@qvac/harness 1.0.0-rc.2 → 1.0.0-rc.21

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 (688) hide show
  1. package/.nvmrc +1 -0
  2. package/CHANGELOG.md +3073 -1485
  3. package/README.md +110 -46
  4. package/dist-lib/index.d.ts +63 -16
  5. package/dist-lib/index.js +232 -38
  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 +11 -2
  10. package/dist-lib/lib/agent/resolve.js +30 -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 +2 -0
  14. package/dist-lib/lib/agent/tools.js +2 -1
  15. package/dist-lib/lib/capabilities/agent-ports.d.ts +1 -1
  16. package/dist-lib/lib/capabilities/agent-ports.js +11 -4
  17. package/dist-lib/lib/capabilities/completion-engine/actors/answering.js +2 -2
  18. package/dist-lib/lib/capabilities/completion-engine/actors/batching.js +1 -0
  19. package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +2 -0
  20. package/dist-lib/lib/capabilities/completion-engine/actors/execute.d.ts +1 -1
  21. package/dist-lib/lib/capabilities/completion-engine/actors/executing.d.ts +2 -1
  22. package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +132 -13
  23. package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +11 -5
  24. package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.js +3 -2
  25. package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.d.ts +1 -1
  26. package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +54 -10
  27. package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.d.ts +1 -1
  28. package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +12 -2
  29. package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +142 -50
  30. package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +10 -4
  31. package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +78 -20
  32. package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.d.ts +2 -1
  33. package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +33 -16
  34. package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +38 -23
  35. package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +50 -12
  36. package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +10 -4
  37. package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +80 -3
  38. package/dist-lib/lib/capabilities/completion-engine/actors/streaming.d.ts +5 -1
  39. package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +101 -41
  40. package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +2 -1
  41. package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +56 -17
  42. package/dist-lib/lib/capabilities/completion-engine/driver.js +58 -15
  43. package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +3 -1
  44. package/dist-lib/lib/capabilities/completion-engine/durable.js +12 -2
  45. package/dist-lib/lib/capabilities/completion-engine/engine.d.ts +4 -1
  46. package/dist-lib/lib/capabilities/completion-engine/engine.js +14 -1
  47. package/dist-lib/lib/capabilities/completion-engine/index.d.ts +5 -1
  48. package/dist-lib/lib/capabilities/completion-engine/index.js +5 -2
  49. package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +26 -3
  50. package/dist-lib/lib/capabilities/completion-engine/loop.js +14 -2
  51. package/dist-lib/lib/capabilities/completion-engine/metrics.d.ts +9 -2
  52. package/dist-lib/lib/capabilities/completion-engine/metrics.js +28 -7
  53. package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +63 -0
  54. package/dist-lib/lib/capabilities/completion-engine/model-round.js +99 -0
  55. package/dist-lib/lib/capabilities/completion-engine/operations.js +30 -10
  56. package/dist-lib/lib/capabilities/completion-engine/ports.js +6 -9
  57. package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +4 -1
  58. package/dist-lib/lib/capabilities/completion-engine/round.d.ts +38 -6
  59. package/dist-lib/lib/capabilities/completion-engine/round.js +395 -118
  60. package/dist-lib/lib/capabilities/completion-engine/session.d.ts +12 -4
  61. package/dist-lib/lib/capabilities/completion-engine/session.js +31 -2
  62. package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +5 -2
  63. package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +8 -43
  64. package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +32 -141
  65. package/dist-lib/lib/capabilities/completion-engine/tool-outcome.d.ts +4 -0
  66. package/dist-lib/lib/capabilities/completion-engine/tool-outcome.js +42 -0
  67. package/dist-lib/lib/capabilities/completion-engine/tool-preflight.d.ts +43 -0
  68. package/dist-lib/lib/capabilities/completion-engine/tool-preflight.js +91 -0
  69. package/dist-lib/lib/capabilities/completion-engine/tool-sets.d.ts +24 -0
  70. package/dist-lib/lib/capabilities/completion-engine/tool-sets.js +15 -0
  71. package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +17 -9
  72. package/dist-lib/lib/capabilities/completion-engine/turns.js +98 -86
  73. package/dist-lib/lib/capabilities/detect-language.d.ts +2 -1
  74. package/dist-lib/lib/capabilities/detect-language.js +14 -2
  75. package/dist-lib/lib/capabilities/download.d.ts +10 -8
  76. package/dist-lib/lib/capabilities/download.js +1 -1
  77. package/dist-lib/lib/capabilities/enhance.d.ts +1 -1
  78. package/dist-lib/lib/capabilities/enhance.js +23 -11
  79. package/dist-lib/lib/capabilities/kv-cache.d.ts +1 -1
  80. package/dist-lib/lib/capabilities/preview-model-source.d.ts +7 -0
  81. package/dist-lib/lib/capabilities/preview-model-source.js +83 -23
  82. package/dist-lib/lib/capabilities/prompt-prefix.d.ts +3 -1
  83. package/dist-lib/lib/capabilities/prompt-prefix.js +8 -0
  84. package/dist-lib/lib/capabilities/sdk-tool.d.ts +13 -4
  85. package/dist-lib/lib/capabilities/sdk-tool.js +59 -7
  86. package/dist-lib/lib/capabilities/skill-entry.d.ts +13 -1
  87. package/dist-lib/lib/capabilities/skill-entry.js +33 -2
  88. package/dist-lib/lib/capabilities/tool-failed-note.d.ts +1 -0
  89. package/dist-lib/lib/capabilities/tool-failed-note.js +1 -0
  90. package/dist-lib/lib/capabilities/tool-plan.d.ts +5 -1
  91. package/dist-lib/lib/capabilities/tool-plan.js +20 -5
  92. package/dist-lib/lib/capabilities/tool-prompt-log.d.ts +1 -1
  93. package/dist-lib/lib/capabilities/tool-prompt-log.js +3 -3
  94. package/dist-lib/lib/capabilities/tool-turns/attachments.d.ts +7 -0
  95. package/dist-lib/lib/capabilities/tool-turns/attachments.js +39 -0
  96. package/dist-lib/lib/capabilities/tool-turns/copy.d.ts +13 -0
  97. package/dist-lib/lib/capabilities/tool-turns/copy.js +29 -0
  98. package/dist-lib/lib/capabilities/tool-turns/result-turn.d.ts +22 -0
  99. package/dist-lib/lib/capabilities/tool-turns/result-turn.js +120 -0
  100. package/dist-lib/lib/capabilities/tool-turns/run-limits.d.ts +6 -0
  101. package/dist-lib/lib/capabilities/tool-turns/run-limits.js +32 -0
  102. package/dist-lib/lib/capabilities/tool-turns/skill-loads.d.ts +9 -0
  103. package/dist-lib/lib/capabilities/tool-turns/skill-loads.js +71 -0
  104. package/dist-lib/lib/capabilities/tool-turns.d.ts +8 -43
  105. package/dist-lib/lib/capabilities/tool-turns.js +6 -253
  106. package/dist-lib/lib/capabilities/usage-breakdown.d.ts +1 -0
  107. package/dist-lib/lib/capabilities/usage-breakdown.js +4 -1
  108. package/dist-lib/lib/client/index.d.ts +19 -0
  109. package/dist-lib/lib/client/index.js +263 -0
  110. package/dist-lib/lib/connect/abort.d.ts +6 -0
  111. package/dist-lib/lib/connect/abort.js +52 -0
  112. package/dist-lib/lib/connect/bridges.d.ts +21 -0
  113. package/dist-lib/lib/connect/bridges.js +185 -0
  114. package/dist-lib/lib/connect/decode.d.ts +31 -0
  115. package/dist-lib/lib/connect/decode.js +114 -0
  116. package/dist-lib/lib/connect/host-run-log.d.ts +16 -0
  117. package/dist-lib/lib/connect/host-run-log.js +74 -0
  118. package/dist-lib/lib/connect/served.d.ts +7 -0
  119. package/dist-lib/lib/connect/served.js +45 -0
  120. package/dist-lib/lib/connect.d.ts +20 -11
  121. package/dist-lib/lib/connect.js +178 -415
  122. package/dist-lib/lib/context-window.d.ts +13 -5
  123. package/dist-lib/lib/context-window.js +19 -6
  124. package/dist-lib/lib/contract/agent.d.ts +25 -4
  125. package/dist-lib/lib/contract/completion.d.ts +82 -32
  126. package/dist-lib/lib/contract/drive.d.ts +130 -0
  127. package/dist-lib/lib/contract/drive.js +1 -0
  128. package/dist-lib/lib/contract/egress-proxy.d.ts +13 -0
  129. package/dist-lib/lib/contract/egress-proxy.js +1 -0
  130. package/dist-lib/lib/contract/exec.d.ts +4 -3
  131. package/dist-lib/lib/contract/hooks.d.ts +4 -1
  132. package/dist-lib/lib/contract/index.d.ts +4 -0
  133. package/dist-lib/lib/contract/knowledge.d.ts +10 -0
  134. package/dist-lib/lib/contract/managed-skills.d.ts +1 -0
  135. package/dist-lib/lib/contract/managed-skills.js +1 -0
  136. package/dist-lib/lib/contract/media.d.ts +58 -0
  137. package/dist-lib/lib/contract/media.js +1 -0
  138. package/dist-lib/lib/contract/models.d.ts +12 -6
  139. package/dist-lib/lib/contract/ocr.d.ts +17 -0
  140. package/dist-lib/lib/contract/ocr.js +1 -0
  141. package/dist-lib/lib/contract/policy.d.ts +75 -0
  142. package/dist-lib/lib/contract/policy.js +1 -0
  143. package/dist-lib/lib/contract/run.d.ts +28 -3
  144. package/dist-lib/lib/contract/sandbox.d.ts +3 -1
  145. package/dist-lib/lib/contract/speech.d.ts +1 -1
  146. package/dist-lib/lib/contract/translation.d.ts +20 -0
  147. package/dist-lib/lib/contract/translation.js +1 -0
  148. package/dist-lib/lib/contract-types.d.ts +48 -16
  149. package/dist-lib/lib/embeddings/index.d.ts +7 -1
  150. package/dist-lib/lib/embeddings/index.js +26 -5
  151. package/dist-lib/lib/errors.d.ts +278 -0
  152. package/dist-lib/lib/errors.js +212 -0
  153. package/dist-lib/lib/fold/index.d.ts +26 -1
  154. package/dist-lib/lib/fold/index.js +76 -9
  155. package/dist-lib/lib/guarded-fetch.js +11 -7
  156. package/dist-lib/lib/guards.d.ts +2 -0
  157. package/dist-lib/lib/guards.js +7 -0
  158. package/dist-lib/lib/hardware/capability-probe.js +10 -7
  159. package/dist-lib/lib/hardware/cpu-placement.d.ts +8 -0
  160. package/dist-lib/lib/hardware/cpu-placement.js +48 -0
  161. package/dist-lib/lib/hardware/gpu-probe-addon.js +26 -11
  162. package/dist-lib/lib/hardware/gpu-probe.js +10 -1
  163. package/dist-lib/lib/hardware/gpu-stats.native.cjs +17 -1
  164. package/dist-lib/lib/helpers/completion-params.d.ts +7 -2
  165. package/dist-lib/lib/helpers/completion-params.js +26 -2
  166. package/dist-lib/lib/helpers/control-tokens.d.ts +3 -0
  167. package/dist-lib/lib/helpers/control-tokens.js +25 -0
  168. package/dist-lib/lib/helpers/engine-error.d.ts +2 -1
  169. package/dist-lib/lib/helpers/engine-error.js +12 -12
  170. package/dist-lib/lib/helpers/goal-check/asks.d.ts +25 -0
  171. package/dist-lib/lib/helpers/goal-check/asks.js +52 -0
  172. package/dist-lib/lib/helpers/goal-check/checks.d.ts +8 -0
  173. package/dist-lib/lib/helpers/goal-check/checks.js +92 -0
  174. package/dist-lib/lib/helpers/goal-check/commands.d.ts +7 -0
  175. package/dist-lib/lib/helpers/goal-check/commands.js +130 -0
  176. package/dist-lib/lib/helpers/goal-check/paths.d.ts +5 -0
  177. package/dist-lib/lib/helpers/goal-check/paths.js +44 -0
  178. package/dist-lib/lib/helpers/goal-check/shell.d.ts +9 -0
  179. package/dist-lib/lib/helpers/goal-check/shell.js +96 -0
  180. package/dist-lib/lib/helpers/goal-check.d.ts +36 -0
  181. package/dist-lib/lib/helpers/goal-check.js +35 -0
  182. package/dist-lib/lib/helpers/head-tail.js +1 -1
  183. package/dist-lib/lib/helpers/html-helpers.js +9 -6
  184. package/dist-lib/lib/helpers/load-stall.d.ts +1 -1
  185. package/dist-lib/lib/helpers/load-stall.js +2 -2
  186. package/dist-lib/lib/helpers/markup-stream-filter.d.ts +4 -1
  187. package/dist-lib/lib/helpers/markup-stream-filter.js +20 -6
  188. package/dist-lib/lib/helpers/recent-map.d.ts +7 -0
  189. package/dist-lib/lib/helpers/recent-map.js +23 -0
  190. package/dist-lib/lib/helpers/repeated-reply.js +24 -16
  191. package/dist-lib/lib/helpers/require-peers.d.ts +3 -0
  192. package/dist-lib/lib/helpers/require-peers.js +23 -0
  193. package/dist-lib/lib/helpers/run-outcome.d.ts +2 -0
  194. package/dist-lib/lib/helpers/run-outcome.js +6 -2
  195. package/dist-lib/lib/helpers/spawn-path.d.ts +1 -0
  196. package/dist-lib/lib/helpers/spawn-path.js +2 -1
  197. package/dist-lib/lib/helpers/thinking.d.ts +3 -2
  198. package/dist-lib/lib/helpers/thinking.js +19 -0
  199. package/dist-lib/lib/helpers/tool-call-markup/emit.d.ts +6 -0
  200. package/dist-lib/lib/helpers/tool-call-markup/emit.js +15 -0
  201. package/dist-lib/lib/helpers/tool-call-markup/recover.d.ts +22 -0
  202. package/dist-lib/lib/helpers/tool-call-markup/recover.js +130 -0
  203. package/dist-lib/lib/helpers/tool-call-markup/skill-recovery.d.ts +3 -0
  204. package/dist-lib/lib/helpers/tool-call-markup/skill-recovery.js +56 -0
  205. package/dist-lib/lib/helpers/tool-call-markup/strip.d.ts +4 -0
  206. package/dist-lib/lib/helpers/tool-call-markup/strip.js +149 -0
  207. package/dist-lib/lib/helpers/tool-call-markup.d.ts +19 -24
  208. package/dist-lib/lib/helpers/tool-call-markup.js +17 -343
  209. package/dist-lib/lib/hooks/built-in/arg-repair.js +6 -2
  210. package/dist-lib/lib/hooks/built-in/policy-rules.d.ts +8 -0
  211. package/dist-lib/lib/hooks/built-in/policy-rules.js +192 -0
  212. package/dist-lib/lib/hooks/built-in/sandbox.js +23 -5
  213. package/dist-lib/lib/hooks/index.d.ts +4 -1
  214. package/dist-lib/lib/hooks/index.js +9 -4
  215. package/dist-lib/lib/hooks/run.js +3 -3
  216. package/dist-lib/lib/lifecycle/index.js +15 -14
  217. package/dist-lib/lib/lifecycle/machine.js +2 -2
  218. package/dist-lib/lib/log.d.ts +26 -5
  219. package/dist-lib/lib/log.js +86 -23
  220. package/dist-lib/lib/machine/completion/actions/completion.d.ts +15 -16
  221. package/dist-lib/lib/machine/completion/actions/completion.js +164 -107
  222. package/dist-lib/lib/machine/completion/actions/goal.d.ts +10 -0
  223. package/dist-lib/lib/machine/completion/actions/goal.js +93 -0
  224. package/dist-lib/lib/machine/completion/actions/prepare.js +3 -2
  225. package/dist-lib/lib/machine/completion/actions/reject-tool.d.ts +16 -0
  226. package/dist-lib/lib/machine/completion/actions/reject-tool.js +147 -0
  227. package/dist-lib/lib/machine/completion/actions/retry-round.d.ts +6 -0
  228. package/dist-lib/lib/machine/completion/actions/retry-round.js +50 -0
  229. package/dist-lib/lib/machine/completion/actions/rounds.d.ts +5 -0
  230. package/dist-lib/lib/machine/completion/actions/rounds.js +31 -0
  231. package/dist-lib/lib/machine/completion/actions/tools.d.ts +1 -16
  232. package/dist-lib/lib/machine/completion/actions/tools.js +111 -140
  233. package/dist-lib/lib/machine/completion/context.js +11 -1
  234. package/dist-lib/lib/machine/completion/guards/retry.d.ts +3 -1
  235. package/dist-lib/lib/machine/completion/guards/retry.js +9 -2
  236. package/dist-lib/lib/machine/completion/implementations.d.ts +18 -9
  237. package/dist-lib/lib/machine/completion/implementations.js +64 -16
  238. package/dist-lib/lib/machine/completion/machine.d.ts +38 -9
  239. package/dist-lib/lib/machine/completion/machine.js +58 -9
  240. package/dist-lib/lib/machine/completion/metrics.d.ts +25 -0
  241. package/dist-lib/lib/machine/completion/metrics.js +68 -0
  242. package/dist-lib/lib/machine/completion/nudges.d.ts +5 -0
  243. package/dist-lib/lib/machine/completion/nudges.js +33 -0
  244. package/dist-lib/lib/machine/completion/rules.d.ts +19 -27
  245. package/dist-lib/lib/machine/completion/rules.js +48 -79
  246. package/dist-lib/lib/machine/completion/splice.d.ts +9 -0
  247. package/dist-lib/lib/machine/completion/splice.js +19 -0
  248. package/dist-lib/lib/machine/completion/types.d.ts +81 -14
  249. package/dist-lib/lib/machine/index.d.ts +50 -11
  250. package/dist-lib/lib/machine/index.js +12 -2
  251. package/dist-lib/lib/media-host.d.ts +12 -0
  252. package/dist-lib/lib/media-host.js +52 -0
  253. package/dist-lib/lib/media-port.d.ts +20 -0
  254. package/dist-lib/lib/media-port.js +77 -0
  255. package/dist-lib/lib/media-wire.d.ts +8 -0
  256. package/dist-lib/lib/media-wire.js +111 -0
  257. package/dist-lib/lib/models/context-choice.d.ts +15 -0
  258. package/dist-lib/lib/models/context-choice.js +62 -0
  259. package/dist-lib/lib/models/context.d.ts +1 -1
  260. package/dist-lib/lib/models/custom-model-cache.d.ts +1 -0
  261. package/dist-lib/lib/models/custom-model-cache.js +3 -0
  262. package/dist-lib/lib/models/download-gate.d.ts +20 -0
  263. package/dist-lib/lib/models/download-gate.js +73 -0
  264. package/dist-lib/lib/models/gguf-header.d.ts +11 -0
  265. package/dist-lib/lib/models/gguf-header.js +203 -15
  266. package/dist-lib/lib/models/gpu-selection.d.ts +6 -1
  267. package/dist-lib/lib/models/gpu-selection.js +29 -5
  268. package/dist-lib/lib/models/kv-cache.d.ts +2 -0
  269. package/dist-lib/lib/models/kv-cache.js +8 -0
  270. package/dist-lib/lib/models/llm-presets.d.ts +6 -1
  271. package/dist-lib/lib/models/llm-presets.js +33 -6
  272. package/dist-lib/lib/models/load-requests.d.ts +9 -0
  273. package/dist-lib/lib/models/load-requests.js +42 -0
  274. package/dist-lib/lib/models/memory-cap.d.ts +13 -0
  275. package/dist-lib/lib/models/memory-cap.js +21 -0
  276. package/dist-lib/lib/models/model-catalog-constants.d.ts +2 -2
  277. package/dist-lib/lib/models/model-catalog-constants.js +3 -4
  278. package/dist-lib/lib/models/model-catalog.d.ts +7 -3
  279. package/dist-lib/lib/models/model-catalog.js +44 -11
  280. package/dist-lib/lib/models/model-delete.d.ts +1 -1
  281. package/dist-lib/lib/models/model-fit.d.ts +2 -2
  282. package/dist-lib/lib/models/model-fit.js +5 -6
  283. package/dist-lib/lib/models/model-handle.d.ts +9 -2
  284. package/dist-lib/lib/models/model-handle.js +14 -3
  285. package/dist-lib/lib/models/model-list.d.ts +9 -2
  286. package/dist-lib/lib/models/model-list.js +23 -0
  287. package/dist-lib/lib/models/model-pool.d.ts +42 -7
  288. package/dist-lib/lib/models/model-pool.js +139 -49
  289. package/dist-lib/lib/models/model-source.d.ts +3 -2
  290. package/dist-lib/lib/models/model-source.js +23 -5
  291. package/dist-lib/lib/models/opencl-cache.js +2 -2
  292. package/dist-lib/lib/models/sdk-faults.d.ts +1 -0
  293. package/dist-lib/lib/models/sdk-faults.js +9 -0
  294. package/dist-lib/lib/models/tool-dialect.d.ts +1 -1
  295. package/dist-lib/lib/models/tts-model-default.d.ts +2 -1
  296. package/dist-lib/lib/models/tts-model-default.js +8 -6
  297. package/dist-lib/lib/no-redirect-fetch-bare.js +2 -1
  298. package/dist-lib/lib/no-redirect-fetch-impl.d.ts +2 -1
  299. package/dist-lib/lib/no-redirect-fetch-impl.js +46 -8
  300. package/dist-lib/lib/office/engine/pptx/picture-area.d.ts +23 -0
  301. package/dist-lib/lib/office/engine/pptx/picture-area.js +84 -0
  302. package/dist-lib/lib/office/engine/pptx/presentation.d.ts +2 -0
  303. package/dist-lib/lib/office/engine/pptx/presentation.js +64 -21
  304. package/dist-lib/lib/office/engine/pptx/types.d.ts +1 -0
  305. package/dist-lib/lib/office/engine/xlsx/sheet.js +10 -4
  306. package/dist-lib/lib/office/engine/xlsx/workbook.d.ts +1 -0
  307. package/dist-lib/lib/office/engine/xlsx/workbook.js +34 -3
  308. package/dist-lib/lib/office/extract.js +4 -3
  309. package/dist-lib/lib/office/index.js +2 -1
  310. package/dist-lib/lib/plugins/registry.d.ts +15 -0
  311. package/dist-lib/lib/plugins/registry.js +91 -22
  312. package/dist-lib/lib/plugins/require-bare.d.ts +1 -0
  313. package/dist-lib/lib/plugins/require-bare.js +13 -0
  314. package/dist-lib/lib/policy/index.d.ts +11 -0
  315. package/dist-lib/lib/policy/index.js +235 -0
  316. package/dist-lib/lib/prompt.d.ts +9 -4
  317. package/dist-lib/lib/prompt.js +95 -32
  318. package/dist-lib/lib/residency/completion-runtime.d.ts +17 -6
  319. package/dist-lib/lib/residency/completion-runtime.js +91 -37
  320. package/dist-lib/lib/residency/index.d.ts +59 -6
  321. package/dist-lib/lib/residency/index.js +444 -42
  322. package/dist-lib/lib/resolution-detector.js +3 -3
  323. package/dist-lib/lib/round-host.d.ts +12 -0
  324. package/dist-lib/lib/round-host.js +57 -0
  325. package/dist-lib/lib/round-port.d.ts +24 -0
  326. package/dist-lib/lib/round-port.js +81 -0
  327. package/dist-lib/lib/rpc-session.js +2 -1
  328. package/dist-lib/lib/run-log/redact.js +7 -7
  329. package/dist-lib/lib/run-log/request-codec.js +2 -2
  330. package/dist-lib/lib/sdk-loader.d.ts +1 -1
  331. package/dist-lib/lib/sdk-loader.js +47 -17
  332. package/dist-lib/lib/sdk-storage.d.ts +1 -0
  333. package/dist-lib/lib/sdk-storage.js +18 -2
  334. package/dist-lib/lib/serve/completion.d.ts +7 -0
  335. package/dist-lib/lib/serve/completion.js +553 -0
  336. package/dist-lib/lib/serve/downloads.d.ts +4 -0
  337. package/dist-lib/lib/serve/downloads.js +79 -0
  338. package/dist-lib/lib/serve/models.d.ts +5 -0
  339. package/dist-lib/lib/serve/models.js +120 -0
  340. package/dist-lib/lib/serve/noop.d.ts +1 -0
  341. package/dist-lib/lib/serve/noop.js +1 -0
  342. package/dist-lib/lib/serve/requests.d.ts +147 -0
  343. package/dist-lib/lib/serve/requests.js +1 -0
  344. package/dist-lib/lib/serve/rounds.d.ts +11 -0
  345. package/dist-lib/lib/serve/rounds.js +67 -0
  346. package/dist-lib/lib/serve/run-log-start.d.ts +38 -0
  347. package/dist-lib/lib/serve/run-log-start.js +254 -0
  348. package/dist-lib/lib/serve/skills.d.ts +32 -0
  349. package/dist-lib/lib/serve/skills.js +46 -0
  350. package/dist-lib/lib/serve.d.ts +5 -1
  351. package/dist-lib/lib/serve.js +51 -916
  352. package/dist-lib/lib/sidecar/index.d.ts +39 -0
  353. package/dist-lib/lib/sidecar/index.js +205 -0
  354. package/dist-lib/lib/sidecar/user-plugins.d.ts +9 -0
  355. package/dist-lib/lib/sidecar/user-plugins.js +119 -0
  356. package/dist-lib/lib/skills-host/index.d.ts +7 -3
  357. package/dist-lib/lib/skills-host/index.js +47 -22
  358. package/dist-lib/lib/spawn.d.ts +6 -4
  359. package/dist-lib/lib/spawn.js +22 -20
  360. package/dist-lib/lib/spill.d.ts +1 -0
  361. package/dist-lib/lib/spill.js +12 -8
  362. package/dist-lib/lib/tools/ask-user.d.ts +2 -0
  363. package/dist-lib/lib/tools/ask-user.js +137 -0
  364. package/dist-lib/lib/tools/attachments/delivered.d.ts +5 -0
  365. package/dist-lib/lib/tools/attachments/delivered.js +16 -0
  366. package/dist-lib/lib/tools/attachments/fetched-file.d.ts +32 -0
  367. package/dist-lib/lib/tools/attachments/fetched-file.js +134 -0
  368. package/dist-lib/lib/tools/attachments/staging.d.ts +1 -0
  369. package/dist-lib/lib/tools/attachments/staging.js +19 -8
  370. package/dist-lib/lib/tools/exec/runner.d.ts +4 -0
  371. package/dist-lib/lib/tools/exec/runner.js +20 -2
  372. package/dist-lib/lib/tools/exec/scope.d.ts +0 -1
  373. package/dist-lib/lib/tools/exec/scope.js +23 -114
  374. package/dist-lib/lib/tools/exec/shell-guidance.js +4 -4
  375. package/dist-lib/lib/tools/exec/shell-line.d.ts +26 -0
  376. package/dist-lib/lib/tools/exec/shell-line.js +334 -0
  377. package/dist-lib/lib/tools/exec.d.ts +4 -1
  378. package/dist-lib/lib/tools/exec.js +89 -27
  379. package/dist-lib/lib/tools/files/edit-file.d.ts +6 -0
  380. package/dist-lib/lib/tools/files/edit-file.js +266 -0
  381. package/dist-lib/lib/tools/files/glob.d.ts +3 -0
  382. package/dist-lib/lib/tools/files/glob.js +65 -0
  383. package/dist-lib/lib/tools/files/grep.d.ts +6 -0
  384. package/dist-lib/lib/tools/files/grep.js +212 -0
  385. package/dist-lib/lib/tools/files/index.d.ts +3 -0
  386. package/dist-lib/lib/tools/files/index.js +25 -0
  387. package/dist-lib/lib/tools/files/list-dir.d.ts +6 -0
  388. package/dist-lib/lib/tools/files/list-dir.js +136 -0
  389. package/dist-lib/lib/tools/files/make-dir.d.ts +3 -0
  390. package/dist-lib/lib/tools/files/make-dir.js +48 -0
  391. package/dist-lib/lib/tools/files/read-file.d.ts +3 -0
  392. package/dist-lib/lib/tools/files/read-file.js +224 -0
  393. package/dist-lib/lib/tools/files/transfer.d.ts +4 -0
  394. package/dist-lib/lib/tools/files/transfer.js +83 -0
  395. package/dist-lib/lib/tools/files/trash-file.d.ts +4 -0
  396. package/dist-lib/lib/tools/files/trash-file.js +62 -0
  397. package/dist-lib/lib/tools/files/write-file.d.ts +3 -0
  398. package/dist-lib/lib/tools/files/write-file.js +56 -0
  399. package/dist-lib/lib/tools/fs/document-text.d.ts +8 -0
  400. package/dist-lib/lib/tools/fs/document-text.js +22 -0
  401. package/dist-lib/lib/tools/fs/drive.d.ts +5 -25
  402. package/dist-lib/lib/tools/fs/drive.js +9 -1
  403. package/dist-lib/lib/tools/fs/edit-match.d.ts +33 -0
  404. package/dist-lib/lib/tools/fs/edit-match.js +445 -0
  405. package/dist-lib/lib/tools/fs/ignore.d.ts +13 -0
  406. package/dist-lib/lib/tools/fs/ignore.js +104 -0
  407. package/dist-lib/lib/tools/fs/local.js +28 -5
  408. package/dist-lib/lib/tools/fs/remote-protocol.d.ts +2 -40
  409. package/dist-lib/lib/tools/fs/remote-protocol.js +1 -1
  410. package/dist-lib/lib/tools/fs/remote.d.ts +3 -11
  411. package/dist-lib/lib/tools/fs/remote.js +24 -14
  412. package/dist-lib/lib/tools/fs/scope.d.ts +4 -15
  413. package/dist-lib/lib/tools/fs/scope.js +5 -2
  414. package/dist-lib/lib/tools/fs/search.d.ts +25 -0
  415. package/dist-lib/lib/tools/fs/search.js +383 -0
  416. package/dist-lib/lib/tools/{file-glob.d.ts → fs/targets.d.ts} +1 -5
  417. package/dist-lib/lib/tools/fs/targets.js +32 -0
  418. package/dist-lib/lib/tools/fs/tool-path.d.ts +27 -0
  419. package/dist-lib/lib/tools/fs/tool-path.js +70 -0
  420. package/dist-lib/lib/tools/fs/walk.d.ts +14 -5
  421. package/dist-lib/lib/tools/fs/walk.js +119 -24
  422. package/dist-lib/lib/tools/http-request/request.d.ts +4 -2
  423. package/dist-lib/lib/tools/http-request/request.js +2 -1
  424. package/dist-lib/lib/tools/http-request/truncate-response.d.ts +16 -1
  425. package/dist-lib/lib/tools/http-request/truncate-response.js +56 -11
  426. package/dist-lib/lib/tools/http-request.d.ts +1 -0
  427. package/dist-lib/lib/tools/http-request.js +101 -16
  428. package/dist-lib/lib/tools/index.d.ts +4 -1
  429. package/dist-lib/lib/tools/index.js +8 -12
  430. package/dist-lib/lib/tools/office/ops.d.ts +1 -0
  431. package/dist-lib/lib/tools/office/ops.js +5 -1
  432. package/dist-lib/lib/tools/office.d.ts +2 -1
  433. package/dist-lib/lib/tools/office.js +273 -56
  434. package/dist-lib/lib/tools/operations/builders.d.ts +4 -3
  435. package/dist-lib/lib/tools/operations/builders.js +41 -3
  436. package/dist-lib/lib/tools/operations/calendar-range.d.ts +16 -0
  437. package/dist-lib/lib/tools/operations/calendar-range.js +40 -0
  438. package/dist-lib/lib/tools/operations/compile.js +8 -6
  439. package/dist-lib/lib/tools/operations/manifest.d.ts +4 -0
  440. package/dist-lib/lib/tools/pdf/build.d.ts +17 -3
  441. package/dist-lib/lib/tools/pdf/build.js +77 -16
  442. package/dist-lib/lib/tools/pdf/pages.d.ts +12 -0
  443. package/dist-lib/lib/tools/pdf/pages.js +31 -0
  444. package/dist-lib/lib/tools/pdf/recognize.d.ts +13 -0
  445. package/dist-lib/lib/tools/pdf/recognize.js +55 -0
  446. package/dist-lib/lib/tools/pdf/request.d.ts +3 -8
  447. package/dist-lib/lib/tools/pdf/request.js +4 -4
  448. package/dist-lib/lib/tools/pdf.d.ts +0 -1
  449. package/dist-lib/lib/tools/pdf.js +56 -13
  450. package/dist-lib/lib/tools/skill.js +23 -11
  451. package/dist-lib/lib/tools/skills/bundled-dir.d.ts +8 -1
  452. package/dist-lib/lib/tools/skills/bundled-dir.js +42 -36
  453. package/dist-lib/lib/tools/skills/bundled-hash.d.ts +1 -0
  454. package/dist-lib/lib/tools/skills/bundled-hash.js +4 -1
  455. package/dist-lib/lib/tools/skills/catalog-loader.d.ts +12 -0
  456. package/dist-lib/lib/tools/skills/catalog-loader.js +173 -0
  457. package/dist-lib/lib/tools/skills/catalog.d.ts +7 -8
  458. package/dist-lib/lib/tools/skills/catalog.js +1 -158
  459. package/dist-lib/lib/tools/skills/cli-argv.js +25 -5
  460. package/dist-lib/lib/tools/skills/cli-schema-check.d.ts +1 -0
  461. package/dist-lib/lib/tools/skills/cli-schema-check.js +3 -0
  462. package/dist-lib/lib/tools/skills/cli-schema-load.js +10 -0
  463. package/dist-lib/lib/tools/skills/cli-schema-types.d.ts +2 -0
  464. package/dist-lib/lib/tools/skills/cli-schema.js +6 -3
  465. package/dist-lib/lib/tools/skills/credential-check.d.ts +1 -0
  466. package/dist-lib/lib/tools/skills/credential-check.js +3 -0
  467. package/dist-lib/lib/tools/skills/credential-health.js +3 -3
  468. package/dist-lib/lib/tools/skills/frontmatter-parser.d.ts +3 -0
  469. package/dist-lib/lib/tools/skills/frontmatter-parser.js +5 -0
  470. package/dist-lib/lib/tools/skills/index.d.ts +1 -0
  471. package/dist-lib/lib/tools/skills/index.js +1 -0
  472. package/dist-lib/lib/tools/skills/manifest-parse.d.ts +1 -0
  473. package/dist-lib/lib/tools/skills/manifest-parse.js +39 -3
  474. package/dist-lib/lib/tools/skills/manifest.d.ts +1 -0
  475. package/dist-lib/lib/tools/skills/mention-name.d.ts +6 -0
  476. package/dist-lib/lib/tools/skills/mention-name.js +6 -0
  477. package/dist-lib/lib/tools/skills/mention.d.ts +2 -2
  478. package/dist-lib/lib/tools/skills/mention.js +11 -4
  479. package/dist-lib/lib/tools/skills/overlay-crud.d.ts +3 -3
  480. package/dist-lib/lib/tools/skills/overlay-crud.js +7 -6
  481. package/dist-lib/lib/tools/skills/overlay-watch.d.ts +2 -2
  482. package/dist-lib/lib/tools/skills/overlay-watch.js +4 -3
  483. package/dist-lib/lib/tools/skills/scope-key.d.ts +1 -0
  484. package/dist-lib/lib/tools/skills/scope-key.js +4 -0
  485. package/dist-lib/lib/tools/skills/skill-state-constants.d.ts +1 -0
  486. package/dist-lib/lib/tools/skills/skill-state-constants.js +4 -0
  487. package/dist-lib/lib/tools/skills/skill-tree.d.ts +5 -0
  488. package/dist-lib/lib/tools/skills/skill-tree.js +54 -0
  489. package/dist-lib/lib/tools/url-guard.d.ts +6 -1
  490. package/dist-lib/lib/tools/url-guard.js +8 -2
  491. package/dist-lib/lib/tools/web-fetch.js +50 -133
  492. package/dist-lib/lib/wire/download.d.ts +10 -0
  493. package/dist-lib/lib/wire/download.js +35 -0
  494. package/dist-lib/lib/wire/event.d.ts +41 -0
  495. package/dist-lib/lib/wire/event.js +306 -0
  496. package/dist-lib/lib/wire/fields.d.ts +3 -0
  497. package/dist-lib/lib/wire/fields.js +12 -0
  498. package/dist-lib/lib/wire/knowledge.d.ts +9 -0
  499. package/dist-lib/lib/wire/knowledge.js +68 -0
  500. package/dist-lib/lib/wire/round.d.ts +14 -0
  501. package/dist-lib/lib/wire/round.js +45 -0
  502. package/dist-lib/lib/wire/vectors.d.ts +6 -0
  503. package/dist-lib/lib/wire/vectors.js +33 -0
  504. package/dist-lib/lib/wire.d.ts +28 -64
  505. package/dist-lib/lib/wire.js +24 -417
  506. package/dist-lib/plugins/coding/index.d.ts +1 -1
  507. package/dist-lib/plugins/coding/index.js +2 -4
  508. package/dist-lib/plugins/coding/read-only.d.ts +1 -0
  509. package/dist-lib/plugins/coding/read-only.js +264 -0
  510. package/dist-lib/plugins/coding/session.d.ts +6 -4
  511. package/dist-lib/plugins/coding/session.js +45 -16
  512. package/dist-lib/plugins/coding-guards/index.d.ts +25 -0
  513. package/dist-lib/plugins/coding-guards/index.js +126 -0
  514. package/dist-lib/plugins/command-hooks/index.js +5 -3
  515. package/dist-lib/plugins/egress-proxy/index.d.ts +53 -0
  516. package/dist-lib/plugins/egress-proxy/index.js +184 -0
  517. package/dist-lib/plugins/image/edit-image.d.ts +3 -22
  518. package/dist-lib/plugins/image/edit-image.js +23 -46
  519. package/dist-lib/plugins/image/fit.d.ts +31 -0
  520. package/dist-lib/plugins/image/fit.js +28 -0
  521. package/dist-lib/plugins/image/generate-image.d.ts +27 -6
  522. package/dist-lib/plugins/image/generate-image.js +201 -74
  523. package/dist-lib/plugins/image/index.d.ts +2 -1
  524. package/dist-lib/plugins/image/index.js +29 -12
  525. package/dist-lib/plugins/knowledge/index.d.ts +3 -0
  526. package/dist-lib/plugins/knowledge/index.js +5 -0
  527. package/dist-lib/plugins/knowledge/manifest.d.ts +53 -0
  528. package/dist-lib/plugins/knowledge/manifest.js +86 -0
  529. package/dist-lib/plugins/knowledge/search-tool.js +8 -8
  530. package/dist-lib/plugins/knowledge/store.d.ts +45 -8
  531. package/dist-lib/plugins/knowledge/store.js +428 -166
  532. package/dist-lib/plugins/language-hint/index.d.ts +15 -0
  533. package/dist-lib/plugins/language-hint/index.js +54 -0
  534. package/dist-lib/plugins/lsp/tool.js +2 -2
  535. package/dist-lib/plugins/mcp/call.js +15 -4
  536. package/dist-lib/plugins/mcp/index.js +6 -3
  537. package/dist-lib/plugins/mcp/protocol.d.ts +10 -2
  538. package/dist-lib/plugins/mcp/protocol.js +13 -12
  539. package/dist-lib/plugins/mcp/server.js +1 -1
  540. package/dist-lib/plugins/mcp/tool-listing.d.ts +6 -0
  541. package/dist-lib/plugins/mcp/tool-listing.js +97 -0
  542. package/dist-lib/plugins/music/generate-music.d.ts +24 -5
  543. package/dist-lib/plugins/music/generate-music.js +170 -64
  544. package/dist-lib/plugins/music/index.d.ts +2 -1
  545. package/dist-lib/plugins/music/index.js +23 -11
  546. package/dist-lib/plugins/obsidian/command.js +2 -2
  547. package/dist-lib/plugins/obsidian/index.js +14 -4
  548. package/dist-lib/plugins/obsidian/note-name.js +2 -1
  549. package/dist-lib/plugins/obsidian/readiness.js +2 -2
  550. package/dist-lib/plugins/obsidian/safe-path.js +5 -4
  551. package/dist-lib/plugins/obsidian/vault-create.js +3 -2
  552. package/dist-lib/plugins/obsidian/vault-fs.js +2 -2
  553. package/dist-lib/plugins/obsidian/vault-paths.js +3 -2
  554. package/dist-lib/plugins/obsidian/vault-read.js +20 -18
  555. package/dist-lib/plugins/obsidian/vault-write.js +13 -12
  556. package/dist-lib/plugins/ocr/bmp.d.ts +2 -0
  557. package/dist-lib/plugins/ocr/bmp.js +27 -0
  558. package/dist-lib/plugins/ocr/coverage.d.ts +3 -0
  559. package/dist-lib/plugins/ocr/coverage.js +67 -0
  560. package/dist-lib/plugins/ocr/index.d.ts +12 -0
  561. package/dist-lib/plugins/ocr/index.js +20 -0
  562. package/dist-lib/plugins/ocr/ocr-runtime.d.ts +25 -0
  563. package/dist-lib/plugins/ocr/ocr-runtime.js +103 -0
  564. package/dist-lib/plugins/ocr/reading-order.d.ts +5 -0
  565. package/dist-lib/plugins/ocr/reading-order.js +218 -0
  566. package/dist-lib/plugins/python/bare-floor.d.ts +1 -0
  567. package/dist-lib/plugins/python/bare-floor.js +2 -0
  568. package/dist-lib/plugins/python/guarded-fetch.d.ts +2 -1
  569. package/dist-lib/plugins/python/guarded-fetch.js +5 -1
  570. package/dist-lib/plugins/python/index.d.ts +4 -1
  571. package/dist-lib/plugins/python/index.js +6 -1
  572. package/dist-lib/plugins/python/interrupt-timer.js +2 -2
  573. package/dist-lib/plugins/python/language.js +11 -10
  574. package/dist-lib/plugins/python/loader.d.ts +1 -0
  575. package/dist-lib/plugins/python/loader.js +76 -3
  576. package/dist-lib/plugins/python/memfs.js +2 -2
  577. package/dist-lib/plugins/python/pyodide.d.ts +1 -0
  578. package/dist-lib/plugins/python/pyodide.js +9 -8
  579. package/dist-lib/plugins/python/python-adapter.d.ts +6 -1
  580. package/dist-lib/plugins/python/python-adapter.js +37 -2
  581. package/dist-lib/plugins/python/run-session.d.ts +1 -0
  582. package/dist-lib/plugins/python/run-session.js +19 -8
  583. package/dist-lib/plugins/python/wheels.js +8 -6
  584. package/dist-lib/plugins/python/worker/active.js +2 -2
  585. package/dist-lib/plugins/python/worker/client.js +10 -9
  586. package/dist-lib/plugins/python/worker/entry.js +2 -8
  587. package/dist-lib/plugins/python/worker/preload.d.ts +1 -0
  588. package/dist-lib/plugins/python/worker/preload.js +2 -0
  589. package/dist-lib/plugins/python/worker/protocol.d.ts +2 -0
  590. package/dist-lib/plugins/python/worker/serve.js +23 -4
  591. package/dist-lib/plugins/python/worker/spawn.d.ts +2 -1
  592. package/dist-lib/plugins/python/worker/spawn.js +3 -2
  593. package/dist-lib/plugins/quickjs/index.js +4 -0
  594. package/dist-lib/plugins/quickjs/runtime.js +8 -3
  595. package/dist-lib/plugins/run-report/chain.d.ts +2 -0
  596. package/dist-lib/plugins/run-report/chain.js +73 -0
  597. package/dist-lib/plugins/run-report/flow-view.js +2 -1
  598. package/dist-lib/plugins/run-report/flow.d.ts +1 -1
  599. package/dist-lib/plugins/run-report/flow.js +66 -14
  600. package/dist-lib/plugins/run-report/index.d.ts +23 -2
  601. package/dist-lib/plugins/run-report/index.js +32 -13
  602. package/dist-lib/plugins/run-report/layout.js +1 -1
  603. package/dist-lib/plugins/run-report/model.d.ts +10 -1
  604. package/dist-lib/plugins/run-report/model.js +12 -6
  605. package/dist-lib/plugins/run-report/page.d.ts +9 -0
  606. package/dist-lib/plugins/run-report/page.js +55 -15
  607. package/dist-lib/plugins/run-report/script.js +317 -43
  608. package/dist-lib/plugins/run-report/story.d.ts +2 -1
  609. package/dist-lib/plugins/run-report/story.js +7 -4
  610. package/dist-lib/plugins/run-report/style.d.ts +1 -1
  611. package/dist-lib/plugins/run-report/style.js +126 -0
  612. package/dist-lib/plugins/run-report/why.js +1 -1
  613. package/dist-lib/plugins/sandbox-linux/index.d.ts +62 -0
  614. package/dist-lib/plugins/sandbox-linux/index.js +354 -0
  615. package/dist-lib/plugins/sandbox-linux/seccomp.d.ts +2 -0
  616. package/dist-lib/plugins/sandbox-linux/seccomp.js +74 -0
  617. package/dist-lib/plugins/sandbox-macos/index.d.ts +25 -11
  618. package/dist-lib/plugins/sandbox-macos/index.js +244 -49
  619. package/dist-lib/plugins/sandbox-vm/index.d.ts +2 -1
  620. package/dist-lib/plugins/sandbox-vm/index.js +5 -2
  621. package/dist-lib/plugins/sandbox-vm/vm-shell.d.ts +7 -3
  622. package/dist-lib/plugins/sandbox-vm/vm-shell.js +54 -20
  623. package/dist-lib/plugins/sandbox-windows/helper/qvac-sandbox.c +554 -0
  624. package/dist-lib/plugins/sandbox-windows/index.d.ts +53 -0
  625. package/dist-lib/plugins/sandbox-windows/index.js +205 -0
  626. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  627. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  628. package/dist-lib/plugins/speech/audio-resample.d.ts +1 -1
  629. package/dist-lib/plugins/speech/audio-resample.js +8 -8
  630. package/dist-lib/plugins/speech/audio-transcode-bare.d.ts +1 -1
  631. package/dist-lib/plugins/speech/audio-transcode-bare.js +23 -26
  632. package/dist-lib/plugins/speech/audio-transcode-node.d.ts +1 -1
  633. package/dist-lib/plugins/speech/audio-transcode-node.js +1 -3
  634. package/dist-lib/plugins/speech/index.d.ts +1 -0
  635. package/dist-lib/plugins/speech/index.js +8 -1
  636. package/dist-lib/plugins/speech/speech-engine.d.ts +1 -1
  637. package/dist-lib/plugins/speech/speech-engine.js +10 -5
  638. package/dist-lib/plugins/speech/speech-runtime.js +37 -37
  639. package/dist-lib/plugins/speech/speech-text.d.ts +1 -0
  640. package/dist-lib/plugins/speech/speech-text.js +9 -4
  641. package/dist-lib/plugins/speech/voice.d.ts +5 -1
  642. package/dist-lib/plugins/speech/voice.js +107 -33
  643. package/dist-lib/plugins/translation/index.d.ts +2 -1
  644. package/dist-lib/plugins/translation/index.js +21 -10
  645. package/dist-lib/plugins/translation/translate.d.ts +9 -5
  646. package/dist-lib/plugins/translation/translate.js +69 -64
  647. package/dist-lib/plugins/walkie-talkie/index.d.ts +4 -2
  648. package/dist-lib/plugins/walkie-talkie/index.js +19 -6
  649. package/dist-lib/plugins/walkie-talkie/wire.d.ts +5 -0
  650. package/dist-lib/plugins/walkie-talkie/wire.js +6 -5
  651. package/dist-lib/plugins/weather/geocode.js +2 -1
  652. package/dist-lib/plugins/weather/lookup.js +6 -4
  653. package/dist-lib/plugins/web-search/engines/bing.js +2 -1
  654. package/dist-lib/plugins/web-search/engines/google.js +2 -1
  655. package/dist-lib/plugins/web-search/fetch-html.d.ts +5 -5
  656. package/dist-lib/plugins/web-search/fetch-html.js +12 -15
  657. package/dist-lib/plugins/web-search/tool.js +1 -0
  658. package/dist-lib/schema/generate.js +8 -1
  659. package/dist-lib/schema/harness.js +94 -12
  660. package/dist-lib/spec/bind.js +12 -0
  661. package/dist-lib/spec/calls.js +4 -0
  662. package/dist-lib/spec/hrpc/hrpc.json +55 -3
  663. package/dist-lib/spec/hrpc/index.js +58 -10
  664. package/dist-lib/spec/hrpc/messages.js +485 -209
  665. package/dist-lib/spec/hyperschema/index.js +485 -209
  666. package/dist-lib/spec/hyperschema/schema.json +290 -85
  667. package/dist-lib/spec/hyperschema/types.d.ts +42 -5
  668. package/package.json +265 -65
  669. package/patches/pyodide@314.0.2.patch +37 -8
  670. package/scripts/addon-externals.cjs +16 -5
  671. package/worker/harness-sidecar.mjs +23 -154
  672. package/dist-lib/lib/tools/create-documents.d.ts +0 -3
  673. package/dist-lib/lib/tools/create-documents.js +0 -95
  674. package/dist-lib/lib/tools/edit-documents.d.ts +0 -3
  675. package/dist-lib/lib/tools/edit-documents.js +0 -132
  676. package/dist-lib/lib/tools/exec/shell-argv.d.ts +0 -2
  677. package/dist-lib/lib/tools/exec/shell-argv.js +0 -61
  678. package/dist-lib/lib/tools/file-glob.js +0 -118
  679. package/dist-lib/lib/tools/grep.d.ts +0 -5
  680. package/dist-lib/lib/tools/grep.js +0 -184
  681. package/dist-lib/lib/tools/read-files.d.ts +0 -5
  682. package/dist-lib/lib/tools/read-files.js +0 -160
  683. package/dist-lib/plugins/coding/write-file.d.ts +0 -3
  684. package/dist-lib/plugins/coding/write-file.js +0 -52
  685. package/patches/@qvac%2Finference@0.21.0.patch +0 -67
  686. package/patches/bare-stow@0.1.5.patch +0 -68
  687. package/patches/hypercore-blob-server@1.15.0.patch +0 -15
  688. package/patches/localwatch@1.4.3.patch +0 -13
@@ -1,24 +1,30 @@
1
- import { compactedFrom, contextCandidates } from '../../context-window.js';
1
+ import { ContextWindow } from '../../context-window.js';
2
+ import { Agent } from '../../agent/index.js';
3
+ import { HarnessError } from '../../errors.js';
2
4
  import { bufferBurst } from '../../helpers/buffer-burst.js';
3
5
  import { endsTurn, stopAtControlToken } from '../../helpers/control-tokens.js';
4
6
  import { createMarkupStreamFilter } from '../../helpers/markup-stream-filter.js';
5
7
  import { AbortedError, raceAbort } from '../../helpers/race-abort.js';
6
8
  import { raceTimeout } from '../../helpers/race-timeout.js';
7
9
  import { withoutRepeatedReply } from '../../helpers/repeated-reply.js';
8
- import { splitThinking } from '../../helpers/thinking.js';
9
- import { errorMessage, isRecord } from '../../guards.js';
10
- import { hlog } from '../../log.js';
11
- import { isContextOverflowError, isForcedCallFault, isSdkModelWedgedError, isToolGrammarFault } from '../../models/sdk-faults.js';
10
+ import { ToolCallMarkup } from '../../helpers/tool-call-markup.js';
11
+ import { splitThinking, tapThinking } from '../../helpers/thinking.js';
12
+ import { errorMessage } from '../../guards.js';
13
+ import { HarnessLog } from '../../log.js';
14
+ import { isContextOverflowError, isForcedCallFault, isKvCacheSaveFault, isSdkModelWedgedError, isToolGrammarFault } from '../../models/sdk-faults.js';
12
15
  import { copy } from '../../helpers/copy.js';
13
16
  import { stableStringify } from '../../helpers/stable-stringify.js';
14
17
  import { detachJson } from '../../helpers/detach-json.js';
15
- import { materializeCompletionHistory } from '../tool-turns.js';
18
+ import { isSkillMentionNudge, materializeCompletionHistory } from '../tool-turns.js';
16
19
  import { completionParams } from '../../helpers/completion-params.js';
20
+ import { requestPromptPrefix } from '../prompt-prefix.js';
21
+ import { renderedTools } from '../sdk-tool.js';
17
22
  import { isFailureResultReference } from '../../helpers/failure-result.js';
23
+ import { GoalCheck } from '../../helpers/goal-check.js';
18
24
  import { Fold } from '../../fold/index.js';
25
+ import { CompletionMachine } from '../../machine/index.js';
19
26
  import { modelTurns } from './turns.js';
20
27
  const BURST_WINDOW_MS = 100;
21
- export const CONTEXT_OVERFLOW_MESSAGE = 'This message is too large for the model context window.';
22
28
  const noop = () => { };
23
29
  function unprovenReplay(state, final) {
24
30
  if (!state.unproven)
@@ -26,7 +32,10 @@ function unprovenReplay(state, final) {
26
32
  if (state.stopToken) {
27
33
  return endsTurn(state.stopToken) ? state.unproven : null;
28
34
  }
29
- if (final.stopReason === 'length' || final.stopReason === 'cancelled') {
35
+ if (state.runaway ||
36
+ state.cut !== null ||
37
+ final.stopReason === 'length' ||
38
+ final.stopReason === 'cancelled') {
30
39
  return null;
31
40
  }
32
41
  return state.unproven;
@@ -42,15 +51,39 @@ function cancelOnce(sdk, requestId) {
42
51
  };
43
52
  return Object.assign(cancel, { flush: () => pending });
44
53
  }
45
- async function* runRoundTokens({ result, state, cancelThisRound, signal, startInThink }) {
54
+ async function* contentDeltas(events) {
55
+ for await (const event of events) {
56
+ if (event.type === 'contentDelta') {
57
+ yield event.text;
58
+ }
59
+ }
60
+ }
61
+ async function* countGenerated(tokens, state) {
62
+ for await (const token of tokens) {
63
+ state.live.rawChars += token.length;
64
+ yield token;
65
+ }
66
+ }
67
+ async function* runRoundTokens({ result, state, cancelThisRound, unsettled, signal, startInThink, knownTools }) {
46
68
  signal?.addEventListener('abort', cancelThisRound, { once: true });
47
- const tokens = stopAtControlToken(result.tokenStream, (token) => {
69
+ armCut(state, cancelThisRound);
70
+ const closeCalls = watchToolCalls(result.toolCallStream, state, cancelThisRound);
71
+ const tokens = stopAtControlToken(contentDeltas(result.events), (token) => {
48
72
  state.stopToken = token;
49
73
  });
74
+ const counted = tapThinking(tokens, { startInThink }, () => {
75
+ state.live.reasoningDeltas = ++state.reasoningDeltas;
76
+ });
50
77
  let tokenEvents = 0;
51
- const events = splitThinking(bufferBurst(tokens, BURST_WINDOW_MS), { startInThink });
52
- const thinkingFilter = createMarkupStreamFilter();
53
- const contentFilter = createMarkupStreamFilter();
78
+ const events = splitThinking(bufferBurst(countGenerated(counted, state), BURST_WINDOW_MS), {
79
+ startInThink
80
+ });
81
+ const thinkingFilter = createMarkupStreamFilter({
82
+ onToolCall: watchMarkupCalls(state, knownTools, cancelThisRound)
83
+ });
84
+ const contentFilter = createMarkupStreamFilter({
85
+ onToolCall: watchMarkupCalls(state, knownTools, cancelThisRound)
86
+ });
54
87
  try {
55
88
  tokenEvents = yield* processRoundTokenEvents({
56
89
  events,
@@ -60,7 +93,7 @@ async function* runRoundTokens({ result, state, cancelThisRound, signal, startIn
60
93
  thinkingFilter,
61
94
  contentFilter
62
95
  });
63
- hlog('stream ended', { events: tokenEvents, stopToken: state.stopToken });
96
+ HarnessLog.info('stream ended', { events: tokenEvents, stopToken: state.stopToken });
64
97
  if (state.stopToken) {
65
98
  cancelThisRound();
66
99
  }
@@ -70,22 +103,97 @@ async function* runRoundTokens({ result, state, cancelThisRound, signal, startIn
70
103
  cancelThisRound();
71
104
  }
72
105
  signal?.removeEventListener('abort', cancelThisRound);
73
- await events.return(null);
106
+ state.live.cut = undefined;
107
+ closeCalls();
108
+ const closed = events.return(null);
109
+ if (signal?.aborted) {
110
+ unsettled.push(closed.catch(noop));
111
+ }
112
+ else {
113
+ await closed;
114
+ }
74
115
  }
75
116
  }
117
+ function armCut(state, cancelThisRound) {
118
+ if (state.live.kind !== 'streaming')
119
+ return;
120
+ state.live.cut = (note) => {
121
+ if (state.cut !== null)
122
+ return;
123
+ state.cut = note;
124
+ HarnessLog.info('round cut by the host', { round: state.live.round });
125
+ cancelThisRound();
126
+ };
127
+ }
128
+ function tripsCap(state, seen, call) {
129
+ state.calls.push(call);
130
+ return tripsCount(seen, stableStringify([call.name, call.arguments]), state.calls.length);
131
+ }
132
+ function tripsCount(seen, key, total) {
133
+ const count = (seen.get(key) ?? 0) + 1;
134
+ seen.set(key, count);
135
+ return count >= CompletionMachine.MAX_ROUND_REPEATS || total >= CompletionMachine.MAX_ROUND_CALLS;
136
+ }
137
+ function watchMarkupCalls(state, knownTools, cancelThisRound) {
138
+ const seen = new Map();
139
+ let blocks = 0;
140
+ return (body) => {
141
+ if (state.runaway)
142
+ return;
143
+ blocks++;
144
+ const parsed = ToolCallMarkup.recoverMarkupToolCalls(body, knownTools).map((call) => [
145
+ call.name,
146
+ call.arguments
147
+ ]);
148
+ const key = parsed.length ? stableStringify(parsed) : body.trim();
149
+ if (tripsCount(seen, key, blocks)) {
150
+ state.runaway = true;
151
+ HarnessLog.info('round stopped on its tool markup', { blocks });
152
+ cancelThisRound();
153
+ }
154
+ };
155
+ }
156
+ function watchToolCalls(stream, state, cancelThisRound) {
157
+ if (!stream)
158
+ return noop;
159
+ const calls = stream[Symbol.asyncIterator]();
160
+ const seen = new Map();
161
+ let closed = false;
162
+ const close = () => {
163
+ if (closed)
164
+ return;
165
+ closed = true;
166
+ Promise.resolve(calls.return?.()).catch(noop);
167
+ };
168
+ const drain = async () => {
169
+ let next = await calls.next();
170
+ while (!next.done && !closed) {
171
+ if (tripsCap(state, seen, next.value.call)) {
172
+ state.runaway = true;
173
+ HarnessLog.info('round stopped on its tool calls', { calls: state.calls.length });
174
+ cancelThisRound();
175
+ close();
176
+ return;
177
+ }
178
+ next = await calls.next();
179
+ }
180
+ };
181
+ drain().catch(noop);
182
+ return close;
183
+ }
76
184
  async function* processRoundTokenEvents({ events, state, cancelThisRound, signal, thinkingFilter, contentFilter }) {
77
185
  let tokenEvents = 0;
78
186
  while (true) {
79
- const next = await events.next();
187
+ if (signal?.aborted) {
188
+ cancelThisRound();
189
+ throw new AbortedError();
190
+ }
191
+ const next = await raceAbort(events.next(), signal);
80
192
  if (next.done) {
81
193
  state.unproven = next.value;
82
194
  yield* flushFilterTails(thinkingFilter, contentFilter);
83
195
  break;
84
196
  }
85
- if (signal?.aborted) {
86
- cancelThisRound();
87
- throw new AbortedError();
88
- }
89
197
  tokenEvents++;
90
198
  if (next.value.type === 'content') {
91
199
  state.rawContentText += next.value.text;
@@ -108,16 +216,36 @@ async function* flushFilterTails(thinkingFilter, contentFilter) {
108
216
  yield { type: 'content', text: contentTail };
109
217
  }
110
218
  }
111
- function sentMessages(stats) {
112
- if (!stats || !('sentMessages' in stats) || !Array.isArray(stats.sentMessages)) {
219
+ export function foldTokens(stats, cacheable) {
220
+ if (cacheable !== false)
221
+ return stats?.cacheTokens;
222
+ if (stats?.promptTokens === undefined)
113
223
  return undefined;
114
- }
115
- if (!stats.sentMessages.every(isMessage))
224
+ return stats.promptTokens + (stats.generatedTokens ?? 0);
225
+ }
226
+ function slotStats(stats, previous) {
227
+ if (!stats)
116
228
  return undefined;
117
- return detachJson(stats.sentMessages);
229
+ const { cacheTokens: _summed, promptTokensPerSecond: _scheduler, ...own } = stats;
230
+ const { promptTokens, timeToFirstToken } = stats;
231
+ const rest = promptTokens !== undefined &&
232
+ promptTokens > 0 &&
233
+ timeToFirstToken !== undefined &&
234
+ timeToFirstToken > 0
235
+ ? { ...own, promptTokensPerSecond: (promptTokens / timeToFirstToken) * 1000 }
236
+ : own;
237
+ if (previous === undefined || promptTokens === undefined) {
238
+ return rest;
239
+ }
240
+ return { ...rest, cacheTokens: previous + promptTokens + (stats.generatedTokens ?? 0) };
118
241
  }
119
- function isMessage(value) {
120
- return isRecord(value) && typeof value.role === 'string' && typeof value.content === 'string';
242
+ function boundaryStats(final, predict) {
243
+ const stats = copy(final.stats);
244
+ if (final.stopReason !== 'length' || stats?.contextBoundary !== undefined) {
245
+ return stats;
246
+ }
247
+ const capped = predict !== undefined && predict > 0 && (stats?.generatedTokens ?? 0) >= predict;
248
+ return { ...stats, contextBoundary: !capped };
121
249
  }
122
250
  function roundTokens(stats) {
123
251
  if (!stats)
@@ -143,67 +271,106 @@ function truncatedFinal(final, contentText) {
143
271
  }
144
272
  export async function* runRecoveredRound(sdk, args) {
145
273
  const lease = args.acquireRound ? await args.acquireRound(args.signal) : null;
274
+ const unsettled = [];
146
275
  try {
147
276
  const roundSdk = lease?.sdk ?? sdk;
148
277
  if (!roundSdk) {
149
278
  throw new Error('A completion round requires an SDK');
150
279
  }
151
280
  const ctxSize = lease?.ctxSize ?? args.fold?.ctxSize;
281
+ const slotted = (lease?.slots ?? 1) > 1;
282
+ const attempts = { sent: 0, uncached: false, overflows: 0, unsettled };
152
283
  const round = yield* runRecoveredRoundWith({
153
284
  sdk: roundSdk,
154
- args,
285
+ args: lease?.canThink === undefined ? args : { ...args, canThink: lease.canThink },
155
286
  modelId: lease?.modelId ?? args.modelId,
156
287
  ctxSize,
157
- attempts: { sent: 0 }
288
+ attempts
158
289
  });
159
- if (args.fold && args.cacheKey && round.cacheable) {
160
- Fold.observe(args.cacheKey, { cacheTokens: round.final.stats?.cacheTokens, ctxSize });
290
+ const final = slotted
291
+ ? {
292
+ ...round.final,
293
+ stats: slotStats(round.final.stats, round.cacheable !== false && args.cacheKey
294
+ ? (Fold.reading(args.cacheKey)?.cacheTokens ?? 0)
295
+ : undefined)
296
+ }
297
+ : round.final;
298
+ if (args.fold?.cacheKey) {
299
+ Fold.observe(args.fold.cacheKey, {
300
+ cacheTokens: foldTokens(final.stats, round.cacheable),
301
+ ctxSize
302
+ });
161
303
  }
162
- return { ...round, ctxSize: lease?.ctxSize };
304
+ const overflows = attempts.overflows ? { overflows: attempts.overflows } : {};
305
+ return { ...round, final, ctxSize: lease?.ctxSize, ...overflows };
163
306
  }
164
307
  finally {
165
- try {
166
- lease?.release();
308
+ if (lease && unsettled.length) {
309
+ void Promise.all(unsettled).then(() => releaseLease(lease));
167
310
  }
168
- catch (error) {
169
- hlog('completion round lease release failed', { error: errorMessage(error) });
311
+ else if (lease) {
312
+ releaseLease(lease);
170
313
  }
171
314
  }
172
315
  }
316
+ function releaseLease(lease) {
317
+ try {
318
+ lease.release();
319
+ }
320
+ catch (error) {
321
+ HarnessLog.info('completion round lease release failed', { error: errorMessage(error) });
322
+ }
323
+ }
324
+ export async function recordWholeRound(args) {
325
+ const history = materializeCompletionHistory(args.history, args.failureResults);
326
+ const origins = historyOrigins(args.history, history);
327
+ const params = inferenceParams({ args, modelId: args.modelId, history });
328
+ await args.recordRequest?.({ round: args.round, attempt: 0, droppedTurns: 0, params }, failureTurns(args, origins, history));
329
+ if (args.signal?.aborted) {
330
+ throw new AbortedError();
331
+ }
332
+ return params;
333
+ }
173
334
  async function* runRecoveredRoundWith(send) {
174
335
  const { args } = send;
175
336
  let history = materializeCompletionHistory(args.history, args.failureResults);
176
337
  const origins = historyOrigins(args.history, history);
177
- const reading = args.round === 0 && args.cacheKey ? Fold.reading(args.cacheKey) : undefined;
178
- if (reading && Fold.due(reading)) {
179
- history = (yield* foldHistory(send, history)) ?? history;
338
+ const reading = args.fold?.reading ??
339
+ (args.round === 0 && args.fold?.cacheKey ? Fold.reading(args.fold.cacheKey) : undefined);
340
+ const fold = { chat: false, rounds: false };
341
+ if (reading && Fold.due({ ...reading, ctxSize: reading.ctxSize ?? send.ctxSize })) {
342
+ history = (yield* foldHistory(send, history, fold)) ?? history;
180
343
  }
181
- const fold = { tried: false };
182
344
  while (true) {
183
345
  const outcome = yield* runLadder({ send, history, origins, fold });
184
346
  if ('round' in outcome) {
185
347
  return outcome.round;
186
348
  }
187
349
  if (!('folded' in outcome)) {
188
- throw errorWithCause(CONTEXT_OVERFLOW_MESSAGE, outcome.overflow);
350
+ throw new HarnessError('CONTEXT_WINDOW_EXCEEDED', [], { cause: outcome.overflow });
189
351
  }
190
352
  history = outcome.folded;
191
353
  }
192
354
  }
193
355
  async function* runLadder({ send, history, origins, fold }) {
194
356
  let lastOverflow = null;
195
- for (const candidate of contextCandidates(history, send.args.continuationNudge, send.args.deliveredNudge)) {
357
+ const candidates = ContextWindow.contextCandidates(history, ...harnessTurns(send.args, history));
358
+ for (const candidate of candidates) {
196
359
  const outcome = yield* runCandidateAttempts({ ...send, candidate, history, origins });
197
360
  if ('round' in outcome) {
198
- return { round: recoveredRound({ candidate, attempt: outcome.round, origins }) };
361
+ const cacheable = !send.attempts.uncached;
362
+ return { round: recoveredRound({ candidate, attempt: outcome.round, origins, cacheable }) };
199
363
  }
200
364
  lastOverflow = outcome.overflow;
201
- if (!fold.tried && candidate.history === history) {
202
- fold.tried = true;
203
- const folded = yield* foldHistory(send, history);
365
+ send.attempts.overflows++;
366
+ if (candidate.history === history) {
367
+ const folded = yield* foldHistory(send, history, fold);
204
368
  if (folded) {
205
369
  return { folded };
206
370
  }
371
+ if (candidates.length > 1) {
372
+ await dropShrunkKey(send);
373
+ }
207
374
  }
208
375
  }
209
376
  if (!lastOverflow) {
@@ -211,7 +378,64 @@ async function* runLadder({ send, history, origins, fold }) {
211
378
  }
212
379
  return { overflow: lastOverflow };
213
380
  }
214
- async function* foldHistory(send, history) {
381
+ async function* foldHistory(send, history, tries) {
382
+ if (!tries.chat) {
383
+ tries.chat = true;
384
+ const folded = yield* foldChat(send, history);
385
+ if (folded) {
386
+ return folded;
387
+ }
388
+ }
389
+ if (tries.rounds) {
390
+ return null;
391
+ }
392
+ tries.rounds = true;
393
+ return foldRounds(send, history);
394
+ }
395
+ function harnessTurns(args, history) {
396
+ const mentions = history.flatMap((message) => message.role === 'user' && isSkillMentionNudge(message.content) ? [message.content] : []);
397
+ const wrapUp = args.wrapUpNudge === undefined ? [] : [args.wrapUpNudge];
398
+ return [args.continuationNudge, args.deliveredNudge, ...wrapUp, ...goalTurns(args), ...mentions];
399
+ }
400
+ function goalTurns(args) {
401
+ const goal = args.goalNudge === undefined ? [] : [args.goalNudge];
402
+ return [...goal, GoalCheck.GOAL_CHECKS_ASK, GoalCheck.GOAL_PROOF_ASK, GoalCheck.GOAL_REVIEW_ASK];
403
+ }
404
+ async function foldRounds(send, history) {
405
+ const { sdk, args, ctxSize } = send;
406
+ const spec = args.fold;
407
+ const nudges = harnessTurns(args, history);
408
+ const goals = goalTurns(args);
409
+ if (!spec || !Fold.roundBoundary(history, { nudges, goals, keeps: keepsLoad })?.foldedRounds) {
410
+ return null;
411
+ }
412
+ const instructions = await spec.instructions?.(history);
413
+ const result = await new Fold(summarizer(send)).rounds(history, {
414
+ ctxSize,
415
+ instructions,
416
+ nudges,
417
+ goals,
418
+ keeps: keepsLoad
419
+ });
420
+ if (args.signal?.aborted) {
421
+ throw new AbortedError();
422
+ }
423
+ if (!result.folded) {
424
+ HarnessLog.info('rounds fold refused', { round: args.round, reason: result.reason });
425
+ return null;
426
+ }
427
+ if (args.cacheKey) {
428
+ await dropFoldedKey(sdk, args.cacheKey);
429
+ }
430
+ HarnessLog.info('folded rounds', { round: args.round, foldedRounds: result.foldedRounds });
431
+ return result.history;
432
+ }
433
+ function keepsLoad(message) {
434
+ return (message.role === 'tool' &&
435
+ (message.content.startsWith(ContextWindow.TOOL_SEARCH_RESULT) ||
436
+ message.content.startsWith(`[Tool: ${Agent.SKILL_TOOL_NAME} (`)));
437
+ }
438
+ async function* foldChat(send, history) {
215
439
  const { sdk, args, ctxSize } = send;
216
440
  const spec = args.fold;
217
441
  const widest = spec && Fold.boundary(spec.messages);
@@ -231,7 +455,7 @@ async function* foldHistory(send, history) {
231
455
  }
232
456
  const result = step.value;
233
457
  if (!result.folded) {
234
- hlog('fold refused', { round: args.round, reason: result.reason });
458
+ HarnessLog.info('fold refused', { round: args.round, reason: result.reason });
235
459
  return null;
236
460
  }
237
461
  const replaced = modelTurns(spec.messages.slice(0, result.end), spec.nudge).length;
@@ -243,7 +467,7 @@ async function* foldHistory(send, history) {
243
467
  if (args.cacheKey) {
244
468
  await dropFoldedKey(sdk, args.cacheKey);
245
469
  }
246
- hlog('folded', { round: args.round, foldedTurns: result.foldedTurns });
470
+ HarnessLog.info('folded', { round: args.round, foldedTurns: result.foldedTurns });
247
471
  yield {
248
472
  type: 'fold',
249
473
  phase: 'done',
@@ -253,16 +477,21 @@ async function* foldHistory(send, history) {
253
477
  };
254
478
  return folded;
255
479
  }
480
+ async function dropShrunkKey({ sdk, args, attempts }) {
481
+ if (args.cacheKey && !attempts.uncached) {
482
+ await dropFoldedKey(sdk, args.cacheKey);
483
+ }
484
+ }
256
485
  async function dropFoldedKey(sdk, cacheKey) {
257
486
  Fold.forget(cacheKey);
258
487
  try {
259
488
  const deleted = await sdk.deleteCache?.({ kvCacheKey: cacheKey });
260
489
  if (deleted && !deleted.success) {
261
- hlog('fold key delete did not succeed');
490
+ HarnessLog.info('fold key delete did not succeed');
262
491
  }
263
492
  }
264
493
  catch (error) {
265
- hlog('fold key delete failed', { error: errorMessage(error) });
494
+ HarnessLog.info('fold key delete failed', { error: errorMessage(error) });
266
495
  }
267
496
  }
268
497
  function renderedAt(history, spec, end) {
@@ -270,51 +499,71 @@ function renderedAt(history, spec, end) {
270
499
  const matches = (at) => rendered.every((turn, index) => history[at + index]?.role === turn.role && history[at + index]?.content === turn.content);
271
500
  return [0, 1].find(matches) ?? null;
272
501
  }
273
- function summarizer({ sdk, args, modelId, attempts }) {
502
+ function summarizer(send) {
274
503
  return async (prompt) => {
275
- const params = completionParams({
276
- modelId,
277
- history: [{ role: 'user', content: prompt }],
278
- generationParams: { reasoning_budget: 0 }
279
- });
280
- await args.recordRequest?.({ round: args.round, attempt: attempts.sent++, droppedTurns: 0, params }, []);
281
- if (args.signal?.aborted) {
282
- return { text: null, overflowed: false };
283
- }
284
- const result = withoutRepeatedReply(sdk.completion(params));
285
- result.final.catch(noop);
286
- const cancel = cancelOnce(sdk, result.requestId);
287
- args.signal?.addEventListener('abort', cancel, { once: true });
288
- let text = '';
289
504
  try {
290
- for await (const event of splitThinking(stopAtControlToken(result.tokenStream, cancel))) {
291
- if (event.type === 'content') {
292
- text += event.text;
293
- }
294
- }
295
- await raceAbort(result.final, args.signal);
296
- return { text: args.signal?.aborted ? null : text, overflowed: false };
505
+ return await summarizeOnce(send, prompt);
297
506
  }
298
507
  catch (error) {
299
- cancel();
300
- return { text: null, overflowed: isContextOverflowError(error) };
301
- }
302
- finally {
303
- args.signal?.removeEventListener('abort', cancel);
304
- await raceTimeout(cancel.flush(), { ms: TRUNCATED_FINAL_MS, fallback: undefined });
508
+ if (!isKvCacheSaveFault(error)) {
509
+ return refusedSummary(error);
510
+ }
511
+ HarnessLog.info('kv cache save failed, retrying the fold summary', {
512
+ round: send.args.round,
513
+ error: errorMessage(error)
514
+ });
515
+ return summarizeOnce(send, prompt).catch(refusedSummary);
305
516
  }
306
517
  };
307
518
  }
519
+ async function summarizeOnce(send, prompt) {
520
+ const { sdk, args, modelId, attempts } = send;
521
+ const params = completionParams({
522
+ modelId,
523
+ history: [{ role: 'user', content: prompt }],
524
+ generationParams: { reasoning_budget: 0 }
525
+ });
526
+ await args.recordRequest?.({ round: args.round, attempt: attempts.sent++, droppedTurns: 0, params }, []);
527
+ if (args.signal?.aborted) {
528
+ return { text: null, overflowed: false };
529
+ }
530
+ const result = withoutRepeatedReply(sdk.completion(params));
531
+ result.final.catch(noop);
532
+ const cancel = cancelOnce(sdk, result.requestId);
533
+ args.signal?.addEventListener('abort', cancel, { once: true });
534
+ let text = '';
535
+ try {
536
+ for await (const event of splitThinking(stopAtControlToken(contentDeltas(result.events), cancel))) {
537
+ if (event.type === 'content') {
538
+ text += event.text;
539
+ }
540
+ }
541
+ await raceAbort(result.final, args.signal);
542
+ return { text: args.signal?.aborted ? null : text, overflowed: false };
543
+ }
544
+ catch (error) {
545
+ cancel();
546
+ throw error;
547
+ }
548
+ finally {
549
+ args.signal?.removeEventListener('abort', cancel);
550
+ await raceTimeout(cancel.flush(), { ms: TRUNCATED_FINAL_MS, fallback: undefined });
551
+ }
552
+ }
553
+ function refusedSummary(error) {
554
+ return { text: null, overflowed: isContextOverflowError(error) };
555
+ }
308
556
  async function* runCandidateAttempts(input) {
309
557
  const { sdk, args, modelId, candidate, history, origins, attempts } = input;
310
- let attemptArgs = args;
558
+ let attemptArgs = attempts.uncached ? { ...args, cacheKey: undefined } : args;
311
559
  while (true) {
312
560
  if (args.signal?.aborted)
313
561
  throw new AbortedError();
314
562
  const progress = {
315
563
  cancel: cancelOnce(sdk, undefined),
316
564
  emitted: false,
317
- attempt: attempts.sent++
565
+ attempt: attempts.sent++,
566
+ unsettled: attempts.unsettled
318
567
  };
319
568
  try {
320
569
  const round = yield* runCandidate({
@@ -323,7 +572,6 @@ async function* runCandidateAttempts(input) {
323
572
  modelId,
324
573
  candidate,
325
574
  progress,
326
- baseHistory: history,
327
575
  origins
328
576
  });
329
577
  return { round };
@@ -337,24 +585,36 @@ async function* runCandidateAttempts(input) {
337
585
  }
338
586
  const grammarOff = withoutToolGrammar(attemptArgs, err);
339
587
  if (grammarOff) {
340
- hlog('tool grammar fault, retrying the round without it', { round: args.round });
588
+ HarnessLog.info('tool grammar fault, retrying the round without it', { round: args.round });
341
589
  yield* resetShownRound(args, progress);
342
590
  attemptArgs = grammarOff;
343
591
  continue;
344
592
  }
345
593
  const unforced = withoutForcedCall(attemptArgs, err);
346
594
  if (unforced) {
347
- hlog('forced tool call refused, retrying the round without it', { round: args.round });
595
+ HarnessLog.info('forced tool call refused, retrying the round without it', {
596
+ round: args.round
597
+ });
348
598
  yield* resetShownRound(args, progress);
349
599
  attemptArgs = unforced;
350
600
  continue;
351
601
  }
602
+ if (!attempts.uncached && isKvCacheSaveFault(err)) {
603
+ HarnessLog.info('kv cache save failed, retrying the round uncached', {
604
+ round: args.round,
605
+ error: errorMessage(err)
606
+ });
607
+ yield* resetShownRound(args, progress);
608
+ attempts.uncached = true;
609
+ attemptArgs = { ...attemptArgs, cacheKey: undefined };
610
+ continue;
611
+ }
352
612
  if (!isContextOverflowError(err)) {
353
613
  throw err;
354
614
  }
355
615
  if (progress.emitted) {
356
- yield* foldHistory(input, history);
357
- throw errorWithCause(CONTEXT_OVERFLOW_MESSAGE, err);
616
+ yield* foldChat(input, history);
617
+ throw new HarnessError('CONTEXT_WINDOW_EXCEEDED', [], { cause: err });
358
618
  }
359
619
  return { overflow: err };
360
620
  }
@@ -396,16 +656,19 @@ async function flushCandidate(args, progress) {
396
656
  }
397
657
  await raceTimeout(progress.cancel.flush(), { ms: TRUNCATED_FINAL_MS, fallback: undefined });
398
658
  }
399
- function recoveredRound({ candidate, attempt, origins }) {
659
+ function recoveredRound({ candidate, attempt, origins, cacheable }) {
400
660
  const replay = unprovenReplay(attempt.state, attempt.final);
401
661
  logCandidateFinal(attempt, replay);
402
662
  return {
403
663
  contentText: attempt.contentText,
404
664
  final: attempt.final,
405
665
  history: restoreHistory(candidate.history, origins),
406
- cacheable: attempt.cacheable,
666
+ cacheable,
667
+ keyed: attempt.keyed,
407
668
  unproven: attempt.state.unproven,
408
- replay
669
+ replay,
670
+ reasoningDeltas: attempt.state.reasoningDeltas || undefined,
671
+ cut: attempt.state.cut ?? undefined
409
672
  };
410
673
  }
411
674
  function historyOrigins(entries, messages) {
@@ -421,16 +684,15 @@ function historyOrigins(entries, messages) {
421
684
  });
422
685
  return origins;
423
686
  }
424
- async function* runCandidate({ sdk, args, modelId, candidate, progress, baseHistory, origins }) {
425
- const cacheable = candidate.history === baseHistory;
426
- const params = inferenceParams({ args, modelId, history: candidate.history, cacheable });
687
+ async function* runCandidate({ sdk, args, modelId, candidate, progress, origins }) {
688
+ const params = inferenceParams({ args, modelId, history: candidate.history });
427
689
  if (args.capture) {
428
690
  yield inferenceCall({
429
691
  args,
430
- candidate,
692
+ droppedTurns: candidate.droppedTurns,
431
693
  modelId,
432
694
  params,
433
- cacheKey: cacheable ? args.cacheKey : undefined
695
+ cacheKey: args.cacheKey
434
696
  });
435
697
  }
436
698
  await args.recordRequest?.({
@@ -445,47 +707,65 @@ async function* runCandidate({ sdk, args, modelId, candidate, progress, baseHist
445
707
  const result = withoutRepeatedReply(sdk.completion(params));
446
708
  result.final.catch(noop);
447
709
  progress.cancel = cancelOnce(sdk, result.requestId);
448
- const state = { stopToken: null, unproven: null, rawContentText: '' };
710
+ args.live.rawChars = 0;
711
+ args.live.reasoningDeltas = 0;
712
+ const state = {
713
+ live: args.live,
714
+ stopToken: null,
715
+ calls: [],
716
+ runaway: false,
717
+ cut: null,
718
+ unproven: null,
719
+ rawContentText: '',
720
+ reasoningDeltas: 0
721
+ };
449
722
  const contentText = yield* streamCandidateTokens({ result, state, args, progress });
450
- const final = state.stopToken
723
+ const final = state.stopToken || state.runaway || state.cut !== null
451
724
  ? await truncatedFinal(result.final, state.rawContentText)
452
725
  : await raceAbort(result.final, args.signal);
453
726
  const detachedFinal = {
454
727
  ...final,
455
- toolCalls: copy(final.toolCalls ?? []),
728
+ toolCalls: copy(state.runaway || state.cut !== null ? state.calls : (final.toolCalls ?? [])),
456
729
  toolErrors: copy(final.toolErrors ?? []),
457
- stats: copy(final.stats)
730
+ stats: boundaryStats(final, params.generationParams?.predict)
458
731
  };
459
732
  if (args.capture) {
460
733
  yield inferenceSent({ args, candidate, final: detachedFinal });
461
734
  }
462
- return { contentText, final: detachedFinal, state, cacheable };
735
+ return { contentText, final: detachedFinal, state, keyed: args.cacheKey !== undefined };
463
736
  }
464
- function inferenceParams({ args, modelId, history, cacheable }) {
737
+ function inferenceParams({ args, modelId, history }) {
465
738
  return completionParams({
466
739
  modelId,
467
740
  history: detachJson(history),
468
741
  tools: args.tools ? detachJson(args.tools) : undefined,
469
- generationParams: args.generationParams ? detachJson(args.generationParams) : undefined,
742
+ generationParams: generationParams(args),
470
743
  responseFormat: args.responseFormat ? detachJson(args.responseFormat) : undefined,
471
744
  toolDialect: args.toolDialect,
472
- kvCache: cacheable ? args.cacheKey : undefined
745
+ kvCache: args.cacheKey
473
746
  });
474
747
  }
475
- function inferenceCall({ args, candidate, modelId, params, cacheKey }) {
748
+ function generationParams(args) {
749
+ const { reasoning_rounds: _rounds, ...host } = args.generationParams
750
+ ? detachJson(args.generationParams)
751
+ : {};
752
+ const sent = args.generationParams ? host : undefined;
753
+ return args.tools?.length ? { parallel_tool_calls: true, ...sent } : sent;
754
+ }
755
+ export function inferenceCall({ args, droppedTurns, modelId, params, cacheKey }) {
476
756
  return {
477
757
  type: 'inference-call',
478
758
  call: {
479
759
  round: args.round,
480
- droppedTurns: candidate.droppedTurns,
760
+ droppedTurns,
481
761
  modelId,
482
762
  messages: params.history,
483
- tools: params.tools,
763
+ tools: renderedTools(params.tools, params.history),
484
764
  generationParams: params.generationParams,
485
765
  responseFormat: params.responseFormat,
486
766
  toolDialect: params.toolDialect,
487
767
  cacheKey,
488
- promptPrefix: args.promptPrefix
768
+ promptPrefix: requestPromptPrefix(params.history, params.tools)
489
769
  }
490
770
  };
491
771
  }
@@ -494,7 +774,6 @@ function inferenceSent({ args, candidate, final }) {
494
774
  type: 'inference-sent',
495
775
  round: args.round,
496
776
  droppedTurns: candidate.droppedTurns,
497
- messages: sentMessages(final.stats),
498
777
  tokens: roundTokens(final.stats),
499
778
  outcome: 'completed',
500
779
  reason: undefined
@@ -502,13 +781,15 @@ function inferenceSent({ args, candidate, final }) {
502
781
  }
503
782
  async function* streamCandidateTokens({ result, state, args, progress }) {
504
783
  let contentText = '';
505
- const startInThink = args.generationParams?.reasoning_budget === -1;
784
+ const startInThink = (args.generationParams?.reasoning_budget ?? 0) !== 0 && args.canThink !== false;
506
785
  for await (const event of runRoundTokens({
507
786
  result,
508
787
  state,
509
788
  cancelThisRound: progress.cancel,
789
+ unsettled: progress.unsettled,
510
790
  signal: args.signal,
511
- startInThink
791
+ startInThink,
792
+ knownTools: args.knownTools ?? []
512
793
  })) {
513
794
  if (event.type === 'content') {
514
795
  contentText += event.text;
@@ -523,25 +804,26 @@ function candidateFailureEvent({ args, candidate, error }) {
523
804
  type: 'inference-sent',
524
805
  round: args.round,
525
806
  droppedTurns: candidate.droppedTurns,
526
- messages: undefined,
527
807
  tokens: undefined,
528
808
  outcome: isContextOverflowError(error) ? 'overflowed' : 'failed',
529
809
  reason: errorMessage(error)
530
810
  };
531
811
  }
532
812
  function logCandidateFinal({ state, final, contentText }, replay) {
533
- hlog('final', {
813
+ HarnessLog.debug('final', {
534
814
  stopReason: final.stopReason,
535
815
  toolCalls: final.toolCalls.length,
536
816
  toolErrors: final.toolErrors?.length ?? 0,
537
817
  contentChars: contentText.length,
538
818
  stopToken: state.stopToken,
819
+ runaway: state.runaway,
820
+ cut: state.cut !== null,
539
821
  replay: replay !== null
540
822
  });
541
823
  }
542
824
  function failureTurns(args, origins, sent) {
543
825
  return sent.flatMap((message, at) => {
544
- const source = compactedFrom(message);
826
+ const source = ContextWindow.compactedFrom(message);
545
827
  const entry = origins.get(source ?? message)?.entry;
546
828
  if (!entry || !isFailureResultReference(entry)) {
547
829
  return [];
@@ -553,7 +835,7 @@ function failureTurns(args, origins, sent) {
553
835
  }
554
836
  function restoreHistory(messages, origins) {
555
837
  return messages.map((message) => {
556
- const source = compactedFrom(message);
838
+ const source = ContextWindow.compactedFrom(message);
557
839
  const origin = origins.get(source ?? message);
558
840
  if (!origin || stableStringify(source ?? message) !== origin.fingerprint) {
559
841
  return message;
@@ -561,8 +843,3 @@ function restoreHistory(messages, origins) {
561
843
  return source ? { ...origin.entry, compactedTo: message.content.length } : origin.entry;
562
844
  });
563
845
  }
564
- function errorWithCause(message, cause) {
565
- const error = new Error(message);
566
- Object.defineProperty(error, 'cause', { value: cause, configurable: true });
567
- return error;
568
- }