Skip to content

feat(agent-manager): add @model, @past-chats and @worktrees mentions to New Worktree prompt - #14251

Merged
marius-kilocode merged 11 commits into
mainfrom
agent-manager-modal-mentions
Sep 18, 2026
Merged

marius-kilocode merged 11 commits into
mainfrom
agent-manager-modal-mentions

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

The Agent Manager New Worktree dialog supports slash commands but has no @-mention support. A prompt written while creating a worktree cannot reference a model, an earlier chat, or another worktree, even though the normal chat composer can.

Why This Change Was Made

Mentions here must be worktree-independent. At dialog time the new worktree does not exist yet, so resolving file paths against it is unsafe. The dialog therefore offers only references that are safe before creation:

  • @model inserts the inline token @providerID/modelID as plain text. It never becomes a file attachment.
  • @past-chats builds a session:{id} attachment. The backend resolves session: file parts into transcript context when the session starts.
  • @worktrees builds a metadata-only data: URL attachment for another Agent Manager worktree.

File, folder, opened-file, terminal, and git-changes mentions are intentionally not offered. Slash-command behavior is unchanged.

A dedicated useWorktreeMention hook reuses the shared mention utilities (rankMentionResults, filterSessions, buildSessionAttachments, buildWorktreeAttachments) but restricts the menu to those three entries, so the dialog never runs file search. Attachments are built at creation time and flow through the existing createMultiVersion file pipeline to the created session.

User Impact

  • Typing @ in the New Worktree prompt shows Model, Past chats, and Worktrees.
  • Picking a past chat or worktree inserts an @ token and sends the resolved context to each created session.
  • Picking a model inserts its inline reference, which stays plain text.
  • Inserted mentions are highlighted in the prompt, matching the chat composer, and the prompt keeps multiple spaces and newlines.
  • Enter inserts a newline in the prompt; Cmd+Enter (Ctrl+Enter on Windows and Linux) creates the worktree, unchanged.
  • Image attachments and version/compare mode keep working.

Evidence

Self-tested in an isolated VS Code dev instance (vscode-self-test) against a disposable fixture repository:

  • The @ menu lists Model, Past chats, and Worktrees, and no file, terminal, or git entries.
  • @model opened the shared model selector and inserted @kilo/kilo-auto/free as text.
  • @worktrees listed the existing fixture-a worktree and inserted its path.
  • @past-chats listed the earlier titled session and inserted its title.
  • The created session received all three: the assistant identified the attached transcript (resolved session: part), the worktree path (resolved metadata data: part), and the model slug.
  • Re-checked after the final commits: every inserted mention renders as a highlighted span, the overlay text exactly matches the textarea for multiple spaces and newlines, the overlay is pointer-events none so text selection is unaffected, Enter inserts a newline, and Cmd+Enter submitted and created the worktree.

The New Worktree prompt @ menu listing Model, Past chats, and Worktrees

New Worktree prompt with highlighted worktree, past chat, and model mentions

Created worktree session showing the resolved transcript context and mention tokens

Created worktree session showing the resolved transcript context and mention tokens

Automated checks from packages/kilo-vscode/:

  • bun run check-types and bun run check-types:webview pass.
  • bun run lint passes.
  • bun run test:unit passes. New coverage lives in tests/unit/worktree-mention.test.ts (three entries, attachment building, token insertion, prose close, Escape handling, disabled worktrees, highlight tokens), tests/unit/file-mention-utils.test.ts (segmentMentionText), and tests/unit/agent-manager-worktree-reference.test.ts (dialog reference list).

Comment thread packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts Outdated
Comment thread packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts
Comment thread packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts Outdated
Comment thread packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Incremental review of 483ac708..3f3947e4, a one-line refactor in escape-regexp.ts: the native RegExp.escape is now called unbound (nativeEscape(value)) instead of via .call(RegExp, value). The RegExp.escape spec does not consult this, so the behavior is identical and the change resolves the prior reviewer note about the unnecessary receiver. No new issues found in the changed lines.

Files Reviewed (1 file, incremental)
  • packages/kilo-vscode/webview-ui/src/utils/escape-regexp.ts
Previous Review Summaries (9 snapshots, latest commit 483ac70)

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

Previous review (commit 483ac70)

Status: No Issues Found | Recommendation: Merge

Incremental review of 4c7d69f..483ac708, a one-line simplification in segmentMentionText: the plain-text segment is now pushed only when the slice is non-empty (if (plain)) instead of comparing index > last. The two conditions are equivalent under matchAll (non-overlapping, ordered matches guarantee index >= last), so there is no behavior change. No new issues found in the changed lines.

Files Reviewed (1 file, incremental)
  • packages/kilo-vscode/webview-ui/src/hooks/file-mention-utils.ts

Previous review (commit 4c7d69f)

Status: No Issues Found | Recommendation: Merge

Incremental review of 0e2f1a5..4c7d69f, which centralizes regex escaping on RegExp.escape. The new escapeRegExp helper prefers native RegExp.escape and falls back to the standard metacharacter escape; both call sites (segmentMentionText and the transcript search pattern) now share it, and the added tests cover metacharacters, backslashes, plain text, and longest-token matching. The previously flagged mention defects are resolved in the current code: disabled-worktree filtering plus a selectWorktree guard, past-chat picker reset on input, undo-preserving insertion with a no-op fallback that syncs the prompt, entry names removed from the prose-close token set, and a single shared worktree recency list. No new issues found in the changed lines.

Files Reviewed (5 files, incremental)
  • packages/kilo-vscode/tests/unit/escape-regexp.test.ts
  • packages/kilo-vscode/tests/unit/file-mention-utils.test.ts
  • packages/kilo-vscode/webview-ui/src/components/chat/MessageList.tsx
  • packages/kilo-vscode/webview-ui/src/hooks/file-mention-utils.ts
  • packages/kilo-vscode/webview-ui/src/utils/escape-regexp.ts

Previous review (commit 0e2f1a5)

Status: No Issues Found | Recommendation: Merge

Incremental review of b434feb..0e2f1a5, which adds the mention highlight overlay to the New Worktree prompt. segmentMentionText matches inserted tokens longest-first, escapes regex metacharacters, and preserves plain text; the dialog keeps the overlay scroll in sync with the textarea and covers the trailing-newline case. No new issues found in the changed lines.

Files Reviewed (6 files, incremental)
  • packages/kilo-vscode/tests/unit/file-mention-utils.test.ts
  • packages/kilo-vscode/tests/unit/worktree-mention.test.ts
  • packages/kilo-vscode/webview-ui/agent-manager/NewWorktreeDialog.tsx
  • packages/kilo-vscode/webview-ui/agent-manager/agent-manager.css
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts
  • packages/kilo-vscode/webview-ui/src/hooks/file-mention-utils.ts

Previous review (commit b434feb)

Status: No Issues Found | Recommendation: Merge

Incremental review of 49aef17..b434feb. The previous suggestion on worktree-references.ts (dialog list never reacting to recency) is resolved: dialogRefs now derives from the chat references memo, so both lists share one createWorktreeRecency signal, and the selected worktree is re-enabled only when it is neither stale nor busy.

Files Reviewed (2 files, incremental)
  • packages/kilo-vscode/tests/unit/agent-manager-worktree-reference.test.ts
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-references.ts

Previous review (commit 49aef17)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

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

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/worktree-references.ts 110 The dialog's worktree list comes from a second createWorktreeReferences whose recency signal never updates, so dialog ordering stops tracking recency.
Files Reviewed (4 files, incremental)
  • packages/kilo-vscode/tests/unit/worktree-mention.test.ts
  • packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-references.ts - 1 issue

Fix these issues in Kilo Cloud

Previous review (commit 2d7b53e)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts 142 @worktrees candidates are still not filtered by worktree.disabled and selectWorktree has no guard, so stale and busy worktrees remain listed and selectable.

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts 148 Entry names in tokens() make spaced queries like @worktrees ref settle as prose, blocking title matches that start with those words.
Files Reviewed (1 file, incremental)
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts

Fix these issues in Kilo Cloud

Previous review (commit 1f4180d)

Status: 4 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts 139 @worktrees candidates are still not filtered by worktree.disabled and selectWorktree has no guard, so stale and busy worktrees remain listed and selectable.

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts 145 Entry names in tokens() make spaced queries like @worktrees ref settle as prose, blocking title matches that start with those words.
packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts 201 onInput resets the worktree and model pickers but not the past-chats picker.
packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts 262 New execCommand branch never syncs setText and has no no-op fallback, so a missed input event silently drops a past-chat or worktree mention from the created session.

Resolved in 1f4180d5: mention insertion now routes through document.execCommand("insertText"), restoring the native undo stack the dialog's undo() handler relies on.

Files Reviewed (1 file, incremental)
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts

Fix these issues in Kilo Cloud

Previous review (commit 9bdd549)

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/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts 139 @worktrees candidates are still not filtered by worktree.disabled (line 41 of worktree-references.ts sets it for the current, stale, and busy worktrees) and selectWorktree has no guard. The new comment at 135-138 documents the departure as intentional for the current-worktree flag and metadata-only attachments, but stale and busy worktrees remain listed and selectable.

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts 259 Direct textarea.value assignment (also at line 327) clears the native undo stack that useFileMention preserves via document.execCommand("insertText"), while the dialog's undo() handler at NewWorktreeDialog.tsx:496 relies on document.execCommand("undo").
packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts 145 Entry names in tokens() make spaced queries like @worktrees ref settle as prose, blocking title matches that start with those words.
Files Reviewed (2 files, incremental)
  • packages/kilo-vscode/tests/unit/worktree-mention.test.ts
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts - 3 issues

Fix these issues in Kilo Cloud

Previous review (commit b3ef153)

Status: 4 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts 135 @worktrees candidates are not filtered by worktree.disabled, and selectWorktree has no guard, so stale/busy worktrees are selectable unlike useFileMention.

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts 196 onInput resets the worktree and model pickers but not sessionPicker, which is only cleared by close().
packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts 254 Direct textarea.value assignment (also at line 322) clears the native undo stack that useFileMention preserves via document.execCommand("insertText").
packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts 141 Entry names in tokens() make spaced queries like @worktrees ref settle as prose, blocking title matches that start with those words.
Files Reviewed (6 files)
  • .changeset/new-worktree-mentions.md
  • packages/kilo-vscode/tests/unit/worktree-mention.test.ts
  • packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx
  • packages/kilo-vscode/webview-ui/agent-manager/NewWorktreeDialog.tsx
  • packages/kilo-vscode/webview-ui/agent-manager/agent-manager.css
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts - 4 issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

Comment thread packages/kilo-vscode/webview-ui/agent-manager/worktree-mention.ts
Comment thread packages/kilo-vscode/webview-ui/agent-manager/worktree-references.ts Outdated
…entions

# Conflicts:
#	packages/kilo-vscode/webview-ui/agent-manager/NewWorktreeDialog.tsx
Comment thread packages/kilo-vscode/webview-ui/src/hooks/file-mention-utils.ts Outdated
Comment thread packages/kilo-vscode/webview-ui/src/hooks/file-mention-utils.ts Outdated
Comment thread packages/kilo-vscode/webview-ui/src/utils/escape-regexp.ts Outdated

@WebReflection WebReflection left a comment

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.

we could drop nativeEscape.call(RegExp, value) and use just nativeEscape(value) instead but it works either ways anyway (context ignored), up to you but this looks good now, thanks

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