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
@@ -1,220 +0,0 @@
1
- import { TODO_WRITE_TOOL_NAME } from "../constants/tools.js";
2
- /**
3
- * TodoWrite tool for creating and managing structured task lists
4
- */
5
- export const todoWriteTool = {
6
- name: TODO_WRITE_TOOL_NAME,
7
- config: {
8
- type: "function",
9
- function: {
10
- name: TODO_WRITE_TOOL_NAME,
11
- description: `Use this tool to create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
12
- It also helps the user understand the progress of the task and overall progress of their requests.
13
-
14
- ## When to Use This Tool
15
- Use this tool proactively in these scenarios:
16
-
17
- 1. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
18
- 2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
19
- 3. User explicitly requests todo list - When the user directly asks you to use the todo list
20
- 4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
21
- 5. After receiving new instructions - Immediately capture user requirements as todos
22
- 6. When you start working on a task - Mark it as in_progress BEFORE beginning work. Ideally you should only have one todo as in_progress at a time
23
- 7. After completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation
24
-
25
- ## When NOT to Use This Tool
26
-
27
- Skip using this tool when:
28
- 1. There is only a single, straightforward task
29
- 2. The task is trivial and tracking it provides no organizational benefit
30
- 3. The task can be completed in less than 3 trivial steps
31
- 4. The task is purely conversational or informational
32
-
33
- 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.
34
-
35
- ## Task States and Management
36
-
37
- 1. **Task States**: Use these states to track progress:
38
- - pending: Task not yet started
39
- - in_progress: Currently working on (limit to ONE task at a time)
40
- - completed: Task finished successfully
41
-
42
- 2. **Task Management**:
43
- - Update task status in real-time as you work
44
- - Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
45
- - Only have ONE task in_progress at any time
46
- - Complete current tasks before starting new ones
47
- - Remove tasks that are no longer relevant from the list entirely
48
-
49
- 3. **Task Completion Requirements**:
50
- - ONLY mark a task as completed when you have FULLY accomplished it
51
- - If you encounter errors, blockers, or cannot finish, keep the task as in_progress
52
- - When blocked, create a new task describing what needs to be resolved
53
- - Never mark a task as completed if:
54
- - Tests are failing
55
- - Implementation is partial
56
- - You encountered unresolved errors
57
- - You couldn't find necessary files or dependencies
58
-
59
- 4. **Task Breakdown**:
60
- - Create specific, actionable items
61
- - Break complex tasks into smaller, manageable steps
62
- - Use clear, descriptive task names
63
-
64
- When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.`,
65
- parameters: {
66
- type: "object",
67
- properties: {
68
- todos: {
69
- type: "array",
70
- items: {
71
- type: "object",
72
- properties: {
73
- content: {
74
- type: "string",
75
- minLength: 1,
76
- },
77
- status: {
78
- type: "string",
79
- enum: ["pending", "in_progress", "completed"],
80
- },
81
- id: {
82
- type: "string",
83
- },
84
- },
85
- required: ["content", "status", "id"],
86
- additionalProperties: false,
87
- },
88
- description: "The updated todo list",
89
- },
90
- },
91
- required: ["todos"],
92
- additionalProperties: false,
93
- },
94
- },
95
- },
96
- formatCompactParams: (params, context) => {
97
- void context; // Context not needed for this tool
98
- try {
99
- const { todos } = params;
100
- // Handle invalid or missing tasks array
101
- if (!todos || !Array.isArray(todos)) {
102
- return "invalid todos";
103
- }
104
- // Handle empty task list
105
- if (todos.length === 0) {
106
- return "0 tasks";
107
- }
108
- // Count completed tasks
109
- const completedCount = todos.filter((todo) => todo && todo.status === "completed").length;
110
- const totalCount = todos.length;
111
- // Format with proper singular/plural
112
- const taskWord = totalCount === 1 ? "task" : "tasks";
113
- return `${completedCount}/${totalCount} ${taskWord}`;
114
- }
115
- catch {
116
- return "invalid todos";
117
- }
118
- },
119
- execute: async (args) => {
120
- try {
121
- // Validate arguments
122
- const { todos } = args;
123
- if (!todos || !Array.isArray(todos)) {
124
- return {
125
- success: false,
126
- content: "",
127
- error: "todos parameter must be an array",
128
- shortResult: "Invalid todos format",
129
- };
130
- }
131
- // Validate each task item
132
- for (const [index, todo] of todos.entries()) {
133
- if (!todo || typeof todo !== "object") {
134
- return {
135
- success: false,
136
- content: "",
137
- error: `Todo item at index ${index} must be an object`,
138
- shortResult: "Invalid todo item",
139
- };
140
- }
141
- if (!todo.content ||
142
- typeof todo.content !== "string" ||
143
- todo.content.trim().length === 0) {
144
- return {
145
- success: false,
146
- content: "",
147
- error: `Todo item at index ${index} must have non-empty content`,
148
- shortResult: "Invalid todo content",
149
- };
150
- }
151
- if (!["pending", "in_progress", "completed"].includes(todo.status)) {
152
- return {
153
- success: false,
154
- content: "",
155
- error: `Todo item at index ${index} has invalid status: ${todo.status}`,
156
- shortResult: "Invalid todo status",
157
- };
158
- }
159
- if (!todo.id ||
160
- typeof todo.id !== "string" ||
161
- todo.id.trim().length === 0) {
162
- return {
163
- success: false,
164
- content: "",
165
- error: `Todo item at index ${index} must have a non-empty id`,
166
- shortResult: "Invalid todo id",
167
- };
168
- }
169
- }
170
- // Check for duplicate IDs
171
- const ids = todos.map((todo) => todo.id);
172
- const duplicateIds = ids.filter((id, index) => ids.indexOf(id) !== index);
173
- if (duplicateIds.length > 0) {
174
- return {
175
- success: false,
176
- content: "",
177
- error: `Duplicate todo IDs found: ${duplicateIds.join(", ")}`,
178
- shortResult: "Duplicate todo IDs",
179
- };
180
- }
181
- // Check that only one task is in_progress
182
- const inProgressTodos = todos.filter((todo) => todo.status === "in_progress");
183
- if (inProgressTodos.length > 1) {
184
- return {
185
- success: false,
186
- content: "",
187
- error: `Only one todo can be in_progress at a time. Found ${inProgressTodos.length} in_progress todos`,
188
- shortResult: "Multiple in_progress todos",
189
- };
190
- }
191
- const completedCount = todos.filter((t) => t.status === "completed").length;
192
- const totalCount = todos.length;
193
- let shortResult = `${completedCount}/${totalCount} done`;
194
- if (totalCount > 0) {
195
- const symbols = {
196
- pending: "[ ]",
197
- in_progress: "[>]",
198
- completed: "[x]",
199
- };
200
- // Show all todos in the shortResult
201
- for (const todo of todos) {
202
- shortResult += `\n${symbols[todo.status]} ${todo.content}`;
203
- }
204
- }
205
- return {
206
- success: true,
207
- content: `Todo list updated: ${completedCount}/${totalCount} completed`,
208
- shortResult: shortResult,
209
- };
210
- }
211
- catch (error) {
212
- return {
213
- success: false,
214
- content: "",
215
- error: error instanceof Error ? error.message : String(error),
216
- shortResult: "Todo list update failed",
217
- };
218
- }
219
- },
220
- };
@@ -1,155 +0,0 @@
1
- import {
2
- ASK_USER_QUESTION_TOOL_NAME,
3
- BASH_TOOL_NAME,
4
- EDIT_TOOL_NAME,
5
- GLOB_TOOL_NAME,
6
- GREP_TOOL_NAME,
7
- LS_TOOL_NAME,
8
- MULTI_EDIT_TOOL_NAME,
9
- READ_TOOL_NAME,
10
- TASK_TOOL_NAME,
11
- TODO_WRITE_TOOL_NAME,
12
- WRITE_TOOL_NAME,
13
- } from "./tools.js";
14
-
15
- export const BASE_SYSTEM_PROMPT = `You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
16
-
17
- # Doing tasks
18
- The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended:
19
- - NEVER propose changes to code you haven't read. If a user asks about or wants you to modify a file, read it first. Understand existing code before suggesting modifications.
20
- - Be careful not to introduce security vulnerabilities such as command injection, XSS, SQL injection, and other OWASP top 10 vulnerabilities. If you notice that you wrote insecure code, immediately fix it.
21
- - Avoid over-engineering. Only make changes that are directly requested or clearly necessary. Keep solutions simple and focused.
22
- - Don't add features, refactor code, or make "improvements" beyond what was asked. A bug fix doesn't need surrounding code cleaned up. A simple feature doesn't need extra configurability. Don't add docstrings, comments, or type annotations to code you didn't change. Only add comments where the logic isn't self-evident.
23
- - Don't add error handling, fallbacks, or validation for scenarios that can't happen. Trust internal code and framework guarantees. Only validate at system boundaries (user input, external APIs). Don't use feature flags or backwards-compatibility shims when you can just change the code.
24
- - Don't create helpers, utilities, or abstractions for one-time operations. Don't design for hypothetical future requirements. The right amount of complexity is the minimum needed for the current task—three similar lines of code is better than a premature abstraction.
25
- - Avoid backwards-compatibility hacks like renaming unused \`_vars\`, re-exporting types, adding \`// removed\` comments for removed code, etc. If something is unused, delete it completely.
26
-
27
- # Tool usage policy
28
- - You can call multiple tools in a single response. If you intend to call multiple tools and there are no dependencies between them, make all independent tool calls in parallel. Maximize use of parallel tool calls where possible to increase efficiency.
29
- - However, if some tool calls depend on previous calls to inform dependent values, do NOT call these tools in parallel and instead call them sequentially. For instance, if one operation must complete before another starts, run these operations sequentially instead. Never use placeholders or guess missing parameters in tool calls.
30
- - If the user specifies that they want you to run tools "in parallel", you MUST send a single message with multiple tool use content blocks.`;
31
-
32
- export const TASK_MANAGEMENT_POLICY = `
33
- # Task Management
34
- You have access to the ${TODO_WRITE_TOOL_NAME} tools to help you manage and plan tasks. Use these tools VERY frequently to ensure that you are tracking your tasks and giving the user visibility into your progress.
35
- These tools are also EXTREMELY helpful for planning tasks, and for breaking down larger complex tasks into smaller steps. If you do not use this tool when planning, you may forget to do important tasks - and that is unacceptable.
36
- It is critical that you mark todos as completed as soon as you are done with a task. Do not batch up multiple tasks before marking them as completed.`;
37
-
38
- export const ASK_USER_POLICY = `
39
- # Asking questions as you work
40
- You have access to the ${ASK_USER_QUESTION_TOOL_NAME} tool to ask the user questions when you need clarification, want to validate assumptions, or need to make a decision you're unsure about. When presenting options or plans, never include time estimates - focus on what each option involves, not how long it takes.`;
41
-
42
- export const SUBAGENT_POLICY = `
43
- - When doing file search, prefer to use the ${TASK_TOOL_NAME} tool in order to reduce context usage.
44
- - You should proactively use the ${TASK_TOOL_NAME} tool with specialized agents when the task at hand matches the agent's description.
45
- - 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.`;
46
-
47
- export const FILE_TOOL_POLICY_PREFIX = `\n- Use specialized tools instead of bash commands when possible, as this provides a better user experience. For file operations, use dedicated tools:`;
48
- export const READ_FILE_POLICY = ` ${READ_TOOL_NAME} for reading files instead of cat/head/tail`;
49
- export const EDIT_FILE_POLICY = ` ${EDIT_TOOL_NAME}/${MULTI_EDIT_TOOL_NAME} for editing instead of sed/awk`;
50
- export const WRITE_FILE_POLICY = ` ${WRITE_TOOL_NAME} for creating files instead of cat with heredoc or echo redirection`;
51
- export const SEARCH_FILE_POLICY = ` ${LS_TOOL_NAME}/${GLOB_TOOL_NAME}/${GREP_TOOL_NAME} for searching and listing files instead of find/ls/grep`;
52
-
53
- export const BASH_POLICY = `
54
- - Reserve bash tools exclusively for actual system commands and terminal operations that require shell execution. NEVER use bash echo or other command-line tools to communicate thoughts, explanations, or instructions to the user. Output all communication directly in your response text instead.
55
- - When making multiple bash tool calls, you MUST send a single message with multiple tools calls to run the calls in parallel. For example, if you need to run "git status" and "git diff", send a single message with two tool calls to run the calls in parallel.`;
56
-
57
- export const DEFAULT_SYSTEM_PROMPT = BASE_SYSTEM_PROMPT;
58
-
59
- export const GENERAL_PURPOSE_SYSTEM_PROMPT = `You are an agent. Given the user's message, you should use the tools available to complete the task. Do what has been asked; nothing more, nothing less. When you complete the task simply respond with a detailed writeup.
60
-
61
- Your strengths:
62
- - Searching for code, configurations, and patterns across large codebases
63
- - Analyzing multiple files to understand system architecture
64
- - Investigating complex questions that require exploring many files
65
- - Performing multi-step research tasks
66
-
67
- Guidelines:
68
- - For file searches: Use Grep or Glob when you need to search broadly. Use Read when you know the specific file path.
69
- - For analysis: Start broad and narrow down. Use multiple search strategies if the first doesn't yield results.
70
- - Be thorough: Check multiple locations, consider different naming conventions, look for related files.
71
- - NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one.
72
- - NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested.
73
- - In your final response always share relevant file names and code snippets. Any file paths you return in your response MUST be absolute. Do NOT use relative paths.
74
- - For clear communication, avoid using emojis.`;
75
-
76
- export const INIT_PROMPT = `Please analyze this codebase and create a AGENTS.md file, which will be given to future instances of Agent to operate in this repository.
77
-
78
- What to add:
79
- 1. Commands that will be commonly used, such as how to build, lint, and run tests. Include the necessary commands to develop in this codebase, such as how to run a single test.
80
- 2. High-level code architecture and structure so that future instances can be productive more quickly. Focus on the "big picture" architecture that requires reading multiple files to understand.
81
-
82
- Usage notes:
83
- - If there's already a AGENTS.md, suggest improvements to it.
84
- - When you make the initial AGENTS.md, do not repeat yourself and do not include obvious instructions like "Provide helpful error messages to users", "Write unit tests for all new utilities", "Never include sensitive information (API keys, tokens) in code or commits".
85
- - Avoid listing every component or file structure that can be easily discovered.
86
- - Don't include generic development practices.
87
- - If there are Cursor rules (in .cursor/rules/ or .cursorrules) or Copilot rules (in .github/copilot-instructions.md), make sure to include the important parts.
88
- - If there is a README.md, make sure to include the important parts.
89
- - Do not make up information such as "Common Development Tasks", "Tips for Development", "Support and Documentation" unless this is expressly included in other files that you read.
90
- - Be sure to prefix the file with the following text:
91
-
92
- \`\`\`
93
- # AGENTS.md
94
-
95
- This file provides guidance to Agent when working with code in this repository.
96
- \`\`\``;
97
-
98
- export function buildSystemPrompt(
99
- basePrompt: string,
100
- tools: { name?: string; function?: { name: string } }[],
101
- ): string {
102
- let prompt = basePrompt;
103
- const toolNames = new Set(
104
- tools.map((t) => t.function?.name || t.name).filter(Boolean),
105
- );
106
-
107
- if (toolNames.has(TODO_WRITE_TOOL_NAME)) {
108
- prompt += TASK_MANAGEMENT_POLICY;
109
- }
110
- if (toolNames.has(ASK_USER_QUESTION_TOOL_NAME)) {
111
- prompt += ASK_USER_POLICY;
112
- }
113
-
114
- if (toolNames.has(TASK_TOOL_NAME)) {
115
- prompt += SUBAGENT_POLICY;
116
- }
117
-
118
- if (
119
- toolNames.has(READ_TOOL_NAME) ||
120
- toolNames.has(EDIT_TOOL_NAME) ||
121
- toolNames.has(MULTI_EDIT_TOOL_NAME) ||
122
- toolNames.has(WRITE_TOOL_NAME) ||
123
- toolNames.has(LS_TOOL_NAME) ||
124
- toolNames.has(GLOB_TOOL_NAME) ||
125
- toolNames.has(GREP_TOOL_NAME)
126
- ) {
127
- const parts: string[] = [];
128
- if (toolNames.has(READ_TOOL_NAME)) {
129
- parts.push(READ_FILE_POLICY);
130
- }
131
- if (toolNames.has(EDIT_TOOL_NAME) || toolNames.has(MULTI_EDIT_TOOL_NAME)) {
132
- parts.push(EDIT_FILE_POLICY);
133
- }
134
- if (toolNames.has(WRITE_TOOL_NAME)) {
135
- parts.push(WRITE_FILE_POLICY);
136
- }
137
- if (
138
- toolNames.has(LS_TOOL_NAME) ||
139
- toolNames.has(GLOB_TOOL_NAME) ||
140
- toolNames.has(GREP_TOOL_NAME)
141
- ) {
142
- parts.push(SEARCH_FILE_POLICY);
143
- }
144
-
145
- if (parts.length > 0) {
146
- prompt += FILE_TOOL_POLICY_PREFIX + parts.join(",") + ".";
147
- }
148
- }
149
-
150
- if (toolNames.has(BASH_TOOL_NAME)) {
151
- prompt += BASH_POLICY;
152
- }
153
-
154
- return prompt;
155
- }
@@ -1,257 +0,0 @@
1
- import type { ToolPlugin, ToolResult, ToolContext } from "./types.js";
2
- import { TODO_WRITE_TOOL_NAME } from "../constants/tools.js";
3
-
4
- interface TodoItem {
5
- content: string;
6
- status: "pending" | "in_progress" | "completed";
7
- id: string;
8
- }
9
-
10
- /**
11
- * TodoWrite tool for creating and managing structured task lists
12
- */
13
- export const todoWriteTool: ToolPlugin = {
14
- name: TODO_WRITE_TOOL_NAME,
15
- config: {
16
- type: "function",
17
- function: {
18
- name: TODO_WRITE_TOOL_NAME,
19
- description: `Use this tool to create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
20
- It also helps the user understand the progress of the task and overall progress of their requests.
21
-
22
- ## When to Use This Tool
23
- Use this tool proactively in these scenarios:
24
-
25
- 1. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
26
- 2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
27
- 3. User explicitly requests todo list - When the user directly asks you to use the todo list
28
- 4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
29
- 5. After receiving new instructions - Immediately capture user requirements as todos
30
- 6. When you start working on a task - Mark it as in_progress BEFORE beginning work. Ideally you should only have one todo as in_progress at a time
31
- 7. After completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation
32
-
33
- ## When NOT to Use This Tool
34
-
35
- Skip using this tool when:
36
- 1. There is only a single, straightforward task
37
- 2. The task is trivial and tracking it provides no organizational benefit
38
- 3. The task can be completed in less than 3 trivial steps
39
- 4. The task is purely conversational or informational
40
-
41
- 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.
42
-
43
- ## Task States and Management
44
-
45
- 1. **Task States**: Use these states to track progress:
46
- - pending: Task not yet started
47
- - in_progress: Currently working on (limit to ONE task at a time)
48
- - completed: Task finished successfully
49
-
50
- 2. **Task Management**:
51
- - Update task status in real-time as you work
52
- - Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
53
- - Only have ONE task in_progress at any time
54
- - Complete current tasks before starting new ones
55
- - Remove tasks that are no longer relevant from the list entirely
56
-
57
- 3. **Task Completion Requirements**:
58
- - ONLY mark a task as completed when you have FULLY accomplished it
59
- - If you encounter errors, blockers, or cannot finish, keep the task as in_progress
60
- - When blocked, create a new task describing what needs to be resolved
61
- - Never mark a task as completed if:
62
- - Tests are failing
63
- - Implementation is partial
64
- - You encountered unresolved errors
65
- - You couldn't find necessary files or dependencies
66
-
67
- 4. **Task Breakdown**:
68
- - Create specific, actionable items
69
- - Break complex tasks into smaller, manageable steps
70
- - Use clear, descriptive task names
71
-
72
- When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.`,
73
- parameters: {
74
- type: "object",
75
- properties: {
76
- todos: {
77
- type: "array",
78
- items: {
79
- type: "object",
80
- properties: {
81
- content: {
82
- type: "string",
83
- minLength: 1,
84
- },
85
- status: {
86
- type: "string",
87
- enum: ["pending", "in_progress", "completed"],
88
- },
89
- id: {
90
- type: "string",
91
- },
92
- },
93
- required: ["content", "status", "id"],
94
- additionalProperties: false,
95
- },
96
- description: "The updated todo list",
97
- },
98
- },
99
- required: ["todos"],
100
- additionalProperties: false,
101
- },
102
- },
103
- },
104
-
105
- formatCompactParams: (
106
- params: Record<string, unknown>,
107
- context: ToolContext,
108
- ) => {
109
- void context; // Context not needed for this tool
110
- try {
111
- const { todos } = params as { todos?: TodoItem[] };
112
-
113
- // Handle invalid or missing tasks array
114
- if (!todos || !Array.isArray(todos)) {
115
- return "invalid todos";
116
- }
117
-
118
- // Handle empty task list
119
- if (todos.length === 0) {
120
- return "0 tasks";
121
- }
122
-
123
- // Count completed tasks
124
- const completedCount = todos.filter(
125
- (todo) => todo && todo.status === "completed",
126
- ).length;
127
- const totalCount = todos.length;
128
-
129
- // Format with proper singular/plural
130
- const taskWord = totalCount === 1 ? "task" : "tasks";
131
- return `${completedCount}/${totalCount} ${taskWord}`;
132
- } catch {
133
- return "invalid todos";
134
- }
135
- },
136
-
137
- execute: async (args: Record<string, unknown>): Promise<ToolResult> => {
138
- try {
139
- // Validate arguments
140
- const { todos } = args as { todos?: TodoItem[] };
141
-
142
- if (!todos || !Array.isArray(todos)) {
143
- return {
144
- success: false,
145
- content: "",
146
- error: "todos parameter must be an array",
147
- shortResult: "Invalid todos format",
148
- };
149
- }
150
-
151
- // Validate each task item
152
- for (const [index, todo] of todos.entries()) {
153
- if (!todo || typeof todo !== "object") {
154
- return {
155
- success: false,
156
- content: "",
157
- error: `Todo item at index ${index} must be an object`,
158
- shortResult: "Invalid todo item",
159
- };
160
- }
161
-
162
- if (
163
- !todo.content ||
164
- typeof todo.content !== "string" ||
165
- todo.content.trim().length === 0
166
- ) {
167
- return {
168
- success: false,
169
- content: "",
170
- error: `Todo item at index ${index} must have non-empty content`,
171
- shortResult: "Invalid todo content",
172
- };
173
- }
174
-
175
- if (!["pending", "in_progress", "completed"].includes(todo.status)) {
176
- return {
177
- success: false,
178
- content: "",
179
- error: `Todo item at index ${index} has invalid status: ${todo.status}`,
180
- shortResult: "Invalid todo status",
181
- };
182
- }
183
-
184
- if (
185
- !todo.id ||
186
- typeof todo.id !== "string" ||
187
- todo.id.trim().length === 0
188
- ) {
189
- return {
190
- success: false,
191
- content: "",
192
- error: `Todo item at index ${index} must have a non-empty id`,
193
- shortResult: "Invalid todo id",
194
- };
195
- }
196
- }
197
-
198
- // Check for duplicate IDs
199
- const ids = todos.map((todo) => todo.id);
200
- const duplicateIds = ids.filter((id, index) => ids.indexOf(id) !== index);
201
- if (duplicateIds.length > 0) {
202
- return {
203
- success: false,
204
- content: "",
205
- error: `Duplicate todo IDs found: ${duplicateIds.join(", ")}`,
206
- shortResult: "Duplicate todo IDs",
207
- };
208
- }
209
-
210
- // Check that only one task is in_progress
211
- const inProgressTodos = todos.filter(
212
- (todo) => todo.status === "in_progress",
213
- );
214
- if (inProgressTodos.length > 1) {
215
- return {
216
- success: false,
217
- content: "",
218
- error: `Only one todo can be in_progress at a time. Found ${inProgressTodos.length} in_progress todos`,
219
- shortResult: "Multiple in_progress todos",
220
- };
221
- }
222
-
223
- const completedCount = todos.filter(
224
- (t) => t.status === "completed",
225
- ).length;
226
- const totalCount = todos.length;
227
-
228
- let shortResult = `${completedCount}/${totalCount} done`;
229
-
230
- if (totalCount > 0) {
231
- const symbols = {
232
- pending: "[ ]",
233
- in_progress: "[>]",
234
- completed: "[x]",
235
- };
236
-
237
- // Show all todos in the shortResult
238
- for (const todo of todos) {
239
- shortResult += `\n${symbols[todo.status]} ${todo.content}`;
240
- }
241
- }
242
-
243
- return {
244
- success: true,
245
- content: `Todo list updated: ${completedCount}/${totalCount} completed`,
246
- shortResult: shortResult,
247
- };
248
- } catch (error) {
249
- return {
250
- success: false,
251
- content: "",
252
- error: error instanceof Error ? error.message : String(error),
253
- shortResult: "Todo list update failed",
254
- };
255
- }
256
- },
257
- };