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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (329) hide show
  1. package/README.md +183 -4
  2. package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
  3. package/dist/bridge/bridge-chat-giphy-look.js +55 -0
  4. package/dist/bridge/bridge-chat-provider-command.d.ts +40 -0
  5. package/dist/bridge/bridge-chat-provider-command.js +230 -0
  6. package/dist/bridge/bridge-chat.types.d.ts +20 -0
  7. package/dist/bridge/bridge-chat.types.js +28 -1
  8. package/dist/bridge/bridge-state-file.d.ts +161 -0
  9. package/dist/bridge/bridge-state-file.js +376 -0
  10. package/dist/bridge/bridge-state-io.d.ts +15 -0
  11. package/dist/bridge/bridge-state-io.js +68 -0
  12. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  13. package/dist/bridge/bridge-state-lock.js +102 -0
  14. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  15. package/dist/bridge/bridge-state-unpublished.js +111 -0
  16. package/dist/bridge/bridge.base.d.ts +9 -0
  17. package/dist/bridge/bridge.service.d.ts +102 -14
  18. package/dist/bridge/bridge.service.js +499 -471
  19. package/dist/bridge/bridge.types.d.ts +37 -0
  20. package/dist/bridge/bridge.types.js +2 -1
  21. package/dist/bridge/default-session-service.d.ts +13 -0
  22. package/dist/bridge/default-session-service.js +22 -0
  23. package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
  24. package/dist/bridge/dispatch-offer-policy.js +58 -0
  25. package/dist/bridge/in-flight-registry.d.ts +62 -0
  26. package/dist/bridge/in-flight-registry.js +207 -0
  27. package/dist/bridge/local-yield-flag.d.ts +6 -0
  28. package/dist/bridge/local-yield-flag.js +34 -0
  29. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  30. package/dist/bridge/readiness-result-outbox.js +20 -0
  31. package/dist/bridge/runner-host-capabilities.d.ts +5 -0
  32. package/dist/bridge/runner-host-capabilities.js +31 -1
  33. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  34. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  35. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  36. package/dist/bridge/test-postgres-capability.js +120 -0
  37. package/dist/bridge/windows-bash-resolution.d.ts +31 -0
  38. package/dist/bridge/windows-bash-resolution.js +153 -0
  39. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  40. package/dist/cleanup/cleanup-wip.js +66 -0
  41. package/dist/cleanup/cleanup.service.d.ts +20 -1
  42. package/dist/cleanup/cleanup.service.js +150 -169
  43. package/dist/cleanup/cleanup.types.d.ts +6 -0
  44. package/dist/cleanup/forge-owned-paths.d.ts +11 -0
  45. package/dist/cleanup/forge-owned-paths.js +62 -0
  46. package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
  47. package/dist/cleanup/host-runtime-ledger.js +130 -0
  48. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  49. package/dist/cleanup/managed-branch-sweep.js +111 -0
  50. package/dist/cli/cli.help.js +75 -13
  51. package/dist/cli/cli.service.d.ts +19 -10
  52. package/dist/cli/cli.service.js +161 -228
  53. package/dist/cli/idle-status.d.ts +84 -0
  54. package/dist/cli/idle-status.js +181 -0
  55. package/dist/cli/local-config.d.ts +18 -1
  56. package/dist/cli/local-config.js +67 -5
  57. package/dist/cli/provider-cli-advertising.d.ts +24 -0
  58. package/dist/cli/provider-cli-advertising.js +88 -0
  59. package/dist/cli/provider-cli-detection.d.ts +10 -0
  60. package/dist/cli/provider-cli-detection.js +160 -0
  61. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  62. package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
  63. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  64. package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
  65. package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
  66. package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
  67. package/dist/runtime/attempt-process-supervisor.js +12 -6
  68. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  69. package/dist/runtime/docker-engine-probe.js +7 -0
  70. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  71. package/dist/runtime/dotnet-build-outputs.js +402 -0
  72. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  73. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  74. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  75. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  76. package/dist/runtime/host-facts.d.ts +2 -1
  77. package/dist/runtime/host-listener-inspector.d.ts +26 -0
  78. package/dist/runtime/host-listener-inspector.js +84 -3
  79. package/dist/runtime/host-load-admission.d.ts +72 -0
  80. package/dist/runtime/host-load-admission.js +99 -0
  81. package/dist/runtime/host-load-capacity.d.ts +198 -0
  82. package/dist/runtime/host-load-capacity.js +353 -0
  83. package/dist/runtime/host-load-child-environment.d.ts +40 -0
  84. package/dist/runtime/host-load-child-environment.js +110 -0
  85. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  86. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  87. package/dist/runtime/host-load-governor-config.d.ts +82 -0
  88. package/dist/runtime/host-load-governor-config.js +104 -0
  89. package/dist/runtime/host-load-governor.d.ts +273 -0
  90. package/dist/runtime/host-load-governor.js +831 -0
  91. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  92. package/dist/runtime/host-load-ledger-lock.js +187 -0
  93. package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
  94. package/dist/runtime/host-load-live-test-slots.js +193 -0
  95. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  96. package/dist/runtime/host-load-runtime-settings.js +80 -0
  97. package/dist/runtime/host-load-sampler.d.ts +92 -2
  98. package/dist/runtime/host-load-sampler.js +166 -8
  99. package/dist/runtime/host-load-step-class.d.ts +70 -0
  100. package/dist/runtime/host-load-step-class.js +161 -0
  101. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  102. package/dist/runtime/host-load-step-reaper.js +95 -0
  103. package/dist/runtime/host-load-step-run.d.ts +107 -0
  104. package/dist/runtime/host-load-step-run.js +158 -0
  105. package/dist/runtime/host-load-test-slot.d.ts +46 -0
  106. package/dist/runtime/host-load-test-slot.js +100 -0
  107. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  108. package/dist/runtime/host-load-token-ledger.js +453 -0
  109. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  110. package/dist/runtime/host-load-windows-cpu.js +85 -0
  111. package/dist/runtime/host-pressure-stall.d.ts +21 -1
  112. package/dist/runtime/host-pressure-stall.js +48 -1
  113. package/dist/runtime/host-runtime-contract.d.ts +15 -0
  114. package/dist/runtime/host-runtime-contract.js +39 -6
  115. package/dist/runtime/host-runtime-lease.d.ts +101 -6
  116. package/dist/runtime/host-runtime-lease.js +408 -294
  117. package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
  118. package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
  119. package/dist/runtime/host-runtime-promotion.d.ts +101 -2
  120. package/dist/runtime/host-runtime-promotion.js +355 -14
  121. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  122. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  123. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  124. package/dist/runtime/host-runtime-requirements.js +117 -0
  125. package/dist/runtime/managed-command-teardown.js +5 -16
  126. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  127. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  128. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  129. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  130. package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
  131. package/dist/runtime/prepared-runtime-identity.js +130 -9
  132. package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
  133. package/dist/runtime/prepared-runtime-readiness.js +89 -18
  134. package/dist/runtime/runner-settings.d.ts +104 -0
  135. package/dist/runtime/runner-settings.js +236 -0
  136. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  137. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  138. package/dist/sandbox/host-capacity-broker.d.ts +115 -0
  139. package/dist/sandbox/host-capacity-broker.js +336 -0
  140. package/dist/sandbox/managed-branch.d.ts +13 -0
  141. package/dist/sandbox/managed-branch.js +90 -0
  142. package/dist/sandbox/provider-auth/codex.js +11 -11
  143. package/dist/sandbox/runtime.d.ts +11 -3
  144. package/dist/sandbox/runtime.js +53 -20
  145. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  146. package/dist/sandbox/sandbox-cgroups.js +42 -0
  147. package/dist/sandbox/sandbox-input.d.ts +22 -0
  148. package/dist/sandbox/sandbox-input.js +49 -0
  149. package/dist/sandbox/workspace.service.js +15 -2
  150. package/dist/session/architect-waits.d.ts +2 -0
  151. package/dist/session/architect-waits.js +138 -0
  152. package/dist/session/managed-attempt-tools.d.ts +2 -7
  153. package/dist/session/managed-attempt-tools.js +204 -141
  154. package/dist/session/managed-build-coordinator.d.ts +16 -0
  155. package/dist/session/managed-build-coordinator.js +10 -0
  156. package/dist/session/managed-build-receipt.d.ts +7 -0
  157. package/dist/session/managed-build-receipt.js +11 -3
  158. package/dist/session/managed-command-environment.d.ts +8 -0
  159. package/dist/session/managed-command-environment.js +28 -0
  160. package/dist/session/managed-command-host-load.d.ts +52 -0
  161. package/dist/session/managed-command-host-load.js +87 -0
  162. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  163. package/dist/session/mcp-argument-coercion.js +121 -0
  164. package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
  165. package/dist/session/phase-completion.artifact-bundle.js +167 -0
  166. package/dist/session/phase-completion.artifacts.d.ts +9 -17
  167. package/dist/session/phase-completion.artifacts.js +158 -190
  168. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  169. package/dist/session/phase-completion.command-validation.js +77 -0
  170. package/dist/session/phase-completion.d.ts +31 -2
  171. package/dist/session/phase-completion.helpers.js +18 -65
  172. package/dist/session/phase-completion.js +19 -32
  173. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  174. package/dist/session/phase-completion.mcp-args.js +195 -0
  175. package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
  176. package/dist/session/phase-completion.phase-aliases.js +43 -0
  177. package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
  178. package/dist/session/phase-completion.pr-review-schema.js +75 -0
  179. package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
  180. package/dist/session/phase-completion.pr-review-validation.js +212 -0
  181. package/dist/session/phase-completion.pr-review.d.ts +36 -0
  182. package/dist/session/phase-completion.pr-review.js +294 -0
  183. package/dist/session/phase-completion.prompts.d.ts +1 -1
  184. package/dist/session/phase-completion.prompts.js +20 -1
  185. package/dist/session/phase-completion.runtime.d.ts +13 -12
  186. package/dist/session/phase-completion.runtime.js +113 -214
  187. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  188. package/dist/session/phase-completion.schema-parts.js +188 -0
  189. package/dist/session/phase-completion.schemas.d.ts +3 -3
  190. package/dist/session/phase-completion.schemas.js +219 -232
  191. package/dist/session/phase-completion.validation.d.ts +3 -3
  192. package/dist/session/phase-completion.validation.js +58 -94
  193. package/dist/session/pr-review-diff-base.d.ts +18 -0
  194. package/dist/session/pr-review-diff-base.js +44 -0
  195. package/dist/session/pr-review-placement.d.ts +50 -0
  196. package/dist/session/pr-review-placement.js +91 -0
  197. package/dist/session/pre-publication-change-set.d.ts +62 -0
  198. package/dist/session/pre-publication-change-set.js +166 -0
  199. package/dist/session/pre-publication-host-load.d.ts +27 -0
  200. package/dist/session/pre-publication-host-load.js +112 -0
  201. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  202. package/dist/session/pre-publication-native-postgres.js +111 -0
  203. package/dist/session/pre-publication-pass.d.ts +61 -0
  204. package/dist/session/pre-publication-pass.js +148 -0
  205. package/dist/session/pre-publication-process.d.ts +3 -0
  206. package/dist/session/pre-publication-process.js +32 -19
  207. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  208. package/dist/session/pre-publication-step-execution.js +50 -0
  209. package/dist/session/pre-publication-validation.d.ts +39 -22
  210. package/dist/session/pre-publication-validation.js +241 -207
  211. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  212. package/dist/session/provider-cli/claude-background-work.js +181 -0
  213. package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
  214. package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
  215. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  216. package/dist/session/provider-cli/host-build-lock.js +30 -0
  217. package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
  218. package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
  219. package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
  220. package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
  221. package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
  222. package/dist/session/provider-cli/pr-review-prompt.js +119 -0
  223. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  224. package/dist/session/provider-cli/pre-publication-repair.js +281 -0
  225. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  226. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  227. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  228. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  229. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  230. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
  231. package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
  232. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
  233. package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
  234. package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
  235. package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
  236. package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
  237. package/dist/session/provider-cli/provider-cli.process.js +41 -432
  238. package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -3
  239. package/dist/session/provider-cli/provider-cli.prompts.js +183 -90
  240. package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
  241. package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
  242. package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
  243. package/dist/session/provider-cli/provider-cli.runtime.js +43 -1
  244. package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
  245. package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
  246. package/dist/session/provider-cli/provider-cli.service.d.ts +18 -18
  247. package/dist/session/provider-cli/provider-cli.service.js +127 -317
  248. package/dist/session/provider-cli/provider-cli.types.d.ts +35 -0
  249. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  250. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  251. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  252. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  253. package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
  254. package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
  255. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  256. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  257. package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
  258. package/dist/session/provider-cli/provider-output-state.js +6 -0
  259. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  260. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  261. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  262. package/dist/session/qa-sidecar-validation.js +28 -0
  263. package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
  264. package/dist/session/sandbox-host-capacity-gate.js +279 -0
  265. package/dist/session/session-host-project.d.ts +22 -0
  266. package/dist/session/session-host-project.js +98 -0
  267. package/dist/session/session-redaction.js +31 -181
  268. package/dist/session/session.base.d.ts +9 -1
  269. package/dist/session/session.parse-helpers.d.ts +10 -0
  270. package/dist/session/session.parse-helpers.js +84 -0
  271. package/dist/session/session.runtime-refresh.d.ts +46 -0
  272. package/dist/session/session.runtime-refresh.js +116 -0
  273. package/dist/session/session.service.d.ts +16 -2
  274. package/dist/session/session.service.js +208 -155
  275. package/dist/session/session.types.d.ts +8 -0
  276. package/dist/session/session.types.js +13 -83
  277. package/dist/session/session.types.pr-review.d.ts +48 -0
  278. package/dist/session/session.types.pr-review.js +51 -0
  279. package/dist/session/sidecar-json-shape.d.ts +31 -0
  280. package/dist/session/sidecar-json-shape.js +217 -0
  281. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  282. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  283. package/dist/shared/fs/file-identity.d.ts +10 -0
  284. package/dist/shared/fs/file-identity.js +15 -0
  285. package/dist/shared/fs/replace-file.d.ts +7 -0
  286. package/dist/shared/fs/replace-file.js +33 -0
  287. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  288. package/dist/shared/process/host-process-recovery.js +23 -3
  289. package/dist/shared/process/host-process-supervisor.d.ts +14 -1
  290. package/dist/shared/process/host-process-supervisor.js +67 -15
  291. package/dist/shared/process/process-tree.d.ts +52 -0
  292. package/dist/shared/process/process-tree.js +144 -0
  293. package/dist/shared/process/process.d.ts +67 -0
  294. package/dist/shared/process/process.js +213 -11
  295. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  296. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  297. package/dist/shared/process/windows-launch.d.ts +18 -0
  298. package/dist/shared/process/windows-launch.js +68 -0
  299. package/dist/shared/provider-capabilities.d.ts +2 -0
  300. package/dist/shared/provider-capabilities.js +23 -7
  301. package/dist/version.d.ts +1 -1
  302. package/dist/version.js +1 -1
  303. package/dist/worktree/artifact-injector.js +24 -0
  304. package/dist/worktree/dependency-warmer.d.ts +25 -0
  305. package/dist/worktree/dependency-warmer.js +46 -10
  306. package/dist/worktree/orphan-relink.d.ts +19 -0
  307. package/dist/worktree/orphan-relink.js +106 -0
  308. package/dist/worktree/wip-git.d.ts +58 -0
  309. package/dist/worktree/wip-git.js +182 -0
  310. package/dist/worktree/wip-refs.d.ts +85 -0
  311. package/dist/worktree/wip-refs.js +169 -0
  312. package/dist/worktree/wip-restore.d.ts +51 -0
  313. package/dist/worktree/wip-restore.js +324 -0
  314. package/dist/worktree/wip-snapshot.d.ts +53 -0
  315. package/dist/worktree/wip-snapshot.js +270 -0
  316. package/dist/worktree/worktree-inputs.d.ts +8 -0
  317. package/dist/worktree/worktree-inputs.js +134 -0
  318. package/dist/worktree/worktree-origin-sync.d.ts +35 -0
  319. package/dist/worktree/worktree-origin-sync.js +128 -0
  320. package/dist/worktree/worktree-wip-events.d.ts +20 -0
  321. package/dist/worktree/worktree-wip-events.js +148 -0
  322. package/dist/worktree/worktree-wip.d.ts +57 -0
  323. package/dist/worktree/worktree-wip.js +200 -0
  324. package/dist/worktree/worktree.base.d.ts +7 -1
  325. package/dist/worktree/worktree.service.d.ts +58 -5
  326. package/dist/worktree/worktree.service.js +237 -161
  327. package/dist/worktree/worktree.types.d.ts +54 -0
  328. package/package.json +2 -2
  329. package/runtime/windows-listener-owner.ps1 +12 -1
@@ -1,18 +1,17 @@
1
- import crypto from "node:crypto";
2
1
  import fs from "node:fs/promises";
3
2
  import path from "node:path";
4
3
  import { redactSecrets } from "../shared/redaction/redaction.js";
5
- import { ensureNoSymbolicLinkPathSegments, isPathUnderRoot, sha256File } from "./qa-sidecar-validation.js";
4
+ import { assertQaSidecarJsonShape, ensureNoSymbolicLinkPathSegments, isPathUnderRoot, sha256File } from "./qa-sidecar-validation.js";
6
5
  import { assertClaimedChangedFilesMatchPublishableDiff } from "./publishable-worktree-changes.js";
7
- import { artifactRootFor, artifactRootForOwner, completionArtifactJsonPath, completionArtifactReportPath, decomposeGateFileNames, draftGateFileNames, phaseFiles, qaGateFileNames } from "./phase-completion.js";
8
- import { artifactOwnerFields, artifactReferenceOwnerFields, artifactOwnerRelativeRoot, defaultQaChecklist, fallbackReport, isNodeError, jsonText, normalizeArtifactPayload, normalizeCompletionStatus, normalizeQaGateArtifactPayload, normalizeQaGateStatus, normalizedString, optionalString, numberOrDefault, parseJsonObject, parseOptionalJsonObject, phaseFromToolName, qaArray, qaArtifactRelativePath, qaArtifactRelativePathForOwner, qaEvidenceSource, qaObjectArray, qaPolicyWarnings, qaStringArray, readOptionalFile, reportMarkdown, requiredRecord, requiredString, qaGateFromToolName, sha256, stableStringify, validateOptionalWorkItemId, validatePayloadShape, validateQaGatePayloadShape, validateQaScopeRecord, writeFileAtomic, asRecord } from "./phase-completion.validation.js";
6
+ import { coerceJsonStringArguments } from "./mcp-argument-coercion.js";
7
+ import { assertStructuralFieldsUnchanged, postRedactionValidationError, publishArtifactBundleAtomic, validatePostRedaction } from "./phase-completion.artifact-bundle.js";
8
+ import { toolInputSchema } from "./phase-completion.schemas.js";
9
+ import { artifactRootFor, artifactRootForOwner, completionArtifactJsonPath, completionArtifactReportPath, decomposeGateFileNames, draftGateFileNames, phaseFiles, qaGateFileNames, decomposeStatuses, draftStatuses } from "./phase-completion.js";
10
+ import { assertPrReviewMatchesRepository, prReviewReportMarkdown } from "./phase-completion.pr-review.js";
11
+ import { artifactOwnerFields, artifactReferenceOwnerFields, artifactOwnerRelativeRoot, defaultQaChecklist, fallbackReport, isNodeError, jsonText, normalizeArtifactPayload, normalizeCompletionStatus, normalizeQaGateArtifactPayload, normalizeQaGateStatus, normalizedString, optionalString, numberOrDefault, parseJsonObject, parseOptionalJsonObject, phaseFromToolName, qaArray, qaArtifactRelativePath, qaArtifactRelativePathForOwner, qaEvidenceSource, qaObjectArray, qaPolicyWarnings, qaEvidenceGates, qaStringArray, readOptionalFile, reportMarkdown, requireField, requiredRecord, requiredString, qaGateFromToolName, sha256, stableStringify, validateOptionalWorkItemId, validatePayloadShape, validatePrReviewPayloadShape, validateQaGatePayloadShape, validateQaScopeRecord, writeFileAtomic, asRecord } from "./phase-completion.validation.js";
9
12
  export async function writeDecomposeGateCompletionArtifact(config, gate, toolName, input) {
10
13
  const payload = asRecord(input, "Decompose completion payload");
11
- const status = normalizeDraftStatus(optionalString(payload, "status") ?? "pass");
12
- if (gate === "decompose_proposal") {
13
- const proposalJson = asRecord(payload["proposal_json"] ?? payload["decomposition_json"], "proposal_json");
14
- validateDecomposeProposalJson(proposalJson);
15
- }
14
+ const status = validateDecomposeGatePayload(gate, payload);
16
15
  const redactedPayload = redactSecrets({ ...payload, status, phase: "decompose", gate, tool_name: toolName }, config.redactionSecrets ?? []);
17
16
  assertStructuralFieldsUnchanged(payload, redactedPayload);
18
17
  if (gate === "decompose_proposal") {
@@ -45,11 +44,7 @@ ${optionalString(redactedPayload, "summary") ?? "Decompose gate recorded."}
45
44
  }
46
45
  export async function writeDraftGateCompletionArtifact(config, gate, toolName, input) {
47
46
  const payload = asRecord(input, "Draft completion payload");
48
- const status = normalizeDraftStatus(optionalString(payload, "status") ?? "pass");
49
- if (gate === "draft_proposal") {
50
- const draftJson = asRecord(payload["draft_json"], "draft_json");
51
- validateDraftProposalJson(draftJson);
52
- }
47
+ const status = validateDraftGatePayload(gate, payload);
53
48
  const redactedPayload = redactSecrets({ ...payload, status, phase: "draft", gate, tool_name: toolName }, config.redactionSecrets ?? []);
54
49
  assertStructuralFieldsUnchanged(payload, redactedPayload);
55
50
  if (gate === "draft_proposal") {
@@ -77,9 +72,48 @@ export async function writeDraftGateCompletionArtifact(config, gate, toolName, i
77
72
  producedBy: config.producedBy ?? "forge-completion-tool"
78
73
  };
79
74
  }
80
- function normalizeDraftStatus(value) {
81
- const normalized = value.trim().toLowerCase();
82
- return normalized === "blocked" || normalized === "needs_revision" || normalized === "needs_rework" ? normalized : "pass";
75
+ /**
76
+ * Judges a Decompose gate call before anything is written and returns its status. The gate's
77
+ * input schema advertises exactly these rules (see the completion tool schema contract test).
78
+ */
79
+ export function validateDecomposeGatePayload(gate, payload) {
80
+ const status = gateStatus(payload, decomposeStatuses);
81
+ if (gate === "decompose_proposal") {
82
+ validateDecomposeProposalJson(asRecord(payload["proposal_json"] ?? payload["decomposition_json"], "proposal_json"));
83
+ }
84
+ else {
85
+ // An earlier Decompose gate's evidence is its summary, and a missing status means pass, so an
86
+ // empty call would otherwise record a pass and move to the next gate.
87
+ requireField(payload, "summary");
88
+ }
89
+ return status;
90
+ }
91
+ /** Judges a Draft gate call before anything is written and returns its status. */
92
+ export function validateDraftGatePayload(gate, payload) {
93
+ const status = gateStatus(payload, draftStatuses);
94
+ if (gate === "draft_proposal") {
95
+ validateDraftProposalJson(asRecord(payload["draft_json"], "draft_json"));
96
+ }
97
+ else {
98
+ // An earlier Draft gate's only evidence is its summary, and a missing status means pass, so an
99
+ // empty call would otherwise record a pass and move to the next gate.
100
+ requireField(payload, "summary");
101
+ }
102
+ return status;
103
+ }
104
+ // Only an omitted status defaults to pass. A status that is present must be one of the advertised
105
+ // values: a typo such as "pas", a blank string or a non-string is rejected rather than advancing
106
+ // the gate as a pass.
107
+ function gateStatus(payload, allowed) {
108
+ const value = payload["status"];
109
+ if (value === undefined || value === null) {
110
+ return "pass";
111
+ }
112
+ const normalized = typeof value === "string" ? value.trim().toLowerCase() : "";
113
+ if (!allowed.includes(normalized)) {
114
+ throw new Error(`status must be one of ${allowed.join(", ")}; received ${typeof value === "string" ? `'${value}'` : JSON.stringify(value)}.`);
115
+ }
116
+ return normalized;
83
117
  }
84
118
  function validateDraftProposalJson(draftJson) {
85
119
  if (draftJson.suggested_qa_scope !== undefined && draftJson.suggested_qa_scope !== null) {
@@ -151,6 +185,9 @@ export async function writeCompletionArtifact(config, toolName, input) {
151
185
  if (qaGate && qaGate !== "qa_verdict") {
152
186
  return await writeQaGateCompletionArtifact(config, qaGate, input);
153
187
  }
188
+ if (phase === "pr_review") {
189
+ return await writePrReviewCompletionArtifact(config, input);
190
+ }
154
191
  const payload = asRecord(input, "completion payload");
155
192
  const status = normalizeCompletionStatus(requiredString(payload, "status"), phase);
156
193
  let validationPayload = { ...payload, status };
@@ -211,6 +248,62 @@ export async function writeCompletionArtifact(config, toolName, input) {
211
248
  producedBy
212
249
  };
213
250
  }
251
+ /**
252
+ * Writes pr-review.result.json and pr-review.report.md. This gate only records the review:
253
+ * Forge posts it to the pull request afterwards, so a pass ends the lane without any
254
+ * publication step here. `stale_head` and `blocked` are accepted terminal outcomes.
255
+ */
256
+ async function writePrReviewCompletionArtifact(config, input) {
257
+ const phase = "pr_review";
258
+ const payload = asRecord(input, "completion payload");
259
+ const status = normalizeCompletionStatus(requiredString(payload, "status"), phase);
260
+ const validationPayload = { ...payload, status };
261
+ validatePrReviewPayloadShape(validationPayload, status, config.prReview);
262
+ validateOptionalWorkItemId(validationPayload, config.workItemId);
263
+ if (status === "reviewed") {
264
+ await assertPrReviewMatchesRepository(config.worktreePath, validationPayload, config.prReview);
265
+ }
266
+ const redactedPayload = redactSecrets(validationPayload, config.redactionSecrets ?? []);
267
+ assertStructuralFieldsUnchanged(validationPayload, redactedPayload);
268
+ validatePostRedaction(() => {
269
+ validatePrReviewPayloadShape(redactedPayload, status, config.prReview);
270
+ validateOptionalWorkItemId(redactedPayload, config.workItemId);
271
+ });
272
+ const producedBy = optionalString(redactedPayload, "produced_by")
273
+ ?? optionalString(redactedPayload, "producedBy")
274
+ ?? config.producedBy
275
+ ?? "forge-completion-tool";
276
+ const artifactWithoutHash = normalizeArtifactPayload(redactedPayload, {
277
+ phase,
278
+ workItemId: config.workItemId,
279
+ ownerType: config.ownerType,
280
+ ownerId: config.ownerId,
281
+ producedBy,
282
+ status
283
+ });
284
+ const contentHash = sha256(stableStringify(artifactWithoutHash));
285
+ const artifactJson = `${JSON.stringify({ ...artifactWithoutHash, content_hash: contentHash }, null, 2)}\n`;
286
+ const report = optionalString(redactedPayload, "report_markdown")
287
+ ? reportMarkdown(redactedPayload, phase, status, producedBy, contentHash)
288
+ : prReviewReportMarkdown(artifactWithoutHash, contentHash);
289
+ const artifactPath = completionArtifactJsonPath(config.worktreePath, config.workItemId, phase);
290
+ const reportPath = completionArtifactReportPath(config.worktreePath, config.workItemId, phase);
291
+ await publishArtifactBundleAtomic(path.dirname(artifactPath), [
292
+ { fileName: path.basename(reportPath), content: report },
293
+ { fileName: path.basename(artifactPath), content: artifactJson }
294
+ ], path.basename(artifactPath));
295
+ return {
296
+ phase,
297
+ workItemId: config.workItemId,
298
+ ...artifactReferenceOwnerFields(config),
299
+ repoPath: path.resolve(config.worktreePath),
300
+ path: artifactPath,
301
+ reportPath,
302
+ contentHash,
303
+ status,
304
+ producedBy
305
+ };
306
+ }
214
307
  export async function writeArchitectCompletionArtifact(config, payload, status, producedBy) {
215
308
  const ownerFields = artifactOwnerFields(config);
216
309
  const artifactRoot = ownerFields.owner_type && ownerFields.owner_id
@@ -220,8 +313,10 @@ export async function writeArchitectCompletionArtifact(config, payload, status,
220
313
  const qaPlanPath = path.join(artifactRoot, "qa.plan.json");
221
314
  const verdictPath = path.join(artifactRoot, "architect.verdict.json");
222
315
  const reportPath = path.join(artifactRoot, "architect.report.md");
223
- const implementationPlan = requiredRecord(payload, "implementation_plan");
224
- const qaPlan = requiredRecord(payload, "qa_plan");
316
+ // A needs_revision or blocked verdict has no plan to approve; its schema lets
317
+ // the agent omit both plans, and the bundle still carries a file for each.
318
+ const implementationPlan = architectPlanRecord(payload, "implementation_plan", status);
319
+ const qaPlan = architectPlanRecord(payload, "qa_plan", status);
225
320
  const report = optionalString(payload, "report") ?? optionalString(payload, "report_markdown") ?? reportMarkdown(payload, "architect", status, producedBy, "pending");
226
321
  const artifactWithoutHash = normalizeArtifactPayload(payload, {
227
322
  phase: "architect",
@@ -254,13 +349,21 @@ export async function writeArchitectCompletionArtifact(config, payload, status,
254
349
  producedBy
255
350
  };
256
351
  }
352
+ function architectPlanRecord(payload, key, status) {
353
+ if (status !== "pass" && (payload[key] === undefined || payload[key] === null)) {
354
+ return {};
355
+ }
356
+ return requiredRecord(payload, key);
357
+ }
257
358
  export async function writeQaGateCompletionArtifact(config, gate, input) {
258
359
  const payload = asRecord(input, "QA gate completion payload");
259
360
  const status = normalizeQaGateStatus(requiredString(payload, "status"));
260
361
  validateQaGatePayloadShape(gate, payload, status);
261
362
  validateOptionalWorkItemId(payload, config.workItemId);
262
363
  const ownerFields = artifactOwnerFields(config);
263
- const validatedSidecars = gate === "qa_manual_web"
364
+ // Every evidence gate's sidecars are merged into the final verdict, which checks each file,
365
+ // so each gate checks its references (exists, under qa/, size and hash match) when it is called.
366
+ const validatedSidecars = qaEvidenceGates.has(gate)
264
367
  ? await validateQaSidecarReferences(config.worktreePath, config.workItemId, qaArray(payload, "sidecars", qaEvidenceSource(payload)), ownerFields.owner_type, ownerFields.owner_id)
265
368
  : null;
266
369
  const redactedPayload = redactSecrets({
@@ -273,7 +376,7 @@ export async function writeQaGateCompletionArtifact(config, gate, input) {
273
376
  validateQaGatePayloadShape(gate, redactedPayload, status);
274
377
  validateOptionalWorkItemId(redactedPayload, config.workItemId);
275
378
  });
276
- if (gate === "qa_manual_web") {
379
+ if (qaEvidenceGates.has(gate)) {
277
380
  await validateQaSidecarReferences(config.worktreePath, config.workItemId, qaArray(redactedPayload, "sidecars", qaEvidenceSource(redactedPayload)), ownerFields.owner_type, ownerFields.owner_id).catch((error) => {
278
381
  throw postRedactionValidationError(error);
279
382
  });
@@ -429,12 +532,12 @@ export async function writeQaCompletionArtifact(config, payload, status, produce
429
532
  };
430
533
  }
431
534
  async function synthesizeQaCycleVerdictPayload(config, payload, status) {
432
- const qaPlan = await readQaGateArtifact(config, "qa_plan");
433
- const qaRegression = await readQaGateArtifact(config, "qa_regression");
434
- const qaApi = await readQaGateArtifact(config, "qa_api");
435
- const qaManualWeb = await readQaGateArtifact(config, "qa_manual_web");
436
- const qaBugRepro = await readQaGateArtifact(config, "qa_bug_repro");
437
- const qaFindings = await readQaGateArtifact(config, "qa_findings");
535
+ const qaPlan = await readInheritedQaGateArtifact(config, "qa_plan");
536
+ const qaRegression = await readInheritedQaGateArtifact(config, "qa_regression");
537
+ const qaApi = await readInheritedQaGateArtifact(config, "qa_api");
538
+ const qaManualWeb = await readInheritedQaGateArtifact(config, "qa_manual_web");
539
+ const qaBugRepro = await readInheritedQaGateArtifact(config, "qa_bug_repro");
540
+ const qaFindings = await readInheritedQaGateArtifact(config, "qa_findings");
438
541
  const evidenceGates = [qaRegression, qaApi, qaManualWeb, qaBugRepro];
439
542
  const payloadEvidence = qaEvidenceSource(payload);
440
543
  const merged = { ...payload };
@@ -482,6 +585,32 @@ async function synthesizeQaCycleVerdictPayload(config, payload, status) {
482
585
  merged.candidate_bugs = mergeQaObjectArraysById(qaObjectArray(payload, "candidate_bugs"), qaObjectArray(qaFindings, "candidate_bugs"));
483
586
  return merged;
484
587
  }
588
+ /**
589
+ * Reads an earlier gate's artifact for the verdict merge. Gates recorded before
590
+ * argument coercion existed may hold a JSON-string array, so the same schema
591
+ * coercion is applied here, and any remaining shape error names the gate file
592
+ * instead of looking like a fault in the verdict payload.
593
+ */
594
+ async function readInheritedQaGateArtifact(config, gate) {
595
+ const artifact = coerceJsonStringArguments(await readQaGateArtifact(config, gate), toolInputSchema("qa", gate));
596
+ // Gates accept sidecars inside the evidence wrapper too; promote them so the verdict inherits
597
+ // them. A top-level value still takes precedence.
598
+ if (artifact.sidecars === undefined || artifact.sidecars === null) {
599
+ const nestedSidecars = qaEvidenceSource(artifact).sidecars;
600
+ if (nestedSidecars !== undefined && nestedSidecars !== null) {
601
+ artifact.sidecars = nestedSidecars;
602
+ }
603
+ }
604
+ for (const key of ["commands", "browser_checks", "sidecars", "checklist", "acceptance_criteria", "findings", "candidate_bugs"]) {
605
+ try {
606
+ qaArray(artifact, key);
607
+ }
608
+ catch (error) {
609
+ throw new Error(`${qaGateFileNames[gate]} recorded by ${gate} has an invalid ${key}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
610
+ }
611
+ }
612
+ return artifact;
613
+ }
485
614
  export async function readQaGateArtifact(config, gate) {
486
615
  const ownerFields = artifactOwnerFields(config);
487
616
  const artifactRoot = ownerFields.owner_type && ownerFields.owner_id
@@ -621,6 +750,7 @@ async function validateQaSidecarReferences(worktreePath, workItemId, sidecars, o
621
750
  if (actualHash !== normalizeSha256ContentHash(contentHash)) {
622
751
  throw new Error(`sidecars[${index}].content_hash does not match the referenced file.`);
623
752
  }
753
+ await assertQaSidecarJsonShape(fullPath, sidecarPath, `sidecars[${index}]`);
624
754
  const canonicalPath = path.relative(worktreePath, fullPath).split(path.sep).join("/");
625
755
  const duplicateKey = canonicalPath.toLowerCase();
626
756
  const existing = validatedByPath.get(duplicateKey);
@@ -668,166 +798,4 @@ export async function readCompletionArtifact(worktreePath, workItemId, phase, ow
668
798
  phase
669
799
  };
670
800
  }
671
- /**
672
- * Stages a complete phase bundle outside the live artifact directory, then
673
- * publishes its canonical verdict/marker last. Consumers treat the marker as
674
- * the bundle's commit point, so they can observe either the old complete bundle
675
- * or the new complete bundle, never a partially written set. A failed or
676
- * cancelled publication rolls every touched file back before rejecting.
677
- */
678
- export async function publishArtifactBundleAtomic(artifactRoot, files, commitFileName, options = {}) {
679
- validateArtifactBundleFiles(files, commitFileName);
680
- throwIfPublicationCancelled(options.signal);
681
- const parent = path.dirname(artifactRoot);
682
- const transactionId = `${process.pid}.${crypto.randomUUID()}`;
683
- const stagingRoot = path.join(parent, `.${path.basename(artifactRoot)}.${transactionId}.publish`);
684
- const backupRoot = path.join(stagingRoot, ".previous");
685
- const orderedFiles = [
686
- ...files.filter((file) => file.fileName !== commitFileName),
687
- files.find((file) => file.fileName === commitFileName)
688
- ];
689
- const backedUp = new Set();
690
- const published = new Set();
691
- try {
692
- await fs.mkdir(parent, { recursive: true });
693
- await fs.mkdir(stagingRoot, { recursive: false });
694
- for (const file of orderedFiles) {
695
- throwIfPublicationCancelled(options.signal);
696
- const handle = await fs.open(path.join(stagingRoot, file.fileName), "wx");
697
- try {
698
- await handle.writeFile(file.content, { encoding: "utf8", signal: options.signal });
699
- await handle.sync();
700
- }
701
- finally {
702
- await handle.close();
703
- }
704
- }
705
- throwIfPublicationCancelled(options.signal);
706
- await fs.mkdir(artifactRoot, { recursive: true });
707
- await fs.mkdir(backupRoot, { recursive: true });
708
- // Hide the previous commit marker before changing any supporting file.
709
- for (const fileName of [commitFileName, ...orderedFiles.map((file) => file.fileName).filter((name) => name !== commitFileName)]) {
710
- const livePath = path.join(artifactRoot, fileName);
711
- try {
712
- await fs.rename(livePath, path.join(backupRoot, fileName));
713
- backedUp.add(fileName);
714
- }
715
- catch (error) {
716
- if (!isNodeError(error) || error.code !== "ENOENT") {
717
- throw error;
718
- }
719
- }
720
- }
721
- for (const [index, file] of orderedFiles.entries()) {
722
- throwIfPublicationCancelled(options.signal);
723
- await options.beforePublishFile?.(file.fileName, index);
724
- await fs.rename(path.join(stagingRoot, file.fileName), path.join(artifactRoot, file.fileName));
725
- published.add(file.fileName);
726
- }
727
- }
728
- catch (error) {
729
- const rollbackErrors = [];
730
- for (const file of [...orderedFiles].reverse()) {
731
- if (!published.has(file.fileName))
732
- continue;
733
- await fs.rm(path.join(artifactRoot, file.fileName), { force: true }).catch(() => {
734
- rollbackErrors.push(file.fileName);
735
- });
736
- }
737
- // Restore the previous marker last for the same observable commit boundary.
738
- const restoreOrder = [
739
- ...orderedFiles.filter((file) => file.fileName !== commitFileName),
740
- orderedFiles.find((file) => file.fileName === commitFileName)
741
- ];
742
- for (const file of restoreOrder) {
743
- if (!backedUp.has(file.fileName))
744
- continue;
745
- await fs.rename(path.join(backupRoot, file.fileName), path.join(artifactRoot, file.fileName)).catch(() => {
746
- rollbackErrors.push(file.fileName);
747
- });
748
- }
749
- if (rollbackErrors.length === 0
750
- && error instanceof Error
751
- && error.message.startsWith("artifact_atomic_publish_cancelled:")) {
752
- throw error;
753
- }
754
- const suffix = rollbackErrors.length > 0 ? " Rollback did not restore every bundle file." : "";
755
- throw new Error(`artifact_atomic_publish_failure: completion artifact bundle was not published.${suffix}`, { cause: error });
756
- }
757
- finally {
758
- await fs.rm(stagingRoot, { recursive: true, force: true }).catch(() => undefined);
759
- }
760
- }
761
- function validateArtifactBundleFiles(files, commitFileName) {
762
- if (files.length === 0 || !files.some((file) => file.fileName === commitFileName)) {
763
- throw new Error("artifact_atomic_publish_failure: bundle commit file is missing.");
764
- }
765
- const names = new Set();
766
- for (const file of files) {
767
- if (!file.fileName || path.basename(file.fileName) !== file.fileName || names.has(file.fileName)) {
768
- throw new Error("artifact_atomic_publish_failure: bundle file names must be unique safe base names.");
769
- }
770
- names.add(file.fileName);
771
- }
772
- }
773
- function throwIfPublicationCancelled(signal) {
774
- if (signal?.aborted) {
775
- throw new Error("artifact_atomic_publish_cancelled: completion artifact bundle publication was cancelled.");
776
- }
777
- }
778
- function validatePostRedaction(validate) {
779
- try {
780
- validate();
781
- }
782
- catch (error) {
783
- throw postRedactionValidationError(error);
784
- }
785
- }
786
- function postRedactionValidationError(error) {
787
- const message = error instanceof Error ? error.message : String(error);
788
- return new Error(`artifact_post_redaction_validation_failed: ${message}`, { cause: error });
789
- }
790
- function assertStructuralFieldsUnchanged(original, redacted) {
791
- if (structuralFieldFingerprint(original) !== structuralFieldFingerprint(redacted)) {
792
- // This stable code is intentionally safe for telemetry: it does not include
793
- // the structural value or any candidate secret.
794
- throw new Error("artifact_redaction_changed_structural_field: redaction changed a structural identifier; the bundle was not published.");
795
- }
796
- }
797
- function structuralFieldFingerprint(value, key = "", result = []) {
798
- if (Array.isArray(value)) {
799
- if (isStructuralFieldKey(key) && value.every((item) => item === null || typeof item !== "object")) {
800
- result.push(stableStringify(value));
801
- }
802
- else {
803
- for (const item of value)
804
- structuralFieldFingerprint(item, key, result);
805
- }
806
- return result.join("\n");
807
- }
808
- if (!value || typeof value !== "object") {
809
- if (isStructuralFieldKey(key))
810
- result.push(stableStringify(value));
811
- return result.join("\n");
812
- }
813
- for (const [childKey, child] of Object.entries(value)) {
814
- if (isStructuralFieldKey(childKey)) {
815
- result.push(`${childKey}:${stableStringify(child)}`);
816
- }
817
- else {
818
- structuralFieldFingerprint(child, childKey, result);
819
- }
820
- }
821
- return result.join("\n");
822
- }
823
- function isStructuralFieldKey(key) {
824
- return key === "id"
825
- || key === "before"
826
- || key === "after"
827
- || key === "from"
828
- || key === "to"
829
- || key === "tasks"
830
- || key === "phases"
831
- || /(?:^|_)(?:id|ids)$/i.test(key)
832
- || /(?:Id|Ids)$/.test(key);
833
- }
801
+ export { publishArtifactBundleAtomic } from "./phase-completion.artifact-bundle.js";
@@ -0,0 +1,7 @@
1
+ export declare function validateQaGatePassingCommands(commands: readonly unknown[], options?: {
2
+ readonly allowClassifiedNonBlockingFailures?: boolean;
3
+ /** Payload field that holds these command records, for error messages. */
4
+ readonly label?: string;
5
+ /** Why a passing result is required, for error messages. */
6
+ readonly context?: string;
7
+ }): void;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Checks the command evidence records (commands, validation, narrow_validation,
3
+ * and similar fields) that a passing completion must report as passing, with
4
+ * the classified non-blocking failure exception for QA regression.
5
+ */
6
+ import { structuredTypeHint } from "./mcp-argument-coercion.js";
7
+ import { normalizedString, optionalString, requireNonEmptyStringRecord, throwCompletionPayloadIssues } from "./phase-completion.helpers.js";
8
+ export function validateQaGatePassingCommands(commands, options = {}) {
9
+ const label = options.label ?? "commands";
10
+ const context = options.context ?? "QA gate status is pass";
11
+ const issues = [];
12
+ for (const [index, command] of commands.entries()) {
13
+ if (!command || typeof command !== "object" || Array.isArray(command)) {
14
+ issues.push(`${label}[${index}] must be an object${structuredTypeHint(command, "object")}.`);
15
+ continue;
16
+ }
17
+ const record = command;
18
+ if (!optionalString(record, "command"))
19
+ issues.push(`${label}[${index}].command is required.`);
20
+ if (!optionalString(record, "status"))
21
+ issues.push(`${label}[${index}].status is required.`);
22
+ if (!optionalString(record, "summary"))
23
+ issues.push(`${label}[${index}].summary is required.`);
24
+ if (typeof record.exit_code !== "number" || !Number.isFinite(record.exit_code)) {
25
+ issues.push(`${label}[${index}].exit_code is required.`);
26
+ continue;
27
+ }
28
+ const passed = record.exit_code === 0 && normalizedString(record.status) === "pass";
29
+ if (!passed
30
+ && options.allowClassifiedNonBlockingFailures
31
+ && optionalString(record, "classification")) {
32
+ try {
33
+ validateClassifiedNonBlockingQaFailure(record, index, label);
34
+ }
35
+ catch (error) {
36
+ issues.push(error instanceof Error ? error.message : String(error));
37
+ }
38
+ continue;
39
+ }
40
+ if (record.exit_code !== 0) {
41
+ issues.push(`${label}[${index}].exit_code must be 0 when ${context}.`);
42
+ }
43
+ if (normalizedString(record.status) !== "pass") {
44
+ issues.push(`${label}[${index}].status must be pass when ${context}.`);
45
+ }
46
+ }
47
+ throwCompletionPayloadIssues(issues);
48
+ }
49
+ function validateClassifiedNonBlockingQaFailure(record, index, label) {
50
+ const prefix = `${label}[${index}]`;
51
+ const classification = normalizedString(optionalString(record, "classification"));
52
+ if (classification !== "out_of_scope_failure" && classification !== "baseline_failure") {
53
+ throw new Error(`${prefix}.classification must be out_of_scope_failure or baseline_failure: a non-passing command in a QA regression pass needs a classification with corroborating evidence.`);
54
+ }
55
+ const classified = `for a non-blocking ${classification} (also required: candidate_bug_id, scope_evidence, acceptance_criteria_independent: true, and ${classification === "out_of_scope_failure" ? "repro_command with a non-zero repro_exit_code" : "baseline_ref, a non-zero baseline_exit_code, and failure_signature_match: true"})`;
56
+ if (!optionalString(record, "candidate_bug_id"))
57
+ throw new Error(`${prefix}.candidate_bug_id is required ${classified}.`);
58
+ if (!optionalString(record, "scope_evidence"))
59
+ throw new Error(`${prefix}.scope_evidence is required ${classified}.`);
60
+ if (record.acceptance_criteria_independent !== true) {
61
+ throw new Error(`${prefix}.acceptance_criteria_independent must be true for a non-blocking QA regression failure.`);
62
+ }
63
+ if (classification === "out_of_scope_failure") {
64
+ requireNonEmptyStringRecord(record, "repro_command", `${prefix}.`);
65
+ if (typeof record.repro_exit_code !== "number" || !Number.isFinite(record.repro_exit_code) || record.repro_exit_code === 0) {
66
+ throw new Error(`${prefix}.repro_exit_code must be a non-zero number for an out-of-scope failure.`);
67
+ }
68
+ return;
69
+ }
70
+ requireNonEmptyStringRecord(record, "baseline_ref", `${prefix}.`);
71
+ if (typeof record.baseline_exit_code !== "number" || !Number.isFinite(record.baseline_exit_code) || record.baseline_exit_code === 0) {
72
+ throw new Error(`${prefix}.baseline_exit_code must be a non-zero number for a baseline failure.`);
73
+ }
74
+ if (record.failure_signature_match !== true) {
75
+ throw new Error(`${prefix}.failure_signature_match must be true for a baseline failure.`);
76
+ }
77
+ }
@@ -2,8 +2,10 @@ import type { RunOnceDispatchPacket } from "./session.types.js";
2
2
  import type { WorktreeHandle } from "../worktree/worktree.types.js";
3
3
  export { isDebugCompletionPhase } from "./phase-completion.validation.js";
4
4
  export { readCompletionArtifact, writeCompletionArtifact } from "./phase-completion.artifacts.js";
5
+ export { recordedPrReviewArtifactProblem } from "./phase-completion.pr-review.js";
5
6
  export * from "./phase-completion.prompts.js";
6
7
  export * from "./phase-completion.runtime.js";
8
+ export * from "./phase-completion.mcp-args.js";
7
9
  export type DevelopCompletionPhase = "implementation" | "self_review" | "validation";
8
10
  export type DebugCompletionPhase = "debug_repro" | "debug_root_cause" | "debug_fix" | "debug_regression";
9
11
  export type ArchitectCompletionPhase = "architect";
@@ -11,7 +13,8 @@ export type DraftCompletionPhase = "draft";
11
13
  export type DecomposeCompletionPhase = "decompose";
12
14
  export type CiRepairCompletionPhase = "ci_repair";
13
15
  export type CommentRepairCompletionPhase = "comment_repair";
14
- export type CompletionPhase = DevelopCompletionPhase | "qa" | DebugCompletionPhase | ArchitectCompletionPhase | DraftCompletionPhase | DecomposeCompletionPhase | CiRepairCompletionPhase | CommentRepairCompletionPhase;
16
+ export type PrReviewCompletionPhase = "pr_review";
17
+ export type CompletionPhase = DevelopCompletionPhase | "qa" | DebugCompletionPhase | ArchitectCompletionPhase | DraftCompletionPhase | DecomposeCompletionPhase | CiRepairCompletionPhase | CommentRepairCompletionPhase | PrReviewCompletionPhase;
15
18
  export type QaCompletionGate = "qa_plan" | "qa_regression" | "qa_api" | "qa_manual_web" | "qa_bug_repro" | "qa_findings" | "qa_verdict";
16
19
  export type DraftCompletionGate = "draft_intent" | "draft_repo_context" | "draft_graph_context" | "draft_product_scope" | "draft_work_order_plan" | "draft_critic" | "draft_proposal";
17
20
  export type DecomposeCompletionGate = "decompose_subject_intake" | "decompose_context_review" | "decompose_breakdown_strategy" | "decompose_child_items" | "decompose_dependency_graph" | "decompose_critic" | "decompose_proposal";
@@ -29,6 +32,25 @@ export interface CompletionToolRuntimeOptions {
29
32
  readonly worktree: WorktreeHandle;
30
33
  readonly phase?: CompletionPhase;
31
34
  readonly runtimeEnvironment?: Readonly<Record<string, string>>;
35
+ /** Host load governor variables; only the MCP server receives them. */
36
+ readonly hostLoadEnvironment?: Readonly<Record<string, string>>;
37
+ /**
38
+ * Serve only the managed-attempt tools (managed commands, verification, waits), never a
39
+ * completion tool. A pre-publication repair turn uses this: its phase's completion artifacts are
40
+ * already recorded and validated, and the repair prompt forbids rewriting them.
41
+ */
42
+ readonly managedToolsOnly?: boolean;
43
+ }
44
+ /**
45
+ * What Forge knows about the pull request under review, handed to the pr_review completion
46
+ * tool so it can reject a review bound to the wrong head or citing threads the dispatch never
47
+ * listed. Every field is optional: whatever is absent is verified against the worktree instead.
48
+ */
49
+ export interface PrReviewCompletionContext {
50
+ readonly headSha?: string;
51
+ readonly baseSha?: string;
52
+ /** Thread ids the dispatch lists as prior review threads. Enforced only when non-empty. */
53
+ readonly threadIds?: readonly string[];
32
54
  }
33
55
  export interface CompletionToolServerConfig {
34
56
  readonly worktreePath: string;
@@ -44,6 +66,8 @@ export interface CompletionToolServerConfig {
44
66
  readonly architectCycle?: boolean;
45
67
  readonly draftCycle?: boolean;
46
68
  readonly decomposeCycle?: boolean;
69
+ readonly prReview?: PrReviewCompletionContext;
70
+ readonly managedToolsOnly?: boolean;
47
71
  }
48
72
  export interface CompletionToolCallResult {
49
73
  readonly content: readonly {
@@ -67,7 +91,7 @@ export interface CompletionToolCallResult {
67
91
  readonly allowed: boolean;
68
92
  readonly reason: string;
69
93
  };
70
- readonly nextPhase: CompletionPhase | "dev_test_ready" | "qa_ready" | "sign_off_ready" | "provider_checks_ready";
94
+ readonly nextPhase: CompletionPhase | "dev_test_ready" | "qa_ready" | "sign_off_ready" | "provider_checks_ready" | "pr_review_complete";
71
95
  readonly nextInstruction: string;
72
96
  };
73
97
  }
@@ -94,6 +118,8 @@ export declare const debugCompletionPhaseOrder: readonly DebugCompletionPhase[];
94
118
  export declare const qaCompletionGateOrder: readonly QaCompletionGate[];
95
119
  export declare const draftCompletionGateOrder: readonly DraftCompletionGate[];
96
120
  export declare const decomposeCompletionGateOrder: readonly DecomposeCompletionGate[];
121
+ export declare const draftStatuses: readonly ["pass", "needs_revision", "needs_rework", "blocked"];
122
+ export declare const decomposeStatuses: readonly ["pass", "needs_rework", "fail", "failed", "needs_revision", "blocked"];
97
123
  export declare const decomposeGateFileNames: Record<DecomposeCompletionGate, string>;
98
124
  export declare const decomposeGateToolNames: Record<DecomposeCompletionGate, string>;
99
125
  export declare const draftGateFileNames: Record<DraftCompletionGate, string>;
@@ -115,6 +141,9 @@ export declare const qaScopeAuthorities: Set<string>;
115
141
  export declare const qaScopeConfidence: Set<string>;
116
142
  export declare const qaScopeFields: Set<string>;
117
143
  export declare const phaseFiles: Record<CompletionPhase, CompletionArtifactFiles>;
144
+ /** Statuses `forge.complete_pr_review` accepts; each one ends the review lane. */
145
+ export declare const prReviewStatuses: readonly ["reviewed", "stale_head", "blocked"];
146
+ export type PrReviewStatus = (typeof prReviewStatuses)[number];
118
147
  export declare function completionPhaseFromDispatch(dispatch: RunOnceDispatchPacket): CompletionPhase;
119
148
  export declare function normalizeCompletionPhase(value: string | null | undefined): CompletionPhase;
120
149
  export declare function usesDevelopCycleCompletion(dispatch: RunOnceDispatchPacket): boolean;