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
@@ -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,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
- };