@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 0.1.4-dev.03584818ede5
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 +146 -5
- package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
- package/dist/bridge/bridge-chat-provider-command.js +137 -0
- package/dist/bridge/bridge-chat.types.d.ts +121 -0
- package/dist/bridge/bridge-chat.types.js +416 -0
- package/dist/bridge/bridge.base.d.ts +13 -1
- package/dist/bridge/bridge.service.d.ts +155 -4
- package/dist/bridge/bridge.service.js +1805 -155
- package/dist/bridge/bridge.types.d.ts +68 -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/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 +21 -0
- package/dist/bridge/readiness-result-outbox.js +54 -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/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup.service.d.ts +10 -0
- package/dist/cleanup/cleanup.service.js +128 -104
- package/dist/cleanup/cleanup.types.d.ts +4 -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 +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -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 +22 -4
- package/dist/cli/cli.service.d.ts +30 -6
- package/dist/cli/cli.service.js +216 -31
- package/dist/cli/local-config.d.ts +5 -0
- package/dist/cli/local-config.js +30 -4
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +429 -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 +90 -0
- package/dist/runtime/docker-engine-probe.js +333 -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 +184 -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 +185 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +78 -0
- package/dist/runtime/host-load-sampler.d.ts +149 -0
- package/dist/runtime/host-load-sampler.js +291 -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 +16 -1
- package/dist/runtime/host-runtime-contract.js +174 -56
- package/dist/runtime/host-runtime-lease.d.ts +163 -9
- package/dist/runtime/host-runtime-lease.js +1464 -121
- 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 +607 -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 +25 -0
- package/dist/runtime/native-test-postgres-fallback.js +91 -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 +100 -0
- package/dist/runtime/runner-settings.js +214 -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 +113 -0
- package/dist/sandbox/host-capacity-broker.js +334 -0
- package/dist/sandbox/preflight.d.ts +31 -1
- package/dist/sandbox/preflight.js +237 -51
- 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 +182 -109
- 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 +44 -1
- package/dist/session/managed-attempt-tools.js +816 -46
- 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 +21 -0
- package/dist/session/managed-build-receipt.js +337 -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 +319 -44
- 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 +15 -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 +18 -3
- package/dist/session/phase-completion.prompts.js +22 -18
- package/dist/session/phase-completion.runtime.d.ts +6 -2
- package/dist/session/phase-completion.runtime.js +191 -47
- 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-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 +11 -0
- package/dist/session/pre-publication-step-execution.js +49 -0
- package/dist/session/pre-publication-validation.d.ts +87 -0
- package/dist/session/pre-publication-validation.js +668 -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 +66 -0
- package/dist/session/provider-cli/claude-background-work.js +180 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
- package/dist/session/provider-cli/pre-publication-repair.js +243 -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 +73 -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 +92 -14
- package/dist/session/provider-cli/provider-cli.process.js +583 -210
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +12 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +200 -25
- 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 +14 -1
- package/dist/session/provider-cli/provider-cli.runtime.js +61 -3
- package/dist/session/provider-cli/provider-cli.service.d.ts +33 -5
- package/dist/session/provider-cli/provider-cli.service.js +819 -84
- 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-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/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +238 -0
- package/dist/session/session-redaction.js +434 -9
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +9 -2
- package/dist/session/session.service.js +264 -27
- package/dist/session/session.types.d.ts +150 -2
- package/dist/session/session.types.js +599 -7
- 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/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.js +3 -2
- package/dist/shared/process/host-process-supervisor.d.ts +3 -0
- package/dist/shared/process/host-process-supervisor.js +61 -12
- 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 +84 -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/worktree.service.d.ts +17 -1
- package/dist/worktree/worktree.service.js +293 -21
- package/dist/worktree/worktree.types.d.ts +14 -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,19 @@ 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;
|
|
53
74
|
}
|
|
54
75
|
export interface BridgeRepoMapping {
|
|
55
76
|
readonly repoId?: string | null;
|
|
@@ -72,6 +93,20 @@ export interface BridgeProviderStatus {
|
|
|
72
93
|
readonly version?: string | null;
|
|
73
94
|
readonly models?: readonly string[] | null;
|
|
74
95
|
}
|
|
96
|
+
export interface BridgeToolCapability {
|
|
97
|
+
readonly available: boolean;
|
|
98
|
+
readonly executable: string;
|
|
99
|
+
readonly version?: string | null;
|
|
100
|
+
}
|
|
101
|
+
export interface BridgeToolchainCapabilities {
|
|
102
|
+
readonly node: BridgeToolCapability;
|
|
103
|
+
readonly pnpm: BridgeToolCapability;
|
|
104
|
+
readonly dotnet: BridgeToolCapability;
|
|
105
|
+
readonly git: BridgeToolCapability;
|
|
106
|
+
readonly bash: BridgeToolCapability;
|
|
107
|
+
readonly powershell: BridgeToolCapability;
|
|
108
|
+
readonly docker?: BridgeToolCapability | null;
|
|
109
|
+
}
|
|
75
110
|
export interface BridgeCapabilities {
|
|
76
111
|
readonly schemaVersion?: number | null;
|
|
77
112
|
readonly activeSessionCount?: number | null;
|
|
@@ -83,6 +118,8 @@ export interface BridgeCapabilities {
|
|
|
83
118
|
readonly sandboxProfiles?: readonly string[] | null;
|
|
84
119
|
readonly runnerInstanceId?: string | null;
|
|
85
120
|
readonly trustDomainId?: string | null;
|
|
121
|
+
readonly executionFacilities?: readonly string[] | null;
|
|
122
|
+
readonly dockerEngine?: DockerEngineCapabilitySnapshot | null;
|
|
86
123
|
readonly sandboxRuntimes?: readonly string[] | null;
|
|
87
124
|
readonly sandboxRuntimeVersion?: string | null;
|
|
88
125
|
readonly sandboxFeatures?: SandboxFeatureMatrix | null;
|
|
@@ -110,6 +147,22 @@ export interface BridgeCapabilities {
|
|
|
110
147
|
readonly supportsDraftRunOnce?: boolean | null;
|
|
111
148
|
readonly supportsDraftAttachments?: boolean | null;
|
|
112
149
|
readonly supportsDraftImageAttachments?: boolean | null;
|
|
150
|
+
readonly bridgeChat?: BridgeChatCapability | null;
|
|
151
|
+
readonly toolchains?: BridgeToolchainCapabilities | null;
|
|
152
|
+
readonly playwrightProjects?: readonly string[] | null;
|
|
153
|
+
readonly browserLaunch?: boolean | null;
|
|
154
|
+
readonly providerConnectivity?: Readonly<Record<string, boolean>> | null;
|
|
155
|
+
/** Native test PostgreSQL and whether its role is a superuser (decision 0013 placement). */
|
|
156
|
+
readonly testPostgres?: BridgeTestPostgresCapability | null;
|
|
157
|
+
/** Static host hardware facts (schema 7). Material: changes are persisted immediately. */
|
|
158
|
+
readonly host?: HostFacts | null;
|
|
159
|
+
/** Live host load sample (schema 7). Never material: heartbeats with only load changes are not persisted. */
|
|
160
|
+
readonly load?: HostLoadSnapshot | null;
|
|
161
|
+
/** Decision 0014 (schema 8): server settings support and the last `SettingsApplied` report. Material. */
|
|
162
|
+
readonly settings?: BridgeSettingsCapability | null;
|
|
163
|
+
}
|
|
164
|
+
export interface BridgeSettingsCapability extends RunnerSettingsReport {
|
|
165
|
+
readonly supportsServerSettings: true;
|
|
113
166
|
}
|
|
114
167
|
export interface SandboxMemoryCapacityDiagnostics {
|
|
115
168
|
readonly defaultWorkerMemoryLimitBytes: number;
|
|
@@ -119,7 +172,10 @@ export interface SandboxMemoryCapacityDiagnostics {
|
|
|
119
172
|
readonly activeReservationBytes: number;
|
|
120
173
|
readonly daemonTotalBytes: number;
|
|
121
174
|
readonly daemonAvailableBytes: number;
|
|
175
|
+
readonly hostAvailableBytes: number;
|
|
176
|
+
readonly conservativeAvailableBytes: number;
|
|
122
177
|
readonly availableForAdmissionBytes: number;
|
|
178
|
+
readonly memoryAdmission: MemoryAdmissionDiagnostics;
|
|
123
179
|
}
|
|
124
180
|
export interface BridgeHelloRequest {
|
|
125
181
|
readonly version: string;
|
|
@@ -200,7 +256,9 @@ export interface BridgeLeaseUpdateRequest {
|
|
|
200
256
|
readonly runnerInstanceId: string;
|
|
201
257
|
readonly expiresAt: string;
|
|
202
258
|
}
|
|
203
|
-
export interface BridgeCancelRequest {
|
|
259
|
+
export interface BridgeCancelRequest extends ChatTurnCancelPacket {
|
|
260
|
+
/** When present, cancels only this pre-start reservation, never an active session. */
|
|
261
|
+
readonly dispatchAttemptId?: string | null;
|
|
204
262
|
readonly leaseId: string;
|
|
205
263
|
readonly fencingToken: string;
|
|
206
264
|
readonly reason?: string | null;
|
|
@@ -223,6 +281,7 @@ export interface BridgeAttemptSnapshotResponse extends BridgeCallbackAck {
|
|
|
223
281
|
readonly generatedAt?: string | null;
|
|
224
282
|
}
|
|
225
283
|
export type BridgeDispatchHandler = (dispatch: unknown) => Promise<void>;
|
|
284
|
+
export type BridgeChatTurnHandler = (dispatch: unknown) => Promise<void>;
|
|
226
285
|
export type BridgeOfferHandler = (dispatch: unknown) => Promise<void>;
|
|
227
286
|
export type BridgeStartHandler = (dispatch: unknown) => Promise<void>;
|
|
228
287
|
export type BridgeLeaseUpdateHandler = (request: BridgeLeaseUpdateRequest) => Promise<void>;
|
|
@@ -254,11 +313,19 @@ export interface BridgeRuntimeReadinessResult {
|
|
|
254
313
|
readonly status: "parallel_ready" | "serialized" | "failed";
|
|
255
314
|
readonly runtimeContractFingerprint?: string | null;
|
|
256
315
|
readonly runtimeContractSource?: string | null;
|
|
316
|
+
readonly runtimeRequirements?: HostRuntimeRequirements | null;
|
|
257
317
|
readonly reasonCode?: string | null;
|
|
258
318
|
readonly reasonMessage?: string | null;
|
|
259
319
|
readonly qaAppLaunchTarget?: BridgeRuntimeReadinessQaLaunchTarget | null;
|
|
260
320
|
readonly checkedAt: string;
|
|
261
321
|
}
|
|
322
|
+
export interface BridgeRuntimeReadinessAccepted {
|
|
323
|
+
readonly schemaVersion: 1;
|
|
324
|
+
readonly requestId: string;
|
|
325
|
+
readonly fencingToken: string;
|
|
326
|
+
readonly runnerInstanceId: string;
|
|
327
|
+
readonly acceptedAt: string;
|
|
328
|
+
}
|
|
262
329
|
export interface BridgeRuntimeReadinessQaLaunchTarget {
|
|
263
330
|
readonly managedRuntimePort: string;
|
|
264
331
|
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
|
+
`;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { SignalRBridgeConnection, SignalRBridgeConnectionFactory, defaultBridgeServiceConfig } from "./bridge.service.js";
|
|
2
|
+
export { bridgeChatProtocolVersion, bridgeChatUpdateRequiredCode, normalizeBridgeChatCapability, parseChatTurnDispatchPacket, unavailableBridgeChatCapability } from "./bridge-chat.types.js";
|
|
2
3
|
export type { BridgeConnection, BridgeConnectionFactory } from "./bridge.base.js";
|
|
4
|
+
export type { BridgeChatCapability, ChatTurnDispatchPacket } from "./bridge-chat.types.js";
|
|
3
5
|
export type { BridgeCallbackAck, BridgeCancelHandler, BridgeCancelRequest, BridgeCapabilities, BridgeDispatchEventCallback, BridgeDispatchHandler, BridgeDispatchResultCallback, BridgeHeartbeatRequest, BridgeHelloRequest, BridgeRepoMapping, BridgeServiceConfig } from "./bridge.types.js";
|
package/dist/bridge/internals.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
1
|
export { SignalRBridgeConnection, SignalRBridgeConnectionFactory, defaultBridgeServiceConfig } from "./bridge.service.js";
|
|
2
|
+
export { bridgeChatProtocolVersion, bridgeChatUpdateRequiredCode, normalizeBridgeChatCapability, parseChatTurnDispatchPacket, unavailableBridgeChatCapability } from "./bridge-chat.types.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** `<config dir>/<config name>.yield.json`, e.g. `~/.config/forge/bridge.yield.json` beside `bridge.json`. */
|
|
2
|
+
export declare function localYieldFlagPathFor(configPath: string): string;
|
|
3
|
+
/** The local flag; a missing or unreadable file means off. */
|
|
4
|
+
export declare function readLocalYieldFlag(flagPath: string): Promise<boolean>;
|
|
5
|
+
/** Writes the flag atomically with mode 0600. */
|
|
6
|
+
export declare function writeLocalYieldFlag(flagPath: string, yieldToForeground: boolean): Promise<void>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
/** `<config dir>/<config name>.yield.json`, e.g. `~/.config/forge/bridge.yield.json` beside `bridge.json`. */
|
|
5
|
+
export function localYieldFlagPathFor(configPath) {
|
|
6
|
+
const parsed = path.parse(path.resolve(configPath));
|
|
7
|
+
return path.join(parsed.dir, `${parsed.name}.yield.json`);
|
|
8
|
+
}
|
|
9
|
+
/** The local flag; a missing or unreadable file means off. */
|
|
10
|
+
export async function readLocalYieldFlag(flagPath) {
|
|
11
|
+
try {
|
|
12
|
+
const parsed = JSON.parse(await fs.readFile(flagPath, "utf8"));
|
|
13
|
+
return parsed?.schemaVersion === 1 && parsed.yieldToForeground === true;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Writes the flag atomically with mode 0600. */
|
|
20
|
+
export async function writeLocalYieldFlag(flagPath, yieldToForeground) {
|
|
21
|
+
const content = { schemaVersion: 1, yieldToForeground, updatedAt: new Date().toISOString() };
|
|
22
|
+
await fs.mkdir(path.dirname(flagPath), { recursive: true, mode: 0o700 });
|
|
23
|
+
const temporary = `${flagPath}.${process.pid}.${randomUUID()}.tmp`;
|
|
24
|
+
try {
|
|
25
|
+
await fs.writeFile(temporary, `${JSON.stringify(content, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
26
|
+
// The umask can narrow the create mode but never widen it; set it exactly.
|
|
27
|
+
await fs.chmod(temporary, 0o600);
|
|
28
|
+
await fs.rename(temporary, flagPath);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
await fs.rm(temporary, { force: true }).catch(() => undefined);
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BridgeRuntimeReadinessResult } from "./bridge.types.js";
|
|
2
|
+
export interface DurableReadinessResult {
|
|
3
|
+
readonly schemaVersion: 1;
|
|
4
|
+
readonly expiresAt: string;
|
|
5
|
+
readonly persistedAt: string;
|
|
6
|
+
readonly result: BridgeRuntimeReadinessResult;
|
|
7
|
+
}
|
|
8
|
+
export interface ReadinessResultOutbox {
|
|
9
|
+
persist(result: BridgeRuntimeReadinessResult, expiresAt: string): Promise<void>;
|
|
10
|
+
pending(): Promise<readonly DurableReadinessResult[]>;
|
|
11
|
+
acknowledge(requestId: string): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare class FileReadinessResultOutbox implements ReadinessResultOutbox {
|
|
14
|
+
private readonly stateRoot;
|
|
15
|
+
private readonly writes;
|
|
16
|
+
constructor(stateRoot: string);
|
|
17
|
+
persist(result: BridgeRuntimeReadinessResult, expiresAt: string): Promise<void>;
|
|
18
|
+
pending(): Promise<readonly DurableReadinessResult[]>;
|
|
19
|
+
acknowledge(requestId: string): Promise<void>;
|
|
20
|
+
private operate;
|
|
21
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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 { readinessReceiptWorker } from "./readiness-result-worker.js";
|
|
6
|
+
export class FileReadinessResultOutbox {
|
|
7
|
+
stateRoot;
|
|
8
|
+
writes = new Map();
|
|
9
|
+
constructor(stateRoot) {
|
|
10
|
+
this.stateRoot = stateRoot;
|
|
11
|
+
}
|
|
12
|
+
async persist(result, expiresAt) {
|
|
13
|
+
const name = recordName(result.requestId);
|
|
14
|
+
// Capture caller-owned data before yielding. Compare semantic JSON, not key order.
|
|
15
|
+
const value = JSON.parse(JSON.stringify({ result, expiresAt }));
|
|
16
|
+
const pending = this.writes.get(name);
|
|
17
|
+
if (pending) {
|
|
18
|
+
if (!isDeepStrictEqual(pending.value, value))
|
|
19
|
+
throw new Error("runtime_readiness_result_conflict: request identity reused.");
|
|
20
|
+
return await pending.write;
|
|
21
|
+
}
|
|
22
|
+
const write = this.operate({ kind: "persist", name, record: {
|
|
23
|
+
schemaVersion: 1, persistedAt: new Date().toISOString(), ...value,
|
|
24
|
+
} }).then(() => undefined);
|
|
25
|
+
this.writes.set(name, { value, write });
|
|
26
|
+
try {
|
|
27
|
+
await write;
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
if (this.writes.get(name)?.write === write)
|
|
31
|
+
this.writes.delete(name);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async pending() {
|
|
35
|
+
return JSON.parse(await this.operate({ kind: "pending" }));
|
|
36
|
+
}
|
|
37
|
+
async acknowledge(requestId) {
|
|
38
|
+
await this.operate({ kind: "acknowledge", name: recordName(requestId) });
|
|
39
|
+
}
|
|
40
|
+
async operate(operation) {
|
|
41
|
+
const root = path.resolve(this.stateRoot, "readiness-results");
|
|
42
|
+
await createCanonicalDirectory(root);
|
|
43
|
+
const identity = await assertCanonicalDirectory(root);
|
|
44
|
+
if (!identity)
|
|
45
|
+
throw new Error("runtime_readiness_result_invalid: outbox directory is missing.");
|
|
46
|
+
return await runPinnedDirectoryProcess(root, identity, readinessReceiptWorker, operation, undefined, 256 * 256 * 1024 + 1024);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function recordName(requestId) {
|
|
50
|
+
const value = requestId.replaceAll("-", "").toLowerCase();
|
|
51
|
+
if (!/^[0-9a-f]{32}$/u.test(value))
|
|
52
|
+
throw new Error("runtime_readiness_result_invalid: request id must be a UUID.");
|
|
53
|
+
return `${value}.json`;
|
|
54
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/** Runs in a bounded async child. Receipt IO stays relative to verified, pinned cwd. */
|
|
2
|
+
export const readinessReceiptWorker = 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 = 256 * 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}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{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.expiresAt) && validDate(record.persistedAt) && record.result
|
|
17
|
+
&& record.result.schemaVersion === 1 && uuid(record.result.requestId) && uuid(record.result.fencingToken)
|
|
18
|
+
&& uuid(record.result.runnerInstanceId) && validDate(record.result.checkedAt)
|
|
19
|
+
&& ['parallel_ready', 'serialized', 'failed'].includes(record.result.status)
|
|
20
|
+
&& record.result.requestId.replaceAll('-', '').toLowerCase() + '.json' === name;
|
|
21
|
+
const read = name => {
|
|
22
|
+
if (!validName(name)) throw new Error('runtime_readiness_result_invalid: invalid name');
|
|
23
|
+
let before;
|
|
24
|
+
try { before = fs.lstatSync(name, { bigint: true }); }
|
|
25
|
+
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
26
|
+
// Atomic publishers may briefly hold their own second hard link until cleanup.
|
|
27
|
+
if (!before.isFile() || before.isSymbolicLink() || before.size > BigInt(maximumBytes))
|
|
28
|
+
throw new Error('runtime_readiness_result_invalid: not a bounded regular file');
|
|
29
|
+
const fd = fs.openSync(name, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0));
|
|
30
|
+
try {
|
|
31
|
+
const opened = fs.fstatSync(fd, { bigint: true });
|
|
32
|
+
if (!same(before, opened) || !opened.isFile() || opened.size !== before.size)
|
|
33
|
+
throw new Error('runtime_readiness_result_invalid: receipt identity changed');
|
|
34
|
+
let baseline = opened;
|
|
35
|
+
let firstRead;
|
|
36
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
37
|
+
const bytes = Buffer.alloc(Number(opened.size));
|
|
38
|
+
let offset = 0;
|
|
39
|
+
while (offset < bytes.length) {
|
|
40
|
+
const count = fs.readSync(fd, bytes, offset, bytes.length - offset, offset);
|
|
41
|
+
if (!count) throw new Error('runtime_readiness_result_invalid: incomplete receipt');
|
|
42
|
+
offset += count;
|
|
43
|
+
}
|
|
44
|
+
const after = fs.fstatSync(fd, { bigint: true });
|
|
45
|
+
const current = fs.lstatSync(name, { bigint: true });
|
|
46
|
+
if (!same(opened, after) || !same(after, current) || !current.isFile() || current.isSymbolicLink()
|
|
47
|
+
|| !sameReadMetadata(baseline, after) || !sameReadMetadata(after, current))
|
|
48
|
+
throw new Error('runtime_readiness_result_invalid: receipt changed during read');
|
|
49
|
+
if (!samePublicationMetadata(baseline, after) || !samePublicationMetadata(after, current)) {
|
|
50
|
+
// A publisher may unlink its temporary hard link between either stat.
|
|
51
|
+
// This is only a retry fence, never permission to trust unstable bytes.
|
|
52
|
+
if (attempt !== 0 || job.kind !== 'persist' || baseline.nlink !== 2n || current.nlink !== 1n
|
|
53
|
+
|| baseline.ctimeNs === current.ctimeNs
|
|
54
|
+
|| (!samePublicationMetadata(baseline, after) && !samePublicationMetadata(after, current)))
|
|
55
|
+
throw new Error('runtime_readiness_result_invalid: receipt changed during read');
|
|
56
|
+
firstRead = bytes;
|
|
57
|
+
baseline = current;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (firstRead && !bytes.equals(firstRead))
|
|
61
|
+
throw new Error('runtime_readiness_result_invalid: receipt changed during read');
|
|
62
|
+
const record = JSON.parse(bytes.toString('utf8'));
|
|
63
|
+
if (!validRecord(record, name)) throw new Error('runtime_readiness_result_invalid: malformed or wrong identity');
|
|
64
|
+
return record;
|
|
65
|
+
}
|
|
66
|
+
throw new Error('runtime_readiness_result_invalid: receipt changed during read');
|
|
67
|
+
} finally { fs.closeSync(fd); }
|
|
68
|
+
};
|
|
69
|
+
const identical = (existing, candidate) => {
|
|
70
|
+
if (!isDeepStrictEqual(existing.result, candidate.result) || existing.expiresAt !== candidate.expiresAt)
|
|
71
|
+
throw new Error('runtime_readiness_result_conflict: request identity reused');
|
|
72
|
+
};
|
|
73
|
+
try {
|
|
74
|
+
const cwd = fs.statSync('.', { bigint: true });
|
|
75
|
+
const real = fs.realpathSync('.');
|
|
76
|
+
if (!same(cwd, { dev: BigInt(job.dev), ino: BigInt(job.ino) })
|
|
77
|
+
|| (process.platform === 'win32' ? real.toLowerCase() !== job.parent.toLowerCase() : real !== job.parent))
|
|
78
|
+
throw new Error('runtime_readiness_result_invalid: parent identity changed');
|
|
79
|
+
if (job.kind === 'persist') {
|
|
80
|
+
if (!validName(job.name) || !validRecord(job.record, job.name)) throw new Error('runtime_readiness_result_invalid: invalid candidate');
|
|
81
|
+
const content = JSON.stringify(job.record) + '\n';
|
|
82
|
+
if (Buffer.byteLength(content) > maximumBytes) throw new Error('runtime_readiness_result_invalid: receipt too large');
|
|
83
|
+
const existing = read(job.name);
|
|
84
|
+
if (existing) identical(existing, job.record);
|
|
85
|
+
else {
|
|
86
|
+
const temporary = job.name + '.' + randomUUID() + '.tmp';
|
|
87
|
+
let owned = false;
|
|
88
|
+
try {
|
|
89
|
+
const fd = fs.openSync(temporary, 'wx', 0o600);
|
|
90
|
+
owned = true;
|
|
91
|
+
try { fs.writeFileSync(fd, content, 'utf8'); fs.fsyncSync(fd); }
|
|
92
|
+
finally { fs.closeSync(fd); }
|
|
93
|
+
try { fs.linkSync(temporary, job.name); }
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (error.code !== 'EEXIST') throw error;
|
|
96
|
+
const winner = read(job.name);
|
|
97
|
+
if (!winner) throw error;
|
|
98
|
+
identical(winner, job.record);
|
|
99
|
+
}
|
|
100
|
+
} finally { if (owned) fs.unlinkSync(temporary); }
|
|
101
|
+
}
|
|
102
|
+
} else if (job.kind === 'pending') {
|
|
103
|
+
const records = [];
|
|
104
|
+
const directory = fs.opendirSync('.');
|
|
105
|
+
try {
|
|
106
|
+
let entry;
|
|
107
|
+
while (records.length < 256 && (entry = directory.readSync()) !== null) {
|
|
108
|
+
if (!entry.isFile() || !validName(entry.name)) continue;
|
|
109
|
+
try { const record = read(entry.name); if (record) records.push(record); }
|
|
110
|
+
catch { /* Retain malformed evidence; never send it as a trusted callback. */ }
|
|
111
|
+
}
|
|
112
|
+
} finally { directory.closeSync(); }
|
|
113
|
+
records.sort((a, b) => a.persistedAt.localeCompare(b.persistedAt));
|
|
114
|
+
process.stdout.write(JSON.stringify(records));
|
|
115
|
+
} else if (job.kind === 'acknowledge') {
|
|
116
|
+
if (!validName(job.name)) throw new Error('runtime_readiness_result_invalid: invalid name');
|
|
117
|
+
// unlink is relative to pinned cwd and never follows a replaced leaf link.
|
|
118
|
+
try { fs.unlinkSync(job.name); } catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
119
|
+
} else throw new Error('runtime_readiness_result_invalid: invalid operation');
|
|
120
|
+
} catch (error) { process.stderr.write(error.message); process.exitCode = 1; }
|
|
121
|
+
`;
|