@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,41 +1,135 @@
1
+ import b4a from 'b4a';
1
2
  import { errorMessage } from '../../guards.js';
2
- import { hlog } from '../../log.js';
3
+ import { HarnessLog } from '../../log.js';
4
+ import { pushQueue } from '../../queue.js';
5
+ import { IgnoreRules } from './ignore.js';
3
6
  import { displayPath } from './scope.js';
4
- export const WALK_SKIP_DIRS = new Set(['.git', 'node_modules']);
7
+ export const WALK_SKIP_DIRS = new Set(['.git', 'node_modules', '.trash']);
8
+ const HIDDEN_DIRS = new Set(['.hg', '.svn', '.venv', '.cache', '.next']);
9
+ const IGNORE_FILES = ['.gitignore', '.ignore'];
5
10
  export const MAX_WALK_ENTRIES = 10_000;
6
11
  export const MAX_WALK_MS = 30_000;
7
- export async function walkFiles(root, folder = '/') {
8
- const files = [];
9
- let visited = 0;
10
- let skippedLinks = 0;
11
- const deadline = Date.now() + MAX_WALK_MS;
12
- try {
13
- for await (const entry of root.drive.list(folder, { skip: WALK_SKIP_DIRS })) {
14
- if (++visited > MAX_WALK_ENTRIES) {
15
- return { files, truncated: true, skippedLinks };
12
+ function childKey(dir, name) {
13
+ return dir === '/' ? `/${name}` : `${dir}/${name}`;
14
+ }
15
+ function isIgnoreFile(child, key) {
16
+ return !('dir' in child) && child.value.linkname === null && child.key === key;
17
+ }
18
+ class Walk {
19
+ skippedLinks = 0;
20
+ kept = 0;
21
+ #root;
22
+ #onFile;
23
+ #includeIgnored;
24
+ #maxEntries;
25
+ #deadline;
26
+ constructor(root, onFile, { includeIgnored = false, maxEntries = MAX_WALK_ENTRIES, maxMs = MAX_WALK_MS }) {
27
+ this.#root = root;
28
+ this.#onFile = onFile;
29
+ this.#includeIgnored = includeIgnored;
30
+ this.#maxEntries = maxEntries;
31
+ this.#deadline = Date.now() + maxMs;
32
+ }
33
+ async #withIgnoreFile(rules, key) {
34
+ const bytes = await this.#root.drive.get(key);
35
+ const dir = key.slice(0, key.lastIndexOf('/'));
36
+ return bytes === null ? rules : rules.add(dir.slice(1), b4a.toString(bytes, 'utf8'));
37
+ }
38
+ async rootRules(folder) {
39
+ let rules = new IgnoreRules();
40
+ if (this.#includeIgnored) {
41
+ return rules;
42
+ }
43
+ const parts = folder.split('/').filter(Boolean);
44
+ for (let depth = 0; depth < parts.length; depth++) {
45
+ const dir = '/' + parts.slice(0, depth).join('/');
46
+ for (const name of IGNORE_FILES) {
47
+ rules = await this.#withIgnoreFile(rules, childKey(dir, name));
16
48
  }
17
- if (Date.now() > deadline) {
18
- return { files, truncated: true, skippedLinks };
49
+ }
50
+ return rules;
51
+ }
52
+ async #list(dir) {
53
+ const children = [];
54
+ const listing = this.#root.drive.list(dir, { skip: WALK_SKIP_DIRS, recursive: false });
55
+ for await (const child of listing) {
56
+ if (Date.now() > this.#deadline)
57
+ return null;
58
+ children.push(child);
59
+ }
60
+ return children;
61
+ }
62
+ #keeps(child, rules) {
63
+ if (this.#includeIgnored)
64
+ return true;
65
+ const isDir = 'dir' in child;
66
+ const name = child.key.slice(child.key.lastIndexOf('/') + 1);
67
+ return !(isDir && HIDDEN_DIRS.has(name)) && !rules.ignored(child.key.slice(1), isDir);
68
+ }
69
+ async #rulesFor(dir, children, inherited) {
70
+ let rules = inherited;
71
+ for (const name of IGNORE_FILES) {
72
+ const key = childKey(dir, name);
73
+ if (!this.#includeIgnored && children.some((child) => isIgnoreFile(child, key))) {
74
+ rules = await this.#withIgnoreFile(rules, key);
19
75
  }
20
- if (entry.value.linkname !== null) {
21
- skippedLinks++;
76
+ }
77
+ return rules;
78
+ }
79
+ async visit(dir, inherited) {
80
+ const children = await this.#list(dir);
81
+ if (children === null) {
82
+ return false;
83
+ }
84
+ const rules = await this.#rulesFor(dir, children, inherited);
85
+ for (const child of children) {
86
+ if (!this.#keeps(child, rules))
22
87
  continue;
88
+ if (++this.kept > this.#maxEntries || Date.now() > this.#deadline) {
89
+ return false;
90
+ }
91
+ if ('dir' in child) {
92
+ if (!(await this.visit(child.key, rules))) {
93
+ return false;
94
+ }
95
+ }
96
+ else if (child.value.linkname !== null) {
97
+ this.skippedLinks++;
98
+ }
99
+ else {
100
+ this.#onFile({
101
+ path: displayPath(this.#root, child.key),
102
+ key: child.key,
103
+ byteLength: child.value.blob?.byteLength ?? 0
104
+ });
23
105
  }
24
- files.push({
25
- path: displayPath(root, entry.key),
26
- key: entry.key,
27
- byteLength: entry.value.blob?.byteLength ?? 0
28
- });
29
106
  }
107
+ return true;
108
+ }
109
+ }
110
+ async function run(walk, root, folder) {
111
+ try {
112
+ const complete = await walk.visit(folder, await walk.rootRules(folder));
113
+ return { truncated: !complete, skippedLinks: walk.skippedLinks };
30
114
  }
31
115
  catch (err) {
32
- hlog('warn: walk aborted mid-listing', {
116
+ HarnessLog.warn('warn: walk aborted mid-listing', {
33
117
  root: displayPath(root, '/'),
34
118
  folder,
35
- visited,
119
+ kept: walk.kept,
36
120
  err: errorMessage(err)
37
121
  });
38
- return { files, truncated: true, skippedLinks };
122
+ return { truncated: true, skippedLinks: walk.skippedLinks };
39
123
  }
40
- return { files, truncated: false, skippedLinks };
124
+ }
125
+ export async function walkFiles(root, folder = '/', opts = {}) {
126
+ const files = [];
127
+ const summary = await run(new Walk(root, (file) => files.push(file), opts), root, folder);
128
+ return { files, ...summary };
129
+ }
130
+ export function streamFiles(root, folder = '/', opts = {}) {
131
+ const queue = pushQueue();
132
+ const result = run(new Walk(root, (file) => void queue.push(file), opts), root, folder);
133
+ void result.then(() => queue.end());
134
+ return { files: queue, result };
41
135
  }
@@ -8,6 +8,7 @@ import { AbortedError } from '../helpers/race-abort.js';
8
8
  import { applyQuery, buildHeaders, contentTypeOf, encodeBody, isRedirectStatus, parseJsonBody, parseObjectArg, TIMEOUT_MS } from './http-request/request.js';
9
9
  import { parseAuth, resolveBearerHeader, resolveRedirectBearerHeader } from './skills/auth-resolver.js';
10
10
  import { recordCredentialHealth } from './skills/credential-health.js';
11
+ import { Policy } from '../policy/index.js';
11
12
  import { resolveOutboundUrl } from './url-guard.js';
12
13
  const MAX_REDIRECTS = 5;
13
14
  export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credentialStore, credentialAllowList, resolveHost = lookupHost } = {}) {
@@ -99,10 +100,15 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
99
100
  return { error: auth.error };
100
101
  }
101
102
  const allowList = credentialAllowList?.(ctx);
103
+ const hosts = Policy.hostsOf(ctx?.policy);
102
104
  const controller = new AbortController();
103
105
  const timeout = setTimeout(() => controller.abort(undefined), TIMEOUT_MS);
104
106
  try {
105
- const initialCheck = await resolveOutboundUrl(url, resolveHost, controller.signal);
107
+ const initialCheck = await resolveOutboundUrl(url, {
108
+ resolveHost,
109
+ signal: controller.signal,
110
+ hosts
111
+ });
106
112
  if (initialCheck.blocked) {
107
113
  return { error: initialCheck.blocked };
108
114
  }
@@ -160,7 +166,11 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
160
166
  if (redirects >= MAX_REDIRECTS) {
161
167
  return { error: 'too many redirects' };
162
168
  }
163
- const hopCheck = await resolveOutboundUrl(nextUrl, resolveHost, controller.signal);
169
+ const hopCheck = await resolveOutboundUrl(nextUrl, {
170
+ resolveHost,
171
+ signal: controller.signal,
172
+ hosts
173
+ });
164
174
  if (hopCheck.blocked) {
165
175
  return { error: hopCheck.blocked };
166
176
  }
@@ -1,13 +1,9 @@
1
- import { createCreateDocumentsTool } from './create-documents.js';
2
- import { createEditDocumentsTool } from './edit-documents.js';
3
- import { createFileGlobTool } from './file-glob.js';
1
+ import { createFileTools } from './files/index.js';
4
2
  import { deniedRootsFor } from './fs/scope.js';
5
- import { createGrepTool } from './grep.js';
6
3
  import { createHttpRequestTool } from './http-request.js';
7
4
  import { createOfficeTools } from './office.js';
8
5
  import { compileOperationTools } from './operations/compile.js';
9
6
  import { createPdfTool } from './pdf.js';
10
- import { createReadFilesTool } from './read-files.js';
11
7
  import { createSkillTool } from './skill.js';
12
8
  import { stageInputs } from './attachments/staging.js';
13
9
  import { ensureBundledSkillsDir } from './skills/bundled-dir.js';
@@ -27,11 +23,7 @@ export class Tools {
27
23
  const tools = [
28
24
  httpRequestTool,
29
25
  createWebFetchTool(),
30
- createReadFilesTool({ deniedRoots }),
31
- createFileGlobTool({ deniedRoots }),
32
- createGrepTool({ deniedRoots }),
33
- createCreateDocumentsTool({ deniedRoots }),
34
- createEditDocumentsTool({ deniedRoots }),
26
+ ...createFileTools({ deniedRoots }),
35
27
  createPdfTool(),
36
28
  ...createOfficeTools()
37
29
  ];
@@ -7,7 +7,7 @@ export const PPTX_OPS = {
7
7
  setText: { slots: [['slide', 'shape'], 'text'] },
8
8
  setCellText: { slots: [['slide', 'shape', 'row', 'column'], 'text'] },
9
9
  setStyle: { slots: [['slide', 'shape'], 'style', ['paragraph']] },
10
- addSlide: { slots: [['like', 'layout', 'at', 'title', 'body']] },
10
+ addSlide: { slots: [['like', 'layout', 'at', 'title', 'body', 'image']] },
11
11
  addPicture: { slots: ['slide', 'image', [...BOX, 'name', 'description']], inches: true },
12
12
  addTextBox: { slots: ['slide', [...BOX, 'text', 'style', 'fill', 'name']], inches: true },
13
13
  addTable: { slots: ['slide', [...BOX, 'rows', 'header', 'name']], inches: true },
@@ -1,14 +1,18 @@
1
1
  import b4a from 'b4a';
2
+ import { HarnessError } from '../errors.js';
2
3
  import { errorMessage, isRecord } from '../guards.js';
3
- import { docx, pptx, units, xlsx } from '../office/engine/index.js';
4
+ import { DocsError, docx, pptx, units, xlsx } from '../office/engine/index.js';
4
5
  import { stageInputs } from './attachments/staging.js';
5
6
  import { checkOutputBytes, RUN_OUTPUT_BUDGET_BYTES } from './attachments/output-policy.js';
6
7
  import { DOCX_OPS, opArguments, opKeys, PPTX_OPS, withAliases, XLSX_OPS } from './office/ops.js';
7
8
  const READ_CELL_LIMIT = 10_000;
8
9
  const attachedThisTurn = new WeakMap();
9
10
  const FIRST_SHEET = /^sheet ?1$/i;
11
+ const NEW_DECK_HINT = '; a new deck has only the slides its addSlide ops make, slides count from 0, and an op on a slide goes after the addSlide that makes it';
10
12
  const SHAPE_ROLES = new Set(['title', 'subtitle', 'body']);
11
13
  const HOISTED = ['attachmentId', 'output'];
14
+ const BLOCK_POSITIONED = new Set(['insertParagraphs', 'addTable', 'addImage', 'addChart']);
15
+ const FILE_NAME = /\.\w+$/;
12
16
  const WHERE_IDS_ARE = 'copy the id from the [Attached file "…" — attachmentId: …] line or an earlier tool result';
13
17
  function isObject(value) {
14
18
  return isRecord(value) && !Array.isArray(value);
@@ -25,6 +29,15 @@ export function shapeFor(deck, op) {
25
29
  const found = deck.read()[slide]?.shapes.find((entry) => entry.name.toLowerCase() === wanted);
26
30
  return found && found.id !== null ? { ...op, shape: found.id } : op;
27
31
  }
32
+ function positionFor(doc, op, created) {
33
+ if (!created || !BLOCK_POSITIONED.has(String(op.op)) || typeof op.at !== 'number') {
34
+ return op;
35
+ }
36
+ return op.at > doc.blockCount ? { ...op, at: doc.blockCount } : op;
37
+ }
38
+ function newDeckHint(err, created) {
39
+ return created && err instanceof DocsError && err.code === 'SLIDE_NOT_FOUND' ? NEW_DECK_HINT : '';
40
+ }
28
41
  export function sheetFor(book, op, created) {
29
42
  if (typeof op.sheet !== 'string')
30
43
  return op;
@@ -64,27 +77,32 @@ function readWorkbook(book) {
64
77
  const PPTX_FORMAT = {
65
78
  name: 'pptx',
66
79
  noun: 'PowerPoint deck',
80
+ stem: 'presentation',
67
81
  ops: PPTX_OPS,
68
82
  createKeys: ['size', 'title', 'fonts', 'colors'],
69
83
  open: (bytes) => pptx.open(bytes),
70
84
  create: (options) => pptx.create(options),
71
85
  read: (deck) => deck.read(),
72
86
  count: (deck) => ({ slides: deck.slideCount }),
73
- prepare: (deck, op) => shapeFor(deck, op)
87
+ prepare: (deck, op) => shapeFor(deck, op),
88
+ hint: newDeckHint
74
89
  };
75
90
  const DOCX_FORMAT = {
76
91
  name: 'docx',
77
92
  noun: 'Word document',
93
+ stem: 'document',
78
94
  ops: DOCX_OPS,
79
95
  createKeys: ['title', 'page', 'size', 'fonts'],
80
96
  open: (bytes) => docx.open(bytes),
81
97
  create: (options) => docx.create(options),
82
98
  read: (doc) => doc.read(),
83
- count: (doc) => ({ blocks: doc.blockCount })
99
+ count: (doc) => ({ blocks: doc.blockCount }),
100
+ prepare: (doc, op, created) => positionFor(doc, op, created)
84
101
  };
85
102
  const XLSX_FORMAT = {
86
103
  name: 'xlsx',
87
104
  noun: 'Excel workbook',
105
+ stem: 'workbook',
88
106
  ops: XLSX_OPS,
89
107
  createKeys: ['sheets', 'title'],
90
108
  open: (bytes) => xlsx.open(bytes),
@@ -119,11 +137,21 @@ export function normalizeArgs(args) {
119
137
  lifted.create = options;
120
138
  continue;
121
139
  }
140
+ if (rest.op === 'output') {
141
+ const { op: _output, ...named } = rest;
142
+ lifted.output ??= Object.values(named).find((value) => typeof value === 'string' && FILE_NAME.test(value));
143
+ continue;
144
+ }
122
145
  ops.push(rest);
123
146
  }
124
- lifted.ops = ops;
147
+ lifted.ops = lifted.attachmentId === undefined ? ops.map(insertedWhereAsked) : ops;
125
148
  return lifted;
126
149
  }
150
+ function insertedWhereAsked(op) {
151
+ return isObject(op) && op.op === 'appendParagraphs' && op.at !== undefined
152
+ ? { ...op, op: 'insertParagraphs' }
153
+ : op;
154
+ }
127
155
  function parseOp(format, op, i) {
128
156
  if (!isObject(op) || typeof op.op !== 'string') {
129
157
  return `ops[${i}] must be { op, ...args }`;
@@ -141,7 +169,11 @@ function parseOp(format, op, i) {
141
169
  return `ops[${i}] sheets lists the sheets and takes no arguments; to add a sheet use { op: "addSheet", name }`;
142
170
  }
143
171
  const takes = keys.length ? `it takes ${keys.join(', ')}` : 'it takes no arguments';
144
- return `ops[${i}] ${op.op} does not take ${unknown.join(', ')}; ${takes}`;
172
+ const nested = unknown.filter((key) => format.ops[key]);
173
+ const apart = nested.length
174
+ ? `; ${nested.map((name) => `{ "op": "${name}", ... }`).join(' and ')} goes in ops as its own entry, next to this one, not inside it`
175
+ : '';
176
+ return `ops[${i}] ${op.op} does not take ${unknown.join(', ')}; ${takes}${apart}`;
145
177
  }
146
178
  function parseOps(format, ops) {
147
179
  if (!Array.isArray(ops)) {
@@ -226,12 +258,24 @@ export function revisedName(format, fileName) {
226
258
  }
227
259
  return `${revised[1]}_revised-${Number(revised[2] ?? 1) + 1}.${format}`;
228
260
  }
229
- function outputFor(format, output, input) {
230
- if (!input)
231
- return output;
232
- if (output && output.toLowerCase() !== input.toLowerCase())
261
+ function newFileName(format, title) {
262
+ const stem = typeof title === 'string'
263
+ ? title
264
+ .toLowerCase()
265
+ .replace(/[^a-z0-9]+/g, '_')
266
+ .replace(/^_+|_+$/g, '')
267
+ .slice(0, 48)
268
+ : '';
269
+ return `${stem || format.stem}.${format.name}`;
270
+ }
271
+ function outputFor(format, { output, create }, input) {
272
+ if (!input) {
273
+ return output ?? newFileName(format, create?.title);
274
+ }
275
+ if (output && output.toLowerCase() !== input.toLowerCase()) {
233
276
  return output;
234
- return revisedName(format, input);
277
+ }
278
+ return revisedName(format.name, input);
235
279
  }
236
280
  async function imageId(ctx, id) {
237
281
  const found = await ctx.fetchAttachment?.({ attachmentId: id, meta: true, signal: ctx.signal });
@@ -252,8 +296,11 @@ async function imageInput(op, i, ctx) {
252
296
  }
253
297
  return { attachmentId: id ? await imageId(ctx, id) : undefined, path: `image-${i}.png` };
254
298
  }
299
+ function takesImage(op) {
300
+ return op.spec.slots.includes('image') || op.args.image !== undefined;
301
+ }
255
302
  async function stagedImages(request, ctx) {
256
- const wanted = request.ops.flatMap((op, i) => (opKeys(op.spec).includes('image') ? [i] : []));
303
+ const wanted = request.ops.flatMap((op, i) => (takesImage(op) ? [i] : []));
257
304
  const images = new Map();
258
305
  if (!wanted.length) {
259
306
  return images;
@@ -286,9 +333,6 @@ async function stagedImages(request, ctx) {
286
333
  return images;
287
334
  }
288
335
  function saveError({ format, document, output }, ctx) {
289
- if (!output) {
290
- return `the ops changed the ${format.noun}; name the file in output`;
291
- }
292
336
  if (!output.toLowerCase().endsWith(`.${format.name}`)) {
293
337
  return `output must end in .${format.name}, got "${output}"`;
294
338
  }
@@ -300,7 +344,7 @@ function saveError({ format, document, output }, ctx) {
300
344
  }
301
345
  async function attachOutput(job, ctx) {
302
346
  const refused = saveError(job, ctx);
303
- if (refused || !job.output || !ctx.attach) {
347
+ if (refused || !ctx.attach) {
304
348
  return { error: refused ?? 'nothing to save' };
305
349
  }
306
350
  const { output, document } = job;
@@ -344,7 +388,7 @@ async function attachOutput(job, ctx) {
344
388
  function runOp(document, op, input) {
345
389
  const method = Reflect.get(document, op.name);
346
390
  if (typeof method !== 'function') {
347
- throw new Error(`${op.name} is not available on this file`);
391
+ throw new HarnessError('OFFICE_OP_UNAVAILABLE', [op.name]);
348
392
  }
349
393
  return Reflect.apply(method, document, opArguments(op.spec, input, units.inches));
350
394
  }
@@ -358,7 +402,8 @@ function runOps({ format, document, request, images }) {
358
402
  results.push(runOp(document, op, input));
359
403
  }
360
404
  catch (err) {
361
- return { error: `ops[${i}] ${op.name}: ${errorMessage(err)}` };
405
+ const hint = format.hint?.(err, created) ?? '';
406
+ return { error: `ops[${i}] ${op.name}: ${errorMessage(err)}${hint}` };
362
407
  }
363
408
  }
364
409
  return results;
@@ -439,19 +484,21 @@ async function execute(format, args, ctx) {
439
484
  if ('error' in results) {
440
485
  return results;
441
486
  }
442
- if (!document.changed && request.attachmentId !== undefined) {
487
+ const onlyQueries = request.ops.every(({ spec }) => spec.query);
488
+ if (onlyQueries || (!document.changed && request.attachmentId !== undefined)) {
443
489
  return { results };
444
490
  }
445
- const output = outputFor(format.name, request.output, fileName);
491
+ const output = outputFor(format, request, fileName);
446
492
  const saved = await attachOutput({ format, document, output }, ctx);
447
493
  if ('error' in saved) {
448
494
  return saved;
449
495
  }
450
496
  const { attachment, repeated } = saved;
451
497
  const counts = format.count(document);
452
- const renamed = output !== request.output
498
+ const renamed = fileName !== null && output !== request.output
453
499
  ? `Saved as ${output}, so the attached ${fileName} keeps its own name. `
454
500
  : '';
501
+ const unplaced = !!ctx.turnImages?.length && !images.size;
455
502
  return {
456
503
  results,
457
504
  attachments: [attachment],
@@ -459,9 +506,18 @@ async function execute(format, args, ctx) {
459
506
  reply: `${attachment.fileName} — ${countLine(counts)}`,
460
507
  next: renamed +
461
508
  `Done: ${attachment.fileName} ${repeated ? 'was already' : 'is'} attached to the chat and shown to the user. ` +
462
- `Do not call ${format.name} again for it. Your answer is the reply value alone, word for word.`
509
+ afterSave(format, attachment.attachmentId, unplaced)
463
510
  };
464
511
  }
512
+ function afterSave(format, attachmentId, unplaced) {
513
+ const reply = 'Your answer is the reply value alone, word for word.';
514
+ if (!unplaced) {
515
+ return `Do not call ${format.name} again for it. ${reply}`;
516
+ }
517
+ return (`The image the user attached to their message is not in it. If they asked for that image in the ${format.noun}, ` +
518
+ `call ${format.name} once more with attachmentId "${attachmentId}" and one op that adds it with "image": {}. ` +
519
+ `Otherwise: ${reply}`);
520
+ }
465
521
  function createOfficeTool(format) {
466
522
  return {
467
523
  name: format.name,
@@ -38,6 +38,10 @@ export interface ReadDocuments {
38
38
  readonly documents: readonly ReadDocument[];
39
39
  }
40
40
  export declare function pagesLabel(count: number): string;
41
- export declare function readDocs(opened: readonly Opened[]): ReadDocument | ReadDocuments;
41
+ export type ShownPage = (fileName: string, page: number) => boolean;
42
+ export declare function textless({ doc }: Opened): boolean;
43
+ export declare function everyPageShown({ source, doc }: Opened, isShown: ShownPage): boolean;
44
+ export declare function shownNote({ source, doc }: Opened): string;
45
+ export declare function readDocs(opened: readonly Opened[], isShown: ShownPage): ReadDocument | ReadDocuments;
42
46
  export declare function build(pdfium: Pdfium, request: PdfRequest, opened: readonly Opened[]): Built | string;
43
47
  export {};
@@ -26,13 +26,38 @@ function describeField(field) {
26
26
  readOnly: field.readOnly || undefined
27
27
  };
28
28
  }
29
- function scannedNote(scanned) {
29
+ const SHOWN = {
30
+ one: 'shown to you as an image in the user message, so read its content from that image',
31
+ many: 'shown to you as images in the user message, so read their content from those images'
32
+ };
33
+ function scannedNote(scanned, shown) {
30
34
  if (!scanned.length)
31
35
  return undefined;
32
36
  const one = scanned.length === 1;
33
- return `${one ? 'page' : 'pages'} ${scanned.join(', ')} ${one ? 'has' : 'have'} no text layer: ${one ? 'it is a scanned image' : 'they are scanned images'}, and there is no OCR here`;
37
+ const what = one ? 'it is a scanned image' : 'they are scanned images';
38
+ const where = shown ? SHOWN[one ? 'one' : 'many'] : 'and there is no OCR here';
39
+ return `${one ? 'page' : 'pages'} ${scanned.join(', ')} ${one ? 'has' : 'have'} no text layer: ${what}, ${where}`;
34
40
  }
35
- function readOne({ source, doc }, budget) {
41
+ export function textless({ doc }) {
42
+ for (const page of doc.textPages()) {
43
+ if (page.text.trim())
44
+ return false;
45
+ }
46
+ return true;
47
+ }
48
+ export function everyPageShown({ source, doc }, isShown) {
49
+ for (let page = 1; page <= doc.pageCount(); page++) {
50
+ if (!isShown(source.fileName, page))
51
+ return false;
52
+ }
53
+ return true;
54
+ }
55
+ export function shownNote({ source, doc }) {
56
+ const one = doc.pageCount() === 1;
57
+ const what = one ? 'it is a scanned image' : 'its pages are scanned images';
58
+ return `${source.fileName} has no text layer: ${what}, ${SHOWN[one ? 'one' : 'many']}`;
59
+ }
60
+ function readOne({ source, doc }, budget, isShown) {
36
61
  const pages = [];
37
62
  const scanned = [];
38
63
  let truncated = false;
@@ -54,13 +79,13 @@ function readOne({ source, doc }, budget) {
54
79
  pageCount: doc.pageCount(),
55
80
  pages,
56
81
  fields: doc.fields().map(describeField),
57
- note: scannedNote(scanned),
82
+ note: scannedNote(scanned, scanned.every((page) => isShown(source.fileName, page))),
58
83
  truncated: truncated || undefined
59
84
  };
60
85
  }
61
- export function readDocs(opened) {
86
+ export function readDocs(opened, isShown) {
62
87
  const budget = { chars: READ_TEXT_LIMIT };
63
- const documents = opened.map((one) => readOne(one, budget));
88
+ const documents = opened.map((one) => readOne(one, budget, isShown));
64
89
  const [only] = documents;
65
90
  return documents.length === 1 && only ? only : { documents };
66
91
  }
@@ -1,6 +1,6 @@
1
1
  import { errorCode, errorMessage } from '../guards.js';
2
2
  import { checkOutputBytes, RUN_OUTPUT_BUDGET_BYTES } from './attachments/output-policy.js';
3
- import { build, pagesLabel, readDocs } from './pdf/build.js';
3
+ import { build, pagesLabel, everyPageShown, readDocs, shownNote, textless } from './pdf/build.js';
4
4
  import { placeImages } from './pdf/images.js';
5
5
  import { PAGE_SIZES, parseRequest, PDF_ACTIONS, WHERE_IDS_ARE } from './pdf/request.js';
6
6
  export { parsePages, parseRequest } from './pdf/request.js';
@@ -201,6 +201,13 @@ function lockOrUnlock(pdfium, request, sources) {
201
201
  }
202
202
  return { ...request, action: 'encrypt', ownerPassword: undefined, permissions: undefined };
203
203
  }
204
+ function renderedPageName(fileName, page) {
205
+ return `${fileName}.p${page - 1}.jpg`.replace(/[^a-zA-Z0-9_.-]/g, '_').slice(-40);
206
+ }
207
+ function shownPages(ctx) {
208
+ const names = (ctx.turnImages ?? []).map((image) => image.path.split(/[\\/]/).pop()?.slice(33));
209
+ return (fileName, page) => names.includes(renderedPageName(fileName, page));
210
+ }
204
211
  async function run(pdfium, asked, ctx) {
205
212
  if (asked.action === 'create') {
206
213
  const placed = await placeImages(asked, ctx);
@@ -217,7 +224,14 @@ async function run(pdfium, asked, ctx) {
217
224
  return { error };
218
225
  }
219
226
  if (request.action === 'read') {
220
- return readDocs(opened);
227
+ return readDocs(opened, shownPages(ctx));
228
+ }
229
+ const [only] = opened;
230
+ if (request.action === 'text' &&
231
+ only &&
232
+ textless(only) &&
233
+ everyPageShown(only, shownPages(ctx))) {
234
+ return { note: shownNote(only) };
221
235
  }
222
236
  return await deliver({ pdfium, request, opened }, ctx);
223
237
  }
@@ -280,6 +294,7 @@ export function createPdfTool(load = loadPdfium) {
280
294
  name: 'pdf',
281
295
  toolset: null,
282
296
  skillGated: true,
297
+ ungatedFor: ['tiny', 'low'],
283
298
  description: DESCRIPTION,
284
299
  parameters: PARAMETERS,
285
300
  effect: () => 'read',
@@ -1,11 +1,12 @@
1
1
  import path from 'path';
2
2
  import b4a from 'b4a';
3
3
  import Localdrive from 'localdrive';
4
+ import { HarnessError } from '../errors.js';
4
5
  import { unquoteArg } from '../helpers/model-args.js';
5
6
  import { resolveSkillsOverlayDir } from './skills/overlay-dir.js';
6
7
  import { parseSkillFrontMatter } from './skills/frontmatter-parser.js';
7
8
  import { Agent } from '../agent/index.js';
8
- import { shellEscapeArg } from './exec/shell-argv.js';
9
+ import { ShellLine } from './exec/shell-line.js';
9
10
  const MAIN_FILE = 'SKILL.md';
10
11
  const NO_FILE = /^(?:none|null|undefined|main)$/i;
11
12
  export function mainFileRequested(name, file) {
@@ -88,7 +89,7 @@ export function createSkillTool({ skillsDir, overlayDir = resolveSkillsOverlayDi
88
89
  return { raw: b4a.toString(buf, 'utf8'), root: root ?? undefined };
89
90
  }
90
91
  }
91
- throw new Error(`ENOENT: ${name}/${file}`);
92
+ throw new HarnessError('SKILL_FILE_NOT_FOUND', [name, file]);
92
93
  }
93
94
  return {
94
95
  name: 'skill',
@@ -134,7 +135,7 @@ export function createSkillTool({ skillsDir, overlayDir = resolveSkillsOverlayDi
134
135
  const { raw, root } = await resolveSkill(name, target);
135
136
  const { body, meta } = parseSkillFrontMatter(raw);
136
137
  const dir = resolveSkillDir(root, name);
137
- const content = dir ? body.replaceAll('{{SKILL_DIR}}', shellEscapeArg(dir)) : body;
138
+ const content = dir ? body.replaceAll('{{SKILL_DIR}}', ShellLine.escape(dir)) : body;
138
139
  const note = toolNote(meta.tools);
139
140
  return {
140
141
  name,
@@ -169,12 +170,14 @@ export function createSkillTool({ skillsDir, overlayDir = resolveSkillsOverlayDi
169
170
  try {
170
171
  return await mainInstead(file, available);
171
172
  }
172
- catch { }
173
+ catch {
174
+ return { error: `skill not found: ${name}` };
175
+ }
173
176
  }
174
177
  const rest = available.length
175
- ? ` — files this skill has: ${available.join(', ')}`
176
- : '. This skill has no other files; you already have its full instructions — act now.';
177
- return { error: `file not found in skill ${name}: ${file}${rest}` };
178
+ ? `Its other files: ${available.join(', ')}.`
179
+ : 'It has no other files; you already have its full instructions, so act now.';
180
+ return { name, content: `There is no file ${file} in this skill. ${rest}` };
178
181
  }
179
182
  }
180
183
  };