@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.0f8fb73715e8

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 (329) hide show
  1. package/README.md +183 -4
  2. package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
  3. package/dist/bridge/bridge-chat-giphy-look.js +55 -0
  4. package/dist/bridge/bridge-chat-provider-command.d.ts +40 -0
  5. package/dist/bridge/bridge-chat-provider-command.js +230 -0
  6. package/dist/bridge/bridge-chat.types.d.ts +20 -0
  7. package/dist/bridge/bridge-chat.types.js +28 -1
  8. package/dist/bridge/bridge-state-file.d.ts +161 -0
  9. package/dist/bridge/bridge-state-file.js +376 -0
  10. package/dist/bridge/bridge-state-io.d.ts +15 -0
  11. package/dist/bridge/bridge-state-io.js +68 -0
  12. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  13. package/dist/bridge/bridge-state-lock.js +102 -0
  14. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  15. package/dist/bridge/bridge-state-unpublished.js +111 -0
  16. package/dist/bridge/bridge.base.d.ts +9 -0
  17. package/dist/bridge/bridge.service.d.ts +102 -14
  18. package/dist/bridge/bridge.service.js +499 -471
  19. package/dist/bridge/bridge.types.d.ts +37 -0
  20. package/dist/bridge/bridge.types.js +2 -1
  21. package/dist/bridge/default-session-service.d.ts +13 -0
  22. package/dist/bridge/default-session-service.js +22 -0
  23. package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
  24. package/dist/bridge/dispatch-offer-policy.js +58 -0
  25. package/dist/bridge/in-flight-registry.d.ts +62 -0
  26. package/dist/bridge/in-flight-registry.js +207 -0
  27. package/dist/bridge/local-yield-flag.d.ts +6 -0
  28. package/dist/bridge/local-yield-flag.js +34 -0
  29. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  30. package/dist/bridge/readiness-result-outbox.js +20 -0
  31. package/dist/bridge/runner-host-capabilities.d.ts +5 -0
  32. package/dist/bridge/runner-host-capabilities.js +31 -1
  33. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  34. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  35. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  36. package/dist/bridge/test-postgres-capability.js +120 -0
  37. package/dist/bridge/windows-bash-resolution.d.ts +31 -0
  38. package/dist/bridge/windows-bash-resolution.js +153 -0
  39. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  40. package/dist/cleanup/cleanup-wip.js +66 -0
  41. package/dist/cleanup/cleanup.service.d.ts +20 -1
  42. package/dist/cleanup/cleanup.service.js +150 -169
  43. package/dist/cleanup/cleanup.types.d.ts +6 -0
  44. package/dist/cleanup/forge-owned-paths.d.ts +11 -0
  45. package/dist/cleanup/forge-owned-paths.js +62 -0
  46. package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
  47. package/dist/cleanup/host-runtime-ledger.js +130 -0
  48. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  49. package/dist/cleanup/managed-branch-sweep.js +111 -0
  50. package/dist/cli/cli.help.js +75 -13
  51. package/dist/cli/cli.service.d.ts +19 -10
  52. package/dist/cli/cli.service.js +161 -228
  53. package/dist/cli/idle-status.d.ts +84 -0
  54. package/dist/cli/idle-status.js +181 -0
  55. package/dist/cli/local-config.d.ts +18 -1
  56. package/dist/cli/local-config.js +67 -5
  57. package/dist/cli/provider-cli-advertising.d.ts +24 -0
  58. package/dist/cli/provider-cli-advertising.js +88 -0
  59. package/dist/cli/provider-cli-detection.d.ts +10 -0
  60. package/dist/cli/provider-cli-detection.js +160 -0
  61. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  62. package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
  63. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  64. package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
  65. package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
  66. package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
  67. package/dist/runtime/attempt-process-supervisor.js +12 -6
  68. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  69. package/dist/runtime/docker-engine-probe.js +7 -0
  70. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  71. package/dist/runtime/dotnet-build-outputs.js +402 -0
  72. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  73. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  74. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  75. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  76. package/dist/runtime/host-facts.d.ts +2 -1
  77. package/dist/runtime/host-listener-inspector.d.ts +26 -0
  78. package/dist/runtime/host-listener-inspector.js +84 -3
  79. package/dist/runtime/host-load-admission.d.ts +72 -0
  80. package/dist/runtime/host-load-admission.js +99 -0
  81. package/dist/runtime/host-load-capacity.d.ts +198 -0
  82. package/dist/runtime/host-load-capacity.js +353 -0
  83. package/dist/runtime/host-load-child-environment.d.ts +40 -0
  84. package/dist/runtime/host-load-child-environment.js +110 -0
  85. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  86. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  87. package/dist/runtime/host-load-governor-config.d.ts +82 -0
  88. package/dist/runtime/host-load-governor-config.js +104 -0
  89. package/dist/runtime/host-load-governor.d.ts +273 -0
  90. package/dist/runtime/host-load-governor.js +831 -0
  91. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  92. package/dist/runtime/host-load-ledger-lock.js +187 -0
  93. package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
  94. package/dist/runtime/host-load-live-test-slots.js +193 -0
  95. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  96. package/dist/runtime/host-load-runtime-settings.js +80 -0
  97. package/dist/runtime/host-load-sampler.d.ts +92 -2
  98. package/dist/runtime/host-load-sampler.js +166 -8
  99. package/dist/runtime/host-load-step-class.d.ts +70 -0
  100. package/dist/runtime/host-load-step-class.js +161 -0
  101. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  102. package/dist/runtime/host-load-step-reaper.js +95 -0
  103. package/dist/runtime/host-load-step-run.d.ts +107 -0
  104. package/dist/runtime/host-load-step-run.js +158 -0
  105. package/dist/runtime/host-load-test-slot.d.ts +46 -0
  106. package/dist/runtime/host-load-test-slot.js +100 -0
  107. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  108. package/dist/runtime/host-load-token-ledger.js +453 -0
  109. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  110. package/dist/runtime/host-load-windows-cpu.js +85 -0
  111. package/dist/runtime/host-pressure-stall.d.ts +21 -1
  112. package/dist/runtime/host-pressure-stall.js +48 -1
  113. package/dist/runtime/host-runtime-contract.d.ts +15 -0
  114. package/dist/runtime/host-runtime-contract.js +39 -6
  115. package/dist/runtime/host-runtime-lease.d.ts +101 -6
  116. package/dist/runtime/host-runtime-lease.js +408 -294
  117. package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
  118. package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
  119. package/dist/runtime/host-runtime-promotion.d.ts +101 -2
  120. package/dist/runtime/host-runtime-promotion.js +355 -14
  121. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  122. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  123. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  124. package/dist/runtime/host-runtime-requirements.js +117 -0
  125. package/dist/runtime/managed-command-teardown.js +5 -16
  126. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  127. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  128. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  129. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  130. package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
  131. package/dist/runtime/prepared-runtime-identity.js +130 -9
  132. package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
  133. package/dist/runtime/prepared-runtime-readiness.js +89 -18
  134. package/dist/runtime/runner-settings.d.ts +104 -0
  135. package/dist/runtime/runner-settings.js +236 -0
  136. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  137. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  138. package/dist/sandbox/host-capacity-broker.d.ts +115 -0
  139. package/dist/sandbox/host-capacity-broker.js +336 -0
  140. package/dist/sandbox/managed-branch.d.ts +13 -0
  141. package/dist/sandbox/managed-branch.js +90 -0
  142. package/dist/sandbox/provider-auth/codex.js +11 -11
  143. package/dist/sandbox/runtime.d.ts +11 -3
  144. package/dist/sandbox/runtime.js +53 -20
  145. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  146. package/dist/sandbox/sandbox-cgroups.js +42 -0
  147. package/dist/sandbox/sandbox-input.d.ts +22 -0
  148. package/dist/sandbox/sandbox-input.js +49 -0
  149. package/dist/sandbox/workspace.service.js +15 -2
  150. package/dist/session/architect-waits.d.ts +2 -0
  151. package/dist/session/architect-waits.js +138 -0
  152. package/dist/session/managed-attempt-tools.d.ts +2 -7
  153. package/dist/session/managed-attempt-tools.js +204 -141
  154. package/dist/session/managed-build-coordinator.d.ts +16 -0
  155. package/dist/session/managed-build-coordinator.js +10 -0
  156. package/dist/session/managed-build-receipt.d.ts +7 -0
  157. package/dist/session/managed-build-receipt.js +11 -3
  158. package/dist/session/managed-command-environment.d.ts +8 -0
  159. package/dist/session/managed-command-environment.js +28 -0
  160. package/dist/session/managed-command-host-load.d.ts +52 -0
  161. package/dist/session/managed-command-host-load.js +87 -0
  162. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  163. package/dist/session/mcp-argument-coercion.js +121 -0
  164. package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
  165. package/dist/session/phase-completion.artifact-bundle.js +167 -0
  166. package/dist/session/phase-completion.artifacts.d.ts +9 -17
  167. package/dist/session/phase-completion.artifacts.js +158 -190
  168. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  169. package/dist/session/phase-completion.command-validation.js +77 -0
  170. package/dist/session/phase-completion.d.ts +31 -2
  171. package/dist/session/phase-completion.helpers.js +18 -65
  172. package/dist/session/phase-completion.js +19 -32
  173. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  174. package/dist/session/phase-completion.mcp-args.js +195 -0
  175. package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
  176. package/dist/session/phase-completion.phase-aliases.js +43 -0
  177. package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
  178. package/dist/session/phase-completion.pr-review-schema.js +75 -0
  179. package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
  180. package/dist/session/phase-completion.pr-review-validation.js +212 -0
  181. package/dist/session/phase-completion.pr-review.d.ts +36 -0
  182. package/dist/session/phase-completion.pr-review.js +294 -0
  183. package/dist/session/phase-completion.prompts.d.ts +1 -1
  184. package/dist/session/phase-completion.prompts.js +20 -1
  185. package/dist/session/phase-completion.runtime.d.ts +13 -12
  186. package/dist/session/phase-completion.runtime.js +113 -214
  187. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  188. package/dist/session/phase-completion.schema-parts.js +188 -0
  189. package/dist/session/phase-completion.schemas.d.ts +3 -3
  190. package/dist/session/phase-completion.schemas.js +219 -232
  191. package/dist/session/phase-completion.validation.d.ts +3 -3
  192. package/dist/session/phase-completion.validation.js +58 -94
  193. package/dist/session/pr-review-diff-base.d.ts +18 -0
  194. package/dist/session/pr-review-diff-base.js +44 -0
  195. package/dist/session/pr-review-placement.d.ts +50 -0
  196. package/dist/session/pr-review-placement.js +91 -0
  197. package/dist/session/pre-publication-change-set.d.ts +62 -0
  198. package/dist/session/pre-publication-change-set.js +166 -0
  199. package/dist/session/pre-publication-host-load.d.ts +27 -0
  200. package/dist/session/pre-publication-host-load.js +112 -0
  201. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  202. package/dist/session/pre-publication-native-postgres.js +111 -0
  203. package/dist/session/pre-publication-pass.d.ts +61 -0
  204. package/dist/session/pre-publication-pass.js +148 -0
  205. package/dist/session/pre-publication-process.d.ts +3 -0
  206. package/dist/session/pre-publication-process.js +32 -19
  207. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  208. package/dist/session/pre-publication-step-execution.js +50 -0
  209. package/dist/session/pre-publication-validation.d.ts +39 -22
  210. package/dist/session/pre-publication-validation.js +241 -207
  211. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  212. package/dist/session/provider-cli/claude-background-work.js +181 -0
  213. package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
  214. package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
  215. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  216. package/dist/session/provider-cli/host-build-lock.js +30 -0
  217. package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
  218. package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
  219. package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
  220. package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
  221. package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
  222. package/dist/session/provider-cli/pr-review-prompt.js +119 -0
  223. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  224. package/dist/session/provider-cli/pre-publication-repair.js +281 -0
  225. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  226. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  227. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  228. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  229. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  230. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
  231. package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
  232. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
  233. package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
  234. package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
  235. package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
  236. package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
  237. package/dist/session/provider-cli/provider-cli.process.js +41 -432
  238. package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -3
  239. package/dist/session/provider-cli/provider-cli.prompts.js +183 -90
  240. package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
  241. package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
  242. package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
  243. package/dist/session/provider-cli/provider-cli.runtime.js +43 -1
  244. package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
  245. package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
  246. package/dist/session/provider-cli/provider-cli.service.d.ts +18 -18
  247. package/dist/session/provider-cli/provider-cli.service.js +127 -317
  248. package/dist/session/provider-cli/provider-cli.types.d.ts +35 -0
  249. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  250. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  251. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  252. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  253. package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
  254. package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
  255. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  256. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  257. package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
  258. package/dist/session/provider-cli/provider-output-state.js +6 -0
  259. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  260. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  261. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  262. package/dist/session/qa-sidecar-validation.js +28 -0
  263. package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
  264. package/dist/session/sandbox-host-capacity-gate.js +279 -0
  265. package/dist/session/session-host-project.d.ts +22 -0
  266. package/dist/session/session-host-project.js +98 -0
  267. package/dist/session/session-redaction.js +31 -181
  268. package/dist/session/session.base.d.ts +9 -1
  269. package/dist/session/session.parse-helpers.d.ts +10 -0
  270. package/dist/session/session.parse-helpers.js +84 -0
  271. package/dist/session/session.runtime-refresh.d.ts +46 -0
  272. package/dist/session/session.runtime-refresh.js +116 -0
  273. package/dist/session/session.service.d.ts +16 -2
  274. package/dist/session/session.service.js +208 -155
  275. package/dist/session/session.types.d.ts +8 -0
  276. package/dist/session/session.types.js +13 -83
  277. package/dist/session/session.types.pr-review.d.ts +48 -0
  278. package/dist/session/session.types.pr-review.js +51 -0
  279. package/dist/session/sidecar-json-shape.d.ts +31 -0
  280. package/dist/session/sidecar-json-shape.js +217 -0
  281. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  282. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  283. package/dist/shared/fs/file-identity.d.ts +10 -0
  284. package/dist/shared/fs/file-identity.js +15 -0
  285. package/dist/shared/fs/replace-file.d.ts +7 -0
  286. package/dist/shared/fs/replace-file.js +33 -0
  287. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  288. package/dist/shared/process/host-process-recovery.js +23 -3
  289. package/dist/shared/process/host-process-supervisor.d.ts +14 -1
  290. package/dist/shared/process/host-process-supervisor.js +67 -15
  291. package/dist/shared/process/process-tree.d.ts +52 -0
  292. package/dist/shared/process/process-tree.js +144 -0
  293. package/dist/shared/process/process.d.ts +67 -0
  294. package/dist/shared/process/process.js +213 -11
  295. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  296. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  297. package/dist/shared/process/windows-launch.d.ts +18 -0
  298. package/dist/shared/process/windows-launch.js +68 -0
  299. package/dist/shared/provider-capabilities.d.ts +2 -0
  300. package/dist/shared/provider-capabilities.js +23 -7
  301. package/dist/version.d.ts +1 -1
  302. package/dist/version.js +1 -1
  303. package/dist/worktree/artifact-injector.js +24 -0
  304. package/dist/worktree/dependency-warmer.d.ts +25 -0
  305. package/dist/worktree/dependency-warmer.js +46 -10
  306. package/dist/worktree/orphan-relink.d.ts +19 -0
  307. package/dist/worktree/orphan-relink.js +106 -0
  308. package/dist/worktree/wip-git.d.ts +58 -0
  309. package/dist/worktree/wip-git.js +182 -0
  310. package/dist/worktree/wip-refs.d.ts +85 -0
  311. package/dist/worktree/wip-refs.js +169 -0
  312. package/dist/worktree/wip-restore.d.ts +51 -0
  313. package/dist/worktree/wip-restore.js +324 -0
  314. package/dist/worktree/wip-snapshot.d.ts +53 -0
  315. package/dist/worktree/wip-snapshot.js +270 -0
  316. package/dist/worktree/worktree-inputs.d.ts +8 -0
  317. package/dist/worktree/worktree-inputs.js +134 -0
  318. package/dist/worktree/worktree-origin-sync.d.ts +35 -0
  319. package/dist/worktree/worktree-origin-sync.js +128 -0
  320. package/dist/worktree/worktree-wip-events.d.ts +20 -0
  321. package/dist/worktree/worktree-wip-events.js +148 -0
  322. package/dist/worktree/worktree-wip.d.ts +57 -0
  323. package/dist/worktree/worktree-wip.js +200 -0
  324. package/dist/worktree/worktree.base.d.ts +7 -1
  325. package/dist/worktree/worktree.service.d.ts +58 -5
  326. package/dist/worktree/worktree.service.js +237 -161
  327. package/dist/worktree/worktree.types.d.ts +54 -0
  328. package/package.json +2 -2
  329. package/runtime/windows-listener-owner.ps1 +12 -1
@@ -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[];
@@ -3,7 +3,63 @@ import { spawn } from "node:child_process";
3
3
  import fs from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import { ForgeFailureError } from "../session/session.types.js";
6
+ import { redactText } from "../shared/redaction/redaction.js";
7
+ import { replaceFile } from "../shared/fs/replace-file.js";
8
+ import { canonicalExistingPathSync, declaresDotnetOutput, isolatedRuntimeOutputArguments, parseDotnetOutputCommand, projectOutputRoot, projectReferenceIncludes, } from "./dotnet-build-outputs.js";
9
+ /**
10
+ * The configured launch arguments of a supervised project. An ASP.NET runtime gets its own
11
+ * build output (isolatedRuntimeOutputArguments): its prebuild and `dotnet run` both use it, so an
12
+ * agent's build of the same project writes the default output and never the running runtime's.
13
+ */
14
+ export function supervisedRuntimeLaunchArguments(port) {
15
+ return port.adapter === "aspnetcore"
16
+ ? isolatedRuntimeOutputArguments(port.launch.command, port.launch.args, port.name)
17
+ : port.launch.args;
18
+ }
6
19
  const inFlightPrebuilds = new Map();
20
+ /** Runs one ASP.NET runtime build under the attempt's supervisor, logging only redacted output. */
21
+ export async function executeAspNetRuntimeBuild(supervisor, logDirectory, plan, signal, exactSecrets = [],
22
+ /** Once the build's supervised tree is up: records it on the build's host load token. */
23
+ onStarted) {
24
+ const childName = `runtime-build-${plan.fingerprint.slice(-12)}`;
25
+ const stdoutLogPath = path.join(logDirectory, `${childName}.stdout.log`);
26
+ const stderrLogPath = path.join(logDirectory, `${childName}.stderr.log`);
27
+ let stdoutTail = "";
28
+ let stderrTail = "";
29
+ const append = async (target, line) => {
30
+ await fs.appendFile(target, `${redactText(line, exactSecrets)}\n`, { encoding: "utf8", mode: 0o600 });
31
+ };
32
+ const child = await supervisor.startChildReady(childName, {
33
+ command: plan.command,
34
+ args: plan.args,
35
+ cwd: plan.cwd,
36
+ env: plan.environment,
37
+ captureOutput: false,
38
+ }, {
39
+ onStdoutLine: async (line) => {
40
+ stdoutTail = appendRuntimeBuildTail(stdoutTail, redactText(line, exactSecrets));
41
+ await append(stdoutLogPath, line);
42
+ },
43
+ onStderrLine: async (line) => {
44
+ stderrTail = appendRuntimeBuildTail(stderrTail, redactText(line, exactSecrets));
45
+ await append(stderrLogPath, line);
46
+ },
47
+ }, signal, { maxStartAttempts: 2, retryDelayMs: 250 });
48
+ await onStarted?.(child.metadataPath);
49
+ const result = await child.result;
50
+ return {
51
+ exitCode: result.exitCode,
52
+ stdoutTail: appendRuntimeBuildTail(stdoutTail, redactText(result.stdout, exactSecrets)),
53
+ stderrTail: appendRuntimeBuildTail(stderrTail, redactText(result.stderr, exactSecrets)),
54
+ stdoutLogPath,
55
+ stderrLogPath,
56
+ };
57
+ }
58
+ function appendRuntimeBuildTail(current, value) {
59
+ if (!value)
60
+ return current;
61
+ return `${current}${current ? "\n" : ""}${value}`.slice(-4_000);
62
+ }
7
63
  export function createAspNetRuntimePrebuildPlan(options) {
8
64
  if (!isDotnetRun(options.command, options.args))
9
65
  return null;
@@ -34,18 +90,46 @@ export function createAspNetRuntimePrebuildPlan(options) {
34
90
  args: buildArgs,
35
91
  environment: buildEnvironmentContract(options.environment ?? {}),
36
92
  })).digest("hex")}`;
93
+ const outputDirectory = runtimeOutputDirectory(options, projectPath, projectDirectory, normalizedWorktree);
94
+ // A chosen output (the isolated OutDir, or the launch's own) keeps its own receipt, verifying only its own files.
95
+ const receiptName = outputDirectory === path.join(projectDirectory, "bin")
96
+ ? ".forge-runtime-build.json"
97
+ : `.forge-runtime-build.${createHash("sha256").update(path.relative(projectDirectory, outputDirectory).replaceAll("\\", "/")).digest("hex").slice(0, 12)}.json`;
37
98
  return {
38
99
  fingerprint,
39
- receiptPath: path.join(projectDirectory, "obj", ".forge-runtime-build.json"),
100
+ receiptPath: path.join(projectDirectory, "obj", receiptName),
40
101
  command: options.command,
41
102
  args: buildArgs,
42
103
  cwd: options.cwd,
43
104
  environment: options.environment ?? {},
44
105
  projectPath,
106
+ outputDirectory,
45
107
  worktreePath: normalizedWorktree,
46
108
  inputCommitSha: options.inputCommitSha,
47
109
  };
48
110
  }
111
+ /**
112
+ * Where the runtime's prebuild writes and its `dotnet run --no-build` reads: the launch's own
113
+ * output choice when it makes one (forwardBuildOptions passes it to the build unchanged), otherwise
114
+ * the project's `bin`. A choice the two commands cannot share, or one outside the worktree, is refused.
115
+ */
116
+ function runtimeOutputDirectory(options, projectPath, projectDirectory, worktreePath) {
117
+ const settings = parseDotnetOutputCommand(options.command, options.args, options.cwd, { holder: true })?.settings;
118
+ if (!settings || !declaresDotnetOutput(settings))
119
+ return path.join(projectDirectory, "bin");
120
+ if (settings.output) {
121
+ throw new Error("host_runtime_build_invalid: dotnet run has no --output option, so its prebuild and run could not share that "
122
+ + "directory. Choose the runtime's output with -p:OutDir=<dir>, -p:BaseOutputPath=<dir>, or --artifacts-path <dir> instead.");
123
+ }
124
+ const projectFile = path.extname(projectPath).toLowerCase() === ".csproj" ? projectPath : null;
125
+ const outputDirectory = projectOutputRoot(projectDirectory, projectFile, settings);
126
+ // By real location: a symlink or junction inside the worktree must not carry the output outside it.
127
+ const relative = path.relative(canonicalExistingPathSync(worktreePath), canonicalExistingPathSync(outputDirectory));
128
+ if (relative.startsWith("..") || path.isAbsolute(relative)) {
129
+ throw new Error(`host_runtime_build_invalid: the ASP.NET runtime's build output ${outputDirectory} must remain inside the managed worktree.`);
130
+ }
131
+ return outputDirectory;
132
+ }
49
133
  export async function ensureAspNetRuntimePrebuilt(plan, execute, signal) {
50
134
  const pending = inFlightPrebuilds.get(plan.receiptPath);
51
135
  if (pending)
@@ -101,7 +185,7 @@ async function ensureAspNetRuntimePrebuiltCore(plan, execute, signal) {
101
185
  };
102
186
  await fs.writeFile(temporaryReceipt, `${JSON.stringify(nextReceipt)}\n`, { encoding: "utf8", mode: 0o600 });
103
187
  try {
104
- await fs.rename(temporaryReceipt, plan.receiptPath);
188
+ await replaceFile(temporaryReceipt, plan.receiptPath);
105
189
  }
106
190
  finally {
107
191
  await fs.rm(temporaryReceipt, { force: true }).catch(() => undefined);
@@ -158,9 +242,12 @@ function readOptionValue(args, option) {
158
242
  const argument = args[index];
159
243
  return argument.startsWith(`${option}=`) ? argument.slice(option.length + 1) : args[index + 1] ?? null;
160
244
  }
245
+ /** The launch's build-shaping options, output choices included, so the prebuild writes where the run reads. */
161
246
  function forwardBuildOptions(args) {
162
247
  const forwarded = [];
163
- const optionsWithValues = new Set(["-c", "--configuration", "-f", "--framework", "-r", "--runtime", "--arch", "--os"]);
248
+ const optionsWithValues = new Set([
249
+ "-c", "--configuration", "-f", "--framework", "-r", "--runtime", "--arch", "--os", "--artifacts-path",
250
+ ]);
164
251
  for (let index = 1; index < args.length; index += 1) {
165
252
  const argument = args[index];
166
253
  if (argument === "--")
@@ -179,9 +266,9 @@ function forwardBuildOptions(args) {
179
266
  }
180
267
  continue;
181
268
  }
269
+ // Every MSBuild property spelling: -p:, --property:, /p:, and the rest that dotnet accepts.
182
270
  if ([...optionsWithValues].some(option => argument.startsWith(`${option}=`))
183
- || argument.startsWith("-p:")
184
- || argument.startsWith("/p:")) {
271
+ || /^(?:-{1,2}|\/)(?:p|property):/iu.test(argument)) {
185
272
  forwarded.push(argument);
186
273
  }
187
274
  }
@@ -211,7 +298,7 @@ async function aspNetBuildInputs(plan) {
211
298
  const projectDirectory = path.extname(plan.projectPath).toLowerCase() === ".csproj"
212
299
  ? path.dirname(plan.projectPath)
213
300
  : plan.projectPath;
214
- const sourceDigest = await directoryContentDigest(projectDirectory);
301
+ const sourceDigest = await projectSourceDigest(plan, projectDirectory);
215
302
  const dependencyReceipt = path.join(projectDirectory, "obj", ".forge-dependency-preparation.json");
216
303
  const dependencyContent = await fs.readFile(dependencyReceipt).catch(() => null);
217
304
  const globalJson = await findAncestorFile(projectDirectory, plan.worktreePath, "global.json");
@@ -225,25 +312,104 @@ async function aspNetBuildInputs(plan) {
225
312
  sdkVersion: await dotnetSdkVersion(plan.cwd),
226
313
  };
227
314
  }
228
- async function directoryContentDigest(directory) {
229
- const files = [];
230
- await collectInputFiles(directory, directory, files);
315
+ /**
316
+ * Digest of everything the project build compiles from inside the worktree: the
317
+ * project directory, every project it references (transitively, through
318
+ * ProjectReference), and the Directory.Build/Directory.Packages files above them.
319
+ * A change in a referenced project must invalidate the receipt, or the launch
320
+ * reuses a binary built from the previous source.
321
+ */
322
+ async function projectSourceDigest(plan, projectDirectory) {
323
+ const worktree = path.resolve(plan.worktreePath);
324
+ const directories = await projectSourceDirectories(plan, projectDirectory);
325
+ const files = new Set();
326
+ // The runtime's own output is never source, even outside bin: a per-project output sits at the same place in every project.
327
+ const relativeOutput = path.relative(projectDirectory, plan.outputDirectory);
328
+ const perProjectOutput = relativeOutput !== "" && containedIn(projectDirectory, plan.outputDirectory);
329
+ for (const directory of directories) {
330
+ const collected = [];
331
+ const excluded = new Set([path.resolve(plan.outputDirectory), ...(perProjectOutput ? [path.join(directory, relativeOutput)] : [])]);
332
+ await collectInputFiles(directory, directory, collected, excluded);
333
+ for (const file of collected)
334
+ files.add(file);
335
+ for (const buildFile of await ancestorBuildFiles(directory, worktree))
336
+ files.add(buildFile);
337
+ }
231
338
  const hash = createHash("sha256");
232
- for (const file of files.sort((left, right) => left.localeCompare(right))) {
233
- hash.update(path.relative(directory, file).replaceAll("\\", "/"));
339
+ for (const file of [...files].sort((left, right) => left.localeCompare(right))) {
340
+ hash.update(path.relative(worktree, file).replaceAll("\\", "/"));
234
341
  hash.update("\0");
235
342
  hash.update(await fs.readFile(file));
236
343
  hash.update("\0");
237
344
  }
238
345
  return `sha256:${hash.digest("hex")}`;
239
346
  }
240
- async function collectInputFiles(root, directory, files) {
347
+ const msbuildProjectExtensions = new Set([".csproj", ".fsproj", ".vbproj"]);
348
+ const msbuildDirectoryFiles = ["Directory.Build.props", "Directory.Build.targets", "Directory.Packages.props"];
349
+ /** The project directory and the directories of the projects it references inside the worktree. */
350
+ async function projectSourceDirectories(plan, projectDirectory) {
351
+ const worktree = path.resolve(plan.worktreePath);
352
+ const directories = new Set([path.resolve(projectDirectory)]);
353
+ const queue = msbuildProjectExtensions.has(path.extname(plan.projectPath).toLowerCase())
354
+ ? [path.resolve(plan.projectPath)]
355
+ : await projectFilesIn(projectDirectory);
356
+ const visited = new Set();
357
+ while (queue.length > 0) {
358
+ const projectFile = queue.shift();
359
+ if (visited.has(projectFile))
360
+ continue;
361
+ visited.add(projectFile);
362
+ const content = await fs.readFile(projectFile, "utf8").catch(() => null);
363
+ if (content === null)
364
+ continue;
365
+ for (const include of projectReferenceIncludes(content)) {
366
+ // An MSBuild property cannot be resolved here; the referenced source stays outside the digest.
367
+ if (include.includes("$("))
368
+ continue;
369
+ const referenced = path.resolve(path.dirname(projectFile), include.replaceAll("\\", "/"));
370
+ if (!containedIn(worktree, referenced))
371
+ continue;
372
+ directories.add(path.dirname(referenced));
373
+ queue.push(referenced);
374
+ }
375
+ }
376
+ return [...directories];
377
+ }
378
+ async function projectFilesIn(directory) {
379
+ const entries = await fs.readdir(directory, { withFileTypes: true }).catch(() => []);
380
+ return entries
381
+ .filter(entry => entry.isFile() && msbuildProjectExtensions.has(path.extname(entry.name).toLowerCase()))
382
+ .map(entry => path.join(directory, entry.name));
383
+ }
384
+ async function ancestorBuildFiles(directory, worktree) {
385
+ const found = [];
386
+ let current = path.resolve(directory);
387
+ while (containedIn(worktree, current)) {
388
+ for (const name of msbuildDirectoryFiles) {
389
+ const candidate = path.join(current, name);
390
+ if (await fs.stat(candidate).then(stat => stat.isFile()).catch(() => false))
391
+ found.push(candidate);
392
+ }
393
+ if (current === worktree)
394
+ break;
395
+ const parent = path.dirname(current);
396
+ if (parent === current)
397
+ break;
398
+ current = parent;
399
+ }
400
+ return found;
401
+ }
402
+ function containedIn(root, candidate) {
403
+ const relative = path.relative(root, candidate);
404
+ return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
405
+ }
406
+ async function collectInputFiles(root, directory, files, excluded) {
241
407
  const entries = await fs.readdir(directory, { withFileTypes: true }).catch(() => []);
242
408
  for (const entry of entries) {
243
409
  const absolute = path.join(directory, entry.name);
244
410
  if (entry.isDirectory()) {
245
- if (!["bin", "obj", "node_modules", ".git", "TestResults"].includes(entry.name)) {
246
- await collectInputFiles(root, absolute, files);
411
+ if (!["bin", "obj", "node_modules", ".git", "TestResults"].includes(entry.name) && !excluded.has(absolute)) {
412
+ await collectInputFiles(root, absolute, files, excluded);
247
413
  }
248
414
  }
249
415
  else if (entry.isFile()) {
@@ -255,9 +421,8 @@ async function collectAspNetBuildOutputs(plan) {
255
421
  const projectDirectory = path.extname(plan.projectPath).toLowerCase() === ".csproj"
256
422
  ? path.dirname(plan.projectPath)
257
423
  : plan.projectPath;
258
- const outputRoot = path.join(projectDirectory, "bin");
259
424
  const outputs = [];
260
- await collectOutputFiles(outputRoot, projectDirectory, outputs);
425
+ await collectOutputFiles(plan.outputDirectory, projectDirectory, outputs);
261
426
  return outputs.sort((left, right) => left.path.localeCompare(right.path));
262
427
  }
263
428
  async function collectOutputFiles(directory, projectDirectory, outputs) {
@@ -283,9 +448,10 @@ async function aspNetOutputsMatch(plan, outputs) {
283
448
  ? path.dirname(plan.projectPath)
284
449
  : plan.projectPath;
285
450
  for (const output of outputs) {
451
+ // Paths are relative to the project, and may leave it for a launch-chosen output, never the plan's output directory.
286
452
  const absolute = path.resolve(projectDirectory, output.path);
287
- const relative = path.relative(projectDirectory, absolute);
288
- if (relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))
453
+ const relative = path.relative(plan.outputDirectory, absolute);
454
+ if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))
289
455
  return false;
290
456
  const stat = await fs.stat(absolute).catch(() => null);
291
457
  if (!stat?.isFile() || stat.size !== output.size)
@@ -75,7 +75,7 @@ export interface NativeTestClusterAdmin {
75
75
  readonly username: string;
76
76
  readonly password: string;
77
77
  }
78
- export declare function nativeTestClusterAdmin(fallback: NativeTestPostgresFallback): NativeTestClusterAdmin;
78
+ export declare function nativeTestClusterAdmin(fallback: Pick<NativeTestPostgresFallback, "connectionString" | "endpoint">): NativeTestClusterAdmin;
79
79
  /** Runs SQL through the psql that ships with the PostgreSQL install hosting the native test cluster. */
80
80
  export declare function psqlSqlRunner(admin: NativeTestClusterAdmin, psqlPath: string, timeoutMs?: number): AttemptDatabaseSqlRunner;
81
81
  /** psql beside the cluster's pg_ctl: FORGE_NATIVE_TEST_POSTGRES_PSQL, a Windows install, or PATH. */
@@ -1,7 +1,13 @@
1
+ import { ForgeFailureError } from "../session/session.types.js";
1
2
  import type { AttemptProcessChildHandle, AttemptProcessSupervisor } from "./attempt-process-supervisor.js";
2
3
  import type { HostPortLeaseOwner } from "./host-port-broker.js";
3
4
  import { HostListenerInspector } from "./host-listener-inspector.js";
5
+ import type { ProviderProcessHandlers, ProviderProcessRunner, ProviderProcessRunRequest, ProviderProcessRunResult } from "../session/provider-cli/provider-cli.process.js";
4
6
  import type { HostListenerOwnership, NodeRuntimeCommandLauncher, NodeRuntimeLaunchRequest, NodeRuntimeReadinessDiagnostics } from "./node-host-runtime-adapter.js";
7
+ export declare function brokeredHostPorts(ports: readonly {
8
+ readonly hostPort: number;
9
+ }[]): ReadonlySet<number>;
10
+ export declare function isolationViolationError(detail: string): ForgeFailureError;
5
11
  /** Launches one explicitly configured HTTP project beneath the attempt coordinator. */
6
12
  export declare class AttemptNodeRuntimeLauncher implements NodeRuntimeCommandLauncher<AttemptProcessChildHandle> {
7
13
  private readonly supervisor;
@@ -10,9 +16,39 @@ export declare class AttemptNodeRuntimeLauncher implements NodeRuntimeCommandLau
10
16
  private readonly listenerInspector;
11
17
  private readonly exactSecrets;
12
18
  private readonly diagnosticsByChild;
19
+ private readonly launchedChildren;
13
20
  constructor(supervisor: AttemptProcessSupervisor, owner: HostPortLeaseOwner, logDirectory: string, listenerInspector?: HostListenerInspector, exactSecrets?: readonly string[]);
14
21
  launch(request: NodeRuntimeLaunchRequest, signal?: AbortSignal): Promise<AttemptProcessChildHandle>;
15
22
  inspectListener(child: AttemptProcessChildHandle, request: NodeRuntimeLaunchRequest): Promise<HostListenerOwnership>;
23
+ /**
24
+ * Every loopback TCP port held by the process trees this launcher started that are still
25
+ * running, brokered or not. A launch the port broker retried leaves an exited child behind;
26
+ * it holds nothing and is skipped.
27
+ */
28
+ ownedListenerPorts(): Promise<readonly number[]>;
29
+ /**
30
+ * Why these process trees break isolation, or null when they do not: a listener the port
31
+ * broker did not assign, or listeners that could not be inspected (unproven isolation).
32
+ */
33
+ unbrokeredListenerViolation(brokered: ReadonlySet<number>): Promise<string | null>;
34
+ /**
35
+ * Re-audits these process trees on an interval until stopped, so a listener opened after
36
+ * readiness (say, a fixed admin port bound once a database connects) is caught within one
37
+ * interval. `brokered` returning null skips a tick. The first violation is reported once and
38
+ * ends the monitor. Returns the function that stops it.
39
+ */
40
+ monitorListeners(brokered: () => ReadonlySet<number> | null, onViolation: (detail: string) => Promise<void>): () => void;
16
41
  stop(child: AttemptProcessChildHandle): Promise<void>;
17
42
  readinessDiagnostics(child: AttemptProcessChildHandle): Promise<NodeRuntimeReadinessDiagnostics>;
18
43
  }
44
+ /** Runs a provider process beneath an attempt supervisor; an analysis-only provider may open no loopback listener. */
45
+ export declare class AttemptSupervisedProviderProcessRunner implements ProviderProcessRunner {
46
+ private readonly supervisor;
47
+ private readonly owner;
48
+ private readonly listenerInspector;
49
+ private readonly enforceNoListeners;
50
+ private readonly onProcessTreeStarted;
51
+ constructor(supervisor: AttemptProcessSupervisor, owner: HostPortLeaseOwner, listenerInspector: HostListenerInspector, enforceNoListeners: boolean, onProcessTreeStarted: () => void);
52
+ run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
53
+ private awaitProviderResult;
54
+ }
@@ -4,7 +4,14 @@ import path from "node:path";
4
4
  import { redactText } from "../shared/redaction/redaction.js";
5
5
  import { ForgeFailureError, sanitizeFailureError } from "../session/session.types.js";
6
6
  import { HostListenerInspector } from "./host-listener-inspector.js";
7
+ import { writeSupervisedRuntimeDescriptor } from "./supervised-runtime-build-guard.js";
7
8
  const diagnosticTailLength = 4_000;
9
+ export function brokeredHostPorts(ports) {
10
+ return new Set(ports.map(port => port.hostPort));
11
+ }
12
+ export function isolationViolationError(detail) {
13
+ return new ForgeFailureError("host_runtime_isolation_violation", `host_runtime_isolation_violation: ${detail}; the repository's parallel promotion was revoked and its runs are serialized until isolation is proven again.`);
14
+ }
8
15
  /** Launches one explicitly configured HTTP project beneath the attempt coordinator. */
9
16
  export class AttemptNodeRuntimeLauncher {
10
17
  supervisor;
@@ -13,6 +20,7 @@ export class AttemptNodeRuntimeLauncher {
13
20
  listenerInspector;
14
21
  exactSecrets;
15
22
  diagnosticsByChild = new WeakMap();
23
+ launchedChildren = [];
16
24
  constructor(supervisor, owner, logDirectory, listenerInspector = new HostListenerInspector(), exactSecrets = []) {
17
25
  this.supervisor = supervisor;
18
26
  this.owner = owner;
@@ -27,6 +35,14 @@ export class AttemptNodeRuntimeLauncher {
27
35
  const diagnostics = { exited: false, stdoutTail: "", stderrTail: "", outputRevision: 0 };
28
36
  let child;
29
37
  try {
38
+ // Recorded before the child starts, so a managed build can never see it running unrecorded.
39
+ await writeSupervisedRuntimeDescriptor(this.logDirectory, {
40
+ role: request.port.name,
41
+ childName,
42
+ command: request.command,
43
+ args: request.args,
44
+ cwd: request.cwd,
45
+ });
30
46
  child = await this.supervisor.startChildReady(childName, {
31
47
  command: request.command,
32
48
  args: request.args,
@@ -54,6 +70,7 @@ export class AttemptNodeRuntimeLauncher {
54
70
  }
55
71
  const exposedChild = sanitizedChildHandle(child, this.exactSecrets);
56
72
  this.diagnosticsByChild.set(exposedChild, diagnostics);
73
+ this.launchedChildren.push(exposedChild);
57
74
  void exposedChild.result.then(result => {
58
75
  diagnostics.exited = true;
59
76
  diagnostics.exitCode = result.exitCode;
@@ -70,6 +87,65 @@ export class AttemptNodeRuntimeLauncher {
70
87
  async inspectListener(child, request) {
71
88
  return await this.listenerInspector.inspect(child, request.port, this.owner);
72
89
  }
90
+ /**
91
+ * Every loopback TCP port held by the process trees this launcher started that are still
92
+ * running, brokered or not. A launch the port broker retried leaves an exited child behind;
93
+ * it holds nothing and is skipped.
94
+ */
95
+ async ownedListenerPorts() {
96
+ const ports = new Set();
97
+ for (const child of this.launchedChildren) {
98
+ if (this.diagnosticsByChild.get(child)?.exited)
99
+ continue;
100
+ for (const port of await this.listenerInspector.inspectOwnedTcpListeners(child, this.owner))
101
+ ports.add(port);
102
+ }
103
+ return [...ports].sort((left, right) => left - right);
104
+ }
105
+ /**
106
+ * Why these process trees break isolation, or null when they do not: a listener the port
107
+ * broker did not assign, or listeners that could not be inspected (unproven isolation).
108
+ */
109
+ async unbrokeredListenerViolation(brokered) {
110
+ try {
111
+ const stray = (await this.ownedListenerPorts()).filter(port => !brokered.has(port));
112
+ return stray.length === 0
113
+ ? null
114
+ : `the launched runtime listens on port(s) the port broker did not assign (${stray.join(", ")})`;
115
+ }
116
+ catch (error) {
117
+ return `the launched runtime's listeners could not be inspected (${error instanceof Error ? error.message : String(error)})`;
118
+ }
119
+ }
120
+ /**
121
+ * Re-audits these process trees on an interval until stopped, so a listener opened after
122
+ * readiness (say, a fixed admin port bound once a database connects) is caught within one
123
+ * interval. `brokered` returning null skips a tick. The first violation is reported once and
124
+ * ends the monitor. Returns the function that stops it.
125
+ */
126
+ monitorListeners(brokered, onViolation) {
127
+ let stopped = false;
128
+ let timer;
129
+ const schedule = () => {
130
+ timer = setTimeout(() => void tick(), this.listenerInspector.ownedListenerAuditIntervalMs);
131
+ timer.unref();
132
+ };
133
+ const tick = async () => {
134
+ const ports = stopped ? null : brokered();
135
+ const violation = ports === null ? null : await this.unbrokeredListenerViolation(ports);
136
+ if (stopped)
137
+ return;
138
+ if (violation === null)
139
+ return schedule();
140
+ stopped = true;
141
+ await onViolation(violation).catch(() => undefined);
142
+ };
143
+ schedule();
144
+ return () => {
145
+ stopped = true;
146
+ clearTimeout(timer);
147
+ };
148
+ }
73
149
  async stop(child) {
74
150
  await child.stop(this.owner.fencingToken);
75
151
  }
@@ -138,3 +214,96 @@ function replaceSanitizedErrorMessage(error, message) {
138
214
  function boundedDiagnostic(value) {
139
215
  return value.replaceAll(/[\r\n\t]+/gu, " ").trim().slice(-1_000);
140
216
  }
217
+ /** Runs a provider process beneath an attempt supervisor; an analysis-only provider may open no loopback listener. */
218
+ export class AttemptSupervisedProviderProcessRunner {
219
+ supervisor;
220
+ owner;
221
+ listenerInspector;
222
+ enforceNoListeners;
223
+ onProcessTreeStarted;
224
+ constructor(supervisor, owner, listenerInspector, enforceNoListeners, onProcessTreeStarted) {
225
+ this.supervisor = supervisor;
226
+ this.owner = owner;
227
+ this.listenerInspector = listenerInspector;
228
+ this.enforceNoListeners = enforceNoListeners;
229
+ this.onProcessTreeStarted = onProcessTreeStarted;
230
+ }
231
+ async run(request, handlers = {}, signal) {
232
+ const baselineListeners = this.enforceNoListeners
233
+ ? new Set(await this.listenerInspector.inspectLoopbackListeners())
234
+ : new Set();
235
+ const child = await this.supervisor.startChildReady("provider", request, handlers, signal, { maxStartAttempts: request.stdin === undefined ? 1 : 3, retryDelayMs: 100 });
236
+ this.onProcessTreeStarted();
237
+ try {
238
+ return await this.awaitProviderResult(child, baselineListeners, signal);
239
+ }
240
+ finally {
241
+ // The provider tree, and the MCP server inside it, is gone. A managed command that
242
+ // server started now has no supervisor and no receipt writer, so it must not keep
243
+ // running into the next provider generation. This never rejects; a command it
244
+ // cannot prove stopped is left to attempt teardown, which fails closed.
245
+ await this.supervisor.stopOrphanedManagedCommands();
246
+ }
247
+ }
248
+ async awaitProviderResult(child, baselineListeners, signal) {
249
+ if (!this.enforceNoListeners)
250
+ return await child.result;
251
+ let settled = false;
252
+ let inspectionFailure;
253
+ const monitor = (async () => {
254
+ while (!settled) {
255
+ try {
256
+ const ports = (await this.listenerInspector.inspectOwnedLoopbackListeners(child, this.owner))
257
+ .filter(port => !baselineListeners.has(port));
258
+ if (ports.length > 0) {
259
+ inspectionFailure = new Error(`host_analysis_listener_violation: analysis-only provider opened undeclared loopback listener(s): ${ports.join(", ")}.`);
260
+ await child.stop(this.owner.fencingToken).catch(() => undefined);
261
+ return;
262
+ }
263
+ }
264
+ catch (error) {
265
+ inspectionFailure = error;
266
+ await child.stop(this.owner.fencingToken).catch(() => undefined);
267
+ return;
268
+ }
269
+ await waitForAnalysisInspection(250, signal).catch(error => {
270
+ if (!settled && !signal?.aborted)
271
+ inspectionFailure = error;
272
+ });
273
+ }
274
+ })();
275
+ try {
276
+ const result = await child.result;
277
+ settled = true;
278
+ await monitor;
279
+ if (inspectionFailure)
280
+ throw inspectionFailure;
281
+ return result;
282
+ }
283
+ catch (error) {
284
+ settled = true;
285
+ await monitor.catch(() => undefined);
286
+ if (inspectionFailure)
287
+ throw inspectionFailure;
288
+ throw error;
289
+ }
290
+ }
291
+ }
292
+ function waitForAnalysisInspection(milliseconds, signal) {
293
+ if (signal?.aborted)
294
+ return Promise.reject(cancellationError(signal));
295
+ return new Promise((resolve, reject) => {
296
+ const timer = setTimeout(() => {
297
+ signal?.removeEventListener("abort", abort);
298
+ resolve();
299
+ }, milliseconds);
300
+ const abort = () => {
301
+ clearTimeout(timer);
302
+ reject(cancellationError(signal));
303
+ };
304
+ signal?.addEventListener("abort", abort, { once: true });
305
+ });
306
+ }
307
+ function cancellationError(signal) {
308
+ return new Error(String(signal?.reason ?? "Dispatch cancelled while waiting for host runtime singleton ownership."));
309
+ }
@@ -57,6 +57,8 @@ export interface AttemptProcessChildReadyOptions {
57
57
  readonly maxStartAttempts?: number;
58
58
  readonly retryDelayMs?: number;
59
59
  }
60
+ /** The attempt's durable child ledger; managed commands read it to find the attempt's running runtimes. */
61
+ export declare function attemptProcessSupervisorLedgerPath(logDirectory: string): string;
60
62
  /**
61
63
  * Owns the independently supervised process trees that belong to one host
62
64
  * dispatch attempt. Each named child gets a distinct Windows Job Object or
@@ -4,6 +4,10 @@ import path from "node:path";
4
4
  import { ForgeFailureError, sanitizeFailureError } from "../session/session.types.js";
5
5
  import { terminateAttemptManagedCommands, } from "./managed-command-teardown.js";
6
6
  import { monotonicNowMs } from "../shared/time/monotonic.js";
7
+ /** The attempt's durable child ledger; managed commands read it to find the attempt's running runtimes. */
8
+ export function attemptProcessSupervisorLedgerPath(logDirectory) {
9
+ return path.join(logDirectory, "attempt-process-supervisor.json");
10
+ }
7
11
  const terminalChildStatuses = new Set(["exited", "failed"]);
8
12
  const defaultMetadataReadyTimeoutMs = process.platform === "win32" ? 60_000 : 10_000;
9
13
  // Windows refuses to replace a file another process (a scanner or indexer) briefly holds
@@ -41,7 +45,7 @@ export class AttemptProcessSupervisor {
41
45
  this.replaceLedgerFile = options.replaceLedgerFile ?? ((temporaryPath, ledgerPath) => fs.rename(temporaryPath, ledgerPath));
42
46
  this.ledgerReplaceRetryMs = options.ledgerReplaceRetryMs ?? defaultLedgerReplaceRetryMs;
43
47
  this.managedCommandTeardownGraceMs = options.managedCommandTeardownGraceMs;
44
- this.ledgerPath = path.join(this.identity.logDirectory, "attempt-process-supervisor.json");
48
+ this.ledgerPath = attemptProcessSupervisorLedgerPath(this.identity.logDirectory);
45
49
  if (options.signal?.aborted) {
46
50
  this.status = "stopping";
47
51
  this.attemptController.abort(options.signal.reason);
@@ -109,17 +113,19 @@ export class AttemptProcessSupervisor {
109
113
  };
110
114
  this.records.push(record);
111
115
  this.currentByName.set(name, record);
112
- const result = this.runner.run(childRequest, handlers, combinedSignal);
113
- record.result = result;
114
- void result.then(value => this.settleChild(record, "exited", value.exitCode, undefined, value), error => this.settleChild(record, "failed", undefined, error));
116
+ // Durable before the process exists, so a ledger reader (the managed-build guard) never misses a child about to run.
115
117
  try {
116
118
  await this.persist();
117
119
  }
118
120
  catch (error) {
119
- controller.abort("Attempt process ledger could not be persisted.");
120
- await result.catch(() => undefined);
121
+ // Never spawned: the record settles as failed, with the reason the ledger could not be written.
122
+ Object.assign(record, { status: "failed", settledAt: new Date().toISOString() });
123
+ record.failure = boundedFailure(error, failureRedactionValues);
121
124
  throw error;
122
125
  }
126
+ const result = this.runner.run(childRequest, handlers, combinedSignal);
127
+ record.result = result;
128
+ void result.then(value => this.settleChild(record, "exited", value.exitCode, undefined, value), error => this.settleChild(record, "failed", undefined, error));
123
129
  const ready = this.observeChildReady(record);
124
130
  void ready.catch(() => undefined);
125
131
  return {