@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,141 @@
1
+ // Ported from caretaker server's src/mcp/fs.ts (read).
2
+ // Sandbox check, line-numbered output, offset/limit pagination, binary
3
+ // detection. On success the absolute path is added to ctx.readPaths so
4
+ // the write tool's read-before-write guard will permit overwrites.
5
+ import { open, stat } from 'node:fs/promises';
6
+ import { createReadStream } from 'node:fs';
7
+ import { createInterface } from 'node:readline';
8
+ import { assertWithinRoot, OutsideRootError } from '../sandbox.js';
9
+ const DEFAULT_LIMIT = 2000;
10
+ const MAX_LINE_LENGTH = 2000;
11
+ const MAX_OUTPUT_BYTES = 256 * 1024;
12
+ const SAMPLE_BYTES = 4096;
13
+ function isBinarySample(buf) {
14
+ if (buf.length === 0)
15
+ return false;
16
+ let nonPrintable = 0;
17
+ for (let i = 0; i < buf.length; i++) {
18
+ const b = buf[i];
19
+ if (b === 0)
20
+ return true;
21
+ if (b < 9 || (b > 13 && b < 32))
22
+ nonPrintable++;
23
+ }
24
+ return nonPrintable / buf.length > 0.3;
25
+ }
26
+ async function readSample(abs, size) {
27
+ if (size === 0)
28
+ return Buffer.alloc(0);
29
+ const fh = await open(abs, 'r');
30
+ try {
31
+ const len = Math.min(size, SAMPLE_BYTES);
32
+ const buf = Buffer.alloc(len);
33
+ await fh.read(buf, 0, len, 0);
34
+ return buf;
35
+ }
36
+ finally {
37
+ await fh.close();
38
+ }
39
+ }
40
+ async function streamLines(abs, offset, limit) {
41
+ const stream = createReadStream(abs, { encoding: 'utf-8' });
42
+ const rl = createInterface({ input: stream, crlfDelay: Infinity });
43
+ const start = offset - 1;
44
+ const raw = [];
45
+ let total = 0;
46
+ let bytes = 0;
47
+ let cut = false;
48
+ let more = false;
49
+ try {
50
+ for await (const text of rl) {
51
+ total++;
52
+ if (total <= start)
53
+ continue;
54
+ if (raw.length >= limit) {
55
+ more = true;
56
+ continue;
57
+ }
58
+ const line = text.length > MAX_LINE_LENGTH
59
+ ? text.slice(0, MAX_LINE_LENGTH) + '… (line truncated)'
60
+ : text;
61
+ const size = Buffer.byteLength(line, 'utf-8') + (raw.length > 0 ? 1 : 0);
62
+ if (bytes + size > MAX_OUTPUT_BYTES) {
63
+ cut = true;
64
+ more = true;
65
+ break;
66
+ }
67
+ raw.push(line);
68
+ bytes += size;
69
+ }
70
+ }
71
+ finally {
72
+ rl.close();
73
+ stream.destroy();
74
+ }
75
+ return { raw, total, cut, more };
76
+ }
77
+ export const readFileTool = {
78
+ name: 'read_file',
79
+ description: 'Read a file from the working directory (cat -n style with line numbers). ' +
80
+ 'Use offset/limit to paginate large files. Required before overwriting an ' +
81
+ 'existing file with `write`; `edit` and `multiedit` rely on oldString matching instead.',
82
+ parameters: {
83
+ type: 'object',
84
+ properties: {
85
+ path: { type: 'string', description: 'Path within the working directory.' },
86
+ offset: { type: 'number', description: '1-based line offset (default 1).' },
87
+ limit: { type: 'number', description: 'Max lines to return (default 2000).' },
88
+ },
89
+ required: ['path'],
90
+ additionalProperties: false,
91
+ },
92
+ async execute(args, ctx) {
93
+ const a = args;
94
+ if (typeof a.path !== 'string' || !a.path.trim()) {
95
+ return { content: 'Error: path must be a non-empty string' };
96
+ }
97
+ let abs;
98
+ try {
99
+ abs = assertWithinRoot(ctx.workingDir, a.path);
100
+ }
101
+ catch (err) {
102
+ if (err instanceof OutsideRootError)
103
+ return { content: `Error: ${err.message}` };
104
+ throw err;
105
+ }
106
+ let st;
107
+ try {
108
+ st = await stat(abs);
109
+ }
110
+ catch (err) {
111
+ const code = err.code;
112
+ if (code === 'ENOENT')
113
+ return { content: `Error: file not found: ${a.path}` };
114
+ if (code === 'EACCES')
115
+ return { content: `Error: permission denied: ${a.path}` };
116
+ return { content: `Error: ${err instanceof Error ? err.message : String(err)}` };
117
+ }
118
+ if (st.isDirectory())
119
+ return { content: `Error: path is a directory: ${a.path}` };
120
+ const sample = await readSample(abs, st.size);
121
+ if (isBinarySample(sample)) {
122
+ return {
123
+ content: `Error: ${a.path} appears to be binary; only text files are supported`,
124
+ };
125
+ }
126
+ const offset = Math.max(1, typeof a.offset === 'number' ? a.offset : 1);
127
+ const limit = typeof a.limit === 'number' && a.limit > 0 ? a.limit : DEFAULT_LIMIT;
128
+ const result = await streamLines(abs, offset, limit);
129
+ const lines = result.raw.map((l, i) => `${String(offset + i).padStart(6, ' ')}\t${l}`);
130
+ let formatted = lines.join('\n');
131
+ const next = offset + result.raw.length;
132
+ if (result.cut) {
133
+ formatted += `\n\n(Output capped at ${MAX_OUTPUT_BYTES} bytes; use offset=${next} to continue)`;
134
+ }
135
+ else if (result.more) {
136
+ formatted += `\n\n(Showing lines ${offset}-${next - 1} of ${result.total}; use offset=${next} to continue)`;
137
+ }
138
+ ctx.readPaths.add(abs);
139
+ return { content: formatted };
140
+ },
141
+ };
@@ -0,0 +1,3 @@
1
+ import type { Tool } from '../types.js';
2
+ export declare const readImageTool: Tool;
3
+ //# sourceMappingURL=read_image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read_image.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/read_image.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGxC,eAAO,MAAM,aAAa,EAAE,IAwE3B,CAAC"}
@@ -0,0 +1,80 @@
1
+ import { readFile, stat } from 'node:fs/promises';
2
+ import * as path from 'node:path';
3
+ import { assertWithinRoot, OutsideRootError } from '../sandbox.js';
4
+ export const readImageTool = {
5
+ name: 'read_image',
6
+ description: 'Read an image file (PNG, JPEG, WEBP, GIF) from the working directory and load it as a tool attachment so the agent can inspect it.',
7
+ parameters: {
8
+ type: 'object',
9
+ properties: {
10
+ path: { type: 'string', description: 'Path within the working directory.' },
11
+ },
12
+ required: ['path'],
13
+ additionalProperties: false,
14
+ },
15
+ async execute(args, ctx) {
16
+ const a = args;
17
+ if (typeof a.path !== 'string' || !a.path.trim()) {
18
+ return { content: 'Error: path must be a non-empty string' };
19
+ }
20
+ let abs;
21
+ try {
22
+ abs = assertWithinRoot(ctx.workingDir, a.path);
23
+ }
24
+ catch (err) {
25
+ if (err instanceof OutsideRootError)
26
+ return { content: `Error: ${err.message}` };
27
+ throw err;
28
+ }
29
+ let st;
30
+ try {
31
+ st = await stat(abs);
32
+ }
33
+ catch (err) {
34
+ const code = err.code;
35
+ if (code === 'ENOENT')
36
+ return { content: `Error: file not found: ${a.path}` };
37
+ if (code === 'EACCES')
38
+ return { content: `Error: permission denied: ${a.path}` };
39
+ return { content: `Error: ${err instanceof Error ? err.message : String(err)}` };
40
+ }
41
+ if (st.isDirectory()) {
42
+ return { content: `Error: path is a directory: ${a.path}` };
43
+ }
44
+ const ext = path.extname(abs).toLowerCase();
45
+ let mime = '';
46
+ if (ext === '.png') {
47
+ mime = 'image/png';
48
+ }
49
+ else if (ext === '.jpg' || ext === '.jpeg') {
50
+ mime = 'image/jpeg';
51
+ }
52
+ else if (ext === '.webp') {
53
+ mime = 'image/webp';
54
+ }
55
+ else if (ext === '.gif') {
56
+ mime = 'image/gif';
57
+ }
58
+ else {
59
+ return {
60
+ content: `Error: unsupported image extension '${ext}'. Supported extensions: .png, .jpg, .jpeg, .webp, .gif`,
61
+ };
62
+ }
63
+ try {
64
+ const buffer = await readFile(abs);
65
+ ctx.readPaths.add(abs);
66
+ return {
67
+ content: `Loaded image ${a.path} (${buffer.length} bytes)`,
68
+ attachments: [
69
+ {
70
+ mime,
71
+ data: buffer,
72
+ },
73
+ ],
74
+ };
75
+ }
76
+ catch (err) {
77
+ return { content: `Error reading image: ${err instanceof Error ? err.message : String(err)}` };
78
+ }
79
+ },
80
+ };
@@ -0,0 +1,3 @@
1
+ import type { Tool } from '../types.js';
2
+ export declare const readSkillTool: Tool;
3
+ //# sourceMappingURL=read_skill.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read_skill.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/read_skill.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGxC,eAAO,MAAM,aAAa,EAAE,IAyB3B,CAAC"}
@@ -0,0 +1,30 @@
1
+ // Fetch the SKILL.md content for one active plugin by name. Names that are
2
+ // not in the agent's active-plugin list, or whose SKILL.md is missing /
3
+ // oversized, surface as a plain "Error: ..." result so the model can recover
4
+ // (e.g. by re-running list_skills).
5
+ import { readActiveSkill } from '../../../plugins/loader.js';
6
+ export const readSkillTool = {
7
+ name: 'read_skill',
8
+ description: 'Read the full instructions of one plugin skill by name. Use the names ' +
9
+ 'returned by `list_skills`. Returns the SKILL.md content; follow it ' +
10
+ 'directly — it is not itself a callable tool.',
11
+ parameters: {
12
+ type: 'object',
13
+ properties: {
14
+ name: { type: 'string', description: 'Skill name from list_skills.' },
15
+ },
16
+ required: ['name'],
17
+ additionalProperties: false,
18
+ },
19
+ async execute(args, ctx) {
20
+ const a = args;
21
+ if (typeof a.name !== 'string' || !a.name.trim()) {
22
+ return { content: 'Error: name must be a non-empty string' };
23
+ }
24
+ const content = await readActiveSkill(a.name, ctx.activePlugins ?? []);
25
+ if (content === null) {
26
+ return { content: `Error: skill "${a.name}" is not available` };
27
+ }
28
+ return { content };
29
+ },
30
+ };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Shell environment probe for Linux.
3
+ *
4
+ * On Linux, .bashrc typically exits early for non-interactive shells due to:
5
+ * [ -z "$PS1" ] && return
6
+ * or similar guards. This means NVM, volta, fnm et al. are NOT available
7
+ * even when spawning with `bash -l -c`.
8
+ *
9
+ * Solution: probe the environment once using an interactive shell
10
+ * (`bash -i -c 'env'`) which DOES source .bashrc, then merge relevant
11
+ * variables (PATH, NVM_DIR, VOLTA_HOME, FNM_DIR, etc.) into the
12
+ * subprocess env when running commands.
13
+ */
14
+ /**
15
+ * Resolved shell environment from probing.
16
+ */
17
+ export interface ShellEnvResult {
18
+ /** Environment variables extracted from interactive shell */
19
+ env: Record<string, string>;
20
+ /** Whether the probe was successful */
21
+ success: boolean;
22
+ /** Error message if probe failed */
23
+ error?: string;
24
+ }
25
+ /**
26
+ * Probe the interactive shell environment.
27
+ *
28
+ * This runs `bash -i -c 'env'` to get the full
29
+ * environment including user's .bashrc customizations.
30
+ *
31
+ * On Windows and macOS, this returns early with an empty result since
32
+ * those platforms handle PATH differently (login shells work correctly).
33
+ *
34
+ * @param force - Force re-probe even if cached result exists
35
+ * @returns Shell environment result
36
+ */
37
+ export declare function probeShellEnv(force?: boolean): Promise<ShellEnvResult>;
38
+ /**
39
+ * Get the cached shell environment, or probe if not yet done.
40
+ *
41
+ * This is a synchronous getter for use in tools where we don't want
42
+ * to await anything. Must call probeShellEnv() at startup.
43
+ */
44
+ export declare function getShellEnv(): Record<string, string>;
45
+ /**
46
+ * Merge the probed shell environment into the given env object.
47
+ *
48
+ * This is used by bash tool to inject PATH and other variables
49
+ * from the user's interactive shell environment.
50
+ *
51
+ * PATH is prepended (so user tools take precedence), while other
52
+ * variables are set only if not already present in the env.
53
+ */
54
+ export declare function mergeShellEnv(existingEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
55
+ //# sourceMappingURL=shell-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-env.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/shell-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAiCH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,6DAA6D;IAC7D,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,uCAAuC;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAKD;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,KAAK,UAAQ,GAAG,OAAO,CAAC,cAAc,CAAC,CA0B1E;AA6ED;;;;;GAKG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,WAAW,EAAE,MAAM,CAAC,UAAU,GAC7B,MAAM,CAAC,UAAU,CAkBnB"}
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Shell environment probe for Linux.
3
+ *
4
+ * On Linux, .bashrc typically exits early for non-interactive shells due to:
5
+ * [ -z "$PS1" ] && return
6
+ * or similar guards. This means NVM, volta, fnm et al. are NOT available
7
+ * even when spawning with `bash -l -c`.
8
+ *
9
+ * Solution: probe the environment once using an interactive shell
10
+ * (`bash -i -c 'env'`) which DOES source .bashrc, then merge relevant
11
+ * variables (PATH, NVM_DIR, VOLTA_HOME, FNM_DIR, etc.) into the
12
+ * subprocess env when running commands.
13
+ */
14
+ import { spawn } from "node:child_process";
15
+ /**
16
+ * Key environment variables to extract from the interactive shell.
17
+ * These are commonly set by version managers and user shell configs.
18
+ */
19
+ const RELEVANT_VARS = [
20
+ // PATH is always needed
21
+ "PATH",
22
+ // Node version managers
23
+ "NVM_DIR",
24
+ "NVM_BIN",
25
+ "NVM_INC",
26
+ "VOLTA_HOME",
27
+ "FNM_DIR",
28
+ "FNM_MULTISHELL_PATH",
29
+ // Other common dev tools
30
+ "GOPATH",
31
+ "GOBIN",
32
+ "CARGO_HOME",
33
+ "RUSTUP_HOME",
34
+ "PYENV_ROOT",
35
+ "RBENV_ROOT",
36
+ // Custom common dev tools
37
+ "JAVA_HOME",
38
+ "ANDROID_HOME",
39
+ "DOTNET_ROOT",
40
+ // Custom paths users may set
41
+ "NODE_PATH",
42
+ ];
43
+ let cachedResult = null;
44
+ let probePromise = null;
45
+ /**
46
+ * Probe the interactive shell environment.
47
+ *
48
+ * This runs `bash -i -c 'env'` to get the full
49
+ * environment including user's .bashrc customizations.
50
+ *
51
+ * On Windows and macOS, this returns early with an empty result since
52
+ * those platforms handle PATH differently (login shells work correctly).
53
+ *
54
+ * @param force - Force re-probe even if cached result exists
55
+ * @returns Shell environment result
56
+ */
57
+ export async function probeShellEnv(force = false) {
58
+ // Windows doesn't need this - handled differently
59
+ if (process.platform === "win32") {
60
+ return { env: {}, success: true };
61
+ }
62
+ // macOS doesn't need this - shells are typically login shells
63
+ // and .bash_profile/.zprofile are sourced properly
64
+ if (process.platform === "darwin") {
65
+ return { env: {}, success: true };
66
+ }
67
+ // Return cached result if available
68
+ if (cachedResult && !force) {
69
+ return cachedResult;
70
+ }
71
+ // If a probe is already in progress, wait for it
72
+ if (probePromise) {
73
+ return probePromise;
74
+ }
75
+ probePromise = doProbe();
76
+ cachedResult = await probePromise;
77
+ probePromise = null;
78
+ return cachedResult;
79
+ }
80
+ /**
81
+ * Perform the actual environment probe.
82
+ */
83
+ async function doProbe() {
84
+ const shell = process.env.SHELL || "/bin/bash";
85
+ const shellName = shell.split("/").pop() || "bash";
86
+ return new Promise((resolve) => {
87
+ const timeout = 10_000; // 10 second timeout
88
+ let stdout = "";
89
+ let stderr = "";
90
+ const proc = spawn(shell, ["-i", "-c", "env"], {
91
+ timeout,
92
+ // Don't inherit stdio - we want to capture output
93
+ stdio: ["ignore", "pipe", "pipe"],
94
+ // Run in its own session (setsid). An interactive shell (`-i`) enables
95
+ // job control and grabs the controlling terminal; sharing our TTY makes
96
+ // it send SIGTTIN/SIGTTOU to our process group, which STOPS the TUI
97
+ // ("[1]+ Stopped") right after boot. Detaching removes the controlling
98
+ // terminal so bash disables job control — .bashrc is still sourced.
99
+ detached: true,
100
+ });
101
+ proc.stdout.on("data", (data) => {
102
+ stdout += data.toString();
103
+ });
104
+ proc.stderr.on("data", (data) => {
105
+ stderr += data.toString();
106
+ });
107
+ proc.on("close", (code) => {
108
+ if (code !== 0 && stdout === "") {
109
+ console.warn(`[shell-env] Probe exited with code ${code}: ${stderr}`);
110
+ resolve({
111
+ env: {},
112
+ success: false,
113
+ error: `Shell probe failed with code ${code}`,
114
+ });
115
+ return;
116
+ }
117
+ const env = {};
118
+ // Parse env output (format: KEY=value per line)
119
+ for (const line of stdout.split("\n")) {
120
+ const eqIdx = line.indexOf("=");
121
+ if (eqIdx === -1)
122
+ continue;
123
+ const key = line.slice(0, eqIdx);
124
+ const value = line.slice(eqIdx + 1);
125
+ if (RELEVANT_VARS.includes(key)) {
126
+ env[key] = value;
127
+ }
128
+ }
129
+ console.log(`[shell-env] Probed ${shellName} environment, found ${Object.keys(env).length} relevant vars: ${Object.keys(env).join(", ") || "(none)"}`);
130
+ resolve({ env, success: true });
131
+ });
132
+ proc.on("error", (err) => {
133
+ console.warn(`[shell-env] Probe error:`, err.message);
134
+ resolve({
135
+ env: {},
136
+ success: false,
137
+ error: err.message,
138
+ });
139
+ });
140
+ });
141
+ }
142
+ /**
143
+ * Get the cached shell environment, or probe if not yet done.
144
+ *
145
+ * This is a synchronous getter for use in tools where we don't want
146
+ * to await anything. Must call probeShellEnv() at startup.
147
+ */
148
+ export function getShellEnv() {
149
+ if (!cachedResult) {
150
+ // Not yet probed - return empty, caller will use default env
151
+ console.warn("[shell-env] getShellEnv() called before probe completed");
152
+ return {};
153
+ }
154
+ return cachedResult.env;
155
+ }
156
+ /**
157
+ * Merge the probed shell environment into the given env object.
158
+ *
159
+ * This is used by bash tool to inject PATH and other variables
160
+ * from the user's interactive shell environment.
161
+ *
162
+ * PATH is prepended (so user tools take precedence), while other
163
+ * variables are set only if not already present in the env.
164
+ */
165
+ export function mergeShellEnv(existingEnv) {
166
+ const shellEnv = getShellEnv();
167
+ const merged = { ...existingEnv };
168
+ // Prepend shell PATH to existing PATH
169
+ if (shellEnv.PATH) {
170
+ merged.PATH = shellEnv.PATH + ":" + (existingEnv.PATH || "");
171
+ }
172
+ // Set other variables only if not already present
173
+ for (const [key, value] of Object.entries(shellEnv)) {
174
+ if (key === "PATH")
175
+ continue; // Already handled above
176
+ if (!(key in merged)) {
177
+ merged[key] = value;
178
+ }
179
+ }
180
+ return merged;
181
+ }
@@ -0,0 +1,21 @@
1
+ import type { Tool } from '../types.js';
2
+ export declare const getTaskStateTool: Tool;
3
+ export declare const updateChecklistItemTool: Tool;
4
+ export declare const updateChecklistTool: Tool;
5
+ export declare const addMessageTool: Tool;
6
+ export declare const completeTaskTool: Tool;
7
+ export declare const blockTaskTool: Tool;
8
+ export declare const yieldTaskTool: Tool;
9
+ export declare const projectListTool: Tool;
10
+ export declare const taskCreateTool: Tool;
11
+ export declare const taskSearchTool: Tool;
12
+ export declare const taskUnblockTool: Tool;
13
+ export declare const taskActivateTool: Tool;
14
+ export declare const taskUnpauseTool: Tool;
15
+ export declare const taskDiscardWorktreeTool: Tool;
16
+ export declare const taskArchiveTool: Tool;
17
+ export declare const taskUnarchiveTool: Tool;
18
+ export declare const taskDeleteTool: Tool;
19
+ export declare const taskSetAgentTool: Tool;
20
+ export declare const submitPlanTool: Tool;
21
+ //# sourceMappingURL=task_tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task_tools.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/task_tools.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AAapD,eAAO,MAAM,gBAAgB,EAAE,IAmD9B,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,IAgCrC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,IA4CjC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAiC5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,IAgD9B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,IAoC3B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,IAoC3B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IAa7B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAgG5B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IA+B5B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IAwC7B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,IAoC9B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IAwC7B,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,IAwBrC,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IAkC7B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,IA8B/B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAqC5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,IAgD9B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAuC5B,CAAC"}