@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 0.1.4-dev.03584818ede5

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 (275) hide show
  1. package/README.md +146 -5
  2. package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
  3. package/dist/bridge/bridge-chat-provider-command.js +137 -0
  4. package/dist/bridge/bridge-chat.types.d.ts +121 -0
  5. package/dist/bridge/bridge-chat.types.js +416 -0
  6. package/dist/bridge/bridge.base.d.ts +13 -1
  7. package/dist/bridge/bridge.service.d.ts +155 -4
  8. package/dist/bridge/bridge.service.js +1805 -155
  9. package/dist/bridge/bridge.types.d.ts +68 -1
  10. package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
  11. package/dist/bridge/dispatch-result-outbox.js +87 -0
  12. package/dist/bridge/dispatch-result-worker.d.ts +2 -0
  13. package/dist/bridge/dispatch-result-worker.js +122 -0
  14. package/dist/bridge/internals.d.ts +2 -0
  15. package/dist/bridge/internals.js +1 -0
  16. package/dist/bridge/local-yield-flag.d.ts +6 -0
  17. package/dist/bridge/local-yield-flag.js +34 -0
  18. package/dist/bridge/readiness-result-outbox.d.ts +21 -0
  19. package/dist/bridge/readiness-result-outbox.js +54 -0
  20. package/dist/bridge/readiness-result-worker.d.ts +2 -0
  21. package/dist/bridge/readiness-result-worker.js +121 -0
  22. package/dist/bridge/runner-host-capabilities.d.ts +20 -0
  23. package/dist/bridge/runner-host-capabilities.js +110 -0
  24. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  25. package/dist/bridge/test-postgres-capability.js +120 -0
  26. package/dist/cleanup/cleanup.service.d.ts +10 -0
  27. package/dist/cleanup/cleanup.service.js +128 -104
  28. package/dist/cleanup/cleanup.types.d.ts +4 -0
  29. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  30. package/dist/cleanup/forge-owned-paths.js +53 -0
  31. package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
  32. package/dist/cleanup/host-runtime-ledger.js +109 -0
  33. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  34. package/dist/cleanup/managed-branch-sweep.js +111 -0
  35. package/dist/cli/cli.help.js +22 -4
  36. package/dist/cli/cli.service.d.ts +30 -6
  37. package/dist/cli/cli.service.js +216 -31
  38. package/dist/cli/local-config.d.ts +5 -0
  39. package/dist/cli/local-config.js +30 -4
  40. package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
  41. package/dist/runtime/aspnet-runtime-prebuild.js +429 -0
  42. package/dist/runtime/attempt-database-broker.d.ts +89 -0
  43. package/dist/runtime/attempt-database-broker.js +390 -0
  44. package/dist/runtime/attempt-node-runtime-launcher.d.ts +2 -1
  45. package/dist/runtime/attempt-node-runtime-launcher.js +57 -18
  46. package/dist/runtime/attempt-path-operation.d.ts +21 -0
  47. package/dist/runtime/attempt-path-operation.js +94 -0
  48. package/dist/runtime/attempt-private-directory.d.ts +6 -0
  49. package/dist/runtime/attempt-private-directory.js +54 -0
  50. package/dist/runtime/attempt-process-supervisor.d.ts +35 -0
  51. package/dist/runtime/attempt-process-supervisor.js +144 -23
  52. package/dist/runtime/canonical-source-file.d.ts +3 -0
  53. package/dist/runtime/canonical-source-file.js +54 -0
  54. package/dist/runtime/docker-engine-probe.d.ts +90 -0
  55. package/dist/runtime/docker-engine-probe.js +333 -0
  56. package/dist/runtime/generated-output-reset.d.ts +10 -0
  57. package/dist/runtime/generated-output-reset.js +62 -8
  58. package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
  59. package/dist/runtime/host-database-capability-boundary.js +63 -0
  60. package/dist/runtime/host-diagnostics.d.ts +11 -0
  61. package/dist/runtime/host-diagnostics.js +192 -0
  62. package/dist/runtime/host-execution-root.d.ts +4 -0
  63. package/dist/runtime/host-execution-root.js +39 -0
  64. package/dist/runtime/host-facts.d.ts +36 -0
  65. package/dist/runtime/host-facts.js +95 -0
  66. package/dist/runtime/host-listener-inspector.d.ts +8 -1
  67. package/dist/runtime/host-listener-inspector.js +121 -60
  68. package/dist/runtime/host-load-admission.d.ts +67 -0
  69. package/dist/runtime/host-load-admission.js +99 -0
  70. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  71. package/dist/runtime/host-load-child-environment.js +76 -0
  72. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  73. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  74. package/dist/runtime/host-load-governor-config.d.ts +52 -0
  75. package/dist/runtime/host-load-governor-config.js +83 -0
  76. package/dist/runtime/host-load-governor.d.ts +184 -0
  77. package/dist/runtime/host-load-governor.js +632 -0
  78. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  79. package/dist/runtime/host-load-ledger-lock.js +185 -0
  80. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  81. package/dist/runtime/host-load-runtime-settings.js +78 -0
  82. package/dist/runtime/host-load-sampler.d.ts +149 -0
  83. package/dist/runtime/host-load-sampler.js +291 -0
  84. package/dist/runtime/host-load-step-class.d.ts +70 -0
  85. package/dist/runtime/host-load-step-class.js +161 -0
  86. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  87. package/dist/runtime/host-load-step-reaper.js +95 -0
  88. package/dist/runtime/host-load-step-run.d.ts +73 -0
  89. package/dist/runtime/host-load-step-run.js +102 -0
  90. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  91. package/dist/runtime/host-load-test-slot.js +81 -0
  92. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  93. package/dist/runtime/host-load-token-ledger.js +453 -0
  94. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  95. package/dist/runtime/host-load-windows-cpu.js +85 -0
  96. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  97. package/dist/runtime/host-pressure-stall.js +168 -0
  98. package/dist/runtime/host-runtime-contract.d.ts +16 -1
  99. package/dist/runtime/host-runtime-contract.js +174 -56
  100. package/dist/runtime/host-runtime-lease.d.ts +163 -9
  101. package/dist/runtime/host-runtime-lease.js +1464 -121
  102. package/dist/runtime/host-runtime-promotion.d.ts +35 -3
  103. package/dist/runtime/host-runtime-promotion.js +107 -12
  104. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  105. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  106. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  107. package/dist/runtime/host-runtime-requirements.js +117 -0
  108. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  109. package/dist/runtime/managed-command-teardown.js +607 -0
  110. package/dist/runtime/memory-capacity.d.ts +70 -0
  111. package/dist/runtime/memory-capacity.js +123 -0
  112. package/dist/runtime/native-test-postgres-fallback.d.ts +25 -0
  113. package/dist/runtime/native-test-postgres-fallback.js +91 -0
  114. package/dist/runtime/node-host-runtime-adapter.d.ts +3 -0
  115. package/dist/runtime/node-host-runtime-adapter.js +29 -11
  116. package/dist/runtime/pinned-directory-process.d.ts +9 -0
  117. package/dist/runtime/pinned-directory-process.js +61 -0
  118. package/dist/runtime/pinned-source-directory.d.ts +17 -0
  119. package/dist/runtime/pinned-source-directory.js +94 -0
  120. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  121. package/dist/runtime/playwright-browser-cache.js +227 -0
  122. package/dist/runtime/playwright-host-runtime-adapter.d.ts +19 -0
  123. package/dist/runtime/playwright-host-runtime-adapter.js +113 -59
  124. package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
  125. package/dist/runtime/prepared-runtime-identity.js +218 -0
  126. package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
  127. package/dist/runtime/prepared-runtime-readiness.js +285 -0
  128. package/dist/runtime/runner-settings.d.ts +100 -0
  129. package/dist/runtime/runner-settings.js +214 -0
  130. package/dist/runtime/runtime-isolation-lease.js +4 -1
  131. package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
  132. package/dist/runtime/workspace-resource-estimator.js +174 -0
  133. package/dist/sandbox/host-capacity-broker.d.ts +113 -0
  134. package/dist/sandbox/host-capacity-broker.js +334 -0
  135. package/dist/sandbox/preflight.d.ts +31 -1
  136. package/dist/sandbox/preflight.js +237 -51
  137. package/dist/sandbox/repository-lock.d.ts +2 -1
  138. package/dist/sandbox/repository-lock.js +19 -9
  139. package/dist/sandbox/runtime.d.ts +16 -2
  140. package/dist/sandbox/runtime.js +182 -109
  141. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  142. package/dist/sandbox/sandbox-cgroups.js +42 -0
  143. package/dist/sandbox/sandbox.types.d.ts +7 -0
  144. package/dist/sandbox/workspace.service.js +2 -0
  145. package/dist/session/architect-waits.d.ts +2 -0
  146. package/dist/session/architect-waits.js +138 -0
  147. package/dist/session/managed-attempt-tools.d.ts +44 -1
  148. package/dist/session/managed-attempt-tools.js +816 -46
  149. package/dist/session/managed-build-coordinator.d.ts +5 -0
  150. package/dist/session/managed-build-coordinator.js +109 -0
  151. package/dist/session/managed-build-receipt.d.ts +21 -0
  152. package/dist/session/managed-build-receipt.js +337 -0
  153. package/dist/session/managed-command-host-load.d.ts +47 -0
  154. package/dist/session/managed-command-host-load.js +83 -0
  155. package/dist/session/managed-verification-timeouts.d.ts +8 -0
  156. package/dist/session/managed-verification-timeouts.js +17 -0
  157. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  158. package/dist/session/mcp-argument-coercion.js +121 -0
  159. package/dist/session/phase-completion.artifacts.d.ts +24 -0
  160. package/dist/session/phase-completion.artifacts.js +319 -44
  161. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  162. package/dist/session/phase-completion.command-validation.js +77 -0
  163. package/dist/session/phase-completion.d.ts +15 -1
  164. package/dist/session/phase-completion.helpers.d.ts +5 -0
  165. package/dist/session/phase-completion.helpers.js +43 -19
  166. package/dist/session/phase-completion.js +18 -3
  167. package/dist/session/phase-completion.prompts.js +22 -18
  168. package/dist/session/phase-completion.runtime.d.ts +6 -2
  169. package/dist/session/phase-completion.runtime.js +191 -47
  170. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  171. package/dist/session/phase-completion.schema-parts.js +188 -0
  172. package/dist/session/phase-completion.schemas.d.ts +3 -3
  173. package/dist/session/phase-completion.schemas.js +250 -226
  174. package/dist/session/phase-completion.validation.d.ts +3 -3
  175. package/dist/session/phase-completion.validation.js +135 -89
  176. package/dist/session/pre-publication-host-load.d.ts +27 -0
  177. package/dist/session/pre-publication-host-load.js +111 -0
  178. package/dist/session/pre-publication-pass.d.ts +61 -0
  179. package/dist/session/pre-publication-pass.js +148 -0
  180. package/dist/session/pre-publication-process.d.ts +23 -0
  181. package/dist/session/pre-publication-process.js +109 -0
  182. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  183. package/dist/session/pre-publication-skipped-tests.js +109 -0
  184. package/dist/session/pre-publication-step-execution.d.ts +11 -0
  185. package/dist/session/pre-publication-step-execution.js +49 -0
  186. package/dist/session/pre-publication-validation.d.ts +87 -0
  187. package/dist/session/pre-publication-validation.js +668 -0
  188. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
  189. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
  190. package/dist/session/provider-cli/ci-repair-readiness.d.ts +8 -0
  191. package/dist/session/provider-cli/ci-repair-readiness.js +23 -3
  192. package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
  193. package/dist/session/provider-cli/claude-background-work.js +180 -0
  194. package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
  195. package/dist/session/provider-cli/pre-publication-repair.js +243 -0
  196. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +6 -3
  197. package/dist/session/provider-cli/provider-cli.artifacts.js +62 -22
  198. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  199. package/dist/session/provider-cli/provider-cli.child-environment.js +73 -0
  200. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  201. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  202. package/dist/session/provider-cli/provider-cli.deterministic.js +34 -2
  203. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  204. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  205. package/dist/session/provider-cli/provider-cli.process.d.ts +92 -14
  206. package/dist/session/provider-cli/provider-cli.process.js +583 -210
  207. package/dist/session/provider-cli/provider-cli.prompts.d.ts +12 -0
  208. package/dist/session/provider-cli/provider-cli.prompts.js +200 -25
  209. package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
  210. package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
  211. package/dist/session/provider-cli/provider-cli.runtime.d.ts +14 -1
  212. package/dist/session/provider-cli/provider-cli.runtime.js +61 -3
  213. package/dist/session/provider-cli/provider-cli.service.d.ts +33 -5
  214. package/dist/session/provider-cli/provider-cli.service.js +819 -84
  215. package/dist/session/provider-cli/provider-cli.types.d.ts +32 -0
  216. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  217. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  218. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  219. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  220. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  221. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  222. package/dist/session/provider-cli/provider-output-state.d.ts +18 -0
  223. package/dist/session/provider-cli/provider-output-state.js +376 -17
  224. package/dist/session/provider-cli/provider-usage.d.ts +9 -1
  225. package/dist/session/provider-cli/provider-usage.js +28 -5
  226. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  227. package/dist/session/publishable-worktree-changes.js +193 -0
  228. package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
  229. package/dist/session/sandbox-host-capacity-gate.js +238 -0
  230. package/dist/session/session-redaction.js +434 -9
  231. package/dist/session/session.base.d.ts +9 -1
  232. package/dist/session/session.service.d.ts +9 -2
  233. package/dist/session/session.service.js +264 -27
  234. package/dist/session/session.types.d.ts +150 -2
  235. package/dist/session/session.types.js +599 -7
  236. package/dist/session/unreferenced-exports.d.ts +12 -0
  237. package/dist/session/unreferenced-exports.js +59 -0
  238. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  239. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  240. package/dist/shared/format/format-bytes.d.ts +1 -0
  241. package/dist/shared/format/format-bytes.js +9 -0
  242. package/dist/shared/git/git.js +2 -1
  243. package/dist/shared/path/path.d.ts +1 -0
  244. package/dist/shared/path/path.js +18 -0
  245. package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
  246. package/dist/shared/process/dotnet-toolchain.js +307 -0
  247. package/dist/shared/process/host-process-recovery.js +3 -2
  248. package/dist/shared/process/host-process-supervisor.d.ts +3 -0
  249. package/dist/shared/process/host-process-supervisor.js +61 -12
  250. package/dist/shared/process/process-tree.d.ts +52 -0
  251. package/dist/shared/process/process-tree.js +144 -0
  252. package/dist/shared/process/process.d.ts +69 -0
  253. package/dist/shared/process/process.js +223 -16
  254. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  255. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  256. package/dist/shared/process/windows-launch.d.ts +18 -0
  257. package/dist/shared/process/windows-launch.js +68 -0
  258. package/dist/shared/provider-capabilities.d.ts +3 -0
  259. package/dist/shared/provider-capabilities.js +84 -0
  260. package/dist/shared/redaction/redaction.d.ts +1 -0
  261. package/dist/shared/redaction/redaction.js +39 -3
  262. package/dist/shared/time/monotonic.d.ts +1 -0
  263. package/dist/shared/time/monotonic.js +8 -0
  264. package/dist/version.d.ts +1 -1
  265. package/dist/version.js +1 -1
  266. package/dist/worktree/dependency-warmer.d.ts +66 -9
  267. package/dist/worktree/dependency-warmer.js +609 -24
  268. package/dist/worktree/index.d.ts +1 -1
  269. package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
  270. package/dist/worktree/story-qa-reference-hydrator.js +253 -0
  271. package/dist/worktree/worktree.service.d.ts +17 -1
  272. package/dist/worktree/worktree.service.js +293 -21
  273. package/dist/worktree/worktree.types.d.ts +14 -1
  274. package/package.json +8 -6
  275. package/runtime/windows-job-supervisor.ps1 +380 -14
@@ -1,4 +1,15 @@
1
1
  import path from "node:path";
2
+ import { redactText } from "../shared/redaction/redaction.js";
3
+ export class ForgeFailureError extends Error {
4
+ failureCode;
5
+ failureSource;
6
+ constructor(failureCode, message, failureSource = "bridge", options) {
7
+ super(message, options);
8
+ this.name = "ForgeFailureError";
9
+ this.failureCode = normalizeFailureCode(failureCode);
10
+ this.failureSource = failureSource;
11
+ }
12
+ }
2
13
  export function parseRunOnceDispatchPacket(value) {
3
14
  const packet = asObject(value, "dispatch packet");
4
15
  const schemaVersion = requiredNumber(packet, "schemaVersion");
@@ -34,6 +45,134 @@ export function parseRunOnceDispatchPacket(value) {
34
45
  draft: parseDraftPrompt(packet.draft)
35
46
  };
36
47
  }
48
+ export function parseRunOnceResultPacket(value) {
49
+ const packet = asObject(value, "run-once result packet");
50
+ const schemaVersion = requiredNumber(packet, "schemaVersion");
51
+ if (schemaVersion !== 1 && schemaVersion !== 2) {
52
+ throw new Error(`Unsupported run-once result schemaVersion: ${schemaVersion}`);
53
+ }
54
+ const exitCode = requiredNumber(packet, "exitCode");
55
+ if (!Number.isSafeInteger(exitCode))
56
+ throw new Error("exitCode must be an integer.");
57
+ requiredString(packet, "summary");
58
+ if (!Array.isArray(packet.events))
59
+ throw new Error("events must be an array.");
60
+ for (const item of packet.events) {
61
+ if (typeof item !== "object" || item === null || !("wait" in item))
62
+ continue;
63
+ const event = asObject(item, "run-once result event");
64
+ if (event.wait !== undefined && event.wait !== null) {
65
+ parseWaitEnvelope(event.wait, requiredString(event, "eventType"));
66
+ }
67
+ }
68
+ if (schemaVersion === 1) {
69
+ if (packet.failure !== undefined && packet.failure !== null) {
70
+ throw new Error("run-once result schemaVersion 1 cannot contain a v2 failure envelope.");
71
+ }
72
+ return packet;
73
+ }
74
+ if (exitCode === 0 && packet.failure !== undefined && packet.failure !== null) {
75
+ throw new Error("run-once result cannot report both success and a failure envelope.");
76
+ }
77
+ if (exitCode !== 0 && (packet.failure === undefined || packet.failure === null)) {
78
+ throw new Error("run-once result schemaVersion 2 requires a failure envelope for a nonzero exit.");
79
+ }
80
+ if (packet.failure !== undefined && packet.failure !== null)
81
+ parseFailureEnvelope(packet.failure);
82
+ return packet;
83
+ }
84
+ const waitKinds = new Map([
85
+ ["host_runtime_admission_waiting", "host_runtime_admission"],
86
+ ["host_runtime_admission_acquired", "host_runtime_admission"],
87
+ ["host_runtime_serial_admission_waiting", "host_runtime_serial_admission"],
88
+ ["host_runtime_prepared_probe_started", "host_runtime_prepared_probe"],
89
+ ["host_runtime_prepared_probe_progress", "host_runtime_prepared_probe"],
90
+ ["host_runtime_prepared_probe_completed", "host_runtime_prepared_probe"],
91
+ ["host_runtime_prepared_admission_waiting", "host_runtime_prepared_admission"],
92
+ ["host_runtime_prepared_admission_acquired", "host_runtime_prepared_admission"],
93
+ ]);
94
+ export function waitKindForEvent(eventType) {
95
+ const kind = waitKinds.get(eventType);
96
+ if (!kind)
97
+ throw new Error(`Unsupported typed wait observation '${eventType}'.`);
98
+ return kind;
99
+ }
100
+ export function waitWakeCondition(kind) {
101
+ switch (kind) {
102
+ case "host_runtime_serial_admission":
103
+ return "project_singleton_released";
104
+ case "host_runtime_prepared_probe":
105
+ return "prepared_runtime_probe_completed";
106
+ default:
107
+ return "host_runtime_admission_available";
108
+ }
109
+ }
110
+ function parseWaitEnvelope(value, eventType) {
111
+ const wait = asObject(value, "wait envelope");
112
+ if (requiredNumber(wait, "schemaVersion") !== 2) {
113
+ throw new Error("Unsupported wait envelope schemaVersion.");
114
+ }
115
+ let expectedKind;
116
+ try {
117
+ expectedKind = waitKindForEvent(eventType);
118
+ }
119
+ catch {
120
+ throw new Error("wait envelope is only valid on a wait lifecycle observation.");
121
+ }
122
+ const kind = requiredString(wait, "kind");
123
+ const scope = requiredString(wait, "scope");
124
+ const wakeCondition = requiredString(wait, "wakeCondition");
125
+ if (kind !== expectedKind
126
+ || !isWaitCode(kind, 80)
127
+ || !isWaitCode(scope, 64)
128
+ || !isWaitCode(wakeCondition, 80)
129
+ || wakeCondition !== waitWakeCondition(kind)) {
130
+ throw new Error("wait envelope kind, scope, or wakeCondition is invalid.");
131
+ }
132
+ if (!Array.isArray(wait.resourceKeys)
133
+ || wait.resourceKeys.length > 16
134
+ || wait.resourceKeys.some(item => typeof item !== "string" || !isWaitCode(item, 256))
135
+ || new Set(wait.resourceKeys).size !== wait.resourceKeys.length) {
136
+ throw new Error("wait envelope resourceKeys are invalid, duplicated, or exceed their bound.");
137
+ }
138
+ const queuePosition = wait.queuePosition;
139
+ if (queuePosition !== undefined && queuePosition !== null
140
+ && (typeof queuePosition !== "number" || !Number.isSafeInteger(queuePosition) || queuePosition <= 0)) {
141
+ throw new Error("wait envelope queuePosition is invalid.");
142
+ }
143
+ const blockerSessionId = wait.blockerSessionId;
144
+ if (blockerSessionId !== undefined && blockerSessionId !== null
145
+ && (typeof blockerSessionId !== "string"
146
+ || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu.test(blockerSessionId)
147
+ || /^0{8}-0{4}-0{4}-0{4}-0{12}$/u.test(blockerSessionId))) {
148
+ throw new Error("wait envelope blockerSessionId is invalid.");
149
+ }
150
+ const blockerTitle = wait.blockerTitle;
151
+ if (blockerTitle !== undefined && blockerTitle !== null
152
+ && (typeof blockerTitle !== "string" || blockerTitle.length > 500)) {
153
+ throw new Error("wait envelope blockerTitle is invalid.");
154
+ }
155
+ const retryAt = wait.retryAt;
156
+ if (retryAt !== undefined && retryAt !== null
157
+ && (typeof retryAt !== "string" || !Number.isFinite(Date.parse(retryAt)))) {
158
+ throw new Error("wait envelope retryAt is invalid.");
159
+ }
160
+ const firstObservedAt = requiredString(wait, "firstObservedAt");
161
+ if (!Number.isFinite(Date.parse(firstObservedAt))) {
162
+ throw new Error("wait envelope firstObservedAt is invalid.");
163
+ }
164
+ const observationVersion = requiredNumber(wait, "observationVersion");
165
+ if (!Number.isSafeInteger(observationVersion) || observationVersion <= 0) {
166
+ throw new Error("wait envelope observationVersion is invalid.");
167
+ }
168
+ if (requiredString(wait, "contractOrigin") !== "bridge_v2") {
169
+ throw new Error("wait envelope contractOrigin must identify the v2 Bridge writer.");
170
+ }
171
+ return value;
172
+ }
173
+ function isWaitCode(value, maximumLength) {
174
+ return value.length <= maximumLength && /^[a-z][a-z0-9_.:-]*$/u.test(value);
175
+ }
37
176
  function parseRuntimeIntent(value) {
38
177
  if (value === undefined || value === null) {
39
178
  return { executionClass: "managed_runtime", applicationRuntimeRequired: true };
@@ -171,17 +310,403 @@ function parseSandboxNetworkPolicy(value) {
171
310
  }
172
311
  return { mode, allowedHosts };
173
312
  }
174
- export function failureResult(summary, events = []) {
313
+ const failureCodePattern = /^[a-z][a-z0-9_.-]{0,79}$/u;
314
+ const failureCategories = new Set(["domain", "provider", "transport", "cancellation", "ownership", "resource", "unknown"]);
315
+ const failurePhases = new Set(["offer", "build", "prepare", "agent", "validation", "import", "teardown", "unknown"]);
316
+ const failureSources = new Set(["bridge", "provider", "sandbox", "unknown"]);
317
+ const failureRetryabilities = new Set(["retryable", "non_retryable", "policy_required", "unknown"]);
318
+ const failureOperatorActions = new Set(["none", "retry_dispatch", "retry_with_policy", "inspect_failure", "fix_input", "fix_environment", "reauthenticate", "restore_ownership"]);
319
+ const maximumFailureMessageLength = 2000;
320
+ const maximumFailureCausalChainLength = 8;
321
+ const waitConditionCodes = new Set([
322
+ "host_runtime_admission_waiting",
323
+ "host_runtime_serial_admission_waiting",
324
+ "host_runtime_prepared_probe_started",
325
+ "host_runtime_prepared_probe_progress",
326
+ "host_runtime_prepared_admission_waiting",
327
+ "waiting_for_capacity",
328
+ ]);
329
+ const stableFailureFamilyCodes = new Set([
330
+ "generated_output_reset_invalid",
331
+ "generated_output_reset_unsafe",
332
+ "sandbox_build_failed",
333
+ "sandbox_build_policy_failed",
334
+ "sandbox_builder_release_failed",
335
+ "sandbox_config_commit_invalid",
336
+ "sandbox_config_commit_missing",
337
+ "sandbox_config_commit_unapproved",
338
+ "contract_invalid",
339
+ "sandbox_input_failed",
340
+ "docker_capacity_unavailable",
341
+ "docker_engine_invalid_response",
342
+ "docker_engine_recovery_failed",
343
+ "docker_engine_recovery_timeout",
344
+ "docker_linux_required",
345
+ "docker_preflight_required",
346
+ "docker_rootless_required",
347
+ "docker_unavailable",
348
+ "docker_unreachable",
349
+ "sandbox_output_conflict",
350
+ "sandbox_output_invalid",
351
+ "sandbox_output_missing",
352
+ "sandbox_output_publish_forbidden",
353
+ "sandbox_output_rejected",
354
+ "sandbox_output_publish_rejected",
355
+ "sandbox_output_publish_stale",
356
+ "sandbox_output_publish_unavailable",
357
+ "sandbox_output_stale",
358
+ "sandbox_import_cancelled",
359
+ "sandbox_import_unavailable",
360
+ "teardown_failed",
361
+ "reaper_cleanup_degraded",
362
+ "reaper_runner_replaced",
363
+ "sandbox_egress_policy_invalid",
364
+ "sandbox_egress_proxy_unavailable",
365
+ "sandbox_event_flood",
366
+ "sandbox_event_invalid",
367
+ "sandbox_identity_invalid",
368
+ "sandbox_image_signature_failed",
369
+ "sandbox_log_limit",
370
+ "sandbox_preflight_failed",
371
+ "sandbox_security_profile_invalid",
372
+ "sandbox_security_profile_unavailable",
373
+ "sandbox_service_health_policy_invalid",
374
+ ]);
375
+ export function failureResult(summary, events = [], facts = failureFactsForCode("bridge.execution_failed")) {
175
376
  return {
176
- schemaVersion: 1,
377
+ schemaVersion: 2,
177
378
  exitCode: 1,
178
- summary,
179
- events
379
+ summary: boundedFailureText(summary),
380
+ events,
381
+ failure: createFailureEnvelope(summary, facts),
382
+ };
383
+ }
384
+ export function createFailureEnvelope(message, facts, occurredAt = new Date().toISOString()) {
385
+ const code = normalizeFailureCode(facts.code);
386
+ if (waitConditionCodes.has(code)) {
387
+ throw new Error(`Wait condition '${code}' must be emitted as lifecycle state, not a terminal failure.`);
388
+ }
389
+ assertFailureFactsMatchPolicy(code, facts);
390
+ return {
391
+ schemaVersion: 2,
392
+ code,
393
+ message: boundedFailureText(message),
394
+ category: facts.category,
395
+ phase: facts.phase,
396
+ source: facts.source,
397
+ retryability: facts.retryability,
398
+ operatorAction: facts.operatorAction,
399
+ causalChain: (facts.causalChain ?? []).slice(0, maximumFailureCausalChainLength).map(cause => ({
400
+ code: normalizeFailureCode(cause.code),
401
+ message: boundedFailureText(cause.message),
402
+ source: cause.source,
403
+ })),
404
+ occurredAt,
405
+ contractOrigin: "bridge_v2",
406
+ };
407
+ }
408
+ export function failureFactsFromError(error, options = {}) {
409
+ if (options.cancelled) {
410
+ const cancellationSource = options.source ?? "bridge";
411
+ return {
412
+ ...failureFactsForCode("bridge.dispatch_cancelled", cancellationSource),
413
+ causalChain: errorCauseChain(error, cancellationSource),
414
+ };
415
+ }
416
+ const source = error instanceof ForgeFailureError
417
+ ? error.failureSource
418
+ : options.source ?? "bridge";
419
+ const code = error instanceof ForgeFailureError
420
+ ? error.failureCode
421
+ : "bridge.execution_failed";
422
+ return {
423
+ ...failureFactsForCode(code, source),
424
+ causalChain: errorCauseChain(error, source),
180
425
  };
181
426
  }
427
+ export function failureFactsForCode(code, source = "bridge") {
428
+ const policy = failurePolicyForCode(code);
429
+ if (policy.known && !policy.allowedSources.includes(source)) {
430
+ throw new Error(`Failure code '${policy.code}' cannot be attributed to source '${source}'.`);
431
+ }
432
+ return {
433
+ code: policy.code,
434
+ category: policy.category,
435
+ phase: policy.phase,
436
+ source,
437
+ retryability: policy.retryability,
438
+ operatorAction: policy.operatorAction,
439
+ };
440
+ }
441
+ export function failurePolicyForCode(code) {
442
+ code = normalizeFailureCode(code);
443
+ const classification = unvalidatedFailureFactsForCode(code, "bridge");
444
+ const known = classification.category !== "unknown" || code === "legacy_failure_unknown";
445
+ return {
446
+ code,
447
+ category: classification.category,
448
+ phase: classification.phase,
449
+ retryability: classification.retryability,
450
+ operatorAction: classification.operatorAction,
451
+ allowedSources: allowedSourcesForCode(code, known),
452
+ known,
453
+ };
454
+ }
455
+ function unvalidatedFailureFactsForCode(code, source) {
456
+ code = normalizeFailureCode(code);
457
+ if (["bridge.dispatch_cancelled", "dispatch_cancelled", "dispatch_session_terminal", "dispatch.capacity_retargeted"].includes(code)) {
458
+ return facts(code, "cancellation", "teardown", source, "non_retryable", "none");
459
+ }
460
+ if (["bridge.dispatch_fence_conflict", "bridge.reservation_stale", "bridge.capacity_wait_lost", "bridge.dispatch_attempt_missing"].includes(code)) {
461
+ return facts(code, "ownership", "offer", source, "non_retryable", "restore_ownership");
462
+ }
463
+ if (["reservation_expired", "bridge.lease_expired", "bridge.stale_runner_instance", "bridge.runner_replaced"].includes(code)) {
464
+ return facts(code, "ownership", "offer", source, "retryable", "retry_dispatch");
465
+ }
466
+ if (["bridge.dispatch_failed", "bridge.execution_failed", "bridge.cli_execution_failed", "bridge_callback_timeout"].includes(code)) {
467
+ return facts(code, "transport", "unknown", source, "policy_required", "inspect_failure");
468
+ }
469
+ if (code === "bridge.unavailable") {
470
+ return facts(code, "transport", "offer", source, "retryable", "retry_dispatch");
471
+ }
472
+ if (["capacity_unavailable", "bridge.runner_draining", "docker_engine_unavailable", "docker_memory_low", "docker_memory_sample_unavailable", "docker_cpu_low", "docker_disk_low", "server_local.resource_pressure", "server_local.capacity_unavailable", "dispatch.preparation_resource_pressure", "sandbox_capacity_profile_unavailable", "host_runtime_admission_expired", "placement_requirements_unmet", "runner_yielding", "runner_settings_pending", "runner_settings_apply_failed", "runner_tier_light", "runner_project_not_allowed"].includes(code)) {
473
+ return facts(code, "resource", "offer", source, "retryable", "retry_dispatch");
474
+ }
475
+ if (["bridge.lease_retry_exhausted", "bridge.capacity_wait_exhausted"].includes(code)) {
476
+ return facts(code, "resource", "offer", source, "non_retryable", "inspect_failure");
477
+ }
478
+ if (["prepublication_infrastructure_failed", "prepublication_capability_unavailable", "host_capacity_timeout", "host_capacity_token_fenced", "host_capacity_ledger_unavailable"].includes(code)) {
479
+ return facts(code, "resource", "validation", source, "retryable", "retry_with_policy");
480
+ }
481
+ if (["prepublication_validation_failed", "prepublication_contract_invalid", "prepublication_execution_scope_invalid"].includes(code)) {
482
+ return facts(code, "domain", "validation", source, "non_retryable", "fix_input");
483
+ }
484
+ if (code === "comment_repair_changed_files_mismatch") {
485
+ return facts(code, "domain", "validation", source, "non_retryable", "inspect_failure");
486
+ }
487
+ if (["generated_output_reset_failed", "generated_output_reset_unverified", "worktree_prepare_failed", "host_runtime_ledger_write_failed", "host_diagnostics_temporary_unavailable", "attempt_process_supervisor_start_failed", "attempt_process_supervisor_start_timeout"].includes(code)) {
488
+ return facts(code, "transport", "prepare", source, "retryable", "retry_dispatch");
489
+ }
490
+ if (stableFailureFamilyCodes.has(code) && code.startsWith("generated_output_reset_")) {
491
+ return facts(code, "domain", "prepare", source, "non_retryable", "fix_environment");
492
+ }
493
+ if (code === "provider_start_unavailable") {
494
+ return facts(code, "provider", "prepare", source, "retryable", "retry_dispatch");
495
+ }
496
+ if (code === "provider_configuration_invalid") {
497
+ return facts(code, "provider", "prepare", source, "non_retryable", "fix_environment");
498
+ }
499
+ if (["host_port_collision", "host_runtime_process_exited", "host_runtime_listener_timeout", "host_runtime_http_readiness_timeout", "host_runtime_prepared_source_changed", "host_runtime_contract_changed", "host_runtime_prepared_probe_incomplete", "host_runtime_prepared_probe_cleanup_unconfirmed"].includes(code)) {
500
+ return facts(code, "resource", "prepare", source, "retryable", "retry_dispatch");
501
+ }
502
+ if (code === "host_runtime_project_start_failed") {
503
+ return facts(code, "domain", "prepare", source, "non_retryable", "fix_environment");
504
+ }
505
+ if (stableFailureFamilyCodes.has(code) && (code.startsWith("sandbox_build") || code.startsWith("image_"))) {
506
+ const policyFailure = code === "sandbox_build_policy_failed";
507
+ return facts(code, "resource", "build", source, policyFailure ? "non_retryable" : "retryable", policyFailure ? "fix_environment" : "retry_dispatch");
508
+ }
509
+ if (code === "provider_network_policy_denied"
510
+ || stableFailureFamilyCodes.has(code) && (code.startsWith("sandbox_config") || code.startsWith("contract_") || code.startsWith("sandbox_input"))) {
511
+ return facts(code, "domain", "prepare", source, "non_retryable", "fix_environment");
512
+ }
513
+ if (stableFailureFamilyCodes.has(code) && code.startsWith("docker_")) {
514
+ return facts(code, "resource", "prepare", source, "non_retryable", "fix_environment");
515
+ }
516
+ if (code === "provider_network_unavailable") {
517
+ return facts(code, "transport", "offer", source, "retryable", "retry_dispatch");
518
+ }
519
+ if (code === "provider_request_not_found") {
520
+ return facts(code, "provider", "offer", source, "retryable", "retry_dispatch");
521
+ }
522
+ if (code === "provider_capacity_unavailable") {
523
+ return facts(code, "resource", "offer", source, "retryable", "retry_dispatch");
524
+ }
525
+ if (code === "provider_completion_tool_missing") {
526
+ return facts(code, "provider", "agent", source, "non_retryable", "inspect_failure");
527
+ }
528
+ if (["provider_terminated_at_turn_ceiling", "provider_turn_ended_with_background_work"].includes(code)) {
529
+ return facts(code, "provider", "agent", source, "retryable", "retry_with_policy");
530
+ }
531
+ if (code === "provider_context_window_exhausted") {
532
+ return facts(code, "provider", "agent", source, "retryable", "retry_dispatch");
533
+ }
534
+ if (stableFailureFamilyCodes.has(code) && (code.startsWith("sandbox_output") || code.startsWith("sandbox_import"))) {
535
+ const retryable = code === "sandbox_import_unavailable" || code === "sandbox_output_publish_unavailable";
536
+ return facts(code, "transport", "import", source, retryable ? "retryable" : "non_retryable", retryable ? "retry_with_policy" : "inspect_failure");
537
+ }
538
+ if (stableFailureFamilyCodes.has(code) && (code.startsWith("teardown") || code.startsWith("reaper"))) {
539
+ return facts(code, "transport", "teardown", source, "retryable", "retry_with_policy");
540
+ }
541
+ if (["invalid_dispatch"].includes(code)) {
542
+ return facts(code, "domain", "offer", source, "non_retryable", "fix_input");
543
+ }
544
+ if ([
545
+ "bridge.api_key_auth_required",
546
+ "bridge.api_key_secret_grant_missing",
547
+ "bridge.api_key_secret_grant_denied",
548
+ "bridge.api_key_secret_grant_provider_mismatch",
549
+ "bridge.api_key_secret_missing",
550
+ "contract_plaintext_secret_rejected",
551
+ ].includes(code)) {
552
+ return facts(code, "domain", "prepare", source, "non_retryable", "reauthenticate");
553
+ }
554
+ if (code === "sandbox_idle_timeout") {
555
+ return facts(code, "provider", "agent", source, "retryable", "retry_with_policy");
556
+ }
557
+ if (code === "sandbox_wall_timeout") {
558
+ return facts(code, "provider", "agent", source, "retryable", "retry_with_policy");
559
+ }
560
+ if (["sandbox_oom_killed", "sandbox_pid_exhausted", "sandbox_file_descriptor_exhausted", "sandbox_storage_exhausted"].includes(code)) {
561
+ return facts(code, "resource", "agent", source, "non_retryable", "inspect_failure");
562
+ }
563
+ if (code === "sandbox_auth_unavailable") {
564
+ return facts(code, "domain", "prepare", source, "non_retryable", "reauthenticate");
565
+ }
566
+ if (code === "sandbox_lease_expired") {
567
+ return facts(code, "ownership", "agent", source, "non_retryable", "restore_ownership");
568
+ }
569
+ if (code === "sandbox_runtime_failed") {
570
+ return facts(code, "provider", "agent", source, "non_retryable", "inspect_failure");
571
+ }
572
+ if (code === "worktree_branch_integration_conflict") {
573
+ return facts(code, "domain", "agent", source, "non_retryable", "fix_input");
574
+ }
575
+ if (["merge_resolution_reverts_upstream_changes", "merge_resolution_unresolved_conflict"].includes(code)) {
576
+ return facts(code, "domain", "validation", source, "non_retryable", "inspect_failure");
577
+ }
578
+ if (stableFailureFamilyCodes.has(code) && code.startsWith("sandbox_")) {
579
+ return facts(code, "provider", "agent", source, "non_retryable", "inspect_failure");
580
+ }
581
+ return facts(code, "unknown", "unknown", source, "unknown", "inspect_failure");
582
+ }
583
+ function parseFailureEnvelope(value) {
584
+ const failure = asObject(value, "failure");
585
+ if (requiredNumber(failure, "schemaVersion") !== 2)
586
+ throw new Error("failure.schemaVersion must be 2.");
587
+ const code = requiredString(failure, "code");
588
+ const message = requiredString(failure, "message");
589
+ const category = requiredString(failure, "category");
590
+ const phase = requiredString(failure, "phase");
591
+ const source = requiredString(failure, "source");
592
+ const retryability = requiredString(failure, "retryability");
593
+ const operatorAction = requiredString(failure, "operatorAction");
594
+ const occurredAt = requiredString(failure, "occurredAt");
595
+ const contractOrigin = requiredString(failure, "contractOrigin");
596
+ if (!failureCodePattern.test(code))
597
+ throw new Error("failure.code is invalid.");
598
+ if (message.length > maximumFailureMessageLength)
599
+ throw new Error("failure.message is too long.");
600
+ if (!failureCategories.has(category) || !failurePhases.has(phase) || !failureSources.has(source)
601
+ || !failureRetryabilities.has(retryability) || !failureOperatorActions.has(operatorAction)) {
602
+ throw new Error("failure contains an unsupported category, phase, source, retryability, or operator action.");
603
+ }
604
+ assertFailureFactsMatchPolicy(code, { code, category, phase, source, retryability, operatorAction });
605
+ if (!Number.isFinite(Date.parse(occurredAt)))
606
+ throw new Error("failure.occurredAt is invalid.");
607
+ if (contractOrigin !== "bridge_v2")
608
+ throw new Error("failure.contractOrigin must be bridge_v2.");
609
+ if (!Array.isArray(failure.causalChain) || failure.causalChain.length > maximumFailureCausalChainLength) {
610
+ throw new Error("failure.causalChain is invalid or too long.");
611
+ }
612
+ const causalChain = failure.causalChain.map((candidate, index) => {
613
+ const cause = asObject(candidate, `failure.causalChain[${index}]`);
614
+ const causeCode = requiredString(cause, "code");
615
+ const causeMessage = requiredString(cause, "message");
616
+ const causeSource = requiredString(cause, "source");
617
+ if (!failureCodePattern.test(causeCode) || causeMessage.length > maximumFailureMessageLength || !failureSources.has(causeSource)) {
618
+ throw new Error(`failure.causalChain[${index}] is invalid.`);
619
+ }
620
+ return { code: causeCode, message: causeMessage, source: causeSource };
621
+ });
622
+ return { schemaVersion: 2, code, message, category, phase, source, retryability, operatorAction, causalChain, occurredAt, contractOrigin };
623
+ }
624
+ function facts(code, category, phase, source, retryability, operatorAction) {
625
+ return { code, category, phase, source, retryability, operatorAction };
626
+ }
627
+ function allowedSourcesForCode(code, known) {
628
+ if (!known)
629
+ return ["bridge", "provider", "sandbox", "unknown"];
630
+ if (code.startsWith("provider_"))
631
+ return ["bridge", "provider", "sandbox"];
632
+ if (code.startsWith("sandbox_")
633
+ || code.startsWith("docker_")
634
+ || code.startsWith("image_")
635
+ || code.startsWith("contract_")
636
+ || code.startsWith("generated_output_reset_")
637
+ || code.startsWith("teardown")
638
+ || code.startsWith("reaper")) {
639
+ return ["bridge", "sandbox"];
640
+ }
641
+ return ["bridge"];
642
+ }
643
+ function assertFailureFactsMatchPolicy(code, factsToValidate) {
644
+ const policy = failurePolicyForCode(code);
645
+ if (!policy.known)
646
+ return;
647
+ if (factsToValidate.category !== policy.category
648
+ || factsToValidate.phase !== policy.phase
649
+ || factsToValidate.retryability !== policy.retryability
650
+ || factsToValidate.operatorAction !== policy.operatorAction
651
+ || !policy.allowedSources.includes(factsToValidate.source)) {
652
+ throw new Error(`Failure code '${policy.code}' contradicts the failure taxonomy or allowed-source registry.`);
653
+ }
654
+ }
655
+ function normalizeFailureCode(value) {
656
+ const normalized = value.trim().toLowerCase().slice(0, 80);
657
+ return failureCodePattern.test(normalized) ? normalized : "bridge.execution_failed";
658
+ }
659
+ function boundedFailureText(value) {
660
+ const bounded = value.trim().slice(0, maximumFailureMessageLength);
661
+ return bounded || "Dispatch failed without a diagnostic message.";
662
+ }
663
+ /**
664
+ * Rebuilds an error graph at a privileged execution boundary without
665
+ * retaining the raw error or any raw recursive cause. Forge failure metadata
666
+ * survives so the P7 taxonomy remains authoritative after sanitization.
667
+ */
668
+ export function sanitizeFailureError(error, exactSecrets = []) {
669
+ return sanitizeFailureErrorAtDepth(error, exactSecrets, new Set(), 0);
670
+ }
671
+ function sanitizeFailureErrorAtDepth(error, exactSecrets, visited, depth) {
672
+ if (depth >= maximumFailureCausalChainLength) {
673
+ return new Error("Additional error causes were omitted.");
674
+ }
675
+ if (error !== null && typeof error === "object") {
676
+ if (visited.has(error))
677
+ return new Error("Circular error cause was omitted.");
678
+ visited.add(error);
679
+ }
680
+ const message = redactText(error instanceof Error ? error.message : String(error), exactSecrets);
681
+ const cause = error instanceof Error && error.cause !== undefined
682
+ ? sanitizeFailureErrorAtDepth(error.cause, exactSecrets, visited, depth + 1)
683
+ : undefined;
684
+ const options = cause === undefined ? undefined : { cause };
685
+ if (error instanceof ForgeFailureError) {
686
+ return new ForgeFailureError(error.failureCode, message, error.failureSource, options);
687
+ }
688
+ if (error instanceof AggregateError) {
689
+ const errors = [...error.errors].map(item => sanitizeFailureErrorAtDepth(item, exactSecrets, visited, depth + 1));
690
+ return new AggregateError(errors, message, options);
691
+ }
692
+ return new Error(message, options);
693
+ }
694
+ function errorCauseChain(error, source) {
695
+ const causes = [];
696
+ let current = error;
697
+ while (current !== undefined && current !== null && causes.length < maximumFailureCausalChainLength) {
698
+ const message = current instanceof Error ? current.message : String(current);
699
+ const code = current instanceof ForgeFailureError ? current.failureCode : "cause_unknown";
700
+ const causeSource = current instanceof ForgeFailureError ? current.failureSource : source;
701
+ causes.push({ code, message: boundedFailureText(message), source: causeSource });
702
+ current = current instanceof Error ? current.cause : undefined;
703
+ }
704
+ return causes;
705
+ }
182
706
  function parseWorkItem(value) {
183
707
  const item = asObject(value, "workItem");
184
708
  return {
709
+ projectId: optionalString(item, "projectId"),
185
710
  id: requiredString(item, "id"),
186
711
  kind: requiredString(item, "kind"),
187
712
  title: requiredString(item, "title"),
@@ -205,6 +730,7 @@ function parseRepo(value) {
205
730
  function parseCycleRun(value) {
206
731
  const cycle = asObject(value, "cycleRun");
207
732
  return {
733
+ effectivePlanAmendmentHash: optionalString(cycle, "effectivePlanAmendmentHash"),
208
734
  id: requiredString(cycle, "id"),
209
735
  ownerType: optionalString(cycle, "ownerType"),
210
736
  ownerId: optionalString(cycle, "ownerId"),
@@ -214,6 +740,7 @@ function parseCycleRun(value) {
214
740
  requestedBase: optionalString(cycle, "requestedBase") ?? "develop",
215
741
  baseBranch: optionalString(cycle, "baseBranch") ?? "develop",
216
742
  expectedCurrentBranch: optionalString(cycle, "expectedCurrentBranch"),
743
+ repairHeadSha: optionalString(cycle, "repairHeadSha"),
217
744
  attempt: requiredNumber(cycle, "attempt"),
218
745
  model: requiredString(cycle, "model")
219
746
  };
@@ -223,7 +750,9 @@ function parseSession(value) {
223
750
  return {
224
751
  id: requiredString(session, "id"),
225
752
  model: requiredString(session, "model"),
226
- lane: requiredString(session, "lane")
753
+ lane: requiredString(session, "lane"),
754
+ resumedFromSessionId: optionalString(session, "resumedFromSessionId"),
755
+ resumeProviderThreadId: optionalString(session, "resumeProviderThreadId")
227
756
  };
228
757
  }
229
758
  function parseLease(value) {
@@ -251,7 +780,8 @@ function parseExecution(value) {
251
780
  role: requiredString(execution, "role"),
252
781
  lane: requiredString(execution, "lane"),
253
782
  requiresApiKeySecretGrant: requiredBoolean(execution, "requiresApiKeySecretGrant"),
254
- runnerRepoLocalPath: optionalString(execution, "runnerRepoLocalPath")
783
+ runnerRepoLocalPath: optionalString(execution, "runnerRepoLocalPath"),
784
+ effort: optionalString(execution, "effort")
255
785
  };
256
786
  }
257
787
  function parseDraftPrompt(value) {
@@ -349,9 +879,49 @@ function parsePullRequest(value) {
349
879
  requiredChecksTotal: requiredNumber(pullRequest, "requiredChecksTotal"),
350
880
  unresolvedThreads: requiredNumber(pullRequest, "unresolvedThreads"),
351
881
  humanApproved: requiredBoolean(pullRequest, "humanApproved"),
352
- hasMergeConflicts: requiredBoolean(pullRequest, "hasMergeConflicts")
882
+ hasMergeConflicts: requiredBoolean(pullRequest, "hasMergeConflicts"),
883
+ headSha: optionalString(pullRequest, "headSha") ?? "",
884
+ reviewIssueKey: optionalString(pullRequest, "reviewIssueKey"),
885
+ reviewFindings: parsePullRequestReviewFindings(pullRequest.reviewFindings),
886
+ openWorkOrderStories: parseWorkOrderStories(pullRequest.openWorkOrderStories)
353
887
  };
354
888
  }
889
+ function parseWorkOrderStories(value) {
890
+ if (value === null || value === undefined)
891
+ return [];
892
+ if (!Array.isArray(value))
893
+ throw new Error("pullRequest.openWorkOrderStories must be an array when provided.");
894
+ return value.map((entry, index) => {
895
+ const story = asObject(entry, `pullRequest.openWorkOrderStories[${index}]`);
896
+ return {
897
+ workItemId: requiredString(story, "workItemId"),
898
+ title: optionalString(story, "title") ?? "",
899
+ acceptanceCriteria: optionalString(story, "acceptanceCriteria") ?? ""
900
+ };
901
+ });
902
+ }
903
+ function parsePullRequestReviewFindings(value) {
904
+ if (value === null || value === undefined)
905
+ return [];
906
+ if (!Array.isArray(value))
907
+ throw new Error("pullRequest.reviewFindings must be an array when provided.");
908
+ return value.map((entry, index) => {
909
+ const finding = asObject(entry, `pullRequest.reviewFindings[${index}]`);
910
+ return {
911
+ claimId: requiredString(finding, "claimId"),
912
+ kind: requiredString(finding, "kind"),
913
+ bodySha256: requiredString(finding, "bodySha256"),
914
+ body: optionalString(finding, "body") ?? "",
915
+ contentAvailable: requiredBoolean(finding, "contentAvailable"),
916
+ actionable: requiredBoolean(finding, "actionable"),
917
+ actionabilityReason: requiredString(finding, "actionabilityReason"),
918
+ author: optionalString(finding, "author"),
919
+ url: optionalString(finding, "url"),
920
+ path: optionalString(finding, "path"),
921
+ line: optionalPositiveInteger(finding, "line")
922
+ };
923
+ });
924
+ }
355
925
  function parseWarmPathOverrides(value) {
356
926
  if (value === undefined || value === null) {
357
927
  return [];
@@ -396,6 +966,7 @@ function parseQaScope(value) {
396
966
  schema_version: requiredNumber(qaScope, "schema_version"),
397
967
  surface: parseOptionalStringArray(qaScope.surface, "qaScope.surface"),
398
968
  required_evidence: parseOptionalStringArray(qaScope.required_evidence, "qaScope.required_evidence"),
969
+ required_capabilities: parseOptionalStringArray(qaScope.required_capabilities ?? qaScope.requiredCapabilities, "qaScope.required_capabilities"),
399
970
  not_applicable: parseOptionalStringArray(qaScope.not_applicable, "qaScope.not_applicable"),
400
971
  browser_required: optionalBoolean(qaScope, "browser_required") ?? optionalBoolean(qaScope, "browserRequired") ?? false,
401
972
  api_required: optionalBoolean(qaScope, "api_required") ?? optionalBoolean(qaScope, "apiRequired") ?? false,
@@ -529,6 +1100,7 @@ function parseStoryQa(value) {
529
1100
  }
530
1101
  const storyQa = asObject(value, "storyQa");
531
1102
  return {
1103
+ references: parseStoryQaReferences(storyQa.references),
532
1104
  storyWorkItemId: requiredString(storyQa, "storyWorkItemId"),
533
1105
  planId: requiredString(storyQa, "planId"),
534
1106
  planContentHash: requiredString(storyQa, "planContentHash"),
@@ -541,6 +1113,26 @@ function parseStoryQa(value) {
541
1113
  dependencies: parseStoryQaDependencies(storyQa.dependencies)
542
1114
  };
543
1115
  }
1116
+ function parseStoryQaReferences(value) {
1117
+ if (value === undefined || value === null)
1118
+ return null;
1119
+ const bundle = asObject(value, "storyQa.references");
1120
+ if (!Array.isArray(bundle.files))
1121
+ throw new Error("storyQa.references.files must be an array.");
1122
+ return {
1123
+ schemaVersion: requiredNumber(bundle, "schemaVersion"),
1124
+ cycleRunId: requiredString(bundle, "cycleRunId"),
1125
+ storyWorkItemId: requiredString(bundle, "storyWorkItemId"),
1126
+ projectId: requiredString(bundle, "projectId"), repoId: requiredString(bundle, "repoId"),
1127
+ planId: requiredString(bundle, "planId"), planContentHash: requiredString(bundle, "planContentHash"),
1128
+ effectiveAmendmentHash: requiredString(bundle, "effectiveAmendmentHash"), capturedAt: requiredString(bundle, "capturedAt"),
1129
+ files: bundle.files.map((entry, index) => {
1130
+ const file = asObject(entry, `storyQa.references.files[${index}]`);
1131
+ return { path: requiredString(file, "path"), body: requiredString(file, "body"),
1132
+ contentHash: requiredString(file, "contentHash"), provenance: requiredString(file, "provenance") };
1133
+ })
1134
+ };
1135
+ }
544
1136
  function parseStoryQaChildTasks(value) {
545
1137
  if (!Array.isArray(value)) {
546
1138
  throw new Error("storyQa.childTasks must be an array.");