wave-agent-sdk 0.5.0 → 0.6.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 (148) hide show
  1. package/dist/agent.d.ts +7 -2
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +58 -74
  4. package/dist/constants/prompts.d.ts +18 -14
  5. package/dist/constants/prompts.d.ts.map +1 -1
  6. package/dist/constants/prompts.js +134 -54
  7. package/dist/constants/tools.d.ts +4 -1
  8. package/dist/constants/tools.d.ts.map +1 -1
  9. package/dist/constants/tools.js +4 -1
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -0
  13. package/dist/managers/aiManager.d.ts +2 -5
  14. package/dist/managers/aiManager.d.ts.map +1 -1
  15. package/dist/managers/aiManager.js +59 -48
  16. package/dist/managers/backgroundTaskManager.d.ts.map +1 -1
  17. package/dist/managers/backgroundTaskManager.js +59 -53
  18. package/dist/managers/foregroundTaskManager.d.ts.map +1 -1
  19. package/dist/managers/foregroundTaskManager.js +3 -2
  20. package/dist/managers/mcpManager.d.ts.map +1 -1
  21. package/dist/managers/messageManager.d.ts +7 -3
  22. package/dist/managers/messageManager.d.ts.map +1 -1
  23. package/dist/managers/messageManager.js +28 -24
  24. package/dist/managers/permissionManager.d.ts.map +1 -1
  25. package/dist/managers/permissionManager.js +25 -15
  26. package/dist/managers/planManager.d.ts +1 -1
  27. package/dist/managers/planManager.d.ts.map +1 -1
  28. package/dist/managers/planManager.js +2 -2
  29. package/dist/managers/subagentManager.d.ts +4 -0
  30. package/dist/managers/subagentManager.d.ts.map +1 -1
  31. package/dist/managers/subagentManager.js +22 -14
  32. package/dist/managers/toolManager.d.ts +11 -0
  33. package/dist/managers/toolManager.d.ts.map +1 -1
  34. package/dist/managers/toolManager.js +20 -2
  35. package/dist/services/aiService.d.ts +0 -1
  36. package/dist/services/aiService.d.ts.map +1 -1
  37. package/dist/services/aiService.js +4 -140
  38. package/dist/services/memory.d.ts +0 -3
  39. package/dist/services/memory.d.ts.map +1 -1
  40. package/dist/services/memory.js +0 -59
  41. package/dist/services/session.d.ts +3 -1
  42. package/dist/services/session.d.ts.map +1 -1
  43. package/dist/services/session.js +16 -1
  44. package/dist/services/taskManager.d.ts +21 -0
  45. package/dist/services/taskManager.d.ts.map +1 -0
  46. package/dist/services/taskManager.js +158 -0
  47. package/dist/tools/askUserQuestion.d.ts.map +1 -1
  48. package/dist/tools/askUserQuestion.js +39 -25
  49. package/dist/tools/bashTool.d.ts.map +1 -1
  50. package/dist/tools/bashTool.js +7 -9
  51. package/dist/tools/editTool.d.ts.map +1 -1
  52. package/dist/tools/editTool.js +2 -1
  53. package/dist/tools/exitPlanMode.d.ts.map +1 -1
  54. package/dist/tools/exitPlanMode.js +25 -1
  55. package/dist/tools/globTool.d.ts.map +1 -1
  56. package/dist/tools/globTool.js +8 -2
  57. package/dist/tools/grepTool.d.ts.map +1 -1
  58. package/dist/tools/grepTool.js +17 -6
  59. package/dist/tools/lsTool.d.ts.map +1 -1
  60. package/dist/tools/lsTool.js +3 -1
  61. package/dist/tools/readTool.d.ts.map +1 -1
  62. package/dist/tools/readTool.js +16 -1
  63. package/dist/tools/taskManagementTools.d.ts +6 -0
  64. package/dist/tools/taskManagementTools.d.ts.map +1 -0
  65. package/dist/tools/taskManagementTools.js +453 -0
  66. package/dist/tools/taskOutputTool.d.ts.map +1 -1
  67. package/dist/tools/taskOutputTool.js +32 -8
  68. package/dist/tools/taskStopTool.d.ts.map +1 -1
  69. package/dist/tools/taskStopTool.js +7 -1
  70. package/dist/tools/taskTool.d.ts.map +1 -1
  71. package/dist/tools/taskTool.js +6 -1
  72. package/dist/tools/types.d.ts +9 -0
  73. package/dist/tools/types.d.ts.map +1 -1
  74. package/dist/tools/writeTool.d.ts.map +1 -1
  75. package/dist/tools/writeTool.js +9 -1
  76. package/dist/types/index.d.ts +1 -0
  77. package/dist/types/index.d.ts.map +1 -1
  78. package/dist/types/index.js +1 -0
  79. package/dist/types/messaging.d.ts +2 -8
  80. package/dist/types/messaging.d.ts.map +1 -1
  81. package/dist/types/processes.d.ts +11 -6
  82. package/dist/types/processes.d.ts.map +1 -1
  83. package/dist/types/tasks.d.ts +13 -0
  84. package/dist/types/tasks.d.ts.map +1 -0
  85. package/dist/types/tasks.js +1 -0
  86. package/dist/types/tools.d.ts +4 -1
  87. package/dist/types/tools.d.ts.map +1 -1
  88. package/dist/utils/builtinSubagents.d.ts.map +1 -1
  89. package/dist/utils/builtinSubagents.js +38 -1
  90. package/dist/utils/cacheControlUtils.d.ts.map +1 -1
  91. package/dist/utils/cacheControlUtils.js +18 -12
  92. package/dist/utils/constants.d.ts +0 -4
  93. package/dist/utils/constants.d.ts.map +1 -1
  94. package/dist/utils/constants.js +0 -4
  95. package/dist/utils/convertMessagesForAPI.js +2 -2
  96. package/dist/utils/messageOperations.d.ts +2 -30
  97. package/dist/utils/messageOperations.d.ts.map +1 -1
  98. package/dist/utils/messageOperations.js +4 -79
  99. package/dist/utils/nameGenerator.d.ts +1 -1
  100. package/dist/utils/nameGenerator.d.ts.map +1 -1
  101. package/dist/utils/nameGenerator.js +19 -3
  102. package/package.json +1 -1
  103. package/src/agent.ts +79 -84
  104. package/src/constants/prompts.ts +161 -65
  105. package/src/constants/tools.ts +4 -1
  106. package/src/index.ts +1 -0
  107. package/src/managers/aiManager.ts +79 -70
  108. package/src/managers/backgroundTaskManager.ts +53 -54
  109. package/src/managers/foregroundTaskManager.ts +3 -2
  110. package/src/managers/mcpManager.ts +6 -3
  111. package/src/managers/messageManager.ts +37 -26
  112. package/src/managers/permissionManager.ts +32 -21
  113. package/src/managers/planManager.ts +2 -2
  114. package/src/managers/subagentManager.ts +33 -14
  115. package/src/managers/toolManager.ts +32 -2
  116. package/src/services/aiService.ts +3 -145
  117. package/src/services/memory.ts +0 -72
  118. package/src/services/session.ts +21 -0
  119. package/src/services/taskManager.ts +188 -0
  120. package/src/tools/askUserQuestion.ts +51 -29
  121. package/src/tools/bashTool.ts +9 -15
  122. package/src/tools/editTool.ts +3 -1
  123. package/src/tools/exitPlanMode.ts +26 -2
  124. package/src/tools/globTool.ts +10 -2
  125. package/src/tools/grepTool.ts +17 -6
  126. package/src/tools/lsTool.ts +3 -1
  127. package/src/tools/readTool.ts +17 -1
  128. package/src/tools/taskManagementTools.ts +498 -0
  129. package/src/tools/taskOutputTool.ts +34 -12
  130. package/src/tools/taskStopTool.ts +7 -1
  131. package/src/tools/taskTool.ts +7 -1
  132. package/src/tools/types.ts +10 -0
  133. package/src/tools/writeTool.ts +9 -2
  134. package/src/types/index.ts +1 -0
  135. package/src/types/messaging.ts +1 -9
  136. package/src/types/processes.ts +13 -7
  137. package/src/types/tasks.ts +13 -0
  138. package/src/types/tools.ts +4 -1
  139. package/src/utils/builtinSubagents.ts +47 -1
  140. package/src/utils/cacheControlUtils.ts +26 -18
  141. package/src/utils/constants.ts +0 -5
  142. package/src/utils/convertMessagesForAPI.ts +2 -2
  143. package/src/utils/messageOperations.ts +5 -116
  144. package/src/utils/nameGenerator.ts +20 -3
  145. package/dist/tools/todoWriteTool.d.ts +0 -6
  146. package/dist/tools/todoWriteTool.d.ts.map +0 -1
  147. package/dist/tools/todoWriteTool.js +0 -220
  148. package/src/tools/todoWriteTool.ts +0 -257
@@ -0,0 +1,498 @@
1
+ import { ToolPlugin, ToolContext, ToolResult } from "./types.js";
2
+ import { Task, TaskStatus } from "../types/tasks.js";
3
+ import {
4
+ TASK_CREATE_TOOL_NAME,
5
+ TASK_GET_TOOL_NAME,
6
+ TASK_UPDATE_TOOL_NAME,
7
+ TASK_LIST_TOOL_NAME,
8
+ } from "../constants/tools.js";
9
+
10
+ export const taskCreateTool: ToolPlugin = {
11
+ name: TASK_CREATE_TOOL_NAME,
12
+ config: {
13
+ type: "function",
14
+ function: {
15
+ name: TASK_CREATE_TOOL_NAME,
16
+ description: "Create a new task in the task list",
17
+ parameters: {
18
+ type: "object",
19
+ properties: {
20
+ subject: {
21
+ type: "string",
22
+ description: "A brief title for the task",
23
+ },
24
+ description: {
25
+ type: "string",
26
+ description: "A detailed description of what needs to be done",
27
+ },
28
+ status: {
29
+ type: "string",
30
+ enum: ["pending", "in_progress", "completed", "deleted"],
31
+ description: "Initial status of the task. Defaults to 'pending'.",
32
+ },
33
+ activeForm: {
34
+ type: "string",
35
+ description:
36
+ 'Present continuous form shown in spinner when in_progress (e.g., "Running tests")',
37
+ },
38
+ owner: {
39
+ type: "string",
40
+ description: "Optional owner of the task.",
41
+ },
42
+ blocks: {
43
+ type: "array",
44
+ items: { type: "string" },
45
+ description: "List of task IDs that this task blocks.",
46
+ },
47
+ blockedBy: {
48
+ type: "array",
49
+ items: { type: "string" },
50
+ description: "List of task IDs that block this task.",
51
+ },
52
+ metadata: {
53
+ type: "object",
54
+ description: "Arbitrary metadata to attach to the task",
55
+ },
56
+ },
57
+ required: ["subject", "description"],
58
+ },
59
+ },
60
+ },
61
+ prompt:
62
+ () => `Use this tool to create a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
63
+ It also helps the user understand the progress of the task and overall progress of their requests.
64
+
65
+ ## When to Use This Tool
66
+
67
+ Use this tool proactively in these scenarios:
68
+
69
+ - Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
70
+ - Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
71
+ - Plan mode - When using plan mode, create a task list to track the work
72
+ - User explicitly requests todo list - When the user directly asks you to use the todo list
73
+ - User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
74
+ - After receiving new instructions - Immediately capture user requirements as tasks
75
+ - When you start working on a task - Mark it as in_progress BEFORE beginning work
76
+ - After completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation
77
+
78
+ ## When NOT to Use This Tool
79
+
80
+ Skip using this tool when:
81
+ - There is only a single, straightforward task
82
+ - The task is trivial and tracking it provides no organizational benefit
83
+ - The task can be completed in less than 3 trivial steps
84
+ - The task is purely conversational or informational
85
+
86
+ NOTE that you should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.
87
+
88
+ ## Task Fields
89
+
90
+ - **subject**: A brief, actionable title in imperative form (e.g., "Fix authentication bug in login flow")
91
+ - **description**: Detailed description of what needs to be done, including context and acceptance criteria
92
+ - **activeForm**: Present continuous form shown in spinner when task is in_progress (e.g., "Fixing authentication bug"). This is displayed to the user while you work on the task.
93
+
94
+ **IMPORTANT**: Always provide activeForm when creating tasks. The subject should be imperative ("Run tests") while activeForm should be present continuous ("Running tests"). All tasks are created with status \`pending\`.
95
+
96
+ ## Tips
97
+
98
+ - Create tasks with clear, specific subjects that describe the outcome
99
+ - Include enough detail in the description for another agent to understand and complete the task
100
+ - After creating tasks, use TaskUpdate to set up dependencies (blocks/blockedBy) if needed
101
+ - Check TaskList first to avoid creating duplicate tasks`,
102
+ execute: async (args, context: ToolContext): Promise<ToolResult> => {
103
+ const taskManager = context.taskManager;
104
+ const task: Omit<Task, "id"> = {
105
+ subject: args.subject as string,
106
+ description: args.description as string,
107
+ status: (args.status as TaskStatus) || "pending",
108
+ activeForm: args.activeForm as string,
109
+ owner: args.owner as string,
110
+ blocks: (args.blocks as string[]) || [],
111
+ blockedBy: (args.blockedBy as string[]) || [],
112
+ metadata: (args.metadata as Record<string, unknown>) || {},
113
+ };
114
+
115
+ const taskId = await taskManager.createTask(task);
116
+
117
+ return {
118
+ success: true,
119
+ content: `Task created with ID: ${taskId}`,
120
+ shortResult: `Created task ${taskId}: ${task.subject}`,
121
+ };
122
+ },
123
+ };
124
+
125
+ export const taskGetTool: ToolPlugin = {
126
+ name: TASK_GET_TOOL_NAME,
127
+ config: {
128
+ type: "function",
129
+ function: {
130
+ name: TASK_GET_TOOL_NAME,
131
+ description: "Get a task by ID from the task list",
132
+ parameters: {
133
+ type: "object",
134
+ properties: {
135
+ taskId: {
136
+ type: "string",
137
+ description: "The ID of the task to retrieve",
138
+ },
139
+ },
140
+ required: ["taskId"],
141
+ },
142
+ },
143
+ },
144
+ prompt: () => `Use this tool to retrieve a task by its ID from the task list.
145
+
146
+ ## When to Use This Tool
147
+
148
+ - When you need the full description and context before starting work on a task
149
+ - To understand task dependencies (what it blocks, what blocks it)
150
+ - After being assigned a task, to get complete requirements
151
+
152
+ ## Output
153
+
154
+ Returns full task details:
155
+ - **subject**: Task title
156
+ - **description**: Detailed requirements and context
157
+ - **status**: 'pending', 'in_progress', or 'completed'
158
+ - **blocks**: Tasks waiting on this one to complete
159
+ - **blockedBy**: Tasks that must complete before this one can start
160
+
161
+ ## Tips
162
+
163
+ - After fetching a task, verify its blockedBy list is empty before beginning work.
164
+ - Use TaskList to see all tasks in summary form.`,
165
+ execute: async (args, context: ToolContext): Promise<ToolResult> => {
166
+ const taskManager = context.taskManager;
167
+ const taskId = args.taskId as string;
168
+
169
+ const task = await taskManager.getTask(taskId);
170
+ if (!task) {
171
+ return {
172
+ success: false,
173
+ content: `Task with ID ${taskId} not found.`,
174
+ };
175
+ }
176
+
177
+ return {
178
+ success: true,
179
+ content: JSON.stringify(task, null, 2),
180
+ };
181
+ },
182
+ };
183
+
184
+ export const taskUpdateTool: ToolPlugin = {
185
+ name: TASK_UPDATE_TOOL_NAME,
186
+ config: {
187
+ type: "function",
188
+ function: {
189
+ name: TASK_UPDATE_TOOL_NAME,
190
+ description: "Update a task in the task list",
191
+ parameters: {
192
+ type: "object",
193
+ properties: {
194
+ taskId: {
195
+ type: "string",
196
+ description: "The ID of the task to update",
197
+ },
198
+ subject: {
199
+ type: "string",
200
+ description: "New subject for the task",
201
+ },
202
+ description: {
203
+ type: "string",
204
+ description: "New description for the task",
205
+ },
206
+ activeForm: {
207
+ type: "string",
208
+ description:
209
+ 'Present continuous form shown in spinner when in_progress (e.g., "Running tests")',
210
+ },
211
+ status: {
212
+ type: "string",
213
+ enum: ["pending", "in_progress", "completed", "deleted"],
214
+ description: "New status for the task",
215
+ },
216
+ addBlocks: {
217
+ type: "array",
218
+ items: { type: "string" },
219
+ description: "Task IDs that this task blocks",
220
+ },
221
+ addBlockedBy: {
222
+ type: "array",
223
+ items: { type: "string" },
224
+ description: "Task IDs that block this task",
225
+ },
226
+ owner: {
227
+ type: "string",
228
+ description: "New owner for the task",
229
+ },
230
+ metadata: {
231
+ type: "object",
232
+ description:
233
+ "Metadata keys to merge into the task. Set a key to null to delete it.",
234
+ },
235
+ },
236
+ required: ["taskId"],
237
+ },
238
+ },
239
+ },
240
+ prompt: () => `Use this tool to update a task in the task list.
241
+
242
+ ## When to Use This Tool
243
+
244
+ **Mark tasks as resolved:**
245
+ - When you have completed the work described in a task
246
+ - When a task is no longer needed or has been superseded
247
+ - IMPORTANT: Always mark your assigned tasks as resolved when you finish them
248
+ - After resolving, call TaskList to find your next task
249
+
250
+ - ONLY mark a task as completed when you have FULLY accomplished it
251
+ - If you encounter errors, blockers, or cannot finish, keep the task as in_progress
252
+ - When blocked, create a new task describing what needs to be resolved
253
+ - Never mark a task as completed if:
254
+ - Tests are failing
255
+ - Implementation is partial
256
+ - You encountered unresolved errors
257
+ - You couldn't find necessary files or dependencies
258
+
259
+ **Delete tasks:**
260
+ - When a task is no longer relevant or was created in error
261
+ - Setting status to \`deleted\` permanently removes the task
262
+
263
+ **Update task details:**
264
+ - When requirements change or become clearer
265
+ - When establishing dependencies between tasks
266
+
267
+ ## Fields You Can Update
268
+
269
+ - **status**: The task status (see Status Workflow below)
270
+ - **subject**: Change the task title (imperative form, e.g., "Run tests")
271
+ - **description**: Change the task description
272
+ - **activeForm**: Present continuous form shown in spinner when in_progress (e.g., "Running tests")
273
+ - **owner**: Change the task owner (agent name)
274
+ - **metadata**: Merge metadata keys into the task (set a key to null to delete it)
275
+ - **addBlocks**: Mark tasks that cannot start until this one completes
276
+ - **addBlockedBy**: Mark tasks that must complete before this one can start
277
+
278
+ ## Status Workflow
279
+
280
+ Status progresses: \`pending\` → \`in_progress\` → \`completed\`
281
+
282
+ Use \`deleted\` to permanently remove a task.
283
+
284
+ ## Staleness
285
+
286
+ Make sure to read a task's latest state using \`TaskGet\` before updating it.
287
+
288
+ ## Examples
289
+
290
+ Mark task as in progress when starting work:
291
+ \`\`\`json
292
+ {"taskId": "1", "status": "in_progress"}
293
+ \`\`\`
294
+
295
+ Mark task as completed after finishing work:
296
+ \`\`\`json
297
+ {"taskId": "1", "status": "completed"}
298
+ \`\`\`
299
+
300
+ Delete a task:
301
+ \`\`\`json
302
+ {"taskId": "1", "status": "deleted"}
303
+ \`\`\`
304
+
305
+ Claim a task by setting owner:
306
+ \`\`\`json
307
+ {"taskId": "1", "owner": "my-name"}
308
+ \`\`\`
309
+
310
+ Set up task dependencies:
311
+ \`\`\`json
312
+ {"taskId": "2", "addBlockedBy": ["1"]}
313
+ \`\`\`
314
+ `,
315
+ execute: async (args, context: ToolContext): Promise<ToolResult> => {
316
+ const taskManager = context.taskManager;
317
+ const taskId = args.taskId as string;
318
+
319
+ const existingTask = await taskManager.getTask(taskId);
320
+ if (!existingTask) {
321
+ return {
322
+ success: false,
323
+ content: `Task with ID ${taskId} not found.`,
324
+ };
325
+ }
326
+
327
+ const updatedFields: string[] = [];
328
+
329
+ const updatedTask: Task = {
330
+ ...existingTask,
331
+ };
332
+
333
+ if (args.subject !== undefined && args.subject !== existingTask.subject) {
334
+ updatedTask.subject = args.subject as string;
335
+ updatedFields.push("subject");
336
+ }
337
+ if (
338
+ args.description !== undefined &&
339
+ args.description !== existingTask.description
340
+ ) {
341
+ updatedTask.description = args.description as string;
342
+ updatedFields.push("description");
343
+ }
344
+ if (args.status !== undefined && args.status !== existingTask.status) {
345
+ updatedTask.status = args.status as TaskStatus;
346
+ updatedFields.push("status");
347
+ }
348
+ if (
349
+ args.activeForm !== undefined &&
350
+ args.activeForm !== existingTask.activeForm
351
+ ) {
352
+ updatedTask.activeForm = args.activeForm as string;
353
+ updatedFields.push("activeForm");
354
+ }
355
+ if (args.owner !== undefined && args.owner !== existingTask.owner) {
356
+ updatedTask.owner = args.owner as string;
357
+ updatedFields.push("owner");
358
+ }
359
+
360
+ if (args.metadata !== undefined) {
361
+ const newMetadata = { ...(existingTask.metadata || {}) };
362
+ for (const [key, value] of Object.entries(
363
+ args.metadata as Record<string, unknown>,
364
+ )) {
365
+ if (value === null) {
366
+ delete newMetadata[key];
367
+ } else {
368
+ newMetadata[key] = value;
369
+ }
370
+ }
371
+ updatedTask.metadata = newMetadata;
372
+ updatedFields.push("metadata");
373
+ }
374
+
375
+ if (args.addBlocks !== undefined) {
376
+ const blocksToAdd = (args.addBlocks as string[]).filter(
377
+ (id) => !updatedTask.blocks.includes(id),
378
+ );
379
+ if (blocksToAdd.length > 0) {
380
+ updatedTask.blocks = [...updatedTask.blocks, ...blocksToAdd];
381
+ updatedFields.push("blocks");
382
+
383
+ // Also update the blockedBy of the target tasks
384
+ for (const targetId of blocksToAdd) {
385
+ const targetTask = await taskManager.getTask(targetId);
386
+ if (targetTask && !targetTask.blockedBy.includes(taskId)) {
387
+ await taskManager.updateTask({
388
+ ...targetTask,
389
+ blockedBy: [...targetTask.blockedBy, taskId],
390
+ });
391
+ }
392
+ }
393
+ }
394
+ }
395
+
396
+ if (args.addBlockedBy !== undefined) {
397
+ const blockedByToAdd = (args.addBlockedBy as string[]).filter(
398
+ (id) => !updatedTask.blockedBy.includes(id),
399
+ );
400
+ if (blockedByToAdd.length > 0) {
401
+ updatedTask.blockedBy = [...updatedTask.blockedBy, ...blockedByToAdd];
402
+ updatedFields.push("blockedBy");
403
+
404
+ // Also update the blocks of the target tasks
405
+ for (const targetId of blockedByToAdd) {
406
+ const targetTask = await taskManager.getTask(targetId);
407
+ if (targetTask && !targetTask.blocks.includes(taskId)) {
408
+ await taskManager.updateTask({
409
+ ...targetTask,
410
+ blocks: [...targetTask.blocks, taskId],
411
+ });
412
+ }
413
+ }
414
+ }
415
+ }
416
+
417
+ await taskManager.updateTask(updatedTask);
418
+
419
+ let content = `Updated task #${taskId} ${updatedFields.join(", ")}`;
420
+ if (updatedTask.status === "completed") {
421
+ content += `\n\nTask completed. Call TaskList now to find your next available task or see if your work unblocked others.`;
422
+ }
423
+
424
+ return {
425
+ success: true,
426
+ content,
427
+ shortResult: `Updated task ${taskId}`,
428
+ };
429
+ },
430
+ };
431
+
432
+ export const taskListTool: ToolPlugin = {
433
+ name: TASK_LIST_TOOL_NAME,
434
+ config: {
435
+ type: "function",
436
+ function: {
437
+ name: TASK_LIST_TOOL_NAME,
438
+ description: "List all tasks in the task list",
439
+ parameters: {
440
+ type: "object",
441
+ properties: {
442
+ status: {
443
+ type: "string",
444
+ enum: ["pending", "in_progress", "completed", "deleted"],
445
+ description: "Optional filter by status.",
446
+ },
447
+ },
448
+ },
449
+ },
450
+ },
451
+ prompt: () => `Use this tool to list all tasks in the task list.
452
+
453
+ ## When to Use This Tool
454
+
455
+ - To see what tasks are available to work on (status: 'pending', no owner, not blocked)
456
+ - To check overall progress on the project
457
+ - To find tasks that are blocked and need dependencies resolved
458
+ - After completing a task, to check for newly unblocked work or claim the next available task
459
+ - **Prefer working on tasks in ID order** (lowest ID first) when multiple tasks are available, as earlier tasks often set up context for later ones
460
+
461
+ ## Output
462
+
463
+ Returns a summary of each task:
464
+ - **id**: Task identifier (use with TaskGet, TaskUpdate)
465
+ - **subject**: Brief description of the task
466
+ - **status**: 'pending', 'in_progress', or 'completed'
467
+ - **owner**: Agent ID if assigned, empty if available
468
+ - **blockedBy**: List of open task IDs that must be resolved first (tasks with blockedBy cannot be claimed until dependencies resolve)
469
+
470
+ Use TaskGet with a specific task ID to view full details including description and comments.`,
471
+ execute: async (args, context: ToolContext): Promise<ToolResult> => {
472
+ const taskManager = context.taskManager;
473
+
474
+ let tasks = await taskManager.listTasks();
475
+ if (args.status) {
476
+ tasks = tasks.filter((t) => t.status === args.status);
477
+ }
478
+
479
+ if (tasks.length === 0) {
480
+ return {
481
+ success: true,
482
+ content: "No tasks found.",
483
+ };
484
+ }
485
+
486
+ // Sort by ID numerically
487
+ tasks.sort((a, b) => parseInt(a.id, 10) - parseInt(b.id, 10));
488
+
489
+ const content = tasks
490
+ .map((t) => `[${t.id}] ${t.subject} (${t.status})`)
491
+ .join("\n");
492
+
493
+ return {
494
+ success: true,
495
+ content,
496
+ };
497
+ },
498
+ };
@@ -10,38 +10,47 @@ export const taskOutputTool: ToolPlugin = {
10
10
  type: "function",
11
11
  function: {
12
12
  name: TASK_OUTPUT_TOOL_NAME,
13
- description:
14
- "Retrieves output from a running or completed background task",
13
+ description: "Retrieves output from a running or completed task",
15
14
  parameters: {
16
15
  type: "object",
17
16
  properties: {
18
17
  task_id: {
19
18
  type: "string",
20
- description:
21
- "The ID of the background task to retrieve output from",
22
- },
23
- filter: {
24
- type: "string",
25
- description:
26
- "Optional regular expression to filter the output lines.",
19
+ description: "The task ID to get output from",
27
20
  },
28
21
  block: {
29
22
  type: "boolean",
30
- description:
31
- "If true, wait for the task to complete before returning output. If false, return current output immediately.",
23
+ default: true,
24
+ description: "Whether to wait for completion",
25
+ },
26
+ timeout: {
27
+ type: "number",
28
+ minimum: 0,
29
+ maximum: 600000,
30
+ default: 30000,
31
+ description: "Max wait time in ms",
32
32
  },
33
33
  },
34
34
  required: ["task_id"],
35
35
  },
36
36
  },
37
37
  },
38
+ prompt:
39
+ () => `- Retrieves output from a running or completed task (background shell, agent, or remote session)
40
+ - Takes a task_id parameter identifying the task
41
+ - Returns the task output along with status information
42
+ - Use block=true (default) to wait for task completion
43
+ - Use block=false for non-blocking check of current status
44
+ - Task IDs can be found using the /tasks command
45
+ - Works with all task types: background shells, async agents, and remote sessions`,
38
46
  execute: async (
39
47
  args: Record<string, unknown>,
40
48
  context: ToolContext,
41
49
  ): Promise<ToolResult> => {
42
50
  const taskId = args.task_id as string;
43
51
  const filter = args.filter as string | undefined;
44
- const block = args.block as boolean | undefined;
52
+ const block = (args.block as boolean | undefined) ?? true;
53
+ const timeout = (args.timeout as number | undefined) ?? 30000;
45
54
 
46
55
  if (!taskId || typeof taskId !== "string") {
47
56
  return {
@@ -91,6 +100,7 @@ export const taskOutputTool: ToolPlugin = {
91
100
  return new Promise((resolve) => {
92
101
  let timeoutHandle: NodeJS.Timeout | null = null;
93
102
  let isAborted = false;
103
+ const startTime = Date.now();
94
104
 
95
105
  const cleanup = () => {
96
106
  if (timeoutHandle) {
@@ -122,6 +132,18 @@ export const taskOutputTool: ToolPlugin = {
122
132
  const check = () => {
123
133
  if (isAborted) return;
124
134
 
135
+ if (Date.now() - startTime > timeout) {
136
+ if (context.abortSignal) {
137
+ context.abortSignal.removeEventListener("abort", onAbort);
138
+ }
139
+ resolve({
140
+ success: true,
141
+ content: "Retrieval timed out",
142
+ shortResult: `${taskId}: timeout`,
143
+ });
144
+ return;
145
+ }
146
+
125
147
  const task = backgroundTaskManager.getTask(taskId);
126
148
  if (!task) {
127
149
  if (context.abortSignal) {
@@ -7,7 +7,7 @@ export const taskStopTool: ToolPlugin = {
7
7
  type: "function",
8
8
  function: {
9
9
  name: TASK_STOP_TOOL_NAME,
10
- description: "Stops a running background task",
10
+ description: "Stop a running background task by ID",
11
11
  parameters: {
12
12
  type: "object",
13
13
  properties: {
@@ -20,6 +20,12 @@ export const taskStopTool: ToolPlugin = {
20
20
  },
21
21
  },
22
22
  },
23
+ prompt: () => `
24
+ - Stops a running background task by its ID
25
+ - Takes a task_id parameter identifying the task to stop
26
+ - Returns a success or failure status
27
+ - Use this tool when you need to terminate a long-running task
28
+ `,
23
29
  execute: async (
24
30
  args: Record<string, unknown>,
25
31
  context: ToolContext,
@@ -58,6 +58,11 @@ export function createTaskTool(subagentManager: SubagentManager): ToolPlugin {
58
58
  };
59
59
  },
60
60
 
61
+ prompt: () => `
62
+ - When doing file search, prefer to use the ${TASK_TOOL_NAME} tool in order to reduce context usage.
63
+ - You should proactively use the ${TASK_TOOL_NAME} tool with specialized agents when the task at hand matches the agent's description.
64
+ - VERY IMPORTANT: When exploring the codebase to gather context or to answer a question that is not a needle query for a specific file/class/function, it is CRITICAL that you use the ${TASK_TOOL_NAME} tool with subagent_type=Explore instead of running search commands directly.`,
65
+
61
66
  execute: async (
62
67
  args: Record<string, unknown>,
63
68
  context: ToolContext,
@@ -140,8 +145,9 @@ export function createTaskTool(subagentManager: SubagentManager): ToolPlugin {
140
145
  // Resolve the tool execution early so the main agent can continue
141
146
  resolve({
142
147
  success: true,
143
- content: `Task moved to background with ID: ${taskId}. Use TaskOutput to monitor progress.`,
148
+ content: `Task moved to background with ID: ${taskId}.`,
144
149
  shortResult: "Task backgrounded",
150
+ isManuallyBackgrounded: true,
145
151
  });
146
152
  },
147
153
  });
@@ -19,6 +19,10 @@ export interface ToolPlugin {
19
19
  params: Record<string, unknown>,
20
20
  context: ToolContext,
21
21
  ) => string;
22
+ /**
23
+ * Optional function to provide a prompt to be added to the system prompt
24
+ */
25
+ prompt?: (context: ToolContext) => string;
22
26
  }
23
27
 
24
28
  export interface ToolResult {
@@ -34,6 +38,8 @@ export interface ToolResult {
34
38
  data: string; // base64 encoded image data
35
39
  mediaType?: string; // Image media type, such as "image/png"
36
40
  }>;
41
+ // Whether the tool was manually backgrounded by the user (e.g. via Ctrl-B)
42
+ isManuallyBackgrounded?: boolean;
37
43
  }
38
44
 
39
45
  export interface ToolContext {
@@ -57,4 +63,8 @@ export interface ToolContext {
57
63
  messageId?: string;
58
64
  /** Foreground task manager for backgrounding tasks */
59
65
  foregroundTaskManager?: import("../types/processes.js").IForegroundTaskManager;
66
+ /** Task manager instance for task management */
67
+ taskManager: import("../services/taskManager.js").TaskManager;
68
+ /** Current session ID */
69
+ sessionId?: string;
60
70
  }
@@ -13,8 +13,7 @@ export const writeTool: ToolPlugin = {
13
13
  type: "function",
14
14
  function: {
15
15
  name: "Write",
16
- description:
17
- "Writes a file to the local filesystem.\n\nUsage:\n- This tool will overwrite the existing file if there is one at the provided path.\n- If this is an existing file, you MUST use the Read tool first to read the file's contents. This tool will fail if you did not read the file first.\n- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.\n- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.\n- Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked.\n- IMPORTANT: Always provide file_path parameter before content parameter when calling this tool.",
16
+ description: "Writes a file to the local filesystem.",
18
17
  parameters: {
19
18
  type: "object",
20
19
  properties: {
@@ -33,6 +32,14 @@ export const writeTool: ToolPlugin = {
33
32
  },
34
33
  },
35
34
  },
35
+ prompt: () => `
36
+ Usage:
37
+ - This tool will overwrite the existing file if there is one at the provided path.
38
+ - If this is an existing file, you MUST use the Read tool first to read the file's contents. This tool will fail if you did not read the file first.
39
+ - ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
40
+ - NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.
41
+ - Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked.
42
+ - IMPORTANT: Always provide file_path parameter before content parameter when calling this tool.`,
36
43
  execute: async (
37
44
  args: Record<string, unknown>,
38
45
  context: ToolContext,
@@ -33,3 +33,4 @@ export * from "./plugins.js";
33
33
  export * from "./marketplace.js";
34
34
  export * from "./memoryRule.js";
35
35
  export * from "./history.js";
36
+ export * from "./tasks.js";