summaryrefslogtreecommitdiffhomepage
path: root/packages/core/src/tools/retrieve.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-05-22 00:19:14 +0900
committerAdam Malczewski <[email protected]>2026-05-22 00:19:14 +0900
commitfb97d4cb72d0a90dde102b7001603716ee6e4c3b (patch)
tree55c6e8b56b3395008523ab94c16c4f526083d846 /packages/core/src/tools/retrieve.ts
parent7884709e3b2adb1b65c1c086257e0300eed51cee (diff)
downloaddispatch-fb97d4cb72d0a90dde102b7001603716ee6e4c3b.tar.gz
dispatch-fb97d4cb72d0a90dde102b7001603716ee6e4c3b.zip
feat: agent summoning system, todo improvements, security fixes, double-execution bug fix
- Add summon/retrieve tools for spawning child agents in new tabs - summon: non-blocking, returns agent_id immediately - retrieve: blocking, waits for child to finish, returns result - Child tools are intersected with parent permissions (no privilege escalation) - Working directory validated to stay within workspace - Abort controller stops orphaned agents on tab close - Rename task_list tool to todo with comprehensive usage guidance in system prompt - Rename PermissionLog.svelte to ToolPermissions.svelte - Add 'Summon agents' toggle to tool permissions UI - Redesign TaskListPanel with DaisyUI checkboxes (indeterminate for in-progress) - Remove 'blocked' status from task system - Add tab-created WebSocket event for child agent tab visibility - Add HMR cleanup for WebSocket connections (close stale connections on hot reload) - Fix ensureAssistantMessage to not throw on closed tabs - Fix double tool execution: remove execute from AI SDK tool() in registry.ts (agent.ts already executes tools manually via executeToolWithStreaming) - Fix all pre-existing test failures (missing mocks, stale API signatures) - Add debug info to copy button (tab ID, injected skills, all tab IDs) - Add tab ID and tools to conversation copy output
Diffstat (limited to 'packages/core/src/tools/retrieve.ts')
-rw-r--r--packages/core/src/tools/retrieve.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/packages/core/src/tools/retrieve.ts b/packages/core/src/tools/retrieve.ts
new file mode 100644
index 0000000..93f4c89
--- /dev/null
+++ b/packages/core/src/tools/retrieve.ts
@@ -0,0 +1,41 @@
+import { z } from "zod";
+import type { ToolDefinition } from "../types/index.js";
+
+export interface RetrieveCallbacks {
+ getResult(
+ agentId: string,
+ ): Promise<{ status: "done"; result: string } | { status: "error"; error: string }>;
+}
+
+export function createRetrieveTool(callbacks: RetrieveCallbacks): ToolDefinition {
+ return {
+ name: "retrieve",
+ description: [
+ "Wait for a child agent to finish and retrieve its result. This tool BLOCKS until the child completes.",
+ "",
+ "Pass the agent_id returned by the summon tool. Once the child finishes, its final output is returned.",
+ "If the child encountered an error, the error message is returned instead.",
+ "",
+ "Typical usage:",
+ ' 1. summon({ task: "...", tools: [...] }) -> get agent_id',
+ " 2. ... do other work or summon more agents ...",
+ ' 3. retrieve({ agent_id: "..." }) -> blocks until done, returns result',
+ ].join("\n"),
+ parameters: z.object({
+ agent_id: z.string().describe("The agent_id returned by a previous summon call."),
+ }),
+ execute: async (args: Record<string, unknown>): Promise<string> => {
+ const agentId = args.agent_id as string;
+
+ try {
+ const outcome = await callbacks.getResult(agentId);
+ if (outcome.status === "done") {
+ return ["<agent_result>", outcome.result, "</agent_result>"].join("\n");
+ }
+ return `Agent error: ${outcome.error}`;
+ } catch (err) {
+ return `Error retrieving result: ${err instanceof Error ? err.message : String(err)}`;
+ }
+ },
+ };
+}