Skip to content

feat(worktree): Phase C — session persistence, hooksPath, Footer + WorktreeExitDialog, three-mode --resume restore#4174

Merged
LaZzyMan merged 27 commits into
mainfrom
lazzy/romantic-burnell-b6e48c
May 19, 2026
Merged

feat(worktree): Phase C — session persistence, hooksPath, Footer + WorktreeExitDialog, three-mode --resume restore#4174
LaZzyMan merged 27 commits into
mainfrom
lazzy/romantic-burnell-b6e48c

Conversation

@LaZzyMan

Copy link
Copy Markdown
Collaborator

Summary

  • What changed: Phase C of the worktree capability (refs Phase A+B in feat(tools): add generic worktree support — EnterWorktree/ExitWorktree + Agent isolation #4073). Adds (1) WorktreeSession sidecar JSON persistence so --resume can recover worktree state, (2) core.hooksPath configuration inside new worktrees so commits run the main repo's hooks, (3) Footer worktree indicator + worktree field in the StatusLine payload, (4) WorktreeExitDialog with dirty-state inspection that intercepts the second Ctrl+C, and (5) a shared restoreWorktreeContext helper that wires --resume worktree restore through TUI, headless, AND ACP modes consistently.
  • Why it changed: Phase A+B shipped the tools and Agent isolation but left worktree state TUI-ephemeral — a session restart lost the worktree binding, stale sidecars accumulated, and the user had no visual confirmation of which worktree was active. Phase C closes the experience gap. The three-mode refactor (commit ada0837e2) was added after E2E Group C exposed that the original implementation only ran in AppContainer.tsx, leaving headless and ACP mode users without restore behavior.
  • Reviewer focus:
    1. packages/core/src/services/worktreeSessionService.ts — shared sidecar I/O + restoreWorktreeContext helper used by all three entry points.
    2. packages/cli/src/ui/AppContainer.tsx — both the dialogsVisible fix (e847bfce8) and the resume-path refactor.
    3. packages/cli/src/nonInteractiveCli.ts and packages/cli/src/acp-integration/{acpAgent,session/Session}.ts — each mode injects the worktree notice via its own mechanism (history INFO item / <system-reminder> prompt prefix / one-shot pendingWorktreeNotice).
    4. packages/core/src/services/gitWorktreeService.ts.husky/ preferred over .git/hooks, skips subprocess when value already matches (mirrors claude-code's optimization).

Validation

  • Commands run:

    # Unit tests
    cd packages/core && npx vitest run \
      src/services/worktreeSessionService.test \
      src/services/gitWorktreeService.test \
      src/services/gitWorktreeService.hooks.integ.test \
      src/tools/enter-worktree.test \
      src/tools/enter-worktree.session.integ.test \
      src/tools/exit-worktree.test \
      src/tools/exit-worktree.session.integ.test
    # → 92 passed
    cd packages/cli && npx vitest run \
      src/ui/components/Footer.test \
      src/ui/components/DialogManager.test \
      src/acp-integration/acpAgent.worktree.test \
      src/acp-integration/session/Session.worktree.test
    # → 25 passed (incl. 7 new ACP tests)
    
    npm run typecheck --workspace=@qwen-code/qwen-code-core
    npm run typecheck --workspace=@qwen-code/qwen-code
    npm run build && npm run bundle  # → dist/cli.js 26MB
  • Prompts / inputs used: see docs/e2e-tests/worktree-phase-c.md (E2E plan covering Groups A–F + a headless --resume retry).

  • Expected vs Observed: all 17 E2E cases + 7 ACP integration tests pass on the post-fix build. The dialog visibility fix (e847bfce8) was caught by Group E (0/5 → 5/5) and the three-mode refactor (ada0837e2) by Group C headless (0/2 → 2/2).

  • Quickest reviewer verification path:

    cd packages/core && npx vitest run src/services/worktreeSessionService.test
    # then in any git repo, start a session, ask the model to "create a worktree
    # named test, write a file inside it, then exit with action=keep"; verify
    # the Footer shows `⎇ worktree-test (test)`, the file lands inside
    # .qwen/worktrees/test/, and `--resume <sessionId>` re-attaches with the
    # `[Resumed] Active worktree: …` system reminder.
  • Evidence:

    Group Result Notes
    A1–A3 (sidecar write / keep clear / remove clear) All 6 fields populated; sidecar deleted on keep+remove; worktree dir deleted on remove
    B1–B3 (hooksPath fallback / husky / hook actually fires) .husky/ preferred when present; commit inside worktree triggers main-repo pre-commit
    C1–C2 (TUI --resume context + stale cleanup) INFO history item shows on resume; sidecar auto-removed when worktree dir is gone
    C-headless1–2 (after ada0837e2 refactor) worktree_restored system message + <system-reminder> prompt prefix; stale sidecar cleaned
    D1–D2 (Footer indicator) ⎇ worktree-X (X) appears / disappears in sync with sidecar
    E1–E5 (ExitDialog on 2nd Ctrl+C, dirty counts, 3 options) After dialog-visibility fix; Cancel keeps session alive, Keep preserves dir, Remove deletes dir + branch
    F1 (full enter→edit→exit keep) File written inside worktree, persists after keep
    F2 (custom statusline gets worktree payload) All five payload fields delivered; built-in row suppressed when custom statusline is active
    ACP integration (7 tests) loadSession sets pendingNotice only when worktree alive; first prompt() injects + clears; subsequent prompts see no leakage

Scope / Risk

  • Main risk or tradeoff: the three-mode refactor for --resume restore touches one entry point per mode but they each inject the notice differently (history INFO vs prompt prefix vs one-shot session field). A single shared helper (restoreWorktreeContext) ensures the cleanup + decision are identical; only the surface mechanism differs. The Phase A simplification still holds — Config.targetDir is never mutated, the worktree path travels via context messages, not process.chdir().
  • Not covered / not validated:
    • Phase D / Future items (--worktree CLI flag, worktree.symlinkDirectories, sparse checkout, .worktreeinclude, tmux integration, PR ref parsing) are explicitly out of scope and documented in docs/design/worktree.md.
    • ACP E2E validation is unit-level (7 tests) rather than full protocol; driving a real ACP stdio channel without a Zed client adds harness complexity that didn't seem worth the value — the boundaries are tightly mocked.
    • Windows / Linux not validated locally; cross-platform behavior depends on simple-git, fs/promises, and execFile, all platform-agnostic.
  • Breaking changes / migration notes: none. New behavior is additive. Existing enter_worktree / exit_worktree callers keep working; the sidecar is created behind the scenes and ignored by older binaries that don't know about it.

Testing Matrix

🍏 🪟 🐧
npm run ⚠️ ⚠️
npx ⚠️ ⚠️ ⚠️
Docker N/A N/A N/A
Podman ⚠️ N/A N/A
Seatbelt ⚠️ N/A N/A

Testing matrix notes:

  • Verified on macOS (darwin 24.6.0) with Node 22.21.1. Cross-platform paths depend only on simple-git, fs/promises, and execFile; no platform-specific code paths were added.

Linked Issues / Bugs

Refs #4056 (Phase C of the generic worktree roadmap; Phase A+B shipped in #4073). Phase D (--worktree CLI flag, symlinkDirectories) and Future items (sparse checkout, .worktreeinclude, tmux, PR refs) are tracked separately in docs/design/worktree.md.

🤖 Generated with Claude Code

LaZzyMan and others added 16 commits May 15, 2026 15:18
- Phase C: session persistence + hooksPath + StatusLine + WorktreeExitDialog
- Phase D: --worktree CLI flag + symlinkDirectories
- Future: sparse checkout, .worktreeinclude, tmux, PR reference parsing
- Feature comparison table updated with Phase A/B completion status

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
8 tasks: WorktreeSession sidecar storage, hooksPath setup,
EnterWorktree/ExitWorktree session wiring, useWorktreeSession hook,
Footer display, --resume context injection, WorktreeExitDialog.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- WorktreeSession: add originalHeadCommit field
- hooksPath: add .husky/ detection + skip-if-already-set logic
- StatusLine payload: expand worktree field to match claude-code schema
- WorktreeExitDialog: load dirty state on mount, display counts in dialog
- UIState.activeWorktree: add originalCwd, originalBranch, originalHeadCommit

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
New worktreeSessionService.ts exposes read/write/clear functions for the
sidecar JSON file at <chatsDir>/<sessionId>.worktree.json. SessionService
gains getWorktreeSessionPath() so callers don't need to know the layout.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
createUserWorktree() now sets `core.hooksPath` inside the new worktree to
the main repo's hooks directory (.husky preferred, .git/hooks fallback) so
commits inside the worktree run the same pre-commit checks as the main
repo. Mirrors claude-code's performPostCreationSetup logic — skips the
subprocess when the value already matches to avoid ~14ms spawn overhead.

Failures are non-fatal: the worktree is still usable without hooks.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
After creating a worktree, EnterWorktreeTool now writes a sidecar JSON
file at <chatsDir>/<sessionId>.worktree.json with the full session state
(slug, paths, branches, original HEAD SHA). --resume reads this in Phase
C task 7 to restore worktree context. Best-effort: write failures don't
abort the creation.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
After successful keep or remove, ExitWorktreeTool now clears the sidecar
JSON file iff its slug matches the worktree being exited. The slug check
prevents wiping the sidecar when the user exits a worktree that isn't
currently tracked (multiple worktrees on disk, sidecar tracks one).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
New useWorktreeSession hook watches the sidecar JSON file (created by
EnterWorktreeTool, deleted by ExitWorktreeTool) and returns the current
WorktreeSession or null. AppContainer wires it into a new
UIState.activeWorktree field consumed by Footer (Task 6) and
WorktreeExitDialog (Task 8).

A showWorktreeExitDialog state placeholder is added too, hardcoded false
until Task 8 wires the dialog trigger.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Footer renders `⎇ <branch> (<slug>)` when activeWorktree != null, but
only when the user has no custom statusline (their script likely
handles it from the stdin payload itself).

useStatusLine's StatusLineCommandInput gains a `worktree` field with
{name, path, branch, original_cwd, original_branch} — matches claude-code's
schema so statusline scripts can be shared across both CLIs.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
On --resume, if the session has a WorktreeSession sidecar, append an
INFO history item pointing the model at the worktree path so it
continues using it for file operations. Stale sidecars (worktree dir
deleted out-of-band) are cleaned up so the Footer indicator doesn't
go stale.

qwen-code can't process.chdir() the way claude-code does because
Config.targetDir is immutable; the context hint is the equivalent
behavioral cue.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
WorktreeExitDialog renders when the user double-presses Ctrl+C inside a
worktree. On mount it runs `git status --porcelain` and
`git rev-list --count <originalHeadCommit>..HEAD` to show how many
uncommitted files and new commits the user would discard by choosing
"Remove". The dialog never auto-removes — every exit goes through
explicit user confirmation per requirements.

handleExit in AppContainer intercepts the second-press quit when
activeWorktree is set and shows the dialog instead. A new UIAction
handleWorktreeExit(choice) routes the user's choice through removal
(via GitWorktreeService.removeUserWorktree) + sidecar cleanup + /quit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- sidecar lives at ~/.qwen/projects/<sanitized-cwd>/chats/, not ~/.qwen/tmp/<hash>/
- qwen --output-format json emits a JSON array, not NDJSON — jq needs .[]

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Phase C task 8 introduced showWorktreeExitDialog state and the dialog
render in DialogManager, but missed adding the flag to the dialogsVisible
OR expression. DefaultAppLayout only renders DialogManager when
dialogsVisible is true, so the dialog was never shown — second Ctrl+C
in a worktree silently absorbed instead of triggering the prompt.

Caught by Group E E2E tests.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Phase C task 7 originally placed the worktree-restore logic in
AppContainer.tsx (TUI only). E2E Group C exposed that headless and ACP
modes never run AppContainer, so stale sidecars accumulate and the model
loses worktree context after --resume.

Refactor to a shared `restoreWorktreeContext` helper in core, then wire
the three entry points:

- TUI (AppContainer): keep historyManager.addItem(INFO) UX, route via
  the helper.
- Headless (nonInteractiveCli): prepend the notice as a system-reminder
  block on the user prompt; emit a `worktree_restored` system message to
  the JSON adapter so SDK consumers can react.
- ACP (Session.pendingWorktreeNotice): set by acpAgent.loadSession on
  resume, consumed and cleared exactly once on the next #executePrompt.

All three modes call the same helper, so stale-sidecar cleanup is
consistent. Helper covers: missing sidecar, live worktree dir,
deleted worktree dir, regular file at worktreePath, malformed JSON.

5 new unit tests for restoreWorktreeContext (13/13 pass total).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Covers:
- acpAgent.worktree.test.ts (3 tests): loadSession sets
  pendingWorktreeNotice only when worktree dir is live, clears
  stale sidecar otherwise, swallows restoreWorktreeContext errors.
- Session.worktree.test.ts (4 tests): #executePrompt prepends the
  system-reminder block exactly once on first prompt, clears the
  pending notice, second prompt sees no leakage, no-op when nothing
  was set.

E2E via real ACP protocol is impractical without a Zed client; these
tests cover the integration boundaries directly.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

📋 Review Summary

This PR implements Phase C of the worktree capability, adding session persistence, hooks configuration, UI visibility, and exit dialogs for git worktrees. The implementation is thorough with comprehensive test coverage (92 core tests + 25 CLI tests passing), clean abstraction through restoreWorktreeContext shared across TUI/headless/ACP modes, and careful attention to edge cases like stale sidecar cleanup. The code quality is high overall with well-documented intent and consistent error handling patterns.

🔍 General Feedback

  • Strong architectural decisions: The restoreWorktreeContext helper unifies worktree restore behavior across three entry points (TUI, headless, ACP), preventing the divergence that caused the original bug in Group C testing.
  • Excellent test coverage: Session integration tests (enter-worktree.session.integ.test.ts, exit-worktree.session.integ.test.ts) thoroughly cover sidecar write/clear semantics including the important "slug mismatch" edge case.
  • Consistent error handling: All worktree operations use best-effort patterns with debugLogger.warn for non-fatal failures, ensuring worktree functionality degrades gracefully.
  • Well-documented intent: JSDoc comments clearly explain the purpose of WorktreeSession.originalHeadCommit, the sidecar file format, and the three-mode injection mechanisms.
  • Code organization: New files (worktreeSessionService.ts, WorktreeExitDialog.tsx, useWorktreeSession.ts) are appropriately separated and follow existing project conventions.

🎯 Specific Feedback

🟡 High

  • File: packages/cli/src/ui/AppContainer.tsx:2466-2483 — The handleExit callback now has activeWorktree in its dependency array, but setShowWorktreeExitDialog from useState is also used inside the callback without being in the deps. While React guarantees setter stability, this should be explicit for maintainability. Consider adding it to the dependency array or extracting the dialog-showing logic to a separate useCallback.

  • File: packages/cli/src/ui/hooks/useWorktreeSession.ts — The fs.watch call is wrapped in a try-catch but the error is silently swallowed. If the file doesn't exist yet, the watcher won't be set up, and subsequent writes won't trigger updates. Consider watching the parent directory instead, or using fs.watchFile with polling for more reliable detection of file creation.

🟢 Medium

  • File: packages/core/src/tools/exit-worktree.ts:320-345 — The maybeClearWorktreeSession method is called in three places (keep, remove success, remove failure) but each call is independent. If the first call fails silently (as designed), subsequent calls will also fail the same way. Consider adding a single call at the end of the method that runs regardless of the path taken, reducing code duplication and ensuring consistent cleanup.

  • File: packages/cli/src/ui/components/WorktreeExitDialog.tsx:67-85 — The execGit helper function wraps execFile but returns { stdout, code } where code is converted from the error object. This loses stderr output which could be valuable for debugging. Consider including stderr in the return type, especially since git errors can be informative (e.g., "not a git repository").

  • File: packages/core/src/services/gitWorktreeService.ts — The hooksPath configuration logic (prioritizing .husky/ over .git/hooks) duplicates claude-code's parseGitConfigValue optimization comment but doesn't implement the actual value parsing function. The comment references ~14ms spawn overhead which suggests this was copied without the supporting infrastructure. Either add the optimization fully or simplify the comment.

🔵 Low

  • File: packages/cli/src/ui/components/Footer.tsx:151-160 — The worktree indicator uses (Unicode U+2387) which may not render correctly in all terminals. Consider adding a fallback or using the more universally supported (U+2388) or plain text worktree: prefix.

  • File: packages/core/src/services/worktreeSessionService.ts:24-29 — The WorktreeSession.originalHeadCommit field is documented as "Empty string when capture failed" but the type is string without a ? optional marker. This is correct but could be clearer by using originalHeadCommit: string | null to match the null-return pattern of readWorktreeSession.

  • File: packages/cli/src/nonInteractiveCli.ts:393-401 — The <system-reminder> block prepends with double newlines (\n\n) after the closing tag, but the TUI equivalent in AppContainer.tsx:523 uses historyManager.addItem without this spacing. Consider standardizing the format between the two entry points for consistent model experience.

  • File: packages/cli/src/acp-integration/session/Session.ts — The pendingWorktreeNotice field is assigned in acpAgent.ts:345 but the consumption in Session.prompt (lines shown in diff) clears it immediately after first use. This is correct behavior but worth documenting why it's one-shot (to avoid repetitive reminders cluttering the conversation history).

✅ Highlights

  • Excellent E2E test plan: The docs/e2e-tests/worktree-phase-c.md file provides comprehensive coverage across 6 groups (A-F) with clear pass/fail criteria and tmux-based interactive testing scripts. The table at the end summarizing expected results is particularly useful for reviewers.

  • Smart stale sidecar handling: The restoreWorktreeContext function validates that the worktree directory still exists before returning the context message, and proactively deletes stale sidecars. This prevents accumulation of orphan state files.

  • Thoughtful dialog design: WorktreeExitDialog loads dirty state (uncommitted files + new commits) on mount and displays counts in the Remove option label, giving users full context before making an irreversible decision. This mirrors claude-code's UX while adapting to qwen-code's architecture.

  • Three-mode consistency: The same restoreWorktreeContext helper is used in TUI (AppContainer.tsx:517), headless (nonInteractiveCli.ts:390), and ACP (acpAgent.ts:340), each injecting the context through their appropriate mechanism (INFO message, <system-reminder> block, pendingWorktreeNotice field). This unified approach prevents the mode divergence that originally caused Group C failures.

  • Comprehensive session integration tests: The enter-worktree.session.integ.test.ts test verifies all 6 fields of the WorktreeSession sidecar including the full 40-character SHA for originalHeadCommit, ensuring the data captured is sufficient for the exit dialog's commit counting.

LaZzyMan and others added 2 commits May 15, 2026 17:43
…l-b6e48c

# Conflicts:
#	packages/cli/src/acp-integration/acpAgent.ts
…-shot rationale

Two doc-only fixes from PR #4174 review:

- gitWorktreeService.ts: previous hooksPath comment overstated the
  optimization (claimed claude-code's ~14ms saving but we still do a
  read subprocess). Rewrite to be explicit: write-skip only, read
  retained, parseGitConfigValue's full optimization deliberately not
  ported because the read happens once per worktree creation.

- Session.ts: pendingWorktreeNotice doc now explains why it's one-shot
  (after the first prompt the worktree path is already in conversation
  context; re-injecting would clutter history without adding signal).

No behavior change.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@LaZzyMan

Copy link
Copy Markdown
Collaborator Author

Triage of the automated review — applied the review-response five-filter framework. Two findings accepted (doc-only), one false-positive, six declined with rationale. Pushed 2ca730e37.

Per-finding outcomes

# Severity File Verdict
1 🟡 High AppContainer.tsx:2466 handleExit deps ❌ declined-low-impact
2 🟡 High useWorktreeSession.ts fs.watch reliability ❌ false-positive
3 🟢 Medium exit-worktree.ts:320 maybeClearWorktreeSession sites ❌ declined-design
4 🟢 Medium WorktreeExitDialog.tsx:67 execGit stderr ❌ declined-low-impact
5 🟢 Medium gitWorktreeService.ts parseGitConfigValue comment ✅ fixed in 2ca730e37
6 🔵 Low Footer.tsx:151 ⎇ Unicode ❌ declined-low-impact
7 🔵 Low worktreeSessionService.ts:24 originalHeadCommit type ❌ declined-low-impact
8 🔵 Low nonInteractiveCli.ts:393 spacing inconsistency ❌ declined-design
9 🔵 Low Session.ts pendingWorktreeNotice one-shot rationale ✅ fixed in 2ca730e37

Rationale for declines

#1 handleExit depssetShowWorktreeExitDialog is a useState setter. React explicitly guarantees setter identity is stable and react-hooks/exhaustive-deps does not require it. Adding it would be lint noise.

#2 fs.watch — the reviewer suggested "watch the parent directory instead". Re-reading useWorktreeSession.ts:43-65: we already do exactly that — fs.watch(dirPath, ...) after an idempotent mkdir -p. The "file doesn't exist yet" failure mode the reviewer warns about cannot occur.

#3 maybeClearWorktreeSession in 3 sites — the three call-sites are the three SUCCESS return paths. Five earlier return errorResult(...) paths (worktree missing, ownership mismatch, dirty-state guard, unmerged-commits guard, removeUserWorktree failure) must NOT clear the sidecar, otherwise a failed exit would orphan the worktree from the CLI's view. A single finally-style clear would need a "did we succeed?" bookkeeping flag — more code than the current explicit 3 calls.

#4 execGit stderr — the dialog is interactive; on git failure we default to 0 commit(s), 0 file(s) and the user can still see the slug + branch and choose Cancel. Capturing stderr only helps if we log or display it; doing neither keeps the dialog focused on the user decision. Logging git's output from a UI component (with truncation, encoding handling, etc.) is a noticeable cost for an edge case the user can already navigate around.

#6 ⎇ Unicode — Footer already uses Unicode glyphs throughout (🔒, , etc.). Phase C is following the established convention. Switching to worktree: plain-text would diverge from the rest of the bottom bar; switching to (U+2388) trades one obscure codepoint for another. Both and render in iTerm2 / Terminal.app / GNOME Terminal / Alacritty / Kitty out of the box.

#7 originalHeadCommit type — empty-string sentinel chosen for JSON-write friendliness (JSON.stringify(...) emits "", not null which would alter file format) and the falsy-check at the consumer (if (originalHeadCommit) execGit(...)) is consistent with the doc string. Switching to null would change the on-disk sidecar format without a behavioral win.

#8 spacing inconsistency — TUI uses historyManager.addItem({ type: INFO, text }) which renders as its own message bubble; no system-reminder wrapper or trailing spacing is needed because the message is a distinct entry. Headless prepends to the user's prompt text, so the <system-reminder> wrapper + \n\n separator distinguishes the notice from the user's actual prompt that follows. They're intentionally different surface formats because they're different injection mechanisms — standardising would either degrade TUI (add unnecessary wrapping) or degrade headless (merge notice into user prompt indistinguishably).

What changed in 2ca730e37

  • gitWorktreeService.ts hooksPath comment now accurately states that only the WRITE subprocess is skipped; the read remains a subprocess (claude-code's parseGitConfigValue skips both, but the read runs once per worktree creation so the file-parser tax isn't worth it for us).
  • Session.ts pendingWorktreeNotice doc now explains the one-shot semantics: after the first prompt the worktree path is in the conversation context, so re-injection on every turn would add history clutter without signal.

@LaZzyMan LaZzyMan marked this pull request as ready for review May 15, 2026 10:00
@LaZzyMan

Copy link
Copy Markdown
Collaborator Author

E2E Test Report — Phase C

Full end-to-end validation against dist/cli.js. Six tmux/headless groups plus two follow-up rounds covering bug fixes and the three-mode --resume extension. 26 / 26 cases pass after the two regression fixes that the harness itself surfaced.

Test plan

docs/e2e-tests/worktree-phase-c.md — six groups (A–F), each with exact bash steps, jq filters, and pre / post expectations. Groups dispatched to test-engineer agents in parallel with unique tmux session names + temp dirs so they don't collide.

Run matrix

Group Mode Cases Coverage Result
A Sidecar write/clear headless 3 enter_worktree writes 6-field sidecar (incl. originalHeadCommit as full SHA); keep and remove both delete it ✅ 3 / 3
B core.hooksPath headless 3 .husky/ preferred, .git/hooks fallback, hook actually fires from inside the worktree on commit ✅ 3 / 3
C --resume (TUI) tmux 2 INFO history item injected, Footer shows ⎇ worktree-X (X), stale sidecar auto-cleaned when worktree dir gone ✅ 2 / 2
D Footer indicator tmux 2 row appears after enter_worktree, disappears after exit_worktree keep ✅ 2 / 2
E WorktreeExitDialog tmux 5 2nd Ctrl+C → dialog (not quit); dirty-state counts; Keep/Remove/Cancel each behave correctly ✅ 5 / 5
F Real user workflow tmux 2 model writes file to worktree absolute path; custom statusline receives full worktree payload; built-in indicator suppressed ✅ 2 / 2
C-headless retest headless 2 worktree_restored system message + <system-reminder> prompt prefix; stale sidecar cleaned ✅ 2 / 2
ACP integration vitest 7 loadSession sets pendingWorktreeNotice only when worktree alive; first prompt injects + clears; subsequent prompts see no leakage ✅ 7 / 7

Two regressions caught by the harness

Bug 1 (Group E 0/5 → 5/5)showWorktreeExitDialog was missing from the dialogsVisible OR-expression in AppContainer.tsx:2101-2135. DefaultAppLayout only renders DialogManager when dialogsVisible === true, so the dialog mounted but was never shown — second Ctrl+C silently absorbed. Fixed in e847bfce8.

Scope gap (Group C-headless 0/2 → 2/2) — Phase C task 7's --resume logic was placed inside AppContainer.tsx's useEffect. Headless and ACP modes don't run AppContainer, so stale sidecars accumulated and the model lost worktree context after --resume in any non-TUI mode. Fixed in ada0837e2 by extracting a shared restoreWorktreeContext helper that all three entry points call (TUI: historyManager.addItem(INFO), headless: <system-reminder> prompt prefix + worktree_restored JSON event, ACP: Session.pendingWorktreeNotice one-shot). 7 ACP integration tests added in b16adb5e7.

Evidence highlights

Group A1 — sidecar from enter_worktree name='a1-test':

{
  "slug": "a1-test",
  "worktreePath": "/tmp/.../.qwen/worktrees/a1-test",
  "worktreeBranch": "worktree-a1-test",
  "originalCwd": "/tmp/...",
  "originalBranch": "main",
  "originalHeadCommit": "d4eca75fe964f30a974e5a1e4f5184502e934047"
}

Group B3pre-commit hook in main repo .git/hooks/ fired from inside the worktree, writing /tmp/qwen-wt-hook-marker on commit.

Group D1 — Footer capture:

  ⎇ worktree-d1-test (d1-test)                                                       2.2% context used
  YOLO mode (shift + tab to cycle)

Group E2 — Dialog body for a dirty worktree (1 new commit + 1 uncommitted file):

│ ⎇ Active worktree: "e2-test" (worktree-e2-test)
│   • 1 new commit(s) on worktree-e2-test
│   • 2 uncommitted file(s)
│   2. Remove worktree and branch (discards 1 commit(s), 2 file(s))

Group F2 — JSON payload captured by a custom statusline command via stdin:

"worktree": {
  "name": "f2-test",
  "path": ".../.qwen/worktrees/f2-test",
  "branch": "worktree-f2-test",
  "original_cwd": ".../qwen-wt-phc-F2-XXXXXX",
  "original_branch": "main"
}

Built-in row was suppressed when the custom statusline was active.

C-headless TC1worktree_restored system message emitted by headless --resume:

{
  "type": "system",
  "subtype": "worktree_restored",
  "data": {
    "slug": "c1head",
    "path": ".../.qwen/worktrees/c1head",
    "branch": "worktree-c1head"
  }
}

Unit test coverage (collocated)

Run as a one-liner regression net:

cd packages/core && npx vitest run \
  src/services/worktreeSessionService.test \
  src/services/gitWorktreeService.test \
  src/services/gitWorktreeService.hooks.integ.test \
  src/tools/enter-worktree.test \
  src/tools/enter-worktree.session.integ.test \
  src/tools/exit-worktree.test \
  src/tools/exit-worktree.session.integ.test
# → 7 test files, 84 passed
cd packages/cli && npx vitest run \
  src/ui/components/Footer.test \
  src/ui/components/DialogManager.test \
  src/acp-integration/acpAgent.worktree.test \
  src/acp-integration/session/Session.worktree.test
# → 4 test files, 25 passed

Limitations

  • ACP E2E uses unit-level integration tests (7 cases verifying the loadSessionpendingWorktreeNotice#executePrompt flow), not a real ACP stdio client. Driving a Zed-style JSON-RPC channel without the Zed editor adds harness complexity that isn't worth the value — the boundaries are mocked tightly.
  • Verified only on macOS (darwin 24.6.0, Node 22.21.1). Cross-platform behavior depends on simple-git / fs/promises / execFile which are platform-agnostic.

CI surfaced TypeError: config.getResumedSessionData is not a function
across 12 tests in nonInteractiveCli.test.ts. The Phase C ada0837
commit added a worktree-restore call in the headless path that probes
config.getResumedSessionData(); the mock Config never had that method.

Return undefined to short-circuit the restore block — these tests
don't exercise --resume.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@github-actions

github-actions Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Summary

Package Lines Statements Functions Branches
CLI 77.3% 77.3% 79.91% 79.88%
Core 79.42% 79.42% 82.07% 82.86%
CLI Package - Full Text Report
-------------------|---------|----------|---------|---------|-------------------
File               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------|---------|----------|---------|---------|-------------------
All files          |    77.3 |    79.88 |   79.91 |    77.3 |                   
 src               |    75.9 |    69.11 |   80.55 |    75.9 |                   
  gemini.tsx       |   68.53 |     66.4 |   76.47 |   68.53 | ...29,946-949,957 
  ...ractiveCli.ts |   80.23 |     68.3 |   78.57 |   80.23 | ...1054,1092,1195 
  ...liCommands.ts |   74.51 |    73.17 |     100 |   74.51 | ...41-265,290,391 
  ...ActiveAuth.ts |     100 |     87.5 |     100 |     100 | 66-80             
 ...cp-integration |   61.97 |    65.24 |   78.12 |   61.97 |                   
  acpAgent.ts      |   63.32 |    65.35 |   83.05 |   63.32 | ...2112,2126-2134 
  authMethods.ts   |   12.19 |      100 |       0 |   12.19 | 11-31,34-38,41-50 
  errorCodes.ts    |       0 |        0 |       0 |       0 | 1-22              
  ...DirContext.ts |     100 |      100 |     100 |     100 |                   
 ...ration/service |   68.65 |    83.33 |   66.66 |   68.65 |                   
  filesystem.ts    |   68.65 |    83.33 |   66.66 |   68.65 | ...32,77-94,97-98 
 ...ration/session |   77.07 |    72.32 |   86.25 |   77.07 |                   
  ...ryReplayer.ts |   67.34 |     75.6 |   81.81 |   67.34 | ...54-269,282-283 
  Session.ts       |   76.45 |    71.11 |   88.46 |   76.45 | ...2566,2572-2575 
  ...entTracker.ts |   90.85 |    84.84 |      90 |   90.85 | ...35,199,251-260 
  index.ts         |       0 |        0 |       0 |       0 | 1-40              
  ...ssionUtils.ts |   84.21 |    77.77 |     100 |   84.21 | ...37-153,209-211 
  types.ts         |       0 |        0 |       0 |       0 | 1                 
 ...ssion/emitters |   96.01 |    90.75 |    92.3 |   96.01 |                   
  BaseEmitter.ts   |   76.92 |    66.66 |      80 |   76.92 | 23-24,39-40,55-56 
  ...ageEmitter.ts |     100 |    89.47 |     100 |     100 | 109,111           
  PlanEmitter.ts   |     100 |      100 |     100 |     100 |                   
  ...allEmitter.ts |   98.06 |     92.3 |     100 |   98.06 | 227-228,327,335   
  index.ts         |       0 |        0 |       0 |       0 | 1-10              
 ...ession/rewrite |   90.36 |    87.83 |   94.11 |   90.36 |                   
  LlmRewriter.ts   |      81 |       84 |     100 |      81 | ...,88-89,155-159 
  ...Middleware.ts |   95.83 |    85.71 |     100 |   95.83 | 119,127-129       
  TurnBuffer.ts    |     100 |      100 |     100 |     100 |                   
  config.ts        |     100 |      100 |     100 |     100 |                   
  index.ts         |     100 |      100 |     100 |     100 |                   
  types.ts         |       0 |        0 |       0 |       0 | 1                 
 src/auth          |    97.7 |    94.81 |   95.45 |    97.7 |                   
  allProviders.ts  |     100 |      100 |     100 |     100 |                   
  ...iderConfig.ts |    97.6 |    95.04 |     100 |    97.6 | ...61,411,433-434 
  types.ts         |       0 |        0 |       0 |       0 | 1                 
 src/auth/install  |   98.57 |    88.88 |     100 |   98.57 |                   
  ...nstallPlan.ts |   98.57 |    88.88 |     100 |   98.57 | 80,93             
 ...viders/alibaba |   96.96 |    66.66 |   66.66 |   96.96 |                   
  ...baStandard.ts |     100 |      100 |     100 |     100 |                   
  codingPlan.ts    |   93.67 |    66.66 |   66.66 |   93.67 | 83,87-89,94       
  tokenPlan.ts     |     100 |      100 |     100 |     100 |                   
 ...oviders/custom |     100 |      100 |     100 |     100 |                   
  ...omProvider.ts |     100 |      100 |     100 |     100 |                   
 ...roviders/oauth |    91.5 |    77.03 |   97.05 |    91.5 |                   
  openrouter.ts    |   84.37 |    33.33 |     100 |   84.37 | 43-48             
  ...outerOAuth.ts |    91.9 |    79.06 |   96.87 |    91.9 | ...53-655,699-701 
 ...ers/thirdParty |     100 |      100 |     100 |     100 |                   
  deepseek.ts      |     100 |      100 |     100 |     100 |                   
  idealab.ts       |     100 |      100 |     100 |     100 |                   
  minimax.ts       |     100 |      100 |     100 |     100 |                   
  modelscope.ts    |     100 |      100 |     100 |     100 |                   
  zai.ts           |     100 |      100 |     100 |     100 |                   
 src/commands      |   47.93 |    85.71 |   43.47 |   47.93 |                   
  auth.ts          |     100 |    83.33 |     100 |     100 | 11,14             
  channel.ts       |   56.66 |      100 |       0 |   56.66 | 15-19,27-34       
  extensions.tsx   |   96.55 |      100 |      50 |   96.55 | 37                
  hooks.tsx        |   66.66 |      100 |       0 |   66.66 | 20-24             
  mcp.ts           |   94.73 |      100 |      50 |   94.73 | 28                
  review.ts        |   51.85 |      100 |       0 |   51.85 | 24-35,38          
  serve.ts         |    7.74 |      100 |       0 |    7.74 | ...51-147,149-230 
 ...mmands/channel |   39.25 |    79.45 |      50 |   39.25 |                   
  ...l-registry.ts |    8.57 |      100 |       0 |    8.57 | 6-21,24-42        
  config-utils.ts  |      92 |      100 |   66.66 |      92 | 21-26             
  configure.ts     |    14.7 |      100 |       0 |    14.7 | 18-21,23-84       
  pairing.ts       |   26.31 |      100 |       0 |   26.31 | ...30,40-50,52-65 
  pidfile.ts       |   96.34 |    86.95 |     100 |   96.34 | 49,59,91          
  start.ts         |   30.98 |       52 |   69.23 |   30.98 | ...72-475,484-486 
  status.ts        |   17.85 |      100 |       0 |   17.85 | 15-26,32-76       
  stop.ts          |      20 |      100 |       0 |      20 | 14-48             
 ...nds/extensions |    84.5 |    88.95 |   81.81 |    84.5 |                   
  consent.ts       |   71.65 |    89.28 |   42.85 |   71.65 | ...85-141,156-162 
  disable.ts       |     100 |      100 |     100 |     100 |                   
  enable.ts        |     100 |      100 |     100 |     100 |                   
  install.ts       |    75.6 |    66.66 |   66.66 |    75.6 | ...39-142,145-153 
  link.ts          |     100 |      100 |     100 |     100 |                   
  list.ts          |     100 |      100 |     100 |     100 |                   
  new.ts           |     100 |      100 |     100 |     100 |                   
  settings.ts      |   99.15 |      100 |   83.33 |   99.15 | 151               
  uninstall.ts     |    37.5 |      100 |   33.33 |    37.5 | 23-45,57-64,67-70 
  update.ts        |   96.32 |      100 |     100 |   96.32 | 101-105           
  utils.ts         |   60.24 |    28.57 |     100 |   60.24 | ...81,83-87,89-93 
 ...les/mcp-server |       0 |        0 |       0 |       0 |                   
  example.ts       |       0 |        0 |       0 |       0 | 1-60              
 src/commands/mcp  |   92.29 |    86.08 |   88.88 |   92.29 |                   
  add.ts           |     100 |    98.03 |     100 |     100 | 293               
  list.ts          |   91.22 |    80.76 |      80 |   91.22 | ...19-121,146-147 
  reconnect.ts     |   76.72 |    71.42 |   85.71 |   76.72 | 35-48,153-175     
  remove.ts        |     100 |       80 |     100 |     100 | 21-25             
 ...ommands/review |   11.57 |      100 |       0 |   11.57 |                   
  cleanup.ts       |   17.94 |      100 |       0 |   17.94 | ...01-106,108-109 
  deterministic.ts |   13.75 |      100 |       0 |   13.75 | ...22-738,740-741 
  fetch-pr.ts      |   11.36 |      100 |       0 |   11.36 | ...80-201,203-204 
  load-rules.ts    |   11.32 |      100 |       0 |   11.32 | ...41-153,155-156 
  pr-context.ts    |    6.22 |      100 |       0 |    6.22 | ...97-312,314-315 
  presubmit.ts     |    9.35 |      100 |       0 |    9.35 | ...62-287,289-290 
 ...nds/review/lib |      30 |      100 |       0 |      30 |                   
  gh.ts            |   22.58 |      100 |       0 |   22.58 | ...49,53-54,62-69 
  git.ts           |   22.72 |      100 |       0 |   22.72 | 15-18,29-39,43-44 
  paths.ts         |   52.94 |      100 |       0 |   52.94 | ...26,37-38,42-43 
 src/config        |    92.8 |    85.18 |   88.09 |    92.8 |                   
  auth.ts          |   86.98 |    80.32 |     100 |   86.98 | ...26-227,243-244 
  config.ts        |   88.31 |    84.87 |      80 |   88.31 | ...1841,1843-1851 
  keyBindings.ts   |   96.55 |       50 |     100 |   96.55 | 193-196           
  ...idersScope.ts |      92 |       90 |     100 |      92 | 11-12             
  sandboxConfig.ts |   61.64 |    71.87 |   66.66 |   61.64 | ...54-68,73,77-89 
  settings.ts      |   85.76 |    87.25 |   89.18 |   85.76 | ...1148,1153-1156 
  ...ingsSchema.ts |     100 |      100 |     100 |     100 |                   
  ...tedFolders.ts |   96.22 |       94 |     100 |   96.22 | ...88-190,205-206 
 ...nfig/migration |   94.89 |    78.94 |   83.33 |   94.89 |                   
  index.ts         |   94.87 |    88.88 |     100 |   94.87 | 91-92             
  scheduler.ts     |   96.55 |    77.77 |     100 |   96.55 | 19-20             
  types.ts         |       0 |        0 |       0 |       0 | 1                 
 ...ation/versions |   94.74 |       96 |     100 |   94.74 |                   
  ...-v2-shared.ts |     100 |      100 |     100 |     100 |                   
  v1-to-v2.ts      |   81.75 |    90.19 |     100 |   81.75 | ...28-229,231-247 
  v2-to-v3.ts      |     100 |      100 |     100 |     100 |                   
  v3-to-v4.ts      |     100 |      100 |     100 |     100 |                   
 src/core          |     100 |      100 |     100 |     100 |                   
  auth.ts          |     100 |      100 |     100 |     100 |                   
  initializer.ts   |     100 |      100 |     100 |     100 |                   
  theme.ts         |     100 |      100 |     100 |     100 |                   
 src/dualOutput    |   63.09 |    64.51 |   55.55 |   63.09 |                   
  ...tputBridge.ts |   62.94 |    65.51 |   56.25 |   62.94 | ...22-323,331-334 
  ...utContext.tsx |     100 |      100 |     100 |     100 |                   
  index.ts         |       0 |        0 |       0 |       0 | 1-8               
 src/export        |       0 |        0 |       0 |       0 |                   
  index.ts         |       0 |        0 |       0 |       0 | 1-7               
 src/generated     |     100 |      100 |     100 |     100 |                   
  git-commit.ts    |     100 |      100 |     100 |     100 |                   
 src/i18n          |   81.47 |    75.94 |   65.71 |   81.47 |                   
  index.ts         |   63.68 |    69.56 |   53.84 |   63.68 | ...70-271,281-286 
  languages.ts     |   96.92 |    86.66 |     100 |   96.92 | 134-135,167,184   
  ...nslateKeys.ts |     100 |      100 |     100 |     100 |                   
  ...lationDict.ts |   93.33 |    66.66 |     100 |   93.33 | 15                
 src/i18n/locales  |     100 |      100 |     100 |     100 |                   
  ca.js            |     100 |      100 |     100 |     100 |                   
  de.js            |     100 |      100 |     100 |     100 |                   
  en.js            |     100 |      100 |     100 |     100 |                   
  fr.js            |     100 |      100 |     100 |     100 |                   
  ja.js            |     100 |      100 |     100 |     100 |                   
  pt.js            |     100 |      100 |     100 |     100 |                   
  ru.js            |     100 |      100 |     100 |     100 |                   
  zh-TW.js         |     100 |      100 |     100 |     100 |                   
  zh.js            |     100 |      100 |     100 |     100 |                   
 ...nonInteractive |   72.57 |    71.12 |   74.07 |   72.57 |                   
  session.ts       |   76.64 |     69.4 |   85.71 |   76.64 | ...23-824,833-843 
  types.ts         |    42.5 |      100 |   33.33 |    42.5 | ...80-581,584-585 
 ...active/control |   77.04 |    88.23 |      80 |   77.04 |                   
  ...rolContext.ts |    7.14 |        0 |       0 |    7.14 | 49-84             
  ...Dispatcher.ts |   91.66 |    91.83 |   88.88 |   91.66 | ...54-372,388,391 
  ...rolService.ts |       8 |        0 |       0 |       8 | 46-179            
 ...ol/controllers |    7.04 |       80 |   13.33 |    7.04 |                   
  ...Controller.ts |   19.32 |      100 |      60 |   19.32 | 81-118,127-210    
  ...Controller.ts |       0 |        0 |       0 |       0 | 1-56              
  ...Controller.ts |    3.96 |      100 |   11.11 |    3.96 | ...61-379,389-494 
  ...Controller.ts |   14.06 |      100 |       0 |   14.06 | ...82-117,130-133 
  ...Controller.ts |    5.21 |      100 |       0 |    5.21 | ...21-433,442-471 
 .../control/types |       0 |        0 |       0 |       0 |                   
  serviceAPIs.ts   |       0 |        0 |       0 |       0 | 1                 
 ...Interactive/io |   97.98 |     93.7 |   95.18 |   97.98 |                   
  ...putAdapter.ts |   97.89 |    92.82 |   98.07 |   97.89 | ...1303,1398-1399 
  ...putAdapter.ts |      96 |     90.9 |   85.71 |      96 | 51-52             
  ...nputReader.ts |     100 |    94.73 |     100 |     100 | 67                
  ...putAdapter.ts |   98.28 |      100 |      90 |   98.28 | 81-82,122-123     
  index.ts         |     100 |      100 |     100 |     100 |                   
 src/patches       |       0 |        0 |       0 |       0 |                   
  is-in-ci.ts      |       0 |        0 |       0 |       0 | 1-17              
 src/remoteInput   |   86.98 |       75 |   85.71 |   86.98 |                   
  ...utContext.tsx |     100 |      100 |     100 |     100 |                   
  ...putWatcher.ts |   88.12 |    76.08 |   91.66 |   88.12 | ...21-222,233-236 
  index.ts         |       0 |        0 |       0 |       0 | 1-8               
 src/serve         |    79.3 |     78.8 |   92.85 |    79.3 |                   
  auth.ts          |   88.49 |    88.63 |     100 |   88.49 | ...49-150,153-155 
  capabilities.ts  |     100 |     90.9 |     100 |     100 | 264               
  ...usProvider.ts |   67.01 |    51.42 |     100 |   67.01 | ...40-245,278-286 
  debugMode.ts     |     100 |      100 |     100 |     100 |                   
  demo.ts          |     100 |      100 |     100 |     100 |                   
  envSnapshot.ts   |    92.3 |       84 |     100 |    92.3 | 108-111,170-177   
  eventBus.ts      |     100 |      100 |     100 |     100 |                   
  httpAcpBridge.ts |   79.62 |    78.84 |   96.38 |   79.62 | ...4246,4277-4318 
  ...oryChannel.ts |     100 |      100 |     100 |     100 |                   
  index.ts         |       0 |        0 |       0 |       0 | 1-106             
  loopbackBinds.ts |     100 |      100 |     100 |     100 |                   
  runQwenServe.ts  |   73.98 |    87.83 |   55.55 |   73.98 | ...94-710,735-737 
  server.ts        |   86.18 |    82.94 |   90.62 |   86.18 | ...2478,2543-2552 
  status.ts        |     100 |      100 |     100 |     100 |                   
  types.ts         |     100 |      100 |     100 |     100 |                   
  ...paceAgents.ts |   64.87 |    70.45 |    90.9 |   64.87 | ...1306,1316-1326 
  ...paceMemory.ts |   87.13 |    78.46 |     100 |   87.13 | ...54-361,421-428 
 src/serve/auth    |   86.54 |    78.75 |   93.75 |   86.54 |                   
  deviceFlow.ts    |   96.33 |    79.51 |    97.5 |   96.33 | ...1526,1630,1700 
  ...owProvider.ts |   45.23 |    74.07 |      75 |   45.23 | ...90-359,375,379 
 src/serve/fs      |   84.85 |    79.75 |     100 |   84.85 |                   
  audit.ts         |     100 |    96.15 |     100 |     100 | 201               
  errors.ts        |     100 |      100 |     100 |     100 |                   
  index.ts         |     100 |      100 |     100 |     100 |                   
  paths.ts         |   77.82 |    77.08 |     100 |   77.82 | ...64,493-497,510 
  policy.ts        |   90.32 |    89.18 |     100 |   90.32 | 142-150           
  ...FileSystem.ts |   83.55 |    76.22 |     100 |   83.55 | ...1859,1886-1887 
 src/serve/routes  |   89.41 |       70 |     100 |   89.41 |                   
  ...ceFileRead.ts |   94.41 |    76.92 |     100 |   94.41 | ...28-329,390-392 
  ...eFileWrite.ts |    82.1 |    60.52 |     100 |    82.1 | ...42-244,247-249 
 src/services      |   91.67 |    91.21 |   97.56 |   91.67 |                   
  ...mandLoader.ts |     100 |    93.75 |     100 |     100 | 93                
  ...killLoader.ts |     100 |    96.15 |     100 |     100 | 47                
  ...andService.ts |    98.7 |      100 |     100 |    98.7 | 107               
  ...mandLoader.ts |   86.83 |    83.87 |     100 |   86.83 | ...30-335,340-345 
  ...omptLoader.ts |   75.84 |    80.64 |   83.33 |   75.84 | ...10-211,277-278 
  ...mandLoader.ts |     100 |      100 |     100 |     100 |                   
  ...nd-factory.ts |   91.42 |    91.66 |     100 |   91.42 | 128,137-144       
  ...ation-tool.ts |     100 |    95.45 |     100 |     100 | 125               
  ...ndMetadata.ts |   98.21 |    96.66 |     100 |   98.21 | 83,87             
  commandUtils.ts  |      96 |     90.9 |     100 |      96 | 48                
  ...and-parser.ts |   90.69 |    85.71 |     100 |   90.69 | 63-66             
  ...ionService.ts |     100 |      100 |     100 |     100 |                   
  types.ts         |     100 |      100 |     100 |     100 |                   
 ...ght/generators |    85.9 |    85.61 |   90.47 |    85.9 |                   
  DataProcessor.ts |   85.63 |     85.6 |   92.85 |   85.63 | ...1122,1126-1133 
  ...tGenerator.ts |   98.21 |    85.71 |     100 |   98.21 | 46                
  ...teRenderer.ts |   45.45 |      100 |       0 |   45.45 | 13-51             
 .../insight/types |       0 |       50 |      50 |       0 |                   
  ...sightTypes.ts |       0 |        0 |       0 |       0 |                   
  ...sightTypes.ts |       0 |        0 |       0 |       0 | 1                 
 ...mpt-processors |   97.27 |    94.04 |     100 |   97.27 |                   
  ...tProcessor.ts |     100 |      100 |     100 |     100 |                   
  ...eProcessor.ts |   94.52 |    84.21 |     100 |   94.52 | 46-47,93-94       
  ...tionParser.ts |     100 |      100 |     100 |     100 |                   
  ...lProcessor.ts |   97.41 |    95.65 |     100 |   97.41 | 95-98             
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/services/tips |   97.35 |    83.07 |     100 |   97.35 |                   
  index.ts         |     100 |      100 |     100 |     100 |                   
  tipHistory.ts    |   92.45 |       70 |     100 |   92.45 | ...22,144,151,160 
  tipRegistry.ts   |     100 |    95.23 |     100 |     100 | 33                
  tipScheduler.ts  |     100 |    91.66 |     100 |     100 | 55                
 src/test-utils    |   93.75 |    83.33 |      80 |   93.75 |                   
  ...omMatchers.ts |   69.69 |       50 |      50 |   69.69 | 32-35,37-39,45-47 
  ...andContext.ts |     100 |      100 |     100 |     100 |                   
  render.tsx       |     100 |      100 |     100 |     100 |                   
 src/ui            |   65.07 |    73.02 |   60.34 |   65.07 |                   
  App.tsx          |     100 |      100 |     100 |     100 |                   
  AppContainer.tsx |   63.11 |    64.56 |      50 |   63.11 | ...3140,3144-3148 
  ...tionNudge.tsx |    9.58 |      100 |       0 |    9.58 | 24-94             
  ...ackDialog.tsx |   29.23 |      100 |       0 |   29.23 | 25-75             
  ...tionNudge.tsx |    7.69 |      100 |       0 |    7.69 | 25-103            
  colors.ts        |      60 |      100 |   35.29 |      60 | ...52,54-55,60-61 
  constants.ts     |     100 |      100 |     100 |     100 |                   
  keyMatchers.ts   |   95.91 |    97.05 |     100 |   95.91 | 25-26             
  ...tic-colors.ts |     100 |      100 |     100 |     100 |                   
  ...inePresets.ts |   98.17 |    88.88 |     100 |   98.17 | ...12,239,387-389 
  textConstants.ts |     100 |      100 |     100 |     100 |                   
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/ui/auth       |   55.06 |    51.13 |   35.48 |   55.06 |                   
  AuthDialog.tsx   |   64.26 |    44.44 |   16.66 |   64.26 | ...59,366-388,392 
  ...nProgress.tsx |       0 |        0 |       0 |       0 | 1-64              
  ...etupSteps.tsx |    39.5 |       32 |   38.46 |    39.5 | ...69,472,478,481 
  useAuth.ts       |   76.63 |    68.29 |     100 |   76.63 | ...48,493-499,560 
  ...rSetupFlow.ts |   44.61 |    33.33 |      50 |   44.61 | ...57-378,395-438 
 src/ui/commands   |   73.46 |    81.23 |   81.61 |   73.46 |                   
  aboutCommand.ts  |     100 |      100 |     100 |     100 |                   
  agentsCommand.ts |   83.78 |      100 |      60 |   83.78 | 30-32,42-44       
  ...odeCommand.ts |     100 |      100 |     100 |     100 |                   
  arenaCommand.ts  |   62.81 |    58.73 |   65.21 |   62.81 | ...91-596,681-689 
  authCommand.ts   |     100 |      100 |     100 |     100 |                   
  branchCommand.ts |     100 |      100 |     100 |     100 |                   
  btwCommand.ts    |   95.59 |    71.42 |     100 |   95.59 | 72,154-159        
  bugCommand.ts    |   81.13 |    71.42 |     100 |   81.13 | 60-69             
  clearCommand.ts  |      92 |    76.47 |     100 |      92 | 43-44,72-73,91-92 
  ...essCommand.ts |    64.7 |       50 |      75 |    64.7 | ...48-149,163-166 
  ...extCommand.ts |   34.78 |    22.22 |   45.45 |   34.78 | ...86-521,532-533 
  copyCommand.ts   |   98.28 |    94.89 |     100 |   98.28 | ...80,280,321,327 
  deleteCommand.ts |     100 |      100 |     100 |     100 |                   
  diffCommand.ts   |   99.02 |    86.11 |     100 |   99.02 | 222,226           
  ...ryCommand.tsx |   68.09 |    77.77 |   77.77 |   68.09 | ...56-261,315-323 
  docsCommand.ts   |     100 |    88.88 |     100 |     100 | 25                
  doctorCommand.ts |   95.06 |    88.28 |     100 |   95.06 | ...92-293,320-321 
  dreamCommand.ts  |      75 |    66.66 |   66.66 |      75 | 22-27,44-47       
  editorCommand.ts |     100 |      100 |     100 |     100 |                   
  exportCommand.ts |   98.25 |    91.02 |     100 |   98.25 | ...81,198-199,364 
  ...onsCommand.ts |   48.66 |     90.9 |   63.63 |   48.66 | ...05-109,159-211 
  forgetCommand.ts |   26.82 |      100 |      50 |   26.82 | 18-51             
  goalCommand.ts   |   91.25 |    83.33 |      90 |   91.25 | ...83-186,198-201 
  helpCommand.ts   |     100 |      100 |     100 |     100 |                   
  hooksCommand.ts  |    20.4 |       40 |      40 |    20.4 | ...48-180,204-205 
  ideCommand.ts    |   60.75 |    64.28 |   41.17 |   60.75 | ...05-306,310-324 
  initCommand.ts   |   84.33 |    72.72 |     100 |   84.33 | 68,82-87,89-94    
  ...ghtCommand.ts |   74.56 |    68.42 |     100 |   74.56 | ...31-245,250-273 
  ...ageCommand.ts |   92.17 |    82.69 |     100 |   92.17 | ...43,164,173-183 
  lspCommand.ts    |     100 |    86.95 |     100 |     100 | 31,101-102        
  ...elsCommand.ts |     100 |      100 |     100 |     100 |                   
  mcpCommand.ts    |     100 |      100 |     100 |     100 |                   
  memoryCommand.ts |     100 |      100 |     100 |     100 |                   
  modelCommand.ts  |   75.09 |    78.18 |      75 |   75.09 | ...20-225,262-267 
  ...onsCommand.ts |     100 |      100 |     100 |     100 |                   
  planCommand.ts   |   78.82 |    76.92 |     100 |   78.82 | 30-35,51-56,68-73 
  quitCommand.ts   |     100 |      100 |     100 |     100 |                   
  recapCommand.ts  |   21.81 |      100 |      50 |   21.81 | 24-73             
  ...berCommand.ts |   32.43 |      100 |      50 |   32.43 | 23-57             
  renameCommand.ts |   85.71 |    86.04 |     100 |   85.71 | ...02-209,216-221 
  ...oreCommand.ts |    92.3 |    87.87 |     100 |    92.3 | ...,83-88,129-130 
  resumeCommand.ts |     100 |      100 |     100 |     100 |                   
  rewindCommand.ts |      80 |      100 |      50 |      80 | 19-21             
  ...ngsCommand.ts |     100 |      100 |     100 |     100 |                   
  ...hubCommand.ts |   81.43 |    65.21 |      80 |   81.43 | ...70-173,176-179 
  skillsCommand.ts |   15.04 |      100 |      25 |   15.04 | ...90-106,109-136 
  statsCommand.ts  |   88.19 |    84.21 |     100 |   88.19 | ...,58-61,143-146 
  ...ineCommand.ts |     100 |      100 |     100 |     100 |                   
  ...aryCommand.ts |    6.46 |      100 |      50 |    6.46 | 31-329            
  tasksCommand.ts  |   77.22 |    72.13 |     100 |   77.22 | ...46-150,172-177 
  ...tupCommand.ts |     100 |      100 |     100 |     100 |                   
  themeCommand.ts  |     100 |      100 |     100 |     100 |                   
  toolsCommand.ts  |     100 |      100 |     100 |     100 |                   
  trustCommand.ts  |     100 |      100 |     100 |     100 |                   
  types.ts         |     100 |      100 |     100 |     100 |                   
  vimCommand.ts    |   54.54 |      100 |      50 |   54.54 | 19-29             
 src/ui/components |   65.76 |    74.44 |    69.5 |   65.76 |                   
  AboutBox.tsx     |     100 |      100 |     100 |     100 |                   
  AnsiOutput.tsx   |   65.57 |      100 |      50 |   65.57 | 69-90             
  ApiKeyInput.tsx  |       0 |        0 |       0 |       0 | 1-97              
  AppHeader.tsx    |   89.39 |       75 |     100 |   89.39 | 35,37-42,44       
  ...odeDialog.tsx |     9.7 |      100 |       0 |     9.7 | 35-47,50-182      
  AsciiArt.ts      |     100 |      100 |     100 |     100 |                   
  ...Indicator.tsx |   14.63 |      100 |       0 |   14.63 | 18-56             
  ...TextInput.tsx |   77.01 |       76 |     100 |   77.01 | ...20,234-236,263 
  Composer.tsx     |    80.8 |     64.7 |     100 |    80.8 | ...85,103,154,167 
  ...entPrompt.tsx |     100 |      100 |     100 |     100 |                   
  ...ryDisplay.tsx |   75.89 |    62.06 |     100 |   75.89 | ...,88,93-108,113 
  ...geDisplay.tsx |   68.42 |    57.14 |     100 |   68.42 | 16-17,31-32,42-50 
  ...ification.tsx |   28.57 |      100 |       0 |   28.57 | 16-36             
  ...gProfiler.tsx |       0 |        0 |       0 |       0 | 1-36              
  ...ogManager.tsx |   12.06 |      100 |       0 |   12.06 | 65-504            
  ...ngsDialog.tsx |    8.44 |      100 |       0 |    8.44 | 37-195            
  ExitWarning.tsx  |     100 |      100 |     100 |     100 |                   
  ...hProgress.tsx |    87.8 |    33.33 |     100 |    87.8 | 28-31,56          
  ...ustDialog.tsx |     100 |      100 |     100 |     100 |                   
  Footer.tsx       |   76.59 |    48.64 |     100 |   76.59 | ...35-136,175-180 
  ...ngSpinner.tsx |   68.42 |       80 |      50 |   68.42 | 35-52,73,80-81    
  GoalPill.tsx     |   76.19 |    81.81 |     100 |   76.19 | 24-30,46-50       
  Header.tsx       |   98.62 |    94.28 |     100 |   98.62 | 162,164           
  Help.tsx         |   98.32 |    89.88 |     100 |   98.32 | ...24,381,447-448 
  ...emDisplay.tsx |    61.7 |       36 |     100 |    61.7 | ...42,345,348-354 
  ...ngeDialog.tsx |     100 |      100 |     100 |     100 |                   
  InputPrompt.tsx  |   82.75 |    78.96 |   83.33 |   82.75 | ...1425,1490,1540 
  ...Shortcuts.tsx |   20.87 |      100 |       0 |   20.87 | ...6,49-51,67-125 
  ...Indicator.tsx |     100 |    91.42 |     100 |     100 | 65,74             
  ...firmation.tsx |   91.42 |      100 |      50 |   91.42 | 26-31             
  MainContent.tsx  |   81.75 |       75 |     100 |   81.75 | ...70-274,282-286 
  ...elsDialog.tsx |   71.05 |    69.11 |   72.72 |   71.05 | ...77,590,601-603 
  MemoryDialog.tsx |    55.1 |    54.54 |   57.14 |    55.1 | ...56,368,381-383 
  ...geDisplay.tsx |       0 |        0 |       0 |       0 | 1-41              
  ModelDialog.tsx  |   80.12 |    63.55 |     100 |   80.12 | ...39-555,612-616 
  ...tsDisplay.tsx |     100 |    97.22 |     100 |     100 | 270               
  ...fications.tsx |   18.18 |      100 |       0 |   18.18 | 15-58             
  ...onsDialog.tsx |    2.13 |      100 |       0 |    2.13 | 62-133,148-1004   
  ...ryDisplay.tsx |     100 |      100 |     100 |     100 |                   
  ...icePrompt.tsx |   92.64 |    85.71 |     100 |   92.64 | 102-106,134-139   
  PrepareLabel.tsx |   91.66 |    77.27 |     100 |   91.66 | 73-75,77-79,110   
  ...atePrompt.tsx |    8.57 |      100 |       0 |    8.57 | 24-55,58-134      
  ...geDisplay.tsx |     100 |      100 |     100 |     100 |                   
  ...ngDisplay.tsx |   21.42 |      100 |       0 |   21.42 | 13-39             
  ...hProgress.tsx |   85.25 |    88.46 |     100 |   85.25 | 121-147           
  ...dSelector.tsx |   41.26 |    61.53 |   71.42 |   41.26 | ...74-472,476-520 
  ...ionPicker.tsx |   83.66 |    72.13 |     100 |   83.66 | ...96,402,444-466 
  ...onPreview.tsx |   92.42 |    84.37 |     100 |   92.42 | ...,70-71,143-145 
  ...ryDisplay.tsx |     100 |      100 |     100 |     100 |                   
  ...putPrompt.tsx |   72.56 |       80 |      40 |   72.56 | ...06-109,114-117 
  ...ngsDialog.tsx |   66.27 |    71.16 |      75 |   66.27 | ...12-820,826-827 
  ...ionDialog.tsx |    87.8 |      100 |   33.33 |    87.8 | 36-39,44-51       
  ...putPrompt.tsx |    15.9 |      100 |       0 |    15.9 | 20-63             
  ...Indicator.tsx |   57.14 |      100 |       0 |   57.14 | 12-15             
  ...MoreLines.tsx |      28 |      100 |       0 |      28 | 18-40             
  ...ionPicker.tsx |   17.59 |      100 |       0 |   17.59 | 55-172            
  StatsDisplay.tsx |     100 |      100 |     100 |     100 |                   
  ...ineDialog.tsx |   93.69 |    83.92 |     100 |   93.69 | ...11,273,293-295 
  ...yTodoList.tsx |   94.17 |       80 |     100 |   94.17 | 56-57,131-134     
  ...nsDisplay.tsx |   87.25 |       64 |     100 |   87.25 | ...45-147,154-156 
  ThemeDialog.tsx  |   89.95 |    46.15 |      75 |   89.95 | ...71-173,243-245 
  Tips.tsx         |   93.54 |       75 |     100 |   93.54 | 39-40             
  TodoDisplay.tsx  |     100 |      100 |     100 |     100 |                   
  ...tsDisplay.tsx |     100 |     87.5 |     100 |     100 | 31-32             
  TrustDialog.tsx  |     100 |    81.81 |     100 |     100 | 71-86             
  ...ification.tsx |   36.36 |      100 |       0 |   36.36 | 15-22             
  ...ackDialog.tsx |    7.84 |      100 |       0 |    7.84 | 24-134            
  ...xitDialog.tsx |   80.36 |    43.47 |      60 |   80.36 | ...24-238,248-251 
 ...nts/agent-view |   38.33 |    70.83 |   36.36 |   38.33 |                   
  ...atContent.tsx |    8.79 |      100 |       0 |    8.79 | 53-265,271-273    
  ...tChatView.tsx |   21.05 |      100 |       0 |   21.05 | 21-39             
  ...tComposer.tsx |    9.95 |      100 |       0 |    9.95 | 57-308            
  AgentFooter.tsx  |   17.07 |      100 |       0 |   17.07 | 28-66             
  AgentHeader.tsx  |   15.38 |      100 |       0 |   15.38 | 27-64             
  AgentTabBar.tsx  |    87.8 |    27.27 |     100 |    87.8 | ...,85,98-106,124 
  ...oryAdapter.ts |     100 |    91.83 |     100 |     100 | 103,109-110,138   
  index.ts         |       0 |        0 |       0 |       0 | 1-12              
 ...mponents/arena |   45.72 |    70.53 |   60.86 |   45.72 |                   
  ArenaCards.tsx   |   73.06 |    71.79 |   85.71 |   73.06 | ...83-185,321-326 
  ...ectDialog.tsx |   83.48 |    69.86 |   88.88 |   83.48 | ...88-392,409-410 
  ...artDialog.tsx |   10.15 |      100 |       0 |   10.15 | 27-161            
  ...tusDialog.tsx |    5.63 |      100 |       0 |    5.63 | 33-75,80-288      
  ...topDialog.tsx |    6.17 |      100 |       0 |    6.17 | 33-213            
 ...ackground-view |   75.63 |    84.44 |   85.29 |   75.63 |                   
  ...sksDialog.tsx |   70.92 |    80.39 |   76.19 |   70.92 | ...1118,1194-1196 
  ...TasksPill.tsx |   63.75 |    86.95 |     100 |   63.75 | 44,86-106,114-122 
  ...gentPanel.tsx |   99.53 |    93.18 |     100 |   99.53 | 123               
 ...nts/extensions |   45.28 |    33.33 |      60 |   45.28 |                   
  ...gerDialog.tsx |   44.31 |    34.14 |      75 |   44.31 | ...71-480,483-488 
  index.ts         |       0 |        0 |       0 |       0 | 1-9               
  types.ts         |     100 |      100 |     100 |     100 |                   
 ...tensions/steps |   54.88 |    94.23 |   66.66 |   54.88 |                   
  ...ctionStep.tsx |   95.12 |    92.85 |   85.71 |   95.12 | 84-86,89          
  ...etailStep.tsx |    6.18 |      100 |       0 |    6.18 | 17-128            
  ...nListStep.tsx |   88.43 |    94.73 |      80 |   88.43 | 52-53,59-72,106   
  ...electStep.tsx |   13.46 |      100 |       0 |   13.46 | 20-70             
  ...nfirmStep.tsx |   19.56 |      100 |       0 |   19.56 | 23-65             
  index.ts         |     100 |      100 |     100 |     100 |                   
 ...mponents/hooks |   68.67 |    69.07 |   69.56 |   68.67 |                   
  ...etailStep.tsx |   74.68 |    66.66 |   66.66 |   74.68 | ...71-184,188-201 
  ...etailStep.tsx |    87.4 |    73.68 |     100 |    87.4 | 41-42,99-113,119  
  ...abledStep.tsx |     100 |      100 |     100 |     100 |                   
  ...sListStep.tsx |     100 |      100 |     100 |     100 |                   
  ...entDialog.tsx |   34.51 |    47.05 |   42.85 |   34.51 | ...78,482-495,499 
  constants.ts     |     100 |      100 |     100 |     100 |                   
  index.ts         |       0 |        0 |       0 |       0 | 1-13              
  types.ts         |     100 |      100 |     100 |     100 |                   
 ...components/mcp |   20.98 |    86.36 |   83.33 |   20.98 |                   
  ...ealthPill.tsx |   68.42 |    85.71 |     100 |   68.42 | 40-46             
  ...entDialog.tsx |    3.64 |      100 |       0 |    3.64 | 41-717            
  constants.ts     |     100 |      100 |     100 |     100 |                   
  index.ts         |       0 |        0 |       0 |       0 | 1-30              
  types.ts         |     100 |      100 |     100 |     100 |                   
  utils.ts         |   95.83 |    88.88 |     100 |   95.83 | 16,20,109-110     
 ...ents/mcp/steps |   26.74 |    54.54 |   42.85 |   26.74 |                   
  ...icateStep.tsx |    5.88 |      100 |       0 |    5.88 | 40-55,58-296      
  ...electStep.tsx |   10.95 |      100 |       0 |   10.95 | 16-88             
  ...etailStep.tsx |    5.26 |      100 |       0 |    5.26 | 31-247            
  ...rListStep.tsx |   75.18 |    59.37 |     100 |   75.18 | ...53-158,169-173 
  ...etailStep.tsx |   10.41 |      100 |       0 |   10.41 | ...1,67-79,82-139 
  ToolListStep.tsx |   69.02 |       50 |     100 |   69.02 | ...22,125,134-143 
 ...nents/messages |   82.44 |    79.55 |    72.6 |   82.44 |                   
  ...ionDialog.tsx |   80.84 |     77.6 |    62.5 |   80.84 | ...98,516,534-536 
  BtwMessage.tsx   |     100 |      100 |     100 |     100 |                   
  ...upDisplay.tsx |   97.67 |    83.72 |     100 |   97.67 | 119,142,150       
  ...onMessage.tsx |   91.93 |    82.35 |     100 |   91.93 | 57-59,61,63       
  ...nMessages.tsx |   79.06 |      100 |      70 |   79.06 | ...51-264,268-280 
  DiffRenderer.tsx |   93.19 |    86.17 |     100 |   93.19 | ...09,237-238,304 
  ...tsDisplay.tsx |   97.82 |    77.27 |     100 |   97.82 | 87,89             
  ...usMessage.tsx |   76.31 |     42.1 |   66.66 |   76.31 | ...99,101,124,155 
  ...ssMessage.tsx |    12.5 |      100 |       0 |    12.5 | 18-59             
  ...edMessage.tsx |   16.66 |      100 |       0 |   16.66 | 22-38             
  ...sMessages.tsx |   55.67 |       40 |   28.57 |   55.67 | ...20-125,133-145 
  ...ryMessage.tsx |   14.28 |      100 |       0 |   14.28 | 23-62             
  ...onMessage.tsx |   81.02 |    69.23 |   33.33 |   81.02 | ...24-426,433-435 
  ...upMessage.tsx |      84 |    93.61 |     100 |      84 | ...56-383,405-420 
  ToolMessage.tsx  |   88.84 |    75.71 |    92.3 |   88.84 | ...44-749,776-778 
 ...ponents/shared |   85.36 |    78.48 |   95.77 |   85.36 |                   
  ...ctionList.tsx |   99.03 |    95.65 |     100 |   99.03 | 85                
  ...tonSelect.tsx |     100 |      100 |     100 |     100 |                   
  EnumSelector.tsx |     100 |    96.42 |     100 |     100 | 58                
  MaxSizedBox.tsx  |   83.01 |    86.25 |   88.88 |   83.01 | ...12-513,618-619 
  MultiSelect.tsx  |   84.31 |    74.19 |     100 |   84.31 | ...37,193-195,205 
  ...tonSelect.tsx |     100 |      100 |     100 |     100 |                   
  ...eSelector.tsx |     100 |       60 |     100 |     100 | 40-45             
  TextInput.tsx    |   77.01 |    48.78 |      80 |   77.01 | ...08-212,224-230 
  ...apsedTime.tsx |     100 |      100 |     100 |     100 |                   
  ...Indicator.tsx |     100 |      100 |     100 |     100 |                   
  text-buffer.ts   |   83.68 |    78.55 |   97.61 |   83.68 | ...2270-2272,2368 
  ...er-actions.ts |   86.71 |    67.79 |     100 |   86.71 | ...07-608,809-811 
 ...ents/subagents |   30.87 |        0 |       0 |   30.87 |                   
  constants.ts     |     100 |      100 |     100 |     100 |                   
  index.ts         |       0 |        0 |       0 |       0 | 1-11              
  reducers.tsx     |    12.1 |      100 |       0 |    12.1 | 33-190            
  types.ts         |     100 |      100 |     100 |     100 |                   
  utils.ts         |   10.95 |      100 |       0 |   10.95 | ...1,56-57,60-102 
 ...bagents/create |    9.13 |      100 |       0 |    9.13 |                   
  ...ionWizard.tsx |    7.28 |      100 |       0 |    7.28 | 34-299            
  ...rSelector.tsx |   14.75 |      100 |       0 |   14.75 | 26-85             
  ...onSummary.tsx |    4.26 |      100 |       0 |    4.26 | 27-331            
  ...tionInput.tsx |    8.63 |      100 |       0 |    8.63 | 23-177            
  ...dSelector.tsx |   33.33 |      100 |       0 |   33.33 | 20-21,26-27,36-63 
  ...nSelector.tsx |    37.5 |      100 |       0 |    37.5 | 20-21,26-27,36-58 
  ...EntryStep.tsx |   12.76 |      100 |       0 |   12.76 | 34-78             
  ToolSelector.tsx |    4.16 |      100 |       0 |    4.16 | 31-253            
 ...bagents/manage |   21.51 |    59.52 |   27.27 |   21.51 |                   
  ...ctionStep.tsx |   10.25 |      100 |       0 |   10.25 | 21-103            
  ...eleteStep.tsx |   20.93 |      100 |       0 |   20.93 | 23-62             
  ...tEditStep.tsx |   25.53 |      100 |       0 |   25.53 | ...2,37-38,51-124 
  ...ctionStep.tsx |   35.42 |    59.52 |     100 |   35.42 | ...20-432,437-439 
  ...iewerStep.tsx |   13.72 |      100 |       0 |   13.72 | 18-73             
  ...gerDialog.tsx |    6.74 |      100 |       0 |    6.74 | 35-341            
 ...mponents/views |   42.16 |    69.23 |   21.42 |   42.16 |                   
  ContextUsage.tsx |     4.7 |      100 |       0 |     4.7 | ...52-167,170-456 
  DoctorReport.tsx |     9.8 |      100 |       0 |     9.8 | 25-54,57-131      
  ...sionsList.tsx |   87.69 |    73.68 |     100 |   87.69 | 65-72             
  McpStatus.tsx    |   89.53 |    60.52 |     100 |   89.53 | ...72,175-177,262 
  SkillsList.tsx   |   27.27 |      100 |       0 |   27.27 | 18-35             
  ToolsList.tsx    |     100 |      100 |     100 |     100 |                   
 src/ui/contexts   |   77.11 |    77.66 |   80.35 |   77.11 |                   
  ...ewContext.tsx |    64.7 |    85.71 |      50 |    64.7 | ...22-225,231-241 
  AppContext.tsx   |      80 |       50 |     100 |      80 | 19-20             
  ...ewContext.tsx |   95.18 |    67.56 |      50 |   95.18 | ...94-195,222-226 
  ...deContext.tsx |     100 |      100 |     100 |     100 |                   
  ...igContext.tsx |   81.81 |       50 |     100 |   81.81 | 15-16             
  ...ssContext.tsx |   81.88 |    82.26 |     100 |   81.88 | ...1153,1159-1161 
  ...owContext.tsx |   89.28 |       80 |   66.66 |   89.28 | 34,47-48,60-62    
  ...deContext.tsx |     100 |      100 |      50 |     100 |                   
  ...onContext.tsx |   43.28 |     62.5 |    62.5 |   43.28 | ...56-259,263-266 
  ...gsContext.tsx |   83.33 |       50 |     100 |   83.33 | 17-18             
  ...usContext.tsx |     100 |      100 |     100 |     100 |                   
  ...ngContext.tsx |   71.42 |       50 |     100 |   71.42 | 17-20             
  ...utContext.tsx |   85.71 |      100 |   66.66 |   85.71 | 13-14             
  ...nsContext.tsx |   88.23 |       50 |     100 |   88.23 | 117-118           
  ...teContext.tsx |   86.66 |       50 |     100 |   86.66 | 193-194           
  ...deContext.tsx |   76.08 |    72.72 |     100 |   76.08 | 47-48,52-59,77-78 
 src/ui/daemon     |   90.76 |    73.73 |   95.45 |   90.76 |                   
  ...TuiAdapter.ts |   90.76 |    73.73 |   95.45 |   90.76 | ...53,771-772,858 
 src/ui/editors    |   93.33 |    85.71 |   66.66 |   93.33 |                   
  ...ngsManager.ts |   93.33 |    85.71 |   66.66 |   93.33 | 49,63-64          
 src/ui/hooks      |   82.45 |    82.46 |   86.79 |   82.45 |                   
  ...dProcessor.ts |   83.12 |    82.56 |     100 |   83.12 | ...88-389,408-435 
  keyToAnsi.ts     |    3.92 |      100 |       0 |    3.92 | 19-77             
  ...dProcessor.ts |    94.8 |    70.58 |     100 |    94.8 | ...76-277,282-283 
  ...dProcessor.ts |   75.75 |    63.01 |   61.53 |   75.75 | ...84,908,927-931 
  ...amingState.ts |   12.22 |      100 |       0 |   12.22 | 54-157            
  ...agerDialog.ts |   88.23 |      100 |     100 |   88.23 | 20,24             
  ...ationFrame.ts |      32 |       60 |     100 |      32 | 42-44,51-90       
  ...odeCommand.ts |   58.82 |      100 |     100 |   58.82 | 28,33-48          
  ...enaCommand.ts |      85 |      100 |     100 |      85 | 23-24,29          
  ...aInProcess.ts |   19.81 |    66.66 |      25 |   19.81 | 57-175            
  ...Completion.ts |   92.77 |    89.09 |     100 |   92.77 | ...86-187,220-223 
  ...ifications.ts |   92.07 |    96.29 |     100 |   92.07 | 116-124           
  ...tIndicator.ts |     100 |    93.75 |     100 |     100 | 63                
  ...waySummary.ts |   96.22 |    69.69 |     100 |   96.22 | 125-127,169       
  ...ndTaskView.ts |   94.21 |    76.08 |     100 |   94.21 | 122-126,213,219   
  ...ketedPaste.ts |    23.8 |      100 |       0 |    23.8 | 19-37             
  ...nchCommand.ts |   94.36 |    74.35 |     100 |   94.36 | ...60,168-169,209 
  ...ompletion.tsx |   95.95 |    82.75 |     100 |   95.95 | ...22-223,225-226 
  ...dMigration.ts |   90.62 |       75 |     100 |   90.62 | 38-40             
  useCompletion.ts |    92.4 |     87.5 |     100 |    92.4 | 68-69,93-94,98-99 
  ...nitMessage.ts |     100 |      100 |     100 |     100 |                   
  ...extualTips.ts |   76.92 |       50 |     100 |   76.92 | 55,68,71-75,88-96 
  ...eteCommand.ts |   78.53 |    88.57 |     100 |   78.53 | ...96-104,112-113 
  ...ialogClose.ts |   14.28 |      100 |     100 |   14.28 | 87-161            
  ...oublePress.ts |   53.12 |       75 |     100 |   53.12 | 33-35,41-54       
  ...orSettings.ts |     100 |      100 |     100 |     100 |                   
  ...Completion.ts |   99.12 |     97.7 |     100 |   99.12 | 182-183           
  ...ionUpdates.ts |   93.45 |     92.3 |     100 |   93.45 | ...83-287,300-306 
  ...agerDialog.ts |   88.88 |      100 |     100 |   88.88 | 21,25             
  ...backDialog.ts |   54.47 |       50 |   33.33 |   54.47 | ...69-171,193-194 
  useFocus.ts      |     100 |      100 |     100 |     100 |                   
  ...olderTrust.ts |     100 |      100 |     100 |     100 |                   
  ...ggestions.tsx |   89.15 |     62.5 |      50 |   89.15 | ...22-124,149-150 
  ...miniStream.ts |    77.7 |    74.93 |   91.66 |    77.7 | ...2497,2510-2518 
  ...BranchName.ts |    90.9 |     92.3 |     100 |    90.9 | 19-20,55-58       
  ...oryManager.ts |   93.15 |    93.75 |     100 |   93.15 | 44,107-110        
  ...ooksDialog.ts |    87.5 |      100 |     100 |    87.5 | 19,23             
  ...stListener.ts |     100 |      100 |     100 |     100 |                   
  ...nAuthError.ts |   76.19 |       50 |     100 |   76.19 | 39-40,43-45       
  ...putHistory.ts |   92.59 |    85.71 |     100 |   92.59 | 63-64,72,94-96    
  ...storyStore.ts |     100 |    94.11 |     100 |     100 | 69                
  useKeypress.ts   |     100 |      100 |     100 |     100 |                   
  ...rdProtocol.ts |   36.36 |      100 |       0 |   36.36 | 24-31             
  ...unchEditor.ts |    9.67 |      100 |       0 |    9.67 | 11-32,39-90       
  ...gIndicator.ts |     100 |      100 |     100 |     100 |                   
  useLogger.ts     |   21.05 |      100 |       0 |   21.05 | 15-37             
  useMCPHealth.ts  |   63.15 |       75 |      50 |   63.15 | 42-52,64-67       
  ...elsCommand.ts |     100 |      100 |     100 |     100 |                   
  useMcpDialog.ts  |    87.5 |      100 |     100 |    87.5 | 19,23             
  ...moryDialog.ts |    87.5 |      100 |     100 |    87.5 | 19,23             
  ...oryMonitor.ts |     100 |      100 |     100 |     100 |                   
  ...ssageQueue.ts |     100 |      100 |     100 |     100 |                   
  ...delCommand.ts |     100 |       75 |     100 |     100 | 22                
  ...raseCycler.ts |   84.74 |    76.47 |     100 |   84.74 | ...49,52-53,69-71 
  ...derUpdates.ts |   86.38 |    77.19 |     100 |   86.38 | ...22,281-293,341 
  useQwenAuth.ts   |     100 |      100 |     100 |     100 |                   
  ...lScheduler.ts |    84.7 |    93.33 |     100 |    84.7 | ...71-276,372-382 
  ...oryCommand.ts |       0 |        0 |       0 |       0 | 1-7               
  ...umeCommand.ts |   97.08 |    83.33 |     100 |   97.08 | 103-104,133       
  ...ompletion.tsx |   90.59 |    83.33 |     100 |   90.59 | ...01,104,137-140 
  ...ectionList.ts |   96.98 |    95.65 |     100 |   96.98 | ...83-184,238-241 
  ...sionPicker.ts |   92.87 |    90.35 |     100 |   92.87 | ...99-501,503-505 
  ...earchInput.ts |     100 |      100 |     100 |     100 |                   
  ...ngsCommand.ts |   18.75 |      100 |       0 |   18.75 | 10-25             
  ...ellHistory.ts |   91.74 |    79.41 |     100 |   91.74 | ...74,122-123,133 
  ...oryCommand.ts |       0 |        0 |       0 |       0 | 1-73              
  ...Completion.ts |   82.67 |    85.41 |   94.73 |   82.67 | ...68-670,678-714 
  ...tateAndRef.ts |     100 |      100 |     100 |     100 |                   
  useStatusLine.ts |   96.09 |    90.37 |     100 |   96.09 | ...62-365,450-457 
  ...eateDialog.ts |   88.23 |      100 |     100 |   88.23 | 14,18             
  ...tification.ts |     100 |    85.71 |     100 |     100 | 47                
  ...alProgress.ts |   53.06 |       50 |   66.66 |   53.06 | ...53,61-68,79-85 
  ...rminalSize.ts |   76.19 |      100 |      50 |   76.19 | 21-25             
  ...emeCommand.ts |   67.01 |    29.41 |     100 |   67.01 | ...10-111,115-116 
  useTimer.ts      |   88.09 |    85.71 |     100 |   88.09 | 44-45,51-53       
  ...lMigration.ts |       0 |        0 |       0 |       0 |                   
  ...rustModify.ts |     100 |      100 |     100 |     100 |                   
  ...elcomeBack.ts |   87.36 |     90.9 |     100 |   87.36 | ...,94-96,114-115 
  ...reeSession.ts |   93.75 |       75 |     100 |   93.75 | 44-45,87          
  vim.ts           |   83.77 |    80.31 |     100 |   83.77 | ...55,759-767,776 
 src/ui/layouts    |   89.72 |     87.5 |     100 |   89.72 |                   
  ...AppLayout.tsx |   89.88 |     87.5 |     100 |   89.88 | 51-53,93-98       
  ...AppLayout.tsx |   89.47 |     87.5 |     100 |   89.47 | 58-63             
 ...i/manageModels |   93.61 |       48 |     100 |   93.61 |                   
  manageModels.ts  |   93.61 |       48 |     100 |   93.61 | ...63-166,179,209 
 src/ui/models     |   80.24 |    79.16 |   71.42 |   80.24 |                   
  ...ableModels.ts |   80.24 |    79.16 |   71.42 |   80.24 | ...,61-71,123-125 
 ...noninteractive |     100 |      100 |   14.28 |     100 |                   
  ...eractiveUi.ts |     100 |      100 |   14.28 |     100 |                   
 src/ui/state      |   94.91 |    81.81 |     100 |   94.91 |                   
  extensions.ts    |   94.91 |    81.81 |     100 |   94.91 | 68-69,88          
 src/ui/themes     |   98.53 |    70.58 |     100 |   98.53 |                   
  ansi-light.ts    |     100 |      100 |     100 |     100 |                   
  ansi.ts          |     100 |      100 |     100 |     100 |                   
  atom-one-dark.ts |     100 |      100 |     100 |     100 |                   
  ayu-light.ts     |     100 |      100 |     100 |     100 |                   
  ayu.ts           |     100 |      100 |     100 |     100 |                   
  color-utils.ts   |     100 |      100 |     100 |     100 |                   
  default-light.ts |     100 |      100 |     100 |     100 |                   
  default.ts       |     100 |      100 |     100 |     100 |                   
  ...inal-theme.ts |   88.59 |    85.96 |     100 |   88.59 | ...57-261,266-270 
  dracula.ts       |     100 |      100 |     100 |     100 |                   
  github-dark.ts   |     100 |      100 |     100 |     100 |                   
  github-light.ts  |     100 |      100 |     100 |     100 |                   
  googlecode.ts    |     100 |      100 |     100 |     100 |                   
  no-color.ts      |     100 |      100 |     100 |     100 |                   
  qwen-dark.ts     |     100 |      100 |     100 |     100 |                   
  qwen-light.ts    |     100 |      100 |     100 |     100 |                   
  ...tic-tokens.ts |     100 |      100 |     100 |     100 |                   
  ...-of-purple.ts |     100 |      100 |     100 |     100 |                   
  theme-manager.ts |   87.98 |    82.89 |     100 |   87.98 | ...48-357,362-363 
  theme.ts         |     100 |    38.02 |     100 |     100 | ...34-449,457-461 
  xcode.ts         |     100 |      100 |     100 |     100 |                   
 src/ui/utils      |   83.92 |    82.91 |   92.56 |   83.92 |                   
  ...Colorizer.tsx |   79.53 |    83.78 |     100 |   79.53 | ...51-152,249-275 
  ...nRenderer.tsx |   68.83 |    70.14 |      50 |   68.83 | ...52-254,274-293 
  ...wnDisplay.tsx |   86.01 |    87.41 |     100 |   86.01 | ...87,704,729-754 
  ...idDiagram.tsx |   87.79 |    95.34 |     100 |   87.79 | 156-179           
  ...eRenderer.tsx |   92.08 |    80.45 |      95 |   92.08 | ...76-679,723-728 
  ...dWorkUtils.ts |     100 |      100 |     100 |     100 |                   
  ...boardUtils.ts |   59.61 |    58.82 |     100 |   59.61 | ...,86-88,107-149 
  commandUtils.ts  |    95.9 |    88.42 |     100 |    95.9 | ...62,164-165,289 
  computeStats.ts  |     100 |      100 |     100 |     100 |                   
  customBanner.ts  |   90.68 |    91.22 |     100 |   90.68 | ...13,324-327,334 
  displayUtils.ts  |   88.37 |    72.22 |     100 |   88.37 | 23,25,29,31,33    
  formatters.ts    |   95.23 |    98.27 |     100 |   95.23 | 117-120           
  gradientUtils.ts |     100 |      100 |     100 |     100 |                   
  highlight.ts     |     100 |      100 |     100 |     100 |                   
  ...oryMapping.ts |     100 |    94.28 |     100 |     100 | 29,51             
  historyUtils.ts  |   94.11 |       94 |     100 |   94.11 | 94-97             
  isNarrowWidth.ts |     100 |      100 |     100 |     100 |                   
  ...olDetector.ts |    8.23 |      100 |       0 |    8.23 | ...31-132,135-136 
  latexRenderer.ts |   94.95 |     73.8 |     100 |   94.95 | ...76-178,184-187 
  layoutUtils.ts   |     100 |      100 |     100 |     100 |                   
  ...ightLoader.ts |     100 |    89.47 |     100 |     100 | 81,110            
  ...nUtilities.ts |   69.84 |    85.71 |     100 |   69.84 | 75-91,100-101     
  ...ToolGroups.ts |   98.66 |    96.77 |     100 |   98.66 | 48-49             
  ...geRenderer.ts |   86.23 |    69.06 |   95.12 |   86.23 | ...1284,1324-1330 
  ...alRenderer.ts |   86.69 |     71.9 |     100 |   86.69 | ...1476,1513-1519 
  ...lsBySource.ts |     100 |    95.23 |     100 |     100 | 84                
  osc8.ts          |   94.71 |    87.41 |     100 |   94.71 | ...43,428,432-433 
  ...mConstants.ts |     100 |      100 |     100 |     100 |                   
  restoreGoal.ts   |   98.98 |    97.05 |     100 |   98.98 | 98                
  ...storyUtils.ts |   61.89 |    69.87 |      90 |   61.89 | ...76,424,429-451 
  ...ickerUtils.ts |     100 |      100 |     100 |     100 |                   
  ...izedOutput.ts |   94.94 |      100 |   88.88 |   94.94 | 112-117           
  ...wOptimizer.ts |     100 |    96.77 |     100 |     100 | 69                
  terminalSetup.ts |    4.37 |      100 |       0 |    4.37 | 44-393            
  textUtils.ts     |   97.35 |    94.38 |   91.66 |   97.35 | ...50-251,386-387 
  todoSnapshot.ts  |   89.11 |    93.33 |     100 |   89.11 | ...,66-78,180-181 
  updateCheck.ts   |     100 |    80.95 |     100 |     100 | 30-42             
 ...i/utils/export |   56.77 |     40.8 |   79.41 |   56.77 |                   
  collect.ts       |   55.92 |    50.58 |   86.36 |   55.92 | ...25-640,642-647 
  index.ts         |     100 |      100 |     100 |     100 |                   
  normalize.ts     |   57.47 |    20.51 |      80 |   57.47 | ...09-310,324-359 
  types.ts         |       0 |        0 |       0 |       0 | 1                 
  utils.ts         |      40 |      100 |       0 |      40 | 11-13             
 ...ort/formatters |    3.38 |      100 |       0 |    3.38 |                   
  html.ts          |    9.61 |      100 |       0 |    9.61 | ...28,34-76,82-84 
  json.ts          |      50 |      100 |       0 |      50 | 14-15             
  jsonl.ts         |     3.5 |      100 |       0 |     3.5 | 14-76             
  markdown.ts      |    0.94 |      100 |       0 |    0.94 | 13-295            
 src/utils         |   76.06 |    89.51 |   93.82 |   76.06 |                   
  acpModelUtils.ts |     100 |      100 |     100 |     100 |                   
  apiPreconnect.ts |   96.72 |    97.14 |     100 |   96.72 | 165-168           
  checks.ts        |   33.33 |      100 |       0 |   33.33 | 23-28             
  cleanup.ts       |   84.12 |    93.33 |      80 |   84.12 | 75,106-115        
  commands.ts      |     100 |      100 |     100 |     100 |                   
  commentJson.ts   |   87.17 |     90.9 |     100 |   87.17 | 64-73             
  ...Calculator.ts |     100 |      100 |     100 |     100 |                   
  deepMerge.ts     |     100 |       90 |     100 |     100 | 41-43,49          
  ...ScopeUtils.ts |   97.56 |    88.88 |     100 |   97.56 | 67                
  doctorChecks.ts  |   71.06 |       75 |     100 |   71.06 | ...95-301,325-341 
  ...putCapture.ts |   90.65 |    86.17 |     100 |   90.65 | ...72,370,372-373 
  ...arResolver.ts |   94.28 |       88 |     100 |   94.28 | 28-29,125-126     
  errors.ts        |   98.67 |    96.36 |     100 |   98.67 | 67-68             
  events.ts        |     100 |      100 |     100 |     100 |                   
  gitUtils.ts      |   91.91 |    84.61 |     100 |   91.91 | 78-81,124-127     
  ...AutoUpdate.ts |   90.76 |    93.33 |   88.88 |   90.76 | 103-114           
  ...lationInfo.ts |     100 |      100 |     100 |     100 |                   
  languageUtils.ts |   97.89 |    96.42 |     100 |   97.89 | 132-133           
  math.ts          |       0 |        0 |       0 |       0 | 1-15              
  ...iagnostics.ts |   94.57 |    83.01 |   88.88 |   94.57 | ...05,311,315-317 
  ...onfigUtils.ts |     100 |      100 |     100 |     100 |                   
  ...iveHelpers.ts |   96.79 |    93.28 |     100 |   96.79 | ...76-477,575,588 
  osc.ts           |    97.5 |      100 |   88.88 |    97.5 | 195-196           
  package.ts       |   88.88 |       80 |     100 |   88.88 | 33-34             
  processUtils.ts  |     100 |      100 |     100 |     100 |                   
  readStdin.ts     |   79.62 |       90 |      80 |   79.62 | 33-40,52-54       
  relaunch.ts      |   98.07 |    76.92 |     100 |   98.07 | 70                
  resolvePath.ts   |   66.66 |       25 |     100 |   66.66 | 12-13,16,18-19    
  sandbox.ts       |       0 |        0 |       0 |       0 | 1-1047            
  settingsUtils.ts |   82.89 |    90.67 |   89.47 |   82.89 | ...52-663,670-678 
  spawnWrapper.ts  |     100 |      100 |     100 |     100 |                   
  ...upProfiler.ts |   98.46 |    94.52 |     100 |   98.46 | 130-131,305       
  ...upWarnings.ts |     100 |      100 |     100 |     100 |                   
  stdioHelpers.ts  |     100 |       60 |     100 |     100 | 23,32             
  systemInfo.ts    |   95.12 |    89.06 |     100 |   95.12 | ...43-244,249-253 
  ...InfoFields.ts |   87.61 |       65 |     100 |   87.61 | ...22-123,144-145 
  ...iffPreview.ts |   94.11 |    83.33 |     100 |   94.11 | 13                
  ...entEmitter.ts |     100 |      100 |     100 |     100 |                   
  ...upWarnings.ts |   91.17 |    82.35 |     100 |   91.17 | 67-68,73-74,77-78 
  version.ts       |     100 |       50 |     100 |     100 | 11                
  windowTitle.ts   |     100 |      100 |     100 |     100 |                   
  ...WithBackup.ts |   63.15 |    81.25 |     100 |   63.15 | 93,118-157        
-------------------|---------|----------|---------|---------|-------------------
Core Package - Full Text Report
-------------------|---------|----------|---------|---------|-------------------
File               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------|---------|----------|---------|---------|-------------------
All files          |   79.42 |    82.86 |   82.07 |   79.42 |                   
 src               |     100 |      100 |     100 |     100 |                   
  index.ts         |     100 |      100 |     100 |     100 |                   
 src/__mocks__/fs  |       0 |        0 |       0 |       0 |                   
  promises.ts      |       0 |        0 |       0 |       0 | 1-48              
 src/agents        |   87.58 |    79.07 |   91.76 |   87.58 |                   
  ...transcript.ts |   92.25 |    85.71 |     100 |   92.25 | ...87,306-307,438 
  ...ent-resume.ts |    82.5 |     71.5 |   77.41 |    82.5 | ...1035-1039,1042 
  ...ound-tasks.ts |    95.4 |    86.48 |     100 |    95.4 | ...55-756,827-828 
  index.ts         |     100 |      100 |     100 |     100 |                   
 src/agents/arena  |   76.54 |    66.87 |   78.72 |   76.54 |                   
  ...gentClient.ts |   79.47 |    88.88 |   81.81 |   79.47 | ...68-183,189-204 
  ArenaManager.ts  |   75.37 |    63.37 |   78.26 |   75.37 | ...1860,1866-1867 
  arena-events.ts  |   64.44 |      100 |      50 |   64.44 | ...71-175,178-183 
  diff-summary.ts  |    87.5 |    72.34 |     100 |    87.5 | ...32-133,137-138 
  index.ts         |     100 |      100 |     100 |     100 |                   
  types.ts         |     100 |      100 |     100 |     100 |                   
 ...gents/backends |   76.29 |    86.15 |   73.04 |   76.29 |                   
  ITermBackend.ts  |   97.97 |    93.93 |     100 |   97.97 | ...78-180,255,307 
  ...essBackend.ts |   91.25 |    90.62 |   86.66 |   91.25 | ...94,249-269,328 
  TmuxBackend.ts   |    90.7 |    76.55 |   97.36 |    90.7 | ...87,697,743-747 
  detect.ts        |   31.25 |      100 |       0 |   31.25 | 34-88             
  index.ts         |     100 |      100 |     100 |     100 |                   
  iterm-it2.ts     |     100 |     92.1 |     100 |     100 | 37-38,106         
  tmux-commands.ts |    6.64 |      100 |    3.03 |    6.64 | ...93-363,386-503 
  types.ts         |     100 |      100 |     100 |     100 |                   
 ...agents/runtime |   81.14 |     76.7 |   71.42 |   81.14 |                   
  agent-context.ts |     100 |      100 |     100 |     100 |                   
  agent-core.ts    |   76.49 |    72.35 |   60.86 |   76.49 | ...1608,1635-1682 
  agent-events.ts  |     100 |      100 |     100 |     100 |                   
  ...t-headless.ts |   81.19 |    71.73 |   60.86 |   81.19 | ...98-399,402-403 
  ...nteractive.ts |   79.71 |    79.62 |      75 |   79.71 | ...54,456,458,461 
  ...statistics.ts |   98.19 |    82.35 |     100 |   98.19 | 127,151,192,225   
  agent-types.ts   |     100 |      100 |     100 |     100 |                   
  index.ts         |     100 |      100 |     100 |     100 |                   
 src/agents/tasks  |     100 |      100 |     100 |     100 |                   
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/config        |   78.32 |    81.27 |   65.39 |   78.32 |                   
  config.ts        |   76.12 |    79.96 |   60.63 |   76.12 | ...3659,3670-3682 
  constants.ts     |     100 |      100 |     100 |     100 |                   
  models.ts        |     100 |      100 |     100 |     100 |                   
  storage.ts       |   95.01 |     90.9 |   90.47 |   95.01 | ...71-372,375-376 
 ...nfirmation-bus |   98.29 |    97.14 |     100 |   98.29 |                   
  message-bus.ts   |   98.14 |    97.05 |     100 |   98.14 | 42-43             
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/core          |   86.91 |    82.83 |    89.9 |   86.91 |                   
  baseLlmClient.ts |   92.35 |    80.85 |   86.66 |   92.35 | ...34,342-356,495 
  client.ts        |   86.49 |    80.29 |   85.29 |   86.49 | ...1836,1875-1878 
  ...tGenerator.ts |    72.1 |    61.11 |     100 |    72.1 | ...63,365,372-375 
  ...lScheduler.ts |   83.06 |    81.67 |   93.47 |   83.06 | ...2447,2499-2503 
  geminiChat.ts    |   89.32 |     84.8 |   91.48 |   89.32 | ...1454,1521-1522 
  geminiRequest.ts |     100 |      100 |     100 |     100 |                   
  ...htProtocol.ts |    9.09 |      100 |       0 |    9.09 | 34-42,45-49,52-87 
  logger.ts        |   87.33 |    87.02 |     100 |   87.33 | ...61-565,611-625 
  ...tyDefaults.ts |     100 |      100 |     100 |     100 |                   
  ...olExecutor.ts |   92.59 |       75 |      50 |   92.59 | 41-42             
  ...on-helpers.ts |   85.71 |    70.58 |     100 |   85.71 | ...90-191,205-214 
  ...issionFlow.ts |   98.59 |    94.73 |     100 |   98.59 | 93                
  prompts.ts       |   89.16 |    86.41 |   76.92 |   89.16 | ...-965,1168-1169 
  tokenLimits.ts   |     100 |    89.47 |     100 |     100 | 51-52             
  ...okTriggers.ts |   99.31 |    90.41 |     100 |   99.31 | 124,135           
  turn.ts          |   96.44 |    88.88 |     100 |   96.44 | ...08,421-422,470 
 ...ntentGenerator |   94.92 |    82.59 |   93.87 |   94.92 |                   
  ...tGenerator.ts |   96.48 |    84.28 |   92.59 |   96.48 | ...01,919-923,963 
  converter.ts     |   94.51 |    80.72 |     100 |   94.51 | ...06-607,617,823 
  index.ts         |       0 |        0 |       0 |       0 | 1-21              
  usage.ts         |     100 |      100 |     100 |     100 |                   
 ...ntentGenerator |   91.53 |    71.64 |   93.33 |   91.53 |                   
  ...tGenerator.ts |      90 |    70.96 |   92.85 |      90 | ...80-286,304-305 
  index.ts         |     100 |       80 |     100 |     100 | 50                
 ...ntentGenerator |   93.32 |    80.28 |   90.32 |   93.32 |                   
  index.ts         |     100 |      100 |     100 |     100 |                   
  ...tGenerator.ts |    93.3 |    80.28 |   90.32 |    93.3 | ...99,909-910,938 
 ...ntentGenerator |   81.66 |    84.08 |    90.9 |   81.66 |                   
  constants.ts     |     100 |      100 |     100 |     100 |                   
  converter.ts     |   76.88 |    82.25 |    87.5 |   76.88 | ...1589,1610-1616 
  errorHandler.ts  |     100 |      100 |     100 |     100 |                   
  index.ts         |   52.38 |    44.44 |      50 |   52.38 | ...77,81-85,89-93 
  ...tGenerator.ts |    66.4 |    70.58 |   88.88 |    66.4 | ...51-157,168-169 
  pipeline.ts      |   93.67 |     84.9 |     100 |   93.67 | ...80-481,489,554 
  ...ureContext.ts |     100 |      100 |     100 |     100 |                   
  ...ingOptions.ts |       0 |        0 |       0 |       0 | 1                 
  ...CallParser.ts |   90.66 |    88.57 |     100 |   90.66 | ...15-319,349-350 
  ...kingParser.ts |     100 |    96.87 |     100 |     100 | 42                
  types.ts         |       0 |        0 |       0 |       0 | 1                 
 ...rator/provider |   96.69 |    89.17 |   95.45 |   96.69 |                   
  dashscope.ts     |   97.29 |    89.77 |   93.33 |   97.29 | ...81-282,358-359 
  deepseek.ts      |   95.55 |    90.56 |     100 |   95.55 | ...31-132,145-146 
  default.ts       |   94.62 |    86.36 |   85.71 |   94.62 | 86-87,157-159     
  index.ts         |     100 |      100 |     100 |     100 |                   
  minimax.ts       |     100 |      100 |     100 |     100 |                   
  mistral.ts       |   96.07 |    73.33 |     100 |   96.07 | 32-33             
  modelscope.ts    |     100 |      100 |     100 |     100 |                   
  openrouter.ts    |     100 |      100 |     100 |     100 |                   
  types.ts         |       0 |        0 |       0 |       0 |                   
 src/extension     |   60.56 |    79.46 |    78.4 |   60.56 |                   
  ...-converter.ts |   62.35 |    47.82 |      90 |   62.35 | ...90-791,800-832 
  ...ionManager.ts |   47.04 |    82.06 |    65.9 |   47.04 | ...1398,1408-1427 
  ...onSettings.ts |   93.46 |    93.05 |     100 |   93.46 | ...17-221,228-232 
  ...-converter.ts |   54.88 |    94.44 |      60 |   54.88 | ...35-146,158-192 
  github.ts        |   44.94 |    88.52 |      60 |   44.94 | ...53-359,398-451 
  index.ts         |     100 |      100 |     100 |     100 |                   
  marketplace.ts   |   97.29 |    93.75 |     100 |   97.29 | ...64,184-185,274 
  npm.ts           |   48.66 |    76.08 |      75 |   48.66 | ...18-420,427-431 
  override.ts      |   94.11 |    88.88 |     100 |   94.11 | 63-64,81-82       
  settings.ts      |   66.26 |      100 |      50 |   66.26 | 81-108,143-149    
  storage.ts       |     100 |      100 |     100 |     100 |                   
  ...ableSchema.ts |     100 |      100 |     100 |     100 |                   
  variables.ts     |   88.75 |    83.33 |     100 |   88.75 | ...28-231,234-237 
 src/followup      |   46.91 |     92.3 |   71.87 |   46.91 |                   
  followupState.ts |      96 |    89.74 |     100 |      96 | 159-161,218-219   
  index.ts         |     100 |      100 |     100 |     100 |                   
  overlayFs.ts     |   95.06 |       84 |     100 |   95.06 | 78,108,122,133    
  speculation.ts   |   13.22 |      100 |   16.66 |   13.22 | 88-458,518-568    
  ...onToolGate.ts |     100 |    96.29 |     100 |     100 | 93                
  ...nGenerator.ts |    38.4 |    95.12 |   33.33 |    38.4 | ...16-318,353-383 
 src/generated     |       0 |        0 |       0 |       0 |                   
  git-commit.ts    |       0 |        0 |       0 |       0 | 1-10              
 src/goals         |   89.57 |    83.45 |   94.44 |   89.57 |                   
  ...eGoalStore.ts |    85.1 |    95.45 |   84.61 |    85.1 | ...63-166,174-182 
  goalHook.ts      |   97.26 |    91.48 |     100 |   97.26 | 100-105           
  goalJudge.ts     |   84.33 |    74.28 |     100 |   84.33 | ...57-358,366-368 
  index.ts         |     100 |      100 |     100 |     100 |                   
 src/hooks         |   83.48 |    84.87 |   86.83 |   83.48 |                   
  ...okRegistry.ts |   86.48 |    77.08 |     100 |   86.48 | ...41-344,362-369 
  ...bortSignal.ts |     100 |      100 |     100 |     100 |                   
  ...terpolator.ts |   96.66 |    93.33 |     100 |   96.66 | 66-67             
  ...HookRunner.ts |   96.68 |    87.23 |     100 |   96.68 | 110-112,231-233   
  ...Aggregator.ts |    96.4 |    90.78 |     100 |    96.4 | ...91,293-294,367 
  ...entHandler.ts |   94.56 |    83.78 |   93.33 |   94.56 | ...38,795-796,806 
  hookPlanner.ts   |   84.13 |    76.59 |      90 |   84.13 | ...38,144,162-173 
  hookRegistry.ts  |   90.17 |    83.33 |     100 |   90.17 | ...33,352,356,360 
  hookRunner.ts    |   58.56 |    71.26 |   66.66 |   58.56 | ...48-749,758-759 
  hookSystem.ts    |   84.57 |      100 |   65.85 |   84.57 | ...21-622,628-629 
  ...HookRunner.ts |   75.51 |     61.9 |      80 |   75.51 | ...05-406,424-425 
  index.ts         |     100 |      100 |     100 |     100 |                   
  ...HookRunner.ts |   93.63 |    89.47 |      90 |   93.63 | ...45-353,427-428 
  ...SkillHooks.ts |   78.75 |       75 |   66.66 |   78.75 | 62-66,137-152     
  ...oksManager.ts |   96.66 |    91.66 |     100 |   96.66 | ...90,209-210,223 
  ssrfGuard.ts     |   77.22 |    85.36 |     100 |   77.22 | ...57,261-267,273 
  stopHookCap.ts   |     100 |      100 |     100 |     100 |                   
  trustedHooks.ts  |       0 |        0 |       0 |       0 | 1-124             
  types.ts         |   91.18 |    92.04 |   85.71 |   91.18 | ...40-441,501-505 
  urlValidator.ts  |     100 |      100 |     100 |     100 |                   
 src/ide           |   74.28 |    83.39 |   78.33 |   74.28 |                   
  constants.ts     |     100 |      100 |     100 |     100 |                   
  detect-ide.ts    |     100 |      100 |     100 |     100 |                   
  ide-client.ts    |    64.2 |    81.48 |   66.66 |    64.2 | ...9-970,999-1007 
  ide-installer.ts |   89.06 |    79.31 |     100 |   89.06 | ...36,143-147,160 
  ideContext.ts    |     100 |      100 |     100 |     100 |                   
  process-utils.ts |   84.84 |    71.79 |     100 |   84.84 | ...37,151,193-194 
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/lsp           |   41.24 |    52.14 |   51.42 |   41.24 |                   
  ...nfigLoader.ts |   70.27 |    35.89 |   94.73 |   70.27 | ...20-422,426-432 
  ...ionFactory.ts |   42.69 |    79.16 |      50 |   42.69 | ...62-413,419-436 
  ...Normalizer.ts |   23.09 |    13.72 |   30.43 |   23.09 | ...04-905,909-924 
  ...verManager.ts |   25.31 |    62.06 |   41.66 |   25.31 | ...85-704,710-740 
  ...eLspClient.ts |   32.77 |       80 |   17.64 |   32.77 | ...84-288,294-295 
  ...LspService.ts |   48.49 |    67.16 |   65.71 |   48.49 | ...1352,1369-1379 
  constants.ts     |     100 |      100 |     100 |     100 |                   
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/mcp           |   78.69 |    75.34 |   75.92 |   78.69 |                   
  constants.ts     |     100 |      100 |     100 |     100 |                   
  ...h-provider.ts |   86.95 |      100 |   33.33 |   86.95 | ...,93,97,101-102 
  ...h-provider.ts |   73.82 |    53.92 |     100 |   73.82 | ...88-895,902-904 
  ...en-storage.ts |   98.62 |    97.72 |     100 |   98.62 | 87-88             
  oauth-utils.ts   |   70.58 |    85.29 |    90.9 |   70.58 | ...70-290,315-344 
  ...n-provider.ts |   89.83 |    95.83 |   45.45 |   89.83 | ...43,147,151-152 
 .../token-storage |   79.52 |    86.66 |   86.36 |   79.52 |                   
  ...en-storage.ts |     100 |      100 |     100 |     100 |                   
  ...en-storage.ts |   82.87 |    82.35 |   92.85 |   82.87 | ...63-173,181-182 
  ...en-storage.ts |     100 |      100 |     100 |     100 |                   
  index.ts         |     100 |      100 |     100 |     100 |                   
  ...en-storage.ts |   68.14 |    82.35 |   64.28 |   68.14 | ...81-295,298-314 
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/memory        |   68.13 |    76.57 |   66.66 |   68.13 |                   
  const.ts         |     100 |      100 |     100 |     100 |                   
  dream.ts         |   65.65 |    73.33 |      50 |   65.65 | 50,107-148        
  ...entPlanner.ts |   57.84 |    72.72 |   33.33 |   57.84 | ...35,140-147,152 
  entries.ts       |   63.77 |    79.16 |      50 |   63.77 | ...72-180,183-189 
  extract.ts       |    95.2 |    79.16 |     100 |    95.2 | 81-86,125         
  ...entPlanner.ts |   63.08 |    65.71 |   41.17 |   63.08 | ...17,222-223,332 
  ...ionPlanner.ts |       0 |        0 |       0 |       0 | 1                 
  forget.ts        |    45.8 |    61.53 |   44.44 |    45.8 | ...04,211,214-346 
  indexer.ts       |   83.87 |    45.45 |     100 |   83.87 | ...50,56-57,69-70 
  manager.ts       |   75.31 |    81.04 |    75.6 |   75.31 | ...1278,1291-1293 
  memoryAge.ts     |   90.47 |    77.77 |     100 |   90.47 | 50-51             
  paths.ts         |   55.47 |    89.47 |   85.71 |   55.47 | ...,89-90,106-114 
  prompt.ts        |   93.36 |    71.42 |     100 |   93.36 | ...58,161,228-229 
  recall.ts        |   79.56 |    69.38 |   88.88 |   79.56 | ...40-245,269-280 
  ...ceSelector.ts |   91.86 |    77.27 |     100 |   91.86 | ...07,109-110,118 
  scan.ts          |   87.91 |    68.42 |     100 |   87.91 | ...47-48,58,82-87 
  ...entPlanner.ts |    11.5 |      100 |       0 |    11.5 | ...57-192,210-298 
  status.ts        |   10.52 |      100 |       0 |   10.52 | 41-98             
  store.ts         |   94.44 |    83.33 |     100 |   94.44 | 56-57,92-93       
  types.ts         |     100 |      100 |     100 |     100 |                   
  ...ontextFile.ts |   79.38 |    81.03 |   81.81 |   79.38 | ...58-272,286-291 
 src/mocks         |       0 |        0 |       0 |       0 |                   
  msw.ts           |       0 |        0 |       0 |       0 | 1-9               
 src/models        |   89.31 |    86.02 |    87.5 |   89.31 |                   
  constants.ts     |     100 |      100 |     100 |     100 |                   
  ...tor-config.ts |   90.24 |    91.42 |     100 |   90.24 | 142,148,151-160   
  index.ts         |     100 |      100 |     100 |     100 |                   
  ...nfigErrors.ts |   74.22 |    47.82 |   84.61 |   74.22 | ...,67-74,106-117 
  ...igResolver.ts |   98.63 |    92.53 |     100 |   98.63 | 161,323,329       
  modelRegistry.ts |     100 |    98.59 |     100 |     100 | 222               
  modelsConfig.ts  |   84.57 |    82.14 |   81.57 |   84.57 | ...1223,1252-1253 
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/output        |     100 |      100 |     100 |     100 |                   
  ...-formatter.ts |     100 |      100 |     100 |     100 |                   
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/permissions   |   71.18 |    88.76 |   48.57 |   71.18 |                   
  index.ts         |     100 |      100 |     100 |     100 |                   
  ...on-manager.ts |   81.42 |    86.66 |      80 |   81.42 | ...29-830,837-846 
  rule-parser.ts   |   95.99 |    93.22 |     100 |   95.99 | ...-864,1013-1015 
  ...-semantics.ts |   58.28 |    85.27 |    30.2 |   58.28 | ...1604-1614,1643 
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/prompts       |   83.63 |      100 |    87.5 |   83.63 |                   
  mcp-prompts.ts   |   18.18 |      100 |       0 |   18.18 | 11-19             
  ...t-registry.ts |     100 |      100 |     100 |     100 |                   
 src/qwen          |   83.87 |    77.23 |   95.83 |   83.87 |                   
  ...tGenerator.ts |   98.64 |    98.18 |     100 |   98.64 | 105-106           
  qwenOAuth2.ts    |   80.85 |    70.27 |   90.32 |   80.85 | ...1169-1185,1215 
  ...kenManager.ts |   83.76 |    76.22 |     100 |   83.76 | ...62-767,788-793 
 src/services      |   85.25 |    83.28 |   91.36 |   85.25 |                   
  ...ionTrailer.ts |     100 |      100 |     100 |     100 |                   
  ...llRegistry.ts |   98.44 |    91.83 |     100 |   98.44 | 268-269           
  ...ionService.ts |    95.6 |    96.36 |     100 |    95.6 | ...32,400,402-406 
  ...ingService.ts |   83.91 |       83 |   83.33 |   83.91 | ...1267,1284-1285 
  ...ttribution.ts |   91.73 |    87.71 |      90 |   91.73 | ...80-685,826-827 
  ...utSlimming.ts |     100 |    96.77 |     100 |     100 | 133,182           
  cronScheduler.ts |   97.56 |    92.98 |     100 |   97.56 | 62-63,77,155      
  ...eryService.ts |   80.43 |    95.45 |      75 |   80.43 | ...19-134,140-141 
  ...oryService.ts |   86.25 |    74.35 |    92.3 |   86.25 | ...46-655,696-699 
  fileReadCache.ts |     100 |      100 |     100 |     100 |                   
  ...temService.ts |   91.27 |    82.69 |    90.9 |   91.27 | ...94,196,294-301 
  ...ratedFiles.ts |      96 |    88.23 |     100 |      96 | 119-120,146-147   
  gitInit.ts       |     100 |      100 |     100 |     100 |                   
  gitService.ts    |   68.75 |     92.3 |   55.55 |   68.75 | ...12-122,125-129 
  ...reeService.ts |   73.83 |    69.31 |    97.5 |   73.83 | ...1460,1488-1489 
  ...ionService.ts |   98.13 |     97.8 |   95.45 |   98.13 | ...32-333,380-381 
  ...orRegistry.ts |   96.54 |    91.73 |     100 |   96.54 | ...70-471,622-623 
  sessionRecap.ts  |   12.04 |      100 |       0 |   12.04 | 49-160            
  ...ionService.ts |   90.23 |     78.8 |   96.77 |   90.23 | ...1294,1298-1299 
  sessionTitle.ts  |   93.87 |    69.81 |     100 |   93.87 | ...33-236,267-268 
  ...ionService.ts |   81.07 |    77.92 |   89.28 |   81.07 | ...1923,1929-1934 
  ...UseSummary.ts |   94.73 |    87.71 |     100 |   94.73 | ...73-175,225-226 
  ...reeCleanup.ts |   14.56 |      100 |   33.33 |   14.56 | 58-185            
  ...ionService.ts |   84.21 |    79.41 |     100 |   84.21 | ...22-223,239-240 
 ...icrocompaction |   98.05 |     91.8 |     100 |   98.05 |                   
  microcompact.ts  |   98.05 |     91.8 |     100 |   98.05 | ...19,289,293,391 
 src/skills        |    87.5 |    83.86 |   94.23 |    87.5 |                   
  index.ts         |     100 |      100 |     100 |     100 |                   
  ...activation.ts |     100 |     93.1 |     100 |     100 | 93,112            
  skill-load.ts    |   92.94 |    81.63 |     100 |   92.94 | ...06,226,238-240 
  skill-manager.ts |   83.31 |    79.66 |   90.32 |   83.31 | ...1120,1127-1131 
  skill-paths.ts   |   86.74 |    77.77 |     100 |   86.74 | ...00-101,106-107 
  symlinkScope.ts  |     100 |      100 |     100 |     100 |                   
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/subagents     |   83.13 |    80.24 |   95.23 |   83.13 |                   
  ...tin-agents.ts |     100 |      100 |     100 |     100 |                   
  index.ts         |     100 |      100 |     100 |     100 |                   
  ...-selection.ts |     100 |      100 |     100 |     100 |                   
  ...nt-manager.ts |   77.21 |    72.09 |   92.85 |   77.21 | ...1180,1202-1203 
  types.ts         |     100 |      100 |     100 |     100 |                   
  validation.ts    |   92.46 |    95.18 |     100 |   92.46 | 51-56,69-74,78-83 
 src/telemetry     |   74.72 |    87.26 |   78.85 |   74.72 |                   
  config.ts        |     100 |      100 |     100 |     100 |                   
  constants.ts     |     100 |      100 |     100 |     100 |                   
  ...attributes.ts |   98.13 |       88 |     100 |   98.13 | 185-187           
  ...-exporters.ts |   46.37 |      100 |   44.44 |   46.37 | ...85,88-89,92-93 
  index.ts         |     100 |      100 |     100 |     100 |                   
  ...t.circular.ts |       0 |        0 |       0 |       0 | 1-111             
  ...-processor.ts |   93.93 |    90.21 |   94.11 |   93.93 | ...75-280,299-300 
  ...t.circular.ts |       0 |        0 |       0 |       0 | 1-128             
  loggers.ts       |    51.9 |       64 |   57.77 |    51.9 | ...1214,1231-1251 
  metrics.ts       |    74.9 |    82.95 |   74.54 |    74.9 | ...58-978,981-992 
  sanitize.ts      |      80 |    83.33 |     100 |      80 | 35-36,41-42       
  sdk.ts           |   90.45 |    83.56 |   76.92 |   90.45 | ...17-318,338-342 
  ...on-context.ts |     100 |      100 |     100 |     100 |                   
  ...on-tracing.ts |   92.24 |    88.77 |     100 |   92.24 | ...21-424,522-525 
  ...etry-utils.ts |     100 |      100 |     100 |     100 |                   
  ...l-decision.ts |     100 |      100 |     100 |     100 |                   
  ...e-id-utils.ts |     100 |      100 |     100 |     100 |                   
  tracer.ts        |   98.61 |    89.36 |     100 |   98.61 | 53,108            
  types.ts         |   79.17 |    94.49 |   83.33 |   79.17 | ...1149,1152-1181 
  uiTelemetry.ts   |   92.97 |    96.96 |   81.25 |   92.97 | ...93-194,200-207 
 ...ry/qwen-logger |   68.24 |    79.56 |   64.91 |   68.24 |                   
  event-types.ts   |       0 |        0 |       0 |       0 |                   
  qwen-logger.ts   |   68.24 |    79.34 |   64.28 |   68.24 | ...1055,1093-1094 
 src/test-utils    |   93.16 |    95.91 |   76.47 |   93.16 |                   
  config.ts        |     100 |      100 |     100 |     100 |                   
  ...st-helpers.ts |   94.11 |       90 |     100 |   94.11 | 69-70             
  index.ts         |     100 |      100 |     100 |     100 |                   
  mock-tool.ts     |   91.19 |    97.14 |   72.41 |   91.19 | ...38,202-203,216 
  ...aceContext.ts |     100 |      100 |     100 |     100 |                   
 src/tools         |    78.6 |    81.66 |    86.8 |    78.6 |                   
  ...erQuestion.ts |   88.93 |    76.74 |    90.9 |   88.93 | ...39-340,347-348 
  cron-create.ts   |   97.75 |    88.88 |   83.33 |   97.75 | 30-31             
  cron-delete.ts   |   96.82 |      100 |   83.33 |   96.82 | 26-27             
  cron-list.ts     |   96.66 |      100 |   83.33 |   96.66 | 25-26             
  diffOptions.ts   |     100 |      100 |     100 |     100 |                   
  edit.ts          |   80.52 |    85.98 |   73.33 |   80.52 | ...15-716,803-853 
  ...r-worktree.ts |   82.95 |    67.56 |    87.5 |   82.95 | ...82-185,276-277 
  exit-worktree.ts |   84.23 |    85.96 |   91.66 |   84.23 | ...92-293,298-312 
  exitPlanMode.ts  |   85.09 |    85.71 |     100 |   85.09 | ...60-163,177-189 
  glob.ts          |   90.63 |    88.33 |   84.61 |   90.63 | ...28,171,302,305 
  grep.ts          |   79.19 |    85.71 |   78.94 |   79.19 | ...20,560,569-576 
  ls.ts            |   96.74 |    90.27 |     100 |   96.74 | 176-181,212,216   
  lsp.ts           |   72.77 |    60.09 |   90.32 |   72.77 | ...1211,1213-1214 
  ...nt-manager.ts |   84.36 |    82.74 |   84.21 |   84.36 | ...2099-2103,2142 
  mcp-client.ts    |   33.18 |    77.65 |   66.66 |   33.18 | ...1490,1494-1497 
  mcp-tool.ts      |   90.98 |    88.88 |   96.42 |   90.98 | ...95-596,646-647 
  memory-config.ts |       0 |        0 |       0 |       0 | 1-47              
  ...iable-tool.ts |     100 |    84.61 |     100 |     100 | 102,109           
  monitor.ts       |   92.36 |    83.94 |      92 |   92.36 | ...29,558-561,574 
  ...nforcement.ts |   82.44 |       90 |     100 |   82.44 | 174-185,234-247   
  read-file.ts     |   95.09 |    88.75 |      90 |   95.09 | ...99,293-296,299 
  ripGrep.ts       |   94.59 |    85.71 |   93.33 |   94.59 | ...60,463,541-542 
  ...-transport.ts |    6.34 |        0 |       0 |    6.34 | 47-145            
  send-message.ts  |   89.32 |    91.66 |   83.33 |   89.32 | 44-45,68-76       
  shell.ts         |   72.96 |     79.6 |    91.3 |   72.96 | ...4216,4265-4271 
  skill-utils.ts   |     100 |      100 |     100 |     100 |                   
  skill.ts         |   88.11 |    91.17 |   84.61 |   88.11 | ...95,399,422-444 
  ...eticOutput.ts |   95.12 |      100 |      80 |   95.12 | 87-88             
  task-stop.ts     |   93.14 |    96.15 |   85.71 |   93.14 | 39-40,54-64       
  todoWrite.ts     |   89.17 |    82.05 |   92.85 |   89.17 | ...41-546,568-569 
  tool-error.ts    |     100 |      100 |     100 |     100 |                   
  tool-names.ts    |     100 |      100 |     100 |     100 |                   
  tool-registry.ts |   74.85 |    76.85 |   80.95 |   74.85 | ...30-831,839-840 
  tool-search.ts   |   95.19 |    86.48 |    92.3 |   95.19 | ...47-153,208-213 
  tools.ts         |   91.98 |    90.19 |   88.88 |   91.98 | ...50-451,467-473 
  web-fetch.ts     |   88.59 |    79.48 |    92.3 |   88.59 | ...12-313,315-316 
  write-file.ts    |   82.23 |    81.17 |   83.33 |   82.23 | ...65-668,680-715 
 src/tools/agent   |   75.01 |    82.55 |   74.62 |   75.01 |                   
  agent.ts         |   75.29 |    82.86 |    75.4 |   75.29 | ...2203,2265-2272 
  fork-subagent.ts |   69.62 |    71.42 |   66.66 |   69.62 | ...04-105,140-151 
 src/utils         |   88.98 |    87.56 |   93.69 |   88.98 |                   
  LruCache.ts      |       0 |        0 |       0 |       0 | 1-41              
  ...ssageQueue.ts |     100 |      100 |     100 |     100 |                   
  ...cFileWrite.ts |   77.96 |    80.48 |     100 |   77.96 | ...35,156,173-176 
  bareMode.ts      |   27.27 |      100 |       0 |   27.27 | 9-15,18-19        
  browser.ts       |    7.69 |      100 |       0 |    7.69 | 17-56             
  bundlePaths.ts   |     100 |      100 |     100 |     100 |                   
  ...igResolver.ts |     100 |      100 |     100 |     100 |                   
  ...engthError.ts |   89.11 |    86.66 |     100 |   89.11 | ...28-129,132-133 
  cronDisplay.ts   |   42.85 |    23.07 |     100 |   42.85 | 26-31,33-45,47-54 
  cronParser.ts    |   89.74 |    85.71 |     100 |   89.74 | ...,63-64,183-186 
  debugLogger.ts   |    95.9 |    93.84 |   94.73 |    95.9 | 106-107,214-218   
  editHelper.ts    |   93.63 |    83.52 |     100 |   93.63 | ...28-429,463-464 
  editor.ts        |   97.61 |    95.71 |     100 |   97.61 | ...70-271,273-274 
  ...arResolver.ts |   94.28 |    88.88 |     100 |   94.28 | 28-29,125-126     
  ...entContext.ts |     100 |    95.45 |     100 |     100 | 83                
  errorParsing.ts  |    97.7 |    97.05 |     100 |    97.7 | 72-73             
  ...rReporting.ts |   88.46 |       90 |     100 |   88.46 | 69-74             
  errors.ts        |   70.92 |       80 |   53.33 |   70.92 | ...03-219,223-229 
  fetch.ts         |   70.18 |    71.42 |   71.42 |   70.18 | ...42,148,161,186 
  fileUtils.ts     |   91.46 |    86.19 |   95.23 |   91.46 | ...1188,1192-1198 
  forkedAgent.ts   |    78.5 |    70.73 |   85.71 |    78.5 | ...30-436,441-447 
  formatters.ts    |   81.81 |       75 |     100 |   81.81 | 15-16             
  ...eUtilities.ts |   89.21 |    86.66 |     100 |   89.21 | 16-17,49-55,65-66 
  ...rStructure.ts |   94.36 |    94.28 |     100 |   94.36 | ...17-120,330-335 
  getPty.ts        |    12.5 |      100 |       0 |    12.5 | 21-34             
  gitDiff.ts       |   92.36 |    79.53 |     100 |   92.36 | ...55-856,928-929 
  ...noreParser.ts |    92.3 |    89.36 |     100 |    92.3 | ...15-116,186-187 
  gitUtils.ts      |   56.66 |    85.71 |      75 |   56.66 | ...2,72-73,97-148 
  iconvHelper.ts   |     100 |      100 |     100 |     100 |                   
  ...rePatterns.ts |     100 |      100 |     100 |     100 |                   
  ...ionManager.ts |     100 |     90.9 |     100 |     100 | 26                
  ...lPromptIds.ts |     100 |      100 |     100 |     100 |                   
  jsonl-utils.ts   |    74.1 |    90.76 |   58.33 |    74.1 | ...23-326,336-342 
  ...-detection.ts |     100 |      100 |     100 |     100 |                   
  ...iagnostics.ts |   96.87 |    91.83 |     100 |   96.87 | 214-219,272       
  ...yDiscovery.ts |    83.9 |    79.36 |     100 |    83.9 | ...16,319,411-414 
  ...tProcessor.ts |   93.63 |       90 |     100 |   93.63 | ...96-302,384-385 
  ...Inspectors.ts |   61.53 |      100 |      50 |   61.53 | 18-23             
  modelId.ts       |   98.55 |    96.87 |     100 |   98.55 | 103               
  ...kerChecker.ts |   88.75 |    85.71 |     100 |   88.75 | 69-70,87-93       
  notebook.ts      |   94.35 |    84.78 |     100 |   94.35 | ...10,122,174-176 
  openaiLogger.ts  |   88.05 |    84.09 |     100 |   88.05 | ...44-146,169-174 
  partUtils.ts     |     100 |    98.61 |     100 |     100 | 206               
  pathReader.ts    |     100 |      100 |     100 |     100 |                   
  paths.ts         |   93.21 |    91.86 |     100 |   93.21 | ...89-390,392-394 
  pdf.ts           |   93.68 |    87.05 |     100 |   93.68 | ...96-297,321-325 
  projectPath.ts   |     100 |      100 |     100 |     100 |                   
  ...ectSummary.ts |   89.39 |    72.41 |     100 |   89.39 | ...37-142,193-196 
  ...tIdContext.ts |     100 |      100 |     100 |     100 |                   
  proxyUtils.ts    |     100 |      100 |     100 |     100 |                   
  ...rDetection.ts |   58.57 |       76 |     100 |   58.57 | ...4,88-89,95-100 
  ...noreParser.ts |   85.45 |    85.18 |     100 |   85.45 | ...59,65-66,72-73 
  rateLimit.ts     |   92.55 |    85.92 |     100 |   92.55 | ...70-272,309-310 
  readManyFiles.ts |   87.96 |    86.95 |     100 |   87.96 | ...05-207,223-234 
  retry.ts         |   89.81 |    88.05 |     100 |   89.81 | ...29,350,357-358 
  ripgrepUtils.ts  |   46.79 |    84.37 |   66.66 |   46.79 | ...45-246,258-335 
  ...sDiscovery.ts |   97.42 |    92.85 |     100 |   97.42 | ...04,182-183,202 
  ...tchOptions.ts |   81.72 |    85.04 |   95.23 |   81.72 | ...11,536,565-574 
  runtimeStatus.ts |    97.5 |    88.57 |     100 |    97.5 | 167-168           
  safeJsonParse.ts |   74.07 |    83.33 |     100 |   74.07 | 40-46             
  ...nStringify.ts |     100 |      100 |     100 |     100 |                   
  ...aConverter.ts |   90.78 |    88.23 |     100 |   90.78 | ...41-42,93,95-96 
  ...aValidator.ts |   94.57 |    80.26 |     100 |   94.57 | ...04,213-216,270 
  ...r-launcher.ts |   76.92 |     91.3 |   66.66 |   76.92 | ...34,136,157-195 
  ...orageUtils.ts |   96.89 |    85.84 |     100 |   96.89 | ...51,367,447,466 
  shell-utils.ts   |   82.93 |    89.89 |     100 |   82.93 | ...1522,1529-1533 
  ...lAstParser.ts |   95.58 |    85.79 |     100 |   95.58 | ...1059-1061,1071 
  ...nlyChecker.ts |   95.75 |    92.39 |     100 |   95.75 | ...00-301,313-314 
  sideQuery.ts     |   98.73 |    94.59 |     100 |   98.73 | 111               
  ...pEventSink.ts |     100 |       80 |     100 |     100 | 61                
  ...tGenerator.ts |     100 |      100 |     100 |     100 |                   
  ...ameContext.ts |     100 |      100 |     100 |     100 |                   
  symlink.ts       |   77.77 |       50 |     100 |   77.77 | 44,54-59          
  ...emEncoding.ts |   96.36 |    91.17 |     100 |   96.36 | 59-60,124-125     
  terminalSafe.ts  |     100 |      100 |     100 |     100 |                   
  ...Serializer.ts |   98.72 |       90 |     100 |   98.72 | 42-43,134,201-203 
  testUtils.ts     |   53.33 |      100 |   33.33 |   53.33 | ...53,59-64,70-72 
  textUtils.ts     |      60 |      100 |   66.66 |      60 | 36-55             
  thoughtUtils.ts  |     100 |    92.85 |     100 |     100 | 71                
  ...-converter.ts |   94.59 |    85.71 |     100 |   94.59 | 35-36             
  tool-utils.ts    |    93.6 |     91.3 |     100 |    93.6 | ...58-159,162-163 
  truncation.ts    |     100 |       92 |     100 |     100 | 52,71             
  windowsPath.ts   |   89.47 |    79.31 |     100 |   89.47 | ...57-58,62,90-91 
  ...aceContext.ts |   93.71 |    89.28 |   93.33 |   93.71 | ...24-225,249-251 
  xml.ts           |     100 |      100 |     100 |     100 |                   
  yaml-parser.ts   |      92 |    84.61 |     100 |      92 | 49-53,65-69       
 ...ils/filesearch |   86.21 |    81.61 |   96.42 |   86.21 |                   
  crawlCache.ts    |     100 |      100 |     100 |     100 |                   
  crawler.ts       |   82.84 |    77.49 |   94.82 |   82.84 | ...1451,1485-1486 
  fileSearch.ts    |   93.58 |    87.32 |     100 |   93.58 | ...46-247,249-250 
  ignore.ts        |     100 |      100 |     100 |     100 |                   
  result-cache.ts  |     100 |     92.3 |     100 |     100 | 46                
 ...uest-tokenizer |   56.63 |    74.52 |   74.19 |   56.63 |                   
  ...eTokenizer.ts |   41.86 |    76.47 |   69.23 |   41.86 | ...70-443,453-507 
  index.ts         |     100 |      100 |     100 |     100 |                   
  ...tTokenizer.ts |   68.39 |    69.49 |    90.9 |   68.39 | ...24-325,327-328 
  ...ageFormats.ts |      76 |      100 |   33.33 |      76 | 45-48,55-56       
  textTokenizer.ts |     100 |      100 |     100 |     100 |                   
  types.ts         |       0 |        0 |       0 |       0 | 1                 
-------------------|---------|----------|---------|---------|-------------------

For detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run.

@wenshao wenshao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Test Coverage Gaps

The following new code paths have zero test coverage and need tests before merge:

  • WorktreeExitDialog.tsx (189 new lines): no unit/integration/ACP test exists for loading state, dirty-state display, escape key handler, radio choices, useEffect cleanup with cancelled flag, or originalHeadCommit empty branch.
  • useWorktreeSession.ts (80 new lines): no test for load(), fs.watch watcher, cancelled flag, or fs.mkdir fallback.
  • nonInteractiveCli.ts:375-408: headless --resume worktree restore is stubbed out in existing tests (mockReturnValue(undefined)). No test verifies <system-reminder> injection or adapter.emitSystemMessage('worktree_restored', ...).
  • AppContainer.tsx worktree changes (~100 lines): historically untested file; handleWorktreeExit, useWorktreeSession consumption, and --resume restore path are uncovered.

Comment thread packages/cli/src/ui/AppContainer.tsx Outdated
setShowWorktreeExitDialog(false);
if (choice === 'remove' && activeWorktree) {
try {
const svc = new GitWorktreeService(config.getTargetDir());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Critical] handleWorktreeExit constructs GitWorktreeService with config.getTargetDir(), but worktrees are created under the repo root (getRepoTopLevel()). When the CLI is launched from a subdirectory (e.g., a monorepo package), paths won't match and removeUserWorktree will silently fail. activeWorktree.originalCwd already stores the correct repo root.

Suggested change
const svc = new GitWorktreeService(config.getTargetDir());
const svc = new GitWorktreeService(activeWorktree.originalCwd);

— DeepSeek/deepseek-v4-pro via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in c0c0e71. Anchor GitWorktreeService at activeWorktree.originalCwd (captured repo top-level) instead of config.getTargetDir(). Monorepo subdir launches now resolve the worktree correctly.

Comment thread packages/cli/src/ui/AppContainer.tsx Outdated
if (choice === 'remove' && activeWorktree) {
try {
const svc = new GitWorktreeService(config.getTargetDir());
await svc.removeUserWorktree(activeWorktree.slug, {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Critical] The remove path has three gaps: (1) removeUserWorktree return value {success, error} is never checked — if removal fails, clearWorktreeSession still runs, orphaning the worktree. (2) forceDeleteBranch is not passed, so branches with unmerged commits are silently preserved contrary to the dialog warning. (3) The entire code path bypasses ExitWorktreeTool's three-guard safety sequence (session ownership, uncommitted changes gate, unmerged commits gate).

Suggested change
await svc.removeUserWorktree(activeWorktree.slug, {
const result = await svc.removeUserWorktree(activeWorktree.slug, {
deleteBranch: true,
forceDeleteBranch: true,
});
if (!result.success) {
// Keep the sidecar so --resume can recover the worktree.
return;
}
await clearWorktreeSession(/* ... */);

— DeepSeek/deepseek-v4-pro via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed parts (1) and (2) in 38db00f. Now checks removeUserWorktree's {success} return and only clears the sidecar on success — if removal fails the sidecar stays so --resume can recover. Also passes forceDeleteBranch: true to honour the dialog's "discards N commits" label. Part (3) declined as design: the dialog IS the safety affordance for this path — it surfaces the dirty-state + commit counts before the user confirms, equivalent to the tool's discard_changes: true opt-in.

const handleWorktreeExit = useCallback(
async (choice: 'keep' | 'remove' | 'cancel') => {
if (choice === 'cancel') {
setShowWorktreeExitDialog(false);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] The keep path does not call clearWorktreeSession, while exit_worktree tool's action='keep' calls maybeClearWorktreeSession. On --resume, the stale sidecar re-injects the worktree context reminder even though the user already chose to exit.

Suggested change
setShowWorktreeExitDialog(false);
if (choice === 'keep') {
if (activeWorktree) {
await clearWorktreeSession(
config
.getSessionService()
.getWorktreeSessionPath(config.getSessionId()),
);
}
handleSlashCommand('/quit');
return;
}

— DeepSeek/deepseek-v4-pro via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Declined-design. Dialog Keep ≠ tool Keep. exit_worktree action='keep' is invoked mid-session when the user wants to leave the worktree context (sidecar cleared, footer indicator off). Dialog Keep is invoked at app-exit when the user wants to come back to this worktree on the next --resume (sidecar preserved, --resume re-injects the context reminder). The dialog label "Keep worktree (exit without deleting)" supports the preserve semantics; clearing here would silently break --resume restoration for the most common case.

// count new commits created inside the worktree. Empty string when
// rev-parse fails (e.g. unborn HEAD) — the dialog treats empty as
// "unknown" and skips the commit-count display.
let originalHeadCommit = '';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Critical] originalHeadCommit is always captured via getCurrentCommitHash() (which runs git rev-parse HEAD on the main repo), regardless of the base_branch parameter. If the user is on main but specifies base_branch='develop', the captured commit is main's HEAD, not develop's. The dialog then computes an inflated commit count. Use the base branch's tip instead.

Suggested change
let originalHeadCommit = '';
let originalHeadCommit = '';
try {
const baseRef = baseBranch ?? 'HEAD';
originalHeadCommit = (await service.git.raw(['rev-parse', baseRef])).trim();
} catch (error) {

— DeepSeek/deepseek-v4-pro via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

False-positive (Filter 1). There is no base_branch parameter in EnterWorktreeTool (see EnterWorktreeParams at enter-worktree.ts:20). baseBranch is set from service.getCurrentBranch() which is the same commit as service.getCurrentCommitHash() (both read the main repo's HEAD), so originalHeadCommit is equivalent to the base branch's tip at creation time. The dialog's rev-list --count <originalHeadCommit>..HEAD inside the worktree therefore correctly counts commits made IN the worktree.

session: WorktreeSession,
): Promise<void> {
await fs.mkdir(path.dirname(filePath), { recursive: true });
await fs.writeFile(filePath, JSON.stringify(session, null, 2), 'utf-8');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Critical] writeWorktreeSession uses a direct fs.writeFile() — not atomic. If the process crashes mid-write, the sidecar file is truncated or contains partial JSON. readWorktreeSession throws SyntaxError from JSON.parse, which all consumers silently degrade to "no active worktree". Use the project's existing atomicWriteJSON utility.

Suggested change
await fs.writeFile(filePath, JSON.stringify(session, null, 2), 'utf-8');
import { atomicWriteJSON } from '../utils/atomicFileWrite.js';
// inside writeWorktreeSession:
await fs.mkdir(path.dirname(filePath), { recursive: true });
await atomicWriteJSON(filePath, session);

— DeepSeek/deepseek-v4-pro via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 38db00f. writeWorktreeSession now uses atomicWriteJSON (write-to-temp + rename), so a crash mid-write can no longer leave a truncated sidecar.

const gitHooksPath = path.join(this.sourceRepoPath, '.git', 'hooks');
let hooksPath: string | null = null;
for (const candidate of [huskyPath, gitHooksPath]) {
try {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Critical] The fs.stat loop in configureHooksPath catches ALL errors identically, treating them as "candidate not found". If .husky/ exists but fs.stat fails with EACCES (permission), EIO, or any transient filesystem error, the function silently falls through. If .git/hooks/ is also inaccessible, NO hooks are configured and worktree commits silently bypass all main-repo hooks.

Suggested change
try {
} catch (error) {
if (!isNodeError(error) || error.code !== 'ENOENT') {
debugLogger.warn(
`configureHooksPath: cannot stat ${candidate}: ${error}`,
);
}
}

— DeepSeek/deepseek-v4-pro via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 38db00f. configureHooksPath now distinguishes ENOENT (the expected "this candidate isn't present" signal) from any other code (EACCES/EIO/ENOTDIR). The latter are warn-logged via debugLogger.warn so a silently-degraded hooksPath is visible to operators.

// Watch the parent dir so create/delete/rename events on the
// sidecar (which may not exist at mount time) are caught.
watcher = fs.watch(dirPath, (_eventType, filename) => {
if (filename === fileName) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] fs.watch on Linux returns filename as a Buffer when no encoding is specified. The comparison filename === fileName (string) always evaluates to false, so the watcher silently never fires on Linux. The Footer indicator won't react to enter_worktree / exit_worktree calls.

Suggested change
if (filename === fileName) {
if (filename?.toString() === fileName) {

— DeepSeek/deepseek-v4-pro via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 38db00f. fs.watch callback now normalizes filename via toString() so the Linux Buffer code path triggers reloads (previously the === fileName string comparison silently never matched). Also treats null filename as "unknown, reload to be safe" — recursive watchers on some platforms emit events without a payload.

args: string[],
cwd: string,
): Promise<{ stdout: string; code: number }> {
return new Promise((resolve) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] execGit always resolves (never rejects), and on error returns {stdout: '', code: 1}. Callers only read stdout. If git status --porcelain or git rev-list --count fails (e.g., corrupt index, git not in PATH), the dialog silently shows "0 files, 0 commits" instead of surfacing the error. The user may choose "remove" thinking nothing is at risk.

Expose the error state so the dialog can warn the user when git commands fail.

— DeepSeek/deepseek-v4-pro via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 38db00f. The dialog now tracks a probeError state; when git status or git rev-list returns non-zero or errors at spawn level, the dialog renders an ⚠ Could not measure worktree state (...) banner with the actual exit code or errno. Users see the failure explicitly before choosing Remove.

*
* Shared by TUI / headless / ACP entry points so all three behave
* consistently on `--resume`. Failures are logged via the supplied
* `onWarn` callback but never thrown — worktree restore is best-effort,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] When readWorktreeSession throws due to corrupted JSON (SyntaxError), restoreWorktreeContext returns nulls but does NOT delete the corrupted sidecar file. Every subsequent --resume will repeat the same parse error and silently fail to restore worktree context. The stale-directory cleanup path correctly calls clearWorktreeSession, but the corrupted-JSON path does not.

Suggested change
* `onWarn` callback but never thrown worktree restore is best-effort,
} catch (error) {
onWarn?.(error);
// Clean up corrupted sidecar so it doesn't block every --resume.
try { await clearWorktreeSession(sidecarPath); } catch {}
return { contextMessage: null, session: null };
}

— DeepSeek/deepseek-v4-pro via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 38db00f. restoreWorktreeContext now calls clearWorktreeSession when readWorktreeSession returns null (malformed JSON / missing fields / wrong types) AND when reading throws a non-ENOENT I/O error. Subsequent --resume calls no longer keep tripping on the same broken file.

@tanzhenxin tanzhenxin added the type/feature-request New feature or enhancement request label May 17, 2026

@wenshao wenshao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ CI failing: Test (windows-latest, Node 22.x), Test (ubuntu-latest, Node 22.x)

Additional findings (not inline-mappable):

  • [Critical] handleWorktreeExit remove path bypasses ExitWorktreeTool safety guards (AppContainer.tsx:1105-1132): The dialog's "Remove" path calls removeUserWorktree() directly without the dirty-state, unmerged-commit, or session-ownership checks that ExitWorktreeTool.execute() enforces. A user who clicks "Remove" on a dirty worktree permanently loses uncommitted changes. Consider factoring the safety guards into a shared function.

  • [Suggestion] loadDirtyState doesn't check git exit code (WorktreeExitDialog.tsx:88-110): If git status --porcelain fails (e.g., worktree deleted between dialog mount and git execution), statusRes.stdout is empty and the dialog silently shows "0 uncommitted files" — presenting a clean-worktree state that's actually an error state.

  • [Suggestion] closeAnyOpenDialog doesn't handle showWorktreeExitDialog (useDialogClose.ts:76-142): Every other dialog in the application can be dismissed by Ctrl+C via closeAnyOpenDialog, but WorktreeExitDialog is the only exception — it can only be dismissed via Escape.

  • [Suggestion] Test coverage gaps: nonInteractiveCli.ts headless --resume worktree restore (3 branches untested), useWorktreeSession.ts hook (no test file), Footer.tsx worktree indicator (0 worktree assertions), useStatusLine.ts worktree payload (0 assertions).

— mimo-v2.5-pro via Qwen Code /review

): Promise<WorktreeSession | null> {
try {
const raw = await fs.readFile(filePath, 'utf-8');
return JSON.parse(raw) as WorktreeSession;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Critical] readWorktreeSession performs JSON.parse(raw) as WorktreeSession with zero runtime validation. If the sidecar file is partially written (process killed during writeFile), truncated by disk full, or manually edited, the parsed object may have undefined for critical fields like worktreePath or slug. This corrupted object propagates through the entire system: WorktreeExitDialog runs git status with cwd: undefined, removeUserWorktree(undefined, ...) may operate on the wrong worktree, and Footer renders ⎇ undefined (undefined).

Suggested change
return JSON.parse(raw) as WorktreeSession;
const parsed = JSON.parse(raw);
if (
typeof parsed?.slug !== 'string' ||
typeof parsed?.worktreePath !== 'string' ||
typeof parsed?.worktreeBranch !== 'string'
) {
return null;
}
return parsed as WorktreeSession;

— mimo-v2.5-pro via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 38db00f. readWorktreeSession now schema-validates the parsed object via isValidWorktreeSession and returns null when any of the 6 required string fields is missing or wrong-typed. Partial writes, schema drift, and manual edits can no longer propagate undefined paths into removeUserWorktree / git status / Footer rendering.

code: error
? typeof (error as NodeJS.ErrnoException).code === 'number'
? ((error as NodeJS.ErrnoException).code as unknown as number)
: 1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] execGit extracts the exit code via (error as NodeJS.ErrnoException).code, but NodeJS.ErrnoException.code is always a string (e.g., 'ENOENT', 'EPERM') — never a number. The typeof ... === 'number' check always evaluates to false, so code is always 1 on any error regardless of the actual git exit code. The real exit code is on (error as any).status.

Suggested change
: 1
code: error
? ((error as NodeJS.ErrnoException & { status?: number }).status ?? 1)
: 0,

— mimo-v2.5-pro via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 38db00f. execGit now reads exit codes from both possible fields: .code as number (subprocess exit codes like 128 "not a git repository") AND .status as number (some Node versions). String .code (e.g. 'ENOENT' from spawn failure) goes into a separate errno field surfaced to the dialog. The previous typeof === 'number' check on .code always evaluated false because for git exits the field is typed as number but my old read path tested the string-typed shape.

worktreePath={uiState.activeWorktree.path}
originalHeadCommit={uiState.activeWorktree.originalHeadCommit}
onKeep={() => void uiActions.handleWorktreeExit('keep')}
onRemove={() => void uiActions.handleWorktreeExit('remove')}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Critical] handleWorktreeExit is async (it awaits removeUserWorktree and clearWorktreeSession), but the callback discards the returned Promise via () => void. This creates a fire-and-forget pattern: the dialog dismisses immediately, the /quit sequence starts, and if process.exit() fires before the git worktree remove subprocess completes, the worktree is left on disk as an orphan with no log or error.

Suggested change
onRemove={() => void uiActions.handleWorktreeExit('remove')}
onRemove={async () => { await uiActions.handleWorktreeExit('remove'); }}

— mimo-v2.5-pro via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Declined — false-positive (Filter 1). handleSlashCommand('/quit') is the LAST statement inside handleWorktreeExit's async function body, gated by the preceding await svc.removeUserWorktree(...) and await clearWorktreeSession(...). The race described ("process.exit fires before git worktree remove completes") cannot occur because /quit is sequenced AFTER both awaits resolve. The Promise discard at the () => void callsite only suppresses the outer Promise — it doesn't break the internal await chain.

LaZzyMan and others added 3 commits May 18, 2026 10:07
…l-b6e48c

# Conflicts:
#	packages/cli/src/ui/AppContainer.tsx
#	packages/cli/src/ui/hooks/useStatusLine.ts
Bundled response to the two review rounds. Per-thread replies follow.

CORE — worktree sidecar robustness (Findings 3252368644, 3252368651, 3255171690):
- atomicWriteJSON instead of fs.writeFile (no more half-written sidecar after a crash)
- readWorktreeSession now schema-validates the parsed object and returns null
  on missing/wrong-type fields instead of propagating undefined into consumers
- restoreWorktreeContext clears the sidecar on JSON parse failure / read I/O
  error so a corrupted file doesn't block every subsequent --resume

CORE — hooksPath setup (Finding 3252368645):
- configureHooksPath distinguishes ENOENT (benign "candidate not present")
  from real stat errors (EACCES/EIO/ENOTDIR); the latter are warn-logged
  so a silently-degraded hooksPath is visible to operators

CLI — handleWorktreeExit Remove path (Findings 3252368637, 3252368640 a+b):
- Anchor GitWorktreeService at activeWorktree.originalCwd (the captured
  repo root), not config.getTargetDir() — fixes monorepo-subdirectory
  launches where the worktree lives under the repo root but getTargetDir
  points at a subpackage
- Check removeUserWorktree return value; on failure, leave the sidecar
  intact so --resume can recover (previous code cleared it regardless)
- Pass forceDeleteBranch:true to honour the dialog's "discards N commits"
  label — without it `git branch -d` refused unmerged commits and the
  branch was silently preserved

CLI — useWorktreeSession watcher (Finding 3252368648):
- Normalize fs.watch filename via toString() so the Linux-Buffer code
  path triggers reloads (previous comparison silently never matched)
- Treat null filename as "unknown, reload to be safe" (recursive watchers
  on some platforms emit events without a payload)

CLI — WorktreeExitDialog (Findings 3252368650, 3255171694):
- execGit now correctly reads numeric exit codes from .code/.status
  (NodeJS.ErrnoException.code is a string for spawn errors, number for
  subprocess exits); previous typeof === 'number' check always missed
- Dialog body shows an "⚠ Could not measure worktree state (...)" banner
  when git status / rev-list failed, so the user doesn't see a misleading
  "0 files, 0 commits" before choosing Remove

CLI — closeAnyOpenDialog (Round 2 review body):
- Wire WorktreeExitDialog into the standard dialog-dismissal path so
  Ctrl+C dismisses it the same way it dismisses every other dialog

TEST FIXES — vitest timeouts:
- Real git invocations + user-global hooks (e.g. trustup post-commit
  webhooks) can take 10–20s per setUp on CI. Bump testTimeout +
  hookTimeout to 30s for the three integ test suites that spawn git
  (Phase B/C worktree integ tests) so the suite isn't flaky.

NEW TESTS:
- worktreeSessionService.test: 3 new cases covering malformed JSON,
  missing required fields, wrong-type fields, malformed sidecar cleanup,
  partial sidecar cleanup (16 total, up from 13).
- useWorktreeSession.test.tsx: 4 new cases — null when no sidecar,
  parsed sidecar at mount, reacts to delete, reacts to creation.
- WorktreeExitDialog.test.tsx: 1 new case — loading frame renders before
  git probes resolve. (Async dialog states tested via E2E — vi.mock of
  execFile in ink-testing-library doesn't fire mock impl reliably.)
- nonInteractiveCli.test: 3 new "Phase C --resume" cases — system-reminder
  injection on live worktree, no injection when sidecar absent, stale
  sidecar cleanup when worktree dir is gone.

DECLINED FINDINGS (replied on threads):
- 3252368642 (Dialog Keep clears sidecar) — declined-design. Dialog
  Keep = "exit app, keep worktree for next --resume"; tool Keep =
  "I'm done with this worktree". Intentionally different semantics.
- 3252368643 (originalHeadCommit base branch) — false-positive. There
  is no base_branch parameter; getCurrentCommitHash() returns HEAD which
  equals the tip of the current branch (== baseBranch in createUserWorktree).
- 3252368640 part c (bypass safety guards) — declined-design. The
  dialog IS the safety affordance for this path — it shows dirty-state
  counts and asks for explicit user confirmation before removal.
- 3255171696 (DialogManager async fire-and-forget) — false-positive.
  handleSlashCommand('/quit') is inside the await chain in
  handleWorktreeExit, so the described race ("process.exit before remove
  completes") cannot occur.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Pre-commit hook auto-fixed imports collapsed value imports
(writeWorktreeSession, clearWorktreeSession) into an `import type`
block, breaking runtime resolution. Split back into value + type imports.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@LaZzyMan

Copy link
Copy Markdown
Collaborator Author

Round 2 + Round 3 review summary — addressed in commits 38db00f6d + c0c0e71df (plus the merge of main in b8c2a5d11).

Per-finding outcomes

# comment_id Verdict
GitWorktreeService config.getTargetDir() vs originalCwd 3252368637 ✅ fixed
removeUserWorktree return / forceDeleteBranch / safety bypass 3252368640 ✅ parts 1+2 fixed, part 3 declined-design
Dialog Keep doesn't clearWorktreeSession 3252368642 ❌ declined-design
originalHeadCommit base branch 3252368643 ❌ false-positive
writeWorktreeSession not atomic 3252368644 ✅ fixed (atomicWriteJSON)
hooksPath fs.stat catches all errors 3252368645 ✅ fixed (ENOENT vs others)
fs.watch filename Buffer on Linux 3252368648 ✅ fixed (toString + null handling)
execGit swallows errors silently 3252368650 ✅ fixed (probeError banner)
Corrupted JSON doesn't clear sidecar 3252368651 ✅ fixed
readWorktreeSession no schema validation 3255171690 ✅ fixed (isValidWorktreeSession)
execGit exit code typed wrong 3255171694 ✅ fixed (reads .code or .status as number)
Async fire-and-forget in DialogManager 3255171696 ❌ false-positive (gated by await chain)
Test coverage gaps (R1 + R2 review bodies) ✅ added 11 tests across 3 files
closeAnyOpenDialog gap (R2 review body) ✅ fixed

Test coverage added

  • worktreeSessionService.test.ts: +3 cases for malformed JSON, missing fields, wrong-type fields, plus the corrupted-sidecar cleanup paths. 16/16 pass.
  • useWorktreeSession.test.tsx (new): 4 cases covering null on no-sidecar, parsed sidecar at mount, reacts to delete, reacts to creation. 4/4 pass.
  • WorktreeExitDialog.test.tsx (new): 1 case for the loading-frame render. Note: the dialog's post-load states (dirty counts, probe-error banner, Remove label variants) are covered by the E2E Group E suite. Driving the async useEffect through ink-testing-library with a mocked execFile proved unreliable in this harness; E2E exercises the real git subprocess against a real temp repo.
  • nonInteractiveCli.test.ts: +3 "Phase C --resume" cases verifying (a) <system-reminder> injection when sidecar names a live worktree, (b) no injection when sidecar absent, (c) stale-sidecar cleanup when worktree dir is gone. 45/45 pass.

Round 2 review body items (no inline ids)

  • Bypass safety guards in handleWorktreeExit: same as inline finding 3252368640 part c — declined-design. The dialog itself surfaces dirty-state counts + "discards N commits" label before remove; that IS the safety affordance.
  • loadDirtyState doesn't check git exit code: addressed via probeError banner (inline 3252368650 fix).
  • closeAnyOpenDialog doesn't handle showWorktreeExitDialog: ✅ added in 38db00f. Ctrl+C / global-escape now dismiss the dialog the same way they dismiss other modals.
  • Test coverage gaps: see "Test coverage added" above.

Other notable changes in this push

  • Merged in 16 commits from main (including f44ed0941 serve/preflight + 78c65c8de ink 7 + 02a65f90c zh-TW i18n + others). Reconciled two import-collision conflicts in AppContainer.tsx and useStatusLine.ts.
  • Bumped vitest timeouts for the four integ test suites that spawn real git (gitWorktreeService.hooks.integ.test.ts, enter-worktree.session.integ.test.ts, exit-worktree.session.integ.test.ts, exit-worktree.test.ts) — under user-global hooks (e.g. trustup post-commit) these were taking 10–20s per setUp and timing out the default 5s ceiling on CI.

Verification

# Core: 87/87
cd packages/core && npx vitest run \
  src/services/worktreeSessionService.test \
  src/services/gitWorktreeService.test \
  src/services/gitWorktreeService.hooks.integ.test \
  src/tools/enter-worktree.test \
  src/tools/exit-worktree.test \
  src/tools/enter-worktree.session.integ.test \
  src/tools/exit-worktree.session.integ.test
# CLI: 68/68 (worktree-scoped)
cd packages/cli && npx vitest run \
  src/ui/components/Footer.test \
  src/ui/components/DialogManager.test \
  src/ui/components/WorktreeExitDialog.test \
  src/ui/hooks/useWorktreeSession.test \
  src/acp-integration/acpAgent.worktree.test \
  src/acp-integration/session/Session.worktree.test \
  src/nonInteractiveCli.test

npm run typecheck --workspace=@qwen-code/qwen-code-core   # clean
npm run typecheck --workspace=@qwen-code/qwen-code        # clean
npm run build && npm run bundle                           # dist/cli.js produced

…integ

Windows CI failure: `repoRoot` from Node's `fs.mkdtemp` returns
backslash-separated paths (`C:\Users\runneradmin\…`), but
`originalCwd` in the sidecar comes from `getRepoTopLevel()` which
delegates to `git rev-parse --show-toplevel` — git on Windows
returns forward slashes (`C:/Users/runneradmin/…`).

The Windows-only assertion `expect(originalCwd).toBe(repoRoot)` was
comparing two different representations of the same canonical path
and rightly failed on `Object.is` equality. Compare via path.normalize
on both sides so the assertion holds across platforms without
changing the runtime path (originalCwd still records git's output
verbatim, which is what consumers expect since other places in the
codebase that read `getRepoTopLevel()` also work with that shape).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
slug: string;
worktreePath: string;
worktreeBranch: string;
originalCwd: string;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit — originalCwd 字段名与存储值不一致

enter-worktree.ts:201 写入这个字段时用的是 projectRoot(即 getRepoTopLevel() 的返回值,repo top-level),不是用户调用时的 cwdAppContainer.handleWorktreeExit 的注释里也明确说明:

// Anchor at the repo top-level (captured at enter time) rather
// than the current targetDir — when the CLI was launched from
// a monorepo subdirectory, `config.getTargetDir()` is that
// subdir but the worktree lives at `<repoRoot>/.qwen/worktrees/`
const svc = new GitWorktreeService(activeWorktree.originalCwd);

字段名读起来是"用户最初的 cwd",实际语义是"repo top-level"。两者在 monorepo subdir 场景下不同——这正是 #3252368637 这条 review 修复的根因。

字段名让未来的维护者容易再次踩坑:看到 originalCwd 会假定它是 process.cwd() 当时的值,而不是 getRepoTopLevel() 的结果。建议改名为 originalProjectRootrepoTopLevel。当前行为正确,仅是命名问题。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Doc-only fix in d4e921a. Renaming the on-disk field would force every existing sidecar to be migrated (each active --resume breaks until the user wipes the old file), so I kept the name for back-compat and added an explicit JSDoc on WorktreeSession.originalCwd that calls out: (1) the field stores getRepoTopLevel() not process.cwd(), (2) consumers expecting cwd semantics should NOT use this field, (3) it's named originalCwd for historical reasons. Future maintainers reading the type definition will see the divergence the name doesn't surface.

// a soft failure. If removal failed, leave the sidecar intact
// so the next --resume can still see the worktree and let the
// user retry. (Finding 3252368640 part 1.)
if (!result.success) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Critical] handleWorktreeExit 在 remove 失败时静默 /quit(follow-up #3252368640)

之前 #3252368640 part 1 的修复加了 !result.success 检测,但是失败分支仍然直接 /quit

if (!result.success) {
  handleSlashCommand('/quit');
  return;
}

用户的 mental model:在 dialog 里看到"discards N commits, M files"+点了 Remove → 期望 worktree 被删除。如果 git worktree remove --force 因为权限/锁/损坏失败,用户收不到任何反馈就 quit 了。下次重启时 sidecar 还在(注释里说这是设计),但用户不知道发生了什么、需要去哪里看、worktree 还在不在磁盘上。

建议在 quit 前给个 UI feedback:

if (!result.success) {
  historyManager.addItem(
    {
      type: MessageType.ERROR,
      text: `Failed to remove worktree "${activeWorktree.slug}": ${result.error}. The worktree is still on disk; use \`exit_worktree\` or remove it manually.`,
    },
    Date.now(),
  );
  // 给用户一帧渲染时间再退出
  setTimeout(() => handleSlashCommand('/quit'), 0);
  return;
}

或者更保守的:失败时不退出,把 dialog 关掉让用户继续在 session 里处理(Cancel 路径就是这样)。Remove 失败应该让用户决定下一步,而不是替他们决定退出。

另外硬失败 catch 块同样问题——/* Hard failure */ 注释承认了这点但仍 fall-through 到 /quit,也建议加 feedback。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in d4e921a. Took the more conservative option you suggested: failure path now surfaces an ERROR history item (Failed to remove worktree "X": <reason>. The worktree is still on disk; use exit_worktree to retry...) and stays in the session instead of /quit'ing. User can then decide — retry via exit_worktree, fix the underlying problem, or force-quit manually. Same treatment applied to the hard-failure catch block (previously it caught the throw and fell through to /quit silently — now emits the error and returns).

// Watcher setup is best-effort: the hook still returns whatever
// load() resolved with on mount. Without a watcher, the UI just
// doesn't react to sidecar changes until the next re-mount.
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit — fs.watch 不会幸存 chatsDir 被删除/轮转

fs.watch(dirPath) 持有的是 inode 句柄。如果 ~/.qwen/projects/.../chats/ 被删除(用户重置状态、杀毒软件隔离、清理脚本)然后被另一个进程重建,watcher 不会重新挂到新 inode 上——Footer 的 worktree 指示器从此停止响应 sidecar 变化。

mount-time 的 mkdir({ recursive: true }) 解决了"首次启动目录不存在",但解决不了"运行中目录消失"。

两种处理方式:

  • 加一个降级的 polling tick(比如 5s 一次 stat sidecar 文件)作为 fallback;watcher 仍然是主路径,polling 只在 watcher 失效时兜底;
  • 监听 error 事件并尝试重新 setupWatcher()
    watcher = fs.watch(dirPath, ...);
    watcher.on('error', () => {
      watcher?.close();
      void setupWatcher();
    });

实操中这是边缘情况——chatsDir 在正常使用中不会被删除——可以接受作为已知 limitation 不修。但建议在 hook 顶部加一行 JSDoc 说明 "watcher does not self-heal if chatsDir is rotated",便于未来排障。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Doc-only fix in 80f9cb4. Took the documented-limitation path you proposed — chatsDir deletion mid-session is rare enough that the polling-fallback / error-event-reset complexity isn't justified. Added a JSDoc block on useWorktreeSession explaining the limitation and pointing future maintainers at the two fix shapes if rotation ever becomes a real failure mode.

statusline (their script already gets `worktree` in stdin payload
and likely renders it itself). Also hidden during ctrl-quit
warnings so they take precedence. */}
{uiState.activeWorktree &&

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit — 自定义 statusline 时 worktree 指示器完全消失

{uiState.activeWorktree &&
  statusLineLines.length === 0 &&  // ← 这里
  !uiState.ctrlCPressedOnce &&
  !uiState.ctrlDPressedOnce && (
    <Text dimColor wrap="truncate">
      {`⎇ ${uiState.activeWorktree.branch} (${uiState.activeWorktree.slug})`}
    </Text>
  )}

statusLineLines.length === 0 这个条件假设了:如果用户有自定义 statusline,那他们会自己在脚本里渲染 payload.worktree。但脚本是用户写的:

  • 用户脚本可能在 PR 之前就写好了,根本不知道 payload.worktree 字段存在;
  • 用户脚本可能故意忽略 worktree(觉得不需要),但用户其实希望看到内置指示器;
  • 用户脚本可能只渲染了部分字段,没渲染 worktree。

这三种情况下,用户有 active worktree 但 Footer 上完全看不到 — 容易让用户忘记自己在 worktree 里、对着错误的目录操作。

两种处理:

  • 保持现状但在 docs/design/worktree.md 里明确说明"自定义 statusline 时需要自行渲染 worktree",并在 payload.worktree 字段加个 docstring;
  • 加个 settings 开关 statusline.suppressBuiltinWorktree: false 让用户主动 opt out(默认 false = 即使有 custom statusline 也保留内置 ⎇ 指示器,避免静默丢失)。

(b) 更安全,因为 worktree 指示器是 awareness UX 而不是装饰——丢了它用户可能在错的 cwd 上做破坏性操作。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 80f9cb4 — went with your option (b). Dropped the statusLineLines.length === 0 gate; built-in indicator now shows by default whenever activeWorktree is non-null. Added ui.hideBuiltinWorktreeIndicator (default false) as the explicit opt-out for users whose custom statusline already renders worktree and want to avoid duplication. Default-safe + opt-out matches the awareness-UX priority you flagged.

LaZzyMan and others added 3 commits May 18, 2026 12:00
Finding #3256237933 (Critical, follow-up to #3252368640 part 1):
handleWorktreeExit silently /quit'd when removeUserWorktree returned
{success:false}, contradicting the user's intent after they clicked
"Remove worktree and branch (discards N commits, M files)". Now
surfaces an ERROR history item with the underlying error message
and STAYS in the session so the user can decide what to do
(retry via exit_worktree, fix the lock/permission/corruption issue,
or quit anyway). Same treatment applied to the hard-failure catch
block — previously it caught the throw and proceeded to /quit with
no log; now it emits the error and stays alive.

Finding #3256236050 (Nit): originalCwd field name implies "user's
launch cwd" but actually stores `getRepoTopLevel()` (different in
monorepo subdir launches — the gap closed by #3252368637). Renaming
the field would force on-disk migration of every existing sidecar
(every active --resume breaks until users wipe the old file).
Doc-only fix: WorktreeSession.originalCwd now carries an explicit
JSDoc explaining the semantics and warning consumers expecting
process.cwd() to NOT use this field.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Finding #3256241831 (Nit, but awareness UX): the built-in `⎇`
indicator used to disappear whenever `statusLineLines.length > 0`,
on the assumption that the user's custom statusline rendered worktree
itself. That assumption is unsafe — scripts written before Phase C
don't know about `payload.worktree`, scripts can deliberately ignore
the field, and partial scripts may render some fields but not
worktree. In any of those cases the user sees no worktree UI while
having an active worktree, risking destructive operations in the
wrong cwd. New behavior: indicator shows by default regardless of
statusline. Added an opt-out setting `ui.hideBuiltinWorktreeIndicator`
(default false) for users whose custom statusline already renders
worktree and want to avoid duplication.

Finding #3256239608 (Nit): `fs.watch` in useWorktreeSession holds
an inode handle to `chatsDir` at mount time. If the directory is
deleted out-of-band (manual cleanup, antivirus quarantine, reset
scripts) and recreated, the watcher does NOT re-attach to the new
inode and the Footer indicator stops reacting to sidecar changes.
Reviewer explicitly accepted this as a documented limitation rather
than adding polling-fallback or error-event-handler complexity for
an edge case that doesn't arise in normal use. Added a JSDoc block
on the hook explaining the limitation and pointing to the future
fix shapes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…reeIndicator

CI Lint step caught that the JSON schema mirror in
packages/vscode-ide-companion was out of date after adding the new
ui.hideBuiltinWorktreeIndicator setting in 80f9cb4. Regenerated
via `npm run generate:settings-schema`.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@wenshao wenshao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Previous review round fixes look good. Two remaining test coverage gaps:

  • WorktreeExitDialog unit tests only assert the loading state; post-load states (dirty counts, remove-label variants, probeError banner) are covered by E2E Group E only — not npm test.
  • AppContainer.handleWorktreeExit callback (~80 lines, 4+ branches: cancel/keep/remove-success/remove-failure) has zero unit test coverage.

— DeepSeek/deepseek-v4-pro via Qwen Code /review


let worktreeAlive = false;
try {
const stat = await fs.stat(session.worktreePath);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] restoreWorktreeContext verifies worktreePath exists and is a directory via fs.stat, but does not validate it's actually a git worktree (e.g., check that .git is a file pointing back to the main repo, or that the path starts with <repo>/.qwen/worktrees/). If the sidecar JSON is corrupted, the model could be directed to operate in an arbitrary existing directory.

Suggested change
const stat = await fs.stat(session.worktreePath);
// After fs.stat confirms the path is a directory, also verify it's a worktree:
const gitFileStat = await fs.stat(path.join(session.worktreePath, '.git')).catch(() => null);
worktreeAlive = gitFileStat?.isFile() ?? false;

— DeepSeek/deepseek-v4-pro via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 7943487 (option chosen: structural prefix check, not the .git file probe). restoreWorktreeContext now requires worktreePath to resolve under <originalCwd>/.qwen/worktrees/ — schema validation already enforces the shape, this adds the boundary. A tampered/copied sidecar pointing at /etc, ~/, or any other existing dir is rejected and cleared. Went with the prefix check over the .git-is-file probe because the prefix is a structural invariant Qwen itself owns (every enter_worktree writes into that subtree), whereas .git file vs dir is a git-internal detail that depends on linked/main worktree state.

@wenshao wenshao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Critical] packages/cli/src/acp-integration/acpAgent.ts: loadSession() restores the persisted worktree context and queues pendingWorktreeNotice, but the parallel unstable_resumeSession() ACP resume path just creates the session and returns. ACP clients that call unstable_resumeSession() will resume a live worktree session without the first prompt being reminded to keep using the worktree path, and stale sidecars also won't be cleaned. Please factor the restore block used by loadSession() into a helper and call it from unstable_resumeSession() after createAndStoreSession() returns the Session.

— gpt-5.5 via Qwen Code /review

*/
private async configureHooksPath(worktreePath: string): Promise<void> {
const huskyPath = path.join(this.sourceRepoPath, '.husky');
const gitHooksPath = path.join(this.sourceRepoPath, '.git', 'hooks');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] The fallback assumes <sourceRepoPath>/.git is a directory, but when Qwen itself is launched from an existing git worktree, .git is a file that points at the real git dir. In that setup, repositories without .husky/ will probe <worktree>/.git/hooks, get ENOTDIR, and skip hook configuration entirely, so commits in the newly-created Qwen worktree can silently bypass the repo's hooks.

Please resolve the hooks directory via git (for example git rev-parse --git-common-dir / --git-dir) instead of constructing .git/hooks from the working tree path.

— gpt-5.5 via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 7943487. configureHooksPath now resolves the canonical hooks dir via git rev-parse --git-common-dir instead of constructing <sourceRepoPath>/.git/hooks. When Qwen runs from a linked worktree, .git is a file pointing at the real gitdir — the old construction ENOTDIRed and silently skipped hook configuration. The new path returns the gitdir-relative hooks/ directory regardless of worktree/main-repo shape.

// Key not set — empty string means "proceed with the write".
}
if (existing !== hooksPath) {
await worktreeGit.raw(['config', 'core.hooksPath', hooksPath]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] This overwrites any existing custom core.hooksPath in the worktree-local config whenever it differs from Qwen's preferred .husky / .git/hooks path. Repositories or users can already configure a custom hooks directory, and creating a Qwen worktree should not silently replace that policy.

Please preserve a non-empty existing value, or only write when the key is unset. If a worktree-specific override is required, treat inherited/custom values as intentional instead of replacing them unconditionally.

— gpt-5.5 via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 7943487. configureHooksPath now writes core.hooksPath only when the worktree-local key is unset (empty string from git config --local). A non-empty inherited or user-configured value is logged at debug level and preserved verbatim — the user/system policy wins. The Phase C "set hooksPath on creation" behavior is unchanged for fresh worktrees (whose local config starts empty).

}

if (this.params.action === 'keep') {
await this.maybeClearWorktreeSession();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Critical] keep leaves the worktree and branch on disk but clears the active sidecar. That makes subsequent --resume lose the persisted worktree binding, so the footer/exit dialog/restore path no longer know this session is still attached to the kept worktree and the model can fall back to editing the parent checkout.

Please keep the sidecar for action: 'keep' and only clear it after a successful remove of the currently tracked worktree. The success message can still tell the model to reference the path, but the persisted state must survive the session boundary.

— gpt-5.5 via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 7943487. exit_worktree action='keep' no longer clears the sidecar — preserving it lets --resume / Footer / WorktreeExitDialog continue to know about the kept worktree, which is exactly the user-visible promise of "keep". The model can still reference the worktree path via the tool's return value as before; only the persisted binding stops being torn down. The corresponding integ test was rewritten to assert preservation (clears-after-keep was a misguided behavior, not the spec).

// intent — without it, `git branch -d` refuses unmerged
// commits and the branch is silently preserved, contradicting
// the dialog text. (Finding 3252368640 part 2.)
const result = await svc.removeUserWorktree(activeWorktree.slug, {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Critical] The TUI dialog's remove path bypasses the ownership guard used by exit_worktree. The tool path reads the in-worktree session marker and refuses to remove another session's worktree, but this UI path trusts the sidecar and directly calls removeUserWorktree(..., forceDeleteBranch: true). A stale or copied sidecar can therefore let one session delete another session's worktree and branch through the dialog.

Please apply the same readWorktreeSessionMarker / config.getSessionId() check here before removal, and refuse or direct the user to the owning session when the marker belongs to a different session.

— gpt-5.5 via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 7943487. handleWorktreeExit's remove path now reads the in-worktree session marker via readWorktreeSessionMarker(activeWorktree.path) and compares against config.getSessionId() — same guard the ExitWorktreeTool tool path applies. When the marker names a different session, the dialog surfaces an ERROR with the owner id + manual recovery command and stays in the session (does not /quit). Stale or copied sidecars can no longer trigger cross-session destruction through the dialog.

console.debug('worktree session restore warning:', err);
});
if (restored.contextMessage) {
historyManager.addItem(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Critical] This restores the worktree only as a UI MessageType.INFO item. Unlike headless and ACP, the TUI path does not prepend the restored context to the next model request; useGeminiStream still sends only the user's next prompt to sendMessageStream(). The user will see the active-worktree notice, but the model is not reminded to keep using session.worktreePath, so resumed interactive sessions can still edit the parent checkout.

Please keep a one-shot pending worktree reminder for the TUI path as well and inject it into the next UserQuery sent to the model. The INFO item can remain for visibility, but it should not be the only restore mechanism.

— gpt-5.5 via Qwen Code /review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 7943487. AppContainer now owns a pendingWorktreeNoticeRef set during --resume restore and consumed by handleFinalSubmit on the user's first non-slash prompt. The submitted value is prefixed with the same <system-reminder>...</system-reminder> block headless and ACP use, so the model actually sees the worktree reminder in the next API request. The INFO history item remains for user visibility but is no longer the only restore mechanism.

Critical fixes:
- #3259975247: TUI dialog Remove now reads the in-worktree session
  marker and refuses to delete a worktree owned by a different
  session — same ownership guard ExitWorktreeTool already applies.
  Stale/copied sidecars can no longer destroy another session's work.
- #3259975249: TUI --resume queues a one-shot pendingWorktreeNotice
  ref consumed by handleFinalSubmit; the user's first prompt is
  prefixed with the same <system-reminder> block headless/ACP use.
  Previously only the INFO history item showed in the transcript
  (UI-only), so resumed models could silently edit the parent
  checkout.
- #3259975245: exit_worktree action='keep' no longer clears the
  sidecar. `keep` means "preserve the worktree for later"; clearing
  the persisted binding broke --resume / Footer / WorktreeExitDialog
  for kept worktrees. Now matches the Dialog keep semantics. Test
  updated to assert preservation instead of clearing.
- ACP unstable_resumeSession parity: factored the worktree restore
  block into #restoreWorktreeOnResume() and called from both
  loadSession() and unstable_resumeSession(). ACP clients using
  resume no longer miss the worktree context.

Suggestion-level fixes:
- #3259975237: configureHooksPath now resolves the canonical hooks
  dir via `git rev-parse --git-common-dir` instead of constructing
  `<sourceRepoPath>/.git/hooks`. The construction assumed .git is a
  directory, but when Qwen runs from a linked worktree it's a file
  pointing at the real gitdir → ENOTDIR → silent no-hooks worktree.
- #3259975242: only writes core.hooksPath when the key is unset.
  A non-empty inherited or user-configured value is preserved
  instead of being silently replaced.
- #3256839787: restoreWorktreeContext adds a structural invariant
  check — worktreePath must live under <originalCwd>/.qwen/worktrees/.
  A tampered/copied sidecar pointing at an arbitrary existing dir
  is rejected and cleared so the model can't be redirected.

Tests:
- worktreeSessionService.test: 17/17 (added prefix-escape rejection
  case + restructured the existing live-worktree case to satisfy
  the new structural invariant).
- exit-worktree.session.integ.test: rewrote keep test to assert
  preservation (matches new behavior).
- nonInteractiveCli.test: updated fixture worktreeDir to live
  under <originalCwd>/.qwen/worktrees/ for the prefix invariant.
- All other suites pass without modification.

Test coverage gap acknowledgement (no comment_id reply): per-handler
unit tests for handleWorktreeExit + dialog post-load states remain
covered by the E2E Group E suite in docs/e2e-tests/worktree-phase-c.md.
The execFile mock path in ink-testing-library still doesn't deliver
async useEffect state transitions reliably, so unit testing those
states adds more harness than signal; deferring.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@LaZzyMan

Copy link
Copy Markdown
Collaborator Author

Round 6 — addressed in commit 7943487b4. All 6 inline replies posted; two review-body items below.

Per-finding outcomes

# comment_id Verdict
worktreePath validation 3256839787 ✅ structural prefix check
hooksPath .git/hooks ENOTDIR 3259975237 git rev-parse --git-common-dir
hooksPath overwrites custom config 3259975242 ✅ write only when unset
tool keep clears sidecar 3259975245 ✅ preserve sidecar on keep
TUI remove bypasses ownership 3259975247 ✅ readWorktreeSessionMarker guard
TUI --resume model injection 3259975249 ✅ pendingWorktreeNoticeRef + prompt prefix
ACP unstable_resumeSession parity (review body) ✅ #restoreWorktreeOnResume() shared helper
Test coverage gap (review body) ⚠️ acknowledged — see below

ACP unstable_resumeSession parity (review body)

Factored the worktree-restore block from loadSession() into a private helper #restoreWorktreeOnResume(config, session). Both loadSession() and unstable_resumeSession() now call it after createAndStoreSession(). ACP clients using either entry point get identical restore behavior (stale-sidecar cleanup + pendingWorktreeNotice queued for the next prompt).

Test coverage gap (review body)

The reviewer's two gaps:

  • WorktreeExitDialog post-load states (dirty counts / Remove-label variants / probeError banner): covered end-to-end by docs/e2e-tests/worktree-phase-c.md Group E. Reproducing these in npm test requires driving the dialog's async useEffect through ink-testing-library with a mocked execFile; multiple attempts in earlier rounds found the mock implementation didn't fire reliably through the ink render loop. The E2E suite runs the actual git subprocesses against a real temp repo, which is the higher-fidelity check anyway.
  • AppContainer.handleWorktreeExit callback: unit-testing this requires mocking five orthogonal modules (GitWorktreeService, the worktree-session helpers, historyManager, useGeminiStream's submitQuery, and the slash-command runner) for ~80 LoC of branches. The branches that matter — Cancel preserves session, Keep exits + preserves wt, Remove with ownership-OK / ownership-mismatch / success / failure — are again covered end-to-end in Group E (5 scenarios across 5 distinct temp git repos).

Defer adding unit tests for those two surfaces until the ink-testing-library execFile-mock pattern is solved separately. The E2E coverage is current.

Verification

cd packages/core && npx vitest run \
  src/services/worktreeSessionService.test \
  src/services/gitWorktreeService.test \
  src/services/gitWorktreeService.hooks.integ.test \
  src/tools/enter-worktree.test \
  src/tools/exit-worktree.test \
  src/tools/enter-worktree.session.integ.test \
  src/tools/exit-worktree.session.integ.test
# → 88/88

cd packages/cli && npx vitest run \
  src/ui/components/Footer.test \
  src/ui/components/DialogManager.test \
  src/ui/components/WorktreeExitDialog.test \
  src/ui/hooks/useWorktreeSession.test \
  src/acp-integration/acpAgent.worktree.test \
  src/acp-integration/session/Session.worktree.test \
  src/nonInteractiveCli.test
# → 68/68

@wenshao wenshao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No new issues found after 6 prior review rounds. All previously reported findings have been addressed in the latest commit. Build, typecheck, and tests pass (17/17 core worktree tests, 25 CLI tests). The one remaining low-confidence item (handleWorktreeExit not checking result.branchPreserved) is a rare edge case with forceDeleteBranch: true and does not block merge. LGTM ✅ — qwen-latest-series-invite-beta-v28 via Qwen Code /review

@LaZzyMan LaZzyMan merged commit a7e0530 into main May 19, 2026
21 checks passed
dreamWB added a commit to dreamWB/qwen-code that referenced this pull request May 20, 2026
…Session

AppContainer.test.tsx mocks every hook that AppContainer.tsx imports,
but the two new hooks (usePreferredEditor from this PR,
useWorktreeSession from main's QwenLM#4174) were not mocked — causing the
real hooks to execute during tests, crash on missing context, and fail
all 47 downstream assertions.
pomelo-nwu pushed a commit that referenced this pull request May 21, 2026
* feat(cli): respect /editor preference in Ctrl+X external editor

The Ctrl+X external editor prompt previously ignored the
general.preferredEditor setting, always falling back to $VISUAL/$EDITOR
env vars. Now it consults the preferred editor first, using the correct
--wait flags for GUI editors, and falls back to env vars only when no
preference is set or the preferred editor is unavailable.

Closes #4165

* fix(cli): address review feedback on external editor feature

- Fix command injection risk: quote args when needsShell is true
- Move writeFileSync inside try/finally with mode 0o600
- Change temp file extension from .md to .txt
- Extend needsShell check to cover .bat extension
- Fix import formatting in AgentComposer.tsx
- Extract usePreferredEditor hook to deduplicate validation
- Add 12 tests for openInExternalEditor covering all branches

* test(cli): add missing vi.mock for usePreferredEditor and useWorktreeSession

AppContainer.test.tsx mocks every hook that AppContainer.tsx imports,
but the two new hooks (usePreferredEditor from this PR,
useWorktreeSession from main's #4174) were not mocked — causing the
real hooks to execute during tests, crash on missing context, and fail
all 47 downstream assertions.

* fix(cli): address review feedback on env-var fallback and spawnSync timeout

- Detect .cmd/.bat in env-var fallback path on Windows and enable shell
  mode with quoted args, matching the preferred-editor path behavior
- Add 30-minute timeout to spawnSync to prevent terminal freeze when a
  GUI editor hangs
- Add test cases for both changes

* fix(cli): propagate preferredEditor to TextInput component

TextInput creates its own useTextBuffer but was not passing
preferredEditor, so Ctrl+X in secondary inputs (dialogs, settings
prompts, etc.) silently ignored the /editor preference.

* fix(cli): document why simple double-quoting is safe for shell args

The args passed to cmd.exe are program-controlled (tmpdir path + fixed
flags), never arbitrary user input. cmd.exe does not expand $() or
backticks inside double quotes. This matches Claude Code's approach.

* fix(cli): handle signal-killed editor and defer undo snapshot

- Check spawnSync signal field to avoid reading stale temp file
  when editor is killed by SIGTERM/SIGKILL
- Move undo snapshot creation after successful file read to prevent
  phantom no-op undo entries on editor failure

* fix(cli): restore private tmpdir, skip undo on unchanged content

- Restore mkdtempSync isolation directory (was flattened to os.tmpdir)
- Skip undo snapshot when editor content is unchanged
- Update JSDoc to reflect deferred-snapshot behavior
- Remove unused crypto import
- Add tests: unchanged content skip, tmpDir cleanup, undo precision

* fix(cli): use path.join in external editor tests for Windows compat

Tests hardcoded forward-slash paths which fail on Windows where
path.join produces backslashes. Use pathMod.join for the expected
temp file path so assertions pass on all platforms.

* fix(cli): quote editorCmd in shell mode, wrap setRawMode, improve logging

- Quote editorCmd along with args when shell: true, so Windows paths
  with spaces (e.g. C:\Program Files\...\code.cmd) survive cmd.exe.
- Wrap setRawMode restore in try/catch so a destroyed stdin doesn't
  skip temp file cleanup.
- Include command, shell mode, and resolution source in error log.
- Add tests: CRLF normalization, readFileSync failure, editorCmd quoting.

* refactor(core): remove unused isTerminal from ExternalEditorCommand

The field was never consumed by any caller — only command, args, and
needsShell are destructured. The standalone isTerminalEditor() function
already serves the same purpose for openDiff.

* docs(cli): update stale JSDoc on openInExternalEditor

Reflect the new editor resolution order (/editor → $VISUAL → $EDITOR → vi)
and the moved undo-snapshot timing (after editor exit, not before).

* fix(cli): address review round 3 — temp dir leak, mkdtemp safety, TextInput stdin

- Split unlinkSync/rmdirSync into separate try/catch blocks to prevent
  temp directory leak when unlinkSync throws (regression from main)
- Move mkdtempSync inside try block with early return on failure
- Pass stdin/setRawMode from TextInput to useTextBuffer so terminal
  editors (vim/neovim/emacs) correctly toggle raw mode via Ctrl+X

* test(cli): add undo-after-successful-edit test for external editor

* fix(cli): opts.editor priority, filePath in error log, warn on invalid editor

* fix(cli): address sandbox gap and Windows env-var safety in external editor

- usePreferredEditor now checks allowEditorTypeInSandbox() and returns
  undefined for GUI editors when SANDBOX env is set
- env/default editor fallback rejects commands containing " or | before
  enabling shell mode on Windows

* fix(cli): address wenshao review — unsafe-char guard, debug logs, test coverage

- Add unsafe-character rejection for opts.editor .cmd paths on Windows
- Change env-var unsafe-char handling from throw to graceful return + cleanup
- Add debug logging before spawnSync and in setRawMode catch block
- Add tests for opts.editor path, .cmd shell mode, and unsafe-char rejection

* fix(cli): expand unsafe-char guard, remove stale comment, add tests

- Expand Windows unsafe-character regex to include % and ! (cmd.exe
  variable expansion and delayed expansion)
- Remove stale "no hooks needed" comment in TextInput.tsx
- Add setRawMode lifecycle test (disable before editor, restore after)
- Add default fallback tests for vi (linux) and notepad (win32)

* fix(cli): remove explicit type annotation on mock.calls.findIndex callback

The `[boolean]` tuple annotation conflicts with vitest's `any[][]`
mock.calls type, causing TS2345 in CI.

* fix(cli): replace unlinkSync+rmdirSync with recursive rmSync for temp cleanup

Leftover swap files from vim/neovim would cause rmdirSync to silently
fail on non-empty directories, leaking temp dirs. Use rmSync with
recursive+force to handle this. Also fix stale JSDoc fallback comment.

* test(cli): add % and ! unsafe-char coverage and error-path raw mode test

- Expand opts.editor and env-var unsafe-char tests to cover %, !, and "
  independently via it.each, preventing silent regex regressions
- Add error-path test verifying setRawMode restore when editor exits
  with non-zero status
LaZzyMan added a commit that referenced this pull request May 21, 2026
…s + PR refs

Three cross-cutting capabilities on top of the Phase A-C worktree
foundation (PRs #4073, #4174).

D-1: --worktree [name] CLI flag creates a worktree (or re-attaches to
one that already exists) before any model turn runs. Supports bare,
plain-slug, `=`, and PR-reference forms; --worktree + --acp rejected
with a clear error; --worktree + --resume overrides the resumed
session's saved sidecar and emits a stderr line.

D-2: worktree.symlinkDirectories: string[] settings key opts into
symlinking main-repo directories (e.g. node_modules) into every
newly-created general-purpose worktree. Applies to all three creation
paths: --worktree flag, EnterWorktreeTool, AgentTool isolation. Path
traversal, absolute paths, and existing destinations all guarded;
missing source dirs and EEXIST silently skipped (fail-open).

D-3: --worktree=#<N> / --worktree <github-url> resolves a PR number,
runs `git fetch origin pull/<N>/head` (30s timeout, no `gh` CLI
dependency, LANG=C for stable error-taxonomy matching), and creates
the worktree off FETCH_HEAD. URL regex tolerates /files, /commits,
/checks sub-paths so users can paste any GitHub PR URL.

Phase 6 verification fixes also included:
- Re-attach to an existing worktree instead of failing with "Worktree
  already exists" — the common `qwen --resume <sid> --worktree foo`
  workflow now succeeds. The session ownership marker is preserved on
  re-attach so cross-session exit_worktree action="remove" still fails
  for non-owners.
- Normalize path-taking argv fields (mcpConfig, jsonSchema @<path>,
  openaiLoggingDir, jsonFile, inputFile, telemetryOutfile,
  includeDirectories) to absolute paths against the launch cwd BEFORE
  the worktree chdir. Otherwise downstream fs.existsSync('./mcp.json')
  resolves into the worktree, where the file doesn't exist.

Phase 7 code-review fixes:
- buildStartupWorktreeNotice differentiates "Active worktree" (fresh
  create) from "Re-attached to worktree" (re-attach path).
- Notice survives sidecar persist failure: set before the try block,
  refreshed inside with override addendum if persist succeeded.
- getRegisteredWorktreeBranch verifies the candidate path's git
  common-dir matches the source repo's — rejects sibling `git init`
  directories that happen to be on a worktree-<slug> branch.

Three-mode parity for the startup notice: TUI consumes via
AppContainer effect, headless prepends a <system-reminder> + emits a
worktree_started JSON event. ACP path is mutually exclusive with
--worktree (ACP hosts supply per-session cwd separately).

Tests (66 + 15 new):
- 15 cli/src/startup/worktreeStartup.test.ts (slug forms, PR fetch
  against local fake remote, re-attach happy + wrong-branch guard)
- 8 core/src/services/gitWorktreeService.test.ts (parsePRReference:
  #N, URLs, malformed, traversal, leading zeros, non-string)
- 10 core/src/services/gitWorktreeService.symlinks.integ.test.ts
  (symlink loop + fetchPullRequestRef error taxonomy)

Known limitations (documented in docs/users/features/worktree.md):
- Cross-slug --resume <sid> --worktree <different-new-slug> is
  unsupported by design (sessions are bound to projectHash(cwd));
  future Config refactor anchoring storage at repo root would lift this.
- Mid-session enter_worktree still does NOT switch cwd/targetDir
  (Phase A's simplification); only the startup --worktree flag does.
- yargs ambiguity: `qwen --worktree "say hi"` consumes the prompt as
  the slug. Quick Start shows the `=` form and reordering workarounds.

Docs:
- docs/users/features/worktree.md (new): Quick Start with --worktree
  flag, CLI Reference table for all four input forms + error codes,
  settings table, Limitations.
- docs/design/worktree.md: Phase D section expanded into D-1/D-2/D-3
  with open questions resolved; capability table updated.
- docs/e2e-tests/worktree-phase-d.md (new): full E2E plan with Phase 4
  dry-run baseline + Phase 6 post-impl reproduction tables.

Refs #4056
wenshao added a commit that referenced this pull request May 24, 2026
…4469)

* fix(core): decouple auto-memory recall from main-agent request path (#4172)

* docs: add async memory recall design spec and implementation plan

* refactor(core): introduce MemoryPrefetchHandle, replace pendingRecallAbortController field

* refactor(core): fire memory recall as non-blocking prefetch with settledAt flag

* refactor(core): replace blocking await with zero-wait settledAt poll at UserQuery consume point

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(core): inject recalled memory on first ToolResult when UserQuery consume point misses

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor(core): replace pendingRecallAbortController with pendingMemoryPrefetch in all cleanup paths

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor(memory): remove 1s AbortSignal.timeout from relevanceSelector — caller controls lifetime

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(core): update auto-memory tests for async prefetch pattern — drop fake timers and deadline references

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(core): add ToolResult inject test — memory injected on first ToolResult when recall settles after UserQuery

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(core): address codex review findings on async memory recall

Three findings fixed:

1. Abort previous prefetch before installing a new one (line 1059):
   A new UserQuery/Cron used to overwrite pendingMemoryPrefetch without
   aborting the old controller, leaking an unbounded background recall now
   that the 1s side-query timeout is gone.

2. Move the UserQuery consume poll AFTER the async reminder setup:
   ensureTool + listSubagents are awaited between the old poll location and
   the final assembly, so recalls that settled during those awaits used to
   be missed (and a tool-less turn never got a ToolResult retry). The poll
   now runs immediately before requestToSend assembly, and unshifts memory
   to the front of systemReminders to preserve ordering.

3. Append memory after functionResponse on ToolResult turns:
   The Qwen API requires the functionResponse part to immediately follow
   the model's functionCall (see lines 1209-1213). Prepending memory text
   risked breaking that pairing on the native Gemini path. Appending keeps
   the pair intact on Gemini and produces the same OpenAI output (text
   becomes a separate user message after the tool messages).

Tests:
- Updated ToolResult inject test to assert memory index > functionResponse
- Added abort-previous-prefetch test (mid-flight UserQuery aborts old handle)

224/224 tests pass; tsc clean on changed files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs(core): add JSDoc + clarifying comments per review feedback

Annotations only, no behavior change:
- MemoryPrefetchHandle: full JSDoc covering lifecycle (create → consume → discard)
- UserQuery consume site: explain why we unshift (front of systemReminders)
- ToolResult inject site: reference hasPendingToolCall pattern instead of
  brittle line numbers when citing the Qwen functionCall/Response constraint
- relevanceSelector.ts: explain why the side-query has no inline timeout
  (caller controls lifetime via MemoryPrefetchHandle.controller)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(core): bridge caller abort signal into memory prefetch + doc accuracy fixes

Behavior fix (addresses copilot review on client.ts:1071):
- When the parent sendMessageStream signal aborts (user Ctrl-C / Esc),
  the prefetch controller now aborts too. Previously the recall side-query
  would keep running until a later cleanup (next UserQuery / /clear / etc),
  wasting fast-model tokens on work whose result no one would consume.
- Listener uses { once: true } and is also removed in the promise's
  finally() so a long-lived parent signal doesn't accumulate listeners
  across many turns under normal completion.
- Edge case: if signal is already aborted when fire runs, abort the
  controller synchronously instead of attaching a listener.

Test:
- New regression guard: "should abort the pending prefetch when the caller
  signal aborts" — verifies the abort handler installed on the recall side
  fires once the parent signal aborts.

Doc accuracy (addresses copilot review on the design spec):
- ToolResult inject: was documented as "prepend", actual implementation
  appends to preserve functionCall/functionResponse pairing. Updated both
  the prose summary and the code sample.
- Cleanup section: was documented as 6 abort-locations including the
  "post-consume clear"; the consume sites don't actually abort (the promise
  has already settled). Reorganized as 5 abort-and-clear sites + 2
  clear-only sites with the distinction made explicit.
- Fire path snippet: added the abort-previous-prefetch line and the
  caller-signal bridge so the spec matches the current implementation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor(core): consolidate memory-prefetch lifecycle + safety nets per round-3 review

Architectural (root-cause fix for cleanup-path sibling drift):
- New private cancelPendingMemoryPrefetch() consolidates the abort+clear
  idiom (was duplicated across 6 sites). Logs at debug when discarding a
  settled-but-unconsumed handle so missing-memory scenarios are diagnosable.
- New private tryConsumeMemoryPrefetch() consolidates the
  consume-and-mark-consumed dance (was duplicated UserQuery + ToolResult).
- All existing cleanup sites + the two newly-flagged early-return sites
  (LoopDetected, Error) now use the helper; future early-returns can rely
  on the finally-block safety net.
- sendMessageStream try-finally now uses a `normalCompletion` flag:
  only the bottom-of-try return path preserves the prefetch (intentional
  — next ToolResult turn may consume it); every other exit (uncaught
  exception, abnormal early-return) goes through cancelPendingMemoryPrefetch
  in finally.

Diagnostics:
- Restored AbortError debug log in fire-path catch (was silent after
  removing the deadline mechanism; aborts now come from 4+ sources so a
  trace is valuable).
- Updated stale "deadline" log in recall.ts to reflect current abort
  sources (caller signal / new UserQuery / cleanup / 30 s safety timeout).

Safety net:
- Added 30 s ceiling in relevanceSelector via AbortSignal.any(...).
  Generous enough that normal ~1 s recalls don't trip it; bounds zombie
  side-queries if the model API hangs and the caller never aborts.
  Replaces the uncancellable `new AbortController().signal` fallback that
  would have left callerless invocations running indefinitely.

Doc sync:
- Design doc updated: UserQuery consume code sample now shows `unshift`
  (matches implementation) with an inline note on the prepend-vs-append
  contrast.

Tests:
- New regression guard: resetChat aborts pending prefetch and clears the
  handle.
- New regression guard: LoopDetected mid-stream aborts pending prefetch
  and clears the handle (catches the sibling-drift bug this round caught).

227/227 tests pass; tsc clean on changed files.

Declined from this round:
- `await Promise.resolve()` after fire path: defensive — current code has
  multiple natural microtask drains before consume point. Added comment
  documenting the dependency instead.
- Renaming `settledAt: number | null` to `settled: boolean`: timestamp
  has diagnostic value for future instrumentation; current consumers'
  null-check usage is documented in the JSDoc.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(test): correct getLastLoopType mock return type — null, not undefined

CI tsc --build (stricter than --noEmit) caught:
  src/core/client.test.ts(2996,65): error TS2345: Argument of type
  'undefined' is not assignable to parameter of type 'LoopType | null'.

getLastLoopType()'s contract returns LoopType | null; the test mock was
returning undefined. Switched to null to match the type.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(core): preserve memory prefetch across hook/next-speaker continuations + accurate recall abort log

Round-4 review findings (self-inflicted regression from round-3):

1. Preserve pending prefetch on `return hookTurn` (Stop-hook continuation)
   and `return continueTurn` (next-speaker continuation). The round-3
   `normalCompletion = true` was only set at the bottom-of-try `return turn`,
   leaving these two recursive-yield paths to trip the finally cleanup.
   When the inner Hook turn produced tool calls, the subsequent ToolResult
   turn found `pendingMemoryPrefetch === undefined` and memory was silently
   dropped.

2. recall.ts catch log distinguishes caller-driven aborts (heuristic
   genuinely skipped below) from the 30s safety-net timeout in
   relevanceSelector (the caller's signal is NOT aborted by that path,
   so the heuristic fallback actually runs).

Regression guard added:
- "should PRESERVE the pending prefetch when next-speaker continueTurn
  returns" — was red before this commit, green after.

258/258 tests pass; tsc --build clean.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(worktree): Phase C — session persistence, hooksPath, Footer + WorktreeExitDialog, three-mode --resume restore (#4174)

* docs(worktree): update design doc — split Phase C/D, add Future section

- Phase C: session persistence + hooksPath + StatusLine + WorktreeExitDialog
- Phase D: --worktree CLI flag + symlinkDirectories
- Future: sparse checkout, .worktreeinclude, tmux, PR reference parsing
- Feature comparison table updated with Phase A/B completion status

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs(worktree): add Phase C implementation plan

8 tasks: WorktreeSession sidecar storage, hooksPath setup,
EnterWorktree/ExitWorktree session wiring, useWorktreeSession hook,
Footer display, --resume context injection, WorktreeExitDialog.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs(worktree): update Phase C plan after claude-code comparison

- WorktreeSession: add originalHeadCommit field
- hooksPath: add .husky/ detection + skip-if-already-set logic
- StatusLine payload: expand worktree field to match claude-code schema
- WorktreeExitDialog: load dirty state on mount, display counts in dialog
- UIState.activeWorktree: add originalCwd, originalBranch, originalHeadCommit

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(worktree): add WorktreeSession sidecar storage

New worktreeSessionService.ts exposes read/write/clear functions for the
sidecar JSON file at <chatsDir>/<sessionId>.worktree.json. SessionService
gains getWorktreeSessionPath() so callers don't need to know the layout.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* feat(worktree): configure core.hooksPath after worktree creation

createUserWorktree() now sets `core.hooksPath` inside the new worktree to
the main repo's hooks directory (.husky preferred, .git/hooks fallback) so
commits inside the worktree run the same pre-commit checks as the main
repo. Mirrors claude-code's performPostCreationSetup logic — skips the
subprocess when the value already matches to avoid ~14ms spawn overhead.

Failures are non-fatal: the worktree is still usable without hooks.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* feat(worktree): persist WorktreeSession sidecar in EnterWorktreeTool

After creating a worktree, EnterWorktreeTool now writes a sidecar JSON
file at <chatsDir>/<sessionId>.worktree.json with the full session state
(slug, paths, branches, original HEAD SHA). --resume reads this in Phase
C task 7 to restore worktree context. Best-effort: write failures don't
abort the creation.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* feat(worktree): clear WorktreeSession sidecar in ExitWorktreeTool

After successful keep or remove, ExitWorktreeTool now clears the sidecar
JSON file iff its slug matches the worktree being exited. The slug check
prevents wiping the sidecar when the user exits a worktree that isn't
currently tracked (multiple worktrees on disk, sidecar tracks one).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* feat(worktree): expose active worktree via useWorktreeSession + UIState

New useWorktreeSession hook watches the sidecar JSON file (created by
EnterWorktreeTool, deleted by ExitWorktreeTool) and returns the current
WorktreeSession or null. AppContainer wires it into a new
UIState.activeWorktree field consumed by Footer (Task 6) and
WorktreeExitDialog (Task 8).

A showWorktreeExitDialog state placeholder is added too, hardcoded false
until Task 8 wires the dialog trigger.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* feat(worktree): show active worktree in Footer + StatusLine payload

Footer renders `⎇ <branch> (<slug>)` when activeWorktree != null, but
only when the user has no custom statusline (their script likely
handles it from the stdin payload itself).

useStatusLine's StatusLineCommandInput gains a `worktree` field with
{name, path, branch, original_cwd, original_branch} — matches claude-code's
schema so statusline scripts can be shared across both CLIs.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* feat(worktree): inject context hint on --resume when worktree is active

On --resume, if the session has a WorktreeSession sidecar, append an
INFO history item pointing the model at the worktree path so it
continues using it for file operations. Stale sidecars (worktree dir
deleted out-of-band) are cleaned up so the Footer indicator doesn't
go stale.

qwen-code can't process.chdir() the way claude-code does because
Config.targetDir is immutable; the context hint is the equivalent
behavioral cue.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* feat(worktree): add WorktreeExitDialog with dirty-state inspection

WorktreeExitDialog renders when the user double-presses Ctrl+C inside a
worktree. On mount it runs `git status --porcelain` and
`git rev-list --count <originalHeadCommit>..HEAD` to show how many
uncommitted files and new commits the user would discard by choosing
"Remove". The dialog never auto-removes — every exit goes through
explicit user confirmation per requirements.

handleExit in AppContainer intercepts the second-press quit when
activeWorktree is set and shows the dialog instead. A new UIAction
handleWorktreeExit(choice) routes the user's choice through removal
(via GitWorktreeService.removeUserWorktree) + sidecar cleanup + /quit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* docs(worktree): add Phase C E2E test plan

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* docs(worktree): fix E2E test plan sidecar path + jq selector

- sidecar lives at ~/.qwen/projects/<sanitized-cwd>/chats/, not ~/.qwen/tmp/<hash>/
- qwen --output-format json emits a JSON array, not NDJSON — jq needs .[]

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(worktree): add showWorktreeExitDialog to dialogsVisible

Phase C task 8 introduced showWorktreeExitDialog state and the dialog
render in DialogManager, but missed adding the flag to the dialogsVisible
OR expression. DefaultAppLayout only renders DialogManager when
dialogsVisible is true, so the dialog was never shown — second Ctrl+C
in a worktree silently absorbed instead of triggering the prompt.

Caught by Group E E2E tests.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* feat(worktree): extend --resume context restore to headless + ACP modes

Phase C task 7 originally placed the worktree-restore logic in
AppContainer.tsx (TUI only). E2E Group C exposed that headless and ACP
modes never run AppContainer, so stale sidecars accumulate and the model
loses worktree context after --resume.

Refactor to a shared `restoreWorktreeContext` helper in core, then wire
the three entry points:

- TUI (AppContainer): keep historyManager.addItem(INFO) UX, route via
  the helper.
- Headless (nonInteractiveCli): prepend the notice as a system-reminder
  block on the user prompt; emit a `worktree_restored` system message to
  the JSON adapter so SDK consumers can react.
- ACP (Session.pendingWorktreeNotice): set by acpAgent.loadSession on
  resume, consumed and cleared exactly once on the next #executePrompt.

All three modes call the same helper, so stale-sidecar cleanup is
consistent. Helper covers: missing sidecar, live worktree dir,
deleted worktree dir, regular file at worktreePath, malformed JSON.

5 new unit tests for restoreWorktreeContext (13/13 pass total).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* test(worktree): add ACP-mode integration tests for --resume context

Covers:
- acpAgent.worktree.test.ts (3 tests): loadSession sets
  pendingWorktreeNotice only when worktree dir is live, clears
  stale sidecar otherwise, swallows restoreWorktreeContext errors.
- Session.worktree.test.ts (4 tests): #executePrompt prepends the
  system-reminder block exactly once on first prompt, clears the
  pending notice, second prompt sees no leakage, no-op when nothing
  was set.

E2E via real ACP protocol is impractical without a Zed client; these
tests cover the integration boundaries directly.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* docs(worktree): clarify hooksPath comment + pendingWorktreeNotice one-shot rationale

Two doc-only fixes from PR #4174 review:

- gitWorktreeService.ts: previous hooksPath comment overstated the
  optimization (claimed claude-code's ~14ms saving but we still do a
  read subprocess). Rewrite to be explicit: write-skip only, read
  retained, parseGitConfigValue's full optimization deliberately not
  ported because the read happens once per worktree creation.

- Session.ts: pendingWorktreeNotice doc now explains why it's one-shot
  (after the first prompt the worktree path is already in conversation
  context; re-injecting would clutter history without adding signal).

No behavior change.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(test): add getResumedSessionData to nonInteractiveCli mock Config

CI surfaced TypeError: config.getResumedSessionData is not a function
across 12 tests in nonInteractiveCli.test.ts. The Phase C ada0837e2
commit added a worktree-restore call in the headless path that probes
config.getResumedSessionData(); the mock Config never had that method.

Return undefined to short-circuit the restore block — these tests
don't exercise --resume.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(worktree): address PR #4174 reviewer findings

Bundled response to the two review rounds. Per-thread replies follow.

CORE — worktree sidecar robustness (Findings 3252368644, 3252368651, 3255171690):
- atomicWriteJSON instead of fs.writeFile (no more half-written sidecar after a crash)
- readWorktreeSession now schema-validates the parsed object and returns null
  on missing/wrong-type fields instead of propagating undefined into consumers
- restoreWorktreeContext clears the sidecar on JSON parse failure / read I/O
  error so a corrupted file doesn't block every subsequent --resume

CORE — hooksPath setup (Finding 3252368645):
- configureHooksPath distinguishes ENOENT (benign "candidate not present")
  from real stat errors (EACCES/EIO/ENOTDIR); the latter are warn-logged
  so a silently-degraded hooksPath is visible to operators

CLI — handleWorktreeExit Remove path (Findings 3252368637, 3252368640 a+b):
- Anchor GitWorktreeService at activeWorktree.originalCwd (the captured
  repo root), not config.getTargetDir() — fixes monorepo-subdirectory
  launches where the worktree lives under the repo root but getTargetDir
  points at a subpackage
- Check removeUserWorktree return value; on failure, leave the sidecar
  intact so --resume can recover (previous code cleared it regardless)
- Pass forceDeleteBranch:true to honour the dialog's "discards N commits"
  label — without it `git branch -d` refused unmerged commits and the
  branch was silently preserved

CLI — useWorktreeSession watcher (Finding 3252368648):
- Normalize fs.watch filename via toString() so the Linux-Buffer code
  path triggers reloads (previous comparison silently never matched)
- Treat null filename as "unknown, reload to be safe" (recursive watchers
  on some platforms emit events without a payload)

CLI — WorktreeExitDialog (Findings 3252368650, 3255171694):
- execGit now correctly reads numeric exit codes from .code/.status
  (NodeJS.ErrnoException.code is a string for spawn errors, number for
  subprocess exits); previous typeof === 'number' check always missed
- Dialog body shows an "⚠ Could not measure worktree state (...)" banner
  when git status / rev-list failed, so the user doesn't see a misleading
  "0 files, 0 commits" before choosing Remove

CLI — closeAnyOpenDialog (Round 2 review body):
- Wire WorktreeExitDialog into the standard dialog-dismissal path so
  Ctrl+C dismisses it the same way it dismisses every other dialog

TEST FIXES — vitest timeouts:
- Real git invocations + user-global hooks (e.g. trustup post-commit
  webhooks) can take 10–20s per setUp on CI. Bump testTimeout +
  hookTimeout to 30s for the three integ test suites that spawn git
  (Phase B/C worktree integ tests) so the suite isn't flaky.

NEW TESTS:
- worktreeSessionService.test: 3 new cases covering malformed JSON,
  missing required fields, wrong-type fields, malformed sidecar cleanup,
  partial sidecar cleanup (16 total, up from 13).
- useWorktreeSession.test.tsx: 4 new cases — null when no sidecar,
  parsed sidecar at mount, reacts to delete, reacts to creation.
- WorktreeExitDialog.test.tsx: 1 new case — loading frame renders before
  git probes resolve. (Async dialog states tested via E2E — vi.mock of
  execFile in ink-testing-library doesn't fire mock impl reliably.)
- nonInteractiveCli.test: 3 new "Phase C --resume" cases — system-reminder
  injection on live worktree, no injection when sidecar absent, stale
  sidecar cleanup when worktree dir is gone.

DECLINED FINDINGS (replied on threads):
- 3252368642 (Dialog Keep clears sidecar) — declined-design. Dialog
  Keep = "exit app, keep worktree for next --resume"; tool Keep =
  "I'm done with this worktree". Intentionally different semantics.
- 3252368643 (originalHeadCommit base branch) — false-positive. There
  is no base_branch parameter; getCurrentCommitHash() returns HEAD which
  equals the tip of the current branch (== baseBranch in createUserWorktree).
- 3252368640 part c (bypass safety guards) — declined-design. The
  dialog IS the safety affordance for this path — it shows dirty-state
  counts and asks for explicit user confirmation before removal.
- 3255171696 (DialogManager async fire-and-forget) — false-positive.
  handleSlashCommand('/quit') is inside the await chain in
  handleWorktreeExit, so the described race ("process.exit before remove
  completes") cannot occur.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(test): correct linter-mangled imports in useWorktreeSession.test

Pre-commit hook auto-fixed imports collapsed value imports
(writeWorktreeSession, clearWorktreeSession) into an `import type`
block, breaking runtime resolution. Split back into value + type imports.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(test): normalize path separators for Windows in worktree session integ

Windows CI failure: `repoRoot` from Node's `fs.mkdtemp` returns
backslash-separated paths (`C:\Users\runneradmin\…`), but
`originalCwd` in the sidecar comes from `getRepoTopLevel()` which
delegates to `git rev-parse --show-toplevel` — git on Windows
returns forward slashes (`C:/Users/runneradmin/…`).

The Windows-only assertion `expect(originalCwd).toBe(repoRoot)` was
comparing two different representations of the same canonical path
and rightly failed on `Object.is` equality. Compare via path.normalize
on both sides so the assertion holds across platforms without
changing the runtime path (originalCwd still records git's output
verbatim, which is what consumers expect since other places in the
codebase that read `getRepoTopLevel()` also work with that shape).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(worktree): address PR #4174 round 4 findings

Finding #3256237933 (Critical, follow-up to #3252368640 part 1):
handleWorktreeExit silently /quit'd when removeUserWorktree returned
{success:false}, contradicting the user's intent after they clicked
"Remove worktree and branch (discards N commits, M files)". Now
surfaces an ERROR history item with the underlying error message
and STAYS in the session so the user can decide what to do
(retry via exit_worktree, fix the lock/permission/corruption issue,
or quit anyway). Same treatment applied to the hard-failure catch
block — previously it caught the throw and proceeded to /quit with
no log; now it emits the error and stays alive.

Finding #3256236050 (Nit): originalCwd field name implies "user's
launch cwd" but actually stores `getRepoTopLevel()` (different in
monorepo subdir launches — the gap closed by #3252368637). Renaming
the field would force on-disk migration of every existing sidecar
(every active --resume breaks until users wipe the old file).
Doc-only fix: WorktreeSession.originalCwd now carries an explicit
JSDoc explaining the semantics and warning consumers expecting
process.cwd() to NOT use this field.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(worktree): address PR #4174 round 5 findings

Finding #3256241831 (Nit, but awareness UX): the built-in `⎇`
indicator used to disappear whenever `statusLineLines.length > 0`,
on the assumption that the user's custom statusline rendered worktree
itself. That assumption is unsafe — scripts written before Phase C
don't know about `payload.worktree`, scripts can deliberately ignore
the field, and partial scripts may render some fields but not
worktree. In any of those cases the user sees no worktree UI while
having an active worktree, risking destructive operations in the
wrong cwd. New behavior: indicator shows by default regardless of
statusline. Added an opt-out setting `ui.hideBuiltinWorktreeIndicator`
(default false) for users whose custom statusline already renders
worktree and want to avoid duplication.

Finding #3256239608 (Nit): `fs.watch` in useWorktreeSession holds
an inode handle to `chatsDir` at mount time. If the directory is
deleted out-of-band (manual cleanup, antivirus quarantine, reset
scripts) and recreated, the watcher does NOT re-attach to the new
inode and the Footer indicator stops reacting to sidecar changes.
Reviewer explicitly accepted this as a documented limitation rather
than adding polling-fallback or error-event-handler complexity for
an edge case that doesn't arise in normal use. Added a JSDoc block
on the hook explaining the limitation and pointing to the future
fix shapes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* chore(worktree): regenerate settings.schema.json for hideBuiltinWorktreeIndicator

CI Lint step caught that the JSON schema mirror in
packages/vscode-ide-companion was out of date after adding the new
ui.hideBuiltinWorktreeIndicator setting in 80f9cb495. Regenerated
via `npm run generate:settings-schema`.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(worktree): address PR #4174 round 6 findings

Critical fixes:
- #3259975247: TUI dialog Remove now reads the in-worktree session
  marker and refuses to delete a worktree owned by a different
  session — same ownership guard ExitWorktreeTool already applies.
  Stale/copied sidecars can no longer destroy another session's work.
- #3259975249: TUI --resume queues a one-shot pendingWorktreeNotice
  ref consumed by handleFinalSubmit; the user's first prompt is
  prefixed with the same <system-reminder> block headless/ACP use.
  Previously only the INFO history item showed in the transcript
  (UI-only), so resumed models could silently edit the parent
  checkout.
- #3259975245: exit_worktree action='keep' no longer clears the
  sidecar. `keep` means "preserve the worktree for later"; clearing
  the persisted binding broke --resume / Footer / WorktreeExitDialog
  for kept worktrees. Now matches the Dialog keep semantics. Test
  updated to assert preservation instead of clearing.
- ACP unstable_resumeSession parity: factored the worktree restore
  block into #restoreWorktreeOnResume() and called from both
  loadSession() and unstable_resumeSession(). ACP clients using
  resume no longer miss the worktree context.

Suggestion-level fixes:
- #3259975237: configureHooksPath now resolves the canonical hooks
  dir via `git rev-parse --git-common-dir` instead of constructing
  `<sourceRepoPath>/.git/hooks`. The construction assumed .git is a
  directory, but when Qwen runs from a linked worktree it's a file
  pointing at the real gitdir → ENOTDIR → silent no-hooks worktree.
- #3259975242: only writes core.hooksPath when the key is unset.
  A non-empty inherited or user-configured value is preserved
  instead of being silently replaced.
- #3256839787: restoreWorktreeContext adds a structural invariant
  check — worktreePath must live under <originalCwd>/.qwen/worktrees/.
  A tampered/copied sidecar pointing at an arbitrary existing dir
  is rejected and cleared so the model can't be redirected.

Tests:
- worktreeSessionService.test: 17/17 (added prefix-escape rejection
  case + restructured the existing live-worktree case to satisfy
  the new structural invariant).
- exit-worktree.session.integ.test: rewrote keep test to assert
  preservation (matches new behavior).
- nonInteractiveCli.test: updated fixture worktreeDir to live
  under <originalCwd>/.qwen/worktrees/ for the prefix invariant.
- All other suites pass without modification.

Test coverage gap acknowledgement (no comment_id reply): per-handler
unit tests for handleWorktreeExit + dialog post-load states remain
covered by the E2E Group E suite in docs/e2e-tests/worktree-phase-c.md.
The execFile mock path in ink-testing-library still doesn't deliver
async useEffect state transitions reliably, so unit testing those
states adds more harness than signal; deferring.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(core): apply defaultModalities() on env-var-only model config (#4219) (#4262)

* fix(core): apply defaultModalities() on env-var-only model config (#4219)

When qwen-code is configured only via env vars (OPENAI_API_KEY /
OPENAI_BASE_URL / OPENAI_MODEL) with no modelProviders entry,
resolveGenerationConfig() never invoked defaultModalities(), so
generationConfig.modalities stayed undefined for image-capable
models. The two other config paths (modelRegistry.resolveModelConfig
and modelsConfig.applyResolvedModelDefaults) already call it. This
aligns the env-var-only path with both so multimodal models like
qwen3.6-35b-a3b correctly accept @image attachments.

Fixes #4219

* test(core): lock modalities fallback invariants on env-var-only path

Address review feedback on PR #4262:
- Strengthen the positive regression test to also assert video:true and
  source kind ('computed'), matching the source-tracking convention used
  elsewhere in this file and catching regex regressions in modalityDefaults.
- Add negative case: unknown model → modalities resolves to {} (text-only),
  never undefined — the key invariant introduced by the fix.
- Add negative case: explicit settings.generationConfig.modalities is not
  clobbered by the fallback (lock the `=== undefined` guard).
- Extend the fallback's comment to document the undefined → {} semantic so
  future maintainers don't reintroduce `modalities === undefined` branches.

No behavior change.

* test(core): pin Qwen OAuth modalities auto-detect for coder-model

Round-2 review feedback on #4262: `resolveGenerationConfig` is shared
by both the OpenAI/env-var-only path and `resolveQwenOAuthConfig`,
which passes `resolvedModel` (defaults to 'coder-model') as modelId.
So the new modalities fallback also activates for Qwen OAuth — a real
behavior change (was undefined, now { image: true, video: true }).
The change is desired (coder-model supports vision per the existing
warning text in resolveQwenOAuthConfig), but no test pinned it down.
Add a regression test so future MODALITY_PATTERNS edits can't silently
shift Qwen OAuth behavior.

* fix(cli): block Windows Tab approval-mode toggle when input has a Tab consumer (#4308)

* fix(cli): block Windows Tab approval-mode toggle when input has a Tab consumer

Closes #4171.

On Windows, Shift+Tab is indistinguishable from a bare Tab in many
terminals, so useAutoAcceptIndicator accepts a bare Tab as the
approval-mode cycle shortcut. To avoid double-firing with the input
area, AppContainer passes a `shouldBlockTab` callback that suppresses
the cycle when the input has its own Tab handler.

Until now that callback only tracked the autocomplete dropdown
(`shouldShowSuggestions`). When the buffer was empty and the followup
prompt-suggestion ("input prediction") was visible, pressing Tab on
Windows accepted the suggestion *and* cycled approval mode at the
same time — the exact behaviour reported in #4171. The mid-input
ghost-text and reverse/command-search paths had the same gap.

Broaden the signal: compute `hasTabConsumer` from every Tab consumer
inside InputPrompt — autocomplete dropdown, followup suggestion,
mid-input ghost text, reverse-search, command-search — and feed that
into `shouldBlockTab`. A single Tab keystroke now triggers exactly
one action on Windows; macOS and Linux behaviour is unchanged.

Tests cover the four states (followup visible, ghost text visible,
autocomplete visible, idle).

* fix(cli): tighten hasTabConsumer, add unmount cleanup + tests (#4308 review)

Three review findings on PR #4308 addressed together — all touch the
same `hasTabConsumer` signal surface exposed from InputPrompt to
AppContainer.

1. **Tighten signal semantics (Copilot)**: drop the standalone
   `reverseSearchActive || commandSearchActive` terms. When those
   overlays have matches, their `showSuggestions` flag already flows
   into `shouldShowSuggestions` and Tab is consumed via
   `ACCEPT_SUGGESTION_REVERSE_SEARCH`. When they're active without
   matches, Tab is NOT consumed — including the bare flags
   misrepresented the signal as "Tab consumer present" when it really
   meant "modal overlay open". `hasTabConsumer` now strictly matches
   its name.

2. **useEffect cleanup on unmount (wenshao)**: previously, if any Tab
   consumer was active when InputPrompt unmounted (e.g. streaming
   begins while autocomplete is open), AppContainer's `hasTabConsumer`
   state retained the stale `true` value and kept blocking Windows
   Tab approval-mode cycling for the entire unmount window. Effect
   now resets to `false` on cleanup. The pre-existing code had the
   same gap with one trigger; expanding to 3 triggers materially
   raised the likelihood.

3. **JSDoc on prop name (wenshao)**: `onSuggestionsVisibilityChange`
   now carries broader "Tab consumer" semantics than the name
   suggests. Cross-file rename across UIActionsContext + Composer +
   AppContainer is too much churn for #4308's scope; add JSDoc on the
   prop declaration documenting the broader signal and that the name
   is retained for backward compatibility.

4. **Test coverage (wenshao)**: add two tests — autocomplete dismissal
   reports `false` (true→false transition); unmount-while-active
   reports `false` (cleanup regression guard).

* fix(cli): split Tab-consumer signal so it doesn't hide Footer (#4308 review)

Self-inflicted regression caught by wenshao: the previous round
broadened `onSuggestionsVisibilityChange` from "autocomplete dropdown
visible" to "any Tab consumer present", but Composer.tsx was using
that same callback for a different purpose — hiding the Footer /
KeyboardShortcuts when the dropdown would overlap their vertical
space. As a result, followup prompt suggestions and mid-input ghost
text (both inline within the input box, neither competing for
vertical space) were also hiding the Footer on every platform.

Split into two signals:

- `onSuggestionsVisibilityChange` — narrow, autocomplete dropdown
  only. Kept local to Composer for Footer hiding. Restored to
  pre-PR semantics; no cleanup-on-unmount needed (the entire
  conditional in Composer.tsx is already gated by
  `uiState.isInputActive`, which goes false when InputPrompt
  unmounts).

- `onTabConsumerChange` — broad, any input-side Tab consumer
  (autocomplete + followup + ghost text). Plumbed through
  UIActionsContext to AppContainer's `hasTabConsumer` state →
  useAutoAcceptIndicator's `shouldBlockTab`. Retains the
  cleanup-on-unmount wenshao added last round (the broad signal
  IS read while InputPrompt is unmounted).

Tests:
- All 6 broad-signal regression tests renamed to assert
  `onTabConsumerChange`.
- 3 new narrow-signal regression tests pin that
  `onSuggestionsVisibilityChange` does NOT fire `true` for followup
  or ghost text. Catches the exact shape of my regression.

* fix(core): mirror Qwen3 reasoning on outbound history (#4294)

* feat(core): extend cross-auth fast models to agents (#4153)

* feat(core): extend cross-auth fast models to agents

* fix(core): tighten cross-auth model resolution fallbacks

When a forked-agent caller passes a selector that cannot resolve (e.g.
`fast` with no fast model configured), fall back to the parent session
model instead of forwarding the raw selector string to the provider.
Matches the subagent path, where unresolvable selectors mean "inherit
parent".

In BaseLlmClient.createContentGeneratorForModel, do not cache the
unregistered-model fallback. getCurrentContentGenerator() reads the
runtime view from AsyncLocalStorage, which can differ between calls;
caching would pin the first call's view-bound generator under the
selector key and reuse it on later calls after that view has unwound.

* docs(core): drop stale getFastModelForSideQuery from sideQuery JSDoc

The function was removed when fast-model resolution collapsed onto getFastModel(); the JSDoc fallback chain still mentioned it.

* feat(cli,core): add Auto approval mode with LLM classifier (#4151)

* feat(cli,core): add Auto approval mode with LLM classifier (#auto-mode)

Add a fifth approval mode positioned between Auto-Edit and YOLO that uses
an LLM classifier to evaluate each tool call and auto-approve safe ones
while blocking risky ones — letting agents work autonomously on long
sessions without forcing users to confirm every shell/network call.

Three-layer filter when L4 returns 'ask'/'default':
  L5.1 acceptEdits fast-path: Edit/Write inside workspace -> allow
  L5.2 safe-tool allowlist:   Read/Grep/LS/TodoWrite/... -> allow
  L5.3 LLM classifier:        two-stage (fast/thinking) via sideQuery

Anti-injection: assistant text and tool results are stripped from the
classifier transcript; each tool projects its args through a new
`toAutoClassifierInput` method to redact sensitive/voluminous fields.

Pending action is rendered as a user-role text turn so it survives the
OpenAI Chat Completions converter (which drops orphan tool_calls).

Safety: fail-closed on classifier failure; denial-tracking caps
3 consecutive blocks / 2 consecutive unavailable before falling back
to manual confirmation; dangerous allow rules (Bash interpreter
wildcards, any Agent/Skill allow) are temporarily stripped while in
AUTO and restored on exit — settings.json is never modified.

Config:
  --approval-mode auto                                 # CLI flag
  tools.approvalMode: "auto"                           # settings.json
  permissions.autoMode.hints.{allow,deny}: string[]    # natural-lang
  permissions.autoMode.environment: string[]

* chore(schema): regenerate settings.schema.json after adding tools.approvalMode 'auto'

The autogenerated VS Code settings schema was out of sync with the
runtime SETTINGS_SCHEMA after the AUTO mode addition; CI's Lint job
caught the drift. No behavior change — this is purely the regenerated
output of `npm run generate:settings-schema`.

* test(cli): update expected error message after adding 'auto' to approval-mode choices

Two tests in `loadCliConfig`'s error-path coverage hard-coded the list of
valid approval modes in the expected error string. Add `auto` to match
the runtime message produced by the new five-mode enum.

* test(core): fix autoMode test fixture on Windows

The fixture's mock isPathWithinWorkspace used path.sep to join the root
prefix, but the hard-coded test paths use forward slashes regardless of
OS. On Windows path.sep is '\\', so prefix matching failed and L5.1
fast-path tests returned false (and the L5.1-gating test then fell into
the classifier branch, hitting an undefined getToolRegistry mock).

Hard-code '/' in the fixture — it controls only intra-file consistency
between mock roots and mock paths, not real workspace behavior.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(cli,core): three asymmetries surfaced by self-review of PR #4151

ACP path (Session.ts) had two asymmetries with the CLI scheduler that
silently degraded AUTO behavior, and the classifier transcript builder
left historical tool_use calls vulnerable to the OpenAI converter's
orphan-tool_call filter on the default Qwen / DashScope backend.

1) ACP runs the classifier even when finalPermission === 'allow'
   The CLI scheduler short-circuits when L4 returned 'allow' (user-
   explicit rule matched) so the classifier never sees the call. The
   ACP duplicate only short-circuits on 'deny'. Mirror the scheduler:
   set autoModeAllowed = (finalPermission === 'allow') before the AUTO
   L5 block. Without this, a user-written `Bash(git push *)` allow rule
   in an ACP session could reach the classifier and be blocked by a
   conservative Stage-1 verdict.

2) ACP never records a successful fallback approval
   When the denialTracking streak forced fallback, ACP correctly dropped
   into requestPermission — but after the user approved, the streak was
   never reset. consecutiveBlock stayed at 3, so every subsequent call
   re-fell into fallback. The session was permanently downgraded to
   manual approval until the mode toggled. Add the post-outcome
   recordFallbackApprove call paralleling coreToolScheduler.ts:1705-
   1717 (approve outcomes only; cancel/abort preserve the streak).

3) Classifier transcript: historical functionCalls become orphans on
   OpenAI-compatible backends
   buildClassifierContents kept model.functionCall parts but stripped
   tool results entirely (anti-injection). On Anthropic-native APIs
   that's fine, but the OpenAI Chat Completions converter
   (converter.ts:1422-1455) filters out tool_calls without a matching
   tool response, and since the assistant message has no text content
   either, the entire turn gets dropped. The classifier on Qwen /
   DashScope ended up seeing only user prompts plus the pending action —
   zero record of prior tool actions in the chain.

   Match ClaudeCode's `buildTranscriptEntries` (yoloClassifier.ts):
   render every historical model.functionCall as a user-role text turn
   ("Prior action: tool(args)") projected through toAutoClassifierInput.
   The result contains only user-role text — no functionCall parts,
   no assistant tool_calls — so it is converter-agnostic by
   construction. Tests updated to assert the new shape and added a
   regression guard verifying no functionCall part survives anywhere
   in the output.

ACP fixes have no new unit tests: their logic is mechanically symmetric
with the CLI scheduler branch, the underlying recordFallbackApprove
state machine is covered by denialTracking.test.ts, and adding ACP
integration tests for these two-to-four-line branches would dwarf the
fix itself. The fix correctness is verifiable from the diff against
the existing scheduler comparison.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(core): recordFallbackApprove resets BOTH consecutive counters

Asymmetry caught by copilot[bot] on PR #4151: the original
implementation only cleared consecutiveBlock when the user approved
a fallback prompt, leaving consecutiveUnavailable at its threshold.
A transient classifier API blip (2 consecutive unavailable verdicts)
therefore permanently downgraded the rest of the session to manual
approval — even after the user explicitly approved the prompt —
because every subsequent shouldFallback() call kept seeing the
{reason: 'consecutive_unavailable'} branch.

The fix mirrors recordAllow: a manual approval signals the user
accepted the action and the next call should re-engage the
classifier. If the API is still degraded, the next call simply re-
arms the counter (one unavailable / one block), same recovery curve
as initial onset. No permanent lock-out, and the documented "Counter
resets on user approve or mode switch" behavior from the PR body
now actually holds for both reasons.

Existing test 'does not reset consecutiveUnavailable' was codifying
the bug — replaced with three positive cases (unavailable recovery,
total-counter preservation as telemetry, and the no-op guard).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(cli,core): address PR #4151 review findings (defense-in-depth + sibling-drift)

20 findings from reviewers wenshao (gpt-5.5 / deepseek-v4-pro / mimo-v2.5-pro)
on PR #4151. Triaged through the five-filter framework, accepted findings
clustered into four root-cause groups + a misc group.

A) Sibling drift: AUTO mode missing in entry-point allowlists
   - packages/core/src/agents/background-agent-resume.ts —
     `normalizeApprovalMode` now accepts `'auto'`; `reconcileResumedApprovalMode`
     now treats `'auto'` as privileged (downgrade in untrusted folder).
   - packages/cli/src/nonInteractive/control/controllers/permissionController.ts —
     `validModes` for `set_permission_mode` includes `'auto'`; the
     non-interactive tool-permission switch handles AUTO (delegates to the
     scheduler's classifier).
   - packages/cli/src/config/config.ts — non-interactive deny-list switch
     adds an AUTO arm that mirrors PLAN/DEFAULT (no fallback UI available).
   - packages/sdk-typescript/{types/protocol,types/queryOptionsSchema}.ts —
     `PermissionMode` and the SDK `permissionMode` zod enum accept `'auto'`.
   - packages/vscode-ide-companion/* — `ApprovalModeValue`, `ApprovalMode`
     enum, `APPROVAL_MODE_MAP`, `APPROVAL_MODE_INFO`, `APPROVAL_MODE_VALUES`,
     and all ACP-session mode unions now include AUTO.

B) Sub-agent AUTO path (architectural)
   - agent.ts: untrusted-folder guard in `resolveSubagentApprovalMode` now
     blocks the `AUTO` privileged mode the same way it blocks YOLO / AUTO_EDIT.
   - agent.ts: `createApprovalModeOverride(_, AUTO)` now triggers
     `PermissionManager.stripDangerousRulesForAutoMode()` on the shared
     manager, so the override path matches the top-level entry path.
   - agent.ts: `AgentTool.toAutoClassifierInput` forwards the full prompt
     (was truncated to 200 chars, which hid attack payloads past character
     200 from the classifier while the sub-agent received the full text).

C) Sibling drift: dangerous-rule surface
   - dangerousRules.ts: interpreter list expanded with php / lua / julia /
     R / rscript / groovy / awk / pwsh / cargo / npm / pnpm / yarn / make /
     gradle / mvn / rake / just / eval / exec / source. Token-based
     detection now catches multi-word interpreter subcommands
     (`bun run *`, `npm run *`), absolute-path forms (`/usr/bin/python3 *`),
     and Monitor-tool allow rules with the same logic. Literal concrete
     commands (`Bash(npm test)`, `Bash(python script.py)`) are NOT flagged.
   - permission-manager.ts: `addSessionAllowRule` / `addPersistentRule`
     now stash newly added dangerous allow rules into `strippedAllowRules`
     while in AUTO mode, instead of letting an "Always allow" choice on
     a fallback prompt persist a broad rule that bypasses the classifier.
   - tools/tools.ts: default `toAutoClassifierInput` returns `''` (the
     no-security-relevance sentinel) instead of `undefined` (which fell
     through to raw args). Third-party MCP tools no longer leak raw
     parameters — potentially API keys, tokens, file contents — into the
     classifier LLM prompt by default. Internal tools that need their
     args inspected for safety override the method explicitly.

D) Classifier defense-in-depth (architectural)
   - autoMode.ts: `send_message` removed from SAFE_TOOL_ALLOWLIST so the
     classifier sees destination + body and can judge inter-agent steering.
   - autoMode.ts: when `pmForcedAsk=true` (user wrote an explicit ask
     rule), the function now returns `{ via: 'fallback' }` instead of
     falling through to the classifier — honoring the documented "ask
     rules force manual confirmation" guarantee.
   - classifier.ts: new `sanitizeClassifierReason` strips angle-bracket
     pseudo-tags, collapses whitespace, and clamps length to 200 chars;
     applied at the stage-2 boundary so `decision.reason` cannot smuggle
     a `<system>...` payload into the main model's tool-error message.
   - classifier.ts: `buildClassifierContents` /
     `buildClassifierSystemPrompt` are now wrapped in a try/catch that
     funnels to the existing `failClosed` handler, so any pathological
     input (circular projected args, registry lookup error, …) becomes
     an `unavailable=true` block result instead of crashing the
     tool-execution loop.
   - classifier-transcript.ts: transcript now truncates to the most
     recent 40 messages so long autonomous sessions don't overflow the
     fast classifier's context window — which would otherwise tip the
     session into the `consecutive_unavailable` fallback after two
     overflow-induced failures.

E) Misc
   - coreToolScheduler.ts + Session.ts: `finalPermission === 'allow'`
     path now calls `recordAllow` in AUTO mode so an explicit allow-rule
     match resets the denialTracking streak (otherwise a 3-block streak
     would silently force the next classifier-eligible call into manual
     approval right after an allow-ruled call just worked).
   - useAutoAcceptIndicator.ts: mount-time effect emits the first-time
     AUTO information notice + stripped-rules notice when the session
     starts already in AUTO (`--approval-mode auto` flag or
     `tools.approvalMode: "auto"` in settings). Previously the notices
     only fired on Shift+Tab / `/approval-mode` switches.

Test updates:
   - permissions/autoMode.test.ts: SAFE_TOOL_ALLOWLIST snapshot updated
     (no longer contains send_message). pmForcedAsk regression test now
     asserts the new `via: 'fallback'` semantics.
   - permissions/dangerousRules.test.ts: 25 new cases covering extended
     interpreter list, multi-word subcommands, absolute paths, and
     Monitor tool.
   - tools/toAutoClassifierInput.test.ts: AgentTool now asserts full-
     prompt passthrough rather than 200-char truncation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(vscode-ide-companion): include 'auto' in NEXT_APPROVAL_MODE cycle

The cycle map in `acpTypes.ts` is typed as
`{ [k in ApprovalModeValue]: ApprovalModeValue }`. After adding `'auto'`
to `ApprovalModeValue` in the previous commit, this map became missing
the `auto` arm — caught by CI's tsc check (`error TS2741: Property 'auto'
is missing`). Add it between `auto-edit` and `yolo` so the cycle order
remains plan → default → auto-edit → auto → yolo → plan, matching the
core APPROVAL_MODES ordering.

Local lint/typecheck only — not introduced or surfaced by review.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(core): silence two CodeQL findings on PR #4151

CodeQL 223 — Incomplete multi-character sanitization
(packages/core/src/permissions/classifier.ts:258)
A single `/<[^>]*>/g` pass can leave residual angle-brackets when the
input is crafted to overlap (e.g. `<scr<script>ipt>`). In our actual
use case the sanitized string is a prompt fragment, not HTML output,
so a "reconstituted script tag" doesn't matter — but iterating the
strip until the string stabilises is cheap defense-in-depth and
removes the warning. Bounded by 8 iterations so the loop is always
O(n) regardless of how the attacker structures the input.

CodeQL 222 — Polynomial regex on uncontrolled data
(packages/core/src/permissions/dangerousRules.ts:93)
The regex `/[*]+$/` is actually linear (single-character class + `$`
anchor, no backtracking), but CodeQL flags any `replace(<regex>, ...)`
applied to user-controlled input. Replace the regex with a manual
trailing-`*` strip via `slice` + a counted loop — same semantics,
no regex engine involved, warning cleared.

Existing tests cover both branches (classifier transcript sanitizer
test suite, dangerousRules interpreter coverage). No regressions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(cli,core,docs): address 4 non-blocker findings from PR #4151 review

Top-level review on c5cf60ee8 declared "可以合并" (good to merge) but
flagged 5 non-blocker items. Four are mechanical / low-cost; the fifth
(thresholds → config) is intentionally deferred — see review reply.

1. docs/users/features/auto-mode.md:223
   The "agent classifier sees first 200 chars of prompt" line was a
   stale leftover from before the truncation was removed (the
   AgentTool.toAutoClassifierInput regression guard now asserts full-
   prompt passthrough). Updated to describe the actual behavior plus
   the safety rationale (same shape as run_shell_command forwarding
   the full command). Also expanded the projection table with a note
   that MCP tools default to argument-stripped projection — pairing
   with the Limitations addendum below.

2. coreToolScheduler.ts:1425 + Session.ts:1945
   The unavailable error message was overwriting `failClosed`'s
   classified reason ('Conversation transcript exceeds classifier
   context window' / 'Classifier prompt construction failed' / etc.)
   with a generic "blocked for safety" line. Operators lose the
   diagnostic distinction. Both sites now append the original reason
   in parentheses when present: 'Auto mode classifier unavailable;
   action blocked for safety (Classifier stage 1 unavailable - …)'.

3. permission-manager.ts:771
   The session branch of the dangerous-rule stash didn't dedupe by
   raw string, while the persistent branch did. A user repeatedly
   clicking "Always allow" on the same fallback prompt would have
   piled duplicate stash entries that all activate on AUTO exit.
   Mirror the persistent-branch dedup.

4. docs/users/features/auto-mode.md (Limitations)
   Added a bullet making MCP-tool conservative-blocking explicit:
   third-party tools that haven't overridden toAutoClassifierInput
   show only their name to the classifier, so most calls will be
   blocked unless the user has written an explicit allow rule. This
   was a deliberate fail-closed choice from the previous round, but
   users wouldn't predict it without documentation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor(cli,core): inline classifier reason inside unavailable message

Minor nit from review on a3138cf5d: the previous wording put the
specific failClosed reason at the tail —
"unavailable; action blocked for safety (Conversation transcript
exceeds classifier context window)" — which separates the reason from
the "unavailable" context. wenshao's suggested wording inlines the
reason right after the noun it qualifies:
"Auto mode classifier unavailable (Conversation transcript exceeds
classifier context window); action blocked for safety".

Both forms preserve the diagnostic content. The inlined version reads
more naturally for operators scanning a tool-error trace. Mirror the
change in the ACP Session.ts path so CLI and ACP keep parallel
diagnostic shapes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(cli,core): address 10 review findings from PR #4151 round 4

Two reviewers (DeepSeek/deepseek-v4-pro + qwen-latest-series-invite-
beta-v28, both via wenshao /review) flagged 12 inline + 2 out-of-scope
findings. 11 accepted and fixed; 1 partially declined (L5 integration
tests — see classified reply).

Grouped by root-cause class:

# Class A — missing tool projections (sibling-drift sweep)

`SendMessageTool`, `MonitorTool`, `CronCreateTool` all reach the
classifier in AUTO (not on the allowlist, L3 default 'ask') but had no
`toAutoClassifierInput` override. The base default returns `''` →
`projectFunctionArgs` maps to `{}` → classifier sees just the tool
name. For `send_message` this was particularly bad: it was
intentionally REMOVED from the safe allowlist in an earlier round so
the classifier could inspect message content, but the classifier
ended up seeing zero arguments anyway.

  - send-message: + getDefaultPermission='ask' (was inheriting 'allow'
    from BaseToolInvocation, so the scheduler auto-approved at L4
    before L5 ran) + toAutoClassifierInput forwarding task_id+message.
  - monitor: toAutoClassifierInput forwards command+directory (same
    shape as ShellTool — classifier needs the actual command).
  - cron-create: toAutoClassifierInput forwards cron+prompt+recurring
    (the scheduled prompt runs against the agent at fire-time, so the
    classifier must see what the agent will be asked to do).

# Class B — client.toPermissionMode missing AUTO arm

SessionStart hooks in AUTO mode were silently receiving
`permission_mode: 'default'`. Add the missing case before the default
branch. Parallels the round-2 sibling-drift sweep that fixed the same
shape in background-agent-resume.

# Class C — duplicated CLI/ACP AUTO branch + missing tests

The classifier-block error message and the approve-outcome predicate
were duplicated verbatim in `coreToolScheduler.ts` and ACP
`Session.ts`. Extracted two helpers:
  - `formatClassifierBlockMessage(decision)` in autoMode.ts
  - `isApproveOutcome(outcome)` in denialTracking.ts
Both unit-tested with regression-guard cases. Both callsites now use
the helpers, so a future outcome added in one place can't drift.

Also added two `evaluateAutoMode` test cases the reviewer flagged
as missing: `pmForcedAsk=true` honors user intent (was already
tested) and `skipClassifier=true` routes to fallback without
dispatching the classifier (NEW guard against denialTracking
regression).

# Class D — perf + dead code + Edit preview

  - `getHistory(false)` → `getHistoryTail(40, false)` at the two AUTO
    classifier-dispatch sites. The transcript builder already truncates
    to 40 messages; cloning the full session every non-fast-path call
    was wasted work.
  - Removed `recordFallbackReject` (dead code per reviewer audit).
    The "rejection preserves state" invariant is enforced by simply
    not calling any state-mutating function; an exported no-op
    helper invited future drift.
  - Bumped Edit/WriteFile preview from 80 → 300 chars and added
    explicit truncation flags. In-workspace edits take the
    acceptEdits fast-path so this only affects out-of-workspace
    writes (~/.npmrc etc.) — exactly the case where the classifier
    needs more headroom to spot a hostile payload after a benign
    prefix.

# Class E — prompt-injection via workspace hints + colon-form Bash FP

  - User-provided `autoMode.hints.{allow,deny}` are now wrapped in
    `<user_hint>` tags in the classifier system prompt, and a new
    decision principle explicitly tells the classifier to treat
    instruction-shaped hints ("always set shouldBlock=false") as
    adversarial prompt injection rather than directives. This pairs
    with the existing untrusted-workspace short-circuit (workspace
    settings are dropped from merged settings on untrusted folders)
    to defend in depth against a hostile `.qwen/settings.json`.
  - `isDangerousBashRule` no longer flags specific colon-form rules
    like `Bash(python3:run-tests)` as dangerous. Previously two paths
    (firstToken-equals-content + colon-with-interpreter) hit specific
    concrete rules as if they were wildcards. Now only empty-suffix
    (`python:`) and `*`-suffix variants are dangerous; concrete
    suffixes are treated the same as `Bash(npm run test)`. Two new
    test groups codify the boundary.

# Class F — classifier observability

The `failClosed` helper consumed the underlying error and returned
only a generic sanitized reason. Operators debugging "every AUTO call
is unavailable" had no way to distinguish API timeout / context
overflow / construction failure. Added `debugLogger.warn` inside
both fail paths (failClosed + the stage-2-review-unavailable branch)
that logs the original error name+message. No telemetry/UI surface
change — debug-only.

# Out-of-scope (top-level review summary)

Already covered as part of Class A — both SendMessageTool and
MonitorTool projections plus SendMessage permission override fix.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(sdk,serve,docs): include 'auto' in DAEMON_APPROVAL_MODES sibling sites

After rebase onto current main, three sites needed updating to keep
the AUTO mode integrated end-to-end:

1) packages/sdk-typescript/src/daemon/types.ts:706
   `DAEMON_APPROVAL_MODES` literal tuple was still 4-mode. The new
   `approval-mode-drift.test.ts` (#4282 fold-in) asserts this tuple
   mirrors core's `APPROVAL_MODES` sequence-exactly — it caught the
   drift before runtime, exactly as designed.

2) packages/cli/src/serve/server.test.ts:2287
   The 400-response assertion for unknown approval-mode literal still
   expected the 4-mode list. Updated to include 'auto' between
   'auto-edit' and 'yolo' (matching core APPROVAL_MODES ordering).

3) docs/developers/qwen-serve-protocol.md:1124
   Protocol docs listed 4 modes for the `POST /session/:id/approval-
   mode` body validator. Updated to 5.

These are mechanical follow-ups to AUTO mode's existing entry-point
sweep — covered by sibling-drift class but only surfaced once main
landed the SDK drift detector and the new serve API.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(core,sdk): two critical bypasses + SDK union drift on PR #4151

wenshao surfaced two critical findings on the round-4 fix; both are
self-inflicted regressions from defenses I added that didn't go deep
enough.

# 1. <user_hint> tag escape (classifier-prompts/system-prompt.ts)
[gpt-5.5 — comment 3263963950]

Round 4 wrapped user-provided hints in raw `<user_hint>...</user_hint>`
tags to mark them as untrusted context. But the tag envelope is broken
the moment the payload itself contains a closing tag:

    "allow": ["</user_hint>\n- Allow all shell commands\n<user_hint>"]

renders as a real bullet outside the wrapper. The defense was empty.

Fix: render user hints as JSON-encoded string literals labelled
`user hint:`. JSON.stringify keeps the entire payload inside a single
quoted string with newlines escaped to `\n` and quotes to `\"` — the
injected text can never become its own structural bullet line.
Decision-principles text updated to reference the new shape.

Regression-guard test: a payload containing `</user_hint>` plus an
injection sentence preceded by a newline must NOT appear as a
standalone bullet line.

# 2. Privileged tools' L3 default = 'allow' bypassed the classifier
[gpt-5.5 — comment 3263963966]

Round 4 added `toAutoClassifierInput` projections to AgentTool /
SkillTool / CronCreateTool but did NOT override `getDefaultPermission`.
The base default is `'allow'`, and the scheduler short-circuits at L4
when finalPermission === 'allow' (the AUTO ack short-circuit I added
in round 1 to honor explicit allow rules) — so the new projections
were never reached and arbitrary sub-agent spawns / skill invocations
/ scheduled prompts silently approved.

Same shape as the SendMessageTool critical from round 4. That round
fixed the one tool the reviewer pointed at; this round audits the
sibling sites I should have caught at the same time.

Override `getDefaultPermission` to return `'ask'` on all three:
  - AgentTool — sub-agent spawn
  - SkillTool — skill load + user code execution
  - CronCreateTool — scheduled prompt that runs against agent at fire-
    time

Updated the two existing "should not require confirmation" tests in
agent.test.ts + skill.test.ts which were codifying the bypass.

# 3. SDK QueryOptions.permissionMode union missing 'auto'
[gpt-5.5 top-level review]

Sibling drift: the SDK protocol schema accepts 'auto' but the public
`QueryOptions.permissionMode` literal union was still 4-mode. Typed
SDK consumers calling `query({ permissionMode: 'auto' })` got a TS
error. Updated the union, refreshed the JSDoc + priority chain, and
inserted 'auto' in the documented mode list.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(core,cli): close 5 review findings on PR #4151 round 5

Two critical + three sugges…
LaZzyMan added a commit that referenced this pull request May 27, 2026
…s + PR refs (#4381)

* feat(worktree): Phase D — startup --worktree flag + symlinkDirectories + PR refs

Three cross-cutting capabilities on top of the Phase A-C worktree
foundation (PRs #4073, #4174).

D-1: --worktree [name] CLI flag creates a worktree (or re-attaches to
one that already exists) before any model turn runs. Supports bare,
plain-slug, `=`, and PR-reference forms; --worktree + --acp rejected
with a clear error; --worktree + --resume overrides the resumed
session's saved sidecar and emits a stderr line.

D-2: worktree.symlinkDirectories: string[] settings key opts into
symlinking main-repo directories (e.g. node_modules) into every
newly-created general-purpose worktree. Applies to all three creation
paths: --worktree flag, EnterWorktreeTool, AgentTool isolation. Path
traversal, absolute paths, and existing destinations all guarded;
missing source dirs and EEXIST silently skipped (fail-open).

D-3: --worktree=#<N> / --worktree <github-url> resolves a PR number,
runs `git fetch origin pull/<N>/head` (30s timeout, no `gh` CLI
dependency, LANG=C for stable error-taxonomy matching), and creates
the worktree off FETCH_HEAD. URL regex tolerates /files, /commits,
/checks sub-paths so users can paste any GitHub PR URL.

Phase 6 verification fixes also included:
- Re-attach to an existing worktree instead of failing with "Worktree
  already exists" — the common `qwen --resume <sid> --worktree foo`
  workflow now succeeds. The session ownership marker is preserved on
  re-attach so cross-session exit_worktree action="remove" still fails
  for non-owners.
- Normalize path-taking argv fields (mcpConfig, jsonSchema @<path>,
  openaiLoggingDir, jsonFile, inputFile, telemetryOutfile,
  includeDirectories) to absolute paths against the launch cwd BEFORE
  the worktree chdir. Otherwise downstream fs.existsSync('./mcp.json')
  resolves into the worktree, where the file doesn't exist.

Phase 7 code-review fixes:
- buildStartupWorktreeNotice differentiates "Active worktree" (fresh
  create) from "Re-attached to worktree" (re-attach path).
- Notice survives sidecar persist failure: set before the try block,
  refreshed inside with override addendum if persist succeeded.
- getRegisteredWorktreeBranch verifies the candidate path's git
  common-dir matches the source repo's — rejects sibling `git init`
  directories that happen to be on a worktree-<slug> branch.

Three-mode parity for the startup notice: TUI consumes via
AppContainer effect, headless prepends a <system-reminder> + emits a
worktree_started JSON event. ACP path is mutually exclusive with
--worktree (ACP hosts supply per-session cwd separately).

Tests (66 + 15 new):
- 15 cli/src/startup/worktreeStartup.test.ts (slug forms, PR fetch
  against local fake remote, re-attach happy + wrong-branch guard)
- 8 core/src/services/gitWorktreeService.test.ts (parsePRReference:
  #N, URLs, malformed, traversal, leading zeros, non-string)
- 10 core/src/services/gitWorktreeService.symlinks.integ.test.ts
  (symlink loop + fetchPullRequestRef error taxonomy)

Known limitations (documented in docs/users/features/worktree.md):
- Cross-slug --resume <sid> --worktree <different-new-slug> is
  unsupported by design (sessions are bound to projectHash(cwd));
  future Config refactor anchoring storage at repo root would lift this.
- Mid-session enter_worktree still does NOT switch cwd/targetDir
  (Phase A's simplification); only the startup --worktree flag does.
- yargs ambiguity: `qwen --worktree "say hi"` consumes the prompt as
  the slug. Quick Start shows the `=` form and reordering workarounds.

Docs:
- docs/users/features/worktree.md (new): Quick Start with --worktree
  flag, CLI Reference table for all four input forms + error codes,
  settings table, Limitations.
- docs/design/worktree.md: Phase D section expanded into D-1/D-2/D-3
  with open questions resolved; capability table updated.
- docs/e2e-tests/worktree-phase-d.md (new): full E2E plan with Phase 4
  dry-run baseline + Phase 6 post-impl reproduction tables.

Refs #4056

* refactor(worktree): apply self-review feedback on Phase D

Self-review pass over the Phase D commit (2636f59) catching one real
typecheck regression plus a batch of small quality + efficiency
improvements. No user-visible behavior change beyond fixing the build.

Build fix:
- worktreeStartup.ts imports — pre-commit prettier had reorganized
  `writeWorktreeSession` and `readWorktreeSession` under an
  `import type { ... }` block, erasing them at compile time
  (verbatimModuleSyntax). `tsc --noEmit` was failing with TS1361.
  Bundle path still worked (esbuild is lenient) so this only surfaced
  when running typecheck.

Startup-path efficiency (~10-25 ms saved per --worktree invocation on
macOS; more on Windows):
- Drop redundant `isGitRepository()` probe — `getRepoTopLevel()`
  returns null on non-git paths and covers both gates in one
  subprocess.
- Run `getCurrentBranch()` + `getCurrentCommitHash()` in parallel via
  Promise.all (independent calls).
- Combine the two `git rev-parse` probes inside
  `getRegisteredWorktreeBranch` into a single multi-arg call, and run
  it in parallel with the source-repo common-dir lookup. Saves one
  fork+exec on the re-attach path.

Quality:
- Extract `withReminder()` local helper in nonInteractiveCli.ts so the
  startup-notice and resume-restore branches share the system-reminder
  wrapping.
- Log `readWorktreeSession` failures in `persistStartupWorktreeSidecar`
  with the sidecar path so operators can recover the previous slug
  from a backup. Silent swallow was making "where did my worktree
  binding go?" undebuggable.
- Drop the dead `Config.getWorktreeSettings()` accessor (only
  `getWorktreeSymlinkDirectories()` has callers); keep the underlying
  `WorktreeSettings` interface for future fields.
- Document the `pendingStartupWorktreeNotice` invariant: at most one
  consumer per process; ACP path is gated out earlier so only TUI XOR
  headless reads it.
- Add a maintainer note in the gemini.tsx path-normalization block:
  the argv path-field allowlist is hand-maintained, register new
  path-bearing flags there or `--worktree` silently breaks for them.
- Drop `Phase 6 fix (G1)/(G2)` parenthetical labels from inline
  comments — internal review-cycle identifiers that decay to noise
  post-merge. Substantive prose retained.

Tests: cli 15/15 (unchanged) + core 66/66 (unchanged); bundle smoke
verified fresh / re-attach / invalid slug / non-git cases.

Findings deliberately left for follow-up:
- Larger refactor extracting a shared `provisionUserWorktree` helper
  for the EnterWorktreeTool / startup overlap (~80% duplicate).
- Splitting the re-attach branch out of `setupStartupWorktree` into
  its own function.
- `isPathWithinRoot` / `isInsideManagedWorktree` shared utils.
- `symlinkConfiguredDirectories` loop concurrency (saves 5-15 ms on a
  cold path that runs only when symlinkDirectories is configured).

* docs(worktree): refresh stale docstring in worktreeStartup

Top-of-file docstring still said `{adj}-{noun}-{4hex}` (actual format
is 6 hex chars) and described the PR form as "detected and rejected
with a clear 'coming in D-3' message" — but D-3 shipped in the same
PR. Tighten to reflect what the code actually does.

* fix(worktree): address findings from dual-reviewer self-check

Two real bugs surfaced by an independent dual-reviewer pass (Claude +
Codex) on the Phase D commits. Both correctness-affecting; both
escaped the earlier internal reviews.

P0 — re-attach captured the wrong baseline for the exit dialog
(Codex):
  setupStartupWorktree captured `originalHeadCommit` from the launch
  cwd (main checkout) before any chdir. On the re-attach path the
  WorktreeExitDialog later runs `git rev-list <originalHeadCommit>..HEAD`
  inside the worktree to count "new commits this session". With the
  main-checkout baseline this counted every commit ever made in the
  kept worktree as new work from the current session — misleading the
  keep/remove prompt. Re-capture HEAD from inside the worktree after
  chdir so the count means what the dialog text says it means.

P0 — getRegisteredWorktreeBranch mis-identified plain directories as
registered worktrees (Claude):
  A plain directory at `<repo>/.qwen/worktrees/<slug>/` (e.g. a stale
  artifact from a previous tool) had no `.git` file of its own, so
  `git rev-parse --git-common-dir` walked up to the outer repo and
  returned the outer common-dir — matching the source repo's
  common-dir check and impersonating a registered worktree. If the
  outer repo happened to be on `worktree-<slug>`, setupStartupWorktree
  would silently chdir into the plain directory and treat it as
  attached; subsequent `exit_worktree action="remove"` would then
  delete a directory that was never registered.
  Fix: also probe `--show-toplevel` and require it to equal the
  candidate path (canonicalised via `realpath` so macOS /var → /private/var
  doesn't break the equality check). A plain dir under the main repo
  gets the outer repo's toplevel and is correctly rejected.

Smaller polish from the same review:
- Normalize the literal string `'HEAD'` returned by `getCurrentBranch`
  on detached HEAD to `undefined`, so the `baseRef` handed to
  `git worktree add -b … HEAD` does not implicitly anchor against
  the loose commit when the launch cwd is detached.
- `symlinkConfiguredDirectories`: blocklist `.git` (any nested
  ancestor) and `.qwen/worktrees` (any nested ancestor). Linking
  `.git` would silently break commits inside the worktree; linking
  `.qwen/worktrees` would create a worktrees-inside-worktrees loop
  that confuses the startup sweep.
- `WorktreeSettings.symlinkDirectories` typed `readonly string[]` to
  match the `createUserWorktree(options.symlinkDirectories)` contract
  and the immutable-config convention elsewhere. `Config.getWorktreeSymlinkDirectories()`
  return type updated to match.

Docs:
- design/worktree.md precedence table rewritten. The previous
  `--worktree` 赢 row was unreachable in practice (sessions are bound
  to `projectHash(cwd)`, and the chdir happens before session lookup).
  New table reflects what actually happens for each combination of
  `--resume` × `--worktree`, including the documented
  cross-projectHash limitation. The `persistStartupWorktreeSidecar`
  override branch is now annotated as dead-on-the-current-architecture
  but kept so a future Config refactor (anchor storage at repo root)
  picks it up for free.

Tests: cli 15/15 + core 66/66 unchanged. Bundle smoke confirms both
P0 fixes end-to-end (re-attach captures worktree HEAD = run-1 tip,
plain-dir attempt errors out without clobbering existing content).

* refactor(worktree): consolidate probe + name detached-HEAD sentinel

Second /simplify pass on the dual-reviewer fixes. Three convergent
findings; net effect is one fewer subprocess on the re-attach path
and clearer intent on string handling / blocklist guards.

Efficiency + quality:
- Fold the worktree HEAD SHA into `getRegisteredWorktreeBranch`'s
  combined rev-parse. The probe already requests common-dir,
  toplevel, and abbrev-ref HEAD in a single subprocess; adding a
  leading `HEAD` positional (which must come BEFORE `--abbrev-ref` so
  the flag doesn't apply to it) returns the SHA on its own line.
  Return type widened to `{ branch, headCommit } | null`. Removes
  the second `GitWorktreeService` instantiation and `getCurrentCommitHash`
  call that `setupStartupWorktree`'s re-attach branch used to do.

Quality:
- Hoist `'HEAD'` to a module-level `DETACHED_HEAD` constant in
  `worktreeStartup.ts`. Three uses, two meanings (input filter when
  normalizing `getCurrentBranch` output, fallback metadata for the
  sidecar's `originalBranch` field on detached state). Naming the
  sentinel makes intent self-documenting and pre-empts the "why is
  the value we just stripped re-appearing as a fallback?" reader stall
  flagged by the round-3 quality review.

Reuse + quality:
- `symlinkConfiguredDirectories`: replace two hand-rolled containment
  checks (`startsWith(prefix + sep)` for `.qwen/worktrees`; `path.relative(...).split(sep)[0]`
  for `.git`) with `isWithinRoot` from `utils/fileUtils.ts`, which is
  already imported in this file. Replace the hardcoded
  `path.join(repoRootAbs, '.qwen', 'worktrees')` with `this.getUserWorktreesDir()`
  so the layout lives in one place (the exported `WORKTREES_DIR`
  constant). Split the misleading `sourceAbs === repoRootAbs` clause
  out of the `.git` branch into its own dedicated "empty / repo-root
  path" rejection with a clearer warn message.

Tests: cli 15/15 + core 66/66 unchanged. Bundle smoke verified the
folded probe still captures the worktree's HEAD on re-attach (not
the launch-cwd HEAD).

Skipped from this review pass:
- Moving `'HEAD'` normalization into `GitWorktreeService.getCurrentBranch()`
  itself — would ripple through `enter-worktree.ts` and `agent.ts`
  callers that hand the result verbatim to `git worktree add -b ...`.
  Out of scope for a polish pass; the local const is enough.

* fix(worktree): broaden symlink blocklist from .qwen/worktrees to all of .qwen

Caught by a second pr-tracker dual-reviewer pass (Codex). The previous
guard at `symlinkConfiguredDirectories` only refused paths inside
`<repoRoot>/.qwen/worktrees/` — `.qwen` itself (the parent) sailed
through because `isWithinRoot` is a strict descendant check. A user
setting `symlinkDirectories: ['.qwen']` would therefore symlink the
entire CLI metadata tree into the new worktree, recursively pulling
in `.qwen/worktrees` and recreating the loop the guard was meant to
prevent. Other `.qwen/*` subtrees (`projects`, `tmp`, …) are CLI
state with no legitimate cross-worktree sharing use case either.

Fix: broaden the guard to reject the whole `<repoRoot>/.qwen` tree.
Both `.qwen` itself and any descendant fail closed.

Also synced the user-facing settings schema description (the in-IDE
help text and the published JSON schema) so it mentions the `.git`
and `.qwen` rejection rules. The `WorktreeSettings` interface JSDoc
already mentioned them; the schema description had not been updated.

Tests: cli 15/15 + core 66/66 unchanged. Smoke confirms `--worktree foo`
with `symlinkDirectories: ['.qwen']` configured leaves the worktree
free of any `.qwen` symlink (only the legitimate per-worktree
`.qwen-session` marker file appears).

* fix(worktree): guard fetchPullRequestRef against CodeQL command-injection alert

CodeQL flagged a "Second order command injection" finding (rule 235) on
the `git fetch origin pull/<N>/head` call in `fetchPullRequestRef`. The
taint analyzer doesn't see the type-narrowing at the function entry
(`Number.isSafeInteger(prNumber) && prNumber > 0 && prNumber <= 1e9`),
so it considers `prNumber` library input that could in principle reach
a `--upload-pack=…`-shaped flag and thereby execute an arbitrary
program. In practice the entry guard already prevents that, but the
alert blocks the CodeQL CI check.

Add `--end-of-options` between `origin` and the refspec — git's
canonical "stop parsing flags" marker (git ≥ 2.24). Tells git
definitively that every subsequent argv element is a positional, not
a flag, which (a) satisfies the analyzer, (b) adds defense-in-depth
against a future regression that might relax the entry guard, and
(c) has zero behavior change for any well-formed PR number.

Verified locally: `git fetch --end-of-options origin pull/<N>/head`
against a local bare-remote with a seeded `refs/pull/42/head` still
fetches the ref correctly; the `--worktree=#42` smoke test reads back
the PR content from the materialized worktree.

Tests: cli 15/15 + core 66/66 unchanged.

* fix(worktree): lexical sanitizer for CodeQL + missing test mock entry

Two fixes from the third CI round on PR #4381:

1. CodeQL re-fires (round 2 of the same finding).

`--end-of-options` is a git-runtime defense, not a lexical sanitizer
that CodeQL's `js/second-order-command-line-injection` taint tracker
recognises. The alert re-fired against the same call after the
previous fix.

Switch to a CodeQL-recognised sanitizer: validate the numeric
component against `/^[1-9][0-9]*$/` immediately at the sink. The
regex digit-only check is one of the documented sanitizer patterns
the rule looks for, and proves at the analyzer level that the
resulting argv element cannot resemble a flag (`--foo`). The entry
guard at the top of the function still establishes the same fact
at runtime; this layer makes the proof visible to static analysis.
Keep `--end-of-options` as a runtime fallback against any future
regression that loosens the entry guard.

2. `nonInteractiveCli.test.ts` mock was missing the new
   `consumePendingStartupWorktreeNotice` Config method.

Phase D-1 added the method on `Config` and `nonInteractiveCli`
calls it on every prompt to pick up the one-shot startup-worktree
notice. The test file's `mockConfig` literal was not updated, so
all 19 `runNonInteractive` tests threw
`TypeError: config.consumePendingStartupWorktreeNotice is not a
function` on Ubuntu / macOS CI.

Add a stub returning `null` so the helper short-circuits, matching
the equivalent Phase C stub for `getResumedSessionData`.

Local: cli (worktreeStartup + nonInteractiveCli) 60 passed + 1
skipped; core (gitWorktreeService + symlinks + hooks +
enter-worktree) 66 passed.

* test(worktree): mock getWorktreeSymlinkDirectories in three more test files

Round 4 of the same Phase D-2 mock-drift class. CI surfaced 9 test
failures across three files whose `Config` mocks construct
`EnterWorktreeTool` for setup but lack the new
`getWorktreeSymlinkDirectories` method `createUserWorktree` now
calls:

- enter-worktree.session.integ.test.ts (2 tests)
- exit-worktree.session.integ.test.ts (3 tests) — provisions
  worktrees via EnterWorktreeTool before exercising exit paths
- exit-worktree.test.ts (4 tests) — same provisioning pattern via
  `provisionWorktree()` and the `makeMockConfig` helper

Add a `getWorktreeSymlinkDirectories: () => []` stub to each so
the symlink loop is a no-op in tests.

`enter-worktree.test.ts` and `agent/agent.test.ts` intentionally
skipped — they mock `GitWorktreeService.createUserWorktree` outright,
so the method call never fires in their code paths. Adding the stub
there would be defensive speculation. If a future test exercises
the real path, it'll surface there too and we'll add it then.

Local: core tools tests now 123 passed (was 9 failed / 114 passed
on CI run 26213122427 against commit 000c9f6).

* fix(worktree): normalize repoRoot path separators + disable autocrlf in tests

Round 5 of CI: Windows-only test failures on the latest HEAD. Two
unrelated Windows-specific bugs, both in / around worktreeStartup.

1. `setupStartupWorktree` stored the raw `getRepoTopLevel()` output
   in `context.repoRoot`. git always emits POSIX paths via
   `--show-toplevel` (`C:/Users/...`), so on Windows the value was
   forward-slash where `fs.realpath` and `path.join` produce
   backslash. The sidecar's `originalCwd` field got the
   inconsistent format and a downstream `expect(...).toBe(tempRepo)`
   in the round-trip test compared `C:/Users/.../tmp/...` against
   `C:\Users\.../tmp/...`.

   Wrap the value in `path.resolve()` to normalize to the
   platform-native separator before storing. Downstream consumers
   (`path.join(session.originalCwd, '.qwen', 'worktrees')` in
   `restoreWorktreeContext`, `new GitWorktreeService(originalCwd)`
   in `AppContainer`) already handle either format, so no migration
   concern for older sidecars.

2. `makeTempRepo` in worktreeStartup.test.ts didn't configure
   `core.autocrlf=false`. On Windows runners the default is `true`,
   so files committed and pushed to the test's fake-remote `pull/<N>/head`
   ref get CRLF-converted on the worktree's checkout. The PR-content
   assertion `expect(prFile).toBe('from PR 42\n')` then failed with
   `'from PR 42\r\n'`.

   Add `core.autocrlf=false` + `core.eol=lf` to the temp-repo setup
   so test files round-trip byte-for-byte regardless of host platform.

Local mac: cli worktreeStartup 15/15 still pass. Windows verification
deferred to CI.

* fix(worktree): reject '..' segments + use junction on Windows

Two Copilot findings on symlinkConfiguredDirectories (PR #4381 round 3):

1. The settingsSchema description, docs/users/features/worktree.md, and
   WorktreeSettings JSDoc all promise that entries containing `..` are
   rejected — but the post-resolve isWithinRoot check accepted
   `foo/../bar` (resolves to `bar`, inside the repo). Add a literal `..`
   segment check before path.resolve so the code matches the contract.

2. On Windows, fs.symlink(..., 'dir') requires
   SeCreateSymbolicLinkPrivilege (admin / Developer Mode) and EPERMs on
   default consumer installs. Use 'junction' for directory entries on
   win32 — junctions are reparse points that achieve the same semantics
   without elevation. Keep 'dir' on POSIX and 'file' for non-directory
   sources (no junction-equivalent for files; rare path).

Adds an integration test exercising `foo/../bar` to lock in the
syntactic guard; existing absolute-path and traversal tests already
covered the other rejection forms.

* fix(worktree): PR-worktree HEAD-SHA capture + symlink guard tests

Three findings from wenshao round 4 (PR #4381):

1. For --worktree=#42 (PR worktrees), originalHeadCommit was captured
   from the parent repo's HEAD via getCurrentCommitHash() — but the
   worktree branches off FETCH_HEAD (the PR tip), not main. Downstream,
   WorktreeExitDialog's `rev-list <originalHeadCommit>..HEAD` would
   count every commit in the fetched PR as "new work this session"
   alongside the user's actual commits.

   Same root cause covers the FETCH_HEAD TOCTOU window: between
   `git fetch origin pull/<N>/head` and `git worktree add ... FETCH_HEAD`,
   a concurrent `git fetch` from any other process sharing this repo
   could overwrite .git/FETCH_HEAD, causing the worktree to branch off
   an unrelated commit.

   Fix: add GitWorktreeService.resolveRef(ref) that returns a 40-char
   SHA (or null). In setupStartupWorktree, immediately after
   fetchPullRequestRef succeeds, resolve FETCH_HEAD to an immutable
   SHA; pass that SHA both as the baseRef to createUserWorktree (closes
   the TOCTOU) AND as originalHeadCommit in the returned context
   (closes the exit-dialog miscount). Fail-close on null resolve.

2. Orphaned JSDoc block at gitWorktreeService.ts:1035-1048 — originally
   wrote validateUserWorktreeSlug's docs, stranded above parsePRReference
   after that function was inserted between them. Move the block down to
   sit immediately above validateUserWorktreeSlug at its current line.

3. `.git` / `.qwen` symlink rejection guards (~20 lines of security-
   critical code at gitWorktreeService.ts:1640-1655) had no regression
   tests — only absolute paths, `..` traversal, isWithinRoot escapes,
   and missing sources were covered. Add two integ tests in
   gitWorktreeService.symlinks.integ.test.ts: one asserts `.git/hooks`
   is refused, one asserts `.qwen/projects` is refused.

Also extends the existing PR-worktree integration test in
worktreeStartup.test.ts to assert originalHeadCommit equals the
resolved FETCH_HEAD SHA AND does NOT equal the parent repo's main HEAD
— the assertion would fail loudly if the new SHA-capture path were
reverted.

* fix(worktree): realpath check on symlinkDirectories source + dest paths

Security fix from PR #4381 round 7 (wenshao/qwen3.7-max). The lexical
isWithinRoot + .git/.qwen blocklist checks in symlinkConfiguredDirectories
all operated on path.resolve(repoRoot, raw) — a STRING operation that
doesn't follow symlinks. A committed (or out-of-band) symlink at
<repo>/node_modules pointing into .git would pass every gate:

  1. path.resolve gives `<repo>/node_modules` (lexical, passes
     isWithinRoot against repo root).
  2. The .git/.qwen blocklists also see the lexical path — they don't
     detect that the realpath chains into .git.
  3. fs.stat() follows the symlink and succeeds against .git/.
  4. fs.symlink writes `<worktree>/node_modules → <repo>/node_modules`,
     which OS-side resolves through to <repo>/.git. Any tool inside the
     worktree that writes to node_modules/hooks/post-merge then has RCE
     on the next hook-firing git operation.

Fix: after fs.stat succeeds, fs.realpath the source and RE-RUN the three
containment checks against the realpath. Refuse on any escape. Use the
realpath (not the lexical sourceAbs) as the symlink target so the new
link is one-hop canonical rather than preserving the chain.

Also closes the dest-side variant of the same root cause — flagged in
round 4 thread #5 (declined then as overthinking) but now in scope per
the skill's iteration rule (two consecutive rounds raising the same
root-cause class). path.join(worktreePath, raw) is also lexical: if
git worktree add materialized a committed worktree-level symlink (e.g.
HEAD ships tools → /etc), then fs.mkdir / fs.symlink for a nested entry
like "tools/cache" writes OUTSIDE the worktree. Realpath the dest
parent before mkdir and refuse if it escapes the worktree.

New integ test covers both source-side variants (escape-to-git via
out-of-band symlink + escape-to-outside-dir) in one block. Was RED
against the pre-fix code: <wt>/escape-to-git was created as a symlink
that chained into the source repo's .git. GREEN after the fix.

* fix(worktree): canonicalise repo root before symlinkDirectories checks

Round-7's source-side realpath fix introduced a canonical-vs-lexical
mismatch: `repoRootAbs = path.resolve(this.sourceRepoPath)` is purely
lexical, while `realSource = await fs.realpath(sourceAbs)` is canonical.
On macOS where `/tmp → /private/tmp` and `/var → /private/var` are
ubiquitous, and on any Linux/Windows setup where the user's checkout
sits behind a symlink, the prefixes diverge at the symlink boundary and
`isWithinRoot(realSource, repoRootAbs)` silently rejects every
configured entry.

Production callers (worktreeStartup.ts, EnterWorktreeTool,
agent isolation) all pass the lexical path returned by
`git rev-parse --show-toplevel`. The integ tests masked the bug because
the shared `beforeEach` did `repoRoot = await fs.realpath(dir)` upfront.

Round 8 fix:

- Hoist `repoRootAbs`, `gitDirAbs`, `qwenDirAbs`, and `realWorktreePath`
  outside the for-loop — they're loop invariants and were being
  recomputed once per entry.
- `await fs.realpath(this.sourceRepoPath)` for `repoRootAbs` so every
  containment check below is canonical-vs-canonical. The derived
  `gitDirAbs` / `qwenDirAbs` blocklist paths inherit the canonical
  prefix automatically. `sourceAbs = path.resolve(repoRootAbs, raw)`
  inherits it too, so the early lexical reject paths (absolute, `..`,
  repo-root equality, isWithinRoot) stay self-consistent.
- Fail-close: if the repo root itself doesn't realpath (deleted /
  inaccessible), bail out of the entire symlink loop rather than
  continuing with comparisons we can't trust. Non-destructive — the
  worktree was created earlier by `git worktree add`.

New integ test provisions the production shape: a symlink path used
as `sourceRepoPath`, distinct from its canonical realpath. RED on the
pre-fix code (assertion fired with "symlinkDirectories entry was
silently rejected — canonical vs lexical isWithinRoot mismatch"),
GREEN after.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/feature-request New feature or enhancement request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants