tuplet 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (319) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +136 -0
  3. package/dist/agent.d.ts +46 -0
  4. package/dist/agent.d.ts.map +1 -0
  5. package/dist/agent.js +393 -0
  6. package/dist/agent.js.map +1 -0
  7. package/dist/built-in-agents/explore.d.ts +9 -0
  8. package/dist/built-in-agents/explore.d.ts.map +1 -0
  9. package/dist/built-in-agents/explore.js +40 -0
  10. package/dist/built-in-agents/explore.js.map +1 -0
  11. package/dist/built-in-agents/index.d.ts +15 -0
  12. package/dist/built-in-agents/index.d.ts.map +1 -0
  13. package/dist/built-in-agents/index.js +19 -0
  14. package/dist/built-in-agents/index.js.map +1 -0
  15. package/dist/built-in-agents/plan.d.ts +10 -0
  16. package/dist/built-in-agents/plan.d.ts.map +1 -0
  17. package/dist/built-in-agents/plan.js +62 -0
  18. package/dist/built-in-agents/plan.js.map +1 -0
  19. package/dist/built-in-agents/worker.d.ts +9 -0
  20. package/dist/built-in-agents/worker.d.ts.map +1 -0
  21. package/dist/built-in-agents/worker.js +53 -0
  22. package/dist/built-in-agents/worker.js.map +1 -0
  23. package/dist/constants.d.ts +7 -0
  24. package/dist/constants.d.ts.map +1 -0
  25. package/dist/constants.js +18 -0
  26. package/dist/constants.js.map +1 -0
  27. package/dist/context-manager.d.ts +65 -0
  28. package/dist/context-manager.d.ts.map +1 -0
  29. package/dist/context-manager.js +272 -0
  30. package/dist/context-manager.js.map +1 -0
  31. package/dist/context-manager.test.d.ts +2 -0
  32. package/dist/context-manager.test.d.ts.map +1 -0
  33. package/dist/context-manager.test.js +394 -0
  34. package/dist/context-manager.test.js.map +1 -0
  35. package/dist/executor.d.ts +29 -0
  36. package/dist/executor.d.ts.map +1 -0
  37. package/dist/executor.js +399 -0
  38. package/dist/executor.js.map +1 -0
  39. package/dist/index.d.ts +24 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +40 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/prompt/index.d.ts +9 -0
  44. package/dist/prompt/index.d.ts.map +1 -0
  45. package/dist/prompt/index.js +10 -0
  46. package/dist/prompt/index.js.map +1 -0
  47. package/dist/prompt/main-agent-builder.d.ts +81 -0
  48. package/dist/prompt/main-agent-builder.d.ts.map +1 -0
  49. package/dist/prompt/main-agent-builder.js +287 -0
  50. package/dist/prompt/main-agent-builder.js.map +1 -0
  51. package/dist/prompt/sub-agent-builder.d.ts +133 -0
  52. package/dist/prompt/sub-agent-builder.d.ts.map +1 -0
  53. package/dist/prompt/sub-agent-builder.js +337 -0
  54. package/dist/prompt/sub-agent-builder.js.map +1 -0
  55. package/dist/prompt/templates.d.ts +87 -0
  56. package/dist/prompt/templates.d.ts.map +1 -0
  57. package/dist/prompt/templates.js +343 -0
  58. package/dist/prompt/templates.js.map +1 -0
  59. package/dist/prompt/types.d.ts +159 -0
  60. package/dist/prompt/types.d.ts.map +1 -0
  61. package/dist/prompt/types.js +5 -0
  62. package/dist/prompt/types.js.map +1 -0
  63. package/dist/prompt.d.ts +32 -0
  64. package/dist/prompt.d.ts.map +1 -0
  65. package/dist/prompt.js +86 -0
  66. package/dist/prompt.js.map +1 -0
  67. package/dist/providers/dataset/base.d.ts +74 -0
  68. package/dist/providers/dataset/base.d.ts.map +1 -0
  69. package/dist/providers/dataset/base.js +7 -0
  70. package/dist/providers/dataset/base.js.map +1 -0
  71. package/dist/providers/dataset/index.d.ts +8 -0
  72. package/dist/providers/dataset/index.d.ts.map +1 -0
  73. package/dist/providers/dataset/index.js +8 -0
  74. package/dist/providers/dataset/index.js.map +1 -0
  75. package/dist/providers/dataset/recorder.d.ts +46 -0
  76. package/dist/providers/dataset/recorder.d.ts.map +1 -0
  77. package/dist/providers/dataset/recorder.js +105 -0
  78. package/dist/providers/dataset/recorder.js.map +1 -0
  79. package/dist/providers/dataset/replayer.d.ts +46 -0
  80. package/dist/providers/dataset/replayer.d.ts.map +1 -0
  81. package/dist/providers/dataset/replayer.js +163 -0
  82. package/dist/providers/dataset/replayer.js.map +1 -0
  83. package/dist/providers/dataset/tester.d.ts +89 -0
  84. package/dist/providers/dataset/tester.d.ts.map +1 -0
  85. package/dist/providers/dataset/tester.js +143 -0
  86. package/dist/providers/dataset/tester.js.map +1 -0
  87. package/dist/providers/env/memory.d.ts +14 -0
  88. package/dist/providers/env/memory.d.ts.map +1 -0
  89. package/dist/providers/env/memory.js +19 -0
  90. package/dist/providers/env/memory.js.map +1 -0
  91. package/dist/providers/index.d.ts +12 -0
  92. package/dist/providers/index.d.ts.map +1 -0
  93. package/dist/providers/index.js +10 -0
  94. package/dist/providers/index.js.map +1 -0
  95. package/dist/providers/llm/base.d.ts +7 -0
  96. package/dist/providers/llm/base.d.ts.map +1 -0
  97. package/dist/providers/llm/base.js +7 -0
  98. package/dist/providers/llm/base.js.map +1 -0
  99. package/dist/providers/llm/claude.d.ts +32 -0
  100. package/dist/providers/llm/claude.d.ts.map +1 -0
  101. package/dist/providers/llm/claude.js +171 -0
  102. package/dist/providers/llm/claude.js.map +1 -0
  103. package/dist/providers/llm/openai.d.ts +26 -0
  104. package/dist/providers/llm/openai.d.ts.map +1 -0
  105. package/dist/providers/llm/openai.js +174 -0
  106. package/dist/providers/llm/openai.js.map +1 -0
  107. package/dist/providers/llm/openrouter.d.ts +43 -0
  108. package/dist/providers/llm/openrouter.d.ts.map +1 -0
  109. package/dist/providers/llm/openrouter.js +288 -0
  110. package/dist/providers/llm/openrouter.js.map +1 -0
  111. package/dist/providers/logger/base.d.ts +7 -0
  112. package/dist/providers/logger/base.d.ts.map +1 -0
  113. package/dist/providers/logger/base.js +7 -0
  114. package/dist/providers/logger/base.js.map +1 -0
  115. package/dist/providers/logger/console.d.ts +29 -0
  116. package/dist/providers/logger/console.d.ts.map +1 -0
  117. package/dist/providers/logger/console.js +70 -0
  118. package/dist/providers/logger/console.js.map +1 -0
  119. package/dist/providers/repository/base.d.ts +7 -0
  120. package/dist/providers/repository/base.d.ts.map +1 -0
  121. package/dist/providers/repository/base.js +7 -0
  122. package/dist/providers/repository/base.js.map +1 -0
  123. package/dist/providers/repository/memory.d.ts +21 -0
  124. package/dist/providers/repository/memory.d.ts.map +1 -0
  125. package/dist/providers/repository/memory.js +50 -0
  126. package/dist/providers/repository/memory.js.map +1 -0
  127. package/dist/providers/workspace/file.d.ts +26 -0
  128. package/dist/providers/workspace/file.d.ts.map +1 -0
  129. package/dist/providers/workspace/file.js +151 -0
  130. package/dist/providers/workspace/file.js.map +1 -0
  131. package/dist/providers/workspace/index.d.ts +7 -0
  132. package/dist/providers/workspace/index.d.ts.map +1 -0
  133. package/dist/providers/workspace/index.js +6 -0
  134. package/dist/providers/workspace/index.js.map +1 -0
  135. package/dist/providers/workspace/memory.d.ts +26 -0
  136. package/dist/providers/workspace/memory.d.ts.map +1 -0
  137. package/dist/providers/workspace/memory.js +136 -0
  138. package/dist/providers/workspace/memory.js.map +1 -0
  139. package/dist/providers/workspace/types.d.ts +27 -0
  140. package/dist/providers/workspace/types.d.ts.map +1 -0
  141. package/dist/providers/workspace/types.js +8 -0
  142. package/dist/providers/workspace/types.js.map +1 -0
  143. package/dist/providers/workspace/workspace-provider.test.d.ts +2 -0
  144. package/dist/providers/workspace/workspace-provider.test.d.ts.map +1 -0
  145. package/dist/providers/workspace/workspace-provider.test.js +250 -0
  146. package/dist/providers/workspace/workspace-provider.test.js.map +1 -0
  147. package/dist/shell/commands/browse.d.ts +6 -0
  148. package/dist/shell/commands/browse.d.ts.map +1 -0
  149. package/dist/shell/commands/browse.js +158 -0
  150. package/dist/shell/commands/browse.js.map +1 -0
  151. package/dist/shell/commands/cat.d.ts +6 -0
  152. package/dist/shell/commands/cat.d.ts.map +1 -0
  153. package/dist/shell/commands/cat.js +104 -0
  154. package/dist/shell/commands/cat.js.map +1 -0
  155. package/dist/shell/commands/curl.d.ts +6 -0
  156. package/dist/shell/commands/curl.d.ts.map +1 -0
  157. package/dist/shell/commands/curl.js +190 -0
  158. package/dist/shell/commands/curl.js.map +1 -0
  159. package/dist/shell/commands/date.d.ts +6 -0
  160. package/dist/shell/commands/date.d.ts.map +1 -0
  161. package/dist/shell/commands/date.js +151 -0
  162. package/dist/shell/commands/date.js.map +1 -0
  163. package/dist/shell/commands/echo.d.ts +6 -0
  164. package/dist/shell/commands/echo.d.ts.map +1 -0
  165. package/dist/shell/commands/echo.js +48 -0
  166. package/dist/shell/commands/echo.js.map +1 -0
  167. package/dist/shell/commands/env.d.ts +8 -0
  168. package/dist/shell/commands/env.d.ts.map +1 -0
  169. package/dist/shell/commands/env.js +41 -0
  170. package/dist/shell/commands/env.js.map +1 -0
  171. package/dist/shell/commands/file.d.ts +6 -0
  172. package/dist/shell/commands/file.d.ts.map +1 -0
  173. package/dist/shell/commands/file.js +213 -0
  174. package/dist/shell/commands/file.js.map +1 -0
  175. package/dist/shell/commands/find.d.ts +6 -0
  176. package/dist/shell/commands/find.d.ts.map +1 -0
  177. package/dist/shell/commands/find.js +100 -0
  178. package/dist/shell/commands/find.js.map +1 -0
  179. package/dist/shell/commands/grep.d.ts +6 -0
  180. package/dist/shell/commands/grep.d.ts.map +1 -0
  181. package/dist/shell/commands/grep.js +229 -0
  182. package/dist/shell/commands/grep.js.map +1 -0
  183. package/dist/shell/commands/head.d.ts +6 -0
  184. package/dist/shell/commands/head.d.ts.map +1 -0
  185. package/dist/shell/commands/head.js +88 -0
  186. package/dist/shell/commands/head.js.map +1 -0
  187. package/dist/shell/commands/index.d.ts +25 -0
  188. package/dist/shell/commands/index.d.ts.map +1 -0
  189. package/dist/shell/commands/index.js +43 -0
  190. package/dist/shell/commands/index.js.map +1 -0
  191. package/dist/shell/commands/jq.d.ts +8 -0
  192. package/dist/shell/commands/jq.d.ts.map +1 -0
  193. package/dist/shell/commands/jq.js +233 -0
  194. package/dist/shell/commands/jq.js.map +1 -0
  195. package/dist/shell/commands/ls.d.ts +6 -0
  196. package/dist/shell/commands/ls.d.ts.map +1 -0
  197. package/dist/shell/commands/ls.js +88 -0
  198. package/dist/shell/commands/ls.js.map +1 -0
  199. package/dist/shell/commands/mkdir.d.ts +6 -0
  200. package/dist/shell/commands/mkdir.d.ts.map +1 -0
  201. package/dist/shell/commands/mkdir.js +43 -0
  202. package/dist/shell/commands/mkdir.js.map +1 -0
  203. package/dist/shell/commands/rm.d.ts +6 -0
  204. package/dist/shell/commands/rm.d.ts.map +1 -0
  205. package/dist/shell/commands/rm.js +64 -0
  206. package/dist/shell/commands/rm.js.map +1 -0
  207. package/dist/shell/commands/sed.d.ts +6 -0
  208. package/dist/shell/commands/sed.d.ts.map +1 -0
  209. package/dist/shell/commands/sed.js +414 -0
  210. package/dist/shell/commands/sed.js.map +1 -0
  211. package/dist/shell/commands/sort.d.ts +6 -0
  212. package/dist/shell/commands/sort.d.ts.map +1 -0
  213. package/dist/shell/commands/sort.js +109 -0
  214. package/dist/shell/commands/sort.js.map +1 -0
  215. package/dist/shell/commands/tail.d.ts +6 -0
  216. package/dist/shell/commands/tail.d.ts.map +1 -0
  217. package/dist/shell/commands/tail.js +68 -0
  218. package/dist/shell/commands/tail.js.map +1 -0
  219. package/dist/shell/commands/wc.d.ts +6 -0
  220. package/dist/shell/commands/wc.d.ts.map +1 -0
  221. package/dist/shell/commands/wc.js +86 -0
  222. package/dist/shell/commands/wc.js.map +1 -0
  223. package/dist/shell/index.d.ts +10 -0
  224. package/dist/shell/index.d.ts.map +1 -0
  225. package/dist/shell/index.js +10 -0
  226. package/dist/shell/index.js.map +1 -0
  227. package/dist/shell/limits.d.ts +5 -0
  228. package/dist/shell/limits.d.ts.map +1 -0
  229. package/dist/shell/limits.js +5 -0
  230. package/dist/shell/limits.js.map +1 -0
  231. package/dist/shell/parser.d.ts +8 -0
  232. package/dist/shell/parser.d.ts.map +1 -0
  233. package/dist/shell/parser.js +307 -0
  234. package/dist/shell/parser.js.map +1 -0
  235. package/dist/shell/path-validation.d.ts +35 -0
  236. package/dist/shell/path-validation.d.ts.map +1 -0
  237. package/dist/shell/path-validation.js +81 -0
  238. package/dist/shell/path-validation.js.map +1 -0
  239. package/dist/shell/shell.d.ts +66 -0
  240. package/dist/shell/shell.d.ts.map +1 -0
  241. package/dist/shell/shell.js +301 -0
  242. package/dist/shell/shell.js.map +1 -0
  243. package/dist/shell/shell.test.d.ts +2 -0
  244. package/dist/shell/shell.test.d.ts.map +1 -0
  245. package/dist/shell/shell.test.js +1088 -0
  246. package/dist/shell/shell.test.js.map +1 -0
  247. package/dist/shell/types.d.ts +82 -0
  248. package/dist/shell/types.d.ts.map +1 -0
  249. package/dist/shell/types.js +5 -0
  250. package/dist/shell/types.js.map +1 -0
  251. package/dist/summarizer.d.ts +28 -0
  252. package/dist/summarizer.d.ts.map +1 -0
  253. package/dist/summarizer.js +136 -0
  254. package/dist/summarizer.js.map +1 -0
  255. package/dist/summarizer.test.d.ts +2 -0
  256. package/dist/summarizer.test.d.ts.map +1 -0
  257. package/dist/summarizer.test.js +192 -0
  258. package/dist/summarizer.test.js.map +1 -0
  259. package/dist/tools/ask-user.d.ts +11 -0
  260. package/dist/tools/ask-user.d.ts.map +1 -0
  261. package/dist/tools/ask-user.js +35 -0
  262. package/dist/tools/ask-user.js.map +1 -0
  263. package/dist/tools/index.d.ts +11 -0
  264. package/dist/tools/index.d.ts.map +1 -0
  265. package/dist/tools/index.js +18 -0
  266. package/dist/tools/index.js.map +1 -0
  267. package/dist/tools/output.d.ts +15 -0
  268. package/dist/tools/output.d.ts.map +1 -0
  269. package/dist/tools/output.js +40 -0
  270. package/dist/tools/output.js.map +1 -0
  271. package/dist/tools/shell.d.ts +13 -0
  272. package/dist/tools/shell.d.ts.map +1 -0
  273. package/dist/tools/shell.js +166 -0
  274. package/dist/tools/shell.js.map +1 -0
  275. package/dist/tools/sub-agent.d.ts +25 -0
  276. package/dist/tools/sub-agent.d.ts.map +1 -0
  277. package/dist/tools/sub-agent.js +312 -0
  278. package/dist/tools/sub-agent.js.map +1 -0
  279. package/dist/tools/tasks.d.ts +170 -0
  280. package/dist/tools/tasks.d.ts.map +1 -0
  281. package/dist/tools/tasks.js +947 -0
  282. package/dist/tools/tasks.js.map +1 -0
  283. package/dist/trace/builder.d.ts +54 -0
  284. package/dist/trace/builder.d.ts.map +1 -0
  285. package/dist/trace/builder.js +229 -0
  286. package/dist/trace/builder.js.map +1 -0
  287. package/dist/trace/console.d.ts +45 -0
  288. package/dist/trace/console.d.ts.map +1 -0
  289. package/dist/trace/console.js +143 -0
  290. package/dist/trace/console.js.map +1 -0
  291. package/dist/trace/index.d.ts +11 -0
  292. package/dist/trace/index.d.ts.map +1 -0
  293. package/dist/trace/index.js +11 -0
  294. package/dist/trace/index.js.map +1 -0
  295. package/dist/trace/openrouter-pricing.d.ts +9 -0
  296. package/dist/trace/openrouter-pricing.d.ts.map +1 -0
  297. package/dist/trace/openrouter-pricing.js +321 -0
  298. package/dist/trace/openrouter-pricing.js.map +1 -0
  299. package/dist/trace/pricing.d.ts +13 -0
  300. package/dist/trace/pricing.d.ts.map +1 -0
  301. package/dist/trace/pricing.js +41 -0
  302. package/dist/trace/pricing.js.map +1 -0
  303. package/dist/trace/types.d.ts +142 -0
  304. package/dist/trace/types.d.ts.map +1 -0
  305. package/dist/trace/types.js +16 -0
  306. package/dist/trace/types.js.map +1 -0
  307. package/dist/trace.d.ts +5 -0
  308. package/dist/trace.d.ts.map +1 -0
  309. package/dist/trace.js +5 -0
  310. package/dist/trace.js.map +1 -0
  311. package/dist/types.d.ts +382 -0
  312. package/dist/types.d.ts.map +1 -0
  313. package/dist/types.js +5 -0
  314. package/dist/types.js.map +1 -0
  315. package/dist/workspace.d.ts +287 -0
  316. package/dist/workspace.d.ts.map +1 -0
  317. package/dist/workspace.js +560 -0
  318. package/dist/workspace.js.map +1 -0
  319. package/package.json +47 -0
@@ -0,0 +1,312 @@
1
+ /**
2
+ * Task Tool
3
+ *
4
+ * Tool for spawning sub-agents to handle complex operations.
5
+ */
6
+ import { OUTPUT_TOOL_NAME, createOutputTool } from "./output.js";
7
+ /**
8
+ * Build description for agent in __sub_agent__ tool
9
+ */
10
+ function buildAgentDescription(agent) {
11
+ let desc = `- **${agent.name}**: ${agent.description}`;
12
+ if (agent.inputSchema?.properties) {
13
+ const props = agent.inputSchema.properties;
14
+ const paramList = Object.entries(props)
15
+ .map(([name, schema]) => `${name}: ${schema.description || schema.type || "any"}`)
16
+ .join(", ");
17
+ desc += `\n Parameters: { ${paramList} }`;
18
+ }
19
+ if (agent.outputSchema) {
20
+ desc += `\n Returns: structured data (summary + data object)`;
21
+ }
22
+ const toolNames = [
23
+ ...agent.tools.map((t) => t.name),
24
+ ...(agent.builtInToolNames || []),
25
+ ];
26
+ desc += `\n Tools: ${toolNames.length > 0 ? toolNames.join(", ") : "none"}`;
27
+ return desc;
28
+ }
29
+ /**
30
+ * Create a wrapper logger that prefixes sub-agent logs
31
+ */
32
+ function createSubLogger(parentLogger, agentName) {
33
+ if (!parentLogger)
34
+ return undefined;
35
+ return {
36
+ ...parentLogger,
37
+ debug: (msg, data) => parentLogger.debug?.(`[${agentName}] ${msg}`, data),
38
+ info: (msg, data) => parentLogger.info?.(`[${agentName}] ${msg}`, data),
39
+ warn: (msg, data) => parentLogger.warn?.(`[${agentName}] ${msg}`, data),
40
+ error: (msg, data) => parentLogger.error?.(`[${agentName}] ${msg}`, data),
41
+ onToolCall: (toolName, toolParams) => {
42
+ parentLogger.info?.(`[${agentName}] Tool: ${toolName}`);
43
+ parentLogger.onToolCall?.(toolName, toolParams);
44
+ },
45
+ onToolResult: (toolName, result, durationMs) => {
46
+ const status = result.success ? "OK" : "ERROR";
47
+ parentLogger.info?.(`[${agentName}] Tool ${toolName}: ${status} (${durationMs}ms)`);
48
+ parentLogger.onToolResult?.(toolName, result, durationMs);
49
+ },
50
+ onProgress: (update) => {
51
+ // Prefix sub-agent progress messages
52
+ parentLogger.onProgress?.({
53
+ ...update,
54
+ message: `[${agentName}] ${update.message}`,
55
+ });
56
+ },
57
+ onTodoUpdate: (update) => {
58
+ // Forward sub-agent todo updates with agent name set
59
+ parentLogger.onTodoUpdate?.({
60
+ ...update,
61
+ agentName: agentName,
62
+ });
63
+ },
64
+ };
65
+ }
66
+ /**
67
+ * Create the __sub_agent__ tool for spawning sub-agents
68
+ */
69
+ export function createTaskTool(context, agents, createSubTuplet) {
70
+ const agentNames = agents.map((a) => a.name);
71
+ const agentDescriptions = agents.map(buildAgentDescription).join("\n");
72
+ // Build combined properties from all agents
73
+ // Runtime validation will check agent-specific requirements
74
+ const combinedProperties = {
75
+ agent: {
76
+ type: "string",
77
+ enum: agentNames,
78
+ description: "Which agent to spawn",
79
+ },
80
+ };
81
+ // Add properties from all agent inputSchemas
82
+ for (const agent of agents) {
83
+ if (agent.inputSchema?.properties) {
84
+ const props = agent.inputSchema.properties;
85
+ for (const [key, schema] of Object.entries(props)) {
86
+ if (!combinedProperties[key]) {
87
+ combinedProperties[key] = {
88
+ type: schema.type || "string",
89
+ description: `[${agent.name}] ${schema.description || ""}`,
90
+ };
91
+ }
92
+ }
93
+ }
94
+ }
95
+ const toolName = "__sub_agent__";
96
+ return {
97
+ name: toolName,
98
+ description: `The ${toolName} tool activates specialized agents designed to autonomously execute complex operations. Each agent variant possesses distinct capabilities and has access to specific tools.
99
+
100
+ Agent types available and their associated tools:
101
+ ${agentDescriptions}
102
+
103
+ When invoking the ${toolName} tool, you must provide a subagent_type parameter to designate which agent variant to utilize.
104
+
105
+ Key considerations:
106
+ - Include a brief description (3-5 words) that summarizes the agent's objective
107
+ - Upon completion, the agent returns a single message to you. This result is not displayed to the user. To share the outcome with the user, send a text message containing a concise summary of what was accomplished.
108
+ - Upon completion, the agent provides both a message and its agent ID. You can leverage this ID to reactivate the agent for subsequent related work.
109
+ - Act as a lead: provide each agent with a clear brief — what to accomplish, relevant context from your exploration, constraints, and how to verify success. Structured input produces better results than vague instructions.
110
+ - Agents marked as having "access to current context" can view the complete conversation history preceding the tool invocation. With these agents, you can write abbreviated prompts that reference prior context (e.g., "analyze the issue mentioned earlier") rather than duplicating information. The agent receives all previous messages and comprehends the context.
111
+ - Generally, trust the agent's output
112
+ - Explicitly inform the agent whether it should create content or conduct research (searching, reading documents, fetching information, etc.), as it cannot infer the user's intentions
113
+ - If an agent description indicates it should be utilized proactively, attempt to deploy it without waiting for an explicit user request. Apply discretion.
114
+
115
+ Example usage:
116
+
117
+ <example_agent_descriptions>
118
+ "travel-planner": deploy this agent after gathering the user's travel preferences and requirements
119
+ "welcome-handler": deploy this agent to reply to user greetings with an amusing quip
120
+ </example_agent_description>
121
+
122
+ <example>
123
+ user: "I need help planning a 5-day trip to Tokyo in spring. I love art museums and local cuisine."
124
+ assistant: I'll help you plan a comprehensive Tokyo itinerary
125
+ assistant: First, let me gather information about spring activities and create a day-by-day plan
126
+ assistant: I'm creating the following itinerary outline:
127
+ <plan>
128
+ Day 1: Arrival and Shibuya exploration
129
+ Day 2: Ueno Park museums (Tokyo National Museum, National Museum of Western Art)
130
+ Day 3: TeamLab Borderless, Odaiba waterfront
131
+ Day 4: Tsukiji Outer Market food tour, Ginza art galleries
132
+ Day 5: Meiji Shrine, Harajuku, departure preparation
133
+ </plan>
134
+ <commentary>
135
+ Since a detailed travel plan has been created, now deploy the travel-planner agent to add specific restaurant recommendations, booking details, and transportation information
136
+ </commentary>
137
+ assistant: Let me now employ the travel-planner agent to enhance this itinerary with detailed logistics
138
+ assistant: Invokes the __sub_agent__ tool to activate the travel-planner agent
139
+ </example>
140
+
141
+ <example>
142
+ user: "Hello"
143
+ <commentary>
144
+ The user has initiated a greeting, so deploy the welcome-handler agent to provide a friendly response
145
+ </commentary>
146
+ assistant: "I'll invoke the __sub_agent__ tool to activate the welcome-handler agent"
147
+ </example>
148
+ `,
149
+ parameters: {
150
+ type: "object",
151
+ properties: combinedProperties,
152
+ required: ["agent"],
153
+ },
154
+ execute: async (params, toolCtx) => {
155
+ const { agent: agentName, ...inputParams } = params;
156
+ const agentConfig = agents.find((a) => a.name === agentName);
157
+ if (!agentConfig) {
158
+ return { success: false, error: `Unknown agent: ${agentName}` };
159
+ }
160
+ // Build the input message for the sub-agent
161
+ const inputMessage = `Task parameters:\n${JSON.stringify(inputParams, null, 2)}`;
162
+ // Log sub-agent start
163
+ context.config.logger?.info(`[Sub-Agent: ${agentName}] Starting...`);
164
+ context.config.logger?.debug(`[Sub-Agent: ${agentName}] Input: ${inputMessage.slice(0, 200)}${inputMessage.length > 200 ? "..." : ""}`);
165
+ // Progress: sub-agent starting
166
+ context.config.logger?.onProgress?.({
167
+ type: "sub_agent_start",
168
+ message: `Starting ${agentName}...`,
169
+ details: { agentName },
170
+ });
171
+ try {
172
+ // Create a wrapper logger that prefixes sub-agent logs
173
+ const subLogger = createSubLogger(context.config.logger, agentName);
174
+ // Use agent-specific LLM/model or fall back to parent's
175
+ const subLlm = agentConfig.llm || context.config.llm;
176
+ // Build sub-agent tools - include __output__ if outputSchema is defined
177
+ const subTools = agentConfig.outputSchema
178
+ ? [...agentConfig.tools, createOutputTool(agentConfig.outputSchema)]
179
+ : agentConfig.tools;
180
+ // Get parent's trace builder for nested tracing
181
+ const parentTraceBuilder = context.getCurrentTraceBuilder();
182
+ // Start sub-agent span in trace
183
+ if (parentTraceBuilder) {
184
+ parentTraceBuilder.startSubAgent(agentName, inputMessage);
185
+ }
186
+ const subTuplet = createSubTuplet({
187
+ role: agentConfig.name,
188
+ _systemPrompt: `Today's date is ${new Date().toISOString().split('T')[0]}.\n\n${agentConfig.systemPrompt}`,
189
+ tools: subTools,
190
+ llm: subLlm,
191
+ logger: subLogger,
192
+ maxIterations: agentConfig.maxIterations || context.config.maxIterations,
193
+ disableAskUser: agentConfig.disableAskUser ?? false,
194
+ // Pass parent's trace config for nested sub-agents
195
+ trace: context.config.trace,
196
+ agentName: agentName,
197
+ // Prevent recursive agent injection — sub-agents don't get their own sub-agents
198
+ agents: [],
199
+ });
200
+ const result = await subTuplet.run(inputMessage, {
201
+ // Pass trace builder for nested tracing
202
+ _traceBuilder: parentTraceBuilder,
203
+ // Pass workspace to sub-agent so its tools receive the same workspace
204
+ conversationId: toolCtx.conversationId,
205
+ userId: toolCtx.userId,
206
+ // Pass workspace so sub-agent can read/write to same workspace
207
+ workspace: toolCtx.workspace,
208
+ });
209
+ // End sub-agent span in trace
210
+ if (parentTraceBuilder) {
211
+ const status = result.status === "complete"
212
+ ? "complete"
213
+ : result.status === "interrupted"
214
+ ? "interrupted"
215
+ : "error";
216
+ parentTraceBuilder.endSubAgent(status, result.response);
217
+ }
218
+ // Log sub-agent completion with details
219
+ context.config.logger?.info(`[Sub-Agent: ${agentName}] Completed with status: ${result.status}`);
220
+ context.config.logger?.debug(`[Sub-Agent: ${agentName}] Tool calls: ${result.toolCalls.length}`, result.toolCalls.map((tc) => tc.name));
221
+ context.config.logger?.debug(`[Sub-Agent: ${agentName}] Response length: ${result.response?.length || 0}`);
222
+ if (result.response) {
223
+ context.config.logger?.debug(`[Sub-Agent: ${agentName}] Response preview: ${result.response.slice(0, 200)}${result.response.length > 200 ? "..." : ""}`);
224
+ }
225
+ if (result.thinking && result.thinking.length > 0) {
226
+ context.config.logger?.debug(`[Sub-Agent: ${agentName}] Thinking blocks: ${result.thinking.length}`);
227
+ }
228
+ // Progress: sub-agent completed
229
+ context.config.logger?.onProgress?.({
230
+ type: "sub_agent_end",
231
+ message: `${agentName} completed`,
232
+ details: { agentName, success: true },
233
+ });
234
+ if (result.status === "needs_input") {
235
+ context.config.logger?.debug(`[Sub-Agent: ${agentName}] Returning: needs_input`);
236
+ return {
237
+ success: false,
238
+ error: "Sub-agent needs user input",
239
+ data: result.pendingQuestion,
240
+ };
241
+ }
242
+ if (result.status === "interrupted") {
243
+ context.config.logger?.warn(`[Sub-Agent: ${agentName}] Was interrupted: ${result.interrupted?.reason}`);
244
+ // Include the agent's last response so the caller can see what was accomplished
245
+ const agentResponse = result.response || '';
246
+ const hasResponse = agentResponse.length > 0;
247
+ return {
248
+ success: hasResponse,
249
+ error: hasResponse
250
+ ? `Sub-agent reached iteration limit but produced output`
251
+ : `Sub-agent was interrupted: ${result.interrupted?.reason || "unknown"}`,
252
+ data: {
253
+ reason: result.interrupted?.reason,
254
+ iterationsCompleted: result.interrupted?.iterationsCompleted,
255
+ summary: agentResponse || null,
256
+ },
257
+ };
258
+ }
259
+ // Check if sub-agent used __output__ tool to return structured data
260
+ const outputCall = result.toolCalls.find((tc) => tc.name === OUTPUT_TOOL_NAME);
261
+ context.config.logger?.debug(`[Sub-Agent: ${agentName}] __output__ tool used: ${!!outputCall}`);
262
+ if (outputCall &&
263
+ outputCall.output?.success &&
264
+ outputCall.output?.data) {
265
+ const outputData = outputCall.output.data;
266
+ context.config.logger?.debug(`[Sub-Agent: ${agentName}] Returning structured output`, {
267
+ summaryLength: outputData.summary?.length || 0,
268
+ hasData: outputData.data !== null && outputData.data !== undefined,
269
+ });
270
+ return {
271
+ success: true,
272
+ data: {
273
+ summary: outputData.summary,
274
+ data: outputData.data,
275
+ },
276
+ };
277
+ }
278
+ // Fallback: return response text as summary when __output__ tool wasn't used
279
+ context.config.logger?.debug(`[Sub-Agent: ${agentName}] Returning text response (no __output__ tool used)`, {
280
+ responseLength: result.response?.length || 0,
281
+ isEmpty: !result.response,
282
+ });
283
+ return {
284
+ success: true,
285
+ data: {
286
+ summary: result.response,
287
+ data: null,
288
+ },
289
+ };
290
+ }
291
+ catch (error) {
292
+ // End sub-agent span with error status
293
+ const parentTraceBuilder = context.getCurrentTraceBuilder();
294
+ if (parentTraceBuilder) {
295
+ parentTraceBuilder.endSubAgent("error");
296
+ }
297
+ context.config.logger?.error(`[Sub-Agent: ${agentName}] Failed: ${error instanceof Error ? error.message : String(error)}`);
298
+ // Progress: sub-agent failed
299
+ context.config.logger?.onProgress?.({
300
+ type: "sub_agent_end",
301
+ message: `${agentName} failed`,
302
+ details: { agentName, success: false },
303
+ });
304
+ return {
305
+ success: false,
306
+ error: error instanceof Error ? error.message : String(error),
307
+ };
308
+ }
309
+ },
310
+ };
311
+ }
312
+ //# sourceMappingURL=sub-agent.js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,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;iBAC9D,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Task Management System (Claude Code 4-Tool Approach)
3
+ *
4
+ * Provides task management functionality for agents to track and execute tasks.
5
+ * Uses 4 separate tools: TaskCreate, TaskUpdate, TaskGet, TaskList
6
+ */
7
+ import type { Tool, TaskItem, TaskStatus, LogProvider, TaskProgress, TodoItem } from "../types.js";
8
+ import type { Workspace } from "../workspace.js";
9
+ /** Serialized task state for persistence */
10
+ interface TaskManagerState {
11
+ items: TaskItem[];
12
+ currentTaskId?: string;
13
+ nextId: number;
14
+ }
15
+ /**
16
+ * Format task list for display
17
+ * @param tasks - Array of tasks to format
18
+ * @param allTasks - Optional full task list (for checking blocker status). If not provided, blockedBy status won't be resolved.
19
+ */
20
+ export declare function formatTaskList(tasks: TaskItem[], allTasks?: TaskItem[]): string;
21
+ /** @deprecated Use formatTaskList instead */
22
+ export declare function formatTodoList(todos: TodoItem[]): string;
23
+ /**
24
+ * TaskManager class for tracking tasks during execution
25
+ */
26
+ export declare class TaskManager {
27
+ private items;
28
+ private currentTaskId?;
29
+ private nextId;
30
+ /**
31
+ * Get all task items
32
+ */
33
+ getAll(): TaskItem[];
34
+ /**
35
+ * Get a task by ID
36
+ */
37
+ get(id: string): TaskItem | undefined;
38
+ /**
39
+ * Get current task being worked on
40
+ */
41
+ getCurrentTask(): TaskItem | undefined;
42
+ /**
43
+ * Check if a task is blocked (has unresolved blockers)
44
+ */
45
+ isBlocked(task: TaskItem): boolean;
46
+ /**
47
+ * Get open (unresolved) blockers for a task
48
+ */
49
+ getOpenBlockers(task: TaskItem): string[];
50
+ /**
51
+ * Create a new task
52
+ * If this is the first task and no tasks are in_progress, auto-starts it (if not blocked)
53
+ */
54
+ create(subject: string, description?: string, activeForm?: string, metadata?: Record<string, unknown>): TaskItem;
55
+ /**
56
+ * Update a task
57
+ * Returns the updated task or undefined if not found
58
+ */
59
+ update(id: string, updates: {
60
+ subject?: string;
61
+ description?: string;
62
+ activeForm?: string;
63
+ status?: TaskStatus | 'deleted';
64
+ owner?: string;
65
+ metadata?: Record<string, unknown>;
66
+ addBlocks?: string[];
67
+ addBlockedBy?: string[];
68
+ comment?: {
69
+ author: string;
70
+ content: string;
71
+ };
72
+ }): {
73
+ task?: TaskItem;
74
+ deleted?: boolean;
75
+ next?: TaskItem;
76
+ };
77
+ /**
78
+ * Remove a task ID from all other tasks' blockedBy lists
79
+ */
80
+ private removeFromBlockedBy;
81
+ /**
82
+ * Remove a task ID from all other tasks' blocks lists
83
+ */
84
+ private removeFromBlocks;
85
+ /**
86
+ * Find and start the next pending task that is not blocked
87
+ */
88
+ private startNextPending;
89
+ /**
90
+ * Check if all tasks are completed
91
+ */
92
+ isAllCompleted(): boolean;
93
+ /**
94
+ * Get progress stats
95
+ */
96
+ getProgress(): TaskProgress;
97
+ /**
98
+ * Normalize a subject string for duplicate comparison.
99
+ * Lowercases, strips common filler words, and collapses whitespace.
100
+ */
101
+ normalizeSubject(subject: string): string;
102
+ /**
103
+ * Find a duplicate among non-completed tasks.
104
+ * Checks for exact normalized match or substring containment.
105
+ */
106
+ findDuplicate(subject: string): TaskItem | undefined;
107
+ /**
108
+ * Clear all tasks (used internally)
109
+ */
110
+ clear(): void;
111
+ /**
112
+ * Serialize the TaskManager state for persistence
113
+ */
114
+ serialize(): TaskManagerState;
115
+ /**
116
+ * Restore TaskManager state from serialized data
117
+ */
118
+ restore(state: TaskManagerState): void;
119
+ /**
120
+ * Save tasks to Workspace (if provided)
121
+ */
122
+ saveToWorkspace(workspace: Workspace | undefined, agentName?: string): void;
123
+ /**
124
+ * Restore tasks from Workspace (if available)
125
+ * Returns true if tasks were restored
126
+ */
127
+ restoreFromWorkspace(workspace: Workspace | undefined): Promise<boolean>;
128
+ }
129
+ /** @deprecated Use TaskManager instead */
130
+ export declare const TodoManager: typeof TaskManager;
131
+ export interface TaskToolOptions {
132
+ /** Logger for notifying UI about task updates */
133
+ logger?: LogProvider;
134
+ /** Agent name (for sub-agents) */
135
+ agentName?: string;
136
+ /** Agent ID for ownership checks (defaults to CLAUDE_CODE_AGENT_ID env var) */
137
+ agentId?: string;
138
+ /** Agent type for permission checks (defaults to CLAUDE_CODE_AGENT_TYPE env var) */
139
+ agentType?: 'team-lead' | string;
140
+ /** Workspace for task persistence across __ask_user__ pauses */
141
+ workspace?: Workspace;
142
+ }
143
+ /** @deprecated Use TaskToolOptions instead */
144
+ export type TodoToolOptions = TaskToolOptions;
145
+ /**
146
+ * Create the TaskCreate tool
147
+ */
148
+ export declare function createTaskCreateTool(manager: TaskManager, options?: TaskToolOptions): Tool;
149
+ /**
150
+ * Create the TaskUpdate tool
151
+ */
152
+ export declare function createTaskUpdateTool(manager: TaskManager, options?: TaskToolOptions): Tool;
153
+ /**
154
+ * Create the TaskGet tool
155
+ */
156
+ export declare function createTaskGetTool(manager: TaskManager, _options?: TaskToolOptions): Tool;
157
+ /**
158
+ * Create the TaskList tool
159
+ */
160
+ export declare function createTaskListTool(manager: TaskManager, options?: TaskToolOptions): Tool;
161
+ /**
162
+ * Create all 4 task management tools
163
+ */
164
+ export declare function createTaskTools(manager: TaskManager, options?: TaskToolOptions): Tool[];
165
+ /**
166
+ * @deprecated Use createTaskTools instead
167
+ */
168
+ export declare function createTodoTool(manager: TaskManager, options?: TaskToolOptions): Tool;
169
+ export {};
170
+ //# sourceMappingURL=tasks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../../src/tools/tasks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAe,WAAW,EAAE,YAAY,EAA0B,QAAQ,EAA4B,MAAM,aAAa,CAAC;AAClK,OAA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