@loucompanion/forge-bridge 0.1.3-dev.f66395c3ac21 → 0.1.4-dev.0098fdb4e213
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/README.md +306 -1
- package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
- package/dist/bridge/bridge-chat-provider-command.js +132 -0
- package/dist/bridge/bridge-chat.types.d.ts +121 -0
- package/dist/bridge/bridge-chat.types.js +416 -0
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.base.d.ts +18 -1
- package/dist/bridge/bridge.service.d.ts +216 -4
- package/dist/bridge/bridge.service.js +2574 -90
- package/dist/bridge/bridge.types.d.ts +245 -2
- package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
- package/dist/bridge/dispatch-result-outbox.js +87 -0
- package/dist/bridge/dispatch-result-worker.d.ts +2 -0
- package/dist/bridge/dispatch-result-worker.js +122 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/internals.d.ts +2 -0
- package/dist/bridge/internals.js +1 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/readiness-result-outbox.d.ts +25 -0
- package/dist/bridge/readiness-result-outbox.js +74 -0
- package/dist/bridge/readiness-result-worker.d.ts +2 -0
- package/dist/bridge/readiness-result-worker.js +121 -0
- package/dist/bridge/runner-host-capabilities.d.ts +20 -0
- package/dist/bridge/runner-host-capabilities.js +110 -0
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +33 -2
- package/dist/cleanup/cleanup.service.js +477 -3
- package/dist/cleanup/cleanup.types.d.ts +16 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
- package/dist/cleanup/host-runtime-ledger.js +130 -0
- package/dist/cleanup/index.d.ts +1 -1
- package/dist/cleanup/index.js +1 -1
- package/dist/cleanup/internals.d.ts +2 -2
- package/dist/cleanup/internals.js +1 -1
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.d.ts +2 -0
- package/dist/cli/cli.help.js +279 -0
- package/dist/cli/cli.service.d.ts +69 -12
- package/dist/cli/cli.service.js +557 -382
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +13 -0
- package/dist/cli/local-config.js +82 -6
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +41 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +474 -0
- package/dist/runtime/attempt-database-broker.d.ts +89 -0
- package/dist/runtime/attempt-database-broker.js +390 -0
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +18 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +140 -0
- package/dist/runtime/attempt-path-operation.d.ts +21 -0
- package/dist/runtime/attempt-path-operation.js +94 -0
- package/dist/runtime/attempt-private-directory.d.ts +6 -0
- package/dist/runtime/attempt-private-directory.js +54 -0
- package/dist/runtime/attempt-process-supervisor-registry.d.ts +20 -0
- package/dist/runtime/attempt-process-supervisor-registry.js +64 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +121 -0
- package/dist/runtime/attempt-process-supervisor.js +471 -0
- package/dist/runtime/canonical-source-file.d.ts +3 -0
- package/dist/runtime/canonical-source-file.js +54 -0
- package/dist/runtime/docker-engine-probe.d.ts +95 -0
- package/dist/runtime/docker-engine-probe.js +340 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/generated-output-reset.d.ts +20 -0
- package/dist/runtime/generated-output-reset.js +157 -0
- package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
- package/dist/runtime/host-database-capability-boundary.js +63 -0
- package/dist/runtime/host-diagnostics.d.ts +11 -0
- package/dist/runtime/host-diagnostics.js +192 -0
- package/dist/runtime/host-execution-root.d.ts +4 -0
- package/dist/runtime/host-execution-root.js +39 -0
- package/dist/runtime/host-facts.d.ts +36 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-listener-inspector.d.ts +51 -0
- package/dist/runtime/host-listener-inspector.js +385 -0
- package/dist/runtime/host-load-admission.d.ts +67 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +186 -0
- package/dist/runtime/host-load-governor.js +632 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +187 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +80 -0
- package/dist/runtime/host-load-sampler.d.ts +156 -0
- package/dist/runtime/host-load-sampler.js +298 -0
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-port-broker.d.ts +76 -0
- package/dist/runtime/host-port-broker.js +333 -0
- package/dist/runtime/host-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +74 -0
- package/dist/runtime/host-runtime-contract.js +846 -0
- package/dist/runtime/host-runtime-lease.d.ts +287 -0
- package/dist/runtime/host-runtime-lease.js +2763 -0
- package/dist/runtime/host-runtime-promotion.d.ts +55 -0
- package/dist/runtime/host-runtime-promotion.js +254 -0
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +596 -0
- package/dist/runtime/memory-capacity.d.ts +70 -0
- package/dist/runtime/memory-capacity.js +123 -0
- package/dist/runtime/native-test-postgres-fallback.d.ts +69 -0
- package/dist/runtime/native-test-postgres-fallback.js +143 -0
- package/dist/runtime/node-host-runtime-adapter.d.ts +54 -0
- package/dist/runtime/node-host-runtime-adapter.js +286 -0
- package/dist/runtime/pinned-directory-process.d.ts +9 -0
- package/dist/runtime/pinned-directory-process.js +61 -0
- package/dist/runtime/pinned-source-directory.d.ts +17 -0
- package/dist/runtime/pinned-source-directory.js +94 -0
- package/dist/runtime/playwright-browser-cache.d.ts +39 -0
- package/dist/runtime/playwright-browser-cache.js +227 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +39 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +274 -0
- package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
- package/dist/runtime/prepared-runtime-identity.js +218 -0
- package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
- package/dist/runtime/prepared-runtime-readiness.js +285 -0
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/runtime-isolation-lease.d.ts +67 -0
- package/dist/runtime/runtime-isolation-lease.js +161 -0
- package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
- package/dist/runtime/workspace-resource-estimator.js +174 -0
- package/dist/sandbox/command-runner.d.ts +4 -0
- package/dist/sandbox/command-runner.js +47 -0
- package/dist/sandbox/contract.d.ts +5 -0
- package/dist/sandbox/contract.js +276 -0
- package/dist/sandbox/event-budget.d.ts +11 -0
- package/dist/sandbox/event-budget.js +27 -0
- package/dist/sandbox/host-capacity-broker.d.ts +115 -0
- package/dist/sandbox/host-capacity-broker.js +336 -0
- package/dist/sandbox/image-policy.d.ts +35 -0
- package/dist/sandbox/image-policy.js +247 -0
- package/dist/sandbox/index.d.ts +5 -0
- package/dist/sandbox/index.js +5 -0
- package/dist/sandbox/lease-watchdog.d.ts +18 -0
- package/dist/sandbox/lease-watchdog.js +67 -0
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +36 -0
- package/dist/sandbox/preflight.d.ts +84 -0
- package/dist/sandbox/preflight.js +521 -0
- package/dist/sandbox/process.d.ts +20 -0
- package/dist/sandbox/process.js +209 -0
- package/dist/sandbox/provider-auth/codex.d.ts +26 -0
- package/dist/sandbox/provider-auth/codex.js +212 -0
- package/dist/sandbox/repository-lock.d.ts +6 -0
- package/dist/sandbox/repository-lock.js +129 -0
- package/dist/sandbox/runtime.d.ts +311 -0
- package/dist/sandbox/runtime.js +2407 -0
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox.types.d.ts +93 -0
- package/dist/sandbox/sandbox.types.js +1 -0
- package/dist/sandbox/smoke.d.ts +76 -0
- package/dist/sandbox/smoke.js +380 -0
- package/dist/sandbox/worker-supervisor.d.ts +13 -0
- package/dist/sandbox/worker-supervisor.js +36 -0
- package/dist/sandbox/worker.d.ts +1 -0
- package/dist/sandbox/worker.js +225 -0
- package/dist/sandbox/workspace.service.d.ts +13 -0
- package/dist/sandbox/workspace.service.js +74 -0
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +48 -0
- package/dist/session/managed-attempt-tools.js +1299 -0
- package/dist/session/managed-build-coordinator.d.ts +5 -0
- package/dist/session/managed-build-coordinator.js +109 -0
- package/dist/session/managed-build-receipt.d.ts +26 -0
- package/dist/session/managed-build-receipt.js +342 -0
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/managed-verification-timeouts.d.ts +8 -0
- package/dist/session/managed-verification-timeouts.js +17 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +34 -0
- package/dist/session/phase-completion.artifacts.js +903 -0
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +65 -42
- package/dist/session/phase-completion.helpers.d.ts +117 -0
- package/dist/session/phase-completion.helpers.js +708 -0
- package/dist/session/phase-completion.js +130 -3007
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.prompts.d.ts +14 -0
- package/dist/session/phase-completion.prompts.js +238 -0
- package/dist/session/phase-completion.runtime.d.ts +43 -0
- package/dist/session/phase-completion.runtime.js +721 -0
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -0
- package/dist/session/phase-completion.schemas.js +836 -0
- package/dist/session/phase-completion.validation.d.ts +37 -0
- package/dist/session/phase-completion.validation.js +874 -0
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.d.ts +23 -0
- package/dist/session/pre-publication-process.js +109 -0
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- package/dist/session/pre-publication-step-execution.d.ts +12 -0
- package/dist/session/pre-publication-step-execution.js +50 -0
- package/dist/session/pre-publication-validation.d.ts +91 -0
- package/dist/session/pre-publication-validation.js +670 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
- package/dist/session/provider-cli/ci-repair-readiness.d.ts +16 -0
- package/dist/session/provider-cli/ci-repair-readiness.js +110 -0
- package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
- package/dist/session/provider-cli/claude-background-work.js +181 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +96 -0
- package/dist/session/provider-cli/provider-cli.artifacts.js +818 -0
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.deterministic-payloads.d.ts +12 -0
- package/dist/session/provider-cli/provider-cli.deterministic-payloads.js +279 -0
- package/dist/session/provider-cli/provider-cli.deterministic.d.ts +14 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +407 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +114 -0
- package/dist/session/provider-cli/provider-cli.process.js +757 -0
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +62 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +770 -0
- package/dist/session/provider-cli/provider-cli.qa-sidecars.d.ts +11 -0
- package/dist/session/provider-cli/provider-cli.qa-sidecars.js +66 -0
- package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +30 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +120 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +53 -53
- package/dist/session/provider-cli/provider-cli.service.js +1299 -2523
- package/dist/session/provider-cli/provider-cli.types.d.ts +38 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +40 -0
- package/dist/session/provider-cli/provider-output-state.js +832 -0
- package/dist/session/provider-cli/provider-usage.d.ts +9 -1
- package/dist/session/provider-cli/provider-usage.js +28 -5
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
- package/dist/session/sandbox-host-capacity-gate.js +257 -0
- package/dist/session/session-redaction.d.ts +3 -0
- package/dist/session/session-redaction.js +298 -0
- package/dist/session/session.base.d.ts +14 -1
- package/dist/session/session.service.d.ts +17 -2
- package/dist/session/session.service.js +708 -60
- package/dist/session/session.types.d.ts +327 -3
- package/dist/session/session.types.js +951 -10
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/unreferenced-exports.d.ts +12 -0
- package/dist/session/unreferenced-exports.js +59 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/format/format-bytes.d.ts +1 -0
- package/dist/shared/format/format-bytes.js +9 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/git/git.js +2 -1
- package/dist/shared/path/path.d.ts +1 -0
- package/dist/shared/path/path.js +21 -1
- package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
- package/dist/shared/process/dotnet-toolchain.js +307 -0
- package/dist/shared/process/host-process-recovery.d.ts +23 -0
- package/dist/shared/process/host-process-recovery.js +99 -0
- package/dist/shared/process/host-process-supervisor.d.ts +72 -0
- package/dist/shared/process/host-process-supervisor.js +383 -0
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +70 -0
- package/dist/shared/process/process.js +224 -16
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +26 -0
- package/dist/shared/process/windows-launch.js +109 -0
- package/dist/shared/provider-capabilities.d.ts +4 -0
- package/dist/shared/provider-capabilities.js +95 -0
- package/dist/shared/redaction/redaction.d.ts +1 -0
- package/dist/shared/redaction/redaction.js +47 -4
- package/dist/shared/time/monotonic.d.ts +1 -0
- package/dist/shared/time/monotonic.js +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.d.ts +3 -2
- package/dist/worktree/artifact-injector.js +82 -10
- package/dist/worktree/dependency-warmer.d.ts +78 -1
- package/dist/worktree/dependency-warmer.js +731 -13
- package/dist/worktree/index.d.ts +2 -1
- package/dist/worktree/index.js +1 -0
- package/dist/worktree/prior-phase-artifact-hydrator.d.ts +2 -0
- package/dist/worktree/prior-phase-artifact-hydrator.js +136 -0
- package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
- package/dist/worktree/story-qa-reference-hydrator.js +253 -0
- package/dist/worktree/wip-git.d.ts +33 -0
- package/dist/worktree/wip-git.js +122 -0
- package/dist/worktree/wip-refs.d.ts +62 -0
- package/dist/worktree/wip-refs.js +119 -0
- package/dist/worktree/wip-restore.d.ts +38 -0
- package/dist/worktree/wip-restore.js +190 -0
- package/dist/worktree/wip-snapshot.d.ts +50 -0
- package/dist/worktree/wip-snapshot.js +268 -0
- package/dist/worktree/worktree-paths.d.ts +4 -0
- package/dist/worktree/worktree-paths.js +30 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +98 -0
- package/dist/worktree/worktree-wip.d.ts +49 -0
- package/dist/worktree/worktree-wip.js +182 -0
- package/dist/worktree/worktree.base.d.ts +10 -1
- package/dist/worktree/worktree.service.d.ts +30 -4
- package/dist/worktree/worktree.service.js +379 -54
- package/dist/worktree/worktree.types.d.ts +38 -1
- package/package.json +12 -7
- package/runtime/windows-job-supervisor.ps1 +722 -0
- package/runtime/windows-listener-owner.ps1 +33 -0
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { promisify } from "node:util";
|
|
7
|
+
import { monotonicNowMs } from "../time/monotonic.js";
|
|
8
|
+
const execFileAsync = promisify(execFile);
|
|
9
|
+
const windowsJobSupervisorPath = fileURLToPath(new URL("../../../runtime/windows-job-supervisor.ps1", import.meta.url));
|
|
10
|
+
export function resolveHostProcessSupervisedLaunch(request, resolvedCommand, resolvedArgs, platform = process.platform) {
|
|
11
|
+
const env = request.env;
|
|
12
|
+
if (env?.FORGE_RUNTIME_MODE !== "host")
|
|
13
|
+
return null;
|
|
14
|
+
const supervisorId = requiredEnvironment(env, "FORGE_PROCESS_SUPERVISOR_ID");
|
|
15
|
+
const metadataPath = requiredEnvironment(env, "FORGE_PROCESS_SUPERVISOR_METADATA_PATH");
|
|
16
|
+
const logDirectory = requiredEnvironment(env, "FORGE_LOG_DIR");
|
|
17
|
+
assertMetadataPath(logDirectory, metadataPath);
|
|
18
|
+
const commandDigest = createHash("sha256")
|
|
19
|
+
.update(JSON.stringify([resolvedCommand, ...resolvedArgs]))
|
|
20
|
+
.digest("hex");
|
|
21
|
+
if (platform === "win32") {
|
|
22
|
+
if (!fs.existsSync(windowsJobSupervisorPath)) {
|
|
23
|
+
throw new Error(`host_process_supervisor_missing: ${windowsJobSupervisorPath}`);
|
|
24
|
+
}
|
|
25
|
+
const payloadPath = `${metadataPath}.launch.json`;
|
|
26
|
+
const readyPath = `${metadataPath}.provider-ready.json`;
|
|
27
|
+
const startGrantPath = `${metadataPath}.provider-start-granted`;
|
|
28
|
+
const memoryTelemetryPath = `${metadataPath}.memory.json`;
|
|
29
|
+
const serializedPayload = `${JSON.stringify({
|
|
30
|
+
command: resolvedCommand,
|
|
31
|
+
args: resolvedArgs,
|
|
32
|
+
cwd: request.cwd,
|
|
33
|
+
parentPid: process.pid,
|
|
34
|
+
supervisorId,
|
|
35
|
+
readyPath,
|
|
36
|
+
startGrantPath,
|
|
37
|
+
memoryTelemetryPath,
|
|
38
|
+
})}\n`;
|
|
39
|
+
const payloadSha256 = createHash("sha256").update(serializedPayload).digest("hex");
|
|
40
|
+
fs.writeFileSync(payloadPath, serializedPayload, {
|
|
41
|
+
encoding: "utf8",
|
|
42
|
+
flag: "wx",
|
|
43
|
+
mode: 0o600,
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
command: windowsPowerShellPath(),
|
|
47
|
+
args: [
|
|
48
|
+
"-NoLogo",
|
|
49
|
+
"-NoProfile",
|
|
50
|
+
"-NonInteractive",
|
|
51
|
+
"-ExecutionPolicy",
|
|
52
|
+
"Bypass",
|
|
53
|
+
"-File",
|
|
54
|
+
windowsJobSupervisorPath,
|
|
55
|
+
"-Mode",
|
|
56
|
+
"Outer",
|
|
57
|
+
"-PayloadPath",
|
|
58
|
+
payloadPath,
|
|
59
|
+
"-PayloadSha256",
|
|
60
|
+
payloadSha256,
|
|
61
|
+
],
|
|
62
|
+
detached: false,
|
|
63
|
+
supervisorId,
|
|
64
|
+
strategy: "windows_job_object",
|
|
65
|
+
metadataPath,
|
|
66
|
+
memoryTelemetryPath,
|
|
67
|
+
payloadPath,
|
|
68
|
+
payloadSha256,
|
|
69
|
+
readyPath,
|
|
70
|
+
startGrantPath,
|
|
71
|
+
commandDigest,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
command: resolvedCommand,
|
|
76
|
+
args: resolvedArgs,
|
|
77
|
+
detached: true,
|
|
78
|
+
supervisorId,
|
|
79
|
+
strategy: "unix_process_group",
|
|
80
|
+
metadataPath,
|
|
81
|
+
commandDigest,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export function persistHostProcessSupervisorMetadata(launch, request, rootPid, rootCreatedAt, providerReady) {
|
|
85
|
+
if (!Number.isSafeInteger(rootPid) || rootPid <= 0) {
|
|
86
|
+
throw new Error("host_process_supervisor_invalid: supervised root PID was not assigned.");
|
|
87
|
+
}
|
|
88
|
+
const env = request.env ?? {};
|
|
89
|
+
const metadata = {
|
|
90
|
+
schemaVersion: 1,
|
|
91
|
+
supervisorId: launch.supervisorId,
|
|
92
|
+
strategy: launch.strategy,
|
|
93
|
+
rootPid,
|
|
94
|
+
rootCreatedAt,
|
|
95
|
+
rootIdentity: providerReady?.rootPid === rootPid
|
|
96
|
+
? providerReady.rootIdentity ?? null
|
|
97
|
+
: captureHostProcessIdentity(rootPid),
|
|
98
|
+
commandDigest: launch.commandDigest,
|
|
99
|
+
worktreePath: request.cwd,
|
|
100
|
+
runtimeLeaseId: requiredEnvironment(env, "FORGE_RESOURCE_LEASE_ID"),
|
|
101
|
+
dispatchAttemptId: requiredEnvironment(env, "FORGE_DISPATCH_ATTEMPT_ID"),
|
|
102
|
+
fencingToken: requiredEnvironment(env, "FORGE_FENCING_TOKEN"),
|
|
103
|
+
bridgePid: process.pid,
|
|
104
|
+
providerPid: providerReady?.providerPid,
|
|
105
|
+
providerCreatedAt: providerReady?.providerCreatedAt,
|
|
106
|
+
providerIdentity: providerReady?.providerIdentity
|
|
107
|
+
?? (providerReady ? captureHostProcessIdentity(providerReady.providerPid) : undefined),
|
|
108
|
+
providerStartAttempt: providerReady?.startAttempt,
|
|
109
|
+
};
|
|
110
|
+
fs.writeFileSync(launch.metadataPath, `${JSON.stringify(metadata)}\n`, {
|
|
111
|
+
encoding: "utf8",
|
|
112
|
+
flag: "wx",
|
|
113
|
+
mode: 0o600,
|
|
114
|
+
});
|
|
115
|
+
return metadata;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Captures an OS-issued process birth marker. Recovery compares this marker
|
|
119
|
+
* before signalling a persisted PID so PID reuse can never redirect cleanup
|
|
120
|
+
* at an unrelated process.
|
|
121
|
+
*/
|
|
122
|
+
export function captureHostProcessIdentity(pid, platform = process.platform) {
|
|
123
|
+
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
124
|
+
return null;
|
|
125
|
+
try {
|
|
126
|
+
if (platform === "linux") {
|
|
127
|
+
const bootId = fs.readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim();
|
|
128
|
+
const stat = fs.readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
129
|
+
const close = stat.lastIndexOf(")");
|
|
130
|
+
const fields = close >= 0 ? stat.slice(close + 2).trim().split(/\s+/u) : [];
|
|
131
|
+
const startTicks = fields[19];
|
|
132
|
+
return bootId && startTicks && /^\d+$/u.test(startTicks)
|
|
133
|
+
? `linux:${bootId}:${startTicks}`
|
|
134
|
+
: null;
|
|
135
|
+
}
|
|
136
|
+
if (platform === "win32") {
|
|
137
|
+
const output = execFileSync(windowsPowerShellPath(), [
|
|
138
|
+
"-NoLogo",
|
|
139
|
+
"-NoProfile",
|
|
140
|
+
"-NonInteractive",
|
|
141
|
+
"-Command",
|
|
142
|
+
`(Get-Process -Id ${pid} -ErrorAction Stop).StartTime.ToUniversalTime().Ticks`,
|
|
143
|
+
], {
|
|
144
|
+
encoding: "utf8",
|
|
145
|
+
windowsHide: true,
|
|
146
|
+
timeout: 10_000,
|
|
147
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
148
|
+
}).trim();
|
|
149
|
+
return /^\d+$/u.test(output) ? `win32:${output}` : null;
|
|
150
|
+
}
|
|
151
|
+
// Other Unix variants do not expose a sufficiently strong birth marker
|
|
152
|
+
// through Node. Fail closed rather than trust a second-resolution ps time.
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
export async function terminateHostProcessTree(child, launch, graceMs = 2_000, windowsJobGone = waitForWindowsSupervisorJobGone) {
|
|
160
|
+
if (!launch) {
|
|
161
|
+
await terminateUnsupervisedProcessTree(child, graceMs);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (launch.strategy === "windows_job_object") {
|
|
165
|
+
const rootPid = child.pid ?? 0;
|
|
166
|
+
const metadata = readSupervisorMetadata(launch.metadataPath);
|
|
167
|
+
try {
|
|
168
|
+
child.kill("SIGTERM");
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
// Closing the launcher is best effort when the Job Object already settled.
|
|
172
|
+
}
|
|
173
|
+
// The root is this process's own child: its exit is observed through the handle
|
|
174
|
+
// Node holds, not by polling its identity with a PowerShell launch per check.
|
|
175
|
+
if (!await waitForChildExit(child, graceMs)) {
|
|
176
|
+
forceWindowsProcessTree(rootPid);
|
|
177
|
+
if (!await waitForChildExit(child, graceMs)) {
|
|
178
|
+
throw new Error("host_process_supervisor_termination_failed: supervised Windows root did not stop.");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const providerPid = metadata?.providerPid ?? 0;
|
|
182
|
+
const providerIdentity = metadata?.providerIdentity ?? null;
|
|
183
|
+
if (exactProcessExists(providerPid, providerIdentity, "win32")) {
|
|
184
|
+
forceWindowsProcessTree(providerPid);
|
|
185
|
+
await waitForExactProcessExit(providerPid, providerIdentity, graceMs, "win32");
|
|
186
|
+
}
|
|
187
|
+
if (exactProcessExists(providerPid, providerIdentity, "win32")) {
|
|
188
|
+
throw new Error("host_process_supervisor_termination_failed: supervised Windows provider tree did not stop.");
|
|
189
|
+
}
|
|
190
|
+
// The root and the provider have exited; the rest of the tree (a descendant that left
|
|
191
|
+
// the provider's process tree, say) is gone only with the Job Object, which outlives
|
|
192
|
+
// its members by no more than a moment unless something still holds it.
|
|
193
|
+
if (!await windowsJobGone(launch.supervisorId, graceMs)) {
|
|
194
|
+
throw new Error(`host_process_supervisor_termination_failed: the Job Object of supervisor ${launch.supervisorId} still holds processes after its root and provider stopped.`);
|
|
195
|
+
}
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const processGroupId = child.pid;
|
|
199
|
+
if (!processGroupId || !signalUnixProcessGroup(processGroupId, "SIGTERM"))
|
|
200
|
+
return;
|
|
201
|
+
await waitForUnixProcessGroupExit(processGroupId, graceMs);
|
|
202
|
+
if (unixProcessGroupExists(processGroupId)) {
|
|
203
|
+
signalUnixProcessGroup(processGroupId, "SIGKILL");
|
|
204
|
+
await waitForUnixProcessGroupExit(processGroupId, graceMs);
|
|
205
|
+
}
|
|
206
|
+
if (unixProcessGroupExists(processGroupId)) {
|
|
207
|
+
throw new Error("host_process_supervisor_termination_failed: supervised Unix process group did not stop.");
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async function terminateUnsupervisedProcessTree(child, graceMs) {
|
|
211
|
+
const rootPid = child.pid ?? 0;
|
|
212
|
+
if (!Number.isSafeInteger(rootPid) || rootPid <= 0) {
|
|
213
|
+
try {
|
|
214
|
+
child.kill("SIGTERM");
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
// The process already settled before a PID was assigned.
|
|
218
|
+
}
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (process.platform === "win32") {
|
|
222
|
+
// Without a Job Object there is no trustworthy ancestry record after the
|
|
223
|
+
// root has already exited. Never target a potentially reused Windows PID.
|
|
224
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
225
|
+
return;
|
|
226
|
+
// Until this child reports its exit, Node still holds its process handle, so
|
|
227
|
+
// its PID cannot name another process. Stop the tree now, rather than after a
|
|
228
|
+
// PowerShell launch to read its identity, during which the provider runs on
|
|
229
|
+
// past the stop (a success ceiling, a cancellation), and observe the exit
|
|
230
|
+
// through that same handle.
|
|
231
|
+
forceWindowsProcessTree(rootPid);
|
|
232
|
+
if (!await waitForChildExit(child, graceMs)) {
|
|
233
|
+
throw new Error("host_process_supervisor_termination_failed: unsupervised Windows provider tree did not stop.");
|
|
234
|
+
}
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (!signalUnixProcessGroup(rootPid, "SIGTERM"))
|
|
238
|
+
return;
|
|
239
|
+
await waitForUnixProcessGroupExit(rootPid, graceMs);
|
|
240
|
+
if (unixProcessGroupExists(rootPid)) {
|
|
241
|
+
signalUnixProcessGroup(rootPid, "SIGKILL");
|
|
242
|
+
await waitForUnixProcessGroupExit(rootPid, graceMs);
|
|
243
|
+
}
|
|
244
|
+
if (unixProcessGroupExists(rootPid)) {
|
|
245
|
+
throw new Error("host_process_supervisor_termination_failed: unsupervised Unix provider tree did not stop.");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function requiredEnvironment(env, name) {
|
|
249
|
+
const value = env[name]?.trim();
|
|
250
|
+
if (!value)
|
|
251
|
+
throw new Error(`host_process_supervisor_invalid: ${name} is required.`);
|
|
252
|
+
return value;
|
|
253
|
+
}
|
|
254
|
+
function assertMetadataPath(logDirectory, metadataPath) {
|
|
255
|
+
const root = path.resolve(logDirectory);
|
|
256
|
+
const target = path.resolve(metadataPath);
|
|
257
|
+
if (target !== root && !target.startsWith(`${root}${path.sep}`)) {
|
|
258
|
+
throw new Error("host_process_supervisor_invalid: metadata path must be inside FORGE_LOG_DIR.");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Polls for the job supervisor's named Job Object (runtime/windows-job-supervisor.ps1 names
|
|
263
|
+
* it Local\Forge-<supervisorId>). A job object exists while any handle or member process
|
|
264
|
+
* holds it, and the supervisor's handle closed with it, so its absence means no member is
|
|
265
|
+
* left. Any answer but "not found" (an unreadable job, a failed check) is not proof.
|
|
266
|
+
*/
|
|
267
|
+
export const waitForWindowsSupervisorJobGone = async (supervisorId, timeoutMs) => {
|
|
268
|
+
if (!/^[A-Za-z0-9._-]{1,200}$/u.test(supervisorId))
|
|
269
|
+
return false;
|
|
270
|
+
const script = [
|
|
271
|
+
"$ErrorActionPreference = 'Stop'",
|
|
272
|
+
"Add-Type -Namespace ForgeRecovery -Name Job -MemberDefinition '[DllImport(\"kernel32.dll\", SetLastError = true, CharSet = CharSet.Unicode)] public static extern IntPtr OpenJobObject(uint access, bool inherit, string name); [DllImport(\"kernel32.dll\")] public static extern bool CloseHandle(IntPtr handle);'",
|
|
273
|
+
`$deadline = [DateTime]::UtcNow.AddMilliseconds(${Math.max(0, Math.round(timeoutMs))})`,
|
|
274
|
+
"$result = 'alive'",
|
|
275
|
+
// JOB_OBJECT_QUERY (4); ERROR_FILE_NOT_FOUND (2) is the only answer that proves the job gone.
|
|
276
|
+
"while ($true) { "
|
|
277
|
+
+ `$handle = [ForgeRecovery.Job]::OpenJobObject(4, $false, 'Local\\Forge-${supervisorId}'); `
|
|
278
|
+
+ "if ($handle -eq [IntPtr]::Zero) { $code = [Runtime.InteropServices.Marshal]::GetLastWin32Error(); "
|
|
279
|
+
+ "if ($code -eq 2) { $result = 'gone' } else { $result = \"error:$code\" }; break }; "
|
|
280
|
+
+ "[ForgeRecovery.Job]::CloseHandle($handle) | Out-Null; "
|
|
281
|
+
+ "if ([DateTime]::UtcNow -ge $deadline) { break }; Start-Sleep -Milliseconds 25 }",
|
|
282
|
+
"Write-Output $result",
|
|
283
|
+
].join("; ");
|
|
284
|
+
const { stdout } = await execFileAsync(windowsPowerShellPath(), [
|
|
285
|
+
"-NoLogo", "-NoProfile", "-NonInteractive", "-Command", script,
|
|
286
|
+
], { encoding: "utf8", windowsHide: true, timeout: timeoutMs + 60_000 }).catch(() => ({ stdout: "" }));
|
|
287
|
+
return stdout.trim() === "gone";
|
|
288
|
+
};
|
|
289
|
+
export function windowsPowerShellPath() {
|
|
290
|
+
const systemRoot = process.env.SystemRoot?.trim() || "C:\\Windows";
|
|
291
|
+
const candidate = path.win32.join(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
292
|
+
return fs.existsSync(candidate) ? candidate : "powershell.exe";
|
|
293
|
+
}
|
|
294
|
+
function signalUnixProcessGroup(processGroupId, signal) {
|
|
295
|
+
try {
|
|
296
|
+
process.kill(-processGroupId, signal);
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
if (error.code === "ESRCH")
|
|
301
|
+
return false;
|
|
302
|
+
throw error;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function unixProcessGroupExists(processGroupId) {
|
|
306
|
+
try {
|
|
307
|
+
process.kill(-processGroupId, 0);
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
if (error.code === "ESRCH")
|
|
312
|
+
return false;
|
|
313
|
+
throw error;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
async function waitForUnixProcessGroupExit(processGroupId, timeoutMs) {
|
|
317
|
+
const deadline = monotonicNowMs() + timeoutMs;
|
|
318
|
+
while (monotonicNowMs() < deadline && unixProcessGroupExists(processGroupId)) {
|
|
319
|
+
await new Promise(resolve => setTimeout(resolve, 25));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function readSupervisorMetadata(metadataPath) {
|
|
323
|
+
try {
|
|
324
|
+
return JSON.parse(fs.readFileSync(metadataPath, "utf8"));
|
|
325
|
+
}
|
|
326
|
+
catch {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function exactProcessExists(pid, identity, platform) {
|
|
331
|
+
if (!identity || !processExists(pid))
|
|
332
|
+
return false;
|
|
333
|
+
return captureHostProcessIdentity(pid, platform) === identity;
|
|
334
|
+
}
|
|
335
|
+
function processExists(pid) {
|
|
336
|
+
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
337
|
+
return false;
|
|
338
|
+
try {
|
|
339
|
+
process.kill(pid, 0);
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
return error.code === "EPERM";
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/** Whether this process's own child reports its exit within `timeoutMs`. */
|
|
347
|
+
async function waitForChildExit(child, timeoutMs) {
|
|
348
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
349
|
+
return true;
|
|
350
|
+
return await new Promise(resolve => {
|
|
351
|
+
const onExit = () => {
|
|
352
|
+
clearTimeout(timer);
|
|
353
|
+
resolve(true);
|
|
354
|
+
};
|
|
355
|
+
const timer = setTimeout(() => {
|
|
356
|
+
child.off("exit", onExit);
|
|
357
|
+
resolve(child.exitCode !== null || child.signalCode !== null);
|
|
358
|
+
}, timeoutMs);
|
|
359
|
+
child.once("exit", onExit);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
async function waitForExactProcessExit(pid, identity, timeoutMs, platform) {
|
|
363
|
+
const deadline = monotonicNowMs() + timeoutMs;
|
|
364
|
+
while (monotonicNowMs() < deadline && exactProcessExists(pid, identity, platform)) {
|
|
365
|
+
await new Promise(resolve => setTimeout(resolve, 25));
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function forceWindowsProcessTree(pid) {
|
|
369
|
+
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
370
|
+
return;
|
|
371
|
+
const systemRoot = process.env.SystemRoot?.trim() || "C:\\Windows";
|
|
372
|
+
const taskkill = path.win32.join(systemRoot, "System32", "taskkill.exe");
|
|
373
|
+
try {
|
|
374
|
+
execFileSync(taskkill, ["/PID", String(pid), "/T", "/F"], {
|
|
375
|
+
windowsHide: true,
|
|
376
|
+
timeout: 5_000,
|
|
377
|
+
stdio: "ignore",
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
catch {
|
|
381
|
+
// A racing process exit is verified by the caller before it returns.
|
|
382
|
+
}
|
|
383
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface WindowsProcessEntry {
|
|
2
|
+
readonly pid: number;
|
|
3
|
+
readonly parentPid: number;
|
|
4
|
+
/** Creation time; a pid with a different one is a different process. */
|
|
5
|
+
readonly createdAt: string;
|
|
6
|
+
}
|
|
7
|
+
/** The process table and termination primitive, injectable for tests. */
|
|
8
|
+
export interface WindowsProcessTable {
|
|
9
|
+
list(): Promise<readonly WindowsProcessEntry[]>;
|
|
10
|
+
/** `taskkill /PID <pid> /T /F`: the process and the descendants Windows still links to it. */
|
|
11
|
+
killTree(pid: number): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare const systemWindowsProcessTable: WindowsProcessTable;
|
|
14
|
+
/** What is known about the root's creation before it has been seen in the table. */
|
|
15
|
+
export type WindowsRootMarker =
|
|
16
|
+
/** Its recorded birth marker (Get-Process ticks): matched within a millisecond. */
|
|
17
|
+
{
|
|
18
|
+
readonly exactCreatedAt: string;
|
|
19
|
+
}
|
|
20
|
+
/** It was spawned no earlier than this (ticks): set synchronously at spawn. */
|
|
21
|
+
| {
|
|
22
|
+
readonly notBefore: string;
|
|
23
|
+
};
|
|
24
|
+
/** .NET ticks (100 ns since 0001-01-01 UTC), the unit Win32_Process creation times are read in. */
|
|
25
|
+
export declare function windowsTicksFromEpochMs(epochMs: number): string;
|
|
26
|
+
/** A Windows command's tracked tree; see the module comment. */
|
|
27
|
+
export declare class WindowsProcessTree {
|
|
28
|
+
private readonly rootPid;
|
|
29
|
+
private readonly table;
|
|
30
|
+
private readonly marker;
|
|
31
|
+
private readonly known;
|
|
32
|
+
/** The root's creation time as the process table reports it, once seen. */
|
|
33
|
+
private observedRoot;
|
|
34
|
+
private rootExited;
|
|
35
|
+
/**
|
|
36
|
+
* The root marker anchors the tree even if the root exits before the first
|
|
37
|
+
* snapshot (or, for a reaped token, before the reaper runs): descendants
|
|
38
|
+
* created after it whose parent was the root are still found. A tree with
|
|
39
|
+
* no marker that never saw its root cannot be proven gone.
|
|
40
|
+
*/
|
|
41
|
+
constructor(rootPid: number, table: WindowsProcessTable, marker?: WindowsRootMarker | null);
|
|
42
|
+
/** The root has exited: from now on its pid only names it if its exact creation was seen. */
|
|
43
|
+
markRootExited(): void;
|
|
44
|
+
/** Records the root's current descendants; call while the command runs. */
|
|
45
|
+
track(): Promise<void>;
|
|
46
|
+
/** Stops every tracked member and proves none is left; false when one survives or nothing anchors the tree. */
|
|
47
|
+
stop(deadlineMs: number): Promise<boolean>;
|
|
48
|
+
private rootAnchor;
|
|
49
|
+
private isRoot;
|
|
50
|
+
private absorb;
|
|
51
|
+
private alive;
|
|
52
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { windowsPowerShellPath } from "./host-process-supervisor.js";
|
|
4
|
+
const execFileAsync = promisify(execFile);
|
|
5
|
+
export const systemWindowsProcessTable = {
|
|
6
|
+
async list() {
|
|
7
|
+
const { stdout } = await execFileAsync(windowsPowerShellPath(), [
|
|
8
|
+
"-NoLogo", "-NoProfile", "-NonInteractive", "-Command",
|
|
9
|
+
"Get-CimInstance Win32_Process | ForEach-Object { \"$($_.ProcessId) $($_.ParentProcessId) $($_.CreationDate.ToUniversalTime().Ticks)\" }",
|
|
10
|
+
], { encoding: "utf8", windowsHide: true, maxBuffer: 8 * 1024 * 1024, timeout: 30_000 });
|
|
11
|
+
return stdout.split(/\r?\n/u).flatMap(line => {
|
|
12
|
+
const [pid, parentPid, createdAt] = line.trim().split(" ");
|
|
13
|
+
return pid && parentPid && createdAt ? [{ pid: Number(pid), parentPid: Number(parentPid), createdAt }] : [];
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
async killTree(pid) {
|
|
17
|
+
await execFileAsync("taskkill", ["/PID", String(pid), "/T", "/F"], { windowsHide: true, timeout: 30_000 })
|
|
18
|
+
.catch(() => undefined);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
/** .NET ticks (100 ns since 0001-01-01 UTC), the unit Win32_Process creation times are read in. */
|
|
22
|
+
export function windowsTicksFromEpochMs(epochMs) {
|
|
23
|
+
return ((BigInt(Math.floor(epochMs)) + 62135596800000n) * 10000n).toString();
|
|
24
|
+
}
|
|
25
|
+
/** A Windows command's tracked tree; see the module comment. */
|
|
26
|
+
export class WindowsProcessTree {
|
|
27
|
+
rootPid;
|
|
28
|
+
table;
|
|
29
|
+
marker;
|
|
30
|
+
known = new Map();
|
|
31
|
+
/** The root's creation time as the process table reports it, once seen. */
|
|
32
|
+
observedRoot = null;
|
|
33
|
+
rootExited = false;
|
|
34
|
+
/**
|
|
35
|
+
* The root marker anchors the tree even if the root exits before the first
|
|
36
|
+
* snapshot (or, for a reaped token, before the reaper runs): descendants
|
|
37
|
+
* created after it whose parent was the root are still found. A tree with
|
|
38
|
+
* no marker that never saw its root cannot be proven gone.
|
|
39
|
+
*/
|
|
40
|
+
constructor(rootPid, table, marker = null) {
|
|
41
|
+
this.rootPid = rootPid;
|
|
42
|
+
this.table = table;
|
|
43
|
+
this.marker = marker;
|
|
44
|
+
const anchor = this.rootAnchor();
|
|
45
|
+
if (anchor !== null)
|
|
46
|
+
this.known.set(rootPid, anchor);
|
|
47
|
+
}
|
|
48
|
+
/** The root has exited: from now on its pid only names it if its exact creation was seen. */
|
|
49
|
+
markRootExited() {
|
|
50
|
+
this.rootExited = true;
|
|
51
|
+
}
|
|
52
|
+
/** Records the root's current descendants; call while the command runs. */
|
|
53
|
+
async track() {
|
|
54
|
+
const entries = await this.table.list().catch(() => null);
|
|
55
|
+
if (entries)
|
|
56
|
+
this.absorb(entries);
|
|
57
|
+
}
|
|
58
|
+
/** Stops every tracked member and proves none is left; false when one survives or nothing anchors the tree. */
|
|
59
|
+
async stop(deadlineMs) {
|
|
60
|
+
for (;;) {
|
|
61
|
+
const entries = await this.table.list().catch(() => null);
|
|
62
|
+
if (!entries) {
|
|
63
|
+
if (Date.now() >= deadlineMs)
|
|
64
|
+
return false;
|
|
65
|
+
await delay(200);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
this.absorb(entries);
|
|
69
|
+
// Without any anchor nothing proves which processes were the root's: fail closed.
|
|
70
|
+
if (!this.known.has(this.rootPid))
|
|
71
|
+
return false;
|
|
72
|
+
const alive = this.alive(entries);
|
|
73
|
+
if (alive.length === 0)
|
|
74
|
+
return true;
|
|
75
|
+
if (Date.now() >= deadlineMs)
|
|
76
|
+
return false;
|
|
77
|
+
for (const pid of alive)
|
|
78
|
+
await this.table.killTree(pid);
|
|
79
|
+
await delay(100);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
rootAnchor() {
|
|
83
|
+
if (this.observedRoot !== null)
|
|
84
|
+
return this.observedRoot;
|
|
85
|
+
if (this.marker === null)
|
|
86
|
+
return null;
|
|
87
|
+
return "exactCreatedAt" in this.marker ? this.marker.exactCreatedAt : this.marker.notBefore;
|
|
88
|
+
}
|
|
89
|
+
isRoot(entry) {
|
|
90
|
+
if (entry.pid !== this.rootPid)
|
|
91
|
+
return false;
|
|
92
|
+
if (this.observedRoot !== null)
|
|
93
|
+
return entry.createdAt === this.observedRoot;
|
|
94
|
+
if (this.marker !== null && "exactCreatedAt" in this.marker)
|
|
95
|
+
return ticksClose(entry.createdAt, this.marker.exactCreatedAt);
|
|
96
|
+
// Before it exits, the root's pid cannot name anyone else.
|
|
97
|
+
if (this.rootExited)
|
|
98
|
+
return false;
|
|
99
|
+
return this.marker === null || compareTicks(entry.createdAt, this.marker.notBefore) >= 0;
|
|
100
|
+
}
|
|
101
|
+
absorb(entries) {
|
|
102
|
+
const root = entries.find(entry => this.isRoot(entry));
|
|
103
|
+
if (root && this.observedRoot === null)
|
|
104
|
+
this.observedRoot = root.createdAt;
|
|
105
|
+
const anchor = this.rootAnchor();
|
|
106
|
+
if (anchor !== null)
|
|
107
|
+
this.known.set(this.rootPid, anchor);
|
|
108
|
+
// Parents first: repeat until no new descendant of a known member appears.
|
|
109
|
+
let added = true;
|
|
110
|
+
while (added) {
|
|
111
|
+
added = false;
|
|
112
|
+
for (const entry of entries) {
|
|
113
|
+
if (this.known.has(entry.pid) || entry.pid === entry.parentPid)
|
|
114
|
+
continue;
|
|
115
|
+
const parentCreatedAt = this.known.get(entry.parentPid);
|
|
116
|
+
// A child is never older than its parent; an older one only reuses the parent's pid as its parent id.
|
|
117
|
+
if (parentCreatedAt === undefined || compareTicks(entry.createdAt, parentCreatedAt) < 0)
|
|
118
|
+
continue;
|
|
119
|
+
this.known.set(entry.pid, entry.createdAt);
|
|
120
|
+
added = true;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
alive(entries) {
|
|
125
|
+
return entries
|
|
126
|
+
.filter(entry => entry.pid === this.rootPid ? this.isRoot(entry) : this.known.get(entry.pid) === entry.createdAt)
|
|
127
|
+
.map(entry => entry.pid);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function ticksClose(left, right) {
|
|
131
|
+
if (!/^\d+$/u.test(left) || !/^\d+$/u.test(right))
|
|
132
|
+
return left === right;
|
|
133
|
+
const difference = BigInt(left) - BigInt(right);
|
|
134
|
+
return (difference < 0n ? -difference : difference) <= 10000n;
|
|
135
|
+
}
|
|
136
|
+
function compareTicks(left, right) {
|
|
137
|
+
if (/^\d+$/u.test(left) && /^\d+$/u.test(right)) {
|
|
138
|
+
return left.length === right.length ? left.localeCompare(right) : left.length - right.length;
|
|
139
|
+
}
|
|
140
|
+
return left.localeCompare(right);
|
|
141
|
+
}
|
|
142
|
+
async function delay(ms) {
|
|
143
|
+
await new Promise(resolve => setTimeout(resolve, ms));
|
|
144
|
+
}
|
|
@@ -1,16 +1,86 @@
|
|
|
1
|
+
import { type WindowsProcessTable } from "./process-tree.js";
|
|
1
2
|
export interface ProcessRunRequest {
|
|
2
3
|
readonly command: string;
|
|
3
4
|
readonly args: readonly string[];
|
|
4
5
|
readonly cwd: string;
|
|
6
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
7
|
+
readonly rawOutput?: boolean;
|
|
8
|
+
readonly windowsVerbatimArguments?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Stops the child (SIGTERM, then SIGKILL after a grace period) and rejects
|
|
11
|
+
* with an AbortError, but only once the child has exited, and with
|
|
12
|
+
* `processGroup` once its whole tree is proven gone: a caller that returns
|
|
13
|
+
* capacity on rejection never does so while the command still runs.
|
|
14
|
+
*/
|
|
15
|
+
readonly signal?: AbortSignal;
|
|
16
|
+
/**
|
|
17
|
+
* Treat the command's whole process tree as the step: it is stopped as a
|
|
18
|
+
* whole (on abort, and whatever outlives the command when it exits) and the
|
|
19
|
+
* run settles only once no member is left. Unix: the command leads its own
|
|
20
|
+
* process group. Windows (no process groups): the tree is tracked while the
|
|
21
|
+
* command runs and stopped with `taskkill /T /F`; see process-tree.ts. If the
|
|
22
|
+
* tree cannot be proven gone the run rejects with ProcessTreeTerminationError.
|
|
23
|
+
*/
|
|
24
|
+
readonly processGroup?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Keeps at most this many characters of each stream: the tail, after a
|
|
27
|
+
* truncation notice. Unbounded when omitted.
|
|
28
|
+
*/
|
|
29
|
+
readonly maxOutputChars?: number;
|
|
30
|
+
/** Called with the child's pid once it has spawned. */
|
|
31
|
+
readonly onSpawn?: (pid: number) => void;
|
|
5
32
|
}
|
|
6
33
|
export interface ProcessRunResult {
|
|
7
34
|
readonly exitCode: number;
|
|
8
35
|
readonly stdout: string;
|
|
9
36
|
readonly stderr: string;
|
|
37
|
+
/** True when maxOutputChars dropped the head of either stream. */
|
|
38
|
+
readonly outputTruncated?: boolean;
|
|
10
39
|
}
|
|
11
40
|
export interface ProcessRunner {
|
|
12
41
|
run(request: ProcessRunRequest): Promise<ProcessRunResult>;
|
|
13
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* A command's process tree could not be proven gone after it was stopped.
|
|
45
|
+
* Whatever reserved capacity for it must keep that reservation.
|
|
46
|
+
*/
|
|
47
|
+
export declare class ProcessTreeTerminationError extends Error {
|
|
48
|
+
readonly rootPid: number;
|
|
49
|
+
readonly command: string;
|
|
50
|
+
readonly stillGone: () => Promise<boolean>;
|
|
51
|
+
readonly code = "process_tree_termination_unconfirmed";
|
|
52
|
+
/**
|
|
53
|
+
* `stillGone` resolves true once the tree is proven gone (Unix: an existence
|
|
54
|
+
* check only, since its members were already SIGKILLed; Windows: another
|
|
55
|
+
* tracked stop), for callers that hold the reservation until then.
|
|
56
|
+
*/
|
|
57
|
+
constructor(rootPid: number, command: string, stillGone: () => Promise<boolean>);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* True when `error`, or anything it wraps (an AggregateError's errors, a cause
|
|
61
|
+
* chain, a sanitized copy that kept only the message), says a process tree
|
|
62
|
+
* could not be proven gone. Whoever holds capacity for that tree must keep it.
|
|
63
|
+
*/
|
|
64
|
+
export declare function isProcessTreeTerminationUnproven(error: unknown, depth?: number): boolean;
|
|
65
|
+
export interface NodeProcessRunnerOptions {
|
|
66
|
+
/** How long a stopped command gets after SIGTERM before SIGKILL. */
|
|
67
|
+
readonly terminationGraceMs?: number;
|
|
68
|
+
/** How long to wait for a SIGKILLed tree to disappear before giving up. */
|
|
69
|
+
readonly killWaitMs?: number;
|
|
70
|
+
/** Test seams for the Windows tree path. */
|
|
71
|
+
readonly platform?: NodeJS.Platform;
|
|
72
|
+
readonly windowsProcesses?: WindowsProcessTable;
|
|
73
|
+
readonly windowsTrackIntervalMs?: number;
|
|
74
|
+
/** Test seam: whether a Unix process group still has members. */
|
|
75
|
+
readonly groupAlive?: (groupId: number) => boolean;
|
|
76
|
+
}
|
|
14
77
|
export declare class NodeProcessRunner implements ProcessRunner {
|
|
78
|
+
private readonly graceMs;
|
|
79
|
+
private readonly killWaitMs;
|
|
80
|
+
private readonly platform;
|
|
81
|
+
private readonly windowsProcesses;
|
|
82
|
+
private readonly windowsTrackIntervalMs;
|
|
83
|
+
private readonly groupAlive;
|
|
84
|
+
constructor(options?: NodeProcessRunnerOptions);
|
|
15
85
|
run(request: ProcessRunRequest): Promise<ProcessRunResult>;
|
|
16
86
|
}
|