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
|
@@ -0,0 +1,2544 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_JSON_FILE_BYTES2,
|
|
3
|
+
RegularFileError2,
|
|
4
|
+
fileIdentity2,
|
|
5
|
+
readRegularFileSync2,
|
|
6
|
+
parseJsonBytes2
|
|
7
|
+
} from "../index-3gwp8ez6.js";
|
|
8
|
+
import {
|
|
9
|
+
ARTIFACT_MANIFEST_FILENAME2,
|
|
10
|
+
DEFAULT_ARTIFACT_MAX_FILE_BYTES2,
|
|
11
|
+
DEFAULT_ARTIFACT_MAX_FILES2,
|
|
12
|
+
ArtifactVerificationError2,
|
|
13
|
+
artifactRelativePathIssue,
|
|
14
|
+
assertSafeSingleSegment,
|
|
15
|
+
ArtifactFileEntrySchema2,
|
|
16
|
+
ArtifactManifestSchema2,
|
|
17
|
+
computeSha256Hex,
|
|
18
|
+
computeArtifactManifestDigest2,
|
|
19
|
+
isProcessGoneError,
|
|
20
|
+
classifyOwnerEvidence,
|
|
21
|
+
isAbsoluteNormalPath,
|
|
22
|
+
sameHostPath,
|
|
23
|
+
createBaseServiceHostAdapter,
|
|
24
|
+
extractPlistLabel,
|
|
25
|
+
LaunchdJobError2,
|
|
26
|
+
LaunchdKeepAliveSchema2,
|
|
27
|
+
LaunchdSessionTypeSchema2,
|
|
28
|
+
LaunchdPlistConfigSchema2,
|
|
29
|
+
renderLaunchdPlist2,
|
|
30
|
+
parseLaunchctlPrint2,
|
|
31
|
+
PLUTIL_PATH2,
|
|
32
|
+
LAUNCHCTL_PATH,
|
|
33
|
+
createDefaultLaunchdHostAdapter2,
|
|
34
|
+
assertAbsolutePlistPath,
|
|
35
|
+
lintLaunchdPlist2,
|
|
36
|
+
readLaunchdPlist2
|
|
37
|
+
} from "../index-fcw255hd.js";
|
|
38
|
+
import"../index-6kec3b14.js";
|
|
39
|
+
import {
|
|
40
|
+
probeLiveness,
|
|
41
|
+
ProcessInstanceSchema2,
|
|
42
|
+
sameProcessInstance,
|
|
43
|
+
observeProcessInstance2,
|
|
44
|
+
observeProcessInstanceAt,
|
|
45
|
+
probeProcessOwner2,
|
|
46
|
+
probeProcessOwnerWith
|
|
47
|
+
} from "../index-x90w78yz.js";
|
|
48
|
+
import"../index-v59pxmf1.js";
|
|
49
|
+
import"../index-7kfcb576.js";
|
|
50
|
+
import {
|
|
51
|
+
PolledJsonFile2
|
|
52
|
+
} from "../index-j13gzgdv.js";
|
|
53
|
+
import {
|
|
54
|
+
runNativeCommand2
|
|
55
|
+
} from "../index-5ptwb6ka.js";
|
|
56
|
+
import {
|
|
57
|
+
messageOf
|
|
58
|
+
} from "../index-r9kq5ark.js";
|
|
59
|
+
import {
|
|
60
|
+
canonicalDigest
|
|
61
|
+
} from "../index-3dq8466w.js";
|
|
62
|
+
import {
|
|
63
|
+
isWithinDir2,
|
|
64
|
+
realPathWithinDir
|
|
65
|
+
} from "../index-5cc6r990.js";
|
|
66
|
+
import {
|
|
67
|
+
syncDirectory
|
|
68
|
+
} from "../index-xtkw9866.js";
|
|
69
|
+
import {
|
|
70
|
+
closeAfterSync
|
|
71
|
+
} from "../index-nbv44x0x.js";
|
|
72
|
+
import {
|
|
73
|
+
stagingName
|
|
74
|
+
} from "../index-39n02e0q.js";
|
|
75
|
+
import {
|
|
76
|
+
errnoOf
|
|
77
|
+
} from "../index-jj9228tt.js";
|
|
78
|
+
import {
|
|
79
|
+
assertPositiveSafeInteger
|
|
80
|
+
} from "../index-kzavdze2.js";
|
|
81
|
+
import {
|
|
82
|
+
assertTimerMs
|
|
83
|
+
} from "../index-agy5fqgf.js";
|
|
84
|
+
import {
|
|
85
|
+
abortReason,
|
|
86
|
+
untilAborted
|
|
87
|
+
} from "../index-rptj3qnc.js";
|
|
88
|
+
|
|
89
|
+
// src/service-host/artifact.ts
|
|
90
|
+
import { createHash } from "node:crypto";
|
|
91
|
+
import {
|
|
92
|
+
closeSync,
|
|
93
|
+
constants,
|
|
94
|
+
fstatSync,
|
|
95
|
+
lstatSync,
|
|
96
|
+
openSync,
|
|
97
|
+
readdirSync,
|
|
98
|
+
readSync
|
|
99
|
+
} from "node:fs";
|
|
100
|
+
import { join, resolve } from "node:path";
|
|
101
|
+
var HASH_CHUNK_BYTES = 64 * 1024;
|
|
102
|
+
var MAX_DIRECTORY_DEPTH = 64;
|
|
103
|
+
function openNoFollowFlags() {
|
|
104
|
+
return constants.O_RDONLY | (constants.O_NONBLOCK ?? 0) | (constants.O_NOFOLLOW ?? 0);
|
|
105
|
+
}
|
|
106
|
+
function assertRealDirectorySync(directory) {
|
|
107
|
+
let info;
|
|
108
|
+
try {
|
|
109
|
+
info = lstatSync(directory);
|
|
110
|
+
} catch (cause) {
|
|
111
|
+
throw new ArtifactVerificationError2("INVALID_ROOT", `Artifact directory is missing or unreadable: ${directory}`, { cause, path: directory });
|
|
112
|
+
}
|
|
113
|
+
if (info.isSymbolicLink() || !info.isDirectory()) {
|
|
114
|
+
throw new ArtifactVerificationError2("INVALID_ROOT", `Artifact root must be a real directory (not a symlink): ${directory}`, { path: directory });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function hashRegularFileNoFollowSync(absPath, relPath, maxFileBytes) {
|
|
118
|
+
for (let attempt = 0;attempt < 2; attempt += 1) {
|
|
119
|
+
let linkInfo;
|
|
120
|
+
try {
|
|
121
|
+
linkInfo = lstatSync(absPath);
|
|
122
|
+
} catch (cause) {
|
|
123
|
+
if (errnoOf(cause) === "ENOENT") {
|
|
124
|
+
throw new ArtifactVerificationError2("MISSING_FILE", `Declared artifact file is missing: ${relPath}`, { cause, path: relPath });
|
|
125
|
+
}
|
|
126
|
+
throw cause;
|
|
127
|
+
}
|
|
128
|
+
if (linkInfo.isSymbolicLink() || !linkInfo.isFile()) {
|
|
129
|
+
throw new ArtifactVerificationError2("UNSUPPORTED_ENTRY", `Artifact payload entry must be a regular file: ${relPath}`, { path: relPath });
|
|
130
|
+
}
|
|
131
|
+
let fd;
|
|
132
|
+
try {
|
|
133
|
+
fd = openSync(absPath, openNoFollowFlags());
|
|
134
|
+
} catch (cause) {
|
|
135
|
+
const code = errnoOf(cause);
|
|
136
|
+
if (code === "ENOENT") {
|
|
137
|
+
throw new ArtifactVerificationError2("MISSING_FILE", `Declared artifact file vanished before open: ${relPath}`, { cause, path: relPath });
|
|
138
|
+
}
|
|
139
|
+
if (code === "ELOOP" || code === "EISDIR" || code === "ENXIO" || code === "EOPNOTSUPP") {
|
|
140
|
+
throw new ArtifactVerificationError2("UNSUPPORTED_ENTRY", `Refused non-regular or symlinked artifact file: ${relPath}`, { cause, path: relPath });
|
|
141
|
+
}
|
|
142
|
+
throw cause;
|
|
143
|
+
}
|
|
144
|
+
const result = closeAfterSync(() => closeSync(fd), () => {
|
|
145
|
+
const before = fstatSync(fd, { bigint: true });
|
|
146
|
+
if (!before.isFile()) {
|
|
147
|
+
throw new ArtifactVerificationError2("UNSUPPORTED_ENTRY", `Artifact payload entry is not a regular file: ${relPath}`, { path: relPath });
|
|
148
|
+
}
|
|
149
|
+
if (before.size > BigInt(maxFileBytes)) {
|
|
150
|
+
throw new ArtifactVerificationError2("LIMIT_EXCEEDED", `Artifact file exceeds ${maxFileBytes}-byte limit: ${relPath}`, { path: relPath });
|
|
151
|
+
}
|
|
152
|
+
const beforeId = fileIdentity2(before);
|
|
153
|
+
const hash = createHash("sha256");
|
|
154
|
+
const buffer = new Uint8Array(HASH_CHUNK_BYTES);
|
|
155
|
+
let total = 0;
|
|
156
|
+
for (;; ) {
|
|
157
|
+
const read = readSync(fd, buffer, 0, buffer.byteLength, null);
|
|
158
|
+
if (read === 0)
|
|
159
|
+
break;
|
|
160
|
+
total += read;
|
|
161
|
+
if (total > maxFileBytes) {
|
|
162
|
+
throw new ArtifactVerificationError2("LIMIT_EXCEEDED", `Artifact file exceeds ${maxFileBytes}-byte limit: ${relPath}`, { path: relPath });
|
|
163
|
+
}
|
|
164
|
+
hash.update(buffer.subarray(0, read));
|
|
165
|
+
}
|
|
166
|
+
const after = fstatSync(fd, { bigint: true });
|
|
167
|
+
const stable = fileIdentity2(after) === beforeId && after.nlink === before.nlink && BigInt(total) === after.size;
|
|
168
|
+
if (!stable)
|
|
169
|
+
return null;
|
|
170
|
+
const mode = Number(after.mode & 0o7777n);
|
|
171
|
+
return {
|
|
172
|
+
sha256: hash.digest("hex"),
|
|
173
|
+
size: total,
|
|
174
|
+
mode,
|
|
175
|
+
executable: (mode & 73) !== 0
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
if (result !== null)
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
181
|
+
throw new ArtifactVerificationError2("DIGEST_MISMATCH", `Artifact file changed concurrently while hashing: ${relPath}`, { path: relPath });
|
|
182
|
+
}
|
|
183
|
+
function collectArtifactFilesSync(rootDir, manifestFileName, maxFiles) {
|
|
184
|
+
const discovered = new Set;
|
|
185
|
+
const emptyDirs = [];
|
|
186
|
+
const maxEntries = Math.max(maxFiles * 4, maxFiles + 1024);
|
|
187
|
+
let visitedEntries = 0;
|
|
188
|
+
const walk = (relDir, depth) => {
|
|
189
|
+
if (depth > MAX_DIRECTORY_DEPTH) {
|
|
190
|
+
throw new ArtifactVerificationError2("LIMIT_EXCEEDED", `Artifact directory exceeds maximum nesting depth (${MAX_DIRECTORY_DEPTH}): ${relDir}`, { path: relDir });
|
|
191
|
+
}
|
|
192
|
+
const absDir = relDir === "" ? rootDir : join(rootDir, relDir);
|
|
193
|
+
const entries = readdirSync(absDir, { withFileTypes: true });
|
|
194
|
+
let filesInSubtree = 0;
|
|
195
|
+
for (const entry of entries) {
|
|
196
|
+
visitedEntries += 1;
|
|
197
|
+
if (visitedEntries > maxEntries) {
|
|
198
|
+
throw new ArtifactVerificationError2("LIMIT_EXCEEDED", `Artifact directory exceeds ${maxEntries}-entry walk limit`);
|
|
199
|
+
}
|
|
200
|
+
const relPath = relDir === "" ? entry.name : `${relDir}/${entry.name}`;
|
|
201
|
+
const absPath = join(absDir, entry.name);
|
|
202
|
+
const info = lstatSync(absPath);
|
|
203
|
+
if (entry.isSymbolicLink() || info.isSymbolicLink()) {
|
|
204
|
+
throw new ArtifactVerificationError2("UNSUPPORTED_ENTRY", `Symlink is forbidden inside artifact directory: ${relPath}`, { path: relPath });
|
|
205
|
+
}
|
|
206
|
+
if (info.isDirectory()) {
|
|
207
|
+
const subFiles = walk(relPath, depth + 1);
|
|
208
|
+
if (subFiles === 0)
|
|
209
|
+
emptyDirs.push(relPath);
|
|
210
|
+
filesInSubtree += subFiles;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (!info.isFile()) {
|
|
214
|
+
throw new ArtifactVerificationError2("UNSUPPORTED_ENTRY", `Non-regular file is forbidden inside artifact directory: ${relPath}`, { path: relPath });
|
|
215
|
+
}
|
|
216
|
+
if (relPath === manifestFileName)
|
|
217
|
+
continue;
|
|
218
|
+
discovered.add(relPath);
|
|
219
|
+
filesInSubtree += 1;
|
|
220
|
+
if (discovered.size > maxFiles) {
|
|
221
|
+
throw new ArtifactVerificationError2("LIMIT_EXCEEDED", `Artifact directory exceeds ${maxFiles}-file limit`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return filesInSubtree;
|
|
225
|
+
};
|
|
226
|
+
walk("", 0);
|
|
227
|
+
return { files: discovered, emptyDirs };
|
|
228
|
+
}
|
|
229
|
+
function readVerifiedManifestSync(rootDir, manifestFileName, maxManifestBytes) {
|
|
230
|
+
const manifestPath = join(rootDir, manifestFileName);
|
|
231
|
+
let info;
|
|
232
|
+
try {
|
|
233
|
+
info = lstatSync(manifestPath);
|
|
234
|
+
} catch (cause) {
|
|
235
|
+
throw new ArtifactVerificationError2("INVALID_MANIFEST", `Artifact manifest is missing: ${manifestFileName}`, { cause, path: manifestFileName });
|
|
236
|
+
}
|
|
237
|
+
if (info.isSymbolicLink() || !info.isFile()) {
|
|
238
|
+
throw new ArtifactVerificationError2("UNSUPPORTED_ENTRY", `Artifact manifest must be a regular file: ${manifestFileName}`, { path: manifestFileName });
|
|
239
|
+
}
|
|
240
|
+
let raw;
|
|
241
|
+
try {
|
|
242
|
+
const bytes = readRegularFileSync2(manifestPath, {
|
|
243
|
+
limit: maxManifestBytes,
|
|
244
|
+
noFollow: true
|
|
245
|
+
});
|
|
246
|
+
raw = parseJsonBytes2(bytes);
|
|
247
|
+
} catch (cause) {
|
|
248
|
+
const detail = cause instanceof RegularFileError2 ? cause.message : messageOf(cause);
|
|
249
|
+
throw new ArtifactVerificationError2("INVALID_MANIFEST", `Failed to read artifact manifest (${manifestFileName}): ${detail}`, { cause, path: manifestFileName });
|
|
250
|
+
}
|
|
251
|
+
const parsed = ArtifactManifestSchema2.safeParse(raw);
|
|
252
|
+
if (!parsed.success) {
|
|
253
|
+
throw new ArtifactVerificationError2("INVALID_MANIFEST", `Invalid artifact manifest (${manifestFileName}): ${parsed.error.message}`, { cause: parsed.error, path: manifestFileName });
|
|
254
|
+
}
|
|
255
|
+
for (const entry of parsed.data.files) {
|
|
256
|
+
const issue = artifactRelativePathIssue(entry.path, manifestFileName);
|
|
257
|
+
if (issue !== null) {
|
|
258
|
+
throw new ArtifactVerificationError2("INVALID_MANIFEST", issue, { path: entry.path });
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return parsed.data;
|
|
262
|
+
}
|
|
263
|
+
async function verifyArtifactDirectory(directory, options = {}) {
|
|
264
|
+
const manifestFileName = options.manifestFileName ?? ARTIFACT_MANIFEST_FILENAME2;
|
|
265
|
+
assertSafeSingleSegment("manifestFileName", manifestFileName, "INVALID_MANIFEST");
|
|
266
|
+
const maxFileBytes = options.maxFileBytes ?? DEFAULT_ARTIFACT_MAX_FILE_BYTES2;
|
|
267
|
+
const maxManifestBytes = options.maxManifestBytes ?? DEFAULT_JSON_FILE_BYTES2;
|
|
268
|
+
const maxFiles = options.maxFiles ?? DEFAULT_ARTIFACT_MAX_FILES2;
|
|
269
|
+
assertPositiveSafeInteger("maxFileBytes", maxFileBytes);
|
|
270
|
+
assertPositiveSafeInteger("maxManifestBytes", maxManifestBytes);
|
|
271
|
+
assertPositiveSafeInteger("maxFiles", maxFiles);
|
|
272
|
+
const absRoot = resolve(directory);
|
|
273
|
+
assertRealDirectorySync(absRoot);
|
|
274
|
+
const manifest = readVerifiedManifestSync(absRoot, manifestFileName, maxManifestBytes);
|
|
275
|
+
if (manifest.files.length > maxFiles) {
|
|
276
|
+
throw new ArtifactVerificationError2("LIMIT_EXCEEDED", `Artifact manifest declares ${manifest.files.length} files, exceeding ${maxFiles}-file limit`);
|
|
277
|
+
}
|
|
278
|
+
const discovered = collectArtifactFilesSync(absRoot, manifestFileName, maxFiles);
|
|
279
|
+
const declaredPaths = new Set(manifest.files.map((entry) => entry.path));
|
|
280
|
+
for (const relPath of declaredPaths) {
|
|
281
|
+
if (!discovered.files.has(relPath)) {
|
|
282
|
+
throw new ArtifactVerificationError2("MISSING_FILE", `Declared artifact file is missing from directory: ${relPath}`, { path: relPath });
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
for (const relPath of discovered.files) {
|
|
286
|
+
if (!declaredPaths.has(relPath)) {
|
|
287
|
+
throw new ArtifactVerificationError2("EXTRA_FILE", `Undeclared extra file found in artifact directory: ${relPath}`, { path: relPath });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const firstEmptyDir = discovered.emptyDirs[0];
|
|
291
|
+
if (firstEmptyDir !== undefined) {
|
|
292
|
+
throw new ArtifactVerificationError2("EXTRA_FILE", `Empty undeclared subdirectory found in artifact directory: ${firstEmptyDir}`, { path: firstEmptyDir });
|
|
293
|
+
}
|
|
294
|
+
const verifiedFiles = [];
|
|
295
|
+
for (const entry of manifest.files) {
|
|
296
|
+
const absPath = resolve(absRoot, entry.path);
|
|
297
|
+
if (!isWithinDir2(absRoot, absPath)) {
|
|
298
|
+
throw new ArtifactVerificationError2("PATH_TRAVERSAL", `Artifact file escapes root directory: ${entry.path}`, { path: entry.path });
|
|
299
|
+
}
|
|
300
|
+
const measured = hashRegularFileNoFollowSync(absPath, entry.path, maxFileBytes);
|
|
301
|
+
if (entry.size !== undefined && measured.size !== entry.size) {
|
|
302
|
+
throw new ArtifactVerificationError2("SIZE_MISMATCH", `Size mismatch for ${entry.path}: expected ${entry.size}, got ${measured.size}`, { path: entry.path });
|
|
303
|
+
}
|
|
304
|
+
if (entry.executable !== undefined && measured.executable !== entry.executable) {
|
|
305
|
+
throw new ArtifactVerificationError2("EXECUTABLE_MISMATCH", `Executable bit mismatch for ${entry.path}: expected ${entry.executable}, got ${measured.executable}`, { path: entry.path });
|
|
306
|
+
}
|
|
307
|
+
if (measured.sha256 !== entry.sha256) {
|
|
308
|
+
throw new ArtifactVerificationError2("DIGEST_MISMATCH", `SHA-256 mismatch for ${entry.path}: expected ${entry.sha256}, got ${measured.sha256}`, { path: entry.path });
|
|
309
|
+
}
|
|
310
|
+
verifiedFiles.push({
|
|
311
|
+
path: entry.path,
|
|
312
|
+
sha256: measured.sha256,
|
|
313
|
+
size: measured.size,
|
|
314
|
+
executable: measured.executable,
|
|
315
|
+
mode: measured.mode
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
const verified = {
|
|
319
|
+
directory: absRoot,
|
|
320
|
+
version: manifest.version,
|
|
321
|
+
manifestDigest: computeArtifactManifestDigest2(manifest),
|
|
322
|
+
manifest,
|
|
323
|
+
files: verifiedFiles
|
|
324
|
+
};
|
|
325
|
+
if (options.checkRequirements !== undefined) {
|
|
326
|
+
try {
|
|
327
|
+
await options.checkRequirements(verified);
|
|
328
|
+
} catch (cause) {
|
|
329
|
+
if (cause instanceof ArtifactVerificationError2)
|
|
330
|
+
throw cause;
|
|
331
|
+
throw new ArtifactVerificationError2("REQUIREMENT_FAILED", `Artifact requirements check failed: ${messageOf(cause)}`, { cause });
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return verified;
|
|
335
|
+
}
|
|
336
|
+
// src/service-host/artifact-activation.ts
|
|
337
|
+
import {
|
|
338
|
+
chmod,
|
|
339
|
+
copyFile,
|
|
340
|
+
lstat,
|
|
341
|
+
mkdir,
|
|
342
|
+
open,
|
|
343
|
+
readlink,
|
|
344
|
+
realpath,
|
|
345
|
+
rename,
|
|
346
|
+
rm,
|
|
347
|
+
symlink,
|
|
348
|
+
unlink
|
|
349
|
+
} from "node:fs/promises";
|
|
350
|
+
import { dirname, join as join2, resolve as resolve2 } from "node:path";
|
|
351
|
+
var MAX_DEFAULT_VERSION_PREFIX = 64;
|
|
352
|
+
async function atomicSwitchSymlink(linkPath, target, errorCode) {
|
|
353
|
+
const tempLink = join2(dirname(linkPath), stagingName());
|
|
354
|
+
try {
|
|
355
|
+
await symlink(target, tempLink);
|
|
356
|
+
try {
|
|
357
|
+
await rename(tempLink, linkPath);
|
|
358
|
+
} catch (cause) {
|
|
359
|
+
await unlink(tempLink).catch(() => {
|
|
360
|
+
return;
|
|
361
|
+
});
|
|
362
|
+
throw cause;
|
|
363
|
+
}
|
|
364
|
+
await syncDirectory(dirname(linkPath));
|
|
365
|
+
} catch (cause) {
|
|
366
|
+
throw new ArtifactVerificationError2(errorCode, `Failed to atomically switch symlink ${linkPath} → ${target}: ${messageOf(cause)}`, { cause, path: linkPath });
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
var RELEASE_DIRECTORY_MODE = 493;
|
|
370
|
+
var RELEASE_FILE_MODE_MASK = 493;
|
|
371
|
+
async function syncFile(path) {
|
|
372
|
+
const handle = await open(path, "r");
|
|
373
|
+
try {
|
|
374
|
+
await handle.sync();
|
|
375
|
+
} finally {
|
|
376
|
+
await handle.close();
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
async function copyVerifiedRelease(sourceDir, destDir, artifact, manifestFileName) {
|
|
380
|
+
await mkdir(destDir, { recursive: true, mode: RELEASE_DIRECTORY_MODE });
|
|
381
|
+
const manifestPath = join2(destDir, manifestFileName);
|
|
382
|
+
await copyFile(join2(sourceDir, manifestFileName), manifestPath);
|
|
383
|
+
await chmod(manifestPath, 420);
|
|
384
|
+
const copied = [manifestPath];
|
|
385
|
+
const directories = new Set([destDir]);
|
|
386
|
+
for (const file of artifact.files) {
|
|
387
|
+
const targetPath = join2(destDir, file.path);
|
|
388
|
+
await mkdir(dirname(targetPath), { recursive: true, mode: RELEASE_DIRECTORY_MODE });
|
|
389
|
+
await copyFile(join2(sourceDir, file.path), targetPath);
|
|
390
|
+
await chmod(targetPath, file.mode & RELEASE_FILE_MODE_MASK);
|
|
391
|
+
copied.push(targetPath);
|
|
392
|
+
for (let dir = dirname(targetPath);dir.length > destDir.length; dir = dirname(dir))
|
|
393
|
+
directories.add(dir);
|
|
394
|
+
}
|
|
395
|
+
for (const path of copied)
|
|
396
|
+
await syncFile(path);
|
|
397
|
+
const deepestFirst = [...directories].sort((a, b) => b.length - a.length);
|
|
398
|
+
for (const dir of deepestFirst)
|
|
399
|
+
await syncDirectory(dir);
|
|
400
|
+
}
|
|
401
|
+
function defaultReleaseKey(artifact) {
|
|
402
|
+
const stripped = artifact.version.replace(/[^A-Za-z0-9._-]/g, "-").replace(/^\.+/, "").slice(0, MAX_DEFAULT_VERSION_PREFIX);
|
|
403
|
+
const prefix = stripped.length > 0 ? stripped : "release";
|
|
404
|
+
return `${prefix}-${artifact.manifestDigest.slice(0, 12)}`;
|
|
405
|
+
}
|
|
406
|
+
async function assertExistingReleaseMatches(releaseDir, releaseKey, expectedDigest, verifyOptions) {
|
|
407
|
+
const existingVerified = await verifyArtifactDirectory(releaseDir, verifyOptions).catch((cause) => {
|
|
408
|
+
throw new ArtifactVerificationError2("ACTIVATION_FAILED", `Existing release directory ${releaseKey} is corrupted or invalid`, { cause, path: releaseDir });
|
|
409
|
+
});
|
|
410
|
+
if (existingVerified.manifestDigest !== expectedDigest) {
|
|
411
|
+
throw new ArtifactVerificationError2("ACTIVATION_FAILED", `Release directory ${releaseKey} already exists with a different manifest digest`, { path: releaseDir });
|
|
412
|
+
}
|
|
413
|
+
return existingVerified;
|
|
414
|
+
}
|
|
415
|
+
function parseRollbackTarget(previousTarget, releasesDirName) {
|
|
416
|
+
if (previousTarget.length === 0 || previousTarget.includes("\x00") || previousTarget.includes("\\") || previousTarget.startsWith("/") || previousTarget.endsWith("/")) {
|
|
417
|
+
throw new ArtifactVerificationError2("ROLLBACK_FAILED", `Rollback target must be '<${releasesDirName}>/<releaseKey>': ${JSON.stringify(previousTarget)}`, { path: previousTarget });
|
|
418
|
+
}
|
|
419
|
+
const parts = previousTarget.split("/");
|
|
420
|
+
if (parts.length !== 2 || parts[0] !== releasesDirName) {
|
|
421
|
+
throw new ArtifactVerificationError2("ROLLBACK_FAILED", `Rollback target must be '<${releasesDirName}>/<releaseKey>': ${JSON.stringify(previousTarget)}`, { path: previousTarget });
|
|
422
|
+
}
|
|
423
|
+
const releaseKey = parts[1] ?? "";
|
|
424
|
+
assertSafeSingleSegment("releaseKey", releaseKey, "ROLLBACK_FAILED");
|
|
425
|
+
return { releaseKey };
|
|
426
|
+
}
|
|
427
|
+
async function activateVersionedArtifact(options) {
|
|
428
|
+
const releasesDirName = options.releasesDirName ?? "releases";
|
|
429
|
+
const currentLinkName = options.currentLinkName ?? "current";
|
|
430
|
+
const manifestFileName = options.verifyOptions?.manifestFileName ?? ARTIFACT_MANIFEST_FILENAME2;
|
|
431
|
+
assertSafeSingleSegment("releasesDirName", releasesDirName, "ACTIVATION_FAILED");
|
|
432
|
+
assertSafeSingleSegment("currentLinkName", currentLinkName, "ACTIVATION_FAILED");
|
|
433
|
+
if (releasesDirName === currentLinkName) {
|
|
434
|
+
throw new ArtifactVerificationError2("ACTIVATION_FAILED", `releasesDirName and currentLinkName must differ (${releasesDirName})`);
|
|
435
|
+
}
|
|
436
|
+
const verifiedSource = await verifyArtifactDirectory(options.sourceDir, options.verifyOptions);
|
|
437
|
+
const releaseKey = options.releaseKey ?? defaultReleaseKey(verifiedSource);
|
|
438
|
+
assertSafeSingleSegment("releaseKey", releaseKey, "ACTIVATION_FAILED");
|
|
439
|
+
const absRoot = resolve2(options.rootDir);
|
|
440
|
+
const releasesDir = join2(absRoot, releasesDirName);
|
|
441
|
+
const releaseDir = join2(releasesDir, releaseKey);
|
|
442
|
+
const currentLinkPath = join2(absRoot, currentLinkName);
|
|
443
|
+
const currentInfo = await lstat(currentLinkPath).catch((cause) => {
|
|
444
|
+
if (errnoOf(cause) === "ENOENT")
|
|
445
|
+
return null;
|
|
446
|
+
throw cause;
|
|
447
|
+
});
|
|
448
|
+
if (currentInfo !== null && !currentInfo.isSymbolicLink()) {
|
|
449
|
+
throw new ArtifactVerificationError2("ACTIVATION_FAILED", `Current pointer path exists and is not a symlink: ${currentLinkPath}`, { path: currentLinkPath });
|
|
450
|
+
}
|
|
451
|
+
const releasesInfo = await lstat(releasesDir).catch((cause) => {
|
|
452
|
+
if (errnoOf(cause) === "ENOENT")
|
|
453
|
+
return null;
|
|
454
|
+
throw cause;
|
|
455
|
+
});
|
|
456
|
+
if (releasesInfo !== null && (releasesInfo.isSymbolicLink() || !releasesInfo.isDirectory())) {
|
|
457
|
+
throw new ArtifactVerificationError2("ACTIVATION_FAILED", `Releases path exists and is not a real directory: ${releasesDir}`, { path: releasesDir });
|
|
458
|
+
}
|
|
459
|
+
await mkdir(releasesDir, { recursive: true });
|
|
460
|
+
await syncDirectory(absRoot);
|
|
461
|
+
const existingRelease = await lstat(releaseDir).catch((cause) => {
|
|
462
|
+
if (errnoOf(cause) === "ENOENT")
|
|
463
|
+
return null;
|
|
464
|
+
throw cause;
|
|
465
|
+
});
|
|
466
|
+
let activatedArtifact;
|
|
467
|
+
if (existingRelease !== null) {
|
|
468
|
+
activatedArtifact = await assertExistingReleaseMatches(releaseDir, releaseKey, verifiedSource.manifestDigest, options.verifyOptions);
|
|
469
|
+
} else {
|
|
470
|
+
const stagedDir = join2(releasesDir, stagingName());
|
|
471
|
+
try {
|
|
472
|
+
await copyVerifiedRelease(verifiedSource.directory, stagedDir, verifiedSource, manifestFileName);
|
|
473
|
+
const stagedVerified = await verifyArtifactDirectory(stagedDir, options.verifyOptions);
|
|
474
|
+
if (stagedVerified.manifestDigest !== verifiedSource.manifestDigest) {
|
|
475
|
+
throw new ArtifactVerificationError2("ACTIVATION_FAILED", `Staged release digest drifted for ${releaseKey}`, { path: stagedDir });
|
|
476
|
+
}
|
|
477
|
+
try {
|
|
478
|
+
await rename(stagedDir, releaseDir);
|
|
479
|
+
await syncDirectory(releasesDir);
|
|
480
|
+
activatedArtifact = stagedVerified;
|
|
481
|
+
} catch (renameCause) {
|
|
482
|
+
const code = errnoOf(renameCause);
|
|
483
|
+
if (code === "EEXIST" || code === "ENOTEMPTY") {
|
|
484
|
+
await rm(stagedDir, { recursive: true, force: true }).catch(() => {
|
|
485
|
+
return;
|
|
486
|
+
});
|
|
487
|
+
activatedArtifact = await assertExistingReleaseMatches(releaseDir, releaseKey, verifiedSource.manifestDigest, options.verifyOptions);
|
|
488
|
+
} else {
|
|
489
|
+
throw renameCause;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
} catch (cause) {
|
|
493
|
+
await rm(stagedDir, { recursive: true, force: true }).catch(() => {
|
|
494
|
+
return;
|
|
495
|
+
});
|
|
496
|
+
if (cause instanceof ArtifactVerificationError2)
|
|
497
|
+
throw cause;
|
|
498
|
+
throw new ArtifactVerificationError2("ACTIVATION_FAILED", `Failed to stage release ${releaseKey}: ${messageOf(cause)}`, { cause, path: releaseDir });
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
let previousTarget = null;
|
|
502
|
+
let previousReleaseDir = null;
|
|
503
|
+
if (currentInfo !== null) {
|
|
504
|
+
previousTarget = await readlink(currentLinkPath);
|
|
505
|
+
previousReleaseDir = resolve2(absRoot, previousTarget);
|
|
506
|
+
}
|
|
507
|
+
const relativeTarget = `${releasesDirName}/${releaseKey}`;
|
|
508
|
+
await atomicSwitchSymlink(currentLinkPath, relativeTarget, "ACTIVATION_FAILED");
|
|
509
|
+
return {
|
|
510
|
+
releaseKey,
|
|
511
|
+
releaseDir,
|
|
512
|
+
currentLinkPath,
|
|
513
|
+
previousTarget,
|
|
514
|
+
previousReleaseDir,
|
|
515
|
+
artifact: { ...activatedArtifact, directory: releaseDir }
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
async function rollbackVersionedArtifact(options) {
|
|
519
|
+
const releasesDirName = options.releasesDirName ?? "releases";
|
|
520
|
+
const currentLinkName = options.currentLinkName ?? "current";
|
|
521
|
+
assertSafeSingleSegment("releasesDirName", releasesDirName, "ROLLBACK_FAILED");
|
|
522
|
+
assertSafeSingleSegment("currentLinkName", currentLinkName, "ROLLBACK_FAILED");
|
|
523
|
+
if (releasesDirName === currentLinkName) {
|
|
524
|
+
throw new ArtifactVerificationError2("ROLLBACK_FAILED", `releasesDirName and currentLinkName must differ (${releasesDirName})`);
|
|
525
|
+
}
|
|
526
|
+
const { releaseKey } = parseRollbackTarget(options.previousTarget, releasesDirName);
|
|
527
|
+
const absRoot = resolve2(options.rootDir);
|
|
528
|
+
const releasesDir = join2(absRoot, releasesDirName);
|
|
529
|
+
const currentLinkPath = join2(absRoot, currentLinkName);
|
|
530
|
+
const releasesInfo = await lstat(releasesDir).catch((cause) => {
|
|
531
|
+
throw new ArtifactVerificationError2("ROLLBACK_FAILED", `Releases directory is missing: ${releasesDir}`, { cause, path: releasesDir });
|
|
532
|
+
});
|
|
533
|
+
if (releasesInfo.isSymbolicLink() || !releasesInfo.isDirectory()) {
|
|
534
|
+
throw new ArtifactVerificationError2("ROLLBACK_FAILED", `Releases path must be a real directory: ${releasesDir}`, { path: releasesDir });
|
|
535
|
+
}
|
|
536
|
+
const currentInfo = await lstat(currentLinkPath).catch((cause) => {
|
|
537
|
+
if (errnoOf(cause) === "ENOENT")
|
|
538
|
+
return null;
|
|
539
|
+
throw cause;
|
|
540
|
+
});
|
|
541
|
+
if (currentInfo !== null && !currentInfo.isSymbolicLink()) {
|
|
542
|
+
throw new ArtifactVerificationError2("ROLLBACK_FAILED", `Current pointer path exists and is not a symlink: ${currentLinkPath}`, { path: currentLinkPath });
|
|
543
|
+
}
|
|
544
|
+
const restoredDir = resolve2(releasesDir, releaseKey);
|
|
545
|
+
const targetInfo = await lstat(restoredDir).catch((cause) => {
|
|
546
|
+
throw new ArtifactVerificationError2("ROLLBACK_FAILED", `Rollback target directory is missing: ${options.previousTarget}`, { cause, path: options.previousTarget });
|
|
547
|
+
});
|
|
548
|
+
if (targetInfo.isSymbolicLink() || !targetInfo.isDirectory()) {
|
|
549
|
+
throw new ArtifactVerificationError2("ROLLBACK_FAILED", `Rollback target must be a real directory: ${options.previousTarget}`, { path: options.previousTarget });
|
|
550
|
+
}
|
|
551
|
+
const [realReleases, realRestored] = await Promise.all([
|
|
552
|
+
realpath(releasesDir).catch(() => null),
|
|
553
|
+
realPathWithinDir(releasesDir, restoredDir)
|
|
554
|
+
]);
|
|
555
|
+
if (realReleases === null || realRestored === null || realRestored === realReleases) {
|
|
556
|
+
throw new ArtifactVerificationError2("ROLLBACK_FAILED", `Rollback target escapes releases directory: ${options.previousTarget}`, { path: options.previousTarget });
|
|
557
|
+
}
|
|
558
|
+
const artifact = await verifyArtifactDirectory(restoredDir, options.verifyOptions);
|
|
559
|
+
await atomicSwitchSymlink(currentLinkPath, options.previousTarget, "ROLLBACK_FAILED");
|
|
560
|
+
return {
|
|
561
|
+
currentLinkPath,
|
|
562
|
+
restoredTarget: options.previousTarget,
|
|
563
|
+
restoredDir,
|
|
564
|
+
artifact
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
// src/service-host/config-reloader-contract.ts
|
|
568
|
+
var DEFAULT_CONFIG_POLL_INTERVAL_MS = 2000;
|
|
569
|
+
var DEFAULT_CONFIG_START_TIMEOUT_MS = 30000;
|
|
570
|
+
var DEFAULT_CONFIG_STOP_TIMEOUT_MS = 1e4;
|
|
571
|
+
|
|
572
|
+
// src/service-host/config-reloader-source.ts
|
|
573
|
+
var DEFAULT_CONFIG_RELOADER_CLOCK = {
|
|
574
|
+
now: () => Date.now(),
|
|
575
|
+
schedule(cb, ms) {
|
|
576
|
+
const timer = globalThis.setTimeout(cb, ms);
|
|
577
|
+
return () => globalThis.clearTimeout(timer);
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
function safeCallObserver(fn) {
|
|
581
|
+
if (!fn)
|
|
582
|
+
return;
|
|
583
|
+
try {
|
|
584
|
+
const result = fn();
|
|
585
|
+
if (result !== undefined && result !== null) {
|
|
586
|
+
Promise.resolve(result).catch(() => {
|
|
587
|
+
return;
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
} catch {}
|
|
591
|
+
}
|
|
592
|
+
function runBoundedOperation(label, op, timeoutMs, clock, parent, onLate) {
|
|
593
|
+
const ctrl = new AbortController;
|
|
594
|
+
const raw = Promise.resolve().then(() => op(ctrl.signal));
|
|
595
|
+
raw.catch(() => {
|
|
596
|
+
return;
|
|
597
|
+
});
|
|
598
|
+
return new Promise((resolve, reject) => {
|
|
599
|
+
let settled = false;
|
|
600
|
+
let cancel = null;
|
|
601
|
+
const onParent = () => fail(parent ? abortReason(parent) : undefined);
|
|
602
|
+
const settle = (fn) => {
|
|
603
|
+
if (settled)
|
|
604
|
+
return;
|
|
605
|
+
settled = true;
|
|
606
|
+
cancel?.();
|
|
607
|
+
cancel = null;
|
|
608
|
+
parent?.removeEventListener("abort", onParent);
|
|
609
|
+
fn();
|
|
610
|
+
};
|
|
611
|
+
const fail = (err) => settle(() => {
|
|
612
|
+
ctrl.abort(err);
|
|
613
|
+
reject(err);
|
|
614
|
+
});
|
|
615
|
+
if (parent?.aborted)
|
|
616
|
+
fail(abortReason(parent));
|
|
617
|
+
else {
|
|
618
|
+
parent?.addEventListener("abort", onParent, { once: true });
|
|
619
|
+
cancel = clock.schedule(() => fail(new Error(`${label} timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
620
|
+
}
|
|
621
|
+
raw.then((v) => settled ? onLate?.(v) : settle(() => resolve(v)), (e) => settle(() => reject(e)));
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
async function validateConfigValue(validate, config, digest) {
|
|
625
|
+
if (!validate)
|
|
626
|
+
return { ok: true };
|
|
627
|
+
try {
|
|
628
|
+
await validate(config);
|
|
629
|
+
return { ok: true };
|
|
630
|
+
} catch (error) {
|
|
631
|
+
const detail = messageOf(error) || String(error);
|
|
632
|
+
return { ok: false, error, detail, key: `validate:${digest}:${canonicalDigest(detail)}` };
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
function createPolledJsonConfigSource(options) {
|
|
636
|
+
const polled = new PolledJsonFile2(options.path, options.schema, {
|
|
637
|
+
limit: options.maxBytes,
|
|
638
|
+
maxCacheBytes: options.maxCacheBytes
|
|
639
|
+
});
|
|
640
|
+
return {
|
|
641
|
+
read() {
|
|
642
|
+
const changed = polled.readChanged();
|
|
643
|
+
if (changed === null)
|
|
644
|
+
return { state: "unchanged" };
|
|
645
|
+
if (changed.state === "missing")
|
|
646
|
+
return { state: "missing" };
|
|
647
|
+
if (changed.state === "unreadable" || changed.state === "invalid") {
|
|
648
|
+
const failureKey = `${changed.state}:${canonicalDigest(changed.detail)}`;
|
|
649
|
+
return { state: "invalid", detail: changed.detail, failureKey };
|
|
650
|
+
}
|
|
651
|
+
const digest = options.digest ? options.digest(changed.value, changed.text) : canonicalDigest(changed.text);
|
|
652
|
+
return { state: "valid", config: changed.value, digest };
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// src/service-host/config-reloader-helpers.ts
|
|
658
|
+
function resolveReloaderSettings(options) {
|
|
659
|
+
const settings = {
|
|
660
|
+
pollMs: options.pollIntervalMs ?? DEFAULT_CONFIG_POLL_INTERVAL_MS,
|
|
661
|
+
startMs: options.startTimeoutMs ?? DEFAULT_CONFIG_START_TIMEOUT_MS,
|
|
662
|
+
stopMs: options.stopTimeoutMs ?? DEFAULT_CONFIG_STOP_TIMEOUT_MS,
|
|
663
|
+
rollback: options.rollbackOnStartFailure ?? true,
|
|
664
|
+
clock: options.clock ?? DEFAULT_CONFIG_RELOADER_CLOCK
|
|
665
|
+
};
|
|
666
|
+
assertTimerMs("pollIntervalMs", settings.pollMs);
|
|
667
|
+
assertTimerMs("startTimeoutMs", settings.startMs);
|
|
668
|
+
assertTimerMs("stopTimeoutMs", settings.stopMs);
|
|
669
|
+
return settings;
|
|
670
|
+
}
|
|
671
|
+
async function startInitialReloaderHandle(options, cfg) {
|
|
672
|
+
const initial = await options.source.read();
|
|
673
|
+
if (initial.state !== "valid") {
|
|
674
|
+
if (initial.state === "unchanged")
|
|
675
|
+
throw new Error("Config source returned unchanged");
|
|
676
|
+
const detail = initial.state === "invalid" ? initial.detail : "Config is missing";
|
|
677
|
+
const key = initial.state === "invalid" ? initial.failureKey : "missing";
|
|
678
|
+
safeCallObserver(() => options.onInvalidConfig?.(detail, key));
|
|
679
|
+
throw new Error(`Startup config failed: ${detail}`);
|
|
680
|
+
}
|
|
681
|
+
const valid = await validateConfigValue(options.validate, initial.config, initial.digest);
|
|
682
|
+
if (!valid.ok) {
|
|
683
|
+
safeCallObserver(() => options.onInvalidConfig?.(valid.detail, valid.key));
|
|
684
|
+
throw valid.error;
|
|
685
|
+
}
|
|
686
|
+
const handle = await runBoundedOperation("start", (sig) => options.start(initial.config, sig), cfg.startMs, cfg.clock, undefined, (lateHandle) => {
|
|
687
|
+
runBoundedOperation("stop", (sig) => options.stop(lateHandle, sig), cfg.stopMs, cfg.clock).catch((err) => safeCallObserver(() => options.onError?.({ phase: "stop", error: err, digest: initial.digest })));
|
|
688
|
+
});
|
|
689
|
+
return { handle, config: initial.config, digest: initial.digest };
|
|
690
|
+
}
|
|
691
|
+
function isPromiseLike(value) {
|
|
692
|
+
return (typeof value === "object" || typeof value === "function") && value !== null && "then" in value && typeof value.then === "function";
|
|
693
|
+
}
|
|
694
|
+
function armShutdownDeadline(shutdownAbort, opts, defaultGraceMs, clock) {
|
|
695
|
+
let forced;
|
|
696
|
+
let cancelDeadline = null;
|
|
697
|
+
const force = (reason) => {
|
|
698
|
+
if (forced !== undefined)
|
|
699
|
+
return;
|
|
700
|
+
forced = reason;
|
|
701
|
+
shutdownAbort.abort(new Error(`ConfigReloader shutdown forced by ${reason}`));
|
|
702
|
+
};
|
|
703
|
+
const onExternal = () => force("signal");
|
|
704
|
+
const graceMs = opts.gracePeriodMs ?? defaultGraceMs;
|
|
705
|
+
if (opts.signal?.aborted)
|
|
706
|
+
force("signal");
|
|
707
|
+
else if (graceMs === 0)
|
|
708
|
+
force("deadline");
|
|
709
|
+
else {
|
|
710
|
+
opts.signal?.addEventListener("abort", onExternal, { once: true });
|
|
711
|
+
cancelDeadline = clock.schedule(() => force("deadline"), graceMs);
|
|
712
|
+
}
|
|
713
|
+
return {
|
|
714
|
+
forcedReason: () => forced,
|
|
715
|
+
disarm() {
|
|
716
|
+
cancelDeadline?.();
|
|
717
|
+
opts.signal?.removeEventListener("abort", onExternal);
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// src/service-host/config-reloader.ts
|
|
723
|
+
class ReloaderController {
|
|
724
|
+
options;
|
|
725
|
+
cfg;
|
|
726
|
+
active;
|
|
727
|
+
state = "running";
|
|
728
|
+
lastInvalidKey = null;
|
|
729
|
+
lastFailedStartDigest = null;
|
|
730
|
+
reloads = 0;
|
|
731
|
+
failedReloads = 0;
|
|
732
|
+
pollCancel = null;
|
|
733
|
+
inFlight = null;
|
|
734
|
+
pending = null;
|
|
735
|
+
shutdownPromise = null;
|
|
736
|
+
shutdownAbort = new AbortController;
|
|
737
|
+
retry = null;
|
|
738
|
+
stopInFlight = null;
|
|
739
|
+
constructor(options, cfg, active) {
|
|
740
|
+
this.options = options;
|
|
741
|
+
this.cfg = cfg;
|
|
742
|
+
this.active = active;
|
|
743
|
+
this.schedulePoll();
|
|
744
|
+
}
|
|
745
|
+
stopping = () => this.state === "closing" || this.state === "closed";
|
|
746
|
+
status = () => ({
|
|
747
|
+
state: this.state,
|
|
748
|
+
activeDigest: this.active.digest,
|
|
749
|
+
lastInvalidKey: this.lastInvalidKey,
|
|
750
|
+
lastFailedStartDigest: this.lastFailedStartDigest,
|
|
751
|
+
reloads: this.reloads,
|
|
752
|
+
failedReloads: this.failedReloads,
|
|
753
|
+
hasActiveHandle: this.active.handle !== null
|
|
754
|
+
});
|
|
755
|
+
triggerReload() {
|
|
756
|
+
if (this.stopping())
|
|
757
|
+
return Promise.resolve();
|
|
758
|
+
this.pollCancel?.();
|
|
759
|
+
this.pollCancel = null;
|
|
760
|
+
if (this.inFlight === null) {
|
|
761
|
+
this.inFlight = this.drainLoop();
|
|
762
|
+
return this.inFlight;
|
|
763
|
+
}
|
|
764
|
+
this.pending ??= Promise.withResolvers();
|
|
765
|
+
return this.pending.promise;
|
|
766
|
+
}
|
|
767
|
+
shutdown(opts = {}) {
|
|
768
|
+
if (this.shutdownPromise !== null)
|
|
769
|
+
return this.shutdownPromise;
|
|
770
|
+
try {
|
|
771
|
+
assertTimerMs("gracePeriodMs", opts.gracePeriodMs, { min: 0 });
|
|
772
|
+
} catch (error) {
|
|
773
|
+
return Promise.reject(error);
|
|
774
|
+
}
|
|
775
|
+
const startedAt = this.cfg.clock.now();
|
|
776
|
+
this.state = "closing";
|
|
777
|
+
this.pollCancel?.();
|
|
778
|
+
this.pollCancel = null;
|
|
779
|
+
this.pending?.resolve();
|
|
780
|
+
this.pending = null;
|
|
781
|
+
const deadline = armShutdownDeadline(this.shutdownAbort, opts, this.cfg.stopMs, this.cfg.clock);
|
|
782
|
+
this.shutdownPromise = (async () => {
|
|
783
|
+
try {
|
|
784
|
+
if (this.inFlight !== null)
|
|
785
|
+
await untilAborted(this.inFlight, this.shutdownAbort.signal);
|
|
786
|
+
if (this.active.handle !== null) {
|
|
787
|
+
const handle = this.active.handle;
|
|
788
|
+
this.active.handle = null;
|
|
789
|
+
let reported = false;
|
|
790
|
+
const reportStopError = (error) => {
|
|
791
|
+
if (reported)
|
|
792
|
+
return;
|
|
793
|
+
reported = true;
|
|
794
|
+
this.emitError("shutdown", error, this.active.digest ?? undefined);
|
|
795
|
+
};
|
|
796
|
+
const earlier = this.stopInFlight?.handle === handle ? this.stopInFlight.settled : undefined;
|
|
797
|
+
const task = Promise.resolve(earlier ?? "failed").then((outcome) => outcome === "stopped" ? undefined : this.options.stop(handle, this.shutdownAbort.signal));
|
|
798
|
+
task.catch((error) => {
|
|
799
|
+
if (deadline.forcedReason() !== undefined)
|
|
800
|
+
reportStopError(error);
|
|
801
|
+
});
|
|
802
|
+
if (deadline.forcedReason() === undefined) {
|
|
803
|
+
try {
|
|
804
|
+
await untilAborted(task, this.shutdownAbort.signal);
|
|
805
|
+
} catch (error) {
|
|
806
|
+
reportStopError(error);
|
|
807
|
+
throw error;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
const forced = deadline.forcedReason();
|
|
812
|
+
return {
|
|
813
|
+
outcome: forced !== undefined ? "forced" : "clean",
|
|
814
|
+
...forced !== undefined && { reason: forced },
|
|
815
|
+
reloads: this.reloads,
|
|
816
|
+
failedReloads: this.failedReloads,
|
|
817
|
+
durationMs: Math.max(0, this.cfg.clock.now() - startedAt)
|
|
818
|
+
};
|
|
819
|
+
} finally {
|
|
820
|
+
deadline.disarm();
|
|
821
|
+
this.state = "closed";
|
|
822
|
+
}
|
|
823
|
+
})();
|
|
824
|
+
return this.shutdownPromise;
|
|
825
|
+
}
|
|
826
|
+
schedulePoll() {
|
|
827
|
+
if (this.stopping() || this.pollCancel !== null)
|
|
828
|
+
return;
|
|
829
|
+
this.pollCancel = this.cfg.clock.schedule(() => {
|
|
830
|
+
this.pollCancel = null;
|
|
831
|
+
if (!this.stopping())
|
|
832
|
+
this.triggerReload();
|
|
833
|
+
}, this.cfg.pollMs);
|
|
834
|
+
}
|
|
835
|
+
emitError(phase, error, digest) {
|
|
836
|
+
safeCallObserver(() => this.options.onError?.({ phase, error, ...digest !== undefined && { digest } }));
|
|
837
|
+
}
|
|
838
|
+
emitInvalid(detail, key) {
|
|
839
|
+
if (this.lastInvalidKey === key)
|
|
840
|
+
return false;
|
|
841
|
+
this.lastInvalidKey = key;
|
|
842
|
+
safeCallObserver(() => this.options.onInvalidConfig?.(detail, key));
|
|
843
|
+
return true;
|
|
844
|
+
}
|
|
845
|
+
async waitForClosingStop(stopTask, digest) {
|
|
846
|
+
const guarded = stopTask.catch((error) => {
|
|
847
|
+
this.emitError("shutdown", error, digest);
|
|
848
|
+
});
|
|
849
|
+
await untilAborted(guarded, this.shutdownAbort.signal);
|
|
850
|
+
}
|
|
851
|
+
stopLate(handle, digest) {
|
|
852
|
+
return runBoundedOperation("stop", (sig) => this.options.stop(handle, sig), this.cfg.stopMs, this.cfg.clock).catch((err) => this.emitError(this.stopping() ? "shutdown" : "stop", err, digest));
|
|
853
|
+
}
|
|
854
|
+
async stopHandleOnClose(handle, digest) {
|
|
855
|
+
if (this.shutdownAbort.signal.aborted) {
|
|
856
|
+
this.stopLate(handle, digest);
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
const stopTask = Promise.resolve().then(() => this.options.stop(handle, this.shutdownAbort.signal));
|
|
860
|
+
await this.waitForClosingStop(stopTask, digest);
|
|
861
|
+
}
|
|
862
|
+
async startCandidate(config, digest) {
|
|
863
|
+
const startState = { task: null, outcome: "pending" };
|
|
864
|
+
let lateCleanup = null;
|
|
865
|
+
const cleanupLate = (late) => {
|
|
866
|
+
if (lateCleanup !== null)
|
|
867
|
+
return lateCleanup;
|
|
868
|
+
lateCleanup = this.stopping() && !this.shutdownAbort.signal.aborted ? this.stopHandleOnClose(late, digest) : this.stopLate(late, digest);
|
|
869
|
+
return lateCleanup;
|
|
870
|
+
};
|
|
871
|
+
try {
|
|
872
|
+
const handle = await runBoundedOperation("start", (sig) => {
|
|
873
|
+
let result;
|
|
874
|
+
try {
|
|
875
|
+
result = this.options.start(config, sig);
|
|
876
|
+
} catch (syncError) {
|
|
877
|
+
startState.outcome = "rejected";
|
|
878
|
+
throw syncError;
|
|
879
|
+
}
|
|
880
|
+
if (isPromiseLike(result)) {
|
|
881
|
+
const task = Promise.resolve(result);
|
|
882
|
+
startState.task = task;
|
|
883
|
+
task.then(() => {
|
|
884
|
+
startState.outcome = "resolved";
|
|
885
|
+
}, () => {
|
|
886
|
+
startState.outcome = "rejected";
|
|
887
|
+
});
|
|
888
|
+
} else {
|
|
889
|
+
startState.outcome = "resolved";
|
|
890
|
+
}
|
|
891
|
+
return result;
|
|
892
|
+
}, this.cfg.startMs, this.cfg.clock, this.shutdownAbort.signal, (late) => {
|
|
893
|
+
cleanupLate(late);
|
|
894
|
+
});
|
|
895
|
+
if (this.stopping()) {
|
|
896
|
+
await this.stopHandleOnClose(handle, digest);
|
|
897
|
+
return { ok: false, closed: true };
|
|
898
|
+
}
|
|
899
|
+
return { ok: true, handle };
|
|
900
|
+
} catch (error) {
|
|
901
|
+
if (!this.stopping())
|
|
902
|
+
return { ok: false, closed: false, error };
|
|
903
|
+
if (startState.outcome !== "rejected" && startState.task !== null && !this.shutdownAbort.signal.aborted) {
|
|
904
|
+
const settledStart = startState.task.then(cleanupLate, () => {
|
|
905
|
+
return;
|
|
906
|
+
});
|
|
907
|
+
await untilAborted(settledStart, this.shutdownAbort.signal);
|
|
908
|
+
}
|
|
909
|
+
return { ok: false, closed: true };
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
async drainLoop() {
|
|
913
|
+
try {
|
|
914
|
+
await this.checkOnce();
|
|
915
|
+
while (this.pending !== null && !this.stopping()) {
|
|
916
|
+
const slot = this.pending;
|
|
917
|
+
this.pending = null;
|
|
918
|
+
try {
|
|
919
|
+
await this.checkOnce();
|
|
920
|
+
} finally {
|
|
921
|
+
slot.resolve();
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
} finally {
|
|
925
|
+
this.inFlight = null;
|
|
926
|
+
this.pending?.resolve();
|
|
927
|
+
this.pending = null;
|
|
928
|
+
if (!this.stopping())
|
|
929
|
+
this.schedulePoll();
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
async checkOnce() {
|
|
933
|
+
if (this.stopping() || this.stopInFlight !== null)
|
|
934
|
+
return;
|
|
935
|
+
let reading;
|
|
936
|
+
try {
|
|
937
|
+
reading = await this.options.source.read();
|
|
938
|
+
} catch (error) {
|
|
939
|
+
return this.emitError("read", error);
|
|
940
|
+
}
|
|
941
|
+
if (this.stopping())
|
|
942
|
+
return;
|
|
943
|
+
if (reading.state === "unchanged") {
|
|
944
|
+
if (this.active.handle === null && this.retry !== null) {
|
|
945
|
+
await this.applyValidated(this.retry.config, this.retry.digest);
|
|
946
|
+
}
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
if (reading.state === "missing") {
|
|
950
|
+
this.retry = null;
|
|
951
|
+
this.emitInvalid("Config is missing", "missing");
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
if (reading.state === "invalid") {
|
|
955
|
+
this.retry = null;
|
|
956
|
+
this.emitInvalid(reading.detail, reading.failureKey);
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
if (reading.digest === this.active.digest && this.active.handle !== null) {
|
|
960
|
+
this.lastInvalidKey = null;
|
|
961
|
+
this.lastFailedStartDigest = null;
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
if (reading.digest === this.lastFailedStartDigest && this.active.handle !== null)
|
|
965
|
+
return;
|
|
966
|
+
const valid = await validateConfigValue(this.options.validate, reading.config, reading.digest);
|
|
967
|
+
if (!valid.ok) {
|
|
968
|
+
this.retry = null;
|
|
969
|
+
if (this.emitInvalid(valid.detail, valid.key)) {
|
|
970
|
+
this.emitError("validate", valid.error, reading.digest);
|
|
971
|
+
}
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
this.lastInvalidKey = null;
|
|
975
|
+
if (!this.stopping())
|
|
976
|
+
await this.applyValidated(reading.config, reading.digest);
|
|
977
|
+
}
|
|
978
|
+
async applyValidated(config, digest) {
|
|
979
|
+
this.state = "reloading";
|
|
980
|
+
const prev = { ...this.active };
|
|
981
|
+
if (prev.handle !== null) {
|
|
982
|
+
const oldHandle = prev.handle;
|
|
983
|
+
this.active.handle = null;
|
|
984
|
+
let stopTask = Promise.resolve();
|
|
985
|
+
let stopSettled = false;
|
|
986
|
+
try {
|
|
987
|
+
await runBoundedOperation("stop", (sig) => {
|
|
988
|
+
stopTask = Promise.resolve().then(() => this.options.stop(oldHandle, sig));
|
|
989
|
+
const settle = () => {
|
|
990
|
+
stopSettled = true;
|
|
991
|
+
};
|
|
992
|
+
stopTask.then(settle, settle);
|
|
993
|
+
return stopTask;
|
|
994
|
+
}, this.cfg.stopMs, this.cfg.clock, this.shutdownAbort.signal);
|
|
995
|
+
} catch (error) {
|
|
996
|
+
if (this.stopping()) {
|
|
997
|
+
if (stopSettled) {
|
|
998
|
+
if (!this.shutdownAbort.signal.aborted) {
|
|
999
|
+
this.emitError("shutdown", error, prev.digest ?? undefined);
|
|
1000
|
+
}
|
|
1001
|
+
} else {
|
|
1002
|
+
await this.waitForClosingStop(stopTask, prev.digest ?? undefined);
|
|
1003
|
+
}
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
this.active.handle = oldHandle;
|
|
1007
|
+
this.failedReloads += 1;
|
|
1008
|
+
this.lastFailedStartDigest = digest;
|
|
1009
|
+
this.state = "degraded";
|
|
1010
|
+
if (!stopSettled)
|
|
1011
|
+
this.followLateStop(oldHandle, stopTask, config, digest);
|
|
1012
|
+
return this.emitError("stop", error, digest);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
if (this.stopping())
|
|
1016
|
+
return;
|
|
1017
|
+
const started = await this.startCandidate(config, digest);
|
|
1018
|
+
if (started.ok) {
|
|
1019
|
+
this.active = { handle: started.handle, config, digest };
|
|
1020
|
+
this.retry = null;
|
|
1021
|
+
this.lastFailedStartDigest = null;
|
|
1022
|
+
this.reloads += 1;
|
|
1023
|
+
this.state = "running";
|
|
1024
|
+
return safeCallObserver(() => this.options.onReload?.(digest));
|
|
1025
|
+
}
|
|
1026
|
+
if (started.closed)
|
|
1027
|
+
return;
|
|
1028
|
+
this.failedReloads += 1;
|
|
1029
|
+
this.lastFailedStartDigest = digest;
|
|
1030
|
+
this.emitError("start", started.error, digest);
|
|
1031
|
+
if (this.cfg.rollback && prev.digest !== null) {
|
|
1032
|
+
const rolled = await this.startCandidate(prev.config, prev.digest);
|
|
1033
|
+
if (rolled.ok) {
|
|
1034
|
+
this.active = { handle: rolled.handle, config: prev.config, digest: prev.digest };
|
|
1035
|
+
this.retry = null;
|
|
1036
|
+
this.state = "running";
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
if (rolled.closed)
|
|
1040
|
+
return;
|
|
1041
|
+
this.emitError("rollback", rolled.error, prev.digest);
|
|
1042
|
+
}
|
|
1043
|
+
this.active.handle = null;
|
|
1044
|
+
this.active.digest = null;
|
|
1045
|
+
this.retry = { config, digest };
|
|
1046
|
+
this.state = "degraded";
|
|
1047
|
+
}
|
|
1048
|
+
followLateStop(handle, stopTask, config, digest) {
|
|
1049
|
+
const settled = stopTask.then(() => "stopped", () => "failed");
|
|
1050
|
+
this.stopInFlight = { handle, settled };
|
|
1051
|
+
settled.then((outcome) => {
|
|
1052
|
+
if (this.stopInFlight?.handle !== handle)
|
|
1053
|
+
return;
|
|
1054
|
+
this.stopInFlight = null;
|
|
1055
|
+
if (outcome !== "stopped" || this.active.handle !== handle)
|
|
1056
|
+
return;
|
|
1057
|
+
this.active.handle = null;
|
|
1058
|
+
this.active.digest = null;
|
|
1059
|
+
this.lastFailedStartDigest = null;
|
|
1060
|
+
this.retry = { config, digest };
|
|
1061
|
+
if (!this.stopping())
|
|
1062
|
+
this.triggerReload();
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
async function startConfigReloader(options) {
|
|
1067
|
+
const cfg = resolveReloaderSettings(options);
|
|
1068
|
+
const initial = await startInitialReloaderHandle(options, cfg);
|
|
1069
|
+
return new ReloaderController(options, cfg, initial);
|
|
1070
|
+
}
|
|
1071
|
+
// src/service-host/identity.ts
|
|
1072
|
+
import { constants as constants2 } from "node:fs";
|
|
1073
|
+
import { access, readdir, readFile, readlink as readlink2, realpath as realpath2, stat } from "node:fs/promises";
|
|
1074
|
+
import { z } from "zod";
|
|
1075
|
+
|
|
1076
|
+
// src/service-host/identity-unix-socket.ts
|
|
1077
|
+
var SO_ACCEPTCON_FLAG = 65536;
|
|
1078
|
+
var PROC_NET_UNIX_LINE = /^[0-9a-fA-F]+:\s+[0-9a-fA-F]+\s+[0-9a-fA-F]+\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+(\d+)(?: (.*))?$/s;
|
|
1079
|
+
var SS_UNIX_LINE = /^u_(?:str|dgr|seq)\s+\S+\s+\d+\s+\d+\s+(.*)\s(\d+)\s+\*\s+0(?:\s(.*))?$/s;
|
|
1080
|
+
var SS_NODE = /(?:^|\s)ino:(\d+)\s+dev:(\d+)\/(\d+)(?:\s|$)/;
|
|
1081
|
+
function recordLines(output, table, format, header) {
|
|
1082
|
+
const lines = output.split(`
|
|
1083
|
+
`);
|
|
1084
|
+
if (lines.at(-1) === "")
|
|
1085
|
+
lines.pop();
|
|
1086
|
+
const records = [];
|
|
1087
|
+
for (const [index, line] of lines.entries()) {
|
|
1088
|
+
if (index === 0 && header !== undefined && line.startsWith(header))
|
|
1089
|
+
continue;
|
|
1090
|
+
const match = format.exec(line);
|
|
1091
|
+
if (match === null) {
|
|
1092
|
+
throw new Error(`${table} line ${index + 1} is not a socket record: a socket name holds a line break, so no line of it can be trusted`);
|
|
1093
|
+
}
|
|
1094
|
+
records.push(match);
|
|
1095
|
+
}
|
|
1096
|
+
return records;
|
|
1097
|
+
}
|
|
1098
|
+
var SS_UNIX_LISTENER_ARGS = ["-H", "-x", "-l", "-e"];
|
|
1099
|
+
function parseUnixSocketListeners(output) {
|
|
1100
|
+
const listeners = [];
|
|
1101
|
+
for (const [, name = "", inode = "", tail = ""] of recordLines(output, "ss", SS_UNIX_LINE)) {
|
|
1102
|
+
const node = SS_NODE.exec(tail);
|
|
1103
|
+
const [, ino, major, minor] = node ?? [];
|
|
1104
|
+
listeners.push({
|
|
1105
|
+
inode,
|
|
1106
|
+
name,
|
|
1107
|
+
...ino !== undefined && major !== undefined && minor !== undefined && {
|
|
1108
|
+
node: { ino: BigInt(ino), dev: BigInt(major) << 20n | BigInt(minor) }
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
return listeners;
|
|
1113
|
+
}
|
|
1114
|
+
function parseProcNetUnixListeningSockets(content) {
|
|
1115
|
+
const sockets = [];
|
|
1116
|
+
for (const match of recordLines(content, "/proc/net/unix", PROC_NET_UNIX_LINE, "Num")) {
|
|
1117
|
+
const flagsHex = match[1] ?? "";
|
|
1118
|
+
const typeHex = match[2] ?? "";
|
|
1119
|
+
const stateHex = match[3] ?? "";
|
|
1120
|
+
const inode = match[4] ?? "";
|
|
1121
|
+
const path = match[5] ?? "";
|
|
1122
|
+
const flags = Number.parseInt(flagsHex, 16);
|
|
1123
|
+
const state = Number.parseInt(stateHex, 16);
|
|
1124
|
+
const listening = state === 1 && (flags & SO_ACCEPTCON_FLAG) !== 0;
|
|
1125
|
+
if (!listening || path.length === 0 || inode === "0")
|
|
1126
|
+
continue;
|
|
1127
|
+
sockets.push({ flagsHex, typeHex, stateHex, listening: true, inode, path });
|
|
1128
|
+
}
|
|
1129
|
+
return sockets;
|
|
1130
|
+
}
|
|
1131
|
+
function matchListeningSockets(sockets, socketPath, boundInodes) {
|
|
1132
|
+
if (socketPath.startsWith("@")) {
|
|
1133
|
+
return sockets.filter((entry) => entry.path === socketPath && boundInodes.has(entry.inode));
|
|
1134
|
+
}
|
|
1135
|
+
return sockets.filter((entry) => !entry.path.startsWith("@") && boundInodes.has(entry.inode));
|
|
1136
|
+
}
|
|
1137
|
+
function sameSocketInodeSet(left, right) {
|
|
1138
|
+
const leftSet = new Set(left.map((entry) => entry.inode));
|
|
1139
|
+
const rightSet = new Set(right.map((entry) => entry.inode));
|
|
1140
|
+
if (leftSet.size !== rightSet.size)
|
|
1141
|
+
return false;
|
|
1142
|
+
for (const inode of leftSet) {
|
|
1143
|
+
if (!rightSet.has(inode))
|
|
1144
|
+
return false;
|
|
1145
|
+
}
|
|
1146
|
+
return true;
|
|
1147
|
+
}
|
|
1148
|
+
async function snapshotListeningSockets(pid, socketPath, adapter) {
|
|
1149
|
+
let listening;
|
|
1150
|
+
let boundInodes;
|
|
1151
|
+
try {
|
|
1152
|
+
listening = parseProcNetUnixListeningSockets(await adapter.readProcNetUnix());
|
|
1153
|
+
boundInodes = await adapter.readSocketInodesAtPath(socketPath);
|
|
1154
|
+
} catch (cause) {
|
|
1155
|
+
return {
|
|
1156
|
+
ok: false,
|
|
1157
|
+
failure: {
|
|
1158
|
+
status: "runtime-unavailable",
|
|
1159
|
+
reason: "socket-unverifiable",
|
|
1160
|
+
pid,
|
|
1161
|
+
socketPath,
|
|
1162
|
+
cause
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
return { ok: true, sockets: matchListeningSockets(listening, socketPath, boundInodes) };
|
|
1167
|
+
}
|
|
1168
|
+
async function readSocketInodesOrFail(pid, socketPath, adapter) {
|
|
1169
|
+
try {
|
|
1170
|
+
return { ok: true, inodes: await adapter.readProcessSocketInodes(pid) };
|
|
1171
|
+
} catch (cause) {
|
|
1172
|
+
return {
|
|
1173
|
+
ok: false,
|
|
1174
|
+
failure: {
|
|
1175
|
+
status: "runtime-unavailable",
|
|
1176
|
+
reason: isProcessGoneError(cause) ? "process-gone" : "process-unobservable",
|
|
1177
|
+
pid,
|
|
1178
|
+
socketPath,
|
|
1179
|
+
cause
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
async function verifyUnixSocketOwnership(pid, socketPath, targetInstance, adapter) {
|
|
1185
|
+
const snap1 = await snapshotListeningSockets(pid, socketPath, adapter);
|
|
1186
|
+
if (!snap1.ok)
|
|
1187
|
+
return snap1;
|
|
1188
|
+
if (snap1.sockets.length === 0) {
|
|
1189
|
+
return {
|
|
1190
|
+
ok: false,
|
|
1191
|
+
failure: {
|
|
1192
|
+
status: "runtime-unavailable",
|
|
1193
|
+
reason: "socket-not-listening",
|
|
1194
|
+
pid,
|
|
1195
|
+
socketPath
|
|
1196
|
+
}
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
const fdRead1 = await readSocketInodesOrFail(pid, socketPath, adapter);
|
|
1200
|
+
if (!fdRead1.ok)
|
|
1201
|
+
return fdRead1;
|
|
1202
|
+
let processInodes = fdRead1.inodes;
|
|
1203
|
+
let owned = snap1.sockets.find((entry) => processInodes.has(entry.inode));
|
|
1204
|
+
if (owned === undefined) {
|
|
1205
|
+
const snap2 = await snapshotListeningSockets(pid, socketPath, adapter);
|
|
1206
|
+
if (!snap2.ok)
|
|
1207
|
+
return snap2;
|
|
1208
|
+
if (snap2.sockets.length === 0) {
|
|
1209
|
+
return {
|
|
1210
|
+
ok: false,
|
|
1211
|
+
failure: {
|
|
1212
|
+
status: "runtime-unavailable",
|
|
1213
|
+
reason: "socket-not-listening",
|
|
1214
|
+
pid,
|
|
1215
|
+
socketPath
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1219
|
+
owned = snap2.sockets.find((entry) => processInodes.has(entry.inode));
|
|
1220
|
+
if (owned === undefined && !sameSocketInodeSet(snap1.sockets, snap2.sockets)) {
|
|
1221
|
+
const fdRead2 = await readSocketInodesOrFail(pid, socketPath, adapter);
|
|
1222
|
+
if (!fdRead2.ok)
|
|
1223
|
+
return fdRead2;
|
|
1224
|
+
processInodes = fdRead2.inodes;
|
|
1225
|
+
owned = snap2.sockets.find((entry) => processInodes.has(entry.inode));
|
|
1226
|
+
}
|
|
1227
|
+
if (owned === undefined) {
|
|
1228
|
+
const ownerNow = await adapter.probeProcessOwner(pid, targetInstance);
|
|
1229
|
+
const ownerFailure = classifyOwnerEvidence(pid, ownerNow);
|
|
1230
|
+
if (ownerFailure !== null)
|
|
1231
|
+
return { ok: false, failure: ownerFailure };
|
|
1232
|
+
return {
|
|
1233
|
+
ok: false,
|
|
1234
|
+
failure: {
|
|
1235
|
+
status: "runtime-conflict",
|
|
1236
|
+
reason: "socket-owned-by-other-process",
|
|
1237
|
+
pid,
|
|
1238
|
+
socketPath,
|
|
1239
|
+
listeningInodes: snap2.sockets.map((entry) => entry.inode)
|
|
1240
|
+
}
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
return { ok: true, inode: owned.inode, processInodes };
|
|
1245
|
+
}
|
|
1246
|
+
async function confirmUnixSocketAfterProbe(pid, socketPath, previousInode, processInodes, targetInstance, adapter) {
|
|
1247
|
+
const snapAfter = await snapshotListeningSockets(pid, socketPath, adapter);
|
|
1248
|
+
if (!snapAfter.ok)
|
|
1249
|
+
return snapAfter;
|
|
1250
|
+
if (snapAfter.sockets.length === 0) {
|
|
1251
|
+
return {
|
|
1252
|
+
ok: false,
|
|
1253
|
+
failure: {
|
|
1254
|
+
status: "runtime-unavailable",
|
|
1255
|
+
reason: "socket-not-listening",
|
|
1256
|
+
pid,
|
|
1257
|
+
socketPath
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
let confirmed = snapAfter.sockets.find((entry) => processInodes.has(entry.inode));
|
|
1262
|
+
if (confirmed === undefined) {
|
|
1263
|
+
if (!snapAfter.sockets.some((entry) => entry.inode === previousInode)) {
|
|
1264
|
+
const fdRefresh = await readSocketInodesOrFail(pid, socketPath, adapter);
|
|
1265
|
+
if (!fdRefresh.ok)
|
|
1266
|
+
return fdRefresh;
|
|
1267
|
+
confirmed = snapAfter.sockets.find((entry) => fdRefresh.inodes.has(entry.inode));
|
|
1268
|
+
}
|
|
1269
|
+
const ownerAfter = await adapter.probeProcessOwner(pid, targetInstance);
|
|
1270
|
+
const ownerFailure = classifyOwnerEvidence(pid, ownerAfter);
|
|
1271
|
+
if (ownerFailure !== null)
|
|
1272
|
+
return { ok: false, failure: ownerFailure };
|
|
1273
|
+
if (confirmed === undefined) {
|
|
1274
|
+
return {
|
|
1275
|
+
ok: false,
|
|
1276
|
+
failure: {
|
|
1277
|
+
status: "runtime-conflict",
|
|
1278
|
+
reason: "socket-owned-by-other-process",
|
|
1279
|
+
pid,
|
|
1280
|
+
socketPath,
|
|
1281
|
+
listeningInodes: snapAfter.sockets.map((entry) => entry.inode)
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
return { ok: true, inode: confirmed.inode };
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
// src/service-host/identity.ts
|
|
1290
|
+
var MAX_PID = 2 ** 31 - 1;
|
|
1291
|
+
var SS_TIMEOUT_MS = 5000;
|
|
1292
|
+
var SS_MAX_OUTPUT_BYTES = 8 * 1024 * 1024;
|
|
1293
|
+
var SOCKET_LINK_PATTERN = /^socket:\[(\d+)\]$/;
|
|
1294
|
+
var SS_CANDIDATES = ["/usr/bin/ss", "/usr/sbin/ss"];
|
|
1295
|
+
async function resolveHostExecutable(candidates) {
|
|
1296
|
+
for (const candidate of candidates) {
|
|
1297
|
+
try {
|
|
1298
|
+
await access(candidate, constants2.X_OK);
|
|
1299
|
+
return candidate;
|
|
1300
|
+
} catch (cause) {
|
|
1301
|
+
const code = errnoOf(cause);
|
|
1302
|
+
if (code !== "ENOENT" && code !== "ENOTDIR" && code !== "EACCES")
|
|
1303
|
+
throw cause;
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
throw new Error(`ss (iproute2) not found: none of ${candidates.join(", ")} is executable`);
|
|
1307
|
+
}
|
|
1308
|
+
function decodeProcCmdline(bytes) {
|
|
1309
|
+
if (bytes.byteLength === 0)
|
|
1310
|
+
return [];
|
|
1311
|
+
const text = new TextDecoder("utf-8").decode(bytes);
|
|
1312
|
+
const parts = text.split("\x00");
|
|
1313
|
+
if (parts.length > 0 && parts[parts.length - 1] === "")
|
|
1314
|
+
parts.pop();
|
|
1315
|
+
return parts;
|
|
1316
|
+
}
|
|
1317
|
+
function createDefaultProcessIdentityAdapter(procRoot = "/proc") {
|
|
1318
|
+
return createProcfsIdentityAdapter({ procRoot, ssCandidates: SS_CANDIDATES });
|
|
1319
|
+
}
|
|
1320
|
+
function createProcfsIdentityAdapter(options) {
|
|
1321
|
+
const { procRoot, ssCandidates } = options;
|
|
1322
|
+
const observe = (pid) => procRoot === "/proc" ? observeProcessInstance2(pid) : observeProcessInstanceAt(pid, procRoot);
|
|
1323
|
+
const probe = (pid, recorded) => {
|
|
1324
|
+
if (procRoot === "/proc")
|
|
1325
|
+
return probeProcessOwner2(pid, recorded);
|
|
1326
|
+
return probeProcessOwnerWith(pid, recorded, {
|
|
1327
|
+
read: async (target) => {
|
|
1328
|
+
const obs = await observeProcessInstanceAt(target, procRoot);
|
|
1329
|
+
return obs.state === "observed" ? obs.instance : null;
|
|
1330
|
+
},
|
|
1331
|
+
observe: (target) => observeProcessInstanceAt(target, procRoot),
|
|
1332
|
+
liveness: probeLiveness
|
|
1333
|
+
});
|
|
1334
|
+
};
|
|
1335
|
+
return {
|
|
1336
|
+
observeProcessInstance: observe,
|
|
1337
|
+
probeProcessOwner: probe,
|
|
1338
|
+
readProcessExe: (pid) => readlink2(`${procRoot}/${pid}/exe`),
|
|
1339
|
+
async resolveExecutablePath(path) {
|
|
1340
|
+
try {
|
|
1341
|
+
return await realpath2(path);
|
|
1342
|
+
} catch (cause) {
|
|
1343
|
+
const code = errnoOf(cause);
|
|
1344
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
1345
|
+
return path;
|
|
1346
|
+
throw cause;
|
|
1347
|
+
}
|
|
1348
|
+
},
|
|
1349
|
+
readProcessArgv: async (pid) => decodeProcCmdline(await readFile(`${procRoot}/${pid}/cmdline`)),
|
|
1350
|
+
readProcNetUnix: () => readFile(`${procRoot}/net/unix`, "utf8"),
|
|
1351
|
+
async readProcessSocketInodes(pid) {
|
|
1352
|
+
const fds = await readdir(`${procRoot}/${pid}/fd`);
|
|
1353
|
+
const inodes = new Set;
|
|
1354
|
+
for (const fd of fds) {
|
|
1355
|
+
const target = await readlink2(`${procRoot}/${pid}/fd/${fd}`).catch((cause) => {
|
|
1356
|
+
if (isProcessGoneError(cause))
|
|
1357
|
+
return null;
|
|
1358
|
+
throw cause;
|
|
1359
|
+
});
|
|
1360
|
+
if (target === null)
|
|
1361
|
+
continue;
|
|
1362
|
+
const matched = SOCKET_LINK_PATTERN.exec(target);
|
|
1363
|
+
if (matched?.[1] !== undefined)
|
|
1364
|
+
inodes.add(matched[1]);
|
|
1365
|
+
}
|
|
1366
|
+
return inodes;
|
|
1367
|
+
},
|
|
1368
|
+
async readSocketInodesAtPath(socketPath) {
|
|
1369
|
+
const abstract = socketPath.startsWith("@");
|
|
1370
|
+
const node = abstract ? null : await stat(socketPath, { bigint: true }).catch((cause) => {
|
|
1371
|
+
const code = errnoOf(cause);
|
|
1372
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
1373
|
+
return null;
|
|
1374
|
+
throw cause;
|
|
1375
|
+
});
|
|
1376
|
+
if (!abstract && !node?.isSocket())
|
|
1377
|
+
return new Set;
|
|
1378
|
+
const listed = await runNativeCommand2({
|
|
1379
|
+
executable: await resolveHostExecutable(ssCandidates),
|
|
1380
|
+
args: [...SS_UNIX_LISTENER_ARGS],
|
|
1381
|
+
envPolicy: "declared-only",
|
|
1382
|
+
capture: true,
|
|
1383
|
+
maxOutputBytes: SS_MAX_OUTPUT_BYTES,
|
|
1384
|
+
timeoutMs: SS_TIMEOUT_MS
|
|
1385
|
+
});
|
|
1386
|
+
if (listed.exitCode !== 0) {
|
|
1387
|
+
throw new Error(`ss ${SS_UNIX_LISTENER_ARGS.join(" ")} failed (exit ${listed.exitCode}): ${new TextDecoder().decode(listed.stderr).trim()}`);
|
|
1388
|
+
}
|
|
1389
|
+
const inodes = new Set;
|
|
1390
|
+
for (const entry of parseUnixSocketListeners(new TextDecoder().decode(listed.stdout))) {
|
|
1391
|
+
const at = node === null ? entry.name === socketPath : entry.node?.ino === node.ino && entry.node.dev === node.dev;
|
|
1392
|
+
if (at)
|
|
1393
|
+
inodes.add(entry.inode);
|
|
1394
|
+
}
|
|
1395
|
+
return inodes;
|
|
1396
|
+
}
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
function argvMatches(actual, expected, mode) {
|
|
1400
|
+
if (mode === "exact") {
|
|
1401
|
+
if (actual.length !== expected.length)
|
|
1402
|
+
return false;
|
|
1403
|
+
} else if (actual.length < expected.length) {
|
|
1404
|
+
return false;
|
|
1405
|
+
}
|
|
1406
|
+
for (let index = 0;index < expected.length; index += 1) {
|
|
1407
|
+
if (actual[index] !== expected[index])
|
|
1408
|
+
return false;
|
|
1409
|
+
}
|
|
1410
|
+
return true;
|
|
1411
|
+
}
|
|
1412
|
+
async function verifySupervisedProcess(options) {
|
|
1413
|
+
const pid = z.number().int().positive().max(MAX_PID).parse(options.pid);
|
|
1414
|
+
const recordedInstance = options.recordedInstance === undefined ? undefined : ProcessInstanceSchema2.parse(options.recordedInstance);
|
|
1415
|
+
const argvMatch = options.argvMatch ?? "exact";
|
|
1416
|
+
const adapter = options.adapter ?? createDefaultProcessIdentityAdapter();
|
|
1417
|
+
const before = await adapter.observeProcessInstance(pid);
|
|
1418
|
+
if (before.state === "unavailable") {
|
|
1419
|
+
return {
|
|
1420
|
+
status: "runtime-unavailable",
|
|
1421
|
+
reason: isProcessGoneError(before.cause) ? "process-gone" : "process-unobservable",
|
|
1422
|
+
pid,
|
|
1423
|
+
cause: before.cause
|
|
1424
|
+
};
|
|
1425
|
+
}
|
|
1426
|
+
if (recordedInstance !== undefined && !sameProcessInstance(recordedInstance, before.instance)) {
|
|
1427
|
+
return {
|
|
1428
|
+
status: "runtime-conflict",
|
|
1429
|
+
reason: "pid-reused",
|
|
1430
|
+
pid,
|
|
1431
|
+
expectedInstance: recordedInstance,
|
|
1432
|
+
actualInstance: before.instance
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
const targetInstance = recordedInstance ?? before.instance;
|
|
1436
|
+
let observedExe;
|
|
1437
|
+
if (options.expectedExe !== undefined) {
|
|
1438
|
+
try {
|
|
1439
|
+
observedExe = await adapter.readProcessExe(pid);
|
|
1440
|
+
} catch (cause) {
|
|
1441
|
+
return {
|
|
1442
|
+
status: "runtime-unavailable",
|
|
1443
|
+
reason: isProcessGoneError(cause) ? "process-gone" : "process-unobservable",
|
|
1444
|
+
pid,
|
|
1445
|
+
cause
|
|
1446
|
+
};
|
|
1447
|
+
}
|
|
1448
|
+
if (observedExe !== options.expectedExe && observedExe !== await adapter.resolveExecutablePath(options.expectedExe)) {
|
|
1449
|
+
const ownerNow = await adapter.probeProcessOwner(pid, targetInstance);
|
|
1450
|
+
const ownerFailure = classifyOwnerEvidence(pid, ownerNow);
|
|
1451
|
+
if (ownerFailure !== null)
|
|
1452
|
+
return ownerFailure;
|
|
1453
|
+
return {
|
|
1454
|
+
status: "runtime-conflict",
|
|
1455
|
+
reason: "exe-mismatch",
|
|
1456
|
+
pid,
|
|
1457
|
+
expectedExe: options.expectedExe,
|
|
1458
|
+
actualExe: observedExe
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
let observedArgv;
|
|
1463
|
+
if (options.expectedArgv !== undefined) {
|
|
1464
|
+
try {
|
|
1465
|
+
observedArgv = await adapter.readProcessArgv(pid);
|
|
1466
|
+
} catch (cause) {
|
|
1467
|
+
return {
|
|
1468
|
+
status: "runtime-unavailable",
|
|
1469
|
+
reason: isProcessGoneError(cause) ? "process-gone" : "process-unobservable",
|
|
1470
|
+
pid,
|
|
1471
|
+
cause
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
if (!argvMatches(observedArgv, options.expectedArgv, argvMatch)) {
|
|
1475
|
+
const ownerNow = await adapter.probeProcessOwner(pid, targetInstance);
|
|
1476
|
+
const ownerFailure = classifyOwnerEvidence(pid, ownerNow);
|
|
1477
|
+
if (ownerFailure !== null)
|
|
1478
|
+
return ownerFailure;
|
|
1479
|
+
return {
|
|
1480
|
+
status: "runtime-conflict",
|
|
1481
|
+
reason: "argv-mismatch",
|
|
1482
|
+
pid,
|
|
1483
|
+
expectedArgv: [...options.expectedArgv],
|
|
1484
|
+
actualArgv: observedArgv
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
let matchedSocketInode;
|
|
1489
|
+
let socketProcessInodes;
|
|
1490
|
+
if (options.socketPath !== undefined) {
|
|
1491
|
+
const socketCheck = await verifyUnixSocketOwnership(pid, options.socketPath, targetInstance, adapter);
|
|
1492
|
+
if (!socketCheck.ok)
|
|
1493
|
+
return socketCheck.failure;
|
|
1494
|
+
matchedSocketInode = socketCheck.inode;
|
|
1495
|
+
socketProcessInodes = socketCheck.processInodes;
|
|
1496
|
+
}
|
|
1497
|
+
const after = await adapter.probeProcessOwner(pid, targetInstance);
|
|
1498
|
+
const afterFailure = classifyOwnerEvidence(pid, after);
|
|
1499
|
+
if (afterFailure !== null)
|
|
1500
|
+
return afterFailure;
|
|
1501
|
+
if (options.socketPath !== undefined && matchedSocketInode !== undefined && socketProcessInodes !== undefined) {
|
|
1502
|
+
const confirmed = await confirmUnixSocketAfterProbe(pid, options.socketPath, matchedSocketInode, socketProcessInodes, targetInstance, adapter);
|
|
1503
|
+
if (!confirmed.ok)
|
|
1504
|
+
return confirmed.failure;
|
|
1505
|
+
matchedSocketInode = confirmed.inode;
|
|
1506
|
+
}
|
|
1507
|
+
return {
|
|
1508
|
+
status: "verified",
|
|
1509
|
+
pid,
|
|
1510
|
+
instance: targetInstance,
|
|
1511
|
+
exe: observedExe,
|
|
1512
|
+
argv: observedArgv,
|
|
1513
|
+
socketInode: matchedSocketInode
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
// src/service-host/launchd.ts
|
|
1517
|
+
var DEFAULT_PLIST_MODE = 420;
|
|
1518
|
+
var DEFAULT_STABILITY_MS = 5000;
|
|
1519
|
+
var DEFAULT_POLL_INTERVAL_MS = 250;
|
|
1520
|
+
var DEFAULT_STARTUP_TIMEOUT_MS = 1e4;
|
|
1521
|
+
var DEFAULT_BOOTOUT_SETTLE_TIMEOUT_MS = 5000;
|
|
1522
|
+
var MAX_WAIT_MS = 300000;
|
|
1523
|
+
var LAUNCHCTL_SERVICE_NOT_FOUND_EXIT = 113;
|
|
1524
|
+
function assertValidLaunchdTarget(label, uid) {
|
|
1525
|
+
if (label.length === 0 || label.includes("/") || label.includes("\\") || label.includes("\x00") || /\s/.test(label)) {
|
|
1526
|
+
throw new LaunchdJobError2("INVALID_CONFIG", `Invalid launchd label: ${JSON.stringify(label)}`);
|
|
1527
|
+
}
|
|
1528
|
+
if (!Number.isSafeInteger(uid) || uid < 0) {
|
|
1529
|
+
throw new LaunchdJobError2("INVALID_CONFIG", `Invalid launchd uid: ${uid}`);
|
|
1530
|
+
}
|
|
1531
|
+
const domain = `gui/${uid}`;
|
|
1532
|
+
return { domain, service: `${domain}/${label}` };
|
|
1533
|
+
}
|
|
1534
|
+
function assertLaunchdWaitMs(name, value, allowZero) {
|
|
1535
|
+
const min = allowZero ? 0 : 1;
|
|
1536
|
+
if (!Number.isSafeInteger(value) || value < min || value > MAX_WAIT_MS) {
|
|
1537
|
+
throw new LaunchdJobError2("INVALID_CONFIG", `Invalid ${name}: expected integer in [${min}, ${MAX_WAIT_MS}], got ${value}`);
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
async function inspectLaunchdJob(options) {
|
|
1541
|
+
const { service } = assertValidLaunchdTarget(options.label, options.uid);
|
|
1542
|
+
const adapter = options.adapter ?? createDefaultLaunchdHostAdapter2();
|
|
1543
|
+
const result = await adapter.runCommand(LAUNCHCTL_PATH, ["print", service]);
|
|
1544
|
+
if (result.exitCode !== 0 && result.exitCode !== LAUNCHCTL_SERVICE_NOT_FOUND_EXIT) {
|
|
1545
|
+
throw new LaunchdJobError2("COMMAND_FAILED", `launchctl print ${service} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
|
|
1546
|
+
}
|
|
1547
|
+
if (result.exitCode !== 0) {
|
|
1548
|
+
return {
|
|
1549
|
+
loaded: false,
|
|
1550
|
+
state: null,
|
|
1551
|
+
program: null,
|
|
1552
|
+
pid: null,
|
|
1553
|
+
path: null,
|
|
1554
|
+
lastExitCode: null
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
return parseLaunchctlPrint2(result.stdout);
|
|
1558
|
+
}
|
|
1559
|
+
async function bootoutAndSettle(label, uid, service, settleTimeoutMs, pollIntervalMs, adapter) {
|
|
1560
|
+
await adapter.runCommand(LAUNCHCTL_PATH, ["bootout", service]);
|
|
1561
|
+
const deadline = adapter.now() + settleTimeoutMs;
|
|
1562
|
+
for (;; ) {
|
|
1563
|
+
const inspected = await inspectLaunchdJob({ label, uid, adapter });
|
|
1564
|
+
if (!inspected.loaded)
|
|
1565
|
+
return;
|
|
1566
|
+
if (adapter.now() >= deadline) {
|
|
1567
|
+
throw new LaunchdJobError2("COMMAND_FAILED", `launchctl bootout did not unload ${service} within ${settleTimeoutMs}ms`);
|
|
1568
|
+
}
|
|
1569
|
+
await adapter.sleep(Math.min(pollIntervalMs, Math.max(1, deadline - adapter.now())));
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
async function bootoutLaunchdJob(options) {
|
|
1573
|
+
const { service } = assertValidLaunchdTarget(options.label, options.uid);
|
|
1574
|
+
const settleTimeoutMs = options.settleTimeoutMs ?? DEFAULT_BOOTOUT_SETTLE_TIMEOUT_MS;
|
|
1575
|
+
const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
1576
|
+
assertLaunchdWaitMs("settleTimeoutMs", settleTimeoutMs, false);
|
|
1577
|
+
assertLaunchdWaitMs("pollIntervalMs", pollIntervalMs, false);
|
|
1578
|
+
const adapter = options.adapter ?? createDefaultLaunchdHostAdapter2();
|
|
1579
|
+
await bootoutAndSettle(options.label, options.uid, service, settleTimeoutMs, pollIntervalMs, adapter);
|
|
1580
|
+
}
|
|
1581
|
+
async function waitForStableLaunchdJob(label, uid, expectedProgram, startupTimeoutMs, stabilityMs, pollIntervalMs, adapter) {
|
|
1582
|
+
const startDeadline = adapter.now() + startupTimeoutMs;
|
|
1583
|
+
let candidatePid = null;
|
|
1584
|
+
let observedProgram = null;
|
|
1585
|
+
for (;; ) {
|
|
1586
|
+
const inspected = await inspectLaunchdJob({ label, uid, adapter });
|
|
1587
|
+
if (inspected.loaded && expectedProgram !== undefined && inspected.program !== null) {
|
|
1588
|
+
if (inspected.program !== expectedProgram) {
|
|
1589
|
+
throw new LaunchdJobError2("PROGRAM_MISMATCH", `Loaded launchd program mismatch for ${label}: expected ${expectedProgram}, observed ${inspected.program}`);
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
if (inspected.loaded && inspected.pid !== null) {
|
|
1593
|
+
if (expectedProgram !== undefined && inspected.program !== expectedProgram) {
|
|
1594
|
+
throw new LaunchdJobError2("PROGRAM_MISMATCH", `Loaded launchd program missing or mismatched for ${label}: expected ${expectedProgram}, observed ${inspected.program ?? "none"}`);
|
|
1595
|
+
}
|
|
1596
|
+
candidatePid = inspected.pid;
|
|
1597
|
+
observedProgram = inspected.program;
|
|
1598
|
+
break;
|
|
1599
|
+
}
|
|
1600
|
+
if (adapter.now() >= startDeadline) {
|
|
1601
|
+
throw new LaunchdJobError2("START_TIMEOUT", `Launchd job ${label} did not start with a live PID within ${startupTimeoutMs}ms`);
|
|
1602
|
+
}
|
|
1603
|
+
await adapter.sleep(Math.min(pollIntervalMs, Math.max(1, startDeadline - adapter.now())));
|
|
1604
|
+
}
|
|
1605
|
+
const stableSince = adapter.now();
|
|
1606
|
+
const stableDeadline = stableSince + stabilityMs;
|
|
1607
|
+
while (adapter.now() < stableDeadline) {
|
|
1608
|
+
await adapter.sleep(Math.min(pollIntervalMs, Math.max(1, stableDeadline - adapter.now())));
|
|
1609
|
+
const inspected = await inspectLaunchdJob({ label, uid, adapter });
|
|
1610
|
+
if (!inspected.loaded || inspected.pid !== candidatePid || expectedProgram !== undefined && inspected.program !== expectedProgram) {
|
|
1611
|
+
throw new LaunchdJobError2("UNSTABLE_CANDIDATE", `Launchd job ${label} lost stability during ${stabilityMs}ms window (expected PID ${candidatePid}, observed ${inspected.pid ?? "none"})`);
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
return {
|
|
1615
|
+
pid: candidatePid,
|
|
1616
|
+
program: observedProgram,
|
|
1617
|
+
stableForMs: adapter.now() - stableSince
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
async function reloadLaunchdJob(options) {
|
|
1621
|
+
const { domain, service } = assertValidLaunchdTarget(options.label, options.uid);
|
|
1622
|
+
assertAbsolutePlistPath(options.plistPath);
|
|
1623
|
+
const stabilityMs = options.stabilityMs ?? DEFAULT_STABILITY_MS;
|
|
1624
|
+
const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
1625
|
+
const startupTimeoutMs = options.startupTimeoutMs ?? DEFAULT_STARTUP_TIMEOUT_MS;
|
|
1626
|
+
const bootoutSettleTimeoutMs = options.bootoutSettleTimeoutMs ?? DEFAULT_BOOTOUT_SETTLE_TIMEOUT_MS;
|
|
1627
|
+
const validatePlist = options.validatePlist ?? "plutil";
|
|
1628
|
+
assertLaunchdWaitMs("stabilityMs", stabilityMs, true);
|
|
1629
|
+
assertLaunchdWaitMs("pollIntervalMs", pollIntervalMs, false);
|
|
1630
|
+
assertLaunchdWaitMs("startupTimeoutMs", startupTimeoutMs, false);
|
|
1631
|
+
assertLaunchdWaitMs("bootoutSettleTimeoutMs", bootoutSettleTimeoutMs, false);
|
|
1632
|
+
if (validatePlist !== "plutil" && validatePlist !== "none") {
|
|
1633
|
+
throw new LaunchdJobError2("INVALID_CONFIG", `Invalid validatePlist mode: ${String(validatePlist)}`);
|
|
1634
|
+
}
|
|
1635
|
+
const adapter = options.adapter ?? createDefaultLaunchdHostAdapter2();
|
|
1636
|
+
if (validatePlist === "plutil") {
|
|
1637
|
+
await lintLaunchdPlist2({ content: options.content, adapter });
|
|
1638
|
+
}
|
|
1639
|
+
const declared = extractPlistLabel(options.content);
|
|
1640
|
+
if (declared !== options.label) {
|
|
1641
|
+
throw new LaunchdJobError2("INVALID_PLIST", declared === undefined ? `Plist for ${options.label} declares no Label` : `Plist declares Label ${declared}, but the job being reloaded is ${options.label}`);
|
|
1642
|
+
}
|
|
1643
|
+
const before = await inspectLaunchdJob({ label: options.label, uid: options.uid, adapter });
|
|
1644
|
+
if (before.loaded && (before.path === null || !await sameHostPath(adapter, before.path, options.plistPath))) {
|
|
1645
|
+
throw new LaunchdJobError2("FOREIGN_FRAGMENT", `Refusing to reload ${service}: launchd loaded it from ${before.path ?? "no plist"}, not ${options.plistPath}`, { rolledBack: false });
|
|
1646
|
+
}
|
|
1647
|
+
const standing = await adapter.inspectPath(options.plistPath);
|
|
1648
|
+
if (standing.kind === "symlink" || standing.kind === "other") {
|
|
1649
|
+
throw new LaunchdJobError2("FOREIGN_FRAGMENT", `Refusing to reload ${service}: ${options.plistPath} is ${standing.kind === "symlink" ? `a symbolic link to ${standing.target}` : "not a regular file"}, not a plist of ours to replace`, { rolledBack: false });
|
|
1650
|
+
}
|
|
1651
|
+
const wasLoaded = before.loaded;
|
|
1652
|
+
const previousBytes = await adapter.readFile(options.plistPath);
|
|
1653
|
+
const mode = options.mode ?? DEFAULT_PLIST_MODE;
|
|
1654
|
+
const previousMode = standing.kind === "file" ? standing.mode : mode;
|
|
1655
|
+
await adapter.writeFileAtomic(options.plistPath, options.content, { mode });
|
|
1656
|
+
let bootstrapped = false;
|
|
1657
|
+
try {
|
|
1658
|
+
await bootoutAndSettle(options.label, options.uid, service, bootoutSettleTimeoutMs, pollIntervalMs, adapter);
|
|
1659
|
+
bootstrapped = true;
|
|
1660
|
+
const result = await adapter.runCommand(LAUNCHCTL_PATH, [
|
|
1661
|
+
"bootstrap",
|
|
1662
|
+
domain,
|
|
1663
|
+
options.plistPath
|
|
1664
|
+
]);
|
|
1665
|
+
if (result.exitCode !== 0) {
|
|
1666
|
+
throw new LaunchdJobError2("COMMAND_FAILED", `launchctl bootstrap ${domain} ${options.plistPath} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
|
|
1667
|
+
}
|
|
1668
|
+
const settled = await waitForStableLaunchdJob(options.label, options.uid, options.expectedProgram, startupTimeoutMs, stabilityMs, pollIntervalMs, adapter);
|
|
1669
|
+
return {
|
|
1670
|
+
label: options.label,
|
|
1671
|
+
digest: computeSha256Hex(options.content),
|
|
1672
|
+
pid: settled.pid,
|
|
1673
|
+
program: settled.program,
|
|
1674
|
+
stableForMs: settled.stableForMs
|
|
1675
|
+
};
|
|
1676
|
+
} catch (cause) {
|
|
1677
|
+
let rolledBack = false;
|
|
1678
|
+
let rollbackError;
|
|
1679
|
+
try {
|
|
1680
|
+
if (bootstrapped) {
|
|
1681
|
+
await bootoutAndSettle(options.label, options.uid, service, bootoutSettleTimeoutMs, pollIntervalMs, adapter);
|
|
1682
|
+
}
|
|
1683
|
+
if (previousBytes !== null) {
|
|
1684
|
+
await adapter.writeFileAtomic(options.plistPath, previousBytes, {
|
|
1685
|
+
mode: previousMode
|
|
1686
|
+
});
|
|
1687
|
+
const inspected = await inspectLaunchdJob({
|
|
1688
|
+
label: options.label,
|
|
1689
|
+
uid: options.uid,
|
|
1690
|
+
adapter
|
|
1691
|
+
});
|
|
1692
|
+
if (wasLoaded && !inspected.loaded) {
|
|
1693
|
+
const restored = await adapter.runCommand(LAUNCHCTL_PATH, [
|
|
1694
|
+
"bootstrap",
|
|
1695
|
+
domain,
|
|
1696
|
+
options.plistPath
|
|
1697
|
+
]);
|
|
1698
|
+
if (restored.exitCode !== 0) {
|
|
1699
|
+
throw new Error(`Rollback launchctl bootstrap failed (exit ${restored.exitCode}): ${restored.stderr.trim()}`);
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
} else {
|
|
1703
|
+
await adapter.removeFile(options.plistPath);
|
|
1704
|
+
if (wasLoaded) {
|
|
1705
|
+
throw new Error(`${service} was loaded from ${options.plistPath}, which had no file: there is nothing to load it again from`);
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
const after = await inspectLaunchdJob({
|
|
1709
|
+
label: options.label,
|
|
1710
|
+
uid: options.uid,
|
|
1711
|
+
adapter
|
|
1712
|
+
});
|
|
1713
|
+
if (after.loaded !== wasLoaded) {
|
|
1714
|
+
throw new Error(`${service} is ${after.loaded ? "loaded" : "not loaded"} after rollback; it was ${wasLoaded ? "loaded" : "not loaded"}`);
|
|
1715
|
+
}
|
|
1716
|
+
rolledBack = true;
|
|
1717
|
+
} catch (rbError) {
|
|
1718
|
+
rollbackError = rbError;
|
|
1719
|
+
}
|
|
1720
|
+
const code = cause instanceof LaunchdJobError2 ? cause.code : "COMMAND_FAILED";
|
|
1721
|
+
const baseMessage = messageOf(cause);
|
|
1722
|
+
const message = !rolledBack && rollbackError !== undefined ? `${baseMessage}; rollback also failed: ${messageOf(rollbackError)}` : baseMessage;
|
|
1723
|
+
throw new LaunchdJobError2(code, message, { cause, rolledBack, rollbackError });
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
// src/service-host/systemd-inspect.ts
|
|
1727
|
+
import { readdir as readdir2 } from "node:fs/promises";
|
|
1728
|
+
import { dirname as dirname2, join as join3, posix } from "node:path";
|
|
1729
|
+
|
|
1730
|
+
// src/service-host/systemd-render.ts
|
|
1731
|
+
import { z as z2 } from "zod";
|
|
1732
|
+
var SystemdScopeSchema = z2.enum(["system", "user"]);
|
|
1733
|
+
|
|
1734
|
+
class SystemdUnitError extends Error {
|
|
1735
|
+
code;
|
|
1736
|
+
rolledBack;
|
|
1737
|
+
rollbackError;
|
|
1738
|
+
foreignDropIns;
|
|
1739
|
+
constructor(code, message, options) {
|
|
1740
|
+
super(message, options);
|
|
1741
|
+
this.name = "SystemdUnitError";
|
|
1742
|
+
this.code = code;
|
|
1743
|
+
this.rolledBack = options?.rolledBack ?? false;
|
|
1744
|
+
this.rollbackError = options?.rollbackError;
|
|
1745
|
+
this.foreignDropIns = options?.foreignDropIns;
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
var ENV_KEY_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
1749
|
+
var EXEC_PREFIX = /^[-@:+!]/;
|
|
1750
|
+
var EXEC_PREFIX_MESSAGE = "the executable must not start with one of systemd's prefixes (-, @, :, +, !): quoting does not disarm them";
|
|
1751
|
+
function hasLineBreakOrNul(value) {
|
|
1752
|
+
return value.includes(`
|
|
1753
|
+
`) || value.includes("\r") || value.includes("\x00");
|
|
1754
|
+
}
|
|
1755
|
+
function assertCleanValue(field, value) {
|
|
1756
|
+
if (hasLineBreakOrNul(value)) {
|
|
1757
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Systemd field '${field}' must not contain newline, carriage return, or NUL characters`);
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
function assertNoWhitespace(field, value) {
|
|
1761
|
+
if (/\s/.test(value)) {
|
|
1762
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Systemd field '${field}' must not contain whitespace: ${JSON.stringify(value)}`);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
function escapeSystemdSpecifiers(value, allowHomeSpecifier) {
|
|
1766
|
+
if (!allowHomeSpecifier)
|
|
1767
|
+
return value.replaceAll("%", "%%");
|
|
1768
|
+
let result = "";
|
|
1769
|
+
for (let index = 0;index < value.length; index += 1) {
|
|
1770
|
+
const ch = value[index];
|
|
1771
|
+
if (ch === "%") {
|
|
1772
|
+
const next = value[index + 1];
|
|
1773
|
+
if (next === "%") {
|
|
1774
|
+
result += "%%%%";
|
|
1775
|
+
index += 1;
|
|
1776
|
+
} else if (next === "h") {
|
|
1777
|
+
result += "%h";
|
|
1778
|
+
index += 1;
|
|
1779
|
+
} else {
|
|
1780
|
+
result += "%%";
|
|
1781
|
+
}
|
|
1782
|
+
} else {
|
|
1783
|
+
result += ch;
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
return result;
|
|
1787
|
+
}
|
|
1788
|
+
function formatSystemdExecToken(field, token, allowHomeSpecifier) {
|
|
1789
|
+
assertCleanValue(field, token);
|
|
1790
|
+
const specEscaped = escapeSystemdSpecifiers(token, allowHomeSpecifier);
|
|
1791
|
+
const safeDollar = specEscaped.replaceAll("$", "$$$$");
|
|
1792
|
+
const needsQuotes = token.length === 0 || /[\s"'\\;]/.test(token);
|
|
1793
|
+
if (!needsQuotes)
|
|
1794
|
+
return safeDollar;
|
|
1795
|
+
const quoted = safeDollar.replaceAll("\\", "\\\\").replaceAll('"', "\\\"");
|
|
1796
|
+
return `"${quoted}"`;
|
|
1797
|
+
}
|
|
1798
|
+
function formatSystemdExecLine(field, argv, allowHomeSpecifier) {
|
|
1799
|
+
return argv.map((token, index) => formatSystemdExecToken(`${field}[${index}]`, token, allowHomeSpecifier)).join(" ");
|
|
1800
|
+
}
|
|
1801
|
+
function formatSystemdEnvironmentLine(key, value, allowHomeSpecifier) {
|
|
1802
|
+
if (!ENV_KEY_PATTERN.test(key)) {
|
|
1803
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Invalid systemd environment variable name: ${JSON.stringify(key)}`);
|
|
1804
|
+
}
|
|
1805
|
+
assertCleanValue(`environment.${key}`, value);
|
|
1806
|
+
const specEscaped = escapeSystemdSpecifiers(value, allowHomeSpecifier);
|
|
1807
|
+
const quoted = specEscaped.replaceAll("\\", "\\\\").replaceAll('"', "\\\"");
|
|
1808
|
+
return `Environment="${key}=${quoted}"`;
|
|
1809
|
+
}
|
|
1810
|
+
function formatSystemdScalar(field, value, allowHomeSpecifier, forbidWhitespace = false) {
|
|
1811
|
+
assertCleanValue(field, value);
|
|
1812
|
+
if (value.endsWith("\\")) {
|
|
1813
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Systemd field '${field}' must not end with a trailing backslash (line continuation)`);
|
|
1814
|
+
}
|
|
1815
|
+
if (forbidWhitespace)
|
|
1816
|
+
assertNoWhitespace(field, value);
|
|
1817
|
+
return escapeSystemdSpecifiers(value, allowHomeSpecifier);
|
|
1818
|
+
}
|
|
1819
|
+
var SystemdServiceUnitConfigSchema = z2.strictObject({
|
|
1820
|
+
description: z2.string().min(1),
|
|
1821
|
+
scope: SystemdScopeSchema.default("system"),
|
|
1822
|
+
execStart: z2.array(z2.string()).min(1),
|
|
1823
|
+
execStartPre: z2.array(z2.array(z2.string()).min(1)).optional(),
|
|
1824
|
+
workingDirectory: z2.string().min(1).optional(),
|
|
1825
|
+
environment: z2.record(z2.string(), z2.string()).optional(),
|
|
1826
|
+
environmentFile: z2.union([z2.string().min(1), z2.array(z2.string().min(1))]).optional(),
|
|
1827
|
+
user: z2.string().min(1).optional(),
|
|
1828
|
+
group: z2.string().min(1).optional(),
|
|
1829
|
+
type: z2.enum(["simple", "exec", "forking", "oneshot", "notify"]).optional(),
|
|
1830
|
+
restart: z2.enum([
|
|
1831
|
+
"no",
|
|
1832
|
+
"on-success",
|
|
1833
|
+
"on-failure",
|
|
1834
|
+
"on-abnormal",
|
|
1835
|
+
"on-watchdog",
|
|
1836
|
+
"on-abort",
|
|
1837
|
+
"always"
|
|
1838
|
+
]).default("on-failure"),
|
|
1839
|
+
restartSec: z2.union([z2.number().nonnegative(), z2.string().min(1)]).optional(),
|
|
1840
|
+
timeoutStopSec: z2.union([z2.number().positive(), z2.string().min(1)]).optional(),
|
|
1841
|
+
killMode: z2.enum(["control-group", "mixed", "process", "none"]).optional(),
|
|
1842
|
+
oomScoreAdjust: z2.number().int().min(-1000).max(1000).optional(),
|
|
1843
|
+
oomPolicy: z2.enum(["continue", "stop", "kill"]).optional(),
|
|
1844
|
+
ioAccounting: z2.boolean().optional(),
|
|
1845
|
+
umask: z2.string().regex(/^0?[0-7]{3,4}$/).optional(),
|
|
1846
|
+
noNewPrivileges: z2.boolean().optional(),
|
|
1847
|
+
runtimeDirectory: z2.union([z2.string().min(1), z2.array(z2.string().min(1))]).optional(),
|
|
1848
|
+
limitNOFILE: z2.union([z2.number().int().positive(), z2.literal("infinity")]).optional(),
|
|
1849
|
+
after: z2.array(z2.string().min(1)).optional(),
|
|
1850
|
+
wants: z2.array(z2.string().min(1)).optional(),
|
|
1851
|
+
wantedBy: z2.array(z2.string().min(1)).optional(),
|
|
1852
|
+
allowHomeSpecifier: z2.boolean().default(false)
|
|
1853
|
+
}).check((ctx) => {
|
|
1854
|
+
const value = ctx.value;
|
|
1855
|
+
if ((value.execStart[0] ?? "").length === 0) {
|
|
1856
|
+
ctx.issues.push({
|
|
1857
|
+
code: "custom",
|
|
1858
|
+
input: value.execStart,
|
|
1859
|
+
path: ["execStart", 0],
|
|
1860
|
+
message: "execStart[0] must be a non-empty executable path"
|
|
1861
|
+
});
|
|
1862
|
+
} else if (EXEC_PREFIX.test(value.execStart[0] ?? "")) {
|
|
1863
|
+
ctx.issues.push({
|
|
1864
|
+
code: "custom",
|
|
1865
|
+
input: value.execStart,
|
|
1866
|
+
path: ["execStart", 0],
|
|
1867
|
+
message: EXEC_PREFIX_MESSAGE
|
|
1868
|
+
});
|
|
1869
|
+
}
|
|
1870
|
+
if (value.execStartPre !== undefined) {
|
|
1871
|
+
for (let index = 0;index < value.execStartPre.length; index += 1) {
|
|
1872
|
+
const cmd = value.execStartPre[index];
|
|
1873
|
+
if ((cmd?.[0] ?? "").length === 0) {
|
|
1874
|
+
ctx.issues.push({
|
|
1875
|
+
code: "custom",
|
|
1876
|
+
input: cmd,
|
|
1877
|
+
path: ["execStartPre", index, 0],
|
|
1878
|
+
message: `execStartPre[${index}][0] must be a non-empty executable path`
|
|
1879
|
+
});
|
|
1880
|
+
} else if (EXEC_PREFIX.test(cmd?.[0] ?? "")) {
|
|
1881
|
+
ctx.issues.push({
|
|
1882
|
+
code: "custom",
|
|
1883
|
+
input: cmd,
|
|
1884
|
+
path: ["execStartPre", index, 0],
|
|
1885
|
+
message: EXEC_PREFIX_MESSAGE
|
|
1886
|
+
});
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
if (value.scope === "user" && (value.user !== undefined || value.group !== undefined)) {
|
|
1891
|
+
ctx.issues.push({
|
|
1892
|
+
code: "custom",
|
|
1893
|
+
input: value,
|
|
1894
|
+
path: ["scope"],
|
|
1895
|
+
message: "systemd user units cannot declare 'user' or 'group'"
|
|
1896
|
+
});
|
|
1897
|
+
}
|
|
1898
|
+
});
|
|
1899
|
+
function toStringList(value) {
|
|
1900
|
+
if (value === undefined)
|
|
1901
|
+
return [];
|
|
1902
|
+
return typeof value === "string" ? [value] : value;
|
|
1903
|
+
}
|
|
1904
|
+
function renderSystemdServiceUnit(config) {
|
|
1905
|
+
const parsedResult = SystemdServiceUnitConfigSchema.safeParse(config);
|
|
1906
|
+
if (!parsedResult.success) {
|
|
1907
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Invalid systemd unit configuration: ${parsedResult.error.message}`, { cause: parsedResult.error });
|
|
1908
|
+
}
|
|
1909
|
+
const parsed = parsedResult.data;
|
|
1910
|
+
const allowHome = parsed.allowHomeSpecifier;
|
|
1911
|
+
const unitLines = [
|
|
1912
|
+
"[Unit]",
|
|
1913
|
+
`Description=${formatSystemdScalar("description", parsed.description, allowHome)}`
|
|
1914
|
+
];
|
|
1915
|
+
if (parsed.after && parsed.after.length > 0) {
|
|
1916
|
+
const items = parsed.after.map((item, i) => formatSystemdScalar(`after[${i}]`, item, false, true));
|
|
1917
|
+
unitLines.push(`After=${items.join(" ")}`);
|
|
1918
|
+
}
|
|
1919
|
+
if (parsed.wants && parsed.wants.length > 0) {
|
|
1920
|
+
const items = parsed.wants.map((item, i) => formatSystemdScalar(`wants[${i}]`, item, false, true));
|
|
1921
|
+
unitLines.push(`Wants=${items.join(" ")}`);
|
|
1922
|
+
}
|
|
1923
|
+
const serviceLines = ["[Service]"];
|
|
1924
|
+
if (parsed.type !== undefined)
|
|
1925
|
+
serviceLines.push(`Type=${parsed.type}`);
|
|
1926
|
+
if (parsed.user !== undefined) {
|
|
1927
|
+
serviceLines.push(`User=${formatSystemdScalar("user", parsed.user, false, true)}`);
|
|
1928
|
+
}
|
|
1929
|
+
if (parsed.group !== undefined) {
|
|
1930
|
+
serviceLines.push(`Group=${formatSystemdScalar("group", parsed.group, false, true)}`);
|
|
1931
|
+
}
|
|
1932
|
+
if (parsed.workingDirectory !== undefined) {
|
|
1933
|
+
serviceLines.push(`WorkingDirectory=${formatSystemdScalar("workingDirectory", parsed.workingDirectory, allowHome)}`);
|
|
1934
|
+
}
|
|
1935
|
+
if (parsed.runtimeDirectory !== undefined) {
|
|
1936
|
+
const dirs = toStringList(parsed.runtimeDirectory).map((dir, i) => formatSystemdScalar(`runtimeDirectory[${i}]`, dir, false, true));
|
|
1937
|
+
if (dirs.length > 0)
|
|
1938
|
+
serviceLines.push(`RuntimeDirectory=${dirs.join(" ")}`);
|
|
1939
|
+
}
|
|
1940
|
+
for (const [index, envFile] of toStringList(parsed.environmentFile).entries()) {
|
|
1941
|
+
serviceLines.push(`EnvironmentFile=${formatSystemdScalar(`environmentFile[${index}]`, envFile, allowHome)}`);
|
|
1942
|
+
}
|
|
1943
|
+
if (parsed.environment !== undefined) {
|
|
1944
|
+
const sortedKeys = Object.keys(parsed.environment).sort();
|
|
1945
|
+
for (const key of sortedKeys) {
|
|
1946
|
+
const value = parsed.environment[key];
|
|
1947
|
+
if (value !== undefined) {
|
|
1948
|
+
serviceLines.push(formatSystemdEnvironmentLine(key, value, allowHome));
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
if (parsed.execStartPre !== undefined) {
|
|
1953
|
+
for (const [index, cmd] of parsed.execStartPre.entries()) {
|
|
1954
|
+
serviceLines.push(`ExecStartPre=${formatSystemdExecLine(`execStartPre[${index}]`, cmd, allowHome)}`);
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
serviceLines.push(`ExecStart=${formatSystemdExecLine("execStart", parsed.execStart, allowHome)}`);
|
|
1958
|
+
serviceLines.push(`Restart=${parsed.restart}`);
|
|
1959
|
+
if (parsed.restartSec !== undefined) {
|
|
1960
|
+
const text = String(parsed.restartSec);
|
|
1961
|
+
serviceLines.push(`RestartSec=${formatSystemdScalar("restartSec", text, false, true)}`);
|
|
1962
|
+
}
|
|
1963
|
+
if (parsed.timeoutStopSec !== undefined) {
|
|
1964
|
+
const text = String(parsed.timeoutStopSec);
|
|
1965
|
+
serviceLines.push(`TimeoutStopSec=${formatSystemdScalar("timeoutStopSec", text, false, true)}`);
|
|
1966
|
+
}
|
|
1967
|
+
if (parsed.killMode !== undefined)
|
|
1968
|
+
serviceLines.push(`KillMode=${parsed.killMode}`);
|
|
1969
|
+
if (parsed.oomScoreAdjust !== undefined) {
|
|
1970
|
+
serviceLines.push(`OOMScoreAdjust=${parsed.oomScoreAdjust}`);
|
|
1971
|
+
}
|
|
1972
|
+
if (parsed.oomPolicy !== undefined)
|
|
1973
|
+
serviceLines.push(`OOMPolicy=${parsed.oomPolicy}`);
|
|
1974
|
+
if (parsed.ioAccounting !== undefined) {
|
|
1975
|
+
serviceLines.push(`IOAccounting=${parsed.ioAccounting ? "yes" : "no"}`);
|
|
1976
|
+
}
|
|
1977
|
+
if (parsed.umask !== undefined)
|
|
1978
|
+
serviceLines.push(`UMask=${parsed.umask}`);
|
|
1979
|
+
if (parsed.noNewPrivileges !== undefined) {
|
|
1980
|
+
serviceLines.push(`NoNewPrivileges=${parsed.noNewPrivileges ? "yes" : "no"}`);
|
|
1981
|
+
}
|
|
1982
|
+
if (parsed.limitNOFILE !== undefined) {
|
|
1983
|
+
serviceLines.push(`LimitNOFILE=${parsed.limitNOFILE}`);
|
|
1984
|
+
}
|
|
1985
|
+
const wantedBy = parsed.wantedBy ?? (parsed.scope === "user" ? ["default.target"] : ["multi-user.target"]);
|
|
1986
|
+
const installLines = ["[Install]"];
|
|
1987
|
+
if (wantedBy.length > 0) {
|
|
1988
|
+
const targets = wantedBy.map((item, i) => formatSystemdScalar(`wantedBy[${i}]`, item, false, true));
|
|
1989
|
+
installLines.push(`WantedBy=${targets.join(" ")}`);
|
|
1990
|
+
}
|
|
1991
|
+
return `${unitLines.join(`
|
|
1992
|
+
`)}
|
|
1993
|
+
|
|
1994
|
+
${serviceLines.join(`
|
|
1995
|
+
`)}
|
|
1996
|
+
|
|
1997
|
+
${installLines.join(`
|
|
1998
|
+
`)}
|
|
1999
|
+
`;
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
// src/service-host/systemd-inspect.ts
|
|
2003
|
+
var DEFAULT_SYSTEMD_UNIT_MODE = 420;
|
|
2004
|
+
var SYSTEMCTL_PATH = "/usr/bin/systemctl";
|
|
2005
|
+
var SHOW_PROPERTIES = "LoadState,FragmentPath,DropInPaths,ActiveState,SubState,MainPID,UnitFileState";
|
|
2006
|
+
var SHA256_HEX_PATTERN = /^[0-9a-f]{64}$/;
|
|
2007
|
+
function createDefaultSystemdHostAdapter() {
|
|
2008
|
+
return {
|
|
2009
|
+
...createBaseServiceHostAdapter({
|
|
2010
|
+
defaultFileMode: DEFAULT_SYSTEMD_UNIT_MODE,
|
|
2011
|
+
nullOnNonRegularFile: true
|
|
2012
|
+
}),
|
|
2013
|
+
async listDir(path) {
|
|
2014
|
+
try {
|
|
2015
|
+
return await readdir2(path);
|
|
2016
|
+
} catch (cause) {
|
|
2017
|
+
if (errnoOf(cause) === "ENOENT")
|
|
2018
|
+
return null;
|
|
2019
|
+
throw cause;
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
};
|
|
2023
|
+
}
|
|
2024
|
+
function hasAsciiControlChar(value) {
|
|
2025
|
+
for (let index = 0;index < value.length; index += 1) {
|
|
2026
|
+
const code = value.charCodeAt(index);
|
|
2027
|
+
if (code <= 31 || code === 127)
|
|
2028
|
+
return true;
|
|
2029
|
+
}
|
|
2030
|
+
return false;
|
|
2031
|
+
}
|
|
2032
|
+
function assertValidSystemdUnitName(unitName) {
|
|
2033
|
+
if (unitName.length === 0 || unitName === "." || unitName.startsWith("-") || unitName.includes("/") || unitName.includes("\\") || unitName.includes("..") || /\s/.test(unitName) || hasAsciiControlChar(unitName)) {
|
|
2034
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Invalid systemd unit name: ${JSON.stringify(unitName)}`);
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
function assertSystemdUnitPath(unitPath) {
|
|
2038
|
+
if (!isAbsoluteNormalPath(unitPath)) {
|
|
2039
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Unit path must be an absolute, normal path without NUL bytes: ${JSON.stringify(unitPath)}`);
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
function systemdScopeArgs(scope, args) {
|
|
2043
|
+
const parsed = SystemdScopeSchema.parse(scope);
|
|
2044
|
+
return parsed === "user" ? ["--user", ...args] : [...args];
|
|
2045
|
+
}
|
|
2046
|
+
function parseSystemdProperties(stdout) {
|
|
2047
|
+
const map = new Map;
|
|
2048
|
+
for (const rawLine of stdout.split(`
|
|
2049
|
+
`)) {
|
|
2050
|
+
const line = rawLine.trimEnd();
|
|
2051
|
+
const eq = line.indexOf("=");
|
|
2052
|
+
if (eq <= 0)
|
|
2053
|
+
continue;
|
|
2054
|
+
map.set(line.slice(0, eq), line.slice(eq + 1));
|
|
2055
|
+
}
|
|
2056
|
+
return map;
|
|
2057
|
+
}
|
|
2058
|
+
function parseMainPid(raw) {
|
|
2059
|
+
if (!raw)
|
|
2060
|
+
return null;
|
|
2061
|
+
const trimmed = raw.trim();
|
|
2062
|
+
if (!/^\d+$/.test(trimmed))
|
|
2063
|
+
return null;
|
|
2064
|
+
const pid = Number(trimmed);
|
|
2065
|
+
return Number.isSafeInteger(pid) && pid > 0 ? pid : null;
|
|
2066
|
+
}
|
|
2067
|
+
function parseUnitPathDirs(stdout) {
|
|
2068
|
+
const trimmed = stdout.trim();
|
|
2069
|
+
if (trimmed.length === 0)
|
|
2070
|
+
return [];
|
|
2071
|
+
const raw = trimmed.startsWith("UnitPath=") ? trimmed.slice("UnitPath=".length) : trimmed;
|
|
2072
|
+
return raw.split(/\s+/).map((entry) => entry.trim()).filter((entry) => entry.startsWith("/"));
|
|
2073
|
+
}
|
|
2074
|
+
function normalizePosixDir(dir) {
|
|
2075
|
+
const normalized = posix.normalize(dir);
|
|
2076
|
+
return normalized.length > 1 && normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
|
|
2077
|
+
}
|
|
2078
|
+
function isAllowedHostServiceDropIn(unitName, dropInPath, trustedSearchDirs) {
|
|
2079
|
+
if (!unitName.endsWith(".service"))
|
|
2080
|
+
return false;
|
|
2081
|
+
if (!dropInPath.startsWith("/"))
|
|
2082
|
+
return false;
|
|
2083
|
+
if (dropInPath.includes(".."))
|
|
2084
|
+
return false;
|
|
2085
|
+
if (posix.normalize(dropInPath) !== dropInPath)
|
|
2086
|
+
return false;
|
|
2087
|
+
if (!dropInPath.endsWith(".conf"))
|
|
2088
|
+
return false;
|
|
2089
|
+
const parentDir = posix.dirname(dropInPath);
|
|
2090
|
+
if (posix.basename(parentDir) !== "service.d")
|
|
2091
|
+
return false;
|
|
2092
|
+
const grandParentDir = posix.dirname(parentDir);
|
|
2093
|
+
return trustedSearchDirs.has(grandParentDir);
|
|
2094
|
+
}
|
|
2095
|
+
function templateUnitNameOf(unitName) {
|
|
2096
|
+
const atIndex = unitName.indexOf("@");
|
|
2097
|
+
if (atIndex <= 0)
|
|
2098
|
+
return null;
|
|
2099
|
+
const dotIndex = unitName.lastIndexOf(".");
|
|
2100
|
+
if (dotIndex <= atIndex + 1)
|
|
2101
|
+
return null;
|
|
2102
|
+
return `${unitName.slice(0, atIndex + 1)}${unitName.slice(dotIndex)}`;
|
|
2103
|
+
}
|
|
2104
|
+
async function resolveUnitSearchDirs(unitPath, scope, extraSearchDirs, adapter) {
|
|
2105
|
+
const searchDirs = new Set([
|
|
2106
|
+
dirname2(unitPath),
|
|
2107
|
+
dirname2(await adapter.canonicalPath(unitPath))
|
|
2108
|
+
]);
|
|
2109
|
+
const unitPathResult = await adapter.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(scope, ["show", "--no-pager", "--property=UnitPath", "--value"]));
|
|
2110
|
+
if (unitPathResult.exitCode !== 0) {
|
|
2111
|
+
throw new SystemdUnitError("COMMAND_FAILED", `systemctl show --property=UnitPath failed (exit ${unitPathResult.exitCode}): ${unitPathResult.stderr.trim()}`);
|
|
2112
|
+
}
|
|
2113
|
+
const managerDirs = parseUnitPathDirs(unitPathResult.stdout);
|
|
2114
|
+
if (managerDirs.length > 0) {
|
|
2115
|
+
for (const dir of managerDirs)
|
|
2116
|
+
searchDirs.add(dir);
|
|
2117
|
+
} else if (scope === "system") {
|
|
2118
|
+
searchDirs.add("/etc/systemd/system");
|
|
2119
|
+
searchDirs.add("/run/systemd/system");
|
|
2120
|
+
}
|
|
2121
|
+
for (const dir of extraSearchDirs ?? [])
|
|
2122
|
+
searchDirs.add(dir);
|
|
2123
|
+
return [...searchDirs];
|
|
2124
|
+
}
|
|
2125
|
+
async function collectForeignDropIns(unitName, unitPath, scope, dropInPathsProp, extraSearchDirs, adapter) {
|
|
2126
|
+
const searchDirs = await resolveUnitSearchDirs(unitPath, scope, extraSearchDirs, adapter);
|
|
2127
|
+
const trustedSearchDirs = new Set(searchDirs.map(normalizePosixDir));
|
|
2128
|
+
const found = new Set;
|
|
2129
|
+
if (dropInPathsProp) {
|
|
2130
|
+
for (const token of dropInPathsProp.trim().split(/\s+/)) {
|
|
2131
|
+
if (token.length === 0)
|
|
2132
|
+
continue;
|
|
2133
|
+
if (isAllowedHostServiceDropIn(unitName, token, trustedSearchDirs))
|
|
2134
|
+
continue;
|
|
2135
|
+
found.add(token);
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
const templateUnitName = templateUnitNameOf(unitName);
|
|
2139
|
+
const dropInDirNames = templateUnitName !== null ? [`${unitName}.d`, `${templateUnitName}.d`] : [`${unitName}.d`];
|
|
2140
|
+
for (const dir of searchDirs) {
|
|
2141
|
+
for (const dropInDirName of dropInDirNames) {
|
|
2142
|
+
const dropInDir = join3(dir, dropInDirName);
|
|
2143
|
+
const entries = await adapter.listDir(dropInDir);
|
|
2144
|
+
if (!entries)
|
|
2145
|
+
continue;
|
|
2146
|
+
for (const entry of entries) {
|
|
2147
|
+
if (entry.endsWith(".conf"))
|
|
2148
|
+
found.add(join3(dropInDir, entry));
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
return [...found].sort();
|
|
2153
|
+
}
|
|
2154
|
+
function foreignUnitSource(check, unitPath) {
|
|
2155
|
+
if (check.loadState === "masked")
|
|
2156
|
+
return "the unit is masked";
|
|
2157
|
+
if (check.loadState === "not-found" || check.fragmentIsUnitPath)
|
|
2158
|
+
return;
|
|
2159
|
+
if (check.loadState === null)
|
|
2160
|
+
return "systemctl show reported no LoadState";
|
|
2161
|
+
if (check.fragmentPath === null) {
|
|
2162
|
+
return `systemd has it ${check.loadState} with no unit file`;
|
|
2163
|
+
}
|
|
2164
|
+
return `systemd loads it from ${check.fragmentPath}, not ${unitPath}`;
|
|
2165
|
+
}
|
|
2166
|
+
function resolveExpectedDigest(options) {
|
|
2167
|
+
const hasContent = options.expectedContent !== undefined;
|
|
2168
|
+
const hasDigest = options.expectedDigest !== undefined;
|
|
2169
|
+
if (hasContent === hasDigest) {
|
|
2170
|
+
throw new SystemdUnitError("INVALID_CONFIG", "checkSystemdUnit requires exactly one of expectedContent or expectedDigest");
|
|
2171
|
+
}
|
|
2172
|
+
if (options.expectedDigest !== undefined) {
|
|
2173
|
+
if (!SHA256_HEX_PATTERN.test(options.expectedDigest)) {
|
|
2174
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Invalid expectedDigest: expected 64 lowercase hex characters, got ${JSON.stringify(options.expectedDigest)}`);
|
|
2175
|
+
}
|
|
2176
|
+
return options.expectedDigest;
|
|
2177
|
+
}
|
|
2178
|
+
return computeSha256Hex(options.expectedContent ?? "");
|
|
2179
|
+
}
|
|
2180
|
+
async function checkSystemdUnit(options) {
|
|
2181
|
+
assertValidSystemdUnitName(options.unitName);
|
|
2182
|
+
assertSystemdUnitPath(options.unitPath);
|
|
2183
|
+
const expectedDigest = resolveExpectedDigest(options);
|
|
2184
|
+
const adapter = options.adapter ?? createDefaultSystemdHostAdapter();
|
|
2185
|
+
const existingBytes = await adapter.readFile(options.unitPath);
|
|
2186
|
+
const actualDigest = existingBytes === null ? null : computeSha256Hex(existingBytes);
|
|
2187
|
+
const showResult = await adapter.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(options.scope, [
|
|
2188
|
+
"show",
|
|
2189
|
+
"--no-pager",
|
|
2190
|
+
`--property=${SHOW_PROPERTIES}`,
|
|
2191
|
+
"--",
|
|
2192
|
+
options.unitName
|
|
2193
|
+
]));
|
|
2194
|
+
if (showResult.exitCode !== 0) {
|
|
2195
|
+
throw new SystemdUnitError("COMMAND_FAILED", `systemctl show failed for ${options.unitName} (exit ${showResult.exitCode}): ${showResult.stderr.trim()}`);
|
|
2196
|
+
}
|
|
2197
|
+
const props = parseSystemdProperties(showResult.stdout);
|
|
2198
|
+
const loadState = props.get("LoadState") || null;
|
|
2199
|
+
const fragmentPath = props.get("FragmentPath") || null;
|
|
2200
|
+
const fragmentIsUnitPath = fragmentPath !== null && await sameHostPath(adapter, fragmentPath, options.unitPath);
|
|
2201
|
+
const activeState = props.get("ActiveState") || null;
|
|
2202
|
+
const mainPid = parseMainPid(props.get("MainPID"));
|
|
2203
|
+
const unitFileState = props.get("UnitFileState") || null;
|
|
2204
|
+
const foreignDropIns = await collectForeignDropIns(options.unitName, options.unitPath, options.scope, props.get("DropInPaths"), options.unitSearchDirs, adapter);
|
|
2205
|
+
let status;
|
|
2206
|
+
if (foreignDropIns.length > 0)
|
|
2207
|
+
status = "foreign-drop-in";
|
|
2208
|
+
else if (loadState === "masked")
|
|
2209
|
+
status = "fragment-mismatch";
|
|
2210
|
+
else if (actualDigest === null) {
|
|
2211
|
+
status = foreignUnitSource({ loadState, fragmentPath, fragmentIsUnitPath }, options.unitPath) === undefined ? "missing" : "fragment-mismatch";
|
|
2212
|
+
} else if (actualDigest !== expectedDigest)
|
|
2213
|
+
status = "digest-mismatch";
|
|
2214
|
+
else if (loadState !== "loaded" || !fragmentIsUnitPath) {
|
|
2215
|
+
status = "fragment-mismatch";
|
|
2216
|
+
} else
|
|
2217
|
+
status = "matches";
|
|
2218
|
+
return {
|
|
2219
|
+
ok: status === "matches",
|
|
2220
|
+
status,
|
|
2221
|
+
expectedDigest,
|
|
2222
|
+
actualDigest,
|
|
2223
|
+
loadState,
|
|
2224
|
+
fragmentPath,
|
|
2225
|
+
fragmentIsUnitPath,
|
|
2226
|
+
foreignDropIns,
|
|
2227
|
+
activeState,
|
|
2228
|
+
mainPid,
|
|
2229
|
+
unitFileState
|
|
2230
|
+
};
|
|
2231
|
+
}
|
|
2232
|
+
async function systemdUnitActive(options) {
|
|
2233
|
+
assertValidSystemdUnitName(options.unitName);
|
|
2234
|
+
const adapter = options.adapter ?? createDefaultSystemdHostAdapter();
|
|
2235
|
+
const result = await adapter.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(options.scope, ["is-active", "--", options.unitName]));
|
|
2236
|
+
return result.exitCode === 0 && result.stdout.trim() === "active";
|
|
2237
|
+
}
|
|
2238
|
+
async function systemdMainPid(options) {
|
|
2239
|
+
assertValidSystemdUnitName(options.unitName);
|
|
2240
|
+
const adapter = options.adapter ?? createDefaultSystemdHostAdapter();
|
|
2241
|
+
const result = await adapter.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(options.scope, [
|
|
2242
|
+
"show",
|
|
2243
|
+
"--no-pager",
|
|
2244
|
+
"--property=MainPID",
|
|
2245
|
+
"--value",
|
|
2246
|
+
"--",
|
|
2247
|
+
options.unitName
|
|
2248
|
+
]));
|
|
2249
|
+
if (result.exitCode !== 0)
|
|
2250
|
+
return null;
|
|
2251
|
+
return parseMainPid(result.stdout);
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
// src/service-host/systemd-links.ts
|
|
2255
|
+
import { basename, join as join4 } from "node:path";
|
|
2256
|
+
var LINK_DIR_SUFFIXES = [".wants", ".requires", ".upholds"];
|
|
2257
|
+
var ALSO_LINE = /^[ \t]*Also[ \t]*=(.*)$/;
|
|
2258
|
+
function enablementNamesOf(unitName, unitPath, contents) {
|
|
2259
|
+
const names = new Set([unitName, basename(unitPath)]);
|
|
2260
|
+
for (const content of contents) {
|
|
2261
|
+
let install = false;
|
|
2262
|
+
for (const raw of content.split(`
|
|
2263
|
+
`)) {
|
|
2264
|
+
const line = raw.trim();
|
|
2265
|
+
if (line.startsWith("["))
|
|
2266
|
+
install = line === "[Install]";
|
|
2267
|
+
const also = install ? ALSO_LINE.exec(line) : null;
|
|
2268
|
+
for (const name of also?.[1]?.split(/\s+/) ?? [])
|
|
2269
|
+
if (name.length > 0)
|
|
2270
|
+
names.add(name);
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
return names;
|
|
2274
|
+
}
|
|
2275
|
+
async function readEnablementLinks(adapter, dirs, names) {
|
|
2276
|
+
const links = new Map;
|
|
2277
|
+
const take = async (path, name) => {
|
|
2278
|
+
const standing = await adapter.inspectPath(path);
|
|
2279
|
+
if (standing.kind !== "symlink")
|
|
2280
|
+
return;
|
|
2281
|
+
if (names.has(name) || names.has(basename(standing.target)))
|
|
2282
|
+
links.set(path, standing.target);
|
|
2283
|
+
};
|
|
2284
|
+
for (const dir of dirs) {
|
|
2285
|
+
for (const entry of await adapter.listDir(dir) ?? []) {
|
|
2286
|
+
const path = join4(dir, entry);
|
|
2287
|
+
if (LINK_DIR_SUFFIXES.some((suffix) => entry.endsWith(suffix))) {
|
|
2288
|
+
for (const child of await adapter.listDir(path) ?? [])
|
|
2289
|
+
await take(join4(path, child), child);
|
|
2290
|
+
} else {
|
|
2291
|
+
await take(path, entry);
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
return links;
|
|
2296
|
+
}
|
|
2297
|
+
async function restoreEnablementLinks(adapter, unitName, before, now) {
|
|
2298
|
+
const changed = [...before].filter(([path, target]) => now.get(path) !== target);
|
|
2299
|
+
if (changed.length > 0) {
|
|
2300
|
+
throw new SystemdUnitError("COMMAND_FAILED", `cannot put back the enable links of ${unitName}: ${changed.map(([path, target]) => `${path} -> ${target}`).join(", ")} changed during the apply`);
|
|
2301
|
+
}
|
|
2302
|
+
const added = [...now.keys()].filter((path) => !before.has(path));
|
|
2303
|
+
for (const path of added)
|
|
2304
|
+
await adapter.removeFile(path);
|
|
2305
|
+
return added.length > 0;
|
|
2306
|
+
}
|
|
2307
|
+
function differentLinks(a, b) {
|
|
2308
|
+
const paths = new Set([...a.keys(), ...b.keys()]);
|
|
2309
|
+
return [...paths].filter((path) => a.get(path) !== b.get(path)).sort();
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
// src/service-host/systemd.ts
|
|
2313
|
+
var DEFAULT_STABILITY_MS2 = 5000;
|
|
2314
|
+
var DEFAULT_POLL_INTERVAL_MS2 = 250;
|
|
2315
|
+
var DEFAULT_STARTUP_TIMEOUT_MS2 = 1e4;
|
|
2316
|
+
var MAX_WAIT_MS2 = 300000;
|
|
2317
|
+
function assertSystemdWaitMs(name, value, allowZero) {
|
|
2318
|
+
const min = allowZero ? 0 : 1;
|
|
2319
|
+
if (!Number.isSafeInteger(value) || value < min || value > MAX_WAIT_MS2) {
|
|
2320
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Invalid ${name}: expected integer in [${min}, ${MAX_WAIT_MS2}], got ${value}`);
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
async function runSystemctlChecked(adapter, scope, args) {
|
|
2324
|
+
const result = await adapter.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(scope, args));
|
|
2325
|
+
if (result.exitCode !== 0) {
|
|
2326
|
+
throw new SystemdUnitError("COMMAND_FAILED", `systemctl ${args.join(" ")} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
async function waitForStableSystemdUnit(unitName, scope, adapter, startupTimeoutMs, stabilityMs, pollIntervalMs) {
|
|
2330
|
+
const startDeadline = adapter.now() + startupTimeoutMs;
|
|
2331
|
+
let candidatePid = null;
|
|
2332
|
+
for (;; ) {
|
|
2333
|
+
const active = await systemdUnitActive({ unitName, scope, adapter });
|
|
2334
|
+
const pid = active ? await systemdMainPid({ unitName, scope, adapter }) : null;
|
|
2335
|
+
if (active && pid !== null) {
|
|
2336
|
+
candidatePid = pid;
|
|
2337
|
+
break;
|
|
2338
|
+
}
|
|
2339
|
+
if (adapter.now() >= startDeadline) {
|
|
2340
|
+
throw new SystemdUnitError("START_TIMEOUT", `Systemd unit ${unitName} did not reach active state with MainPID within ${startupTimeoutMs}ms`);
|
|
2341
|
+
}
|
|
2342
|
+
await adapter.sleep(Math.min(pollIntervalMs, Math.max(1, startDeadline - adapter.now())));
|
|
2343
|
+
}
|
|
2344
|
+
const stableSince = adapter.now();
|
|
2345
|
+
const stableDeadline = stableSince + stabilityMs;
|
|
2346
|
+
while (adapter.now() < stableDeadline) {
|
|
2347
|
+
await adapter.sleep(Math.min(pollIntervalMs, Math.max(1, stableDeadline - adapter.now())));
|
|
2348
|
+
const active = await systemdUnitActive({ unitName, scope, adapter });
|
|
2349
|
+
const pid = active ? await systemdMainPid({ unitName, scope, adapter }) : null;
|
|
2350
|
+
if (!active || pid !== candidatePid) {
|
|
2351
|
+
throw new SystemdUnitError("UNSTABLE_CANDIDATE", `Systemd unit ${unitName} lost stability during ${stabilityMs}ms window (expected PID ${candidatePid}, observed ${pid ?? "none"})`);
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
return { mainPid: candidatePid, stableForMs: adapter.now() - stableSince };
|
|
2355
|
+
}
|
|
2356
|
+
var ONESHOT_TYPE = /^[ \t]*Type[ \t]*=[ \t]*oneshot[ \t]*$/m;
|
|
2357
|
+
async function restoreEnablement(adapter, options, point) {
|
|
2358
|
+
const { scope, unitName } = options;
|
|
2359
|
+
const read = () => readEnablementLinks(adapter, point.linkDirs, point.linkNames);
|
|
2360
|
+
if (await restoreEnablementLinks(adapter, unitName, point.linksBefore, await read()))
|
|
2361
|
+
await runSystemctlChecked(adapter, scope, ["daemon-reload"]);
|
|
2362
|
+
const differ = differentLinks(point.linksBefore, await read());
|
|
2363
|
+
if (differ.length > 0) {
|
|
2364
|
+
throw new SystemdUnitError("COMMAND_FAILED", `the enable links of ${unitName} differ from before the apply: ${differ.join(", ")}`);
|
|
2365
|
+
}
|
|
2366
|
+
if (point.previousBytes === null)
|
|
2367
|
+
return;
|
|
2368
|
+
const expected = point.previousUnitFileState;
|
|
2369
|
+
if (expected === null) {
|
|
2370
|
+
throw new SystemdUnitError("COMMAND_FAILED", `UnitFileState of ${unitName} was unknown before the apply: its enablement cannot be checked`);
|
|
2371
|
+
}
|
|
2372
|
+
const result = await adapter.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(scope, ["is-enabled", "--", unitName]));
|
|
2373
|
+
const state = result.stdout.trim();
|
|
2374
|
+
if (state !== expected) {
|
|
2375
|
+
throw new SystemdUnitError("COMMAND_FAILED", `UnitFileState of ${unitName} is ${state || "unknown"} after rollback, not ${expected}${result.stderr.trim() ? ` (${result.stderr.trim()})` : ""}`);
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
async function restorePreviousUnit(adapter, options, point) {
|
|
2379
|
+
const { scope, unitName, unitPath } = options;
|
|
2380
|
+
if (point.previousBytes === null) {
|
|
2381
|
+
if (point.didRestart)
|
|
2382
|
+
await runSystemctlChecked(adapter, scope, ["stop", "--", unitName]);
|
|
2383
|
+
if (point.didEnable)
|
|
2384
|
+
await restoreEnablement(adapter, options, point);
|
|
2385
|
+
await adapter.removeFile(unitPath);
|
|
2386
|
+
await runSystemctlChecked(adapter, scope, ["daemon-reload"]);
|
|
2387
|
+
return;
|
|
2388
|
+
}
|
|
2389
|
+
await adapter.writeFileAtomic(unitPath, point.previousBytes, { mode: point.mode });
|
|
2390
|
+
await runSystemctlChecked(adapter, scope, ["daemon-reload"]);
|
|
2391
|
+
if (point.didRestart) {
|
|
2392
|
+
await runSystemctlChecked(adapter, scope, [
|
|
2393
|
+
point.wasActive ? "restart" : "stop",
|
|
2394
|
+
"--",
|
|
2395
|
+
unitName
|
|
2396
|
+
]);
|
|
2397
|
+
}
|
|
2398
|
+
if (point.didEnable)
|
|
2399
|
+
await restoreEnablement(adapter, options, point);
|
|
2400
|
+
}
|
|
2401
|
+
async function applySystemdUnit(options, defaultEnable) {
|
|
2402
|
+
assertValidSystemdUnitName(options.unitName);
|
|
2403
|
+
const stabilityMs = options.stabilityMs ?? DEFAULT_STABILITY_MS2;
|
|
2404
|
+
const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS2;
|
|
2405
|
+
const startupTimeoutMs = options.startupTimeoutMs ?? DEFAULT_STARTUP_TIMEOUT_MS2;
|
|
2406
|
+
assertSystemdWaitMs("stabilityMs", stabilityMs, true);
|
|
2407
|
+
assertSystemdWaitMs("pollIntervalMs", pollIntervalMs, false);
|
|
2408
|
+
assertSystemdWaitMs("startupTimeoutMs", startupTimeoutMs, false);
|
|
2409
|
+
const adapter = options.adapter ?? createDefaultSystemdHostAdapter();
|
|
2410
|
+
const preCheck = await checkSystemdUnit({
|
|
2411
|
+
unitName: options.unitName,
|
|
2412
|
+
unitPath: options.unitPath,
|
|
2413
|
+
expectedContent: options.content,
|
|
2414
|
+
scope: options.scope,
|
|
2415
|
+
...options.unitSearchDirs ? { unitSearchDirs: options.unitSearchDirs } : {},
|
|
2416
|
+
adapter
|
|
2417
|
+
});
|
|
2418
|
+
if (preCheck.foreignDropIns.length > 0) {
|
|
2419
|
+
throw new SystemdUnitError("FOREIGN_DROP_IN", `Refusing to manage ${options.unitName}: foreign drop-ins present (${preCheck.foreignDropIns.join(", ")})`, { rolledBack: false, foreignDropIns: preCheck.foreignDropIns });
|
|
2420
|
+
}
|
|
2421
|
+
const foreign = foreignUnitSource(preCheck, options.unitPath);
|
|
2422
|
+
if (foreign !== undefined) {
|
|
2423
|
+
throw new SystemdUnitError("FOREIGN_FRAGMENT", `Refusing to manage ${options.unitName}: ${foreign}`, { rolledBack: false });
|
|
2424
|
+
}
|
|
2425
|
+
if (ONESHOT_TYPE.test(options.content)) {
|
|
2426
|
+
throw new SystemdUnitError("UNSUPPORTED_UNIT_TYPE", `Refusing to apply ${options.unitName}: Type=oneshot has no main process to hold stable`, { rolledBack: false });
|
|
2427
|
+
}
|
|
2428
|
+
const standing = await adapter.inspectPath(options.unitPath);
|
|
2429
|
+
if (standing.kind === "symlink" || standing.kind === "other") {
|
|
2430
|
+
throw new SystemdUnitError("FOREIGN_FRAGMENT", `Refusing to manage ${options.unitName}: ${options.unitPath} is ${standing.kind === "symlink" ? `a symbolic link to ${standing.target}` : "not a regular file"}, not a unit file of ours to replace`, { rolledBack: false });
|
|
2431
|
+
}
|
|
2432
|
+
const previousBytes = await adapter.readFile(options.unitPath);
|
|
2433
|
+
const wasActive = preCheck.activeState === "active";
|
|
2434
|
+
const mode = options.mode ?? DEFAULT_SYSTEMD_UNIT_MODE;
|
|
2435
|
+
const enable = options.enable ?? defaultEnable;
|
|
2436
|
+
const linkNames = enablementNamesOf(options.unitName, options.unitPath, [
|
|
2437
|
+
options.content,
|
|
2438
|
+
...previousBytes === null ? [] : [new TextDecoder().decode(previousBytes)]
|
|
2439
|
+
]);
|
|
2440
|
+
const linkDirs = enable ? await resolveUnitSearchDirs(options.unitPath, options.scope, options.unitSearchDirs, adapter) : [];
|
|
2441
|
+
const linksBefore = enable ? await readEnablementLinks(adapter, linkDirs, linkNames) : new Map;
|
|
2442
|
+
await adapter.writeFileAtomic(options.unitPath, options.content, { mode });
|
|
2443
|
+
let didEnable = false;
|
|
2444
|
+
let didRestart = false;
|
|
2445
|
+
try {
|
|
2446
|
+
await runSystemctlChecked(adapter, options.scope, ["daemon-reload"]);
|
|
2447
|
+
const loaded = await checkSystemdUnit({
|
|
2448
|
+
unitName: options.unitName,
|
|
2449
|
+
unitPath: options.unitPath,
|
|
2450
|
+
expectedContent: options.content,
|
|
2451
|
+
scope: options.scope,
|
|
2452
|
+
...options.unitSearchDirs ? { unitSearchDirs: options.unitSearchDirs } : {},
|
|
2453
|
+
adapter
|
|
2454
|
+
});
|
|
2455
|
+
if (loaded.status !== "matches") {
|
|
2456
|
+
throw new SystemdUnitError("FOREIGN_FRAGMENT", `systemd did not load ${options.unitPath} for ${options.unitName} (${loaded.status}, LoadState=${loaded.loadState ?? "unknown"}, FragmentPath=${loaded.fragmentPath ?? "none"})`);
|
|
2457
|
+
}
|
|
2458
|
+
if (enable) {
|
|
2459
|
+
didEnable = true;
|
|
2460
|
+
await runSystemctlChecked(adapter, options.scope, ["enable", "--", options.unitName]);
|
|
2461
|
+
}
|
|
2462
|
+
didRestart = true;
|
|
2463
|
+
await runSystemctlChecked(adapter, options.scope, ["restart", "--", options.unitName]);
|
|
2464
|
+
const settled = await waitForStableSystemdUnit(options.unitName, options.scope, adapter, startupTimeoutMs, stabilityMs, pollIntervalMs);
|
|
2465
|
+
return {
|
|
2466
|
+
unitName: options.unitName,
|
|
2467
|
+
digest: computeSha256Hex(options.content),
|
|
2468
|
+
mainPid: settled.mainPid,
|
|
2469
|
+
stableForMs: settled.stableForMs
|
|
2470
|
+
};
|
|
2471
|
+
} catch (cause) {
|
|
2472
|
+
let rolledBack = false;
|
|
2473
|
+
let rollbackError;
|
|
2474
|
+
try {
|
|
2475
|
+
await restorePreviousUnit(adapter, options, {
|
|
2476
|
+
mode: standing.kind === "file" ? standing.mode : mode,
|
|
2477
|
+
previousBytes,
|
|
2478
|
+
wasActive,
|
|
2479
|
+
previousUnitFileState: preCheck.unitFileState,
|
|
2480
|
+
linkDirs,
|
|
2481
|
+
linkNames,
|
|
2482
|
+
linksBefore,
|
|
2483
|
+
didEnable,
|
|
2484
|
+
didRestart
|
|
2485
|
+
});
|
|
2486
|
+
rolledBack = true;
|
|
2487
|
+
} catch (rbError) {
|
|
2488
|
+
rollbackError = rbError;
|
|
2489
|
+
}
|
|
2490
|
+
const code = cause instanceof SystemdUnitError ? cause.code : "COMMAND_FAILED";
|
|
2491
|
+
const baseMessage = messageOf(cause);
|
|
2492
|
+
const message = !rolledBack && rollbackError !== undefined ? `${baseMessage}; rollback also failed: ${messageOf(rollbackError)}` : baseMessage;
|
|
2493
|
+
throw new SystemdUnitError(code, message, { cause, rolledBack, rollbackError });
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
function installAndStartSystemdUnit(options) {
|
|
2497
|
+
return applySystemdUnit(options, true);
|
|
2498
|
+
}
|
|
2499
|
+
function reloadSystemdUnit(options) {
|
|
2500
|
+
return applySystemdUnit(options, false);
|
|
2501
|
+
}
|
|
2502
|
+
export {
|
|
2503
|
+
ARTIFACT_MANIFEST_FILENAME2 as ARTIFACT_MANIFEST_FILENAME,
|
|
2504
|
+
ArtifactFileEntrySchema2 as ArtifactFileEntrySchema,
|
|
2505
|
+
ArtifactManifestSchema2 as ArtifactManifestSchema,
|
|
2506
|
+
ArtifactVerificationError2 as ArtifactVerificationError,
|
|
2507
|
+
DEFAULT_ARTIFACT_MAX_FILES2 as DEFAULT_ARTIFACT_MAX_FILES,
|
|
2508
|
+
DEFAULT_ARTIFACT_MAX_FILE_BYTES2 as DEFAULT_ARTIFACT_MAX_FILE_BYTES,
|
|
2509
|
+
DEFAULT_CONFIG_POLL_INTERVAL_MS,
|
|
2510
|
+
DEFAULT_CONFIG_START_TIMEOUT_MS,
|
|
2511
|
+
DEFAULT_CONFIG_STOP_TIMEOUT_MS,
|
|
2512
|
+
LaunchdJobError2 as LaunchdJobError,
|
|
2513
|
+
LaunchdKeepAliveSchema2 as LaunchdKeepAliveSchema,
|
|
2514
|
+
LaunchdPlistConfigSchema2 as LaunchdPlistConfigSchema,
|
|
2515
|
+
LaunchdSessionTypeSchema2 as LaunchdSessionTypeSchema,
|
|
2516
|
+
PLUTIL_PATH2 as PLUTIL_PATH,
|
|
2517
|
+
SystemdScopeSchema,
|
|
2518
|
+
SystemdServiceUnitConfigSchema,
|
|
2519
|
+
SystemdUnitError,
|
|
2520
|
+
activateVersionedArtifact,
|
|
2521
|
+
bootoutLaunchdJob,
|
|
2522
|
+
checkSystemdUnit,
|
|
2523
|
+
computeArtifactManifestDigest2 as computeArtifactManifestDigest,
|
|
2524
|
+
createDefaultLaunchdHostAdapter2 as createDefaultLaunchdHostAdapter,
|
|
2525
|
+
createDefaultProcessIdentityAdapter,
|
|
2526
|
+
createDefaultSystemdHostAdapter,
|
|
2527
|
+
createPolledJsonConfigSource,
|
|
2528
|
+
inspectLaunchdJob,
|
|
2529
|
+
installAndStartSystemdUnit,
|
|
2530
|
+
lintLaunchdPlist2 as lintLaunchdPlist,
|
|
2531
|
+
parseLaunchctlPrint2 as parseLaunchctlPrint,
|
|
2532
|
+
parseProcNetUnixListeningSockets,
|
|
2533
|
+
readLaunchdPlist2 as readLaunchdPlist,
|
|
2534
|
+
reloadLaunchdJob,
|
|
2535
|
+
reloadSystemdUnit,
|
|
2536
|
+
renderLaunchdPlist2 as renderLaunchdPlist,
|
|
2537
|
+
renderSystemdServiceUnit,
|
|
2538
|
+
rollbackVersionedArtifact,
|
|
2539
|
+
startConfigReloader,
|
|
2540
|
+
systemdMainPid,
|
|
2541
|
+
systemdUnitActive,
|
|
2542
|
+
verifyArtifactDirectory,
|
|
2543
|
+
verifySupervisedProcess
|
|
2544
|
+
};
|