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