Skip to content

feat(vscode): add searchable worktree references - #13512

Merged
marius-kilocode merged 2 commits into
mainfrom
support-worktree-references-in-prompts
Aug 27, 2026
Merged

feat(vscode): add searchable worktree references#13512
marius-kilocode merged 2 commits into
mainfrom
support-worktree-references-in-prompts

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Comparing work across Agent Manager worktrees currently requires copying directory paths or attaching a past conversation when only a reference is needed. A flat list of all worktrees in the main @ menu would also make file selection noisy.

Why This Change Was Made

Add one Worktrees entry to the @ menu. It opens a searchable picker built with the same shared List component and row styling as Past chats. Selection inserts the absolute worktree path and attaches a small text record containing its branch, base branch, and session IDs/titles. It does not attach directory contents, diffs, or conversation history, change the agent's working directory, or bypass normal tool permissions.

The implementation reuses the active project's existing worktree inventory and session projection. It adds no backend endpoint or discovery request. The custom search input, clear button, filter state, and search-key forwarding were removed. A one-line shared List fix routes clearing through applyFilter(""), so the actual results reset with the input. Past chats' session-fetching logic is unchanged.

Sorting, quoted from the implementation

Source: packages/kilo-vscode/webview-ui/agent-manager/worktree-references.ts:47.

(recency.get(a.path) ?? recent.length) - (recency.get(b.path) ?? recent.length) ||
(activity.get(b.path) ?? 0) - (activity.get(a.path) ?? 0)

With an empty search:

  1. Most recently opened worktrees come first. Visits are recorded on worktree activation in Agent Manager, not when a reference is selected.
  2. Worktrees without a recent visit fall back to activity: the latest of worktree creation and associated session updates.
  3. Equal ranks keep the persisted sidebar order, using a stable sort.

Visit history is bounded to 100 absolute paths and stored in webview state. Path identity avoids collisions between project-local worktree IDs. The current worktree, missing worktrees, and worktrees undergoing a worktree operation are not offered. A running agent is not excluded just because it is generating.

A typed query uses the shared List's fuzzy ranking over names, branches, and session titles. Absolute directory prefixes are deliberately excluded from fuzzy matching so common path characters do not produce unrelated results. The full path remains available on hover and in the reference.

Component Empty-query order Typed query
Worktree references Recent worktree visits, then latest activity, then sidebar order Shared List fuzzy ranking over name, branch, and session titles
Past chats Session update time, newest first Shared List fuzzy ranking over title and worktree name
Standard Agent Manager sidebar search Sessions before contexts; then waiting, busy/retry, visibility, activity, and title Shared List fuzzy ranking

The experimental multi-project sidebar keeps its existing project/context insertion behavior. This change does not replace its sorting rules.

User Impact

Type @, select Worktrees, then search and select with Enter, Tab, or the mouse. Escape closes the picker. Existing atomic deletion, native undo, and draft restoration remain available.

Example with an anonymized path:

Compare your changes with @/workspace/demo/.kilo/worktrees/logging-refactor

The receiving agent can inspect that directory with its normal filesystem/Git tools, or use the supplied session IDs with Agent Manager and recall. A reference is metadata, not a frozen copy of the other worktree; a directory removed later can therefore be stale.

Evidence

The final simplified build was exercised in isolated VS Code with three real managed worktrees. Checks covered recent-first ordering, current-worktree exclusion, session-title search, clearing an unmatched query, keyboard selection, undo, draft restoration, and visit-order persistence after a webview reload.

A live agent deliberately inverted one comparison in a disposable worktree. A second live agent selected it through the new picker, inspected its on-disk Git diff, and reported:

internal/logging/logger.go:91 - Logger.Get now returns the first message whose ID does not match the requested ID. This causes lookups for existing IDs to return an unrelated message, while lookups for missing IDs may incorrectly succeed instead of returning io.EOF.

The reviewing worktree remained unchanged. The isolated environment was cleaned up afterward.

1. Open Worktrees from the main @ menu.

The at-mention menu with a single Worktrees entry alongside Terminal, Git changes, and Past chats

2. Search or choose a recent worktree. Logging refactor was visited most recently in this example.

The shared searchable worktree picker with Logging refactor first and Error handling second

Validation:

  • Monorepo bun run typecheck passed, including JetBrains.
  • Root bun run lint completed with warnings and no errors.
  • Extension compile, lint, typechecks, Knip, and Kilo-owned source guards passed.
  • 4,277 extension unit tests and 160 shared UI tests passed.
  • The existing tab-switcher DOM fixture reproduces the native clear bug before the fix and passes afterward.
  • Browser-runtime tests cover selection-driven recency and project-scoped metadata. Additional tests cover Unicode/spaced paths, metadata-only attachments, restoration races, unavailable worktrees, and ID collisions.
  • Shared-source annotation and formatting checks passed. Source-link extraction produced no additional URL changes.

All screenshots were privacy-reviewed and hosted in the separate PR-assets repository; no PR media is added to this repository.

@kilo-code-bot

kilo-code-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (40 files)
  • .changeset/agent-manager-worktree-mentions.md
  • packages/kilo-vscode/tests/fixtures/session-tab-switcher.tsx
  • packages/kilo-vscode/tests/fixtures/worktree-references.ts
  • packages/kilo-vscode/tests/unit/agent-manager-worktree-reference.test.ts
  • packages/kilo-vscode/tests/unit/project-session-filter.test.ts
  • packages/kilo-vscode/tests/unit/project-sessions-live.test.ts
  • packages/kilo-vscode/tests/unit/worktree-recency.test.ts
  • packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx
  • packages/kilo-vscode/webview-ui/agent-manager/project/session-filter.ts
  • packages/kilo-vscode/webview-ui/agent-manager/project/sessions-live.ts
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-recency.ts
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-references.ts
  • packages/kilo-vscode/webview-ui/src/components/chat/ChatView.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/WorktreeMentionPicker.tsx
  • packages/kilo-vscode/webview-ui/src/hooks/file-mention-utils.ts
  • packages/kilo-vscode/webview-ui/src/hooks/useFileMention.ts
  • packages/kilo-vscode/webview-ui/src/i18n/ar.ts
  • packages/kilo-vscode/webview-ui/src/i18n/br.ts
  • packages/kilo-vscode/webview-ui/src/i18n/bs.ts
  • packages/kilo-vscode/webview-ui/src/i18n/da.ts
  • packages/kilo-vscode/webview-ui/src/i18n/de.ts
  • packages/kilo-vscode/webview-ui/src/i18n/en.ts
  • packages/kilo-vscode/webview-ui/src/i18n/es.ts
  • packages/kilo-vscode/webview-ui/src/i18n/fa.ts
  • packages/kilo-vscode/webview-ui/src/i18n/fr.ts
  • packages/kilo-vscode/webview-ui/src/i18n/it.ts
  • packages/kilo-vscode/webview-ui/src/i18n/ja.ts
  • packages/kilo-vscode/webview-ui/src/i18n/ko.ts
  • packages/kilo-vscode/webview-ui/src/i18n/nl.ts
  • packages/kilo-vscode/webview-ui/src/i18n/no.ts
  • packages/kilo-vscode/webview-ui/src/i18n/pl.ts
  • packages/kilo-vscode/webview-ui/src/i18n/ru.ts
  • packages/kilo-vscode/webview-ui/src/i18n/th.ts
  • packages/kilo-vscode/webview-ui/src/i18n/tr.ts
  • packages/kilo-vscode/webview-ui/src/i18n/uk.ts
  • packages/kilo-vscode/webview-ui/src/i18n/zh.ts
  • packages/kilo-vscode/webview-ui/src/i18n/zht.ts
  • packages/kilo-vscode/webview-ui/src/styles/prompt-dropdowns.css
  • packages/ui/src/components/list.tsx
Previous Review Summary (commit 13a9673)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 13a9673)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (38 files)
  • .changeset/agent-manager-worktree-mentions.md
  • packages/kilo-vscode/tests/fixtures/session-tab-switcher.tsx
  • packages/kilo-vscode/tests/fixtures/worktree-references.ts
  • packages/kilo-vscode/tests/unit/agent-manager-worktree-reference.test.ts
  • packages/kilo-vscode/tests/unit/project-sessions-live.test.ts
  • packages/kilo-vscode/tests/unit/worktree-recency.test.ts
  • packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx
  • packages/kilo-vscode/webview-ui/agent-manager/project/sessions-live.ts
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-recency.ts
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-references.ts
  • packages/kilo-vscode/webview-ui/src/components/chat/ChatView.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/WorktreeMentionPicker.tsx
  • packages/kilo-vscode/webview-ui/src/hooks/file-mention-utils.ts
  • packages/kilo-vscode/webview-ui/src/hooks/useFileMention.ts
  • packages/kilo-vscode/webview-ui/src/i18n/ar.ts
  • packages/kilo-vscode/webview-ui/src/i18n/br.ts
  • packages/kilo-vscode/webview-ui/src/i18n/bs.ts
  • packages/kilo-vscode/webview-ui/src/i18n/da.ts
  • packages/kilo-vscode/webview-ui/src/i18n/de.ts
  • packages/kilo-vscode/webview-ui/src/i18n/en.ts
  • packages/kilo-vscode/webview-ui/src/i18n/es.ts
  • packages/kilo-vscode/webview-ui/src/i18n/fa.ts
  • packages/kilo-vscode/webview-ui/src/i18n/fr.ts
  • packages/kilo-vscode/webview-ui/src/i18n/it.ts
  • packages/kilo-vscode/webview-ui/src/i18n/ja.ts
  • packages/kilo-vscode/webview-ui/src/i18n/ko.ts
  • packages/kilo-vscode/webview-ui/src/i18n/nl.ts
  • packages/kilo-vscode/webview-ui/src/i18n/no.ts
  • packages/kilo-vscode/webview-ui/src/i18n/pl.ts
  • packages/kilo-vscode/webview-ui/src/i18n/ru.ts
  • packages/kilo-vscode/webview-ui/src/i18n/th.ts
  • packages/kilo-vscode/webview-ui/src/i18n/tr.ts
  • packages/kilo-vscode/webview-ui/src/i18n/uk.ts
  • packages/kilo-vscode/webview-ui/src/i18n/zh.ts
  • packages/kilo-vscode/webview-ui/src/i18n/zht.ts
  • packages/kilo-vscode/webview-ui/src/styles/prompt-dropdowns.css
  • packages/ui/src/components/list.tsx

Reviewed by grok-4.6 · Input: 77.8K · Output: 7.4K · Cached: 259.3K

Review guidance: REVIEW.md from base branch main

@marius-kilocode
marius-kilocode merged commit e3ff6fb into main Aug 27, 2026
47 of 50 checks passed
@marius-kilocode
marius-kilocode deleted the support-worktree-references-in-prompts branch August 27, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants