stitchkit 0.134.2 → 0.135.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 (1104) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +1 -1
  3. package/dist/agent-executor/acp/v1-connect.d.ts +1 -1
  4. package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
  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/json-rpc-peer.d.ts +1 -1
  8. package/dist/agent-executor/json-rpc-peer.d.ts.map +1 -1
  9. package/dist/agent-runtime/browser/browser-control-contract.d.ts +1364 -0
  10. package/dist/agent-runtime/browser/browser-control-contract.d.ts.map +1 -0
  11. package/dist/agent-runtime/browser/browser-controller-view.d.ts +44 -0
  12. package/dist/agent-runtime/browser/browser-controller-view.d.ts.map +1 -0
  13. package/dist/agent-runtime/browser/browser-controller.d.ts +53 -0
  14. package/dist/agent-runtime/browser/browser-controller.d.ts.map +1 -0
  15. package/dist/agent-runtime/browser/control-interaction-schema.d.ts.map +1 -0
  16. package/dist/agent-runtime/browser/control-schema.d.ts +1378 -0
  17. package/dist/agent-runtime/browser/control-schema.d.ts.map +1 -0
  18. package/dist/agent-runtime/browser/control-view.d.ts +64 -0
  19. package/dist/agent-runtime/browser/control-view.d.ts.map +1 -0
  20. package/dist/agent-runtime/browser/react.d.ts.map +1 -0
  21. package/dist/agent-runtime/coding/coding-discovery.d.ts +25 -0
  22. package/dist/agent-runtime/coding/coding-discovery.d.ts.map +1 -0
  23. package/dist/agent-runtime/coding/coding-sandbox.d.ts +8 -0
  24. package/dist/agent-runtime/coding/coding-sandbox.d.ts.map +1 -0
  25. package/dist/agent-runtime/coding/coding-search-automaton.d.ts.map +1 -0
  26. package/dist/agent-runtime/coding/coding-search-case-fold.d.ts.map +1 -0
  27. package/dist/agent-runtime/coding/coding-search-class-ranges.d.ts.map +1 -0
  28. package/dist/agent-runtime/coding/coding-search-contract.d.ts.map +1 -0
  29. package/dist/agent-runtime/coding/coding-search-limits.d.ts.map +1 -0
  30. package/dist/agent-runtime/coding/coding-search-matcher.d.ts.map +1 -0
  31. package/dist/agent-runtime/coding/coding-search-output.d.ts.map +1 -0
  32. package/dist/agent-runtime/coding/coding-search-regex-syntax.d.ts.map +1 -0
  33. package/dist/agent-runtime/coding/coding-search-unit-classes.d.ts.map +1 -0
  34. package/dist/agent-runtime/coding/coding-shell-process.d.ts +36 -0
  35. package/dist/agent-runtime/coding/coding-shell-process.d.ts.map +1 -0
  36. package/dist/agent-runtime/coding/coding-tool-contract.d.ts +261 -0
  37. package/dist/agent-runtime/coding/coding-tool-contract.d.ts.map +1 -0
  38. package/dist/agent-runtime/coding/coding-tool-files.d.ts.map +1 -0
  39. package/dist/agent-runtime/coding/coding-tool-listing.d.ts.map +1 -0
  40. package/dist/agent-runtime/coding/coding-tool-paths.d.ts +53 -0
  41. package/dist/agent-runtime/coding/coding-tool-paths.d.ts.map +1 -0
  42. package/dist/agent-runtime/coding/coding-tool-refusals.d.ts.map +1 -0
  43. package/dist/agent-runtime/coding/coding-tool-search-patch.d.ts.map +1 -0
  44. package/dist/agent-runtime/coding/coding-tool-search.d.ts +113 -0
  45. package/dist/agent-runtime/coding/coding-tool-search.d.ts.map +1 -0
  46. package/dist/agent-runtime/coding/coding-tool-shell.d.ts.map +1 -0
  47. package/dist/agent-runtime/coding/coding-tool-utf8.d.ts.map +1 -0
  48. package/dist/agent-runtime/coding/coding-tools.d.ts.map +1 -0
  49. package/dist/agent-runtime/coding/contained-scan-budget.d.ts.map +1 -0
  50. package/dist/agent-runtime/coding/contained-scan-contract.d.ts.map +1 -0
  51. package/dist/agent-runtime/coding/contained-scan.d.ts +56 -0
  52. package/dist/agent-runtime/coding/contained-scan.d.ts.map +1 -0
  53. package/dist/agent-runtime/coding/workspace-glob.d.ts.map +1 -0
  54. package/dist/agent-runtime/context-issue.d.ts +1 -1
  55. package/dist/agent-runtime/context-issue.d.ts.map +1 -1
  56. package/dist/agent-runtime/deferred-tool-types.d.ts +3 -1
  57. package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -1
  58. package/dist/agent-runtime/harness/harness-contract.d.ts +206 -0
  59. package/dist/agent-runtime/harness/harness-contract.d.ts.map +1 -0
  60. package/dist/agent-runtime/harness/harness-control.d.ts +34 -0
  61. package/dist/agent-runtime/harness/harness-control.d.ts.map +1 -0
  62. package/dist/agent-runtime/harness/harness-file-resources.d.ts +33 -0
  63. package/dist/agent-runtime/harness/harness-file-resources.d.ts.map +1 -0
  64. package/dist/agent-runtime/harness/harness-resources.d.ts.map +1 -0
  65. package/dist/agent-runtime/harness/harness.d.ts +15 -0
  66. package/dist/agent-runtime/harness/harness.d.ts.map +1 -0
  67. package/dist/agent-runtime/history/compaction.d.ts +103 -0
  68. package/dist/agent-runtime/history/compaction.d.ts.map +1 -0
  69. package/dist/agent-runtime/history/history.d.ts +93 -0
  70. package/dist/agent-runtime/history/history.d.ts.map +1 -0
  71. package/dist/agent-runtime/history/run-history-parts.d.ts +14 -0
  72. package/dist/agent-runtime/history/run-history-parts.d.ts.map +1 -0
  73. package/dist/agent-runtime/loop/admission-lanes.d.ts +35 -0
  74. package/dist/agent-runtime/loop/admission-lanes.d.ts.map +1 -0
  75. package/dist/agent-runtime/loop/coordinator.d.ts.map +1 -0
  76. package/dist/agent-runtime/loop/deferred-tool-search.d.ts +9 -0
  77. package/dist/agent-runtime/loop/deferred-tool-search.d.ts.map +1 -0
  78. package/dist/agent-runtime/loop/deferred-tool-selection.d.ts +32 -0
  79. package/dist/agent-runtime/loop/deferred-tool-selection.d.ts.map +1 -0
  80. package/dist/agent-runtime/loop/deferred-tools-internal.d.ts +19 -0
  81. package/dist/agent-runtime/loop/deferred-tools-internal.d.ts.map +1 -0
  82. package/dist/agent-runtime/loop/deferred-tools.d.ts +4 -0
  83. package/dist/agent-runtime/loop/deferred-tools.d.ts.map +1 -0
  84. package/dist/agent-runtime/loop/injection.d.ts +28 -0
  85. package/dist/agent-runtime/loop/injection.d.ts.map +1 -0
  86. package/dist/agent-runtime/loop/invocation-attempt.d.ts +32 -0
  87. package/dist/agent-runtime/loop/invocation-attempt.d.ts.map +1 -0
  88. package/dist/agent-runtime/loop/invocation-failure.d.ts.map +1 -0
  89. package/dist/agent-runtime/loop/invocation-payload.d.ts +38 -0
  90. package/dist/agent-runtime/loop/invocation-payload.d.ts.map +1 -0
  91. package/dist/agent-runtime/loop/invocation-read.d.ts +134 -0
  92. package/dist/agent-runtime/loop/invocation-read.d.ts.map +1 -0
  93. package/dist/agent-runtime/loop/invocation-spend.d.ts +9 -0
  94. package/dist/agent-runtime/loop/invocation-spend.d.ts.map +1 -0
  95. package/dist/agent-runtime/loop/invocation-stream.d.ts +20 -0
  96. package/dist/agent-runtime/loop/invocation-stream.d.ts.map +1 -0
  97. package/dist/agent-runtime/loop/invocations.d.ts +63 -0
  98. package/dist/agent-runtime/loop/invocations.d.ts.map +1 -0
  99. package/dist/agent-runtime/loop/managed-tools.d.ts +20 -0
  100. package/dist/agent-runtime/loop/managed-tools.d.ts.map +1 -0
  101. package/dist/agent-runtime/loop/observability.d.ts +579 -0
  102. package/dist/agent-runtime/loop/observability.d.ts.map +1 -0
  103. package/dist/agent-runtime/loop/owned-provider-stream.d.ts.map +1 -0
  104. package/dist/agent-runtime/loop/provider-origin.d.ts +17 -0
  105. package/dist/agent-runtime/loop/provider-origin.d.ts.map +1 -0
  106. package/dist/agent-runtime/loop/provider-stream-parts.d.ts +5 -0
  107. package/dist/agent-runtime/loop/provider-stream-parts.d.ts.map +1 -0
  108. package/dist/agent-runtime/loop/provider-stream-segments.d.ts +63 -0
  109. package/dist/agent-runtime/loop/provider-stream-segments.d.ts.map +1 -0
  110. package/dist/agent-runtime/loop/retry-policy.d.ts +49 -0
  111. package/dist/agent-runtime/loop/retry-policy.d.ts.map +1 -0
  112. package/dist/agent-runtime/loop/run-acquisition.d.ts +24 -0
  113. package/dist/agent-runtime/loop/run-acquisition.d.ts.map +1 -0
  114. package/dist/agent-runtime/loop/run-approval.d.ts +82 -0
  115. package/dist/agent-runtime/loop/run-approval.d.ts.map +1 -0
  116. package/dist/agent-runtime/loop/run-complete-retry.d.ts +24 -0
  117. package/dist/agent-runtime/loop/run-complete-retry.d.ts.map +1 -0
  118. package/dist/agent-runtime/loop/run-complete-stream.d.ts +9 -0
  119. package/dist/agent-runtime/loop/run-complete-stream.d.ts.map +1 -0
  120. package/dist/agent-runtime/loop/run-complete-types.d.ts +171 -0
  121. package/dist/agent-runtime/loop/run-complete-types.d.ts.map +1 -0
  122. package/dist/agent-runtime/loop/run-complete.d.ts +25 -0
  123. package/dist/agent-runtime/loop/run-complete.d.ts.map +1 -0
  124. package/dist/agent-runtime/loop/run-driver-compose.d.ts +21 -0
  125. package/dist/agent-runtime/loop/run-driver-compose.d.ts.map +1 -0
  126. package/dist/agent-runtime/loop/run-execution-state.d.ts +177 -0
  127. package/dist/agent-runtime/loop/run-execution-state.d.ts.map +1 -0
  128. package/dist/agent-runtime/loop/run-execution.d.ts +22 -0
  129. package/dist/agent-runtime/loop/run-execution.d.ts.map +1 -0
  130. package/dist/agent-runtime/loop/run-failure.d.ts +21 -0
  131. package/dist/agent-runtime/loop/run-failure.d.ts.map +1 -0
  132. package/dist/agent-runtime/loop/run-loop-events.d.ts +126 -0
  133. package/dist/agent-runtime/loop/run-loop-events.d.ts.map +1 -0
  134. package/dist/agent-runtime/loop/run-model-attempts.d.ts +6 -0
  135. package/dist/agent-runtime/loop/run-model-attempts.d.ts.map +1 -0
  136. package/dist/agent-runtime/loop/run-model-messages.d.ts +9 -0
  137. package/dist/agent-runtime/loop/run-model-messages.d.ts.map +1 -0
  138. package/dist/agent-runtime/loop/run-model-step.d.ts +43 -0
  139. package/dist/agent-runtime/loop/run-model-step.d.ts.map +1 -0
  140. package/dist/agent-runtime/loop/run-model-stream.d.ts +27 -0
  141. package/dist/agent-runtime/loop/run-model-stream.d.ts.map +1 -0
  142. package/dist/agent-runtime/loop/run-operation-lifecycle.d.ts +32 -0
  143. package/dist/agent-runtime/loop/run-operation-lifecycle.d.ts.map +1 -0
  144. package/dist/agent-runtime/loop/run-prompt-history.d.ts +53 -0
  145. package/dist/agent-runtime/loop/run-prompt-history.d.ts.map +1 -0
  146. package/dist/agent-runtime/loop/run-provider-ledger.d.ts +32 -0
  147. package/dist/agent-runtime/loop/run-provider-ledger.d.ts.map +1 -0
  148. package/dist/agent-runtime/loop/run-step-barriers.d.ts +120 -0
  149. package/dist/agent-runtime/loop/run-step-barriers.d.ts.map +1 -0
  150. package/dist/agent-runtime/loop/run-step-helpers.d.ts +50 -0
  151. package/dist/agent-runtime/loop/run-step-helpers.d.ts.map +1 -0
  152. package/dist/agent-runtime/loop/run-step-prepare.d.ts +34 -0
  153. package/dist/agent-runtime/loop/run-step-prepare.d.ts.map +1 -0
  154. package/dist/agent-runtime/loop/run-step-spend.d.ts +394 -0
  155. package/dist/agent-runtime/loop/run-step-spend.d.ts.map +1 -0
  156. package/dist/agent-runtime/loop/run-stream-parts.d.ts +34 -0
  157. package/dist/agent-runtime/loop/run-stream-parts.d.ts.map +1 -0
  158. package/dist/agent-runtime/loop/run-stream-recorded.d.ts +8 -0
  159. package/dist/agent-runtime/loop/run-stream-recorded.d.ts.map +1 -0
  160. package/dist/agent-runtime/loop/run-stream-step-text.d.ts +47 -0
  161. package/dist/agent-runtime/loop/run-stream-step-text.d.ts.map +1 -0
  162. package/dist/agent-runtime/loop/run-terminal.d.ts +11 -0
  163. package/dist/agent-runtime/loop/run-terminal.d.ts.map +1 -0
  164. package/dist/agent-runtime/loop/run-tool-approval-flow.d.ts +36 -0
  165. package/dist/agent-runtime/loop/run-tool-approval-flow.d.ts.map +1 -0
  166. package/dist/agent-runtime/loop/run-tool-approval-records.d.ts +24 -0
  167. package/dist/agent-runtime/loop/run-tool-approval-records.d.ts.map +1 -0
  168. package/dist/agent-runtime/loop/run-tool-call.d.ts +119 -0
  169. package/dist/agent-runtime/loop/run-tool-call.d.ts.map +1 -0
  170. package/dist/agent-runtime/loop/run-tool-errors.d.ts.map +1 -0
  171. package/dist/agent-runtime/loop/run-tool-executor.d.ts +42 -0
  172. package/dist/agent-runtime/loop/run-tool-executor.d.ts.map +1 -0
  173. package/dist/agent-runtime/loop/run-tool-progress.d.ts +21 -0
  174. package/dist/agent-runtime/loop/run-tool-progress.d.ts.map +1 -0
  175. package/dist/agent-runtime/loop/run-tool-slots.d.ts +114 -0
  176. package/dist/agent-runtime/loop/run-tool-slots.d.ts.map +1 -0
  177. package/dist/agent-runtime/loop/run-turn-preparation.d.ts +25 -0
  178. package/dist/agent-runtime/loop/run-turn-preparation.d.ts.map +1 -0
  179. package/dist/agent-runtime/loop/run-unacquired.d.ts +19 -0
  180. package/dist/agent-runtime/loop/run-unacquired.d.ts.map +1 -0
  181. package/dist/agent-runtime/loop/runtime-admission-gate.d.ts.map +1 -0
  182. package/dist/agent-runtime/loop/runtime-control.d.ts +9 -0
  183. package/dist/agent-runtime/loop/runtime-control.d.ts.map +1 -0
  184. package/dist/agent-runtime/loop/runtime-recovery.d.ts +10 -0
  185. package/dist/agent-runtime/loop/runtime-recovery.d.ts.map +1 -0
  186. package/dist/agent-runtime/loop/runtime-state.d.ts +36 -0
  187. package/dist/agent-runtime/loop/runtime-state.d.ts.map +1 -0
  188. package/dist/agent-runtime/loop/runtime-submit.d.ts +5 -0
  189. package/dist/agent-runtime/loop/runtime-submit.d.ts.map +1 -0
  190. package/dist/agent-runtime/loop/runtime.d.ts +352 -0
  191. package/dist/agent-runtime/loop/runtime.d.ts.map +1 -0
  192. package/dist/agent-runtime/loop/state-slots.d.ts +48 -0
  193. package/dist/agent-runtime/loop/state-slots.d.ts.map +1 -0
  194. package/dist/agent-runtime/loop/state-tools.d.ts +117 -0
  195. package/dist/agent-runtime/loop/state-tools.d.ts.map +1 -0
  196. package/dist/agent-runtime/protocol.d.ts +1 -1
  197. package/dist/agent-runtime/protocol.d.ts.map +1 -1
  198. package/dist/agent-runtime/providers/ai-sdk-convert.d.ts +15 -0
  199. package/dist/agent-runtime/providers/ai-sdk-convert.d.ts.map +1 -0
  200. package/dist/agent-runtime/providers/ai-sdk.d.ts +31 -0
  201. package/dist/agent-runtime/providers/ai-sdk.d.ts.map +1 -0
  202. package/dist/agent-runtime/providers/anthropic-media.d.ts +11 -0
  203. package/dist/agent-runtime/providers/anthropic-media.d.ts.map +1 -0
  204. package/dist/agent-runtime/providers/anthropic-messages.d.ts +25 -0
  205. package/dist/agent-runtime/providers/anthropic-messages.d.ts.map +1 -0
  206. package/dist/agent-runtime/providers/anthropic-options.d.ts +80 -0
  207. package/dist/agent-runtime/providers/anthropic-options.d.ts.map +1 -0
  208. package/dist/agent-runtime/providers/anthropic-response.d.ts +19 -0
  209. package/dist/agent-runtime/providers/anthropic-response.d.ts.map +1 -0
  210. package/dist/agent-runtime/providers/anthropic-sse.d.ts.map +1 -0
  211. package/dist/agent-runtime/providers/anthropic.d.ts.map +1 -0
  212. package/dist/agent-runtime/providers/models-driver-step.d.ts +212 -0
  213. package/dist/agent-runtime/providers/models-driver-step.d.ts.map +1 -0
  214. package/dist/agent-runtime/providers/models-driver-telemetry.d.ts.map +1 -0
  215. package/dist/agent-runtime/providers/models-driver.d.ts +235 -0
  216. package/dist/agent-runtime/providers/models-driver.d.ts.map +1 -0
  217. package/dist/agent-runtime/providers/models.d.ts.map +1 -0
  218. package/dist/agent-runtime/providers/openai-messages.d.ts.map +1 -0
  219. package/dist/agent-runtime/providers/openai-options.d.ts +91 -0
  220. package/dist/agent-runtime/providers/openai-options.d.ts.map +1 -0
  221. package/dist/agent-runtime/providers/openai-response.d.ts +77 -0
  222. package/dist/agent-runtime/providers/openai-response.d.ts.map +1 -0
  223. package/dist/agent-runtime/providers/openai-sse-state.d.ts.map +1 -0
  224. package/dist/agent-runtime/providers/openai-sse.d.ts.map +1 -0
  225. package/dist/agent-runtime/providers/openai.d.ts.map +1 -0
  226. package/dist/agent-runtime/providers/openrouter-admission.d.ts +85 -0
  227. package/dist/agent-runtime/providers/openrouter-admission.d.ts.map +1 -0
  228. package/dist/agent-runtime/providers/openrouter-benchmarks.d.ts.map +1 -0
  229. package/dist/agent-runtime/providers/openrouter-catalog-cache.d.ts.map +1 -0
  230. package/dist/agent-runtime/providers/openrouter-catalog-query.d.ts +82 -0
  231. package/dist/agent-runtime/providers/openrouter-catalog-query.d.ts.map +1 -0
  232. package/dist/agent-runtime/providers/openrouter-catalog.d.ts.map +1 -0
  233. package/dist/agent-runtime/providers/openrouter-models.d.ts.map +1 -0
  234. package/dist/agent-runtime/providers/openrouter-options.d.ts +136 -0
  235. package/dist/agent-runtime/providers/openrouter-options.d.ts.map +1 -0
  236. package/dist/agent-runtime/providers/openrouter-response.d.ts +22 -0
  237. package/dist/agent-runtime/providers/openrouter-response.d.ts.map +1 -0
  238. package/dist/agent-runtime/providers/openrouter-route.d.ts.map +1 -0
  239. package/dist/agent-runtime/providers/openrouter-spend.d.ts +24 -0
  240. package/dist/agent-runtime/providers/openrouter-spend.d.ts.map +1 -0
  241. package/dist/agent-runtime/providers/openrouter.d.ts.map +1 -0
  242. package/dist/agent-runtime/providers/provider-cache.d.ts +30 -0
  243. package/dist/agent-runtime/providers/provider-cache.d.ts.map +1 -0
  244. package/dist/agent-runtime/providers/provider-content.d.ts.map +1 -0
  245. package/dist/agent-runtime/providers/provider-failure.d.ts +97 -0
  246. package/dist/agent-runtime/providers/provider-failure.d.ts.map +1 -0
  247. package/dist/agent-runtime/providers/provider-history.d.ts +13 -0
  248. package/dist/agent-runtime/providers/provider-history.d.ts.map +1 -0
  249. package/dist/agent-runtime/providers/provider-http.d.ts.map +1 -0
  250. package/dist/agent-runtime/providers/provider-journal.d.ts.map +1 -0
  251. package/dist/agent-runtime/providers/provider-json-schema-strip.d.ts.map +1 -0
  252. package/dist/agent-runtime/providers/provider-json-schema.d.ts +31 -0
  253. package/dist/agent-runtime/providers/provider-json-schema.d.ts.map +1 -0
  254. package/dist/agent-runtime/providers/provider-media.d.ts +49 -0
  255. package/dist/agent-runtime/providers/provider-media.d.ts.map +1 -0
  256. package/dist/agent-runtime/providers/provider-openai-chat-helpers.d.ts +27 -0
  257. package/dist/agent-runtime/providers/provider-openai-chat-helpers.d.ts.map +1 -0
  258. package/dist/agent-runtime/providers/provider-openai-chat-sse.d.ts +25 -0
  259. package/dist/agent-runtime/providers/provider-openai-chat-sse.d.ts.map +1 -0
  260. package/dist/agent-runtime/providers/provider-openai-chat.d.ts +27 -0
  261. package/dist/agent-runtime/providers/provider-openai-chat.d.ts.map +1 -0
  262. package/dist/agent-runtime/providers/provider-sse.d.ts.map +1 -0
  263. package/dist/agent-runtime/providers/provider-usage.d.ts +24 -0
  264. package/dist/agent-runtime/providers/provider-usage.d.ts.map +1 -0
  265. package/dist/agent-runtime/realtime/harness-realtime.d.ts +53 -0
  266. package/dist/agent-runtime/realtime/harness-realtime.d.ts.map +1 -0
  267. package/dist/agent-runtime/sandbox/sandbox-binding.d.ts.map +1 -0
  268. package/dist/agent-runtime/sandbox/sandbox-broker.d.ts.map +1 -0
  269. package/dist/agent-runtime/sandbox/sandbox-bubblewrap-args.d.ts.map +1 -0
  270. package/dist/agent-runtime/sandbox/sandbox-bubblewrap-storage.d.ts.map +1 -0
  271. package/dist/agent-runtime/sandbox/sandbox-bubblewrap.d.ts.map +1 -0
  272. package/dist/agent-runtime/sandbox/sandbox-coding-adapter.d.ts.map +1 -0
  273. package/dist/agent-runtime/sandbox/sandbox-contract.d.ts.map +1 -0
  274. package/dist/agent-runtime/sandbox/sandbox-process-linux.d.ts.map +1 -0
  275. package/dist/agent-runtime/sandbox/sandbox-process-macos.d.ts.map +1 -0
  276. package/dist/agent-runtime/sandbox/sandbox-process-owner.d.ts +19 -0
  277. package/dist/agent-runtime/sandbox/sandbox-process-owner.d.ts.map +1 -0
  278. package/dist/agent-runtime/sandbox/sandbox-process-spec.d.ts.map +1 -0
  279. package/dist/agent-runtime/sandbox/sandbox-process-wrapper.d.ts.map +1 -0
  280. package/dist/agent-runtime/sandbox/sandbox-process.d.ts +8 -0
  281. package/dist/agent-runtime/sandbox/sandbox-process.d.ts.map +1 -0
  282. package/dist/agent-runtime/sandbox/sandbox-session.d.ts.map +1 -0
  283. package/dist/agent-runtime/sandbox/sandbox.d.ts +125 -0
  284. package/dist/agent-runtime/sandbox/sandbox.d.ts.map +1 -0
  285. package/dist/agent-runtime/stores/archive-projection.d.ts.map +1 -0
  286. package/dist/agent-runtime/stores/archive-spill.d.ts.map +1 -0
  287. package/dist/agent-runtime/stores/branch-contract.d.ts.map +1 -0
  288. package/dist/agent-runtime/stores/branch-events.d.ts +25 -0
  289. package/dist/agent-runtime/stores/branch-events.d.ts.map +1 -0
  290. package/dist/agent-runtime/stores/branch-identities.d.ts +75 -0
  291. package/dist/agent-runtime/stores/branch-identities.d.ts.map +1 -0
  292. package/dist/agent-runtime/stores/branch-messages.d.ts +21 -0
  293. package/dist/agent-runtime/stores/branch-messages.d.ts.map +1 -0
  294. package/dist/agent-runtime/stores/branch-observations.d.ts +227 -0
  295. package/dist/agent-runtime/stores/branch-observations.d.ts.map +1 -0
  296. package/dist/agent-runtime/stores/branch-provider.d.ts.map +1 -0
  297. package/dist/agent-runtime/stores/branch-refusal.d.ts.map +1 -0
  298. package/dist/agent-runtime/stores/branch-replay.d.ts +456 -0
  299. package/dist/agent-runtime/stores/branch-replay.d.ts.map +1 -0
  300. package/dist/agent-runtime/stores/branch-runtime-tools.d.ts.map +1 -0
  301. package/dist/agent-runtime/stores/branch-source.d.ts +33 -0
  302. package/dist/agent-runtime/stores/branch-source.d.ts.map +1 -0
  303. package/dist/agent-runtime/stores/branch-transitions.d.ts.map +1 -0
  304. package/dist/agent-runtime/stores/child-blocking.d.ts.map +1 -0
  305. package/dist/agent-runtime/stores/child-budget-policy.d.ts +17 -0
  306. package/dist/agent-runtime/stores/child-budget-policy.d.ts.map +1 -0
  307. package/dist/agent-runtime/stores/child-tools.d.ts +144 -0
  308. package/dist/agent-runtime/stores/child-tools.d.ts.map +1 -0
  309. package/dist/agent-runtime/stores/children-contract.d.ts +236 -0
  310. package/dist/agent-runtime/stores/children-contract.d.ts.map +1 -0
  311. package/dist/agent-runtime/stores/children-control.d.ts.map +1 -0
  312. package/dist/agent-runtime/stores/children-spawn.d.ts.map +1 -0
  313. package/dist/agent-runtime/stores/children-state.d.ts.map +1 -0
  314. package/dist/agent-runtime/stores/children-usage.d.ts.map +1 -0
  315. package/dist/agent-runtime/stores/children.d.ts.map +1 -0
  316. package/dist/agent-runtime/stores/companion-host.d.ts +38 -0
  317. package/dist/agent-runtime/stores/companion-host.d.ts.map +1 -0
  318. package/dist/agent-runtime/stores/conversations.d.ts.map +1 -0
  319. package/dist/agent-runtime/stores/event-search-postgres.d.ts.map +1 -0
  320. package/dist/agent-runtime/stores/event-search-terms.d.ts.map +1 -0
  321. package/dist/agent-runtime/stores/event-search-tools.d.ts +190 -0
  322. package/dist/agent-runtime/stores/event-search-tools.d.ts.map +1 -0
  323. package/dist/agent-runtime/stores/event-search.d.ts.map +1 -0
  324. package/dist/agent-runtime/stores/postgres-schema.d.ts.map +1 -0
  325. package/dist/agent-runtime/stores/postgres-transactions.d.ts +54 -0
  326. package/dist/agent-runtime/stores/postgres-transactions.d.ts.map +1 -0
  327. package/dist/agent-runtime/stores/postgres.d.ts +72 -0
  328. package/dist/agent-runtime/stores/postgres.d.ts.map +1 -0
  329. package/dist/agent-runtime/stores/projections.d.ts +109 -0
  330. package/dist/agent-runtime/stores/projections.d.ts.map +1 -0
  331. package/dist/agent-runtime/stores/purge.d.ts.map +1 -0
  332. package/dist/agent-runtime/stores/schedule-contract.d.ts.map +1 -0
  333. package/dist/agent-runtime/stores/schedule-dispatch.d.ts.map +1 -0
  334. package/dist/agent-runtime/stores/schedule-records.d.ts.map +1 -0
  335. package/dist/agent-runtime/stores/schedule-tools.d.ts +76 -0
  336. package/dist/agent-runtime/stores/schedule-tools.d.ts.map +1 -0
  337. package/dist/agent-runtime/stores/schedules.d.ts.map +1 -0
  338. package/dist/agent-runtime/stores/spill.d.ts +26 -0
  339. package/dist/agent-runtime/stores/spill.d.ts.map +1 -0
  340. package/dist/agent-runtime/stores/sql-events.d.ts.map +1 -0
  341. package/dist/agent-runtime/stores/sql-history.d.ts.map +1 -0
  342. package/dist/agent-runtime/stores/sql-ledger.d.ts.map +1 -0
  343. package/dist/agent-runtime/stores/sql-purge.d.ts.map +1 -0
  344. package/dist/agent-runtime/stores/sql-reads.d.ts.map +1 -0
  345. package/dist/agent-runtime/stores/sql-rows.d.ts.map +1 -0
  346. package/dist/agent-runtime/stores/sql-session.d.ts.map +1 -0
  347. package/dist/agent-runtime/stores/sqlite-bun.d.ts.map +1 -0
  348. package/dist/agent-runtime/stores/sqlite-node.d.ts.map +1 -0
  349. package/dist/agent-runtime/stores/sqlite-purge.d.ts +6 -0
  350. package/dist/agent-runtime/stores/sqlite-purge.d.ts.map +1 -0
  351. package/dist/agent-runtime/stores/sqlite-schema.d.ts +7 -0
  352. package/dist/agent-runtime/stores/sqlite-schema.d.ts.map +1 -0
  353. package/dist/agent-runtime/stores/sqlite-transactions.d.ts +29 -0
  354. package/dist/agent-runtime/stores/sqlite-transactions.d.ts.map +1 -0
  355. package/dist/agent-runtime/stores/sqlite.d.ts +33 -0
  356. package/dist/agent-runtime/stores/sqlite.d.ts.map +1 -0
  357. package/dist/agent-runtime/stores/store-archive.d.ts.map +1 -0
  358. package/dist/agent-runtime/stores/store-branch.d.ts.map +1 -0
  359. package/dist/agent-runtime/stores/store-capabilities.d.ts.map +1 -0
  360. package/dist/agent-runtime/stores/store-create.d.ts.map +1 -0
  361. package/dist/agent-runtime/stores/store-driver-contract.d.ts +1016 -0
  362. package/dist/agent-runtime/stores/store-driver-contract.d.ts.map +1 -0
  363. package/dist/agent-runtime/stores/store-event-once.d.ts +37 -0
  364. package/dist/agent-runtime/stores/store-event-once.d.ts.map +1 -0
  365. package/dist/agent-runtime/stores/store-events.d.ts +2231 -0
  366. package/dist/agent-runtime/stores/store-events.d.ts.map +1 -0
  367. package/dist/agent-runtime/stores/store-memory-archive.d.ts.map +1 -0
  368. package/dist/agent-runtime/stores/store-memory-events.d.ts +7 -0
  369. package/dist/agent-runtime/stores/store-memory-events.d.ts.map +1 -0
  370. package/dist/agent-runtime/stores/store-memory.d.ts.map +1 -0
  371. package/dist/agent-runtime/stores/store-migrations/v1-to-v2.d.ts +6 -0
  372. package/dist/agent-runtime/stores/store-migrations/v1-to-v2.d.ts.map +1 -0
  373. package/dist/agent-runtime/stores/store-migrations/v2-to-v3.d.ts +14 -0
  374. package/dist/agent-runtime/stores/store-migrations/v2-to-v3.d.ts.map +1 -0
  375. package/dist/agent-runtime/stores/store-migrations/v3-to-v4.d.ts +4 -0
  376. package/dist/agent-runtime/stores/store-migrations/v3-to-v4.d.ts.map +1 -0
  377. package/dist/agent-runtime/stores/store-mutate.d.ts.map +1 -0
  378. package/dist/agent-runtime/stores/store-purge.d.ts.map +1 -0
  379. package/dist/agent-runtime/stores/store-reads.d.ts +29 -0
  380. package/dist/agent-runtime/stores/store-reads.d.ts.map +1 -0
  381. package/dist/agent-runtime/stores/store-reduce-history.d.ts +10 -0
  382. package/dist/agent-runtime/stores/store-reduce-history.d.ts.map +1 -0
  383. package/dist/agent-runtime/stores/store-reduce-run.d.ts +14 -0
  384. package/dist/agent-runtime/stores/store-reduce-run.d.ts.map +1 -0
  385. package/dist/agent-runtime/stores/store-reduce-shared.d.ts +78 -0
  386. package/dist/agent-runtime/stores/store-reduce-shared.d.ts.map +1 -0
  387. package/dist/agent-runtime/stores/store-reduce-terminal.d.ts +6 -0
  388. package/dist/agent-runtime/stores/store-reduce-terminal.d.ts.map +1 -0
  389. package/dist/agent-runtime/stores/store-reducer.d.ts +24 -0
  390. package/dist/agent-runtime/stores/store-reducer.d.ts.map +1 -0
  391. package/dist/agent-runtime/stores/store-replay.d.ts.map +1 -0
  392. package/dist/agent-runtime/stores/store-snapshot.d.ts +19 -0
  393. package/dist/agent-runtime/stores/store-snapshot.d.ts.map +1 -0
  394. package/dist/agent-runtime/stores/store.d.ts +3032 -0
  395. package/dist/agent-runtime/stores/store.d.ts.map +1 -0
  396. package/dist/agent-runtime/terminal-commit.d.ts +1 -1
  397. package/dist/agent-runtime/terminal-commit.d.ts.map +1 -1
  398. package/dist/agent-runtime/testing/fault-bench.d.ts.map +1 -0
  399. package/dist/agent-runtime/testing/run-assertions.d.ts +63 -0
  400. package/dist/agent-runtime/testing/run-assertions.d.ts.map +1 -0
  401. package/dist/agent-runtime/testing/store-conformance-branch.d.ts +7 -0
  402. package/dist/agent-runtime/testing/store-conformance-branch.d.ts.map +1 -0
  403. package/dist/agent-runtime/testing/store-conformance-capabilities.d.ts +6 -0
  404. package/dist/agent-runtime/testing/store-conformance-capabilities.d.ts.map +1 -0
  405. package/dist/agent-runtime/testing/store-conformance-event-once.d.ts +12 -0
  406. package/dist/agent-runtime/testing/store-conformance-event-once.d.ts.map +1 -0
  407. package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts +454 -0
  408. package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts.map +1 -0
  409. package/dist/agent-runtime/testing/store-conformance-ordering.d.ts +18 -0
  410. package/dist/agent-runtime/testing/store-conformance-ordering.d.ts.map +1 -0
  411. package/dist/agent-runtime/testing/store-conformance-seed.d.ts +8 -0
  412. package/dist/agent-runtime/testing/store-conformance-seed.d.ts.map +1 -0
  413. package/dist/agent-runtime/testing/store-conformance-support.d.ts.map +1 -0
  414. package/dist/agent-runtime/testing/store-conformance-terminal.d.ts +12 -0
  415. package/dist/agent-runtime/testing/store-conformance-terminal.d.ts.map +1 -0
  416. package/dist/agent-runtime/testing/store-conformance.d.ts +71 -0
  417. package/dist/agent-runtime/testing/store-conformance.d.ts.map +1 -0
  418. package/dist/agent-runtime/testing/testing.d.ts +46 -0
  419. package/dist/agent-runtime/testing/testing.d.ts.map +1 -0
  420. package/dist/browser/client-executors.d.ts.map +1 -1
  421. package/dist/browser/client.d.ts +3 -2
  422. package/dist/browser/client.d.ts.map +1 -1
  423. package/dist/browser/http.d.ts +6 -3
  424. package/dist/browser/http.d.ts.map +1 -1
  425. package/dist/contract/client-types.d.ts +4 -3
  426. package/dist/contract/client-types.d.ts.map +1 -1
  427. package/dist/entrypoints/agent-executor/acp.js +38 -12
  428. package/dist/entrypoints/agent-executor/claude-sdk.js +1 -1
  429. package/dist/entrypoints/agent-executor/codex.js +2 -2
  430. package/dist/entrypoints/agent-executor/testing/claude-sdk.js +3 -3
  431. package/dist/entrypoints/agent-executor/testing.js +3 -3
  432. package/dist/entrypoints/agent-executor.js +1 -1
  433. package/dist/entrypoints/agent-runtime/ai-sdk.d.ts +3 -3
  434. package/dist/entrypoints/agent-runtime/ai-sdk.d.ts.map +1 -1
  435. package/dist/entrypoints/agent-runtime/ai-sdk.js +9 -8
  436. package/dist/entrypoints/agent-runtime/anthropic.d.ts +3 -3
  437. package/dist/entrypoints/agent-runtime/anthropic.d.ts.map +1 -1
  438. package/dist/entrypoints/agent-runtime/anthropic.js +72 -18
  439. package/dist/entrypoints/agent-runtime/browser.d.ts +6 -6
  440. package/dist/entrypoints/agent-runtime/browser.d.ts.map +1 -1
  441. package/dist/entrypoints/agent-runtime/browser.js +39 -39
  442. package/dist/entrypoints/agent-runtime/coding-tools.d.ts +1 -1
  443. package/dist/entrypoints/agent-runtime/coding-tools.d.ts.map +1 -1
  444. package/dist/entrypoints/agent-runtime/coding-tools.js +2 -2
  445. package/dist/entrypoints/agent-runtime/harness.d.ts +1 -1
  446. package/dist/entrypoints/agent-runtime/harness.d.ts.map +1 -1
  447. package/dist/entrypoints/agent-runtime/harness.js +27 -28
  448. package/dist/entrypoints/agent-runtime/openai.d.ts +3 -3
  449. package/dist/entrypoints/agent-runtime/openai.d.ts.map +1 -1
  450. package/dist/entrypoints/agent-runtime/openai.js +9 -9
  451. package/dist/entrypoints/agent-runtime/openrouter.d.ts +10 -10
  452. package/dist/entrypoints/agent-runtime/openrouter.d.ts.map +1 -1
  453. package/dist/entrypoints/agent-runtime/openrouter.js +167 -113
  454. package/dist/entrypoints/agent-runtime/postgres.d.ts +2 -2
  455. package/dist/entrypoints/agent-runtime/postgres.d.ts.map +1 -1
  456. package/dist/entrypoints/agent-runtime/postgres.js +8 -8
  457. package/dist/entrypoints/agent-runtime/react.d.ts +1 -1
  458. package/dist/entrypoints/agent-runtime/react.d.ts.map +1 -1
  459. package/dist/entrypoints/agent-runtime/react.js +1 -1
  460. package/dist/entrypoints/agent-runtime/realtime.d.ts +1 -1
  461. package/dist/entrypoints/agent-runtime/realtime.d.ts.map +1 -1
  462. package/dist/entrypoints/agent-runtime/realtime.js +5 -5
  463. package/dist/entrypoints/agent-runtime/sandbox.d.ts +9 -9
  464. package/dist/entrypoints/agent-runtime/sandbox.d.ts.map +1 -1
  465. package/dist/entrypoints/agent-runtime/sandbox.js +220 -93
  466. package/dist/entrypoints/agent-runtime/sqlite/bun.d.ts +1 -1
  467. package/dist/entrypoints/agent-runtime/sqlite/bun.d.ts.map +1 -1
  468. package/dist/entrypoints/agent-runtime/sqlite/bun.js +8 -8
  469. package/dist/entrypoints/agent-runtime/sqlite/node.d.ts +1 -1
  470. package/dist/entrypoints/agent-runtime/sqlite/node.d.ts.map +1 -1
  471. package/dist/entrypoints/agent-runtime/sqlite/node.js +8 -8
  472. package/dist/entrypoints/agent-runtime/testing.d.ts +4 -4
  473. package/dist/entrypoints/agent-runtime/testing.d.ts.map +1 -1
  474. package/dist/entrypoints/agent-runtime/testing.js +21 -21
  475. package/dist/entrypoints/agent-runtime.d.ts +50 -50
  476. package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
  477. package/dist/entrypoints/agent-runtime.js +2853 -3107
  478. package/dist/entrypoints/cli.js +8 -9
  479. package/dist/entrypoints/http.js +2 -2
  480. package/dist/entrypoints/index.js +2 -2
  481. package/dist/entrypoints/react.js +1 -1
  482. package/dist/entrypoints/remote.js +2 -2
  483. package/dist/entrypoints/server.js +2 -2
  484. package/dist/entrypoints/testing.js +7 -9
  485. package/dist/entrypoints/tools/agent.js +476 -13
  486. package/dist/entrypoints/tools/connections.js +9 -7
  487. package/dist/entrypoints/tools/contract.js +4 -4
  488. package/dist/entrypoints/tools/invoker.js +7 -8
  489. package/dist/entrypoints/tools/mcp.js +9 -11
  490. package/dist/entrypoints/tools/toolkit.d.ts +6 -4
  491. package/dist/entrypoints/tools/toolkit.d.ts.map +1 -1
  492. package/dist/entrypoints/tools/toolkit.js +11 -18
  493. package/dist/entrypoints/tools.js +12 -13
  494. package/dist/index-125ks2ec.js +17 -0
  495. package/dist/index-1w69rj9f.js +224 -0
  496. package/dist/index-1zy31r3b.js +26 -0
  497. package/dist/index-3czc3ykr.js +53 -0
  498. package/dist/index-3d2c45jn.js +77 -0
  499. package/dist/index-57sbckhv.js +271 -0
  500. package/dist/index-64t6pheq.js +2872 -0
  501. package/dist/index-73wq9abg.js +367 -0
  502. package/dist/index-84tp547a.js +981 -0
  503. package/dist/index-9be3tf6r.js +196 -0
  504. package/dist/index-asnd4h2k.js +969 -0
  505. package/dist/index-b4c9dpzm.js +1210 -0
  506. package/dist/index-baba8ehy.js +53 -0
  507. package/dist/index-c24bj2r1.js +510 -0
  508. package/dist/index-cgjtj8zh.js +707 -0
  509. package/dist/index-d4at0q09.js +601 -0
  510. package/dist/index-de7b0kvz.js +215 -0
  511. package/dist/index-dm84tsd5.js +164 -0
  512. package/dist/index-fsw9wxk9.js +349 -0
  513. package/dist/index-gk6dq9ay.js +124 -0
  514. package/dist/index-gs0jw0hy.js +174 -0
  515. package/dist/index-hce3hbdg.js +121 -0
  516. package/dist/index-mcv7b2n0.js +3545 -0
  517. package/dist/index-n9358ydy.js +63 -0
  518. package/dist/index-npfdymav.js +409 -0
  519. package/dist/index-p9cab61p.js +305 -0
  520. package/dist/index-q86qnzzf.js +231 -0
  521. package/dist/index-qcy8et93.js +698 -0
  522. package/dist/index-refgnzy0.js +158 -0
  523. package/dist/index-rkphknhx.js +40 -0
  524. package/dist/index-v0j22shs.js +3781 -0
  525. package/dist/index-vse7x1qt.js +460 -0
  526. package/dist/index-wdb5jhas.js +51 -0
  527. package/dist/index-ws0awmzq.js +47 -0
  528. package/dist/index-wsv11dhg.js +725 -0
  529. package/dist/index-xbb8ysmq.js +40 -0
  530. package/dist/index-y0mwkgkf.js +7812 -0
  531. package/dist/index-yhwx4fwk.js +295 -0
  532. package/dist/index-z72vazf5.js +502 -0
  533. package/dist/index-zfrysr1e.js +710 -0
  534. package/dist/json-schema/dialect.d.ts.map +1 -1
  535. package/dist/json-schema/string-format.d.ts.map +1 -1
  536. package/dist/tools/agent-call-context.d.ts +23 -0
  537. package/dist/tools/agent-call-context.d.ts.map +1 -0
  538. package/dist/tools/agent.d.ts.map +1 -1
  539. package/dist/tools/schema/flatten.d.ts.map +1 -1
  540. package/dist/tools/toolkit.d.ts +8 -6
  541. package/dist/tools/toolkit.d.ts.map +1 -1
  542. package/llms/agent-runtime-ai-sdk.txt +2 -2
  543. package/llms/agent-runtime-anthropic.txt +8 -4
  544. package/llms/agent-runtime-openrouter.txt +4 -4
  545. package/llms/agent-runtime-sandbox.txt +20 -7
  546. package/llms/agent-runtime.3.txt +19 -3
  547. package/llms/agent-runtime.4.txt +2 -2
  548. package/llms/agent-runtime.txt +20 -7
  549. package/llms/cli.2.txt +8 -5
  550. package/llms/contract.txt +1 -1
  551. package/llms/server.txt +10 -6
  552. package/llms/stitchkit.2.txt +18 -11
  553. package/llms/stitchkit.txt +85 -85
  554. package/llms/tools-toolkit.txt +3 -6
  555. package/llms/tools.4.txt +3 -3
  556. package/llms/upgrading-0.128.0-0.135.0.txt +700 -0
  557. package/llms/upgrading.txt +1 -1
  558. package/llms-full.txt +264 -146
  559. package/llms.txt +12 -12
  560. package/package.json +1 -1
  561. package/dist/agent-runtime/admission-lanes.d.ts +0 -35
  562. package/dist/agent-runtime/admission-lanes.d.ts.map +0 -1
  563. package/dist/agent-runtime/ai-sdk-convert.d.ts +0 -15
  564. package/dist/agent-runtime/ai-sdk-convert.d.ts.map +0 -1
  565. package/dist/agent-runtime/ai-sdk.d.ts +0 -31
  566. package/dist/agent-runtime/ai-sdk.d.ts.map +0 -1
  567. package/dist/agent-runtime/anthropic-media.d.ts +0 -11
  568. package/dist/agent-runtime/anthropic-media.d.ts.map +0 -1
  569. package/dist/agent-runtime/anthropic-messages.d.ts +0 -24
  570. package/dist/agent-runtime/anthropic-messages.d.ts.map +0 -1
  571. package/dist/agent-runtime/anthropic-options.d.ts +0 -79
  572. package/dist/agent-runtime/anthropic-options.d.ts.map +0 -1
  573. package/dist/agent-runtime/anthropic-response.d.ts +0 -19
  574. package/dist/agent-runtime/anthropic-response.d.ts.map +0 -1
  575. package/dist/agent-runtime/anthropic-sse.d.ts.map +0 -1
  576. package/dist/agent-runtime/anthropic.d.ts.map +0 -1
  577. package/dist/agent-runtime/archive-projection.d.ts.map +0 -1
  578. package/dist/agent-runtime/archive-spill.d.ts.map +0 -1
  579. package/dist/agent-runtime/branch-contract.d.ts.map +0 -1
  580. package/dist/agent-runtime/branch-events.d.ts +0 -25
  581. package/dist/agent-runtime/branch-events.d.ts.map +0 -1
  582. package/dist/agent-runtime/branch-identities.d.ts +0 -75
  583. package/dist/agent-runtime/branch-identities.d.ts.map +0 -1
  584. package/dist/agent-runtime/branch-messages.d.ts +0 -21
  585. package/dist/agent-runtime/branch-messages.d.ts.map +0 -1
  586. package/dist/agent-runtime/branch-observations.d.ts +0 -227
  587. package/dist/agent-runtime/branch-observations.d.ts.map +0 -1
  588. package/dist/agent-runtime/branch-provider.d.ts.map +0 -1
  589. package/dist/agent-runtime/branch-refusal.d.ts.map +0 -1
  590. package/dist/agent-runtime/branch-replay.d.ts +0 -456
  591. package/dist/agent-runtime/branch-replay.d.ts.map +0 -1
  592. package/dist/agent-runtime/branch-runtime-tools.d.ts.map +0 -1
  593. package/dist/agent-runtime/branch-source.d.ts +0 -33
  594. package/dist/agent-runtime/branch-source.d.ts.map +0 -1
  595. package/dist/agent-runtime/branch-transitions.d.ts.map +0 -1
  596. package/dist/agent-runtime/browser-control-contract.d.ts +0 -1364
  597. package/dist/agent-runtime/browser-control-contract.d.ts.map +0 -1
  598. package/dist/agent-runtime/browser-controller-view.d.ts +0 -44
  599. package/dist/agent-runtime/browser-controller-view.d.ts.map +0 -1
  600. package/dist/agent-runtime/browser-controller.d.ts +0 -53
  601. package/dist/agent-runtime/browser-controller.d.ts.map +0 -1
  602. package/dist/agent-runtime/child-blocking.d.ts.map +0 -1
  603. package/dist/agent-runtime/child-budget-policy.d.ts +0 -17
  604. package/dist/agent-runtime/child-budget-policy.d.ts.map +0 -1
  605. package/dist/agent-runtime/child-tools.d.ts +0 -144
  606. package/dist/agent-runtime/child-tools.d.ts.map +0 -1
  607. package/dist/agent-runtime/children-contract.d.ts +0 -236
  608. package/dist/agent-runtime/children-contract.d.ts.map +0 -1
  609. package/dist/agent-runtime/children-control.d.ts.map +0 -1
  610. package/dist/agent-runtime/children-spawn.d.ts.map +0 -1
  611. package/dist/agent-runtime/children-state.d.ts.map +0 -1
  612. package/dist/agent-runtime/children-usage.d.ts.map +0 -1
  613. package/dist/agent-runtime/children.d.ts.map +0 -1
  614. package/dist/agent-runtime/coding-discovery.d.ts +0 -25
  615. package/dist/agent-runtime/coding-discovery.d.ts.map +0 -1
  616. package/dist/agent-runtime/coding-sandbox.d.ts +0 -8
  617. package/dist/agent-runtime/coding-sandbox.d.ts.map +0 -1
  618. package/dist/agent-runtime/coding-search-automaton.d.ts.map +0 -1
  619. package/dist/agent-runtime/coding-search-case-fold.d.ts.map +0 -1
  620. package/dist/agent-runtime/coding-search-class-ranges.d.ts.map +0 -1
  621. package/dist/agent-runtime/coding-search-contract.d.ts.map +0 -1
  622. package/dist/agent-runtime/coding-search-limits.d.ts.map +0 -1
  623. package/dist/agent-runtime/coding-search-matcher.d.ts.map +0 -1
  624. package/dist/agent-runtime/coding-search-output.d.ts.map +0 -1
  625. package/dist/agent-runtime/coding-search-regex-syntax.d.ts.map +0 -1
  626. package/dist/agent-runtime/coding-search-unit-classes.d.ts.map +0 -1
  627. package/dist/agent-runtime/coding-shell-process.d.ts +0 -36
  628. package/dist/agent-runtime/coding-shell-process.d.ts.map +0 -1
  629. package/dist/agent-runtime/coding-tool-contract.d.ts +0 -261
  630. package/dist/agent-runtime/coding-tool-contract.d.ts.map +0 -1
  631. package/dist/agent-runtime/coding-tool-files.d.ts.map +0 -1
  632. package/dist/agent-runtime/coding-tool-listing.d.ts.map +0 -1
  633. package/dist/agent-runtime/coding-tool-paths.d.ts +0 -53
  634. package/dist/agent-runtime/coding-tool-paths.d.ts.map +0 -1
  635. package/dist/agent-runtime/coding-tool-refusals.d.ts.map +0 -1
  636. package/dist/agent-runtime/coding-tool-search-patch.d.ts.map +0 -1
  637. package/dist/agent-runtime/coding-tool-search.d.ts +0 -113
  638. package/dist/agent-runtime/coding-tool-search.d.ts.map +0 -1
  639. package/dist/agent-runtime/coding-tool-shell.d.ts.map +0 -1
  640. package/dist/agent-runtime/coding-tool-utf8.d.ts.map +0 -1
  641. package/dist/agent-runtime/coding-tools.d.ts.map +0 -1
  642. package/dist/agent-runtime/compaction.d.ts +0 -103
  643. package/dist/agent-runtime/compaction.d.ts.map +0 -1
  644. package/dist/agent-runtime/companion-host.d.ts +0 -38
  645. package/dist/agent-runtime/companion-host.d.ts.map +0 -1
  646. package/dist/agent-runtime/contained-scan-budget.d.ts.map +0 -1
  647. package/dist/agent-runtime/contained-scan-contract.d.ts.map +0 -1
  648. package/dist/agent-runtime/contained-scan.d.ts +0 -56
  649. package/dist/agent-runtime/contained-scan.d.ts.map +0 -1
  650. package/dist/agent-runtime/control-interaction-schema.d.ts.map +0 -1
  651. package/dist/agent-runtime/control-schema.d.ts +0 -1378
  652. package/dist/agent-runtime/control-schema.d.ts.map +0 -1
  653. package/dist/agent-runtime/control-view.d.ts +0 -64
  654. package/dist/agent-runtime/control-view.d.ts.map +0 -1
  655. package/dist/agent-runtime/conversations.d.ts.map +0 -1
  656. package/dist/agent-runtime/coordinator.d.ts.map +0 -1
  657. package/dist/agent-runtime/deferred-tool-search.d.ts +0 -9
  658. package/dist/agent-runtime/deferred-tool-search.d.ts.map +0 -1
  659. package/dist/agent-runtime/deferred-tool-selection.d.ts +0 -32
  660. package/dist/agent-runtime/deferred-tool-selection.d.ts.map +0 -1
  661. package/dist/agent-runtime/deferred-tools-internal.d.ts +0 -9
  662. package/dist/agent-runtime/deferred-tools-internal.d.ts.map +0 -1
  663. package/dist/agent-runtime/deferred-tools.d.ts +0 -4
  664. package/dist/agent-runtime/deferred-tools.d.ts.map +0 -1
  665. package/dist/agent-runtime/event-search-postgres.d.ts.map +0 -1
  666. package/dist/agent-runtime/event-search-terms.d.ts.map +0 -1
  667. package/dist/agent-runtime/event-search-tools.d.ts +0 -190
  668. package/dist/agent-runtime/event-search-tools.d.ts.map +0 -1
  669. package/dist/agent-runtime/event-search.d.ts.map +0 -1
  670. package/dist/agent-runtime/fault-bench.d.ts.map +0 -1
  671. package/dist/agent-runtime/harness-contract.d.ts +0 -206
  672. package/dist/agent-runtime/harness-contract.d.ts.map +0 -1
  673. package/dist/agent-runtime/harness-control.d.ts +0 -34
  674. package/dist/agent-runtime/harness-control.d.ts.map +0 -1
  675. package/dist/agent-runtime/harness-file-resources.d.ts +0 -33
  676. package/dist/agent-runtime/harness-file-resources.d.ts.map +0 -1
  677. package/dist/agent-runtime/harness-realtime.d.ts +0 -53
  678. package/dist/agent-runtime/harness-realtime.d.ts.map +0 -1
  679. package/dist/agent-runtime/harness-resources.d.ts.map +0 -1
  680. package/dist/agent-runtime/harness.d.ts +0 -15
  681. package/dist/agent-runtime/harness.d.ts.map +0 -1
  682. package/dist/agent-runtime/history.d.ts +0 -93
  683. package/dist/agent-runtime/history.d.ts.map +0 -1
  684. package/dist/agent-runtime/injection.d.ts +0 -28
  685. package/dist/agent-runtime/injection.d.ts.map +0 -1
  686. package/dist/agent-runtime/invocation-attempt.d.ts +0 -32
  687. package/dist/agent-runtime/invocation-attempt.d.ts.map +0 -1
  688. package/dist/agent-runtime/invocation-failure.d.ts.map +0 -1
  689. package/dist/agent-runtime/invocation-payload.d.ts +0 -38
  690. package/dist/agent-runtime/invocation-payload.d.ts.map +0 -1
  691. package/dist/agent-runtime/invocation-read.d.ts +0 -134
  692. package/dist/agent-runtime/invocation-read.d.ts.map +0 -1
  693. package/dist/agent-runtime/invocation-spend.d.ts +0 -9
  694. package/dist/agent-runtime/invocation-spend.d.ts.map +0 -1
  695. package/dist/agent-runtime/invocation-stream.d.ts +0 -20
  696. package/dist/agent-runtime/invocation-stream.d.ts.map +0 -1
  697. package/dist/agent-runtime/invocations.d.ts +0 -63
  698. package/dist/agent-runtime/invocations.d.ts.map +0 -1
  699. package/dist/agent-runtime/managed-tools.d.ts +0 -20
  700. package/dist/agent-runtime/managed-tools.d.ts.map +0 -1
  701. package/dist/agent-runtime/models-driver-step.d.ts +0 -212
  702. package/dist/agent-runtime/models-driver-step.d.ts.map +0 -1
  703. package/dist/agent-runtime/models-driver-telemetry.d.ts.map +0 -1
  704. package/dist/agent-runtime/models-driver.d.ts +0 -235
  705. package/dist/agent-runtime/models-driver.d.ts.map +0 -1
  706. package/dist/agent-runtime/models.d.ts.map +0 -1
  707. package/dist/agent-runtime/observability.d.ts +0 -579
  708. package/dist/agent-runtime/observability.d.ts.map +0 -1
  709. package/dist/agent-runtime/openai-messages.d.ts.map +0 -1
  710. package/dist/agent-runtime/openai-options.d.ts +0 -91
  711. package/dist/agent-runtime/openai-options.d.ts.map +0 -1
  712. package/dist/agent-runtime/openai-response.d.ts +0 -77
  713. package/dist/agent-runtime/openai-response.d.ts.map +0 -1
  714. package/dist/agent-runtime/openai-sse-state.d.ts.map +0 -1
  715. package/dist/agent-runtime/openai-sse.d.ts.map +0 -1
  716. package/dist/agent-runtime/openai.d.ts.map +0 -1
  717. package/dist/agent-runtime/openrouter-admission.d.ts +0 -84
  718. package/dist/agent-runtime/openrouter-admission.d.ts.map +0 -1
  719. package/dist/agent-runtime/openrouter-benchmarks.d.ts.map +0 -1
  720. package/dist/agent-runtime/openrouter-catalog-cache.d.ts.map +0 -1
  721. package/dist/agent-runtime/openrouter-catalog-query.d.ts +0 -57
  722. package/dist/agent-runtime/openrouter-catalog-query.d.ts.map +0 -1
  723. package/dist/agent-runtime/openrouter-catalog.d.ts.map +0 -1
  724. package/dist/agent-runtime/openrouter-models.d.ts.map +0 -1
  725. package/dist/agent-runtime/openrouter-options.d.ts +0 -136
  726. package/dist/agent-runtime/openrouter-options.d.ts.map +0 -1
  727. package/dist/agent-runtime/openrouter-response.d.ts +0 -22
  728. package/dist/agent-runtime/openrouter-response.d.ts.map +0 -1
  729. package/dist/agent-runtime/openrouter-route.d.ts.map +0 -1
  730. package/dist/agent-runtime/openrouter-spend.d.ts +0 -24
  731. package/dist/agent-runtime/openrouter-spend.d.ts.map +0 -1
  732. package/dist/agent-runtime/openrouter.d.ts.map +0 -1
  733. package/dist/agent-runtime/owned-provider-stream.d.ts.map +0 -1
  734. package/dist/agent-runtime/postgres-schema.d.ts.map +0 -1
  735. package/dist/agent-runtime/postgres-transactions.d.ts +0 -54
  736. package/dist/agent-runtime/postgres-transactions.d.ts.map +0 -1
  737. package/dist/agent-runtime/postgres.d.ts +0 -72
  738. package/dist/agent-runtime/postgres.d.ts.map +0 -1
  739. package/dist/agent-runtime/projections.d.ts +0 -109
  740. package/dist/agent-runtime/projections.d.ts.map +0 -1
  741. package/dist/agent-runtime/provider-cache.d.ts +0 -30
  742. package/dist/agent-runtime/provider-cache.d.ts.map +0 -1
  743. package/dist/agent-runtime/provider-content.d.ts.map +0 -1
  744. package/dist/agent-runtime/provider-failure.d.ts +0 -95
  745. package/dist/agent-runtime/provider-failure.d.ts.map +0 -1
  746. package/dist/agent-runtime/provider-history.d.ts +0 -13
  747. package/dist/agent-runtime/provider-history.d.ts.map +0 -1
  748. package/dist/agent-runtime/provider-http.d.ts.map +0 -1
  749. package/dist/agent-runtime/provider-journal.d.ts.map +0 -1
  750. package/dist/agent-runtime/provider-json-schema-strip.d.ts.map +0 -1
  751. package/dist/agent-runtime/provider-json-schema.d.ts +0 -28
  752. package/dist/agent-runtime/provider-json-schema.d.ts.map +0 -1
  753. package/dist/agent-runtime/provider-media.d.ts +0 -49
  754. package/dist/agent-runtime/provider-media.d.ts.map +0 -1
  755. package/dist/agent-runtime/provider-openai-chat-helpers.d.ts +0 -27
  756. package/dist/agent-runtime/provider-openai-chat-helpers.d.ts.map +0 -1
  757. package/dist/agent-runtime/provider-openai-chat-sse.d.ts +0 -25
  758. package/dist/agent-runtime/provider-openai-chat-sse.d.ts.map +0 -1
  759. package/dist/agent-runtime/provider-openai-chat.d.ts +0 -27
  760. package/dist/agent-runtime/provider-openai-chat.d.ts.map +0 -1
  761. package/dist/agent-runtime/provider-origin.d.ts +0 -10
  762. package/dist/agent-runtime/provider-origin.d.ts.map +0 -1
  763. package/dist/agent-runtime/provider-sse.d.ts.map +0 -1
  764. package/dist/agent-runtime/provider-stream-parts.d.ts +0 -5
  765. package/dist/agent-runtime/provider-stream-parts.d.ts.map +0 -1
  766. package/dist/agent-runtime/provider-stream-segments.d.ts +0 -63
  767. package/dist/agent-runtime/provider-stream-segments.d.ts.map +0 -1
  768. package/dist/agent-runtime/provider-usage.d.ts +0 -24
  769. package/dist/agent-runtime/provider-usage.d.ts.map +0 -1
  770. package/dist/agent-runtime/purge.d.ts.map +0 -1
  771. package/dist/agent-runtime/react.d.ts.map +0 -1
  772. package/dist/agent-runtime/retry-policy.d.ts +0 -49
  773. package/dist/agent-runtime/retry-policy.d.ts.map +0 -1
  774. package/dist/agent-runtime/run-acquisition.d.ts +0 -24
  775. package/dist/agent-runtime/run-acquisition.d.ts.map +0 -1
  776. package/dist/agent-runtime/run-approval.d.ts +0 -82
  777. package/dist/agent-runtime/run-approval.d.ts.map +0 -1
  778. package/dist/agent-runtime/run-assertions.d.ts +0 -63
  779. package/dist/agent-runtime/run-assertions.d.ts.map +0 -1
  780. package/dist/agent-runtime/run-complete-retry.d.ts +0 -24
  781. package/dist/agent-runtime/run-complete-retry.d.ts.map +0 -1
  782. package/dist/agent-runtime/run-complete-stream.d.ts +0 -9
  783. package/dist/agent-runtime/run-complete-stream.d.ts.map +0 -1
  784. package/dist/agent-runtime/run-complete-tools.d.ts +0 -21
  785. package/dist/agent-runtime/run-complete-tools.d.ts.map +0 -1
  786. package/dist/agent-runtime/run-complete-types.d.ts +0 -168
  787. package/dist/agent-runtime/run-complete-types.d.ts.map +0 -1
  788. package/dist/agent-runtime/run-complete.d.ts +0 -25
  789. package/dist/agent-runtime/run-complete.d.ts.map +0 -1
  790. package/dist/agent-runtime/run-driver-compose.d.ts +0 -21
  791. package/dist/agent-runtime/run-driver-compose.d.ts.map +0 -1
  792. package/dist/agent-runtime/run-execution-state.d.ts +0 -178
  793. package/dist/agent-runtime/run-execution-state.d.ts.map +0 -1
  794. package/dist/agent-runtime/run-execution.d.ts +0 -22
  795. package/dist/agent-runtime/run-execution.d.ts.map +0 -1
  796. package/dist/agent-runtime/run-failure.d.ts +0 -21
  797. package/dist/agent-runtime/run-failure.d.ts.map +0 -1
  798. package/dist/agent-runtime/run-history-parts.d.ts +0 -14
  799. package/dist/agent-runtime/run-history-parts.d.ts.map +0 -1
  800. package/dist/agent-runtime/run-loop-events.d.ts +0 -126
  801. package/dist/agent-runtime/run-loop-events.d.ts.map +0 -1
  802. package/dist/agent-runtime/run-model-attempts.d.ts +0 -6
  803. package/dist/agent-runtime/run-model-attempts.d.ts.map +0 -1
  804. package/dist/agent-runtime/run-model-messages.d.ts +0 -9
  805. package/dist/agent-runtime/run-model-messages.d.ts.map +0 -1
  806. package/dist/agent-runtime/run-model-step.d.ts +0 -43
  807. package/dist/agent-runtime/run-model-step.d.ts.map +0 -1
  808. package/dist/agent-runtime/run-model-stream.d.ts +0 -27
  809. package/dist/agent-runtime/run-model-stream.d.ts.map +0 -1
  810. package/dist/agent-runtime/run-operation-lifecycle.d.ts +0 -32
  811. package/dist/agent-runtime/run-operation-lifecycle.d.ts.map +0 -1
  812. package/dist/agent-runtime/run-prompt-history.d.ts +0 -53
  813. package/dist/agent-runtime/run-prompt-history.d.ts.map +0 -1
  814. package/dist/agent-runtime/run-provider-ledger.d.ts +0 -32
  815. package/dist/agent-runtime/run-provider-ledger.d.ts.map +0 -1
  816. package/dist/agent-runtime/run-step-barriers.d.ts +0 -114
  817. package/dist/agent-runtime/run-step-barriers.d.ts.map +0 -1
  818. package/dist/agent-runtime/run-step-helpers.d.ts +0 -49
  819. package/dist/agent-runtime/run-step-helpers.d.ts.map +0 -1
  820. package/dist/agent-runtime/run-step-prepare.d.ts +0 -34
  821. package/dist/agent-runtime/run-step-prepare.d.ts.map +0 -1
  822. package/dist/agent-runtime/run-step-spend.d.ts +0 -394
  823. package/dist/agent-runtime/run-step-spend.d.ts.map +0 -1
  824. package/dist/agent-runtime/run-stream-parts.d.ts +0 -34
  825. package/dist/agent-runtime/run-stream-parts.d.ts.map +0 -1
  826. package/dist/agent-runtime/run-stream-recorded.d.ts +0 -8
  827. package/dist/agent-runtime/run-stream-recorded.d.ts.map +0 -1
  828. package/dist/agent-runtime/run-stream-step-text.d.ts +0 -29
  829. package/dist/agent-runtime/run-stream-step-text.d.ts.map +0 -1
  830. package/dist/agent-runtime/run-terminal.d.ts +0 -11
  831. package/dist/agent-runtime/run-terminal.d.ts.map +0 -1
  832. package/dist/agent-runtime/run-tool-approval-flow.d.ts +0 -36
  833. package/dist/agent-runtime/run-tool-approval-flow.d.ts.map +0 -1
  834. package/dist/agent-runtime/run-tool-approval-records.d.ts +0 -24
  835. package/dist/agent-runtime/run-tool-approval-records.d.ts.map +0 -1
  836. package/dist/agent-runtime/run-tool-call.d.ts +0 -73
  837. package/dist/agent-runtime/run-tool-call.d.ts.map +0 -1
  838. package/dist/agent-runtime/run-tool-errors.d.ts.map +0 -1
  839. package/dist/agent-runtime/run-tool-executor.d.ts +0 -34
  840. package/dist/agent-runtime/run-tool-executor.d.ts.map +0 -1
  841. package/dist/agent-runtime/run-tool-progress.d.ts +0 -21
  842. package/dist/agent-runtime/run-tool-progress.d.ts.map +0 -1
  843. package/dist/agent-runtime/run-turn-preparation.d.ts +0 -25
  844. package/dist/agent-runtime/run-turn-preparation.d.ts.map +0 -1
  845. package/dist/agent-runtime/run-unacquired.d.ts +0 -19
  846. package/dist/agent-runtime/run-unacquired.d.ts.map +0 -1
  847. package/dist/agent-runtime/runtime-admission-gate.d.ts.map +0 -1
  848. package/dist/agent-runtime/runtime-control.d.ts +0 -9
  849. package/dist/agent-runtime/runtime-control.d.ts.map +0 -1
  850. package/dist/agent-runtime/runtime-recovery.d.ts +0 -10
  851. package/dist/agent-runtime/runtime-recovery.d.ts.map +0 -1
  852. package/dist/agent-runtime/runtime-state.d.ts +0 -36
  853. package/dist/agent-runtime/runtime-state.d.ts.map +0 -1
  854. package/dist/agent-runtime/runtime-submit.d.ts +0 -5
  855. package/dist/agent-runtime/runtime-submit.d.ts.map +0 -1
  856. package/dist/agent-runtime/runtime.d.ts +0 -352
  857. package/dist/agent-runtime/runtime.d.ts.map +0 -1
  858. package/dist/agent-runtime/sandbox-binding.d.ts.map +0 -1
  859. package/dist/agent-runtime/sandbox-broker.d.ts.map +0 -1
  860. package/dist/agent-runtime/sandbox-bubblewrap-args.d.ts.map +0 -1
  861. package/dist/agent-runtime/sandbox-bubblewrap-storage.d.ts.map +0 -1
  862. package/dist/agent-runtime/sandbox-bubblewrap.d.ts.map +0 -1
  863. package/dist/agent-runtime/sandbox-coding-adapter.d.ts.map +0 -1
  864. package/dist/agent-runtime/sandbox-contract.d.ts.map +0 -1
  865. package/dist/agent-runtime/sandbox-process-linux.d.ts.map +0 -1
  866. package/dist/agent-runtime/sandbox-process-macos.d.ts.map +0 -1
  867. package/dist/agent-runtime/sandbox-process-owner.d.ts +0 -19
  868. package/dist/agent-runtime/sandbox-process-owner.d.ts.map +0 -1
  869. package/dist/agent-runtime/sandbox-process-spec.d.ts.map +0 -1
  870. package/dist/agent-runtime/sandbox-process-wrapper.d.ts.map +0 -1
  871. package/dist/agent-runtime/sandbox-process.d.ts +0 -8
  872. package/dist/agent-runtime/sandbox-process.d.ts.map +0 -1
  873. package/dist/agent-runtime/sandbox-session.d.ts.map +0 -1
  874. package/dist/agent-runtime/sandbox.d.ts +0 -125
  875. package/dist/agent-runtime/sandbox.d.ts.map +0 -1
  876. package/dist/agent-runtime/schedule-contract.d.ts.map +0 -1
  877. package/dist/agent-runtime/schedule-dispatch.d.ts.map +0 -1
  878. package/dist/agent-runtime/schedule-records.d.ts.map +0 -1
  879. package/dist/agent-runtime/schedule-tools.d.ts +0 -76
  880. package/dist/agent-runtime/schedule-tools.d.ts.map +0 -1
  881. package/dist/agent-runtime/schedules.d.ts.map +0 -1
  882. package/dist/agent-runtime/spill.d.ts +0 -26
  883. package/dist/agent-runtime/spill.d.ts.map +0 -1
  884. package/dist/agent-runtime/sql-events.d.ts.map +0 -1
  885. package/dist/agent-runtime/sql-history.d.ts.map +0 -1
  886. package/dist/agent-runtime/sql-ledger.d.ts.map +0 -1
  887. package/dist/agent-runtime/sql-purge.d.ts.map +0 -1
  888. package/dist/agent-runtime/sql-reads.d.ts.map +0 -1
  889. package/dist/agent-runtime/sql-rows.d.ts.map +0 -1
  890. package/dist/agent-runtime/sql-session.d.ts.map +0 -1
  891. package/dist/agent-runtime/sqlite-bun.d.ts.map +0 -1
  892. package/dist/agent-runtime/sqlite-node.d.ts.map +0 -1
  893. package/dist/agent-runtime/sqlite-purge.d.ts +0 -6
  894. package/dist/agent-runtime/sqlite-purge.d.ts.map +0 -1
  895. package/dist/agent-runtime/sqlite-schema.d.ts +0 -7
  896. package/dist/agent-runtime/sqlite-schema.d.ts.map +0 -1
  897. package/dist/agent-runtime/sqlite-transactions.d.ts +0 -29
  898. package/dist/agent-runtime/sqlite-transactions.d.ts.map +0 -1
  899. package/dist/agent-runtime/sqlite.d.ts +0 -33
  900. package/dist/agent-runtime/sqlite.d.ts.map +0 -1
  901. package/dist/agent-runtime/state-slots.d.ts +0 -48
  902. package/dist/agent-runtime/state-slots.d.ts.map +0 -1
  903. package/dist/agent-runtime/state-tools.d.ts +0 -117
  904. package/dist/agent-runtime/state-tools.d.ts.map +0 -1
  905. package/dist/agent-runtime/store-archive.d.ts.map +0 -1
  906. package/dist/agent-runtime/store-branch.d.ts.map +0 -1
  907. package/dist/agent-runtime/store-capabilities.d.ts.map +0 -1
  908. package/dist/agent-runtime/store-conformance-branch.d.ts +0 -7
  909. package/dist/agent-runtime/store-conformance-branch.d.ts.map +0 -1
  910. package/dist/agent-runtime/store-conformance-capabilities.d.ts +0 -6
  911. package/dist/agent-runtime/store-conformance-capabilities.d.ts.map +0 -1
  912. package/dist/agent-runtime/store-conformance-event-once.d.ts +0 -12
  913. package/dist/agent-runtime/store-conformance-event-once.d.ts.map +0 -1
  914. package/dist/agent-runtime/store-conformance-lifecycle.d.ts +0 -454
  915. package/dist/agent-runtime/store-conformance-lifecycle.d.ts.map +0 -1
  916. package/dist/agent-runtime/store-conformance-ordering.d.ts +0 -18
  917. package/dist/agent-runtime/store-conformance-ordering.d.ts.map +0 -1
  918. package/dist/agent-runtime/store-conformance-seed.d.ts +0 -8
  919. package/dist/agent-runtime/store-conformance-seed.d.ts.map +0 -1
  920. package/dist/agent-runtime/store-conformance-support.d.ts.map +0 -1
  921. package/dist/agent-runtime/store-conformance-terminal.d.ts +0 -12
  922. package/dist/agent-runtime/store-conformance-terminal.d.ts.map +0 -1
  923. package/dist/agent-runtime/store-conformance.d.ts +0 -71
  924. package/dist/agent-runtime/store-conformance.d.ts.map +0 -1
  925. package/dist/agent-runtime/store-create.d.ts.map +0 -1
  926. package/dist/agent-runtime/store-driver-contract.d.ts +0 -1016
  927. package/dist/agent-runtime/store-driver-contract.d.ts.map +0 -1
  928. package/dist/agent-runtime/store-event-once.d.ts +0 -37
  929. package/dist/agent-runtime/store-event-once.d.ts.map +0 -1
  930. package/dist/agent-runtime/store-events.d.ts +0 -2231
  931. package/dist/agent-runtime/store-events.d.ts.map +0 -1
  932. package/dist/agent-runtime/store-memory-archive.d.ts.map +0 -1
  933. package/dist/agent-runtime/store-memory-events.d.ts +0 -7
  934. package/dist/agent-runtime/store-memory-events.d.ts.map +0 -1
  935. package/dist/agent-runtime/store-memory.d.ts.map +0 -1
  936. package/dist/agent-runtime/store-migrations/v1-to-v2.d.ts +0 -6
  937. package/dist/agent-runtime/store-migrations/v1-to-v2.d.ts.map +0 -1
  938. package/dist/agent-runtime/store-migrations/v2-to-v3.d.ts +0 -14
  939. package/dist/agent-runtime/store-migrations/v2-to-v3.d.ts.map +0 -1
  940. package/dist/agent-runtime/store-migrations/v3-to-v4.d.ts +0 -4
  941. package/dist/agent-runtime/store-migrations/v3-to-v4.d.ts.map +0 -1
  942. package/dist/agent-runtime/store-mutate.d.ts.map +0 -1
  943. package/dist/agent-runtime/store-purge.d.ts.map +0 -1
  944. package/dist/agent-runtime/store-reads.d.ts +0 -29
  945. package/dist/agent-runtime/store-reads.d.ts.map +0 -1
  946. package/dist/agent-runtime/store-reduce-history.d.ts +0 -10
  947. package/dist/agent-runtime/store-reduce-history.d.ts.map +0 -1
  948. package/dist/agent-runtime/store-reduce-run.d.ts +0 -14
  949. package/dist/agent-runtime/store-reduce-run.d.ts.map +0 -1
  950. package/dist/agent-runtime/store-reduce-shared.d.ts +0 -78
  951. package/dist/agent-runtime/store-reduce-shared.d.ts.map +0 -1
  952. package/dist/agent-runtime/store-reduce-terminal.d.ts +0 -6
  953. package/dist/agent-runtime/store-reduce-terminal.d.ts.map +0 -1
  954. package/dist/agent-runtime/store-reducer.d.ts +0 -24
  955. package/dist/agent-runtime/store-reducer.d.ts.map +0 -1
  956. package/dist/agent-runtime/store-replay.d.ts.map +0 -1
  957. package/dist/agent-runtime/store-snapshot.d.ts +0 -19
  958. package/dist/agent-runtime/store-snapshot.d.ts.map +0 -1
  959. package/dist/agent-runtime/store.d.ts +0 -3032
  960. package/dist/agent-runtime/store.d.ts.map +0 -1
  961. package/dist/agent-runtime/testing.d.ts +0 -46
  962. package/dist/agent-runtime/testing.d.ts.map +0 -1
  963. package/dist/agent-runtime/workspace-glob.d.ts.map +0 -1
  964. package/dist/index-18pf56dq.js +0 -409
  965. package/dist/index-1gmgwfn3.js +0 -439
  966. package/dist/index-23wn8sgf.js +0 -47
  967. package/dist/index-27hck3z2.js +0 -307
  968. package/dist/index-27srek2g.js +0 -3781
  969. package/dist/index-360j58vb.js +0 -63
  970. package/dist/index-67pnt4bh.js +0 -174
  971. package/dist/index-6kpwkpgx.js +0 -415
  972. package/dist/index-6xw1wf4m.js +0 -969
  973. package/dist/index-6yb4stq3.js +0 -224
  974. package/dist/index-76yhxa41.js +0 -725
  975. package/dist/index-79vqbjcz.js +0 -26
  976. package/dist/index-a84wj6y8.js +0 -510
  977. package/dist/index-b23s6e2c.js +0 -158
  978. package/dist/index-cb4nnvfr.js +0 -40
  979. package/dist/index-ek9w11r0.js +0 -40
  980. package/dist/index-er483f3w.js +0 -601
  981. package/dist/index-fjac2w5e.js +0 -3543
  982. package/dist/index-ga6avd48.js +0 -53
  983. package/dist/index-hy4653g4.js +0 -345
  984. package/dist/index-j903yhp4.js +0 -121
  985. package/dist/index-jzdbkanz.js +0 -215
  986. package/dist/index-k9g061ma.js +0 -164
  987. package/dist/index-krekhmp7.js +0 -707
  988. package/dist/index-ky79wwgs.js +0 -2872
  989. package/dist/index-mgr0mdqp.js +0 -271
  990. package/dist/index-mx2gya05.js +0 -465
  991. package/dist/index-nfeafbzh.js +0 -7379
  992. package/dist/index-ngwf1s3c.js +0 -51
  993. package/dist/index-pjjh91vw.js +0 -53
  994. package/dist/index-qv5v6w9c.js +0 -696
  995. package/dist/index-rj32hkkp.js +0 -305
  996. package/dist/index-t5zp1jjj.js +0 -77
  997. package/dist/index-v5hmyef8.js +0 -951
  998. package/dist/index-vv0hxrmy.js +0 -295
  999. package/dist/index-vxm0ya3f.js +0 -707
  1000. package/dist/index-xtxxt87z.js +0 -349
  1001. package/dist/index-zag9sjpd.js +0 -1210
  1002. package/dist/index-zk839vzf.js +0 -231
  1003. package/llms/upgrading-0.128.0-0.134.0.txt +0 -639
  1004. /package/dist/agent-runtime/{control-interaction-schema.d.ts → browser/control-interaction-schema.d.ts} +0 -0
  1005. /package/dist/agent-runtime/{react.d.ts → browser/react.d.ts} +0 -0
  1006. /package/dist/agent-runtime/{coding-search-automaton.d.ts → coding/coding-search-automaton.d.ts} +0 -0
  1007. /package/dist/agent-runtime/{coding-search-case-fold.d.ts → coding/coding-search-case-fold.d.ts} +0 -0
  1008. /package/dist/agent-runtime/{coding-search-class-ranges.d.ts → coding/coding-search-class-ranges.d.ts} +0 -0
  1009. /package/dist/agent-runtime/{coding-search-contract.d.ts → coding/coding-search-contract.d.ts} +0 -0
  1010. /package/dist/agent-runtime/{coding-search-limits.d.ts → coding/coding-search-limits.d.ts} +0 -0
  1011. /package/dist/agent-runtime/{coding-search-matcher.d.ts → coding/coding-search-matcher.d.ts} +0 -0
  1012. /package/dist/agent-runtime/{coding-search-output.d.ts → coding/coding-search-output.d.ts} +0 -0
  1013. /package/dist/agent-runtime/{coding-search-regex-syntax.d.ts → coding/coding-search-regex-syntax.d.ts} +0 -0
  1014. /package/dist/agent-runtime/{coding-search-unit-classes.d.ts → coding/coding-search-unit-classes.d.ts} +0 -0
  1015. /package/dist/agent-runtime/{coding-tool-files.d.ts → coding/coding-tool-files.d.ts} +0 -0
  1016. /package/dist/agent-runtime/{coding-tool-listing.d.ts → coding/coding-tool-listing.d.ts} +0 -0
  1017. /package/dist/agent-runtime/{coding-tool-refusals.d.ts → coding/coding-tool-refusals.d.ts} +0 -0
  1018. /package/dist/agent-runtime/{coding-tool-search-patch.d.ts → coding/coding-tool-search-patch.d.ts} +0 -0
  1019. /package/dist/agent-runtime/{coding-tool-shell.d.ts → coding/coding-tool-shell.d.ts} +0 -0
  1020. /package/dist/agent-runtime/{coding-tool-utf8.d.ts → coding/coding-tool-utf8.d.ts} +0 -0
  1021. /package/dist/agent-runtime/{coding-tools.d.ts → coding/coding-tools.d.ts} +0 -0
  1022. /package/dist/agent-runtime/{contained-scan-budget.d.ts → coding/contained-scan-budget.d.ts} +0 -0
  1023. /package/dist/agent-runtime/{contained-scan-contract.d.ts → coding/contained-scan-contract.d.ts} +0 -0
  1024. /package/dist/agent-runtime/{workspace-glob.d.ts → coding/workspace-glob.d.ts} +0 -0
  1025. /package/dist/agent-runtime/{harness-resources.d.ts → harness/harness-resources.d.ts} +0 -0
  1026. /package/dist/agent-runtime/{coordinator.d.ts → loop/coordinator.d.ts} +0 -0
  1027. /package/dist/agent-runtime/{invocation-failure.d.ts → loop/invocation-failure.d.ts} +0 -0
  1028. /package/dist/agent-runtime/{owned-provider-stream.d.ts → loop/owned-provider-stream.d.ts} +0 -0
  1029. /package/dist/agent-runtime/{run-tool-errors.d.ts → loop/run-tool-errors.d.ts} +0 -0
  1030. /package/dist/agent-runtime/{runtime-admission-gate.d.ts → loop/runtime-admission-gate.d.ts} +0 -0
  1031. /package/dist/agent-runtime/{anthropic-sse.d.ts → providers/anthropic-sse.d.ts} +0 -0
  1032. /package/dist/agent-runtime/{anthropic.d.ts → providers/anthropic.d.ts} +0 -0
  1033. /package/dist/agent-runtime/{models-driver-telemetry.d.ts → providers/models-driver-telemetry.d.ts} +0 -0
  1034. /package/dist/agent-runtime/{models.d.ts → providers/models.d.ts} +0 -0
  1035. /package/dist/agent-runtime/{openai-messages.d.ts → providers/openai-messages.d.ts} +0 -0
  1036. /package/dist/agent-runtime/{openai-sse-state.d.ts → providers/openai-sse-state.d.ts} +0 -0
  1037. /package/dist/agent-runtime/{openai-sse.d.ts → providers/openai-sse.d.ts} +0 -0
  1038. /package/dist/agent-runtime/{openai.d.ts → providers/openai.d.ts} +0 -0
  1039. /package/dist/agent-runtime/{openrouter-benchmarks.d.ts → providers/openrouter-benchmarks.d.ts} +0 -0
  1040. /package/dist/agent-runtime/{openrouter-catalog-cache.d.ts → providers/openrouter-catalog-cache.d.ts} +0 -0
  1041. /package/dist/agent-runtime/{openrouter-catalog.d.ts → providers/openrouter-catalog.d.ts} +0 -0
  1042. /package/dist/agent-runtime/{openrouter-models.d.ts → providers/openrouter-models.d.ts} +0 -0
  1043. /package/dist/agent-runtime/{openrouter-route.d.ts → providers/openrouter-route.d.ts} +0 -0
  1044. /package/dist/agent-runtime/{openrouter.d.ts → providers/openrouter.d.ts} +0 -0
  1045. /package/dist/agent-runtime/{provider-content.d.ts → providers/provider-content.d.ts} +0 -0
  1046. /package/dist/agent-runtime/{provider-http.d.ts → providers/provider-http.d.ts} +0 -0
  1047. /package/dist/agent-runtime/{provider-journal.d.ts → providers/provider-journal.d.ts} +0 -0
  1048. /package/dist/agent-runtime/{provider-json-schema-strip.d.ts → providers/provider-json-schema-strip.d.ts} +0 -0
  1049. /package/dist/agent-runtime/{provider-sse.d.ts → providers/provider-sse.d.ts} +0 -0
  1050. /package/dist/agent-runtime/{sandbox-binding.d.ts → sandbox/sandbox-binding.d.ts} +0 -0
  1051. /package/dist/agent-runtime/{sandbox-broker.d.ts → sandbox/sandbox-broker.d.ts} +0 -0
  1052. /package/dist/agent-runtime/{sandbox-bubblewrap-args.d.ts → sandbox/sandbox-bubblewrap-args.d.ts} +0 -0
  1053. /package/dist/agent-runtime/{sandbox-bubblewrap-storage.d.ts → sandbox/sandbox-bubblewrap-storage.d.ts} +0 -0
  1054. /package/dist/agent-runtime/{sandbox-bubblewrap.d.ts → sandbox/sandbox-bubblewrap.d.ts} +0 -0
  1055. /package/dist/agent-runtime/{sandbox-coding-adapter.d.ts → sandbox/sandbox-coding-adapter.d.ts} +0 -0
  1056. /package/dist/agent-runtime/{sandbox-contract.d.ts → sandbox/sandbox-contract.d.ts} +0 -0
  1057. /package/dist/agent-runtime/{sandbox-process-linux.d.ts → sandbox/sandbox-process-linux.d.ts} +0 -0
  1058. /package/dist/agent-runtime/{sandbox-process-macos.d.ts → sandbox/sandbox-process-macos.d.ts} +0 -0
  1059. /package/dist/agent-runtime/{sandbox-process-spec.d.ts → sandbox/sandbox-process-spec.d.ts} +0 -0
  1060. /package/dist/agent-runtime/{sandbox-process-wrapper.d.ts → sandbox/sandbox-process-wrapper.d.ts} +0 -0
  1061. /package/dist/agent-runtime/{sandbox-session.d.ts → sandbox/sandbox-session.d.ts} +0 -0
  1062. /package/dist/agent-runtime/{archive-projection.d.ts → stores/archive-projection.d.ts} +0 -0
  1063. /package/dist/agent-runtime/{archive-spill.d.ts → stores/archive-spill.d.ts} +0 -0
  1064. /package/dist/agent-runtime/{branch-contract.d.ts → stores/branch-contract.d.ts} +0 -0
  1065. /package/dist/agent-runtime/{branch-provider.d.ts → stores/branch-provider.d.ts} +0 -0
  1066. /package/dist/agent-runtime/{branch-refusal.d.ts → stores/branch-refusal.d.ts} +0 -0
  1067. /package/dist/agent-runtime/{branch-runtime-tools.d.ts → stores/branch-runtime-tools.d.ts} +0 -0
  1068. /package/dist/agent-runtime/{branch-transitions.d.ts → stores/branch-transitions.d.ts} +0 -0
  1069. /package/dist/agent-runtime/{child-blocking.d.ts → stores/child-blocking.d.ts} +0 -0
  1070. /package/dist/agent-runtime/{children-control.d.ts → stores/children-control.d.ts} +0 -0
  1071. /package/dist/agent-runtime/{children-spawn.d.ts → stores/children-spawn.d.ts} +0 -0
  1072. /package/dist/agent-runtime/{children-state.d.ts → stores/children-state.d.ts} +0 -0
  1073. /package/dist/agent-runtime/{children-usage.d.ts → stores/children-usage.d.ts} +0 -0
  1074. /package/dist/agent-runtime/{children.d.ts → stores/children.d.ts} +0 -0
  1075. /package/dist/agent-runtime/{conversations.d.ts → stores/conversations.d.ts} +0 -0
  1076. /package/dist/agent-runtime/{event-search-postgres.d.ts → stores/event-search-postgres.d.ts} +0 -0
  1077. /package/dist/agent-runtime/{event-search-terms.d.ts → stores/event-search-terms.d.ts} +0 -0
  1078. /package/dist/agent-runtime/{event-search.d.ts → stores/event-search.d.ts} +0 -0
  1079. /package/dist/agent-runtime/{postgres-schema.d.ts → stores/postgres-schema.d.ts} +0 -0
  1080. /package/dist/agent-runtime/{purge.d.ts → stores/purge.d.ts} +0 -0
  1081. /package/dist/agent-runtime/{schedule-contract.d.ts → stores/schedule-contract.d.ts} +0 -0
  1082. /package/dist/agent-runtime/{schedule-dispatch.d.ts → stores/schedule-dispatch.d.ts} +0 -0
  1083. /package/dist/agent-runtime/{schedule-records.d.ts → stores/schedule-records.d.ts} +0 -0
  1084. /package/dist/agent-runtime/{schedules.d.ts → stores/schedules.d.ts} +0 -0
  1085. /package/dist/agent-runtime/{sql-events.d.ts → stores/sql-events.d.ts} +0 -0
  1086. /package/dist/agent-runtime/{sql-history.d.ts → stores/sql-history.d.ts} +0 -0
  1087. /package/dist/agent-runtime/{sql-ledger.d.ts → stores/sql-ledger.d.ts} +0 -0
  1088. /package/dist/agent-runtime/{sql-purge.d.ts → stores/sql-purge.d.ts} +0 -0
  1089. /package/dist/agent-runtime/{sql-reads.d.ts → stores/sql-reads.d.ts} +0 -0
  1090. /package/dist/agent-runtime/{sql-rows.d.ts → stores/sql-rows.d.ts} +0 -0
  1091. /package/dist/agent-runtime/{sql-session.d.ts → stores/sql-session.d.ts} +0 -0
  1092. /package/dist/agent-runtime/{sqlite-bun.d.ts → stores/sqlite-bun.d.ts} +0 -0
  1093. /package/dist/agent-runtime/{sqlite-node.d.ts → stores/sqlite-node.d.ts} +0 -0
  1094. /package/dist/agent-runtime/{store-archive.d.ts → stores/store-archive.d.ts} +0 -0
  1095. /package/dist/agent-runtime/{store-branch.d.ts → stores/store-branch.d.ts} +0 -0
  1096. /package/dist/agent-runtime/{store-capabilities.d.ts → stores/store-capabilities.d.ts} +0 -0
  1097. /package/dist/agent-runtime/{store-create.d.ts → stores/store-create.d.ts} +0 -0
  1098. /package/dist/agent-runtime/{store-memory-archive.d.ts → stores/store-memory-archive.d.ts} +0 -0
  1099. /package/dist/agent-runtime/{store-memory.d.ts → stores/store-memory.d.ts} +0 -0
  1100. /package/dist/agent-runtime/{store-mutate.d.ts → stores/store-mutate.d.ts} +0 -0
  1101. /package/dist/agent-runtime/{store-purge.d.ts → stores/store-purge.d.ts} +0 -0
  1102. /package/dist/agent-runtime/{store-replay.d.ts → stores/store-replay.d.ts} +0 -0
  1103. /package/dist/agent-runtime/{fault-bench.d.ts → testing/fault-bench.d.ts} +0 -0
  1104. /package/dist/agent-runtime/{store-conformance-support.d.ts → testing/store-conformance-support.d.ts} +0 -0
@@ -1,3543 +0,0 @@
1
- import {
2
- validateDeclaredOutput
3
- } from "./index-78da4g74.js";
4
- import {
5
- HELP_SHOWN_KEYWORDS,
6
- STANDARD_STRING_FORMATS
7
- } from "./index-27hck3z2.js";
8
- import {
9
- toJsonSchema,
10
- jsonSchemaFields
11
- } from "./index-ngwf1s3c.js";
12
- import {
13
- toolSurfaceOutputSchema,
14
- toToolName,
15
- assertUniqueToolName,
16
- buildToolPresentationSchema,
17
- projectedContractToolName
18
- } from "./index-v5hmyef8.js";
19
- import {
20
- unwrapZodWrappers,
21
- objectShapeKeys,
22
- mergeSchemas
23
- } from "./index-360j58vb.js";
24
- import {
25
- jsonSchemaObjectCoercionMembers
26
- } from "./index-dsa676h8.js";
27
- import {
28
- coerceJsonArgs2
29
- } from "./index-j903yhp4.js";
30
- import {
31
- isInspectOnlyLifecycle,
32
- inspectOnlyError,
33
- resolveOptionalCliToolAccess,
34
- toolResultFromError,
35
- toolErrorFromResult,
36
- toolCauseFromResult,
37
- createToolRunner,
38
- formatToolError
39
- } from "./index-er483f3w.js";
40
- import {
41
- isRepeatableRead
42
- } from "./index-0x4mnwg5.js";
43
- import {
44
- MCP_FILE_NAME_META_KEY2,
45
- McpImageContentSchema,
46
- McpAudioContentSchema
47
- } from "./index-gy9x38a2.js";
48
- import {
49
- readContractStreamItems,
50
- contractStreamLifetimeExceeded
51
- } from "./index-yrhw10ef.js";
52
- import {
53
- writeContainedFile
54
- } from "./index-rjs94dny.js";
55
- import {
56
- openPinnedDirectory,
57
- isSafeEntryName,
58
- containedEntryMetadata
59
- } from "./index-xrgn784x.js";
60
- import {
61
- pollUntil,
62
- mediaExtension
63
- } from "./index-mh3jdb25.js";
64
- import {
65
- fetchGuarded,
66
- readCapped
67
- } from "./index-dz6tstcp.js";
68
- import {
69
- projectJsonSafe,
70
- stringifyJsonSafe
71
- } from "./index-5awtbyns.js";
72
- import {
73
- collectToolSurface
74
- } from "./index-pjjh91vw.js";
75
- import {
76
- assertNoLegacyTransports
77
- } from "./index-akfgymyr.js";
78
- import {
79
- isUnsafeKey,
80
- safeJsonParse
81
- } from "./index-zsarb5xp.js";
82
- import {
83
- errnoOf
84
- } from "./index-jj9228tt.js";
85
- import {
86
- formatZodError2
87
- } from "./index-1eeqpadm.js";
88
- import {
89
- AppError2,
90
- STITCH_ERROR_STATUS2
91
- } from "./index-7fjbdga8.js";
92
- import {
93
- UNIX_CLIENT_TRANSPORT_ERROR_NAME,
94
- UNIX_CLIENT_TRANSPORT_ERROR_CODES,
95
- UNIX_CLIENT_DELIVERY_STATES
96
- } from "./index-cv9b7fz2.js";
97
- import {
98
- assertPositiveSafeInteger
99
- } from "./index-gr0kxymw.js";
100
- import {
101
- isRecord,
102
- isAsyncIterable,
103
- transportResult
104
- } from "./index-ps3djm8d.js";
105
-
106
- // src/tools/cli/args-fields.ts
107
- import { z } from "zod";
108
-
109
- // src/tools/cli/argument-error.ts
110
- class CliArgumentError2 extends Error {
111
- name = "CliArgumentError";
112
- }
113
-
114
- // src/tools/cli/args-fields.ts
115
- function appendCliOptionValue(raw, name, value, info) {
116
- const existing = raw.get(name);
117
- const repeatable = info?.kind === "array" || !name.includes(".") && info === undefined;
118
- if (existing !== undefined) {
119
- if (!repeatable) {
120
- throw new CliArgumentError2(`--${name} was passed ${existing.length + 1} times`);
121
- }
122
- existing.push(value);
123
- } else {
124
- raw.set(name, [value]);
125
- }
126
- }
127
- function literalKind(field) {
128
- const base = unwrapZodWrappers(field);
129
- if (base instanceof z.ZodLiteral) {
130
- const kinds = new Set;
131
- for (const value of base.values) {
132
- const kind = typeof value;
133
- if (kind !== "boolean" && kind !== "number" && kind !== "bigint" && kind !== "string")
134
- return;
135
- kinds.add(kind);
136
- }
137
- return kinds.size === 1 ? kinds.values().next().value : undefined;
138
- }
139
- if (base instanceof z.ZodUnion) {
140
- const kinds = base.def.options.map(literalKind);
141
- const first = kinds[0];
142
- return first !== undefined && kinds.every((kind) => kind === first) ? first : undefined;
143
- }
144
- return;
145
- }
146
- function classify(field) {
147
- if (field instanceof z.ZodBoolean)
148
- return "boolean";
149
- if (field instanceof z.ZodNumber)
150
- return "number";
151
- if (field instanceof z.ZodBigInt)
152
- return "bigint";
153
- if (field instanceof z.ZodDate)
154
- return "date";
155
- if (field instanceof z.ZodEnum)
156
- return "enum";
157
- if (field instanceof z.ZodArray)
158
- return "array";
159
- if (field instanceof z.ZodObject)
160
- return "object";
161
- const primitiveLiteral = literalKind(field);
162
- if (primitiveLiteral !== undefined)
163
- return primitiveLiteral;
164
- if (field instanceof z.ZodString)
165
- return "string";
166
- return "other";
167
- }
168
- function mergeField(fields, name, info) {
169
- const existing = fields.get(name);
170
- if (!existing) {
171
- fields.set(name, info);
172
- return;
173
- }
174
- if (existing.kind === info.kind) {
175
- if (existing.kind === "array" && existing.elementKind !== info.elementKind) {
176
- fields.set(name, { kind: "array", elementKind: "other" });
177
- } else if (existing.kind === "boolean" && existing.pureBoolean !== info.pureBoolean) {
178
- fields.set(name, { kind: "boolean" });
179
- }
180
- return;
181
- }
182
- if (existing.kind === "boolean" || info.kind === "boolean") {
183
- fields.set(name, { kind: "boolean" });
184
- return;
185
- }
186
- fields.set(name, { kind: "other" });
187
- }
188
- function collectSchemaFields(schema, fields, inUnion = false) {
189
- const base = unwrapZodWrappers(schema);
190
- if (base instanceof z.ZodObject) {
191
- for (const [name, raw] of Object.entries(base.shape)) {
192
- const fieldBase = unwrapZodWrappers(raw);
193
- const kind = classify(fieldBase);
194
- if (kind === "array" && fieldBase instanceof z.ZodArray) {
195
- mergeField(fields, name, {
196
- kind,
197
- elementKind: classify(unwrapZodWrappers(fieldBase.element))
198
- });
199
- } else {
200
- mergeField(fields, name, {
201
- kind,
202
- ...fieldBase instanceof z.ZodNumber && fieldBase.isInt && { integer: true },
203
- ...kind === "boolean" && !inUnion && { pureBoolean: true }
204
- });
205
- }
206
- }
207
- return;
208
- }
209
- if (base instanceof z.ZodUnion) {
210
- for (const option of base.def.options)
211
- collectSchemaFields(option, fields, true);
212
- return;
213
- }
214
- if (base instanceof z.ZodIntersection) {
215
- collectSchemaFields(base.def.left, fields, inUnion);
216
- collectSchemaFields(base.def.right, fields, inUnion);
217
- return;
218
- }
219
- }
220
- function describeSchemaFields(schema) {
221
- const fields = new Map;
222
- if (schema)
223
- collectSchemaFields(schema, fields);
224
- return fields;
225
- }
226
- function infoOf(field) {
227
- const base = unwrapZodWrappers(field);
228
- const kind = classify(base);
229
- if (kind === "array" && base instanceof z.ZodArray) {
230
- return { kind, elementKind: classify(unwrapZodWrappers(base.element)) };
231
- }
232
- return {
233
- kind,
234
- ...base instanceof z.ZodNumber && base.isInt && { integer: true },
235
- ...kind === "boolean" && { pureBoolean: true }
236
- };
237
- }
238
- function mergePathInfos(infos, composition) {
239
- const present = infos.filter((info) => info !== undefined);
240
- if (present.length === 0)
241
- return;
242
- if (composition === "union" && present.some((info) => info.kind === "other")) {
243
- return { kind: "other" };
244
- }
245
- const concrete = present.filter((info) => info.kind !== "other");
246
- const candidates = composition === "intersection" && concrete.length > 0 ? concrete : present;
247
- const first = candidates[0];
248
- if (!first)
249
- return;
250
- if (candidates.every((info) => info.kind === first.kind)) {
251
- const elementKind = first.kind === "array" ? candidates.every((info) => info.elementKind === first.elementKind) ? first.elementKind : "other" : undefined;
252
- const pureBoolean = first.kind === "boolean" && (composition === "intersection" ? candidates.some((info) => info.pureBoolean) : infos.every((info) => info?.pureBoolean));
253
- return {
254
- kind: first.kind,
255
- ...elementKind && { elementKind },
256
- ...first.integer && candidates.every((info) => info.integer) && { integer: true },
257
- ...pureBoolean && { pureBoolean: true }
258
- };
259
- }
260
- return candidates.some((info) => info.kind === "boolean") ? { kind: "boolean" } : { kind: "other" };
261
- }
262
- function pathInfo(schema, path) {
263
- const guarded = jsonSchemaObjectCoercionMembers(schema);
264
- if (guarded) {
265
- return mergePathInfos(guarded.map((member) => pathInfo(member, path)), "intersection");
266
- }
267
- const base = unwrapZodWrappers(schema);
268
- if (base !== schema)
269
- return pathInfo(base, path);
270
- if (base instanceof z.ZodUnion) {
271
- return mergePathInfos(base.def.options.map((member) => pathInfo(member, path)), "union");
272
- }
273
- if (base instanceof z.ZodIntersection) {
274
- return mergePathInfos([pathInfo(base.def.left, path), pathInfo(base.def.right, path)], "intersection");
275
- }
276
- if (path.length === 0)
277
- return infoOf(base);
278
- const [name, ...rest] = path;
279
- if (name === undefined)
280
- return infoOf(base);
281
- if (base instanceof z.ZodObject) {
282
- const member = base.shape[name] ?? base.def.catchall;
283
- return member ? pathInfo(member, rest) : undefined;
284
- }
285
- if (base instanceof z.ZodRecord)
286
- return pathInfo(base.valueType, rest);
287
- return;
288
- }
289
- function describeSchemaPath(schema, path) {
290
- if (!schema || path.length === 0)
291
- return;
292
- return pathInfo(schema, path);
293
- }
294
- var BOOL_WORDS = {
295
- true: { value: true, separate: true },
296
- "1": { value: true, separate: false },
297
- yes: { value: true, separate: false },
298
- on: { value: true, separate: false },
299
- false: { value: false, separate: true },
300
- "0": { value: false, separate: false },
301
- no: { value: false, separate: false },
302
- off: { value: false, separate: false }
303
- };
304
- function lookupBoolWord(value) {
305
- const key = value.toLowerCase();
306
- return Object.hasOwn(BOOL_WORDS, key) ? BOOL_WORDS[key] : undefined;
307
- }
308
- function separateBoolValue(next) {
309
- if (next === undefined)
310
- return;
311
- const row = lookupBoolWord(next);
312
- return row?.separate ? row.value : undefined;
313
- }
314
- function isReservedBoolWord(value) {
315
- return lookupBoolWord(value) !== undefined;
316
- }
317
- function parseReservedBool(name, value) {
318
- const row = lookupBoolWord(value);
319
- if (row !== undefined)
320
- return row.value;
321
- throw new CliArgumentError2(`--${name} expects a boolean (true/false), got "${value}"`);
322
- }
323
- function coerceScalar(kind, value) {
324
- switch (kind) {
325
- case "boolean":
326
- return lookupBoolWord(value)?.value ?? value;
327
- case "number": {
328
- const n = Number(value);
329
- return value.trim() !== "" && !Number.isNaN(n) ? n : value;
330
- }
331
- case "bigint":
332
- try {
333
- return BigInt(value);
334
- } catch {
335
- return value;
336
- }
337
- case "date": {
338
- const d = new Date(value);
339
- return Number.isNaN(d.getTime()) ? value : d;
340
- }
341
- default:
342
- return value;
343
- }
344
- }
345
- function looseCoerce(value) {
346
- if (value === "true")
347
- return true;
348
- if (value === "false")
349
- return false;
350
- const number = Number(value);
351
- return value.trim() !== "" && !Number.isNaN(number) ? number : value;
352
- }
353
- function refuseGlobalOption(issue) {
354
- const field = issue?.path[0];
355
- const where = typeof field === "string" ? `--${field}` : "application option";
356
- throw new CliArgumentError2(`${where}: ${issue?.message ?? "invalid value"}`);
357
- }
358
- function parseCliGlobalValues(schema, raw) {
359
- const base = raw ?? {};
360
- if (schema === undefined)
361
- return transportResult(base);
362
- let coerced;
363
- try {
364
- coerced = coerceJsonArgs2(base, schema);
365
- } catch (error) {
366
- if (error instanceof z.ZodError)
367
- refuseGlobalOption(error.issues[0]);
368
- throw error;
369
- }
370
- const parsed = schema.safeParse(coerced);
371
- if (!parsed.success)
372
- refuseGlobalOption(parsed.error.issues[0]);
373
- return parsed.data;
374
- }
375
- function looksLikeJson(value) {
376
- const t = value.trim();
377
- return t.startsWith("[") || t.startsWith("{");
378
- }
379
- function expectedValue(kind, integer) {
380
- if (kind === "number")
381
- return integer ? "a whole number" : "a number";
382
- if (kind === "bigint")
383
- return "a whole number";
384
- if (kind === "date")
385
- return "a date";
386
- return;
387
- }
388
- function coerceNamed(label, kind, integer, value) {
389
- const coerced = coerceScalar(kind, value);
390
- const expected = expectedValue(kind, integer);
391
- if (expected !== undefined && typeof coerced === "string") {
392
- throw new CliArgumentError2(`${label} expects ${expected}, got "${value}"`);
393
- }
394
- if (integer && typeof coerced === "number" && !Number.isInteger(coerced)) {
395
- throw new CliArgumentError2(`${label} expects ${expected}, got "${value}"`);
396
- }
397
- return coerced;
398
- }
399
- function coerceField(info, values, label) {
400
- const last = values[values.length - 1] ?? "";
401
- if (!info)
402
- return values.length > 1 ? values : last;
403
- if (info.kind === "array") {
404
- if (values.length === 1 && looksLikeJson(last))
405
- return last;
406
- return values.map((v) => coerceNamed(label, info.elementKind ?? "string", false, v));
407
- }
408
- if (info.kind === "object")
409
- return last;
410
- return coerceNamed(label, info.kind, info.integer, last);
411
- }
412
- function setNested(target, path, value) {
413
- const unsafe = path.find(isUnsafeKey);
414
- if (unsafe !== undefined) {
415
- throw new CliArgumentError2(`Unsafe option path segment "${unsafe}"`);
416
- }
417
- let node = target;
418
- for (let i = 0;i < path.length - 1; i++) {
419
- const key = path[i];
420
- if (key === undefined)
421
- return;
422
- const next = node[key];
423
- if (isRecord(next)) {
424
- node = next;
425
- } else {
426
- const created = {};
427
- node[key] = created;
428
- node = created;
429
- }
430
- }
431
- const leaf = path[path.length - 1];
432
- if (leaf !== undefined)
433
- node[leaf] = value;
434
- }
435
-
436
- // src/tools/cli/format.ts
437
- var DEFAULT_EXIT_CODES2 = {
438
- VALIDATION_ERROR: 1,
439
- BAD_REQUEST: 1,
440
- UNAUTHORIZED: 2,
441
- FORBIDDEN: 3,
442
- NOT_FOUND: 4,
443
- UNKNOWN_OPERATION: 4,
444
- CONFLICT: 5,
445
- RATE_LIMITED: 6,
446
- TIMEOUT: 7,
447
- REQUEST_ABORTED: 130,
448
- REQUEST_TIMEOUT: 7,
449
- CONNECTION_TIMEOUT: 7,
450
- STREAM_LIFETIME_EXCEEDED: 7,
451
- CONNECTION_RESPONSE_TOO_LARGE: 1,
452
- CONNECTION_REQUEST_FAILED: 1,
453
- UPSTREAM_TOOL_ERROR: 1,
454
- MCP_STRUCTURED_CONTENT_MISSING: 1,
455
- WAIT_FAILED: 1,
456
- CLI_COMMAND_UNAVAILABLE: 1,
457
- CLI_PRESENTATION_FAILED: 8,
458
- UNIX_CONNECT_FAILED: 9,
459
- UNIX_TARGET_REFUSED: 9,
460
- UNIX_CLIENT_CLOSED: 9,
461
- UNIX_CONNECTION_LIMIT: 9,
462
- UNIX_REQUEST_TOO_LARGE: 9,
463
- UNIX_DELIVERY_UNCERTAIN: 10,
464
- UNIX_HEADERS_TIMEOUT: 10,
465
- INTERNAL_SERVER_ERROR: 1
466
- };
467
- function cliExitCode2(result, exitCodes) {
468
- if (result.ok)
469
- return 0;
470
- const codes = { ...DEFAULT_EXIT_CODES2, ...exitCodes };
471
- return Object.hasOwn(codes, result.code) ? codes[result.code] ?? 1 : 1;
472
- }
473
- function emitResult2(result, writers, opts) {
474
- if (result.ok) {
475
- if (result.data === undefined)
476
- return 0;
477
- const text = stringifyJsonSafe(result.data, opts.json ? undefined : 2);
478
- writers.stdout(`${text}
479
- `);
480
- return 0;
481
- }
482
- const error = formatToolError(result, opts.toolName, opts.errorHint);
483
- const text = opts.json ? JSON.stringify(error) : JSON.stringify(error, null, 2);
484
- writers.stderr(`${text}
485
- `);
486
- return cliExitCode2(result, opts.exitCodes);
487
- }
488
- function presentationFailureHint(repeatable, printed) {
489
- if (repeatable) {
490
- return "The result was not printed: this command only reads. Repeat it with a corrected view.";
491
- }
492
- return printed ? "The complete, unformatted result is on stdout. Do not repeat the command to recover its result." : "The command returned no result. Do not repeat it.";
493
- }
494
- function emitPresentationFailure(result, failure, writers, opts) {
495
- const printed = !opts.repeatable && result.data !== undefined;
496
- if (printed)
497
- emitResult2(result, writers, opts);
498
- return emitResult2({
499
- ok: false,
500
- code: "CLI_PRESENTATION_FAILED",
501
- retryable: false,
502
- details: {
503
- message: "The command completed successfully, but its result presentation failed.",
504
- command: opts.toolName,
505
- operationSucceeded: true,
506
- resultOnStdout: printed,
507
- cause: formatToolError(failure)
508
- },
509
- hint: presentationFailureHint(opts.repeatable, printed)
510
- }, writers, { json: opts.json, toolName: opts.toolName, exitCodes: opts.exitCodes });
511
- }
512
-
513
- // src/tools/cli/view.ts
514
- var ABSENT = "(absent)";
515
- function selectRecords(data) {
516
- if (Array.isArray(data))
517
- return data;
518
- if (isRecord(data)) {
519
- const arrays = Object.entries(data).filter(([, value]) => Array.isArray(value));
520
- const only = arrays[0];
521
- if (arrays.length === 1 && only && Array.isArray(only[1]))
522
- return only[1];
523
- if (arrays.length > 1) {
524
- throw new CliArgumentError2(`an aggregate needs one collection, but the result carries several: ${arrays.map(([key]) => key).join(", ")} — name the shape you want with jq instead`);
525
- }
526
- }
527
- throw new CliArgumentError2("an aggregate needs a collection; this result is not one");
528
- }
529
- function isAbsent(value) {
530
- return value === undefined || value === null;
531
- }
532
- function readField(record, path) {
533
- let current = record;
534
- for (const segment of path) {
535
- if (!isRecord(current) || !Object.hasOwn(current, segment))
536
- return;
537
- current = current[segment];
538
- }
539
- return current;
540
- }
541
- function fieldPath(field) {
542
- const path = field.split(".");
543
- if (path.some((segment) => segment.length === 0 || isUnsafeKey(segment))) {
544
- throw new CliArgumentError2(`"${field}" is not a readable field path`);
545
- }
546
- return path;
547
- }
548
- function availableFields(records) {
549
- const keys = new Set;
550
- for (const record of records) {
551
- if (isRecord(record))
552
- for (const key of Object.keys(record))
553
- keys.add(key);
554
- }
555
- return [...keys].sort();
556
- }
557
- function assertFieldPresent(records, field) {
558
- const path = fieldPath(field);
559
- const present = records.some((record) => readField(record, path) !== undefined);
560
- if (records.length > 0 && !present) {
561
- const available = availableFields(records);
562
- throw new CliArgumentError2(`no record carries the field "${field}"${available.length > 0 ? ` — available: ${available.join(", ")}` : ""}`);
563
- }
564
- return path;
565
- }
566
- function groupKey(value) {
567
- if (value === undefined)
568
- return ABSENT;
569
- if (value === null)
570
- return "null";
571
- if (value === "null" || value === ABSENT)
572
- return JSON.stringify(value);
573
- if (typeof value === "object")
574
- return stringifyJsonSafe(value);
575
- return String(value);
576
- }
577
- function ordered(totals, top) {
578
- const entries = [...totals].sort(([leftKey, left], [rightKey, right]) => right === left ? leftKey.localeCompare(rightKey) : right - left);
579
- const sliced = top === undefined ? entries : entries.slice(0, top);
580
- return {
581
- kind: "json",
582
- data: Object.fromEntries(sliced),
583
- order: sliced.map(([key]) => key)
584
- };
585
- }
586
- function stringifyGroups(data, order, compact) {
587
- if (!isRecord(data) || order.length === 0)
588
- return stringifyJsonSafe(data);
589
- const lines = order.map((key) => `${JSON.stringify(key)}:${compact ? "" : " "}${stringifyJsonSafe(data[key])}`);
590
- return compact ? `{${lines.join(",")}}` : `{
591
- ${lines.join(`,
592
- `)}
593
- }`;
594
- }
595
- function numericValue(value, field) {
596
- if (isAbsent(value))
597
- return;
598
- if (typeof value === "number" && Number.isFinite(value))
599
- return value;
600
- if (typeof value === "bigint")
601
- return Number(value);
602
- throw new CliArgumentError2(`--sum ${field}: "${groupKey(value)}" is not a number`);
603
- }
604
- function renderTable(records, columns) {
605
- const fields = columns.map(({ field }) => field);
606
- const cell = (value) => {
607
- if (value === undefined)
608
- return "";
609
- if (value === null)
610
- return "null";
611
- if (typeof value === "object")
612
- return stringifyJsonSafe(value);
613
- return String(value);
614
- };
615
- const rows = records.map((record) => columns.map(({ path }) => cell(readField(record, path))));
616
- const widths = fields.map((field, column) => Math.max(field.length, ...rows.map((row) => row[column]?.length ?? 0)));
617
- const line = (cells) => cells.map((value, column) => value.padEnd(widths[column] ?? value.length)).join(" ").trimEnd();
618
- return `${[line(fields), line(widths.map((width) => "-".repeat(width))), ...rows.map(line)].join(`
619
- `)}
620
- `;
621
- }
622
- function compareFieldValues(left, right) {
623
- if (isAbsent(left))
624
- return isAbsent(right) ? 0 : 1;
625
- if (isAbsent(right))
626
- return -1;
627
- if (typeof left === "number" && typeof right === "number")
628
- return left - right;
629
- if (typeof left === "bigint" || typeof right === "bigint") {
630
- return Number(left) - Number(right);
631
- }
632
- return groupKey(left).localeCompare(groupKey(right));
633
- }
634
- function renderRecords(records, view) {
635
- let selected = [...records];
636
- if (view.sort !== undefined) {
637
- const path = assertFieldPresent(records, view.sort);
638
- const direction = view.ascending ? 1 : -1;
639
- selected.sort((left, right) => {
640
- const leftValue = readField(left, path);
641
- const rightValue = readField(right, path);
642
- const order = compareFieldValues(leftValue, rightValue);
643
- return isAbsent(leftValue) || isAbsent(rightValue) ? order : order * direction;
644
- });
645
- }
646
- const columns = view.table?.map((field) => ({
647
- field,
648
- path: assertFieldPresent(records, field)
649
- }));
650
- if (view.top !== undefined)
651
- selected = selected.slice(0, view.top);
652
- return columns ? { kind: "text", text: renderTable(selected, columns) } : { kind: "json", data: selected };
653
- }
654
- function refuseEnvelopeFields(data, view) {
655
- if (!isRecord(data))
656
- return;
657
- const fields = view.kind === "records" ? [...view.sort === undefined ? [] : [view.sort], ...view.table ?? []] : [view.field, ...view.kind === "sum" && view.by !== undefined ? [view.by] : []];
658
- for (const field of fields) {
659
- const first = field.split(".")[0] ?? "";
660
- if (Object.hasOwn(data, first) && !Array.isArray(data[first])) {
661
- throw new CliArgumentError2(`"${field}" belongs to the result object, not to its empty collection`);
662
- }
663
- }
664
- }
665
- function renderCliView2(data, view) {
666
- const records = selectRecords(data);
667
- if (records.length === 0)
668
- refuseEnvelopeFields(data, view);
669
- if (view.kind === "records")
670
- return renderRecords(records, view);
671
- if (view.kind === "count") {
672
- const path = assertFieldPresent(records, view.field);
673
- const totals = new Map;
674
- for (const record of records) {
675
- const key = groupKey(readField(record, path));
676
- totals.set(key, (totals.get(key) ?? 0) + 1);
677
- }
678
- return ordered(totals, view.top);
679
- }
680
- const path = assertFieldPresent(records, view.field);
681
- if (view.by === undefined) {
682
- let total = 0;
683
- for (const record of records)
684
- total += numericValue(readField(record, path), view.field) ?? 0;
685
- return { kind: "json", data: total };
686
- }
687
- const byPath = assertFieldPresent(records, view.by);
688
- const totals = new Map;
689
- for (const record of records) {
690
- const key = groupKey(readField(record, byPath));
691
- totals.set(key, (totals.get(key) ?? 0) + (numericValue(readField(record, path), view.field) ?? 0));
692
- }
693
- return ordered(totals, view.top);
694
- }
695
-
696
- // src/tools/cli/view-columns.ts
697
- import { z as z2 } from "zod";
698
- function unwrapReadonly(schema) {
699
- return schema instanceof z2.ZodReadonly ? unwrapReadonly(schema.unwrap()) : schema;
700
- }
701
- function hasOpenCatchall(objectSchema) {
702
- const catchall = objectSchema.def.catchall;
703
- return catchall !== undefined && !(catchall instanceof z2.ZodNever);
704
- }
705
- function couldBeArray(schema) {
706
- const base = unwrapZodWrappers(schema);
707
- if (base instanceof z2.ZodArray || base instanceof z2.ZodTuple)
708
- return true;
709
- if (base instanceof z2.ZodUnknown || base instanceof z2.ZodAny)
710
- return true;
711
- if (base instanceof z2.ZodUnion)
712
- return base.def.options.some(couldBeArray);
713
- if (base instanceof z2.ZodIntersection) {
714
- return couldBeArray(base.def.left) || couldBeArray(base.def.right);
715
- }
716
- return false;
717
- }
718
- function resolveUnambiguousRecordSchema(outputSchema) {
719
- if (outputSchema === undefined)
720
- return;
721
- const root = unwrapReadonly(outputSchema);
722
- let element;
723
- if (root instanceof z2.ZodArray) {
724
- element = root.element;
725
- } else if (root instanceof z2.ZodObject) {
726
- if (hasOpenCatchall(root))
727
- return;
728
- let requiredArray;
729
- for (const field of Object.values(root.shape)) {
730
- const bare = unwrapReadonly(field);
731
- if (bare instanceof z2.ZodArray) {
732
- if (requiredArray !== undefined)
733
- return;
734
- requiredArray = bare;
735
- continue;
736
- }
737
- if (couldBeArray(field))
738
- return;
739
- }
740
- element = requiredArray?.element;
741
- }
742
- if (element === undefined)
743
- return;
744
- const record = unwrapReadonly(element);
745
- if (!(record instanceof z2.ZodObject) || hasOpenCatchall(record))
746
- return;
747
- return record;
748
- }
749
- function pathExistsOnSchema(schema, path) {
750
- if (path.length === 0)
751
- return true;
752
- const base = unwrapZodWrappers(schema);
753
- if (base instanceof z2.ZodUnknown || base instanceof z2.ZodAny)
754
- return true;
755
- if (base instanceof z2.ZodRecord)
756
- return pathExistsOnSchema(base.valueType, path.slice(1));
757
- if (base instanceof z2.ZodUnion) {
758
- return base.def.options.some((branch) => pathExistsOnSchema(branch, path));
759
- }
760
- if (base instanceof z2.ZodIntersection) {
761
- return pathExistsOnSchema(base.def.left, path) || pathExistsOnSchema(base.def.right, path);
762
- }
763
- if (base instanceof z2.ZodObject) {
764
- const [head, ...rest] = path;
765
- if (head === undefined)
766
- return true;
767
- if (Object.hasOwn(base.shape, head)) {
768
- const child = base.shape[head];
769
- return child !== undefined && pathExistsOnSchema(child, rest);
770
- }
771
- if (hasOpenCatchall(base) && base.def.catchall !== undefined) {
772
- return pathExistsOnSchema(base.def.catchall, rest);
773
- }
774
- return false;
775
- }
776
- return false;
777
- }
778
- function requestedViewFields(view) {
779
- if (view.kind === "records") {
780
- return [...view.sort === undefined ? [] : [view.sort], ...view.table ?? []];
781
- }
782
- if (view.kind === "sum") {
783
- return [view.field, ...view.by === undefined ? [] : [view.by]];
784
- }
785
- return [view.field];
786
- }
787
- function assertViewColumns(view, outputSchema) {
788
- const record = resolveUnambiguousRecordSchema(outputSchema);
789
- if (record === undefined)
790
- return;
791
- const available = Object.keys(record.shape).sort();
792
- for (const field of requestedViewFields(view)) {
793
- const path = field.split(".");
794
- if (path.some((segment) => segment.length === 0 || isUnsafeKey(segment))) {
795
- throw new CliArgumentError2(`"${field}" is not a readable field path`);
796
- }
797
- if (!pathExistsOnSchema(record, path)) {
798
- throw new CliArgumentError2(`no record carries the field "${field}"${available.length > 0 ? ` — available: ${available.join(", ")}` : ""}`);
799
- }
800
- }
801
- }
802
-
803
- // src/tools/cli/command.ts
804
- function defineCliResult2(output, policy) {
805
- return { ...policy, output };
806
- }
807
- function defineCliCommand2(definition) {
808
- return definition;
809
- }
810
- function cliCommandReturnsResult(definition) {
811
- return definition.output !== undefined;
812
- }
813
- function cliCommandSuccessExitCode(policy, data) {
814
- const successExitCode = policy?.exitCode?.(data) ?? 0;
815
- if (!Number.isSafeInteger(successExitCode) || successExitCode < 0 || successExitCode > 255) {
816
- throw new Error("CLI success exit code must be an integer from 0 to 255");
817
- }
818
- return successExitCode;
819
- }
820
- function cliCommandResultPolicy(definition) {
821
- return cliCommandReturnsResult(definition) ? definition : undefined;
822
- }
823
- function prepareCliCommandEmission(policy, result, options) {
824
- if (!result.ok || policy === undefined) {
825
- return { result, successExitCode: 0 };
826
- }
827
- let successExitCode;
828
- try {
829
- successExitCode = cliCommandSuccessExitCode(policy, result.data);
830
- } catch (error) {
831
- return {
832
- result: toolResultFromError(new Error("CLI result policy failed", { cause: error })),
833
- successExitCode: 0
834
- };
835
- }
836
- try {
837
- if (policy.present === undefined)
838
- return { result, successExitCode };
839
- const presentation = policy.present({ result: result.data, options });
840
- if (typeof presentation !== "string") {
841
- throw new Error("CLI result presenter must return a string");
842
- }
843
- return { result, presentation, successExitCode };
844
- } catch (error) {
845
- return {
846
- result,
847
- presentationFailure: toolResultFromError(new Error("CLI result presentation failed", { cause: error })),
848
- successExitCode
849
- };
850
- }
851
- }
852
- function emitCliCommandResult(policy, result, options, writers, emit, shown) {
853
- const emission = prepareCliCommandEmission(policy, result, options);
854
- if (!emission.result.ok)
855
- return emitResult2(emission.result, writers, emit);
856
- if (emission.presentation !== undefined) {
857
- writers.stdout(emission.presentation);
858
- return emission.successExitCode;
859
- }
860
- const printed = shown ?? emission.result;
861
- if (emission.presentationFailure !== undefined) {
862
- return emitPresentationFailure(printed, emission.presentationFailure, writers, emit);
863
- }
864
- emitResult2(printed, writers, emit);
865
- return emission.successExitCode;
866
- }
867
- function cliCommandPresentationSchema(definition) {
868
- return buildToolPresentationSchema({
869
- inputSchema: definition.input,
870
- unrepresentable: "any"
871
- });
872
- }
873
- async function executeCliCommand(definition, rawArgs, options, writers, coerceJson, globals = {}) {
874
- let parsed;
875
- try {
876
- parsed = definition.input.safeParse(coerceJson ? coerceJsonArgs2(rawArgs, definition.input) : rawArgs);
877
- } catch (error) {
878
- return toolResultFromError(error);
879
- }
880
- if (!parsed.success) {
881
- return {
882
- ok: false,
883
- code: "VALIDATION_ERROR",
884
- details: { message: `Invalid input: ${formatZodError2(parsed.error)}` }
885
- };
886
- }
887
- try {
888
- const data = await definition.handler({
889
- input: parsed.data,
890
- options,
891
- globals,
892
- ...writers
893
- });
894
- const checked = validateDeclaredOutput(definition.output, data);
895
- if (!checked.ok) {
896
- return {
897
- ok: false,
898
- code: "INTERNAL_SERVER_ERROR",
899
- details: { message: checked.message }
900
- };
901
- }
902
- return { ok: true, data: checked.data };
903
- } catch (error) {
904
- return toolResultFromError(error);
905
- }
906
- }
907
- function emitCliViewOrResult(policy, result, options, writers, emit, initialShown, mediaExitCode = 0) {
908
- if (!result.ok)
909
- return emitResult2(result, writers, emit);
910
- let shown = initialShown ?? result;
911
- if (options.view) {
912
- let viewed;
913
- try {
914
- viewed = renderCliView2(shown.data, options.view);
915
- } catch (error) {
916
- const failure = error instanceof CliArgumentError2 ? { ok: false, code: "BAD_REQUEST", details: { message: error.message } } : toolResultFromError(error);
917
- return emitPresentationFailure(shown, failure, writers, emit);
918
- }
919
- if (viewed.kind === "text") {
920
- writers.stdout(viewed.text);
921
- return mediaExitCode;
922
- }
923
- if (viewed.order) {
924
- writers.stdout(`${stringifyGroups(viewed.data, viewed.order, options.json === true)}
925
- `);
926
- return mediaExitCode;
927
- }
928
- shown = { ...shown, data: viewed.data };
929
- }
930
- const activePolicy = options.view === undefined && !options.wait ? policy : undefined;
931
- const exitCode = emitCliCommandResult(activePolicy, result, options, writers, emit, shown);
932
- return mediaExitCode || exitCode;
933
- }
934
- var IN_PROCESS_RUN_OPTIONS = Object.freeze({
935
- json: false,
936
- wait: false,
937
- quiet: true,
938
- dryRun: false,
939
- help: false,
940
- schema: false
941
- });
942
- function shapeCliInvocationResult(result, toolName, config, policy) {
943
- if (!result.ok) {
944
- const normalized = toolErrorFromResult(result);
945
- const hints = [];
946
- if (result.hint)
947
- hints.push(result.hint);
948
- const global = config.errorHint?.(toolName, result.code);
949
- if (global)
950
- hints.push(global);
951
- return {
952
- ok: false,
953
- exitCode: cliExitCode2(result, config.exitCodes),
954
- error: {
955
- code: result.code,
956
- message: normalized.message,
957
- ...result.details !== undefined && { details: result.details },
958
- ...hints.length > 0 && { hint: hints.join(" ") },
959
- ...result.retryable !== undefined && { retryable: result.retryable }
960
- }
961
- };
962
- }
963
- const data = result.data === undefined ? undefined : projectJsonSafe(result.data).value;
964
- if (policy === undefined)
965
- return { ok: true, exitCode: 0, data };
966
- try {
967
- return {
968
- ok: true,
969
- exitCode: cliCommandSuccessExitCode(policy, result.data),
970
- data
971
- };
972
- } catch (error) {
973
- return shapeCliInvocationResult(toolResultFromError(new Error("CLI result policy failed", { cause: error })), toolName, config);
974
- }
975
- }
976
- async function executeNativeCommand(definition, rawArgs, coerceJson, globals, target) {
977
- if (target.mode === "terminal") {
978
- if (target.options.view !== undefined) {
979
- if (!cliCommandReturnsResult(definition)) {
980
- target.writers.stderr(`aggregate views do not apply to native command "${definition.name}" without an output schema
981
- `);
982
- return 2;
983
- }
984
- try {
985
- assertViewColumns(target.options.view, definition.output);
986
- } catch (error) {
987
- if (!(error instanceof CliArgumentError2))
988
- throw error;
989
- target.writers.stderr(`${error.message}
990
- `);
991
- return 2;
992
- }
993
- }
994
- const result = await executeCliCommand(definition, rawArgs, target.options, target.writers, coerceJson, globals);
995
- return emitCliViewOrResult(cliCommandResultPolicy(definition), result, target.options, target.writers, target.emit);
996
- }
997
- let out = "";
998
- let err = "";
999
- const result = await executeCliCommand(definition, rawArgs, IN_PROCESS_RUN_OPTIONS, {
1000
- stdout: (text) => {
1001
- out += text;
1002
- },
1003
- stderr: (text) => {
1004
- err += text;
1005
- }
1006
- }, coerceJson, globals);
1007
- const invocation = shapeCliInvocationResult(result, definition.name, target, cliCommandResultPolicy(definition));
1008
- if (out === "" && err === "")
1009
- return invocation;
1010
- return {
1011
- ...invocation,
1012
- written: { ...out !== "" && { stdout: out }, ...err !== "" && { stderr: err } }
1013
- };
1014
- }
1015
-
1016
- // src/tools/cli/args-json.ts
1017
- function cliFieldOption(option, fields) {
1018
- const json = option.inline && option.name.endsWith(":") && !fields.has(option.name);
1019
- const name = json ? option.name.slice(0, -1) : option.name;
1020
- return { name, json };
1021
- }
1022
- function appendCliFieldValue(raw, jsonFields, name, value, info, json) {
1023
- appendCliOptionValue(raw, name, value, json || jsonFields.has(name) ? { kind: "other" } : info);
1024
- if (json)
1025
- jsonFields.add(name);
1026
- }
1027
- function coerceCliFieldValue(info, values, label, json) {
1028
- if (!json)
1029
- return coerceField(info, values, label);
1030
- try {
1031
- return safeJsonParse(values[0] ?? "");
1032
- } catch (cause) {
1033
- throw new CliArgumentError2(`${label} expects valid JSON`, { cause });
1034
- }
1035
- }
1036
-
1037
- // src/tools/cli/args-view.ts
1038
- function resolveCliView(flags, ascending) {
1039
- if (flags.size === 0) {
1040
- if (ascending) {
1041
- throw new CliArgumentError2("--ascending orders a record view; pass --sort with it");
1042
- }
1043
- return;
1044
- }
1045
- const countBy = flags.get("count-by");
1046
- const sum = flags.get("sum");
1047
- const table = flags.get("table");
1048
- const by = flags.get("by");
1049
- const rawTop = flags.get("top");
1050
- const named = [
1051
- ["--count-by", countBy],
1052
- ["--sum", sum]
1053
- ].filter(([, value]) => value !== undefined);
1054
- if (named.length > 1) {
1055
- throw new CliArgumentError2(`${named.map(([flag]) => flag).join(" and ")} ask for different shapes — pass one`);
1056
- }
1057
- let top;
1058
- if (rawTop !== undefined) {
1059
- top = Number(rawTop);
1060
- if (!Number.isInteger(top) || top <= 0) {
1061
- throw new CliArgumentError2("--top must be a positive whole number");
1062
- }
1063
- }
1064
- const sort = flags.get("sort");
1065
- if (table !== undefined || sort !== undefined) {
1066
- if (countBy !== undefined || sum !== undefined) {
1067
- throw new CliArgumentError2(`${table !== undefined ? "--table" : "--sort"} lists records; --count-by and --sum aggregate them — pass one`);
1068
- }
1069
- if (by !== undefined) {
1070
- throw new CliArgumentError2("--by groups a view; a record view orders with --sort");
1071
- }
1072
- if (top !== undefined && sort === undefined) {
1073
- throw new CliArgumentError2("--top needs --sort here: unordered records have no n largest");
1074
- }
1075
- let fields;
1076
- if (table !== undefined) {
1077
- fields = table.split(",").map((field) => field.trim()).filter(Boolean);
1078
- if (fields.length === 0)
1079
- throw new CliArgumentError2("--table needs at least one field");
1080
- }
1081
- return {
1082
- kind: "records",
1083
- ...sort !== undefined && { sort },
1084
- ...ascending && { ascending },
1085
- ...top !== undefined && { top },
1086
- ...fields && { table: fields }
1087
- };
1088
- }
1089
- if (ascending) {
1090
- throw new CliArgumentError2("--ascending orders a record view; pass --sort with it");
1091
- }
1092
- if (sum !== undefined) {
1093
- if (top !== undefined && by === undefined) {
1094
- throw new CliArgumentError2("--top needs --by: a single sum has nothing to rank");
1095
- }
1096
- return {
1097
- kind: "sum",
1098
- field: sum,
1099
- ...by !== undefined && { by },
1100
- ...top !== undefined && { top }
1101
- };
1102
- }
1103
- if (countBy !== undefined) {
1104
- if (by !== undefined) {
1105
- throw new CliArgumentError2("--count-by already names the grouping field; drop --by");
1106
- }
1107
- return { kind: "count", field: countBy, ...top !== undefined && { top } };
1108
- }
1109
- if (by !== undefined) {
1110
- if (top === undefined) {
1111
- throw new CliArgumentError2("--by groups a view; pass --count-by, --sum or --top with it");
1112
- }
1113
- return { kind: "count", field: by, top };
1114
- }
1115
- throw new CliArgumentError2("--top needs --sort, --by, --count-by or --sum to rank");
1116
- }
1117
-
1118
- // src/tools/cli/args-classify.ts
1119
- function isOptionToken(token) {
1120
- return token.startsWith("--") || /^-[A-Za-z](?:=|$)/.test(token);
1121
- }
1122
- function looksLikeOption(token) {
1123
- return token.startsWith("--") || /^-[A-Za-z]/.test(token);
1124
- }
1125
- var BOOL_OPTIONS = new Set([
1126
- "json",
1127
- "wait",
1128
- "quiet",
1129
- "dry-run",
1130
- "help",
1131
- "schema",
1132
- "ascending"
1133
- ]);
1134
- var VIEW_OPTIONS = new Set(["count-by", "sum", "by", "top", "table", "sort"]);
1135
- var VALUE_OPTIONS = new Set(["wait-timeout", "output-dir", ...VIEW_OPTIONS]);
1136
- var RESERVED_CLI_OPTIONS = new Set([...BOOL_OPTIONS, ...VALUE_OPTIONS]);
1137
- function classifyLongOptionToken(token) {
1138
- if (!token.startsWith("--") || token === "--")
1139
- return;
1140
- const equals = token.indexOf("=");
1141
- const name = equals >= 0 ? token.slice(2, equals) : token.slice(2);
1142
- return {
1143
- name,
1144
- value: equals >= 0 ? token.slice(equals + 1) : undefined,
1145
- inline: equals >= 0,
1146
- globalKind: BOOL_OPTIONS.has(name) ? "boolean" : VALUE_OPTIONS.has(name) ? "value" : undefined
1147
- };
1148
- }
1149
- var HELP_TOKENS = new Set(["--help", "-h", "help"]);
1150
- function isCliVersionToken(token) {
1151
- return token === "--version" || token === "version";
1152
- }
1153
- function isOptionShapedToken(token) {
1154
- return token.startsWith("-") && token !== "-";
1155
- }
1156
- function isReservedCliCommandName(name) {
1157
- return isOptionShapedToken(name) || name === "--" || HELP_TOKENS.has(name) || isCliVersionToken(name) || classifyLongOptionToken(name)?.globalKind !== undefined;
1158
- }
1159
- function isTopHelpOption(token) {
1160
- return token === "--help" || token === "-h" || token.startsWith("--help=") && !isReservedBoolWord(token.slice("--help=".length));
1161
- }
1162
- function isOwnLeadingToken(token, appFields) {
1163
- if (token === undefined || token === "--" || isTopHelpOption(token) || isCliVersionToken(token))
1164
- return true;
1165
- const opt = classifyLongOptionToken(token);
1166
- if (!opt)
1167
- return false;
1168
- return opt.globalKind !== undefined || appFields.has(cliFieldOption(opt, appFields).name);
1169
- }
1170
- function deferScanError(ctx, error) {
1171
- ctx.deferredError ??= error;
1172
- }
1173
- function recordAppGlobalError(ctx, error) {
1174
- ctx.appGlobalError ??= error;
1175
- deferScanError(ctx, error);
1176
- }
1177
- function pushRestToken(ctx, token, index) {
1178
- ctx.withoutGlobals.push(token);
1179
- ctx.withoutCommand.push(token);
1180
- ctx.withoutCommandFrom.push(index);
1181
- }
1182
- function pushCommandToken(ctx, token, index) {
1183
- if ((ctx.removedAfterCmdToken || ctx.separatedInput.has(index)) && ctx.commandTokens.length > 0) {
1184
- ctx.separatedBefore.add(ctx.commandTokens.length);
1185
- }
1186
- ctx.removedAfterCmdToken = false;
1187
- ctx.commandTokens.push(token);
1188
- pushRestToken(ctx, token, index);
1189
- }
1190
- function withoutCommandSeparations(ctx) {
1191
- const separated = new Set;
1192
- ctx.withoutCommandFrom.forEach((from, at) => {
1193
- if (at > 0 && ctx.separatedInput.has(from))
1194
- separated.add(at);
1195
- });
1196
- return separated;
1197
- }
1198
- function markCommandTokenRemoved(ctx) {
1199
- if (ctx.commandFound)
1200
- ctx.removedAfterCmdToken = true;
1201
- }
1202
- function tryReadAppGlobalToken(ctx, index, opt, raw, jsonFields) {
1203
- if (!opt || opt.globalKind !== undefined)
1204
- return -1;
1205
- const appField = cliFieldOption(opt, ctx.appFields);
1206
- const info = ctx.appFields.get(appField.name);
1207
- if (!info)
1208
- return -1;
1209
- if (ctx.bareBool)
1210
- ctx.bareBool.removedAfter = true;
1211
- let { value } = opt;
1212
- let nextIndex = index;
1213
- if (value === undefined && info.kind === "boolean") {
1214
- const sep = separateBoolValue(ctx.argv[index + 1]);
1215
- if (sep !== undefined)
1216
- nextIndex++;
1217
- value = String(sep ?? true);
1218
- } else if (value === undefined) {
1219
- const next = ctx.argv[index + 1];
1220
- if (next === undefined || isOptionToken(next)) {
1221
- recordAppGlobalError(ctx, new CliArgumentError2(`--${opt.name} requires a value`));
1222
- return nextIndex;
1223
- }
1224
- value = next;
1225
- nextIndex++;
1226
- } else if (info.kind === "boolean" && !appField.json) {
1227
- if (raw.has(appField.name)) {
1228
- appendCliFieldValue(raw, jsonFields, appField.name, value, info, appField.json);
1229
- return nextIndex;
1230
- }
1231
- try {
1232
- parseReservedBool(appField.name, value);
1233
- } catch (error) {
1234
- if (error instanceof CliArgumentError2)
1235
- recordAppGlobalError(ctx, error);
1236
- else
1237
- throw error;
1238
- }
1239
- }
1240
- appendCliFieldValue(raw, jsonFields, appField.name, value, info, appField.json);
1241
- return nextIndex;
1242
- }
1243
- function reservedJsonTarget(opt) {
1244
- if (!opt?.inline || !opt.name.endsWith(":"))
1245
- return;
1246
- const target = opt.name.slice(0, -1);
1247
- return RESERVED_CLI_OPTIONS.has(target) ? target : undefined;
1248
- }
1249
- function consumeFrameworkOptionToken(argv, index, opt, state, callbacks) {
1250
- const adjacent = callbacks.adjacent ?? (() => true);
1251
- const report = (error) => {
1252
- if (opt.name === "schema") {
1253
- state.fw.schema = false;
1254
- state.schemaInvalid = true;
1255
- } else if (opt.name === "help")
1256
- state.fw.help = false;
1257
- callbacks.onError(error);
1258
- };
1259
- const record = (name, raw, kind) => {
1260
- try {
1261
- appendCliOptionValue(state.fwFlags, name, raw, { kind });
1262
- return true;
1263
- } catch (error) {
1264
- if (error instanceof CliArgumentError2) {
1265
- report(error);
1266
- return false;
1267
- }
1268
- throw error;
1269
- }
1270
- };
1271
- let nextIdx = index;
1272
- if (opt.globalKind === "boolean") {
1273
- const following = argv[index + 1];
1274
- if (!opt.inline && !adjacent(index + 1) && following !== undefined && separateBoolValue(following) !== undefined) {
1275
- report(brokenBooleanBoundaryError(opt.name, following));
1276
- if (opt.name === "help" || opt.name === "schema")
1277
- return nextIdx;
1278
- }
1279
- const nextTok = adjacent(index + 1) ? following : undefined;
1280
- const sep = opt.inline ? undefined : separateBoolValue(nextTok);
1281
- if (sep !== undefined && nextTok !== undefined) {
1282
- nextIdx++;
1283
- callbacks.onValueToken?.(nextTok);
1284
- }
1285
- const rawValue = opt.value ?? String(sep ?? true);
1286
- if (opt.name !== "help" && !record(opt.name, rawValue, "boolean"))
1287
- return nextIdx;
1288
- let enabled;
1289
- if (opt.inline) {
1290
- try {
1291
- enabled = parseReservedBool(opt.name, opt.value ?? "");
1292
- } catch (error) {
1293
- if (error instanceof CliArgumentError2) {
1294
- report(error);
1295
- return nextIdx;
1296
- }
1297
- throw error;
1298
- }
1299
- } else {
1300
- enabled = sep ?? true;
1301
- }
1302
- if (!opt.inline && sep === undefined)
1303
- callbacks.onBareBoolean?.(opt.name);
1304
- if (opt.name === "dry-run")
1305
- state.fw.dryRun = enabled;
1306
- else if (opt.name === "json")
1307
- state.fw.json = enabled;
1308
- else if (opt.name === "wait")
1309
- state.fw.wait = enabled;
1310
- else if (opt.name === "quiet")
1311
- state.fw.quiet = enabled;
1312
- else if (opt.name === "ascending")
1313
- state.ascending = enabled;
1314
- else if (opt.name === "schema") {
1315
- state.fw.schema = !state.schemaInvalid && (state.fw.schema || enabled);
1316
- } else if (opt.name === "help")
1317
- state.fw.help = state.fw.help || enabled;
1318
- return nextIdx;
1319
- }
1320
- let value = opt.value;
1321
- if (!opt.inline) {
1322
- const next = adjacent(index + 1) ? argv[index + 1] : undefined;
1323
- if (next === undefined || isOptionToken(next)) {
1324
- report(new CliArgumentError2(`--${opt.name} requires a value`));
1325
- if (callbacks.onMissingValue?.(next))
1326
- nextIdx++;
1327
- } else {
1328
- value = next;
1329
- nextIdx++;
1330
- callbacks.onValueToken?.(next);
1331
- }
1332
- }
1333
- if (value !== undefined) {
1334
- if (!record(opt.name, value, "string"))
1335
- return nextIdx;
1336
- if (opt.name === "wait-timeout") {
1337
- const n = Number(value);
1338
- if (!Number.isFinite(n) || n <= 0) {
1339
- report(new CliArgumentError2("--wait-timeout must be a positive number"));
1340
- } else {
1341
- state.fw.waitTimeout = n;
1342
- }
1343
- } else if (VIEW_OPTIONS.has(opt.name))
1344
- state.viewFlags.set(opt.name, value);
1345
- else
1346
- state.fw.outputDir = value;
1347
- }
1348
- return nextIdx;
1349
- }
1350
- function readFrameworkOptionToken(ctx, index, token, opt) {
1351
- ctx.bareBool = undefined;
1352
- pushRestToken(ctx, token, index);
1353
- return consumeFrameworkOptionToken(ctx.argv, index, opt, ctx, {
1354
- adjacent: (at) => !ctx.separatedInput.has(at),
1355
- onError: (error) => deferScanError(ctx, error),
1356
- onValueToken: (valueToken) => pushRestToken(ctx, valueToken, index + 1),
1357
- onBareBoolean: (name) => {
1358
- ctx.bareBool = { name, removedAfter: false };
1359
- },
1360
- onMissingValue: (next) => {
1361
- if (!ctx.commandFound && next !== undefined && !isOwnLeadingToken(next, ctx.appFields)) {
1362
- pushRestToken(ctx, next, index + 1);
1363
- return true;
1364
- }
1365
- return false;
1366
- }
1367
- });
1368
- }
1369
- function finalizeFrameworkView(ctx) {
1370
- if (ctx.viewFlags.size === 0 && !ctx.ascending)
1371
- return;
1372
- try {
1373
- ctx.fw.view = resolveCliView(ctx.viewFlags, ctx.ascending);
1374
- } catch (error) {
1375
- if (error instanceof CliArgumentError2)
1376
- deferScanError(ctx, error);
1377
- else
1378
- throw error;
1379
- }
1380
- }
1381
- function createFrameworkStepContext(argv, appFields, separatedInput = new Set) {
1382
- return {
1383
- argv,
1384
- appFields,
1385
- fwFlags: new Map,
1386
- viewFlags: new Map,
1387
- fw: { json: false, quiet: false, help: false, schema: false, dryRun: false, wait: false },
1388
- ascending: false,
1389
- commandFound: false,
1390
- withoutGlobals: [],
1391
- withoutCommand: [],
1392
- withoutCommandFrom: [],
1393
- commandTokens: [],
1394
- separatedBefore: new Set,
1395
- removedAfterCmdToken: false,
1396
- separatedInput
1397
- };
1398
- }
1399
- function coerceAppGlobalMap(raw, fields, jsonFields) {
1400
- const coerced = {};
1401
- for (const [name, values] of raw) {
1402
- coerced[name] = coerceCliFieldValue(fields.get(name), values, `--${name}`, jsonFields.has(name));
1403
- }
1404
- return coerced;
1405
- }
1406
- function brokenBooleanBoundaryError(flagName, word) {
1407
- const flag = flagName.startsWith("-") ? flagName : `--${flagName}`;
1408
- return new CliArgumentError2(`Bare ${flag} cannot be separated from "${word}" — use ${flag}=true, ${flag}=false or "-- ${word}"`);
1409
- }
1410
-
1411
- // src/tools/cli/stream-surface.ts
1412
- function cliStreamIdentity(serviceName, methodName, method) {
1413
- if (!method.stream || !method.expose?.includes("CLI"))
1414
- return;
1415
- return { name: toToolName(serviceName, methodName), descriptor: method.stream };
1416
- }
1417
- function collectCliStreams(services) {
1418
- const streams = new Map;
1419
- for (const service of services) {
1420
- for (const [methodName, method] of Object.entries(service.methods)) {
1421
- const identity = cliStreamIdentity(service.name, methodName, method);
1422
- if (identity === undefined)
1423
- continue;
1424
- const { name, descriptor } = identity;
1425
- streams.set(name, {
1426
- descriptor,
1427
- tool: {
1428
- method,
1429
- name,
1430
- argumentSchema: mergeSchemas(method.paramsSchema, method.inputSchema),
1431
- presentationSchema: buildToolPresentationSchema({
1432
- paramsSchema: method.paramsSchema,
1433
- inputSchema: method.inputSchema,
1434
- inputRecursionDepth: method.inputRecursionDepth,
1435
- inputNestingDepth: method.inputNestingDepth,
1436
- unrepresentable: "any"
1437
- }),
1438
- shouldExtend: false
1439
- }
1440
- });
1441
- }
1442
- }
1443
- return streams;
1444
- }
1445
-
1446
- // src/tools/cli/command-shape.ts
1447
- function nativeCliDescriptor(definition) {
1448
- return {
1449
- description: definition.description,
1450
- argumentSchema: definition.input,
1451
- presentationSchema: cliCommandPresentationSchema(definition),
1452
- outputSchema: definition.output
1453
- };
1454
- }
1455
- function assertNoPassthroughAlias(name, descriptor, passthroughField) {
1456
- if (passthroughField !== undefined && descriptor.aliases.has(passthroughField)) {
1457
- throw new Error(`[stitchkit] CLI command "${name}" cannot alias passthrough field "${passthroughField}"`);
1458
- }
1459
- }
1460
- function invokerCommandShapeIssue(name, descriptor, exists, passthroughField) {
1461
- assertUniqueToolName(name, exists, "CLI command");
1462
- assertNoPassthroughAlias(name, descriptor, passthroughField);
1463
- return;
1464
- }
1465
- function assertCliCommandName(name) {
1466
- if (isReservedCliCommandName(name)) {
1467
- throw new Error(`[stitchkit] CLI command "${name}" is reserved. Rename the command to a word outside the option syntax.`);
1468
- }
1469
- }
1470
- function assertStaticCliCommandNames(services, runtimeTools) {
1471
- for (const tool of runtimeTools) {
1472
- assertNoLegacyTransports(tool, `Runtime tool "${tool.name}"`);
1473
- if (tool.expose?.includes("CLI"))
1474
- assertCliCommandName(tool.name);
1475
- }
1476
- for (const service of services) {
1477
- for (const [key, method] of Object.entries(service.methods)) {
1478
- const name = projectedContractToolName(service.name, key, method, "CLI") ?? cliStreamIdentity(service.name, key, method)?.name;
1479
- if (name !== undefined)
1480
- assertCliCommandName(name);
1481
- }
1482
- }
1483
- }
1484
- function commandShapeIssue(name, descriptor, exists, passthroughField, applicationGlobals = new Set) {
1485
- assertUniqueToolName(name, exists, "CLI command");
1486
- assertCliCommandName(name);
1487
- assertNoPassthroughAlias(name, descriptor, passthroughField);
1488
- const fieldNames = jsonSchemaFields(descriptor.presentationSchema).map((field) => field.name);
1489
- const conflicting = fieldNames.filter((field) => RESERVED_CLI_OPTIONS.has(field));
1490
- if (conflicting.length > 0) {
1491
- return `[stitchkit] CLI command "${name}" declares reserved option field(s): ${conflicting.join(", ")}`;
1492
- }
1493
- const shadowed = fieldNames.filter((field) => applicationGlobals.has(field));
1494
- if (shadowed.length > 0) {
1495
- return `[stitchkit] CLI command "${name}" declares field(s) shadowed by application global options: ${shadowed.join(", ")}`;
1496
- }
1497
- }
1498
-
1499
- // src/tools/cli/policy.ts
1500
- var REMOVED_TOP_LEVEL_KEYS = [
1501
- "optionAliases",
1502
- "positionals",
1503
- "results",
1504
- "passthrough",
1505
- "wait"
1506
- ];
1507
- function assertNoLegacyCliPolicyKeys(config) {
1508
- if (typeof config !== "object" || config === null)
1509
- return;
1510
- for (const key of REMOVED_TOP_LEVEL_KEYS) {
1511
- if (Object.hasOwn(config, key)) {
1512
- throw new TypeError(`[stitchkit] CLI option "${key}" was moved into "commandSettings.<command>" — migrate to commandSettings`);
1513
- }
1514
- }
1515
- }
1516
- var SHORT_ALIAS = /^[A-Za-z]$/;
1517
- var RESERVED_SHORT_OPTIONS = new Set(["h"]);
1518
- function fieldMap(descriptor) {
1519
- return new Map(jsonSchemaFields(descriptor.presentationSchema).map((field) => [field.name, field]));
1520
- }
1521
- function resolveAliases(command, descriptor, configured) {
1522
- if (!configured)
1523
- return new Map;
1524
- const fields = fieldMap(descriptor);
1525
- const aliases = new Map;
1526
- for (const [alias, target] of Object.entries(configured)) {
1527
- if (!SHORT_ALIAS.test(alias)) {
1528
- throw new Error(`[stitchkit] CLI command "${command}" alias "${alias}" must be one ASCII letter`);
1529
- }
1530
- if (RESERVED_SHORT_OPTIONS.has(alias)) {
1531
- throw new Error(`[stitchkit] CLI command "${command}" alias "-${alias}" is reserved`);
1532
- }
1533
- if (isUnsafeKey(target) || !fields.has(target)) {
1534
- throw new Error(`[stitchkit] CLI command "${command}" alias "-${alias}" targets unknown field "${target}"`);
1535
- }
1536
- const existing = aliases.get(target);
1537
- if (existing !== undefined) {
1538
- throw new Error(`[stitchkit] CLI command "${command}" field "${target}" has multiple aliases: -${existing}, -${alias}`);
1539
- }
1540
- aliases.set(target, alias);
1541
- }
1542
- return aliases;
1543
- }
1544
- function resolvePositionals(command, descriptor, configured) {
1545
- if (configured === undefined)
1546
- return;
1547
- const fields = fieldMap(descriptor);
1548
- const kinds = describeSchemaFields(descriptor.argumentSchema);
1549
- const seen = new Set;
1550
- let optionalSeen = false;
1551
- for (const name of configured) {
1552
- const field = fields.get(name);
1553
- if (isUnsafeKey(name) || !field || !kinds.has(name)) {
1554
- throw new Error(`[stitchkit] CLI command "${command}" positional targets unknown field "${name}"`);
1555
- }
1556
- if (seen.has(name)) {
1557
- throw new Error(`[stitchkit] CLI command "${command}" repeats positional field "${name}"`);
1558
- }
1559
- if (kinds.get(name)?.kind === "boolean") {
1560
- throw new Error(`[stitchkit] CLI command "${command}" boolean field "${name}" cannot be positional`);
1561
- }
1562
- if (optionalSeen && field.required) {
1563
- throw new Error(`[stitchkit] CLI command "${command}" required positional "${name}" cannot follow an optional positional`);
1564
- }
1565
- if (!field.required)
1566
- optionalSeen = true;
1567
- seen.add(name);
1568
- }
1569
- return [...configured];
1570
- }
1571
- function cliCommandSettingsFor(config, command) {
1572
- return config.commandSettings && Object.hasOwn(config.commandSettings, command) ? config.commandSettings[command] : undefined;
1573
- }
1574
- function cliResultPolicy(config, command) {
1575
- return cliCommandSettingsFor(config, command)?.result;
1576
- }
1577
- function cliPassthroughField(config, command) {
1578
- return cliCommandSettingsFor(config, command)?.passthrough;
1579
- }
1580
- function cliWaitConfig(config, command) {
1581
- return cliCommandSettingsFor(config, command)?.wait;
1582
- }
1583
- function applyCliPresentationPolicy(command, descriptor, config) {
1584
- const base = { ...descriptor, aliases: new Map };
1585
- const settings = cliCommandSettingsFor(config, command);
1586
- return {
1587
- ...base,
1588
- aliases: resolveAliases(command, base, settings?.aliases),
1589
- positionals: resolvePositionals(command, base, settings?.positionals)
1590
- };
1591
- }
1592
- function assertCliPoliciesResolved(commands, config) {
1593
- const configuredNames = new Set(Object.keys(config.commandSettings ?? {}));
1594
- if (config.defaultCommand !== undefined)
1595
- configuredNames.add(config.defaultCommand);
1596
- for (const name of configuredNames) {
1597
- if (!commands.has(name)) {
1598
- throw new Error(`[stitchkit] CLI policy targets unavailable command "${name}"`);
1599
- }
1600
- }
1601
- }
1602
-
1603
- // src/tools/cli/unix-outcome.ts
1604
- var MAX_CAUSE_DEPTH = 16;
1605
- var UNIX_ERROR_CODES = new Set(UNIX_CLIENT_TRANSPORT_ERROR_CODES);
1606
- var UNIX_DELIVERY_STATES = new Set(UNIX_CLIENT_DELIVERY_STATES);
1607
- function ownString(value, key) {
1608
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
1609
- return descriptor && "value" in descriptor && typeof descriptor.value === "string" ? descriptor.value : undefined;
1610
- }
1611
- function isUnixErrorCode(value) {
1612
- return value !== undefined && UNIX_ERROR_CODES.has(value);
1613
- }
1614
- function isUnixDeliveryState(value) {
1615
- return value !== undefined && UNIX_DELIVERY_STATES.has(value);
1616
- }
1617
- function findUnixTransportError(root) {
1618
- const visited = new Set;
1619
- let current = root;
1620
- for (let depth = 0;depth < MAX_CAUSE_DEPTH && current !== undefined; depth += 1) {
1621
- if (typeof current !== "object" || current === null || visited.has(current))
1622
- return;
1623
- visited.add(current);
1624
- if (current instanceof Error && ownString(current, "name") === UNIX_CLIENT_TRANSPORT_ERROR_NAME) {
1625
- const code = ownString(current, "code");
1626
- const delivery = ownString(current, "delivery");
1627
- if (isUnixErrorCode(code) && isUnixDeliveryState(delivery)) {
1628
- const inner = current.cause;
1629
- const causeCode = typeof inner === "object" && inner !== null ? ownString(inner, "code") : undefined;
1630
- const causePath = typeof inner === "object" && inner !== null ? ownString(inner, "path") : undefined;
1631
- const socketPath = ownString(current, "socketPath") ?? causePath;
1632
- return {
1633
- code,
1634
- delivery,
1635
- message: current.message,
1636
- ...causeCode !== undefined && { causeCode },
1637
- ...socketPath !== undefined && { socketPath }
1638
- };
1639
- }
1640
- }
1641
- current = "cause" in current ? Reflect.get(current, "cause") : undefined;
1642
- }
1643
- return;
1644
- }
1645
- function notDispatchedMessage(found) {
1646
- if (found.code === "UNIX_CONNECT_FAILED") {
1647
- const target = found.socketPath ? `"${found.socketPath}"` : "the unix socket";
1648
- const suffix = found.causeCode ? ` (${found.causeCode})` : "";
1649
- return `Not executed: application is not listening on ${target}${suffix}`;
1650
- }
1651
- if (found.code === "UNIX_TARGET_REFUSED") {
1652
- return `Not executed: unix socket target refused — ${found.message}`;
1653
- }
1654
- return `Not executed: ${found.message}`;
1655
- }
1656
- function notDispatchedHint(code) {
1657
- if (code === "UNIX_CONNECT_FAILED") {
1658
- return "The request was not executed because the application is not listening; start the application and retry.";
1659
- }
1660
- if (code === "UNIX_TARGET_REFUSED") {
1661
- return "The request was not executed; check the unix socket path, owner and directory permissions.";
1662
- }
1663
- return "The request was not dispatched to the application.";
1664
- }
1665
- function projectCliUnixFailure(result) {
1666
- const found = findUnixTransportError(toolCauseFromResult(result));
1667
- if (!found)
1668
- return result;
1669
- if (found.delivery === "not-dispatched") {
1670
- return {
1671
- ok: false,
1672
- code: found.code,
1673
- details: {
1674
- message: notDispatchedMessage(found),
1675
- delivery: "not-dispatched",
1676
- ...found.socketPath !== undefined && { socketPath: found.socketPath },
1677
- ...found.causeCode !== undefined && { errno: found.causeCode }
1678
- },
1679
- hint: notDispatchedHint(found.code),
1680
- retryable: found.code === "UNIX_CONNECT_FAILED"
1681
- };
1682
- }
1683
- if (found.delivery === "possibly-dispatched") {
1684
- const code = found.code === "UNIX_HEADERS_TIMEOUT" ? "UNIX_HEADERS_TIMEOUT" : "UNIX_DELIVERY_UNCERTAIN";
1685
- const message = found.code === "UNIX_HEADERS_TIMEOUT" ? `Outcome unknown, not retried: ${found.message}` : `Outcome unknown, not retried: connection closed after the request was sent (${found.message})`;
1686
- return {
1687
- ok: false,
1688
- code,
1689
- details: {
1690
- message,
1691
- delivery: "possibly-dispatched",
1692
- ...found.socketPath !== undefined && { socketPath: found.socketPath }
1693
- },
1694
- hint: "The request may have been executed by the application before the connection closed; inspect state before retrying.",
1695
- retryable: false
1696
- };
1697
- }
1698
- return {
1699
- ok: false,
1700
- code: found.code,
1701
- details: {
1702
- message: found.message,
1703
- delivery: "response-received"
1704
- },
1705
- retryable: false
1706
- };
1707
- }
1708
-
1709
- // src/tools/cli/runner.ts
1710
- function assertCliAuthConfig(config) {
1711
- if (config.auth !== undefined && config.resolveAuth !== undefined) {
1712
- throw new Error("[stitchkit] createCli: use either auth or resolveAuth, not both");
1713
- }
1714
- }
1715
- function resolveCliIdentity(config, typedGlobals) {
1716
- let authPromise;
1717
- return () => {
1718
- authPromise ??= (async () => config.resolveAuth ? await config.resolveAuth(typedGlobals) : await config.auth)();
1719
- return authPromise;
1720
- };
1721
- }
1722
- function createCliToolRunner(config, lifecycle, auth, typedGlobals) {
1723
- const run = createToolRunner({
1724
- source: "cli",
1725
- toolSurface: true,
1726
- context: { ...config.context?.(auth, typedGlobals), signal: config.signal },
1727
- hooks: config.hooks,
1728
- lifecycle,
1729
- coerceJsonArgs: config.coerceJsonArgs
1730
- });
1731
- return async (tool, rawArgs, context, call) => {
1732
- const result = await run(tool, rawArgs, context, call);
1733
- return result.ok ? result : projectCliUnixFailure(result);
1734
- };
1735
- }
1736
-
1737
- // src/tools/cli/unavailable.ts
1738
- function unavailableCommand(reason) {
1739
- return toolResultFromError(new AppError2("CLI_COMMAND_UNAVAILABLE", {
1740
- message: reason,
1741
- status: STITCH_ERROR_STATUS2.CLI_COMMAND_UNAVAILABLE,
1742
- retryable: false
1743
- }));
1744
- }
1745
- function unknownCliCommand(command) {
1746
- return {
1747
- ok: false,
1748
- code: "UNKNOWN_OPERATION",
1749
- details: { message: `Unknown command "${command}"`, operation: command }
1750
- };
1751
- }
1752
-
1753
- // src/tools/cli/invoke.ts
1754
- function cliInvocationResult2(result, toolName, config) {
1755
- return shapeCliInvocationResult(result, toolName, config);
1756
- }
1757
- async function createCliInvoker2(config, globals) {
1758
- const lifecycle = resolveOptionalCliToolAccess("createCliInvoker", config);
1759
- assertNoLegacyCliPolicyKeys(config);
1760
- assertCliAuthConfig(config);
1761
- const typedGlobals = parseCliGlobalValues(config.globalOptions, globals);
1762
- const hasManagedFactory = typeof config.services === "function" || typeof config.runtimeTools === "function";
1763
- const auth = hasManagedFactory || !isInspectOnlyLifecycle(lifecycle) ? await resolveCliIdentity(config, typedGlobals)() : undefined;
1764
- const natives = new Map;
1765
- const allNativeHelp = new Map;
1766
- for (const definition of config.commands ?? []) {
1767
- const descriptor = applyCliPresentationPolicy(definition.name, nativeCliDescriptor(definition), config);
1768
- invokerCommandShapeIssue(definition.name, descriptor, allNativeHelp.has(definition.name), cliPassthroughField(config, definition.name));
1769
- allNativeHelp.set(definition.name, descriptor);
1770
- if (cliCommandReturnsResult(definition))
1771
- natives.set(definition.name, definition);
1772
- }
1773
- const { tools, help } = buildCliSurface(config, auth, typedGlobals, allNativeHelp, new Set, invokerCommandShapeIssue);
1774
- const runTool = isInspectOnlyLifecycle(lifecycle) ? undefined : createCliToolRunner(config, lifecycle, auth, typedGlobals);
1775
- return {
1776
- commands: [
1777
- ...[...natives].map(([name, definition]) => ({
1778
- name,
1779
- description: definition.description
1780
- })),
1781
- ...[...help].filter(([name, presentation]) => !allNativeHelp.has(name) && presentation.unavailableReason === undefined).map(([name, presentation]) => ({
1782
- name,
1783
- description: presentation.description
1784
- }))
1785
- ],
1786
- invoke: async (command, args) => {
1787
- const native = natives.get(command);
1788
- if (native) {
1789
- return executeNativeCommand(native, args, config.coerceJsonArgs ?? true, typedGlobals, {
1790
- mode: "in-process",
1791
- errorHint: config.errorHint,
1792
- exitCodes: config.exitCodes
1793
- });
1794
- }
1795
- const tool = tools.get(command);
1796
- if (!tool) {
1797
- return cliInvocationResult2(unknownCliCommand(command), command, config);
1798
- }
1799
- const inspectErr = inspectOnlyError(lifecycle);
1800
- if (inspectErr || !runTool) {
1801
- return shapeCliInvocationResult(toolResultFromError(inspectErr ?? new Error("Inspect-only surface refuses execution")), command, config, cliResultPolicy(config, command));
1802
- }
1803
- let result;
1804
- try {
1805
- result = await runTool(tool, args);
1806
- } catch (error) {
1807
- result = toolResultFromError(error);
1808
- }
1809
- return shapeCliInvocationResult(result, command, config, cliResultPolicy(config, command));
1810
- }
1811
- };
1812
- }
1813
- function buildCliSurface(config, auth, typedGlobals, nativeHelp, applicationGlobalNames, shapeIssue) {
1814
- resolveOptionalCliToolAccess("buildCliSurface", config);
1815
- assertNoLegacyCliPolicyKeys(config);
1816
- const services = typeof config.services === "function" ? config.services(auth, typedGlobals) : config.services ?? [];
1817
- const runtimeTools = typeof config.runtimeTools === "function" ? config.runtimeTools(auth, typedGlobals) : config.runtimeTools ?? [];
1818
- const tools = new Map;
1819
- const help = new Map(nativeHelp);
1820
- for (const { kind, mountable } of collectToolSurface({
1821
- surface: { services, runtimeTools },
1822
- transport: "CLI"
1823
- })) {
1824
- const descriptor = applyCliPresentationPolicy(mountable.name, managedCliDescriptor(mountable), config);
1825
- const issue = shapeIssue?.(mountable.name, descriptor, help.has(mountable.name), cliPassthroughField(config, mountable.name), applicationGlobalNames);
1826
- if (issue !== undefined) {
1827
- if (kind !== "runtime")
1828
- throw new Error(issue);
1829
- help.set(mountable.name, { ...descriptor, unavailableReason: issue });
1830
- } else {
1831
- tools.set(mountable.name, mountable);
1832
- help.set(mountable.name, descriptor);
1833
- }
1834
- }
1835
- const streams = collectCliStreams(services);
1836
- for (const [name, stream] of streams) {
1837
- const descriptor = applyCliPresentationPolicy(name, {
1838
- ...managedCliDescriptor(stream.tool),
1839
- outputSchema: stream.descriptor.item,
1840
- stream: true
1841
- }, config);
1842
- const issue = shapeIssue?.(name, descriptor, help.has(name), cliPassthroughField(config, name), applicationGlobalNames);
1843
- if (issue !== undefined)
1844
- throw new Error(issue);
1845
- help.set(name, descriptor);
1846
- }
1847
- assertCliPoliciesResolved(help, config);
1848
- for (const [name, settings] of Object.entries(config.commandSettings ?? {})) {
1849
- const policy = settings?.result;
1850
- if (!policy)
1851
- continue;
1852
- if (!tools.has(name) && !streams.has(name)) {
1853
- throw new Error(`[stitchkit] CLI result policy "${name}" targets a command that is not managed; a native command declares present and exitCode on defineCliCommand`);
1854
- }
1855
- if (policy.output !== undefined && policy.output !== help.get(name)?.outputSchema) {
1856
- throw new Error(`[stitchkit] CLI result policy "${name}" is typed against a schema that is not the one the command answers with; pass the command's own output schema to defineCliResult`);
1857
- }
1858
- if (streams.has(name) && policy.exitCode !== undefined) {
1859
- throw new Error(`[stitchkit] CLI result policy "${name}" declares exitCode for a stream command; a stream has no single result to classify`);
1860
- }
1861
- }
1862
- return { tools, streams, help };
1863
- }
1864
- function managedCliDescriptor(tool) {
1865
- return {
1866
- description: tool.method.desc,
1867
- argumentSchema: tool.argumentSchema,
1868
- presentationSchema: tool.presentationSchema,
1869
- outputSchema: toolSurfaceOutputSchema(tool.method)
1870
- };
1871
- }
1872
-
1873
- // src/tools/cli/io.ts
1874
- import { writeSync } from "node:fs";
1875
-
1876
- // src/tools/cli/stdin.ts
1877
- function readPipedStdin(input = process.stdin) {
1878
- if (input.isTTY || input.readableEnded)
1879
- return Promise.resolve(null);
1880
- if (input.destroyed)
1881
- return Promise.reject(new Error("stdin closed before EOF"));
1882
- return new Promise((resolve, reject) => {
1883
- const chunks = [];
1884
- const cleanup = () => {
1885
- clearTimeout(timer);
1886
- input.pause();
1887
- input.off("data", onData);
1888
- input.off("end", onEnd);
1889
- input.off("error", onError);
1890
- input.off("close", onClose);
1891
- };
1892
- const onData = (chunk) => {
1893
- if (chunk.length === 0)
1894
- return;
1895
- clearTimeout(timer);
1896
- chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
1897
- };
1898
- const onEnd = () => {
1899
- cleanup();
1900
- const text = Buffer.concat(chunks).toString("utf8").trim();
1901
- resolve(text.length > 0 ? text : null);
1902
- };
1903
- const onError = (error) => {
1904
- cleanup();
1905
- reject(error);
1906
- };
1907
- const onClose = () => onError(new Error("stdin closed before EOF"));
1908
- const timer = setTimeout(() => {
1909
- cleanup();
1910
- resolve(null);
1911
- }, 250);
1912
- input.on("end", onEnd);
1913
- input.on("error", onError);
1914
- input.on("close", onClose);
1915
- input.on("data", onData);
1916
- input.resume();
1917
- });
1918
- }
1919
-
1920
- // src/tools/cli/io.ts
1921
- function isReaderGone(error) {
1922
- const code = errnoOf(error);
1923
- return code === "EPIPE" || code === "ERR_STREAM_DESTROYED";
1924
- }
1925
- function createCliIo(config) {
1926
- let pendingWrite;
1927
- let writeFailed = false;
1928
- const writeFd = (fd, text) => {
1929
- const bytes = Buffer.from(text, "utf8");
1930
- let offset = 0;
1931
- while (offset < bytes.length) {
1932
- try {
1933
- offset += writeSync(fd, bytes, offset, bytes.length - offset);
1934
- } catch (error) {
1935
- if (fd === 1 && isReaderGone(error))
1936
- throw error;
1937
- if (errnoOf(error) === "EAGAIN") {
1938
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 1);
1939
- continue;
1940
- }
1941
- const stream = fd === 1 ? process.stdout : process.stderr;
1942
- const rest = bytes.subarray(offset);
1943
- pendingWrite = new Promise((resolve) => {
1944
- stream.write(rest, (failure) => {
1945
- if (failure)
1946
- writeFailed = true;
1947
- resolve();
1948
- });
1949
- });
1950
- return;
1951
- }
1952
- }
1953
- };
1954
- const writeStdout = config.stdout ?? ((text) => writeFd(1, text));
1955
- let readerGone = false;
1956
- const stdoutWhileOpen = (text) => {
1957
- if (readerGone)
1958
- return false;
1959
- try {
1960
- writeStdout(text);
1961
- return true;
1962
- } catch (error) {
1963
- if (!isReaderGone(error))
1964
- throw error;
1965
- readerGone = true;
1966
- return false;
1967
- }
1968
- };
1969
- const stdout = (text) => {
1970
- stdoutWhileOpen(text);
1971
- };
1972
- const stderr = config.stderr ?? ((text) => writeFd(2, text));
1973
- const exit = config.exit ?? ((code) => {
1974
- if (pendingWrite === undefined)
1975
- process.exit(code);
1976
- else
1977
- pendingWrite.then(() => process.exit(writeFailed ? 1 : code));
1978
- });
1979
- const readStdin = config.stdin ?? readPipedStdin;
1980
- return { stdout, stdoutWhileOpen, stderr, exit, readStdin };
1981
- }
1982
-
1983
- // src/tools/cli/notices.ts
1984
- import { AsyncLocalStorage } from "node:async_hooks";
1985
-
1986
- // src/tools/cli/args-scan.ts
1987
- var EMPTY_FIELDS = new Map;
1988
- function optionBeforeCommandError(token) {
1989
- const name = token.split("=")[0] ?? token;
1990
- return new CliArgumentError2(`${name} is an option of a command, not a command: put it after the command name (<command> ${token})`);
1991
- }
1992
- function bareOptionInfo(token) {
1993
- if (token === undefined || token === "--" || token === "-h")
1994
- return;
1995
- const opt = classifyLongOptionToken(token);
1996
- if (opt) {
1997
- return opt.inline ? undefined : { name: opt.name, frameworkBool: opt.globalKind === "boolean" };
1998
- }
1999
- if (/^-[A-Za-z]$/.test(token))
2000
- return { name: token, frameworkBool: false };
2001
- return;
2002
- }
2003
- function withdrawBrokenRequest(ctx, name) {
2004
- if (name === "schema") {
2005
- ctx.fw.schema = false;
2006
- ctx.schemaInvalid = true;
2007
- } else if (name === "help")
2008
- ctx.fw.help = false;
2009
- }
2010
- function scanCliArgv(argv, options = {}) {
2011
- const { appGlobals, defaultCommand } = options;
2012
- const appFields = appGlobals ? describeSchemaFields(appGlobals) : EMPTY_FIELDS;
2013
- const ctx = createFrameworkStepContext(argv, appFields, options.separatedBefore);
2014
- ctx.commandFound = options.afterCommand === true;
2015
- const appRaw = new Map;
2016
- const appJson = new Set;
2017
- const separatedBeforeGlobals = new Set;
2018
- let command;
2019
- let topLevelHelp = false;
2020
- let expectHelpFilter = false;
2021
- let helpFilter;
2022
- let version = false;
2023
- let optionsEnded = false;
2024
- let separatorBeforeCommand = false;
2025
- let optionBeforeCommand;
2026
- let leadingToken;
2027
- let hadLeadingPrefix = false;
2028
- let boundaryError;
2029
- const boundarySeparatedBefore = new Set;
2030
- let liftedBoundaryError;
2031
- let liftedAfter;
2032
- for (let i = 0;i < argv.length; i++) {
2033
- const token = argv[i];
2034
- if (token === undefined)
2035
- continue;
2036
- const bareBefore = liftedAfter;
2037
- liftedAfter = undefined;
2038
- if (optionsEnded) {
2039
- pushCommandToken(ctx, token, i);
2040
- continue;
2041
- }
2042
- if (token === "--") {
2043
- ctx.bareBool = undefined;
2044
- optionsEnded = true;
2045
- if (!ctx.commandFound && !topLevelHelp && !version) {
2046
- separatorBeforeCommand = true;
2047
- deferScanError(ctx, new CliArgumentError2('A command is required before "--"'));
2048
- pushRestToken(ctx, token, i);
2049
- } else {
2050
- pushCommandToken(ctx, token, i);
2051
- }
2052
- continue;
2053
- }
2054
- const opt = classifyLongOptionToken(token);
2055
- const appNext = tryReadAppGlobalToken(ctx, i, opt, appRaw, appJson);
2056
- if (appNext >= 0) {
2057
- liftedAfter = bareBefore ?? bareOptionInfo(ctx.withoutGlobals.at(-1));
2058
- markCommandTokenRemoved(ctx);
2059
- i = appNext;
2060
- continue;
2061
- }
2062
- if (bareBefore !== undefined) {
2063
- if (bareBefore.frameworkBool && separateBoolValue(token) !== undefined) {
2064
- liftedBoundaryError ??= brokenBooleanBoundaryError(bareBefore.name, token);
2065
- withdrawBrokenRequest(ctx, bareBefore.name);
2066
- deferScanError(ctx, liftedBoundaryError);
2067
- separatedBeforeGlobals.add(ctx.withoutGlobals.length);
2068
- } else if (!bareBefore.frameworkBool && !isOptionToken(token)) {
2069
- separatedBeforeGlobals.add(ctx.withoutGlobals.length);
2070
- }
2071
- }
2072
- if (!ctx.commandFound && !topLevelHelp && !version && (isTopHelpOption(token) || token === "help" || isCliVersionToken(token))) {
2073
- ctx.bareBool = undefined;
2074
- leadingToken = token;
2075
- hadLeadingPrefix = ctx.withoutGlobals.length > 0;
2076
- ctx.withoutGlobals.push(token);
2077
- if (isCliVersionToken(token))
2078
- version = true;
2079
- else {
2080
- topLevelHelp = true;
2081
- if (token.startsWith("--help=")) {
2082
- helpFilter = token.slice("--help=".length).trim() || undefined;
2083
- } else
2084
- expectHelpFilter = true;
2085
- }
2086
- continue;
2087
- }
2088
- if (token === "-h") {
2089
- ctx.bareBool = undefined;
2090
- ctx.fw.help = true;
2091
- markCommandTokenRemoved(ctx);
2092
- pushRestToken(ctx, token, i);
2093
- continue;
2094
- }
2095
- const jsonTarget = reservedJsonTarget(opt);
2096
- if (jsonTarget !== undefined) {
2097
- ctx.bareBool = undefined;
2098
- if (jsonTarget === "schema") {
2099
- ctx.fw.schema = false;
2100
- ctx.schemaInvalid = true;
2101
- } else if (jsonTarget === "help")
2102
- ctx.fw.help = false;
2103
- deferScanError(ctx, new CliArgumentError2(`--${jsonTarget} is a framework option and does not accept :=JSON`));
2104
- markCommandTokenRemoved(ctx);
2105
- pushRestToken(ctx, token, i);
2106
- continue;
2107
- }
2108
- if (opt?.globalKind !== undefined) {
2109
- markCommandTokenRemoved(ctx);
2110
- i = readFrameworkOptionToken(ctx, i, token, opt);
2111
- continue;
2112
- }
2113
- if (topLevelHelp || version) {
2114
- if (topLevelHelp && expectHelpFilter) {
2115
- expectHelpFilter = false;
2116
- if (!token.startsWith("-"))
2117
- helpFilter = token;
2118
- }
2119
- pushRestToken(ctx, token, i);
2120
- continue;
2121
- }
2122
- if (!ctx.commandFound) {
2123
- if (defaultCommand !== undefined && isOptionShapedToken(token)) {
2124
- command = defaultCommand;
2125
- ctx.commandFound = true;
2126
- } else if (isOptionShapedToken(token)) {
2127
- optionBeforeCommand ??= optionBeforeCommandError(token);
2128
- deferScanError(ctx, optionBeforeCommand);
2129
- pushRestToken(ctx, token, i);
2130
- continue;
2131
- } else {
2132
- command = token;
2133
- ctx.commandFound = true;
2134
- ctx.withoutGlobals.push(token);
2135
- if (ctx.bareBool)
2136
- ctx.bareBool.removedAfter = true;
2137
- continue;
2138
- }
2139
- }
2140
- if (ctx.bareBool?.removedAfter && separateBoolValue(token) !== undefined) {
2141
- withdrawBrokenRequest(ctx, ctx.bareBool.name);
2142
- boundaryError ??= brokenBooleanBoundaryError(ctx.bareBool.name, token);
2143
- deferScanError(ctx, boundaryError);
2144
- boundarySeparatedBefore.add(ctx.withoutCommand.length);
2145
- }
2146
- ctx.bareBool = undefined;
2147
- pushCommandToken(ctx, token, i);
2148
- }
2149
- finalizeFrameworkView(ctx);
2150
- let globals = parseCliGlobalValues(undefined, {});
2151
- try {
2152
- const rawGlobals = coerceAppGlobalMap(appRaw, appFields, appJson);
2153
- globals = parseCliGlobalValues(appGlobals, rawGlobals);
2154
- } catch (error) {
2155
- if (error instanceof CliArgumentError2)
2156
- recordAppGlobalError(ctx, error);
2157
- else
2158
- throw error;
2159
- }
2160
- if (!ctx.commandFound && !topLevelHelp && !version && !separatorBeforeCommand) {
2161
- if (defaultCommand !== undefined)
2162
- command = defaultCommand;
2163
- else if (ctx.deferredError === undefined || ctx.fw.help)
2164
- topLevelHelp = true;
2165
- }
2166
- return {
2167
- framework: ctx.fw,
2168
- globals,
2169
- ...command !== undefined && { command },
2170
- commandTokens: ctx.commandTokens,
2171
- separatedBefore: ctx.separatedBefore,
2172
- topLevelHelp,
2173
- ...helpFilter !== undefined && { helpFilter },
2174
- version,
2175
- withoutGlobals: ctx.withoutGlobals,
2176
- withoutCommand: ctx.withoutCommand,
2177
- withoutCommandSeparatedBefore: withoutCommandSeparations(ctx),
2178
- separatedBeforeGlobals,
2179
- ...ctx.deferredError !== undefined && { deferredError: ctx.deferredError },
2180
- ...ctx.appGlobalError !== undefined && { appGlobalError: ctx.appGlobalError },
2181
- ...boundaryError !== undefined && { boundaryError },
2182
- boundarySeparatedBefore,
2183
- ...liftedBoundaryError !== undefined && { liftedBoundaryError },
2184
- separatorBeforeCommand,
2185
- ...optionBeforeCommand !== undefined && { optionBeforeCommand },
2186
- ...leadingToken !== undefined && { leadingToken },
2187
- hadLeadingPrefix
2188
- };
2189
- }
2190
- function answersBeforeArguments(scan) {
2191
- return scan.topLevelHelp || scan.version || scan.framework.help || scan.framework.schema;
2192
- }
2193
- function scanCliInvocation2(argv, options) {
2194
- let res;
2195
- try {
2196
- res = scanCliArgv(argv, options);
2197
- } catch (error) {
2198
- if (error instanceof CliArgumentError2) {
2199
- return {
2200
- framework: {
2201
- json: false,
2202
- wait: false,
2203
- quiet: false,
2204
- dryRun: false,
2205
- help: false,
2206
- schema: false
2207
- },
2208
- globals: parseCliGlobalValues(undefined, {}),
2209
- commandTokens: [],
2210
- separatedBefore: new Set,
2211
- topLevelHelp: false,
2212
- version: false,
2213
- error
2214
- };
2215
- }
2216
- throw error;
2217
- }
2218
- const error = answersBeforeArguments(res) ? undefined : res.deferredError;
2219
- if (error !== undefined) {
2220
- return {
2221
- framework: res.framework,
2222
- globals: res.globals,
2223
- commandTokens: [],
2224
- separatedBefore: new Set,
2225
- topLevelHelp: false,
2226
- version: false,
2227
- error
2228
- };
2229
- }
2230
- return {
2231
- framework: res.framework,
2232
- globals: res.globals,
2233
- ...res.command !== undefined && { command: res.command },
2234
- commandTokens: res.commandTokens,
2235
- separatedBefore: res.separatedBefore,
2236
- topLevelHelp: res.topLevelHelp,
2237
- ...res.helpFilter !== undefined && { helpFilter: res.helpFilter },
2238
- version: res.version
2239
- };
2240
- }
2241
-
2242
- // src/tools/cli/notices.ts
2243
- var invocationNotices = new AsyncLocalStorage;
2244
- function withCliNotices(quiet, stderr, run) {
2245
- return invocationNotices.run({ quiet, stderr }, run);
2246
- }
2247
- function writeCliNotice(text) {
2248
- const invocation = invocationNotices.getStore();
2249
- if (invocation !== undefined) {
2250
- if (!invocation.quiet)
2251
- invocation.stderr(text);
2252
- return;
2253
- }
2254
- const scan = scanCliInvocation2(process.argv.slice(2));
2255
- if (scan.error !== undefined || scan.framework.quiet)
2256
- return;
2257
- process.stderr.write(text);
2258
- }
2259
-
2260
- // src/tools/cli/download.ts
2261
- import { createHash } from "node:crypto";
2262
- import { basename as basename2, resolve } from "node:path";
2263
-
2264
- // src/internal/write-download.ts
2265
- import path from "node:path";
2266
- async function writeDownload(root, name, data) {
2267
- if (!isSafeEntryName(name) || path.basename(name) !== name) {
2268
- throw new Error("download name escapes the output dir");
2269
- }
2270
- const parent = { handle: root, basename: name };
2271
- const metadata = await containedEntryMetadata(parent);
2272
- await writeContainedFile({
2273
- parent,
2274
- content: data,
2275
- replace: true,
2276
- ...metadata?.isFile() && { mode: metadata.mode }
2277
- });
2278
- }
2279
-
2280
- // src/tools/cli/inline-files.ts
2281
- import { basename } from "node:path";
2282
- import { pathToFileURL } from "node:url";
2283
- import { z as z3 } from "zod";
2284
- var EmbeddedResourceSchema = z3.object({
2285
- type: z3.literal("resource"),
2286
- resource: z3.union([
2287
- z3.object({ uri: z3.string(), mimeType: z3.string().optional(), blob: z3.string() }),
2288
- z3.object({ uri: z3.string(), mimeType: z3.string().optional(), text: z3.string() })
2289
- ])
2290
- });
2291
- var InlineFileSchema = z3.discriminatedUnion("type", [
2292
- McpImageContentSchema,
2293
- McpAudioContentSchema,
2294
- EmbeddedResourceSchema
2295
- ]);
2296
- function inlineFileBlocks(data) {
2297
- if (!isRecord(data) || !Array.isArray(data.content))
2298
- return [];
2299
- return data.content.flatMap((part, index) => {
2300
- const parsed = InlineFileSchema.safeParse(part);
2301
- return parsed.success ? [{ index, file: parsed.data }] : [];
2302
- });
2303
- }
2304
- function decodeBase64(data, maxBytes) {
2305
- const padding = data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0;
2306
- const decodedLength = Math.floor((data.length - padding) * 3 / 4);
2307
- if (data.length > Math.ceil(maxBytes / 3) * 4 || decodedLength > maxBytes) {
2308
- throw new Error(`file exceeds the ${maxBytes}-byte cap`);
2309
- }
2310
- if (data.length % 4 === 1 || padding > 0 && data.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(data)) {
2311
- throw new Error("invalid base64");
2312
- }
2313
- const bytes = Buffer.from(data, "base64");
2314
- if (!bytes.toString("base64").startsWith(data))
2315
- throw new Error("invalid base64");
2316
- return bytes;
2317
- }
2318
- function encodeText(text, maxBytes) {
2319
- const bytes = text.length > maxBytes ? undefined : Buffer.from(text, "utf8");
2320
- if (!bytes || bytes.length > maxBytes) {
2321
- throw new Error(`file exceeds the ${maxBytes}-byte cap`);
2322
- }
2323
- return bytes;
2324
- }
2325
- function inlineFileBytes(file, maxBytes) {
2326
- if (file.type !== "resource")
2327
- return decodeBase64(file.data, maxBytes);
2328
- return "blob" in file.resource ? decodeBase64(file.resource.blob, maxBytes) : encodeText(file.resource.text, maxBytes);
2329
- }
2330
- function uriFileName(uri) {
2331
- try {
2332
- return basename(new URL(uri).pathname);
2333
- } catch {
2334
- return "";
2335
- }
2336
- }
2337
- function inlineFileMimeType(file) {
2338
- return file.type === "resource" ? file.resource.mimeType : file.mimeType;
2339
- }
2340
- function ownFileName(file) {
2341
- if (file.type === "resource")
2342
- return uriFileName(file.resource.uri) || undefined;
2343
- const name = file._meta?.[MCP_FILE_NAME_META_KEY2];
2344
- return typeof name === "string" ? name : undefined;
2345
- }
2346
- function inlineFileName(file, digest) {
2347
- return ownFileName(file) ?? `${file.type}-${digest}${mediaExtension(inlineFileMimeType(file) ?? "") ?? ".bin"}`;
2348
- }
2349
- function linkSavedFiles(data, blocks, saved) {
2350
- if (!isRecord(data) || !Array.isArray(data.content))
2351
- return data;
2352
- const links = new Map;
2353
- for (const block of blocks) {
2354
- const file = saved(block);
2355
- if (!file)
2356
- continue;
2357
- const mimeType = inlineFileMimeType(block.file);
2358
- links.set(block.index, {
2359
- type: "resource_link",
2360
- uri: pathToFileURL(file.path).href,
2361
- name: file.name,
2362
- ...mimeType !== undefined && { mimeType },
2363
- size: file.size
2364
- });
2365
- }
2366
- if (links.size === 0)
2367
- return data;
2368
- return { ...data, content: data.content.map((part, index) => links.get(index) ?? part) };
2369
- }
2370
-
2371
- // src/tools/cli/download.ts
2372
- var DEFAULT_DOWNLOAD_MAX_BYTES = 100 * 1024 * 1024;
2373
- async function saveResultMedia(data, options) {
2374
- const blocks = inlineFileBlocks(data);
2375
- const sources = [...options.download?.(data) ?? [], ...blocks];
2376
- if (sources.length === 0) {
2377
- if (!options.quiet)
2378
- options.stderr(`--output-dir: the result carries no files to save
2379
- `);
2380
- return { ok: true, data };
2381
- }
2382
- const batch = await saveBatch(sources, options);
2383
- return {
2384
- ok: batch.ok,
2385
- data: linkSavedFiles(data, blocks, (block) => batch.files.get(block))
2386
- };
2387
- }
2388
- async function saveBatch(sources, { dir, allowPrivateHosts, maxBytes, timeoutMs, quiet, stderr }) {
2389
- const root = resolve(dir);
2390
- const files = new Map;
2391
- let directory;
2392
- try {
2393
- directory = await openPinnedDirectory(root, { create: true, readable: false });
2394
- } catch (error) {
2395
- stderr(`failed to prepare download directory: ${error instanceof Error ? error.message : String(error)}
2396
- `);
2397
- return { ok: false, files };
2398
- }
2399
- let ok = true;
2400
- const digests = new Map;
2401
- try {
2402
- for (const source of sources) {
2403
- try {
2404
- const bytes = "url" in source ? await fetchDownload(source.url, allowPrivateHosts, maxBytes, timeoutMs) : inlineFileBytes(source.file, maxBytes);
2405
- const digest = createHash("sha256").update(bytes).digest("hex");
2406
- const name = basename2("url" in source ? source.name : inlineFileName(source.file, digest));
2407
- const path = resolve(root, name);
2408
- const written = digests.get(name);
2409
- if (written === undefined) {
2410
- await writeDownload(directory, name, bytes);
2411
- digests.set(name, digest);
2412
- if (!quiet)
2413
- stderr(`saved ${path} (${(bytes.length / 1024).toFixed(0)}KB)
2414
- `);
2415
- } else if (written !== digest) {
2416
- throw new Error(`another file of this batch is already saved as ${JSON.stringify(name)}`);
2417
- }
2418
- files.set(source, { path, name, size: bytes.length });
2419
- } catch (err) {
2420
- ok = false;
2421
- const reason = errnoOf(err) ?? (err instanceof Error ? err.message : String(err));
2422
- const subject = "url" in source ? `failed to download ${source.url}` : `failed to save content[${source.index}]`;
2423
- stderr(`${subject}: ${reason}
2424
- `);
2425
- }
2426
- }
2427
- } finally {
2428
- try {
2429
- await directory.close();
2430
- } catch (error) {
2431
- ok = false;
2432
- stderr(`failed to close download directory: ${error instanceof Error ? error.message : String(error)}
2433
- `);
2434
- }
2435
- }
2436
- return { ok, files };
2437
- }
2438
- async function fetchDownload(url, allowPrivateHosts, maxBytes, timeoutMs) {
2439
- const res = await fetchGuarded(new URL(url), allowPrivateHosts, { timeoutMs });
2440
- if (!res.ok)
2441
- throw new Error(`HTTP ${res.status}`);
2442
- const bytes = await readCapped(res, maxBytes);
2443
- if (!bytes)
2444
- throw new Error(`file exceeds the ${maxBytes}-byte cap`);
2445
- return bytes;
2446
- }
2447
-
2448
- // src/tools/cli/help.ts
2449
- var GLOBAL_OPTIONS = [
2450
- ["--json", "Emit compact success/error JSON records (for scripts)"],
2451
- ["--wait", "Block-poll an async result to a terminal state"],
2452
- ["--wait-timeout <s>", "Override the --wait timeout in seconds"],
2453
- ["--output-dir <dir>", "Save the files a result names or carries into a directory"],
2454
- ["--quiet", "Suppress non-essential stderr output"],
2455
- ["--dry-run", "Print the resolved call without executing it"],
2456
- ["--schema", "Print the JSON Schema of a command input and output"],
2457
- ["--help, -h", "Show help for a command"],
2458
- ["--help <text>", "List only the commands matching a substring"],
2459
- ["--count-by <field>", "Count records per distinct value of a field"],
2460
- ["--sum <field>", "Total a numeric field, optionally grouped by --by"],
2461
- ["--sort <field>", "Order the records by a field, largest first"],
2462
- ["--ascending", "Flip --sort to smallest first"],
2463
- ["--top <n>", "Keep the n leading entries of the view asked for"],
2464
- ["--table <a,b>", "Render the named fields as an aligned table"]
2465
- ];
2466
- function typeLabel(schema) {
2467
- if (HELP_SHOWN_KEYWORDS.has("enum") && Array.isArray(schema.enum)) {
2468
- return schema.enum.join("|");
2469
- }
2470
- if (HELP_SHOWN_KEYWORDS.has("type")) {
2471
- if (schema.type === "array")
2472
- return "value";
2473
- if (typeof schema.type === "string")
2474
- return schema.type;
2475
- }
2476
- return "value";
2477
- }
2478
- function isPatternOnly(member) {
2479
- return isRecord(member) && typeof member.pattern === "string" && Object.keys(member).every((key) => key === "pattern" || key === "type");
2480
- }
2481
- function constraintLabel(schema) {
2482
- const limits = [];
2483
- const format = HELP_SHOWN_KEYWORDS.has("format") && typeof schema.format === "string" ? schema.format : undefined;
2484
- const pattern = HELP_SHOWN_KEYWORDS.has("pattern") && typeof schema.pattern === "string" ? schema.pattern : undefined;
2485
- const named = format !== undefined && STANDARD_STRING_FORMATS.has(format);
2486
- if (format !== undefined && (named || pattern === undefined)) {
2487
- limits.push(format);
2488
- } else if (pattern !== undefined) {
2489
- limits.push(`pattern /${pattern}/`);
2490
- }
2491
- const bounds = [
2492
- ["minimum", ">="],
2493
- ["exclusiveMinimum", ">"],
2494
- ["maximum", "<="],
2495
- ["exclusiveMaximum", "<"],
2496
- ["minLength", "length >="],
2497
- ["maxLength", "length <="],
2498
- ["minItems", "items >="],
2499
- ["maxItems", "items <="]
2500
- ];
2501
- for (const [keyword, label] of bounds) {
2502
- if (!HELP_SHOWN_KEYWORDS.has(keyword))
2503
- continue;
2504
- const bound = schema[keyword];
2505
- if (typeof bound !== "number")
2506
- continue;
2507
- if (schema.type === "integer" && Math.abs(bound) === Number.MAX_SAFE_INTEGER)
2508
- continue;
2509
- limits.push(`${label}${bound}`);
2510
- }
2511
- const compositions = [
2512
- ["anyOf", "any of", " | "],
2513
- ["oneOf", "one of", " | "],
2514
- ["allOf", "all of", " & "]
2515
- ];
2516
- for (const [keyword, label, separator] of compositions) {
2517
- if (!HELP_SHOWN_KEYWORDS.has(keyword))
2518
- continue;
2519
- const members = schema[keyword];
2520
- if (!Array.isArray(members))
2521
- continue;
2522
- const stated = named && keyword === "allOf" ? members.filter((member) => !isPatternOnly(member)) : members;
2523
- const branches = stated.map((member) => {
2524
- const constraints = isRecord(member) ? constraintLabel(member) : "";
2525
- const type = isRecord(member) ? typeLabel(member) : member === false ? "no value" : "any value";
2526
- return { constraints, text: `${type}${constraints}` };
2527
- });
2528
- if (branches.every((branch) => branch.constraints === ""))
2529
- continue;
2530
- limits.push(`${label}: ${branches.map((branch) => branch.text).join(separator)}`);
2531
- }
2532
- return limits.length === 0 ? "" : ` [${limits.join(", ")}]`;
2533
- }
2534
- function fieldTypeLabel(schema) {
2535
- return `<${typeLabel(schema)}>${constraintLabel(schema)}`;
2536
- }
2537
- function nullableField(schema) {
2538
- if (schema.type === "null")
2539
- return true;
2540
- if (Array.isArray(schema.type) && schema.type.includes("null"))
2541
- return true;
2542
- return Array.isArray(schema.anyOf) && schema.anyOf.some((member) => isRecord(member) && nullableField(member));
2543
- }
2544
- function jsonValueHelp(fields) {
2545
- const example = fields.find((field) => nullableField(field.schema))?.name;
2546
- return [
2547
- "Assign a whole JSON value with --field:=JSON; the declared schema still validates it.",
2548
- ...example === undefined ? [] : [`JSON null: --${example}:=null. The literal string stays --${example} null.`]
2549
- ];
2550
- }
2551
- function padRight(text, width) {
2552
- return text.length >= width ? text : text + " ".repeat(width - text.length);
2553
- }
2554
- function summarize(desc) {
2555
- const firstLine = desc.split(`
2556
- `)[0]?.trim() ?? "";
2557
- const firstSentence = firstLine.split(". ")[0]?.trim() ?? firstLine;
2558
- const max = 72;
2559
- return firstSentence.length > max ? `${firstSentence.slice(0, max - 1).trimEnd()}…` : firstSentence;
2560
- }
2561
- function applicationOptionLines(fields) {
2562
- if (fields.length === 0)
2563
- return [];
2564
- const labels = new Map(fields.map((field) => [field.name, `--${field.name} ${fieldTypeLabel(field.schema)}`]));
2565
- const width = Math.max(...fields.map((field) => labels.get(field.name)?.length ?? 0));
2566
- return [
2567
- "",
2568
- "Application options:",
2569
- ...fields.map((field) => ` ${padRight(labels.get(field.name) ?? `--${field.name}`, width)} ${field.description ?? ""}`.trimEnd())
2570
- ];
2571
- }
2572
- function filterCommands(commands, filter) {
2573
- const needle = filter.toLowerCase();
2574
- return new Map([...commands].filter(([command, descriptor]) => command.toLowerCase().includes(needle) || descriptor.description.toLowerCase().includes(needle)));
2575
- }
2576
- function renderTopHelp(input) {
2577
- const { name, version, defaultCommand } = input;
2578
- const commands = input.filter === undefined ? input.commands : filterCommands(input.commands, input.filter);
2579
- const lines = [
2580
- `${name} ${version}`,
2581
- "",
2582
- `Usage: ${name} ${defaultCommand ? "[command]" : "<command>"} [args] [--flags]`,
2583
- "",
2584
- input.filter === undefined ? "Commands:" : `Commands matching "${input.filter}" (${commands.size} of ${input.commands.size}):`
2585
- ];
2586
- const width = Math.max(0, ...[...commands.keys()].map((key) => key.length));
2587
- for (const [command, descriptor] of commands) {
2588
- lines.push(` ${padRight(command, width)} ${summarize(descriptor.description)}${command === defaultCommand ? " (default)" : ""}${descriptor.unavailableReason !== undefined ? " [unavailable]" : ""}`);
2589
- if (descriptor.unavailableReason !== undefined) {
2590
- lines.push(` Unavailable: ${descriptor.unavailableReason}`);
2591
- }
2592
- }
2593
- if (input.unavailable !== undefined) {
2594
- lines.push("", `Managed commands are unavailable: ${input.unavailable}`);
2595
- }
2596
- if (input.filter !== undefined) {
2597
- lines.push("", `Run "${name} <command> --help" for command-specific flags.`);
2598
- return `${lines.join(`
2599
- `)}
2600
- `;
2601
- }
2602
- lines.push("", "Global options:");
2603
- const optWidth = Math.max(...GLOBAL_OPTIONS.map(([flag]) => flag.length));
2604
- for (const [flag, desc] of GLOBAL_OPTIONS)
2605
- lines.push(` ${padRight(flag, optWidth)} ${desc}`);
2606
- lines.push(...applicationOptionLines(input.applicationOptions));
2607
- lines.push("", ...jsonValueHelp(input.applicationOptions));
2608
- lines.push("", `Run "${name} <command> --help" for command-specific flags.`);
2609
- return `${lines.join(`
2610
- `)}
2611
- `;
2612
- }
2613
- function renderCommandHelp(name, command, descriptor, applicationOptions = []) {
2614
- const fields = jsonSchemaFields(descriptor.presentationSchema);
2615
- const fieldsByName = new Map(fields.map((field) => [field.name, field]));
2616
- const kinds = describeSchemaFields(descriptor.argumentSchema);
2617
- const positionals = [];
2618
- const positionalNames = descriptor.positionals ?? [...kinds].filter(([, info]) => info.kind !== "boolean").map(([fieldName]) => fieldName);
2619
- for (const fieldName of positionalNames) {
2620
- const field = fieldsByName.get(fieldName);
2621
- if (field)
2622
- positionals.push(field);
2623
- }
2624
- const variadicTail = descriptor.positionals !== undefined && kinds.get(descriptor.positionals[descriptor.positionals.length - 1] ?? "")?.kind === "array" ? descriptor.positionals[descriptor.positionals.length - 1] : undefined;
2625
- const positionalSyntax = new Map(positionals.map((field) => {
2626
- const label = field.name === variadicTail ? `${field.name}...` : field.name;
2627
- return [field.name, field.required ? `<${label}>` : `[${label}]`];
2628
- }));
2629
- const usage = [
2630
- `Usage: ${name} ${command}`,
2631
- ...positionals.map((field) => positionalSyntax.get(field.name) ?? field.name),
2632
- "[--flags]"
2633
- ].join(" ");
2634
- const lines = [descriptor.description, "", usage, ""];
2635
- if (descriptor.unavailableReason !== undefined) {
2636
- lines.push(`Unavailable: ${descriptor.unavailableReason}`, "");
2637
- }
2638
- if (fields.length > 0) {
2639
- lines.push("Arguments:");
2640
- const labels = new Map(fields.map((field) => {
2641
- const positional = positionalSyntax.get(field.name);
2642
- const alias = descriptor.aliases.get(field.name);
2643
- const option = alias ? `-${alias}, --${field.name}` : `--${field.name}`;
2644
- return [field.name, positional ? `${positional} | ${option}` : option];
2645
- }));
2646
- const width = Math.max(...fields.map((field) => labels.get(field.name)?.length ?? 0));
2647
- for (const f of fields) {
2648
- const req = f.required ? " (required)" : "";
2649
- const desc = f.description ? ` — ${f.description}` : "";
2650
- const label = labels.get(f.name) ?? `--${f.name}`;
2651
- lines.push(` ${padRight(label, width)} ${fieldTypeLabel(f.schema)}${req}${desc}`);
2652
- }
2653
- const flag = [...kinds].find(([, info]) => info.kind === "boolean")?.[0];
2654
- if (flag !== undefined) {
2655
- lines.push("", `A boolean flag is on alone or takes true/false: --${flag}, --${flag} false, --no-${flag}`);
2656
- }
2657
- const arrays = [...kinds].filter(([, info]) => info.kind === "array");
2658
- for (const [field] of arrays) {
2659
- lines.push("", `Repeat --${field} <value> for each element, or assign the whole array with --${field}:=JSON.`);
2660
- }
2661
- if (arrays.length > 0 && descriptor.positionals === undefined) {
2662
- lines.push("Array options cannot be combined with automatic positional arguments; name other fields with flags.");
2663
- }
2664
- lines.push("", ...jsonValueHelp(fields), "");
2665
- }
2666
- const applicationLines = applicationOptionLines(applicationOptions);
2667
- if (applicationLines.length > 0)
2668
- lines.push(...applicationLines.slice(1), "");
2669
- return `${lines.join(`
2670
- `)}
2671
- `;
2672
- }
2673
-
2674
- // src/tools/cli/managed-surface.ts
2675
- async function buildManagedSurface(session, typedGlobals, forExecution) {
2676
- const { config, nativeHelp, applicationGlobalNames } = session;
2677
- const resolveIdentity = resolveCliIdentity(config, typedGlobals);
2678
- let auth;
2679
- if (session.hasManagedFactory || forExecution) {
2680
- try {
2681
- auth = await resolveIdentity();
2682
- } catch (error) {
2683
- const failure = toolResultFromError(error);
2684
- const normalized = toolErrorFromResult(failure);
2685
- return {
2686
- resolved: false,
2687
- failure,
2688
- reason: `${normalized.code}: ${normalized.message}`,
2689
- help: new Map(nativeHelp)
2690
- };
2691
- }
2692
- }
2693
- const { tools, streams, help } = buildCliSurface(config, auth, typedGlobals, nativeHelp, applicationGlobalNames, commandShapeIssue);
2694
- return { resolved: true, auth, help, tools, streams };
2695
- }
2696
-
2697
- // src/tools/cli/args-tokens.ts
2698
- function readCliTokens(argv, fields, fieldFor, config) {
2699
- const fwState = {
2700
- fw: { json: false, wait: false, quiet: false, dryRun: false, help: false, schema: false },
2701
- fwFlags: new Map,
2702
- viewFlags: new Map,
2703
- ascending: false
2704
- };
2705
- const flags = new Map;
2706
- const jsonFields = new Set;
2707
- const literalBooleanFlags = new Set;
2708
- const positionals = [];
2709
- const pushFlag = (name, value, json = false) => {
2710
- appendCliFieldValue(flags, jsonFields, name, value, fieldFor(name), json);
2711
- };
2712
- const adjacent = (index) => !config.separatedBefore?.has(index);
2713
- let optionsEnded = false;
2714
- for (let i = 0;i < argv.length; i++) {
2715
- const tok = argv[i];
2716
- if (tok === undefined)
2717
- continue;
2718
- if (!optionsEnded && tok === "--") {
2719
- optionsEnded = true;
2720
- continue;
2721
- }
2722
- if (optionsEnded || !looksLikeOption(tok)) {
2723
- positionals.push(tok);
2724
- continue;
2725
- }
2726
- if (tok === "-h") {
2727
- fwState.fw.help = true;
2728
- continue;
2729
- }
2730
- if (!tok.startsWith("--")) {
2731
- const match = /^-([A-Za-z])(?:=(.*))?$/.exec(tok);
2732
- const alias = match?.[1];
2733
- const field = alias === undefined ? undefined : config.aliases?.get(alias);
2734
- if (!alias || !field)
2735
- throw new CliArgumentError2(`Unknown option "${tok}"`);
2736
- const inline = match?.[2];
2737
- const info = fieldFor(field);
2738
- if (info?.kind === "boolean") {
2739
- const separate = inline === undefined && adjacent(i + 1) ? separateBoolValue(argv[i + 1]) : undefined;
2740
- if (separate !== undefined)
2741
- i++;
2742
- pushFlag(field, inline ?? String(separate ?? true));
2743
- if (inline !== undefined && info.pureBoolean === true) {
2744
- parseReservedBool(field, inline);
2745
- }
2746
- literalBooleanFlags.add(field);
2747
- continue;
2748
- }
2749
- let value = inline;
2750
- if (value === undefined) {
2751
- const next = adjacent(i + 1) ? argv[i + 1] : undefined;
2752
- if (next !== undefined && !isOptionToken(next)) {
2753
- value = next;
2754
- i++;
2755
- } else {
2756
- throw new CliArgumentError2(`--${field} requires a value`);
2757
- }
2758
- }
2759
- pushFlag(field, value);
2760
- continue;
2761
- }
2762
- const option = classifyLongOptionToken(tok);
2763
- if (!option)
2764
- throw new CliArgumentError2(`Unknown option "${tok}"`);
2765
- const { name, json } = cliFieldOption(option, fields);
2766
- let { value } = option;
2767
- if (name.length === 0)
2768
- throw new CliArgumentError2("Invalid empty option name");
2769
- if (json && RESERVED_CLI_OPTIONS.has(name)) {
2770
- throw new CliArgumentError2(`--${name} is a framework option and does not accept :=JSON`);
2771
- }
2772
- if (option.globalKind !== undefined) {
2773
- i = consumeFrameworkOptionToken(argv, i, option, fwState, {
2774
- adjacent,
2775
- onError: (error) => {
2776
- throw error;
2777
- }
2778
- });
2779
- continue;
2780
- }
2781
- if (value === undefined && name.startsWith("no-") && !fieldFor(name) && fieldFor(name.slice(3))?.kind === "boolean") {
2782
- pushFlag(name.slice(3), "false");
2783
- literalBooleanFlags.add(name.slice(3));
2784
- continue;
2785
- }
2786
- const unsafeSegment = name.split(".").find(isUnsafeKey);
2787
- if (unsafeSegment !== undefined) {
2788
- throw new CliArgumentError2(`Unsafe option name "--${name}"`);
2789
- }
2790
- const info = fieldFor(name);
2791
- const rootName = name.split(".")[0] ?? name;
2792
- if (!fields.has(rootName) && !config.allowUnknown) {
2793
- throw new CliArgumentError2(`Unknown option "--${name}"`);
2794
- }
2795
- if (value === undefined) {
2796
- if (info?.kind === "boolean") {
2797
- const separate = adjacent(i + 1) ? separateBoolValue(argv[i + 1]) : undefined;
2798
- if (separate !== undefined)
2799
- i++;
2800
- pushFlag(name, String(separate ?? true));
2801
- literalBooleanFlags.add(name);
2802
- continue;
2803
- }
2804
- const next = adjacent(i + 1) ? argv[i + 1] : undefined;
2805
- if (next !== undefined && !isOptionToken(next)) {
2806
- value = next;
2807
- i++;
2808
- } else {
2809
- throw new CliArgumentError2(`--${name} requires a value`);
2810
- }
2811
- }
2812
- pushFlag(name, value, json);
2813
- if (option.inline && !json && info?.kind === "boolean" && info.pureBoolean === true) {
2814
- parseReservedBool(name, value);
2815
- }
2816
- }
2817
- const { fw } = fwState;
2818
- const options = {
2819
- json: fw.json,
2820
- wait: fw.wait,
2821
- quiet: fw.quiet,
2822
- dryRun: fw.dryRun,
2823
- help: fw.help,
2824
- schema: fw.schema,
2825
- ...fw.waitTimeout !== undefined && { waitTimeout: fw.waitTimeout },
2826
- ...fw.outputDir !== undefined && { outputDir: fw.outputDir }
2827
- };
2828
- return {
2829
- options,
2830
- flags,
2831
- jsonFields,
2832
- literalBooleanFlags,
2833
- viewFlags: fwState.viewFlags,
2834
- ascending: fwState.ascending,
2835
- positionals
2836
- };
2837
- }
2838
-
2839
- // src/tools/cli/args.ts
2840
- function buildToolArgs(tokens, fields, fieldFor, declaredPositionals, allowUnknown) {
2841
- const { flags, jsonFields, literalBooleanFlags, positionals } = tokens;
2842
- if (declaredPositionals === undefined && positionals.length > 0) {
2843
- const arrayFlag = [...flags.keys()].find((key) => fieldFor(key)?.kind === "array");
2844
- if (arrayFlag !== undefined) {
2845
- throw new CliArgumentError2(`--${arrayFlag} cannot be combined with automatic positional arguments. Repeat --${arrayFlag} for each element or use --${arrayFlag}:=JSON; name other fields with flags, or declare a positional policy.`);
2846
- }
2847
- }
2848
- const toolArgs = {};
2849
- const fillable = declaredPositionals === undefined ? [...fields.entries()].filter(([, info]) => info.kind !== "boolean").map(([name]) => name) : [...declaredPositionals];
2850
- const variadicTail = declaredPositionals !== undefined && fields.get(fillable[fillable.length - 1] ?? "")?.kind === "array" ? fillable[fillable.length - 1] : undefined;
2851
- let pi = 0;
2852
- for (const key of fillable) {
2853
- if (pi >= positionals.length)
2854
- break;
2855
- if (key === variadicTail) {
2856
- if (flags.has(key)) {
2857
- throw new CliArgumentError2(`--${key} conflicts with the positional values for "${key}" — pass one form, not both`);
2858
- }
2859
- toolArgs[key] = coerceField(fields.get(key), positionals.slice(pi), `<${key}>`);
2860
- pi = positionals.length;
2861
- break;
2862
- }
2863
- if (flags.has(key))
2864
- continue;
2865
- const value = positionals[pi++];
2866
- if (value !== undefined) {
2867
- toolArgs[key] = coerceField(fields.get(key), [value], `<${key}>`);
2868
- }
2869
- }
2870
- if (pi < positionals.length) {
2871
- throw new CliArgumentError2(`Unexpected positional argument "${positionals[pi]}"`);
2872
- }
2873
- const dottedRoots = new Map;
2874
- for (const key of flags.keys()) {
2875
- const dot = key.indexOf(".");
2876
- const exactLiteralBoolean = literalBooleanFlags.has(key) && fields.has(key);
2877
- if (dot > 0 && !exactLiteralBoolean) {
2878
- dottedRoots.set(key.slice(0, dot), key);
2879
- }
2880
- }
2881
- for (const [root, dotted] of dottedRoots) {
2882
- if (flags.has(root)) {
2883
- throw new CliArgumentError2(`--${root} conflicts with --${dotted} — pass one form, not both`);
2884
- }
2885
- }
2886
- for (const key of jsonFields) {
2887
- for (const other of flags.keys()) {
2888
- if (other.startsWith(`${key}.`) || key.startsWith(`${other}.`)) {
2889
- throw new CliArgumentError2(`--${key} conflicts with --${other} — pass one form, not both`);
2890
- }
2891
- }
2892
- }
2893
- for (const [key, values] of flags) {
2894
- const info = fieldFor(key);
2895
- const exactLiteralBoolean = literalBooleanFlags.has(key) && fields.has(key);
2896
- if (key.includes(".") && !exactLiteralBoolean) {
2897
- const root = key.split(".")[0] ?? key;
2898
- const value = !jsonFields.has(key) && info === undefined && allowUnknown && !fields.has(root) ? looseCoerce(values[0] ?? "") : coerceCliFieldValue(info, values, `--${key}`, jsonFields.has(key));
2899
- setNested(toolArgs, key.split("."), value);
2900
- continue;
2901
- }
2902
- toolArgs[key] = coerceCliFieldValue(info, values, `--${key}`, jsonFields.has(key));
2903
- }
2904
- return toolArgs;
2905
- }
2906
- function cliRunOptions(framework) {
2907
- return {
2908
- json: framework.json,
2909
- wait: framework.wait,
2910
- quiet: framework.quiet,
2911
- dryRun: framework.dryRun,
2912
- help: framework.help,
2913
- schema: framework.schema,
2914
- ...framework.waitTimeout !== undefined && { waitTimeout: framework.waitTimeout },
2915
- ...framework.outputDir !== undefined && { outputDir: framework.outputDir },
2916
- ...framework.view !== undefined && { view: framework.view }
2917
- };
2918
- }
2919
- function parseCliArgs2(argv, schema, config = {}) {
2920
- try {
2921
- return parseCommandArgv(argv, schema, config);
2922
- } catch (error) {
2923
- if (!(error instanceof CliArgumentError2))
2924
- throw error;
2925
- const scan = scanCliArgv(argv, {
2926
- afterCommand: true,
2927
- separatedBefore: config.separatedBefore
2928
- });
2929
- if (!answersBeforeArguments(scan))
2930
- throw error;
2931
- return { toolArgs: {}, options: cliRunOptions(scan.framework) };
2932
- }
2933
- }
2934
- function parseCommandArgv(argv, schema, config) {
2935
- const fields = describeSchemaFields(schema);
2936
- for (const name of config.knownFields ?? []) {
2937
- if (!fields.has(name))
2938
- fields.set(name, { kind: "other" });
2939
- }
2940
- const fieldFor = (name) => fields.get(name) ?? (name.includes(".") ? describeSchemaPath(schema, name.split(".")) : undefined);
2941
- const tokens = readCliTokens(argv, fields, fieldFor, config);
2942
- const { options } = tokens;
2943
- const view = resolveCliView(tokens.viewFlags, tokens.ascending);
2944
- if (view)
2945
- options.view = view;
2946
- return {
2947
- toolArgs: buildToolArgs(tokens, fields, fieldFor, config.positionals, config.allowUnknown === true),
2948
- options
2949
- };
2950
- }
2951
- function extractCliGlobalOptions2(argv, schema) {
2952
- if (schema === undefined)
2953
- return { argv: [...argv], globals: {} };
2954
- let result;
2955
- try {
2956
- result = scanCliArgv(argv, { appGlobals: schema });
2957
- } catch (error) {
2958
- if (error instanceof CliArgumentError2) {
2959
- return { argv: [], globals: {}, error };
2960
- }
2961
- throw error;
2962
- }
2963
- const early = answersBeforeArguments(result);
2964
- const error = early ? undefined : result.appGlobalError ?? result.liftedBoundaryError;
2965
- if (error !== undefined) {
2966
- return {
2967
- argv: [],
2968
- globals: result.globals,
2969
- error
2970
- };
2971
- }
2972
- return {
2973
- argv: result.withoutGlobals,
2974
- globals: result.globals,
2975
- ...result.separatedBeforeGlobals.size > 0 && {
2976
- separatedBefore: result.separatedBeforeGlobals
2977
- }
2978
- };
2979
- }
2980
-
2981
- // src/tools/cli/prepare.ts
2982
- function looseCoerceValue(value) {
2983
- if (Array.isArray(value))
2984
- return value.map(looseCoerceValue);
2985
- return typeof value === "string" ? looseCoerce(value) : value;
2986
- }
2987
- function passthroughBase(value) {
2988
- if (isRecord(value))
2989
- return value;
2990
- if (typeof value === "string") {
2991
- try {
2992
- const parsed = safeJsonParse(value);
2993
- if (isRecord(parsed))
2994
- return parsed;
2995
- } catch {}
2996
- }
2997
- return;
2998
- }
2999
- function collectPassthrough(toolArgs, field, knownKeys) {
3000
- const known = new Set(knownKeys);
3001
- const bag = {};
3002
- for (const key of Object.keys(toolArgs)) {
3003
- if (key === field || known.has(key))
3004
- continue;
3005
- bag[key] = looseCoerceValue(toolArgs[key]);
3006
- delete toolArgs[key];
3007
- }
3008
- if (Object.keys(bag).length === 0)
3009
- return;
3010
- const base = passthroughBase(toolArgs[field]);
3011
- toolArgs[field] = base ? { ...base, ...bag } : bag;
3012
- }
3013
- async function prepareInvocation(command, commandTokens, separatedBefore, framework, descriptor, config, readStdin) {
3014
- const passthroughField = cliPassthroughField(config, command);
3015
- let parsed;
3016
- try {
3017
- parsed = parseCliArgs2(commandTokens, descriptor.argumentSchema, {
3018
- allowUnknown: passthroughField !== undefined,
3019
- knownFields: jsonSchemaFields(descriptor.presentationSchema).map((field) => field.name),
3020
- aliases: new Map([...descriptor.aliases].map(([field, alias]) => [alias, field])),
3021
- positionals: descriptor.positionals,
3022
- separatedBefore
3023
- });
3024
- } catch (error) {
3025
- if (!(error instanceof CliArgumentError2))
3026
- throw error;
3027
- return { ok: false, message: error.message };
3028
- }
3029
- const { toolArgs } = parsed;
3030
- const options = cliRunOptions(framework);
3031
- const firstUnset = jsonSchemaFields(descriptor.presentationSchema).find((field) => field.required && !(field.name in toolArgs) && field.schema.type !== "boolean");
3032
- if (firstUnset) {
3033
- const piped = await readStdin();
3034
- if (piped !== null) {
3035
- if (descriptor.positionals === undefined) {
3036
- toolArgs[firstUnset.name] = piped;
3037
- } else {
3038
- const fieldInfo = describeSchemaFields(descriptor.argumentSchema).get(firstUnset.name);
3039
- try {
3040
- toolArgs[firstUnset.name] = coerceField(fieldInfo, [piped], `--${firstUnset.name}`);
3041
- } catch (error) {
3042
- if (!(error instanceof CliArgumentError2))
3043
- throw error;
3044
- return { ok: false, message: error.message };
3045
- }
3046
- }
3047
- }
3048
- }
3049
- if (passthroughField) {
3050
- collectPassthrough(toolArgs, passthroughField, objectShapeKeys(descriptor.argumentSchema));
3051
- }
3052
- return { ok: true, toolArgs, options };
3053
- }
3054
-
3055
- // src/tools/cli/session.ts
3056
- function createCliSession(config, io) {
3057
- const lifecycle = resolveOptionalCliToolAccess("createCliSession", config);
3058
- assertNoLegacyCliPolicyKeys(config);
3059
- assertCliAuthConfig(config);
3060
- assertPositiveSafeInteger("createCli maxDownloadBytes", config.maxDownloadBytes);
3061
- const applicationOptions = config.globalOptions ? jsonSchemaFields(buildToolPresentationSchema({
3062
- inputSchema: config.globalOptions,
3063
- unrepresentable: "any"
3064
- })) : [];
3065
- const applicationGlobalNames = new Set(applicationOptions.map((field) => field.name));
3066
- for (const name of applicationGlobalNames) {
3067
- if (RESERVED_CLI_OPTIONS.has(name)) {
3068
- throw new Error(`[stitchkit] CLI global option "--${name}" is reserved by the framework`);
3069
- }
3070
- }
3071
- const nativeCommands = new Map;
3072
- const nativeHelp = new Map;
3073
- assertStaticCliCommandNames(typeof config.services === "function" ? [] : config.services ?? [], typeof config.runtimeTools === "function" ? [] : config.runtimeTools ?? []);
3074
- for (const definition of config.commands ?? []) {
3075
- if (cliResultPolicy(config, definition.name) !== undefined) {
3076
- throw new Error(`[stitchkit] CLI result policy "${definition.name}" targets a command that is not managed; a native command declares present and exitCode on defineCliCommand`);
3077
- }
3078
- const descriptor = applyCliPresentationPolicy(definition.name, nativeCliDescriptor(definition), config);
3079
- const issue = commandShapeIssue(definition.name, descriptor, nativeCommands.has(definition.name), cliPassthroughField(config, definition.name), applicationGlobalNames);
3080
- if (issue !== undefined)
3081
- throw new Error(issue);
3082
- nativeCommands.set(definition.name, definition);
3083
- nativeHelp.set(definition.name, descriptor);
3084
- }
3085
- if (config.services === undefined && config.runtimeTools === undefined) {
3086
- assertCliPoliciesResolved(nativeHelp, config);
3087
- }
3088
- return {
3089
- config,
3090
- lifecycle,
3091
- io,
3092
- applicationOptions,
3093
- applicationGlobalNames,
3094
- nativeCommands,
3095
- nativeHelp,
3096
- hasManagedFactory: typeof config.services === "function" || typeof config.runtimeTools === "function"
3097
- };
3098
- }
3099
- function resolveCliRoute(session, argv) {
3100
- const { config } = session;
3101
- const { stdout, stderr, exit } = session.io;
3102
- const scan = scanCliInvocation2(argv, {
3103
- appGlobals: config.globalOptions,
3104
- defaultCommand: config.defaultCommand
3105
- });
3106
- if (scan.error !== undefined) {
3107
- stderr(`${scan.error.message}
3108
- `);
3109
- exit(2);
3110
- return;
3111
- }
3112
- if (scan.version) {
3113
- stdout(`${config.name} ${config.version}
3114
- `);
3115
- exit(0);
3116
- return;
3117
- }
3118
- const helpRequested = scan.framework.help;
3119
- const schemaRequested = !helpRequested && scan.framework.schema;
3120
- return {
3121
- globals: scan.globals,
3122
- typedGlobals: scan.globals,
3123
- framework: scan.framework,
3124
- command: scan.command,
3125
- commandTokens: scan.commandTokens,
3126
- separatedBefore: scan.separatedBefore,
3127
- topLevelHelp: scan.topLevelHelp,
3128
- ...scan.helpFilter !== undefined && { helpFilter: scan.helpFilter },
3129
- quiet: scan.framework.quiet,
3130
- helpRequested,
3131
- schemaRequested
3132
- };
3133
- }
3134
- function renderCommandSchema(command, descriptor) {
3135
- return `${JSON.stringify({
3136
- command,
3137
- input: descriptor.presentationSchema,
3138
- ...descriptor.outputSchema !== undefined && {
3139
- [descriptor.stream ? "item" : "output"]: toJsonSchema(descriptor.outputSchema, "output", "any", "draft-07")
3140
- }
3141
- })}
3142
- `;
3143
- }
3144
- function emitOptionsFor(config, json, toolName) {
3145
- return {
3146
- json,
3147
- toolName,
3148
- errorHint: config.errorHint,
3149
- exitCodes: { ...DEFAULT_EXIT_CODES2, ...config.exitCodes }
3150
- };
3151
- }
3152
-
3153
- // src/tools/cli/run-stream.ts
3154
- async function runStreamCommand(session, route, managed, stream, { toolArgs, options }) {
3155
- const { config } = session;
3156
- const { stdout, stderr, exit } = session.io;
3157
- const command = stream.tool.name;
3158
- if (options.wait || options.outputDir !== undefined || options.view !== undefined) {
3159
- stderr(`--wait, --output-dir and aggregate views do not apply to stream command "${command}"
3160
- `);
3161
- return exit(2);
3162
- }
3163
- const abort = new AbortController;
3164
- let cancelled = false;
3165
- const cancel = () => {
3166
- cancelled = true;
3167
- abort.abort(config.signal?.reason);
3168
- };
3169
- if (config.signal?.aborted)
3170
- cancel();
3171
- else
3172
- config.signal?.addEventListener("abort", cancel, { once: true });
3173
- const runTool = createCliToolRunner(config, session.lifecycle, managed.auth, route.typedGlobals);
3174
- let opened;
3175
- try {
3176
- opened = await runTool(stream.tool, toolArgs, { signal: abort.signal });
3177
- } catch (error) {
3178
- opened = toolResultFromError(error);
3179
- }
3180
- const policy = cliResultPolicy(config, command);
3181
- let outcome;
3182
- if (!opened.ok)
3183
- outcome = opened;
3184
- else if (!isAsyncIterable(opened.data)) {
3185
- outcome = toolResultFromError(new Error(`Stream command "${command}" handler did not return an async iterable`));
3186
- } else {
3187
- outcome = await printStreamItems(opened.data, stream, abort, () => cancelled, (item) => session.io.stdoutWhileOpen(streamLine(command, item, policy, options)));
3188
- }
3189
- config.signal?.removeEventListener("abort", cancel);
3190
- if (outcome === "completed" || outcome === "reader-gone")
3191
- return exit(0);
3192
- if (outcome === "cancelled" || cancelled) {
3193
- return exit(cliExitCode2({ ok: false, code: "REQUEST_ABORTED" }, config.exitCodes));
3194
- }
3195
- return exit(emitResult2(outcome, { stdout, stderr }, emitOptionsFor(config, options.json, command)));
3196
- }
3197
- function streamLine(command, item, policy, options) {
3198
- if (policy?.present === undefined)
3199
- return `${stringifyJsonSafe(item)}
3200
- `;
3201
- let line;
3202
- try {
3203
- line = policy.present({ result: item, options });
3204
- if (typeof line !== "string")
3205
- throw new Error("CLI result presenter must return a string");
3206
- } catch (error) {
3207
- throw new AppError2("CLI_PRESENTATION_FAILED", {
3208
- message: "A stream item was produced, but its presentation failed.",
3209
- status: 500,
3210
- details: { command, cause: formatToolError(toolResultFromError(error)) }
3211
- });
3212
- }
3213
- return line;
3214
- }
3215
- async function printStreamItems(source, { descriptor }, abort, wasCancelled, write) {
3216
- const iterator = source[Symbol.asyncIterator]();
3217
- let lifetimeExpired = false;
3218
- const lifetime = descriptor.lifetimeMs === undefined ? undefined : setTimeout(() => {
3219
- lifetimeExpired = true;
3220
- abort.abort(new Error("Stream lifetime expired"));
3221
- }, descriptor.lifetimeMs);
3222
- lifetime?.unref?.();
3223
- try {
3224
- for await (const { item } of readContractStreamItems(iterator, descriptor, abort.signal)) {
3225
- if (!write(item))
3226
- return "reader-gone";
3227
- }
3228
- return "completed";
3229
- } catch (error) {
3230
- if (wasCancelled())
3231
- return "cancelled";
3232
- if (lifetimeExpired) {
3233
- return toolResultFromError(contractStreamLifetimeExceeded());
3234
- }
3235
- return projectCliUnixFailure(toolResultFromError(error));
3236
- } finally {
3237
- if (lifetime !== undefined)
3238
- clearTimeout(lifetime);
3239
- abort.abort();
3240
- Promise.resolve().then(() => iterator.return?.(undefined)).catch(() => {
3241
- return;
3242
- });
3243
- }
3244
- }
3245
-
3246
- // src/tools/cli/wait.ts
3247
- var DEFAULT_TIMEOUT = 600;
3248
- function waitFailure(tool, result) {
3249
- return {
3250
- ok: false,
3251
- code: "WAIT_FAILED",
3252
- details: {
3253
- message: `"${tool}" reached a terminal failed state`,
3254
- result
3255
- }
3256
- };
3257
- }
3258
- async function pollUntilDone2(params) {
3259
- const { initial, wait, call } = params;
3260
- if (!initial.ok)
3261
- return initial;
3262
- if (wait.failed?.(initial.data))
3263
- return waitFailure(wait.tool, initial.data);
3264
- if (wait.done(initial.data))
3265
- return initial;
3266
- const pollArgs = wait.poll(initial.data);
3267
- if (!pollArgs)
3268
- return initial;
3269
- const timeoutSec = params.timeoutSec ?? wait.timeout ?? DEFAULT_TIMEOUT;
3270
- let failedState;
3271
- const { state, timedOut } = await pollUntil({
3272
- poll: () => call(wait.tool, pollArgs),
3273
- done: (result) => {
3274
- if (!result.ok)
3275
- return true;
3276
- if (wait.failed?.(result.data)) {
3277
- failedState = result;
3278
- return true;
3279
- }
3280
- return wait.done(result.data);
3281
- },
3282
- backoff: wait.backoff,
3283
- timeoutSec,
3284
- sleepFn: params.sleepFn,
3285
- onTick: params.onTick,
3286
- signal: params.signal
3287
- });
3288
- if (timedOut) {
3289
- return {
3290
- ok: false,
3291
- code: "TIMEOUT",
3292
- details: { message: `Timed out after ${timeoutSec}s waiting for "${wait.tool}"` }
3293
- };
3294
- }
3295
- if (state === failedState && state.ok)
3296
- return waitFailure(wait.tool, state.data);
3297
- return state;
3298
- }
3299
-
3300
- // src/tools/cli/run-managed.ts
3301
- async function runManagedInvocation(session, route) {
3302
- const { config } = session;
3303
- const { stdout, stderr, exit } = session.io;
3304
- const { command, topLevelHelp, helpRequested, schemaRequested } = route;
3305
- const managed = await buildManagedSurface(session, route.typedGlobals, !topLevelHelp && !helpRequested && !schemaRequested && !isInspectOnlyLifecycle(session.lifecycle));
3306
- if (topLevelHelp || command === undefined)
3307
- return respondTopLevelHelp(session, route, managed);
3308
- if (!managed.resolved) {
3309
- return exit(emitResult2(managed.failure, { stdout, stderr }, emitOptionsFor(config, route.framework.json, command)));
3310
- }
3311
- return runManagedCommand(session, route, command, managed);
3312
- }
3313
- function respondTopLevelHelp(session, route, managed) {
3314
- const { config, applicationOptions } = session;
3315
- const { stdout, stderr, exit } = session.io;
3316
- const filter = route.helpFilter;
3317
- if (filter !== undefined && filterCommands(managed.help, filter).size === 0) {
3318
- stderr(`no command matches "${filter}" (${[...managed.help.values()].filter((entry) => entry.unavailableReason === undefined).length} available)
3319
- ` + (managed.resolved ? "" : `Managed commands are unavailable: ${managed.reason}
3320
- `));
3321
- const codes = { ...DEFAULT_EXIT_CODES2, ...config.exitCodes };
3322
- exit(codes.NOT_FOUND ?? 4);
3323
- return;
3324
- }
3325
- stdout(renderTopHelp({
3326
- name: config.name,
3327
- version: config.version,
3328
- commands: managed.help,
3329
- defaultCommand: config.defaultCommand,
3330
- applicationOptions,
3331
- ...filter !== undefined && { filter },
3332
- ...managed.resolved ? {} : { unavailable: managed.reason }
3333
- }));
3334
- exit(0);
3335
- }
3336
- async function runManagedCommand(session, route, command, managed) {
3337
- const { config, applicationOptions } = session;
3338
- const { stdout, stderr, exit, readStdin } = session.io;
3339
- const descriptor = managed.help.get(command);
3340
- if (!descriptor) {
3341
- stderr(`Unknown command "${command}". Run "${config.name} --help" for the command list.
3342
- `);
3343
- return exit(cliExitCode2(unknownCliCommand(command), config.exitCodes));
3344
- }
3345
- if (route.helpRequested) {
3346
- stdout(renderCommandHelp(config.name, command, descriptor, applicationOptions));
3347
- return exit(0);
3348
- }
3349
- if (route.schemaRequested) {
3350
- stdout(renderCommandSchema(command, descriptor));
3351
- return exit(0);
3352
- }
3353
- const inspectErr = inspectOnlyError(session.lifecycle);
3354
- if (inspectErr) {
3355
- return exit(emitResult2(toolResultFromError(inspectErr), { stdout, stderr }, emitOptionsFor(config, route.framework.json, command)));
3356
- }
3357
- if (descriptor.unavailableReason !== undefined) {
3358
- return exit(emitResult2(unavailableCommand(descriptor.unavailableReason), { stdout, stderr }, emitOptionsFor(config, route.framework.json, command)));
3359
- }
3360
- const stream = managed.streams.get(command);
3361
- const tool = managed.tools.get(command);
3362
- if (!tool && !stream)
3363
- throw new Error("[stitchkit] managed CLI executable invariant failed");
3364
- const prepared = await prepareInvocation(command, route.commandTokens, route.separatedBefore, route.framework, descriptor, config, readStdin);
3365
- if (!prepared.ok) {
3366
- stderr(`${prepared.message}
3367
- `);
3368
- return exit(2);
3369
- }
3370
- const { toolArgs, options } = prepared;
3371
- if (options.wait && !cliWaitConfig(config, command)) {
3372
- stderr(`--wait is not configured for command "${command}"
3373
- `);
3374
- return exit(2);
3375
- }
3376
- if (options.waitTimeout !== undefined && !options.wait) {
3377
- stderr(`--wait-timeout requires --wait
3378
- `);
3379
- return exit(2);
3380
- }
3381
- if (options.dryRun) {
3382
- stdout(`${JSON.stringify({ command, args: toolArgs }, null, 2)}
3383
- `);
3384
- return exit(0);
3385
- }
3386
- if (stream)
3387
- return runStreamCommand(session, route, managed, stream, { toolArgs, options });
3388
- if (!tool)
3389
- throw new Error("[stitchkit] managed CLI executable invariant failed");
3390
- if (options.view !== undefined && !options.wait) {
3391
- try {
3392
- assertViewColumns(options.view, descriptor.outputSchema);
3393
- } catch (error) {
3394
- if (!(error instanceof CliArgumentError2))
3395
- throw error;
3396
- stderr(`${error.message}
3397
- `);
3398
- return exit(2);
3399
- }
3400
- }
3401
- const result = await executeManagedTool(session, route, command, managed, tool, {
3402
- toolArgs,
3403
- options
3404
- });
3405
- return emitManagedResult(session, command, result, options, isRepeatableRead(tool.method));
3406
- }
3407
- async function executeManagedTool(session, route, command, managed, tool, { toolArgs, options }) {
3408
- const { config } = session;
3409
- const { stderr } = session.io;
3410
- const runTool = createCliToolRunner(config, session.lifecycle, managed.auth, route.typedGlobals);
3411
- let result;
3412
- try {
3413
- result = await runTool(tool, toolArgs);
3414
- } catch (err) {
3415
- result = toolResultFromError(err);
3416
- }
3417
- const waitConfig = cliWaitConfig(config, command);
3418
- if (options.wait && waitConfig) {
3419
- result = await pollUntilDone2({
3420
- initial: result,
3421
- wait: waitConfig,
3422
- call: async (toolName, args) => {
3423
- const unavailable = managed.help.get(toolName)?.unavailableReason;
3424
- if (unavailable !== undefined)
3425
- return unavailableCommand(unavailable);
3426
- const pollTool = managed.tools.get(toolName);
3427
- if (!pollTool) {
3428
- return {
3429
- ok: false,
3430
- code: "UNKNOWN_OPERATION",
3431
- details: {
3432
- message: `--wait: no command "${toolName}" to poll`,
3433
- operation: toolName
3434
- }
3435
- };
3436
- }
3437
- return runTool(pollTool, args);
3438
- },
3439
- timeoutSec: options.waitTimeout,
3440
- onTick: options.quiet ? undefined : (attempt) => stderr(`waiting… (poll ${attempt})
3441
- `),
3442
- signal: config.signal
3443
- });
3444
- }
3445
- return result;
3446
- }
3447
- async function emitManagedResult(session, command, result, options, repeatable) {
3448
- const { config } = session;
3449
- const { stdout, stderr, exit } = session.io;
3450
- const emit = { ...emitOptionsFor(config, options.json, command), repeatable };
3451
- if (!result.ok)
3452
- return exit(emitResult2(result, { stdout, stderr }, emit));
3453
- let shown = result;
3454
- let mediaExitCode = 0;
3455
- if (options.outputDir !== undefined) {
3456
- const saved = await saveResultMedia(result.data, {
3457
- dir: options.outputDir,
3458
- download: config.download,
3459
- allowPrivateHosts: config.allowPrivateDownloadHosts ?? false,
3460
- maxBytes: config.maxDownloadBytes ?? DEFAULT_DOWNLOAD_MAX_BYTES,
3461
- timeoutMs: config.downloadTimeoutMs,
3462
- quiet: options.quiet,
3463
- stderr
3464
- });
3465
- shown = { ...result, data: saved.data };
3466
- if (!saved.ok)
3467
- mediaExitCode = 1;
3468
- }
3469
- return exit(emitCliViewOrResult(cliResultPolicy(config, command), result, options, { stdout, stderr }, emit, shown, mediaExitCode));
3470
- }
3471
-
3472
- // src/tools/cli/run-native.ts
3473
- async function runNativeCommand(session, route, command, native) {
3474
- const { config, applicationOptions, nativeHelp } = session;
3475
- const { stdout, stderr, exit, readStdin } = session.io;
3476
- const { commandTokens, separatedBefore, framework, helpRequested, globals } = route;
3477
- const descriptor = nativeHelp.get(command);
3478
- if (!descriptor)
3479
- throw new Error("[stitchkit] native CLI descriptor invariant failed");
3480
- if (helpRequested) {
3481
- stdout(renderCommandHelp(config.name, command, descriptor, applicationOptions));
3482
- return exit(0);
3483
- }
3484
- if (route.schemaRequested) {
3485
- stdout(renderCommandSchema(command, descriptor));
3486
- return exit(0);
3487
- }
3488
- const prepared = await prepareInvocation(command, commandTokens, separatedBefore, framework, descriptor, config, readStdin);
3489
- if (!prepared.ok) {
3490
- stderr(`${prepared.message}
3491
- `);
3492
- return exit(2);
3493
- }
3494
- const { toolArgs, options } = prepared;
3495
- if (options.wait) {
3496
- stderr(`--wait is not configured for native command "${command}"
3497
- `);
3498
- return exit(2);
3499
- }
3500
- if (options.waitTimeout !== undefined) {
3501
- stderr(`--wait-timeout requires --wait
3502
- `);
3503
- return exit(2);
3504
- }
3505
- if (options.outputDir !== undefined) {
3506
- stderr(`--output-dir is not configured for native commands
3507
- `);
3508
- return exit(2);
3509
- }
3510
- if (options.dryRun) {
3511
- stdout(`${JSON.stringify({ command, args: toolArgs }, null, 2)}
3512
- `);
3513
- return exit(0);
3514
- }
3515
- return exit(await executeNativeCommand(native, toolArgs, config.coerceJsonArgs ?? true, globals, {
3516
- mode: "terminal",
3517
- options,
3518
- writers: { stdout, stderr },
3519
- emit: { ...emitOptionsFor(config, options.json, command), repeatable: false }
3520
- }));
3521
- }
3522
-
3523
- // src/tools/cli/create-cli.ts
3524
- async function createCli2(config) {
3525
- resolveOptionalCliToolAccess("createCli", config);
3526
- assertNoLegacyCliPolicyKeys(config);
3527
- const io = createCliIo(config);
3528
- const argv = config.argv ?? process.argv.slice(2);
3529
- const session = createCliSession(config, io);
3530
- const route = resolveCliRoute(session, argv);
3531
- if (route === undefined)
3532
- return;
3533
- return withCliNotices(route.quiet, io.stderr, () => {
3534
- const { command } = route;
3535
- const native = command === undefined ? undefined : session.nativeCommands.get(command);
3536
- if (native && command !== undefined) {
3537
- return runNativeCommand(session, route, command, native);
3538
- }
3539
- return runManagedInvocation(session, route);
3540
- });
3541
- }
3542
-
3543
- export { CliArgumentError2, DEFAULT_EXIT_CODES2, cliExitCode2, emitResult2, renderCliView2, defineCliResult2, defineCliCommand2, cliInvocationResult2, createCliInvoker2, scanCliArgv, answersBeforeArguments, scanCliInvocation2, writeCliNotice, parseCliArgs2, extractCliGlobalOptions2, pollUntilDone2, createCli2 };