@qvac/harness 1.0.0-rc.3 → 1.0.0-rc.4

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 (460) hide show
  1. package/.nvmrc +1 -0
  2. package/CHANGELOG.md +2280 -1485
  3. package/README.md +44 -31
  4. package/dist-lib/index.d.ts +50 -6
  5. package/dist-lib/index.js +130 -28
  6. package/dist-lib/lib/agent/delegate.d.ts +3 -2
  7. package/dist-lib/lib/agent/delegate.js +6 -4
  8. package/dist-lib/lib/agent/follow.d.ts +5 -0
  9. package/dist-lib/lib/agent/follow.js +2 -0
  10. package/dist-lib/lib/agent/resolve.js +22 -17
  11. package/dist-lib/lib/agent/tool-selection.d.ts +4 -2
  12. package/dist-lib/lib/agent/tool-selection.js +5 -6
  13. package/dist-lib/lib/agent/tools.d.ts +1 -0
  14. package/dist-lib/lib/agent/tools.js +2 -1
  15. package/dist-lib/lib/capabilities/agent-ports.js +3 -3
  16. package/dist-lib/lib/capabilities/completion-engine/actors/batching.js +1 -0
  17. package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +2 -0
  18. package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +60 -9
  19. package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +4 -4
  20. package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.js +3 -2
  21. package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +35 -6
  22. package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.d.ts +1 -1
  23. package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +2 -0
  24. package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +67 -27
  25. package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +6 -1
  26. package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +61 -16
  27. package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +2 -2
  28. package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +23 -13
  29. package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +8 -3
  30. package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +61 -3
  31. package/dist-lib/lib/capabilities/completion-engine/actors/streaming.d.ts +5 -1
  32. package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +47 -21
  33. package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +1 -0
  34. package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +30 -5
  35. package/dist-lib/lib/capabilities/completion-engine/driver.js +27 -11
  36. package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +1 -0
  37. package/dist-lib/lib/capabilities/completion-engine/durable.js +5 -1
  38. package/dist-lib/lib/capabilities/completion-engine/index.d.ts +2 -1
  39. package/dist-lib/lib/capabilities/completion-engine/index.js +2 -2
  40. package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +15 -2
  41. package/dist-lib/lib/capabilities/completion-engine/loop.js +7 -0
  42. package/dist-lib/lib/capabilities/completion-engine/metrics.d.ts +9 -2
  43. package/dist-lib/lib/capabilities/completion-engine/metrics.js +28 -7
  44. package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +46 -0
  45. package/dist-lib/lib/capabilities/completion-engine/model-round.js +45 -0
  46. package/dist-lib/lib/capabilities/completion-engine/operations.js +1 -1
  47. package/dist-lib/lib/capabilities/completion-engine/ports.js +3 -7
  48. package/dist-lib/lib/capabilities/completion-engine/round.d.ts +23 -3
  49. package/dist-lib/lib/capabilities/completion-engine/round.js +323 -97
  50. package/dist-lib/lib/capabilities/completion-engine/session.d.ts +10 -3
  51. package/dist-lib/lib/capabilities/completion-engine/session.js +30 -2
  52. package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +3 -2
  53. package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +4 -3
  54. package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +15 -10
  55. package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +11 -4
  56. package/dist-lib/lib/capabilities/completion-engine/turns.js +48 -65
  57. package/dist-lib/lib/capabilities/download.d.ts +9 -7
  58. package/dist-lib/lib/capabilities/download.js +1 -1
  59. package/dist-lib/lib/capabilities/enhance.d.ts +1 -1
  60. package/dist-lib/lib/capabilities/enhance.js +20 -8
  61. package/dist-lib/lib/capabilities/preview-model-source.d.ts +7 -0
  62. package/dist-lib/lib/capabilities/preview-model-source.js +83 -23
  63. package/dist-lib/lib/capabilities/sdk-tool.d.ts +1 -0
  64. package/dist-lib/lib/capabilities/sdk-tool.js +18 -1
  65. package/dist-lib/lib/capabilities/tool-plan.d.ts +1 -1
  66. package/dist-lib/lib/capabilities/tool-plan.js +5 -5
  67. package/dist-lib/lib/capabilities/tool-prompt-log.js +3 -3
  68. package/dist-lib/lib/capabilities/tool-turns.d.ts +7 -9
  69. package/dist-lib/lib/capabilities/tool-turns.js +25 -20
  70. package/dist-lib/lib/client/index.d.ts +19 -0
  71. package/dist-lib/lib/client/index.js +262 -0
  72. package/dist-lib/lib/connect.d.ts +13 -10
  73. package/dist-lib/lib/connect.js +62 -24
  74. package/dist-lib/lib/context-window.d.ts +1 -0
  75. package/dist-lib/lib/context-window.js +3 -3
  76. package/dist-lib/lib/contract/agent.d.ts +7 -3
  77. package/dist-lib/lib/contract/completion.d.ts +44 -29
  78. package/dist-lib/lib/contract/egress-proxy.d.ts +13 -0
  79. package/dist-lib/lib/contract/egress-proxy.js +1 -0
  80. package/dist-lib/lib/contract/exec.d.ts +3 -3
  81. package/dist-lib/lib/contract/hooks.d.ts +4 -1
  82. package/dist-lib/lib/contract/index.d.ts +1 -0
  83. package/dist-lib/lib/contract/models.d.ts +6 -4
  84. package/dist-lib/lib/contract/policy.d.ts +75 -0
  85. package/dist-lib/lib/contract/policy.js +1 -0
  86. package/dist-lib/lib/contract/run.d.ts +9 -3
  87. package/dist-lib/lib/contract/sandbox.d.ts +3 -1
  88. package/dist-lib/lib/contract/translation.d.ts +20 -0
  89. package/dist-lib/lib/contract/translation.js +1 -0
  90. package/dist-lib/lib/contract-types.d.ts +32 -14
  91. package/dist-lib/lib/embeddings/index.d.ts +7 -1
  92. package/dist-lib/lib/embeddings/index.js +26 -5
  93. package/dist-lib/lib/errors.d.ts +266 -0
  94. package/dist-lib/lib/errors.js +198 -0
  95. package/dist-lib/lib/fold/index.d.ts +25 -1
  96. package/dist-lib/lib/fold/index.js +75 -9
  97. package/dist-lib/lib/guarded-fetch.js +11 -7
  98. package/dist-lib/lib/hardware/gpu-probe.js +10 -1
  99. package/dist-lib/lib/helpers/completion-params.d.ts +6 -2
  100. package/dist-lib/lib/helpers/completion-params.js +10 -1
  101. package/dist-lib/lib/helpers/engine-error.d.ts +2 -1
  102. package/dist-lib/lib/helpers/engine-error.js +12 -12
  103. package/dist-lib/lib/helpers/goal-check.d.ts +4 -0
  104. package/dist-lib/lib/helpers/goal-check.js +81 -0
  105. package/dist-lib/lib/helpers/head-tail.js +1 -1
  106. package/dist-lib/lib/helpers/load-stall.d.ts +1 -1
  107. package/dist-lib/lib/helpers/load-stall.js +2 -2
  108. package/dist-lib/lib/helpers/markup-stream-filter.d.ts +4 -1
  109. package/dist-lib/lib/helpers/markup-stream-filter.js +20 -6
  110. package/dist-lib/lib/helpers/repeated-reply.js +24 -16
  111. package/dist-lib/lib/helpers/thinking.d.ts +3 -2
  112. package/dist-lib/lib/helpers/thinking.js +19 -0
  113. package/dist-lib/lib/hooks/built-in/arg-repair.js +6 -2
  114. package/dist-lib/lib/hooks/built-in/policy-rules.d.ts +8 -0
  115. package/dist-lib/lib/hooks/built-in/policy-rules.js +192 -0
  116. package/dist-lib/lib/hooks/built-in/sandbox.js +23 -5
  117. package/dist-lib/lib/hooks/index.d.ts +4 -1
  118. package/dist-lib/lib/hooks/index.js +9 -4
  119. package/dist-lib/lib/hooks/run.js +3 -3
  120. package/dist-lib/lib/lifecycle/index.js +15 -14
  121. package/dist-lib/lib/lifecycle/machine.js +2 -2
  122. package/dist-lib/lib/log.d.ts +26 -5
  123. package/dist-lib/lib/log.js +86 -23
  124. package/dist-lib/lib/machine/completion/actions/completion.d.ts +4 -2
  125. package/dist-lib/lib/machine/completion/actions/completion.js +75 -10
  126. package/dist-lib/lib/machine/completion/actions/prepare.js +1 -1
  127. package/dist-lib/lib/machine/completion/actions/tools.js +48 -5
  128. package/dist-lib/lib/machine/completion/context.js +4 -1
  129. package/dist-lib/lib/machine/completion/guards/retry.d.ts +1 -0
  130. package/dist-lib/lib/machine/completion/guards/retry.js +8 -2
  131. package/dist-lib/lib/machine/completion/implementations.d.ts +10 -4
  132. package/dist-lib/lib/machine/completion/implementations.js +27 -6
  133. package/dist-lib/lib/machine/completion/machine.d.ts +21 -3
  134. package/dist-lib/lib/machine/completion/machine.js +33 -4
  135. package/dist-lib/lib/machine/completion/rules.d.ts +17 -2
  136. package/dist-lib/lib/machine/completion/rules.js +49 -3
  137. package/dist-lib/lib/machine/completion/types.d.ts +36 -0
  138. package/dist-lib/lib/machine/index.d.ts +27 -4
  139. package/dist-lib/lib/machine/index.js +6 -1
  140. package/dist-lib/lib/models/context-choice.d.ts +15 -0
  141. package/dist-lib/lib/models/context-choice.js +55 -0
  142. package/dist-lib/lib/models/download-gate.d.ts +20 -0
  143. package/dist-lib/lib/models/download-gate.js +73 -0
  144. package/dist-lib/lib/models/gguf-header.d.ts +5 -0
  145. package/dist-lib/lib/models/gguf-header.js +165 -14
  146. package/dist-lib/lib/models/llm-presets.d.ts +5 -1
  147. package/dist-lib/lib/models/llm-presets.js +6 -5
  148. package/dist-lib/lib/models/memory-cap.d.ts +13 -0
  149. package/dist-lib/lib/models/memory-cap.js +21 -0
  150. package/dist-lib/lib/models/model-catalog.d.ts +2 -0
  151. package/dist-lib/lib/models/model-catalog.js +15 -0
  152. package/dist-lib/lib/models/model-fit.d.ts +1 -1
  153. package/dist-lib/lib/models/model-fit.js +5 -6
  154. package/dist-lib/lib/models/model-handle.d.ts +8 -2
  155. package/dist-lib/lib/models/model-handle.js +14 -3
  156. package/dist-lib/lib/models/model-list.d.ts +8 -1
  157. package/dist-lib/lib/models/model-list.js +23 -0
  158. package/dist-lib/lib/models/model-pool.d.ts +35 -5
  159. package/dist-lib/lib/models/model-pool.js +121 -43
  160. package/dist-lib/lib/models/model-source.d.ts +1 -0
  161. package/dist-lib/lib/models/model-source.js +23 -5
  162. package/dist-lib/lib/models/sdk-faults.d.ts +1 -0
  163. package/dist-lib/lib/models/sdk-faults.js +9 -0
  164. package/dist-lib/lib/no-redirect-fetch-bare.js +2 -1
  165. package/dist-lib/lib/no-redirect-fetch-impl.js +2 -1
  166. package/dist-lib/lib/office/engine/pptx/picture-area.d.ts +23 -0
  167. package/dist-lib/lib/office/engine/pptx/picture-area.js +84 -0
  168. package/dist-lib/lib/office/engine/pptx/presentation.d.ts +2 -0
  169. package/dist-lib/lib/office/engine/pptx/presentation.js +55 -17
  170. package/dist-lib/lib/office/engine/pptx/types.d.ts +1 -0
  171. package/dist-lib/lib/office/engine/xlsx/workbook.d.ts +1 -0
  172. package/dist-lib/lib/office/engine/xlsx/workbook.js +34 -3
  173. package/dist-lib/lib/office/extract.js +4 -3
  174. package/dist-lib/lib/office/index.js +2 -1
  175. package/dist-lib/lib/plugins/registry.d.ts +3 -0
  176. package/dist-lib/lib/plugins/registry.js +16 -7
  177. package/dist-lib/lib/policy/index.d.ts +10 -0
  178. package/dist-lib/lib/policy/index.js +229 -0
  179. package/dist-lib/lib/prompt.d.ts +1 -0
  180. package/dist-lib/lib/prompt.js +7 -1
  181. package/dist-lib/lib/residency/completion-runtime.d.ts +1 -0
  182. package/dist-lib/lib/residency/completion-runtime.js +11 -4
  183. package/dist-lib/lib/residency/index.d.ts +44 -4
  184. package/dist-lib/lib/residency/index.js +399 -35
  185. package/dist-lib/lib/resolution-detector.js +3 -3
  186. package/dist-lib/lib/rpc-session.js +2 -1
  187. package/dist-lib/lib/sdk-loader.js +17 -11
  188. package/dist-lib/lib/serve.js +76 -36
  189. package/dist-lib/lib/sidecar/index.d.ts +29 -0
  190. package/dist-lib/lib/sidecar/index.js +174 -0
  191. package/dist-lib/lib/sidecar/user-plugins.d.ts +8 -0
  192. package/dist-lib/lib/sidecar/user-plugins.js +117 -0
  193. package/dist-lib/lib/skills-host/index.d.ts +1 -0
  194. package/dist-lib/lib/skills-host/index.js +8 -4
  195. package/dist-lib/lib/spawn.d.ts +3 -4
  196. package/dist-lib/lib/spawn.js +17 -17
  197. package/dist-lib/lib/spill.d.ts +1 -0
  198. package/dist-lib/lib/spill.js +12 -8
  199. package/dist-lib/lib/tools/attachments/staging.js +8 -8
  200. package/dist-lib/lib/tools/exec/runner.js +2 -1
  201. package/dist-lib/lib/tools/exec/scope.d.ts +0 -1
  202. package/dist-lib/lib/tools/exec/scope.js +23 -114
  203. package/dist-lib/lib/tools/exec/shell-guidance.js +4 -4
  204. package/dist-lib/lib/tools/exec/shell-line.d.ts +26 -0
  205. package/dist-lib/lib/tools/exec/shell-line.js +334 -0
  206. package/dist-lib/lib/tools/exec.d.ts +4 -1
  207. package/dist-lib/lib/tools/exec.js +87 -26
  208. package/dist-lib/lib/tools/files/edit-file.d.ts +3 -0
  209. package/dist-lib/lib/tools/files/edit-file.js +74 -0
  210. package/dist-lib/lib/tools/files/glob.d.ts +3 -0
  211. package/dist-lib/lib/tools/files/glob.js +65 -0
  212. package/dist-lib/lib/tools/files/grep.d.ts +6 -0
  213. package/dist-lib/lib/tools/files/grep.js +114 -0
  214. package/dist-lib/lib/tools/files/index.d.ts +3 -0
  215. package/dist-lib/lib/tools/files/index.js +23 -0
  216. package/dist-lib/lib/tools/files/list-dir.d.ts +6 -0
  217. package/dist-lib/lib/tools/files/list-dir.js +136 -0
  218. package/dist-lib/lib/tools/files/make-dir.d.ts +3 -0
  219. package/dist-lib/lib/tools/files/make-dir.js +48 -0
  220. package/dist-lib/lib/tools/files/read-file.d.ts +3 -0
  221. package/dist-lib/lib/tools/files/read-file.js +105 -0
  222. package/dist-lib/lib/tools/files/transfer.d.ts +4 -0
  223. package/dist-lib/lib/tools/files/transfer.js +83 -0
  224. package/dist-lib/lib/tools/files/trash-file.d.ts +4 -0
  225. package/dist-lib/lib/tools/files/trash-file.js +62 -0
  226. package/dist-lib/lib/tools/files/write-file.d.ts +3 -0
  227. package/dist-lib/lib/tools/files/write-file.js +56 -0
  228. package/dist-lib/lib/tools/fs/document-text.d.ts +2 -0
  229. package/dist-lib/lib/tools/fs/document-text.js +38 -0
  230. package/dist-lib/lib/tools/fs/drive.d.ts +14 -3
  231. package/dist-lib/lib/tools/fs/drive.js +9 -1
  232. package/dist-lib/lib/tools/fs/edit-match.d.ts +11 -0
  233. package/dist-lib/lib/tools/fs/edit-match.js +85 -0
  234. package/dist-lib/lib/tools/fs/ignore.d.ts +13 -0
  235. package/dist-lib/lib/tools/fs/ignore.js +104 -0
  236. package/dist-lib/lib/tools/fs/local.js +28 -5
  237. package/dist-lib/lib/tools/fs/remote-protocol.d.ts +23 -3
  238. package/dist-lib/lib/tools/fs/remote.d.ts +3 -4
  239. package/dist-lib/lib/tools/fs/remote.js +23 -13
  240. package/dist-lib/lib/tools/fs/scope.d.ts +5 -1
  241. package/dist-lib/lib/tools/fs/scope.js +5 -2
  242. package/dist-lib/lib/tools/fs/search.d.ts +41 -0
  243. package/dist-lib/lib/tools/fs/search.js +382 -0
  244. package/dist-lib/lib/tools/{file-glob.d.ts → fs/targets.d.ts} +1 -5
  245. package/dist-lib/lib/tools/fs/targets.js +32 -0
  246. package/dist-lib/lib/tools/fs/tool-path.d.ts +27 -0
  247. package/dist-lib/lib/tools/fs/tool-path.js +70 -0
  248. package/dist-lib/lib/tools/fs/walk.d.ts +15 -3
  249. package/dist-lib/lib/tools/fs/walk.js +118 -24
  250. package/dist-lib/lib/tools/http-request.js +12 -2
  251. package/dist-lib/lib/tools/index.js +2 -10
  252. package/dist-lib/lib/tools/office/ops.js +1 -1
  253. package/dist-lib/lib/tools/office.js +77 -21
  254. package/dist-lib/lib/tools/pdf/build.d.ts +5 -1
  255. package/dist-lib/lib/tools/pdf/build.js +31 -6
  256. package/dist-lib/lib/tools/pdf.js +17 -2
  257. package/dist-lib/lib/tools/skill.js +10 -7
  258. package/dist-lib/lib/tools/skills/bundled-dir.js +4 -4
  259. package/dist-lib/lib/tools/skills/catalog.d.ts +2 -0
  260. package/dist-lib/lib/tools/skills/catalog.js +6 -2
  261. package/dist-lib/lib/tools/skills/cli-argv.js +25 -5
  262. package/dist-lib/lib/tools/skills/cli-schema-check.d.ts +1 -0
  263. package/dist-lib/lib/tools/skills/cli-schema-check.js +3 -0
  264. package/dist-lib/lib/tools/skills/cli-schema-load.js +10 -0
  265. package/dist-lib/lib/tools/skills/cli-schema-types.d.ts +2 -0
  266. package/dist-lib/lib/tools/skills/cli-schema.js +6 -3
  267. package/dist-lib/lib/tools/skills/credential-health.js +3 -3
  268. package/dist-lib/lib/tools/skills/frontmatter-parser.d.ts +2 -0
  269. package/dist-lib/lib/tools/skills/frontmatter-parser.js +4 -0
  270. package/dist-lib/lib/tools/skills/manifest-parse.d.ts +1 -0
  271. package/dist-lib/lib/tools/skills/manifest-parse.js +12 -0
  272. package/dist-lib/lib/tools/skills/mention-name.d.ts +6 -0
  273. package/dist-lib/lib/tools/skills/mention-name.js +6 -0
  274. package/dist-lib/lib/tools/skills/mention.d.ts +2 -2
  275. package/dist-lib/lib/tools/skills/mention.js +11 -4
  276. package/dist-lib/lib/tools/skills/overlay-crud.js +3 -2
  277. package/dist-lib/lib/tools/url-guard.d.ts +6 -1
  278. package/dist-lib/lib/tools/url-guard.js +8 -2
  279. package/dist-lib/lib/tools/web-fetch.js +10 -4
  280. package/dist-lib/lib/wire.js +3 -5
  281. package/dist-lib/plugins/coding/index.d.ts +1 -1
  282. package/dist-lib/plugins/coding/index.js +2 -4
  283. package/dist-lib/plugins/coding/session.d.ts +3 -3
  284. package/dist-lib/plugins/coding/session.js +26 -14
  285. package/dist-lib/plugins/command-hooks/index.js +5 -3
  286. package/dist-lib/plugins/egress-proxy/index.d.ts +53 -0
  287. package/dist-lib/plugins/egress-proxy/index.js +182 -0
  288. package/dist-lib/plugins/image/edit-image.js +4 -3
  289. package/dist-lib/plugins/image/generate-image.d.ts +4 -3
  290. package/dist-lib/plugins/image/generate-image.js +10 -9
  291. package/dist-lib/plugins/image/index.d.ts +1 -1
  292. package/dist-lib/plugins/image/index.js +13 -10
  293. package/dist-lib/plugins/language-hint/index.d.ts +15 -0
  294. package/dist-lib/plugins/language-hint/index.js +51 -0
  295. package/dist-lib/plugins/lsp/tool.js +2 -2
  296. package/dist-lib/plugins/mcp/index.js +6 -3
  297. package/dist-lib/plugins/music/generate-music.d.ts +4 -2
  298. package/dist-lib/plugins/music/generate-music.js +7 -4
  299. package/dist-lib/plugins/music/index.js +12 -9
  300. package/dist-lib/plugins/obsidian/command.js +2 -2
  301. package/dist-lib/plugins/obsidian/note-name.js +2 -1
  302. package/dist-lib/plugins/obsidian/safe-path.js +5 -4
  303. package/dist-lib/plugins/obsidian/vault-create.js +3 -2
  304. package/dist-lib/plugins/obsidian/vault-fs.js +2 -2
  305. package/dist-lib/plugins/obsidian/vault-paths.js +3 -2
  306. package/dist-lib/plugins/obsidian/vault-read.js +6 -5
  307. package/dist-lib/plugins/obsidian/vault-write.js +13 -12
  308. package/dist-lib/plugins/python/guarded-fetch.d.ts +2 -1
  309. package/dist-lib/plugins/python/guarded-fetch.js +5 -1
  310. package/dist-lib/plugins/python/interrupt-timer.js +2 -2
  311. package/dist-lib/plugins/python/loader.js +68 -3
  312. package/dist-lib/plugins/python/memfs.js +2 -2
  313. package/dist-lib/plugins/python/pyodide.d.ts +1 -0
  314. package/dist-lib/plugins/python/pyodide.js +9 -8
  315. package/dist-lib/plugins/python/python-adapter.js +3 -1
  316. package/dist-lib/plugins/python/run-session.d.ts +1 -0
  317. package/dist-lib/plugins/python/run-session.js +19 -8
  318. package/dist-lib/plugins/python/wheels.js +8 -6
  319. package/dist-lib/plugins/python/worker/active.js +2 -2
  320. package/dist-lib/plugins/python/worker/client.js +9 -8
  321. package/dist-lib/plugins/python/worker/protocol.d.ts +2 -0
  322. package/dist-lib/plugins/python/worker/serve.js +23 -4
  323. package/dist-lib/plugins/python/worker/spawn.d.ts +2 -1
  324. package/dist-lib/plugins/python/worker/spawn.js +2 -1
  325. package/dist-lib/plugins/run-report/chain.d.ts +2 -0
  326. package/dist-lib/plugins/run-report/chain.js +73 -0
  327. package/dist-lib/plugins/run-report/flow-view.js +2 -1
  328. package/dist-lib/plugins/run-report/flow.d.ts +1 -1
  329. package/dist-lib/plugins/run-report/flow.js +66 -14
  330. package/dist-lib/plugins/run-report/index.d.ts +23 -2
  331. package/dist-lib/plugins/run-report/index.js +27 -12
  332. package/dist-lib/plugins/run-report/model.d.ts +10 -1
  333. package/dist-lib/plugins/run-report/model.js +12 -6
  334. package/dist-lib/plugins/run-report/page.d.ts +9 -0
  335. package/dist-lib/plugins/run-report/page.js +55 -15
  336. package/dist-lib/plugins/run-report/script.js +317 -43
  337. package/dist-lib/plugins/run-report/story.d.ts +2 -1
  338. package/dist-lib/plugins/run-report/story.js +3 -3
  339. package/dist-lib/plugins/run-report/style.d.ts +1 -1
  340. package/dist-lib/plugins/run-report/style.js +126 -0
  341. package/dist-lib/plugins/run-report/why.js +1 -1
  342. package/dist-lib/plugins/sandbox-linux/index.d.ts +60 -0
  343. package/dist-lib/plugins/sandbox-linux/index.js +347 -0
  344. package/dist-lib/plugins/sandbox-linux/seccomp.d.ts +2 -0
  345. package/dist-lib/plugins/sandbox-linux/seccomp.js +74 -0
  346. package/dist-lib/plugins/sandbox-macos/index.d.ts +23 -11
  347. package/dist-lib/plugins/sandbox-macos/index.js +239 -49
  348. package/dist-lib/plugins/sandbox-vm/vm-shell.d.ts +4 -2
  349. package/dist-lib/plugins/sandbox-vm/vm-shell.js +9 -4
  350. package/dist-lib/plugins/sandbox-windows/helper/qvac-sandbox.c +554 -0
  351. package/dist-lib/plugins/sandbox-windows/index.d.ts +53 -0
  352. package/dist-lib/plugins/sandbox-windows/index.js +205 -0
  353. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  354. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  355. package/dist-lib/plugins/speech/audio-resample.d.ts +1 -1
  356. package/dist-lib/plugins/speech/audio-resample.js +7 -8
  357. package/dist-lib/plugins/speech/audio-transcode-bare.d.ts +1 -1
  358. package/dist-lib/plugins/speech/audio-transcode-bare.js +23 -26
  359. package/dist-lib/plugins/speech/audio-transcode-node.d.ts +1 -1
  360. package/dist-lib/plugins/speech/audio-transcode-node.js +1 -3
  361. package/dist-lib/plugins/speech/speech-runtime.js +37 -37
  362. package/dist-lib/plugins/speech/voice.d.ts +5 -1
  363. package/dist-lib/plugins/speech/voice.js +100 -31
  364. package/dist-lib/plugins/translation/index.d.ts +1 -0
  365. package/dist-lib/plugins/translation/index.js +16 -9
  366. package/dist-lib/plugins/translation/translate.d.ts +7 -3
  367. package/dist-lib/plugins/translation/translate.js +64 -58
  368. package/dist-lib/plugins/weather/geocode.js +2 -1
  369. package/dist-lib/plugins/weather/lookup.js +5 -4
  370. package/dist-lib/plugins/web-search/engines/bing.js +2 -1
  371. package/dist-lib/plugins/web-search/engines/google.js +2 -1
  372. package/dist-lib/plugins/web-search/fetch-html.d.ts +5 -5
  373. package/dist-lib/plugins/web-search/fetch-html.js +12 -15
  374. package/dist-lib/plugins/web-search/tool.js +1 -0
  375. package/dist-lib/schema/harness.js +48 -7
  376. package/dist-lib/spec/bind.js +9 -0
  377. package/dist-lib/spec/calls.js +3 -0
  378. package/dist-lib/spec/hrpc/hrpc.json +42 -3
  379. package/dist-lib/spec/hrpc/index.js +44 -8
  380. package/dist-lib/spec/hrpc/messages.js +297 -202
  381. package/dist-lib/spec/hyperschema/index.js +297 -202
  382. package/dist-lib/spec/hyperschema/schema.json +155 -84
  383. package/dist-lib/spec/hyperschema/types.d.ts +23 -3
  384. package/package.json +98 -26
  385. package/patches/@qvac%2Finference@0.22.0.patch +59 -0
  386. package/patches/pyodide@314.0.2.patch +37 -8
  387. package/scripts/addon-externals.cjs +10 -5
  388. package/worker/harness-sidecar.mjs +18 -154
  389. package/bench/README.md +0 -94
  390. package/bench/bfcl/checker.ts +0 -313
  391. package/bench/bfcl/data.ts +0 -93
  392. package/bench/bfcl/observe.ts +0 -93
  393. package/bench/bfcl/run.ts +0 -213
  394. package/bench/bfcl/tools.ts +0 -72
  395. package/bench/bridge/bridge.ts +0 -392
  396. package/bench/bridge/openai.ts +0 -150
  397. package/bench/bridge/python/qvac_bench/__init__.py +0 -3
  398. package/bench/bridge/python/qvac_bench/airline.py +0 -42
  399. package/bench/bridge/python/qvac_bench/approval.py +0 -26
  400. package/bench/bridge/python/qvac_bench/bfcl_multi_turn.py +0 -152
  401. package/bench/bridge/python/qvac_bench/client.py +0 -88
  402. package/bench/bridge/python/qvac_bench/harbor_agent.py +0 -85
  403. package/bench/bridge/python/qvac_bench/session.py +0 -107
  404. package/bench/bridge/python/qvac_bench/speed.py +0 -30
  405. package/bench/bridge/python/qvac_bench/tau2_agent.py +0 -106
  406. package/bench/bridge/python/qvac_bench/tools.py +0 -11
  407. package/bench/bridge/python/run_bfcl_multi_turn.py +0 -95
  408. package/bench/bridge/python/run_tau2.py +0 -150
  409. package/bench/bridge/python/smoke.py +0 -47
  410. package/bench/bridge/python/test_airline.py +0 -28
  411. package/bench/bridge/python/test_approval.py +0 -57
  412. package/bench/bridge/python/test_bfcl_multi_turn.py +0 -185
  413. package/bench/bridge/python/test_harbor_agent.py +0 -107
  414. package/bench/bridge/serve.ts +0 -52
  415. package/bench/bridge/transcript.ts +0 -52
  416. package/bench/bun-tsconfig.json +0 -15
  417. package/bench/cpu-main.mjs +0 -216
  418. package/bench/cpu.ts +0 -457
  419. package/bench/evidence/2026-09-28-review15.md +0 -225
  420. package/bench/evidence/redact-bun1.3.14.json +0 -92
  421. package/bench/evidence/redact-node24.11.json +0 -92
  422. package/bench/graph-metrics.ts +0 -43
  423. package/bench/harness.ts +0 -73
  424. package/bench/issue129-matrix.mjs +0 -722
  425. package/bench/redact-adversarial.ts +0 -256
  426. package/bench/repeat-cpu.mjs +0 -281
  427. package/bench/report.ts +0 -1075
  428. package/bench/skill-eval/harness.ts +0 -30
  429. package/bench/skill-eval/laws.ts +0 -37
  430. package/bench/skill-eval/mermaid/client.ts +0 -132
  431. package/bench/skill-eval/mermaid/validate.mjs +0 -115
  432. package/bench/skill-eval/pack.ts +0 -61
  433. package/bench/skill-eval/packs/diagrams/cases.ts +0 -281
  434. package/bench/skill-eval/packs/diagrams/index.ts +0 -50
  435. package/bench/skill-eval/packs/diagrams/score.ts +0 -74
  436. package/bench/skill-eval/packs/index.ts +0 -5
  437. package/bench/skill-eval/packs/weather/cases.ts +0 -279
  438. package/bench/skill-eval/packs/weather/fixtures/wttr.json +0 -566
  439. package/bench/skill-eval/packs/weather/fixtures.ts +0 -84
  440. package/bench/skill-eval/packs/weather/index.ts +0 -55
  441. package/bench/skill-eval/packs/weather/score.ts +0 -92
  442. package/bench/skill-eval/report.ts +0 -194
  443. package/bench/skill-eval/run.ts +0 -316
  444. package/bench/speed.ts +0 -80
  445. package/dist-lib/lib/tools/create-documents.d.ts +0 -3
  446. package/dist-lib/lib/tools/create-documents.js +0 -95
  447. package/dist-lib/lib/tools/edit-documents.d.ts +0 -3
  448. package/dist-lib/lib/tools/edit-documents.js +0 -132
  449. package/dist-lib/lib/tools/exec/shell-argv.d.ts +0 -2
  450. package/dist-lib/lib/tools/exec/shell-argv.js +0 -61
  451. package/dist-lib/lib/tools/file-glob.js +0 -118
  452. package/dist-lib/lib/tools/grep.d.ts +0 -5
  453. package/dist-lib/lib/tools/grep.js +0 -184
  454. package/dist-lib/lib/tools/read-files.d.ts +0 -5
  455. package/dist-lib/lib/tools/read-files.js +0 -160
  456. package/dist-lib/plugins/coding/write-file.d.ts +0 -3
  457. package/dist-lib/plugins/coding/write-file.js +0 -52
  458. package/patches/@qvac%2Finference@0.21.0.patch +0 -67
  459. package/patches/bare-stow@0.1.5.patch +0 -68
  460. package/patches/hypercore-blob-server@1.15.0.patch +0 -15
@@ -0,0 +1,334 @@
1
+ const UNJUDGEABLE = {
2
+ expansion: '$ expansion',
3
+ backtick: 'backtick substitution',
4
+ 'process-substitution': 'process substitution',
5
+ subshell: 'subshell',
6
+ group: '{ } group',
7
+ negation: '! negation',
8
+ keyword: 'shell keyword',
9
+ function: 'function definition',
10
+ eval: 'eval, ., source, trap or a builtin given $ or `',
11
+ comment: 'comment',
12
+ unterminated: 'unterminated quote'
13
+ };
14
+ const KEYWORDS = [
15
+ 'if',
16
+ 'then',
17
+ 'else',
18
+ 'elif',
19
+ 'fi',
20
+ 'for',
21
+ 'while',
22
+ 'until',
23
+ 'do',
24
+ 'done',
25
+ 'case',
26
+ 'esac',
27
+ 'in',
28
+ 'select',
29
+ 'function',
30
+ '[['
31
+ ];
32
+ const RESERVED = new Map([
33
+ ['{', 'group'],
34
+ ['}', 'group'],
35
+ ['!', 'negation'],
36
+ ...KEYWORDS.map((word) => [word, 'keyword'])
37
+ ]);
38
+ const REINTERPRETS = new Set(['eval', '.', 'source', 'trap']);
39
+ const SUBSCRIPTS = new Set([
40
+ 'let',
41
+ 'declare',
42
+ 'typeset',
43
+ 'local',
44
+ 'export',
45
+ 'readonly',
46
+ 'read',
47
+ 'unset'
48
+ ]);
49
+ const SEPARATORS = [
50
+ ['&&', 'ampersand'],
51
+ ['||', 'pipe'],
52
+ ['|&', 'pipe'],
53
+ [';', 'chain'],
54
+ ['&', 'ampersand'],
55
+ ['|', 'pipe']
56
+ ];
57
+ const REDIRECTS = [
58
+ ['&>>', 'ampersand'],
59
+ ['&>', 'ampersand'],
60
+ ['<<<', 'redirect-input'],
61
+ ['<<-', 'redirect-input'],
62
+ ['<<', 'redirect-input'],
63
+ ['<>', 'redirect-input'],
64
+ ['<&', 'redirect-input'],
65
+ ['>>', 'redirect-output'],
66
+ ['>|', 'redirect-output'],
67
+ ['>&', 'redirect-output'],
68
+ ['<', 'redirect-input'],
69
+ ['>', 'redirect-output']
70
+ ];
71
+ const ASSIGNMENT = /^[A-Za-z_]\w*(\[[^\]]*\])?\+?=/;
72
+ const BLANK = /^[ \t\n]*$/;
73
+ const FD = /^\d+$/;
74
+ const GLOB = /[*?]|\[[^\]]*\]/;
75
+ const BRACE_LIST = /\{[^{}]*(,|\.\.)[^{}]*\}/;
76
+ const QUOTED = '\0';
77
+ function emptyCommand() {
78
+ return { argv: [], expands: [], assignments: [], redirects: [] };
79
+ }
80
+ function expands(unquoted) {
81
+ return GLOB.test(unquoted) || unquoted.startsWith('~') || BRACE_LIST.test(unquoted);
82
+ }
83
+ function evaluates(argv) {
84
+ const [program = '', ...rest] = argv;
85
+ const named = SUBSCRIPTS.has(program) || (program === 'printf' && rest.includes('-v'));
86
+ return named && rest.some((word) => /[$`]/.test(word));
87
+ }
88
+ export class ShellLine {
89
+ commands = [];
90
+ ops = [];
91
+ constructs = [];
92
+ unjudgeable;
93
+ #line;
94
+ #i = 0;
95
+ #start = 0;
96
+ #word = null;
97
+ #command = emptyCommand();
98
+ #redirect = null;
99
+ #reason = null;
100
+ constructor(line) {
101
+ this.#line = line;
102
+ while (this.#i < line.length) {
103
+ this.#step();
104
+ }
105
+ this.#endWord();
106
+ this.#endCommand();
107
+ this.constructs.sort((a, b) => a.at - b.at);
108
+ this.unjudgeable = this.#reason;
109
+ }
110
+ static parse(line) {
111
+ return new ShellLine(line);
112
+ }
113
+ static escape(value) {
114
+ return value.replace(/[ \t\\'"`$;&|<>(){}#!*?[\]~]/g, '\\$&').replaceAll('\n', "'\n'");
115
+ }
116
+ #step() {
117
+ const c = this.#line.charAt(this.#i);
118
+ if (this.#word === null) {
119
+ this.#start = this.#i;
120
+ }
121
+ if (c === ' ' || c === '\t') {
122
+ this.#endWord();
123
+ this.#i++;
124
+ }
125
+ else if (c === '\n') {
126
+ this.#newline();
127
+ }
128
+ else if (c === '#' && this.#word === null) {
129
+ this.#comment();
130
+ }
131
+ else if (c === '\\') {
132
+ this.#escaped();
133
+ }
134
+ else if (c === "'") {
135
+ this.#singleQuoted();
136
+ }
137
+ else if (c === '"') {
138
+ this.#doubleQuoted();
139
+ }
140
+ else if (c === '$' || c === '`') {
141
+ this.#mark(c === '$' ? 'expansion' : 'backtick', this.#i);
142
+ this.#bare(c);
143
+ }
144
+ else if (!this.#operator(c)) {
145
+ this.#bare(c);
146
+ }
147
+ }
148
+ #operator(c) {
149
+ const rest = this.#line.slice(this.#i);
150
+ if (/^[<>]\(/.test(rest)) {
151
+ this.#endWord();
152
+ this.#mark('process-substitution', this.#i);
153
+ this.#i += 2;
154
+ return true;
155
+ }
156
+ const redirect = REDIRECTS.find(([op]) => rest.startsWith(op));
157
+ if (redirect) {
158
+ this.#redirectOp(redirect);
159
+ return true;
160
+ }
161
+ const separator = SEPARATORS.find(([op]) => rest.startsWith(op));
162
+ if (separator) {
163
+ this.#endWord();
164
+ this.#mark(separator[1], this.#i);
165
+ this.#separate(separator[0]);
166
+ this.#i += separator[0].length;
167
+ return true;
168
+ }
169
+ if (c === '(' || c === ')') {
170
+ this.#paren(c);
171
+ return true;
172
+ }
173
+ return false;
174
+ }
175
+ #redirectOp([op, kind]) {
176
+ const word = this.#word;
177
+ const fd = word !== null && FD.test(word.raw) ? word.text : '';
178
+ if (fd) {
179
+ this.#word = null;
180
+ }
181
+ else {
182
+ this.#endWord();
183
+ }
184
+ this.#mark(kind, this.#i);
185
+ if (op === '<<' || op === '<<-') {
186
+ this.#reason ??= 'heredoc';
187
+ }
188
+ this.#redirect = { fd, op };
189
+ this.#i += op.length;
190
+ }
191
+ #paren(c) {
192
+ const words = this.#command.argv.length + (this.#word === null ? 0 : 1);
193
+ this.#endWord();
194
+ const defines = c === '(' && words === 1 && /^\(\s*\)/.test(this.#line.slice(this.#i));
195
+ this.#mark(defines ? 'function' : 'subshell', this.#i);
196
+ this.#endCommand();
197
+ this.#i++;
198
+ }
199
+ #newline() {
200
+ this.#endWord();
201
+ if (BLANK.test(this.#line.slice(this.#i))) {
202
+ this.#i = this.#line.length;
203
+ return;
204
+ }
205
+ this.#mark('newline', this.#i);
206
+ this.#separate('\n');
207
+ this.#i++;
208
+ }
209
+ #comment() {
210
+ this.#mark('comment', this.#i);
211
+ const end = this.#line.indexOf('\n', this.#i);
212
+ this.#i = end === -1 ? this.#line.length : end;
213
+ }
214
+ #escaped() {
215
+ const next = this.#line[this.#i + 1];
216
+ if (next === '\n') {
217
+ this.#mark('continuation', this.#i);
218
+ }
219
+ else {
220
+ this.#literal(next ?? '\\', this.#line.slice(this.#i, this.#i + 2));
221
+ }
222
+ this.#i += 2;
223
+ }
224
+ #singleQuoted() {
225
+ const end = this.#line.indexOf("'", this.#i + 1);
226
+ if (end === -1) {
227
+ this.#mark('unterminated', this.#i);
228
+ }
229
+ const stop = end === -1 ? this.#line.length : end;
230
+ this.#literal(this.#line.slice(this.#i + 1, stop), this.#line.slice(this.#i, stop + 1));
231
+ this.#i = stop + 1;
232
+ }
233
+ #doubleQuoted() {
234
+ const open = this.#i;
235
+ let text = '';
236
+ this.#i++;
237
+ while (this.#i < this.#line.length && this.#line[this.#i] !== '"') {
238
+ text += this.#quotedChar();
239
+ }
240
+ if (this.#i >= this.#line.length) {
241
+ this.#mark('unterminated', open);
242
+ }
243
+ this.#i++;
244
+ this.#literal(text, this.#line.slice(open, this.#i));
245
+ }
246
+ #quotedChar() {
247
+ const c = this.#line.charAt(this.#i);
248
+ if (c === '\\') {
249
+ const next = this.#line[this.#i + 1];
250
+ if (next === '\n') {
251
+ this.#mark('continuation', this.#i);
252
+ }
253
+ this.#i += 2;
254
+ if (next === undefined || next === '\n') {
255
+ return next === undefined ? c : '';
256
+ }
257
+ return '$`"\\'.includes(next) ? next : c + next;
258
+ }
259
+ if (c === '$' || c === '`') {
260
+ this.#mark(c === '$' ? 'expansion' : 'backtick', this.#i);
261
+ }
262
+ this.#i++;
263
+ return c;
264
+ }
265
+ #literal(text, raw) {
266
+ const word = this.#open();
267
+ word.text += text;
268
+ word.raw += raw;
269
+ word.unquoted += QUOTED.repeat(text.length);
270
+ word.plain = false;
271
+ }
272
+ #bare(c) {
273
+ const word = this.#open();
274
+ word.text += c;
275
+ word.raw += c;
276
+ word.unquoted += c;
277
+ this.#i++;
278
+ }
279
+ #open() {
280
+ this.#word ??= { text: '', raw: '', unquoted: '', plain: true };
281
+ return this.#word;
282
+ }
283
+ #endWord() {
284
+ const word = this.#word;
285
+ this.#word = null;
286
+ if (word === null) {
287
+ return;
288
+ }
289
+ if (this.#redirect) {
290
+ this.#command.redirects.push({ ...this.#redirect, target: word.text });
291
+ this.#redirect = null;
292
+ return;
293
+ }
294
+ if (this.#command.argv.length === 0 && this.#prefix(word)) {
295
+ return;
296
+ }
297
+ if (this.#command.argv.length === 0 && REINTERPRETS.has(word.text)) {
298
+ this.#mark('eval', this.#start);
299
+ }
300
+ this.#command.argv.push(word.text);
301
+ this.#command.expands.push(expands(word.unquoted));
302
+ }
303
+ #prefix(word) {
304
+ if (ASSIGNMENT.test(word.raw)) {
305
+ this.#command.assignments.push(word.text);
306
+ return true;
307
+ }
308
+ const kind = word.plain ? RESERVED.get(word.text) : undefined;
309
+ if (kind) {
310
+ this.#mark(kind, this.#start);
311
+ return true;
312
+ }
313
+ return false;
314
+ }
315
+ #separate(op) {
316
+ this.#endCommand();
317
+ this.ops.push(op);
318
+ }
319
+ #endCommand() {
320
+ const { argv, assignments, redirects } = this.#command;
321
+ if (evaluates(argv)) {
322
+ this.#mark('eval', this.#start);
323
+ }
324
+ if (argv.length > 0 || assignments.length > 0 || redirects.length > 0) {
325
+ this.commands.push(this.#command);
326
+ }
327
+ this.#command = emptyCommand();
328
+ this.#redirect = null;
329
+ }
330
+ #mark(kind, at) {
331
+ this.constructs.push({ kind, at });
332
+ this.#reason ??= UNJUDGEABLE[kind] ?? null;
333
+ }
334
+ }
@@ -13,8 +13,11 @@ export interface ExecToolOptions {
13
13
  readonly languages?: readonly ExecLanguage[];
14
14
  readonly routes?: readonly ExecRoute[];
15
15
  readonly skillSettings?: SkillSettingsFn;
16
+ readonly skillEnv?: SkillEnvFn;
16
17
  readonly realpath?: Realpath;
17
18
  readonly deniedRoots?: readonly string[];
18
19
  readonly skillsDir?: string;
19
20
  }
20
- export declare function createExecTool({ policyVersion, spawn, killProcess, shell: composedShell, languages, routes, skillSettings, realpath, deniedRoots, skillsDir }?: ExecToolOptions): ToolDefinition;
21
+ export type SkillEnvFn = (skill: string) => Readonly<Record<string, string>> | undefined;
22
+ export declare function declaredEnv(declared: Readonly<Record<string, string>> | undefined, session: string | undefined): Record<string, string>;
23
+ export declare function createExecTool({ policyVersion, spawn, killProcess, shell: composedShell, languages, routes, skillSettings, skillEnv, realpath, deniedRoots, skillsDir }?: ExecToolOptions): ToolDefinition;
@@ -1,11 +1,12 @@
1
1
  import { createHash } from 'crypto';
2
+ import { Policy } from '../policy/index.js';
2
3
  import { AbortedError } from '../helpers/race-abort.js';
3
4
  import { createShellAdapter } from './exec/adapters/shell/shell-adapter.js';
4
5
  import { isPythonLanguage } from './exec/python-source.js';
5
- import { MAX_OUTPUT_CHARS_LIMIT } from './exec/runner.js';
6
- import { bareBin, firstCommandToken, sanitizeCommand } from './exec/scope.js';
6
+ import { MAX_OUTPUT_CHARS, MAX_OUTPUT_CHARS_LIMIT } from './exec/runner.js';
7
+ import { bareBin, sanitizeCommand } from './exec/scope.js';
7
8
  import { LANGUAGE_UNAVAILABLE_ERROR, PYTHON_UNAVAILABLE_ERROR, SHELL_DOWNLOAD_NOTE, shellOnlyError, videoToolError } from './exec/shell-guidance.js';
8
- import { shellArgv } from './exec/shell-argv.js';
9
+ import { ShellLine } from './exec/shell-line.js';
9
10
  import { bareRuntime } from './exec/bare-runtime.js';
10
11
  import { canonicalDenyRoots, defaultRealpath, hostPath, resolveKey } from './fs/scope.js';
11
12
  import { settingsEnv } from './skills/skill-settings.js';
@@ -19,29 +20,61 @@ function parsePositiveInt(value, name, max) {
19
20
  }
20
21
  return n;
21
22
  }
22
- function resolveShellOps(command, toolOps) {
23
- const bin = bareBin(firstCommandToken(command));
24
- return { ops: (bin ? toolOps?.get(bin) : undefined) ?? [], argv: shellArgv(command).slice(1) };
23
+ function resolveShellOps(line, toolOps) {
24
+ const [program = '', ...argv] = line.commands[0]?.argv ?? [];
25
+ const bin = bareBin(program);
26
+ return { ops: (bin ? toolOps?.get(bin) : undefined) ?? [], argv };
25
27
  }
26
28
  function checkShellScope(command, toolOps) {
27
29
  const unsafe = sanitizeCommand(command);
28
30
  if (unsafe) {
29
31
  return unsafe;
30
32
  }
31
- const { ops, argv } = resolveShellOps(command, toolOps);
33
+ const { ops, argv } = resolveShellOps(ShellLine.parse(command), toolOps);
32
34
  if (ops.length === 0) {
33
35
  return null;
34
36
  }
35
37
  return checkCliOps(argv, ops);
36
38
  }
37
39
  function shellEffect(command, toolOps) {
38
- const { ops, argv } = resolveShellOps(command, toolOps);
40
+ const line = ShellLine.parse(command);
41
+ const [first] = line.commands;
42
+ if (line.unjudgeable ||
43
+ line.ops.length > 0 ||
44
+ first?.redirects.length ||
45
+ first?.assignments.length) {
46
+ return 'write';
47
+ }
48
+ const { ops, argv } = resolveShellOps(line, toolOps);
39
49
  const matched = ops.filter((op) => op.check(argv) === null);
40
50
  if (matched.length === 0) {
41
51
  return 'write';
42
52
  }
43
53
  return matched.every((op) => op.annotation(argv) === 'read') ? 'read' : 'write';
44
54
  }
55
+ function shellOutputCap(command, toolOps) {
56
+ const { ops, argv } = resolveShellOps(ShellLine.parse(command), toolOps);
57
+ const caps = ops.map((op) => op.outputCap(argv)).filter((cap) => cap !== undefined);
58
+ return caps.length > 0 ? Math.min(...caps) : undefined;
59
+ }
60
+ const CUT_MARKER = /(…\[\d+ chars omitted[^\]]*)\]…/;
61
+ function noteCeiling(result, ceiling) {
62
+ if (!result || typeof result !== 'object')
63
+ return result;
64
+ const out = { ...result };
65
+ for (const stream of ['stdout', 'stderr']) {
66
+ const text = out[stream];
67
+ if (typeof text === 'string') {
68
+ out[stream] = text.replace(CUT_MARKER, `$1; this skill limits this command to ${ceiling} characters, a larger maxOutputChars does not apply]…`);
69
+ }
70
+ }
71
+ return out;
72
+ }
73
+ function cappedOutput(requested, ceiling) {
74
+ if (ceiling === undefined)
75
+ return requested;
76
+ return Math.min(requested ?? MAX_OUTPUT_CHARS, ceiling);
77
+ }
45
78
  function stringList(value) {
46
79
  if (!Array.isArray(value))
47
80
  return undefined;
@@ -104,17 +137,32 @@ function checkExecutionScope(args, language, { toolOps, sandbox, languages }) {
104
137
  shellOnlyError(command) ??
105
138
  checkShellScope(command, toolOps));
106
139
  }
107
- async function skillsEnv(skillSettings, ctx) {
140
+ async function skillsEnv(skillSettings, skillEnv, ctx) {
108
141
  const skills = ctx?.skills ?? [];
109
142
  if (skills.length === 0) {
110
143
  return undefined;
111
144
  }
112
145
  const env = {};
113
146
  for (const skill of skills) {
114
- Object.assign(env, settingsEnv(skill, await skillSettings(skill, ctx?.agentId)));
147
+ if (skillSettings) {
148
+ Object.assign(env, settingsEnv(skill, await skillSettings(skill, ctx?.agentId)));
149
+ }
150
+ Object.assign(env, declaredEnv(skillEnv?.(skill), ctx?.session));
115
151
  }
116
152
  return Object.keys(env).length > 0 ? env : undefined;
117
153
  }
154
+ export function declaredEnv(declared, session) {
155
+ const env = {};
156
+ for (const [name, value] of Object.entries(declared ?? {})) {
157
+ if (!value.includes('${session}')) {
158
+ env[name] = value;
159
+ }
160
+ else if (session) {
161
+ env[name] = value.replaceAll('${session}', session);
162
+ }
163
+ }
164
+ return env;
165
+ }
118
166
  function execSchema(languages) {
119
167
  const text = languages.map((language) => language.text);
120
168
  const runs = (each) => text.map((t) => `, or ${each(t)}`).join('');
@@ -160,7 +208,7 @@ function execSchema(languages) {
160
208
  },
161
209
  maxOutputChars: {
162
210
  type: 'number',
163
- description: 'Optional stdout/stderr cap in characters (default 8192, max 65536); longer output keeps its start and end. Raise when reading long content, e.g. a full note.'
211
+ description: 'Optional stdout/stderr cap in characters (default 8192, max 65536); longer output keeps its start and end. Raise when reading long content, e.g. a full note. A skill may cap one of its commands lower; the truncation note says so, and raising this does not lift that cap.'
164
212
  }
165
213
  },
166
214
  required: []
@@ -190,7 +238,7 @@ function execSchema(languages) {
190
238
  }
191
239
  };
192
240
  }
193
- export function createExecTool({ policyVersion, spawn, killProcess, shell: composedShell, languages = [], routes = [], skillSettings, realpath = defaultRealpath, deniedRoots, skillsDir } = {}) {
241
+ export function createExecTool({ policyVersion, spawn, killProcess, shell: composedShell, languages = [], routes = [], skillSettings, skillEnv, realpath = defaultRealpath, deniedRoots, skillsDir } = {}) {
194
242
  const shell = composedShell ??
195
243
  createShellAdapter({
196
244
  spawn,
@@ -233,6 +281,12 @@ export function createExecTool({ policyVersion, spawn, killProcess, shell: compo
233
281
  }
234
282
  return shellEffect(String(call.args.command ?? '').trim(), ctx?.toolOps);
235
283
  },
284
+ command(rawArgs) {
285
+ const call = resolveCall(rawArgs, languages);
286
+ return 'error' in call || call.language || call.bundled
287
+ ? null
288
+ : String(call.args.command ?? '');
289
+ },
236
290
  validate(args, ctx) {
237
291
  const call = resolveCall(args, languages);
238
292
  if ('error' in call) {
@@ -244,7 +298,7 @@ export function createExecTool({ policyVersion, spawn, killProcess, shell: compo
244
298
  }
245
299
  const { language } = call;
246
300
  const rawArgs = run.args;
247
- const sandbox = ctx?.sandboxMode === true;
301
+ const sandbox = ctx?.policy?.network.mode === 'off';
248
302
  const command = String(rawArgs.command ?? '').trim();
249
303
  if (!command) {
250
304
  return commandRequired(rawArgs, { sandbox }, language);
@@ -285,7 +339,7 @@ export function createExecTool({ policyVersion, spawn, killProcess, shell: compo
285
339
  }
286
340
  const workdir = typeof args.workdir === 'string' && args.workdir.trim() ? args.workdir.trim() : null;
287
341
  const body = call.language
288
- ? call.language.label(args, { sandbox: ctx?.sandboxMode === true })
342
+ ? call.language.label(args, { sandbox: ctx?.policy?.network.mode === 'off' })
289
343
  : command;
290
344
  return {
291
345
  kind: 'command',
@@ -303,7 +357,7 @@ export function createExecTool({ policyVersion, spawn, killProcess, shell: compo
303
357
  }
304
358
  const { language } = call;
305
359
  const rawArgs = run.args;
306
- const sandbox = ctx?.sandboxMode === true;
360
+ const sandbox = ctx?.policy?.network.mode === 'off';
307
361
  const command = String(rawArgs.command ?? '').trim();
308
362
  if (!command) {
309
363
  return { error: commandRequired(rawArgs, { sandbox }, language) };
@@ -319,7 +373,8 @@ export function createExecTool({ policyVersion, spawn, killProcess, shell: compo
319
373
  const workdir = rawArgs.workdir === undefined || rawArgs.workdir === null
320
374
  ? undefined
321
375
  : String(rawArgs.workdir);
322
- const deny = await canonicalDenyRoots(deniedRoots, realpath);
376
+ const policy = ctx?.policy ?? Policy.compile(undefined, { write: localRoots(ctx?.fsWriteRoots) });
377
+ const deny = await canonicalDenyRoots([...(deniedRoots ?? []), ...policy.files.deny], realpath);
323
378
  let cwd = workdir;
324
379
  if (workdir !== undefined && !language) {
325
380
  const roots = ctx?.fsRoots ?? [];
@@ -354,10 +409,12 @@ export function createExecTool({ policyVersion, spawn, killProcess, shell: compo
354
409
  timeout = Math.min(timeout, remaining);
355
410
  }
356
411
  }
357
- const maxOutputChars = parsePositiveInt(rawArgs.maxOutputChars, 'maxOutputChars', MAX_OUTPUT_CHARS_LIMIT);
358
- if (maxOutputChars && typeof maxOutputChars === 'object') {
359
- return maxOutputChars;
412
+ const requestedCap = parsePositiveInt(rawArgs.maxOutputChars, 'maxOutputChars', MAX_OUTPUT_CHARS_LIMIT);
413
+ if (requestedCap && typeof requestedCap === 'object') {
414
+ return requestedCap;
360
415
  }
416
+ const ceiling = language ? undefined : shellOutputCap(command, ctx?.toolOps);
417
+ const maxOutputChars = cappedOutput(requestedCap, ceiling);
361
418
  const route = language ? undefined : routes.find((each) => each.claims(command));
362
419
  if (route) {
363
420
  return route.run(command, ctx, {
@@ -367,29 +424,30 @@ export function createExecTool({ policyVersion, spawn, killProcess, shell: compo
367
424
  runtime: spawn ? async () => ({ spawn, killProcess }) : bareRuntime
368
425
  });
369
426
  }
370
- const skillEnv = skillSettings ? await skillsEnv(skillSettings, ctx) : undefined;
427
+ const childEnv = await skillsEnv(skillSettings, skillEnv, ctx);
371
428
  try {
372
429
  const context = {
373
430
  attach: ctx?.attach,
374
431
  fetchAttachment: ctx?.fetchAttachment,
375
432
  turnImages: ctx?.turnImages,
376
433
  runBudget: ctx?.runBudget,
377
- sandboxMode: ctx?.sandboxMode,
434
+ policy: { ...policy, files: { ...policy.files, deny: [...new Set(deny)] } },
378
435
  toolNames: ctx?.toolNames,
379
436
  approval: ctx?.approval,
380
- askUser: ctx?.askUser,
381
- writeRoots: (ctx?.fsWriteRoots ?? []).flatMap((each) => each.kind === 'local' ? [each.root] : []),
382
- deniedRoots: deny
437
+ askUser: ctx?.askUser
383
438
  };
384
439
  const execution = language?.resolve(rawArgs, context) ?? shell.resolve(rawArgs, context);
385
- return await execution.run({
440
+ const result = await execution.run({
386
441
  cwd,
387
442
  timeoutMs: timeout,
388
443
  maxOutputChars,
389
444
  signal: ctx?.signal,
390
- env: skillEnv,
445
+ env: childEnv,
391
446
  spill: ctx?.spill
392
447
  });
448
+ return ceiling !== undefined && maxOutputChars === ceiling
449
+ ? noteCeiling(result, ceiling)
450
+ : result;
393
451
  }
394
452
  catch (err) {
395
453
  const error = err instanceof Error ? err : new Error(String(err));
@@ -402,3 +460,6 @@ export function createExecTool({ policyVersion, spawn, killProcess, shell: compo
402
460
  }
403
461
  };
404
462
  }
463
+ function localRoots(roots) {
464
+ return (roots ?? []).flatMap((each) => (each.kind === 'local' ? [each.root] : []));
465
+ }
@@ -0,0 +1,3 @@
1
+ import type { ToolDefinition } from '../../contract/index.ts';
2
+ import { type FsToolOptions } from '../fs/scope.ts';
3
+ export declare function createEditFileTool({ realpath, deniedRoots }?: FsToolOptions): ToolDefinition;
@@ -0,0 +1,74 @@
1
+ import b4a from 'b4a';
2
+ import { errorMessage } from '../../guards.js';
3
+ import { editMatch } from '../fs/edit-match.js';
4
+ import { defaultRealpath } from '../fs/scope.js';
5
+ import { resolveRooted, rootedArgs, rootedLabel, stringArg } from '../fs/tool-path.js';
6
+ import { writeText } from '../fs/write.js';
7
+ export function createEditFileTool({ realpath = defaultRealpath, deniedRoots } = {}) {
8
+ return {
9
+ name: 'edit_file',
10
+ toolset: 'files',
11
+ description: 'Change part of a file in the shared folder: replaces the text in old with new. old must match ' +
12
+ 'one place in the file (copy it from read_file, without the line numbers); set replaceAll to ' +
13
+ 'change every match. Asks the user first.',
14
+ parameters: {
15
+ type: 'object',
16
+ properties: {
17
+ path: { type: 'string', description: 'File path, relative to the shared folder' },
18
+ old: { type: 'string', description: 'The exact text to replace' },
19
+ new: { type: 'string', description: 'The text to put in its place' },
20
+ replaceAll: { type: 'boolean', description: 'Replace every match instead of exactly one' }
21
+ },
22
+ required: ['path', 'old', 'new']
23
+ },
24
+ effect: () => 'write',
25
+ autoApprove: false,
26
+ writeRootsRequired: true,
27
+ validate(args) {
28
+ if (!stringArg(args, 'path'))
29
+ return 'path is required';
30
+ if (typeof args.old !== 'string' || !args.old) {
31
+ return 'old must be the text to replace';
32
+ }
33
+ return typeof args.new === 'string' ? null : 'new must be a string';
34
+ },
35
+ paths: (args, ctx) => rootedArgs(args, ctx, ['path']),
36
+ resource: (args, ctx) => ({
37
+ kind: 'file',
38
+ label: rootedLabel('edit', { grants: ctx, paths: [String(args.path)] })
39
+ }),
40
+ async execute(args, ctx) {
41
+ const requested = String(args.path);
42
+ const resolved = await resolveRooted(requested, {
43
+ grants: ctx,
44
+ write: true,
45
+ realpath,
46
+ deniedRoots
47
+ });
48
+ if ('error' in resolved) {
49
+ return resolved;
50
+ }
51
+ try {
52
+ const { drive } = resolved.root;
53
+ const entry = await drive.entry(resolved.key);
54
+ const blob = entry === null ? null : await drive.get(resolved.key);
55
+ if (entry === null || blob === null) {
56
+ return { error: `no such file: ${requested}` };
57
+ }
58
+ const result = editMatch(b4a.toString(blob, 'utf8'), {
59
+ old: String(args.old),
60
+ replacement: String(args.new),
61
+ replaceAll: args.replaceAll === true
62
+ });
63
+ if (result.error) {
64
+ return { error: result.error };
65
+ }
66
+ await writeText(drive, resolved.key, result.content, { executable: entry.value.executable });
67
+ return { edited: requested, replacements: result.count };
68
+ }
69
+ catch (err) {
70
+ return { error: errorMessage(err) };
71
+ }
72
+ }
73
+ };
74
+ }
@@ -0,0 +1,3 @@
1
+ import type { ToolDefinition } from '../../contract/index.ts';
2
+ import { type FsToolOptions } from '../fs/scope.ts';
3
+ export declare function createGlobTool({ realpath, deniedRoots }?: FsToolOptions): ToolDefinition;