Skip to content

Replace agent-session quickpick with a smart dispatcher#5262

Open
ianhattendorf wants to merge 1 commit into
mainfrom
agent-smart-quickpick
Open

Replace agent-session quickpick with a smart dispatcher#5262
ianhattendorf wants to merge 1 commit into
mainfrom
agent-smart-quickpick

Conversation

@ianhattendorf
Copy link
Copy Markdown
Contributor

@ianhattendorf ianhattendorf commented May 20, 2026

Summary

Replaces the action-pick quickpick that fired on "open agent session" with a deterministic dispatcher that picks the right action based on session host + workspace state:

  • In-workspace + extension-hosted → open in the Claude Code VS Code extension
  • In-workspace + CLI-hosted → focus the owning terminal window via pid
  • Out-of-workspace → ask the peer GitLens window that already has the workspace open to pre-open the session in its Claude Code extension (new agents/sessions/open IPC route), then vscode.openFolder to focus that peer's window

Host classification reads ~/.claude/sessions/<pid>.json for the entrypoint field, with a stale-file guard (file's pid field must match the filename) and a sensible "extension if installed, else CLI" fallback when the metadata file is missing.

The peer-notify call is capped at 500 ms so an unhealthy peer can't stall the click — the POST keeps running in the background after vscode.openFolder lands.

Test plan

  • Unit tests: pnpm run test:packages (4 new agents/sessions/open IPC handler cases, 3 new notifyPeerOpenSession cases) and pnpm run test (7 new classifyClaudeSessionHost cases) all pass
  • In-workspace + extension-hosted session: clicking "open agent session" routes to the Claude Code extension editor pane
  • In-workspace + CLI-hosted session: clicking routes to the terminal window (with parent-PID walk for tmux-style setups)
  • Out-of-workspace session with a peer window holding the workspace open: peer's Claude Code extension receives the session before the focus switch lands
  • Out-of-workspace session with no peer window: vscode.openFolder falls through and the current window switches to the folder
  • Extension-hosted session whose extension command throws: surfaces the "Unable to open agent session" warning rather than focusing the VS Code window in a misleading no-op
  • Unhealthy peer (paused/unresponsive but not RST): click resolves within ~500 ms instead of waiting the full per-fetch timeout

@ianhattendorf ianhattendorf marked this pull request as ready for review May 20, 2026 20:19
@ianhattendorf ianhattendorf requested a review from Copilot May 20, 2026 20:19
@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented May 20, 2026

🤖 Augment PR Summary

Summary: This PR replaces the “open agent session” action quickpick with a deterministic dispatcher that chooses the best action based on session host + workspace state.

Changes:

  • Adds session-host classification via Claude session metadata files (~/.claude/sessions/<pid>.json) to distinguish extension-hosted vs CLI-hosted sessions
  • Updates AgentStatusService to route clicks automatically: open in Claude Code extension, focus terminal by PID, or switch to the owning workspace
  • Introduces a new IPC route agents/sessions/open so a peer VS Code window can pre-open a session before focus switches
  • Adds notifyPeerOpenSession to scan discovery files and POST the sessionId to the matching peer window
  • Extracts Claude extension availability detection into a shared helper and updates the agent registry to reuse it
  • Adds unit tests covering the new IPC handler, peer notification behavior, and session-host classification edge cases

Technical Notes: Peer notification is best-effort and the UI wait is capped (~500ms) so unresponsive peers don’t stall the click.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/agents/agentStatusService.ts Outdated
Comment thread src/agents/agentStatusService.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Replaces the “open agent session” action quickpick with a deterministic dispatcher that routes to the Claude Code VS Code extension, focuses the owning terminal, or coordinates with a peer GitLens window via a new IPC route.

Changes:

  • Add session-host classification via Claude session metadata (~/.claude/sessions/<pid>.json) and use it to choose extension vs CLI behavior
  • Add peer-window session pre-open support (agents/sessions/open IPC handler + notifyPeerOpenSession) and wire it into session dispatch
  • Extract Claude extension availability checks into a shared utility and add unit tests for the new behaviors

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/plus/agents/agentRegistry.ts Moves Claude extension constants/availability check into a shared util and re-exports them for agent picking/dispatch.
src/env/node/providers.ts Wires a new callback to open sessions in the Claude Code extension from the host side.
src/agents/utils/claudeSessionFile.ts Adds Claude session metadata parsing + host classification helper.
src/agents/utils/-webview/claudeExtension.ts Centralizes Claude extension IDs/commands and availability detection.
src/agents/utils/tests/claudeSessionFile.test.ts Adds unit tests for host classification (missing/malformed/stale/entrypoint variants).
src/agents/agentStatusService.ts Replaces action quickpick with deterministic dispatch logic (extension/terminal/peer+openFolder).
packages/plus/agents/src/types.ts Extends provider/callback contracts for peer session open + host-triggered extension open.
packages/plus/agents/src/providers/claudeCodeProvider.ts Adds agents/sessions/open IPC handler and implements notifyPeerOpenSession to contact peers.
packages/plus/agents/src/tests/claudeCodeProvider.test.ts Adds tests for the new IPC handler and peer notification behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/agents/agentStatusService.ts Outdated
Comment thread src/agents/agentStatusService.ts Outdated
- Routes session opens deterministically by host: extension-hosted (entrypoint=claude-vscode) opens in the Claude Code extension, CLI-hosted focuses the owning terminal window, out-of-workspace asks a peer GitLens window to pre-open the session then switches the folder
- Adds an `agents/sessions/open` IPC route so a peer window can open a session in its Claude Code extension on behalf of the current window; caps the peer-notify wait at 500ms so an unhealthy peer can't stall the click
- Reads `~/.claude/sessions/<pid>.json` for the `entrypoint` field to classify the host, with a stale-file guard (pid mismatch returns undefined) and a sensible fallback when the file is missing
@ianhattendorf ianhattendorf force-pushed the agent-smart-quickpick branch from eb310f3 to 32a709d Compare May 20, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants