@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.0f07274d438b
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 +183 -4
- package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
- package/dist/bridge/bridge-chat-giphy-look.js +55 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +40 -0
- package/dist/bridge/bridge-chat-provider-command.js +230 -0
- package/dist/bridge/bridge-chat.types.d.ts +20 -0
- package/dist/bridge/bridge-chat.types.js +28 -1
- 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 +15 -0
- package/dist/bridge/bridge-state-io.js +68 -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 +9 -0
- package/dist/bridge/bridge.service.d.ts +102 -14
- package/dist/bridge/bridge.service.js +499 -471
- package/dist/bridge/bridge.types.d.ts +37 -0
- package/dist/bridge/bridge.types.js +2 -1
- package/dist/bridge/default-session-service.d.ts +13 -0
- package/dist/bridge/default-session-service.js +22 -0
- package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
- package/dist/bridge/dispatch-offer-policy.js +58 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -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 +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.d.ts +5 -0
- package/dist/bridge/runner-host-capabilities.js +31 -1
- 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/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -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 +20 -1
- package/dist/cleanup/cleanup.service.js +150 -169
- package/dist/cleanup/cleanup.types.d.ts +6 -0
- package/dist/cleanup/forge-owned-paths.d.ts +11 -0
- package/dist/cleanup/forge-owned-paths.js +62 -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 +75 -13
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +161 -228
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +18 -1
- package/dist/cli/local-config.js +67 -5
- package/dist/cli/provider-cli-advertising.d.ts +24 -0
- package/dist/cli/provider-cli-advertising.js +88 -0
- 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 +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -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/host-facts.d.ts +2 -1
- package/dist/runtime/host-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +72 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-capacity.d.ts +198 -0
- package/dist/runtime/host-load-capacity.js +353 -0
- package/dist/runtime/host-load-child-environment.d.ts +40 -0
- package/dist/runtime/host-load-child-environment.js +110 -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 +82 -0
- package/dist/runtime/host-load-governor-config.js +104 -0
- package/dist/runtime/host-load-governor.d.ts +273 -0
- package/dist/runtime/host-load-governor.js +831 -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-live-test-slots.d.ts +61 -0
- package/dist/runtime/host-load-live-test-slots.js +193 -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 +92 -2
- package/dist/runtime/host-load-sampler.js +166 -8
- 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 +107 -0
- package/dist/runtime/host-load-step-run.js +158 -0
- package/dist/runtime/host-load-test-slot.d.ts +46 -0
- package/dist/runtime/host-load-test-slot.js +100 -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 +21 -1
- package/dist/runtime/host-pressure-stall.js +48 -1
- package/dist/runtime/host-runtime-contract.d.ts +15 -0
- package/dist/runtime/host-runtime-contract.js +39 -6
- package/dist/runtime/host-runtime-lease.d.ts +101 -6
- package/dist/runtime/host-runtime-lease.js +408 -294
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +101 -2
- package/dist/runtime/host-runtime-promotion.js +355 -14
- 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.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
- package/dist/runtime/prepared-runtime-identity.js +130 -9
- package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
- package/dist/runtime/prepared-runtime-readiness.js +89 -18
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -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 +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.d.ts +11 -3
- package/dist/sandbox/runtime.js +53 -20
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox-input.d.ts +22 -0
- package/dist/sandbox/sandbox-input.js +49 -0
- package/dist/sandbox/workspace.service.js +15 -2
- 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 +2 -7
- package/dist/session/managed-attempt-tools.js +204 -141
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +7 -0
- package/dist/session/managed-build-receipt.js +11 -3
- package/dist/session/managed-command-environment.d.ts +8 -0
- package/dist/session/managed-command-environment.js +28 -0
- package/dist/session/managed-command-host-load.d.ts +52 -0
- package/dist/session/managed-command-host-load.js +87 -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.artifact-bundle.d.ts +20 -0
- package/dist/session/phase-completion.artifact-bundle.js +167 -0
- package/dist/session/phase-completion.artifacts.d.ts +9 -17
- package/dist/session/phase-completion.artifacts.js +158 -190
- 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 +31 -2
- package/dist/session/phase-completion.helpers.js +18 -65
- package/dist/session/phase-completion.js +19 -32
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +195 -0
- package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
- package/dist/session/phase-completion.phase-aliases.js +43 -0
- package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
- package/dist/session/phase-completion.pr-review-schema.js +75 -0
- package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
- package/dist/session/phase-completion.pr-review-validation.js +212 -0
- package/dist/session/phase-completion.pr-review.d.ts +36 -0
- package/dist/session/phase-completion.pr-review.js +294 -0
- package/dist/session/phase-completion.prompts.d.ts +1 -1
- package/dist/session/phase-completion.prompts.js +20 -1
- package/dist/session/phase-completion.runtime.d.ts +13 -12
- package/dist/session/phase-completion.runtime.js +113 -214
- 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 +219 -232
- package/dist/session/phase-completion.validation.d.ts +3 -3
- package/dist/session/phase-completion.validation.js +58 -94
- package/dist/session/pr-review-diff-base.d.ts +18 -0
- package/dist/session/pr-review-diff-base.js +44 -0
- package/dist/session/pr-review-placement.d.ts +50 -0
- package/dist/session/pr-review-placement.js +91 -0
- package/dist/session/pre-publication-change-set.d.ts +62 -0
- package/dist/session/pre-publication-change-set.js +166 -0
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +112 -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 +3 -0
- package/dist/session/pre-publication-process.js +32 -19
- 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 +39 -22
- package/dist/session/pre-publication-validation.js +241 -207
- 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/dispatch-target-branch.d.ts +7 -0
- package/dist/session/provider-cli/dispatch-target-branch.js +8 -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/pr-review-credential-isolation.d.ts +83 -0
- package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
- package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
- package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
- package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
- package/dist/session/provider-cli/pr-review-prompt.js +119 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +281 -0
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
- package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
- package/dist/session/provider-cli/provider-cli.process.js +41 -432
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -3
- package/dist/session/provider-cli/provider-cli.prompts.js +183 -90
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +43 -1
- package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
- package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +18 -18
- package/dist/session/provider-cli/provider-cli.service.js +127 -317
- package/dist/session/provider-cli/provider-cli.types.d.ts +35 -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 +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +45 -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 +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -0
- 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/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 +279 -0
- package/dist/session/session-host-project.d.ts +22 -0
- package/dist/session/session-host-project.js +98 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.parse-helpers.d.ts +10 -0
- package/dist/session/session.parse-helpers.js +84 -0
- package/dist/session/session.runtime-refresh.d.ts +46 -0
- package/dist/session/session.runtime-refresh.js +116 -0
- package/dist/session/session.service.d.ts +16 -2
- package/dist/session/session.service.js +208 -155
- package/dist/session/session.types.d.ts +8 -0
- package/dist/session/session.types.js +13 -83
- package/dist/session/session.types.pr-review.d.ts +48 -0
- package/dist/session/session.types.pr-review.js +51 -0
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -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/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +14 -1
- package/dist/shared/process/host-process-supervisor.js +67 -15
- 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 +67 -0
- package/dist/shared/process/process.js +213 -11
- 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 +2 -0
- package/dist/shared/provider-capabilities.js +23 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.js +24 -0
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -10
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +58 -0
- package/dist/worktree/wip-git.js +182 -0
- package/dist/worktree/wip-refs.d.ts +85 -0
- package/dist/worktree/wip-refs.js +169 -0
- package/dist/worktree/wip-restore.d.ts +51 -0
- package/dist/worktree/wip-restore.js +324 -0
- package/dist/worktree/wip-snapshot.d.ts +53 -0
- package/dist/worktree/wip-snapshot.js +270 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +35 -0
- package/dist/worktree/worktree-origin-sync.js +128 -0
- package/dist/worktree/worktree-wip-events.d.ts +20 -0
- package/dist/worktree/worktree-wip-events.js +148 -0
- package/dist/worktree/worktree-wip.d.ts +57 -0
- package/dist/worktree/worktree-wip.js +200 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +58 -5
- package/dist/worktree/worktree.service.js +237 -161
- package/dist/worktree/worktree.types.d.ts +54 -0
- package/package.json +2 -2
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
// File helpers shared by the bridge state file and its unpublished markers.
|
|
5
|
+
const retryableFsCodes = new Set(["EACCES", "EBUSY", "EPERM"]);
|
|
6
|
+
/**
|
|
7
|
+
* Writes JSON atomically: a temp file in the same folder, then a rename over the old one.
|
|
8
|
+
* On Windows the rename fails with EPERM/EBUSY/EACCES while a reader or an antivirus
|
|
9
|
+
* scanner has the target open, so it retries briefly.
|
|
10
|
+
*/
|
|
11
|
+
export async function writeJsonFileAtomically(target, value) {
|
|
12
|
+
await fs.mkdir(path.dirname(target), { recursive: true, mode: 0o700 });
|
|
13
|
+
const temporary = `${target}.${process.pid}.${randomUUID()}.tmp`;
|
|
14
|
+
try {
|
|
15
|
+
await fs.writeFile(temporary, `${JSON.stringify(value, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
16
|
+
await withFsRetry(() => fs.rename(temporary, target));
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
await fs.rm(temporary, { force: true }).catch(() => undefined);
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** True when a process with this id exists. EPERM means it exists but belongs to someone else. */
|
|
24
|
+
export function isProcessAlive(pid) {
|
|
25
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
26
|
+
return false;
|
|
27
|
+
try {
|
|
28
|
+
process.kill(pid, 0);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
return errorCode(error) === "EPERM";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* How long an fs call keeps retrying while Windows refuses it. Windows cannot rename over
|
|
37
|
+
* or delete a file that any handle has open, and a reader of a large file holds it open
|
|
38
|
+
* across several chunked reads: on a Windows 11 host, three readers polling a 2 MB state
|
|
39
|
+
* file every few milliseconds kept a rename refused for up to ~0.6 s, past the old ~0.4 s
|
|
40
|
+
* budget. Two seconds rides that out and stays well inside the state file's staleness window.
|
|
41
|
+
*/
|
|
42
|
+
const fsRetryBudgetMs = 2_000;
|
|
43
|
+
/** A backstop on top of the time budget. */
|
|
44
|
+
const fsRetryMaxAttempts = 100;
|
|
45
|
+
/**
|
|
46
|
+
* Retries an fs call that Windows refuses with EPERM/EBUSY/EACCES while another handle is
|
|
47
|
+
* open. The backoff is jittered so a writer does not keep landing in lockstep with polling
|
|
48
|
+
* readers, and the budget runs on the monotonic clock so a faked `Date` cannot stretch it.
|
|
49
|
+
*/
|
|
50
|
+
export async function withFsRetry(operation, budgetMs = fsRetryBudgetMs) {
|
|
51
|
+
const deadline = performance.now() + budgetMs;
|
|
52
|
+
for (let attempt = 1;; attempt += 1) {
|
|
53
|
+
try {
|
|
54
|
+
return await operation();
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (attempt >= fsRetryMaxAttempts || !retryableFsCodes.has(errorCode(error)))
|
|
58
|
+
throw error;
|
|
59
|
+
const delayMs = Math.min(100, 10 * attempt) * (0.5 + Math.random());
|
|
60
|
+
if (performance.now() + delayMs > deadline)
|
|
61
|
+
throw error;
|
|
62
|
+
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export function errorCode(error) {
|
|
67
|
+
return error?.code ?? "";
|
|
68
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const defaultStateLockTimeoutMs = 5000;
|
|
2
|
+
export interface BridgeStateLockOptions {
|
|
3
|
+
/** How long to wait for a lock another publisher holds. */
|
|
4
|
+
readonly timeoutMs?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class BridgeStateLockError extends Error {
|
|
7
|
+
}
|
|
8
|
+
/** Runs `critical` while this holder alone has the state file's lock. */
|
|
9
|
+
export declare function withBridgeStateLock<T>(statePath: string, critical: () => Promise<T>, options?: BridgeStateLockOptions): Promise<T>;
|
|
10
|
+
/** The lock's name for a state file: the same for every path that names the same file. */
|
|
11
|
+
export declare function bridgeStateLockName(canonicalPath: string, platform?: NodeJS.Platform): string;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { constants as fsConstants } from "node:fs";
|
|
3
|
+
import net from "node:net";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { errorCode } from "./bridge-state-io.js";
|
|
7
|
+
// Serializes every read-decide-write of bridge.state.json across processes (PR #636 review).
|
|
8
|
+
// Two `connect` processes on one config, or an old bridge stopping while its replacement
|
|
9
|
+
// starts, must never interleave a read of the record with a write over it: the later one
|
|
10
|
+
// would publish a decision taken on a record that no longer exists (two "no conflict"
|
|
11
|
+
// records, or a "stopped" record over a newer bridge's "running" one).
|
|
12
|
+
//
|
|
13
|
+
// The lock is a name the operating system owns, not a file the bridge creates and deletes:
|
|
14
|
+
// - Linux: an abstract-namespace Unix socket ("\0forge-bridge-state-<hash>"). Binding it
|
|
15
|
+
// is atomic; a second bind fails with EADDRINUSE; it has no file, and the kernel frees it
|
|
16
|
+
// when the holder closes it or its process dies.
|
|
17
|
+
// - Windows: a named pipe (\\.\pipe\forge-bridge-state-<hash>), created as the first
|
|
18
|
+
// instance; a second creation fails (EADDRINUSE), and Windows frees it when the holder's
|
|
19
|
+
// handle closes, including when its process dies.
|
|
20
|
+
// - macOS and the BSDs: an O_EXLOCK (flock) open of `<state file>.lock`, never unlinked;
|
|
21
|
+
// the kernel drops the lock when the descriptor closes or the process dies.
|
|
22
|
+
// No holder ever removes or takes over another holder's lock, so there is no stale-lock
|
|
23
|
+
// takeover to race and no release that can free a successor's lock. A holder that hangs
|
|
24
|
+
// keeps it: publishers wait, then fail closed.
|
|
25
|
+
export const defaultStateLockTimeoutMs = 5_000;
|
|
26
|
+
// <sys/fcntl.h> on macOS and the BSDs; libuv passes open flags through to open(2).
|
|
27
|
+
const exclusiveFlockFlag = 0x20;
|
|
28
|
+
export class BridgeStateLockError extends Error {
|
|
29
|
+
}
|
|
30
|
+
/** Runs `critical` while this holder alone has the state file's lock. */
|
|
31
|
+
export async function withBridgeStateLock(statePath, critical, options = {}) {
|
|
32
|
+
const name = bridgeStateLockName(await canonicalStatePath(statePath));
|
|
33
|
+
const held = await acquire(name, options.timeoutMs ?? defaultStateLockTimeoutMs);
|
|
34
|
+
try {
|
|
35
|
+
return await critical();
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
await held.release();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** The lock's name for a state file: the same for every path that names the same file. */
|
|
42
|
+
export function bridgeStateLockName(canonicalPath, platform = process.platform) {
|
|
43
|
+
// Windows paths (and pipe names) are case-insensitive.
|
|
44
|
+
const key = createHash("sha256").update(platform === "win32" ? canonicalPath.toLowerCase() : canonicalPath).digest("hex").slice(0, 40);
|
|
45
|
+
if (platform === "win32")
|
|
46
|
+
return `\\\\.\\pipe\\forge-bridge-state-${key}`;
|
|
47
|
+
if (platform === "linux")
|
|
48
|
+
return `\0forge-bridge-state-${key}`;
|
|
49
|
+
return `${canonicalPath}.lock`;
|
|
50
|
+
}
|
|
51
|
+
async function canonicalStatePath(statePath) {
|
|
52
|
+
const resolved = path.resolve(statePath);
|
|
53
|
+
await fs.mkdir(path.dirname(resolved), { recursive: true, mode: 0o700 });
|
|
54
|
+
return path.join(await fs.realpath(path.dirname(resolved)), path.basename(resolved));
|
|
55
|
+
}
|
|
56
|
+
async function acquire(name, timeoutMs) {
|
|
57
|
+
const deadline = Date.now() + timeoutMs;
|
|
58
|
+
for (let attempt = 1;; attempt += 1) {
|
|
59
|
+
const held = isSocketName(name) ? await tryListen(name) : await tryFlock(name);
|
|
60
|
+
if (held)
|
|
61
|
+
return held;
|
|
62
|
+
if (Date.now() >= deadline) {
|
|
63
|
+
throw new BridgeStateLockError(`Timed out after ${timeoutMs} ms waiting for the bridge state lock; another bridge process holds it.`);
|
|
64
|
+
}
|
|
65
|
+
await new Promise(resolve => setTimeout(resolve, Math.min(50, 5 * attempt)));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function isSocketName(name) {
|
|
69
|
+
return name.startsWith("\0") || name.startsWith("\\\\.\\pipe\\");
|
|
70
|
+
}
|
|
71
|
+
/** Binds the name, or null when another holder has it. */
|
|
72
|
+
function tryListen(name) {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
const server = net.createServer(socket => socket.destroy());
|
|
75
|
+
server.once("error", error => {
|
|
76
|
+
const code = errorCode(error);
|
|
77
|
+
// EACCES: a pipe of that name made by another user. Held all the same.
|
|
78
|
+
if (code === "EADDRINUSE" || code === "EACCES")
|
|
79
|
+
resolve(null);
|
|
80
|
+
else
|
|
81
|
+
reject(error);
|
|
82
|
+
});
|
|
83
|
+
server.listen(name, () => {
|
|
84
|
+
server.removeAllListeners("error");
|
|
85
|
+
server.on("error", () => undefined);
|
|
86
|
+
server.unref();
|
|
87
|
+
resolve({ release: () => new Promise(done => server.close(() => done())) });
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async function tryFlock(lockPath) {
|
|
92
|
+
const flags = fsConstants.O_RDWR | fsConstants.O_CREAT | fsConstants.O_NONBLOCK | exclusiveFlockFlag;
|
|
93
|
+
try {
|
|
94
|
+
const handle = await fs.open(lockPath, flags, 0o600);
|
|
95
|
+
return { release: () => handle.close() };
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (errorCode(error) === "EAGAIN" || errorCode(error) === "EWOULDBLOCK")
|
|
99
|
+
return null;
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface UnpublishedMarker {
|
|
2
|
+
readonly schemaVersion: 1;
|
|
3
|
+
readonly pid: number;
|
|
4
|
+
readonly publisherId: string;
|
|
5
|
+
readonly runnerInstanceId: string;
|
|
6
|
+
readonly since: string;
|
|
7
|
+
readonly updatedAt: string;
|
|
8
|
+
readonly publishIntervalMs: number;
|
|
9
|
+
readonly error: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function unpublishedMarkerPathFor(statePath: string, publisherId: string): string;
|
|
12
|
+
export declare function writeUnpublishedMarker(statePath: string, marker: UnpublishedMarker): Promise<void>;
|
|
13
|
+
export declare function removeUnpublishedMarker(statePath: string, publisherId: string): Promise<void>;
|
|
14
|
+
/** Every marker beside the state file. Throws on one it can't trust: idle can't be confirmed then. */
|
|
15
|
+
export declare function readUnpublishedMarkers(statePath: string, now?: number): Promise<UnpublishedMarker[]>;
|
|
16
|
+
/** Removes valid markers whose process has exited: they can no longer hold anything back. */
|
|
17
|
+
export declare function removeExitedUnpublishedMarkers(statePath: string, pidAlive?: (pid: number) => boolean): Promise<void>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { errorCode, isProcessAlive, withFsRetry, writeJsonFileAtomically } from "./bridge-state-io.js";
|
|
4
|
+
// The id is a single safe path component (the publisher's random UUID). A marker's id is
|
|
5
|
+
// always taken from its own file name in the state directory, never from its contents, and
|
|
6
|
+
// the contents must name the same id: no path is ever built from what a file says.
|
|
7
|
+
const publisherIdPattern = /^[A-Za-z0-9-]{1,64}$/u;
|
|
8
|
+
// Allows for a writer clock slightly ahead of the reader's.
|
|
9
|
+
const futureToleranceMs = 60_000;
|
|
10
|
+
export function unpublishedMarkerPathFor(statePath, publisherId) {
|
|
11
|
+
if (!publisherIdPattern.test(publisherId))
|
|
12
|
+
throw new Error(`Invalid publisher id for an unpublished-state marker: ${JSON.stringify(publisherId)}.`);
|
|
13
|
+
return path.join(path.dirname(statePath), markerFileName(statePath, publisherId));
|
|
14
|
+
}
|
|
15
|
+
export async function writeUnpublishedMarker(statePath, marker) {
|
|
16
|
+
await writeJsonFileAtomically(unpublishedMarkerPathFor(statePath, marker.publisherId), marker);
|
|
17
|
+
}
|
|
18
|
+
export async function removeUnpublishedMarker(statePath, publisherId) {
|
|
19
|
+
await withFsRetry(() => fs.rm(unpublishedMarkerPathFor(statePath, publisherId), { force: true }));
|
|
20
|
+
}
|
|
21
|
+
/** Every marker beside the state file. Throws on one it can't trust: idle can't be confirmed then. */
|
|
22
|
+
export async function readUnpublishedMarkers(statePath, now = Date.now()) {
|
|
23
|
+
const listed = await listUnpublishedMarkers(statePath, now);
|
|
24
|
+
const untrusted = listed.find(entry => entry.marker === null);
|
|
25
|
+
if (untrusted)
|
|
26
|
+
throw new Error(`The unpublished-state marker ${untrusted.fileName} is ${untrusted.problem}.`);
|
|
27
|
+
return listed.map(entry => entry.marker);
|
|
28
|
+
}
|
|
29
|
+
/** Removes valid markers whose process has exited: they can no longer hold anything back. */
|
|
30
|
+
export async function removeExitedUnpublishedMarkers(statePath, pidAlive = isProcessAlive) {
|
|
31
|
+
const directory = path.resolve(path.dirname(statePath));
|
|
32
|
+
const listed = await listUnpublishedMarkers(statePath, Date.now()).catch(() => []);
|
|
33
|
+
for (const { fileName, marker } of listed) {
|
|
34
|
+
if (!marker || pidAlive(marker.pid))
|
|
35
|
+
continue;
|
|
36
|
+
// Only the exact file listed, directly inside the state directory.
|
|
37
|
+
const target = path.resolve(directory, fileName);
|
|
38
|
+
if (path.dirname(target) !== directory || path.basename(target) !== fileName)
|
|
39
|
+
continue;
|
|
40
|
+
await withFsRetry(() => fs.rm(target, { force: true })).catch(() => undefined);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function listUnpublishedMarkers(statePath, now) {
|
|
44
|
+
const directory = path.dirname(statePath);
|
|
45
|
+
const prefix = `${path.basename(statePath)}.unpublished.`;
|
|
46
|
+
let names;
|
|
47
|
+
try {
|
|
48
|
+
names = await withFsRetry(() => fs.readdir(directory));
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (errorCode(error) === "ENOENT")
|
|
52
|
+
return [];
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
const listed = [];
|
|
56
|
+
// Temp files of an atomic write end in ".tmp" and are not markers yet.
|
|
57
|
+
for (const fileName of names.filter(name => name.startsWith(prefix) && name.endsWith(".json"))) {
|
|
58
|
+
const publisherId = fileName.slice(prefix.length, -".json".length);
|
|
59
|
+
if (!publisherIdPattern.test(publisherId)) {
|
|
60
|
+
listed.push({ fileName, marker: null, problem: "not named for a valid publisher id" });
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
let text;
|
|
64
|
+
try {
|
|
65
|
+
text = await withFsRetry(() => fs.readFile(path.join(directory, fileName), "utf8"));
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
// Removed between the listing and the read: its publisher has published again.
|
|
69
|
+
if (errorCode(error) === "ENOENT")
|
|
70
|
+
continue;
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
const marker = parseMarker(text, publisherId, now);
|
|
74
|
+
listed.push(marker ? { fileName, marker, problem: null } : { fileName, marker: null, problem: "malformed" });
|
|
75
|
+
}
|
|
76
|
+
return listed;
|
|
77
|
+
}
|
|
78
|
+
function markerFileName(statePath, publisherId) {
|
|
79
|
+
return `${path.basename(statePath)}.unpublished.${publisherId}.json`;
|
|
80
|
+
}
|
|
81
|
+
// Every field the evaluator relies on, with its type and range: a marker it could not use to
|
|
82
|
+
// hold readers back (a NaN timestamp or interval) is malformed, which reads as unknown.
|
|
83
|
+
const markerChecks = [
|
|
84
|
+
marker => marker.schemaVersion === 1,
|
|
85
|
+
marker => Number.isInteger(marker.pid) && marker.pid > 0,
|
|
86
|
+
(marker, publisherId) => marker.publisherId === publisherId,
|
|
87
|
+
marker => typeof marker.runnerInstanceId === "string",
|
|
88
|
+
(marker, _publisherId, now) => isPastTimestamp(marker.since, now),
|
|
89
|
+
(marker, _publisherId, now) => isPastTimestamp(marker.updatedAt, now),
|
|
90
|
+
marker => typeof marker.publishIntervalMs === "number" && Number.isFinite(marker.publishIntervalMs) && marker.publishIntervalMs > 0,
|
|
91
|
+
marker => typeof marker.error === "string",
|
|
92
|
+
];
|
|
93
|
+
function parseMarker(text, publisherId, now) {
|
|
94
|
+
let value;
|
|
95
|
+
try {
|
|
96
|
+
value = JSON.parse(text);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
102
|
+
return null;
|
|
103
|
+
const marker = value;
|
|
104
|
+
return markerChecks.every(check => check(marker, publisherId, now)) ? marker : null;
|
|
105
|
+
}
|
|
106
|
+
function isPastTimestamp(value, now) {
|
|
107
|
+
if (typeof value !== "string")
|
|
108
|
+
return false;
|
|
109
|
+
const at = Date.parse(value);
|
|
110
|
+
return Number.isFinite(at) && at <= now + futureToleranceMs;
|
|
111
|
+
}
|
|
@@ -18,8 +18,17 @@ export interface BridgeConnection {
|
|
|
18
18
|
onCancel(handler: BridgeCancelHandler): void;
|
|
19
19
|
onReap?(handler: BridgeReapHandler): void;
|
|
20
20
|
onReadinessProbe?(handler: BridgeReadinessProbeHandler): void;
|
|
21
|
+
/** Decision 0014: the owner removed this runner from Forge; the bridge must stop, not reconnect. */
|
|
22
|
+
onRevoked?(handler: (notice: BridgeRevokedNotice) => void): void;
|
|
23
|
+
/** Decision 0014: the server pushes the runner settings document (`ApplySettings`, schema 8 bridges only). */
|
|
24
|
+
onApplySettings?(handler: (document: unknown) => void | Promise<void>): void;
|
|
21
25
|
invoke<TResponse>(methodName: string, payload: unknown): Promise<TResponse>;
|
|
22
26
|
}
|
|
27
|
+
/** The `Revoked` hub message: the runner was removed from Forge and must be paired again. */
|
|
28
|
+
export interface BridgeRevokedNotice {
|
|
29
|
+
runnerId?: string;
|
|
30
|
+
reason?: string;
|
|
31
|
+
}
|
|
23
32
|
export interface BridgeConnectionFactory {
|
|
24
33
|
create(config: BridgeServiceConfig): BridgeConnection;
|
|
25
34
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type { SessionService } from "../session/session.base.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type ProviderProcessRunner } from "../session/provider-cli/provider-cli.service.js";
|
|
3
|
+
import { type RunnerSettingsReport } from "../runtime/runner-settings.js";
|
|
3
4
|
import { DockerEngineProbe, type DockerEngineCapabilitySnapshot } from "../runtime/docker-engine-probe.js";
|
|
4
|
-
import { type
|
|
5
|
+
import { type RunOnceDispatchPacket, type RunOnceResultPacket } from "../session/session.types.js";
|
|
5
6
|
import { DockerPreflight } from "../sandbox/preflight.js";
|
|
6
|
-
import type { SandboxPreflightResult } from "../sandbox/sandbox.types.js";
|
|
7
7
|
import { type SandboxRuntime } from "../sandbox/runtime.js";
|
|
8
|
-
import type { BridgeConnection, BridgeConnectionFactory, BridgeService } from "./bridge.base.js";
|
|
8
|
+
import type { BridgeConnection, BridgeConnectionFactory, BridgeRevokedNotice, BridgeService } from "./bridge.base.js";
|
|
9
9
|
import { type RunnerHostCapabilityProbe } from "./runner-host-capabilities.js";
|
|
10
10
|
import { type HostLoadSource } from "../runtime/host-load-sampler.js";
|
|
11
11
|
import type { BridgeCancelHandler, BridgeChatTurnHandler, BridgeDispatchHandler, BridgeLeaseUpdateRequest, BridgeReapRequest, BridgeServiceConfig } from "./bridge.types.js";
|
|
12
12
|
import { type ReadinessResultOutbox } from "./readiness-result-outbox.js";
|
|
13
13
|
import { type DispatchResultOutbox } from "./dispatch-result-outbox.js";
|
|
14
|
+
import { BridgeInFlightRegistry } from "./in-flight-registry.js";
|
|
15
|
+
import { canReserveSandboxResources, resolveDynamicSandboxResources, resolveSandboxResourcesFromRepo, sandboxCapacityFailureMessage, sandboxMemoryCommitmentCapacity, type ResolvedSandboxResourceProfile, type SandboxResourceVector } from "./sandbox-resource-accounting.js";
|
|
14
16
|
export type SandboxResourceResolver = (dispatch: RunOnceDispatchPacket) => Promise<ResolvedSandboxResourceProfile>;
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
readonly sandboxConfigCommitSha: string;
|
|
18
|
-
}
|
|
17
|
+
export { canReserveSandboxResources, resolveDynamicSandboxResources, resolveSandboxResourcesFromRepo, sandboxCapacityFailureMessage, sandboxMemoryCommitmentCapacity, };
|
|
18
|
+
export type { ResolvedSandboxResourceProfile, SandboxResourceVector };
|
|
19
19
|
/**
|
|
20
20
|
* Protocol-v2 events are acknowledged one at a time before runOnce returns.
|
|
21
21
|
* Sending the complete transcript again in DispatchResult made long QA and CI
|
|
@@ -39,13 +39,17 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
39
39
|
private leaseWatchdogTimer;
|
|
40
40
|
private sandboxMaintenanceTimer;
|
|
41
41
|
private sandboxMaintenanceRunning;
|
|
42
|
+
private attemptSnapshotPending;
|
|
42
43
|
private closed;
|
|
43
44
|
private transportRecovery;
|
|
44
45
|
private transportRecoveryGeneration;
|
|
45
46
|
private stopped;
|
|
47
|
+
private revokedReason;
|
|
46
48
|
private readonly activeSessions;
|
|
47
49
|
private readonly reservations;
|
|
48
50
|
private readonly activeReadinessProbes;
|
|
51
|
+
/** Everything a bridge restart would interrupt, published for `forge-bridge status --idle`. */
|
|
52
|
+
readonly inFlight: BridgeInFlightRegistry;
|
|
49
53
|
private readonly readinessResultOutbox;
|
|
50
54
|
private readinessResultFlush;
|
|
51
55
|
private readonly dispatchResultOutbox;
|
|
@@ -60,17 +64,88 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
60
64
|
private readonly sessions;
|
|
61
65
|
private readonly enforceHostDatabaseCapabilityBoundary;
|
|
62
66
|
private hostCapabilities;
|
|
67
|
+
private dockerAvailable;
|
|
68
|
+
private appliedSettingsDocument;
|
|
69
|
+
private localYield;
|
|
70
|
+
/** The yield Forge last acknowledged in a report (Hello, Heartbeat, SettingsApplied); published as `yielding`. */
|
|
71
|
+
private forgeAckedYield;
|
|
72
|
+
private publishState;
|
|
73
|
+
private effectiveSettings;
|
|
74
|
+
private settingsReport;
|
|
75
|
+
/** Applies run one at a time; offers wait for every apply queued before them. */
|
|
76
|
+
private settingsTail;
|
|
77
|
+
private pendingYieldOn;
|
|
78
|
+
private settingsStarted;
|
|
79
|
+
private hostRequirementFacts;
|
|
63
80
|
private readonly recoveredHostAttempts;
|
|
64
81
|
private hostCapabilitiesDetected;
|
|
82
|
+
/** The default session service's host load governor, for the startup capacity log line. */
|
|
83
|
+
private readonly hostLoadGovernor;
|
|
65
84
|
constructor(config: BridgeServiceConfig, sessions?: SessionService | undefined, connections?: BridgeConnectionFactory, preflight?: DockerPreflight, sandboxRuntime?: SandboxRuntime, sandboxResourceResolver?: SandboxResourceResolver, dockerEngineProbe?: DockerEngineProbe, hostCapabilityProbe?: RunnerHostCapabilityProbe, readinessResultOutbox?: ReadinessResultOutbox, chatProcessRunner?: ProviderProcessRunner, dispatchResultOutbox?: DispatchResultOutbox, hostLoad?: HostLoadSource);
|
|
85
|
+
/** Once per bridge process: host capabilities, and how many heavy steps this host runs at once, and why. */
|
|
86
|
+
private detectHostCapabilities;
|
|
66
87
|
connectOnce(): Promise<void>;
|
|
67
88
|
private rememberRecoveredHostAttempts;
|
|
68
89
|
private recoveredHostAttemptsForHello;
|
|
69
90
|
private registerConnection;
|
|
70
91
|
run(signal?: AbortSignal): Promise<void>;
|
|
92
|
+
private startStatePublisher;
|
|
93
|
+
/** The reason Forge gave when it removed this runner, or null while it is paired. */
|
|
94
|
+
get revoked(): string | null;
|
|
95
|
+
/**
|
|
96
|
+
* Decision 0014 §3 "Remove": Forge removed this runner. Stop for good instead of
|
|
97
|
+
* reconnecting; its attempts were already settled on the server, so local work is
|
|
98
|
+
* aborted rather than reported.
|
|
99
|
+
*/
|
|
100
|
+
private handleRevoked;
|
|
101
|
+
/** The effective settings and how they were derived, as last reported (decision 0014). */
|
|
102
|
+
get runnerSettings(): RunnerSettingsReport;
|
|
103
|
+
private runnerHostDefaults;
|
|
104
|
+
/**
|
|
105
|
+
* Once per bridge process: drop governor overrides an earlier process left on
|
|
106
|
+
* the state root, then put today's effective settings (env bounds and the local
|
|
107
|
+
* yield flag, no server document yet) in force.
|
|
108
|
+
*/
|
|
109
|
+
private startSettings;
|
|
110
|
+
/**
|
|
111
|
+
* Decision 0014 `ApplySettings`. Applies only a document newer than the one
|
|
112
|
+
* applied, one at a time, then acknowledges it with `SettingsApplied`. A replay of
|
|
113
|
+
* the applied version is acknowledged again without applying it; an older one is
|
|
114
|
+
* ignored.
|
|
115
|
+
*/
|
|
116
|
+
private handleApplySettings;
|
|
117
|
+
/**
|
|
118
|
+
* Polls the local `forge-bridge yield` flag (every heartbeat and before each
|
|
119
|
+
* offer decision). A change is applied at once and reported again under the
|
|
120
|
+
* same settings version.
|
|
121
|
+
*/
|
|
122
|
+
/** Yielding now, or about to: a received yield-on that is still being applied counts. */
|
|
123
|
+
private yieldingOrQueued;
|
|
124
|
+
private refreshLocalYield;
|
|
125
|
+
/**
|
|
126
|
+
* A setting the host couldn't put in force holds placement on the server, so
|
|
127
|
+
* every heartbeat tries the applied document again until it takes.
|
|
128
|
+
*/
|
|
129
|
+
private retryFailedSettings;
|
|
130
|
+
private readLocalYield;
|
|
131
|
+
private enqueueSettings;
|
|
132
|
+
private applySettings;
|
|
133
|
+
/**
|
|
134
|
+
* Max attempts and the memory reserve go to host attempt admission; the governor
|
|
135
|
+
* budget (the yield budget while yielding) and the heavy-step limit go to the
|
|
136
|
+
* shared settings file every governor on the state root reads at admission.
|
|
137
|
+
* Neither touches admitted work. Returns the keys the host could not put in
|
|
138
|
+
* force (`apply_failed`); their previous values stay in force.
|
|
139
|
+
*/
|
|
140
|
+
private putSettingsInForce;
|
|
141
|
+
private ackYield;
|
|
142
|
+
/** A failed acknowledgement is not retried here: the next heartbeat carries the same report. */
|
|
143
|
+
private sendSettingsApplied;
|
|
71
144
|
stop(): Promise<void>;
|
|
72
145
|
private handleChatTurn;
|
|
73
146
|
private createChatTurnWorkspace;
|
|
147
|
+
/** Has Claude look at the turn's sent GIFs once, pulling their frames from the hub; no looks means text only. */
|
|
148
|
+
private lookAtChatGiphyFrames;
|
|
74
149
|
private runChatProviderProcess;
|
|
75
150
|
private sendChatProviderEvent;
|
|
76
151
|
private sendChatAbortTerminal;
|
|
@@ -80,6 +155,10 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
80
155
|
private requiredChatCapabilityFailure;
|
|
81
156
|
private bridgeChatCapability;
|
|
82
157
|
private handleDispatch;
|
|
158
|
+
private registerActiveDispatch;
|
|
159
|
+
private dispatchEventSink;
|
|
160
|
+
/** Runs the dispatch on the host or in its Docker sandbox, logging start and end with its ids. */
|
|
161
|
+
private runDispatchOnce;
|
|
83
162
|
private reservedDispatchHandoffIsCurrent;
|
|
84
163
|
private releaseReservedDispatchHandoff;
|
|
85
164
|
private releaseActiveSessionAndRefreshCapacity;
|
|
@@ -90,6 +169,12 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
90
169
|
private redeemPublishGrant;
|
|
91
170
|
private handleLeaseUpdate;
|
|
92
171
|
private sendOfferDecision;
|
|
172
|
+
/**
|
|
173
|
+
* The terminal result for a dispatch this runner refuses before any worktree or provider exists: the host
|
|
174
|
+
* database capability boundary, a missing required facility, or a Forge PR review outside the Docker sandbox
|
|
175
|
+
* without the owner's opt-in. Null when it may run.
|
|
176
|
+
*/
|
|
177
|
+
private refusalBeforeRun;
|
|
93
178
|
private parseDispatchOrReport;
|
|
94
179
|
private parseChatTurnOrReport;
|
|
95
180
|
private handleCancel;
|
|
@@ -144,6 +229,13 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
144
229
|
private waitForClose;
|
|
145
230
|
private stopConnection;
|
|
146
231
|
}
|
|
232
|
+
/** The `run` command's exit code after Forge removed the runner. */
|
|
233
|
+
export declare const bridgeRevokedExitCode = 3;
|
|
234
|
+
export declare const bridgeRevokedMessage = "This bridge was removed from Forge. Pair it again with forge-bridge pair.";
|
|
235
|
+
/** Thrown by `run` after Forge removed the runner, so the CLI exits instead of reconnecting. */
|
|
236
|
+
export declare class BridgeRevokedError extends Error {
|
|
237
|
+
constructor(message?: string);
|
|
238
|
+
}
|
|
147
239
|
export declare class SignalRBridgeConnectionFactory implements BridgeConnectionFactory {
|
|
148
240
|
create(config: BridgeServiceConfig): BridgeConnection;
|
|
149
241
|
}
|
|
@@ -151,6 +243,8 @@ export declare class SignalRBridgeConnection implements BridgeConnection {
|
|
|
151
243
|
private readonly config;
|
|
152
244
|
private readonly connection;
|
|
153
245
|
constructor(config: BridgeServiceConfig);
|
|
246
|
+
onApplySettings(handler: (document: unknown) => void | Promise<void>): void;
|
|
247
|
+
onRevoked(handler: (notice: BridgeRevokedNotice) => void): void;
|
|
154
248
|
start(): Promise<void>;
|
|
155
249
|
stop(): Promise<void>;
|
|
156
250
|
onClose(handler: (error?: Error) => void): void;
|
|
@@ -175,9 +269,3 @@ export declare function canReapManagedSandboxes(preflight: {
|
|
|
175
269
|
readonly unavailableCode?: string | null;
|
|
176
270
|
}): boolean;
|
|
177
271
|
export declare function dockerEngineRequirementFailure(requiredCapabilities: readonly string[], executionMode: string | undefined, capability: DockerEngineCapabilitySnapshot | null): string | null;
|
|
178
|
-
export type SandboxResourceVector = DispatchSandboxResourceRequest;
|
|
179
|
-
export declare function canReserveSandboxResources(used: SandboxResourceVector, requested: SandboxResourceVector, capacity: SandboxResourceVector): boolean;
|
|
180
|
-
export declare function sandboxMemoryCommitmentCapacity(preflight: Pick<SandboxPreflightResult, "totalMemoryBytes" | "availableMemoryBytes" | "hostReserveBytes">, activeMemoryBytes: number): number;
|
|
181
|
-
export declare function sandboxCapacityFailureMessage(used: SandboxResourceVector, requested: SandboxResourceVector, capacity: SandboxResourceVector, preflight: SandboxPreflightResult | null, config: BridgeServiceConfig): string;
|
|
182
|
-
export declare function resolveDynamicSandboxResources(requested: DispatchSandboxResourceRequest, serviceCount: number, networkMode: "offline" | "public_allowlist" | "open_public", baseRuntimeOverheadBytes?: number): DispatchSandboxResourceRequest;
|
|
183
|
-
export declare function resolveSandboxResourcesFromRepo(dispatch: RunOnceDispatchPacket, baseRuntimeOverheadBytes?: number): Promise<ResolvedSandboxResourceProfile>;
|