@loucompanion/forge-bridge 0.1.4-dev.f22f5e3d01fe → 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 +128 -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 +27 -3
- package/dist/bridge/bridge-chat-provider-command.js +131 -26
- 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.service.d.ts +29 -12
- package/dist/bridge/bridge.service.js +215 -380
- package/dist/bridge/bridge.types.d.ts +21 -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/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.js +14 -1
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -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 +11 -1
- package/dist/cleanup/cleanup.service.js +80 -62
- package/dist/cleanup/cleanup.types.d.ts +2 -0
- package/dist/cleanup/forge-owned-paths.d.ts +2 -0
- package/dist/cleanup/forge-owned-paths.js +9 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.js +30 -9
- package/dist/cli/cli.help.js +57 -13
- package/dist/cli/cli.service.d.ts +3 -10
- package/dist/cli/cli.service.js +20 -213
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +14 -1
- package/dist/cli/local-config.js +42 -2
- 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 +104 -26
- 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-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +5 -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 +13 -0
- package/dist/runtime/host-load-child-environment.js +35 -1
- package/dist/runtime/host-load-governor-config.d.ts +33 -3
- package/dist/runtime/host-load-governor-config.js +24 -3
- package/dist/runtime/host-load-governor.d.ts +91 -2
- package/dist/runtime/host-load-governor.js +217 -18
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- 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.js +4 -2
- package/dist/runtime/host-load-sampler.d.ts +25 -1
- package/dist/runtime/host-load-sampler.js +38 -7
- package/dist/runtime/host-load-step-run.d.ts +37 -3
- package/dist/runtime/host-load-step-run.js +63 -7
- package/dist/runtime/host-load-test-slot.d.ts +3 -0
- package/dist/runtime/host-load-test-slot.js +26 -7
- package/dist/runtime/host-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +35 -5
- package/dist/runtime/host-runtime-lease.d.ts +28 -3
- package/dist/runtime/host-runtime-lease.js +140 -296
- 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 +78 -2
- package/dist/runtime/host-runtime-promotion.js +307 -14
- 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/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 +4 -0
- package/dist/runtime/runner-settings.js +22 -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 +3 -1
- package/dist/sandbox/host-capacity-broker.js +4 -2
- 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 +1 -2
- package/dist/sandbox/runtime.js +9 -19
- 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/managed-attempt-tools.d.ts +0 -7
- package/dist/session/managed-attempt-tools.js +54 -109
- 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 +10 -5
- package/dist/session/managed-command-host-load.js +18 -14
- 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 +2 -17
- package/dist/session/phase-completion.artifacts.js +65 -166
- package/dist/session/phase-completion.d.ts +27 -2
- package/dist/session/phase-completion.helpers.js +5 -53
- package/dist/session/phase-completion.js +15 -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 +14 -0
- package/dist/session/phase-completion.runtime.d.ts +8 -9
- package/dist/session/phase-completion.runtime.js +65 -196
- package/dist/session/phase-completion.schemas.js +12 -2
- package/dist/session/phase-completion.validation.d.ts +1 -0
- package/dist/session/phase-completion.validation.js +9 -1
- 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.js +6 -5
- 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-process.js +13 -12
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +9 -4
- package/dist/session/pre-publication-validation.js +62 -65
- package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
- package/dist/session/provider-cli/claude-background-work.js +4 -3
- 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 +16 -0
- package/dist/session/provider-cli/pre-publication-repair.js +41 -3
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
- 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 +2 -14
- package/dist/session/provider-cli/provider-cli.process.js +4 -94
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +13 -3
- package/dist/session/provider-cli/provider-cli.prompts.js +137 -84
- 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 +37 -2
- 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 +15 -18
- package/dist/session/provider-cli/provider-cli.service.js +59 -190
- package/dist/session/provider-cli/provider-cli.types.d.ts +7 -2
- 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-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 +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +63 -22
- 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.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 +8 -1
- package/dist/session/session.service.js +177 -239
- package/dist/session/session.types.d.ts +5 -0
- package/dist/session/session.types.js +9 -79
- 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/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 +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- package/dist/shared/provider-capabilities.d.ts +2 -0
- package/dist/shared/provider-capabilities.js +18 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.js +24 -0
- 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 +49 -5
- package/dist/worktree/worktree.service.js +223 -187
- package/dist/worktree/worktree.types.d.ts +47 -0
- package/package.json +1 -1
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -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
|
+
}
|
|
@@ -2,9 +2,8 @@ import type { SessionService } from "../session/session.base.js";
|
|
|
2
2
|
import { type ProviderProcessRunner } from "../session/provider-cli/provider-cli.service.js";
|
|
3
3
|
import { type RunnerSettingsReport } from "../runtime/runner-settings.js";
|
|
4
4
|
import { DockerEngineProbe, type DockerEngineCapabilitySnapshot } from "../runtime/docker-engine-probe.js";
|
|
5
|
-
import { type
|
|
5
|
+
import { type RunOnceDispatchPacket, type RunOnceResultPacket } from "../session/session.types.js";
|
|
6
6
|
import { DockerPreflight } from "../sandbox/preflight.js";
|
|
7
|
-
import type { SandboxPreflightResult } from "../sandbox/sandbox.types.js";
|
|
8
7
|
import { type SandboxRuntime } from "../sandbox/runtime.js";
|
|
9
8
|
import type { BridgeConnection, BridgeConnectionFactory, BridgeRevokedNotice, BridgeService } from "./bridge.base.js";
|
|
10
9
|
import { type RunnerHostCapabilityProbe } from "./runner-host-capabilities.js";
|
|
@@ -12,11 +11,11 @@ import { type HostLoadSource } from "../runtime/host-load-sampler.js";
|
|
|
12
11
|
import type { BridgeCancelHandler, BridgeChatTurnHandler, BridgeDispatchHandler, BridgeLeaseUpdateRequest, BridgeReapRequest, BridgeServiceConfig } from "./bridge.types.js";
|
|
13
12
|
import { type ReadinessResultOutbox } from "./readiness-result-outbox.js";
|
|
14
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";
|
|
15
16
|
export type SandboxResourceResolver = (dispatch: RunOnceDispatchPacket) => Promise<ResolvedSandboxResourceProfile>;
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
readonly sandboxConfigCommitSha: string;
|
|
19
|
-
}
|
|
17
|
+
export { canReserveSandboxResources, resolveDynamicSandboxResources, resolveSandboxResourcesFromRepo, sandboxCapacityFailureMessage, sandboxMemoryCommitmentCapacity, };
|
|
18
|
+
export type { ResolvedSandboxResourceProfile, SandboxResourceVector };
|
|
20
19
|
/**
|
|
21
20
|
* Protocol-v2 events are acknowledged one at a time before runOnce returns.
|
|
22
21
|
* Sending the complete transcript again in DispatchResult made long QA and CI
|
|
@@ -40,6 +39,7 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
40
39
|
private leaseWatchdogTimer;
|
|
41
40
|
private sandboxMaintenanceTimer;
|
|
42
41
|
private sandboxMaintenanceRunning;
|
|
42
|
+
private attemptSnapshotPending;
|
|
43
43
|
private closed;
|
|
44
44
|
private transportRecovery;
|
|
45
45
|
private transportRecoveryGeneration;
|
|
@@ -48,6 +48,8 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
48
48
|
private readonly activeSessions;
|
|
49
49
|
private readonly reservations;
|
|
50
50
|
private readonly activeReadinessProbes;
|
|
51
|
+
/** Everything a bridge restart would interrupt, published for `forge-bridge status --idle`. */
|
|
52
|
+
readonly inFlight: BridgeInFlightRegistry;
|
|
51
53
|
private readonly readinessResultOutbox;
|
|
52
54
|
private readinessResultFlush;
|
|
53
55
|
private readonly dispatchResultOutbox;
|
|
@@ -65,6 +67,9 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
65
67
|
private dockerAvailable;
|
|
66
68
|
private appliedSettingsDocument;
|
|
67
69
|
private localYield;
|
|
70
|
+
/** The yield Forge last acknowledged in a report (Hello, Heartbeat, SettingsApplied); published as `yielding`. */
|
|
71
|
+
private forgeAckedYield;
|
|
72
|
+
private publishState;
|
|
68
73
|
private effectiveSettings;
|
|
69
74
|
private settingsReport;
|
|
70
75
|
/** Applies run one at a time; offers wait for every apply queued before them. */
|
|
@@ -74,12 +79,17 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
74
79
|
private hostRequirementFacts;
|
|
75
80
|
private readonly recoveredHostAttempts;
|
|
76
81
|
private hostCapabilitiesDetected;
|
|
82
|
+
/** The default session service's host load governor, for the startup capacity log line. */
|
|
83
|
+
private readonly hostLoadGovernor;
|
|
77
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;
|
|
78
87
|
connectOnce(): Promise<void>;
|
|
79
88
|
private rememberRecoveredHostAttempts;
|
|
80
89
|
private recoveredHostAttemptsForHello;
|
|
81
90
|
private registerConnection;
|
|
82
91
|
run(signal?: AbortSignal): Promise<void>;
|
|
92
|
+
private startStatePublisher;
|
|
83
93
|
/** The reason Forge gave when it removed this runner, or null while it is paired. */
|
|
84
94
|
get revoked(): string | null;
|
|
85
95
|
/**
|
|
@@ -128,11 +138,14 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
128
138
|
* force (`apply_failed`); their previous values stay in force.
|
|
129
139
|
*/
|
|
130
140
|
private putSettingsInForce;
|
|
141
|
+
private ackYield;
|
|
131
142
|
/** A failed acknowledgement is not retried here: the next heartbeat carries the same report. */
|
|
132
143
|
private sendSettingsApplied;
|
|
133
144
|
stop(): Promise<void>;
|
|
134
145
|
private handleChatTurn;
|
|
135
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;
|
|
136
149
|
private runChatProviderProcess;
|
|
137
150
|
private sendChatProviderEvent;
|
|
138
151
|
private sendChatAbortTerminal;
|
|
@@ -142,6 +155,10 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
142
155
|
private requiredChatCapabilityFailure;
|
|
143
156
|
private bridgeChatCapability;
|
|
144
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;
|
|
145
162
|
private reservedDispatchHandoffIsCurrent;
|
|
146
163
|
private releaseReservedDispatchHandoff;
|
|
147
164
|
private releaseActiveSessionAndRefreshCapacity;
|
|
@@ -152,6 +169,12 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
152
169
|
private redeemPublishGrant;
|
|
153
170
|
private handleLeaseUpdate;
|
|
154
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;
|
|
155
178
|
private parseDispatchOrReport;
|
|
156
179
|
private parseChatTurnOrReport;
|
|
157
180
|
private handleCancel;
|
|
@@ -246,9 +269,3 @@ export declare function canReapManagedSandboxes(preflight: {
|
|
|
246
269
|
readonly unavailableCode?: string | null;
|
|
247
270
|
}): boolean;
|
|
248
271
|
export declare function dockerEngineRequirementFailure(requiredCapabilities: readonly string[], executionMode: string | undefined, capability: DockerEngineCapabilitySnapshot | null): string | null;
|
|
249
|
-
export type SandboxResourceVector = DispatchSandboxResourceRequest;
|
|
250
|
-
export declare function canReserveSandboxResources(used: SandboxResourceVector, requested: SandboxResourceVector, capacity: SandboxResourceVector): boolean;
|
|
251
|
-
export declare function sandboxMemoryCommitmentCapacity(preflight: Pick<SandboxPreflightResult, "totalMemoryBytes" | "availableMemoryBytes" | "hostReserveBytes">, activeMemoryBytes: number): number;
|
|
252
|
-
export declare function sandboxCapacityFailureMessage(used: SandboxResourceVector, requested: SandboxResourceVector, capacity: SandboxResourceVector, preflight: SandboxPreflightResult | null, config: BridgeServiceConfig): string;
|
|
253
|
-
export declare function resolveDynamicSandboxResources(requested: DispatchSandboxResourceRequest, serviceCount: number, networkMode: "offline" | "public_allowlist" | "open_public", baseRuntimeOverheadBytes?: number): DispatchSandboxResourceRequest;
|
|
254
|
-
export declare function resolveSandboxResourcesFromRepo(dispatch: RunOnceDispatchPacket, baseRuntimeOverheadBytes?: number): Promise<ResolvedSandboxResourceProfile>;
|