@loucompanion/forge-bridge 0.1.4-dev.63db04bcffca → 0.1.4-dev.8901ba056f68
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 +2 -2
- package/dist/bridge/bridge.service.d.ts +14 -1
- package/dist/bridge/bridge.service.js +80 -9
- package/dist/bridge/bridge.types.d.ts +11 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- 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/cli/cli.service.js +3 -1
- 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 +52 -0
- package/dist/runtime/host-load-admission.js +84 -0
- package/dist/runtime/host-load-child-environment.d.ts +22 -0
- package/dist/runtime/host-load-child-environment.js +65 -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 +34 -0
- package/dist/runtime/host-load-governor-config.js +46 -0
- package/dist/runtime/host-load-governor.d.ts +172 -0
- package/dist/runtime/host-load-governor.js +519 -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-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 +6 -1
- package/dist/runtime/host-runtime-lease.d.ts +17 -3
- package/dist/runtime/host-runtime-lease.js +138 -13
- package/dist/runtime/host-runtime-promotion.js +12 -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 +11 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +48 -54
- package/dist/sandbox/host-capacity-broker.d.ts +107 -0
- package/dist/sandbox/host-capacity-broker.js +315 -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 +25 -0
- package/dist/session/managed-attempt-tools.js +320 -27
- 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 +45 -0
- package/dist/session/managed-command-host-load.js +82 -0
- package/dist/session/phase-completion.artifacts.js +4 -0
- package/dist/session/phase-completion.d.ts +2 -0
- package/dist/session/phase-completion.runtime.d.ts +1 -1
- package/dist/session/phase-completion.runtime.js +36 -23
- 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-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 +9 -9
- package/dist/session/pre-publication-validation.js +48 -112
- 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 +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +15 -0
- package/dist/session/provider-cli/provider-cli.service.js +141 -33
- package/dist/session/provider-cli/provider-cli.types.d.ts +4 -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/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 +3 -0
- package/dist/session/session.service.d.ts +2 -0
- package/dist/session/session.service.js +21 -4
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +14 -2
- 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/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 +6 -1
- package/dist/worktree/worktree.service.js +14 -2
- package/dist/worktree/worktree.types.d.ts +7 -0
- package/package.json +1 -1
|
@@ -2,14 +2,17 @@ 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 { runtimeAdmissionPriority } from "../../runtime/host-runtime-lease.js";
|
|
6
|
+
import { sandboxHostLoadGateFromEnvironment } from "../sandbox-host-capacity-gate.js";
|
|
5
7
|
import { buildSpecBody, selectLaneCommand } from "../../worktree/artifact-injector.js";
|
|
6
8
|
import { defaultWorktreeCoordinatorStateRoot } from "../../worktree/worktree-paths.js";
|
|
7
9
|
import { completionPhaseFromDispatch, prepareCompletionToolRuntime, readCompletionArtifact, usesDebugCycleCompletion, usesDevelopCycleCompletion } from "../phase-completion.js";
|
|
8
10
|
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,
|
|
11
|
+
import { cleanupCompletionTools, commitWorktreeChanges, completionPhaseFromArtifact, emitArchitectStructuredEvents, emitCompletionArtifactRecorded, emitDecomposeGateArtifacts, emitDraftGateArtifacts, emitPhaseCompletionEvent, emitPhaseGateEvents, emitQaArtifactRecorded, emitQaStructuredEvents, enforceQaBrowserLaunchTargetGate, LiveArchitectArtifactEmitter, LiveCompletionArtifactEmitter, LiveQaArtifactEmitter, readCompletionArtifactsForRun, readQaCompletionArtifactBundle, waitForCompletionArtifact } from "./provider-cli.artifacts.js";
|
|
12
|
+
import { diffClaimedChangedFiles, findUnpublishedWorktreePaths, normalizeChangedFilePath, stagePublishableWorktreeChangeSet, } from "../publishable-worktree-changes.js";
|
|
10
13
|
import { DeterministicProviderCliService } from "./provider-cli.deterministic.js";
|
|
11
14
|
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";
|
|
15
|
+
import { isTransientCodexProviderNotFoundFailure, providerCompletionToolMissingFailure, recoveringProviderProcessRunner, StreamingProviderProcessRunner } from "./provider-cli.process.js";
|
|
13
16
|
import { emitProviderUsageEvent, prePublicationValidationEnv, providerProcessEnv } from "./provider-cli.runtime.js";
|
|
14
17
|
import { clip, createProviderOutputState, parseJsonLine } from "./provider-output-state.js";
|
|
15
18
|
import { writeCiRepairReadinessManifest } from "./ci-repair-readiness.js";
|
|
@@ -68,12 +71,54 @@ function assertCommentRepairArtifactMatchesChanges(artifact, actualChangedFiles)
|
|
|
68
71
|
const claimed = [...new Set(claimedChangedFiles)].sort();
|
|
69
72
|
const actual = [...new Set(normalizedActual)].sort();
|
|
70
73
|
if (hasFixedDisposition && actual.length === 0) {
|
|
71
|
-
throw
|
|
74
|
+
throw commentRepairChangedFilesMismatch("Comment repair fixed dispositions require an actual publishable source diff.");
|
|
72
75
|
}
|
|
73
76
|
if (claimed.length !== actual.length || claimed.some((value, index) => value !== actual[index])) {
|
|
74
|
-
|
|
77
|
+
const { missing, unexpected } = diffClaimedChangedFiles(claimed, actual);
|
|
78
|
+
throw commentRepairChangedFilesMismatch(`Comment repair changed_files must exactly match the publishable staged source diff${formatChangedFilesDelta(missing, unexpected)}.`);
|
|
75
79
|
}
|
|
76
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* A finding resolved as fixed must not point at a file whose edit Forge leaves out of the
|
|
83
|
+
* published commit; otherwise the thread would be resolved without its fix. That covers
|
|
84
|
+
* runtime output Forge unstaged and untracked or git-ignored files it never stages.
|
|
85
|
+
*/
|
|
86
|
+
async function assertFixedFindingsArePublished(git, worktreePath, dispatch, artifact, changeSet) {
|
|
87
|
+
const findingPaths = new Map((dispatch.pullRequest?.reviewFindings ?? []).map(finding => [
|
|
88
|
+
`${finding.kind.trim().toLowerCase()}:${finding.claimId}:${finding.bodySha256.trim().toLowerCase()}`,
|
|
89
|
+
finding.path ? normalizeChangedFilePath(finding.path) : "",
|
|
90
|
+
]));
|
|
91
|
+
const payload = JSON.parse(artifact.verdictJson);
|
|
92
|
+
const dispositions = Array.isArray(payload.dispositions) ? payload.dispositions : [];
|
|
93
|
+
const fixed = dispositions.flatMap(value => {
|
|
94
|
+
const record = value;
|
|
95
|
+
if (record.disposition !== "fixed")
|
|
96
|
+
return [];
|
|
97
|
+
const identity = `${String(record.kind ?? "").trim().toLowerCase()}:${String(record.claim_id ?? "")}:${String(record.body_sha256 ?? "").trim().toLowerCase()}`;
|
|
98
|
+
const findingPath = findingPaths.get(identity);
|
|
99
|
+
return findingPath ? [{ claimId: String(record.claim_id ?? ""), path: findingPath }] : [];
|
|
100
|
+
});
|
|
101
|
+
if (fixed.length === 0)
|
|
102
|
+
return;
|
|
103
|
+
const unpublished = new Set([
|
|
104
|
+
...changeSet.excluded.map(normalizeChangedFilePath),
|
|
105
|
+
...await findUnpublishedWorktreePaths(git, worktreePath, fixed.map(entry => entry.path), changeSet.publishable),
|
|
106
|
+
]);
|
|
107
|
+
const dropped = fixed.filter(entry => unpublished.has(entry.path)).map(entry => `${entry.claimId} (${entry.path})`);
|
|
108
|
+
if (dropped.length > 0) {
|
|
109
|
+
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.`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function commentRepairChangedFilesMismatch(message) {
|
|
113
|
+
return new ForgeFailureError("comment_repair_changed_files_mismatch", message);
|
|
114
|
+
}
|
|
115
|
+
function formatChangedFilesDelta(missing, unexpected) {
|
|
116
|
+
const parts = [
|
|
117
|
+
missing.length > 0 ? `missing from changed_files: ${missing.join(", ")}` : "",
|
|
118
|
+
unexpected.length > 0 ? `not in the publishable diff: ${unexpected.join(", ")}` : "",
|
|
119
|
+
].filter(Boolean);
|
|
120
|
+
return parts.length > 0 ? ` (${parts.join("; ")})` : "";
|
|
121
|
+
}
|
|
77
122
|
async function finalizeCommentRepairChangedFiles(artifact, baselineChangedFiles, actualChangedFiles) {
|
|
78
123
|
const payload = JSON.parse(artifact.verdictJson);
|
|
79
124
|
const claimedRecords = Array.isArray(payload.changed_files)
|
|
@@ -90,11 +135,11 @@ async function finalizeCommentRepairChangedFiles(artifact, baselineChangedFiles,
|
|
|
90
135
|
const dispositions = Array.isArray(payload.dispositions) ? payload.dispositions : [];
|
|
91
136
|
const hasFixedDisposition = dispositions.some(value => value.disposition === "fixed");
|
|
92
137
|
if (hasFixedDisposition && authoritativePaths.length === 0) {
|
|
93
|
-
throw
|
|
138
|
+
throw commentRepairChangedFilesMismatch("Comment repair fixed dispositions require an actual publishable source diff.");
|
|
94
139
|
}
|
|
95
140
|
for (const baselinePath of baselineChangedFiles.map(value => value.trim().replaceAll("\\", "/"))) {
|
|
96
141
|
if (baselinePath && !authoritative.has(baselinePath)) {
|
|
97
|
-
throw
|
|
142
|
+
throw commentRepairChangedFilesMismatch(`Comment repair pre-publication repair removed '${baselinePath}' from the publishable staged source diff.`);
|
|
98
143
|
}
|
|
99
144
|
}
|
|
100
145
|
payload.changed_files = authoritativePaths.map(filePath => {
|
|
@@ -170,16 +215,20 @@ function providerOwnsBranchPublication(context) {
|
|
|
170
215
|
return context.dispatch.sandbox?.executionMode !== "docker";
|
|
171
216
|
}
|
|
172
217
|
function prePublicationExecution(context, environment, defaultRunner, baselineRevision) {
|
|
218
|
+
const hostLoadOwner = {
|
|
219
|
+
dispatchAttemptId: context.dispatch.sandbox?.dispatchAttemptId ?? null,
|
|
220
|
+
priority: runtimeAdmissionPriority(context.dispatch),
|
|
221
|
+
};
|
|
173
222
|
if (context.processRunner)
|
|
174
|
-
return { baselineRevision, environment, processRunner: context.processRunner };
|
|
223
|
+
return { baselineRevision, environment, processRunner: context.processRunner, hostLoadOwner };
|
|
175
224
|
if (context.dispatch.sandbox?.executionMode !== "docker")
|
|
176
|
-
return { baselineRevision, environment };
|
|
225
|
+
return { baselineRevision, environment, hostLoadOwner };
|
|
177
226
|
const expectedSandboxId = context.dispatch.sandbox.dispatchAttemptId;
|
|
178
227
|
const observedSandboxId = context.runtimeEnvironment?.FORGE_SANDBOX_ID ?? process.env.FORGE_SANDBOX_ID;
|
|
179
228
|
if (observedSandboxId !== expectedSandboxId) {
|
|
180
229
|
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
230
|
}
|
|
182
|
-
return { baselineRevision, environment, processRunner: defaultRunner };
|
|
231
|
+
return { baselineRevision, environment, processRunner: defaultRunner, hostLoadOwner };
|
|
183
232
|
}
|
|
184
233
|
function remoteTrackingRefspec(branchName) {
|
|
185
234
|
return `refs/heads/${branchName}:refs/remotes/origin/${branchName}`;
|
|
@@ -389,7 +438,8 @@ export class ManagedVerificationProgressEmitter {
|
|
|
389
438
|
}
|
|
390
439
|
}
|
|
391
440
|
function isManagedVerificationNonterminal(status) {
|
|
392
|
-
return status === "starting" || status === "running" || status === "waiting_for_build_slot"
|
|
441
|
+
return status === "starting" || status === "running" || status === "waiting_for_build_slot"
|
|
442
|
+
|| status === "waiting_for_host_capacity";
|
|
393
443
|
}
|
|
394
444
|
async function parseManagedVerificationSnapshot(receiptPath) {
|
|
395
445
|
try {
|
|
@@ -429,10 +479,17 @@ class ProviderToolActivityHeartbeat {
|
|
|
429
479
|
emit;
|
|
430
480
|
intervalMs;
|
|
431
481
|
timer = null;
|
|
482
|
+
/** Lets the provider runner hold its end-of-turn timers while a tool call is in flight. */
|
|
483
|
+
isToolCallInFlight = () => this.outputState.hasActiveToolCall;
|
|
484
|
+
/** Forgets tool calls a previous generation left open; called before every relaunch. */
|
|
485
|
+
startGeneration = () => this.outputState.resetActiveToolCalls();
|
|
432
486
|
constructor(outputState, emit, intervalMs) {
|
|
433
487
|
this.outputState = outputState;
|
|
434
488
|
this.emit = emit;
|
|
435
489
|
this.intervalMs = intervalMs;
|
|
490
|
+
// Each heartbeat watches one provider generation. Calls an earlier generation left
|
|
491
|
+
// open died with it; inheriting them would hold the new generation's timers forever.
|
|
492
|
+
this.outputState.resetActiveToolCalls();
|
|
436
493
|
}
|
|
437
494
|
async consume(line) {
|
|
438
495
|
const events = this.outputState.consume(line);
|
|
@@ -514,7 +571,12 @@ export class ProcessBackedProviderCliService {
|
|
|
514
571
|
providerToolHeartbeatIntervalMs;
|
|
515
572
|
publicationCoordinator;
|
|
516
573
|
prePublicationValidator;
|
|
517
|
-
constructor(processRunner = new StreamingProviderProcessRunner(), git = new GitClient(), providerToolHeartbeatIntervalMs = defaultProviderToolHeartbeatIntervalMs, publicationCoordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
574
|
+
constructor(processRunner = new StreamingProviderProcessRunner(), git = new GitClient(), providerToolHeartbeatIntervalMs = defaultProviderToolHeartbeatIntervalMs, publicationCoordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
575
|
+
// The Docker sandbox worker (`forge` run-once via ForgeBridgeCliService) builds
|
|
576
|
+
// this default. A container cannot reach the host ledger, so when the host
|
|
577
|
+
// bridge enabled it, its steps ask the bridge for tokens over the sandbox
|
|
578
|
+
// channel (decision 0013); elsewhere the gate is absent and validation is ungated.
|
|
579
|
+
prePublicationValidator = new PrePublicationValidator(undefined, undefined, undefined, sandboxHostLoadGateFromEnvironment())) {
|
|
518
580
|
this.processRunner = processRunner;
|
|
519
581
|
this.git = git;
|
|
520
582
|
this.providerToolHeartbeatIntervalMs = providerToolHeartbeatIntervalMs;
|
|
@@ -533,7 +595,7 @@ export class ProcessBackedProviderCliService {
|
|
|
533
595
|
await fs.writeFile(path.join(metadataRoot, "spec.md"), buildDraftSpec(dispatch), "utf8");
|
|
534
596
|
const stagedAttachments = await stageDraftAttachments(dispatch, metadataRoot);
|
|
535
597
|
const decomposeDraft = isDecomposeDraftDispatch(dispatch);
|
|
536
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: decomposeDraft ? "decompose" : "draft", runtimeEnvironment: context.runtimeEnvironment });
|
|
598
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: decomposeDraft ? "decompose" : "draft", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
537
599
|
const draftPrompt = buildDraftPrompt(dispatch, { attachmentReferences: stagedAttachments.textReferences });
|
|
538
600
|
const providerPrompt = buildProviderCliPrompt(dispatch, draftPrompt, context.runtimeEnvironment);
|
|
539
601
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -586,6 +648,7 @@ export class ProcessBackedProviderCliService {
|
|
|
586
648
|
args: command.args,
|
|
587
649
|
cwd: worktree.worktreePath,
|
|
588
650
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
651
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
589
652
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
590
653
|
}, {
|
|
591
654
|
onStarted: async () => {
|
|
@@ -596,6 +659,8 @@ export class ProcessBackedProviderCliService {
|
|
|
596
659
|
eventType: "provider_cli_started"
|
|
597
660
|
});
|
|
598
661
|
},
|
|
662
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
663
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
599
664
|
onStdoutLine: async (line) => {
|
|
600
665
|
await toolHeartbeat.consume(line);
|
|
601
666
|
}
|
|
@@ -645,7 +710,7 @@ export class ProcessBackedProviderCliService {
|
|
|
645
710
|
await emitDecomposeGateArtifacts(context.emit, worktree.worktreePath, dispatch.workItem.id);
|
|
646
711
|
const proposalArtifact = earlyProposalArtifact ?? await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "decompose");
|
|
647
712
|
if (!proposalArtifact) {
|
|
648
|
-
throw
|
|
713
|
+
throw providerCompletionToolMissingFailure("Provider CLI Decompose completed but did not call forge.complete_decompose_proposal.", result);
|
|
649
714
|
}
|
|
650
715
|
const proposal = parseJsonLine(proposalArtifact.verdictJson) ?? {};
|
|
651
716
|
const proposalJson = proposal["proposal_json"] ?? proposal["decomposition_json"];
|
|
@@ -668,7 +733,7 @@ export class ProcessBackedProviderCliService {
|
|
|
668
733
|
await emitDraftGateArtifacts(context.emit, worktree.worktreePath, dispatch.workItem.id);
|
|
669
734
|
const proposalArtifact = earlyProposalArtifact ?? await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "draft");
|
|
670
735
|
if (!proposalArtifact) {
|
|
671
|
-
throw
|
|
736
|
+
throw providerCompletionToolMissingFailure("Provider CLI Draft completed but did not call forge.complete_draft_proposal.", result);
|
|
672
737
|
}
|
|
673
738
|
const proposal = parseJsonLine(proposalArtifact.verdictJson) ?? {};
|
|
674
739
|
const draftJson = proposal["draft_json"];
|
|
@@ -713,7 +778,7 @@ export class ProcessBackedProviderCliService {
|
|
|
713
778
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
714
779
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
715
780
|
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 });
|
|
781
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase, runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
717
782
|
const implementationPrompt = debugCycle
|
|
718
783
|
? buildDebugCyclePrompt(dispatch, phase)
|
|
719
784
|
: developCycle
|
|
@@ -755,6 +820,7 @@ export class ProcessBackedProviderCliService {
|
|
|
755
820
|
args: command.args,
|
|
756
821
|
cwd: worktree.worktreePath,
|
|
757
822
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
823
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
758
824
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
759
825
|
}, {
|
|
760
826
|
onStarted: async () => {
|
|
@@ -765,6 +831,8 @@ export class ProcessBackedProviderCliService {
|
|
|
765
831
|
eventType: "provider_cli_started"
|
|
766
832
|
});
|
|
767
833
|
},
|
|
834
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
835
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
768
836
|
onStdoutLine: async (line) => {
|
|
769
837
|
await toolHeartbeat.consume(line);
|
|
770
838
|
}
|
|
@@ -806,7 +874,7 @@ export class ProcessBackedProviderCliService {
|
|
|
806
874
|
eventType: "worktree_branch_pushed"
|
|
807
875
|
});
|
|
808
876
|
}
|
|
809
|
-
const completionArtifacts = await readCompletionArtifactsForRun(worktree.worktreePath, dispatch.workItem.id, phase, developCycle, debugCycle);
|
|
877
|
+
const completionArtifacts = await readCompletionArtifactsForRun(worktree.worktreePath, dispatch.workItem.id, phase, developCycle, debugCycle, result);
|
|
810
878
|
for (const artifact of completionArtifacts) {
|
|
811
879
|
if (!liveCompletionEvents.hasEmitted(completionPhaseFromArtifact(artifact))) {
|
|
812
880
|
await emitCompletionArtifactRecorded(context.emit, worktree.worktreePath, artifact);
|
|
@@ -858,7 +926,7 @@ export class ProcessBackedProviderCliService {
|
|
|
858
926
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
859
927
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
860
928
|
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 });
|
|
929
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "architect", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
862
930
|
const architectPrompt = buildArchitectPrompt(dispatch);
|
|
863
931
|
const providerPrompt = buildProviderCliPrompt(dispatch, architectPrompt, context.runtimeEnvironment);
|
|
864
932
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -893,6 +961,7 @@ export class ProcessBackedProviderCliService {
|
|
|
893
961
|
args: command.args,
|
|
894
962
|
cwd: worktree.worktreePath,
|
|
895
963
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
964
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
896
965
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
897
966
|
}, {
|
|
898
967
|
onStarted: async () => {
|
|
@@ -903,6 +972,8 @@ export class ProcessBackedProviderCliService {
|
|
|
903
972
|
eventType: "provider_cli_started"
|
|
904
973
|
});
|
|
905
974
|
},
|
|
975
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
976
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
906
977
|
onStdoutLine: async (line) => await toolHeartbeat.consume(line)
|
|
907
978
|
}, context.signal);
|
|
908
979
|
}
|
|
@@ -923,7 +994,7 @@ export class ProcessBackedProviderCliService {
|
|
|
923
994
|
await emitProviderUsageEvent(context.emit, dispatch, outputState);
|
|
924
995
|
const architectArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "architect");
|
|
925
996
|
if (!architectArtifact) {
|
|
926
|
-
throw
|
|
997
|
+
throw providerCompletionToolMissingFailure("Provider CLI Architect completed but did not call the Forge Architect completion tool.", result);
|
|
927
998
|
}
|
|
928
999
|
if (!liveArchitectEvents.hasEmitted()) {
|
|
929
1000
|
await emitCompletionArtifactRecorded(context.emit, worktree.worktreePath, architectArtifact);
|
|
@@ -960,7 +1031,7 @@ export class ProcessBackedProviderCliService {
|
|
|
960
1031
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
961
1032
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
962
1033
|
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 });
|
|
1034
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "qa", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
964
1035
|
const qaPrompt = buildQaPrompt(dispatch, specBody);
|
|
965
1036
|
const providerPrompt = buildProviderCliPrompt(dispatch, qaPrompt, context.runtimeEnvironment);
|
|
966
1037
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -997,6 +1068,7 @@ export class ProcessBackedProviderCliService {
|
|
|
997
1068
|
args: command.args,
|
|
998
1069
|
cwd: worktree.worktreePath,
|
|
999
1070
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
1071
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
1000
1072
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
1001
1073
|
}, {
|
|
1002
1074
|
onStarted: async () => {
|
|
@@ -1007,6 +1079,8 @@ export class ProcessBackedProviderCliService {
|
|
|
1007
1079
|
eventType: "provider_cli_started"
|
|
1008
1080
|
});
|
|
1009
1081
|
},
|
|
1082
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1083
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1010
1084
|
onStdoutLine: async (line) => await toolHeartbeat.consume(line)
|
|
1011
1085
|
}, context.signal);
|
|
1012
1086
|
}
|
|
@@ -1026,17 +1100,19 @@ export class ProcessBackedProviderCliService {
|
|
|
1026
1100
|
eventType: "provider_cli_completed"
|
|
1027
1101
|
});
|
|
1028
1102
|
await emitProviderUsageEvent(context.emit, dispatch, outputState);
|
|
1103
|
+
const lastRun = { result };
|
|
1029
1104
|
let qaArtifact = await readQaCompletionArtifactBundle(worktree.worktreePath, dispatch.workItem.id, dispatch.cycleRun.ownerType, dispatch.cycleRun.ownerId);
|
|
1030
1105
|
if (!qaArtifact && !(await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "qa"))) {
|
|
1031
1106
|
// A headless provider that ends its turn to "wait for a background watcher"
|
|
1032
1107
|
// exits for good. Resume the same thread instead of failing the session.
|
|
1033
|
-
qaArtifact = await this.recoverMissingQaCompletion({ context, outputState });
|
|
1108
|
+
qaArtifact = await this.recoverMissingQaCompletion({ context, outputState, lastRun });
|
|
1034
1109
|
}
|
|
1035
1110
|
if (!qaArtifact) {
|
|
1036
1111
|
const verdictOnly = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "qa");
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1112
|
+
if (verdictOnly) {
|
|
1113
|
+
throw new Error("Provider CLI QA completed but did not produce the complete durable QA artifact bundle.");
|
|
1114
|
+
}
|
|
1115
|
+
throw providerCompletionToolMissingFailure("Provider CLI QA completed but did not call the Forge QA completion tool.", lastRun.result);
|
|
1040
1116
|
}
|
|
1041
1117
|
await enforceQaBrowserLaunchTargetGate(dispatch, qaArtifact);
|
|
1042
1118
|
if (!liveQaEvents.hasEmitted()) {
|
|
@@ -1096,7 +1172,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1096
1172
|
};
|
|
1097
1173
|
const readiness = await writeCiRepairReadinessManifest(dispatch, worktree.worktreePath, specPath, context.runtimeEnvironment);
|
|
1098
1174
|
repairEnvironment = readiness.environment;
|
|
1099
|
-
completionTools = await prepareCompletionToolRuntime({
|
|
1175
|
+
completionTools = await prepareCompletionToolRuntime({
|
|
1176
|
+
dispatch, worktree, phase: "ci_repair", runtimeEnvironment: repairEnvironment, hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1177
|
+
});
|
|
1100
1178
|
await context.emit({
|
|
1101
1179
|
role: "runner",
|
|
1102
1180
|
kind: "checkpoint",
|
|
@@ -1111,7 +1189,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1111
1189
|
});
|
|
1112
1190
|
}
|
|
1113
1191
|
if (addressComments) {
|
|
1114
|
-
completionTools = await prepareCompletionToolRuntime({
|
|
1192
|
+
completionTools = await prepareCompletionToolRuntime({
|
|
1193
|
+
dispatch, worktree, phase: "comment_repair", runtimeEnvironment: repairEnvironment, hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1194
|
+
});
|
|
1115
1195
|
await context.emit({
|
|
1116
1196
|
role: "runner",
|
|
1117
1197
|
kind: "checkpoint",
|
|
@@ -1149,6 +1229,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1149
1229
|
args: command.args,
|
|
1150
1230
|
cwd: worktree.worktreePath,
|
|
1151
1231
|
env: providerProcessEnv(dispatch, repairEnvironment),
|
|
1232
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
1152
1233
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
1153
1234
|
}, {
|
|
1154
1235
|
onStarted: async () => {
|
|
@@ -1160,6 +1241,8 @@ export class ProcessBackedProviderCliService {
|
|
|
1160
1241
|
});
|
|
1161
1242
|
providerStarted = true;
|
|
1162
1243
|
},
|
|
1244
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1245
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1163
1246
|
onStdoutLine: async (line) => {
|
|
1164
1247
|
await toolHeartbeat.consume(line);
|
|
1165
1248
|
}
|
|
@@ -1194,7 +1277,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1194
1277
|
if (repairChecks) {
|
|
1195
1278
|
repairArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "ci_repair");
|
|
1196
1279
|
if (!repairArtifact) {
|
|
1197
|
-
throw
|
|
1280
|
+
throw providerCompletionToolMissingFailure("Provider CLI completed but did not call forge.complete_ci_repair. Forge did not commit or push the repair.", result);
|
|
1198
1281
|
}
|
|
1199
1282
|
if ((repairArtifact.status ?? "").trim().toLowerCase() !== "pass") {
|
|
1200
1283
|
throw new Error(`CI repair completion gate recorded ${repairArtifact.status}; Forge did not commit or push the repair.`);
|
|
@@ -1202,16 +1285,18 @@ export class ProcessBackedProviderCliService {
|
|
|
1202
1285
|
}
|
|
1203
1286
|
if (addressComments) {
|
|
1204
1287
|
repairArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "comment_repair");
|
|
1288
|
+
const lastRun = { result };
|
|
1205
1289
|
if (!repairArtifact) {
|
|
1206
1290
|
repairArtifact = await this.recoverMissingCommentRepairCompletion({
|
|
1207
1291
|
context,
|
|
1208
1292
|
repairEnvironment,
|
|
1209
1293
|
outputState,
|
|
1210
1294
|
preparedHeadSha,
|
|
1295
|
+
lastRun,
|
|
1211
1296
|
});
|
|
1212
1297
|
}
|
|
1213
1298
|
if (!repairArtifact) {
|
|
1214
|
-
throw
|
|
1299
|
+
throw providerCompletionToolMissingFailure("Provider CLI completed but did not call forge.complete_comment_repair. Forge did not publish or resolve review findings.", lastRun.result);
|
|
1215
1300
|
}
|
|
1216
1301
|
if ((repairArtifact.status ?? "").trim().toLowerCase() !== "pass") {
|
|
1217
1302
|
throw new Error(`Comment repair completion gate recorded ${repairArtifact.status}; Forge did not publish or resolve review findings.`);
|
|
@@ -1220,7 +1305,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1220
1305
|
}
|
|
1221
1306
|
let commentRepairBaselineChangedFiles = null;
|
|
1222
1307
|
if (addressComments && repairArtifact) {
|
|
1223
|
-
|
|
1308
|
+
const baseline = await stagePublishableWorktreeChangeSet(this.git, worktree.worktreePath);
|
|
1309
|
+
commentRepairBaselineChangedFiles = baseline.publishable;
|
|
1310
|
+
await assertFixedFindingsArePublished(this.git, worktree.worktreePath, dispatch, repairArtifact, baseline);
|
|
1224
1311
|
assertCommentRepairArtifactMatchesChanges(repairArtifact, commentRepairBaselineChangedFiles);
|
|
1225
1312
|
}
|
|
1226
1313
|
const validationProfile = repairChecks
|
|
@@ -1236,8 +1323,10 @@ export class ProcessBackedProviderCliService {
|
|
|
1236
1323
|
preparedHeadSha,
|
|
1237
1324
|
repairScope: "pull_request",
|
|
1238
1325
|
});
|
|
1239
|
-
const
|
|
1326
|
+
const stagedChangeSet = await stagePublishableWorktreeChangeSet(this.git, worktree.worktreePath);
|
|
1327
|
+
const stagedChangedFiles = stagedChangeSet.publishable;
|
|
1240
1328
|
if (addressComments && repairArtifact && commentRepairBaselineChangedFiles) {
|
|
1329
|
+
await assertFixedFindingsArePublished(this.git, worktree.worktreePath, dispatch, repairArtifact, stagedChangeSet);
|
|
1241
1330
|
repairArtifact = await finalizeCommentRepairChangedFiles(repairArtifact, commentRepairBaselineChangedFiles, stagedChangedFiles);
|
|
1242
1331
|
}
|
|
1243
1332
|
const committed = await commitWorktreeChanges(this.git, worktree.worktreePath, dispatch.workItem.id, stagedChangedFiles);
|
|
@@ -1311,6 +1400,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1311
1400
|
worktree,
|
|
1312
1401
|
phase: "qa",
|
|
1313
1402
|
runtimeEnvironment: context.runtimeEnvironment,
|
|
1403
|
+
hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1314
1404
|
});
|
|
1315
1405
|
const command = buildProviderCliCommand(recoveryDispatch, {
|
|
1316
1406
|
worktreePath: worktree.worktreePath,
|
|
@@ -1334,13 +1424,19 @@ export class ProcessBackedProviderCliService {
|
|
|
1334
1424
|
args: command.args,
|
|
1335
1425
|
cwd: worktree.worktreePath,
|
|
1336
1426
|
env: providerProcessEnv(recoveryDispatch, context.runtimeEnvironment),
|
|
1427
|
+
resumesProviderThread: Boolean(recoveryDispatch.session.resumeProviderThreadId),
|
|
1337
1428
|
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1338
|
-
}, {
|
|
1429
|
+
}, {
|
|
1430
|
+
onStdoutLine: async (line) => await toolHeartbeat.consume(line),
|
|
1431
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1432
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1433
|
+
}, context.signal);
|
|
1339
1434
|
}
|
|
1340
1435
|
finally {
|
|
1341
1436
|
toolHeartbeat.stop();
|
|
1342
1437
|
await cleanupCompletionTools(completionTools, context.emit);
|
|
1343
1438
|
}
|
|
1439
|
+
options.lastRun.result = result;
|
|
1344
1440
|
if (result.exitCode !== 0)
|
|
1345
1441
|
throw providerCliExitFailure(command.command, result);
|
|
1346
1442
|
const artifact = await readQaCompletionArtifactBundle(worktree.worktreePath, dispatch.workItem.id, dispatch.cycleRun.ownerType, dispatch.cycleRun.ownerId);
|
|
@@ -1397,10 +1493,14 @@ export class ProcessBackedProviderCliService {
|
|
|
1397
1493
|
session: { ...dispatch.session, resumeProviderThreadId: providerThreadId },
|
|
1398
1494
|
};
|
|
1399
1495
|
const recoveryPrompt = [
|
|
1400
|
-
"Forge did not receive the required forge.complete_comment_repair call from your previous turn.",
|
|
1496
|
+
"Forge did not receive the required forge.complete_comment_repair call from your previous turn, so the provider process exited.",
|
|
1497
|
+
"Background watchers, monitors and notifications from that turn did not survive and will never report back,",
|
|
1498
|
+
"and Forge stopped any managed command that process was still running; its receipt reports that.",
|
|
1401
1499
|
"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
|
-
"
|
|
1500
|
+
"Review the current diff and the durable review snapshot and preserve the validation evidence already gathered.",
|
|
1501
|
+
"Check each managed command with forge.get_managed_command, restart any that were interrupted,",
|
|
1502
|
+
"and block on long commands with forge.wait_managed_command, calling it again while command_continues is true.",
|
|
1503
|
+
"Do not end your turn until you have called forge.complete_comment_repair with an evidence-backed disposition for every actionable finding.",
|
|
1404
1504
|
"Do not commit or push; Forge owns publication after the completion gate succeeds.",
|
|
1405
1505
|
].join(" ");
|
|
1406
1506
|
const providerPrompt = buildProviderCliPrompt(recoveryDispatch, recoveryPrompt, repairEnvironment);
|
|
@@ -1410,6 +1510,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1410
1510
|
worktree,
|
|
1411
1511
|
phase: "comment_repair",
|
|
1412
1512
|
runtimeEnvironment: repairEnvironment,
|
|
1513
|
+
hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1413
1514
|
});
|
|
1414
1515
|
const command = buildProviderCliCommand(recoveryDispatch, {
|
|
1415
1516
|
worktreePath: worktree.worktreePath,
|
|
@@ -1434,6 +1535,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1434
1535
|
args: command.args,
|
|
1435
1536
|
cwd: worktree.worktreePath,
|
|
1436
1537
|
env: providerProcessEnv(recoveryDispatch, repairEnvironment),
|
|
1538
|
+
resumesProviderThread: Boolean(recoveryDispatch.session.resumeProviderThreadId),
|
|
1437
1539
|
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1438
1540
|
}, {
|
|
1439
1541
|
onStarted: async () => {
|
|
@@ -1445,6 +1547,8 @@ export class ProcessBackedProviderCliService {
|
|
|
1445
1547
|
eventType: "provider_cli_started",
|
|
1446
1548
|
});
|
|
1447
1549
|
},
|
|
1550
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1551
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1448
1552
|
onStdoutLine: async (line) => {
|
|
1449
1553
|
await toolHeartbeat.consume(line);
|
|
1450
1554
|
},
|
|
@@ -1466,6 +1570,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1466
1570
|
await cleanupCompletionTools(completionTools, context.emit);
|
|
1467
1571
|
}
|
|
1468
1572
|
}
|
|
1573
|
+
options.lastRun.result = result;
|
|
1469
1574
|
if (result.exitCode !== 0)
|
|
1470
1575
|
throw providerCliExitFailure(command.command, result);
|
|
1471
1576
|
const postRecoveryHeadSha = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
@@ -1551,6 +1656,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1551
1656
|
args: command.args,
|
|
1552
1657
|
cwd: worktree.worktreePath,
|
|
1553
1658
|
env: environment,
|
|
1659
|
+
resumesProviderThread: Boolean(repairDispatch.session.resumeProviderThreadId),
|
|
1554
1660
|
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1555
1661
|
}, {
|
|
1556
1662
|
onStarted: async () => {
|
|
@@ -1562,6 +1668,8 @@ export class ProcessBackedProviderCliService {
|
|
|
1562
1668
|
});
|
|
1563
1669
|
providerStarted = true;
|
|
1564
1670
|
},
|
|
1671
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1672
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1565
1673
|
onStdoutLine: async (line) => {
|
|
1566
1674
|
await toolHeartbeat.consume(line);
|
|
1567
1675
|
},
|
|
@@ -5,6 +5,8 @@ export interface ProviderCliRunContext {
|
|
|
5
5
|
readonly dispatch: RunOnceDispatchPacket;
|
|
6
6
|
readonly worktree: WorktreeHandle;
|
|
7
7
|
readonly runtimeEnvironment?: Readonly<Record<string, string>>;
|
|
8
|
+
/** Host load governor variables for the completion MCP server only (decision 0013). */
|
|
9
|
+
readonly hostLoadEnvironment?: Readonly<Record<string, string>>;
|
|
8
10
|
readonly processRunner?: ProviderProcessRunner;
|
|
9
11
|
readonly signal?: AbortSignal;
|
|
10
12
|
emit(event: RunnerDispatchEvent): Promise<void>;
|
|
@@ -13,6 +15,8 @@ export interface ProviderCliDraftContext {
|
|
|
13
15
|
readonly dispatch: RunOnceDispatchPacket;
|
|
14
16
|
readonly worktree: WorktreeHandle;
|
|
15
17
|
readonly runtimeEnvironment?: Readonly<Record<string, string>>;
|
|
18
|
+
/** Host load governor variables for the completion MCP server only (decision 0013). */
|
|
19
|
+
readonly hostLoadEnvironment?: Readonly<Record<string, string>>;
|
|
16
20
|
readonly processRunner?: ProviderProcessRunner;
|
|
17
21
|
readonly signal?: AbortSignal;
|
|
18
22
|
emit(event: RunnerDispatchEvent): Promise<void>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True while an attempt-owned managed command (a receipt under
|
|
3
|
+
* `<FORGE_LOG_DIR>/managed-commands/`) is still starting, queued or running.
|
|
4
|
+
* Unreadable or stale receipts do not count.
|
|
5
|
+
*/
|
|
6
|
+
export declare function hasNonterminalManagedCommand(logDirectory: string | undefined, nowMs?: number): Promise<boolean>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const nonterminalManagedCommandStatuses = new Set(["starting", "running", "waiting_for_build_slot"]);
|
|
4
|
+
// A running receipt is rewritten every 5 s. One that has not changed for a minute
|
|
5
|
+
// belongs to a command whose supervisor is gone, so it no longer holds the provider open.
|
|
6
|
+
const runningReceiptStaleMs = 60_000;
|
|
7
|
+
// Starting and queued receipts are written once. They hold the provider open for at most
|
|
8
|
+
// the command's own timeout (the managed-command maximum when absent) plus a margin.
|
|
9
|
+
const maximumManagedCommandTimeoutMs = 2 * 60 * 60_000;
|
|
10
|
+
const queuedReceiptMarginMs = 60_000;
|
|
11
|
+
/**
|
|
12
|
+
* True while an attempt-owned managed command (a receipt under
|
|
13
|
+
* `<FORGE_LOG_DIR>/managed-commands/`) is still starting, queued or running.
|
|
14
|
+
* Unreadable or stale receipts do not count.
|
|
15
|
+
*/
|
|
16
|
+
export async function hasNonterminalManagedCommand(logDirectory, nowMs = Date.now()) {
|
|
17
|
+
if (!logDirectory?.trim())
|
|
18
|
+
return false;
|
|
19
|
+
const directory = path.join(logDirectory, "managed-commands");
|
|
20
|
+
const names = await fs.readdir(directory).catch(() => []);
|
|
21
|
+
for (const name of names) {
|
|
22
|
+
if (!name.endsWith(".receipt.json"))
|
|
23
|
+
continue;
|
|
24
|
+
if (await receiptHoldsProvider(path.join(directory, name), nowMs))
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
async function receiptHoldsProvider(receiptPath, nowMs) {
|
|
30
|
+
try {
|
|
31
|
+
const [stat, content] = await Promise.all([fs.stat(receiptPath), fs.readFile(receiptPath, "utf8")]);
|
|
32
|
+
const receipt = JSON.parse(content);
|
|
33
|
+
const status = typeof receipt.status === "string" ? receipt.status : "";
|
|
34
|
+
if (!nonterminalManagedCommandStatuses.has(status))
|
|
35
|
+
return false;
|
|
36
|
+
const ageMs = nowMs - stat.mtimeMs;
|
|
37
|
+
if (status === "running")
|
|
38
|
+
return ageMs <= runningReceiptStaleMs;
|
|
39
|
+
const timeoutMs = typeof receipt.timeout_ms === "number" && Number.isFinite(receipt.timeout_ms)
|
|
40
|
+
? receipt.timeout_ms
|
|
41
|
+
: maximumManagedCommandTimeoutMs;
|
|
42
|
+
return ageMs <= timeoutMs + queuedReceiptMarginMs;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -9,6 +9,12 @@ export interface ProviderOutputState {
|
|
|
9
9
|
finalMessage: string | null;
|
|
10
10
|
/** True only while the provider has reported a tool/command start without a matching completion. */
|
|
11
11
|
readonly hasActiveToolCall: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Forgets tool calls a previous provider generation started but never completed. A
|
|
14
|
+
* generation that exits mid-call reports no completion, and the next generation must not
|
|
15
|
+
* inherit that call as still in flight.
|
|
16
|
+
*/
|
|
17
|
+
resetActiveToolCalls(): void;
|
|
12
18
|
/** Accumulated provider-reported token usage for this run, or null when none was reported. */
|
|
13
19
|
readonly usage: ProviderUsage | null;
|
|
14
20
|
consume(line: string): readonly RunnerDispatchEvent[];
|
|
@@ -43,6 +43,9 @@ class CursorStreamJsonState {
|
|
|
43
43
|
get hasActiveToolCall() {
|
|
44
44
|
return this.activeToolCallCount > 0;
|
|
45
45
|
}
|
|
46
|
+
resetActiveToolCalls() {
|
|
47
|
+
this.activeToolCallCount = 0;
|
|
48
|
+
}
|
|
46
49
|
consume(line) {
|
|
47
50
|
const event = parseJsonLine(line);
|
|
48
51
|
if (!event) {
|
|
@@ -264,6 +267,9 @@ class ClaudeStreamJsonState {
|
|
|
264
267
|
get hasActiveToolCall() {
|
|
265
268
|
return this.activeToolUses.size > 0;
|
|
266
269
|
}
|
|
270
|
+
resetActiveToolCalls() {
|
|
271
|
+
this.activeToolUses.clear();
|
|
272
|
+
}
|
|
267
273
|
consume(line) {
|
|
268
274
|
const event = parseJsonLine(line);
|
|
269
275
|
if (!event) {
|
|
@@ -544,6 +550,9 @@ class CodexJsonState {
|
|
|
544
550
|
get hasActiveToolCall() {
|
|
545
551
|
return this.activeToolCallCount > 0;
|
|
546
552
|
}
|
|
553
|
+
resetActiveToolCalls() {
|
|
554
|
+
this.activeToolCallCount = 0;
|
|
555
|
+
}
|
|
547
556
|
consume(line) {
|
|
548
557
|
const event = parseJsonLine(line);
|
|
549
558
|
if (!event) {
|