@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,4 +1,4 @@
1
- import { hlog } from '../../lib/log.js';
1
+ import { HarnessLog } from '../../lib/log.js';
2
2
  import { PluginRegistry } from '../../lib/plugins/index.js';
3
3
  import { Tools } from '../../lib/tools/index.js';
4
4
  import { credentialAllowListFor, mcpReadMethods } from '../../lib/tools/skills/index.js';
@@ -67,13 +67,16 @@ export class McpPlugin {
67
67
  servers.forEach((server, index) => {
68
68
  const outcome = listed[index];
69
69
  if (outcome.status === 'rejected') {
70
- hlog('mcp server unavailable', { server: server.name, error: String(outcome.reason) });
70
+ HarnessLog.info('mcp server unavailable', {
71
+ server: server.name,
72
+ error: String(outcome.reason)
73
+ });
71
74
  return;
72
75
  }
73
76
  for (const entry of outcome.value) {
74
77
  const tool = serverTool(server, entry, credentialStore);
75
78
  if (names.has(tool.name)) {
76
- hlog('mcp tool listed twice', { tool: tool.name });
79
+ HarnessLog.info('mcp tool listed twice', { tool: tool.name });
77
80
  continue;
78
81
  }
79
82
  names.add(tool.name);
@@ -3,6 +3,7 @@ import type { MusicSettings, ToolDefinition, ToolExecuteContext } from '../../li
3
3
  import type { ModelSrc } from '../../lib/models/context.ts';
4
4
  import { type MusicClamps, type MusicModelStages } 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_DURATION_SECONDS = 300;
8
9
  export declare const MIN_DURATION_SECONDS = 1;
@@ -70,7 +71,8 @@ export interface MusicRuntimeOptions extends MusicModelStages {
70
71
  inferenceSteps?: number;
71
72
  useGpu?: boolean;
72
73
  onProgress?: (model: string, progress: Record<string, unknown>) => void;
73
- onBeforeLoad?: (signal?: BareAbortSignal) => Promise<void>;
74
+ onBeforeLoad?: (signal: BareAbortSignal | undefined, srcs: ReadonlyArray<string>) => Promise<void>;
75
+ hold?: HoldFn;
74
76
  loads?: Pick<ModelHost, 'track'>;
75
77
  }
76
78
  export interface LoadedMusicModel {
@@ -92,7 +94,7 @@ export interface MusicRuntime {
92
94
  release(): void;
93
95
  }
94
96
  export declare function musicPercentTick(onPercent: (percentage: number) => void): (tick: MusicTick) => void;
95
- export declare function createMusicRuntime({ loadSdk, onProgress, onBeforeLoad, loads, inferenceSteps: baseSteps, useGpu, ...base }: MusicRuntimeOptions): MusicRuntime;
97
+ export declare function createMusicRuntime({ loadSdk, onProgress, onBeforeLoad, hold, loads, inferenceSteps: baseSteps, useGpu, ...base }: MusicRuntimeOptions): MusicRuntime;
96
98
  export declare const BUSY_ERROR = "a music generation is already running; try again when it finishes";
97
99
  export interface MusicToolError {
98
100
  error: string;
@@ -1,7 +1,7 @@
1
1
  import process from 'process';
2
2
  import ScopeLock from 'scope-lock';
3
3
  import { AbortedError, raceAbort } from '../../lib/helpers/race-abort.js';
4
- import { hdiag } from '../../lib/log.js';
4
+ import { HarnessLog } from '../../lib/log.js';
5
5
  import { AUDIOGEN_CATALOG, musicChoiceForDit, musicDefaultSteps, musicModelSet } from '../../lib/models/model-catalog.js';
6
6
  import { GENERATE_MUSIC_TOOL } from '../../lib/models/music-catalog.js';
7
7
  import { resolveModelSrc } from '../../lib/models/model-source.js';
@@ -48,7 +48,7 @@ function musicProgressName(dit) {
48
48
  const entry = AUDIOGEN_CATALOG.find((candidate) => candidate.dit.src === dit || candidate.dit.name === dit);
49
49
  return entry?.name ?? dit;
50
50
  }
51
- export function createMusicRuntime({ loadSdk, onProgress, onBeforeLoad, loads = { track: (pending) => pending }, inferenceSteps: baseSteps, useGpu = true, ...base }) {
51
+ export function createMusicRuntime({ loadSdk, onProgress, onBeforeLoad, hold, loads = { track: (pending) => pending }, inferenceSteps: baseSteps, useGpu = true, ...base }) {
52
52
  let loading = null;
53
53
  let residentFingerprint = null;
54
54
  let busy = false;
@@ -88,13 +88,16 @@ export function createMusicRuntime({ loadSdk, onProgress, onBeforeLoad, loads =
88
88
  const stages = stagesFor(modelChoice, base);
89
89
  const effectiveSteps = steps ?? baseSteps;
90
90
  const fingerprint = fingerprintOf(stages, effectiveSteps);
91
+ if (hold && !(loading && residentFingerprint === fingerprint)) {
92
+ await hold(musicProgressName(stages.dit), 'audiogen', signal);
93
+ }
91
94
  await lock.lock();
92
95
  try {
93
96
  if (loading && residentFingerprint !== fingerprint) {
94
97
  await doUnload();
95
98
  }
96
99
  if (!loading && onBeforeLoad) {
97
- await onBeforeLoad(signal);
100
+ await onBeforeLoad(signal, [stages.dit, stages.textEnc, stages.lm, stages.vae]);
98
101
  }
99
102
  residentFingerprint = fingerprint;
100
103
  loading ??= (async () => {
@@ -237,7 +240,7 @@ export function backendName(backendId) {
237
240
  return BACKEND_NAMES[backendId] ?? `id-${backendId}`;
238
241
  }
239
242
  function logBackendUsed({ gpuRequested, stats, fallback }) {
240
- hdiag('music.backend', {
243
+ HarnessLog.diag('music.backend', {
241
244
  gpuRequested,
242
245
  backend: backendName(stats?.backendId),
243
246
  backendId: stats?.backendId ?? null,
@@ -1,8 +1,8 @@
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 { createGenerateMusicTool, createMusicRuntime } from './generate-music.js';
4
5
  export { audioDurationSeconds, backendDevice, backendName, CPU_FALLBACK_NOTICE, createGenerateMusicTool, createMusicRuntime, gpuFallback, musicPercentTick, pcmToWav, presentStats } from './generate-music.js';
5
- const BUSY_MESSAGE = 'the chat model is busy; try the music again once the current reply finishes';
6
6
  export class Music {
7
7
  name = 'music';
8
8
  api = PluginRegistry.API_VERSION;
@@ -22,22 +22,25 @@ export class Music {
22
22
  const models = ctx.service('models');
23
23
  const loadSdk = retryMemo(async () => {
24
24
  const sdk = await models.sdk();
25
- const [{ audioGenPlugin }, { registerPlugin }] = await Promise.all([
26
- import('@qvac/sdk/audiogen-ggml/plugin'),
27
- import('@qvac/sdk/plugins')
28
- ]);
29
- try {
30
- registerPlugin(audioGenPlugin);
25
+ if (typeof globalThis.Bare !== 'undefined') {
26
+ const [{ audioGenPlugin }, { registerPlugin }] = await Promise.all([
27
+ import('@qvac/sdk/audiogen-ggml/plugin'),
28
+ import('@qvac/sdk/plugins')
29
+ ]);
30
+ try {
31
+ registerPlugin(audioGenPlugin);
32
+ }
33
+ catch { }
31
34
  }
32
- catch { }
33
35
  return sdk;
34
36
  });
35
37
  const runtime = createMusicRuntime({
36
38
  ...model,
37
39
  loads: models,
38
40
  loadSdk,
41
+ hold: models.hold,
39
42
  onProgress: (name, progress) => models.emit(models.progressState(name, progress)),
40
- onBeforeLoad: (signal) => models.makeRoom(signal, BUSY_MESSAGE)
43
+ onBeforeLoad: (signal, srcs) => models.makeRoom(signal, new HarnessError('CHAT_MODEL_BUSY', ['music']), srcs)
41
44
  });
42
45
  return {
43
46
  tools: [createGenerateMusicTool(runtime, clamps)],
@@ -1,4 +1,4 @@
1
- import { shellArgv } from '../../lib/tools/exec/shell-argv.js';
1
+ import { ShellLine } from '../../lib/tools/exec/shell-line.js';
2
2
  const OBSIDIAN_BIN = /^obsidian(?:\.exe|\.com)?$/i;
3
3
  const OBSIDIAN_PREFIX = /^obsidian(?:\.exe|\.com)?(?:\s|$)/i;
4
4
  export function parseObsidianCommand(command) {
@@ -6,7 +6,7 @@ export function parseObsidianCommand(command) {
6
6
  if (!OBSIDIAN_PREFIX.test(trimmed)) {
7
7
  return null;
8
8
  }
9
- const tokens = shellArgv(trimmed);
9
+ const tokens = ShellLine.parse(trimmed).commands[0]?.argv ?? [];
10
10
  if (tokens.length === 0 || !OBSIDIAN_BIN.test(tokens[0] ?? '')) {
11
11
  return null;
12
12
  }
@@ -1,6 +1,7 @@
1
+ import { HarnessError } from '../../lib/errors.js';
1
2
  export function markdownFileName(name) {
2
3
  if (name.includes('/') || name.includes('\\') || name === '.' || name === '..') {
3
- throw new Error('name= must be a note name, not a path.');
4
+ throw new HarnessError('OBSIDIAN_NOTE_NAME_IS_PATH');
4
5
  }
5
6
  return name.endsWith('.md') ? name : `${name}.md`;
6
7
  }
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { HarnessError } from '../../lib/errors.js';
3
4
  function lstatOrNull(p) {
4
5
  try {
5
6
  return fs.lstatSync(p);
@@ -18,7 +19,7 @@ function rejectSymlinkComponents(root, target) {
18
19
  return;
19
20
  }
20
21
  if (stat.isSymbolicLink()) {
21
- throw new Error(`Path "${target}" crosses a symlink inside the vault.`);
22
+ throw new HarnessError('OBSIDIAN_PATH_CROSSES_SYMLINK', [target]);
22
23
  }
23
24
  }
24
25
  }
@@ -26,7 +27,7 @@ export function ensureWithinRoot(root, rel) {
26
27
  const resolvedRoot = path.resolve(root);
27
28
  const target = path.resolve(resolvedRoot, rel);
28
29
  if (target !== resolvedRoot && !target.startsWith(resolvedRoot + path.sep)) {
29
- throw new Error(`Path "${rel}" escapes the vault root.`);
30
+ throw new HarnessError('OBSIDIAN_PATH_ESCAPES_VAULT', [rel]);
30
31
  }
31
32
  rejectSymlinkComponents(resolvedRoot, target);
32
33
  return target;
@@ -36,7 +37,7 @@ export function isSymlink(p) {
36
37
  }
37
38
  export function writeNewFileText(filePath, content) {
38
39
  if (fs.existsSync(filePath)) {
39
- throw new Error(`Destination already exists: ${filePath}`);
40
+ throw new HarnessError('OBSIDIAN_DESTINATION_EXISTS', [filePath]);
40
41
  }
41
42
  let fd;
42
43
  try {
@@ -44,7 +45,7 @@ export function writeNewFileText(filePath, content) {
44
45
  }
45
46
  catch (error) {
46
47
  if (fs.existsSync(filePath)) {
47
- throw new Error(`Destination already exists: ${filePath}`);
48
+ throw new HarnessError('OBSIDIAN_DESTINATION_EXISTS', [filePath]);
48
49
  }
49
50
  throw error;
50
51
  }
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { HarnessError } from '../../lib/errors.js';
3
4
  import { markdownFileName } from './note-name.js';
4
5
  import { ensureWithinRoot, getArg, getContentArg, writeNewFileText } from './vault-paths.js';
5
6
  function markdownPath(vaultPath, target) {
@@ -20,7 +21,7 @@ function createNamed(vaultPath, { name, folder, content }) {
20
21
  const fileName = markdownFileName(name);
21
22
  const filePath = ensureWithinRoot(vaultPath, path.join(folder, fileName));
22
23
  if (fs.existsSync(filePath)) {
23
- throw new Error(`Note "${name}" already exists at ${folder || '/'}`);
24
+ throw new HarnessError('OBSIDIAN_NOTE_EXISTS', [name, folder || '/']);
24
25
  }
25
26
  writeNewFileText(filePath, content);
26
27
  return `Created: ${folder ? `${folder}/` : ''}${fileName}`;
@@ -42,7 +43,7 @@ export function handleCreate(vaultPath, args) {
42
43
  }
43
44
  const target = filePath ?? file;
44
45
  if (!target) {
45
- throw new Error('Missing required argument: name=, file=, or path=');
46
+ throw new HarnessError('OBSIDIAN_MISSING_ARGUMENT', ['name=, file=, or path=']);
46
47
  }
47
48
  return createAtPath(vaultPath, target, content || '');
48
49
  }
@@ -1,3 +1,4 @@
1
+ import { HarnessError } from '../../lib/errors.js';
1
2
  import { handleCreate } from './vault-create.js';
2
3
  import { todayStamp } from './vault-paths.js';
3
4
  import { handleDailyRead, handleFiles, handleFolders, handleOutline, handleProperties, handleRead, handleSearch, handleTags, handleVault, handleVaults, handleWordcount } from './vault-read.js';
@@ -51,7 +52,6 @@ export function executeVaultFsAction(vaultPath, action, args) {
51
52
  case 'daily:path':
52
53
  return `Daily Notes/${todayStamp()}.md`;
53
54
  default:
54
- throw new Error(`Action "${action}" is not supported in vault file mode. ` +
55
- `This action requires the Obsidian CLI connected to the running app.`);
55
+ throw new HarnessError('OBSIDIAN_ACTION_UNSUPPORTED', [action]);
56
56
  }
57
57
  }
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { HarnessError } from '../../lib/errors.js';
3
4
  import { ensureWithinRoot, isSymlink, writeNewFileText } from './safe-path.js';
4
5
  export { ensureWithinRoot, writeNewFileText } from './safe-path.js';
5
6
  export const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---/;
@@ -90,13 +91,13 @@ export function writeIfUnchanged(filePath, content, expectedMtimeMs) {
90
91
  }
91
92
  if (expectedMtimeMs === null) {
92
93
  if (current) {
93
- throw new Error(`Note changed on disk during update (file appeared): ${path.basename(filePath)}`);
94
+ throw new HarnessError('OBSIDIAN_NOTE_CHANGED', ['file appeared', path.basename(filePath)]);
94
95
  }
95
96
  fs.writeFileSync(filePath, content);
96
97
  return;
97
98
  }
98
99
  if (!current || current.mtimeMs !== expectedMtimeMs) {
99
- throw new Error(`Note changed on disk during update (re-read and retry): ${path.basename(filePath)}`);
100
+ throw new HarnessError('OBSIDIAN_NOTE_CHANGED', ['re-read and retry', path.basename(filePath)]);
100
101
  }
101
102
  fs.writeFileSync(filePath, content);
102
103
  }
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { HarnessError } from '../../lib/errors.js';
3
4
  import { dailyCandidates, ensureWithinRoot, FRONTMATTER_RE, getArg, listFolders, listMarkdownFiles, parseFrontmatter, readFileText, resolveNotePath, todayStamp } from './vault-paths.js';
4
5
  export function handleVault(vaultPath) {
5
6
  return JSON.stringify({ name: path.basename(vaultPath), path: vaultPath });
@@ -17,7 +18,7 @@ export function handleVaults(vaultPath) {
17
18
  export function handleRead(vaultPath, args) {
18
19
  const notePath = resolveNotePath(vaultPath, args);
19
20
  if (!notePath || !fs.existsSync(notePath)) {
20
- throw new Error(`Note not found. Args: ${args.join(', ')}`);
21
+ throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
21
22
  }
22
23
  return readFileText(notePath);
23
24
  }
@@ -43,7 +44,7 @@ function parseLimit(args) {
43
44
  export function handleSearch(vaultPath, args) {
44
45
  const query = getArg(args, 'query');
45
46
  if (!query) {
46
- throw new Error('Missing required argument: query=');
47
+ throw new HarnessError('OBSIDIAN_MISSING_ARGUMENT', ['query=']);
47
48
  }
48
49
  const limit = parseLimit(args);
49
50
  const lowerQuery = query.toLowerCase();
@@ -70,7 +71,7 @@ export function handleSearch(vaultPath, args) {
70
71
  export function handleProperties(vaultPath, args) {
71
72
  const notePath = resolveNotePath(vaultPath, args);
72
73
  if (!notePath || !fs.existsSync(notePath)) {
73
- throw new Error(`Note not found. Args: ${args.join(', ')}`);
74
+ throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
74
75
  }
75
76
  return JSON.stringify(parseFrontmatter(readFileText(notePath)), null, 2);
76
77
  }
@@ -99,7 +100,7 @@ export function handleTags(vaultPath) {
99
100
  export function handleWordcount(vaultPath, args) {
100
101
  const notePath = resolveNotePath(vaultPath, args);
101
102
  if (!notePath || !fs.existsSync(notePath)) {
102
- throw new Error(`Note not found. Args: ${args.join(', ')}`);
103
+ throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
103
104
  }
104
105
  const body = readFileText(notePath).replace(FRONTMATTER_RE, '').trim();
105
106
  const words = body.split(/\s+/).filter(Boolean).length;
@@ -108,7 +109,7 @@ export function handleWordcount(vaultPath, args) {
108
109
  export function handleOutline(vaultPath, args) {
109
110
  const notePath = resolveNotePath(vaultPath, args);
110
111
  if (!notePath || !fs.existsSync(notePath)) {
111
- throw new Error(`Note not found. Args: ${args.join(', ')}`);
112
+ throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
112
113
  }
113
114
  const headings = readFileText(notePath)
114
115
  .split('\n')
@@ -1,15 +1,16 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { HarnessError } from '../../lib/errors.js';
3
4
  import { markdownFileName } from './note-name.js';
4
5
  import { appendToFile, dailyCandidates, ensureWithinRoot, FRONTMATTER_RE, getArg, getContentArg, moveFile, readFileSnapshot, resolveNotePath, todayStamp, updateFileText, writeIfUnchanged } from './vault-paths.js';
5
6
  export function handleAppend(vaultPath, args) {
6
7
  const notePath = resolveNotePath(vaultPath, args);
7
8
  if (!notePath || !fs.existsSync(notePath)) {
8
- throw new Error(`Note not found. Args: ${args.join(', ')}`);
9
+ throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
9
10
  }
10
11
  const content = getContentArg(args);
11
12
  if (!content) {
12
- throw new Error('Missing required argument: content=');
13
+ throw new HarnessError('OBSIDIAN_MISSING_ARGUMENT', ['content=']);
13
14
  }
14
15
  appendToFile(notePath, content);
15
16
  return `Appended to: ${path.relative(vaultPath, notePath)}`;
@@ -17,11 +18,11 @@ export function handleAppend(vaultPath, args) {
17
18
  export function handlePrepend(vaultPath, args) {
18
19
  const notePath = resolveNotePath(vaultPath, args);
19
20
  if (!notePath || !fs.existsSync(notePath)) {
20
- throw new Error(`Note not found. Args: ${args.join(', ')}`);
21
+ throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
21
22
  }
22
23
  const content = getContentArg(args);
23
24
  if (!content) {
24
- throw new Error('Missing required argument: content=');
25
+ throw new HarnessError('OBSIDIAN_MISSING_ARGUMENT', ['content=']);
25
26
  }
26
27
  updateFileText(notePath, (existing) => content + existing);
27
28
  return `Prepended to: ${path.relative(vaultPath, notePath)}`;
@@ -40,7 +41,7 @@ function uniqueTrashPath(base) {
40
41
  export function handleDelete(vaultPath, args) {
41
42
  const notePath = resolveNotePath(vaultPath, args);
42
43
  if (!notePath || !fs.existsSync(notePath)) {
43
- throw new Error(`Note not found. Args: ${args.join(', ')}`);
44
+ throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
44
45
  }
45
46
  const root = path.resolve(vaultPath);
46
47
  const trashPath = uniqueTrashPath(ensureWithinRoot(vaultPath, path.join('.trash', path.relative(root, notePath))));
@@ -51,11 +52,11 @@ export function handleDelete(vaultPath, args) {
51
52
  export function handleMove(vaultPath, args) {
52
53
  const notePath = resolveNotePath(vaultPath, args);
53
54
  if (!notePath || !fs.existsSync(notePath)) {
54
- throw new Error(`Note not found. Args: ${args.join(', ')}`);
55
+ throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
55
56
  }
56
57
  const to = getArg(args, 'to');
57
58
  if (!to) {
58
- throw new Error('Missing required argument: to=');
59
+ throw new HarnessError('OBSIDIAN_MISSING_ARGUMENT', ['to=']);
59
60
  }
60
61
  const destDir = ensureWithinRoot(vaultPath, to);
61
62
  if (!fs.existsSync(destDir)) {
@@ -68,11 +69,11 @@ export function handleMove(vaultPath, args) {
68
69
  export function handleRename(vaultPath, args) {
69
70
  const notePath = resolveNotePath(vaultPath, args);
70
71
  if (!notePath || !fs.existsSync(notePath)) {
71
- throw new Error(`Note not found. Args: ${args.join(', ')}`);
72
+ throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
72
73
  }
73
74
  const newName = getArg(args, 'name');
74
75
  if (!newName) {
75
- throw new Error('Missing required argument: name=');
76
+ throw new HarnessError('OBSIDIAN_MISSING_ARGUMENT', ['name=']);
76
77
  }
77
78
  const fileName = markdownFileName(newName);
78
79
  const relativeDir = path.relative(path.resolve(vaultPath), path.dirname(notePath));
@@ -96,11 +97,11 @@ function mergeIntoFrontmatter(fmBlock, newProps) {
96
97
  export function handlePropertySet(vaultPath, args) {
97
98
  const notePath = resolveNotePath(vaultPath, args);
98
99
  if (!notePath || !fs.existsSync(notePath)) {
99
- throw new Error(`Note not found. Args: ${args.join(', ')}`);
100
+ throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
100
101
  }
101
102
  const propArgs = args.filter((a) => !a.startsWith('file=') && !a.startsWith('path=') && a.includes('='));
102
103
  if (propArgs.length === 0) {
103
- throw new Error('No property key=value pairs provided.');
104
+ throw new HarnessError('OBSIDIAN_NO_PROPERTIES');
104
105
  }
105
106
  const newProps = propArgs.map((a) => {
106
107
  const eqIdx = a.indexOf('=');
@@ -120,7 +121,7 @@ export function handlePropertySet(vaultPath, args) {
120
121
  export function handleDailyAppend(vaultPath, args) {
121
122
  const content = getContentArg(args);
122
123
  if (!content) {
123
- throw new Error('Missing required argument: content=');
124
+ throw new HarnessError('OBSIDIAN_MISSING_ARGUMENT', ['content=']);
124
125
  }
125
126
  const dateStr = todayStamp();
126
127
  let target = null;
@@ -1,8 +1,9 @@
1
1
  import { type GuardedFetch, type GuardedFetchOptions } from '../../lib/guarded-fetch.ts';
2
2
  declare const GUARDED: unique symbol;
3
3
  export interface ConnectPolicy {
4
- readonly named: readonly string[];
4
+ readonly named?: readonly string[] | undefined;
5
5
  readonly ask: (host: string) => Promise<boolean>;
6
+ readonly allowed?: readonly string[] | undefined;
6
7
  }
7
8
  export declare function setConnectPolicy(next: ConnectPolicy | null): void;
8
9
  export declare function isGuardedFetch(fetch: unknown): boolean;
@@ -1,4 +1,5 @@
1
1
  import { createGuardedFetch as createCoreFetch } from '../../lib/guarded-fetch.js';
2
+ import { Policy } from '../../lib/policy/index.js';
2
3
  import { hostIsNamed } from './named-hosts.js';
3
4
  const GUARDED = Symbol.for('qvac.harness.guardedFetch');
4
5
  let policy = null;
@@ -8,7 +9,10 @@ export function setConnectPolicy(next) {
8
9
  granted.clear();
9
10
  }
10
11
  async function mayConnect(host) {
11
- if (!policy || granted.has(host) || hostIsNamed(host, policy.named)) {
12
+ if (policy?.allowed && !Policy.allowsHost(policy.allowed, host)) {
13
+ return false;
14
+ }
15
+ if (!policy?.named || granted.has(host) || hostIsNamed(host, policy.named)) {
12
16
  return true;
13
17
  }
14
18
  const allowed = await policy.ask(host);
@@ -1,7 +1,7 @@
1
1
  import { fileURLToPath } from 'url';
2
2
  import { Worker } from 'worker_threads';
3
3
  import { errorMessage } from '../../lib/guards.js';
4
- import { hlog } from '../../lib/log.js';
4
+ import { HarnessLog } from '../../lib/log.js';
5
5
  import { DISARMED, FIRED } from './deadline-state.js';
6
6
  export function startInterruptTimer(ms) {
7
7
  const state = new Int32Array(new SharedArrayBuffer(4));
@@ -9,7 +9,7 @@ export function startInterruptTimer(ms) {
9
9
  const workerData = { state: state.buffer, interrupt: interrupt.buffer, ms };
10
10
  const entry = fileURLToPath(import.meta.resolve('#pyodide-interrupt-deadline'));
11
11
  new Worker(entry, { workerData })
12
- .on('error', (error) => hlog('python: interrupt deadline failed', { err: errorMessage(error) }))
12
+ .on('error', (error) => HarnessLog.warn('python: interrupt deadline failed', { err: errorMessage(error) }))
13
13
  .unref();
14
14
  return {
15
15
  interrupt,
@@ -90,10 +90,71 @@ export function pyodideLoadOptions() {
90
90
  return { ...silentStdio, packageCacheDir: cacheDir };
91
91
  }
92
92
  function pyodideIndexURL() {
93
+ if (typeof import.meta.asset !== 'function') {
94
+ return path.dirname(fileURLToPath(import.meta.resolve('pyodide'))) + '/';
95
+ }
93
96
  import.meta.asset('pyodide/python_stdlib.zip');
94
97
  import.meta.asset('pyodide/pyodide-lock.json');
95
98
  return path.dirname(fileURLToPath(import.meta.asset('pyodide/pyodide.asm.wasm'))) + '/';
96
99
  }
100
+ const JS_GLOBALS = [
101
+ 'setTimeout',
102
+ 'clearTimeout',
103
+ 'setInterval',
104
+ 'clearInterval',
105
+ 'fetch',
106
+ 'AbortController',
107
+ 'AbortSignal',
108
+ 'Object',
109
+ 'Request'
110
+ ];
111
+ function guestGlobals() {
112
+ const g = globalThis;
113
+ const allowed = Object.create(null);
114
+ for (const name of JS_GLOBALS) {
115
+ Object.defineProperty(allowed, name, { get: () => g[name], enumerable: true });
116
+ }
117
+ return allowed;
118
+ }
119
+ function nullObject(fields) {
120
+ return Object.assign(Object.create(null), fields);
121
+ }
122
+ function guestPyodideJs(py) {
123
+ const api = py._api;
124
+ const loadPackage = (names) => {
125
+ const list = typeof names === 'string' ? [names] : Array.from(names);
126
+ for (const name of list) {
127
+ if (!Object.hasOwn(api.lockfile_packages, name)) {
128
+ throw new Error(`not a lockfile package: ${name}`);
129
+ }
130
+ }
131
+ return py.loadPackage(list);
132
+ };
133
+ const internals = nullObject({
134
+ install: api.install,
135
+ loadBinaryFile: () => {
136
+ throw new Error('loadBinaryFile reads host files and is refused');
137
+ },
138
+ lockfile_packages: JSON.parse(JSON.stringify(api.lockfile_packages)),
139
+ lockfile_info: JSON.parse(JSON.stringify(api.lockfile_info)),
140
+ scheduleCallback: api.scheduleCallback,
141
+ abortSignalAny: api.abortSignalAny,
142
+ config: nullObject({ enableRunUntilComplete: api.config.enableRunUntilComplete })
143
+ });
144
+ const module = nullObject({ lockfileBaseUrl: py.lockfileBaseUrl, loadPackage, _api: internals });
145
+ Object.defineProperty(module, 'loadedPackages', {
146
+ get: () => py.loadedPackages,
147
+ enumerable: true
148
+ });
149
+ return module;
150
+ }
151
+ const FORGET_PYODIDE_JS = `
152
+ def _forget(modules):
153
+ for name in [name for name in modules if name == 'pyodide_js' or name.startswith('pyodide_js.')]:
154
+ del modules[name]
155
+ _forget(__import__('sys').modules)
156
+ del _forget
157
+ `;
97
158
  async function importPyodide() {
98
159
  if (typeof globalThis.Bare !== 'undefined') {
99
160
  await shapeBareGlobals();
@@ -112,9 +173,13 @@ export const defaultLoad = async () => {
112
173
  seedPackageCache(options.packageCacheDir);
113
174
  }
114
175
  const indexURL = pyodideIndexURL();
115
- return (await loadPyodide({
176
+ const py = await loadPyodide({
116
177
  ...options,
117
178
  indexURL,
118
- createPyodideModule
119
- }));
179
+ createPyodideModule,
180
+ jsglobals: guestGlobals()
181
+ });
182
+ py.registerJsModule('pyodide_js', guestPyodideJs(py));
183
+ py.runPython(FORGET_PYODIDE_JS);
184
+ return py;
120
185
  };
@@ -1,5 +1,5 @@
1
1
  import { errorMessage } from '../../lib/guards.js';
2
- import { hlog } from '../../lib/log.js';
2
+ import { HarnessLog } from '../../lib/log.js';
3
3
  import { MAX_OUTPUT_FILE_BYTES, MAX_OUTPUT_TOTAL_BYTES } from '../../lib/tools/attachments/output-policy.js';
4
4
  let runCounter = 0;
5
5
  function filePath(dir, name) {
@@ -69,7 +69,7 @@ export function removeScratch(fs, dir, previousCwd) {
69
69
  removeTree(fs, dir);
70
70
  }
71
71
  catch (error) {
72
- hlog('python: scratch cleanup failed', {
72
+ HarnessLog.warn('python: scratch cleanup failed', {
73
73
  dir,
74
74
  err: errorMessage(error)
75
75
  });
@@ -18,5 +18,6 @@ export interface RunPythonOptions {
18
18
  readonly network?: boolean;
19
19
  readonly hosts?: readonly string[];
20
20
  readonly askConnect?: (host: string) => Promise<boolean>;
21
+ readonly allowed?: readonly string[];
21
22
  }
22
23
  export declare function runPython(code: string, options?: RunPythonOptions): Promise<PythonRunResult>;
@@ -2,7 +2,8 @@ import { AbortController } from 'bare-abort-controller';
2
2
  import ScopeLock from 'scope-lock';
3
3
  import { errorMessage } from '../../lib/guards.js';
4
4
  import { AbortedError, raceAbort } from '../../lib/helpers/race-abort.js';
5
- import { hlog } from '../../lib/log.js';
5
+ import { HarnessError } from '../../lib/errors.js';
6
+ import { HarnessLog } from '../../lib/log.js';
6
7
  import { MAX_OUTPUT_CHARS } from '../../lib/tools/exec/runner.js';
7
8
  import { startInterruptTimer } from './interrupt-timer.js';
8
9
  import { pyodideLoadOptions } from './loader.js';
@@ -15,15 +16,15 @@ const cache = new Map();
15
16
  function getPyodide(load) {
16
17
  let loaded = cache.get(load);
17
18
  if (!loaded) {
18
- hlog('python: booting interpreter');
19
+ HarnessLog.info('python: booting interpreter');
19
20
  loaded = load()
20
21
  .then((py) => {
21
- hlog('python: interpreter ready');
22
+ HarnessLog.info('python: interpreter ready');
22
23
  return py;
23
24
  })
24
25
  .catch((error) => {
25
26
  cache.delete(load);
26
- hlog('python: interpreter boot failed', {
27
+ HarnessLog.error('python: interpreter boot failed', {
27
28
  err: errorMessage(error)
28
29
  });
29
30
  throw error;
@@ -35,7 +36,6 @@ function getPyodide(load) {
35
36
  const runLock = new ScopeLock();
36
37
  async function runInProcess(load, spec, options) {
37
38
  const deadline = Date.now() + options.timeoutMs;
38
- const timeoutMessage = `Command timed out after ${options.timeoutMs}ms`;
39
39
  let timedOut = false;
40
40
  const stop = new AbortController();
41
41
  const ask = options.askConnect;
@@ -63,10 +63,10 @@ async function runInProcess(load, spec, options) {
63
63
  }
64
64
  if (outcome.evict) {
65
65
  cache.delete(load);
66
- hlog('python: interpreter evicted; next run boots fresh');
66
+ HarnessLog.warn('python: interpreter evicted; next run boots fresh');
67
67
  }
68
68
  if (timedOut) {
69
- throw new Error(timeoutMessage);
69
+ throw new HarnessError('COMMAND_TIMED_OUT', [options.timeoutMs]);
70
70
  }
71
71
  return outcome.result;
72
72
  }
@@ -84,7 +84,7 @@ async function runInProcess(load, spec, options) {
84
84
  const timeout = new Promise((_, reject) => {
85
85
  timer = setTimeout(() => {
86
86
  timedOut = true;
87
- reject(new Error(timeoutMessage));
87
+ reject(new HarnessError('COMMAND_TIMED_OUT', [options.timeoutMs]));
88
88
  }, options.timeoutMs);
89
89
  });
90
90
  try {
@@ -111,6 +111,7 @@ export async function runPython(code, options = {}) {
111
111
  maxOutputChars: options.maxOutputChars ?? MAX_OUTPUT_CHARS,
112
112
  network: options.network === true,
113
113
  hosts: options.hosts,
114
+ allowed: options.allowed,
114
115
  installTimeoutMs: timeoutMs
115
116
  };
116
117
  if (options.loadPyodide) {