@loucompanion/forge-bridge 0.1.4-dev.c2f22d1dd395 → 0.1.4-dev.e1b4f55fb18d
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 +2 -0
- package/dist/bridge/bridge.service.js +30 -5
- package/dist/bridge/bridge.types.d.ts +5 -0
- package/dist/bridge/runner-host-capabilities.d.ts +2 -0
- package/dist/bridge/runner-host-capabilities.js +4 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +57 -100
- package/dist/cleanup/cleanup.types.d.ts +4 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.service.js +10 -2
- 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 +43 -0
- package/dist/runtime/host-load-sampler.js +74 -6
- 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 +21 -1
- package/dist/runtime/host-pressure-stall.js +48 -1
- package/dist/runtime/host-runtime-contract.d.ts +3 -0
- package/dist/runtime/host-runtime-contract.js +4 -1
- package/dist/runtime/host-runtime-lease.d.ts +17 -3
- package/dist/runtime/host-runtime-lease.js +83 -4
- 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/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 +2 -0
- package/dist/session/managed-attempt-tools.js +156 -37
- package/dist/session/managed-command-host-load.d.ts +45 -0
- package/dist/session/managed-command-host-load.js +82 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +7 -0
- package/dist/session/phase-completion.artifacts.js +94 -25
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +4 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +4 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -3
- package/dist/session/phase-completion.runtime.js +49 -19
- 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 +184 -209
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +46 -92
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-process.d.ts +3 -0
- package/dist/session/pre-publication-process.js +23 -11
- 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 +21 -55
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
- package/dist/session/provider-cli/provider-cli.artifacts.js +20 -7
- 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 +32 -1
- package/dist/session/provider-cli/provider-cli.process.js +122 -30
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +16 -1
- package/dist/session/provider-cli/provider-cli.service.js +80 -23
- 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 +10 -1
- package/dist/session/publishable-worktree-changes.js +21 -5
- 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 +11 -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 +10 -1
- package/dist/worktree/worktree.service.js +42 -2
- package/dist/worktree/worktree.types.d.ts +7 -0
- package/package.json +1 -1
|
@@ -2,6 +2,8 @@ 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";
|
|
@@ -10,7 +12,7 @@ import { cleanupCompletionTools, commitWorktreeChanges, completionPhaseFromArtif
|
|
|
10
12
|
import { diffClaimedChangedFiles, findUnpublishedWorktreePaths, normalizeChangedFilePath, stagePublishableWorktreeChangeSet, } from "../publishable-worktree-changes.js";
|
|
11
13
|
import { DeterministicProviderCliService } from "./provider-cli.deterministic.js";
|
|
12
14
|
import { buildArchitectPrompt, buildConflictResolvePrompt, buildDebugCyclePrompt, buildDevelopCyclePrompt, buildDraftPrompt, buildDraftSpec, buildImplementationPrompt, buildProviderCliPrompt, buildProviderCliCommand, durableDraftInput, buildPullRequestCheckRepairPrompt, buildPullRequestCommentsPrompt, buildQaPrompt, formatProviderCliCommandForCheckpoint, isDecomposeDraftDispatch, isPullRequestCheckRepairDispatch, isPullRequestCommentsDispatch } from "./provider-cli.prompts.js";
|
|
13
|
-
import { isTransientCodexProviderNotFoundFailure, recoveringProviderProcessRunner, StreamingProviderProcessRunner } from "./provider-cli.process.js";
|
|
15
|
+
import { isTransientCodexProviderNotFoundFailure, providerCompletionToolMissingFailure, recoveringProviderProcessRunner, StreamingProviderProcessRunner } from "./provider-cli.process.js";
|
|
14
16
|
import { emitProviderUsageEvent, prePublicationValidationEnv, providerProcessEnv } from "./provider-cli.runtime.js";
|
|
15
17
|
import { clip, createProviderOutputState, parseJsonLine } from "./provider-output-state.js";
|
|
16
18
|
import { writeCiRepairReadinessManifest } from "./ci-repair-readiness.js";
|
|
@@ -213,16 +215,20 @@ function providerOwnsBranchPublication(context) {
|
|
|
213
215
|
return context.dispatch.sandbox?.executionMode !== "docker";
|
|
214
216
|
}
|
|
215
217
|
function prePublicationExecution(context, environment, defaultRunner, baselineRevision) {
|
|
218
|
+
const hostLoadOwner = {
|
|
219
|
+
dispatchAttemptId: context.dispatch.sandbox?.dispatchAttemptId ?? null,
|
|
220
|
+
priority: runtimeAdmissionPriority(context.dispatch),
|
|
221
|
+
};
|
|
216
222
|
if (context.processRunner)
|
|
217
|
-
return { baselineRevision, environment, processRunner: context.processRunner };
|
|
223
|
+
return { baselineRevision, environment, processRunner: context.processRunner, hostLoadOwner };
|
|
218
224
|
if (context.dispatch.sandbox?.executionMode !== "docker")
|
|
219
|
-
return { baselineRevision, environment };
|
|
225
|
+
return { baselineRevision, environment, hostLoadOwner };
|
|
220
226
|
const expectedSandboxId = context.dispatch.sandbox.dispatchAttemptId;
|
|
221
227
|
const observedSandboxId = context.runtimeEnvironment?.FORGE_SANDBOX_ID ?? process.env.FORGE_SANDBOX_ID;
|
|
222
228
|
if (observedSandboxId !== expectedSandboxId) {
|
|
223
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");
|
|
224
230
|
}
|
|
225
|
-
return { baselineRevision, environment, processRunner: defaultRunner };
|
|
231
|
+
return { baselineRevision, environment, processRunner: defaultRunner, hostLoadOwner };
|
|
226
232
|
}
|
|
227
233
|
function remoteTrackingRefspec(branchName) {
|
|
228
234
|
return `refs/heads/${branchName}:refs/remotes/origin/${branchName}`;
|
|
@@ -432,7 +438,8 @@ export class ManagedVerificationProgressEmitter {
|
|
|
432
438
|
}
|
|
433
439
|
}
|
|
434
440
|
function isManagedVerificationNonterminal(status) {
|
|
435
|
-
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";
|
|
436
443
|
}
|
|
437
444
|
async function parseManagedVerificationSnapshot(receiptPath) {
|
|
438
445
|
try {
|
|
@@ -472,10 +479,17 @@ class ProviderToolActivityHeartbeat {
|
|
|
472
479
|
emit;
|
|
473
480
|
intervalMs;
|
|
474
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();
|
|
475
486
|
constructor(outputState, emit, intervalMs) {
|
|
476
487
|
this.outputState = outputState;
|
|
477
488
|
this.emit = emit;
|
|
478
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();
|
|
479
493
|
}
|
|
480
494
|
async consume(line) {
|
|
481
495
|
const events = this.outputState.consume(line);
|
|
@@ -557,7 +571,12 @@ export class ProcessBackedProviderCliService {
|
|
|
557
571
|
providerToolHeartbeatIntervalMs;
|
|
558
572
|
publicationCoordinator;
|
|
559
573
|
prePublicationValidator;
|
|
560
|
-
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())) {
|
|
561
580
|
this.processRunner = processRunner;
|
|
562
581
|
this.git = git;
|
|
563
582
|
this.providerToolHeartbeatIntervalMs = providerToolHeartbeatIntervalMs;
|
|
@@ -576,7 +595,7 @@ export class ProcessBackedProviderCliService {
|
|
|
576
595
|
await fs.writeFile(path.join(metadataRoot, "spec.md"), buildDraftSpec(dispatch), "utf8");
|
|
577
596
|
const stagedAttachments = await stageDraftAttachments(dispatch, metadataRoot);
|
|
578
597
|
const decomposeDraft = isDecomposeDraftDispatch(dispatch);
|
|
579
|
-
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 });
|
|
580
599
|
const draftPrompt = buildDraftPrompt(dispatch, { attachmentReferences: stagedAttachments.textReferences });
|
|
581
600
|
const providerPrompt = buildProviderCliPrompt(dispatch, draftPrompt, context.runtimeEnvironment);
|
|
582
601
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -629,6 +648,7 @@ export class ProcessBackedProviderCliService {
|
|
|
629
648
|
args: command.args,
|
|
630
649
|
cwd: worktree.worktreePath,
|
|
631
650
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
651
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
632
652
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
633
653
|
}, {
|
|
634
654
|
onStarted: async () => {
|
|
@@ -639,6 +659,8 @@ export class ProcessBackedProviderCliService {
|
|
|
639
659
|
eventType: "provider_cli_started"
|
|
640
660
|
});
|
|
641
661
|
},
|
|
662
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
663
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
642
664
|
onStdoutLine: async (line) => {
|
|
643
665
|
await toolHeartbeat.consume(line);
|
|
644
666
|
}
|
|
@@ -688,7 +710,7 @@ export class ProcessBackedProviderCliService {
|
|
|
688
710
|
await emitDecomposeGateArtifacts(context.emit, worktree.worktreePath, dispatch.workItem.id);
|
|
689
711
|
const proposalArtifact = earlyProposalArtifact ?? await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "decompose");
|
|
690
712
|
if (!proposalArtifact) {
|
|
691
|
-
throw
|
|
713
|
+
throw providerCompletionToolMissingFailure("Provider CLI Decompose completed but did not call forge.complete_decompose_proposal.", result);
|
|
692
714
|
}
|
|
693
715
|
const proposal = parseJsonLine(proposalArtifact.verdictJson) ?? {};
|
|
694
716
|
const proposalJson = proposal["proposal_json"] ?? proposal["decomposition_json"];
|
|
@@ -711,7 +733,7 @@ export class ProcessBackedProviderCliService {
|
|
|
711
733
|
await emitDraftGateArtifacts(context.emit, worktree.worktreePath, dispatch.workItem.id);
|
|
712
734
|
const proposalArtifact = earlyProposalArtifact ?? await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "draft");
|
|
713
735
|
if (!proposalArtifact) {
|
|
714
|
-
throw
|
|
736
|
+
throw providerCompletionToolMissingFailure("Provider CLI Draft completed but did not call forge.complete_draft_proposal.", result);
|
|
715
737
|
}
|
|
716
738
|
const proposal = parseJsonLine(proposalArtifact.verdictJson) ?? {};
|
|
717
739
|
const draftJson = proposal["draft_json"];
|
|
@@ -756,7 +778,7 @@ export class ProcessBackedProviderCliService {
|
|
|
756
778
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
757
779
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
758
780
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" }) + "\n", "utf8");
|
|
759
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase, runtimeEnvironment: context.runtimeEnvironment });
|
|
781
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase, runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
760
782
|
const implementationPrompt = debugCycle
|
|
761
783
|
? buildDebugCyclePrompt(dispatch, phase)
|
|
762
784
|
: developCycle
|
|
@@ -798,6 +820,7 @@ export class ProcessBackedProviderCliService {
|
|
|
798
820
|
args: command.args,
|
|
799
821
|
cwd: worktree.worktreePath,
|
|
800
822
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
823
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
801
824
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
802
825
|
}, {
|
|
803
826
|
onStarted: async () => {
|
|
@@ -808,6 +831,8 @@ export class ProcessBackedProviderCliService {
|
|
|
808
831
|
eventType: "provider_cli_started"
|
|
809
832
|
});
|
|
810
833
|
},
|
|
834
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
835
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
811
836
|
onStdoutLine: async (line) => {
|
|
812
837
|
await toolHeartbeat.consume(line);
|
|
813
838
|
}
|
|
@@ -849,7 +874,7 @@ export class ProcessBackedProviderCliService {
|
|
|
849
874
|
eventType: "worktree_branch_pushed"
|
|
850
875
|
});
|
|
851
876
|
}
|
|
852
|
-
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);
|
|
853
878
|
for (const artifact of completionArtifacts) {
|
|
854
879
|
if (!liveCompletionEvents.hasEmitted(completionPhaseFromArtifact(artifact))) {
|
|
855
880
|
await emitCompletionArtifactRecorded(context.emit, worktree.worktreePath, artifact);
|
|
@@ -901,7 +926,7 @@ export class ProcessBackedProviderCliService {
|
|
|
901
926
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
902
927
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
903
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");
|
|
904
|
-
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 });
|
|
905
930
|
const architectPrompt = buildArchitectPrompt(dispatch);
|
|
906
931
|
const providerPrompt = buildProviderCliPrompt(dispatch, architectPrompt, context.runtimeEnvironment);
|
|
907
932
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -936,6 +961,7 @@ export class ProcessBackedProviderCliService {
|
|
|
936
961
|
args: command.args,
|
|
937
962
|
cwd: worktree.worktreePath,
|
|
938
963
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
964
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
939
965
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
940
966
|
}, {
|
|
941
967
|
onStarted: async () => {
|
|
@@ -946,6 +972,8 @@ export class ProcessBackedProviderCliService {
|
|
|
946
972
|
eventType: "provider_cli_started"
|
|
947
973
|
});
|
|
948
974
|
},
|
|
975
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
976
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
949
977
|
onStdoutLine: async (line) => await toolHeartbeat.consume(line)
|
|
950
978
|
}, context.signal);
|
|
951
979
|
}
|
|
@@ -966,7 +994,7 @@ export class ProcessBackedProviderCliService {
|
|
|
966
994
|
await emitProviderUsageEvent(context.emit, dispatch, outputState);
|
|
967
995
|
const architectArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "architect");
|
|
968
996
|
if (!architectArtifact) {
|
|
969
|
-
throw
|
|
997
|
+
throw providerCompletionToolMissingFailure("Provider CLI Architect completed but did not call the Forge Architect completion tool.", result);
|
|
970
998
|
}
|
|
971
999
|
if (!liveArchitectEvents.hasEmitted()) {
|
|
972
1000
|
await emitCompletionArtifactRecorded(context.emit, worktree.worktreePath, architectArtifact);
|
|
@@ -1003,7 +1031,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1003
1031
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
1004
1032
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
1005
1033
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" }) + "\n", "utf8");
|
|
1006
|
-
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 });
|
|
1007
1035
|
const qaPrompt = buildQaPrompt(dispatch, specBody);
|
|
1008
1036
|
const providerPrompt = buildProviderCliPrompt(dispatch, qaPrompt, context.runtimeEnvironment);
|
|
1009
1037
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -1040,6 +1068,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1040
1068
|
args: command.args,
|
|
1041
1069
|
cwd: worktree.worktreePath,
|
|
1042
1070
|
env: providerProcessEnv(dispatch, context.runtimeEnvironment),
|
|
1071
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
1043
1072
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
1044
1073
|
}, {
|
|
1045
1074
|
onStarted: async () => {
|
|
@@ -1050,6 +1079,8 @@ export class ProcessBackedProviderCliService {
|
|
|
1050
1079
|
eventType: "provider_cli_started"
|
|
1051
1080
|
});
|
|
1052
1081
|
},
|
|
1082
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1083
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1053
1084
|
onStdoutLine: async (line) => await toolHeartbeat.consume(line)
|
|
1054
1085
|
}, context.signal);
|
|
1055
1086
|
}
|
|
@@ -1069,17 +1100,19 @@ export class ProcessBackedProviderCliService {
|
|
|
1069
1100
|
eventType: "provider_cli_completed"
|
|
1070
1101
|
});
|
|
1071
1102
|
await emitProviderUsageEvent(context.emit, dispatch, outputState);
|
|
1103
|
+
const lastRun = { result };
|
|
1072
1104
|
let qaArtifact = await readQaCompletionArtifactBundle(worktree.worktreePath, dispatch.workItem.id, dispatch.cycleRun.ownerType, dispatch.cycleRun.ownerId);
|
|
1073
1105
|
if (!qaArtifact && !(await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "qa"))) {
|
|
1074
1106
|
// A headless provider that ends its turn to "wait for a background watcher"
|
|
1075
1107
|
// exits for good. Resume the same thread instead of failing the session.
|
|
1076
|
-
qaArtifact = await this.recoverMissingQaCompletion({ context, outputState });
|
|
1108
|
+
qaArtifact = await this.recoverMissingQaCompletion({ context, outputState, lastRun });
|
|
1077
1109
|
}
|
|
1078
1110
|
if (!qaArtifact) {
|
|
1079
1111
|
const verdictOnly = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "qa");
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
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);
|
|
1083
1116
|
}
|
|
1084
1117
|
await enforceQaBrowserLaunchTargetGate(dispatch, qaArtifact);
|
|
1085
1118
|
if (!liveQaEvents.hasEmitted()) {
|
|
@@ -1139,7 +1172,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1139
1172
|
};
|
|
1140
1173
|
const readiness = await writeCiRepairReadinessManifest(dispatch, worktree.worktreePath, specPath, context.runtimeEnvironment);
|
|
1141
1174
|
repairEnvironment = readiness.environment;
|
|
1142
|
-
completionTools = await prepareCompletionToolRuntime({
|
|
1175
|
+
completionTools = await prepareCompletionToolRuntime({
|
|
1176
|
+
dispatch, worktree, phase: "ci_repair", runtimeEnvironment: repairEnvironment, hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1177
|
+
});
|
|
1143
1178
|
await context.emit({
|
|
1144
1179
|
role: "runner",
|
|
1145
1180
|
kind: "checkpoint",
|
|
@@ -1154,7 +1189,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1154
1189
|
});
|
|
1155
1190
|
}
|
|
1156
1191
|
if (addressComments) {
|
|
1157
|
-
completionTools = await prepareCompletionToolRuntime({
|
|
1192
|
+
completionTools = await prepareCompletionToolRuntime({
|
|
1193
|
+
dispatch, worktree, phase: "comment_repair", runtimeEnvironment: repairEnvironment, hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1194
|
+
});
|
|
1158
1195
|
await context.emit({
|
|
1159
1196
|
role: "runner",
|
|
1160
1197
|
kind: "checkpoint",
|
|
@@ -1192,6 +1229,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1192
1229
|
args: command.args,
|
|
1193
1230
|
cwd: worktree.worktreePath,
|
|
1194
1231
|
env: providerProcessEnv(dispatch, repairEnvironment),
|
|
1232
|
+
resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
|
|
1195
1233
|
stdin: pipePromptToStdin ? providerPrompt : undefined
|
|
1196
1234
|
}, {
|
|
1197
1235
|
onStarted: async () => {
|
|
@@ -1203,6 +1241,8 @@ export class ProcessBackedProviderCliService {
|
|
|
1203
1241
|
});
|
|
1204
1242
|
providerStarted = true;
|
|
1205
1243
|
},
|
|
1244
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1245
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1206
1246
|
onStdoutLine: async (line) => {
|
|
1207
1247
|
await toolHeartbeat.consume(line);
|
|
1208
1248
|
}
|
|
@@ -1237,7 +1277,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1237
1277
|
if (repairChecks) {
|
|
1238
1278
|
repairArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "ci_repair");
|
|
1239
1279
|
if (!repairArtifact) {
|
|
1240
|
-
throw
|
|
1280
|
+
throw providerCompletionToolMissingFailure("Provider CLI completed but did not call forge.complete_ci_repair. Forge did not commit or push the repair.", result);
|
|
1241
1281
|
}
|
|
1242
1282
|
if ((repairArtifact.status ?? "").trim().toLowerCase() !== "pass") {
|
|
1243
1283
|
throw new Error(`CI repair completion gate recorded ${repairArtifact.status}; Forge did not commit or push the repair.`);
|
|
@@ -1245,16 +1285,18 @@ export class ProcessBackedProviderCliService {
|
|
|
1245
1285
|
}
|
|
1246
1286
|
if (addressComments) {
|
|
1247
1287
|
repairArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "comment_repair");
|
|
1288
|
+
const lastRun = { result };
|
|
1248
1289
|
if (!repairArtifact) {
|
|
1249
1290
|
repairArtifact = await this.recoverMissingCommentRepairCompletion({
|
|
1250
1291
|
context,
|
|
1251
1292
|
repairEnvironment,
|
|
1252
1293
|
outputState,
|
|
1253
1294
|
preparedHeadSha,
|
|
1295
|
+
lastRun,
|
|
1254
1296
|
});
|
|
1255
1297
|
}
|
|
1256
1298
|
if (!repairArtifact) {
|
|
1257
|
-
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);
|
|
1258
1300
|
}
|
|
1259
1301
|
if ((repairArtifact.status ?? "").trim().toLowerCase() !== "pass") {
|
|
1260
1302
|
throw new Error(`Comment repair completion gate recorded ${repairArtifact.status}; Forge did not publish or resolve review findings.`);
|
|
@@ -1358,6 +1400,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1358
1400
|
worktree,
|
|
1359
1401
|
phase: "qa",
|
|
1360
1402
|
runtimeEnvironment: context.runtimeEnvironment,
|
|
1403
|
+
hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1361
1404
|
});
|
|
1362
1405
|
const command = buildProviderCliCommand(recoveryDispatch, {
|
|
1363
1406
|
worktreePath: worktree.worktreePath,
|
|
@@ -1381,13 +1424,19 @@ export class ProcessBackedProviderCliService {
|
|
|
1381
1424
|
args: command.args,
|
|
1382
1425
|
cwd: worktree.worktreePath,
|
|
1383
1426
|
env: providerProcessEnv(recoveryDispatch, context.runtimeEnvironment),
|
|
1427
|
+
resumesProviderThread: Boolean(recoveryDispatch.session.resumeProviderThreadId),
|
|
1384
1428
|
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1385
|
-
}, {
|
|
1429
|
+
}, {
|
|
1430
|
+
onStdoutLine: async (line) => await toolHeartbeat.consume(line),
|
|
1431
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1432
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1433
|
+
}, context.signal);
|
|
1386
1434
|
}
|
|
1387
1435
|
finally {
|
|
1388
1436
|
toolHeartbeat.stop();
|
|
1389
1437
|
await cleanupCompletionTools(completionTools, context.emit);
|
|
1390
1438
|
}
|
|
1439
|
+
options.lastRun.result = result;
|
|
1391
1440
|
if (result.exitCode !== 0)
|
|
1392
1441
|
throw providerCliExitFailure(command.command, result);
|
|
1393
1442
|
const artifact = await readQaCompletionArtifactBundle(worktree.worktreePath, dispatch.workItem.id, dispatch.cycleRun.ownerType, dispatch.cycleRun.ownerId);
|
|
@@ -1461,6 +1510,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1461
1510
|
worktree,
|
|
1462
1511
|
phase: "comment_repair",
|
|
1463
1512
|
runtimeEnvironment: repairEnvironment,
|
|
1513
|
+
hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1464
1514
|
});
|
|
1465
1515
|
const command = buildProviderCliCommand(recoveryDispatch, {
|
|
1466
1516
|
worktreePath: worktree.worktreePath,
|
|
@@ -1485,6 +1535,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1485
1535
|
args: command.args,
|
|
1486
1536
|
cwd: worktree.worktreePath,
|
|
1487
1537
|
env: providerProcessEnv(recoveryDispatch, repairEnvironment),
|
|
1538
|
+
resumesProviderThread: Boolean(recoveryDispatch.session.resumeProviderThreadId),
|
|
1488
1539
|
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1489
1540
|
}, {
|
|
1490
1541
|
onStarted: async () => {
|
|
@@ -1496,6 +1547,8 @@ export class ProcessBackedProviderCliService {
|
|
|
1496
1547
|
eventType: "provider_cli_started",
|
|
1497
1548
|
});
|
|
1498
1549
|
},
|
|
1550
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1551
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1499
1552
|
onStdoutLine: async (line) => {
|
|
1500
1553
|
await toolHeartbeat.consume(line);
|
|
1501
1554
|
},
|
|
@@ -1517,6 +1570,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1517
1570
|
await cleanupCompletionTools(completionTools, context.emit);
|
|
1518
1571
|
}
|
|
1519
1572
|
}
|
|
1573
|
+
options.lastRun.result = result;
|
|
1520
1574
|
if (result.exitCode !== 0)
|
|
1521
1575
|
throw providerCliExitFailure(command.command, result);
|
|
1522
1576
|
const postRecoveryHeadSha = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
@@ -1602,6 +1656,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1602
1656
|
args: command.args,
|
|
1603
1657
|
cwd: worktree.worktreePath,
|
|
1604
1658
|
env: environment,
|
|
1659
|
+
resumesProviderThread: Boolean(repairDispatch.session.resumeProviderThreadId),
|
|
1605
1660
|
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1606
1661
|
}, {
|
|
1607
1662
|
onStarted: async () => {
|
|
@@ -1613,6 +1668,8 @@ export class ProcessBackedProviderCliService {
|
|
|
1613
1668
|
});
|
|
1614
1669
|
providerStarted = true;
|
|
1615
1670
|
},
|
|
1671
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1672
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1616
1673
|
onStdoutLine: async (line) => {
|
|
1617
1674
|
await toolHeartbeat.consume(line);
|
|
1618
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) {
|
|
@@ -16,7 +16,16 @@ export interface PublishableWorktreeChangeSet {
|
|
|
16
16
|
* `.forge/` file that differs from HEAD is an author edit and must be published.
|
|
17
17
|
*/
|
|
18
18
|
export declare function isNonPublishableWorktreeChange(relativePath: string, status: string): boolean;
|
|
19
|
-
/**
|
|
19
|
+
/** `.local/`, `.forge/work-items/` and `.forge/stories/`: never published, even during a merge. */
|
|
20
|
+
export declare function isRuntimeOnlyPath(relativePath: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Stages every publishable worktree change in the real index and returns both sets.
|
|
23
|
+
*
|
|
24
|
+
* During an in-progress merge it first refuses unresolved conflicts, and afterwards
|
|
25
|
+
* restores merge-owned paths that the exclusion unstaged back to HEAD (the story side),
|
|
26
|
+
* such as `.forge/` files the target branch added (#491). Runtime-only paths are never
|
|
27
|
+
* restored.
|
|
28
|
+
*/
|
|
20
29
|
export declare function stagePublishableWorktreeChangeSet(git: Pick<GitClient, "run">, worktreePath: string): Promise<PublishableWorktreeChangeSet>;
|
|
21
30
|
/**
|
|
22
31
|
* Computes the same change set as {@link stagePublishableWorktreeChangeSet} without
|
|
@@ -3,6 +3,7 @@ import os from "node:os";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { GitClient } from "../shared/git/git.js";
|
|
5
5
|
import { NodeProcessRunner } from "../shared/process/process.js";
|
|
6
|
+
import { assertNoUnresolvedMergeConflicts, restoreMergeOwnedPaths } from "./provider-cli/provider-cli.merge-integrity.js";
|
|
6
7
|
/**
|
|
7
8
|
* Forge runtime output that is never published, whether or not the target repository
|
|
8
9
|
* tracks other `.forge/` content. Completion artifacts and evidence live here.
|
|
@@ -20,7 +21,7 @@ const resetBatchSize = 200;
|
|
|
20
21
|
*/
|
|
21
22
|
export function isNonPublishableWorktreeChange(relativePath, status) {
|
|
22
23
|
const normalized = relativePath.trim().replaceAll("\\", "/");
|
|
23
|
-
if (
|
|
24
|
+
if (isRuntimeOnlyPath(normalized)) {
|
|
24
25
|
return true;
|
|
25
26
|
}
|
|
26
27
|
if (normalized === ".forge" || normalized.startsWith(".forge/")) {
|
|
@@ -28,16 +29,31 @@ export function isNonPublishableWorktreeChange(relativePath, status) {
|
|
|
28
29
|
}
|
|
29
30
|
return false;
|
|
30
31
|
}
|
|
31
|
-
/**
|
|
32
|
+
/** `.local/`, `.forge/work-items/` and `.forge/stories/`: never published, even during a merge. */
|
|
33
|
+
export function isRuntimeOnlyPath(relativePath) {
|
|
34
|
+
const normalizedPath = normalizeChangedFilePath(relativePath);
|
|
35
|
+
return normalizedPath === ".local" || runtimeOnlyPathPrefixes.some(prefix => normalizedPath.startsWith(prefix));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Stages every publishable worktree change in the real index and returns both sets.
|
|
39
|
+
*
|
|
40
|
+
* During an in-progress merge it first refuses unresolved conflicts, and afterwards
|
|
41
|
+
* restores merge-owned paths that the exclusion unstaged back to HEAD (the story side),
|
|
42
|
+
* such as `.forge/` files the target branch added (#491). Runtime-only paths are never
|
|
43
|
+
* restored.
|
|
44
|
+
*/
|
|
32
45
|
export async function stagePublishableWorktreeChangeSet(git, worktreePath) {
|
|
46
|
+
await assertNoUnresolvedMergeConflicts(git, worktreePath);
|
|
33
47
|
await git.run(worktreePath, ["add", "-A"]);
|
|
34
|
-
const
|
|
48
|
+
const excludedChanges = (await readStagedChanges(git, worktreePath))
|
|
35
49
|
.filter(change => isNonPublishableWorktreeChange(change.path, change.status))
|
|
36
50
|
.map(change => change.path);
|
|
37
|
-
for (let index = 0; index <
|
|
38
|
-
const batch =
|
|
51
|
+
for (let index = 0; index < excludedChanges.length; index += resetBatchSize) {
|
|
52
|
+
const batch = excludedChanges.slice(index, index + resetBatchSize).map(filePath => `:(literal)${filePath}`);
|
|
39
53
|
await git.run(worktreePath, ["reset", "-q", "--", ...batch]);
|
|
40
54
|
}
|
|
55
|
+
const restored = new Set(await restoreMergeOwnedPaths(git, worktreePath, excludedChanges.filter(filePath => !isRuntimeOnlyPath(filePath))));
|
|
56
|
+
const excluded = excludedChanges.filter(filePath => !restored.has(filePath));
|
|
41
57
|
const publishable = (await git.run(worktreePath, ["diff", "--cached", "--name-only"]))
|
|
42
58
|
.split(/\r?\n/)
|
|
43
59
|
.map(line => line.trim())
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type HostLoadAcquireOptions, type HostLoadAdmission, type HostLoadStepGate, type HostLoadStepRequest } from "../runtime/host-load-governor.js";
|
|
2
|
+
export interface SandboxHostCapacityGateOptions {
|
|
3
|
+
readonly write?: (line: string) => void;
|
|
4
|
+
readonly responseRoot?: string;
|
|
5
|
+
readonly pollMs?: number;
|
|
6
|
+
/** Fails closed if the bridge never answers (the host enforces its own maximum wait first). */
|
|
7
|
+
readonly maxWaitMs?: number;
|
|
8
|
+
/** Owner of authentic replies (root in the container; tests use their own uid). */
|
|
9
|
+
readonly trustedOwnerUid?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class SandboxBrokeredHostLoadGate implements HostLoadStepGate {
|
|
12
|
+
readonly enabled = true;
|
|
13
|
+
private readonly write;
|
|
14
|
+
private readonly responseRoot;
|
|
15
|
+
private readonly pollMs;
|
|
16
|
+
private readonly trustedOwnerUid;
|
|
17
|
+
readonly maxWaitMs: number;
|
|
18
|
+
constructor(options?: SandboxHostCapacityGateOptions);
|
|
19
|
+
acquire(request: HostLoadStepRequest, options?: HostLoadAcquireOptions): Promise<HostLoadAdmission>;
|
|
20
|
+
private admission;
|
|
21
|
+
private send;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The brokered gate when the host bridge enabled it for this sandbox. The
|
|
25
|
+
* variable is removed once read, so commands the sandbox runs never inherit it
|
|
26
|
+
* (a nested Forge process must not queue behind its parent's token).
|
|
27
|
+
*/
|
|
28
|
+
export declare function sandboxHostLoadGateFromEnvironment(environment?: NodeJS.ProcessEnv): HostLoadStepGate | undefined;
|
|
29
|
+
/** Test support: forgets the cached gate. */
|
|
30
|
+
export declare function resetSandboxHostLoadGateForTesting(): void;
|