@loucompanion/forge-bridge 0.1.3-dev.5e880f4c0920 → 0.1.3-dev.66e9a6e6a9f9

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 (158) hide show
  1. package/README.md +95 -0
  2. package/dist/bridge/bridge.base.d.ts +8 -1
  3. package/dist/bridge/bridge.service.d.ts +84 -3
  4. package/dist/bridge/bridge.service.js +1252 -45
  5. package/dist/bridge/bridge.types.d.ts +176 -1
  6. package/dist/cleanup/cleanup.service.d.ts +14 -2
  7. package/dist/cleanup/cleanup.service.js +496 -3
  8. package/dist/cleanup/cleanup.types.d.ts +10 -0
  9. package/dist/cleanup/index.d.ts +1 -1
  10. package/dist/cleanup/index.js +1 -1
  11. package/dist/cleanup/internals.d.ts +2 -2
  12. package/dist/cleanup/internals.js +1 -1
  13. package/dist/cli/cli.help.js +47 -1
  14. package/dist/cli/cli.service.d.ts +42 -2
  15. package/dist/cli/cli.service.js +360 -26
  16. package/dist/cli/local-config.d.ts +6 -0
  17. package/dist/cli/local-config.js +47 -3
  18. package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
  19. package/dist/runtime/aspnet-runtime-prebuild.js +340 -0
  20. package/dist/runtime/attempt-node-runtime-launcher.d.ts +17 -0
  21. package/dist/runtime/attempt-node-runtime-launcher.js +105 -0
  22. package/dist/runtime/attempt-process-supervisor-registry.d.ts +20 -0
  23. package/dist/runtime/attempt-process-supervisor-registry.js +64 -0
  24. package/dist/runtime/attempt-process-supervisor.d.ts +97 -0
  25. package/dist/runtime/attempt-process-supervisor.js +384 -0
  26. package/dist/runtime/generated-output-reset.d.ts +10 -0
  27. package/dist/runtime/generated-output-reset.js +103 -0
  28. package/dist/runtime/host-listener-inspector.d.ts +46 -0
  29. package/dist/runtime/host-listener-inspector.js +349 -0
  30. package/dist/runtime/host-port-broker.d.ts +76 -0
  31. package/dist/runtime/host-port-broker.js +333 -0
  32. package/dist/runtime/host-runtime-contract.d.ts +47 -0
  33. package/dist/runtime/host-runtime-contract.js +700 -0
  34. package/dist/runtime/host-runtime-lease.d.ts +194 -0
  35. package/dist/runtime/host-runtime-lease.js +2138 -0
  36. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  37. package/dist/runtime/host-runtime-promotion.js +159 -0
  38. package/dist/runtime/memory-capacity.d.ts +68 -0
  39. package/dist/runtime/memory-capacity.js +121 -0
  40. package/dist/runtime/node-host-runtime-adapter.d.ts +54 -0
  41. package/dist/runtime/node-host-runtime-adapter.js +284 -0
  42. package/dist/runtime/playwright-host-runtime-adapter.d.ts +21 -0
  43. package/dist/runtime/playwright-host-runtime-adapter.js +225 -0
  44. package/dist/runtime/runtime-isolation-lease.d.ts +67 -0
  45. package/dist/runtime/runtime-isolation-lease.js +158 -0
  46. package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
  47. package/dist/runtime/workspace-resource-estimator.js +174 -0
  48. package/dist/sandbox/command-runner.d.ts +4 -0
  49. package/dist/sandbox/command-runner.js +47 -0
  50. package/dist/sandbox/contract.d.ts +5 -0
  51. package/dist/sandbox/contract.js +276 -0
  52. package/dist/sandbox/event-budget.d.ts +11 -0
  53. package/dist/sandbox/event-budget.js +27 -0
  54. package/dist/sandbox/image-policy.d.ts +35 -0
  55. package/dist/sandbox/image-policy.js +247 -0
  56. package/dist/sandbox/index.d.ts +5 -0
  57. package/dist/sandbox/index.js +5 -0
  58. package/dist/sandbox/lease-watchdog.d.ts +18 -0
  59. package/dist/sandbox/lease-watchdog.js +67 -0
  60. package/dist/sandbox/preflight.d.ts +84 -0
  61. package/dist/sandbox/preflight.js +521 -0
  62. package/dist/sandbox/process.d.ts +20 -0
  63. package/dist/sandbox/process.js +209 -0
  64. package/dist/sandbox/provider-auth/codex.d.ts +26 -0
  65. package/dist/sandbox/provider-auth/codex.js +212 -0
  66. package/dist/sandbox/repository-lock.d.ts +5 -0
  67. package/dist/sandbox/repository-lock.js +121 -0
  68. package/dist/sandbox/runtime.d.ts +297 -0
  69. package/dist/sandbox/runtime.js +2338 -0
  70. package/dist/sandbox/sandbox.types.d.ts +93 -0
  71. package/dist/sandbox/sandbox.types.js +1 -0
  72. package/dist/sandbox/smoke.d.ts +76 -0
  73. package/dist/sandbox/smoke.js +380 -0
  74. package/dist/sandbox/worker-supervisor.d.ts +13 -0
  75. package/dist/sandbox/worker-supervisor.js +36 -0
  76. package/dist/sandbox/worker.d.ts +1 -0
  77. package/dist/sandbox/worker.js +225 -0
  78. package/dist/sandbox/workspace.service.d.ts +13 -0
  79. package/dist/sandbox/workspace.service.js +72 -0
  80. package/dist/session/managed-attempt-tools.d.ts +18 -0
  81. package/dist/session/managed-attempt-tools.js +854 -0
  82. package/dist/session/managed-build-coordinator.d.ts +5 -0
  83. package/dist/session/managed-build-coordinator.js +105 -0
  84. package/dist/session/managed-build-receipt.d.ts +21 -0
  85. package/dist/session/managed-build-receipt.js +335 -0
  86. package/dist/session/phase-completion.artifacts.d.ts +17 -0
  87. package/dist/session/phase-completion.artifacts.js +256 -26
  88. package/dist/session/phase-completion.d.ts +11 -2
  89. package/dist/session/phase-completion.helpers.d.ts +5 -0
  90. package/dist/session/phase-completion.helpers.js +51 -10
  91. package/dist/session/phase-completion.js +12 -3
  92. package/dist/session/phase-completion.prompts.d.ts +3 -3
  93. package/dist/session/phase-completion.prompts.js +21 -6
  94. package/dist/session/phase-completion.runtime.d.ts +13 -1
  95. package/dist/session/phase-completion.runtime.js +189 -8
  96. package/dist/session/phase-completion.schemas.js +108 -3
  97. package/dist/session/phase-completion.validation.d.ts +4 -1
  98. package/dist/session/phase-completion.validation.js +151 -21
  99. package/dist/session/provider-cli/ci-repair-readiness.d.ts +14 -0
  100. package/dist/session/provider-cli/ci-repair-readiness.js +105 -0
  101. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +3 -2
  102. package/dist/session/provider-cli/provider-cli.artifacts.js +65 -7
  103. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  104. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +2 -0
  105. package/dist/session/provider-cli/provider-cli.deterministic.js +66 -9
  106. package/dist/session/provider-cli/provider-cli.process.d.ts +24 -0
  107. package/dist/session/provider-cli/provider-cli.process.js +431 -21
  108. package/dist/session/provider-cli/provider-cli.prompts.d.ts +16 -2
  109. package/dist/session/provider-cli/provider-cli.prompts.js +217 -20
  110. package/dist/session/provider-cli/provider-cli.qa-sidecars.js +1 -0
  111. package/dist/session/provider-cli/provider-cli.runtime.d.ts +1 -1
  112. package/dist/session/provider-cli/provider-cli.runtime.js +6 -3
  113. package/dist/session/provider-cli/provider-cli.service.d.ts +24 -3
  114. package/dist/session/provider-cli/provider-cli.service.js +579 -90
  115. package/dist/session/provider-cli/provider-cli.types.d.ts +5 -0
  116. package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
  117. package/dist/session/provider-cli/provider-output-state.js +91 -16
  118. package/dist/session/provider-cli/provider-usage.d.ts +7 -0
  119. package/dist/session/provider-cli/provider-usage.js +28 -5
  120. package/dist/session/session-redaction.d.ts +3 -0
  121. package/dist/session/session-redaction.js +38 -0
  122. package/dist/session/session.base.d.ts +6 -1
  123. package/dist/session/session.service.d.ts +8 -2
  124. package/dist/session/session.service.js +530 -42
  125. package/dist/session/session.types.d.ts +122 -1
  126. package/dist/session/session.types.js +229 -4
  127. package/dist/shared/format/format-bytes.d.ts +1 -0
  128. package/dist/shared/format/format-bytes.js +9 -0
  129. package/dist/shared/path/path.d.ts +1 -0
  130. package/dist/shared/path/path.js +21 -1
  131. package/dist/shared/process/host-process-recovery.d.ts +12 -0
  132. package/dist/shared/process/host-process-recovery.js +78 -0
  133. package/dist/shared/process/host-process-supervisor.d.ts +59 -0
  134. package/dist/shared/process/host-process-supervisor.js +330 -0
  135. package/dist/shared/process/process.d.ts +1 -0
  136. package/dist/shared/process/process.js +1 -0
  137. package/dist/shared/provider-capabilities.d.ts +1 -0
  138. package/dist/shared/provider-capabilities.js +3 -0
  139. package/dist/shared/redaction/redaction.js +16 -4
  140. package/dist/version.d.ts +1 -1
  141. package/dist/version.js +1 -1
  142. package/dist/worktree/artifact-injector.d.ts +3 -2
  143. package/dist/worktree/artifact-injector.js +43 -4
  144. package/dist/worktree/dependency-warmer.d.ts +28 -1
  145. package/dist/worktree/dependency-warmer.js +308 -9
  146. package/dist/worktree/index.d.ts +2 -1
  147. package/dist/worktree/index.js +1 -0
  148. package/dist/worktree/prior-phase-artifact-hydrator.d.ts +2 -0
  149. package/dist/worktree/prior-phase-artifact-hydrator.js +136 -0
  150. package/dist/worktree/worktree-paths.d.ts +4 -0
  151. package/dist/worktree/worktree-paths.js +30 -0
  152. package/dist/worktree/worktree.base.d.ts +3 -0
  153. package/dist/worktree/worktree.service.d.ts +9 -2
  154. package/dist/worktree/worktree.service.js +217 -48
  155. package/dist/worktree/worktree.types.d.ts +5 -1
  156. package/package.json +8 -4
  157. package/runtime/windows-job-supervisor.ps1 +444 -0
  158. package/runtime/windows-listener-owner.ps1 +33 -0
package/README.md CHANGED
@@ -33,6 +33,16 @@ The bridge can also read connection settings from environment variables:
33
33
  - `FORGE_CLI_PROVIDERS`
34
34
  - `FORGE_CODEX_MODELS` / `FORGE_CURSOR_MODELS` (optional comma-separated model ids advertised in runner capabilities)
35
35
 
36
+ Show or change the saved server without editing `bridge.json`:
37
+
38
+ ```bash
39
+ forge-bridge server show
40
+ forge-bridge server set http://localhost:5208
41
+ forge-bridge server set https://srv1493013.tail66073d.ts.net:8443
42
+ ```
43
+
44
+ `FORGE_URL` overrides the saved server. Changing the saved URL retains runner credentials so aliases for the same deployment keep working; pair again with `--server` when switching to a different Forge deployment.
45
+
36
46
  ## Repo-local development
37
47
 
38
48
  For active Forge branch development, run the bridge directly from the checkout instead of publishing a package:
@@ -53,6 +63,91 @@ forge-bridge add-repo Forge /path/to/Forge
53
63
  forge-bridge remove-repo Forge
54
64
  ```
55
65
 
66
+ ## Docker sandbox runners
67
+
68
+ Protocol-v2 bridges preflight Docker before advertising the `docker` sandbox runtime. Validate a repository contract and the local runner before enabling a project's `sandbox_required` policy:
69
+
70
+ ```bash
71
+ forge sandbox init
72
+ forge sandbox doctor
73
+ forge sandbox smoke
74
+ forge-bridge sandbox reap
75
+ ```
76
+
77
+ Configure the local bridge's persistent Docker placement policy with:
78
+
79
+ ```bash
80
+ forge-bridge sandbox on
81
+ forge-bridge sandbox on --allow-open-public
82
+ forge-bridge sandbox status
83
+ forge-bridge sandbox off
84
+ ```
85
+
86
+ `sandbox on` keeps unrestricted public networking denied by default. The developer-only
87
+ `--allow-open-public` option stores an explicit local approval in `bridge.json`; it survives
88
+ bridge restarts and is reported by `sandbox status`. Restart a connected bridge after changing
89
+ the policy. `FORGE_DOCKER_SANDBOX` and `FORGE_ALLOW_OPEN_PUBLIC_SANDBOX` remain higher-priority
90
+ operator overrides when present.
91
+
92
+ `forge sandbox smoke` runs doctor, builds the repository-owned `.forge/Dockerfile`, launches a disposable hardened container on an internal network with a fresh workspace volume, and verifies that its exact attempt-labeled container, network, volume, and image are gone afterward. It writes a redacted JSON report under `FORGE_SANDBOX_STATE_ROOT/smoke-reports`; use `--report <path>` to choose a different destination. Stop the connected bridge before running smoke so the command can exclusively acquire the Docker-context ownership lock.
93
+
94
+ Use `forge sandbox smoke --probe-loopback-port` only when proving Docker host-port allocation. The normal hardened container remains internal with no publication; a separate exact-labeled fixture requests `127.0.0.1::8080/tcp`, records Docker's assigned loopback port, rejects wildcard or ambiguous mappings, and is removed by the same exact-label cleanup verification.
95
+
96
+ Production shared runners require a Linux rootless Docker daemon. Docker Desktop is developer-only and must be opted in with `FORGE_ALLOW_DOCKER_DESKTOP_SANDBOX=true`. Useful runner settings are:
97
+
98
+ - `FORGE_TRUST_DOMAIN_ID` — must match the project trust domain.
99
+ - `FORGE_MAX_CONCURRENT_SANDBOXES` — hard slot ceiling; start at `1`.
100
+ - `FORGE_MAX_CONCURRENT_SANDBOX_BUILDS` / `FORGE_SANDBOX_PID_CAPACITY` — weighted build and PID admission ceilings (defaults: `1` and `2048`).
101
+ - `FORGE_DOCKER_CONTEXT` / `FORGE_DOCKER_EXECUTABLE` — dedicated daemon selection.
102
+ - `FORGE_SANDBOX_STATE_ROOT` — fsync'd attempt ledgers, restricted diagnostics, and build state.
103
+ - `FORGE_DISK_HIGH_WATERMARK_PERCENT` / `FORGE_DISK_LOW_WATERMARK_PERCENT` / `FORGE_MINIMUM_WORKSPACE_BYTES` — admission watermarks with high/low hysteresis.
104
+ - Per-attempt workspace reservations are calculated from the repository source footprint, detected Node/.NET/browser toolchains, the execution role, and immutable sandbox app services. The API uses that request for local and Bridge placement; a Bridge rechecks its authoritative checkout and Docker contract before acceptance. Shared Docker images and package caches remain runner-level capacity, while `FORGE_MINIMUM_WORKSPACE_BYTES` remains a separate host safety reserve rather than a per-lane charge.
105
+ - `FORGE_SANDBOX_HOST_MEMORY_RESERVE_BYTES` — explicit host-memory safety-reserve override for sandbox admission. Without an override, Forge derives a bounded reserve from the sampled capacity domain (Linux: 12.5%, 1–4 GiB; Docker Desktop development: 6.25%, 1–2 GiB). The floor, ceiling, and percentage are configurable with `FORGE_SANDBOX_HOST_MEMORY_RESERVE_FLOOR_BYTES`, `FORGE_SANDBOX_HOST_MEMORY_RESERVE_CEILING_BYTES`, and `FORGE_SANDBOX_HOST_MEMORY_RESERVE_PERCENT`.
106
+ - Managed-host admission uses the same bounded 12.5% physical-memory policy through `FORGE_HOST_MEMORY_RESERVE_BYTES` or its `_FLOOR_BYTES`, `_CEILING_BYTES`, and `_PERCENT` controls. Pressure is applied immediately; recovery requires two samples one second apart by default (`FORGE_HOST_MEMORY_RECOVERY_SAMPLES` and `FORGE_HOST_MEMORY_RECOVERY_SAMPLE_INTERVAL_MS`). `FORGE_HOST_DEFAULT_WORKER_MEMORY_LIMIT_BYTES` configures only the conservative cold-start fallback for legacy packets that omit an exact worker request; current packets remain governed by their explicit role request.
107
+ - `FORGE_SANDBOX_MEMORY_SAMPLE_INTERVAL_MS` — interval for sampled Docker peak-memory telemetry (default `1000` ms, clamped to `250`–`30000` ms). Sampling is diagnostic and never changes an attempt outcome.
108
+ - `FORGE_SANDBOX_DEDICATED_DISK=true` — operator assertion that sandbox storage is on a dedicated, conservatively watermarked disk when the Docker storage driver cannot enforce per-volume quotas. `sandbox_required` fails placement unless either quota support or this assertion is advertised.
109
+ - `FORGE_SANDBOX_IMAGE_RETENTION_COUNT` / `FORGE_SANDBOX_IMAGE_RETENTION_TTL_MS` — per-project image-cache retention (defaults: 3 images and 7 days).
110
+ - `FORGE_SANDBOX_AUDIT_RETENTION_COUNT` / `FORGE_SANDBOX_AUDIT_RETENTION_TTL_MS` — restricted failed-build/attestation retention (defaults: 200 keys and 30 days); evidence for active image digests is protected.
111
+ - `FORGE_AGENT_TOOLING_IMAGE` — digest-pinned Node tooling base required by `sandbox_required`.
112
+ - `FORGE_SANDBOX_IMAGE_POLICY_ENFORCED`, `FORGE_SANDBOX_SBOM_EXECUTABLE`, `FORGE_SANDBOX_VULNERABILITY_EXECUTABLE`, and `FORGE_SANDBOX_PROVENANCE_SIGNING_KEY` — required generated-image promotion gates. The SBOM command must accept Syft-compatible `<image> -o spdx-json`; the vulnerability command must accept Trivy-compatible image arguments.
113
+ - `FORGE_SANDBOX_SIGNATURE_EXECUTABLE` / `FORGE_SANDBOX_SIGNATURE_PUBLIC_KEY` — Cosign-compatible verifier and bounded public-key file. `sandbox_required` verifies every digest-pinned external Dockerfile base/`COPY --from` source and Forge tooling base before generated-image promotion, plus every service-catalog and egress-proxy image before runtime use; adoption modes emit a warning when verification is not configured.
114
+ - `FORGE_SANDBOX_BUILD_EGRESS_ENFORCED` — confirms the dedicated BuildKit builder is behind the approved build-egress control; required for `sandbox_required`.
115
+ - `FORGE_SANDBOX_BUILD_NOFILE` — bounded per-build-step file-descriptor cap (default: `4096`). `FORGE_SANDBOX_BUILDER_PIDS_LIMIT` caps and verifies aggregate processes on the dedicated BuildKit container (default `512`). Buildx `--resource` memory/CPU caps are intentionally not emitted because they are not portable across supported Buildx versions; agent runtime containers still receive Docker memory/CPU limits.
116
+ - `FORGE_SANDBOX_BUILDKIT_CACHE_MAX` / `FORGE_SANDBOX_BUILDKIT_CACHE_RESERVED` — pressure-triggered dedicated-builder cache bounds (defaults: 20 GiB maximum and 2 GiB reserved; minimum free space follows `FORGE_MINIMUM_WORKSPACE_BYTES`).
117
+ - `FORGE_SANDBOX_SECCOMP_PROFILE` / `FORGE_SANDBOX_LSM_SECURITY_OPT` — absolute hardened seccomp profile and AppArmor/SELinux Docker security option applied to every agent and service; required for `sandbox_required`.
118
+ - `FORGE_SANDBOX_HARD_WALL_SECONDS` / `FORGE_SANDBOX_IDLE_SECONDS` — monotonic worker deadlines (defaults: 8 hours and 30 minutes; both are capped by the 8-hour hard maximum).
119
+ - `FORGE_SANDBOX_PUBLICATION_MODE=bridge_push` — remote-safe exact-SHA result publication. This is required for `sandbox_required`; the default `shared_filesystem` mode is intended only for deployments where the bridge and API intentionally share the repository filesystem.
120
+ - `FORGE_SERVICE_POSTGRES_IMAGE`, `FORGE_SERVICE_REDIS_IMAGE`, and `FORGE_SERVICE_BROWSER_IMAGE` — digest-pinned service-catalog images when declared by a contract.
121
+
122
+ `public_allowlist` uses an internal agent network plus a separate external network joined only by a restricted Squid-compatible proxy. Configure a digest-pinned `FORGE_SANDBOX_EGRESS_PROXY_IMAGE` and `FORGE_SANDBOX_EGRESS_ENFORCED=true`; Forge generates the domain allowlist with private, loopback, link-local, metadata, unsafe-port, and default-deny rules and injects proxy variables into the worker. `open_public` is developer-only and additionally requires `FORGE_ALLOW_OPEN_PUBLIC_SANDBOX=true`. Neither setting weakens `sandbox_required`.
123
+
124
+ Before selecting `sandbox_required`, save the full approved 40- or 64-character Git commit SHA in the project's Sandbox policy dialog. The server persists that SHA on the immutable attempt and the bridge reads `.forge/forge.sandbox.yml`, `.forge/Dockerfile`, and the tracked build context only from that commit. API-key dispatches carry an opaque one-time grant handle; the authenticated current runner instance redeems it after reservation, and plaintext stays out of offers, database payloads, Docker metadata, and host-persisted control files.
125
+
126
+ Temporary host fallback for `sandbox_preferred` requires both sides to opt in: a project owner must save a reason and future expiry (maximum 30 days), and an operator must enable **Host fallback** for the runner in Profile Settings. Either missing or expired authorization fails closed. `sandbox_required` never falls back.
127
+
128
+ The bridge reaps exact-labeled orphan resources before connecting and every minute afterward. Connected passes reconcile current-instance ledgers against an authoritative, instance-scoped server attempt snapshot; startup does not adopt old-instance resources and terminates them before advertising capacity. Per-resource removal outcomes are written mode-0600 under `FORGE_SANDBOX_STATE_ROOT/cleanup-reports` before transmission, replayed after reconnect, acknowledged by report ID, and persisted by the API only when attempt, fence, resource runner instance, and current reporting runner match. Fenced dispatch events also persist image/cache status, build/agent-start/import/teardown timestamps, and a validated inventory of created agent/sidecar containers, networks, volumes, and published ports. Selected-session diagnostics expose that lifecycle data and recent cleanup actions while retaining cleanup-pending state after the agent outcome is terminal. Install `forge-bridge sandbox reap` as an independently supervised OS timer with the same `FORGE_RUNNER_ID`, Docker context, and state root so resources are reconciled while the bridge is down; the Docker-context ownership lock makes an overlapping pass fail safely. A non-zero `degradedReservationCount` means teardown has not completed; the affected capacity remains unavailable until a successful reaper pass. Drain a runner from Profile Settings before upgrades or Docker maintenance, wait for active/starting counts to reach zero, then restart the bridge. Profile Settings also exposes a scoped **Reap** action; the API delivers it only to the currently established protocol-v2 runner instance. Image GC runs only while disk pressure is latched, shares the build lock, preserves active image digests, and prunes only expired images beyond the per-project retention count. Lease renewals are HMAC-bound to the attempt and fence and advance an in-container monotonic deadline; lease, hard-wall, and idle expiry produce distinct failure codes.
129
+
130
+ Every attempt-owned container (including short-lived initialization helpers), network, and volume carries `dev.forge.resource-lease-id` equal to the dispatch execution lease. Ledger schema v2 persists the same `resourceLeaseId`; teardown compares the complete expected label set, and orphan reaping fails closed unless the managed, resource-lease, execution-lease, attempt, runner, runner-instance, and fencing identities are all present and consistent.
131
+
132
+ In `bridge_push` mode, the start packet carries only an attempt/fence/branch-bound publication handle. After validating and importing the output bundle, the authenticated current bridge redeems that handle for an in-memory, exact-repository credential; the API rechecks the live lease/fence/grant/branch/result SHA and records redemption before returning it. Git receives the credential through a process environment configuration, never command arguments, files, Git config, or the container. The bridge compares the remote branch with the immutable input commit and pushes only the exact result commit using `--force-with-lease`; cancellation aborts Git, an already-published matching result is an idempotent success, and any other remote value is rejected as stale. The API records the fenced publication acknowledgment before sign-off and does not push the branch a second time while opening the pull request.
133
+
134
+ Failed project, tooling, and agent image stages preserve only a redacted, capped, mode-0600 diagnostic at `FORGE_SANDBOX_STATE_ROOT/build-logs/<image-key>/<stage>.log`. The event stream carries its digest, byte count, and truncation flag, never the log contents. Treat this directory as restricted source-bearing audit data and apply local retention controls.
135
+
136
+ ## Owned test evidence
137
+
138
+ `npm test` closes a manifest over the complete Bridge source, test, runtime, configuration, workflow,
139
+ and imported fixture set before compilation. It records the Git commit and exact Node, npm, Git, .NET,
140
+ TypeScript, Vitest, OS, and temporary-root identities, compiles into an owned temporary root, runs
141
+ Vitest through the Windows process-tree supervisor, revalidates the source and toolchain, independently
142
+ rehashes the compiled output, and removes the exact owner root before reporting success.
143
+
144
+ Set `FORGE_BRIDGE_SUITE_RECEIPT_PATH` to an absolute path for a nonexistent output file to retain the
145
+ verified execution receipt. On Windows evidence runs, `TEMP`, `TMP`, `TMPDIR`, and `FORGE_TMPDIR` may
146
+ point to the same short, empty, high-capacity root. This changes only owned temporary-file placement; it
147
+ does not weaken disk, memory, cleanup, or Docker preflight policy. A Bridge receipt remains
148
+ `fullGateAttested=false` until the suite is registered with the live residue auditor and the required
149
+ source/toolchain-identical repeat evidence is complete.
150
+
56
151
  ## Package smoke check
57
152
 
58
153
  From this package directory:
@@ -1,4 +1,4 @@
1
- import type { BridgeCancelHandler, BridgeDispatchHandler, BridgeServiceConfig } from "./bridge.types.js";
1
+ import type { BridgeCancelHandler, BridgeDispatchHandler, BridgeLeaseUpdateHandler, BridgeOfferHandler, BridgeReadinessProbeHandler, BridgeReapHandler, BridgeServiceConfig, BridgeStartHandler } from "./bridge.types.js";
2
2
  export interface BridgeService {
3
3
  connectOnce(): Promise<void>;
4
4
  run(signal?: AbortSignal): Promise<void>;
@@ -8,8 +8,15 @@ export interface BridgeConnection {
8
8
  start(): Promise<void>;
9
9
  stop(): Promise<void>;
10
10
  onClose(handler: (error?: Error) => void): void;
11
+ onReconnecting?(handler: (error?: Error) => void): void;
12
+ onReconnected?(handler: (connectionId?: string) => void | Promise<void>): void;
11
13
  onDispatch(handler: BridgeDispatchHandler): void;
14
+ onOffer?(handler: BridgeOfferHandler): void;
15
+ onStart?(handler: BridgeStartHandler): void;
16
+ onLeaseUpdate?(handler: BridgeLeaseUpdateHandler): void;
12
17
  onCancel(handler: BridgeCancelHandler): void;
18
+ onReap?(handler: BridgeReapHandler): void;
19
+ onReadinessProbe?(handler: BridgeReadinessProbeHandler): void;
13
20
  invoke<TResponse>(methodName: string, payload: unknown): Promise<TResponse>;
14
21
  }
15
22
  export interface BridgeConnectionFactory {
@@ -1,30 +1,91 @@
1
1
  import type { SessionService } from "../session/session.base.js";
2
+ import { type DispatchSandboxResourceRequest, type RunOnceDispatchPacket, type RunOnceResultPacket } from "../session/session.types.js";
3
+ import { DockerPreflight } from "../sandbox/preflight.js";
4
+ import type { SandboxPreflightResult } from "../sandbox/sandbox.types.js";
5
+ import { type SandboxRuntime } from "../sandbox/runtime.js";
2
6
  import type { BridgeConnection, BridgeConnectionFactory, BridgeService } from "./bridge.base.js";
3
- import type { BridgeCancelHandler, BridgeDispatchHandler, BridgeServiceConfig } from "./bridge.types.js";
7
+ import type { BridgeCancelHandler, BridgeDispatchHandler, BridgeLeaseUpdateRequest, BridgeReapRequest, BridgeServiceConfig } from "./bridge.types.js";
8
+ export type SandboxResourceResolver = (dispatch: RunOnceDispatchPacket) => Promise<ResolvedSandboxResourceProfile>;
9
+ export interface ResolvedSandboxResourceProfile {
10
+ readonly resources: DispatchSandboxResourceRequest;
11
+ readonly sandboxConfigCommitSha: string;
12
+ }
13
+ /**
14
+ * Protocol-v2 events are acknowledged one at a time before runOnce returns.
15
+ * Sending the complete transcript again in DispatchResult made long QA and CI
16
+ * sessions exceed SignalR's receive limit, disconnecting the bridge after the
17
+ * provider had already completed. The API combines its acknowledged streamed
18
+ * events with the terminal result, so the callback only needs the outcome and
19
+ * artifacts. Protocol v1 retains the transcript for legacy servers.
20
+ */
21
+ export declare function compactTerminalResult(dispatch: RunOnceDispatchPacket, result: RunOnceResultPacket): RunOnceResultPacket;
4
22
  export declare class ForgeBridgeService implements BridgeService {
5
23
  private readonly config;
6
- private readonly sessions;
7
24
  private readonly connections;
8
25
  private connection;
9
26
  private heartbeatTimer;
27
+ private heartbeatInFlight;
28
+ private consecutiveHeartbeatFailures;
29
+ private reconnectingFromHeartbeatFailure;
30
+ private leaseWatchdogTimer;
31
+ private sandboxMaintenanceTimer;
32
+ private sandboxMaintenanceRunning;
10
33
  private closed;
34
+ private transportRecovery;
35
+ private transportRecoveryGeneration;
11
36
  private stopped;
12
37
  private readonly activeSessions;
13
- constructor(config: BridgeServiceConfig, sessions?: SessionService, connections?: BridgeConnectionFactory);
38
+ private readonly reservations;
39
+ private readonly activeReadinessProbes;
40
+ private readonly preflight;
41
+ private readonly sandboxRuntime;
42
+ private readonly sandboxResourceResolver;
43
+ private readonly sessions;
44
+ private sandboxAmbientMemoryCommitmentBytes;
45
+ constructor(config: BridgeServiceConfig, sessions?: SessionService | undefined, connections?: BridgeConnectionFactory, preflight?: DockerPreflight, sandboxRuntime?: SandboxRuntime, sandboxResourceResolver?: SandboxResourceResolver);
14
46
  connectOnce(): Promise<void>;
47
+ private registerConnection;
15
48
  run(signal?: AbortSignal): Promise<void>;
16
49
  stop(): Promise<void>;
17
50
  private handleDispatch;
51
+ private handleOffer;
52
+ private commitOfferReservation;
53
+ private handleStart;
54
+ private redeemSecretGrant;
55
+ private redeemPublishGrant;
56
+ private handleLeaseUpdate;
57
+ private sendOfferDecision;
18
58
  private parseDispatchOrReport;
19
59
  private handleCancel;
60
+ private handleReap;
61
+ private handleReadinessProbe;
20
62
  private abortActiveSessions;
63
+ private abortActiveReadinessProbes;
21
64
  private normalizeDispatch;
22
65
  private sendResult;
66
+ private sendLegacyResult;
67
+ private sendResultPayload;
23
68
  private startHeartbeat;
69
+ private heartbeatTick;
70
+ private startLeaseWatchdog;
71
+ private stopLeaseWatchdog;
72
+ private expireLeases;
73
+ private expireReservations;
24
74
  private stopHeartbeat;
75
+ private startSandboxMaintenance;
76
+ private stopSandboxMaintenance;
77
+ private runSandboxMaintenance;
78
+ private readAttemptSnapshot;
79
+ private flushCleanupReports;
25
80
  private sendHeartbeat;
26
81
  private capabilities;
82
+ private usedSandboxResources;
83
+ private activeSandboxResources;
84
+ private sandboxResourceCapacity;
27
85
  private invokeAck;
86
+ private beginTransportRecovery;
87
+ private completeTransportRecovery;
88
+ private waitForTransportRecovery;
28
89
  private waitForClose;
29
90
  private stopConnection;
30
91
  }
@@ -38,9 +99,29 @@ export declare class SignalRBridgeConnection implements BridgeConnection {
38
99
  start(): Promise<void>;
39
100
  stop(): Promise<void>;
40
101
  onClose(handler: (error?: Error) => void): void;
102
+ onReconnecting(handler: (error?: Error) => void): void;
103
+ onReconnected(handler: (connectionId?: string) => void | Promise<void>): void;
41
104
  onDispatch(handler: BridgeDispatchHandler): void;
105
+ onOffer(handler: BridgeDispatchHandler): void;
106
+ onStart(handler: BridgeDispatchHandler): void;
107
+ onLeaseUpdate(handler: (request: BridgeLeaseUpdateRequest) => Promise<void>): void;
42
108
  onCancel(handler: BridgeCancelHandler): void;
109
+ onReap(handler: (request: BridgeReapRequest) => Promise<void>): void;
110
+ onReadinessProbe(handler: (request: unknown) => Promise<void>): void;
43
111
  invoke<TResponse>(methodName: string, payload: unknown): Promise<TResponse>;
44
112
  }
45
113
  export declare function defaultBridgeServiceConfig(overrides?: Partial<BridgeServiceConfig>): BridgeServiceConfig;
46
114
  export declare function resolveBridgeRunnerHubUrl(serverUrl: string): URL;
115
+ export declare function delay(ms: number, signal?: AbortSignal): Promise<void>;
116
+ export declare function waitForPromiseOrAbort(promise: Promise<unknown>, signal?: AbortSignal): Promise<void>;
117
+ export declare function canReapManagedSandboxes(preflight: {
118
+ readonly healthy: boolean;
119
+ readonly unavailableCode?: string | null;
120
+ }): boolean;
121
+ export declare function infrastructureFailureEventType(summary: string): string | null;
122
+ export type SandboxResourceVector = DispatchSandboxResourceRequest;
123
+ export declare function canReserveSandboxResources(used: SandboxResourceVector, requested: SandboxResourceVector, capacity: SandboxResourceVector): boolean;
124
+ export declare function sandboxMemoryCommitmentCapacity(preflight: Pick<SandboxPreflightResult, "totalMemoryBytes" | "availableMemoryBytes" | "hostReserveBytes">, activeMemoryBytes: number, ambientMemoryCommitmentBytes?: number): number;
125
+ export declare function sandboxCapacityFailureMessage(used: SandboxResourceVector, requested: SandboxResourceVector, capacity: SandboxResourceVector, preflight: SandboxPreflightResult | null, config: BridgeServiceConfig): string;
126
+ export declare function resolveDynamicSandboxResources(requested: DispatchSandboxResourceRequest, serviceCount: number, networkMode: "offline" | "public_allowlist" | "open_public", baseRuntimeOverheadBytes?: number): DispatchSandboxResourceRequest;
127
+ export declare function resolveSandboxResourcesFromRepo(dispatch: RunOnceDispatchPacket, baseRuntimeOverheadBytes?: number): Promise<ResolvedSandboxResourceProfile>;