@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,6 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import process from 'process';
4
+ import { HarnessError } from '../../errors.js';
4
5
  import { SPILL_DIR } from '../../spill.js';
5
6
  export const defaultRealpath = (p) => fs.promises.realpath(p);
6
7
  export const NO_DIRS_GRANTED = 'no directories are granted';
@@ -11,10 +12,9 @@ function rootLabel(root) {
11
12
  function outside(roots) {
12
13
  return { error: `path must be inside one of: ${roots.map(rootLabel).join(', ')}` };
13
14
  }
14
- export const NO_STORAGE_ROOT = 'cannot fence the app storage root: the SDK home is unknown';
15
15
  export function deniedRootsFor(sdkHome) {
16
16
  if (!sdkHome)
17
- throw new Error(NO_STORAGE_ROOT);
17
+ throw new HarnessError('NO_STORAGE_ROOT');
18
18
  return [path.dirname(sdkHome), SPILL_DIR];
19
19
  }
20
20
  export const PROTECTED_PATH_ERROR = 'path is inside a protected app directory';
@@ -34,6 +34,9 @@ export async function canonicalDenyRoots(deniedRoots, realpath) {
34
34
  }
35
35
  }));
36
36
  }
37
+ export function callDenyRoots(deniedRoots, policy, realpath) {
38
+ return canonicalDenyRoots([...(deniedRoots ?? []), ...(policy?.files.deny ?? [])], realpath);
39
+ }
37
40
  export function isDeniedPath(hostPath, canonicalDenyRoots) {
38
41
  return canonicalDenyRoots.some((root) => contained(hostPath, root, { ignoreCase: true }));
39
42
  }
@@ -0,0 +1,41 @@
1
+ import { type Drive } from './drive.ts';
2
+ import type { DriveResponse, DriveSearchRequest } from './remote-protocol.ts';
3
+ import { type DriveRoot } from './scope.ts';
4
+ import { type WalkSummary } from './walk.ts';
5
+ export declare const MAX_GREP_MATCHES = 1000;
6
+ export interface SearchHit {
7
+ file: string;
8
+ line: number;
9
+ text: string;
10
+ }
11
+ export interface SearchFile {
12
+ path: string;
13
+ key: string;
14
+ }
15
+ export interface SearchOptions {
16
+ regex?: boolean;
17
+ caseSensitive?: boolean;
18
+ concurrency?: number;
19
+ }
20
+ export interface SearchResult {
21
+ hits: SearchHit[];
22
+ capped: boolean;
23
+ cut: boolean;
24
+ }
25
+ export interface FolderSearchOptions {
26
+ maxMatches: number;
27
+ includeIgnored?: boolean;
28
+ maxEntries?: number;
29
+ maxMs?: number;
30
+ deny?: readonly string[];
31
+ include?: ((name: string) => boolean) | null;
32
+ }
33
+ export interface FolderSearchResult extends SearchResult, WalkSummary {
34
+ }
35
+ export declare class DriveSearch {
36
+ #private;
37
+ constructor(queries: readonly string[], { regex, caseSensitive, concurrency }?: SearchOptions);
38
+ static answer(drive: Drive, request: DriveSearchRequest): Promise<DriveResponse>;
39
+ searchFolder(root: DriveRoot, folder: string, { maxMatches, includeIgnored, maxEntries, maxMs, deny, include }: FolderSearchOptions): Promise<FolderSearchResult>;
40
+ search(drive: Drive, files: AsyncIterable<SearchFile>, maxMatches: number): Promise<SearchResult>;
41
+ }
@@ -0,0 +1,382 @@
1
+ import b4a from 'b4a';
2
+ import { errorMessage } from '../../guards.js';
3
+ import { HarnessLog } from '../../log.js';
4
+ import { isDriveReadTruncated } from './drive.js';
5
+ import { isDeniedPath } from './scope.js';
6
+ import { MAX_WALK_ENTRIES, MAX_WALK_MS, streamFiles } from './walk.js';
7
+ export const MAX_GREP_MATCHES = 1000;
8
+ const NEWLINE = 0x0a;
9
+ const LINE_END = b4a.from([NEWLINE]);
10
+ const MAX_LINE_CHARS = 500;
11
+ const BINARY_PROBE_BYTES = 1024;
12
+ const DEFAULT_CONCURRENCY = 8;
13
+ const MAX_UNCOUNTED_BYTES = 1024 * 1024;
14
+ const MAX_LINE_BYTES = 1024 * 1024;
15
+ const UNSEARCHED = -2;
16
+ const LOOKAROUND = /\(\?<?[=!]/;
17
+ const BACKREFERENCE = /\\[1-9]|\\k</;
18
+ const CROSSES_LINES = /\[\^|\\(?:[sWDn0]|12|x0[aA]|u000[aA]|c[jJ])|\\(?:x[\da-fA-F]{2}|u[\da-fA-F]{4}|c[a-zA-Z]|[^dDsSwW])-|[\0-\n]|\(\?[a-zA-Z-]/;
19
+ function cursors(keys) {
20
+ return keys.map((key) => ({ key, at: UNSEARCHED }));
21
+ }
22
+ function nearest(all, from, find) {
23
+ let best = -1;
24
+ for (const cursor of all) {
25
+ if (cursor.at === UNSEARCHED || (cursor.at >= 0 && cursor.at < from)) {
26
+ cursor.at = find(cursor.key, from);
27
+ }
28
+ if (cursor.at >= 0 && (best === -1 || cursor.at < best)) {
29
+ best = cursor.at;
30
+ }
31
+ }
32
+ return best;
33
+ }
34
+ function countNewlines(bytes, start, end) {
35
+ let count = 0;
36
+ for (let i = start; i < end; i++) {
37
+ if (bytes[i] === NEWLINE) {
38
+ count++;
39
+ }
40
+ }
41
+ return count;
42
+ }
43
+ class ByteHaystack {
44
+ #bytes;
45
+ #needles;
46
+ constructor(bytes, needles) {
47
+ this.#bytes = bytes;
48
+ this.#needles = cursors(needles);
49
+ }
50
+ get length() {
51
+ return this.#bytes.length;
52
+ }
53
+ next(from) {
54
+ return nearest(this.#needles, from, (needle, at) => b4a.indexOf(this.#bytes, needle, at));
55
+ }
56
+ newlineAt(from) {
57
+ return b4a.indexOf(this.#bytes, NEWLINE, from);
58
+ }
59
+ newlineBefore(index) {
60
+ return b4a.lastIndexOf(this.#bytes, NEWLINE, index - 1);
61
+ }
62
+ slice(start, end) {
63
+ return b4a.toString(this.#bytes, 'utf8', start, end);
64
+ }
65
+ newlines(start, end) {
66
+ return countNewlines(this.#bytes, start, end);
67
+ }
68
+ }
69
+ class TextHaystack {
70
+ #text;
71
+ #finders;
72
+ constructor(text, finders) {
73
+ this.#text = text;
74
+ this.#finders = finders === null ? null : cursors(finders);
75
+ }
76
+ get length() {
77
+ return this.#text.length;
78
+ }
79
+ next(from) {
80
+ const at = this.#finders === null
81
+ ? from
82
+ : nearest(this.#finders, from, (finder, start) => {
83
+ finder.lastIndex = start;
84
+ return finder.exec(this.#text)?.index ?? -1;
85
+ });
86
+ return at < this.#text.length ? at : -1;
87
+ }
88
+ newlineAt(from) {
89
+ return this.#text.indexOf('\n', from);
90
+ }
91
+ newlineBefore(index) {
92
+ return this.#text.lastIndexOf('\n', index - 1);
93
+ }
94
+ slice(start, end) {
95
+ return this.#text.slice(start, end);
96
+ }
97
+ newlines(start, end) {
98
+ let count = 0;
99
+ let at = this.#text.indexOf('\n', start);
100
+ while (at !== -1 && at < end) {
101
+ count++;
102
+ at = this.#text.indexOf('\n', at + 1);
103
+ }
104
+ return count;
105
+ }
106
+ }
107
+ class LineCounter {
108
+ line = 1;
109
+ #pending = [];
110
+ #pendingBytes = 0;
111
+ defer(block) {
112
+ this.#pending.push(block);
113
+ this.#pendingBytes += block.length;
114
+ if (this.#pendingBytes > MAX_UNCOUNTED_BYTES) {
115
+ this.flush();
116
+ }
117
+ }
118
+ flush() {
119
+ for (const block of this.#pending) {
120
+ this.line += countNewlines(block, 0, block.length);
121
+ }
122
+ this.#pending.length = 0;
123
+ this.#pendingBytes = 0;
124
+ }
125
+ }
126
+ class OrderedCommits {
127
+ hits = [];
128
+ cut = false;
129
+ #maxMatches;
130
+ #pending = [];
131
+ constructor(maxMatches) {
132
+ this.#maxMatches = maxMatches;
133
+ }
134
+ get room() {
135
+ return this.#maxMatches - this.hits.length;
136
+ }
137
+ add(file, read) {
138
+ const entry = { file, read, scan: null };
139
+ void read.then((scan) => {
140
+ entry.scan = scan;
141
+ });
142
+ this.#pending.push(entry);
143
+ }
144
+ async settle(keep) {
145
+ for (let head = this.#pending[0]; head !== undefined; head = this.#pending[0]) {
146
+ if (head.scan === null && this.#pending.length <= keep) {
147
+ return false;
148
+ }
149
+ const scan = head.scan ?? (await head.read);
150
+ this.#pending.shift();
151
+ if (this.#commit(head.file, scan)) {
152
+ return true;
153
+ }
154
+ }
155
+ return false;
156
+ }
157
+ result(capped) {
158
+ return { hits: this.hits, capped, cut: this.cut };
159
+ }
160
+ #commit(file, scan) {
161
+ const room = this.room;
162
+ if (scan.hits.length >= room) {
163
+ this.hits.push(...scan.hits.slice(0, room));
164
+ return true;
165
+ }
166
+ if (scan.end === 'unreadable') {
167
+ HarnessLog.info('warn: grep skipped a file', {
168
+ file: file.path,
169
+ err: errorMessage(scan.error)
170
+ });
171
+ }
172
+ else if (scan.end !== 'binary') {
173
+ this.cut ||= scan.end === 'cut';
174
+ this.hits.push(...scan.hits);
175
+ }
176
+ return false;
177
+ }
178
+ }
179
+ function escapeLiteral(query) {
180
+ return query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
181
+ }
182
+ function finders(sources, flags) {
183
+ if (!sources.some((source) => BACKREFERENCE.test(source))) {
184
+ try {
185
+ return [new RegExp(sources.map((source) => `(?:${source})`).join('|'), flags)];
186
+ }
187
+ catch {
188
+ }
189
+ }
190
+ return sources.map((source) => new RegExp(source, flags));
191
+ }
192
+ function hasNul(head) {
193
+ return b4a.indexOf(head.subarray(0, BINARY_PROBE_BYTES), 0) !== -1;
194
+ }
195
+ async function* gated(files, gate) {
196
+ for await (const file of files) {
197
+ if (Date.now() > gate.deadline) {
198
+ gate.late = true;
199
+ return;
200
+ }
201
+ const name = file.key.slice(file.key.lastIndexOf('/') + 1);
202
+ if (!isDeniedPath(file.path, gate.deny) && (gate.include === null || gate.include(name))) {
203
+ yield file;
204
+ }
205
+ }
206
+ }
207
+ export class DriveSearch {
208
+ #concurrency;
209
+ #tests;
210
+ #needles;
211
+ #finders;
212
+ constructor(queries, { regex = false, caseSensitive = false, concurrency = DEFAULT_CONCURRENCY } = {}) {
213
+ this.#concurrency = concurrency;
214
+ const bytes = !regex && caseSensitive && !queries.some((query) => query === '' || query.includes('\uFFFD'));
215
+ const flags = caseSensitive ? '' : 'i';
216
+ const sources = regex ? queries : queries.map(escapeLiteral);
217
+ const lines = bytes ? [] : sources.map((source) => new RegExp(source, flags));
218
+ this.#tests = bytes
219
+ ? queries.map((query) => (line) => line.includes(query))
220
+ : lines.map((rx) => (line) => rx.test(line));
221
+ this.#needles = bytes ? queries.map((query) => b4a.from(query)) : null;
222
+ this.#finders =
223
+ bytes ||
224
+ (regex && queries.some((query) => LOOKAROUND.test(query) || CROSSES_LINES.test(query)))
225
+ ? null
226
+ : finders(sources, `${flags}g${regex ? 'm' : ''}`);
227
+ }
228
+ static async answer(drive, request) {
229
+ const search = new DriveSearch(request.queries, {
230
+ regex: request.regex,
231
+ caseSensitive: request.caseSensitive
232
+ });
233
+ const root = {
234
+ kind: 'hyper',
235
+ key: request.driveKey,
236
+ writable: false,
237
+ prefix: '/',
238
+ drive
239
+ };
240
+ return search.searchFolder(root, request.folder, {
241
+ includeIgnored: request.includeIgnored,
242
+ maxMatches: Math.min(request.maxMatches, MAX_GREP_MATCHES),
243
+ maxEntries: Math.min(request.maxEntries, MAX_WALK_ENTRIES),
244
+ maxMs: Math.min(request.maxMs, MAX_WALK_MS)
245
+ });
246
+ }
247
+ async searchFolder(root, folder, { maxMatches, includeIgnored, maxEntries, maxMs, deny = [], include = null }) {
248
+ const walk = streamFiles(root, folder, { includeIgnored, maxEntries, maxMs });
249
+ const gate = {
250
+ deny,
251
+ include,
252
+ deadline: maxMs === undefined ? Infinity : Date.now() + maxMs,
253
+ late: false
254
+ };
255
+ const found = await this.search(root.drive, gated(walk.files, gate), maxMatches);
256
+ const listed = await walk.result;
257
+ return {
258
+ ...found,
259
+ truncated: listed.truncated || gate.late,
260
+ skippedLinks: listed.skippedLinks
261
+ };
262
+ }
263
+ async search(drive, files, maxMatches) {
264
+ const commits = new OrderedCommits(maxMatches);
265
+ const stop = { stopped: false };
266
+ try {
267
+ for await (const file of files) {
268
+ if (await commits.settle(this.#concurrency - 1)) {
269
+ return commits.result(true);
270
+ }
271
+ commits.add(file, this.#scan(drive, { file, room: commits.room, stop }));
272
+ }
273
+ return commits.result(await commits.settle(0));
274
+ }
275
+ finally {
276
+ stop.stopped = true;
277
+ }
278
+ }
279
+ async #scan(drive, { file, room, stop }) {
280
+ const state = {
281
+ file,
282
+ room,
283
+ hits: [],
284
+ lines: new LineCounter(),
285
+ probed: false,
286
+ carry: null,
287
+ skipping: false
288
+ };
289
+ try {
290
+ for await (const chunk of drive.createReadStream(file.key)) {
291
+ const end = stop.stopped ? 'complete' : this.#take(chunk, state);
292
+ if (end !== null) {
293
+ return { hits: state.hits, end };
294
+ }
295
+ }
296
+ return { hits: state.hits, end: this.#last(state) };
297
+ }
298
+ catch (error) {
299
+ if (!state.probed && state.carry !== null && !hasNul(state.carry)) {
300
+ this.#wholeLines(state.carry, state);
301
+ }
302
+ return { hits: state.hits, end: isDriveReadTruncated(error) ? 'cut' : 'unreadable', error };
303
+ }
304
+ }
305
+ #take(chunk, state) {
306
+ if (state.skipping) {
307
+ const newline = b4a.indexOf(chunk, NEWLINE);
308
+ if (newline === -1) {
309
+ return null;
310
+ }
311
+ state.skipping = false;
312
+ chunk = chunk.subarray(newline + 1);
313
+ }
314
+ const buffer = state.carry === null ? chunk : b4a.concat([state.carry, chunk]);
315
+ if (!state.probed && buffer.length < BINARY_PROBE_BYTES) {
316
+ state.carry = buffer;
317
+ return null;
318
+ }
319
+ if (!state.probed && hasNul(buffer)) {
320
+ return 'binary';
321
+ }
322
+ state.probed = true;
323
+ return this.#wholeLines(buffer, state) || this.#longLine(state) ? 'complete' : null;
324
+ }
325
+ #longLine(state) {
326
+ const { carry } = state;
327
+ if (carry === null || carry.length <= MAX_LINE_BYTES) {
328
+ return false;
329
+ }
330
+ state.carry = null;
331
+ state.skipping = true;
332
+ return this.#block(b4a.concat([carry.subarray(0, MAX_LINE_BYTES), LINE_END]), state);
333
+ }
334
+ #last(state) {
335
+ const { carry } = state;
336
+ if (carry === null) {
337
+ return 'complete';
338
+ }
339
+ if (!state.probed && hasNul(carry)) {
340
+ return 'binary';
341
+ }
342
+ this.#block(carry[carry.length - 1] === NEWLINE ? carry : b4a.concat([carry, LINE_END]), state);
343
+ return 'complete';
344
+ }
345
+ #wholeLines(buffer, state) {
346
+ const last = b4a.lastIndexOf(buffer, NEWLINE);
347
+ state.carry = last + 1 === buffer.length ? null : buffer.subarray(last + 1);
348
+ return last !== -1 && this.#block(buffer.subarray(0, last + 1), state);
349
+ }
350
+ #block(block, { file, hits, lines, room }) {
351
+ const hay = this.#needles === null
352
+ ? new TextHaystack(b4a.toString(block, 'utf8'), this.#finders)
353
+ : new ByteHaystack(block, this.#needles);
354
+ let counted = -1;
355
+ for (let at = hay.next(0); at !== -1; at = hay.next(counted)) {
356
+ const start = at === 0 ? 0 : hay.newlineBefore(at) + 1;
357
+ const newline = hay.newlineAt(at);
358
+ const end = newline === -1 ? hay.length : newline;
359
+ if (counted === -1) {
360
+ lines.flush();
361
+ counted = 0;
362
+ }
363
+ lines.line += hay.newlines(counted, start);
364
+ const text = hay.slice(start, end);
365
+ if (this.#tests.some((test) => test(text))) {
366
+ hits.push({ file: file.path, line: lines.line, text: text.slice(0, MAX_LINE_CHARS) });
367
+ }
368
+ if (hits.length >= room) {
369
+ return true;
370
+ }
371
+ lines.line++;
372
+ counted = end + 1;
373
+ }
374
+ if (counted === -1) {
375
+ lines.defer(block);
376
+ }
377
+ else if (counted < hay.length) {
378
+ lines.line += hay.newlines(counted, hay.length);
379
+ }
380
+ return false;
381
+ }
382
+ }
@@ -1,7 +1,4 @@
1
- import type { ToolDefinition } from '../contract/index.ts';
2
- import { type DriveRoot, type FsToolError, type FsToolOptions, type ResolveKeyOptions } from './fs/scope.ts';
3
- export declare const DEFAULT_GLOB_MATCHES = 100;
4
- export declare const MAX_GLOB_MATCHES = 1000;
1
+ import { type DriveRoot, type FsToolError, type ResolveKeyOptions } from './scope.ts';
5
2
  export interface SearchTarget {
6
3
  root: DriveRoot;
7
4
  folder: string;
@@ -11,4 +8,3 @@ export interface ResolvedTargets {
11
8
  }
12
9
  export declare function searchTargets(dir: unknown, roots: readonly DriveRoot[], { realpath, deny }: ResolveKeyOptions): Promise<ResolvedTargets | FsToolError>;
13
10
  export declare function relativeKey(key: string, folder: string): string;
14
- export declare function createFileGlobTool({ realpath, deniedRoots }?: FsToolOptions): ToolDefinition;
@@ -0,0 +1,32 @@
1
+ import { NO_DIRS_GRANTED, resolveKey } from './scope.js';
2
+ export async function searchTargets(dir, roots, { realpath, deny }) {
3
+ if (typeof dir === 'string' && dir.trim()) {
4
+ const resolved = await resolveKey(dir, roots, { realpath, deny });
5
+ if ('error' in resolved) {
6
+ return resolved;
7
+ }
8
+ if (resolved.root.kind === 'local') {
9
+ if (!resolved.exists) {
10
+ return { error: `no such file: ${dir}` };
11
+ }
12
+ }
13
+ else {
14
+ let hasEntry = false;
15
+ for await (const _entry of resolved.root.drive.list(resolved.key)) {
16
+ hasEntry = true;
17
+ break;
18
+ }
19
+ if (!hasEntry && (await resolved.root.drive.entry(resolved.key)) === null) {
20
+ return { error: `no such file: ${dir}` };
21
+ }
22
+ }
23
+ return { targets: [{ root: resolved.root, folder: resolved.key }] };
24
+ }
25
+ if (roots.length === 0) {
26
+ return { error: NO_DIRS_GRANTED };
27
+ }
28
+ return { targets: roots.map((root) => ({ root, folder: '/' })) };
29
+ }
30
+ export function relativeKey(key, folder) {
31
+ return folder === '/' ? key.slice(1) : key.slice(folder.length + 1);
32
+ }
@@ -0,0 +1,27 @@
1
+ import type { CompiledPolicy } from '../../contract/policy.ts';
2
+ import { type DriveRoot, type FsToolError, type Realpath, type ResolvedKey } from './scope.ts';
3
+ export interface Grants {
4
+ readonly fsRoots?: readonly DriveRoot[] | undefined;
5
+ readonly fsWriteRoots?: readonly DriveRoot[] | undefined;
6
+ readonly policy?: CompiledPolicy | undefined;
7
+ }
8
+ export declare function anchorOf(grants: Grants | undefined): DriveRoot | undefined;
9
+ export declare function rootedPath(p: string, anchor: DriveRoot | undefined): string;
10
+ export declare function shownPath(full: string, anchor: DriveRoot | undefined): string;
11
+ export interface RootedScope {
12
+ readonly grants: Grants | undefined;
13
+ readonly write: boolean;
14
+ readonly realpath: Realpath;
15
+ readonly deniedRoots?: readonly string[] | undefined;
16
+ }
17
+ export declare function resolveRooted(p: string, { grants, write, realpath, deniedRoots }: RootedScope): Promise<ResolvedKey | FsToolError>;
18
+ export declare function rootedArgs(args: Record<string, unknown>, grants: Grants | undefined, keys: readonly string[]): string[] | null;
19
+ export declare function stringArg(args: Record<string, unknown>, key: string): string | null;
20
+ export declare function positiveInt(value: unknown): number | undefined;
21
+ export declare function existsNow(p: string | null, grants: Grants | undefined): boolean;
22
+ export interface LabelPaths {
23
+ readonly grants: Grants | undefined;
24
+ readonly paths: readonly string[];
25
+ }
26
+ export declare function rootedLabel(verb: string, { grants, paths }: LabelPaths): string;
27
+ export declare function localPathOf(resolved: ResolvedKey): string | null;
@@ -0,0 +1,70 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { callDenyRoots, hostPath, resolveKey } from './scope.js';
4
+ const HYPER_PREFIX = 'hyper://';
5
+ export function anchorOf(grants) {
6
+ return grants?.fsRoots?.[0] ?? grants?.fsWriteRoots?.[0];
7
+ }
8
+ function baseOf(root) {
9
+ return root.kind === 'local' ? root.root : `${HYPER_PREFIX}${root.key}`;
10
+ }
11
+ export function rootedPath(p, anchor) {
12
+ if (!anchor || p.startsWith(HYPER_PREFIX) || path.isAbsolute(p) || p.startsWith('~')) {
13
+ return p;
14
+ }
15
+ if (anchor.kind === 'local') {
16
+ return path.join(anchor.root, p);
17
+ }
18
+ const prefix = anchor.prefix === '/' ? '' : anchor.prefix;
19
+ return `${HYPER_PREFIX}${anchor.key}${prefix}/${p.replace(/^\.?\//, '')}`;
20
+ }
21
+ export function shownPath(full, anchor) {
22
+ if (!anchor) {
23
+ return full;
24
+ }
25
+ const base = baseOf(anchor);
26
+ if (full === base) {
27
+ return '.';
28
+ }
29
+ return full.startsWith(base + '/') ? full.slice(base.length + 1) : full;
30
+ }
31
+ export async function resolveRooted(p, { grants, write, realpath, deniedRoots }) {
32
+ const roots = (write ? grants?.fsWriteRoots : grants?.fsRoots) ?? [];
33
+ const deny = await callDenyRoots(deniedRoots, grants?.policy, realpath);
34
+ return resolveKey(rootedPath(p, anchorOf(grants)), roots, { realpath, deny });
35
+ }
36
+ export function rootedArgs(args, grants, keys) {
37
+ const anchor = anchorOf(grants);
38
+ const paths = [];
39
+ for (const key of keys) {
40
+ const value = stringArg(args, key);
41
+ if (value === null) {
42
+ return null;
43
+ }
44
+ paths.push(rootedPath(value, anchor));
45
+ }
46
+ return paths;
47
+ }
48
+ export function stringArg(args, key) {
49
+ const value = args[key];
50
+ return typeof value === 'string' && value.trim() ? value : null;
51
+ }
52
+ export function positiveInt(value) {
53
+ const n = Number(value);
54
+ return value === undefined || value === null || !Number.isInteger(n) || n < 1 ? undefined : n;
55
+ }
56
+ export function existsNow(p, grants) {
57
+ const anchor = anchorOf(grants);
58
+ if (!p || !anchor || anchor.kind !== 'local') {
59
+ return true;
60
+ }
61
+ const target = rootedPath(p, anchor);
62
+ return !path.isAbsolute(target) || fs.existsSync(target);
63
+ }
64
+ export function rootedLabel(verb, { grants, paths }) {
65
+ const anchor = anchorOf(grants);
66
+ return `${verb} ${paths.map((p) => rootedPath(p, anchor)).join(' → ')}`;
67
+ }
68
+ export function localPathOf(resolved) {
69
+ return resolved.root.kind === 'local' ? hostPath(resolved.root, resolved.key) : null;
70
+ }
@@ -7,9 +7,21 @@ export interface WalkedFile {
7
7
  key: string;
8
8
  byteLength: number;
9
9
  }
10
- export interface WalkResult {
11
- files: WalkedFile[];
10
+ export interface WalkSummary {
12
11
  truncated: boolean;
13
12
  skippedLinks: number;
14
13
  }
15
- export declare function walkFiles(root: DriveRoot, folder?: string): Promise<WalkResult>;
14
+ export interface WalkResult extends WalkSummary {
15
+ files: WalkedFile[];
16
+ }
17
+ export interface WalkStream {
18
+ files: AsyncIterable<WalkedFile>;
19
+ result: Promise<WalkSummary>;
20
+ }
21
+ export interface WalkOptions {
22
+ includeIgnored?: boolean;
23
+ maxEntries?: number;
24
+ maxMs?: number;
25
+ }
26
+ export declare function walkFiles(root: DriveRoot, folder?: string, opts?: WalkOptions): Promise<WalkResult>;
27
+ export declare function streamFiles(root: DriveRoot, folder?: string, opts?: WalkOptions): WalkStream;