@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 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 +232 -5
- 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 +13 -1
- package/dist/bridge/bridge.service.d.ts +169 -14
- package/dist/bridge/bridge.service.js +1868 -330
- package/dist/bridge/bridge.types.d.ts +73 -1
- 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 +21 -1
- package/dist/cleanup/cleanup.service.js +185 -143
- package/dist/cleanup/cleanup.types.d.ts +6 -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/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +78 -16
- package/dist/cli/cli.service.d.ts +32 -15
- package/dist/cli/cli.service.js +206 -182
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +7 -0
- package/dist/cli/local-config.js +36 -4
- 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 +2 -1
- package/dist/runtime/attempt-node-runtime-launcher.js +57 -18
- 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.d.ts +35 -0
- package/dist/runtime/attempt-process-supervisor.js +144 -23
- 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 +10 -0
- package/dist/runtime/generated-output-reset.js +62 -8
- 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 +8 -1
- package/dist/runtime/host-listener-inspector.js +121 -60
- 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-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +28 -1
- package/dist/runtime/host-runtime-contract.js +203 -57
- package/dist/runtime/host-runtime-lease.d.ts +163 -9
- package/dist/runtime/host-runtime-lease.js +1427 -124
- package/dist/runtime/host-runtime-promotion.d.ts +35 -3
- package/dist/runtime/host-runtime-promotion.js +107 -12
- 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 +3 -0
- package/dist/runtime/node-host-runtime-adapter.js +29 -11
- 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 +19 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +113 -59
- 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.js +4 -1
- package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
- package/dist/runtime/workspace-resource-estimator.js +174 -0
- package/dist/sandbox/host-capacity-broker.d.ts +115 -0
- package/dist/sandbox/host-capacity-broker.js +336 -0
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +36 -0
- package/dist/sandbox/preflight.d.ts +31 -1
- package/dist/sandbox/preflight.js +237 -51
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/repository-lock.d.ts +2 -1
- package/dist/sandbox/repository-lock.js +19 -9
- package/dist/sandbox/runtime.d.ts +16 -2
- package/dist/sandbox/runtime.js +183 -114
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox.types.d.ts +7 -0
- package/dist/sandbox/workspace.service.js +2 -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 +37 -1
- package/dist/session/managed-attempt-tools.js +822 -84
- 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 +24 -0
- package/dist/session/phase-completion.artifacts.js +321 -45
- 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 +23 -1
- package/dist/session/phase-completion.helpers.d.ts +5 -0
- package/dist/session/phase-completion.helpers.js +43 -19
- package/dist/session/phase-completion.js +19 -3
- 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.js +22 -18
- package/dist/session/phase-completion.runtime.d.ts +6 -10
- package/dist/session/phase-completion.runtime.js +214 -224
- 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 -3
- package/dist/session/phase-completion.schemas.js +250 -226
- package/dist/session/phase-completion.validation.d.ts +3 -3
- package/dist/session/phase-completion.validation.js +135 -89
- 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 +8 -0
- package/dist/session/provider-cli/ci-repair-readiness.js +23 -3
- 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 +6 -3
- package/dist/session/provider-cli/provider-cli.artifacts.js +62 -22
- 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.js +34 -2
- 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 +85 -19
- package/dist/session/provider-cli/provider-cli.process.js +566 -283
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +211 -36
- 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 +22 -1
- package/dist/session/provider-cli/provider-cli.runtime.js +83 -4
- package/dist/session/provider-cli/provider-cli.service.d.ts +36 -5
- package/dist/session/provider-cli/provider-cli.service.js +818 -99
- package/dist/session/provider-cli/provider-cli.types.d.ts +32 -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 +18 -0
- package/dist/session/provider-cli/provider-output-state.js +376 -17
- 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.js +284 -9
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +11 -2
- package/dist/session/session.service.js +301 -58
- package/dist/session/session.types.d.ts +150 -2
- package/dist/session/session.types.js +599 -7
- 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 +18 -0
- 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 +14 -3
- package/dist/shared/process/host-process-recovery.js +26 -5
- package/dist/shared/process/host-process-supervisor.d.ts +16 -1
- package/dist/shared/process/host-process-supervisor.js +124 -23
- 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 +69 -0
- package/dist/shared/process/process.js +223 -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 +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.d.ts +3 -0
- package/dist/shared/provider-capabilities.js +92 -0
- package/dist/shared/redaction/redaction.d.ts +1 -0
- package/dist/shared/redaction/redaction.js +39 -3
- 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/dependency-warmer.d.ts +66 -9
- package/dist/worktree/dependency-warmer.js +609 -24
- package/dist/worktree/index.d.ts +1 -1
- 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-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 +7 -1
- package/dist/worktree/worktree.service.d.ts +22 -2
- package/dist/worktree/worktree.service.js +302 -25
- package/dist/worktree/worktree.types.d.ts +36 -1
- package/package.json +8 -6
- package/runtime/windows-job-supervisor.ps1 +380 -14
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
import type { HostRuntimeRequirements } from "../runtime/host-runtime-requirements.js";
|
|
2
|
+
import type { BridgeTestPostgresCapability } from "./test-postgres-capability.js";
|
|
1
3
|
import type { ApiKeySecretGrant, DispatchSandboxResourceRequest, RunOnceResultPacket, RunnerDispatchEvent } from "../session/session.types.js";
|
|
2
4
|
import type { SandboxFeatureMatrix } from "../sandbox/sandbox.types.js";
|
|
3
5
|
import type { HostRuntimeCapacitySnapshot } from "../runtime/host-runtime-lease.js";
|
|
6
|
+
import type { MemoryAdmissionDiagnostics } from "../runtime/memory-capacity.js";
|
|
7
|
+
import type { DockerEngineCapabilitySnapshot } from "../runtime/docker-engine-probe.js";
|
|
8
|
+
import type { HostFacts } from "../runtime/host-facts.js";
|
|
9
|
+
import type { HostLoadSnapshot } from "../runtime/host-load-sampler.js";
|
|
10
|
+
import type { RunnerSettingsReport } from "../runtime/runner-settings.js";
|
|
11
|
+
import type { BridgeChatCapability, ChatTurnCancelPacket } from "./bridge-chat.types.js";
|
|
4
12
|
export interface BridgeServiceConfig {
|
|
5
13
|
readonly serverUrl: string;
|
|
6
14
|
readonly runnerId: string;
|
|
@@ -14,7 +22,12 @@ export interface BridgeServiceConfig {
|
|
|
14
22
|
readonly sandboxPublicationMode?: "bridge_push" | "shared_filesystem";
|
|
15
23
|
readonly dockerExecutable: string;
|
|
16
24
|
readonly dockerContext: string;
|
|
25
|
+
readonly dockerDesktopRecoveryEnabled: boolean;
|
|
26
|
+
readonly dockerRecoveryFailureThreshold: number;
|
|
27
|
+
readonly dockerRecoveryCooldownMs: number;
|
|
28
|
+
readonly dockerRecoveryStartupTimeoutMs: number;
|
|
17
29
|
readonly sandboxStateRoot: string;
|
|
30
|
+
readonly sandboxExecutionRoot: string;
|
|
18
31
|
readonly requireRootlessDocker: boolean;
|
|
19
32
|
readonly diskHighWatermarkPercent: number;
|
|
20
33
|
readonly diskLowWatermarkPercent: number;
|
|
@@ -45,11 +58,24 @@ export interface BridgeServiceConfig {
|
|
|
45
58
|
readonly supportsDraftRunOnce: boolean;
|
|
46
59
|
readonly supportsDraftAttachments: boolean;
|
|
47
60
|
readonly supportsDraftImageAttachments: boolean;
|
|
61
|
+
readonly bridgeChat: BridgeChatCapability;
|
|
48
62
|
readonly version: string;
|
|
49
63
|
readonly protocolVersion: number;
|
|
50
64
|
readonly minServerVersion?: string | null;
|
|
51
65
|
readonly heartbeatIntervalMs: number;
|
|
66
|
+
readonly callbackAckTimeoutMs?: number;
|
|
67
|
+
readonly heartbeatDockerProbeWaitMs?: number;
|
|
52
68
|
readonly reconnectBackoffMs: readonly number[];
|
|
69
|
+
/**
|
|
70
|
+
* Decision 0014: the `forge-bridge yield` flag file next to the bridge config,
|
|
71
|
+
* polled while running. Null or absent: no local yield flag.
|
|
72
|
+
*/
|
|
73
|
+
readonly localYieldFlagPath?: string | null;
|
|
74
|
+
/**
|
|
75
|
+
* Where the running bridge publishes whether it is idle (`bridge.state.json` next to
|
|
76
|
+
* the bridge config), read by `forge-bridge status --idle`. Null or absent: not published.
|
|
77
|
+
*/
|
|
78
|
+
readonly bridgeStatePath?: string | null;
|
|
53
79
|
}
|
|
54
80
|
export interface BridgeRepoMapping {
|
|
55
81
|
readonly repoId?: string | null;
|
|
@@ -72,6 +98,20 @@ export interface BridgeProviderStatus {
|
|
|
72
98
|
readonly version?: string | null;
|
|
73
99
|
readonly models?: readonly string[] | null;
|
|
74
100
|
}
|
|
101
|
+
export interface BridgeToolCapability {
|
|
102
|
+
readonly available: boolean;
|
|
103
|
+
readonly executable: string;
|
|
104
|
+
readonly version?: string | null;
|
|
105
|
+
}
|
|
106
|
+
export interface BridgeToolchainCapabilities {
|
|
107
|
+
readonly node: BridgeToolCapability;
|
|
108
|
+
readonly pnpm: BridgeToolCapability;
|
|
109
|
+
readonly dotnet: BridgeToolCapability;
|
|
110
|
+
readonly git: BridgeToolCapability;
|
|
111
|
+
readonly bash: BridgeToolCapability;
|
|
112
|
+
readonly powershell: BridgeToolCapability;
|
|
113
|
+
readonly docker?: BridgeToolCapability | null;
|
|
114
|
+
}
|
|
75
115
|
export interface BridgeCapabilities {
|
|
76
116
|
readonly schemaVersion?: number | null;
|
|
77
117
|
readonly activeSessionCount?: number | null;
|
|
@@ -83,6 +123,8 @@ export interface BridgeCapabilities {
|
|
|
83
123
|
readonly sandboxProfiles?: readonly string[] | null;
|
|
84
124
|
readonly runnerInstanceId?: string | null;
|
|
85
125
|
readonly trustDomainId?: string | null;
|
|
126
|
+
readonly executionFacilities?: readonly string[] | null;
|
|
127
|
+
readonly dockerEngine?: DockerEngineCapabilitySnapshot | null;
|
|
86
128
|
readonly sandboxRuntimes?: readonly string[] | null;
|
|
87
129
|
readonly sandboxRuntimeVersion?: string | null;
|
|
88
130
|
readonly sandboxFeatures?: SandboxFeatureMatrix | null;
|
|
@@ -110,6 +152,22 @@ export interface BridgeCapabilities {
|
|
|
110
152
|
readonly supportsDraftRunOnce?: boolean | null;
|
|
111
153
|
readonly supportsDraftAttachments?: boolean | null;
|
|
112
154
|
readonly supportsDraftImageAttachments?: boolean | null;
|
|
155
|
+
readonly bridgeChat?: BridgeChatCapability | null;
|
|
156
|
+
readonly toolchains?: BridgeToolchainCapabilities | null;
|
|
157
|
+
readonly playwrightProjects?: readonly string[] | null;
|
|
158
|
+
readonly browserLaunch?: boolean | null;
|
|
159
|
+
readonly providerConnectivity?: Readonly<Record<string, boolean>> | null;
|
|
160
|
+
/** Native test PostgreSQL and whether its role is a superuser (decision 0013 placement). */
|
|
161
|
+
readonly testPostgres?: BridgeTestPostgresCapability | null;
|
|
162
|
+
/** Static host hardware facts (schema 7). Material: changes are persisted immediately. */
|
|
163
|
+
readonly host?: HostFacts | null;
|
|
164
|
+
/** Live host load sample (schema 7). Never material: heartbeats with only load changes are not persisted. */
|
|
165
|
+
readonly load?: HostLoadSnapshot | null;
|
|
166
|
+
/** Decision 0014 (schema 8): server settings support and the last `SettingsApplied` report. Material. */
|
|
167
|
+
readonly settings?: BridgeSettingsCapability | null;
|
|
168
|
+
}
|
|
169
|
+
export interface BridgeSettingsCapability extends RunnerSettingsReport {
|
|
170
|
+
readonly supportsServerSettings: true;
|
|
113
171
|
}
|
|
114
172
|
export interface SandboxMemoryCapacityDiagnostics {
|
|
115
173
|
readonly defaultWorkerMemoryLimitBytes: number;
|
|
@@ -119,7 +177,10 @@ export interface SandboxMemoryCapacityDiagnostics {
|
|
|
119
177
|
readonly activeReservationBytes: number;
|
|
120
178
|
readonly daemonTotalBytes: number;
|
|
121
179
|
readonly daemonAvailableBytes: number;
|
|
180
|
+
readonly hostAvailableBytes: number;
|
|
181
|
+
readonly conservativeAvailableBytes: number;
|
|
122
182
|
readonly availableForAdmissionBytes: number;
|
|
183
|
+
readonly memoryAdmission: MemoryAdmissionDiagnostics;
|
|
123
184
|
}
|
|
124
185
|
export interface BridgeHelloRequest {
|
|
125
186
|
readonly version: string;
|
|
@@ -200,7 +261,9 @@ export interface BridgeLeaseUpdateRequest {
|
|
|
200
261
|
readonly runnerInstanceId: string;
|
|
201
262
|
readonly expiresAt: string;
|
|
202
263
|
}
|
|
203
|
-
export interface BridgeCancelRequest {
|
|
264
|
+
export interface BridgeCancelRequest extends ChatTurnCancelPacket {
|
|
265
|
+
/** When present, cancels only this pre-start reservation, never an active session. */
|
|
266
|
+
readonly dispatchAttemptId?: string | null;
|
|
204
267
|
readonly leaseId: string;
|
|
205
268
|
readonly fencingToken: string;
|
|
206
269
|
readonly reason?: string | null;
|
|
@@ -223,6 +286,7 @@ export interface BridgeAttemptSnapshotResponse extends BridgeCallbackAck {
|
|
|
223
286
|
readonly generatedAt?: string | null;
|
|
224
287
|
}
|
|
225
288
|
export type BridgeDispatchHandler = (dispatch: unknown) => Promise<void>;
|
|
289
|
+
export type BridgeChatTurnHandler = (dispatch: unknown) => Promise<void>;
|
|
226
290
|
export type BridgeOfferHandler = (dispatch: unknown) => Promise<void>;
|
|
227
291
|
export type BridgeStartHandler = (dispatch: unknown) => Promise<void>;
|
|
228
292
|
export type BridgeLeaseUpdateHandler = (request: BridgeLeaseUpdateRequest) => Promise<void>;
|
|
@@ -254,11 +318,19 @@ export interface BridgeRuntimeReadinessResult {
|
|
|
254
318
|
readonly status: "parallel_ready" | "serialized" | "failed";
|
|
255
319
|
readonly runtimeContractFingerprint?: string | null;
|
|
256
320
|
readonly runtimeContractSource?: string | null;
|
|
321
|
+
readonly runtimeRequirements?: HostRuntimeRequirements | null;
|
|
257
322
|
readonly reasonCode?: string | null;
|
|
258
323
|
readonly reasonMessage?: string | null;
|
|
259
324
|
readonly qaAppLaunchTarget?: BridgeRuntimeReadinessQaLaunchTarget | null;
|
|
260
325
|
readonly checkedAt: string;
|
|
261
326
|
}
|
|
327
|
+
export interface BridgeRuntimeReadinessAccepted {
|
|
328
|
+
readonly schemaVersion: 1;
|
|
329
|
+
readonly requestId: string;
|
|
330
|
+
readonly fencingToken: string;
|
|
331
|
+
readonly runnerInstanceId: string;
|
|
332
|
+
readonly acceptedAt: string;
|
|
333
|
+
}
|
|
262
334
|
export interface BridgeRuntimeReadinessQaLaunchTarget {
|
|
263
335
|
readonly managedRuntimePort: string;
|
|
264
336
|
readonly routes: readonly string[];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { BridgeDispatchResultCallback } from "./bridge.types.js";
|
|
2
|
+
export interface DurableDispatchResult {
|
|
3
|
+
readonly schemaVersion: 1;
|
|
4
|
+
readonly persistedAt: string;
|
|
5
|
+
readonly payload: BridgeDispatchResultCallback;
|
|
6
|
+
}
|
|
7
|
+
export interface DispatchResultOutbox {
|
|
8
|
+
persist(payload: BridgeDispatchResultCallback): Promise<void>;
|
|
9
|
+
pending(): Promise<readonly DurableDispatchResult[]>;
|
|
10
|
+
acknowledge(leaseId: string): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Moves an undeliverable record out of the replay set. The redacted result
|
|
13
|
+
* is kept, with its original persistedAt, so preserved work can be reconciled.
|
|
14
|
+
*/
|
|
15
|
+
quarantine(record: DurableDispatchResult): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export declare const dispatchResultOutboxDirectory = "dispatch-results";
|
|
18
|
+
export declare const dispatchResultQuarantineDirectory = "dispatch-results-quarantine";
|
|
19
|
+
/**
|
|
20
|
+
* Persists the already-redacted terminal result before the Bridge attempts its
|
|
21
|
+
* SignalR callback. A transport or API restart can therefore delay delivery,
|
|
22
|
+
* but cannot turn successful provider work into a fabricated failed result.
|
|
23
|
+
*/
|
|
24
|
+
export declare class FileDispatchResultOutbox implements DispatchResultOutbox {
|
|
25
|
+
private readonly stateRoot;
|
|
26
|
+
private readonly directory;
|
|
27
|
+
private readonly writes;
|
|
28
|
+
constructor(stateRoot: string, directory?: string);
|
|
29
|
+
persist(payload: BridgeDispatchResultCallback): Promise<void>;
|
|
30
|
+
private persistRecord;
|
|
31
|
+
pending(): Promise<readonly DurableDispatchResult[]>;
|
|
32
|
+
acknowledge(leaseId: string): Promise<void>;
|
|
33
|
+
quarantine(record: DurableDispatchResult): Promise<void>;
|
|
34
|
+
private operate;
|
|
35
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
3
|
+
import { assertCanonicalDirectory, createCanonicalDirectory } from "../runtime/attempt-private-directory.js";
|
|
4
|
+
import { runPinnedDirectoryProcess } from "../runtime/pinned-directory-process.js";
|
|
5
|
+
import { dispatchResultReceiptWorker } from "./dispatch-result-worker.js";
|
|
6
|
+
export const dispatchResultOutboxDirectory = "dispatch-results";
|
|
7
|
+
export const dispatchResultQuarantineDirectory = "dispatch-results-quarantine";
|
|
8
|
+
/**
|
|
9
|
+
* Persists the already-redacted terminal result before the Bridge attempts its
|
|
10
|
+
* SignalR callback. A transport or API restart can therefore delay delivery,
|
|
11
|
+
* but cannot turn successful provider work into a fabricated failed result.
|
|
12
|
+
*/
|
|
13
|
+
export class FileDispatchResultOutbox {
|
|
14
|
+
stateRoot;
|
|
15
|
+
directory;
|
|
16
|
+
writes = new Map();
|
|
17
|
+
constructor(stateRoot, directory = dispatchResultOutboxDirectory) {
|
|
18
|
+
this.stateRoot = stateRoot;
|
|
19
|
+
this.directory = directory;
|
|
20
|
+
}
|
|
21
|
+
async persist(payload) {
|
|
22
|
+
await this.persistRecord(payload, new Date().toISOString());
|
|
23
|
+
}
|
|
24
|
+
async persistRecord(payload, persistedAt) {
|
|
25
|
+
const name = recordName(payload.leaseId);
|
|
26
|
+
const value = JSON.parse(JSON.stringify({ payload }));
|
|
27
|
+
const pending = this.writes.get(name);
|
|
28
|
+
if (pending) {
|
|
29
|
+
if (!isDeepStrictEqual(pending.value, value)) {
|
|
30
|
+
throw new Error("dispatch_result_conflict: lease identity reused with a different result.");
|
|
31
|
+
}
|
|
32
|
+
return await pending.write;
|
|
33
|
+
}
|
|
34
|
+
const write = this.operate({
|
|
35
|
+
kind: "persist",
|
|
36
|
+
name,
|
|
37
|
+
record: { schemaVersion: 1, persistedAt, ...value },
|
|
38
|
+
}).then(() => undefined);
|
|
39
|
+
this.writes.set(name, { value, write });
|
|
40
|
+
try {
|
|
41
|
+
await write;
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
if (this.writes.get(name)?.write === write)
|
|
45
|
+
this.writes.delete(name);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async pending() {
|
|
49
|
+
return JSON.parse(await this.operate({ kind: "pending" }));
|
|
50
|
+
}
|
|
51
|
+
async acknowledge(leaseId) {
|
|
52
|
+
await this.operate({ kind: "acknowledge", name: recordName(leaseId) });
|
|
53
|
+
}
|
|
54
|
+
async quarantine(record) {
|
|
55
|
+
// One execution lease can carry several dispatch attempts, so quarantine
|
|
56
|
+
// files are grouped per attempt: <quarantine>/<attempt>/<lease>.json.
|
|
57
|
+
// Copy before removal: a crash in between leaves an identical record in
|
|
58
|
+
// both places, and the next replay quarantines it again idempotently.
|
|
59
|
+
// A record without an attempt id has no per-attempt bucket; the caller
|
|
60
|
+
// keeps it deferred rather than grouping unrelated attempts together.
|
|
61
|
+
const { payload } = record;
|
|
62
|
+
if (!payload.dispatchAttemptId) {
|
|
63
|
+
throw new Error("dispatch_result_invalid: only attempt-bound results can be quarantined.");
|
|
64
|
+
}
|
|
65
|
+
const bucket = path.join(dispatchResultQuarantineDirectory, compactUuid(payload.dispatchAttemptId));
|
|
66
|
+
await new FileDispatchResultOutbox(this.stateRoot, bucket).persistRecord(payload, record.persistedAt);
|
|
67
|
+
await this.acknowledge(payload.leaseId);
|
|
68
|
+
}
|
|
69
|
+
async operate(operation) {
|
|
70
|
+
const root = path.resolve(this.stateRoot, this.directory);
|
|
71
|
+
await createCanonicalDirectory(root);
|
|
72
|
+
const identity = await assertCanonicalDirectory(root);
|
|
73
|
+
if (!identity)
|
|
74
|
+
throw new Error("dispatch_result_invalid: outbox directory is missing.");
|
|
75
|
+
return await runPinnedDirectoryProcess(root, identity, dispatchResultReceiptWorker, operation, undefined, 256 * 1024 * 1024);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function recordName(leaseId) {
|
|
79
|
+
return `${compactUuid(leaseId)}.json`;
|
|
80
|
+
}
|
|
81
|
+
function compactUuid(id) {
|
|
82
|
+
const value = id.replaceAll("-", "").toLowerCase();
|
|
83
|
+
if (!/^[0-9a-f]{32}$/u.test(value)) {
|
|
84
|
+
throw new Error("dispatch_result_invalid: identifiers must be UUIDs.");
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/** Runs in a bounded async child. Receipt IO stays relative to verified, pinned cwd. */
|
|
2
|
+
export const dispatchResultReceiptWorker = String.raw `
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const { randomUUID } = require('node:crypto');
|
|
5
|
+
const { isDeepStrictEqual } = require('node:util');
|
|
6
|
+
const job = JSON.parse(fs.readFileSync(0, 'utf8'));
|
|
7
|
+
const maximumBytes = 64 * 1024 * 1024;
|
|
8
|
+
const same = (a, b) => a.dev === b.dev && a.ino === b.ino;
|
|
9
|
+
const sameReadMetadata = (a, b) => a.size === b.size && a.mtimeNs === b.mtimeNs
|
|
10
|
+
&& a.mode === b.mode && a.uid === b.uid && a.gid === b.gid && a.birthtimeNs === b.birthtimeNs;
|
|
11
|
+
const samePublicationMetadata = (a, b) => a.ctimeNs === b.ctimeNs && a.nlink === b.nlink;
|
|
12
|
+
const validDate = value => typeof value === 'string' && Number.isFinite(Date.parse(value));
|
|
13
|
+
const uuid = value => typeof value === 'string' && /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(value);
|
|
14
|
+
const validName = name => typeof name === 'string' && /^[0-9a-f]{32}\.json$/.test(name);
|
|
15
|
+
const validRecord = (record, name) => record && record.schemaVersion === 1
|
|
16
|
+
&& validDate(record.persistedAt) && record.payload
|
|
17
|
+
&& uuid(record.payload.leaseId) && uuid(record.payload.fencingToken)
|
|
18
|
+
&& (record.payload.dispatchAttemptId == null || uuid(record.payload.dispatchAttemptId))
|
|
19
|
+
&& (record.payload.runnerInstanceId == null || uuid(record.payload.runnerInstanceId))
|
|
20
|
+
&& record.payload.result && Number.isInteger(record.payload.result.exitCode)
|
|
21
|
+
&& typeof record.payload.result.summary === 'string'
|
|
22
|
+
&& Array.isArray(record.payload.result.events)
|
|
23
|
+
&& record.payload.leaseId.replaceAll('-', '').toLowerCase() + '.json' === name;
|
|
24
|
+
const read = name => {
|
|
25
|
+
if (!validName(name)) throw new Error('dispatch_result_invalid: invalid name');
|
|
26
|
+
let before;
|
|
27
|
+
try { before = fs.lstatSync(name, { bigint: true }); }
|
|
28
|
+
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
29
|
+
if (!before.isFile() || before.isSymbolicLink() || before.size > BigInt(maximumBytes))
|
|
30
|
+
throw new Error('dispatch_result_invalid: not a bounded regular file');
|
|
31
|
+
const fd = fs.openSync(name, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0));
|
|
32
|
+
try {
|
|
33
|
+
const opened = fs.fstatSync(fd, { bigint: true });
|
|
34
|
+
if (!same(before, opened) || !opened.isFile() || opened.size !== before.size)
|
|
35
|
+
throw new Error('dispatch_result_invalid: receipt identity changed');
|
|
36
|
+
let baseline = opened;
|
|
37
|
+
let firstRead;
|
|
38
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
39
|
+
const bytes = Buffer.alloc(Number(opened.size));
|
|
40
|
+
let offset = 0;
|
|
41
|
+
while (offset < bytes.length) {
|
|
42
|
+
const count = fs.readSync(fd, bytes, offset, bytes.length - offset, offset);
|
|
43
|
+
if (!count) throw new Error('dispatch_result_invalid: incomplete receipt');
|
|
44
|
+
offset += count;
|
|
45
|
+
}
|
|
46
|
+
const after = fs.fstatSync(fd, { bigint: true });
|
|
47
|
+
const current = fs.lstatSync(name, { bigint: true });
|
|
48
|
+
if (!same(opened, after) || !same(after, current) || !current.isFile() || current.isSymbolicLink()
|
|
49
|
+
|| !sameReadMetadata(baseline, after) || !sameReadMetadata(after, current))
|
|
50
|
+
throw new Error('dispatch_result_invalid: receipt changed during read');
|
|
51
|
+
if (!samePublicationMetadata(baseline, after) || !samePublicationMetadata(after, current)) {
|
|
52
|
+
// A publisher may unlink its temporary hard link between either stat.
|
|
53
|
+
// This is only a retry fence, never permission to trust unstable bytes.
|
|
54
|
+
if (attempt !== 0 || job.kind !== 'persist' || baseline.nlink !== 2n || current.nlink !== 1n
|
|
55
|
+
|| baseline.ctimeNs === current.ctimeNs
|
|
56
|
+
|| (!samePublicationMetadata(baseline, after) && !samePublicationMetadata(after, current)))
|
|
57
|
+
throw new Error('dispatch_result_invalid: receipt changed during read');
|
|
58
|
+
firstRead = bytes;
|
|
59
|
+
baseline = current;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (firstRead && !bytes.equals(firstRead))
|
|
63
|
+
throw new Error('dispatch_result_invalid: receipt changed during read');
|
|
64
|
+
const record = JSON.parse(bytes.toString('utf8'));
|
|
65
|
+
if (!validRecord(record, name)) throw new Error('dispatch_result_invalid: malformed or wrong identity');
|
|
66
|
+
return record;
|
|
67
|
+
}
|
|
68
|
+
throw new Error('dispatch_result_invalid: receipt changed during read');
|
|
69
|
+
} finally { fs.closeSync(fd); }
|
|
70
|
+
};
|
|
71
|
+
const identical = (existing, candidate) => {
|
|
72
|
+
if (!isDeepStrictEqual(existing.payload, candidate.payload))
|
|
73
|
+
throw new Error('dispatch_result_conflict: lease identity reused with a different result');
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
const cwd = fs.statSync('.', { bigint: true });
|
|
77
|
+
const real = fs.realpathSync('.');
|
|
78
|
+
if (!same(cwd, { dev: BigInt(job.dev), ino: BigInt(job.ino) })
|
|
79
|
+
|| (process.platform === 'win32' ? real.toLowerCase() !== job.parent.toLowerCase() : real !== job.parent))
|
|
80
|
+
throw new Error('dispatch_result_invalid: parent identity changed');
|
|
81
|
+
if (job.kind === 'persist') {
|
|
82
|
+
if (!validName(job.name) || !validRecord(job.record, job.name)) throw new Error('dispatch_result_invalid: invalid candidate');
|
|
83
|
+
const content = JSON.stringify(job.record) + '\n';
|
|
84
|
+
if (Buffer.byteLength(content) > maximumBytes) throw new Error('dispatch_result_invalid: receipt too large');
|
|
85
|
+
const existing = read(job.name);
|
|
86
|
+
if (existing) identical(existing, job.record);
|
|
87
|
+
else {
|
|
88
|
+
const temporary = job.name + '.' + randomUUID() + '.tmp';
|
|
89
|
+
let owned = false;
|
|
90
|
+
try {
|
|
91
|
+
const fd = fs.openSync(temporary, 'wx', 0o600);
|
|
92
|
+
owned = true;
|
|
93
|
+
try { fs.writeFileSync(fd, content, 'utf8'); fs.fsyncSync(fd); }
|
|
94
|
+
finally { fs.closeSync(fd); }
|
|
95
|
+
try { fs.linkSync(temporary, job.name); }
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (error.code !== 'EEXIST') throw error;
|
|
98
|
+
const winner = read(job.name);
|
|
99
|
+
if (!winner) throw error;
|
|
100
|
+
identical(winner, job.record);
|
|
101
|
+
}
|
|
102
|
+
} finally { if (owned) fs.unlinkSync(temporary); }
|
|
103
|
+
}
|
|
104
|
+
} else if (job.kind === 'pending') {
|
|
105
|
+
const records = [];
|
|
106
|
+
const directory = fs.opendirSync('.');
|
|
107
|
+
try {
|
|
108
|
+
let entry;
|
|
109
|
+
while (records.length < 3 && (entry = directory.readSync()) !== null) {
|
|
110
|
+
if (!entry.isFile() || !validName(entry.name)) continue;
|
|
111
|
+
try { const record = read(entry.name); if (record) records.push(record); }
|
|
112
|
+
catch { /* Retain malformed evidence; never send it as a trusted callback. */ }
|
|
113
|
+
}
|
|
114
|
+
} finally { directory.closeSync(); }
|
|
115
|
+
records.sort((a, b) => a.persistedAt.localeCompare(b.persistedAt));
|
|
116
|
+
process.stdout.write(JSON.stringify(records));
|
|
117
|
+
} else if (job.kind === 'acknowledge') {
|
|
118
|
+
if (!validName(job.name)) throw new Error('dispatch_result_invalid: invalid name');
|
|
119
|
+
try { fs.unlinkSync(job.name); } catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
120
|
+
} else throw new Error('dispatch_result_invalid: invalid operation');
|
|
121
|
+
} catch (error) { process.stderr.write(error.message); process.exitCode = 1; }
|
|
122
|
+
`;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export type InFlightKind = "offer" | "start" | "dispatch" | "chat_turn" | "readiness_probe" | "reservation" | "session"
|
|
2
|
+
/** The bridge could not read its own ledgers; treated as busy. */
|
|
3
|
+
| "unknown";
|
|
4
|
+
export interface InFlightIds {
|
|
5
|
+
readonly dispatchAttemptId?: string;
|
|
6
|
+
readonly leaseId?: string;
|
|
7
|
+
readonly sessionId?: string;
|
|
8
|
+
readonly cycleRunId?: string;
|
|
9
|
+
readonly workItemId?: string;
|
|
10
|
+
readonly turnId?: string;
|
|
11
|
+
readonly requestId?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface InFlightEntry {
|
|
14
|
+
readonly kind: InFlightKind;
|
|
15
|
+
readonly ids: InFlightIds;
|
|
16
|
+
readonly phase: string;
|
|
17
|
+
/** When this bridge took the work on, or null when the ledger does not record it. */
|
|
18
|
+
readonly since: string | null;
|
|
19
|
+
/** When the current phase began, or null when unknown. */
|
|
20
|
+
readonly phaseSince: string | null;
|
|
21
|
+
}
|
|
22
|
+
export type InFlightSource = () => readonly InFlightEntry[];
|
|
23
|
+
export declare class BridgeInFlightRegistry {
|
|
24
|
+
private readonly now;
|
|
25
|
+
private readonly tracked;
|
|
26
|
+
private readonly sources;
|
|
27
|
+
private readonly listeners;
|
|
28
|
+
private nextKey;
|
|
29
|
+
constructor(now?: () => Date);
|
|
30
|
+
/** Starts tracking one piece of work; returns the key that ends it. */
|
|
31
|
+
begin(kind: InFlightKind, ids: InFlightIds, phase?: string): number;
|
|
32
|
+
end(key: number): void;
|
|
33
|
+
/** Moves every tracked entry for this lease to a new phase. */
|
|
34
|
+
notePhase(leaseId: string, phase: string | null | undefined): void;
|
|
35
|
+
/** Tracks a hub handler for as long as it runs, whether it resolves or throws. */
|
|
36
|
+
track<T>(kind: InFlightKind, raw: unknown, run: () => Promise<T>): Promise<T>;
|
|
37
|
+
addSource(source: InFlightSource): void;
|
|
38
|
+
onChange(listener: () => void): () => void;
|
|
39
|
+
snapshot(): InFlightEntry[];
|
|
40
|
+
get idle(): boolean;
|
|
41
|
+
private changed;
|
|
42
|
+
}
|
|
43
|
+
/** Reads the ids of a hub payload: an Offer/Start envelope, a dispatch packet, a chat turn or a readiness probe. */
|
|
44
|
+
export declare function inFlightIdsFrom(raw: unknown): InFlightIds;
|
|
45
|
+
/** Accepted offers whose Start has not arrived yet. A claimed one is the Start handler's. */
|
|
46
|
+
export declare function reservationInFlightEntries(reservations: ReadonlyMap<string, {
|
|
47
|
+
readonly leaseId: string;
|
|
48
|
+
readonly reservedUntil: string;
|
|
49
|
+
readonly startClaim?: unknown;
|
|
50
|
+
}>, now?: number): InFlightEntry[];
|
|
51
|
+
export declare function sessionInFlightEntries(sessions: ReadonlyMap<string, {
|
|
52
|
+
readonly kind: string;
|
|
53
|
+
readonly dispatchAttemptId: string | null;
|
|
54
|
+
readonly turnId?: string;
|
|
55
|
+
}>): InFlightEntry[];
|
|
56
|
+
export declare function readinessInFlightEntries(probes: ReadonlyMap<string, unknown>): InFlightEntry[];
|
|
57
|
+
/** Whether a value read back from the state file is a complete in-flight entry. */
|
|
58
|
+
export declare function isInFlightEntry(value: unknown): value is InFlightEntry;
|
|
59
|
+
/** A server-supplied label (role, phase) made safe for one log line: plain identifier or "unknown". */
|
|
60
|
+
export declare function safeLogLabel(value: unknown): string;
|
|
61
|
+
/** "attempt=…, lease=…, session=…, cycle=…" for log lines and status output. */
|
|
62
|
+
export declare function describeInFlightIds(ids: InFlightIds): string;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// The connected bridge's in-flight work, so a host can tell whether restarting the
|
|
2
|
+
// bridge would kill something (owner, 2026-11-19: a restart killed a develop session
|
|
3
|
+
// that was still in host-runtime preparation, with no agent process yet).
|
|
4
|
+
//
|
|
5
|
+
// Two kinds of entries make up the snapshot:
|
|
6
|
+
// - tracked entries: every Offer, Start, Dispatch, chat turn and readiness probe
|
|
7
|
+
// handler from the moment Forge hands it over until the handler returns, with
|
|
8
|
+
// the phase updated from the runner events the dispatch emits;
|
|
9
|
+
// - source entries: work the bridge still holds after a handler returned or before
|
|
10
|
+
// one is tracked, read from the bridge's own ledgers (accepted offers waiting for
|
|
11
|
+
// Start, active sessions, readiness probes). A source entry that names the same
|
|
12
|
+
// work as a tracked one is dropped.
|
|
13
|
+
// Entries leave the snapshot when the handler settles (success, failure or cancel)
|
|
14
|
+
// or when the ledger releases the work, so nothing has to remember to remove them.
|
|
15
|
+
const idKeys = ["dispatchAttemptId", "leaseId", "sessionId", "cycleRunId", "workItemId", "turnId", "requestId"];
|
|
16
|
+
const identityKeys = ["dispatchAttemptId", "leaseId", "turnId", "requestId"];
|
|
17
|
+
// Ids are written to a local file and logs: keep only plain identifiers.
|
|
18
|
+
const safeId = /^[A-Za-z0-9._:-]{1,200}$/u;
|
|
19
|
+
const safePhase = /^[A-Za-z0-9._:-]{1,120}$/u;
|
|
20
|
+
export class BridgeInFlightRegistry {
|
|
21
|
+
now;
|
|
22
|
+
tracked = new Map();
|
|
23
|
+
sources = [];
|
|
24
|
+
listeners = new Set();
|
|
25
|
+
nextKey = 1;
|
|
26
|
+
constructor(now = () => new Date()) {
|
|
27
|
+
this.now = now;
|
|
28
|
+
}
|
|
29
|
+
/** Starts tracking one piece of work; returns the key that ends it. */
|
|
30
|
+
begin(kind, ids, phase = `${kind}_received`) {
|
|
31
|
+
const key = this.nextKey++;
|
|
32
|
+
const at = this.now().toISOString();
|
|
33
|
+
this.tracked.set(key, { kind, ids, phase: cleanPhase(phase), since: at, phaseSince: at });
|
|
34
|
+
this.changed();
|
|
35
|
+
return key;
|
|
36
|
+
}
|
|
37
|
+
end(key) {
|
|
38
|
+
if (this.tracked.delete(key))
|
|
39
|
+
this.changed();
|
|
40
|
+
}
|
|
41
|
+
/** Moves every tracked entry for this lease to a new phase. */
|
|
42
|
+
notePhase(leaseId, phase) {
|
|
43
|
+
if (!phase || !safePhase.test(phase))
|
|
44
|
+
return;
|
|
45
|
+
let changed = false;
|
|
46
|
+
for (const entry of this.tracked.values()) {
|
|
47
|
+
if (entry.ids.leaseId !== leaseId || entry.phase === phase)
|
|
48
|
+
continue;
|
|
49
|
+
entry.phase = phase;
|
|
50
|
+
entry.phaseSince = this.now().toISOString();
|
|
51
|
+
changed = true;
|
|
52
|
+
}
|
|
53
|
+
if (changed)
|
|
54
|
+
this.changed();
|
|
55
|
+
}
|
|
56
|
+
/** Tracks a hub handler for as long as it runs, whether it resolves or throws. */
|
|
57
|
+
async track(kind, raw, run) {
|
|
58
|
+
const key = this.begin(kind, inFlightIdsFrom(raw));
|
|
59
|
+
try {
|
|
60
|
+
return await run();
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
this.end(key);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
addSource(source) {
|
|
67
|
+
this.sources.push(source);
|
|
68
|
+
}
|
|
69
|
+
onChange(listener) {
|
|
70
|
+
this.listeners.add(listener);
|
|
71
|
+
return () => this.listeners.delete(listener);
|
|
72
|
+
}
|
|
73
|
+
snapshot() {
|
|
74
|
+
const tracked = [...this.tracked.values()].map(entry => ({ ...entry, ids: { ...entry.ids } }));
|
|
75
|
+
const fromSources = [];
|
|
76
|
+
for (const source of this.sources) {
|
|
77
|
+
for (const entry of source()) {
|
|
78
|
+
if (![...tracked, ...fromSources].some(other => sameWork(entry.ids, other.ids)))
|
|
79
|
+
fromSources.push(entry);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return [...tracked, ...fromSources];
|
|
83
|
+
}
|
|
84
|
+
get idle() {
|
|
85
|
+
return this.snapshot().length === 0;
|
|
86
|
+
}
|
|
87
|
+
changed() {
|
|
88
|
+
for (const listener of this.listeners) {
|
|
89
|
+
try {
|
|
90
|
+
listener();
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// A listener (the state file publisher) must never break the bridge.
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** Reads the ids of a hub payload: an Offer/Start envelope, a dispatch packet, a chat turn or a readiness probe. */
|
|
99
|
+
export function inFlightIdsFrom(raw) {
|
|
100
|
+
const root = asRecord(raw);
|
|
101
|
+
if (!root)
|
|
102
|
+
return {};
|
|
103
|
+
const packet = asRecord(field(root, "dispatch")) ?? root;
|
|
104
|
+
const values = {
|
|
105
|
+
dispatchAttemptId: firstId(root, asRecord(field(packet, "sandbox")), "dispatchAttemptId"),
|
|
106
|
+
leaseId: firstId(root, null, "leaseId") ?? firstId(asRecord(field(packet, "lease")), null, "id"),
|
|
107
|
+
sessionId: firstId(asRecord(field(packet, "session")), null, "id"),
|
|
108
|
+
cycleRunId: firstId(asRecord(field(packet, "cycleRun")), null, "id"),
|
|
109
|
+
workItemId: firstId(asRecord(field(packet, "workItem")), null, "id"),
|
|
110
|
+
turnId: firstId(root, null, "turnId"),
|
|
111
|
+
requestId: firstId(root, null, "requestId"),
|
|
112
|
+
};
|
|
113
|
+
return Object.fromEntries(idKeys.flatMap(key => values[key] ? [[key, values[key]]] : []));
|
|
114
|
+
}
|
|
115
|
+
/** Accepted offers whose Start has not arrived yet. A claimed one is the Start handler's. */
|
|
116
|
+
export function reservationInFlightEntries(reservations, now = Date.now()) {
|
|
117
|
+
return [...reservations].flatMap(([dispatchAttemptId, reservation]) => {
|
|
118
|
+
if (Date.parse(reservation.reservedUntil) <= now)
|
|
119
|
+
return [];
|
|
120
|
+
return [{
|
|
121
|
+
kind: "reservation",
|
|
122
|
+
ids: cleanIds({ dispatchAttemptId, leaseId: reservation.leaseId }),
|
|
123
|
+
phase: reservation.startClaim ? "start_claimed" : "awaiting_start",
|
|
124
|
+
since: null,
|
|
125
|
+
phaseSince: null,
|
|
126
|
+
}];
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
export function sessionInFlightEntries(sessions) {
|
|
130
|
+
return [...sessions].map(([leaseId, session]) => ({
|
|
131
|
+
kind: session.kind === "chat" ? "chat_turn" : "session",
|
|
132
|
+
ids: cleanIds({ leaseId, dispatchAttemptId: session.dispatchAttemptId ?? undefined, turnId: session.turnId }),
|
|
133
|
+
phase: "active",
|
|
134
|
+
since: null,
|
|
135
|
+
phaseSince: null,
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
export function readinessInFlightEntries(probes) {
|
|
139
|
+
return [...probes.keys()].map(requestId => ({
|
|
140
|
+
kind: "readiness_probe",
|
|
141
|
+
ids: cleanIds({ requestId }),
|
|
142
|
+
phase: "probing",
|
|
143
|
+
since: null,
|
|
144
|
+
phaseSince: null,
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
const inFlightKinds = new Set([
|
|
148
|
+
"offer", "start", "dispatch", "chat_turn", "readiness_probe", "reservation", "session", "unknown",
|
|
149
|
+
]);
|
|
150
|
+
/** Whether a value read back from the state file is a complete in-flight entry. */
|
|
151
|
+
export function isInFlightEntry(value) {
|
|
152
|
+
const entry = asRecord(value);
|
|
153
|
+
const ids = entry ? asRecord(entry.ids) : null;
|
|
154
|
+
return entry !== null && ids !== null
|
|
155
|
+
&& typeof entry.kind === "string" && inFlightKinds.has(entry.kind)
|
|
156
|
+
&& Object.values(ids).every(id => typeof id === "string")
|
|
157
|
+
&& typeof entry.phase === "string" && entry.phase.length > 0
|
|
158
|
+
&& isNullableString(entry.since) && isNullableString(entry.phaseSince);
|
|
159
|
+
}
|
|
160
|
+
function isNullableString(value) {
|
|
161
|
+
return value === null || typeof value === "string";
|
|
162
|
+
}
|
|
163
|
+
/** A server-supplied label (role, phase) made safe for one log line: plain identifier or "unknown". */
|
|
164
|
+
export function safeLogLabel(value) {
|
|
165
|
+
return typeof value === "string" && safePhase.test(value) ? value : "unknown";
|
|
166
|
+
}
|
|
167
|
+
/** "attempt=…, lease=…, session=…, cycle=…" for log lines and status output. */
|
|
168
|
+
export function describeInFlightIds(ids) {
|
|
169
|
+
const labels = {
|
|
170
|
+
dispatchAttemptId: "attempt",
|
|
171
|
+
leaseId: "lease",
|
|
172
|
+
sessionId: "session",
|
|
173
|
+
cycleRunId: "cycle",
|
|
174
|
+
workItemId: "work item",
|
|
175
|
+
turnId: "turn",
|
|
176
|
+
requestId: "request",
|
|
177
|
+
};
|
|
178
|
+
const parts = idKeys.flatMap(key => ids[key] ? [`${labels[key]} ${ids[key]}`] : []);
|
|
179
|
+
return parts.length > 0 ? parts.join(", ") : "no ids";
|
|
180
|
+
}
|
|
181
|
+
function sameWork(left, right) {
|
|
182
|
+
return identityKeys.some(key => left[key] !== undefined && left[key] === right[key]);
|
|
183
|
+
}
|
|
184
|
+
function cleanIds(values) {
|
|
185
|
+
return Object.fromEntries(idKeys.flatMap(key => {
|
|
186
|
+
const value = values[key];
|
|
187
|
+
return typeof value === "string" && safeId.test(value) ? [[key, value]] : [];
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
function cleanPhase(phase) {
|
|
191
|
+
return safePhase.test(phase) ? phase : "unknown";
|
|
192
|
+
}
|
|
193
|
+
function firstId(primary, fallback, key) {
|
|
194
|
+
for (const source of [primary, fallback]) {
|
|
195
|
+
const value = source ? field(source, key) : undefined;
|
|
196
|
+
if (typeof value === "string" && safeId.test(value))
|
|
197
|
+
return value;
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
// Hub payloads arrive camelCase; older servers sent PascalCase.
|
|
202
|
+
function field(source, camelKey) {
|
|
203
|
+
return source[camelKey] ?? source[camelKey.charAt(0).toUpperCase() + camelKey.slice(1)];
|
|
204
|
+
}
|
|
205
|
+
function asRecord(value) {
|
|
206
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
207
|
+
}
|