@loucompanion/forge-bridge 0.1.4-dev.bfa11ebe98c6 → 0.1.4-dev.c03d3c89ec4a
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 +45 -3
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +84 -2
- package/dist/bridge/bridge.service.js +358 -12
- 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 +20 -2
- 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-database-broker.d.ts +89 -0
- package/dist/runtime/attempt-database-broker.js +390 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +24 -0
- package/dist/runtime/attempt-process-supervisor.js +77 -3
- 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-diagnostics.js +4 -3
- 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 +60 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +22 -0
- package/dist/runtime/host-load-child-environment.js +67 -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 +43 -0
- package/dist/runtime/host-load-governor-config.js +76 -0
- package/dist/runtime/host-load-governor.d.ts +174 -0
- package/dist/runtime/host-load-governor.js +541 -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 +68 -0
- package/dist/runtime/host-load-step-class.js +106 -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-token-ledger.d.ts +174 -0
- package/dist/runtime/host-load-token-ledger.js +421 -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 +75 -11
- package/dist/runtime/host-runtime-lease.d.ts +76 -4
- package/dist/runtime/host-runtime-lease.js +386 -32
- 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/node-host-runtime-adapter.js +5 -4
- 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 +107 -0
- package/dist/sandbox/host-capacity-broker.js +315 -0
- package/dist/sandbox/repository-lock.js +3 -2
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +50 -6
- 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 +366 -45
- package/dist/session/managed-build-coordinator.d.ts +1 -1
- package/dist/session/managed-build-coordinator.js +8 -4
- package/dist/session/managed-command-host-load.d.ts +45 -0
- package/dist/session/managed-command-host-load.js +82 -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 +78 -36
- 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 +178 -193
- 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 +37 -1
- package/dist/session/provider-cli/provider-cli.process.js +299 -25
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +62 -9
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +14 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +200 -162
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +6 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +47 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +6 -0
- package/dist/session/provider-cli/provider-output-state.js +9 -0
- package/dist/session/provider-cli/provider-usage.d.ts +2 -1
- 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 +229 -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-recovery.js +3 -2
- package/dist/shared/process/host-process-supervisor.d.ts +1 -0
- package/dist/shared/process/host-process-supervisor.js +6 -5
- 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/shared/time/monotonic.d.ts +1 -0
- package/dist/shared/time/monotonic.js +8 -0
- 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 +120 -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";
|
|
14
|
+
import { isTransientCodexProviderNotFoundFailure, providerCompletionToolMissingFailure, recoveringProviderProcessRunner, StreamingProviderProcessRunner } from "./provider-cli.process.js";
|
|
13
15
|
import { emitProviderUsageEvent, providerProcessEnv } from "./provider-cli.runtime.js";
|
|
14
16
|
import { clip, 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
|
}
|
|
@@ -389,7 +421,8 @@ export class ManagedVerificationProgressEmitter {
|
|
|
389
421
|
}
|
|
390
422
|
}
|
|
391
423
|
function isManagedVerificationNonterminal(status) {
|
|
392
|
-
return status === "starting" || status === "running" || status === "waiting_for_build_slot"
|
|
424
|
+
return status === "starting" || status === "running" || status === "waiting_for_build_slot"
|
|
425
|
+
|| status === "waiting_for_host_capacity";
|
|
393
426
|
}
|
|
394
427
|
async function parseManagedVerificationSnapshot(receiptPath) {
|
|
395
428
|
try {
|
|
@@ -429,10 +462,17 @@ class ProviderToolActivityHeartbeat {
|
|
|
429
462
|
emit;
|
|
430
463
|
intervalMs;
|
|
431
464
|
timer = null;
|
|
465
|
+
/** Lets the provider runner hold its end-of-turn timers while a tool call is in flight. */
|
|
466
|
+
isToolCallInFlight = () => this.outputState.hasActiveToolCall;
|
|
467
|
+
/** Forgets tool calls a previous generation left open; called before every relaunch. */
|
|
468
|
+
startGeneration = () => this.outputState.resetActiveToolCalls();
|
|
432
469
|
constructor(outputState, emit, intervalMs) {
|
|
433
470
|
this.outputState = outputState;
|
|
434
471
|
this.emit = emit;
|
|
435
472
|
this.intervalMs = intervalMs;
|
|
473
|
+
// Each heartbeat watches one provider generation. Calls an earlier generation left
|
|
474
|
+
// open died with it; inheriting them would hold the new generation's timers forever.
|
|
475
|
+
this.outputState.resetActiveToolCalls();
|
|
436
476
|
}
|
|
437
477
|
async consume(line) {
|
|
438
478
|
const events = this.outputState.consume(line);
|
|
@@ -514,12 +554,19 @@ export class ProcessBackedProviderCliService {
|
|
|
514
554
|
providerToolHeartbeatIntervalMs;
|
|
515
555
|
publicationCoordinator;
|
|
516
556
|
prePublicationValidator;
|
|
517
|
-
|
|
557
|
+
prePublicationRepairTurns;
|
|
558
|
+
constructor(processRunner = new StreamingProviderProcessRunner(), git = new GitClient(), providerToolHeartbeatIntervalMs = defaultProviderToolHeartbeatIntervalMs, publicationCoordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
559
|
+
// The Docker sandbox worker (`forge` run-once via ForgeBridgeCliService) builds
|
|
560
|
+
// this default. A container cannot reach the host ledger, so when the host
|
|
561
|
+
// bridge enabled it, its steps ask the bridge for tokens over the sandbox
|
|
562
|
+
// channel (decision 0013); elsewhere the gate is absent and validation is ungated.
|
|
563
|
+
prePublicationValidator = new PrePublicationValidator(undefined, undefined, undefined, sandboxHostLoadGateFromEnvironment()), prePublicationRepairTurns = prePublicationRepairTurnsFromEnvironment()) {
|
|
518
564
|
this.processRunner = processRunner;
|
|
519
565
|
this.git = git;
|
|
520
566
|
this.providerToolHeartbeatIntervalMs = providerToolHeartbeatIntervalMs;
|
|
521
567
|
this.publicationCoordinator = publicationCoordinator;
|
|
522
568
|
this.prePublicationValidator = prePublicationValidator;
|
|
569
|
+
this.prePublicationRepairTurns = prePublicationRepairTurns;
|
|
523
570
|
}
|
|
524
571
|
async runDraft(context) {
|
|
525
572
|
const { dispatch } = context;
|
|
@@ -533,7 +580,7 @@ export class ProcessBackedProviderCliService {
|
|
|
533
580
|
await fs.writeFile(path.join(metadataRoot, "spec.md"), buildDraftSpec(dispatch), "utf8");
|
|
534
581
|
const stagedAttachments = await stageDraftAttachments(dispatch, metadataRoot);
|
|
535
582
|
const decomposeDraft = isDecomposeDraftDispatch(dispatch);
|
|
536
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: decomposeDraft ? "decompose" : "draft", runtimeEnvironment: context.runtimeEnvironment });
|
|
583
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: decomposeDraft ? "decompose" : "draft", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
537
584
|
const draftPrompt = buildDraftPrompt(dispatch, { attachmentReferences: stagedAttachments.textReferences });
|
|
538
585
|
const providerPrompt = buildProviderCliPrompt(dispatch, draftPrompt, context.runtimeEnvironment);
|
|
539
586
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -586,6 +633,7 @@ export class ProcessBackedProviderCliService {
|
|
|
586
633
|
args: command.args,
|
|
587
634
|
cwd: worktree.worktreePath,
|
|
588
635
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
636
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
589
637
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
590
638
|
}, {
|
|
591
639
|
onStarted: async () => {
|
|
@@ -596,6 +644,8 @@ export class ProcessBackedProviderCliService {
|
|
|
596
644
|
eventType: "provider_cli_started"
|
|
597
645
|
});
|
|
598
646
|
},
|
|
647
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
648
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
599
649
|
onStdoutLine: async (line) => {
|
|
600
650
|
await toolHeartbeat.consume(line);
|
|
601
651
|
}
|
|
@@ -645,7 +695,7 @@ export class ProcessBackedProviderCliService {
|
|
|
645
695
|
await emitDecomposeGateArtifacts(context.emit, worktree.worktreePath, dispatch.workItem.id);
|
|
646
696
|
const proposalArtifact = earlyProposalArtifact ?? await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "decompose");
|
|
647
697
|
if (!proposalArtifact) {
|
|
648
|
-
throw
|
|
698
|
+
throw providerCompletionToolMissingFailure("Provider CLI Decompose completed but did not call forge.complete_decompose_proposal.", result);
|
|
649
699
|
}
|
|
650
700
|
const proposal = parseJsonLine(proposalArtifact.verdictJson) ?? {};
|
|
651
701
|
const proposalJson = proposal["proposal_json"] ?? proposal["decomposition_json"];
|
|
@@ -668,7 +718,7 @@ export class ProcessBackedProviderCliService {
|
|
|
668
718
|
await emitDraftGateArtifacts(context.emit, worktree.worktreePath, dispatch.workItem.id);
|
|
669
719
|
const proposalArtifact = earlyProposalArtifact ?? await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "draft");
|
|
670
720
|
if (!proposalArtifact) {
|
|
671
|
-
throw
|
|
721
|
+
throw providerCompletionToolMissingFailure("Provider CLI Draft completed but did not call forge.complete_draft_proposal.", result);
|
|
672
722
|
}
|
|
673
723
|
const proposal = parseJsonLine(proposalArtifact.verdictJson) ?? {};
|
|
674
724
|
const draftJson = proposal["draft_json"];
|
|
@@ -713,7 +763,7 @@ export class ProcessBackedProviderCliService {
|
|
|
713
763
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
714
764
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
715
765
|
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 });
|
|
766
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase, runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
717
767
|
const implementationPrompt = debugCycle
|
|
718
768
|
? buildDebugCyclePrompt(dispatch, phase)
|
|
719
769
|
: developCycle
|
|
@@ -755,6 +805,7 @@ export class ProcessBackedProviderCliService {
|
|
|
755
805
|
args: command.args,
|
|
756
806
|
cwd: worktree.worktreePath,
|
|
757
807
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
808
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
758
809
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
759
810
|
}, {
|
|
760
811
|
onStarted: async () => {
|
|
@@ -765,6 +816,8 @@ export class ProcessBackedProviderCliService {
|
|
|
765
816
|
eventType: "provider_cli_started"
|
|
766
817
|
});
|
|
767
818
|
},
|
|
819
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
820
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
768
821
|
onStdoutLine: async (line) => {
|
|
769
822
|
await toolHeartbeat.consume(line);
|
|
770
823
|
}
|
|
@@ -806,7 +859,7 @@ export class ProcessBackedProviderCliService {
|
|
|
806
859
|
eventType: "worktree_branch_pushed"
|
|
807
860
|
});
|
|
808
861
|
}
|
|
809
|
-
const completionArtifacts = await readCompletionArtifactsForRun(worktree.worktreePath, dispatch.workItem.id, phase, developCycle, debugCycle);
|
|
862
|
+
const completionArtifacts = await readCompletionArtifactsForRun(worktree.worktreePath, dispatch.workItem.id, phase, developCycle, debugCycle, result);
|
|
810
863
|
for (const artifact of completionArtifacts) {
|
|
811
864
|
if (!liveCompletionEvents.hasEmitted(completionPhaseFromArtifact(artifact))) {
|
|
812
865
|
await emitCompletionArtifactRecorded(context.emit, worktree.worktreePath, artifact);
|
|
@@ -858,7 +911,7 @@ export class ProcessBackedProviderCliService {
|
|
|
858
911
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
859
912
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
860
913
|
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 });
|
|
914
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "architect", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
862
915
|
const architectPrompt = buildArchitectPrompt(dispatch);
|
|
863
916
|
const providerPrompt = buildProviderCliPrompt(dispatch, architectPrompt, context.runtimeEnvironment);
|
|
864
917
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -893,6 +946,7 @@ export class ProcessBackedProviderCliService {
|
|
|
893
946
|
args: command.args,
|
|
894
947
|
cwd: worktree.worktreePath,
|
|
895
948
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
949
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
896
950
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
897
951
|
}, {
|
|
898
952
|
onStarted: async () => {
|
|
@@ -903,6 +957,8 @@ export class ProcessBackedProviderCliService {
|
|
|
903
957
|
eventType: "provider_cli_started"
|
|
904
958
|
});
|
|
905
959
|
},
|
|
960
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
961
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
906
962
|
onStdoutLine: async (line) => await toolHeartbeat.consume(line)
|
|
907
963
|
}, context.signal);
|
|
908
964
|
}
|
|
@@ -923,7 +979,7 @@ export class ProcessBackedProviderCliService {
|
|
|
923
979
|
await emitProviderUsageEvent(context.emit, dispatch, outputState);
|
|
924
980
|
const architectArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "architect");
|
|
925
981
|
if (!architectArtifact) {
|
|
926
|
-
throw
|
|
982
|
+
throw providerCompletionToolMissingFailure("Provider CLI Architect completed but did not call the Forge Architect completion tool.", result);
|
|
927
983
|
}
|
|
928
984
|
if (!liveArchitectEvents.hasEmitted()) {
|
|
929
985
|
await emitCompletionArtifactRecorded(context.emit, worktree.worktreePath, architectArtifact);
|
|
@@ -960,7 +1016,7 @@ export class ProcessBackedProviderCliService {
|
|
|
960
1016
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
961
1017
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
962
1018
|
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 });
|
|
1019
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "qa", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
964
1020
|
const qaPrompt = buildQaPrompt(dispatch, specBody);
|
|
965
1021
|
const providerPrompt = buildProviderCliPrompt(dispatch, qaPrompt, context.runtimeEnvironment);
|
|
966
1022
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -997,6 +1053,7 @@ export class ProcessBackedProviderCliService {
|
|
|
997
1053
|
args: command.args,
|
|
998
1054
|
cwd: worktree.worktreePath,
|
|
999
1055
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
1056
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
1000
1057
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
1001
1058
|
}, {
|
|
1002
1059
|
onStarted: async () => {
|
|
@@ -1007,6 +1064,8 @@ export class ProcessBackedProviderCliService {
|
|
|
1007
1064
|
eventType: "provider_cli_started"
|
|
1008
1065
|
});
|
|
1009
1066
|
},
|
|
1067
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1068
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1010
1069
|
onStdoutLine: async (line) => await toolHeartbeat.consume(line)
|
|
1011
1070
|
}, context.signal);
|
|
1012
1071
|
}
|
|
@@ -1026,17 +1085,19 @@ export class ProcessBackedProviderCliService {
|
|
|
1026
1085
|
eventType: "provider_cli_completed"
|
|
1027
1086
|
});
|
|
1028
1087
|
await emitProviderUsageEvent(context.emit, dispatch, outputState);
|
|
1088
|
+
const lastRun = { result };
|
|
1029
1089
|
let qaArtifact = await readQaCompletionArtifactBundle(worktree.worktreePath, dispatch.workItem.id, dispatch.cycleRun.ownerType, dispatch.cycleRun.ownerId);
|
|
1030
1090
|
if (!qaArtifact && !(await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "qa"))) {
|
|
1031
1091
|
// A headless provider that ends its turn to "wait for a background watcher"
|
|
1032
1092
|
// exits for good. Resume the same thread instead of failing the session.
|
|
1033
|
-
qaArtifact = await this.recoverMissingQaCompletion({ context, outputState });
|
|
1093
|
+
qaArtifact = await this.recoverMissingQaCompletion({ context, outputState, lastRun });
|
|
1034
1094
|
}
|
|
1035
1095
|
if (!qaArtifact) {
|
|
1036
1096
|
const verdictOnly = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "qa");
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1097
|
+
if (verdictOnly) {
|
|
1098
|
+
throw new Error("Provider CLI QA completed but did not produce the complete durable QA artifact bundle.");
|
|
1099
|
+
}
|
|
1100
|
+
throw providerCompletionToolMissingFailure("Provider CLI QA completed but did not call the Forge QA completion tool.", lastRun.result);
|
|
1040
1101
|
}
|
|
1041
1102
|
await enforceQaBrowserLaunchTargetGate(dispatch, qaArtifact);
|
|
1042
1103
|
if (!liveQaEvents.hasEmitted()) {
|
|
@@ -1075,6 +1136,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1075
1136
|
const addressComments = !repairChecks && isPullRequestCommentsDispatch(dispatch);
|
|
1076
1137
|
let repairSpec = null;
|
|
1077
1138
|
let repairEnvironment = context.runtimeEnvironment;
|
|
1139
|
+
let ciRepairSpecPath = null;
|
|
1078
1140
|
let completionTools = null;
|
|
1079
1141
|
if (repairChecks) {
|
|
1080
1142
|
const metadataRoot = path.join(worktree.worktreePath, ".forge", "work-items", dispatch.workItem.id);
|
|
@@ -1085,6 +1147,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1085
1147
|
}
|
|
1086
1148
|
const specBody = buildSpecBody(laneCommand, dispatch.workItem, "ci_repair");
|
|
1087
1149
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
1150
|
+
ciRepairSpecPath = specPath;
|
|
1088
1151
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
1089
1152
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), `${JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" })}\n`, "utf8");
|
|
1090
1153
|
repairSpec = {
|
|
@@ -1096,7 +1159,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1096
1159
|
};
|
|
1097
1160
|
const readiness = await writeCiRepairReadinessManifest(dispatch, worktree.worktreePath, specPath, context.runtimeEnvironment);
|
|
1098
1161
|
repairEnvironment = readiness.environment;
|
|
1099
|
-
completionTools = await prepareCompletionToolRuntime({
|
|
1162
|
+
completionTools = await prepareCompletionToolRuntime({
|
|
1163
|
+
dispatch, worktree, phase: "ci_repair", runtimeEnvironment: repairEnvironment, hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1164
|
+
});
|
|
1100
1165
|
await context.emit({
|
|
1101
1166
|
role: "runner",
|
|
1102
1167
|
kind: "checkpoint",
|
|
@@ -1111,7 +1176,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1111
1176
|
});
|
|
1112
1177
|
}
|
|
1113
1178
|
if (addressComments) {
|
|
1114
|
-
completionTools = await prepareCompletionToolRuntime({
|
|
1179
|
+
completionTools = await prepareCompletionToolRuntime({
|
|
1180
|
+
dispatch, worktree, phase: "comment_repair", runtimeEnvironment: repairEnvironment, hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1181
|
+
});
|
|
1115
1182
|
await context.emit({
|
|
1116
1183
|
role: "runner",
|
|
1117
1184
|
kind: "checkpoint",
|
|
@@ -1149,6 +1216,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1149
1216
|
args: command.args,
|
|
1150
1217
|
cwd: worktree.worktreePath,
|
|
1151
1218
|
env: providerProcessEnv(dispatch, repairEnvironment),
|
|
1219
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
1152
1220
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
1153
1221
|
}, {
|
|
1154
1222
|
onStarted: async () => {
|
|
@@ -1160,6 +1228,8 @@ export class ProcessBackedProviderCliService {
|
|
|
1160
1228
|
});
|
|
1161
1229
|
providerStarted = true;
|
|
1162
1230
|
},
|
|
1231
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1232
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1163
1233
|
onStdoutLine: async (line) => {
|
|
1164
1234
|
await toolHeartbeat.consume(line);
|
|
1165
1235
|
}
|
|
@@ -1194,7 +1264,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1194
1264
|
if (repairChecks) {
|
|
1195
1265
|
repairArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "ci_repair");
|
|
1196
1266
|
if (!repairArtifact) {
|
|
1197
|
-
throw
|
|
1267
|
+
throw providerCompletionToolMissingFailure("Provider CLI completed but did not call forge.complete_ci_repair. Forge did not commit or push the repair.", result);
|
|
1198
1268
|
}
|
|
1199
1269
|
if ((repairArtifact.status ?? "").trim().toLowerCase() !== "pass") {
|
|
1200
1270
|
throw new Error(`CI repair completion gate recorded ${repairArtifact.status}; Forge did not commit or push the repair.`);
|
|
@@ -1202,16 +1272,18 @@ export class ProcessBackedProviderCliService {
|
|
|
1202
1272
|
}
|
|
1203
1273
|
if (addressComments) {
|
|
1204
1274
|
repairArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "comment_repair");
|
|
1275
|
+
const lastRun = { result };
|
|
1205
1276
|
if (!repairArtifact) {
|
|
1206
1277
|
repairArtifact = await this.recoverMissingCommentRepairCompletion({
|
|
1207
1278
|
context,
|
|
1208
1279
|
repairEnvironment,
|
|
1209
1280
|
outputState,
|
|
1210
1281
|
preparedHeadSha,
|
|
1282
|
+
lastRun,
|
|
1211
1283
|
});
|
|
1212
1284
|
}
|
|
1213
1285
|
if (!repairArtifact) {
|
|
1214
|
-
throw
|
|
1286
|
+
throw providerCompletionToolMissingFailure("Provider CLI completed but did not call forge.complete_comment_repair. Forge did not publish or resolve review findings.", lastRun.result);
|
|
1215
1287
|
}
|
|
1216
1288
|
if ((repairArtifact.status ?? "").trim().toLowerCase() !== "pass") {
|
|
1217
1289
|
throw new Error(`Comment repair completion gate recorded ${repairArtifact.status}; Forge did not publish or resolve review findings.`);
|
|
@@ -1220,7 +1292,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1220
1292
|
}
|
|
1221
1293
|
let commentRepairBaselineChangedFiles = null;
|
|
1222
1294
|
if (addressComments && repairArtifact) {
|
|
1223
|
-
|
|
1295
|
+
const baseline = await stagePublishableWorktreeChangeSet(this.git, worktree.worktreePath);
|
|
1296
|
+
commentRepairBaselineChangedFiles = baseline.publishable;
|
|
1297
|
+
await assertFixedFindingsArePublished(this.git, worktree.worktreePath, dispatch, repairArtifact, baseline);
|
|
1224
1298
|
assertCommentRepairArtifactMatchesChanges(repairArtifact, commentRepairBaselineChangedFiles);
|
|
1225
1299
|
}
|
|
1226
1300
|
const validationProfile = repairChecks
|
|
@@ -1228,6 +1302,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1228
1302
|
: addressComments
|
|
1229
1303
|
? "comment_repair"
|
|
1230
1304
|
: "conflict_repair";
|
|
1305
|
+
const readinessSpecPath = ciRepairSpecPath;
|
|
1231
1306
|
await this.validatePrePublicationWithRecovery({
|
|
1232
1307
|
context,
|
|
1233
1308
|
validationProfile,
|
|
@@ -1235,9 +1310,15 @@ export class ProcessBackedProviderCliService {
|
|
|
1235
1310
|
outputState,
|
|
1236
1311
|
preparedHeadSha,
|
|
1237
1312
|
repairScope: "pull_request",
|
|
1313
|
+
...(readinessSpecPath ? {
|
|
1314
|
+
// The readiness manifest records the attempt URLs; a restart must not leave it pointing at the old stack.
|
|
1315
|
+
onRuntimeEnvironmentRefreshed: async (runtimeEnvironment) => (await writeCiRepairReadinessManifest(dispatch, worktree.worktreePath, readinessSpecPath, runtimeEnvironment)).environment,
|
|
1316
|
+
} : {}),
|
|
1238
1317
|
});
|
|
1239
|
-
const
|
|
1318
|
+
const stagedChangeSet = await stagePublishableWorktreeChangeSet(this.git, worktree.worktreePath);
|
|
1319
|
+
const stagedChangedFiles = stagedChangeSet.publishable;
|
|
1240
1320
|
if (addressComments && repairArtifact && commentRepairBaselineChangedFiles) {
|
|
1321
|
+
await assertFixedFindingsArePublished(this.git, worktree.worktreePath, dispatch, repairArtifact, stagedChangeSet);
|
|
1241
1322
|
repairArtifact = await finalizeCommentRepairChangedFiles(repairArtifact, commentRepairBaselineChangedFiles, stagedChangedFiles);
|
|
1242
1323
|
}
|
|
1243
1324
|
const committed = await commitWorktreeChanges(this.git, worktree.worktreePath, dispatch.workItem.id, stagedChangedFiles);
|
|
@@ -1311,6 +1392,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1311
1392
|
worktree,
|
|
1312
1393
|
phase: "qa",
|
|
1313
1394
|
runtimeEnvironment: context.runtimeEnvironment,
|
|
1395
|
+
hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1314
1396
|
});
|
|
1315
1397
|
const command = buildProviderCliCommand(recoveryDispatch, {
|
|
1316
1398
|
worktreePath: worktree.worktreePath,
|
|
@@ -1334,13 +1416,19 @@ export class ProcessBackedProviderCliService {
|
|
|
1334
1416
|
args: command.args,
|
|
1335
1417
|
cwd: worktree.worktreePath,
|
|
1336
1418
|
env: providerProcessEnv(recoveryDispatch, context.runtimeEnvironment),
|
|
1419
|
+
resumesProviderThread: Boolean(recoveryDispatch.session.resumeProviderThreadId),
|
|
1337
1420
|
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1338
|
-
}, {
|
|
1421
|
+
}, {
|
|
1422
|
+
onStdoutLine: async (line) => await toolHeartbeat.consume(line),
|
|
1423
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1424
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1425
|
+
}, context.signal);
|
|
1339
1426
|
}
|
|
1340
1427
|
finally {
|
|
1341
1428
|
toolHeartbeat.stop();
|
|
1342
1429
|
await cleanupCompletionTools(completionTools, context.emit);
|
|
1343
1430
|
}
|
|
1431
|
+
options.lastRun.result = result;
|
|
1344
1432
|
if (result.exitCode !== 0)
|
|
1345
1433
|
throw providerCliExitFailure(command.command, result);
|
|
1346
1434
|
const artifact = await readQaCompletionArtifactBundle(worktree.worktreePath, dispatch.workItem.id, dispatch.cycleRun.ownerType, dispatch.cycleRun.ownerId);
|
|
@@ -1397,10 +1485,14 @@ export class ProcessBackedProviderCliService {
|
|
|
1397
1485
|
session: { ...dispatch.session, resumeProviderThreadId: providerThreadId },
|
|
1398
1486
|
};
|
|
1399
1487
|
const recoveryPrompt = [
|
|
1400
|
-
"Forge did not receive the required forge.complete_comment_repair call from your previous turn.",
|
|
1488
|
+
"Forge did not receive the required forge.complete_comment_repair call from your previous turn, so the provider process exited.",
|
|
1489
|
+
"Background watchers, monitors and notifications from that turn did not survive and will never report back,",
|
|
1490
|
+
"and Forge stopped any managed command that process was still running; its receipt reports that.",
|
|
1401
1491
|
"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
|
-
"
|
|
1492
|
+
"Review the current diff and the durable review snapshot and preserve the validation evidence already gathered.",
|
|
1493
|
+
"Check each managed command with forge.get_managed_command, restart any that were interrupted,",
|
|
1494
|
+
"and block on long commands with forge.wait_managed_command, calling it again while command_continues is true.",
|
|
1495
|
+
"Do not end your turn until you have called forge.complete_comment_repair with an evidence-backed disposition for every actionable finding.",
|
|
1404
1496
|
"Do not commit or push; Forge owns publication after the completion gate succeeds.",
|
|
1405
1497
|
].join(" ");
|
|
1406
1498
|
const providerPrompt = buildProviderCliPrompt(recoveryDispatch, recoveryPrompt, repairEnvironment);
|
|
@@ -1410,6 +1502,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1410
1502
|
worktree,
|
|
1411
1503
|
phase: "comment_repair",
|
|
1412
1504
|
runtimeEnvironment: repairEnvironment,
|
|
1505
|
+
hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1413
1506
|
});
|
|
1414
1507
|
const command = buildProviderCliCommand(recoveryDispatch, {
|
|
1415
1508
|
worktreePath: worktree.worktreePath,
|
|
@@ -1434,6 +1527,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1434
1527
|
args: command.args,
|
|
1435
1528
|
cwd: worktree.worktreePath,
|
|
1436
1529
|
env: providerProcessEnv(recoveryDispatch, repairEnvironment),
|
|
1530
|
+
resumesProviderThread: Boolean(recoveryDispatch.session.resumeProviderThreadId),
|
|
1437
1531
|
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1438
1532
|
}, {
|
|
1439
1533
|
onStarted: async () => {
|
|
@@ -1445,6 +1539,8 @@ export class ProcessBackedProviderCliService {
|
|
|
1445
1539
|
eventType: "provider_cli_started",
|
|
1446
1540
|
});
|
|
1447
1541
|
},
|
|
1542
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1543
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1448
1544
|
onStdoutLine: async (line) => {
|
|
1449
1545
|
await toolHeartbeat.consume(line);
|
|
1450
1546
|
},
|
|
@@ -1466,6 +1562,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1466
1562
|
await cleanupCompletionTools(completionTools, context.emit);
|
|
1467
1563
|
}
|
|
1468
1564
|
}
|
|
1565
|
+
options.lastRun.result = result;
|
|
1469
1566
|
if (result.exitCode !== 0)
|
|
1470
1567
|
throw providerCliExitFailure(command.command, result);
|
|
1471
1568
|
const postRecoveryHeadSha = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
@@ -1485,137 +1582,78 @@ export class ProcessBackedProviderCliService {
|
|
|
1485
1582
|
return artifact;
|
|
1486
1583
|
}
|
|
1487
1584
|
async validatePrePublicationWithRecovery(options) {
|
|
1488
|
-
const
|
|
1585
|
+
const processRunner = recoveringProviderProcessRunner(options.context.processRunner ?? this.processRunner);
|
|
1586
|
+
await validatePrePublicationWithRepair(options, {
|
|
1587
|
+
validator: this.prePublicationValidator,
|
|
1588
|
+
defaultProcessRunner: this.processRunner,
|
|
1589
|
+
maxRepairTurns: this.prePublicationRepairTurns,
|
|
1590
|
+
runRepairTurn: async (turn) => await this.runPrePublicationRepairTurn(options, processRunner, turn),
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
/** Resumes the provider thread for one in-place repair turn; the turn must leave HEAD where it was. */
|
|
1594
|
+
async runPrePublicationRepairTurn(options, processRunner, turn) {
|
|
1595
|
+
const { context, outputState, preparedHeadSha } = options;
|
|
1489
1596
|
const { dispatch, worktree } = context;
|
|
1490
|
-
const
|
|
1491
|
-
const
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1597
|
+
const { prompt: focusedPrompt, repairTurn: nextRepairTurn, maxRepairTurns, repairEnvironment, environment } = turn;
|
|
1598
|
+
const repairDispatch = {
|
|
1599
|
+
...dispatch,
|
|
1600
|
+
session: { ...dispatch.session, resumeProviderThreadId: turn.providerThreadId },
|
|
1601
|
+
};
|
|
1602
|
+
const providerPrompt = buildProviderCliPrompt(repairDispatch, focusedPrompt, repairEnvironment);
|
|
1603
|
+
const pipePromptToStdin = shouldPipePromptToStdin(repairDispatch.execution.provider, providerPrompt, usesManagedWindowsHost(repairDispatch));
|
|
1604
|
+
const command = buildProviderCliCommand(repairDispatch, {
|
|
1605
|
+
worktreePath: worktree.worktreePath,
|
|
1606
|
+
prompt: focusedPrompt,
|
|
1607
|
+
promptFromStdin: pipePromptToStdin,
|
|
1608
|
+
runtimeEnvironment: repairEnvironment,
|
|
1609
|
+
});
|
|
1610
|
+
const toolHeartbeat = new ProviderToolActivityHeartbeat(outputState, context.emit, this.providerToolHeartbeatIntervalMs);
|
|
1611
|
+
let result;
|
|
1612
|
+
let providerStarted = false;
|
|
1613
|
+
try {
|
|
1614
|
+
result = await processRunner.run({
|
|
1615
|
+
command: command.command,
|
|
1616
|
+
args: command.args,
|
|
1617
|
+
cwd: worktree.worktreePath,
|
|
1618
|
+
env: environment,
|
|
1619
|
+
resumesProviderThread: Boolean(repairDispatch.session.resumeProviderThreadId),
|
|
1620
|
+
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1621
|
+
}, {
|
|
1622
|
+
onStarted: async () => {
|
|
1496
1623
|
await context.emit({
|
|
1497
1624
|
role: "runner",
|
|
1498
1625
|
kind: "checkpoint",
|
|
1499
|
-
content: `
|
|
1500
|
-
eventType: "
|
|
1501
|
-
data: JSON.stringify({ repairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
return;
|
|
1505
|
-
}
|
|
1506
|
-
catch (error) {
|
|
1507
|
-
if (!(error instanceof PrePublicationValidationError))
|
|
1508
|
-
throw error;
|
|
1509
|
-
if (repairTurn >= maxPrePublicationRepairTurns) {
|
|
1510
|
-
await context.emit({
|
|
1511
|
-
role: "runner",
|
|
1512
|
-
kind: "error",
|
|
1513
|
-
content: `Pre-publication validation still fails after ${maxPrePublicationRepairTurns} in-place repair turns: ${clip(error.message, 4000)}`,
|
|
1514
|
-
eventType: "prepublication_repair_exhausted",
|
|
1515
|
-
data: JSON.stringify({ checkId: error.checkId, repairTurns: repairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1626
|
+
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxRepairTurns} is supervised and ready.`,
|
|
1627
|
+
eventType: "provider_cli_started",
|
|
1516
1628
|
});
|
|
1517
|
-
|
|
1518
|
-
}
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
const providerPrompt = buildProviderCliPrompt(repairDispatch, focusedPrompt, repairEnvironment);
|
|
1530
|
-
const pipePromptToStdin = shouldPipePromptToStdin(repairDispatch.execution.provider, providerPrompt, usesManagedWindowsHost(repairDispatch));
|
|
1531
|
-
const command = buildProviderCliCommand(repairDispatch, {
|
|
1532
|
-
worktreePath: worktree.worktreePath,
|
|
1533
|
-
prompt: focusedPrompt,
|
|
1534
|
-
promptFromStdin: pipePromptToStdin,
|
|
1535
|
-
runtimeEnvironment: repairEnvironment,
|
|
1536
|
-
});
|
|
1629
|
+
providerStarted = true;
|
|
1630
|
+
},
|
|
1631
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1632
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1633
|
+
onStdoutLine: async (line) => {
|
|
1634
|
+
await toolHeartbeat.consume(line);
|
|
1635
|
+
},
|
|
1636
|
+
}, context.signal);
|
|
1637
|
+
}
|
|
1638
|
+
finally {
|
|
1639
|
+
toolHeartbeat.stop();
|
|
1640
|
+
if (providerStarted) {
|
|
1537
1641
|
await context.emit({
|
|
1538
1642
|
role: "runner",
|
|
1539
1643
|
kind: "checkpoint",
|
|
1540
|
-
content: `
|
|
1541
|
-
eventType: "
|
|
1542
|
-
data: JSON.stringify({ checkId: error.checkId, repairTurn: nextRepairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1644
|
+
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxRepairTurns} exited.`,
|
|
1645
|
+
eventType: "provider_cli_completed",
|
|
1543
1646
|
});
|
|
1544
|
-
const toolHeartbeat = new ProviderToolActivityHeartbeat(outputState, context.emit, this.providerToolHeartbeatIntervalMs);
|
|
1545
|
-
let result;
|
|
1546
|
-
let providerStarted = false;
|
|
1547
|
-
try {
|
|
1548
|
-
result = await processRunner.run({
|
|
1549
|
-
command: command.command,
|
|
1550
|
-
args: command.args,
|
|
1551
|
-
cwd: worktree.worktreePath,
|
|
1552
|
-
env: environment,
|
|
1553
|
-
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1554
|
-
}, {
|
|
1555
|
-
onStarted: async () => {
|
|
1556
|
-
await context.emit({
|
|
1557
|
-
role: "runner",
|
|
1558
|
-
kind: "checkpoint",
|
|
1559
|
-
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxPrePublicationRepairTurns} is supervised and ready.`,
|
|
1560
|
-
eventType: "provider_cli_started",
|
|
1561
|
-
});
|
|
1562
|
-
providerStarted = true;
|
|
1563
|
-
},
|
|
1564
|
-
onStdoutLine: async (line) => {
|
|
1565
|
-
await toolHeartbeat.consume(line);
|
|
1566
|
-
},
|
|
1567
|
-
}, context.signal);
|
|
1568
|
-
}
|
|
1569
|
-
finally {
|
|
1570
|
-
toolHeartbeat.stop();
|
|
1571
|
-
if (providerStarted) {
|
|
1572
|
-
await context.emit({
|
|
1573
|
-
role: "runner",
|
|
1574
|
-
kind: "checkpoint",
|
|
1575
|
-
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxPrePublicationRepairTurns} exited.`,
|
|
1576
|
-
eventType: "provider_cli_completed",
|
|
1577
|
-
});
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
if (result.exitCode !== 0)
|
|
1581
|
-
throw providerCliExitFailure(command.command, result);
|
|
1582
|
-
const postRepairHeadSha = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
1583
|
-
if (postRepairHeadSha.toLowerCase() !== preparedHeadSha.toLowerCase()) {
|
|
1584
|
-
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 });
|
|
1585
|
-
}
|
|
1586
1647
|
}
|
|
1587
1648
|
}
|
|
1649
|
+
if (result.exitCode !== 0)
|
|
1650
|
+
throw providerCliExitFailure(command.command, result);
|
|
1651
|
+
const postRepairHeadSha = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
1652
|
+
if (postRepairHeadSha.toLowerCase() !== preparedHeadSha.toLowerCase()) {
|
|
1653
|
+
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 });
|
|
1654
|
+
}
|
|
1588
1655
|
}
|
|
1589
1656
|
}
|
|
1590
|
-
function buildPrePublicationRepairPrompt(error, repairTurn, repairScope) {
|
|
1591
|
-
const invocation = [error.command, ...error.args].join(" ");
|
|
1592
|
-
const priorWork = repairScope === "implementation"
|
|
1593
|
-
? "Keep the completed implementation and its Forge-owned completion artifacts intact."
|
|
1594
|
-
: "Keep the existing PR-comment or CI repairs intact.";
|
|
1595
|
-
return [
|
|
1596
|
-
`Forge pre-publication validation failed after your ${repairScope === "implementation" ? "implementation" : "PR repair"} turn.`,
|
|
1597
|
-
`This is bounded in-place repair turn ${repairTurn}/${maxPrePublicationRepairTurns}.`,
|
|
1598
|
-
`Failed check: ${error.checkId}`,
|
|
1599
|
-
`Command: ${invocation}`,
|
|
1600
|
-
`Exit code: ${error.exitCode}`,
|
|
1601
|
-
"Diagnostics:",
|
|
1602
|
-
error.detail || "The validation command returned no diagnostic output.",
|
|
1603
|
-
"Fix the root cause in the current worktree and run the focused failing check.",
|
|
1604
|
-
`${priorWork} Do not commit, push, rebase, or modify Forge-owned protocol artifacts.`,
|
|
1605
|
-
"When the focused check passes, stop; Bridge will rerun the complete required pre-publication profile and owns commit/push.",
|
|
1606
|
-
].join("\n\n");
|
|
1607
|
-
}
|
|
1608
|
-
function publicationCapabilities(context, runtimeEnvironment) {
|
|
1609
|
-
const capabilities = new Set();
|
|
1610
|
-
const launchTarget = context.dispatch.qaBrowser?.launchTarget;
|
|
1611
|
-
if (runtimeEnvironment?.FORGE_PLAYWRIGHT_CONFIG
|
|
1612
|
-
|| launchTarget?.url
|
|
1613
|
-
|| launchTarget?.command
|
|
1614
|
-
|| launchTarget?.managed_runtime_port) {
|
|
1615
|
-
capabilities.add("browser_launch");
|
|
1616
|
-
}
|
|
1617
|
-
return capabilities;
|
|
1618
|
-
}
|
|
1619
1657
|
async function stageDraftAttachments(dispatch, metadataRoot) {
|
|
1620
1658
|
const attachments = dispatch.draft?.attachments ?? [];
|
|
1621
1659
|
const stageable = attachments.filter((attachment) => (attachment.kind === "text" && typeof attachment.textContent === "string")
|