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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/README.md +128 -4
  2. package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
  3. package/dist/bridge/bridge-chat-giphy-look.js +55 -0
  4. package/dist/bridge/bridge-chat-provider-command.d.ts +27 -3
  5. package/dist/bridge/bridge-chat-provider-command.js +131 -26
  6. package/dist/bridge/bridge-chat.types.d.ts +20 -0
  7. package/dist/bridge/bridge-chat.types.js +28 -1
  8. package/dist/bridge/bridge-state-file.d.ts +161 -0
  9. package/dist/bridge/bridge-state-file.js +376 -0
  10. package/dist/bridge/bridge-state-io.d.ts +15 -0
  11. package/dist/bridge/bridge-state-io.js +68 -0
  12. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  13. package/dist/bridge/bridge-state-lock.js +102 -0
  14. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  15. package/dist/bridge/bridge-state-unpublished.js +111 -0
  16. package/dist/bridge/bridge.service.d.ts +29 -12
  17. package/dist/bridge/bridge.service.js +215 -380
  18. package/dist/bridge/bridge.types.d.ts +21 -0
  19. package/dist/bridge/bridge.types.js +2 -1
  20. package/dist/bridge/default-session-service.d.ts +13 -0
  21. package/dist/bridge/default-session-service.js +22 -0
  22. package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
  23. package/dist/bridge/dispatch-offer-policy.js +58 -0
  24. package/dist/bridge/in-flight-registry.d.ts +62 -0
  25. package/dist/bridge/in-flight-registry.js +207 -0
  26. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  27. package/dist/bridge/readiness-result-outbox.js +20 -0
  28. package/dist/bridge/runner-host-capabilities.js +14 -1
  29. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  30. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  31. package/dist/bridge/windows-bash-resolution.d.ts +31 -0
  32. package/dist/bridge/windows-bash-resolution.js +153 -0
  33. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  34. package/dist/cleanup/cleanup-wip.js +66 -0
  35. package/dist/cleanup/cleanup.service.d.ts +11 -1
  36. package/dist/cleanup/cleanup.service.js +80 -62
  37. package/dist/cleanup/cleanup.types.d.ts +2 -0
  38. package/dist/cleanup/forge-owned-paths.d.ts +2 -0
  39. package/dist/cleanup/forge-owned-paths.js +9 -0
  40. package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
  41. package/dist/cleanup/host-runtime-ledger.js +30 -9
  42. package/dist/cli/cli.help.js +57 -13
  43. package/dist/cli/cli.service.d.ts +3 -10
  44. package/dist/cli/cli.service.js +20 -213
  45. package/dist/cli/idle-status.d.ts +84 -0
  46. package/dist/cli/idle-status.js +181 -0
  47. package/dist/cli/local-config.d.ts +14 -1
  48. package/dist/cli/local-config.js +42 -2
  49. package/dist/cli/provider-cli-advertising.d.ts +24 -0
  50. package/dist/cli/provider-cli-advertising.js +88 -0
  51. package/dist/cli/provider-cli-detection.d.ts +10 -0
  52. package/dist/cli/provider-cli-detection.js +160 -0
  53. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  54. package/dist/runtime/aspnet-runtime-prebuild.js +104 -26
  55. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  56. package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
  57. package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
  58. package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
  59. package/dist/runtime/attempt-process-supervisor.js +12 -6
  60. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  61. package/dist/runtime/docker-engine-probe.js +7 -0
  62. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  63. package/dist/runtime/dotnet-build-outputs.js +402 -0
  64. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  65. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  66. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  67. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  68. package/dist/runtime/host-listener-inspector.d.ts +26 -0
  69. package/dist/runtime/host-listener-inspector.js +84 -3
  70. package/dist/runtime/host-load-admission.d.ts +5 -0
  71. package/dist/runtime/host-load-capacity.d.ts +198 -0
  72. package/dist/runtime/host-load-capacity.js +353 -0
  73. package/dist/runtime/host-load-child-environment.d.ts +13 -0
  74. package/dist/runtime/host-load-child-environment.js +35 -1
  75. package/dist/runtime/host-load-governor-config.d.ts +33 -3
  76. package/dist/runtime/host-load-governor-config.js +24 -3
  77. package/dist/runtime/host-load-governor.d.ts +91 -2
  78. package/dist/runtime/host-load-governor.js +217 -18
  79. package/dist/runtime/host-load-ledger-lock.js +6 -4
  80. package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
  81. package/dist/runtime/host-load-live-test-slots.js +193 -0
  82. package/dist/runtime/host-load-runtime-settings.js +4 -2
  83. package/dist/runtime/host-load-sampler.d.ts +25 -1
  84. package/dist/runtime/host-load-sampler.js +38 -7
  85. package/dist/runtime/host-load-step-run.d.ts +37 -3
  86. package/dist/runtime/host-load-step-run.js +63 -7
  87. package/dist/runtime/host-load-test-slot.d.ts +3 -0
  88. package/dist/runtime/host-load-test-slot.js +26 -7
  89. package/dist/runtime/host-runtime-contract.d.ts +12 -0
  90. package/dist/runtime/host-runtime-contract.js +35 -5
  91. package/dist/runtime/host-runtime-lease.d.ts +28 -3
  92. package/dist/runtime/host-runtime-lease.js +140 -296
  93. package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
  94. package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
  95. package/dist/runtime/host-runtime-promotion.d.ts +78 -2
  96. package/dist/runtime/host-runtime-promotion.js +307 -14
  97. package/dist/runtime/managed-command-teardown.js +5 -16
  98. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  99. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  100. package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
  101. package/dist/runtime/prepared-runtime-identity.js +130 -9
  102. package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
  103. package/dist/runtime/prepared-runtime-readiness.js +89 -18
  104. package/dist/runtime/runner-settings.d.ts +4 -0
  105. package/dist/runtime/runner-settings.js +22 -0
  106. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  107. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  108. package/dist/sandbox/host-capacity-broker.d.ts +3 -1
  109. package/dist/sandbox/host-capacity-broker.js +4 -2
  110. package/dist/sandbox/managed-branch.d.ts +13 -0
  111. package/dist/sandbox/managed-branch.js +90 -0
  112. package/dist/sandbox/provider-auth/codex.js +11 -11
  113. package/dist/sandbox/runtime.d.ts +1 -2
  114. package/dist/sandbox/runtime.js +9 -19
  115. package/dist/sandbox/sandbox-input.d.ts +22 -0
  116. package/dist/sandbox/sandbox-input.js +49 -0
  117. package/dist/sandbox/workspace.service.js +15 -2
  118. package/dist/session/managed-attempt-tools.d.ts +0 -7
  119. package/dist/session/managed-attempt-tools.js +54 -109
  120. package/dist/session/managed-build-coordinator.d.ts +16 -0
  121. package/dist/session/managed-build-coordinator.js +10 -0
  122. package/dist/session/managed-build-receipt.d.ts +7 -0
  123. package/dist/session/managed-build-receipt.js +11 -3
  124. package/dist/session/managed-command-environment.d.ts +8 -0
  125. package/dist/session/managed-command-environment.js +28 -0
  126. package/dist/session/managed-command-host-load.d.ts +10 -5
  127. package/dist/session/managed-command-host-load.js +18 -14
  128. package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
  129. package/dist/session/phase-completion.artifact-bundle.js +167 -0
  130. package/dist/session/phase-completion.artifacts.d.ts +2 -17
  131. package/dist/session/phase-completion.artifacts.js +65 -166
  132. package/dist/session/phase-completion.d.ts +27 -2
  133. package/dist/session/phase-completion.helpers.js +5 -53
  134. package/dist/session/phase-completion.js +15 -32
  135. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  136. package/dist/session/phase-completion.mcp-args.js +195 -0
  137. package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
  138. package/dist/session/phase-completion.phase-aliases.js +43 -0
  139. package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
  140. package/dist/session/phase-completion.pr-review-schema.js +75 -0
  141. package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
  142. package/dist/session/phase-completion.pr-review-validation.js +212 -0
  143. package/dist/session/phase-completion.pr-review.d.ts +36 -0
  144. package/dist/session/phase-completion.pr-review.js +294 -0
  145. package/dist/session/phase-completion.prompts.d.ts +1 -1
  146. package/dist/session/phase-completion.prompts.js +14 -0
  147. package/dist/session/phase-completion.runtime.d.ts +8 -9
  148. package/dist/session/phase-completion.runtime.js +65 -196
  149. package/dist/session/phase-completion.schemas.js +12 -2
  150. package/dist/session/phase-completion.validation.d.ts +1 -0
  151. package/dist/session/phase-completion.validation.js +9 -1
  152. package/dist/session/pr-review-diff-base.d.ts +18 -0
  153. package/dist/session/pr-review-diff-base.js +44 -0
  154. package/dist/session/pr-review-placement.d.ts +50 -0
  155. package/dist/session/pr-review-placement.js +91 -0
  156. package/dist/session/pre-publication-change-set.d.ts +62 -0
  157. package/dist/session/pre-publication-change-set.js +166 -0
  158. package/dist/session/pre-publication-host-load.js +6 -5
  159. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  160. package/dist/session/pre-publication-native-postgres.js +111 -0
  161. package/dist/session/pre-publication-process.js +13 -12
  162. package/dist/session/pre-publication-step-execution.d.ts +2 -1
  163. package/dist/session/pre-publication-step-execution.js +6 -5
  164. package/dist/session/pre-publication-validation.d.ts +9 -4
  165. package/dist/session/pre-publication-validation.js +62 -65
  166. package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
  167. package/dist/session/provider-cli/claude-background-work.js +4 -3
  168. package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
  169. package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
  170. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  171. package/dist/session/provider-cli/host-build-lock.js +30 -0
  172. package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
  173. package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
  174. package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
  175. package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
  176. package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
  177. package/dist/session/provider-cli/pr-review-prompt.js +119 -0
  178. package/dist/session/provider-cli/pre-publication-repair.d.ts +16 -0
  179. package/dist/session/provider-cli/pre-publication-repair.js +41 -3
  180. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  181. package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
  182. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
  183. package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
  184. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
  185. package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
  186. package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
  187. package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
  188. package/dist/session/provider-cli/provider-cli.process.d.ts +2 -14
  189. package/dist/session/provider-cli/provider-cli.process.js +4 -94
  190. package/dist/session/provider-cli/provider-cli.prompts.d.ts +13 -3
  191. package/dist/session/provider-cli/provider-cli.prompts.js +137 -84
  192. package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
  193. package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
  194. package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
  195. package/dist/session/provider-cli/provider-cli.runtime.js +37 -2
  196. package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
  197. package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
  198. package/dist/session/provider-cli/provider-cli.service.d.ts +15 -18
  199. package/dist/session/provider-cli/provider-cli.service.js +59 -190
  200. package/dist/session/provider-cli/provider-cli.types.d.ts +7 -2
  201. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  202. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  203. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  204. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  205. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  206. package/dist/session/qa-sidecar-validation.js +28 -0
  207. package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
  208. package/dist/session/sandbox-host-capacity-gate.js +63 -22
  209. package/dist/session/session-host-project.d.ts +22 -0
  210. package/dist/session/session-host-project.js +98 -0
  211. package/dist/session/session-redaction.js +31 -181
  212. package/dist/session/session.parse-helpers.d.ts +10 -0
  213. package/dist/session/session.parse-helpers.js +84 -0
  214. package/dist/session/session.runtime-refresh.d.ts +46 -0
  215. package/dist/session/session.runtime-refresh.js +116 -0
  216. package/dist/session/session.service.d.ts +8 -1
  217. package/dist/session/session.service.js +177 -239
  218. package/dist/session/session.types.d.ts +5 -0
  219. package/dist/session/session.types.js +9 -79
  220. package/dist/session/session.types.pr-review.d.ts +48 -0
  221. package/dist/session/session.types.pr-review.js +51 -0
  222. package/dist/session/sidecar-json-shape.d.ts +31 -0
  223. package/dist/session/sidecar-json-shape.js +217 -0
  224. package/dist/shared/fs/file-identity.d.ts +10 -0
  225. package/dist/shared/fs/file-identity.js +15 -0
  226. package/dist/shared/fs/replace-file.d.ts +7 -0
  227. package/dist/shared/fs/replace-file.js +33 -0
  228. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  229. package/dist/shared/process/host-process-recovery.js +23 -3
  230. package/dist/shared/process/host-process-supervisor.d.ts +13 -1
  231. package/dist/shared/process/host-process-supervisor.js +66 -14
  232. package/dist/shared/provider-capabilities.d.ts +2 -0
  233. package/dist/shared/provider-capabilities.js +18 -1
  234. package/dist/version.d.ts +1 -1
  235. package/dist/version.js +1 -1
  236. package/dist/worktree/artifact-injector.js +24 -0
  237. package/dist/worktree/orphan-relink.d.ts +19 -0
  238. package/dist/worktree/orphan-relink.js +106 -0
  239. package/dist/worktree/wip-git.d.ts +58 -0
  240. package/dist/worktree/wip-git.js +182 -0
  241. package/dist/worktree/wip-refs.d.ts +85 -0
  242. package/dist/worktree/wip-refs.js +169 -0
  243. package/dist/worktree/wip-restore.d.ts +51 -0
  244. package/dist/worktree/wip-restore.js +324 -0
  245. package/dist/worktree/wip-snapshot.d.ts +53 -0
  246. package/dist/worktree/wip-snapshot.js +270 -0
  247. package/dist/worktree/worktree-inputs.d.ts +8 -0
  248. package/dist/worktree/worktree-inputs.js +134 -0
  249. package/dist/worktree/worktree-origin-sync.d.ts +35 -0
  250. package/dist/worktree/worktree-origin-sync.js +128 -0
  251. package/dist/worktree/worktree-wip-events.d.ts +20 -0
  252. package/dist/worktree/worktree-wip-events.js +148 -0
  253. package/dist/worktree/worktree-wip.d.ts +57 -0
  254. package/dist/worktree/worktree-wip.js +200 -0
  255. package/dist/worktree/worktree.base.d.ts +7 -1
  256. package/dist/worktree/worktree.service.d.ts +49 -5
  257. package/dist/worktree/worktree.service.js +223 -187
  258. package/dist/worktree/worktree.types.d.ts +47 -0
  259. package/package.json +1 -1
  260. package/runtime/windows-listener-owner.ps1 +12 -1
@@ -4,6 +4,7 @@ export interface ProviderCliService {
4
4
  runArchitect(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
5
5
  runCiRepair(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
6
6
  runConflictResolve(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
7
+ runPrReview(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
7
8
  runQa(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
8
9
  runDraft(context: ProviderCliDraftContext): Promise<ProviderCliRunResult>;
9
10
  }
@@ -2,6 +2,9 @@ import os from "node:os";
2
2
  import { normalizeWindowsProviderEnvironment, windowsAllowedProviderParentEnvNames } from "./provider-cli.windows-environment.js";
3
3
  // The environment a provider child process starts with: an allowlist of the Bridge's own
4
4
  // variables, the request's values, the Windows defaults, then the .NET build-server settings.
5
+ // CLAUDE_CONFIG_DIR is not passed: it would point Claude Code at a user configuration directory
6
+ // of the host's choosing (provider-user-config-isolation.ts). Claude signs in from the provider
7
+ // home's default `.claude` directory under HOME or USERPROFILE, or with a Forge-granted API key.
5
8
  const allowedProviderParentEnvNames = [
6
9
  "PATH",
7
10
  "HOME",
@@ -9,8 +12,7 @@ const allowedProviderParentEnvNames = [
9
12
  "TMPDIR",
10
13
  "TEMP",
11
14
  "TMP",
12
- "LANG",
13
- "CLAUDE_CONFIG_DIR"
15
+ "LANG"
14
16
  ];
15
17
  export function buildProviderChildEnvironment(requestEnv, options = {}) {
16
18
  const parentEnv = options.parentEnv ?? process.env;
@@ -10,5 +10,6 @@ export declare class DeterministicProviderCliService implements ProviderCliServi
10
10
  runQa(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
11
11
  runCiRepair(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
12
12
  runConflictResolve(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
13
+ runPrReview(_context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
13
14
  private runPullRequestRepair;
14
15
  }
@@ -3,6 +3,7 @@ import path from "node:path";
3
3
  import { GitClient } from "../../shared/git/git.js";
4
4
  import { buildSpecBody, selectLaneCommand } from "../../worktree/artifact-injector.js";
5
5
  import { completionPhaseFromDispatch, debugCompletionPhaseOrder, expectedCompletionToolName, expectedDebugCompletionToolName, expectedQaCompletionToolName, qaCompletionGateOrder, readCompletionArtifact, usesDebugCycleCompletion, usesDevelopCycleCompletion, writeCompletionArtifact } from "../phase-completion.js";
6
+ import { ForgeFailureError } from "../session.types.js";
6
7
  import { commitWorktreeChanges, emitArchitectStructuredEvents, emitCompletionArtifactRecorded, emitQaArtifactRecorded, emitQaGateAccepted, emitQaStructuredEvents, isDebugCompletionPhaseForProvider, nextQaGate, phaseCompleteEventType, qaArtifactRootForDispatch, readQaCompletionArtifactBundle, readQaGateArtifact } from "./provider-cli.artifacts.js";
7
8
  import { deterministicBrowserCheck, deterministicBrowserSidecar, hasLaunchTarget, writeQaSidecarFiles } from "./provider-cli.qa-sidecars.js";
8
9
  import { buildProviderCliCommand, formatProviderCliCommand, isPullRequestCheckRepairDispatch, isPullRequestCommentsDispatch, singleLine } from "./provider-cli.prompts.js";
@@ -210,6 +211,10 @@ export class DeterministicProviderCliService {
210
211
  async runConflictResolve(context) {
211
212
  return await this.runPullRequestRepair(context, "conflict_resolve");
212
213
  }
214
+ async runPrReview(_context) {
215
+ // The review lane never falls back to the deterministic implementation worker.
216
+ throw new ForgeFailureError("pr_review_unsupported_worker", "pr_review_unsupported_worker: the deterministic fake worker cannot perform a pull request review.", "bridge");
217
+ }
213
218
  async runPullRequestRepair(context, route) {
214
219
  const { dispatch, worktree } = context;
215
220
  await assertRepairHeadEpoch(context, this.git);
@@ -57,17 +57,20 @@ export declare class MergeResolutionUnresolvedConflictError extends ForgeFailure
57
57
  export declare function isMergeInProgress(git: GitRunner, worktreePath: string): Promise<boolean>;
58
58
  export declare function readInProgressMerge(git: GitRunner, worktreePath: string): Promise<InProgressMerge | null>;
59
59
  /**
60
- * Fails before `git add -A` can silently resolve a conflict:
60
+ * Fails before `git add -A` can silently resolve a conflict, during a merge or whenever the index
61
+ * holds unmerged paths without one (a WIP snapshot re-applied across a branch move that conflicted,
62
+ * see wip-restore.ts):
61
63
  * - a modify/delete conflict, by keeping whatever is on disk;
62
64
  * - a binary (or other marker-less) conflict, by staging whichever side is on disk;
63
65
  * - a content conflict, by staging its conflict markers. This includes markers
64
66
  * the provider already staged, which clears the unmerged stages, so every path
65
- * both sides changed is checked too.
67
+ * both sides of the merge changed is checked too, or without a merge every path
68
+ * the worktree's WIP re-apply conflict record lists.
66
69
  * A text conflict the agent resolved in the working tree without `git add` is
67
70
  * still unmerged here and is accepted once its markers are gone.
68
71
  */
69
72
  export declare function assertNoUnresolvedMergeConflicts(git: GitRunner, worktreePath: string): Promise<void>;
70
- export declare function readUnresolvedMergeConflicts(git: GitRunner, worktreePath: string, merge: InProgressMerge): Promise<readonly UnresolvedMergeConflict[]>;
73
+ export declare function readUnresolvedMergeConflicts(git: GitRunner, worktreePath: string, merge: InProgressMerge | null): Promise<readonly UnresolvedMergeConflict[]>;
71
74
  /**
72
75
  * Staging excludes some worktree changes (Forge runtime output) by unstaging them
73
76
  * back to HEAD. During a merge HEAD is the story side, so an excluded path the merge
@@ -1,5 +1,6 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
+ import { hasConflictMarkerLines, parseReapplyConflictRecord, wipReapplyConflictRecordName } from "../../worktree/wip-refs.js";
3
4
  import { ForgeFailureError } from "../session.types.js";
4
5
  const maxListedPaths = 20;
5
6
  const pathArgumentChunkSize = 100;
@@ -61,19 +62,20 @@ export async function readInProgressMerge(git, worktreePath) {
61
62
  return { headSha, mergeHeadSha, mergeBaseSha };
62
63
  }
63
64
  /**
64
- * Fails before `git add -A` can silently resolve a conflict:
65
+ * Fails before `git add -A` can silently resolve a conflict, during a merge or whenever the index
66
+ * holds unmerged paths without one (a WIP snapshot re-applied across a branch move that conflicted,
67
+ * see wip-restore.ts):
65
68
  * - a modify/delete conflict, by keeping whatever is on disk;
66
69
  * - a binary (or other marker-less) conflict, by staging whichever side is on disk;
67
70
  * - a content conflict, by staging its conflict markers. This includes markers
68
71
  * the provider already staged, which clears the unmerged stages, so every path
69
- * both sides changed is checked too.
72
+ * both sides of the merge changed is checked too, or without a merge every path
73
+ * the worktree's WIP re-apply conflict record lists.
70
74
  * A text conflict the agent resolved in the working tree without `git add` is
71
75
  * still unmerged here and is accepted once its markers are gone.
72
76
  */
73
77
  export async function assertNoUnresolvedMergeConflicts(git, worktreePath) {
74
78
  const merge = await readInProgressMerge(git, worktreePath);
75
- if (!merge)
76
- return;
77
79
  const conflicts = await readUnresolvedMergeConflicts(git, worktreePath, merge);
78
80
  if (conflicts.length > 0) {
79
81
  throw new MergeResolutionUnresolvedConflictError(conflicts);
@@ -117,16 +119,34 @@ export async function readUnresolvedMergeConflicts(git, worktreePath, merge) {
117
119
  else if (hasConflictMarkers(content))
118
120
  conflicts.push({ path: filePath, kind: "conflict_markers" });
119
121
  }
122
+ const unmergedPaths = new Set(stagesByPath.keys());
123
+ conflicts.push(...await markerConflicts(worktreePath, unmergedPaths, merge
124
+ ? await bothChangedPaths(git, worktreePath, merge)
125
+ : await reapplyConflictPaths(git, worktreePath)));
126
+ return conflicts.sort((left, right) => left.path.localeCompare(right.path));
127
+ }
128
+ /** Paths both sides of the merge changed. */
129
+ async function bothChangedPaths(git, worktreePath, merge) {
120
130
  const storyChanged = new Set(await diffNames(git, worktreePath, [merge.mergeBaseSha, merge.headSha]));
121
- const bothChanged = (await diffNames(git, worktreePath, [merge.mergeBaseSha, merge.mergeHeadSha]))
122
- .filter(filePath => storyChanged.has(filePath) && !stagesByPath.has(filePath));
123
- for (const filePath of bothChanged) {
131
+ return (await diffNames(git, worktreePath, [merge.mergeBaseSha, merge.mergeHeadSha]))
132
+ .filter(filePath => storyChanged.has(filePath));
133
+ }
134
+ /** Paths a WIP re-apply left conflicted, from the worktree's record (wip-refs.ts); [] without one. */
135
+ async function reapplyConflictPaths(git, worktreePath) {
136
+ const raw = (await git.run(worktreePath, ["rev-parse", "--git-path", wipReapplyConflictRecordName])).trim();
137
+ const record = path.isAbsolute(raw) ? raw : path.resolve(worktreePath, raw);
138
+ return parseReapplyConflictRecord(await fs.readFile(record, "utf8").catch(() => null));
139
+ }
140
+ /** Candidate conflict paths whose markers the provider already staged (no unmerged stages left). */
141
+ async function markerConflicts(worktreePath, unmergedPaths, candidates) {
142
+ const conflicts = [];
143
+ for (const filePath of candidates.filter(candidate => !unmergedPaths.has(candidate))) {
124
144
  const content = await readWorkingFile(worktreePath, filePath);
125
145
  if (content && !isBinary(content) && hasConflictMarkers(content)) {
126
146
  conflicts.push({ path: filePath, kind: "conflict_markers" });
127
147
  }
128
148
  }
129
- return conflicts.sort((left, right) => left.path.localeCompare(right.path));
149
+ return conflicts;
130
150
  }
131
151
  /**
132
152
  * Staging excludes some worktree changes (Forge runtime output) by unstaging them
@@ -265,9 +285,8 @@ function chunks(paths) {
265
285
  }
266
286
  return result;
267
287
  }
268
- const conflictMarkerPattern = /^<{7}(?: |$)[\s\S]*^>{7}(?: |$)/mu;
269
288
  function hasConflictMarkers(content) {
270
- return conflictMarkerPattern.test(content.toString("utf8"));
289
+ return hasConflictMarkerLines(content.toString("utf8"));
271
290
  }
272
291
  /**
273
292
  * Paths whose effective `merge` attribute selects Git's binary merge driver, which
@@ -0,0 +1,23 @@
1
+ import type { GitClient } from "../../shared/git/git.js";
2
+ import type { ProviderCliRunContext, ProviderCliRunResult } from "./provider-cli.types.js";
3
+ import { type ProviderProcessRunner } from "./provider-cli.process.js";
4
+ /** What a review-only session needs from the provider CLI service that hosts it. */
5
+ export interface PrReviewRunServices {
6
+ readonly git: GitClient;
7
+ readonly processRunner: ProviderProcessRunner;
8
+ readonly providerToolHeartbeatIntervalMs: number;
9
+ }
10
+ /**
11
+ * A review session is read-only and publish-free only where the provider launch itself enforces it:
12
+ * Claude (tool deny rules, any platform) and Codex (POSIX only, because the Windows launch has no git/gh
13
+ * shim; its read-only sandbox on a host, the container in Docker: codexReviewSandboxMode). Every other provider or
14
+ * platform fails closed before anything starts.
15
+ */
16
+ export declare function assertPrReviewProviderSupported(provider: string, platform?: NodeJS.Platform): void;
17
+ /**
18
+ * Review-only session for a pull request head. Never routed through implementation: the worktree
19
+ * is detached at the dispatched head, the provider cannot change or publish anything, and the
20
+ * review is handed to Forge only through the completion tool. No commit, push or GitHub call
21
+ * is made here; a worktree that differs after the session fails with `guardrail_violation`.
22
+ */
23
+ export declare function runPrReviewSession(services: PrReviewRunServices, runContext: ProviderCliRunContext): Promise<ProviderCliRunResult>;
@@ -0,0 +1,213 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { artifactExecutionBody, selectLaneCommand } from "../../worktree/artifact-injector.js";
4
+ import { prepareCompletionToolRuntime, prReviewContextFromDispatch, readCompletionArtifact, recordedPrReviewArtifactProblem, } from "../phase-completion.js";
5
+ import { resolveReviewDiffBase, withReviewDiffBase } from "../pr-review-diff-base.js";
6
+ import { ForgeFailureError } from "../session.types.js";
7
+ import { cleanupCompletionTools, emitCompletionArtifactRecorded, emitPhaseCompletionEvent } from "./provider-cli.artifacts.js";
8
+ import { buildPrReviewPrompt, buildProviderCliCommand, buildProviderCliPrompt, formatProviderCliCommandForCheckpoint, shouldPipePromptToStdin, usesManagedWindowsHost } from "./provider-cli.prompts.js";
9
+ import { providerCompletionToolMissingFailure, recoveringProviderProcessRunner } from "./provider-cli.process.js";
10
+ import { emitProviderUsageEvent, prReviewProviderProcessEnv } from "./provider-cli.runtime.js";
11
+ import { ProviderToolActivityHeartbeat, providerCliExitFailure } from "./provider-cli.service-support.js";
12
+ import { assertReviewRefsUnchanged, assertReviewRemoteHeadUnchanged, assertWorktreeUnchanged, installPrReviewCommandShims, listRemotes, preparePrReviewCredentialIsolation, readReviewRemoteHead, reviewRefPatterns, snapshotReviewRefs, snapshotWorktree, } from "./pr-review-guardrails.js";
13
+ import { createProviderOutputState } from "./provider-output-state.js";
14
+ /**
15
+ * A review session is read-only and publish-free only where the provider launch itself enforces it:
16
+ * Claude (tool deny rules, any platform) and Codex (POSIX only, because the Windows launch has no git/gh
17
+ * shim; its read-only sandbox on a host, the container in Docker: codexReviewSandboxMode). Every other provider or
18
+ * platform fails closed before anything starts.
19
+ */
20
+ export function assertPrReviewProviderSupported(provider, platform = process.platform) {
21
+ const normalized = provider.trim().toLowerCase();
22
+ const supported = normalized === "claude" || (normalized === "codex" && platform !== "win32");
23
+ if (!supported) {
24
+ throw new ForgeFailureError("pr_review_provider_unsupported", `pr_review_provider_unsupported: the '${provider}' provider on ${platform} cannot be launched read-only with publication denied, so Forge did not start the review.`, "bridge");
25
+ }
26
+ }
27
+ /** The dispatched head the review is bound to; throws unless the worktree is checked out at it. */
28
+ async function requireDispatchedHead(git, context) {
29
+ const { dispatch, worktree } = context;
30
+ const headSha = (dispatch.prReview?.headSha || dispatch.pullRequest?.headSha || "").trim().toLowerCase();
31
+ if (!headSha) {
32
+ throw new ForgeFailureError("pr_review_head_missing", "pr_review_head_missing: the pr_review dispatch did not name a head_sha.", "bridge");
33
+ }
34
+ const checkedOutHead = (await git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim().toLowerCase();
35
+ if (checkedOutHead !== headSha) {
36
+ throw new ForgeFailureError("pr_review_head_mismatch", `pr_review_head_mismatch: the worktree is at ${checkedOutHead}, expected the dispatched head ${headSha}.`, "bridge");
37
+ }
38
+ return headSha;
39
+ }
40
+ /** Writes the Story spec from the payload, when there is one; the lane command body is prompt text only. */
41
+ async function writeReviewStorySpec(context) {
42
+ const { dispatch, worktree } = context;
43
+ const metadataRoot = path.join(worktree.worktreePath, ".forge", "work-items", dispatch.workItem.id);
44
+ await fs.mkdir(metadataRoot, { recursive: true });
45
+ const storySpec = dispatch.prReview?.storySpec ?? "";
46
+ if (storySpec.trim().length === 0) {
47
+ return null;
48
+ }
49
+ const specPath = path.join(metadataRoot, "spec.md");
50
+ await fs.writeFile(specPath, storySpec, "utf8");
51
+ await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), `${JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-story-spec" })}\n`, "utf8");
52
+ return { repoPath: worktree.worktreePath, path: specPath, body: storySpec, producedBy: "forge-story-spec", status: "approved" };
53
+ }
54
+ function buildPrReviewLaunch(context, headSha, completionTools, laneCommandBody) {
55
+ const { dispatch, worktree } = context;
56
+ const reviewPrompt = buildPrReviewPrompt(dispatch, laneCommandBody.replaceAll("{workItemId}", dispatch.workItem.id), headSha);
57
+ const providerPrompt = buildProviderCliPrompt(dispatch, reviewPrompt, context.runtimeEnvironment, { reviewOnly: true });
58
+ const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
59
+ const command = buildProviderCliCommand(dispatch, {
60
+ worktreePath: worktree.worktreePath,
61
+ prompt: reviewPrompt,
62
+ promptFromStdin: pipePromptToStdin,
63
+ completionTools,
64
+ runtimeEnvironment: context.runtimeEnvironment,
65
+ reviewOnly: true,
66
+ });
67
+ return { command, providerPrompt, pipePromptToStdin };
68
+ }
69
+ /**
70
+ * Runs the review-only provider under the guardrails: the worktree and the review's refs are
71
+ * snapshotted before launch (and, on a host, the pull request branch on origin is read with the bridge's
72
+ * own git), the provider gets an environment with no credential Forge controls and empty git and gh
73
+ * configuration (pr-review-credential-isolation.ts), and command shims deny
74
+ * git writes and GitHub calls. Always releases the completion tools and the isolation directory.
75
+ */
76
+ async function superviseReviewProvider(services, context, launch, completionTools, outputState, snapshotOptions) {
77
+ const { dispatch, worktree } = context;
78
+ const toolHeartbeat = new ProviderToolActivityHeartbeat(outputState, context.emit, services.providerToolHeartbeatIntervalMs);
79
+ let shims = null;
80
+ let isolation = null;
81
+ let providerStarted = false;
82
+ try {
83
+ // Setup lives inside the try so a failure here still releases the completion tools.
84
+ const baseline = await snapshotWorktree(services.git, worktree.worktreePath, snapshotOptions);
85
+ const remotes = await listRemotes(services.git, worktree.worktreePath);
86
+ const patterns = reviewRefPatterns(dispatch.pullRequest?.sourceBranch, remotes);
87
+ const refs = {
88
+ patterns,
89
+ snapshot: await snapshotReviewRefs(services.git, worktree.worktreePath, patterns),
90
+ remoteHead: await readReviewRemoteHead(services.git, worktree.worktreePath, dispatch),
91
+ };
92
+ isolation = await preparePrReviewCredentialIsolation({ remotes, safeDirectories: [worktree.worktreePath, worktree.repoPath] });
93
+ shims = await installPrReviewCommandShims();
94
+ const result = await recoveringProviderProcessRunner(context.processRunner ?? services.processRunner).run({
95
+ command: launch.command.command,
96
+ args: launch.command.args,
97
+ cwd: worktree.worktreePath,
98
+ env: prReviewProviderProcessEnv(dispatch, context.runtimeEnvironment, shims?.directory, isolation.env),
99
+ resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
100
+ stdin: launch.pipePromptToStdin ? launch.providerPrompt : undefined
101
+ }, {
102
+ onStarted: async () => {
103
+ await context.emit({ role: "runner", kind: "checkpoint", content: "Provider CLI PR review is supervised and ready.", eventType: "provider_cli_started" });
104
+ providerStarted = true;
105
+ },
106
+ isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
107
+ onGenerationStart: toolHeartbeat.startGeneration,
108
+ onStdoutLine: async (line) => {
109
+ await toolHeartbeat.consume(line);
110
+ }
111
+ }, context.signal);
112
+ return { result, baseline, refs };
113
+ }
114
+ finally {
115
+ toolHeartbeat.stop();
116
+ try {
117
+ if (providerStarted) {
118
+ await context.emit({ role: "runner", kind: "checkpoint", content: "Provider CLI PR review turn exited.", eventType: "provider_cli_completed" });
119
+ }
120
+ }
121
+ finally {
122
+ try {
123
+ await cleanupCompletionTools(completionTools, context.emit);
124
+ }
125
+ finally {
126
+ await shims?.cleanup();
127
+ await isolation?.cleanup();
128
+ }
129
+ }
130
+ }
131
+ }
132
+ async function emitPrReviewLaunchCheckpoints(context, launch) {
133
+ await context.emit({
134
+ role: "runner",
135
+ kind: "checkpoint",
136
+ content: "Forge PR review completion tool configured; the review-only provider must call forge.complete_pr_review. Forge denies git push, commit, rebase, reset, checkout, gh and GitHub API calls, and publishes nothing.",
137
+ eventType: "completion_tools_configured",
138
+ });
139
+ await context.emit({
140
+ role: "runner",
141
+ kind: "checkpoint",
142
+ content: `Starting provider CLI PR review: ${formatProviderCliCommandForCheckpoint(launch.command)} in ${context.worktree.worktreePath}`,
143
+ eventType: "provider_cli_starting",
144
+ });
145
+ }
146
+ /** Reads the accepted review artifact and announces it; throws when the provider never completed. */
147
+ async function recordReviewArtifact(context, outputState, result, headSha) {
148
+ const { dispatch, worktree } = context;
149
+ const reviewArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "pr_review");
150
+ if (!reviewArtifact) {
151
+ throw providerCompletionToolMissingFailure("Provider CLI completed but did not call forge.complete_pr_review. Forge recorded no review.", result);
152
+ }
153
+ // The session can write the result file itself, so hold the file to the completion tool's rules again.
154
+ const problem = await recordedPrReviewArtifactProblem(worktree.worktreePath, dispatch.workItem.id, reviewArtifact.verdictJson, prReviewContextFromDispatch(dispatch));
155
+ if (problem) {
156
+ throw new ForgeFailureError("pr_review_artifact_invalid", `pr_review_artifact_invalid: ${problem}. Forge recorded no review.`, "bridge");
157
+ }
158
+ await emitCompletionArtifactRecorded(context.emit, worktree.worktreePath, reviewArtifact);
159
+ await emitPhaseCompletionEvent(context.emit, reviewArtifact);
160
+ await emitProviderUsageEvent(context.emit, dispatch, outputState);
161
+ await context.emit({
162
+ role: "assistant",
163
+ kind: "message",
164
+ content: outputState.finalMessage || `${dispatch.execution.provider} CLI reviewed pull request head ${headSha.slice(0, 12)}.`,
165
+ eventType: "pr_review_complete",
166
+ });
167
+ return reviewArtifact;
168
+ }
169
+ /**
170
+ * Review-only session for a pull request head. Never routed through implementation: the worktree
171
+ * is detached at the dispatched head, the provider cannot change or publish anything, and the
172
+ * review is handed to Forge only through the completion tool. No commit, push or GitHub call
173
+ * is made here; a worktree that differs after the session fails with `guardrail_violation`.
174
+ */
175
+ export async function runPrReviewSession(services, runContext) {
176
+ assertPrReviewProviderSupported(runContext.dispatch.execution.provider);
177
+ const headSha = await requireDispatchedHead(services.git, runContext);
178
+ // The prompt, the completion tool and the recorded review all diff against the merge base, a commit the worktree has.
179
+ const diffBase = await resolveReviewDiffBase(runContext.dispatch, (args) => services.git.run(runContext.worktree.worktreePath, args));
180
+ const context = { ...runContext, dispatch: withReviewDiffBase(runContext.dispatch, diffBase) };
181
+ const { dispatch, worktree } = context;
182
+ const laneCommand = selectLaneCommand(dispatch.artifacts, dispatch.execution.lane, dispatch.cycleRun.phase);
183
+ if (!laneCommand) {
184
+ throw new Error(`PR review readiness failed: lane command for '${dispatch.execution.lane}' was not resolved.`);
185
+ }
186
+ const reviewSpec = await writeReviewStorySpec(context);
187
+ const completionTools = await prepareCompletionToolRuntime({
188
+ dispatch, worktree, phase: "pr_review", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment,
189
+ });
190
+ const launch = buildPrReviewLaunch(context, headSha, completionTools, artifactExecutionBody(laneCommand));
191
+ await emitPrReviewLaunchCheckpoints(context, launch);
192
+ const snapshotOptions = { ignoredDirectories: context.runtimeEnvironment?.FORGE_TEST_OUTPUT_DIR ? [context.runtimeEnvironment.FORGE_TEST_OUTPUT_DIR] : [] };
193
+ const outputState = createProviderOutputState(dispatch.execution.provider);
194
+ const { result, baseline, refs } = await superviseReviewProvider(services, context, launch, completionTools, outputState, snapshotOptions);
195
+ // A ref the session moved is a guardrail violation whether or not the provider exited cleanly.
196
+ await assertReviewRefsUnchanged(services.git, worktree.worktreePath, refs.patterns, refs.snapshot);
197
+ // A push leaves the local refs alone; the pull request branch on origin, read with the bridge's own git, does not.
198
+ await assertReviewRemoteHeadUnchanged(services.git, worktree.worktreePath, refs.remoteHead);
199
+ if (result.exitCode !== 0) {
200
+ throw providerCliExitFailure(launch.command.command, result);
201
+ }
202
+ // The worktree must be exactly as the review found it, whatever the review concluded.
203
+ await assertWorktreeUnchanged(services.git, worktree.worktreePath, baseline, snapshotOptions);
204
+ const reviewArtifact = await recordReviewArtifact(context, outputState, result, headSha);
205
+ return {
206
+ summary: `${dispatch.execution.provider} CLI reviewed pull request head ${headSha.slice(0, 12)} (${(reviewArtifact.status ?? "unknown").trim() || "unknown"}).`,
207
+ resultCommitSha: null,
208
+ publishedCommitSha: null,
209
+ spec: reviewSpec,
210
+ artifact: reviewArtifact,
211
+ artifacts: [reviewArtifact],
212
+ };
213
+ }
@@ -1,9 +1,10 @@
1
- import { type LaunchCommand } from "../../shared/process/windows-launch.js";
1
+ import type { LaunchCommand } from "../../shared/process/windows-launch.js";
2
2
  import { ForgeFailureError } from "../session.types.js";
3
3
  export { chooseWindowsCommandCandidate, resolveWindowsCommandFromPath } from "../../shared/process/windows-launch.js";
4
4
  export { buildProviderChildEnvironment, type ProviderChildEnvironmentOptions } from "./provider-cli.child-environment.js";
5
5
  export declare const PROVIDER_OUTPUT_CAPTURE_LIMIT_CHARS: number;
6
6
  export type ProviderCliCommand = LaunchCommand;
7
+ export { resolveClaudeNpmDirectLaunch, resolveCodexNpmDirectLaunch, resolvePackageManagerDirectLaunch } from "./provider-cli.windows-launch.js";
7
8
  export interface ProviderProcessRunRequest {
8
9
  readonly command: string;
9
10
  readonly args: readonly string[];
@@ -111,16 +112,3 @@ export declare function providerCompletionToolMissingFailure(message: string, re
111
112
  export declare function processGroupResidentMemoryBytes(processGroupId: number, platform?: NodeJS.Platform, procRoot?: string): number | null;
112
113
  export declare const UNIX_PROVIDER_START_GRANT_LINE = "forge-provider-start-granted\n";
113
114
  export declare function buildUnixProviderStartGateLaunch(command: string, args: readonly string[]): LaunchCommand;
114
- export declare function resolveCodexNpmDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
115
- /**
116
- * npm installs of Claude Code (`npm i -g @anthropic-ai/claude-code`) put a `claude.cmd` shim on
117
- * PATH; launch its cli.js directly for the same Job Object reasons as Codex. The native installer
118
- * ships `claude.exe`, which is preferred by PATH resolution and needs no rewrite.
119
- */
120
- export declare function resolveClaudeNpmDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
121
- /**
122
- * Avoids cmd.exe's nested-quote handling for package-manager shims. That
123
- * quoting loses executable paths containing spaces after the command is
124
- * wrapped by the Windows Job Object supervisor.
125
- */
126
- export declare function resolvePackageManagerDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
@@ -1,11 +1,9 @@
1
- import { execFile, execFileSync, spawn } from "node:child_process";
1
+ import { execFileSync, spawn } from "node:child_process";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
- import { promisify } from "node:util";
5
- import { resolveCursorAgentDirectLaunch } from "../../shared/cursor-agent/cursor-agent.launch.js";
6
4
  import { persistHostProcessSupervisorMetadata, resolveHostProcessSupervisedLaunch, terminateHostProcessTree, } from "../../shared/process/host-process-supervisor.js";
7
- import { buildWindowsLaunchCommand, chooseWindowsCommandCandidate, resolveWindowsCommandFromPath } from "../../shared/process/windows-launch.js";
8
5
  import { buildProviderChildEnvironment } from "./provider-cli.child-environment.js";
6
+ import { resolveWindowsProviderLaunch } from "./provider-cli.windows-launch.js";
9
7
  import { isCodexModelsCacheSchemaFailure, quarantineIncompatibleCodexModelsCache } from "./provider-cli.codex-models-cache.js";
10
8
  import { assertHostDatabaseCapabilityBoundary } from "../../runtime/host-database-capability-boundary.js";
11
9
  import { ForgeFailureError } from "../session.types.js";
@@ -14,7 +12,6 @@ import { hasNonterminalManagedCommand, isProviderTerminalFailure, isProviderTerm
14
12
  import { OutputPipeRelease, readProcessLines, PROVIDER_OUTPUT_PIPE_RELEASE_GRACE_MS } from "./provider-output-pipes.js";
15
13
  export { chooseWindowsCommandCandidate, resolveWindowsCommandFromPath } from "../../shared/process/windows-launch.js";
16
14
  export { buildProviderChildEnvironment } from "./provider-cli.child-environment.js";
17
- const execFileAsync = promisify(execFile);
18
15
  // Provider processes can emit many gigabytes over a long-running session. The
19
16
  // line handlers stream that output to Forge as it arrives; the completed result
20
17
  // only needs a bounded diagnostic tail for failure classification.
@@ -26,6 +23,7 @@ const PROVIDER_TERMINAL_EXIT_GRACE_MS = 15_000;
26
23
  const PROVIDER_TERMINAL_SUCCESS_CEILING_MS = 10 * 60_000;
27
24
  // How often the end-of-turn timers re-check whether supervised work is still in flight.
28
25
  const PROVIDER_TERMINAL_WORK_POLL_MS = 1_000;
26
+ export { resolveClaudeNpmDirectLaunch, resolveCodexNpmDirectLaunch, resolvePackageManagerDirectLaunch } from "./provider-cli.windows-launch.js";
29
27
  /** Recovery must wrap the attempt coordinator, never its raw OS runner. Each
30
28
  * relaunch needs a new fenced child generation and exclusive launch files. The outer
31
29
  * layer fails any run Forge stopped because its turn ended with background work live. */
@@ -648,18 +646,7 @@ async function resolveProviderProcessLaunch(command, args) {
648
646
  if (process.platform !== "win32") {
649
647
  return { command, args };
650
648
  }
651
- const cursorDirect = await resolveCursorAgentDirectLaunch(command, args);
652
- if (cursorDirect) {
653
- return cursorDirect;
654
- }
655
- const resolved = await resolveWindowsCommand(command);
656
- if (!resolved) {
657
- return { command, args };
658
- }
659
- return resolveCodexNpmDirectLaunch(resolved, args)
660
- ?? resolveClaudeNpmDirectLaunch(resolved, args)
661
- ?? resolvePackageManagerDirectLaunch(resolved, args)
662
- ?? buildWindowsLaunchCommand(resolved, args);
649
+ return await resolveWindowsProviderLaunch(command, args);
663
650
  }
664
651
  const UNIX_PROVIDER_START_GATE_SHELL = "/bin/sh";
665
652
  const UNIX_PROVIDER_START_GATE_NAME = "forge-provider-start-gate";
@@ -768,80 +755,3 @@ async function waitForWindowsProviderReady(launch, signal, isClosed) {
768
755
  await new Promise(resolve => setTimeout(resolve, 25));
769
756
  }
770
757
  }
771
- export function resolveCodexNpmDirectLaunch(commandPath, args) {
772
- const extension = path.extname(commandPath).toLowerCase();
773
- if ((extension !== ".cmd" && extension !== ".ps1")
774
- || path.basename(commandPath, extension).toLowerCase() !== "codex") {
775
- return null;
776
- }
777
- const entryPoint = path.join(path.dirname(commandPath), "node_modules", "@openai", "codex", "bin", "codex.js");
778
- return fs.existsSync(entryPoint)
779
- ? { command: process.execPath, args: [entryPoint, ...args] }
780
- : null;
781
- }
782
- /**
783
- * npm installs of Claude Code (`npm i -g @anthropic-ai/claude-code`) put a `claude.cmd` shim on
784
- * PATH; launch its cli.js directly for the same Job Object reasons as Codex. The native installer
785
- * ships `claude.exe`, which is preferred by PATH resolution and needs no rewrite.
786
- */
787
- export function resolveClaudeNpmDirectLaunch(commandPath, args) {
788
- const extension = path.extname(commandPath).toLowerCase();
789
- if ((extension !== ".cmd" && extension !== ".ps1")
790
- || path.basename(commandPath, extension).toLowerCase() !== "claude") {
791
- return null;
792
- }
793
- const entryPoint = path.join(path.dirname(commandPath), "node_modules", "@anthropic-ai", "claude-code", "cli.js");
794
- return fs.existsSync(entryPoint)
795
- ? { command: process.execPath, args: [entryPoint, ...args] }
796
- : null;
797
- }
798
- /**
799
- * Avoids cmd.exe's nested-quote handling for package-manager shims. That
800
- * quoting loses executable paths containing spaces after the command is
801
- * wrapped by the Windows Job Object supervisor.
802
- */
803
- export function resolvePackageManagerDirectLaunch(commandPath, args) {
804
- const extension = path.extname(commandPath).toLowerCase();
805
- if (extension !== ".cmd" && extension !== ".ps1")
806
- return null;
807
- const packageManager = path.basename(commandPath, extension).toLowerCase();
808
- if (!["corepack", "npm", "npx", "pnpm", "pnpx", "yarn", "yarnpkg"].includes(packageManager))
809
- return null;
810
- const root = path.dirname(commandPath);
811
- const candidates = [
812
- path.join(root, "node_modules", "corepack", "dist", packageManager === "corepack" ? "corepack.js" : `${packageManager}.js`),
813
- ...(packageManager === "npm" || packageManager === "npx"
814
- ? [path.join(root, "node_modules", "npm", "bin", `${packageManager}-cli.js`)]
815
- : []),
816
- ...(packageManager === "pnpm" || packageManager === "pnpx"
817
- ? [path.join(root, "node_modules", "pnpm", "bin", `${packageManager}.cjs`)]
818
- : []),
819
- ...(packageManager === "yarn" || packageManager === "yarnpkg"
820
- ? [path.join(root, "node_modules", "yarn", "bin", "yarn.js")]
821
- : []),
822
- ];
823
- const entryPoint = candidates.find(candidate => fs.existsSync(candidate));
824
- if (!entryPoint)
825
- return null;
826
- const adjacentNode = path.join(root, "node.exe");
827
- return {
828
- command: fs.existsSync(adjacentNode) ? adjacentNode : process.execPath,
829
- args: [entryPoint, ...args],
830
- };
831
- }
832
- async function resolveWindowsCommand(command) {
833
- if (path.isAbsolute(command)) {
834
- return command;
835
- }
836
- const resolvedFromPath = resolveWindowsCommandFromPath(command);
837
- if (resolvedFromPath) {
838
- return resolvedFromPath;
839
- }
840
- try {
841
- const result = await execFileAsync("where.exe", [command], { timeout: 2000 });
842
- return chooseWindowsCommandCandidate(result.stdout.split(/\r?\n/));
843
- }
844
- catch {
845
- return null;
846
- }
847
- }
@@ -15,7 +15,7 @@ export declare function isDecomposeDraftDispatch(dispatch: RunOnceDispatchPacket
15
15
  export declare function formatProviderCliCommand(command: ProviderCliCommand): string;
16
16
  export declare function formatProviderCliCommandForCheckpoint(command: ProviderCliCommand): string;
17
17
  export declare function singleLine(value: string): string;
18
- export declare function buildProviderCliCommand(dispatch: RunOnceDispatchPacket, run?: {
18
+ type ProviderCliRun = {
19
19
  readonly prompt?: string;
20
20
  readonly promptFromStdin?: boolean;
21
21
  readonly worktreePath?: string;
@@ -23,13 +23,21 @@ export declare function buildProviderCliCommand(dispatch: RunOnceDispatchPacket,
23
23
  readonly skipGitRepoCheck?: boolean;
24
24
  readonly imagePaths?: readonly string[];
25
25
  readonly runtimeEnvironment?: Readonly<Record<string, string>>;
26
- }): ProviderCliCommand;
26
+ /** Review-only launch: the provider is started without the tools that change or publish the checkout. */
27
+ readonly reviewOnly?: boolean;
28
+ };
29
+ export declare function buildProviderCliCommand(dispatch: RunOnceDispatchPacket, run?: ProviderCliRun): ProviderCliCommand;
27
30
  /**
28
31
  * Returns the effort level to pass to the provider CLI, or null to keep Forge's provider default.
29
32
  * Values the provider does not accept are dropped rather than failing the attempt; Forge validates on save.
30
33
  */
31
34
  export declare function providerEffort(provider: string, effort: string | null | undefined): string | null;
32
- export declare function buildProviderCliPrompt(dispatch: RunOnceDispatchPacket, prompt: string, runtimeEnvironment?: Readonly<Record<string, string>>): string;
35
+ /** Whether the provider reads its prompt from stdin rather than the command line. */
36
+ export declare function shouldPipePromptToStdin(provider: string, prompt: string, force?: boolean): boolean;
37
+ export declare function usesManagedWindowsHost(dispatch: RunOnceDispatchPacket): boolean;
38
+ export declare function buildProviderCliPrompt(dispatch: RunOnceDispatchPacket, prompt: string, runtimeEnvironment?: Readonly<Record<string, string>>, options?: {
39
+ readonly reviewOnly?: boolean;
40
+ }): string;
33
41
  export declare function codexSandboxModeForPlatform(platform?: NodeJS.Platform, executionMode?: string): "workspace-write" | "danger-full-access";
34
42
  export declare function buildArchitectPrompt(dispatch: RunOnceDispatchPacket): string;
35
43
  export declare function architectDependencyInstruction(dispatch: RunOnceDispatchPacket): string;
@@ -52,8 +60,10 @@ export declare function phaseWorkInstruction(phase: ReturnType<typeof completion
52
60
  export declare function qaBrowserInstruction(dispatch: RunOnceDispatchPacket): string;
53
61
  export declare function storyQaInstruction(dispatch: RunOnceDispatchPacket): string;
54
62
  export declare function buildQaPrompt(dispatch: RunOnceDispatchPacket, laneSpec: string): string;
63
+ export { buildPrReviewPrompt } from "./pr-review-prompt.js";
55
64
  export declare function buildConflictResolvePrompt(dispatch: RunOnceDispatchPacket, branchName: string): string;
56
65
  export declare function buildPullRequestCheckRepairPrompt(dispatch: RunOnceDispatchPacket, branchName: string): string;
57
66
  export declare function buildPullRequestCommentsPrompt(dispatch: RunOnceDispatchPacket, branchName: string): string;
58
67
  export declare function isPullRequestCheckRepairDispatch(dispatch: RunOnceDispatchPacket): boolean;
59
68
  export declare function isPullRequestCommentsDispatch(dispatch: RunOnceDispatchPacket): boolean;
69
+ export { reapplyConflictInstruction, withReapplyConflictInstruction, withRemainingReapplyConflictInstruction, } from "./provider-cli.reapply-conflicts.js";