@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,75 @@
1
+ // Ported from caretaker server's src/mcp/web.ts (fetch).
2
+ // HTTP GET with format conversion (text/markdown/json/raw). 30s timeout,
3
+ // 5 MB body cap. Honors ctx.signal.
4
+ import TurndownService from 'turndown';
5
+ const MAX_BYTES = 5 * 1024 * 1024;
6
+ const TIMEOUT_MS = 30_000;
7
+ export const fetchTool = {
8
+ name: 'fetch',
9
+ description: 'GET a URL (http/https only). Format options: text (default), markdown (HTML→md), json, raw.',
10
+ parameters: {
11
+ type: 'object',
12
+ properties: {
13
+ url: { type: 'string' },
14
+ format: { type: 'string', enum: ['text', 'markdown', 'json', 'raw'] },
15
+ },
16
+ required: ['url'],
17
+ additionalProperties: false,
18
+ },
19
+ dangerous: true,
20
+ async execute(args, ctx) {
21
+ const a = args;
22
+ if (typeof a.url !== 'string' || !a.url.trim()) {
23
+ return { content: 'Error: url must be a non-empty string' };
24
+ }
25
+ let parsed;
26
+ try {
27
+ parsed = new URL(a.url);
28
+ }
29
+ catch {
30
+ return { content: `Error: invalid URL: ${a.url}` };
31
+ }
32
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
33
+ return { content: `Error: unsupported scheme: ${parsed.protocol}` };
34
+ }
35
+ const fmt = typeof a.format === 'string' ? a.format : 'text';
36
+ if (!['text', 'markdown', 'json', 'raw'].includes(fmt)) {
37
+ return { content: `Error: unknown format: ${fmt}` };
38
+ }
39
+ // Tie the per-tool timeout to the caller-provided abort: aborting the
40
+ // run cancels the in-flight fetch.
41
+ const ac = new AbortController();
42
+ const timer = setTimeout(() => ac.abort(), TIMEOUT_MS);
43
+ const onParentAbort = () => ac.abort();
44
+ ctx.signal.addEventListener('abort', onParentAbort, { once: true });
45
+ try {
46
+ const res = await fetch(a.url, { signal: ac.signal, redirect: 'follow' });
47
+ const buf = await res.arrayBuffer();
48
+ if (buf.byteLength > MAX_BYTES) {
49
+ return { content: `Error: body too large: ${buf.byteLength} bytes (max ${MAX_BYTES})` };
50
+ }
51
+ const text = new TextDecoder('utf-8').decode(buf);
52
+ if (fmt === 'raw' || fmt === 'text')
53
+ return { content: text };
54
+ if (fmt === 'json') {
55
+ try {
56
+ return { content: JSON.stringify(JSON.parse(text), null, 2) };
57
+ }
58
+ catch {
59
+ return { content: 'Error: body is not valid JSON' };
60
+ }
61
+ }
62
+ // markdown
63
+ const td = new TurndownService();
64
+ return { content: td.turndown(text) };
65
+ }
66
+ catch (err) {
67
+ const msg = err instanceof Error ? err.message : String(err);
68
+ return { content: `Error: fetch failed: ${msg}` };
69
+ }
70
+ finally {
71
+ clearTimeout(timer);
72
+ ctx.signal.removeEventListener('abort', onParentAbort);
73
+ }
74
+ },
75
+ };
@@ -0,0 +1,3 @@
1
+ import type { Tool } from '../types.js';
2
+ export declare const getAgentContextTool: Tool;
3
+ //# sourceMappingURL=get_agent_context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get_agent_context.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/get_agent_context.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAoBxC,eAAO,MAAM,mBAAmB,EAAE,IAgEjC,CAAC"}
@@ -0,0 +1,76 @@
1
+ // Live self-introspection: returns the agent's identity (also surfaced in
2
+ // the <runtime-info> block of the system prompt, but cheap to repeat
3
+ // here) plus the current run's token usage. The numbers come from
4
+ // ctx.liveUsage, which the loop mutates in place each turn — so the value
5
+ // the model sees here is always the latest, not a snapshot from when the
6
+ // run started. `contextWindow` is resolved from the models.dev registry
7
+ // (populated lazily at boot); `percent` is computed from the cumulative
8
+ // total. Both stay null when the model is unknown to the registry.
9
+ import { resolveContextWindow } from '../../model_limits.js';
10
+ function totalOf(u) {
11
+ if (!u)
12
+ return 0;
13
+ return ((u.input ?? 0) + (u.output ?? 0) + (u.cacheRead ?? 0) + (u.cacheWrite ?? 0) + (u.reasoning ?? 0));
14
+ }
15
+ export const getAgentContextTool = {
16
+ name: 'get_agent_context',
17
+ description: "Return live information about this run: the agent's identity (name, " +
18
+ 'model, provider, working directory) and token usage so far ' +
19
+ '(last turn breakdown + cumulative across the run). Static identity is ' +
20
+ 'also visible in the <runtime-info> block of your system prompt — ' +
21
+ 'prefer reading that for non-live questions. Call this tool only when ' +
22
+ 'you need fresh token-usage numbers.',
23
+ parameters: {
24
+ type: 'object',
25
+ properties: {},
26
+ additionalProperties: false,
27
+ },
28
+ async execute(_args, ctx) {
29
+ const agent = ctx.callerAgent;
30
+ const usage = ctx.liveUsage;
31
+ const cumulative = usage?.cumulative ?? {
32
+ input: 0,
33
+ output: 0,
34
+ cacheRead: 0,
35
+ cacheWrite: 0,
36
+ reasoning: 0,
37
+ };
38
+ const lastTurn = usage?.lastTurn ?? null;
39
+ const cumulativeTotal = totalOf(cumulative);
40
+ const contextWindow = agent?.model ? resolveContextWindow(agent.model) : null;
41
+ const percent = contextWindow && cumulativeTotal > 0
42
+ ? Math.round((cumulativeTotal / contextWindow) * 100)
43
+ : null;
44
+ const payload = {
45
+ agent: {
46
+ name: agent?.name ?? null,
47
+ model: agent?.model ?? null,
48
+ provider: agent?.provider ?? null,
49
+ },
50
+ workingDir: ctx.workingDir,
51
+ usage: {
52
+ lastTurn: lastTurn
53
+ ? {
54
+ input: lastTurn.input ?? 0,
55
+ output: lastTurn.output ?? 0,
56
+ cacheRead: lastTurn.cacheRead ?? 0,
57
+ cacheWrite: lastTurn.cacheWrite ?? 0,
58
+ reasoning: lastTurn.reasoning ?? 0,
59
+ total: totalOf(lastTurn),
60
+ }
61
+ : null,
62
+ cumulative: {
63
+ input: cumulative.input ?? 0,
64
+ output: cumulative.output ?? 0,
65
+ cacheRead: cumulative.cacheRead ?? 0,
66
+ cacheWrite: cumulative.cacheWrite ?? 0,
67
+ reasoning: cumulative.reasoning ?? 0,
68
+ total: cumulativeTotal,
69
+ },
70
+ contextWindow,
71
+ percent,
72
+ },
73
+ };
74
+ return { content: JSON.stringify(payload, null, 2) };
75
+ },
76
+ };
@@ -0,0 +1,3 @@
1
+ import type { Tool } from '../types.js';
2
+ export declare const globTool: Tool;
3
+ //# sourceMappingURL=glob.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/glob.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAKxC,eAAO,MAAM,QAAQ,EAAE,IA8CtB,CAAC"}
@@ -0,0 +1,52 @@
1
+ // Ported from caretaker server's src/mcp/fs.ts (glob).
2
+ // Find files matching a glob pattern, scoped to the working directory.
3
+ // Returns paths relative to the workingDir (or to a sub-path when supplied),
4
+ // capped at 1000 entries.
5
+ import fg from 'fast-glob';
6
+ import { assertWithinRoot, OutsideRootError } from '../sandbox.js';
7
+ const MAX_RESULTS = 1000;
8
+ export const globTool = {
9
+ name: 'glob',
10
+ description: 'Find files matching a glob pattern (e.g. **/*.ts) within the working directory. ' +
11
+ 'Returns up to 1000 paths relative to the search root.',
12
+ parameters: {
13
+ type: 'object',
14
+ properties: {
15
+ pattern: { type: 'string', description: 'Glob pattern, e.g. **/*.ts' },
16
+ path: {
17
+ type: 'string',
18
+ description: 'Optional sub-path under the working directory to scope the search.',
19
+ },
20
+ },
21
+ required: ['pattern'],
22
+ additionalProperties: false,
23
+ },
24
+ async execute(args, ctx) {
25
+ const a = args;
26
+ if (typeof a.pattern !== 'string' || !a.pattern.trim()) {
27
+ return { content: 'Error: pattern must be a non-empty string' };
28
+ }
29
+ let root;
30
+ try {
31
+ root =
32
+ typeof a.path === 'string' && a.path.trim()
33
+ ? assertWithinRoot(ctx.workingDir, a.path)
34
+ : ctx.workingDir;
35
+ }
36
+ catch (err) {
37
+ if (err instanceof OutsideRootError)
38
+ return { content: `Error: ${err.message}` };
39
+ throw err;
40
+ }
41
+ let found;
42
+ try {
43
+ found = await fg(a.pattern, { cwd: root, onlyFiles: true, dot: false });
44
+ }
45
+ catch (err) {
46
+ return { content: `Error: ${err instanceof Error ? err.message : String(err)}` };
47
+ }
48
+ const capped = found.slice(0, MAX_RESULTS);
49
+ const tail = found.length > MAX_RESULTS ? `\n[truncated to ${MAX_RESULTS} of ${found.length}]` : '';
50
+ return { content: capped.join('\n') + tail };
51
+ },
52
+ };
@@ -0,0 +1,3 @@
1
+ import type { Tool } from '../types.js';
2
+ export declare const grepTool: Tool;
3
+ //# sourceMappingURL=grep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grep.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/grep.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AA8BxC,eAAO,MAAM,QAAQ,EAAE,IAqFtB,CAAC"}
@@ -0,0 +1,126 @@
1
+ // Ported from caretaker server's src/mcp/fs.ts (grep).
2
+ // Find lines matching a regex across files. Skips binary files cheaply via
3
+ // a leading sample. Output format: "path:line:text", capped at 200 hits.
4
+ import fg from 'fast-glob';
5
+ import * as path from 'node:path';
6
+ import { open, readFile, stat } from 'node:fs/promises';
7
+ import { assertWithinRoot, OutsideRootError } from '../sandbox.js';
8
+ const MAX_HITS = 200;
9
+ const SAMPLE_BYTES = 4096;
10
+ function isBinarySample(buf) {
11
+ if (buf.length === 0)
12
+ return false;
13
+ let nonPrintable = 0;
14
+ for (let i = 0; i < buf.length; i++) {
15
+ const b = buf[i];
16
+ if (b === 0)
17
+ return true;
18
+ if (b < 9 || (b > 13 && b < 32))
19
+ nonPrintable++;
20
+ }
21
+ return nonPrintable / buf.length > 0.3;
22
+ }
23
+ async function readSample(abs, size) {
24
+ if (size === 0)
25
+ return Buffer.alloc(0);
26
+ const fh = await open(abs, 'r');
27
+ try {
28
+ const len = Math.min(size, SAMPLE_BYTES);
29
+ const buf = Buffer.alloc(len);
30
+ await fh.read(buf, 0, len, 0);
31
+ return buf;
32
+ }
33
+ finally {
34
+ await fh.close();
35
+ }
36
+ }
37
+ export const grepTool = {
38
+ name: 'grep',
39
+ description: 'Find lines matching a regex across files (relative to the working directory). ' +
40
+ 'Returns up to 200 hits as path:line:text. Filter by glob or file-extension type.',
41
+ parameters: {
42
+ type: 'object',
43
+ properties: {
44
+ pattern: { type: 'string', description: 'Regular expression.' },
45
+ path: { type: 'string', description: 'Optional sub-path under workingDir.' },
46
+ glob: { type: 'string', description: 'Optional glob filter, e.g. **/*.ts' },
47
+ type: {
48
+ type: 'string',
49
+ description: 'Optional file-extension filter, e.g. ts (shorthand for **/*.ts).',
50
+ },
51
+ },
52
+ required: ['pattern'],
53
+ additionalProperties: false,
54
+ },
55
+ async execute(args, ctx) {
56
+ const a = args;
57
+ if (typeof a.pattern !== 'string' || !a.pattern.trim()) {
58
+ return { content: 'Error: pattern must be a non-empty string' };
59
+ }
60
+ let root;
61
+ try {
62
+ root =
63
+ typeof a.path === 'string' && a.path.trim()
64
+ ? assertWithinRoot(ctx.workingDir, a.path)
65
+ : ctx.workingDir;
66
+ }
67
+ catch (err) {
68
+ if (err instanceof OutsideRootError)
69
+ return { content: `Error: ${err.message}` };
70
+ throw err;
71
+ }
72
+ const globPat = typeof a.glob === 'string' && a.glob.trim()
73
+ ? a.glob
74
+ : typeof a.type === 'string' && a.type.trim()
75
+ ? `**/*.${a.type}`
76
+ : '**/*';
77
+ let re;
78
+ try {
79
+ re = new RegExp(a.pattern);
80
+ }
81
+ catch (err) {
82
+ return {
83
+ content: `Error: invalid regex: ${err instanceof Error ? err.message : String(err)}`,
84
+ };
85
+ }
86
+ const files = await fg(globPat, { cwd: root, onlyFiles: true, dot: false });
87
+ const hits = [];
88
+ for (const rel of files) {
89
+ if (hits.length >= MAX_HITS)
90
+ break;
91
+ if (ctx.signal.aborted)
92
+ break;
93
+ const abs = path.join(root, rel);
94
+ let st;
95
+ try {
96
+ st = await stat(abs);
97
+ }
98
+ catch {
99
+ continue;
100
+ }
101
+ let sample;
102
+ try {
103
+ sample = await readSample(abs, st.size);
104
+ }
105
+ catch {
106
+ continue;
107
+ }
108
+ if (isBinarySample(sample))
109
+ continue;
110
+ let content;
111
+ try {
112
+ content = await readFile(abs, 'utf-8');
113
+ }
114
+ catch {
115
+ continue;
116
+ }
117
+ const lines = content.split('\n');
118
+ for (let i = 0; i < lines.length && hits.length < MAX_HITS; i++) {
119
+ if (re.test(lines[i]))
120
+ hits.push(`${rel}:${i + 1}:${lines[i]}`);
121
+ }
122
+ }
123
+ const tail = hits.length === MAX_HITS ? `\n[truncated at ${MAX_HITS} matches]` : '';
124
+ return { content: hits.join('\n') + tail };
125
+ },
126
+ };
@@ -0,0 +1,23 @@
1
+ import type { ToolRegistry } from '../registry.js';
2
+ import { readFileTool } from './read_file.js';
3
+ import { readDocumentTool } from './read_document.js';
4
+ import { readImageTool } from './read_image.js';
5
+ import { readAttachmentTool } from './read_attachment.js';
6
+ import { writeTool } from './write.js';
7
+ import { editTool } from './edit.js';
8
+ import { multieditTool } from './multiedit.js';
9
+ import { globTool } from './glob.js';
10
+ import { grepTool } from './grep.js';
11
+ import { fetchTool } from './fetch.js';
12
+ import { bashTool } from './bash.js';
13
+ import { listSkillsTool } from './list_skills.js';
14
+ import { readSkillTool } from './read_skill.js';
15
+ import { listAgentsTool } from './list_agents.js';
16
+ import { invokeAgentTool } from './invoke_agent.js';
17
+ import { listCommandsTool } from './list_commands.js';
18
+ import { invokeCommandTool } from './invoke_command.js';
19
+ import { getAgentContextTool } from './get_agent_context.js';
20
+ import { getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool } from './task_tools.js';
21
+ export declare function registerBuiltins(registry: ToolRegistry): void;
22
+ export { readFileTool, readDocumentTool, readImageTool, readAttachmentTool, writeTool, editTool, multieditTool, globTool, grepTool, fetchTool, bashTool, listSkillsTool, readSkillTool, listAgentsTool, invokeAgentTool, listCommandsTool, invokeCommandTool, getAgentContextTool, getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, };
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACf,MAAM,iBAAiB,CAAC;AAEzB,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAmD7D;AAED,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,cAAc,GACf,CAAC"}
@@ -0,0 +1,74 @@
1
+ // Built-in (in-process, native) tools shipped with the app. New native
2
+ // tools are added here. The future MCP adapter will register additional
3
+ // tools alongside these via a separate entry point.
4
+ import { readFileTool } from './read_file.js';
5
+ import { readDocumentTool } from './read_document.js';
6
+ import { readImageTool } from './read_image.js';
7
+ import { readAttachmentTool } from './read_attachment.js';
8
+ import { writeTool } from './write.js';
9
+ import { editTool } from './edit.js';
10
+ import { multieditTool } from './multiedit.js';
11
+ import { globTool } from './glob.js';
12
+ import { grepTool } from './grep.js';
13
+ import { fetchTool } from './fetch.js';
14
+ import { bashTool } from './bash.js';
15
+ import { listSkillsTool } from './list_skills.js';
16
+ import { readSkillTool } from './read_skill.js';
17
+ import { listAgentsTool } from './list_agents.js';
18
+ import { invokeAgentTool } from './invoke_agent.js';
19
+ import { listCommandsTool } from './list_commands.js';
20
+ import { invokeCommandTool } from './invoke_command.js';
21
+ import { getAgentContextTool } from './get_agent_context.js';
22
+ import { getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, } from './task_tools.js';
23
+ export function registerBuiltins(registry) {
24
+ // Filesystem (sandboxed to ctx.workingDir).
25
+ registry.register(readFileTool);
26
+ registry.register(readDocumentTool);
27
+ registry.register(readImageTool);
28
+ registry.register(readAttachmentTool);
29
+ registry.register(writeTool);
30
+ registry.register(editTool);
31
+ registry.register(multieditTool);
32
+ registry.register(globTool);
33
+ registry.register(grepTool);
34
+ // Network.
35
+ registry.register(fetchTool);
36
+ // Shell.
37
+ registry.register(bashTool);
38
+ // Plugin skills (auto-included by resolveAgentTools when an agent has
39
+ // active plugins; not part of the agent's allowedTools surface).
40
+ registry.register(listSkillsTool);
41
+ registry.register(readSkillTool);
42
+ // Sub-agent dispatch (auto-included by resolveAgentTools when there is
43
+ // more than one agent configured — they're useless otherwise).
44
+ registry.register(listAgentsTool);
45
+ registry.register(invokeAgentTool);
46
+ // Slash commands as tools — same gating as skills (auto-included when
47
+ // the agent has at least one plugin active).
48
+ registry.register(listCommandsTool);
49
+ registry.register(invokeCommandTool);
50
+ // Self-introspection (always present — the agent should be able to ask
51
+ // "how much context am I using" without prerequisites).
52
+ registry.register(getAgentContextTool);
53
+ // Autonomous task tools.
54
+ registry.register(getTaskStateTool);
55
+ registry.register(updateChecklistItemTool);
56
+ registry.register(updateChecklistTool);
57
+ registry.register(addMessageTool);
58
+ registry.register(completeTaskTool);
59
+ registry.register(blockTaskTool);
60
+ registry.register(yieldTaskTool);
61
+ registry.register(projectListTool);
62
+ registry.register(taskCreateTool);
63
+ registry.register(taskSearchTool);
64
+ registry.register(taskUnblockTool);
65
+ registry.register(taskActivateTool);
66
+ registry.register(taskUnpauseTool);
67
+ registry.register(taskDiscardWorktreeTool);
68
+ registry.register(taskArchiveTool);
69
+ registry.register(taskUnarchiveTool);
70
+ registry.register(taskDeleteTool);
71
+ registry.register(taskSetAgentTool);
72
+ registry.register(submitPlanTool);
73
+ }
74
+ export { readFileTool, readDocumentTool, readImageTool, readAttachmentTool, writeTool, editTool, multieditTool, globTool, grepTool, fetchTool, bashTool, listSkillsTool, readSkillTool, listAgentsTool, invokeAgentTool, listCommandsTool, invokeCommandTool, getAgentContextTool, getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, };
@@ -0,0 +1,3 @@
1
+ import type { Tool } from '../types.js';
2
+ export declare const invokeAgentTool: Tool;
3
+ //# sourceMappingURL=invoke_agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke_agent.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/invoke_agent.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AA2BxC,eAAO,MAAM,eAAe,EAAE,IAgE7B,CAAC"}
@@ -0,0 +1,106 @@
1
+ // Dispatch a one-shot task to another agent and return its final assistant
2
+ // text. Two modes:
3
+ //
4
+ // 1. Named — `invoke_agent({name, task})` looks up the agent in
5
+ // agents.json and dispatches it with field-level inheritance applied
6
+ // to its empty runtime fields. Self-invocation is rejected: an agent
7
+ // with a fixed identity/goal in its systemPrompt would just spin on
8
+ // its own goal again.
9
+ //
10
+ // 2. Anonymous — `invoke_agent({task})` (no `name`) spins up an
11
+ // ephemeral generic agent that inherits provider, model, allowedTools,
12
+ // plugins, mcpServers, workingDir, confirmTools from the caller and
13
+ // has NO systemPrompt of its own. The task becomes the only user
14
+ // message. Useful for delegating speculative subtasks without
15
+ // polluting the parent's history and without dragging the parent's
16
+ // identity along. Bounded by the standard dispatch-depth cap.
17
+ //
18
+ // Errors during the child run (provider failure, missing config, abort,
19
+ // guard) surface as `Error: <msg>` so the parent loop continues.
20
+ import { randomUUID } from 'node:crypto';
21
+ import { loadAgents } from '../../../store/json.js';
22
+ // dispatchAgent is lazy-imported to break a static-import cycle:
23
+ // instance.ts → builtin/index.ts → invoke_agent.ts → agents/dispatch.ts
24
+ // → harness/tools/instance.js (singleton) ← back to start
25
+ // At call time the modules are fully initialized, so the dynamic import is
26
+ // safe and adds one cache lookup per invocation (negligible).
27
+ function buildAnonymousAgent(callerMaxTurns) {
28
+ // Empty everywhere — every meaningful field gets filled in by
29
+ // effectiveAgent's inheritance rule from ctx.callerAgent. The fresh
30
+ // UUID guarantees the self-invocation guard cannot misfire.
31
+ return {
32
+ id: randomUUID(),
33
+ name: '(anonymous)',
34
+ systemPrompt: '',
35
+ provider: '',
36
+ model: '',
37
+ allowedTools: [],
38
+ // maxTurns isn't inherited; pick something sensible. The caller's
39
+ // own cap is a fine upper bound for a one-shot subtask.
40
+ maxTurns: callerMaxTurns,
41
+ };
42
+ }
43
+ export const invokeAgentTool = {
44
+ name: 'invoke_agent',
45
+ description: 'Invoke another agent one-shot with a task. Two modes: ' +
46
+ '(1) pass `name` (from list_agents) to dispatch a configured agent — ' +
47
+ 'runtime fields it left empty inherit from you, but its systemPrompt ' +
48
+ 'is its own (so use this when you want a specific identity/goal). ' +
49
+ '(2) omit `name` to spin up an ANONYMOUS sub-agent that inherits ' +
50
+ 'provider/model/tools/plugins/mcpServers/workingDir from you and has ' +
51
+ 'no systemPrompt — the task IS the prompt. Useful for speculative ' +
52
+ 'subtasks you want isolated from your own history. There is never ' +
53
+ 'shared history; each invocation starts fresh.',
54
+ parameters: {
55
+ type: 'object',
56
+ properties: {
57
+ name: {
58
+ type: 'string',
59
+ description: "Optional. AgentConfig.name from list_agents (e.g. 'security-auditor' or " +
60
+ "'code-modernization/legacy-analyst'). Omit to dispatch an anonymous sub-agent.",
61
+ },
62
+ task: {
63
+ type: 'string',
64
+ description: 'What you want the invoked agent to do. This becomes its only user message.',
65
+ },
66
+ },
67
+ required: ['task'],
68
+ additionalProperties: false,
69
+ },
70
+ async execute(args, ctx) {
71
+ const a = args;
72
+ if (typeof a.task !== 'string' || !a.task.trim()) {
73
+ return { content: 'Error: task must be a non-empty string' };
74
+ }
75
+ let invoked;
76
+ if (a.name === undefined || (typeof a.name === 'string' && a.name.trim() === '')) {
77
+ invoked = buildAnonymousAgent(ctx.callerAgent?.maxTurns ?? 30);
78
+ }
79
+ else if (typeof a.name === 'string') {
80
+ const all = await loadAgents();
81
+ const found = all.find((x) => x.name === a.name);
82
+ if (!found)
83
+ return { content: `Error: agent "${a.name}" not found` };
84
+ invoked = found;
85
+ }
86
+ else {
87
+ return { content: 'Error: name must be a string when provided' };
88
+ }
89
+ const { dispatchAgent } = await import('../../../agents/dispatch.js');
90
+ const result = await dispatchAgent({ invoked, task: a.task, ctx });
91
+ if (result.guardError) {
92
+ return { content: `Error: ${result.guardError}` };
93
+ }
94
+ if (result.stop === 'aborted') {
95
+ return { content: 'Error: invocation aborted' };
96
+ }
97
+ if (result.stop === 'max_turns') {
98
+ return {
99
+ content: result.text
100
+ ? `${result.text}\n\n(invocation hit max_turns without a clean stop)`
101
+ : 'Error: invocation hit max_turns without producing output',
102
+ };
103
+ }
104
+ return { content: result.text };
105
+ },
106
+ };
@@ -0,0 +1,3 @@
1
+ import type { Tool } from '../types.js';
2
+ export declare const invokeCommandTool: Tool;
3
+ //# sourceMappingURL=invoke_command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke_command.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/invoke_command.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGxC,eAAO,MAAM,iBAAiB,EAAE,IAmC/B,CAAC"}
@@ -0,0 +1,42 @@
1
+ // Expand a slash command template and return the result so the model can
2
+ // act on it. Mirrors the user-side path in tui/chat.tsx:
3
+ // 1. resolveCommand(name, activePlugins) — gates on agent.plugins
4
+ // 2. tokenizeArgs(args) — same quoting rules as the chat input
5
+ // 3. expandTemplate(body, args, raw) — `$1`..`$9` and `$ARGUMENTS`
6
+ // The expanded body comes back as the tool result; the model reads it
7
+ // inline and follows the instructions in the same conversation.
8
+ import { expandTemplate, resolveCommand, tokenizeArgs } from '../../../commands/loader.js';
9
+ export const invokeCommandTool = {
10
+ name: 'invoke_command',
11
+ description: 'Expand a slash command template into prose you can act on. Pass `name` ' +
12
+ '(from list_commands) and optionally `args` as a single string — the ' +
13
+ 'same text that would follow `/foo` in the chat input. Whitespace splits ' +
14
+ 'into positionals; double-quoted spans are kept as one. The expanded ' +
15
+ 'body is returned as the tool result; follow its instructions.',
16
+ parameters: {
17
+ type: 'object',
18
+ properties: {
19
+ name: { type: 'string', description: 'Command name from list_commands.' },
20
+ args: {
21
+ type: 'string',
22
+ description: 'Args as a single string (everything that would follow `/<name>`). ' +
23
+ 'Optional; commands with no positionals or no `$ARGUMENTS` ignore it.',
24
+ },
25
+ },
26
+ required: ['name'],
27
+ additionalProperties: false,
28
+ },
29
+ async execute(args, ctx) {
30
+ const a = args;
31
+ if (typeof a.name !== 'string' || !a.name.trim()) {
32
+ return { content: 'Error: name must be a non-empty string' };
33
+ }
34
+ const cmd = await resolveCommand(a.name, ctx.activePlugins ?? []);
35
+ if (!cmd) {
36
+ return { content: `Error: command "${a.name}" is not available` };
37
+ }
38
+ const tail = typeof a.args === 'string' ? a.args : '';
39
+ const tokens = tokenizeArgs(tail);
40
+ return { content: expandTemplate(cmd.spec.body, tokens, tail) };
41
+ },
42
+ };
@@ -0,0 +1,3 @@
1
+ import type { Tool } from '../types.js';
2
+ export declare const listAgentsTool: Tool;
3
+ //# sourceMappingURL=list_agents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list_agents.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/list_agents.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAUxC,eAAO,MAAM,cAAc,EAAE,IA0B5B,CAAC"}