@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
@@ -0,0 +1,554 @@
1
+ // qvac-sandbox: runs one cmd line inside the harness's AppContainer.
2
+ //
3
+ // qvac-sandbox --probe
4
+ // qvac-sandbox --prepare [--deny <root>]... [--pin <folder>]...
5
+ // [--write <capability> <root>]... [--read <capability> <root>]...
6
+ // qvac-sandbox [--cap <capability>]... [--net] [--cwd <dir>] -- <line>
7
+ //
8
+ // --prepare changes ACLs and runs nothing; a line run changes no ACL, so killing it never
9
+ // leaves a tree half written. Each root is granted to its own capability SID, and the child's
10
+ // token carries only the capabilities of this run, so a grant an earlier run left on a folder
11
+ // does nothing here. A denied root gets a protected DACL that holds no capability, so no grant
12
+ // reaches it. With no --cwd the line starts in its TEMP. A failure before the child starts
13
+ // exits REFUSED with a `qvac-sandbox:` line on stderr.
14
+ //
15
+ // MSVC: cl /nologo /std:c11 /O2 /W4 qvac-sandbox.c
16
+
17
+ #ifndef UNICODE
18
+ #define UNICODE
19
+ #endif
20
+ #ifndef _UNICODE
21
+ #define _UNICODE
22
+ #endif
23
+ #define WIN32_LEAN_AND_MEAN
24
+
25
+ #include <windows.h>
26
+ #include <aclapi.h>
27
+ #include <sddl.h>
28
+ #include <userenv.h>
29
+ #include <objbase.h>
30
+ #include <shlobj.h>
31
+ #include <knownfolders.h>
32
+ #include <stdio.h>
33
+ #include <stdlib.h>
34
+ #include <wchar.h>
35
+
36
+ #ifdef _MSC_VER
37
+ #pragma comment(lib, "advapi32.lib")
38
+ #pragma comment(lib, "userenv.lib")
39
+ #pragma comment(lib, "ole32.lib")
40
+ #pragma comment(lib, "shell32.lib")
41
+ #pragma comment(lib, "uuid.lib")
42
+ #endif
43
+
44
+ // AppContainerSandbox's REFUSED holds the same number
45
+ #define REFUSED 125
46
+ #define PROFILE L"qvac.harness.sandbox"
47
+ #define MAX_ROOTS 256
48
+ #define NETWORK_CAPABILITIES 3
49
+
50
+ #define READ_MASK (FILE_GENERIC_READ | FILE_GENERIC_EXECUTE)
51
+ // No FILE_DELETE_CHILD: a denied folder inside a write root cannot be removed or renamed away
52
+ #define WRITE_MASK (READ_MASK | FILE_GENERIC_WRITE | DELETE)
53
+ #define DENY_MASK FILE_ALL_ACCESS
54
+ #define INHERIT (OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE)
55
+ #define ROOT_ONLY 0
56
+
57
+ typedef BOOL(WINAPI *derive_capability_t)(LPCWSTR, PSID **, DWORD *, PSID **, DWORD *);
58
+
59
+ typedef struct {
60
+ const wchar_t *capability;
61
+ const wchar_t *root;
62
+ } grant_t;
63
+
64
+ typedef struct {
65
+ grant_t write[MAX_ROOTS];
66
+ grant_t read[MAX_ROOTS];
67
+ const wchar_t *deny[MAX_ROOTS];
68
+ const wchar_t *pin[MAX_ROOTS];
69
+ const wchar_t *cap[2 * MAX_ROOTS];
70
+ int writes, reads, denies, pins, caps;
71
+ BOOL network, probe, prepare;
72
+ const wchar_t *cwd, *line;
73
+ } request_t;
74
+
75
+ static int
76
+ refuse(const wchar_t *what, const wchar_t *subject, DWORD error) {
77
+ fwprintf(stderr, L"qvac-sandbox: %ls%ls%ls (error %lu)\n", what, subject ? L" " : L"", subject ? subject : L"", error);
78
+ return REFUSED;
79
+ }
80
+
81
+ static BOOL
82
+ parse(int argc, wchar_t **argv, request_t *req) {
83
+ for (int i = 1; i < argc; i++) {
84
+ const wchar_t *arg = argv[i];
85
+ if (wcscmp(arg, L"--probe") == 0) {
86
+ req->probe = TRUE;
87
+ } else if (wcscmp(arg, L"--prepare") == 0) {
88
+ req->prepare = TRUE;
89
+ } else if (wcscmp(arg, L"--net") == 0) {
90
+ req->network = TRUE;
91
+ } else if (wcscmp(arg, L"--write") == 0 && i + 2 < argc && req->writes < MAX_ROOTS) {
92
+ req->write[req->writes++] = (grant_t){argv[i + 1], argv[i + 2]};
93
+ i += 2;
94
+ } else if (wcscmp(arg, L"--read") == 0 && i + 2 < argc && req->reads < MAX_ROOTS) {
95
+ req->read[req->reads++] = (grant_t){argv[i + 1], argv[i + 2]};
96
+ i += 2;
97
+ } else if (wcscmp(arg, L"--deny") == 0 && i + 1 < argc && req->denies < MAX_ROOTS) {
98
+ req->deny[req->denies++] = argv[++i];
99
+ } else if (wcscmp(arg, L"--pin") == 0 && i + 1 < argc && req->pins < MAX_ROOTS) {
100
+ req->pin[req->pins++] = argv[++i];
101
+ } else if (wcscmp(arg, L"--cap") == 0 && i + 1 < argc && req->caps < 2 * MAX_ROOTS) {
102
+ req->cap[req->caps++] = argv[++i];
103
+ } else if (wcscmp(arg, L"--cwd") == 0 && i + 1 < argc) {
104
+ req->cwd = argv[++i];
105
+ } else if (wcscmp(arg, L"--") == 0 && i + 2 == argc) {
106
+ req->line = argv[++i];
107
+ } else {
108
+ return FALSE;
109
+ }
110
+ }
111
+
112
+ return req->probe || req->prepare || req->line;
113
+ }
114
+
115
+ // Made once per user; every later run derives the same SID from the name
116
+ static HRESULT
117
+ container(PSID *sid) {
118
+ HRESULT hr = CreateAppContainerProfile(PROFILE, PROFILE, L"qvac harness exec sandbox", NULL, 0, sid);
119
+ if (hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)) {
120
+ hr = DeriveAppContainerSidFromAppContainerName(PROFILE, sid);
121
+ }
122
+
123
+ return hr;
124
+ }
125
+
126
+ // Kernelbase exports it with no import library in older SDKs
127
+ static PSID
128
+ capability(const wchar_t *name) {
129
+ static derive_capability_t derive = NULL;
130
+ if (!derive) {
131
+ HMODULE kernelbase = GetModuleHandleW(L"kernelbase.dll");
132
+ if (!kernelbase) return NULL;
133
+ derive = (derive_capability_t) (void *) GetProcAddress(kernelbase, "DeriveCapabilitySidsFromName");
134
+ if (!derive) return NULL;
135
+ }
136
+
137
+ PSID *groups = NULL, *sids = NULL;
138
+ DWORD group_count = 0, sid_count = 0;
139
+ if (!derive(name, &groups, &group_count, &sids, &sid_count) || sid_count < 1) return NULL;
140
+
141
+ return sids[0];
142
+ }
143
+
144
+ // An explicit ACE whose inheritance flags are exactly `flags`
145
+ static BOOL
146
+ has_ace(PACL dacl, BYTE type, PSID sid, DWORD mask, BYTE flags) {
147
+ if (!dacl) return FALSE;
148
+
149
+ for (DWORD i = 0; i < dacl->AceCount; i++) {
150
+ ACE_HEADER *header;
151
+ if (!GetAce(dacl, i, (void **) &header)) continue;
152
+ if (header->AceType != type || (header->AceFlags & VALID_INHERIT_FLAGS) != flags) continue;
153
+
154
+ // An allowed and a denied ACE share this layout
155
+ ACCESS_ALLOWED_ACE *ace = (ACCESS_ALLOWED_ACE *) header;
156
+ if ((ace->Mask & mask) == mask && EqualSid((PSID) &ace->SidStart, sid)) return TRUE;
157
+ }
158
+
159
+ return FALSE;
160
+ }
161
+
162
+ // A root-only ACE written to this one object, with no walk below it. Written after a walk, it
163
+ // is the proof that the walk finished: a check of the root's own entry alone proves nothing.
164
+ static DWORD
165
+ mark(const wchar_t *path, BYTE type, PSID sid, DWORD mask) {
166
+ PACL dacl = NULL, marked = NULL;
167
+ PSECURITY_DESCRIPTOR descriptor = NULL;
168
+ DWORD error = GetNamedSecurityInfoW(path, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, &dacl, NULL, &descriptor);
169
+ if (error != ERROR_SUCCESS) return error;
170
+
171
+ if (!dacl) {
172
+ error = ERROR_INVALID_ACL;
173
+ } else if (!has_ace(dacl, type, sid, mask, ROOT_ONLY)) {
174
+ BOOL deny = type == ACCESS_DENIED_ACE_TYPE, placed = FALSE;
175
+ DWORD size = dacl->AclSize + sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(sid);
176
+ marked = LocalAlloc(LPTR, size);
177
+ BOOL ok = marked && InitializeAcl(marked, size, dacl->AclRevision);
178
+
179
+ // Canonical order: a deny goes first, an allow before the first inherited entry
180
+ for (DWORD i = 0; ok && i <= dacl->AceCount; i++) {
181
+ ACE_HEADER *header = NULL;
182
+ if (i < dacl->AceCount) ok = GetAce(dacl, i, (void **) &header);
183
+ if (ok && !placed && (deny || !header || (header->AceFlags & INHERITED_ACE))) {
184
+ placed = TRUE;
185
+ ok = deny ? AddAccessDeniedAceEx(marked, dacl->AclRevision, ROOT_ONLY, mask, sid)
186
+ : AddAccessAllowedAceEx(marked, dacl->AclRevision, ROOT_ONLY, mask, sid);
187
+ }
188
+ if (ok && header) ok = AddAce(marked, dacl->AclRevision, MAXDWORD, header, header->AceSize);
189
+ }
190
+
191
+ // SetFileSecurityW writes no child; the copied control bits keep the root protected or inheriting
192
+ SECURITY_DESCRIPTOR fresh;
193
+ SECURITY_DESCRIPTOR_CONTROL control = 0, kept = SE_DACL_PROTECTED | SE_DACL_AUTO_INHERITED;
194
+ DWORD revision = 0;
195
+ ok = ok && GetSecurityDescriptorControl(descriptor, &control, &revision) &&
196
+ InitializeSecurityDescriptor(&fresh, SECURITY_DESCRIPTOR_REVISION) &&
197
+ SetSecurityDescriptorDacl(&fresh, TRUE, marked, FALSE) &&
198
+ SetSecurityDescriptorControl(&fresh, kept, control & kept) &&
199
+ SetFileSecurityW(path, DACL_SECURITY_INFORMATION, &fresh);
200
+ error = ok ? ERROR_SUCCESS : GetLastError();
201
+ }
202
+
203
+ LocalFree(marked);
204
+ LocalFree(descriptor);
205
+
206
+ return error;
207
+ }
208
+
209
+ // An inheritable ACE on the root and every file below it, then its proof. With no proof the
210
+ // ACL is written again, which walks the tree again, so a walk cut short is finished.
211
+ static DWORD
212
+ add_ace(const wchar_t *root, PSID sid, DWORD mask) {
213
+ PACL dacl = NULL, merged = NULL;
214
+ PSECURITY_DESCRIPTOR descriptor = NULL;
215
+ DWORD error = GetNamedSecurityInfoW(root, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, &dacl, NULL, &descriptor);
216
+ if (error != ERROR_SUCCESS) return error;
217
+
218
+ if (!has_ace(dacl, ACCESS_ALLOWED_ACE_TYPE, sid, mask, ROOT_ONLY)) {
219
+ if (!has_ace(dacl, ACCESS_ALLOWED_ACE_TYPE, sid, mask, INHERIT)) {
220
+ EXPLICIT_ACCESSW access = {0};
221
+ access.grfAccessPermissions = mask;
222
+ access.grfAccessMode = GRANT_ACCESS;
223
+ access.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
224
+ access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
225
+ access.Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
226
+ access.Trustee.ptstrName = (LPWSTR) sid;
227
+
228
+ error = SetEntriesInAclW(1, &access, dacl, &merged);
229
+ }
230
+
231
+ if (error == ERROR_SUCCESS) {
232
+ error = SetNamedSecurityInfoW((LPWSTR) root, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, merged ? merged : dacl, NULL);
233
+ }
234
+ if (error == ERROR_SUCCESS) error = mark(root, ACCESS_ALLOWED_ACE_TYPE, sid, mask);
235
+
236
+ LocalFree(merged);
237
+ }
238
+
239
+ LocalFree(descriptor);
240
+
241
+ return error;
242
+ }
243
+
244
+ static BOOL
245
+ denies(const ACE_HEADER *header) {
246
+ return header->AceType == ACCESS_DENIED_ACE_TYPE || header->AceType == ACCESS_DENIED_CALLBACK_ACE_TYPE;
247
+ }
248
+
249
+ // An allow for a capability SID (S-1-15-3-...), explicit or inherited
250
+ static BOOL
251
+ grants_capability(const ACE_HEADER *header) {
252
+ static const SID_IDENTIFIER_AUTHORITY app_package = SECURITY_APP_PACKAGE_AUTHORITY;
253
+ if (header->AceType != ACCESS_ALLOWED_ACE_TYPE && header->AceType != ACCESS_ALLOWED_CALLBACK_ACE_TYPE) return FALSE;
254
+
255
+ // A callback ACE shares this layout
256
+ PSID sid = (PSID) &((ACCESS_ALLOWED_ACE *) header)->SidStart;
257
+ return memcmp(GetSidIdentifierAuthority(sid), &app_package, sizeof(app_package)) == 0 &&
258
+ *GetSidSubAuthorityCount(sid) > 0 && *GetSidSubAuthority(sid, 0) == SECURITY_CAPABILITY_BASE_RID;
259
+ }
260
+
261
+ static BOOL
262
+ fenced(PSECURITY_DESCRIPTOR descriptor, PACL dacl, PSID container_sid) {
263
+ SECURITY_DESCRIPTOR_CONTROL control = 0;
264
+ DWORD revision = 0;
265
+ if (!GetSecurityDescriptorControl(descriptor, &control, &revision) || !(control & SE_DACL_PROTECTED)) return FALSE;
266
+
267
+ for (DWORD i = 0; i < dacl->AceCount; i++) {
268
+ ACE_HEADER *header;
269
+ if (GetAce(dacl, i, (void **) &header) && grants_capability(header)) return FALSE;
270
+ }
271
+
272
+ return has_ace(dacl, ACCESS_DENIED_ACE_TYPE, container_sid, DENY_MASK, INHERIT) &&
273
+ has_ace(dacl, ACCESS_DENIED_ACE_TYPE, container_sid, DENY_MASK, ROOT_ONLY);
274
+ }
275
+
276
+ // The container's deny ACE alone holds writes but not reads. A denied root instead inherits
277
+ // nothing and keeps no capability allow, so no grant on it or above it opens it; every other
278
+ // entry stays, made explicit, so its owner keeps their access. Skipped once its proof is there.
279
+ static DWORD
280
+ protect(const wchar_t *root, PSID container_sid) {
281
+ PACL dacl = NULL, rebuilt = NULL;
282
+ PSECURITY_DESCRIPTOR descriptor = NULL;
283
+ DWORD error = GetNamedSecurityInfoW(root, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, &dacl, NULL, &descriptor);
284
+ if (error != ERROR_SUCCESS) return error;
285
+
286
+ // A null DACL lets everyone in; a deny-only DACL in its place would lock the owner out
287
+ if (!dacl) {
288
+ error = ERROR_INVALID_ACL;
289
+ } else if (!fenced(descriptor, dacl, container_sid)) {
290
+ DWORD size = dacl->AclSize + sizeof(ACCESS_DENIED_ACE) + GetLengthSid(container_sid);
291
+ rebuilt = LocalAlloc(LPTR, size);
292
+ BOOL ok = rebuilt && InitializeAcl(rebuilt, size, dacl->AclRevision) &&
293
+ AddAccessDeniedAceEx(rebuilt, dacl->AclRevision, INHERIT, DENY_MASK, container_sid);
294
+
295
+ // Every entry is explicit now, so denies go first or an allow before them wins
296
+ for (int pass = 0; ok && pass < 2; pass++) {
297
+ for (DWORD i = 0; ok && i < dacl->AceCount; i++) {
298
+ ACE_HEADER *header, *added;
299
+ if (!GetAce(dacl, i, (void **) &header) || denies(header) != (pass == 0) || grants_capability(header)) continue;
300
+ if (denies(header) && EqualSid((PSID) &((ACCESS_DENIED_ACE *) header)->SidStart, container_sid)) continue;
301
+
302
+ ok = AddAce(rebuilt, dacl->AclRevision, MAXDWORD, header, header->AceSize) &&
303
+ GetAce(rebuilt, rebuilt->AceCount - 1, (void **) &added);
304
+ if (ok) added->AceFlags &= ~INHERITED_ACE;
305
+ }
306
+ }
307
+
308
+ error = ok ? SetNamedSecurityInfoW((LPWSTR) root, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION | PROTECTED_DACL_SECURITY_INFORMATION, NULL, NULL, rebuilt, NULL)
309
+ : GetLastError();
310
+ if (error == ERROR_SUCCESS) error = mark(root, ACCESS_DENIED_ACE_TYPE, container_sid, DENY_MASK);
311
+ }
312
+
313
+ LocalFree(rebuilt);
314
+ LocalFree(descriptor);
315
+
316
+ return error;
317
+ }
318
+
319
+ static BOOL
320
+ missing(DWORD error) {
321
+ return error == ERROR_FILE_NOT_FOUND || error == ERROR_PATH_NOT_FOUND;
322
+ }
323
+
324
+ // Fences each denied root, pins the folders above it, then grants each root to its capability.
325
+ // Fenced first, a parent's new grant stops at the protected root.
326
+ static int
327
+ prepare(const request_t *req, PSID container_sid) {
328
+ for (int i = 0; i < req->denies; i++) {
329
+ DWORD error = protect(req->deny[i], container_sid);
330
+ if (error != ERROR_SUCCESS && !missing(error)) return refuse(L"could not deny", req->deny[i], error);
331
+ }
332
+
333
+ // A line that renames a folder above a denied root would move the root out from under its path
334
+ for (int i = 0; i < req->pins; i++) {
335
+ DWORD error = mark(req->pin[i], ACCESS_DENIED_ACE_TYPE, container_sid, DELETE);
336
+ if (error != ERROR_SUCCESS && !missing(error)) return refuse(L"could not pin", req->pin[i], error);
337
+ }
338
+
339
+ for (int i = 0; i < req->writes + req->reads; i++) {
340
+ BOOL writes = i < req->writes;
341
+ const grant_t *each = writes ? &req->write[i] : &req->read[i - req->writes];
342
+ PSID sid = capability(each->capability);
343
+ if (!sid) return refuse(L"could not derive the capability for", each->root, GetLastError());
344
+
345
+ DWORD error = add_ace(each->root, sid, writes ? WRITE_MASK : READ_MASK);
346
+ // A read root that does not exist yet has nothing to grant
347
+ if (error != ERROR_SUCCESS && (writes || !missing(error))) return refuse(L"could not grant", each->root, error);
348
+ }
349
+
350
+ return 0;
351
+ }
352
+
353
+ static int
354
+ capabilities(const request_t *req, SID_AND_ATTRIBUTES *caps, DWORD *count) {
355
+ for (int i = 0; i < req->caps; i++) {
356
+ PSID sid = capability(req->cap[i]);
357
+ if (!sid) return refuse(L"could not derive the capability", req->cap[i], GetLastError());
358
+
359
+ caps[(*count)++] = (SID_AND_ATTRIBUTES){sid, SE_GROUP_ENABLED};
360
+ }
361
+
362
+ return 0;
363
+ }
364
+
365
+ static int
366
+ network(SID_AND_ATTRIBUTES *caps, DWORD *count, BYTE storage[][SECURITY_MAX_SID_SIZE]) {
367
+ static const WELL_KNOWN_SID_TYPE kinds[NETWORK_CAPABILITIES] = {
368
+ WinCapabilityInternetClientSid,
369
+ WinCapabilityInternetClientServerSid,
370
+ WinCapabilityPrivateNetworkClientServerSid,
371
+ };
372
+
373
+ for (int i = 0; i < NETWORK_CAPABILITIES; i++) {
374
+ DWORD size = SECURITY_MAX_SID_SIZE;
375
+ if (!CreateWellKnownSid(kinds[i], NULL, storage[i], &size)) {
376
+ return refuse(L"could not make a network capability", NULL, GetLastError());
377
+ }
378
+
379
+ caps[(*count)++] = (SID_AND_ATTRIBUTES){storage[i], SE_GROUP_ENABLED};
380
+ }
381
+
382
+ return 0;
383
+ }
384
+
385
+ // Windows builds the container's environment from these; the run's env allowlist leaves them out
386
+ static int
387
+ app_data(void) {
388
+ static const struct {
389
+ const wchar_t *name;
390
+ const KNOWNFOLDERID *folder;
391
+ } dirs[] = {
392
+ {L"LOCALAPPDATA", &FOLDERID_LocalAppData},
393
+ {L"APPDATA", &FOLDERID_RoamingAppData},
394
+ };
395
+
396
+ for (size_t i = 0; i < sizeof(dirs) / sizeof(dirs[0]); i++) {
397
+ if (GetEnvironmentVariableW(dirs[i].name, NULL, 0) > 0) continue;
398
+
399
+ PWSTR path = NULL;
400
+ HRESULT hr = SHGetKnownFolderPath(dirs[i].folder, 0, NULL, &path);
401
+ if (FAILED(hr)) return refuse(L"could not find", dirs[i].name, (DWORD) hr);
402
+
403
+ BOOL set = SetEnvironmentVariableW(dirs[i].name, path);
404
+ CoTaskMemFree(path);
405
+ if (!set) return refuse(L"could not set", dirs[i].name, GetLastError());
406
+ }
407
+
408
+ return 0;
409
+ }
410
+
411
+ // TEMP and TMP point into the container's own folder, which it can write with no grant
412
+ static int
413
+ temp_dir(PSID container_sid, wchar_t temp[MAX_PATH * 2]) {
414
+ LPWSTR sid_string = NULL, folder = NULL;
415
+ if (!ConvertSidToStringSidW(container_sid, &sid_string)) {
416
+ return refuse(L"could not name the container", NULL, GetLastError());
417
+ }
418
+
419
+ HRESULT hr = GetAppContainerFolderPath(sid_string, &folder);
420
+ LocalFree(sid_string);
421
+ if (FAILED(hr)) return refuse(L"could not find the container folder", NULL, (DWORD) hr);
422
+
423
+ int written = swprintf(temp, MAX_PATH * 2, L"%ls\\Temp", folder);
424
+ CoTaskMemFree(folder);
425
+ if (written < 0) return refuse(L"the container folder path is too long", NULL, ERROR_BUFFER_OVERFLOW);
426
+
427
+ if (!CreateDirectoryW(temp, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) {
428
+ return refuse(L"could not make", temp, GetLastError());
429
+ }
430
+
431
+ if (!SetEnvironmentVariableW(L"TEMP", temp) || !SetEnvironmentVariableW(L"TMP", temp)) {
432
+ return refuse(L"could not set TEMP", NULL, GetLastError());
433
+ }
434
+
435
+ return 0;
436
+ }
437
+
438
+ // The child gets the stdio handles and nothing else this process holds
439
+ static DWORD
440
+ stdio_handles(HANDLE std[3], HANDLE inherit[3]) {
441
+ DWORD count = 0;
442
+ for (int i = 0; i < 3; i++) {
443
+ HANDLE handle = std[i];
444
+ if (handle == NULL || handle == INVALID_HANDLE_VALUE) continue;
445
+
446
+ BOOL listed = FALSE;
447
+ for (DWORD j = 0; j < count; j++) listed |= inherit[j] == handle;
448
+ if (listed || !SetHandleInformation(handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) continue;
449
+
450
+ inherit[count++] = handle;
451
+ }
452
+
453
+ return count;
454
+ }
455
+
456
+ // Runs `%COMSPEC% /d /s /c "<line>"`, as Node's shell: true does, in a Job that dies with this process
457
+ static int
458
+ run(PSID container_sid, SID_AND_ATTRIBUTES *caps, DWORD count, const wchar_t *cwd, const wchar_t *line) {
459
+ wchar_t comspec[MAX_PATH];
460
+ DWORD length = GetEnvironmentVariableW(L"COMSPEC", comspec, MAX_PATH);
461
+ if (length == 0 || length >= MAX_PATH) {
462
+ length = GetSystemDirectoryW(comspec, MAX_PATH);
463
+ if (length == 0 || length + 9 > MAX_PATH) return refuse(L"could not find cmd.exe", NULL, GetLastError());
464
+ wcscat_s(comspec, MAX_PATH, L"\\cmd.exe");
465
+ }
466
+
467
+ size_t size = wcslen(comspec) + wcslen(line) + 16;
468
+ wchar_t *command = malloc(size * sizeof(wchar_t));
469
+ if (!command || swprintf(command, size, L"\"%ls\" /d /s /c \"%ls\"", comspec, line) < 0) {
470
+ return refuse(L"the line is too long", NULL, ERROR_BUFFER_OVERFLOW);
471
+ }
472
+
473
+ HANDLE job = CreateJobObjectW(NULL, NULL);
474
+ JOBOBJECT_EXTENDED_LIMIT_INFORMATION limits = {0};
475
+ limits.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
476
+ if (!job || !SetInformationJobObject(job, JobObjectExtendedLimitInformation, &limits, sizeof(limits))) {
477
+ return refuse(L"could not make the job", NULL, GetLastError());
478
+ }
479
+
480
+ HANDLE std[3] = {GetStdHandle(STD_INPUT_HANDLE), GetStdHandle(STD_OUTPUT_HANDLE), GetStdHandle(STD_ERROR_HANDLE)};
481
+ HANDLE inherit[3];
482
+ DWORD inherited = stdio_handles(std, inherit);
483
+
484
+ SIZE_T attributes_size = 0;
485
+ InitializeProcThreadAttributeList(NULL, 2, 0, &attributes_size);
486
+ LPPROC_THREAD_ATTRIBUTE_LIST attributes = HeapAlloc(GetProcessHeap(), 0, attributes_size);
487
+ SECURITY_CAPABILITIES security = {container_sid, count ? caps : NULL, count, 0};
488
+ if (
489
+ !attributes ||
490
+ !InitializeProcThreadAttributeList(attributes, 2, 0, &attributes_size) ||
491
+ !UpdateProcThreadAttribute(attributes, 0, PROC_THREAD_ATTRIBUTE_SECURITY_CAPABILITIES, &security, sizeof(security), NULL, NULL) ||
492
+ (inherited && !UpdateProcThreadAttribute(attributes, 0, PROC_THREAD_ATTRIBUTE_HANDLE_LIST, inherit, inherited * sizeof(HANDLE), NULL, NULL))
493
+ ) {
494
+ return refuse(L"could not set the container attributes", NULL, GetLastError());
495
+ }
496
+
497
+ STARTUPINFOEXW startup = {0};
498
+ startup.StartupInfo.cb = sizeof(startup);
499
+ startup.StartupInfo.dwFlags = STARTF_USESTDHANDLES;
500
+ startup.StartupInfo.hStdInput = std[0];
501
+ startup.StartupInfo.hStdOutput = std[1];
502
+ startup.StartupInfo.hStdError = std[2];
503
+ startup.lpAttributeList = attributes;
504
+
505
+ PROCESS_INFORMATION child = {0};
506
+ DWORD flags = EXTENDED_STARTUPINFO_PRESENT | CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT;
507
+ if (!CreateProcessW(comspec, command, NULL, NULL, inherited > 0, flags, NULL, cwd, &startup.StartupInfo, &child)) {
508
+ return refuse(L"could not start the line in", cwd, GetLastError());
509
+ }
510
+
511
+ // Assigned while suspended, so nothing it starts escapes the job
512
+ if (!AssignProcessToJobObject(job, child.hProcess)) {
513
+ DWORD error = GetLastError();
514
+ TerminateProcess(child.hProcess, REFUSED);
515
+ return refuse(L"could not put the line in its job", NULL, error);
516
+ }
517
+
518
+ ResumeThread(child.hThread);
519
+ WaitForSingleObject(child.hProcess, INFINITE);
520
+
521
+ DWORD code = 1;
522
+ GetExitCodeProcess(child.hProcess, &code);
523
+
524
+ return (int) code;
525
+ }
526
+
527
+ int
528
+ wmain(int argc, wchar_t **argv) {
529
+ static request_t req;
530
+ if (!parse(argc, argv, &req)) {
531
+ return refuse(L"usage: --probe | --prepare [--deny <root>] [--pin <folder>] [--write <cap> <root>] [--read <cap> <root>] | [--cap <cap>] [--net] [--cwd <dir>] -- <line>", NULL, ERROR_INVALID_PARAMETER);
532
+ }
533
+
534
+ PSID container_sid = NULL;
535
+ HRESULT hr = container(&container_sid);
536
+ if (FAILED(hr)) return refuse(L"could not make the AppContainer profile", PROFILE, (DWORD) hr);
537
+ if (req.prepare) return prepare(&req, container_sid);
538
+
539
+ static wchar_t temp[MAX_PATH * 2];
540
+ int failed = app_data();
541
+ if (!failed) failed = temp_dir(container_sid, temp);
542
+ if (failed) return failed;
543
+
544
+ if (req.probe) return run(container_sid, NULL, 0, temp, L"exit 0");
545
+
546
+ static SID_AND_ATTRIBUTES caps[2 * MAX_ROOTS + NETWORK_CAPABILITIES];
547
+ static BYTE network_sids[NETWORK_CAPABILITIES][SECURITY_MAX_SID_SIZE];
548
+ DWORD count = 0;
549
+ failed = capabilities(&req, caps, &count);
550
+ if (!failed && req.network) failed = network(caps, &count, network_sids);
551
+ if (failed) return failed;
552
+
553
+ return run(container_sid, caps, count, req.cwd ? req.cwd : temp, req.line);
554
+ }
@@ -0,0 +1,53 @@
1
+ import type { HarnessPlugin, PluginContext, PluginSetup } from '../../lib/plugins/index.ts';
2
+ import type { ExecShell } from '../../lib/contract/exec.ts';
3
+ import type { PolicyEnforcement } from '../../lib/contract/index.ts';
4
+ export interface AppContainerOptions {
5
+ readonly helper?: string;
6
+ }
7
+ export interface HelperRun {
8
+ readonly write: readonly string[];
9
+ readonly read: readonly string[];
10
+ readonly deny: readonly string[];
11
+ readonly network: boolean;
12
+ readonly cwd?: string;
13
+ }
14
+ export declare class AppContainerSandbox implements HarnessPlugin {
15
+ readonly name = "sandbox-windows";
16
+ readonly api = 1;
17
+ readonly addons: {
18
+ 'bare-subprocess': () => Promise<{
19
+ constants: Record<string, number>;
20
+ errors: typeof import("bare-subprocess").errors;
21
+ Subprocess: typeof import("bare-subprocess").Subprocess;
22
+ spawn(file: string, args?: string[] | null, opts?: import("bare-subprocess").SpawnOptions): import("bare-subprocess").Subprocess;
23
+ spawn(file: string, opts?: import("bare-subprocess").SpawnOptions): import("bare-subprocess").Subprocess;
24
+ spawnSync(file: string, args?: string[] | null, opts?: import("bare-subprocess").SpawnSyncOptions): import("bare-subprocess").SpawnSyncResult;
25
+ spawnSync(file: string, opts?: import("bare-subprocess").SpawnSyncOptions): import("bare-subprocess").SpawnSyncResult;
26
+ default: typeof import("bare-subprocess");
27
+ }>;
28
+ };
29
+ readonly enforces: PolicyEnforcement;
30
+ readonly shell: ExecShell;
31
+ private readonly _helper;
32
+ private _denied;
33
+ private readonly _prepared;
34
+ private _preparing;
35
+ constructor({ helper }?: AppContainerOptions);
36
+ validate(): string | null;
37
+ setup(ctx: PluginContext): Promise<PluginSetup>;
38
+ static argv(run: HelperRun, line: string): string[];
39
+ static steps({ write, read, deny }: HelperRun): string[][];
40
+ static capability(kind: 'w' | 'r', root: string): string;
41
+ private _admit;
42
+ private _spawn;
43
+ private _spawnHelper;
44
+ private _prepare;
45
+ private _enqueue;
46
+ private static _prepareWith;
47
+ private static _within;
48
+ private static _confined;
49
+ private static _env;
50
+ private static _shipped;
51
+ static prebuilt(arch: string): string;
52
+ private _probe;
53
+ }