fix(agent-switch): make handoff durable and sync CLI TUI selection

This commit is contained in:
ismeth
2026-02-18 19:26:33 +01:00
committed by YeonGyu-Kim
parent 4764d65db1
commit 8de10c1f2b
17 changed files with 1698 additions and 35 deletions
+25 -1
View File
@@ -1,5 +1,6 @@
import { tool, type ToolDefinition } from "@opencode-ai/plugin"
import { setPendingSwitch } from "../../features/agent-switch"
import { schedulePendingSwitchApply } from "../../features/agent-switch/scheduler"
import { updateSessionAgent } from "../../features/claude-code-session-state"
import type { SwitchAgentArgs } from "./types"
@@ -10,7 +11,26 @@ const DESCRIPTION =
const ALLOWED_AGENTS = new Set(["atlas", "prometheus", "sisyphus", "hephaestus"])
export function createSwitchAgentTool(): ToolDefinition {
type SessionClient = {
session: {
prompt?: (input: {
path: { id: string }
body: { agent: string; parts: Array<{ type: "text"; text: string }> }
}) => Promise<unknown>
promptAsync: (input: {
path: { id: string }
body: { agent: string; parts: Array<{ type: "text"; text: string }> }
}) => Promise<unknown>
messages: (input: { path: { id: string } }) => Promise<unknown>
status?: () => Promise<unknown>
}
}
export function createSwitchAgentTool(args: {
client: SessionClient
}): ToolDefinition {
const { client } = args
return tool({
description: DESCRIPTION,
args: {
@@ -30,6 +50,10 @@ export function createSwitchAgentTool(): ToolDefinition {
updateSessionAgent(toolContext.sessionID, agentName)
setPendingSwitch(toolContext.sessionID, agentName, args.context)
schedulePendingSwitchApply({
sessionID: toolContext.sessionID,
client,
})
return `Agent switch queued. Session will switch to ${agentName} when your turn completes.`
},