@loucompanion/forge-bridge 0.1.4-dev.bbb61d3d6127 → 0.1.4-dev.bd2cfb6b7438

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 (169) hide show
  1. package/README.md +55 -0
  2. package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
  3. package/dist/bridge/bridge-chat-provider-command.js +137 -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.base.d.ts +9 -0
  7. package/dist/bridge/bridge.service.d.ts +71 -2
  8. package/dist/bridge/bridge.service.js +292 -118
  9. package/dist/bridge/bridge.types.d.ts +11 -0
  10. package/dist/bridge/local-yield-flag.d.ts +6 -0
  11. package/dist/bridge/local-yield-flag.js +34 -0
  12. package/dist/bridge/runner-host-capabilities.d.ts +3 -0
  13. package/dist/bridge/runner-host-capabilities.js +13 -0
  14. package/dist/cleanup/cleanup.service.d.ts +9 -0
  15. package/dist/cleanup/cleanup.service.js +72 -109
  16. package/dist/cleanup/cleanup.types.d.ts +4 -0
  17. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  18. package/dist/cleanup/forge-owned-paths.js +53 -0
  19. package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
  20. package/dist/cleanup/host-runtime-ledger.js +109 -0
  21. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  22. package/dist/cleanup/managed-branch-sweep.js +111 -0
  23. package/dist/cli/cli.help.js +18 -0
  24. package/dist/cli/cli.service.d.ts +16 -0
  25. package/dist/cli/cli.service.js +140 -16
  26. package/dist/cli/local-config.d.ts +4 -0
  27. package/dist/cli/local-config.js +26 -4
  28. package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
  29. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  30. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  31. package/dist/runtime/docker-engine-probe.js +7 -0
  32. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  33. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  34. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  35. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  36. package/dist/runtime/host-facts.d.ts +2 -1
  37. package/dist/runtime/host-load-admission.d.ts +18 -3
  38. package/dist/runtime/host-load-admission.js +19 -4
  39. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  40. package/dist/runtime/host-load-child-environment.js +76 -0
  41. package/dist/runtime/host-load-forge-cgroups.d.ts +41 -0
  42. package/dist/runtime/host-load-forge-cgroups.js +93 -4
  43. package/dist/runtime/host-load-governor-config.d.ts +19 -1
  44. package/dist/runtime/host-load-governor-config.js +37 -0
  45. package/dist/runtime/host-load-governor.d.ts +72 -11
  46. package/dist/runtime/host-load-governor.js +284 -67
  47. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  48. package/dist/runtime/host-load-runtime-settings.js +78 -0
  49. package/dist/runtime/host-load-sampler.d.ts +39 -4
  50. package/dist/runtime/host-load-sampler.js +83 -9
  51. package/dist/runtime/host-load-step-class.d.ts +37 -0
  52. package/dist/runtime/host-load-step-class.js +117 -2
  53. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  54. package/dist/runtime/host-load-step-reaper.js +95 -0
  55. package/dist/runtime/host-load-step-run.d.ts +73 -0
  56. package/dist/runtime/host-load-step-run.js +102 -0
  57. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  58. package/dist/runtime/host-load-test-slot.js +81 -0
  59. package/dist/runtime/host-load-token-ledger.d.ts +82 -17
  60. package/dist/runtime/host-load-token-ledger.js +187 -79
  61. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  62. package/dist/runtime/host-load-windows-cpu.js +85 -0
  63. package/dist/runtime/host-runtime-lease.d.ts +62 -3
  64. package/dist/runtime/host-runtime-lease.js +258 -13
  65. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  66. package/dist/runtime/host-runtime-promotion.js +36 -0
  67. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  68. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  69. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  70. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  71. package/dist/runtime/runner-settings.d.ts +100 -0
  72. package/dist/runtime/runner-settings.js +214 -0
  73. package/dist/sandbox/host-capacity-broker.d.ts +113 -0
  74. package/dist/sandbox/host-capacity-broker.js +334 -0
  75. package/dist/sandbox/runtime.d.ts +10 -1
  76. package/dist/sandbox/runtime.js +45 -2
  77. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  78. package/dist/sandbox/sandbox-cgroups.js +42 -0
  79. package/dist/session/architect-waits.d.ts +2 -0
  80. package/dist/session/architect-waits.js +138 -0
  81. package/dist/session/managed-attempt-tools.d.ts +2 -7
  82. package/dist/session/managed-attempt-tools.js +200 -92
  83. package/dist/session/managed-command-host-load.d.ts +47 -0
  84. package/dist/session/managed-command-host-load.js +83 -0
  85. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  86. package/dist/session/mcp-argument-coercion.js +121 -0
  87. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  88. package/dist/session/phase-completion.artifacts.js +96 -26
  89. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  90. package/dist/session/phase-completion.command-validation.js +77 -0
  91. package/dist/session/phase-completion.d.ts +4 -0
  92. package/dist/session/phase-completion.helpers.js +13 -12
  93. package/dist/session/phase-completion.js +4 -0
  94. package/dist/session/phase-completion.prompts.js +6 -1
  95. package/dist/session/phase-completion.runtime.d.ts +5 -3
  96. package/dist/session/phase-completion.runtime.js +50 -20
  97. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  98. package/dist/session/phase-completion.schema-parts.js +188 -0
  99. package/dist/session/phase-completion.schemas.d.ts +3 -3
  100. package/dist/session/phase-completion.schemas.js +208 -231
  101. package/dist/session/phase-completion.validation.d.ts +2 -3
  102. package/dist/session/phase-completion.validation.js +49 -93
  103. package/dist/session/pre-publication-host-load.js +31 -16
  104. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  105. package/dist/session/pre-publication-native-postgres.js +111 -0
  106. package/dist/session/pre-publication-pass.d.ts +61 -0
  107. package/dist/session/pre-publication-pass.js +148 -0
  108. package/dist/session/pre-publication-process.d.ts +3 -0
  109. package/dist/session/pre-publication-process.js +23 -11
  110. package/dist/session/pre-publication-step-execution.d.ts +2 -1
  111. package/dist/session/pre-publication-step-execution.js +6 -5
  112. package/dist/session/pre-publication-validation.d.ts +30 -14
  113. package/dist/session/pre-publication-validation.js +211 -134
  114. package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
  115. package/dist/session/provider-cli/claude-background-work.js +180 -0
  116. package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
  117. package/dist/session/provider-cli/pre-publication-repair.js +243 -0
  118. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  119. package/dist/session/provider-cli/provider-cli.child-environment.js +73 -0
  120. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  121. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  122. package/dist/session/provider-cli/provider-cli.process.d.ts +13 -22
  123. package/dist/session/provider-cli/provider-cli.process.js +38 -339
  124. package/dist/session/provider-cli/provider-cli.prompts.d.ts +2 -0
  125. package/dist/session/provider-cli/provider-cli.prompts.js +50 -10
  126. package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
  127. package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
  128. package/dist/session/provider-cli/provider-cli.service.js +93 -162
  129. package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
  130. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  131. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  132. package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
  133. package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
  134. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  135. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  136. package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
  137. package/dist/session/provider-cli/provider-output-state.js +6 -0
  138. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  139. package/dist/session/qa-sidecar-validation.js +28 -0
  140. package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
  141. package/dist/session/sandbox-host-capacity-gate.js +238 -0
  142. package/dist/session/session-redaction.js +31 -181
  143. package/dist/session/session.base.d.ts +6 -1
  144. package/dist/session/session.service.d.ts +7 -2
  145. package/dist/session/session.service.js +115 -5
  146. package/dist/session/session.types.js +4 -4
  147. package/dist/session/sidecar-json-shape.d.ts +31 -0
  148. package/dist/session/sidecar-json-shape.js +217 -0
  149. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  150. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  151. package/dist/shared/process/host-process-supervisor.d.ts +1 -0
  152. package/dist/shared/process/host-process-supervisor.js +1 -1
  153. package/dist/shared/process/process-tree.d.ts +52 -0
  154. package/dist/shared/process/process-tree.js +144 -0
  155. package/dist/shared/process/process.d.ts +67 -0
  156. package/dist/shared/process/process.js +213 -11
  157. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  158. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  159. package/dist/shared/process/windows-launch.d.ts +18 -0
  160. package/dist/shared/process/windows-launch.js +68 -0
  161. package/dist/shared/provider-capabilities.js +5 -6
  162. package/dist/version.d.ts +1 -1
  163. package/dist/version.js +1 -1
  164. package/dist/worktree/dependency-warmer.d.ts +25 -0
  165. package/dist/worktree/dependency-warmer.js +46 -10
  166. package/dist/worktree/worktree.service.d.ts +10 -1
  167. package/dist/worktree/worktree.service.js +42 -2
  168. package/dist/worktree/worktree.types.d.ts +7 -0
  169. package/package.json +2 -2
package/README.md CHANGED
@@ -23,6 +23,16 @@ forge-bridge status
23
23
  forge-bridge connect --server <forge-url> --runner-id <runner-id> --device-token <device-token>
24
24
  ```
25
25
 
26
+ To pair, open **Settings → Runners → Connect a bridge** in Forge and run the command it shows:
27
+
28
+ ```bash
29
+ forge-bridge pair <code> --server <forge-url>
30
+ ```
31
+
32
+ The runner name, provider CLIs and repo folder chosen in that dialog come back with the claim
33
+ and are saved to `bridge.json`; `--repo-root` and `--cli-provider` on the command line win over
34
+ them. `bridge.json` holds the device token, so the bridge writes it with mode `0600`.
35
+
26
36
  The bridge can also read connection settings from environment variables:
27
37
 
28
38
  - `FORGE_URL`
@@ -129,6 +139,51 @@ enters a ten-minute cooldown after an unsuccessful attempt. Remote `DOCKER_HOST`
129
139
  restarted. Operators can tune the bounded policy with `FORGE_DOCKER_RECOVERY_FAILURE_THRESHOLD`,
130
140
  `FORGE_DOCKER_RECOVERY_COOLDOWN_MS`, and `FORGE_DOCKER_RECOVERY_STARTUP_TIMEOUT_MS`.
131
141
 
142
+ ## Runner limits and yield
143
+
144
+ Forge owns each runner's limits (Settings → Runners → Limits) and pushes them to the bridge, which
145
+ applies them without a restart and without stopping admitted work: max attempts and the memory reserve
146
+ apply at the next attempt admission, the CPU budget, yield budget and max heavy steps at the next heavy
147
+ step. Host env vars only bound the server's values and are reported back to Forge: a ceiling on
148
+ capacity (`FORGE_HOST_MAX_CONCURRENT_ATTEMPTS`, `FORGE_HOST_CPU_BUDGET_PERCENT`,
149
+ `FORGE_HOST_LOAD_CPU_BUDGET_FRACTION`, `FORGE_HOST_MAX_HEAVY_STEPS`) and a floor on the reserve
150
+ (`FORGE_HOST_MEMORY_RESERVE_BYTES`). Without a server value, the env var or the bridge default applies.
151
+ The CPU budget, yield budget and heavy-step limit take effect only with `FORGE_HOST_LOAD_GOVERNOR=on`.
152
+ They gate on Linux PSI. Windows has no PSI, so a Windows bridge estimates CPU pressure from whole-host
153
+ CPU use and reports it with `pressureSource: "windows_estimate"` (decision 0021). Forge's Load column
154
+ and the budgets then work there too. Without either signal, the governor falls back to one heavy step at a time.
155
+
156
+ Two or more attempts on one host take turns at the host test slot (decision 0018): builds, test runs,
157
+ Playwright, pre-publication checks and the ASP.NET runtime build each wait for it in one host-wide queue,
158
+ foreground first, then first come, first served, across the bridge and every completion MCP server. Plain
159
+ managed commands and dependency installs never wait for it. A waiting step reports who holds the slot
160
+ (`prepublication_host_capacity_waiting`, `host_runtime_build_waiting_for_host_capacity`, or
161
+ `host_load_wait_detail` on a managed command's receipt), and its own timeout starts only once it runs.
162
+ A holder that crashes or stalls keeps the slot only until the host load ledger takes its token back (its
163
+ process tree stopped, its lease fenced, or attempt teardown). `FORGE_HOST_LOAD_TEST_SLOTS` sets how many
164
+ run at once (default 1; `0` turns the slot off).
165
+
166
+ Yield this machine to foreground work (for example while gaming) from the host itself:
167
+
168
+ ```bash
169
+ forge-bridge yield on
170
+ forge-bridge yield status
171
+ forge-bridge yield off
172
+ ```
173
+
174
+ While yielding, the bridge takes no new attempts and heavy steps of running attempts use the yield CPU
175
+ budget. Yield is on when this local flag or the runner's Yield toggle in Forge is on. The flag is stored
176
+ in `bridge.yield.json` next to `bridge.json`, and a running bridge notices it within one heartbeat.
177
+
178
+ ## Pre-publication repair
179
+
180
+ Before Forge commits and pushes an agent's work, the bridge runs the CI parity checks in
181
+ `.forge/validation/ci-parity.v1.json`. A failed check does not stop the pass: the other checks still
182
+ run, except those that need what failed (the OpenAPI export and E2E after a .NET compile failure, E2E
183
+ after a failed runtime restart). The provider thread then gets one in-place repair turn that lists
184
+ every failed check. A Work Order holds after `FORGE_PREPUBLICATION_REPAIR_TURNS` repair turns (a whole
185
+ number from 1, capped at 10; default 4) if validation still fails.
186
+
132
187
  ## Docker sandbox runners
133
188
 
134
189
  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:
@@ -0,0 +1,16 @@
1
+ import type { ProviderCliCommand, ProviderProcessRunResult } from "../session/provider-cli/provider-cli.process.js";
2
+ import { type ChatTurnDispatchPacket } from "./bridge-chat.types.js";
3
+ /** The turn-scoped handoff metadata file the bridge writes into the chat workspace. */
4
+ export declare const chatTurnMetadataFileName = "forge-chat-metadata.json";
5
+ /**
6
+ * Fails a Bridge Chat turn Forge stopped because it ended with background work still live: the
7
+ * turn never delivered its answer, so it must not be reported as one.
8
+ */
9
+ export declare function assertChatTurnFinished(result: Pick<ProviderProcessRunResult, "terminalStopReason">): void;
10
+ export interface ChatProviderCommandPlan {
11
+ readonly command: ProviderCliCommand;
12
+ readonly stdin?: string;
13
+ /** Provider environment, such as the headless background-work restrictions for Claude. */
14
+ readonly env?: Readonly<Record<string, string>>;
15
+ }
16
+ export declare function buildChatProviderCommand(packet: ChatTurnDispatchPacket, cwd: string): ChatProviderCommandPlan;
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Builds the provider command for a Bridge Chat turn: the CLI invocation for the turn's provider
3
+ * and the prompt that carries the conversation, its context references and its bounded handoff
4
+ * metadata.
5
+ */
6
+ import { claudeHeadlessEnvironment, claudeHeadlessToolArgs, providerTurnEndedWithBackgroundWorkFailure } from "../session/provider-cli/claude-background-work.js";
7
+ import { codexSandboxModeForPlatform, providerEffort } from "../session/provider-cli/provider-cli.prompts.js";
8
+ import { chatProviderKind } from "./bridge-chat.types.js";
9
+ /** The turn-scoped handoff metadata file the bridge writes into the chat workspace. */
10
+ export const chatTurnMetadataFileName = "forge-chat-metadata.json";
11
+ /**
12
+ * Fails a Bridge Chat turn Forge stopped because it ended with background work still live: the
13
+ * turn never delivered its answer, so it must not be reported as one.
14
+ */
15
+ export function assertChatTurnFinished(result) {
16
+ if (result.terminalStopReason === "turn_ended_with_background_work") {
17
+ throw providerTurnEndedWithBackgroundWorkFailure("The Bridge Chat turn did not finish.");
18
+ }
19
+ }
20
+ export function buildChatProviderCommand(packet, cwd) {
21
+ // The provider kind picks the CLI and its effort levels; an auth-path suffix such as `:bridge` does not.
22
+ const provider = chatProviderKind(packet.providerKind);
23
+ const model = packet.model.trim();
24
+ const prompt = buildChatPrompt(packet);
25
+ const resumeThreadId = packet.providerThreadId?.trim() || null;
26
+ // Levels the provider does not accept are dropped, so the CLI keeps its own default.
27
+ const effort = providerEffort(provider, packet.effort);
28
+ if (provider === "codex") {
29
+ const args = ["-s", codexSandboxModeForPlatform(process.platform, "host"), "-a", "never", "exec"];
30
+ if (resumeThreadId) {
31
+ args.push("--cd", cwd, "resume");
32
+ }
33
+ args.push("--model", model);
34
+ if (effort) {
35
+ args.push("-c", `model_reasoning_effort=${JSON.stringify(effort)}`);
36
+ }
37
+ args.push("--json");
38
+ if (!resumeThreadId) {
39
+ args.push("--cd", cwd);
40
+ }
41
+ args.push("--skip-git-repo-check");
42
+ if (resumeThreadId) {
43
+ args.push(resumeThreadId);
44
+ }
45
+ args.push("-");
46
+ return { command: { command: "codex", args }, stdin: prompt };
47
+ }
48
+ if (provider === "cursor") {
49
+ const args = ["--print", "--output-format", "stream-json", "--model", model, "--workspace", cwd];
50
+ if (resumeThreadId) {
51
+ args.push("--resume", resumeThreadId);
52
+ }
53
+ args.push("--yolo", "--approve-mcps", "--trust", prompt);
54
+ return { command: { command: "cursor-agent", args } };
55
+ }
56
+ if (provider === "claude") {
57
+ const args = ["-p", "--output-format", "stream-json", "--verbose", "--model", model];
58
+ if (effort) {
59
+ args.push("--effort", effort);
60
+ }
61
+ args.push("--permission-mode", "bypassPermissions", ...claudeHeadlessToolArgs());
62
+ if (resumeThreadId) {
63
+ args.push("--resume", resumeThreadId);
64
+ }
65
+ return { command: { command: "claude", args }, stdin: prompt, env: claudeHeadlessEnvironment };
66
+ }
67
+ return {
68
+ command: {
69
+ command: provider,
70
+ args: ["--model", model, prompt],
71
+ },
72
+ };
73
+ }
74
+ function buildChatPrompt(packet) {
75
+ const messages = packet.messages
76
+ .map((message, index) => {
77
+ const role = message.role.trim() || `message-${index + 1}`;
78
+ return `[${role}]\n${message.content}`;
79
+ })
80
+ .join("\n\n");
81
+ const contextRefs = packet.contextRefs.length === 0
82
+ ? ""
83
+ : `\n\n# Context References\n\n${packet.contextRefs.map((ref, index) => {
84
+ const title = ref.title?.trim() ? `\nTitle: ${ref.title.trim()}` : "";
85
+ const summary = ref.summary?.trim() ? `\nSummary: ${ref.summary.trim()}` : "";
86
+ return `${index + 1}. ${ref.kind}:${ref.refId}${title}${summary}`;
87
+ }).join("\n\n")}`;
88
+ const continuation = packet.providerThreadId
89
+ ? "\n\nContinue the existing provider thread identified by the bridge; do not restart the conversation context."
90
+ : "";
91
+ const boundedMetadata = buildChatBoundedMetadataPrompt(packet);
92
+ return `You are handling a Forge Bridge Chat turn.
93
+
94
+ Conversation ID: ${packet.conversationId}
95
+ Turn ID: ${packet.turnId}
96
+ Provider: ${packet.providerKind}
97
+ Model: ${packet.model}${continuation}${boundedMetadata}
98
+
99
+ # Conversation
100
+
101
+ ${messages}${contextRefs}
102
+ `;
103
+ }
104
+ function buildChatBoundedMetadataPrompt(packet) {
105
+ if (packet.attachmentHandoffs.length === 0 && packet.actionBrokerGrants.length === 0) {
106
+ return "";
107
+ }
108
+ const sections = [
109
+ `\n\n# Bounded Handoff Metadata\n\nMetadata file: ${chatTurnMetadataFileName}\n\nThe metadata file is turn-scoped and cleaned up by the bridge when the turn ends. It contains opaque handles only; attachment content, raw paths, and grant nonces are not included.`,
110
+ ];
111
+ if (packet.attachmentHandoffs.length > 0) {
112
+ sections.push(`Attachment handoffs:\n${packet.attachmentHandoffs.map((handoff, index) => [
113
+ `${index + 1}. turnId: ${handoff.turnId}`,
114
+ ` attachmentId: ${handoff.attachmentId}`,
115
+ ` tempFileToken: ${handoff.tempFileToken}`,
116
+ ` mimeType: ${handoff.mimeType}`,
117
+ ` sizeBytes: ${handoff.sizeBytes}`,
118
+ ` sha256: ${handoff.sha256}`,
119
+ ` fileNameDisplay: ${handoff.fileNameDisplay}`,
120
+ ` expiresAt: ${handoff.expiresAt}`,
121
+ ` status: ${handoff.status}`,
122
+ ].join("\n")).join("\n\n")}`);
123
+ }
124
+ if (packet.actionBrokerGrants.length > 0) {
125
+ sections.push(`Action-broker grants:\n${packet.actionBrokerGrants.map((grant, index) => [
126
+ `${index + 1}. grantId: ${grant.grantId}`,
127
+ ` turnId: ${grant.turnId}`,
128
+ ` leaseId: ${grant.leaseId}`,
129
+ ` fencingToken: ${grant.fencingToken}`,
130
+ ` allowedScopes: ${grant.allowedScopes.join(", ")}`,
131
+ ` expiresAt: ${grant.expiresAt}`,
132
+ ` redactionStatus: ${grant.redactionStatus}`,
133
+ " nonce: held by bridge",
134
+ ].join("\n")).join("\n\n")}`);
135
+ }
136
+ return sections.join("\n\n");
137
+ }
@@ -35,6 +35,11 @@ export interface ChatTurnDispatchPacket {
35
35
  readonly contextRefs: readonly ChatTurnContextRef[];
36
36
  readonly idempotencyKey: string;
37
37
  readonly providerThreadId?: string | null;
38
+ /**
39
+ * The Chat role's reasoning effort for this provider and model, or null for the provider default.
40
+ * Older servers omit it. The command builder drops levels the provider does not accept.
41
+ */
42
+ readonly effort?: string | null;
38
43
  readonly protocolVersion: typeof bridgeChatProtocolVersion;
39
44
  readonly requestedCapabilities: readonly BridgeChatRequestedCapability[];
40
45
  readonly attachmentHandoffs: readonly ChatAttachmentHandoffHandle[];
@@ -107,5 +112,10 @@ export interface ChatTurnCancelPacket {
107
112
  export declare function unavailableBridgeChatCapability(protocolVersion?: string, unavailableCode?: string | null, unavailableReason?: string | null): BridgeChatCapability;
108
113
  export declare function normalizeBridgeChatCapability(value: BridgeChatCapability | null | undefined): BridgeChatCapability;
109
114
  export declare function parseChatTurnDispatchPacket(value: unknown, capability?: BridgeChatCapability): ChatTurnDispatchPacket;
115
+ /**
116
+ * The provider kind of a saved provider selection: `codex:bridge` and `codex` are both `codex`.
117
+ * Forge stores the Chat role's provider with its auth-path suffix and may send it as is.
118
+ */
119
+ export declare function chatProviderKind(provider: string): string;
110
120
  export declare function isTerminalChatTurnCallbackKind(kind: ChatTurnCallbackKind): boolean;
111
121
  export declare function assertBridgeChatCallbackPayload(value: unknown, label?: string): void;
@@ -87,18 +87,26 @@ export function parseChatTurnDispatchPacket(value, capability = unavailableBridg
87
87
  leaseId,
88
88
  fencingToken,
89
89
  runnerInstanceId: requiredUuid(packet, "runnerInstanceId"),
90
- providerKind: requiredString(packet, "providerKind").trim().toLowerCase(),
90
+ providerKind: requiredProviderKind(packet),
91
91
  model: requiredString(packet, "model").trim(),
92
92
  messages,
93
93
  contextRefs,
94
94
  idempotencyKey: requiredString(packet, "idempotencyKey").trim(),
95
95
  providerThreadId: optionalString(packet, "providerThreadId", bridgeChatMaxProviderThreadIdChars),
96
+ effort: optionalString(packet, "effort")?.toLowerCase() ?? null,
96
97
  protocolVersion: bridgeChatProtocolVersion,
97
98
  requestedCapabilities,
98
99
  attachmentHandoffs,
99
100
  actionBrokerGrants,
100
101
  };
101
102
  }
103
+ /**
104
+ * The provider kind of a saved provider selection: `codex:bridge` and `codex` are both `codex`.
105
+ * Forge stores the Chat role's provider with its auth-path suffix and may send it as is.
106
+ */
107
+ export function chatProviderKind(provider) {
108
+ return (provider.split(":", 1)[0] ?? "").trim().toLowerCase();
109
+ }
102
110
  export function isTerminalChatTurnCallbackKind(kind) {
103
111
  return kind === "output_completed" || kind === "failed" || kind === "cancelled" || kind === "expired";
104
112
  }
@@ -304,6 +312,13 @@ function requiredUuid(source, key) {
304
312
  }
305
313
  return value;
306
314
  }
315
+ function requiredProviderKind(source) {
316
+ const kind = chatProviderKind(requiredString(source, "providerKind"));
317
+ if (kind.length === 0) {
318
+ throw new Error("providerKind must be a non-empty string.");
319
+ }
320
+ return kind;
321
+ }
307
322
  function requiredString(source, key) {
308
323
  const value = source[key];
309
324
  if (typeof value !== "string" || value.trim().length === 0) {
@@ -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,11 +1,12 @@
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
5
  import { type DispatchSandboxResourceRequest, type RunOnceDispatchPacket, type RunOnceResultPacket } from "../session/session.types.js";
5
6
  import { DockerPreflight } from "../sandbox/preflight.js";
6
7
  import type { SandboxPreflightResult } from "../sandbox/sandbox.types.js";
7
8
  import { type SandboxRuntime } from "../sandbox/runtime.js";
8
- import type { BridgeConnection, BridgeConnectionFactory, BridgeService } from "./bridge.base.js";
9
+ import type { BridgeConnection, BridgeConnectionFactory, BridgeRevokedNotice, BridgeService } from "./bridge.base.js";
9
10
  import { type RunnerHostCapabilityProbe } from "./runner-host-capabilities.js";
10
11
  import { type HostLoadSource } from "../runtime/host-load-sampler.js";
11
12
  import type { BridgeCancelHandler, BridgeChatTurnHandler, BridgeDispatchHandler, BridgeLeaseUpdateRequest, BridgeReapRequest, BridgeServiceConfig } from "./bridge.types.js";
@@ -43,6 +44,7 @@ export declare class ForgeBridgeService implements BridgeService {
43
44
  private transportRecovery;
44
45
  private transportRecoveryGeneration;
45
46
  private stopped;
47
+ private revokedReason;
46
48
  private readonly activeSessions;
47
49
  private readonly reservations;
48
50
  private readonly activeReadinessProbes;
@@ -61,6 +63,14 @@ export declare class ForgeBridgeService implements BridgeService {
61
63
  private readonly enforceHostDatabaseCapabilityBoundary;
62
64
  private hostCapabilities;
63
65
  private dockerAvailable;
66
+ private appliedSettingsDocument;
67
+ private localYield;
68
+ private effectiveSettings;
69
+ private settingsReport;
70
+ /** Applies run one at a time; offers wait for every apply queued before them. */
71
+ private settingsTail;
72
+ private pendingYieldOn;
73
+ private settingsStarted;
64
74
  private hostRequirementFacts;
65
75
  private readonly recoveredHostAttempts;
66
76
  private hostCapabilitiesDetected;
@@ -70,6 +80,56 @@ export declare class ForgeBridgeService implements BridgeService {
70
80
  private recoveredHostAttemptsForHello;
71
81
  private registerConnection;
72
82
  run(signal?: AbortSignal): Promise<void>;
83
+ /** The reason Forge gave when it removed this runner, or null while it is paired. */
84
+ get revoked(): string | null;
85
+ /**
86
+ * Decision 0014 §3 "Remove": Forge removed this runner. Stop for good instead of
87
+ * reconnecting; its attempts were already settled on the server, so local work is
88
+ * aborted rather than reported.
89
+ */
90
+ private handleRevoked;
91
+ /** The effective settings and how they were derived, as last reported (decision 0014). */
92
+ get runnerSettings(): RunnerSettingsReport;
93
+ private runnerHostDefaults;
94
+ /**
95
+ * Once per bridge process: drop governor overrides an earlier process left on
96
+ * the state root, then put today's effective settings (env bounds and the local
97
+ * yield flag, no server document yet) in force.
98
+ */
99
+ private startSettings;
100
+ /**
101
+ * Decision 0014 `ApplySettings`. Applies only a document newer than the one
102
+ * applied, one at a time, then acknowledges it with `SettingsApplied`. A replay of
103
+ * the applied version is acknowledged again without applying it; an older one is
104
+ * ignored.
105
+ */
106
+ private handleApplySettings;
107
+ /**
108
+ * Polls the local `forge-bridge yield` flag (every heartbeat and before each
109
+ * offer decision). A change is applied at once and reported again under the
110
+ * same settings version.
111
+ */
112
+ /** Yielding now, or about to: a received yield-on that is still being applied counts. */
113
+ private yieldingOrQueued;
114
+ private refreshLocalYield;
115
+ /**
116
+ * A setting the host couldn't put in force holds placement on the server, so
117
+ * every heartbeat tries the applied document again until it takes.
118
+ */
119
+ private retryFailedSettings;
120
+ private readLocalYield;
121
+ private enqueueSettings;
122
+ private applySettings;
123
+ /**
124
+ * Max attempts and the memory reserve go to host attempt admission; the governor
125
+ * budget (the yield budget while yielding) and the heavy-step limit go to the
126
+ * shared settings file every governor on the state root reads at admission.
127
+ * Neither touches admitted work. Returns the keys the host could not put in
128
+ * force (`apply_failed`); their previous values stay in force.
129
+ */
130
+ private putSettingsInForce;
131
+ /** A failed acknowledgement is not retried here: the next heartbeat carries the same report. */
132
+ private sendSettingsApplied;
73
133
  stop(): Promise<void>;
74
134
  private handleChatTurn;
75
135
  private createChatTurnWorkspace;
@@ -146,6 +206,13 @@ export declare class ForgeBridgeService implements BridgeService {
146
206
  private waitForClose;
147
207
  private stopConnection;
148
208
  }
209
+ /** The `run` command's exit code after Forge removed the runner. */
210
+ export declare const bridgeRevokedExitCode = 3;
211
+ export declare const bridgeRevokedMessage = "This bridge was removed from Forge. Pair it again with forge-bridge pair.";
212
+ /** Thrown by `run` after Forge removed the runner, so the CLI exits instead of reconnecting. */
213
+ export declare class BridgeRevokedError extends Error {
214
+ constructor(message?: string);
215
+ }
149
216
  export declare class SignalRBridgeConnectionFactory implements BridgeConnectionFactory {
150
217
  create(config: BridgeServiceConfig): BridgeConnection;
151
218
  }
@@ -153,6 +220,8 @@ export declare class SignalRBridgeConnection implements BridgeConnection {
153
220
  private readonly config;
154
221
  private readonly connection;
155
222
  constructor(config: BridgeServiceConfig);
223
+ onApplySettings(handler: (document: unknown) => void | Promise<void>): void;
224
+ onRevoked(handler: (notice: BridgeRevokedNotice) => void): void;
156
225
  start(): Promise<void>;
157
226
  stop(): Promise<void>;
158
227
  onClose(handler: (error?: Error) => void): void;