@loucompanion/forge-bridge 0.1.4-dev.63db04bcffca → 0.1.4-dev.800627ea0931
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.
- package/README.md +54 -2
- package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
- package/dist/bridge/bridge-chat-provider-command.js +125 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +85 -3
- package/dist/bridge/bridge.service.js +361 -122
- package/dist/bridge/bridge.types.d.ts +22 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/runner-host-capabilities.d.ts +2 -0
- package/dist/bridge/runner-host-capabilities.js +4 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +72 -109
- package/dist/cleanup/cleanup.types.d.ts +4 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +18 -0
- package/dist/cli/cli.service.d.ts +16 -0
- package/dist/cli/cli.service.js +142 -16
- package/dist/cli/local-config.d.ts +4 -0
- package/dist/cli/local-config.js +26 -4
- package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
- package/dist/runtime/attempt-process-supervisor.d.ts +19 -0
- package/dist/runtime/attempt-process-supervisor.js +50 -0
- package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
- package/dist/runtime/host-database-capability-boundary.js +1 -0
- package/dist/runtime/host-facts.d.ts +35 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-load-admission.d.ts +64 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +184 -0
- package/dist/runtime/host-load-governor.js +632 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +185 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +78 -0
- package/dist/runtime/host-load-sampler.d.ts +126 -0
- package/dist/runtime/host-load-sampler.js +232 -0
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- package/dist/runtime/host-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +4 -0
- package/dist/runtime/host-runtime-contract.js +6 -1
- package/dist/runtime/host-runtime-lease.d.ts +74 -4
- package/dist/runtime/host-runtime-lease.js +336 -20
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +48 -0
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +607 -0
- package/dist/runtime/playwright-browser-cache.d.ts +39 -0
- package/dist/runtime/playwright-browser-cache.js +227 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +18 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
- package/dist/runtime/runner-settings.d.ts +100 -0
- package/dist/runtime/runner-settings.js +214 -0
- package/dist/sandbox/host-capacity-broker.d.ts +113 -0
- package/dist/sandbox/host-capacity-broker.js +334 -0
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +45 -2
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/session/managed-attempt-tools.d.ts +27 -0
- package/dist/session/managed-attempt-tools.js +356 -41
- package/dist/session/managed-build-coordinator.d.ts +1 -1
- package/dist/session/managed-build-coordinator.js +4 -1
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +7 -0
- package/dist/session/phase-completion.artifacts.js +98 -25
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +4 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +4 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -3
- package/dist/session/phase-completion.runtime.js +70 -35
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +206 -221
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +46 -92
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +60 -0
- package/dist/session/pre-publication-pass.js +145 -0
- package/dist/session/pre-publication-process.d.ts +23 -0
- package/dist/session/pre-publication-process.js +109 -0
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- package/dist/session/pre-publication-step-execution.d.ts +11 -0
- package/dist/session/pre-publication-step-execution.js +49 -0
- package/dist/session/pre-publication-validation.d.ts +30 -20
- package/dist/session/pre-publication-validation.js +173 -192
- package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
- package/dist/session/provider-cli/claude-background-work.js +180 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
- package/dist/session/provider-cli/pre-publication-repair.js +243 -0
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
- package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +39 -2
- package/dist/session/provider-cli/provider-cli.process.js +276 -42
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +65 -10
- package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +203 -172
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +8 -0
- package/dist/session/provider-cli/provider-output-state.js +15 -0
- package/dist/session/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +231 -0
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +9 -2
- package/dist/session/session.service.js +120 -5
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +15 -3
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/process/host-process-supervisor.d.ts +1 -0
- package/dist/shared/process/host-process-supervisor.js +1 -1
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +67 -0
- package/dist/shared/process/process.js +213 -11
- package/dist/shared/provider-capabilities.js +5 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -10
- package/dist/worktree/worktree.service.d.ts +10 -1
- package/dist/worktree/worktree.service.js +42 -2
- package/dist/worktree/worktree.types.d.ts +7 -0
- package/package.json +2 -2
|
@@ -2,20 +2,22 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { RepositoryCoordinatorLock } from "../../sandbox/repository-lock.js";
|
|
4
4
|
import { GitClient } from "../../shared/git/git.js";
|
|
5
|
+
import { sandboxHostLoadGateFromEnvironment } from "../sandbox-host-capacity-gate.js";
|
|
5
6
|
import { buildSpecBody, selectLaneCommand } from "../../worktree/artifact-injector.js";
|
|
6
7
|
import { defaultWorktreeCoordinatorStateRoot } from "../../worktree/worktree-paths.js";
|
|
7
8
|
import { completionPhaseFromDispatch, prepareCompletionToolRuntime, readCompletionArtifact, usesDebugCycleCompletion, usesDevelopCycleCompletion } from "../phase-completion.js";
|
|
8
9
|
import { ForgeFailureError } from "../session.types.js";
|
|
9
|
-
import { cleanupCompletionTools, commitWorktreeChanges, completionPhaseFromArtifact, emitArchitectStructuredEvents, emitCompletionArtifactRecorded, emitDecomposeGateArtifacts, emitDraftGateArtifacts, emitPhaseCompletionEvent, emitPhaseGateEvents, emitQaArtifactRecorded, emitQaStructuredEvents, enforceQaBrowserLaunchTargetGate, LiveArchitectArtifactEmitter, LiveCompletionArtifactEmitter, LiveQaArtifactEmitter, readCompletionArtifactsForRun, readQaCompletionArtifactBundle,
|
|
10
|
+
import { cleanupCompletionTools, commitWorktreeChanges, completionPhaseFromArtifact, emitArchitectStructuredEvents, emitCompletionArtifactRecorded, emitDecomposeGateArtifacts, emitDraftGateArtifacts, emitPhaseCompletionEvent, emitPhaseGateEvents, emitQaArtifactRecorded, emitQaStructuredEvents, enforceQaBrowserLaunchTargetGate, LiveArchitectArtifactEmitter, LiveCompletionArtifactEmitter, LiveQaArtifactEmitter, readCompletionArtifactsForRun, readQaCompletionArtifactBundle, waitForCompletionArtifact } from "./provider-cli.artifacts.js";
|
|
11
|
+
import { diffClaimedChangedFiles, findUnpublishedWorktreePaths, normalizeChangedFilePath, stagePublishableWorktreeChangeSet, } from "../publishable-worktree-changes.js";
|
|
10
12
|
import { DeterministicProviderCliService } from "./provider-cli.deterministic.js";
|
|
11
13
|
import { buildArchitectPrompt, buildConflictResolvePrompt, buildDebugCyclePrompt, buildDevelopCyclePrompt, buildDraftPrompt, buildDraftSpec, buildImplementationPrompt, buildProviderCliPrompt, buildProviderCliCommand, durableDraftInput, buildPullRequestCheckRepairPrompt, buildPullRequestCommentsPrompt, buildQaPrompt, formatProviderCliCommandForCheckpoint, isDecomposeDraftDispatch, isPullRequestCheckRepairDispatch, isPullRequestCommentsDispatch } from "./provider-cli.prompts.js";
|
|
12
|
-
import { isTransientCodexProviderNotFoundFailure, recoveringProviderProcessRunner, StreamingProviderProcessRunner } from "./provider-cli.process.js";
|
|
13
|
-
import { emitProviderUsageEvent,
|
|
14
|
-
import { clip, createProviderOutputState, parseJsonLine } from "./provider-output-state.js";
|
|
14
|
+
import { isTransientCodexProviderNotFoundFailure, providerCompletionToolMissingFailure, recoveringProviderProcessRunner, StreamingProviderProcessRunner } from "./provider-cli.process.js";
|
|
15
|
+
import { emitProviderUsageEvent, providerProcessEnv } from "./provider-cli.runtime.js";
|
|
16
|
+
import { clip, clipTail, createProviderOutputState, parseJsonLine } from "./provider-output-state.js";
|
|
15
17
|
import { writeCiRepairReadinessManifest } from "./ci-repair-readiness.js";
|
|
16
18
|
import { assertRepairHeadEpoch } from "./provider-cli.repair-epoch.js";
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
+
import { PrePublicationValidator } from "../pre-publication-validation.js";
|
|
20
|
+
import { prePublicationRepairTurnsFromEnvironment, validatePrePublicationWithRepair, } from "./pre-publication-repair.js";
|
|
19
21
|
const maxQaCompletionRecoveryTurns = 2;
|
|
20
22
|
function assertCommentRepairArtifactMatchesDispatch(dispatch, artifact) {
|
|
21
23
|
const pullRequest = dispatch.pullRequest;
|
|
@@ -68,12 +70,54 @@ function assertCommentRepairArtifactMatchesChanges(artifact, actualChangedFiles)
|
|
|
68
70
|
const claimed = [...new Set(claimedChangedFiles)].sort();
|
|
69
71
|
const actual = [...new Set(normalizedActual)].sort();
|
|
70
72
|
if (hasFixedDisposition && actual.length === 0) {
|
|
71
|
-
throw
|
|
73
|
+
throw commentRepairChangedFilesMismatch("Comment repair fixed dispositions require an actual publishable source diff.");
|
|
72
74
|
}
|
|
73
75
|
if (claimed.length !== actual.length || claimed.some((value, index) => value !== actual[index])) {
|
|
74
|
-
|
|
76
|
+
const { missing, unexpected } = diffClaimedChangedFiles(claimed, actual);
|
|
77
|
+
throw commentRepairChangedFilesMismatch(`Comment repair changed_files must exactly match the publishable staged source diff${formatChangedFilesDelta(missing, unexpected)}.`);
|
|
75
78
|
}
|
|
76
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* A finding resolved as fixed must not point at a file whose edit Forge leaves out of the
|
|
82
|
+
* published commit; otherwise the thread would be resolved without its fix. That covers
|
|
83
|
+
* runtime output Forge unstaged and untracked or git-ignored files it never stages.
|
|
84
|
+
*/
|
|
85
|
+
async function assertFixedFindingsArePublished(git, worktreePath, dispatch, artifact, changeSet) {
|
|
86
|
+
const findingPaths = new Map((dispatch.pullRequest?.reviewFindings ?? []).map(finding => [
|
|
87
|
+
`${finding.kind.trim().toLowerCase()}:${finding.claimId}:${finding.bodySha256.trim().toLowerCase()}`,
|
|
88
|
+
finding.path ? normalizeChangedFilePath(finding.path) : "",
|
|
89
|
+
]));
|
|
90
|
+
const payload = JSON.parse(artifact.verdictJson);
|
|
91
|
+
const dispositions = Array.isArray(payload.dispositions) ? payload.dispositions : [];
|
|
92
|
+
const fixed = dispositions.flatMap(value => {
|
|
93
|
+
const record = value;
|
|
94
|
+
if (record.disposition !== "fixed")
|
|
95
|
+
return [];
|
|
96
|
+
const identity = `${String(record.kind ?? "").trim().toLowerCase()}:${String(record.claim_id ?? "")}:${String(record.body_sha256 ?? "").trim().toLowerCase()}`;
|
|
97
|
+
const findingPath = findingPaths.get(identity);
|
|
98
|
+
return findingPath ? [{ claimId: String(record.claim_id ?? ""), path: findingPath }] : [];
|
|
99
|
+
});
|
|
100
|
+
if (fixed.length === 0)
|
|
101
|
+
return;
|
|
102
|
+
const unpublished = new Set([
|
|
103
|
+
...changeSet.excluded.map(normalizeChangedFilePath),
|
|
104
|
+
...await findUnpublishedWorktreePaths(git, worktreePath, fixed.map(entry => entry.path), changeSet.publishable),
|
|
105
|
+
]);
|
|
106
|
+
const dropped = fixed.filter(entry => unpublished.has(entry.path)).map(entry => `${entry.claimId} (${entry.path})`);
|
|
107
|
+
if (dropped.length > 0) {
|
|
108
|
+
throw commentRepairChangedFilesMismatch(`Comment repair marked ${dropped.join(", ")} fixed, but Forge does not publish that file (runtime output, untracked, or git-ignored); Forge did not publish or resolve review findings.`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function commentRepairChangedFilesMismatch(message) {
|
|
112
|
+
return new ForgeFailureError("comment_repair_changed_files_mismatch", message);
|
|
113
|
+
}
|
|
114
|
+
function formatChangedFilesDelta(missing, unexpected) {
|
|
115
|
+
const parts = [
|
|
116
|
+
missing.length > 0 ? `missing from changed_files: ${missing.join(", ")}` : "",
|
|
117
|
+
unexpected.length > 0 ? `not in the publishable diff: ${unexpected.join(", ")}` : "",
|
|
118
|
+
].filter(Boolean);
|
|
119
|
+
return parts.length > 0 ? ` (${parts.join("; ")})` : "";
|
|
120
|
+
}
|
|
77
121
|
async function finalizeCommentRepairChangedFiles(artifact, baselineChangedFiles, actualChangedFiles) {
|
|
78
122
|
const payload = JSON.parse(artifact.verdictJson);
|
|
79
123
|
const claimedRecords = Array.isArray(payload.changed_files)
|
|
@@ -90,11 +134,11 @@ async function finalizeCommentRepairChangedFiles(artifact, baselineChangedFiles,
|
|
|
90
134
|
const dispositions = Array.isArray(payload.dispositions) ? payload.dispositions : [];
|
|
91
135
|
const hasFixedDisposition = dispositions.some(value => value.disposition === "fixed");
|
|
92
136
|
if (hasFixedDisposition && authoritativePaths.length === 0) {
|
|
93
|
-
throw
|
|
137
|
+
throw commentRepairChangedFilesMismatch("Comment repair fixed dispositions require an actual publishable source diff.");
|
|
94
138
|
}
|
|
95
139
|
for (const baselinePath of baselineChangedFiles.map(value => value.trim().replaceAll("\\", "/"))) {
|
|
96
140
|
if (baselinePath && !authoritative.has(baselinePath)) {
|
|
97
|
-
throw
|
|
141
|
+
throw commentRepairChangedFilesMismatch(`Comment repair pre-publication repair removed '${baselinePath}' from the publishable staged source diff.`);
|
|
98
142
|
}
|
|
99
143
|
}
|
|
100
144
|
payload.changed_files = authoritativePaths.map(filePath => {
|
|
@@ -169,18 +213,6 @@ async function pushWorktreeBranch(git, worktreePath, branchName, repoPath, coord
|
|
|
169
213
|
function providerOwnsBranchPublication(context) {
|
|
170
214
|
return context.dispatch.sandbox?.executionMode !== "docker";
|
|
171
215
|
}
|
|
172
|
-
function prePublicationExecution(context, environment, defaultRunner, baselineRevision) {
|
|
173
|
-
if (context.processRunner)
|
|
174
|
-
return { baselineRevision, environment, processRunner: context.processRunner };
|
|
175
|
-
if (context.dispatch.sandbox?.executionMode !== "docker")
|
|
176
|
-
return { baselineRevision, environment };
|
|
177
|
-
const expectedSandboxId = context.dispatch.sandbox.dispatchAttemptId;
|
|
178
|
-
const observedSandboxId = context.runtimeEnvironment?.FORGE_SANDBOX_ID ?? process.env.FORGE_SANDBOX_ID;
|
|
179
|
-
if (observedSandboxId !== expectedSandboxId) {
|
|
180
|
-
throw new ForgeFailureError("prepublication_execution_scope_invalid", `prepublication_execution_scope_invalid: Docker attempt ${expectedSandboxId} has no runner proven to execute inside that sandbox.`, "bridge");
|
|
181
|
-
}
|
|
182
|
-
return { baselineRevision, environment, processRunner: defaultRunner };
|
|
183
|
-
}
|
|
184
216
|
function remoteTrackingRefspec(branchName) {
|
|
185
217
|
return `refs/heads/${branchName}:refs/remotes/origin/${branchName}`;
|
|
186
218
|
}
|
|
@@ -215,11 +247,6 @@ function providerCliExitFailure(command, result) {
|
|
|
215
247
|
}
|
|
216
248
|
return new Error(`${command} exited ${result.exitCode}${suffix}`);
|
|
217
249
|
}
|
|
218
|
-
function clipTail(value, maximumLength) {
|
|
219
|
-
if (value.length <= maximumLength)
|
|
220
|
-
return value;
|
|
221
|
-
return `...${value.slice(-(maximumLength - 3))}`;
|
|
222
|
-
}
|
|
223
250
|
/**
|
|
224
251
|
* Capacity is trusted only when a nonzero provider process writes one of the
|
|
225
252
|
* narrow service-level messages to stderr. Stdout can contain arbitrary agent
|
|
@@ -389,7 +416,8 @@ export class ManagedVerificationProgressEmitter {
|
|
|
389
416
|
}
|
|
390
417
|
}
|
|
391
418
|
function isManagedVerificationNonterminal(status) {
|
|
392
|
-
return status === "starting" || status === "running" || status === "waiting_for_build_slot"
|
|
419
|
+
return status === "starting" || status === "running" || status === "waiting_for_build_slot"
|
|
420
|
+
|| status === "waiting_for_host_capacity";
|
|
393
421
|
}
|
|
394
422
|
async function parseManagedVerificationSnapshot(receiptPath) {
|
|
395
423
|
try {
|
|
@@ -429,10 +457,17 @@ class ProviderToolActivityHeartbeat {
|
|
|
429
457
|
emit;
|
|
430
458
|
intervalMs;
|
|
431
459
|
timer = null;
|
|
460
|
+
/** Lets the provider runner hold its end-of-turn timers while a tool call is in flight. */
|
|
461
|
+
isToolCallInFlight = () => this.outputState.hasActiveToolCall;
|
|
462
|
+
/** Forgets tool calls a previous generation left open; called before every relaunch. */
|
|
463
|
+
startGeneration = () => this.outputState.resetActiveToolCalls();
|
|
432
464
|
constructor(outputState, emit, intervalMs) {
|
|
433
465
|
this.outputState = outputState;
|
|
434
466
|
this.emit = emit;
|
|
435
467
|
this.intervalMs = intervalMs;
|
|
468
|
+
// Each heartbeat watches one provider generation. Calls an earlier generation left
|
|
469
|
+
// open died with it; inheriting them would hold the new generation's timers forever.
|
|
470
|
+
this.outputState.resetActiveToolCalls();
|
|
436
471
|
}
|
|
437
472
|
async consume(line) {
|
|
438
473
|
const events = this.outputState.consume(line);
|
|
@@ -514,12 +549,19 @@ export class ProcessBackedProviderCliService {
|
|
|
514
549
|
providerToolHeartbeatIntervalMs;
|
|
515
550
|
publicationCoordinator;
|
|
516
551
|
prePublicationValidator;
|
|
517
|
-
|
|
552
|
+
prePublicationRepairTurns;
|
|
553
|
+
constructor(processRunner = new StreamingProviderProcessRunner(), git = new GitClient(), providerToolHeartbeatIntervalMs = defaultProviderToolHeartbeatIntervalMs, publicationCoordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
554
|
+
// The Docker sandbox worker (`forge` run-once via ForgeBridgeCliService) builds
|
|
555
|
+
// this default. A container cannot reach the host ledger, so when the host
|
|
556
|
+
// bridge enabled it, its steps ask the bridge for tokens over the sandbox
|
|
557
|
+
// channel (decision 0013); elsewhere the gate is absent and validation is ungated.
|
|
558
|
+
prePublicationValidator = new PrePublicationValidator(undefined, undefined, undefined, sandboxHostLoadGateFromEnvironment()), prePublicationRepairTurns = prePublicationRepairTurnsFromEnvironment()) {
|
|
518
559
|
this.processRunner = processRunner;
|
|
519
560
|
this.git = git;
|
|
520
561
|
this.providerToolHeartbeatIntervalMs = providerToolHeartbeatIntervalMs;
|
|
521
562
|
this.publicationCoordinator = publicationCoordinator;
|
|
522
563
|
this.prePublicationValidator = prePublicationValidator;
|
|
564
|
+
this.prePublicationRepairTurns = prePublicationRepairTurns;
|
|
523
565
|
}
|
|
524
566
|
async runDraft(context) {
|
|
525
567
|
const { dispatch } = context;
|
|
@@ -533,7 +575,7 @@ export class ProcessBackedProviderCliService {
|
|
|
533
575
|
await fs.writeFile(path.join(metadataRoot, "spec.md"), buildDraftSpec(dispatch), "utf8");
|
|
534
576
|
const stagedAttachments = await stageDraftAttachments(dispatch, metadataRoot);
|
|
535
577
|
const decomposeDraft = isDecomposeDraftDispatch(dispatch);
|
|
536
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: decomposeDraft ? "decompose" : "draft", runtimeEnvironment: context.runtimeEnvironment });
|
|
578
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: decomposeDraft ? "decompose" : "draft", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
537
579
|
const draftPrompt = buildDraftPrompt(dispatch, { attachmentReferences: stagedAttachments.textReferences });
|
|
538
580
|
const providerPrompt = buildProviderCliPrompt(dispatch, draftPrompt, context.runtimeEnvironment);
|
|
539
581
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -586,6 +628,7 @@ export class ProcessBackedProviderCliService {
|
|
|
586
628
|
args: command.args,
|
|
587
629
|
cwd: worktree.worktreePath,
|
|
588
630
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
631
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
589
632
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
590
633
|
}, {
|
|
591
634
|
onStarted: async () => {
|
|
@@ -596,6 +639,8 @@ export class ProcessBackedProviderCliService {
|
|
|
596
639
|
eventType: "provider_cli_started"
|
|
597
640
|
});
|
|
598
641
|
},
|
|
642
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
643
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
599
644
|
onStdoutLine: async (line) => {
|
|
600
645
|
await toolHeartbeat.consume(line);
|
|
601
646
|
}
|
|
@@ -645,7 +690,7 @@ export class ProcessBackedProviderCliService {
|
|
|
645
690
|
await emitDecomposeGateArtifacts(context.emit, worktree.worktreePath, dispatch.workItem.id);
|
|
646
691
|
const proposalArtifact = earlyProposalArtifact ?? await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "decompose");
|
|
647
692
|
if (!proposalArtifact) {
|
|
648
|
-
throw
|
|
693
|
+
throw providerCompletionToolMissingFailure("Provider CLI Decompose completed but did not call forge.complete_decompose_proposal.", result);
|
|
649
694
|
}
|
|
650
695
|
const proposal = parseJsonLine(proposalArtifact.verdictJson) ?? {};
|
|
651
696
|
const proposalJson = proposal["proposal_json"] ?? proposal["decomposition_json"];
|
|
@@ -668,7 +713,7 @@ export class ProcessBackedProviderCliService {
|
|
|
668
713
|
await emitDraftGateArtifacts(context.emit, worktree.worktreePath, dispatch.workItem.id);
|
|
669
714
|
const proposalArtifact = earlyProposalArtifact ?? await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "draft");
|
|
670
715
|
if (!proposalArtifact) {
|
|
671
|
-
throw
|
|
716
|
+
throw providerCompletionToolMissingFailure("Provider CLI Draft completed but did not call forge.complete_draft_proposal.", result);
|
|
672
717
|
}
|
|
673
718
|
const proposal = parseJsonLine(proposalArtifact.verdictJson) ?? {};
|
|
674
719
|
const draftJson = proposal["draft_json"];
|
|
@@ -713,7 +758,7 @@ export class ProcessBackedProviderCliService {
|
|
|
713
758
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
714
759
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
715
760
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" }) + "\n", "utf8");
|
|
716
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase, runtimeEnvironment: context.runtimeEnvironment });
|
|
761
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase, runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
717
762
|
const implementationPrompt = debugCycle
|
|
718
763
|
? buildDebugCyclePrompt(dispatch, phase)
|
|
719
764
|
: developCycle
|
|
@@ -755,6 +800,7 @@ export class ProcessBackedProviderCliService {
|
|
|
755
800
|
args: command.args,
|
|
756
801
|
cwd: worktree.worktreePath,
|
|
757
802
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
803
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
758
804
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
759
805
|
}, {
|
|
760
806
|
onStarted: async () => {
|
|
@@ -765,6 +811,8 @@ export class ProcessBackedProviderCliService {
|
|
|
765
811
|
eventType: "provider_cli_started"
|
|
766
812
|
});
|
|
767
813
|
},
|
|
814
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
815
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
768
816
|
onStdoutLine: async (line) => {
|
|
769
817
|
await toolHeartbeat.consume(line);
|
|
770
818
|
}
|
|
@@ -775,9 +823,8 @@ export class ProcessBackedProviderCliService {
|
|
|
775
823
|
await liveCompletionEvents.stop();
|
|
776
824
|
await cleanupCompletionTools(completionTools, context.emit);
|
|
777
825
|
}
|
|
778
|
-
if (result.exitCode !== 0)
|
|
826
|
+
if (result.exitCode !== 0)
|
|
779
827
|
throw providerCliExitFailure(command.command, result);
|
|
780
|
-
}
|
|
781
828
|
await context.emit({
|
|
782
829
|
role: "runner",
|
|
783
830
|
kind: "checkpoint",
|
|
@@ -806,7 +853,7 @@ export class ProcessBackedProviderCliService {
|
|
|
806
853
|
eventType: "worktree_branch_pushed"
|
|
807
854
|
});
|
|
808
855
|
}
|
|
809
|
-
const completionArtifacts = await readCompletionArtifactsForRun(worktree.worktreePath, dispatch.workItem.id, phase, developCycle, debugCycle);
|
|
856
|
+
const completionArtifacts = await readCompletionArtifactsForRun(worktree.worktreePath, dispatch.workItem.id, phase, developCycle, debugCycle, result);
|
|
810
857
|
for (const artifact of completionArtifacts) {
|
|
811
858
|
if (!liveCompletionEvents.hasEmitted(completionPhaseFromArtifact(artifact))) {
|
|
812
859
|
await emitCompletionArtifactRecorded(context.emit, worktree.worktreePath, artifact);
|
|
@@ -858,7 +905,7 @@ export class ProcessBackedProviderCliService {
|
|
|
858
905
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
859
906
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
860
907
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), JSON.stringify({ schema_version: 1, status: "pending_approval", produced_by: "forge-lane-command" }) + "\n", "utf8");
|
|
861
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "architect", runtimeEnvironment: context.runtimeEnvironment });
|
|
908
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "architect", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
862
909
|
const architectPrompt = buildArchitectPrompt(dispatch);
|
|
863
910
|
const providerPrompt = buildProviderCliPrompt(dispatch, architectPrompt, context.runtimeEnvironment);
|
|
864
911
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -893,6 +940,7 @@ export class ProcessBackedProviderCliService {
|
|
|
893
940
|
args: command.args,
|
|
894
941
|
cwd: worktree.worktreePath,
|
|
895
942
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
943
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
896
944
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
897
945
|
}, {
|
|
898
946
|
onStarted: async () => {
|
|
@@ -903,6 +951,8 @@ export class ProcessBackedProviderCliService {
|
|
|
903
951
|
eventType: "provider_cli_started"
|
|
904
952
|
});
|
|
905
953
|
},
|
|
954
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
955
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
906
956
|
onStdoutLine: async (line) => await toolHeartbeat.consume(line)
|
|
907
957
|
}, context.signal);
|
|
908
958
|
}
|
|
@@ -923,7 +973,7 @@ export class ProcessBackedProviderCliService {
|
|
|
923
973
|
await emitProviderUsageEvent(context.emit, dispatch, outputState);
|
|
924
974
|
const architectArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "architect");
|
|
925
975
|
if (!architectArtifact) {
|
|
926
|
-
throw
|
|
976
|
+
throw providerCompletionToolMissingFailure("Provider CLI Architect completed but did not call the Forge Architect completion tool.", result);
|
|
927
977
|
}
|
|
928
978
|
if (!liveArchitectEvents.hasEmitted()) {
|
|
929
979
|
await emitCompletionArtifactRecorded(context.emit, worktree.worktreePath, architectArtifact);
|
|
@@ -960,7 +1010,7 @@ export class ProcessBackedProviderCliService {
|
|
|
960
1010
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
961
1011
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
962
1012
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" }) + "\n", "utf8");
|
|
963
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "qa", runtimeEnvironment: context.runtimeEnvironment });
|
|
1013
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "qa", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
964
1014
|
const qaPrompt = buildQaPrompt(dispatch, specBody);
|
|
965
1015
|
const providerPrompt = buildProviderCliPrompt(dispatch, qaPrompt, context.runtimeEnvironment);
|
|
966
1016
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -997,6 +1047,7 @@ export class ProcessBackedProviderCliService {
|
|
|
997
1047
|
args: command.args,
|
|
998
1048
|
cwd: worktree.worktreePath,
|
|
999
1049
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
1050
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
1000
1051
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
1001
1052
|
}, {
|
|
1002
1053
|
onStarted: async () => {
|
|
@@ -1007,6 +1058,8 @@ export class ProcessBackedProviderCliService {
|
|
|
1007
1058
|
eventType: "provider_cli_started"
|
|
1008
1059
|
});
|
|
1009
1060
|
},
|
|
1061
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1062
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1010
1063
|
onStdoutLine: async (line) => await toolHeartbeat.consume(line)
|
|
1011
1064
|
}, context.signal);
|
|
1012
1065
|
}
|
|
@@ -1026,17 +1079,19 @@ export class ProcessBackedProviderCliService {
|
|
|
1026
1079
|
eventType: "provider_cli_completed"
|
|
1027
1080
|
});
|
|
1028
1081
|
await emitProviderUsageEvent(context.emit, dispatch, outputState);
|
|
1082
|
+
const lastRun = { result };
|
|
1029
1083
|
let qaArtifact = await readQaCompletionArtifactBundle(worktree.worktreePath, dispatch.workItem.id, dispatch.cycleRun.ownerType, dispatch.cycleRun.ownerId);
|
|
1030
1084
|
if (!qaArtifact && !(await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "qa"))) {
|
|
1031
1085
|
// A headless provider that ends its turn to "wait for a background watcher"
|
|
1032
1086
|
// exits for good. Resume the same thread instead of failing the session.
|
|
1033
|
-
qaArtifact = await this.recoverMissingQaCompletion({ context, outputState });
|
|
1087
|
+
qaArtifact = await this.recoverMissingQaCompletion({ context, outputState, lastRun });
|
|
1034
1088
|
}
|
|
1035
1089
|
if (!qaArtifact) {
|
|
1036
1090
|
const verdictOnly = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "qa");
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1091
|
+
if (verdictOnly) {
|
|
1092
|
+
throw new Error("Provider CLI QA completed but did not produce the complete durable QA artifact bundle.");
|
|
1093
|
+
}
|
|
1094
|
+
throw providerCompletionToolMissingFailure("Provider CLI QA completed but did not call the Forge QA completion tool.", lastRun.result);
|
|
1040
1095
|
}
|
|
1041
1096
|
await enforceQaBrowserLaunchTargetGate(dispatch, qaArtifact);
|
|
1042
1097
|
if (!liveQaEvents.hasEmitted()) {
|
|
@@ -1075,6 +1130,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1075
1130
|
const addressComments = !repairChecks && isPullRequestCommentsDispatch(dispatch);
|
|
1076
1131
|
let repairSpec = null;
|
|
1077
1132
|
let repairEnvironment = context.runtimeEnvironment;
|
|
1133
|
+
let ciRepairSpecPath = null;
|
|
1078
1134
|
let completionTools = null;
|
|
1079
1135
|
if (repairChecks) {
|
|
1080
1136
|
const metadataRoot = path.join(worktree.worktreePath, ".forge", "work-items", dispatch.workItem.id);
|
|
@@ -1085,6 +1141,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1085
1141
|
}
|
|
1086
1142
|
const specBody = buildSpecBody(laneCommand, dispatch.workItem, "ci_repair");
|
|
1087
1143
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
1144
|
+
ciRepairSpecPath = specPath;
|
|
1088
1145
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
1089
1146
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), `${JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" })}\n`, "utf8");
|
|
1090
1147
|
repairSpec = {
|
|
@@ -1096,7 +1153,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1096
1153
|
};
|
|
1097
1154
|
const readiness = await writeCiRepairReadinessManifest(dispatch, worktree.worktreePath, specPath, context.runtimeEnvironment);
|
|
1098
1155
|
repairEnvironment = readiness.environment;
|
|
1099
|
-
completionTools = await prepareCompletionToolRuntime({
|
|
1156
|
+
completionTools = await prepareCompletionToolRuntime({
|
|
1157
|
+
dispatch, worktree, phase: "ci_repair", runtimeEnvironment: repairEnvironment, hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1158
|
+
});
|
|
1100
1159
|
await context.emit({
|
|
1101
1160
|
role: "runner",
|
|
1102
1161
|
kind: "checkpoint",
|
|
@@ -1111,7 +1170,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1111
1170
|
});
|
|
1112
1171
|
}
|
|
1113
1172
|
if (addressComments) {
|
|
1114
|
-
completionTools = await prepareCompletionToolRuntime({
|
|
1173
|
+
completionTools = await prepareCompletionToolRuntime({
|
|
1174
|
+
dispatch, worktree, phase: "comment_repair", runtimeEnvironment: repairEnvironment, hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1175
|
+
});
|
|
1115
1176
|
await context.emit({
|
|
1116
1177
|
role: "runner",
|
|
1117
1178
|
kind: "checkpoint",
|
|
@@ -1149,6 +1210,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1149
1210
|
args: command.args,
|
|
1150
1211
|
cwd: worktree.worktreePath,
|
|
1151
1212
|
env: providerProcessEnv(dispatch, repairEnvironment),
|
|
1213
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
1152
1214
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
1153
1215
|
}, {
|
|
1154
1216
|
onStarted: async () => {
|
|
@@ -1160,6 +1222,8 @@ export class ProcessBackedProviderCliService {
|
|
|
1160
1222
|
});
|
|
1161
1223
|
providerStarted = true;
|
|
1162
1224
|
},
|
|
1225
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1226
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1163
1227
|
onStdoutLine: async (line) => {
|
|
1164
1228
|
await toolHeartbeat.consume(line);
|
|
1165
1229
|
}
|
|
@@ -1194,7 +1258,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1194
1258
|
if (repairChecks) {
|
|
1195
1259
|
repairArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "ci_repair");
|
|
1196
1260
|
if (!repairArtifact) {
|
|
1197
|
-
throw
|
|
1261
|
+
throw providerCompletionToolMissingFailure("Provider CLI completed but did not call forge.complete_ci_repair. Forge did not commit or push the repair.", result);
|
|
1198
1262
|
}
|
|
1199
1263
|
if ((repairArtifact.status ?? "").trim().toLowerCase() !== "pass") {
|
|
1200
1264
|
throw new Error(`CI repair completion gate recorded ${repairArtifact.status}; Forge did not commit or push the repair.`);
|
|
@@ -1202,16 +1266,18 @@ export class ProcessBackedProviderCliService {
|
|
|
1202
1266
|
}
|
|
1203
1267
|
if (addressComments) {
|
|
1204
1268
|
repairArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "comment_repair");
|
|
1269
|
+
const lastRun = { result };
|
|
1205
1270
|
if (!repairArtifact) {
|
|
1206
1271
|
repairArtifact = await this.recoverMissingCommentRepairCompletion({
|
|
1207
1272
|
context,
|
|
1208
1273
|
repairEnvironment,
|
|
1209
1274
|
outputState,
|
|
1210
1275
|
preparedHeadSha,
|
|
1276
|
+
lastRun,
|
|
1211
1277
|
});
|
|
1212
1278
|
}
|
|
1213
1279
|
if (!repairArtifact) {
|
|
1214
|
-
throw
|
|
1280
|
+
throw providerCompletionToolMissingFailure("Provider CLI completed but did not call forge.complete_comment_repair. Forge did not publish or resolve review findings.", lastRun.result);
|
|
1215
1281
|
}
|
|
1216
1282
|
if ((repairArtifact.status ?? "").trim().toLowerCase() !== "pass") {
|
|
1217
1283
|
throw new Error(`Comment repair completion gate recorded ${repairArtifact.status}; Forge did not publish or resolve review findings.`);
|
|
@@ -1220,7 +1286,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1220
1286
|
}
|
|
1221
1287
|
let commentRepairBaselineChangedFiles = null;
|
|
1222
1288
|
if (addressComments && repairArtifact) {
|
|
1223
|
-
|
|
1289
|
+
const baseline = await stagePublishableWorktreeChangeSet(this.git, worktree.worktreePath);
|
|
1290
|
+
commentRepairBaselineChangedFiles = baseline.publishable;
|
|
1291
|
+
await assertFixedFindingsArePublished(this.git, worktree.worktreePath, dispatch, repairArtifact, baseline);
|
|
1224
1292
|
assertCommentRepairArtifactMatchesChanges(repairArtifact, commentRepairBaselineChangedFiles);
|
|
1225
1293
|
}
|
|
1226
1294
|
const validationProfile = repairChecks
|
|
@@ -1228,6 +1296,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1228
1296
|
: addressComments
|
|
1229
1297
|
? "comment_repair"
|
|
1230
1298
|
: "conflict_repair";
|
|
1299
|
+
const readinessSpecPath = ciRepairSpecPath;
|
|
1231
1300
|
await this.validatePrePublicationWithRecovery({
|
|
1232
1301
|
context,
|
|
1233
1302
|
validationProfile,
|
|
@@ -1235,9 +1304,15 @@ export class ProcessBackedProviderCliService {
|
|
|
1235
1304
|
outputState,
|
|
1236
1305
|
preparedHeadSha,
|
|
1237
1306
|
repairScope: "pull_request",
|
|
1307
|
+
...(readinessSpecPath ? {
|
|
1308
|
+
// The readiness manifest records the attempt URLs; a restart must not leave it pointing at the old stack.
|
|
1309
|
+
onRuntimeEnvironmentRefreshed: async (runtimeEnvironment) => (await writeCiRepairReadinessManifest(dispatch, worktree.worktreePath, readinessSpecPath, runtimeEnvironment)).environment,
|
|
1310
|
+
} : {}),
|
|
1238
1311
|
});
|
|
1239
|
-
const
|
|
1312
|
+
const stagedChangeSet = await stagePublishableWorktreeChangeSet(this.git, worktree.worktreePath);
|
|
1313
|
+
const stagedChangedFiles = stagedChangeSet.publishable;
|
|
1240
1314
|
if (addressComments && repairArtifact && commentRepairBaselineChangedFiles) {
|
|
1315
|
+
await assertFixedFindingsArePublished(this.git, worktree.worktreePath, dispatch, repairArtifact, stagedChangeSet);
|
|
1241
1316
|
repairArtifact = await finalizeCommentRepairChangedFiles(repairArtifact, commentRepairBaselineChangedFiles, stagedChangedFiles);
|
|
1242
1317
|
}
|
|
1243
1318
|
const committed = await commitWorktreeChanges(this.git, worktree.worktreePath, dispatch.workItem.id, stagedChangedFiles);
|
|
@@ -1311,6 +1386,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1311
1386
|
worktree,
|
|
1312
1387
|
phase: "qa",
|
|
1313
1388
|
runtimeEnvironment: context.runtimeEnvironment,
|
|
1389
|
+
hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1314
1390
|
});
|
|
1315
1391
|
const command = buildProviderCliCommand(recoveryDispatch, {
|
|
1316
1392
|
worktreePath: worktree.worktreePath,
|
|
@@ -1334,13 +1410,19 @@ export class ProcessBackedProviderCliService {
|
|
|
1334
1410
|
args: command.args,
|
|
1335
1411
|
cwd: worktree.worktreePath,
|
|
1336
1412
|
env: providerProcessEnv(recoveryDispatch, context.runtimeEnvironment),
|
|
1413
|
+
resumesProviderThread: Boolean(recoveryDispatch.session.resumeProviderThreadId),
|
|
1337
1414
|
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1338
|
-
}, {
|
|
1415
|
+
}, {
|
|
1416
|
+
onStdoutLine: async (line) => await toolHeartbeat.consume(line),
|
|
1417
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1418
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1419
|
+
}, context.signal);
|
|
1339
1420
|
}
|
|
1340
1421
|
finally {
|
|
1341
1422
|
toolHeartbeat.stop();
|
|
1342
1423
|
await cleanupCompletionTools(completionTools, context.emit);
|
|
1343
1424
|
}
|
|
1425
|
+
options.lastRun.result = result;
|
|
1344
1426
|
if (result.exitCode !== 0)
|
|
1345
1427
|
throw providerCliExitFailure(command.command, result);
|
|
1346
1428
|
const artifact = await readQaCompletionArtifactBundle(worktree.worktreePath, dispatch.workItem.id, dispatch.cycleRun.ownerType, dispatch.cycleRun.ownerId);
|
|
@@ -1397,10 +1479,14 @@ export class ProcessBackedProviderCliService {
|
|
|
1397
1479
|
session: { ...dispatch.session, resumeProviderThreadId: providerThreadId },
|
|
1398
1480
|
};
|
|
1399
1481
|
const recoveryPrompt = [
|
|
1400
|
-
"Forge did not receive the required forge.complete_comment_repair call from your previous turn.",
|
|
1482
|
+
"Forge did not receive the required forge.complete_comment_repair call from your previous turn, so the provider process exited.",
|
|
1483
|
+
"Background watchers, monitors and notifications from that turn did not survive and will never report back,",
|
|
1484
|
+
"and Forge stopped any managed command that process was still running; its receipt reports that.",
|
|
1401
1485
|
"Resume the existing work exactly where it is. Do not reimplement or discard the prepared changes.",
|
|
1402
|
-
"Review the current diff and the durable review snapshot
|
|
1403
|
-
"
|
|
1486
|
+
"Review the current diff and the durable review snapshot and preserve the validation evidence already gathered.",
|
|
1487
|
+
"Check each managed command with forge.get_managed_command, restart any that were interrupted,",
|
|
1488
|
+
"and block on long commands with forge.wait_managed_command, calling it again while command_continues is true.",
|
|
1489
|
+
"Do not end your turn until you have called forge.complete_comment_repair with an evidence-backed disposition for every actionable finding.",
|
|
1404
1490
|
"Do not commit or push; Forge owns publication after the completion gate succeeds.",
|
|
1405
1491
|
].join(" ");
|
|
1406
1492
|
const providerPrompt = buildProviderCliPrompt(recoveryDispatch, recoveryPrompt, repairEnvironment);
|
|
@@ -1410,6 +1496,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1410
1496
|
worktree,
|
|
1411
1497
|
phase: "comment_repair",
|
|
1412
1498
|
runtimeEnvironment: repairEnvironment,
|
|
1499
|
+
hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1413
1500
|
});
|
|
1414
1501
|
const command = buildProviderCliCommand(recoveryDispatch, {
|
|
1415
1502
|
worktreePath: worktree.worktreePath,
|
|
@@ -1434,6 +1521,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1434
1521
|
args: command.args,
|
|
1435
1522
|
cwd: worktree.worktreePath,
|
|
1436
1523
|
env: providerProcessEnv(recoveryDispatch, repairEnvironment),
|
|
1524
|
+
resumesProviderThread: Boolean(recoveryDispatch.session.resumeProviderThreadId),
|
|
1437
1525
|
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1438
1526
|
}, {
|
|
1439
1527
|
onStarted: async () => {
|
|
@@ -1445,6 +1533,8 @@ export class ProcessBackedProviderCliService {
|
|
|
1445
1533
|
eventType: "provider_cli_started",
|
|
1446
1534
|
});
|
|
1447
1535
|
},
|
|
1536
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1537
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1448
1538
|
onStdoutLine: async (line) => {
|
|
1449
1539
|
await toolHeartbeat.consume(line);
|
|
1450
1540
|
},
|
|
@@ -1466,6 +1556,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1466
1556
|
await cleanupCompletionTools(completionTools, context.emit);
|
|
1467
1557
|
}
|
|
1468
1558
|
}
|
|
1559
|
+
options.lastRun.result = result;
|
|
1469
1560
|
if (result.exitCode !== 0)
|
|
1470
1561
|
throw providerCliExitFailure(command.command, result);
|
|
1471
1562
|
const postRecoveryHeadSha = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
@@ -1485,138 +1576,78 @@ export class ProcessBackedProviderCliService {
|
|
|
1485
1576
|
return artifact;
|
|
1486
1577
|
}
|
|
1487
1578
|
async validatePrePublicationWithRecovery(options) {
|
|
1488
|
-
const
|
|
1579
|
+
const processRunner = recoveringProviderProcessRunner(options.context.processRunner ?? this.processRunner);
|
|
1580
|
+
await validatePrePublicationWithRepair(options, {
|
|
1581
|
+
validator: this.prePublicationValidator,
|
|
1582
|
+
defaultProcessRunner: this.processRunner,
|
|
1583
|
+
maxRepairTurns: this.prePublicationRepairTurns,
|
|
1584
|
+
runRepairTurn: async (turn) => await this.runPrePublicationRepairTurn(options, processRunner, turn),
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
/** Resumes the provider thread for one in-place repair turn; the turn must leave HEAD where it was. */
|
|
1588
|
+
async runPrePublicationRepairTurn(options, processRunner, turn) {
|
|
1589
|
+
const { context, outputState, preparedHeadSha } = options;
|
|
1489
1590
|
const { dispatch, worktree } = context;
|
|
1490
|
-
const
|
|
1491
|
-
const
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1591
|
+
const { prompt: focusedPrompt, repairTurn: nextRepairTurn, maxRepairTurns, repairEnvironment, environment } = turn;
|
|
1592
|
+
const repairDispatch = {
|
|
1593
|
+
...dispatch,
|
|
1594
|
+
session: { ...dispatch.session, resumeProviderThreadId: turn.providerThreadId },
|
|
1595
|
+
};
|
|
1596
|
+
const providerPrompt = buildProviderCliPrompt(repairDispatch, focusedPrompt, repairEnvironment);
|
|
1597
|
+
const pipePromptToStdin = shouldPipePromptToStdin(repairDispatch.execution.provider, providerPrompt, usesManagedWindowsHost(repairDispatch));
|
|
1598
|
+
const command = buildProviderCliCommand(repairDispatch, {
|
|
1599
|
+
worktreePath: worktree.worktreePath,
|
|
1600
|
+
prompt: focusedPrompt,
|
|
1601
|
+
promptFromStdin: pipePromptToStdin,
|
|
1602
|
+
runtimeEnvironment: repairEnvironment,
|
|
1603
|
+
});
|
|
1604
|
+
const toolHeartbeat = new ProviderToolActivityHeartbeat(outputState, context.emit, this.providerToolHeartbeatIntervalMs);
|
|
1605
|
+
let result;
|
|
1606
|
+
let providerStarted = false;
|
|
1607
|
+
try {
|
|
1608
|
+
result = await processRunner.run({
|
|
1609
|
+
command: command.command,
|
|
1610
|
+
args: command.args,
|
|
1611
|
+
cwd: worktree.worktreePath,
|
|
1612
|
+
env: environment,
|
|
1613
|
+
resumesProviderThread: Boolean(repairDispatch.session.resumeProviderThreadId),
|
|
1614
|
+
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1615
|
+
}, {
|
|
1616
|
+
onStarted: async () => {
|
|
1497
1617
|
await context.emit({
|
|
1498
1618
|
role: "runner",
|
|
1499
1619
|
kind: "checkpoint",
|
|
1500
|
-
content: `
|
|
1501
|
-
eventType: "
|
|
1502
|
-
data: JSON.stringify({ repairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1503
|
-
});
|
|
1504
|
-
}
|
|
1505
|
-
return;
|
|
1506
|
-
}
|
|
1507
|
-
catch (error) {
|
|
1508
|
-
if (!(error instanceof PrePublicationValidationError))
|
|
1509
|
-
throw error;
|
|
1510
|
-
if (repairTurn >= maxPrePublicationRepairTurns) {
|
|
1511
|
-
await context.emit({
|
|
1512
|
-
role: "runner",
|
|
1513
|
-
kind: "error",
|
|
1514
|
-
content: `Pre-publication validation still fails after ${maxPrePublicationRepairTurns} in-place repair turns: ${clip(error.message, 4000)}`,
|
|
1515
|
-
eventType: "prepublication_repair_exhausted",
|
|
1516
|
-
data: JSON.stringify({ checkId: error.checkId, repairTurns: repairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1620
|
+
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxRepairTurns} is supervised and ready.`,
|
|
1621
|
+
eventType: "provider_cli_started",
|
|
1517
1622
|
});
|
|
1518
|
-
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
const providerPrompt = buildProviderCliPrompt(repairDispatch, focusedPrompt, repairEnvironment);
|
|
1531
|
-
const pipePromptToStdin = shouldPipePromptToStdin(repairDispatch.execution.provider, providerPrompt, usesManagedWindowsHost(repairDispatch));
|
|
1532
|
-
const command = buildProviderCliCommand(repairDispatch, {
|
|
1533
|
-
worktreePath: worktree.worktreePath,
|
|
1534
|
-
prompt: focusedPrompt,
|
|
1535
|
-
promptFromStdin: pipePromptToStdin,
|
|
1536
|
-
runtimeEnvironment: repairEnvironment,
|
|
1537
|
-
});
|
|
1623
|
+
providerStarted = true;
|
|
1624
|
+
},
|
|
1625
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1626
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1627
|
+
onStdoutLine: async (line) => {
|
|
1628
|
+
await toolHeartbeat.consume(line);
|
|
1629
|
+
},
|
|
1630
|
+
}, context.signal);
|
|
1631
|
+
}
|
|
1632
|
+
finally {
|
|
1633
|
+
toolHeartbeat.stop();
|
|
1634
|
+
if (providerStarted) {
|
|
1538
1635
|
await context.emit({
|
|
1539
1636
|
role: "runner",
|
|
1540
1637
|
kind: "checkpoint",
|
|
1541
|
-
content: `
|
|
1542
|
-
eventType: "
|
|
1543
|
-
data: JSON.stringify({ checkId: error.checkId, repairTurn: nextRepairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1638
|
+
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxRepairTurns} exited.`,
|
|
1639
|
+
eventType: "provider_cli_completed",
|
|
1544
1640
|
});
|
|
1545
|
-
const toolHeartbeat = new ProviderToolActivityHeartbeat(outputState, context.emit, this.providerToolHeartbeatIntervalMs);
|
|
1546
|
-
let result;
|
|
1547
|
-
let providerStarted = false;
|
|
1548
|
-
try {
|
|
1549
|
-
result = await processRunner.run({
|
|
1550
|
-
command: command.command,
|
|
1551
|
-
args: command.args,
|
|
1552
|
-
cwd: worktree.worktreePath,
|
|
1553
|
-
env: environment,
|
|
1554
|
-
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1555
|
-
}, {
|
|
1556
|
-
onStarted: async () => {
|
|
1557
|
-
await context.emit({
|
|
1558
|
-
role: "runner",
|
|
1559
|
-
kind: "checkpoint",
|
|
1560
|
-
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxPrePublicationRepairTurns} is supervised and ready.`,
|
|
1561
|
-
eventType: "provider_cli_started",
|
|
1562
|
-
});
|
|
1563
|
-
providerStarted = true;
|
|
1564
|
-
},
|
|
1565
|
-
onStdoutLine: async (line) => {
|
|
1566
|
-
await toolHeartbeat.consume(line);
|
|
1567
|
-
},
|
|
1568
|
-
}, context.signal);
|
|
1569
|
-
}
|
|
1570
|
-
finally {
|
|
1571
|
-
toolHeartbeat.stop();
|
|
1572
|
-
if (providerStarted) {
|
|
1573
|
-
await context.emit({
|
|
1574
|
-
role: "runner",
|
|
1575
|
-
kind: "checkpoint",
|
|
1576
|
-
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxPrePublicationRepairTurns} exited.`,
|
|
1577
|
-
eventType: "provider_cli_completed",
|
|
1578
|
-
});
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
if (result.exitCode !== 0)
|
|
1582
|
-
throw providerCliExitFailure(command.command, result);
|
|
1583
|
-
const postRepairHeadSha = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
1584
|
-
if (postRepairHeadSha.toLowerCase() !== preparedHeadSha.toLowerCase()) {
|
|
1585
|
-
throw new Error(`provider_publication_boundary_violation: pre-publication repair changed HEAD from ${preparedHeadSha} to ${postRepairHeadSha}; Forge requires provider changes to remain uncommitted and unpushed until validation passes.`, { cause: error });
|
|
1586
|
-
}
|
|
1587
1641
|
}
|
|
1588
1642
|
}
|
|
1643
|
+
if (result.exitCode !== 0)
|
|
1644
|
+
throw providerCliExitFailure(command.command, result);
|
|
1645
|
+
const postRepairHeadSha = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
1646
|
+
if (postRepairHeadSha.toLowerCase() !== preparedHeadSha.toLowerCase()) {
|
|
1647
|
+
throw new Error(`provider_publication_boundary_violation: pre-publication repair changed HEAD from ${preparedHeadSha} to ${postRepairHeadSha}; Forge requires provider changes to remain uncommitted and unpushed until validation passes.`, { cause: turn.failure });
|
|
1648
|
+
}
|
|
1589
1649
|
}
|
|
1590
1650
|
}
|
|
1591
|
-
function buildPrePublicationRepairPrompt(error, repairTurn, repairScope) {
|
|
1592
|
-
const invocation = [error.command, ...error.args].join(" ");
|
|
1593
|
-
const priorWork = repairScope === "implementation"
|
|
1594
|
-
? "Keep the completed implementation and its Forge-owned completion artifacts intact."
|
|
1595
|
-
: "Keep the existing PR-comment or CI repairs intact.";
|
|
1596
|
-
return [
|
|
1597
|
-
`Forge pre-publication validation failed after your ${repairScope === "implementation" ? "implementation" : "PR repair"} turn.`,
|
|
1598
|
-
`This is bounded in-place repair turn ${repairTurn}/${maxPrePublicationRepairTurns}.`,
|
|
1599
|
-
`Failed check: ${error.checkId}`,
|
|
1600
|
-
`Command: ${invocation}`,
|
|
1601
|
-
`Exit code: ${error.exitCode}`,
|
|
1602
|
-
"Diagnostics:",
|
|
1603
|
-
error.detail || "The validation command returned no diagnostic output.",
|
|
1604
|
-
"Fix the root cause in the current worktree and run the focused failing check.",
|
|
1605
|
-
`${priorWork} Do not commit, push, rebase, or modify Forge-owned protocol artifacts.`,
|
|
1606
|
-
"When the focused check passes, stop; Bridge will rerun the complete required pre-publication profile and owns commit/push.",
|
|
1607
|
-
].join("\n\n");
|
|
1608
|
-
}
|
|
1609
|
-
function publicationCapabilities(context, runtimeEnvironment) {
|
|
1610
|
-
const capabilities = new Set();
|
|
1611
|
-
const launchTarget = context.dispatch.qaBrowser?.launchTarget;
|
|
1612
|
-
if (runtimeEnvironment?.FORGE_PLAYWRIGHT_CONFIG
|
|
1613
|
-
|| launchTarget?.url
|
|
1614
|
-
|| launchTarget?.command
|
|
1615
|
-
|| launchTarget?.managed_runtime_port) {
|
|
1616
|
-
capabilities.add("browser_launch");
|
|
1617
|
-
}
|
|
1618
|
-
return capabilities;
|
|
1619
|
-
}
|
|
1620
1651
|
async function stageDraftAttachments(dispatch, metadataRoot) {
|
|
1621
1652
|
const attachments = dispatch.draft?.attachments ?? [];
|
|
1622
1653
|
const stageable = attachments.filter((attachment) => (attachment.kind === "text" && typeof attachment.textContent === "string")
|