@loucompanion/forge-bridge 0.1.3-dev.f66395c3ac21 → 0.1.4-dev.028808a841c8

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 (243) hide show
  1. package/README.md +165 -1
  2. package/dist/bridge/bridge-chat.types.d.ts +111 -0
  3. package/dist/bridge/bridge-chat.types.js +401 -0
  4. package/dist/bridge/bridge.base.d.ts +9 -1
  5. package/dist/bridge/bridge.service.d.ts +140 -3
  6. package/dist/bridge/bridge.service.js +2471 -68
  7. package/dist/bridge/bridge.types.d.ts +224 -2
  8. package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
  9. package/dist/bridge/dispatch-result-outbox.js +87 -0
  10. package/dist/bridge/dispatch-result-worker.d.ts +2 -0
  11. package/dist/bridge/dispatch-result-worker.js +122 -0
  12. package/dist/bridge/internals.d.ts +2 -0
  13. package/dist/bridge/internals.js +1 -0
  14. package/dist/bridge/readiness-result-outbox.d.ts +21 -0
  15. package/dist/bridge/readiness-result-outbox.js +54 -0
  16. package/dist/bridge/readiness-result-worker.d.ts +2 -0
  17. package/dist/bridge/readiness-result-worker.js +121 -0
  18. package/dist/bridge/runner-host-capabilities.d.ts +15 -0
  19. package/dist/bridge/runner-host-capabilities.js +93 -0
  20. package/dist/cleanup/cleanup.service.d.ts +14 -2
  21. package/dist/cleanup/cleanup.service.js +496 -3
  22. package/dist/cleanup/cleanup.types.d.ts +10 -0
  23. package/dist/cleanup/index.d.ts +1 -1
  24. package/dist/cleanup/index.js +1 -1
  25. package/dist/cleanup/internals.d.ts +2 -2
  26. package/dist/cleanup/internals.js +1 -1
  27. package/dist/cli/cli.help.d.ts +2 -0
  28. package/dist/cli/cli.help.js +217 -0
  29. package/dist/cli/cli.service.d.ts +55 -7
  30. package/dist/cli/cli.service.js +429 -219
  31. package/dist/cli/local-config.d.ts +7 -0
  32. package/dist/cli/local-config.js +51 -3
  33. package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
  34. package/dist/runtime/aspnet-runtime-prebuild.js +341 -0
  35. package/dist/runtime/attempt-database-broker.d.ts +89 -0
  36. package/dist/runtime/attempt-database-broker.js +390 -0
  37. package/dist/runtime/attempt-node-runtime-launcher.d.ts +18 -0
  38. package/dist/runtime/attempt-node-runtime-launcher.js +140 -0
  39. package/dist/runtime/attempt-path-operation.d.ts +21 -0
  40. package/dist/runtime/attempt-path-operation.js +94 -0
  41. package/dist/runtime/attempt-private-directory.d.ts +6 -0
  42. package/dist/runtime/attempt-private-directory.js +54 -0
  43. package/dist/runtime/attempt-process-supervisor-registry.d.ts +20 -0
  44. package/dist/runtime/attempt-process-supervisor-registry.js +64 -0
  45. package/dist/runtime/attempt-process-supervisor.d.ts +121 -0
  46. package/dist/runtime/attempt-process-supervisor.js +471 -0
  47. package/dist/runtime/canonical-source-file.d.ts +3 -0
  48. package/dist/runtime/canonical-source-file.js +54 -0
  49. package/dist/runtime/docker-engine-probe.d.ts +90 -0
  50. package/dist/runtime/docker-engine-probe.js +333 -0
  51. package/dist/runtime/generated-output-reset.d.ts +20 -0
  52. package/dist/runtime/generated-output-reset.js +157 -0
  53. package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
  54. package/dist/runtime/host-database-capability-boundary.js +63 -0
  55. package/dist/runtime/host-diagnostics.d.ts +11 -0
  56. package/dist/runtime/host-diagnostics.js +192 -0
  57. package/dist/runtime/host-execution-root.d.ts +4 -0
  58. package/dist/runtime/host-execution-root.js +39 -0
  59. package/dist/runtime/host-facts.d.ts +35 -0
  60. package/dist/runtime/host-facts.js +95 -0
  61. package/dist/runtime/host-listener-inspector.d.ts +51 -0
  62. package/dist/runtime/host-listener-inspector.js +385 -0
  63. package/dist/runtime/host-load-sampler.d.ts +83 -0
  64. package/dist/runtime/host-load-sampler.js +164 -0
  65. package/dist/runtime/host-port-broker.d.ts +76 -0
  66. package/dist/runtime/host-port-broker.js +333 -0
  67. package/dist/runtime/host-pressure-stall.d.ts +41 -0
  68. package/dist/runtime/host-pressure-stall.js +121 -0
  69. package/dist/runtime/host-runtime-contract.d.ts +59 -0
  70. package/dist/runtime/host-runtime-contract.js +815 -0
  71. package/dist/runtime/host-runtime-lease.d.ts +217 -0
  72. package/dist/runtime/host-runtime-lease.js +2533 -0
  73. package/dist/runtime/host-runtime-promotion.d.ts +32 -0
  74. package/dist/runtime/host-runtime-promotion.js +206 -0
  75. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  76. package/dist/runtime/managed-command-teardown.js +607 -0
  77. package/dist/runtime/memory-capacity.d.ts +70 -0
  78. package/dist/runtime/memory-capacity.js +123 -0
  79. package/dist/runtime/native-test-postgres-fallback.d.ts +25 -0
  80. package/dist/runtime/native-test-postgres-fallback.js +91 -0
  81. package/dist/runtime/node-host-runtime-adapter.d.ts +54 -0
  82. package/dist/runtime/node-host-runtime-adapter.js +286 -0
  83. package/dist/runtime/pinned-directory-process.d.ts +9 -0
  84. package/dist/runtime/pinned-directory-process.js +61 -0
  85. package/dist/runtime/pinned-source-directory.d.ts +17 -0
  86. package/dist/runtime/pinned-source-directory.js +94 -0
  87. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  88. package/dist/runtime/playwright-browser-cache.js +227 -0
  89. package/dist/runtime/playwright-host-runtime-adapter.d.ts +32 -0
  90. package/dist/runtime/playwright-host-runtime-adapter.js +262 -0
  91. package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
  92. package/dist/runtime/prepared-runtime-identity.js +218 -0
  93. package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
  94. package/dist/runtime/prepared-runtime-readiness.js +285 -0
  95. package/dist/runtime/runtime-isolation-lease.d.ts +67 -0
  96. package/dist/runtime/runtime-isolation-lease.js +161 -0
  97. package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
  98. package/dist/runtime/workspace-resource-estimator.js +174 -0
  99. package/dist/sandbox/command-runner.d.ts +4 -0
  100. package/dist/sandbox/command-runner.js +47 -0
  101. package/dist/sandbox/contract.d.ts +5 -0
  102. package/dist/sandbox/contract.js +276 -0
  103. package/dist/sandbox/event-budget.d.ts +11 -0
  104. package/dist/sandbox/event-budget.js +27 -0
  105. package/dist/sandbox/image-policy.d.ts +35 -0
  106. package/dist/sandbox/image-policy.js +247 -0
  107. package/dist/sandbox/index.d.ts +5 -0
  108. package/dist/sandbox/index.js +5 -0
  109. package/dist/sandbox/lease-watchdog.d.ts +18 -0
  110. package/dist/sandbox/lease-watchdog.js +67 -0
  111. package/dist/sandbox/preflight.d.ts +84 -0
  112. package/dist/sandbox/preflight.js +521 -0
  113. package/dist/sandbox/process.d.ts +20 -0
  114. package/dist/sandbox/process.js +209 -0
  115. package/dist/sandbox/provider-auth/codex.d.ts +26 -0
  116. package/dist/sandbox/provider-auth/codex.js +212 -0
  117. package/dist/sandbox/repository-lock.d.ts +6 -0
  118. package/dist/sandbox/repository-lock.js +129 -0
  119. package/dist/sandbox/runtime.d.ts +302 -0
  120. package/dist/sandbox/runtime.js +2368 -0
  121. package/dist/sandbox/sandbox.types.d.ts +93 -0
  122. package/dist/sandbox/sandbox.types.js +1 -0
  123. package/dist/sandbox/smoke.d.ts +76 -0
  124. package/dist/sandbox/smoke.js +380 -0
  125. package/dist/sandbox/worker-supervisor.d.ts +13 -0
  126. package/dist/sandbox/worker-supervisor.js +36 -0
  127. package/dist/sandbox/worker.d.ts +1 -0
  128. package/dist/sandbox/worker.js +225 -0
  129. package/dist/sandbox/workspace.service.d.ts +13 -0
  130. package/dist/sandbox/workspace.service.js +74 -0
  131. package/dist/session/managed-attempt-tools.d.ts +53 -0
  132. package/dist/session/managed-attempt-tools.js +1213 -0
  133. package/dist/session/managed-build-coordinator.d.ts +5 -0
  134. package/dist/session/managed-build-coordinator.js +109 -0
  135. package/dist/session/managed-build-receipt.d.ts +21 -0
  136. package/dist/session/managed-build-receipt.js +337 -0
  137. package/dist/session/managed-verification-timeouts.d.ts +8 -0
  138. package/dist/session/managed-verification-timeouts.js +17 -0
  139. package/dist/session/phase-completion.artifacts.d.ts +27 -0
  140. package/dist/session/phase-completion.artifacts.js +833 -0
  141. package/dist/session/phase-completion.d.ts +53 -42
  142. package/dist/session/phase-completion.helpers.d.ts +117 -0
  143. package/dist/session/phase-completion.helpers.js +707 -0
  144. package/dist/session/phase-completion.js +125 -3007
  145. package/dist/session/phase-completion.prompts.d.ts +14 -0
  146. package/dist/session/phase-completion.prompts.js +233 -0
  147. package/dist/session/phase-completion.runtime.d.ts +49 -0
  148. package/dist/session/phase-completion.runtime.js +845 -0
  149. package/dist/session/phase-completion.schemas.d.ts +3 -0
  150. package/dist/session/phase-completion.schemas.js +859 -0
  151. package/dist/session/phase-completion.validation.d.ts +38 -0
  152. package/dist/session/phase-completion.validation.js +918 -0
  153. package/dist/session/pre-publication-process.d.ts +20 -0
  154. package/dist/session/pre-publication-process.js +97 -0
  155. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  156. package/dist/session/pre-publication-skipped-tests.js +109 -0
  157. package/dist/session/pre-publication-validation.d.ts +75 -0
  158. package/dist/session/pre-publication-validation.js +631 -0
  159. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
  160. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
  161. package/dist/session/provider-cli/ci-repair-readiness.d.ts +16 -0
  162. package/dist/session/provider-cli/ci-repair-readiness.js +110 -0
  163. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +96 -0
  164. package/dist/session/provider-cli/provider-cli.artifacts.js +818 -0
  165. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  166. package/dist/session/provider-cli/provider-cli.deterministic-payloads.d.ts +12 -0
  167. package/dist/session/provider-cli/provider-cli.deterministic-payloads.js +279 -0
  168. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +14 -0
  169. package/dist/session/provider-cli/provider-cli.deterministic.js +407 -0
  170. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  171. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  172. package/dist/session/provider-cli/provider-cli.process.d.ts +128 -0
  173. package/dist/session/provider-cli/provider-cli.process.js +1140 -0
  174. package/dist/session/provider-cli/provider-cli.prompts.d.ts +57 -0
  175. package/dist/session/provider-cli/provider-cli.prompts.js +730 -0
  176. package/dist/session/provider-cli/provider-cli.qa-sidecars.d.ts +11 -0
  177. package/dist/session/provider-cli/provider-cli.qa-sidecars.js +66 -0
  178. package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
  179. package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
  180. package/dist/session/provider-cli/provider-cli.runtime.d.ts +22 -0
  181. package/dist/session/provider-cli/provider-cli.runtime.js +92 -0
  182. package/dist/session/provider-cli/provider-cli.service.d.ts +47 -53
  183. package/dist/session/provider-cli/provider-cli.service.js +1344 -2506
  184. package/dist/session/provider-cli/provider-cli.types.d.ts +8 -0
  185. package/dist/session/provider-cli/provider-in-flight-work.d.ts +6 -0
  186. package/dist/session/provider-cli/provider-in-flight-work.js +47 -0
  187. package/dist/session/provider-cli/provider-output-state.d.ts +38 -0
  188. package/dist/session/provider-cli/provider-output-state.js +826 -0
  189. package/dist/session/provider-cli/provider-usage.d.ts +9 -1
  190. package/dist/session/provider-cli/provider-usage.js +28 -5
  191. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  192. package/dist/session/publishable-worktree-changes.js +193 -0
  193. package/dist/session/session-redaction.d.ts +3 -0
  194. package/dist/session/session-redaction.js +448 -0
  195. package/dist/session/session.base.d.ts +6 -1
  196. package/dist/session/session.service.d.ts +8 -2
  197. package/dist/session/session.service.js +586 -59
  198. package/dist/session/session.types.d.ts +324 -3
  199. package/dist/session/session.types.js +951 -10
  200. package/dist/session/unreferenced-exports.d.ts +12 -0
  201. package/dist/session/unreferenced-exports.js +59 -0
  202. package/dist/shared/format/format-bytes.d.ts +1 -0
  203. package/dist/shared/format/format-bytes.js +9 -0
  204. package/dist/shared/git/git.js +2 -1
  205. package/dist/shared/path/path.d.ts +1 -0
  206. package/dist/shared/path/path.js +21 -1
  207. package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
  208. package/dist/shared/process/dotnet-toolchain.js +307 -0
  209. package/dist/shared/process/host-process-recovery.d.ts +12 -0
  210. package/dist/shared/process/host-process-recovery.js +79 -0
  211. package/dist/shared/process/host-process-supervisor.d.ts +59 -0
  212. package/dist/shared/process/host-process-supervisor.js +331 -0
  213. package/dist/shared/process/process.d.ts +3 -0
  214. package/dist/shared/process/process.js +13 -7
  215. package/dist/shared/process/windows-launch.d.ts +8 -0
  216. package/dist/shared/process/windows-launch.js +41 -0
  217. package/dist/shared/provider-capabilities.d.ts +4 -0
  218. package/dist/shared/provider-capabilities.js +88 -0
  219. package/dist/shared/redaction/redaction.d.ts +1 -0
  220. package/dist/shared/redaction/redaction.js +47 -4
  221. package/dist/shared/time/monotonic.d.ts +1 -0
  222. package/dist/shared/time/monotonic.js +8 -0
  223. package/dist/version.d.ts +1 -1
  224. package/dist/version.js +1 -1
  225. package/dist/worktree/artifact-injector.d.ts +3 -2
  226. package/dist/worktree/artifact-injector.js +82 -10
  227. package/dist/worktree/dependency-warmer.d.ts +53 -1
  228. package/dist/worktree/dependency-warmer.js +693 -11
  229. package/dist/worktree/index.d.ts +2 -1
  230. package/dist/worktree/index.js +1 -0
  231. package/dist/worktree/prior-phase-artifact-hydrator.d.ts +2 -0
  232. package/dist/worktree/prior-phase-artifact-hydrator.js +136 -0
  233. package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
  234. package/dist/worktree/story-qa-reference-hydrator.js +253 -0
  235. package/dist/worktree/worktree-paths.d.ts +4 -0
  236. package/dist/worktree/worktree-paths.js +30 -0
  237. package/dist/worktree/worktree.base.d.ts +3 -0
  238. package/dist/worktree/worktree.service.d.ts +16 -3
  239. package/dist/worktree/worktree.service.js +334 -54
  240. package/dist/worktree/worktree.types.d.ts +9 -1
  241. package/package.json +12 -7
  242. package/runtime/windows-job-supervisor.ps1 +722 -0
  243. package/runtime/windows-listener-owner.ps1 +33 -0
@@ -0,0 +1,407 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { GitClient } from "../../shared/git/git.js";
4
+ import { buildSpecBody, selectLaneCommand } from "../../worktree/artifact-injector.js";
5
+ import { completionPhaseFromDispatch, debugCompletionPhaseOrder, expectedCompletionToolName, expectedDebugCompletionToolName, expectedQaCompletionToolName, qaCompletionGateOrder, readCompletionArtifact, usesDebugCycleCompletion, usesDevelopCycleCompletion, writeCompletionArtifact } from "../phase-completion.js";
6
+ import { commitWorktreeChanges, emitArchitectStructuredEvents, emitCompletionArtifactRecorded, emitQaArtifactRecorded, emitQaGateAccepted, emitQaStructuredEvents, isDebugCompletionPhaseForProvider, nextQaGate, phaseCompleteEventType, qaArtifactRootForDispatch, readQaCompletionArtifactBundle, readQaGateArtifact } from "./provider-cli.artifacts.js";
7
+ import { deterministicBrowserCheck, deterministicBrowserSidecar, hasLaunchTarget, writeQaSidecarFiles } from "./provider-cli.qa-sidecars.js";
8
+ import { buildProviderCliCommand, formatProviderCliCommand, isPullRequestCheckRepairDispatch, isPullRequestCommentsDispatch, singleLine } from "./provider-cli.prompts.js";
9
+ import { estimatedDeterministicUsage, exactRedactionSecrets } from "./provider-cli.runtime.js";
10
+ import { buildProviderUsageEvent } from "./provider-usage.js";
11
+ import { writeCiRepairReadinessManifest } from "./ci-repair-readiness.js";
12
+ import { assertRepairHeadEpoch } from "./provider-cli.repair-epoch.js";
13
+ import { deterministicArchitectPayload, deterministicCompletionPayload, deterministicQaGatePayload } from "./provider-cli.deterministic-payloads.js";
14
+ export class DeterministicProviderCliService {
15
+ git;
16
+ constructor(git = new GitClient()) {
17
+ this.git = git;
18
+ }
19
+ async runDraft(context) {
20
+ const content = JSON.stringify(deterministicDraftPayload(context.dispatch));
21
+ await context.emit({
22
+ role: "assistant",
23
+ kind: "message",
24
+ content,
25
+ eventType: "draft_complete"
26
+ });
27
+ await context.emit(buildProviderUsageEvent(context.dispatch, estimatedDeterministicUsage()));
28
+ return { summary: "forge-bridge generated deterministic draft." };
29
+ }
30
+ async runImplementation(context) {
31
+ const { dispatch, worktree } = context;
32
+ const phase = completionPhaseFromDispatch(dispatch);
33
+ const developCycle = usesDevelopCycleCompletion(dispatch);
34
+ const debugCycle = usesDebugCycleCompletion(dispatch);
35
+ const providerCommand = buildProviderCliCommand(dispatch);
36
+ const providerCommandText = formatProviderCliCommand(providerCommand);
37
+ const metadataRoot = path.join(worktree.worktreePath, ".forge", "work-items", dispatch.workItem.id);
38
+ const artifactRoot = path.join(metadataRoot, "artifacts");
39
+ await fs.mkdir(artifactRoot, { recursive: true });
40
+ const laneCommand = selectLaneCommand(dispatch.artifacts, dispatch.execution.lane, dispatch.cycleRun.phase);
41
+ if (!laneCommand) {
42
+ throw new Error(`Lane command for lane '${dispatch.execution.lane}' phase '${dispatch.cycleRun.phase}' was not resolved.`);
43
+ }
44
+ const specBody = `${buildSpecBody(laneCommand, dispatch.workItem, phase)}
45
+ ## Execution
46
+
47
+ - Provider: ${singleLine(dispatch.execution.provider)}
48
+ - Model: ${singleLine(dispatch.execution.model)}
49
+ - Command: ${providerCommandText}
50
+ `;
51
+ const specPath = path.join(metadataRoot, "spec.md");
52
+ await fs.writeFile(specPath, specBody, "utf8");
53
+ await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" }) + "\n", "utf8");
54
+ const changesetPath = path.join(worktree.worktreePath, "FORGE_PHASE5_CHANGESET.md");
55
+ const changesetBody = `# Forge Phase 5 bridge changeset\n\nWork item: ${dispatch.workItem.id}\nTitle: ${dispatch.workItem.title}\nBranch: ${worktree.branchName}\nProvider: ${singleLine(dispatch.execution.provider)}\nModel: ${singleLine(dispatch.execution.model)}\nCommand: ${providerCommandText}\n\nThis deterministic file is written by forge-bridge run-once through the shared session/worktree service path.\n`;
56
+ await fs.writeFile(changesetPath, changesetBody, "utf8");
57
+ await this.git.run(worktree.worktreePath, ["add", "FORGE_PHASE5_CHANGESET.md"]);
58
+ await this.git.run(worktree.worktreePath, ["commit", "--allow-empty", "-m", `forge bridge changeset for ${dispatch.workItem.id.slice(0, 8)}`]);
59
+ await context.emit({
60
+ role: "worker",
61
+ kind: "file_edit",
62
+ content: `Created bridge changeset at ${changesetPath}`,
63
+ eventType: "changeset"
64
+ });
65
+ const phases = debugCycle
66
+ ? debugCompletionPhaseOrder
67
+ : developCycle
68
+ ? ["implementation", "self_review", "validation"]
69
+ : [phase];
70
+ const completionArtifacts = [];
71
+ for (const completionPhase of phases) {
72
+ await writeCompletionArtifact({
73
+ worktreePath: worktree.worktreePath,
74
+ workItemId: dispatch.workItem.id,
75
+ phase: completionPhase,
76
+ producedBy: "forge-bridge",
77
+ redactionSecrets: exactRedactionSecrets(dispatch)
78
+ }, isDebugCompletionPhaseForProvider(completionPhase)
79
+ ? expectedDebugCompletionToolName(completionPhase)
80
+ : expectedCompletionToolName(completionPhase), deterministicCompletionPayload(completionPhase, dispatch, changesetBody));
81
+ const completionArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, completionPhase);
82
+ if (!completionArtifact) {
83
+ throw new Error(`Deterministic provider did not produce the Forge ${completionPhase} completion artifact.`);
84
+ }
85
+ completionArtifacts.push(completionArtifact);
86
+ await emitCompletionArtifactRecorded(context.emit, worktree.worktreePath, completionArtifact);
87
+ await context.emit({
88
+ role: "assistant",
89
+ kind: "message",
90
+ content: `${completionPhase.replace(/_/g, " ")} complete. forge-bridge produced deterministic phase artifacts.`,
91
+ eventType: phaseCompleteEventType(completionPhase)
92
+ });
93
+ }
94
+ await context.emit(buildProviderUsageEvent(dispatch, estimatedDeterministicUsage()));
95
+ return {
96
+ summary: `forge-bridge completed ${worktree.branchName} (${debugCycle ? "debug cycle" : developCycle ? "develop cycle" : phase}).`,
97
+ spec: {
98
+ repoPath: worktree.worktreePath,
99
+ path: specPath,
100
+ body: specBody,
101
+ producedBy: "forge-lane-command",
102
+ status: "approved"
103
+ },
104
+ artifact: completionArtifacts[0],
105
+ artifacts: completionArtifacts
106
+ };
107
+ }
108
+ async runArchitect(context) {
109
+ const { dispatch, worktree } = context;
110
+ const metadataRoot = path.join(worktree.worktreePath, ".forge", "work-items", dispatch.workItem.id);
111
+ await fs.mkdir(metadataRoot, { recursive: true });
112
+ const specBody = `---\ntitle: "${dispatch.workItem.title}"\nstatus: pending_approval\nproduced_by: forge-bridge\n---\n\n# ${dispatch.workItem.title}\n\nArchitect plan pending approval.\n`;
113
+ const specPath = path.join(metadataRoot, "spec.md");
114
+ await fs.writeFile(specPath, specBody, "utf8");
115
+ await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), JSON.stringify({ schema_version: 1, status: "pending_approval", produced_by: "forge-bridge" }) + "\n", "utf8");
116
+ await writeCompletionArtifact({
117
+ worktreePath: worktree.worktreePath,
118
+ workItemId: dispatch.workItem.id,
119
+ phase: "architect",
120
+ producedBy: "forge-bridge",
121
+ redactionSecrets: exactRedactionSecrets(dispatch),
122
+ architectCycle: true
123
+ }, expectedCompletionToolName("architect"), deterministicArchitectPayload(dispatch));
124
+ const artifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "architect");
125
+ if (!artifact) {
126
+ throw new Error("Deterministic provider did not produce the Forge Architect completion artifact.");
127
+ }
128
+ await emitCompletionArtifactRecorded(context.emit, worktree.worktreePath, artifact);
129
+ await emitArchitectStructuredEvents(context.emit, worktree.worktreePath, dispatch.workItem.id, artifact);
130
+ await context.emit({
131
+ role: "assistant",
132
+ kind: "message",
133
+ content: "Architect plan complete. forge-bridge produced deterministic planning artifacts.",
134
+ eventType: "architect_complete"
135
+ });
136
+ return {
137
+ summary: "forge-bridge completed Architect plan (deterministic).",
138
+ spec: {
139
+ repoPath: worktree.worktreePath,
140
+ path: specPath,
141
+ body: specBody,
142
+ producedBy: "forge-bridge",
143
+ status: "pending_approval"
144
+ },
145
+ artifact,
146
+ artifacts: [artifact]
147
+ };
148
+ }
149
+ async runQa(context) {
150
+ const { dispatch, worktree } = context;
151
+ await context.emit({
152
+ role: "worker",
153
+ kind: "message",
154
+ content: `Planning ${dispatch.execution.provider} QA checks through forge-bridge.`,
155
+ eventType: "qa_plan"
156
+ });
157
+ const qaBrowser = dispatch.qaBrowser;
158
+ const launchTarget = qaBrowser?.launchTarget ?? null;
159
+ const missingLaunchTarget = qaBrowser?.required === true && !hasLaunchTarget(launchTarget);
160
+ const browserSidecar = !missingLaunchTarget && qaBrowser?.required === true && launchTarget
161
+ ? deterministicBrowserSidecar(dispatch.workItem.id, launchTarget, dispatch.cycleRun.ownerType, dispatch.cycleRun.ownerId)
162
+ : null;
163
+ const browserChecks = browserSidecar && launchTarget
164
+ ? [deterministicBrowserCheck(launchTarget, browserSidecar.relativePath)]
165
+ : [];
166
+ const sidecars = await writeQaSidecarFiles(worktree.worktreePath, browserSidecar ? [browserSidecar] : []);
167
+ const summary = missingLaunchTarget
168
+ ? "QA blocked because browser testing is required but no app launch target was provided."
169
+ : "All checks passed. forge-bridge QA completed.";
170
+ const criterion = dispatch.workItem.acceptanceCriteria.trim() || "Forge QA evidence exists";
171
+ for (const gate of qaCompletionGateOrder) {
172
+ await writeCompletionArtifact({
173
+ worktreePath: worktree.worktreePath,
174
+ workItemId: dispatch.workItem.id,
175
+ phase: "qa",
176
+ producedBy: "forge-bridge",
177
+ redactionSecrets: exactRedactionSecrets(dispatch),
178
+ qaCycle: true,
179
+ ownerType: dispatch.cycleRun.ownerType ?? undefined,
180
+ ownerId: dispatch.cycleRun.ownerId ?? undefined
181
+ }, expectedQaCompletionToolName(gate), deterministicQaGatePayload({
182
+ gate,
183
+ criterion,
184
+ summary,
185
+ missingLaunchTarget,
186
+ browserChecks,
187
+ sidecars
188
+ }));
189
+ const gateArtifact = await readQaGateArtifact(qaArtifactRootForDispatch(worktree.worktreePath, dispatch.workItem.id, dispatch), gate);
190
+ if (gateArtifact) {
191
+ await emitQaGateAccepted(context.emit, worktree.worktreePath, gateArtifact, nextQaGate(gate));
192
+ }
193
+ }
194
+ const qaArtifact = await readQaCompletionArtifactBundle(worktree.worktreePath, dispatch.workItem.id, dispatch.cycleRun.ownerType, dispatch.cycleRun.ownerId);
195
+ if (!qaArtifact) {
196
+ throw new Error("Deterministic QA did not produce the complete durable QA artifact bundle.");
197
+ }
198
+ await emitQaArtifactRecorded(context.emit, worktree.worktreePath, qaArtifact);
199
+ await emitQaStructuredEvents(context.emit, qaArtifact);
200
+ await context.emit(buildProviderUsageEvent(dispatch, estimatedDeterministicUsage()));
201
+ return {
202
+ summary: missingLaunchTarget ? "forge-bridge QA blocked." : "forge-bridge QA passed.",
203
+ artifact: qaArtifact,
204
+ artifacts: [qaArtifact]
205
+ };
206
+ }
207
+ async runCiRepair(context) {
208
+ return await this.runPullRequestRepair(context, "ci_repair");
209
+ }
210
+ async runConflictResolve(context) {
211
+ return await this.runPullRequestRepair(context, "conflict_resolve");
212
+ }
213
+ async runPullRequestRepair(context, route) {
214
+ const { dispatch, worktree } = context;
215
+ await assertRepairHeadEpoch(context, this.git);
216
+ const repairChecks = route === "ci_repair" || isPullRequestCheckRepairDispatch(dispatch);
217
+ const addressComments = isPullRequestCommentsDispatch(dispatch);
218
+ let repairArtifact = null;
219
+ let repairSpec = null;
220
+ if (repairChecks) {
221
+ const metadataRoot = path.join(worktree.worktreePath, ".forge", "work-items", dispatch.workItem.id);
222
+ await fs.mkdir(metadataRoot, { recursive: true });
223
+ const laneCommand = selectLaneCommand(dispatch.artifacts, dispatch.execution.lane, dispatch.cycleRun.phase);
224
+ if (!laneCommand)
225
+ throw new Error("Deterministic CI repair could not materialize the approved lane spec.");
226
+ const specBody = buildSpecBody(laneCommand, dispatch.workItem, "ci_repair");
227
+ const specPath = path.join(metadataRoot, "spec.md");
228
+ await fs.writeFile(specPath, specBody, "utf8");
229
+ await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), `${JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" })}\n`, "utf8");
230
+ repairSpec = { repoPath: worktree.worktreePath, path: specPath, body: specBody, producedBy: "forge-lane-command", status: "approved" };
231
+ await writeCiRepairReadinessManifest(dispatch, worktree.worktreePath, specPath, context.runtimeEnvironment);
232
+ const reference = await writeCompletionArtifact({
233
+ worktreePath: worktree.worktreePath,
234
+ workItemId: dispatch.workItem.id,
235
+ phase: "ci_repair",
236
+ producedBy: "forge-deterministic-provider",
237
+ }, expectedCompletionToolName("ci_repair"), deterministicCiRepairPayload());
238
+ repairArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "ci_repair");
239
+ if (!repairArtifact)
240
+ throw new Error(`Deterministic CI repair did not produce ${reference.path}.`);
241
+ await emitCompletionArtifactRecorded(context.emit, worktree.worktreePath, repairArtifact);
242
+ }
243
+ if (addressComments) {
244
+ const actionable = dispatch.pullRequest?.reviewFindings.filter(finding => finding.actionable) ?? [];
245
+ if (actionable.length === 0 || !dispatch.pullRequest?.reviewIssueKey || !dispatch.pullRequest.headSha) {
246
+ throw new Error("Deterministic comment repair requires a durable actionable finding snapshot.");
247
+ }
248
+ await writeCompletionArtifact({
249
+ worktreePath: worktree.worktreePath,
250
+ workItemId: dispatch.workItem.id,
251
+ phase: "comment_repair",
252
+ producedBy: "forge-deterministic-provider",
253
+ }, expectedCompletionToolName("comment_repair"), {
254
+ status: "pass",
255
+ summary: "Recorded deterministic decision-required outcomes without changing source.",
256
+ repair_head_sha: dispatch.pullRequest.headSha,
257
+ repair_issue_key: dispatch.pullRequest.reviewIssueKey,
258
+ dispositions: actionable.map(finding => ({
259
+ claim_id: finding.claimId,
260
+ kind: finding.kind,
261
+ body_sha256: finding.bodySha256,
262
+ disposition: "needs_decision",
263
+ evidence: "The deterministic provider cannot evaluate semantic review feedback."
264
+ })),
265
+ changed_files: [],
266
+ validation: []
267
+ });
268
+ repairArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "comment_repair");
269
+ if (!repairArtifact)
270
+ throw new Error("Deterministic comment repair did not produce its completion artifact.");
271
+ await emitCompletionArtifactRecorded(context.emit, worktree.worktreePath, repairArtifact);
272
+ }
273
+ await commitWorktreeChanges(this.git, worktree.worktreePath, dispatch.workItem.id);
274
+ await context.emit(buildProviderUsageEvent(dispatch, estimatedDeterministicUsage()));
275
+ await context.emit({
276
+ role: "assistant",
277
+ kind: "message",
278
+ content: repairChecks
279
+ ? `Deterministic CI repair completed for ${worktree.branchName}.`
280
+ : addressComments
281
+ ? `Deterministic PR comment addressing completed for ${worktree.branchName}.`
282
+ : `Deterministic conflict resolve completed for ${worktree.branchName}.`,
283
+ eventType: repairChecks ? "pr_checks_complete" : addressComments ? "pr_comments_complete" : "conflict_resolve_complete"
284
+ });
285
+ return {
286
+ summary: repairChecks
287
+ ? `forge-bridge repaired PR checks for ${worktree.branchName}.`
288
+ : addressComments
289
+ ? `forge-bridge addressed PR comments for ${worktree.branchName}.`
290
+ : `forge-bridge resolved conflicts for ${worktree.branchName}.`,
291
+ spec: repairSpec,
292
+ artifact: repairArtifact,
293
+ artifacts: repairArtifact ? [repairArtifact] : [],
294
+ };
295
+ }
296
+ }
297
+ function deterministicCiRepairPayload() {
298
+ const command = { command: "forge deterministic ci-repair validation", exit_code: 0, status: "pass", summary: "Deterministic CI repair fixture passed." };
299
+ return {
300
+ status: "pass",
301
+ summary: "Deterministic CI repair handoff is ready for provider checks.",
302
+ failed_checks: [{ name: "CI / deterministic", provider_state: "failure", workflow: ".github/workflows/ci.yml", job: "deterministic", step: "fixture" }],
303
+ root_cause: { classification: "test expectation mismatch", summary: "Deterministic fixture failure repaired.", evidence: ["Fixture provider reported the expected failed check."] },
304
+ changed_files: [],
305
+ no_code_action: { action: "deterministic_fixture", reason: "The deterministic provider models the repair without a product diff." },
306
+ narrow_validation: [command],
307
+ workflow_validation: [{ step: "deterministic fixture", equivalence: "supported", command: command.command, exit_code: 0, status: "pass", summary: command.summary }],
308
+ broader_validation: [command],
309
+ remaining_risks: [],
310
+ provider_state: "ready_for_rerun",
311
+ ready_for_push: true,
312
+ };
313
+ }
314
+ function deterministicDraftPayload(dispatch) {
315
+ const kind = dispatch.draft?.kind ?? "work_item";
316
+ if (kind === "work_order_decomposition") {
317
+ return {
318
+ summary: "Fake decompose proposed a Feature DAG for the Work Order.",
319
+ blockedReason: "",
320
+ candidates: [
321
+ {
322
+ origin: "agent",
323
+ key: "intake-submission",
324
+ title: "Customer intake submission",
325
+ summary: "Collect, validate, de-duplicate, and confirm incoming customer requests.",
326
+ planningPacket: "# Customer intake submission\n\nPlan Stories for request form validation, attachment support, duplicate prevention, and submission confirmation.",
327
+ sortOrder: 10,
328
+ dependsOn: []
329
+ },
330
+ {
331
+ origin: "agent",
332
+ key: "review-queue",
333
+ title: "Reviewer triage queue",
334
+ summary: "Provide reviewer triage, assignment, notes, status transitions, and audit trail.",
335
+ planningPacket: "# Reviewer triage queue\n\nPlan Stories for queue filtering, assignment, reviewer notes, status changes, and immutable audit trail.",
336
+ sortOrder: 20,
337
+ dependsOn: ["intake-submission"]
338
+ }
339
+ ]
340
+ };
341
+ }
342
+ if (kind === "feature_decomposition") {
343
+ return {
344
+ summary: "Fake decompose proposed a Story DAG for the Feature.",
345
+ blockedReason: "",
346
+ candidates: [
347
+ {
348
+ origin: "agent",
349
+ key: "foundation",
350
+ title: "Build the feature foundation",
351
+ description: "Create the persistence, API, and UI shell needed by the feature.",
352
+ acceptanceCriteria: "Scenario: Foundation exists\nGiven the Feature is selected\nWhen the foundation is delivered\nThen downstream Stories can build on stable contracts",
353
+ points: 3,
354
+ sortOrder: 10,
355
+ dependsOn: []
356
+ },
357
+ {
358
+ origin: "agent",
359
+ key: "workflow-behavior",
360
+ title: "Implement the primary workflow behavior",
361
+ description: "Implement the main user-visible behavior for the feature after the foundation is ready.",
362
+ acceptanceCriteria: "Scenario: Workflow behavior works\nGiven the foundation Story is complete\nWhen the user performs the primary workflow\nThen the expected state change and feedback are visible",
363
+ points: 5,
364
+ sortOrder: 20,
365
+ dependsOn: ["foundation"]
366
+ },
367
+ {
368
+ origin: "agent",
369
+ key: "audit-and-tests",
370
+ title: "Add audit coverage and regression tests",
371
+ description: "Add audit/evidence behavior and automated regression coverage for the feature.",
372
+ acceptanceCriteria: "Scenario: Feature is verifiable\nGiven the workflow behavior is complete\nWhen validation runs\nThen audit evidence and tests cover the expected outcomes",
373
+ points: 3,
374
+ sortOrder: 30,
375
+ dependsOn: ["workflow-behavior"]
376
+ }
377
+ ]
378
+ };
379
+ }
380
+ if (kind === "work_order") {
381
+ return {
382
+ title: "Deterministic runner Work Order draft",
383
+ summary: "Forge Runner generated this deterministic Work Order draft.",
384
+ objective: "Validate runner-backed Draft generation.",
385
+ planningPacket: "Runner-backed draft generation returned a Work Order JSON payload.",
386
+ decompositionContext: "Use this deterministic fixture only in bridge tests.",
387
+ assumptions: ["Forge Runner dispatch is available."],
388
+ warnings: []
389
+ };
390
+ }
391
+ if (kind === "story") {
392
+ return {
393
+ title: "Deterministic runner Story draft",
394
+ description: "Forge Runner generated this deterministic Story draft.",
395
+ acceptanceCriteria: "Given runner-backed Draft generation, when Forge requests a Story draft, then JSON is returned.",
396
+ points: 3
397
+ };
398
+ }
399
+ return {
400
+ title: "Deterministic runner Work Item draft",
401
+ description: "Forge Runner generated this deterministic Work Item draft.",
402
+ acceptanceCriteria: "Given runner-backed Draft generation, when Forge requests a draft, then JSON is returned.",
403
+ reproSteps: "Run Draft with a Forge Runner provider selected.",
404
+ systemInfo: "forge-bridge deterministic provider",
405
+ points: 1
406
+ };
407
+ }
@@ -0,0 +1,89 @@
1
+ import type { GitClient } from "../../shared/git/git.js";
2
+ import { ForgeFailureError } from "../session.types.js";
3
+ /**
4
+ * Publication guards for a provider-run `git merge --no-commit` that Forge Bridge
5
+ * turns into the final merge commit (the conflict-resolve lane, and any repair
6
+ * lane that merges the target branch).
7
+ *
8
+ * Forge stages with `git add -A` and then unstages worktree-local runtime paths
9
+ * such as `.forge` and `.local`. Unstaging resets those paths to HEAD, which is
10
+ * the story side of the merge. Without these guards that silently reverted every
11
+ * upstream change under those paths and re-added files the target branch had
12
+ * deleted (issue #491: 253 files on story/829e1219ee16 and story/6ac8c6c6e704).
13
+ */
14
+ type GitRunner = Pick<GitClient, "run">;
15
+ export interface InProgressMerge {
16
+ readonly headSha: string;
17
+ readonly mergeHeadSha: string;
18
+ readonly mergeBaseSha: string;
19
+ }
20
+ export interface MergeResolutionReport {
21
+ /**
22
+ * Paths the target branch deleted that the story had changed and that the
23
+ * resolution keeps. These are deliberate modify/delete decisions, recorded in
24
+ * the merge commit message so reviewers see them.
25
+ */
26
+ readonly keptOverUpstreamDeletion: readonly string[];
27
+ }
28
+ export type UnresolvedMergeConflictKind = "deleted_by_upstream" | "deleted_by_story" | "missing_while_unmerged" | "unresolved_binary" | "conflict_markers";
29
+ export interface UnresolvedMergeConflict {
30
+ readonly path: string;
31
+ readonly kind: UnresolvedMergeConflictKind;
32
+ }
33
+ /**
34
+ * The publication would re-add files that the target branch deleted, or revert
35
+ * target-branch edits, on paths the story never changed. Forge refuses to commit
36
+ * or push such a merge.
37
+ */
38
+ export declare class MergeResolutionRevertsUpstreamChangesError extends ForgeFailureError {
39
+ readonly merge: InProgressMerge;
40
+ readonly resurrectedPaths: readonly string[];
41
+ readonly revertedPaths: readonly string[];
42
+ readonly code = "merge_resolution_reverts_upstream_changes";
43
+ constructor(merge: InProgressMerge, resurrectedPaths: readonly string[], revertedPaths: readonly string[]);
44
+ }
45
+ /**
46
+ * A conflict is still unresolved when Forge would stage the merge: a
47
+ * modify/delete conflict nobody decided (`git add -A` would silently keep the
48
+ * modified side), or a content conflict whose file still has conflict markers
49
+ * (`git add -A` would commit them).
50
+ */
51
+ export declare class MergeResolutionUnresolvedConflictError extends ForgeFailureError {
52
+ readonly conflicts: readonly UnresolvedMergeConflict[];
53
+ readonly code = "merge_resolution_unresolved_conflict";
54
+ constructor(conflicts: readonly UnresolvedMergeConflict[]);
55
+ }
56
+ /** True while MERGE_HEAD exists, whether or not the histories share a merge base. */
57
+ export declare function isMergeInProgress(git: GitRunner, worktreePath: string): Promise<boolean>;
58
+ export declare function readInProgressMerge(git: GitRunner, worktreePath: string): Promise<InProgressMerge | null>;
59
+ /**
60
+ * Fails before `git add -A` can silently resolve a conflict:
61
+ * - a modify/delete conflict, by keeping whatever is on disk;
62
+ * - a binary (or other marker-less) conflict, by staging whichever side is on disk;
63
+ * - a content conflict, by staging its conflict markers. This includes markers
64
+ * the provider already staged, which clears the unmerged stages, so every path
65
+ * both sides changed is checked too.
66
+ * A text conflict the agent resolved in the working tree without `git add` is
67
+ * still unmerged here and is accepted once its markers are gone.
68
+ */
69
+ export declare function assertNoUnresolvedMergeConflicts(git: GitRunner, worktreePath: string): Promise<void>;
70
+ export declare function readUnresolvedMergeConflicts(git: GitRunner, worktreePath: string, merge: InProgressMerge): Promise<readonly UnresolvedMergeConflict[]>;
71
+ /**
72
+ * Staging excludes some worktree changes (Forge runtime output) by unstaging them
73
+ * back to HEAD. During a merge HEAD is the story side, so an excluded path the merge
74
+ * itself changed would lose the target's change. Given the excluded candidate
75
+ * paths, put the merge-owned ones back into the index: the target branch's version
76
+ * where the story never touched the path, and the agent's working-tree resolution
77
+ * where both sides changed it. Returns the restored paths; the rest stay excluded.
78
+ */
79
+ export declare function restoreMergeOwnedPaths(git: GitRunner, worktreePath: string, candidatePaths: readonly string[]): Promise<readonly string[]>;
80
+ /**
81
+ * Final check on the index Forge is about to commit. Throws when the merge
82
+ * resolution re-adds a path the target branch deleted, or drops a target-branch
83
+ * edit, on a path the story never changed.
84
+ */
85
+ export declare function assertMergeResolutionPreservesUpstreamChanges(git: GitRunner, worktreePath: string, options?: {
86
+ readonly ignorePath?: (filePath: string) => boolean;
87
+ }): Promise<MergeResolutionReport>;
88
+ export declare function mergeResolutionCommitNotes(report: MergeResolutionReport): readonly string[];
89
+ export {};