@loucompanion/forge-bridge 0.1.3-dev.f66395c3ac21 → 0.1.4-dev.0098fdb4e213

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 (381) hide show
  1. package/README.md +306 -1
  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 +121 -0
  5. package/dist/bridge/bridge-chat.types.js +416 -0
  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 +18 -1
  15. package/dist/bridge/bridge.service.d.ts +216 -4
  16. package/dist/bridge/bridge.service.js +2574 -90
  17. package/dist/bridge/bridge.types.d.ts +245 -2
  18. package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
  19. package/dist/bridge/dispatch-result-outbox.js +87 -0
  20. package/dist/bridge/dispatch-result-worker.d.ts +2 -0
  21. package/dist/bridge/dispatch-result-worker.js +122 -0
  22. package/dist/bridge/in-flight-registry.d.ts +62 -0
  23. package/dist/bridge/in-flight-registry.js +207 -0
  24. package/dist/bridge/internals.d.ts +2 -0
  25. package/dist/bridge/internals.js +1 -0
  26. package/dist/bridge/local-yield-flag.d.ts +6 -0
  27. package/dist/bridge/local-yield-flag.js +34 -0
  28. package/dist/bridge/readiness-result-outbox.d.ts +25 -0
  29. package/dist/bridge/readiness-result-outbox.js +74 -0
  30. package/dist/bridge/readiness-result-worker.d.ts +2 -0
  31. package/dist/bridge/readiness-result-worker.js +121 -0
  32. package/dist/bridge/runner-host-capabilities.d.ts +20 -0
  33. package/dist/bridge/runner-host-capabilities.js +110 -0
  34. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  35. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  36. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  37. package/dist/bridge/test-postgres-capability.js +120 -0
  38. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  39. package/dist/cleanup/cleanup-wip.js +66 -0
  40. package/dist/cleanup/cleanup.service.d.ts +33 -2
  41. package/dist/cleanup/cleanup.service.js +477 -3
  42. package/dist/cleanup/cleanup.types.d.ts +16 -0
  43. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  44. package/dist/cleanup/forge-owned-paths.js +53 -0
  45. package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
  46. package/dist/cleanup/host-runtime-ledger.js +130 -0
  47. package/dist/cleanup/index.d.ts +1 -1
  48. package/dist/cleanup/index.js +1 -1
  49. package/dist/cleanup/internals.d.ts +2 -2
  50. package/dist/cleanup/internals.js +1 -1
  51. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  52. package/dist/cleanup/managed-branch-sweep.js +111 -0
  53. package/dist/cli/cli.help.d.ts +2 -0
  54. package/dist/cli/cli.help.js +279 -0
  55. package/dist/cli/cli.service.d.ts +69 -12
  56. package/dist/cli/cli.service.js +557 -382
  57. package/dist/cli/idle-status.d.ts +84 -0
  58. package/dist/cli/idle-status.js +181 -0
  59. package/dist/cli/local-config.d.ts +13 -0
  60. package/dist/cli/local-config.js +82 -6
  61. package/dist/cli/provider-cli-detection.d.ts +10 -0
  62. package/dist/cli/provider-cli-detection.js +160 -0
  63. package/dist/runtime/aspnet-runtime-prebuild.d.ts +41 -0
  64. package/dist/runtime/aspnet-runtime-prebuild.js +474 -0
  65. package/dist/runtime/attempt-database-broker.d.ts +89 -0
  66. package/dist/runtime/attempt-database-broker.js +390 -0
  67. package/dist/runtime/attempt-node-runtime-launcher.d.ts +18 -0
  68. package/dist/runtime/attempt-node-runtime-launcher.js +140 -0
  69. package/dist/runtime/attempt-path-operation.d.ts +21 -0
  70. package/dist/runtime/attempt-path-operation.js +94 -0
  71. package/dist/runtime/attempt-private-directory.d.ts +6 -0
  72. package/dist/runtime/attempt-private-directory.js +54 -0
  73. package/dist/runtime/attempt-process-supervisor-registry.d.ts +20 -0
  74. package/dist/runtime/attempt-process-supervisor-registry.js +64 -0
  75. package/dist/runtime/attempt-process-supervisor.d.ts +121 -0
  76. package/dist/runtime/attempt-process-supervisor.js +471 -0
  77. package/dist/runtime/canonical-source-file.d.ts +3 -0
  78. package/dist/runtime/canonical-source-file.js +54 -0
  79. package/dist/runtime/docker-engine-probe.d.ts +95 -0
  80. package/dist/runtime/docker-engine-probe.js +340 -0
  81. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  82. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  83. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  84. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  85. package/dist/runtime/generated-output-reset.d.ts +20 -0
  86. package/dist/runtime/generated-output-reset.js +157 -0
  87. package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
  88. package/dist/runtime/host-database-capability-boundary.js +63 -0
  89. package/dist/runtime/host-diagnostics.d.ts +11 -0
  90. package/dist/runtime/host-diagnostics.js +192 -0
  91. package/dist/runtime/host-execution-root.d.ts +4 -0
  92. package/dist/runtime/host-execution-root.js +39 -0
  93. package/dist/runtime/host-facts.d.ts +36 -0
  94. package/dist/runtime/host-facts.js +95 -0
  95. package/dist/runtime/host-listener-inspector.d.ts +51 -0
  96. package/dist/runtime/host-listener-inspector.js +385 -0
  97. package/dist/runtime/host-load-admission.d.ts +67 -0
  98. package/dist/runtime/host-load-admission.js +99 -0
  99. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  100. package/dist/runtime/host-load-child-environment.js +76 -0
  101. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  102. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  103. package/dist/runtime/host-load-governor-config.d.ts +52 -0
  104. package/dist/runtime/host-load-governor-config.js +83 -0
  105. package/dist/runtime/host-load-governor.d.ts +186 -0
  106. package/dist/runtime/host-load-governor.js +632 -0
  107. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  108. package/dist/runtime/host-load-ledger-lock.js +187 -0
  109. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  110. package/dist/runtime/host-load-runtime-settings.js +80 -0
  111. package/dist/runtime/host-load-sampler.d.ts +156 -0
  112. package/dist/runtime/host-load-sampler.js +298 -0
  113. package/dist/runtime/host-load-step-class.d.ts +70 -0
  114. package/dist/runtime/host-load-step-class.js +161 -0
  115. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  116. package/dist/runtime/host-load-step-reaper.js +95 -0
  117. package/dist/runtime/host-load-step-run.d.ts +73 -0
  118. package/dist/runtime/host-load-step-run.js +102 -0
  119. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  120. package/dist/runtime/host-load-test-slot.js +81 -0
  121. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  122. package/dist/runtime/host-load-token-ledger.js +453 -0
  123. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  124. package/dist/runtime/host-load-windows-cpu.js +85 -0
  125. package/dist/runtime/host-port-broker.d.ts +76 -0
  126. package/dist/runtime/host-port-broker.js +333 -0
  127. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  128. package/dist/runtime/host-pressure-stall.js +168 -0
  129. package/dist/runtime/host-runtime-contract.d.ts +74 -0
  130. package/dist/runtime/host-runtime-contract.js +846 -0
  131. package/dist/runtime/host-runtime-lease.d.ts +287 -0
  132. package/dist/runtime/host-runtime-lease.js +2763 -0
  133. package/dist/runtime/host-runtime-promotion.d.ts +55 -0
  134. package/dist/runtime/host-runtime-promotion.js +254 -0
  135. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  136. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  137. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  138. package/dist/runtime/host-runtime-requirements.js +117 -0
  139. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  140. package/dist/runtime/managed-command-teardown.js +596 -0
  141. package/dist/runtime/memory-capacity.d.ts +70 -0
  142. package/dist/runtime/memory-capacity.js +123 -0
  143. package/dist/runtime/native-test-postgres-fallback.d.ts +69 -0
  144. package/dist/runtime/native-test-postgres-fallback.js +143 -0
  145. package/dist/runtime/node-host-runtime-adapter.d.ts +54 -0
  146. package/dist/runtime/node-host-runtime-adapter.js +286 -0
  147. package/dist/runtime/pinned-directory-process.d.ts +9 -0
  148. package/dist/runtime/pinned-directory-process.js +61 -0
  149. package/dist/runtime/pinned-source-directory.d.ts +17 -0
  150. package/dist/runtime/pinned-source-directory.js +94 -0
  151. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  152. package/dist/runtime/playwright-browser-cache.js +227 -0
  153. package/dist/runtime/playwright-host-runtime-adapter.d.ts +39 -0
  154. package/dist/runtime/playwright-host-runtime-adapter.js +274 -0
  155. package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
  156. package/dist/runtime/prepared-runtime-identity.js +218 -0
  157. package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
  158. package/dist/runtime/prepared-runtime-readiness.js +285 -0
  159. package/dist/runtime/runner-settings.d.ts +104 -0
  160. package/dist/runtime/runner-settings.js +236 -0
  161. package/dist/runtime/runtime-isolation-lease.d.ts +67 -0
  162. package/dist/runtime/runtime-isolation-lease.js +161 -0
  163. package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
  164. package/dist/runtime/workspace-resource-estimator.js +174 -0
  165. package/dist/sandbox/command-runner.d.ts +4 -0
  166. package/dist/sandbox/command-runner.js +47 -0
  167. package/dist/sandbox/contract.d.ts +5 -0
  168. package/dist/sandbox/contract.js +276 -0
  169. package/dist/sandbox/event-budget.d.ts +11 -0
  170. package/dist/sandbox/event-budget.js +27 -0
  171. package/dist/sandbox/host-capacity-broker.d.ts +115 -0
  172. package/dist/sandbox/host-capacity-broker.js +336 -0
  173. package/dist/sandbox/image-policy.d.ts +35 -0
  174. package/dist/sandbox/image-policy.js +247 -0
  175. package/dist/sandbox/index.d.ts +5 -0
  176. package/dist/sandbox/index.js +5 -0
  177. package/dist/sandbox/lease-watchdog.d.ts +18 -0
  178. package/dist/sandbox/lease-watchdog.js +67 -0
  179. package/dist/sandbox/managed-branch.d.ts +13 -0
  180. package/dist/sandbox/managed-branch.js +36 -0
  181. package/dist/sandbox/preflight.d.ts +84 -0
  182. package/dist/sandbox/preflight.js +521 -0
  183. package/dist/sandbox/process.d.ts +20 -0
  184. package/dist/sandbox/process.js +209 -0
  185. package/dist/sandbox/provider-auth/codex.d.ts +26 -0
  186. package/dist/sandbox/provider-auth/codex.js +212 -0
  187. package/dist/sandbox/repository-lock.d.ts +6 -0
  188. package/dist/sandbox/repository-lock.js +129 -0
  189. package/dist/sandbox/runtime.d.ts +311 -0
  190. package/dist/sandbox/runtime.js +2407 -0
  191. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  192. package/dist/sandbox/sandbox-cgroups.js +42 -0
  193. package/dist/sandbox/sandbox.types.d.ts +93 -0
  194. package/dist/sandbox/sandbox.types.js +1 -0
  195. package/dist/sandbox/smoke.d.ts +76 -0
  196. package/dist/sandbox/smoke.js +380 -0
  197. package/dist/sandbox/worker-supervisor.d.ts +13 -0
  198. package/dist/sandbox/worker-supervisor.js +36 -0
  199. package/dist/sandbox/worker.d.ts +1 -0
  200. package/dist/sandbox/worker.js +225 -0
  201. package/dist/sandbox/workspace.service.d.ts +13 -0
  202. package/dist/sandbox/workspace.service.js +74 -0
  203. package/dist/session/architect-waits.d.ts +2 -0
  204. package/dist/session/architect-waits.js +138 -0
  205. package/dist/session/managed-attempt-tools.d.ts +48 -0
  206. package/dist/session/managed-attempt-tools.js +1299 -0
  207. package/dist/session/managed-build-coordinator.d.ts +5 -0
  208. package/dist/session/managed-build-coordinator.js +109 -0
  209. package/dist/session/managed-build-receipt.d.ts +26 -0
  210. package/dist/session/managed-build-receipt.js +342 -0
  211. package/dist/session/managed-command-host-load.d.ts +47 -0
  212. package/dist/session/managed-command-host-load.js +83 -0
  213. package/dist/session/managed-verification-timeouts.d.ts +8 -0
  214. package/dist/session/managed-verification-timeouts.js +17 -0
  215. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  216. package/dist/session/mcp-argument-coercion.js +121 -0
  217. package/dist/session/phase-completion.artifacts.d.ts +34 -0
  218. package/dist/session/phase-completion.artifacts.js +903 -0
  219. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  220. package/dist/session/phase-completion.command-validation.js +77 -0
  221. package/dist/session/phase-completion.d.ts +65 -42
  222. package/dist/session/phase-completion.helpers.d.ts +117 -0
  223. package/dist/session/phase-completion.helpers.js +708 -0
  224. package/dist/session/phase-completion.js +130 -3007
  225. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  226. package/dist/session/phase-completion.mcp-args.js +156 -0
  227. package/dist/session/phase-completion.prompts.d.ts +14 -0
  228. package/dist/session/phase-completion.prompts.js +238 -0
  229. package/dist/session/phase-completion.runtime.d.ts +43 -0
  230. package/dist/session/phase-completion.runtime.js +721 -0
  231. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  232. package/dist/session/phase-completion.schema-parts.js +188 -0
  233. package/dist/session/phase-completion.schemas.d.ts +3 -0
  234. package/dist/session/phase-completion.schemas.js +836 -0
  235. package/dist/session/phase-completion.validation.d.ts +37 -0
  236. package/dist/session/phase-completion.validation.js +874 -0
  237. package/dist/session/pre-publication-host-load.d.ts +27 -0
  238. package/dist/session/pre-publication-host-load.js +111 -0
  239. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  240. package/dist/session/pre-publication-native-postgres.js +111 -0
  241. package/dist/session/pre-publication-pass.d.ts +61 -0
  242. package/dist/session/pre-publication-pass.js +148 -0
  243. package/dist/session/pre-publication-process.d.ts +23 -0
  244. package/dist/session/pre-publication-process.js +109 -0
  245. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  246. package/dist/session/pre-publication-skipped-tests.js +109 -0
  247. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  248. package/dist/session/pre-publication-step-execution.js +50 -0
  249. package/dist/session/pre-publication-validation.d.ts +91 -0
  250. package/dist/session/pre-publication-validation.js +670 -0
  251. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
  252. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
  253. package/dist/session/provider-cli/ci-repair-readiness.d.ts +16 -0
  254. package/dist/session/provider-cli/ci-repair-readiness.js +110 -0
  255. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  256. package/dist/session/provider-cli/claude-background-work.js +181 -0
  257. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  258. package/dist/session/provider-cli/host-build-lock.js +30 -0
  259. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  260. package/dist/session/provider-cli/pre-publication-repair.js +276 -0
  261. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +96 -0
  262. package/dist/session/provider-cli/provider-cli.artifacts.js +818 -0
  263. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  264. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  265. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  266. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  267. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  268. package/dist/session/provider-cli/provider-cli.deterministic-payloads.d.ts +12 -0
  269. package/dist/session/provider-cli/provider-cli.deterministic-payloads.js +279 -0
  270. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +14 -0
  271. package/dist/session/provider-cli/provider-cli.deterministic.js +407 -0
  272. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  273. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  274. package/dist/session/provider-cli/provider-cli.process.d.ts +114 -0
  275. package/dist/session/provider-cli/provider-cli.process.js +757 -0
  276. package/dist/session/provider-cli/provider-cli.prompts.d.ts +62 -0
  277. package/dist/session/provider-cli/provider-cli.prompts.js +770 -0
  278. package/dist/session/provider-cli/provider-cli.qa-sidecars.d.ts +11 -0
  279. package/dist/session/provider-cli/provider-cli.qa-sidecars.js +66 -0
  280. package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
  281. package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
  282. package/dist/session/provider-cli/provider-cli.runtime.d.ts +30 -0
  283. package/dist/session/provider-cli/provider-cli.runtime.js +120 -0
  284. package/dist/session/provider-cli/provider-cli.service.d.ts +53 -53
  285. package/dist/session/provider-cli/provider-cli.service.js +1299 -2523
  286. package/dist/session/provider-cli/provider-cli.types.d.ts +38 -0
  287. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  288. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  289. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  290. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  291. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  292. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  293. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  294. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  295. package/dist/session/provider-cli/provider-output-state.d.ts +40 -0
  296. package/dist/session/provider-cli/provider-output-state.js +832 -0
  297. package/dist/session/provider-cli/provider-usage.d.ts +9 -1
  298. package/dist/session/provider-cli/provider-usage.js +28 -5
  299. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  300. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  301. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  302. package/dist/session/publishable-worktree-changes.js +193 -0
  303. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  304. package/dist/session/qa-sidecar-validation.js +28 -0
  305. package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
  306. package/dist/session/sandbox-host-capacity-gate.js +257 -0
  307. package/dist/session/session-redaction.d.ts +3 -0
  308. package/dist/session/session-redaction.js +298 -0
  309. package/dist/session/session.base.d.ts +14 -1
  310. package/dist/session/session.service.d.ts +17 -2
  311. package/dist/session/session.service.js +708 -60
  312. package/dist/session/session.types.d.ts +327 -3
  313. package/dist/session/session.types.js +951 -10
  314. package/dist/session/sidecar-json-shape.d.ts +31 -0
  315. package/dist/session/sidecar-json-shape.js +217 -0
  316. package/dist/session/unreferenced-exports.d.ts +12 -0
  317. package/dist/session/unreferenced-exports.js +59 -0
  318. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  319. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  320. package/dist/shared/format/format-bytes.d.ts +1 -0
  321. package/dist/shared/format/format-bytes.js +9 -0
  322. package/dist/shared/fs/file-identity.d.ts +10 -0
  323. package/dist/shared/fs/file-identity.js +15 -0
  324. package/dist/shared/fs/replace-file.d.ts +7 -0
  325. package/dist/shared/fs/replace-file.js +33 -0
  326. package/dist/shared/git/git.js +2 -1
  327. package/dist/shared/path/path.d.ts +1 -0
  328. package/dist/shared/path/path.js +21 -1
  329. package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
  330. package/dist/shared/process/dotnet-toolchain.js +307 -0
  331. package/dist/shared/process/host-process-recovery.d.ts +23 -0
  332. package/dist/shared/process/host-process-recovery.js +99 -0
  333. package/dist/shared/process/host-process-supervisor.d.ts +72 -0
  334. package/dist/shared/process/host-process-supervisor.js +383 -0
  335. package/dist/shared/process/process-tree.d.ts +52 -0
  336. package/dist/shared/process/process-tree.js +144 -0
  337. package/dist/shared/process/process.d.ts +70 -0
  338. package/dist/shared/process/process.js +224 -16
  339. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  340. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  341. package/dist/shared/process/windows-launch.d.ts +26 -0
  342. package/dist/shared/process/windows-launch.js +109 -0
  343. package/dist/shared/provider-capabilities.d.ts +4 -0
  344. package/dist/shared/provider-capabilities.js +95 -0
  345. package/dist/shared/redaction/redaction.d.ts +1 -0
  346. package/dist/shared/redaction/redaction.js +47 -4
  347. package/dist/shared/time/monotonic.d.ts +1 -0
  348. package/dist/shared/time/monotonic.js +8 -0
  349. package/dist/version.d.ts +1 -1
  350. package/dist/version.js +1 -1
  351. package/dist/worktree/artifact-injector.d.ts +3 -2
  352. package/dist/worktree/artifact-injector.js +82 -10
  353. package/dist/worktree/dependency-warmer.d.ts +78 -1
  354. package/dist/worktree/dependency-warmer.js +731 -13
  355. package/dist/worktree/index.d.ts +2 -1
  356. package/dist/worktree/index.js +1 -0
  357. package/dist/worktree/prior-phase-artifact-hydrator.d.ts +2 -0
  358. package/dist/worktree/prior-phase-artifact-hydrator.js +136 -0
  359. package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
  360. package/dist/worktree/story-qa-reference-hydrator.js +253 -0
  361. package/dist/worktree/wip-git.d.ts +33 -0
  362. package/dist/worktree/wip-git.js +122 -0
  363. package/dist/worktree/wip-refs.d.ts +62 -0
  364. package/dist/worktree/wip-refs.js +119 -0
  365. package/dist/worktree/wip-restore.d.ts +38 -0
  366. package/dist/worktree/wip-restore.js +190 -0
  367. package/dist/worktree/wip-snapshot.d.ts +50 -0
  368. package/dist/worktree/wip-snapshot.js +268 -0
  369. package/dist/worktree/worktree-paths.d.ts +4 -0
  370. package/dist/worktree/worktree-paths.js +30 -0
  371. package/dist/worktree/worktree-wip-events.d.ts +18 -0
  372. package/dist/worktree/worktree-wip-events.js +98 -0
  373. package/dist/worktree/worktree-wip.d.ts +49 -0
  374. package/dist/worktree/worktree-wip.js +182 -0
  375. package/dist/worktree/worktree.base.d.ts +10 -1
  376. package/dist/worktree/worktree.service.d.ts +30 -4
  377. package/dist/worktree/worktree.service.js +379 -54
  378. package/dist/worktree/worktree.types.d.ts +38 -1
  379. package/package.json +12 -7
  380. package/runtime/windows-job-supervisor.ps1 +722 -0
  381. package/runtime/windows-listener-owner.ps1 +33 -0
@@ -0,0 +1,721 @@
1
+ import fs from "node:fs/promises";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { completionPhaseFromDispatch, completionPhaseOrder, completionRedactionSecretsEnv, completionToolNamesForDebugGate, completionToolNamesForDecomposeGate, completionToolNamesForDraftGate, completionToolNamesForPhase, completionToolNamesForQaGate, debugCompletionPhaseOrder, decomposeCompletionGateOrder, draftCompletionGateOrder, qaCompletionGateOrder, toolServerName, usesArchitectCycleCompletion, usesDebugCycleCompletion, usesDevelopCycleCompletion, usesQaCycleCompletion } from "./phase-completion.js";
5
+ import { CompletionPayloadValidationError, asDebugCompletionPhase, asJsonRpcMessage, asMutableRecord, asRecord, artifactOwnerRelativeRoot, decomposeGateFromToolName, draftGateFromToolName, errorMessage, forgeBridgeCliBinPath, isDebugCompletionPhase, isDecomposeDispatch, normalizedOwnerType, phaseFromToolName, qaGateFromToolName, requiredString, rpcError, tomlString, tomlStringArray, writeJsonRpc } from "./phase-completion.validation.js";
6
+ import { completionPromptForDebugCycle, completionPromptForDecomposeCycle, completionPromptForDevelopCycle, completionPromptForDraftCycle, completionPromptForPhase, completionPromptForQaCycle, completionToolNextInstruction, completionToolNextInstructionForDebugGate, completionToolNextInstructionForDecomposeGate, completionToolNextInstructionForDraftGate, completionToolNextInstructionForQaGate, nextDebugPhaseAfter, nextPhaseAfter } from "./phase-completion.prompts.js";
7
+ import { configuredNativeTestPostgresFallbackPath, nativeTestPostgresFallbackConfigEnvironment, } from "../runtime/native-test-postgres-fallback.js";
8
+ import { isHostLoadChildEnvironmentName } from "../runtime/host-load-child-environment.js";
9
+ import { isProviderUserConfigIsolated, providerUserConfigIsolationUnsupported } from "./provider-cli/provider-user-config-isolation.js";
10
+ import { toolDescription, toolInputSchema } from "./phase-completion.schemas.js";
11
+ import { coerceJsonStringArguments, emptyToolInputHint, isEmptyToolInput } from "./mcp-argument-coercion.js";
12
+ import { writeCompletionArtifact, writeDecomposeGateCompletionArtifact, writeDraftGateCompletionArtifact } from "./phase-completion.artifacts.js";
13
+ import { buildCompletionToolServerArgs } from "./phase-completion.mcp-args.js";
14
+ import { callManagedAttemptTool, isManagedAttemptTool, managedAttemptToolDefinition, managedAttemptToolInputSchema, managedAttemptToolNames, runWithOwnerShutdown, } from "./managed-attempt-tools.js";
15
+ export async function prepareCompletionToolRuntime(options) {
16
+ const phase = options.phase ?? completionPhaseFromDispatch(options.dispatch);
17
+ const worktreePath = path.resolve(options.worktree.worktreePath);
18
+ const workItemId = options.dispatch.workItem.id;
19
+ const ownerType = normalizedOwnerType(options.dispatch.cycleRun.ownerType) ?? "work_item";
20
+ const ownerId = options.dispatch.cycleRun.ownerId ?? workItemId;
21
+ // A managed-tools-only server records no completion artifact, so it takes no cycle mode.
22
+ const cycles = !options.managedToolsOnly;
23
+ const mcpArgs = buildCompletionToolServerArgs({
24
+ worktreePath,
25
+ workItemId,
26
+ ownerType,
27
+ ownerId,
28
+ phase,
29
+ producedBy: `${options.dispatch.execution.provider}-cli`,
30
+ managedToolsOnly: options.managedToolsOnly,
31
+ developCycle: cycles && usesDevelopCycleCompletion(options.dispatch),
32
+ qaCycle: cycles && usesQaCycleCompletion(options.dispatch),
33
+ debugCycle: cycles && usesDebugCycleCompletion(options.dispatch),
34
+ architectCycle: cycles && usesArchitectCycleCompletion(options.dispatch),
35
+ draftCycle: cycles
36
+ && (phase === "draft"
37
+ || options.dispatch.execution.lane.trim().toLowerCase() === "draft"
38
+ || options.dispatch.cycleRun.kind.trim().toLowerCase() === "draft")
39
+ && !isDecomposeDispatch(options.dispatch),
40
+ decomposeCycle: cycles && isDecomposeDispatch(options.dispatch)
41
+ });
42
+ const runtime = {
43
+ serverName: toolServerName,
44
+ command: process.execPath,
45
+ args: [forgeBridgeCliBinPath(), ...mcpArgs],
46
+ env: completionToolRuntimeEnvironment(options.runtimeEnvironment, configuredNativeTestPostgresFallbackPath(), options.hostLoadEnvironment),
47
+ cleanup: async () => undefined
48
+ };
49
+ const provider = options.dispatch.execution.provider.trim().toLowerCase();
50
+ // Provider phases refuse these at entry (admitUserConfigIsolatedProvider, provider-cli.runtime.ts);
51
+ // this guards any other caller before the Claude MCP config is written.
52
+ if (!isProviderUserConfigIsolated(provider)) {
53
+ throw providerUserConfigIsolationUnsupported(options.dispatch.execution.provider);
54
+ }
55
+ if (provider === "claude") {
56
+ return await prepareClaudeCompletionToolRuntime(runtime);
57
+ }
58
+ return runtime;
59
+ }
60
+ export function codexMcpConfigArgs(runtime) {
61
+ const prefix = `mcp_servers.${runtime.serverName}`;
62
+ const args = [
63
+ "-c",
64
+ `${prefix}.command=${tomlString(runtime.command)}`,
65
+ "-c",
66
+ `${prefix}.args=${tomlStringArray(runtime.args)}`,
67
+ "-c",
68
+ `${prefix}.default_tools_approval_mode=${tomlString("approve")}`,
69
+ "-c",
70
+ `${prefix}.tool_timeout_sec=7200`
71
+ ];
72
+ for (const [key, value] of Object.entries(runtime.env)) {
73
+ args.push("-c", `${prefix}.env.${key}=${tomlString(value)}`);
74
+ }
75
+ return args;
76
+ }
77
+ export function cursorMcpServerConfig(runtime) {
78
+ return {
79
+ command: runtime.command,
80
+ args: [...runtime.args],
81
+ env: runtime.env
82
+ };
83
+ }
84
+ export function claudeMcpServerConfig(runtime) {
85
+ return {
86
+ type: "stdio",
87
+ command: runtime.command,
88
+ args: [...runtime.args],
89
+ env: runtime.env
90
+ };
91
+ }
92
+ export function completionToolNamesForServer(config) {
93
+ return config.decomposeCycle
94
+ ? decomposeCompletionGateOrder.flatMap((gate) => completionToolNamesForDecomposeGate(gate))
95
+ : config.draftCycle
96
+ ? draftCompletionGateOrder.flatMap((gate) => completionToolNamesForDraftGate(gate))
97
+ : config.debugCycle
98
+ ? debugCompletionPhaseOrder.flatMap((gate) => completionToolNamesForDebugGate(gate))
99
+ : config.qaCycle
100
+ ? qaCompletionGateOrder.flatMap((gate) => completionToolNamesForQaGate(gate))
101
+ : config.developCycle
102
+ ? completionPhaseOrder.flatMap((phase) => completionToolNamesForPhase(phase))
103
+ : config.architectCycle
104
+ ? completionToolNamesForPhase("architect")
105
+ : completionToolNamesForPhase(config.phase);
106
+ }
107
+ const managedToolsOnlyInstructions = "Forge serves only its managed-attempt tools in this turn: "
108
+ + "forge.start_managed_verification, forge.start_managed_command, forge.wait_managed_command, forge.get_managed_command, "
109
+ + "forge.run_managed_command and forge.reset_generated_outputs. No completion tool is available; the phase's completion "
110
+ + "artifacts are already recorded and must stay as they are.";
111
+ export class CompletionToolServerSession {
112
+ config;
113
+ currentPhase;
114
+ currentQaGate = "qa_plan";
115
+ currentDraftGate = "draft_intent";
116
+ currentDecomposeGate = "decompose_subject_intake";
117
+ managedCommandReceipts = [];
118
+ completed = false;
119
+ constructor(config) {
120
+ this.config = config;
121
+ this.currentPhase = config.phase;
122
+ }
123
+ get instructions() {
124
+ return this.config.managedToolsOnly
125
+ ? managedToolsOnlyInstructions
126
+ : this.config.decomposeCycle
127
+ ? completionPromptForDecomposeCycle(this.currentDecomposeGate)
128
+ : this.config.draftCycle
129
+ ? completionPromptForDraftCycle(this.currentDraftGate)
130
+ : this.config.debugCycle
131
+ ? completionPromptForDebugCycle(asDebugCompletionPhase(this.currentPhase))
132
+ : this.config.qaCycle
133
+ ? completionPromptForQaCycle(this.currentQaGate, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId))
134
+ : this.config.developCycle
135
+ ? completionPromptForDevelopCycle(this.currentPhase)
136
+ : completionPromptForPhase(this.currentPhase, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId));
137
+ }
138
+ toolDefinitions() {
139
+ const completionTools = this.config.managedToolsOnly
140
+ ? []
141
+ : completionToolNamesForServer(this.config).map(toolDefinition);
142
+ return managedAttemptToolsAvailable()
143
+ ? [...completionTools, ...managedAttemptToolNames.map(managedAttemptToolDefinition)]
144
+ : completionTools;
145
+ }
146
+ async callTool(toolName, rawInput) {
147
+ if (isManagedAttemptTool(toolName)) {
148
+ if (!managedAttemptToolsAvailable()) {
149
+ throw new Error("Forge managed-attempt tools require an active managed host runtime.");
150
+ }
151
+ const managedInput = coerceJsonStringArguments(rawInput, managedAttemptToolInputSchema(toolName));
152
+ const result = await callManagedAttemptTool(toolName, managedInput, this.config.worktreePath);
153
+ if (Array.isArray(result.structuredContent.command)) {
154
+ this.managedCommandReceipts.push(result.structuredContent);
155
+ }
156
+ return result;
157
+ }
158
+ if (this.config.managedToolsOnly) {
159
+ throw new Error(`${toolName} is not available in this turn: Forge serves only its managed-attempt tools during a pre-publication repair turn, and the phase's completion artifacts are already recorded. Fix the failing checks and stop; Bridge reruns validation.`);
160
+ }
161
+ const requestedPhase = phaseFromToolName(toolName);
162
+ // Clients sometimes send a declared array/object argument as its JSON text.
163
+ const input = coerceJsonStringArguments(rawInput, completionToolInputSchema(toolName));
164
+ if (this.completed) {
165
+ throw new Error("Forge completion cycle is already complete; no more completion calls are accepted.");
166
+ }
167
+ if (this.config.decomposeCycle) {
168
+ return await this.callDecomposeGateTool(toolName, requestedPhase, input);
169
+ }
170
+ if (this.config.draftCycle) {
171
+ return await this.callDraftGateTool(toolName, requestedPhase, input);
172
+ }
173
+ if (this.config.debugCycle) {
174
+ return await this.callDebugGateTool(toolName, requestedPhase, input);
175
+ }
176
+ if (this.config.qaCycle) {
177
+ return await this.callQaGateTool(toolName, requestedPhase, input);
178
+ }
179
+ if (requestedPhase !== this.currentPhase) {
180
+ throw new Error(`Tool ${toolName} is out of order. Current Forge phase is ${this.currentPhase}.`);
181
+ }
182
+ const completedPhase = this.currentPhase;
183
+ const reference = await writeCompletionArtifact({ ...this.config, phase: completedPhase }, toolName, input);
184
+ const status = reference.status.trim().toLowerCase();
185
+ const pass = status === "pass";
186
+ const nextPhase = pass
187
+ ? this.advanceAfterPass(completedPhase)
188
+ : completedPhase;
189
+ const nextInstruction = completionToolNextInstruction(completedPhase, status, nextPhase);
190
+ const reason = completedPhase === "qa"
191
+ ? `QA artifact recorded locally with status ${status}; API ingestion and acceptance are pending.`
192
+ : pass
193
+ ? `${completedPhase} completion artifact accepted.`
194
+ : `${completedPhase} completion artifact recorded with status ${status}; rework is required before phase progression.`;
195
+ return {
196
+ content: [
197
+ {
198
+ type: "text",
199
+ text: `Forge recorded ${reference.phase} completion artifact ${path.relative(reference.repoPath, reference.path)} (${reference.status}, ${reference.contentHash}). ${nextInstruction}`
200
+ }
201
+ ],
202
+ structuredContent: {
203
+ ...reference,
204
+ ...acceptedArtifactReceipt(reference),
205
+ gate: {
206
+ phase: completedPhase,
207
+ status,
208
+ allowed: pass,
209
+ reason
210
+ },
211
+ nextPhase,
212
+ nextInstruction
213
+ }
214
+ };
215
+ }
216
+ async callDecomposeGateTool(toolName, requestedPhase, input) {
217
+ const requestedGate = decomposeGateFromToolName(toolName);
218
+ if (requestedPhase !== "decompose" || !requestedGate) {
219
+ throw new Error(`Tool ${toolName} is not available in Decompose-cycle mode. Current Forge Decompose gate is ${this.currentDecomposeGate}.`);
220
+ }
221
+ if (requestedGate !== this.currentDecomposeGate) {
222
+ throw new Error(`Tool ${toolName} is out of order. Current Forge Decompose gate is ${this.currentDecomposeGate}.`);
223
+ }
224
+ const completedGate = this.currentDecomposeGate;
225
+ const reference = await writeDecomposeGateCompletionArtifact(this.config, completedGate, toolName, input);
226
+ const status = reference.status.trim().toLowerCase();
227
+ const pass = status === "pass";
228
+ const nextGate = pass ? this.advanceAfterDecomposeGate(completedGate) : completedGate;
229
+ const nextPhase = pass
230
+ ? (nextGate ? "decompose" : "sign_off_ready")
231
+ : "decompose";
232
+ const nextInstruction = completionToolNextInstructionForDecomposeGate(completedGate, status, nextGate);
233
+ const reason = pass
234
+ ? nextGate
235
+ ? `${completedGate} artifact accepted; continue to ${nextGate}.`
236
+ : `Decompose proposal artifact accepted with status ${status}.`
237
+ : `${completedGate} artifact recorded with status ${status}; rework is required before continuing.`;
238
+ return {
239
+ content: [{ type: "text", text: `Forge recorded ${completedGate} artifact ${path.relative(reference.repoPath, reference.path)} (${reference.status}, ${reference.contentHash}). ${nextInstruction}` }],
240
+ structuredContent: {
241
+ ...reference,
242
+ ...acceptedArtifactReceipt(reference),
243
+ gate: { phase: "decompose", decomposeGate: completedGate, status, allowed: pass, reason },
244
+ nextPhase,
245
+ nextInstruction
246
+ }
247
+ };
248
+ }
249
+ async callDraftGateTool(toolName, requestedPhase, input) {
250
+ const requestedGate = draftGateFromToolName(toolName);
251
+ if (requestedPhase !== "draft" || !requestedGate) {
252
+ throw new Error(`Tool ${toolName} is not available in Draft-cycle mode. Current Forge Draft gate is ${this.currentDraftGate}.`);
253
+ }
254
+ if (requestedGate !== this.currentDraftGate) {
255
+ throw new Error(`Tool ${toolName} is out of order. Current Forge Draft gate is ${this.currentDraftGate}.`);
256
+ }
257
+ const completedGate = this.currentDraftGate;
258
+ const reference = await writeDraftGateCompletionArtifact(this.config, completedGate, toolName, input);
259
+ const status = reference.status.trim().toLowerCase();
260
+ // Only a pass completes a Draft gate; needs_revision, needs_rework, and blocked keep the same
261
+ // gate selected so it is retried, never skipped.
262
+ const pass = status === "pass";
263
+ const nextGate = pass ? this.advanceAfterDraftGate(completedGate) : completedGate;
264
+ const nextPhase = pass ? (nextGate ? "draft" : "sign_off_ready") : "draft";
265
+ const nextInstruction = completionToolNextInstructionForDraftGate(completedGate, status, pass ? nextGate : null);
266
+ return {
267
+ content: [{ type: "text", text: `Forge recorded ${completedGate} artifact ${path.relative(reference.repoPath, reference.path)} (${reference.status}, ${reference.contentHash}). ${nextInstruction}` }],
268
+ structuredContent: {
269
+ ...reference,
270
+ ...acceptedArtifactReceipt(reference),
271
+ gate: {
272
+ phase: "draft",
273
+ draftGate: completedGate,
274
+ status,
275
+ allowed: pass,
276
+ reason: !pass
277
+ ? `${completedGate} artifact recorded with status ${status}; rework is required before continuing.`
278
+ : nextGate ? `${completedGate} artifact accepted; continue to ${nextGate}.` : `Draft proposal artifact accepted with status ${status}.`
279
+ },
280
+ nextPhase,
281
+ nextInstruction
282
+ }
283
+ };
284
+ }
285
+ async callDebugGateTool(toolName, requestedPhase, input) {
286
+ const currentDebugGate = asDebugCompletionPhase(this.currentPhase);
287
+ if (!isDebugCompletionPhase(requestedPhase)) {
288
+ throw new Error(`Tool ${toolName} is not available in Debug-cycle mode. Current Forge Debug gate is ${currentDebugGate}.`);
289
+ }
290
+ if (requestedPhase !== currentDebugGate) {
291
+ throw new Error(`Tool ${toolName} is out of order. Current Forge Debug gate is ${currentDebugGate}.`);
292
+ }
293
+ const completedGate = currentDebugGate;
294
+ const reference = await writeCompletionArtifact({ ...this.config, phase: completedGate }, toolName, input);
295
+ const status = reference.status.trim().toLowerCase();
296
+ const pass = status === "pass";
297
+ const nextGate = pass ? this.advanceAfterDebugGate(completedGate) : completedGate;
298
+ const nextPhase = nextGate ?? "qa_ready";
299
+ const nextInstruction = completionToolNextInstructionForDebugGate(completedGate, status, nextGate);
300
+ const reason = pass
301
+ ? `${completedGate} artifact accepted${nextGate ? `; continue to ${nextGate}.` : "; Debug regression is QA-ready."}`
302
+ : `${completedGate} artifact recorded with status ${status}; rework is required before Debug progression.`;
303
+ return {
304
+ content: [
305
+ {
306
+ type: "text",
307
+ text: `Forge recorded ${completedGate} artifact ${path.relative(reference.repoPath, reference.path)} (${reference.status}, ${reference.contentHash}). ${nextInstruction}`
308
+ }
309
+ ],
310
+ structuredContent: {
311
+ ...reference,
312
+ ...acceptedArtifactReceipt(reference),
313
+ gate: {
314
+ phase: completedGate,
315
+ status,
316
+ allowed: pass,
317
+ reason
318
+ },
319
+ nextPhase,
320
+ nextInstruction
321
+ }
322
+ };
323
+ }
324
+ async callQaGateTool(toolName, requestedPhase, input) {
325
+ const requestedGate = qaGateFromToolName(toolName);
326
+ if (requestedPhase !== "qa" || !requestedGate) {
327
+ throw new Error(`Tool ${toolName} is not available in QA-cycle mode. Current Forge QA gate is ${this.currentQaGate}.`);
328
+ }
329
+ if (requestedGate !== this.currentQaGate) {
330
+ throw new Error(`Tool ${toolName} is out of order. Current Forge QA gate is ${this.currentQaGate}.`);
331
+ }
332
+ const completedGate = this.currentQaGate;
333
+ if (completedGate === "qa_regression" && managedAttemptToolsAvailable()) {
334
+ assertManagedQaRegressionEvidence(input, this.managedCommandReceipts);
335
+ }
336
+ const reference = await writeCompletionArtifact({ ...this.config, phase: "qa" }, toolName, input);
337
+ const status = reference.status.trim().toLowerCase();
338
+ const nextGate = this.advanceAfterQaGate(completedGate);
339
+ const nextPhase = nextGate ? "qa" : "sign_off_ready";
340
+ const nextInstruction = completionToolNextInstructionForQaGate(completedGate, status, nextGate);
341
+ const allowed = status !== "blocked";
342
+ const reason = nextGate
343
+ ? `${completedGate} artifact accepted locally; continue to ${nextGate}.`
344
+ : `QA verdict artifact recorded locally with status ${status}; API ingestion and acceptance are pending.`;
345
+ return {
346
+ content: [
347
+ {
348
+ type: "text",
349
+ text: `Forge recorded ${completedGate} artifact ${path.relative(reference.repoPath, reference.path)} (${reference.status}, ${reference.contentHash}). ${nextInstruction}`
350
+ }
351
+ ],
352
+ structuredContent: {
353
+ ...reference,
354
+ ...acceptedArtifactReceipt(reference),
355
+ gate: {
356
+ phase: "qa",
357
+ qaGate: completedGate,
358
+ status,
359
+ allowed,
360
+ reason
361
+ },
362
+ nextPhase,
363
+ nextInstruction
364
+ }
365
+ };
366
+ }
367
+ advanceAfterPass(phase) {
368
+ if (phase === "qa") {
369
+ this.completed = true;
370
+ return "sign_off_ready";
371
+ }
372
+ if (phase === "ci_repair") {
373
+ this.completed = true;
374
+ return "provider_checks_ready";
375
+ }
376
+ if (isDebugCompletionPhase(phase)) {
377
+ return nextDebugPhaseAfter(phase) ?? "qa_ready";
378
+ }
379
+ const next = nextPhaseAfter(phase);
380
+ if (!this.config.developCycle) {
381
+ return next ?? "dev_test_ready";
382
+ }
383
+ if (next) {
384
+ this.currentPhase = next;
385
+ return next;
386
+ }
387
+ this.completed = true;
388
+ return "dev_test_ready";
389
+ }
390
+ advanceAfterDecomposeGate(gate) {
391
+ const index = decomposeCompletionGateOrder.indexOf(gate);
392
+ const next = index >= 0 ? decomposeCompletionGateOrder[index + 1] ?? null : null;
393
+ if (next) {
394
+ this.currentDecomposeGate = next;
395
+ return next;
396
+ }
397
+ this.completed = true;
398
+ return null;
399
+ }
400
+ advanceAfterDraftGate(gate) {
401
+ const index = draftCompletionGateOrder.indexOf(gate);
402
+ const next = index >= 0 ? draftCompletionGateOrder[index + 1] ?? null : null;
403
+ if (next) {
404
+ this.currentDraftGate = next;
405
+ return next;
406
+ }
407
+ this.completed = true;
408
+ return null;
409
+ }
410
+ advanceAfterQaGate(gate) {
411
+ const index = qaCompletionGateOrder.indexOf(gate);
412
+ const next = index >= 0 ? qaCompletionGateOrder[index + 1] ?? null : null;
413
+ if (next) {
414
+ this.currentQaGate = next;
415
+ return next;
416
+ }
417
+ this.completed = true;
418
+ return null;
419
+ }
420
+ advanceAfterDebugGate(gate) {
421
+ const index = debugCompletionPhaseOrder.indexOf(gate);
422
+ const next = index >= 0 ? debugCompletionPhaseOrder[index + 1] ?? null : null;
423
+ if (next) {
424
+ this.currentPhase = next;
425
+ return next;
426
+ }
427
+ this.completed = true;
428
+ return null;
429
+ }
430
+ }
431
+ const completionToolRuntimeEnvironmentNames = [
432
+ "FORGE_RUNTIME_MODE",
433
+ "FORGE_RESOURCE_LEASE_ID",
434
+ "FORGE_DISPATCH_ATTEMPT_ID",
435
+ "FORGE_E2E_OWNERSHIP_MODE",
436
+ "FORGE_E2E_OWNERSHIP_TOKEN",
437
+ "FORGE_WORKTREE_PATH",
438
+ "FORGE_LOG_DIR",
439
+ "FORGE_CACHE_DIR",
440
+ "FORGE_TEST_OUTPUT_DIR",
441
+ "FORGE_ATTEMPT_DATABASE_SCHEMA",
442
+ "FORGE_ATTEMPT_DATABASE_READINESS_PATH",
443
+ "FORGE_ATTEMPT_DATABASE_CAPABILITY",
444
+ "FORGE_CI_REPAIR_READINESS_PATH",
445
+ "FORGE_CI_REPAIR_HANDOFF_PATH",
446
+ "FORGE_CI_REPAIR_PROVIDER_ONLY_SPECS",
447
+ "FORGE_PLAYWRIGHT_CONFIG",
448
+ "FORGE_API_URL",
449
+ "FORGE_WEB_URL",
450
+ "FORGE_E2E_API_URL",
451
+ "FORGE_E2E_WEB_URL",
452
+ "PLAYWRIGHT_BROWSERS_PATH",
453
+ "FORGE_TMPDIR",
454
+ "NPM_CONFIG_CACHE",
455
+ "TMPDIR",
456
+ "TMP",
457
+ "TEMP",
458
+ ];
459
+ export function completionToolRuntimeEnvironment(runtimeEnvironment, nativeTestPostgresFallbackPath, hostLoadEnvironment) {
460
+ const env = {};
461
+ // Without a runtime environment the server gets nothing from it, but it still
462
+ // joins the host ledger when the bridge handed it the governor's variables.
463
+ if (!runtimeEnvironment && !hostLoadEnvironment)
464
+ return env;
465
+ for (const name of completionToolRuntimeEnvironmentNames) {
466
+ const value = runtimeEnvironment?.[name]?.trim();
467
+ if (value)
468
+ env[name] = value;
469
+ }
470
+ // The host load governor's flag, state root and tuning: managed commands join its ledger.
471
+ for (const [name, value] of Object.entries(hostLoadEnvironment ?? {})) {
472
+ if (isHostLoadChildEnvironmentName(name) && value.trim())
473
+ env[name] = value.trim();
474
+ }
475
+ // Managed verification reads the operator's native test cluster only through
476
+ // this explicit path; the file's `use` decides whether Docker comes first.
477
+ if (runtimeEnvironment && nativeTestPostgresFallbackPath) {
478
+ env[nativeTestPostgresFallbackConfigEnvironment] = nativeTestPostgresFallbackPath;
479
+ }
480
+ return env;
481
+ }
482
+ const minimumManagedSolutionTestTimeoutMs = 45 * 60 * 1000;
483
+ /**
484
+ * A solution-wide Forge test is long enough that a generic provider shell can
485
+ * expire while VSTest is still healthy. On managed host attempts, only the
486
+ * attempt-owned command runner can prove the exact process outcome and clean
487
+ * up its process tree. Keep this check at the completion gate so prompt drift
488
+ * cannot turn an arbitrary shell timeout into a QA blocker.
489
+ */
490
+ export function assertManagedQaRegressionEvidence(input, receipts) {
491
+ const payload = asRecord(input, "QA regression completion payload");
492
+ const nestedEvidence = asMutableRecord(payload.evidence);
493
+ const commands = payload.commands ?? nestedEvidence.commands;
494
+ if (!Array.isArray(commands))
495
+ return;
496
+ for (const [index, entry] of commands.entries()) {
497
+ if (!entry || typeof entry !== "object" || Array.isArray(entry))
498
+ continue;
499
+ const command = entry.command;
500
+ if (typeof command !== "string" || !isForgeSolutionTestCommand(command))
501
+ continue;
502
+ const managedCommandId = entry.managed_command_id;
503
+ if (typeof managedCommandId !== "string" || !managedCommandId.trim()) {
504
+ throw new Error(`qa_regression_managed_command_id_required: commands[${index}] runs the solution-wide Forge test. `
505
+ + "Run it with forge.start_managed_command, continue independent work, then call forge.wait_managed_command for a transport-safe receipt. "
506
+ + "If command_continues=true, continue useful work or wait again after retry_after_ms. Include the terminal managed_command_id in this command evidence.");
507
+ }
508
+ const matchingReceipts = receipts.filter((receipt) => {
509
+ const tokens = receipt.command;
510
+ return receipt.command_id === managedCommandId
511
+ && Array.isArray(tokens)
512
+ && tokens.every((token) => typeof token === "string")
513
+ && isForgeSolutionTestCommand(tokens.join(" "));
514
+ });
515
+ if (matchingReceipts.length === 0) {
516
+ throw new Error(`qa_regression_managed_command_required: commands[${index}] runs the solution-wide Forge test. `
517
+ + "Run it with forge.start_managed_command, continue independent work, then call forge.wait_managed_command for a transport-safe receipt. "
518
+ + "If command_continues=true, continue useful work or wait again after retry_after_ms. Include its matching terminal managed_command_id; generic-shell timeout evidence is not accepted on a managed host.");
519
+ }
520
+ const terminalReceipts = matchingReceipts.filter((receipt) => typeof receipt.status === "string" && [
521
+ "pass",
522
+ "fail",
523
+ "timed_out",
524
+ "timeout_termination_failed",
525
+ "runner_error",
526
+ ].includes(receipt.status));
527
+ if (terminalReceipts.length === 0) {
528
+ throw new Error(`qa_regression_managed_command_in_progress: commands[${index}] has not produced a terminal managed receipt. `
529
+ + "Call forge.wait_managed_command. If command_continues=true, continue useful work or wait again after retry_after_ms; resubmit this gate only after the receipt is terminal.");
530
+ }
531
+ const adequateReceipt = terminalReceipts.some((receipt) => {
532
+ if (receipt.timed_out !== true)
533
+ return true;
534
+ return typeof receipt.timeout_ms === "number"
535
+ && receipt.timeout_ms >= minimumManagedSolutionTestTimeoutMs
536
+ && receipt.process_tree_terminated === true;
537
+ });
538
+ if (!adequateReceipt) {
539
+ throw new Error(`qa_regression_managed_timeout_too_short: commands[${index}] timed out before the minimum `
540
+ + `${minimumManagedSolutionTestTimeoutMs}ms solution-test budget. Rerun it with forge.start_managed_command `
541
+ + "using at least a 45-minute timeout and resubmit this gate.");
542
+ }
543
+ }
544
+ }
545
+ function isForgeSolutionTestCommand(command) {
546
+ const normalized = command.trim().toLowerCase().replaceAll("\\", "/");
547
+ return normalized.includes("dotnet")
548
+ && /(?:^|\s)test(?:\s|$)/u.test(normalized)
549
+ && /(?:^|[\s/"'])forge\.sln(?:[\s"']|$)/u.test(normalized);
550
+ }
551
+ function managedAttemptToolsAvailable() {
552
+ return process.env.FORGE_RUNTIME_MODE === "host"
553
+ && Boolean(process.env.FORGE_RESOURCE_LEASE_ID?.trim())
554
+ && Boolean(process.env.FORGE_DISPATCH_ATTEMPT_ID?.trim())
555
+ && Boolean(process.env.FORGE_LOG_DIR?.trim())
556
+ && Boolean(process.env.FORGE_TEST_OUTPUT_DIR?.trim());
557
+ }
558
+ export async function runCompletionMcpServer(config) {
559
+ const session = new CompletionToolServerSession(config);
560
+ // This server is the only supervisor of the managed commands it starts, and they run in
561
+ // their own process groups. When the provider closes the connection or stops this server,
562
+ // stop them first so none outlives its supervisor and receipt writer.
563
+ await runWithOwnerShutdown(async () => {
564
+ process.stdin.setEncoding("utf8");
565
+ let buffer = "";
566
+ for await (const chunk of process.stdin) {
567
+ buffer += chunk;
568
+ let newlineIndex = buffer.indexOf("\n");
569
+ while (newlineIndex >= 0) {
570
+ const rawLine = buffer.slice(0, newlineIndex).trim();
571
+ buffer = buffer.slice(newlineIndex + 1);
572
+ if (rawLine.length > 0) {
573
+ await handleJsonRpcLine(session, rawLine);
574
+ }
575
+ newlineIndex = buffer.indexOf("\n");
576
+ }
577
+ }
578
+ const trailing = buffer.trim();
579
+ if (trailing.length > 0) {
580
+ await handleJsonRpcLine(session, trailing);
581
+ }
582
+ });
583
+ }
584
+ export function completionRedactionEnv(secrets) {
585
+ const filtered = secrets.filter((secret) => secret.length > 0);
586
+ return filtered.length > 0
587
+ ? { [completionRedactionSecretsEnv]: JSON.stringify(filtered) }
588
+ : {};
589
+ }
590
+ /**
591
+ * Claude Code takes MCP servers from `--mcp-config <file>`. The file lives in an attempt-owned
592
+ * temp directory (never the worktree) because its env block can carry redaction secrets, and
593
+ * passing the JSON inline would not survive Windows shim quoting.
594
+ */
595
+ async function prepareClaudeCompletionToolRuntime(runtime) {
596
+ const configDir = await fs.mkdtemp(path.join(os.tmpdir(), "forge-claude-mcp-"));
597
+ const configPath = path.join(configDir, "mcp.json");
598
+ const config = {
599
+ mcpServers: {
600
+ [runtime.serverName]: claudeMcpServerConfig(runtime)
601
+ }
602
+ };
603
+ await fs.writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
604
+ return {
605
+ ...runtime,
606
+ claudeMcpConfigPath: configPath,
607
+ cleanup: async () => {
608
+ await fs.rm(configDir, { recursive: true, force: true });
609
+ }
610
+ };
611
+ }
612
+ async function handleJsonRpcLine(session, rawLine) {
613
+ let message;
614
+ try {
615
+ message = JSON.parse(rawLine);
616
+ }
617
+ catch (error) {
618
+ writeJsonRpc({ jsonrpc: "2.0", id: null, error: rpcError(-32700, errorMessage(error)) });
619
+ return;
620
+ }
621
+ const request = asJsonRpcMessage(message);
622
+ if (!request) {
623
+ writeJsonRpc({ jsonrpc: "2.0", id: null, error: rpcError(-32600, "Invalid JSON-RPC message.") });
624
+ return;
625
+ }
626
+ if (request.id === undefined) {
627
+ return;
628
+ }
629
+ try {
630
+ const result = await handleJsonRpcRequest(session, request.method, request.params);
631
+ writeJsonRpc({ jsonrpc: "2.0", id: request.id, result });
632
+ }
633
+ catch (error) {
634
+ writeJsonRpc({ jsonrpc: "2.0", id: request.id, error: rpcError(-32000, errorMessage(error)) });
635
+ }
636
+ }
637
+ async function handleJsonRpcRequest(session, method, params) {
638
+ if (method === "initialize") {
639
+ const initializeParams = params && typeof params === "object" && !Array.isArray(params)
640
+ ? params
641
+ : {};
642
+ return {
643
+ protocolVersion: typeof initializeParams.protocolVersion === "string" ? initializeParams.protocolVersion : "2025-06-18",
644
+ capabilities: {
645
+ tools: {}
646
+ },
647
+ serverInfo: {
648
+ name: "forge-completion-tools",
649
+ version: "0.1.0"
650
+ },
651
+ instructions: session.instructions
652
+ };
653
+ }
654
+ if (method === "ping") {
655
+ return {};
656
+ }
657
+ if (method === "tools/list") {
658
+ return {
659
+ tools: session.toolDefinitions()
660
+ };
661
+ }
662
+ if (method === "tools/call") {
663
+ const call = asRecord(params, "tools/call params");
664
+ const name = requiredString(call, "name");
665
+ const args = call.arguments ?? {};
666
+ try {
667
+ return await session.callTool(name, args);
668
+ }
669
+ catch (error) {
670
+ if (isManagedAttemptTool(name))
671
+ throw error;
672
+ return completionToolRejectedResult(name, error, args);
673
+ }
674
+ }
675
+ throw new Error(`Unsupported MCP method: ${method}`);
676
+ }
677
+ export function completionToolRejectedResult(toolName, error, input) {
678
+ const issues = error instanceof CompletionPayloadValidationError
679
+ ? [...error.issues]
680
+ : [errorMessage(error)];
681
+ if (input !== undefined && isEmptyToolInput(input)) {
682
+ issues.push(`${emptyToolInputHint} Keep long free text such as report_markdown short.`);
683
+ }
684
+ const repairInstruction = "Repair every listed issue and resubmit this same gate once. Do not inspect the artifact path: rejected calls never write or replace completion artifacts.";
685
+ return {
686
+ content: [{
687
+ type: "text",
688
+ text: `Forge rejected ${toolName}. No artifact was written.\n${issues.map(issue => `- ${issue}`).join("\n")}\n${repairInstruction}`,
689
+ }],
690
+ structuredContent: {
691
+ status: "rejected",
692
+ tool_name: toolName,
693
+ artifact_written: false,
694
+ issues,
695
+ repair_instruction: repairInstruction,
696
+ },
697
+ isError: true,
698
+ };
699
+ }
700
+ function acceptedArtifactReceipt(reference) {
701
+ return {
702
+ artifact_written: true,
703
+ artifact_receipt: {
704
+ schema_version: 1,
705
+ path: reference.path,
706
+ report_path: reference.reportPath,
707
+ content_hash: reference.contentHash,
708
+ },
709
+ };
710
+ }
711
+ function toolDefinition(name) {
712
+ return {
713
+ name,
714
+ description: toolDescription(phaseFromToolName(name), qaGateFromToolName(name), decomposeGateFromToolName(name), draftGateFromToolName(name)),
715
+ inputSchema: completionToolInputSchema(name)
716
+ };
717
+ }
718
+ /** The input schema a completion tool advertises; also the shape its arguments are coerced to. */
719
+ export function completionToolInputSchema(name) {
720
+ return toolInputSchema(phaseFromToolName(name), qaGateFromToolName(name), decomposeGateFromToolName(name), draftGateFromToolName(name));
721
+ }