stitchkit 0.93.0 → 0.94.1
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.
- package/CHANGELOG.md +198 -0
- package/README.md +5 -2
- package/dist/agent-runtime/children-control.d.ts +6 -0
- package/dist/agent-runtime/children-control.d.ts.map +1 -0
- package/dist/agent-runtime/children-spawn.d.ts +6 -0
- package/dist/agent-runtime/children-spawn.d.ts.map +1 -0
- package/dist/agent-runtime/children-state.d.ts +46 -0
- package/dist/agent-runtime/children-state.d.ts.map +1 -0
- package/dist/agent-runtime/children-usage.d.ts +8 -0
- package/dist/agent-runtime/children-usage.d.ts.map +1 -0
- package/dist/agent-runtime/children.d.ts +11 -14
- package/dist/agent-runtime/children.d.ts.map +1 -1
- package/dist/agent-runtime/coding-shell-process.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-contract.d.ts +2 -1
- package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-listing.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-search-patch.d.ts.map +1 -1
- package/dist/agent-runtime/contained-darwin.d.ts +38 -0
- package/dist/agent-runtime/contained-darwin.d.ts.map +1 -0
- package/dist/agent-runtime/contained-files.d.ts +11 -26
- package/dist/agent-runtime/contained-files.d.ts.map +1 -1
- package/dist/agent-runtime/contained-scan.d.ts +21 -0
- package/dist/agent-runtime/contained-scan.d.ts.map +1 -0
- package/dist/agent-runtime/contained-write.d.ts +9 -0
- package/dist/agent-runtime/contained-write.d.ts.map +1 -0
- package/dist/agent-runtime/deferred-tool-types.d.ts +4 -3
- package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -1
- package/dist/agent-runtime/events.d.ts +1 -1
- package/dist/agent-runtime/events.d.ts.map +1 -1
- package/dist/agent-runtime/harness-control.d.ts +0 -1
- package/dist/agent-runtime/harness-control.d.ts.map +1 -1
- package/dist/agent-runtime/harness.d.ts +0 -5
- package/dist/agent-runtime/harness.d.ts.map +1 -1
- package/dist/agent-runtime/managed-tools.d.ts +3 -2
- package/dist/agent-runtime/managed-tools.d.ts.map +1 -1
- package/dist/agent-runtime/observability.d.ts +1 -1
- package/dist/agent-runtime/observability.d.ts.map +1 -1
- package/dist/agent-runtime/openrouter.d.ts +29 -0
- package/dist/agent-runtime/openrouter.d.ts.map +1 -0
- package/dist/agent-runtime/projections.d.ts +1 -1
- package/dist/agent-runtime/projections.d.ts.map +1 -1
- package/dist/agent-runtime/run-acquisition.d.ts +17 -0
- package/dist/agent-runtime/run-acquisition.d.ts.map +1 -0
- package/dist/agent-runtime/run-execution-state.d.ts +133 -0
- package/dist/agent-runtime/run-execution-state.d.ts.map +1 -0
- package/dist/agent-runtime/run-execution.d.ts +17 -33
- package/dist/agent-runtime/run-execution.d.ts.map +1 -1
- package/dist/agent-runtime/run-failure.d.ts +18 -0
- package/dist/agent-runtime/run-failure.d.ts.map +1 -0
- package/dist/agent-runtime/run-model-attempts.d.ts +6 -0
- package/dist/agent-runtime/run-model-attempts.d.ts.map +1 -0
- package/dist/agent-runtime/run-prompt-history.d.ts +58 -0
- package/dist/agent-runtime/run-prompt-history.d.ts.map +1 -0
- package/dist/agent-runtime/run-provider-ledger.d.ts +26 -0
- package/dist/agent-runtime/run-provider-ledger.d.ts.map +1 -0
- package/dist/agent-runtime/run-stream-parts.d.ts +17 -0
- package/dist/agent-runtime/run-stream-parts.d.ts.map +1 -0
- package/dist/agent-runtime/run-terminal.d.ts +11 -0
- package/dist/agent-runtime/run-terminal.d.ts.map +1 -0
- package/dist/agent-runtime/run-turn-preparation.d.ts +22 -0
- package/dist/agent-runtime/run-turn-preparation.d.ts.map +1 -0
- package/dist/agent-runtime/runtime-admission-gate.d.ts +29 -0
- package/dist/agent-runtime/runtime-admission-gate.d.ts.map +1 -0
- package/dist/agent-runtime/runtime-control.d.ts +9 -0
- package/dist/agent-runtime/runtime-control.d.ts.map +1 -0
- package/dist/agent-runtime/runtime-recovery.d.ts +10 -0
- package/dist/agent-runtime/runtime-recovery.d.ts.map +1 -0
- package/dist/agent-runtime/runtime-state.d.ts +36 -0
- package/dist/agent-runtime/runtime-state.d.ts.map +1 -0
- package/dist/agent-runtime/runtime-submit.d.ts +5 -0
- package/dist/agent-runtime/runtime-submit.d.ts.map +1 -0
- package/dist/agent-runtime/runtime.d.ts +10 -5
- package/dist/agent-runtime/runtime.d.ts.map +1 -1
- package/dist/agent-runtime/schedule-records.d.ts +34 -0
- package/dist/agent-runtime/schedule-records.d.ts.map +1 -0
- package/dist/agent-runtime/schedules.d.ts +34 -0
- package/dist/agent-runtime/schedules.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite-bun.d.ts +12 -0
- package/dist/agent-runtime/sqlite-bun.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-events.d.ts +5 -0
- package/dist/agent-runtime/sqlite-events.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-history.d.ts +7 -0
- package/dist/agent-runtime/sqlite-history.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-ledger.d.ts +7 -0
- package/dist/agent-runtime/sqlite-ledger.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-node.d.ts +12 -0
- package/dist/agent-runtime/sqlite-node.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-reads.d.ts +14 -0
- package/dist/agent-runtime/sqlite-reads.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-rows.d.ts +178 -0
- package/dist/agent-runtime/sqlite-rows.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-schema.d.ts +7 -0
- package/dist/agent-runtime/sqlite-schema.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-transactions.d.ts +25 -0
- package/dist/agent-runtime/sqlite-transactions.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite.d.ts +10 -6
- package/dist/agent-runtime/sqlite.d.ts.map +1 -1
- package/dist/agent-runtime/store-archive.d.ts +16 -0
- package/dist/agent-runtime/store-archive.d.ts.map +1 -0
- package/dist/agent-runtime/store-conformance-lifecycle.d.ts +434 -0
- package/dist/agent-runtime/store-conformance-lifecycle.d.ts.map +1 -0
- package/dist/agent-runtime/store-conformance-ordering.d.ts +18 -0
- package/dist/agent-runtime/store-conformance-ordering.d.ts.map +1 -0
- package/dist/agent-runtime/store-conformance-support.d.ts +130 -0
- package/dist/agent-runtime/store-conformance-support.d.ts.map +1 -0
- package/dist/agent-runtime/store-conformance-terminal.d.ts +12 -0
- package/dist/agent-runtime/store-conformance-terminal.d.ts.map +1 -0
- package/dist/agent-runtime/store-conformance.d.ts +40 -0
- package/dist/agent-runtime/store-conformance.d.ts.map +1 -0
- package/dist/agent-runtime/store-create.d.ts +11 -0
- package/dist/agent-runtime/store-create.d.ts.map +1 -0
- package/dist/agent-runtime/store-driver-contract.d.ts +814 -0
- package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -0
- package/dist/agent-runtime/store-events.d.ts +7 -89
- package/dist/agent-runtime/store-events.d.ts.map +1 -1
- package/dist/agent-runtime/store-memory.d.ts +4 -0
- package/dist/agent-runtime/store-memory.d.ts.map +1 -0
- package/dist/agent-runtime/store-mutate.d.ts +13 -0
- package/dist/agent-runtime/store-mutate.d.ts.map +1 -0
- package/dist/agent-runtime/store-purge.d.ts +1 -1
- package/dist/agent-runtime/store-purge.d.ts.map +1 -1
- package/dist/agent-runtime/store-reads.d.ts +29 -0
- package/dist/agent-runtime/store-reads.d.ts.map +1 -0
- package/dist/agent-runtime/store-reduce-history.d.ts +10 -0
- package/dist/agent-runtime/store-reduce-history.d.ts.map +1 -0
- package/dist/agent-runtime/store-reduce-run.d.ts +14 -0
- package/dist/agent-runtime/store-reduce-run.d.ts.map +1 -0
- package/dist/agent-runtime/store-reduce-shared.d.ts +76 -0
- package/dist/agent-runtime/store-reduce-shared.d.ts.map +1 -0
- package/dist/agent-runtime/store-reduce-terminal.d.ts +6 -0
- package/dist/agent-runtime/store-reduce-terminal.d.ts.map +1 -0
- package/dist/agent-runtime/store-reducer.d.ts +24 -0
- package/dist/agent-runtime/store-reducer.d.ts.map +1 -0
- package/dist/agent-runtime/store-snapshot.d.ts +19 -0
- package/dist/agent-runtime/store-snapshot.d.ts.map +1 -0
- package/dist/agent-runtime/store.d.ts +1 -1
- package/dist/agent-runtime/store.d.ts.map +1 -1
- package/dist/application/admission-rate.d.ts +21 -0
- package/dist/application/admission-rate.d.ts.map +1 -0
- package/dist/application/admission-run.d.ts +8 -0
- package/dist/application/admission-run.d.ts.map +1 -0
- package/dist/application/admission.d.ts +1 -1
- package/dist/application/admission.d.ts.map +1 -1
- package/dist/application/diagnostic-journal-lock.d.ts +9 -34
- package/dist/application/diagnostic-journal-lock.d.ts.map +1 -1
- package/dist/application/diagnostic-journal-manager.d.ts.map +1 -1
- package/dist/application/diagnostic-journal-storage.d.ts.map +1 -1
- package/dist/application/events.d.ts +1 -1
- package/dist/application/events.d.ts.map +1 -1
- package/dist/application/file-state-store.d.ts +23 -0
- package/dist/application/file-state-store.d.ts.map +1 -0
- package/dist/application/health.d.ts +1 -1
- package/dist/application/health.d.ts.map +1 -1
- package/dist/application/kernel-admission.d.ts +8 -0
- package/dist/application/kernel-admission.d.ts.map +1 -0
- package/dist/application/kernel-contract.d.ts +142 -0
- package/dist/application/kernel-contract.d.ts.map +1 -0
- package/dist/application/kernel-resource-context.d.ts +24 -0
- package/dist/application/kernel-resource-context.d.ts.map +1 -0
- package/dist/application/kernel-restart.d.ts +5 -0
- package/dist/application/kernel-restart.d.ts.map +1 -0
- package/dist/application/kernel-rollback.d.ts +4 -0
- package/dist/application/kernel-rollback.d.ts.map +1 -0
- package/dist/application/kernel-shutdown.d.ts +6 -0
- package/dist/application/kernel-shutdown.d.ts.map +1 -0
- package/dist/application/kernel-start.d.ts +20 -0
- package/dist/application/kernel-start.d.ts.map +1 -0
- package/dist/application/kernel-state.d.ts +116 -0
- package/dist/application/kernel-state.d.ts.map +1 -0
- package/dist/application/kernel.d.ts +9 -140
- package/dist/application/kernel.d.ts.map +1 -1
- package/dist/application/latest-sink.d.ts +1 -1
- package/dist/application/latest-sink.d.ts.map +1 -1
- package/dist/application/notification-outbox.d.ts.map +1 -1
- package/dist/application/opentelemetry.d.ts +1 -1
- package/dist/application/opentelemetry.d.ts.map +1 -1
- package/dist/application/schedule.d.ts +0 -1
- package/dist/application/schedule.d.ts.map +1 -1
- package/dist/application/watch-hub-core.d.ts +122 -0
- package/dist/application/watch-hub-core.d.ts.map +1 -0
- package/dist/application/watch-hub.d.ts +3 -3
- package/dist/application/watch-hub.d.ts.map +1 -1
- package/dist/browser/client-executors.d.ts +14 -0
- package/dist/browser/client-executors.d.ts.map +1 -0
- package/dist/browser/client-multipart.d.ts +1 -1
- package/dist/browser/client-multipart.d.ts.map +1 -1
- package/dist/browser/client-url.d.ts +1 -1
- package/dist/browser/client-url.d.ts.map +1 -1
- package/dist/browser/client.d.ts +3 -2
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/contract-stream.d.ts +1 -1
- package/dist/browser/contract-stream.d.ts.map +1 -1
- package/dist/browser/http-fetch.d.ts +22 -0
- package/dist/browser/http-fetch.d.ts.map +1 -0
- package/dist/browser/http.d.ts +2 -4
- package/dist/browser/http.d.ts.map +1 -1
- package/dist/browser/live-state-core.d.ts +63 -0
- package/dist/browser/live-state-core.d.ts.map +1 -0
- package/dist/browser/live-state.d.ts.map +1 -1
- package/dist/browser/realtime-client.d.ts +26 -0
- package/dist/browser/realtime-client.d.ts.map +1 -0
- package/dist/browser/resumable.d.ts +1 -28
- package/dist/browser/resumable.d.ts.map +1 -1
- package/dist/browser/retained.d.ts.map +1 -0
- package/dist/browser/socket-io-connection.d.ts +82 -0
- package/dist/browser/socket-io-connection.d.ts.map +1 -0
- package/dist/browser/socket-io-peer.d.ts +20 -0
- package/dist/browser/socket-io-peer.d.ts.map +1 -0
- package/dist/browser/socket-io-trace.d.ts +31 -0
- package/dist/browser/socket-io-trace.d.ts.map +1 -0
- package/dist/browser/socket-io.d.ts +24 -18
- package/dist/browser/socket-io.d.ts.map +1 -1
- package/dist/browser/stream.d.ts +14 -2
- package/dist/browser/stream.d.ts.map +1 -1
- package/dist/contract/client-types.d.ts +134 -0
- package/dist/contract/client-types.d.ts.map +1 -0
- package/dist/contract/define-validation.d.ts +30 -0
- package/dist/contract/define-validation.d.ts.map +1 -0
- package/dist/contract/define.d.ts +47 -394
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/normalize.d.ts +56 -0
- package/dist/contract/normalize.d.ts.map +1 -0
- package/dist/contract/runtime-context.d.ts +131 -0
- package/dist/contract/runtime-context.d.ts.map +1 -0
- package/dist/contract/tool-options.d.ts +105 -0
- package/dist/contract/tool-options.d.ts.map +1 -0
- package/dist/contract/tool-view.d.ts +148 -0
- package/dist/contract/tool-view.d.ts.map +1 -0
- package/dist/declaration/declaration.d.ts.map +1 -0
- package/dist/durability/contract.d.ts +259 -0
- package/dist/durability/contract.d.ts.map +1 -0
- package/dist/durability/effect.d.ts +24 -0
- package/dist/durability/effect.d.ts.map +1 -0
- package/dist/durability/engine.d.ts +14 -0
- package/dist/durability/engine.d.ts.map +1 -0
- package/dist/durability/events.d.ts +103 -0
- package/dist/durability/events.d.ts.map +1 -0
- package/dist/durability/json.d.ts +3 -0
- package/dist/durability/json.d.ts.map +1 -0
- package/dist/durability/ledger.d.ts +27 -0
- package/dist/durability/ledger.d.ts.map +1 -0
- package/dist/durability/parks.d.ts +22 -0
- package/dist/durability/parks.d.ts.map +1 -0
- package/dist/durability/scheduler.d.ts +30 -0
- package/dist/durability/scheduler.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/browser.d.ts +5 -0
- package/dist/entrypoints/agent-runtime/browser.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/browser.js +124 -0
- package/dist/entrypoints/agent-runtime/coding-tools.d.ts +2 -0
- package/dist/entrypoints/agent-runtime/coding-tools.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/coding-tools.js +22 -0
- package/dist/entrypoints/agent-runtime/harness.d.ts +2 -0
- package/dist/entrypoints/agent-runtime/harness.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/harness.js +739 -0
- package/dist/entrypoints/agent-runtime/openrouter.d.ts +2 -0
- package/dist/entrypoints/agent-runtime/openrouter.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/openrouter.js +270 -0
- package/dist/entrypoints/agent-runtime/sandbox.d.ts +5 -0
- package/dist/entrypoints/agent-runtime/sandbox.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/sandbox.js +797 -0
- package/dist/entrypoints/agent-runtime/sqlite/bun.d.ts +2 -0
- package/dist/entrypoints/agent-runtime/sqlite/bun.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +44 -0
- package/dist/entrypoints/agent-runtime/sqlite/node.d.ts +2 -0
- package/dist/entrypoints/agent-runtime/sqlite/node.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/sqlite/node.js +46 -0
- package/dist/entrypoints/agent-runtime/testing.d.ts +4 -0
- package/dist/entrypoints/agent-runtime/testing.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/testing.js +1116 -0
- package/dist/entrypoints/agent-runtime.d.ts +42 -0
- package/dist/entrypoints/agent-runtime.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime.js +2670 -0
- package/dist/entrypoints/application/diagnostic-journal.d.ts +21 -0
- package/dist/entrypoints/application/diagnostic-journal.d.ts.map +1 -0
- package/dist/entrypoints/application/diagnostic-journal.js +492 -0
- package/dist/entrypoints/application/grammy.d.ts +2 -0
- package/dist/entrypoints/application/grammy.d.ts.map +1 -0
- package/dist/entrypoints/application/grammy.js +169 -0
- package/dist/entrypoints/application/opentelemetry.d.ts +2 -0
- package/dist/entrypoints/application/opentelemetry.d.ts.map +1 -0
- package/dist/entrypoints/application/opentelemetry.js +250 -0
- package/dist/entrypoints/application/schemas.d.ts +15 -0
- package/dist/entrypoints/application/schemas.d.ts.map +1 -0
- package/dist/entrypoints/application/schemas.js +27 -0
- package/dist/entrypoints/application.d.ts +23 -0
- package/dist/entrypoints/application.d.ts.map +1 -0
- package/dist/entrypoints/application.js +2016 -0
- package/dist/entrypoints/bin/upgrade-cli.d.ts.map +1 -0
- package/dist/entrypoints/bin/upgrade-cli.js +177 -0
- package/dist/entrypoints/cli.d.ts +44 -0
- package/dist/entrypoints/cli.d.ts.map +1 -0
- package/dist/entrypoints/cli.js +773 -0
- package/dist/entrypoints/contract.d.ts +12 -0
- package/dist/entrypoints/contract.d.ts.map +1 -0
- package/dist/entrypoints/contract.js +64 -0
- package/dist/entrypoints/declaration.d.ts +2 -0
- package/dist/entrypoints/declaration.d.ts.map +1 -0
- package/dist/entrypoints/declaration.js +183 -0
- package/dist/entrypoints/files.d.ts +5 -0
- package/dist/entrypoints/files.d.ts.map +1 -0
- package/dist/entrypoints/files.js +111 -0
- package/dist/entrypoints/geo.d.ts +3 -0
- package/dist/entrypoints/geo.d.ts.map +1 -0
- package/dist/entrypoints/geo.js +245 -0
- package/dist/entrypoints/google.d.ts +2 -0
- package/dist/entrypoints/google.d.ts.map +1 -0
- package/dist/entrypoints/google.js +175 -0
- package/dist/entrypoints/index.d.ts +17 -0
- package/dist/entrypoints/index.d.ts.map +1 -0
- package/dist/entrypoints/index.js +764 -0
- package/dist/entrypoints/live.d.ts +19 -0
- package/dist/entrypoints/live.d.ts.map +1 -0
- package/dist/entrypoints/live.js +302 -0
- package/dist/entrypoints/node.d.ts +19 -0
- package/dist/entrypoints/node.d.ts.map +1 -0
- package/dist/entrypoints/node.js +308 -0
- package/dist/entrypoints/oauth.d.ts +2 -0
- package/dist/entrypoints/oauth.d.ts.map +1 -0
- package/dist/entrypoints/oauth.js +170 -0
- package/dist/entrypoints/observability.d.ts +19 -0
- package/dist/entrypoints/observability.d.ts.map +1 -0
- package/dist/entrypoints/observability.js +567 -0
- package/dist/entrypoints/primitives.d.ts +3 -0
- package/dist/entrypoints/primitives.d.ts.map +1 -0
- package/dist/entrypoints/primitives.js +749 -0
- package/dist/entrypoints/react.d.ts +5 -0
- package/dist/entrypoints/react.d.ts.map +1 -0
- package/dist/entrypoints/react.js +403 -0
- package/dist/entrypoints/release.d.ts +15 -0
- package/dist/entrypoints/release.d.ts.map +1 -0
- package/dist/entrypoints/release.js +196 -0
- package/dist/entrypoints/remote.d.ts +9 -0
- package/dist/entrypoints/remote.d.ts.map +1 -0
- package/dist/entrypoints/remote.js +66 -0
- package/dist/entrypoints/server.d.ts +39 -0
- package/dist/entrypoints/server.d.ts.map +1 -0
- package/dist/entrypoints/server.js +2009 -0
- package/dist/entrypoints/telegram.d.ts +3 -0
- package/dist/entrypoints/telegram.d.ts.map +1 -0
- package/dist/entrypoints/telegram.js +224 -0
- package/dist/entrypoints/testing.d.ts +10 -0
- package/dist/entrypoints/testing.d.ts.map +1 -0
- package/dist/entrypoints/testing.js +1377 -0
- package/dist/entrypoints/tools/connections.d.ts +19 -0
- package/dist/entrypoints/tools/connections.d.ts.map +1 -0
- package/dist/entrypoints/tools/connections.js +1110 -0
- package/dist/entrypoints/tools/contract.d.ts +29 -0
- package/dist/entrypoints/tools/contract.d.ts.map +1 -0
- package/dist/entrypoints/tools/contract.js +24 -0
- package/dist/entrypoints/tools/invoker.d.ts +9 -0
- package/dist/entrypoints/tools/invoker.d.ts.map +1 -0
- package/dist/entrypoints/tools/invoker.js +20 -0
- package/dist/entrypoints/tools.d.ts +54 -0
- package/dist/entrypoints/tools.d.ts.map +1 -0
- package/dist/entrypoints/tools.js +3009 -0
- package/dist/entrypoints/tracking/server.d.ts +15 -0
- package/dist/entrypoints/tracking/server.d.ts.map +1 -0
- package/dist/entrypoints/tracking.d.ts +24 -0
- package/dist/entrypoints/tracking.d.ts.map +1 -0
- package/dist/entrypoints/tracking.js +1140 -0
- package/dist/files/boundary.d.ts.map +1 -1
- package/dist/files/file-io.d.ts +14 -0
- package/dist/files/file-io.d.ts.map +1 -0
- package/dist/google/google.d.ts.map +1 -0
- package/dist/index-0b1ess5e.js +38 -0
- package/dist/index-1j8pm5t0.js +412 -0
- package/dist/index-1zbbzgfh.js +89 -0
- package/dist/index-2bxbyab0.js +47 -0
- package/dist/index-2gxzjvyr.js +266 -0
- package/dist/index-35mh5bhj.js +177 -0
- package/dist/index-48ffdxgk.js +6 -0
- package/dist/index-4gcnakhx.js +82 -0
- package/dist/index-55hkhm67.js +343 -0
- package/dist/index-79z7m7dt.js +675 -0
- package/dist/index-7f68ghdn.js +3618 -0
- package/dist/index-7p1f0vp2.js +154 -0
- package/dist/index-83bdg97s.js +16 -0
- package/dist/index-863ea9jb.js +154 -0
- package/dist/index-8p52kd5p.js +242 -0
- package/dist/index-d9pk3td4.js +326 -0
- package/dist/index-dce5wxcq.js +63 -0
- package/dist/index-e01r054k.js +105 -0
- package/dist/index-ensd0r74.js +595 -0
- package/dist/index-eqqvgdb3.js +46 -0
- package/dist/index-gxrt5h6v.js +341 -0
- package/dist/index-h6eeys1v.js +211 -0
- package/dist/index-ham5sz8m.js +734 -0
- package/dist/index-het2he5g.js +1387 -0
- package/dist/index-hffjpmq9.js +30 -0
- package/dist/index-hmp4800j.js +51 -0
- package/dist/index-k30h66yd.js +317 -0
- package/dist/index-k5hsfc3j.js +31 -0
- package/dist/index-khtgb21r.js +92 -0
- package/dist/index-m9zn6cpq.js +51 -0
- package/dist/index-ndddxtyx.js +324 -0
- package/dist/index-ngfhvfpd.js +30 -0
- package/dist/index-np4m8hd3.js +1205 -0
- package/dist/index-p3vsv1fb.js +3493 -0
- package/dist/index-p5r7qpdd.js +85 -0
- package/dist/index-p9e0w8hs.js +1084 -0
- package/dist/index-p9sh0xx4.js +64 -0
- package/dist/index-paz6sgdp.js +371 -0
- package/dist/index-px2gm2jp.js +448 -0
- package/dist/index-qwhynv6x.js +103 -0
- package/dist/index-s812ycat.js +65 -0
- package/dist/index-sp1tzwnb.js +281 -0
- package/dist/index-t9rhjr9f.js +2306 -0
- package/dist/index-v260df89.js +342 -0
- package/dist/index-w906953s.js +946 -0
- package/dist/index-wdkt63w3.js +214 -0
- package/dist/index-wqgjfstn.js +18 -0
- package/dist/index-wsm5w4ee.js +1023 -0
- package/dist/index-xw3s75nj.js +100 -0
- package/dist/index-yw4fzmdz.js +268 -0
- package/dist/index-zfrhfn82.js +85 -0
- package/dist/index-znfs20ss.js +98 -0
- package/dist/internal/atomic-file.d.ts +23 -2
- package/dist/internal/atomic-file.d.ts.map +1 -1
- package/dist/internal/backoff.d.ts +29 -0
- package/dist/internal/backoff.d.ts.map +1 -0
- package/dist/internal/canonical-json.d.ts +21 -11
- package/dist/internal/canonical-json.d.ts.map +1 -1
- package/dist/internal/channel.d.ts.map +1 -0
- package/dist/internal/exclusive-lock.d.ts +51 -0
- package/dist/internal/exclusive-lock.d.ts.map +1 -0
- package/dist/internal/logger.d.ts.map +1 -0
- package/dist/internal/process-identity.d.ts +47 -0
- package/dist/internal/process-identity.d.ts.map +1 -0
- package/dist/internal/request.d.ts.map +1 -0
- package/dist/internal/stable-digest.d.ts +0 -43
- package/dist/internal/stable-digest.d.ts.map +1 -1
- package/dist/internal/typed.d.ts +0 -8
- package/dist/internal/typed.d.ts.map +1 -1
- package/dist/internal/with-exclusive-lock.d.ts +67 -0
- package/dist/internal/with-exclusive-lock.d.ts.map +1 -0
- package/dist/internal/zod-issues.d.ts +38 -0
- package/dist/internal/zod-issues.d.ts.map +1 -0
- package/dist/json-schema/dialect.d.ts +17 -0
- package/dist/json-schema/dialect.d.ts.map +1 -0
- package/dist/json-schema/json-schema.d.ts.map +1 -0
- package/dist/live/watch-client.d.ts.map +1 -1
- package/dist/live/watch-delta.d.ts.map +1 -1
- package/dist/oauth/authorization-code.d.ts +57 -0
- package/dist/oauth/authorization-code.d.ts.map +1 -0
- package/dist/observability/audit.d.ts +3 -3
- package/dist/observability/audit.d.ts.map +1 -1
- package/dist/observability/bounded-logger.d.ts +1 -1
- package/dist/observability/bounded-logger.d.ts.map +1 -1
- package/dist/observability/bounded-sink.d.ts +81 -0
- package/dist/observability/bounded-sink.d.ts.map +1 -0
- package/dist/observability/context.d.ts +1 -1
- package/dist/observability/context.d.ts.map +1 -1
- package/dist/observability/event.d.ts +2 -1
- package/dist/observability/event.d.ts.map +1 -1
- package/dist/observability/work.d.ts +1 -1
- package/dist/observability/work.d.ts.map +1 -1
- package/dist/primitives/audit.d.ts +1 -1
- package/dist/primitives/audit.d.ts.map +1 -1
- package/dist/primitives/export-operation.d.ts +4 -2
- package/dist/primitives/export-operation.d.ts.map +1 -1
- package/dist/realtime/registry.d.ts +0 -5
- package/dist/realtime/registry.d.ts.map +1 -1
- package/dist/realtime/socket.d.ts +1 -1
- package/dist/realtime/socket.d.ts.map +1 -1
- package/dist/server/bun.d.ts +0 -1
- package/dist/server/bun.d.ts.map +1 -1
- package/dist/server/context-contribution.d.ts +1 -1
- package/dist/server/context-contribution.d.ts.map +1 -1
- package/dist/server/context.d.ts +2 -2
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/contract-method.d.ts +15 -0
- package/dist/server/contract-method.d.ts.map +1 -0
- package/dist/server/contract-stream.d.ts +1 -1
- package/dist/server/contract-stream.d.ts.map +1 -1
- package/dist/server/create.d.ts +8 -0
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/endpoint-dispatch.d.ts +10 -0
- package/dist/server/endpoint-dispatch.d.ts.map +1 -0
- package/dist/server/endpoint-response.d.ts +19 -0
- package/dist/server/endpoint-response.d.ts.map +1 -0
- package/dist/server/error-dispatch.d.ts +17 -1
- package/dist/server/error-dispatch.d.ts.map +1 -1
- package/dist/server/error-hook.d.ts +2 -2
- package/dist/server/error-hook.d.ts.map +1 -1
- package/dist/server/handler-state.d.ts +44 -0
- package/dist/server/handler-state.d.ts.map +1 -0
- package/dist/server/implement-registry.d.ts +54 -0
- package/dist/server/implement-registry.d.ts.map +1 -0
- package/dist/server/implement.d.ts +9 -55
- package/dist/server/implement.d.ts.map +1 -1
- package/dist/server/middleware/auth.d.ts +1 -31
- package/dist/server/middleware/auth.d.ts.map +1 -1
- package/dist/server/middleware/cors.d.ts +17 -0
- package/dist/server/middleware/cors.d.ts.map +1 -1
- package/dist/server/middleware/jwt.d.ts +31 -0
- package/dist/server/middleware/jwt.d.ts.map +1 -0
- package/dist/server/middleware/trust-fence.d.ts +1 -1
- package/dist/server/middleware/trust-fence.d.ts.map +1 -1
- package/dist/server/multipart-reader.d.ts +22 -0
- package/dist/server/multipart-reader.d.ts.map +1 -0
- package/dist/server/multipart.d.ts +1 -1
- package/dist/server/multipart.d.ts.map +1 -1
- package/dist/server/oauth/cimd.d.ts +88 -0
- package/dist/server/oauth/cimd.d.ts.map +1 -0
- package/dist/server/oauth/endpoints.d.ts +39 -0
- package/dist/server/oauth/endpoints.d.ts.map +1 -0
- package/dist/server/oauth/metadata.d.ts +28 -0
- package/dist/server/oauth/metadata.d.ts.map +1 -0
- package/dist/server/oauth/provider.d.ts +117 -0
- package/dist/server/oauth/provider.d.ts.map +1 -0
- package/dist/server/realtime.d.ts +1 -1
- package/dist/server/realtime.d.ts.map +1 -1
- package/dist/server/request-completion.d.ts +16 -0
- package/dist/server/request-completion.d.ts.map +1 -0
- package/dist/server/response-metadata.d.ts +1 -1
- package/dist/server/response-metadata.d.ts.map +1 -1
- package/dist/server/route-table.d.ts +9 -0
- package/dist/server/route-table.d.ts.map +1 -0
- package/dist/server/stream.d.ts +0 -13
- package/dist/server/stream.d.ts.map +1 -1
- package/dist/server/streaming-pump.d.ts +66 -0
- package/dist/server/streaming-pump.d.ts.map +1 -0
- package/dist/server/streaming-route.d.ts +12 -5
- package/dist/server/streaming-route.d.ts.map +1 -1
- package/dist/server/types.d.ts +10 -4
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/unix-client-bun.d.ts.map +1 -1
- package/dist/server/unix-client-http1.d.ts +76 -0
- package/dist/server/unix-client-http1.d.ts.map +1 -0
- package/dist/server/unix-client.d.ts.map +1 -1
- package/dist/testing/handler-clients.d.ts +32 -0
- package/dist/testing/handler-clients.d.ts.map +1 -0
- package/dist/testing/managed-resource-conformance-scenarios.d.ts.map +1 -1
- package/dist/testing/realtime-probe.d.ts +33 -0
- package/dist/testing/realtime-probe.d.ts.map +1 -0
- package/dist/testing/surface-conformance.d.ts +2 -32
- package/dist/testing/surface-conformance.d.ts.map +1 -1
- package/dist/testing/surface-manifest-digest.d.ts +44 -0
- package/dist/testing/surface-manifest-digest.d.ts.map +1 -0
- package/dist/testing/surface-manifest.d.ts +30 -4
- package/dist/testing/surface-manifest.d.ts.map +1 -1
- package/dist/tools/agent.d.ts +1 -1
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/cli/args-fields.d.ts +31 -0
- package/dist/tools/cli/args-fields.d.ts.map +1 -0
- package/dist/tools/cli/args-route.d.ts +42 -0
- package/dist/tools/cli/args-route.d.ts.map +1 -0
- package/dist/tools/cli/args-view.d.ts +32 -0
- package/dist/tools/cli/args-view.d.ts.map +1 -0
- package/dist/tools/cli/args.d.ts +80 -0
- package/dist/tools/cli/args.d.ts.map +1 -0
- package/dist/tools/cli/argument-error.d.ts +5 -0
- package/dist/tools/cli/argument-error.d.ts.map +1 -0
- package/dist/tools/cli/checkpoint.d.ts +24 -0
- package/dist/tools/cli/checkpoint.d.ts.map +1 -0
- package/dist/tools/cli/command.d.ts +70 -0
- package/dist/tools/cli/command.d.ts.map +1 -0
- package/dist/tools/cli/config.d.ts +90 -0
- package/dist/tools/cli/config.d.ts.map +1 -0
- package/dist/tools/cli/create-cli.d.ts +36 -0
- package/dist/tools/cli/create-cli.d.ts.map +1 -0
- package/dist/tools/cli/download.d.ts +8 -0
- package/dist/tools/cli/download.d.ts.map +1 -0
- package/dist/tools/cli/format.d.ts +50 -0
- package/dist/tools/cli/format.d.ts.map +1 -0
- package/dist/tools/cli/help.d.ts +24 -0
- package/dist/tools/cli/help.d.ts.map +1 -0
- package/dist/tools/cli/installer.d.ts +34 -0
- package/dist/tools/cli/installer.d.ts.map +1 -0
- package/dist/tools/cli/invoke.d.ts +144 -0
- package/dist/tools/cli/invoke.d.ts.map +1 -0
- package/dist/tools/cli/io.d.ts +10 -0
- package/dist/tools/cli/io.d.ts.map +1 -0
- package/dist/tools/cli/managed-surface.d.ts +30 -0
- package/dist/tools/cli/managed-surface.d.ts.map +1 -0
- package/dist/tools/cli/manifest.d.ts +80 -0
- package/dist/tools/cli/manifest.d.ts.map +1 -0
- package/dist/tools/cli/policy.d.ts +27 -0
- package/dist/tools/cli/policy.d.ts.map +1 -0
- package/dist/tools/cli/prepare.d.ts +14 -0
- package/dist/tools/cli/prepare.d.ts.map +1 -0
- package/dist/tools/cli/profile.d.ts +40 -0
- package/dist/tools/cli/profile.d.ts.map +1 -0
- package/dist/tools/cli/run-managed.d.ts +5 -0
- package/dist/tools/cli/run-managed.d.ts.map +1 -0
- package/dist/tools/cli/run-native.d.ts +9 -0
- package/dist/tools/cli/run-native.d.ts.map +1 -0
- package/dist/tools/cli/session.d.ts +40 -0
- package/dist/tools/cli/session.d.ts.map +1 -0
- package/dist/tools/cli/signature.d.ts +81 -0
- package/dist/tools/cli/signature.d.ts.map +1 -0
- package/dist/tools/cli/stream.d.ts +93 -0
- package/dist/tools/cli/stream.d.ts.map +1 -0
- package/dist/tools/cli/update.d.ts +145 -0
- package/dist/tools/cli/update.d.ts.map +1 -0
- package/dist/tools/cli/view.d.ts +12 -0
- package/dist/tools/cli/view.d.ts.map +1 -0
- package/dist/tools/cli/wait.d.ts +54 -0
- package/dist/tools/cli/wait.d.ts.map +1 -0
- package/dist/tools/connections/runtime.d.ts +1 -1
- package/dist/tools/connections/runtime.d.ts.map +1 -1
- package/dist/tools/connections/types.d.ts +3 -3
- package/dist/tools/connections/types.d.ts.map +1 -1
- package/dist/tools/durability-context.d.ts +1 -1
- package/dist/tools/durability-context.d.ts.map +1 -1
- package/dist/tools/execute-args.d.ts +23 -0
- package/dist/tools/execute-args.d.ts.map +1 -0
- package/dist/tools/execute-hooks.d.ts +146 -0
- package/dist/tools/execute-hooks.d.ts.map +1 -0
- package/dist/tools/execute-result.d.ts +40 -0
- package/dist/tools/execute-result.d.ts.map +1 -0
- package/dist/tools/execute.d.ts +31 -193
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/internal/surface-projector.d.ts +9 -6
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/dist/tools/internal/tool-view.d.ts +41 -0
- package/dist/tools/internal/tool-view.d.ts.map +1 -0
- package/dist/tools/invoker.d.ts +13 -4
- package/dist/tools/invoker.d.ts.map +1 -1
- package/dist/tools/lifecycle.d.ts +1 -1
- package/dist/tools/lifecycle.d.ts.map +1 -1
- package/dist/tools/list-names.d.ts +3 -3
- package/dist/tools/list-names.d.ts.map +1 -1
- package/dist/tools/manifest.d.ts +2 -2
- package/dist/tools/manifest.d.ts.map +1 -1
- package/dist/tools/mcp/app.d.ts +62 -0
- package/dist/tools/mcp/app.d.ts.map +1 -0
- package/dist/tools/mcp/catalog.d.ts +68 -0
- package/dist/tools/mcp/catalog.d.ts.map +1 -0
- package/dist/tools/mcp/handler.d.ts +46 -0
- package/dist/tools/mcp/handler.d.ts.map +1 -0
- package/dist/tools/mcp/mount.d.ts +152 -0
- package/dist/tools/mcp/mount.d.ts.map +1 -0
- package/dist/tools/mcp/prepare.d.ts +76 -0
- package/dist/tools/mcp/prepare.d.ts.map +1 -0
- package/dist/tools/mcp/progress.d.ts +46 -0
- package/dist/tools/mcp/progress.d.ts.map +1 -0
- package/dist/tools/mcp/register.d.ts +36 -0
- package/dist/tools/mcp/register.d.ts.map +1 -0
- package/dist/tools/mcp/round-context.d.ts +38 -0
- package/dist/tools/mcp/round-context.d.ts.map +1 -0
- package/dist/tools/mcp/round-policy.d.ts +33 -0
- package/dist/tools/mcp/round-policy.d.ts.map +1 -0
- package/dist/tools/mcp/round.d.ts +53 -0
- package/dist/tools/mcp/round.d.ts.map +1 -0
- package/dist/tools/mcp/runtime-tools.d.ts +25 -0
- package/dist/tools/mcp/runtime-tools.d.ts.map +1 -0
- package/dist/tools/mcp/stdio-signals.d.ts +33 -0
- package/dist/tools/mcp/stdio-signals.d.ts.map +1 -0
- package/dist/tools/mcp/stdio.d.ts +20 -0
- package/dist/tools/mcp/stdio.d.ts.map +1 -0
- package/dist/tools/mcp/trace.d.ts +12 -0
- package/dist/tools/mcp/trace.d.ts.map +1 -0
- package/dist/tools/mount.d.ts +14 -7
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools/native-definition.d.ts +4 -3
- package/dist/tools/native-definition.d.ts.map +1 -1
- package/dist/tools/operations/async-operation-binding-types.d.ts +127 -0
- package/dist/tools/operations/async-operation-binding-types.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-binding.d.ts +28 -0
- package/dist/tools/operations/async-operation-binding.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-canonical-types.d.ts +110 -0
- package/dist/tools/operations/async-operation-canonical-types.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-canonical.d.ts +7 -0
- package/dist/tools/operations/async-operation-canonical.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-contract.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-id.d.ts +23 -0
- package/dist/tools/operations/async-operation-id.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-runtime-tools.d.ts +41 -0
- package/dist/tools/operations/async-operation-runtime-tools.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-runtime-types.d.ts +69 -0
- package/dist/tools/operations/async-operation-runtime-types.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-runtime.d.ts +5 -0
- package/dist/tools/operations/async-operation-runtime.d.ts.map +1 -0
- package/dist/tools/operations/define-wait-tool.d.ts +22 -0
- package/dist/tools/operations/define-wait-tool.d.ts.map +1 -0
- package/dist/tools/operations/mount-wait.d.ts.map +1 -0
- package/dist/tools/operations/wait-core.d.ts.map +1 -0
- package/dist/tools/remote.d.ts +1 -1
- package/dist/tools/remote.d.ts.map +1 -1
- package/dist/tools/runtime-tool.d.ts +13 -4
- package/dist/tools/runtime-tool.d.ts.map +1 -1
- package/dist/tools/schema/coerce.d.ts.map +1 -0
- package/dist/tools/schema/flatten-join.d.ts.map +1 -0
- package/dist/tools/schema/flatten.d.ts.map +1 -0
- package/dist/tools/schema/portable-formats.d.ts.map +1 -0
- package/dist/tools/schema/presentation.d.ts +24 -0
- package/dist/tools/schema/presentation.d.ts.map +1 -0
- package/dist/tools/schema/schema.d.ts.map +1 -0
- package/dist/tools/schema/untyped-properties.d.ts.map +1 -0
- package/dist/tools/surface.d.ts +2 -3
- package/dist/tools/surface.d.ts.map +1 -1
- package/dist/tools/tool-logger.d.ts +1 -1
- package/dist/tools/tool-logger.d.ts.map +1 -1
- package/dist/tools/toolkit.d.ts +4 -4
- package/dist/tools/toolkit.d.ts.map +1 -1
- package/dist/tools/transfer/define-download-tool.d.ts +18 -0
- package/dist/tools/transfer/define-download-tool.d.ts.map +1 -0
- package/dist/tools/transfer/define-upload-tool.d.ts +16 -0
- package/dist/tools/transfer/define-upload-tool.d.ts.map +1 -0
- package/dist/tools/transfer/define-view-file-tool.d.ts +10 -0
- package/dist/tools/transfer/define-view-file-tool.d.ts.map +1 -0
- package/dist/tools/transfer/download-core.d.ts +20 -0
- package/dist/tools/transfer/download-core.d.ts.map +1 -0
- package/dist/tools/transfer/managed-file-error.d.ts +6 -0
- package/dist/tools/transfer/managed-file-error.d.ts.map +1 -0
- package/dist/tools/transfer/mount-download.d.ts +41 -0
- package/dist/tools/transfer/mount-download.d.ts.map +1 -0
- package/dist/tools/transfer/mount-upload.d.ts +21 -0
- package/dist/tools/transfer/mount-upload.d.ts.map +1 -0
- package/dist/tools/transfer/native-result.d.ts.map +1 -0
- package/dist/tools/transfer/upload-core.d.ts +4 -0
- package/dist/tools/transfer/upload-core.d.ts.map +1 -0
- package/dist/tools/transfer/view-file-contract.d.ts.map +1 -0
- package/dist/tools/transfer/view-file.d.ts +62 -0
- package/dist/tools/transfer/view-file.d.ts.map +1 -0
- package/dist/tools/transports.d.ts +1 -1
- package/dist/tools/transports.d.ts.map +1 -1
- package/dist/tracking/client-listeners.d.ts +30 -0
- package/dist/tracking/client-listeners.d.ts.map +1 -0
- package/dist/tracking/client-visit.d.ts +61 -0
- package/dist/tracking/client-visit.d.ts.map +1 -0
- package/dist/tracking/client.d.ts +3 -2
- package/dist/tracking/client.d.ts.map +1 -1
- package/dist/tracking/contract.d.ts +1 -1
- package/dist/tracking/contract.d.ts.map +1 -1
- package/llms/agent-runtime-browser.txt +33 -0
- package/llms/agent-runtime-coding-tools.txt +58 -0
- package/llms/agent-runtime-harness.txt +45 -0
- package/llms/agent-runtime-openrouter.txt +22 -0
- package/llms/agent-runtime-sandbox.txt +159 -0
- package/llms/agent-runtime-sqlite-bun.txt +29 -0
- package/llms/agent-runtime-sqlite-node.txt +26 -0
- package/llms/agent-runtime-testing.txt +30 -0
- package/llms/agent-runtime.2.txt +550 -0
- package/llms/agent-runtime.3.txt +311 -0
- package/llms/agent-runtime.txt +893 -0
- package/llms/application-diagnostic-journal.txt +30 -0
- package/llms/application-grammy.txt +27 -0
- package/llms/application-opentelemetry.txt +27 -0
- package/llms/application-schemas.txt +42 -0
- package/llms/application.2.txt +487 -0
- package/llms/application.txt +886 -0
- package/llms/cli.2.txt +80 -0
- package/llms/cli.txt +948 -0
- package/llms/contract.txt +606 -0
- package/llms/declaration.txt +286 -0
- package/llms/files.txt +33 -0
- package/llms/geo.txt +114 -0
- package/llms/google.txt +27 -0
- package/llms/live.txt +471 -0
- package/llms/node.txt +43 -0
- package/llms/oauth.txt +136 -0
- package/llms/observability.txt +893 -0
- package/llms/primitives.txt +158 -0
- package/llms/react.txt +184 -0
- package/llms/release.txt +176 -0
- package/llms/remote.txt +25 -0
- package/llms/server.2.txt +361 -0
- package/llms/server.3.txt +1031 -0
- package/llms/server.4.txt +905 -0
- package/llms/server.5.txt +250 -0
- package/llms/server.txt +996 -0
- package/llms/stitchkit.2.txt +836 -0
- package/llms/stitchkit.3.txt +147 -0
- package/llms/stitchkit.txt +260 -0
- package/llms/telegram.txt +30 -0
- package/llms/testing.txt +676 -0
- package/llms/tools-connections.txt +45 -0
- package/llms/tools-contract.txt +9 -0
- package/llms/tools-invoker.txt +9 -0
- package/llms/tools.2.txt +647 -0
- package/llms/tools.3.txt +288 -0
- package/llms/tools.txt +966 -0
- package/llms/tracking-server.txt +32 -0
- package/llms/tracking.txt +263 -0
- package/llms/upgrading-0.37.0-0.50.0.txt +947 -0
- package/llms/upgrading-0.53.0-0.67.0.txt +1174 -0
- package/llms/upgrading-0.68.0-0.94.0.txt +1159 -0
- package/llms/upgrading.txt +215 -0
- package/llms-full.txt +312 -77
- package/llms.txt +54 -5
- package/package.json +84 -83
- package/dist/agent-runtime/durability-contract.d.ts +0 -176
- package/dist/agent-runtime/durability-contract.d.ts.map +0 -1
- package/dist/agent-runtime/durability-json.d.ts +0 -3
- package/dist/agent-runtime/durability-json.d.ts.map +0 -1
- package/dist/agent-runtime/durability-ledger.d.ts +0 -16
- package/dist/agent-runtime/durability-ledger.d.ts.map +0 -1
- package/dist/agent-runtime/durability-scheduler.d.ts +0 -29
- package/dist/agent-runtime/durability-scheduler.d.ts.map +0 -1
- package/dist/agent-runtime/durability.d.ts +0 -14
- package/dist/agent-runtime/durability.d.ts.map +0 -1
- package/dist/agent-runtime/store-driver.d.ts +0 -814
- package/dist/agent-runtime/store-driver.d.ts.map +0 -1
- package/dist/agent-runtime-browser.d.ts +0 -5
- package/dist/agent-runtime-browser.d.ts.map +0 -1
- package/dist/agent-runtime-browser.js +0 -124
- package/dist/agent-runtime-coding-tools.d.ts +0 -2
- package/dist/agent-runtime-coding-tools.d.ts.map +0 -1
- package/dist/agent-runtime-coding-tools.js +0 -23
- package/dist/agent-runtime-harness.d.ts +0 -2
- package/dist/agent-runtime-harness.d.ts.map +0 -1
- package/dist/agent-runtime-harness.js +0 -729
- package/dist/agent-runtime-openrouter.d.ts +0 -29
- package/dist/agent-runtime-openrouter.d.ts.map +0 -1
- package/dist/agent-runtime-openrouter.js +0 -270
- package/dist/agent-runtime-sandbox.d.ts +0 -5
- package/dist/agent-runtime-sandbox.d.ts.map +0 -1
- package/dist/agent-runtime-sandbox.js +0 -798
- package/dist/agent-runtime-sqlite-bun.d.ts +0 -11
- package/dist/agent-runtime-sqlite-bun.d.ts.map +0 -1
- package/dist/agent-runtime-sqlite-bun.js +0 -42
- package/dist/agent-runtime-sqlite-node.d.ts +0 -11
- package/dist/agent-runtime-sqlite-node.d.ts.map +0 -1
- package/dist/agent-runtime-sqlite-node.js +0 -44
- package/dist/agent-runtime-testing.d.ts +0 -3
- package/dist/agent-runtime-testing.d.ts.map +0 -1
- package/dist/agent-runtime-testing.js +0 -156
- package/dist/agent-runtime.d.ts +0 -38
- package/dist/agent-runtime.d.ts.map +0 -1
- package/dist/agent-runtime.js +0 -2607
- package/dist/application/channel.d.ts.map +0 -1
- package/dist/application-diagnostic-journal.d.ts +0 -21
- package/dist/application-diagnostic-journal.d.ts.map +0 -1
- package/dist/application-diagnostic-journal.js +0 -632
- package/dist/application-grammy.d.ts +0 -2
- package/dist/application-grammy.d.ts.map +0 -1
- package/dist/application-grammy.js +0 -169
- package/dist/application-opentelemetry.d.ts +0 -2
- package/dist/application-opentelemetry.d.ts.map +0 -1
- package/dist/application-opentelemetry.js +0 -250
- package/dist/application-schemas.d.ts +0 -15
- package/dist/application-schemas.d.ts.map +0 -1
- package/dist/application-schemas.js +0 -27
- package/dist/application.d.ts +0 -22
- package/dist/application.d.ts.map +0 -1
- package/dist/application.js +0 -1977
- package/dist/cli.d.ts +0 -41
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -753
- package/dist/contract/index.d.ts +0 -8
- package/dist/contract/index.d.ts.map +0 -1
- package/dist/contract/index.js +0 -55
- package/dist/declaration.d.ts.map +0 -1
- package/dist/declaration.js +0 -183
- package/dist/files.d.ts +0 -3
- package/dist/files.d.ts.map +0 -1
- package/dist/files.js +0 -15
- package/dist/geo.d.ts +0 -3
- package/dist/geo.d.ts.map +0 -1
- package/dist/geo.js +0 -245
- package/dist/google.d.ts.map +0 -1
- package/dist/google.js +0 -175
- package/dist/index-0a349c33.js +0 -470
- package/dist/index-0j3vcp5m.js +0 -28
- package/dist/index-2c2bjw3s.js +0 -51
- package/dist/index-2na0qrfn.js +0 -214
- package/dist/index-2qzskm8h.js +0 -63
- package/dist/index-3bmnp41g.js +0 -2169
- package/dist/index-3xwxfj4z.js +0 -334
- package/dist/index-4fpa9dy2.js +0 -51
- package/dist/index-6kyksz9y.js +0 -268
- package/dist/index-77fekveh.js +0 -44
- package/dist/index-7gnkny4z.js +0 -326
- package/dist/index-7zbps32p.js +0 -89
- package/dist/index-9f8ztey6.js +0 -588
- package/dist/index-a11g2kry.js +0 -866
- package/dist/index-a916km3r.js +0 -45
- package/dist/index-actkayzn.js +0 -367
- package/dist/index-bn2cjajt.js +0 -524
- package/dist/index-bx75zwt7.js +0 -63
- package/dist/index-cby4ar3v.js +0 -46
- package/dist/index-cnyk6te3.js +0 -77
- package/dist/index-cxqhvq21.js +0 -413
- package/dist/index-e0znv5gn.js +0 -176
- package/dist/index-e42wzzz5.js +0 -154
- package/dist/index-f477k430.js +0 -324
- package/dist/index-f9mb610r.js +0 -177
- package/dist/index-fadnxwna.js +0 -1046
- package/dist/index-fq77yfzc.js +0 -1303
- package/dist/index-h9etkkyk.js +0 -1126
- package/dist/index-hrbajay7.js +0 -1196
- package/dist/index-kw9t5ayn.js +0 -507
- package/dist/index-mzvgxp0n.js +0 -80
- package/dist/index-n0f51dfn.js +0 -3170
- package/dist/index-p13mwz16.js +0 -16
- package/dist/index-s8cnx02s.js +0 -90
- package/dist/index-sr93cwf9.js +0 -325
- package/dist/index-tmwcrptx.js +0 -85
- package/dist/index-v5573g1k.js +0 -142
- package/dist/index-vjpvjqpn.js +0 -86
- package/dist/index-vk3kq9sb.js +0 -3344
- package/dist/index-wc4x00bn.js +0 -103
- package/dist/index-wnfk50r0.js +0 -211
- package/dist/index-yewwh1w4.js +0 -647
- package/dist/index-yn8remb1.js +0 -290
- package/dist/index-ywd0y6m1.js +0 -394
- package/dist/index-zwkgfq1s.js +0 -345
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -632
- package/dist/internal/errors.d.ts +0 -92
- package/dist/internal/errors.d.ts.map +0 -1
- package/dist/internal/observability-sink.d.ts +0 -81
- package/dist/internal/observability-sink.d.ts.map +0 -1
- package/dist/live.d.ts +0 -19
- package/dist/live.d.ts.map +0 -1
- package/dist/live.js +0 -282
- package/dist/logger.d.ts.map +0 -1
- package/dist/node.d.ts +0 -18
- package/dist/node.d.ts.map +0 -1
- package/dist/node.js +0 -303
- package/dist/oauth.d.ts +0 -57
- package/dist/oauth.d.ts.map +0 -1
- package/dist/oauth.js +0 -170
- package/dist/observability/index.d.ts +0 -19
- package/dist/observability/index.d.ts.map +0 -1
- package/dist/observability/index.js +0 -569
- package/dist/primitives.d.ts +0 -3
- package/dist/primitives.d.ts.map +0 -1
- package/dist/primitives.js +0 -754
- package/dist/react.d.ts +0 -5
- package/dist/react.d.ts.map +0 -1
- package/dist/react.js +0 -403
- package/dist/release.d.ts +0 -15
- package/dist/release.d.ts.map +0 -1
- package/dist/release.js +0 -196
- package/dist/remote.d.ts +0 -9
- package/dist/remote.d.ts.map +0 -1
- package/dist/remote.js +0 -88
- package/dist/retained.d.ts.map +0 -1
- package/dist/server/file-state-store.d.ts +0 -23
- package/dist/server/file-state-store.d.ts.map +0 -1
- package/dist/server/index.d.ts +0 -36
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js +0 -1745
- package/dist/server/request.d.ts.map +0 -1
- package/dist/telegram.d.ts +0 -3
- package/dist/telegram.d.ts.map +0 -1
- package/dist/telegram.js +0 -224
- package/dist/testing/agent-store-conformance.d.ts +0 -40
- package/dist/testing/agent-store-conformance.d.ts.map +0 -1
- package/dist/testing.d.ts +0 -39
- package/dist/testing.d.ts.map +0 -1
- package/dist/testing.js +0 -2209
- package/dist/tool-invoker.d.ts +0 -9
- package/dist/tool-invoker.d.ts.map +0 -1
- package/dist/tool-invoker.js +0 -21
- package/dist/tools/async-operation-contract.d.ts.map +0 -1
- package/dist/tools/async-operation.d.ts +0 -332
- package/dist/tools/async-operation.d.ts.map +0 -1
- package/dist/tools/cli-args.d.ts +0 -143
- package/dist/tools/cli-args.d.ts.map +0 -1
- package/dist/tools/cli-checkpoint.d.ts +0 -24
- package/dist/tools/cli-checkpoint.d.ts.map +0 -1
- package/dist/tools/cli-command.d.ts +0 -70
- package/dist/tools/cli-command.d.ts.map +0 -1
- package/dist/tools/cli-format.d.ts +0 -49
- package/dist/tools/cli-format.d.ts.map +0 -1
- package/dist/tools/cli-installer.d.ts +0 -34
- package/dist/tools/cli-installer.d.ts.map +0 -1
- package/dist/tools/cli-invoke.d.ts +0 -143
- package/dist/tools/cli-invoke.d.ts.map +0 -1
- package/dist/tools/cli-manifest.d.ts +0 -80
- package/dist/tools/cli-manifest.d.ts.map +0 -1
- package/dist/tools/cli-policy.d.ts +0 -27
- package/dist/tools/cli-policy.d.ts.map +0 -1
- package/dist/tools/cli-profile.d.ts +0 -40
- package/dist/tools/cli-profile.d.ts.map +0 -1
- package/dist/tools/cli-signature.d.ts +0 -81
- package/dist/tools/cli-signature.d.ts.map +0 -1
- package/dist/tools/cli-stream.d.ts +0 -93
- package/dist/tools/cli-stream.d.ts.map +0 -1
- package/dist/tools/cli-update.d.ts +0 -126
- package/dist/tools/cli-update.d.ts.map +0 -1
- package/dist/tools/cli-view.d.ts +0 -12
- package/dist/tools/cli-view.d.ts.map +0 -1
- package/dist/tools/cli-wait.d.ts +0 -54
- package/dist/tools/cli-wait.d.ts.map +0 -1
- package/dist/tools/cli.d.ts +0 -94
- package/dist/tools/cli.d.ts.map +0 -1
- package/dist/tools/coerce.d.ts.map +0 -1
- package/dist/tools/connections/index.d.ts +0 -20
- package/dist/tools/connections/index.d.ts.map +0 -1
- package/dist/tools/connections/index.js +0 -1107
- package/dist/tools/define-download-tool.d.ts +0 -18
- package/dist/tools/define-download-tool.d.ts.map +0 -1
- package/dist/tools/define-upload-tool.d.ts +0 -16
- package/dist/tools/define-upload-tool.d.ts.map +0 -1
- package/dist/tools/define-view-file-tool.d.ts +0 -10
- package/dist/tools/define-view-file-tool.d.ts.map +0 -1
- package/dist/tools/define-wait-tool.d.ts +0 -22
- package/dist/tools/define-wait-tool.d.ts.map +0 -1
- package/dist/tools/download-core.d.ts +0 -20
- package/dist/tools/download-core.d.ts.map +0 -1
- package/dist/tools/flatten-join.d.ts.map +0 -1
- package/dist/tools/flatten.d.ts.map +0 -1
- package/dist/tools/json-schema-dialect.d.ts +0 -17
- package/dist/tools/json-schema-dialect.d.ts.map +0 -1
- package/dist/tools/json-schema.d.ts.map +0 -1
- package/dist/tools/managed-file-error.d.ts +0 -6
- package/dist/tools/managed-file-error.d.ts.map +0 -1
- package/dist/tools/mcp-app.d.ts +0 -62
- package/dist/tools/mcp-app.d.ts.map +0 -1
- package/dist/tools/mcp-catalog.d.ts +0 -68
- package/dist/tools/mcp-catalog.d.ts.map +0 -1
- package/dist/tools/mcp-handler.d.ts +0 -46
- package/dist/tools/mcp-handler.d.ts.map +0 -1
- package/dist/tools/mcp-prepare.d.ts +0 -75
- package/dist/tools/mcp-prepare.d.ts.map +0 -1
- package/dist/tools/mcp-progress.d.ts +0 -46
- package/dist/tools/mcp-progress.d.ts.map +0 -1
- package/dist/tools/mcp-round-policy.d.ts +0 -33
- package/dist/tools/mcp-round-policy.d.ts.map +0 -1
- package/dist/tools/mcp-round.d.ts +0 -61
- package/dist/tools/mcp-round.d.ts.map +0 -1
- package/dist/tools/mcp-stdio-signals.d.ts +0 -33
- package/dist/tools/mcp-stdio-signals.d.ts.map +0 -1
- package/dist/tools/mcp-stdio.d.ts +0 -20
- package/dist/tools/mcp-stdio.d.ts.map +0 -1
- package/dist/tools/mcp-trace.d.ts +0 -12
- package/dist/tools/mcp-trace.d.ts.map +0 -1
- package/dist/tools/mcp.d.ts +0 -152
- package/dist/tools/mcp.d.ts.map +0 -1
- package/dist/tools/mount-download.d.ts +0 -41
- package/dist/tools/mount-download.d.ts.map +0 -1
- package/dist/tools/mount-upload.d.ts +0 -21
- package/dist/tools/mount-upload.d.ts.map +0 -1
- package/dist/tools/mount-wait.d.ts.map +0 -1
- package/dist/tools/native-mcp.d.ts +0 -20
- package/dist/tools/native-mcp.d.ts.map +0 -1
- package/dist/tools/native-result.d.ts.map +0 -1
- package/dist/tools/oauth-metadata.d.ts +0 -28
- package/dist/tools/oauth-metadata.d.ts.map +0 -1
- package/dist/tools/oauth-provider.d.ts +0 -184
- package/dist/tools/oauth-provider.d.ts.map +0 -1
- package/dist/tools/portable-formats.d.ts.map +0 -1
- package/dist/tools/presentation.d.ts +0 -22
- package/dist/tools/presentation.d.ts.map +0 -1
- package/dist/tools/schema.d.ts.map +0 -1
- package/dist/tools/untyped-properties.d.ts.map +0 -1
- package/dist/tools/upload-core.d.ts +0 -4
- package/dist/tools/upload-core.d.ts.map +0 -1
- package/dist/tools/view-file-contract.d.ts.map +0 -1
- package/dist/tools/view-file.d.ts +0 -62
- package/dist/tools/view-file.d.ts.map +0 -1
- package/dist/tools/wait-core.d.ts.map +0 -1
- package/dist/tools-contract.d.ts +0 -29
- package/dist/tools-contract.d.ts.map +0 -1
- package/dist/tools-contract.js +0 -24
- package/dist/tools.d.ts +0 -50
- package/dist/tools.d.ts.map +0 -1
- package/dist/tools.js +0 -2930
- package/dist/tracking-server.d.ts +0 -15
- package/dist/tracking-server.d.ts.map +0 -1
- package/dist/tracking.d.ts +0 -24
- package/dist/tracking.d.ts.map +0 -1
- package/dist/tracking.js +0 -1092
- package/dist/upgrade-cli.d.ts.map +0 -1
- package/dist/upgrade-cli.js +0 -177
- /package/dist/{retained.d.ts → browser/retained.d.ts} +0 -0
- /package/dist/{declaration.d.ts → declaration/declaration.d.ts} +0 -0
- /package/dist/{upgrade-cli.d.ts → entrypoints/bin/upgrade-cli.d.ts} +0 -0
- /package/dist/{tracking-server.js → entrypoints/tracking/server.js} +0 -0
- /package/dist/{google.d.ts → google/google.d.ts} +0 -0
- /package/dist/{index-pq95qkbf.js → index-5jm36zv1.js} +0 -0
- /package/dist/{application → internal}/channel.d.ts +0 -0
- /package/dist/{logger.d.ts → internal/logger.d.ts} +0 -0
- /package/dist/{server → internal}/request.d.ts +0 -0
- /package/dist/{tools → json-schema}/json-schema.d.ts +0 -0
- /package/dist/tools/{async-operation-contract.d.ts → operations/async-operation-contract.d.ts} +0 -0
- /package/dist/tools/{mount-wait.d.ts → operations/mount-wait.d.ts} +0 -0
- /package/dist/tools/{wait-core.d.ts → operations/wait-core.d.ts} +0 -0
- /package/dist/tools/{coerce.d.ts → schema/coerce.d.ts} +0 -0
- /package/dist/tools/{flatten-join.d.ts → schema/flatten-join.d.ts} +0 -0
- /package/dist/tools/{flatten.d.ts → schema/flatten.d.ts} +0 -0
- /package/dist/tools/{portable-formats.d.ts → schema/portable-formats.d.ts} +0 -0
- /package/dist/tools/{schema.d.ts → schema/schema.d.ts} +0 -0
- /package/dist/tools/{untyped-properties.d.ts → schema/untyped-properties.d.ts} +0 -0
- /package/dist/tools/{native-result.d.ts → transfer/native-result.d.ts} +0 -0
- /package/dist/tools/{view-file-contract.d.ts → transfer/view-file-contract.d.ts} +0 -0
package/dist/index-3bmnp41g.js
DELETED
|
@@ -1,2169 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isWithinDir
|
|
3
|
-
} from "./index-sbdmyz75.js";
|
|
4
|
-
import {
|
|
5
|
-
collectToolSurface
|
|
6
|
-
} from "./index-2c2bjw3s.js";
|
|
7
|
-
import {
|
|
8
|
-
createToolRunner,
|
|
9
|
-
formatToolError
|
|
10
|
-
} from "./index-mzvgxp0n.js";
|
|
11
|
-
import {
|
|
12
|
-
toolErrorFromResult,
|
|
13
|
-
toolResultFromError
|
|
14
|
-
} from "./index-yn8remb1.js";
|
|
15
|
-
import {
|
|
16
|
-
formatZodError,
|
|
17
|
-
validateDeclaredOutput
|
|
18
|
-
} from "./index-e0znv5gn.js";
|
|
19
|
-
import {
|
|
20
|
-
coerceJsonArgs
|
|
21
|
-
} from "./index-7zbps32p.js";
|
|
22
|
-
import {
|
|
23
|
-
assertUniqueToolName,
|
|
24
|
-
buildToolPresentationSchema,
|
|
25
|
-
objectShapeKeys
|
|
26
|
-
} from "./index-h9etkkyk.js";
|
|
27
|
-
import {
|
|
28
|
-
jsonSchemaFields
|
|
29
|
-
} from "./index-cby4ar3v.js";
|
|
30
|
-
import {
|
|
31
|
-
isUnsafeKey,
|
|
32
|
-
safeJsonParse
|
|
33
|
-
} from "./index-kzfs85xp.js";
|
|
34
|
-
import {
|
|
35
|
-
isRecord
|
|
36
|
-
} from "./index-77fekveh.js";
|
|
37
|
-
|
|
38
|
-
// src/tools/cli-args.ts
|
|
39
|
-
import { z } from "zod";
|
|
40
|
-
var NUMERIC_VALUE = /^-(\d+\.?\d*|\.\d+)$/;
|
|
41
|
-
var BOOL_OPTIONS = new Set(["json", "wait", "quiet", "dry-run", "help", "ascending"]);
|
|
42
|
-
var VIEW_OPTIONS = new Set(["count-by", "sum", "by", "top", "table", "sort"]);
|
|
43
|
-
var VALUE_OPTIONS = new Set(["wait-timeout", "output-dir", ...VIEW_OPTIONS]);
|
|
44
|
-
var RESERVED_CLI_OPTIONS = new Set([...BOOL_OPTIONS, ...VALUE_OPTIONS]);
|
|
45
|
-
function classifyLongOptionToken(token) {
|
|
46
|
-
if (!token.startsWith("--") || token === "--")
|
|
47
|
-
return;
|
|
48
|
-
const equals = token.indexOf("=");
|
|
49
|
-
const name = equals >= 0 ? token.slice(2, equals) : token.slice(2);
|
|
50
|
-
return {
|
|
51
|
-
name,
|
|
52
|
-
value: equals >= 0 ? token.slice(equals + 1) : undefined,
|
|
53
|
-
inline: equals >= 0,
|
|
54
|
-
globalKind: BOOL_OPTIONS.has(name) ? "boolean" : VALUE_OPTIONS.has(name) ? "value" : undefined
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
var HELP_TOKENS = new Set(["--help", "-h", "help"]);
|
|
58
|
-
function helpFilterFrom(token, rest) {
|
|
59
|
-
if (token?.startsWith("--help=")) {
|
|
60
|
-
const value = token.slice("--help=".length).trim();
|
|
61
|
-
if (value.length === 0 || isReservedBoolWord(value))
|
|
62
|
-
return;
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
if (token === undefined || !HELP_TOKENS.has(token))
|
|
66
|
-
return;
|
|
67
|
-
const next = rest[0];
|
|
68
|
-
return next !== undefined && !next.startsWith("-") ? next : undefined;
|
|
69
|
-
}
|
|
70
|
-
function routeCliArgv(argv, defaultCommand) {
|
|
71
|
-
if (defaultCommand === undefined) {
|
|
72
|
-
const [command, ...commandArgv] = argv;
|
|
73
|
-
const helpFilter = helpFilterFrom(command, commandArgv);
|
|
74
|
-
return {
|
|
75
|
-
command,
|
|
76
|
-
commandArgv,
|
|
77
|
-
topLevelHelp: false,
|
|
78
|
-
version: false,
|
|
79
|
-
...helpFilter !== undefined && { helpFilter }
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
const globals = [];
|
|
83
|
-
let index = 0;
|
|
84
|
-
while (index < argv.length) {
|
|
85
|
-
const token = argv[index];
|
|
86
|
-
if (token === undefined)
|
|
87
|
-
break;
|
|
88
|
-
if (token === "--") {
|
|
89
|
-
return {
|
|
90
|
-
commandArgv: [],
|
|
91
|
-
topLevelHelp: false,
|
|
92
|
-
version: false,
|
|
93
|
-
error: 'A command is required before "--"'
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
const inlineHelpFilter = token.startsWith("--help=") && !isReservedBoolWord(token.slice("--help=".length));
|
|
97
|
-
if (token === "--help" || token === "-h" || inlineHelpFilter) {
|
|
98
|
-
const helpFilter = helpFilterFrom(token, argv.slice(index + 1));
|
|
99
|
-
return {
|
|
100
|
-
commandArgv: [],
|
|
101
|
-
topLevelHelp: true,
|
|
102
|
-
version: false,
|
|
103
|
-
...helpFilter !== undefined && { helpFilter }
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
if (token === "--version" || token === "version") {
|
|
107
|
-
return { commandArgv: [], topLevelHelp: false, version: true };
|
|
108
|
-
}
|
|
109
|
-
if (!token.startsWith("-") || token === "-") {
|
|
110
|
-
return {
|
|
111
|
-
command: token,
|
|
112
|
-
commandArgv: [...globals, ...argv.slice(index + 1)],
|
|
113
|
-
topLevelHelp: false,
|
|
114
|
-
version: false
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
if (!token.startsWith("--")) {
|
|
118
|
-
return {
|
|
119
|
-
command: defaultCommand,
|
|
120
|
-
commandArgv: [...globals, ...argv.slice(index)],
|
|
121
|
-
topLevelHelp: false,
|
|
122
|
-
version: false
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
const option = classifyLongOptionToken(token);
|
|
126
|
-
if (!option) {
|
|
127
|
-
return {
|
|
128
|
-
command: defaultCommand,
|
|
129
|
-
commandArgv: [...globals, ...argv.slice(index)],
|
|
130
|
-
topLevelHelp: false,
|
|
131
|
-
version: false
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
if (option.globalKind === "boolean") {
|
|
135
|
-
globals.push(token);
|
|
136
|
-
index += 1;
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if (option.globalKind === "value") {
|
|
140
|
-
globals.push(token);
|
|
141
|
-
if (!option.inline) {
|
|
142
|
-
const value = argv[index + 1];
|
|
143
|
-
if (value === "--help" || value === "-h") {
|
|
144
|
-
const helpFilter = helpFilterFrom(value, argv.slice(index + 2));
|
|
145
|
-
return {
|
|
146
|
-
commandArgv: [],
|
|
147
|
-
topLevelHelp: true,
|
|
148
|
-
version: false,
|
|
149
|
-
...helpFilter !== undefined && { helpFilter }
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
if (value === "--version" || value === "version") {
|
|
153
|
-
return { commandArgv: [], topLevelHelp: false, version: true };
|
|
154
|
-
}
|
|
155
|
-
if (value !== undefined)
|
|
156
|
-
globals.push(value);
|
|
157
|
-
index += value === undefined ? 1 : 2;
|
|
158
|
-
} else {
|
|
159
|
-
index += 1;
|
|
160
|
-
}
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
return {
|
|
164
|
-
command: defaultCommand,
|
|
165
|
-
commandArgv: [...globals, ...argv.slice(index)],
|
|
166
|
-
topLevelHelp: false,
|
|
167
|
-
version: false
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
return {
|
|
171
|
-
command: defaultCommand,
|
|
172
|
-
commandArgv: globals,
|
|
173
|
-
topLevelHelp: false,
|
|
174
|
-
version: false
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
class CliArgumentError extends Error {
|
|
179
|
-
name = "CliArgumentError";
|
|
180
|
-
}
|
|
181
|
-
function unwrap(field) {
|
|
182
|
-
if (field instanceof z.ZodOptional || field instanceof z.ZodNullable || field instanceof z.ZodDefault) {
|
|
183
|
-
return unwrap(field.unwrap());
|
|
184
|
-
}
|
|
185
|
-
return field;
|
|
186
|
-
}
|
|
187
|
-
function classify(field) {
|
|
188
|
-
if (field instanceof z.ZodBoolean)
|
|
189
|
-
return "boolean";
|
|
190
|
-
if (field instanceof z.ZodNumber)
|
|
191
|
-
return "number";
|
|
192
|
-
if (field instanceof z.ZodBigInt)
|
|
193
|
-
return "bigint";
|
|
194
|
-
if (field instanceof z.ZodDate)
|
|
195
|
-
return "date";
|
|
196
|
-
if (field instanceof z.ZodEnum)
|
|
197
|
-
return "enum";
|
|
198
|
-
if (field instanceof z.ZodArray)
|
|
199
|
-
return "array";
|
|
200
|
-
if (field instanceof z.ZodObject)
|
|
201
|
-
return "object";
|
|
202
|
-
if (field instanceof z.ZodString || field instanceof z.ZodLiteral)
|
|
203
|
-
return "string";
|
|
204
|
-
return "other";
|
|
205
|
-
}
|
|
206
|
-
function mergeField(fields, name, info) {
|
|
207
|
-
const existing = fields.get(name);
|
|
208
|
-
if (!existing) {
|
|
209
|
-
fields.set(name, info);
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
if (existing.kind === info.kind)
|
|
213
|
-
return;
|
|
214
|
-
if (existing.kind === "boolean" || info.kind === "boolean") {
|
|
215
|
-
fields.set(name, { kind: "boolean" });
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
fields.set(name, { kind: "other" });
|
|
219
|
-
}
|
|
220
|
-
function collectSchemaFields(schema, fields) {
|
|
221
|
-
const base = unwrap(schema);
|
|
222
|
-
if (base instanceof z.ZodObject) {
|
|
223
|
-
for (const [name, raw] of Object.entries(base.shape)) {
|
|
224
|
-
const fieldBase = unwrap(raw);
|
|
225
|
-
const kind = classify(fieldBase);
|
|
226
|
-
if (kind === "array" && fieldBase instanceof z.ZodArray) {
|
|
227
|
-
mergeField(fields, name, { kind, elementKind: classify(unwrap(fieldBase.element)) });
|
|
228
|
-
} else {
|
|
229
|
-
mergeField(fields, name, { kind });
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
if (base instanceof z.ZodUnion) {
|
|
235
|
-
for (const option of base.def.options)
|
|
236
|
-
collectSchemaFields(option, fields);
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
if (base instanceof z.ZodIntersection) {
|
|
240
|
-
collectSchemaFields(base.def.left, fields);
|
|
241
|
-
collectSchemaFields(base.def.right, fields);
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
function describeSchemaFields(schema) {
|
|
246
|
-
const fields = new Map;
|
|
247
|
-
if (schema)
|
|
248
|
-
collectSchemaFields(schema, fields);
|
|
249
|
-
return fields;
|
|
250
|
-
}
|
|
251
|
-
var TRUE_WORDS = new Set(["true", "1", "yes", "on"]);
|
|
252
|
-
var FALSE_WORDS = new Set(["false", "0", "no", "off"]);
|
|
253
|
-
function isReservedBoolWord(value) {
|
|
254
|
-
const word = value.toLowerCase();
|
|
255
|
-
return TRUE_WORDS.has(word) || FALSE_WORDS.has(word);
|
|
256
|
-
}
|
|
257
|
-
function parseReservedBool(name, value) {
|
|
258
|
-
const v = value.toLowerCase();
|
|
259
|
-
if (TRUE_WORDS.has(v))
|
|
260
|
-
return true;
|
|
261
|
-
if (FALSE_WORDS.has(v))
|
|
262
|
-
return false;
|
|
263
|
-
throw new CliArgumentError(`--${name} expects a boolean (true/false), got "${value}"`);
|
|
264
|
-
}
|
|
265
|
-
function coerceScalar(kind, value) {
|
|
266
|
-
switch (kind) {
|
|
267
|
-
case "boolean": {
|
|
268
|
-
const v = value.toLowerCase();
|
|
269
|
-
if (TRUE_WORDS.has(v))
|
|
270
|
-
return true;
|
|
271
|
-
if (FALSE_WORDS.has(v))
|
|
272
|
-
return false;
|
|
273
|
-
return value;
|
|
274
|
-
}
|
|
275
|
-
case "number": {
|
|
276
|
-
const n = Number(value);
|
|
277
|
-
return value.trim() !== "" && !Number.isNaN(n) ? n : value;
|
|
278
|
-
}
|
|
279
|
-
case "bigint":
|
|
280
|
-
try {
|
|
281
|
-
return BigInt(value);
|
|
282
|
-
} catch {
|
|
283
|
-
return value;
|
|
284
|
-
}
|
|
285
|
-
case "date": {
|
|
286
|
-
const d = new Date(value);
|
|
287
|
-
return Number.isNaN(d.getTime()) ? value : d;
|
|
288
|
-
}
|
|
289
|
-
default:
|
|
290
|
-
return value;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
function looseCoerce(value) {
|
|
294
|
-
if (value === "true")
|
|
295
|
-
return true;
|
|
296
|
-
if (value === "false")
|
|
297
|
-
return false;
|
|
298
|
-
const n = Number(value);
|
|
299
|
-
return value.trim() !== "" && !Number.isNaN(n) ? n : value;
|
|
300
|
-
}
|
|
301
|
-
function looksLikeJson(value) {
|
|
302
|
-
const t = value.trim();
|
|
303
|
-
return t.startsWith("[") || t.startsWith("{");
|
|
304
|
-
}
|
|
305
|
-
function coerceField(info, values) {
|
|
306
|
-
const last = values[values.length - 1] ?? "";
|
|
307
|
-
if (!info)
|
|
308
|
-
return values.length > 1 ? values : last;
|
|
309
|
-
if (info.kind === "array") {
|
|
310
|
-
if (values.length === 1 && looksLikeJson(last))
|
|
311
|
-
return last;
|
|
312
|
-
return values.map((v) => coerceScalar(info.elementKind ?? "string", v));
|
|
313
|
-
}
|
|
314
|
-
if (info.kind === "object")
|
|
315
|
-
return last;
|
|
316
|
-
return coerceScalar(info.kind, last);
|
|
317
|
-
}
|
|
318
|
-
function setNested(target, path, value) {
|
|
319
|
-
const unsafe = path.find(isUnsafeKey);
|
|
320
|
-
if (unsafe !== undefined) {
|
|
321
|
-
throw new CliArgumentError(`Unsafe option path segment "${unsafe}"`);
|
|
322
|
-
}
|
|
323
|
-
let node = target;
|
|
324
|
-
for (let i = 0;i < path.length - 1; i++) {
|
|
325
|
-
const key = path[i];
|
|
326
|
-
if (key === undefined)
|
|
327
|
-
return;
|
|
328
|
-
const next = node[key];
|
|
329
|
-
if (isRecord(next)) {
|
|
330
|
-
node = next;
|
|
331
|
-
} else {
|
|
332
|
-
const created = {};
|
|
333
|
-
node[key] = created;
|
|
334
|
-
node = created;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
const leaf = path[path.length - 1];
|
|
338
|
-
if (leaf !== undefined)
|
|
339
|
-
node[leaf] = value;
|
|
340
|
-
}
|
|
341
|
-
function parseCliArgs(argv, schema, config = {}) {
|
|
342
|
-
const options = {
|
|
343
|
-
json: false,
|
|
344
|
-
wait: false,
|
|
345
|
-
quiet: false,
|
|
346
|
-
dryRun: false,
|
|
347
|
-
help: false
|
|
348
|
-
};
|
|
349
|
-
const fields = describeSchemaFields(schema);
|
|
350
|
-
for (const name of config.knownFields ?? []) {
|
|
351
|
-
if (!fields.has(name))
|
|
352
|
-
fields.set(name, { kind: "other" });
|
|
353
|
-
}
|
|
354
|
-
const flags = new Map;
|
|
355
|
-
const boolFlags = new Map;
|
|
356
|
-
const viewFlags = new Map;
|
|
357
|
-
let ascending = false;
|
|
358
|
-
const positionals = [];
|
|
359
|
-
const pushFlag = (name, value) => {
|
|
360
|
-
const existing = flags.get(name);
|
|
361
|
-
if (existing)
|
|
362
|
-
existing.push(value);
|
|
363
|
-
else
|
|
364
|
-
flags.set(name, [value]);
|
|
365
|
-
};
|
|
366
|
-
let optionsEnded = false;
|
|
367
|
-
for (let i = 0;i < argv.length; i++) {
|
|
368
|
-
const tok = argv[i];
|
|
369
|
-
if (tok === undefined)
|
|
370
|
-
continue;
|
|
371
|
-
if (!optionsEnded && tok === "--") {
|
|
372
|
-
optionsEnded = true;
|
|
373
|
-
continue;
|
|
374
|
-
}
|
|
375
|
-
if (optionsEnded || !tok.startsWith("-") || tok === "-") {
|
|
376
|
-
positionals.push(tok);
|
|
377
|
-
continue;
|
|
378
|
-
}
|
|
379
|
-
if (tok === "-h") {
|
|
380
|
-
options.help = true;
|
|
381
|
-
continue;
|
|
382
|
-
}
|
|
383
|
-
if (!tok.startsWith("--")) {
|
|
384
|
-
const match = /^-([A-Za-z])(?:=(.*))?$/.exec(tok);
|
|
385
|
-
const alias = match?.[1];
|
|
386
|
-
const field = alias === undefined ? undefined : config.optionAliases?.get(alias);
|
|
387
|
-
if (!alias || !field)
|
|
388
|
-
throw new CliArgumentError(`Unknown option "${tok}"`);
|
|
389
|
-
const inline = match?.[2];
|
|
390
|
-
const info2 = fields.get(field);
|
|
391
|
-
if (info2?.kind === "boolean") {
|
|
392
|
-
boolFlags.set(field, inline === undefined ? true : parseReservedBool(field, inline));
|
|
393
|
-
continue;
|
|
394
|
-
}
|
|
395
|
-
let value2 = inline;
|
|
396
|
-
if (value2 === undefined) {
|
|
397
|
-
const next = argv[i + 1];
|
|
398
|
-
if (next !== undefined && (!next.startsWith("-") || NUMERIC_VALUE.test(next))) {
|
|
399
|
-
value2 = next;
|
|
400
|
-
i++;
|
|
401
|
-
} else {
|
|
402
|
-
throw new CliArgumentError(`--${field} requires a value`);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
pushFlag(field, value2);
|
|
406
|
-
continue;
|
|
407
|
-
}
|
|
408
|
-
const option = classifyLongOptionToken(tok);
|
|
409
|
-
if (!option)
|
|
410
|
-
throw new CliArgumentError(`Unknown option "${tok}"`);
|
|
411
|
-
const { name } = option;
|
|
412
|
-
let { value } = option;
|
|
413
|
-
if (name.length === 0)
|
|
414
|
-
throw new CliArgumentError("Invalid empty option name");
|
|
415
|
-
if (option.globalKind === "boolean") {
|
|
416
|
-
const enabled = value === undefined ? true : parseReservedBool(name, value);
|
|
417
|
-
if (name === "dry-run")
|
|
418
|
-
options.dryRun = enabled;
|
|
419
|
-
else if (name === "json")
|
|
420
|
-
options.json = enabled;
|
|
421
|
-
else if (name === "wait")
|
|
422
|
-
options.wait = enabled;
|
|
423
|
-
else if (name === "quiet")
|
|
424
|
-
options.quiet = enabled;
|
|
425
|
-
else if (name === "ascending")
|
|
426
|
-
ascending = enabled;
|
|
427
|
-
else
|
|
428
|
-
options.help = enabled;
|
|
429
|
-
continue;
|
|
430
|
-
}
|
|
431
|
-
if (option.globalKind === "value") {
|
|
432
|
-
const next = argv[i + 1];
|
|
433
|
-
value = value ?? next;
|
|
434
|
-
if (value === undefined || value.startsWith("-") && !NUMERIC_VALUE.test(value)) {
|
|
435
|
-
throw new CliArgumentError(`--${name} requires a value`);
|
|
436
|
-
}
|
|
437
|
-
if (!option.inline)
|
|
438
|
-
i++;
|
|
439
|
-
if (name === "wait-timeout") {
|
|
440
|
-
const timeout = Number(value);
|
|
441
|
-
if (!Number.isFinite(timeout) || timeout <= 0) {
|
|
442
|
-
throw new CliArgumentError("--wait-timeout must be a positive number");
|
|
443
|
-
}
|
|
444
|
-
options.waitTimeout = timeout;
|
|
445
|
-
} else if (VIEW_OPTIONS.has(name)) {
|
|
446
|
-
if (viewFlags.has(name))
|
|
447
|
-
throw new CliArgumentError(`--${name} was given twice`);
|
|
448
|
-
viewFlags.set(name, value);
|
|
449
|
-
} else {
|
|
450
|
-
options.outputDir = value;
|
|
451
|
-
}
|
|
452
|
-
continue;
|
|
453
|
-
}
|
|
454
|
-
if (value === undefined && name.startsWith("no-") && fields.get(name.slice(3))?.kind === "boolean") {
|
|
455
|
-
boolFlags.set(name.slice(3), false);
|
|
456
|
-
continue;
|
|
457
|
-
}
|
|
458
|
-
const unsafeSegment = name.split(".").find(isUnsafeKey);
|
|
459
|
-
if (unsafeSegment !== undefined) {
|
|
460
|
-
throw new CliArgumentError(`Unsafe option name "--${name}"`);
|
|
461
|
-
}
|
|
462
|
-
const info = fields.get(name);
|
|
463
|
-
const rootName = name.split(".")[0] ?? name;
|
|
464
|
-
if (!fields.has(rootName) && !config.allowUnknown) {
|
|
465
|
-
throw new CliArgumentError(`Unknown option "--${name}"`);
|
|
466
|
-
}
|
|
467
|
-
if (value === undefined) {
|
|
468
|
-
if (info?.kind === "boolean") {
|
|
469
|
-
boolFlags.set(name, true);
|
|
470
|
-
continue;
|
|
471
|
-
}
|
|
472
|
-
const next = argv[i + 1];
|
|
473
|
-
if (next !== undefined && (!next.startsWith("-") || NUMERIC_VALUE.test(next))) {
|
|
474
|
-
value = next;
|
|
475
|
-
i++;
|
|
476
|
-
} else {
|
|
477
|
-
throw new CliArgumentError(`--${name} requires a value`);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
pushFlag(name, value);
|
|
481
|
-
}
|
|
482
|
-
const view = resolveCliView(viewFlags, ascending);
|
|
483
|
-
if (view)
|
|
484
|
-
options.view = view;
|
|
485
|
-
const toolArgs = {};
|
|
486
|
-
const fillable = config.positionals === undefined ? [...fields.entries()].filter(([, info]) => info.kind !== "boolean").map(([name]) => name) : [...config.positionals];
|
|
487
|
-
const variadicTail = config.positionals !== undefined && fields.get(fillable[fillable.length - 1] ?? "")?.kind === "array" ? fillable[fillable.length - 1] : undefined;
|
|
488
|
-
let pi = 0;
|
|
489
|
-
for (const key of fillable) {
|
|
490
|
-
if (pi >= positionals.length)
|
|
491
|
-
break;
|
|
492
|
-
if (key === variadicTail) {
|
|
493
|
-
if (flags.has(key)) {
|
|
494
|
-
throw new CliArgumentError(`--${key} conflicts with the positional values for "${key}" — pass one form, not both`);
|
|
495
|
-
}
|
|
496
|
-
toolArgs[key] = coerceField(fields.get(key), positionals.slice(pi));
|
|
497
|
-
pi = positionals.length;
|
|
498
|
-
break;
|
|
499
|
-
}
|
|
500
|
-
if (flags.has(key))
|
|
501
|
-
continue;
|
|
502
|
-
const value = positionals[pi++];
|
|
503
|
-
if (value !== undefined)
|
|
504
|
-
toolArgs[key] = coerceField(fields.get(key), [value]);
|
|
505
|
-
}
|
|
506
|
-
if (pi < positionals.length) {
|
|
507
|
-
throw new CliArgumentError(`Unexpected positional argument "${positionals[pi]}"`);
|
|
508
|
-
}
|
|
509
|
-
for (const [key, value] of boolFlags) {
|
|
510
|
-
toolArgs[key] = value;
|
|
511
|
-
}
|
|
512
|
-
const dottedRoots = new Map;
|
|
513
|
-
for (const key of flags.keys()) {
|
|
514
|
-
const dot = key.indexOf(".");
|
|
515
|
-
if (dot > 0)
|
|
516
|
-
dottedRoots.set(key.slice(0, dot), key);
|
|
517
|
-
}
|
|
518
|
-
for (const [root, dotted] of dottedRoots) {
|
|
519
|
-
if (flags.has(root)) {
|
|
520
|
-
throw new CliArgumentError(`--${root} conflicts with --${dotted} — pass one form, not both`);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
for (const [key, values] of flags) {
|
|
524
|
-
if (key.includes(".")) {
|
|
525
|
-
if (values.length > 1) {
|
|
526
|
-
throw new CliArgumentError(`--${key} was passed ${values.length} times`);
|
|
527
|
-
}
|
|
528
|
-
setNested(toolArgs, key.split("."), looseCoerce(values[0] ?? ""));
|
|
529
|
-
continue;
|
|
530
|
-
}
|
|
531
|
-
const info = fields.get(key);
|
|
532
|
-
if (values.length > 1 && info !== undefined && info.kind !== "array" && info.kind !== "other") {
|
|
533
|
-
throw new CliArgumentError(`--${key} was passed ${values.length} times`);
|
|
534
|
-
}
|
|
535
|
-
toolArgs[key] = coerceField(info, values);
|
|
536
|
-
}
|
|
537
|
-
return { toolArgs, options };
|
|
538
|
-
}
|
|
539
|
-
function extractCliGlobalOptions(argv, schema) {
|
|
540
|
-
if (schema === undefined)
|
|
541
|
-
return { argv: [...argv], globals: {} };
|
|
542
|
-
const fields = describeSchemaFields(schema);
|
|
543
|
-
const rest = [];
|
|
544
|
-
const raw = new Map;
|
|
545
|
-
let ended = false;
|
|
546
|
-
for (let i = 0;i < argv.length; i++) {
|
|
547
|
-
const token = argv[i];
|
|
548
|
-
if (token === undefined)
|
|
549
|
-
continue;
|
|
550
|
-
if (!ended && token === "--")
|
|
551
|
-
ended = true;
|
|
552
|
-
const option = ended ? undefined : classifyLongOptionToken(token);
|
|
553
|
-
const info = option && option.globalKind === undefined ? fields.get(option.name) : undefined;
|
|
554
|
-
if (!option || !info) {
|
|
555
|
-
rest.push(token);
|
|
556
|
-
continue;
|
|
557
|
-
}
|
|
558
|
-
let { value } = option;
|
|
559
|
-
if (value === undefined && info.kind === "boolean") {
|
|
560
|
-
value = "true";
|
|
561
|
-
} else if (value === undefined) {
|
|
562
|
-
const next = argv[i + 1];
|
|
563
|
-
if (next !== undefined && (!next.startsWith("-") || NUMERIC_VALUE.test(next))) {
|
|
564
|
-
value = next;
|
|
565
|
-
i++;
|
|
566
|
-
} else {
|
|
567
|
-
throw new CliArgumentError(`--${option.name} requires a value`);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
const existing = raw.get(option.name);
|
|
571
|
-
if (existing)
|
|
572
|
-
existing.push(value);
|
|
573
|
-
else
|
|
574
|
-
raw.set(option.name, [value]);
|
|
575
|
-
}
|
|
576
|
-
const args = {};
|
|
577
|
-
for (const [name, values] of raw)
|
|
578
|
-
args[name] = coerceField(fields.get(name), values);
|
|
579
|
-
const parsed = schema.safeParse(coerceJsonArgs(args, schema));
|
|
580
|
-
if (!parsed.success) {
|
|
581
|
-
const issue = parsed.error.issues[0];
|
|
582
|
-
const field = issue?.path[0];
|
|
583
|
-
const where = typeof field === "string" ? `--${field}` : "application option";
|
|
584
|
-
throw new CliArgumentError(`${where}: ${issue?.message ?? "invalid value"}`);
|
|
585
|
-
}
|
|
586
|
-
return { argv: rest, globals: parsed.data };
|
|
587
|
-
}
|
|
588
|
-
function resolveCliView(flags, ascending) {
|
|
589
|
-
if (flags.size === 0) {
|
|
590
|
-
if (ascending) {
|
|
591
|
-
throw new CliArgumentError("--ascending orders a record view; pass --sort with it");
|
|
592
|
-
}
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
const countBy = flags.get("count-by");
|
|
596
|
-
const sum = flags.get("sum");
|
|
597
|
-
const table = flags.get("table");
|
|
598
|
-
const by = flags.get("by");
|
|
599
|
-
const rawTop = flags.get("top");
|
|
600
|
-
const named = [
|
|
601
|
-
["--count-by", countBy],
|
|
602
|
-
["--sum", sum]
|
|
603
|
-
].filter(([, value]) => value !== undefined);
|
|
604
|
-
if (named.length > 1) {
|
|
605
|
-
throw new CliArgumentError(`${named.map(([flag]) => flag).join(" and ")} ask for different shapes — pass one`);
|
|
606
|
-
}
|
|
607
|
-
let top;
|
|
608
|
-
if (rawTop !== undefined) {
|
|
609
|
-
top = Number(rawTop);
|
|
610
|
-
if (!Number.isInteger(top) || top <= 0) {
|
|
611
|
-
throw new CliArgumentError("--top must be a positive whole number");
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
const sort = flags.get("sort");
|
|
615
|
-
if (table !== undefined || sort !== undefined) {
|
|
616
|
-
if (countBy !== undefined || sum !== undefined) {
|
|
617
|
-
throw new CliArgumentError(`${table !== undefined ? "--table" : "--sort"} lists records; --count-by and --sum aggregate them — pass one`);
|
|
618
|
-
}
|
|
619
|
-
if (by !== undefined) {
|
|
620
|
-
throw new CliArgumentError("--by groups a view; a record view orders with --sort");
|
|
621
|
-
}
|
|
622
|
-
if (top !== undefined && sort === undefined) {
|
|
623
|
-
throw new CliArgumentError("--top needs --sort here: unordered records have no n largest");
|
|
624
|
-
}
|
|
625
|
-
let fields;
|
|
626
|
-
if (table !== undefined) {
|
|
627
|
-
fields = table.split(",").map((field) => field.trim()).filter(Boolean);
|
|
628
|
-
if (fields.length === 0)
|
|
629
|
-
throw new CliArgumentError("--table needs at least one field");
|
|
630
|
-
}
|
|
631
|
-
return {
|
|
632
|
-
kind: "records",
|
|
633
|
-
...sort !== undefined && { sort },
|
|
634
|
-
...ascending && { ascending },
|
|
635
|
-
...top !== undefined && { top },
|
|
636
|
-
...fields && { table: fields }
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
if (ascending) {
|
|
640
|
-
throw new CliArgumentError("--ascending orders a record view; pass --sort with it");
|
|
641
|
-
}
|
|
642
|
-
if (sum !== undefined) {
|
|
643
|
-
if (top !== undefined && by === undefined) {
|
|
644
|
-
throw new CliArgumentError("--top needs --by: a single sum has nothing to rank");
|
|
645
|
-
}
|
|
646
|
-
return {
|
|
647
|
-
kind: "sum",
|
|
648
|
-
field: sum,
|
|
649
|
-
...by !== undefined && { by },
|
|
650
|
-
...top !== undefined && { top }
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
if (countBy !== undefined) {
|
|
654
|
-
if (by !== undefined) {
|
|
655
|
-
throw new CliArgumentError("--count-by already names the grouping field; drop --by");
|
|
656
|
-
}
|
|
657
|
-
return { kind: "count", field: countBy, ...top !== undefined && { top } };
|
|
658
|
-
}
|
|
659
|
-
if (by !== undefined) {
|
|
660
|
-
if (top === undefined) {
|
|
661
|
-
throw new CliArgumentError("--by groups a view; pass --count-by, --sum or --top with it");
|
|
662
|
-
}
|
|
663
|
-
return { kind: "count", field: by, top };
|
|
664
|
-
}
|
|
665
|
-
throw new CliArgumentError("--top needs --sort, --by, --count-by or --sum to rank");
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
// src/tools/cli-command.ts
|
|
669
|
-
function defineCliCommand(definition) {
|
|
670
|
-
return definition;
|
|
671
|
-
}
|
|
672
|
-
function cliCommandReturnsResult(definition) {
|
|
673
|
-
return definition.output !== undefined;
|
|
674
|
-
}
|
|
675
|
-
function cliCommandSuccessExitCode(definition, data) {
|
|
676
|
-
const successExitCode = definition.exitCode?.(data) ?? 0;
|
|
677
|
-
if (!Number.isSafeInteger(successExitCode) || successExitCode < 0 || successExitCode > 255) {
|
|
678
|
-
throw new Error("CLI success exit code must be an integer from 0 to 255");
|
|
679
|
-
}
|
|
680
|
-
return successExitCode;
|
|
681
|
-
}
|
|
682
|
-
function prepareCliCommandEmission(definition, result, options) {
|
|
683
|
-
if (!result.ok || definition.output === undefined) {
|
|
684
|
-
return { result, successExitCode: 0 };
|
|
685
|
-
}
|
|
686
|
-
try {
|
|
687
|
-
const successExitCode = cliCommandSuccessExitCode(definition, result.data);
|
|
688
|
-
const presentation = definition.present?.({ result: result.data, options });
|
|
689
|
-
if (presentation !== undefined && typeof presentation !== "string") {
|
|
690
|
-
throw new Error("CLI result presenter must return a string");
|
|
691
|
-
}
|
|
692
|
-
return { result, presentation, successExitCode };
|
|
693
|
-
} catch (error) {
|
|
694
|
-
return {
|
|
695
|
-
result: toolResultFromError(new Error("CLI result policy failed", { cause: error })),
|
|
696
|
-
successExitCode: 0
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
function cliCommandPresentationSchema(definition) {
|
|
701
|
-
return buildToolPresentationSchema({
|
|
702
|
-
inputSchema: definition.input,
|
|
703
|
-
unrepresentable: "any"
|
|
704
|
-
});
|
|
705
|
-
}
|
|
706
|
-
async function executeCliCommand(definition, rawArgs, options, writers, coerceJson, globals = {}) {
|
|
707
|
-
let parsed;
|
|
708
|
-
try {
|
|
709
|
-
parsed = definition.input.safeParse(coerceJson ? coerceJsonArgs(rawArgs, definition.input) : rawArgs);
|
|
710
|
-
} catch (error) {
|
|
711
|
-
return toolResultFromError(error);
|
|
712
|
-
}
|
|
713
|
-
if (!parsed.success) {
|
|
714
|
-
return {
|
|
715
|
-
ok: false,
|
|
716
|
-
code: "VALIDATION_ERROR",
|
|
717
|
-
details: { message: `Invalid input: ${formatZodError(parsed.error)}` }
|
|
718
|
-
};
|
|
719
|
-
}
|
|
720
|
-
try {
|
|
721
|
-
const data = await definition.handler({
|
|
722
|
-
input: parsed.data,
|
|
723
|
-
options,
|
|
724
|
-
globals,
|
|
725
|
-
...writers
|
|
726
|
-
});
|
|
727
|
-
const checked = validateDeclaredOutput(definition.output, data);
|
|
728
|
-
if (!checked.ok) {
|
|
729
|
-
return {
|
|
730
|
-
ok: false,
|
|
731
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
732
|
-
details: { message: checked.message }
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
return { ok: true, data: checked.data };
|
|
736
|
-
} catch (error) {
|
|
737
|
-
return toolResultFromError(error);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
// src/tools/cli-format.ts
|
|
742
|
-
var DEFAULT_EXIT_CODES = {
|
|
743
|
-
VALIDATION_ERROR: 1,
|
|
744
|
-
BAD_REQUEST: 1,
|
|
745
|
-
UNAUTHORIZED: 2,
|
|
746
|
-
FORBIDDEN: 3,
|
|
747
|
-
NOT_FOUND: 4,
|
|
748
|
-
CONFLICT: 5,
|
|
749
|
-
RATE_LIMITED: 6,
|
|
750
|
-
TIMEOUT: 7,
|
|
751
|
-
WAIT_FAILED: 1,
|
|
752
|
-
INTERNAL_SERVER_ERROR: 1
|
|
753
|
-
};
|
|
754
|
-
function cliExitCode(result, exitCodes) {
|
|
755
|
-
if (result.ok)
|
|
756
|
-
return 0;
|
|
757
|
-
const codes = { ...DEFAULT_EXIT_CODES, ...exitCodes };
|
|
758
|
-
return Object.hasOwn(codes, result.code) ? codes[result.code] ?? 1 : 1;
|
|
759
|
-
}
|
|
760
|
-
function emitResult(result, writers, opts) {
|
|
761
|
-
if (result.ok) {
|
|
762
|
-
if (result.data === undefined)
|
|
763
|
-
return 0;
|
|
764
|
-
const text2 = opts.json ? JSON.stringify(result.data) : JSON.stringify(result.data, null, 2);
|
|
765
|
-
writers.stdout(`${text2}
|
|
766
|
-
`);
|
|
767
|
-
return 0;
|
|
768
|
-
}
|
|
769
|
-
const error = formatToolError(result, opts.toolName, opts.errorHint);
|
|
770
|
-
const text = opts.json ? JSON.stringify(error) : JSON.stringify(error, null, 2);
|
|
771
|
-
writers.stderr(`${text}
|
|
772
|
-
`);
|
|
773
|
-
return cliExitCode(result, opts.exitCodes);
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
// src/tools/cli-policy.ts
|
|
777
|
-
var SHORT_ALIAS = /^[A-Za-z]$/;
|
|
778
|
-
var RESERVED_SHORT_OPTIONS = new Set(["h"]);
|
|
779
|
-
function fieldMap(descriptor) {
|
|
780
|
-
return new Map(jsonSchemaFields(descriptor.presentationSchema).map((field) => [field.name, field]));
|
|
781
|
-
}
|
|
782
|
-
function resolveAliases(command, descriptor, configured) {
|
|
783
|
-
if (!configured)
|
|
784
|
-
return new Map;
|
|
785
|
-
const fields = fieldMap(descriptor);
|
|
786
|
-
const aliases = new Map;
|
|
787
|
-
for (const [alias, target] of Object.entries(configured)) {
|
|
788
|
-
if (!SHORT_ALIAS.test(alias)) {
|
|
789
|
-
throw new Error(`[stitchkit] CLI command "${command}" alias "${alias}" must be one ASCII letter`);
|
|
790
|
-
}
|
|
791
|
-
if (RESERVED_SHORT_OPTIONS.has(alias)) {
|
|
792
|
-
throw new Error(`[stitchkit] CLI command "${command}" alias "-${alias}" is reserved`);
|
|
793
|
-
}
|
|
794
|
-
if (isUnsafeKey(target) || !fields.has(target)) {
|
|
795
|
-
throw new Error(`[stitchkit] CLI command "${command}" alias "-${alias}" targets unknown field "${target}"`);
|
|
796
|
-
}
|
|
797
|
-
const existing = aliases.get(target);
|
|
798
|
-
if (existing !== undefined) {
|
|
799
|
-
throw new Error(`[stitchkit] CLI command "${command}" field "${target}" has multiple aliases: -${existing}, -${alias}`);
|
|
800
|
-
}
|
|
801
|
-
aliases.set(target, alias);
|
|
802
|
-
}
|
|
803
|
-
return aliases;
|
|
804
|
-
}
|
|
805
|
-
function resolvePositionals(command, descriptor, configured) {
|
|
806
|
-
if (configured === undefined)
|
|
807
|
-
return;
|
|
808
|
-
const fields = fieldMap(descriptor);
|
|
809
|
-
const kinds = describeSchemaFields(descriptor.argumentSchema);
|
|
810
|
-
const seen = new Set;
|
|
811
|
-
let optionalSeen = false;
|
|
812
|
-
for (const name of configured) {
|
|
813
|
-
const field = fields.get(name);
|
|
814
|
-
if (isUnsafeKey(name) || !field || !kinds.has(name)) {
|
|
815
|
-
throw new Error(`[stitchkit] CLI command "${command}" positional targets unknown field "${name}"`);
|
|
816
|
-
}
|
|
817
|
-
if (seen.has(name)) {
|
|
818
|
-
throw new Error(`[stitchkit] CLI command "${command}" repeats positional field "${name}"`);
|
|
819
|
-
}
|
|
820
|
-
if (kinds.get(name)?.kind === "boolean") {
|
|
821
|
-
throw new Error(`[stitchkit] CLI command "${command}" boolean field "${name}" cannot be positional`);
|
|
822
|
-
}
|
|
823
|
-
if (optionalSeen && field.required) {
|
|
824
|
-
throw new Error(`[stitchkit] CLI command "${command}" required positional "${name}" cannot follow an optional positional`);
|
|
825
|
-
}
|
|
826
|
-
if (!field.required)
|
|
827
|
-
optionalSeen = true;
|
|
828
|
-
seen.add(name);
|
|
829
|
-
}
|
|
830
|
-
return [...configured];
|
|
831
|
-
}
|
|
832
|
-
function applyCliPresentationPolicy(command, descriptor, config) {
|
|
833
|
-
const base = { ...descriptor, aliases: new Map };
|
|
834
|
-
const configuredAliases = config.optionAliases && Object.hasOwn(config.optionAliases, command) ? config.optionAliases[command] : undefined;
|
|
835
|
-
const configuredPositionals = config.positionals && Object.hasOwn(config.positionals, command) ? config.positionals[command] : undefined;
|
|
836
|
-
return {
|
|
837
|
-
...base,
|
|
838
|
-
aliases: resolveAliases(command, base, configuredAliases),
|
|
839
|
-
positionals: resolvePositionals(command, base, configuredPositionals)
|
|
840
|
-
};
|
|
841
|
-
}
|
|
842
|
-
function assertCliPoliciesResolved(commands, config) {
|
|
843
|
-
const configuredNames = new Set([
|
|
844
|
-
...Object.keys(config.optionAliases ?? {}),
|
|
845
|
-
...Object.keys(config.positionals ?? {})
|
|
846
|
-
]);
|
|
847
|
-
if (config.defaultCommand !== undefined)
|
|
848
|
-
configuredNames.add(config.defaultCommand);
|
|
849
|
-
for (const name of configuredNames) {
|
|
850
|
-
if (!commands.has(name)) {
|
|
851
|
-
throw new Error(`[stitchkit] CLI policy targets unavailable command "${name}"`);
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
// src/tools/cli-invoke.ts
|
|
857
|
-
function parseCliGlobals(schema, globals) {
|
|
858
|
-
if (!schema)
|
|
859
|
-
return globals ?? {};
|
|
860
|
-
return schema.parse(globals ?? {});
|
|
861
|
-
}
|
|
862
|
-
function cliInvocationResult(result, toolName, config) {
|
|
863
|
-
if (result.ok)
|
|
864
|
-
return { ok: true, exitCode: 0, data: result.data };
|
|
865
|
-
const normalized = toolErrorFromResult(result);
|
|
866
|
-
const hints = [];
|
|
867
|
-
if (result.hint)
|
|
868
|
-
hints.push(result.hint);
|
|
869
|
-
const global = config.errorHint?.(toolName, result.code);
|
|
870
|
-
if (global)
|
|
871
|
-
hints.push(global);
|
|
872
|
-
return {
|
|
873
|
-
ok: false,
|
|
874
|
-
exitCode: cliExitCode(result, config.exitCodes),
|
|
875
|
-
error: {
|
|
876
|
-
code: result.code,
|
|
877
|
-
message: normalized.message,
|
|
878
|
-
...result.details !== undefined && { details: result.details },
|
|
879
|
-
...hints.length > 0 && { hint: hints.join(" ") },
|
|
880
|
-
...result.retryable !== undefined && { retryable: result.retryable }
|
|
881
|
-
}
|
|
882
|
-
};
|
|
883
|
-
}
|
|
884
|
-
async function createCliInvoker(config, globals) {
|
|
885
|
-
const typedGlobals = parseCliGlobals(config.globalOptions, globals);
|
|
886
|
-
const auth = await (config.resolveAuth ? config.resolveAuth(typedGlobals) : config.auth);
|
|
887
|
-
const natives = new Map((config.commands ?? []).filter(cliCommandReturnsResult).map((definition) => [definition.name, definition]));
|
|
888
|
-
const nativeHelp = new Map([...natives].map(([name, definition]) => [
|
|
889
|
-
name,
|
|
890
|
-
{ description: definition.description, argumentSchema: {}, presentationSchema: {} }
|
|
891
|
-
]));
|
|
892
|
-
const { tools, help } = buildCliSurface(config, auth, new Map, new Set);
|
|
893
|
-
const runTool = createToolRunner({
|
|
894
|
-
source: "cli",
|
|
895
|
-
context: { ...config.context?.(auth, typedGlobals), signal: config.signal },
|
|
896
|
-
hooks: config.hooks,
|
|
897
|
-
lifecycle: config.lifecycle,
|
|
898
|
-
errorHint: config.errorHint,
|
|
899
|
-
coerceJsonArgs: config.coerceJsonArgs
|
|
900
|
-
});
|
|
901
|
-
return {
|
|
902
|
-
commands: [...nativeHelp, ...help].map(([name, presentation]) => ({
|
|
903
|
-
name,
|
|
904
|
-
description: presentation.description
|
|
905
|
-
})),
|
|
906
|
-
invoke: async (command, args) => {
|
|
907
|
-
const native = natives.get(command);
|
|
908
|
-
if (native)
|
|
909
|
-
return runNativeCommand(native, args, config, typedGlobals);
|
|
910
|
-
const tool = tools.get(command);
|
|
911
|
-
if (!tool) {
|
|
912
|
-
return cliInvocationResult({
|
|
913
|
-
ok: false,
|
|
914
|
-
code: "NOT_FOUND",
|
|
915
|
-
details: { message: `Unknown command "${command}"` }
|
|
916
|
-
}, command, config);
|
|
917
|
-
}
|
|
918
|
-
let result;
|
|
919
|
-
try {
|
|
920
|
-
result = await runTool(tool, args);
|
|
921
|
-
} catch (error) {
|
|
922
|
-
result = toolResultFromError(error);
|
|
923
|
-
}
|
|
924
|
-
return cliInvocationResult(result, command, config);
|
|
925
|
-
}
|
|
926
|
-
};
|
|
927
|
-
}
|
|
928
|
-
var IN_PROCESS_RUN_OPTIONS = Object.freeze({
|
|
929
|
-
json: false,
|
|
930
|
-
wait: false,
|
|
931
|
-
quiet: true,
|
|
932
|
-
dryRun: false,
|
|
933
|
-
help: false
|
|
934
|
-
});
|
|
935
|
-
async function runNativeCommand(definition, args, config, globals) {
|
|
936
|
-
let out = "";
|
|
937
|
-
let err = "";
|
|
938
|
-
const result = await executeCliCommand(definition, args, IN_PROCESS_RUN_OPTIONS, {
|
|
939
|
-
stdout: (text) => {
|
|
940
|
-
out += text;
|
|
941
|
-
},
|
|
942
|
-
stderr: (text) => {
|
|
943
|
-
err += text;
|
|
944
|
-
}
|
|
945
|
-
}, config.coerceJsonArgs ?? true, globals);
|
|
946
|
-
let invocation = cliInvocationResult(result, definition.name, config);
|
|
947
|
-
if (invocation.ok) {
|
|
948
|
-
try {
|
|
949
|
-
invocation = {
|
|
950
|
-
...invocation,
|
|
951
|
-
exitCode: cliCommandSuccessExitCode(definition, result.ok ? result.data : undefined)
|
|
952
|
-
};
|
|
953
|
-
} catch (error) {
|
|
954
|
-
invocation = cliInvocationResult(toolResultFromError(error), definition.name, config);
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
if (out === "" && err === "")
|
|
958
|
-
return invocation;
|
|
959
|
-
return {
|
|
960
|
-
...invocation,
|
|
961
|
-
written: { ...out !== "" && { stdout: out }, ...err !== "" && { stderr: err } }
|
|
962
|
-
};
|
|
963
|
-
}
|
|
964
|
-
function buildCliSurface(config, auth, nativeHelp, applicationGlobalNames, assertShape) {
|
|
965
|
-
const services = typeof config.services === "function" ? config.services(auth) : config.services ?? [];
|
|
966
|
-
const runtimeTools = typeof config.runtimeTools === "function" ? config.runtimeTools(auth) : config.runtimeTools ?? [];
|
|
967
|
-
const tools = new Map;
|
|
968
|
-
const help = new Map(nativeHelp);
|
|
969
|
-
for (const { mountable } of collectToolSurface({
|
|
970
|
-
surface: { services, runtimeTools },
|
|
971
|
-
transport: "CLI"
|
|
972
|
-
})) {
|
|
973
|
-
const descriptor = applyCliPresentationPolicy(mountable.name, managedCliDescriptor(mountable), config);
|
|
974
|
-
assertShape?.(mountable.name, descriptor, help.has(mountable.name), config.passthrough?.[mountable.name], applicationGlobalNames);
|
|
975
|
-
tools.set(mountable.name, mountable);
|
|
976
|
-
help.set(mountable.name, descriptor);
|
|
977
|
-
}
|
|
978
|
-
assertCliPoliciesResolved(help, config);
|
|
979
|
-
return { tools, help };
|
|
980
|
-
}
|
|
981
|
-
function managedCliDescriptor(tool) {
|
|
982
|
-
return {
|
|
983
|
-
description: tool.method.desc,
|
|
984
|
-
argumentSchema: tool.argumentSchema,
|
|
985
|
-
presentationSchema: tool.presentationSchema
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
// src/tools/cli-view.ts
|
|
990
|
-
var ABSENT = "(absent)";
|
|
991
|
-
function selectRecords(data) {
|
|
992
|
-
if (Array.isArray(data))
|
|
993
|
-
return data;
|
|
994
|
-
if (isRecord(data)) {
|
|
995
|
-
const arrays = Object.entries(data).filter(([, value]) => Array.isArray(value));
|
|
996
|
-
const only = arrays[0];
|
|
997
|
-
if (arrays.length === 1 && only && Array.isArray(only[1]))
|
|
998
|
-
return only[1];
|
|
999
|
-
if (arrays.length > 1) {
|
|
1000
|
-
throw new CliArgumentError(`an aggregate needs one collection, but the result carries several: ${arrays.map(([key]) => key).join(", ")} — name the shape you want with jq instead`);
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
throw new CliArgumentError("an aggregate needs a collection; this result is not one");
|
|
1004
|
-
}
|
|
1005
|
-
function readField(record, path) {
|
|
1006
|
-
let current = record;
|
|
1007
|
-
for (const segment of path) {
|
|
1008
|
-
if (!isRecord(current))
|
|
1009
|
-
return;
|
|
1010
|
-
current = current[segment];
|
|
1011
|
-
}
|
|
1012
|
-
return current;
|
|
1013
|
-
}
|
|
1014
|
-
function fieldPath(field) {
|
|
1015
|
-
const path = field.split(".");
|
|
1016
|
-
if (path.some((segment) => segment.length === 0 || isUnsafeKey(segment))) {
|
|
1017
|
-
throw new CliArgumentError(`"${field}" is not a readable field path`);
|
|
1018
|
-
}
|
|
1019
|
-
return path;
|
|
1020
|
-
}
|
|
1021
|
-
function availableFields(records) {
|
|
1022
|
-
const keys = new Set;
|
|
1023
|
-
for (const record of records) {
|
|
1024
|
-
if (isRecord(record))
|
|
1025
|
-
for (const key of Object.keys(record))
|
|
1026
|
-
keys.add(key);
|
|
1027
|
-
}
|
|
1028
|
-
return [...keys].sort();
|
|
1029
|
-
}
|
|
1030
|
-
function assertFieldPresent(records, field) {
|
|
1031
|
-
const path = fieldPath(field);
|
|
1032
|
-
const present = records.some((record) => readField(record, path) !== undefined);
|
|
1033
|
-
if (!present) {
|
|
1034
|
-
const available = availableFields(records);
|
|
1035
|
-
throw new CliArgumentError(`no record carries the field "${field}"${available.length > 0 ? ` — available: ${available.join(", ")}` : ""}`);
|
|
1036
|
-
}
|
|
1037
|
-
return path;
|
|
1038
|
-
}
|
|
1039
|
-
function groupKey(value) {
|
|
1040
|
-
if (value === undefined)
|
|
1041
|
-
return ABSENT;
|
|
1042
|
-
if (value === null)
|
|
1043
|
-
return "null";
|
|
1044
|
-
if (typeof value === "object")
|
|
1045
|
-
return JSON.stringify(value);
|
|
1046
|
-
return String(value);
|
|
1047
|
-
}
|
|
1048
|
-
function ordered(totals, top) {
|
|
1049
|
-
const entries = [...totals].sort(([leftKey, left], [rightKey, right]) => right === left ? leftKey.localeCompare(rightKey) : right - left);
|
|
1050
|
-
const sliced = top === undefined ? entries : entries.slice(0, top);
|
|
1051
|
-
return Object.fromEntries(sliced);
|
|
1052
|
-
}
|
|
1053
|
-
function numericValue(value, field) {
|
|
1054
|
-
if (value === undefined || value === null)
|
|
1055
|
-
return;
|
|
1056
|
-
if (typeof value === "number" && Number.isFinite(value))
|
|
1057
|
-
return value;
|
|
1058
|
-
if (typeof value === "bigint")
|
|
1059
|
-
return Number(value);
|
|
1060
|
-
throw new CliArgumentError(`--sum ${field}: "${groupKey(value)}" is not a number`);
|
|
1061
|
-
}
|
|
1062
|
-
function renderTable(records, fields) {
|
|
1063
|
-
const paths = fields.map((field) => assertFieldPresent(records, field));
|
|
1064
|
-
const cell = (value) => {
|
|
1065
|
-
if (value === undefined)
|
|
1066
|
-
return "";
|
|
1067
|
-
if (value === null)
|
|
1068
|
-
return "null";
|
|
1069
|
-
if (typeof value === "object")
|
|
1070
|
-
return JSON.stringify(value);
|
|
1071
|
-
return String(value);
|
|
1072
|
-
};
|
|
1073
|
-
const rows = records.map((record) => paths.map((path) => cell(readField(record, path))));
|
|
1074
|
-
const widths = fields.map((field, column) => Math.max(field.length, ...rows.map((row) => row[column]?.length ?? 0)));
|
|
1075
|
-
const line = (cells) => cells.map((value, column) => value.padEnd(widths[column] ?? value.length)).join(" ").trimEnd();
|
|
1076
|
-
return `${[line(fields), line(widths.map((width) => "-".repeat(width))), ...rows.map(line)].join(`
|
|
1077
|
-
`)}
|
|
1078
|
-
`;
|
|
1079
|
-
}
|
|
1080
|
-
function compareFieldValues(left, right) {
|
|
1081
|
-
if (left === undefined || left === null)
|
|
1082
|
-
return right === undefined || right === null ? 0 : 1;
|
|
1083
|
-
if (right === undefined || right === null)
|
|
1084
|
-
return -1;
|
|
1085
|
-
if (typeof left === "number" && typeof right === "number")
|
|
1086
|
-
return left - right;
|
|
1087
|
-
if (typeof left === "bigint" || typeof right === "bigint") {
|
|
1088
|
-
return Number(left) - Number(right);
|
|
1089
|
-
}
|
|
1090
|
-
return groupKey(left).localeCompare(groupKey(right));
|
|
1091
|
-
}
|
|
1092
|
-
function renderRecords(records, view) {
|
|
1093
|
-
let selected = [...records];
|
|
1094
|
-
if (view.sort !== undefined) {
|
|
1095
|
-
const path = assertFieldPresent(records, view.sort);
|
|
1096
|
-
const direction = view.ascending ? 1 : -1;
|
|
1097
|
-
selected.sort((left, right) => {
|
|
1098
|
-
const order = compareFieldValues(readField(left, path), readField(right, path));
|
|
1099
|
-
const absent = readField(left, path) === undefined || readField(right, path) === undefined;
|
|
1100
|
-
return absent ? order : order * direction;
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
if (view.top !== undefined)
|
|
1104
|
-
selected = selected.slice(0, view.top);
|
|
1105
|
-
return view.table ? { kind: "text", text: renderTable(selected, view.table) } : { kind: "json", data: selected };
|
|
1106
|
-
}
|
|
1107
|
-
function renderCliView(data, view) {
|
|
1108
|
-
const records = selectRecords(data);
|
|
1109
|
-
if (view.kind === "records")
|
|
1110
|
-
return renderRecords(records, view);
|
|
1111
|
-
if (view.kind === "count") {
|
|
1112
|
-
const path2 = assertFieldPresent(records, view.field);
|
|
1113
|
-
const totals2 = new Map;
|
|
1114
|
-
for (const record of records) {
|
|
1115
|
-
const key = groupKey(readField(record, path2));
|
|
1116
|
-
totals2.set(key, (totals2.get(key) ?? 0) + 1);
|
|
1117
|
-
}
|
|
1118
|
-
return { kind: "json", data: ordered(totals2, view.top) };
|
|
1119
|
-
}
|
|
1120
|
-
const path = assertFieldPresent(records, view.field);
|
|
1121
|
-
if (view.by === undefined) {
|
|
1122
|
-
let total = 0;
|
|
1123
|
-
for (const record of records)
|
|
1124
|
-
total += numericValue(readField(record, path), view.field) ?? 0;
|
|
1125
|
-
return { kind: "json", data: total };
|
|
1126
|
-
}
|
|
1127
|
-
const byPath = assertFieldPresent(records, view.by);
|
|
1128
|
-
const totals = new Map;
|
|
1129
|
-
for (const record of records) {
|
|
1130
|
-
const key = groupKey(readField(record, byPath));
|
|
1131
|
-
totals.set(key, (totals.get(key) ?? 0) + (numericValue(readField(record, path), view.field) ?? 0));
|
|
1132
|
-
}
|
|
1133
|
-
return { kind: "json", data: ordered(totals, view.top) };
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
// src/tools/wait-core.ts
|
|
1137
|
-
var DEFAULT_BACKOFF = [2, 3, 5, 5, 8, 10];
|
|
1138
|
-
var DEFAULT_TIMEOUT = 600;
|
|
1139
|
-
|
|
1140
|
-
class WaitTimeoutError extends Error {
|
|
1141
|
-
constructor() {
|
|
1142
|
-
super("wait deadline elapsed before the first snapshot");
|
|
1143
|
-
this.name = "WaitTimeoutError";
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
var defaultSleep = (ms, signal) => {
|
|
1147
|
-
signal?.throwIfAborted();
|
|
1148
|
-
return new Promise((resolve, reject) => {
|
|
1149
|
-
let settled = false;
|
|
1150
|
-
const settle = (action) => {
|
|
1151
|
-
if (settled)
|
|
1152
|
-
return;
|
|
1153
|
-
settled = true;
|
|
1154
|
-
signal?.removeEventListener("abort", onAbort);
|
|
1155
|
-
action();
|
|
1156
|
-
};
|
|
1157
|
-
const timer = setTimeout(() => {
|
|
1158
|
-
settle(resolve);
|
|
1159
|
-
}, ms);
|
|
1160
|
-
timer.unref?.();
|
|
1161
|
-
const onAbort = () => {
|
|
1162
|
-
clearTimeout(timer);
|
|
1163
|
-
settle(() => reject(signal?.reason ?? new Error("aborted")));
|
|
1164
|
-
};
|
|
1165
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1166
|
-
if (signal?.aborted)
|
|
1167
|
-
onAbort();
|
|
1168
|
-
});
|
|
1169
|
-
};
|
|
1170
|
-
async function pollUntil(params) {
|
|
1171
|
-
const backoff = params.backoff?.length ? params.backoff : DEFAULT_BACKOFF;
|
|
1172
|
-
const lastBackoff = backoff[backoff.length - 1] ?? 5;
|
|
1173
|
-
const timeoutSec = params.timeoutSec ?? DEFAULT_TIMEOUT;
|
|
1174
|
-
const sleep = params.sleepFn ?? defaultSleep;
|
|
1175
|
-
const now = params.nowFn ?? (() => performance.now());
|
|
1176
|
-
const startedAt = now();
|
|
1177
|
-
const deadline = startedAt + timeoutSec * 1000;
|
|
1178
|
-
let last;
|
|
1179
|
-
for (let attempt = 0;; attempt++) {
|
|
1180
|
-
params.signal?.throwIfAborted();
|
|
1181
|
-
const remainingBeforePoll = Math.max(0, deadline - now());
|
|
1182
|
-
if (remainingBeforePoll === 0 && last) {
|
|
1183
|
-
return { state: last.state, timedOut: true };
|
|
1184
|
-
}
|
|
1185
|
-
const deadlineController = new AbortController;
|
|
1186
|
-
const onCallerAbort = () => deadlineController.abort(params.signal?.reason);
|
|
1187
|
-
params.signal?.addEventListener("abort", onCallerAbort, { once: true });
|
|
1188
|
-
const deadlineTimer = setTimeout(() => deadlineController.abort(new WaitTimeoutError), remainingBeforePoll);
|
|
1189
|
-
deadlineTimer.unref?.();
|
|
1190
|
-
let state;
|
|
1191
|
-
try {
|
|
1192
|
-
state = await params.poll(deadlineController.signal);
|
|
1193
|
-
} catch (error) {
|
|
1194
|
-
if (params.signal?.aborted)
|
|
1195
|
-
throw params.signal.reason ?? error;
|
|
1196
|
-
if (deadlineController.signal.aborted && now() >= deadline) {
|
|
1197
|
-
if (last)
|
|
1198
|
-
return { state: last.state, timedOut: true };
|
|
1199
|
-
throw new WaitTimeoutError;
|
|
1200
|
-
}
|
|
1201
|
-
throw error;
|
|
1202
|
-
} finally {
|
|
1203
|
-
clearTimeout(deadlineTimer);
|
|
1204
|
-
params.signal?.removeEventListener("abort", onCallerAbort);
|
|
1205
|
-
}
|
|
1206
|
-
params.signal?.throwIfAborted();
|
|
1207
|
-
last = { state };
|
|
1208
|
-
if (params.done(state))
|
|
1209
|
-
return { state, timedOut: false };
|
|
1210
|
-
const elapsedMs = now() - startedAt;
|
|
1211
|
-
const elapsedSec = elapsedMs / 1000;
|
|
1212
|
-
params.onTick?.(attempt + 1, elapsedSec);
|
|
1213
|
-
if (elapsedSec >= timeoutSec)
|
|
1214
|
-
return { state, timedOut: true };
|
|
1215
|
-
const waitSec = backoff[Math.min(attempt, backoff.length - 1)] ?? lastBackoff;
|
|
1216
|
-
await sleep(Math.min(waitSec * 1000, Math.max(0, deadline - now())), params.signal);
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
function runWaitOperation(params) {
|
|
1220
|
-
return pollUntil({
|
|
1221
|
-
poll: (signal) => params.poll(params.input, signal),
|
|
1222
|
-
done: params.done,
|
|
1223
|
-
backoff: params.backoff,
|
|
1224
|
-
timeoutSec: params.timeoutSec,
|
|
1225
|
-
sleepFn: params.sleepFn,
|
|
1226
|
-
onTick: params.onTick,
|
|
1227
|
-
signal: params.signal,
|
|
1228
|
-
nowFn: params.nowFn
|
|
1229
|
-
});
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
// src/tools/cli-wait.ts
|
|
1233
|
-
var DEFAULT_TIMEOUT2 = 600;
|
|
1234
|
-
function waitFailure(tool, result) {
|
|
1235
|
-
return {
|
|
1236
|
-
ok: false,
|
|
1237
|
-
code: "WAIT_FAILED",
|
|
1238
|
-
details: {
|
|
1239
|
-
message: `"${tool}" reached a terminal failed state`,
|
|
1240
|
-
result
|
|
1241
|
-
}
|
|
1242
|
-
};
|
|
1243
|
-
}
|
|
1244
|
-
async function pollUntilDone(params) {
|
|
1245
|
-
const { initial, wait, call } = params;
|
|
1246
|
-
if (!initial.ok)
|
|
1247
|
-
return initial;
|
|
1248
|
-
if (wait.failed?.(initial.data))
|
|
1249
|
-
return waitFailure(wait.tool, initial.data);
|
|
1250
|
-
if (wait.done(initial.data))
|
|
1251
|
-
return initial;
|
|
1252
|
-
const pollArgs = wait.poll(initial.data);
|
|
1253
|
-
if (!pollArgs)
|
|
1254
|
-
return initial;
|
|
1255
|
-
const timeoutSec = params.timeoutSec ?? wait.timeout ?? DEFAULT_TIMEOUT2;
|
|
1256
|
-
let failedState;
|
|
1257
|
-
const { state, timedOut } = await pollUntil({
|
|
1258
|
-
poll: () => call(wait.tool, pollArgs),
|
|
1259
|
-
done: (result) => {
|
|
1260
|
-
if (!result.ok)
|
|
1261
|
-
return true;
|
|
1262
|
-
if (wait.failed?.(result.data)) {
|
|
1263
|
-
failedState = result;
|
|
1264
|
-
return true;
|
|
1265
|
-
}
|
|
1266
|
-
return wait.done(result.data);
|
|
1267
|
-
},
|
|
1268
|
-
backoff: wait.backoff,
|
|
1269
|
-
timeoutSec,
|
|
1270
|
-
sleepFn: params.sleepFn,
|
|
1271
|
-
onTick: params.onTick,
|
|
1272
|
-
signal: params.signal
|
|
1273
|
-
});
|
|
1274
|
-
if (timedOut) {
|
|
1275
|
-
return {
|
|
1276
|
-
ok: false,
|
|
1277
|
-
code: "TIMEOUT",
|
|
1278
|
-
details: { message: `Timed out after ${timeoutSec}s waiting for "${wait.tool}"` }
|
|
1279
|
-
};
|
|
1280
|
-
}
|
|
1281
|
-
if (state === failedState && state.ok)
|
|
1282
|
-
return waitFailure(wait.tool, state.data);
|
|
1283
|
-
return state;
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
|
-
// src/tools/cli.ts
|
|
1287
|
-
import { writeSync } from "node:fs";
|
|
1288
|
-
import { basename, resolve } from "node:path";
|
|
1289
|
-
|
|
1290
|
-
// src/internal/secure-fetch.ts
|
|
1291
|
-
import { lookup } from "node:dns/promises";
|
|
1292
|
-
import { request as httpRequest } from "node:http";
|
|
1293
|
-
import { request as httpsRequest } from "node:https";
|
|
1294
|
-
import { isIP } from "node:net";
|
|
1295
|
-
var NUMERIC_HOST = /^(0x[0-9a-f]+|[0-9.]+)$/i;
|
|
1296
|
-
var MAX_REDIRECTS = 5;
|
|
1297
|
-
function assertHttpUrl(url) {
|
|
1298
|
-
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
1299
|
-
throw new Error(`refusing to fetch a non-http(s) URL (${url.protocol})`);
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
function mappedIpv4FromIpv6(ip) {
|
|
1303
|
-
const rest = ip.startsWith("::ffff:") ? ip.slice("::ffff:".length) : ip.startsWith("0:0:0:0:0:ffff:") ? ip.slice("0:0:0:0:0:ffff:".length) : null;
|
|
1304
|
-
if (rest === null)
|
|
1305
|
-
return null;
|
|
1306
|
-
if (isIP(rest) === 4)
|
|
1307
|
-
return rest;
|
|
1308
|
-
const [hiRaw, loRaw, extra] = rest.split(":");
|
|
1309
|
-
if (hiRaw === undefined || loRaw === undefined || extra !== undefined)
|
|
1310
|
-
return null;
|
|
1311
|
-
if (!/^[0-9a-f]{1,4}$/i.test(hiRaw) || !/^[0-9a-f]{1,4}$/i.test(loRaw))
|
|
1312
|
-
return null;
|
|
1313
|
-
const hi = Number.parseInt(hiRaw, 16);
|
|
1314
|
-
const lo = Number.parseInt(loRaw, 16);
|
|
1315
|
-
return [hi >> 8, hi & 255, lo >> 8, lo & 255].join(".");
|
|
1316
|
-
}
|
|
1317
|
-
function ipv6Words(ip) {
|
|
1318
|
-
const halves = ip.toLowerCase().split("::");
|
|
1319
|
-
if (halves.length > 2)
|
|
1320
|
-
return null;
|
|
1321
|
-
const head = halves[0] ? halves[0].split(":") : [];
|
|
1322
|
-
const tail = halves[1] ? halves[1].split(":") : [];
|
|
1323
|
-
const missing = 8 - head.length - tail.length;
|
|
1324
|
-
if (halves.length === 1 && missing !== 0 || missing < 0)
|
|
1325
|
-
return null;
|
|
1326
|
-
const parts = halves.length === 2 ? [...head, ...Array(missing).fill("0"), ...tail] : head;
|
|
1327
|
-
if (parts.length !== 8)
|
|
1328
|
-
return null;
|
|
1329
|
-
const words = [];
|
|
1330
|
-
for (const part of parts) {
|
|
1331
|
-
if (!/^[0-9a-f]{1,4}$/i.test(part))
|
|
1332
|
-
return null;
|
|
1333
|
-
words.push(Number.parseInt(part, 16));
|
|
1334
|
-
}
|
|
1335
|
-
return words;
|
|
1336
|
-
}
|
|
1337
|
-
function isPrivateIp(ip) {
|
|
1338
|
-
const normalized = ip.replace(/^\[|\]$/g, "");
|
|
1339
|
-
const family = isIP(normalized);
|
|
1340
|
-
if (family === 4) {
|
|
1341
|
-
const [a, b] = normalized.split(".").map(Number);
|
|
1342
|
-
if (a === undefined || b === undefined)
|
|
1343
|
-
return true;
|
|
1344
|
-
const value = normalized.split(".").map(Number).reduce((total, octet) => total * 256 + octet, 0);
|
|
1345
|
-
const inCidr = (base, prefix) => {
|
|
1346
|
-
const baseValue = base.split(".").map(Number).reduce((total, octet) => total * 256 + octet, 0);
|
|
1347
|
-
const size = 2 ** (32 - prefix);
|
|
1348
|
-
return value >= baseValue && value < baseValue + size;
|
|
1349
|
-
};
|
|
1350
|
-
const blockedRanges = [
|
|
1351
|
-
["0.0.0.0", 8],
|
|
1352
|
-
["10.0.0.0", 8],
|
|
1353
|
-
["100.64.0.0", 10],
|
|
1354
|
-
["127.0.0.0", 8],
|
|
1355
|
-
["169.254.0.0", 16],
|
|
1356
|
-
["172.16.0.0", 12],
|
|
1357
|
-
["192.0.0.0", 24],
|
|
1358
|
-
["192.0.2.0", 24],
|
|
1359
|
-
["192.31.196.0", 24],
|
|
1360
|
-
["192.52.193.0", 24],
|
|
1361
|
-
["192.88.99.0", 24],
|
|
1362
|
-
["192.168.0.0", 16],
|
|
1363
|
-
["192.175.48.0", 24],
|
|
1364
|
-
["198.18.0.0", 15],
|
|
1365
|
-
["198.51.100.0", 24],
|
|
1366
|
-
["203.0.113.0", 24],
|
|
1367
|
-
["224.0.0.0", 4],
|
|
1368
|
-
["240.0.0.0", 4]
|
|
1369
|
-
];
|
|
1370
|
-
return blockedRanges.some(([base, prefix]) => inCidr(base, prefix));
|
|
1371
|
-
}
|
|
1372
|
-
if (family === 6) {
|
|
1373
|
-
const lower = normalized.toLowerCase();
|
|
1374
|
-
const mapped = mappedIpv4FromIpv6(lower);
|
|
1375
|
-
if (mapped)
|
|
1376
|
-
return isPrivateIp(mapped);
|
|
1377
|
-
const words = ipv6Words(lower);
|
|
1378
|
-
if (!words)
|
|
1379
|
-
return true;
|
|
1380
|
-
const [first, second, third] = words;
|
|
1381
|
-
if (first === undefined || second === undefined || third === undefined)
|
|
1382
|
-
return true;
|
|
1383
|
-
return first === 0 || first === 100 && second === 65435 && third === 1 || first === 256 && second === 0 || first === 8193 && (second <= 511 || second === 3512) || first === 8194 || first === 16383 || first === 24320 || (first & 65024) === 64512 || (first & 65472) === 65152 || (first & 65280) === 65280;
|
|
1384
|
-
}
|
|
1385
|
-
return false;
|
|
1386
|
-
}
|
|
1387
|
-
function raceWithAbort(promise, signal) {
|
|
1388
|
-
if (signal.aborted) {
|
|
1389
|
-
promise.catch(() => {
|
|
1390
|
-
return;
|
|
1391
|
-
});
|
|
1392
|
-
return Promise.reject(signal.reason ?? new Error("aborted"));
|
|
1393
|
-
}
|
|
1394
|
-
return new Promise((resolve, reject) => {
|
|
1395
|
-
const onAbort = () => reject(signal.reason ?? new Error("aborted"));
|
|
1396
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
1397
|
-
promise.then((value) => {
|
|
1398
|
-
signal.removeEventListener("abort", onAbort);
|
|
1399
|
-
resolve(value);
|
|
1400
|
-
}, (error) => {
|
|
1401
|
-
signal.removeEventListener("abort", onAbort);
|
|
1402
|
-
reject(error);
|
|
1403
|
-
});
|
|
1404
|
-
});
|
|
1405
|
-
}
|
|
1406
|
-
async function assertPublicUrl(url, signal) {
|
|
1407
|
-
await resolvePublicAddress(url, signal);
|
|
1408
|
-
}
|
|
1409
|
-
async function fetchGuarded(start, allowPrivate, options = {}) {
|
|
1410
|
-
const timeoutMs = options.timeoutMs ?? 15000;
|
|
1411
|
-
const bodyTimeoutMs = options.bodyTimeoutMs ?? 120000;
|
|
1412
|
-
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
1413
|
-
throw new Error("timeoutMs must be positive");
|
|
1414
|
-
}
|
|
1415
|
-
if (!Number.isFinite(bodyTimeoutMs) || bodyTimeoutMs <= 0) {
|
|
1416
|
-
throw new Error("bodyTimeoutMs must be positive");
|
|
1417
|
-
}
|
|
1418
|
-
const controller = new AbortController;
|
|
1419
|
-
const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
|
|
1420
|
-
const headerTimer = setTimeout(() => {
|
|
1421
|
-
controller.abort(new Error(`fetch did not produce response headers within ${timeoutMs}ms`));
|
|
1422
|
-
}, timeoutMs);
|
|
1423
|
-
headerTimer.unref?.();
|
|
1424
|
-
let settled = false;
|
|
1425
|
-
try {
|
|
1426
|
-
let url = start;
|
|
1427
|
-
for (let hop = 0;hop <= MAX_REDIRECTS; hop++) {
|
|
1428
|
-
if (allowPrivate)
|
|
1429
|
-
assertHttpUrl(url);
|
|
1430
|
-
else
|
|
1431
|
-
await assertPublicUrl(url, signal);
|
|
1432
|
-
const res = await fetch(url, { redirect: "manual", signal });
|
|
1433
|
-
const location = res.status >= 300 && res.status < 400 ? res.headers.get("location") : null;
|
|
1434
|
-
if (location === null) {
|
|
1435
|
-
settled = true;
|
|
1436
|
-
clearTimeout(headerTimer);
|
|
1437
|
-
const bodyTimer = setTimeout(() => {
|
|
1438
|
-
controller.abort(new Error(`fetch body was not consumed within ${bodyTimeoutMs}ms`));
|
|
1439
|
-
}, bodyTimeoutMs);
|
|
1440
|
-
bodyTimer.unref?.();
|
|
1441
|
-
return res;
|
|
1442
|
-
}
|
|
1443
|
-
await res.body?.cancel();
|
|
1444
|
-
url = new URL(location, url);
|
|
1445
|
-
}
|
|
1446
|
-
throw new Error("too many redirects");
|
|
1447
|
-
} finally {
|
|
1448
|
-
if (!settled)
|
|
1449
|
-
clearTimeout(headerTimer);
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
class PrivateAddressRefusal extends Error {
|
|
1454
|
-
name = "PrivateAddressRefusal";
|
|
1455
|
-
}
|
|
1456
|
-
async function resolvePublicAddress(url, signal) {
|
|
1457
|
-
assertHttpUrl(url);
|
|
1458
|
-
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
1459
|
-
if (!host)
|
|
1460
|
-
throw new Error("refusing to fetch a URL with no host");
|
|
1461
|
-
const ipFamily = isIP(host);
|
|
1462
|
-
if (ipFamily) {
|
|
1463
|
-
if (isPrivateIp(host))
|
|
1464
|
-
throw new PrivateAddressRefusal("refusing to fetch a private address");
|
|
1465
|
-
return { address: host, family: ipFamily === 6 ? 6 : 4 };
|
|
1466
|
-
}
|
|
1467
|
-
if (NUMERIC_HOST.test(host)) {
|
|
1468
|
-
throw new PrivateAddressRefusal("refusing to fetch a non-canonical numeric host");
|
|
1469
|
-
}
|
|
1470
|
-
if (host === "localhost" || host.endsWith(".local") || host.endsWith(".internal")) {
|
|
1471
|
-
throw new PrivateAddressRefusal("refusing to fetch an internal host");
|
|
1472
|
-
}
|
|
1473
|
-
const pending = lookup(host, { all: true });
|
|
1474
|
-
const records = signal ? await raceWithAbort(pending, signal) : await pending;
|
|
1475
|
-
for (const record2 of records) {
|
|
1476
|
-
if (isPrivateIp(record2.address)) {
|
|
1477
|
-
throw new PrivateAddressRefusal("refusing to fetch a host that resolves to a private address");
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
const record = records[0];
|
|
1481
|
-
if (!record)
|
|
1482
|
-
throw new Error("public hostname resolved to no addresses");
|
|
1483
|
-
return { address: record.address, family: record.family === 6 ? 6 : 4 };
|
|
1484
|
-
}
|
|
1485
|
-
async function fetchPinnedDocument(start, options) {
|
|
1486
|
-
if (!Number.isInteger(options.maxBytes) || options.maxBytes < 1) {
|
|
1487
|
-
throw new Error("maxBytes must be a positive integer");
|
|
1488
|
-
}
|
|
1489
|
-
if (!Number.isFinite(options.timeoutMs) || options.timeoutMs <= 0) {
|
|
1490
|
-
throw new Error("timeoutMs must be positive");
|
|
1491
|
-
}
|
|
1492
|
-
let url = start;
|
|
1493
|
-
const maxRedirects = options.maxRedirects ?? MAX_REDIRECTS;
|
|
1494
|
-
if (!Number.isInteger(maxRedirects) || maxRedirects < 0) {
|
|
1495
|
-
throw new Error("maxRedirects must be a non-negative integer");
|
|
1496
|
-
}
|
|
1497
|
-
const signal = AbortSignal.timeout(options.timeoutMs);
|
|
1498
|
-
for (let hop = 0;hop <= maxRedirects; hop++) {
|
|
1499
|
-
if (options.requireHttps && url.protocol !== "https:") {
|
|
1500
|
-
throw new Error("document URL and every redirect must use https");
|
|
1501
|
-
}
|
|
1502
|
-
if (url.username || url.password) {
|
|
1503
|
-
throw new Error("document URL cannot contain credentials");
|
|
1504
|
-
}
|
|
1505
|
-
const resolved = await resolvePublicAddress(url, signal);
|
|
1506
|
-
const transport = url.protocol === "https:" ? httpsRequest : httpRequest;
|
|
1507
|
-
const response = await new Promise((resolve, reject) => {
|
|
1508
|
-
const request = transport({
|
|
1509
|
-
protocol: url.protocol,
|
|
1510
|
-
hostname: resolved.address,
|
|
1511
|
-
family: resolved.family,
|
|
1512
|
-
port: url.port || undefined,
|
|
1513
|
-
path: `${url.pathname}${url.search}`,
|
|
1514
|
-
method: "GET",
|
|
1515
|
-
signal,
|
|
1516
|
-
servername: url.hostname,
|
|
1517
|
-
headers: {
|
|
1518
|
-
host: url.host,
|
|
1519
|
-
accept: "application/json",
|
|
1520
|
-
...options.headers
|
|
1521
|
-
}
|
|
1522
|
-
}, (incoming) => {
|
|
1523
|
-
const headers = new Headers;
|
|
1524
|
-
for (const [name, value] of Object.entries(incoming.headers)) {
|
|
1525
|
-
if (Array.isArray(value)) {
|
|
1526
|
-
for (const item of value)
|
|
1527
|
-
headers.append(name, item);
|
|
1528
|
-
} else if (value !== undefined) {
|
|
1529
|
-
headers.set(name, value);
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
const chunks = [];
|
|
1533
|
-
let total = 0;
|
|
1534
|
-
incoming.on("data", (chunk) => {
|
|
1535
|
-
total += chunk.byteLength;
|
|
1536
|
-
if (total > options.maxBytes) {
|
|
1537
|
-
incoming.destroy(new Error("response body exceeds configured byte limit"));
|
|
1538
|
-
return;
|
|
1539
|
-
}
|
|
1540
|
-
chunks.push(chunk);
|
|
1541
|
-
});
|
|
1542
|
-
incoming.once("error", reject);
|
|
1543
|
-
incoming.once("end", () => {
|
|
1544
|
-
const body = new Uint8Array(total);
|
|
1545
|
-
let offset = 0;
|
|
1546
|
-
for (const chunk of chunks) {
|
|
1547
|
-
body.set(chunk, offset);
|
|
1548
|
-
offset += chunk.byteLength;
|
|
1549
|
-
}
|
|
1550
|
-
resolve({ status: incoming.statusCode ?? 0, headers, body, url });
|
|
1551
|
-
});
|
|
1552
|
-
});
|
|
1553
|
-
request.once("error", reject);
|
|
1554
|
-
request.end();
|
|
1555
|
-
});
|
|
1556
|
-
if (response.status < 300 || response.status >= 400)
|
|
1557
|
-
return response;
|
|
1558
|
-
const location = response.headers.get("location");
|
|
1559
|
-
if (!location)
|
|
1560
|
-
return response;
|
|
1561
|
-
url = new URL(location, url);
|
|
1562
|
-
}
|
|
1563
|
-
throw new Error("too many redirects");
|
|
1564
|
-
}
|
|
1565
|
-
async function readCapped(res, max) {
|
|
1566
|
-
const reader = res.body?.getReader();
|
|
1567
|
-
if (!reader)
|
|
1568
|
-
return Buffer.alloc(0);
|
|
1569
|
-
const chunks = [];
|
|
1570
|
-
let total = 0;
|
|
1571
|
-
try {
|
|
1572
|
-
while (true) {
|
|
1573
|
-
const { done, value } = await reader.read();
|
|
1574
|
-
if (done)
|
|
1575
|
-
break;
|
|
1576
|
-
total += value.length;
|
|
1577
|
-
if (total > max) {
|
|
1578
|
-
await reader.cancel();
|
|
1579
|
-
return null;
|
|
1580
|
-
}
|
|
1581
|
-
chunks.push(value);
|
|
1582
|
-
}
|
|
1583
|
-
} finally {
|
|
1584
|
-
reader.releaseLock();
|
|
1585
|
-
}
|
|
1586
|
-
return Buffer.concat(chunks);
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
// src/internal/write-download.ts
|
|
1590
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
1591
|
-
import { dirname } from "node:path";
|
|
1592
|
-
async function writeDownload(root, target, data) {
|
|
1593
|
-
if (!isWithinDir(root, target)) {
|
|
1594
|
-
throw new Error("download name escapes the output dir");
|
|
1595
|
-
}
|
|
1596
|
-
await mkdir(dirname(target), { recursive: true });
|
|
1597
|
-
await writeFile(target, data);
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1600
|
-
// src/tools/cli.ts
|
|
1601
|
-
var GLOBAL_OPTIONS = [
|
|
1602
|
-
["--json", "Emit compact success/error JSON records (for scripts)"],
|
|
1603
|
-
["--wait", "Block-poll an async result to a terminal state"],
|
|
1604
|
-
["--wait-timeout <s>", "Override the --wait timeout in seconds"],
|
|
1605
|
-
["--output-dir <dir>", "Download result media into a directory"],
|
|
1606
|
-
["--quiet", "Suppress non-essential stderr output"],
|
|
1607
|
-
["--dry-run", "Print the resolved call without executing it"],
|
|
1608
|
-
["--help, -h", "Show help for a command"],
|
|
1609
|
-
["--help <text>", "List only the commands matching a substring"],
|
|
1610
|
-
["--count-by <field>", "Count records per distinct value of a field"],
|
|
1611
|
-
["--sum <field>", "Total a numeric field, optionally grouped by --by"],
|
|
1612
|
-
["--sort <field>", "Order the records by a field, largest first"],
|
|
1613
|
-
["--ascending", "Flip --sort to smallest first"],
|
|
1614
|
-
["--top <n>", "Keep the n leading entries of the view asked for"],
|
|
1615
|
-
["--table <a,b>", "Render the named fields as an aligned table"]
|
|
1616
|
-
];
|
|
1617
|
-
async function readPipedStdin() {
|
|
1618
|
-
if (process.stdin.isTTY)
|
|
1619
|
-
return null;
|
|
1620
|
-
const chunks = [];
|
|
1621
|
-
for await (const chunk of process.stdin) {
|
|
1622
|
-
chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
1623
|
-
}
|
|
1624
|
-
const text = Buffer.concat(chunks).toString("utf8").trim();
|
|
1625
|
-
return text.length > 0 ? text : null;
|
|
1626
|
-
}
|
|
1627
|
-
function typeLabel(schema) {
|
|
1628
|
-
if (Array.isArray(schema.enum))
|
|
1629
|
-
return schema.enum.join("|");
|
|
1630
|
-
if (schema.type === "array")
|
|
1631
|
-
return "value…";
|
|
1632
|
-
if (typeof schema.type === "string")
|
|
1633
|
-
return schema.type;
|
|
1634
|
-
return "value";
|
|
1635
|
-
}
|
|
1636
|
-
function padRight(text, width) {
|
|
1637
|
-
return text.length >= width ? text : text + " ".repeat(width - text.length);
|
|
1638
|
-
}
|
|
1639
|
-
function summarize(desc) {
|
|
1640
|
-
const firstLine = desc.split(`
|
|
1641
|
-
`)[0]?.trim() ?? "";
|
|
1642
|
-
const firstSentence = firstLine.split(". ")[0]?.trim() ?? firstLine;
|
|
1643
|
-
const max = 72;
|
|
1644
|
-
return firstSentence.length > max ? `${firstSentence.slice(0, max - 1).trimEnd()}…` : firstSentence;
|
|
1645
|
-
}
|
|
1646
|
-
function looseCoerceValue(value) {
|
|
1647
|
-
if (Array.isArray(value))
|
|
1648
|
-
return value.map(looseCoerceValue);
|
|
1649
|
-
if (typeof value !== "string")
|
|
1650
|
-
return value;
|
|
1651
|
-
if (value === "true")
|
|
1652
|
-
return true;
|
|
1653
|
-
if (value === "false")
|
|
1654
|
-
return false;
|
|
1655
|
-
const n = Number(value);
|
|
1656
|
-
return value.trim() !== "" && !Number.isNaN(n) ? n : value;
|
|
1657
|
-
}
|
|
1658
|
-
function passthroughBase(value) {
|
|
1659
|
-
if (isRecord(value))
|
|
1660
|
-
return value;
|
|
1661
|
-
if (typeof value === "string") {
|
|
1662
|
-
try {
|
|
1663
|
-
const parsed = safeJsonParse(value);
|
|
1664
|
-
if (isRecord(parsed))
|
|
1665
|
-
return parsed;
|
|
1666
|
-
} catch {}
|
|
1667
|
-
}
|
|
1668
|
-
return;
|
|
1669
|
-
}
|
|
1670
|
-
function collectPassthrough(toolArgs, field, knownKeys) {
|
|
1671
|
-
const known = new Set(knownKeys);
|
|
1672
|
-
const bag = {};
|
|
1673
|
-
for (const key of Object.keys(toolArgs)) {
|
|
1674
|
-
if (key === field || known.has(key))
|
|
1675
|
-
continue;
|
|
1676
|
-
bag[key] = looseCoerceValue(toolArgs[key]);
|
|
1677
|
-
delete toolArgs[key];
|
|
1678
|
-
}
|
|
1679
|
-
if (Object.keys(bag).length === 0)
|
|
1680
|
-
return;
|
|
1681
|
-
const base = passthroughBase(toolArgs[field]);
|
|
1682
|
-
toolArgs[field] = base ? { ...base, ...bag } : bag;
|
|
1683
|
-
}
|
|
1684
|
-
function applicationOptionLines(fields) {
|
|
1685
|
-
if (fields.length === 0)
|
|
1686
|
-
return [];
|
|
1687
|
-
const labels = new Map(fields.map((field) => [field.name, `--${field.name} <${typeLabel(field.schema)}>`]));
|
|
1688
|
-
const width = Math.max(...fields.map((field) => labels.get(field.name)?.length ?? 0));
|
|
1689
|
-
return [
|
|
1690
|
-
"",
|
|
1691
|
-
"Application options:",
|
|
1692
|
-
...fields.map((field) => ` ${padRight(labels.get(field.name) ?? `--${field.name}`, width)} ${field.description ?? ""}`.trimEnd())
|
|
1693
|
-
];
|
|
1694
|
-
}
|
|
1695
|
-
function filterCommands(commands, filter) {
|
|
1696
|
-
const needle = filter.toLowerCase();
|
|
1697
|
-
return new Map([...commands].filter(([command, descriptor]) => command.toLowerCase().includes(needle) || descriptor.description.toLowerCase().includes(needle)));
|
|
1698
|
-
}
|
|
1699
|
-
function renderTopHelp(input) {
|
|
1700
|
-
const { name, version, defaultCommand } = input;
|
|
1701
|
-
const commands = input.filter === undefined ? input.commands : filterCommands(input.commands, input.filter);
|
|
1702
|
-
const lines = [
|
|
1703
|
-
`${name} ${version}`,
|
|
1704
|
-
"",
|
|
1705
|
-
`Usage: ${name} ${defaultCommand ? "[command]" : "<command>"} [args] [--flags]`,
|
|
1706
|
-
"",
|
|
1707
|
-
input.filter === undefined ? "Commands:" : `Commands matching "${input.filter}" (${commands.size} of ${input.commands.size}):`
|
|
1708
|
-
];
|
|
1709
|
-
const width = Math.max(0, ...[...commands.keys()].map((key) => key.length));
|
|
1710
|
-
for (const [command, descriptor] of commands) {
|
|
1711
|
-
lines.push(` ${padRight(command, width)} ${summarize(descriptor.description)}${command === defaultCommand ? " (default)" : ""}`);
|
|
1712
|
-
}
|
|
1713
|
-
if (input.unavailable !== undefined) {
|
|
1714
|
-
lines.push("", `Managed commands are unavailable: ${input.unavailable}`);
|
|
1715
|
-
}
|
|
1716
|
-
if (input.filter !== undefined) {
|
|
1717
|
-
lines.push("", `Run "${name} <command> --help" for command-specific flags.`);
|
|
1718
|
-
return `${lines.join(`
|
|
1719
|
-
`)}
|
|
1720
|
-
`;
|
|
1721
|
-
}
|
|
1722
|
-
lines.push("", "Global options:");
|
|
1723
|
-
const optWidth = Math.max(...GLOBAL_OPTIONS.map(([flag]) => flag.length));
|
|
1724
|
-
for (const [flag, desc] of GLOBAL_OPTIONS)
|
|
1725
|
-
lines.push(` ${padRight(flag, optWidth)} ${desc}`);
|
|
1726
|
-
lines.push(...applicationOptionLines(input.applicationOptions));
|
|
1727
|
-
lines.push("", `Run "${name} <command> --help" for command-specific flags.`);
|
|
1728
|
-
return `${lines.join(`
|
|
1729
|
-
`)}
|
|
1730
|
-
`;
|
|
1731
|
-
}
|
|
1732
|
-
function renderCommandHelp(name, command, descriptor, applicationOptions = []) {
|
|
1733
|
-
const fields = jsonSchemaFields(descriptor.presentationSchema);
|
|
1734
|
-
const fieldsByName = new Map(fields.map((field) => [field.name, field]));
|
|
1735
|
-
const kinds = describeSchemaFields(descriptor.argumentSchema);
|
|
1736
|
-
const positionals = [];
|
|
1737
|
-
const positionalNames = descriptor.positionals ?? [...kinds].filter(([, info]) => info.kind !== "boolean").map(([fieldName]) => fieldName);
|
|
1738
|
-
for (const fieldName of positionalNames) {
|
|
1739
|
-
const field = fieldsByName.get(fieldName);
|
|
1740
|
-
if (field)
|
|
1741
|
-
positionals.push(field);
|
|
1742
|
-
}
|
|
1743
|
-
const variadicTail = descriptor.positionals !== undefined && kinds.get(descriptor.positionals[descriptor.positionals.length - 1] ?? "")?.kind === "array" ? descriptor.positionals[descriptor.positionals.length - 1] : undefined;
|
|
1744
|
-
const positionalSyntax = new Map(positionals.map((field) => {
|
|
1745
|
-
const label = field.name === variadicTail ? `${field.name}...` : field.name;
|
|
1746
|
-
return [field.name, field.required ? `<${label}>` : `[${label}]`];
|
|
1747
|
-
}));
|
|
1748
|
-
const usage = [
|
|
1749
|
-
`Usage: ${name} ${command}`,
|
|
1750
|
-
...positionals.map((field) => positionalSyntax.get(field.name) ?? field.name),
|
|
1751
|
-
"[--flags]"
|
|
1752
|
-
].join(" ");
|
|
1753
|
-
const lines = [descriptor.description, "", usage, ""];
|
|
1754
|
-
if (fields.length > 0) {
|
|
1755
|
-
lines.push("Arguments:");
|
|
1756
|
-
const labels = new Map(fields.map((field) => {
|
|
1757
|
-
const positional = positionalSyntax.get(field.name);
|
|
1758
|
-
const alias = descriptor.aliases.get(field.name);
|
|
1759
|
-
const option = alias ? `-${alias}, --${field.name}` : `--${field.name}`;
|
|
1760
|
-
return [field.name, positional ? `${positional} | ${option}` : option];
|
|
1761
|
-
}));
|
|
1762
|
-
const width = Math.max(...fields.map((field) => labels.get(field.name)?.length ?? 0));
|
|
1763
|
-
for (const f of fields) {
|
|
1764
|
-
const req = f.required ? " (required)" : "";
|
|
1765
|
-
const desc = f.description ? ` — ${f.description}` : "";
|
|
1766
|
-
const label = labels.get(f.name) ?? `--${f.name}`;
|
|
1767
|
-
lines.push(` ${padRight(label, width)} <${typeLabel(f.schema)}>${req}${desc}`);
|
|
1768
|
-
}
|
|
1769
|
-
lines.push("");
|
|
1770
|
-
}
|
|
1771
|
-
const applicationLines = applicationOptionLines(applicationOptions);
|
|
1772
|
-
if (applicationLines.length > 0)
|
|
1773
|
-
lines.push(...applicationLines.slice(1), "");
|
|
1774
|
-
return `${lines.join(`
|
|
1775
|
-
`)}
|
|
1776
|
-
`;
|
|
1777
|
-
}
|
|
1778
|
-
function nativeDescriptor(definition) {
|
|
1779
|
-
return {
|
|
1780
|
-
description: definition.description,
|
|
1781
|
-
argumentSchema: definition.input,
|
|
1782
|
-
presentationSchema: cliCommandPresentationSchema(definition)
|
|
1783
|
-
};
|
|
1784
|
-
}
|
|
1785
|
-
function assertCommandShape(name, descriptor, exists, passthroughField, applicationGlobals = new Set) {
|
|
1786
|
-
assertUniqueToolName(name, exists, "CLI command");
|
|
1787
|
-
if (name === "help" || name === "version") {
|
|
1788
|
-
throw new Error(`[stitchkit] CLI command "${name}" is reserved`);
|
|
1789
|
-
}
|
|
1790
|
-
const fieldNames = jsonSchemaFields(descriptor.presentationSchema).map((field) => field.name);
|
|
1791
|
-
const conflicting = fieldNames.filter((field) => RESERVED_CLI_OPTIONS.has(field));
|
|
1792
|
-
if (conflicting.length > 0) {
|
|
1793
|
-
throw new Error(`[stitchkit] CLI command "${name}" declares reserved option field(s): ${conflicting.join(", ")}`);
|
|
1794
|
-
}
|
|
1795
|
-
const shadowed = fieldNames.filter((field) => applicationGlobals.has(field));
|
|
1796
|
-
if (shadowed.length > 0) {
|
|
1797
|
-
throw new Error(`[stitchkit] CLI command "${name}" declares field(s) shadowed by application global options: ${shadowed.join(", ")}`);
|
|
1798
|
-
}
|
|
1799
|
-
if (passthroughField !== undefined && descriptor.aliases.has(passthroughField)) {
|
|
1800
|
-
throw new Error(`[stitchkit] CLI command "${name}" cannot alias passthrough field "${passthroughField}"`);
|
|
1801
|
-
}
|
|
1802
|
-
}
|
|
1803
|
-
async function prepareInvocation(command, commandArgv, descriptor, config, readStdin) {
|
|
1804
|
-
let parsed;
|
|
1805
|
-
try {
|
|
1806
|
-
parsed = parseCliArgs(commandArgv, descriptor.argumentSchema, {
|
|
1807
|
-
allowUnknown: config.passthrough?.[command] !== undefined,
|
|
1808
|
-
knownFields: jsonSchemaFields(descriptor.presentationSchema).map((field) => field.name),
|
|
1809
|
-
optionAliases: new Map([...descriptor.aliases].map(([field, alias]) => [alias, field])),
|
|
1810
|
-
positionals: descriptor.positionals
|
|
1811
|
-
});
|
|
1812
|
-
} catch (error) {
|
|
1813
|
-
if (!(error instanceof CliArgumentError))
|
|
1814
|
-
throw error;
|
|
1815
|
-
return { ok: false, message: error.message };
|
|
1816
|
-
}
|
|
1817
|
-
const { toolArgs, options } = parsed;
|
|
1818
|
-
const firstUnset = jsonSchemaFields(descriptor.presentationSchema).find((field) => field.required && !(field.name in toolArgs) && field.schema.type !== "boolean");
|
|
1819
|
-
if (firstUnset) {
|
|
1820
|
-
const piped = await readStdin();
|
|
1821
|
-
if (piped !== null) {
|
|
1822
|
-
if (descriptor.positionals === undefined) {
|
|
1823
|
-
toolArgs[firstUnset.name] = piped;
|
|
1824
|
-
} else {
|
|
1825
|
-
const stdinArgs = parseCliArgs([`--${firstUnset.name}`, piped], descriptor.argumentSchema);
|
|
1826
|
-
toolArgs[firstUnset.name] = stdinArgs.toolArgs[firstUnset.name];
|
|
1827
|
-
}
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
const passthroughField = config.passthrough?.[command];
|
|
1831
|
-
if (passthroughField) {
|
|
1832
|
-
collectPassthrough(toolArgs, passthroughField, objectShapeKeys(descriptor.argumentSchema));
|
|
1833
|
-
}
|
|
1834
|
-
return { ok: true, toolArgs, options };
|
|
1835
|
-
}
|
|
1836
|
-
var DEFAULT_DOWNLOAD_MAX_BYTES = 100 * 1024 * 1024;
|
|
1837
|
-
async function downloadResults(files, dir, stderr, quiet, allowPrivate, maxBytes, timeoutMs) {
|
|
1838
|
-
const root = resolve(dir);
|
|
1839
|
-
let succeeded = true;
|
|
1840
|
-
for (const file of files) {
|
|
1841
|
-
try {
|
|
1842
|
-
const res = await fetchGuarded(new URL(file.url), allowPrivate, { timeoutMs });
|
|
1843
|
-
if (!res.ok)
|
|
1844
|
-
throw new Error(`HTTP ${res.status}`);
|
|
1845
|
-
const buffer = await readCapped(res, maxBytes);
|
|
1846
|
-
if (!buffer)
|
|
1847
|
-
throw new Error(`file exceeds the ${maxBytes}-byte cap`);
|
|
1848
|
-
const target = resolve(root, basename(file.name));
|
|
1849
|
-
await writeDownload(root, target, buffer);
|
|
1850
|
-
if (!quiet)
|
|
1851
|
-
stderr(`saved ${target} (${(buffer.length / 1024).toFixed(0)}KB)
|
|
1852
|
-
`);
|
|
1853
|
-
} catch (err) {
|
|
1854
|
-
succeeded = false;
|
|
1855
|
-
stderr(`failed to download ${file.url}: ${err instanceof Error ? err.message : String(err)}
|
|
1856
|
-
`);
|
|
1857
|
-
}
|
|
1858
|
-
}
|
|
1859
|
-
return succeeded;
|
|
1860
|
-
}
|
|
1861
|
-
async function createCli(config) {
|
|
1862
|
-
let pendingWrite;
|
|
1863
|
-
let writeFailed = false;
|
|
1864
|
-
const writeFd = (fd, text) => {
|
|
1865
|
-
const bytes = Buffer.from(text, "utf8");
|
|
1866
|
-
let offset = 0;
|
|
1867
|
-
while (offset < bytes.length) {
|
|
1868
|
-
try {
|
|
1869
|
-
offset += writeSync(fd, bytes, offset, bytes.length - offset);
|
|
1870
|
-
} catch (error) {
|
|
1871
|
-
if (isRecord(error) && error.code === "EAGAIN") {
|
|
1872
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 1);
|
|
1873
|
-
continue;
|
|
1874
|
-
}
|
|
1875
|
-
const stream = fd === 1 ? process.stdout : process.stderr;
|
|
1876
|
-
const rest = bytes.subarray(offset);
|
|
1877
|
-
pendingWrite = new Promise((resolve2) => {
|
|
1878
|
-
stream.write(rest, (failure) => {
|
|
1879
|
-
if (failure)
|
|
1880
|
-
writeFailed = true;
|
|
1881
|
-
resolve2();
|
|
1882
|
-
});
|
|
1883
|
-
});
|
|
1884
|
-
return;
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
};
|
|
1888
|
-
const stdout = config.stdout ?? ((text) => writeFd(1, text));
|
|
1889
|
-
const stderr = config.stderr ?? ((text) => writeFd(2, text));
|
|
1890
|
-
const exit = config.exit ?? ((code) => {
|
|
1891
|
-
if (pendingWrite === undefined)
|
|
1892
|
-
process.exit(code);
|
|
1893
|
-
else
|
|
1894
|
-
pendingWrite.then(() => process.exit(writeFailed ? 1 : code));
|
|
1895
|
-
});
|
|
1896
|
-
const argv = config.argv ?? process.argv.slice(2);
|
|
1897
|
-
const readStdin = config.stdin ?? readPipedStdin;
|
|
1898
|
-
if (config.auth !== undefined && config.resolveAuth !== undefined) {
|
|
1899
|
-
throw new Error("[stitchkit] createCli: use either auth or resolveAuth, not both");
|
|
1900
|
-
}
|
|
1901
|
-
const applicationOptions = config.globalOptions ? jsonSchemaFields(buildToolPresentationSchema({
|
|
1902
|
-
inputSchema: config.globalOptions,
|
|
1903
|
-
unrepresentable: "any"
|
|
1904
|
-
})) : [];
|
|
1905
|
-
const applicationGlobalNames = new Set(applicationOptions.map((field) => field.name));
|
|
1906
|
-
for (const name of applicationGlobalNames) {
|
|
1907
|
-
if (RESERVED_CLI_OPTIONS.has(name)) {
|
|
1908
|
-
throw new Error(`[stitchkit] CLI global option "--${name}" is reserved by the framework`);
|
|
1909
|
-
}
|
|
1910
|
-
}
|
|
1911
|
-
const nativeCommands = new Map;
|
|
1912
|
-
const nativeHelp = new Map;
|
|
1913
|
-
for (const definition of config.commands ?? []) {
|
|
1914
|
-
const descriptor2 = applyCliPresentationPolicy(definition.name, nativeDescriptor(definition), config);
|
|
1915
|
-
assertCommandShape(definition.name, descriptor2, nativeCommands.has(definition.name), config.passthrough?.[definition.name], applicationGlobalNames);
|
|
1916
|
-
nativeCommands.set(definition.name, definition);
|
|
1917
|
-
nativeHelp.set(definition.name, descriptor2);
|
|
1918
|
-
}
|
|
1919
|
-
let globals;
|
|
1920
|
-
let routableArgv;
|
|
1921
|
-
try {
|
|
1922
|
-
const lifted = extractCliGlobalOptions(argv, config.globalOptions);
|
|
1923
|
-
globals = lifted.globals;
|
|
1924
|
-
routableArgv = lifted.argv;
|
|
1925
|
-
} catch (error) {
|
|
1926
|
-
if (!(error instanceof CliArgumentError))
|
|
1927
|
-
throw error;
|
|
1928
|
-
stderr(`${error.message}
|
|
1929
|
-
`);
|
|
1930
|
-
return exit(2);
|
|
1931
|
-
}
|
|
1932
|
-
const typedGlobals = globals;
|
|
1933
|
-
const route = routeCliArgv(routableArgv, config.defaultCommand);
|
|
1934
|
-
if (route.error) {
|
|
1935
|
-
stderr(`${route.error}
|
|
1936
|
-
`);
|
|
1937
|
-
return exit(2);
|
|
1938
|
-
}
|
|
1939
|
-
const { command, commandArgv } = route;
|
|
1940
|
-
if (route.version || command === "--version" || command === "version") {
|
|
1941
|
-
stdout(`${config.name} ${config.version}
|
|
1942
|
-
`);
|
|
1943
|
-
return exit(0);
|
|
1944
|
-
}
|
|
1945
|
-
const beforeSeparator = commandArgv.indexOf("--") === -1 ? commandArgv : commandArgv.slice(0, commandArgv.indexOf("--"));
|
|
1946
|
-
const helpRequested = beforeSeparator.includes("--help") || beforeSeparator.includes("-h");
|
|
1947
|
-
const native = command === undefined ? undefined : nativeCommands.get(command);
|
|
1948
|
-
if (native && command !== undefined) {
|
|
1949
|
-
const descriptor2 = nativeHelp.get(command);
|
|
1950
|
-
if (!descriptor2)
|
|
1951
|
-
throw new Error("[stitchkit] native CLI descriptor invariant failed");
|
|
1952
|
-
if (helpRequested) {
|
|
1953
|
-
stdout(renderCommandHelp(config.name, command, descriptor2, applicationOptions));
|
|
1954
|
-
return exit(0);
|
|
1955
|
-
}
|
|
1956
|
-
const prepared2 = await prepareInvocation(command, commandArgv, descriptor2, config, readStdin);
|
|
1957
|
-
if (!prepared2.ok) {
|
|
1958
|
-
stderr(`${prepared2.message}
|
|
1959
|
-
`);
|
|
1960
|
-
return exit(2);
|
|
1961
|
-
}
|
|
1962
|
-
const { toolArgs: toolArgs2, options: options2 } = prepared2;
|
|
1963
|
-
if (options2.help) {
|
|
1964
|
-
stdout(renderCommandHelp(config.name, command, descriptor2, applicationOptions));
|
|
1965
|
-
return exit(0);
|
|
1966
|
-
}
|
|
1967
|
-
if (options2.wait) {
|
|
1968
|
-
stderr(`--wait is not configured for native command "${command}"
|
|
1969
|
-
`);
|
|
1970
|
-
return exit(2);
|
|
1971
|
-
}
|
|
1972
|
-
if (options2.waitTimeout !== undefined) {
|
|
1973
|
-
stderr(`--wait-timeout requires --wait
|
|
1974
|
-
`);
|
|
1975
|
-
return exit(2);
|
|
1976
|
-
}
|
|
1977
|
-
if (options2.outputDir !== undefined) {
|
|
1978
|
-
stderr(`--output-dir is not configured for native commands
|
|
1979
|
-
`);
|
|
1980
|
-
return exit(2);
|
|
1981
|
-
}
|
|
1982
|
-
if (options2.dryRun) {
|
|
1983
|
-
stdout(`${JSON.stringify({ command, args: toolArgs2 }, null, 2)}
|
|
1984
|
-
`);
|
|
1985
|
-
return exit(0);
|
|
1986
|
-
}
|
|
1987
|
-
const result2 = await executeCliCommand(native, toolArgs2, options2, { stdout, stderr }, config.coerceJsonArgs ?? true, globals);
|
|
1988
|
-
const emission = prepareCliCommandEmission(native, result2, options2);
|
|
1989
|
-
let emittedExitCode;
|
|
1990
|
-
if (emission.result.ok && emission.presentation !== undefined) {
|
|
1991
|
-
stdout(emission.presentation);
|
|
1992
|
-
emittedExitCode = 0;
|
|
1993
|
-
} else {
|
|
1994
|
-
emittedExitCode = emitResult(emission.result, { stdout, stderr }, {
|
|
1995
|
-
json: options2.json,
|
|
1996
|
-
toolName: command,
|
|
1997
|
-
errorHint: config.errorHint,
|
|
1998
|
-
exitCodes: { ...DEFAULT_EXIT_CODES, ...config.exitCodes }
|
|
1999
|
-
});
|
|
2000
|
-
}
|
|
2001
|
-
return exit(emission.result.ok ? emission.successExitCode : emittedExitCode);
|
|
2002
|
-
}
|
|
2003
|
-
let authPromise;
|
|
2004
|
-
const resolveIdentity = () => {
|
|
2005
|
-
authPromise ??= (async () => config.resolveAuth ? await config.resolveAuth(typedGlobals) : await config.auth)();
|
|
2006
|
-
return authPromise;
|
|
2007
|
-
};
|
|
2008
|
-
const dynamicSurface = typeof config.services === "function" || typeof config.runtimeTools === "function";
|
|
2009
|
-
const buildManagedSurface = async (forExecution) => {
|
|
2010
|
-
let auth;
|
|
2011
|
-
if (dynamicSurface || forExecution) {
|
|
2012
|
-
try {
|
|
2013
|
-
auth = await resolveIdentity();
|
|
2014
|
-
} catch (error) {
|
|
2015
|
-
const failure = toolResultFromError(error);
|
|
2016
|
-
const normalized = toolErrorFromResult(failure);
|
|
2017
|
-
return {
|
|
2018
|
-
resolved: false,
|
|
2019
|
-
failure,
|
|
2020
|
-
reason: `${normalized.code}: ${normalized.message}`,
|
|
2021
|
-
help: new Map(nativeHelp)
|
|
2022
|
-
};
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
const { tools, help } = buildCliSurface(config, auth, nativeHelp, applicationGlobalNames, assertCommandShape);
|
|
2026
|
-
return { resolved: true, auth, help, tools };
|
|
2027
|
-
};
|
|
2028
|
-
const topLevelHelp = route.topLevelHelp || command === undefined || command === "help" || command === "--help" || command === "-h" || command.startsWith("--help=") && !isReservedBoolWord(command.slice("--help=".length));
|
|
2029
|
-
const managed = await buildManagedSurface(!topLevelHelp && !helpRequested);
|
|
2030
|
-
if (topLevelHelp) {
|
|
2031
|
-
const helpFilter = route.helpFilter ?? (command !== undefined ? commandArgv[0] : undefined);
|
|
2032
|
-
const filter = helpFilter !== undefined && !helpFilter.startsWith("-") ? helpFilter : undefined;
|
|
2033
|
-
if (filter !== undefined && filterCommands(managed.help, filter).size === 0) {
|
|
2034
|
-
stderr(`no command matches "${filter}" (${managed.help.size} available)
|
|
2035
|
-
` + (managed.resolved ? "" : `Managed commands are unavailable: ${managed.reason}
|
|
2036
|
-
`));
|
|
2037
|
-
const codes = { ...DEFAULT_EXIT_CODES, ...config.exitCodes };
|
|
2038
|
-
return exit(codes.NOT_FOUND ?? 4);
|
|
2039
|
-
}
|
|
2040
|
-
stdout(renderTopHelp({
|
|
2041
|
-
name: config.name,
|
|
2042
|
-
version: config.version,
|
|
2043
|
-
commands: managed.help,
|
|
2044
|
-
defaultCommand: config.defaultCommand,
|
|
2045
|
-
applicationOptions,
|
|
2046
|
-
...filter !== undefined && { filter },
|
|
2047
|
-
...managed.resolved ? {} : { unavailable: managed.reason }
|
|
2048
|
-
}));
|
|
2049
|
-
return exit(0);
|
|
2050
|
-
}
|
|
2051
|
-
if (!managed.resolved) {
|
|
2052
|
-
return exit(emitResult(managed.failure, { stdout, stderr }, {
|
|
2053
|
-
json: beforeSeparator.includes("--json"),
|
|
2054
|
-
toolName: command ?? config.name,
|
|
2055
|
-
errorHint: config.errorHint,
|
|
2056
|
-
exitCodes: { ...DEFAULT_EXIT_CODES, ...config.exitCodes }
|
|
2057
|
-
}));
|
|
2058
|
-
}
|
|
2059
|
-
const tool = managed.tools.get(command);
|
|
2060
|
-
if (!tool) {
|
|
2061
|
-
stderr(`Unknown command "${command}". Run "${config.name} --help" for the command list.
|
|
2062
|
-
`);
|
|
2063
|
-
return exit(1);
|
|
2064
|
-
}
|
|
2065
|
-
const descriptor = managed.help.get(command);
|
|
2066
|
-
if (!descriptor)
|
|
2067
|
-
throw new Error("[stitchkit] managed CLI descriptor invariant failed");
|
|
2068
|
-
if (helpRequested) {
|
|
2069
|
-
stdout(renderCommandHelp(config.name, command, descriptor, applicationOptions));
|
|
2070
|
-
return exit(0);
|
|
2071
|
-
}
|
|
2072
|
-
const prepared = await prepareInvocation(command, commandArgv, descriptor, config, readStdin);
|
|
2073
|
-
if (!prepared.ok) {
|
|
2074
|
-
stderr(`${prepared.message}
|
|
2075
|
-
`);
|
|
2076
|
-
return exit(2);
|
|
2077
|
-
}
|
|
2078
|
-
const { toolArgs, options } = prepared;
|
|
2079
|
-
if (options.wait && !config.wait?.[command]) {
|
|
2080
|
-
stderr(`--wait is not configured for command "${command}"
|
|
2081
|
-
`);
|
|
2082
|
-
return exit(2);
|
|
2083
|
-
}
|
|
2084
|
-
if (options.waitTimeout !== undefined && !options.wait) {
|
|
2085
|
-
stderr(`--wait-timeout requires --wait
|
|
2086
|
-
`);
|
|
2087
|
-
return exit(2);
|
|
2088
|
-
}
|
|
2089
|
-
if (options.outputDir !== undefined && !config.download) {
|
|
2090
|
-
stderr(`--output-dir is not configured for this CLI
|
|
2091
|
-
`);
|
|
2092
|
-
return exit(2);
|
|
2093
|
-
}
|
|
2094
|
-
if (options.help) {
|
|
2095
|
-
stdout(renderCommandHelp(config.name, command, descriptor, applicationOptions));
|
|
2096
|
-
return exit(0);
|
|
2097
|
-
}
|
|
2098
|
-
if (options.dryRun) {
|
|
2099
|
-
stdout(`${JSON.stringify({ command, args: toolArgs }, null, 2)}
|
|
2100
|
-
`);
|
|
2101
|
-
return exit(0);
|
|
2102
|
-
}
|
|
2103
|
-
const runTool = createToolRunner({
|
|
2104
|
-
source: "cli",
|
|
2105
|
-
context: { ...config.context?.(managed.auth, typedGlobals), signal: config.signal },
|
|
2106
|
-
hooks: config.hooks,
|
|
2107
|
-
lifecycle: config.lifecycle,
|
|
2108
|
-
errorHint: config.errorHint,
|
|
2109
|
-
coerceJsonArgs: config.coerceJsonArgs
|
|
2110
|
-
});
|
|
2111
|
-
let result;
|
|
2112
|
-
try {
|
|
2113
|
-
result = await runTool(tool, toolArgs);
|
|
2114
|
-
} catch (err) {
|
|
2115
|
-
result = toolResultFromError(err);
|
|
2116
|
-
}
|
|
2117
|
-
const waitConfig = config.wait?.[command];
|
|
2118
|
-
if (options.wait && waitConfig) {
|
|
2119
|
-
result = await pollUntilDone({
|
|
2120
|
-
initial: result,
|
|
2121
|
-
wait: waitConfig,
|
|
2122
|
-
call: async (toolName, args) => {
|
|
2123
|
-
const pollTool = managed.tools.get(toolName);
|
|
2124
|
-
if (!pollTool) {
|
|
2125
|
-
return {
|
|
2126
|
-
ok: false,
|
|
2127
|
-
code: "NOT_FOUND",
|
|
2128
|
-
details: { message: `--wait: no command "${toolName}" to poll` }
|
|
2129
|
-
};
|
|
2130
|
-
}
|
|
2131
|
-
return runTool(pollTool, args);
|
|
2132
|
-
},
|
|
2133
|
-
timeoutSec: options.waitTimeout,
|
|
2134
|
-
onTick: options.quiet ? undefined : (attempt) => stderr(`waiting… (poll ${attempt})
|
|
2135
|
-
`),
|
|
2136
|
-
signal: config.signal
|
|
2137
|
-
});
|
|
2138
|
-
}
|
|
2139
|
-
let downloadsOk = true;
|
|
2140
|
-
if (options.outputDir && result.ok && config.download) {
|
|
2141
|
-
downloadsOk = await downloadResults(config.download(result.data), options.outputDir, stderr, options.quiet, config.allowPrivateDownloadHosts ?? false, config.maxDownloadBytes ?? DEFAULT_DOWNLOAD_MAX_BYTES, config.downloadTimeoutMs);
|
|
2142
|
-
}
|
|
2143
|
-
if (options.view && result.ok) {
|
|
2144
|
-
let viewed;
|
|
2145
|
-
try {
|
|
2146
|
-
viewed = renderCliView(result.data, options.view);
|
|
2147
|
-
} catch (error) {
|
|
2148
|
-
if (!(error instanceof CliArgumentError))
|
|
2149
|
-
throw error;
|
|
2150
|
-
stderr(`${error.message}
|
|
2151
|
-
`);
|
|
2152
|
-
return exit(2);
|
|
2153
|
-
}
|
|
2154
|
-
if (viewed.kind === "text") {
|
|
2155
|
-
stdout(viewed.text);
|
|
2156
|
-
return exit(downloadsOk ? 0 : 1);
|
|
2157
|
-
}
|
|
2158
|
-
result = { ...result, data: viewed.data };
|
|
2159
|
-
}
|
|
2160
|
-
const exitCode = emitResult(result, { stdout, stderr }, {
|
|
2161
|
-
json: options.json,
|
|
2162
|
-
toolName: command,
|
|
2163
|
-
errorHint: config.errorHint,
|
|
2164
|
-
exitCodes: { ...DEFAULT_EXIT_CODES, ...config.exitCodes }
|
|
2165
|
-
});
|
|
2166
|
-
return exit(downloadsOk ? exitCode : 1);
|
|
2167
|
-
}
|
|
2168
|
-
|
|
2169
|
-
export { WaitTimeoutError, runWaitOperation, fetchGuarded, PrivateAddressRefusal, fetchPinnedDocument, readCapped, routeCliArgv, CliArgumentError, parseCliArgs, extractCliGlobalOptions, defineCliCommand, DEFAULT_EXIT_CODES, cliExitCode, emitResult, cliInvocationResult, createCliInvoker, renderCliView, pollUntilDone, createCli };
|