@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
@@ -0,0 +1,66 @@
1
+ import { ForgeFailureError } from "../session.types.js";
2
+ import type { ProviderProcessHandlers, ProviderProcessRunner, ProviderProcessRunRequest, ProviderProcessRunResult } from "./provider-cli.process.js";
3
+ /**
4
+ * Removes the `run_in_background` parameter from Bash, PowerShell and the Agent tool, runs
5
+ * forked subagents and forked skills in the foreground, and stops Claude Code from moving long
6
+ * shell commands, subagents and MCP calls to the background on its own. Cron disables the
7
+ * session-scoped scheduled tasks (`CronCreate`, `/loop`). Applied last, so a project's runtime
8
+ * environment cannot turn them back on.
9
+ */
10
+ export declare const claudeHeadlessEnvironment: Readonly<Record<string, string>>;
11
+ /**
12
+ * Tools whose only purpose is work that reports after the turn. `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS`
13
+ * leaves Monitor running in the background, so it is removed here, together with self-paced
14
+ * wakeups, workflows (which run their agents in the background), cloud routines, cron
15
+ * (also disabled by environment), SendMessage, which resumes an earlier subagent in the
16
+ * background, and agent teams, whose teammates run alongside the turn. Foreground subagents
17
+ * stay available: they block the turn until they finish.
18
+ */
19
+ export declare const claudeHeadlessDisallowedTools: readonly string[];
20
+ /**
21
+ * The Claude Code arguments that apply the restrictions: the tool deny list, and the environment
22
+ * again as flag settings, which outrank a user's or repository's settings `env` block.
23
+ */
24
+ export declare function claudeHeadlessToolArgs(): readonly string[];
25
+ /**
26
+ * The provider ended its turn while background work it started (a background subagent or
27
+ * shell, a Monitor watch, a wakeup) was still live. Claude Code withholds the turn's terminal
28
+ * result for such work, and nothing started in the background reports to Forge, so Forge stops
29
+ * the provider at once instead of waiting for an idle watchdog. Retryable: the harness, not the
30
+ * task, ended the run.
31
+ */
32
+ export declare function providerTurnEndedWithBackgroundWorkFailure(message: string): ForgeFailureError;
33
+ /**
34
+ * Fails every provider run Forge stopped because its turn ended with background work still live,
35
+ * whether or not the turn recorded a completion first: the stop cut that work short, so nothing
36
+ * may validate, commit or publish the worktree it left behind.
37
+ */
38
+ export declare class BackgroundWorkStopFailingRunner implements ProviderProcessRunner {
39
+ private readonly inner;
40
+ constructor(inner: ProviderProcessRunner);
41
+ run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
42
+ }
43
+ /**
44
+ * Recognizes a main-conversation turn that ended while background tasks it started were still
45
+ * live, the case in which Claude Code withholds the turn's `result`. The turn end is Claude
46
+ * Code's `post_turn_summary` event; the live set is the documented `background_tasks_changed`
47
+ * event (Claude Code's own `ambient` tasks and `awaited` ones do not count). After `graceMs`
48
+ * without the result or new main-conversation activity, it calls `onTurnEndedWithBackgroundWork`
49
+ * once, so the runner can stop the provider instead of waiting on work no one will collect.
50
+ */
51
+ export declare class ClaudeBackgroundTurnEndWatch {
52
+ private readonly graceMs;
53
+ private readonly onTurnEndedWithBackgroundWork;
54
+ private liveBackgroundTasks;
55
+ private terminalSinceMainActivity;
56
+ private mainTurnEnded;
57
+ private timer;
58
+ private stopped;
59
+ private readonly enabled;
60
+ /** Watches only Claude Code, by its executable `command`; other output is left alone. */
61
+ constructor(command: string, graceMs: number, onTurnEndedWithBackgroundWork: () => void);
62
+ consume(line: string): void;
63
+ stop(): void;
64
+ private armIfTurnEndedWithBackgroundWork;
65
+ private cancel;
66
+ }
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Headless Claude Code runs must not start work that outlives the turn.
3
+ *
4
+ * Forge runs `claude -p` and treats the turn's terminal `result` event as the end of the run.
5
+ * When background work is still live at the end of a turn (a background subagent or shell, a
6
+ * Monitor watch, a scheduled wakeup), Claude Code withholds that `result` and keeps the process
7
+ * open for the work, so Forge sees a silent provider instead of a finished one. The launch
8
+ * restrictions below remove the ways to start such work; `ClaudeBackgroundTurnEndWatch` is the
9
+ * backstop for anything that still gets through.
10
+ */
11
+ import path from "node:path";
12
+ import { ForgeFailureError } from "../session.types.js";
13
+ /**
14
+ * Removes the `run_in_background` parameter from Bash, PowerShell and the Agent tool, runs
15
+ * forked subagents and forked skills in the foreground, and stops Claude Code from moving long
16
+ * shell commands, subagents and MCP calls to the background on its own. Cron disables the
17
+ * session-scoped scheduled tasks (`CronCreate`, `/loop`). Applied last, so a project's runtime
18
+ * environment cannot turn them back on.
19
+ */
20
+ export const claudeHeadlessEnvironment = Object.freeze({
21
+ CLAUDE_CODE_DISABLE_BACKGROUND_TASKS: "1",
22
+ CLAUDE_CODE_DISABLE_CRON: "1",
23
+ });
24
+ /**
25
+ * Tools whose only purpose is work that reports after the turn. `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS`
26
+ * leaves Monitor running in the background, so it is removed here, together with self-paced
27
+ * wakeups, workflows (which run their agents in the background), cloud routines, cron
28
+ * (also disabled by environment), SendMessage, which resumes an earlier subagent in the
29
+ * background, and agent teams, whose teammates run alongside the turn. Foreground subagents
30
+ * stay available: they block the turn until they finish.
31
+ */
32
+ export const claudeHeadlessDisallowedTools = Object.freeze([
33
+ "Monitor",
34
+ "ScheduleWakeup",
35
+ "Workflow",
36
+ "RemoteTrigger",
37
+ "CronCreate",
38
+ "SendMessage",
39
+ "TeamCreate",
40
+ ]);
41
+ /**
42
+ * The Claude Code arguments that apply the restrictions: the tool deny list, and the environment
43
+ * again as flag settings, which outrank a user's or repository's settings `env` block.
44
+ */
45
+ export function claudeHeadlessToolArgs() {
46
+ return [
47
+ "--disallowedTools", claudeHeadlessDisallowedTools.join(","),
48
+ "--settings", JSON.stringify({ env: claudeHeadlessEnvironment }),
49
+ ];
50
+ }
51
+ /**
52
+ * The provider ended its turn while background work it started (a background subagent or
53
+ * shell, a Monitor watch, a wakeup) was still live. Claude Code withholds the turn's terminal
54
+ * result for such work, and nothing started in the background reports to Forge, so Forge stops
55
+ * the provider at once instead of waiting for an idle watchdog. Retryable: the harness, not the
56
+ * task, ended the run.
57
+ */
58
+ export function providerTurnEndedWithBackgroundWorkFailure(message) {
59
+ return new ForgeFailureError("provider_turn_ended_with_background_work", `${message} The provider ended its turn while background work it started was still running, so it never delivered a terminal result; Forge stopped it instead of waiting.`);
60
+ }
61
+ /**
62
+ * Fails every provider run Forge stopped because its turn ended with background work still live,
63
+ * whether or not the turn recorded a completion first: the stop cut that work short, so nothing
64
+ * may validate, commit or publish the worktree it left behind.
65
+ */
66
+ export class BackgroundWorkStopFailingRunner {
67
+ inner;
68
+ constructor(inner) {
69
+ this.inner = inner;
70
+ }
71
+ async run(request, handlers, signal) {
72
+ const result = await this.inner.run(request, handlers, signal);
73
+ if (result.terminalStopReason === "turn_ended_with_background_work") {
74
+ throw providerTurnEndedWithBackgroundWorkFailure("The provider turn did not finish.");
75
+ }
76
+ return result;
77
+ }
78
+ }
79
+ /**
80
+ * Recognizes a main-conversation turn that ended while background tasks it started were still
81
+ * live, the case in which Claude Code withholds the turn's `result`. The turn end is Claude
82
+ * Code's `post_turn_summary` event; the live set is the documented `background_tasks_changed`
83
+ * event (Claude Code's own `ambient` tasks and `awaited` ones do not count). After `graceMs`
84
+ * without the result or new main-conversation activity, it calls `onTurnEndedWithBackgroundWork`
85
+ * once, so the runner can stop the provider instead of waiting on work no one will collect.
86
+ */
87
+ export class ClaudeBackgroundTurnEndWatch {
88
+ graceMs;
89
+ onTurnEndedWithBackgroundWork;
90
+ liveBackgroundTasks = 0;
91
+ terminalSinceMainActivity = false;
92
+ mainTurnEnded = false;
93
+ timer = null;
94
+ stopped = false;
95
+ enabled;
96
+ /** Watches only Claude Code, by its executable `command`; other output is left alone. */
97
+ constructor(command, graceMs, onTurnEndedWithBackgroundWork) {
98
+ this.graceMs = graceMs;
99
+ this.onTurnEndedWithBackgroundWork = onTurnEndedWithBackgroundWork;
100
+ this.enabled = path.parse(command).name.toLowerCase() === "claude";
101
+ }
102
+ consume(line) {
103
+ if (!this.enabled || this.stopped)
104
+ return;
105
+ const event = parseStreamEvent(line);
106
+ if (!event)
107
+ return;
108
+ if (isTerminalEvent(event)) {
109
+ this.terminalSinceMainActivity = true;
110
+ this.cancel();
111
+ }
112
+ else if (event.type === "system" && event.subtype === "background_tasks_changed") {
113
+ this.liveBackgroundTasks = liveBackgroundTaskCount(event.tasks);
114
+ // The work settled: Claude Code now delivers the result or starts a turn for it, and a
115
+ // follow-up turn can think for a while before its first event.
116
+ if (this.liveBackgroundTasks === 0)
117
+ this.cancel();
118
+ // A task can be reported just after the turn summary, as the turn ends.
119
+ else if (this.mainTurnEnded)
120
+ this.armIfTurnEndedWithBackgroundWork();
121
+ }
122
+ else if (event.type === "system" && event.subtype === "post_turn_summary") {
123
+ this.mainTurnEnded = true;
124
+ this.armIfTurnEndedWithBackgroundWork();
125
+ }
126
+ else if ((event.type === "assistant" || event.type === "user") && !event.parent_tool_use_id) {
127
+ // The main conversation is working again (a new turn, or a turn that is still going).
128
+ this.terminalSinceMainActivity = false;
129
+ this.mainTurnEnded = false;
130
+ this.cancel();
131
+ }
132
+ }
133
+ stop() {
134
+ this.stopped = true;
135
+ this.cancel();
136
+ }
137
+ armIfTurnEndedWithBackgroundWork() {
138
+ if (this.timer || this.terminalSinceMainActivity || this.liveBackgroundTasks === 0)
139
+ return;
140
+ this.timer = setTimeout(() => {
141
+ this.timer = null;
142
+ this.stopped = true;
143
+ this.onTurnEndedWithBackgroundWork();
144
+ }, this.graceMs);
145
+ this.timer.unref?.();
146
+ }
147
+ cancel() {
148
+ if (!this.timer)
149
+ return;
150
+ clearTimeout(this.timer);
151
+ this.timer = null;
152
+ }
153
+ }
154
+ function parseStreamEvent(line) {
155
+ const trimmed = line.trim();
156
+ if (!trimmed.startsWith("{"))
157
+ return null;
158
+ try {
159
+ const parsed = JSON.parse(trimmed);
160
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
161
+ }
162
+ catch {
163
+ return null;
164
+ }
165
+ }
166
+ function isTerminalEvent(event) {
167
+ return event.type === "result" || event.type === "error";
168
+ }
169
+ /**
170
+ * Tasks that keep the turn's result back: not Claude Code's own `ambient` tasks, and not
171
+ * `awaited` ones, which a still-running tool call of the turn waits for.
172
+ */
173
+ function liveBackgroundTaskCount(tasks) {
174
+ if (!Array.isArray(tasks))
175
+ return 0;
176
+ return tasks.filter(task => {
177
+ const entry = task && typeof task === "object" ? task : {};
178
+ return entry.ambient !== true && entry.awaited !== true;
179
+ }).length;
180
+ }
@@ -0,0 +1,40 @@
1
+ import { PrePublicationValidationError, type PrePublicationProfile, type PrePublicationValidator } from "../pre-publication-validation.js";
2
+ import type { ProviderProcessRunner } from "./provider-cli.process.js";
3
+ import type { ProviderCliRunContext } from "./provider-cli.types.js";
4
+ import { type ProviderOutputState } from "./provider-output-state.js";
5
+ /**
6
+ * The in-place repair budget: FORGE_PREPUBLICATION_REPAIR_TURNS when it is a whole number from 1
7
+ * (capped at 10), otherwise 4.
8
+ */
9
+ export declare function prePublicationRepairTurnsFromEnvironment(environment?: Readonly<Record<string, string | undefined>>): number;
10
+ export interface PrePublicationRepairOptions {
11
+ readonly context: ProviderCliRunContext;
12
+ readonly validationProfile: PrePublicationProfile;
13
+ readonly repairEnvironment: Readonly<Record<string, string>> | undefined;
14
+ readonly outputState: ProviderOutputState;
15
+ readonly preparedHeadSha: string;
16
+ readonly repairScope: "implementation" | "pull_request";
17
+ /**
18
+ * Derives the repair environment from a refreshed runtime environment. CI repair
19
+ * rewrites its readiness manifest so the attempt URLs it records stay current.
20
+ */
21
+ readonly onRuntimeEnvironmentRefreshed?: (runtimeEnvironment: Readonly<Record<string, string>>) => Promise<Readonly<Record<string, string>>>;
22
+ }
23
+ /** One resumed provider turn that repairs a failed pass in place. */
24
+ export interface PrePublicationRepairTurn {
25
+ readonly prompt: string;
26
+ readonly repairTurn: number;
27
+ readonly maxRepairTurns: number;
28
+ readonly providerThreadId: string;
29
+ readonly repairEnvironment: Readonly<Record<string, string>> | undefined;
30
+ readonly environment: Readonly<Record<string, string>>;
31
+ readonly failure: PrePublicationValidationError;
32
+ }
33
+ export interface PrePublicationRepairDependencies {
34
+ readonly validator: PrePublicationValidator;
35
+ readonly defaultProcessRunner: ProviderProcessRunner;
36
+ readonly maxRepairTurns: number;
37
+ readonly runRepairTurn: (turn: PrePublicationRepairTurn) => Promise<void>;
38
+ }
39
+ export declare function validatePrePublicationWithRepair(options: PrePublicationRepairOptions, dependencies: PrePublicationRepairDependencies): Promise<void>;
40
+ export declare function buildPrePublicationRepairPrompt(error: PrePublicationValidationError, repairTurn: number, maxRepairTurns: number, repairScope: "implementation" | "pull_request"): string;
@@ -0,0 +1,243 @@
1
+ import { HostPortCollisionError } from "../../runtime/host-port-broker.js";
2
+ import { runtimeAdmissionPriority } from "../../runtime/host-runtime-lease.js";
3
+ import { runtimeRestartCheckId } from "../pre-publication-pass.js";
4
+ import { PrePublicationValidationError, } from "../pre-publication-validation.js";
5
+ import { ForgeFailureError } from "../session.types.js";
6
+ import { prePublicationValidationEnv, providerProcessEnv } from "./provider-cli.runtime.js";
7
+ import { clip } from "./provider-output-state.js";
8
+ // Pre-publication validation with bounded in-place repair: each pass restarts the attempt's runtime
9
+ // stack when the workspace changed, runs every check that can still meaningfully run, and hands all
10
+ // of the pass's failures to one resumed provider turn, up to the repair budget.
11
+ const defaultRepairTurns = 4;
12
+ const maximumRepairTurns = 10;
13
+ const repairTurnsEnvironment = "FORGE_PREPUBLICATION_REPAIR_TURNS";
14
+ // The repair prompt's diagnostics: each failed check gets an equal share of the total, between the
15
+ // floor and the ceiling (validation already clips each check's own output to the ceiling). The
16
+ // total keeps a prompt passed as a command-line argument within Windows' 32,767-character limit.
17
+ const repairPromptDetailBudget = 18_000;
18
+ const repairPromptDetailCeiling = 6000;
19
+ const repairPromptDetailFloor = 1500;
20
+ /**
21
+ * The in-place repair budget: FORGE_PREPUBLICATION_REPAIR_TURNS when it is a whole number from 1
22
+ * (capped at 10), otherwise 4.
23
+ */
24
+ export function prePublicationRepairTurnsFromEnvironment(environment = process.env) {
25
+ const configured = environment[repairTurnsEnvironment]?.trim() ?? "";
26
+ return /^\d+$/u.test(configured) && Number(configured) >= 1
27
+ ? Math.min(Number(configured), maximumRepairTurns)
28
+ : defaultRepairTurns;
29
+ }
30
+ /** The environments a pass and its repair turn use; a runtime restart assigns new ports, so all move together. */
31
+ class RepairEnvironments {
32
+ options;
33
+ repair;
34
+ constructor(options) {
35
+ this.options = options;
36
+ this.repair = options.repairEnvironment;
37
+ }
38
+ get provider() {
39
+ return providerProcessEnv(this.options.context.dispatch, this.repair);
40
+ }
41
+ get validation() {
42
+ return prePublicationValidationEnv(this.options.context.dispatch, this.repair);
43
+ }
44
+ async refresh(runtimeEnvironment) {
45
+ this.repair = this.options.onRuntimeEnvironmentRefreshed
46
+ ? await this.options.onRuntimeEnvironmentRefreshed(runtimeEnvironment)
47
+ : runtimeEnvironment;
48
+ }
49
+ /**
50
+ * The restart stopped the stack and released its ports before it failed, so the URLs the pass and
51
+ * repair turn would inherit name ports another attempt may now hold. Both run without them; the
52
+ * next pass restarts the stack and supplies fresh ones.
53
+ */
54
+ async withdrawRuntimeStack() {
55
+ await this.refresh(withoutRuntimeStack(this.repair, this.options.context.runtimeStackEnvironmentKeys ?? []));
56
+ }
57
+ }
58
+ export async function validatePrePublicationWithRepair(options, dependencies) {
59
+ const { context, outputState } = options;
60
+ const { maxRepairTurns } = dependencies;
61
+ const environments = new RepairEnvironments(options);
62
+ for (let repairTurn = 0;; repairTurn += 1) {
63
+ const failure = await runValidationPass(options, dependencies, environments, repairTurn);
64
+ if (!failure) {
65
+ if (repairTurn > 0) {
66
+ await context.emit(repairEvent("checkpoint", "prepublication_repair_completed", `Pre-publication validation passed after ${repairTurn} in-place repair turn${repairTurn === 1 ? "" : "s"}.`, { repairTurn, maxRepairTurns }));
67
+ }
68
+ return;
69
+ }
70
+ if (repairTurn >= maxRepairTurns) {
71
+ await context.emit(repairEvent("error", "prepublication_repair_exhausted", `Pre-publication validation still fails after ${maxRepairTurns} in-place repair turns: ${clip(failure.message, 4000)}`, { checkId: failure.checkId, checkIds: failure.checkIds, repairTurns: repairTurn, maxRepairTurns }));
72
+ throw failure;
73
+ }
74
+ const providerThreadId = outputState.providerThreadId?.trim();
75
+ if (!providerThreadId) {
76
+ throw new Error(`prepublication_repair_unavailable: ${failure.message}; provider did not report a resumable thread id, so Forge preserved the dirty worktree without starting a blind replacement run.`, { cause: failure });
77
+ }
78
+ const nextRepairTurn = repairTurn + 1;
79
+ await context.emit(repairEvent("checkpoint", "prepublication_repair_started", `Resuming ${context.dispatch.execution.provider} ${outputState.sessionLabel ?? "provider thread"} for bounded pre-publication repair ${nextRepairTurn}/${maxRepairTurns} after ${describeFailedChecks(failure.checkIds)} failed.`, { checkId: failure.checkId, checkIds: failure.checkIds, repairTurn: nextRepairTurn, maxRepairTurns }));
80
+ await dependencies.runRepairTurn({
81
+ prompt: buildPrePublicationRepairPrompt(failure, nextRepairTurn, maxRepairTurns, options.repairScope),
82
+ repairTurn: nextRepairTurn,
83
+ maxRepairTurns,
84
+ providerThreadId,
85
+ repairEnvironment: environments.repair,
86
+ environment: environments.provider,
87
+ failure,
88
+ });
89
+ }
90
+ }
91
+ /** Restarts the runtime stack if needed, then validates; returns every failure of the pass, or null. */
92
+ async function runValidationPass(options, dependencies, environments, repairTurn) {
93
+ const { context, validationProfile, preparedHeadSha } = options;
94
+ let runtimeRestartFailure;
95
+ try {
96
+ const refreshed = await refreshPrePublicationRuntime(context, validationProfile, repairTurn);
97
+ if (refreshed)
98
+ await environments.refresh(refreshed);
99
+ }
100
+ catch (error) {
101
+ if (!(error instanceof PrePublicationValidationError))
102
+ throw error;
103
+ // The pass still runs the checks that do not need the stack, so the repair turn sees them too.
104
+ runtimeRestartFailure = error;
105
+ await environments.withdrawRuntimeStack();
106
+ }
107
+ try {
108
+ await dependencies.validator.validate(context.worktree.worktreePath, validationProfile, publicationCapabilities(context, environments.repair), context.emit, context.signal, {
109
+ ...prePublicationExecution(context, environments.validation, dependencies.defaultProcessRunner, preparedHeadSha),
110
+ runtimeRestartFailure,
111
+ });
112
+ // The validator reports the restart failure with its own; the restart failed either way.
113
+ return runtimeRestartFailure ?? null;
114
+ }
115
+ catch (error) {
116
+ if (!(error instanceof PrePublicationValidationError))
117
+ throw error;
118
+ return runtimeRestartFailure && !error.checkIds.includes(runtimeRestartCheckId)
119
+ ? new PrePublicationValidationError(runtimeRestartFailure.checkId, runtimeRestartFailure.exitCode, runtimeRestartFailure.command, runtimeRestartFailure.args, runtimeRestartFailure.detail, error.failures)
120
+ : error;
121
+ }
122
+ }
123
+ function describeFailedChecks(checkIds) {
124
+ const quoted = checkIds.map(checkId => `'${checkId}'`);
125
+ return quoted.length <= 1
126
+ ? quoted.join("")
127
+ : `${quoted.slice(0, -1).join(", ")} and ${quoted.at(-1)}`;
128
+ }
129
+ function repairEvent(kind, eventType, content, data) {
130
+ return { role: "runner", kind, content, eventType, data: JSON.stringify(data) };
131
+ }
132
+ export function buildPrePublicationRepairPrompt(error, repairTurn, maxRepairTurns, repairScope) {
133
+ const { failures } = error;
134
+ const several = failures.length > 1;
135
+ const detailLimit = Math.min(repairPromptDetailCeiling, Math.max(repairPromptDetailFloor, Math.floor(repairPromptDetailBudget / failures.length)));
136
+ const priorWork = repairScope === "implementation"
137
+ ? "Keep the completed implementation and its Forge-owned completion artifacts intact."
138
+ : "Keep the existing PR-comment or CI repairs intact.";
139
+ const sections = failures.map((failure, index) => [
140
+ several ? `Failed check ${index + 1}/${failures.length}: ${failure.checkId}` : `Failed check: ${failure.checkId}`,
141
+ `Command: ${[failure.command, ...failure.args].join(" ")}`,
142
+ `Exit code: ${failure.exitCode}`,
143
+ "Diagnostics:",
144
+ clip(failure.detail, detailLimit) || "The validation command returned no diagnostic output.",
145
+ ].join("\n\n"));
146
+ return [
147
+ `Forge pre-publication validation failed after your ${repairScope === "implementation" ? "implementation" : "PR repair"} turn.`,
148
+ `This is bounded in-place repair turn ${repairTurn}/${maxRepairTurns}.`,
149
+ ...(several
150
+ ? [`${failures.length} checks failed in the same validation pass: ${error.checkIds.join(", ")}. Fix every one of them in this turn.`]
151
+ : []),
152
+ ...sections,
153
+ several
154
+ ? "Fix the root cause of each failed check in the current worktree and run each focused failing check."
155
+ : "Fix the root cause in the current worktree and run the focused failing check.",
156
+ `${priorWork} Do not commit, push, rebase, or modify Forge-owned protocol artifacts.`,
157
+ `When the focused check${several ? "s pass" : " passes"}, stop; Bridge will rerun the complete required pre-publication profile and owns commit/push.`,
158
+ ].join("\n\n");
159
+ }
160
+ /**
161
+ * Restarts the attempt's runtime stack when the workspace changed since it was
162
+ * launched, before a validation pass runs against it. A build of the changed
163
+ * source that fails is a validation failure the bounded repair turn can fix.
164
+ */
165
+ async function refreshPrePublicationRuntime(context, validationProfile, repairTurn) {
166
+ if (!context.refreshRuntimeEnvironment)
167
+ return null;
168
+ let refreshed;
169
+ try {
170
+ refreshed = await context.refreshRuntimeEnvironment(context.signal);
171
+ }
172
+ catch (error) {
173
+ // A restart that fails to build, start or become ready reflects the changed source, which a
174
+ // bounded repair turn can fix; the next pass restarts again. Cancellation, a released lease
175
+ // and a changed runtime contract still end the attempt.
176
+ if (restartFailureForRepair(error)) {
177
+ throw new PrePublicationValidationError(runtimeRestartCheckId, 1, "forge-host-runtime-restart", [],
178
+ // The session's host_runtime_restart_started event records why it restarted.
179
+ `Forge restarted the attempt runtime stack before validation, and the restart failed: ${error.message}`);
180
+ }
181
+ throw error;
182
+ }
183
+ if (!refreshed)
184
+ return null;
185
+ const { environment: restarted, reason, changes } = refreshed;
186
+ const apiUrl = restarted.FORGE_E2E_API_URL ?? restarted.FORGE_API_URL ?? null;
187
+ const webUrl = restarted.FORGE_E2E_WEB_URL ?? restarted.FORGE_WEB_URL ?? restarted.FORGE_PLAYWRIGHT_BASE_URL ?? null;
188
+ await context.emit(repairEvent("checkpoint", "prepublication_runtime_restarted", `Restarted the attempt runtime stack before pre-publication validation because ${restartReasonText[reason]}; validation${repairTurn > 0 ? " and repair turns" : ""} now use${apiUrl ? ` API ${apiUrl}` : " the refreshed runtime URLs"}${webUrl ? ` and web ${webUrl}` : ""}.`, { reason, changes, validationProfile, repairTurn, apiUrl, webUrl }));
189
+ return restarted;
190
+ }
191
+ const restartReasonText = {
192
+ previous_restart_incomplete: "the previous restart did not complete",
193
+ fingerprint_unavailable: "the workspace state could not be compared with the stack's",
194
+ workspace_changed: "the workspace changed since it was launched",
195
+ };
196
+ /** The environment with the runtime stack's URLs and ports withheld and the stack marked unavailable. */
197
+ function withoutRuntimeStack(environment, stackKeys) {
198
+ const remaining = { ...(environment ?? {}) };
199
+ for (const key of stackKeys)
200
+ delete remaining[key];
201
+ remaining.FORGE_RUNTIME_STACK = "unavailable";
202
+ return remaining;
203
+ }
204
+ const restartFailuresForRepair = new Set([
205
+ "host_runtime_project_start_failed",
206
+ "host_runtime_process_exited",
207
+ "host_runtime_listener_timeout",
208
+ "host_runtime_http_readiness_timeout",
209
+ "host_port_collision",
210
+ ]);
211
+ function restartFailureForRepair(error) {
212
+ if (error instanceof ForgeFailureError)
213
+ return restartFailuresForRepair.has(error.failureCode);
214
+ // The port broker throws an untyped collision once its launch retries are exhausted.
215
+ return error instanceof HostPortCollisionError;
216
+ }
217
+ function publicationCapabilities(context, runtimeEnvironment) {
218
+ const capabilities = new Set();
219
+ const launchTarget = context.dispatch.qaBrowser?.launchTarget;
220
+ if (runtimeEnvironment?.FORGE_PLAYWRIGHT_CONFIG
221
+ || launchTarget?.url
222
+ || launchTarget?.command
223
+ || launchTarget?.managed_runtime_port) {
224
+ capabilities.add("browser_launch");
225
+ }
226
+ return capabilities;
227
+ }
228
+ function prePublicationExecution(context, environment, defaultRunner, baselineRevision) {
229
+ const hostLoadOwner = {
230
+ dispatchAttemptId: context.dispatch.sandbox?.dispatchAttemptId ?? null,
231
+ priority: runtimeAdmissionPriority(context.dispatch),
232
+ };
233
+ if (context.processRunner)
234
+ return { baselineRevision, environment, processRunner: context.processRunner, hostLoadOwner };
235
+ if (context.dispatch.sandbox?.executionMode !== "docker")
236
+ return { baselineRevision, environment, hostLoadOwner };
237
+ const expectedSandboxId = context.dispatch.sandbox.dispatchAttemptId;
238
+ const observedSandboxId = context.runtimeEnvironment?.FORGE_SANDBOX_ID ?? process.env.FORGE_SANDBOX_ID;
239
+ if (observedSandboxId !== expectedSandboxId) {
240
+ throw new ForgeFailureError("prepublication_execution_scope_invalid", `prepublication_execution_scope_invalid: Docker attempt ${expectedSandboxId} has no runner proven to execute inside that sandbox.`, "bridge");
241
+ }
242
+ return { baselineRevision, environment, processRunner: defaultRunner, hostLoadOwner };
243
+ }
@@ -1,7 +1,8 @@
1
1
  import { GitClient } from "../../shared/git/git.js";
2
2
  import { type CompletionPhase, type CompletionToolRuntime, type DebugCompletionPhase, type QaCompletionGate } from "../phase-completion.js";
3
- import type { RunOnceDispatchPacket, RunnerDispatchArtifact } from "../session.types.js";
3
+ import type { RunOnceDispatchPacket, RunnerDispatchArtifact, RunnerDispatchSidecar } from "../session.types.js";
4
4
  import type { ProviderCliRunContext } from "./provider-cli.types.js";
5
+ import { type ProviderProcessRunResult } from "./provider-cli.process.js";
5
6
  export declare function emitDraftGateArtifacts(emit: ProviderCliRunContext["emit"], worktreePath: string, workItemId: string): Promise<void>;
6
7
  export declare function emitDecomposeGateArtifacts(emit: ProviderCliRunContext["emit"], worktreePath: string, workItemId: string): Promise<void>;
7
8
  export declare function fileExists(filePath: string): Promise<boolean>;
@@ -9,10 +10,11 @@ export declare function summarizeStderr(stderr: string): string;
9
10
  export declare function waitForCompletionArtifact(worktreePath: string, workItemId: string, phase: "draft" | "decompose", signal?: AbortSignal): Promise<RunnerDispatchArtifact>;
10
11
  export declare function delay(ms: number, signal?: AbortSignal): Promise<void>;
11
12
  export declare function cleanupCompletionTools(completionTools: CompletionToolRuntime, emit: ProviderCliRunContext["emit"]): Promise<void>;
12
- export declare function commitWorktreeChanges(git: GitClient, worktreePath: string, workItemId: string): Promise<{
13
+ export declare function commitWorktreeChanges(git: GitClient, worktreePath: string, workItemId: string, alreadyStagedChangedFiles?: readonly string[]): Promise<{
13
14
  readonly commitSha: string;
14
15
  readonly changedFiles: readonly string[];
15
16
  }>;
17
+ export declare function stagePublishableWorktreeChanges(git: GitClient, worktreePath: string): Promise<readonly string[]>;
16
18
  export declare function phaseCompleteEventType(phase: CompletionPhase): string;
17
19
  export declare function isDebugCompletionPhaseForProvider(phase: CompletionPhase): phase is DebugCompletionPhase;
18
20
  export declare function emitQaArtifactRecorded(emit: ProviderCliRunContext["emit"], worktreePath: string, artifact: RunnerDispatchArtifact): Promise<void>;
@@ -20,6 +22,7 @@ export declare function readQaCompletionArtifactBundle(worktreePath: string, wor
20
22
  export declare function hasCompleteQaArtifactBundle(worktreePath: string, workItemId: string, ownerType?: string | null, ownerId?: string | null): Promise<boolean>;
21
23
  export declare function enforceQaBrowserLaunchTargetGate(dispatch: RunOnceDispatchPacket, artifact: RunnerDispatchArtifact): Promise<void>;
22
24
  export declare function validateQaBundleSidecarReferences(worktreePath: string, workItemId: string, ownerType?: string | null, ownerId?: string | null): Promise<void>;
25
+ export declare function readQaBundleSidecars(worktreePath: string, workItemId: string, ownerType?: string | null, ownerId?: string | null): Promise<RunnerDispatchSidecar[]>;
23
26
  export declare function emitQaStructuredEvents(emit: ProviderCliRunContext["emit"], artifact: RunnerDispatchArtifact): Promise<void>;
24
27
  interface QaGateArtifactSnapshot {
25
28
  readonly gate: QaCompletionGate;
@@ -89,5 +92,5 @@ export declare class LiveCompletionArtifactEmitter {
89
92
  private pollQueued;
90
93
  private poll;
91
94
  }
92
- export declare function readCompletionArtifactsForRun(worktreePath: string, workItemId: string, phase: CompletionPhase, developCycle: boolean, debugCycle: boolean): Promise<RunnerDispatchArtifact[]>;
95
+ export declare function readCompletionArtifactsForRun(worktreePath: string, workItemId: string, phase: CompletionPhase, developCycle: boolean, debugCycle: boolean, providerResult?: Pick<ProviderProcessRunResult, "terminalStopReason"> | null): Promise<RunnerDispatchArtifact[]>;
93
96
  export {};