@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
@@ -3,6 +3,7 @@ import { spawn } from "node:child_process";
3
3
  import fs from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import { defaultWorktreeCoordinatorStateRoot } from "../worktree/worktree-paths.js";
6
+ import { replaceFile } from "../shared/fs/replace-file.js";
6
7
  const schemaVersion = 1;
7
8
  const maximumRetainedReceipts = 8;
8
9
  const maximumOutputManifestEntries = 20_000;
@@ -262,7 +263,7 @@ async function persistImmutableReceipt(receiptPath, receipt) {
262
263
  const temporaryPath = `${receiptPath}.${randomUUID()}.tmp`;
263
264
  await fs.writeFile(temporaryPath, `${JSON.stringify(receipt, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
264
265
  try {
265
- await fs.rename(temporaryPath, receiptPath).catch(async (error) => {
266
+ await replaceFile(temporaryPath, receiptPath).catch(async (error) => {
266
267
  if (error.code !== "EEXIST")
267
268
  throw error;
268
269
  });
@@ -271,11 +272,18 @@ async function persistImmutableReceipt(receiptPath, receipt) {
271
272
  await fs.rm(temporaryPath, { force: true }).catch(() => undefined);
272
273
  }
273
274
  }
274
- async function persistJsonAtomically(receiptPath, value) {
275
+ /**
276
+ * Writes a JSON receipt by replacing the whole file. Agents and Forge poll receipts, and on
277
+ * Windows a poll that has one open refuses the replace: that delays a write, never fails it.
278
+ * `commit`, when given, runs the final replace and may skip it (a write that went stale while
279
+ * it was being prepared); the receipt is then left as it was.
280
+ */
281
+ export async function persistJsonAtomically(receiptPath, value, commit) {
275
282
  const temporaryPath = `${receiptPath}.${randomUUID()}.tmp`;
276
283
  await fs.writeFile(temporaryPath, `${JSON.stringify(value, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
277
284
  try {
278
- await fs.rename(temporaryPath, receiptPath);
285
+ const replace = async () => await replaceFile(temporaryPath, receiptPath);
286
+ await (commit ? commit(replace) : replace());
279
287
  }
280
288
  finally {
281
289
  await fs.rm(temporaryPath, { force: true }).catch(() => undefined);
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The environment a managed command runs with: the bridge's own, without secrets and without
3
+ * the host load governor, plus the command's overrides. A nested Forge process must not join
4
+ * the host ledger: it would queue behind the token this command already holds, so every
5
+ * FORGE_HOST_LOAD_* variable is dropped, the test slot count too (decision 0018). A heavy
6
+ * command that shares the host with other heavy steps sizes its test parallelism for its share.
7
+ */
8
+ export declare function inheritedManagedCommandEnvironment(overrides: Readonly<Record<string, string>>, source?: Readonly<Record<string, string | undefined>>): Readonly<Record<string, string>>;
@@ -0,0 +1,28 @@
1
+ import { withHostTestParallelism, withoutHostLoadGovernorVariables } from "../runtime/host-load-child-environment.js";
2
+ /**
3
+ * The environment a managed command runs with: the bridge's own, without secrets and without
4
+ * the host load governor, plus the command's overrides. A nested Forge process must not join
5
+ * the host ledger: it would queue behind the token this command already holds, so every
6
+ * FORGE_HOST_LOAD_* variable is dropped, the test slot count too (decision 0018). A heavy
7
+ * command that shares the host with other heavy steps sizes its test parallelism for its share.
8
+ */
9
+ export function inheritedManagedCommandEnvironment(overrides, source = process.env) {
10
+ const env = {};
11
+ for (const [key, value] of Object.entries(withoutHostLoadGovernorVariables(source))) {
12
+ if (typeof value === "string" && !looksSensitiveEnvironmentName(key))
13
+ env[key] = value;
14
+ }
15
+ return withHostTestParallelism({ ...env, ...overrides });
16
+ }
17
+ function looksSensitiveEnvironmentName(name) {
18
+ const normalized = name.trim().toUpperCase();
19
+ return normalized.includes("SECRET")
20
+ || normalized.includes("TOKEN")
21
+ || normalized.includes("PASSWORD")
22
+ || normalized.includes("CREDENTIAL")
23
+ || normalized.includes("CONNECTION_STRING")
24
+ || normalized.startsWith("CONNECTIONSTRINGS__")
25
+ || normalized.startsWith("CONNECTIONSTRINGS:")
26
+ || normalized.endsWith("_API_KEY")
27
+ || normalized === "OPENAI_API_KEY";
28
+ }
@@ -0,0 +1,52 @@
1
+ import { type HostLoadStepGate } from "../runtime/host-load-governor.js";
2
+ import { type HostLoadStepClassification, type ManagedCommandStepInput } from "../runtime/host-load-step-class.js";
3
+ import { type HostLoadStepControl, type WaitReportFence } from "../runtime/host-load-step-run.js";
4
+ /** Host-load facts a managed command receipt carries; absent while the governor is off. */
5
+ export interface ManagedCommandHostLoadFields {
6
+ readonly stepClass: string;
7
+ /** Queue time before admission; never part of elapsed_ms. */
8
+ readonly waitMs: number;
9
+ /** Set while the command is still queued: the receipt reports the wait so far. */
10
+ readonly waitStartedAt?: number;
11
+ /** Why it waits, for example for the host test slot and who holds it (decision 0018). */
12
+ readonly waitDetail?: string;
13
+ /** When the command was admitted; elapsed_ms counts from here. */
14
+ readonly executionStartedAt?: number;
15
+ }
16
+ /** This MCP server's governor, built once from the environment the bridge handed it. */
17
+ export declare function managedCommandHostLoadGate(): HostLoadStepGate | undefined;
18
+ /** Test support: installs a gate (undefined disables it; null rebuilds from the environment). */
19
+ export declare function setManagedCommandHostLoadGateForTesting(value: HostLoadStepGate | undefined | null): void;
20
+ /**
21
+ * Admits one managed command. The waiting receipt is written while the command
22
+ * is queued, and rewritten whenever the wait changes (a new slot holder, say).
23
+ * The writes run in order and land before the launch receipts, so a stale
24
+ * "waiting" write can never replace a later status or a newer wait. A write
25
+ * that never settles holds the launch (with its token) or the terminal receipt
26
+ * back only for the governor's drain bound; writes still queued after it are
27
+ * dropped as stale, and one still running can no longer replace the receipt
28
+ * (orderedWaitReports, WaitReportFence).
29
+ */
30
+ export declare class ManagedCommandHostCapacity {
31
+ private readonly persistWaiting;
32
+ private readonly gateFor;
33
+ readonly classification: HostLoadStepClassification;
34
+ private readonly label;
35
+ private requestedAtMs;
36
+ private readonly waitingWrites;
37
+ constructor(input: ManagedCommandStepInput & {
38
+ readonly label: string;
39
+ }, persistWaiting: (fields: ManagedCommandHostLoadFields, fence: WaitReportFence) => Promise<void>, gateFor?: () => HostLoadStepGate | undefined);
40
+ /** Runs `launch` once admitted; `fields` is undefined with the governor off. */
41
+ run<T>(signal: AbortSignal, launch: (fields: ManagedCommandHostLoadFields | undefined, control: HostLoadStepControl) => Promise<T>, onReleaseFailed?: (error: unknown) => Promise<void>): Promise<T>;
42
+ /**
43
+ * Host-load facts for a command that was never admitted (it timed out in
44
+ * the queue or was stopped while waiting), once its waiting receipt landed.
45
+ */
46
+ unadmittedFields(error: unknown): Promise<ManagedCommandHostLoadFields | undefined>;
47
+ }
48
+ /**
49
+ * The managed command's process tree as its supervisor recorded it, for its
50
+ * host load token: a reclaim then stops exactly this tree before reuse.
51
+ */
52
+ export declare function attachManagedCommandProcess(control: HostLoadStepControl, metadataPath: string): Promise<void>;
@@ -0,0 +1,87 @@
1
+ import { hostLoadGovernorFromChildEnvironment } from "../runtime/host-load-child-environment.js";
2
+ import { HostCapacityTimeoutError } from "../runtime/host-load-governor.js";
3
+ import { classifyManagedCommand } from "../runtime/host-load-step-class.js";
4
+ import { attachSupervisedStepProcess, orderedWaitReports, runHostGovernedStep, } from "../runtime/host-load-step-run.js";
5
+ let gate = null;
6
+ /** This MCP server's governor, built once from the environment the bridge handed it. */
7
+ export function managedCommandHostLoadGate() {
8
+ if (gate === null)
9
+ gate = hostLoadGovernorFromChildEnvironment();
10
+ return gate;
11
+ }
12
+ /** Test support: installs a gate (undefined disables it; null rebuilds from the environment). */
13
+ export function setManagedCommandHostLoadGateForTesting(value) {
14
+ gate = value;
15
+ }
16
+ /**
17
+ * Admits one managed command. The waiting receipt is written while the command
18
+ * is queued, and rewritten whenever the wait changes (a new slot holder, say).
19
+ * The writes run in order and land before the launch receipts, so a stale
20
+ * "waiting" write can never replace a later status or a newer wait. A write
21
+ * that never settles holds the launch (with its token) or the terminal receipt
22
+ * back only for the governor's drain bound; writes still queued after it are
23
+ * dropped as stale, and one still running can no longer replace the receipt
24
+ * (orderedWaitReports, WaitReportFence).
25
+ */
26
+ export class ManagedCommandHostCapacity {
27
+ persistWaiting;
28
+ gateFor;
29
+ classification;
30
+ label;
31
+ requestedAtMs = null;
32
+ waitingWrites;
33
+ constructor(input, persistWaiting, gateFor = managedCommandHostLoadGate) {
34
+ this.persistWaiting = persistWaiting;
35
+ this.gateFor = gateFor;
36
+ this.classification = classifyManagedCommand(input);
37
+ this.label = input.label;
38
+ this.waitingWrites = orderedWaitReports(async (decision, fence) => await this.persistWaiting({
39
+ stepClass: this.classification.stepClass,
40
+ waitMs: 0,
41
+ waitStartedAt: this.requestedAtMs ?? Date.now(),
42
+ waitDetail: decision.detail,
43
+ }, fence));
44
+ }
45
+ /** Runs `launch` once admitted; `fields` is undefined with the governor off. */
46
+ async run(signal, launch, onReleaseFailed) {
47
+ const current = this.gateFor();
48
+ if (current?.enabled)
49
+ this.requestedAtMs = Date.now();
50
+ return await runHostGovernedStep(current, {
51
+ classification: this.classification,
52
+ label: this.label,
53
+ dispatchAttemptId: process.env.FORGE_DISPATCH_ATTEMPT_ID?.trim() || null,
54
+ // An agent waits on its managed commands; readiness probes never start one.
55
+ priority: "foreground",
56
+ signal,
57
+ // The receipt says host_capacity_token_fenced itself (termination_reason).
58
+ reportsOwnFence: true,
59
+ onWaiting: this.waitingWrites.onWaiting,
60
+ onReleaseFailed,
61
+ }, async (waitMs, control) => {
62
+ await this.waitingWrites.drained();
63
+ // The launch timer and timeout_ms start inside `launch`, after admission.
64
+ return await launch(waitMs === null
65
+ ? undefined
66
+ : { stepClass: this.classification.stepClass, waitMs, executionStartedAt: Date.now() }, control);
67
+ });
68
+ }
69
+ /**
70
+ * Host-load facts for a command that was never admitted (it timed out in
71
+ * the queue or was stopped while waiting), once its waiting receipt landed.
72
+ */
73
+ async unadmittedFields(error) {
74
+ await this.waitingWrites.drained();
75
+ if (this.requestedAtMs === null)
76
+ return undefined;
77
+ const waitMs = error instanceof HostCapacityTimeoutError ? error.waitMs : Date.now() - this.requestedAtMs;
78
+ return { stepClass: this.classification.stepClass, waitMs: Math.round(waitMs), executionStartedAt: Date.now() };
79
+ }
80
+ }
81
+ /**
82
+ * The managed command's process tree as its supervisor recorded it, for its
83
+ * host load token: a reclaim then stops exactly this tree before reuse.
84
+ */
85
+ export async function attachManagedCommandProcess(control, metadataPath) {
86
+ await attachSupervisedStepProcess(control, metadataPath);
87
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * MCP clients sometimes send a structured tool argument as its JSON text, for
3
+ * example `sidecars: "[{...}]"` instead of `sidecars: [{...}]`. At the tool-call
4
+ * boundary, before any validation, this replaces such a string with its parsed
5
+ * value, but only where the tool's declared input schema says the value is an
6
+ * array or an object and the string parses to exactly that kind of value.
7
+ *
8
+ * Nothing else is coerced: a string field that happens to contain JSON stays a
9
+ * string, an undeclared field is left alone, and a malformed string is passed
10
+ * through unchanged so the validator reports it.
11
+ */
12
+ export declare function coerceJsonStringArguments(value: unknown, schema: unknown): unknown;
13
+ type StructuredKind = "array" | "object";
14
+ /**
15
+ * Explains why a value is not the expected array or object, for validator
16
+ * messages. A string gets an explicit instruction because that is the usual
17
+ * client mistake; the hint never echoes the value itself.
18
+ */
19
+ export declare function structuredTypeHint(value: unknown, expected: StructuredKind): string;
20
+ /** True when a tool call arrived with no usable arguments at all. */
21
+ export declare function isEmptyToolInput(input: unknown): boolean;
22
+ export declare const emptyToolInputHint: string;
23
+ export {};
@@ -0,0 +1,121 @@
1
+ /**
2
+ * MCP clients sometimes send a structured tool argument as its JSON text, for
3
+ * example `sidecars: "[{...}]"` instead of `sidecars: [{...}]`. At the tool-call
4
+ * boundary, before any validation, this replaces such a string with its parsed
5
+ * value, but only where the tool's declared input schema says the value is an
6
+ * array or an object and the string parses to exactly that kind of value.
7
+ *
8
+ * Nothing else is coerced: a string field that happens to contain JSON stays a
9
+ * string, an undeclared field is left alone, and a malformed string is passed
10
+ * through unchanged so the validator reports it.
11
+ */
12
+ export function coerceJsonStringArguments(value, schema) {
13
+ const node = schemaNode(schema);
14
+ if (!node)
15
+ return value;
16
+ const expected = structuredKind(node);
17
+ let current = value;
18
+ if (typeof current === "string" && expected) {
19
+ const parsed = parseStructured(current, expected);
20
+ if (parsed !== undefined)
21
+ current = parsed;
22
+ }
23
+ if (Array.isArray(current)) {
24
+ const items = schemaNode(node.items);
25
+ if (!items || !acceptsKind(node, "array"))
26
+ return current;
27
+ let changed = current !== value;
28
+ const next = current.map((entry) => {
29
+ const coerced = coerceJsonStringArguments(entry, items);
30
+ if (coerced !== entry)
31
+ changed = true;
32
+ return coerced;
33
+ });
34
+ return changed ? next : current;
35
+ }
36
+ if (isPlainRecord(current)) {
37
+ const properties = schemaNode(node.properties);
38
+ if (!properties || !acceptsKind(node, "object"))
39
+ return current;
40
+ let next = current !== value ? { ...current } : null;
41
+ for (const [key, propertySchema] of Object.entries(properties)) {
42
+ if (!Object.prototype.hasOwnProperty.call(current, key))
43
+ continue;
44
+ const original = current[key];
45
+ const coerced = coerceJsonStringArguments(original, propertySchema);
46
+ if (coerced !== original) {
47
+ next ??= { ...current };
48
+ next[key] = coerced;
49
+ }
50
+ }
51
+ return next ?? current;
52
+ }
53
+ return current;
54
+ }
55
+ function structuredKind(node) {
56
+ const type = node.type;
57
+ if (type === "array" || type === "object")
58
+ return type;
59
+ if (Array.isArray(type)) {
60
+ // A schema that also admits a string must keep the string as sent.
61
+ if (type.includes("string"))
62
+ return null;
63
+ if (type.includes("array") && !type.includes("object"))
64
+ return "array";
65
+ if (type.includes("object") && !type.includes("array"))
66
+ return "object";
67
+ }
68
+ return null;
69
+ }
70
+ function acceptsKind(node, kind) {
71
+ const type = node.type;
72
+ if (type === undefined)
73
+ return true;
74
+ return type === kind || (Array.isArray(type) && type.includes(kind));
75
+ }
76
+ function parseStructured(text, expected) {
77
+ const trimmed = text.trim();
78
+ if (!trimmed.startsWith(expected === "array" ? "[" : "{"))
79
+ return undefined;
80
+ try {
81
+ const parsed = JSON.parse(trimmed);
82
+ if (expected === "array" ? Array.isArray(parsed) : isPlainRecord(parsed))
83
+ return parsed;
84
+ }
85
+ catch {
86
+ // Leave malformed JSON text in place; the validator reports it with a hint.
87
+ }
88
+ return undefined;
89
+ }
90
+ function schemaNode(value) {
91
+ return isPlainRecord(value) ? value : null;
92
+ }
93
+ function isPlainRecord(value) {
94
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
95
+ }
96
+ /**
97
+ * Explains why a value is not the expected array or object, for validator
98
+ * messages. A string gets an explicit instruction because that is the usual
99
+ * client mistake; the hint never echoes the value itself.
100
+ */
101
+ export function structuredTypeHint(value, expected) {
102
+ if (value === undefined || value === null) {
103
+ return " (it was omitted)";
104
+ }
105
+ if (typeof value === "string") {
106
+ return expected === "array"
107
+ ? " (received a string; pass a JSON array value, not a quoted string)"
108
+ : " (received a string; pass a JSON object value, not a quoted string)";
109
+ }
110
+ if (Array.isArray(value))
111
+ return " (received an array)";
112
+ return typeof value === "object" ? " (received an object)" : ` (received a ${typeof value})`;
113
+ }
114
+ /** True when a tool call arrived with no usable arguments at all. */
115
+ export function isEmptyToolInput(input) {
116
+ return input === undefined
117
+ || input === null
118
+ || (isPlainRecord(input) && Object.keys(input).length === 0);
119
+ }
120
+ export const emptyToolInputHint = "No arguments were received: the call arrived as an empty object. "
121
+ + "If the call was large it was probably cut off before it was sent; resend it with every required field.";
@@ -0,0 +1,20 @@
1
+ export interface ArtifactBundleFile {
2
+ readonly fileName: string;
3
+ readonly content: string;
4
+ }
5
+ export interface ArtifactBundlePublicationOptions {
6
+ readonly signal?: AbortSignal;
7
+ /** Fault-injection hook used by publication tests. */
8
+ readonly beforePublishFile?: (fileName: string, index: number) => void | Promise<void>;
9
+ }
10
+ /**
11
+ * Stages a complete phase bundle outside the live artifact directory, then
12
+ * publishes its canonical verdict/marker last. Consumers treat the marker as
13
+ * the bundle's commit point, so they can observe either the old complete bundle
14
+ * or the new complete bundle, never a partially written set. A failed or
15
+ * cancelled publication rolls every touched file back before rejecting.
16
+ */
17
+ export declare function publishArtifactBundleAtomic(artifactRoot: string, files: readonly ArtifactBundleFile[], commitFileName: string, options?: ArtifactBundlePublicationOptions): Promise<void>;
18
+ export declare function validatePostRedaction(validate: () => void): void;
19
+ export declare function postRedactionValidationError(error: unknown): Error;
20
+ export declare function assertStructuralFieldsUnchanged(original: Record<string, unknown>, redacted: Record<string, unknown>): void;
@@ -0,0 +1,167 @@
1
+ import crypto from "node:crypto";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { isNodeError, stableStringify } from "./phase-completion.validation.js";
5
+ /**
6
+ * Stages a complete phase bundle outside the live artifact directory, then
7
+ * publishes its canonical verdict/marker last. Consumers treat the marker as
8
+ * the bundle's commit point, so they can observe either the old complete bundle
9
+ * or the new complete bundle, never a partially written set. A failed or
10
+ * cancelled publication rolls every touched file back before rejecting.
11
+ */
12
+ export async function publishArtifactBundleAtomic(artifactRoot, files, commitFileName, options = {}) {
13
+ validateArtifactBundleFiles(files, commitFileName);
14
+ throwIfPublicationCancelled(options.signal);
15
+ const parent = path.dirname(artifactRoot);
16
+ const transactionId = `${process.pid}.${crypto.randomUUID()}`;
17
+ const stagingRoot = path.join(parent, `.${path.basename(artifactRoot)}.${transactionId}.publish`);
18
+ const backupRoot = path.join(stagingRoot, ".previous");
19
+ const orderedFiles = [
20
+ ...files.filter((file) => file.fileName !== commitFileName),
21
+ files.find((file) => file.fileName === commitFileName)
22
+ ];
23
+ const backedUp = new Set();
24
+ const published = new Set();
25
+ try {
26
+ await fs.mkdir(parent, { recursive: true });
27
+ await fs.mkdir(stagingRoot, { recursive: false });
28
+ for (const file of orderedFiles) {
29
+ throwIfPublicationCancelled(options.signal);
30
+ const handle = await fs.open(path.join(stagingRoot, file.fileName), "wx");
31
+ try {
32
+ await handle.writeFile(file.content, { encoding: "utf8", signal: options.signal });
33
+ await handle.sync();
34
+ }
35
+ finally {
36
+ await handle.close();
37
+ }
38
+ }
39
+ throwIfPublicationCancelled(options.signal);
40
+ await fs.mkdir(artifactRoot, { recursive: true });
41
+ await fs.mkdir(backupRoot, { recursive: true });
42
+ // Hide the previous commit marker before changing any supporting file.
43
+ for (const fileName of [commitFileName, ...orderedFiles.map((file) => file.fileName).filter((name) => name !== commitFileName)]) {
44
+ const livePath = path.join(artifactRoot, fileName);
45
+ try {
46
+ await fs.rename(livePath, path.join(backupRoot, fileName));
47
+ backedUp.add(fileName);
48
+ }
49
+ catch (error) {
50
+ if (!isNodeError(error) || error.code !== "ENOENT") {
51
+ throw error;
52
+ }
53
+ }
54
+ }
55
+ for (const [index, file] of orderedFiles.entries()) {
56
+ throwIfPublicationCancelled(options.signal);
57
+ await options.beforePublishFile?.(file.fileName, index);
58
+ await fs.rename(path.join(stagingRoot, file.fileName), path.join(artifactRoot, file.fileName));
59
+ published.add(file.fileName);
60
+ }
61
+ }
62
+ catch (error) {
63
+ const rollbackErrors = [];
64
+ for (const file of [...orderedFiles].reverse()) {
65
+ if (!published.has(file.fileName))
66
+ continue;
67
+ await fs.rm(path.join(artifactRoot, file.fileName), { force: true }).catch(() => {
68
+ rollbackErrors.push(file.fileName);
69
+ });
70
+ }
71
+ // Restore the previous marker last for the same observable commit boundary.
72
+ const restoreOrder = [
73
+ ...orderedFiles.filter((file) => file.fileName !== commitFileName),
74
+ orderedFiles.find((file) => file.fileName === commitFileName)
75
+ ];
76
+ for (const file of restoreOrder) {
77
+ if (!backedUp.has(file.fileName))
78
+ continue;
79
+ await fs.rename(path.join(backupRoot, file.fileName), path.join(artifactRoot, file.fileName)).catch(() => {
80
+ rollbackErrors.push(file.fileName);
81
+ });
82
+ }
83
+ if (rollbackErrors.length === 0
84
+ && error instanceof Error
85
+ && error.message.startsWith("artifact_atomic_publish_cancelled:")) {
86
+ throw error;
87
+ }
88
+ const suffix = rollbackErrors.length > 0 ? " Rollback did not restore every bundle file." : "";
89
+ throw new Error(`artifact_atomic_publish_failure: completion artifact bundle was not published.${suffix}`, { cause: error });
90
+ }
91
+ finally {
92
+ await fs.rm(stagingRoot, { recursive: true, force: true }).catch(() => undefined);
93
+ }
94
+ }
95
+ function validateArtifactBundleFiles(files, commitFileName) {
96
+ if (files.length === 0 || !files.some((file) => file.fileName === commitFileName)) {
97
+ throw new Error("artifact_atomic_publish_failure: bundle commit file is missing.");
98
+ }
99
+ const names = new Set();
100
+ for (const file of files) {
101
+ if (!file.fileName || path.basename(file.fileName) !== file.fileName || names.has(file.fileName)) {
102
+ throw new Error("artifact_atomic_publish_failure: bundle file names must be unique safe base names.");
103
+ }
104
+ names.add(file.fileName);
105
+ }
106
+ }
107
+ function throwIfPublicationCancelled(signal) {
108
+ if (signal?.aborted) {
109
+ throw new Error("artifact_atomic_publish_cancelled: completion artifact bundle publication was cancelled.");
110
+ }
111
+ }
112
+ export function validatePostRedaction(validate) {
113
+ try {
114
+ validate();
115
+ }
116
+ catch (error) {
117
+ throw postRedactionValidationError(error);
118
+ }
119
+ }
120
+ export function postRedactionValidationError(error) {
121
+ const message = error instanceof Error ? error.message : String(error);
122
+ return new Error(`artifact_post_redaction_validation_failed: ${message}`, { cause: error });
123
+ }
124
+ export function assertStructuralFieldsUnchanged(original, redacted) {
125
+ if (structuralFieldFingerprint(original) !== structuralFieldFingerprint(redacted)) {
126
+ // This stable code is intentionally safe for telemetry: it does not include
127
+ // the structural value or any candidate secret.
128
+ throw new Error("artifact_redaction_changed_structural_field: redaction changed a structural identifier; the bundle was not published.");
129
+ }
130
+ }
131
+ function structuralFieldFingerprint(value, key = "", result = []) {
132
+ if (Array.isArray(value)) {
133
+ if (isStructuralFieldKey(key) && value.every((item) => item === null || typeof item !== "object")) {
134
+ result.push(stableStringify(value));
135
+ }
136
+ else {
137
+ for (const item of value)
138
+ structuralFieldFingerprint(item, key, result);
139
+ }
140
+ return result.join("\n");
141
+ }
142
+ if (!value || typeof value !== "object") {
143
+ if (isStructuralFieldKey(key))
144
+ result.push(stableStringify(value));
145
+ return result.join("\n");
146
+ }
147
+ for (const [childKey, child] of Object.entries(value)) {
148
+ if (isStructuralFieldKey(childKey)) {
149
+ result.push(`${childKey}:${stableStringify(child)}`);
150
+ }
151
+ else {
152
+ structuralFieldFingerprint(child, childKey, result);
153
+ }
154
+ }
155
+ return result.join("\n");
156
+ }
157
+ function isStructuralFieldKey(key) {
158
+ return key === "id"
159
+ || key === "before"
160
+ || key === "after"
161
+ || key === "from"
162
+ || key === "to"
163
+ || key === "tasks"
164
+ || key === "phases"
165
+ || /(?:^|_)(?:id|ids)$/i.test(key)
166
+ || /(?:Id|Ids)$/.test(key);
167
+ }
@@ -2,26 +2,18 @@ import { type CompletionArtifactReference, type CompletionPhase, type Completion
2
2
  import type { RunnerDispatchArtifact } from "./session.types.js";
3
3
  export declare function writeDecomposeGateCompletionArtifact(config: CompletionToolServerConfig, gate: DecomposeCompletionGate, toolName: string, input: unknown): Promise<CompletionArtifactReference>;
4
4
  export declare function writeDraftGateCompletionArtifact(config: CompletionToolServerConfig, gate: DraftCompletionGate, toolName: string, input: unknown): Promise<CompletionArtifactReference>;
5
+ /**
6
+ * Judges a Decompose gate call before anything is written and returns its status. The gate's
7
+ * input schema advertises exactly these rules (see the completion tool schema contract test).
8
+ */
9
+ export declare function validateDecomposeGatePayload(gate: DecomposeCompletionGate, payload: Record<string, unknown>): string;
10
+ /** Judges a Draft gate call before anything is written and returns its status. */
11
+ export declare function validateDraftGatePayload(gate: DraftCompletionGate, payload: Record<string, unknown>): string;
5
12
  export declare function writeCompletionArtifact(config: CompletionToolServerConfig, toolName: string, input: unknown): Promise<CompletionArtifactReference>;
6
13
  export declare function writeArchitectCompletionArtifact(config: CompletionToolServerConfig, payload: Record<string, unknown>, status: string, producedBy: string): Promise<CompletionArtifactReference>;
7
14
  export declare function writeQaGateCompletionArtifact(config: CompletionToolServerConfig, gate: QaCompletionGate, input: unknown): Promise<CompletionArtifactReference>;
8
15
  export declare function writeQaCompletionArtifact(config: CompletionToolServerConfig, payload: Record<string, unknown>, status: string, producedBy: string): Promise<CompletionArtifactReference>;
9
16
  export declare function readQaGateArtifact(config: CompletionToolServerConfig, gate: QaCompletionGate): Promise<Record<string, unknown>>;
10
17
  export declare function readCompletionArtifact(worktreePath: string, workItemId: string, phase: CompletionPhase, ownerType?: string | null, ownerId?: string | null): Promise<RunnerDispatchArtifact | null>;
11
- export interface ArtifactBundleFile {
12
- readonly fileName: string;
13
- readonly content: string;
14
- }
15
- export interface ArtifactBundlePublicationOptions {
16
- readonly signal?: AbortSignal;
17
- /** Fault-injection hook used by publication tests. */
18
- readonly beforePublishFile?: (fileName: string, index: number) => void | Promise<void>;
19
- }
20
- /**
21
- * Stages a complete phase bundle outside the live artifact directory, then
22
- * publishes its canonical verdict/marker last. Consumers treat the marker as
23
- * the bundle's commit point, so they can observe either the old complete bundle
24
- * or the new complete bundle, never a partially written set. A failed or
25
- * cancelled publication rolls every touched file back before rejecting.
26
- */
27
- export declare function publishArtifactBundleAtomic(artifactRoot: string, files: readonly ArtifactBundleFile[], commitFileName: string, options?: ArtifactBundlePublicationOptions): Promise<void>;
18
+ export { publishArtifactBundleAtomic } from "./phase-completion.artifact-bundle.js";
19
+ export type { ArtifactBundleFile, ArtifactBundlePublicationOptions } from "./phase-completion.artifact-bundle.js";