@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,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,25 @@
|
|
|
1
|
+
import type { BridgeRuntimeReadinessRequest, 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
|
+
}
|
|
22
|
+
/** A failed result Forge retries later (`host_runtime_probe_deferred`), for a probe the bridge will not run now. */
|
|
23
|
+
export declare function deferredReadinessResult(request: BridgeRuntimeReadinessRequest, runnerInstanceId: string, reasonMessage?: string): BridgeRuntimeReadinessResult;
|
|
24
|
+
/** The deferral reason a probe was aborted with, or null when it was aborted for another reason. */
|
|
25
|
+
export declare function readinessDeferralReason(signal: AbortSignal): string | null;
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
}
|
|
55
|
+
/** A failed result Forge retries later (`host_runtime_probe_deferred`), for a probe the bridge will not run now. */
|
|
56
|
+
export function deferredReadinessResult(request, runnerInstanceId, reasonMessage = "Foreground agent work is active; Forge deferred background runtime readiness so it cannot consume the agent's host capacity.") {
|
|
57
|
+
return {
|
|
58
|
+
schemaVersion: 1,
|
|
59
|
+
requestId: request.requestId,
|
|
60
|
+
fencingToken: request.fencingToken,
|
|
61
|
+
runnerInstanceId,
|
|
62
|
+
status: "failed",
|
|
63
|
+
reasonCode: "host_runtime_probe_deferred",
|
|
64
|
+
reasonMessage,
|
|
65
|
+
checkedAt: new Date().toISOString(),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** The deferral reason a probe was aborted with, or null when it was aborted for another reason. */
|
|
69
|
+
export function readinessDeferralReason(signal) {
|
|
70
|
+
if (!signal.aborted)
|
|
71
|
+
return null;
|
|
72
|
+
const reason = signal.reason instanceof Error ? signal.reason.message : String(signal.reason);
|
|
73
|
+
return reason.startsWith("host_runtime_probe_deferred:") ? reason : null;
|
|
74
|
+
}
|
|
@@ -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
|
+
`;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BridgeServiceConfig, BridgeToolchainCapabilities } from "./bridge.types.js";
|
|
2
|
+
import { type BridgeTestPostgresCapability } from "./test-postgres-capability.js";
|
|
3
|
+
export interface RunnerHostCapabilitySnapshot {
|
|
4
|
+
readonly toolchains: BridgeToolchainCapabilities;
|
|
5
|
+
readonly playwrightProjects: readonly string[];
|
|
6
|
+
readonly browserLaunch: boolean;
|
|
7
|
+
readonly providerConnectivity: Readonly<Record<string, boolean>>;
|
|
8
|
+
readonly testPostgres: BridgeTestPostgresCapability;
|
|
9
|
+
}
|
|
10
|
+
export interface RunnerHostCapabilityProbe {
|
|
11
|
+
detect(config: BridgeServiceConfig): Promise<RunnerHostCapabilitySnapshot>;
|
|
12
|
+
}
|
|
13
|
+
export declare class ProcessRunnerHostCapabilityProbe implements RunnerHostCapabilityProbe {
|
|
14
|
+
private readonly warn;
|
|
15
|
+
private readonly providerEnvironment;
|
|
16
|
+
constructor(warn?: (message: string) => void, providerEnvironment?: () => NodeJS.ProcessEnv);
|
|
17
|
+
detect(config: BridgeServiceConfig): Promise<RunnerHostCapabilitySnapshot>;
|
|
18
|
+
}
|
|
19
|
+
export declare function isUnavailablePlaywrightConfigError(error: unknown): boolean;
|
|
20
|
+
export declare function emptyRunnerHostCapabilitySnapshot(): RunnerHostCapabilitySnapshot;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { probeTestPostgresCapability } from "./test-postgres-capability.js";
|
|
6
|
+
import { appExecutionAliasWarning } from "../shared/process/windows-app-execution-alias.js";
|
|
7
|
+
import { buildProviderChildEnvironment } from "../session/provider-cli/provider-cli.process.js";
|
|
8
|
+
const execFileAsync = promisify(execFile);
|
|
9
|
+
export class ProcessRunnerHostCapabilityProbe {
|
|
10
|
+
warn;
|
|
11
|
+
providerEnvironment;
|
|
12
|
+
constructor(warn = message => process.stderr.write(`[${new Date().toISOString()}] ${message}\n`), providerEnvironment = () => buildProviderChildEnvironment()) {
|
|
13
|
+
this.warn = warn;
|
|
14
|
+
this.providerEnvironment = providerEnvironment;
|
|
15
|
+
}
|
|
16
|
+
async detect(config) {
|
|
17
|
+
// Readiness, not a capability: the bridge still settles an attempt whose descendant escaped
|
|
18
|
+
// the Job Object (see OutputPipeRelease), but the host should not hand out aliases.
|
|
19
|
+
const aliasWarning = appExecutionAliasWarning(this.providerEnvironment());
|
|
20
|
+
if (aliasWarning)
|
|
21
|
+
this.warn(aliasWarning);
|
|
22
|
+
const [pnpm, dotnet, git, bash, pwsh, windowsPowerShell] = await Promise.all([
|
|
23
|
+
probe("pnpm", ["--version"]),
|
|
24
|
+
probe("dotnet", ["--version"]),
|
|
25
|
+
probe("git", ["--version"]),
|
|
26
|
+
probe("bash", ["--version"]),
|
|
27
|
+
probe("pwsh", ["-NoProfile", "-Command", "$PSVersionTable.PSVersion.ToString()"]),
|
|
28
|
+
process.platform === "win32"
|
|
29
|
+
? probe("powershell.exe", ["-NoProfile", "-Command", "$PSVersionTable.PSVersion.ToString()"])
|
|
30
|
+
: Promise.resolve(unavailable("powershell.exe")),
|
|
31
|
+
]);
|
|
32
|
+
const playwrightProjects = await detectPlaywrightProjects(config.repoMappings);
|
|
33
|
+
const testPostgres = await probeTestPostgresCapability();
|
|
34
|
+
const browserLaunch = playwrightProjects.length > 0
|
|
35
|
+
|| config.repoMappings.some(mapping => Boolean(mapping.qaAppLaunchTarget?.url
|
|
36
|
+
|| mapping.qaAppLaunchTarget?.command
|
|
37
|
+
|| mapping.qaAppLaunchTarget?.managed_runtime_port));
|
|
38
|
+
return {
|
|
39
|
+
toolchains: {
|
|
40
|
+
node: { available: true, executable: process.execPath, version: process.version },
|
|
41
|
+
pnpm,
|
|
42
|
+
dotnet,
|
|
43
|
+
git,
|
|
44
|
+
bash,
|
|
45
|
+
powershell: pwsh.available ? pwsh : windowsPowerShell,
|
|
46
|
+
},
|
|
47
|
+
playwrightProjects,
|
|
48
|
+
browserLaunch,
|
|
49
|
+
providerConnectivity: Object.fromEntries(Object.entries(config.providerStatuses)
|
|
50
|
+
.map(([provider, status]) => [provider, status.signedIn === true])),
|
|
51
|
+
testPostgres,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function probe(executable, args) {
|
|
56
|
+
try {
|
|
57
|
+
const result = await execFileAsync(executable, [...args], { encoding: "utf8", timeout: 5_000 });
|
|
58
|
+
const version = `${result.stdout || result.stderr}`.trim().split(/\r?\n/u)[0] ?? "";
|
|
59
|
+
return { available: true, executable, version };
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return unavailable(executable);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function unavailable(executable) {
|
|
66
|
+
return { available: false, executable, version: null };
|
|
67
|
+
}
|
|
68
|
+
async function detectPlaywrightProjects(repoMappings) {
|
|
69
|
+
const projects = new Set();
|
|
70
|
+
for (const mapping of repoMappings) {
|
|
71
|
+
if (!mapping.localPath)
|
|
72
|
+
continue;
|
|
73
|
+
const candidates = [
|
|
74
|
+
"playwright.config.ts", "playwright.config.js", "playwright.config.mjs",
|
|
75
|
+
"tests/e2e/playwright.config.ts", "tests/e2e/playwright.config.js", "tests/e2e/playwright.config.mjs",
|
|
76
|
+
];
|
|
77
|
+
for (const relative of candidates) {
|
|
78
|
+
try {
|
|
79
|
+
const source = await fs.readFile(path.join(mapping.localPath, relative), "utf8");
|
|
80
|
+
for (const match of source.matchAll(/\bname\s*:\s*["']([^"']+)["']/gu))
|
|
81
|
+
projects.add(match[1]);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (!isUnavailablePlaywrightConfigError(error))
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return [...projects].sort((left, right) => left.localeCompare(right));
|
|
90
|
+
}
|
|
91
|
+
export function isUnavailablePlaywrightConfigError(error) {
|
|
92
|
+
const code = error?.code;
|
|
93
|
+
return code === "ENOENT" || code === "EACCES" || code === "EPERM" || code === "ENOTDIR";
|
|
94
|
+
}
|
|
95
|
+
export function emptyRunnerHostCapabilitySnapshot() {
|
|
96
|
+
return {
|
|
97
|
+
toolchains: {
|
|
98
|
+
node: { available: true, executable: process.execPath, version: process.version },
|
|
99
|
+
pnpm: unavailable("pnpm"),
|
|
100
|
+
dotnet: unavailable("dotnet"),
|
|
101
|
+
git: unavailable("git"),
|
|
102
|
+
bash: unavailable("bash"),
|
|
103
|
+
powershell: unavailable(process.platform === "win32" ? "powershell.exe" : "pwsh"),
|
|
104
|
+
},
|
|
105
|
+
playwrightProjects: [],
|
|
106
|
+
browserLaunch: false,
|
|
107
|
+
providerConnectivity: {},
|
|
108
|
+
testPostgres: { available: false, superuser: null },
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SandboxPreflightResult } from "../sandbox/sandbox.types.js";
|
|
2
|
+
import type { DispatchSandboxResourceRequest, RunOnceDispatchPacket } from "../session/session.types.js";
|
|
3
|
+
import type { BridgeServiceConfig } from "./bridge.types.js";
|
|
4
|
+
export interface ResolvedSandboxResourceProfile {
|
|
5
|
+
readonly resources: DispatchSandboxResourceRequest;
|
|
6
|
+
readonly sandboxConfigCommitSha: string;
|
|
7
|
+
}
|
|
8
|
+
export type SandboxResourceVector = DispatchSandboxResourceRequest;
|
|
9
|
+
export declare function canReserveSandboxResources(used: SandboxResourceVector, requested: SandboxResourceVector, capacity: SandboxResourceVector): boolean;
|
|
10
|
+
export declare function sandboxMemoryCommitmentCapacity(preflight: Pick<SandboxPreflightResult, "totalMemoryBytes" | "availableMemoryBytes" | "hostReserveBytes">, activeMemoryBytes: number): number;
|
|
11
|
+
export declare function sandboxCapacityFailureMessage(used: SandboxResourceVector, requested: SandboxResourceVector, capacity: SandboxResourceVector, preflight: SandboxPreflightResult | null, config: BridgeServiceConfig): string;
|
|
12
|
+
export declare function sumSandboxResources(resources: readonly SandboxResourceVector[]): SandboxResourceVector;
|
|
13
|
+
export declare function zeroSandboxResources(): SandboxResourceVector;
|
|
14
|
+
export declare function defaultSandboxResources(): SandboxResourceVector;
|
|
15
|
+
export declare function resolveDynamicSandboxResources(requested: DispatchSandboxResourceRequest, serviceCount: number, networkMode: "offline" | "public_allowlist" | "open_public", baseRuntimeOverheadBytes?: number): DispatchSandboxResourceRequest;
|
|
16
|
+
export declare function resolveSandboxResourcesFromRepo(dispatch: RunOnceDispatchPacket, baseRuntimeOverheadBytes?: number): Promise<ResolvedSandboxResourceProfile>;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { formatBytes } from "../shared/format/format-bytes.js";
|
|
2
|
+
import { validateSandboxContract } from "../sandbox/contract.js";
|
|
3
|
+
import { runSandboxProcess } from "../sandbox/process.js";
|
|
4
|
+
import { selectSandboxConfigRefs } from "../sandbox/runtime.js";
|
|
5
|
+
import { estimateWorkspaceBytesFromRepo } from "../runtime/workspace-resource-estimator.js";
|
|
6
|
+
export function canReserveSandboxResources(used, requested, capacity) {
|
|
7
|
+
return used.sandboxSlots + requested.sandboxSlots <= capacity.sandboxSlots
|
|
8
|
+
&& used.cpuMillis + requested.cpuMillis <= capacity.cpuMillis
|
|
9
|
+
&& used.memoryBytes + requested.memoryBytes <= capacity.memoryBytes
|
|
10
|
+
&& used.workspaceBytes + requested.workspaceBytes <= capacity.workspaceBytes
|
|
11
|
+
&& used.pids + requested.pids <= capacity.pids
|
|
12
|
+
&& used.buildSlots + requested.buildSlots <= capacity.buildSlots;
|
|
13
|
+
}
|
|
14
|
+
export function sandboxMemoryCommitmentCapacity(preflight, activeMemoryBytes) {
|
|
15
|
+
const ambientCapacity = preflight.availableMemoryBytes
|
|
16
|
+
- preflight.hostReserveBytes
|
|
17
|
+
+ activeMemoryBytes;
|
|
18
|
+
const commitmentCapacity = preflight.totalMemoryBytes
|
|
19
|
+
- preflight.hostReserveBytes;
|
|
20
|
+
return Math.max(0, Math.min(ambientCapacity, commitmentCapacity));
|
|
21
|
+
}
|
|
22
|
+
export function sandboxCapacityFailureMessage(used, requested, capacity, preflight, config) {
|
|
23
|
+
const availableSlots = Math.max(0, capacity.sandboxSlots - used.sandboxSlots);
|
|
24
|
+
if (requested.sandboxSlots > availableSlots) {
|
|
25
|
+
return `Sandbox slot capacity is insufficient: requested ${requested.sandboxSlots}, available ${availableSlots}, ${used.sandboxSlots} already reserved.`;
|
|
26
|
+
}
|
|
27
|
+
const availableMemoryBytes = Math.max(0, capacity.memoryBytes - used.memoryBytes);
|
|
28
|
+
if (requested.memoryBytes > availableMemoryBytes) {
|
|
29
|
+
return [
|
|
30
|
+
`Sandbox memory capacity is insufficient: requested ${formatBytes(requested.memoryBytes)} total`,
|
|
31
|
+
`(worker ${formatBytes(requested.workerMemoryLimitBytes)}, services ${formatBytes(requested.serviceMemoryLimitBytes)}, runtime overhead ${formatBytes(requested.runtimeOverheadBytes)}),`,
|
|
32
|
+
`but ${formatBytes(availableMemoryBytes)} is available for admission.`,
|
|
33
|
+
`Docker reports ${formatBytes(preflight?.availableMemoryBytes ?? 0)} available of ${formatBytes(preflight?.totalMemoryBytes ?? 0)};`,
|
|
34
|
+
`Forge reserves ${formatBytes(preflight?.hostReserveBytes ?? config.sandboxHostMemoryReserveBytes ?? 0)} for the host and tracks ${formatBytes(used.memoryBytes)} in active or reserved attempts.`,
|
|
35
|
+
].join(" ");
|
|
36
|
+
}
|
|
37
|
+
const availableCpuMillis = Math.max(0, capacity.cpuMillis - used.cpuMillis);
|
|
38
|
+
if (requested.cpuMillis > availableCpuMillis) {
|
|
39
|
+
return `Sandbox CPU capacity is insufficient: requested ${requested.cpuMillis} millis, available ${availableCpuMillis} millis, ${used.cpuMillis} millis already reserved.`;
|
|
40
|
+
}
|
|
41
|
+
const availableWorkspaceBytes = Math.max(0, capacity.workspaceBytes - used.workspaceBytes);
|
|
42
|
+
if (requested.workspaceBytes > availableWorkspaceBytes) {
|
|
43
|
+
return `Sandbox workspace capacity is insufficient: requested ${formatBytes(requested.workspaceBytes)}, available ${formatBytes(availableWorkspaceBytes)}, ${formatBytes(used.workspaceBytes)} already reserved.`;
|
|
44
|
+
}
|
|
45
|
+
const availablePids = Math.max(0, capacity.pids - used.pids);
|
|
46
|
+
if (requested.pids > availablePids) {
|
|
47
|
+
return `Sandbox PID capacity is insufficient: requested ${requested.pids}, available ${availablePids}, ${used.pids} already reserved.`;
|
|
48
|
+
}
|
|
49
|
+
const availableBuildSlots = Math.max(0, capacity.buildSlots - used.buildSlots);
|
|
50
|
+
return `Sandbox build capacity is insufficient: requested ${requested.buildSlots}, available ${availableBuildSlots}, ${used.buildSlots} already reserved.`;
|
|
51
|
+
}
|
|
52
|
+
export function sumSandboxResources(resources) {
|
|
53
|
+
return resources.reduce((total, resource) => ({
|
|
54
|
+
sandboxSlots: total.sandboxSlots + resource.sandboxSlots,
|
|
55
|
+
cpuMillis: total.cpuMillis + resource.cpuMillis,
|
|
56
|
+
workerMemoryLimitBytes: total.workerMemoryLimitBytes + resource.workerMemoryLimitBytes,
|
|
57
|
+
serviceMemoryLimitBytes: total.serviceMemoryLimitBytes + resource.serviceMemoryLimitBytes,
|
|
58
|
+
runtimeOverheadBytes: total.runtimeOverheadBytes + resource.runtimeOverheadBytes,
|
|
59
|
+
memoryBytes: total.memoryBytes + resource.memoryBytes,
|
|
60
|
+
workspaceBytes: total.workspaceBytes + resource.workspaceBytes,
|
|
61
|
+
pids: total.pids + resource.pids,
|
|
62
|
+
buildSlots: total.buildSlots + resource.buildSlots
|
|
63
|
+
}), zeroSandboxResources());
|
|
64
|
+
}
|
|
65
|
+
export function zeroSandboxResources() {
|
|
66
|
+
return {
|
|
67
|
+
sandboxSlots: 0,
|
|
68
|
+
cpuMillis: 0,
|
|
69
|
+
workerMemoryLimitBytes: 0,
|
|
70
|
+
serviceMemoryLimitBytes: 0,
|
|
71
|
+
runtimeOverheadBytes: 0,
|
|
72
|
+
memoryBytes: 0,
|
|
73
|
+
workspaceBytes: 0,
|
|
74
|
+
pids: 0,
|
|
75
|
+
buildSlots: 0,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export function defaultSandboxResources() {
|
|
79
|
+
return {
|
|
80
|
+
sandboxSlots: 1,
|
|
81
|
+
cpuMillis: 2000,
|
|
82
|
+
workerMemoryLimitBytes: 2 * 1024 ** 3,
|
|
83
|
+
serviceMemoryLimitBytes: 0,
|
|
84
|
+
runtimeOverheadBytes: 128 * 1024 ** 2,
|
|
85
|
+
memoryBytes: 2 * 1024 ** 3 + 128 * 1024 ** 2,
|
|
86
|
+
workspaceBytes: 10 * 1024 ** 3,
|
|
87
|
+
pids: 512,
|
|
88
|
+
buildSlots: 0
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export function resolveDynamicSandboxResources(requested, serviceCount, networkMode, baseRuntimeOverheadBytes = 128 * 1024 ** 2) {
|
|
92
|
+
const serviceMemoryLimitBytes = Math.max(0, serviceCount) * 1024 ** 3;
|
|
93
|
+
const runtimeOverheadBytes = Math.max(128 * 1024 ** 2, baseRuntimeOverheadBytes)
|
|
94
|
+
+ (networkMode === "public_allowlist" ? 256 * 1024 ** 2 : 0);
|
|
95
|
+
return {
|
|
96
|
+
...requested,
|
|
97
|
+
serviceMemoryLimitBytes,
|
|
98
|
+
runtimeOverheadBytes,
|
|
99
|
+
memoryBytes: requested.workerMemoryLimitBytes + serviceMemoryLimitBytes + runtimeOverheadBytes,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export async function resolveSandboxResourcesFromRepo(dispatch, baseRuntimeOverheadBytes = 128 * 1024 ** 2) {
|
|
103
|
+
const repoPath = dispatch.repo.serverLocalPath;
|
|
104
|
+
const sandbox = dispatch.sandbox;
|
|
105
|
+
if (!repoPath || !sandbox) {
|
|
106
|
+
throw new Error("Sandbox admission needs a mapped repository.");
|
|
107
|
+
}
|
|
108
|
+
const selection = selectSandboxConfigRefs(sandbox.executionPolicy, sandbox.sandboxConfigCommitSha, dispatch.repo.defaultBranch);
|
|
109
|
+
const configCommitSha = await resolveFirstGitCommit(repoPath, selection.refs);
|
|
110
|
+
if (!configCommitSha) {
|
|
111
|
+
throw new Error("Sandbox admission could not resolve the immutable sandbox config commit.");
|
|
112
|
+
}
|
|
113
|
+
const contractResult = await runSandboxProcess({
|
|
114
|
+
command: "git",
|
|
115
|
+
args: ["-C", repoPath, "show", `${configCommitSha}:.forge/forge.sandbox.yml`],
|
|
116
|
+
timeoutMs: 30_000,
|
|
117
|
+
maxOutputBytes: 1024 * 1024,
|
|
118
|
+
});
|
|
119
|
+
if (contractResult.exitCode !== 0) {
|
|
120
|
+
throw new Error("The approved immutable sandbox contract is unavailable in the mapped repository.");
|
|
121
|
+
}
|
|
122
|
+
const contract = validateSandboxContract(contractResult.stdout);
|
|
123
|
+
const workspaceBytes = await estimateWorkspaceBytesFromRepo(repoPath, {
|
|
124
|
+
role: dispatch.execution.role,
|
|
125
|
+
serviceCount: contract.contract.services.length,
|
|
126
|
+
browser: contract.contract.browser,
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
resources: resolveDynamicSandboxResources({
|
|
130
|
+
...sandbox.requestedResources,
|
|
131
|
+
workspaceBytes: Math.max(sandbox.requestedResources.workspaceBytes, workspaceBytes),
|
|
132
|
+
}, contract.contract.services.length, sandbox.networkPolicy.mode, baseRuntimeOverheadBytes),
|
|
133
|
+
sandboxConfigCommitSha: configCommitSha,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
async function resolveFirstGitCommit(repoPath, refs) {
|
|
137
|
+
for (const ref of refs) {
|
|
138
|
+
const result = await runSandboxProcess({
|
|
139
|
+
command: "git",
|
|
140
|
+
args: ["-C", repoPath, "rev-parse", "--verify", `${ref}^{commit}`],
|
|
141
|
+
timeoutMs: 30_000,
|
|
142
|
+
maxOutputBytes: 1024 * 1024,
|
|
143
|
+
});
|
|
144
|
+
const commitSha = result.stdout.trim().toLowerCase();
|
|
145
|
+
if (result.exitCode === 0 && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(commitSha)) {
|
|
146
|
+
return commitSha;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether this host offers a native test PostgreSQL and whether its role is a superuser
|
|
3
|
+
* (decision 0013 placement). Suites that need `session_replication_role`, `CREATE ROLE` or
|
|
4
|
+
* similar can only run on a superuser test database or on Docker-backed Testcontainers.
|
|
5
|
+
*/
|
|
6
|
+
export interface BridgeTestPostgresCapability {
|
|
7
|
+
readonly available: boolean;
|
|
8
|
+
/** Null when the cluster is configured but the role could not be checked. */
|
|
9
|
+
readonly superuser: boolean | null;
|
|
10
|
+
}
|
|
11
|
+
export type PsqlRunner = (args: readonly string[], env: NodeJS.ProcessEnv) => Promise<string>;
|
|
12
|
+
export declare function probeTestPostgresCapability(environment?: NodeJS.ProcessEnv, runPsql?: PsqlRunner, readFallback?: () => string | null): Promise<BridgeTestPostgresCapability>;
|
|
13
|
+
/** Maps an Npgsql-style connection string or a postgres:// URI to libpq environment. */
|
|
14
|
+
export declare function psqlTarget(connection: string): Record<string, string> | null;
|