@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,240 +1,21 @@
1
1
  import b4a from 'b4a';
2
- import { AbortController } from 'bare-abort-controller';
3
- import fs from 'fs';
2
+ import { HarnessError } from './errors.js';
4
3
  import { settleOnClose } from './rpc-session.js';
5
- import { pipeline, Readable } from 'streamx';
4
+ import { pipeline } from 'streamx';
6
5
  import { bindApi } from '../spec/bind.js';
7
6
  import HRPC from '../spec/hrpc/index.js';
8
- import { encode } from '../spec/hrpc/messages.js';
9
- import { checkGoal } from './capabilities/tool-turns.js';
10
- import { isCapability } from './capabilities/invoke.js';
11
7
  import { CUSTOM_TASK_TYPES } from './models/model-catalog.js';
12
8
  import { unsupportedKvCacheDeletion } from './capabilities/kv-cache.js';
13
- import { RunLog } from './run-log/index.js';
14
- import { errorMessage, isRecord } from './guards.js';
15
- import { hlog } from './log.js';
16
- import { pushQueue } from './queue.js';
17
- import { TextCoalescer } from './helpers/text-coalescer.js';
18
9
  import { prepareOpenclCache } from './models/opencl-cache.js';
19
- import { stageFile, sweepStaging } from './staging.js';
10
+ import { sweepStaging } from './staging.js';
20
11
  import { sweepSpill } from './spill.js';
21
- import { readSetup, toWireSetup } from './tools/skills/manifest-parse.js';
22
- import { fromKnowledgeUpsertWire, packVectors, toDownloadWire, toKnowledgeUpsertResultWire, toWire } from './wire.js';
23
- const MODEL_STATUSES = new Set([
24
- 'loading',
25
- 'downloading',
26
- 'downloaded',
27
- 'ready',
28
- 'error',
29
- 'unloading',
30
- 'unloaded'
31
- ]);
32
- const DOWNLOAD_PROGRESS_INTERVAL_MS = 500;
33
- const WIRE_HIGH_WATER_MARK = 64;
34
- const TEXT_COALESCE_CAP = 8192;
35
- const TEXT_COALESCE_MS = 60;
36
- function noop() { }
37
- function decodeDigestKey(value) {
38
- if (typeof value !== 'string' || !/^[0-9a-f]{64}$/i.test(value)) {
39
- return undefined;
40
- }
41
- return b4a.from(value, 'hex');
42
- }
43
- function isEngineBoot(value) {
44
- if (!isEngineBootEnvelope(value)) {
45
- return false;
46
- }
47
- try {
48
- RunLog.validateEngineBoot(value);
49
- return true;
50
- }
51
- catch {
52
- return false;
53
- }
54
- }
55
- function isEngineBootEnvelope(value) {
56
- if (!isRecord(value)) {
57
- return false;
58
- }
59
- const counter = (name) => typeof value[name] === 'number' && Number.isSafeInteger(value[name]) && value[name] >= 0;
60
- const metadata = value.metadata;
61
- const hasMetadata = metadata === null ||
62
- (isRecord(metadata) && metadata.version === RunLog.VERSION && metadata.type === 'metadata');
63
- return (value.protocolVersion === 1 &&
64
- counter('length') &&
65
- counter('nextSeq') &&
66
- counter('deltasSinceCheckpoint') &&
67
- counter('unredactedLength') &&
68
- (value.machineVersion === null || typeof value.machineVersion === 'number') &&
69
- (value.xstateVersion === null || typeof value.xstateVersion === 'string') &&
70
- hasMetadata &&
71
- 'eventState' in value &&
72
- (value.snapshotSavedAt === undefined || typeof value.snapshotSavedAt === 'number') &&
73
- (value.firstSavedAt === undefined || typeof value.firstSavedAt === 'number') &&
74
- (value.redactedPendingArgs === null || typeof value.redactedPendingArgs === 'boolean') &&
75
- typeof value.restoredRedacted === 'boolean' &&
76
- Array.isArray(value.forkBeforeWrite) &&
77
- Array.isArray(value.receipts) &&
78
- Array.isArray(value.intentArgs));
79
- }
80
- const EMPTY_IDENTITY_FIELDS = new Set([
81
- 'model',
82
- 'cacheKey',
83
- 'thinkingDefault',
84
- 'agent.id',
85
- 'agent.name',
86
- 'agent.bio'
87
- ]);
88
- function optionalNumber(value) {
89
- return value === undefined || typeof value === 'number';
90
- }
91
- function goalFrom(value) {
92
- const { objective, rounds, ms, tokens } = value;
93
- if (typeof objective !== 'string' ||
94
- !optionalNumber(rounds) ||
95
- !optionalNumber(ms) ||
96
- !optionalNumber(tokens)) {
97
- throw new TypeError('Invalid goal');
98
- }
99
- return { objective, rounds, ms, tokens };
100
- }
101
- function startPayloadFrom(value) {
102
- if (!isRecord(value)) {
103
- return {};
104
- }
105
- const payload = {};
106
- if (value.resume === null || typeof value.resume === 'boolean') {
107
- payload.resume = value.resume;
108
- }
109
- if (value.recoveryEvents === null || typeof value.recoveryEvents === 'boolean') {
110
- payload.recoveryEvents = value.recoveryEvents;
111
- }
112
- if (Object.hasOwn(value, 'explicitEmptyIdentity')) {
113
- if (!Array.isArray(value.explicitEmptyIdentity) ||
114
- value.explicitEmptyIdentity.length > EMPTY_IDENTITY_FIELDS.size) {
115
- throw new TypeError('Invalid explicit-empty identity marker');
116
- }
117
- const fields = new Set();
118
- for (const field of value.explicitEmptyIdentity) {
119
- if (typeof field !== 'string' || !EMPTY_IDENTITY_FIELDS.has(field)) {
120
- throw new TypeError('Invalid explicit-empty identity marker');
121
- }
122
- fields.add(field);
123
- }
124
- if (fields.size) {
125
- payload.explicitEmptyIdentity = [...fields];
126
- }
127
- }
128
- if (Array.isArray(value.resolutions)) {
129
- payload.resolutions = value.resolutions.map((resolution) => {
130
- if (!isRecord(resolution) || typeof resolution.operationId !== 'string') {
131
- throw new TypeError('Invalid run recovery resolution');
132
- }
133
- if (resolution.decision === 'retry') {
134
- return { operationId: resolution.operationId, decision: 'retry' };
135
- }
136
- if (resolution.decision === 'result' && 'result' in resolution) {
137
- return {
138
- operationId: resolution.operationId,
139
- decision: 'result',
140
- result: resolution.result
141
- };
142
- }
143
- if (resolution.decision === 'skip') {
144
- return { operationId: resolution.operationId, decision: 'skip' };
145
- }
146
- throw new TypeError('Invalid run recovery resolution');
147
- });
148
- }
149
- if (isRecord(value.knowledge)) {
150
- const { scopes } = value.knowledge;
151
- if (!Array.isArray(scopes) || !scopes.every((scope) => typeof scope === 'string')) {
152
- throw new TypeError('Invalid knowledge grant');
153
- }
154
- payload.knowledge = { scopes };
155
- }
156
- if (value.planMode === true) {
157
- payload.planMode = true;
158
- }
159
- if (typeof value.parentRunId === 'string') {
160
- payload.parentRunId = value.parentRunId;
161
- }
162
- if (isRecord(value.goal)) {
163
- payload.goal = goalFrom(value.goal);
164
- }
165
- if (value.runLog === null) {
166
- payload.runLog = null;
167
- }
168
- else if (value.runLog) {
169
- const runLog = isRecord(value.runLog) ? value.runLog : {};
170
- payload.runLog = {
171
- boot: runLog.boot,
172
- digestKey: runLog.digestKey,
173
- hostAppendTimeoutMs: typeof runLog.hostAppendTimeoutMs === 'number' ? runLog.hostAppendTimeoutMs : undefined
174
- };
175
- }
176
- return payload;
177
- }
178
- function assertEmptyIdentityMarkersMatchFrame(frame, fields) {
179
- for (const field of fields) {
180
- let value;
181
- switch (field) {
182
- case 'model':
183
- value = frame.model;
184
- break;
185
- case 'cacheKey':
186
- value = frame.cacheKey;
187
- break;
188
- case 'thinkingDefault':
189
- value = frame.thinkingDefault;
190
- break;
191
- case 'agent.id':
192
- if (frame.agent === null || frame.agent === undefined) {
193
- throw new TypeError('Explicit-empty agent identity requires an agent frame');
194
- }
195
- value = frame.agent?.id;
196
- break;
197
- case 'agent.name':
198
- if (frame.agent === null || frame.agent === undefined) {
199
- throw new TypeError('Explicit-empty agent identity requires an agent frame');
200
- }
201
- value = frame.agent?.name;
202
- break;
203
- case 'agent.bio':
204
- if (frame.agent === null || frame.agent === undefined) {
205
- throw new TypeError('Explicit-empty agent identity requires an agent frame');
206
- }
207
- value = frame.agent?.bio;
208
- break;
209
- }
210
- if (value !== null && value !== undefined && value !== '') {
211
- throw new TypeError('Conflicting explicit-empty identity marker');
212
- }
213
- }
214
- }
215
- function normalizeAgentKnobs(agent) {
216
- const normalized = { ...agent };
217
- if (normalized.id === null || normalized.id === undefined) {
218
- delete normalized.id;
219
- }
220
- if (normalized.name === null || normalized.name === undefined) {
221
- delete normalized.name;
222
- }
223
- if (normalized.bio === null || normalized.bio === undefined) {
224
- delete normalized.bio;
225
- }
226
- if (normalized.handoffs === null || normalized.handoffs === undefined) {
227
- delete normalized.handoffs;
228
- }
229
- if (normalized.model === null || normalized.model === undefined) {
230
- delete normalized.model;
231
- }
232
- return normalized;
233
- }
234
- function tick() {
235
- return new Promise((resolve) => setTimeout(resolve, 0));
236
- }
237
- export function serveHarness(stream, harness) {
12
+ import { Wire } from './wire.js';
13
+ import { noop } from './serve/noop.js';
14
+ import { toWireSkill, unsupportedKnowledge, unsupportedEmbeddingDeviceControl } from './serve/skills.js';
15
+ import { modelEvents, speakStream } from './serve/models.js';
16
+ import { completion } from './serve/completion.js';
17
+ import { downloadStream } from './serve/downloads.js';
18
+ function serveHarness(stream, harness) {
238
19
  sweepStaging();
239
20
  sweepSpill();
240
21
  prepareOpenclCache();
@@ -252,6 +33,20 @@ export function serveHarness(stream, harness) {
252
33
  await harness.setModelIdleTimeout?.(ms);
253
34
  return { ok: true };
254
35
  },
36
+ setModelMemoryCap: async ({ percent }) => {
37
+ await harness.setModelMemoryCap?.(percent);
38
+ return { ok: true };
39
+ },
40
+ memoryUsage: async () => {
41
+ if (!harness.memoryUsage) {
42
+ throw new HarnessError('CAPABILITY_UNSUPPORTED', ['memoryUsage']);
43
+ }
44
+ return harness.memoryUsage();
45
+ },
46
+ setDownloadsAllowed: async ({ allowed }) => {
47
+ await harness.setDownloadsAllowed?.({ allowed: allowed === true });
48
+ return { ok: true };
49
+ },
255
50
  listManagedSkills: async () => ({
256
51
  skills: (await harness.listManagedSkills?.()) ?? []
257
52
  }),
@@ -296,7 +91,7 @@ export function serveHarness(stream, harness) {
296
91
  },
297
92
  previewModelSource: async ({ src, mmprojSrc }) => {
298
93
  if (!harness.previewModelSource) {
299
- throw new Error('harness does not support previewModelSource');
94
+ throw new HarnessError('CAPABILITY_UNSUPPORTED', ['previewModelSource']);
300
95
  }
301
96
  return harness.previewModelSource({ src: src ?? '', mmprojSrc: mmprojSrc ?? undefined });
302
97
  },
@@ -314,21 +109,29 @@ export function serveHarness(stream, harness) {
314
109
  skills: []
315
110
  },
316
111
  embed: async ({ model, texts }) => {
317
- if (!harness.embed)
318
- throw new Error('harness does not support embed');
319
- return packVectors(await harness.embed({ model, texts: texts ?? [] }));
112
+ if (!harness.embed) {
113
+ throw new HarnessError('CAPABILITY_UNSUPPORTED', ['embed']);
114
+ }
115
+ return Wire.packVectors(await harness.embed({ model, texts: texts ?? [] }));
320
116
  },
321
117
  transcribe: async ({ model, audio }) => {
322
118
  if (!harness.transcribe) {
323
- throw new Error('harness does not support transcribe');
119
+ throw new HarnessError('CAPABILITY_UNSUPPORTED', ['transcribe']);
324
120
  }
325
121
  return {
326
122
  text: await harness.transcribe({ model: model ?? '', audio: audio ?? b4a.alloc(0) })
327
123
  };
328
124
  },
125
+ ocrRead: async ({ width, height, data }) => {
126
+ if (!harness.ocrRead) {
127
+ throw new HarnessError('CAPABILITY_UNSUPPORTED', ['ocr']);
128
+ }
129
+ const image = { width: width ?? 0, height: height ?? 0, data: data ?? b4a.alloc(0) };
130
+ return await harness.ocrRead({ image });
131
+ },
329
132
  detectLanguage: async ({ text, topK }) => {
330
133
  if (!harness.detectLanguage) {
331
- throw new Error('harness does not support detectLanguage');
134
+ throw new HarnessError('CAPABILITY_UNSUPPORTED', ['detectLanguage']);
332
135
  }
333
136
  const languages = await harness.detectLanguage({
334
137
  text: text ?? '',
@@ -337,8 +140,9 @@ export function serveHarness(stream, harness) {
337
140
  return { languages };
338
141
  },
339
142
  speak: async ({ model, text }) => {
340
- if (!harness.speak)
341
- throw new Error('harness does not support speak');
143
+ if (!harness.speak) {
144
+ throw new HarnessError('CAPABILITY_UNSUPPORTED', ['speak']);
145
+ }
342
146
  return harness.speak({ model: model ?? '', text: text ?? '' });
343
147
  },
344
148
  speakStream: speakStream(harness),
@@ -382,26 +186,26 @@ export function serveHarness(stream, harness) {
382
186
  }),
383
187
  capability: async () => {
384
188
  if (!harness.capability) {
385
- throw new Error('harness does not support capability');
189
+ throw new HarnessError('CAPABILITY_UNSUPPORTED', ['capability']);
386
190
  }
387
191
  return harness.capability();
388
192
  },
389
193
  warmModel: async ({ model, agent }) => {
390
194
  if (!harness.warmModel) {
391
- throw new Error('harness does not support warmModel');
195
+ throw new HarnessError('CAPABILITY_UNSUPPORTED', ['warmModel']);
392
196
  }
393
197
  await harness.warmModel({ model, agent: agent ?? {} });
394
198
  return { ok: true };
395
199
  },
396
200
  loadModel: async ({ model, agent }) => {
397
201
  if (!harness.loadModel) {
398
- throw new Error('harness does not support loadModel');
202
+ throw new HarnessError('CAPABILITY_UNSUPPORTED', ['loadModel']);
399
203
  }
400
204
  return harness.loadModel({ model, agent: agent ?? {} });
401
205
  },
402
206
  unloadModel: async ({ model }) => {
403
207
  if (!harness.unloadModel) {
404
- throw new Error('harness does not support unloadModel');
208
+ throw new HarnessError('CAPABILITY_UNSUPPORTED', ['unloadModel']);
405
209
  }
406
210
  return harness.unloadModel({ model });
407
211
  },
@@ -409,7 +213,7 @@ export function serveHarness(stream, harness) {
409
213
  if (!harness.knowledgeUpsert) {
410
214
  throw unsupportedKnowledge();
411
215
  }
412
- return toKnowledgeUpsertResultWire(await harness.knowledgeUpsert(fromKnowledgeUpsertWire(req)));
216
+ return Wire.toKnowledgeUpsertResultWire(await harness.knowledgeUpsert(Wire.fromKnowledgeUpsertWire(req)));
413
217
  },
414
218
  knowledgeRemove: async ({ artifactId }) => {
415
219
  if (!harness.knowledgeRemove) {
@@ -417,11 +221,12 @@ export function serveHarness(stream, harness) {
417
221
  }
418
222
  return harness.knowledgeRemove(artifactId);
419
223
  },
420
- knowledgeSearch: async ({ text, scopes, k }) => {
224
+ knowledgeSearch: async ({ text, scopes, k, focus }) => {
421
225
  if (!harness.knowledgeSearch) {
422
226
  throw unsupportedKnowledge();
423
227
  }
424
- return { hits: await harness.knowledgeSearch({ text, scopes, k: k || undefined }) };
228
+ const query = { text, scopes, k: k || undefined, focus: focus?.length ? focus : undefined };
229
+ return { hits: await harness.knowledgeSearch(query) };
425
230
  },
426
231
  knowledgeStatus: async () => {
427
232
  if (!harness.knowledgeStatus) {
@@ -438,676 +243,6 @@ export function serveHarness(stream, harness) {
438
243
  out.writeStream?.on('close', () => src.destroy());
439
244
  });
440
245
  }
441
- function toWireSkill(skill) {
442
- const setupV2 = toWireSetup(readSetup(skill.setup));
443
- const binaries = (skill.requires?.bins ?? []).map((bin) => ({
444
- bin,
445
- minVersion: skill.requires?.binMinVersions?.[bin]?.min,
446
- command: skill.requires?.binMinVersions?.[bin]?.command
447
- }));
448
- return {
449
- name: skill.name,
450
- description: skill.description,
451
- tools: skill.tools,
452
- credentials: skill.credentials,
453
- allowList: skill.allowList,
454
- platforms: skill.platform,
455
- status: skill.status,
456
- requirements: skill.requires
457
- ? { binaries, credentials: skill.requires.credentials ?? [] }
458
- : undefined,
459
- install: skill.install || undefined,
460
- setup: skill.setup || undefined,
461
- setupV2,
462
- stub: skill.stub,
463
- minCapabilityProfile: skill.minCapabilityProfile || undefined,
464
- emoji: skill.emoji || undefined
465
- };
466
- }
467
- function unsupportedKnowledge() {
468
- return new Error('harness does not support knowledge');
469
- }
470
- function unsupportedEmbeddingDeviceControl() {
471
- return new Error('harness does not support embedding device control');
472
- }
473
- function modelEvents(harness) {
474
- let last = '';
475
- let pendingProgress = null;
476
- let lastProgressAt = 0;
477
- const flushProgress = (at) => {
478
- if (pendingProgress === null)
479
- return;
480
- stream.push(pendingProgress);
481
- pendingProgress = null;
482
- lastProgressAt = at;
483
- };
484
- const onModel = (state) => {
485
- if (!MODEL_STATUSES.has(state.status))
486
- return;
487
- const percentage = Math.floor(state.percentage ?? 0);
488
- const downloaded = Math.floor(state.downloaded ?? 0);
489
- const total = Math.floor(state.total ?? 0);
490
- const loaded = state.loaded ?? [];
491
- const catalogChanged = state.catalogChanged === true;
492
- const key = [
493
- state.status,
494
- state.model ?? '',
495
- percentage,
496
- downloaded,
497
- total,
498
- state.message ?? '',
499
- catalogChanged,
500
- ...loaded.map((entry) => `${entry.model}:${entry.refs}`)
501
- ].join('\0');
502
- if (key === last && !catalogChanged) {
503
- return;
504
- }
505
- last = key;
506
- const frame = encodableModelEvent({
507
- status: state.status,
508
- model: state.model,
509
- percentage,
510
- downloaded,
511
- total,
512
- message: state.message,
513
- catalogChanged,
514
- loaded
515
- });
516
- const now = Date.now();
517
- if (frame.status === 'downloading') {
518
- pendingProgress = frame;
519
- if (lastProgressAt === 0 || now - lastProgressAt >= DOWNLOAD_PROGRESS_INTERVAL_MS) {
520
- flushProgress(now);
521
- }
522
- return;
523
- }
524
- flushProgress(now);
525
- lastProgressAt = 0;
526
- stream.push(frame);
527
- };
528
- const stream = new Readable({
529
- open(cb) {
530
- harness.on?.('model', onModel);
531
- cb(null);
532
- },
533
- destroy(cb) {
534
- harness.off?.('model', onModel);
535
- cb(null);
536
- }
537
- });
538
- return stream;
539
- }
540
- function encodableModelEvent(frame) {
541
- try {
542
- encode('@harness/model-event', frame);
543
- return frame;
544
- }
545
- catch (err) {
546
- return { status: 'error', message: `cannot encode model event: ${errorMessage(err)}` };
547
- }
548
- }
549
- function speakStream(harness) {
550
- return async function* (duplex) {
551
- if (!harness.speakStream) {
552
- throw new Error('harness does not support speakStream');
553
- }
554
- const text = pushQueue();
555
- const end = () => text.end();
556
- duplex.on('close', end);
557
- duplex.on('end', end);
558
- duplex.readStream?.on('close', end);
559
- duplex.on('data', (frame) => {
560
- if (frame.text) {
561
- text.push(frame.text);
562
- }
563
- });
564
- for await (const chunk of harness.speakStream({ model: '', text })) {
565
- const frame = { audio: chunk.audio, sampleRate: chunk.sampleRate };
566
- try {
567
- encode('@harness/speak-response', frame);
568
- }
569
- catch (err) {
570
- throw new Error(`cannot encode speak frame: ${errorMessage(err)}`);
571
- }
572
- yield frame;
573
- }
574
- };
575
- }
576
- function runFrame(harness, frame, context) {
577
- if (frame.type !== 'invoke') {
578
- return harness.completion(context);
579
- }
580
- if (!harness.invoke)
581
- throw new Error('harness does not support invoke');
582
- const capability = frame.capability ?? '';
583
- if (!isCapability(capability)) {
584
- throw new Error(`unknown capability: ${capability}`);
585
- }
586
- return harness.invoke({
587
- capability,
588
- args: frame.arguments ?? {},
589
- enhance: frame.enhance === 'auto' ? 'auto' : 'never',
590
- agent: frame.agent ?? undefined,
591
- attach: context.attach,
592
- fetchAttachment: context.fetchAttachment,
593
- progress: context.progress,
594
- signal: context.signal
595
- });
596
- }
597
- function completion(harness) {
598
- return async function* (duplex) {
599
- const events = pushQueue({ highWaterMark: WIRE_HIGH_WATER_MARK });
600
- const pending = new Map();
601
- const pendingAttach = new Map();
602
- const pendingFetch = new Map();
603
- const pendingQuestion = new Map();
604
- const pendingDrive = new Map();
605
- const pendingRunLog = new Map();
606
- const input = pushQueue();
607
- const controller = new AbortController();
608
- let calls = 0;
609
- let started = false;
610
- let clientGone = false;
611
- const gone = () => {
612
- clientGone = true;
613
- controller.abort('client gone');
614
- for (const resolve of pending.values()) {
615
- resolve(false);
616
- }
617
- pending.clear();
618
- for (const { reject, staged } of pendingAttach.values()) {
619
- void fs.promises.unlink(staged).catch(noop);
620
- reject(new Error('client gone'));
621
- }
622
- pendingAttach.clear();
623
- for (const { reject } of pendingFetch.values()) {
624
- reject(new Error('client gone'));
625
- }
626
- pendingFetch.clear();
627
- for (const { resolve } of pendingQuestion.values()) {
628
- resolve(null);
629
- }
630
- pendingQuestion.clear();
631
- for (const { reject, path } of pendingDrive.values()) {
632
- if (path) {
633
- void fs.promises.unlink(path).catch(noop);
634
- }
635
- reject(new Error('client gone'));
636
- }
637
- pendingDrive.clear();
638
- for (const { reject } of pendingRunLog.values()) {
639
- reject(new Error('client gone'));
640
- }
641
- pendingRunLog.clear();
642
- input.end();
643
- events.end();
644
- };
645
- duplex.on('close', gone);
646
- duplex.on('end', gone);
647
- duplex.readStream?.on('close', gone);
648
- duplex.on('data', (frame) => {
649
- if (frame.type === 'decision') {
650
- if (typeof frame.callId !== 'string') {
651
- return;
652
- }
653
- pending.get(frame.callId)?.(frame.approved === true);
654
- pending.delete(frame.callId);
655
- return;
656
- }
657
- if (frame.type === 'attach-result') {
658
- if (typeof frame.callId !== 'string') {
659
- return;
660
- }
661
- const waiter = pendingAttach.get(frame.callId);
662
- pendingAttach.delete(frame.callId);
663
- if (!waiter) {
664
- return;
665
- }
666
- void fs.promises.unlink(waiter.staged).catch(noop);
667
- if (frame.attachment) {
668
- waiter.resolve(frame.attachment);
669
- }
670
- else {
671
- waiter.reject(new Error(frame.message || 'the host failed to store the attachment'));
672
- }
673
- return;
674
- }
675
- if (frame.type === 'fetch-result') {
676
- if (typeof frame.callId !== 'string') {
677
- return;
678
- }
679
- const waiter = pendingFetch.get(frame.callId);
680
- pendingFetch.delete(frame.callId);
681
- if (!waiter) {
682
- return;
683
- }
684
- if (frame.message) {
685
- return waiter.reject(new Error(frame.message));
686
- }
687
- const staged = frame.path;
688
- const { fileName, mimeType, attachmentId, size } = frame;
689
- if (frame.meta === true) {
690
- return waiter.resolve({
691
- id: attachmentId ?? '',
692
- fileName: fileName ?? '',
693
- mimeType: mimeType ?? '',
694
- byteLength: typeof size === 'number' ? size : 0
695
- });
696
- }
697
- if (!staged) {
698
- return waiter.resolve(null);
699
- }
700
- fs.promises.readFile(staged).then((bytes) => waiter.resolve({
701
- id: attachmentId ?? '',
702
- fileName: fileName ?? '',
703
- mimeType: mimeType ?? '',
704
- byteLength: typeof size === 'number' ? size : bytes.byteLength,
705
- bytes
706
- }), (err) => waiter.reject(err));
707
- return;
708
- }
709
- if (frame.type === 'question-result') {
710
- if (typeof frame.callId !== 'string') {
711
- return;
712
- }
713
- const waiter = pendingQuestion.get(frame.callId);
714
- pendingQuestion.delete(frame.callId);
715
- if (!waiter) {
716
- return;
717
- }
718
- if (frame.message) {
719
- hlog('question failed', { callId: frame.callId, message: frame.message });
720
- }
721
- waiter.resolve(frame.answer || null);
722
- return;
723
- }
724
- if (frame.type === 'drive-result') {
725
- if (typeof frame.callId !== 'string') {
726
- return;
727
- }
728
- const waiter = pendingDrive.get(frame.callId);
729
- pendingDrive.delete(frame.callId);
730
- if (!waiter) {
731
- return;
732
- }
733
- if (frame.message) {
734
- return waiter.reject(new Error(frame.message));
735
- }
736
- waiter.resolve(frame.payload ?? {});
737
- return;
738
- }
739
- if (frame.type === 'pause') {
740
- controller.abort('paused');
741
- return;
742
- }
743
- if (frame.type === 'steer' || frame.type === 'follow-up') {
744
- void input.push({
745
- mode: frame.type,
746
- text: frame.messages?.[0]?.content ?? '',
747
- id: frame.callId || undefined
748
- });
749
- return;
750
- }
751
- if (frame.type === 'run-log-result') {
752
- if (typeof frame.callId !== 'string') {
753
- return;
754
- }
755
- const waiter = pendingRunLog.get(frame.callId);
756
- pendingRunLog.delete(frame.callId);
757
- if (!waiter) {
758
- return;
759
- }
760
- if (frame.message) {
761
- return waiter.reject(new Error(frame.message));
762
- }
763
- waiter.resolve();
764
- return;
765
- }
766
- if (started || (frame.type !== 'start' && frame.type !== 'invoke')) {
767
- return;
768
- }
769
- started = true;
770
- let startPayload;
771
- try {
772
- startPayload = startPayloadFrom(frame.payload);
773
- if (startPayload.goal) {
774
- checkGoal(startPayload.goal, frame.responseFormat);
775
- }
776
- assertEmptyIdentityMarkersMatchFrame(frame, startPayload.explicitEmptyIdentity ?? []);
777
- }
778
- catch (err) {
779
- events.push({ type: 'error', message: errorMessage(err) });
780
- events.push({ type: 'done' });
781
- events.end();
782
- return;
783
- }
784
- const explicitEmptyIdentity = new Set(startPayload.explicitEmptyIdentity ?? []);
785
- const runLog = startPayload.runLog;
786
- const resuming = startPayload.resume === true ||
787
- Boolean(isEngineBoot(runLog?.boot) && runLog.boot.metadata !== null);
788
- const requestDigestKey = runLog ? decodeDigestKey(runLog.digestKey) : undefined;
789
- const agent = normalizeAgentKnobs(frame.agent ?? {});
790
- if ((frame.agent?.id === null || frame.agent?.id === undefined) &&
791
- explicitEmptyIdentity.has('agent.id')) {
792
- agent.id = '';
793
- }
794
- if ((frame.agent?.name === null || frame.agent?.name === undefined) &&
795
- explicitEmptyIdentity.has('agent.name')) {
796
- agent.name = '';
797
- }
798
- if ((frame.agent?.bio === null || frame.agent?.bio === undefined) &&
799
- explicitEmptyIdentity.has('agent.bio')) {
800
- agent.bio = '';
801
- }
802
- const onStep = runLog
803
- ? (step) => {
804
- if (clientGone) {
805
- return Promise.reject(new Error('client gone'));
806
- }
807
- return new Promise((resolve, reject) => {
808
- const callId = String(calls++);
809
- pendingRunLog.set(callId, { resolve, reject });
810
- events.push({ type: 'run-log-append', callId, payload: step });
811
- });
812
- }
813
- : undefined;
814
- const context = {
815
- runId: frame.runId || undefined,
816
- resume: resuming,
817
- recovery: startPayload.resolutions ?? undefined,
818
- boot: isEngineBoot(runLog?.boot) ? runLog.boot : undefined,
819
- onStep,
820
- requestDigestKey,
821
- hostAppendTimeoutMs: runLog?.hostAppendTimeoutMs,
822
- model: frame.model ?? '',
823
- agent,
824
- cacheKey: frame.cacheKey ?? (explicitEmptyIdentity.has('cacheKey') ? '' : undefined),
825
- thinkingDefault: frame.thinkingDefault ?? (explicitEmptyIdentity.has('thinkingDefault') ? '' : undefined),
826
- generationParams: frame.generationParams ?? undefined,
827
- responseFormat: frame.responseFormat ?? undefined,
828
- captureInferenceCalls: frame.captureInferenceCalls ?? undefined,
829
- maxToolRounds: frame.maxToolRounds || undefined,
830
- knowledge: startPayload.knowledge,
831
- planMode: startPayload.planMode,
832
- parentRunId: startPayload.parentRunId,
833
- goal: startPayload.goal,
834
- messages: (frame.messages ?? []).map(({ role, content, attachments, toolCalls, toolCallId, name, id }) => ({
835
- role,
836
- content,
837
- attachments: attachments?.length
838
- ? attachments.map(({ path: file }) => ({ path: file }))
839
- : undefined,
840
- toolCalls: toolCalls ?? undefined,
841
- toolCallId: toolCallId ?? undefined,
842
- name: name ?? undefined,
843
- id: id || undefined
844
- })),
845
- toolConfigs: frame.toolConfigs ?? undefined,
846
- grantedDirs: frame.grantedDirs ?? undefined,
847
- grantedDrives: frame.grantedDrives?.length
848
- ? frame.grantedDrives.map((drive) => ({
849
- key: drive.key,
850
- writable: drive.writable === true
851
- }))
852
- : undefined,
853
- driveOp: frame.grantedDrives?.length
854
- ? (request) => controller.signal.aborted
855
- ? Promise.reject(new Error('client gone'))
856
- : new Promise((resolve, reject) => {
857
- const callId = String(calls++);
858
- pendingDrive.set(callId, {
859
- resolve,
860
- reject,
861
- path: request.op === 'write' ? request.path : undefined
862
- });
863
- events.push({ type: 'drive-ask', callId, op: request.op, payload: request });
864
- })
865
- : undefined,
866
- grantedWriteDirs: frame.grantedWriteDirs ?? undefined,
867
- signal: controller.signal,
868
- input,
869
- approve: (call) => new Promise((resolve) => {
870
- const callId = String(calls++);
871
- pending.set(callId, resolve);
872
- const frame = {
873
- type: 'approval-ask',
874
- callId,
875
- name: call.name,
876
- arguments: call.arguments,
877
- resource: call.resource ?? undefined,
878
- effect: call.effect,
879
- intent: call.intent ?? undefined,
880
- display: call.display ?? undefined,
881
- question: call.quote ?? undefined
882
- };
883
- if (call.callId !== undefined || call.round !== undefined) {
884
- frame.payload = { callId: call.callId, round: call.round };
885
- }
886
- events.push(frame);
887
- }),
888
- attach: async (input) => {
889
- const staged = await stageFile('attach', input.bytes);
890
- if (controller.signal.aborted) {
891
- void fs.promises.unlink(staged).catch(noop);
892
- throw new Error('client gone');
893
- }
894
- return new Promise((resolve, reject) => {
895
- const callId = String(calls++);
896
- pendingAttach.set(callId, { resolve, reject, staged });
897
- events.push({
898
- type: 'attach-ask',
899
- callId,
900
- path: staged,
901
- fileName: input.fileName,
902
- mimeType: input.mimeType,
903
- raw: input.raw ?? false
904
- });
905
- });
906
- },
907
- fetchAttachment: ({ attachmentId, meta } = {}) => controller.signal.aborted
908
- ? Promise.reject(new Error('client gone'))
909
- : new Promise((resolve, reject) => {
910
- const callId = String(calls++);
911
- pendingFetch.set(callId, { resolve, reject });
912
- events.push({
913
- type: 'fetch-ask',
914
- callId,
915
- attachmentId,
916
- meta: meta === true ? true : undefined
917
- });
918
- }),
919
- progress: (update) => {
920
- events.push(update
921
- ? { type: 'progress', percentage: update.percentage }
922
- : { type: 'progress', cleared: true });
923
- },
924
- askUser: (question) => controller.signal.aborted
925
- ? Promise.resolve(null)
926
- : new Promise((resolve, reject) => {
927
- const callId = String(calls++);
928
- pendingQuestion.set(callId, { resolve, reject });
929
- events.push({
930
- type: 'question-ask',
931
- callId,
932
- question: question.question,
933
- options: question.options
934
- });
935
- })
936
- };
937
- if (resuming) {
938
- for (const key of [
939
- 'model',
940
- 'agent',
941
- 'messages',
942
- 'cacheKey',
943
- 'thinkingDefault',
944
- 'generationParams',
945
- 'responseFormat'
946
- ]) {
947
- const value = frame[key];
948
- const explicitEmpty = (key === 'model' &&
949
- (frame.model === null || frame.model === undefined) &&
950
- explicitEmptyIdentity.has('model')) ||
951
- (key === 'cacheKey' &&
952
- (frame.cacheKey === null || frame.cacheKey === undefined) &&
953
- explicitEmptyIdentity.has('cacheKey')) ||
954
- (key === 'thinkingDefault' &&
955
- (frame.thinkingDefault === null || frame.thinkingDefault === undefined) &&
956
- explicitEmptyIdentity.has('thinkingDefault'));
957
- if ((value === null || value === undefined || value === '') && !explicitEmpty) {
958
- const mutableContext = context;
959
- delete mutableContext[key];
960
- }
961
- }
962
- }
963
- void (async () => {
964
- let produced = 0;
965
- let frames = 0;
966
- const textIdentity = {};
967
- const text = new TextCoalescer((type, merged) => {
968
- frames++;
969
- return events.push({ type, text: merged, ...textIdentity });
970
- }, { cap: TEXT_COALESCE_CAP, holdMs: TEXT_COALESCE_MS });
971
- try {
972
- if (runLog && !requestDigestKey) {
973
- throw new Error('The host did not provide a valid run-log digest key');
974
- }
975
- if (runLog?.boot &&
976
- (!isEngineBoot(runLog.boot) ||
977
- (runLog.boot.metadata !== null && runLog.boot.metadata.runId !== frame.runId))) {
978
- throw new Error('The host did not provide a valid run-log boot');
979
- }
980
- if (resuming && !onStep && !(await harness.capability?.())?.completionRecovery) {
981
- throw new Error('This peer does not support persistent completion recovery');
982
- }
983
- for await (const event of runFrame(harness, frame, context)) {
984
- produced++;
985
- if (!startPayload.recoveryEvents &&
986
- ['run-started', 'run-resumed', 'round-reset', 'recovery-required'].includes(event.type)) {
987
- continue;
988
- }
989
- const wire = !startPayload.recoveryEvents && event.type === 'paused'
990
- ? { type: 'aborted' }
991
- : toWire(event);
992
- if (await accumulateTextFrame(wire, textIdentity, text)) {
993
- continue;
994
- }
995
- await text.flush();
996
- frames++;
997
- await events.push(wire);
998
- }
999
- await text.flush();
1000
- }
1001
- catch (err) {
1002
- await text.flush();
1003
- events.push({ type: 'error', message: errorMessage(err) });
1004
- }
1005
- input.end();
1006
- events.push({ type: 'done' });
1007
- hlog('wire end', { produced, frames });
1008
- events.end();
1009
- })();
1010
- });
1011
- for await (const event of events) {
1012
- try {
1013
- encode('@harness/completion-event', event);
1014
- }
1015
- catch (err) {
1016
- yield { type: 'error', message: `cannot encode ${event.type} event: ${errorMessage(err)}` };
1017
- await tick();
1018
- yield { type: 'done' };
1019
- await tick();
1020
- gone();
1021
- return;
1022
- }
1023
- yield event;
1024
- await tick();
1025
- }
1026
- hlog('wire handed off');
1027
- };
1028
- }
1029
- function encodableDownloadEvent(wire) {
1030
- try {
1031
- encode('@harness/download-event', wire);
1032
- }
1033
- catch (err) {
1034
- throw new Error(`cannot encode ${wire.type} event: ${errorMessage(err)}`);
1035
- }
1036
- return wire;
1037
- }
1038
- async function accumulateTextFrame(wire, identity, text) {
1039
- if ((wire.type !== 'content' && wire.type !== 'thinking') || !wire.text) {
1040
- return false;
1041
- }
1042
- if (identity.runId !== wire.runId || identity.round !== wire.round) {
1043
- await text.flush();
1044
- }
1045
- identity.runId = wire.runId;
1046
- identity.round = wire.round;
1047
- await text.add(wire.type, wire.text);
1048
- return true;
1049
- }
1050
- function downloadStream(harness, req) {
1051
- const controller = new AbortController();
1052
- const stream = new Readable({
1053
- open(cb) {
1054
- void run();
1055
- cb(null);
1056
- },
1057
- destroy(cb) {
1058
- controller.abort('client gone');
1059
- cb(null);
1060
- }
1061
- });
1062
- const run = async () => {
1063
- if (!harness.download) {
1064
- stream.push({
1065
- type: 'error',
1066
- message: 'harness does not support download'
1067
- });
1068
- stream.push(null);
1069
- return;
1070
- }
1071
- let pendingProgress = null;
1072
- let lastProgressAt = 0;
1073
- const flushProgress = (at = Date.now()) => {
1074
- if (pendingProgress === null)
1075
- return;
1076
- stream.push(pendingProgress);
1077
- pendingProgress = null;
1078
- lastProgressAt = at;
1079
- };
1080
- const queueProgress = (wire) => {
1081
- const now = Date.now();
1082
- pendingProgress = wire;
1083
- if (lastProgressAt === 0 || now - lastProgressAt >= DOWNLOAD_PROGRESS_INTERVAL_MS) {
1084
- flushProgress(now);
1085
- }
1086
- };
1087
- try {
1088
- for await (const event of harness.download({
1089
- model: req.model,
1090
- addon: req.addon,
1091
- seed: req.seed,
1092
- signal: controller.signal
1093
- })) {
1094
- const wire = encodableDownloadEvent(toDownloadWire(event));
1095
- if (wire.type === 'progress') {
1096
- queueProgress(wire);
1097
- continue;
1098
- }
1099
- flushProgress();
1100
- stream.push(wire);
1101
- }
1102
- flushProgress();
1103
- }
1104
- catch (err) {
1105
- if (!controller.signal.aborted) {
1106
- flushProgress();
1107
- stream.push({ type: 'error', message: errorMessage(err) });
1108
- }
1109
- }
1110
- stream.push(null);
1111
- };
1112
- return stream;
246
+ export class HarnessServer {
247
+ static serve = serveHarness;
1113
248
  }