refactor(athena): rename session_handoff to switch_agent to avoid confusion with /handoff command
Rename across all layers to eliminate naming ambiguity: - Tool: session_handoff → switch_agent - Hook: agent-handoff → agent-switch - Feature: agent-handoff/ → agent-switch/ - Types: SessionHandoffArgs → SwitchAgentArgs, PendingHandoff → PendingSwitch - Functions: setPendingHandoff → setPendingSwitch, consumePendingHandoff → consumePendingSwitch /handoff = inter-session context summary (existing command) switch_agent = intra-session active agent change (our new tool)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
import { consumePendingSwitch } from "../../features/agent-switch"
|
||||
import { log } from "../../shared/logger"
|
||||
|
||||
const HOOK_NAME = "agent-switch" as const
|
||||
|
||||
export function createAgentSwitchHook(ctx: PluginInput) {
|
||||
return {
|
||||
event: async (input: { event: { type: string; properties?: Record<string, unknown> } }): Promise<void> => {
|
||||
if (input.event.type !== "session.idle") return
|
||||
|
||||
const props = input.event.properties as Record<string, unknown> | undefined
|
||||
const sessionID = props?.sessionID as string | undefined
|
||||
if (!sessionID) return
|
||||
|
||||
const pending = consumePendingSwitch(sessionID)
|
||||
if (!pending) return
|
||||
|
||||
log(`[${HOOK_NAME}] Switching to ${pending.agent}`, { sessionID })
|
||||
|
||||
try {
|
||||
await ctx.client.session.promptAsync({
|
||||
path: { id: sessionID },
|
||||
body: {
|
||||
agent: pending.agent,
|
||||
parts: [{ type: "text", text: pending.context }],
|
||||
},
|
||||
query: { directory: ctx.directory },
|
||||
})
|
||||
|
||||
log(`[${HOOK_NAME}] Switch to ${pending.agent} complete`, { sessionID })
|
||||
} catch (err) {
|
||||
log(`[${HOOK_NAME}] Switch failed`, { sessionID, error: String(err) })
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { createAgentSwitchHook } from "./hook"
|
||||
Reference in New Issue
Block a user