@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 0.1.4-dev.03584818ede5

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 (275) hide show
  1. package/README.md +146 -5
  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 +121 -0
  5. package/dist/bridge/bridge-chat.types.js +416 -0
  6. package/dist/bridge/bridge.base.d.ts +13 -1
  7. package/dist/bridge/bridge.service.d.ts +155 -4
  8. package/dist/bridge/bridge.service.js +1805 -155
  9. package/dist/bridge/bridge.types.d.ts +68 -1
  10. package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
  11. package/dist/bridge/dispatch-result-outbox.js +87 -0
  12. package/dist/bridge/dispatch-result-worker.d.ts +2 -0
  13. package/dist/bridge/dispatch-result-worker.js +122 -0
  14. package/dist/bridge/internals.d.ts +2 -0
  15. package/dist/bridge/internals.js +1 -0
  16. package/dist/bridge/local-yield-flag.d.ts +6 -0
  17. package/dist/bridge/local-yield-flag.js +34 -0
  18. package/dist/bridge/readiness-result-outbox.d.ts +21 -0
  19. package/dist/bridge/readiness-result-outbox.js +54 -0
  20. package/dist/bridge/readiness-result-worker.d.ts +2 -0
  21. package/dist/bridge/readiness-result-worker.js +121 -0
  22. package/dist/bridge/runner-host-capabilities.d.ts +20 -0
  23. package/dist/bridge/runner-host-capabilities.js +110 -0
  24. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  25. package/dist/bridge/test-postgres-capability.js +120 -0
  26. package/dist/cleanup/cleanup.service.d.ts +10 -0
  27. package/dist/cleanup/cleanup.service.js +128 -104
  28. package/dist/cleanup/cleanup.types.d.ts +4 -0
  29. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  30. package/dist/cleanup/forge-owned-paths.js +53 -0
  31. package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
  32. package/dist/cleanup/host-runtime-ledger.js +109 -0
  33. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  34. package/dist/cleanup/managed-branch-sweep.js +111 -0
  35. package/dist/cli/cli.help.js +22 -4
  36. package/dist/cli/cli.service.d.ts +30 -6
  37. package/dist/cli/cli.service.js +216 -31
  38. package/dist/cli/local-config.d.ts +5 -0
  39. package/dist/cli/local-config.js +30 -4
  40. package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
  41. package/dist/runtime/aspnet-runtime-prebuild.js +429 -0
  42. package/dist/runtime/attempt-database-broker.d.ts +89 -0
  43. package/dist/runtime/attempt-database-broker.js +390 -0
  44. package/dist/runtime/attempt-node-runtime-launcher.d.ts +2 -1
  45. package/dist/runtime/attempt-node-runtime-launcher.js +57 -18
  46. package/dist/runtime/attempt-path-operation.d.ts +21 -0
  47. package/dist/runtime/attempt-path-operation.js +94 -0
  48. package/dist/runtime/attempt-private-directory.d.ts +6 -0
  49. package/dist/runtime/attempt-private-directory.js +54 -0
  50. package/dist/runtime/attempt-process-supervisor.d.ts +35 -0
  51. package/dist/runtime/attempt-process-supervisor.js +144 -23
  52. package/dist/runtime/canonical-source-file.d.ts +3 -0
  53. package/dist/runtime/canonical-source-file.js +54 -0
  54. package/dist/runtime/docker-engine-probe.d.ts +90 -0
  55. package/dist/runtime/docker-engine-probe.js +333 -0
  56. package/dist/runtime/generated-output-reset.d.ts +10 -0
  57. package/dist/runtime/generated-output-reset.js +62 -8
  58. package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
  59. package/dist/runtime/host-database-capability-boundary.js +63 -0
  60. package/dist/runtime/host-diagnostics.d.ts +11 -0
  61. package/dist/runtime/host-diagnostics.js +192 -0
  62. package/dist/runtime/host-execution-root.d.ts +4 -0
  63. package/dist/runtime/host-execution-root.js +39 -0
  64. package/dist/runtime/host-facts.d.ts +36 -0
  65. package/dist/runtime/host-facts.js +95 -0
  66. package/dist/runtime/host-listener-inspector.d.ts +8 -1
  67. package/dist/runtime/host-listener-inspector.js +121 -60
  68. package/dist/runtime/host-load-admission.d.ts +67 -0
  69. package/dist/runtime/host-load-admission.js +99 -0
  70. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  71. package/dist/runtime/host-load-child-environment.js +76 -0
  72. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  73. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  74. package/dist/runtime/host-load-governor-config.d.ts +52 -0
  75. package/dist/runtime/host-load-governor-config.js +83 -0
  76. package/dist/runtime/host-load-governor.d.ts +184 -0
  77. package/dist/runtime/host-load-governor.js +632 -0
  78. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  79. package/dist/runtime/host-load-ledger-lock.js +185 -0
  80. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  81. package/dist/runtime/host-load-runtime-settings.js +78 -0
  82. package/dist/runtime/host-load-sampler.d.ts +149 -0
  83. package/dist/runtime/host-load-sampler.js +291 -0
  84. package/dist/runtime/host-load-step-class.d.ts +70 -0
  85. package/dist/runtime/host-load-step-class.js +161 -0
  86. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  87. package/dist/runtime/host-load-step-reaper.js +95 -0
  88. package/dist/runtime/host-load-step-run.d.ts +73 -0
  89. package/dist/runtime/host-load-step-run.js +102 -0
  90. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  91. package/dist/runtime/host-load-test-slot.js +81 -0
  92. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  93. package/dist/runtime/host-load-token-ledger.js +453 -0
  94. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  95. package/dist/runtime/host-load-windows-cpu.js +85 -0
  96. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  97. package/dist/runtime/host-pressure-stall.js +168 -0
  98. package/dist/runtime/host-runtime-contract.d.ts +16 -1
  99. package/dist/runtime/host-runtime-contract.js +174 -56
  100. package/dist/runtime/host-runtime-lease.d.ts +163 -9
  101. package/dist/runtime/host-runtime-lease.js +1464 -121
  102. package/dist/runtime/host-runtime-promotion.d.ts +35 -3
  103. package/dist/runtime/host-runtime-promotion.js +107 -12
  104. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  105. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  106. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  107. package/dist/runtime/host-runtime-requirements.js +117 -0
  108. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  109. package/dist/runtime/managed-command-teardown.js +607 -0
  110. package/dist/runtime/memory-capacity.d.ts +70 -0
  111. package/dist/runtime/memory-capacity.js +123 -0
  112. package/dist/runtime/native-test-postgres-fallback.d.ts +25 -0
  113. package/dist/runtime/native-test-postgres-fallback.js +91 -0
  114. package/dist/runtime/node-host-runtime-adapter.d.ts +3 -0
  115. package/dist/runtime/node-host-runtime-adapter.js +29 -11
  116. package/dist/runtime/pinned-directory-process.d.ts +9 -0
  117. package/dist/runtime/pinned-directory-process.js +61 -0
  118. package/dist/runtime/pinned-source-directory.d.ts +17 -0
  119. package/dist/runtime/pinned-source-directory.js +94 -0
  120. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  121. package/dist/runtime/playwright-browser-cache.js +227 -0
  122. package/dist/runtime/playwright-host-runtime-adapter.d.ts +19 -0
  123. package/dist/runtime/playwright-host-runtime-adapter.js +113 -59
  124. package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
  125. package/dist/runtime/prepared-runtime-identity.js +218 -0
  126. package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
  127. package/dist/runtime/prepared-runtime-readiness.js +285 -0
  128. package/dist/runtime/runner-settings.d.ts +100 -0
  129. package/dist/runtime/runner-settings.js +214 -0
  130. package/dist/runtime/runtime-isolation-lease.js +4 -1
  131. package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
  132. package/dist/runtime/workspace-resource-estimator.js +174 -0
  133. package/dist/sandbox/host-capacity-broker.d.ts +113 -0
  134. package/dist/sandbox/host-capacity-broker.js +334 -0
  135. package/dist/sandbox/preflight.d.ts +31 -1
  136. package/dist/sandbox/preflight.js +237 -51
  137. package/dist/sandbox/repository-lock.d.ts +2 -1
  138. package/dist/sandbox/repository-lock.js +19 -9
  139. package/dist/sandbox/runtime.d.ts +16 -2
  140. package/dist/sandbox/runtime.js +182 -109
  141. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  142. package/dist/sandbox/sandbox-cgroups.js +42 -0
  143. package/dist/sandbox/sandbox.types.d.ts +7 -0
  144. package/dist/sandbox/workspace.service.js +2 -0
  145. package/dist/session/architect-waits.d.ts +2 -0
  146. package/dist/session/architect-waits.js +138 -0
  147. package/dist/session/managed-attempt-tools.d.ts +44 -1
  148. package/dist/session/managed-attempt-tools.js +816 -46
  149. package/dist/session/managed-build-coordinator.d.ts +5 -0
  150. package/dist/session/managed-build-coordinator.js +109 -0
  151. package/dist/session/managed-build-receipt.d.ts +21 -0
  152. package/dist/session/managed-build-receipt.js +337 -0
  153. package/dist/session/managed-command-host-load.d.ts +47 -0
  154. package/dist/session/managed-command-host-load.js +83 -0
  155. package/dist/session/managed-verification-timeouts.d.ts +8 -0
  156. package/dist/session/managed-verification-timeouts.js +17 -0
  157. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  158. package/dist/session/mcp-argument-coercion.js +121 -0
  159. package/dist/session/phase-completion.artifacts.d.ts +24 -0
  160. package/dist/session/phase-completion.artifacts.js +319 -44
  161. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  162. package/dist/session/phase-completion.command-validation.js +77 -0
  163. package/dist/session/phase-completion.d.ts +15 -1
  164. package/dist/session/phase-completion.helpers.d.ts +5 -0
  165. package/dist/session/phase-completion.helpers.js +43 -19
  166. package/dist/session/phase-completion.js +18 -3
  167. package/dist/session/phase-completion.prompts.js +22 -18
  168. package/dist/session/phase-completion.runtime.d.ts +6 -2
  169. package/dist/session/phase-completion.runtime.js +191 -47
  170. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  171. package/dist/session/phase-completion.schema-parts.js +188 -0
  172. package/dist/session/phase-completion.schemas.d.ts +3 -3
  173. package/dist/session/phase-completion.schemas.js +250 -226
  174. package/dist/session/phase-completion.validation.d.ts +3 -3
  175. package/dist/session/phase-completion.validation.js +135 -89
  176. package/dist/session/pre-publication-host-load.d.ts +27 -0
  177. package/dist/session/pre-publication-host-load.js +111 -0
  178. package/dist/session/pre-publication-pass.d.ts +61 -0
  179. package/dist/session/pre-publication-pass.js +148 -0
  180. package/dist/session/pre-publication-process.d.ts +23 -0
  181. package/dist/session/pre-publication-process.js +109 -0
  182. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  183. package/dist/session/pre-publication-skipped-tests.js +109 -0
  184. package/dist/session/pre-publication-step-execution.d.ts +11 -0
  185. package/dist/session/pre-publication-step-execution.js +49 -0
  186. package/dist/session/pre-publication-validation.d.ts +87 -0
  187. package/dist/session/pre-publication-validation.js +668 -0
  188. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
  189. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
  190. package/dist/session/provider-cli/ci-repair-readiness.d.ts +8 -0
  191. package/dist/session/provider-cli/ci-repair-readiness.js +23 -3
  192. package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
  193. package/dist/session/provider-cli/claude-background-work.js +180 -0
  194. package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
  195. package/dist/session/provider-cli/pre-publication-repair.js +243 -0
  196. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +6 -3
  197. package/dist/session/provider-cli/provider-cli.artifacts.js +62 -22
  198. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  199. package/dist/session/provider-cli/provider-cli.child-environment.js +73 -0
  200. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  201. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  202. package/dist/session/provider-cli/provider-cli.deterministic.js +34 -2
  203. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  204. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  205. package/dist/session/provider-cli/provider-cli.process.d.ts +92 -14
  206. package/dist/session/provider-cli/provider-cli.process.js +583 -210
  207. package/dist/session/provider-cli/provider-cli.prompts.d.ts +12 -0
  208. package/dist/session/provider-cli/provider-cli.prompts.js +200 -25
  209. package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
  210. package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
  211. package/dist/session/provider-cli/provider-cli.runtime.d.ts +14 -1
  212. package/dist/session/provider-cli/provider-cli.runtime.js +61 -3
  213. package/dist/session/provider-cli/provider-cli.service.d.ts +33 -5
  214. package/dist/session/provider-cli/provider-cli.service.js +819 -84
  215. package/dist/session/provider-cli/provider-cli.types.d.ts +32 -0
  216. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  217. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  218. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  219. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  220. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  221. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  222. package/dist/session/provider-cli/provider-output-state.d.ts +18 -0
  223. package/dist/session/provider-cli/provider-output-state.js +376 -17
  224. package/dist/session/provider-cli/provider-usage.d.ts +9 -1
  225. package/dist/session/provider-cli/provider-usage.js +28 -5
  226. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  227. package/dist/session/publishable-worktree-changes.js +193 -0
  228. package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
  229. package/dist/session/sandbox-host-capacity-gate.js +238 -0
  230. package/dist/session/session-redaction.js +434 -9
  231. package/dist/session/session.base.d.ts +9 -1
  232. package/dist/session/session.service.d.ts +9 -2
  233. package/dist/session/session.service.js +264 -27
  234. package/dist/session/session.types.d.ts +150 -2
  235. package/dist/session/session.types.js +599 -7
  236. package/dist/session/unreferenced-exports.d.ts +12 -0
  237. package/dist/session/unreferenced-exports.js +59 -0
  238. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  239. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  240. package/dist/shared/format/format-bytes.d.ts +1 -0
  241. package/dist/shared/format/format-bytes.js +9 -0
  242. package/dist/shared/git/git.js +2 -1
  243. package/dist/shared/path/path.d.ts +1 -0
  244. package/dist/shared/path/path.js +18 -0
  245. package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
  246. package/dist/shared/process/dotnet-toolchain.js +307 -0
  247. package/dist/shared/process/host-process-recovery.js +3 -2
  248. package/dist/shared/process/host-process-supervisor.d.ts +3 -0
  249. package/dist/shared/process/host-process-supervisor.js +61 -12
  250. package/dist/shared/process/process-tree.d.ts +52 -0
  251. package/dist/shared/process/process-tree.js +144 -0
  252. package/dist/shared/process/process.d.ts +69 -0
  253. package/dist/shared/process/process.js +223 -16
  254. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  255. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  256. package/dist/shared/process/windows-launch.d.ts +18 -0
  257. package/dist/shared/process/windows-launch.js +68 -0
  258. package/dist/shared/provider-capabilities.d.ts +3 -0
  259. package/dist/shared/provider-capabilities.js +84 -0
  260. package/dist/shared/redaction/redaction.d.ts +1 -0
  261. package/dist/shared/redaction/redaction.js +39 -3
  262. package/dist/shared/time/monotonic.d.ts +1 -0
  263. package/dist/shared/time/monotonic.js +8 -0
  264. package/dist/version.d.ts +1 -1
  265. package/dist/version.js +1 -1
  266. package/dist/worktree/dependency-warmer.d.ts +66 -9
  267. package/dist/worktree/dependency-warmer.js +609 -24
  268. package/dist/worktree/index.d.ts +1 -1
  269. package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
  270. package/dist/worktree/story-qa-reference-hydrator.js +253 -0
  271. package/dist/worktree/worktree.service.d.ts +17 -1
  272. package/dist/worktree/worktree.service.js +293 -21
  273. package/dist/worktree/worktree.types.d.ts +14 -1
  274. package/package.json +8 -6
  275. package/runtime/windows-job-supervisor.ps1 +380 -14
@@ -6,12 +6,13 @@ import { createInterface } from "node:readline/promises";
6
6
  import { promisify } from "node:util";
7
7
  import { resolveCursorAgentDirectLaunch } from "../shared/cursor-agent/cursor-agent.launch.js";
8
8
  import { buildWindowsCmdLaunch } from "../shared/process/windows-launch.js";
9
+ import { configureDotNetToolchain } from "../shared/process/dotnet-toolchain.js";
9
10
  import { supportsDraftImageAttachmentsFor } from "../shared/provider-capabilities.js";
10
11
  import { redactText } from "../shared/redaction/redaction.js";
11
- import { defaultBridgeServiceConfig, ForgeBridgeService } from "../bridge/bridge.service.js";
12
+ import { BridgeRevokedError, bridgeRevokedExitCode, defaultBridgeServiceConfig, ForgeBridgeService, } from "../bridge/bridge.service.js";
12
13
  import { forgeBridgeVersion } from "../version.js";
13
14
  import { ManagedWorktreeCleanupService } from "../cleanup/cleanup.service.js";
14
- import { addRepoMapping, applyLocalConfigDefaults, providerStatusesFor, readLocalConfigSync, removeRepoMapping, resolveLocalConfigPath, setSandboxPolicy, setServerUrl, writeLocalConfig } from "./local-config.js";
15
+ import { addRepoMapping, applyLocalConfigDefaults, providerStatusesFor, readLocalConfigSync, removeRepoMapping, resolveLocalConfigPath, resolveLocalYieldFlagPath, setSandboxPolicy, setServerUrl, writeLocalConfig } from "./local-config.js";
15
16
  import { BridgeSessionService } from "../session/session.service.js";
16
17
  import { redactRunnerDispatchEvent, redactRunOnceResultPacket } from "../session/session-redaction.js";
17
18
  import { validateDockerfilePolicy, validateSandboxContract } from "../sandbox/contract.js";
@@ -19,8 +20,9 @@ import { DockerPreflight } from "../sandbox/preflight.js";
19
20
  import { DockerSandboxRuntime } from "../sandbox/runtime.js";
20
21
  import { DockerSandboxSmoke } from "../sandbox/smoke.js";
21
22
  import { parseCompletionMcpArgs, runCompletionMcpServer } from "../session/phase-completion.js";
22
- import { failureResult, parseRunOnceDispatchPacket } from "../session/session.types.js";
23
+ import { failureFactsFromError, failureResult, parseRunOnceDispatchPacket } from "../session/session.types.js";
23
24
  import { commandHelpText, helpText } from "./cli.help.js";
25
+ import { readLocalYieldFlag, writeLocalYieldFlag } from "../bridge/local-yield-flag.js";
24
26
  const apiKeySecretGrantEnv = "FORGE_API_KEY_SECRET_GRANT";
25
27
  const execFileAsync = promisify(execFile);
26
28
  export class ForgeBridgeCliService {
@@ -28,11 +30,15 @@ export class ForgeBridgeCliService {
28
30
  bridgeFactory;
29
31
  pairRunner;
30
32
  cleanupFactory;
31
- constructor(sessions = new BridgeSessionService(), bridgeFactory = (config) => new ForgeBridgeService(config), pairRunner = claimBridgeRunner, cleanupFactory = stateRoot => new ManagedWorktreeCleanupService(stateRoot)) {
33
+ dotNetToolchainConfigurator;
34
+ constructor(
35
+ // In a Docker sandbox the default chain's validator asks the host bridge for host load tokens (decision 0013).
36
+ sessions = new BridgeSessionService(), bridgeFactory = (config) => new ForgeBridgeService(config), pairRunner = claimBridgeRunner, cleanupFactory = stateRoot => new ManagedWorktreeCleanupService(stateRoot), dotNetToolchainConfigurator = configureDotNetToolchain) {
32
37
  this.sessions = sessions;
33
38
  this.bridgeFactory = bridgeFactory;
34
39
  this.pairRunner = pairRunner;
35
40
  this.cleanupFactory = cleanupFactory;
41
+ this.dotNetToolchainConfigurator = dotNetToolchainConfigurator;
36
42
  }
37
43
  async run(argv, io = { stdout: process.stdout, stderr: process.stderr }) {
38
44
  if (argv.length === 0 || argv[0] === "--help" || argv[0] === "-h") {
@@ -67,15 +73,41 @@ export class ForgeBridgeCliService {
67
73
  io.stderr.write(`forge-bridge connect requires ${missing[0]}.\n`);
68
74
  return 2;
69
75
  }
76
+ let dotNetToolchain;
77
+ try {
78
+ dotNetToolchain = await this.dotNetToolchainConfigurator(await dotNetPreflightRoots(config, args.implicitCloneDestination), { cloneFolders: [config.defaultRepoRoot.trim()].filter(Boolean) });
79
+ }
80
+ catch (error) {
81
+ io.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
82
+ return 1;
83
+ }
84
+ if (dotNetToolchain) {
85
+ io.stdout.write(`Using .NET SDK ${dotNetToolchain.sdkVersion}: ${dotNetToolchain.executablePath}\n`);
86
+ }
70
87
  const controller = new AbortController();
71
88
  const stop = () => controller.abort("signal received");
72
89
  process.once("SIGINT", stop);
73
90
  process.once("SIGTERM", stop);
74
91
  try {
92
+ if (config.cleanupWorktrees && config.repoMappings.some(mapping => mapping.localPath?.trim())) {
93
+ io.stdout.write("Cleaning stale managed worktrees before accepting dispatches.\n");
94
+ await cleanupRepos(config, "stale", true, this.cleanupFactory(config.sandboxStateRoot), io);
95
+ // Forge branches on this device whose work has merged since the bridge last ran.
96
+ await cleanupRepos(config, "merged", true, this.cleanupFactory(config.sandboxStateRoot), io);
97
+ }
75
98
  io.stdout.write(connectStartupText(config));
76
99
  await this.bridgeFactory(config).run(controller.signal);
77
100
  return 0;
78
101
  }
102
+ catch (error) {
103
+ if (error instanceof BridgeRevokedError) {
104
+ // Decision 0014: removed from Forge. Exit with a distinct code so a supervisor can
105
+ // tell "pair again" apart from a crash.
106
+ io.stderr.write(`${error.message}\n`);
107
+ return bridgeRevokedExitCode;
108
+ }
109
+ throw error;
110
+ }
79
111
  finally {
80
112
  process.off("SIGINT", stop);
81
113
  process.off("SIGTERM", stop);
@@ -99,13 +131,22 @@ export class ForgeBridgeCliService {
99
131
  const current = readLocalConfigSync();
100
132
  io.stdout.write(`Pairing with server: ${args.serverUrl}\n`);
101
133
  const code = await resolvePairingCode(args.code);
102
- const repoRoot = await resolvePairRepoRoot(args.repoRoot, current.defaultRepoRoot);
103
- await fs.mkdir(repoRoot, { recursive: true });
104
- const pairArgs = await withDetectedPairCliProviders({ ...args, code, repoRoot });
134
+ const provisionalRoot = path.resolve(args.repoRoot ?? current.defaultRepoRoot ?? path.join(os.homedir(), "ForgeRepos"));
135
+ const pairArgs = await withDetectedPairCliProviders({ ...args, code, repoRoot: provisionalRoot });
105
136
  const claim = await this.pairRunner(pairArgs);
106
- const next = pairedConfig(current, pairArgs, claim);
107
- await writeLocalConfig(next);
108
- io.stdout.write(`Paired runner ${claim.runnerId}.\n`);
137
+ // The code is spent now: save the credentials before anything else can fail or prompt.
138
+ const applied = applyPairHost(pairArgs, claim.host, args.repoRoot !== undefined, io);
139
+ await writeLocalConfig(pairedConfig(current, applied.args, claim));
140
+ let repoRoot = applied.args.repoRoot;
141
+ if (!args.repoRoot && !applied.repoRootFromHost) {
142
+ const answered = await promptPairRepoRoot(repoRoot);
143
+ if (answered !== repoRoot) {
144
+ repoRoot = answered;
145
+ await writeLocalConfig(pairedConfig(current, { ...applied.args, repoRoot }, claim));
146
+ }
147
+ }
148
+ await fs.mkdir(repoRoot, { recursive: true });
149
+ io.stdout.write(`Paired runner ${claim.runnerId}${applied.args.name ? ` (${applied.args.name})` : ""}.\n`);
109
150
  io.stdout.write(`Repo folder: ${repoRoot}\n`);
110
151
  io.stdout.write(`Config: ${resolveLocalConfigPath()}\n`);
111
152
  io.stdout.write("Start the bridge with: forge-bridge connect\n");
@@ -188,6 +229,9 @@ export class ForgeBridgeCliService {
188
229
  writeSandboxPolicyStatus(readLocalConfigSync(), io);
189
230
  return 0;
190
231
  }
232
+ if (args.command === "yield") {
233
+ return await runYieldCommand(args.action, io);
234
+ }
191
235
  if (args.command === "mcp") {
192
236
  const parsed = parseCompletionMcpArgs(args.argv);
193
237
  if (!parsed.ok) {
@@ -216,7 +260,7 @@ export class ForgeBridgeCliService {
216
260
  }
217
261
  catch (error) {
218
262
  const summary = redactText(error instanceof Error ? error.message : String(error), redactionSecrets);
219
- await writeJsonAtomic(args.resultPath, failureResult(summary)).catch(() => undefined);
263
+ await writeJsonAtomic(args.resultPath, redactRunOnceResultPacket(failureResult(summary, [], failureFactsFromError(error, { source: "bridge" })), redactionSecrets)).catch(() => undefined);
220
264
  io.stderr.write(`${summary}\n`);
221
265
  return 1;
222
266
  }
@@ -225,6 +269,36 @@ export class ForgeBridgeCliService {
225
269
  }
226
270
  }
227
271
  }
272
+ /**
273
+ * Decision 0014 `forge-bridge yield`: the host's own yield switch. It writes a
274
+ * flag file next to the bridge config (never bridge.json); a running bridge
275
+ * polls it and stops taking new attempts without a restart.
276
+ */
277
+ async function runYieldCommand(action, io) {
278
+ const flagPath = resolveLocalYieldFlagPath();
279
+ try {
280
+ if (action !== "status") {
281
+ await writeLocalYieldFlag(flagPath, action === "on");
282
+ }
283
+ const on = await readLocalYieldFlag(flagPath);
284
+ if (action === "on") {
285
+ io.stdout.write("Local yield to foreground is on. A running bridge takes no new attempts within one heartbeat; running attempts finish.\n");
286
+ }
287
+ else if (action === "off") {
288
+ io.stdout.write("Local yield to foreground is off. The bridge takes new attempts again unless yield is on in Forge.\n");
289
+ }
290
+ else {
291
+ io.stdout.write(`Local yield to foreground: ${on ? "on" : "off"}\n`);
292
+ }
293
+ io.stdout.write(`Flag file: ${flagPath}\n`);
294
+ io.stdout.write("The effective state also depends on Forge: the runner yields when this flag or its Yield toggle in Forge is on.\n");
295
+ return 0;
296
+ }
297
+ catch (error) {
298
+ io.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
299
+ return 1;
300
+ }
301
+ }
228
302
  function attachEnvSecretGrant(dispatch) {
229
303
  if (!dispatch.execution.requiresApiKeySecretGrant) {
230
304
  delete process.env[apiKeySecretGrantEnv];
@@ -328,6 +402,13 @@ export function parseArgs(argv) {
328
402
  if (argv[0] === "sandbox") {
329
403
  return parseSandboxArgs(argv);
330
404
  }
405
+ if (argv[0] === "yield") {
406
+ const action = argv[1] ?? "status";
407
+ if (argv.length > 2 || (action !== "on" && action !== "off" && action !== "status")) {
408
+ return { ok: false, error: "Usage: forge-bridge yield [on|off|status]" };
409
+ }
410
+ return { ok: true, command: "yield", action };
411
+ }
331
412
  if (argv[0] !== "run-once") {
332
413
  return {
333
414
  ok: false,
@@ -582,6 +663,28 @@ async function reapSandboxes(io) {
582
663
  await preflight.release();
583
664
  }
584
665
  }
666
+ async function dotNetPreflightRoots(config, implicitCloneDestination) {
667
+ const roots = config.repoMappings.map((mapping) => mapping.localPath?.trim())
668
+ .filter((repoRoot) => Boolean(repoRoot));
669
+ const defaultRoot = config.defaultRepoRoot.trim();
670
+ if (!defaultRoot)
671
+ return roots;
672
+ if (implicitCloneDestination) {
673
+ try {
674
+ // The built-in clone destination need not exist on first connect. lstat
675
+ // deliberately retains dangling links for the strict SDK scanner to reject.
676
+ // Explicit mappings (including this same path) remain required inputs.
677
+ await fs.lstat(defaultRoot);
678
+ }
679
+ catch (error) {
680
+ if (error.code === "ENOENT")
681
+ return roots;
682
+ throw error;
683
+ }
684
+ }
685
+ roots.push(defaultRoot);
686
+ return roots;
687
+ }
585
688
  function parseConnectArgs(argv) {
586
689
  let serverUrl = null;
587
690
  let runnerId = null;
@@ -651,7 +754,10 @@ function parseConnectArgs(argv) {
651
754
  return {
652
755
  ok: true,
653
756
  command: "connect",
654
- config: configuredBridgeServiceConfig(overrides, localConfig)
757
+ config: configuredBridgeServiceConfig(overrides, localConfig),
758
+ implicitCloneDestination: repoRoot === null
759
+ && process.env.FORGE_REPO_ROOT === undefined
760
+ && localConfig.defaultRepoRoot === undefined,
655
761
  };
656
762
  }
657
763
  function parsePairArgs(argv) {
@@ -714,8 +820,9 @@ function parsePairArgs(argv) {
714
820
  name: name?.trim() || defaultName,
715
821
  fingerprint: fingerprint?.trim() || `local-bridge:${os.hostname()}:${user}`,
716
822
  repoRoot: repoRoot?.trim() ? path.resolve(repoRoot) : undefined,
717
- cleanupWorktrees: cleanupWorktrees ?? localConfig.cleanupWorktrees ?? false,
823
+ cleanupWorktrees: cleanupWorktrees ?? defaultConfig.cleanupWorktrees,
718
824
  cliProviders: cliProviders.length > 0 ? cliProviders : localConfig.cliProviders && localConfig.cliProviders.length > 0 ? [...localConfig.cliProviders] : ["codex"],
825
+ cliProvidersFromFlag: cliProviders.length > 0,
719
826
  projectLabels: projectLabels.length > 0 ? projectLabels : localConfig.projectLabels ? [...localConfig.projectLabels] : []
720
827
  };
721
828
  }
@@ -778,9 +885,71 @@ async function claimBridgeRunner(args) {
778
885
  }
779
886
  return {
780
887
  runnerId: value.runnerId,
781
- deviceToken: value.deviceToken
888
+ deviceToken: value.deviceToken,
889
+ host: parsePairRunnerHost(value.host)
890
+ };
891
+ }
892
+ function parsePairRunnerHost(value) {
893
+ if (!value || typeof value !== "object") {
894
+ return undefined;
895
+ }
896
+ const host = value;
897
+ const name = typeof host.name === "string" && host.name.trim() ? host.name.trim() : undefined;
898
+ const repoRoot = typeof host.repoRoot === "string" && host.repoRoot.trim() ? host.repoRoot.trim() : undefined;
899
+ const cliProviders = Array.isArray(host.cliProviders)
900
+ ? host.cliProviders.filter((provider) => typeof provider === "string" && provider.trim().length > 0)
901
+ : [];
902
+ return { name, repoRoot, cliProviders: cliProviders.length > 0 ? cliProviders : undefined };
903
+ }
904
+ /**
905
+ * Decision 0014 §5: the claim's host block carries what the Connect dialog chose. The runner name
906
+ * is the server's; providers and the repo folder apply unless a flag named them on this command line.
907
+ */
908
+ function applyPairHost(args, host, repoRootFromFlag, io) {
909
+ if (!host) {
910
+ return { args, repoRootFromHost: false };
911
+ }
912
+ let repoRoot = args.repoRoot;
913
+ let repoRootFromHost = false;
914
+ if (host.repoRoot && !repoRootFromFlag) {
915
+ const resolved = resolveHostRepoRoot(host.repoRoot);
916
+ if (!resolved) {
917
+ io.stderr.write(`Ignoring the repo folder chosen in Forge (${host.repoRoot}): it is not a path on this machine.\n`);
918
+ }
919
+ else {
920
+ repoRootFromHost = true;
921
+ repoRoot = resolved;
922
+ }
923
+ }
924
+ return {
925
+ args: {
926
+ ...args,
927
+ name: host.name ?? args.name,
928
+ cliProviders: host.cliProviders && !args.cliProvidersFromFlag ? [...host.cliProviders] : args.cliProviders,
929
+ repoRoot
930
+ },
931
+ repoRootFromHost
782
932
  };
783
933
  }
934
+ /** Expands `~` in a repo folder chosen in Forge and rejects one shaped for another OS. */
935
+ export function resolveHostRepoRoot(value, platform = process.platform, home = os.homedir()) {
936
+ const trimmed = value.trim();
937
+ if (!trimmed) {
938
+ return undefined;
939
+ }
940
+ const pathApi = platform === "win32" ? path.win32 : path.posix;
941
+ if (trimmed === "~") {
942
+ return home;
943
+ }
944
+ if (/^~[\\/]/.test(trimmed)) {
945
+ return pathApi.resolve(home, trimmed.slice(2));
946
+ }
947
+ const windowsShaped = /^[A-Za-z]:[\\/]/.test(trimmed) || trimmed.startsWith("\\\\");
948
+ if (platform === "win32") {
949
+ return windowsShaped || trimmed.startsWith("/") ? pathApi.resolve(trimmed) : undefined;
950
+ }
951
+ return !windowsShaped && trimmed.startsWith("/") ? pathApi.resolve(trimmed) : undefined;
952
+ }
784
953
  function pairedConfig(current, args, claim) {
785
954
  return {
786
955
  ...current,
@@ -825,11 +994,7 @@ async function resolvePairingCode(code) {
825
994
  prompt.close();
826
995
  }
827
996
  }
828
- async function resolvePairRepoRoot(repoRoot, configuredRoot) {
829
- const fallback = path.resolve(repoRoot ?? configuredRoot ?? path.join(os.homedir(), "ForgeRepos"));
830
- if (repoRoot?.trim()) {
831
- return fallback;
832
- }
997
+ async function promptPairRepoRoot(fallback) {
833
998
  if (!process.stdin.isTTY || !process.stdout.isTTY) {
834
999
  return fallback;
835
1000
  }
@@ -869,6 +1034,7 @@ function connectStartupText(config) {
869
1034
  ` repo folder: ${config.defaultRepoRoot || "not configured"}`,
870
1035
  ` providers: ${formatList(config.cliProviders)}`,
871
1036
  ` cleanup worktrees: ${config.cleanupWorktrees ? "enabled" : "disabled"}`,
1037
+ ` Docker Desktop auto-recovery: ${config.dockerDesktopRecoveryEnabled ? "enabled" : "disabled"}`,
872
1038
  ` open public sandbox networking: ${config.allowOpenPublicSandbox ? "enabled" : "disabled"}`,
873
1039
  "",
874
1040
  "Press Ctrl+C to stop.",
@@ -900,7 +1066,7 @@ async function writeJsonAtomic(outputPath, value) {
900
1066
  await fs.rename(tempPath, outputPath);
901
1067
  }
902
1068
  async function writeStatus(config, checkUpdates, io) {
903
- const detected = await detectCliProviders([...new Set([...config.cliProviders, "codex", "cursor"])]);
1069
+ const detected = await detectCliProviders([...new Set([...config.cliProviders, "codex", "cursor", "claude"])]);
904
1070
  const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
905
1071
  io.stdout.write(`Forge bridge ${config.version}\n`);
906
1072
  io.stdout.write(`Config: ${resolveLocalConfigPath()}\n`);
@@ -957,7 +1123,11 @@ async function cleanupRepos(config, mode, force, cleanup, io) {
957
1123
  io.stdout.write(`Removed ${result.removedWorktrees} stale managed ${result.removedWorktrees === 1 ? "worktree" : "worktrees"} from ${result.worktreeRoot}\n`);
958
1124
  }
959
1125
  else {
960
- io.stdout.write(`Pruned stale worktree metadata for ${repoPath}\n`);
1126
+ const deleted = result.deletedBranches ?? 0;
1127
+ io.stdout.write(`Pruned stale worktree metadata and deleted ${deleted} Forge ${deleted === 1 ? "branch" : "branches"} (merged work and leftover readiness probes) in ${repoPath}\n`);
1128
+ if (result.mergedBaseUnresolved) {
1129
+ io.stderr.write(`${repoPath}: merged work branches were kept because the base branch couldn't be determined: origin/HEAD is unset or names a branch that no longer exists, and origin has none or more than one of develop, main and master. Run \`git fetch origin && git remote set-head origin --auto\`.\n`);
1130
+ }
961
1131
  }
962
1132
  }
963
1133
  catch (error) {
@@ -973,7 +1143,7 @@ async function detectCliProviders(providers) {
973
1143
  let detected = null;
974
1144
  for (const probe of cliProbeCommandsFor(provider)) {
975
1145
  try {
976
- detected = await execVersionCommand(probe);
1146
+ detected = await execVersionCommand(probe, probe.timeoutMs);
977
1147
  break;
978
1148
  }
979
1149
  catch {
@@ -997,6 +1167,13 @@ function cliProbeCommandsFor(provider) {
997
1167
  { command: "codex", args: ["--version"] }
998
1168
  ];
999
1169
  }
1170
+ if (normalized === "claude") {
1171
+ return [
1172
+ // Claude Code's Node startup can exceed the default 2s probe on a cold Windows host.
1173
+ { command: "claude", args: ["--version"], timeoutMs: 8000 },
1174
+ { command: "claude", args: ["-v"], timeoutMs: 8000 }
1175
+ ];
1176
+ }
1000
1177
  if (normalized === "cursor") {
1001
1178
  return [
1002
1179
  { command: "cursor-agent", args: ["-v"] },
@@ -1010,22 +1187,22 @@ function cliProbeCommandsFor(provider) {
1010
1187
  { command: provider, args: ["-V"] }
1011
1188
  ];
1012
1189
  }
1013
- async function execVersionCommand(probe, timeout = 2000) {
1190
+ async function execVersionCommand(probe, timeout = 2000, maxBuffer) {
1014
1191
  const directLaunch = process.platform === "win32"
1015
1192
  ? await resolveCursorAgentDirectLaunch(probe.command, probe.args)
1016
1193
  : null;
1017
1194
  if (directLaunch) {
1018
- return await execFileAsync(directLaunch.command, [...directLaunch.args], { timeout });
1195
+ return await execFileAsync(directLaunch.command, [...directLaunch.args], { timeout, maxBuffer });
1019
1196
  }
1020
1197
  try {
1021
- return await execFileAsync(probe.command, probe.args, { timeout });
1198
+ return await execFileAsync(probe.command, probe.args, { timeout, maxBuffer });
1022
1199
  }
1023
1200
  catch (error) {
1024
1201
  if (process.platform !== "win32") {
1025
1202
  throw error;
1026
1203
  }
1027
1204
  const launch = buildWindowsCmdLaunch(probe.command, probe.args);
1028
- return await execFileAsync(launch.command, [...launch.args], { timeout });
1205
+ return await execFileAsync(launch.command, [...launch.args], { timeout, maxBuffer });
1029
1206
  }
1030
1207
  }
1031
1208
  function versionLine(output) {
@@ -1040,19 +1217,26 @@ async function detectCliModels(provider) {
1040
1217
  const normalized = provider.toLowerCase();
1041
1218
  try {
1042
1219
  if (normalized === "codex") {
1043
- const result = await execFileAsync("codex", ["debug", "models"], { timeout: 5000, maxBuffer: 10 * 1024 * 1024 });
1220
+ // Windows installs codex as a .cmd shim, which execFile cannot launch directly.
1221
+ const result = await execVersionCommand({ command: "codex", args: ["debug", "models"] }, 10_000, 10 * 1024 * 1024);
1044
1222
  return parseCodexModelCatalog(result.stdout);
1045
1223
  }
1046
1224
  if (normalized === "cursor") {
1047
1225
  const result = await execVersionCommand({ command: "cursor-agent", args: ["models"] }, 10_000);
1048
1226
  return parseCursorModelList(`${result.stdout || result.stderr}`);
1049
1227
  }
1228
+ if (normalized === "claude") {
1229
+ // Claude Code has no model-listing command; it accepts these aliases and full model IDs.
1230
+ const configured = splitCsv(process.env.FORGE_CLAUDE_MODELS ?? "");
1231
+ return configured.length > 0 ? configured : [...claudeDefaultModels];
1232
+ }
1050
1233
  }
1051
1234
  catch {
1052
1235
  return [];
1053
1236
  }
1054
1237
  return [];
1055
1238
  }
1239
+ export const claudeDefaultModels = ["sonnet", "opus", "haiku"];
1056
1240
  export function parseCodexModelCatalog(raw) {
1057
1241
  try {
1058
1242
  const parsed = JSON.parse(raw);
@@ -1105,8 +1289,8 @@ function uniqueModels(models) {
1105
1289
  function isRecord(value) {
1106
1290
  return typeof value === "object" && value !== null;
1107
1291
  }
1108
- async function withDetectedCliProviders(config) {
1109
- const detected = await detectCliProviders(configuredProviderCandidates(config.cliProviders));
1292
+ async function withDetectedCliProviders(config, candidates = config.cliProviders) {
1293
+ const detected = await detectCliProviders(uniqueProviders(candidates));
1110
1294
  const found = detected.filter((result) => result.found);
1111
1295
  if (found.length === 0) {
1112
1296
  return config;
@@ -1130,6 +1314,7 @@ async function withDetectedCliProviders(config) {
1130
1314
  };
1131
1315
  }
1132
1316
  async function withDetectedPairCliProviders(args) {
1317
+ const configured = configuredProviderCandidates(args.cliProviders);
1133
1318
  const detectedConfig = await withDetectedCliProviders({
1134
1319
  ...defaultBridgeServiceConfig({
1135
1320
  serverUrl: args.serverUrl,
@@ -1139,14 +1324,14 @@ async function withDetectedPairCliProviders(args) {
1139
1324
  cleanupWorktrees: args.cleanupWorktrees,
1140
1325
  defaultRepoRoot: args.repoRoot ?? defaultBridgeServiceConfig().defaultRepoRoot
1141
1326
  })
1142
- });
1327
+ }, configured);
1143
1328
  return {
1144
1329
  ...args,
1145
1330
  cliProviders: detectedConfig.cliProviders
1146
1331
  };
1147
1332
  }
1148
1333
  function configuredProviderCandidates(providers) {
1149
- return uniqueProviders([...providers, "codex", "cursor"]);
1334
+ return uniqueProviders([...providers, "codex", "cursor", "claude"]);
1150
1335
  }
1151
1336
  function uniqueProviders(providers) {
1152
1337
  return providers
@@ -8,6 +8,7 @@ export interface BridgeLocalConfig {
8
8
  readonly defaultRepoRoot?: string;
9
9
  readonly cleanupWorktrees?: boolean;
10
10
  readonly dockerEnabled?: boolean;
11
+ readonly dockerDesktopRecoveryEnabled?: boolean;
11
12
  readonly allowOpenPublicSandbox?: boolean;
12
13
  readonly cliProviders?: readonly string[];
13
14
  readonly providerStatuses?: Readonly<Record<string, BridgeProviderStatus>>;
@@ -29,8 +30,12 @@ export interface LocalRepoMapping extends BridgeRepoMapping {
29
30
  export declare function resolveLocalConfigPath(): string;
30
31
  export declare function readLocalConfig(): Promise<BridgeLocalConfig>;
31
32
  export declare function readLocalConfigSync(): BridgeLocalConfig;
33
+ /** Decision 0014 §5: `bridge.json` holds the device token, so only its owner may read it. */
34
+ export declare const localConfigFileMode = 384;
32
35
  export declare function writeLocalConfig(config: BridgeLocalConfig): Promise<void>;
33
36
  export declare function applyLocalConfigDefaults(config: BridgeServiceConfig, local: BridgeLocalConfig): BridgeServiceConfig;
37
+ /** Decision 0014: the `forge-bridge yield` flag, beside the bridge config and never inside it. */
38
+ export declare function resolveLocalYieldFlagPath(): string;
34
39
  export declare function addRepoMapping(label: string, repoPath: string): Promise<BridgeLocalConfig>;
35
40
  export declare function removeRepoMapping(label: string): Promise<{
36
41
  readonly config: BridgeLocalConfig;
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
2
2
  import fsSync from "node:fs";
3
3
  import os from "node:os";
4
4
  import path from "node:path";
5
+ import { localYieldFlagPathFor } from "../bridge/local-yield-flag.js";
5
6
  export function resolveLocalConfigPath() {
6
7
  if (process.env.FORGE_BRIDGE_CONFIG?.trim()) {
7
8
  return path.resolve(process.env.FORGE_BRIDGE_CONFIG);
@@ -28,12 +29,28 @@ export function readLocalConfigSync() {
28
29
  }
29
30
  return parseLocalConfig(fsSync.readFileSync(configPath, "utf8"));
30
31
  }
32
+ /** Decision 0014 §5: `bridge.json` holds the device token, so only its owner may read it. */
33
+ export const localConfigFileMode = 0o600;
34
+ const localConfigDirectoryMode = 0o700;
31
35
  export async function writeLocalConfig(config) {
32
36
  const configPath = resolveLocalConfigPath();
33
- await fs.mkdir(path.dirname(configPath), { recursive: true });
37
+ await fs.mkdir(path.dirname(configPath), { recursive: true, mode: localConfigDirectoryMode });
34
38
  const tempPath = `${configPath}.${process.pid}.${Date.now()}.tmp`;
35
- await fs.writeFile(tempPath, `${JSON.stringify(normalizeLocalConfig(config), null, 2)}\n`, "utf8");
36
- await fs.rename(tempPath, configPath);
39
+ try {
40
+ await fs.writeFile(tempPath, `${JSON.stringify(normalizeLocalConfig(config), null, 2)}\n`, {
41
+ encoding: "utf8",
42
+ mode: localConfigFileMode
43
+ });
44
+ if (process.platform !== "win32") {
45
+ // The create mode is masked by the umask; set it exactly before the file becomes visible.
46
+ await fs.chmod(tempPath, localConfigFileMode);
47
+ }
48
+ await fs.rename(tempPath, configPath);
49
+ }
50
+ catch (error) {
51
+ await fs.rm(tempPath, { force: true }).catch(() => undefined);
52
+ throw error;
53
+ }
37
54
  }
38
55
  export function applyLocalConfigDefaults(config, local) {
39
56
  const cliProviders = local.cliProviders && local.cliProviders.length > 0 ? [...local.cliProviders] : config.cliProviders;
@@ -48,6 +65,9 @@ export function applyLocalConfigDefaults(config, local) {
48
65
  dockerEnabled: process.env.FORGE_DOCKER_SANDBOX === undefined
49
66
  ? local.dockerEnabled ?? config.dockerEnabled
50
67
  : config.dockerEnabled,
68
+ dockerDesktopRecoveryEnabled: process.env.FORGE_DOCKER_DESKTOP_AUTO_RECOVERY === undefined
69
+ ? local.dockerDesktopRecoveryEnabled ?? config.dockerDesktopRecoveryEnabled
70
+ : config.dockerDesktopRecoveryEnabled,
51
71
  allowOpenPublicSandbox: process.env.FORGE_ALLOW_OPEN_PUBLIC_SANDBOX === undefined
52
72
  ? local.allowOpenPublicSandbox ?? config.allowOpenPublicSandbox
53
73
  : config.allowOpenPublicSandbox,
@@ -62,9 +82,14 @@ export function applyLocalConfigDefaults(config, local) {
62
82
  supportsRunnerAuthoredPhaseArtifacts: local.supportsRunnerAuthoredPhaseArtifacts ?? config.supportsRunnerAuthoredPhaseArtifacts,
63
83
  supportsDraftRunOnce: local.supportsDraftRunOnce ?? config.supportsDraftRunOnce,
64
84
  supportsDraftAttachments: local.supportsDraftAttachments ?? config.supportsDraftAttachments,
65
- supportsDraftImageAttachments: local.supportsDraftImageAttachments ?? config.supportsDraftImageAttachments
85
+ supportsDraftImageAttachments: local.supportsDraftImageAttachments ?? config.supportsDraftImageAttachments,
86
+ localYieldFlagPath: resolveLocalYieldFlagPath()
66
87
  };
67
88
  }
89
+ /** Decision 0014: the `forge-bridge yield` flag, beside the bridge config and never inside it. */
90
+ export function resolveLocalYieldFlagPath() {
91
+ return localYieldFlagPathFor(resolveLocalConfigPath());
92
+ }
68
93
  export async function addRepoMapping(label, repoPath) {
69
94
  const normalizedLabel = normalizeLabel(label);
70
95
  const localPath = path.resolve(repoPath);
@@ -126,6 +151,7 @@ function normalizeLocalConfig(config) {
126
151
  defaultRepoRoot: cleanString(config.defaultRepoRoot),
127
152
  cleanupWorktrees: config.cleanupWorktrees,
128
153
  dockerEnabled: config.dockerEnabled,
154
+ dockerDesktopRecoveryEnabled: config.dockerDesktopRecoveryEnabled,
129
155
  allowOpenPublicSandbox: config.allowOpenPublicSandbox,
130
156
  cliProviders: cleanList(config.cliProviders),
131
157
  providerStatuses: normalizeProviderStatuses(config.providerStatuses),
@@ -0,0 +1,36 @@
1
+ export interface AspNetRuntimePrebuildPlan {
2
+ readonly fingerprint: string;
3
+ readonly receiptPath: string;
4
+ readonly command: string;
5
+ readonly args: readonly string[];
6
+ readonly cwd: string;
7
+ readonly environment: Readonly<Record<string, string>>;
8
+ readonly projectPath: string;
9
+ readonly worktreePath: string;
10
+ readonly inputCommitSha: string;
11
+ }
12
+ export interface AspNetRuntimePrebuildResult {
13
+ readonly cacheHit: boolean;
14
+ readonly receiptPath: string;
15
+ readonly fingerprint: string;
16
+ }
17
+ export interface AspNetRuntimeBuildExecutionResult {
18
+ readonly exitCode: number;
19
+ readonly stdoutTail: string;
20
+ readonly stderrTail: string;
21
+ readonly stdoutLogPath: string;
22
+ readonly stderrLogPath: string;
23
+ }
24
+ export type AspNetRuntimeBuildExecutor = (plan: AspNetRuntimePrebuildPlan, signal?: AbortSignal) => Promise<AspNetRuntimeBuildExecutionResult>;
25
+ export declare function createAspNetRuntimePrebuildPlan(options: {
26
+ readonly command: string;
27
+ readonly args: readonly string[];
28
+ readonly cwd: string;
29
+ readonly worktreePath: string;
30
+ readonly environment?: Readonly<Record<string, string>>;
31
+ readonly inputCommitSha: string;
32
+ readonly runtimeContractFingerprint: string;
33
+ }): AspNetRuntimePrebuildPlan | null;
34
+ export declare function ensureAspNetRuntimePrebuilt(plan: AspNetRuntimePrebuildPlan, execute: AspNetRuntimeBuildExecutor, signal?: AbortSignal): Promise<AspNetRuntimePrebuildResult>;
35
+ export declare function withAspNetPrebuiltRunArguments(command: string, args: readonly string[]): readonly string[];
36
+ export declare function resolveWorktreeCommitSha(worktreePath: string, supplied?: string | null): Promise<string>;