Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/types/src/global-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ export const globalSettingsSchema = z.object({
*/
maxDiagnosticMessages: z.number().optional(),

/**
* Whether to include current time in environment details sent with each request
* @default true
*/
includeCurrentTime: z.boolean().optional(),
/**
* Whether to include timezone information when current time is included
* @default false
*/
includeTimezone: z.boolean().optional(),

browserToolEnabled: z.boolean().optional(),
browserViewportSize: z.string().optional(),
screenshotQuality: z.number().optional(),
Expand Down Expand Up @@ -311,6 +322,9 @@ export const EVALS_SETTINGS: RooCodeSettings = {
includeDiagnosticMessages: true,
maxDiagnosticMessages: 50,

includeCurrentTime: true,
includeTimezone: false,

language: "en",
telemetrySetting: "enabled",

Expand Down
26 changes: 17 additions & 9 deletions src/core/environment/getEnvironmentDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo
terminalOutputLineLimit = 500,
terminalOutputCharacterLimit = DEFAULT_TERMINAL_OUTPUT_CHARACTER_LIMIT,
maxWorkspaceFiles = 200,
includeCurrentTime = true,
includeTimezone = false,
} = state ?? {}

// It could be useful for cline to know if the user went from one or no
Expand Down Expand Up @@ -190,15 +192,21 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo
details += terminalDetails
}

// Add current time information with timezone.
const now = new Date()

const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
const timeZoneOffset = -now.getTimezoneOffset() / 60 // Convert to hours and invert sign to match conventional notation
const timeZoneOffsetHours = Math.floor(Math.abs(timeZoneOffset))
const timeZoneOffsetMinutes = Math.abs(Math.round((Math.abs(timeZoneOffset) - timeZoneOffsetHours) * 60))
const timeZoneOffsetStr = `${timeZoneOffset >= 0 ? "+" : "-"}${timeZoneOffsetHours}:${timeZoneOffsetMinutes.toString().padStart(2, "0")}`
details += `\n\n# Current Time\nCurrent time in ISO 8601 UTC format: ${now.toISOString()}\nUser time zone: ${timeZone}, UTC${timeZoneOffsetStr}`
// Add current time information (only if enabled).
if (includeCurrentTime) {
const now = new Date()
details += `\n\n# Current Time\nCurrent time in ISO 8601 UTC format: ${now.toISOString()}`

// Add timezone information only if both includeCurrentTime and includeTimezone are enabled
if (includeTimezone) {
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
const timeZoneOffset = -now.getTimezoneOffset() / 60 // Convert to hours and invert sign to match conventional notation
const timeZoneOffsetHours = Math.floor(Math.abs(timeZoneOffset))
const timeZoneOffsetMinutes = Math.abs(Math.round((Math.abs(timeZoneOffset) - timeZoneOffsetHours) * 60))
const timeZoneOffsetStr = `${timeZoneOffset >= 0 ? "+" : "-"}${timeZoneOffsetHours}:${timeZoneOffsetMinutes.toString().padStart(2, "0")}`
details += `\nUser time zone: ${timeZone}, UTC${timeZoneOffsetStr}`
}
}

// Add context tokens information.
const { contextTokens, totalCost } = getApiMetrics(cline.clineMessages)
Expand Down
6 changes: 6 additions & 0 deletions src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,8 @@ export class ClineProvider
followupAutoApproveTimeoutMs,
includeDiagnosticMessages,
maxDiagnosticMessages,
includeCurrentTime,
includeTimezone,
includeTaskHistoryInEnhance,
taskSyncEnabled,
remoteControlEnabled,
Expand Down Expand Up @@ -1957,6 +1959,8 @@ export class ClineProvider
followupAutoApproveTimeoutMs: followupAutoApproveTimeoutMs ?? 60000,
includeDiagnosticMessages: includeDiagnosticMessages ?? true,
maxDiagnosticMessages: maxDiagnosticMessages ?? 50,
includeCurrentTime: includeCurrentTime ?? true,
includeTimezone: includeTimezone ?? false,
includeTaskHistoryInEnhance: includeTaskHistoryInEnhance ?? true,
taskSyncEnabled,
remoteControlEnabled,
Expand Down Expand Up @@ -2168,6 +2172,8 @@ export class ClineProvider
profileThresholds: stateValues.profileThresholds ?? {},
includeDiagnosticMessages: stateValues.includeDiagnosticMessages ?? true,
maxDiagnosticMessages: stateValues.maxDiagnosticMessages ?? 50,
includeCurrentTime: stateValues.includeCurrentTime ?? true,
includeTimezone: stateValues.includeTimezone ?? false,
includeTaskHistoryInEnhance: stateValues.includeTaskHistoryInEnhance ?? true,
taskSyncEnabled,
remoteControlEnabled: (() => {
Expand Down
2 changes: 2 additions & 0 deletions src/core/webview/__tests__/ClineProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ describe("ClineProvider", () => {
maxReadFileLine: 500,
maxImageFileSize: 5,
maxTotalImageSize: 20,
includeCurrentTime: true,
includeTimezone: false,
cloudUserInfo: null,
organizationAllowList: ORGANIZATION_ALLOW_ALL,
autoCondenseContext: true,
Expand Down
8 changes: 8 additions & 0 deletions src/core/webview/webviewMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,14 @@ export const webviewMessageHandler = async (
await updateGlobalState("maxDiagnosticMessages", message.value ?? 50)
await provider.postStateToWebview()
break
case "includeCurrentTime":
await updateGlobalState("includeCurrentTime", message.bool ?? true)
await provider.postStateToWebview()
break
case "includeTimezone":
await updateGlobalState("includeTimezone", message.bool ?? false)
await provider.postStateToWebview()
break
case "setHistoryPreviewCollapsed": // Add the new case handler
await updateGlobalState("historyPreviewCollapsed", message.bool ?? false)
// No need to call postStateToWebview here as the UI already updated optimistically
Expand Down
2 changes: 2 additions & 0 deletions src/shared/ExtensionMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ export type ExtensionState = Pick<
| "profileThresholds"
| "includeDiagnosticMessages"
| "maxDiagnosticMessages"
| "includeCurrentTime"
| "includeTimezone"
| "openRouterImageGenerationSelectedModel"
| "includeTaskHistoryInEnhance"
| "reasoningBlockCollapsed"
Expand Down
2 changes: 2 additions & 0 deletions src/shared/WebviewMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ export interface WebviewMessage {
| "maxConcurrentFileReads"
| "includeDiagnosticMessages"
| "maxDiagnosticMessages"
| "includeCurrentTime"
| "includeTimezone"
| "searchFiles"
| "toggleApiConfigPin"
| "setHistoryPreviewCollapsed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type ContextManagementSettingsProps = HTMLAttributes<HTMLDivElement> & {
includeDiagnosticMessages?: boolean
maxDiagnosticMessages?: number
writeDelayMs: number
includeCurrentTime?: boolean
includeTimezone?: boolean
setCachedStateField: SetCachedStateField<
| "autoCondenseContext"
| "autoCondenseContextPercent"
Expand All @@ -41,6 +43,8 @@ type ContextManagementSettingsProps = HTMLAttributes<HTMLDivElement> & {
| "includeDiagnosticMessages"
| "maxDiagnosticMessages"
| "writeDelayMs"
| "includeCurrentTime"
| "includeTimezone"
>
}

Expand All @@ -60,6 +64,8 @@ export const ContextManagementSettings = ({
includeDiagnosticMessages,
maxDiagnosticMessages,
writeDelayMs,
includeCurrentTime = true,
includeTimezone = false,
className,
...props
}: ContextManagementSettingsProps) => {
Expand Down Expand Up @@ -356,6 +362,35 @@ export const ContextManagementSettings = ({
{t("settings:contextManagement.diagnostics.delayAfterWrite.description")}
</div>
</div>

<div>
<VSCodeCheckbox
checked={includeCurrentTime}
onChange={(e: any) => setCachedStateField("includeCurrentTime", e.target.checked)}
data-testid="include-current-time-checkbox">
<label className="block font-medium mb-1">
{t("settings:contextManagement.timeInfo.includeCurrentTime.label")}
</label>
</VSCodeCheckbox>
<div className="text-vscode-descriptionForeground text-sm mt-1 mb-3">
{t("settings:contextManagement.timeInfo.includeCurrentTime.description")}
</div>
</div>

<div>
<VSCodeCheckbox
checked={includeTimezone}
disabled={!includeCurrentTime}
onChange={(e: any) => setCachedStateField("includeTimezone", e.target.checked)}
data-testid="include-timezone-checkbox">
<label className="block font-medium mb-1">
{t("settings:contextManagement.timeInfo.includeTimezone.label")}
</label>
</VSCodeCheckbox>
<div className="text-vscode-descriptionForeground text-sm mt-1 mb-3">
{t("settings:contextManagement.timeInfo.includeTimezone.description")}
</div>
</div>
</Section>
<Section className="pt-2">
<VSCodeCheckbox
Expand Down
6 changes: 6 additions & 0 deletions webview-ui/src/components/settings/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
followupAutoApproveTimeoutMs,
includeDiagnosticMessages,
maxDiagnosticMessages,
includeCurrentTime,
includeTimezone,
includeTaskHistoryInEnhance,
openRouterImageApiKey,
openRouterImageGenerationSelectedModel,
Expand Down Expand Up @@ -372,6 +374,8 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
vscode.postMessage({ type: "maxConcurrentFileReads", value: cachedState.maxConcurrentFileReads ?? 5 })
vscode.postMessage({ type: "includeDiagnosticMessages", bool: includeDiagnosticMessages })
vscode.postMessage({ type: "maxDiagnosticMessages", value: maxDiagnosticMessages ?? 50 })
vscode.postMessage({ type: "includeCurrentTime", bool: includeCurrentTime ?? true })
vscode.postMessage({ type: "includeTimezone", bool: includeTimezone ?? false })
vscode.postMessage({ type: "currentApiConfigName", text: currentApiConfigName })
vscode.postMessage({ type: "updateExperimental", values: experiments })
vscode.postMessage({ type: "alwaysAllowModeSwitch", bool: alwaysAllowModeSwitch })
Expand Down Expand Up @@ -744,6 +748,8 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
includeDiagnosticMessages={includeDiagnosticMessages}
maxDiagnosticMessages={maxDiagnosticMessages}
writeDelayMs={writeDelayMs}
includeCurrentTime={includeCurrentTime}
includeTimezone={includeTimezone}
setCachedStateField={setCachedStateField}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ describe("SettingsView - Change Detection Fix", () => {
followupAutoApproveTimeoutMs: undefined,
includeDiagnosticMessages: false,
maxDiagnosticMessages: 50,
includeCurrentTime: true,
includeTimezone: false,
includeTaskHistoryInEnhance: true,
openRouterImageApiKey: undefined,
openRouterImageGenerationSelectedModel: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ describe("SettingsView - Unsaved Changes Detection", () => {
followupAutoApproveTimeoutMs: undefined,
includeDiagnosticMessages: false,
maxDiagnosticMessages: 50,
includeCurrentTime: true,
includeTimezone: false,
includeTaskHistoryInEnhance: true,
openRouterImageApiKey: undefined,
openRouterImageGenerationSelectedModel: undefined,
Expand Down
14 changes: 14 additions & 0 deletions webview-ui/src/context/ExtensionStateContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ export interface ExtensionStateContextType extends ExtensionState {
includeDiagnosticMessages?: boolean
setIncludeDiagnosticMessages: (value: boolean) => void
maxDiagnosticMessages?: number
includeCurrentTime?: boolean
setIncludeCurrentTime: (value: boolean) => void
includeTimezone?: boolean
setIncludeTimezone: (value: boolean) => void
setMaxDiagnosticMessages: (value: number) => void
includeTaskHistoryInEnhance?: boolean
setIncludeTaskHistoryInEnhance: (value: boolean) => void
Expand Down Expand Up @@ -264,6 +268,8 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
alwaysAllowUpdateTodoList: true,
includeDiagnosticMessages: true,
maxDiagnosticMessages: 50,
includeCurrentTime: true, // Default to including current time in requests
includeTimezone: false, // Default to NOT including timezone
openRouterImageApiKey: "",
openRouterImageGenerationSelectedModel: "",
})
Expand Down Expand Up @@ -557,6 +563,14 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
setMaxDiagnosticMessages: (value) => {
setState((prevState) => ({ ...prevState, maxDiagnosticMessages: value }))
},
includeCurrentTime: state.includeCurrentTime,
setIncludeCurrentTime: (value) => {
setState((prevState) => ({ ...prevState, includeCurrentTime: value }))
},
includeTimezone: state.includeTimezone,
setIncludeTimezone: (value) => {
setState((prevState) => ({ ...prevState, includeTimezone: value }))
},
includeTaskHistoryInEnhance,
setIncludeTaskHistoryInEnhance,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ describe("mergeExtensionState", () => {
hasOpenedModeSelector: false, // Add the new required property
maxImageFileSize: 5,
maxTotalImageSize: 20,
includeCurrentTime: true,
includeTimezone: false,
remoteControlEnabled: false,
taskSyncEnabled: false,
featureRoomoteControlEnabled: false,
Expand Down
10 changes: 10 additions & 0 deletions webview-ui/src/i18n/locales/ca/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions webview-ui/src/i18n/locales/de/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions webview-ui/src/i18n/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,16 @@
"profileDescription": "Custom threshold for this profile only (overrides global default)",
"inheritDescription": "This profile inherits the global default threshold ({{threshold}}%)",
"usesGlobal": "(uses global {{threshold}}%)"
},
"timeInfo": {
"includeCurrentTime": {
"label": "Include current time in requests",
"description": "When enabled, the current date and time will be included in the context sent with each request. This can help the AI provide time-aware responses."
},
"includeTimezone": {
"label": "Include timezone information",
"description": "When enabled, your timezone information will be included along with the current time. This is only available when 'Include current time in requests' is enabled."
}
}
},
"terminal": {
Expand Down
10 changes: 10 additions & 0 deletions webview-ui/src/i18n/locales/es/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions webview-ui/src/i18n/locales/fr/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions webview-ui/src/i18n/locales/hi/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading