diff --git a/src/cli/App.tsx b/src/cli/App.tsx index 025c8b2..bbec37a 100644 --- a/src/cli/App.tsx +++ b/src/cli/App.tsx @@ -1255,6 +1255,52 @@ export default function App({ return { submitted: true }; } + // Special handling for /download command - download agent file + if (msg.trim() === "/download") { + const cmdId = uid("cmd"); + buffersRef.current.byId.set(cmdId, { + kind: "command", + id: cmdId, + input: msg, + output: "Downloading agent file...", + phase: "running", + }); + buffersRef.current.order.push(cmdId); + refreshDerived(); + + setCommandRunning(true); + + try { + const client = await getClient(); + const fileContent = await client.agents.exportFile(agentId); + const fileName = `${agentId}.af`; + await Bun.write(fileName, JSON.stringify(fileContent, null, 2)); + + buffersRef.current.byId.set(cmdId, { + kind: "command", + id: cmdId, + input: msg, + output: `AgentFile downloaded to ${fileName}`, + phase: "finished", + success: true, + }); + refreshDerived(); + } catch (error) { + buffersRef.current.byId.set(cmdId, { + kind: "command", + id: cmdId, + input: msg, + output: `Failed: ${error instanceof Error ? error.message : String(error)}`, + phase: "finished", + success: false, + }); + refreshDerived(); + } finally { + setCommandRunning(false); + } + return { submitted: true }; + } + // Immediately add command to transcript with "running" phase const cmdId = uid("cmd"); buffersRef.current.byId.set(cmdId, { diff --git a/src/cli/commands/registry.ts b/src/cli/commands/registry.ts index cf963f5..5bb15b4 100644 --- a/src/cli/commands/registry.ts +++ b/src/cli/commands/registry.ts @@ -85,6 +85,13 @@ export const commands: Record = { return "Opening toolset selector..."; }, }, + "/download": { + desc: "Download agent file locally", + handler: () => { + // Handled specially in App.tsx to access agent ID and client + return "Downloading agent file..."; + }, + }, }; /**