@qvac/harness 1.0.0-rc.2 → 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 (404) hide show
  1. package/.nvmrc +1 -0
  2. package/CHANGELOG.md +2280 -1485
  3. package/README.md +56 -43
  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 +101 -38
  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/dist-lib/lib/tools/create-documents.d.ts +0 -3
  390. package/dist-lib/lib/tools/create-documents.js +0 -95
  391. package/dist-lib/lib/tools/edit-documents.d.ts +0 -3
  392. package/dist-lib/lib/tools/edit-documents.js +0 -132
  393. package/dist-lib/lib/tools/exec/shell-argv.d.ts +0 -2
  394. package/dist-lib/lib/tools/exec/shell-argv.js +0 -61
  395. package/dist-lib/lib/tools/file-glob.js +0 -118
  396. package/dist-lib/lib/tools/grep.d.ts +0 -5
  397. package/dist-lib/lib/tools/grep.js +0 -184
  398. package/dist-lib/lib/tools/read-files.d.ts +0 -5
  399. package/dist-lib/lib/tools/read-files.js +0 -160
  400. package/dist-lib/plugins/coding/write-file.d.ts +0 -3
  401. package/dist-lib/plugins/coding/write-file.js +0 -52
  402. package/patches/@qvac%2Finference@0.21.0.patch +0 -67
  403. package/patches/bare-stow@0.1.5.patch +0 -68
  404. package/patches/hypercore-blob-server@1.15.0.patch +0 -15
@@ -10,6 +10,7 @@ export class Fold {
10
10
  static TIERS = TIERS;
11
11
  static RATIO = 0.95;
12
12
  static KEEP_TURNS = 1;
13
+ static KEEP_ROUNDS = 2;
13
14
  static PREFIX = '[Summary of the earlier conversation in this chat, written by another model. Treat it as established context, not as a new request.]';
14
15
  summarize;
15
16
  constructor(summarize) {
@@ -21,13 +22,25 @@ export class Fold {
21
22
  static isSummary(message) {
22
23
  return message.role === 'user' && message.content.startsWith(Fold.PREFIX);
23
24
  }
25
+ static isTurn(message, nudges) {
26
+ return (message.role === 'user' &&
27
+ !Fold.isSummary(message) &&
28
+ !nudges.includes(message.content) &&
29
+ !Fold.carriesPlan(message, nudges));
30
+ }
31
+ static carriesPlan(message, nudges) {
32
+ return (message.role === 'user' &&
33
+ nudges.some((nudge) => message.content.startsWith(`${nudge}\nPlan:\n`)));
34
+ }
24
35
  static ratio(ctxSize) {
25
36
  return TIERS.find(([below]) => ctxSize < below)?.[1] ?? Fold.RATIO;
26
37
  }
27
38
  static fits(ctxSize) {
28
39
  return ctxSize === undefined || ctxSize >= Fold.FLOOR;
29
40
  }
30
- static due({ cacheTokens, ctxSize }) {
41
+ static due({ cacheTokens, ctxSize, cutOff }) {
42
+ if (cutOff)
43
+ return true;
31
44
  if (!cacheTokens || !ctxSize)
32
45
  return false;
33
46
  return cacheTokens >= ctxSize * Fold.ratio(ctxSize);
@@ -49,18 +62,30 @@ export class Fold {
49
62
  const end = users[users.length - keepTurns];
50
63
  return end > 0 ? { end, foldedTurns: users.length - keepTurns } : null;
51
64
  }
65
+ static roundBoundary(messages, { nudges, keeps }, most = Infinity) {
66
+ const task = messages.findLastIndex((message) => Fold.isTurn(message, nudges));
67
+ if (task === -1) {
68
+ return null;
69
+ }
70
+ const starts = messages.flatMap((message, at) => at > task && message.role === 'assistant' ? [at] : []);
71
+ const plan = messages.findLastIndex((message, at) => at > task && Fold.carriesPlan(message, nudges));
72
+ const kept = (from, to) => (plan >= from && plan < to) || messages.slice(from, to).some(keeps);
73
+ const rounds = starts
74
+ .map((from, index) => [from, starts[index + 1] ?? messages.length])
75
+ .slice(0, Math.max(0, starts.length - Fold.KEEP_ROUNDS))
76
+ .filter(([from, to]) => !kept(from, to))
77
+ .slice(0, most);
78
+ const summaries = messages.flatMap((message, at) => at > task && Fold.isSummary(message) ? [at] : []);
79
+ const folded = rounds.flatMap(([from, to]) => Array.from({ length: to - from }, (_, offset) => from + offset));
80
+ return { task, folded: [...summaries, ...folded], foldedRounds: rounds.length };
81
+ }
52
82
  static prompt(messages, instructions) {
53
- const prior = messages[0] !== undefined && Fold.isSummary(messages[0]);
54
- const transcript = messages
55
- .map((message) => {
56
- const sender = message.role === 'user' && message.name ? `${message.name}: ` : '';
57
- return `${message.role === 'user' ? 'User' : 'Assistant'}: ${sender}${message.content}`;
58
- })
59
- .join('\n\n');
83
+ const prior = messages.some(Fold.isSummary);
84
+ const transcript = messages.map(transcribed).join('\n\n');
60
85
  return [
61
86
  'Summarize the conversation below so another model can continue it without seeing it.',
62
87
  prior
63
- ? 'The conversation opens with an earlier summary. Carry everything from it that is still true into your new summary — it is discarded after this, so whatever you leave out is lost — and correct it where the later turns disagree.'
88
+ ? 'The conversation carries an earlier summary. Carry everything from it that is still true into your new summary — it is discarded after this, so whatever you leave out is lost — and correct it where the later turns disagree.'
64
89
  : null,
65
90
  'Output exactly these four sections, in this order, keeping every heading even when it has nothing under it:',
66
91
  '## Objective\n## Facts and decisions\n## State\n## Next steps',
@@ -120,4 +145,45 @@ export class Fold {
120
145
  };
121
146
  }
122
147
  }
148
+ async rounds(messages, options) {
149
+ if (!Fold.fits(options.ctxSize)) {
150
+ return { folded: false, reason: 'below-floor' };
151
+ }
152
+ let most = Infinity;
153
+ for (;;) {
154
+ const boundary = Fold.roundBoundary(messages, options, most);
155
+ if (!boundary?.foldedRounds) {
156
+ const summarized = boundary !== null && boundary.folded.length > 0;
157
+ return { folded: false, reason: summarized ? 'already-compacted' : 'nothing-to-fold' };
158
+ }
159
+ const folded = boundary.folded.map((at) => messages[at]);
160
+ const attempt = await this.summarize(Fold.prompt([messages[boundary.task], ...folded], options.instructions));
161
+ const summary = attempt.text?.trim() || null;
162
+ if (!summary) {
163
+ if (attempt.overflowed && boundary.foldedRounds > 1) {
164
+ most = Math.floor(boundary.foldedRounds / 2);
165
+ continue;
166
+ }
167
+ return { folded: false, reason: 'no-summary' };
168
+ }
169
+ if (!Fold.shrinks(folded, summary)) {
170
+ return { folded: false, reason: 'summary-not-smaller' };
171
+ }
172
+ const history = spliced(messages, boundary, summary);
173
+ return { folded: true, history, summary, foldedRounds: boundary.foldedRounds };
174
+ }
175
+ }
176
+ }
177
+ function spliced(messages, boundary, summary) {
178
+ const gone = new Set(boundary.folded);
179
+ return [
180
+ ...messages.slice(0, boundary.task + 1),
181
+ { role: 'user', content: Fold.turn(summary) },
182
+ ...messages.filter((_, at) => at > boundary.task && !gone.has(at))
183
+ ];
184
+ }
185
+ const SENDERS = { user: 'User', tool: 'Tool result' };
186
+ function transcribed(message) {
187
+ const sender = message.role === 'user' && message.name ? `${message.name}: ` : '';
188
+ return `${SENDERS[message.role] ?? 'Assistant'}: ${sender}${message.content}`;
123
189
  }
@@ -1,6 +1,7 @@
1
1
  import { AbortController } from 'bare-abort-controller';
2
2
  import b4a from 'b4a';
3
3
  import { noRedirectFetch } from '#no-redirect-fetch';
4
+ import { HarnessError } from './errors.js';
4
5
  import { lookupHost } from './dns-lookup.js';
5
6
  import { checkOutboundHost, resolveOutboundUrl } from './tools/url-guard.js';
6
7
  export const MAX_RESPONSE_BYTES = 100 * 1024 * 1024;
@@ -164,18 +165,21 @@ export function createGuardedFetch(options = {}) {
164
165
  try {
165
166
  for (let hops = 0;; hops++) {
166
167
  if (url.protocol !== 'http:' && url.protocol !== 'https:') {
167
- throw new TypeError(`fetch refused: unsupported protocol ${url.protocol}`);
168
+ throw new HarnessError('FETCH_REFUSED', [`unsupported protocol ${url.protocol}`]);
168
169
  }
169
170
  const literal = checkOutboundHost(url);
170
171
  if (literal) {
171
- throw new TypeError(`fetch refused: ${literal}`);
172
+ throw new HarnessError('FETCH_REFUSED', [`${literal}`]);
172
173
  }
173
174
  if (!(await mayConnect(url.hostname))) {
174
- throw new TypeError(`fetch refused: ${url.hostname} was not approved for this run`);
175
+ throw new HarnessError('FETCH_REFUSED', [`${url.hostname} was not approved for this run`]);
175
176
  }
176
- const check = await resolveOutboundUrl(url, resolveHost, controller.signal);
177
+ const check = await resolveOutboundUrl(url, {
178
+ resolveHost,
179
+ signal: controller.signal
180
+ });
177
181
  if (check.blocked) {
178
- throw new TypeError(`fetch refused: ${check.blocked}`);
182
+ throw new HarnessError('FETCH_REFUSED', [`${check.blocked}`]);
179
183
  }
180
184
  const response = await send(url, {
181
185
  method,
@@ -195,10 +199,10 @@ export function createGuardedFetch(options = {}) {
195
199
  });
196
200
  }
197
201
  if (init.redirect === 'error') {
198
- throw new TypeError('fetch refused: redirect not allowed');
202
+ throw new HarnessError('FETCH_REFUSED', ['redirect not allowed']);
199
203
  }
200
204
  if (hops >= MAX_REDIRECTS) {
201
- throw new TypeError('fetch refused: too many redirects');
205
+ throw new HarnessError('FETCH_REFUSED', ['too many redirects']);
202
206
  }
203
207
  const next = new URL(location, url);
204
208
  if (next.protocol !== url.protocol || next.host !== url.host) {
@@ -4,9 +4,12 @@ import os from 'os';
4
4
  import { readSystemStats } from '#hw-gpu-stats';
5
5
  const FLAG = '--gpu-probe';
6
6
  const TIMEOUT_MS = 5000;
7
+ let relaunchable = false;
7
8
  export function runGpuProbeIfRequested() {
8
- if (!Bare.argv.includes(FLAG))
9
+ relaunchable = true;
10
+ if (!Bare.argv.includes(FLAG)) {
9
11
  return;
12
+ }
10
13
  console.log(JSON.stringify(readSystemStats()));
11
14
  queueMicrotask(() => Bare.exit(0));
12
15
  }
@@ -48,9 +51,15 @@ export function spawnGpuProbe(entry = Bare.argv[1]) {
48
51
  });
49
52
  }
50
53
  export async function probeGpuStats() {
54
+ if (typeof Bare !== 'undefined' && Bare.argv.includes(FLAG)) {
55
+ return null;
56
+ }
51
57
  const platform = os.platform();
52
58
  if (typeof Bare === 'undefined' || (platform !== 'linux' && platform !== 'win32')) {
53
59
  return readSystemStats();
54
60
  }
61
+ if (!relaunchable) {
62
+ return null;
63
+ }
55
64
  return (await spawnGpuProbe()).stats;
56
65
  }
@@ -1,3 +1,7 @@
1
- import type { CompletionSdk } from '../contract/index.ts';
1
+ import type { CompletionSdk, Message } from '../contract/index.ts';
2
2
  export type CompletionParams = Parameters<CompletionSdk['completion']>[0];
3
- export declare function completionParams({ modelId, history, tools, generationParams, responseFormat, toolDialect, kvCache }: Omit<CompletionParams, 'stream'>): CompletionParams;
3
+ interface CompletionParamsInput extends Omit<CompletionParams, 'stream' | 'history'> {
4
+ history: Message[];
5
+ }
6
+ export declare function completionParams({ modelId, history, tools, generationParams, responseFormat, toolDialect, kvCache }: CompletionParamsInput): CompletionParams;
7
+ export {};
@@ -1,7 +1,16 @@
1
+ function isSdkMessage(turn) {
2
+ return turn.toolCalls !== null && turn.toolCallId !== null;
3
+ }
1
4
  export function completionParams({ modelId, history, tools, generationParams, responseFormat, toolDialect, kvCache }) {
2
5
  return {
3
6
  modelId,
4
- history,
7
+ history: history.map((turn) => isSdkMessage(turn)
8
+ ? turn
9
+ : {
10
+ ...turn,
11
+ toolCalls: turn.toolCalls ?? undefined,
12
+ toolCallId: turn.toolCallId ?? undefined
13
+ }),
5
14
  stream: true,
6
15
  tools,
7
16
  generationParams,
@@ -1,3 +1,4 @@
1
+ import { HarnessError } from '../errors.ts';
1
2
  import type { Operation } from '../contract/run.ts';
2
3
  export declare class RecoveryRequired extends Error {
3
4
  readonly operation: Operation;
@@ -8,7 +9,7 @@ export declare class HookHalt extends Error {
8
9
  readonly hook: string;
9
10
  constructor(reason: string, hook: string);
10
11
  }
11
- export declare class AbortedError extends Error {
12
+ export declare class AbortedError extends HarnessError<'ABORTED'> {
12
13
  constructor();
13
14
  }
14
15
  export interface ErrorCause {
@@ -1,3 +1,4 @@
1
+ import { HarnessError } from '../errors.js';
1
2
  export class RecoveryRequired extends Error {
2
3
  operation;
3
4
  constructor(operation) {
@@ -14,11 +15,9 @@ export class HookHalt extends Error {
14
15
  this.hook = hook;
15
16
  }
16
17
  }
17
- export class AbortedError extends Error {
18
+ export class AbortedError extends HarnessError {
18
19
  constructor() {
19
- super('aborted');
20
- this.name = 'AbortedError';
21
- Error.captureStackTrace?.(this, AbortedError);
20
+ super('ABORTED');
22
21
  }
23
22
  }
24
23
  const CAUSE_DEPTH = 3;
@@ -44,10 +43,7 @@ function tagCause(error, depth) {
44
43
  else if (object && typeof ownData(object, 'name') === 'string') {
45
44
  name = ownData(object, 'name');
46
45
  }
47
- const code = object && typeof ownData(object, 'code') === 'string'
48
- ?
49
- ownData(object, 'code')
50
- : undefined;
46
+ const code = object ? ownCode(object) : undefined;
51
47
  const stack = error instanceof Error ? error.stack : undefined;
52
48
  const cause = object ? tagCause(ownData(object, 'cause'), depth - 1) : undefined;
53
49
  const taggedCause = { message, name };
@@ -260,10 +256,7 @@ export function tagError(error) {
260
256
  }
261
257
  return aborted;
262
258
  }
263
- let code;
264
- if (object && typeof ownData(object, 'code') === 'string') {
265
- code = ownData(object, 'code');
266
- }
259
+ const code = object ? ownCode(object) : undefined;
267
260
  const cause = object ? tagCause(ownData(object, 'cause'), CAUSE_DEPTH) : undefined;
268
261
  const failed = {
269
262
  tag: 'failed',
@@ -330,6 +323,13 @@ function rehydrateCause(value, depth = CAUSE_DEPTH) {
330
323
  }
331
324
  return error;
332
325
  }
326
+ function ownCode(object) {
327
+ const code = ownData(object, 'code');
328
+ if (typeof code === 'string') {
329
+ return code;
330
+ }
331
+ return typeof code === 'number' && Number.isFinite(code) ? String(code) : undefined;
332
+ }
333
333
  function errorMessage(value) {
334
334
  if (typeof value === 'string')
335
335
  return value;
@@ -0,0 +1,4 @@
1
+ export declare const MAX_GOAL_CHECKS = 8;
2
+ export declare const GOAL_CHECKS_ASK: string;
3
+ export declare function namedChecks(text: string): string[];
4
+ export declare function runsCheck(command: string, check: string): boolean;
@@ -0,0 +1,81 @@
1
+ const SHELL_OPERATOR = /(&&|\|\||;|\||\n)/;
2
+ const RUNNER = /^(python[\d.]*|bash|sh|node|bun|pytest)$/;
3
+ const CHECKS_HEADING = /^[\s*#_]*checks:?[\s*_]*$/i;
4
+ const CHECK_LINE = /^\s*(?:[-*]|\d+[.)])?\s*`([^`]+)`\s*$/;
5
+ export const MAX_GOAL_CHECKS = 8;
6
+ export const GOAL_CHECKS_ASK = '[This goal has no checks yet. Name the commands that will prove the task is done: write a ' +
7
+ 'line `Checks:`, then one command per line in backticks, such as `test -s /app/result.json` ' +
8
+ 'or `python3 check.py`. Each must exit 0 only once the task is done, with no pipe, ; or && ' +
9
+ 'in it. The goal is met only once each of them ran on its own and exited 0.]';
10
+ export function namedChecks(text) {
11
+ const lines = text.split('\n');
12
+ const heading = lines.findIndex((line) => CHECKS_HEADING.test(line));
13
+ if (heading < 0) {
14
+ return [];
15
+ }
16
+ const named = [];
17
+ for (const line of lines.slice(heading + 1)) {
18
+ const command = CHECK_LINE.exec(line)?.[1].trim();
19
+ if (!command) {
20
+ if (line.trim() || named.length) {
21
+ break;
22
+ }
23
+ continue;
24
+ }
25
+ if (runsCheck(command, command) && !named.includes(command)) {
26
+ named.push(command);
27
+ }
28
+ }
29
+ return named.slice(0, MAX_GOAL_CHECKS);
30
+ }
31
+ export function runsCheck(command, check) {
32
+ const wanted = words(check);
33
+ const parts = command.split(SHELL_OPERATOR);
34
+ for (let at = parts.length - 1; at >= 0; at -= 2) {
35
+ if (!parts[at].trim()) {
36
+ parts.splice(at === parts.length - 1 ? Math.max(at - 1, 0) : at, 2);
37
+ }
38
+ }
39
+ for (let at = 0; at < parts.length; at += 2) {
40
+ const after = parts.slice(at + 1).filter((_, n) => n % 2 === 0);
41
+ if (parts[at - 1] !== '||' &&
42
+ after.every((operator) => operator === '&&') &&
43
+ invokes(words(parts[at]), wanted)) {
44
+ return true;
45
+ }
46
+ }
47
+ return false;
48
+ }
49
+ function words(text) {
50
+ return text
51
+ .trim()
52
+ .split(/\s+/)
53
+ .filter(Boolean)
54
+ .map((word) => word.replace(/^['"]|['"]$/g, ''));
55
+ }
56
+ function invokes(tokens, wanted) {
57
+ let start = tokens.findIndex((token) => !/^\w+=/.test(token));
58
+ if (start < 0) {
59
+ return false;
60
+ }
61
+ if (leads(tokens.slice(start), wanted)) {
62
+ return true;
63
+ }
64
+ if (!RUNNER.test(tokens[start].split('/').at(-1) ?? '')) {
65
+ return false;
66
+ }
67
+ start++;
68
+ while (tokens[start]?.startsWith('-')) {
69
+ start++;
70
+ }
71
+ return leads(tokens.slice(start), wanted);
72
+ }
73
+ function leads(tokens, wanted) {
74
+ return (wanted.length > 0 &&
75
+ wanted.every((word, at) => tokens[at] !== undefined && samePath(tokens[at], word)));
76
+ }
77
+ function samePath(a, b) {
78
+ const left = a.replace(/^\.\//, '');
79
+ const right = b.replace(/^\.\//, '');
80
+ return left === right || left.endsWith(`/${right}`) || right.endsWith(`/${left}`);
81
+ }
@@ -1,5 +1,5 @@
1
1
  function omitted(count, locator, startLine) {
2
- const where = locator ? `; read_files path=${locator} startLine=${startLine}` : '';
2
+ const where = locator ? `; read_file path=${locator} startLine=${startLine}` : '';
3
3
  return `\n…[${count} chars omitted${where}]…\n`;
4
4
  }
5
5
  export function headTail(text, limit) {
@@ -3,4 +3,4 @@ export interface LoadStall {
3
3
  clear: () => void;
4
4
  promise: Promise<never>;
5
5
  }
6
- export declare function createLoadStall(ms: number, message: string): LoadStall;
6
+ export declare function createLoadStall(ms: number, stalled: () => Error): LoadStall;
@@ -1,4 +1,4 @@
1
- export function createLoadStall(ms, message) {
1
+ export function createLoadStall(ms, stalled) {
2
2
  let timer = null;
3
3
  let rejectStall = null;
4
4
  const promise = new Promise((_, reject) => {
@@ -9,7 +9,7 @@ export function createLoadStall(ms, message) {
9
9
  clearTimeout(timer);
10
10
  }
11
11
  timer = setTimeout(() => {
12
- rejectStall?.(new Error(message));
12
+ rejectStall?.(stalled());
13
13
  }, ms);
14
14
  };
15
15
  arm();
@@ -1,5 +1,8 @@
1
+ export interface MarkupStreamFilterOptions {
2
+ readonly onToolCall?: (body: string) => void;
3
+ }
1
4
  export interface MarkupStreamFilter {
2
5
  readonly push: (token: string) => string;
3
6
  readonly flush: () => string;
4
7
  }
5
- export declare function createMarkupStreamFilter(): MarkupStreamFilter;
8
+ export declare function createMarkupStreamFilter(options?: MarkupStreamFilterOptions): MarkupStreamFilter;
@@ -1,7 +1,8 @@
1
1
  import { holdback } from 'asenion/scan';
2
2
  import { createJoinGuard } from './join-guard.js';
3
3
  import { scanNamedMarkup } from './markup-scanner.js';
4
- const MARKUP_OPENERS = ['<tool_call>', '<tool_response>'];
4
+ const TOOL_CALL_OPEN = '<tool_call>';
5
+ const MARKUP_OPENERS = [TOOL_CALL_OPEN, '<tool_response>'];
5
6
  const MARKUP_CLOSERS = {
6
7
  '<tool_call>': '</tool_call>',
7
8
  '<tool_response>': '</tool_response>'
@@ -9,13 +10,15 @@ const MARKUP_CLOSERS = {
9
10
  const MARKUP_MARKERS = [...MARKUP_OPENERS, ...Object.values(MARKUP_CLOSERS)];
10
11
  const FUNCTION_CLOSE = '</function>';
11
12
  const JOIN_MARKERS = [...MARKUP_MARKERS, '<function', '</function>', '<FUNCTION', '</FUNCTION>'];
12
- function initialState() {
13
+ function initialState({ onToolCall = noop }) {
13
14
  return {
14
15
  buffer: '',
15
16
  lower: '',
16
17
  markerAt: MARKUP_MARKERS.map(() => -1),
17
18
  namedFrom: 0,
18
19
  closer: null,
20
+ held: null,
21
+ onToolCall,
19
22
  candidate: null,
20
23
  candidateTail: '',
21
24
  stripNewline: false,
@@ -67,8 +70,8 @@ function nextStep(state) {
67
70
  }
68
71
  return state.closer ? consumeSuppressed(state) : emitUntilOpener(state);
69
72
  }
70
- export function createMarkupStreamFilter() {
71
- const state = initialState();
73
+ export function createMarkupStreamFilter(options = {}) {
74
+ const state = initialState(options);
72
75
  return {
73
76
  push(token) {
74
77
  appendBuffer(state, token);
@@ -87,6 +90,7 @@ export function createMarkupStreamFilter() {
87
90
  function resetPending(state) {
88
91
  setBuffer(state, '');
89
92
  state.closer = null;
93
+ state.held = null;
90
94
  state.candidate = null;
91
95
  state.candidateTail = '';
92
96
  state.stripNewline = false;
@@ -112,10 +116,18 @@ function consumeSuppressed(state) {
112
116
  const closer = state.closer ?? '';
113
117
  const end = state.buffer.indexOf(closer);
114
118
  if (end === -1) {
115
- const held = holdback(state.buffer, [closer]);
116
- setBuffer(state, state.buffer.slice(state.buffer.length - held));
119
+ const kept = state.buffer.length - holdback(state.buffer, [closer]);
120
+ if (state.held !== null) {
121
+ state.held += state.buffer.slice(0, kept);
122
+ }
123
+ setBuffer(state, state.buffer.slice(kept));
117
124
  return { out: '', done: true };
118
125
  }
126
+ if (state.held !== null) {
127
+ const body = state.held + state.buffer.slice(0, end);
128
+ state.held = null;
129
+ state.onToolCall(body);
130
+ }
119
131
  setBuffer(state, state.buffer.slice(end + closer.length));
120
132
  state.stripNewline = true;
121
133
  state.closer = null;
@@ -143,6 +155,7 @@ function consumeFixedMarker(state, index, marker) {
143
155
  const closer = MARKUP_CLOSERS[marker];
144
156
  state.stripNewline = closer === undefined;
145
157
  state.closer = closer ?? null;
158
+ state.held = marker === TOOL_CALL_OPEN ? '' : null;
146
159
  return { out, done: false };
147
160
  }
148
161
  function scanNamedOpen(buffer, haystack, start) {
@@ -179,3 +192,4 @@ function emitUntilOpener(state) {
179
192
  setBuffer(state, state.buffer.slice(state.buffer.length - hold));
180
193
  return { out, done: true };
181
194
  }
195
+ function noop() { }
@@ -17,28 +17,36 @@ function firstHalf(items, key) {
17
17
  const repeats = items.slice(half).every((item, at) => key(item) === key(items[at]));
18
18
  return repeats ? items.slice(0, half) : items;
19
19
  }
20
- async function* withoutRepeatedTail(tokens) {
20
+ async function* withoutRepeatedTail(events) {
21
21
  let streamed = '';
22
- let held = '';
23
- for await (const token of tokens) {
24
- if (held && streamed.startsWith(held + token)) {
25
- held += token;
22
+ let held = [];
23
+ let heldText = '';
24
+ for await (const event of events) {
25
+ if (event.type !== 'contentDelta') {
26
+ yield event;
26
27
  continue;
27
28
  }
28
- if (held) {
29
- yield held;
30
- streamed += held;
31
- held = '';
29
+ if (heldText && streamed.startsWith(heldText + event.text)) {
30
+ held.push(event);
31
+ heldText += event.text;
32
+ continue;
33
+ }
34
+ if (heldText) {
35
+ yield* held;
36
+ streamed += heldText;
37
+ held = [];
38
+ heldText = '';
32
39
  }
33
- if (streamed.length >= MIN_REPEAT_CHARS && token && streamed.startsWith(token)) {
34
- held = token;
40
+ if (streamed.length >= MIN_REPEAT_CHARS && event.text && streamed.startsWith(event.text)) {
41
+ held = [event];
42
+ heldText = event.text;
35
43
  continue;
36
44
  }
37
- streamed += token;
38
- yield token;
45
+ streamed += event.text;
46
+ yield event;
39
47
  }
40
- if (held && held !== streamed) {
41
- yield held;
48
+ if (heldText && heldText !== streamed) {
49
+ yield* held;
42
50
  }
43
51
  }
44
52
  function once(reply) {
@@ -58,6 +66,6 @@ function once(reply) {
58
66
  export function withoutRepeatedReply(result) {
59
67
  const final = result.final.then(once);
60
68
  final.catch(noop);
61
- return { ...result, tokenStream: withoutRepeatedTail(result.tokenStream), final };
69
+ return { ...result, events: withoutRepeatedTail(result.events), final };
62
70
  }
63
71
  function noop() { }
@@ -1,8 +1,9 @@
1
- export interface TextEvent {
1
+ export type TextEvent = {
2
2
  type: 'thinking' | 'content';
3
3
  text: string;
4
- }
4
+ };
5
5
  export interface SplitThinkingOptions {
6
6
  startInThink?: boolean;
7
7
  }
8
+ export declare function tapThinking(tokens: AsyncIterable<string>, opts: SplitThinkingOptions, onThinking: () => void): AsyncGenerator<string>;
8
9
  export declare function splitThinking(tokens: AsyncIterable<string>, opts?: SplitThinkingOptions): AsyncGenerator<TextEvent, string | null>;
@@ -24,6 +24,25 @@ function nextTag(buffer, inThink) {
24
24
  }
25
25
  return open && { ...open, inThink: true };
26
26
  }
27
+ export async function* tapThinking(tokens, opts, onThinking) {
28
+ let inThink = opts.startInThink === true;
29
+ let tail = '';
30
+ for await (const token of tokens) {
31
+ const wasThinking = inThink;
32
+ tail += token;
33
+ let tag = firstMarker(tail, inThink ? CLOSE_TAGS : OPEN_TAGS);
34
+ while (tag) {
35
+ tail = tail.slice(tag.index + tag.marker.length);
36
+ inThink = !inThink;
37
+ tag = firstMarker(tail, inThink ? CLOSE_TAGS : OPEN_TAGS);
38
+ }
39
+ tail = tail.slice(tail.length - holdback(tail, inThink ? CLOSE_TAGS : OPEN_TAGS));
40
+ if (wasThinking && inThink) {
41
+ onThinking();
42
+ }
43
+ yield token;
44
+ }
45
+ }
27
46
  export async function* splitThinking(tokens, opts) {
28
47
  let buffer = '';
29
48
  let inThink = opts?.startInThink === true;
@@ -1,6 +1,6 @@
1
1
  import { jsonrepair } from 'jsonrepair';
2
2
  import { isRecord } from '../../guards.js';
3
- import { hlog } from '../../log.js';
3
+ import { HarnessLog } from '../../log.js';
4
4
  import { escapeLiteralDollars } from '../../tools/exec/scope.js';
5
5
  const JSON_NUMBER = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
6
6
  export class ArgRepairHook {
@@ -57,7 +57,11 @@ function coerceString(value, schema, site) {
57
57
  }
58
58
  }
59
59
  if (structured || scalarOnly) {
60
- hlog('arg repair declined', { tool: site.tool, param: site.path, length: value.length });
60
+ HarnessLog.debug('arg repair declined', {
61
+ tool: site.tool,
62
+ param: site.path,
63
+ length: value.length
64
+ });
61
65
  }
62
66
  return value;
63
67
  }
@@ -0,0 +1,8 @@
1
+ import type { HarnessHook, HookContext, HookResult, PolicyRule } from '../../contract/index.ts';
2
+ export declare class PolicyRulesHook implements HarnessHook {
3
+ readonly name = "policy-rules";
4
+ readonly phase: 'preToolCall';
5
+ readonly rules: readonly PolicyRule[];
6
+ constructor(rules: readonly PolicyRule[]);
7
+ run(ctx: HookContext): HookResult;
8
+ }