stitchkit 0.135.0 → 0.136.0

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 (380) hide show
  1. package/CHANGELOG.md +117 -0
  2. package/README.md +25 -11
  3. package/dist/agent-executor/acp/v1-session-build.d.ts +51 -0
  4. package/dist/agent-executor/acp/v1-session-build.d.ts.map +1 -0
  5. package/dist/agent-executor/acp/v1-session.d.ts +1 -1
  6. package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
  7. package/dist/agent-executor/claude/classify.d.ts +1 -1
  8. package/dist/agent-executor/claude/classify.d.ts.map +1 -1
  9. package/dist/agent-executor/claude/events-wire.d.ts +13 -0
  10. package/dist/agent-executor/claude/events-wire.d.ts.map +1 -0
  11. package/dist/agent-executor/claude/events.d.ts +1 -11
  12. package/dist/agent-executor/claude/events.d.ts.map +1 -1
  13. package/dist/agent-executor/codex/protocol.d.ts +0 -143
  14. package/dist/agent-executor/codex/protocol.d.ts.map +1 -1
  15. package/dist/agent-executor/codex/request-answers.d.ts +1 -1
  16. package/dist/agent-executor/codex/request-answers.d.ts.map +1 -1
  17. package/dist/agent-executor/codex/server-requests.d.ts +150 -0
  18. package/dist/agent-executor/codex/server-requests.d.ts.map +1 -0
  19. package/dist/agent-executor/image-input.d.ts +10 -3
  20. package/dist/agent-executor/image-input.d.ts.map +1 -1
  21. package/dist/agent-executor/testing/replay-scenarios.d.ts.map +1 -1
  22. package/dist/agent-executor/testing/replay-transcript.d.ts.map +1 -1
  23. package/dist/agent-runtime/browser/browser-control-contract.d.ts +4 -0
  24. package/dist/agent-runtime/browser/browser-control-contract.d.ts.map +1 -1
  25. package/dist/agent-runtime/browser/control-schema.d.ts +4 -0
  26. package/dist/agent-runtime/browser/control-schema.d.ts.map +1 -1
  27. package/dist/agent-runtime/browser/control-view.d.ts.map +1 -1
  28. package/dist/agent-runtime/event-schema.d.ts +16 -3
  29. package/dist/agent-runtime/event-schema.d.ts.map +1 -1
  30. package/dist/agent-runtime/loop/deferred-tools.d.ts.map +1 -1
  31. package/dist/agent-runtime/loop/invocation-payload.d.ts.map +1 -1
  32. package/dist/agent-runtime/loop/invocation-stream.d.ts +9 -1
  33. package/dist/agent-runtime/loop/invocation-stream.d.ts.map +1 -1
  34. package/dist/agent-runtime/loop/provider-stream-parts.d.ts +6 -0
  35. package/dist/agent-runtime/loop/provider-stream-parts.d.ts.map +1 -1
  36. package/dist/agent-runtime/loop/provider-stream-segments.d.ts +1 -1
  37. package/dist/agent-runtime/loop/provider-stream-segments.d.ts.map +1 -1
  38. package/dist/agent-runtime/loop/run-acquisition.d.ts.map +1 -1
  39. package/dist/agent-runtime/loop/run-approval-signature.d.ts +34 -0
  40. package/dist/agent-runtime/loop/run-approval-signature.d.ts.map +1 -0
  41. package/dist/agent-runtime/loop/run-approval.d.ts +0 -28
  42. package/dist/agent-runtime/loop/run-approval.d.ts.map +1 -1
  43. package/dist/agent-runtime/loop/run-complete-port.d.ts +24 -0
  44. package/dist/agent-runtime/loop/run-complete-port.d.ts.map +1 -0
  45. package/dist/agent-runtime/loop/run-complete-stream.d.ts +7 -2
  46. package/dist/agent-runtime/loop/run-complete-stream.d.ts.map +1 -1
  47. package/dist/agent-runtime/loop/run-complete-types.d.ts +14 -1
  48. package/dist/agent-runtime/loop/run-complete-types.d.ts.map +1 -1
  49. package/dist/agent-runtime/loop/run-complete.d.ts +2 -2
  50. package/dist/agent-runtime/loop/run-complete.d.ts.map +1 -1
  51. package/dist/agent-runtime/loop/run-execution-state.d.ts +8 -0
  52. package/dist/agent-runtime/loop/run-execution-state.d.ts.map +1 -1
  53. package/dist/agent-runtime/loop/run-model-call.d.ts +44 -0
  54. package/dist/agent-runtime/loop/run-model-call.d.ts.map +1 -0
  55. package/dist/agent-runtime/loop/run-model-step.d.ts +25 -28
  56. package/dist/agent-runtime/loop/run-model-step.d.ts.map +1 -1
  57. package/dist/agent-runtime/loop/run-model-steps.d.ts +6 -0
  58. package/dist/agent-runtime/loop/run-model-steps.d.ts.map +1 -0
  59. package/dist/agent-runtime/loop/run-model-stream.d.ts +3 -1
  60. package/dist/agent-runtime/loop/run-model-stream.d.ts.map +1 -1
  61. package/dist/agent-runtime/loop/run-operation-lifecycle.d.ts +0 -2
  62. package/dist/agent-runtime/loop/run-operation-lifecycle.d.ts.map +1 -1
  63. package/dist/agent-runtime/loop/run-step-loop.d.ts +19 -0
  64. package/dist/agent-runtime/loop/run-step-loop.d.ts.map +1 -0
  65. package/dist/agent-runtime/loop/run-step-port.d.ts +175 -0
  66. package/dist/agent-runtime/loop/run-step-port.d.ts.map +1 -0
  67. package/dist/agent-runtime/loop/run-stream-parts.d.ts.map +1 -1
  68. package/dist/agent-runtime/loop/run-stream-step-text.d.ts.map +1 -1
  69. package/dist/agent-runtime/loop/run-tool-approval-flow.d.ts +2 -1
  70. package/dist/agent-runtime/loop/run-tool-approval-flow.d.ts.map +1 -1
  71. package/dist/agent-runtime/loop/run-tool-call-input.d.ts +39 -0
  72. package/dist/agent-runtime/loop/run-tool-call-input.d.ts.map +1 -0
  73. package/dist/agent-runtime/loop/run-tool-call.d.ts +2 -31
  74. package/dist/agent-runtime/loop/run-tool-call.d.ts.map +1 -1
  75. package/dist/agent-runtime/loop/run-tool-errors.d.ts +5 -0
  76. package/dist/agent-runtime/loop/run-tool-errors.d.ts.map +1 -1
  77. package/dist/agent-runtime/loop/run-tool-executor.d.ts +1 -1
  78. package/dist/agent-runtime/loop/run-tool-executor.d.ts.map +1 -1
  79. package/dist/agent-runtime/loop/run-tool-slots.d.ts +2 -1
  80. package/dist/agent-runtime/loop/run-tool-slots.d.ts.map +1 -1
  81. package/dist/agent-runtime/loop/runtime-state.d.ts.map +1 -1
  82. package/dist/agent-runtime/loop/runtime.d.ts +0 -5
  83. package/dist/agent-runtime/loop/runtime.d.ts.map +1 -1
  84. package/dist/agent-runtime/providers/ai-sdk-convert.d.ts +1 -5
  85. package/dist/agent-runtime/providers/ai-sdk-convert.d.ts.map +1 -1
  86. package/dist/agent-runtime/providers/ai-sdk-normalize.d.ts +11 -0
  87. package/dist/agent-runtime/providers/ai-sdk-normalize.d.ts.map +1 -0
  88. package/dist/agent-runtime/providers/ai-sdk-tools.d.ts +11 -0
  89. package/dist/agent-runtime/providers/ai-sdk-tools.d.ts.map +1 -0
  90. package/dist/agent-runtime/providers/ai-sdk.d.ts +1 -9
  91. package/dist/agent-runtime/providers/ai-sdk.d.ts.map +1 -1
  92. package/dist/agent-runtime/providers/anthropic-sse.d.ts.map +1 -1
  93. package/dist/agent-runtime/providers/openrouter-admission.d.ts.map +1 -1
  94. package/dist/agent-runtime/providers/openrouter-audio.d.ts +164 -0
  95. package/dist/agent-runtime/providers/openrouter-audio.d.ts.map +1 -0
  96. package/dist/agent-runtime/providers/openrouter-catalog-cache.d.ts.map +1 -1
  97. package/dist/agent-runtime/providers/openrouter-catalog-query.d.ts.map +1 -1
  98. package/dist/agent-runtime/providers/openrouter-catalog.d.ts +4 -2
  99. package/dist/agent-runtime/providers/openrouter-catalog.d.ts.map +1 -1
  100. package/dist/agent-runtime/providers/openrouter-client.d.ts +37 -0
  101. package/dist/agent-runtime/providers/openrouter-client.d.ts.map +1 -0
  102. package/dist/agent-runtime/providers/openrouter-http.d.ts +120 -0
  103. package/dist/agent-runtime/providers/openrouter-http.d.ts.map +1 -0
  104. package/dist/agent-runtime/providers/openrouter-media.d.ts +174 -0
  105. package/dist/agent-runtime/providers/openrouter-media.d.ts.map +1 -0
  106. package/dist/agent-runtime/providers/openrouter-models.d.ts +2 -23
  107. package/dist/agent-runtime/providers/openrouter-models.d.ts.map +1 -1
  108. package/dist/agent-runtime/providers/openrouter-options.d.ts +4 -0
  109. package/dist/agent-runtime/providers/openrouter-options.d.ts.map +1 -1
  110. package/dist/agent-runtime/providers/openrouter-request.d.ts +23 -0
  111. package/dist/agent-runtime/providers/openrouter-request.d.ts.map +1 -0
  112. package/dist/agent-runtime/providers/openrouter-response.d.ts.map +1 -1
  113. package/dist/agent-runtime/providers/openrouter-retrieval.d.ts +145 -0
  114. package/dist/agent-runtime/providers/openrouter-retrieval.d.ts.map +1 -0
  115. package/dist/agent-runtime/providers/openrouter-speech.d.ts +90 -0
  116. package/dist/agent-runtime/providers/openrouter-speech.d.ts.map +1 -0
  117. package/dist/agent-runtime/providers/openrouter-spend.d.ts +7 -3
  118. package/dist/agent-runtime/providers/openrouter-spend.d.ts.map +1 -1
  119. package/dist/agent-runtime/providers/openrouter-stream.d.ts +29 -0
  120. package/dist/agent-runtime/providers/openrouter-stream.d.ts.map +1 -0
  121. package/dist/agent-runtime/providers/openrouter-systemone.d.ts +137 -0
  122. package/dist/agent-runtime/providers/openrouter-systemone.d.ts.map +1 -0
  123. package/dist/agent-runtime/providers/openrouter-url.d.ts +19 -0
  124. package/dist/agent-runtime/providers/openrouter-url.d.ts.map +1 -0
  125. package/dist/agent-runtime/providers/openrouter-wire.d.ts +45 -0
  126. package/dist/agent-runtime/providers/openrouter-wire.d.ts.map +1 -0
  127. package/dist/agent-runtime/providers/openrouter.d.ts +5 -4
  128. package/dist/agent-runtime/providers/openrouter.d.ts.map +1 -1
  129. package/dist/agent-runtime/providers/provider-http.d.ts +29 -3
  130. package/dist/agent-runtime/providers/provider-http.d.ts.map +1 -1
  131. package/dist/agent-runtime/providers/provider-json-schema-strip.d.ts.map +1 -1
  132. package/dist/agent-runtime/providers/provider-json-schema.d.ts.map +1 -1
  133. package/dist/agent-runtime/providers/provider-openai-chat-sse.d.ts.map +1 -1
  134. package/dist/agent-runtime/providers/provider-openai-chat-state.d.ts +42 -0
  135. package/dist/agent-runtime/providers/provider-openai-chat-state.d.ts.map +1 -0
  136. package/dist/agent-runtime/providers/provider-usage.d.ts +9 -0
  137. package/dist/agent-runtime/providers/provider-usage.d.ts.map +1 -1
  138. package/dist/agent-runtime/sandbox/sandbox-bubblewrap-args.d.ts +9 -0
  139. package/dist/agent-runtime/sandbox/sandbox-bubblewrap-args.d.ts.map +1 -1
  140. package/dist/agent-runtime/sandbox/sandbox-bubblewrap.d.ts +6 -0
  141. package/dist/agent-runtime/sandbox/sandbox-bubblewrap.d.ts.map +1 -1
  142. package/dist/agent-runtime/sandbox/sandbox-contract.d.ts.map +1 -1
  143. package/dist/agent-runtime/sandbox/sandbox-process-linux.d.ts.map +1 -1
  144. package/dist/agent-runtime/sandbox/sandbox-process-spec.d.ts +5 -1
  145. package/dist/agent-runtime/sandbox/sandbox-process-spec.d.ts.map +1 -1
  146. package/dist/agent-runtime/sandbox/sandbox-process-wrapper.d.ts.map +1 -1
  147. package/dist/agent-runtime/stores/branch-messages.d.ts.map +1 -1
  148. package/dist/agent-runtime/stores/sql-rows.d.ts +10 -10
  149. package/dist/agent-runtime/terminal-commit.d.ts +10 -10
  150. package/dist/agent-runtime/testing/fault-bench.d.ts +5 -1
  151. package/dist/agent-runtime/testing/fault-bench.d.ts.map +1 -1
  152. package/dist/application/diagnostic-journal-contract.d.ts.map +1 -1
  153. package/dist/browser/client-executors.d.ts.map +1 -1
  154. package/dist/browser/client-url.d.ts.map +1 -1
  155. package/dist/contract/define.d.ts +3 -7
  156. package/dist/contract/define.d.ts.map +1 -1
  157. package/dist/contract/normalize.d.ts +17 -5
  158. package/dist/contract/normalize.d.ts.map +1 -1
  159. package/dist/entrypoints/agent-executor/acp.js +4 -2
  160. package/dist/entrypoints/agent-executor/claude-sdk.js +20 -20
  161. package/dist/entrypoints/agent-executor/claude.js +7 -7
  162. package/dist/entrypoints/agent-executor/codex.d.ts +2 -1
  163. package/dist/entrypoints/agent-executor/codex.d.ts.map +1 -1
  164. package/dist/entrypoints/agent-executor/codex.js +129 -35
  165. package/dist/entrypoints/agent-executor/testing/claude-sdk.js +2 -2
  166. package/dist/entrypoints/agent-executor/testing.js +17 -13
  167. package/dist/entrypoints/agent-executor.js +1 -1
  168. package/dist/entrypoints/agent-runtime/ai-sdk.d.ts +2 -1
  169. package/dist/entrypoints/agent-runtime/ai-sdk.d.ts.map +1 -1
  170. package/dist/entrypoints/agent-runtime/ai-sdk.js +10 -12
  171. package/dist/entrypoints/agent-runtime/anthropic.js +13 -10
  172. package/dist/entrypoints/agent-runtime/browser.js +8 -4
  173. package/dist/entrypoints/agent-runtime/harness.js +18 -19
  174. package/dist/entrypoints/agent-runtime/openai.js +5 -5
  175. package/dist/entrypoints/agent-runtime/openrouter.d.ts +11 -2
  176. package/dist/entrypoints/agent-runtime/openrouter.d.ts.map +1 -1
  177. package/dist/entrypoints/agent-runtime/openrouter.js +1940 -496
  178. package/dist/entrypoints/agent-runtime/postgres.js +2 -2
  179. package/dist/entrypoints/agent-runtime/realtime.js +5 -5
  180. package/dist/entrypoints/agent-runtime/sandbox.js +167 -139
  181. package/dist/entrypoints/agent-runtime/sqlite/bun.js +3 -3
  182. package/dist/entrypoints/agent-runtime/sqlite/node.js +3 -3
  183. package/dist/entrypoints/agent-runtime/testing.js +3 -3
  184. package/dist/entrypoints/agent-runtime.js +246 -360
  185. package/dist/entrypoints/application.js +2 -2
  186. package/dist/entrypoints/cli.js +36 -15
  187. package/dist/entrypoints/contract.js +12 -10
  188. package/dist/entrypoints/geo.js +1 -1
  189. package/dist/entrypoints/handler.js +5 -6
  190. package/dist/entrypoints/http.d.ts +2 -0
  191. package/dist/entrypoints/http.d.ts.map +1 -1
  192. package/dist/entrypoints/http.js +16 -4
  193. package/dist/entrypoints/index.js +26 -35
  194. package/dist/entrypoints/live.js +3 -3
  195. package/dist/entrypoints/node.js +7 -7
  196. package/dist/entrypoints/observability.js +9 -7
  197. package/dist/entrypoints/process.js +3 -3
  198. package/dist/entrypoints/remote.js +5 -5
  199. package/dist/entrypoints/server.js +29 -16
  200. package/dist/entrypoints/telegram/grammy.d.ts +1 -1
  201. package/dist/entrypoints/telegram/grammy.d.ts.map +1 -1
  202. package/dist/entrypoints/telegram/grammy.js +39 -5
  203. package/dist/entrypoints/telegram/screens.js +3 -0
  204. package/dist/entrypoints/telegram.d.ts +1 -1
  205. package/dist/entrypoints/telegram.d.ts.map +1 -1
  206. package/dist/entrypoints/telegram.js +19 -6
  207. package/dist/entrypoints/testing.js +10 -11
  208. package/dist/entrypoints/tools/agent.js +8 -9
  209. package/dist/entrypoints/tools/connections.js +27 -57
  210. package/dist/entrypoints/tools/contract.js +4 -4
  211. package/dist/entrypoints/tools/invoker.js +7 -8
  212. package/dist/entrypoints/tools/mcp.js +9 -10
  213. package/dist/entrypoints/tools/toolkit.js +11 -12
  214. package/dist/entrypoints/tools.js +20 -20
  215. package/dist/entrypoints/tracking/contract.js +1 -1
  216. package/dist/entrypoints/tracking/performance.js +1 -1
  217. package/dist/entrypoints/tracking.js +1 -1
  218. package/dist/{index-3czc3ykr.js → index-08a3qfr8.js} +1 -1
  219. package/dist/{index-grhhsrd5.js → index-1en7k3q5.js} +2 -1
  220. package/dist/{index-pdcbjd6a.js → index-1yky29qg.js} +6 -3
  221. package/dist/{index-b4c9dpzm.js → index-252den5a.js} +10 -11
  222. package/dist/{index-xtby8rj3.js → index-28kbdn63.js} +5 -47
  223. package/dist/{index-57sbckhv.js → index-36mtj8xm.js} +2 -2
  224. package/dist/{index-dm84tsd5.js → index-3kb8dw48.js} +1 -1
  225. package/dist/index-3tb82xr7.js +11 -0
  226. package/dist/{index-c24bj2r1.js → index-4243301z.js} +2 -2
  227. package/dist/{index-nr4fhfn4.js → index-4p2zx593.js} +2 -0
  228. package/dist/{index-q86qnzzf.js → index-54wp467c.js} +4 -4
  229. package/dist/{index-mcv7b2n0.js → index-63ctzjp4.js} +497 -495
  230. package/dist/{index-y0a4gt1s.js → index-65p8v81y.js} +3 -2
  231. package/dist/{index-z72vazf5.js → index-6y3eae97.js} +27 -83
  232. package/dist/{index-5awtbyns.js → index-9vj869rx.js} +1 -1
  233. package/dist/{index-5q0qpw3v.js → index-aqm7e864.js} +23 -8
  234. package/dist/{index-d4at0q09.js → index-b9mj31q7.js} +90 -88
  235. package/dist/{index-baba8ehy.js → index-bjrcbcn2.js} +2 -2
  236. package/dist/{index-fsw9wxk9.js → index-c9j8441q.js} +1 -103
  237. package/dist/{index-wdb5jhas.js → index-d1pdv8qc.js} +1 -1
  238. package/dist/{index-73wq9abg.js → index-df5xr2f9.js} +13 -59
  239. package/dist/{index-n9358ydy.js → index-dm50x3by.js} +1 -1
  240. package/dist/{index-zyyerdny.js → index-dmrx8xma.js} +3 -0
  241. package/dist/{index-78da4g74.js → index-dwq6a6sq.js} +17 -13
  242. package/dist/{index-9be3tf6r.js → index-e413q2cj.js} +49 -22
  243. package/dist/{index-g4gstmp1.js → index-ednf2cxs.js} +1 -1
  244. package/dist/{index-84tp547a.js → index-edpkm3k7.js} +29 -97
  245. package/dist/{index-gs0jw0hy.js → index-efbzm2se.js} +3 -3
  246. package/dist/{index-de7b0kvz.js → index-epwvp88y.js} +1 -1
  247. package/dist/{index-asnd4h2k.js → index-f0dzyskg.js} +27 -4
  248. package/dist/{index-xbb8ysmq.js → index-fatke81t.js} +2 -2
  249. package/dist/{index-6nzzj7qr.js → index-gq35s3bm.js} +1 -1
  250. package/dist/index-gvgtmt7a.js +102 -0
  251. package/dist/{index-m2b49tvc.js → index-h08xqfw9.js} +20 -21
  252. package/dist/{index-gk6dq9ay.js → index-ha1tv70k.js} +3 -26
  253. package/dist/{index-wsv11dhg.js → index-hberxns4.js} +1 -1
  254. package/dist/{index-rkphknhx.js → index-hpzhz1vm.js} +1 -1
  255. package/dist/{index-npfdymav.js → index-j5vzhj3d.js} +1 -1
  256. package/dist/{index-d3s070eh.js → index-jperyn0c.js} +1 -1
  257. package/dist/{index-yhwx4fwk.js → index-kzsetgh9.js} +1 -1
  258. package/dist/{index-x6sp5vpa.js → index-q4tr9vnf.js} +1 -1
  259. package/dist/{index-hce3hbdg.js → index-qj0sq69b.js} +6 -2
  260. package/dist/{index-v0j22shs.js → index-rg08syp1.js} +9 -6
  261. package/dist/{index-8vzh5wpv.js → index-rw1caff2.js} +14 -26
  262. package/dist/index-s8af9jqw.js +6 -0
  263. package/dist/{index-bgj9hbm3.js → index-sdppfbrh.js} +30 -16
  264. package/dist/{index-y0mwkgkf.js → index-shte29pg.js} +1086 -1055
  265. package/dist/{index-fec05c9k.js → index-ta0e2daw.js} +9 -7
  266. package/dist/{index-zfrysr1e.js → index-tb36xawm.js} +110 -75
  267. package/dist/{index-c0yym4a0.js → index-w7e402wx.js} +11 -105
  268. package/dist/{index-bvpevwt6.js → index-xnqab06h.js} +207 -202
  269. package/dist/index-xrbrvn15.js +147 -0
  270. package/dist/{index-ac3rfec5.js → index-y6wzzk2e.js} +21 -1
  271. package/dist/{index-3d2c45jn.js → index-yjx5jna7.js} +2 -2
  272. package/dist/internal/loopback-host.d.ts +8 -0
  273. package/dist/internal/loopback-host.d.ts.map +1 -0
  274. package/dist/internal/own-member.d.ts +7 -0
  275. package/dist/internal/own-member.d.ts.map +1 -0
  276. package/dist/internal/request.d.ts +17 -8
  277. package/dist/internal/request.d.ts.map +1 -1
  278. package/dist/internal/secret-shapes.d.ts +33 -4
  279. package/dist/internal/secret-shapes.d.ts.map +1 -1
  280. package/dist/json-schema/dialect.d.ts.map +1 -1
  281. package/dist/json-schema/keywords.d.ts +25 -6
  282. package/dist/json-schema/keywords.d.ts.map +1 -1
  283. package/dist/json-schema/string-format.d.ts.map +1 -1
  284. package/dist/live/events.d.ts.map +1 -1
  285. package/dist/live/watch-client.d.ts.map +1 -1
  286. package/dist/live/watch-delta.d.ts.map +1 -1
  287. package/dist/observability/context.d.ts +4 -3
  288. package/dist/observability/context.d.ts.map +1 -1
  289. package/dist/observability/sanitize.d.ts.map +1 -1
  290. package/dist/observability/secret-values.d.ts +0 -9
  291. package/dist/observability/secret-values.d.ts.map +1 -1
  292. package/dist/server/context.d.ts +3 -2
  293. package/dist/server/context.d.ts.map +1 -1
  294. package/dist/server/error-hook.d.ts +4 -3
  295. package/dist/server/error-hook.d.ts.map +1 -1
  296. package/dist/server/event-bus.d.ts.map +1 -1
  297. package/dist/server/file.d.ts +11 -3
  298. package/dist/server/file.d.ts.map +1 -1
  299. package/dist/server/handler-state.d.ts +2 -2
  300. package/dist/server/handler-state.d.ts.map +1 -1
  301. package/dist/server/middleware/jwt.d.ts +12 -1
  302. package/dist/server/middleware/jwt.d.ts.map +1 -1
  303. package/dist/server/middleware/trust-fence.d.ts +4 -0
  304. package/dist/server/middleware/trust-fence.d.ts.map +1 -1
  305. package/dist/server/multipart.d.ts +2 -3
  306. package/dist/server/multipart.d.ts.map +1 -1
  307. package/dist/server/raw.d.ts.map +1 -1
  308. package/dist/server/request-body.d.ts +12 -1
  309. package/dist/server/request-body.d.ts.map +1 -1
  310. package/dist/server/request-completion.d.ts.map +1 -1
  311. package/dist/server/types.d.ts +14 -9
  312. package/dist/server/types.d.ts.map +1 -1
  313. package/dist/telegram/crypto.d.ts.map +1 -1
  314. package/dist/telegram/init-data.d.ts +4 -4
  315. package/dist/telegram/init-data.d.ts.map +1 -1
  316. package/dist/telegram/outbound-cost.d.ts.map +1 -1
  317. package/dist/telegram/screens/test-chat.d.ts.map +1 -1
  318. package/dist/telegram/widget-api.d.ts +85 -13
  319. package/dist/telegram/widget-api.d.ts.map +1 -1
  320. package/dist/telegram/widget.d.ts +46 -2
  321. package/dist/telegram/widget.d.ts.map +1 -1
  322. package/dist/tools/cli/args-classify.d.ts +4 -74
  323. package/dist/tools/cli/args-classify.d.ts.map +1 -1
  324. package/dist/tools/cli/args-framework.d.ts +79 -0
  325. package/dist/tools/cli/args-framework.d.ts.map +1 -0
  326. package/dist/tools/cli/args-scan.d.ts.map +1 -1
  327. package/dist/tools/cli/args-tokens.d.ts.map +1 -1
  328. package/dist/tools/cli/checkpoint.d.ts +5 -0
  329. package/dist/tools/cli/checkpoint.d.ts.map +1 -1
  330. package/dist/tools/cli/stream.d.ts.map +1 -1
  331. package/dist/tools/connections/foreign-schema-join.d.ts.map +1 -1
  332. package/dist/tools/connections/openapi.d.ts.map +1 -1
  333. package/dist/tools/connections/runtime.d.ts.map +1 -1
  334. package/dist/tools/execute-handler.d.ts +24 -0
  335. package/dist/tools/execute-handler.d.ts.map +1 -0
  336. package/dist/tools/execute.d.ts.map +1 -1
  337. package/dist/tools/mcp/round.d.ts.map +1 -1
  338. package/dist/tools/schema/coerce.d.ts.map +1 -1
  339. package/dist/tools/schema/flatten.d.ts.map +1 -1
  340. package/dist/tools/schema/inline-references.d.ts.map +1 -1
  341. package/dist/tools/schema/nesting-limit.d.ts.map +1 -1
  342. package/dist/tools/schema/presentation.d.ts.map +1 -1
  343. package/dist/tracking/privacy.d.ts.map +1 -1
  344. package/llms/agent-runtime-openrouter.txt +14 -5
  345. package/llms/agent-runtime-sandbox.txt +50 -11
  346. package/llms/agent-runtime-testing.txt +1 -1
  347. package/llms/agent-runtime.2.txt +342 -230
  348. package/llms/agent-runtime.3.txt +225 -380
  349. package/llms/agent-runtime.4.txt +387 -158
  350. package/llms/agent-runtime.5.txt +157 -152
  351. package/llms/agent-runtime.6.txt +164 -0
  352. package/llms/agent-runtime.txt +307 -362
  353. package/llms/application.txt +3 -1
  354. package/llms/http.txt +1 -1
  355. package/llms/live.txt +3 -1
  356. package/llms/observability.txt +16 -9
  357. package/llms/server.2.txt +13 -8
  358. package/llms/server.4.txt +23 -11
  359. package/llms/server.5.txt +5 -5
  360. package/llms/server.txt +54 -1
  361. package/llms/spend.txt +18 -1
  362. package/llms/stitchkit.2.txt +4 -2
  363. package/llms/stitchkit.txt +113 -93
  364. package/llms/telegram-grammy.txt +3 -2
  365. package/llms/telegram.2.txt +3 -1
  366. package/llms/telegram.txt +35 -10
  367. package/llms/upgrading-0.128.0-0.129.0.txt +175 -0
  368. package/llms/{upgrading-0.128.0-0.135.0.txt → upgrading-0.130.0-0.136.0.txt} +353 -169
  369. package/llms/upgrading.txt +2 -1
  370. package/llms-full.txt +1035 -208
  371. package/llms.txt +14 -13
  372. package/package.json +6 -6
  373. package/dist/agent-runtime/loop/deferred-tools-internal.d.ts +0 -19
  374. package/dist/agent-runtime/loop/deferred-tools-internal.d.ts.map +0 -1
  375. package/dist/agent-runtime/loop/run-complete-retry.d.ts +0 -24
  376. package/dist/agent-runtime/loop/run-complete-retry.d.ts.map +0 -1
  377. package/dist/agent-runtime/loop/run-model-attempts.d.ts +0 -6
  378. package/dist/agent-runtime/loop/run-model-attempts.d.ts.map +0 -1
  379. package/dist/index-sznqf8fx.js +0 -20
  380. /package/dist/{index-fthw8dwa.js → index-4gbybjg6.js} +0 -0
@@ -1,31 +1,28 @@
1
- import {
2
- validateDeclaredOutput
3
- } from "./index-78da4g74.js";
4
1
  import {
5
2
  STANDARD_STRING_FORMATS
6
- } from "./index-gk6dq9ay.js";
3
+ } from "./index-ha1tv70k.js";
7
4
  import {
8
5
  toJsonSchema,
9
6
  jsonSchemaFields
10
- } from "./index-wdb5jhas.js";
7
+ } from "./index-d1pdv8qc.js";
11
8
  import {
12
9
  toolSurfaceOutputSchema,
13
10
  toToolName,
14
11
  assertUniqueToolName,
15
12
  buildToolPresentationSchema,
16
13
  projectedContractToolName
17
- } from "./index-84tp547a.js";
14
+ } from "./index-edpkm3k7.js";
18
15
  import {
19
16
  unwrapZodWrappers,
20
17
  objectShapeKeys,
21
18
  mergeSchemas
22
- } from "./index-n9358ydy.js";
19
+ } from "./index-dm50x3by.js";
23
20
  import {
24
21
  jsonSchemaObjectCoercionMembers
25
22
  } from "./index-dsa676h8.js";
26
23
  import {
27
24
  coerceJsonArgs2
28
- } from "./index-hce3hbdg.js";
25
+ } from "./index-qj0sq69b.js";
29
26
  import {
30
27
  isInspectOnlyLifecycle,
31
28
  inspectOnlyError,
@@ -35,7 +32,7 @@ import {
35
32
  toolCauseFromResult,
36
33
  createToolRunner,
37
34
  formatToolError
38
- } from "./index-d4at0q09.js";
35
+ } from "./index-b9mj31q7.js";
39
36
  import {
40
37
  isRepeatableRead
41
38
  } from "./index-0x4mnwg5.js";
@@ -67,16 +64,19 @@ import {
67
64
  import {
68
65
  projectJsonSafe,
69
66
  stringifyJsonSafe
70
- } from "./index-5awtbyns.js";
67
+ } from "./index-9vj869rx.js";
71
68
  import {
72
69
  collectToolSurface
73
- } from "./index-baba8ehy.js";
70
+ } from "./index-bjrcbcn2.js";
71
+ import {
72
+ validateDeclaredOutput
73
+ } from "./index-dwq6a6sq.js";
74
74
  import {
75
75
  assertNoLegacyTransports
76
76
  } from "./index-akfgymyr.js";
77
77
  import {
78
78
  HELP_SHOWN_KEYWORDS
79
- } from "./index-9be3tf6r.js";
79
+ } from "./index-e413q2cj.js";
80
80
  import {
81
81
  isUnsafeKey,
82
82
  safeJsonParse
@@ -1036,87 +1036,6 @@ function coerceCliFieldValue(info, values, label, json) {
1036
1036
  }
1037
1037
  }
1038
1038
 
1039
- // src/tools/cli/args-view.ts
1040
- function resolveCliView(flags, ascending) {
1041
- if (flags.size === 0) {
1042
- if (ascending) {
1043
- throw new CliArgumentError2("--ascending orders a record view; pass --sort with it");
1044
- }
1045
- return;
1046
- }
1047
- const countBy = flags.get("count-by");
1048
- const sum = flags.get("sum");
1049
- const table = flags.get("table");
1050
- const by = flags.get("by");
1051
- const rawTop = flags.get("top");
1052
- const named = [
1053
- ["--count-by", countBy],
1054
- ["--sum", sum]
1055
- ].filter(([, value]) => value !== undefined);
1056
- if (named.length > 1) {
1057
- throw new CliArgumentError2(`${named.map(([flag]) => flag).join(" and ")} ask for different shapes — pass one`);
1058
- }
1059
- let top;
1060
- if (rawTop !== undefined) {
1061
- top = Number(rawTop);
1062
- if (!Number.isInteger(top) || top <= 0) {
1063
- throw new CliArgumentError2("--top must be a positive whole number");
1064
- }
1065
- }
1066
- const sort = flags.get("sort");
1067
- if (table !== undefined || sort !== undefined) {
1068
- if (countBy !== undefined || sum !== undefined) {
1069
- throw new CliArgumentError2(`${table !== undefined ? "--table" : "--sort"} lists records; --count-by and --sum aggregate them — pass one`);
1070
- }
1071
- if (by !== undefined) {
1072
- throw new CliArgumentError2("--by groups a view; a record view orders with --sort");
1073
- }
1074
- if (top !== undefined && sort === undefined) {
1075
- throw new CliArgumentError2("--top needs --sort here: unordered records have no n largest");
1076
- }
1077
- let fields;
1078
- if (table !== undefined) {
1079
- fields = table.split(",").map((field) => field.trim()).filter(Boolean);
1080
- if (fields.length === 0)
1081
- throw new CliArgumentError2("--table needs at least one field");
1082
- }
1083
- return {
1084
- kind: "records",
1085
- ...sort !== undefined && { sort },
1086
- ...ascending && { ascending },
1087
- ...top !== undefined && { top },
1088
- ...fields && { table: fields }
1089
- };
1090
- }
1091
- if (ascending) {
1092
- throw new CliArgumentError2("--ascending orders a record view; pass --sort with it");
1093
- }
1094
- if (sum !== undefined) {
1095
- if (top !== undefined && by === undefined) {
1096
- throw new CliArgumentError2("--top needs --by: a single sum has nothing to rank");
1097
- }
1098
- return {
1099
- kind: "sum",
1100
- field: sum,
1101
- ...by !== undefined && { by },
1102
- ...top !== undefined && { top }
1103
- };
1104
- }
1105
- if (countBy !== undefined) {
1106
- if (by !== undefined) {
1107
- throw new CliArgumentError2("--count-by already names the grouping field; drop --by");
1108
- }
1109
- return { kind: "count", field: countBy, ...top !== undefined && { top } };
1110
- }
1111
- if (by !== undefined) {
1112
- if (top === undefined) {
1113
- throw new CliArgumentError2("--by groups a view; pass --count-by, --sum or --top with it");
1114
- }
1115
- return { kind: "count", field: by, top };
1116
- }
1117
- throw new CliArgumentError2("--top needs --sort, --by, --count-by or --sum to rank");
1118
- }
1119
-
1120
1039
  // src/tools/cli/args-classify.ts
1121
1040
  function isOptionToken(token) {
1122
1041
  return token.startsWith("--") || /^-[A-Za-z](?:=|$)/.test(token);
@@ -1169,436 +1088,196 @@ function isOwnLeadingToken(token, appFields) {
1169
1088
  return false;
1170
1089
  return opt.globalKind !== undefined || appFields.has(cliFieldOption(opt, appFields).name);
1171
1090
  }
1172
- function deferScanError(ctx, error) {
1173
- ctx.deferredError ??= error;
1091
+
1092
+ // src/tools/cli/stream-surface.ts
1093
+ function cliStreamIdentity(serviceName, methodName, method) {
1094
+ if (!method.stream || !method.expose?.includes("CLI"))
1095
+ return;
1096
+ return { name: toToolName(serviceName, methodName), descriptor: method.stream };
1174
1097
  }
1175
- function recordAppGlobalError(ctx, error) {
1176
- ctx.appGlobalError ??= error;
1177
- deferScanError(ctx, error);
1098
+ function collectCliStreams(services) {
1099
+ const streams = new Map;
1100
+ for (const service of services) {
1101
+ for (const [methodName, method] of Object.entries(service.methods)) {
1102
+ const identity = cliStreamIdentity(service.name, methodName, method);
1103
+ if (identity === undefined)
1104
+ continue;
1105
+ const { name, descriptor } = identity;
1106
+ streams.set(name, {
1107
+ descriptor,
1108
+ tool: {
1109
+ method,
1110
+ name,
1111
+ argumentSchema: mergeSchemas(method.paramsSchema, method.inputSchema),
1112
+ presentationSchema: buildToolPresentationSchema({
1113
+ paramsSchema: method.paramsSchema,
1114
+ inputSchema: method.inputSchema,
1115
+ inputRecursionDepth: method.inputRecursionDepth,
1116
+ inputNestingDepth: method.inputNestingDepth,
1117
+ unrepresentable: "any"
1118
+ }),
1119
+ shouldExtend: false
1120
+ }
1121
+ });
1122
+ }
1123
+ }
1124
+ return streams;
1178
1125
  }
1179
- function pushRestToken(ctx, token, index) {
1180
- ctx.withoutGlobals.push(token);
1181
- ctx.withoutCommand.push(token);
1182
- ctx.withoutCommandFrom.push(index);
1126
+
1127
+ // src/tools/cli/command-shape.ts
1128
+ function nativeCliDescriptor(definition) {
1129
+ return {
1130
+ description: definition.description,
1131
+ argumentSchema: definition.input,
1132
+ presentationSchema: cliCommandPresentationSchema(definition),
1133
+ outputSchema: definition.output
1134
+ };
1183
1135
  }
1184
- function pushCommandToken(ctx, token, index) {
1185
- if ((ctx.removedAfterCmdToken || ctx.separatedInput.has(index)) && ctx.commandTokens.length > 0) {
1186
- ctx.separatedBefore.add(ctx.commandTokens.length);
1136
+ function assertNoPassthroughAlias(name, descriptor, passthroughField) {
1137
+ if (passthroughField !== undefined && descriptor.aliases.has(passthroughField)) {
1138
+ throw new Error(`[stitchkit] CLI command "${name}" cannot alias passthrough field "${passthroughField}"`);
1187
1139
  }
1188
- ctx.removedAfterCmdToken = false;
1189
- ctx.commandTokens.push(token);
1190
- pushRestToken(ctx, token, index);
1191
1140
  }
1192
- function withoutCommandSeparations(ctx) {
1193
- const separated = new Set;
1194
- ctx.withoutCommandFrom.forEach((from, at) => {
1195
- if (at > 0 && ctx.separatedInput.has(from))
1196
- separated.add(at);
1197
- });
1198
- return separated;
1141
+ function invokerCommandShapeIssue(name, descriptor, exists, passthroughField) {
1142
+ assertUniqueToolName(name, exists, "CLI command");
1143
+ assertNoPassthroughAlias(name, descriptor, passthroughField);
1144
+ return;
1199
1145
  }
1200
- function markCommandTokenRemoved(ctx) {
1201
- if (ctx.commandFound)
1202
- ctx.removedAfterCmdToken = true;
1146
+ function assertCliCommandName(name) {
1147
+ if (isReservedCliCommandName(name)) {
1148
+ throw new Error(`[stitchkit] CLI command "${name}" is reserved. Rename the command to a word outside the option syntax.`);
1149
+ }
1203
1150
  }
1204
- function tryReadAppGlobalToken(ctx, index, opt, raw, jsonFields) {
1205
- if (!opt || opt.globalKind !== undefined)
1206
- return -1;
1207
- const appField = cliFieldOption(opt, ctx.appFields);
1208
- const info = ctx.appFields.get(appField.name);
1209
- if (!info)
1210
- return -1;
1211
- if (ctx.bareBool)
1212
- ctx.bareBool.removedAfter = true;
1213
- let { value } = opt;
1214
- let nextIndex = index;
1215
- if (value === undefined && info.kind === "boolean") {
1216
- const sep = separateBoolValue(ctx.argv[index + 1]);
1217
- if (sep !== undefined)
1218
- nextIndex++;
1219
- value = String(sep ?? true);
1220
- } else if (value === undefined) {
1221
- const next = ctx.argv[index + 1];
1222
- if (next === undefined || isOptionToken(next)) {
1223
- recordAppGlobalError(ctx, new CliArgumentError2(`--${opt.name} requires a value`));
1224
- return nextIndex;
1225
- }
1226
- value = next;
1227
- nextIndex++;
1228
- } else if (info.kind === "boolean" && !appField.json) {
1229
- if (raw.has(appField.name)) {
1230
- appendCliFieldValue(raw, jsonFields, appField.name, value, info, appField.json);
1231
- return nextIndex;
1232
- }
1233
- try {
1234
- parseReservedBool(appField.name, value);
1235
- } catch (error) {
1236
- if (error instanceof CliArgumentError2)
1237
- recordAppGlobalError(ctx, error);
1238
- else
1239
- throw error;
1151
+ function assertStaticCliCommandNames(services, runtimeTools) {
1152
+ for (const tool of runtimeTools) {
1153
+ assertNoLegacyTransports(tool, `Runtime tool "${tool.name}"`);
1154
+ if (tool.expose?.includes("CLI"))
1155
+ assertCliCommandName(tool.name);
1156
+ }
1157
+ for (const service of services) {
1158
+ for (const [key, method] of Object.entries(service.methods)) {
1159
+ const name = projectedContractToolName(service.name, key, method, "CLI") ?? cliStreamIdentity(service.name, key, method)?.name;
1160
+ if (name !== undefined)
1161
+ assertCliCommandName(name);
1240
1162
  }
1241
1163
  }
1242
- appendCliFieldValue(raw, jsonFields, appField.name, value, info, appField.json);
1243
- return nextIndex;
1244
1164
  }
1245
- function reservedJsonTarget(opt) {
1246
- if (!opt?.inline || !opt.name.endsWith(":"))
1165
+ function commandShapeIssue(name, descriptor, exists, passthroughField, applicationGlobals = new Set) {
1166
+ assertUniqueToolName(name, exists, "CLI command");
1167
+ assertCliCommandName(name);
1168
+ assertNoPassthroughAlias(name, descriptor, passthroughField);
1169
+ const fieldNames = jsonSchemaFields(descriptor.presentationSchema).map((field) => field.name);
1170
+ const conflicting = fieldNames.filter((field) => RESERVED_CLI_OPTIONS.has(field));
1171
+ if (conflicting.length > 0) {
1172
+ return `[stitchkit] CLI command "${name}" declares reserved option field(s): ${conflicting.join(", ")}`;
1173
+ }
1174
+ const shadowed = fieldNames.filter((field) => applicationGlobals.has(field));
1175
+ if (shadowed.length > 0) {
1176
+ return `[stitchkit] CLI command "${name}" declares field(s) shadowed by application global options: ${shadowed.join(", ")}`;
1177
+ }
1178
+ }
1179
+
1180
+ // src/tools/cli/policy.ts
1181
+ var REMOVED_TOP_LEVEL_KEYS = [
1182
+ "optionAliases",
1183
+ "positionals",
1184
+ "results",
1185
+ "passthrough",
1186
+ "wait"
1187
+ ];
1188
+ function assertNoLegacyCliPolicyKeys(config) {
1189
+ if (typeof config !== "object" || config === null)
1247
1190
  return;
1248
- const target = opt.name.slice(0, -1);
1249
- return RESERVED_CLI_OPTIONS.has(target) ? target : undefined;
1191
+ for (const key of REMOVED_TOP_LEVEL_KEYS) {
1192
+ if (Object.hasOwn(config, key)) {
1193
+ throw new TypeError(`[stitchkit] CLI option "${key}" was moved into "commandSettings.<command>" — migrate to commandSettings`);
1194
+ }
1195
+ }
1250
1196
  }
1251
- function consumeFrameworkOptionToken(argv, index, opt, state, callbacks) {
1252
- const adjacent = callbacks.adjacent ?? (() => true);
1253
- const report = (error) => {
1254
- if (opt.name === "schema") {
1255
- state.fw.schema = false;
1256
- state.schemaInvalid = true;
1257
- } else if (opt.name === "help")
1258
- state.fw.help = false;
1259
- callbacks.onError(error);
1260
- };
1261
- const record = (name, raw, kind) => {
1262
- try {
1263
- appendCliOptionValue(state.fwFlags, name, raw, { kind });
1264
- return true;
1265
- } catch (error) {
1266
- if (error instanceof CliArgumentError2) {
1267
- report(error);
1268
- return false;
1269
- }
1270
- throw error;
1271
- }
1272
- };
1273
- let nextIdx = index;
1274
- if (opt.globalKind === "boolean") {
1275
- const following = argv[index + 1];
1276
- if (!opt.inline && !adjacent(index + 1) && following !== undefined && separateBoolValue(following) !== undefined) {
1277
- report(brokenBooleanBoundaryError(opt.name, following));
1278
- if (opt.name === "help" || opt.name === "schema")
1279
- return nextIdx;
1197
+ var SHORT_ALIAS = /^[A-Za-z]$/;
1198
+ var RESERVED_SHORT_OPTIONS = new Set(["h"]);
1199
+ function fieldMap(descriptor) {
1200
+ return new Map(jsonSchemaFields(descriptor.presentationSchema).map((field) => [field.name, field]));
1201
+ }
1202
+ function resolveAliases(command, descriptor, configured) {
1203
+ if (!configured)
1204
+ return new Map;
1205
+ const fields = fieldMap(descriptor);
1206
+ const aliases = new Map;
1207
+ for (const [alias, target] of Object.entries(configured)) {
1208
+ if (!SHORT_ALIAS.test(alias)) {
1209
+ throw new Error(`[stitchkit] CLI command "${command}" alias "${alias}" must be one ASCII letter`);
1280
1210
  }
1281
- const nextTok = adjacent(index + 1) ? following : undefined;
1282
- const sep = opt.inline ? undefined : separateBoolValue(nextTok);
1283
- if (sep !== undefined && nextTok !== undefined) {
1284
- nextIdx++;
1285
- callbacks.onValueToken?.(nextTok);
1211
+ if (RESERVED_SHORT_OPTIONS.has(alias)) {
1212
+ throw new Error(`[stitchkit] CLI command "${command}" alias "-${alias}" is reserved`);
1286
1213
  }
1287
- const rawValue = opt.value ?? String(sep ?? true);
1288
- if (opt.name !== "help" && !record(opt.name, rawValue, "boolean"))
1289
- return nextIdx;
1290
- let enabled;
1291
- if (opt.inline) {
1292
- try {
1293
- enabled = parseReservedBool(opt.name, opt.value ?? "");
1294
- } catch (error) {
1295
- if (error instanceof CliArgumentError2) {
1296
- report(error);
1297
- return nextIdx;
1298
- }
1299
- throw error;
1300
- }
1301
- } else {
1302
- enabled = sep ?? true;
1214
+ if (isUnsafeKey(target) || !fields.has(target)) {
1215
+ throw new Error(`[stitchkit] CLI command "${command}" alias "-${alias}" targets unknown field "${target}"`);
1303
1216
  }
1304
- if (!opt.inline && sep === undefined)
1305
- callbacks.onBareBoolean?.(opt.name);
1306
- if (opt.name === "dry-run")
1307
- state.fw.dryRun = enabled;
1308
- else if (opt.name === "json")
1309
- state.fw.json = enabled;
1310
- else if (opt.name === "wait")
1311
- state.fw.wait = enabled;
1312
- else if (opt.name === "quiet")
1313
- state.fw.quiet = enabled;
1314
- else if (opt.name === "ascending")
1315
- state.ascending = enabled;
1316
- else if (opt.name === "schema") {
1317
- state.fw.schema = !state.schemaInvalid && (state.fw.schema || enabled);
1318
- } else if (opt.name === "help")
1319
- state.fw.help = state.fw.help || enabled;
1320
- return nextIdx;
1321
- }
1322
- let value = opt.value;
1323
- if (!opt.inline) {
1324
- const next = adjacent(index + 1) ? argv[index + 1] : undefined;
1325
- if (next === undefined || isOptionToken(next)) {
1326
- report(new CliArgumentError2(`--${opt.name} requires a value`));
1327
- if (callbacks.onMissingValue?.(next))
1328
- nextIdx++;
1329
- } else {
1330
- value = next;
1331
- nextIdx++;
1332
- callbacks.onValueToken?.(next);
1217
+ const existing = aliases.get(target);
1218
+ if (existing !== undefined) {
1219
+ throw new Error(`[stitchkit] CLI command "${command}" field "${target}" has multiple aliases: -${existing}, -${alias}`);
1333
1220
  }
1221
+ aliases.set(target, alias);
1334
1222
  }
1335
- if (value !== undefined) {
1336
- if (!record(opt.name, value, "string"))
1337
- return nextIdx;
1338
- if (opt.name === "wait-timeout") {
1339
- const n = Number(value);
1340
- if (!Number.isFinite(n) || n <= 0) {
1341
- report(new CliArgumentError2("--wait-timeout must be a positive number"));
1342
- } else {
1343
- state.fw.waitTimeout = n;
1344
- }
1345
- } else if (VIEW_OPTIONS.has(opt.name))
1346
- state.viewFlags.set(opt.name, value);
1347
- else
1348
- state.fw.outputDir = value;
1349
- }
1350
- return nextIdx;
1351
- }
1352
- function readFrameworkOptionToken(ctx, index, token, opt) {
1353
- ctx.bareBool = undefined;
1354
- pushRestToken(ctx, token, index);
1355
- return consumeFrameworkOptionToken(ctx.argv, index, opt, ctx, {
1356
- adjacent: (at) => !ctx.separatedInput.has(at),
1357
- onError: (error) => deferScanError(ctx, error),
1358
- onValueToken: (valueToken) => pushRestToken(ctx, valueToken, index + 1),
1359
- onBareBoolean: (name) => {
1360
- ctx.bareBool = { name, removedAfter: false };
1361
- },
1362
- onMissingValue: (next) => {
1363
- if (!ctx.commandFound && next !== undefined && !isOwnLeadingToken(next, ctx.appFields)) {
1364
- pushRestToken(ctx, next, index + 1);
1365
- return true;
1366
- }
1367
- return false;
1368
- }
1369
- });
1223
+ return aliases;
1370
1224
  }
1371
- function finalizeFrameworkView(ctx) {
1372
- if (ctx.viewFlags.size === 0 && !ctx.ascending)
1225
+ function resolvePositionals(command, descriptor, configured) {
1226
+ if (configured === undefined)
1373
1227
  return;
1374
- try {
1375
- ctx.fw.view = resolveCliView(ctx.viewFlags, ctx.ascending);
1376
- } catch (error) {
1377
- if (error instanceof CliArgumentError2)
1378
- deferScanError(ctx, error);
1379
- else
1380
- throw error;
1228
+ const fields = fieldMap(descriptor);
1229
+ const kinds = describeSchemaFields(descriptor.argumentSchema);
1230
+ const seen = new Set;
1231
+ let optionalSeen = false;
1232
+ for (const name of configured) {
1233
+ const field = fields.get(name);
1234
+ if (isUnsafeKey(name) || !field || !kinds.has(name)) {
1235
+ throw new Error(`[stitchkit] CLI command "${command}" positional targets unknown field "${name}"`);
1236
+ }
1237
+ if (seen.has(name)) {
1238
+ throw new Error(`[stitchkit] CLI command "${command}" repeats positional field "${name}"`);
1239
+ }
1240
+ if (kinds.get(name)?.kind === "boolean") {
1241
+ throw new Error(`[stitchkit] CLI command "${command}" boolean field "${name}" cannot be positional`);
1242
+ }
1243
+ if (optionalSeen && field.required) {
1244
+ throw new Error(`[stitchkit] CLI command "${command}" required positional "${name}" cannot follow an optional positional`);
1245
+ }
1246
+ if (!field.required)
1247
+ optionalSeen = true;
1248
+ seen.add(name);
1381
1249
  }
1250
+ return [...configured];
1382
1251
  }
1383
- function createFrameworkStepContext(argv, appFields, separatedInput = new Set) {
1384
- return {
1385
- argv,
1386
- appFields,
1387
- fwFlags: new Map,
1388
- viewFlags: new Map,
1389
- fw: { json: false, quiet: false, help: false, schema: false, dryRun: false, wait: false },
1390
- ascending: false,
1391
- commandFound: false,
1392
- withoutGlobals: [],
1393
- withoutCommand: [],
1394
- withoutCommandFrom: [],
1395
- commandTokens: [],
1396
- separatedBefore: new Set,
1397
- removedAfterCmdToken: false,
1398
- separatedInput
1399
- };
1400
- }
1401
- function coerceAppGlobalMap(raw, fields, jsonFields) {
1402
- const coerced = {};
1403
- for (const [name, values] of raw) {
1404
- coerced[name] = coerceCliFieldValue(fields.get(name), values, `--${name}`, jsonFields.has(name));
1405
- }
1406
- return coerced;
1252
+ function cliCommandSettingsFor(config, command) {
1253
+ return config.commandSettings && Object.hasOwn(config.commandSettings, command) ? config.commandSettings[command] : undefined;
1407
1254
  }
1408
- function brokenBooleanBoundaryError(flagName, word) {
1409
- const flag = flagName.startsWith("-") ? flagName : `--${flagName}`;
1410
- return new CliArgumentError2(`Bare ${flag} cannot be separated from "${word}" — use ${flag}=true, ${flag}=false or "-- ${word}"`);
1255
+ function cliResultPolicy(config, command) {
1256
+ return cliCommandSettingsFor(config, command)?.result;
1411
1257
  }
1412
-
1413
- // src/tools/cli/stream-surface.ts
1414
- function cliStreamIdentity(serviceName, methodName, method) {
1415
- if (!method.stream || !method.expose?.includes("CLI"))
1416
- return;
1417
- return { name: toToolName(serviceName, methodName), descriptor: method.stream };
1258
+ function cliPassthroughField(config, command) {
1259
+ return cliCommandSettingsFor(config, command)?.passthrough;
1418
1260
  }
1419
- function collectCliStreams(services) {
1420
- const streams = new Map;
1421
- for (const service of services) {
1422
- for (const [methodName, method] of Object.entries(service.methods)) {
1423
- const identity = cliStreamIdentity(service.name, methodName, method);
1424
- if (identity === undefined)
1425
- continue;
1426
- const { name, descriptor } = identity;
1427
- streams.set(name, {
1428
- descriptor,
1429
- tool: {
1430
- method,
1431
- name,
1432
- argumentSchema: mergeSchemas(method.paramsSchema, method.inputSchema),
1433
- presentationSchema: buildToolPresentationSchema({
1434
- paramsSchema: method.paramsSchema,
1435
- inputSchema: method.inputSchema,
1436
- inputRecursionDepth: method.inputRecursionDepth,
1437
- inputNestingDepth: method.inputNestingDepth,
1438
- unrepresentable: "any"
1439
- }),
1440
- shouldExtend: false
1441
- }
1442
- });
1443
- }
1444
- }
1445
- return streams;
1261
+ function cliWaitConfig(config, command) {
1262
+ return cliCommandSettingsFor(config, command)?.wait;
1446
1263
  }
1447
-
1448
- // src/tools/cli/command-shape.ts
1449
- function nativeCliDescriptor(definition) {
1264
+ function applyCliPresentationPolicy(command, descriptor, config) {
1265
+ const base = { ...descriptor, aliases: new Map };
1266
+ const settings = cliCommandSettingsFor(config, command);
1450
1267
  return {
1451
- description: definition.description,
1452
- argumentSchema: definition.input,
1453
- presentationSchema: cliCommandPresentationSchema(definition),
1454
- outputSchema: definition.output
1268
+ ...base,
1269
+ aliases: resolveAliases(command, base, settings?.aliases),
1270
+ positionals: resolvePositionals(command, base, settings?.positionals)
1455
1271
  };
1456
1272
  }
1457
- function assertNoPassthroughAlias(name, descriptor, passthroughField) {
1458
- if (passthroughField !== undefined && descriptor.aliases.has(passthroughField)) {
1459
- throw new Error(`[stitchkit] CLI command "${name}" cannot alias passthrough field "${passthroughField}"`);
1460
- }
1461
- }
1462
- function invokerCommandShapeIssue(name, descriptor, exists, passthroughField) {
1463
- assertUniqueToolName(name, exists, "CLI command");
1464
- assertNoPassthroughAlias(name, descriptor, passthroughField);
1465
- return;
1466
- }
1467
- function assertCliCommandName(name) {
1468
- if (isReservedCliCommandName(name)) {
1469
- throw new Error(`[stitchkit] CLI command "${name}" is reserved. Rename the command to a word outside the option syntax.`);
1470
- }
1471
- }
1472
- function assertStaticCliCommandNames(services, runtimeTools) {
1473
- for (const tool of runtimeTools) {
1474
- assertNoLegacyTransports(tool, `Runtime tool "${tool.name}"`);
1475
- if (tool.expose?.includes("CLI"))
1476
- assertCliCommandName(tool.name);
1477
- }
1478
- for (const service of services) {
1479
- for (const [key, method] of Object.entries(service.methods)) {
1480
- const name = projectedContractToolName(service.name, key, method, "CLI") ?? cliStreamIdentity(service.name, key, method)?.name;
1481
- if (name !== undefined)
1482
- assertCliCommandName(name);
1483
- }
1484
- }
1485
- }
1486
- function commandShapeIssue(name, descriptor, exists, passthroughField, applicationGlobals = new Set) {
1487
- assertUniqueToolName(name, exists, "CLI command");
1488
- assertCliCommandName(name);
1489
- assertNoPassthroughAlias(name, descriptor, passthroughField);
1490
- const fieldNames = jsonSchemaFields(descriptor.presentationSchema).map((field) => field.name);
1491
- const conflicting = fieldNames.filter((field) => RESERVED_CLI_OPTIONS.has(field));
1492
- if (conflicting.length > 0) {
1493
- return `[stitchkit] CLI command "${name}" declares reserved option field(s): ${conflicting.join(", ")}`;
1494
- }
1495
- const shadowed = fieldNames.filter((field) => applicationGlobals.has(field));
1496
- if (shadowed.length > 0) {
1497
- return `[stitchkit] CLI command "${name}" declares field(s) shadowed by application global options: ${shadowed.join(", ")}`;
1498
- }
1499
- }
1500
-
1501
- // src/tools/cli/policy.ts
1502
- var REMOVED_TOP_LEVEL_KEYS = [
1503
- "optionAliases",
1504
- "positionals",
1505
- "results",
1506
- "passthrough",
1507
- "wait"
1508
- ];
1509
- function assertNoLegacyCliPolicyKeys(config) {
1510
- if (typeof config !== "object" || config === null)
1511
- return;
1512
- for (const key of REMOVED_TOP_LEVEL_KEYS) {
1513
- if (Object.hasOwn(config, key)) {
1514
- throw new TypeError(`[stitchkit] CLI option "${key}" was moved into "commandSettings.<command>" — migrate to commandSettings`);
1515
- }
1516
- }
1517
- }
1518
- var SHORT_ALIAS = /^[A-Za-z]$/;
1519
- var RESERVED_SHORT_OPTIONS = new Set(["h"]);
1520
- function fieldMap(descriptor) {
1521
- return new Map(jsonSchemaFields(descriptor.presentationSchema).map((field) => [field.name, field]));
1522
- }
1523
- function resolveAliases(command, descriptor, configured) {
1524
- if (!configured)
1525
- return new Map;
1526
- const fields = fieldMap(descriptor);
1527
- const aliases = new Map;
1528
- for (const [alias, target] of Object.entries(configured)) {
1529
- if (!SHORT_ALIAS.test(alias)) {
1530
- throw new Error(`[stitchkit] CLI command "${command}" alias "${alias}" must be one ASCII letter`);
1531
- }
1532
- if (RESERVED_SHORT_OPTIONS.has(alias)) {
1533
- throw new Error(`[stitchkit] CLI command "${command}" alias "-${alias}" is reserved`);
1534
- }
1535
- if (isUnsafeKey(target) || !fields.has(target)) {
1536
- throw new Error(`[stitchkit] CLI command "${command}" alias "-${alias}" targets unknown field "${target}"`);
1537
- }
1538
- const existing = aliases.get(target);
1539
- if (existing !== undefined) {
1540
- throw new Error(`[stitchkit] CLI command "${command}" field "${target}" has multiple aliases: -${existing}, -${alias}`);
1541
- }
1542
- aliases.set(target, alias);
1543
- }
1544
- return aliases;
1545
- }
1546
- function resolvePositionals(command, descriptor, configured) {
1547
- if (configured === undefined)
1548
- return;
1549
- const fields = fieldMap(descriptor);
1550
- const kinds = describeSchemaFields(descriptor.argumentSchema);
1551
- const seen = new Set;
1552
- let optionalSeen = false;
1553
- for (const name of configured) {
1554
- const field = fields.get(name);
1555
- if (isUnsafeKey(name) || !field || !kinds.has(name)) {
1556
- throw new Error(`[stitchkit] CLI command "${command}" positional targets unknown field "${name}"`);
1557
- }
1558
- if (seen.has(name)) {
1559
- throw new Error(`[stitchkit] CLI command "${command}" repeats positional field "${name}"`);
1560
- }
1561
- if (kinds.get(name)?.kind === "boolean") {
1562
- throw new Error(`[stitchkit] CLI command "${command}" boolean field "${name}" cannot be positional`);
1563
- }
1564
- if (optionalSeen && field.required) {
1565
- throw new Error(`[stitchkit] CLI command "${command}" required positional "${name}" cannot follow an optional positional`);
1566
- }
1567
- if (!field.required)
1568
- optionalSeen = true;
1569
- seen.add(name);
1570
- }
1571
- return [...configured];
1572
- }
1573
- function cliCommandSettingsFor(config, command) {
1574
- return config.commandSettings && Object.hasOwn(config.commandSettings, command) ? config.commandSettings[command] : undefined;
1575
- }
1576
- function cliResultPolicy(config, command) {
1577
- return cliCommandSettingsFor(config, command)?.result;
1578
- }
1579
- function cliPassthroughField(config, command) {
1580
- return cliCommandSettingsFor(config, command)?.passthrough;
1581
- }
1582
- function cliWaitConfig(config, command) {
1583
- return cliCommandSettingsFor(config, command)?.wait;
1584
- }
1585
- function applyCliPresentationPolicy(command, descriptor, config) {
1586
- const base = { ...descriptor, aliases: new Map };
1587
- const settings = cliCommandSettingsFor(config, command);
1588
- return {
1589
- ...base,
1590
- aliases: resolveAliases(command, base, settings?.aliases),
1591
- positionals: resolvePositionals(command, base, settings?.positionals)
1592
- };
1593
- }
1594
- function assertCliPoliciesResolved(commands, config) {
1595
- const configuredNames = new Set(Object.keys(config.commandSettings ?? {}));
1596
- if (config.defaultCommand !== undefined)
1597
- configuredNames.add(config.defaultCommand);
1598
- for (const name of configuredNames) {
1599
- if (!commands.has(name)) {
1600
- throw new Error(`[stitchkit] CLI policy targets unavailable command "${name}"`);
1601
- }
1273
+ function assertCliPoliciesResolved(commands, config) {
1274
+ const configuredNames = new Set(Object.keys(config.commandSettings ?? {}));
1275
+ if (config.defaultCommand !== undefined)
1276
+ configuredNames.add(config.defaultCommand);
1277
+ for (const name of configuredNames) {
1278
+ if (!commands.has(name)) {
1279
+ throw new Error(`[stitchkit] CLI policy targets unavailable command "${name}"`);
1280
+ }
1602
1281
  }
1603
1282
  }
1604
1283
 
@@ -1985,6 +1664,329 @@ function createCliIo(config) {
1985
1664
  // src/tools/cli/notices.ts
1986
1665
  import { AsyncLocalStorage } from "node:async_hooks";
1987
1666
 
1667
+ // src/tools/cli/args-view.ts
1668
+ function resolveCliView(flags, ascending) {
1669
+ if (flags.size === 0) {
1670
+ if (ascending) {
1671
+ throw new CliArgumentError2("--ascending orders a record view; pass --sort with it");
1672
+ }
1673
+ return;
1674
+ }
1675
+ const countBy = flags.get("count-by");
1676
+ const sum = flags.get("sum");
1677
+ const table = flags.get("table");
1678
+ const by = flags.get("by");
1679
+ const rawTop = flags.get("top");
1680
+ const named = [
1681
+ ["--count-by", countBy],
1682
+ ["--sum", sum]
1683
+ ].filter(([, value]) => value !== undefined);
1684
+ if (named.length > 1) {
1685
+ throw new CliArgumentError2(`${named.map(([flag]) => flag).join(" and ")} ask for different shapes — pass one`);
1686
+ }
1687
+ let top;
1688
+ if (rawTop !== undefined) {
1689
+ top = Number(rawTop);
1690
+ if (!Number.isInteger(top) || top <= 0) {
1691
+ throw new CliArgumentError2("--top must be a positive whole number");
1692
+ }
1693
+ }
1694
+ const sort = flags.get("sort");
1695
+ if (table !== undefined || sort !== undefined) {
1696
+ if (countBy !== undefined || sum !== undefined) {
1697
+ throw new CliArgumentError2(`${table !== undefined ? "--table" : "--sort"} lists records; --count-by and --sum aggregate them — pass one`);
1698
+ }
1699
+ if (by !== undefined) {
1700
+ throw new CliArgumentError2("--by groups a view; a record view orders with --sort");
1701
+ }
1702
+ if (top !== undefined && sort === undefined) {
1703
+ throw new CliArgumentError2("--top needs --sort here: unordered records have no n largest");
1704
+ }
1705
+ let fields;
1706
+ if (table !== undefined) {
1707
+ fields = table.split(",").map((field) => field.trim()).filter(Boolean);
1708
+ if (fields.length === 0)
1709
+ throw new CliArgumentError2("--table needs at least one field");
1710
+ }
1711
+ return {
1712
+ kind: "records",
1713
+ ...sort !== undefined && { sort },
1714
+ ...ascending && { ascending },
1715
+ ...top !== undefined && { top },
1716
+ ...fields && { table: fields }
1717
+ };
1718
+ }
1719
+ if (ascending) {
1720
+ throw new CliArgumentError2("--ascending orders a record view; pass --sort with it");
1721
+ }
1722
+ if (sum !== undefined) {
1723
+ if (top !== undefined && by === undefined) {
1724
+ throw new CliArgumentError2("--top needs --by: a single sum has nothing to rank");
1725
+ }
1726
+ return {
1727
+ kind: "sum",
1728
+ field: sum,
1729
+ ...by !== undefined && { by },
1730
+ ...top !== undefined && { top }
1731
+ };
1732
+ }
1733
+ if (countBy !== undefined) {
1734
+ if (by !== undefined) {
1735
+ throw new CliArgumentError2("--count-by already names the grouping field; drop --by");
1736
+ }
1737
+ return { kind: "count", field: countBy, ...top !== undefined && { top } };
1738
+ }
1739
+ if (by !== undefined) {
1740
+ if (top === undefined) {
1741
+ throw new CliArgumentError2("--by groups a view; pass --count-by, --sum or --top with it");
1742
+ }
1743
+ return { kind: "count", field: by, top };
1744
+ }
1745
+ throw new CliArgumentError2("--top needs --sort, --by, --count-by or --sum to rank");
1746
+ }
1747
+
1748
+ // src/tools/cli/args-framework.ts
1749
+ function deferScanError(ctx, error) {
1750
+ ctx.deferredError ??= error;
1751
+ }
1752
+ function recordAppGlobalError(ctx, error) {
1753
+ ctx.appGlobalError ??= error;
1754
+ deferScanError(ctx, error);
1755
+ }
1756
+ function pushRestToken(ctx, token, index) {
1757
+ ctx.withoutGlobals.push(token);
1758
+ ctx.withoutCommand.push(token);
1759
+ ctx.withoutCommandFrom.push(index);
1760
+ }
1761
+ function pushCommandToken(ctx, token, index) {
1762
+ if ((ctx.removedAfterCmdToken || ctx.separatedInput.has(index)) && ctx.commandTokens.length > 0) {
1763
+ ctx.separatedBefore.add(ctx.commandTokens.length);
1764
+ }
1765
+ ctx.removedAfterCmdToken = false;
1766
+ ctx.commandTokens.push(token);
1767
+ pushRestToken(ctx, token, index);
1768
+ }
1769
+ function withoutCommandSeparations(ctx) {
1770
+ const separated = new Set;
1771
+ ctx.withoutCommandFrom.forEach((from, at) => {
1772
+ if (at > 0 && ctx.separatedInput.has(from))
1773
+ separated.add(at);
1774
+ });
1775
+ return separated;
1776
+ }
1777
+ function markCommandTokenRemoved(ctx) {
1778
+ if (ctx.commandFound)
1779
+ ctx.removedAfterCmdToken = true;
1780
+ }
1781
+ function tryReadAppGlobalToken(ctx, index, opt, raw, jsonFields) {
1782
+ if (!opt || opt.globalKind !== undefined)
1783
+ return -1;
1784
+ const appField = cliFieldOption(opt, ctx.appFields);
1785
+ const info = ctx.appFields.get(appField.name);
1786
+ if (!info)
1787
+ return -1;
1788
+ if (ctx.bareBool)
1789
+ ctx.bareBool.removedAfter = true;
1790
+ let { value } = opt;
1791
+ let nextIndex = index;
1792
+ if (value === undefined && info.kind === "boolean") {
1793
+ const sep = separateBoolValue(ctx.argv[index + 1]);
1794
+ if (sep !== undefined)
1795
+ nextIndex++;
1796
+ value = String(sep ?? true);
1797
+ } else if (value === undefined) {
1798
+ const next = ctx.argv[index + 1];
1799
+ if (next === undefined || isOptionToken(next)) {
1800
+ recordAppGlobalError(ctx, new CliArgumentError2(`--${opt.name} requires a value`));
1801
+ return nextIndex;
1802
+ }
1803
+ value = next;
1804
+ nextIndex++;
1805
+ } else if (info.kind === "boolean" && !appField.json) {
1806
+ if (raw.has(appField.name)) {
1807
+ appendCliFieldValue(raw, jsonFields, appField.name, value, info, appField.json);
1808
+ return nextIndex;
1809
+ }
1810
+ try {
1811
+ parseReservedBool(appField.name, value);
1812
+ } catch (error) {
1813
+ if (error instanceof CliArgumentError2)
1814
+ recordAppGlobalError(ctx, error);
1815
+ else
1816
+ throw error;
1817
+ }
1818
+ }
1819
+ appendCliFieldValue(raw, jsonFields, appField.name, value, info, appField.json);
1820
+ return nextIndex;
1821
+ }
1822
+ function reservedJsonTarget(opt) {
1823
+ if (!opt?.inline || !opt.name.endsWith(":"))
1824
+ return;
1825
+ const target = opt.name.slice(0, -1);
1826
+ return RESERVED_CLI_OPTIONS.has(target) ? target : undefined;
1827
+ }
1828
+ function consumeFrameworkOptionToken(argv, index, opt, state, callbacks) {
1829
+ const adjacent = callbacks.adjacent ?? (() => true);
1830
+ const report = (error) => {
1831
+ if (opt.name === "schema") {
1832
+ state.fw.schema = false;
1833
+ state.schemaInvalid = true;
1834
+ } else if (opt.name === "help")
1835
+ state.fw.help = false;
1836
+ callbacks.onError(error);
1837
+ };
1838
+ const record = (name, raw, kind) => {
1839
+ try {
1840
+ appendCliOptionValue(state.fwFlags, name, raw, { kind });
1841
+ return true;
1842
+ } catch (error) {
1843
+ if (error instanceof CliArgumentError2) {
1844
+ report(error);
1845
+ return false;
1846
+ }
1847
+ throw error;
1848
+ }
1849
+ };
1850
+ let nextIdx = index;
1851
+ if (opt.globalKind === "boolean") {
1852
+ const following = argv[index + 1];
1853
+ if (!opt.inline && !adjacent(index + 1) && following !== undefined && separateBoolValue(following) !== undefined) {
1854
+ report(brokenBooleanBoundaryError(opt.name, following));
1855
+ if (opt.name === "help" || opt.name === "schema")
1856
+ return nextIdx;
1857
+ }
1858
+ const nextTok = adjacent(index + 1) ? following : undefined;
1859
+ const sep = opt.inline ? undefined : separateBoolValue(nextTok);
1860
+ if (sep !== undefined && nextTok !== undefined) {
1861
+ nextIdx++;
1862
+ callbacks.onValueToken?.(nextTok);
1863
+ }
1864
+ const rawValue = opt.value ?? String(sep ?? true);
1865
+ if (opt.name !== "help" && !record(opt.name, rawValue, "boolean"))
1866
+ return nextIdx;
1867
+ let enabled;
1868
+ if (opt.inline) {
1869
+ try {
1870
+ enabled = parseReservedBool(opt.name, opt.value ?? "");
1871
+ } catch (error) {
1872
+ if (error instanceof CliArgumentError2) {
1873
+ report(error);
1874
+ return nextIdx;
1875
+ }
1876
+ throw error;
1877
+ }
1878
+ } else {
1879
+ enabled = sep ?? true;
1880
+ }
1881
+ if (!opt.inline && sep === undefined)
1882
+ callbacks.onBareBoolean?.(opt.name);
1883
+ if (opt.name === "dry-run")
1884
+ state.fw.dryRun = enabled;
1885
+ else if (opt.name === "json")
1886
+ state.fw.json = enabled;
1887
+ else if (opt.name === "wait")
1888
+ state.fw.wait = enabled;
1889
+ else if (opt.name === "quiet")
1890
+ state.fw.quiet = enabled;
1891
+ else if (opt.name === "ascending")
1892
+ state.ascending = enabled;
1893
+ else if (opt.name === "schema") {
1894
+ state.fw.schema = !state.schemaInvalid && (state.fw.schema || enabled);
1895
+ } else if (opt.name === "help")
1896
+ state.fw.help = state.fw.help || enabled;
1897
+ return nextIdx;
1898
+ }
1899
+ let value = opt.value;
1900
+ if (!opt.inline) {
1901
+ const next = adjacent(index + 1) ? argv[index + 1] : undefined;
1902
+ if (next === undefined || isOptionToken(next)) {
1903
+ report(new CliArgumentError2(`--${opt.name} requires a value`));
1904
+ if (callbacks.onMissingValue?.(next))
1905
+ nextIdx++;
1906
+ } else {
1907
+ value = next;
1908
+ nextIdx++;
1909
+ callbacks.onValueToken?.(next);
1910
+ }
1911
+ }
1912
+ if (value !== undefined) {
1913
+ if (!record(opt.name, value, "string"))
1914
+ return nextIdx;
1915
+ if (opt.name === "wait-timeout") {
1916
+ const n = Number(value);
1917
+ if (!Number.isFinite(n) || n <= 0) {
1918
+ report(new CliArgumentError2("--wait-timeout must be a positive number"));
1919
+ } else {
1920
+ state.fw.waitTimeout = n;
1921
+ }
1922
+ } else if (VIEW_OPTIONS.has(opt.name))
1923
+ state.viewFlags.set(opt.name, value);
1924
+ else
1925
+ state.fw.outputDir = value;
1926
+ }
1927
+ return nextIdx;
1928
+ }
1929
+ function readFrameworkOptionToken(ctx, index, token, opt) {
1930
+ ctx.bareBool = undefined;
1931
+ pushRestToken(ctx, token, index);
1932
+ return consumeFrameworkOptionToken(ctx.argv, index, opt, ctx, {
1933
+ adjacent: (at) => !ctx.separatedInput.has(at),
1934
+ onError: (error) => deferScanError(ctx, error),
1935
+ onValueToken: (valueToken) => pushRestToken(ctx, valueToken, index + 1),
1936
+ onBareBoolean: (name) => {
1937
+ ctx.bareBool = { name, removedAfter: false };
1938
+ },
1939
+ onMissingValue: (next) => {
1940
+ if (!ctx.commandFound && next !== undefined && !isOwnLeadingToken(next, ctx.appFields)) {
1941
+ pushRestToken(ctx, next, index + 1);
1942
+ return true;
1943
+ }
1944
+ return false;
1945
+ }
1946
+ });
1947
+ }
1948
+ function finalizeFrameworkView(ctx) {
1949
+ if (ctx.viewFlags.size === 0 && !ctx.ascending)
1950
+ return;
1951
+ try {
1952
+ ctx.fw.view = resolveCliView(ctx.viewFlags, ctx.ascending);
1953
+ } catch (error) {
1954
+ if (error instanceof CliArgumentError2)
1955
+ deferScanError(ctx, error);
1956
+ else
1957
+ throw error;
1958
+ }
1959
+ }
1960
+ function createFrameworkStepContext(argv, appFields, separatedInput = new Set) {
1961
+ return {
1962
+ argv,
1963
+ appFields,
1964
+ fwFlags: new Map,
1965
+ viewFlags: new Map,
1966
+ fw: { json: false, quiet: false, help: false, schema: false, dryRun: false, wait: false },
1967
+ ascending: false,
1968
+ commandFound: false,
1969
+ withoutGlobals: [],
1970
+ withoutCommand: [],
1971
+ withoutCommandFrom: [],
1972
+ commandTokens: [],
1973
+ separatedBefore: new Set,
1974
+ removedAfterCmdToken: false,
1975
+ separatedInput
1976
+ };
1977
+ }
1978
+ function coerceAppGlobalMap(raw, fields, jsonFields) {
1979
+ const coerced = {};
1980
+ for (const [name, values] of raw) {
1981
+ coerced[name] = coerceCliFieldValue(fields.get(name), values, `--${name}`, jsonFields.has(name));
1982
+ }
1983
+ return coerced;
1984
+ }
1985
+ function brokenBooleanBoundaryError(flagName, word) {
1986
+ const flag = flagName.startsWith("-") ? flagName : `--${flagName}`;
1987
+ return new CliArgumentError2(`Bare ${flag} cannot be separated from "${word}" — use ${flag}=true, ${flag}=false or "-- ${word}"`);
1988
+ }
1989
+
1988
1990
  // src/tools/cli/args-scan.ts
1989
1991
  var EMPTY_FIELDS = new Map;
1990
1992
  function optionBeforeCommandError(token) {