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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (466) hide show
  1. package/.nvmrc +1 -0
  2. package/CHANGELOG.md +2302 -1485
  3. package/README.md +44 -31
  4. package/dist-lib/index.d.ts +51 -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 +104 -40
  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 +22 -13
  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 +50 -22
  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 +33 -6
  35. package/dist-lib/lib/capabilities/completion-engine/driver.js +28 -13
  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/engine.d.ts +4 -1
  39. package/dist-lib/lib/capabilities/completion-engine/engine.js +14 -1
  40. package/dist-lib/lib/capabilities/completion-engine/index.d.ts +2 -1
  41. package/dist-lib/lib/capabilities/completion-engine/index.js +2 -2
  42. package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +16 -2
  43. package/dist-lib/lib/capabilities/completion-engine/loop.js +7 -0
  44. package/dist-lib/lib/capabilities/completion-engine/metrics.d.ts +9 -2
  45. package/dist-lib/lib/capabilities/completion-engine/metrics.js +28 -7
  46. package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +46 -0
  47. package/dist-lib/lib/capabilities/completion-engine/model-round.js +45 -0
  48. package/dist-lib/lib/capabilities/completion-engine/operations.js +1 -1
  49. package/dist-lib/lib/capabilities/completion-engine/ports.js +3 -7
  50. package/dist-lib/lib/capabilities/completion-engine/round.d.ts +23 -3
  51. package/dist-lib/lib/capabilities/completion-engine/round.js +323 -97
  52. package/dist-lib/lib/capabilities/completion-engine/session.d.ts +10 -3
  53. package/dist-lib/lib/capabilities/completion-engine/session.js +30 -2
  54. package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +3 -2
  55. package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +4 -3
  56. package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +15 -10
  57. package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +14 -9
  58. package/dist-lib/lib/capabilities/completion-engine/turns.js +63 -86
  59. package/dist-lib/lib/capabilities/download.d.ts +9 -7
  60. package/dist-lib/lib/capabilities/download.js +1 -1
  61. package/dist-lib/lib/capabilities/enhance.d.ts +1 -1
  62. package/dist-lib/lib/capabilities/enhance.js +20 -8
  63. package/dist-lib/lib/capabilities/preview-model-source.d.ts +7 -0
  64. package/dist-lib/lib/capabilities/preview-model-source.js +83 -23
  65. package/dist-lib/lib/capabilities/sdk-tool.d.ts +1 -0
  66. package/dist-lib/lib/capabilities/sdk-tool.js +18 -1
  67. package/dist-lib/lib/capabilities/tool-plan.d.ts +1 -1
  68. package/dist-lib/lib/capabilities/tool-plan.js +5 -5
  69. package/dist-lib/lib/capabilities/tool-prompt-log.js +3 -3
  70. package/dist-lib/lib/capabilities/tool-turns.d.ts +7 -9
  71. package/dist-lib/lib/capabilities/tool-turns.js +25 -20
  72. package/dist-lib/lib/client/index.d.ts +19 -0
  73. package/dist-lib/lib/client/index.js +262 -0
  74. package/dist-lib/lib/connect.d.ts +13 -10
  75. package/dist-lib/lib/connect.js +68 -26
  76. package/dist-lib/lib/context-window.d.ts +1 -0
  77. package/dist-lib/lib/context-window.js +3 -3
  78. package/dist-lib/lib/contract/agent.d.ts +7 -3
  79. package/dist-lib/lib/contract/completion.d.ts +51 -30
  80. package/dist-lib/lib/contract/drive.d.ts +4 -0
  81. package/dist-lib/lib/contract/drive.js +1 -0
  82. package/dist-lib/lib/contract/egress-proxy.d.ts +13 -0
  83. package/dist-lib/lib/contract/egress-proxy.js +1 -0
  84. package/dist-lib/lib/contract/exec.d.ts +3 -3
  85. package/dist-lib/lib/contract/hooks.d.ts +4 -1
  86. package/dist-lib/lib/contract/index.d.ts +3 -0
  87. package/dist-lib/lib/contract/managed-skills.d.ts +1 -0
  88. package/dist-lib/lib/contract/managed-skills.js +1 -0
  89. package/dist-lib/lib/contract/models.d.ts +6 -4
  90. package/dist-lib/lib/contract/policy.d.ts +75 -0
  91. package/dist-lib/lib/contract/policy.js +1 -0
  92. package/dist-lib/lib/contract/run.d.ts +15 -3
  93. package/dist-lib/lib/contract/sandbox.d.ts +3 -1
  94. package/dist-lib/lib/contract/translation.d.ts +20 -0
  95. package/dist-lib/lib/contract/translation.js +1 -0
  96. package/dist-lib/lib/contract-types.d.ts +35 -15
  97. package/dist-lib/lib/embeddings/index.d.ts +7 -1
  98. package/dist-lib/lib/embeddings/index.js +26 -5
  99. package/dist-lib/lib/errors.d.ts +266 -0
  100. package/dist-lib/lib/errors.js +198 -0
  101. package/dist-lib/lib/fold/index.d.ts +25 -1
  102. package/dist-lib/lib/fold/index.js +75 -9
  103. package/dist-lib/lib/guarded-fetch.js +11 -7
  104. package/dist-lib/lib/hardware/gpu-probe.js +10 -1
  105. package/dist-lib/lib/helpers/completion-params.d.ts +6 -2
  106. package/dist-lib/lib/helpers/completion-params.js +10 -1
  107. package/dist-lib/lib/helpers/engine-error.d.ts +2 -1
  108. package/dist-lib/lib/helpers/engine-error.js +12 -12
  109. package/dist-lib/lib/helpers/goal-check.d.ts +4 -0
  110. package/dist-lib/lib/helpers/goal-check.js +81 -0
  111. package/dist-lib/lib/helpers/head-tail.js +1 -1
  112. package/dist-lib/lib/helpers/load-stall.d.ts +1 -1
  113. package/dist-lib/lib/helpers/load-stall.js +2 -2
  114. package/dist-lib/lib/helpers/markup-stream-filter.d.ts +4 -1
  115. package/dist-lib/lib/helpers/markup-stream-filter.js +20 -6
  116. package/dist-lib/lib/helpers/repeated-reply.js +24 -16
  117. package/dist-lib/lib/helpers/thinking.d.ts +3 -2
  118. package/dist-lib/lib/helpers/thinking.js +19 -0
  119. package/dist-lib/lib/hooks/built-in/arg-repair.js +6 -2
  120. package/dist-lib/lib/hooks/built-in/policy-rules.d.ts +8 -0
  121. package/dist-lib/lib/hooks/built-in/policy-rules.js +192 -0
  122. package/dist-lib/lib/hooks/built-in/sandbox.js +23 -5
  123. package/dist-lib/lib/hooks/index.d.ts +4 -1
  124. package/dist-lib/lib/hooks/index.js +9 -4
  125. package/dist-lib/lib/hooks/run.js +3 -3
  126. package/dist-lib/lib/lifecycle/index.js +15 -14
  127. package/dist-lib/lib/lifecycle/machine.js +2 -2
  128. package/dist-lib/lib/log.d.ts +26 -5
  129. package/dist-lib/lib/log.js +86 -23
  130. package/dist-lib/lib/machine/completion/actions/completion.d.ts +4 -2
  131. package/dist-lib/lib/machine/completion/actions/completion.js +78 -12
  132. package/dist-lib/lib/machine/completion/actions/prepare.js +1 -1
  133. package/dist-lib/lib/machine/completion/actions/tools.js +48 -5
  134. package/dist-lib/lib/machine/completion/context.js +5 -1
  135. package/dist-lib/lib/machine/completion/guards/retry.d.ts +1 -0
  136. package/dist-lib/lib/machine/completion/guards/retry.js +8 -2
  137. package/dist-lib/lib/machine/completion/implementations.d.ts +10 -4
  138. package/dist-lib/lib/machine/completion/implementations.js +43 -10
  139. package/dist-lib/lib/machine/completion/machine.d.ts +23 -3
  140. package/dist-lib/lib/machine/completion/machine.js +33 -4
  141. package/dist-lib/lib/machine/completion/rules.d.ts +17 -2
  142. package/dist-lib/lib/machine/completion/rules.js +49 -3
  143. package/dist-lib/lib/machine/completion/types.d.ts +43 -1
  144. package/dist-lib/lib/machine/index.d.ts +29 -4
  145. package/dist-lib/lib/machine/index.js +6 -1
  146. package/dist-lib/lib/models/context-choice.d.ts +15 -0
  147. package/dist-lib/lib/models/context-choice.js +55 -0
  148. package/dist-lib/lib/models/download-gate.d.ts +20 -0
  149. package/dist-lib/lib/models/download-gate.js +73 -0
  150. package/dist-lib/lib/models/gguf-header.d.ts +5 -0
  151. package/dist-lib/lib/models/gguf-header.js +165 -14
  152. package/dist-lib/lib/models/llm-presets.d.ts +5 -1
  153. package/dist-lib/lib/models/llm-presets.js +6 -5
  154. package/dist-lib/lib/models/memory-cap.d.ts +13 -0
  155. package/dist-lib/lib/models/memory-cap.js +21 -0
  156. package/dist-lib/lib/models/model-catalog.d.ts +2 -0
  157. package/dist-lib/lib/models/model-catalog.js +15 -0
  158. package/dist-lib/lib/models/model-fit.d.ts +1 -1
  159. package/dist-lib/lib/models/model-fit.js +5 -6
  160. package/dist-lib/lib/models/model-handle.d.ts +8 -2
  161. package/dist-lib/lib/models/model-handle.js +14 -3
  162. package/dist-lib/lib/models/model-list.d.ts +8 -1
  163. package/dist-lib/lib/models/model-list.js +23 -0
  164. package/dist-lib/lib/models/model-pool.d.ts +35 -5
  165. package/dist-lib/lib/models/model-pool.js +121 -43
  166. package/dist-lib/lib/models/model-source.d.ts +1 -0
  167. package/dist-lib/lib/models/model-source.js +23 -5
  168. package/dist-lib/lib/models/sdk-faults.d.ts +1 -0
  169. package/dist-lib/lib/models/sdk-faults.js +9 -0
  170. package/dist-lib/lib/no-redirect-fetch-bare.js +2 -1
  171. package/dist-lib/lib/no-redirect-fetch-impl.js +2 -1
  172. package/dist-lib/lib/office/engine/pptx/picture-area.d.ts +23 -0
  173. package/dist-lib/lib/office/engine/pptx/picture-area.js +84 -0
  174. package/dist-lib/lib/office/engine/pptx/presentation.d.ts +2 -0
  175. package/dist-lib/lib/office/engine/pptx/presentation.js +55 -17
  176. package/dist-lib/lib/office/engine/pptx/types.d.ts +1 -0
  177. package/dist-lib/lib/office/engine/xlsx/workbook.d.ts +1 -0
  178. package/dist-lib/lib/office/engine/xlsx/workbook.js +34 -3
  179. package/dist-lib/lib/office/extract.js +4 -3
  180. package/dist-lib/lib/office/index.js +2 -1
  181. package/dist-lib/lib/plugins/registry.d.ts +3 -0
  182. package/dist-lib/lib/plugins/registry.js +16 -7
  183. package/dist-lib/lib/policy/index.d.ts +10 -0
  184. package/dist-lib/lib/policy/index.js +229 -0
  185. package/dist-lib/lib/prompt.d.ts +1 -0
  186. package/dist-lib/lib/prompt.js +7 -1
  187. package/dist-lib/lib/residency/completion-runtime.d.ts +1 -0
  188. package/dist-lib/lib/residency/completion-runtime.js +11 -4
  189. package/dist-lib/lib/residency/index.d.ts +44 -4
  190. package/dist-lib/lib/residency/index.js +399 -35
  191. package/dist-lib/lib/resolution-detector.js +3 -3
  192. package/dist-lib/lib/rpc-session.js +2 -1
  193. package/dist-lib/lib/sdk-loader.js +17 -11
  194. package/dist-lib/lib/serve.js +83 -38
  195. package/dist-lib/lib/sidecar/index.d.ts +29 -0
  196. package/dist-lib/lib/sidecar/index.js +174 -0
  197. package/dist-lib/lib/sidecar/user-plugins.d.ts +8 -0
  198. package/dist-lib/lib/sidecar/user-plugins.js +117 -0
  199. package/dist-lib/lib/skills-host/index.d.ts +1 -0
  200. package/dist-lib/lib/skills-host/index.js +8 -4
  201. package/dist-lib/lib/spawn.d.ts +3 -4
  202. package/dist-lib/lib/spawn.js +17 -17
  203. package/dist-lib/lib/spill.d.ts +1 -0
  204. package/dist-lib/lib/spill.js +12 -8
  205. package/dist-lib/lib/tools/attachments/staging.js +8 -8
  206. package/dist-lib/lib/tools/exec/runner.js +2 -1
  207. package/dist-lib/lib/tools/exec/scope.d.ts +0 -1
  208. package/dist-lib/lib/tools/exec/scope.js +23 -114
  209. package/dist-lib/lib/tools/exec/shell-guidance.js +4 -4
  210. package/dist-lib/lib/tools/exec/shell-line.d.ts +26 -0
  211. package/dist-lib/lib/tools/exec/shell-line.js +334 -0
  212. package/dist-lib/lib/tools/exec.d.ts +4 -1
  213. package/dist-lib/lib/tools/exec.js +87 -26
  214. package/dist-lib/lib/tools/files/edit-file.d.ts +3 -0
  215. package/dist-lib/lib/tools/files/edit-file.js +74 -0
  216. package/dist-lib/lib/tools/files/glob.d.ts +3 -0
  217. package/dist-lib/lib/tools/files/glob.js +65 -0
  218. package/dist-lib/lib/tools/files/grep.d.ts +6 -0
  219. package/dist-lib/lib/tools/files/grep.js +114 -0
  220. package/dist-lib/lib/tools/files/index.d.ts +3 -0
  221. package/dist-lib/lib/tools/files/index.js +23 -0
  222. package/dist-lib/lib/tools/files/list-dir.d.ts +6 -0
  223. package/dist-lib/lib/tools/files/list-dir.js +136 -0
  224. package/dist-lib/lib/tools/files/make-dir.d.ts +3 -0
  225. package/dist-lib/lib/tools/files/make-dir.js +48 -0
  226. package/dist-lib/lib/tools/files/read-file.d.ts +3 -0
  227. package/dist-lib/lib/tools/files/read-file.js +105 -0
  228. package/dist-lib/lib/tools/files/transfer.d.ts +4 -0
  229. package/dist-lib/lib/tools/files/transfer.js +83 -0
  230. package/dist-lib/lib/tools/files/trash-file.d.ts +4 -0
  231. package/dist-lib/lib/tools/files/trash-file.js +62 -0
  232. package/dist-lib/lib/tools/files/write-file.d.ts +3 -0
  233. package/dist-lib/lib/tools/files/write-file.js +56 -0
  234. package/dist-lib/lib/tools/fs/document-text.d.ts +2 -0
  235. package/dist-lib/lib/tools/fs/document-text.js +38 -0
  236. package/dist-lib/lib/tools/fs/drive.d.ts +14 -3
  237. package/dist-lib/lib/tools/fs/drive.js +9 -1
  238. package/dist-lib/lib/tools/fs/edit-match.d.ts +11 -0
  239. package/dist-lib/lib/tools/fs/edit-match.js +85 -0
  240. package/dist-lib/lib/tools/fs/ignore.d.ts +13 -0
  241. package/dist-lib/lib/tools/fs/ignore.js +104 -0
  242. package/dist-lib/lib/tools/fs/local.js +28 -5
  243. package/dist-lib/lib/tools/fs/remote-protocol.d.ts +23 -3
  244. package/dist-lib/lib/tools/fs/remote.d.ts +3 -4
  245. package/dist-lib/lib/tools/fs/remote.js +23 -13
  246. package/dist-lib/lib/tools/fs/scope.d.ts +5 -1
  247. package/dist-lib/lib/tools/fs/scope.js +5 -2
  248. package/dist-lib/lib/tools/fs/search.d.ts +41 -0
  249. package/dist-lib/lib/tools/fs/search.js +382 -0
  250. package/dist-lib/lib/tools/{file-glob.d.ts → fs/targets.d.ts} +1 -5
  251. package/dist-lib/lib/tools/fs/targets.js +32 -0
  252. package/dist-lib/lib/tools/fs/tool-path.d.ts +27 -0
  253. package/dist-lib/lib/tools/fs/tool-path.js +70 -0
  254. package/dist-lib/lib/tools/fs/walk.d.ts +15 -3
  255. package/dist-lib/lib/tools/fs/walk.js +118 -24
  256. package/dist-lib/lib/tools/http-request.js +12 -2
  257. package/dist-lib/lib/tools/index.js +2 -10
  258. package/dist-lib/lib/tools/office/ops.js +1 -1
  259. package/dist-lib/lib/tools/office.js +77 -21
  260. package/dist-lib/lib/tools/pdf/build.d.ts +5 -1
  261. package/dist-lib/lib/tools/pdf/build.js +31 -6
  262. package/dist-lib/lib/tools/pdf.js +17 -2
  263. package/dist-lib/lib/tools/skill.js +10 -7
  264. package/dist-lib/lib/tools/skills/bundled-dir.js +4 -4
  265. package/dist-lib/lib/tools/skills/catalog.d.ts +2 -0
  266. package/dist-lib/lib/tools/skills/catalog.js +6 -2
  267. package/dist-lib/lib/tools/skills/cli-argv.js +25 -5
  268. package/dist-lib/lib/tools/skills/cli-schema-check.d.ts +1 -0
  269. package/dist-lib/lib/tools/skills/cli-schema-check.js +3 -0
  270. package/dist-lib/lib/tools/skills/cli-schema-load.js +10 -0
  271. package/dist-lib/lib/tools/skills/cli-schema-types.d.ts +2 -0
  272. package/dist-lib/lib/tools/skills/cli-schema.js +6 -3
  273. package/dist-lib/lib/tools/skills/credential-health.js +3 -3
  274. package/dist-lib/lib/tools/skills/frontmatter-parser.d.ts +2 -0
  275. package/dist-lib/lib/tools/skills/frontmatter-parser.js +4 -0
  276. package/dist-lib/lib/tools/skills/manifest-parse.d.ts +1 -0
  277. package/dist-lib/lib/tools/skills/manifest-parse.js +12 -0
  278. package/dist-lib/lib/tools/skills/mention-name.d.ts +6 -0
  279. package/dist-lib/lib/tools/skills/mention-name.js +6 -0
  280. package/dist-lib/lib/tools/skills/mention.d.ts +2 -2
  281. package/dist-lib/lib/tools/skills/mention.js +11 -4
  282. package/dist-lib/lib/tools/skills/overlay-crud.js +3 -2
  283. package/dist-lib/lib/tools/url-guard.d.ts +6 -1
  284. package/dist-lib/lib/tools/url-guard.js +8 -2
  285. package/dist-lib/lib/tools/web-fetch.js +10 -4
  286. package/dist-lib/lib/wire.js +8 -5
  287. package/dist-lib/plugins/coding/index.d.ts +1 -1
  288. package/dist-lib/plugins/coding/index.js +2 -4
  289. package/dist-lib/plugins/coding/session.d.ts +3 -3
  290. package/dist-lib/plugins/coding/session.js +26 -14
  291. package/dist-lib/plugins/command-hooks/index.js +5 -3
  292. package/dist-lib/plugins/egress-proxy/index.d.ts +53 -0
  293. package/dist-lib/plugins/egress-proxy/index.js +182 -0
  294. package/dist-lib/plugins/image/edit-image.js +4 -3
  295. package/dist-lib/plugins/image/generate-image.d.ts +4 -3
  296. package/dist-lib/plugins/image/generate-image.js +10 -9
  297. package/dist-lib/plugins/image/index.d.ts +1 -1
  298. package/dist-lib/plugins/image/index.js +13 -10
  299. package/dist-lib/plugins/language-hint/index.d.ts +15 -0
  300. package/dist-lib/plugins/language-hint/index.js +51 -0
  301. package/dist-lib/plugins/lsp/tool.js +2 -2
  302. package/dist-lib/plugins/mcp/index.js +6 -3
  303. package/dist-lib/plugins/music/generate-music.d.ts +4 -2
  304. package/dist-lib/plugins/music/generate-music.js +7 -4
  305. package/dist-lib/plugins/music/index.js +12 -9
  306. package/dist-lib/plugins/obsidian/command.js +2 -2
  307. package/dist-lib/plugins/obsidian/note-name.js +2 -1
  308. package/dist-lib/plugins/obsidian/safe-path.js +5 -4
  309. package/dist-lib/plugins/obsidian/vault-create.js +3 -2
  310. package/dist-lib/plugins/obsidian/vault-fs.js +2 -2
  311. package/dist-lib/plugins/obsidian/vault-paths.js +3 -2
  312. package/dist-lib/plugins/obsidian/vault-read.js +6 -5
  313. package/dist-lib/plugins/obsidian/vault-write.js +13 -12
  314. package/dist-lib/plugins/python/guarded-fetch.d.ts +2 -1
  315. package/dist-lib/plugins/python/guarded-fetch.js +5 -1
  316. package/dist-lib/plugins/python/interrupt-timer.js +2 -2
  317. package/dist-lib/plugins/python/loader.js +68 -3
  318. package/dist-lib/plugins/python/memfs.js +2 -2
  319. package/dist-lib/plugins/python/pyodide.d.ts +1 -0
  320. package/dist-lib/plugins/python/pyodide.js +9 -8
  321. package/dist-lib/plugins/python/python-adapter.js +3 -1
  322. package/dist-lib/plugins/python/run-session.d.ts +1 -0
  323. package/dist-lib/plugins/python/run-session.js +19 -8
  324. package/dist-lib/plugins/python/wheels.js +8 -6
  325. package/dist-lib/plugins/python/worker/active.js +2 -2
  326. package/dist-lib/plugins/python/worker/client.js +9 -8
  327. package/dist-lib/plugins/python/worker/protocol.d.ts +2 -0
  328. package/dist-lib/plugins/python/worker/serve.js +23 -4
  329. package/dist-lib/plugins/python/worker/spawn.d.ts +2 -1
  330. package/dist-lib/plugins/python/worker/spawn.js +2 -1
  331. package/dist-lib/plugins/run-report/chain.d.ts +2 -0
  332. package/dist-lib/plugins/run-report/chain.js +73 -0
  333. package/dist-lib/plugins/run-report/flow-view.js +2 -1
  334. package/dist-lib/plugins/run-report/flow.d.ts +1 -1
  335. package/dist-lib/plugins/run-report/flow.js +66 -14
  336. package/dist-lib/plugins/run-report/index.d.ts +23 -2
  337. package/dist-lib/plugins/run-report/index.js +27 -12
  338. package/dist-lib/plugins/run-report/model.d.ts +10 -1
  339. package/dist-lib/plugins/run-report/model.js +12 -6
  340. package/dist-lib/plugins/run-report/page.d.ts +9 -0
  341. package/dist-lib/plugins/run-report/page.js +55 -15
  342. package/dist-lib/plugins/run-report/script.js +317 -43
  343. package/dist-lib/plugins/run-report/story.d.ts +2 -1
  344. package/dist-lib/plugins/run-report/story.js +3 -3
  345. package/dist-lib/plugins/run-report/style.d.ts +1 -1
  346. package/dist-lib/plugins/run-report/style.js +126 -0
  347. package/dist-lib/plugins/run-report/why.js +1 -1
  348. package/dist-lib/plugins/sandbox-linux/index.d.ts +60 -0
  349. package/dist-lib/plugins/sandbox-linux/index.js +347 -0
  350. package/dist-lib/plugins/sandbox-linux/seccomp.d.ts +2 -0
  351. package/dist-lib/plugins/sandbox-linux/seccomp.js +74 -0
  352. package/dist-lib/plugins/sandbox-macos/index.d.ts +23 -11
  353. package/dist-lib/plugins/sandbox-macos/index.js +239 -49
  354. package/dist-lib/plugins/sandbox-vm/vm-shell.d.ts +4 -2
  355. package/dist-lib/plugins/sandbox-vm/vm-shell.js +9 -4
  356. package/dist-lib/plugins/sandbox-windows/helper/qvac-sandbox.c +554 -0
  357. package/dist-lib/plugins/sandbox-windows/index.d.ts +53 -0
  358. package/dist-lib/plugins/sandbox-windows/index.js +205 -0
  359. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  360. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  361. package/dist-lib/plugins/speech/audio-resample.d.ts +1 -1
  362. package/dist-lib/plugins/speech/audio-resample.js +7 -8
  363. package/dist-lib/plugins/speech/audio-transcode-bare.d.ts +1 -1
  364. package/dist-lib/plugins/speech/audio-transcode-bare.js +23 -26
  365. package/dist-lib/plugins/speech/audio-transcode-node.d.ts +1 -1
  366. package/dist-lib/plugins/speech/audio-transcode-node.js +1 -3
  367. package/dist-lib/plugins/speech/speech-runtime.js +37 -37
  368. package/dist-lib/plugins/speech/voice.d.ts +5 -1
  369. package/dist-lib/plugins/speech/voice.js +100 -31
  370. package/dist-lib/plugins/translation/index.d.ts +1 -0
  371. package/dist-lib/plugins/translation/index.js +16 -9
  372. package/dist-lib/plugins/translation/translate.d.ts +7 -3
  373. package/dist-lib/plugins/translation/translate.js +64 -58
  374. package/dist-lib/plugins/weather/geocode.js +2 -1
  375. package/dist-lib/plugins/weather/lookup.js +5 -4
  376. package/dist-lib/plugins/web-search/engines/bing.js +2 -1
  377. package/dist-lib/plugins/web-search/engines/google.js +2 -1
  378. package/dist-lib/plugins/web-search/fetch-html.d.ts +5 -5
  379. package/dist-lib/plugins/web-search/fetch-html.js +12 -15
  380. package/dist-lib/plugins/web-search/tool.js +1 -0
  381. package/dist-lib/schema/harness.js +52 -9
  382. package/dist-lib/spec/bind.js +9 -0
  383. package/dist-lib/spec/calls.js +3 -0
  384. package/dist-lib/spec/hrpc/hrpc.json +42 -3
  385. package/dist-lib/spec/hrpc/index.js +44 -8
  386. package/dist-lib/spec/hrpc/messages.js +310 -205
  387. package/dist-lib/spec/hyperschema/index.js +310 -205
  388. package/dist-lib/spec/hyperschema/schema.json +164 -84
  389. package/dist-lib/spec/hyperschema/types.d.ts +25 -4
  390. package/package.json +98 -26
  391. package/patches/@qvac%2Finference@0.22.0.patch +59 -0
  392. package/patches/pyodide@314.0.2.patch +37 -8
  393. package/scripts/addon-externals.cjs +10 -5
  394. package/worker/harness-sidecar.mjs +18 -154
  395. package/bench/README.md +0 -94
  396. package/bench/bfcl/checker.ts +0 -313
  397. package/bench/bfcl/data.ts +0 -93
  398. package/bench/bfcl/observe.ts +0 -93
  399. package/bench/bfcl/run.ts +0 -213
  400. package/bench/bfcl/tools.ts +0 -72
  401. package/bench/bridge/bridge.ts +0 -392
  402. package/bench/bridge/openai.ts +0 -150
  403. package/bench/bridge/python/qvac_bench/__init__.py +0 -3
  404. package/bench/bridge/python/qvac_bench/airline.py +0 -42
  405. package/bench/bridge/python/qvac_bench/approval.py +0 -26
  406. package/bench/bridge/python/qvac_bench/bfcl_multi_turn.py +0 -152
  407. package/bench/bridge/python/qvac_bench/client.py +0 -88
  408. package/bench/bridge/python/qvac_bench/harbor_agent.py +0 -85
  409. package/bench/bridge/python/qvac_bench/session.py +0 -107
  410. package/bench/bridge/python/qvac_bench/speed.py +0 -30
  411. package/bench/bridge/python/qvac_bench/tau2_agent.py +0 -106
  412. package/bench/bridge/python/qvac_bench/tools.py +0 -11
  413. package/bench/bridge/python/run_bfcl_multi_turn.py +0 -95
  414. package/bench/bridge/python/run_tau2.py +0 -150
  415. package/bench/bridge/python/smoke.py +0 -47
  416. package/bench/bridge/python/test_airline.py +0 -28
  417. package/bench/bridge/python/test_approval.py +0 -57
  418. package/bench/bridge/python/test_bfcl_multi_turn.py +0 -185
  419. package/bench/bridge/python/test_harbor_agent.py +0 -107
  420. package/bench/bridge/serve.ts +0 -52
  421. package/bench/bridge/transcript.ts +0 -52
  422. package/bench/bun-tsconfig.json +0 -15
  423. package/bench/cpu-main.mjs +0 -216
  424. package/bench/cpu.ts +0 -457
  425. package/bench/evidence/2026-09-28-review15.md +0 -225
  426. package/bench/evidence/redact-bun1.3.14.json +0 -92
  427. package/bench/evidence/redact-node24.11.json +0 -92
  428. package/bench/graph-metrics.ts +0 -43
  429. package/bench/harness.ts +0 -73
  430. package/bench/issue129-matrix.mjs +0 -722
  431. package/bench/redact-adversarial.ts +0 -256
  432. package/bench/repeat-cpu.mjs +0 -281
  433. package/bench/report.ts +0 -1075
  434. package/bench/skill-eval/harness.ts +0 -30
  435. package/bench/skill-eval/laws.ts +0 -37
  436. package/bench/skill-eval/mermaid/client.ts +0 -132
  437. package/bench/skill-eval/mermaid/validate.mjs +0 -115
  438. package/bench/skill-eval/pack.ts +0 -61
  439. package/bench/skill-eval/packs/diagrams/cases.ts +0 -281
  440. package/bench/skill-eval/packs/diagrams/index.ts +0 -50
  441. package/bench/skill-eval/packs/diagrams/score.ts +0 -74
  442. package/bench/skill-eval/packs/index.ts +0 -5
  443. package/bench/skill-eval/packs/weather/cases.ts +0 -279
  444. package/bench/skill-eval/packs/weather/fixtures/wttr.json +0 -566
  445. package/bench/skill-eval/packs/weather/fixtures.ts +0 -84
  446. package/bench/skill-eval/packs/weather/index.ts +0 -55
  447. package/bench/skill-eval/packs/weather/score.ts +0 -92
  448. package/bench/skill-eval/report.ts +0 -194
  449. package/bench/skill-eval/run.ts +0 -316
  450. package/bench/speed.ts +0 -80
  451. package/dist-lib/lib/tools/create-documents.d.ts +0 -3
  452. package/dist-lib/lib/tools/create-documents.js +0 -95
  453. package/dist-lib/lib/tools/edit-documents.d.ts +0 -3
  454. package/dist-lib/lib/tools/edit-documents.js +0 -132
  455. package/dist-lib/lib/tools/exec/shell-argv.d.ts +0 -2
  456. package/dist-lib/lib/tools/exec/shell-argv.js +0 -61
  457. package/dist-lib/lib/tools/file-glob.js +0 -118
  458. package/dist-lib/lib/tools/grep.d.ts +0 -5
  459. package/dist-lib/lib/tools/grep.js +0 -184
  460. package/dist-lib/lib/tools/read-files.d.ts +0 -5
  461. package/dist-lib/lib/tools/read-files.js +0 -160
  462. package/dist-lib/plugins/coding/write-file.d.ts +0 -3
  463. package/dist-lib/plugins/coding/write-file.js +0 -52
  464. package/patches/@qvac%2Finference@0.21.0.patch +0 -67
  465. package/patches/bare-stow@0.1.5.patch +0 -68
  466. package/patches/hypercore-blob-server@1.15.0.patch +0 -15
@@ -1,7 +1,7 @@
1
1
  import { Agent } from '../../../agent/index.js';
2
2
  import { spliceFrom } from '../splice.js';
3
3
  import { AbortedError } from '../../../helpers/race-abort.js';
4
- import { hlog } from '../../../log.js';
4
+ import { HarnessLog } from '../../../log.js';
5
5
  import { MALFORMED_CALL_ID, stripToolCallMarkup } from '../../../helpers/tool-call-markup.js';
6
6
  import { toolResultTurn } from '../../tool-turns.js';
7
7
  import { unloadedTools } from '../../sdk-tool.js';
@@ -9,19 +9,27 @@ import { assistantToolTurn } from '../turns.js';
9
9
  import { resolveToolCalls } from '../tool-execution.js';
10
10
  import { toolContext } from './execution-plan.js';
11
11
  import { detachJson } from '../../../helpers/detach-json.js';
12
+ import { CompletionMachine } from '../../../machine/index.js';
12
13
  const REISSUE_HINT = 'Re-issue the tool call with complete, valid markup.';
13
- const NARRATED_INTENT = /\b(I['’]ll|I will|Now I|Let me(?! know)|Next,? I)\b[^.!?]*[.!?]?\s*$/i;
14
+ const REPEATED_CALL_ID = 'call-repeated';
15
+ const NARRATED_INTENT = /\b(?:I['’]ll|I will|Now I|Let me(?! know)|Next,? I)\b/i;
16
+ const PARAGRAPH = /(?<!:\s*)\n\s*\n(?!\s*(?:[-*+]|\d+[.)])\s)|(?<=[.!?]\s*)\n\s*\n/;
17
+ const SENTENCE = /(?<=[.!?])(?<!(?:^|\n)\s*\d+\.)\s+/;
14
18
  const CODE = /```[\s\S]*?(?:```|$)|`[^`\n]*`/g;
15
19
  const QUESTION = /\?(?![\w=&%/])/;
16
20
  const ASKS = /\bplease\s+(?:provide|tell|give|share|send|specify|confirm|let me know)\b|\b(?:tell|send|show)\s+me\b|\bgive\s+me\b(?!\s+(?:just\s+)?(?:a|an|one|two|\d+|a few|a couple(?:\s+of)?|some)\s+(?:moment|sec(?:ond)?|minute|min|bit|while|tick)s?\s*(?:[,.;!…—–]|\s-|$|(?:to|while|and|so|as|then)\b))|\blet me know\b/i;
17
21
  function narratedIntent(spoken) {
18
- const prose = spoken.replace(CODE, '');
19
- return NARRATED_INTENT.test(spoken) && !QUESTION.test(prose) && !ASKS.test(prose);
22
+ const prose = spoken.replace(CODE, '').trimEnd();
23
+ const tail = prose.split(PARAGRAPH).at(-1) ?? '';
24
+ const sentences = tail.split(SENTENCE).slice(-2);
25
+ return (sentences.some((sentence) => NARRATED_INTENT.test(sentence)) &&
26
+ !QUESTION.test(prose) &&
27
+ !ASKS.test(prose));
20
28
  }
21
29
  export const resolving = async function resolving({ input: deps, context }) {
22
30
  const { args, session } = deps;
23
31
  const round = context.lastRound;
24
- const toolCalls = round.toolCalls.map((call) => ({
32
+ const toolCalls = firstOfEach(round.toolCalls, session).map((call) => ({
25
33
  id: call.id,
26
34
  name: call.name,
27
35
  arguments: call.arguments,
@@ -35,27 +43,46 @@ export const resolving = async function resolving({ input: deps, context }) {
35
43
  agentId: context.agentId,
36
44
  pipeline: session.pipeline,
37
45
  skillNames: session.inContextSkills.map((skill) => skill.name),
38
- sandboxMode: session.policy.sandbox,
46
+ network: session.access?.network.mode ?? 'on',
39
47
  toolContext: (name) => toolContext({ deps, context, name }),
40
48
  signal: args.signal
41
49
  });
42
50
  if (args.signal?.aborted) {
43
51
  throw new AbortedError();
44
52
  }
45
- return resolvedOutput({ context, round, resolved, deps });
53
+ const repeated = toolCalls.length < round.toolCalls.length;
54
+ return resolvedOutput({ context, round, resolved, repeated, deps });
46
55
  };
56
+ function firstOfEach(calls, session) {
57
+ const seen = new Set();
58
+ return calls.filter((call) => {
59
+ const key = session.callKey(call.name, call.arguments);
60
+ const first = !seen.has(key);
61
+ seen.add(key);
62
+ return first;
63
+ });
64
+ }
47
65
  function answerFacts({ round, context, session }) {
48
66
  const replay = round.replay ? stripToolCallMarkup(round.replay) : '';
49
67
  const spoken = round.contentText.trim();
50
- const narrated = session.enabled.length && !replay && narratedIntent(spoken) ? spoken : undefined;
68
+ const cutOff = session.enabled.length > 0 && !replay && CompletionMachine.atContextBoundary(round);
69
+ const narrated = session.enabled.length && !replay && !cutOff && narratedIntent(spoken) ? spoken : undefined;
51
70
  if (narrated) {
52
- hlog('round narrated a tool call', { round: context.round });
71
+ HarnessLog.info('round narrated a tool call', { round: context.round });
53
72
  }
54
- const answer = { calls: [], response: replay || round.contentText, narrated };
73
+ if (cutOff) {
74
+ HarnessLog.info('round cut off at the context window', { round: context.round });
75
+ }
76
+ const answer = {
77
+ calls: [],
78
+ response: replay || round.contentText,
79
+ narrated,
80
+ cutOff: cutOff ? true : undefined
81
+ };
55
82
  if (!round.toolErrors?.length) {
56
83
  return answer;
57
84
  }
58
- hlog('round made malformed tool calls', {
85
+ HarnessLog.info('round made malformed tool calls', {
59
86
  round: context.round,
60
87
  errors: round.toolErrors.map((error) => error.code)
61
88
  });
@@ -64,8 +91,8 @@ function answerFacts({ round, context, session }) {
64
91
  function malformedCallTurns({ round, context, session }) {
65
92
  const errors = round.toolErrors ?? [];
66
93
  const said = [round.contentText.trim(), ...errors.map((error) => error.raw ?? '')];
67
- const error = round.stopReason === 'length'
68
- ? context.policy.cutOffMessage
94
+ const error = CompletionMachine.cutShort(round)
95
+ ? CompletionMachine.cutOffMessage(context.policy, round)
69
96
  : [
70
97
  ...errors.map(({ code, message }) => `${code}: ${message}`),
71
98
  reissueHint(errors, unloadedTools(session.enabled, context.history))
@@ -83,14 +110,31 @@ function reissueHint(errors, unloaded) {
83
110
  ? `Load ${named.join(', ')} first: call tool_search with the tool's name, then call the tool.`
84
111
  : REISSUE_HINT;
85
112
  }
86
- function resolvedOutput({ context, round, resolved, deps }) {
113
+ function repeatedCallTurn(context) {
114
+ const guidance = { guidance: context.policy.repeatedCallMessage };
115
+ return { role: 'tool', content: toolResultTurn('tool_call', REPEATED_CALL_ID, guidance) };
116
+ }
117
+ function cutTailTurn(context, round) {
118
+ const error = { error: CompletionMachine.cutOffMessage(context.policy, round) };
119
+ return { role: 'tool', content: toolResultTurn('tool_call', MALFORMED_CALL_ID, error) };
120
+ }
121
+ function cutCallId(round) {
122
+ return CompletionMachine.cutShort(round) && !round.toolErrors?.length
123
+ ? round.toolCalls.at(-1)?.id
124
+ : undefined;
125
+ }
126
+ function resolvedOutput({ context, round, resolved, repeated, deps }) {
87
127
  const { session } = deps;
128
+ const cutId = cutCallId(round);
129
+ const cutTail = CompletionMachine.cutShort(round) && Boolean(round.toolErrors?.length);
88
130
  const history = [
89
131
  ...context.history,
90
132
  {
91
133
  role: 'assistant',
92
134
  content: assistantToolTurn(round.contentText, resolved.map(({ call, args: callArgs }) => ({ name: call.name, arguments: callArgs })))
93
- }
135
+ },
136
+ ...(cutTail ? [cutTailTurn(context, round)] : []),
137
+ ...(repeated ? [repeatedCallTurn(context)] : [])
94
138
  ];
95
139
  return {
96
140
  calls: resolved.map(({ call, tool, args: callArgs, rawCall, intent, rejection, permission }) => ({
@@ -111,7 +155,8 @@ function resolvedOutput({ context, round, resolved, deps }) {
111
155
  : undefined,
112
156
  leavesPlan: context.planMode && tool?.name === Agent.PLAN_TOOL_NAME && callArgs.submit === true
113
157
  ? true
114
- : undefined
158
+ : undefined,
159
+ cutOff: call.id === cutId ? true : undefined
115
160
  })),
116
161
  history: spliceFrom(context.history, history)
117
162
  };
@@ -1,25 +1,34 @@
1
1
  import { AbortedError } from '../../../helpers/race-abort.js';
2
2
  import { isFailureResultReference } from '../../../helpers/failure-result.js';
3
- import { hlog } from '../../../log.js';
3
+ import { HarnessLog } from '../../../log.js';
4
4
  import { errorMessage } from '../../../guards.js';
5
5
  import { spliceFrom } from '../splice.js';
6
- import { knowledgeLastUser } from '../turns.js';
7
- export const retrieving = async function retrieving({ input, context }) {
8
- const { history } = context;
6
+ import { turnText } from '../turns.js';
7
+ export const retrieving = async function retrieving({ input, context, emit }) {
8
+ const { history, edgeInputs } = context;
9
9
  const at = history.findLastIndex((entry) => !isFailureResultReference(entry) && entry.role === 'user');
10
10
  const turn = history[at];
11
- if (!turn || isFailureResultReference(turn)) {
12
- return {};
11
+ const hits = turn && !isFailureResultReference(turn)
12
+ ? await knowledgeSearch(input, {
13
+ id: `${context.runId}:round-${context.round}:input:knowledge`,
14
+ text: turn.content
15
+ })
16
+ : [];
17
+ const excerpts = hits.map((hit) => hit.text);
18
+ for (const [index, queued] of edgeInputs.entries()) {
19
+ const added = index === edgeInputs.length - 1 && excerpts.length ? { excerpts } : {};
20
+ const turnContext = { ...queued.context, ...added };
21
+ if (Object.keys(turnContext).length > 0) {
22
+ emit(queued.id === undefined
23
+ ? { type: 'context', context: turnContext, round: context.round }
24
+ : { type: 'context', id: queued.id, context: turnContext, round: context.round });
25
+ }
13
26
  }
14
- const hits = await knowledgeSearch(input, {
15
- id: `${context.runId}:round-${context.round}:input:knowledge`,
16
- text: turn.content
17
- });
18
- if (hits.length === 0) {
27
+ if (!turn || isFailureResultReference(turn) || hits.length === 0) {
19
28
  return {};
20
29
  }
21
30
  const next = [...history];
22
- next[at] = knowledgeLastUser([turn], hits)[0];
31
+ next[at] = { ...turn, content: turnText(turn.content, { excerpts }) };
23
32
  return {
24
33
  history: spliceFrom(history, next),
25
34
  sources: hits.map((hit) => input.session.outbound.facts('tool-result', hit.text))
@@ -43,7 +52,7 @@ export function knowledgeSearch({ args, services, operations }, { id, text }) {
43
52
  if (args.signal?.aborted || error instanceof AbortedError) {
44
53
  throw error;
45
54
  }
46
- hlog('knowledge search failed', { err: errorMessage(error) });
55
+ HarnessLog.info('knowledge search failed', { err: errorMessage(error) });
47
56
  return [];
48
57
  }
49
58
  };
@@ -1,10 +1,11 @@
1
1
  import { spliceFrom } from '../splice.js';
2
- import { annotateCompletionHistoryLastUserTime, preloadLastUser } from '../turns.js';
2
+ import { annotateCompletionHistoryLastUserTime, directToolHistory, withLastUserNote } from '../turns.js';
3
3
  import { labelOf, skillEmojiFrom } from '../loop.js';
4
- import { withoutSkillLoadTurns } from '../../tool-turns.js';
4
+ import { loadedSkills } from '../session.js';
5
+ import { PRELOAD_ID_PREFIX } from '../../tool-turns.js';
5
6
  import { Agent } from '../../../agent/index.js';
6
7
  import { errorMessage, isRecord } from '../../../guards.js';
7
- const ID_PREFIX = 'preload-';
8
+ import { isFailureResultReference } from '../../../helpers/failure-result.js';
8
9
  export const skillStep = {
9
10
  label: 'Skill loading',
10
11
  propose({ session }, { preload }) {
@@ -12,7 +13,7 @@ export const skillStep = {
12
13
  return null;
13
14
  }
14
15
  return {
15
- id: `${ID_PREFIX}${preload.name}`,
16
+ id: `${PRELOAD_ID_PREFIX}${preload.name}`,
16
17
  tool: Agent.SKILL_TOOL_NAME,
17
18
  args: { name: preload.name },
18
19
  done: session.loadedThisTurn.has(preload.name)
@@ -24,9 +25,7 @@ export const skillStep = {
24
25
  settle({ deps, context, step, result, announce }) {
25
26
  const { session } = deps;
26
27
  const name = skillOf(step);
27
- if (!context.activated.includes(name)) {
28
- announce();
29
- }
28
+ announce();
30
29
  if (!hasContent(result)) {
31
30
  return {
32
31
  failure: fail({
@@ -40,13 +39,18 @@ export const skillStep = {
40
39
  const content = String(result.content);
41
40
  session.loadedThisTurn.add(name);
42
41
  session.skillIcon = skillEmojiFrom(session.inContextSkills, name) ?? session.skillIcon;
43
- const inlined = preloadLastUser(context.history, name, content);
44
- const turns = withoutSkillLoadTurns(inlined, name);
45
- const history = annotateCompletionHistoryLastUserTime(turns, new Date(session.startedAt));
42
+ const typed = withSystem(annotateCompletionHistoryLastUserTime(context.history, new Date(session.startedAt)), session.preloadSystem?.(name));
43
+ session.reselectTools?.(new Set([...loadedSkills(context, session), name]));
44
+ const history = directToolHistory(typed, {
45
+ tool: step.tool,
46
+ id: step.id,
47
+ args: step.args,
48
+ output: result,
49
+ nudge: context.policy.continuationNudge
50
+ });
46
51
  return {
47
52
  history: spliceFrom(context.history, history),
48
53
  source: session.outbound.facts('skill', content),
49
- cacheable: false,
50
54
  activate: name
51
55
  };
52
56
  },
@@ -55,15 +59,21 @@ export const skillStep = {
55
59
  function fail({ deps, context, step, error }) {
56
60
  const { history } = context;
57
61
  const message = `Skill "${skillOf(step)}" could not be loaded: ${error}`;
58
- const guided = preloadLastUser(history, skillOf(step), message);
62
+ const guided = withLastUserNote(history, message);
59
63
  const startedAt = new Date(deps.session.startedAt);
60
64
  return {
61
65
  error: message,
62
66
  history: spliceFrom(history, annotateCompletionHistoryLastUserTime(guided, startedAt))
63
67
  };
64
68
  }
69
+ function withSystem(history, text) {
70
+ const [first, ...rest] = history;
71
+ return text !== undefined && first && !isFailureResultReference(first) && first.role === 'system'
72
+ ? [{ ...first, content: text }, ...rest]
73
+ : history;
74
+ }
65
75
  function skillOf(step) {
66
- return step.id.slice(ID_PREFIX.length);
76
+ return step.id.slice(PRELOAD_ID_PREFIX.length);
67
77
  }
68
78
  function hasContent(value) {
69
79
  return isRecord(value) && 'content' in value;
@@ -1,12 +1,17 @@
1
1
  import type { CompletionEvent, CompletionSdk } from '../../../contract/index.ts';
2
- import { type RecoveredRound, type RoundArgs } from '../round.ts';
2
+ import { type RecoveredRound, type RoundArgs, type RoundKind } from '../round.ts';
3
+ import { type ModelRoundPort } from '../model-round.ts';
4
+ import type { Session } from '../session.ts';
3
5
  interface ForwardStreamOptions<Result> {
4
6
  stream: AsyncGenerator<CompletionEvent, Result> | Generator<CompletionEvent, Result>;
5
7
  emit: (event: CompletionEvent) => void;
6
8
  }
7
9
  interface RunRoundOptions {
8
10
  sdk: CompletionSdk | undefined;
9
- args: RoundArgs;
11
+ modelRound?: ModelRoundPort | undefined;
12
+ kind: RoundKind;
13
+ args: Omit<RoundArgs, 'live' | 'knownTools'>;
14
+ session: Pick<Session, 'liveRound' | 'enabled' | 'runId'>;
10
15
  emit: (event: CompletionEvent) => void;
11
16
  }
12
17
  export interface AssembleAnswerOptions {
@@ -16,6 +21,6 @@ export interface AssembleAnswerOptions {
16
21
  emit: (event: CompletionEvent) => void;
17
22
  }
18
23
  export declare function forwardStream<Result>({ stream, emit }: ForwardStreamOptions<Result>): Promise<Result>;
19
- export declare function runRound({ sdk, args, emit }: RunRoundOptions): Promise<RecoveredRound>;
24
+ export declare function runRound({ sdk, modelRound, kind, args, session, emit }: RunRoundOptions): Promise<RecoveredRound>;
20
25
  export declare function assembleAnswer({ contentText, replay, landed, emit }: AssembleAnswerOptions): Promise<string>;
21
26
  export {};
@@ -1,6 +1,10 @@
1
1
  import { reportUnnamedWrites } from '../loop.js';
2
- import { runRecoveredRound } from '../round.js';
2
+ import { recordWholeRound, runRecoveredRound } from '../round.js';
3
+ import { ModelRound } from '../model-round.js';
3
4
  import { AbortedError } from '../../../helpers/race-abort.js';
5
+ import { HarnessLog } from '../../../log.js';
6
+ const BOUNDARY_UNFLAGGED = "length stop without contextBoundary: the host's @qvac/inference patch lacks the contextBoundary hunk";
7
+ let boundaryUnflaggedLogged = false;
4
8
  export async function forwardStream({ stream, emit }) {
5
9
  try {
6
10
  while (true) {
@@ -15,19 +19,73 @@ export async function forwardStream({ stream, emit }) {
15
19
  await Promise.resolve(stream.return(undefined)).catch(noop);
16
20
  }
17
21
  }
18
- export async function runRound({ sdk, args, emit }) {
22
+ export async function runRound({ sdk, modelRound, kind, args, session, emit }) {
19
23
  if (args.signal?.aborted)
20
24
  throw new AbortedError();
25
+ const live = { round: args.round, kind, startedAt: Date.now(), rawChars: 0, reasoningDeltas: 0 };
26
+ session.liveRound = live;
21
27
  try {
22
- return await forwardStream({ stream: runRecoveredRound(sdk, args), emit });
28
+ const round = modelRound
29
+ ? await remoteRound({
30
+ port: modelRound,
31
+ kind,
32
+ args: { ...args, live },
33
+ runId: session.runId,
34
+ emit
35
+ })
36
+ : await forwardStream({
37
+ stream: runRecoveredRound(sdk, { ...args, live, knownTools: session.enabled }),
38
+ emit
39
+ });
40
+ session.liveRound = null;
41
+ logUnflaggedBoundary(round.final, args.round, kind);
42
+ return round;
23
43
  }
24
44
  catch (error) {
25
45
  if (error instanceof AbortedError || args.signal?.aborted) {
26
46
  throw new AbortedError();
27
47
  }
48
+ session.liveRound = null;
28
49
  throw error;
29
50
  }
30
51
  }
52
+ async function remoteRound({ port, kind, args, runId, emit }) {
53
+ const params = await recordWholeRound(args);
54
+ const result = await ModelRound.run(port, {
55
+ runId,
56
+ round: args.round,
57
+ kind,
58
+ attempt: 0,
59
+ modelId: params.modelId,
60
+ history: params.history,
61
+ tools: params.tools,
62
+ generationParams: params.generationParams,
63
+ responseFormat: params.responseFormat,
64
+ toolDialect: params.toolDialect,
65
+ cacheKey: args.cacheKey,
66
+ promptPrefix: args.promptPrefix,
67
+ continuationNudge: args.continuationNudge,
68
+ deliveredNudge: args.deliveredNudge
69
+ }, { signal: args.signal, emit });
70
+ return {
71
+ contentText: result.contentText,
72
+ final: result.final,
73
+ history: args.history,
74
+ cacheable: true,
75
+ unproven: null,
76
+ replay: null,
77
+ cut: result.cut
78
+ };
79
+ }
80
+ function logUnflaggedBoundary(final, round, kind) {
81
+ if (boundaryUnflaggedLogged || final.stopReason !== 'length')
82
+ return;
83
+ if (final.stats?.contextBoundary !== undefined)
84
+ return;
85
+ boundaryUnflaggedLogged = true;
86
+ const log = HarnessLog.enabled('info') ? HarnessLog.info : HarnessLog.diag;
87
+ log(BOUNDARY_UNFLAGGED, { round, kind });
88
+ }
31
89
  export async function assembleAnswer({ contentText, replay, landed, emit }) {
32
90
  let response = replay || contentText;
33
91
  if (replay) {
@@ -1,3 +1,7 @@
1
- import type { CompletionActor } from '../session.ts';
1
+ import type { CompletionArgs } from '../loop.ts';
2
+ import { type RoundFold } from '../round.ts';
3
+ import { type CompletionActor, type Session } from '../session.ts';
2
4
  import type { RoundDonePayload } from '../stages.ts';
5
+ import { type CompletionContext } from '../../../machine/index.ts';
3
6
  export declare const streaming: CompletionActor<RoundDonePayload>;
7
+ export declare function roundFold(args: CompletionArgs, session: Session, context: CompletionContext): RoundFold;
@@ -1,13 +1,16 @@
1
1
  import { spliceFrom } from '../splice.js';
2
2
  import { carriesRunOnlyText } from '../turns.js';
3
3
  import { runRound } from './stream.js';
4
+ import { foldTokens } from '../round.js';
4
5
  import { truncateAtControlToken } from '../../../helpers/control-tokens.js';
5
6
  import { clipRawCall, recoverMarkupToolCalls, recoverPrintedSkillLoad, recoverSkillNamedCall, stripToolResponseBlocks } from '../../../helpers/tool-call-markup.js';
6
7
  import { unquoteArg } from '../../../helpers/model-args.js';
7
8
  import { Agent } from '../../../agent/index.js';
8
9
  import { loadedTools, unloadedTools } from '../../sdk-tool.js';
9
- import { hlog } from '../../../log.js';
10
+ import { HarnessLog } from '../../../log.js';
10
11
  import { toolDialectFor } from '../../../models/model-catalog.js';
12
+ import { loadedSkills } from '../session.js';
13
+ import { CompletionMachine } from '../../../machine/index.js';
11
14
  export const streaming = async function streaming({ emit, input: { sdk, args, session, operations }, context }) {
12
15
  const { recovered, promptPrefix, thinkingText, durationMs } = await generateStreamingRound({
13
16
  sdk,
@@ -34,10 +37,13 @@ export const streaming = async function streaming({ emit, input: { sdk, args, se
34
37
  stopReason: recovered.final.stopReason,
35
38
  durationMs,
36
39
  ctxSize: recovered.ctxSize,
40
+ overflows: recovered.overflows,
41
+ reasoningDeltas: recovered.reasoningDeltas,
37
42
  promptPrefix,
38
43
  replay: recovered.replay,
39
44
  history: recovered.history ? spliceFrom(context.history, recovered.history) : undefined,
40
- cacheable: recovered.cacheable
45
+ cacheable: recovered.cacheable,
46
+ cut: recovered.cut
41
47
  };
42
48
  };
43
49
  function roundCalls({ recovered, session, context }) {
@@ -45,11 +51,20 @@ function roundCalls({ recovered, session, context }) {
45
51
  const calls = recoverToolCalls({ recovered, session, round: context.round });
46
52
  const callable = calls.filter((call) => !unloaded.has(call.name));
47
53
  const refused = calls.filter((call) => unloaded.has(call.name)).map(notLoaded);
54
+ const toolCalls = identifyToolCalls(callable, session.runId, context.round);
55
+ const sdkErrors = recovered.final.toolErrors ?? [];
56
+ if (!callable.length) {
57
+ return { toolCalls, toolErrors: roundToolErrors([...sdkErrors, ...refused]) };
58
+ }
59
+ const cut = CompletionMachine.cutShort({
60
+ stopReason: recovered.final.stopReason,
61
+ cut: recovered.cut
62
+ });
63
+ const tail = calls.at(-1);
64
+ const unloadedTail = !sdkErrors.length && tail && unloaded.has(tail.name) ? [notLoaded(tail)] : [];
48
65
  return {
49
- toolCalls: identifyToolCalls(callable, session.runId, context.round),
50
- toolErrors: callable.length
51
- ? undefined
52
- : roundToolErrors([...(recovered.final.toolErrors ?? []), ...refused])
66
+ toolCalls,
67
+ toolErrors: cut ? roundToolErrors([...sdkErrors, ...unloadedTail]) : undefined
53
68
  };
54
69
  }
55
70
  function notLoaded(call) {
@@ -69,6 +84,9 @@ async function generateStreamingRound({ sdk, args, session, operations, context,
69
84
  let thinkingText = '';
70
85
  const recovered = await runRound({
71
86
  sdk,
87
+ modelRound: args.modelRound,
88
+ kind: 'streaming',
89
+ session,
72
90
  args: prepared.args,
73
91
  emit: (event) => {
74
92
  if (event.type === 'thinking') {
@@ -85,19 +103,17 @@ async function generateStreamingRound({ sdk, args, session, operations, context,
85
103
  return { recovered, promptPrefix: prepared.promptPrefix, thinkingText, durationMs };
86
104
  }
87
105
  function logRoundStats({ round, durationMs, recovered }) {
88
- hlog('round stats', Object.assign({ round, wallMs: durationMs }, recovered.final.stats));
89
- }
90
- function roundLoadedSkills(context, session) {
91
- return new Set([...context.activated, ...session.loadedThisTurn]);
106
+ HarnessLog.debug('round stats', Object.assign({ round, wallMs: durationMs }, recovered.final.stats));
92
107
  }
93
108
  function prepareStreamingRound({ args, session, operations, context }) {
94
109
  const { modelId, acquireRound, responseFormat, signal } = args;
95
- const cacheKey = carriesRunOnlyText(context.history) ? undefined : (context.cacheKey ?? undefined);
110
+ const cacheKey = !args.replaysContext && carriesRunOnlyText(context.history)
111
+ ? undefined
112
+ : (context.cacheKey ?? undefined);
96
113
  const model = args.model;
97
114
  const toolDialect = model ? toolDialectFor(model) : undefined;
98
- const loadedSkills = roundLoadedSkills(context, session);
99
- const promptPrefix = session.reselectTools?.(loadedSkills) ?? context.promptPrefix;
100
- hlog('round start', {
115
+ const promptPrefix = session.reselectTools?.(loadedSkills(context, session)) ?? context.promptPrefix;
116
+ HarnessLog.debug('round start', {
101
117
  round: context.round,
102
118
  turns: context.history.length,
103
119
  tools: session.sdkTools?.length ?? 0,
@@ -123,17 +139,29 @@ function prepareStreamingRound({ args, session, operations, context }) {
123
139
  promptPrefix,
124
140
  capture: args.captureInferenceCalls === true,
125
141
  recordRequest: operations.recordRequest,
126
- fold: {
127
- messages: args.messages,
128
- nudge: context.policy.continuationNudge,
129
- ctxSize: args.ctxSize,
130
- instructions: (messages) => session.pipeline.preFold({ runId: session.runId, agentId: context.agentId, messages })
131
- }
142
+ fold: roundFold(args, session, context)
132
143
  },
133
144
  promptPrefix,
134
145
  startedAt
135
146
  };
136
147
  }
148
+ export function roundFold(args, session, context) {
149
+ const { lastRound } = context;
150
+ return {
151
+ messages: args.messages,
152
+ nudge: context.policy.continuationNudge,
153
+ ctxSize: args.ctxSize,
154
+ cacheKey: carriesRunOnlyText(context.history) ? undefined : args.cacheKey,
155
+ instructions: (messages) => session.pipeline.preFold({ runId: session.runId, agentId: context.agentId, messages }),
156
+ reading: lastRound
157
+ ? {
158
+ cacheTokens: foldTokens(lastRound.stats, lastRound.cacheable),
159
+ ctxSize: lastRound.ctxSize ?? context.metrics.ctxSize,
160
+ cutOff: CompletionMachine.atContextBoundary(lastRound)
161
+ }
162
+ : undefined
163
+ };
164
+ }
137
165
  function roundGenerationParams(context, session, responseFormat) {
138
166
  const owesCall = context.narrated || (context.malformed && context.lastRound?.stopReason !== 'length');
139
167
  if (!owesCall ||
@@ -175,7 +203,7 @@ function recoverPrintedSkill(markup, session, round) {
175
203
  return [];
176
204
  }
177
205
  if (rescued.length) {
178
- hlog('recovered printed skill load', { round });
206
+ HarnessLog.info('recovered printed skill load', { round });
179
207
  }
180
208
  return rescued;
181
209
  }
@@ -190,7 +218,7 @@ function recoverNamedSkill(markup, session, round) {
190
218
  session.nudgedSkills.add(unquoteArg(call.arguments.name));
191
219
  }
192
220
  if (calls.length) {
193
- hlog('recovered skill-named call', { round });
221
+ HarnessLog.info('recovered skill-named call', { round });
194
222
  }
195
223
  return calls;
196
224
  }
@@ -1,5 +1,6 @@
1
1
  import type { CompletionActor } from '../session.ts';
2
2
  import type { RoundDonePayload } from '../stages.ts';
3
+ export declare const WRAP_UP_PREDICT = 4096;
3
4
  interface WrapUpOutput extends RoundDonePayload {
4
5
  response: string;
5
6
  }
@@ -1,18 +1,26 @@
1
1
  import { spliceFrom } from '../splice.js';
2
2
  import { carriesRunOnlyText } from '../turns.js';
3
3
  import { runRound } from './stream.js';
4
+ import { roundFold } from './streaming.js';
4
5
  import { degenerateAnswer } from '../../../helpers/run-outcome.js';
5
6
  import { stripToolCallMarkup } from '../../../helpers/tool-call-markup.js';
6
7
  import { promptPrefixHash } from '../../prompt-prefix.js';
7
8
  import { materializeCompletionHistory } from '../../tool-turns.js';
9
+ import { CompletionMachine } from '../../../machine/index.js';
8
10
  import { isFailureResultReference } from '../../../helpers/failure-result.js';
11
+ export const WRAP_UP_PREDICT = 4096;
9
12
  export const wrapUp = async function wrapUp({ emit, input: { sdk, args, session, operations }, context }) {
10
13
  const { modelId, acquireRound, signal } = args;
11
- const cacheKey = carriesRunOnlyText(context.history) ? undefined : (context.cacheKey ?? undefined);
14
+ const cacheKey = !args.replaysContext && carriesRunOnlyText(context.history)
15
+ ? undefined
16
+ : (context.cacheKey ?? undefined);
12
17
  const promptPrefix = promptPrefixHash({ system: systemMessage(context), tools: undefined });
13
18
  const startedAt = Date.now();
14
19
  const recovered = await runRound({
15
20
  sdk,
21
+ modelRound: args.modelRound,
22
+ kind: 'wrap-up',
23
+ session,
16
24
  args: {
17
25
  modelId,
18
26
  acquireRound,
@@ -21,21 +29,32 @@ export const wrapUp = async function wrapUp({ emit, input: { sdk, args, session,
21
29
  continuationNudge: context.policy.continuationNudge,
22
30
  deliveredNudge: context.policy.deliveredNudge,
23
31
  tools: undefined,
24
- generationParams: session.generationParams,
32
+ generationParams: wrapUpParams(session.generationParams),
25
33
  cacheKey,
26
34
  signal,
27
35
  round: context.roundsSent,
28
36
  promptPrefix,
29
37
  capture: args.captureInferenceCalls === true,
30
- recordRequest: operations.recordRequest
38
+ recordRequest: operations.recordRequest,
39
+ fold: roundFold(args, session, context)
31
40
  },
32
41
  emit
33
42
  });
34
43
  const durationMs = Date.now() - startedAt;
35
- const replay = recovered.replay ? stripToolCallMarkup(recovered.replay) : '';
44
+ const cutOff = CompletionMachine.atContextBoundary(recovered.final);
45
+ const replay = !cutOff && recovered.replay?.trim() ? stripToolCallMarkup(recovered.replay) : '';
46
+ const contentText = !cutOff && recovered.contentText.trim() ? recovered.contentText : '';
47
+ if (cutOff) {
48
+ emit({
49
+ type: 'round-reset',
50
+ runId: session.runId,
51
+ round: context.roundsSent,
52
+ replacedTypes: ['content', 'thinking']
53
+ });
54
+ }
36
55
  const fallbackResponse = degenerateAnswer(wrapOutcome(context), materializeCompletionHistory(context.history, context.failureResults), { ...previewFinishedRound(session.runOutcomes.snapshot()), delivered: context.delivered });
37
56
  return {
38
- contentText: recovered.contentText,
57
+ contentText,
39
58
  thinkingText: '',
40
59
  promptPrefix,
41
60
  toolCalls: [],
@@ -43,12 +62,20 @@ export const wrapUp = async function wrapUp({ emit, input: { sdk, args, session,
43
62
  stopReason: recovered.final.stopReason,
44
63
  durationMs,
45
64
  ctxSize: recovered.ctxSize,
65
+ overflows: recovered.overflows,
66
+ reasoningDeltas: recovered.reasoningDeltas,
46
67
  replay,
47
68
  history: recovered.history ? spliceFrom(context.history, recovered.history) : undefined,
48
69
  cacheable: recovered.cacheable,
49
- response: replay || recovered.contentText || fallbackResponse
70
+ response: replay || contentText || fallbackResponse
50
71
  };
51
72
  };
73
+ function wrapUpParams(params) {
74
+ if (!params)
75
+ return undefined;
76
+ const reasoning = Math.max(params.reasoning_budget ?? 0, 0);
77
+ return { predict: reasoning + WRAP_UP_PREDICT, ...params };
78
+ }
52
79
  function previewFinishedRound(state) {
53
80
  return {
54
81
  latestFailure: state.hasRoundResult ? state.roundFailure : state.latestFailure,