stitchkit 0.125.0 → 0.127.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1707 -1
- package/README.md +12 -4
- package/dist/agent-executor/acp/scenarios.d.ts +4 -0
- package/dist/agent-executor/acp/scenarios.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-connect.d.ts +89 -0
- package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-driver.d.ts +31 -0
- package/dist/agent-executor/acp/v1-driver.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-map.d.ts +41 -0
- package/dist/agent-executor/acp/v1-map.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-protocol.d.ts +270 -0
- package/dist/agent-executor/acp/v1-protocol.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-session.d.ts +22 -0
- package/dist/agent-executor/acp/v1-session.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-turn.d.ts +25 -0
- package/dist/agent-executor/acp/v1-turn.d.ts.map +1 -0
- package/dist/agent-executor/claude/classify.d.ts +54 -0
- package/dist/agent-executor/claude/classify.d.ts.map +1 -0
- package/dist/agent-executor/claude/cli-driver.d.ts +27 -0
- package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -0
- package/dist/agent-executor/claude/limits.d.ts +8 -0
- package/dist/agent-executor/claude/limits.d.ts.map +1 -0
- package/dist/agent-executor/claude/protocol.d.ts +188 -0
- package/dist/agent-executor/claude/protocol.d.ts.map +1 -0
- package/dist/agent-executor/claude/scenarios.d.ts +4 -0
- package/dist/agent-executor/claude/scenarios.d.ts.map +1 -0
- package/dist/agent-executor/claude/session.d.ts +22 -0
- package/dist/agent-executor/claude/session.d.ts.map +1 -0
- package/dist/agent-executor/claude/transcript.d.ts +33 -0
- package/dist/agent-executor/claude/transcript.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/driver.d.ts +31 -0
- package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/session.d.ts +10 -0
- package/dist/agent-executor/claude-sdk/session.d.ts.map +1 -0
- package/dist/agent-executor/codex/classify.d.ts +28 -0
- package/dist/agent-executor/codex/classify.d.ts.map +1 -0
- package/dist/agent-executor/codex/driver.d.ts +23 -0
- package/dist/agent-executor/codex/driver.d.ts.map +1 -0
- package/dist/agent-executor/codex/limits.d.ts +4 -0
- package/dist/agent-executor/codex/limits.d.ts.map +1 -0
- package/dist/agent-executor/codex/protocol.d.ts +152 -0
- package/dist/agent-executor/codex/protocol.d.ts.map +1 -0
- package/dist/agent-executor/codex/scenarios.d.ts +4 -0
- package/dist/agent-executor/codex/scenarios.d.ts.map +1 -0
- package/dist/agent-executor/codex/session.d.ts +41 -0
- package/dist/agent-executor/codex/session.d.ts.map +1 -0
- package/dist/agent-executor/contract.d.ts +454 -0
- package/dist/agent-executor/contract.d.ts.map +1 -0
- package/dist/agent-executor/dispatch.d.ts +41 -0
- package/dist/agent-executor/dispatch.d.ts.map +1 -0
- package/dist/agent-executor/engine-process.d.ts +45 -0
- package/dist/agent-executor/engine-process.d.ts.map +1 -0
- package/dist/agent-executor/engine-requests.d.ts +63 -0
- package/dist/agent-executor/engine-requests.d.ts.map +1 -0
- package/dist/agent-executor/engine.d.ts +64 -0
- package/dist/agent-executor/engine.d.ts.map +1 -0
- package/dist/agent-executor/executor-contract.d.ts +387 -0
- package/dist/agent-executor/executor-contract.d.ts.map +1 -0
- package/dist/agent-executor/executor-machine.d.ts +50 -0
- package/dist/agent-executor/executor-machine.d.ts.map +1 -0
- package/dist/agent-executor/hello.d.ts +235 -0
- package/dist/agent-executor/hello.d.ts.map +1 -0
- package/dist/agent-executor/json-rpc-peer.d.ts +48 -0
- package/dist/agent-executor/json-rpc-peer.d.ts.map +1 -0
- package/dist/agent-executor/leases.d.ts +159 -0
- package/dist/agent-executor/leases.d.ts.map +1 -0
- package/dist/agent-executor/plan-limits.d.ts +25 -0
- package/dist/agent-executor/plan-limits.d.ts.map +1 -0
- package/dist/agent-executor/profile.d.ts +52 -0
- package/dist/agent-executor/profile.d.ts.map +1 -0
- package/dist/agent-executor/projection.d.ts +14 -0
- package/dist/agent-executor/projection.d.ts.map +1 -0
- package/dist/agent-executor/session-primitives.d.ts +72 -0
- package/dist/agent-executor/session-primitives.d.ts.map +1 -0
- package/dist/agent-executor/testing/conformance.d.ts +55 -0
- package/dist/agent-executor/testing/conformance.d.ts.map +1 -0
- package/dist/agent-executor/testing/fake-claude-engine.d.ts +18 -0
- package/dist/agent-executor/testing/fake-claude-engine.d.ts.map +1 -0
- package/dist/agent-executor/testing/fake-engine.d.ts +52 -0
- package/dist/agent-executor/testing/fake-engine.d.ts.map +1 -0
- package/dist/agent-executor/turn-phases.d.ts +10 -0
- package/dist/agent-executor/turn-phases.d.ts.map +1 -0
- package/dist/agent-executor/vocabulary.d.ts +353 -0
- package/dist/agent-executor/vocabulary.d.ts.map +1 -0
- package/dist/agent-parts/parts.d.ts +160 -0
- package/dist/agent-parts/parts.d.ts.map +1 -0
- package/dist/agent-runtime/agent-tool.d.ts +1 -1
- package/dist/agent-runtime/agent-tool.d.ts.map +1 -1
- package/dist/agent-runtime/archive-projection.d.ts +5 -0
- package/dist/agent-runtime/archive-projection.d.ts.map +1 -1
- package/dist/agent-runtime/branch-contract.d.ts +63 -1
- package/dist/agent-runtime/branch-contract.d.ts.map +1 -1
- package/dist/agent-runtime/branch-events.d.ts +7 -0
- package/dist/agent-runtime/branch-events.d.ts.map +1 -1
- package/dist/agent-runtime/branch-identities.d.ts +53 -1
- package/dist/agent-runtime/branch-identities.d.ts.map +1 -1
- package/dist/agent-runtime/branch-messages.d.ts +15 -26
- package/dist/agent-runtime/branch-messages.d.ts.map +1 -1
- package/dist/agent-runtime/branch-observations.d.ts +138 -28
- package/dist/agent-runtime/branch-observations.d.ts.map +1 -1
- package/dist/agent-runtime/branch-provider.d.ts +32 -51
- package/dist/agent-runtime/branch-provider.d.ts.map +1 -1
- package/dist/agent-runtime/branch-refusal.d.ts +60 -0
- package/dist/agent-runtime/branch-refusal.d.ts.map +1 -0
- package/dist/agent-runtime/branch-runtime-tools.d.ts +14 -0
- package/dist/agent-runtime/branch-runtime-tools.d.ts.map +1 -0
- package/dist/agent-runtime/branch-source.d.ts +7 -2
- package/dist/agent-runtime/branch-source.d.ts.map +1 -1
- package/dist/agent-runtime/branch-transitions.d.ts.map +1 -1
- package/dist/agent-runtime/browser-control-contract.d.ts +2 -2
- package/dist/agent-runtime/browser-controller.d.ts.map +1 -1
- package/dist/agent-runtime/child-blocking.d.ts +17 -6
- package/dist/agent-runtime/child-blocking.d.ts.map +1 -1
- package/dist/agent-runtime/child-budget-policy.d.ts +4 -9
- package/dist/agent-runtime/child-budget-policy.d.ts.map +1 -1
- package/dist/agent-runtime/child-tools.d.ts +19 -8
- package/dist/agent-runtime/child-tools.d.ts.map +1 -1
- package/dist/agent-runtime/children-contract.d.ts +84 -3
- package/dist/agent-runtime/children-contract.d.ts.map +1 -1
- package/dist/agent-runtime/children-control.d.ts +23 -2
- package/dist/agent-runtime/children-control.d.ts.map +1 -1
- package/dist/agent-runtime/children-spawn.d.ts +9 -0
- package/dist/agent-runtime/children-spawn.d.ts.map +1 -1
- package/dist/agent-runtime/children-state.d.ts +121 -19
- package/dist/agent-runtime/children-state.d.ts.map +1 -1
- package/dist/agent-runtime/children-usage.d.ts +10 -1
- package/dist/agent-runtime/children-usage.d.ts.map +1 -1
- package/dist/agent-runtime/children.d.ts +3 -3
- package/dist/agent-runtime/children.d.ts.map +1 -1
- package/dist/agent-runtime/{sandbox-coding.d.ts → coding-sandbox.d.ts} +2 -9
- package/dist/agent-runtime/coding-sandbox.d.ts.map +1 -0
- package/dist/agent-runtime/coding-shell-process.d.ts +2 -0
- package/dist/agent-runtime/coding-shell-process.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-contract.d.ts +32 -1
- package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-shell.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tools.d.ts.map +1 -1
- package/dist/agent-runtime/compaction.d.ts.map +1 -1
- package/dist/agent-runtime/companion-host.d.ts +38 -0
- package/dist/agent-runtime/companion-host.d.ts.map +1 -0
- package/dist/agent-runtime/context-issue.d.ts +5 -0
- package/dist/agent-runtime/context-issue.d.ts.map +1 -0
- package/dist/agent-runtime/control-schema.d.ts +2 -2
- package/dist/agent-runtime/control-schema.d.ts.map +1 -1
- package/dist/agent-runtime/conversations.d.ts.map +1 -1
- package/dist/agent-runtime/coordinator.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tool-types.d.ts +17 -5
- package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tools-internal.d.ts +2 -0
- package/dist/agent-runtime/deferred-tools-internal.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tools.d.ts.map +1 -1
- package/dist/agent-runtime/event-durability.d.ts +8 -0
- package/dist/agent-runtime/event-durability.d.ts.map +1 -0
- package/dist/agent-runtime/event-schema.d.ts +13 -5
- package/dist/agent-runtime/event-schema.d.ts.map +1 -1
- package/dist/agent-runtime/event-search-postgres.d.ts +38 -0
- package/dist/agent-runtime/event-search-postgres.d.ts.map +1 -0
- package/dist/agent-runtime/event-search-terms.d.ts +37 -0
- package/dist/agent-runtime/event-search-terms.d.ts.map +1 -0
- package/dist/agent-runtime/event-search-tools.d.ts +64 -4
- package/dist/agent-runtime/event-search-tools.d.ts.map +1 -1
- package/dist/agent-runtime/event-search.d.ts +16 -3
- package/dist/agent-runtime/event-search.d.ts.map +1 -1
- package/dist/agent-runtime/fault-bench.d.ts.map +1 -1
- package/dist/agent-runtime/harness-control.d.ts +8 -0
- package/dist/agent-runtime/harness-control.d.ts.map +1 -1
- package/dist/agent-runtime/harness-realtime.d.ts +0 -2
- package/dist/agent-runtime/harness-realtime.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-read.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-schema.d.ts +23 -0
- package/dist/agent-runtime/invocation-schema.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-spend.d.ts +9 -0
- package/dist/agent-runtime/invocation-spend.d.ts.map +1 -0
- package/dist/agent-runtime/invocations.d.ts.map +1 -1
- package/dist/agent-runtime/managed-tools.d.ts +2 -2
- package/dist/agent-runtime/managed-tools.d.ts.map +1 -1
- package/dist/agent-runtime/observability.d.ts +42 -4
- package/dist/agent-runtime/observability.d.ts.map +1 -1
- package/dist/agent-runtime/openrouter-admission.d.ts +81 -0
- package/dist/agent-runtime/openrouter-admission.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter-catalog.d.ts +83 -0
- package/dist/agent-runtime/openrouter-catalog.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter-models.d.ts +66 -0
- package/dist/agent-runtime/openrouter-models.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter-options.d.ts +106 -0
- package/dist/agent-runtime/openrouter-options.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter-route.d.ts +50 -0
- package/dist/agent-runtime/openrouter-route.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter-spend.d.ts +24 -0
- package/dist/agent-runtime/openrouter-spend.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter.d.ts +23 -2
- package/dist/agent-runtime/openrouter.d.ts.map +1 -1
- package/dist/agent-runtime/owned-provider-stream.d.ts.map +1 -1
- package/dist/agent-runtime/postgres-schema.d.ts +34 -0
- package/dist/agent-runtime/postgres-schema.d.ts.map +1 -0
- package/dist/agent-runtime/postgres-transactions.d.ts +54 -0
- package/dist/agent-runtime/postgres-transactions.d.ts.map +1 -0
- package/dist/agent-runtime/postgres.d.ts +72 -0
- package/dist/agent-runtime/postgres.d.ts.map +1 -0
- package/dist/agent-runtime/projections.d.ts +57 -17
- package/dist/agent-runtime/projections.d.ts.map +1 -1
- package/dist/agent-runtime/provider-journal.d.ts +57 -0
- package/dist/agent-runtime/provider-journal.d.ts.map +1 -1
- package/dist/agent-runtime/purge.d.ts.map +1 -1
- package/dist/agent-runtime/retry-policy.d.ts +6 -0
- package/dist/agent-runtime/retry-policy.d.ts.map +1 -1
- package/dist/agent-runtime/run-acquisition.d.ts.map +1 -1
- package/dist/agent-runtime/run-execution-state.d.ts +26 -2
- package/dist/agent-runtime/run-execution-state.d.ts.map +1 -1
- package/dist/agent-runtime/run-execution.d.ts.map +1 -1
- package/dist/agent-runtime/run-failure.d.ts.map +1 -1
- package/dist/agent-runtime/run-model-attempts.d.ts.map +1 -1
- package/dist/agent-runtime/run-provider-ledger.d.ts +2 -0
- package/dist/agent-runtime/run-provider-ledger.d.ts.map +1 -1
- package/dist/agent-runtime/run-step-barriers.d.ts +72 -0
- package/dist/agent-runtime/run-step-barriers.d.ts.map +1 -0
- package/dist/agent-runtime/run-step-spend.d.ts +319 -0
- package/dist/agent-runtime/run-step-spend.d.ts.map +1 -0
- package/dist/agent-runtime/run-stream-parts.d.ts +2 -0
- package/dist/agent-runtime/run-stream-parts.d.ts.map +1 -1
- package/dist/agent-runtime/{tool-progress.d.ts → run-tool-progress.d.ts} +1 -1
- package/dist/agent-runtime/run-tool-progress.d.ts.map +1 -0
- package/dist/agent-runtime/run-turn-preparation.d.ts +3 -1
- package/dist/agent-runtime/run-turn-preparation.d.ts.map +1 -1
- package/dist/agent-runtime/runtime-admission-gate.d.ts +0 -14
- package/dist/agent-runtime/runtime-admission-gate.d.ts.map +1 -1
- package/dist/agent-runtime/runtime-internals.d.ts +6 -0
- package/dist/agent-runtime/runtime-internals.d.ts.map +1 -1
- package/dist/agent-runtime/runtime-state.d.ts.map +1 -1
- package/dist/agent-runtime/runtime.d.ts +31 -2
- package/dist/agent-runtime/runtime.d.ts.map +1 -1
- package/dist/agent-runtime/sandbox-binding.d.ts +10 -0
- package/dist/agent-runtime/sandbox-binding.d.ts.map +1 -0
- package/dist/agent-runtime/sandbox-bubblewrap-storage.d.ts.map +1 -1
- package/dist/agent-runtime/sandbox-contract.d.ts +1 -1
- package/dist/agent-runtime/sandbox-contract.d.ts.map +1 -1
- package/dist/agent-runtime/sandbox.d.ts +5 -0
- package/dist/agent-runtime/sandbox.d.ts.map +1 -1
- package/dist/agent-runtime/schedule-contract.d.ts +3 -2
- package/dist/agent-runtime/schedule-contract.d.ts.map +1 -1
- package/dist/agent-runtime/schedule-dispatch.d.ts +3 -2
- package/dist/agent-runtime/schedule-dispatch.d.ts.map +1 -1
- package/dist/agent-runtime/schedule-records.d.ts +6 -6
- package/dist/agent-runtime/schedule-records.d.ts.map +1 -1
- package/dist/agent-runtime/schedule-tools.d.ts +19 -8
- package/dist/agent-runtime/schedule-tools.d.ts.map +1 -1
- package/dist/agent-runtime/schedules.d.ts +13 -3
- package/dist/agent-runtime/schedules.d.ts.map +1 -1
- package/dist/agent-runtime/schemas-message.d.ts +118 -0
- package/dist/agent-runtime/schemas-message.d.ts.map +1 -0
- package/dist/agent-runtime/schemas-provider.d.ts +8 -0
- package/dist/agent-runtime/schemas-provider.d.ts.map +1 -0
- package/dist/agent-runtime/schemas-records.d.ts +5 -0
- package/dist/agent-runtime/schemas-records.d.ts.map +1 -0
- package/dist/agent-runtime/schemas-run.d.ts +487 -0
- package/dist/agent-runtime/schemas-run.d.ts.map +1 -0
- package/dist/agent-runtime/schemas-usage.d.ts +129 -0
- package/dist/agent-runtime/schemas-usage.d.ts.map +1 -0
- package/dist/agent-runtime/schemas.d.ts +11 -886
- package/dist/agent-runtime/schemas.d.ts.map +1 -1
- package/dist/agent-runtime/spill.d.ts +9 -7
- package/dist/agent-runtime/spill.d.ts.map +1 -1
- package/dist/agent-runtime/sql-events.d.ts +6 -0
- package/dist/agent-runtime/sql-events.d.ts.map +1 -0
- package/dist/agent-runtime/sql-history.d.ts +8 -0
- package/dist/agent-runtime/sql-history.d.ts.map +1 -0
- package/dist/agent-runtime/sql-ledger.d.ts +5 -0
- package/dist/agent-runtime/sql-ledger.d.ts.map +1 -0
- package/dist/agent-runtime/sql-purge.d.ts +13 -0
- package/dist/agent-runtime/sql-purge.d.ts.map +1 -0
- package/dist/agent-runtime/sql-reads.d.ts +16 -0
- package/dist/agent-runtime/sql-reads.d.ts.map +1 -0
- package/dist/agent-runtime/{sqlite-rows.d.ts → sql-rows.d.ts} +24 -10
- package/dist/agent-runtime/sql-rows.d.ts.map +1 -0
- package/dist/agent-runtime/sql-session.d.ts +71 -0
- package/dist/agent-runtime/sql-session.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-bun.d.ts +1 -1
- package/dist/agent-runtime/sqlite-bun.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite-node.d.ts +1 -1
- package/dist/agent-runtime/sqlite-node.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite-purge.d.ts +2 -3
- package/dist/agent-runtime/sqlite-purge.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite-schema.d.ts +1 -1
- package/dist/agent-runtime/sqlite-schema.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite-transactions.d.ts +10 -6
- package/dist/agent-runtime/sqlite-transactions.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite.d.ts +10 -29
- package/dist/agent-runtime/sqlite.d.ts.map +1 -1
- package/dist/agent-runtime/state-tools.d.ts +8 -4
- package/dist/agent-runtime/state-tools.d.ts.map +1 -1
- package/dist/agent-runtime/store-archive.d.ts.map +1 -1
- package/dist/agent-runtime/store-branch.d.ts +6 -1
- package/dist/agent-runtime/store-branch.d.ts.map +1 -1
- package/dist/agent-runtime/store-capabilities.d.ts +42 -0
- package/dist/agent-runtime/store-capabilities.d.ts.map +1 -0
- package/dist/agent-runtime/store-conformance-branch.d.ts +5 -2
- package/dist/agent-runtime/store-conformance-branch.d.ts.map +1 -1
- package/dist/agent-runtime/store-conformance-capabilities.d.ts +6 -0
- package/dist/agent-runtime/store-conformance-capabilities.d.ts.map +1 -0
- package/dist/agent-runtime/store-conformance-event-once.d.ts +12 -0
- package/dist/agent-runtime/store-conformance-event-once.d.ts.map +1 -0
- package/dist/agent-runtime/store-conformance-lifecycle.d.ts +20 -20
- package/dist/agent-runtime/store-conformance-seed.d.ts +8 -0
- package/dist/agent-runtime/store-conformance-seed.d.ts.map +1 -0
- package/dist/agent-runtime/store-conformance.d.ts +31 -8
- package/dist/agent-runtime/store-conformance.d.ts.map +1 -1
- package/dist/agent-runtime/store-create.d.ts +1 -1
- package/dist/agent-runtime/store-create.d.ts.map +1 -1
- package/dist/agent-runtime/store-driver-contract.d.ts +15 -8
- package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -1
- package/dist/agent-runtime/store-event-once.d.ts.map +1 -1
- package/dist/agent-runtime/store-events.d.ts +114 -0
- package/dist/agent-runtime/store-events.d.ts.map +1 -1
- package/dist/agent-runtime/store-memory-archive.d.ts +2 -0
- package/dist/agent-runtime/store-memory-archive.d.ts.map +1 -1
- package/dist/agent-runtime/store-memory.d.ts +2 -2
- package/dist/agent-runtime/store-memory.d.ts.map +1 -1
- package/dist/agent-runtime/store-mutate.d.ts.map +1 -1
- package/dist/agent-runtime/store-reduce-shared.d.ts +2 -1
- package/dist/agent-runtime/store-reduce-shared.d.ts.map +1 -1
- package/dist/agent-runtime/store-reducer.d.ts.map +1 -1
- package/dist/agent-runtime/store-replay.d.ts.map +1 -1
- package/dist/agent-runtime/store.d.ts +15 -2
- package/dist/agent-runtime/store.d.ts.map +1 -1
- package/dist/agent-runtime/terminal-commit.d.ts +10 -10
- package/dist/application/admission-run.d.ts.map +1 -1
- package/dist/application/admission.d.ts.map +1 -1
- package/dist/application/change-subscription.d.ts.map +1 -1
- package/dist/application/decisions.d.ts.map +1 -1
- package/dist/application/diagnostic-journal-lock-format.d.ts +9 -0
- package/dist/application/diagnostic-journal-lock-format.d.ts.map +1 -0
- package/dist/application/diagnostic-journal-manager.d.ts.map +1 -1
- package/dist/application/directory-inbox-delivery.d.ts.map +1 -1
- package/dist/application/grammy-update-admission.d.ts.map +1 -1
- package/dist/application/health.d.ts.map +1 -1
- package/dist/application/kernel-admission.d.ts.map +1 -1
- package/dist/application/kernel-contract.d.ts.map +1 -1
- package/dist/application/kernel-restart.d.ts.map +1 -1
- package/dist/application/kernel-rollback.d.ts.map +1 -1
- package/dist/application/kernel-shutdown.d.ts.map +1 -1
- package/dist/application/kernel-state.d.ts.map +1 -1
- package/dist/application/notification-outbox-state.d.ts.map +1 -1
- package/dist/application/notification-outbox.d.ts +1 -1
- package/dist/application/notification-outbox.d.ts.map +1 -1
- package/dist/application/revision-signal.d.ts.map +1 -1
- package/dist/application/schedule-run.d.ts.map +1 -1
- package/dist/application/schedule.d.ts.map +1 -1
- package/dist/application/sqlite-migrations.d.ts +104 -0
- package/dist/application/sqlite-migrations.d.ts.map +1 -0
- package/dist/application/watch-hub-core.d.ts +2 -1
- package/dist/application/watch-hub-core.d.ts.map +1 -1
- package/dist/application/watch-hub-source.d.ts +2 -0
- package/dist/application/watch-hub-source.d.ts.map +1 -1
- package/dist/application/watch-hub.d.ts +20 -1
- package/dist/application/watch-hub.d.ts.map +1 -1
- package/dist/browser/bridge-errors.d.ts +24 -0
- package/dist/browser/bridge-errors.d.ts.map +1 -0
- package/dist/browser/bridge-fetch.d.ts +30 -0
- package/dist/browser/bridge-fetch.d.ts.map +1 -0
- package/dist/browser/bridge-inbound.d.ts +28 -0
- package/dist/browser/bridge-inbound.d.ts.map +1 -0
- package/dist/browser/cancellation.d.ts +10 -2
- package/dist/browser/cancellation.d.ts.map +1 -1
- package/dist/browser/chunked-upload.d.ts +1 -1
- package/dist/browser/chunked-upload.d.ts.map +1 -1
- package/dist/browser/client-call-arguments.d.ts +31 -0
- package/dist/browser/client-call-arguments.d.ts.map +1 -0
- package/dist/browser/client-executors.d.ts +6 -0
- package/dist/browser/client-executors.d.ts.map +1 -1
- package/dist/browser/client.d.ts +9 -0
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/http.d.ts +17 -2
- package/dist/browser/http.d.ts.map +1 -1
- package/dist/browser/realtime-client.d.ts +0 -5
- package/dist/browser/realtime-client.d.ts.map +1 -1
- package/dist/browser/session-credentials-storage.d.ts +48 -0
- package/dist/browser/session-credentials-storage.d.ts.map +1 -0
- package/dist/browser/session-credentials.d.ts +26 -5
- package/dist/browser/session-credentials.d.ts.map +1 -1
- package/dist/browser/session-refresh-policy.d.ts +124 -0
- package/dist/browser/session-refresh-policy.d.ts.map +1 -0
- package/dist/browser/session-refresh-timer.d.ts +30 -0
- package/dist/browser/session-refresh-timer.d.ts.map +1 -0
- package/dist/browser/session.d.ts.map +1 -1
- package/dist/browser/socket-io-connection.d.ts.map +1 -1
- package/dist/browser/socket-io-explicit-peer.d.ts +0 -1
- package/dist/browser/socket-io-explicit-peer.d.ts.map +1 -1
- package/dist/browser/stream.d.ts +1 -1
- package/dist/browser/stream.d.ts.map +1 -1
- package/dist/browser/upload-progress.d.ts +3 -0
- package/dist/browser/upload-progress.d.ts.map +1 -1
- package/dist/contract/bridge-envelope.d.ts +155 -0
- package/dist/contract/bridge-envelope.d.ts.map +1 -0
- package/dist/contract/define-validation.d.ts +2 -0
- package/dist/contract/define-validation.d.ts.map +1 -1
- package/dist/contract/define.d.ts +3 -0
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/errors.d.ts +4 -4
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/normalize.d.ts +3 -1
- package/dist/contract/normalize.d.ts.map +1 -1
- package/dist/contract/operation-effect.d.ts +29 -0
- package/dist/contract/operation-effect.d.ts.map +1 -0
- package/dist/contract/runtime-context.d.ts +2 -0
- package/dist/contract/runtime-context.d.ts.map +1 -1
- package/dist/contract/tool-options.d.ts +7 -0
- package/dist/contract/tool-options.d.ts.map +1 -1
- package/dist/declaration/command.d.ts +26 -0
- package/dist/declaration/command.d.ts.map +1 -0
- package/dist/declaration/declaration.d.ts +4 -22
- package/dist/declaration/declaration.d.ts.map +1 -1
- package/dist/declaration/machine-names.d.ts +11 -0
- package/dist/declaration/machine-names.d.ts.map +1 -0
- package/dist/durability/effect.d.ts.map +1 -1
- package/dist/durability/engine.d.ts.map +1 -1
- package/dist/durability/events.d.ts +5 -8
- package/dist/durability/events.d.ts.map +1 -1
- package/dist/durability/parks.d.ts +0 -5
- package/dist/durability/parks.d.ts.map +1 -1
- package/dist/durability/scheduler.d.ts +5 -0
- package/dist/durability/scheduler.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.d.ts +4 -0
- package/dist/entrypoints/agent-executor/acp.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor/acp.js +910 -0
- package/dist/entrypoints/agent-executor/claude-sdk.d.ts +2 -0
- package/dist/entrypoints/agent-executor/claude-sdk.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor/claude-sdk.js +309 -0
- package/dist/entrypoints/agent-executor/claude.d.ts +5 -0
- package/dist/entrypoints/agent-executor/claude.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor/claude.js +403 -0
- package/dist/entrypoints/agent-executor/codex.d.ts +4 -0
- package/dist/entrypoints/agent-executor/codex.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor/codex.js +798 -0
- package/dist/entrypoints/agent-executor/testing.d.ts +4 -0
- package/dist/entrypoints/agent-executor/testing.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor/testing.js +375 -0
- package/dist/entrypoints/agent-executor.d.ts +15 -0
- package/dist/entrypoints/agent-executor.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor.js +455 -0
- package/dist/entrypoints/agent-runtime/browser.d.ts +1 -0
- package/dist/entrypoints/agent-runtime/browser.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/browser.js +60 -30
- package/dist/entrypoints/agent-runtime/coding-tools.js +9 -12
- package/dist/entrypoints/agent-runtime/harness.js +35 -22
- package/dist/entrypoints/agent-runtime/openrouter.d.ts +6 -0
- package/dist/entrypoints/agent-runtime/openrouter.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/openrouter.js +675 -45
- package/dist/entrypoints/agent-runtime/postgres.d.ts +4 -0
- package/dist/entrypoints/agent-runtime/postgres.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/postgres.js +330 -0
- package/dist/entrypoints/agent-runtime/realtime.js +46 -49
- package/dist/entrypoints/agent-runtime/sandbox.d.ts +3 -1
- package/dist/entrypoints/agent-runtime/sandbox.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/sandbox.js +74 -67
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +18 -18
- package/dist/entrypoints/agent-runtime/sqlite/node.js +18 -18
- package/dist/entrypoints/agent-runtime/testing.d.ts +1 -1
- package/dist/entrypoints/agent-runtime/testing.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/testing.js +419 -96
- package/dist/entrypoints/agent-runtime.d.ts +21 -13
- package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime.js +1280 -1086
- package/dist/entrypoints/application/diagnostic-journal.js +16 -11
- package/dist/entrypoints/application/directory-inbox.js +20 -14
- package/dist/entrypoints/application/grammy.js +11 -8
- package/dist/entrypoints/application/opentelemetry.js +3 -3
- package/dist/entrypoints/application.d.ts +5 -3
- package/dist/entrypoints/application.d.ts.map +1 -1
- package/dist/entrypoints/application.js +464 -116
- package/dist/entrypoints/bin/upgrade-cli.d.ts +0 -12
- package/dist/entrypoints/bin/upgrade-cli.d.ts.map +1 -1
- package/dist/entrypoints/bin/upgrade-cli.js +13 -7
- package/dist/entrypoints/cli/publish.js +10 -9
- package/dist/entrypoints/cli.d.ts +10 -3
- package/dist/entrypoints/cli.d.ts.map +1 -1
- package/dist/entrypoints/cli.js +91 -29
- package/dist/entrypoints/contract.d.ts +2 -1
- package/dist/entrypoints/contract.d.ts.map +1 -1
- package/dist/entrypoints/contract.js +13 -7
- package/dist/entrypoints/declaration.d.ts +2 -0
- package/dist/entrypoints/declaration.d.ts.map +1 -1
- package/dist/entrypoints/declaration.js +55 -44
- package/dist/entrypoints/files/packaging.js +8 -5
- package/dist/entrypoints/files.d.ts +5 -0
- package/dist/entrypoints/files.d.ts.map +1 -1
- package/dist/entrypoints/files.js +236 -47
- package/dist/entrypoints/geo.js +9 -4
- package/dist/entrypoints/google.js +14 -13
- package/dist/entrypoints/handler.d.ts +12 -0
- package/dist/entrypoints/handler.d.ts.map +1 -0
- package/dist/entrypoints/handler.js +350 -0
- package/dist/entrypoints/http.d.ts +4 -0
- package/dist/entrypoints/http.d.ts.map +1 -1
- package/dist/entrypoints/http.js +411 -5
- package/dist/entrypoints/index.d.ts +2 -0
- package/dist/entrypoints/index.d.ts.map +1 -1
- package/dist/entrypoints/index.js +664 -91
- package/dist/entrypoints/live.js +22 -12
- package/dist/entrypoints/node.d.ts +2 -1
- package/dist/entrypoints/node.d.ts.map +1 -1
- package/dist/entrypoints/node.js +34 -24
- package/dist/entrypoints/observability.d.ts +2 -0
- package/dist/entrypoints/observability.d.ts.map +1 -1
- package/dist/entrypoints/observability.js +205 -131
- package/dist/entrypoints/primitives.js +152 -14
- package/dist/entrypoints/process/owner-loss.js +2 -2
- package/dist/entrypoints/process.js +18 -92
- package/dist/entrypoints/react.js +6 -5
- package/dist/entrypoints/realtime.d.ts +1 -0
- package/dist/entrypoints/realtime.d.ts.map +1 -1
- package/dist/entrypoints/realtime.js +6 -3
- package/dist/entrypoints/release.js +4 -0
- package/dist/entrypoints/remote.js +7 -6
- package/dist/entrypoints/server.d.ts +4 -2
- package/dist/entrypoints/server.d.ts.map +1 -1
- package/dist/entrypoints/server.js +300 -199
- package/dist/entrypoints/service-host/macos.d.ts +16 -0
- package/dist/entrypoints/service-host/macos.d.ts.map +1 -0
- package/dist/entrypoints/service-host/macos.js +1998 -0
- package/dist/entrypoints/service-host.d.ts +23 -0
- package/dist/entrypoints/service-host.d.ts.map +1 -0
- package/dist/entrypoints/service-host.js +2544 -0
- package/dist/entrypoints/spend/testing.d.ts +2 -0
- package/dist/entrypoints/spend/testing.d.ts.map +1 -0
- package/dist/entrypoints/spend/testing.js +442 -0
- package/dist/entrypoints/spend.d.ts +8 -0
- package/dist/entrypoints/spend.d.ts.map +1 -0
- package/dist/entrypoints/spend.js +593 -0
- package/dist/entrypoints/sync/postgres.d.ts +12 -0
- package/dist/entrypoints/sync/postgres.d.ts.map +1 -0
- package/dist/entrypoints/sync/postgres.js +737 -0
- package/dist/entrypoints/sync.d.ts +12 -0
- package/dist/entrypoints/sync.d.ts.map +1 -0
- package/dist/entrypoints/sync.js +782 -0
- package/dist/entrypoints/telegram/grammy.js +5 -5
- package/dist/entrypoints/telegram/html.d.ts +2 -0
- package/dist/entrypoints/telegram/html.d.ts.map +1 -1
- package/dist/entrypoints/telegram/html.js +839 -2
- package/dist/entrypoints/telegram/screens.js +13 -15
- package/dist/entrypoints/telegram.d.ts +1 -1
- package/dist/entrypoints/telegram.d.ts.map +1 -1
- package/dist/entrypoints/telegram.js +286 -76
- package/dist/entrypoints/testing.js +33 -41
- package/dist/entrypoints/tools/agent.js +12 -9
- package/dist/entrypoints/tools/connections.js +664 -63
- package/dist/entrypoints/tools/contract.d.ts +2 -2
- package/dist/entrypoints/tools/contract.js +4 -1
- package/dist/entrypoints/tools/invoker.js +9 -7
- package/dist/entrypoints/tools/mcp.js +16 -11
- package/dist/entrypoints/tools/toolkit.js +21 -16
- package/dist/entrypoints/tools.d.ts +3 -1
- package/dist/entrypoints/tools.d.ts.map +1 -1
- package/dist/entrypoints/tools.js +107 -94
- package/dist/entrypoints/tracking/contract.js +2 -1
- package/dist/entrypoints/tracking/performance.js +4 -0
- package/dist/entrypoints/tracking.js +6 -1
- package/dist/entrypoints/voice.js +3 -3
- package/dist/entrypoints/xlsx.js +1 -1
- package/dist/files/boundary.d.ts.map +1 -1
- package/dist/files/chunk-spool.d.ts +27 -0
- package/dist/files/chunk-spool.d.ts.map +1 -1
- package/dist/files/directory-appearance.d.ts +44 -0
- package/dist/files/directory-appearance.d.ts.map +1 -0
- package/dist/files/file-io.d.ts.map +1 -1
- package/dist/files/file-stamp.d.ts +35 -0
- package/dist/files/file-stamp.d.ts.map +1 -0
- package/dist/files/json-file-reading.d.ts +37 -0
- package/dist/files/json-file-reading.d.ts.map +1 -0
- package/dist/files/native-packaging.d.ts.map +1 -1
- package/dist/files/polled-json.d.ts +121 -0
- package/dist/files/polled-json.d.ts.map +1 -0
- package/dist/files/regular-file.d.ts +125 -0
- package/dist/files/regular-file.d.ts.map +1 -0
- package/dist/geo/index.d.ts +2 -1
- package/dist/geo/index.d.ts.map +1 -1
- package/dist/geo/resolver.d.ts.map +1 -1
- package/dist/geo/types.d.ts +0 -1
- package/dist/geo/types.d.ts.map +1 -1
- package/dist/google/google.d.ts +6 -0
- package/dist/google/google.d.ts.map +1 -1
- package/dist/{index-w0eqdhyd.js → index-09f7w2qq.js} +6 -1
- package/dist/index-0djnptn8.js +501 -0
- package/dist/index-0hdm5sx6.js +1457 -0
- package/dist/{index-t05a2ry4.js → index-0p0s5hrj.js} +8 -14
- package/dist/{index-1c945ten.js → index-0r15pkjq.js} +1 -1
- package/dist/{index-v1swr26p.js → index-0tyt97nk.js} +2 -2
- package/dist/{index-332d0m9g.js → index-0x4mnwg5.js} +4 -0
- package/dist/index-118aebbg.js +48 -0
- package/dist/index-1q0n6zek.js +184 -0
- package/dist/index-27hck3z2.js +307 -0
- package/dist/index-2rf33y2h.js +77 -0
- package/dist/index-360j58vb.js +63 -0
- package/dist/{index-tt30h7mr.js → index-39n02e0q.js} +1 -1
- package/dist/index-3agqmmrg.js +42 -0
- package/dist/{index-n6hvd1r2.js → index-3b31z0pc.js} +22 -15
- package/dist/index-3djgv3ch.js +472 -0
- package/dist/{index-mfntvj58.js → index-3dq8466w.js} +1 -1
- package/dist/index-3gwp8ez6.js +200 -0
- package/dist/{index-x2d51zay.js → index-3ypvpkwr.js} +309 -345
- package/dist/index-4gk6k3zc.js +248 -0
- package/dist/index-4qvyhn23.js +40 -0
- package/dist/index-4s2w4g37.js +647 -0
- package/dist/index-4ynw5ktx.js +78 -0
- package/dist/index-5awtbyns.js +19 -0
- package/dist/{index-kxff9e9w.js → index-5e0zsbf7.js} +5 -4
- package/dist/{index-nz06qw5a.js → index-5jyjb4s0.js} +1 -1
- package/dist/{index-7q05ag0z.js → index-5ptwb6ka.js} +1 -1
- package/dist/{index-w3nv6kr8.js → index-5q0qpw3v.js} +54 -9
- package/dist/{index-mm89hd8v.js → index-5t4fpdct.js} +1 -1
- package/dist/{index-0v9xb8pz.js → index-5y7j383h.js} +5 -5
- package/dist/index-5zwac8ft.js +221 -0
- package/dist/{index-v62cpkx3.js → index-6g85s734.js} +1 -1
- package/dist/{index-sqc6ezrb.js → index-6kec3b14.js} +17 -4
- package/dist/{index-kqnd6a85.js → index-7416mhyh.js} +1 -1
- package/dist/{index-m0wsfmrc.js → index-7csn6pva.js} +37 -24
- package/dist/{index-dqpesdck.js → index-7grgs8cx.js} +25 -5
- package/dist/{index-gdqawggb.js → index-7kfcb576.js} +143 -39
- package/dist/{index-cvjddnvd.js → index-7xp05h20.js} +19 -10
- package/dist/{index-fgzbc06j.js → index-83n766x4.js} +91 -50
- package/dist/{index-ss67fxhj.js → index-877e9y8r.js} +7 -7
- package/dist/{index-aw6kx2e6.js → index-8gmmdz7k.js} +1 -1
- package/dist/{index-wt6rw7rf.js → index-8xr2eq99.js} +29 -21
- package/dist/{index-rz3z13e9.js → index-97q9kykw.js} +1 -1
- package/dist/index-97rp94ff.js +8 -0
- package/dist/{index-0w0hxp7n.js → index-9pv126eh.js} +3 -9
- package/dist/{index-x2rvpbtj.js → index-9wh98cpa.js} +110 -16
- package/dist/{index-egg0yp2j.js → index-9xr44d2g.js} +86 -210
- package/dist/{index-b2sey031.js → index-9y0afd5f.js} +24 -23
- package/dist/index-a725ayvz.js +405 -0
- package/dist/{index-nmaqxdx7.js → index-ac5rj3d4.js} +203 -90
- package/dist/{index-wqzw3qg9.js → index-agy5fqgf.js} +32 -13
- package/dist/index-ajmtxsky.js +193 -0
- package/dist/{index-ndjzbt2v.js → index-akf0xkrm.js} +4 -3
- package/dist/index-akfgymyr.js +8 -0
- package/dist/index-apv5xfef.js +13 -0
- package/dist/index-ax3wns1a.js +93 -0
- package/dist/{index-0sg3wnzr.js → index-bbzvrq66.js} +1670 -340
- package/dist/index-bh4pmtr9.js +317 -0
- package/dist/{index-fa53vygr.js → index-bmaz3jzy.js} +3 -3
- package/dist/{index-8kzct1d6.js → index-bn2baakz.js} +143 -143
- package/dist/{index-m8ddk770.js → index-brhhaygm.js} +1 -1
- package/dist/index-caywx1c0.js +199 -0
- package/dist/index-cbhxhma2.js +90 -0
- package/dist/index-cfnmvcq8.js +11 -0
- package/dist/index-cv9b7fz2.js +42 -0
- package/dist/index-d4svrknj.js +156 -0
- package/dist/{index-a3z56mtn.js → index-d96c1n1q.js} +5 -3
- package/dist/{index-3ymcmpa9.js → index-dvd1qdwa.js} +33 -163
- package/dist/{index-v7rbjatr.js → index-dwa6pskj.js} +1837 -1151
- package/dist/{index-ne4j9998.js → index-e06z0tkb.js} +123 -94
- package/dist/{index-99nnsz39.js → index-en8e5zsj.js} +15 -135
- package/dist/index-fcw255hd.js +929 -0
- package/dist/{index-20hn8pbh.js → index-fmzg39a8.js} +1 -1
- package/dist/{index-fvd6pvw3.js → index-g1q7fwn9.js} +2 -2
- package/dist/index-g56ht6qf.js +98 -0
- package/dist/{index-f56ct5gb.js → index-gj1rjf78.js} +4 -3
- package/dist/{index-g6a3na27.js → index-gnjgkecx.js} +7 -3
- package/dist/index-hy4653g4.js +345 -0
- package/dist/index-j13gzgdv.js +403 -0
- package/dist/{index-r8swbw1x.js → index-j516jaaz.js} +37 -11
- package/dist/{index-t8jz0e20.js → index-j903yhp4.js} +30 -38
- package/dist/{index-9ypczvpj.js → index-jb4m241t.js} +2 -0
- package/dist/index-jrka9029.js +177 -0
- package/dist/{index-cjzaj7ev.js → index-jxtg307y.js} +23 -21
- package/dist/index-kmbpej2y.js +1152 -0
- package/dist/{index-bz9cmnqq.js → index-kt6dh1n6.js} +4 -4
- package/dist/index-ky3ardqn.js +80 -0
- package/dist/index-kyejf658.js +14 -0
- package/dist/{index-zyc64nbh.js → index-kynwa08q.js} +52 -47
- package/dist/index-kzavdze2.js +15 -0
- package/dist/{index-pq7rkwkk.js → index-mbd92r1w.js} +67 -12
- package/dist/index-mxt0wfjy.js +58 -0
- package/dist/{index-9cxxfkhb.js → index-n20tybgk.js} +14 -9
- package/dist/index-nbv44x0x.js +250 -0
- package/dist/index-ngwf1s3c.js +51 -0
- package/dist/{index-zfncctjp.js → index-nk0cy9g1.js} +5 -4
- package/dist/index-p1m9djt6.js +108 -0
- package/dist/{index-hs76yzt7.js → index-paff5y0r.js} +17 -11
- package/dist/{index-qaet40b2.js → index-prf6ayhf.js} +5 -7
- package/dist/{index-hkxgennw.js → index-ps3djm8d.js} +7 -1
- package/dist/{index-1v3k5zgx.js → index-qnzhmk2s.js} +528 -1129
- package/dist/{index-3bzk2645.js → index-r9kq5ark.js} +1 -1
- package/dist/{index-hkw233vx.js → index-rbd2rq3z.js} +2 -2
- package/dist/{index-r0xr7y4m.js → index-rhb33thr.js} +138 -33
- package/dist/{index-kffm4r8w.js → index-rj32hkkp.js} +2 -2
- package/dist/index-rptj3qnc.js +96 -0
- package/dist/{index-hqsbtvta.js → index-rpyn7geq.js} +11 -3
- package/dist/{index-m9hb9wnk.js → index-sfzfd2m2.js} +2 -2
- package/dist/{index-sqkttz7z.js → index-sv5svtq7.js} +1 -1
- package/dist/{index-srs8hj9c.js → index-sx3g49y2.js} +5 -1
- package/dist/{index-9mjrnqxs.js → index-t1a2jrg7.js} +21 -91
- package/dist/{index-568w258r.js → index-tazm4dxf.js} +1 -1
- package/dist/{index-b51tzcgh.js → index-tf70nm22.js} +2 -2
- package/dist/index-ttexdtjj.js +28 -0
- package/dist/{index-gbj964dt.js → index-v37b2cd6.js} +1970 -3142
- package/dist/{index-0ndz5r8z.js → index-v59pxmf1.js} +17 -9
- package/dist/{index-rfkh44ss.js → index-vgytj9wp.js} +1 -1
- package/dist/{index-tnnmekgb.js → index-wa6h4tz6.js} +3 -3
- package/dist/{index-8wzhmgpa.js → index-wavv538x.js} +211 -196
- package/dist/{index-1szhrfsf.js → index-wbnpa8z6.js} +7 -5
- package/dist/index-werjqesf.js +43 -0
- package/dist/{index-7qyv50r4.js → index-wv8dqy7q.js} +2 -2
- package/dist/index-wz392jyz.js +10 -0
- package/dist/{index-1d7s7da0.js → index-x6sp5vpa.js} +36 -5
- package/dist/{index-bqzgaj57.js → index-x90w78yz.js} +183 -61
- package/dist/index-xgae0bn7.js +37 -0
- package/dist/index-xmr47znh.js +160 -0
- package/dist/{index-ftk3838x.js → index-xq4s9mka.js} +7 -2
- package/dist/{index-ww3gss55.js → index-xrgn784x.js} +1 -1
- package/dist/{index-fpwbskp2.js → index-xtby8rj3.js} +1 -1
- package/dist/index-xtkw9866.js +107 -0
- package/dist/{index-btjwc7xr.js → index-xypxnzhp.js} +15 -14
- package/dist/{index-yex7eg1v.js → index-y7sy1xdp.js} +6 -2
- package/dist/index-z4k0hqp9.js +476 -0
- package/dist/{index-a7ebd769.js → index-zwgwyvdt.js} +3 -3
- package/dist/internal/abort-error.d.ts +9 -0
- package/dist/internal/abort-error.d.ts.map +1 -0
- package/dist/internal/abort-race.d.ts +47 -4
- package/dist/internal/abort-race.d.ts.map +1 -1
- package/dist/internal/atomic-file.d.ts +19 -0
- package/dist/internal/atomic-file.d.ts.map +1 -1
- package/dist/internal/backoff.d.ts.map +1 -1
- package/dist/internal/bounded-body.d.ts +37 -1
- package/dist/internal/bounded-body.d.ts.map +1 -1
- package/dist/internal/bounded-file-read.d.ts +31 -15
- package/dist/internal/bounded-file-read.d.ts.map +1 -1
- package/dist/internal/bun-command.d.ts +11 -0
- package/dist/internal/bun-command.d.ts.map +1 -1
- package/dist/internal/channel.d.ts.map +1 -1
- package/dist/internal/coalesced-task.d.ts +14 -2
- package/dist/internal/coalesced-task.d.ts.map +1 -1
- package/dist/internal/darwin-binding-error.d.ts.map +1 -1
- package/dist/internal/darwin-binding.d.ts +10 -0
- package/dist/internal/darwin-binding.d.ts.map +1 -1
- package/dist/internal/deadline.d.ts +22 -2
- package/dist/internal/deadline.d.ts.map +1 -1
- package/dist/internal/exclusive-lock-owner.d.ts +20 -1
- package/dist/internal/exclusive-lock-owner.d.ts.map +1 -1
- package/dist/internal/exclusive-lock-read.d.ts +2 -0
- package/dist/internal/exclusive-lock-read.d.ts.map +1 -1
- package/dist/internal/exclusive-lock.d.ts +26 -0
- package/dist/internal/exclusive-lock.d.ts.map +1 -1
- package/dist/internal/file-observation.d.ts +49 -0
- package/dist/internal/file-observation.d.ts.map +1 -1
- package/dist/internal/json-response.d.ts +10 -0
- package/dist/internal/json-response.d.ts.map +1 -0
- package/dist/internal/open-descriptors.d.ts +5 -0
- package/dist/internal/open-descriptors.d.ts.map +1 -1
- package/dist/internal/optional-peer.d.ts.map +1 -1
- package/dist/internal/pinned-http.d.ts.map +1 -1
- package/dist/internal/positive-integer.d.ts +14 -6
- package/dist/internal/positive-integer.d.ts.map +1 -1
- package/dist/internal/postgres-query.d.ts +16 -0
- package/dist/internal/postgres-query.d.ts.map +1 -0
- package/dist/internal/process-identity.d.ts +21 -1
- package/dist/internal/process-identity.d.ts.map +1 -1
- package/dist/internal/process-instance.d.ts +6 -0
- package/dist/internal/process-instance.d.ts.map +1 -1
- package/dist/internal/request.d.ts +4 -0
- package/dist/internal/request.d.ts.map +1 -1
- package/dist/internal/secret-equal.d.ts +11 -0
- package/dist/internal/secret-equal.d.ts.map +1 -0
- package/dist/internal/secure-fetch.d.ts.map +1 -1
- package/dist/internal/sqlite.d.ts +8 -0
- package/dist/internal/sqlite.d.ts.map +1 -1
- package/dist/internal/timers.d.ts +20 -0
- package/dist/internal/timers.d.ts.map +1 -1
- package/dist/internal/typed.d.ts +11 -0
- package/dist/internal/typed.d.ts.map +1 -1
- package/dist/internal/unix-client-error.d.ts +21 -0
- package/dist/internal/unix-client-error.d.ts.map +1 -0
- package/dist/internal/unix-socket-lock.d.ts +23 -0
- package/dist/internal/unix-socket-lock.d.ts.map +1 -0
- package/dist/internal/unix-socket.d.ts +60 -0
- package/dist/internal/unix-socket.d.ts.map +1 -1
- package/dist/internal/upgrade-affects.d.ts +3 -3
- package/dist/internal/upgrade-affects.d.ts.map +1 -1
- package/dist/internal/upgrade-plan.d.ts.map +1 -1
- package/dist/json-schema/dialect.d.ts +0 -6
- package/dist/json-schema/dialect.d.ts.map +1 -1
- package/dist/json-schema/keywords.d.ts +116 -0
- package/dist/json-schema/keywords.d.ts.map +1 -0
- package/dist/json-schema/string-format.d.ts.map +1 -1
- package/dist/live/events.d.ts.map +1 -1
- package/dist/live/watch-client.d.ts.map +1 -1
- package/dist/observability/bounded-logger.d.ts +3 -0
- package/dist/observability/bounded-logger.d.ts.map +1 -1
- package/dist/observability/bounded-sink.d.ts.map +1 -1
- package/dist/observability/context.d.ts +12 -2
- package/dist/observability/context.d.ts.map +1 -1
- package/dist/observability/event-loop-delay.d.ts +62 -0
- package/dist/observability/event-loop-delay.d.ts.map +1 -0
- package/dist/observability/json-logger.d.ts.map +1 -1
- package/dist/observability/log-repeat.d.ts +44 -0
- package/dist/observability/log-repeat.d.ts.map +1 -0
- package/dist/observability/spool-core.d.ts +95 -0
- package/dist/observability/spool-core.d.ts.map +1 -0
- package/dist/observability/spool-file.d.ts +46 -0
- package/dist/observability/spool-file.d.ts.map +1 -0
- package/dist/observability/spool.d.ts +14 -8
- package/dist/observability/spool.d.ts.map +1 -1
- package/dist/observability/trace.d.ts.map +1 -1
- package/dist/observability/work.d.ts.map +1 -1
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/order-key.d.ts +37 -0
- package/dist/primitives/order-key.d.ts.map +1 -0
- package/dist/process/bun-child.d.ts.map +1 -1
- package/dist/process/command-owner.d.ts.map +1 -1
- package/dist/process/contract.d.ts +4 -3
- package/dist/process/contract.d.ts.map +1 -1
- package/dist/process/group-presence.d.ts.map +1 -1
- package/dist/process/group-settlement.d.ts +2 -0
- package/dist/process/group-settlement.d.ts.map +1 -1
- package/dist/process/group.d.ts +5 -1
- package/dist/process/group.d.ts.map +1 -1
- package/dist/process/launch.d.ts +5 -3
- package/dist/process/launch.d.ts.map +1 -1
- package/dist/process/owner-loss-guard.d.ts.map +1 -1
- package/dist/react/cache-bridge.d.ts.map +1 -1
- package/dist/release/watcher.d.ts.map +1 -1
- package/dist/server/bridge-host.d.ts +51 -0
- package/dist/server/bridge-host.d.ts.map +1 -0
- package/dist/server/bun.d.ts +4 -4
- package/dist/server/bun.d.ts.map +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.map +1 -1
- package/dist/server/create.d.ts +1 -0
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/endpoint-dispatch.d.ts.map +1 -1
- package/dist/server/endpoint-response.d.ts.map +1 -1
- package/dist/server/error-dispatch.d.ts +4 -0
- package/dist/server/error-dispatch.d.ts.map +1 -1
- package/dist/server/error-hook.d.ts +2 -0
- package/dist/server/error-hook.d.ts.map +1 -1
- package/dist/server/handler-state.d.ts +16 -2
- package/dist/server/handler-state.d.ts.map +1 -1
- package/dist/server/implement.d.ts +1 -0
- package/dist/server/implement.d.ts.map +1 -1
- package/dist/server/local-host.d.ts +47 -0
- package/dist/server/local-host.d.ts.map +1 -0
- package/dist/server/logger.d.ts +20 -3
- package/dist/server/logger.d.ts.map +1 -1
- package/dist/server/logging.d.ts +2 -1
- package/dist/server/logging.d.ts.map +1 -1
- package/dist/server/middleware/cors.d.ts +49 -3
- package/dist/server/middleware/cors.d.ts.map +1 -1
- package/dist/server/middleware/signed-link.d.ts +42 -0
- package/dist/server/middleware/signed-link.d.ts.map +1 -0
- package/dist/server/multipart-reader.d.ts +3 -1
- package/dist/server/multipart-reader.d.ts.map +1 -1
- package/dist/server/multipart.d.ts.map +1 -1
- package/dist/server/oauth/cimd.d.ts.map +1 -1
- package/dist/server/oauth/endpoints.d.ts.map +1 -1
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/server/protocol-outcome.d.ts +17 -0
- package/dist/server/protocol-outcome.d.ts.map +1 -0
- package/dist/server/raw.d.ts.map +1 -1
- package/dist/server/request-completion.d.ts +3 -1
- package/dist/server/request-completion.d.ts.map +1 -1
- package/dist/server/shutdown.d.ts.map +1 -1
- package/dist/server/socket-io-config.d.ts +1 -1
- package/dist/server/socket-io-config.d.ts.map +1 -1
- package/dist/server/streaming-route.d.ts.map +1 -1
- package/dist/server/types.d.ts +20 -11
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/unix-client-body.d.ts +4 -1
- package/dist/server/unix-client-body.d.ts.map +1 -1
- package/dist/server/unix-client-bun.d.ts.map +1 -1
- package/dist/server/unix-client.d.ts +1 -1
- package/dist/server/unix-client.d.ts.map +1 -1
- package/dist/service-host/artifact-activation.d.ts +58 -0
- package/dist/service-host/artifact-activation.d.ts.map +1 -0
- package/dist/service-host/artifact-manifest.d.ts +68 -0
- package/dist/service-host/artifact-manifest.d.ts.map +1 -0
- package/dist/service-host/artifact.d.ts +43 -0
- package/dist/service-host/artifact.d.ts.map +1 -0
- package/dist/service-host/config-reloader-contract.d.ts +66 -0
- package/dist/service-host/config-reloader-contract.d.ts.map +1 -0
- package/dist/service-host/config-reloader-helpers.d.ts +32 -0
- package/dist/service-host/config-reloader-helpers.d.ts.map +1 -0
- package/dist/service-host/config-reloader-source.d.ts +47 -0
- package/dist/service-host/config-reloader-source.d.ts.map +1 -0
- package/dist/service-host/config-reloader.d.ts +6 -0
- package/dist/service-host/config-reloader.d.ts.map +1 -0
- package/dist/service-host/host-adapter.d.ts +72 -0
- package/dist/service-host/host-adapter.d.ts.map +1 -0
- package/dist/service-host/identity-unix-socket.d.ts +101 -0
- package/dist/service-host/identity-unix-socket.d.ts.map +1 -0
- package/dist/service-host/identity.d.ts +117 -0
- package/dist/service-host/identity.d.ts.map +1 -0
- package/dist/service-host/launchd-plist.d.ts +77 -0
- package/dist/service-host/launchd-plist.d.ts.map +1 -0
- package/dist/service-host/launchd-render.d.ts +91 -0
- package/dist/service-host/launchd-render.d.ts.map +1 -0
- package/dist/service-host/launchd.d.ts +82 -0
- package/dist/service-host/launchd.d.ts.map +1 -0
- package/dist/service-host/macos/bundle-plist.d.ts +50 -0
- package/dist/service-host/macos/bundle-plist.d.ts.map +1 -0
- package/dist/service-host/macos/bundle.d.ts +66 -0
- package/dist/service-host/macos/bundle.d.ts.map +1 -0
- package/dist/service-host/macos/codesign.d.ts +95 -0
- package/dist/service-host/macos/codesign.d.ts.map +1 -0
- package/dist/service-host/macos/icon.d.ts +93 -0
- package/dist/service-host/macos/icon.d.ts.map +1 -0
- package/dist/service-host/macos/launch-services.d.ts +88 -0
- package/dist/service-host/macos/launch-services.d.ts.map +1 -0
- package/dist/service-host/macos/launcher.d.ts +59 -0
- package/dist/service-host/macos/launcher.d.ts.map +1 -0
- package/dist/service-host/macos/responsibility.d.ts +90 -0
- package/dist/service-host/macos/responsibility.d.ts.map +1 -0
- package/dist/service-host/macos/runner.d.ts +69 -0
- package/dist/service-host/macos/runner.d.ts.map +1 -0
- package/dist/service-host/plist-xml.d.ts +48 -0
- package/dist/service-host/plist-xml.d.ts.map +1 -0
- package/dist/service-host/process-evidence.d.ts +17 -0
- package/dist/service-host/process-evidence.d.ts.map +1 -0
- package/dist/service-host/systemd-inspect.d.ts +126 -0
- package/dist/service-host/systemd-inspect.d.ts.map +1 -0
- package/dist/service-host/systemd-links.d.ts +23 -0
- package/dist/service-host/systemd-links.d.ts.map +1 -0
- package/dist/service-host/systemd-render.d.ts +93 -0
- package/dist/service-host/systemd-render.d.ts.map +1 -0
- package/dist/service-host/systemd.d.ts +50 -0
- package/dist/service-host/systemd.d.ts.map +1 -0
- package/dist/spend/attribution.d.ts +17 -0
- package/dist/spend/attribution.d.ts.map +1 -0
- package/dist/spend/coverage-guard.d.ts +60 -0
- package/dist/spend/coverage-guard.d.ts.map +1 -0
- package/dist/spend/coverage-lexer.d.ts +20 -0
- package/dist/spend/coverage-lexer.d.ts.map +1 -0
- package/dist/spend/facts.d.ts +23 -0
- package/dist/spend/facts.d.ts.map +1 -0
- package/dist/spend/gateway-stream.d.ts +25 -0
- package/dist/spend/gateway-stream.d.ts.map +1 -0
- package/dist/spend/gateway.d.ts +64 -0
- package/dist/spend/gateway.d.ts.map +1 -0
- package/dist/spend/receipt-merge.d.ts +13 -0
- package/dist/spend/receipt-merge.d.ts.map +1 -0
- package/dist/spend/receipt-spool.d.ts +35 -0
- package/dist/spend/receipt-spool.d.ts.map +1 -0
- package/dist/spend/reconcile.d.ts +45 -0
- package/dist/spend/reconcile.d.ts.map +1 -0
- package/dist/spend/schemas.d.ts +249 -0
- package/dist/spend/schemas.d.ts.map +1 -0
- package/dist/sync/outbox.d.ts +131 -0
- package/dist/sync/outbox.d.ts.map +1 -0
- package/dist/sync/overlay.d.ts +59 -0
- package/dist/sync/overlay.d.ts.map +1 -0
- package/dist/sync/protocol.d.ts +132 -0
- package/dist/sync/protocol.d.ts.map +1 -0
- package/dist/sync/server-store-check.d.ts +10 -0
- package/dist/sync/server-store-check.d.ts.map +1 -0
- package/dist/sync/server-store-memory.d.ts +14 -0
- package/dist/sync/server-store-memory.d.ts.map +1 -0
- package/dist/sync/server-store-postgres.d.ts +25 -0
- package/dist/sync/server-store-postgres.d.ts.map +1 -0
- package/dist/sync/server-store.d.ts +139 -0
- package/dist/sync/server-store.d.ts.map +1 -0
- package/dist/sync/session-machine.d.ts +79 -0
- package/dist/sync/session-machine.d.ts.map +1 -0
- package/dist/sync/session-snapshot.d.ts +19 -0
- package/dist/sync/session-snapshot.d.ts.map +1 -0
- package/dist/sync/session-steps.d.ts +15 -0
- package/dist/sync/session-steps.d.ts.map +1 -0
- package/dist/sync/session.d.ts +142 -0
- package/dist/sync/session.d.ts.map +1 -0
- package/dist/sync/tombstones.d.ts +53 -0
- package/dist/sync/tombstones.d.ts.map +1 -0
- package/dist/telegram/bot-api.d.ts.map +1 -1
- package/dist/telegram/broadcast-failure.d.ts.map +1 -1
- package/dist/telegram/budget-transformer.d.ts.map +1 -1
- package/dist/telegram/crypto.d.ts +2 -10
- package/dist/telegram/crypto.d.ts.map +1 -1
- package/dist/telegram/html/markdown-inline.d.ts +19 -0
- package/dist/telegram/html/markdown-inline.d.ts.map +1 -0
- package/dist/telegram/html/markdown-lines.d.ts +51 -0
- package/dist/telegram/html/markdown-lines.d.ts.map +1 -0
- package/dist/telegram/html/markdown-split.d.ts +49 -0
- package/dist/telegram/html/markdown-split.d.ts.map +1 -0
- package/dist/telegram/html/markdown.d.ts +14 -0
- package/dist/telegram/html/markdown.d.ts.map +1 -0
- package/dist/telegram/html/nodes.d.ts +26 -4
- package/dist/telegram/html/nodes.d.ts.map +1 -1
- package/dist/telegram/html/parse.d.ts.map +1 -1
- package/dist/telegram/html/render.d.ts.map +1 -1
- package/dist/telegram/init-data.d.ts.map +1 -1
- package/dist/telegram/local-files.d.ts.map +1 -1
- package/dist/telegram/operator-channel.d.ts +15 -2
- package/dist/telegram/operator-channel.d.ts.map +1 -1
- package/dist/telegram/outbound-budget.d.ts.map +1 -1
- package/dist/telegram/outbound-cost.d.ts +9 -1
- package/dist/telegram/outbound-cost.d.ts.map +1 -1
- package/dist/telegram/outbound-queue.d.ts +2 -1
- package/dist/telegram/outbound-queue.d.ts.map +1 -1
- package/dist/telegram/screens/outcome.d.ts.map +1 -1
- package/dist/telegram/send-failure.d.ts.map +1 -1
- package/dist/telegram/transport-connect.d.ts.map +1 -1
- package/dist/telegram/transport.d.ts.map +1 -1
- package/dist/telegram/update-intake.d.ts.map +1 -1
- package/dist/telegram/update-store-postgres.d.ts +2 -2
- package/dist/telegram/update-store-postgres.d.ts.map +1 -1
- package/dist/telegram/webhook.d.ts.map +1 -1
- package/dist/testing/managed-resource-conformance.d.ts.map +1 -1
- package/dist/testing/surface-conformance.d.ts.map +1 -1
- package/dist/testing/surface-manifest.d.ts +2 -0
- package/dist/testing/surface-manifest.d.ts.map +1 -1
- package/dist/tools/access.d.ts +34 -0
- package/dist/tools/access.d.ts.map +1 -0
- package/dist/tools/agent.d.ts +14 -6
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/cli/args-classify.d.ts +154 -0
- package/dist/tools/cli/args-classify.d.ts.map +1 -0
- package/dist/tools/cli/args-fields.d.ts +14 -7
- package/dist/tools/cli/args-fields.d.ts.map +1 -1
- package/dist/tools/cli/args-json.d.ts +1 -1
- package/dist/tools/cli/args-json.d.ts.map +1 -1
- package/dist/tools/cli/args-route.d.ts +4 -48
- package/dist/tools/cli/args-route.d.ts.map +1 -1
- package/dist/tools/cli/args-scan.d.ts +70 -0
- package/dist/tools/cli/args-scan.d.ts.map +1 -0
- package/dist/tools/cli/args-tokens.d.ts +2 -1
- package/dist/tools/cli/args-tokens.d.ts.map +1 -1
- package/dist/tools/cli/args.d.ts +31 -19
- package/dist/tools/cli/args.d.ts.map +1 -1
- package/dist/tools/cli/checkpoint.d.ts.map +1 -1
- package/dist/tools/cli/command-shape.d.ts +5 -0
- package/dist/tools/cli/command-shape.d.ts.map +1 -1
- package/dist/tools/cli/command.d.ts +57 -2
- package/dist/tools/cli/command.d.ts.map +1 -1
- package/dist/tools/cli/config.d.ts +15 -58
- package/dist/tools/cli/config.d.ts.map +1 -1
- package/dist/tools/cli/create-cli.d.ts +7 -3
- package/dist/tools/cli/create-cli.d.ts.map +1 -1
- package/dist/tools/cli/format.d.ts.map +1 -1
- package/dist/tools/cli/help.d.ts.map +1 -1
- package/dist/tools/cli/invoke.d.ts +70 -20
- package/dist/tools/cli/invoke.d.ts.map +1 -1
- package/dist/tools/cli/io.d.ts.map +1 -1
- package/dist/tools/cli/managed-surface.d.ts.map +1 -1
- package/dist/tools/cli/notices.d.ts.map +1 -1
- package/dist/tools/cli/policy.d.ts +66 -10
- package/dist/tools/cli/policy.d.ts.map +1 -1
- package/dist/tools/cli/prepare.d.ts +5 -4
- package/dist/tools/cli/prepare.d.ts.map +1 -1
- package/dist/tools/cli/run-managed.d.ts.map +1 -1
- package/dist/tools/cli/run-native.d.ts.map +1 -1
- package/dist/tools/cli/run-stream.d.ts.map +1 -1
- package/dist/tools/cli/runner.d.ts +28 -0
- package/dist/tools/cli/runner.d.ts.map +1 -0
- package/dist/tools/cli/session.d.ts +12 -6
- package/dist/tools/cli/session.d.ts.map +1 -1
- package/dist/tools/cli/stream-surface.d.ts.map +1 -1
- package/dist/tools/cli/stream.d.ts.map +1 -1
- package/dist/tools/cli/unavailable.d.ts +2 -0
- package/dist/tools/cli/unavailable.d.ts.map +1 -1
- package/dist/tools/cli/unix-outcome.d.ts +8 -0
- package/dist/tools/cli/unix-outcome.d.ts.map +1 -0
- package/dist/tools/cli/update.d.ts.map +1 -1
- package/dist/tools/cli/view-columns.d.ts +18 -0
- package/dist/tools/cli/view-columns.d.ts.map +1 -0
- package/dist/tools/cli/view.d.ts.map +1 -1
- package/dist/tools/connections/define.d.ts.map +1 -1
- package/dist/tools/connections/foreign-schema-join.d.ts +28 -0
- package/dist/tools/connections/foreign-schema-join.d.ts.map +1 -0
- package/dist/tools/connections/foreign-schema.d.ts +9 -0
- package/dist/tools/connections/foreign-schema.d.ts.map +1 -0
- package/dist/tools/connections/limits.d.ts +1 -1
- package/dist/tools/connections/limits.d.ts.map +1 -1
- package/dist/tools/connections/mcp-client.d.ts.map +1 -1
- package/dist/tools/connections/mcp.d.ts.map +1 -1
- package/dist/tools/connections/openapi.d.ts.map +1 -1
- package/dist/tools/connections/runtime.d.ts +18 -6
- package/dist/tools/connections/runtime.d.ts.map +1 -1
- package/dist/tools/connections/sse-session.d.ts.map +1 -1
- package/dist/tools/connections/types.d.ts +12 -2
- package/dist/tools/connections/types.d.ts.map +1 -1
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/internal/expose.d.ts +6 -0
- package/dist/tools/internal/expose.d.ts.map +1 -0
- package/dist/tools/internal/json-projection.d.ts +17 -0
- package/dist/tools/internal/json-projection.d.ts.map +1 -0
- package/dist/tools/internal/surface-projector.d.ts +18 -4
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/dist/tools/invoker.d.ts +9 -2
- package/dist/tools/invoker.d.ts.map +1 -1
- package/dist/tools/lifecycle.d.ts +8 -2
- package/dist/tools/lifecycle.d.ts.map +1 -1
- package/dist/tools/list-names.d.ts +1 -1
- package/dist/tools/list-names.d.ts.map +1 -1
- package/dist/tools/manifest.d.ts +2 -0
- package/dist/tools/manifest.d.ts.map +1 -1
- package/dist/tools/mcp/handler.d.ts.map +1 -1
- package/dist/tools/mcp/mount.d.ts +26 -14
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/prepare.d.ts +2 -0
- package/dist/tools/mcp/prepare.d.ts.map +1 -1
- package/dist/tools/mcp/register.d.ts.map +1 -1
- package/dist/tools/mcp/runtime-tools.d.ts +1 -1
- package/dist/tools/mcp/runtime-tools.d.ts.map +1 -1
- package/dist/tools/mcp/stdio.d.ts.map +1 -1
- package/dist/tools/mount.d.ts +7 -2
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools/native-definition.d.ts +1 -1
- package/dist/tools/native-definition.d.ts.map +1 -1
- package/dist/tools/operations/async-operation-runtime-tools.d.ts +2 -2
- package/dist/tools/operations/async-operation-runtime-tools.d.ts.map +1 -1
- package/dist/tools/operations/async-operation-runtime-types.d.ts +1 -1
- package/dist/tools/operations/async-operation-runtime-types.d.ts.map +1 -1
- package/dist/tools/operations/define-wait-tool.d.ts.map +1 -1
- package/dist/tools/operations/mount-wait.d.ts.map +1 -1
- package/dist/tools/operations/wait-core.d.ts.map +1 -1
- package/dist/tools/read-operation.d.ts +6 -4
- package/dist/tools/read-operation.d.ts.map +1 -1
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/runtime-tool-declaration.d.ts +4 -1
- package/dist/tools/runtime-tool-declaration.d.ts.map +1 -1
- package/dist/tools/runtime-tool.d.ts +6 -1
- package/dist/tools/runtime-tool.d.ts.map +1 -1
- package/dist/tools/schema/coerce.d.ts.map +1 -1
- package/dist/tools/schema/inline-references.d.ts +7 -0
- package/dist/tools/schema/inline-references.d.ts.map +1 -0
- package/dist/tools/schema/json-schema-origin.d.ts +1 -1
- package/dist/tools/schema/json-schema-origin.d.ts.map +1 -1
- package/dist/tools/schema/presentation.d.ts +6 -0
- package/dist/tools/schema/presentation.d.ts.map +1 -1
- package/dist/tools/schema/schema.d.ts +2 -0
- package/dist/tools/schema/schema.d.ts.map +1 -1
- package/dist/tools/schema/untyped-properties.d.ts.map +1 -1
- package/dist/tools/surface.d.ts.map +1 -1
- package/dist/tools/toolkit.d.ts +6 -3
- package/dist/tools/toolkit.d.ts.map +1 -1
- package/dist/tools/transfer/define-download-tool.d.ts.map +1 -1
- package/dist/tools/transfer/define-upload-tool.d.ts.map +1 -1
- package/dist/tools/transfer/define-view-file-tool.d.ts +2 -1
- package/dist/tools/transfer/define-view-file-tool.d.ts.map +1 -1
- package/dist/tools/transfer/mount-download.d.ts.map +1 -1
- package/dist/tools/transfer/view-file-contract.d.ts +2 -2
- package/dist/tools/transfer/view-file.d.ts +1 -2
- package/dist/tools/transfer/view-file.d.ts.map +1 -1
- package/dist/tracking/client.d.ts +0 -13
- package/dist/tracking/client.d.ts.map +1 -1
- package/dist/tracking/delivery.d.ts.map +1 -1
- package/dist/tracking/performance/collector.d.ts.map +1 -1
- package/llms/agent-executor-acp.txt +51 -0
- package/llms/agent-executor-claude-sdk.txt +31 -0
- package/llms/agent-executor-claude.txt +29 -0
- package/llms/agent-executor-codex.txt +25 -0
- package/llms/agent-executor-testing.txt +26 -0
- package/llms/agent-executor.txt +40 -0
- package/llms/agent-runtime-harness.txt +68 -5
- package/llms/agent-runtime-openrouter.txt +8 -2
- package/llms/agent-runtime-postgres.txt +30 -0
- package/llms/agent-runtime-react.txt +1 -1
- package/llms/agent-runtime-realtime.txt +1 -1
- package/llms/agent-runtime-sandbox.txt +5 -2
- package/llms/agent-runtime-sqlite-bun.txt +2 -2
- package/llms/agent-runtime-sqlite-node.txt +2 -2
- package/llms/agent-runtime-testing.txt +2 -1
- package/llms/agent-runtime.2.txt +475 -496
- package/llms/agent-runtime.3.txt +229 -267
- package/llms/agent-runtime.4.txt +23 -242
- package/llms/agent-runtime.5.txt +1 -1
- package/llms/agent-runtime.txt +551 -2
- package/llms/application-diagnostic-journal.txt +2 -0
- package/llms/application.2.txt +3 -0
- package/llms/application.3.txt +30 -7
- package/llms/application.txt +4 -1
- package/llms/cli.2.txt +259 -99
- package/llms/cli.3.txt +90 -0
- package/llms/cli.txt +95 -184
- package/llms/contract.txt +7 -6
- package/llms/declaration.txt +1 -1
- package/llms/files.txt +11 -0
- package/llms/handler.txt +25 -0
- package/llms/http.txt +18 -1
- package/llms/live.txt +28 -1
- package/llms/node.txt +3 -2
- package/llms/observability.2.txt +105 -0
- package/llms/observability.txt +14 -90
- package/llms/primitives.txt +27 -0
- package/llms/process.2.txt +2 -2
- package/llms/process.txt +10 -9
- package/llms/realtime.txt +11 -0
- package/llms/server.2.txt +355 -0
- package/llms/server.3.txt +2 -1
- package/llms/server.4.txt +45 -6
- package/llms/server.5.txt +9 -2
- package/llms/server.txt +185 -255
- package/llms/service-host-macos.txt +53 -0
- package/llms/service-host.txt +69 -0
- package/llms/spend-testing.txt +21 -0
- package/llms/spend.txt +173 -0
- package/llms/stitchkit.2.txt +368 -42
- package/llms/stitchkit.3.txt +164 -13
- package/llms/stitchkit.txt +95 -417
- package/llms/sync-postgres.txt +31 -0
- package/llms/sync.txt +396 -0
- package/llms/telegram-html.txt +4 -1
- package/llms/telegram.2.txt +4 -4
- package/llms/telegram.txt +105 -14
- package/llms/testing.txt +4 -3
- package/llms/tools-connections.txt +4 -4
- package/llms/tools.2.txt +78 -17
- package/llms/tools.3.txt +12 -8
- package/llms/tools.txt +85 -78
- package/llms/{upgrading-0.106.0-0.125.0.txt → upgrading-0.106.0-0.126.0.txt} +42 -3
- package/llms/upgrading-0.127.0.txt +1059 -0
- package/llms/upgrading.txt +2 -1
- package/llms-full.txt +3692 -518
- package/llms.txt +45 -29
- package/native/darwin-arm64.node +0 -0
- package/native/darwin-x64.node +0 -0
- package/native-assets.json +4 -4
- package/package.json +69 -11
- package/dist/agent-runtime/sandbox-coding.d.ts.map +0 -1
- package/dist/agent-runtime/sqlite-events.d.ts +0 -5
- package/dist/agent-runtime/sqlite-events.d.ts.map +0 -1
- package/dist/agent-runtime/sqlite-history.d.ts +0 -7
- package/dist/agent-runtime/sqlite-history.d.ts.map +0 -1
- package/dist/agent-runtime/sqlite-ledger.d.ts +0 -7
- package/dist/agent-runtime/sqlite-ledger.d.ts.map +0 -1
- package/dist/agent-runtime/sqlite-reads.d.ts +0 -14
- package/dist/agent-runtime/sqlite-reads.d.ts.map +0 -1
- package/dist/agent-runtime/sqlite-rows.d.ts.map +0 -1
- package/dist/agent-runtime/tool-progress.d.ts.map +0 -1
- package/dist/entrypoints/application/schemas.d.ts +0 -15
- package/dist/entrypoints/application/schemas.d.ts.map +0 -1
- package/dist/entrypoints/application/schemas.js +0 -27
- package/dist/index-0s4xebbg.js +0 -8
- package/dist/index-5dmk54h9.js +0 -256
- package/dist/index-7cn66qdk.js +0 -92
- package/dist/index-8x0q6yfb.js +0 -247
- package/dist/index-a5qr2rj6.js +0 -26
- package/dist/index-b0kddvzw.js +0 -35
- package/dist/index-cj5f0x4y.js +0 -1150
- package/dist/index-drcjjhy1.js +0 -40
- package/dist/index-eemvahkc.js +0 -21
- package/dist/index-gfk7nrht.js +0 -0
- package/dist/index-jp2qd9jb.js +0 -108
- package/dist/index-nx6eazt0.js +0 -160
- package/dist/index-wxadzdb7.js +0 -55
- package/dist/internal/until-aborted.d.ts +0 -9
- package/dist/internal/until-aborted.d.ts.map +0 -1
- package/dist/server/unix-client-error.d.ts +0 -9
- package/dist/server/unix-client-error.d.ts.map +0 -1
- package/llms/application-schemas.txt +0 -42
|
@@ -1,37 +1,42 @@
|
|
|
1
1
|
import {
|
|
2
2
|
validateDeclaredOutput
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-akf0xkrm.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
coerceJsonArgs2
|
|
9
|
-
} from "./index-t8jz0e20.js";
|
|
5
|
+
HELP_SHOWN_KEYWORDS,
|
|
6
|
+
STANDARD_STRING_FORMATS
|
|
7
|
+
} from "./index-27hck3z2.js";
|
|
10
8
|
import {
|
|
11
|
-
STANDARD_STRING_FORMATS,
|
|
12
9
|
toJsonSchema,
|
|
13
10
|
jsonSchemaFields
|
|
14
|
-
} from "./index-
|
|
11
|
+
} from "./index-ngwf1s3c.js";
|
|
15
12
|
import {
|
|
16
13
|
toolSurfaceOutputSchema,
|
|
17
|
-
objectShapeKeys,
|
|
18
|
-
mergeSchemas,
|
|
19
14
|
toToolName,
|
|
20
15
|
assertUniqueToolName,
|
|
21
16
|
buildToolPresentationSchema,
|
|
22
17
|
projectedContractToolName
|
|
23
|
-
} from "./index-
|
|
18
|
+
} from "./index-3ypvpkwr.js";
|
|
24
19
|
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
unwrapZodWrappers,
|
|
21
|
+
objectShapeKeys,
|
|
22
|
+
mergeSchemas
|
|
23
|
+
} from "./index-360j58vb.js";
|
|
24
|
+
import {
|
|
25
|
+
jsonSchemaObjectCoercionMembers
|
|
26
|
+
} from "./index-dsa676h8.js";
|
|
27
|
+
import {
|
|
28
|
+
coerceJsonArgs2
|
|
29
|
+
} from "./index-j903yhp4.js";
|
|
28
30
|
import {
|
|
31
|
+
toolResultFromError,
|
|
32
|
+
toolErrorFromResult,
|
|
33
|
+
toolCauseFromResult,
|
|
29
34
|
createToolRunner,
|
|
30
35
|
formatToolError
|
|
31
|
-
} from "./index-
|
|
36
|
+
} from "./index-9wh98cpa.js";
|
|
32
37
|
import {
|
|
33
38
|
isRepeatableRead
|
|
34
|
-
} from "./index-
|
|
39
|
+
} from "./index-0x4mnwg5.js";
|
|
35
40
|
import {
|
|
36
41
|
MCP_FILE_NAME_META_KEY2,
|
|
37
42
|
McpImageContentSchema,
|
|
@@ -40,221 +45,63 @@ import {
|
|
|
40
45
|
import {
|
|
41
46
|
readContractStreamItems,
|
|
42
47
|
contractStreamLifetimeExceeded
|
|
43
|
-
} from "./index-
|
|
48
|
+
} from "./index-5y7j383h.js";
|
|
44
49
|
import {
|
|
45
50
|
writeContainedFile
|
|
46
|
-
} from "./index-
|
|
51
|
+
} from "./index-bmaz3jzy.js";
|
|
47
52
|
import {
|
|
48
53
|
openPinnedDirectory,
|
|
49
54
|
isSafeEntryName,
|
|
50
55
|
containedEntryMetadata
|
|
51
|
-
} from "./index-
|
|
56
|
+
} from "./index-xrgn784x.js";
|
|
57
|
+
import {
|
|
58
|
+
projectJsonSafe,
|
|
59
|
+
stringifyJsonSafe
|
|
60
|
+
} from "./index-5awtbyns.js";
|
|
61
|
+
import {
|
|
62
|
+
UNIX_CLIENT_TRANSPORT_ERROR_NAME,
|
|
63
|
+
UNIX_CLIENT_TRANSPORT_ERROR_CODES,
|
|
64
|
+
UNIX_CLIENT_DELIVERY_STATES
|
|
65
|
+
} from "./index-cv9b7fz2.js";
|
|
52
66
|
import {
|
|
53
67
|
pollUntil,
|
|
54
68
|
mediaExtension
|
|
55
|
-
} from "./index-
|
|
69
|
+
} from "./index-n20tybgk.js";
|
|
56
70
|
import {
|
|
57
71
|
collectToolSurface
|
|
58
|
-
} from "./index-
|
|
72
|
+
} from "./index-5e0zsbf7.js";
|
|
73
|
+
import {
|
|
74
|
+
resolveOptionalCliToolAccess
|
|
75
|
+
} from "./index-ax3wns1a.js";
|
|
76
|
+
import {
|
|
77
|
+
assertNoLegacyTransports
|
|
78
|
+
} from "./index-akfgymyr.js";
|
|
59
79
|
import {
|
|
60
80
|
fetchGuarded,
|
|
61
81
|
readCapped
|
|
62
|
-
} from "./index-
|
|
63
|
-
import {
|
|
64
|
-
errnoOf
|
|
65
|
-
} from "./index-jj9228tt.js";
|
|
82
|
+
} from "./index-9y0afd5f.js";
|
|
66
83
|
import {
|
|
67
84
|
isUnsafeKey,
|
|
68
85
|
safeJsonParse
|
|
69
86
|
} from "./index-zsarb5xp.js";
|
|
70
|
-
import {
|
|
71
|
-
assertPositiveSafeInteger
|
|
72
|
-
} from "./index-0s4xebbg.js";
|
|
73
87
|
import {
|
|
74
88
|
formatZodError2
|
|
75
89
|
} from "./index-1eeqpadm.js";
|
|
90
|
+
import {
|
|
91
|
+
errnoOf
|
|
92
|
+
} from "./index-jj9228tt.js";
|
|
76
93
|
import {
|
|
77
94
|
AppError2,
|
|
78
95
|
STITCH_ERROR_STATUS2
|
|
79
|
-
} from "./index-
|
|
96
|
+
} from "./index-9pv126eh.js";
|
|
97
|
+
import {
|
|
98
|
+
assertPositiveSafeInteger
|
|
99
|
+
} from "./index-kzavdze2.js";
|
|
80
100
|
import {
|
|
81
101
|
isRecord,
|
|
82
|
-
isAsyncIterable
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// src/tools/cli/format.ts
|
|
86
|
-
var DEFAULT_EXIT_CODES2 = {
|
|
87
|
-
VALIDATION_ERROR: 1,
|
|
88
|
-
BAD_REQUEST: 1,
|
|
89
|
-
UNAUTHORIZED: 2,
|
|
90
|
-
FORBIDDEN: 3,
|
|
91
|
-
NOT_FOUND: 4,
|
|
92
|
-
UNKNOWN_OPERATION: 4,
|
|
93
|
-
CONFLICT: 5,
|
|
94
|
-
RATE_LIMITED: 6,
|
|
95
|
-
TIMEOUT: 7,
|
|
96
|
-
REQUEST_ABORTED: 130,
|
|
97
|
-
REQUEST_TIMEOUT: 7,
|
|
98
|
-
CONNECTION_TIMEOUT: 7,
|
|
99
|
-
STREAM_LIFETIME_EXCEEDED: 7,
|
|
100
|
-
CONNECTION_RESPONSE_TOO_LARGE: 1,
|
|
101
|
-
CONNECTION_REQUEST_FAILED: 1,
|
|
102
|
-
UPSTREAM_TOOL_ERROR: 1,
|
|
103
|
-
WAIT_FAILED: 1,
|
|
104
|
-
CLI_COMMAND_UNAVAILABLE: 1,
|
|
105
|
-
CLI_PRESENTATION_FAILED: 8,
|
|
106
|
-
INTERNAL_SERVER_ERROR: 1
|
|
107
|
-
};
|
|
108
|
-
function cliExitCode2(result, exitCodes) {
|
|
109
|
-
if (result.ok)
|
|
110
|
-
return 0;
|
|
111
|
-
const codes = { ...DEFAULT_EXIT_CODES2, ...exitCodes };
|
|
112
|
-
return Object.hasOwn(codes, result.code) ? codes[result.code] ?? 1 : 1;
|
|
113
|
-
}
|
|
114
|
-
function emitResult2(result, writers, opts) {
|
|
115
|
-
if (result.ok) {
|
|
116
|
-
if (result.data === undefined)
|
|
117
|
-
return 0;
|
|
118
|
-
const text = opts.json ? JSON.stringify(result.data) : JSON.stringify(result.data, null, 2);
|
|
119
|
-
writers.stdout(`${text}
|
|
120
|
-
`);
|
|
121
|
-
return 0;
|
|
122
|
-
}
|
|
123
|
-
const error = formatToolError(result, opts.toolName, opts.errorHint);
|
|
124
|
-
const text = opts.json ? JSON.stringify(error) : JSON.stringify(error, null, 2);
|
|
125
|
-
writers.stderr(`${text}
|
|
126
|
-
`);
|
|
127
|
-
return cliExitCode2(result, opts.exitCodes);
|
|
128
|
-
}
|
|
129
|
-
function presentationFailureHint(repeatable, printed) {
|
|
130
|
-
if (repeatable) {
|
|
131
|
-
return "The result was not printed: this command only reads. Repeat it with a corrected view.";
|
|
132
|
-
}
|
|
133
|
-
return printed ? "The complete, unformatted result is on stdout. Do not repeat the command to recover its result." : "The command returned no result. Do not repeat it.";
|
|
134
|
-
}
|
|
135
|
-
function emitPresentationFailure(result, failure, writers, opts) {
|
|
136
|
-
const printed = !opts.repeatable && result.data !== undefined;
|
|
137
|
-
if (printed)
|
|
138
|
-
emitResult2(result, writers, opts);
|
|
139
|
-
return emitResult2({
|
|
140
|
-
ok: false,
|
|
141
|
-
code: "CLI_PRESENTATION_FAILED",
|
|
142
|
-
retryable: false,
|
|
143
|
-
details: {
|
|
144
|
-
message: "The command completed successfully, but its result presentation failed.",
|
|
145
|
-
command: opts.toolName,
|
|
146
|
-
operationSucceeded: true,
|
|
147
|
-
resultOnStdout: printed,
|
|
148
|
-
cause: formatToolError(failure)
|
|
149
|
-
},
|
|
150
|
-
hint: presentationFailureHint(opts.repeatable, printed)
|
|
151
|
-
}, writers, { json: opts.json, toolName: opts.toolName, exitCodes: opts.exitCodes });
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// src/tools/cli/command.ts
|
|
155
|
-
function defineCliResult2(output, policy) {
|
|
156
|
-
return { ...policy, output };
|
|
157
|
-
}
|
|
158
|
-
function defineCliCommand2(definition) {
|
|
159
|
-
return definition;
|
|
160
|
-
}
|
|
161
|
-
function cliCommandReturnsResult(definition) {
|
|
162
|
-
return definition.output !== undefined;
|
|
163
|
-
}
|
|
164
|
-
function cliCommandSuccessExitCode(policy, data) {
|
|
165
|
-
const successExitCode = policy?.exitCode?.(data) ?? 0;
|
|
166
|
-
if (!Number.isSafeInteger(successExitCode) || successExitCode < 0 || successExitCode > 255) {
|
|
167
|
-
throw new Error("CLI success exit code must be an integer from 0 to 255");
|
|
168
|
-
}
|
|
169
|
-
return successExitCode;
|
|
170
|
-
}
|
|
171
|
-
function cliCommandResultPolicy(definition) {
|
|
172
|
-
return cliCommandReturnsResult(definition) ? definition : undefined;
|
|
173
|
-
}
|
|
174
|
-
function prepareCliCommandEmission(policy, result, options) {
|
|
175
|
-
if (!result.ok || policy === undefined) {
|
|
176
|
-
return { result, successExitCode: 0 };
|
|
177
|
-
}
|
|
178
|
-
let successExitCode;
|
|
179
|
-
try {
|
|
180
|
-
successExitCode = cliCommandSuccessExitCode(policy, result.data);
|
|
181
|
-
} catch (error) {
|
|
182
|
-
return {
|
|
183
|
-
result: toolResultFromError(new Error("CLI result policy failed", { cause: error })),
|
|
184
|
-
successExitCode: 0
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
try {
|
|
188
|
-
if (policy.present === undefined)
|
|
189
|
-
return { result, successExitCode };
|
|
190
|
-
const presentation = policy.present({ result: result.data, options });
|
|
191
|
-
if (typeof presentation !== "string") {
|
|
192
|
-
throw new Error("CLI result presenter must return a string");
|
|
193
|
-
}
|
|
194
|
-
return { result, presentation, successExitCode };
|
|
195
|
-
} catch (error) {
|
|
196
|
-
return {
|
|
197
|
-
result,
|
|
198
|
-
presentationFailure: toolResultFromError(new Error("CLI result presentation failed", { cause: error })),
|
|
199
|
-
successExitCode
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
function emitCliCommandResult(policy, result, options, writers, emit, shown) {
|
|
204
|
-
const emission = prepareCliCommandEmission(policy, result, options);
|
|
205
|
-
if (!emission.result.ok)
|
|
206
|
-
return emitResult2(emission.result, writers, emit);
|
|
207
|
-
if (emission.presentation !== undefined) {
|
|
208
|
-
writers.stdout(emission.presentation);
|
|
209
|
-
return emission.successExitCode;
|
|
210
|
-
}
|
|
211
|
-
const printed = shown ?? emission.result;
|
|
212
|
-
if (emission.presentationFailure !== undefined) {
|
|
213
|
-
return emitPresentationFailure(printed, emission.presentationFailure, writers, emit);
|
|
214
|
-
}
|
|
215
|
-
emitResult2(printed, writers, emit);
|
|
216
|
-
return emission.successExitCode;
|
|
217
|
-
}
|
|
218
|
-
function cliCommandPresentationSchema(definition) {
|
|
219
|
-
return buildToolPresentationSchema({
|
|
220
|
-
inputSchema: definition.input,
|
|
221
|
-
unrepresentable: "any"
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
async function executeCliCommand(definition, rawArgs, options, writers, coerceJson, globals = {}) {
|
|
225
|
-
let parsed;
|
|
226
|
-
try {
|
|
227
|
-
parsed = definition.input.safeParse(coerceJson ? coerceJsonArgs2(rawArgs, definition.input) : rawArgs);
|
|
228
|
-
} catch (error) {
|
|
229
|
-
return toolResultFromError(error);
|
|
230
|
-
}
|
|
231
|
-
if (!parsed.success) {
|
|
232
|
-
return {
|
|
233
|
-
ok: false,
|
|
234
|
-
code: "VALIDATION_ERROR",
|
|
235
|
-
details: { message: `Invalid input: ${formatZodError2(parsed.error)}` }
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
try {
|
|
239
|
-
const data = await definition.handler({
|
|
240
|
-
input: parsed.data,
|
|
241
|
-
options,
|
|
242
|
-
globals,
|
|
243
|
-
...writers
|
|
244
|
-
});
|
|
245
|
-
const checked = validateDeclaredOutput(definition.output, data);
|
|
246
|
-
if (!checked.ok) {
|
|
247
|
-
return {
|
|
248
|
-
ok: false,
|
|
249
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
250
|
-
details: { message: checked.message }
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
return { ok: true, data: checked.data };
|
|
254
|
-
} catch (error) {
|
|
255
|
-
return toolResultFromError(error);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
102
|
+
isAsyncIterable,
|
|
103
|
+
transportResult
|
|
104
|
+
} from "./index-ps3djm8d.js";
|
|
258
105
|
|
|
259
106
|
// src/tools/cli/args-fields.ts
|
|
260
107
|
import { z } from "zod";
|
|
@@ -277,14 +124,8 @@ function appendCliOptionValue(raw, name, value, info) {
|
|
|
277
124
|
raw.set(name, [value]);
|
|
278
125
|
}
|
|
279
126
|
}
|
|
280
|
-
function unwrap(field) {
|
|
281
|
-
if (field instanceof z.ZodOptional || field instanceof z.ZodNullable || field instanceof z.ZodDefault) {
|
|
282
|
-
return unwrap(field.unwrap());
|
|
283
|
-
}
|
|
284
|
-
return field;
|
|
285
|
-
}
|
|
286
127
|
function literalKind(field) {
|
|
287
|
-
const base =
|
|
128
|
+
const base = unwrapZodWrappers(field);
|
|
288
129
|
if (base instanceof z.ZodLiteral) {
|
|
289
130
|
const kinds = new Set;
|
|
290
131
|
for (const value of base.values) {
|
|
@@ -333,6 +174,8 @@ function mergeField(fields, name, info) {
|
|
|
333
174
|
if (existing.kind === info.kind) {
|
|
334
175
|
if (existing.kind === "array" && existing.elementKind !== info.elementKind) {
|
|
335
176
|
fields.set(name, { kind: "array", elementKind: "other" });
|
|
177
|
+
} else if (existing.kind === "boolean" && existing.pureBoolean !== info.pureBoolean) {
|
|
178
|
+
fields.set(name, { kind: "boolean" });
|
|
336
179
|
}
|
|
337
180
|
return;
|
|
338
181
|
}
|
|
@@ -342,21 +185,22 @@ function mergeField(fields, name, info) {
|
|
|
342
185
|
}
|
|
343
186
|
fields.set(name, { kind: "other" });
|
|
344
187
|
}
|
|
345
|
-
function collectSchemaFields(schema, fields) {
|
|
346
|
-
const base =
|
|
188
|
+
function collectSchemaFields(schema, fields, inUnion = false) {
|
|
189
|
+
const base = unwrapZodWrappers(schema);
|
|
347
190
|
if (base instanceof z.ZodObject) {
|
|
348
191
|
for (const [name, raw] of Object.entries(base.shape)) {
|
|
349
|
-
const fieldBase =
|
|
192
|
+
const fieldBase = unwrapZodWrappers(raw);
|
|
350
193
|
const kind = classify(fieldBase);
|
|
351
194
|
if (kind === "array" && fieldBase instanceof z.ZodArray) {
|
|
352
195
|
mergeField(fields, name, {
|
|
353
196
|
kind,
|
|
354
|
-
elementKind: classify(
|
|
197
|
+
elementKind: classify(unwrapZodWrappers(fieldBase.element))
|
|
355
198
|
});
|
|
356
199
|
} else {
|
|
357
200
|
mergeField(fields, name, {
|
|
358
201
|
kind,
|
|
359
|
-
...fieldBase instanceof z.ZodNumber && fieldBase.isInt && { integer: true }
|
|
202
|
+
...fieldBase instanceof z.ZodNumber && fieldBase.isInt && { integer: true },
|
|
203
|
+
...kind === "boolean" && !inUnion && { pureBoolean: true }
|
|
360
204
|
});
|
|
361
205
|
}
|
|
362
206
|
}
|
|
@@ -364,12 +208,12 @@ function collectSchemaFields(schema, fields) {
|
|
|
364
208
|
}
|
|
365
209
|
if (base instanceof z.ZodUnion) {
|
|
366
210
|
for (const option of base.def.options)
|
|
367
|
-
collectSchemaFields(option, fields);
|
|
211
|
+
collectSchemaFields(option, fields, true);
|
|
368
212
|
return;
|
|
369
213
|
}
|
|
370
214
|
if (base instanceof z.ZodIntersection) {
|
|
371
|
-
collectSchemaFields(base.def.left, fields);
|
|
372
|
-
collectSchemaFields(base.def.right, fields);
|
|
215
|
+
collectSchemaFields(base.def.left, fields, inUnion);
|
|
216
|
+
collectSchemaFields(base.def.right, fields, inUnion);
|
|
373
217
|
return;
|
|
374
218
|
}
|
|
375
219
|
}
|
|
@@ -380,14 +224,15 @@ function describeSchemaFields(schema) {
|
|
|
380
224
|
return fields;
|
|
381
225
|
}
|
|
382
226
|
function infoOf(field) {
|
|
383
|
-
const base =
|
|
227
|
+
const base = unwrapZodWrappers(field);
|
|
384
228
|
const kind = classify(base);
|
|
385
229
|
if (kind === "array" && base instanceof z.ZodArray) {
|
|
386
|
-
return { kind, elementKind: classify(
|
|
230
|
+
return { kind, elementKind: classify(unwrapZodWrappers(base.element)) };
|
|
387
231
|
}
|
|
388
232
|
return {
|
|
389
233
|
kind,
|
|
390
|
-
...base instanceof z.ZodNumber && base.isInt && { integer: true }
|
|
234
|
+
...base instanceof z.ZodNumber && base.isInt && { integer: true },
|
|
235
|
+
...kind === "boolean" && { pureBoolean: true }
|
|
391
236
|
};
|
|
392
237
|
}
|
|
393
238
|
function mergePathInfos(infos, composition) {
|
|
@@ -404,10 +249,12 @@ function mergePathInfos(infos, composition) {
|
|
|
404
249
|
return;
|
|
405
250
|
if (candidates.every((info) => info.kind === first.kind)) {
|
|
406
251
|
const elementKind = first.kind === "array" ? candidates.every((info) => info.elementKind === first.elementKind) ? first.elementKind : "other" : undefined;
|
|
252
|
+
const pureBoolean = first.kind === "boolean" && (composition === "intersection" ? candidates.some((info) => info.pureBoolean) : infos.every((info) => info?.pureBoolean));
|
|
407
253
|
return {
|
|
408
254
|
kind: first.kind,
|
|
409
255
|
...elementKind && { elementKind },
|
|
410
|
-
...first.integer && candidates.every((info) => info.integer) && { integer: true }
|
|
256
|
+
...first.integer && candidates.every((info) => info.integer) && { integer: true },
|
|
257
|
+
...pureBoolean && { pureBoolean: true }
|
|
411
258
|
};
|
|
412
259
|
}
|
|
413
260
|
return candidates.some((info) => info.kind === "boolean") ? { kind: "boolean" } : { kind: "other" };
|
|
@@ -417,7 +264,7 @@ function pathInfo(schema, path) {
|
|
|
417
264
|
if (guarded) {
|
|
418
265
|
return mergePathInfos(guarded.map((member) => pathInfo(member, path)), "intersection");
|
|
419
266
|
}
|
|
420
|
-
const base =
|
|
267
|
+
const base = unwrapZodWrappers(schema);
|
|
421
268
|
if (base !== schema)
|
|
422
269
|
return pathInfo(base, path);
|
|
423
270
|
if (base instanceof z.ZodUnion) {
|
|
@@ -444,37 +291,39 @@ function describeSchemaPath(schema, path) {
|
|
|
444
291
|
return;
|
|
445
292
|
return pathInfo(schema, path);
|
|
446
293
|
}
|
|
447
|
-
var
|
|
448
|
-
|
|
294
|
+
var BOOL_WORDS = {
|
|
295
|
+
true: { value: true, separate: true },
|
|
296
|
+
"1": { value: true, separate: false },
|
|
297
|
+
yes: { value: true, separate: false },
|
|
298
|
+
on: { value: true, separate: false },
|
|
299
|
+
false: { value: false, separate: true },
|
|
300
|
+
"0": { value: false, separate: false },
|
|
301
|
+
no: { value: false, separate: false },
|
|
302
|
+
off: { value: false, separate: false }
|
|
303
|
+
};
|
|
304
|
+
function lookupBoolWord(value) {
|
|
305
|
+
const key = value.toLowerCase();
|
|
306
|
+
return Object.hasOwn(BOOL_WORDS, key) ? BOOL_WORDS[key] : undefined;
|
|
307
|
+
}
|
|
449
308
|
function separateBoolValue(next) {
|
|
450
|
-
if (next ===
|
|
451
|
-
return
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
return;
|
|
309
|
+
if (next === undefined)
|
|
310
|
+
return;
|
|
311
|
+
const row = lookupBoolWord(next);
|
|
312
|
+
return row?.separate ? row.value : undefined;
|
|
455
313
|
}
|
|
456
314
|
function isReservedBoolWord(value) {
|
|
457
|
-
|
|
458
|
-
return TRUE_WORDS.has(word) || FALSE_WORDS.has(word);
|
|
315
|
+
return lookupBoolWord(value) !== undefined;
|
|
459
316
|
}
|
|
460
317
|
function parseReservedBool(name, value) {
|
|
461
|
-
const
|
|
462
|
-
if (
|
|
463
|
-
return
|
|
464
|
-
if (FALSE_WORDS.has(v))
|
|
465
|
-
return false;
|
|
318
|
+
const row = lookupBoolWord(value);
|
|
319
|
+
if (row !== undefined)
|
|
320
|
+
return row.value;
|
|
466
321
|
throw new CliArgumentError2(`--${name} expects a boolean (true/false), got "${value}"`);
|
|
467
322
|
}
|
|
468
323
|
function coerceScalar(kind, value) {
|
|
469
324
|
switch (kind) {
|
|
470
|
-
case "boolean":
|
|
471
|
-
|
|
472
|
-
if (TRUE_WORDS.has(v))
|
|
473
|
-
return true;
|
|
474
|
-
if (FALSE_WORDS.has(v))
|
|
475
|
-
return false;
|
|
476
|
-
return value;
|
|
477
|
-
}
|
|
325
|
+
case "boolean":
|
|
326
|
+
return lookupBoolWord(value)?.value ?? value;
|
|
478
327
|
case "number": {
|
|
479
328
|
const n = Number(value);
|
|
480
329
|
return value.trim() !== "" && !Number.isNaN(n) ? n : value;
|
|
@@ -501,6 +350,28 @@ function looseCoerce(value) {
|
|
|
501
350
|
const number = Number(value);
|
|
502
351
|
return value.trim() !== "" && !Number.isNaN(number) ? number : value;
|
|
503
352
|
}
|
|
353
|
+
function refuseGlobalOption(issue) {
|
|
354
|
+
const field = issue?.path[0];
|
|
355
|
+
const where = typeof field === "string" ? `--${field}` : "application option";
|
|
356
|
+
throw new CliArgumentError2(`${where}: ${issue?.message ?? "invalid value"}`);
|
|
357
|
+
}
|
|
358
|
+
function parseCliGlobalValues(schema, raw) {
|
|
359
|
+
const base = raw ?? {};
|
|
360
|
+
if (schema === undefined)
|
|
361
|
+
return transportResult(base);
|
|
362
|
+
let coerced;
|
|
363
|
+
try {
|
|
364
|
+
coerced = coerceJsonArgs2(base, schema);
|
|
365
|
+
} catch (error) {
|
|
366
|
+
if (error instanceof z.ZodError)
|
|
367
|
+
refuseGlobalOption(error.issues[0]);
|
|
368
|
+
throw error;
|
|
369
|
+
}
|
|
370
|
+
const parsed = schema.safeParse(coerced);
|
|
371
|
+
if (!parsed.success)
|
|
372
|
+
refuseGlobalOption(parsed.error.issues[0]);
|
|
373
|
+
return parsed.data;
|
|
374
|
+
}
|
|
504
375
|
function looksLikeJson(value) {
|
|
505
376
|
const t = value.trim();
|
|
506
377
|
return t.startsWith("[") || t.startsWith("{");
|
|
@@ -562,32 +433,1110 @@ function setNested(target, path, value) {
|
|
|
562
433
|
node[leaf] = value;
|
|
563
434
|
}
|
|
564
435
|
|
|
565
|
-
// src/tools/cli/
|
|
566
|
-
var
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
436
|
+
// src/tools/cli/format.ts
|
|
437
|
+
var DEFAULT_EXIT_CODES2 = {
|
|
438
|
+
VALIDATION_ERROR: 1,
|
|
439
|
+
BAD_REQUEST: 1,
|
|
440
|
+
UNAUTHORIZED: 2,
|
|
441
|
+
FORBIDDEN: 3,
|
|
442
|
+
NOT_FOUND: 4,
|
|
443
|
+
UNKNOWN_OPERATION: 4,
|
|
444
|
+
CONFLICT: 5,
|
|
445
|
+
RATE_LIMITED: 6,
|
|
446
|
+
TIMEOUT: 7,
|
|
447
|
+
REQUEST_ABORTED: 130,
|
|
448
|
+
REQUEST_TIMEOUT: 7,
|
|
449
|
+
CONNECTION_TIMEOUT: 7,
|
|
450
|
+
STREAM_LIFETIME_EXCEEDED: 7,
|
|
451
|
+
CONNECTION_RESPONSE_TOO_LARGE: 1,
|
|
452
|
+
CONNECTION_REQUEST_FAILED: 1,
|
|
453
|
+
UPSTREAM_TOOL_ERROR: 1,
|
|
454
|
+
MCP_STRUCTURED_CONTENT_MISSING: 1,
|
|
455
|
+
WAIT_FAILED: 1,
|
|
456
|
+
CLI_COMMAND_UNAVAILABLE: 1,
|
|
457
|
+
CLI_PRESENTATION_FAILED: 8,
|
|
458
|
+
UNIX_CONNECT_FAILED: 9,
|
|
459
|
+
UNIX_TARGET_REFUSED: 9,
|
|
460
|
+
UNIX_CLIENT_CLOSED: 9,
|
|
461
|
+
UNIX_CONNECTION_LIMIT: 9,
|
|
462
|
+
UNIX_REQUEST_TOO_LARGE: 9,
|
|
463
|
+
UNIX_DELIVERY_UNCERTAIN: 10,
|
|
464
|
+
UNIX_HEADERS_TIMEOUT: 10,
|
|
465
|
+
INTERNAL_SERVER_ERROR: 1
|
|
466
|
+
};
|
|
467
|
+
function cliExitCode2(result, exitCodes) {
|
|
468
|
+
if (result.ok)
|
|
469
|
+
return 0;
|
|
470
|
+
const codes = { ...DEFAULT_EXIT_CODES2, ...exitCodes };
|
|
471
|
+
return Object.hasOwn(codes, result.code) ? codes[result.code] ?? 1 : 1;
|
|
472
|
+
}
|
|
473
|
+
function emitResult2(result, writers, opts) {
|
|
474
|
+
if (result.ok) {
|
|
475
|
+
if (result.data === undefined)
|
|
476
|
+
return 0;
|
|
477
|
+
const text = stringifyJsonSafe(result.data, opts.json ? undefined : 2);
|
|
478
|
+
writers.stdout(`${text}
|
|
479
|
+
`);
|
|
480
|
+
return 0;
|
|
481
|
+
}
|
|
482
|
+
const error = formatToolError(result, opts.toolName, opts.errorHint);
|
|
483
|
+
const text = opts.json ? JSON.stringify(error) : JSON.stringify(error, null, 2);
|
|
484
|
+
writers.stderr(`${text}
|
|
485
|
+
`);
|
|
486
|
+
return cliExitCode2(result, opts.exitCodes);
|
|
487
|
+
}
|
|
488
|
+
function presentationFailureHint(repeatable, printed) {
|
|
489
|
+
if (repeatable) {
|
|
490
|
+
return "The result was not printed: this command only reads. Repeat it with a corrected view.";
|
|
491
|
+
}
|
|
492
|
+
return printed ? "The complete, unformatted result is on stdout. Do not repeat the command to recover its result." : "The command returned no result. Do not repeat it.";
|
|
493
|
+
}
|
|
494
|
+
function emitPresentationFailure(result, failure, writers, opts) {
|
|
495
|
+
const printed = !opts.repeatable && result.data !== undefined;
|
|
496
|
+
if (printed)
|
|
497
|
+
emitResult2(result, writers, opts);
|
|
498
|
+
return emitResult2({
|
|
499
|
+
ok: false,
|
|
500
|
+
code: "CLI_PRESENTATION_FAILED",
|
|
501
|
+
retryable: false,
|
|
502
|
+
details: {
|
|
503
|
+
message: "The command completed successfully, but its result presentation failed.",
|
|
504
|
+
command: opts.toolName,
|
|
505
|
+
operationSucceeded: true,
|
|
506
|
+
resultOnStdout: printed,
|
|
507
|
+
cause: formatToolError(failure)
|
|
508
|
+
},
|
|
509
|
+
hint: presentationFailureHint(opts.repeatable, printed)
|
|
510
|
+
}, writers, { json: opts.json, toolName: opts.toolName, exitCodes: opts.exitCodes });
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// src/tools/cli/view.ts
|
|
514
|
+
var ABSENT = "(absent)";
|
|
515
|
+
function selectRecords(data) {
|
|
516
|
+
if (Array.isArray(data))
|
|
517
|
+
return data;
|
|
518
|
+
if (isRecord(data)) {
|
|
519
|
+
const arrays = Object.entries(data).filter(([, value]) => Array.isArray(value));
|
|
520
|
+
const only = arrays[0];
|
|
521
|
+
if (arrays.length === 1 && only && Array.isArray(only[1]))
|
|
522
|
+
return only[1];
|
|
523
|
+
if (arrays.length > 1) {
|
|
524
|
+
throw new CliArgumentError2(`an aggregate needs one collection, but the result carries several: ${arrays.map(([key]) => key).join(", ")} — name the shape you want with jq instead`);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
throw new CliArgumentError2("an aggregate needs a collection; this result is not one");
|
|
528
|
+
}
|
|
529
|
+
function isAbsent(value) {
|
|
530
|
+
return value === undefined || value === null;
|
|
531
|
+
}
|
|
532
|
+
function readField(record, path) {
|
|
533
|
+
let current = record;
|
|
534
|
+
for (const segment of path) {
|
|
535
|
+
if (!isRecord(current) || !Object.hasOwn(current, segment))
|
|
536
|
+
return;
|
|
537
|
+
current = current[segment];
|
|
538
|
+
}
|
|
539
|
+
return current;
|
|
540
|
+
}
|
|
541
|
+
function fieldPath(field) {
|
|
542
|
+
const path = field.split(".");
|
|
543
|
+
if (path.some((segment) => segment.length === 0 || isUnsafeKey(segment))) {
|
|
544
|
+
throw new CliArgumentError2(`"${field}" is not a readable field path`);
|
|
545
|
+
}
|
|
546
|
+
return path;
|
|
547
|
+
}
|
|
548
|
+
function availableFields(records) {
|
|
549
|
+
const keys = new Set;
|
|
550
|
+
for (const record of records) {
|
|
551
|
+
if (isRecord(record))
|
|
552
|
+
for (const key of Object.keys(record))
|
|
553
|
+
keys.add(key);
|
|
554
|
+
}
|
|
555
|
+
return [...keys].sort();
|
|
556
|
+
}
|
|
557
|
+
function assertFieldPresent(records, field) {
|
|
558
|
+
const path = fieldPath(field);
|
|
559
|
+
const present = records.some((record) => readField(record, path) !== undefined);
|
|
560
|
+
if (records.length > 0 && !present) {
|
|
561
|
+
const available = availableFields(records);
|
|
562
|
+
throw new CliArgumentError2(`no record carries the field "${field}"${available.length > 0 ? ` — available: ${available.join(", ")}` : ""}`);
|
|
563
|
+
}
|
|
564
|
+
return path;
|
|
565
|
+
}
|
|
566
|
+
function groupKey(value) {
|
|
567
|
+
if (value === undefined)
|
|
568
|
+
return ABSENT;
|
|
569
|
+
if (value === null)
|
|
570
|
+
return "null";
|
|
571
|
+
if (value === "null" || value === ABSENT)
|
|
572
|
+
return JSON.stringify(value);
|
|
573
|
+
if (typeof value === "object")
|
|
574
|
+
return stringifyJsonSafe(value);
|
|
575
|
+
return String(value);
|
|
576
|
+
}
|
|
577
|
+
function ordered(totals, top) {
|
|
578
|
+
const entries = [...totals].sort(([leftKey, left], [rightKey, right]) => right === left ? leftKey.localeCompare(rightKey) : right - left);
|
|
579
|
+
const sliced = top === undefined ? entries : entries.slice(0, top);
|
|
580
|
+
return {
|
|
581
|
+
kind: "json",
|
|
582
|
+
data: Object.fromEntries(sliced),
|
|
583
|
+
order: sliced.map(([key]) => key)
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
function stringifyGroups(data, order, compact) {
|
|
587
|
+
if (!isRecord(data) || order.length === 0)
|
|
588
|
+
return stringifyJsonSafe(data);
|
|
589
|
+
const lines = order.map((key) => `${JSON.stringify(key)}:${compact ? "" : " "}${stringifyJsonSafe(data[key])}`);
|
|
590
|
+
return compact ? `{${lines.join(",")}}` : `{
|
|
591
|
+
${lines.join(`,
|
|
592
|
+
`)}
|
|
593
|
+
}`;
|
|
594
|
+
}
|
|
595
|
+
function numericValue(value, field) {
|
|
596
|
+
if (isAbsent(value))
|
|
597
|
+
return;
|
|
598
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
599
|
+
return value;
|
|
600
|
+
if (typeof value === "bigint")
|
|
601
|
+
return Number(value);
|
|
602
|
+
throw new CliArgumentError2(`--sum ${field}: "${groupKey(value)}" is not a number`);
|
|
603
|
+
}
|
|
604
|
+
function renderTable(records, columns) {
|
|
605
|
+
const fields = columns.map(({ field }) => field);
|
|
606
|
+
const cell = (value) => {
|
|
607
|
+
if (value === undefined)
|
|
608
|
+
return "";
|
|
609
|
+
if (value === null)
|
|
610
|
+
return "null";
|
|
611
|
+
if (typeof value === "object")
|
|
612
|
+
return stringifyJsonSafe(value);
|
|
613
|
+
return String(value);
|
|
614
|
+
};
|
|
615
|
+
const rows = records.map((record) => columns.map(({ path }) => cell(readField(record, path))));
|
|
616
|
+
const widths = fields.map((field, column) => Math.max(field.length, ...rows.map((row) => row[column]?.length ?? 0)));
|
|
617
|
+
const line = (cells) => cells.map((value, column) => value.padEnd(widths[column] ?? value.length)).join(" ").trimEnd();
|
|
618
|
+
return `${[line(fields), line(widths.map((width) => "-".repeat(width))), ...rows.map(line)].join(`
|
|
619
|
+
`)}
|
|
620
|
+
`;
|
|
621
|
+
}
|
|
622
|
+
function compareFieldValues(left, right) {
|
|
623
|
+
if (isAbsent(left))
|
|
624
|
+
return isAbsent(right) ? 0 : 1;
|
|
625
|
+
if (isAbsent(right))
|
|
626
|
+
return -1;
|
|
627
|
+
if (typeof left === "number" && typeof right === "number")
|
|
628
|
+
return left - right;
|
|
629
|
+
if (typeof left === "bigint" || typeof right === "bigint") {
|
|
630
|
+
return Number(left) - Number(right);
|
|
631
|
+
}
|
|
632
|
+
return groupKey(left).localeCompare(groupKey(right));
|
|
633
|
+
}
|
|
634
|
+
function renderRecords(records, view) {
|
|
635
|
+
let selected = [...records];
|
|
636
|
+
if (view.sort !== undefined) {
|
|
637
|
+
const path = assertFieldPresent(records, view.sort);
|
|
638
|
+
const direction = view.ascending ? 1 : -1;
|
|
639
|
+
selected.sort((left, right) => {
|
|
640
|
+
const leftValue = readField(left, path);
|
|
641
|
+
const rightValue = readField(right, path);
|
|
642
|
+
const order = compareFieldValues(leftValue, rightValue);
|
|
643
|
+
return isAbsent(leftValue) || isAbsent(rightValue) ? order : order * direction;
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
const columns = view.table?.map((field) => ({
|
|
647
|
+
field,
|
|
648
|
+
path: assertFieldPresent(records, field)
|
|
649
|
+
}));
|
|
650
|
+
if (view.top !== undefined)
|
|
651
|
+
selected = selected.slice(0, view.top);
|
|
652
|
+
return columns ? { kind: "text", text: renderTable(selected, columns) } : { kind: "json", data: selected };
|
|
653
|
+
}
|
|
654
|
+
function refuseEnvelopeFields(data, view) {
|
|
655
|
+
if (!isRecord(data))
|
|
656
|
+
return;
|
|
657
|
+
const fields = view.kind === "records" ? [...view.sort === undefined ? [] : [view.sort], ...view.table ?? []] : [view.field, ...view.kind === "sum" && view.by !== undefined ? [view.by] : []];
|
|
658
|
+
for (const field of fields) {
|
|
659
|
+
const first = field.split(".")[0] ?? "";
|
|
660
|
+
if (Object.hasOwn(data, first) && !Array.isArray(data[first])) {
|
|
661
|
+
throw new CliArgumentError2(`"${field}" belongs to the result object, not to its empty collection`);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
function renderCliView2(data, view) {
|
|
666
|
+
const records = selectRecords(data);
|
|
667
|
+
if (records.length === 0)
|
|
668
|
+
refuseEnvelopeFields(data, view);
|
|
669
|
+
if (view.kind === "records")
|
|
670
|
+
return renderRecords(records, view);
|
|
671
|
+
if (view.kind === "count") {
|
|
672
|
+
const path = assertFieldPresent(records, view.field);
|
|
673
|
+
const totals = new Map;
|
|
674
|
+
for (const record of records) {
|
|
675
|
+
const key = groupKey(readField(record, path));
|
|
676
|
+
totals.set(key, (totals.get(key) ?? 0) + 1);
|
|
677
|
+
}
|
|
678
|
+
return ordered(totals, view.top);
|
|
679
|
+
}
|
|
680
|
+
const path = assertFieldPresent(records, view.field);
|
|
681
|
+
if (view.by === undefined) {
|
|
682
|
+
let total = 0;
|
|
683
|
+
for (const record of records)
|
|
684
|
+
total += numericValue(readField(record, path), view.field) ?? 0;
|
|
685
|
+
return { kind: "json", data: total };
|
|
686
|
+
}
|
|
687
|
+
const byPath = assertFieldPresent(records, view.by);
|
|
688
|
+
const totals = new Map;
|
|
689
|
+
for (const record of records) {
|
|
690
|
+
const key = groupKey(readField(record, byPath));
|
|
691
|
+
totals.set(key, (totals.get(key) ?? 0) + (numericValue(readField(record, path), view.field) ?? 0));
|
|
692
|
+
}
|
|
693
|
+
return ordered(totals, view.top);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// src/tools/cli/view-columns.ts
|
|
697
|
+
import { z as z2 } from "zod";
|
|
698
|
+
function unwrapReadonly(schema) {
|
|
699
|
+
return schema instanceof z2.ZodReadonly ? unwrapReadonly(schema.unwrap()) : schema;
|
|
700
|
+
}
|
|
701
|
+
function hasOpenCatchall(objectSchema) {
|
|
702
|
+
const catchall = objectSchema.def.catchall;
|
|
703
|
+
return catchall !== undefined && !(catchall instanceof z2.ZodNever);
|
|
704
|
+
}
|
|
705
|
+
function couldBeArray(schema) {
|
|
706
|
+
const base = unwrapZodWrappers(schema);
|
|
707
|
+
if (base instanceof z2.ZodArray || base instanceof z2.ZodTuple)
|
|
708
|
+
return true;
|
|
709
|
+
if (base instanceof z2.ZodUnknown || base instanceof z2.ZodAny)
|
|
710
|
+
return true;
|
|
711
|
+
if (base instanceof z2.ZodUnion)
|
|
712
|
+
return base.def.options.some(couldBeArray);
|
|
713
|
+
if (base instanceof z2.ZodIntersection) {
|
|
714
|
+
return couldBeArray(base.def.left) || couldBeArray(base.def.right);
|
|
715
|
+
}
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
|
+
function resolveUnambiguousRecordSchema(outputSchema) {
|
|
719
|
+
if (outputSchema === undefined)
|
|
720
|
+
return;
|
|
721
|
+
const root = unwrapReadonly(outputSchema);
|
|
722
|
+
let element;
|
|
723
|
+
if (root instanceof z2.ZodArray) {
|
|
724
|
+
element = root.element;
|
|
725
|
+
} else if (root instanceof z2.ZodObject) {
|
|
726
|
+
if (hasOpenCatchall(root))
|
|
727
|
+
return;
|
|
728
|
+
let requiredArray;
|
|
729
|
+
for (const field of Object.values(root.shape)) {
|
|
730
|
+
const bare = unwrapReadonly(field);
|
|
731
|
+
if (bare instanceof z2.ZodArray) {
|
|
732
|
+
if (requiredArray !== undefined)
|
|
733
|
+
return;
|
|
734
|
+
requiredArray = bare;
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
if (couldBeArray(field))
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
element = requiredArray?.element;
|
|
741
|
+
}
|
|
742
|
+
if (element === undefined)
|
|
743
|
+
return;
|
|
744
|
+
const record = unwrapReadonly(element);
|
|
745
|
+
if (!(record instanceof z2.ZodObject) || hasOpenCatchall(record))
|
|
746
|
+
return;
|
|
747
|
+
return record;
|
|
748
|
+
}
|
|
749
|
+
function pathExistsOnSchema(schema, path) {
|
|
750
|
+
if (path.length === 0)
|
|
751
|
+
return true;
|
|
752
|
+
const base = unwrapZodWrappers(schema);
|
|
753
|
+
if (base instanceof z2.ZodUnknown || base instanceof z2.ZodAny)
|
|
754
|
+
return true;
|
|
755
|
+
if (base instanceof z2.ZodRecord)
|
|
756
|
+
return pathExistsOnSchema(base.valueType, path.slice(1));
|
|
757
|
+
if (base instanceof z2.ZodUnion) {
|
|
758
|
+
return base.def.options.some((branch) => pathExistsOnSchema(branch, path));
|
|
759
|
+
}
|
|
760
|
+
if (base instanceof z2.ZodIntersection) {
|
|
761
|
+
return pathExistsOnSchema(base.def.left, path) || pathExistsOnSchema(base.def.right, path);
|
|
762
|
+
}
|
|
763
|
+
if (base instanceof z2.ZodObject) {
|
|
764
|
+
const [head, ...rest] = path;
|
|
765
|
+
if (head === undefined)
|
|
766
|
+
return true;
|
|
767
|
+
if (Object.hasOwn(base.shape, head)) {
|
|
768
|
+
const child = base.shape[head];
|
|
769
|
+
return child !== undefined && pathExistsOnSchema(child, rest);
|
|
770
|
+
}
|
|
771
|
+
if (hasOpenCatchall(base) && base.def.catchall !== undefined) {
|
|
772
|
+
return pathExistsOnSchema(base.def.catchall, rest);
|
|
773
|
+
}
|
|
774
|
+
return false;
|
|
775
|
+
}
|
|
776
|
+
return false;
|
|
777
|
+
}
|
|
778
|
+
function requestedViewFields(view) {
|
|
779
|
+
if (view.kind === "records") {
|
|
780
|
+
return [...view.sort === undefined ? [] : [view.sort], ...view.table ?? []];
|
|
781
|
+
}
|
|
782
|
+
if (view.kind === "sum") {
|
|
783
|
+
return [view.field, ...view.by === undefined ? [] : [view.by]];
|
|
784
|
+
}
|
|
785
|
+
return [view.field];
|
|
786
|
+
}
|
|
787
|
+
function assertViewColumns(view, outputSchema) {
|
|
788
|
+
const record = resolveUnambiguousRecordSchema(outputSchema);
|
|
789
|
+
if (record === undefined)
|
|
790
|
+
return;
|
|
791
|
+
const available = Object.keys(record.shape).sort();
|
|
792
|
+
for (const field of requestedViewFields(view)) {
|
|
793
|
+
const path = field.split(".");
|
|
794
|
+
if (path.some((segment) => segment.length === 0 || isUnsafeKey(segment))) {
|
|
795
|
+
throw new CliArgumentError2(`"${field}" is not a readable field path`);
|
|
796
|
+
}
|
|
797
|
+
if (!pathExistsOnSchema(record, path)) {
|
|
798
|
+
throw new CliArgumentError2(`no record carries the field "${field}"${available.length > 0 ? ` — available: ${available.join(", ")}` : ""}`);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// src/tools/cli/command.ts
|
|
804
|
+
function defineCliResult2(output, policy) {
|
|
805
|
+
return { ...policy, output };
|
|
806
|
+
}
|
|
807
|
+
function defineCliCommand2(definition) {
|
|
808
|
+
return definition;
|
|
809
|
+
}
|
|
810
|
+
function cliCommandReturnsResult(definition) {
|
|
811
|
+
return definition.output !== undefined;
|
|
812
|
+
}
|
|
813
|
+
function cliCommandSuccessExitCode(policy, data) {
|
|
814
|
+
const successExitCode = policy?.exitCode?.(data) ?? 0;
|
|
815
|
+
if (!Number.isSafeInteger(successExitCode) || successExitCode < 0 || successExitCode > 255) {
|
|
816
|
+
throw new Error("CLI success exit code must be an integer from 0 to 255");
|
|
817
|
+
}
|
|
818
|
+
return successExitCode;
|
|
819
|
+
}
|
|
820
|
+
function cliCommandResultPolicy(definition) {
|
|
821
|
+
return cliCommandReturnsResult(definition) ? definition : undefined;
|
|
822
|
+
}
|
|
823
|
+
function prepareCliCommandEmission(policy, result, options) {
|
|
824
|
+
if (!result.ok || policy === undefined) {
|
|
825
|
+
return { result, successExitCode: 0 };
|
|
826
|
+
}
|
|
827
|
+
let successExitCode;
|
|
828
|
+
try {
|
|
829
|
+
successExitCode = cliCommandSuccessExitCode(policy, result.data);
|
|
830
|
+
} catch (error) {
|
|
831
|
+
return {
|
|
832
|
+
result: toolResultFromError(new Error("CLI result policy failed", { cause: error })),
|
|
833
|
+
successExitCode: 0
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
try {
|
|
837
|
+
if (policy.present === undefined)
|
|
838
|
+
return { result, successExitCode };
|
|
839
|
+
const presentation = policy.present({ result: result.data, options });
|
|
840
|
+
if (typeof presentation !== "string") {
|
|
841
|
+
throw new Error("CLI result presenter must return a string");
|
|
842
|
+
}
|
|
843
|
+
return { result, presentation, successExitCode };
|
|
844
|
+
} catch (error) {
|
|
845
|
+
return {
|
|
846
|
+
result,
|
|
847
|
+
presentationFailure: toolResultFromError(new Error("CLI result presentation failed", { cause: error })),
|
|
848
|
+
successExitCode
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
function emitCliCommandResult(policy, result, options, writers, emit, shown) {
|
|
853
|
+
const emission = prepareCliCommandEmission(policy, result, options);
|
|
854
|
+
if (!emission.result.ok)
|
|
855
|
+
return emitResult2(emission.result, writers, emit);
|
|
856
|
+
if (emission.presentation !== undefined) {
|
|
857
|
+
writers.stdout(emission.presentation);
|
|
858
|
+
return emission.successExitCode;
|
|
859
|
+
}
|
|
860
|
+
const printed = shown ?? emission.result;
|
|
861
|
+
if (emission.presentationFailure !== undefined) {
|
|
862
|
+
return emitPresentationFailure(printed, emission.presentationFailure, writers, emit);
|
|
863
|
+
}
|
|
864
|
+
emitResult2(printed, writers, emit);
|
|
865
|
+
return emission.successExitCode;
|
|
866
|
+
}
|
|
867
|
+
function cliCommandPresentationSchema(definition) {
|
|
868
|
+
return buildToolPresentationSchema({
|
|
869
|
+
inputSchema: definition.input,
|
|
870
|
+
unrepresentable: "any"
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
async function executeCliCommand(definition, rawArgs, options, writers, coerceJson, globals = {}) {
|
|
874
|
+
let parsed;
|
|
875
|
+
try {
|
|
876
|
+
parsed = definition.input.safeParse(coerceJson ? coerceJsonArgs2(rawArgs, definition.input) : rawArgs);
|
|
877
|
+
} catch (error) {
|
|
878
|
+
return toolResultFromError(error);
|
|
879
|
+
}
|
|
880
|
+
if (!parsed.success) {
|
|
881
|
+
return {
|
|
882
|
+
ok: false,
|
|
883
|
+
code: "VALIDATION_ERROR",
|
|
884
|
+
details: { message: `Invalid input: ${formatZodError2(parsed.error)}` }
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
try {
|
|
888
|
+
const data = await definition.handler({
|
|
889
|
+
input: parsed.data,
|
|
890
|
+
options,
|
|
891
|
+
globals,
|
|
892
|
+
...writers
|
|
893
|
+
});
|
|
894
|
+
const checked = validateDeclaredOutput(definition.output, data);
|
|
895
|
+
if (!checked.ok) {
|
|
896
|
+
return {
|
|
897
|
+
ok: false,
|
|
898
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
899
|
+
details: { message: checked.message }
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
return { ok: true, data: checked.data };
|
|
903
|
+
} catch (error) {
|
|
904
|
+
return toolResultFromError(error);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
function emitCliViewOrResult(policy, result, options, writers, emit, initialShown, mediaExitCode = 0) {
|
|
908
|
+
if (!result.ok)
|
|
909
|
+
return emitResult2(result, writers, emit);
|
|
910
|
+
let shown = initialShown ?? result;
|
|
911
|
+
if (options.view) {
|
|
912
|
+
let viewed;
|
|
913
|
+
try {
|
|
914
|
+
viewed = renderCliView2(shown.data, options.view);
|
|
915
|
+
} catch (error) {
|
|
916
|
+
const failure = error instanceof CliArgumentError2 ? { ok: false, code: "BAD_REQUEST", details: { message: error.message } } : toolResultFromError(error);
|
|
917
|
+
return emitPresentationFailure(shown, failure, writers, emit);
|
|
918
|
+
}
|
|
919
|
+
if (viewed.kind === "text") {
|
|
920
|
+
writers.stdout(viewed.text);
|
|
921
|
+
return mediaExitCode;
|
|
922
|
+
}
|
|
923
|
+
if (viewed.order) {
|
|
924
|
+
writers.stdout(`${stringifyGroups(viewed.data, viewed.order, options.json === true)}
|
|
925
|
+
`);
|
|
926
|
+
return mediaExitCode;
|
|
927
|
+
}
|
|
928
|
+
shown = { ...shown, data: viewed.data };
|
|
929
|
+
}
|
|
930
|
+
const activePolicy = options.view === undefined && !options.wait ? policy : undefined;
|
|
931
|
+
const exitCode = emitCliCommandResult(activePolicy, result, options, writers, emit, shown);
|
|
932
|
+
return mediaExitCode || exitCode;
|
|
933
|
+
}
|
|
934
|
+
var IN_PROCESS_RUN_OPTIONS = Object.freeze({
|
|
935
|
+
json: false,
|
|
936
|
+
wait: false,
|
|
937
|
+
quiet: true,
|
|
938
|
+
dryRun: false,
|
|
939
|
+
help: false,
|
|
940
|
+
schema: false
|
|
941
|
+
});
|
|
942
|
+
function shapeCliInvocationResult(result, toolName, config, policy) {
|
|
943
|
+
if (!result.ok) {
|
|
944
|
+
const normalized = toolErrorFromResult(result);
|
|
945
|
+
const hints = [];
|
|
946
|
+
if (result.hint)
|
|
947
|
+
hints.push(result.hint);
|
|
948
|
+
const global = config.errorHint?.(toolName, result.code);
|
|
949
|
+
if (global)
|
|
950
|
+
hints.push(global);
|
|
951
|
+
return {
|
|
952
|
+
ok: false,
|
|
953
|
+
exitCode: cliExitCode2(result, config.exitCodes),
|
|
954
|
+
error: {
|
|
955
|
+
code: result.code,
|
|
956
|
+
message: normalized.message,
|
|
957
|
+
...result.details !== undefined && { details: result.details },
|
|
958
|
+
...hints.length > 0 && { hint: hints.join(" ") },
|
|
959
|
+
...result.retryable !== undefined && { retryable: result.retryable }
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
const data = result.data === undefined ? undefined : projectJsonSafe(result.data).value;
|
|
964
|
+
if (policy === undefined)
|
|
965
|
+
return { ok: true, exitCode: 0, data };
|
|
966
|
+
try {
|
|
967
|
+
return {
|
|
968
|
+
ok: true,
|
|
969
|
+
exitCode: cliCommandSuccessExitCode(policy, result.data),
|
|
970
|
+
data
|
|
971
|
+
};
|
|
972
|
+
} catch (error) {
|
|
973
|
+
return shapeCliInvocationResult(toolResultFromError(new Error("CLI result policy failed", { cause: error })), toolName, config);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
async function executeNativeCommand(definition, rawArgs, coerceJson, globals, target) {
|
|
977
|
+
if (target.mode === "terminal") {
|
|
978
|
+
if (target.options.view !== undefined) {
|
|
979
|
+
if (!cliCommandReturnsResult(definition)) {
|
|
980
|
+
target.writers.stderr(`aggregate views do not apply to native command "${definition.name}" without an output schema
|
|
981
|
+
`);
|
|
982
|
+
return 2;
|
|
983
|
+
}
|
|
984
|
+
try {
|
|
985
|
+
assertViewColumns(target.options.view, definition.output);
|
|
986
|
+
} catch (error) {
|
|
987
|
+
if (!(error instanceof CliArgumentError2))
|
|
988
|
+
throw error;
|
|
989
|
+
target.writers.stderr(`${error.message}
|
|
990
|
+
`);
|
|
991
|
+
return 2;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
const result = await executeCliCommand(definition, rawArgs, target.options, target.writers, coerceJson, globals);
|
|
995
|
+
return emitCliViewOrResult(cliCommandResultPolicy(definition), result, target.options, target.writers, target.emit);
|
|
996
|
+
}
|
|
997
|
+
let out = "";
|
|
998
|
+
let err = "";
|
|
999
|
+
const result = await executeCliCommand(definition, rawArgs, IN_PROCESS_RUN_OPTIONS, {
|
|
1000
|
+
stdout: (text) => {
|
|
1001
|
+
out += text;
|
|
1002
|
+
},
|
|
1003
|
+
stderr: (text) => {
|
|
1004
|
+
err += text;
|
|
1005
|
+
}
|
|
1006
|
+
}, coerceJson, globals);
|
|
1007
|
+
const invocation = shapeCliInvocationResult(result, definition.name, target, cliCommandResultPolicy(definition));
|
|
1008
|
+
if (out === "" && err === "")
|
|
1009
|
+
return invocation;
|
|
1010
|
+
return {
|
|
1011
|
+
...invocation,
|
|
1012
|
+
written: { ...out !== "" && { stdout: out }, ...err !== "" && { stderr: err } }
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
// src/tools/cli/args-json.ts
|
|
1017
|
+
function cliFieldOption(option, fields) {
|
|
1018
|
+
const json = option.inline && option.name.endsWith(":") && !fields.has(option.name);
|
|
1019
|
+
const name = json ? option.name.slice(0, -1) : option.name;
|
|
1020
|
+
return { name, json };
|
|
1021
|
+
}
|
|
1022
|
+
function appendCliFieldValue(raw, jsonFields, name, value, info, json) {
|
|
1023
|
+
appendCliOptionValue(raw, name, value, json || jsonFields.has(name) ? { kind: "other" } : info);
|
|
1024
|
+
if (json)
|
|
1025
|
+
jsonFields.add(name);
|
|
1026
|
+
}
|
|
1027
|
+
function coerceCliFieldValue(info, values, label, json) {
|
|
1028
|
+
if (!json)
|
|
1029
|
+
return coerceField(info, values, label);
|
|
1030
|
+
try {
|
|
1031
|
+
return safeJsonParse(values[0] ?? "");
|
|
1032
|
+
} catch (cause) {
|
|
1033
|
+
throw new CliArgumentError2(`${label} expects valid JSON`, { cause });
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
// src/tools/cli/args-view.ts
|
|
1038
|
+
function resolveCliView(flags, ascending) {
|
|
1039
|
+
if (flags.size === 0) {
|
|
1040
|
+
if (ascending) {
|
|
1041
|
+
throw new CliArgumentError2("--ascending orders a record view; pass --sort with it");
|
|
1042
|
+
}
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
const countBy = flags.get("count-by");
|
|
1046
|
+
const sum = flags.get("sum");
|
|
1047
|
+
const table = flags.get("table");
|
|
1048
|
+
const by = flags.get("by");
|
|
1049
|
+
const rawTop = flags.get("top");
|
|
1050
|
+
const named = [
|
|
1051
|
+
["--count-by", countBy],
|
|
1052
|
+
["--sum", sum]
|
|
1053
|
+
].filter(([, value]) => value !== undefined);
|
|
1054
|
+
if (named.length > 1) {
|
|
1055
|
+
throw new CliArgumentError2(`${named.map(([flag]) => flag).join(" and ")} ask for different shapes — pass one`);
|
|
1056
|
+
}
|
|
1057
|
+
let top;
|
|
1058
|
+
if (rawTop !== undefined) {
|
|
1059
|
+
top = Number(rawTop);
|
|
1060
|
+
if (!Number.isInteger(top) || top <= 0) {
|
|
1061
|
+
throw new CliArgumentError2("--top must be a positive whole number");
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
const sort = flags.get("sort");
|
|
1065
|
+
if (table !== undefined || sort !== undefined) {
|
|
1066
|
+
if (countBy !== undefined || sum !== undefined) {
|
|
1067
|
+
throw new CliArgumentError2(`${table !== undefined ? "--table" : "--sort"} lists records; --count-by and --sum aggregate them — pass one`);
|
|
1068
|
+
}
|
|
1069
|
+
if (by !== undefined) {
|
|
1070
|
+
throw new CliArgumentError2("--by groups a view; a record view orders with --sort");
|
|
1071
|
+
}
|
|
1072
|
+
if (top !== undefined && sort === undefined) {
|
|
1073
|
+
throw new CliArgumentError2("--top needs --sort here: unordered records have no n largest");
|
|
1074
|
+
}
|
|
1075
|
+
let fields;
|
|
1076
|
+
if (table !== undefined) {
|
|
1077
|
+
fields = table.split(",").map((field) => field.trim()).filter(Boolean);
|
|
1078
|
+
if (fields.length === 0)
|
|
1079
|
+
throw new CliArgumentError2("--table needs at least one field");
|
|
1080
|
+
}
|
|
1081
|
+
return {
|
|
1082
|
+
kind: "records",
|
|
1083
|
+
...sort !== undefined && { sort },
|
|
1084
|
+
...ascending && { ascending },
|
|
1085
|
+
...top !== undefined && { top },
|
|
1086
|
+
...fields && { table: fields }
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
if (ascending) {
|
|
1090
|
+
throw new CliArgumentError2("--ascending orders a record view; pass --sort with it");
|
|
1091
|
+
}
|
|
1092
|
+
if (sum !== undefined) {
|
|
1093
|
+
if (top !== undefined && by === undefined) {
|
|
1094
|
+
throw new CliArgumentError2("--top needs --by: a single sum has nothing to rank");
|
|
1095
|
+
}
|
|
1096
|
+
return {
|
|
1097
|
+
kind: "sum",
|
|
1098
|
+
field: sum,
|
|
1099
|
+
...by !== undefined && { by },
|
|
1100
|
+
...top !== undefined && { top }
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
if (countBy !== undefined) {
|
|
1104
|
+
if (by !== undefined) {
|
|
1105
|
+
throw new CliArgumentError2("--count-by already names the grouping field; drop --by");
|
|
1106
|
+
}
|
|
1107
|
+
return { kind: "count", field: countBy, ...top !== undefined && { top } };
|
|
1108
|
+
}
|
|
1109
|
+
if (by !== undefined) {
|
|
1110
|
+
if (top === undefined) {
|
|
1111
|
+
throw new CliArgumentError2("--by groups a view; pass --count-by, --sum or --top with it");
|
|
1112
|
+
}
|
|
1113
|
+
return { kind: "count", field: by, top };
|
|
1114
|
+
}
|
|
1115
|
+
throw new CliArgumentError2("--top needs --sort, --by, --count-by or --sum to rank");
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
// src/tools/cli/args-classify.ts
|
|
1119
|
+
function isOptionToken(token) {
|
|
1120
|
+
return token.startsWith("--") || /^-[A-Za-z](?:=|$)/.test(token);
|
|
1121
|
+
}
|
|
1122
|
+
function looksLikeOption(token) {
|
|
1123
|
+
return token.startsWith("--") || /^-[A-Za-z]/.test(token);
|
|
1124
|
+
}
|
|
1125
|
+
var BOOL_OPTIONS = new Set([
|
|
1126
|
+
"json",
|
|
1127
|
+
"wait",
|
|
1128
|
+
"quiet",
|
|
1129
|
+
"dry-run",
|
|
1130
|
+
"help",
|
|
1131
|
+
"schema",
|
|
1132
|
+
"ascending"
|
|
1133
|
+
]);
|
|
1134
|
+
var VIEW_OPTIONS = new Set(["count-by", "sum", "by", "top", "table", "sort"]);
|
|
1135
|
+
var VALUE_OPTIONS = new Set(["wait-timeout", "output-dir", ...VIEW_OPTIONS]);
|
|
1136
|
+
var RESERVED_CLI_OPTIONS = new Set([...BOOL_OPTIONS, ...VALUE_OPTIONS]);
|
|
1137
|
+
function classifyLongOptionToken(token) {
|
|
1138
|
+
if (!token.startsWith("--") || token === "--")
|
|
1139
|
+
return;
|
|
1140
|
+
const equals = token.indexOf("=");
|
|
1141
|
+
const name = equals >= 0 ? token.slice(2, equals) : token.slice(2);
|
|
1142
|
+
return {
|
|
1143
|
+
name,
|
|
1144
|
+
value: equals >= 0 ? token.slice(equals + 1) : undefined,
|
|
1145
|
+
inline: equals >= 0,
|
|
1146
|
+
globalKind: BOOL_OPTIONS.has(name) ? "boolean" : VALUE_OPTIONS.has(name) ? "value" : undefined
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
var HELP_TOKENS = new Set(["--help", "-h", "help"]);
|
|
1150
|
+
function isCliVersionToken(token) {
|
|
1151
|
+
return token === "--version" || token === "version";
|
|
1152
|
+
}
|
|
1153
|
+
function isOptionShapedToken(token) {
|
|
1154
|
+
return token.startsWith("-") && token !== "-";
|
|
1155
|
+
}
|
|
1156
|
+
function isReservedCliCommandName(name) {
|
|
1157
|
+
return isOptionShapedToken(name) || name === "--" || HELP_TOKENS.has(name) || isCliVersionToken(name) || classifyLongOptionToken(name)?.globalKind !== undefined;
|
|
1158
|
+
}
|
|
1159
|
+
function isTopHelpOption(token) {
|
|
1160
|
+
return token === "--help" || token === "-h" || token.startsWith("--help=") && !isReservedBoolWord(token.slice("--help=".length));
|
|
1161
|
+
}
|
|
1162
|
+
function isOwnLeadingToken(token, appFields) {
|
|
1163
|
+
if (token === undefined || token === "--" || isTopHelpOption(token) || isCliVersionToken(token))
|
|
1164
|
+
return true;
|
|
1165
|
+
const opt = classifyLongOptionToken(token);
|
|
1166
|
+
if (!opt)
|
|
1167
|
+
return false;
|
|
1168
|
+
return opt.globalKind !== undefined || appFields.has(cliFieldOption(opt, appFields).name);
|
|
1169
|
+
}
|
|
1170
|
+
function deferScanError(ctx, error) {
|
|
1171
|
+
ctx.deferredError ??= error;
|
|
1172
|
+
}
|
|
1173
|
+
function recordAppGlobalError(ctx, error) {
|
|
1174
|
+
ctx.appGlobalError ??= error;
|
|
1175
|
+
deferScanError(ctx, error);
|
|
1176
|
+
}
|
|
1177
|
+
function pushRestToken(ctx, token, index) {
|
|
1178
|
+
ctx.withoutGlobals.push(token);
|
|
1179
|
+
ctx.withoutCommand.push(token);
|
|
1180
|
+
ctx.withoutCommandFrom.push(index);
|
|
1181
|
+
}
|
|
1182
|
+
function pushCommandToken(ctx, token, index) {
|
|
1183
|
+
if ((ctx.removedAfterCmdToken || ctx.separatedInput.has(index)) && ctx.commandTokens.length > 0) {
|
|
1184
|
+
ctx.separatedBefore.add(ctx.commandTokens.length);
|
|
1185
|
+
}
|
|
1186
|
+
ctx.removedAfterCmdToken = false;
|
|
1187
|
+
ctx.commandTokens.push(token);
|
|
1188
|
+
pushRestToken(ctx, token, index);
|
|
1189
|
+
}
|
|
1190
|
+
function withoutCommandSeparations(ctx) {
|
|
1191
|
+
const separated = new Set;
|
|
1192
|
+
ctx.withoutCommandFrom.forEach((from, at) => {
|
|
1193
|
+
if (at > 0 && ctx.separatedInput.has(from))
|
|
1194
|
+
separated.add(at);
|
|
1195
|
+
});
|
|
1196
|
+
return separated;
|
|
1197
|
+
}
|
|
1198
|
+
function markCommandTokenRemoved(ctx) {
|
|
1199
|
+
if (ctx.commandFound)
|
|
1200
|
+
ctx.removedAfterCmdToken = true;
|
|
1201
|
+
}
|
|
1202
|
+
function tryReadAppGlobalToken(ctx, index, opt, raw, jsonFields) {
|
|
1203
|
+
if (!opt || opt.globalKind !== undefined)
|
|
1204
|
+
return -1;
|
|
1205
|
+
const appField = cliFieldOption(opt, ctx.appFields);
|
|
1206
|
+
const info = ctx.appFields.get(appField.name);
|
|
1207
|
+
if (!info)
|
|
1208
|
+
return -1;
|
|
1209
|
+
if (ctx.bareBool)
|
|
1210
|
+
ctx.bareBool.removedAfter = true;
|
|
1211
|
+
let { value } = opt;
|
|
1212
|
+
let nextIndex = index;
|
|
1213
|
+
if (value === undefined && info.kind === "boolean") {
|
|
1214
|
+
const sep = separateBoolValue(ctx.argv[index + 1]);
|
|
1215
|
+
if (sep !== undefined)
|
|
1216
|
+
nextIndex++;
|
|
1217
|
+
value = String(sep ?? true);
|
|
1218
|
+
} else if (value === undefined) {
|
|
1219
|
+
const next = ctx.argv[index + 1];
|
|
1220
|
+
if (next === undefined || isOptionToken(next)) {
|
|
1221
|
+
recordAppGlobalError(ctx, new CliArgumentError2(`--${opt.name} requires a value`));
|
|
1222
|
+
return nextIndex;
|
|
1223
|
+
}
|
|
1224
|
+
value = next;
|
|
1225
|
+
nextIndex++;
|
|
1226
|
+
} else if (info.kind === "boolean" && !appField.json) {
|
|
1227
|
+
if (raw.has(appField.name)) {
|
|
1228
|
+
appendCliFieldValue(raw, jsonFields, appField.name, value, info, appField.json);
|
|
1229
|
+
return nextIndex;
|
|
1230
|
+
}
|
|
1231
|
+
try {
|
|
1232
|
+
parseReservedBool(appField.name, value);
|
|
1233
|
+
} catch (error) {
|
|
1234
|
+
if (error instanceof CliArgumentError2)
|
|
1235
|
+
recordAppGlobalError(ctx, error);
|
|
1236
|
+
else
|
|
1237
|
+
throw error;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
appendCliFieldValue(raw, jsonFields, appField.name, value, info, appField.json);
|
|
1241
|
+
return nextIndex;
|
|
1242
|
+
}
|
|
1243
|
+
function reservedJsonTarget(opt) {
|
|
1244
|
+
if (!opt?.inline || !opt.name.endsWith(":"))
|
|
1245
|
+
return;
|
|
1246
|
+
const target = opt.name.slice(0, -1);
|
|
1247
|
+
return RESERVED_CLI_OPTIONS.has(target) ? target : undefined;
|
|
1248
|
+
}
|
|
1249
|
+
function consumeFrameworkOptionToken(argv, index, opt, state, callbacks) {
|
|
1250
|
+
const adjacent = callbacks.adjacent ?? (() => true);
|
|
1251
|
+
const report = (error) => {
|
|
1252
|
+
if (opt.name === "schema") {
|
|
1253
|
+
state.fw.schema = false;
|
|
1254
|
+
state.schemaInvalid = true;
|
|
1255
|
+
} else if (opt.name === "help")
|
|
1256
|
+
state.fw.help = false;
|
|
1257
|
+
callbacks.onError(error);
|
|
1258
|
+
};
|
|
1259
|
+
const record = (name, raw, kind) => {
|
|
1260
|
+
try {
|
|
1261
|
+
appendCliOptionValue(state.fwFlags, name, raw, { kind });
|
|
1262
|
+
return true;
|
|
1263
|
+
} catch (error) {
|
|
1264
|
+
if (error instanceof CliArgumentError2) {
|
|
1265
|
+
report(error);
|
|
1266
|
+
return false;
|
|
1267
|
+
}
|
|
1268
|
+
throw error;
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
let nextIdx = index;
|
|
1272
|
+
if (opt.globalKind === "boolean") {
|
|
1273
|
+
const following = argv[index + 1];
|
|
1274
|
+
if (!opt.inline && !adjacent(index + 1) && following !== undefined && separateBoolValue(following) !== undefined) {
|
|
1275
|
+
report(brokenBooleanBoundaryError(opt.name, following));
|
|
1276
|
+
if (opt.name === "help" || opt.name === "schema")
|
|
1277
|
+
return nextIdx;
|
|
1278
|
+
}
|
|
1279
|
+
const nextTok = adjacent(index + 1) ? following : undefined;
|
|
1280
|
+
const sep = opt.inline ? undefined : separateBoolValue(nextTok);
|
|
1281
|
+
if (sep !== undefined && nextTok !== undefined) {
|
|
1282
|
+
nextIdx++;
|
|
1283
|
+
callbacks.onValueToken?.(nextTok);
|
|
1284
|
+
}
|
|
1285
|
+
const rawValue = opt.value ?? String(sep ?? true);
|
|
1286
|
+
if (opt.name !== "help" && !record(opt.name, rawValue, "boolean"))
|
|
1287
|
+
return nextIdx;
|
|
1288
|
+
let enabled;
|
|
1289
|
+
if (opt.inline) {
|
|
1290
|
+
try {
|
|
1291
|
+
enabled = parseReservedBool(opt.name, opt.value ?? "");
|
|
1292
|
+
} catch (error) {
|
|
1293
|
+
if (error instanceof CliArgumentError2) {
|
|
1294
|
+
report(error);
|
|
1295
|
+
return nextIdx;
|
|
1296
|
+
}
|
|
1297
|
+
throw error;
|
|
1298
|
+
}
|
|
1299
|
+
} else {
|
|
1300
|
+
enabled = sep ?? true;
|
|
1301
|
+
}
|
|
1302
|
+
if (!opt.inline && sep === undefined)
|
|
1303
|
+
callbacks.onBareBoolean?.(opt.name);
|
|
1304
|
+
if (opt.name === "dry-run")
|
|
1305
|
+
state.fw.dryRun = enabled;
|
|
1306
|
+
else if (opt.name === "json")
|
|
1307
|
+
state.fw.json = enabled;
|
|
1308
|
+
else if (opt.name === "wait")
|
|
1309
|
+
state.fw.wait = enabled;
|
|
1310
|
+
else if (opt.name === "quiet")
|
|
1311
|
+
state.fw.quiet = enabled;
|
|
1312
|
+
else if (opt.name === "ascending")
|
|
1313
|
+
state.ascending = enabled;
|
|
1314
|
+
else if (opt.name === "schema") {
|
|
1315
|
+
state.fw.schema = !state.schemaInvalid && (state.fw.schema || enabled);
|
|
1316
|
+
} else if (opt.name === "help")
|
|
1317
|
+
state.fw.help = state.fw.help || enabled;
|
|
1318
|
+
return nextIdx;
|
|
1319
|
+
}
|
|
1320
|
+
let value = opt.value;
|
|
1321
|
+
if (!opt.inline) {
|
|
1322
|
+
const next = adjacent(index + 1) ? argv[index + 1] : undefined;
|
|
1323
|
+
if (next === undefined || isOptionToken(next)) {
|
|
1324
|
+
report(new CliArgumentError2(`--${opt.name} requires a value`));
|
|
1325
|
+
if (callbacks.onMissingValue?.(next))
|
|
1326
|
+
nextIdx++;
|
|
1327
|
+
} else {
|
|
1328
|
+
value = next;
|
|
1329
|
+
nextIdx++;
|
|
1330
|
+
callbacks.onValueToken?.(next);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
if (value !== undefined) {
|
|
1334
|
+
if (!record(opt.name, value, "string"))
|
|
1335
|
+
return nextIdx;
|
|
1336
|
+
if (opt.name === "wait-timeout") {
|
|
1337
|
+
const n = Number(value);
|
|
1338
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
1339
|
+
report(new CliArgumentError2("--wait-timeout must be a positive number"));
|
|
1340
|
+
} else {
|
|
1341
|
+
state.fw.waitTimeout = n;
|
|
1342
|
+
}
|
|
1343
|
+
} else if (VIEW_OPTIONS.has(opt.name))
|
|
1344
|
+
state.viewFlags.set(opt.name, value);
|
|
1345
|
+
else
|
|
1346
|
+
state.fw.outputDir = value;
|
|
1347
|
+
}
|
|
1348
|
+
return nextIdx;
|
|
1349
|
+
}
|
|
1350
|
+
function readFrameworkOptionToken(ctx, index, token, opt) {
|
|
1351
|
+
ctx.bareBool = undefined;
|
|
1352
|
+
pushRestToken(ctx, token, index);
|
|
1353
|
+
return consumeFrameworkOptionToken(ctx.argv, index, opt, ctx, {
|
|
1354
|
+
adjacent: (at) => !ctx.separatedInput.has(at),
|
|
1355
|
+
onError: (error) => deferScanError(ctx, error),
|
|
1356
|
+
onValueToken: (valueToken) => pushRestToken(ctx, valueToken, index + 1),
|
|
1357
|
+
onBareBoolean: (name) => {
|
|
1358
|
+
ctx.bareBool = { name, removedAfter: false };
|
|
1359
|
+
},
|
|
1360
|
+
onMissingValue: (next) => {
|
|
1361
|
+
if (!ctx.commandFound && next !== undefined && !isOwnLeadingToken(next, ctx.appFields)) {
|
|
1362
|
+
pushRestToken(ctx, next, index + 1);
|
|
1363
|
+
return true;
|
|
1364
|
+
}
|
|
1365
|
+
return false;
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
function finalizeFrameworkView(ctx) {
|
|
1370
|
+
if (ctx.viewFlags.size === 0 && !ctx.ascending)
|
|
1371
|
+
return;
|
|
1372
|
+
try {
|
|
1373
|
+
ctx.fw.view = resolveCliView(ctx.viewFlags, ctx.ascending);
|
|
1374
|
+
} catch (error) {
|
|
1375
|
+
if (error instanceof CliArgumentError2)
|
|
1376
|
+
deferScanError(ctx, error);
|
|
1377
|
+
else
|
|
1378
|
+
throw error;
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
function createFrameworkStepContext(argv, appFields, separatedInput = new Set) {
|
|
1382
|
+
return {
|
|
1383
|
+
argv,
|
|
1384
|
+
appFields,
|
|
1385
|
+
fwFlags: new Map,
|
|
1386
|
+
viewFlags: new Map,
|
|
1387
|
+
fw: { json: false, quiet: false, help: false, schema: false, dryRun: false, wait: false },
|
|
1388
|
+
ascending: false,
|
|
1389
|
+
commandFound: false,
|
|
1390
|
+
withoutGlobals: [],
|
|
1391
|
+
withoutCommand: [],
|
|
1392
|
+
withoutCommandFrom: [],
|
|
1393
|
+
commandTokens: [],
|
|
1394
|
+
separatedBefore: new Set,
|
|
1395
|
+
removedAfterCmdToken: false,
|
|
1396
|
+
separatedInput
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
function coerceAppGlobalMap(raw, fields, jsonFields) {
|
|
1400
|
+
const coerced = {};
|
|
1401
|
+
for (const [name, values] of raw) {
|
|
1402
|
+
coerced[name] = coerceCliFieldValue(fields.get(name), values, `--${name}`, jsonFields.has(name));
|
|
1403
|
+
}
|
|
1404
|
+
return coerced;
|
|
1405
|
+
}
|
|
1406
|
+
function brokenBooleanBoundaryError(flagName, word) {
|
|
1407
|
+
const flag = flagName.startsWith("-") ? flagName : `--${flagName}`;
|
|
1408
|
+
return new CliArgumentError2(`Bare ${flag} cannot be separated from "${word}" — use ${flag}=true, ${flag}=false or "-- ${word}"`);
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
// src/tools/cli/stream-surface.ts
|
|
1412
|
+
function cliStreamIdentity(serviceName, methodName, method) {
|
|
1413
|
+
if (!method.stream || !method.expose?.includes("CLI"))
|
|
1414
|
+
return;
|
|
1415
|
+
return { name: toToolName(serviceName, methodName), descriptor: method.stream };
|
|
1416
|
+
}
|
|
1417
|
+
function collectCliStreams(services) {
|
|
1418
|
+
const streams = new Map;
|
|
1419
|
+
for (const service of services) {
|
|
1420
|
+
for (const [methodName, method] of Object.entries(service.methods)) {
|
|
1421
|
+
const identity = cliStreamIdentity(service.name, methodName, method);
|
|
1422
|
+
if (identity === undefined)
|
|
1423
|
+
continue;
|
|
1424
|
+
const { name, descriptor } = identity;
|
|
1425
|
+
streams.set(name, {
|
|
1426
|
+
descriptor,
|
|
1427
|
+
tool: {
|
|
1428
|
+
method,
|
|
1429
|
+
name,
|
|
1430
|
+
argumentSchema: mergeSchemas(method.paramsSchema, method.inputSchema),
|
|
1431
|
+
presentationSchema: buildToolPresentationSchema({
|
|
1432
|
+
paramsSchema: method.paramsSchema,
|
|
1433
|
+
inputSchema: method.inputSchema,
|
|
1434
|
+
inputRecursionDepth: method.inputRecursionDepth,
|
|
1435
|
+
unrepresentable: "any"
|
|
1436
|
+
}),
|
|
1437
|
+
shouldExtend: false
|
|
1438
|
+
}
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
return streams;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
// src/tools/cli/command-shape.ts
|
|
1446
|
+
function nativeCliDescriptor(definition) {
|
|
1447
|
+
return {
|
|
1448
|
+
description: definition.description,
|
|
1449
|
+
argumentSchema: definition.input,
|
|
1450
|
+
presentationSchema: cliCommandPresentationSchema(definition),
|
|
1451
|
+
outputSchema: definition.output
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
function assertNoPassthroughAlias(name, descriptor, passthroughField) {
|
|
1455
|
+
if (passthroughField !== undefined && descriptor.aliases.has(passthroughField)) {
|
|
1456
|
+
throw new Error(`[stitchkit] CLI command "${name}" cannot alias passthrough field "${passthroughField}"`);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
function invokerCommandShapeIssue(name, descriptor, exists, passthroughField) {
|
|
1460
|
+
assertUniqueToolName(name, exists, "CLI command");
|
|
1461
|
+
assertNoPassthroughAlias(name, descriptor, passthroughField);
|
|
1462
|
+
return;
|
|
1463
|
+
}
|
|
1464
|
+
function assertCliCommandName(name) {
|
|
1465
|
+
if (isReservedCliCommandName(name)) {
|
|
1466
|
+
throw new Error(`[stitchkit] CLI command "${name}" is reserved. Rename the command to a word outside the option syntax.`);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
function assertStaticCliCommandNames(services, runtimeTools) {
|
|
1470
|
+
for (const tool of runtimeTools) {
|
|
1471
|
+
assertNoLegacyTransports(tool, `Runtime tool "${tool.name}"`);
|
|
1472
|
+
if (tool.expose?.includes("CLI"))
|
|
1473
|
+
assertCliCommandName(tool.name);
|
|
1474
|
+
}
|
|
1475
|
+
for (const service of services) {
|
|
1476
|
+
for (const [key, method] of Object.entries(service.methods)) {
|
|
1477
|
+
const name = projectedContractToolName(service.name, key, method, "CLI") ?? cliStreamIdentity(service.name, key, method)?.name;
|
|
1478
|
+
if (name !== undefined)
|
|
1479
|
+
assertCliCommandName(name);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
function commandShapeIssue(name, descriptor, exists, passthroughField, applicationGlobals = new Set) {
|
|
1484
|
+
assertUniqueToolName(name, exists, "CLI command");
|
|
1485
|
+
assertCliCommandName(name);
|
|
1486
|
+
assertNoPassthroughAlias(name, descriptor, passthroughField);
|
|
1487
|
+
const fieldNames = jsonSchemaFields(descriptor.presentationSchema).map((field) => field.name);
|
|
1488
|
+
const conflicting = fieldNames.filter((field) => RESERVED_CLI_OPTIONS.has(field));
|
|
1489
|
+
if (conflicting.length > 0) {
|
|
1490
|
+
return `[stitchkit] CLI command "${name}" declares reserved option field(s): ${conflicting.join(", ")}`;
|
|
1491
|
+
}
|
|
1492
|
+
const shadowed = fieldNames.filter((field) => applicationGlobals.has(field));
|
|
1493
|
+
if (shadowed.length > 0) {
|
|
1494
|
+
return `[stitchkit] CLI command "${name}" declares field(s) shadowed by application global options: ${shadowed.join(", ")}`;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
// src/tools/cli/policy.ts
|
|
1499
|
+
var REMOVED_TOP_LEVEL_KEYS = [
|
|
1500
|
+
"optionAliases",
|
|
1501
|
+
"positionals",
|
|
1502
|
+
"results",
|
|
1503
|
+
"passthrough",
|
|
1504
|
+
"wait"
|
|
1505
|
+
];
|
|
1506
|
+
function assertNoLegacyCliPolicyKeys(config) {
|
|
1507
|
+
if (typeof config !== "object" || config === null)
|
|
1508
|
+
return;
|
|
1509
|
+
for (const key of REMOVED_TOP_LEVEL_KEYS) {
|
|
1510
|
+
if (Object.hasOwn(config, key)) {
|
|
1511
|
+
throw new TypeError(`[stitchkit] CLI option "${key}" was moved into "commandSettings.<command>" — migrate to commandSettings`);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
var SHORT_ALIAS = /^[A-Za-z]$/;
|
|
1516
|
+
var RESERVED_SHORT_OPTIONS = new Set(["h"]);
|
|
1517
|
+
function fieldMap(descriptor) {
|
|
1518
|
+
return new Map(jsonSchemaFields(descriptor.presentationSchema).map((field) => [field.name, field]));
|
|
1519
|
+
}
|
|
1520
|
+
function resolveAliases(command, descriptor, configured) {
|
|
1521
|
+
if (!configured)
|
|
1522
|
+
return new Map;
|
|
1523
|
+
const fields = fieldMap(descriptor);
|
|
1524
|
+
const aliases = new Map;
|
|
1525
|
+
for (const [alias, target] of Object.entries(configured)) {
|
|
1526
|
+
if (!SHORT_ALIAS.test(alias)) {
|
|
1527
|
+
throw new Error(`[stitchkit] CLI command "${command}" alias "${alias}" must be one ASCII letter`);
|
|
1528
|
+
}
|
|
1529
|
+
if (RESERVED_SHORT_OPTIONS.has(alias)) {
|
|
1530
|
+
throw new Error(`[stitchkit] CLI command "${command}" alias "-${alias}" is reserved`);
|
|
1531
|
+
}
|
|
1532
|
+
if (isUnsafeKey(target) || !fields.has(target)) {
|
|
1533
|
+
throw new Error(`[stitchkit] CLI command "${command}" alias "-${alias}" targets unknown field "${target}"`);
|
|
1534
|
+
}
|
|
1535
|
+
const existing = aliases.get(target);
|
|
1536
|
+
if (existing !== undefined) {
|
|
1537
|
+
throw new Error(`[stitchkit] CLI command "${command}" field "${target}" has multiple aliases: -${existing}, -${alias}`);
|
|
1538
|
+
}
|
|
1539
|
+
aliases.set(target, alias);
|
|
591
1540
|
}
|
|
592
1541
|
return aliases;
|
|
593
1542
|
}
|
|
@@ -618,25 +1567,29 @@ function resolvePositionals(command, descriptor, configured) {
|
|
|
618
1567
|
}
|
|
619
1568
|
return [...configured];
|
|
620
1569
|
}
|
|
1570
|
+
function cliCommandSettingsFor(config, command) {
|
|
1571
|
+
return config.commandSettings && Object.hasOwn(config.commandSettings, command) ? config.commandSettings[command] : undefined;
|
|
1572
|
+
}
|
|
621
1573
|
function cliResultPolicy(config, command) {
|
|
622
|
-
return
|
|
1574
|
+
return cliCommandSettingsFor(config, command)?.result;
|
|
1575
|
+
}
|
|
1576
|
+
function cliPassthroughField(config, command) {
|
|
1577
|
+
return cliCommandSettingsFor(config, command)?.passthrough;
|
|
1578
|
+
}
|
|
1579
|
+
function cliWaitConfig(config, command) {
|
|
1580
|
+
return cliCommandSettingsFor(config, command)?.wait;
|
|
623
1581
|
}
|
|
624
1582
|
function applyCliPresentationPolicy(command, descriptor, config) {
|
|
625
1583
|
const base = { ...descriptor, aliases: new Map };
|
|
626
|
-
const
|
|
627
|
-
const configuredPositionals = config.positionals && Object.hasOwn(config.positionals, command) ? config.positionals[command] : undefined;
|
|
1584
|
+
const settings = cliCommandSettingsFor(config, command);
|
|
628
1585
|
return {
|
|
629
1586
|
...base,
|
|
630
|
-
aliases: resolveAliases(command, base,
|
|
631
|
-
positionals: resolvePositionals(command, base,
|
|
1587
|
+
aliases: resolveAliases(command, base, settings?.aliases),
|
|
1588
|
+
positionals: resolvePositionals(command, base, settings?.positionals)
|
|
632
1589
|
};
|
|
633
1590
|
}
|
|
634
1591
|
function assertCliPoliciesResolved(commands, config) {
|
|
635
|
-
const configuredNames = new Set(
|
|
636
|
-
...Object.keys(config.optionAliases ?? {}),
|
|
637
|
-
...Object.keys(config.positionals ?? {}),
|
|
638
|
-
...Object.keys(config.results ?? {})
|
|
639
|
-
]);
|
|
1592
|
+
const configuredNames = new Set(Object.keys(config.commandSettings ?? {}));
|
|
640
1593
|
if (config.defaultCommand !== undefined)
|
|
641
1594
|
configuredNames.add(config.defaultCommand);
|
|
642
1595
|
for (const name of configuredNames) {
|
|
@@ -646,100 +1599,200 @@ function assertCliPoliciesResolved(commands, config) {
|
|
|
646
1599
|
}
|
|
647
1600
|
}
|
|
648
1601
|
|
|
649
|
-
// src/tools/cli/
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
1602
|
+
// src/tools/cli/unix-outcome.ts
|
|
1603
|
+
var MAX_CAUSE_DEPTH = 16;
|
|
1604
|
+
var UNIX_ERROR_CODES = new Set(UNIX_CLIENT_TRANSPORT_ERROR_CODES);
|
|
1605
|
+
var UNIX_DELIVERY_STATES = new Set(UNIX_CLIENT_DELIVERY_STATES);
|
|
1606
|
+
function ownString(value, key) {
|
|
1607
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
1608
|
+
return descriptor && "value" in descriptor && typeof descriptor.value === "string" ? descriptor.value : undefined;
|
|
1609
|
+
}
|
|
1610
|
+
function isUnixErrorCode(value) {
|
|
1611
|
+
return value !== undefined && UNIX_ERROR_CODES.has(value);
|
|
1612
|
+
}
|
|
1613
|
+
function isUnixDeliveryState(value) {
|
|
1614
|
+
return value !== undefined && UNIX_DELIVERY_STATES.has(value);
|
|
1615
|
+
}
|
|
1616
|
+
function findUnixTransportError(root) {
|
|
1617
|
+
const visited = new Set;
|
|
1618
|
+
let current = root;
|
|
1619
|
+
for (let depth = 0;depth < MAX_CAUSE_DEPTH && current !== undefined; depth += 1) {
|
|
1620
|
+
if (typeof current !== "object" || current === null || visited.has(current))
|
|
1621
|
+
return;
|
|
1622
|
+
visited.add(current);
|
|
1623
|
+
if (current instanceof Error && ownString(current, "name") === UNIX_CLIENT_TRANSPORT_ERROR_NAME) {
|
|
1624
|
+
const code = ownString(current, "code");
|
|
1625
|
+
const delivery = ownString(current, "delivery");
|
|
1626
|
+
if (isUnixErrorCode(code) && isUnixDeliveryState(delivery)) {
|
|
1627
|
+
const inner = current.cause;
|
|
1628
|
+
const causeCode = typeof inner === "object" && inner !== null ? ownString(inner, "code") : undefined;
|
|
1629
|
+
const causePath = typeof inner === "object" && inner !== null ? ownString(inner, "path") : undefined;
|
|
1630
|
+
const socketPath = ownString(current, "socketPath") ?? causePath;
|
|
1631
|
+
return {
|
|
1632
|
+
code,
|
|
1633
|
+
delivery,
|
|
1634
|
+
message: current.message,
|
|
1635
|
+
...causeCode !== undefined && { causeCode },
|
|
1636
|
+
...socketPath !== undefined && { socketPath }
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
677
1639
|
}
|
|
1640
|
+
current = "cause" in current ? Reflect.get(current, "cause") : undefined;
|
|
678
1641
|
}
|
|
679
|
-
return
|
|
1642
|
+
return;
|
|
680
1643
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
return
|
|
686
|
-
|
|
1644
|
+
function notDispatchedMessage(found) {
|
|
1645
|
+
if (found.code === "UNIX_CONNECT_FAILED") {
|
|
1646
|
+
const target = found.socketPath ? `"${found.socketPath}"` : "the unix socket";
|
|
1647
|
+
const suffix = found.causeCode ? ` (${found.causeCode})` : "";
|
|
1648
|
+
return `Not executed: application is not listening on ${target}${suffix}`;
|
|
1649
|
+
}
|
|
1650
|
+
if (found.code === "UNIX_TARGET_REFUSED") {
|
|
1651
|
+
return `Not executed: unix socket target refused — ${found.message}`;
|
|
1652
|
+
}
|
|
1653
|
+
return `Not executed: ${found.message}`;
|
|
687
1654
|
}
|
|
688
|
-
function
|
|
689
|
-
if (
|
|
690
|
-
return
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
1655
|
+
function notDispatchedHint(code) {
|
|
1656
|
+
if (code === "UNIX_CONNECT_FAILED") {
|
|
1657
|
+
return "The request was not executed because the application is not listening; start the application and retry.";
|
|
1658
|
+
}
|
|
1659
|
+
if (code === "UNIX_TARGET_REFUSED") {
|
|
1660
|
+
return "The request was not executed; check the unix socket path, owner and directory permissions.";
|
|
1661
|
+
}
|
|
1662
|
+
return "The request was not dispatched to the application.";
|
|
1663
|
+
}
|
|
1664
|
+
function projectCliUnixFailure(result) {
|
|
1665
|
+
const found = findUnixTransportError(toolCauseFromResult(result));
|
|
1666
|
+
if (!found)
|
|
1667
|
+
return result;
|
|
1668
|
+
if (found.delivery === "not-dispatched") {
|
|
1669
|
+
return {
|
|
1670
|
+
ok: false,
|
|
1671
|
+
code: found.code,
|
|
1672
|
+
details: {
|
|
1673
|
+
message: notDispatchedMessage(found),
|
|
1674
|
+
delivery: "not-dispatched",
|
|
1675
|
+
...found.socketPath !== undefined && { socketPath: found.socketPath },
|
|
1676
|
+
...found.causeCode !== undefined && { errno: found.causeCode }
|
|
1677
|
+
},
|
|
1678
|
+
hint: notDispatchedHint(found.code),
|
|
1679
|
+
retryable: found.code === "UNIX_CONNECT_FAILED"
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1682
|
+
if (found.delivery === "possibly-dispatched") {
|
|
1683
|
+
const code = found.code === "UNIX_HEADERS_TIMEOUT" ? "UNIX_HEADERS_TIMEOUT" : "UNIX_DELIVERY_UNCERTAIN";
|
|
1684
|
+
const message = found.code === "UNIX_HEADERS_TIMEOUT" ? `Outcome unknown, not retried: ${found.message}` : `Outcome unknown, not retried: connection closed after the request was sent (${found.message})`;
|
|
1685
|
+
return {
|
|
1686
|
+
ok: false,
|
|
1687
|
+
code,
|
|
1688
|
+
details: {
|
|
1689
|
+
message,
|
|
1690
|
+
delivery: "possibly-dispatched",
|
|
1691
|
+
...found.socketPath !== undefined && { socketPath: found.socketPath }
|
|
1692
|
+
},
|
|
1693
|
+
hint: "The request may have been executed by the application before the connection closed; inspect state before retrying.",
|
|
1694
|
+
retryable: false
|
|
1695
|
+
};
|
|
1696
|
+
}
|
|
698
1697
|
return {
|
|
699
1698
|
ok: false,
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
...result.retryable !== undefined && { retryable: result.retryable }
|
|
707
|
-
}
|
|
1699
|
+
code: found.code,
|
|
1700
|
+
details: {
|
|
1701
|
+
message: found.message,
|
|
1702
|
+
delivery: "response-received"
|
|
1703
|
+
},
|
|
1704
|
+
retryable: false
|
|
708
1705
|
};
|
|
709
1706
|
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
1707
|
+
|
|
1708
|
+
// src/tools/cli/runner.ts
|
|
1709
|
+
function assertCliAuthConfig(config) {
|
|
1710
|
+
if (config.auth !== undefined && config.resolveAuth !== undefined) {
|
|
1711
|
+
throw new Error("[stitchkit] createCli: use either auth or resolveAuth, not both");
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
function resolveCliIdentity(config, typedGlobals) {
|
|
1715
|
+
let authPromise;
|
|
1716
|
+
return () => {
|
|
1717
|
+
authPromise ??= (async () => config.resolveAuth ? await config.resolveAuth(typedGlobals) : await config.auth)();
|
|
1718
|
+
return authPromise;
|
|
1719
|
+
};
|
|
1720
|
+
}
|
|
1721
|
+
function createCliToolRunner(config, lifecycle, auth, typedGlobals) {
|
|
1722
|
+
const run = createToolRunner({
|
|
720
1723
|
source: "cli",
|
|
721
1724
|
toolSurface: true,
|
|
722
1725
|
context: { ...config.context?.(auth, typedGlobals), signal: config.signal },
|
|
723
1726
|
hooks: config.hooks,
|
|
724
|
-
lifecycle
|
|
1727
|
+
lifecycle,
|
|
725
1728
|
coerceJsonArgs: config.coerceJsonArgs
|
|
726
1729
|
});
|
|
1730
|
+
return async (tool, rawArgs, context, call) => {
|
|
1731
|
+
const result = await run(tool, rawArgs, context, call);
|
|
1732
|
+
return result.ok ? result : projectCliUnixFailure(result);
|
|
1733
|
+
};
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
// src/tools/cli/unavailable.ts
|
|
1737
|
+
function unavailableCommand(reason) {
|
|
1738
|
+
return toolResultFromError(new AppError2("CLI_COMMAND_UNAVAILABLE", {
|
|
1739
|
+
message: reason,
|
|
1740
|
+
status: STITCH_ERROR_STATUS2.CLI_COMMAND_UNAVAILABLE,
|
|
1741
|
+
retryable: false
|
|
1742
|
+
}));
|
|
1743
|
+
}
|
|
1744
|
+
function unknownCliCommand(command) {
|
|
1745
|
+
return {
|
|
1746
|
+
ok: false,
|
|
1747
|
+
code: "UNKNOWN_OPERATION",
|
|
1748
|
+
details: { message: `Unknown command "${command}"`, operation: command }
|
|
1749
|
+
};
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
// src/tools/cli/invoke.ts
|
|
1753
|
+
function cliInvocationResult2(result, toolName, config) {
|
|
1754
|
+
return shapeCliInvocationResult(result, toolName, config);
|
|
1755
|
+
}
|
|
1756
|
+
async function createCliInvoker2(config, globals) {
|
|
1757
|
+
const lifecycle = resolveOptionalCliToolAccess("createCliInvoker", config);
|
|
1758
|
+
assertNoLegacyCliPolicyKeys(config);
|
|
1759
|
+
assertCliAuthConfig(config);
|
|
1760
|
+
const typedGlobals = parseCliGlobalValues(config.globalOptions, globals);
|
|
1761
|
+
const auth = await resolveCliIdentity(config, typedGlobals)();
|
|
1762
|
+
const natives = new Map;
|
|
1763
|
+
const allNativeHelp = new Map;
|
|
1764
|
+
for (const definition of config.commands ?? []) {
|
|
1765
|
+
const descriptor = applyCliPresentationPolicy(definition.name, nativeCliDescriptor(definition), config);
|
|
1766
|
+
invokerCommandShapeIssue(definition.name, descriptor, allNativeHelp.has(definition.name), cliPassthroughField(config, definition.name));
|
|
1767
|
+
allNativeHelp.set(definition.name, descriptor);
|
|
1768
|
+
if (cliCommandReturnsResult(definition))
|
|
1769
|
+
natives.set(definition.name, definition);
|
|
1770
|
+
}
|
|
1771
|
+
const { tools, help } = buildCliSurface(config, auth, typedGlobals, allNativeHelp, new Set, invokerCommandShapeIssue);
|
|
1772
|
+
const runTool = createCliToolRunner(config, lifecycle, auth, typedGlobals);
|
|
727
1773
|
return {
|
|
728
|
-
commands: [
|
|
729
|
-
name,
|
|
730
|
-
|
|
731
|
-
|
|
1774
|
+
commands: [
|
|
1775
|
+
...[...natives].map(([name, definition]) => ({
|
|
1776
|
+
name,
|
|
1777
|
+
description: definition.description
|
|
1778
|
+
})),
|
|
1779
|
+
...[...help].filter(([name, presentation]) => !allNativeHelp.has(name) && presentation.unavailableReason === undefined).map(([name, presentation]) => ({
|
|
1780
|
+
name,
|
|
1781
|
+
description: presentation.description
|
|
1782
|
+
}))
|
|
1783
|
+
],
|
|
732
1784
|
invoke: async (command, args) => {
|
|
733
1785
|
const native = natives.get(command);
|
|
734
|
-
if (native)
|
|
735
|
-
return
|
|
1786
|
+
if (native) {
|
|
1787
|
+
return executeNativeCommand(native, args, config.coerceJsonArgs ?? true, typedGlobals, {
|
|
1788
|
+
mode: "in-process",
|
|
1789
|
+
errorHint: config.errorHint,
|
|
1790
|
+
exitCodes: config.exitCodes
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
736
1793
|
const tool = tools.get(command);
|
|
737
1794
|
if (!tool) {
|
|
738
|
-
return cliInvocationResult2(
|
|
739
|
-
ok: false,
|
|
740
|
-
code: "UNKNOWN_OPERATION",
|
|
741
|
-
details: { message: `Unknown command "${command}"`, operation: command }
|
|
742
|
-
}, command, config);
|
|
1795
|
+
return cliInvocationResult2(unknownCliCommand(command), command, config);
|
|
743
1796
|
}
|
|
744
1797
|
let result;
|
|
745
1798
|
try {
|
|
@@ -747,48 +1800,15 @@ async function createCliInvoker2(config, globals) {
|
|
|
747
1800
|
} catch (error) {
|
|
748
1801
|
result = toolResultFromError(error);
|
|
749
1802
|
}
|
|
750
|
-
return
|
|
751
|
-
}
|
|
752
|
-
};
|
|
753
|
-
}
|
|
754
|
-
function withSuccessExitCode(invocation, policy, result, command, config) {
|
|
755
|
-
if (!result.ok || policy === undefined)
|
|
756
|
-
return invocation;
|
|
757
|
-
try {
|
|
758
|
-
return { ...invocation, exitCode: cliCommandSuccessExitCode(policy, result.data) };
|
|
759
|
-
} catch (error) {
|
|
760
|
-
return cliInvocationResult2(toolResultFromError(new Error("CLI result policy failed", { cause: error })), command, config);
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
var IN_PROCESS_RUN_OPTIONS = Object.freeze({
|
|
764
|
-
json: false,
|
|
765
|
-
wait: false,
|
|
766
|
-
quiet: true,
|
|
767
|
-
dryRun: false,
|
|
768
|
-
help: false
|
|
769
|
-
});
|
|
770
|
-
async function runNativeCommand(definition, args, config, globals) {
|
|
771
|
-
let out = "";
|
|
772
|
-
let err = "";
|
|
773
|
-
const result = await executeCliCommand(definition, args, IN_PROCESS_RUN_OPTIONS, {
|
|
774
|
-
stdout: (text) => {
|
|
775
|
-
out += text;
|
|
776
|
-
},
|
|
777
|
-
stderr: (text) => {
|
|
778
|
-
err += text;
|
|
1803
|
+
return shapeCliInvocationResult(result, command, config, cliResultPolicy(config, command));
|
|
779
1804
|
}
|
|
780
|
-
}, config.coerceJsonArgs ?? true, globals);
|
|
781
|
-
const invocation = withSuccessExitCode(cliInvocationResult2(result, definition.name, config), cliCommandResultPolicy(definition), result, definition.name, config);
|
|
782
|
-
if (out === "" && err === "")
|
|
783
|
-
return invocation;
|
|
784
|
-
return {
|
|
785
|
-
...invocation,
|
|
786
|
-
written: { ...out !== "" && { stdout: out }, ...err !== "" && { stderr: err } }
|
|
787
1805
|
};
|
|
788
1806
|
}
|
|
789
|
-
function buildCliSurface(config, auth, nativeHelp, applicationGlobalNames, shapeIssue) {
|
|
790
|
-
|
|
791
|
-
|
|
1807
|
+
function buildCliSurface(config, auth, typedGlobals, nativeHelp, applicationGlobalNames, shapeIssue) {
|
|
1808
|
+
resolveOptionalCliToolAccess("buildCliSurface", config);
|
|
1809
|
+
assertNoLegacyCliPolicyKeys(config);
|
|
1810
|
+
const services = typeof config.services === "function" ? config.services(auth, typedGlobals) : config.services ?? [];
|
|
1811
|
+
const runtimeTools = typeof config.runtimeTools === "function" ? config.runtimeTools(auth, typedGlobals) : config.runtimeTools ?? [];
|
|
792
1812
|
const tools = new Map;
|
|
793
1813
|
const help = new Map(nativeHelp);
|
|
794
1814
|
for (const { kind, mountable } of collectToolSurface({
|
|
@@ -796,7 +1816,7 @@ function buildCliSurface(config, auth, nativeHelp, applicationGlobalNames, shape
|
|
|
796
1816
|
transport: "CLI"
|
|
797
1817
|
})) {
|
|
798
1818
|
const descriptor = applyCliPresentationPolicy(mountable.name, managedCliDescriptor(mountable), config);
|
|
799
|
-
const issue = shapeIssue?.(mountable.name, descriptor, help.has(mountable.name), config
|
|
1819
|
+
const issue = shapeIssue?.(mountable.name, descriptor, help.has(mountable.name), cliPassthroughField(config, mountable.name), applicationGlobalNames);
|
|
800
1820
|
if (issue !== undefined) {
|
|
801
1821
|
if (kind !== "runtime")
|
|
802
1822
|
throw new Error(issue);
|
|
@@ -813,13 +1833,16 @@ function buildCliSurface(config, auth, nativeHelp, applicationGlobalNames, shape
|
|
|
813
1833
|
outputSchema: stream.descriptor.item,
|
|
814
1834
|
stream: true
|
|
815
1835
|
}, config);
|
|
816
|
-
const issue = shapeIssue?.(name, descriptor, help.has(name), config
|
|
1836
|
+
const issue = shapeIssue?.(name, descriptor, help.has(name), cliPassthroughField(config, name), applicationGlobalNames);
|
|
817
1837
|
if (issue !== undefined)
|
|
818
1838
|
throw new Error(issue);
|
|
819
1839
|
help.set(name, descriptor);
|
|
820
1840
|
}
|
|
821
1841
|
assertCliPoliciesResolved(help, config);
|
|
822
|
-
for (const [name,
|
|
1842
|
+
for (const [name, settings] of Object.entries(config.commandSettings ?? {})) {
|
|
1843
|
+
const policy = settings?.result;
|
|
1844
|
+
if (!policy)
|
|
1845
|
+
continue;
|
|
823
1846
|
if (!tools.has(name) && !streams.has(name)) {
|
|
824
1847
|
throw new Error(`[stitchkit] CLI result policy "${name}" targets a command that is not managed; a native command declares present and exitCode on defineCliCommand`);
|
|
825
1848
|
}
|
|
@@ -890,7 +1913,8 @@ function readPipedStdin(input = process.stdin) {
|
|
|
890
1913
|
|
|
891
1914
|
// src/tools/cli/io.ts
|
|
892
1915
|
function isReaderGone(error) {
|
|
893
|
-
|
|
1916
|
+
const code = errnoOf(error);
|
|
1917
|
+
return code === "EPIPE" || code === "ERR_STREAM_DESTROYED";
|
|
894
1918
|
}
|
|
895
1919
|
function createCliIo(config) {
|
|
896
1920
|
let pendingWrite;
|
|
@@ -904,7 +1928,7 @@ function createCliIo(config) {
|
|
|
904
1928
|
} catch (error) {
|
|
905
1929
|
if (fd === 1 && isReaderGone(error))
|
|
906
1930
|
throw error;
|
|
907
|
-
if (
|
|
1931
|
+
if (errnoOf(error) === "EAGAIN") {
|
|
908
1932
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 1);
|
|
909
1933
|
continue;
|
|
910
1934
|
}
|
|
@@ -953,159 +1977,226 @@ function createCliIo(config) {
|
|
|
953
1977
|
// src/tools/cli/notices.ts
|
|
954
1978
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
955
1979
|
|
|
956
|
-
// src/tools/cli/args-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
"json",
|
|
965
|
-
"wait",
|
|
966
|
-
"quiet",
|
|
967
|
-
"dry-run",
|
|
968
|
-
"help",
|
|
969
|
-
"schema",
|
|
970
|
-
"ascending"
|
|
971
|
-
]);
|
|
972
|
-
var VIEW_OPTIONS = new Set(["count-by", "sum", "by", "top", "table", "sort"]);
|
|
973
|
-
var VALUE_OPTIONS = new Set(["wait-timeout", "output-dir", ...VIEW_OPTIONS]);
|
|
974
|
-
var RESERVED_CLI_OPTIONS = new Set([...BOOL_OPTIONS, ...VALUE_OPTIONS]);
|
|
975
|
-
function classifyLongOptionToken(token) {
|
|
976
|
-
if (!token.startsWith("--") || token === "--")
|
|
1980
|
+
// src/tools/cli/args-scan.ts
|
|
1981
|
+
var EMPTY_FIELDS = new Map;
|
|
1982
|
+
function optionBeforeCommandError(token) {
|
|
1983
|
+
const name = token.split("=")[0] ?? token;
|
|
1984
|
+
return new CliArgumentError2(`${name} is an option of a command, not a command: put it after the command name (<command> ${token})`);
|
|
1985
|
+
}
|
|
1986
|
+
function bareOptionInfo(token) {
|
|
1987
|
+
if (token === undefined || token === "--" || token === "-h")
|
|
977
1988
|
return;
|
|
978
|
-
const
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
};
|
|
1989
|
+
const opt = classifyLongOptionToken(token);
|
|
1990
|
+
if (opt) {
|
|
1991
|
+
return opt.inline ? undefined : { name: opt.name, frameworkBool: opt.globalKind === "boolean" };
|
|
1992
|
+
}
|
|
1993
|
+
if (/^-[A-Za-z]$/.test(token))
|
|
1994
|
+
return { name: token, frameworkBool: false };
|
|
1995
|
+
return;
|
|
986
1996
|
}
|
|
987
|
-
function
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1997
|
+
function withdrawBrokenRequest(ctx, name) {
|
|
1998
|
+
if (name === "schema") {
|
|
1999
|
+
ctx.fw.schema = false;
|
|
2000
|
+
ctx.schemaInvalid = true;
|
|
2001
|
+
} else if (name === "help")
|
|
2002
|
+
ctx.fw.help = false;
|
|
2003
|
+
}
|
|
2004
|
+
function scanCliArgv(argv, options = {}) {
|
|
2005
|
+
const { appGlobals, defaultCommand } = options;
|
|
2006
|
+
const appFields = appGlobals ? describeSchemaFields(appGlobals) : EMPTY_FIELDS;
|
|
2007
|
+
const ctx = createFrameworkStepContext(argv, appFields, options.separatedBefore);
|
|
2008
|
+
ctx.commandFound = options.afterCommand === true;
|
|
2009
|
+
const appRaw = new Map;
|
|
2010
|
+
const appJson = new Set;
|
|
2011
|
+
const separatedBeforeGlobals = new Set;
|
|
2012
|
+
let command;
|
|
2013
|
+
let topLevelHelp = false;
|
|
2014
|
+
let expectHelpFilter = false;
|
|
2015
|
+
let helpFilter;
|
|
2016
|
+
let version = false;
|
|
2017
|
+
let optionsEnded = false;
|
|
2018
|
+
let separatorBeforeCommand = false;
|
|
2019
|
+
let optionBeforeCommand;
|
|
2020
|
+
let leadingToken;
|
|
2021
|
+
let hadLeadingPrefix = false;
|
|
2022
|
+
let boundaryError;
|
|
2023
|
+
const boundarySeparatedBefore = new Set;
|
|
2024
|
+
let liftedBoundaryError;
|
|
2025
|
+
let liftedAfter;
|
|
2026
|
+
for (let i = 0;i < argv.length; i++) {
|
|
2027
|
+
const token = argv[i];
|
|
992
2028
|
if (token === undefined)
|
|
993
2029
|
continue;
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
2030
|
+
const bareBefore = liftedAfter;
|
|
2031
|
+
liftedAfter = undefined;
|
|
2032
|
+
if (optionsEnded) {
|
|
2033
|
+
pushCommandToken(ctx, token, i);
|
|
998
2034
|
continue;
|
|
999
|
-
|
|
1000
|
-
if (
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
if (option?.globalKind === "boolean" && !option.inline) {
|
|
1011
|
-
prefix[prefix.length - 1] = last === "--help" ? "-h" : `${last}=true`;
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
var HELP_TOKENS = new Set(["--help", "-h", "help"]);
|
|
1015
|
-
function isCliVersionToken(token) {
|
|
1016
|
-
return token === "--version" || token === "version";
|
|
1017
|
-
}
|
|
1018
|
-
function isReservedCliCommandName(name) {
|
|
1019
|
-
return name === "--" || HELP_TOKENS.has(name) || isCliVersionToken(name) || classifyLongOptionToken(name)?.globalKind !== undefined;
|
|
1020
|
-
}
|
|
1021
|
-
function helpFilterFrom(token, rest) {
|
|
1022
|
-
if (token?.startsWith("--help=")) {
|
|
1023
|
-
const value = token.slice("--help=".length).trim();
|
|
1024
|
-
if (value.length === 0 || isReservedBoolWord(value))
|
|
1025
|
-
return;
|
|
1026
|
-
return value;
|
|
1027
|
-
}
|
|
1028
|
-
if (token === undefined || !HELP_TOKENS.has(token))
|
|
1029
|
-
return;
|
|
1030
|
-
const next = rest[0];
|
|
1031
|
-
return next !== undefined && !next.startsWith("-") ? next : undefined;
|
|
1032
|
-
}
|
|
1033
|
-
function isTopHelpOption(token) {
|
|
1034
|
-
return token === "--help" || token === "-h" || token.startsWith("--help=") && !isReservedBoolWord(token.slice("--help=".length));
|
|
1035
|
-
}
|
|
1036
|
-
function leadingGlobalCount(argv, hasDefault) {
|
|
1037
|
-
let index = 0;
|
|
1038
|
-
while (index < argv.length) {
|
|
1039
|
-
const token = argv[index];
|
|
1040
|
-
if (token === undefined || isTopHelpOption(token))
|
|
1041
|
-
break;
|
|
1042
|
-
const option = classifyLongOptionToken(token);
|
|
1043
|
-
if (!option?.globalKind)
|
|
1044
|
-
break;
|
|
1045
|
-
index++;
|
|
1046
|
-
if (option.inline)
|
|
2035
|
+
}
|
|
2036
|
+
if (token === "--") {
|
|
2037
|
+
ctx.bareBool = undefined;
|
|
2038
|
+
optionsEnded = true;
|
|
2039
|
+
if (!ctx.commandFound && !topLevelHelp && !version) {
|
|
2040
|
+
separatorBeforeCommand = true;
|
|
2041
|
+
deferScanError(ctx, new CliArgumentError2('A command is required before "--"'));
|
|
2042
|
+
pushRestToken(ctx, token, i);
|
|
2043
|
+
} else {
|
|
2044
|
+
pushCommandToken(ctx, token, i);
|
|
2045
|
+
}
|
|
1047
2046
|
continue;
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
if (
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
2047
|
+
}
|
|
2048
|
+
const opt = classifyLongOptionToken(token);
|
|
2049
|
+
const appNext = tryReadAppGlobalToken(ctx, i, opt, appRaw, appJson);
|
|
2050
|
+
if (appNext >= 0) {
|
|
2051
|
+
liftedAfter = bareBefore ?? bareOptionInfo(ctx.withoutGlobals.at(-1));
|
|
2052
|
+
markCommandTokenRemoved(ctx);
|
|
2053
|
+
i = appNext;
|
|
2054
|
+
continue;
|
|
2055
|
+
}
|
|
2056
|
+
if (bareBefore !== undefined) {
|
|
2057
|
+
if (bareBefore.frameworkBool && separateBoolValue(token) !== undefined) {
|
|
2058
|
+
liftedBoundaryError ??= brokenBooleanBoundaryError(bareBefore.name, token);
|
|
2059
|
+
withdrawBrokenRequest(ctx, bareBefore.name);
|
|
2060
|
+
deferScanError(ctx, liftedBoundaryError);
|
|
2061
|
+
separatedBeforeGlobals.add(ctx.withoutGlobals.length);
|
|
2062
|
+
} else if (!bareBefore.frameworkBool && !isOptionToken(token)) {
|
|
2063
|
+
separatedBeforeGlobals.add(ctx.withoutGlobals.length);
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
if (!ctx.commandFound && !topLevelHelp && !version && (isTopHelpOption(token) || token === "help" || isCliVersionToken(token))) {
|
|
2067
|
+
ctx.bareBool = undefined;
|
|
2068
|
+
leadingToken = token;
|
|
2069
|
+
hadLeadingPrefix = ctx.withoutGlobals.length > 0;
|
|
2070
|
+
ctx.withoutGlobals.push(token);
|
|
2071
|
+
if (isCliVersionToken(token))
|
|
2072
|
+
version = true;
|
|
2073
|
+
else {
|
|
2074
|
+
topLevelHelp = true;
|
|
2075
|
+
if (token.startsWith("--help=")) {
|
|
2076
|
+
helpFilter = token.slice("--help=".length).trim() || undefined;
|
|
2077
|
+
} else
|
|
2078
|
+
expectHelpFilter = true;
|
|
1057
2079
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
2080
|
+
continue;
|
|
2081
|
+
}
|
|
2082
|
+
if (token === "-h") {
|
|
2083
|
+
ctx.bareBool = undefined;
|
|
2084
|
+
ctx.fw.help = true;
|
|
2085
|
+
markCommandTokenRemoved(ctx);
|
|
2086
|
+
pushRestToken(ctx, token, i);
|
|
2087
|
+
continue;
|
|
2088
|
+
}
|
|
2089
|
+
const jsonTarget = reservedJsonTarget(opt);
|
|
2090
|
+
if (jsonTarget !== undefined) {
|
|
2091
|
+
ctx.bareBool = undefined;
|
|
2092
|
+
if (jsonTarget === "schema") {
|
|
2093
|
+
ctx.fw.schema = false;
|
|
2094
|
+
ctx.schemaInvalid = true;
|
|
2095
|
+
} else if (jsonTarget === "help")
|
|
2096
|
+
ctx.fw.help = false;
|
|
2097
|
+
deferScanError(ctx, new CliArgumentError2(`--${jsonTarget} is a framework option and does not accept :=JSON`));
|
|
2098
|
+
markCommandTokenRemoved(ctx);
|
|
2099
|
+
pushRestToken(ctx, token, i);
|
|
2100
|
+
continue;
|
|
2101
|
+
}
|
|
2102
|
+
if (opt?.globalKind !== undefined) {
|
|
2103
|
+
markCommandTokenRemoved(ctx);
|
|
2104
|
+
i = readFrameworkOptionToken(ctx, i, token, opt);
|
|
2105
|
+
continue;
|
|
1060
2106
|
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
commandArgv: [],
|
|
1070
|
-
topLevelHelp: false,
|
|
1071
|
-
version: false,
|
|
1072
|
-
error: 'A command is required before "--"'
|
|
1073
|
-
};
|
|
1074
|
-
}
|
|
1075
|
-
if (defaultCommand !== undefined) {
|
|
1076
|
-
if (token !== undefined && isTopHelpOption(token)) {
|
|
1077
|
-
const helpFilter = helpFilterFrom(token, argv.slice(index + 1));
|
|
1078
|
-
return {
|
|
1079
|
-
commandArgv: [],
|
|
1080
|
-
topLevelHelp: true,
|
|
1081
|
-
version: false,
|
|
1082
|
-
...helpFilter !== undefined && { helpFilter }
|
|
1083
|
-
};
|
|
2107
|
+
if (topLevelHelp || version) {
|
|
2108
|
+
if (topLevelHelp && expectHelpFilter) {
|
|
2109
|
+
expectHelpFilter = false;
|
|
2110
|
+
if (!token.startsWith("-"))
|
|
2111
|
+
helpFilter = token;
|
|
2112
|
+
}
|
|
2113
|
+
pushRestToken(ctx, token, i);
|
|
2114
|
+
continue;
|
|
1084
2115
|
}
|
|
1085
|
-
if (
|
|
1086
|
-
|
|
2116
|
+
if (!ctx.commandFound) {
|
|
2117
|
+
if (defaultCommand !== undefined && isOptionShapedToken(token)) {
|
|
2118
|
+
command = defaultCommand;
|
|
2119
|
+
ctx.commandFound = true;
|
|
2120
|
+
} else if (isOptionShapedToken(token)) {
|
|
2121
|
+
optionBeforeCommand ??= optionBeforeCommandError(token);
|
|
2122
|
+
deferScanError(ctx, optionBeforeCommand);
|
|
2123
|
+
pushRestToken(ctx, token, i);
|
|
2124
|
+
continue;
|
|
2125
|
+
} else {
|
|
2126
|
+
command = token;
|
|
2127
|
+
ctx.commandFound = true;
|
|
2128
|
+
ctx.withoutGlobals.push(token);
|
|
2129
|
+
if (ctx.bareBool)
|
|
2130
|
+
ctx.bareBool.removedAfter = true;
|
|
2131
|
+
continue;
|
|
2132
|
+
}
|
|
1087
2133
|
}
|
|
1088
|
-
if (
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
version: false
|
|
1094
|
-
};
|
|
2134
|
+
if (ctx.bareBool?.removedAfter && separateBoolValue(token) !== undefined) {
|
|
2135
|
+
withdrawBrokenRequest(ctx, ctx.bareBool.name);
|
|
2136
|
+
boundaryError ??= brokenBooleanBoundaryError(ctx.bareBool.name, token);
|
|
2137
|
+
deferScanError(ctx, boundaryError);
|
|
2138
|
+
boundarySeparatedBefore.add(ctx.withoutCommand.length);
|
|
1095
2139
|
}
|
|
2140
|
+
ctx.bareBool = undefined;
|
|
2141
|
+
pushCommandToken(ctx, token, i);
|
|
2142
|
+
}
|
|
2143
|
+
finalizeFrameworkView(ctx);
|
|
2144
|
+
let globals = parseCliGlobalValues(undefined, {});
|
|
2145
|
+
try {
|
|
2146
|
+
const rawGlobals = coerceAppGlobalMap(appRaw, appFields, appJson);
|
|
2147
|
+
globals = parseCliGlobalValues(appGlobals, rawGlobals);
|
|
2148
|
+
} catch (error) {
|
|
2149
|
+
if (error instanceof CliArgumentError2)
|
|
2150
|
+
recordAppGlobalError(ctx, error);
|
|
2151
|
+
else
|
|
2152
|
+
throw error;
|
|
2153
|
+
}
|
|
2154
|
+
if (!ctx.commandFound && !topLevelHelp && !version && !separatorBeforeCommand) {
|
|
2155
|
+
if (defaultCommand !== undefined)
|
|
2156
|
+
command = defaultCommand;
|
|
2157
|
+
else if (ctx.deferredError === undefined || ctx.fw.help)
|
|
2158
|
+
topLevelHelp = true;
|
|
1096
2159
|
}
|
|
1097
|
-
const commandIndex = token === undefined ? 0 : index;
|
|
1098
|
-
const command = argv[commandIndex];
|
|
1099
|
-
const rest = argv.slice(commandIndex + 1);
|
|
1100
|
-
const prefix = argv.slice(0, commandIndex);
|
|
1101
|
-
preserveCliBooleanBoundary(prefix, rest[0]);
|
|
1102
|
-
const helpFilter = commandIndex > 0 || defaultCommand === undefined ? helpFilterFrom(command, rest) : undefined;
|
|
1103
2160
|
return {
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
2161
|
+
framework: ctx.fw,
|
|
2162
|
+
globals,
|
|
2163
|
+
...command !== undefined && { command },
|
|
2164
|
+
commandTokens: ctx.commandTokens,
|
|
2165
|
+
separatedBefore: ctx.separatedBefore,
|
|
2166
|
+
topLevelHelp,
|
|
2167
|
+
...helpFilter !== undefined && { helpFilter },
|
|
2168
|
+
version,
|
|
2169
|
+
withoutGlobals: ctx.withoutGlobals,
|
|
2170
|
+
withoutCommand: ctx.withoutCommand,
|
|
2171
|
+
withoutCommandSeparatedBefore: withoutCommandSeparations(ctx),
|
|
2172
|
+
separatedBeforeGlobals,
|
|
2173
|
+
...ctx.deferredError !== undefined && { deferredError: ctx.deferredError },
|
|
2174
|
+
...ctx.appGlobalError !== undefined && { appGlobalError: ctx.appGlobalError },
|
|
2175
|
+
...boundaryError !== undefined && { boundaryError },
|
|
2176
|
+
boundarySeparatedBefore,
|
|
2177
|
+
...liftedBoundaryError !== undefined && { liftedBoundaryError },
|
|
2178
|
+
separatorBeforeCommand,
|
|
2179
|
+
...optionBeforeCommand !== undefined && { optionBeforeCommand },
|
|
2180
|
+
...leadingToken !== undefined && { leadingToken },
|
|
2181
|
+
hadLeadingPrefix
|
|
2182
|
+
};
|
|
2183
|
+
}
|
|
2184
|
+
function answersBeforeArguments(scan) {
|
|
2185
|
+
return scan.topLevelHelp || scan.version || scan.framework.help || scan.framework.schema;
|
|
2186
|
+
}
|
|
2187
|
+
function scanCliInvocation2(argv, options) {
|
|
2188
|
+
const res = scanCliArgv(argv, options);
|
|
2189
|
+
if (!answersBeforeArguments(res) && res.deferredError !== undefined)
|
|
2190
|
+
throw res.deferredError;
|
|
2191
|
+
return {
|
|
2192
|
+
framework: res.framework,
|
|
2193
|
+
globals: res.globals,
|
|
2194
|
+
...res.command !== undefined && { command: res.command },
|
|
2195
|
+
commandTokens: res.commandTokens,
|
|
2196
|
+
separatedBefore: res.separatedBefore,
|
|
2197
|
+
topLevelHelp: res.topLevelHelp,
|
|
2198
|
+
...res.helpFilter !== undefined && { helpFilter: res.helpFilter },
|
|
2199
|
+
version: res.version
|
|
1109
2200
|
};
|
|
1110
2201
|
}
|
|
1111
2202
|
|
|
@@ -1119,9 +2210,18 @@ function writeCliNotice(text) {
|
|
|
1119
2210
|
if (invocation !== undefined) {
|
|
1120
2211
|
if (!invocation.quiet)
|
|
1121
2212
|
invocation.stderr(text);
|
|
1122
|
-
|
|
1123
|
-
|
|
2213
|
+
return;
|
|
2214
|
+
}
|
|
2215
|
+
let quiet;
|
|
2216
|
+
try {
|
|
2217
|
+
quiet = scanCliInvocation2(process.argv.slice(2)).framework.quiet;
|
|
2218
|
+
} catch (error) {
|
|
2219
|
+
if (error instanceof CliArgumentError2)
|
|
2220
|
+
return;
|
|
2221
|
+
throw error;
|
|
1124
2222
|
}
|
|
2223
|
+
if (!quiet)
|
|
2224
|
+
process.stderr.write(text);
|
|
1125
2225
|
}
|
|
1126
2226
|
|
|
1127
2227
|
// src/tools/cli/download.ts
|
|
@@ -1147,15 +2247,15 @@ async function writeDownload(root, name, data) {
|
|
|
1147
2247
|
// src/tools/cli/inline-files.ts
|
|
1148
2248
|
import { basename } from "node:path";
|
|
1149
2249
|
import { pathToFileURL } from "node:url";
|
|
1150
|
-
import { z as
|
|
1151
|
-
var EmbeddedResourceSchema =
|
|
1152
|
-
type:
|
|
1153
|
-
resource:
|
|
1154
|
-
|
|
1155
|
-
|
|
2250
|
+
import { z as z3 } from "zod";
|
|
2251
|
+
var EmbeddedResourceSchema = z3.object({
|
|
2252
|
+
type: z3.literal("resource"),
|
|
2253
|
+
resource: z3.union([
|
|
2254
|
+
z3.object({ uri: z3.string(), mimeType: z3.string().optional(), blob: z3.string() }),
|
|
2255
|
+
z3.object({ uri: z3.string(), mimeType: z3.string().optional(), text: z3.string() })
|
|
1156
2256
|
])
|
|
1157
2257
|
});
|
|
1158
|
-
var InlineFileSchema =
|
|
2258
|
+
var InlineFileSchema = z3.discriminatedUnion("type", [
|
|
1159
2259
|
McpImageContentSchema,
|
|
1160
2260
|
McpAudioContentSchema,
|
|
1161
2261
|
EmbeddedResourceSchema
|
|
@@ -1331,12 +2431,15 @@ var GLOBAL_OPTIONS = [
|
|
|
1331
2431
|
["--table <a,b>", "Render the named fields as an aligned table"]
|
|
1332
2432
|
];
|
|
1333
2433
|
function typeLabel(schema) {
|
|
1334
|
-
if (Array.isArray(schema.enum))
|
|
2434
|
+
if (HELP_SHOWN_KEYWORDS.has("enum") && Array.isArray(schema.enum)) {
|
|
1335
2435
|
return schema.enum.join("|");
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
2436
|
+
}
|
|
2437
|
+
if (HELP_SHOWN_KEYWORDS.has("type")) {
|
|
2438
|
+
if (schema.type === "array")
|
|
2439
|
+
return "value";
|
|
2440
|
+
if (typeof schema.type === "string")
|
|
2441
|
+
return schema.type;
|
|
2442
|
+
}
|
|
1340
2443
|
return "value";
|
|
1341
2444
|
}
|
|
1342
2445
|
function isPatternOnly(member) {
|
|
@@ -1344,8 +2447,8 @@ function isPatternOnly(member) {
|
|
|
1344
2447
|
}
|
|
1345
2448
|
function constraintLabel(schema) {
|
|
1346
2449
|
const limits = [];
|
|
1347
|
-
const format = typeof schema.format === "string" ? schema.format : undefined;
|
|
1348
|
-
const pattern = typeof schema.pattern === "string" ? schema.pattern : undefined;
|
|
2450
|
+
const format = HELP_SHOWN_KEYWORDS.has("format") && typeof schema.format === "string" ? schema.format : undefined;
|
|
2451
|
+
const pattern = HELP_SHOWN_KEYWORDS.has("pattern") && typeof schema.pattern === "string" ? schema.pattern : undefined;
|
|
1349
2452
|
const named = format !== undefined && STANDARD_STRING_FORMATS.has(format);
|
|
1350
2453
|
if (format !== undefined && (named || pattern === undefined)) {
|
|
1351
2454
|
limits.push(format);
|
|
@@ -1363,6 +2466,8 @@ function constraintLabel(schema) {
|
|
|
1363
2466
|
["maxItems", "items <="]
|
|
1364
2467
|
];
|
|
1365
2468
|
for (const [keyword, label] of bounds) {
|
|
2469
|
+
if (!HELP_SHOWN_KEYWORDS.has(keyword))
|
|
2470
|
+
continue;
|
|
1366
2471
|
const bound = schema[keyword];
|
|
1367
2472
|
if (typeof bound !== "number")
|
|
1368
2473
|
continue;
|
|
@@ -1376,6 +2481,8 @@ function constraintLabel(schema) {
|
|
|
1376
2481
|
["allOf", "all of", " & "]
|
|
1377
2482
|
];
|
|
1378
2483
|
for (const [keyword, label, separator] of compositions) {
|
|
2484
|
+
if (!HELP_SHOWN_KEYWORDS.has(keyword))
|
|
2485
|
+
continue;
|
|
1379
2486
|
const members = schema[keyword];
|
|
1380
2487
|
if (!Array.isArray(members))
|
|
1381
2488
|
continue;
|
|
@@ -1531,50 +2638,10 @@ function renderCommandHelp(name, command, descriptor, applicationOptions = []) {
|
|
|
1531
2638
|
`;
|
|
1532
2639
|
}
|
|
1533
2640
|
|
|
1534
|
-
// src/tools/cli/command-shape.ts
|
|
1535
|
-
function assertCliCommandName(name) {
|
|
1536
|
-
if (isReservedCliCommandName(name)) {
|
|
1537
|
-
throw new Error(`[stitchkit] CLI command "${name}" is reserved. Rename the command to a word outside the framework option syntax.`);
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
function assertStaticCliCommandNames(services, runtimeTools) {
|
|
1541
|
-
for (const tool of runtimeTools) {
|
|
1542
|
-
if (tool.transports?.includes("CLI"))
|
|
1543
|
-
assertCliCommandName(tool.name);
|
|
1544
|
-
}
|
|
1545
|
-
for (const service of services) {
|
|
1546
|
-
for (const [key, method] of Object.entries(service.methods)) {
|
|
1547
|
-
const name = projectedContractToolName(service.name, key, method, "CLI") ?? cliStreamIdentity(service.name, key, method)?.name;
|
|
1548
|
-
if (name !== undefined)
|
|
1549
|
-
assertCliCommandName(name);
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
function commandShapeIssue(name, descriptor, exists, passthroughField, applicationGlobals = new Set) {
|
|
1554
|
-
assertUniqueToolName(name, exists, "CLI command");
|
|
1555
|
-
assertCliCommandName(name);
|
|
1556
|
-
if (passthroughField !== undefined && descriptor.aliases.has(passthroughField)) {
|
|
1557
|
-
throw new Error(`[stitchkit] CLI command "${name}" cannot alias passthrough field "${passthroughField}"`);
|
|
1558
|
-
}
|
|
1559
|
-
const fieldNames = jsonSchemaFields(descriptor.presentationSchema).map((field) => field.name);
|
|
1560
|
-
const conflicting = fieldNames.filter((field) => RESERVED_CLI_OPTIONS.has(field));
|
|
1561
|
-
if (conflicting.length > 0) {
|
|
1562
|
-
return `[stitchkit] CLI command "${name}" declares reserved option field(s): ${conflicting.join(", ")}`;
|
|
1563
|
-
}
|
|
1564
|
-
const shadowed = fieldNames.filter((field) => applicationGlobals.has(field));
|
|
1565
|
-
if (shadowed.length > 0) {
|
|
1566
|
-
return `[stitchkit] CLI command "${name}" declares field(s) shadowed by application global options: ${shadowed.join(", ")}`;
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
2641
|
// src/tools/cli/managed-surface.ts
|
|
1571
2642
|
async function buildManagedSurface(session, typedGlobals, forExecution) {
|
|
1572
2643
|
const { config, nativeHelp, applicationGlobalNames } = session;
|
|
1573
|
-
|
|
1574
|
-
const resolveIdentity = () => {
|
|
1575
|
-
authPromise ??= (async () => config.resolveAuth ? await config.resolveAuth(typedGlobals) : await config.auth)();
|
|
1576
|
-
return authPromise;
|
|
1577
|
-
};
|
|
2644
|
+
const resolveIdentity = resolveCliIdentity(config, typedGlobals);
|
|
1578
2645
|
let auth;
|
|
1579
2646
|
if (session.hasManagedFactory || forExecution) {
|
|
1580
2647
|
try {
|
|
@@ -1590,53 +2657,26 @@ async function buildManagedSurface(session, typedGlobals, forExecution) {
|
|
|
1590
2657
|
};
|
|
1591
2658
|
}
|
|
1592
2659
|
}
|
|
1593
|
-
const { tools, streams, help } = buildCliSurface(config, auth, nativeHelp, applicationGlobalNames, commandShapeIssue);
|
|
2660
|
+
const { tools, streams, help } = buildCliSurface(config, auth, typedGlobals, nativeHelp, applicationGlobalNames, commandShapeIssue);
|
|
1594
2661
|
return { resolved: true, auth, help, tools, streams };
|
|
1595
2662
|
}
|
|
1596
2663
|
|
|
1597
|
-
// src/tools/cli/args.ts
|
|
1598
|
-
import { z as z3 } from "zod";
|
|
1599
|
-
|
|
1600
|
-
// src/tools/cli/args-json.ts
|
|
1601
|
-
function cliFieldOption(option, fields) {
|
|
1602
|
-
const json = option.inline && option.name.endsWith(":") && !fields.has(option.name);
|
|
1603
|
-
const name = json ? option.name.slice(0, -1) : option.name;
|
|
1604
|
-
return { name, json };
|
|
1605
|
-
}
|
|
1606
|
-
function appendCliFieldValue(raw, jsonFields, name, value, info, json) {
|
|
1607
|
-
appendCliOptionValue(raw, name, value, json || jsonFields.has(name) ? { kind: "other" } : info);
|
|
1608
|
-
if (json)
|
|
1609
|
-
jsonFields.add(name);
|
|
1610
|
-
}
|
|
1611
|
-
function coerceCliFieldValue(info, values, label, json) {
|
|
1612
|
-
if (!json)
|
|
1613
|
-
return coerceField(info, values, label);
|
|
1614
|
-
try {
|
|
1615
|
-
return safeJsonParse(values[0] ?? "");
|
|
1616
|
-
} catch (cause) {
|
|
1617
|
-
throw new CliArgumentError2(`${label} expects valid JSON`, { cause });
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
|
|
1621
2664
|
// src/tools/cli/args-tokens.ts
|
|
1622
2665
|
function readCliTokens(argv, fields, fieldFor, config) {
|
|
1623
|
-
const
|
|
1624
|
-
json: false,
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
help: false
|
|
2666
|
+
const fwState = {
|
|
2667
|
+
fw: { json: false, wait: false, quiet: false, dryRun: false, help: false, schema: false },
|
|
2668
|
+
fwFlags: new Map,
|
|
2669
|
+
viewFlags: new Map,
|
|
2670
|
+
ascending: false
|
|
1629
2671
|
};
|
|
1630
2672
|
const flags = new Map;
|
|
1631
2673
|
const jsonFields = new Set;
|
|
1632
2674
|
const literalBooleanFlags = new Set;
|
|
1633
|
-
const frameworkFlags = new Map;
|
|
1634
|
-
const viewFlags = new Map;
|
|
1635
|
-
let ascending = false;
|
|
1636
2675
|
const positionals = [];
|
|
1637
2676
|
const pushFlag = (name, value, json = false) => {
|
|
1638
2677
|
appendCliFieldValue(flags, jsonFields, name, value, fieldFor(name), json);
|
|
1639
2678
|
};
|
|
2679
|
+
const adjacent = (index) => !config.separatedBefore?.has(index);
|
|
1640
2680
|
let optionsEnded = false;
|
|
1641
2681
|
for (let i = 0;i < argv.length; i++) {
|
|
1642
2682
|
const tok = argv[i];
|
|
@@ -1651,30 +2691,31 @@ function readCliTokens(argv, fields, fieldFor, config) {
|
|
|
1651
2691
|
continue;
|
|
1652
2692
|
}
|
|
1653
2693
|
if (tok === "-h") {
|
|
1654
|
-
|
|
2694
|
+
fwState.fw.help = true;
|
|
1655
2695
|
continue;
|
|
1656
2696
|
}
|
|
1657
2697
|
if (!tok.startsWith("--")) {
|
|
1658
2698
|
const match = /^-([A-Za-z])(?:=(.*))?$/.exec(tok);
|
|
1659
2699
|
const alias = match?.[1];
|
|
1660
|
-
const field = alias === undefined ? undefined : config.
|
|
2700
|
+
const field = alias === undefined ? undefined : config.aliases?.get(alias);
|
|
1661
2701
|
if (!alias || !field)
|
|
1662
2702
|
throw new CliArgumentError2(`Unknown option "${tok}"`);
|
|
1663
2703
|
const inline = match?.[2];
|
|
1664
2704
|
const info = fieldFor(field);
|
|
1665
2705
|
if (info?.kind === "boolean") {
|
|
1666
|
-
const separate = inline === undefined ? separateBoolValue(argv[i + 1]) : undefined;
|
|
2706
|
+
const separate = inline === undefined && adjacent(i + 1) ? separateBoolValue(argv[i + 1]) : undefined;
|
|
1667
2707
|
if (separate !== undefined)
|
|
1668
2708
|
i++;
|
|
1669
2709
|
pushFlag(field, inline ?? String(separate ?? true));
|
|
1670
|
-
if (inline !== undefined)
|
|
2710
|
+
if (inline !== undefined && info.pureBoolean === true) {
|
|
1671
2711
|
parseReservedBool(field, inline);
|
|
2712
|
+
}
|
|
1672
2713
|
literalBooleanFlags.add(field);
|
|
1673
2714
|
continue;
|
|
1674
2715
|
}
|
|
1675
2716
|
let value = inline;
|
|
1676
2717
|
if (value === undefined) {
|
|
1677
|
-
const next = argv[i + 1];
|
|
2718
|
+
const next = adjacent(i + 1) ? argv[i + 1] : undefined;
|
|
1678
2719
|
if (next !== undefined && !isOptionToken(next)) {
|
|
1679
2720
|
value = next;
|
|
1680
2721
|
i++;
|
|
@@ -1695,55 +2736,16 @@ function readCliTokens(argv, fields, fieldFor, config) {
|
|
|
1695
2736
|
if (json && RESERVED_CLI_OPTIONS.has(name)) {
|
|
1696
2737
|
throw new CliArgumentError2(`--${name} is a framework option and does not accept :=JSON`);
|
|
1697
2738
|
}
|
|
1698
|
-
if (option.globalKind
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
appendCliOptionValue(frameworkFlags, name, value ?? String(separate ?? true), {
|
|
1704
|
-
kind: "boolean"
|
|
1705
|
-
});
|
|
1706
|
-
}
|
|
1707
|
-
const enabled = value === undefined ? separate ?? true : parseReservedBool(name, value);
|
|
1708
|
-
if (name === "dry-run")
|
|
1709
|
-
options.dryRun = enabled;
|
|
1710
|
-
else if (name === "json")
|
|
1711
|
-
options.json = enabled;
|
|
1712
|
-
else if (name === "wait")
|
|
1713
|
-
options.wait = enabled;
|
|
1714
|
-
else if (name === "quiet")
|
|
1715
|
-
options.quiet = enabled;
|
|
1716
|
-
else if (name === "ascending")
|
|
1717
|
-
ascending = enabled;
|
|
1718
|
-
else if (name === "schema")
|
|
1719
|
-
continue;
|
|
1720
|
-
else
|
|
1721
|
-
options.help = options.help || enabled;
|
|
1722
|
-
continue;
|
|
1723
|
-
}
|
|
1724
|
-
if (option.globalKind === "value") {
|
|
1725
|
-
const next = argv[i + 1];
|
|
1726
|
-
value = value ?? next;
|
|
1727
|
-
if (value === undefined || !option.inline && isOptionToken(value)) {
|
|
1728
|
-
throw new CliArgumentError2(`--${name} requires a value`);
|
|
1729
|
-
}
|
|
1730
|
-
if (!option.inline)
|
|
1731
|
-
i++;
|
|
1732
|
-
appendCliOptionValue(frameworkFlags, name, value, { kind: "string" });
|
|
1733
|
-
if (name === "wait-timeout") {
|
|
1734
|
-
const timeout = Number(value);
|
|
1735
|
-
if (!Number.isFinite(timeout) || timeout <= 0) {
|
|
1736
|
-
throw new CliArgumentError2("--wait-timeout must be a positive number");
|
|
2739
|
+
if (option.globalKind !== undefined) {
|
|
2740
|
+
i = consumeFrameworkOptionToken(argv, i, option, fwState, {
|
|
2741
|
+
adjacent,
|
|
2742
|
+
onError: (error) => {
|
|
2743
|
+
throw error;
|
|
1737
2744
|
}
|
|
1738
|
-
|
|
1739
|
-
} else if (VIEW_OPTIONS.has(name)) {
|
|
1740
|
-
viewFlags.set(name, value);
|
|
1741
|
-
} else {
|
|
1742
|
-
options.outputDir = value;
|
|
1743
|
-
}
|
|
2745
|
+
});
|
|
1744
2746
|
continue;
|
|
1745
2747
|
}
|
|
1746
|
-
if (value === undefined && name.startsWith("no-") && fieldFor(name.slice(3))?.kind === "boolean") {
|
|
2748
|
+
if (value === undefined && name.startsWith("no-") && !fieldFor(name) && fieldFor(name.slice(3))?.kind === "boolean") {
|
|
1747
2749
|
pushFlag(name.slice(3), "false");
|
|
1748
2750
|
literalBooleanFlags.add(name.slice(3));
|
|
1749
2751
|
continue;
|
|
@@ -1759,14 +2761,14 @@ function readCliTokens(argv, fields, fieldFor, config) {
|
|
|
1759
2761
|
}
|
|
1760
2762
|
if (value === undefined) {
|
|
1761
2763
|
if (info?.kind === "boolean") {
|
|
1762
|
-
const separate = separateBoolValue(argv[i + 1]);
|
|
2764
|
+
const separate = adjacent(i + 1) ? separateBoolValue(argv[i + 1]) : undefined;
|
|
1763
2765
|
if (separate !== undefined)
|
|
1764
2766
|
i++;
|
|
1765
2767
|
pushFlag(name, String(separate ?? true));
|
|
1766
2768
|
literalBooleanFlags.add(name);
|
|
1767
2769
|
continue;
|
|
1768
2770
|
}
|
|
1769
|
-
const next = argv[i + 1];
|
|
2771
|
+
const next = adjacent(i + 1) ? argv[i + 1] : undefined;
|
|
1770
2772
|
if (next !== undefined && !isOptionToken(next)) {
|
|
1771
2773
|
value = next;
|
|
1772
2774
|
i++;
|
|
@@ -1775,99 +2777,32 @@ function readCliTokens(argv, fields, fieldFor, config) {
|
|
|
1775
2777
|
}
|
|
1776
2778
|
}
|
|
1777
2779
|
pushFlag(name, value, json);
|
|
2780
|
+
if (option.inline && !json && info?.kind === "boolean" && info.pureBoolean === true) {
|
|
2781
|
+
parseReservedBool(name, value);
|
|
2782
|
+
}
|
|
1778
2783
|
}
|
|
2784
|
+
const { fw } = fwState;
|
|
2785
|
+
const options = {
|
|
2786
|
+
json: fw.json,
|
|
2787
|
+
wait: fw.wait,
|
|
2788
|
+
quiet: fw.quiet,
|
|
2789
|
+
dryRun: fw.dryRun,
|
|
2790
|
+
help: fw.help,
|
|
2791
|
+
schema: fw.schema,
|
|
2792
|
+
...fw.waitTimeout !== undefined && { waitTimeout: fw.waitTimeout },
|
|
2793
|
+
...fw.outputDir !== undefined && { outputDir: fw.outputDir }
|
|
2794
|
+
};
|
|
1779
2795
|
return {
|
|
1780
2796
|
options,
|
|
1781
2797
|
flags,
|
|
1782
2798
|
jsonFields,
|
|
1783
2799
|
literalBooleanFlags,
|
|
1784
|
-
viewFlags,
|
|
1785
|
-
ascending,
|
|
2800
|
+
viewFlags: fwState.viewFlags,
|
|
2801
|
+
ascending: fwState.ascending,
|
|
1786
2802
|
positionals
|
|
1787
2803
|
};
|
|
1788
2804
|
}
|
|
1789
2805
|
|
|
1790
|
-
// src/tools/cli/args-view.ts
|
|
1791
|
-
function resolveCliView(flags, ascending) {
|
|
1792
|
-
if (flags.size === 0) {
|
|
1793
|
-
if (ascending) {
|
|
1794
|
-
throw new CliArgumentError2("--ascending orders a record view; pass --sort with it");
|
|
1795
|
-
}
|
|
1796
|
-
return;
|
|
1797
|
-
}
|
|
1798
|
-
const countBy = flags.get("count-by");
|
|
1799
|
-
const sum = flags.get("sum");
|
|
1800
|
-
const table = flags.get("table");
|
|
1801
|
-
const by = flags.get("by");
|
|
1802
|
-
const rawTop = flags.get("top");
|
|
1803
|
-
const named = [
|
|
1804
|
-
["--count-by", countBy],
|
|
1805
|
-
["--sum", sum]
|
|
1806
|
-
].filter(([, value]) => value !== undefined);
|
|
1807
|
-
if (named.length > 1) {
|
|
1808
|
-
throw new CliArgumentError2(`${named.map(([flag]) => flag).join(" and ")} ask for different shapes — pass one`);
|
|
1809
|
-
}
|
|
1810
|
-
let top;
|
|
1811
|
-
if (rawTop !== undefined) {
|
|
1812
|
-
top = Number(rawTop);
|
|
1813
|
-
if (!Number.isInteger(top) || top <= 0) {
|
|
1814
|
-
throw new CliArgumentError2("--top must be a positive whole number");
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
const sort = flags.get("sort");
|
|
1818
|
-
if (table !== undefined || sort !== undefined) {
|
|
1819
|
-
if (countBy !== undefined || sum !== undefined) {
|
|
1820
|
-
throw new CliArgumentError2(`${table !== undefined ? "--table" : "--sort"} lists records; --count-by and --sum aggregate them — pass one`);
|
|
1821
|
-
}
|
|
1822
|
-
if (by !== undefined) {
|
|
1823
|
-
throw new CliArgumentError2("--by groups a view; a record view orders with --sort");
|
|
1824
|
-
}
|
|
1825
|
-
if (top !== undefined && sort === undefined) {
|
|
1826
|
-
throw new CliArgumentError2("--top needs --sort here: unordered records have no n largest");
|
|
1827
|
-
}
|
|
1828
|
-
let fields;
|
|
1829
|
-
if (table !== undefined) {
|
|
1830
|
-
fields = table.split(",").map((field) => field.trim()).filter(Boolean);
|
|
1831
|
-
if (fields.length === 0)
|
|
1832
|
-
throw new CliArgumentError2("--table needs at least one field");
|
|
1833
|
-
}
|
|
1834
|
-
return {
|
|
1835
|
-
kind: "records",
|
|
1836
|
-
...sort !== undefined && { sort },
|
|
1837
|
-
...ascending && { ascending },
|
|
1838
|
-
...top !== undefined && { top },
|
|
1839
|
-
...fields && { table: fields }
|
|
1840
|
-
};
|
|
1841
|
-
}
|
|
1842
|
-
if (ascending) {
|
|
1843
|
-
throw new CliArgumentError2("--ascending orders a record view; pass --sort with it");
|
|
1844
|
-
}
|
|
1845
|
-
if (sum !== undefined) {
|
|
1846
|
-
if (top !== undefined && by === undefined) {
|
|
1847
|
-
throw new CliArgumentError2("--top needs --by: a single sum has nothing to rank");
|
|
1848
|
-
}
|
|
1849
|
-
return {
|
|
1850
|
-
kind: "sum",
|
|
1851
|
-
field: sum,
|
|
1852
|
-
...by !== undefined && { by },
|
|
1853
|
-
...top !== undefined && { top }
|
|
1854
|
-
};
|
|
1855
|
-
}
|
|
1856
|
-
if (countBy !== undefined) {
|
|
1857
|
-
if (by !== undefined) {
|
|
1858
|
-
throw new CliArgumentError2("--count-by already names the grouping field; drop --by");
|
|
1859
|
-
}
|
|
1860
|
-
return { kind: "count", field: countBy, ...top !== undefined && { top } };
|
|
1861
|
-
}
|
|
1862
|
-
if (by !== undefined) {
|
|
1863
|
-
if (top === undefined) {
|
|
1864
|
-
throw new CliArgumentError2("--by groups a view; pass --count-by, --sum or --top with it");
|
|
1865
|
-
}
|
|
1866
|
-
return { kind: "count", field: by, top };
|
|
1867
|
-
}
|
|
1868
|
-
throw new CliArgumentError2("--top needs --sort, --by, --count-by or --sum to rank");
|
|
1869
|
-
}
|
|
1870
|
-
|
|
1871
2806
|
// src/tools/cli/args.ts
|
|
1872
2807
|
function buildToolArgs(tokens, fields, fieldFor, declaredPositionals, allowUnknown) {
|
|
1873
2808
|
const { flags, jsonFields, literalBooleanFlags, positionals } = tokens;
|
|
@@ -1935,7 +2870,35 @@ function buildToolArgs(tokens, fields, fieldFor, declaredPositionals, allowUnkno
|
|
|
1935
2870
|
}
|
|
1936
2871
|
return toolArgs;
|
|
1937
2872
|
}
|
|
2873
|
+
function cliRunOptions(framework) {
|
|
2874
|
+
return {
|
|
2875
|
+
json: framework.json,
|
|
2876
|
+
wait: framework.wait,
|
|
2877
|
+
quiet: framework.quiet,
|
|
2878
|
+
dryRun: framework.dryRun,
|
|
2879
|
+
help: framework.help,
|
|
2880
|
+
schema: framework.schema,
|
|
2881
|
+
...framework.waitTimeout !== undefined && { waitTimeout: framework.waitTimeout },
|
|
2882
|
+
...framework.outputDir !== undefined && { outputDir: framework.outputDir },
|
|
2883
|
+
...framework.view !== undefined && { view: framework.view }
|
|
2884
|
+
};
|
|
2885
|
+
}
|
|
1938
2886
|
function parseCliArgs2(argv, schema, config = {}) {
|
|
2887
|
+
try {
|
|
2888
|
+
return parseCommandArgv(argv, schema, config);
|
|
2889
|
+
} catch (error) {
|
|
2890
|
+
if (!(error instanceof CliArgumentError2))
|
|
2891
|
+
throw error;
|
|
2892
|
+
const scan = scanCliArgv(argv, {
|
|
2893
|
+
afterCommand: true,
|
|
2894
|
+
separatedBefore: config.separatedBefore
|
|
2895
|
+
});
|
|
2896
|
+
if (!answersBeforeArguments(scan))
|
|
2897
|
+
throw error;
|
|
2898
|
+
return { toolArgs: {}, options: cliRunOptions(scan.framework) };
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
function parseCommandArgv(argv, schema, config) {
|
|
1939
2902
|
const fields = describeSchemaFields(schema);
|
|
1940
2903
|
for (const name of config.knownFields ?? []) {
|
|
1941
2904
|
if (!fields.has(name))
|
|
@@ -1952,80 +2915,36 @@ function parseCliArgs2(argv, schema, config = {}) {
|
|
|
1952
2915
|
options
|
|
1953
2916
|
};
|
|
1954
2917
|
}
|
|
1955
|
-
function refuseGlobalOption(issue) {
|
|
1956
|
-
const field = issue?.path[0];
|
|
1957
|
-
const where = typeof field === "string" ? `--${field}` : "application option";
|
|
1958
|
-
throw new CliArgumentError2(`${where}: ${issue?.message ?? "invalid value"}`);
|
|
1959
|
-
}
|
|
1960
2918
|
function extractCliGlobalOptions2(argv, schema) {
|
|
1961
2919
|
if (schema === undefined)
|
|
1962
2920
|
return { argv: [...argv], globals: {} };
|
|
1963
|
-
const
|
|
1964
|
-
const
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
const option = ended ? undefined : classifyLongOptionToken(token);
|
|
1975
|
-
const field = option ? cliFieldOption(option, fields) : undefined;
|
|
1976
|
-
const info = field && option?.globalKind === undefined ? fields.get(field.name) : undefined;
|
|
1977
|
-
if (!option || !field || !info) {
|
|
1978
|
-
rest.push(token);
|
|
1979
|
-
continue;
|
|
1980
|
-
}
|
|
1981
|
-
let { value } = option;
|
|
1982
|
-
if (value === undefined && info.kind === "boolean") {
|
|
1983
|
-
const separate = separateBoolValue(argv[i + 1]);
|
|
1984
|
-
if (separate !== undefined)
|
|
1985
|
-
i++;
|
|
1986
|
-
value = String(separate ?? true);
|
|
1987
|
-
} else if (value === undefined) {
|
|
1988
|
-
const next = argv[i + 1];
|
|
1989
|
-
if (next !== undefined && !isOptionToken(next)) {
|
|
1990
|
-
value = next;
|
|
1991
|
-
i++;
|
|
1992
|
-
} else {
|
|
1993
|
-
throw new CliArgumentError2(`--${option.name} requires a value`);
|
|
2921
|
+
const result = scanCliArgv(argv, { appGlobals: schema });
|
|
2922
|
+
const early = answersBeforeArguments(result);
|
|
2923
|
+
if (!early && result.appGlobalError !== undefined)
|
|
2924
|
+
throw result.appGlobalError;
|
|
2925
|
+
const refusal = early ? undefined : result.liftedBoundaryError;
|
|
2926
|
+
if (refusal === undefined) {
|
|
2927
|
+
return {
|
|
2928
|
+
argv: result.withoutGlobals,
|
|
2929
|
+
globals: result.globals,
|
|
2930
|
+
...result.separatedBeforeGlobals.size > 0 && {
|
|
2931
|
+
separatedBefore: result.separatedBeforeGlobals
|
|
1994
2932
|
}
|
|
1995
|
-
}
|
|
1996
|
-
appendCliFieldValue(raw, jsonFields, field.name, value, info, field.json);
|
|
1997
|
-
preserveCliBooleanBoundary(rest, argv[i + 1]);
|
|
1998
|
-
}
|
|
1999
|
-
const args = {};
|
|
2000
|
-
for (const [name, values] of raw) {
|
|
2001
|
-
args[name] = coerceCliFieldValue(fields.get(name), values, `--${name}`, jsonFields.has(name));
|
|
2002
|
-
}
|
|
2003
|
-
let coerced;
|
|
2004
|
-
try {
|
|
2005
|
-
coerced = coerceJsonArgs2(args, schema);
|
|
2006
|
-
} catch (error) {
|
|
2007
|
-
if (error instanceof z3.ZodError)
|
|
2008
|
-
refuseGlobalOption(error.issues[0]);
|
|
2009
|
-
throw error;
|
|
2933
|
+
};
|
|
2010
2934
|
}
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2935
|
+
return {
|
|
2936
|
+
globals: result.globals,
|
|
2937
|
+
get argv() {
|
|
2938
|
+
throw refusal;
|
|
2939
|
+
}
|
|
2940
|
+
};
|
|
2015
2941
|
}
|
|
2016
2942
|
|
|
2017
2943
|
// src/tools/cli/prepare.ts
|
|
2018
2944
|
function looseCoerceValue(value) {
|
|
2019
2945
|
if (Array.isArray(value))
|
|
2020
|
-
return value.map(looseCoerceValue);
|
|
2021
|
-
|
|
2022
|
-
return value;
|
|
2023
|
-
if (value === "true")
|
|
2024
|
-
return true;
|
|
2025
|
-
if (value === "false")
|
|
2026
|
-
return false;
|
|
2027
|
-
const n = Number(value);
|
|
2028
|
-
return value.trim() !== "" && !Number.isNaN(n) ? n : value;
|
|
2946
|
+
return value.map(looseCoerceValue);
|
|
2947
|
+
return typeof value === "string" ? looseCoerce(value) : value;
|
|
2029
2948
|
}
|
|
2030
2949
|
function passthroughBase(value) {
|
|
2031
2950
|
if (isRecord(value))
|
|
@@ -2053,21 +2972,24 @@ function collectPassthrough(toolArgs, field, knownKeys) {
|
|
|
2053
2972
|
const base = passthroughBase(toolArgs[field]);
|
|
2054
2973
|
toolArgs[field] = base ? { ...base, ...bag } : bag;
|
|
2055
2974
|
}
|
|
2056
|
-
async function prepareInvocation(command,
|
|
2975
|
+
async function prepareInvocation(command, commandTokens, separatedBefore, framework, descriptor, config, readStdin) {
|
|
2976
|
+
const passthroughField = cliPassthroughField(config, command);
|
|
2057
2977
|
let parsed;
|
|
2058
2978
|
try {
|
|
2059
|
-
parsed = parseCliArgs2(
|
|
2060
|
-
allowUnknown:
|
|
2979
|
+
parsed = parseCliArgs2(commandTokens, descriptor.argumentSchema, {
|
|
2980
|
+
allowUnknown: passthroughField !== undefined,
|
|
2061
2981
|
knownFields: jsonSchemaFields(descriptor.presentationSchema).map((field) => field.name),
|
|
2062
|
-
|
|
2063
|
-
positionals: descriptor.positionals
|
|
2982
|
+
aliases: new Map([...descriptor.aliases].map(([field, alias]) => [alias, field])),
|
|
2983
|
+
positionals: descriptor.positionals,
|
|
2984
|
+
separatedBefore
|
|
2064
2985
|
});
|
|
2065
2986
|
} catch (error) {
|
|
2066
2987
|
if (!(error instanceof CliArgumentError2))
|
|
2067
2988
|
throw error;
|
|
2068
2989
|
return { ok: false, message: error.message };
|
|
2069
2990
|
}
|
|
2070
|
-
const { toolArgs
|
|
2991
|
+
const { toolArgs } = parsed;
|
|
2992
|
+
const options = cliRunOptions(framework);
|
|
2071
2993
|
const firstUnset = jsonSchemaFields(descriptor.presentationSchema).find((field) => field.required && !(field.name in toolArgs) && field.schema.type !== "boolean");
|
|
2072
2994
|
if (firstUnset) {
|
|
2073
2995
|
const piped = await readStdin();
|
|
@@ -2075,12 +2997,17 @@ async function prepareInvocation(command, commandArgv, descriptor, config, readS
|
|
|
2075
2997
|
if (descriptor.positionals === undefined) {
|
|
2076
2998
|
toolArgs[firstUnset.name] = piped;
|
|
2077
2999
|
} else {
|
|
2078
|
-
const
|
|
2079
|
-
|
|
3000
|
+
const fieldInfo = describeSchemaFields(descriptor.argumentSchema).get(firstUnset.name);
|
|
3001
|
+
try {
|
|
3002
|
+
toolArgs[firstUnset.name] = coerceField(fieldInfo, [piped], `--${firstUnset.name}`);
|
|
3003
|
+
} catch (error) {
|
|
3004
|
+
if (!(error instanceof CliArgumentError2))
|
|
3005
|
+
throw error;
|
|
3006
|
+
return { ok: false, message: error.message };
|
|
3007
|
+
}
|
|
2080
3008
|
}
|
|
2081
3009
|
}
|
|
2082
3010
|
}
|
|
2083
|
-
const passthroughField = config.passthrough?.[command];
|
|
2084
3011
|
if (passthroughField) {
|
|
2085
3012
|
collectPassthrough(toolArgs, passthroughField, objectShapeKeys(descriptor.argumentSchema));
|
|
2086
3013
|
}
|
|
@@ -2088,18 +3015,10 @@ async function prepareInvocation(command, commandArgv, descriptor, config, readS
|
|
|
2088
3015
|
}
|
|
2089
3016
|
|
|
2090
3017
|
// src/tools/cli/session.ts
|
|
2091
|
-
function nativeDescriptor(definition) {
|
|
2092
|
-
return {
|
|
2093
|
-
description: definition.description,
|
|
2094
|
-
argumentSchema: definition.input,
|
|
2095
|
-
presentationSchema: cliCommandPresentationSchema(definition),
|
|
2096
|
-
outputSchema: definition.output
|
|
2097
|
-
};
|
|
2098
|
-
}
|
|
2099
3018
|
function createCliSession(config, io) {
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
3019
|
+
const lifecycle = resolveOptionalCliToolAccess("createCliSession", config);
|
|
3020
|
+
assertNoLegacyCliPolicyKeys(config);
|
|
3021
|
+
assertCliAuthConfig(config);
|
|
2103
3022
|
assertPositiveSafeInteger("createCli maxDownloadBytes", config.maxDownloadBytes);
|
|
2104
3023
|
const applicationOptions = config.globalOptions ? jsonSchemaFields(buildToolPresentationSchema({
|
|
2105
3024
|
inputSchema: config.globalOptions,
|
|
@@ -2115,15 +3034,22 @@ function createCliSession(config, io) {
|
|
|
2115
3034
|
const nativeHelp = new Map;
|
|
2116
3035
|
assertStaticCliCommandNames(typeof config.services === "function" ? [] : config.services ?? [], typeof config.runtimeTools === "function" ? [] : config.runtimeTools ?? []);
|
|
2117
3036
|
for (const definition of config.commands ?? []) {
|
|
2118
|
-
|
|
2119
|
-
|
|
3037
|
+
if (cliResultPolicy(config, definition.name) !== undefined) {
|
|
3038
|
+
throw new Error(`[stitchkit] CLI result policy "${definition.name}" targets a command that is not managed; a native command declares present and exitCode on defineCliCommand`);
|
|
3039
|
+
}
|
|
3040
|
+
const descriptor = applyCliPresentationPolicy(definition.name, nativeCliDescriptor(definition), config);
|
|
3041
|
+
const issue = commandShapeIssue(definition.name, descriptor, nativeCommands.has(definition.name), cliPassthroughField(config, definition.name), applicationGlobalNames);
|
|
2120
3042
|
if (issue !== undefined)
|
|
2121
3043
|
throw new Error(issue);
|
|
2122
3044
|
nativeCommands.set(definition.name, definition);
|
|
2123
3045
|
nativeHelp.set(definition.name, descriptor);
|
|
2124
3046
|
}
|
|
3047
|
+
if (config.services === undefined && config.runtimeTools === undefined) {
|
|
3048
|
+
assertCliPoliciesResolved(nativeHelp, config);
|
|
3049
|
+
}
|
|
2125
3050
|
return {
|
|
2126
3051
|
config,
|
|
3052
|
+
lifecycle,
|
|
2127
3053
|
io,
|
|
2128
3054
|
applicationOptions,
|
|
2129
3055
|
applicationGlobalNames,
|
|
@@ -2135,12 +3061,12 @@ function createCliSession(config, io) {
|
|
|
2135
3061
|
function resolveCliRoute(session, argv) {
|
|
2136
3062
|
const { config } = session;
|
|
2137
3063
|
const { stdout, stderr, exit } = session.io;
|
|
2138
|
-
let
|
|
2139
|
-
let routableArgv;
|
|
3064
|
+
let scan;
|
|
2140
3065
|
try {
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
3066
|
+
scan = scanCliInvocation2(argv, {
|
|
3067
|
+
appGlobals: config.globalOptions,
|
|
3068
|
+
defaultCommand: config.defaultCommand
|
|
3069
|
+
});
|
|
2144
3070
|
} catch (error) {
|
|
2145
3071
|
if (!(error instanceof CliArgumentError2))
|
|
2146
3072
|
throw error;
|
|
@@ -2149,36 +3075,24 @@ function resolveCliRoute(session, argv) {
|
|
|
2149
3075
|
exit(2);
|
|
2150
3076
|
return;
|
|
2151
3077
|
}
|
|
2152
|
-
|
|
2153
|
-
const route = routeCliArgv2(routableArgv, config.defaultCommand);
|
|
2154
|
-
if (route.error) {
|
|
2155
|
-
stderr(`${route.error}
|
|
2156
|
-
`);
|
|
2157
|
-
exit(2);
|
|
2158
|
-
return;
|
|
2159
|
-
}
|
|
2160
|
-
const { command, commandArgv } = route;
|
|
2161
|
-
if (config.defaultCommand === undefined && session.hasManagedFactory && command !== undefined && command !== routableArgv[0] && session.nativeCommands.has(command)) {
|
|
2162
|
-
stderr(`Managed command names are unknown before native dispatch. Put "${config.name} ${command}" first and keep options with their values. ` + `If moving a bare boolean flag next to positional true or false, spell the flag explicitly (for example, --dry-run=true).
|
|
2163
|
-
`);
|
|
2164
|
-
exit(2);
|
|
2165
|
-
return;
|
|
2166
|
-
}
|
|
2167
|
-
if (route.version || isCliVersionToken(command)) {
|
|
3078
|
+
if (scan.version) {
|
|
2168
3079
|
stdout(`${config.name} ${config.version}
|
|
2169
3080
|
`);
|
|
2170
3081
|
exit(0);
|
|
2171
3082
|
return;
|
|
2172
3083
|
}
|
|
2173
|
-
const helpRequested =
|
|
2174
|
-
const schemaRequested = !helpRequested &&
|
|
3084
|
+
const helpRequested = scan.framework.help;
|
|
3085
|
+
const schemaRequested = !helpRequested && scan.framework.schema;
|
|
2175
3086
|
return {
|
|
2176
|
-
globals,
|
|
2177
|
-
typedGlobals,
|
|
2178
|
-
|
|
2179
|
-
command,
|
|
2180
|
-
|
|
2181
|
-
|
|
3087
|
+
globals: scan.globals,
|
|
3088
|
+
typedGlobals: scan.globals,
|
|
3089
|
+
framework: scan.framework,
|
|
3090
|
+
command: scan.command,
|
|
3091
|
+
commandTokens: scan.commandTokens,
|
|
3092
|
+
separatedBefore: scan.separatedBefore,
|
|
3093
|
+
topLevelHelp: scan.topLevelHelp,
|
|
3094
|
+
...scan.helpFilter !== undefined && { helpFilter: scan.helpFilter },
|
|
3095
|
+
quiet: scan.framework.quiet,
|
|
2182
3096
|
helpRequested,
|
|
2183
3097
|
schemaRequested
|
|
2184
3098
|
};
|
|
@@ -2222,17 +3136,10 @@ async function runStreamCommand(session, route, managed, stream, { toolArgs, opt
|
|
|
2222
3136
|
cancel();
|
|
2223
3137
|
else
|
|
2224
3138
|
config.signal?.addEventListener("abort", cancel, { once: true });
|
|
2225
|
-
const runTool =
|
|
2226
|
-
source: "cli",
|
|
2227
|
-
toolSurface: true,
|
|
2228
|
-
context: { ...config.context?.(managed.auth, route.typedGlobals), signal: abort.signal },
|
|
2229
|
-
hooks: config.hooks,
|
|
2230
|
-
lifecycle: config.lifecycle,
|
|
2231
|
-
coerceJsonArgs: config.coerceJsonArgs
|
|
2232
|
-
});
|
|
3139
|
+
const runTool = createCliToolRunner(config, session.lifecycle, managed.auth, route.typedGlobals);
|
|
2233
3140
|
let opened;
|
|
2234
3141
|
try {
|
|
2235
|
-
opened = await runTool(stream.tool, toolArgs);
|
|
3142
|
+
opened = await runTool(stream.tool, toolArgs, { signal: abort.signal });
|
|
2236
3143
|
} catch (error) {
|
|
2237
3144
|
opened = toolResultFromError(error);
|
|
2238
3145
|
}
|
|
@@ -2255,7 +3162,7 @@ async function runStreamCommand(session, route, managed, stream, { toolArgs, opt
|
|
|
2255
3162
|
}
|
|
2256
3163
|
function streamLine(command, item, policy, options) {
|
|
2257
3164
|
if (policy?.present === undefined)
|
|
2258
|
-
return `${
|
|
3165
|
+
return `${stringifyJsonSafe(item)}
|
|
2259
3166
|
`;
|
|
2260
3167
|
let line;
|
|
2261
3168
|
try {
|
|
@@ -2291,7 +3198,7 @@ async function printStreamItems(source, { descriptor }, abort, wasCancelled, wri
|
|
|
2291
3198
|
if (lifetimeExpired) {
|
|
2292
3199
|
return toolResultFromError(contractStreamLifetimeExceeded());
|
|
2293
3200
|
}
|
|
2294
|
-
return toolResultFromError(error);
|
|
3201
|
+
return projectCliUnixFailure(toolResultFromError(error));
|
|
2295
3202
|
} finally {
|
|
2296
3203
|
if (lifetime !== undefined)
|
|
2297
3204
|
clearTimeout(lifetime);
|
|
@@ -2302,198 +3209,6 @@ async function printStreamItems(source, { descriptor }, abort, wasCancelled, wri
|
|
|
2302
3209
|
}
|
|
2303
3210
|
}
|
|
2304
3211
|
|
|
2305
|
-
// src/tools/cli/unavailable.ts
|
|
2306
|
-
function unavailableCommand(reason) {
|
|
2307
|
-
return toolResultFromError(new AppError2("CLI_COMMAND_UNAVAILABLE", {
|
|
2308
|
-
message: reason,
|
|
2309
|
-
status: STITCH_ERROR_STATUS2.CLI_COMMAND_UNAVAILABLE,
|
|
2310
|
-
retryable: false
|
|
2311
|
-
}));
|
|
2312
|
-
}
|
|
2313
|
-
|
|
2314
|
-
// src/tools/cli/view.ts
|
|
2315
|
-
var ABSENT = "(absent)";
|
|
2316
|
-
function selectRecords(data) {
|
|
2317
|
-
if (Array.isArray(data))
|
|
2318
|
-
return data;
|
|
2319
|
-
if (isRecord(data)) {
|
|
2320
|
-
const arrays = Object.entries(data).filter(([, value]) => Array.isArray(value));
|
|
2321
|
-
const only = arrays[0];
|
|
2322
|
-
if (arrays.length === 1 && only && Array.isArray(only[1]))
|
|
2323
|
-
return only[1];
|
|
2324
|
-
if (arrays.length > 1) {
|
|
2325
|
-
throw new CliArgumentError2(`an aggregate needs one collection, but the result carries several: ${arrays.map(([key]) => key).join(", ")} — name the shape you want with jq instead`);
|
|
2326
|
-
}
|
|
2327
|
-
}
|
|
2328
|
-
throw new CliArgumentError2("an aggregate needs a collection; this result is not one");
|
|
2329
|
-
}
|
|
2330
|
-
function isAbsent(value) {
|
|
2331
|
-
return value === undefined || value === null;
|
|
2332
|
-
}
|
|
2333
|
-
function readField(record, path) {
|
|
2334
|
-
let current = record;
|
|
2335
|
-
for (const segment of path) {
|
|
2336
|
-
if (!isRecord(current) || !Object.hasOwn(current, segment))
|
|
2337
|
-
return;
|
|
2338
|
-
current = current[segment];
|
|
2339
|
-
}
|
|
2340
|
-
return current;
|
|
2341
|
-
}
|
|
2342
|
-
function fieldPath(field) {
|
|
2343
|
-
const path = field.split(".");
|
|
2344
|
-
if (path.some((segment) => segment.length === 0 || isUnsafeKey(segment))) {
|
|
2345
|
-
throw new CliArgumentError2(`"${field}" is not a readable field path`);
|
|
2346
|
-
}
|
|
2347
|
-
return path;
|
|
2348
|
-
}
|
|
2349
|
-
function availableFields(records) {
|
|
2350
|
-
const keys = new Set;
|
|
2351
|
-
for (const record of records) {
|
|
2352
|
-
if (isRecord(record))
|
|
2353
|
-
for (const key of Object.keys(record))
|
|
2354
|
-
keys.add(key);
|
|
2355
|
-
}
|
|
2356
|
-
return [...keys].sort();
|
|
2357
|
-
}
|
|
2358
|
-
function assertFieldPresent(records, field) {
|
|
2359
|
-
const path = fieldPath(field);
|
|
2360
|
-
const present = records.some((record) => readField(record, path) !== undefined);
|
|
2361
|
-
if (records.length > 0 && !present) {
|
|
2362
|
-
const available = availableFields(records);
|
|
2363
|
-
throw new CliArgumentError2(`no record carries the field "${field}"${available.length > 0 ? ` — available: ${available.join(", ")}` : ""}`);
|
|
2364
|
-
}
|
|
2365
|
-
return path;
|
|
2366
|
-
}
|
|
2367
|
-
function groupKey(value) {
|
|
2368
|
-
if (value === undefined)
|
|
2369
|
-
return ABSENT;
|
|
2370
|
-
if (value === null)
|
|
2371
|
-
return "null";
|
|
2372
|
-
if (value === "null" || value === ABSENT)
|
|
2373
|
-
return JSON.stringify(value);
|
|
2374
|
-
if (typeof value === "object")
|
|
2375
|
-
return JSON.stringify(value);
|
|
2376
|
-
return String(value);
|
|
2377
|
-
}
|
|
2378
|
-
function ordered(totals, top) {
|
|
2379
|
-
const entries = [...totals].sort(([leftKey, left], [rightKey, right]) => right === left ? leftKey.localeCompare(rightKey) : right - left);
|
|
2380
|
-
const sliced = top === undefined ? entries : entries.slice(0, top);
|
|
2381
|
-
return {
|
|
2382
|
-
kind: "json",
|
|
2383
|
-
data: Object.fromEntries(sliced),
|
|
2384
|
-
order: sliced.map(([key]) => key)
|
|
2385
|
-
};
|
|
2386
|
-
}
|
|
2387
|
-
function stringifyGroups(data, order, compact) {
|
|
2388
|
-
if (!isRecord(data) || order.length === 0)
|
|
2389
|
-
return JSON.stringify(data);
|
|
2390
|
-
const lines = order.map((key) => `${JSON.stringify(key)}:${compact ? "" : " "}${JSON.stringify(data[key])}`);
|
|
2391
|
-
return compact ? `{${lines.join(",")}}` : `{
|
|
2392
|
-
${lines.join(`,
|
|
2393
|
-
`)}
|
|
2394
|
-
}`;
|
|
2395
|
-
}
|
|
2396
|
-
function numericValue(value, field) {
|
|
2397
|
-
if (isAbsent(value))
|
|
2398
|
-
return;
|
|
2399
|
-
if (typeof value === "number" && Number.isFinite(value))
|
|
2400
|
-
return value;
|
|
2401
|
-
if (typeof value === "bigint")
|
|
2402
|
-
return Number(value);
|
|
2403
|
-
throw new CliArgumentError2(`--sum ${field}: "${groupKey(value)}" is not a number`);
|
|
2404
|
-
}
|
|
2405
|
-
function renderTable(records, columns) {
|
|
2406
|
-
const fields = columns.map(({ field }) => field);
|
|
2407
|
-
const cell = (value) => {
|
|
2408
|
-
if (value === undefined)
|
|
2409
|
-
return "";
|
|
2410
|
-
if (value === null)
|
|
2411
|
-
return "null";
|
|
2412
|
-
if (typeof value === "object")
|
|
2413
|
-
return JSON.stringify(value);
|
|
2414
|
-
return String(value);
|
|
2415
|
-
};
|
|
2416
|
-
const rows = records.map((record) => columns.map(({ path }) => cell(readField(record, path))));
|
|
2417
|
-
const widths = fields.map((field, column) => Math.max(field.length, ...rows.map((row) => row[column]?.length ?? 0)));
|
|
2418
|
-
const line = (cells) => cells.map((value, column) => value.padEnd(widths[column] ?? value.length)).join(" ").trimEnd();
|
|
2419
|
-
return `${[line(fields), line(widths.map((width) => "-".repeat(width))), ...rows.map(line)].join(`
|
|
2420
|
-
`)}
|
|
2421
|
-
`;
|
|
2422
|
-
}
|
|
2423
|
-
function compareFieldValues(left, right) {
|
|
2424
|
-
if (isAbsent(left))
|
|
2425
|
-
return isAbsent(right) ? 0 : 1;
|
|
2426
|
-
if (isAbsent(right))
|
|
2427
|
-
return -1;
|
|
2428
|
-
if (typeof left === "number" && typeof right === "number")
|
|
2429
|
-
return left - right;
|
|
2430
|
-
if (typeof left === "bigint" || typeof right === "bigint") {
|
|
2431
|
-
return Number(left) - Number(right);
|
|
2432
|
-
}
|
|
2433
|
-
return groupKey(left).localeCompare(groupKey(right));
|
|
2434
|
-
}
|
|
2435
|
-
function renderRecords(records, view) {
|
|
2436
|
-
let selected = [...records];
|
|
2437
|
-
if (view.sort !== undefined) {
|
|
2438
|
-
const path = assertFieldPresent(records, view.sort);
|
|
2439
|
-
const direction = view.ascending ? 1 : -1;
|
|
2440
|
-
selected.sort((left, right) => {
|
|
2441
|
-
const leftValue = readField(left, path);
|
|
2442
|
-
const rightValue = readField(right, path);
|
|
2443
|
-
const order = compareFieldValues(leftValue, rightValue);
|
|
2444
|
-
return isAbsent(leftValue) || isAbsent(rightValue) ? order : order * direction;
|
|
2445
|
-
});
|
|
2446
|
-
}
|
|
2447
|
-
const columns = view.table?.map((field) => ({
|
|
2448
|
-
field,
|
|
2449
|
-
path: assertFieldPresent(records, field)
|
|
2450
|
-
}));
|
|
2451
|
-
if (view.top !== undefined)
|
|
2452
|
-
selected = selected.slice(0, view.top);
|
|
2453
|
-
return columns ? { kind: "text", text: renderTable(selected, columns) } : { kind: "json", data: selected };
|
|
2454
|
-
}
|
|
2455
|
-
function refuseEnvelopeFields(data, view) {
|
|
2456
|
-
if (!isRecord(data))
|
|
2457
|
-
return;
|
|
2458
|
-
const fields = view.kind === "records" ? [...view.sort === undefined ? [] : [view.sort], ...view.table ?? []] : [view.field, ...view.kind === "sum" && view.by !== undefined ? [view.by] : []];
|
|
2459
|
-
for (const field of fields) {
|
|
2460
|
-
const first = field.split(".")[0] ?? "";
|
|
2461
|
-
if (Object.hasOwn(data, first) && !Array.isArray(data[first])) {
|
|
2462
|
-
throw new CliArgumentError2(`"${field}" belongs to the result object, not to its empty collection`);
|
|
2463
|
-
}
|
|
2464
|
-
}
|
|
2465
|
-
}
|
|
2466
|
-
function renderCliView2(data, view) {
|
|
2467
|
-
const records = selectRecords(data);
|
|
2468
|
-
if (records.length === 0)
|
|
2469
|
-
refuseEnvelopeFields(data, view);
|
|
2470
|
-
if (view.kind === "records")
|
|
2471
|
-
return renderRecords(records, view);
|
|
2472
|
-
if (view.kind === "count") {
|
|
2473
|
-
const path = assertFieldPresent(records, view.field);
|
|
2474
|
-
const totals = new Map;
|
|
2475
|
-
for (const record of records) {
|
|
2476
|
-
const key = groupKey(readField(record, path));
|
|
2477
|
-
totals.set(key, (totals.get(key) ?? 0) + 1);
|
|
2478
|
-
}
|
|
2479
|
-
return ordered(totals, view.top);
|
|
2480
|
-
}
|
|
2481
|
-
const path = assertFieldPresent(records, view.field);
|
|
2482
|
-
if (view.by === undefined) {
|
|
2483
|
-
let total = 0;
|
|
2484
|
-
for (const record of records)
|
|
2485
|
-
total += numericValue(readField(record, path), view.field) ?? 0;
|
|
2486
|
-
return { kind: "json", data: total };
|
|
2487
|
-
}
|
|
2488
|
-
const byPath = assertFieldPresent(records, view.by);
|
|
2489
|
-
const totals = new Map;
|
|
2490
|
-
for (const record of records) {
|
|
2491
|
-
const key = groupKey(readField(record, byPath));
|
|
2492
|
-
totals.set(key, (totals.get(key) ?? 0) + (numericValue(readField(record, path), view.field) ?? 0));
|
|
2493
|
-
}
|
|
2494
|
-
return ordered(totals, view.top);
|
|
2495
|
-
}
|
|
2496
|
-
|
|
2497
3212
|
// src/tools/cli/wait.ts
|
|
2498
3213
|
var DEFAULT_TIMEOUT = 600;
|
|
2499
3214
|
function waitFailure(tool, result) {
|
|
@@ -2552,22 +3267,19 @@ async function pollUntilDone2(params) {
|
|
|
2552
3267
|
async function runManagedInvocation(session, route) {
|
|
2553
3268
|
const { config } = session;
|
|
2554
3269
|
const { stdout, stderr, exit } = session.io;
|
|
2555
|
-
const { command, helpRequested, schemaRequested } = route;
|
|
2556
|
-
const topLevelHelp = route.route.topLevelHelp || command === undefined || command === "help" || command === "--help" || command === "-h" || command.startsWith("--help=") && !isReservedBoolWord(command.slice("--help=".length));
|
|
3270
|
+
const { command, topLevelHelp, helpRequested, schemaRequested } = route;
|
|
2557
3271
|
const managed = await buildManagedSurface(session, route.typedGlobals, !topLevelHelp && !helpRequested && !schemaRequested);
|
|
2558
|
-
if (topLevelHelp)
|
|
3272
|
+
if (topLevelHelp || command === undefined)
|
|
2559
3273
|
return respondTopLevelHelp(session, route, managed);
|
|
2560
3274
|
if (!managed.resolved) {
|
|
2561
|
-
return exit(emitResult2(managed.failure, { stdout, stderr }, emitOptionsFor(config,
|
|
3275
|
+
return exit(emitResult2(managed.failure, { stdout, stderr }, emitOptionsFor(config, route.framework.json, command)));
|
|
2562
3276
|
}
|
|
2563
3277
|
return runManagedCommand(session, route, command, managed);
|
|
2564
3278
|
}
|
|
2565
3279
|
function respondTopLevelHelp(session, route, managed) {
|
|
2566
3280
|
const { config, applicationOptions } = session;
|
|
2567
3281
|
const { stdout, stderr, exit } = session.io;
|
|
2568
|
-
const
|
|
2569
|
-
const helpFilter = route.route.helpFilter ?? (command !== undefined ? commandArgv[0] : undefined);
|
|
2570
|
-
const filter = helpFilter !== undefined && !helpFilter.startsWith("-") ? helpFilter : undefined;
|
|
3282
|
+
const filter = route.helpFilter;
|
|
2571
3283
|
if (filter !== undefined && filterCommands(managed.help, filter).size === 0) {
|
|
2572
3284
|
stderr(`no command matches "${filter}" (${[...managed.help.values()].filter((entry) => entry.unavailableReason === undefined).length} available)
|
|
2573
3285
|
` + (managed.resolved ? "" : `Managed commands are unavailable: ${managed.reason}
|
|
@@ -2594,7 +3306,7 @@ async function runManagedCommand(session, route, command, managed) {
|
|
|
2594
3306
|
if (!descriptor) {
|
|
2595
3307
|
stderr(`Unknown command "${command}". Run "${config.name} --help" for the command list.
|
|
2596
3308
|
`);
|
|
2597
|
-
return exit(
|
|
3309
|
+
return exit(cliExitCode2(unknownCliCommand(command), config.exitCodes));
|
|
2598
3310
|
}
|
|
2599
3311
|
if (route.helpRequested) {
|
|
2600
3312
|
stdout(renderCommandHelp(config.name, command, descriptor, applicationOptions));
|
|
@@ -2605,20 +3317,20 @@ async function runManagedCommand(session, route, command, managed) {
|
|
|
2605
3317
|
return exit(0);
|
|
2606
3318
|
}
|
|
2607
3319
|
if (descriptor.unavailableReason !== undefined) {
|
|
2608
|
-
return exit(emitResult2(unavailableCommand(descriptor.unavailableReason), { stdout, stderr }, emitOptionsFor(config,
|
|
3320
|
+
return exit(emitResult2(unavailableCommand(descriptor.unavailableReason), { stdout, stderr }, emitOptionsFor(config, route.framework.json, command)));
|
|
2609
3321
|
}
|
|
2610
3322
|
const stream = managed.streams.get(command);
|
|
2611
3323
|
const tool = managed.tools.get(command);
|
|
2612
3324
|
if (!tool && !stream)
|
|
2613
3325
|
throw new Error("[stitchkit] managed CLI executable invariant failed");
|
|
2614
|
-
const prepared = await prepareInvocation(command, route.
|
|
3326
|
+
const prepared = await prepareInvocation(command, route.commandTokens, route.separatedBefore, route.framework, descriptor, config, readStdin);
|
|
2615
3327
|
if (!prepared.ok) {
|
|
2616
3328
|
stderr(`${prepared.message}
|
|
2617
3329
|
`);
|
|
2618
3330
|
return exit(2);
|
|
2619
3331
|
}
|
|
2620
3332
|
const { toolArgs, options } = prepared;
|
|
2621
|
-
if (options.wait && !config
|
|
3333
|
+
if (options.wait && !cliWaitConfig(config, command)) {
|
|
2622
3334
|
stderr(`--wait is not configured for command "${command}"
|
|
2623
3335
|
`);
|
|
2624
3336
|
return exit(2);
|
|
@@ -2628,10 +3340,6 @@ async function runManagedCommand(session, route, command, managed) {
|
|
|
2628
3340
|
`);
|
|
2629
3341
|
return exit(2);
|
|
2630
3342
|
}
|
|
2631
|
-
if (options.help) {
|
|
2632
|
-
stdout(renderCommandHelp(config.name, command, descriptor, applicationOptions));
|
|
2633
|
-
return exit(0);
|
|
2634
|
-
}
|
|
2635
3343
|
if (options.dryRun) {
|
|
2636
3344
|
stdout(`${JSON.stringify({ command, args: toolArgs }, null, 2)}
|
|
2637
3345
|
`);
|
|
@@ -2641,6 +3349,17 @@ async function runManagedCommand(session, route, command, managed) {
|
|
|
2641
3349
|
return runStreamCommand(session, route, managed, stream, { toolArgs, options });
|
|
2642
3350
|
if (!tool)
|
|
2643
3351
|
throw new Error("[stitchkit] managed CLI executable invariant failed");
|
|
3352
|
+
if (options.view !== undefined && !options.wait) {
|
|
3353
|
+
try {
|
|
3354
|
+
assertViewColumns(options.view, descriptor.outputSchema);
|
|
3355
|
+
} catch (error) {
|
|
3356
|
+
if (!(error instanceof CliArgumentError2))
|
|
3357
|
+
throw error;
|
|
3358
|
+
stderr(`${error.message}
|
|
3359
|
+
`);
|
|
3360
|
+
return exit(2);
|
|
3361
|
+
}
|
|
3362
|
+
}
|
|
2644
3363
|
const result = await executeManagedTool(session, route, command, managed, tool, {
|
|
2645
3364
|
toolArgs,
|
|
2646
3365
|
options
|
|
@@ -2650,21 +3369,14 @@ async function runManagedCommand(session, route, command, managed) {
|
|
|
2650
3369
|
async function executeManagedTool(session, route, command, managed, tool, { toolArgs, options }) {
|
|
2651
3370
|
const { config } = session;
|
|
2652
3371
|
const { stderr } = session.io;
|
|
2653
|
-
const runTool =
|
|
2654
|
-
source: "cli",
|
|
2655
|
-
toolSurface: true,
|
|
2656
|
-
context: { ...config.context?.(managed.auth, route.typedGlobals), signal: config.signal },
|
|
2657
|
-
hooks: config.hooks,
|
|
2658
|
-
lifecycle: config.lifecycle,
|
|
2659
|
-
coerceJsonArgs: config.coerceJsonArgs
|
|
2660
|
-
});
|
|
3372
|
+
const runTool = createCliToolRunner(config, session.lifecycle, managed.auth, route.typedGlobals);
|
|
2661
3373
|
let result;
|
|
2662
3374
|
try {
|
|
2663
3375
|
result = await runTool(tool, toolArgs);
|
|
2664
3376
|
} catch (err) {
|
|
2665
3377
|
result = toolResultFromError(err);
|
|
2666
3378
|
}
|
|
2667
|
-
const waitConfig = config
|
|
3379
|
+
const waitConfig = cliWaitConfig(config, command);
|
|
2668
3380
|
if (options.wait && waitConfig) {
|
|
2669
3381
|
result = await pollUntilDone2({
|
|
2670
3382
|
initial: result,
|
|
@@ -2716,39 +3428,14 @@ async function emitManagedResult(session, command, result, options, repeatable)
|
|
|
2716
3428
|
if (!saved.ok)
|
|
2717
3429
|
mediaExitCode = 1;
|
|
2718
3430
|
}
|
|
2719
|
-
|
|
2720
|
-
let viewed;
|
|
2721
|
-
try {
|
|
2722
|
-
viewed = renderCliView2(shown.data, options.view);
|
|
2723
|
-
} catch (error) {
|
|
2724
|
-
const failure = error instanceof CliArgumentError2 ? {
|
|
2725
|
-
ok: false,
|
|
2726
|
-
code: "BAD_REQUEST",
|
|
2727
|
-
details: { message: error.message }
|
|
2728
|
-
} : toolResultFromError(error);
|
|
2729
|
-
return exit(emitPresentationFailure(shown, failure, { stdout, stderr }, emit));
|
|
2730
|
-
}
|
|
2731
|
-
if (viewed.kind === "text") {
|
|
2732
|
-
stdout(viewed.text);
|
|
2733
|
-
return exit(mediaExitCode);
|
|
2734
|
-
}
|
|
2735
|
-
if (viewed.order) {
|
|
2736
|
-
stdout(`${stringifyGroups(viewed.data, viewed.order, options.json === true)}
|
|
2737
|
-
`);
|
|
2738
|
-
return exit(mediaExitCode);
|
|
2739
|
-
}
|
|
2740
|
-
shown = { ...shown, data: viewed.data };
|
|
2741
|
-
}
|
|
2742
|
-
const policy = options.view === undefined && !options.wait ? cliResultPolicy(config, command) : undefined;
|
|
2743
|
-
const exitCode = emitCliCommandResult(policy, result, options, { stdout, stderr }, emit, shown);
|
|
2744
|
-
return exit(mediaExitCode || exitCode);
|
|
3431
|
+
return exit(emitCliViewOrResult(cliResultPolicy(config, command), result, options, { stdout, stderr }, emit, shown, mediaExitCode));
|
|
2745
3432
|
}
|
|
2746
3433
|
|
|
2747
3434
|
// src/tools/cli/run-native.ts
|
|
2748
|
-
async function
|
|
3435
|
+
async function runNativeCommand(session, route, command, native) {
|
|
2749
3436
|
const { config, applicationOptions, nativeHelp } = session;
|
|
2750
3437
|
const { stdout, stderr, exit, readStdin } = session.io;
|
|
2751
|
-
const {
|
|
3438
|
+
const { commandTokens, separatedBefore, framework, helpRequested, globals } = route;
|
|
2752
3439
|
const descriptor = nativeHelp.get(command);
|
|
2753
3440
|
if (!descriptor)
|
|
2754
3441
|
throw new Error("[stitchkit] native CLI descriptor invariant failed");
|
|
@@ -2760,17 +3447,13 @@ async function runNativeCommand2(session, route, command, native) {
|
|
|
2760
3447
|
stdout(renderCommandSchema(command, descriptor));
|
|
2761
3448
|
return exit(0);
|
|
2762
3449
|
}
|
|
2763
|
-
const prepared = await prepareInvocation(command,
|
|
3450
|
+
const prepared = await prepareInvocation(command, commandTokens, separatedBefore, framework, descriptor, config, readStdin);
|
|
2764
3451
|
if (!prepared.ok) {
|
|
2765
3452
|
stderr(`${prepared.message}
|
|
2766
3453
|
`);
|
|
2767
3454
|
return exit(2);
|
|
2768
3455
|
}
|
|
2769
3456
|
const { toolArgs, options } = prepared;
|
|
2770
|
-
if (options.help) {
|
|
2771
|
-
stdout(renderCommandHelp(config.name, command, descriptor, applicationOptions));
|
|
2772
|
-
return exit(0);
|
|
2773
|
-
}
|
|
2774
3457
|
if (options.wait) {
|
|
2775
3458
|
stderr(`--wait is not configured for native command "${command}"
|
|
2776
3459
|
`);
|
|
@@ -2791,17 +3474,20 @@ async function runNativeCommand2(session, route, command, native) {
|
|
|
2791
3474
|
`);
|
|
2792
3475
|
return exit(0);
|
|
2793
3476
|
}
|
|
2794
|
-
|
|
2795
|
-
|
|
3477
|
+
return exit(await executeNativeCommand(native, toolArgs, config.coerceJsonArgs ?? true, globals, {
|
|
3478
|
+
mode: "terminal",
|
|
3479
|
+
options,
|
|
3480
|
+
writers: { stdout, stderr },
|
|
3481
|
+
emit: { ...emitOptionsFor(config, options.json, command), repeatable: false }
|
|
3482
|
+
}));
|
|
2796
3483
|
}
|
|
2797
3484
|
|
|
2798
3485
|
// src/tools/cli/create-cli.ts
|
|
2799
3486
|
async function createCli2(config) {
|
|
3487
|
+
resolveOptionalCliToolAccess("createCli", config);
|
|
3488
|
+
assertNoLegacyCliPolicyKeys(config);
|
|
2800
3489
|
const io = createCliIo(config);
|
|
2801
3490
|
const argv = config.argv ?? process.argv.slice(2);
|
|
2802
|
-
if (config.auth !== undefined && config.resolveAuth !== undefined) {
|
|
2803
|
-
throw new Error("[stitchkit] createCli: use either auth or resolveAuth, not both");
|
|
2804
|
-
}
|
|
2805
3491
|
const session = createCliSession(config, io);
|
|
2806
3492
|
const route = resolveCliRoute(session, argv);
|
|
2807
3493
|
if (route === undefined)
|
|
@@ -2810,10 +3496,10 @@ async function createCli2(config) {
|
|
|
2810
3496
|
const { command } = route;
|
|
2811
3497
|
const native = command === undefined ? undefined : session.nativeCommands.get(command);
|
|
2812
3498
|
if (native && command !== undefined) {
|
|
2813
|
-
return
|
|
3499
|
+
return runNativeCommand(session, route, command, native);
|
|
2814
3500
|
}
|
|
2815
3501
|
return runManagedInvocation(session, route);
|
|
2816
3502
|
});
|
|
2817
3503
|
}
|
|
2818
3504
|
|
|
2819
|
-
export { DEFAULT_EXIT_CODES2, cliExitCode2, emitResult2, defineCliResult2, defineCliCommand2,
|
|
3505
|
+
export { CliArgumentError2, DEFAULT_EXIT_CODES2, cliExitCode2, emitResult2, renderCliView2, defineCliResult2, defineCliCommand2, cliInvocationResult2, createCliInvoker2, scanCliArgv, answersBeforeArguments, scanCliInvocation2, writeCliNotice, parseCliArgs2, extractCliGlobalOptions2, pollUntilDone2, createCli2 };
|