@loucompanion/forge-bridge 0.1.4-dev.63db04bcffca → 0.1.4-dev.724427ea7be8

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 (271) hide show
  1. package/README.md +144 -3
  2. package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
  3. package/dist/bridge/bridge-chat-provider-command.js +132 -0
  4. package/dist/bridge/bridge-chat.types.d.ts +10 -0
  5. package/dist/bridge/bridge-chat.types.js +16 -1
  6. package/dist/bridge/bridge-state-file.d.ts +161 -0
  7. package/dist/bridge/bridge-state-file.js +376 -0
  8. package/dist/bridge/bridge-state-io.d.ts +11 -0
  9. package/dist/bridge/bridge-state-io.js +50 -0
  10. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  11. package/dist/bridge/bridge-state-lock.js +102 -0
  12. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  13. package/dist/bridge/bridge-state-unpublished.js +111 -0
  14. package/dist/bridge/bridge.base.d.ts +9 -0
  15. package/dist/bridge/bridge.service.d.ts +101 -15
  16. package/dist/bridge/bridge.service.js +472 -345
  17. package/dist/bridge/bridge.types.d.ts +27 -0
  18. package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
  19. package/dist/bridge/dispatch-result-outbox.js +31 -6
  20. package/dist/bridge/in-flight-registry.d.ts +62 -0
  21. package/dist/bridge/in-flight-registry.js +207 -0
  22. package/dist/bridge/local-yield-flag.d.ts +6 -0
  23. package/dist/bridge/local-yield-flag.js +34 -0
  24. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  25. package/dist/bridge/readiness-result-outbox.js +20 -0
  26. package/dist/bridge/runner-host-capabilities.d.ts +5 -0
  27. package/dist/bridge/runner-host-capabilities.js +17 -0
  28. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  29. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  30. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  31. package/dist/bridge/test-postgres-capability.js +120 -0
  32. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  33. package/dist/cleanup/cleanup-wip.js +66 -0
  34. package/dist/cleanup/cleanup.service.d.ts +20 -1
  35. package/dist/cleanup/cleanup.service.js +150 -169
  36. package/dist/cleanup/cleanup.types.d.ts +6 -0
  37. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  38. package/dist/cleanup/forge-owned-paths.js +53 -0
  39. package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
  40. package/dist/cleanup/host-runtime-ledger.js +130 -0
  41. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  42. package/dist/cleanup/managed-branch-sweep.js +111 -0
  43. package/dist/cli/cli.help.js +74 -12
  44. package/dist/cli/cli.service.d.ts +19 -10
  45. package/dist/cli/cli.service.js +152 -187
  46. package/dist/cli/idle-status.d.ts +84 -0
  47. package/dist/cli/idle-status.js +181 -0
  48. package/dist/cli/local-config.d.ts +6 -0
  49. package/dist/cli/local-config.js +32 -4
  50. package/dist/cli/provider-cli-detection.d.ts +10 -0
  51. package/dist/cli/provider-cli-detection.js +160 -0
  52. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  53. package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
  54. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  55. package/dist/runtime/attempt-node-runtime-launcher.js +9 -0
  56. package/dist/runtime/attempt-process-supervisor.d.ts +21 -0
  57. package/dist/runtime/attempt-process-supervisor.js +62 -6
  58. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  59. package/dist/runtime/docker-engine-probe.js +7 -0
  60. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  61. package/dist/runtime/dotnet-build-outputs.js +402 -0
  62. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  63. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  64. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  65. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  66. package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
  67. package/dist/runtime/host-database-capability-boundary.js +1 -0
  68. package/dist/runtime/host-facts.d.ts +36 -0
  69. package/dist/runtime/host-facts.js +95 -0
  70. package/dist/runtime/host-load-admission.d.ts +67 -0
  71. package/dist/runtime/host-load-admission.js +99 -0
  72. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  73. package/dist/runtime/host-load-child-environment.js +76 -0
  74. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  75. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  76. package/dist/runtime/host-load-governor-config.d.ts +52 -0
  77. package/dist/runtime/host-load-governor-config.js +83 -0
  78. package/dist/runtime/host-load-governor.d.ts +186 -0
  79. package/dist/runtime/host-load-governor.js +632 -0
  80. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  81. package/dist/runtime/host-load-ledger-lock.js +187 -0
  82. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  83. package/dist/runtime/host-load-runtime-settings.js +80 -0
  84. package/dist/runtime/host-load-sampler.d.ts +156 -0
  85. package/dist/runtime/host-load-sampler.js +298 -0
  86. package/dist/runtime/host-load-step-class.d.ts +70 -0
  87. package/dist/runtime/host-load-step-class.js +161 -0
  88. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  89. package/dist/runtime/host-load-step-reaper.js +95 -0
  90. package/dist/runtime/host-load-step-run.d.ts +73 -0
  91. package/dist/runtime/host-load-step-run.js +102 -0
  92. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  93. package/dist/runtime/host-load-test-slot.js +81 -0
  94. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  95. package/dist/runtime/host-load-token-ledger.js +453 -0
  96. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  97. package/dist/runtime/host-load-windows-cpu.js +85 -0
  98. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  99. package/dist/runtime/host-pressure-stall.js +168 -0
  100. package/dist/runtime/host-runtime-contract.d.ts +16 -0
  101. package/dist/runtime/host-runtime-contract.js +35 -2
  102. package/dist/runtime/host-runtime-lease.d.ts +76 -5
  103. package/dist/runtime/host-runtime-lease.js +322 -129
  104. package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
  105. package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
  106. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  107. package/dist/runtime/host-runtime-promotion.js +48 -0
  108. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  109. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  110. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  111. package/dist/runtime/host-runtime-requirements.js +117 -0
  112. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  113. package/dist/runtime/managed-command-teardown.js +596 -0
  114. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  115. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  116. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  117. package/dist/runtime/playwright-browser-cache.js +227 -0
  118. package/dist/runtime/playwright-host-runtime-adapter.d.ts +18 -0
  119. package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
  120. package/dist/runtime/runner-settings.d.ts +104 -0
  121. package/dist/runtime/runner-settings.js +236 -0
  122. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  123. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  124. package/dist/sandbox/host-capacity-broker.d.ts +115 -0
  125. package/dist/sandbox/host-capacity-broker.js +336 -0
  126. package/dist/sandbox/managed-branch.d.ts +13 -0
  127. package/dist/sandbox/managed-branch.js +90 -0
  128. package/dist/sandbox/provider-auth/codex.js +11 -11
  129. package/dist/sandbox/runtime.d.ts +10 -1
  130. package/dist/sandbox/runtime.js +47 -8
  131. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  132. package/dist/sandbox/sandbox-cgroups.js +42 -0
  133. package/dist/session/architect-waits.d.ts +2 -0
  134. package/dist/session/architect-waits.js +138 -0
  135. package/dist/session/managed-attempt-tools.d.ts +27 -7
  136. package/dist/session/managed-attempt-tools.js +406 -123
  137. package/dist/session/managed-build-coordinator.d.ts +17 -1
  138. package/dist/session/managed-build-coordinator.js +14 -1
  139. package/dist/session/managed-build-receipt.d.ts +5 -0
  140. package/dist/session/managed-build-receipt.js +8 -3
  141. package/dist/session/managed-command-host-load.d.ts +47 -0
  142. package/dist/session/managed-command-host-load.js +83 -0
  143. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  144. package/dist/session/mcp-argument-coercion.js +121 -0
  145. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  146. package/dist/session/phase-completion.artifacts.js +100 -26
  147. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  148. package/dist/session/phase-completion.command-validation.js +77 -0
  149. package/dist/session/phase-completion.d.ts +12 -0
  150. package/dist/session/phase-completion.helpers.js +13 -12
  151. package/dist/session/phase-completion.js +5 -0
  152. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  153. package/dist/session/phase-completion.mcp-args.js +156 -0
  154. package/dist/session/phase-completion.prompts.js +6 -1
  155. package/dist/session/phase-completion.runtime.d.ts +5 -11
  156. package/dist/session/phase-completion.runtime.js +111 -230
  157. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  158. package/dist/session/phase-completion.schema-parts.js +188 -0
  159. package/dist/session/phase-completion.schemas.d.ts +3 -3
  160. package/dist/session/phase-completion.schemas.js +208 -231
  161. package/dist/session/phase-completion.validation.d.ts +2 -3
  162. package/dist/session/phase-completion.validation.js +49 -93
  163. package/dist/session/pre-publication-host-load.d.ts +27 -0
  164. package/dist/session/pre-publication-host-load.js +111 -0
  165. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  166. package/dist/session/pre-publication-native-postgres.js +111 -0
  167. package/dist/session/pre-publication-pass.d.ts +61 -0
  168. package/dist/session/pre-publication-pass.js +148 -0
  169. package/dist/session/pre-publication-process.d.ts +23 -0
  170. package/dist/session/pre-publication-process.js +109 -0
  171. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  172. package/dist/session/pre-publication-skipped-tests.js +109 -0
  173. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  174. package/dist/session/pre-publication-step-execution.js +50 -0
  175. package/dist/session/pre-publication-validation.d.ts +37 -21
  176. package/dist/session/pre-publication-validation.js +228 -219
  177. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  178. package/dist/session/provider-cli/claude-background-work.js +181 -0
  179. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  180. package/dist/session/provider-cli/host-build-lock.js +30 -0
  181. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  182. package/dist/session/provider-cli/pre-publication-repair.js +276 -0
  183. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
  184. package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
  185. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  186. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  187. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  188. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  189. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  190. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  191. package/dist/session/provider-cli/provider-cli.process.d.ts +46 -31
  192. package/dist/session/provider-cli/provider-cli.process.js +286 -403
  193. package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -0
  194. package/dist/session/provider-cli/provider-cli.prompts.js +87 -32
  195. package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
  196. package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
  197. package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
  198. package/dist/session/provider-cli/provider-cli.service.js +207 -192
  199. package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
  200. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  201. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  202. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  203. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  204. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  205. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  206. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  207. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  208. package/dist/session/provider-cli/provider-output-state.d.ts +8 -0
  209. package/dist/session/provider-cli/provider-output-state.js +15 -0
  210. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  211. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  212. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  213. package/dist/session/publishable-worktree-changes.js +193 -0
  214. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  215. package/dist/session/qa-sidecar-validation.js +28 -0
  216. package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
  217. package/dist/session/sandbox-host-capacity-gate.js +257 -0
  218. package/dist/session/session-redaction.js +31 -181
  219. package/dist/session/session.base.d.ts +9 -1
  220. package/dist/session/session.service.d.ts +11 -2
  221. package/dist/session/session.service.js +189 -69
  222. package/dist/session/session.types.d.ts +3 -0
  223. package/dist/session/session.types.js +15 -3
  224. package/dist/session/sidecar-json-shape.d.ts +31 -0
  225. package/dist/session/sidecar-json-shape.js +217 -0
  226. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  227. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  228. package/dist/shared/fs/file-identity.d.ts +10 -0
  229. package/dist/shared/fs/file-identity.js +15 -0
  230. package/dist/shared/fs/replace-file.d.ts +7 -0
  231. package/dist/shared/fs/replace-file.js +33 -0
  232. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  233. package/dist/shared/process/host-process-recovery.js +23 -3
  234. package/dist/shared/process/host-process-supervisor.d.ts +14 -1
  235. package/dist/shared/process/host-process-supervisor.js +67 -15
  236. package/dist/shared/process/process-tree.d.ts +52 -0
  237. package/dist/shared/process/process-tree.js +144 -0
  238. package/dist/shared/process/process.d.ts +67 -0
  239. package/dist/shared/process/process.js +213 -11
  240. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  241. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  242. package/dist/shared/process/windows-launch.d.ts +18 -0
  243. package/dist/shared/process/windows-launch.js +68 -0
  244. package/dist/shared/provider-capabilities.js +14 -7
  245. package/dist/version.d.ts +1 -1
  246. package/dist/version.js +1 -1
  247. package/dist/worktree/dependency-warmer.d.ts +25 -0
  248. package/dist/worktree/dependency-warmer.js +46 -10
  249. package/dist/worktree/orphan-relink.d.ts +19 -0
  250. package/dist/worktree/orphan-relink.js +106 -0
  251. package/dist/worktree/wip-git.d.ts +33 -0
  252. package/dist/worktree/wip-git.js +122 -0
  253. package/dist/worktree/wip-refs.d.ts +62 -0
  254. package/dist/worktree/wip-refs.js +119 -0
  255. package/dist/worktree/wip-restore.d.ts +38 -0
  256. package/dist/worktree/wip-restore.js +190 -0
  257. package/dist/worktree/wip-snapshot.d.ts +50 -0
  258. package/dist/worktree/wip-snapshot.js +268 -0
  259. package/dist/worktree/worktree-inputs.d.ts +8 -0
  260. package/dist/worktree/worktree-inputs.js +134 -0
  261. package/dist/worktree/worktree-origin-sync.d.ts +34 -0
  262. package/dist/worktree/worktree-origin-sync.js +127 -0
  263. package/dist/worktree/worktree-wip-events.d.ts +18 -0
  264. package/dist/worktree/worktree-wip-events.js +98 -0
  265. package/dist/worktree/worktree-wip.d.ts +50 -0
  266. package/dist/worktree/worktree-wip.js +185 -0
  267. package/dist/worktree/worktree.base.d.ts +7 -1
  268. package/dist/worktree/worktree.service.d.ts +36 -5
  269. package/dist/worktree/worktree.service.js +124 -155
  270. package/dist/worktree/worktree.types.d.ts +38 -0
  271. package/package.json +2 -2
@@ -0,0 +1,181 @@
1
+ import { evaluateBridgeIdle, formatAge, isProcessAlive, readBridgeStateFile, } from "../bridge/bridge-state-file.js";
2
+ import { describeInFlightIds } from "../bridge/in-flight-registry.js";
3
+ import { readLocalYieldFlag } from "../bridge/local-yield-flag.js";
4
+ import { resolveBridgeStatePath, resolveLocalYieldFlagPath } from "./local-config.js";
5
+ const statusUsage = "Usage: forge-bridge status [--check-updates] | forge-bridge status --idle [--require-yield] [--json] [--wait <seconds>]";
6
+ export function parseStatusArgs(argv, config) {
7
+ // --wait is tracked apart from its value: `--wait 0` without --idle is the same usage error as `--wait 5`.
8
+ const flags = { checkUpdates: false, idle: false, json: false, requireYield: false, waitSeconds: null };
9
+ const switches = {
10
+ "--check-updates": "checkUpdates", "--idle": "idle", "--json": "json", "--require-yield": "requireYield",
11
+ };
12
+ for (let index = 1; index < argv.length; index += 1) {
13
+ const arg = argv[index];
14
+ if (Object.hasOwn(switches, arg)) {
15
+ flags[switches[arg]] = true;
16
+ }
17
+ else if (arg === "--wait") {
18
+ const seconds = Number(argv[++index]);
19
+ if (!Number.isFinite(seconds) || seconds < 0)
20
+ return { ok: false, error: "--wait requires a number of seconds (0 or more)." };
21
+ flags.waitSeconds = seconds;
22
+ }
23
+ else {
24
+ return { ok: false, error: `Unknown argument: ${arg}\n${statusUsage}` };
25
+ }
26
+ }
27
+ if (!flags.idle && (flags.json || flags.requireYield || flags.waitSeconds !== null)) {
28
+ return { ok: false, error: `--json, --require-yield and --wait apply to --idle.\n${statusUsage}` };
29
+ }
30
+ if (flags.idle && flags.checkUpdates) {
31
+ return { ok: false, error: `--check-updates cannot be combined with --idle.\n${statusUsage}` };
32
+ }
33
+ return {
34
+ ok: true,
35
+ command: "status",
36
+ config: config(),
37
+ checkUpdates: flags.checkUpdates,
38
+ idle: flags.idle ? { json: flags.json, waitSeconds: flags.waitSeconds ?? 0, requireYield: flags.requireYield } : null,
39
+ };
40
+ }
41
+ export function defaultIdleStatusDependencies() {
42
+ return {
43
+ statePath: resolveBridgeStatePath(),
44
+ now: () => Date.now(),
45
+ pidAlive: isProcessAlive,
46
+ read: readBridgeStateFile,
47
+ localYield: () => readLocalYieldFlag(resolveLocalYieldFlagPath()),
48
+ sleep: ms => new Promise(resolve => setTimeout(resolve, ms)),
49
+ pollMs: 2_000,
50
+ };
51
+ }
52
+ export async function runIdleStatusCommand(options, io, deps = defaultIdleStatusDependencies()) {
53
+ const check = async () => evaluateBridgeIdle(await deps.read(deps.statePath), {
54
+ now: deps.now(),
55
+ pidAlive: deps.pidAlive,
56
+ requireYield: options.requireYield,
57
+ });
58
+ let evaluation = await check();
59
+ const deadline = deps.now() + options.waitSeconds * 1000;
60
+ if (worthWaiting(evaluation) && deps.now() < deadline && !options.json) {
61
+ io.stderr.write(`Waiting up to ${options.waitSeconds}s for the bridge to become idle (${evaluation.verdict})...\n`);
62
+ }
63
+ while (worthWaiting(evaluation) && deps.now() < deadline) {
64
+ await deps.sleep(Math.max(1, Math.min(deps.pollMs, deadline - deps.now())));
65
+ evaluation = await check();
66
+ }
67
+ const localYield = await deps.localYield().catch(() => false);
68
+ if (options.json) {
69
+ io.stdout.write(`${JSON.stringify(idleStatusJson(evaluation, deps, localYield), null, 2)}\n`);
70
+ }
71
+ else {
72
+ io.stdout.write(idleStatusText(evaluation, deps, localYield));
73
+ }
74
+ return evaluation.exitCode;
75
+ }
76
+ /** One line for plain `forge-bridge status`. */
77
+ export async function idleSummaryLine(deps = defaultIdleStatusDependencies()) {
78
+ const evaluation = evaluateBridgeIdle(await deps.read(deps.statePath), { now: deps.now(), pidAlive: deps.pidAlive });
79
+ return `${verdictTitles[evaluation.verdict]}: ${evaluation.reason} Details: forge-bridge status --idle`;
80
+ }
81
+ /**
82
+ * Busy work finishes, yield reaches Forge within a heartbeat, a stale heartbeat can recover and an
83
+ * unreadable or missing file can be a reader holding it (antivirus, the indexer) or a bridge
84
+ * starting. Only a dead bridge process will not change by waiting.
85
+ */
86
+ function worthWaiting(evaluation) {
87
+ return evaluation.verdict !== "idle" && evaluation.verdict !== "not_running";
88
+ }
89
+ export function idleStatusJson(evaluation, deps, localYield) {
90
+ return {
91
+ schemaVersion: 1,
92
+ verdict: evaluation.verdict,
93
+ idle: evaluation.verdict === "idle",
94
+ exitCode: evaluation.exitCode,
95
+ reason: evaluation.reason,
96
+ statePath: deps.statePath,
97
+ checkedAt: new Date(deps.now()).toISOString(),
98
+ pidAlive: evaluation.pidAlive,
99
+ heartbeatAgeMs: evaluation.heartbeatAgeMs,
100
+ staleAfterMs: evaluation.staleAfterMs,
101
+ localYield,
102
+ ...publishedStateFields(evaluation.state),
103
+ };
104
+ }
105
+ function publishedStateFields(state) {
106
+ if (!state) {
107
+ return {
108
+ pid: null, runnerId: null, runnerInstanceId: null, version: null, state: null, startedAt: null,
109
+ updatedAt: null, connected: null, yielding: null, yieldApplied: null, conflict: null, inFlight: [],
110
+ };
111
+ }
112
+ return {
113
+ pid: state.pid,
114
+ runnerId: state.runnerId,
115
+ runnerInstanceId: state.runnerInstanceId,
116
+ version: state.version,
117
+ state: state.state,
118
+ startedAt: state.startedAt,
119
+ updatedAt: state.updatedAt,
120
+ connected: state.connected,
121
+ yielding: state.yielding,
122
+ yieldApplied: state.yieldApplied ?? state.yielding,
123
+ conflict: state.conflict ?? null,
124
+ inFlight: state.inFlight,
125
+ };
126
+ }
127
+ const verdictTitles = {
128
+ idle: "Bridge idle",
129
+ busy: "Bridge busy",
130
+ not_yielding: "Bridge idle but not yielding",
131
+ stale: "Bridge state stale",
132
+ unknown: "Bridge state unknown",
133
+ not_running: "Bridge not running",
134
+ };
135
+ function idleStatusText(evaluation, deps, localYield) {
136
+ const state = evaluation.state;
137
+ const lines = [`${verdictTitles[evaluation.verdict]}: ${evaluation.reason}`, `State file: ${deps.statePath}`];
138
+ if (state) {
139
+ lines.push(`Process: pid ${state.pid} (${evaluation.pidAlive ? "running" : "not running"}), runner ${state.runnerId || "unknown"}, instance ${state.runnerInstanceId}, bridge ${state.version}`, `Heartbeat: ${state.updatedAt} (${formatAge(evaluation.heartbeatAgeMs ?? Number.NaN)} ago, stale after ${formatAge(evaluation.staleAfterMs)}); connected to Forge: ${state.connected ? "yes" : "no"}`, `Yield: ${yieldLine(state)} (local flag ${localYield ? "on" : "off"})`);
140
+ lines.push(...inFlightLines(state.inFlight, deps.now()));
141
+ }
142
+ lines.push(nextStep(evaluation, localYield));
143
+ return `${lines.join("\n")}\n`;
144
+ }
145
+ function inFlightLines(entries, now) {
146
+ if (entries.length === 0)
147
+ return ["In flight: nothing"];
148
+ return ["In flight:", ...entries.map(entry => {
149
+ const phaseAge = entry.phaseSince ? ` for ${formatAge(now - Date.parse(entry.phaseSince))}` : "";
150
+ const since = entry.since ? `, since ${entry.since}` : "";
151
+ return ` - ${entry.kind}: phase ${entry.phase}${phaseAge}${since}; ${describeInFlightIds(entry.ids)}`;
152
+ })];
153
+ }
154
+ function nextStep(evaluation, localYield) {
155
+ switch (evaluation.verdict) {
156
+ case "idle":
157
+ return evaluation.state?.yielding ? "Safe to restart now. After the new bridge connects, run `forge-bridge yield off` so it takes work again." : idleWithoutYieldStep(localYield);
158
+ case "not_yielding":
159
+ return evaluation.state?.yieldApplied
160
+ ? "The bridge applies yield but Forge has not acknowledged it yet (at most one heartbeat). Check again before restarting."
161
+ : idleWithoutYieldStep(localYield);
162
+ case "busy":
163
+ return "Do not restart. Run `forge-bridge yield on`, then `forge-bridge status --idle --require-yield --wait <seconds>` until it exits 0.";
164
+ case "not_running":
165
+ return "Nothing to interrupt, but confirm no other bridge process serves this runner before starting one.";
166
+ default:
167
+ return "Do not restart on this result: idle could not be confirmed.";
168
+ }
169
+ }
170
+ function yieldLine(state) {
171
+ if (state.yielding)
172
+ return "on and acknowledged by Forge, no new attempts";
173
+ return state.yieldApplied ? "applied, waiting for Forge to acknowledge it" : "off, Forge can still send new work";
174
+ }
175
+ // The bridge's own report is what counts: a flag written from another environment
176
+ // (another user, FORGE_BRIDGE_CONFIG, or a sandbox that virtualizes %APPDATA%) never reaches it.
177
+ function idleWithoutYieldStep(localYield) {
178
+ return localYield
179
+ ? "The local yield flag is on but the bridge has not reported yield yet. It picks the flag up within one heartbeat; if it never does, this flag file is not the one the bridge reads. Check again before restarting."
180
+ : "Idle now, but yield is off: run `forge-bridge yield on` and check again with --require-yield so no new work starts before the restart.";
181
+ }
@@ -30,8 +30,14 @@ export interface LocalRepoMapping extends BridgeRepoMapping {
30
30
  export declare function resolveLocalConfigPath(): string;
31
31
  export declare function readLocalConfig(): Promise<BridgeLocalConfig>;
32
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;
33
35
  export declare function writeLocalConfig(config: BridgeLocalConfig): Promise<void>;
34
36
  export declare function applyLocalConfigDefaults(config: BridgeServiceConfig, local: BridgeLocalConfig): BridgeServiceConfig;
37
+ /** Where `forge-bridge connect` publishes whether it is idle: `bridge.state.json` beside the config. */
38
+ export declare function resolveBridgeStatePath(): string;
39
+ /** Decision 0014: the `forge-bridge yield` flag, beside the bridge config and never inside it. */
40
+ export declare function resolveLocalYieldFlagPath(): string;
35
41
  export declare function addRepoMapping(label: string, repoPath: string): Promise<BridgeLocalConfig>;
36
42
  export declare function removeRepoMapping(label: string): Promise<{
37
43
  readonly config: BridgeLocalConfig;
@@ -2,6 +2,8 @@ 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";
6
+ import { bridgeStatePathFor } from "../bridge/bridge-state-file.js";
5
7
  export function resolveLocalConfigPath() {
6
8
  if (process.env.FORGE_BRIDGE_CONFIG?.trim()) {
7
9
  return path.resolve(process.env.FORGE_BRIDGE_CONFIG);
@@ -28,12 +30,28 @@ export function readLocalConfigSync() {
28
30
  }
29
31
  return parseLocalConfig(fsSync.readFileSync(configPath, "utf8"));
30
32
  }
33
+ /** Decision 0014 §5: `bridge.json` holds the device token, so only its owner may read it. */
34
+ export const localConfigFileMode = 0o600;
35
+ const localConfigDirectoryMode = 0o700;
31
36
  export async function writeLocalConfig(config) {
32
37
  const configPath = resolveLocalConfigPath();
33
- await fs.mkdir(path.dirname(configPath), { recursive: true });
38
+ await fs.mkdir(path.dirname(configPath), { recursive: true, mode: localConfigDirectoryMode });
34
39
  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);
40
+ try {
41
+ await fs.writeFile(tempPath, `${JSON.stringify(normalizeLocalConfig(config), null, 2)}\n`, {
42
+ encoding: "utf8",
43
+ mode: localConfigFileMode
44
+ });
45
+ if (process.platform !== "win32") {
46
+ // The create mode is masked by the umask; set it exactly before the file becomes visible.
47
+ await fs.chmod(tempPath, localConfigFileMode);
48
+ }
49
+ await fs.rename(tempPath, configPath);
50
+ }
51
+ catch (error) {
52
+ await fs.rm(tempPath, { force: true }).catch(() => undefined);
53
+ throw error;
54
+ }
37
55
  }
38
56
  export function applyLocalConfigDefaults(config, local) {
39
57
  const cliProviders = local.cliProviders && local.cliProviders.length > 0 ? [...local.cliProviders] : config.cliProviders;
@@ -65,9 +83,19 @@ export function applyLocalConfigDefaults(config, local) {
65
83
  supportsRunnerAuthoredPhaseArtifacts: local.supportsRunnerAuthoredPhaseArtifacts ?? config.supportsRunnerAuthoredPhaseArtifacts,
66
84
  supportsDraftRunOnce: local.supportsDraftRunOnce ?? config.supportsDraftRunOnce,
67
85
  supportsDraftAttachments: local.supportsDraftAttachments ?? config.supportsDraftAttachments,
68
- supportsDraftImageAttachments: local.supportsDraftImageAttachments ?? config.supportsDraftImageAttachments
86
+ supportsDraftImageAttachments: local.supportsDraftImageAttachments ?? config.supportsDraftImageAttachments,
87
+ localYieldFlagPath: resolveLocalYieldFlagPath(),
88
+ bridgeStatePath: resolveBridgeStatePath()
69
89
  };
70
90
  }
91
+ /** Where `forge-bridge connect` publishes whether it is idle: `bridge.state.json` beside the config. */
92
+ export function resolveBridgeStatePath() {
93
+ return bridgeStatePathFor(resolveLocalConfigPath());
94
+ }
95
+ /** Decision 0014: the `forge-bridge yield` flag, beside the bridge config and never inside it. */
96
+ export function resolveLocalYieldFlagPath() {
97
+ return localYieldFlagPathFor(resolveLocalConfigPath());
98
+ }
71
99
  export async function addRepoMapping(label, repoPath) {
72
100
  const normalizedLabel = normalizeLabel(label);
73
101
  const localPath = path.resolve(repoPath);
@@ -0,0 +1,10 @@
1
+ export interface CliProviderDetection {
2
+ readonly provider: string;
3
+ readonly found: boolean;
4
+ readonly version: string;
5
+ readonly models: readonly string[];
6
+ }
7
+ export declare function detectCliProviders(providers: readonly string[]): Promise<CliProviderDetection[]>;
8
+ export declare const claudeDefaultModels: readonly string[];
9
+ export declare function parseCodexModelCatalog(raw: string): string[];
10
+ export declare function parseCursorModelList(raw: string): string[];
@@ -0,0 +1,160 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ import { resolveCursorAgentDirectLaunch } from "../shared/cursor-agent/cursor-agent.launch.js";
4
+ import { buildWindowsCmdLaunch } from "../shared/process/windows-launch.js";
5
+ // Provider CLI detection probes for `forge-bridge status`, `connect` and `pair`: which
6
+ // provider CLIs are installed, their versions and the models they list. Split out of
7
+ // cli.service.ts (file-size inventory plan).
8
+ const execFileAsync = promisify(execFile);
9
+ export async function detectCliProviders(providers) {
10
+ const results = [];
11
+ for (const provider of providers) {
12
+ let detected = null;
13
+ for (const probe of cliProbeCommandsFor(provider)) {
14
+ try {
15
+ detected = await execVersionCommand(probe, probe.timeoutMs);
16
+ break;
17
+ }
18
+ catch {
19
+ // Try the next provider-specific probe.
20
+ }
21
+ }
22
+ results.push({
23
+ provider,
24
+ found: detected !== null,
25
+ version: detected ? versionLine(`${detected.stdout || detected.stderr}`) : "",
26
+ models: detected ? await detectCliModels(provider) : []
27
+ });
28
+ }
29
+ return results;
30
+ }
31
+ function cliProbeCommandsFor(provider) {
32
+ const normalized = provider.toLowerCase();
33
+ if (normalized === "codex") {
34
+ return [
35
+ { command: "codex", args: ["-V"] },
36
+ { command: "codex", args: ["--version"] }
37
+ ];
38
+ }
39
+ if (normalized === "claude") {
40
+ return [
41
+ // Claude Code's Node startup can exceed the default 2s probe on a cold Windows host.
42
+ { command: "claude", args: ["--version"], timeoutMs: 8000 },
43
+ { command: "claude", args: ["-v"], timeoutMs: 8000 }
44
+ ];
45
+ }
46
+ if (normalized === "cursor") {
47
+ return [
48
+ { command: "cursor-agent", args: ["-v"] },
49
+ { command: "agent", args: ["-v"] },
50
+ { command: "cursor-agent", args: ["--version"] },
51
+ { command: "agent", args: ["--version"] }
52
+ ];
53
+ }
54
+ return [
55
+ { command: provider, args: ["--version"] },
56
+ { command: provider, args: ["-V"] }
57
+ ];
58
+ }
59
+ async function execVersionCommand(probe, timeout = 2000, maxBuffer) {
60
+ const directLaunch = process.platform === "win32"
61
+ ? await resolveCursorAgentDirectLaunch(probe.command, probe.args)
62
+ : null;
63
+ if (directLaunch) {
64
+ return await execFileAsync(directLaunch.command, [...directLaunch.args], { timeout, maxBuffer });
65
+ }
66
+ try {
67
+ return await execFileAsync(probe.command, probe.args, { timeout, maxBuffer });
68
+ }
69
+ catch (error) {
70
+ if (process.platform !== "win32") {
71
+ throw error;
72
+ }
73
+ const launch = buildWindowsCmdLaunch(probe.command, probe.args);
74
+ return await execFileAsync(launch.command, [...launch.args], { timeout, maxBuffer });
75
+ }
76
+ }
77
+ function versionLine(output) {
78
+ const lines = output
79
+ .trim()
80
+ .split(/\r?\n/)
81
+ .map((line) => line.trim())
82
+ .filter((line) => line.length > 0);
83
+ return lines.at(-1) ?? "";
84
+ }
85
+ async function detectCliModels(provider) {
86
+ const normalized = provider.toLowerCase();
87
+ try {
88
+ if (normalized === "codex") {
89
+ // Windows installs codex as a .cmd shim, which execFile cannot launch directly.
90
+ const result = await execVersionCommand({ command: "codex", args: ["debug", "models"] }, 10_000, 10 * 1024 * 1024);
91
+ return parseCodexModelCatalog(result.stdout);
92
+ }
93
+ if (normalized === "cursor") {
94
+ const result = await execVersionCommand({ command: "cursor-agent", args: ["models"] }, 10_000);
95
+ return parseCursorModelList(`${result.stdout || result.stderr}`);
96
+ }
97
+ if (normalized === "claude") {
98
+ // Claude Code has no model-listing command; it accepts these aliases and full model IDs.
99
+ const configured = (process.env.FORGE_CLAUDE_MODELS ?? "").split(",").map(model => model.trim()).filter(Boolean);
100
+ return configured.length > 0 ? configured : [...claudeDefaultModels];
101
+ }
102
+ }
103
+ catch {
104
+ return [];
105
+ }
106
+ return [];
107
+ }
108
+ export const claudeDefaultModels = ["sonnet", "opus", "haiku"];
109
+ export function parseCodexModelCatalog(raw) {
110
+ try {
111
+ const parsed = JSON.parse(raw);
112
+ if (!isRecord(parsed) || !Array.isArray(parsed.models)) {
113
+ return [];
114
+ }
115
+ const entries = parsed.models
116
+ .map((entry, index) => {
117
+ if (!isRecord(entry) || typeof entry.slug !== "string") {
118
+ return null;
119
+ }
120
+ const visibility = typeof entry.visibility === "string" ? entry.visibility.toLowerCase() : "list";
121
+ if (visibility !== "list") {
122
+ return null;
123
+ }
124
+ const priority = typeof entry.priority === "number" && Number.isFinite(entry.priority) ? entry.priority : index;
125
+ return { slug: entry.slug, priority, index };
126
+ })
127
+ .filter((entry) => entry !== null)
128
+ .sort((left, right) => left.priority - right.priority || left.index - right.index)
129
+ .map((entry) => entry.slug);
130
+ return uniqueModels(entries);
131
+ }
132
+ catch {
133
+ return [];
134
+ }
135
+ }
136
+ export function parseCursorModelList(raw) {
137
+ return uniqueModels(raw
138
+ .split(/\r?\n/)
139
+ .map((line) => line.trim())
140
+ .filter((line) => line.length > 0 && !line.toLowerCase().startsWith("available models"))
141
+ .map((line) => line.split(/\s+-\s+/, 1)[0]?.trim() ?? "")
142
+ .filter((model) => model.length > 0));
143
+ }
144
+ function uniqueModels(models) {
145
+ const seen = new Set();
146
+ const result = [];
147
+ for (const model of models) {
148
+ const trimmed = model.trim();
149
+ const key = trimmed.toLowerCase();
150
+ if (!trimmed || seen.has(key)) {
151
+ continue;
152
+ }
153
+ seen.add(key);
154
+ result.push(trimmed);
155
+ }
156
+ return result;
157
+ }
158
+ function isRecord(value) {
159
+ return typeof value === "object" && value !== null;
160
+ }
@@ -1,3 +1,4 @@
1
+ import type { AttemptProcessSupervisor } from "./attempt-process-supervisor.js";
1
2
  export interface AspNetRuntimePrebuildPlan {
2
3
  readonly fingerprint: string;
3
4
  readonly receiptPath: string;
@@ -6,9 +7,24 @@ export interface AspNetRuntimePrebuildPlan {
6
7
  readonly cwd: string;
7
8
  readonly environment: Readonly<Record<string, string>>;
8
9
  readonly projectPath: string;
10
+ /** Where the runtime's build output lands and what its receipt verifies: the project's `bin` unless the launch chooses an output. */
11
+ readonly outputDirectory: string;
9
12
  readonly worktreePath: string;
10
13
  readonly inputCommitSha: string;
11
14
  }
15
+ /**
16
+ * The configured launch arguments of a supervised project. An ASP.NET runtime gets its own
17
+ * build output (isolatedRuntimeOutputArguments): its prebuild and `dotnet run` both use it, so an
18
+ * agent's build of the same project writes the default output and never the running runtime's.
19
+ */
20
+ export declare function supervisedRuntimeLaunchArguments(port: {
21
+ readonly name: string;
22
+ readonly adapter: string | null;
23
+ readonly launch: {
24
+ readonly command: string;
25
+ readonly args: readonly string[];
26
+ };
27
+ }): readonly string[];
12
28
  export interface AspNetRuntimePrebuildResult {
13
29
  readonly cacheHit: boolean;
14
30
  readonly receiptPath: string;
@@ -22,6 +38,10 @@ export interface AspNetRuntimeBuildExecutionResult {
22
38
  readonly stderrLogPath: string;
23
39
  }
24
40
  export type AspNetRuntimeBuildExecutor = (plan: AspNetRuntimePrebuildPlan, signal?: AbortSignal) => Promise<AspNetRuntimeBuildExecutionResult>;
41
+ /** Runs one ASP.NET runtime build under the attempt's supervisor, logging only redacted output. */
42
+ export declare function executeAspNetRuntimeBuild(supervisor: AttemptProcessSupervisor, logDirectory: string, plan: AspNetRuntimePrebuildPlan, signal?: AbortSignal, exactSecrets?: readonly string[],
43
+ /** Once the build's supervised tree is up: records it on the build's host load token. */
44
+ onStarted?: (metadataPath: string) => Promise<void>): Promise<AspNetRuntimeBuildExecutionResult>;
25
45
  export declare function createAspNetRuntimePrebuildPlan(options: {
26
46
  readonly command: string;
27
47
  readonly args: readonly string[];