@hyperwindmill/caretaker-cli 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (275) hide show
  1. package/LICENSE +110 -0
  2. package/README.md +25 -0
  3. package/dist/agents/dispatch.d.ts +35 -0
  4. package/dist/agents/dispatch.d.ts.map +1 -0
  5. package/dist/agents/dispatch.js +108 -0
  6. package/dist/agents/sync.d.ts +10 -0
  7. package/dist/agents/sync.d.ts.map +1 -0
  8. package/dist/agents/sync.js +95 -0
  9. package/dist/cli/index.d.ts +2 -0
  10. package/dist/cli/index.d.ts.map +1 -0
  11. package/dist/cli/index.js +50 -0
  12. package/dist/cli/run.d.ts +11 -0
  13. package/dist/cli/run.d.ts.map +1 -0
  14. package/dist/cli/run.js +89 -0
  15. package/dist/cli/web/fs.d.ts +3 -0
  16. package/dist/cli/web/fs.d.ts.map +1 -0
  17. package/dist/cli/web/fs.js +35 -0
  18. package/dist/cli/web/mcp_bridge.d.ts +7 -0
  19. package/dist/cli/web/mcp_bridge.d.ts.map +1 -0
  20. package/dist/cli/web/mcp_bridge.js +86 -0
  21. package/dist/cli/web/scheduler/heartbeat.d.ts +16 -0
  22. package/dist/cli/web/scheduler/heartbeat.d.ts.map +1 -0
  23. package/dist/cli/web/scheduler/heartbeat.js +181 -0
  24. package/dist/cli/web/scheduler/locks.d.ts +8 -0
  25. package/dist/cli/web/scheduler/locks.d.ts.map +1 -0
  26. package/dist/cli/web/scheduler/locks.js +7 -0
  27. package/dist/cli/web/scheduler/logs.d.ts +21 -0
  28. package/dist/cli/web/scheduler/logs.d.ts.map +1 -0
  29. package/dist/cli/web/scheduler/logs.js +62 -0
  30. package/dist/cli/web/scheduler/strategy.d.ts +6 -0
  31. package/dist/cli/web/scheduler/strategy.d.ts.map +1 -0
  32. package/dist/cli/web/scheduler/strategy.js +1 -0
  33. package/dist/cli/web/scheduler/task_review.d.ts +18 -0
  34. package/dist/cli/web/scheduler/task_review.d.ts.map +1 -0
  35. package/dist/cli/web/scheduler/task_review.js +77 -0
  36. package/dist/cli/web/scheduler/task_roles.d.ts +22 -0
  37. package/dist/cli/web/scheduler/task_roles.d.ts.map +1 -0
  38. package/dist/cli/web/scheduler/task_roles.js +70 -0
  39. package/dist/cli/web/scheduler/task_strategy.d.ts +2 -0
  40. package/dist/cli/web/scheduler/task_strategy.d.ts.map +1 -0
  41. package/dist/cli/web/scheduler/task_strategy.js +437 -0
  42. package/dist/cli/web/scheduler/telegram.d.ts +7 -0
  43. package/dist/cli/web/scheduler/telegram.d.ts.map +1 -0
  44. package/dist/cli/web/scheduler/telegram.js +393 -0
  45. package/dist/cli/web/scheduler.d.ts +15 -0
  46. package/dist/cli/web/scheduler.d.ts.map +1 -0
  47. package/dist/cli/web/scheduler.js +60 -0
  48. package/dist/cli/web/server.d.ts +38 -0
  49. package/dist/cli/web/server.d.ts.map +1 -0
  50. package/dist/cli/web/server.js +970 -0
  51. package/dist/commands/loader.d.ts +37 -0
  52. package/dist/commands/loader.d.ts.map +1 -0
  53. package/dist/commands/loader.js +110 -0
  54. package/dist/harness/claude_code_runner.d.ts +47 -0
  55. package/dist/harness/claude_code_runner.d.ts.map +1 -0
  56. package/dist/harness/claude_code_runner.js +325 -0
  57. package/dist/harness/claude_code_stream.d.ts +32 -0
  58. package/dist/harness/claude_code_stream.d.ts.map +1 -0
  59. package/dist/harness/claude_code_stream.js +121 -0
  60. package/dist/harness/context_files.d.ts +23 -0
  61. package/dist/harness/context_files.d.ts.map +1 -0
  62. package/dist/harness/context_files.js +126 -0
  63. package/dist/harness/history.d.ts +4 -0
  64. package/dist/harness/history.d.ts.map +1 -0
  65. package/dist/harness/history.js +120 -0
  66. package/dist/harness/index.d.ts +8 -0
  67. package/dist/harness/index.d.ts.map +1 -0
  68. package/dist/harness/index.js +8 -0
  69. package/dist/harness/loop.d.ts +73 -0
  70. package/dist/harness/loop.d.ts.map +1 -0
  71. package/dist/harness/loop.js +373 -0
  72. package/dist/harness/model_limits.d.ts +25 -0
  73. package/dist/harness/model_limits.d.ts.map +1 -0
  74. package/dist/harness/model_limits.js +67 -0
  75. package/dist/harness/models.d.ts +9 -0
  76. package/dist/harness/models.d.ts.map +1 -0
  77. package/dist/harness/models.js +38 -0
  78. package/dist/harness/prelude.d.ts +21 -0
  79. package/dist/harness/prelude.d.ts.map +1 -0
  80. package/dist/harness/prelude.js +41 -0
  81. package/dist/harness/provider.d.ts +87 -0
  82. package/dist/harness/provider.d.ts.map +1 -0
  83. package/dist/harness/provider.js +140 -0
  84. package/dist/harness/runtime_info.d.ts +7 -0
  85. package/dist/harness/runtime_info.d.ts.map +1 -0
  86. package/dist/harness/runtime_info.js +15 -0
  87. package/dist/harness/think_tag_splitter.d.ts +33 -0
  88. package/dist/harness/think_tag_splitter.d.ts.map +1 -0
  89. package/dist/harness/think_tag_splitter.js +70 -0
  90. package/dist/harness/title.d.ts +17 -0
  91. package/dist/harness/title.d.ts.map +1 -0
  92. package/dist/harness/title.js +75 -0
  93. package/dist/harness/tools/builtin/bash.d.ts +3 -0
  94. package/dist/harness/tools/builtin/bash.d.ts.map +1 -0
  95. package/dist/harness/tools/builtin/bash.js +137 -0
  96. package/dist/harness/tools/builtin/edit.d.ts +6 -0
  97. package/dist/harness/tools/builtin/edit.d.ts.map +1 -0
  98. package/dist/harness/tools/builtin/edit.js +85 -0
  99. package/dist/harness/tools/builtin/fetch.d.ts +3 -0
  100. package/dist/harness/tools/builtin/fetch.d.ts.map +1 -0
  101. package/dist/harness/tools/builtin/fetch.js +75 -0
  102. package/dist/harness/tools/builtin/get_agent_context.d.ts +3 -0
  103. package/dist/harness/tools/builtin/get_agent_context.d.ts.map +1 -0
  104. package/dist/harness/tools/builtin/get_agent_context.js +76 -0
  105. package/dist/harness/tools/builtin/glob.d.ts +3 -0
  106. package/dist/harness/tools/builtin/glob.d.ts.map +1 -0
  107. package/dist/harness/tools/builtin/glob.js +52 -0
  108. package/dist/harness/tools/builtin/grep.d.ts +3 -0
  109. package/dist/harness/tools/builtin/grep.d.ts.map +1 -0
  110. package/dist/harness/tools/builtin/grep.js +126 -0
  111. package/dist/harness/tools/builtin/index.d.ts +23 -0
  112. package/dist/harness/tools/builtin/index.d.ts.map +1 -0
  113. package/dist/harness/tools/builtin/index.js +74 -0
  114. package/dist/harness/tools/builtin/invoke_agent.d.ts +3 -0
  115. package/dist/harness/tools/builtin/invoke_agent.d.ts.map +1 -0
  116. package/dist/harness/tools/builtin/invoke_agent.js +106 -0
  117. package/dist/harness/tools/builtin/invoke_command.d.ts +3 -0
  118. package/dist/harness/tools/builtin/invoke_command.d.ts.map +1 -0
  119. package/dist/harness/tools/builtin/invoke_command.js +42 -0
  120. package/dist/harness/tools/builtin/list_agents.d.ts +3 -0
  121. package/dist/harness/tools/builtin/list_agents.d.ts.map +1 -0
  122. package/dist/harness/tools/builtin/list_agents.js +32 -0
  123. package/dist/harness/tools/builtin/list_commands.d.ts +3 -0
  124. package/dist/harness/tools/builtin/list_commands.d.ts.map +1 -0
  125. package/dist/harness/tools/builtin/list_commands.js +27 -0
  126. package/dist/harness/tools/builtin/list_skills.d.ts +3 -0
  127. package/dist/harness/tools/builtin/list_skills.d.ts.map +1 -0
  128. package/dist/harness/tools/builtin/list_skills.js +24 -0
  129. package/dist/harness/tools/builtin/multiedit.d.ts +3 -0
  130. package/dist/harness/tools/builtin/multiedit.d.ts.map +1 -0
  131. package/dist/harness/tools/builtin/multiedit.js +88 -0
  132. package/dist/harness/tools/builtin/read_attachment.d.ts +3 -0
  133. package/dist/harness/tools/builtin/read_attachment.d.ts.map +1 -0
  134. package/dist/harness/tools/builtin/read_attachment.js +128 -0
  135. package/dist/harness/tools/builtin/read_document.d.ts +37 -0
  136. package/dist/harness/tools/builtin/read_document.d.ts.map +1 -0
  137. package/dist/harness/tools/builtin/read_document.js +238 -0
  138. package/dist/harness/tools/builtin/read_file.d.ts +3 -0
  139. package/dist/harness/tools/builtin/read_file.d.ts.map +1 -0
  140. package/dist/harness/tools/builtin/read_file.js +141 -0
  141. package/dist/harness/tools/builtin/read_image.d.ts +3 -0
  142. package/dist/harness/tools/builtin/read_image.d.ts.map +1 -0
  143. package/dist/harness/tools/builtin/read_image.js +80 -0
  144. package/dist/harness/tools/builtin/read_skill.d.ts +3 -0
  145. package/dist/harness/tools/builtin/read_skill.d.ts.map +1 -0
  146. package/dist/harness/tools/builtin/read_skill.js +30 -0
  147. package/dist/harness/tools/builtin/shell-env.d.ts +55 -0
  148. package/dist/harness/tools/builtin/shell-env.d.ts.map +1 -0
  149. package/dist/harness/tools/builtin/shell-env.js +181 -0
  150. package/dist/harness/tools/builtin/task_tools.d.ts +21 -0
  151. package/dist/harness/tools/builtin/task_tools.d.ts.map +1 -0
  152. package/dist/harness/tools/builtin/task_tools.js +708 -0
  153. package/dist/harness/tools/builtin/write.d.ts +3 -0
  154. package/dist/harness/tools/builtin/write.d.ts.map +1 -0
  155. package/dist/harness/tools/builtin/write.js +56 -0
  156. package/dist/harness/tools/index.d.ts +6 -0
  157. package/dist/harness/tools/index.d.ts.map +1 -0
  158. package/dist/harness/tools/index.js +7 -0
  159. package/dist/harness/tools/instance.d.ts +3 -0
  160. package/dist/harness/tools/instance.d.ts.map +1 -0
  161. package/dist/harness/tools/instance.js +19 -0
  162. package/dist/harness/tools/registry.d.ts +21 -0
  163. package/dist/harness/tools/registry.d.ts.map +1 -0
  164. package/dist/harness/tools/registry.js +33 -0
  165. package/dist/harness/tools/resolve.d.ts +5 -0
  166. package/dist/harness/tools/resolve.d.ts.map +1 -0
  167. package/dist/harness/tools/resolve.js +60 -0
  168. package/dist/harness/tools/sandbox.d.ts +6 -0
  169. package/dist/harness/tools/sandbox.d.ts.map +1 -0
  170. package/dist/harness/tools/sandbox.js +23 -0
  171. package/dist/harness/tools/types.d.ts +80 -0
  172. package/dist/harness/tools/types.d.ts.map +1 -0
  173. package/dist/harness/tools/types.js +16 -0
  174. package/dist/index.d.ts +3 -0
  175. package/dist/index.d.ts.map +1 -0
  176. package/dist/index.js +46 -0
  177. package/dist/lib/encryption.d.ts +24 -0
  178. package/dist/lib/encryption.d.ts.map +1 -0
  179. package/dist/lib/encryption.js +163 -0
  180. package/dist/lib/open_url.d.ts +9 -0
  181. package/dist/lib/open_url.d.ts.map +1 -0
  182. package/dist/lib/open_url.js +23 -0
  183. package/dist/lib/task_git.d.ts +11 -0
  184. package/dist/lib/task_git.d.ts.map +1 -0
  185. package/dist/lib/task_git.js +100 -0
  186. package/dist/mcp/adapter.d.ts +9 -0
  187. package/dist/mcp/adapter.d.ts.map +1 -0
  188. package/dist/mcp/adapter.js +74 -0
  189. package/dist/mcp/client.d.ts +50 -0
  190. package/dist/mcp/client.d.ts.map +1 -0
  191. package/dist/mcp/client.js +243 -0
  192. package/dist/mcp/oauth.d.ts +30 -0
  193. package/dist/mcp/oauth.d.ts.map +1 -0
  194. package/dist/mcp/oauth.js +171 -0
  195. package/dist/mcp/oauth_callback.d.ts +9 -0
  196. package/dist/mcp/oauth_callback.d.ts.map +1 -0
  197. package/dist/mcp/oauth_callback.js +51 -0
  198. package/dist/mcp/oauth_store.d.ts +22 -0
  199. package/dist/mcp/oauth_store.d.ts.map +1 -0
  200. package/dist/mcp/oauth_store.js +40 -0
  201. package/dist/mcp/server_manager.d.ts +49 -0
  202. package/dist/mcp/server_manager.d.ts.map +1 -0
  203. package/dist/mcp/server_manager.js +271 -0
  204. package/dist/plugins/fetchers/git.d.ts +67 -0
  205. package/dist/plugins/fetchers/git.d.ts.map +1 -0
  206. package/dist/plugins/fetchers/git.js +130 -0
  207. package/dist/plugins/fetchers/path.d.ts +4 -0
  208. package/dist/plugins/fetchers/path.d.ts.map +1 -0
  209. package/dist/plugins/fetchers/path.js +22 -0
  210. package/dist/plugins/loader.d.ts +31 -0
  211. package/dist/plugins/loader.d.ts.map +1 -0
  212. package/dist/plugins/loader.js +146 -0
  213. package/dist/plugins/manifest.d.ts +56 -0
  214. package/dist/plugins/manifest.d.ts.map +1 -0
  215. package/dist/plugins/manifest.js +389 -0
  216. package/dist/plugins/refresh_on_start.d.ts +7 -0
  217. package/dist/plugins/refresh_on_start.d.ts.map +1 -0
  218. package/dist/plugins/refresh_on_start.js +35 -0
  219. package/dist/plugins/source_manager.d.ts +27 -0
  220. package/dist/plugins/source_manager.d.ts.map +1 -0
  221. package/dist/plugins/source_manager.js +211 -0
  222. package/dist/plugins/types.d.ts +41 -0
  223. package/dist/plugins/types.d.ts.map +1 -0
  224. package/dist/plugins/types.js +11 -0
  225. package/dist/session/context_usage.d.ts +13 -0
  226. package/dist/session/context_usage.d.ts.map +1 -0
  227. package/dist/session/context_usage.js +25 -0
  228. package/dist/session/index.d.ts +7 -0
  229. package/dist/session/index.d.ts.map +1 -0
  230. package/dist/session/index.js +5 -0
  231. package/dist/session/store.d.ts +68 -0
  232. package/dist/session/store.d.ts.map +1 -0
  233. package/dist/session/store.js +268 -0
  234. package/dist/session/types.d.ts +60 -0
  235. package/dist/session/types.d.ts.map +1 -0
  236. package/dist/session/types.js +11 -0
  237. package/dist/store/db.d.ts +64 -0
  238. package/dist/store/db.d.ts.map +1 -0
  239. package/dist/store/db.js +91 -0
  240. package/dist/store/json.d.ts +21 -0
  241. package/dist/store/json.d.ts.map +1 -0
  242. package/dist/store/json.js +135 -0
  243. package/dist/tui/agents.d.ts +4 -0
  244. package/dist/tui/agents.d.ts.map +1 -0
  245. package/dist/tui/agents.js +616 -0
  246. package/dist/tui/app.d.ts +2 -0
  247. package/dist/tui/app.d.ts.map +1 -0
  248. package/dist/tui/app.js +32 -0
  249. package/dist/tui/chat.d.ts +10 -0
  250. package/dist/tui/chat.d.ts.map +1 -0
  251. package/dist/tui/chat.js +258 -0
  252. package/dist/tui/logo.d.ts +2 -0
  253. package/dist/tui/logo.d.ts.map +1 -0
  254. package/dist/tui/logo.js +10 -0
  255. package/dist/tui/mcp_servers.d.ts +4 -0
  256. package/dist/tui/mcp_servers.d.ts.map +1 -0
  257. package/dist/tui/mcp_servers.js +287 -0
  258. package/dist/tui/plugins.d.ts +4 -0
  259. package/dist/tui/plugins.d.ts.map +1 -0
  260. package/dist/tui/plugins.js +234 -0
  261. package/dist/tui/providers.d.ts +4 -0
  262. package/dist/tui/providers.d.ts.map +1 -0
  263. package/dist/tui/providers.js +178 -0
  264. package/dist/tui/tool_picker_state.d.ts +9 -0
  265. package/dist/tui/tool_picker_state.d.ts.map +1 -0
  266. package/dist/tui/tool_picker_state.js +37 -0
  267. package/dist/types.d.ts +2 -0
  268. package/dist/types.d.ts.map +1 -0
  269. package/dist/types.js +1 -0
  270. package/dist/webview/index.html +22 -0
  271. package/dist/webview/standalone.css +2732 -0
  272. package/dist/webview/standalone.css.map +7 -0
  273. package/dist/webview/standalone.js +20641 -0
  274. package/dist/webview/standalone.js.map +7 -0
  275. package/package.json +120 -0
@@ -0,0 +1,708 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { getDb, getTaskById, saveTask, createTask, addTaskMessage, deleteTask } from '../../../store/db.js';
3
+ import { loadConfig, loadAgents } from '../../../store/json.js';
4
+ import { discardWorktree } from '../../../lib/task_git.js';
5
+ import { runningTasks } from '../../../cli/web/scheduler/locks.js';
6
+ import { resolveReviewEnabled, resolvePlanningEnabled, activationStatus } from '../../../cli/web/scheduler/task_roles.js';
7
+ function ok(data = {}) {
8
+ return { content: JSON.stringify({ ok: true, ...data }) };
9
+ }
10
+ function err(msg) {
11
+ return { content: JSON.stringify({ error: msg }) };
12
+ }
13
+ export const getTaskStateTool = {
14
+ name: 'mcp__task__task_get_state',
15
+ description: 'Get the current state of a task: objective, checklist, recent messages, and project info.',
16
+ parameters: {
17
+ type: 'object',
18
+ properties: {
19
+ task_id: { type: 'number' },
20
+ },
21
+ required: ['task_id'],
22
+ },
23
+ execute: async (args) => {
24
+ const db = getDb();
25
+ const taskId = Number(args.task_id);
26
+ const task = await getTaskById(taskId);
27
+ if (!task)
28
+ return err(`Task ${taskId} not found`);
29
+ const config = await loadConfig();
30
+ const project = (config.projects || []).find((p) => p.id === task.projectId) || null;
31
+ const messages = (await db.query(`SELECT * FROM task_messages WHERE taskId = ${taskId}`));
32
+ messages.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
33
+ return {
34
+ content: JSON.stringify({
35
+ id: task.id,
36
+ projectId: task.projectId,
37
+ title: task.title,
38
+ objective: task.objective,
39
+ checklist: task.checklist,
40
+ status: task.status,
41
+ archived: !!task.archived,
42
+ blockedReason: task.blockedReason,
43
+ noProgressCount: task.noProgressCount,
44
+ maxNoProgress: task.maxNoProgress,
45
+ agentId: task.agentId || null,
46
+ plannerAgentId: task.plannerAgentId || null,
47
+ reviewerAgentId: task.reviewerAgentId || null,
48
+ planningEnabled: task.planningEnabled ?? null,
49
+ reviewEnabled: task.reviewEnabled ?? null,
50
+ sddEnabled: task.sddEnabled ?? null,
51
+ project: project
52
+ ? {
53
+ name: project.name,
54
+ workingDir: project.workingDir,
55
+ }
56
+ : null,
57
+ recentMessages: messages.slice(-20),
58
+ }),
59
+ };
60
+ },
61
+ };
62
+ export const updateChecklistItemTool = {
63
+ name: 'mcp__task__task_update_checklist_item',
64
+ description: 'Update the status of a checklist item.',
65
+ parameters: {
66
+ type: 'object',
67
+ properties: {
68
+ task_id: { type: 'number' },
69
+ item_id: { type: 'string' },
70
+ status: { type: 'string', enum: ['pending', 'in_progress', 'done', 'skipped'] },
71
+ },
72
+ required: ['task_id', 'item_id', 'status'],
73
+ },
74
+ execute: async (args) => {
75
+ const db = getDb();
76
+ const taskId = Number(args.task_id);
77
+ const itemId = String(args.item_id);
78
+ const status = args.status;
79
+ const task = await getTaskById(taskId);
80
+ if (!task)
81
+ return err(`Task ${taskId} not found`);
82
+ const checklist = (task.checklist || []).map((item) => item.id === itemId ? { ...item, status } : item);
83
+ task.checklist = checklist;
84
+ task.updatedAt = new Date().toISOString();
85
+ await saveTask(task);
86
+ return ok();
87
+ },
88
+ };
89
+ export const updateChecklistTool = {
90
+ name: 'mcp__task__task_update_checklist',
91
+ description: 'Replace the entire checklist of a task.',
92
+ parameters: {
93
+ type: 'object',
94
+ properties: {
95
+ task_id: { type: 'number' },
96
+ checklist: {
97
+ type: 'array',
98
+ items: {
99
+ type: 'object',
100
+ properties: {
101
+ id: { type: 'string' },
102
+ text: { type: 'string' },
103
+ status: { type: 'string', enum: ['pending', 'in_progress', 'done', 'skipped'] },
104
+ },
105
+ required: ['text', 'status'],
106
+ },
107
+ },
108
+ },
109
+ required: ['task_id', 'checklist'],
110
+ },
111
+ execute: async (args) => {
112
+ const db = getDb();
113
+ const taskId = Number(args.task_id);
114
+ const checklistInput = args.checklist;
115
+ const task = await getTaskById(taskId);
116
+ if (!task)
117
+ return err(`Task ${taskId} not found`);
118
+ const checklist = checklistInput.map((item, idx) => ({
119
+ id: item.id || randomUUID(),
120
+ text: item.text,
121
+ status: item.status,
122
+ order: idx,
123
+ }));
124
+ task.checklist = checklist;
125
+ task.updatedAt = new Date().toISOString();
126
+ await saveTask(task);
127
+ return ok();
128
+ },
129
+ };
130
+ export const addMessageTool = {
131
+ name: 'mcp__task__task_add_message',
132
+ description: 'Add a message to the task thread. Use this to document what you did in this session.',
133
+ parameters: {
134
+ type: 'object',
135
+ properties: {
136
+ task_id: { type: 'number' },
137
+ content: { type: 'string' },
138
+ },
139
+ required: ['task_id', 'content'],
140
+ },
141
+ execute: async (args) => {
142
+ const db = getDb();
143
+ const taskId = Number(args.task_id);
144
+ const content = String(args.content);
145
+ await addTaskMessage({
146
+ taskId,
147
+ role: 'assistant',
148
+ messageType: 'chat',
149
+ content,
150
+ agentId: null,
151
+ });
152
+ // Update task updatedAt
153
+ const task = await getTaskById(taskId);
154
+ if (task) {
155
+ task.updatedAt = new Date().toISOString();
156
+ await saveTask(task);
157
+ }
158
+ return ok();
159
+ },
160
+ };
161
+ export const completeTaskTool = {
162
+ name: 'mcp__task__task_complete',
163
+ description: 'Mark the task as done. Use when the objective is fully achieved.',
164
+ parameters: {
165
+ type: 'object',
166
+ properties: {
167
+ task_id: { type: 'number' },
168
+ summary: { type: 'string' },
169
+ },
170
+ required: ['task_id'],
171
+ },
172
+ execute: async (args) => {
173
+ const db = getDb();
174
+ const taskId = Number(args.task_id);
175
+ const summary = args.summary ? String(args.summary) : '';
176
+ const task = await getTaskById(taskId);
177
+ if (!task)
178
+ return err(`Task ${taskId} not found`);
179
+ if (task.status === 'planning') {
180
+ return err(`Task ${taskId} is in the planning phase. Submit a plan with task_submit_plan before completing.`);
181
+ }
182
+ // Git-isolated tasks enter review before finalizing — unless the review
183
+ // gate is disabled for this task/project. Non-git tasks always finalize
184
+ // directly (the review is git-diff based, it needs a branch to inspect).
185
+ const config = await loadConfig();
186
+ const project = (config.projects || []).find((p) => p.id === task.projectId);
187
+ const reviewOn = resolveReviewEnabled(task, project);
188
+ task.status = task.worktreePath && reviewOn ? 'reviewing' : 'done';
189
+ task.lockedAt = null;
190
+ task.updatedAt = new Date().toISOString();
191
+ await saveTask(task);
192
+ const content = summary ? `Task completed. ${summary}` : 'Task completed.';
193
+ await addTaskMessage({
194
+ taskId,
195
+ role: 'assistant',
196
+ messageType: 'system',
197
+ content,
198
+ agentId: null,
199
+ });
200
+ return ok();
201
+ },
202
+ };
203
+ export const blockTaskTool = {
204
+ name: 'mcp__task__task_block',
205
+ description: 'Mark the task as blocked. Use when you need human input to continue.',
206
+ parameters: {
207
+ type: 'object',
208
+ properties: {
209
+ task_id: { type: 'number' },
210
+ reason: { type: 'string' },
211
+ },
212
+ required: ['task_id', 'reason'],
213
+ },
214
+ execute: async (args) => {
215
+ const db = getDb();
216
+ const taskId = Number(args.task_id);
217
+ const reason = String(args.reason);
218
+ const task = await getTaskById(taskId);
219
+ if (!task)
220
+ return err(`Task ${taskId} not found`);
221
+ task.status = 'blocked';
222
+ task.blockedReason = reason;
223
+ task.lockedAt = null;
224
+ task.updatedAt = new Date().toISOString();
225
+ await saveTask(task);
226
+ await addTaskMessage({
227
+ taskId,
228
+ role: 'assistant',
229
+ messageType: 'block',
230
+ content: reason,
231
+ agentId: null,
232
+ });
233
+ return ok();
234
+ },
235
+ };
236
+ export const yieldTaskTool = {
237
+ name: 'mcp__task__task_yield',
238
+ description: 'Signal end of this invocation without completing the task. Task remains active.',
239
+ parameters: {
240
+ type: 'object',
241
+ properties: {
242
+ task_id: { type: 'number' },
243
+ notes: { type: 'string' },
244
+ },
245
+ required: ['task_id'],
246
+ },
247
+ execute: async (args) => {
248
+ const db = getDb();
249
+ const taskId = Number(args.task_id);
250
+ const notes = args.notes ? String(args.notes) : '';
251
+ const task = await getTaskById(taskId);
252
+ if (!task)
253
+ return err(`Task ${taskId} not found`);
254
+ task.lockedAt = null;
255
+ task.updatedAt = new Date().toISOString();
256
+ await saveTask(task);
257
+ if (notes) {
258
+ await addTaskMessage({
259
+ taskId,
260
+ role: 'assistant',
261
+ messageType: 'system',
262
+ content: `Yield: ${notes}`,
263
+ agentId: null,
264
+ });
265
+ }
266
+ return ok();
267
+ },
268
+ };
269
+ export const projectListTool = {
270
+ name: 'mcp__task__project_list',
271
+ description: 'List all available projects with their IDs, names, and working directories. Call this before task_create to pick the correct project_id.',
272
+ parameters: {
273
+ type: 'object',
274
+ properties: {},
275
+ },
276
+ execute: async () => {
277
+ const config = await loadConfig();
278
+ const projects = [...(config.projects || [])];
279
+ projects.sort((a, b) => a.name.localeCompare(b.name));
280
+ return { content: JSON.stringify(projects) };
281
+ },
282
+ };
283
+ export const taskCreateTool = {
284
+ name: 'mcp__task__task_create',
285
+ description: 'Create a new task in the system.',
286
+ parameters: {
287
+ type: 'object',
288
+ properties: {
289
+ project_id: { type: 'number' },
290
+ title: { type: 'string' },
291
+ objective: { type: 'string' },
292
+ checklist: {
293
+ type: 'array',
294
+ items: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'] },
295
+ },
296
+ start_active: { type: 'boolean' },
297
+ agent_id: {
298
+ type: 'string',
299
+ description: 'Optional agent ID to assign to this task. If omitted, the project default agent is used.',
300
+ },
301
+ planner_agent_id: { type: 'string', description: 'Optional planner-role agent for this task.' },
302
+ reviewer_agent_id: { type: 'string', description: 'Optional reviewer-role agent for this task.' },
303
+ planning_enabled: { type: 'boolean', description: 'Override the project planning-phase default for this task.' },
304
+ review_enabled: { type: 'boolean', description: 'Override the project review-gate default for this task.' },
305
+ sdd_enabled: { type: 'boolean', description: 'Override the project SDD-mode default for this task (planner may write .md files during planning).' },
306
+ },
307
+ required: ['project_id', 'title', 'objective', 'checklist'],
308
+ },
309
+ execute: async (args) => {
310
+ const db = getDb();
311
+ const projectId = Number(args.project_id);
312
+ const title = String(args.title);
313
+ const objective = String(args.objective);
314
+ const checklistInput = args.checklist;
315
+ const startActive = !!args.start_active;
316
+ const agentId = args.agent_id ? String(args.agent_id) : null;
317
+ const plannerAgentId = args.planner_agent_id ? String(args.planner_agent_id) : null;
318
+ const reviewerAgentId = args.reviewer_agent_id ? String(args.reviewer_agent_id) : null;
319
+ const planningEnabled = typeof args.planning_enabled === 'boolean' ? args.planning_enabled : null;
320
+ const reviewEnabled = typeof args.review_enabled === 'boolean' ? args.review_enabled : null;
321
+ const sddEnabled = typeof args.sdd_enabled === 'boolean' ? args.sdd_enabled : null;
322
+ const config = await loadConfig();
323
+ const project = (config.projects || []).find((p) => p.id === projectId);
324
+ if (!project)
325
+ return err(`Project ${projectId} not found`);
326
+ // Validate that the specified agents exist (if provided).
327
+ const idsToValidate = [agentId, plannerAgentId, reviewerAgentId].filter(Boolean);
328
+ if (idsToValidate.length > 0) {
329
+ const agents = await loadAgents();
330
+ for (const id of idsToValidate) {
331
+ if (!agents.some((a) => a.id === id)) {
332
+ return err(`Agent "${id}" not found. Available agents: ${agents.map((a) => a.id).join(', ') || '(none)'}`);
333
+ }
334
+ }
335
+ }
336
+ const checklist = checklistInput.map((item, idx) => ({
337
+ id: randomUUID(),
338
+ text: item.text,
339
+ status: 'pending',
340
+ order: idx,
341
+ }));
342
+ const startStatus = startActive
343
+ ? (resolvePlanningEnabled({ planningEnabled }, project) ? 'planning' : 'active')
344
+ : 'draft';
345
+ const createdTask = await createTask({
346
+ projectId,
347
+ title,
348
+ objective,
349
+ checklist,
350
+ status: startStatus,
351
+ blockedReason: null,
352
+ noProgressCount: 0,
353
+ maxNoProgress: 5,
354
+ lockedAt: null,
355
+ agentId,
356
+ plannerAgentId,
357
+ reviewerAgentId,
358
+ planningEnabled,
359
+ reviewEnabled,
360
+ sddEnabled,
361
+ });
362
+ if (startActive) {
363
+ await addTaskMessage({
364
+ taskId: createdTask.id,
365
+ role: 'assistant',
366
+ messageType: 'system',
367
+ content: startStatus === 'planning' ? 'Task created and activated (planning phase).' : 'Task created and activated.',
368
+ agentId: null,
369
+ });
370
+ }
371
+ return ok({ task_id: createdTask.id });
372
+ },
373
+ };
374
+ export const taskSearchTool = {
375
+ name: 'mcp__task__task_search',
376
+ description: 'Search tasks by query matching title or objective. By default archived tasks are excluded; set include_archived to true to search them too.',
377
+ parameters: {
378
+ type: 'object',
379
+ properties: {
380
+ query: { type: 'string' },
381
+ limit: { type: 'number' },
382
+ include_archived: { type: 'boolean' },
383
+ },
384
+ required: ['query'],
385
+ },
386
+ execute: async (args) => {
387
+ const db = getDb();
388
+ const query = String(args.query).toLowerCase();
389
+ const limit = args.limit ? Number(args.limit) : 5;
390
+ const includeArchived = args.include_archived === true;
391
+ const allTasks = (await db.query(`SELECT * FROM tasks`));
392
+ const filtered = includeArchived ? allTasks : allTasks.filter((t) => !t.archived);
393
+ const matches = filtered.filter((t) => t.title.toLowerCase().includes(query) ||
394
+ t.objective.toLowerCase().includes(query));
395
+ matches.sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
396
+ return { content: JSON.stringify(matches.slice(0, limit)) };
397
+ },
398
+ };
399
+ export const taskUnblockTool = {
400
+ name: 'mcp__task__task_unblock',
401
+ description: 'Unblock a blocked task.',
402
+ parameters: {
403
+ type: 'object',
404
+ properties: {
405
+ task_id: { type: 'number' },
406
+ message: { type: 'string' },
407
+ },
408
+ required: ['task_id'],
409
+ },
410
+ execute: async (args) => {
411
+ const db = getDb();
412
+ const taskId = Number(args.task_id);
413
+ const message = args.message ? String(args.message) : '';
414
+ const task = await getTaskById(taskId);
415
+ if (!task)
416
+ return err(`Task ${taskId} not found`);
417
+ if (task.status !== 'blocked')
418
+ return err(`Task ${taskId} is not blocked.`);
419
+ const config = await loadConfig();
420
+ const project = (config.projects || []).find((p) => p.id === task.projectId);
421
+ task.status = await activationStatus(task, project);
422
+ task.blockedReason = null;
423
+ task.updatedAt = new Date().toISOString();
424
+ await saveTask(task);
425
+ const content = message ? `Task unblocked: ${message}` : 'Task unblocked.';
426
+ await addTaskMessage({
427
+ taskId,
428
+ role: 'assistant',
429
+ messageType: 'system',
430
+ content,
431
+ agentId: null,
432
+ });
433
+ return ok();
434
+ },
435
+ };
436
+ export const taskActivateTool = {
437
+ name: 'mcp__task__task_activate',
438
+ description: 'Activate a draft task.',
439
+ parameters: {
440
+ type: 'object',
441
+ properties: {
442
+ task_id: { type: 'number' },
443
+ },
444
+ required: ['task_id'],
445
+ },
446
+ execute: async (args) => {
447
+ const db = getDb();
448
+ const taskId = Number(args.task_id);
449
+ const task = await getTaskById(taskId);
450
+ if (!task)
451
+ return err(`Task ${taskId} not found`);
452
+ if (task.status !== 'draft')
453
+ return err(`Task ${taskId} is not a draft.`);
454
+ const config = await loadConfig();
455
+ const project = (config.projects || []).find((p) => p.id === task.projectId);
456
+ task.status = await activationStatus(task, project);
457
+ task.updatedAt = new Date().toISOString();
458
+ await saveTask(task);
459
+ await addTaskMessage({
460
+ taskId,
461
+ role: 'assistant',
462
+ messageType: 'system',
463
+ content: task.status === 'planning' ? 'Task activated (planning phase).' : 'Task activated.',
464
+ agentId: null,
465
+ });
466
+ return ok();
467
+ },
468
+ };
469
+ export const taskUnpauseTool = {
470
+ name: 'mcp__task__task_unpause',
471
+ description: 'Resume a paused task.',
472
+ parameters: {
473
+ type: 'object',
474
+ properties: {
475
+ task_id: { type: 'number' },
476
+ message: { type: 'string' },
477
+ },
478
+ required: ['task_id'],
479
+ },
480
+ execute: async (args) => {
481
+ const db = getDb();
482
+ const taskId = Number(args.task_id);
483
+ const message = args.message ? String(args.message) : '';
484
+ const task = await getTaskById(taskId);
485
+ if (!task)
486
+ return err(`Task ${taskId} not found`);
487
+ if (task.status !== 'paused')
488
+ return err(`Task ${taskId} is not paused.`);
489
+ const config = await loadConfig();
490
+ const project = (config.projects || []).find((p) => p.id === task.projectId);
491
+ task.status = await activationStatus(task, project);
492
+ task.noProgressCount = 0; // reset progress cap on manual unpause
493
+ task.updatedAt = new Date().toISOString();
494
+ await saveTask(task);
495
+ const content = message ? `Task unpaused: ${message}` : 'Task unpaused.';
496
+ await addTaskMessage({
497
+ taskId,
498
+ role: 'assistant',
499
+ messageType: 'system',
500
+ content,
501
+ agentId: null,
502
+ });
503
+ return ok();
504
+ },
505
+ };
506
+ export const taskDiscardWorktreeTool = {
507
+ name: 'mcp__task__task_discard_worktree',
508
+ description: 'Commit any pending changes on the task branch, then remove its git worktree (the branch is kept). Use to clean up a task worktree manually when a task is done or abandoned.',
509
+ parameters: {
510
+ type: 'object',
511
+ properties: {
512
+ task_id: { type: 'number' },
513
+ },
514
+ required: ['task_id'],
515
+ },
516
+ execute: async (args) => {
517
+ const taskId = Number(args.task_id);
518
+ const task = await getTaskById(taskId);
519
+ if (!task)
520
+ return err(`Task ${taskId} not found`);
521
+ if (!task.worktreePath)
522
+ return err(`Task ${taskId} has no active worktree`);
523
+ await discardWorktree(task.worktreePath, task.title);
524
+ task.worktreePath = null;
525
+ task.updatedAt = new Date().toISOString();
526
+ await saveTask(task);
527
+ return ok({ branch: task.branch });
528
+ },
529
+ };
530
+ export const taskArchiveTool = {
531
+ name: 'mcp__task__task_archive',
532
+ description: 'Archive a task. Archived tasks are hidden from the default task list and excluded from the scheduler heartbeat, but remain in the store and can be unarchived.',
533
+ parameters: {
534
+ type: 'object',
535
+ properties: {
536
+ task_id: { type: 'number' },
537
+ },
538
+ required: ['task_id'],
539
+ },
540
+ execute: async (args) => {
541
+ const taskId = Number(args.task_id);
542
+ const task = await getTaskById(taskId);
543
+ if (!task)
544
+ return err(`Task ${taskId} not found`);
545
+ task.archived = true;
546
+ // An archived task stops running: pause it so the heartbeat won't pick it up.
547
+ if (task.status === 'active' || task.status === 'reviewing') {
548
+ task.status = 'paused';
549
+ }
550
+ task.updatedAt = new Date().toISOString();
551
+ await saveTask(task);
552
+ await addTaskMessage({
553
+ taskId,
554
+ role: 'assistant',
555
+ messageType: 'system',
556
+ content: 'Task archived.',
557
+ agentId: null,
558
+ });
559
+ return ok();
560
+ },
561
+ };
562
+ export const taskUnarchiveTool = {
563
+ name: 'mcp__task__task_unarchive',
564
+ description: 'Unarchive a previously archived task, making it visible in the default task list again. The task status is not changed — use task_activate or task_unpause to resume work.',
565
+ parameters: {
566
+ type: 'object',
567
+ properties: {
568
+ task_id: { type: 'number' },
569
+ },
570
+ required: ['task_id'],
571
+ },
572
+ execute: async (args) => {
573
+ const taskId = Number(args.task_id);
574
+ const task = await getTaskById(taskId);
575
+ if (!task)
576
+ return err(`Task ${taskId} not found`);
577
+ task.archived = false;
578
+ task.updatedAt = new Date().toISOString();
579
+ await saveTask(task);
580
+ await addTaskMessage({
581
+ taskId,
582
+ role: 'assistant',
583
+ messageType: 'system',
584
+ content: 'Task unarchived.',
585
+ agentId: null,
586
+ });
587
+ return ok();
588
+ },
589
+ };
590
+ export const taskDeleteTool = {
591
+ name: 'mcp__task__task_delete',
592
+ description: 'Permanently delete a task and all of its messages from the store. This is irreversible. If the task has an active git worktree, it is discarded first (branch kept).',
593
+ parameters: {
594
+ type: 'object',
595
+ properties: {
596
+ task_id: { type: 'number' },
597
+ },
598
+ required: ['task_id'],
599
+ },
600
+ execute: async (args) => {
601
+ const taskId = Number(args.task_id);
602
+ const task = await getTaskById(taskId);
603
+ if (!task)
604
+ return err(`Task ${taskId} not found`);
605
+ // Guard against deleting a task that is currently being processed by the
606
+ // scheduler heartbeat. The heartbeat holds an in-process lock and a DB
607
+ // lockedAt timestamp; deleting mid-run would cause the finally block to
608
+ // resurrect the task as a zombie via saveTask.
609
+ const lockKey = `task_db_${taskId}`;
610
+ if (task.lockedAt || runningTasks.has(lockKey)) {
611
+ return err(`Task ${taskId} is currently running (locked). Wait for it to finish or pause it first.`);
612
+ }
613
+ // Clean up any active worktree before deleting the task record.
614
+ if (task.worktreePath) {
615
+ try {
616
+ await discardWorktree(task.worktreePath, task.title);
617
+ }
618
+ catch {
619
+ // Best-effort: proceed with deletion even if worktree cleanup fails.
620
+ }
621
+ }
622
+ await deleteTask(taskId);
623
+ return ok();
624
+ },
625
+ };
626
+ export const taskSetAgentTool = {
627
+ name: 'mcp__task__task_set_agent',
628
+ description: 'Assign a specific agent to a task role, overriding the project default. role: developer (default, the main task agent), planner, or reviewer. Pass null or omit agent_id to clear the override and fall back to the project default.',
629
+ parameters: {
630
+ type: 'object',
631
+ properties: {
632
+ task_id: { type: 'number' },
633
+ agent_id: { type: 'string', description: 'The agent ID to assign, or null to clear the override.' },
634
+ role: {
635
+ type: 'string',
636
+ enum: ['developer', 'planner', 'reviewer'],
637
+ description: 'Which role to assign. Defaults to developer (the main task agent).',
638
+ },
639
+ },
640
+ required: ['task_id'],
641
+ },
642
+ execute: async (args) => {
643
+ const taskId = Number(args.task_id);
644
+ const agentId = args.agent_id != null ? String(args.agent_id) : null;
645
+ const role = args.role === 'planner' || args.role === 'reviewer' ? args.role : 'developer';
646
+ const task = await getTaskById(taskId);
647
+ if (!task)
648
+ return err(`Task ${taskId} not found`);
649
+ // Guard against reassigning a task that is currently running.
650
+ const lockKey = `task_db_${taskId}`;
651
+ if (task.lockedAt || runningTasks.has(lockKey)) {
652
+ return err(`Task ${taskId} is currently running. Wait for it to finish or pause it first.`);
653
+ }
654
+ // Validate that the specified agent exists (if provided and non-null).
655
+ if (agentId) {
656
+ const agents = await loadAgents();
657
+ if (!agents.some((a) => a.id === agentId)) {
658
+ return err(`Agent "${agentId}" not found. Available agents: ${agents.map((a) => a.id).join(', ') || '(none)'}`);
659
+ }
660
+ }
661
+ if (role === 'planner')
662
+ task.plannerAgentId = agentId;
663
+ else if (role === 'reviewer')
664
+ task.reviewerAgentId = agentId;
665
+ else
666
+ task.agentId = agentId;
667
+ task.updatedAt = new Date().toISOString();
668
+ await saveTask(task);
669
+ return ok({ role, agentId });
670
+ },
671
+ };
672
+ export const submitPlanTool = {
673
+ name: 'mcp__task__task_submit_plan',
674
+ description: 'Submit the implementation plan for a task in the planning phase and start execution. Persists the plan to the task thread and transitions the task from planning to active. Only valid while the task status is "planning".',
675
+ parameters: {
676
+ type: 'object',
677
+ properties: {
678
+ task_id: { type: 'number' },
679
+ plan: { type: 'string', description: 'The full implementation plan, markdown.' },
680
+ },
681
+ required: ['task_id', 'plan'],
682
+ },
683
+ execute: async (args) => {
684
+ const taskId = Number(args.task_id);
685
+ const plan = String(args.plan ?? '').trim();
686
+ if (!plan)
687
+ return err('Plan must not be empty.');
688
+ const task = await getTaskById(taskId);
689
+ if (!task)
690
+ return err(`Task ${taskId} not found`);
691
+ if (task.status !== 'planning') {
692
+ return err(`Task ${taskId} is not in planning (status: ${task.status}).`);
693
+ }
694
+ await addTaskMessage({
695
+ taskId,
696
+ role: 'assistant',
697
+ messageType: 'plan',
698
+ content: plan,
699
+ agentId: null,
700
+ });
701
+ task.status = 'active';
702
+ task.noProgressCount = 0;
703
+ task.lockedAt = null;
704
+ task.updatedAt = new Date().toISOString();
705
+ await saveTask(task);
706
+ return ok({ status: 'active' });
707
+ },
708
+ };