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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (404) hide show
  1. package/.nvmrc +1 -0
  2. package/CHANGELOG.md +2280 -1485
  3. package/README.md +56 -43
  4. package/dist-lib/index.d.ts +50 -6
  5. package/dist-lib/index.js +130 -28
  6. package/dist-lib/lib/agent/delegate.d.ts +3 -2
  7. package/dist-lib/lib/agent/delegate.js +6 -4
  8. package/dist-lib/lib/agent/follow.d.ts +5 -0
  9. package/dist-lib/lib/agent/follow.js +2 -0
  10. package/dist-lib/lib/agent/resolve.js +22 -17
  11. package/dist-lib/lib/agent/tool-selection.d.ts +4 -2
  12. package/dist-lib/lib/agent/tool-selection.js +5 -6
  13. package/dist-lib/lib/agent/tools.d.ts +1 -0
  14. package/dist-lib/lib/agent/tools.js +2 -1
  15. package/dist-lib/lib/capabilities/agent-ports.js +3 -3
  16. package/dist-lib/lib/capabilities/completion-engine/actors/batching.js +1 -0
  17. package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +2 -0
  18. package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +60 -9
  19. package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +4 -4
  20. package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.js +3 -2
  21. package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +35 -6
  22. package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.d.ts +1 -1
  23. package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +2 -0
  24. package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +67 -27
  25. package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +6 -1
  26. package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +61 -16
  27. package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +2 -2
  28. package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +23 -13
  29. package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +8 -3
  30. package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +61 -3
  31. package/dist-lib/lib/capabilities/completion-engine/actors/streaming.d.ts +5 -1
  32. package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +47 -21
  33. package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +1 -0
  34. package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +30 -5
  35. package/dist-lib/lib/capabilities/completion-engine/driver.js +27 -11
  36. package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +1 -0
  37. package/dist-lib/lib/capabilities/completion-engine/durable.js +5 -1
  38. package/dist-lib/lib/capabilities/completion-engine/index.d.ts +2 -1
  39. package/dist-lib/lib/capabilities/completion-engine/index.js +2 -2
  40. package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +15 -2
  41. package/dist-lib/lib/capabilities/completion-engine/loop.js +7 -0
  42. package/dist-lib/lib/capabilities/completion-engine/metrics.d.ts +9 -2
  43. package/dist-lib/lib/capabilities/completion-engine/metrics.js +28 -7
  44. package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +46 -0
  45. package/dist-lib/lib/capabilities/completion-engine/model-round.js +45 -0
  46. package/dist-lib/lib/capabilities/completion-engine/operations.js +1 -1
  47. package/dist-lib/lib/capabilities/completion-engine/ports.js +3 -7
  48. package/dist-lib/lib/capabilities/completion-engine/round.d.ts +23 -3
  49. package/dist-lib/lib/capabilities/completion-engine/round.js +323 -97
  50. package/dist-lib/lib/capabilities/completion-engine/session.d.ts +10 -3
  51. package/dist-lib/lib/capabilities/completion-engine/session.js +30 -2
  52. package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +3 -2
  53. package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +4 -3
  54. package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +15 -10
  55. package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +11 -4
  56. package/dist-lib/lib/capabilities/completion-engine/turns.js +48 -65
  57. package/dist-lib/lib/capabilities/download.d.ts +9 -7
  58. package/dist-lib/lib/capabilities/download.js +1 -1
  59. package/dist-lib/lib/capabilities/enhance.d.ts +1 -1
  60. package/dist-lib/lib/capabilities/enhance.js +20 -8
  61. package/dist-lib/lib/capabilities/preview-model-source.d.ts +7 -0
  62. package/dist-lib/lib/capabilities/preview-model-source.js +83 -23
  63. package/dist-lib/lib/capabilities/sdk-tool.d.ts +1 -0
  64. package/dist-lib/lib/capabilities/sdk-tool.js +18 -1
  65. package/dist-lib/lib/capabilities/tool-plan.d.ts +1 -1
  66. package/dist-lib/lib/capabilities/tool-plan.js +5 -5
  67. package/dist-lib/lib/capabilities/tool-prompt-log.js +3 -3
  68. package/dist-lib/lib/capabilities/tool-turns.d.ts +7 -9
  69. package/dist-lib/lib/capabilities/tool-turns.js +25 -20
  70. package/dist-lib/lib/client/index.d.ts +19 -0
  71. package/dist-lib/lib/client/index.js +262 -0
  72. package/dist-lib/lib/connect.d.ts +13 -10
  73. package/dist-lib/lib/connect.js +62 -24
  74. package/dist-lib/lib/context-window.d.ts +1 -0
  75. package/dist-lib/lib/context-window.js +3 -3
  76. package/dist-lib/lib/contract/agent.d.ts +7 -3
  77. package/dist-lib/lib/contract/completion.d.ts +44 -29
  78. package/dist-lib/lib/contract/egress-proxy.d.ts +13 -0
  79. package/dist-lib/lib/contract/egress-proxy.js +1 -0
  80. package/dist-lib/lib/contract/exec.d.ts +3 -3
  81. package/dist-lib/lib/contract/hooks.d.ts +4 -1
  82. package/dist-lib/lib/contract/index.d.ts +1 -0
  83. package/dist-lib/lib/contract/models.d.ts +6 -4
  84. package/dist-lib/lib/contract/policy.d.ts +75 -0
  85. package/dist-lib/lib/contract/policy.js +1 -0
  86. package/dist-lib/lib/contract/run.d.ts +9 -3
  87. package/dist-lib/lib/contract/sandbox.d.ts +3 -1
  88. package/dist-lib/lib/contract/translation.d.ts +20 -0
  89. package/dist-lib/lib/contract/translation.js +1 -0
  90. package/dist-lib/lib/contract-types.d.ts +32 -14
  91. package/dist-lib/lib/embeddings/index.d.ts +7 -1
  92. package/dist-lib/lib/embeddings/index.js +26 -5
  93. package/dist-lib/lib/errors.d.ts +266 -0
  94. package/dist-lib/lib/errors.js +198 -0
  95. package/dist-lib/lib/fold/index.d.ts +25 -1
  96. package/dist-lib/lib/fold/index.js +75 -9
  97. package/dist-lib/lib/guarded-fetch.js +11 -7
  98. package/dist-lib/lib/hardware/gpu-probe.js +10 -1
  99. package/dist-lib/lib/helpers/completion-params.d.ts +6 -2
  100. package/dist-lib/lib/helpers/completion-params.js +10 -1
  101. package/dist-lib/lib/helpers/engine-error.d.ts +2 -1
  102. package/dist-lib/lib/helpers/engine-error.js +12 -12
  103. package/dist-lib/lib/helpers/goal-check.d.ts +4 -0
  104. package/dist-lib/lib/helpers/goal-check.js +81 -0
  105. package/dist-lib/lib/helpers/head-tail.js +1 -1
  106. package/dist-lib/lib/helpers/load-stall.d.ts +1 -1
  107. package/dist-lib/lib/helpers/load-stall.js +2 -2
  108. package/dist-lib/lib/helpers/markup-stream-filter.d.ts +4 -1
  109. package/dist-lib/lib/helpers/markup-stream-filter.js +20 -6
  110. package/dist-lib/lib/helpers/repeated-reply.js +24 -16
  111. package/dist-lib/lib/helpers/thinking.d.ts +3 -2
  112. package/dist-lib/lib/helpers/thinking.js +19 -0
  113. package/dist-lib/lib/hooks/built-in/arg-repair.js +6 -2
  114. package/dist-lib/lib/hooks/built-in/policy-rules.d.ts +8 -0
  115. package/dist-lib/lib/hooks/built-in/policy-rules.js +192 -0
  116. package/dist-lib/lib/hooks/built-in/sandbox.js +23 -5
  117. package/dist-lib/lib/hooks/index.d.ts +4 -1
  118. package/dist-lib/lib/hooks/index.js +9 -4
  119. package/dist-lib/lib/hooks/run.js +3 -3
  120. package/dist-lib/lib/lifecycle/index.js +15 -14
  121. package/dist-lib/lib/lifecycle/machine.js +2 -2
  122. package/dist-lib/lib/log.d.ts +26 -5
  123. package/dist-lib/lib/log.js +86 -23
  124. package/dist-lib/lib/machine/completion/actions/completion.d.ts +4 -2
  125. package/dist-lib/lib/machine/completion/actions/completion.js +75 -10
  126. package/dist-lib/lib/machine/completion/actions/prepare.js +1 -1
  127. package/dist-lib/lib/machine/completion/actions/tools.js +48 -5
  128. package/dist-lib/lib/machine/completion/context.js +4 -1
  129. package/dist-lib/lib/machine/completion/guards/retry.d.ts +1 -0
  130. package/dist-lib/lib/machine/completion/guards/retry.js +8 -2
  131. package/dist-lib/lib/machine/completion/implementations.d.ts +10 -4
  132. package/dist-lib/lib/machine/completion/implementations.js +27 -6
  133. package/dist-lib/lib/machine/completion/machine.d.ts +21 -3
  134. package/dist-lib/lib/machine/completion/machine.js +33 -4
  135. package/dist-lib/lib/machine/completion/rules.d.ts +17 -2
  136. package/dist-lib/lib/machine/completion/rules.js +49 -3
  137. package/dist-lib/lib/machine/completion/types.d.ts +36 -0
  138. package/dist-lib/lib/machine/index.d.ts +27 -4
  139. package/dist-lib/lib/machine/index.js +6 -1
  140. package/dist-lib/lib/models/context-choice.d.ts +15 -0
  141. package/dist-lib/lib/models/context-choice.js +55 -0
  142. package/dist-lib/lib/models/download-gate.d.ts +20 -0
  143. package/dist-lib/lib/models/download-gate.js +73 -0
  144. package/dist-lib/lib/models/gguf-header.d.ts +5 -0
  145. package/dist-lib/lib/models/gguf-header.js +165 -14
  146. package/dist-lib/lib/models/llm-presets.d.ts +5 -1
  147. package/dist-lib/lib/models/llm-presets.js +6 -5
  148. package/dist-lib/lib/models/memory-cap.d.ts +13 -0
  149. package/dist-lib/lib/models/memory-cap.js +21 -0
  150. package/dist-lib/lib/models/model-catalog.d.ts +2 -0
  151. package/dist-lib/lib/models/model-catalog.js +15 -0
  152. package/dist-lib/lib/models/model-fit.d.ts +1 -1
  153. package/dist-lib/lib/models/model-fit.js +5 -6
  154. package/dist-lib/lib/models/model-handle.d.ts +8 -2
  155. package/dist-lib/lib/models/model-handle.js +14 -3
  156. package/dist-lib/lib/models/model-list.d.ts +8 -1
  157. package/dist-lib/lib/models/model-list.js +23 -0
  158. package/dist-lib/lib/models/model-pool.d.ts +35 -5
  159. package/dist-lib/lib/models/model-pool.js +121 -43
  160. package/dist-lib/lib/models/model-source.d.ts +1 -0
  161. package/dist-lib/lib/models/model-source.js +23 -5
  162. package/dist-lib/lib/models/sdk-faults.d.ts +1 -0
  163. package/dist-lib/lib/models/sdk-faults.js +9 -0
  164. package/dist-lib/lib/no-redirect-fetch-bare.js +2 -1
  165. package/dist-lib/lib/no-redirect-fetch-impl.js +2 -1
  166. package/dist-lib/lib/office/engine/pptx/picture-area.d.ts +23 -0
  167. package/dist-lib/lib/office/engine/pptx/picture-area.js +84 -0
  168. package/dist-lib/lib/office/engine/pptx/presentation.d.ts +2 -0
  169. package/dist-lib/lib/office/engine/pptx/presentation.js +55 -17
  170. package/dist-lib/lib/office/engine/pptx/types.d.ts +1 -0
  171. package/dist-lib/lib/office/engine/xlsx/workbook.d.ts +1 -0
  172. package/dist-lib/lib/office/engine/xlsx/workbook.js +34 -3
  173. package/dist-lib/lib/office/extract.js +4 -3
  174. package/dist-lib/lib/office/index.js +2 -1
  175. package/dist-lib/lib/plugins/registry.d.ts +3 -0
  176. package/dist-lib/lib/plugins/registry.js +16 -7
  177. package/dist-lib/lib/policy/index.d.ts +10 -0
  178. package/dist-lib/lib/policy/index.js +229 -0
  179. package/dist-lib/lib/prompt.d.ts +1 -0
  180. package/dist-lib/lib/prompt.js +7 -1
  181. package/dist-lib/lib/residency/completion-runtime.d.ts +1 -0
  182. package/dist-lib/lib/residency/completion-runtime.js +11 -4
  183. package/dist-lib/lib/residency/index.d.ts +44 -4
  184. package/dist-lib/lib/residency/index.js +399 -35
  185. package/dist-lib/lib/resolution-detector.js +3 -3
  186. package/dist-lib/lib/rpc-session.js +2 -1
  187. package/dist-lib/lib/sdk-loader.js +17 -11
  188. package/dist-lib/lib/serve.js +76 -36
  189. package/dist-lib/lib/sidecar/index.d.ts +29 -0
  190. package/dist-lib/lib/sidecar/index.js +174 -0
  191. package/dist-lib/lib/sidecar/user-plugins.d.ts +8 -0
  192. package/dist-lib/lib/sidecar/user-plugins.js +117 -0
  193. package/dist-lib/lib/skills-host/index.d.ts +1 -0
  194. package/dist-lib/lib/skills-host/index.js +8 -4
  195. package/dist-lib/lib/spawn.d.ts +3 -4
  196. package/dist-lib/lib/spawn.js +17 -17
  197. package/dist-lib/lib/spill.d.ts +1 -0
  198. package/dist-lib/lib/spill.js +12 -8
  199. package/dist-lib/lib/tools/attachments/staging.js +8 -8
  200. package/dist-lib/lib/tools/exec/runner.js +2 -1
  201. package/dist-lib/lib/tools/exec/scope.d.ts +0 -1
  202. package/dist-lib/lib/tools/exec/scope.js +23 -114
  203. package/dist-lib/lib/tools/exec/shell-guidance.js +4 -4
  204. package/dist-lib/lib/tools/exec/shell-line.d.ts +26 -0
  205. package/dist-lib/lib/tools/exec/shell-line.js +334 -0
  206. package/dist-lib/lib/tools/exec.d.ts +4 -1
  207. package/dist-lib/lib/tools/exec.js +87 -26
  208. package/dist-lib/lib/tools/files/edit-file.d.ts +3 -0
  209. package/dist-lib/lib/tools/files/edit-file.js +74 -0
  210. package/dist-lib/lib/tools/files/glob.d.ts +3 -0
  211. package/dist-lib/lib/tools/files/glob.js +65 -0
  212. package/dist-lib/lib/tools/files/grep.d.ts +6 -0
  213. package/dist-lib/lib/tools/files/grep.js +114 -0
  214. package/dist-lib/lib/tools/files/index.d.ts +3 -0
  215. package/dist-lib/lib/tools/files/index.js +23 -0
  216. package/dist-lib/lib/tools/files/list-dir.d.ts +6 -0
  217. package/dist-lib/lib/tools/files/list-dir.js +136 -0
  218. package/dist-lib/lib/tools/files/make-dir.d.ts +3 -0
  219. package/dist-lib/lib/tools/files/make-dir.js +48 -0
  220. package/dist-lib/lib/tools/files/read-file.d.ts +3 -0
  221. package/dist-lib/lib/tools/files/read-file.js +105 -0
  222. package/dist-lib/lib/tools/files/transfer.d.ts +4 -0
  223. package/dist-lib/lib/tools/files/transfer.js +83 -0
  224. package/dist-lib/lib/tools/files/trash-file.d.ts +4 -0
  225. package/dist-lib/lib/tools/files/trash-file.js +62 -0
  226. package/dist-lib/lib/tools/files/write-file.d.ts +3 -0
  227. package/dist-lib/lib/tools/files/write-file.js +56 -0
  228. package/dist-lib/lib/tools/fs/document-text.d.ts +2 -0
  229. package/dist-lib/lib/tools/fs/document-text.js +38 -0
  230. package/dist-lib/lib/tools/fs/drive.d.ts +14 -3
  231. package/dist-lib/lib/tools/fs/drive.js +9 -1
  232. package/dist-lib/lib/tools/fs/edit-match.d.ts +11 -0
  233. package/dist-lib/lib/tools/fs/edit-match.js +85 -0
  234. package/dist-lib/lib/tools/fs/ignore.d.ts +13 -0
  235. package/dist-lib/lib/tools/fs/ignore.js +104 -0
  236. package/dist-lib/lib/tools/fs/local.js +28 -5
  237. package/dist-lib/lib/tools/fs/remote-protocol.d.ts +23 -3
  238. package/dist-lib/lib/tools/fs/remote.d.ts +3 -4
  239. package/dist-lib/lib/tools/fs/remote.js +23 -13
  240. package/dist-lib/lib/tools/fs/scope.d.ts +5 -1
  241. package/dist-lib/lib/tools/fs/scope.js +5 -2
  242. package/dist-lib/lib/tools/fs/search.d.ts +41 -0
  243. package/dist-lib/lib/tools/fs/search.js +382 -0
  244. package/dist-lib/lib/tools/{file-glob.d.ts → fs/targets.d.ts} +1 -5
  245. package/dist-lib/lib/tools/fs/targets.js +32 -0
  246. package/dist-lib/lib/tools/fs/tool-path.d.ts +27 -0
  247. package/dist-lib/lib/tools/fs/tool-path.js +70 -0
  248. package/dist-lib/lib/tools/fs/walk.d.ts +15 -3
  249. package/dist-lib/lib/tools/fs/walk.js +118 -24
  250. package/dist-lib/lib/tools/http-request.js +12 -2
  251. package/dist-lib/lib/tools/index.js +2 -10
  252. package/dist-lib/lib/tools/office/ops.js +1 -1
  253. package/dist-lib/lib/tools/office.js +77 -21
  254. package/dist-lib/lib/tools/pdf/build.d.ts +5 -1
  255. package/dist-lib/lib/tools/pdf/build.js +31 -6
  256. package/dist-lib/lib/tools/pdf.js +17 -2
  257. package/dist-lib/lib/tools/skill.js +10 -7
  258. package/dist-lib/lib/tools/skills/bundled-dir.js +4 -4
  259. package/dist-lib/lib/tools/skills/catalog.d.ts +2 -0
  260. package/dist-lib/lib/tools/skills/catalog.js +6 -2
  261. package/dist-lib/lib/tools/skills/cli-argv.js +25 -5
  262. package/dist-lib/lib/tools/skills/cli-schema-check.d.ts +1 -0
  263. package/dist-lib/lib/tools/skills/cli-schema-check.js +3 -0
  264. package/dist-lib/lib/tools/skills/cli-schema-load.js +10 -0
  265. package/dist-lib/lib/tools/skills/cli-schema-types.d.ts +2 -0
  266. package/dist-lib/lib/tools/skills/cli-schema.js +6 -3
  267. package/dist-lib/lib/tools/skills/credential-health.js +3 -3
  268. package/dist-lib/lib/tools/skills/frontmatter-parser.d.ts +2 -0
  269. package/dist-lib/lib/tools/skills/frontmatter-parser.js +4 -0
  270. package/dist-lib/lib/tools/skills/manifest-parse.d.ts +1 -0
  271. package/dist-lib/lib/tools/skills/manifest-parse.js +12 -0
  272. package/dist-lib/lib/tools/skills/mention-name.d.ts +6 -0
  273. package/dist-lib/lib/tools/skills/mention-name.js +6 -0
  274. package/dist-lib/lib/tools/skills/mention.d.ts +2 -2
  275. package/dist-lib/lib/tools/skills/mention.js +11 -4
  276. package/dist-lib/lib/tools/skills/overlay-crud.js +3 -2
  277. package/dist-lib/lib/tools/url-guard.d.ts +6 -1
  278. package/dist-lib/lib/tools/url-guard.js +8 -2
  279. package/dist-lib/lib/tools/web-fetch.js +10 -4
  280. package/dist-lib/lib/wire.js +3 -5
  281. package/dist-lib/plugins/coding/index.d.ts +1 -1
  282. package/dist-lib/plugins/coding/index.js +2 -4
  283. package/dist-lib/plugins/coding/session.d.ts +3 -3
  284. package/dist-lib/plugins/coding/session.js +26 -14
  285. package/dist-lib/plugins/command-hooks/index.js +5 -3
  286. package/dist-lib/plugins/egress-proxy/index.d.ts +53 -0
  287. package/dist-lib/plugins/egress-proxy/index.js +182 -0
  288. package/dist-lib/plugins/image/edit-image.js +4 -3
  289. package/dist-lib/plugins/image/generate-image.d.ts +4 -3
  290. package/dist-lib/plugins/image/generate-image.js +10 -9
  291. package/dist-lib/plugins/image/index.d.ts +1 -1
  292. package/dist-lib/plugins/image/index.js +13 -10
  293. package/dist-lib/plugins/language-hint/index.d.ts +15 -0
  294. package/dist-lib/plugins/language-hint/index.js +51 -0
  295. package/dist-lib/plugins/lsp/tool.js +2 -2
  296. package/dist-lib/plugins/mcp/index.js +6 -3
  297. package/dist-lib/plugins/music/generate-music.d.ts +4 -2
  298. package/dist-lib/plugins/music/generate-music.js +7 -4
  299. package/dist-lib/plugins/music/index.js +12 -9
  300. package/dist-lib/plugins/obsidian/command.js +2 -2
  301. package/dist-lib/plugins/obsidian/note-name.js +2 -1
  302. package/dist-lib/plugins/obsidian/safe-path.js +5 -4
  303. package/dist-lib/plugins/obsidian/vault-create.js +3 -2
  304. package/dist-lib/plugins/obsidian/vault-fs.js +2 -2
  305. package/dist-lib/plugins/obsidian/vault-paths.js +3 -2
  306. package/dist-lib/plugins/obsidian/vault-read.js +6 -5
  307. package/dist-lib/plugins/obsidian/vault-write.js +13 -12
  308. package/dist-lib/plugins/python/guarded-fetch.d.ts +2 -1
  309. package/dist-lib/plugins/python/guarded-fetch.js +5 -1
  310. package/dist-lib/plugins/python/interrupt-timer.js +2 -2
  311. package/dist-lib/plugins/python/loader.js +68 -3
  312. package/dist-lib/plugins/python/memfs.js +2 -2
  313. package/dist-lib/plugins/python/pyodide.d.ts +1 -0
  314. package/dist-lib/plugins/python/pyodide.js +9 -8
  315. package/dist-lib/plugins/python/python-adapter.js +3 -1
  316. package/dist-lib/plugins/python/run-session.d.ts +1 -0
  317. package/dist-lib/plugins/python/run-session.js +19 -8
  318. package/dist-lib/plugins/python/wheels.js +8 -6
  319. package/dist-lib/plugins/python/worker/active.js +2 -2
  320. package/dist-lib/plugins/python/worker/client.js +9 -8
  321. package/dist-lib/plugins/python/worker/protocol.d.ts +2 -0
  322. package/dist-lib/plugins/python/worker/serve.js +23 -4
  323. package/dist-lib/plugins/python/worker/spawn.d.ts +2 -1
  324. package/dist-lib/plugins/python/worker/spawn.js +2 -1
  325. package/dist-lib/plugins/run-report/chain.d.ts +2 -0
  326. package/dist-lib/plugins/run-report/chain.js +73 -0
  327. package/dist-lib/plugins/run-report/flow-view.js +2 -1
  328. package/dist-lib/plugins/run-report/flow.d.ts +1 -1
  329. package/dist-lib/plugins/run-report/flow.js +66 -14
  330. package/dist-lib/plugins/run-report/index.d.ts +23 -2
  331. package/dist-lib/plugins/run-report/index.js +27 -12
  332. package/dist-lib/plugins/run-report/model.d.ts +10 -1
  333. package/dist-lib/plugins/run-report/model.js +12 -6
  334. package/dist-lib/plugins/run-report/page.d.ts +9 -0
  335. package/dist-lib/plugins/run-report/page.js +55 -15
  336. package/dist-lib/plugins/run-report/script.js +317 -43
  337. package/dist-lib/plugins/run-report/story.d.ts +2 -1
  338. package/dist-lib/plugins/run-report/story.js +3 -3
  339. package/dist-lib/plugins/run-report/style.d.ts +1 -1
  340. package/dist-lib/plugins/run-report/style.js +126 -0
  341. package/dist-lib/plugins/run-report/why.js +1 -1
  342. package/dist-lib/plugins/sandbox-linux/index.d.ts +60 -0
  343. package/dist-lib/plugins/sandbox-linux/index.js +347 -0
  344. package/dist-lib/plugins/sandbox-linux/seccomp.d.ts +2 -0
  345. package/dist-lib/plugins/sandbox-linux/seccomp.js +74 -0
  346. package/dist-lib/plugins/sandbox-macos/index.d.ts +23 -11
  347. package/dist-lib/plugins/sandbox-macos/index.js +239 -49
  348. package/dist-lib/plugins/sandbox-vm/vm-shell.d.ts +4 -2
  349. package/dist-lib/plugins/sandbox-vm/vm-shell.js +9 -4
  350. package/dist-lib/plugins/sandbox-windows/helper/qvac-sandbox.c +554 -0
  351. package/dist-lib/plugins/sandbox-windows/index.d.ts +53 -0
  352. package/dist-lib/plugins/sandbox-windows/index.js +205 -0
  353. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  354. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  355. package/dist-lib/plugins/speech/audio-resample.d.ts +1 -1
  356. package/dist-lib/plugins/speech/audio-resample.js +7 -8
  357. package/dist-lib/plugins/speech/audio-transcode-bare.d.ts +1 -1
  358. package/dist-lib/plugins/speech/audio-transcode-bare.js +23 -26
  359. package/dist-lib/plugins/speech/audio-transcode-node.d.ts +1 -1
  360. package/dist-lib/plugins/speech/audio-transcode-node.js +1 -3
  361. package/dist-lib/plugins/speech/speech-runtime.js +37 -37
  362. package/dist-lib/plugins/speech/voice.d.ts +5 -1
  363. package/dist-lib/plugins/speech/voice.js +100 -31
  364. package/dist-lib/plugins/translation/index.d.ts +1 -0
  365. package/dist-lib/plugins/translation/index.js +16 -9
  366. package/dist-lib/plugins/translation/translate.d.ts +7 -3
  367. package/dist-lib/plugins/translation/translate.js +64 -58
  368. package/dist-lib/plugins/weather/geocode.js +2 -1
  369. package/dist-lib/plugins/weather/lookup.js +5 -4
  370. package/dist-lib/plugins/web-search/engines/bing.js +2 -1
  371. package/dist-lib/plugins/web-search/engines/google.js +2 -1
  372. package/dist-lib/plugins/web-search/fetch-html.d.ts +5 -5
  373. package/dist-lib/plugins/web-search/fetch-html.js +12 -15
  374. package/dist-lib/plugins/web-search/tool.js +1 -0
  375. package/dist-lib/schema/harness.js +48 -7
  376. package/dist-lib/spec/bind.js +9 -0
  377. package/dist-lib/spec/calls.js +3 -0
  378. package/dist-lib/spec/hrpc/hrpc.json +42 -3
  379. package/dist-lib/spec/hrpc/index.js +44 -8
  380. package/dist-lib/spec/hrpc/messages.js +297 -202
  381. package/dist-lib/spec/hyperschema/index.js +297 -202
  382. package/dist-lib/spec/hyperschema/schema.json +155 -84
  383. package/dist-lib/spec/hyperschema/types.d.ts +23 -3
  384. package/package.json +101 -38
  385. package/patches/@qvac%2Finference@0.22.0.patch +59 -0
  386. package/patches/pyodide@314.0.2.patch +37 -8
  387. package/scripts/addon-externals.cjs +10 -5
  388. package/worker/harness-sidecar.mjs +18 -154
  389. package/dist-lib/lib/tools/create-documents.d.ts +0 -3
  390. package/dist-lib/lib/tools/create-documents.js +0 -95
  391. package/dist-lib/lib/tools/edit-documents.d.ts +0 -3
  392. package/dist-lib/lib/tools/edit-documents.js +0 -132
  393. package/dist-lib/lib/tools/exec/shell-argv.d.ts +0 -2
  394. package/dist-lib/lib/tools/exec/shell-argv.js +0 -61
  395. package/dist-lib/lib/tools/file-glob.js +0 -118
  396. package/dist-lib/lib/tools/grep.d.ts +0 -5
  397. package/dist-lib/lib/tools/grep.js +0 -184
  398. package/dist-lib/lib/tools/read-files.d.ts +0 -5
  399. package/dist-lib/lib/tools/read-files.js +0 -160
  400. package/dist-lib/plugins/coding/write-file.d.ts +0 -3
  401. package/dist-lib/plugins/coding/write-file.js +0 -52
  402. package/patches/@qvac%2Finference@0.21.0.patch +0 -67
  403. package/patches/bare-stow@0.1.5.patch +0 -68
  404. package/patches/hypercore-blob-server@1.15.0.patch +0 -15
@@ -1,9 +1,11 @@
1
1
  import b4a from 'b4a';
2
2
  import { randomBytes } from 'crypto';
3
3
  import path from 'path';
4
+ import { Policy } from '../../lib/policy/index.js';
5
+ import { HarnessError } from '../../lib/errors.js';
4
6
  import { isRecord } from '../../lib/guards.js';
5
7
  import { appendOutput, createCapturedOutput, formatOutput, MAX_OUTPUT_CHARS } from '../../lib/tools/exec/runner.js';
6
- import { canonicalDenyRoots, defaultRealpath, overlaps, resolveKey } from '../../lib/tools/fs/scope.js';
8
+ import { callDenyRoots, defaultRealpath, overlaps, resolveKey } from '../../lib/tools/fs/scope.js';
7
9
  const STATE_DIR = '"$__qvac_dir"';
8
10
  const SHELL_TIMEOUT_MS = 300_000;
9
11
  const MAX_TIMEOUT_MS = 1_800_000;
@@ -11,7 +13,7 @@ const NO_WORKSPACE = 'the coding tools need one writable directory granted to th
11
13
  const DRIVE_WORKSPACE = 'the coding tools work in a local project folder, not a drive or a filesystem root';
12
14
  const DENIED_WORKSPACE = 'the coding tools need a project folder that neither holds nor sits in a protected app folder';
13
15
  const DRIVE_PATH = 'the coding tools take a local path inside the project, not a drive path';
14
- const NOT_ISOLATED = 'sandbox mode is on and this sandbox is not isolated, so the coding tools are off';
16
+ const NOT_ISOLATED = 'the network is off and this sandbox is not isolated, so the coding tools are off';
15
17
  const BUDGET_SPENT = 'run wall-clock budget exhausted; no time remains for this call';
16
18
  export function guidance(error) {
17
19
  return { error, guidance: true };
@@ -24,7 +26,7 @@ export function shellQuote(text) {
24
26
  }
25
27
  export function errorText(error) {
26
28
  if (error instanceof Error) {
27
- return error.name === 'AbortError' || error.name === 'AbortedError'
29
+ return error.name === 'AbortError' || HarnessError.is(error, 'ABORTED')
28
30
  ? 'command aborted'
29
31
  : error.message;
30
32
  }
@@ -44,7 +46,7 @@ function workspaceRoot(ctx) {
44
46
  }
45
47
  return root;
46
48
  }
47
- export async function workspaceKey(root, input) {
49
+ async function workspaceKey(root, input) {
48
50
  if (input.includes('://')) {
49
51
  return { error: DRIVE_PATH };
50
52
  }
@@ -89,25 +91,29 @@ export class CodingSession {
89
91
  _bind;
90
92
  _workspaces;
91
93
  _runs;
94
+ _keys;
92
95
  constructor(sandbox, deniedRoots = []) {
93
96
  this.sandbox = sandbox;
94
97
  this.deniedRoots = deniedRoots;
95
98
  this._bind = `__qvac_dir="\${TMPDIR:-/tmp}"/qvac-coding-${b4a.toHex(randomBytes(8))}`;
96
99
  this._workspaces = new Map();
97
100
  this._runs = new Map();
101
+ this._keys = new Map();
98
102
  }
99
103
  effect(ctx) {
100
104
  return ctx?.planMode || !this.sandbox.isolated ? 'write' : 'read';
101
105
  }
102
106
  refusal(ctx) {
103
- return ctx?.sandboxMode && !this.sandbox.isolated ? guidance(NOT_ISOLATED) : null;
107
+ return ctx?.policy?.network.mode === 'off' && !this.sandbox.isolated
108
+ ? guidance(NOT_ISOLATED)
109
+ : null;
104
110
  }
105
111
  async workspace(ctx) {
106
112
  const root = this.refusal(ctx) ?? workspaceRoot(ctx);
107
113
  if (isError(root)) {
108
114
  return root;
109
115
  }
110
- const deny = await canonicalDenyRoots(this.deniedRoots, defaultRealpath);
116
+ const deny = await callDenyRoots(this.deniedRoots, ctx?.policy, defaultRealpath);
111
117
  return deny.some((each) => overlaps(root.root, each)) ? guidance(DENIED_WORKSPACE) : root;
112
118
  }
113
119
  policyVersion() {
@@ -120,19 +126,21 @@ export class CodingSession {
120
126
  statePath(runId) {
121
127
  return `${STATE_DIR}/${b4a.toHex(b4a.from(runId))}`;
122
128
  }
123
- open(root, runId) {
129
+ open(root, runId, policy) {
130
+ const key = `${root.root}\0${JSON.stringify(policy)}`;
124
131
  this._runs.set(runId, root.root);
125
- let workspace = this._workspaces.get(root.root);
132
+ this._keys.set(runId, key);
133
+ let workspace = this._workspaces.get(key);
126
134
  if (!workspace) {
127
- workspace = this.sandbox.open(root.root);
128
- workspace.catch(() => this._workspaces.delete(root.root));
129
- this._workspaces.set(root.root, workspace);
135
+ workspace = this.sandbox.open(root.root, policy);
136
+ workspace.catch(() => this._workspaces.delete(key));
137
+ this._workspaces.set(key, workspace);
130
138
  }
131
139
  return workspace;
132
140
  }
133
141
  workspaceOf(runId) {
134
- const dir = this._runs.get(runId);
135
- return dir === undefined ? null : (this._workspaces.get(dir) ?? null);
142
+ const key = this._keys.get(runId);
143
+ return key === undefined ? null : (this._workspaces.get(key) ?? null);
136
144
  }
137
145
  _prelude(runId) {
138
146
  return [
@@ -171,6 +179,7 @@ export class CodingSession {
171
179
  async endRun(runId) {
172
180
  const workspace = this.workspaceOf(runId);
173
181
  this._runs.delete(runId);
182
+ this._keys.delete(runId);
174
183
  if (workspace) {
175
184
  const state = this.statePath(runId);
176
185
  await this.execState(await workspace, `rm -f ${state}.env ${state}.cwd ${state}.tmp`);
@@ -180,6 +189,7 @@ export class CodingSession {
180
189
  const workspaces = await Promise.allSettled(this._workspaces.values());
181
190
  this._workspaces.clear();
182
191
  this._runs.clear();
192
+ this._keys.clear();
183
193
  await Promise.allSettled(workspaces.map(async (each) => {
184
194
  if (each.status !== 'fulfilled')
185
195
  return;
@@ -233,7 +243,8 @@ async function runShell({ session, start }, args, ctx) {
233
243
  }
234
244
  const runId = ctx?.runId ?? '';
235
245
  try {
236
- const call = { workspace: await session.open(root, runId), runId, line };
246
+ const policy = ctx?.policy ?? Policy.compile(undefined, { write: [root.root] });
247
+ const call = { workspace: await session.open(root, runId, policy), runId, line };
237
248
  if (args.background === true) {
238
249
  return await start(call);
239
250
  }
@@ -253,6 +264,7 @@ export function shellTool(options) {
253
264
  parameters: SHELL_PARAMETERS,
254
265
  effect: (_args, ctx) => session.effect(ctx),
255
266
  quote: (args) => (typeof args.command === 'string' ? args.command : null),
267
+ command: (args) => (typeof args.command === 'string' ? args.command : null),
256
268
  validate(args) {
257
269
  return typeof args.command === 'string' && args.command.trim()
258
270
  ? null
@@ -3,7 +3,7 @@ import { spawn } from 'child_process';
3
3
  import process from 'process';
4
4
  import { errorMessage, isRecord } from '../../lib/guards.js';
5
5
  import { execEnv } from '../../lib/helpers/spawn-path.js';
6
- import { hlog } from '../../lib/log.js';
6
+ import { HarnessLog } from '../../lib/log.js';
7
7
  import { PluginRegistry } from '../../lib/plugins/index.js';
8
8
  const DEFAULT_TIMEOUT_S = 60;
9
9
  const STDERR_TAIL = 2_000;
@@ -120,7 +120,7 @@ function blocked(event, reason) {
120
120
  case 'Stop':
121
121
  return { continue: said };
122
122
  case 'PreCompact':
123
- hlog('PreCompact hook exited 2; a fold cannot be blocked', { reason: said });
123
+ HarnessLog.info('PreCompact hook exited 2; a fold cannot be blocked', { reason: said });
124
124
  return undefined;
125
125
  }
126
126
  }
@@ -291,7 +291,9 @@ export class CommandHooks {
291
291
  const config = this._hooks;
292
292
  const skipped = Object.keys(config).filter(isSkipped);
293
293
  if (skipped.length) {
294
- hlog('command-hooks: these events have no harness phase and never run', { events: skipped });
294
+ HarnessLog.info('command-hooks: these events have no harness phase and never run', {
295
+ events: skipped
296
+ });
295
297
  }
296
298
  const commands = Object.entries(config).flatMap(([event, entries = []]) => isEvent(event) ? commandsOf(event, entries) : []);
297
299
  const hooks = commands.map((spec) => ({
@@ -0,0 +1,53 @@
1
+ import net from 'net';
2
+ import type { HarnessPlugin, PluginSetup } from '../../lib/plugins/index.ts';
3
+ import { type HostResolver } from '../../lib/tools/url-guard.ts';
4
+ import type { EgressProxyOptions, EgressProxyService, EgressProxySession } from '../../lib/contract/egress-proxy.ts';
5
+ export type Dial = (address: string, port: number) => net.Socket;
6
+ export interface EgressProxyPluginOptions {
7
+ readonly resolveHost?: HostResolver;
8
+ readonly dial?: Dial;
9
+ }
10
+ export declare class EgressProxy implements HarnessPlugin, EgressProxyService {
11
+ readonly name = "egress-proxy";
12
+ readonly api = 1;
13
+ readonly provides: string[];
14
+ readonly addons: {
15
+ 'bare-net': () => Promise<{
16
+ constants: {
17
+ type: {
18
+ TCP: 1;
19
+ IPC: 2;
20
+ };
21
+ state: {
22
+ UNREFED: number;
23
+ BINDING: number;
24
+ BOUND: number;
25
+ };
26
+ };
27
+ errors: typeof import("bare-net").errors;
28
+ isIP: typeof import("bare-tcp").isIP;
29
+ isIPv4: typeof import("bare-tcp").isIPv4;
30
+ isIPv6: typeof import("bare-tcp").isIPv6;
31
+ Socket: typeof import("bare-net").NetSocket;
32
+ Server: typeof import("bare-net").NetServer;
33
+ createConnection(path: string, opts?: import("bare-net").NetOptions & import("bare-pipe").PipeConnectOptions, onconnect?: () => void): import("bare-net").NetSocket;
34
+ createConnection(path: string, onconnect: () => void): import("bare-net").NetSocket;
35
+ createConnection(port: number, host?: string, opts?: import("bare-net").NetOptions & import("bare-tcp").TCPSocketConnectOptions, onconnect?: () => void): import("bare-net").NetSocket;
36
+ createConnection(port: number, host: string, onconnect: () => void): import("bare-net").NetSocket;
37
+ createConnection(port: number, onconnect: () => void): import("bare-net").NetSocket;
38
+ createConnection(opts: import("bare-net").NetOptions & import("bare-net").NetSocketConnectOptions, onconnect?: () => void): import("bare-net").NetSocket;
39
+ connect: typeof import("bare-net").createConnection;
40
+ createServer(opts?: import("bare-net").NetOptions, onconnection?: (socket: import("bare-net").NetSocket) => void): import("bare-net").NetServer;
41
+ createServer(onconnection: (socket: import("bare-net").NetSocket) => void): import("bare-net").NetServer;
42
+ default: typeof import("bare-net");
43
+ }>;
44
+ };
45
+ private readonly _resolveHost;
46
+ private readonly _dial;
47
+ private readonly _sessions;
48
+ constructor({ resolveHost, dial }?: EgressProxyPluginOptions);
49
+ setup(): PluginSetup;
50
+ open({ hosts, signal }: EgressProxyOptions): Promise<EgressProxySession>;
51
+ private _serve;
52
+ private _forward;
53
+ }
@@ -0,0 +1,182 @@
1
+ import b4a from 'b4a';
2
+ import net from 'net';
3
+ import { lookupHost } from '../../lib/dns-lookup.js';
4
+ import { PluginRegistry } from '../../lib/plugins/index.js';
5
+ import { resolveOutboundUrl } from '../../lib/tools/url-guard.js';
6
+ const MAX_HEAD = 64 * 1024;
7
+ const HEAD_END = '\r\n\r\n';
8
+ const REASONS = {
9
+ 400: 'Bad Request',
10
+ 403: 'Forbidden',
11
+ 431: 'Request Header Fields Too Large',
12
+ 502: 'Bad Gateway'
13
+ };
14
+ const DROPPED = /^(host|connection|keep-alive|proxy-connection|proxy-authorization)\s*:/i;
15
+ export class EgressProxy {
16
+ name = 'egress-proxy';
17
+ api = PluginRegistry.API_VERSION;
18
+ provides = ['egress-proxy'];
19
+ addons = { 'bare-net': () => import('bare-net') };
20
+ _resolveHost;
21
+ _dial;
22
+ _sessions = new Set();
23
+ constructor({ resolveHost = lookupHost, dial = (address, port) => net.connect(port, address) } = {}) {
24
+ this._resolveHost = resolveHost;
25
+ this._dial = dial;
26
+ }
27
+ setup() {
28
+ return {
29
+ services: { 'egress-proxy': { open: (options) => this.open(options) } },
30
+ teardown: async () => {
31
+ await Promise.all([...this._sessions].map((session) => session.close()));
32
+ }
33
+ };
34
+ }
35
+ async open({ hosts, signal }) {
36
+ const sockets = new Set();
37
+ const served = {
38
+ hosts,
39
+ denied: new Set(),
40
+ track: (socket) => {
41
+ sockets.add(socket);
42
+ socket.on('close', () => sockets.delete(socket));
43
+ }
44
+ };
45
+ const server = net.createServer((client) => {
46
+ served.track(client);
47
+ this._serve(client, served);
48
+ });
49
+ const port = await listen(server);
50
+ let closing = null;
51
+ const session = {
52
+ port,
53
+ denied: () => [...served.denied],
54
+ close: () => {
55
+ closing ??= new Promise((resolve) => {
56
+ for (const socket of sockets) {
57
+ socket.destroy();
58
+ }
59
+ server.close(() => resolve());
60
+ }).then(() => {
61
+ this._sessions.delete(session);
62
+ });
63
+ return closing;
64
+ }
65
+ };
66
+ this._sessions.add(session);
67
+ signal?.addEventListener('abort', () => void session.close());
68
+ return session;
69
+ }
70
+ _serve(client, served) {
71
+ const chunks = [];
72
+ client.on('error', () => client.destroy());
73
+ const onData = (chunk) => {
74
+ chunks.push(chunk);
75
+ const buffered = b4a.concat(chunks);
76
+ const end = b4a.indexOf(buffered, HEAD_END);
77
+ if (end === -1) {
78
+ if (buffered.byteLength > MAX_HEAD) {
79
+ client.removeListener('data', onData);
80
+ reply(client, 431, 'the request head is too large');
81
+ }
82
+ return;
83
+ }
84
+ client.pause();
85
+ client.removeListener('data', onData);
86
+ void this._forward(client, parseHead(buffered, end), served);
87
+ };
88
+ client.on('data', onData);
89
+ }
90
+ async _forward(client, request, served) {
91
+ const tunnel = request.method.toUpperCase() === 'CONNECT';
92
+ const url = parseTarget(tunnel ? `http://${request.target}` : request.target);
93
+ if (!url || url.protocol !== 'http:' || (tunnel && url.pathname !== '/')) {
94
+ reply(client, 400, 'the proxy takes CONNECT host:port or an absolute http:// URL');
95
+ return;
96
+ }
97
+ const check = await resolveOutboundUrl(url, {
98
+ resolveHost: this._resolveHost,
99
+ hosts: served.hosts
100
+ });
101
+ if (check.blocked) {
102
+ served.denied.add(url.hostname);
103
+ reply(client, 403, `egress-proxy refused ${url.hostname}: ${check.blocked}`);
104
+ return;
105
+ }
106
+ const address = check.addresses?.[0] ?? url.hostname.replace(/^\[(.*)\]$/, '$1');
107
+ const upstream = this._dial(address, Number(url.port) || 80);
108
+ served.track(upstream);
109
+ const opening = tunnel ? null : originHead(request, url);
110
+ splice(client, upstream, { opening, rest: request.rest, host: url.hostname });
111
+ }
112
+ }
113
+ function parseHead(buffered, end) {
114
+ const [line, ...fields] = b4a.toString(buffered.subarray(0, end), 'latin1').split('\r\n');
115
+ const [method = '', target = '', version = 'HTTP/1.1'] = line.split(' ');
116
+ return { method, target, version, fields, rest: buffered.subarray(end + HEAD_END.length) };
117
+ }
118
+ function splice(client, upstream, { opening, rest, host }) {
119
+ let connected = false;
120
+ upstream.on('error', () => {
121
+ if (connected) {
122
+ client.destroy();
123
+ }
124
+ else {
125
+ reply(client, 502, `egress-proxy could not reach ${host}`);
126
+ }
127
+ upstream.destroy();
128
+ });
129
+ client.on('error', () => upstream.destroy());
130
+ upstream.once('connect', () => {
131
+ connected = true;
132
+ if (opening === null) {
133
+ client.write('HTTP/1.1 200 Connection Established\r\n\r\n');
134
+ }
135
+ else {
136
+ upstream.write(opening);
137
+ }
138
+ if (rest.byteLength > 0) {
139
+ upstream.write(rest);
140
+ }
141
+ client.pipe(upstream);
142
+ upstream.pipe(client);
143
+ });
144
+ }
145
+ async function listen(server) {
146
+ await new Promise((resolve, reject) => {
147
+ server.once('error', reject);
148
+ server.listen(0, '127.0.0.1', () => resolve());
149
+ });
150
+ const address = server.address();
151
+ return typeof address === 'object' && address ? address.port : 0;
152
+ }
153
+ function parseTarget(target) {
154
+ try {
155
+ return new URL(target);
156
+ }
157
+ catch {
158
+ return null;
159
+ }
160
+ }
161
+ function originHead({ method, version, fields }, url) {
162
+ const kept = fields.filter((field) => field !== '' && !DROPPED.test(field));
163
+ return [
164
+ `${method} ${url.pathname}${url.search} ${version}`,
165
+ `Host: ${url.host}`,
166
+ ...kept,
167
+ 'Connection: close',
168
+ '',
169
+ ''
170
+ ].join('\r\n');
171
+ }
172
+ function reply(socket, status, reason) {
173
+ const body = `${reason}\n`;
174
+ socket.end([
175
+ `HTTP/1.1 ${status} ${REASONS[status]}`,
176
+ 'Content-Type: text/plain',
177
+ `Content-Length: ${b4a.byteLength(body)}`,
178
+ 'Connection: close',
179
+ '',
180
+ body
181
+ ].join('\r\n'));
182
+ }
@@ -1,8 +1,9 @@
1
1
  import b4a from 'b4a';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
+ import { HarnessError } from '../../lib/errors.js';
4
5
  import { AbortedError } from '../../lib/helpers/race-abort.js';
5
- import { BUSY_ERROR, DIM_STEP, effectiveSteps, generationPercentTick, IMAGE_LOAD_STALL_ERROR, normalizeClamps, parseCommonArgs, runDiffusion } from './generate-image.js';
6
+ import { BUSY_ERROR, DIM_STEP, effectiveSteps, generationPercentTick, normalizeClamps, parseCommonArgs, runDiffusion } from './generate-image.js';
6
7
  const DEFAULT_STRENGTH = 0.7;
7
8
  const FLUX2_GUIDANCE = 3.5;
8
9
  const FLUX2_CFG_SCALE = 1;
@@ -283,8 +284,8 @@ export function createEditImageTool(runtime, { loadMedia = defaultLoadMedia, res
283
284
  if (err instanceof AbortedError) {
284
285
  return { error: 'image generation canceled' };
285
286
  }
286
- if (err instanceof Error && err.message === IMAGE_LOAD_STALL_ERROR) {
287
- return { error: IMAGE_LOAD_STALL_ERROR };
287
+ if (HarnessError.is(err, 'IMAGE_LOAD_STALLED')) {
288
+ return { error: HarnessError.IMAGE_LOAD_STALL_ERROR };
288
289
  }
289
290
  throw err;
290
291
  }
@@ -3,6 +3,7 @@ import type { ToolDefinition } from '../../lib/contract/index.ts';
3
3
  import type { ModelSrc } from '../../lib/models/context.ts';
4
4
  import { type ImageClamps, type ImageModelSet } from '../../lib/models/model-catalog.ts';
5
5
  import type { ModelHost, TrackedLoad } from '../../lib/contract/models.ts';
6
+ import type { HoldFn } from '../../lib/contract/models.ts';
6
7
  import { type ModelRegistrySdk } from '../../lib/models/model-source.ts';
7
8
  export declare const MAX_DIM = 1024;
8
9
  export declare const DIM_STEP = 64;
@@ -62,7 +63,8 @@ export interface DiffusionRuntimeOptions extends ImageModelSet {
62
63
  loadSdk: () => Promise<DiffusionSdk>;
63
64
  onProgress?: (model: string, progress: Record<string, unknown>) => void;
64
65
  onLoaded?: (model: string) => void;
65
- onBeforeLoad?: (signal?: BareAbortSignal) => Promise<void>;
66
+ onBeforeLoad?: (signal: BareAbortSignal | undefined, srcs: ReadonlyArray<string>) => Promise<void>;
67
+ hold?: HoldFn;
66
68
  loads?: Pick<ModelHost, 'track'>;
67
69
  stallMs?: number;
68
70
  }
@@ -80,8 +82,7 @@ export interface DiffusionRuntime {
80
82
  release(): void;
81
83
  }
82
84
  export declare function generationPercentTick(onPercent: (percentage: number) => void, encodePhases?: number): (tick: DiffusionTick) => void;
83
- export declare const IMAGE_LOAD_STALL_ERROR = "image model download stalled";
84
- export declare function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBeforeLoad, loads, stallMs, ...base }: DiffusionRuntimeOptions): DiffusionRuntime;
85
+ export declare function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBeforeLoad, hold, loads, stallMs, ...base }: DiffusionRuntimeOptions): DiffusionRuntime;
85
86
  export declare const BUSY_ERROR = "an image generation is already running; try again when it finishes";
86
87
  export interface ImageToolError {
87
88
  error: string;
@@ -1,4 +1,5 @@
1
1
  import ScopeLock from 'scope-lock';
2
+ import { HarnessError } from '../../lib/errors.js';
2
3
  import { AbortedError, raceAbort } from '../../lib/helpers/race-abort.js';
3
4
  import { DIFFUSION_CATALOG, imageModelFor } from '../../lib/models/model-catalog.js';
4
5
  import { createLoadStall } from '../../lib/helpers/load-stall.js';
@@ -37,8 +38,7 @@ function diffusionProgressName(set) {
37
38
  const entry = DIFFUSION_CATALOG.find((candidate) => candidate.model.src === set.model);
38
39
  return entry?.name ?? set.model;
39
40
  }
40
- export const IMAGE_LOAD_STALL_ERROR = 'image model download stalled';
41
- export function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBeforeLoad, loads = { track: (pending) => pending }, stallMs = IMAGE_LOAD_STALL_MS, ...base }) {
41
+ export function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBeforeLoad, hold, loads = { track: (pending) => pending }, stallMs = IMAGE_LOAD_STALL_MS, ...base }) {
42
42
  let loading = null;
43
43
  let residentFingerprint = null;
44
44
  let busy = false;
@@ -75,13 +75,16 @@ export function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBefore
75
75
  ensureLoaded: async (sdk, signal, modelChoice) => {
76
76
  const set = (modelChoice && imageModelFor(modelChoice)) || base;
77
77
  const fingerprint = fingerprintOf(set);
78
+ if (hold && !(loading && residentFingerprint === fingerprint)) {
79
+ await hold(diffusionProgressName(set), 'diffusion', signal);
80
+ }
78
81
  await lock.lock();
79
82
  try {
80
83
  if (loading && residentFingerprint !== fingerprint) {
81
84
  await doUnload();
82
85
  }
83
86
  if (!loading && onBeforeLoad) {
84
- await onBeforeLoad(signal);
87
+ await onBeforeLoad(signal, [set.model, set.llmModel, set.vaeModel].filter((src) => src !== undefined));
85
88
  }
86
89
  residentFingerprint = fingerprint;
87
90
  loading ??= (async () => {
@@ -98,7 +101,7 @@ export function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBefore
98
101
  config.vaeModelSrc = await resolveModelSrc(sdk, set.vaeModel, 'diffusion');
99
102
  }
100
103
  const modelConfig = Object.keys(config).length ? config : undefined;
101
- const stall = createLoadStall(stallMs, IMAGE_LOAD_STALL_ERROR);
104
+ const stall = createLoadStall(stallMs, () => new HarnessError('IMAGE_LOAD_STALLED'));
102
105
  const pending = sdk.loadModel({
103
106
  modelSrc,
104
107
  modelType: 'diffusion',
@@ -114,9 +117,7 @@ export function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBefore
114
117
  return { modelId, prediction: set.prediction };
115
118
  }
116
119
  catch (err) {
117
- if (err instanceof Error &&
118
- err.message === IMAGE_LOAD_STALL_ERROR &&
119
- pending.requestId) {
120
+ if (HarnessError.is(err, 'IMAGE_LOAD_STALLED') && pending.requestId) {
120
121
  void sdk.cancel?.({ requestId: pending.requestId }).catch(noop);
121
122
  }
122
123
  throw err;
@@ -367,8 +368,8 @@ export function createGenerateImageTool(runtime, clamps) {
367
368
  if (err instanceof AbortedError) {
368
369
  return { error: 'image generation canceled' };
369
370
  }
370
- if (err instanceof Error && err.message === IMAGE_LOAD_STALL_ERROR) {
371
- return { error: IMAGE_LOAD_STALL_ERROR };
371
+ if (HarnessError.is(err, 'IMAGE_LOAD_STALLED')) {
372
+ return { error: HarnessError.IMAGE_LOAD_STALL_ERROR };
372
373
  }
373
374
  throw err;
374
375
  }
@@ -2,7 +2,7 @@ import type { ImageClamps, ImageModelSet } from '../../lib/models/model-catalog.
2
2
  import type { HarnessPlugin, PluginContext, PluginSetup } from '../../lib/plugins/index.ts';
3
3
  import { loadMediaCodecs } from './edit-image.ts';
4
4
  export { createEditImageTool } from './edit-image.ts';
5
- export { createDiffusionRuntime, createGenerateImageTool, generationPercentTick, IMAGE_LOAD_STALL_ERROR, settingsDimension, settingsSteps, type DiffusionRuntime, type DiffusionRuntimeOptions, type DiffusionSdk, type DiffusionTick } from './generate-image.ts';
5
+ export { createDiffusionRuntime, createGenerateImageTool, generationPercentTick, settingsDimension, settingsSteps, type DiffusionRuntime, type DiffusionRuntimeOptions, type DiffusionSdk, type DiffusionTick } from './generate-image.ts';
6
6
  export interface ImageOptions {
7
7
  model: string | ImageModelSet;
8
8
  clamps?: ImageClamps;
@@ -1,21 +1,23 @@
1
+ import { HarnessError } from '../../lib/errors.js';
1
2
  import { retryMemo } from '../../lib/helpers/retry-memo.js';
2
3
  import { PluginRegistry } from '../../lib/plugins/index.js';
3
4
  import { createEditImageTool, loadMediaCodecs } from './edit-image.js';
4
5
  import { createDiffusionRuntime, createGenerateImageTool } from './generate-image.js';
5
6
  export { createEditImageTool } from './edit-image.js';
6
- export { createDiffusionRuntime, createGenerateImageTool, generationPercentTick, IMAGE_LOAD_STALL_ERROR, settingsDimension, settingsSteps } from './generate-image.js';
7
- const BUSY_MESSAGE = 'the chat model is busy; try the image again once the current reply finishes';
7
+ export { createDiffusionRuntime, createGenerateImageTool, generationPercentTick, settingsDimension, settingsSteps } from './generate-image.js';
8
8
  function diffusionRuntime(models, model) {
9
9
  const loadSdk = retryMemo(async () => {
10
10
  const sdk = await models.sdk();
11
- const [{ diffusionPlugin }, { registerPlugin }] = await Promise.all([
12
- import('@qvac/sdk/sdcpp-generation/plugin'),
13
- import('@qvac/sdk/plugins')
14
- ]);
15
- try {
16
- registerPlugin(diffusionPlugin);
11
+ if (typeof globalThis.Bare !== 'undefined') {
12
+ const [{ diffusionPlugin }, { registerPlugin }] = await Promise.all([
13
+ import('@qvac/sdk/sdcpp-generation/plugin'),
14
+ import('@qvac/sdk/plugins')
15
+ ]);
16
+ try {
17
+ registerPlugin(diffusionPlugin);
18
+ }
19
+ catch { }
17
20
  }
18
- catch { }
19
21
  return sdk;
20
22
  });
21
23
  const transfers = new Map();
@@ -23,6 +25,7 @@ function diffusionRuntime(models, model) {
23
25
  ...(typeof model === 'string' ? { model } : model),
24
26
  loads: models,
25
27
  loadSdk,
28
+ hold: models.hold,
26
29
  onProgress: (name, progress) => {
27
30
  const state = models.progressState(name, progress);
28
31
  if (state.status === 'downloading' &&
@@ -43,7 +46,7 @@ function diffusionRuntime(models, model) {
43
46
  models.statusChanged();
44
47
  models.emit({ ...transfer, status: 'downloaded' });
45
48
  },
46
- onBeforeLoad: (signal) => models.makeRoom(signal, BUSY_MESSAGE)
49
+ onBeforeLoad: (signal, srcs) => models.makeRoom(signal, new HarnessError('CHAT_MODEL_BUSY', ['image']), srcs)
47
50
  });
48
51
  }
49
52
  export class Image {
@@ -0,0 +1,15 @@
1
+ import type { HarnessPlugin, PluginContext, PluginSetup } from '../../lib/plugins/index.ts';
2
+ export interface LanguageHintOptions {
3
+ minWords?: number;
4
+ minProbability?: number;
5
+ }
6
+ export declare class LanguageHint implements HarnessPlugin {
7
+ readonly name = "language-hint";
8
+ readonly api = 1;
9
+ readonly needs: string[];
10
+ private readonly _minWords;
11
+ private readonly _minProbability;
12
+ constructor(options?: LanguageHintOptions);
13
+ setup(ctx: PluginContext): PluginSetup;
14
+ private _hint;
15
+ }
@@ -0,0 +1,51 @@
1
+ import { detectLanguage, UNDETERMINED } from '../../lib/capabilities/detect-language.js';
2
+ import { PluginRegistry } from '../../lib/plugins/index.js';
3
+ const TIMEOUT_MS = 120_000;
4
+ export class LanguageHint {
5
+ name = 'language-hint';
6
+ api = PluginRegistry.API_VERSION;
7
+ needs = ['translation'];
8
+ _minWords;
9
+ _minProbability;
10
+ constructor(options = {}) {
11
+ this._minWords = options.minWords ?? 3;
12
+ this._minProbability = options.minProbability ?? 0.5;
13
+ }
14
+ setup(ctx) {
15
+ const translation = ctx.service('translation');
16
+ const hook = {
17
+ name: 'language-hint',
18
+ phase: 'promptSubmit',
19
+ timeoutMs: TIMEOUT_MS,
20
+ run: (payload, options) => payload.phase === 'promptSubmit'
21
+ ? this._hint(translation, payload.text, options)
22
+ : undefined
23
+ };
24
+ return { hooks: [hook] };
25
+ }
26
+ async _hint(translation, text, options) {
27
+ if (text.trim().split(/\s+/).length < this._minWords)
28
+ return;
29
+ const [top] = detectLanguage({ text, topK: 2 });
30
+ if (!top || top.code === UNDETERMINED || top.code === 'en') {
31
+ return;
32
+ }
33
+ if ((top.probability ?? 0) < this._minProbability) {
34
+ return;
35
+ }
36
+ const said = `The user wrote in ${top.language}.`;
37
+ const answer = `Answer in ${top.language}.`;
38
+ let english;
39
+ try {
40
+ english = await translation.translate({ text, from: top.code, to: 'en' }, options?.signal);
41
+ }
42
+ catch {
43
+ return { context: `${said} ${answer}` };
44
+ }
45
+ return {
46
+ context: 'error' in english
47
+ ? `${said} ${answer}`
48
+ : `${said} In English: "${english.text}". Work from the English. ${answer}`
49
+ };
50
+ }
51
+ }
@@ -2,7 +2,7 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { fileURLToPath, pathToFileURL } from 'url';
4
4
  import { errorMessage, isRecord } from '../../lib/guards.js';
5
- import { canonicalDenyRoots, defaultRealpath, hostPath, isDeniedPath, PROTECTED_PATH_ERROR, resolveKey } from '../../lib/tools/fs/scope.js';
5
+ import { callDenyRoots, defaultRealpath, hostPath, isDeniedPath, PROTECTED_PATH_ERROR, resolveKey } from '../../lib/tools/fs/scope.js';
6
6
  const OPERATIONS = ['definition', 'references', 'hover', 'symbols', 'diagnostics'];
7
7
  const MAX_LOCATIONS = 30;
8
8
  const MAX_OUTLINE = 100;
@@ -320,7 +320,7 @@ const PARAMETERS = {
320
320
  };
321
321
  async function run(args, ctx, options) {
322
322
  const { pool, servers, requestTimeoutMs, deniedRoots, realpath = defaultRealpath } = options;
323
- const deny = await canonicalDenyRoots(deniedRoots, realpath);
323
+ const deny = await callDenyRoots(deniedRoots, ctx?.policy, realpath);
324
324
  const view = { roots: ctx?.fsRoots ?? [], deny, realpath, lines: new Map() };
325
325
  const found = await target(args, view, servers);
326
326
  if ('error' in found) {