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

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 (688) hide show
  1. package/.nvmrc +1 -0
  2. package/CHANGELOG.md +3073 -1485
  3. package/README.md +110 -46
  4. package/dist-lib/index.d.ts +63 -16
  5. package/dist-lib/index.js +232 -38
  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 +11 -2
  10. package/dist-lib/lib/agent/resolve.js +30 -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 +2 -0
  14. package/dist-lib/lib/agent/tools.js +2 -1
  15. package/dist-lib/lib/capabilities/agent-ports.d.ts +1 -1
  16. package/dist-lib/lib/capabilities/agent-ports.js +11 -4
  17. package/dist-lib/lib/capabilities/completion-engine/actors/answering.js +2 -2
  18. package/dist-lib/lib/capabilities/completion-engine/actors/batching.js +1 -0
  19. package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +2 -0
  20. package/dist-lib/lib/capabilities/completion-engine/actors/execute.d.ts +1 -1
  21. package/dist-lib/lib/capabilities/completion-engine/actors/executing.d.ts +2 -1
  22. package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +132 -13
  23. package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +11 -5
  24. package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.js +3 -2
  25. package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.d.ts +1 -1
  26. package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +54 -10
  27. package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.d.ts +1 -1
  28. package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +12 -2
  29. package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +142 -50
  30. package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +10 -4
  31. package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +78 -20
  32. package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.d.ts +2 -1
  33. package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +33 -16
  34. package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +38 -23
  35. package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +50 -12
  36. package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +10 -4
  37. package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +80 -3
  38. package/dist-lib/lib/capabilities/completion-engine/actors/streaming.d.ts +5 -1
  39. package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +101 -41
  40. package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +2 -1
  41. package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +56 -17
  42. package/dist-lib/lib/capabilities/completion-engine/driver.js +58 -15
  43. package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +3 -1
  44. package/dist-lib/lib/capabilities/completion-engine/durable.js +12 -2
  45. package/dist-lib/lib/capabilities/completion-engine/engine.d.ts +4 -1
  46. package/dist-lib/lib/capabilities/completion-engine/engine.js +14 -1
  47. package/dist-lib/lib/capabilities/completion-engine/index.d.ts +5 -1
  48. package/dist-lib/lib/capabilities/completion-engine/index.js +5 -2
  49. package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +26 -3
  50. package/dist-lib/lib/capabilities/completion-engine/loop.js +14 -2
  51. package/dist-lib/lib/capabilities/completion-engine/metrics.d.ts +9 -2
  52. package/dist-lib/lib/capabilities/completion-engine/metrics.js +28 -7
  53. package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +63 -0
  54. package/dist-lib/lib/capabilities/completion-engine/model-round.js +99 -0
  55. package/dist-lib/lib/capabilities/completion-engine/operations.js +30 -10
  56. package/dist-lib/lib/capabilities/completion-engine/ports.js +6 -9
  57. package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +4 -1
  58. package/dist-lib/lib/capabilities/completion-engine/round.d.ts +38 -6
  59. package/dist-lib/lib/capabilities/completion-engine/round.js +395 -118
  60. package/dist-lib/lib/capabilities/completion-engine/session.d.ts +12 -4
  61. package/dist-lib/lib/capabilities/completion-engine/session.js +31 -2
  62. package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +5 -2
  63. package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +8 -43
  64. package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +32 -141
  65. package/dist-lib/lib/capabilities/completion-engine/tool-outcome.d.ts +4 -0
  66. package/dist-lib/lib/capabilities/completion-engine/tool-outcome.js +42 -0
  67. package/dist-lib/lib/capabilities/completion-engine/tool-preflight.d.ts +43 -0
  68. package/dist-lib/lib/capabilities/completion-engine/tool-preflight.js +91 -0
  69. package/dist-lib/lib/capabilities/completion-engine/tool-sets.d.ts +24 -0
  70. package/dist-lib/lib/capabilities/completion-engine/tool-sets.js +15 -0
  71. package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +17 -9
  72. package/dist-lib/lib/capabilities/completion-engine/turns.js +98 -86
  73. package/dist-lib/lib/capabilities/detect-language.d.ts +2 -1
  74. package/dist-lib/lib/capabilities/detect-language.js +14 -2
  75. package/dist-lib/lib/capabilities/download.d.ts +10 -8
  76. package/dist-lib/lib/capabilities/download.js +1 -1
  77. package/dist-lib/lib/capabilities/enhance.d.ts +1 -1
  78. package/dist-lib/lib/capabilities/enhance.js +23 -11
  79. package/dist-lib/lib/capabilities/kv-cache.d.ts +1 -1
  80. package/dist-lib/lib/capabilities/preview-model-source.d.ts +7 -0
  81. package/dist-lib/lib/capabilities/preview-model-source.js +83 -23
  82. package/dist-lib/lib/capabilities/prompt-prefix.d.ts +3 -1
  83. package/dist-lib/lib/capabilities/prompt-prefix.js +8 -0
  84. package/dist-lib/lib/capabilities/sdk-tool.d.ts +13 -4
  85. package/dist-lib/lib/capabilities/sdk-tool.js +59 -7
  86. package/dist-lib/lib/capabilities/skill-entry.d.ts +13 -1
  87. package/dist-lib/lib/capabilities/skill-entry.js +33 -2
  88. package/dist-lib/lib/capabilities/tool-failed-note.d.ts +1 -0
  89. package/dist-lib/lib/capabilities/tool-failed-note.js +1 -0
  90. package/dist-lib/lib/capabilities/tool-plan.d.ts +5 -1
  91. package/dist-lib/lib/capabilities/tool-plan.js +20 -5
  92. package/dist-lib/lib/capabilities/tool-prompt-log.d.ts +1 -1
  93. package/dist-lib/lib/capabilities/tool-prompt-log.js +3 -3
  94. package/dist-lib/lib/capabilities/tool-turns/attachments.d.ts +7 -0
  95. package/dist-lib/lib/capabilities/tool-turns/attachments.js +39 -0
  96. package/dist-lib/lib/capabilities/tool-turns/copy.d.ts +13 -0
  97. package/dist-lib/lib/capabilities/tool-turns/copy.js +29 -0
  98. package/dist-lib/lib/capabilities/tool-turns/result-turn.d.ts +22 -0
  99. package/dist-lib/lib/capabilities/tool-turns/result-turn.js +120 -0
  100. package/dist-lib/lib/capabilities/tool-turns/run-limits.d.ts +6 -0
  101. package/dist-lib/lib/capabilities/tool-turns/run-limits.js +32 -0
  102. package/dist-lib/lib/capabilities/tool-turns/skill-loads.d.ts +9 -0
  103. package/dist-lib/lib/capabilities/tool-turns/skill-loads.js +71 -0
  104. package/dist-lib/lib/capabilities/tool-turns.d.ts +8 -43
  105. package/dist-lib/lib/capabilities/tool-turns.js +6 -253
  106. package/dist-lib/lib/capabilities/usage-breakdown.d.ts +1 -0
  107. package/dist-lib/lib/capabilities/usage-breakdown.js +4 -1
  108. package/dist-lib/lib/client/index.d.ts +19 -0
  109. package/dist-lib/lib/client/index.js +263 -0
  110. package/dist-lib/lib/connect/abort.d.ts +6 -0
  111. package/dist-lib/lib/connect/abort.js +52 -0
  112. package/dist-lib/lib/connect/bridges.d.ts +21 -0
  113. package/dist-lib/lib/connect/bridges.js +185 -0
  114. package/dist-lib/lib/connect/decode.d.ts +31 -0
  115. package/dist-lib/lib/connect/decode.js +114 -0
  116. package/dist-lib/lib/connect/host-run-log.d.ts +16 -0
  117. package/dist-lib/lib/connect/host-run-log.js +74 -0
  118. package/dist-lib/lib/connect/served.d.ts +7 -0
  119. package/dist-lib/lib/connect/served.js +45 -0
  120. package/dist-lib/lib/connect.d.ts +20 -11
  121. package/dist-lib/lib/connect.js +178 -415
  122. package/dist-lib/lib/context-window.d.ts +13 -5
  123. package/dist-lib/lib/context-window.js +19 -6
  124. package/dist-lib/lib/contract/agent.d.ts +25 -4
  125. package/dist-lib/lib/contract/completion.d.ts +82 -32
  126. package/dist-lib/lib/contract/drive.d.ts +130 -0
  127. package/dist-lib/lib/contract/drive.js +1 -0
  128. package/dist-lib/lib/contract/egress-proxy.d.ts +13 -0
  129. package/dist-lib/lib/contract/egress-proxy.js +1 -0
  130. package/dist-lib/lib/contract/exec.d.ts +4 -3
  131. package/dist-lib/lib/contract/hooks.d.ts +4 -1
  132. package/dist-lib/lib/contract/index.d.ts +4 -0
  133. package/dist-lib/lib/contract/knowledge.d.ts +10 -0
  134. package/dist-lib/lib/contract/managed-skills.d.ts +1 -0
  135. package/dist-lib/lib/contract/managed-skills.js +1 -0
  136. package/dist-lib/lib/contract/media.d.ts +58 -0
  137. package/dist-lib/lib/contract/media.js +1 -0
  138. package/dist-lib/lib/contract/models.d.ts +12 -6
  139. package/dist-lib/lib/contract/ocr.d.ts +17 -0
  140. package/dist-lib/lib/contract/ocr.js +1 -0
  141. package/dist-lib/lib/contract/policy.d.ts +75 -0
  142. package/dist-lib/lib/contract/policy.js +1 -0
  143. package/dist-lib/lib/contract/run.d.ts +28 -3
  144. package/dist-lib/lib/contract/sandbox.d.ts +3 -1
  145. package/dist-lib/lib/contract/speech.d.ts +1 -1
  146. package/dist-lib/lib/contract/translation.d.ts +20 -0
  147. package/dist-lib/lib/contract/translation.js +1 -0
  148. package/dist-lib/lib/contract-types.d.ts +48 -16
  149. package/dist-lib/lib/embeddings/index.d.ts +7 -1
  150. package/dist-lib/lib/embeddings/index.js +26 -5
  151. package/dist-lib/lib/errors.d.ts +278 -0
  152. package/dist-lib/lib/errors.js +212 -0
  153. package/dist-lib/lib/fold/index.d.ts +26 -1
  154. package/dist-lib/lib/fold/index.js +76 -9
  155. package/dist-lib/lib/guarded-fetch.js +11 -7
  156. package/dist-lib/lib/guards.d.ts +2 -0
  157. package/dist-lib/lib/guards.js +7 -0
  158. package/dist-lib/lib/hardware/capability-probe.js +10 -7
  159. package/dist-lib/lib/hardware/cpu-placement.d.ts +8 -0
  160. package/dist-lib/lib/hardware/cpu-placement.js +48 -0
  161. package/dist-lib/lib/hardware/gpu-probe-addon.js +26 -11
  162. package/dist-lib/lib/hardware/gpu-probe.js +10 -1
  163. package/dist-lib/lib/hardware/gpu-stats.native.cjs +17 -1
  164. package/dist-lib/lib/helpers/completion-params.d.ts +7 -2
  165. package/dist-lib/lib/helpers/completion-params.js +26 -2
  166. package/dist-lib/lib/helpers/control-tokens.d.ts +3 -0
  167. package/dist-lib/lib/helpers/control-tokens.js +25 -0
  168. package/dist-lib/lib/helpers/engine-error.d.ts +2 -1
  169. package/dist-lib/lib/helpers/engine-error.js +12 -12
  170. package/dist-lib/lib/helpers/goal-check/asks.d.ts +25 -0
  171. package/dist-lib/lib/helpers/goal-check/asks.js +52 -0
  172. package/dist-lib/lib/helpers/goal-check/checks.d.ts +8 -0
  173. package/dist-lib/lib/helpers/goal-check/checks.js +92 -0
  174. package/dist-lib/lib/helpers/goal-check/commands.d.ts +7 -0
  175. package/dist-lib/lib/helpers/goal-check/commands.js +130 -0
  176. package/dist-lib/lib/helpers/goal-check/paths.d.ts +5 -0
  177. package/dist-lib/lib/helpers/goal-check/paths.js +44 -0
  178. package/dist-lib/lib/helpers/goal-check/shell.d.ts +9 -0
  179. package/dist-lib/lib/helpers/goal-check/shell.js +96 -0
  180. package/dist-lib/lib/helpers/goal-check.d.ts +36 -0
  181. package/dist-lib/lib/helpers/goal-check.js +35 -0
  182. package/dist-lib/lib/helpers/head-tail.js +1 -1
  183. package/dist-lib/lib/helpers/html-helpers.js +9 -6
  184. package/dist-lib/lib/helpers/load-stall.d.ts +1 -1
  185. package/dist-lib/lib/helpers/load-stall.js +2 -2
  186. package/dist-lib/lib/helpers/markup-stream-filter.d.ts +4 -1
  187. package/dist-lib/lib/helpers/markup-stream-filter.js +20 -6
  188. package/dist-lib/lib/helpers/recent-map.d.ts +7 -0
  189. package/dist-lib/lib/helpers/recent-map.js +23 -0
  190. package/dist-lib/lib/helpers/repeated-reply.js +24 -16
  191. package/dist-lib/lib/helpers/require-peers.d.ts +3 -0
  192. package/dist-lib/lib/helpers/require-peers.js +23 -0
  193. package/dist-lib/lib/helpers/run-outcome.d.ts +2 -0
  194. package/dist-lib/lib/helpers/run-outcome.js +6 -2
  195. package/dist-lib/lib/helpers/spawn-path.d.ts +1 -0
  196. package/dist-lib/lib/helpers/spawn-path.js +2 -1
  197. package/dist-lib/lib/helpers/thinking.d.ts +3 -2
  198. package/dist-lib/lib/helpers/thinking.js +19 -0
  199. package/dist-lib/lib/helpers/tool-call-markup/emit.d.ts +6 -0
  200. package/dist-lib/lib/helpers/tool-call-markup/emit.js +15 -0
  201. package/dist-lib/lib/helpers/tool-call-markup/recover.d.ts +22 -0
  202. package/dist-lib/lib/helpers/tool-call-markup/recover.js +130 -0
  203. package/dist-lib/lib/helpers/tool-call-markup/skill-recovery.d.ts +3 -0
  204. package/dist-lib/lib/helpers/tool-call-markup/skill-recovery.js +56 -0
  205. package/dist-lib/lib/helpers/tool-call-markup/strip.d.ts +4 -0
  206. package/dist-lib/lib/helpers/tool-call-markup/strip.js +149 -0
  207. package/dist-lib/lib/helpers/tool-call-markup.d.ts +19 -24
  208. package/dist-lib/lib/helpers/tool-call-markup.js +17 -343
  209. package/dist-lib/lib/hooks/built-in/arg-repair.js +6 -2
  210. package/dist-lib/lib/hooks/built-in/policy-rules.d.ts +8 -0
  211. package/dist-lib/lib/hooks/built-in/policy-rules.js +192 -0
  212. package/dist-lib/lib/hooks/built-in/sandbox.js +23 -5
  213. package/dist-lib/lib/hooks/index.d.ts +4 -1
  214. package/dist-lib/lib/hooks/index.js +9 -4
  215. package/dist-lib/lib/hooks/run.js +3 -3
  216. package/dist-lib/lib/lifecycle/index.js +15 -14
  217. package/dist-lib/lib/lifecycle/machine.js +2 -2
  218. package/dist-lib/lib/log.d.ts +26 -5
  219. package/dist-lib/lib/log.js +86 -23
  220. package/dist-lib/lib/machine/completion/actions/completion.d.ts +15 -16
  221. package/dist-lib/lib/machine/completion/actions/completion.js +164 -107
  222. package/dist-lib/lib/machine/completion/actions/goal.d.ts +10 -0
  223. package/dist-lib/lib/machine/completion/actions/goal.js +93 -0
  224. package/dist-lib/lib/machine/completion/actions/prepare.js +3 -2
  225. package/dist-lib/lib/machine/completion/actions/reject-tool.d.ts +16 -0
  226. package/dist-lib/lib/machine/completion/actions/reject-tool.js +147 -0
  227. package/dist-lib/lib/machine/completion/actions/retry-round.d.ts +6 -0
  228. package/dist-lib/lib/machine/completion/actions/retry-round.js +50 -0
  229. package/dist-lib/lib/machine/completion/actions/rounds.d.ts +5 -0
  230. package/dist-lib/lib/machine/completion/actions/rounds.js +31 -0
  231. package/dist-lib/lib/machine/completion/actions/tools.d.ts +1 -16
  232. package/dist-lib/lib/machine/completion/actions/tools.js +111 -140
  233. package/dist-lib/lib/machine/completion/context.js +11 -1
  234. package/dist-lib/lib/machine/completion/guards/retry.d.ts +3 -1
  235. package/dist-lib/lib/machine/completion/guards/retry.js +9 -2
  236. package/dist-lib/lib/machine/completion/implementations.d.ts +18 -9
  237. package/dist-lib/lib/machine/completion/implementations.js +64 -16
  238. package/dist-lib/lib/machine/completion/machine.d.ts +38 -9
  239. package/dist-lib/lib/machine/completion/machine.js +58 -9
  240. package/dist-lib/lib/machine/completion/metrics.d.ts +25 -0
  241. package/dist-lib/lib/machine/completion/metrics.js +68 -0
  242. package/dist-lib/lib/machine/completion/nudges.d.ts +5 -0
  243. package/dist-lib/lib/machine/completion/nudges.js +33 -0
  244. package/dist-lib/lib/machine/completion/rules.d.ts +19 -27
  245. package/dist-lib/lib/machine/completion/rules.js +48 -79
  246. package/dist-lib/lib/machine/completion/splice.d.ts +9 -0
  247. package/dist-lib/lib/machine/completion/splice.js +19 -0
  248. package/dist-lib/lib/machine/completion/types.d.ts +81 -14
  249. package/dist-lib/lib/machine/index.d.ts +50 -11
  250. package/dist-lib/lib/machine/index.js +12 -2
  251. package/dist-lib/lib/media-host.d.ts +12 -0
  252. package/dist-lib/lib/media-host.js +52 -0
  253. package/dist-lib/lib/media-port.d.ts +20 -0
  254. package/dist-lib/lib/media-port.js +77 -0
  255. package/dist-lib/lib/media-wire.d.ts +8 -0
  256. package/dist-lib/lib/media-wire.js +111 -0
  257. package/dist-lib/lib/models/context-choice.d.ts +15 -0
  258. package/dist-lib/lib/models/context-choice.js +62 -0
  259. package/dist-lib/lib/models/context.d.ts +1 -1
  260. package/dist-lib/lib/models/custom-model-cache.d.ts +1 -0
  261. package/dist-lib/lib/models/custom-model-cache.js +3 -0
  262. package/dist-lib/lib/models/download-gate.d.ts +20 -0
  263. package/dist-lib/lib/models/download-gate.js +73 -0
  264. package/dist-lib/lib/models/gguf-header.d.ts +11 -0
  265. package/dist-lib/lib/models/gguf-header.js +203 -15
  266. package/dist-lib/lib/models/gpu-selection.d.ts +6 -1
  267. package/dist-lib/lib/models/gpu-selection.js +29 -5
  268. package/dist-lib/lib/models/kv-cache.d.ts +2 -0
  269. package/dist-lib/lib/models/kv-cache.js +8 -0
  270. package/dist-lib/lib/models/llm-presets.d.ts +6 -1
  271. package/dist-lib/lib/models/llm-presets.js +33 -6
  272. package/dist-lib/lib/models/load-requests.d.ts +9 -0
  273. package/dist-lib/lib/models/load-requests.js +42 -0
  274. package/dist-lib/lib/models/memory-cap.d.ts +13 -0
  275. package/dist-lib/lib/models/memory-cap.js +21 -0
  276. package/dist-lib/lib/models/model-catalog-constants.d.ts +2 -2
  277. package/dist-lib/lib/models/model-catalog-constants.js +3 -4
  278. package/dist-lib/lib/models/model-catalog.d.ts +7 -3
  279. package/dist-lib/lib/models/model-catalog.js +44 -11
  280. package/dist-lib/lib/models/model-delete.d.ts +1 -1
  281. package/dist-lib/lib/models/model-fit.d.ts +2 -2
  282. package/dist-lib/lib/models/model-fit.js +5 -6
  283. package/dist-lib/lib/models/model-handle.d.ts +9 -2
  284. package/dist-lib/lib/models/model-handle.js +14 -3
  285. package/dist-lib/lib/models/model-list.d.ts +9 -2
  286. package/dist-lib/lib/models/model-list.js +23 -0
  287. package/dist-lib/lib/models/model-pool.d.ts +42 -7
  288. package/dist-lib/lib/models/model-pool.js +139 -49
  289. package/dist-lib/lib/models/model-source.d.ts +3 -2
  290. package/dist-lib/lib/models/model-source.js +23 -5
  291. package/dist-lib/lib/models/opencl-cache.js +2 -2
  292. package/dist-lib/lib/models/sdk-faults.d.ts +1 -0
  293. package/dist-lib/lib/models/sdk-faults.js +9 -0
  294. package/dist-lib/lib/models/tool-dialect.d.ts +1 -1
  295. package/dist-lib/lib/models/tts-model-default.d.ts +2 -1
  296. package/dist-lib/lib/models/tts-model-default.js +8 -6
  297. package/dist-lib/lib/no-redirect-fetch-bare.js +2 -1
  298. package/dist-lib/lib/no-redirect-fetch-impl.d.ts +2 -1
  299. package/dist-lib/lib/no-redirect-fetch-impl.js +46 -8
  300. package/dist-lib/lib/office/engine/pptx/picture-area.d.ts +23 -0
  301. package/dist-lib/lib/office/engine/pptx/picture-area.js +84 -0
  302. package/dist-lib/lib/office/engine/pptx/presentation.d.ts +2 -0
  303. package/dist-lib/lib/office/engine/pptx/presentation.js +64 -21
  304. package/dist-lib/lib/office/engine/pptx/types.d.ts +1 -0
  305. package/dist-lib/lib/office/engine/xlsx/sheet.js +10 -4
  306. package/dist-lib/lib/office/engine/xlsx/workbook.d.ts +1 -0
  307. package/dist-lib/lib/office/engine/xlsx/workbook.js +34 -3
  308. package/dist-lib/lib/office/extract.js +4 -3
  309. package/dist-lib/lib/office/index.js +2 -1
  310. package/dist-lib/lib/plugins/registry.d.ts +15 -0
  311. package/dist-lib/lib/plugins/registry.js +91 -22
  312. package/dist-lib/lib/plugins/require-bare.d.ts +1 -0
  313. package/dist-lib/lib/plugins/require-bare.js +13 -0
  314. package/dist-lib/lib/policy/index.d.ts +11 -0
  315. package/dist-lib/lib/policy/index.js +235 -0
  316. package/dist-lib/lib/prompt.d.ts +9 -4
  317. package/dist-lib/lib/prompt.js +95 -32
  318. package/dist-lib/lib/residency/completion-runtime.d.ts +17 -6
  319. package/dist-lib/lib/residency/completion-runtime.js +91 -37
  320. package/dist-lib/lib/residency/index.d.ts +59 -6
  321. package/dist-lib/lib/residency/index.js +444 -42
  322. package/dist-lib/lib/resolution-detector.js +3 -3
  323. package/dist-lib/lib/round-host.d.ts +12 -0
  324. package/dist-lib/lib/round-host.js +57 -0
  325. package/dist-lib/lib/round-port.d.ts +24 -0
  326. package/dist-lib/lib/round-port.js +81 -0
  327. package/dist-lib/lib/rpc-session.js +2 -1
  328. package/dist-lib/lib/run-log/redact.js +7 -7
  329. package/dist-lib/lib/run-log/request-codec.js +2 -2
  330. package/dist-lib/lib/sdk-loader.d.ts +1 -1
  331. package/dist-lib/lib/sdk-loader.js +47 -17
  332. package/dist-lib/lib/sdk-storage.d.ts +1 -0
  333. package/dist-lib/lib/sdk-storage.js +18 -2
  334. package/dist-lib/lib/serve/completion.d.ts +7 -0
  335. package/dist-lib/lib/serve/completion.js +553 -0
  336. package/dist-lib/lib/serve/downloads.d.ts +4 -0
  337. package/dist-lib/lib/serve/downloads.js +79 -0
  338. package/dist-lib/lib/serve/models.d.ts +5 -0
  339. package/dist-lib/lib/serve/models.js +120 -0
  340. package/dist-lib/lib/serve/noop.d.ts +1 -0
  341. package/dist-lib/lib/serve/noop.js +1 -0
  342. package/dist-lib/lib/serve/requests.d.ts +147 -0
  343. package/dist-lib/lib/serve/requests.js +1 -0
  344. package/dist-lib/lib/serve/rounds.d.ts +11 -0
  345. package/dist-lib/lib/serve/rounds.js +67 -0
  346. package/dist-lib/lib/serve/run-log-start.d.ts +38 -0
  347. package/dist-lib/lib/serve/run-log-start.js +254 -0
  348. package/dist-lib/lib/serve/skills.d.ts +32 -0
  349. package/dist-lib/lib/serve/skills.js +46 -0
  350. package/dist-lib/lib/serve.d.ts +5 -1
  351. package/dist-lib/lib/serve.js +51 -916
  352. package/dist-lib/lib/sidecar/index.d.ts +39 -0
  353. package/dist-lib/lib/sidecar/index.js +205 -0
  354. package/dist-lib/lib/sidecar/user-plugins.d.ts +9 -0
  355. package/dist-lib/lib/sidecar/user-plugins.js +119 -0
  356. package/dist-lib/lib/skills-host/index.d.ts +7 -3
  357. package/dist-lib/lib/skills-host/index.js +47 -22
  358. package/dist-lib/lib/spawn.d.ts +6 -4
  359. package/dist-lib/lib/spawn.js +22 -20
  360. package/dist-lib/lib/spill.d.ts +1 -0
  361. package/dist-lib/lib/spill.js +12 -8
  362. package/dist-lib/lib/tools/ask-user.d.ts +2 -0
  363. package/dist-lib/lib/tools/ask-user.js +137 -0
  364. package/dist-lib/lib/tools/attachments/delivered.d.ts +5 -0
  365. package/dist-lib/lib/tools/attachments/delivered.js +16 -0
  366. package/dist-lib/lib/tools/attachments/fetched-file.d.ts +32 -0
  367. package/dist-lib/lib/tools/attachments/fetched-file.js +134 -0
  368. package/dist-lib/lib/tools/attachments/staging.d.ts +1 -0
  369. package/dist-lib/lib/tools/attachments/staging.js +19 -8
  370. package/dist-lib/lib/tools/exec/runner.d.ts +4 -0
  371. package/dist-lib/lib/tools/exec/runner.js +20 -2
  372. package/dist-lib/lib/tools/exec/scope.d.ts +0 -1
  373. package/dist-lib/lib/tools/exec/scope.js +23 -114
  374. package/dist-lib/lib/tools/exec/shell-guidance.js +4 -4
  375. package/dist-lib/lib/tools/exec/shell-line.d.ts +26 -0
  376. package/dist-lib/lib/tools/exec/shell-line.js +334 -0
  377. package/dist-lib/lib/tools/exec.d.ts +4 -1
  378. package/dist-lib/lib/tools/exec.js +89 -27
  379. package/dist-lib/lib/tools/files/edit-file.d.ts +6 -0
  380. package/dist-lib/lib/tools/files/edit-file.js +266 -0
  381. package/dist-lib/lib/tools/files/glob.d.ts +3 -0
  382. package/dist-lib/lib/tools/files/glob.js +65 -0
  383. package/dist-lib/lib/tools/files/grep.d.ts +6 -0
  384. package/dist-lib/lib/tools/files/grep.js +212 -0
  385. package/dist-lib/lib/tools/files/index.d.ts +3 -0
  386. package/dist-lib/lib/tools/files/index.js +25 -0
  387. package/dist-lib/lib/tools/files/list-dir.d.ts +6 -0
  388. package/dist-lib/lib/tools/files/list-dir.js +136 -0
  389. package/dist-lib/lib/tools/files/make-dir.d.ts +3 -0
  390. package/dist-lib/lib/tools/files/make-dir.js +48 -0
  391. package/dist-lib/lib/tools/files/read-file.d.ts +3 -0
  392. package/dist-lib/lib/tools/files/read-file.js +224 -0
  393. package/dist-lib/lib/tools/files/transfer.d.ts +4 -0
  394. package/dist-lib/lib/tools/files/transfer.js +83 -0
  395. package/dist-lib/lib/tools/files/trash-file.d.ts +4 -0
  396. package/dist-lib/lib/tools/files/trash-file.js +62 -0
  397. package/dist-lib/lib/tools/files/write-file.d.ts +3 -0
  398. package/dist-lib/lib/tools/files/write-file.js +56 -0
  399. package/dist-lib/lib/tools/fs/document-text.d.ts +8 -0
  400. package/dist-lib/lib/tools/fs/document-text.js +22 -0
  401. package/dist-lib/lib/tools/fs/drive.d.ts +5 -25
  402. package/dist-lib/lib/tools/fs/drive.js +9 -1
  403. package/dist-lib/lib/tools/fs/edit-match.d.ts +33 -0
  404. package/dist-lib/lib/tools/fs/edit-match.js +445 -0
  405. package/dist-lib/lib/tools/fs/ignore.d.ts +13 -0
  406. package/dist-lib/lib/tools/fs/ignore.js +104 -0
  407. package/dist-lib/lib/tools/fs/local.js +28 -5
  408. package/dist-lib/lib/tools/fs/remote-protocol.d.ts +2 -40
  409. package/dist-lib/lib/tools/fs/remote-protocol.js +1 -1
  410. package/dist-lib/lib/tools/fs/remote.d.ts +3 -11
  411. package/dist-lib/lib/tools/fs/remote.js +24 -14
  412. package/dist-lib/lib/tools/fs/scope.d.ts +4 -15
  413. package/dist-lib/lib/tools/fs/scope.js +5 -2
  414. package/dist-lib/lib/tools/fs/search.d.ts +25 -0
  415. package/dist-lib/lib/tools/fs/search.js +383 -0
  416. package/dist-lib/lib/tools/{file-glob.d.ts → fs/targets.d.ts} +1 -5
  417. package/dist-lib/lib/tools/fs/targets.js +32 -0
  418. package/dist-lib/lib/tools/fs/tool-path.d.ts +27 -0
  419. package/dist-lib/lib/tools/fs/tool-path.js +70 -0
  420. package/dist-lib/lib/tools/fs/walk.d.ts +14 -5
  421. package/dist-lib/lib/tools/fs/walk.js +119 -24
  422. package/dist-lib/lib/tools/http-request/request.d.ts +4 -2
  423. package/dist-lib/lib/tools/http-request/request.js +2 -1
  424. package/dist-lib/lib/tools/http-request/truncate-response.d.ts +16 -1
  425. package/dist-lib/lib/tools/http-request/truncate-response.js +56 -11
  426. package/dist-lib/lib/tools/http-request.d.ts +1 -0
  427. package/dist-lib/lib/tools/http-request.js +101 -16
  428. package/dist-lib/lib/tools/index.d.ts +4 -1
  429. package/dist-lib/lib/tools/index.js +8 -12
  430. package/dist-lib/lib/tools/office/ops.d.ts +1 -0
  431. package/dist-lib/lib/tools/office/ops.js +5 -1
  432. package/dist-lib/lib/tools/office.d.ts +2 -1
  433. package/dist-lib/lib/tools/office.js +273 -56
  434. package/dist-lib/lib/tools/operations/builders.d.ts +4 -3
  435. package/dist-lib/lib/tools/operations/builders.js +41 -3
  436. package/dist-lib/lib/tools/operations/calendar-range.d.ts +16 -0
  437. package/dist-lib/lib/tools/operations/calendar-range.js +40 -0
  438. package/dist-lib/lib/tools/operations/compile.js +8 -6
  439. package/dist-lib/lib/tools/operations/manifest.d.ts +4 -0
  440. package/dist-lib/lib/tools/pdf/build.d.ts +17 -3
  441. package/dist-lib/lib/tools/pdf/build.js +77 -16
  442. package/dist-lib/lib/tools/pdf/pages.d.ts +12 -0
  443. package/dist-lib/lib/tools/pdf/pages.js +31 -0
  444. package/dist-lib/lib/tools/pdf/recognize.d.ts +13 -0
  445. package/dist-lib/lib/tools/pdf/recognize.js +55 -0
  446. package/dist-lib/lib/tools/pdf/request.d.ts +3 -8
  447. package/dist-lib/lib/tools/pdf/request.js +4 -4
  448. package/dist-lib/lib/tools/pdf.d.ts +0 -1
  449. package/dist-lib/lib/tools/pdf.js +56 -13
  450. package/dist-lib/lib/tools/skill.js +23 -11
  451. package/dist-lib/lib/tools/skills/bundled-dir.d.ts +8 -1
  452. package/dist-lib/lib/tools/skills/bundled-dir.js +42 -36
  453. package/dist-lib/lib/tools/skills/bundled-hash.d.ts +1 -0
  454. package/dist-lib/lib/tools/skills/bundled-hash.js +4 -1
  455. package/dist-lib/lib/tools/skills/catalog-loader.d.ts +12 -0
  456. package/dist-lib/lib/tools/skills/catalog-loader.js +173 -0
  457. package/dist-lib/lib/tools/skills/catalog.d.ts +7 -8
  458. package/dist-lib/lib/tools/skills/catalog.js +1 -158
  459. package/dist-lib/lib/tools/skills/cli-argv.js +25 -5
  460. package/dist-lib/lib/tools/skills/cli-schema-check.d.ts +1 -0
  461. package/dist-lib/lib/tools/skills/cli-schema-check.js +3 -0
  462. package/dist-lib/lib/tools/skills/cli-schema-load.js +10 -0
  463. package/dist-lib/lib/tools/skills/cli-schema-types.d.ts +2 -0
  464. package/dist-lib/lib/tools/skills/cli-schema.js +6 -3
  465. package/dist-lib/lib/tools/skills/credential-check.d.ts +1 -0
  466. package/dist-lib/lib/tools/skills/credential-check.js +3 -0
  467. package/dist-lib/lib/tools/skills/credential-health.js +3 -3
  468. package/dist-lib/lib/tools/skills/frontmatter-parser.d.ts +3 -0
  469. package/dist-lib/lib/tools/skills/frontmatter-parser.js +5 -0
  470. package/dist-lib/lib/tools/skills/index.d.ts +1 -0
  471. package/dist-lib/lib/tools/skills/index.js +1 -0
  472. package/dist-lib/lib/tools/skills/manifest-parse.d.ts +1 -0
  473. package/dist-lib/lib/tools/skills/manifest-parse.js +39 -3
  474. package/dist-lib/lib/tools/skills/manifest.d.ts +1 -0
  475. package/dist-lib/lib/tools/skills/mention-name.d.ts +6 -0
  476. package/dist-lib/lib/tools/skills/mention-name.js +6 -0
  477. package/dist-lib/lib/tools/skills/mention.d.ts +2 -2
  478. package/dist-lib/lib/tools/skills/mention.js +11 -4
  479. package/dist-lib/lib/tools/skills/overlay-crud.d.ts +3 -3
  480. package/dist-lib/lib/tools/skills/overlay-crud.js +7 -6
  481. package/dist-lib/lib/tools/skills/overlay-watch.d.ts +2 -2
  482. package/dist-lib/lib/tools/skills/overlay-watch.js +4 -3
  483. package/dist-lib/lib/tools/skills/scope-key.d.ts +1 -0
  484. package/dist-lib/lib/tools/skills/scope-key.js +4 -0
  485. package/dist-lib/lib/tools/skills/skill-state-constants.d.ts +1 -0
  486. package/dist-lib/lib/tools/skills/skill-state-constants.js +4 -0
  487. package/dist-lib/lib/tools/skills/skill-tree.d.ts +5 -0
  488. package/dist-lib/lib/tools/skills/skill-tree.js +54 -0
  489. package/dist-lib/lib/tools/url-guard.d.ts +6 -1
  490. package/dist-lib/lib/tools/url-guard.js +8 -2
  491. package/dist-lib/lib/tools/web-fetch.js +50 -133
  492. package/dist-lib/lib/wire/download.d.ts +10 -0
  493. package/dist-lib/lib/wire/download.js +35 -0
  494. package/dist-lib/lib/wire/event.d.ts +41 -0
  495. package/dist-lib/lib/wire/event.js +306 -0
  496. package/dist-lib/lib/wire/fields.d.ts +3 -0
  497. package/dist-lib/lib/wire/fields.js +12 -0
  498. package/dist-lib/lib/wire/knowledge.d.ts +9 -0
  499. package/dist-lib/lib/wire/knowledge.js +68 -0
  500. package/dist-lib/lib/wire/round.d.ts +14 -0
  501. package/dist-lib/lib/wire/round.js +45 -0
  502. package/dist-lib/lib/wire/vectors.d.ts +6 -0
  503. package/dist-lib/lib/wire/vectors.js +33 -0
  504. package/dist-lib/lib/wire.d.ts +28 -64
  505. package/dist-lib/lib/wire.js +24 -417
  506. package/dist-lib/plugins/coding/index.d.ts +1 -1
  507. package/dist-lib/plugins/coding/index.js +2 -4
  508. package/dist-lib/plugins/coding/read-only.d.ts +1 -0
  509. package/dist-lib/plugins/coding/read-only.js +264 -0
  510. package/dist-lib/plugins/coding/session.d.ts +6 -4
  511. package/dist-lib/plugins/coding/session.js +45 -16
  512. package/dist-lib/plugins/coding-guards/index.d.ts +25 -0
  513. package/dist-lib/plugins/coding-guards/index.js +126 -0
  514. package/dist-lib/plugins/command-hooks/index.js +5 -3
  515. package/dist-lib/plugins/egress-proxy/index.d.ts +53 -0
  516. package/dist-lib/plugins/egress-proxy/index.js +184 -0
  517. package/dist-lib/plugins/image/edit-image.d.ts +3 -22
  518. package/dist-lib/plugins/image/edit-image.js +23 -46
  519. package/dist-lib/plugins/image/fit.d.ts +31 -0
  520. package/dist-lib/plugins/image/fit.js +28 -0
  521. package/dist-lib/plugins/image/generate-image.d.ts +27 -6
  522. package/dist-lib/plugins/image/generate-image.js +201 -74
  523. package/dist-lib/plugins/image/index.d.ts +2 -1
  524. package/dist-lib/plugins/image/index.js +29 -12
  525. package/dist-lib/plugins/knowledge/index.d.ts +3 -0
  526. package/dist-lib/plugins/knowledge/index.js +5 -0
  527. package/dist-lib/plugins/knowledge/manifest.d.ts +53 -0
  528. package/dist-lib/plugins/knowledge/manifest.js +86 -0
  529. package/dist-lib/plugins/knowledge/search-tool.js +8 -8
  530. package/dist-lib/plugins/knowledge/store.d.ts +45 -8
  531. package/dist-lib/plugins/knowledge/store.js +428 -166
  532. package/dist-lib/plugins/language-hint/index.d.ts +15 -0
  533. package/dist-lib/plugins/language-hint/index.js +54 -0
  534. package/dist-lib/plugins/lsp/tool.js +2 -2
  535. package/dist-lib/plugins/mcp/call.js +15 -4
  536. package/dist-lib/plugins/mcp/index.js +6 -3
  537. package/dist-lib/plugins/mcp/protocol.d.ts +10 -2
  538. package/dist-lib/plugins/mcp/protocol.js +13 -12
  539. package/dist-lib/plugins/mcp/server.js +1 -1
  540. package/dist-lib/plugins/mcp/tool-listing.d.ts +6 -0
  541. package/dist-lib/plugins/mcp/tool-listing.js +97 -0
  542. package/dist-lib/plugins/music/generate-music.d.ts +24 -5
  543. package/dist-lib/plugins/music/generate-music.js +170 -64
  544. package/dist-lib/plugins/music/index.d.ts +2 -1
  545. package/dist-lib/plugins/music/index.js +23 -11
  546. package/dist-lib/plugins/obsidian/command.js +2 -2
  547. package/dist-lib/plugins/obsidian/index.js +14 -4
  548. package/dist-lib/plugins/obsidian/note-name.js +2 -1
  549. package/dist-lib/plugins/obsidian/readiness.js +2 -2
  550. package/dist-lib/plugins/obsidian/safe-path.js +5 -4
  551. package/dist-lib/plugins/obsidian/vault-create.js +3 -2
  552. package/dist-lib/plugins/obsidian/vault-fs.js +2 -2
  553. package/dist-lib/plugins/obsidian/vault-paths.js +3 -2
  554. package/dist-lib/plugins/obsidian/vault-read.js +20 -18
  555. package/dist-lib/plugins/obsidian/vault-write.js +13 -12
  556. package/dist-lib/plugins/ocr/bmp.d.ts +2 -0
  557. package/dist-lib/plugins/ocr/bmp.js +27 -0
  558. package/dist-lib/plugins/ocr/coverage.d.ts +3 -0
  559. package/dist-lib/plugins/ocr/coverage.js +67 -0
  560. package/dist-lib/plugins/ocr/index.d.ts +12 -0
  561. package/dist-lib/plugins/ocr/index.js +20 -0
  562. package/dist-lib/plugins/ocr/ocr-runtime.d.ts +25 -0
  563. package/dist-lib/plugins/ocr/ocr-runtime.js +103 -0
  564. package/dist-lib/plugins/ocr/reading-order.d.ts +5 -0
  565. package/dist-lib/plugins/ocr/reading-order.js +218 -0
  566. package/dist-lib/plugins/python/bare-floor.d.ts +1 -0
  567. package/dist-lib/plugins/python/bare-floor.js +2 -0
  568. package/dist-lib/plugins/python/guarded-fetch.d.ts +2 -1
  569. package/dist-lib/plugins/python/guarded-fetch.js +5 -1
  570. package/dist-lib/plugins/python/index.d.ts +4 -1
  571. package/dist-lib/plugins/python/index.js +6 -1
  572. package/dist-lib/plugins/python/interrupt-timer.js +2 -2
  573. package/dist-lib/plugins/python/language.js +11 -10
  574. package/dist-lib/plugins/python/loader.d.ts +1 -0
  575. package/dist-lib/plugins/python/loader.js +76 -3
  576. package/dist-lib/plugins/python/memfs.js +2 -2
  577. package/dist-lib/plugins/python/pyodide.d.ts +1 -0
  578. package/dist-lib/plugins/python/pyodide.js +9 -8
  579. package/dist-lib/plugins/python/python-adapter.d.ts +6 -1
  580. package/dist-lib/plugins/python/python-adapter.js +37 -2
  581. package/dist-lib/plugins/python/run-session.d.ts +1 -0
  582. package/dist-lib/plugins/python/run-session.js +19 -8
  583. package/dist-lib/plugins/python/wheels.js +8 -6
  584. package/dist-lib/plugins/python/worker/active.js +2 -2
  585. package/dist-lib/plugins/python/worker/client.js +10 -9
  586. package/dist-lib/plugins/python/worker/entry.js +2 -8
  587. package/dist-lib/plugins/python/worker/preload.d.ts +1 -0
  588. package/dist-lib/plugins/python/worker/preload.js +2 -0
  589. package/dist-lib/plugins/python/worker/protocol.d.ts +2 -0
  590. package/dist-lib/plugins/python/worker/serve.js +23 -4
  591. package/dist-lib/plugins/python/worker/spawn.d.ts +2 -1
  592. package/dist-lib/plugins/python/worker/spawn.js +3 -2
  593. package/dist-lib/plugins/quickjs/index.js +4 -0
  594. package/dist-lib/plugins/quickjs/runtime.js +8 -3
  595. package/dist-lib/plugins/run-report/chain.d.ts +2 -0
  596. package/dist-lib/plugins/run-report/chain.js +73 -0
  597. package/dist-lib/plugins/run-report/flow-view.js +2 -1
  598. package/dist-lib/plugins/run-report/flow.d.ts +1 -1
  599. package/dist-lib/plugins/run-report/flow.js +66 -14
  600. package/dist-lib/plugins/run-report/index.d.ts +23 -2
  601. package/dist-lib/plugins/run-report/index.js +32 -13
  602. package/dist-lib/plugins/run-report/layout.js +1 -1
  603. package/dist-lib/plugins/run-report/model.d.ts +10 -1
  604. package/dist-lib/plugins/run-report/model.js +12 -6
  605. package/dist-lib/plugins/run-report/page.d.ts +9 -0
  606. package/dist-lib/plugins/run-report/page.js +55 -15
  607. package/dist-lib/plugins/run-report/script.js +317 -43
  608. package/dist-lib/plugins/run-report/story.d.ts +2 -1
  609. package/dist-lib/plugins/run-report/story.js +7 -4
  610. package/dist-lib/plugins/run-report/style.d.ts +1 -1
  611. package/dist-lib/plugins/run-report/style.js +126 -0
  612. package/dist-lib/plugins/run-report/why.js +1 -1
  613. package/dist-lib/plugins/sandbox-linux/index.d.ts +62 -0
  614. package/dist-lib/plugins/sandbox-linux/index.js +354 -0
  615. package/dist-lib/plugins/sandbox-linux/seccomp.d.ts +2 -0
  616. package/dist-lib/plugins/sandbox-linux/seccomp.js +74 -0
  617. package/dist-lib/plugins/sandbox-macos/index.d.ts +25 -11
  618. package/dist-lib/plugins/sandbox-macos/index.js +244 -49
  619. package/dist-lib/plugins/sandbox-vm/index.d.ts +2 -1
  620. package/dist-lib/plugins/sandbox-vm/index.js +5 -2
  621. package/dist-lib/plugins/sandbox-vm/vm-shell.d.ts +7 -3
  622. package/dist-lib/plugins/sandbox-vm/vm-shell.js +54 -20
  623. package/dist-lib/plugins/sandbox-windows/helper/qvac-sandbox.c +554 -0
  624. package/dist-lib/plugins/sandbox-windows/index.d.ts +53 -0
  625. package/dist-lib/plugins/sandbox-windows/index.js +205 -0
  626. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  627. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  628. package/dist-lib/plugins/speech/audio-resample.d.ts +1 -1
  629. package/dist-lib/plugins/speech/audio-resample.js +8 -8
  630. package/dist-lib/plugins/speech/audio-transcode-bare.d.ts +1 -1
  631. package/dist-lib/plugins/speech/audio-transcode-bare.js +23 -26
  632. package/dist-lib/plugins/speech/audio-transcode-node.d.ts +1 -1
  633. package/dist-lib/plugins/speech/audio-transcode-node.js +1 -3
  634. package/dist-lib/plugins/speech/index.d.ts +1 -0
  635. package/dist-lib/plugins/speech/index.js +8 -1
  636. package/dist-lib/plugins/speech/speech-engine.d.ts +1 -1
  637. package/dist-lib/plugins/speech/speech-engine.js +10 -5
  638. package/dist-lib/plugins/speech/speech-runtime.js +37 -37
  639. package/dist-lib/plugins/speech/speech-text.d.ts +1 -0
  640. package/dist-lib/plugins/speech/speech-text.js +9 -4
  641. package/dist-lib/plugins/speech/voice.d.ts +5 -1
  642. package/dist-lib/plugins/speech/voice.js +107 -33
  643. package/dist-lib/plugins/translation/index.d.ts +2 -1
  644. package/dist-lib/plugins/translation/index.js +21 -10
  645. package/dist-lib/plugins/translation/translate.d.ts +9 -5
  646. package/dist-lib/plugins/translation/translate.js +69 -64
  647. package/dist-lib/plugins/walkie-talkie/index.d.ts +4 -2
  648. package/dist-lib/plugins/walkie-talkie/index.js +19 -6
  649. package/dist-lib/plugins/walkie-talkie/wire.d.ts +5 -0
  650. package/dist-lib/plugins/walkie-talkie/wire.js +6 -5
  651. package/dist-lib/plugins/weather/geocode.js +2 -1
  652. package/dist-lib/plugins/weather/lookup.js +6 -4
  653. package/dist-lib/plugins/web-search/engines/bing.js +2 -1
  654. package/dist-lib/plugins/web-search/engines/google.js +2 -1
  655. package/dist-lib/plugins/web-search/fetch-html.d.ts +5 -5
  656. package/dist-lib/plugins/web-search/fetch-html.js +12 -15
  657. package/dist-lib/plugins/web-search/tool.js +1 -0
  658. package/dist-lib/schema/generate.js +8 -1
  659. package/dist-lib/schema/harness.js +94 -12
  660. package/dist-lib/spec/bind.js +12 -0
  661. package/dist-lib/spec/calls.js +4 -0
  662. package/dist-lib/spec/hrpc/hrpc.json +55 -3
  663. package/dist-lib/spec/hrpc/index.js +58 -10
  664. package/dist-lib/spec/hrpc/messages.js +485 -209
  665. package/dist-lib/spec/hyperschema/index.js +485 -209
  666. package/dist-lib/spec/hyperschema/schema.json +290 -85
  667. package/dist-lib/spec/hyperschema/types.d.ts +42 -5
  668. package/package.json +265 -65
  669. package/patches/pyodide@314.0.2.patch +37 -8
  670. package/scripts/addon-externals.cjs +16 -5
  671. package/worker/harness-sidecar.mjs +23 -154
  672. package/dist-lib/lib/tools/create-documents.d.ts +0 -3
  673. package/dist-lib/lib/tools/create-documents.js +0 -95
  674. package/dist-lib/lib/tools/edit-documents.d.ts +0 -3
  675. package/dist-lib/lib/tools/edit-documents.js +0 -132
  676. package/dist-lib/lib/tools/exec/shell-argv.d.ts +0 -2
  677. package/dist-lib/lib/tools/exec/shell-argv.js +0 -61
  678. package/dist-lib/lib/tools/file-glob.js +0 -118
  679. package/dist-lib/lib/tools/grep.d.ts +0 -5
  680. package/dist-lib/lib/tools/grep.js +0 -184
  681. package/dist-lib/lib/tools/read-files.d.ts +0 -5
  682. package/dist-lib/lib/tools/read-files.js +0 -160
  683. package/dist-lib/plugins/coding/write-file.d.ts +0 -3
  684. package/dist-lib/plugins/coding/write-file.js +0 -52
  685. package/patches/@qvac%2Finference@0.21.0.patch +0 -67
  686. package/patches/bare-stow@0.1.5.patch +0 -68
  687. package/patches/hypercore-blob-server@1.15.0.patch +0 -15
  688. package/patches/localwatch@1.4.3.patch +0 -13
@@ -1,13 +1,10 @@
1
- import { createCreateDocumentsTool } from './create-documents.js';
2
- import { createEditDocumentsTool } from './edit-documents.js';
3
- import { createFileGlobTool } from './file-glob.js';
1
+ import { createAskUserTool } from './ask-user.js';
2
+ import { createFileTools } from './files/index.js';
4
3
  import { deniedRootsFor } from './fs/scope.js';
5
- import { createGrepTool } from './grep.js';
6
4
  import { createHttpRequestTool } from './http-request.js';
7
5
  import { createOfficeTools } from './office.js';
8
6
  import { compileOperationTools } from './operations/compile.js';
9
7
  import { createPdfTool } from './pdf.js';
10
- import { createReadFilesTool } from './read-files.js';
11
8
  import { createSkillTool } from './skill.js';
12
9
  import { stageInputs } from './attachments/staging.js';
13
10
  import { ensureBundledSkillsDir } from './skills/bundled-dir.js';
@@ -18,7 +15,7 @@ export class Tools {
18
15
  static bundledSkillsDir = ensureBundledSkillsDir;
19
16
  static stageInputs = stageInputs;
20
17
  static operations = compileOperationTools;
21
- static product({ sdkHome, skillsDir, skillCatalog, credentialStore }) {
18
+ static product({ sdkHome, skillsDir, skillCatalog, credentialStore, files = true, ask = false }) {
22
19
  const deniedRoots = deniedRootsFor(sdkHome);
23
20
  const credentialed = skillCatalog
24
21
  ? { credentialStore, credentialAllowList: credentialAllowListFor(skillCatalog) }
@@ -27,20 +24,19 @@ export class Tools {
27
24
  const tools = [
28
25
  httpRequestTool,
29
26
  createWebFetchTool(),
30
- createReadFilesTool({ deniedRoots }),
31
- createFileGlobTool({ deniedRoots }),
32
- createGrepTool({ deniedRoots }),
33
- createCreateDocumentsTool({ deniedRoots }),
34
- createEditDocumentsTool({ deniedRoots }),
27
+ ...(files ? createFileTools({ deniedRoots }) : []),
35
28
  createPdfTool(),
36
29
  ...createOfficeTools()
37
30
  ];
38
31
  if (skillCatalog) {
39
32
  tools.push(...compileOperationTools(skillCatalog, { httpRequestTool }));
40
33
  }
41
- if (skillsDir) {
34
+ if (skillsDir || skillCatalog?.length) {
42
35
  tools.push(createSkillTool({ skillsDir }));
43
36
  }
37
+ if (ask) {
38
+ tools.push(createAskUserTool());
39
+ }
44
40
  return tools;
45
41
  }
46
42
  }
@@ -4,6 +4,7 @@ export interface OpSpec {
4
4
  readonly inches?: boolean;
5
5
  readonly query?: boolean;
6
6
  readonly aliases?: Readonly<Record<string, string>>;
7
+ readonly skipsLooks?: boolean;
7
8
  }
8
9
  export declare const PPTX_OPS: Readonly<Record<string, OpSpec>>;
9
10
  export declare const DOCX_OPS: Readonly<Record<string, OpSpec>>;
@@ -7,7 +7,11 @@ 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: {
11
+ slots: [['like', 'layout', 'at', 'title', 'body', 'image']],
12
+ aliases: { subtitle: 'body' },
13
+ skipsLooks: true
14
+ },
11
15
  addPicture: { slots: ['slide', 'image', [...BOX, 'name', 'description']], inches: true },
12
16
  addTextBox: { slots: ['slide', [...BOX, 'text', 'style', 'fill', 'name']], inches: true },
13
17
  addTable: { slots: ['slide', [...BOX, 'rows', 'header', 'name']], inches: true },
@@ -4,9 +4,10 @@ type Deck = ReturnType<typeof pptx.open>;
4
4
  type Workbook = ReturnType<typeof xlsx.open>;
5
5
  type FormatName = 'pptx' | 'docx' | 'xlsx';
6
6
  type Args = Record<string, unknown>;
7
+ export declare function bodyLines(op: Args): Args;
7
8
  export declare function shapeFor(deck: Deck, op: Args): Args;
8
9
  export declare function sheetFor(book: Workbook, op: Args, created: boolean): Args;
9
- export declare function normalizeArgs(args: Args): Args;
10
+ export declare function normalizeArgs(raw: Args): Args;
10
11
  export declare function revisedName(format: FormatName, fileName: string): string;
11
12
  export declare function createOfficeTools(): ToolDefinition[];
12
13
  export {};
@@ -1,18 +1,36 @@
1
- import b4a from 'b4a';
1
+ import { HarnessError } from '../errors.js';
2
2
  import { errorMessage, isRecord } from '../guards.js';
3
- import { docx, pptx, units, xlsx } from '../office/engine/index.js';
4
- import { stageInputs } from './attachments/staging.js';
3
+ import { DocsError, docx, pptx, units, xlsx } from '../office/engine/index.js';
4
+ import { stageInputs, uploadsAvailable } from './attachments/staging.js';
5
5
  import { checkOutputBytes, RUN_OUTPUT_BUDGET_BYTES } from './attachments/output-policy.js';
6
+ import { attachmentOf, deliveredFile, recordDelivered, sha256 } from './attachments/delivered.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
- const attachedThisTurn = new WeakMap();
9
9
  const FIRST_SHEET = /^sheet ?1$/i;
10
+ 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
11
  const SHAPE_ROLES = new Set(['title', 'subtitle', 'body']);
11
12
  const HOISTED = ['attachmentId', 'output'];
13
+ const BLOCK_POSITIONED = new Set(['insertParagraphs', 'addTable', 'addImage', 'addChart']);
14
+ const FILE_NAME = /\.\w+$/;
12
15
  const WHERE_IDS_ARE = 'copy the id from the [Attached file "…" — attachmentId: …] line or an earlier tool result';
13
16
  function isObject(value) {
14
17
  return isRecord(value) && !Array.isArray(value);
15
18
  }
19
+ const LOOK_KEY = /colou?r|background|^bg|font|style|theme|^level$/i;
20
+ function isLook(key, value) {
21
+ return value === null || LOOK_KEY.test(key);
22
+ }
23
+ const TYPED_BULLET = /^\s*[•◦▪●]\s+/;
24
+ export function bodyLines(op) {
25
+ const items = typeof op.body === 'string' ? [op.body] : op.body;
26
+ if (op.op !== 'addSlide' || !Array.isArray(items)) {
27
+ return op;
28
+ }
29
+ const body = items.flatMap((item) => typeof item === 'string'
30
+ ? item.split('\n').map((line) => line.replace(TYPED_BULLET, ''))
31
+ : [item]);
32
+ return { ...op, body };
33
+ }
16
34
  export function shapeFor(deck, op) {
17
35
  const { shape, slide } = op;
18
36
  if (typeof shape !== 'string' || SHAPE_ROLES.has(shape) || typeof slide !== 'number') {
@@ -25,6 +43,15 @@ export function shapeFor(deck, op) {
25
43
  const found = deck.read()[slide]?.shapes.find((entry) => entry.name.toLowerCase() === wanted);
26
44
  return found && found.id !== null ? { ...op, shape: found.id } : op;
27
45
  }
46
+ function positionFor(doc, op, created) {
47
+ if (!created || !BLOCK_POSITIONED.has(String(op.op)) || typeof op.at !== 'number') {
48
+ return op;
49
+ }
50
+ return op.at > doc.blockCount ? { ...op, at: doc.blockCount } : op;
51
+ }
52
+ function newDeckHint(err, created) {
53
+ return created && err instanceof DocsError && err.code === 'SLIDE_NOT_FOUND' ? NEW_DECK_HINT : '';
54
+ }
28
55
  export function sheetFor(book, op, created) {
29
56
  if (typeof op.sheet !== 'string')
30
57
  return op;
@@ -64,27 +91,34 @@ function readWorkbook(book) {
64
91
  const PPTX_FORMAT = {
65
92
  name: 'pptx',
66
93
  noun: 'PowerPoint deck',
94
+ stem: 'presentation',
67
95
  ops: PPTX_OPS,
68
96
  createKeys: ['size', 'title', 'fonts', 'colors'],
97
+ looks: ['fonts', 'colors'],
69
98
  open: (bytes) => pptx.open(bytes),
70
99
  create: (options) => pptx.create(options),
71
100
  read: (deck) => deck.read(),
72
101
  count: (deck) => ({ slides: deck.slideCount }),
73
- prepare: (deck, op) => shapeFor(deck, op)
102
+ prepare: (deck, op) => shapeFor(deck, bodyLines(op)),
103
+ retry: withoutLayout,
104
+ hint: newDeckHint
74
105
  };
75
106
  const DOCX_FORMAT = {
76
107
  name: 'docx',
77
108
  noun: 'Word document',
109
+ stem: 'document',
78
110
  ops: DOCX_OPS,
79
111
  createKeys: ['title', 'page', 'size', 'fonts'],
80
112
  open: (bytes) => docx.open(bytes),
81
113
  create: (options) => docx.create(options),
82
114
  read: (doc) => doc.read(),
83
- count: (doc) => ({ blocks: doc.blockCount })
115
+ count: (doc) => ({ blocks: doc.blockCount }),
116
+ prepare: (doc, op, created) => positionFor(doc, op, created)
84
117
  };
85
118
  const XLSX_FORMAT = {
86
119
  name: 'xlsx',
87
120
  noun: 'Excel workbook',
121
+ stem: 'workbook',
88
122
  ops: XLSX_OPS,
89
123
  createKeys: ['sheets', 'title'],
90
124
  open: (bytes) => xlsx.open(bytes),
@@ -96,13 +130,24 @@ const XLSX_FORMAT = {
96
130
  ? 'the workbook has macros, which cannot be saved as .xlsx — add a removeMacros op'
97
131
  : null
98
132
  };
99
- export function normalizeArgs(args) {
100
- if (!Array.isArray(args.ops))
133
+ export function normalizeArgs(raw) {
134
+ const blankId = raw.attachmentId === '' || raw.attachmentId === null;
135
+ const args = blankId && isObject(raw.create) ? withoutKeys(raw, ['attachmentId']) : raw;
136
+ if (!Array.isArray(args.ops)) {
101
137
  return args;
138
+ }
102
139
  const lifted = { ...args };
103
140
  const ops = [];
104
- for (const entry of args.ops) {
105
- const op = typeof entry === 'string' ? { op: entry } : entry;
141
+ const entries = args.ops.flat();
142
+ for (const [i, entry] of entries.entries()) {
143
+ if (entries[i - 1] === 'output' && entry === ':') {
144
+ continue;
145
+ }
146
+ if (entries[i - 2] === 'output' && entries[i - 1] === ':') {
147
+ lifted.output ??= typeof entry === 'string' && FILE_NAME.test(entry) ? entry : undefined;
148
+ continue;
149
+ }
150
+ const op = typeof entry === 'string' ? { op: entry } : opNamedByKey(entry);
106
151
  if (!isObject(op)) {
107
152
  ops.push(op);
108
153
  continue;
@@ -119,11 +164,27 @@ export function normalizeArgs(args) {
119
164
  lifted.create = options;
120
165
  continue;
121
166
  }
167
+ if (rest.op === 'output') {
168
+ const { op: _output, ...named } = rest;
169
+ lifted.output ??= Object.values(named).find((value) => typeof value === 'string' && FILE_NAME.test(value));
170
+ continue;
171
+ }
122
172
  ops.push(rest);
123
173
  }
124
- lifted.ops = ops;
174
+ lifted.ops = lifted.attachmentId === undefined ? ops.map(insertedWhereAsked) : ops;
125
175
  return lifted;
126
176
  }
177
+ function opNamedByKey(entry) {
178
+ if (!isObject(entry) || 'op' in entry)
179
+ return entry;
180
+ const [only, ...more] = Object.entries(entry);
181
+ return only && !more.length && isObject(only[1]) ? { ...only[1], op: only[0] } : entry;
182
+ }
183
+ function insertedWhereAsked(op) {
184
+ return isObject(op) && op.op === 'appendParagraphs' && op.at !== undefined
185
+ ? { ...op, op: 'insertParagraphs' }
186
+ : op;
187
+ }
127
188
  function parseOp(format, op, i) {
128
189
  if (!isObject(op) || typeof op.op !== 'string') {
129
190
  return `ops[${i}] must be { op, ...args }`;
@@ -133,29 +194,42 @@ function parseOp(format, op, i) {
133
194
  return `ops[${i}]: unknown op "${op.op}"; ops are ${Object.keys(format.ops).join(', ')}`;
134
195
  }
135
196
  const keys = opKeys(spec);
136
- const unknown = Object.keys(op).filter((key) => key !== 'op' && !keys.includes(key));
197
+ const extra = Object.keys(op).filter((key) => key !== 'op' && !keys.includes(key));
198
+ const skippable = spec.skipsLooks ? extra.filter((key) => isLook(key, op[key])) : [];
199
+ const unknown = extra.filter((key) => !skippable.includes(key));
137
200
  if (!unknown.length) {
138
- return { name: op.op, spec, args: withAliases(spec, op) };
201
+ const kept = Object.fromEntries(Object.entries(op).filter(([key]) => !skippable.includes(key)));
202
+ const shadowed = Object.entries(spec.aliases ?? {})
203
+ .filter(([alias, key]) => kept[alias] !== undefined && kept[key] !== undefined)
204
+ .map(([alias]) => alias);
205
+ const skipped = [...skippable, ...shadowed].map((key) => `ops[${i}].${key}`);
206
+ return { op: { name: op.op, spec, args: withAliases(spec, kept) }, skipped };
139
207
  }
140
208
  if (op.op === 'sheets' && 'name' in op && format.ops.addSheet) {
141
209
  return `ops[${i}] sheets lists the sheets and takes no arguments; to add a sheet use { op: "addSheet", name }`;
142
210
  }
143
211
  const takes = keys.length ? `it takes ${keys.join(', ')}` : 'it takes no arguments';
144
- return `ops[${i}] ${op.op} does not take ${unknown.join(', ')}; ${takes}`;
212
+ const nested = unknown.filter((key) => format.ops[key]);
213
+ const apart = nested.length
214
+ ? `; ${nested.map((name) => `{ "op": "${name}", ... }`).join(' and ')} goes in ops as its own entry, next to this one, not inside it`
215
+ : '';
216
+ return `ops[${i}] ${op.op} does not take ${unknown.join(', ')}; ${takes}${apart}`;
145
217
  }
146
218
  function parseOps(format, ops) {
147
219
  if (!Array.isArray(ops)) {
148
220
  return 'ops must be an array of { op, ...args }';
149
221
  }
150
222
  const parsed = [];
223
+ const skipped = [];
151
224
  for (const [i, op] of ops.entries()) {
152
225
  const result = parseOp(format, op, i);
153
226
  if (typeof result === 'string') {
154
227
  return result;
155
228
  }
156
- parsed.push(result);
229
+ parsed.push(result.op);
230
+ skipped.push(...result.skipped);
157
231
  }
158
- return parsed;
232
+ return { ops: parsed, skipped };
159
233
  }
160
234
  function argumentError(format, args) {
161
235
  const { attachmentId, create, output } = args;
@@ -183,24 +257,25 @@ function parseRequest(format, raw) {
183
257
  if (error) {
184
258
  return error;
185
259
  }
186
- const ops = parseOps(format, args.ops ?? []);
187
- if (typeof ops === 'string') {
188
- return ops;
260
+ const parsed = parseOps(format, args.ops ?? []);
261
+ if (typeof parsed === 'string') {
262
+ return parsed;
189
263
  }
190
264
  const attachmentId = typeof args.attachmentId === 'string' ? args.attachmentId : undefined;
191
- if (attachmentId === undefined && !ops.length) {
265
+ if (attachmentId === undefined && !parsed.ops.length && !isObject(args.create)) {
192
266
  return `nothing to read: pass the attachmentId of a ${format.noun} (${WHERE_IDS_ARE}), or ops to build one`;
193
267
  }
194
268
  return {
195
269
  attachmentId,
196
270
  create: isObject(args.create) ? args.create : undefined,
197
- ops,
198
- output: typeof args.output === 'string' ? args.output : undefined
271
+ ops: parsed.ops,
272
+ output: typeof args.output === 'string' ? args.output : undefined,
273
+ skipped: parsed.skipped
199
274
  };
200
275
  }
201
276
  async function sourceDocument(format, request, ctx) {
202
277
  if (request.attachmentId === undefined) {
203
- return { document: format.create(request.create ?? {}), fileName: null };
278
+ return createDocument(format, request.create ?? {});
204
279
  }
205
280
  const found = await ctx.fetchAttachment?.({
206
281
  attachmentId: request.attachmentId,
@@ -211,7 +286,43 @@ async function sourceDocument(format, request, ctx) {
211
286
  error: `attachment ${request.attachmentId} not found in this chat; ${WHERE_IDS_ARE}, not a file name`
212
287
  };
213
288
  }
214
- return { document: format.open(found.bytes), fileName: found.fileName };
289
+ return { document: format.open(found.bytes), fileName: found.fileName, skipped: [] };
290
+ }
291
+ function createDocument(format, options) {
292
+ try {
293
+ return { document: format.create(options), fileName: null, skipped: [] };
294
+ }
295
+ catch (err) {
296
+ const looks = (format.looks ?? []).filter((key) => options[key] !== undefined);
297
+ if (!invalidOptions(err) || !looks.length) {
298
+ throw err;
299
+ }
300
+ const plain = withoutKeys(options, looks);
301
+ const refused = looks.filter((key) => !creates(format, { ...plain, [key]: options[key] }));
302
+ return {
303
+ document: format.create(withoutKeys(options, refused)),
304
+ fileName: null,
305
+ skipped: refused.map((key) => `create.${key}`)
306
+ };
307
+ }
308
+ }
309
+ function creates(format, options) {
310
+ try {
311
+ format.create(options);
312
+ return true;
313
+ }
314
+ catch (err) {
315
+ if (!invalidOptions(err)) {
316
+ throw err;
317
+ }
318
+ return false;
319
+ }
320
+ }
321
+ function invalidOptions(err) {
322
+ return err instanceof DocsError && err.code === 'INVALID_OPTIONS';
323
+ }
324
+ function withoutKeys(args, keys) {
325
+ return Object.fromEntries(Object.entries(args).filter(([key]) => !keys.includes(key)));
215
326
  }
216
327
  export function revisedName(format, fileName) {
217
328
  const dot = fileName.lastIndexOf('.');
@@ -226,12 +337,24 @@ export function revisedName(format, fileName) {
226
337
  }
227
338
  return `${revised[1]}_revised-${Number(revised[2] ?? 1) + 1}.${format}`;
228
339
  }
229
- function outputFor(format, output, input) {
230
- if (!input)
231
- return output;
232
- if (output && output.toLowerCase() !== input.toLowerCase())
340
+ function newFileName(format, title) {
341
+ const stem = typeof title === 'string'
342
+ ? title
343
+ .toLowerCase()
344
+ .replace(/[^a-z0-9]+/g, '_')
345
+ .replace(/^_+|_+$/g, '')
346
+ .slice(0, 48)
347
+ : '';
348
+ return `${stem || format.stem}.${format.name}`;
349
+ }
350
+ function outputFor(format, { output, create }, input) {
351
+ if (!input) {
352
+ return output ?? newFileName(format, create?.title);
353
+ }
354
+ if (output && output.toLowerCase() !== input.toLowerCase()) {
233
355
  return output;
234
- return revisedName(format, input);
356
+ }
357
+ return revisedName(format.name, input);
235
358
  }
236
359
  async function imageId(ctx, id) {
237
360
  const found = await ctx.fetchAttachment?.({ attachmentId: id, meta: true, signal: ctx.signal });
@@ -246,14 +369,55 @@ async function imageInput(op, i, ctx) {
246
369
  if (!isObject(image)) {
247
370
  return { error: `ops[${i}]: image must be { attachmentId } or {}` };
248
371
  }
249
- const id = image.attachmentId;
372
+ const id = image.attachmentId ?? undefined;
250
373
  if (id !== undefined && (typeof id !== 'string' || !id)) {
251
374
  return { error: `ops[${i}]: image.attachmentId must be a non-empty string` };
252
375
  }
253
376
  return { attachmentId: id ? await imageId(ctx, id) : undefined, path: `image-${i}.png` };
254
377
  }
378
+ function takesImage(op) {
379
+ return op.spec.slots.includes('image') || op.args.image !== undefined;
380
+ }
381
+ async function withoutMissingUploads(request, ctx) {
382
+ if (!ctx.fetchAttachment || !request.ops.some((op) => idless(op) && optionalImage(op))) {
383
+ return request;
384
+ }
385
+ const available = await uploadsAvailable(ctx.fetchAttachment, {
386
+ turnImages: ctx.turnImages,
387
+ signal: ctx.signal
388
+ });
389
+ if (available === null) {
390
+ return request;
391
+ }
392
+ const uploading = await Promise.all(request.ops.map((op) => takesUpload(op, ctx)));
393
+ let uploads = 0;
394
+ const skipped = [];
395
+ const ops = request.ops.map((op, i) => {
396
+ if (!uploading[i] || uploads++ < available || !optionalImage(op)) {
397
+ return op;
398
+ }
399
+ skipped.push(`ops[${i}].image`);
400
+ return { ...op, args: withoutKeys(op.args, ['image']) };
401
+ });
402
+ return { ...request, ops, skipped: [...request.skipped, ...skipped] };
403
+ }
404
+ function idless(op) {
405
+ const { image } = op.args;
406
+ const id = isObject(image) ? image.attachmentId : image;
407
+ return takesImage(op) && (id === undefined || id === null);
408
+ }
409
+ async function takesUpload(op, ctx) {
410
+ const id = isObject(op.args.image) ? op.args.image.attachmentId : undefined;
411
+ if (typeof id !== 'string' || !id) {
412
+ return idless(op);
413
+ }
414
+ return (await imageId(ctx, id)) === undefined;
415
+ }
416
+ function optionalImage({ spec }) {
417
+ return spec.slots.some((slot) => typeof slot !== 'string' && slot.includes('image'));
418
+ }
255
419
  async function stagedImages(request, ctx) {
256
- const wanted = request.ops.flatMap((op, i) => (opKeys(op.spec).includes('image') ? [i] : []));
420
+ const wanted = request.ops.flatMap((op, i) => (takesImage(op) ? [i] : []));
257
421
  const images = new Map();
258
422
  if (!wanted.length) {
259
423
  return images;
@@ -286,9 +450,6 @@ async function stagedImages(request, ctx) {
286
450
  return images;
287
451
  }
288
452
  function saveError({ format, document, output }, ctx) {
289
- if (!output) {
290
- return `the ops changed the ${format.noun}; name the file in output`;
291
- }
292
453
  if (!output.toLowerCase().endsWith(`.${format.name}`)) {
293
454
  return `output must end in .${format.name}, got "${output}"`;
294
455
  }
@@ -300,26 +461,26 @@ function saveError({ format, document, output }, ctx) {
300
461
  }
301
462
  async function attachOutput(job, ctx) {
302
463
  const refused = saveError(job, ctx);
303
- if (refused || !job.output || !ctx.attach) {
464
+ if (refused || !ctx.attach) {
304
465
  return { error: refused ?? 'nothing to save' };
305
466
  }
306
467
  const { output, document } = job;
307
- const delivered = attachedThisTurn.get(ctx.attach) ?? new Map();
308
- const earlier = delivered.get(output.toLowerCase());
468
+ const budget = ctx.runBudget;
469
+ const earlier = deliveredFile(budget, output);
309
470
  const bytes = document.save();
310
- if (earlier && b4a.equals(earlier.bytes, bytes)) {
311
- return { attachment: earlier.attachment, repeated: true };
471
+ const hash = sha256(bytes);
472
+ if (earlier?.sha256 === hash) {
473
+ return { attachment: attachmentOf(earlier), repeated: true };
312
474
  }
313
475
  if (earlier) {
314
476
  return {
315
- error: `${earlier.attachment.fileName} is already attached with different content; save this version under a new name in output`
477
+ error: `${earlier.fileName} is already attached with different content; save this version under a new name in output`
316
478
  };
317
479
  }
318
480
  const verdict = checkOutputBytes(output, bytes, 0);
319
481
  if ('error' in verdict) {
320
482
  return verdict;
321
483
  }
322
- const budget = ctx.runBudget;
323
484
  if (budget && budget.outputBytesUsed + bytes.byteLength > RUN_OUTPUT_BUDGET_BYTES) {
324
485
  return { error: 'run output budget exceeded' };
325
486
  }
@@ -337,19 +498,19 @@ async function attachOutput(job, ctx) {
337
498
  fileName: record.fileName,
338
499
  byteLength: record.byteLength
339
500
  };
340
- delivered.set(output.toLowerCase(), { attachment, bytes });
341
- attachedThisTurn.set(ctx.attach, delivered);
501
+ recordDelivered(budget, { name: output.toLowerCase(), sha256: hash, ...attachment });
342
502
  return { attachment, repeated: false };
343
503
  }
344
504
  function runOp(document, op, input) {
345
505
  const method = Reflect.get(document, op.name);
346
506
  if (typeof method !== 'function') {
347
- throw new Error(`${op.name} is not available on this file`);
507
+ throw new HarnessError('OFFICE_OP_UNAVAILABLE', [op.name]);
348
508
  }
349
509
  return Reflect.apply(method, document, opArguments(op.spec, input, units.inches));
350
510
  }
351
511
  function runOps({ format, document, request, images }) {
352
512
  const results = [];
513
+ const skipped = [];
353
514
  const created = request.attachmentId === undefined;
354
515
  for (const [i, op] of request.ops.entries()) {
355
516
  const placed = format.prepare?.(document, op.args, created) ?? op.args;
@@ -358,10 +519,35 @@ function runOps({ format, document, request, images }) {
358
519
  results.push(runOp(document, op, input));
359
520
  }
360
521
  catch (err) {
361
- return { error: `ops[${i}] ${op.name}: ${errorMessage(err)}` };
522
+ const retry = format.retry?.(err, op, input);
523
+ const again = retry ? rerun(document, op, retry.input) : RETRY_FAILED;
524
+ if (retry && again !== RETRY_FAILED) {
525
+ results.push(again);
526
+ skipped.push(`ops[${i}].${retry.skipped}`);
527
+ continue;
528
+ }
529
+ const hint = format.hint?.(err, created) ?? '';
530
+ return { error: `ops[${i}] ${op.name}: ${errorMessage(err)}${hint}` };
362
531
  }
363
532
  }
364
- return results;
533
+ return { results, skipped };
534
+ }
535
+ const RETRY_FAILED = Symbol('retry failed');
536
+ function rerun(document, op, input) {
537
+ try {
538
+ return runOp(document, op, input);
539
+ }
540
+ catch {
541
+ return RETRY_FAILED;
542
+ }
543
+ }
544
+ function withoutLayout(err, op, input) {
545
+ const shapeMissing = err instanceof DocsError && err.code === 'SHAPE_NOT_FOUND';
546
+ if (op.name !== 'addSlide' || input.layout === undefined || !shapeMissing) {
547
+ return null;
548
+ }
549
+ const { layout: _layout, ...rest } = input;
550
+ return { input: rest, skipped: 'layout' };
365
551
  }
366
552
  function countLine(counts) {
367
553
  return Object.entries(counts)
@@ -399,6 +585,7 @@ function parameters(format) {
399
585
  items: {
400
586
  type: 'object',
401
587
  properties: { op: { type: 'string', enum: Object.keys(format.ops) } },
588
+ additionalProperties: true,
402
589
  required: ['op']
403
590
  }
404
591
  },
@@ -410,10 +597,11 @@ function parameters(format) {
410
597
  };
411
598
  }
412
599
  async function execute(format, args, ctx) {
413
- const request = parseRequest(format, args);
414
- if (typeof request === 'string') {
415
- return { error: request };
600
+ const parsed = parseRequest(format, args);
601
+ if (typeof parsed === 'string') {
602
+ return { error: parsed };
416
603
  }
604
+ const request = await withoutMissingUploads(parsed, ctx);
417
605
  if (request.attachmentId !== undefined && !ctx.fetchAttachment) {
418
606
  return { error: 'this device cannot read chat attachments' };
419
607
  }
@@ -432,36 +620,65 @@ async function execute(format, args, ctx) {
432
620
  return source;
433
621
  }
434
622
  const { document, fileName } = source;
623
+ if (!request.ops.length && request.attachmentId === undefined) {
624
+ return {
625
+ next: `No ${format.noun} exists yet, so there is nothing to open: make it in one call with create, ops and output.`
626
+ };
627
+ }
435
628
  if (!request.ops.length) {
436
629
  return { document: format.read(document) };
437
630
  }
438
- const results = runOps({ format, document, request, images });
439
- if ('error' in results) {
440
- return results;
631
+ const ran = runOps({ format, document, request, images });
632
+ if ('error' in ran) {
633
+ return ran;
441
634
  }
442
- if (!document.changed && request.attachmentId !== undefined) {
635
+ const { results } = ran;
636
+ const onlyQueries = request.ops.every(({ spec }) => spec.query);
637
+ if (onlyQueries || (!document.changed && request.attachmentId !== undefined)) {
443
638
  return { results };
444
639
  }
445
- const output = outputFor(format.name, request.output, fileName);
640
+ const output = outputFor(format, request, fileName);
446
641
  const saved = await attachOutput({ format, document, output }, ctx);
447
642
  if ('error' in saved) {
448
643
  return saved;
449
644
  }
450
645
  const { attachment, repeated } = saved;
646
+ const skipped = [...source.skipped, ...request.skipped, ...ran.skipped];
451
647
  const counts = format.count(document);
452
- const renamed = output !== request.output
648
+ const renamed = fileName !== null && output !== request.output
453
649
  ? `Saved as ${output}, so the attached ${fileName} keeps its own name. `
454
650
  : '';
651
+ const unplaced = images.size ? null : await leftOutImage(request, ctx);
455
652
  return {
456
653
  results,
457
654
  attachments: [attachment],
458
655
  ...counts,
656
+ skipped: skipped.length ? skipped : undefined,
459
657
  reply: `${attachment.fileName} — ${countLine(counts)}`,
460
658
  next: renamed +
461
659
  `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.`
660
+ afterSave(format, attachment.attachmentId, unplaced)
463
661
  };
464
662
  }
663
+ async function leftOutImage(request, ctx) {
664
+ if (ctx.turnImages?.length) {
665
+ return 'The image the user attached to their message';
666
+ }
667
+ if (request.attachmentId !== undefined || !ctx.fetchAttachment) {
668
+ return null;
669
+ }
670
+ const available = await uploadsAvailable(ctx.fetchAttachment, { signal: ctx.signal });
671
+ return available ? 'An image in this chat' : null;
672
+ }
673
+ function afterSave(format, attachmentId, unplaced) {
674
+ const reply = 'Your answer is the reply value alone, word for word.';
675
+ if (!unplaced) {
676
+ return `Do not call ${format.name} again for it. ${reply}`;
677
+ }
678
+ return (`${unplaced} is not in it. If they asked for that image in the ${format.noun}, ` +
679
+ `call ${format.name} once more with attachmentId "${attachmentId}" and one op that adds it with "image": {}. ` +
680
+ `Otherwise: ${reply}`);
681
+ }
465
682
  function createOfficeTool(format) {
466
683
  return {
467
684
  name: format.name,
@@ -1,3 +1,4 @@
1
+ import type { ToolExecuteContext } from '../../contract/index.ts';
1
2
  export interface OperationRequest {
2
3
  body?: Record<string, unknown>;
3
4
  params?: Record<string, unknown>;
@@ -10,9 +11,9 @@ export type BuilderOutcome = {
10
11
  error: string;
11
12
  };
12
13
  export interface OperationBuilder {
13
- build: (args: Record<string, unknown>) => BuilderOutcome;
14
+ build: (args: Record<string, unknown>, context?: ToolExecuteContext) => BuilderOutcome;
14
15
  }
15
- export declare const BUILDER_POLICY_VERSION = 1;
16
- export declare const BUILDER_NAMES: readonly ['gmail-send', 'gmail-draft', 'gmail-get', 'calendar-meet-event', 'calendar-add-meet', 'docs-create', 'docs-append-text', 'sheets-create', 'sheets-write-values', 'sheets-append-values', 'drive-create-folder', 'drive-trash', 'notion-create-page', 'notion-insert-content'];
16
+ export declare const BUILDER_POLICY_VERSION = 3;
17
+ export declare const BUILDER_NAMES: readonly ['gmail-send', 'gmail-draft', 'gmail-get', 'calendar-list-events', 'calendar-list-calendars', 'calendar-meet-event', 'calendar-add-meet', 'docs-create', 'docs-append-text', 'sheets-create', 'sheets-write-values', 'sheets-append-values', 'drive-create-folder', 'drive-trash', 'notion-create-page', 'notion-insert-content'];
17
18
  export type BuilderName = (typeof BUILDER_NAMES)[number];
18
19
  export declare const BUILDERS: Record<BuilderName, OperationBuilder>;