wave-agent-sdk 0.5.0 → 0.6.2

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 (169) hide show
  1. package/dist/agent.d.ts +14 -11
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +64 -151
  4. package/dist/constants/subagents.d.ts +5 -0
  5. package/dist/constants/subagents.d.ts.map +1 -0
  6. package/dist/constants/subagents.js +4 -0
  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 +43 -48
  16. package/dist/managers/backgroundTaskManager.d.ts.map +1 -1
  17. package/dist/managers/backgroundTaskManager.js +63 -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 +13 -27
  22. package/dist/managers/messageManager.d.ts.map +1 -1
  23. package/dist/managers/messageManager.js +94 -89
  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/reversionManager.d.ts.map +1 -1
  30. package/dist/managers/reversionManager.js +23 -2
  31. package/dist/managers/slashCommandManager.d.ts +3 -0
  32. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  33. package/dist/managers/slashCommandManager.js +8 -3
  34. package/dist/managers/subagentManager.d.ts +8 -14
  35. package/dist/managers/subagentManager.d.ts.map +1 -1
  36. package/dist/managers/subagentManager.js +46 -112
  37. package/dist/managers/toolManager.d.ts +11 -0
  38. package/dist/managers/toolManager.d.ts.map +1 -1
  39. package/dist/managers/toolManager.js +20 -2
  40. package/dist/{constants/prompts.d.ts → prompts/index.d.ts} +17 -15
  41. package/dist/prompts/index.d.ts.map +1 -0
  42. package/dist/prompts/index.js +309 -0
  43. package/dist/services/aiService.d.ts +0 -1
  44. package/dist/services/aiService.d.ts.map +1 -1
  45. package/dist/services/aiService.js +4 -140
  46. package/dist/services/memory.d.ts +0 -3
  47. package/dist/services/memory.d.ts.map +1 -1
  48. package/dist/services/memory.js +0 -59
  49. package/dist/services/session.d.ts +15 -1
  50. package/dist/services/session.d.ts.map +1 -1
  51. package/dist/services/session.js +57 -1
  52. package/dist/services/taskManager.d.ts +25 -0
  53. package/dist/services/taskManager.d.ts.map +1 -0
  54. package/dist/services/taskManager.js +164 -0
  55. package/dist/tools/askUserQuestion.d.ts.map +1 -1
  56. package/dist/tools/askUserQuestion.js +39 -25
  57. package/dist/tools/bashTool.d.ts.map +1 -1
  58. package/dist/tools/bashTool.js +13 -11
  59. package/dist/tools/editTool.d.ts.map +1 -1
  60. package/dist/tools/editTool.js +2 -1
  61. package/dist/tools/exitPlanMode.d.ts.map +1 -1
  62. package/dist/tools/exitPlanMode.js +26 -2
  63. package/dist/tools/globTool.d.ts.map +1 -1
  64. package/dist/tools/globTool.js +8 -2
  65. package/dist/tools/grepTool.d.ts.map +1 -1
  66. package/dist/tools/grepTool.js +17 -6
  67. package/dist/tools/lsTool.d.ts.map +1 -1
  68. package/dist/tools/lsTool.js +3 -1
  69. package/dist/tools/readTool.d.ts.map +1 -1
  70. package/dist/tools/readTool.js +16 -1
  71. package/dist/tools/taskManagementTools.d.ts +6 -0
  72. package/dist/tools/taskManagementTools.d.ts.map +1 -0
  73. package/dist/tools/taskManagementTools.js +461 -0
  74. package/dist/tools/taskOutputTool.d.ts.map +1 -1
  75. package/dist/tools/taskOutputTool.js +32 -8
  76. package/dist/tools/taskStopTool.d.ts.map +1 -1
  77. package/dist/tools/taskStopTool.js +7 -1
  78. package/dist/tools/taskTool.d.ts.map +1 -1
  79. package/dist/tools/taskTool.js +37 -2
  80. package/dist/tools/types.d.ts +11 -0
  81. package/dist/tools/types.d.ts.map +1 -1
  82. package/dist/tools/writeTool.d.ts.map +1 -1
  83. package/dist/tools/writeTool.js +9 -1
  84. package/dist/types/index.d.ts +1 -0
  85. package/dist/types/index.d.ts.map +1 -1
  86. package/dist/types/index.js +1 -0
  87. package/dist/types/messaging.d.ts +2 -18
  88. package/dist/types/messaging.d.ts.map +1 -1
  89. package/dist/types/processes.d.ts +16 -6
  90. package/dist/types/processes.d.ts.map +1 -1
  91. package/dist/types/tasks.d.ts +13 -0
  92. package/dist/types/tasks.d.ts.map +1 -0
  93. package/dist/types/tasks.js +1 -0
  94. package/dist/types/tools.d.ts +4 -1
  95. package/dist/types/tools.d.ts.map +1 -1
  96. package/dist/utils/builtinSubagents.d.ts.map +1 -1
  97. package/dist/utils/builtinSubagents.js +59 -44
  98. package/dist/utils/cacheControlUtils.d.ts.map +1 -1
  99. package/dist/utils/cacheControlUtils.js +18 -12
  100. package/dist/utils/constants.d.ts +0 -4
  101. package/dist/utils/constants.d.ts.map +1 -1
  102. package/dist/utils/constants.js +0 -4
  103. package/dist/utils/convertMessagesForAPI.js +2 -2
  104. package/dist/utils/editUtils.d.ts.map +1 -1
  105. package/dist/utils/editUtils.js +2 -2
  106. package/dist/utils/gitUtils.d.ts +7 -0
  107. package/dist/utils/gitUtils.d.ts.map +1 -0
  108. package/dist/utils/gitUtils.js +24 -0
  109. package/dist/utils/messageOperations.d.ts +3 -58
  110. package/dist/utils/messageOperations.d.ts.map +1 -1
  111. package/dist/utils/messageOperations.js +4 -146
  112. package/dist/utils/nameGenerator.d.ts +1 -1
  113. package/dist/utils/nameGenerator.d.ts.map +1 -1
  114. package/dist/utils/nameGenerator.js +19 -3
  115. package/package.json +1 -1
  116. package/src/agent.ts +86 -183
  117. package/src/constants/subagents.ts +4 -0
  118. package/src/constants/tools.ts +4 -1
  119. package/src/index.ts +1 -0
  120. package/src/managers/aiManager.ts +63 -70
  121. package/src/managers/backgroundTaskManager.ts +58 -54
  122. package/src/managers/foregroundTaskManager.ts +3 -2
  123. package/src/managers/mcpManager.ts +6 -3
  124. package/src/managers/messageManager.ts +126 -142
  125. package/src/managers/permissionManager.ts +32 -21
  126. package/src/managers/planManager.ts +2 -2
  127. package/src/managers/reversionManager.ts +26 -2
  128. package/src/managers/slashCommandManager.ts +12 -3
  129. package/src/managers/subagentManager.ts +60 -144
  130. package/src/managers/toolManager.ts +32 -2
  131. package/src/prompts/index.ts +366 -0
  132. package/src/services/aiService.ts +3 -145
  133. package/src/services/memory.ts +0 -72
  134. package/src/services/session.ts +73 -0
  135. package/src/services/taskManager.ts +195 -0
  136. package/src/tools/askUserQuestion.ts +51 -29
  137. package/src/tools/bashTool.ts +15 -17
  138. package/src/tools/editTool.ts +3 -1
  139. package/src/tools/exitPlanMode.ts +27 -3
  140. package/src/tools/globTool.ts +10 -2
  141. package/src/tools/grepTool.ts +17 -6
  142. package/src/tools/lsTool.ts +3 -1
  143. package/src/tools/readTool.ts +17 -1
  144. package/src/tools/taskManagementTools.ts +516 -0
  145. package/src/tools/taskOutputTool.ts +34 -12
  146. package/src/tools/taskStopTool.ts +7 -1
  147. package/src/tools/taskTool.ts +45 -1
  148. package/src/tools/types.ts +12 -0
  149. package/src/tools/writeTool.ts +9 -2
  150. package/src/types/index.ts +1 -0
  151. package/src/types/messaging.ts +1 -21
  152. package/src/types/processes.ts +18 -7
  153. package/src/types/tasks.ts +13 -0
  154. package/src/types/tools.ts +4 -1
  155. package/src/utils/builtinSubagents.ts +81 -45
  156. package/src/utils/cacheControlUtils.ts +26 -18
  157. package/src/utils/constants.ts +0 -5
  158. package/src/utils/convertMessagesForAPI.ts +2 -2
  159. package/src/utils/editUtils.ts +2 -6
  160. package/src/utils/gitUtils.ts +24 -0
  161. package/src/utils/messageOperations.ts +6 -229
  162. package/src/utils/nameGenerator.ts +20 -3
  163. package/dist/constants/prompts.d.ts.map +0 -1
  164. package/dist/constants/prompts.js +0 -118
  165. package/dist/tools/todoWriteTool.d.ts +0 -6
  166. package/dist/tools/todoWriteTool.d.ts.map +0 -1
  167. package/dist/tools/todoWriteTool.js +0 -220
  168. package/src/constants/prompts.ts +0 -155
  169. package/src/tools/todoWriteTool.ts +0 -257
@@ -18,7 +18,7 @@ export const grepTool: ToolPlugin = {
18
18
  type: "function",
19
19
  function: {
20
20
  name: GREP_TOOL_NAME,
21
- description: `A powerful search tool built on ripgrep\n\n Usage:\n - ALWAYS use ${GREP_TOOL_NAME} for search tasks. NEVER invoke \`grep\` or \`rg\` as a ${BASH_TOOL_NAME} command. The ${GREP_TOOL_NAME} tool has been optimized for correct permissions and access.\n - Supports full regex syntax (e.g., "log.*Error", "function\\s+\\w+")\n - Filter files with glob parameter (e.g., "*.js", "**/*.tsx") or type parameter (e.g., "js", "py", "rust")\n - Output modes: "content" shows matching lines, "files_with_matches" shows only file paths (default), "count" shows match counts\n - Use ${TASK_TOOL_NAME} tool for open-ended searches requiring multiple rounds\n - Pattern syntax: Uses ripgrep (not grep) - literal braces need escaping (use \`interface\\{\\}\` to find \`interface{}\` in Go code)\n - Multiline matching: By default patterns match within single lines only. For cross-line patterns like \`struct \\{[\\s\\S]*?field\`, use \`multiline: true\``,
21
+ description: "A powerful search tool built on ripgrep",
22
22
  parameters: {
23
23
  type: "object",
24
24
  properties: {
@@ -61,7 +61,7 @@ export const grepTool: ToolPlugin = {
61
61
  "-n": {
62
62
  type: "boolean",
63
63
  description:
64
- 'Show line numbers in output (rg -n). Requires output_mode: "content", ignored otherwise.',
64
+ 'Show line numbers in output (rg -n). Requires output_mode: "content", ignored otherwise. Defaults to true.',
65
65
  },
66
66
  "-i": {
67
67
  type: "boolean",
@@ -75,7 +75,7 @@ export const grepTool: ToolPlugin = {
75
75
  head_limit: {
76
76
  type: "number",
77
77
  description:
78
- 'Limit output to first N lines/entries, equivalent to "| head -N". Works across all output modes: content (limits output lines), files_with_matches (limits file paths), count (limits count entries). Defaults to 100 to prevent excessive token usage.',
78
+ 'Limit output to first N lines/entries, equivalent to "| head -N". Works across all output modes: content (limits output lines), files_with_matches (limits file paths), count (limits count entries). Defaults to 0 (unlimited).',
79
79
  },
80
80
  multiline: {
81
81
  type: "boolean",
@@ -87,6 +87,17 @@ export const grepTool: ToolPlugin = {
87
87
  },
88
88
  },
89
89
  },
90
+ prompt: () => `A powerful search tool built on ripgrep
91
+
92
+ Usage:
93
+ - ALWAYS use ${GREP_TOOL_NAME} for search tasks. NEVER invoke \`grep\` or \`rg\` as a ${BASH_TOOL_NAME} command. The ${GREP_TOOL_NAME} tool has been optimized for correct permissions and access.
94
+ - Supports full regex syntax (e.g., "log.*Error", "function\\s+\\w+")
95
+ - Filter files with glob parameter (e.g., "*.js", "**/*.tsx") or type parameter (e.g., "js", "py", "rust")
96
+ - Output modes: "content" shows matching lines, "files_with_matches" shows only file paths (default), "count" shows match counts
97
+ - Use ${TASK_TOOL_NAME} tool for open-ended searches requiring multiple rounds
98
+ - Pattern syntax: Uses ripgrep (not grep) - literal braces need escaping (use \`interface\\{\\}\` to find \`interface{}\` in Go code)
99
+ - Multiline matching: By default patterns match within single lines only. For cross-line patterns like \`struct \\{[\\s\\S]*?field\`, use \`multiline: true\`
100
+ `,
90
101
  execute: async (
91
102
  args: Record<string, unknown>,
92
103
  context: ToolContext,
@@ -98,7 +109,7 @@ export const grepTool: ToolPlugin = {
98
109
  const contextBefore = args["-B"] as number;
99
110
  const contextAfter = args["-A"] as number;
100
111
  const contextAround = args["-C"] as number;
101
- const showLineNumbers = args["-n"] as boolean;
112
+ const showLineNumbers = args["-n"] !== false;
102
113
  const caseInsensitive = args["-i"] as boolean;
103
114
  const fileType = args.type as string;
104
115
  const headLimit = args.head_limit as number;
@@ -218,9 +229,9 @@ export const grepTool: ToolPlugin = {
218
229
  let lines = output.split("\n");
219
230
 
220
231
  // Set default head_limit if not specified to prevent excessive token usage
221
- const effectiveHeadLimit = headLimit || 100;
232
+ const effectiveHeadLimit = headLimit || 0;
222
233
 
223
- if (lines.length > effectiveHeadLimit) {
234
+ if (effectiveHeadLimit > 0 && lines.length > effectiveHeadLimit) {
224
235
  lines = lines.slice(0, effectiveHeadLimit);
225
236
  finalOutput = lines.join("\n");
226
237
  }
@@ -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,
@@ -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,516 @@
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
+ if (context.reversionManager && context.messageId) {
118
+ const taskPath = taskManager.getTaskPath(taskId);
119
+ await context.reversionManager.recordSnapshot(
120
+ context.messageId,
121
+ taskPath,
122
+ "create",
123
+ );
124
+ }
125
+
126
+ return {
127
+ success: true,
128
+ content: `Task created with ID: ${taskId}`,
129
+ shortResult: `Created task ${taskId}: ${task.subject}`,
130
+ };
131
+ },
132
+ };
133
+
134
+ export const taskGetTool: ToolPlugin = {
135
+ name: TASK_GET_TOOL_NAME,
136
+ config: {
137
+ type: "function",
138
+ function: {
139
+ name: TASK_GET_TOOL_NAME,
140
+ description: "Get a task by ID from the task list",
141
+ parameters: {
142
+ type: "object",
143
+ properties: {
144
+ taskId: {
145
+ type: "string",
146
+ description: "The ID of the task to retrieve",
147
+ },
148
+ },
149
+ required: ["taskId"],
150
+ },
151
+ },
152
+ },
153
+ prompt: () => `Use this tool to retrieve a task by its ID from the task list.
154
+
155
+ ## When to Use This Tool
156
+
157
+ - When you need the full description and context before starting work on a task
158
+ - To understand task dependencies (what it blocks, what blocks it)
159
+ - After being assigned a task, to get complete requirements
160
+
161
+ ## Output
162
+
163
+ Returns full task details:
164
+ - **subject**: Task title
165
+ - **description**: Detailed requirements and context
166
+ - **status**: 'pending', 'in_progress', or 'completed'
167
+ - **blocks**: Tasks waiting on this one to complete
168
+ - **blockedBy**: Tasks that must complete before this one can start
169
+
170
+ ## Tips
171
+
172
+ - After fetching a task, verify its blockedBy list is empty before beginning work.
173
+ - Use TaskList to see all tasks in summary form.`,
174
+ execute: async (args, context: ToolContext): Promise<ToolResult> => {
175
+ const taskManager = context.taskManager;
176
+ const taskId = args.taskId as string;
177
+
178
+ const task = await taskManager.getTask(taskId);
179
+ if (!task) {
180
+ return {
181
+ success: false,
182
+ content: `Task with ID ${taskId} not found.`,
183
+ };
184
+ }
185
+
186
+ return {
187
+ success: true,
188
+ content: JSON.stringify(task, null, 2),
189
+ };
190
+ },
191
+ };
192
+
193
+ export const taskUpdateTool: ToolPlugin = {
194
+ name: TASK_UPDATE_TOOL_NAME,
195
+ config: {
196
+ type: "function",
197
+ function: {
198
+ name: TASK_UPDATE_TOOL_NAME,
199
+ description: "Update a task in the task list",
200
+ parameters: {
201
+ type: "object",
202
+ properties: {
203
+ taskId: {
204
+ type: "string",
205
+ description: "The ID of the task to update",
206
+ },
207
+ subject: {
208
+ type: "string",
209
+ description: "New subject for the task",
210
+ },
211
+ description: {
212
+ type: "string",
213
+ description: "New description for the task",
214
+ },
215
+ activeForm: {
216
+ type: "string",
217
+ description:
218
+ 'Present continuous form shown in spinner when in_progress (e.g., "Running tests")',
219
+ },
220
+ status: {
221
+ type: "string",
222
+ enum: ["pending", "in_progress", "completed", "deleted"],
223
+ description: "New status for the task",
224
+ },
225
+ addBlocks: {
226
+ type: "array",
227
+ items: { type: "string" },
228
+ description: "Task IDs that this task blocks",
229
+ },
230
+ addBlockedBy: {
231
+ type: "array",
232
+ items: { type: "string" },
233
+ description: "Task IDs that block this task",
234
+ },
235
+ owner: {
236
+ type: "string",
237
+ description: "New owner for the task",
238
+ },
239
+ metadata: {
240
+ type: "object",
241
+ description:
242
+ "Metadata keys to merge into the task. Set a key to null to delete it.",
243
+ },
244
+ },
245
+ required: ["taskId"],
246
+ },
247
+ },
248
+ },
249
+ prompt: () => `Use this tool to update a task in the task list.
250
+
251
+ ## When to Use This Tool
252
+
253
+ **Mark tasks as resolved:**
254
+ - When you have completed the work described in a task
255
+ - When a task is no longer needed or has been superseded
256
+ - IMPORTANT: Always mark your assigned tasks as resolved when you finish them
257
+ - After resolving, call TaskList to find your next task
258
+
259
+ - ONLY mark a task as completed when you have FULLY accomplished it
260
+ - If you encounter errors, blockers, or cannot finish, keep the task as in_progress
261
+ - When blocked, create a new task describing what needs to be resolved
262
+ - Never mark a task as completed if:
263
+ - Tests are failing
264
+ - Implementation is partial
265
+ - You encountered unresolved errors
266
+ - You couldn't find necessary files or dependencies
267
+
268
+ **Delete tasks:**
269
+ - When a task is no longer relevant or was created in error
270
+ - Setting status to \`deleted\` permanently removes the task
271
+
272
+ **Update task details:**
273
+ - When requirements change or become clearer
274
+ - When establishing dependencies between tasks
275
+
276
+ ## Fields You Can Update
277
+
278
+ - **status**: The task status (see Status Workflow below)
279
+ - **subject**: Change the task title (imperative form, e.g., "Run tests")
280
+ - **description**: Change the task description
281
+ - **activeForm**: Present continuous form shown in spinner when in_progress (e.g., "Running tests")
282
+ - **owner**: Change the task owner (agent name)
283
+ - **metadata**: Merge metadata keys into the task (set a key to null to delete it)
284
+ - **addBlocks**: Mark tasks that cannot start until this one completes
285
+ - **addBlockedBy**: Mark tasks that must complete before this one can start
286
+
287
+ ## Status Workflow
288
+
289
+ Status progresses: \`pending\` → \`in_progress\` → \`completed\`
290
+
291
+ Use \`deleted\` to permanently remove a task.
292
+
293
+ ## Staleness
294
+
295
+ Make sure to read a task's latest state using \`TaskGet\` before updating it.
296
+
297
+ ## Examples
298
+
299
+ Mark task as in progress when starting work:
300
+ \`\`\`json
301
+ {"taskId": "1", "status": "in_progress"}
302
+ \`\`\`
303
+
304
+ Mark task as completed after finishing work:
305
+ \`\`\`json
306
+ {"taskId": "1", "status": "completed"}
307
+ \`\`\`
308
+
309
+ Delete a task:
310
+ \`\`\`json
311
+ {"taskId": "1", "status": "deleted"}
312
+ \`\`\`
313
+
314
+ Claim a task by setting owner:
315
+ \`\`\`json
316
+ {"taskId": "1", "owner": "my-name"}
317
+ \`\`\`
318
+
319
+ Set up task dependencies:
320
+ \`\`\`json
321
+ {"taskId": "2", "addBlockedBy": ["1"]}
322
+ \`\`\`
323
+ `,
324
+ execute: async (args, context: ToolContext): Promise<ToolResult> => {
325
+ const taskManager = context.taskManager;
326
+ const taskId = args.taskId as string;
327
+
328
+ const existingTask = await taskManager.getTask(taskId);
329
+ if (!existingTask) {
330
+ return {
331
+ success: false,
332
+ content: `Task with ID ${taskId} not found.`,
333
+ };
334
+ }
335
+
336
+ if (context.reversionManager && context.messageId) {
337
+ const taskPath = taskManager.getTaskPath(taskId);
338
+ await context.reversionManager.recordSnapshot(
339
+ context.messageId,
340
+ taskPath,
341
+ "modify",
342
+ );
343
+ }
344
+
345
+ const updatedFields: string[] = [];
346
+
347
+ const updatedTask: Task = {
348
+ ...existingTask,
349
+ };
350
+
351
+ if (args.subject !== undefined && args.subject !== existingTask.subject) {
352
+ updatedTask.subject = args.subject as string;
353
+ updatedFields.push("subject");
354
+ }
355
+ if (
356
+ args.description !== undefined &&
357
+ args.description !== existingTask.description
358
+ ) {
359
+ updatedTask.description = args.description as string;
360
+ updatedFields.push("description");
361
+ }
362
+ if (args.status !== undefined && args.status !== existingTask.status) {
363
+ updatedTask.status = args.status as TaskStatus;
364
+ updatedFields.push("status");
365
+ }
366
+ if (
367
+ args.activeForm !== undefined &&
368
+ args.activeForm !== existingTask.activeForm
369
+ ) {
370
+ updatedTask.activeForm = args.activeForm as string;
371
+ updatedFields.push("activeForm");
372
+ }
373
+ if (args.owner !== undefined && args.owner !== existingTask.owner) {
374
+ updatedTask.owner = args.owner as string;
375
+ updatedFields.push("owner");
376
+ }
377
+
378
+ if (args.metadata !== undefined) {
379
+ const newMetadata = { ...(existingTask.metadata || {}) };
380
+ for (const [key, value] of Object.entries(
381
+ args.metadata as Record<string, unknown>,
382
+ )) {
383
+ if (value === null) {
384
+ delete newMetadata[key];
385
+ } else {
386
+ newMetadata[key] = value;
387
+ }
388
+ }
389
+ updatedTask.metadata = newMetadata;
390
+ updatedFields.push("metadata");
391
+ }
392
+
393
+ if (args.addBlocks !== undefined) {
394
+ const blocksToAdd = (args.addBlocks as string[]).filter(
395
+ (id) => !updatedTask.blocks.includes(id),
396
+ );
397
+ if (blocksToAdd.length > 0) {
398
+ updatedTask.blocks = [...updatedTask.blocks, ...blocksToAdd];
399
+ updatedFields.push("blocks");
400
+
401
+ // Also update the blockedBy of the target tasks
402
+ for (const targetId of blocksToAdd) {
403
+ const targetTask = await taskManager.getTask(targetId);
404
+ if (targetTask && !targetTask.blockedBy.includes(taskId)) {
405
+ await taskManager.updateTask({
406
+ ...targetTask,
407
+ blockedBy: [...targetTask.blockedBy, taskId],
408
+ });
409
+ }
410
+ }
411
+ }
412
+ }
413
+
414
+ if (args.addBlockedBy !== undefined) {
415
+ const blockedByToAdd = (args.addBlockedBy as string[]).filter(
416
+ (id) => !updatedTask.blockedBy.includes(id),
417
+ );
418
+ if (blockedByToAdd.length > 0) {
419
+ updatedTask.blockedBy = [...updatedTask.blockedBy, ...blockedByToAdd];
420
+ updatedFields.push("blockedBy");
421
+
422
+ // Also update the blocks of the target tasks
423
+ for (const targetId of blockedByToAdd) {
424
+ const targetTask = await taskManager.getTask(targetId);
425
+ if (targetTask && !targetTask.blocks.includes(taskId)) {
426
+ await taskManager.updateTask({
427
+ ...targetTask,
428
+ blocks: [...targetTask.blocks, taskId],
429
+ });
430
+ }
431
+ }
432
+ }
433
+ }
434
+
435
+ await taskManager.updateTask(updatedTask);
436
+
437
+ let content = `Updated task #${taskId} ${updatedFields.join(", ")}`;
438
+ if (updatedTask.status === "completed") {
439
+ content += `\n\nTask completed. Call TaskList now to find your next available task or see if your work unblocked others.`;
440
+ }
441
+
442
+ return {
443
+ success: true,
444
+ content,
445
+ shortResult: `Updated task ${taskId}`,
446
+ };
447
+ },
448
+ };
449
+
450
+ export const taskListTool: ToolPlugin = {
451
+ name: TASK_LIST_TOOL_NAME,
452
+ config: {
453
+ type: "function",
454
+ function: {
455
+ name: TASK_LIST_TOOL_NAME,
456
+ description: "List all tasks in the task list",
457
+ parameters: {
458
+ type: "object",
459
+ properties: {
460
+ status: {
461
+ type: "string",
462
+ enum: ["pending", "in_progress", "completed", "deleted"],
463
+ description: "Optional filter by status.",
464
+ },
465
+ },
466
+ },
467
+ },
468
+ },
469
+ prompt: () => `Use this tool to list all tasks in the task list.
470
+
471
+ ## When to Use This Tool
472
+
473
+ - To see what tasks are available to work on (status: 'pending', no owner, not blocked)
474
+ - To check overall progress on the project
475
+ - To find tasks that are blocked and need dependencies resolved
476
+ - After completing a task, to check for newly unblocked work or claim the next available task
477
+ - **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
478
+
479
+ ## Output
480
+
481
+ Returns a summary of each task:
482
+ - **id**: Task identifier (use with TaskGet, TaskUpdate)
483
+ - **subject**: Brief description of the task
484
+ - **status**: 'pending', 'in_progress', or 'completed'
485
+ - **owner**: Agent ID if assigned, empty if available
486
+ - **blockedBy**: List of open task IDs that must be resolved first (tasks with blockedBy cannot be claimed until dependencies resolve)
487
+
488
+ Use TaskGet with a specific task ID to view full details including description and comments.`,
489
+ execute: async (args, context: ToolContext): Promise<ToolResult> => {
490
+ const taskManager = context.taskManager;
491
+
492
+ let tasks = await taskManager.listTasks();
493
+ if (args.status) {
494
+ tasks = tasks.filter((t) => t.status === args.status);
495
+ }
496
+
497
+ if (tasks.length === 0) {
498
+ return {
499
+ success: true,
500
+ content: "No tasks found.",
501
+ };
502
+ }
503
+
504
+ // Sort by ID numerically
505
+ tasks.sort((a, b) => parseInt(a.id, 10) - parseInt(b.id, 10));
506
+
507
+ const content = tasks
508
+ .map((t) => `[${t.id}] ${t.subject} (${t.status})`)
509
+ .join("\n");
510
+
511
+ return {
512
+ success: true,
513
+ content,
514
+ };
515
+ },
516
+ };