wave-agent-sdk 0.4.0 → 0.6.1

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 (190) hide show
  1. package/dist/agent.d.ts +42 -11
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +114 -115
  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 +130 -54
  7. package/dist/constants/tools.d.ts +6 -3
  8. package/dist/constants/tools.d.ts.map +1 -1
  9. package/dist/constants/tools.js +6 -3
  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/MemoryRuleManager.js +1 -1
  14. package/dist/managers/aiManager.d.ts +5 -3
  15. package/dist/managers/aiManager.d.ts.map +1 -1
  16. package/dist/managers/aiManager.js +57 -20
  17. package/dist/managers/backgroundBashManager.d.ts.map +1 -1
  18. package/dist/managers/backgroundBashManager.js +1 -0
  19. package/dist/managers/backgroundTaskManager.d.ts +35 -0
  20. package/dist/managers/backgroundTaskManager.d.ts.map +1 -0
  21. package/dist/managers/backgroundTaskManager.js +255 -0
  22. package/dist/managers/foregroundTaskManager.d.ts +9 -0
  23. package/dist/managers/foregroundTaskManager.d.ts.map +1 -0
  24. package/dist/managers/foregroundTaskManager.js +21 -0
  25. package/dist/managers/liveConfigManager.d.ts +1 -1
  26. package/dist/managers/lspManager.d.ts.map +1 -1
  27. package/dist/managers/lspManager.js +3 -1
  28. package/dist/managers/mcpManager.d.ts.map +1 -1
  29. package/dist/managers/messageManager.d.ts +26 -12
  30. package/dist/managers/messageManager.d.ts.map +1 -1
  31. package/dist/managers/messageManager.js +138 -64
  32. package/dist/managers/permissionManager.d.ts.map +1 -1
  33. package/dist/managers/permissionManager.js +26 -22
  34. package/dist/managers/planManager.d.ts +1 -1
  35. package/dist/managers/planManager.d.ts.map +1 -1
  36. package/dist/managers/planManager.js +2 -2
  37. package/dist/managers/pluginManager.d.ts.map +1 -1
  38. package/dist/managers/pluginManager.js +3 -2
  39. package/dist/managers/slashCommandManager.d.ts +6 -0
  40. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  41. package/dist/managers/slashCommandManager.js +8 -2
  42. package/dist/managers/subagentManager.d.ts +15 -2
  43. package/dist/managers/subagentManager.d.ts.map +1 -1
  44. package/dist/managers/subagentManager.js +153 -39
  45. package/dist/managers/toolManager.d.ts +18 -1
  46. package/dist/managers/toolManager.d.ts.map +1 -1
  47. package/dist/managers/toolManager.js +29 -5
  48. package/dist/services/GitService.d.ts.map +1 -1
  49. package/dist/services/GitService.js +6 -2
  50. package/dist/services/MarketplaceService.d.ts +2 -2
  51. package/dist/services/MarketplaceService.d.ts.map +1 -1
  52. package/dist/services/MarketplaceService.js +18 -11
  53. package/dist/services/MemoryRuleService.d.ts +1 -1
  54. package/dist/services/MemoryRuleService.d.ts.map +1 -1
  55. package/dist/services/MemoryRuleService.js +13 -2
  56. package/dist/services/aiService.d.ts +0 -1
  57. package/dist/services/aiService.d.ts.map +1 -1
  58. package/dist/services/aiService.js +4 -140
  59. package/dist/services/memory.d.ts +0 -3
  60. package/dist/services/memory.d.ts.map +1 -1
  61. package/dist/services/memory.js +1 -60
  62. package/dist/services/session.d.ts +15 -1
  63. package/dist/services/session.d.ts.map +1 -1
  64. package/dist/services/session.js +57 -1
  65. package/dist/services/taskManager.d.ts +21 -0
  66. package/dist/services/taskManager.d.ts.map +1 -0
  67. package/dist/services/taskManager.js +158 -0
  68. package/dist/tools/askUserQuestion.d.ts.map +1 -1
  69. package/dist/tools/askUserQuestion.js +39 -25
  70. package/dist/tools/bashTool.d.ts +0 -8
  71. package/dist/tools/bashTool.d.ts.map +1 -1
  72. package/dist/tools/bashTool.js +48 -172
  73. package/dist/tools/editTool.d.ts.map +1 -1
  74. package/dist/tools/editTool.js +8 -6
  75. package/dist/tools/exitPlanMode.d.ts.map +1 -1
  76. package/dist/tools/exitPlanMode.js +25 -1
  77. package/dist/tools/globTool.d.ts.map +1 -1
  78. package/dist/tools/globTool.js +8 -2
  79. package/dist/tools/grepTool.d.ts.map +1 -1
  80. package/dist/tools/grepTool.js +17 -6
  81. package/dist/tools/lsTool.d.ts.map +1 -1
  82. package/dist/tools/lsTool.js +3 -1
  83. package/dist/tools/multiEditTool.d.ts.map +1 -1
  84. package/dist/tools/multiEditTool.js +7 -6
  85. package/dist/tools/readTool.d.ts.map +1 -1
  86. package/dist/tools/readTool.js +16 -1
  87. package/dist/tools/taskManagementTools.d.ts +6 -0
  88. package/dist/tools/taskManagementTools.d.ts.map +1 -0
  89. package/dist/tools/taskManagementTools.js +453 -0
  90. package/dist/tools/taskOutputTool.d.ts +3 -0
  91. package/dist/tools/taskOutputTool.d.ts.map +1 -0
  92. package/dist/tools/taskOutputTool.js +173 -0
  93. package/dist/tools/taskStopTool.d.ts +3 -0
  94. package/dist/tools/taskStopTool.d.ts.map +1 -0
  95. package/dist/tools/taskStopTool.js +71 -0
  96. package/dist/tools/taskTool.d.ts.map +1 -1
  97. package/dist/tools/taskTool.js +110 -63
  98. package/dist/tools/types.d.ts +12 -0
  99. package/dist/tools/types.d.ts.map +1 -1
  100. package/dist/tools/writeTool.d.ts.map +1 -1
  101. package/dist/tools/writeTool.js +9 -1
  102. package/dist/types/index.d.ts +1 -0
  103. package/dist/types/index.d.ts.map +1 -1
  104. package/dist/types/index.js +1 -0
  105. package/dist/types/marketplace.d.ts +1 -0
  106. package/dist/types/marketplace.d.ts.map +1 -1
  107. package/dist/types/messaging.d.ts +3 -8
  108. package/dist/types/messaging.d.ts.map +1 -1
  109. package/dist/types/processes.d.ts +29 -4
  110. package/dist/types/processes.d.ts.map +1 -1
  111. package/dist/types/tasks.d.ts +13 -0
  112. package/dist/types/tasks.d.ts.map +1 -0
  113. package/dist/types/tasks.js +1 -0
  114. package/dist/types/tools.d.ts +4 -1
  115. package/dist/types/tools.d.ts.map +1 -1
  116. package/dist/utils/builtinSubagents.d.ts.map +1 -1
  117. package/dist/utils/builtinSubagents.js +38 -1
  118. package/dist/utils/cacheControlUtils.d.ts.map +1 -1
  119. package/dist/utils/cacheControlUtils.js +18 -12
  120. package/dist/utils/constants.d.ts +0 -4
  121. package/dist/utils/constants.d.ts.map +1 -1
  122. package/dist/utils/constants.js +0 -4
  123. package/dist/utils/convertMessagesForAPI.js +2 -2
  124. package/dist/utils/editUtils.d.ts +2 -11
  125. package/dist/utils/editUtils.d.ts.map +1 -1
  126. package/dist/utils/editUtils.js +52 -79
  127. package/dist/utils/messageOperations.d.ts +5 -36
  128. package/dist/utils/messageOperations.d.ts.map +1 -1
  129. package/dist/utils/messageOperations.js +9 -98
  130. package/dist/utils/nameGenerator.d.ts +1 -1
  131. package/dist/utils/nameGenerator.d.ts.map +1 -1
  132. package/dist/utils/nameGenerator.js +19 -3
  133. package/package.json +5 -5
  134. package/src/agent.ts +157 -134
  135. package/src/constants/prompts.ts +156 -65
  136. package/src/constants/tools.ts +6 -3
  137. package/src/index.ts +1 -0
  138. package/src/managers/MemoryRuleManager.ts +1 -1
  139. package/src/managers/aiManager.ts +77 -35
  140. package/src/managers/backgroundBashManager.ts +1 -0
  141. package/src/managers/backgroundTaskManager.ts +305 -0
  142. package/src/managers/foregroundTaskManager.ts +27 -0
  143. package/src/managers/lspManager.ts +3 -1
  144. package/src/managers/mcpManager.ts +6 -3
  145. package/src/managers/messageManager.ts +185 -75
  146. package/src/managers/permissionManager.ts +33 -28
  147. package/src/managers/planManager.ts +2 -2
  148. package/src/managers/pluginManager.ts +4 -3
  149. package/src/managers/slashCommandManager.ts +15 -2
  150. package/src/managers/subagentManager.ts +194 -35
  151. package/src/managers/toolManager.ts +48 -6
  152. package/src/services/GitService.ts +6 -2
  153. package/src/services/MarketplaceService.ts +30 -12
  154. package/src/services/MemoryRuleService.ts +18 -6
  155. package/src/services/aiService.ts +3 -145
  156. package/src/services/memory.ts +1 -73
  157. package/src/services/session.ts +73 -0
  158. package/src/services/taskManager.ts +188 -0
  159. package/src/tools/askUserQuestion.ts +51 -29
  160. package/src/tools/bashTool.ts +63 -196
  161. package/src/tools/editTool.ts +9 -18
  162. package/src/tools/exitPlanMode.ts +26 -2
  163. package/src/tools/globTool.ts +10 -2
  164. package/src/tools/grepTool.ts +17 -6
  165. package/src/tools/lsTool.ts +3 -1
  166. package/src/tools/multiEditTool.ts +7 -18
  167. package/src/tools/readTool.ts +17 -1
  168. package/src/tools/taskManagementTools.ts +498 -0
  169. package/src/tools/taskOutputTool.ts +196 -0
  170. package/src/tools/taskStopTool.ts +78 -0
  171. package/src/tools/taskTool.ts +136 -74
  172. package/src/tools/types.ts +13 -0
  173. package/src/tools/writeTool.ts +9 -2
  174. package/src/types/index.ts +1 -0
  175. package/src/types/marketplace.ts +1 -0
  176. package/src/types/messaging.ts +2 -9
  177. package/src/types/processes.ts +39 -4
  178. package/src/types/tasks.ts +13 -0
  179. package/src/types/tools.ts +4 -1
  180. package/src/utils/builtinSubagents.ts +47 -1
  181. package/src/utils/cacheControlUtils.ts +26 -18
  182. package/src/utils/constants.ts +0 -5
  183. package/src/utils/convertMessagesForAPI.ts +2 -2
  184. package/src/utils/editUtils.ts +65 -103
  185. package/src/utils/messageOperations.ts +12 -136
  186. package/src/utils/nameGenerator.ts +20 -3
  187. package/dist/tools/todoWriteTool.d.ts +0 -6
  188. package/dist/tools/todoWriteTool.d.ts.map +0 -1
  189. package/dist/tools/todoWriteTool.js +0 -220
  190. package/src/tools/todoWriteTool.ts +0 -257
@@ -18,7 +18,7 @@ export const lsTool: ToolPlugin = {
18
18
  type: "function",
19
19
  function: {
20
20
  name: LS_TOOL_NAME,
21
- description: `Lists files and directories in a given path. The path parameter must be an absolute path, not a relative path. You can optionally provide an array of glob patterns to ignore with the ignore parameter. You should generally prefer the ${GLOB_TOOL_NAME} and ${GREP_TOOL_NAME} tools, if you know which directories to search.`,
21
+ description: "Lists files and directories in a given path.",
22
22
  parameters: {
23
23
  type: "object",
24
24
  properties: {
@@ -39,6 +39,8 @@ export const lsTool: ToolPlugin = {
39
39
  },
40
40
  },
41
41
  },
42
+ prompt: () => `
43
+ Lists files and directories in a given path. The path parameter must be an absolute path, not a relative path. You can optionally provide an array of glob patterns to ignore with the ignore parameter. You should generally prefer the ${GLOB_TOOL_NAME} and ${GREP_TOOL_NAME} tools, if you know which directories to search.`,
42
44
  execute: async (
43
45
  args: Record<string, unknown>,
44
46
  context: ToolContext,
@@ -2,11 +2,7 @@ import { readFile, writeFile } from "fs/promises";
2
2
  import { logger } from "../utils/globalLogger.js";
3
3
  import type { ToolPlugin, ToolResult, ToolContext } from "./types.js";
4
4
  import { resolvePath, getDisplayPath } from "../utils/path.js";
5
- import {
6
- findIndentationInsensitiveMatch,
7
- escapeRegExp,
8
- saveEditErrorSnapshot,
9
- } from "../utils/editUtils.js";
5
+ import { escapeRegExp, analyzeEditMismatch } from "../utils/editUtils.js";
10
6
  import {
11
7
  MULTI_EDIT_TOOL_NAME,
12
8
  EDIT_TOOL_NAME,
@@ -185,23 +181,16 @@ export const multiEditTool: ToolPlugin = {
185
181
  continue;
186
182
  }
187
183
 
188
- // Check if old_string exists (with smart indentation matching)
189
- const matchedOldString = findIndentationInsensitiveMatch(
190
- currentContent,
191
- edit.old_string,
192
- );
184
+ // Check if old_string exists
185
+ const matchedOldString = currentContent.includes(edit.old_string)
186
+ ? edit.old_string
187
+ : null;
193
188
 
194
189
  if (!matchedOldString) {
195
- await saveEditErrorSnapshot(
196
- resolvedPath,
197
- edit.old_string,
198
- currentContent,
199
- MULTI_EDIT_TOOL_NAME,
200
- );
201
190
  return {
202
191
  success: false,
203
192
  content: "",
204
- error: `Edit operation ${i + 1}: old_string not found in current content`,
193
+ error: `Edit operation ${i + 1}: ${analyzeEditMismatch(currentContent, edit.old_string)}`,
205
194
  };
206
195
  }
207
196
 
@@ -209,7 +198,7 @@ export const multiEditTool: ToolPlugin = {
209
198
 
210
199
  if (replaceAll) {
211
200
  // Replace all matches
212
- const regex = new RegExp(escapeRegExp(matchedOldString), "g");
201
+ const regex = new RegExp(escapeRegExp(edit.old_string), "g");
213
202
  currentContent = currentContent.replace(regex, edit.new_string);
214
203
  replacementCount = (currentContent.match(regex) || []).length;
215
204
  appliedEdits.push(
@@ -131,11 +131,27 @@ async function processImageFile(
131
131
  */
132
132
  export const readTool: ToolPlugin = {
133
133
  name: READ_TOOL_NAME,
134
+ prompt:
135
+ () => `Reads a file from the local filesystem. You can access any file directly by using this tool.
136
+ Assume this tool is able to read all files on the machine. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.
137
+
138
+ Usage:
139
+ - The file_path parameter must be an absolute path, not a relative path
140
+ - By default, it reads up to 2000 lines starting from the beginning of the file
141
+ - You can optionally specify a line offset and limit (especially handy for long files), but it's recommended to read the whole file by not providing these parameters
142
+ - Any lines longer than 2000 characters will be truncated
143
+ - Results are returned using cat -n format, with line numbers starting at 1
144
+ - This tool allows Agent to read images (eg PNG, JPG, etc). When reading an image file the contents are presented visually as Agent is a multimodal LLM.
145
+ - This tool can read Jupyter notebooks (.ipynb files) and returns all cells with their outputs, combining code, text, and visualizations.
146
+ - You have the capability to call multiple tools in a single response. It is always better to speculatively read multiple files as a batch that are potentially useful.
147
+ - You will regularly be asked to read screenshots. If the user provides a path to a screenshot ALWAYS use this tool to view the file at the path. This tool will work with all temporary file paths like /var/folders/123/abc/T/TemporaryItems/NSIRD_screencaptureui_ZfB1tD/Screenshot.png
148
+ - If you read a file that exists but has empty contents you will receive a system reminder warning in place of file contents.
149
+ - Binary document formats (PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX) are not supported and will return an error.`,
134
150
  config: {
135
151
  type: "function",
136
152
  function: {
137
153
  name: READ_TOOL_NAME,
138
- description: `Reads a file from the local filesystem. You can access any file directly by using this tool.\nAssume this tool is able to read all files on the machine. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.\n\nUsage:\n- The file_path parameter must be an absolute path, not a relative path\n- By default, it reads up to 2000 lines starting from the beginning of the file\n- You can optionally specify a line offset and limit (especially handy for long files), but it's recommended to read the whole file by not providing these parameters\n- Any lines longer than 2000 characters will be truncated\n- Results are returned using cat -n format, with line numbers starting at 1\n- This tool allows Agent to read images (eg PNG, JPG, etc). When reading an image file the contents are presented visually as Agent is a multimodal LLM.\n- This tool can read Jupyter notebooks (.ipynb files) and returns all cells with their outputs, combining code, text, and visualizations.\n- You have the capability to call multiple tools in a single response. It is always better to speculatively read multiple files as a batch that are potentially useful.\n- You will regularly be asked to read screenshots. If the user provides a path to a screenshot ALWAYS use this tool to view the file at the path. This tool will work with all temporary file paths like /var/folders/123/abc/T/TemporaryItems/NSIRD_screencaptureui_ZfB1tD/Screenshot.png\n- If you read a file that exists but has empty contents you will receive a system reminder warning in place of file contents.\n- Binary document formats (PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX) are not supported and will return an error.`,
154
+ description: "Read a file from the local filesystem.",
139
155
  parameters: {
140
156
  type: "object",
141
157
  properties: {
@@ -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
+ };