@loucompanion/forge-bridge 0.1.4-dev.494233aa2e50 → 0.1.4-dev.4e7855579f82

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.
Files changed (217) hide show
  1. package/README.md +144 -3
  2. package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
  3. package/dist/bridge/bridge-chat-provider-command.js +132 -0
  4. package/dist/bridge/bridge-chat.types.d.ts +10 -0
  5. package/dist/bridge/bridge-chat.types.js +16 -1
  6. package/dist/bridge/bridge-state-file.d.ts +161 -0
  7. package/dist/bridge/bridge-state-file.js +376 -0
  8. package/dist/bridge/bridge-state-io.d.ts +11 -0
  9. package/dist/bridge/bridge-state-io.js +50 -0
  10. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  11. package/dist/bridge/bridge-state-lock.js +102 -0
  12. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  13. package/dist/bridge/bridge-state-unpublished.js +111 -0
  14. package/dist/bridge/bridge.base.d.ts +9 -0
  15. package/dist/bridge/bridge.service.d.ts +89 -14
  16. package/dist/bridge/bridge.service.js +423 -342
  17. package/dist/bridge/bridge.types.d.ts +21 -0
  18. package/dist/bridge/in-flight-registry.d.ts +62 -0
  19. package/dist/bridge/in-flight-registry.js +207 -0
  20. package/dist/bridge/local-yield-flag.d.ts +6 -0
  21. package/dist/bridge/local-yield-flag.js +34 -0
  22. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  23. package/dist/bridge/readiness-result-outbox.js +20 -0
  24. package/dist/bridge/runner-host-capabilities.d.ts +5 -0
  25. package/dist/bridge/runner-host-capabilities.js +17 -0
  26. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  27. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  28. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  29. package/dist/bridge/test-postgres-capability.js +120 -0
  30. package/dist/cleanup/cleanup.service.d.ts +9 -0
  31. package/dist/cleanup/cleanup.service.js +72 -109
  32. package/dist/cleanup/cleanup.types.d.ts +4 -0
  33. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  34. package/dist/cleanup/forge-owned-paths.js +53 -0
  35. package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
  36. package/dist/cleanup/host-runtime-ledger.js +109 -0
  37. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  38. package/dist/cleanup/managed-branch-sweep.js +111 -0
  39. package/dist/cli/cli.help.js +74 -12
  40. package/dist/cli/cli.service.d.ts +19 -10
  41. package/dist/cli/cli.service.js +152 -187
  42. package/dist/cli/idle-status.d.ts +84 -0
  43. package/dist/cli/idle-status.js +181 -0
  44. package/dist/cli/local-config.d.ts +6 -0
  45. package/dist/cli/local-config.js +32 -4
  46. package/dist/cli/provider-cli-detection.d.ts +10 -0
  47. package/dist/cli/provider-cli-detection.js +160 -0
  48. package/dist/runtime/aspnet-runtime-prebuild.d.ts +5 -0
  49. package/dist/runtime/aspnet-runtime-prebuild.js +138 -6
  50. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  51. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  52. package/dist/runtime/docker-engine-probe.js +7 -0
  53. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  54. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  55. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  56. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  57. package/dist/runtime/host-facts.d.ts +2 -1
  58. package/dist/runtime/host-load-admission.d.ts +67 -0
  59. package/dist/runtime/host-load-admission.js +99 -0
  60. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  61. package/dist/runtime/host-load-child-environment.js +76 -0
  62. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  63. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  64. package/dist/runtime/host-load-governor-config.d.ts +52 -0
  65. package/dist/runtime/host-load-governor-config.js +83 -0
  66. package/dist/runtime/host-load-governor.d.ts +184 -0
  67. package/dist/runtime/host-load-governor.js +632 -0
  68. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  69. package/dist/runtime/host-load-ledger-lock.js +185 -0
  70. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  71. package/dist/runtime/host-load-runtime-settings.js +78 -0
  72. package/dist/runtime/host-load-sampler.d.ts +75 -2
  73. package/dist/runtime/host-load-sampler.js +142 -8
  74. package/dist/runtime/host-load-step-class.d.ts +70 -0
  75. package/dist/runtime/host-load-step-class.js +161 -0
  76. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  77. package/dist/runtime/host-load-step-reaper.js +95 -0
  78. package/dist/runtime/host-load-step-run.d.ts +73 -0
  79. package/dist/runtime/host-load-step-run.js +102 -0
  80. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  81. package/dist/runtime/host-load-test-slot.js +81 -0
  82. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  83. package/dist/runtime/host-load-token-ledger.js +453 -0
  84. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  85. package/dist/runtime/host-load-windows-cpu.js +85 -0
  86. package/dist/runtime/host-pressure-stall.d.ts +21 -1
  87. package/dist/runtime/host-pressure-stall.js +48 -1
  88. package/dist/runtime/host-runtime-contract.d.ts +15 -0
  89. package/dist/runtime/host-runtime-contract.js +33 -2
  90. package/dist/runtime/host-runtime-lease.d.ts +74 -4
  91. package/dist/runtime/host-runtime-lease.js +285 -55
  92. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  93. package/dist/runtime/host-runtime-promotion.js +48 -0
  94. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  95. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  96. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  97. package/dist/runtime/host-runtime-requirements.js +117 -0
  98. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  99. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  100. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  101. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  102. package/dist/runtime/runner-settings.d.ts +104 -0
  103. package/dist/runtime/runner-settings.js +236 -0
  104. package/dist/sandbox/host-capacity-broker.d.ts +113 -0
  105. package/dist/sandbox/host-capacity-broker.js +334 -0
  106. package/dist/sandbox/runtime.d.ts +10 -1
  107. package/dist/sandbox/runtime.js +45 -2
  108. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  109. package/dist/sandbox/sandbox-cgroups.js +42 -0
  110. package/dist/session/architect-waits.d.ts +2 -0
  111. package/dist/session/architect-waits.js +138 -0
  112. package/dist/session/managed-attempt-tools.d.ts +2 -7
  113. package/dist/session/managed-attempt-tools.js +200 -92
  114. package/dist/session/managed-command-host-load.d.ts +47 -0
  115. package/dist/session/managed-command-host-load.js +83 -0
  116. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  117. package/dist/session/mcp-argument-coercion.js +121 -0
  118. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  119. package/dist/session/phase-completion.artifacts.js +96 -26
  120. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  121. package/dist/session/phase-completion.command-validation.js +77 -0
  122. package/dist/session/phase-completion.d.ts +12 -0
  123. package/dist/session/phase-completion.helpers.js +13 -12
  124. package/dist/session/phase-completion.js +5 -0
  125. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  126. package/dist/session/phase-completion.mcp-args.js +156 -0
  127. package/dist/session/phase-completion.prompts.js +6 -1
  128. package/dist/session/phase-completion.runtime.d.ts +5 -11
  129. package/dist/session/phase-completion.runtime.js +91 -215
  130. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  131. package/dist/session/phase-completion.schema-parts.js +188 -0
  132. package/dist/session/phase-completion.schemas.d.ts +3 -3
  133. package/dist/session/phase-completion.schemas.js +208 -231
  134. package/dist/session/phase-completion.validation.d.ts +2 -3
  135. package/dist/session/phase-completion.validation.js +49 -93
  136. package/dist/session/pre-publication-host-load.d.ts +27 -0
  137. package/dist/session/pre-publication-host-load.js +111 -0
  138. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  139. package/dist/session/pre-publication-native-postgres.js +111 -0
  140. package/dist/session/pre-publication-pass.d.ts +61 -0
  141. package/dist/session/pre-publication-pass.js +148 -0
  142. package/dist/session/pre-publication-process.d.ts +3 -0
  143. package/dist/session/pre-publication-process.js +23 -11
  144. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  145. package/dist/session/pre-publication-step-execution.js +50 -0
  146. package/dist/session/pre-publication-validation.d.ts +37 -21
  147. package/dist/session/pre-publication-validation.js +221 -182
  148. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  149. package/dist/session/provider-cli/claude-background-work.js +181 -0
  150. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  151. package/dist/session/provider-cli/host-build-lock.js +30 -0
  152. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  153. package/dist/session/provider-cli/pre-publication-repair.js +276 -0
  154. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
  155. package/dist/session/provider-cli/provider-cli.artifacts.js +20 -7
  156. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  157. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  158. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  159. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  160. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  161. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  162. package/dist/session/provider-cli/provider-cli.process.d.ts +41 -31
  163. package/dist/session/provider-cli/provider-cli.process.js +139 -438
  164. package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -0
  165. package/dist/session/provider-cli/provider-cli.prompts.js +87 -32
  166. package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
  167. package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
  168. package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
  169. package/dist/session/provider-cli/provider-cli.service.js +146 -182
  170. package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
  171. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  172. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  173. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  174. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  175. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  176. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  177. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  178. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  179. package/dist/session/provider-cli/provider-output-state.d.ts +8 -0
  180. package/dist/session/provider-cli/provider-output-state.js +15 -0
  181. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  182. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  183. package/dist/session/publishable-worktree-changes.d.ts +10 -1
  184. package/dist/session/publishable-worktree-changes.js +21 -5
  185. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  186. package/dist/session/qa-sidecar-validation.js +28 -0
  187. package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
  188. package/dist/session/sandbox-host-capacity-gate.js +238 -0
  189. package/dist/session/session-redaction.js +31 -181
  190. package/dist/session/session.base.d.ts +9 -1
  191. package/dist/session/session.service.d.ts +9 -2
  192. package/dist/session/session.service.js +120 -5
  193. package/dist/session/session.types.d.ts +3 -0
  194. package/dist/session/session.types.js +13 -4
  195. package/dist/session/sidecar-json-shape.d.ts +31 -0
  196. package/dist/session/sidecar-json-shape.js +217 -0
  197. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  198. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  199. package/dist/shared/process/host-process-supervisor.d.ts +1 -0
  200. package/dist/shared/process/host-process-supervisor.js +1 -1
  201. package/dist/shared/process/process-tree.d.ts +52 -0
  202. package/dist/shared/process/process-tree.js +144 -0
  203. package/dist/shared/process/process.d.ts +67 -0
  204. package/dist/shared/process/process.js +213 -11
  205. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  206. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  207. package/dist/shared/process/windows-launch.d.ts +18 -0
  208. package/dist/shared/process/windows-launch.js +68 -0
  209. package/dist/shared/provider-capabilities.js +14 -7
  210. package/dist/version.d.ts +1 -1
  211. package/dist/version.js +1 -1
  212. package/dist/worktree/dependency-warmer.d.ts +25 -0
  213. package/dist/worktree/dependency-warmer.js +46 -10
  214. package/dist/worktree/worktree.service.d.ts +10 -1
  215. package/dist/worktree/worktree.service.js +42 -2
  216. package/dist/worktree/worktree.types.d.ts +7 -0
  217. package/package.json +2 -2
@@ -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 { ProviderProcessRunner } from "../session/provider-cli/provider-cli.process.js";
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 DispatchSandboxResourceRequest, type RunOnceDispatchPacket, type RunOnceResultPacket } from "../session/session.types.js";
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 interface ResolvedSandboxResourceProfile {
16
- readonly resources: DispatchSandboxResourceRequest;
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
@@ -43,9 +43,12 @@ export declare class ForgeBridgeService implements BridgeService {
43
43
  private transportRecovery;
44
44
  private transportRecoveryGeneration;
45
45
  private stopped;
46
+ private revokedReason;
46
47
  private readonly activeSessions;
47
48
  private readonly reservations;
48
49
  private readonly activeReadinessProbes;
50
+ /** Everything a bridge restart would interrupt, published for `forge-bridge status --idle`. */
51
+ readonly inFlight: BridgeInFlightRegistry;
49
52
  private readonly readinessResultOutbox;
50
53
  private readinessResultFlush;
51
54
  private readonly dispatchResultOutbox;
@@ -60,6 +63,19 @@ export declare class ForgeBridgeService implements BridgeService {
60
63
  private readonly sessions;
61
64
  private readonly enforceHostDatabaseCapabilityBoundary;
62
65
  private hostCapabilities;
66
+ private dockerAvailable;
67
+ private appliedSettingsDocument;
68
+ private localYield;
69
+ /** The yield Forge last acknowledged in a report (Hello, Heartbeat, SettingsApplied); published as `yielding`. */
70
+ private forgeAckedYield;
71
+ private publishState;
72
+ private effectiveSettings;
73
+ private settingsReport;
74
+ /** Applies run one at a time; offers wait for every apply queued before them. */
75
+ private settingsTail;
76
+ private pendingYieldOn;
77
+ private settingsStarted;
78
+ private hostRequirementFacts;
63
79
  private readonly recoveredHostAttempts;
64
80
  private hostCapabilitiesDetected;
65
81
  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);
@@ -68,6 +84,58 @@ export declare class ForgeBridgeService implements BridgeService {
68
84
  private recoveredHostAttemptsForHello;
69
85
  private registerConnection;
70
86
  run(signal?: AbortSignal): Promise<void>;
87
+ private startStatePublisher;
88
+ /** The reason Forge gave when it removed this runner, or null while it is paired. */
89
+ get revoked(): string | null;
90
+ /**
91
+ * Decision 0014 §3 "Remove": Forge removed this runner. Stop for good instead of
92
+ * reconnecting; its attempts were already settled on the server, so local work is
93
+ * aborted rather than reported.
94
+ */
95
+ private handleRevoked;
96
+ /** The effective settings and how they were derived, as last reported (decision 0014). */
97
+ get runnerSettings(): RunnerSettingsReport;
98
+ private runnerHostDefaults;
99
+ /**
100
+ * Once per bridge process: drop governor overrides an earlier process left on
101
+ * the state root, then put today's effective settings (env bounds and the local
102
+ * yield flag, no server document yet) in force.
103
+ */
104
+ private startSettings;
105
+ /**
106
+ * Decision 0014 `ApplySettings`. Applies only a document newer than the one
107
+ * applied, one at a time, then acknowledges it with `SettingsApplied`. A replay of
108
+ * the applied version is acknowledged again without applying it; an older one is
109
+ * ignored.
110
+ */
111
+ private handleApplySettings;
112
+ /**
113
+ * Polls the local `forge-bridge yield` flag (every heartbeat and before each
114
+ * offer decision). A change is applied at once and reported again under the
115
+ * same settings version.
116
+ */
117
+ /** Yielding now, or about to: a received yield-on that is still being applied counts. */
118
+ private yieldingOrQueued;
119
+ private refreshLocalYield;
120
+ /**
121
+ * A setting the host couldn't put in force holds placement on the server, so
122
+ * every heartbeat tries the applied document again until it takes.
123
+ */
124
+ private retryFailedSettings;
125
+ private readLocalYield;
126
+ private enqueueSettings;
127
+ private applySettings;
128
+ /**
129
+ * Max attempts and the memory reserve go to host attempt admission; the governor
130
+ * budget (the yield budget while yielding) and the heavy-step limit go to the
131
+ * shared settings file every governor on the state root reads at admission.
132
+ * Neither touches admitted work. Returns the keys the host could not put in
133
+ * force (`apply_failed`); their previous values stay in force.
134
+ */
135
+ private putSettingsInForce;
136
+ private ackYield;
137
+ /** A failed acknowledgement is not retried here: the next heartbeat carries the same report. */
138
+ private sendSettingsApplied;
71
139
  stop(): Promise<void>;
72
140
  private handleChatTurn;
73
141
  private createChatTurnWorkspace;
@@ -80,6 +148,10 @@ export declare class ForgeBridgeService implements BridgeService {
80
148
  private requiredChatCapabilityFailure;
81
149
  private bridgeChatCapability;
82
150
  private handleDispatch;
151
+ private registerActiveDispatch;
152
+ private dispatchEventSink;
153
+ /** Runs the dispatch on the host or in its Docker sandbox, logging start and end with its ids. */
154
+ private runDispatchOnce;
83
155
  private reservedDispatchHandoffIsCurrent;
84
156
  private releaseReservedDispatchHandoff;
85
157
  private releaseActiveSessionAndRefreshCapacity;
@@ -144,6 +216,13 @@ export declare class ForgeBridgeService implements BridgeService {
144
216
  private waitForClose;
145
217
  private stopConnection;
146
218
  }
219
+ /** The `run` command's exit code after Forge removed the runner. */
220
+ export declare const bridgeRevokedExitCode = 3;
221
+ export declare const bridgeRevokedMessage = "This bridge was removed from Forge. Pair it again with forge-bridge pair.";
222
+ /** Thrown by `run` after Forge removed the runner, so the CLI exits instead of reconnecting. */
223
+ export declare class BridgeRevokedError extends Error {
224
+ constructor(message?: string);
225
+ }
147
226
  export declare class SignalRBridgeConnectionFactory implements BridgeConnectionFactory {
148
227
  create(config: BridgeServiceConfig): BridgeConnection;
149
228
  }
@@ -151,6 +230,8 @@ export declare class SignalRBridgeConnection implements BridgeConnection {
151
230
  private readonly config;
152
231
  private readonly connection;
153
232
  constructor(config: BridgeServiceConfig);
233
+ onApplySettings(handler: (document: unknown) => void | Promise<void>): void;
234
+ onRevoked(handler: (notice: BridgeRevokedNotice) => void): void;
154
235
  start(): Promise<void>;
155
236
  stop(): Promise<void>;
156
237
  onClose(handler: (error?: Error) => void): void;
@@ -175,9 +256,3 @@ export declare function canReapManagedSandboxes(preflight: {
175
256
  readonly unavailableCode?: string | null;
176
257
  }): boolean;
177
258
  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>;