Skip to content

feat: send editor context (visible files, open tabs, shell, timezone) to CLI backend - #6151

Merged
markijbema merged 10 commits into
mainfrom
mark/editor-context
Feb 23, 2026
Merged

feat: send editor context (visible files, open tabs, shell, timezone) to CLI backend#6151
markijbema merged 10 commits into
mainfrom
mark/editor-context

Conversation

@markijbema

@markijbema markijbema commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Send editor context information (visible files, open tabs, active file, shell, timezone) alongside chat messages to the CLI backend.

Changes

  • EditorContext interface added to src/services/cli-backend/types.ts — defines the shape of editor context data (visible files, open tabs, active file, shell, timezone, cwd)
  • sendMessage() in http-client.ts extended to accept and forward an optional editorContext parameter to the CLI backend
  • gatherEditorContext() in KiloProvider.ts — new method that collects:
    • Visible text editor file paths
    • Open tab file paths
    • Active file path
    • Default shell from VS Code terminal profile
    • User timezone (via Intl.DateTimeFormat)
    • Workspace root as cwd
  • All paths are workspace-relative; files outside the workspace are excluded
  • Existing active editor file:// URI injection into the message body is preserved for backward compatibility
  • Includes docs/vscode-context-plan.md design document
CleanShot 2026-02-23 at 16 15 11

Context

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

CleanShot 2026-02-23 at 14 57 25

@changeset-bot

changeset-bot Bot commented Feb 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e7ae46f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@markijbema markijbema changed the title Mark/editor context feat: send editor context (visible files, open tabs, shell, timezone) to CLI backend Feb 23, 2026
Mark IJbema added 8 commits February 23, 2026 14:23
…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.
@markijbema
markijbema marked this pull request as ready for review February 23, 2026 15:15
const now = new Date()
const lines = [` Current time: ${now.toISOString()}`]
if (timezone) {
const offset = -now.getTimezoneOffset()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

@kilo-code-bot

kilo-code-bot Bot commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 2
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/kilocode/editor-context.ts 13 getTimezoneOffset() returns the server's local offset, not the user's timezone offset — will produce wrong UTC offset when CLI runs in a different timezone than VS Code

SUGGESTION

File Line Issue
packages/kilo-vscode/src/KiloProvider.ts 1522 Old ignoreController not disposed when workspace directory changes (minor resource leak)
packages/kilo-vscode/src/KiloProvider.ts 1511 Orphaned JSDoc comment — "Gather VS Code editor context" block is detached from gatherEditorContext()
Files Reviewed (6 files)
  • packages/kilo-vscode/src/KiloProvider.ts - 2 issues
  • packages/kilo-vscode/src/services/cli-backend/http-client.ts - 0 issues
  • packages/kilo-vscode/src/services/cli-backend/types.ts - 0 issues
  • packages/opencode/src/kilocode/editor-context.ts - 1 issue
  • packages/opencode/src/session/message-v2.ts - 0 issues
  • packages/opencode/src/session/prompt.ts - 0 issues
  • packages/opencode/src/session/system.ts - 0 issues

Fix these issues in Kilo Cloud

@markijbema
markijbema merged commit 89400ad into main Feb 23, 2026
10 checks passed
@markijbema
markijbema deleted the mark/editor-context branch February 23, 2026 16:14
markijbema pushed a commit that referenced this pull request Feb 24, 2026
…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.
jliounis pushed a commit to jliounis/kilocode that referenced this pull request May 18, 2026
feat: send editor context (visible files, open tabs, shell, timezone) to CLI backend
jliounis pushed a commit to jliounis/kilocode that referenced this pull request May 18, 2026
…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.
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
feat: send editor context (visible files, open tabs, shell, timezone) to CLI backend
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants