@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.35

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 (466) hide show
  1. package/CHANGELOG.md +368 -0
  2. package/README.md +341 -208
  3. package/dist/adapters.d.ts +3 -4
  4. package/dist/adapters.js +18 -15
  5. package/dist/agent-rows.d.ts +99 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +75 -25
  9. package/dist/agents.d.ts +9 -125
  10. package/dist/agents.js +15 -305
  11. package/dist/answer-json.d.ts +23 -0
  12. package/dist/answer-json.js +58 -0
  13. package/dist/api-only.d.ts +1 -1
  14. package/dist/api-only.js +2 -2
  15. package/dist/archil-settings.d.ts +11 -1
  16. package/dist/archil-settings.js +10 -0
  17. package/dist/bash-read-only.d.ts +35 -0
  18. package/dist/bash-read-only.js +778 -0
  19. package/dist/box-settings.d.ts +3 -23
  20. package/dist/box-settings.js +7 -51
  21. package/dist/boxes.d.ts +17 -0
  22. package/dist/boxes.js +27 -20
  23. package/dist/browser-commands.d.ts +5 -2
  24. package/dist/browser-commands.js +4 -4
  25. package/dist/browser-computer.d.ts +5 -0
  26. package/dist/browser-computer.js +21 -0
  27. package/dist/browser-cost.d.ts +9 -6
  28. package/dist/browser-cost.js +95 -51
  29. package/dist/browser-live.d.ts +7 -20
  30. package/dist/browser-live.js +15 -93
  31. package/dist/browser-person.d.ts +18 -51
  32. package/dist/browser-person.js +94 -277
  33. package/dist/budget.d.ts +0 -5
  34. package/dist/budget.js +0 -5
  35. package/dist/cap.d.ts +14 -8
  36. package/dist/cap.js +19 -9
  37. package/dist/cli.js +71 -18
  38. package/dist/closed-pipes.d.ts +2 -0
  39. package/dist/closed-pipes.js +13 -0
  40. package/dist/computer-commands.d.ts +2 -0
  41. package/dist/computer-commands.js +2 -0
  42. package/dist/computer-keys.d.ts +20 -10
  43. package/dist/computer-keys.js +36 -54
  44. package/dist/computer-setting.d.ts +20 -3
  45. package/dist/computer-setting.js +58 -10
  46. package/dist/computers.d.ts +35 -2
  47. package/dist/computers.js +72 -11
  48. package/dist/confine.d.ts +120 -0
  49. package/dist/confine.js +436 -0
  50. package/dist/console/assets/index-B7NKTU8E.css +1 -0
  51. package/dist/console/assets/index-CXZMgJE7.js +550 -0
  52. package/dist/console/index.html +2 -2
  53. package/dist/content-filter.d.ts +7 -0
  54. package/dist/content-filter.js +23 -0
  55. package/dist/decision-cap.d.ts +7 -29
  56. package/dist/decision-cap.js +3 -94
  57. package/dist/decision-rows.d.ts +1 -1
  58. package/dist/decision-rows.js +1 -1
  59. package/dist/docker-daemon.d.ts +31 -0
  60. package/dist/docker-daemon.js +56 -0
  61. package/dist/effort-guidance.js +4 -3
  62. package/dist/environment.d.ts +0 -3
  63. package/dist/environment.js +3 -5
  64. package/dist/errors.d.ts +1 -2
  65. package/dist/errors.js +9 -9
  66. package/dist/explain.js +3 -1
  67. package/dist/filed-answer.d.ts +32 -0
  68. package/dist/filed-answer.js +160 -0
  69. package/dist/files.d.ts +1 -3
  70. package/dist/files.js +2 -4
  71. package/dist/github-connection.d.ts +1 -1
  72. package/dist/github-connection.js +25 -7
  73. package/dist/github-faux.d.ts +26 -0
  74. package/dist/github-faux.js +76 -0
  75. package/dist/github.d.ts +6 -2
  76. package/dist/github.js +5 -3
  77. package/dist/graph-served.d.ts +5 -3
  78. package/dist/graph-served.js +14 -6
  79. package/dist/graph-view.d.ts +3 -5
  80. package/dist/graph-view.js +9 -16
  81. package/dist/handed-values.d.ts +9 -0
  82. package/dist/handed-values.js +26 -0
  83. package/dist/harness-install.d.ts +1 -7
  84. package/dist/harness-install.js +1 -18
  85. package/dist/harness-opencode/adapter.d.ts +7 -0
  86. package/dist/harness-opencode/adapter.js +23 -6
  87. package/dist/harness-opencode/harness.js +0 -1
  88. package/dist/harness-opencode/host/policy.js +2 -2
  89. package/dist/harness-opencode/index.d.ts +1 -1
  90. package/dist/harness-opencode/index.js +1 -1
  91. package/dist/harness-opencode/verify.d.ts +17 -0
  92. package/dist/harness-opencode/verify.js +30 -10
  93. package/dist/harness-table.js +6 -1
  94. package/dist/heard.js +1 -1
  95. package/dist/held-fd.d.ts +5 -0
  96. package/dist/held-fd.js +14 -0
  97. package/dist/host-calls.d.ts +20 -0
  98. package/dist/host-calls.js +12 -0
  99. package/dist/host-tools.d.ts +4 -21
  100. package/dist/host-tools.js +4 -61
  101. package/dist/host.d.ts +2 -4
  102. package/dist/host.js +2 -7
  103. package/dist/import-summary.d.ts +1 -5
  104. package/dist/import-summary.js +0 -21
  105. package/dist/import.d.ts +6 -6
  106. package/dist/import.js +14 -15
  107. package/dist/index.d.ts +1 -0
  108. package/dist/index.js +1 -0
  109. package/dist/key-refusal.d.ts +5 -1
  110. package/dist/key-refusal.js +19 -4
  111. package/dist/learn/check.d.ts +8 -2
  112. package/dist/learn/check.js +85 -31
  113. package/dist/learn/folder.d.ts +11 -4
  114. package/dist/learn/folder.js +17 -19
  115. package/dist/learn/grade.d.ts +18 -1
  116. package/dist/learn/grade.js +108 -14
  117. package/dist/learn/index.d.ts +5 -5
  118. package/dist/learn/index.js +5 -5
  119. package/dist/learn/learning.sh +1 -14
  120. package/dist/learn/notes.d.ts +14 -3
  121. package/dist/learn/notes.js +16 -6
  122. package/dist/learn/reflect.d.ts +31 -2
  123. package/dist/learn/reflect.js +83 -6
  124. package/dist/learn/relevance.d.ts +24 -0
  125. package/dist/learn/relevance.js +91 -0
  126. package/dist/learn/secrets.d.ts +7 -1
  127. package/dist/learn/secrets.js +86 -19
  128. package/dist/learn/skills.d.ts +159 -18
  129. package/dist/learn/skills.js +644 -64
  130. package/dist/learned-nodes.d.ts +14 -0
  131. package/dist/learned-nodes.js +8 -0
  132. package/dist/learned-workflow.d.ts +41 -6
  133. package/dist/learned-workflow.js +153 -18
  134. package/dist/learning-routes.d.ts +49 -4
  135. package/dist/learning-routes.js +113 -31
  136. package/dist/learning-run.d.ts +16 -31
  137. package/dist/learning-run.js +31 -38
  138. package/dist/learning-words.d.ts +12 -5
  139. package/dist/learning-words.js +18 -9
  140. package/dist/learning.d.ts +91 -97
  141. package/dist/learning.js +176 -320
  142. package/dist/live/stream.js +1 -1
  143. package/dist/live/translate.js +12 -2
  144. package/dist/llm.d.ts +4 -1
  145. package/dist/llm.js +4 -2
  146. package/dist/local-models.d.ts +11 -5
  147. package/dist/local-models.js +13 -8
  148. package/dist/mcp-gateway.d.ts +17 -49
  149. package/dist/mcp-gateway.js +55 -136
  150. package/dist/mcp-oauth.d.ts +10 -14
  151. package/dist/mcp-oauth.js +14 -32
  152. package/dist/mcp-probe.d.ts +0 -7
  153. package/dist/mcp-probe.js +4 -10
  154. package/dist/mcp-servers-store.d.ts +18 -18
  155. package/dist/mcp-servers-store.js +12 -14
  156. package/dist/mcp-store.js +3 -4
  157. package/dist/mcp.js +4 -3
  158. package/dist/model.d.ts +9 -7
  159. package/dist/model.js +51 -27
  160. package/dist/monid.d.ts +0 -2
  161. package/dist/monid.js +3 -6
  162. package/dist/openapi.d.ts +8 -1
  163. package/dist/openapi.js +156 -58
  164. package/dist/page.d.ts +1 -3
  165. package/dist/page.js +6 -18
  166. package/dist/paid-calls.d.ts +21 -27
  167. package/dist/paid-calls.js +26 -61
  168. package/dist/pause.d.ts +2 -19
  169. package/dist/pause.js +5 -74
  170. package/dist/port-models.d.ts +10 -3
  171. package/dist/port-models.js +26 -6
  172. package/dist/propose.d.ts +2 -0
  173. package/dist/propose.js +80 -45
  174. package/dist/push-handler.d.ts +1 -1
  175. package/dist/reflect-range.d.ts +25 -0
  176. package/dist/reflect-range.js +30 -0
  177. package/dist/refusal-words.d.ts +5 -1
  178. package/dist/refusal-words.js +5 -1
  179. package/dist/rows.d.ts +1 -1
  180. package/dist/run-cut.d.ts +0 -6
  181. package/dist/run-cut.js +0 -6
  182. package/dist/run-db.d.ts +2 -11
  183. package/dist/run-db.js +2 -37
  184. package/dist/run-launch.d.ts +21 -2
  185. package/dist/run-launch.js +14 -5
  186. package/dist/run-learning-served.d.ts +21 -4
  187. package/dist/run-learning-served.js +23 -13
  188. package/dist/run-reads-over-store.d.ts +5 -3
  189. package/dist/run-reads-over-store.js +25 -14
  190. package/dist/run-secrets.d.ts +1 -1
  191. package/dist/run-timeline-served.d.ts +5 -1
  192. package/dist/run-timeline-served.js +27 -6
  193. package/dist/run-view.d.ts +37 -22
  194. package/dist/run-view.js +85 -38
  195. package/dist/runnable.d.ts +21 -10
  196. package/dist/runnable.js +35 -12
  197. package/dist/runner/adapter-loop.d.ts +36 -5
  198. package/dist/runner/adapter-loop.js +663 -69
  199. package/dist/runner/adapter-run-spec.d.ts +42 -8
  200. package/dist/runner/adapter-run-spec.js +186 -52
  201. package/dist/runner/adapters/index.js +11 -1
  202. package/dist/runner/adapters/pi.d.ts +40 -2
  203. package/dist/runner/adapters/pi.js +110 -27
  204. package/dist/runner/beside.d.ts +38 -3
  205. package/dist/runner/beside.js +54 -5
  206. package/dist/runner/claim-secrets.d.ts +16 -1
  207. package/dist/runner/claim-secrets.js +62 -14
  208. package/dist/runner/cli-run-spec.d.ts +5 -0
  209. package/dist/runner/cli-run-spec.js +159 -41
  210. package/dist/runner/commands.js +1 -1
  211. package/dist/runner/computer-journal.d.ts +15 -2
  212. package/dist/runner/computer-journal.js +41 -5
  213. package/dist/runner/conformance/harness.d.ts +1 -0
  214. package/dist/runner/conformance/harness.js +123 -13
  215. package/dist/runner/conformance/subject.d.ts +4 -1
  216. package/dist/runner/dispatch.d.ts +8 -1
  217. package/dist/runner/dispatch.js +81 -7
  218. package/dist/runner/end-of-run.d.ts +8 -2
  219. package/dist/runner/end-of-run.js +10 -4
  220. package/dist/runner/github-app.d.ts +7 -2
  221. package/dist/runner/github-app.js +47 -16
  222. package/dist/runner/harness-loops.d.ts +15 -2
  223. package/dist/runner/harness-loops.js +38 -2
  224. package/dist/runner/journal-kinds.d.ts +60 -6
  225. package/dist/runner/journal-kinds.js +43 -5
  226. package/dist/runner/journal-reader.d.ts +1 -1
  227. package/dist/runner/journal-reader.js +2 -2
  228. package/dist/runner/learning-ask.d.ts +4 -0
  229. package/dist/runner/learning-ask.js +15 -1
  230. package/dist/runner/learning-end.d.ts +18 -3
  231. package/dist/runner/learning-end.js +194 -20
  232. package/dist/runner/learning-loop.d.ts +7 -0
  233. package/dist/runner/learning-loop.js +36 -8
  234. package/dist/runner/learning-seed.d.ts +6 -0
  235. package/dist/runner/learning-seed.js +6 -0
  236. package/dist/runner/loop-contract.d.ts +4 -0
  237. package/dist/runner/main.d.ts +61 -9
  238. package/dist/runner/main.js +144 -20
  239. package/dist/runner/mcp-claim.d.ts +3 -0
  240. package/dist/runner/mcp-claim.js +7 -3
  241. package/dist/runner/mcp-github.d.ts +11 -2
  242. package/dist/runner/mcp-github.js +55 -4
  243. package/dist/runner/mcp-run.d.ts +2 -0
  244. package/dist/runner/mcp-run.js +16 -5
  245. package/dist/runner/memory-claim.d.ts +9 -0
  246. package/dist/runner/memory-claim.js +25 -0
  247. package/dist/runner/metrics.d.ts +46 -1
  248. package/dist/runner/metrics.js +156 -1
  249. package/dist/runner/model-route.d.ts +16 -0
  250. package/dist/runner/model-route.js +134 -10
  251. package/dist/runner/reflect-hook.d.ts +12 -1
  252. package/dist/runner/reflect-hook.js +33 -3
  253. package/dist/runner/runner.d.ts +20 -0
  254. package/dist/runner/runner.js +146 -18
  255. package/dist/runner/spec-holds.d.ts +7 -2
  256. package/dist/runner/spec-holds.js +4 -3
  257. package/dist/runner/store-port.d.ts +1 -1
  258. package/dist/runner/store-secrets.d.ts +3 -3
  259. package/dist/runner/store-secrets.js +8 -12
  260. package/dist/runner/text-tools.d.ts +44 -0
  261. package/dist/runner/text-tools.js +237 -0
  262. package/dist/runner/workflow-host.d.ts +7 -2
  263. package/dist/runner/workflow-host.js +3 -1
  264. package/dist/runner/workflow-loop.d.ts +10 -1
  265. package/dist/runner/workflow-loop.js +14 -6
  266. package/dist/runner/workflow-spec.d.ts +21 -0
  267. package/dist/runner/workflow-spec.js +217 -93
  268. package/dist/runs-over-store.d.ts +14 -3
  269. package/dist/runs-over-store.js +100 -23
  270. package/dist/seal-key.d.ts +0 -2
  271. package/dist/seal-key.js +5 -45
  272. package/dist/sealed-settings-store.d.ts +19 -4
  273. package/dist/sealed-settings-store.js +9 -9
  274. package/dist/sealing.d.ts +4 -0
  275. package/dist/sealing.js +20 -0
  276. package/dist/secret-cut.d.ts +1 -1
  277. package/dist/secret-cut.js +1 -1
  278. package/dist/secret-name.d.ts +9 -0
  279. package/dist/secret-name.js +15 -0
  280. package/dist/secret-writes.d.ts +0 -1
  281. package/dist/secret-writes.js +0 -1
  282. package/dist/server-fs.d.ts +4 -0
  283. package/dist/server-fs.js +8 -2
  284. package/dist/server-lock.d.ts +0 -24
  285. package/dist/server-lock.js +5 -85
  286. package/dist/server-secrets-store.d.ts +4 -4
  287. package/dist/server-secrets-store.js +9 -31
  288. package/dist/server-secrets.d.ts +4 -9
  289. package/dist/server-secrets.js +12 -36
  290. package/dist/server.d.ts +37 -56
  291. package/dist/server.js +322 -134
  292. package/dist/sign-ins-store.d.ts +34 -36
  293. package/dist/sign-ins-store.js +27 -38
  294. package/dist/sign-ins.d.ts +2 -119
  295. package/dist/sign-ins.js +5 -311
  296. package/dist/standard-webhooks.d.ts +1 -1
  297. package/dist/standard-webhooks.js +1 -1
  298. package/dist/stats.d.ts +3 -2
  299. package/dist/stats.js +1 -1
  300. package/dist/stop-signals.d.ts +4 -2
  301. package/dist/stop-signals.js +5 -3
  302. package/dist/store/agent-body.d.ts +12 -2
  303. package/dist/store/agent-body.js +22 -4
  304. package/dist/store/deadline.d.ts +18 -0
  305. package/dist/store/deadline.js +45 -0
  306. package/dist/store/index.d.ts +2 -2
  307. package/dist/store/index.js +2 -2
  308. package/dist/store/open.d.ts +6 -3
  309. package/dist/store/open.js +2 -2
  310. package/dist/store/postgres/connection.d.ts +22 -2
  311. package/dist/store/postgres/connection.js +211 -41
  312. package/dist/store/postgres/migrate.d.ts +4 -0
  313. package/dist/store/postgres/migrate.js +9 -2
  314. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  315. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  316. package/dist/store/postgres/store.d.ts +9 -2
  317. package/dist/store/postgres/store.js +9 -0
  318. package/dist/store/schema.js +1 -1
  319. package/dist/store/seal.js +2 -2
  320. package/dist/store/sqlite/connection.js +14 -5
  321. package/dist/store/sqlite/run-patch.d.ts +3 -0
  322. package/dist/store/sqlite/run-patch.js +3 -0
  323. package/dist/store/sqlite/store.js +41 -12
  324. package/dist/store/store.d.ts +35 -6
  325. package/dist/store/store.js +12 -2
  326. package/dist/store-reads/cap.d.ts +1 -1
  327. package/dist/store-reads/cap.js +22 -4
  328. package/dist/store-reads/journal.d.ts +9 -6
  329. package/dist/store-reads/journal.js +129 -18
  330. package/dist/store-reads/learning.d.ts +82 -8
  331. package/dist/store-reads/learning.js +184 -11
  332. package/dist/store-reads/workflow.d.ts +1 -1
  333. package/dist/store-reads/workflow.js +1 -1
  334. package/dist/store-view.d.ts +19 -1
  335. package/dist/store-view.js +95 -27
  336. package/dist/template-eval.d.ts +60 -4
  337. package/dist/template-eval.js +120 -54
  338. package/dist/templates.d.ts +33 -14
  339. package/dist/templates.js +82 -46
  340. package/dist/timeline/group.d.ts +33 -0
  341. package/dist/timeline/group.js +77 -0
  342. package/dist/timeline/index.d.ts +7 -0
  343. package/dist/timeline/index.js +7 -0
  344. package/dist/timeline/labels.d.ts +79 -0
  345. package/dist/timeline/labels.js +150 -0
  346. package/dist/timeline/origin.d.ts +56 -0
  347. package/dist/timeline/origin.js +92 -0
  348. package/dist/timeline/render-text.d.ts +11 -0
  349. package/dist/timeline/render-text.js +62 -0
  350. package/dist/timeline/timeline.d.ts +282 -0
  351. package/dist/timeline/timeline.js +1308 -0
  352. package/dist/timeline/util.d.ts +17 -0
  353. package/dist/timeline/util.js +49 -0
  354. package/dist/tool-budget.d.ts +18 -0
  355. package/dist/tool-budget.js +50 -0
  356. package/dist/tool-gate.d.ts +47 -218
  357. package/dist/tool-gate.js +87 -545
  358. package/dist/tool-keys-store.d.ts +11 -12
  359. package/dist/tool-keys-store.js +24 -31
  360. package/dist/tool-keys.d.ts +5 -101
  361. package/dist/tool-keys.js +8 -267
  362. package/dist/tool-plane.d.ts +23 -52
  363. package/dist/tool-plane.js +23 -81
  364. package/dist/tool-settings-store.d.ts +1 -2
  365. package/dist/tool-settings-store.js +5 -8
  366. package/dist/tools.d.ts +67 -25
  367. package/dist/tools.js +170 -119
  368. package/dist/trigger-adapter.d.ts +2 -2
  369. package/dist/trigger-targets.d.ts +13 -1
  370. package/dist/trigger-targets.js +31 -1
  371. package/dist/triggers.d.ts +2 -2
  372. package/dist/triggers.js +3 -3
  373. package/dist/turn-end.d.ts +1 -1
  374. package/dist/turn-end.js +1 -1
  375. package/dist/turns.d.ts +0 -6
  376. package/dist/turns.js +0 -19
  377. package/dist/uploads.d.ts +28 -5
  378. package/dist/uploads.js +83 -10
  379. package/dist/usage.d.ts +1 -49
  380. package/dist/usage.js +3 -84
  381. package/dist/validate.d.ts +4 -0
  382. package/dist/validate.js +33 -14
  383. package/dist/webhooks.d.ts +102 -76
  384. package/dist/webhooks.js +266 -233
  385. package/dist/workflow-run.d.ts +114 -0
  386. package/dist/workflow-run.js +144 -0
  387. package/dist/workspace/archil-claim.d.ts +2 -2
  388. package/dist/workspace/archil-claim.js +4 -3
  389. package/dist/workspace/archil-disk.d.ts +10 -1
  390. package/dist/workspace/archil-disk.js +4 -0
  391. package/dist/workspace/archil-exec.d.ts +12 -2
  392. package/dist/workspace/archil-exec.js +16 -0
  393. package/dist/workspace/archil.d.ts +2 -2
  394. package/dist/workspace/archil.js +25 -5
  395. package/dist/workspace/attach.js +2 -0
  396. package/dist/workspace/beneath.d.ts +19 -0
  397. package/dist/workspace/beneath.js +106 -0
  398. package/dist/workspace/computer-deps.d.ts +26 -9
  399. package/dist/workspace/computer-deps.js +144 -43
  400. package/dist/workspace/computer-for-claim.d.ts +17 -14
  401. package/dist/workspace/computer-for-claim.js +99 -26
  402. package/dist/workspace/computer-hold.d.ts +6 -1
  403. package/dist/workspace/computer-hold.js +6 -1
  404. package/dist/workspace/computer-janitor.d.ts +47 -0
  405. package/dist/workspace/computer-janitor.js +182 -0
  406. package/dist/workspace/computer-ledger.d.ts +1 -8
  407. package/dist/workspace/computer-ledger.js +0 -3
  408. package/dist/workspace/computer-providers.d.ts +5 -3
  409. package/dist/workspace/computer-providers.js +11 -9
  410. package/dist/workspace/grep-worker.d.ts +5 -0
  411. package/dist/workspace/grep-worker.js +9 -6
  412. package/dist/workspace/hands.d.ts +5 -2
  413. package/dist/workspace/hands.js +4 -3
  414. package/dist/workspace/index.d.ts +6 -5
  415. package/dist/workspace/index.js +4 -4
  416. package/dist/workspace/local.d.ts +14 -2
  417. package/dist/workspace/local.js +170 -43
  418. package/dist/workspace/paths.js +3 -2
  419. package/dist/workspace/pi-env.d.ts +4 -0
  420. package/dist/workspace/pi-env.js +3 -2
  421. package/dist/workspace/resolve-computer.d.ts +55 -10
  422. package/dist/workspace/resolve-computer.js +66 -14
  423. package/dist/workspace/run-tools.d.ts +15 -31
  424. package/dist/workspace/run-tools.js +19 -30
  425. package/dist/workspace/workspace.d.ts +5 -0
  426. package/dist/workspace-paths.d.ts +0 -17
  427. package/dist/workspace-paths.js +1 -41
  428. package/dist/workspace.d.ts +0 -17
  429. package/dist/workspace.js +4 -110
  430. package/package.json +14 -14
  431. package/skills/agentrun-serve/SKILL.md +1 -1
  432. package/templates/README.md +11 -5
  433. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  434. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  435. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  436. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  437. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  438. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  439. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  440. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  441. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  442. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  443. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  444. package/templates/market-monitor/agent.md +2 -2
  445. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  446. package/templates/release-notes/agent.md +11 -0
  447. package/dist/bound-files.d.ts +0 -4
  448. package/dist/bound-files.js +0 -164
  449. package/dist/coding-tools.d.ts +0 -47
  450. package/dist/coding-tools.js +0 -189
  451. package/dist/computer-adb.d.ts +0 -12
  452. package/dist/computer-adb.js +0 -14
  453. package/dist/console/assets/index-Dn0ngwG9.js +0 -535
  454. package/dist/console/assets/index-DvW6Aled.css +0 -1
  455. package/dist/grade.d.ts +0 -63
  456. package/dist/grade.js +0 -150
  457. package/dist/mcp-servers.d.ts +0 -269
  458. package/dist/mcp-servers.js +0 -456
  459. package/dist/packs.d.ts +0 -71
  460. package/dist/packs.js +0 -180
  461. package/dist/sealed-settings.d.ts +0 -60
  462. package/dist/sealed-settings.js +0 -171
  463. package/dist/sessions.d.ts +0 -6
  464. package/dist/sessions.js +0 -109
  465. package/dist/workspace/computer-serves.d.ts +0 -12
  466. package/dist/workspace/computer-serves.js +0 -15
@@ -0,0 +1,778 @@
1
+ // The read-only bash policy: an agent's own tool setting `tool_settings.bash.policy: "read-only"` (a template's
2
+ // `tool_policy: {bash: read-only}`). The tool gate (tool-gate.ts RunGate.decide) reads every bash call's command before it
3
+ // runs or anyone is asked, and refuses, in words the model reads, any command that could write, run code, or read outside
4
+ // the run's folder. A policy adds to bash's permission and is never one, as a pin is: bash: deny still refuses, an allow
5
+ // or an ask decides only once the policy let the command through, and approvals "never" lifts no refusal of it. An
6
+ // approved call is decided again on its resume, so the policy holds then too.
7
+ //
8
+ // The rule, for one command line:
9
+ // - Shape: a shell-style tokenizer (single quotes, double quotes, backslash escapes; a quoted or escaped `;` is part of
10
+ // its word). Commands are joined by `;` or `&&`; a line with a `cd` joins them by `&&` only, so a cd that fails stops
11
+ // what follows. Refused outright: `||`, a lone `&` (backgrounding), `$` (variables, `$(...)`), backticks, subshells and
12
+ // braces, `!`, newlines and carriage returns, NUL, and `~` or `#` at a word's start. A command may pipe into a filter
13
+ // (PIPE_TARGETS), each segment checked as a command. The only redirections are the exact words `2>/dev/null` and
14
+ // `2>&1`; any other `>` or `<` is refused.
15
+ // - Programs: PROGRAMS only (git's read subcommands, grep, sed -n, cat, head, tail, wc, ls, find and the like). Every
16
+ // other program, a shell, an interpreter, a package manager, xargs, env, awk, tee, is refused.
17
+ // - Paths: for every program, `--` ends the options; every positional (and every `--opt=value` value) must stay inside
18
+ // the run's folder, lexically: resolved from the command's directory, never absolute elsewhere, never `~`, never up
19
+ // past the folder with `..`, and never a name on the never-open list (.env*, .ssh/, id_rsa*, *.pem, *.key, .npmrc,
20
+ // .netrc, .git-credentials, credentials). A short option with an attached path (`-f/x`) is refused. The policy reads
21
+ // the command, never the folder: a symbolic link in the folder is followed by the program that opens it, so what a
22
+ // link can reach is the computer's to contain (a run's computer holds no key of the server's).
23
+ // - Globs: a word holding `*`, `?`, `[` or `]` is refused unless all of them are quoted or escaped (the shell never
24
+ // expands it: an expanded glob is the folder's file names, any of which may read as an option), and it is a grep/rg
25
+ // pattern, a `--include=`/`--exclude=`/`--exclude-dir=` value (grep, egrep, fgrep, rg) or find's `-name`/`-iname`
26
+ // value, that value holding no `/`.
27
+ // - git: `--no-pager` and `-C <dir>` (a directory inside the folder; later paths are read from it, as git reads them)
28
+ // may precede a read subcommand (GIT_READS); options that read or write a file, run a program, page, or point git at
29
+ // another repository are refused, their abbreviations too (git takes those).
30
+ // - sed: `-n` with one `N,Mp` range script (`$` for the last line), nothing else. find: no -exec, -execdir, -ok,
31
+ // -okdir, -delete, -fprint*, -fls, -L, -follow or -H. sort: no -o or -T. tail: no -f. diff: no -r. grep and rg: no
32
+ // -R, --pre, --follow; rg no -L, -z or --hostname-bin. `--files0-from` is refused for every program. Each refused
33
+ // long option is refused with every prefix too (`sort --out=f`), as GNU getopt takes an unambiguous prefix.
34
+ // - The shell tools: bash's command is read as above. bash_background and bash_input are refused (a read-only shell
35
+ // runs one command in the foreground); bash_output, bash_list and bash_signal, which reach only processes this run
36
+ // started, pass. A CLI harness's own shell call (codex's `shell`, an argv) is read as the command it runs.
37
+ //
38
+ // - The shell's environment: a shell under a policy runs git with its config locked down (policyEnv, below): no
39
+ // system or global config, and command-line config that turns off what a repository's config could run.
40
+ //
41
+ // What it does not hold: the policy reads bash alone. An agent that may also write or edit can change what a read
42
+ // program obeys (a repository's .git/config names programs git runs), so a read-only agent's tools are read and bash.
43
+ // The never-open list refuses a command that names such a file; it is no fence around the folder's contents: a recursive
44
+ // search (grep -r, rg, git grep, git log -p) reads every file the folder holds. The folder holds the run's own files
45
+ // (its checkout, its inputs), never a key of the server's, and the agent may read all of it.
46
+ import { posix } from "node:path";
47
+ /** The policies an agent may set on bash (tool_settings.bash.policy). */
48
+ export const BASH_POLICIES = ["read-only"];
49
+ /** An agent's bash policy as its own tool settings write it (tool_settings.bash.policy), or undefined for none: any
50
+ * value, a policy this server does not know too (the gate refuses its every call; policyEnv holds its shell all the same). */
51
+ export function bashPolicyOf(toolSettings) {
52
+ const bash = typeof toolSettings === "object" && toolSettings !== null ? toolSettings.bash : undefined;
53
+ const policy = typeof bash === "object" && bash !== null ? bash.policy : undefined;
54
+ return policy === undefined ? undefined : String(policy);
55
+ }
56
+ // git's config under a policy. The policy refuses `git -c`, `--config-env`, `--ext-diff`, `--textconv` and `--paginate`,
57
+ // but git also reads config from files, and config can name a program git runs on a plain read (core.fsmonitor on
58
+ // status and diff, core.pager, a hook on an index write, a diff or filter driver that an attribute attaches to a path, a
59
+ // signature program for log's %G?, a transport for a partial clone's lazy fetch). A checkout of someone else's code can
60
+ // hold such config: a bare repository planted in the tree, found when a command runs from inside it. So a shell under a
61
+ // policy runs git with:
62
+ // - no system or global config (the image's and HOME's are no business of a read);
63
+ // - command-line config (GIT_CONFIG_COUNT, which outranks every file) turning those programs off: no fsmonitor, hooks
64
+ // from /dev/null, cat as the pager, attributes from an empty tree and no attributes file (so no in-tree .gitattributes
65
+ // attaches a textconv, external diff or filter driver), a bare repository only when named (safe.bareRepository,
66
+ // which git reads from command-line config, never a repository's own), no transport at all, and no signature program;
67
+ // - GIT_PAGER and PAGER cat, no prompt, no optional lock (status leaves the index unwritten) and no lazy fetch.
68
+ // The config needs git 2.43 (attr.tree; safe.bareRepository is 2.38), and an older git ignores what it does not know,
69
+ // so a shell under a policy runs with a prelude (policyPrelude) defining `git` as a function that runs git only at 2.43
70
+ // or later and otherwise refuses, in words, before anything runs: fail closed, never a read with half the lock-down.
71
+ // Archil's stock exec image has git 2.34 (archil.ts), so a Mode 2 server runs its execs in DEFAULT_ARCHIL_EXEC_IMAGE
72
+ // (archil-settings.ts, git 2.47) unless the owner saved another, which needs git 2.43 too. The model cannot step around the function: the policy refuses `command`, a path to a program, `$`,
73
+ // `unset` and every program but git by name.
74
+ // What config cannot turn off: diff.external (an empty value makes git diff fail; git has no unset on the command
75
+ // line). It needs a repository's own config, which the policy never lets a command write and safe.bareRepository keeps
76
+ // a planted repository from supplying.
77
+ /** The empty tree's id, as attr.tree's value: attributes read from no tree (an id that does not resolve, a sha256
78
+ * repository's case, reads as the empty tree too). */
79
+ const EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
80
+ /** The command-line config a shell under a policy gives git (GIT_CONFIG_KEY_n / GIT_CONFIG_VALUE_n). */
81
+ export const POLICY_GIT_CONFIG = [
82
+ ["core.fsmonitor", "false"],
83
+ ["core.hooksPath", "/dev/null"],
84
+ ["core.pager", "cat"],
85
+ ["core.attributesFile", "/dev/null"],
86
+ ["attr.tree", EMPTY_TREE],
87
+ ["safe.bareRepository", "explicit"],
88
+ ["protocol.allow", "never"],
89
+ ["log.showSignature", "false"],
90
+ ["gpg.program", "false"],
91
+ ["gpg.openpgp.program", "false"],
92
+ ["gpg.x509.program", "false"],
93
+ ["gpg.ssh.program", "false"],
94
+ ];
95
+ /** What a shell under bash policy `policy` adds to the run's fixed environment (hands.ts shellEnv): git's config locked
96
+ * down (POLICY_GIT_CONFIG and the variables above); nothing without a policy. */
97
+ export function policyEnv(policy) {
98
+ if (policy === undefined)
99
+ return {};
100
+ return {
101
+ GIT_CONFIG_NOSYSTEM: "1",
102
+ GIT_CONFIG_GLOBAL: "/dev/null",
103
+ GIT_ATTR_NOSYSTEM: "1",
104
+ GIT_TERMINAL_PROMPT: "0",
105
+ GIT_PAGER: "cat",
106
+ PAGER: "cat",
107
+ GIT_OPTIONAL_LOCKS: "0",
108
+ GIT_NO_LAZY_FETCH: "1",
109
+ GIT_CONFIG_COUNT: String(POLICY_GIT_CONFIG.length),
110
+ ...Object.fromEntries(POLICY_GIT_CONFIG.flatMap(([key, value], n) => [[`GIT_CONFIG_KEY_${n}`, key], [`GIT_CONFIG_VALUE_${n}`, value]])),
111
+ };
112
+ }
113
+ /** The oldest git that holds the whole lock-down (attr.tree). */
114
+ export const POLICY_GIT_FLOOR = "2.43";
115
+ // `git version` at the floor or later: 2.43-2.49, 2.50-2.99, 2.100 and up, 3 and up.
116
+ const GIT_AT_FLOOR = `"git version 2.4"[3-9]*|"git version 2."[5-9][0-9]*|"git version 2."[1-9][0-9][0-9]*|"git version "[3-9]*|"git version "[1-9][0-9]*`;
117
+ const GIT_FUNCTION = `git() { case "$(command git version 2>/dev/null)" in ${GIT_AT_FLOOR}) command git "$@" ;; *) echo "git refused: this agent's bash policy needs git ${POLICY_GIT_FLOOR} or later to keep a repository's config from running a program, and this shell has $(command git version 2>/dev/null || echo no git); nothing ran." >&2; return 126 ;; esac; }`;
118
+ /** What a shell under bash policy `policy` runs before the command, on a line of its own: `git` as a function that runs
119
+ * git only at POLICY_GIT_FLOOR or later. Empty without a policy. POSIX sh, for bash and the sh fallback alike. */
120
+ export function policyPrelude(policy) {
121
+ return policy === undefined ? "" : `${GIT_FUNCTION}\n`;
122
+ }
123
+ /** The programs a read-only command may run. */
124
+ export const PROGRAMS = new Set(["git", "grep", "egrep", "fgrep", "rg", "sed", "ls", "cat", "head", "tail", "wc", "nl", "sort", "uniq", "cut", "tr", "find", "diff", "basename", "dirname", "true", "echo"]);
125
+ /** The programs a command may pipe into: filters of their input. */
126
+ export const PIPE_TARGETS = new Set(["head", "tail", "sed", "wc", "sort", "uniq", "grep", "egrep", "fgrep", "rg", "cut", "tr", "nl"]);
127
+ /** git's read subcommands. */
128
+ export const GIT_READS = new Set(["diff", "show", "log", "blame", "grep", "ls-files", "ls-tree", "rev-parse", "cat-file", "merge-base", "status", "shortlog", "rev-list", "diff-tree", "name-rev", "describe"]);
129
+ /** The only redirections: stderr dropped, or joined to stdout. */
130
+ const REDIRECTIONS = ["2>/dev/null", "2>&1"];
131
+ /** The shell tools that only watch or end a process the run started: nothing for a read-only shell to refuse. */
132
+ const WATCHERS = new Set(["bash_output", "bash_list", "bash_signal"]);
133
+ /** What a refusal adds, so the model knows what it may run instead. */
134
+ export const READ_ONLY_HINT = "Use read commands only: git diff, show, log, grep, ls-files, merge-base or rev-parse; grep -n; sed -n 'N,Mp' FILE; cat, head, tail, wc, ls; find without -exec. Pipe only into head, tail, sed -n, grep, wc, sort, uniq, cut, tr or nl, with no redirection but 2>/dev/null or 2>&1, no $ or backticks, and quote glob patterns.";
135
+ /** The refusal of a call under the read-only policy, as the model reads it: the reason, that it did not run, and what may. */
136
+ export const readOnlyText = (tool, reason, notRun) => `${tool} is read-only for this agent, so this call was refused: ${reason}. ${notRun} ${READ_ONLY_HINT}`;
137
+ // The never-open list: any path segment `.ssh`, or a final name matching.
138
+ const SECRET = [/^\.env/, /^id_rsa/, /\.pem$/, /\.key$/, /^\.npmrc$/, /^\.netrc$/, /^\.git-credentials$/, /^credentials(\.json)?$/];
139
+ const secretPath = (rel) => {
140
+ const segments = rel.split("/");
141
+ return segments.includes(".ssh") || SECRET.some((re) => re.test(segments[segments.length - 1] ?? ""));
142
+ };
143
+ /** `given` from the folder-relative directory `here`, as a folder-relative path ("" for the folder), or undefined when
144
+ * it leaves the folder. Lexical (posix): no link is read. */
145
+ function inFolder(folder, here, given) {
146
+ if (given.startsWith("~") || given.includes("\0"))
147
+ return undefined;
148
+ const abs = posix.resolve(posix.join(folder[0], here), given);
149
+ for (const name of folder.map((one) => posix.resolve(one))) {
150
+ if (abs === name)
151
+ return "";
152
+ if (abs.startsWith(name === "/" ? "/" : `${name}/`))
153
+ return abs.slice(name === "/" ? 1 : name.length + 1);
154
+ }
155
+ return undefined;
156
+ }
157
+ /** `p`, from `here`, as a folder-relative path; throws when it leaves the folder or is on the never-open list. */
158
+ function checkPath(folder, here, p, what = "path") {
159
+ if (p.startsWith("~"))
160
+ throw new Error(`${what} ${p}: ~ is not allowed`);
161
+ const rel = inFolder(folder, here, p);
162
+ if (rel === undefined)
163
+ throw new Error(`${what} ${p} is outside the run's folder`);
164
+ if (secretPath(rel))
165
+ throw new Error(`${what} ${p} is on the never-open list (.env*, .ssh/, id_rsa*, *.pem, *.key, .npmrc, .netrc, .git-credentials, credentials)`);
166
+ return rel;
167
+ }
168
+ /** A grep/rg pattern is never opened, but if its position was misjudged it would be: it must still not name a path
169
+ * outside the folder. The never-open list is not applied to a pattern. */
170
+ function checkPattern(folder, here, p) {
171
+ if (p.startsWith("~"))
172
+ throw new Error(`pattern ${p}: ~ is not allowed`);
173
+ if (inFolder(folder, here, p) === undefined)
174
+ throw new Error(`pattern ${p} would name a path outside the run's folder`);
175
+ }
176
+ /** The shell-style tokenizer. Words come back unquoted; operators are `;`, `&&`, `|` and the two redirections. */
177
+ function tokenize(command) {
178
+ if (/[\n\r]/.test(command))
179
+ throw new Error("newlines and carriage returns are not allowed: give one command line");
180
+ if (/[\u0000\u0001]/.test(command))
181
+ throw new Error("NUL and \\u0001 characters are not allowed");
182
+ const tokens = [];
183
+ let current = "";
184
+ let inWord = false;
185
+ let unquotedGlob = false;
186
+ const push = () => {
187
+ if (inWord)
188
+ tokens.push({ word: (unquotedGlob ? "\u0001" : "") + current });
189
+ current = "";
190
+ inWord = false;
191
+ unquotedGlob = false;
192
+ };
193
+ let i = 0;
194
+ while (i < command.length) {
195
+ const c = command[i];
196
+ if (c === "'") {
197
+ const j = command.indexOf("'", i + 1);
198
+ if (j < 0)
199
+ throw new Error("unterminated quote");
200
+ current += command.slice(i + 1, j);
201
+ inWord = true;
202
+ i = j + 1;
203
+ continue;
204
+ }
205
+ if (c === '"') {
206
+ let j = i + 1;
207
+ while (j < command.length && command[j] !== '"') {
208
+ const d = command[j];
209
+ if (d === "$" || d === "`")
210
+ throw new Error("$ and backticks are not allowed (no variables or command substitution)");
211
+ if (d === "\\" && j + 1 < command.length && '$`"\\'.includes(command[j + 1])) {
212
+ current += command[j + 1];
213
+ j += 2;
214
+ continue;
215
+ }
216
+ current += d;
217
+ j++;
218
+ }
219
+ if (j >= command.length)
220
+ throw new Error("unterminated quote");
221
+ inWord = true;
222
+ i = j + 1;
223
+ continue;
224
+ }
225
+ if (c === "\\") {
226
+ if (i + 1 >= command.length)
227
+ throw new Error("trailing backslash");
228
+ current += command[i + 1];
229
+ inWord = true;
230
+ i += 2;
231
+ continue;
232
+ }
233
+ if (c === " " || c === "\t") {
234
+ push();
235
+ i++;
236
+ continue;
237
+ }
238
+ if (c === ";") {
239
+ push();
240
+ tokens.push({ op: ";" });
241
+ i++;
242
+ continue;
243
+ }
244
+ if (c === "&") {
245
+ if (command[i + 1] === "&") {
246
+ push();
247
+ tokens.push({ op: "&&" });
248
+ i += 2;
249
+ continue;
250
+ }
251
+ throw new Error("a lone & (backgrounding) is not allowed");
252
+ }
253
+ if (c === "|") {
254
+ if (command[i + 1] === "|")
255
+ throw new Error("|| is not allowed");
256
+ push();
257
+ tokens.push({ op: "|" });
258
+ i++;
259
+ continue;
260
+ }
261
+ if (c === ">" || c === "<") {
262
+ // Only the exact words 2>/dev/null and 2>&1, standing alone.
263
+ const start = i - 1;
264
+ const redirection = REDIRECTIONS.find((one) => command.startsWith(one, start));
265
+ const end = start + (redirection ? redirection.length : 0);
266
+ if (redirection && inWord && current === "2" && (start === 0 || " \t".includes(command[start - 1])) &&
267
+ (end === command.length || " \t;|".includes(command[end]) || command.startsWith("&&", end))) {
268
+ current = "";
269
+ inWord = false;
270
+ tokens.push({ op: redirection });
271
+ i = end;
272
+ continue;
273
+ }
274
+ throw new Error("redirection is not allowed (only 2>/dev/null and 2>&1): nothing may be written");
275
+ }
276
+ if ("$`(){}!".includes(c))
277
+ throw new Error(`${JSON.stringify(c)} is not allowed (no variables, command substitution, subshells or history)`);
278
+ if (!inWord && (c === "~" || c === "#"))
279
+ throw new Error(`${JSON.stringify(c)} at a word's start is not allowed`);
280
+ if ("*?[]".includes(c))
281
+ unquotedGlob = true;
282
+ current += c;
283
+ inWord = true;
284
+ i++;
285
+ }
286
+ push();
287
+ return tokens;
288
+ }
289
+ /** The command line's commands, each a pipeline of segments (word lists), and the operators that join them. */
290
+ function parse(command) {
291
+ const commands = [];
292
+ const joins = [];
293
+ let pipe = [[]];
294
+ const endCommand = (last) => {
295
+ const empty = pipe.length === 1 && pipe[0].length === 0;
296
+ if (empty) {
297
+ if (last && commands.length > 0 && joins[joins.length - 1] === ";") {
298
+ joins.pop(); // one trailing `;` is fine
299
+ return;
300
+ }
301
+ throw new Error("empty command");
302
+ }
303
+ if (pipe.some((segment) => segment.length === 0))
304
+ throw new Error("empty pipeline segment");
305
+ commands.push(pipe);
306
+ pipe = [[]];
307
+ };
308
+ for (const token of tokenize(command)) {
309
+ if ("op" in token) {
310
+ if (token.op === ";" || token.op === "&&") {
311
+ endCommand(false);
312
+ joins.push(token.op);
313
+ }
314
+ else if (token.op === "|") {
315
+ if (pipe[pipe.length - 1].length === 0)
316
+ throw new Error("empty pipeline segment");
317
+ pipe.push([]);
318
+ }
319
+ else
320
+ pipe[pipe.length - 1].push(`\u0000${token.op}`);
321
+ }
322
+ else
323
+ pipe[pipe.length - 1].push(token.word);
324
+ }
325
+ endCommand(true);
326
+ if (commands.length === 0)
327
+ throw new Error("empty command");
328
+ return { commands, joins };
329
+ }
330
+ // Long options that read a file, write a file, run a program, page, or point git elsewhere (git's global options and its
331
+ // read subcommands'). An unambiguous abbreviation of one (git takes those) is refused too.
332
+ const GIT_BAD_LONG = [
333
+ "--config", "--config-env", "--git-dir", "--work-tree", "--namespace", "--exec-path", "--super-prefix",
334
+ "--paginate", "--list-cmds", "--attr-source", "--output", "--output-directory", "--ext-diff", "--textconv",
335
+ "--no-index", "--orderfile", "--open-files-in-pager", "--contents", "--ignore-revs-file", "--file",
336
+ "--exclude-from", "--exclude-per-directory", "--pathspec-from-file", "--pathspec-file-nul", "--filters", "--path",
337
+ "--resolve-git-dir", "--git-path", "--show-signature", "--upload-pack", "--receive-pack", "--exec", "--template",
338
+ "--separate-git-dir", "--reference",
339
+ ];
340
+ // Short options after the subcommand with the same effect: -O (an order file, or grep's pager), -X (ls-files' exclude
341
+ // file), blame -S (a revisions file), grep -f (a patterns file).
342
+ const GIT_BAD_SHORT = [/^-O/, /^-X/];
343
+ const GIT_BAD_SUB = { blame: [/^-S/], grep: [/^-f/] };
344
+ function gitOptionBad(sub, a) {
345
+ if (a.startsWith("--")) {
346
+ const name = a.split("=")[0];
347
+ if (name === "--")
348
+ return false;
349
+ return GIT_BAD_LONG.some((bad) => abbreviates(name, bad));
350
+ }
351
+ if (a.startsWith("-"))
352
+ return GIT_BAD_SHORT.some((re) => re.test(a)) || (GIT_BAD_SUB[sub] ?? []).some((re) => re.test(a));
353
+ return false;
354
+ }
355
+ /** An option word: a `--opt=value` value is a path (checked when it looks like one: holds `/`, starts with `.` or `~`);
356
+ * a short option never carries an attached path or `~`. */
357
+ function checkOption(folder, here, a) {
358
+ const eq = a.indexOf("=");
359
+ if (a.startsWith("--") && eq > 0) {
360
+ const value = a.slice(eq + 1);
361
+ if (value && (value.includes("/") || value.startsWith("~") || value.startsWith(".")))
362
+ checkPath(folder, here, value, `option value ${a.slice(0, eq)}=`);
363
+ return;
364
+ }
365
+ if (!a.startsWith("--") && a.includes("/"))
366
+ throw new Error(`option ${a}: an attached path is not allowed; give it as its own word`);
367
+ if (!a.startsWith("--") && a.includes("~"))
368
+ throw new Error(`option ${a}: ~ is not allowed`);
369
+ }
370
+ // Options that take their value as the next word, so that word is not taken for the pattern.
371
+ const GREP_VALUE_OPTS = new Set(["-m", "-A", "-B", "-C", "-d", "-D", "--max-count", "--context", "--after-context", "--before-context", "--binary-files", "--devices", "--directories", "--label", "--group-separator", "--exclude-from"]);
372
+ const RG_VALUE_OPTS = new Set(["-g", "--glob", "--iglob", "-t", "--type", "-T", "--type-not", "--type-add", "-m", "--max-count", "-A", "-B", "-C", "--context", "--after-context", "--before-context", "-M", "--max-columns", "-j", "--threads", "-E", "--encoding", "-r", "--replace", "-d", "--max-depth", "--sort", "--sortr", "--colors", "--path-separator", "--max-filesize", "--context-separator", "--field-match-separator", "--engine", "--ignore-file"]);
373
+ // Short options that take a value, per program (attached, `-e.`, or the next word, `-e .`).
374
+ const GREP_VALUE_LETTERS = "efmABCdD";
375
+ const RG_VALUE_LETTERS = "efgtTmABCMjErd";
376
+ const GREP_LIKE = ["grep", "egrep", "fgrep", "rg"];
377
+ const unmark = (w) => (w.startsWith("\u0001") ? w.slice(1) : w);
378
+ /** For a grep/rg short option word: its first value-taking letter, and that value as attached ("": the next word). */
379
+ function shortValue(program, w) {
380
+ if (!(w.length >= 2 && w[0] === "-" && w[1] !== "-"))
381
+ return null;
382
+ const letters = program === "rg" ? RG_VALUE_LETTERS : GREP_VALUE_LETTERS;
383
+ for (let i = 1; i < w.length; i++)
384
+ if (letters.includes(w[i]))
385
+ return { letter: w[i], attached: w.slice(i + 1) };
386
+ return null;
387
+ }
388
+ /** The index of the `--` that ends the options (not one taken as an option's value), or -1. */
389
+ function endOfOptions(program, rest) {
390
+ const grepLike = GREP_LIKE.includes(program);
391
+ const valueOpts = program === "rg" ? RG_VALUE_OPTS : GREP_VALUE_OPTS;
392
+ for (let k = 0; k < rest.length; k++) {
393
+ const a = rest[k];
394
+ if (a === "--")
395
+ return k;
396
+ if (grepLike) {
397
+ const sv = shortValue(program, a);
398
+ if ((sv && sv.attached === "") || a === "--regexp" || a === "--file" || valueOpts.has(a))
399
+ k++;
400
+ }
401
+ else if (program === "sed" && a === "-e")
402
+ k++;
403
+ }
404
+ return -1;
405
+ }
406
+ /** Whether long option `name` (`--out`, without its `=value`) is `bad` or a prefix of it: GNU getopt and git take any
407
+ * unambiguous prefix (`sort --out=f` is `--output=f`), so each prefix of a refused option is refused too. */
408
+ const abbreviates = (name, bad) => name === bad || (name.length >= 3 && name !== "--" && bad.startsWith(name));
409
+ // Long options that write a file, read a list of files, follow, or run a program, per program, refused with every
410
+ // prefix (abbreviates).
411
+ const LONG_BAN = {
412
+ sort: ["--output", "--compress-program", "--temporary-directory", "--files0-from"],
413
+ wc: ["--files0-from"],
414
+ tail: ["--follow", "--retry"],
415
+ diff: ["--to-file", "--from-file", "--recursive"],
416
+ grep: ["--dereference-recursive"], egrep: ["--dereference-recursive"], fgrep: ["--dereference-recursive"],
417
+ rg: ["--pre", "--pre-glob", "--follow", "--search-zip", "--hostname-bin"],
418
+ };
419
+ /** The indexes of the words options before `dd` (the `--` that ends them, -1: none) take as their value: the next word
420
+ * of a grep/rg option that takes one with none attached (`-e`, `-m`, `--regexp`, `--file`, ...), and of sed's `-e`. */
421
+ function optionValues(program, rest, dd) {
422
+ const values = new Set();
423
+ const grepLike = GREP_LIKE.includes(program);
424
+ const valueOpts = program === "rg" ? RG_VALUE_OPTS : GREP_VALUE_OPTS;
425
+ for (let k = 0; k < rest.length && (dd < 0 || k < dd); k++) {
426
+ const a = rest[k];
427
+ if (!a.startsWith("-") || a === "-")
428
+ continue;
429
+ const sv = grepLike ? shortValue(program, a) : null;
430
+ const takes = grepLike ? (sv !== null && sv.attached === "") || valueOpts.has(a) || a === "--regexp" || a === "--file" : program === "sed" && a === "-e";
431
+ if (takes && k + 1 < rest.length)
432
+ values.add(++k);
433
+ }
434
+ return values;
435
+ }
436
+ // A short-option cluster (`-rf`, `-iz`) may carry a refused letter that an exact match would miss.
437
+ const CLUSTER_BAN = { rg: /[zL]/, sort: /[oT]/, tail: /[fF]/, diff: /r/ };
438
+ const GIT_CLUSTER_BAN = { grep: /[Of]/, blame: /S/, "ls-files": /X/, diff: /O/, log: /O/, show: /O/, "diff-tree": /O/ };
439
+ const shortCluster = (a) => a.length > 2 && a[0] === "-" && a[1] !== "-";
440
+ const SED_RANGE = /^(\d+|\$)(,(\d+|\$|\+\d+))?p$/;
441
+ /** One pipeline segment, run from the folder-relative directory `start`. */
442
+ function checkSegment(folder, start, words) {
443
+ const marked = words.filter((w) => !w.startsWith("\u0000"));
444
+ const args = marked.map(unmark);
445
+ const program = args[0];
446
+ if (program === undefined)
447
+ throw new Error("a redirection alone is no command");
448
+ if (!PROGRAMS.has(program))
449
+ throw new Error(`${JSON.stringify(program)} is not a read command this policy runs`);
450
+ const rest = args.slice(1);
451
+ const restUnquotedGlob = marked.slice(1).map((w) => w.startsWith("\u0001"));
452
+ let here = start;
453
+ const dd = endOfOptions(program, rest);
454
+ const isOption = (idx) => (dd < 0 || idx < dd) && rest[idx].startsWith("-") && rest[idx] !== "-";
455
+ const exempt = new Set(); // never opened as files: the sed script, git's subcommand and -C, a rev:path
456
+ const patterns = new Set(); // grep/rg patterns: a relaxed check (checkPattern)
457
+ if (dd >= 0)
458
+ exempt.add(dd);
459
+ // The words an option takes as its value (grep's `-e --pre`, sed's `-e`): text, never an option of their own.
460
+ const values = optionValues(program, rest, dd);
461
+ for (let idx = 0; idx < rest.length; idx++) {
462
+ if (values.has(idx))
463
+ continue;
464
+ const name = rest[idx].split("=")[0];
465
+ if (isOption(idx) && (name === "-files0-from" || name === "--files0-from"))
466
+ throw new Error(`${program} ${rest[idx]} is not allowed (it reads a list of files to open)`);
467
+ if (isOption(idx) && name.startsWith("--") && (LONG_BAN[program] ?? []).some((bad) => abbreviates(name, bad)))
468
+ throw new Error(`${program} ${rest[idx]} is not allowed (it writes or names a file to read, follows, or runs a program; a prefix of such an option is refused too)`);
469
+ const ban = CLUSTER_BAN[program];
470
+ if (ban && isOption(idx) && shortCluster(rest[idx]) && ban.test(rest[idx].slice(1)))
471
+ throw new Error(`${program} option ${rest[idx]} is not allowed`);
472
+ }
473
+ switch (program) {
474
+ case "git": {
475
+ // Before the subcommand: --no-pager, and -C <dir> inside the folder (git reads later paths from it).
476
+ let k = 0;
477
+ for (;;) {
478
+ if (rest[k] === "--no-pager") {
479
+ exempt.add(k);
480
+ k++;
481
+ continue;
482
+ }
483
+ if (rest[k] === "-C") {
484
+ const dir = rest[k + 1];
485
+ if (dir === undefined)
486
+ throw new Error("git -C needs a directory");
487
+ if (/[*?[\]]/.test(dir))
488
+ throw new Error(`git -C ${dir}: a glob is not allowed`);
489
+ here = checkPath(folder, here, dir, "git -C");
490
+ exempt.add(k);
491
+ exempt.add(k + 1);
492
+ k += 2;
493
+ continue;
494
+ }
495
+ break;
496
+ }
497
+ const sub = rest[k];
498
+ if (sub === undefined || !GIT_READS.has(sub))
499
+ throw new Error(`git ${sub ?? ""} is not allowed: only --no-pager and -C <dir> may precede a read subcommand (${[...GIT_READS].join(", ")})`);
500
+ exempt.add(k);
501
+ for (let idx = k + 1; idx < rest.length; idx++) {
502
+ const a = rest[idx];
503
+ if (gitOptionBad(sub, a))
504
+ throw new Error(`git ${sub} option ${a} is not allowed (it reads or writes a file, runs a program, pages or points git elsewhere)`);
505
+ const ban = GIT_CLUSTER_BAN[sub];
506
+ if (ban && isOption(idx) && shortCluster(a) && ban.test(a.slice(1)))
507
+ throw new Error(`git ${sub} option ${a} is not allowed`);
508
+ if ((dd < 0 || idx < dd) && /^[^/:]*:/.test(a) && !a.startsWith("-")) {
509
+ // <rev>:<path> reads an object: its path part is checked as a path.
510
+ const p = a.slice(a.indexOf(":") + 1);
511
+ if (p)
512
+ checkPath(folder, here, p);
513
+ exempt.add(idx);
514
+ }
515
+ }
516
+ break;
517
+ }
518
+ case "sed": {
519
+ let hasN = false;
520
+ let sawScript = rest.some((x, k) => x === "-e" && isOption(k));
521
+ for (let k = 0; k < rest.length; k++) {
522
+ const x = rest[k];
523
+ if (k === dd)
524
+ continue;
525
+ if (isOption(k)) {
526
+ if (x === "-n") {
527
+ hasN = true;
528
+ exempt.add(k);
529
+ }
530
+ else if (x === "-E" || x === "-r")
531
+ exempt.add(k);
532
+ else if (x === "-e") {
533
+ if (!SED_RANGE.test(rest[k + 1] ?? ""))
534
+ throw new Error("sed's script must be one N,Mp range");
535
+ exempt.add(k);
536
+ exempt.add(k + 1);
537
+ k++;
538
+ }
539
+ else
540
+ throw new Error(`sed ${x} is not allowed (only -n with an N,Mp range)`);
541
+ }
542
+ else if (!sawScript) {
543
+ if (!SED_RANGE.test(x))
544
+ throw new Error("sed's script must be one N,Mp range");
545
+ exempt.add(k);
546
+ sawScript = true;
547
+ }
548
+ }
549
+ if (!hasN)
550
+ throw new Error("sed needs -n (sed -n 'N,Mp' FILE)");
551
+ break;
552
+ }
553
+ case "grep":
554
+ case "egrep":
555
+ case "fgrep":
556
+ case "rg": {
557
+ let explicit = false;
558
+ const takesValue = program === "rg" ? RG_VALUE_OPTS : GREP_VALUE_OPTS;
559
+ const nextIsValue = (k) => {
560
+ const sv = shortValue(program, rest[k]);
561
+ return (sv !== null && sv.attached === "") || takesValue.has(rest[k]) || rest[k] === "--regexp" || rest[k] === "--file";
562
+ };
563
+ for (let k = 0; k < rest.length; k++) {
564
+ const a = rest[k];
565
+ if (!isOption(k))
566
+ continue;
567
+ if (a === "-R" || a === "--dereference-recursive" || a.startsWith("--pre") || a === "--follow" ||
568
+ (program === "rg" && (a === "-L" || a === "-z" || a.startsWith("--search-zip") || a.startsWith("--hostname-bin")))) {
569
+ throw new Error(`${program} ${a} is not allowed`);
570
+ }
571
+ const sv = shortValue(program, a);
572
+ if (sv && (sv.letter === "e" || sv.letter === "f")) {
573
+ // -e<pat>, -ie<pat>, -e <pat>, -f<file>, -f <file>: explicit patterns, so no positional is the pattern.
574
+ explicit = true;
575
+ if (sv.attached !== "") {
576
+ if (sv.letter === "e")
577
+ checkPattern(folder, here, sv.attached);
578
+ else
579
+ checkPath(folder, here, sv.attached, "pattern file");
580
+ }
581
+ else if (sv.letter === "e")
582
+ patterns.add(k + 1);
583
+ if (sv.attached === "")
584
+ k++;
585
+ continue;
586
+ }
587
+ if (a === "--regexp") {
588
+ patterns.add(k + 1);
589
+ explicit = true;
590
+ k++;
591
+ }
592
+ else if (a.startsWith("--regexp=")) {
593
+ patterns.add(k);
594
+ explicit = true;
595
+ }
596
+ else if (a === "--file") {
597
+ explicit = true;
598
+ k++;
599
+ }
600
+ else if (a.startsWith("--file=")) {
601
+ explicit = true;
602
+ checkPath(folder, here, a.slice("--file=".length), "pattern file");
603
+ }
604
+ // A file an option reads, named in the option's own word: the whole path rule, never-open list included.
605
+ if (a.startsWith("--exclude-from=") || (program === "rg" && a.startsWith("--ignore-file=")))
606
+ checkPath(folder, here, a.slice(a.indexOf("=") + 1), "file");
607
+ else if (nextIsValue(k))
608
+ k++;
609
+ }
610
+ if (!explicit) {
611
+ // The pattern: the first positional that is not an option's value (after `--`, simply the first word).
612
+ for (let k = 0; k < rest.length; k++) {
613
+ if (k === dd)
614
+ continue;
615
+ if (isOption(k)) {
616
+ if (nextIsValue(k))
617
+ k++;
618
+ continue;
619
+ }
620
+ patterns.add(k);
621
+ break;
622
+ }
623
+ }
624
+ break;
625
+ }
626
+ case "find": {
627
+ for (const a of rest)
628
+ if (/^-(exec|execdir|ok|okdir|delete|fprint|fprint0|fprintf|fls|L|follow|H)$/.test(a))
629
+ throw new Error(`find ${a} is not allowed`);
630
+ break;
631
+ }
632
+ case "sort": {
633
+ rest.forEach((a, idx) => {
634
+ if (isOption(idx) && (a.startsWith("-o") || a.startsWith("--output") || a.startsWith("--compress-program") || a.startsWith("--temporary-directory") || a.startsWith("-T")))
635
+ throw new Error(`sort ${a} is not allowed`);
636
+ });
637
+ break;
638
+ }
639
+ case "uniq": {
640
+ if (rest.filter((_, idx) => idx !== dd && !isOption(idx)).length > 1)
641
+ throw new Error("uniq's output file is not allowed");
642
+ break;
643
+ }
644
+ case "tail": {
645
+ rest.forEach((a, idx) => {
646
+ if (isOption(idx) && (a === "-f" || a === "-F" || a.startsWith("--follow") || a.startsWith("--retry")))
647
+ throw new Error("tail -f is not allowed");
648
+ });
649
+ break;
650
+ }
651
+ case "diff": {
652
+ rest.forEach((a, idx) => {
653
+ if (isOption(idx) && (a.startsWith("--to-file") || a.startsWith("--from-file") || a === "-r" || (a.length >= 5 && "--recursive".startsWith(a.split("=")[0]))))
654
+ throw new Error(`diff ${a} is not allowed`);
655
+ });
656
+ break;
657
+ }
658
+ }
659
+ // Globs: quoted, and only in a grep/rg pattern, --include=/--exclude=/--exclude-dir= values (grep family, rg) and find
660
+ // -name/-iname, without '/'.
661
+ for (let idx = 0; idx < rest.length; idx++) {
662
+ const a = rest[idx];
663
+ if (!/[*?[\]]/.test(a))
664
+ continue;
665
+ const m = isOption(idx) ? /^--(include|exclude|exclude-dir)=(.*)$/.exec(a) : null;
666
+ // Every glob must be quoted or escaped: one the shell expands becomes the folder's file names, any of which may read
667
+ // as an option (a file named -delete after find -name *delete).
668
+ const quotedGlob = !restUnquotedGlob[idx];
669
+ const okGrep = GREP_LIKE.includes(program) && m !== null && !m[2].includes("/") && quotedGlob;
670
+ const okFind = program === "find" && idx > 0 && (rest[idx - 1] === "-name" || rest[idx - 1] === "-iname") && !a.includes("/") && quotedGlob;
671
+ const okPattern = patterns.has(idx) && quotedGlob;
672
+ if (!okGrep && !okFind && !okPattern)
673
+ throw new Error(`the glob ${a} is not allowed here (quote it: only in a quoted grep/rg pattern, an --include=, --exclude= or --exclude-dir= value, or find -name/-iname, without '/')`);
674
+ }
675
+ for (let idx = 0; idx < rest.length; idx++) {
676
+ const a = rest[idx];
677
+ if (patterns.has(idx)) {
678
+ checkPattern(folder, here, a);
679
+ continue;
680
+ }
681
+ if (exempt.has(idx))
682
+ continue;
683
+ if (isOption(idx)) {
684
+ checkOption(folder, here, a);
685
+ continue;
686
+ }
687
+ // Every positional is a path, whatever it looks like (a word that is no path names something in the folder).
688
+ checkPath(folder, here, a);
689
+ }
690
+ }
691
+ /** Throws, with the reason, unless `command` is a read-only command line run from `folder`'s first name (relative to the
692
+ * folder: `start`, "" for the folder itself). */
693
+ export function checkReadOnly(command, folder, start = "") {
694
+ const { commands, joins } = parse(command);
695
+ let here = start;
696
+ const hasCd = commands.some((pipeline) => pipeline.some((segment) => unmark(segment.find((w) => !w.startsWith("\u0000")) ?? "") === "cd"));
697
+ // A cd that fails leaves the shell where it was: joined by && only, nothing after it runs then.
698
+ if (hasCd && joins.some((join) => join !== "&&"))
699
+ throw new Error("a command line with cd joins its commands with && only, so nothing runs where cd did not go");
700
+ for (const pipeline of commands) {
701
+ const first = pipeline[0].filter((w) => !w.startsWith("\u0000")).map(unmark);
702
+ if (first[0] === "cd") {
703
+ if (pipeline.length !== 1 || pipeline[0].length !== first.length)
704
+ throw new Error("cd must be a command of its own");
705
+ if (first.length !== 2)
706
+ throw new Error("cd needs exactly one directory");
707
+ // An option-shaped word (`-`, `--`, `-P`) is cd's option, never a directory: with none left, cd goes to $HOME.
708
+ if (first[1].startsWith("-") || /[*?[\]]/.test(first[1]))
709
+ throw new Error(`cd ${first[1]} is not allowed: give cd one directory inside the run's folder`);
710
+ here = checkPath(folder, here, first[1], "cd");
711
+ continue;
712
+ }
713
+ pipeline.forEach((segment, k) => {
714
+ const words = segment.filter((w) => !w.startsWith("\u0000")).map(unmark);
715
+ if (words[0] === "cd")
716
+ throw new Error("cd must be a command of its own");
717
+ if (k > 0 && words[0] !== undefined && !PIPE_TARGETS.has(words[0]))
718
+ throw new Error(`${words[0]} cannot take piped input (pipe only into ${[...PIPE_TARGETS].join(", ")})`);
719
+ checkSegment(folder, here, segment);
720
+ });
721
+ }
722
+ }
723
+ /** A word of an argv, quoted for the shell: what the argv runs, as a command line (no word of it expanded). */
724
+ const quoted = (word) => `'${word.replace(/'/g, `'\\''`)}'`;
725
+ const SHELLS = new Set(["bash", "sh", "zsh", "dash", "/bin/bash", "/bin/sh", "/usr/bin/bash", "/usr/bin/zsh", "/bin/zsh", "/bin/dash"]);
726
+ /** The command line a shell call runs, and the folder-relative directory it starts in, or the reason it can't be read.
727
+ * `command` a string (bash, claude-agent's Bash), or an argv (codex's shell: `[bash, -lc, <line>]`, else the argv as
728
+ * is); `workdir` or `cwd`, where given, inside the folder (readOnlyReason checks the command from there and from the
729
+ * folder, as a tool that does not take one runs it in the folder). */
730
+ function commandOf(args, folder) {
731
+ const given = (typeof args === "object" && args !== null ? args : {});
732
+ if (given.run_in_background === true)
733
+ return { reason: "a command run in the background is not allowed: run it in the foreground" };
734
+ let start = "";
735
+ for (const key of ["workdir", "cwd"]) {
736
+ const dir = given[key];
737
+ if (dir === undefined)
738
+ continue;
739
+ if (typeof dir !== "string")
740
+ return { reason: `its ${key} is not a path` };
741
+ const rel = inFolder(folder, "", dir);
742
+ if (rel === undefined)
743
+ return { reason: `its ${key} ${dir} is outside the run's folder` };
744
+ start = rel;
745
+ }
746
+ const command = given.command;
747
+ if (typeof command === "string")
748
+ return { line: command, start };
749
+ if (Array.isArray(command) && command.length > 0 && command.every((word) => typeof word === "string")) {
750
+ const argv = command;
751
+ if (argv.length === 3 && SHELLS.has(argv[0]) && (argv[1] === "-c" || argv[1] === "-lc"))
752
+ return { line: argv[2], start };
753
+ return { line: argv.map(quoted).join(" "), start };
754
+ }
755
+ return { reason: "it carries no command this policy can read" };
756
+ }
757
+ /** Why the read-only policy refuses shell tool `tool`'s call with `args`, or undefined when it may go on to the gate's
758
+ * permission. `folder`: the run's folder by its names (the first is where a command starts). */
759
+ export function readOnlyReason(tool, args, folder) {
760
+ if (WATCHERS.has(tool))
761
+ return undefined;
762
+ if (tool !== "bash")
763
+ return `${tool} is not offered: a read-only shell runs one command at a time, in the foreground, with bash`;
764
+ const read = commandOf(args, folder);
765
+ if ("reason" in read)
766
+ return read.reason;
767
+ try {
768
+ // Checked from the folder and from the call's workdir: a tool that does not honor the workdir runs the command in the
769
+ // folder, so it must hold from both.
770
+ checkReadOnly(read.line, folder);
771
+ if (read.start !== "")
772
+ checkReadOnly(read.line, folder, read.start);
773
+ return undefined;
774
+ }
775
+ catch (error) {
776
+ return error.message;
777
+ }
778
+ }