@loucompanion/forge-bridge 0.1.4-dev.86fc5d1208e6 → 0.1.4-dev.894bcbd53d64

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 (269) 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 +74 -4
  103. package/dist/runtime/host-runtime-lease.js +343 -67
  104. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  105. package/dist/runtime/host-runtime-promotion.js +48 -0
  106. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  107. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  108. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  109. package/dist/runtime/host-runtime-requirements.js +117 -0
  110. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  111. package/dist/runtime/managed-command-teardown.js +596 -0
  112. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  113. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  114. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  115. package/dist/runtime/playwright-browser-cache.js +227 -0
  116. package/dist/runtime/playwright-host-runtime-adapter.d.ts +18 -0
  117. package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
  118. package/dist/runtime/runner-settings.d.ts +104 -0
  119. package/dist/runtime/runner-settings.js +236 -0
  120. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  121. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  122. package/dist/sandbox/host-capacity-broker.d.ts +115 -0
  123. package/dist/sandbox/host-capacity-broker.js +336 -0
  124. package/dist/sandbox/managed-branch.d.ts +13 -0
  125. package/dist/sandbox/managed-branch.js +90 -0
  126. package/dist/sandbox/provider-auth/codex.js +11 -11
  127. package/dist/sandbox/runtime.d.ts +10 -1
  128. package/dist/sandbox/runtime.js +47 -8
  129. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  130. package/dist/sandbox/sandbox-cgroups.js +42 -0
  131. package/dist/session/architect-waits.d.ts +2 -0
  132. package/dist/session/architect-waits.js +138 -0
  133. package/dist/session/managed-attempt-tools.d.ts +27 -7
  134. package/dist/session/managed-attempt-tools.js +406 -123
  135. package/dist/session/managed-build-coordinator.d.ts +17 -1
  136. package/dist/session/managed-build-coordinator.js +14 -1
  137. package/dist/session/managed-build-receipt.d.ts +5 -0
  138. package/dist/session/managed-build-receipt.js +8 -3
  139. package/dist/session/managed-command-host-load.d.ts +47 -0
  140. package/dist/session/managed-command-host-load.js +83 -0
  141. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  142. package/dist/session/mcp-argument-coercion.js +121 -0
  143. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  144. package/dist/session/phase-completion.artifacts.js +100 -26
  145. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  146. package/dist/session/phase-completion.command-validation.js +77 -0
  147. package/dist/session/phase-completion.d.ts +12 -0
  148. package/dist/session/phase-completion.helpers.js +13 -12
  149. package/dist/session/phase-completion.js +5 -0
  150. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  151. package/dist/session/phase-completion.mcp-args.js +156 -0
  152. package/dist/session/phase-completion.prompts.js +6 -1
  153. package/dist/session/phase-completion.runtime.d.ts +5 -11
  154. package/dist/session/phase-completion.runtime.js +111 -230
  155. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  156. package/dist/session/phase-completion.schema-parts.js +188 -0
  157. package/dist/session/phase-completion.schemas.d.ts +3 -3
  158. package/dist/session/phase-completion.schemas.js +208 -231
  159. package/dist/session/phase-completion.validation.d.ts +2 -3
  160. package/dist/session/phase-completion.validation.js +49 -93
  161. package/dist/session/pre-publication-host-load.d.ts +27 -0
  162. package/dist/session/pre-publication-host-load.js +111 -0
  163. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  164. package/dist/session/pre-publication-native-postgres.js +111 -0
  165. package/dist/session/pre-publication-pass.d.ts +61 -0
  166. package/dist/session/pre-publication-pass.js +148 -0
  167. package/dist/session/pre-publication-process.d.ts +23 -0
  168. package/dist/session/pre-publication-process.js +109 -0
  169. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  170. package/dist/session/pre-publication-skipped-tests.js +109 -0
  171. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  172. package/dist/session/pre-publication-step-execution.js +50 -0
  173. package/dist/session/pre-publication-validation.d.ts +37 -21
  174. package/dist/session/pre-publication-validation.js +228 -219
  175. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  176. package/dist/session/provider-cli/claude-background-work.js +181 -0
  177. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  178. package/dist/session/provider-cli/host-build-lock.js +30 -0
  179. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  180. package/dist/session/provider-cli/pre-publication-repair.js +276 -0
  181. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
  182. package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
  183. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  184. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  185. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  186. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  187. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  188. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  189. package/dist/session/provider-cli/provider-cli.process.d.ts +46 -31
  190. package/dist/session/provider-cli/provider-cli.process.js +286 -403
  191. package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -0
  192. package/dist/session/provider-cli/provider-cli.prompts.js +87 -32
  193. package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
  194. package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
  195. package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
  196. package/dist/session/provider-cli/provider-cli.service.js +207 -192
  197. package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
  198. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  199. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  200. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  201. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  202. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  203. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  204. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  205. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  206. package/dist/session/provider-cli/provider-output-state.d.ts +8 -0
  207. package/dist/session/provider-cli/provider-output-state.js +15 -0
  208. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  209. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  210. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  211. package/dist/session/publishable-worktree-changes.js +193 -0
  212. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  213. package/dist/session/qa-sidecar-validation.js +28 -0
  214. package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
  215. package/dist/session/sandbox-host-capacity-gate.js +257 -0
  216. package/dist/session/session-redaction.js +31 -181
  217. package/dist/session/session.base.d.ts +9 -1
  218. package/dist/session/session.service.d.ts +11 -2
  219. package/dist/session/session.service.js +189 -69
  220. package/dist/session/session.types.d.ts +3 -0
  221. package/dist/session/session.types.js +15 -3
  222. package/dist/session/sidecar-json-shape.d.ts +31 -0
  223. package/dist/session/sidecar-json-shape.js +217 -0
  224. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  225. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  226. package/dist/shared/fs/file-identity.d.ts +10 -0
  227. package/dist/shared/fs/file-identity.js +15 -0
  228. package/dist/shared/fs/replace-file.d.ts +7 -0
  229. package/dist/shared/fs/replace-file.js +33 -0
  230. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  231. package/dist/shared/process/host-process-recovery.js +23 -3
  232. package/dist/shared/process/host-process-supervisor.d.ts +14 -1
  233. package/dist/shared/process/host-process-supervisor.js +67 -15
  234. package/dist/shared/process/process-tree.d.ts +52 -0
  235. package/dist/shared/process/process-tree.js +144 -0
  236. package/dist/shared/process/process.d.ts +67 -0
  237. package/dist/shared/process/process.js +213 -11
  238. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  239. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  240. package/dist/shared/process/windows-launch.d.ts +18 -0
  241. package/dist/shared/process/windows-launch.js +68 -0
  242. package/dist/shared/provider-capabilities.js +14 -7
  243. package/dist/version.d.ts +1 -1
  244. package/dist/version.js +1 -1
  245. package/dist/worktree/dependency-warmer.d.ts +25 -0
  246. package/dist/worktree/dependency-warmer.js +120 -10
  247. package/dist/worktree/orphan-relink.d.ts +19 -0
  248. package/dist/worktree/orphan-relink.js +106 -0
  249. package/dist/worktree/wip-git.d.ts +33 -0
  250. package/dist/worktree/wip-git.js +122 -0
  251. package/dist/worktree/wip-refs.d.ts +62 -0
  252. package/dist/worktree/wip-refs.js +119 -0
  253. package/dist/worktree/wip-restore.d.ts +38 -0
  254. package/dist/worktree/wip-restore.js +190 -0
  255. package/dist/worktree/wip-snapshot.d.ts +50 -0
  256. package/dist/worktree/wip-snapshot.js +268 -0
  257. package/dist/worktree/worktree-inputs.d.ts +8 -0
  258. package/dist/worktree/worktree-inputs.js +134 -0
  259. package/dist/worktree/worktree-origin-sync.d.ts +34 -0
  260. package/dist/worktree/worktree-origin-sync.js +127 -0
  261. package/dist/worktree/worktree-wip-events.d.ts +18 -0
  262. package/dist/worktree/worktree-wip-events.js +98 -0
  263. package/dist/worktree/worktree-wip.d.ts +50 -0
  264. package/dist/worktree/worktree-wip.js +185 -0
  265. package/dist/worktree/worktree.base.d.ts +7 -1
  266. package/dist/worktree/worktree.service.d.ts +36 -5
  267. package/dist/worktree/worktree.service.js +124 -155
  268. package/dist/worktree/worktree.types.d.ts +38 -0
  269. package/package.json +2 -2
@@ -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. */
@@ -4,6 +4,7 @@ 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;
8
9
  /** Launches one explicitly configured HTTP project beneath the attempt coordinator. */
9
10
  export class AttemptNodeRuntimeLauncher {
@@ -27,6 +28,14 @@ export class AttemptNodeRuntimeLauncher {
27
28
  const diagnostics = { exited: false, stdoutTail: "", stderrTail: "", outputRevision: 0 };
28
29
  let child;
29
30
  try {
31
+ // Recorded before the child starts, so a managed build can never see it running unrecorded.
32
+ await writeSupervisedRuntimeDescriptor(this.logDirectory, {
33
+ role: request.port.name,
34
+ childName,
35
+ command: request.command,
36
+ args: request.args,
37
+ cwd: request.cwd,
38
+ });
30
39
  child = await this.supervisor.startChildReady(childName, {
31
40
  command: request.command,
32
41
  args: request.args,
@@ -1,4 +1,5 @@
1
1
  import type { ProviderProcessHandlers, ProviderProcessRunRequest, ProviderProcessRunner, ProviderProcessRunResult } from "../session/provider-cli/provider-cli.process.js";
2
+ import { type ManagedCommandTeardownOptions, type ManagedCommandTeardownOutcome } from "./managed-command-teardown.js";
2
3
  export type AttemptProcessChildStatus = "starting" | "running" | "stopping" | "exited" | "failed";
3
4
  export type AttemptProcessSupervisorStatus = "active" | "stopping" | "stopped" | "degraded";
4
5
  export interface AttemptProcessSupervisorIdentity {
@@ -32,6 +33,8 @@ export interface AttemptProcessSupervisorLedger {
32
33
  readonly status: AttemptProcessSupervisorStatus;
33
34
  readonly updatedAt: string;
34
35
  readonly children: readonly AttemptProcessChildLedgerEntry[];
36
+ /** A provider-exit managed-command cleanup that failed and was left to attempt teardown. */
37
+ readonly deferredManagedCommandTeardownFailure?: string;
35
38
  }
36
39
  export interface AttemptProcessChildHandle {
37
40
  readonly name: string;
@@ -48,11 +51,14 @@ export interface AttemptProcessSupervisorOptions {
48
51
  readonly signal?: AbortSignal;
49
52
  readonly replaceLedgerFile?: (temporaryPath: string, ledgerPath: string) => Promise<void>;
50
53
  readonly ledgerReplaceRetryMs?: number;
54
+ readonly managedCommandTeardownGraceMs?: number;
51
55
  }
52
56
  export interface AttemptProcessChildReadyOptions {
53
57
  readonly maxStartAttempts?: number;
54
58
  readonly retryDelayMs?: number;
55
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;
56
62
  /**
57
63
  * Owns the independently supervised process trees that belong to one host
58
64
  * dispatch attempt. Each named child gets a distinct Windows Job Object or
@@ -66,6 +72,7 @@ export declare class AttemptProcessSupervisor {
66
72
  private readonly metadataReadyTimeoutMs;
67
73
  private readonly replaceLedgerFile;
68
74
  private readonly ledgerReplaceRetryMs;
75
+ private readonly managedCommandTeardownGraceMs;
69
76
  private readonly records;
70
77
  private readonly currentByName;
71
78
  private readonly attemptController;
@@ -73,6 +80,8 @@ export declare class AttemptProcessSupervisor {
73
80
  private persistTail;
74
81
  private persistenceFailure;
75
82
  private stopOperation;
83
+ private managedCommandTeardownTail;
84
+ private deferredManagedCommandTeardownFailure;
76
85
  constructor(identity: AttemptProcessSupervisorIdentity, runner: ProviderProcessRunner, options?: AttemptProcessSupervisorOptions);
77
86
  startChild(name: string, request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<AttemptProcessChildHandle>;
78
87
  /**
@@ -86,6 +95,18 @@ export declare class AttemptProcessSupervisor {
86
95
  stopChild(name: string, generation: number, fencingToken: string, reason?: unknown): Promise<ProviderProcessRunResult>;
87
96
  stopAll(fencingToken: string, reason?: unknown): Promise<void>;
88
97
  private performStopAll;
98
+ /**
99
+ * Stops the managed commands this attempt's MCP servers started and finalizes their
100
+ * receipts. With `onlyOrphaned`, a command whose owning MCP server is still alive is
101
+ * left running: it survives wait slices and MCP call boundaries within a live provider.
102
+ */
103
+ terminateManagedCommands(options: Omit<ManagedCommandTeardownOptions, "graceMs">): Promise<readonly ManagedCommandTeardownOutcome[]>;
104
+ /**
105
+ * After a provider exits, stops the managed commands its MCP server left behind. It never
106
+ * fails the provider's result: a command it cannot prove stopped is recorded in the ledger
107
+ * and left to attempt teardown, which fails closed.
108
+ */
109
+ stopOrphanedManagedCommands(): Promise<void>;
89
110
  snapshot(): AttemptProcessSupervisorLedger;
90
111
  providerMemoryTelemetry(): AttemptProcessTreeMemoryTelemetry | null;
91
112
  private observeChildReady;
@@ -2,7 +2,12 @@ import { createHash } from "node:crypto";
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { ForgeFailureError, sanitizeFailureError } from "../session/session.types.js";
5
+ import { terminateAttemptManagedCommands, } from "./managed-command-teardown.js";
5
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
+ }
6
11
  const terminalChildStatuses = new Set(["exited", "failed"]);
7
12
  const defaultMetadataReadyTimeoutMs = process.platform === "win32" ? 60_000 : 10_000;
8
13
  // Windows refuses to replace a file another process (a scanner or indexer) briefly holds
@@ -23,6 +28,7 @@ export class AttemptProcessSupervisor {
23
28
  metadataReadyTimeoutMs;
24
29
  replaceLedgerFile;
25
30
  ledgerReplaceRetryMs;
31
+ managedCommandTeardownGraceMs;
26
32
  records = [];
27
33
  currentByName = new Map();
28
34
  attemptController = new AbortController();
@@ -30,13 +36,16 @@ export class AttemptProcessSupervisor {
30
36
  persistTail = Promise.resolve();
31
37
  persistenceFailure;
32
38
  stopOperation = null;
39
+ managedCommandTeardownTail = Promise.resolve();
40
+ deferredManagedCommandTeardownFailure;
33
41
  constructor(identity, runner, options = {}) {
34
42
  this.runner = runner;
35
43
  this.identity = validateIdentity(identity);
36
44
  this.metadataReadyTimeoutMs = boundedInteger(options.metadataReadyTimeoutMs ?? defaultMetadataReadyTimeoutMs, 100, 120_000, "metadataReadyTimeoutMs");
37
45
  this.replaceLedgerFile = options.replaceLedgerFile ?? ((temporaryPath, ledgerPath) => fs.rename(temporaryPath, ledgerPath));
38
46
  this.ledgerReplaceRetryMs = options.ledgerReplaceRetryMs ?? defaultLedgerReplaceRetryMs;
39
- this.ledgerPath = path.join(this.identity.logDirectory, "attempt-process-supervisor.json");
47
+ this.managedCommandTeardownGraceMs = options.managedCommandTeardownGraceMs;
48
+ this.ledgerPath = attemptProcessSupervisorLedgerPath(this.identity.logDirectory);
40
49
  if (options.signal?.aborted) {
41
50
  this.status = "stopping";
42
51
  this.attemptController.abort(options.signal.reason);
@@ -104,17 +113,19 @@ export class AttemptProcessSupervisor {
104
113
  };
105
114
  this.records.push(record);
106
115
  this.currentByName.set(name, record);
107
- const result = this.runner.run(childRequest, handlers, combinedSignal);
108
- record.result = result;
109
- 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.
110
117
  try {
111
118
  await this.persist();
112
119
  }
113
120
  catch (error) {
114
- controller.abort("Attempt process ledger could not be persisted.");
115
- 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);
116
124
  throw error;
117
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));
118
129
  const ready = this.observeChildReady(record);
119
130
  void ready.catch(() => undefined);
120
131
  return {
@@ -199,6 +210,14 @@ export class AttemptProcessSupervisor {
199
210
  const rejected = results.flatMap((result, index) => result.status === "rejected"
200
211
  ? [sanitizeFailureError(result.reason, active[index].failureRedactionValues)]
201
212
  : []);
213
+ // Managed commands run in their own process groups, outside every child tree stopped
214
+ // above. The attempt is not stopped until each of them is proven stopped too.
215
+ try {
216
+ await this.terminateManagedCommands({ reason: "attempt_teardown" });
217
+ }
218
+ catch (error) {
219
+ rejected.push(error instanceof Error ? error : new Error(String(error)));
220
+ }
202
221
  const terminalStatus = rejected.length > 0 || this.persistenceFailure !== undefined ? "degraded" : "stopped";
203
222
  await this.persist({
204
223
  ...this.snapshot(),
@@ -212,6 +231,40 @@ export class AttemptProcessSupervisor {
212
231
  if (this.persistenceFailure !== undefined)
213
232
  throw this.persistenceFailure;
214
233
  }
234
+ /**
235
+ * Stops the managed commands this attempt's MCP servers started and finalizes their
236
+ * receipts. With `onlyOrphaned`, a command whose owning MCP server is still alive is
237
+ * left running: it survives wait slices and MCP call boundaries within a live provider.
238
+ */
239
+ async terminateManagedCommands(options) {
240
+ // One sweep at a time: a provider-exit sweep and attempt teardown would otherwise
241
+ // signal the same groups and write the same receipts concurrently, and stopAll must
242
+ // not report the attempt stopped while an earlier sweep is still writing.
243
+ const sweep = this.managedCommandTeardownTail.then(async () => await terminateAttemptManagedCommands({
244
+ logDirectory: this.identity.logDirectory,
245
+ dispatchAttemptId: this.identity.dispatchAttemptId,
246
+ runtimeLeaseId: this.identity.executionLeaseId,
247
+ }, {
248
+ ...options,
249
+ ...(this.managedCommandTeardownGraceMs === undefined ? {} : { graceMs: this.managedCommandTeardownGraceMs }),
250
+ }));
251
+ this.managedCommandTeardownTail = sweep.catch(() => undefined);
252
+ return await sweep;
253
+ }
254
+ /**
255
+ * After a provider exits, stops the managed commands its MCP server left behind. It never
256
+ * fails the provider's result: a command it cannot prove stopped is recorded in the ledger
257
+ * and left to attempt teardown, which fails closed.
258
+ */
259
+ async stopOrphanedManagedCommands() {
260
+ try {
261
+ await this.terminateManagedCommands({ reason: "owner_exited", onlyOrphaned: true });
262
+ }
263
+ catch (error) {
264
+ this.deferredManagedCommandTeardownFailure = boundedFailure(error, []);
265
+ await this.persist().catch(() => undefined);
266
+ }
267
+ }
215
268
  snapshot() {
216
269
  return {
217
270
  schemaVersion: 1,
@@ -220,6 +273,9 @@ export class AttemptProcessSupervisor {
220
273
  executionLeaseId: this.identity.executionLeaseId,
221
274
  status: this.status,
222
275
  updatedAt: new Date().toISOString(),
276
+ ...(this.deferredManagedCommandTeardownFailure
277
+ ? { deferredManagedCommandTeardownFailure: this.deferredManagedCommandTeardownFailure }
278
+ : {}),
223
279
  children: this.records.map(record => ({
224
280
  name: record.name,
225
281
  generation: record.generation,
@@ -62,6 +62,11 @@ export declare class DockerEngineProbe {
62
62
  constructor(options?: DockerEngineProbeOptions, commands?: CommandRunner, cacheMs?: number);
63
63
  current(): DockerEngineCapabilitySnapshot | null;
64
64
  refresh(force?: boolean): Promise<DockerEngineCapabilitySnapshot>;
65
+ /**
66
+ * One fresh daemon reading that never starts recovery and leaves the cache and the
67
+ * failure streak alone, for callers that only need to know whether Docker is up.
68
+ */
69
+ probeWithoutRecovery(): Promise<DockerEngineCapabilitySnapshot>;
65
70
  /**
66
71
  * Establishes a fresh daemon fence for work that declares Docker as a hard
67
72
  * prerequisite. This remains bounded, cooldown protected and single-flight;
@@ -69,6 +69,13 @@ export class DockerEngineProbe {
69
69
  this.inFlight = operation;
70
70
  return await operation;
71
71
  }
72
+ /**
73
+ * One fresh daemon reading that never starts recovery and leaves the cache and the
74
+ * failure streak alone, for callers that only need to know whether Docker is up.
75
+ */
76
+ async probeWithoutRecovery() {
77
+ return await this.inspectSafely();
78
+ }
72
79
  /**
73
80
  * Establishes a fresh daemon fence for work that declares Docker as a hard
74
81
  * prerequisite. This remains bounded, cooldown protected and single-flight;
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Where a supervised ASP.NET runtime builds and runs from, relative to each project in its
3
+ * graph. Agent builds keep the default `bin/<Configuration>/<TargetFramework>/` output, so they
4
+ * never overwrite (or, on Windows, fail on the locks of) the files a running runtime executes.
5
+ */
6
+ export declare const supervisedRuntimeOutputRoot = "bin/forge-runtime";
7
+ export type DotnetPathPlatform = "win32" | "posix";
8
+ /** A directory option: CLI options are fixed for the whole graph, MSBuild properties resolve per project. */
9
+ export interface DotnetOutputLocation {
10
+ readonly path: string;
11
+ readonly perProject: boolean;
12
+ }
13
+ export interface DotnetOutputSettings {
14
+ readonly configuration: string;
15
+ readonly framework: string | null;
16
+ readonly runtime: string | null;
17
+ /** `-p:OutDir` or `-p:OutputPath`: MSBuild resolves a relative value against each project. */
18
+ readonly outDir: DotnetOutputLocation | null;
19
+ /** `-o`/`--output`: one directory for every project the command builds. */
20
+ readonly output: DotnetOutputLocation | null;
21
+ readonly baseOutputPath: DotnetOutputLocation | null;
22
+ readonly artifactsPath: DotnetOutputLocation | null;
23
+ }
24
+ /** A dotnet command that writes (or, for a runtime, executes from) project build output. */
25
+ export interface DotnetOutputCommand {
26
+ readonly verb: string;
27
+ readonly cwd: string;
28
+ /** Absolute target candidates (project, solution, or directory); empty means the working directory. */
29
+ readonly targets: readonly string[];
30
+ readonly settings: DotnetOutputSettings;
31
+ }
32
+ export interface DotnetProjectFiles {
33
+ readonly read: (file: string) => Promise<string | null>;
34
+ readonly list: (directory: string) => Promise<readonly string[] | null>;
35
+ /** The real location of a path (canonicalExistingPath); without it paths compare as written. */
36
+ readonly canonical?: (target: string) => Promise<string>;
37
+ }
38
+ export interface DotnetOutputCollision {
39
+ /** The project whose output both commands use. */
40
+ readonly project: string;
41
+ readonly outputDirectory: string;
42
+ }
43
+ /**
44
+ * Where a path really is, existing or not yet: its deepest existing ancestor resolved through every
45
+ * symlink and junction, with the rest appended. A lexical path alone lets a link alias another directory.
46
+ * A link whose target does not exist yet still leads to that target, so it is followed by its
47
+ * link text, never taken as its own location; a link loop fails with `path_link_unresolvable`.
48
+ */
49
+ export declare function canonicalExistingPath(target: string): Promise<string>;
50
+ /** canonicalExistingPath, for synchronous planning. */
51
+ export declare function canonicalExistingPathSync(target: string): string;
52
+ export declare const fileSystemProjectFiles: DotnetProjectFiles;
53
+ export declare function hostPathPlatform(): DotnetPathPlatform;
54
+ export declare function isDotnetExecutable(command: string, platform?: DotnetPathPlatform): boolean;
55
+ /**
56
+ * Reads a dotnet command's build-output intent: its verb, target candidates, and output
57
+ * settings. Returns null when the command writes no build output. With `holder`, the command is
58
+ * a running runtime's `dotnet run`: `--no-build` does not matter, it executes from the output.
59
+ */
60
+ export declare function parseDotnetOutputCommand(command: string, args: readonly string[], cwd: string, options?: {
61
+ readonly platform?: DotnetPathPlatform;
62
+ readonly holder?: boolean;
63
+ }): DotnetOutputCommand | null;
64
+ /** True when the arguments already choose where the build output goes. */
65
+ export declare function declaresDotnetOutput(settings: DotnetOutputSettings): boolean;
66
+ /** What the project file itself decides about its output layout. */
67
+ export interface DotnetProjectLayout {
68
+ /** The project sets `<TargetFrameworks>`: the artifacts layout then adds the framework to its pivot. */
69
+ readonly multiTargeted?: boolean;
70
+ }
71
+ /** True when a project file multi-targets (`<TargetFrameworks>`, even with one entry). */
72
+ export declare function isMultiTargetedProject(projectXml: string): boolean;
73
+ /**
74
+ * The directory a project's primary output lands in under these settings. An unknown target
75
+ * framework is the wildcard `*`, which matches any framework in sameOutputDirectory.
76
+ */
77
+ export declare function projectOutputDirectory(projectFile: string, settings: DotnetOutputSettings, platform?: DotnetPathPlatform, layout?: DotnetProjectLayout): string;
78
+ /**
79
+ * The one directory holding every build output of a project under these settings, whatever
80
+ * configuration or framework they leave open: what a runtime's build receipt verifies. Without
81
+ * the project file's name, an artifacts layout's root is its `bin`, above every project's folder.
82
+ */
83
+ export declare function projectOutputRoot(projectDirectory: string, projectFile: string | null, settings: DotnetOutputSettings, platform?: DotnetPathPlatform): string;
84
+ /**
85
+ * Compares two output directories segment by segment. `*` matches any run of characters inside
86
+ * one segment: `*` is any framework folder, and `debug_*` any framework pivot.
87
+ */
88
+ export declare function sameOutputDirectory(left: string, right: string, platform?: DotnetPathPlatform): boolean;
89
+ /** ProjectReference Include values of a project file, ignoring commented-out references. */
90
+ export declare function projectReferenceIncludes(projectXml: string): readonly string[];
91
+ /** Project paths a .sln or .slnx lists. */
92
+ export declare function solutionProjectPaths(solution: string, content: string): readonly string[];
93
+ /** Every project file a command builds: its targets, solution members, and their ProjectReference closure. */
94
+ export declare function dotnetCommandProjects(command: DotnetOutputCommand, files?: DotnetProjectFiles, platform?: DotnetPathPlatform): Promise<readonly string[]>;
95
+ /**
96
+ * The projects whose output a build (`writer`) would write while a runtime (`holder`) executes
97
+ * from that same output, in the runtime's graph order (its own project first).
98
+ */
99
+ export declare function findDotnetOutputCollisions(writer: DotnetOutputCommand, holder: DotnetOutputCommand, files?: DotnetProjectFiles, platform?: DotnetPathPlatform): Promise<readonly DotnetOutputCollision[]>;
100
+ /** A runtime role as a directory name: kept when it is already safe, otherwise a stable digest. */
101
+ export declare function runtimeOutputName(role: string): string;
102
+ /**
103
+ * Gives a supervised `dotnet run` its own build output, `bin/forge-runtime/<role>/` under each
104
+ * project, unless the configured arguments already choose one. The ASP.NET prebuild forwards the
105
+ * same property to its `dotnet build`, so the runtime builds and runs from that directory.
106
+ */
107
+ export declare function isolatedRuntimeOutputArguments(command: string, args: readonly string[], role: string, platform?: DotnetPathPlatform): readonly string[];