feat: send editor context (visible files, open tabs, shell, timezone) to CLI backend - #6151
Conversation
|
e7ae46f to
2a0ac40
Compare
…mits - Replace duck-typing with instanceof vscode.TabInputText to exclude non-text tabs (notebooks, diffs, custom editors) from open tabs context - Cap visible files at 200 and open tabs at 20 to avoid bloating context
Use FileIgnoreController to filter visible files, open tabs, and the active file through .kilocodeignore patterns before sending them to the CLI backend. Falls back to .gitignore + sensitive env patterns when no .kilocodeignore exists. The controller is lazily initialized and cached per workspace directory.
Replace imprecise toDateString() (e.g. 'Mon Feb 23 2026') with full
ISO 8601 UTC timestamp and user timezone with UTC offset when the
extension provides it via editorContext.timezone.
Before: Today's date: Mon Feb 23 2026
After: Current time: 2026-02-23T12:23:04.159Z
User timezone: Europe/Amsterdam, UTC+1:00
The active editor was being sent as a file:// URI part, causing the CLI backend to read and include the full file content in the conversation. This made the model act on file contents even when the user just said 'hello'. Now that editorContext.activeFile provides the filename as metadata only, the full content injection is no longer needed.
Design document served its purpose during implementation; removing to keep the repo clean.
Mark editorContext additions in message-v2.ts, prompt.ts, and system.ts with kilocode_change markers to ease upstream merge conflict resolution.
Move formatTime and editor context env-line building into a dedicated kilocode-specific file to minimize changes in the shared system.ts. The only changes to system.ts are now: import, signature, and one spread call.
| const now = new Date() | ||
| const lines = [` Current time: ${now.toISOString()}`] | ||
| if (timezone) { | ||
| const offset = -now.getTimezoneOffset() |
There was a problem hiding this comment.
WARNING: Timezone offset mismatch — getTimezoneOffset() returns the server/CLI process local offset, not the offset for the user's timezone string.
When the CLI backend runs in a different timezone than the VS Code client (e.g., remote dev server in UTC, user in Europe/Amsterdam), the displayed offset will be wrong while the timezone name is correct.
To compute the correct offset from the timezone string, you could use Intl.DateTimeFormat:
function getUtcOffset(timezone: string): string {
const now = new Date()
const formatter = new Intl.DateTimeFormat("en-US", {
timeZone: timezone,
timeZoneName: "shortOffset",
})
const parts = formatter.formatToParts(now)
const tzPart = parts.find((p) => p.type === "timeZoneName")
return tzPart?.value ?? ""
}Or simply omit the computed offset and just display the timezone name, since the name is authoritative.
| } | ||
| const controller = new FileIgnoreController(workspaceDir) | ||
| await controller.initialize() | ||
| this.ignoreController = controller |
There was a problem hiding this comment.
SUGGESTION: The old ignoreController is replaced but never disposed when the workspace directory changes. This leaks the previous controller's internal state (loaded contents, realpath cache).
Consider disposing the old controller before replacing it:
this.ignoreController?.dispose()before assigning the new one.
|
|
||
| /** | ||
| * Gather VS Code editor context to send alongside messages to the CLI backend. | ||
| */ |
There was a problem hiding this comment.
SUGGESTION: Orphaned JSDoc comment — this doc block ("Gather VS Code editor context...") was likely intended for gatherEditorContext() at line 1527, but it's now attached to nothing since getIgnoreController() has its own JSDoc immediately below. Consider removing this block or moving it above gatherEditorContext().
Code Review SummaryStatus: 3 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (6 files)
|
…preserve caching The editor context change in PR #6151 switched from Today's date (toDateString) to Current time (toISOString), which breaks prompt caching because the system prompt now changes every second instead of once per day. This changes it back to date-only format while keeping all other editor context improvements.
feat: send editor context (visible files, open tabs, shell, timezone) to CLI backend
…preserve caching The editor context change in PR Kilo-Org#6151 switched from Today's date (toDateString) to Current time (toISOString), which breaks prompt caching because the system prompt now changes every second instead of once per day. This changes it back to date-only format while keeping all other editor context improvements.
feat: send editor context (visible files, open tabs, shell, timezone) to CLI backend
…preserve caching The editor context change in PR Kilo-Org#6151 switched from Today's date (toDateString) to Current time (toISOString), which breaks prompt caching because the system prompt now changes every second instead of once per day. This changes it back to date-only format while keeping all other editor context improvements.
Summary
Send editor context information (visible files, open tabs, active file, shell, timezone) alongside chat messages to the CLI backend.
Changes
EditorContextinterface added tosrc/services/cli-backend/types.ts— defines the shape of editor context data (visible files, open tabs, active file, shell, timezone, cwd)sendMessage()inhttp-client.tsextended to accept and forward an optionaleditorContextparameter to the CLI backendgatherEditorContext()inKiloProvider.ts— new method that collects:Intl.DateTimeFormat)file://URI injection into the message body is preserved for backward compatibilitydocs/vscode-context-plan.mddesign documentContext
Implements the extension-side pieces of Phase 1 + Phase 2 from
docs/vscode-context-plan.md. The CLI backend side (consuming the context) is tracked separately.Remove full file
don't send the full open editor, as the agent will interpret that as part of the prompt, no wi can say hello to the agent again without the agent starting work on the todo immediately