@loucompanion/forge-bridge 0.1.4-dev.a690038a6849 → 0.1.4-dev.b33004c2b0ea
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 +44 -2
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +72 -1
- package/dist/bridge/bridge.service.js +308 -9
- package/dist/bridge/bridge.types.d.ts +16 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/runner-host-capabilities.d.ts +2 -0
- package/dist/bridge/runner-host-capabilities.js +4 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +72 -109
- package/dist/cleanup/cleanup.types.d.ts +4 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +18 -0
- package/dist/cli/cli.service.d.ts +16 -0
- package/dist/cli/cli.service.js +142 -16
- package/dist/cli/local-config.d.ts +4 -0
- package/dist/cli/local-config.js +26 -4
- package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
- package/dist/runtime/host-load-admission.d.ts +60 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +22 -0
- package/dist/runtime/host-load-child-environment.js +67 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +43 -0
- package/dist/runtime/host-load-governor-config.js +76 -0
- package/dist/runtime/host-load-governor.d.ts +174 -0
- package/dist/runtime/host-load-governor.js +541 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +185 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +78 -0
- package/dist/runtime/host-load-sampler.d.ts +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 +74 -4
- package/dist/runtime/host-runtime-lease.js +281 -11
- 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/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/runtime/runner-settings.d.ts +100 -0
- package/dist/runtime/runner-settings.js +214 -0
- package/dist/sandbox/host-capacity-broker.d.ts +107 -0
- package/dist/sandbox/host-capacity-broker.js +315 -0
- package/dist/sandbox/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-pass.d.ts +60 -0
- package/dist/session/pre-publication-pass.js +145 -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 +30 -20
- package/dist/session/pre-publication-validation.js +166 -155
- package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
- package/dist/session/provider-cli/pre-publication-repair.js +243 -0
- package/dist/session/provider-cli/provider-cli.artifacts.js +15 -3
- 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 +7 -0
- package/dist/session/provider-cli/provider-cli.process.js +15 -7
- package/dist/session/provider-cli/provider-cli.prompts.js +7 -2
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +105 -145
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -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 +9 -1
- package/dist/session/session.service.d.ts +9 -2
- package/dist/session/session.service.js +120 -5
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +6 -3
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/process/host-process-supervisor.d.ts +1 -0
- package/dist/shared/process/host-process-supervisor.js +1 -1
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +67 -0
- package/dist/shared/process/process.js +213 -11
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -10
- package/dist/worktree/worktree.service.d.ts +10 -1
- package/dist/worktree/worktree.service.js +42 -2
- package/dist/worktree/worktree.types.d.ts +7 -0
- package/package.json +2 -2
|
@@ -2,6 +2,7 @@ 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";
|
|
@@ -11,12 +12,12 @@ import { diffClaimedChangedFiles, findUnpublishedWorktreePaths, normalizeChanged
|
|
|
11
12
|
import { DeterministicProviderCliService } from "./provider-cli.deterministic.js";
|
|
12
13
|
import { buildArchitectPrompt, buildConflictResolvePrompt, buildDebugCyclePrompt, buildDevelopCyclePrompt, buildDraftPrompt, buildDraftSpec, buildImplementationPrompt, buildProviderCliPrompt, buildProviderCliCommand, durableDraftInput, buildPullRequestCheckRepairPrompt, buildPullRequestCommentsPrompt, buildQaPrompt, formatProviderCliCommandForCheckpoint, isDecomposeDraftDispatch, isPullRequestCheckRepairDispatch, isPullRequestCommentsDispatch } from "./provider-cli.prompts.js";
|
|
13
14
|
import { isTransientCodexProviderNotFoundFailure, providerCompletionToolMissingFailure, recoveringProviderProcessRunner, StreamingProviderProcessRunner } from "./provider-cli.process.js";
|
|
14
|
-
import { emitProviderUsageEvent,
|
|
15
|
+
import { emitProviderUsageEvent, providerProcessEnv } from "./provider-cli.runtime.js";
|
|
15
16
|
import { clip, createProviderOutputState, parseJsonLine } from "./provider-output-state.js";
|
|
16
17
|
import { writeCiRepairReadinessManifest } from "./ci-repair-readiness.js";
|
|
17
18
|
import { assertRepairHeadEpoch } from "./provider-cli.repair-epoch.js";
|
|
18
|
-
import {
|
|
19
|
-
|
|
19
|
+
import { PrePublicationValidator } from "../pre-publication-validation.js";
|
|
20
|
+
import { prePublicationRepairTurnsFromEnvironment, validatePrePublicationWithRepair, } from "./pre-publication-repair.js";
|
|
20
21
|
const maxQaCompletionRecoveryTurns = 2;
|
|
21
22
|
function assertCommentRepairArtifactMatchesDispatch(dispatch, artifact) {
|
|
22
23
|
const pullRequest = dispatch.pullRequest;
|
|
@@ -212,18 +213,6 @@ async function pushWorktreeBranch(git, worktreePath, branchName, repoPath, coord
|
|
|
212
213
|
function providerOwnsBranchPublication(context) {
|
|
213
214
|
return context.dispatch.sandbox?.executionMode !== "docker";
|
|
214
215
|
}
|
|
215
|
-
function prePublicationExecution(context, environment, defaultRunner, baselineRevision) {
|
|
216
|
-
if (context.processRunner)
|
|
217
|
-
return { baselineRevision, environment, processRunner: context.processRunner };
|
|
218
|
-
if (context.dispatch.sandbox?.executionMode !== "docker")
|
|
219
|
-
return { baselineRevision, environment };
|
|
220
|
-
const expectedSandboxId = context.dispatch.sandbox.dispatchAttemptId;
|
|
221
|
-
const observedSandboxId = context.runtimeEnvironment?.FORGE_SANDBOX_ID ?? process.env.FORGE_SANDBOX_ID;
|
|
222
|
-
if (observedSandboxId !== expectedSandboxId) {
|
|
223
|
-
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
|
-
}
|
|
225
|
-
return { baselineRevision, environment, processRunner: defaultRunner };
|
|
226
|
-
}
|
|
227
216
|
function remoteTrackingRefspec(branchName) {
|
|
228
217
|
return `refs/heads/${branchName}:refs/remotes/origin/${branchName}`;
|
|
229
218
|
}
|
|
@@ -432,7 +421,8 @@ export class ManagedVerificationProgressEmitter {
|
|
|
432
421
|
}
|
|
433
422
|
}
|
|
434
423
|
function isManagedVerificationNonterminal(status) {
|
|
435
|
-
return status === "starting" || status === "running" || status === "waiting_for_build_slot"
|
|
424
|
+
return status === "starting" || status === "running" || status === "waiting_for_build_slot"
|
|
425
|
+
|| status === "waiting_for_host_capacity";
|
|
436
426
|
}
|
|
437
427
|
async function parseManagedVerificationSnapshot(receiptPath) {
|
|
438
428
|
try {
|
|
@@ -474,6 +464,8 @@ class ProviderToolActivityHeartbeat {
|
|
|
474
464
|
timer = null;
|
|
475
465
|
/** Lets the provider runner hold its end-of-turn timers while a tool call is in flight. */
|
|
476
466
|
isToolCallInFlight = () => this.outputState.hasActiveToolCall;
|
|
467
|
+
/** Forgets tool calls a previous generation left open; called before every relaunch. */
|
|
468
|
+
startGeneration = () => this.outputState.resetActiveToolCalls();
|
|
477
469
|
constructor(outputState, emit, intervalMs) {
|
|
478
470
|
this.outputState = outputState;
|
|
479
471
|
this.emit = emit;
|
|
@@ -562,12 +554,19 @@ export class ProcessBackedProviderCliService {
|
|
|
562
554
|
providerToolHeartbeatIntervalMs;
|
|
563
555
|
publicationCoordinator;
|
|
564
556
|
prePublicationValidator;
|
|
565
|
-
|
|
557
|
+
prePublicationRepairTurns;
|
|
558
|
+
constructor(processRunner = new StreamingProviderProcessRunner(), git = new GitClient(), providerToolHeartbeatIntervalMs = defaultProviderToolHeartbeatIntervalMs, publicationCoordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
559
|
+
// The Docker sandbox worker (`forge` run-once via ForgeBridgeCliService) builds
|
|
560
|
+
// this default. A container cannot reach the host ledger, so when the host
|
|
561
|
+
// bridge enabled it, its steps ask the bridge for tokens over the sandbox
|
|
562
|
+
// channel (decision 0013); elsewhere the gate is absent and validation is ungated.
|
|
563
|
+
prePublicationValidator = new PrePublicationValidator(undefined, undefined, undefined, sandboxHostLoadGateFromEnvironment()), prePublicationRepairTurns = prePublicationRepairTurnsFromEnvironment()) {
|
|
566
564
|
this.processRunner = processRunner;
|
|
567
565
|
this.git = git;
|
|
568
566
|
this.providerToolHeartbeatIntervalMs = providerToolHeartbeatIntervalMs;
|
|
569
567
|
this.publicationCoordinator = publicationCoordinator;
|
|
570
568
|
this.prePublicationValidator = prePublicationValidator;
|
|
569
|
+
this.prePublicationRepairTurns = prePublicationRepairTurns;
|
|
571
570
|
}
|
|
572
571
|
async runDraft(context) {
|
|
573
572
|
const { dispatch } = context;
|
|
@@ -581,7 +580,7 @@ export class ProcessBackedProviderCliService {
|
|
|
581
580
|
await fs.writeFile(path.join(metadataRoot, "spec.md"), buildDraftSpec(dispatch), "utf8");
|
|
582
581
|
const stagedAttachments = await stageDraftAttachments(dispatch, metadataRoot);
|
|
583
582
|
const decomposeDraft = isDecomposeDraftDispatch(dispatch);
|
|
584
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: decomposeDraft ? "decompose" : "draft", runtimeEnvironment: context.runtimeEnvironment });
|
|
583
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: decomposeDraft ? "decompose" : "draft", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
585
584
|
const draftPrompt = buildDraftPrompt(dispatch, { attachmentReferences: stagedAttachments.textReferences });
|
|
586
585
|
const providerPrompt = buildProviderCliPrompt(dispatch, draftPrompt, context.runtimeEnvironment);
|
|
587
586
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -646,6 +645,7 @@ export class ProcessBackedProviderCliService {
|
|
|
646
645
|
});
|
|
647
646
|
},
|
|
648
647
|
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
648
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
649
649
|
onStdoutLine: async (line) => {
|
|
650
650
|
await toolHeartbeat.consume(line);
|
|
651
651
|
}
|
|
@@ -763,7 +763,7 @@ export class ProcessBackedProviderCliService {
|
|
|
763
763
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
764
764
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
765
765
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" }) + "\n", "utf8");
|
|
766
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase, runtimeEnvironment: context.runtimeEnvironment });
|
|
766
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase, runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
767
767
|
const implementationPrompt = debugCycle
|
|
768
768
|
? buildDebugCyclePrompt(dispatch, phase)
|
|
769
769
|
: developCycle
|
|
@@ -817,6 +817,7 @@ export class ProcessBackedProviderCliService {
|
|
|
817
817
|
});
|
|
818
818
|
},
|
|
819
819
|
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
820
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
820
821
|
onStdoutLine: async (line) => {
|
|
821
822
|
await toolHeartbeat.consume(line);
|
|
822
823
|
}
|
|
@@ -910,7 +911,7 @@ export class ProcessBackedProviderCliService {
|
|
|
910
911
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
911
912
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
912
913
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), JSON.stringify({ schema_version: 1, status: "pending_approval", produced_by: "forge-lane-command" }) + "\n", "utf8");
|
|
913
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "architect", runtimeEnvironment: context.runtimeEnvironment });
|
|
914
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "architect", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
914
915
|
const architectPrompt = buildArchitectPrompt(dispatch);
|
|
915
916
|
const providerPrompt = buildProviderCliPrompt(dispatch, architectPrompt, context.runtimeEnvironment);
|
|
916
917
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -957,6 +958,7 @@ export class ProcessBackedProviderCliService {
|
|
|
957
958
|
});
|
|
958
959
|
},
|
|
959
960
|
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
961
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
960
962
|
onStdoutLine: async (line) => await toolHeartbeat.consume(line)
|
|
961
963
|
}, context.signal);
|
|
962
964
|
}
|
|
@@ -1014,7 +1016,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1014
1016
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
1015
1017
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
1016
1018
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" }) + "\n", "utf8");
|
|
1017
|
-
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "qa", runtimeEnvironment: context.runtimeEnvironment });
|
|
1019
|
+
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase: "qa", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
1018
1020
|
const qaPrompt = buildQaPrompt(dispatch, specBody);
|
|
1019
1021
|
const providerPrompt = buildProviderCliPrompt(dispatch, qaPrompt, context.runtimeEnvironment);
|
|
1020
1022
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
@@ -1063,6 +1065,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1063
1065
|
});
|
|
1064
1066
|
},
|
|
1065
1067
|
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1068
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1066
1069
|
onStdoutLine: async (line) => await toolHeartbeat.consume(line)
|
|
1067
1070
|
}, context.signal);
|
|
1068
1071
|
}
|
|
@@ -1133,6 +1136,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1133
1136
|
const addressComments = !repairChecks && isPullRequestCommentsDispatch(dispatch);
|
|
1134
1137
|
let repairSpec = null;
|
|
1135
1138
|
let repairEnvironment = context.runtimeEnvironment;
|
|
1139
|
+
let ciRepairSpecPath = null;
|
|
1136
1140
|
let completionTools = null;
|
|
1137
1141
|
if (repairChecks) {
|
|
1138
1142
|
const metadataRoot = path.join(worktree.worktreePath, ".forge", "work-items", dispatch.workItem.id);
|
|
@@ -1143,6 +1147,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1143
1147
|
}
|
|
1144
1148
|
const specBody = buildSpecBody(laneCommand, dispatch.workItem, "ci_repair");
|
|
1145
1149
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
1150
|
+
ciRepairSpecPath = specPath;
|
|
1146
1151
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
1147
1152
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), `${JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" })}\n`, "utf8");
|
|
1148
1153
|
repairSpec = {
|
|
@@ -1154,7 +1159,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1154
1159
|
};
|
|
1155
1160
|
const readiness = await writeCiRepairReadinessManifest(dispatch, worktree.worktreePath, specPath, context.runtimeEnvironment);
|
|
1156
1161
|
repairEnvironment = readiness.environment;
|
|
1157
|
-
completionTools = await prepareCompletionToolRuntime({
|
|
1162
|
+
completionTools = await prepareCompletionToolRuntime({
|
|
1163
|
+
dispatch, worktree, phase: "ci_repair", runtimeEnvironment: repairEnvironment, hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1164
|
+
});
|
|
1158
1165
|
await context.emit({
|
|
1159
1166
|
role: "runner",
|
|
1160
1167
|
kind: "checkpoint",
|
|
@@ -1169,7 +1176,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1169
1176
|
});
|
|
1170
1177
|
}
|
|
1171
1178
|
if (addressComments) {
|
|
1172
|
-
completionTools = await prepareCompletionToolRuntime({
|
|
1179
|
+
completionTools = await prepareCompletionToolRuntime({
|
|
1180
|
+
dispatch, worktree, phase: "comment_repair", runtimeEnvironment: repairEnvironment, hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1181
|
+
});
|
|
1173
1182
|
await context.emit({
|
|
1174
1183
|
role: "runner",
|
|
1175
1184
|
kind: "checkpoint",
|
|
@@ -1220,6 +1229,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1220
1229
|
providerStarted = true;
|
|
1221
1230
|
},
|
|
1222
1231
|
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1232
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1223
1233
|
onStdoutLine: async (line) => {
|
|
1224
1234
|
await toolHeartbeat.consume(line);
|
|
1225
1235
|
}
|
|
@@ -1292,6 +1302,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1292
1302
|
: addressComments
|
|
1293
1303
|
? "comment_repair"
|
|
1294
1304
|
: "conflict_repair";
|
|
1305
|
+
const readinessSpecPath = ciRepairSpecPath;
|
|
1295
1306
|
await this.validatePrePublicationWithRecovery({
|
|
1296
1307
|
context,
|
|
1297
1308
|
validationProfile,
|
|
@@ -1299,6 +1310,10 @@ export class ProcessBackedProviderCliService {
|
|
|
1299
1310
|
outputState,
|
|
1300
1311
|
preparedHeadSha,
|
|
1301
1312
|
repairScope: "pull_request",
|
|
1313
|
+
...(readinessSpecPath ? {
|
|
1314
|
+
// The readiness manifest records the attempt URLs; a restart must not leave it pointing at the old stack.
|
|
1315
|
+
onRuntimeEnvironmentRefreshed: async (runtimeEnvironment) => (await writeCiRepairReadinessManifest(dispatch, worktree.worktreePath, readinessSpecPath, runtimeEnvironment)).environment,
|
|
1316
|
+
} : {}),
|
|
1302
1317
|
});
|
|
1303
1318
|
const stagedChangeSet = await stagePublishableWorktreeChangeSet(this.git, worktree.worktreePath);
|
|
1304
1319
|
const stagedChangedFiles = stagedChangeSet.publishable;
|
|
@@ -1377,6 +1392,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1377
1392
|
worktree,
|
|
1378
1393
|
phase: "qa",
|
|
1379
1394
|
runtimeEnvironment: context.runtimeEnvironment,
|
|
1395
|
+
hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1380
1396
|
});
|
|
1381
1397
|
const command = buildProviderCliCommand(recoveryDispatch, {
|
|
1382
1398
|
worktreePath: worktree.worktreePath,
|
|
@@ -1402,7 +1418,11 @@ export class ProcessBackedProviderCliService {
|
|
|
1402
1418
|
env: providerProcessEnv(recoveryDispatch, context.runtimeEnvironment),
|
|
1403
1419
|
resumesProviderThread: Boolean(recoveryDispatch.session.resumeProviderThreadId),
|
|
1404
1420
|
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1405
|
-
}, {
|
|
1421
|
+
}, {
|
|
1422
|
+
onStdoutLine: async (line) => await toolHeartbeat.consume(line),
|
|
1423
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1424
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1425
|
+
}, context.signal);
|
|
1406
1426
|
}
|
|
1407
1427
|
finally {
|
|
1408
1428
|
toolHeartbeat.stop();
|
|
@@ -1482,6 +1502,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1482
1502
|
worktree,
|
|
1483
1503
|
phase: "comment_repair",
|
|
1484
1504
|
runtimeEnvironment: repairEnvironment,
|
|
1505
|
+
hostLoadEnvironment: context.hostLoadEnvironment,
|
|
1485
1506
|
});
|
|
1486
1507
|
const command = buildProviderCliCommand(recoveryDispatch, {
|
|
1487
1508
|
worktreePath: worktree.worktreePath,
|
|
@@ -1519,6 +1540,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1519
1540
|
});
|
|
1520
1541
|
},
|
|
1521
1542
|
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1543
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1522
1544
|
onStdoutLine: async (line) => {
|
|
1523
1545
|
await toolHeartbeat.consume(line);
|
|
1524
1546
|
},
|
|
@@ -1560,140 +1582,78 @@ export class ProcessBackedProviderCliService {
|
|
|
1560
1582
|
return artifact;
|
|
1561
1583
|
}
|
|
1562
1584
|
async validatePrePublicationWithRecovery(options) {
|
|
1563
|
-
const
|
|
1585
|
+
const processRunner = recoveringProviderProcessRunner(options.context.processRunner ?? this.processRunner);
|
|
1586
|
+
await validatePrePublicationWithRepair(options, {
|
|
1587
|
+
validator: this.prePublicationValidator,
|
|
1588
|
+
defaultProcessRunner: this.processRunner,
|
|
1589
|
+
maxRepairTurns: this.prePublicationRepairTurns,
|
|
1590
|
+
runRepairTurn: async (turn) => await this.runPrePublicationRepairTurn(options, processRunner, turn),
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
/** Resumes the provider thread for one in-place repair turn; the turn must leave HEAD where it was. */
|
|
1594
|
+
async runPrePublicationRepairTurn(options, processRunner, turn) {
|
|
1595
|
+
const { context, outputState, preparedHeadSha } = options;
|
|
1564
1596
|
const { dispatch, worktree } = context;
|
|
1565
|
-
const
|
|
1566
|
-
const
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1597
|
+
const { prompt: focusedPrompt, repairTurn: nextRepairTurn, maxRepairTurns, repairEnvironment, environment } = turn;
|
|
1598
|
+
const repairDispatch = {
|
|
1599
|
+
...dispatch,
|
|
1600
|
+
session: { ...dispatch.session, resumeProviderThreadId: turn.providerThreadId },
|
|
1601
|
+
};
|
|
1602
|
+
const providerPrompt = buildProviderCliPrompt(repairDispatch, focusedPrompt, repairEnvironment);
|
|
1603
|
+
const pipePromptToStdin = shouldPipePromptToStdin(repairDispatch.execution.provider, providerPrompt, usesManagedWindowsHost(repairDispatch));
|
|
1604
|
+
const command = buildProviderCliCommand(repairDispatch, {
|
|
1605
|
+
worktreePath: worktree.worktreePath,
|
|
1606
|
+
prompt: focusedPrompt,
|
|
1607
|
+
promptFromStdin: pipePromptToStdin,
|
|
1608
|
+
runtimeEnvironment: repairEnvironment,
|
|
1609
|
+
});
|
|
1610
|
+
const toolHeartbeat = new ProviderToolActivityHeartbeat(outputState, context.emit, this.providerToolHeartbeatIntervalMs);
|
|
1611
|
+
let result;
|
|
1612
|
+
let providerStarted = false;
|
|
1613
|
+
try {
|
|
1614
|
+
result = await processRunner.run({
|
|
1615
|
+
command: command.command,
|
|
1616
|
+
args: command.args,
|
|
1617
|
+
cwd: worktree.worktreePath,
|
|
1618
|
+
env: environment,
|
|
1619
|
+
resumesProviderThread: Boolean(repairDispatch.session.resumeProviderThreadId),
|
|
1620
|
+
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1621
|
+
}, {
|
|
1622
|
+
onStarted: async () => {
|
|
1572
1623
|
await context.emit({
|
|
1573
1624
|
role: "runner",
|
|
1574
1625
|
kind: "checkpoint",
|
|
1575
|
-
content: `
|
|
1576
|
-
eventType: "
|
|
1577
|
-
data: JSON.stringify({ repairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1578
|
-
});
|
|
1579
|
-
}
|
|
1580
|
-
return;
|
|
1581
|
-
}
|
|
1582
|
-
catch (error) {
|
|
1583
|
-
if (!(error instanceof PrePublicationValidationError))
|
|
1584
|
-
throw error;
|
|
1585
|
-
if (repairTurn >= maxPrePublicationRepairTurns) {
|
|
1586
|
-
await context.emit({
|
|
1587
|
-
role: "runner",
|
|
1588
|
-
kind: "error",
|
|
1589
|
-
content: `Pre-publication validation still fails after ${maxPrePublicationRepairTurns} in-place repair turns: ${clip(error.message, 4000)}`,
|
|
1590
|
-
eventType: "prepublication_repair_exhausted",
|
|
1591
|
-
data: JSON.stringify({ checkId: error.checkId, repairTurns: repairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1626
|
+
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxRepairTurns} is supervised and ready.`,
|
|
1627
|
+
eventType: "provider_cli_started",
|
|
1592
1628
|
});
|
|
1593
|
-
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
const providerPrompt = buildProviderCliPrompt(repairDispatch, focusedPrompt, repairEnvironment);
|
|
1606
|
-
const pipePromptToStdin = shouldPipePromptToStdin(repairDispatch.execution.provider, providerPrompt, usesManagedWindowsHost(repairDispatch));
|
|
1607
|
-
const command = buildProviderCliCommand(repairDispatch, {
|
|
1608
|
-
worktreePath: worktree.worktreePath,
|
|
1609
|
-
prompt: focusedPrompt,
|
|
1610
|
-
promptFromStdin: pipePromptToStdin,
|
|
1611
|
-
runtimeEnvironment: repairEnvironment,
|
|
1612
|
-
});
|
|
1629
|
+
providerStarted = true;
|
|
1630
|
+
},
|
|
1631
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1632
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1633
|
+
onStdoutLine: async (line) => {
|
|
1634
|
+
await toolHeartbeat.consume(line);
|
|
1635
|
+
},
|
|
1636
|
+
}, context.signal);
|
|
1637
|
+
}
|
|
1638
|
+
finally {
|
|
1639
|
+
toolHeartbeat.stop();
|
|
1640
|
+
if (providerStarted) {
|
|
1613
1641
|
await context.emit({
|
|
1614
1642
|
role: "runner",
|
|
1615
1643
|
kind: "checkpoint",
|
|
1616
|
-
content: `
|
|
1617
|
-
eventType: "
|
|
1618
|
-
data: JSON.stringify({ checkId: error.checkId, repairTurn: nextRepairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1644
|
+
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxRepairTurns} exited.`,
|
|
1645
|
+
eventType: "provider_cli_completed",
|
|
1619
1646
|
});
|
|
1620
|
-
const toolHeartbeat = new ProviderToolActivityHeartbeat(outputState, context.emit, this.providerToolHeartbeatIntervalMs);
|
|
1621
|
-
let result;
|
|
1622
|
-
let providerStarted = false;
|
|
1623
|
-
try {
|
|
1624
|
-
result = await processRunner.run({
|
|
1625
|
-
command: command.command,
|
|
1626
|
-
args: command.args,
|
|
1627
|
-
cwd: worktree.worktreePath,
|
|
1628
|
-
env: environment,
|
|
1629
|
-
resumesProviderThread: Boolean(repairDispatch.session.resumeProviderThreadId),
|
|
1630
|
-
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1631
|
-
}, {
|
|
1632
|
-
onStarted: async () => {
|
|
1633
|
-
await context.emit({
|
|
1634
|
-
role: "runner",
|
|
1635
|
-
kind: "checkpoint",
|
|
1636
|
-
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxPrePublicationRepairTurns} is supervised and ready.`,
|
|
1637
|
-
eventType: "provider_cli_started",
|
|
1638
|
-
});
|
|
1639
|
-
providerStarted = true;
|
|
1640
|
-
},
|
|
1641
|
-
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1642
|
-
onStdoutLine: async (line) => {
|
|
1643
|
-
await toolHeartbeat.consume(line);
|
|
1644
|
-
},
|
|
1645
|
-
}, context.signal);
|
|
1646
|
-
}
|
|
1647
|
-
finally {
|
|
1648
|
-
toolHeartbeat.stop();
|
|
1649
|
-
if (providerStarted) {
|
|
1650
|
-
await context.emit({
|
|
1651
|
-
role: "runner",
|
|
1652
|
-
kind: "checkpoint",
|
|
1653
|
-
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxPrePublicationRepairTurns} exited.`,
|
|
1654
|
-
eventType: "provider_cli_completed",
|
|
1655
|
-
});
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
if (result.exitCode !== 0)
|
|
1659
|
-
throw providerCliExitFailure(command.command, result);
|
|
1660
|
-
const postRepairHeadSha = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
1661
|
-
if (postRepairHeadSha.toLowerCase() !== preparedHeadSha.toLowerCase()) {
|
|
1662
|
-
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 });
|
|
1663
|
-
}
|
|
1664
1647
|
}
|
|
1665
1648
|
}
|
|
1649
|
+
if (result.exitCode !== 0)
|
|
1650
|
+
throw providerCliExitFailure(command.command, result);
|
|
1651
|
+
const postRepairHeadSha = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
1652
|
+
if (postRepairHeadSha.toLowerCase() !== preparedHeadSha.toLowerCase()) {
|
|
1653
|
+
throw new Error(`provider_publication_boundary_violation: pre-publication repair changed HEAD from ${preparedHeadSha} to ${postRepairHeadSha}; Forge requires provider changes to remain uncommitted and unpushed until validation passes.`, { cause: turn.failure });
|
|
1654
|
+
}
|
|
1666
1655
|
}
|
|
1667
1656
|
}
|
|
1668
|
-
function buildPrePublicationRepairPrompt(error, repairTurn, repairScope) {
|
|
1669
|
-
const invocation = [error.command, ...error.args].join(" ");
|
|
1670
|
-
const priorWork = repairScope === "implementation"
|
|
1671
|
-
? "Keep the completed implementation and its Forge-owned completion artifacts intact."
|
|
1672
|
-
: "Keep the existing PR-comment or CI repairs intact.";
|
|
1673
|
-
return [
|
|
1674
|
-
`Forge pre-publication validation failed after your ${repairScope === "implementation" ? "implementation" : "PR repair"} turn.`,
|
|
1675
|
-
`This is bounded in-place repair turn ${repairTurn}/${maxPrePublicationRepairTurns}.`,
|
|
1676
|
-
`Failed check: ${error.checkId}`,
|
|
1677
|
-
`Command: ${invocation}`,
|
|
1678
|
-
`Exit code: ${error.exitCode}`,
|
|
1679
|
-
"Diagnostics:",
|
|
1680
|
-
error.detail || "The validation command returned no diagnostic output.",
|
|
1681
|
-
"Fix the root cause in the current worktree and run the focused failing check.",
|
|
1682
|
-
`${priorWork} Do not commit, push, rebase, or modify Forge-owned protocol artifacts.`,
|
|
1683
|
-
"When the focused check passes, stop; Bridge will rerun the complete required pre-publication profile and owns commit/push.",
|
|
1684
|
-
].join("\n\n");
|
|
1685
|
-
}
|
|
1686
|
-
function publicationCapabilities(context, runtimeEnvironment) {
|
|
1687
|
-
const capabilities = new Set();
|
|
1688
|
-
const launchTarget = context.dispatch.qaBrowser?.launchTarget;
|
|
1689
|
-
if (runtimeEnvironment?.FORGE_PLAYWRIGHT_CONFIG
|
|
1690
|
-
|| launchTarget?.url
|
|
1691
|
-
|| launchTarget?.command
|
|
1692
|
-
|| launchTarget?.managed_runtime_port) {
|
|
1693
|
-
capabilities.add("browser_launch");
|
|
1694
|
-
}
|
|
1695
|
-
return capabilities;
|
|
1696
|
-
}
|
|
1697
1657
|
async function stageDraftAttachments(dispatch, metadataRoot) {
|
|
1698
1658
|
const attachments = dispatch.draft?.attachments ?? [];
|
|
1699
1659
|
const stageable = attachments.filter((attachment) => (attachment.kind === "text" && typeof attachment.textContent === "string")
|
|
@@ -1,18 +1,48 @@
|
|
|
1
1
|
import type { RunOnceDispatchPacket, RunnerDispatchArtifact, RunnerDispatchEvent, RunnerDispatchSpec } from "../session.types.js";
|
|
2
2
|
import type { WorktreeHandle } from "../../worktree/worktree.types.js";
|
|
3
3
|
import type { ProviderProcessRunner } from "./provider-cli.process.js";
|
|
4
|
+
/**
|
|
5
|
+
* Why the attempt's runtime stack restarted before a validation pass. The first cause that applies:
|
|
6
|
+
* a previous restart did not complete; the workspace state could not be compared with the stack's
|
|
7
|
+
* (either reading was unavailable); or the workspace changed since the stack was launched.
|
|
8
|
+
*/
|
|
9
|
+
export type RuntimeRestartReason = "previous_restart_incomplete" | "fingerprint_unavailable" | "workspace_changed";
|
|
10
|
+
export interface RuntimeEnvironmentRefresh {
|
|
11
|
+
/** The restarted stack's runtime environment. */
|
|
12
|
+
readonly environment: Readonly<Record<string, string>>;
|
|
13
|
+
readonly reason: RuntimeRestartReason;
|
|
14
|
+
/** What changed in the workspace since the stack was launched, when both states could be read. */
|
|
15
|
+
readonly changes: readonly string[];
|
|
16
|
+
}
|
|
4
17
|
export interface ProviderCliRunContext {
|
|
5
18
|
readonly dispatch: RunOnceDispatchPacket;
|
|
6
19
|
readonly worktree: WorktreeHandle;
|
|
7
20
|
readonly runtimeEnvironment?: Readonly<Record<string, string>>;
|
|
21
|
+
/** Host load governor variables for the completion MCP server only (decision 0013). */
|
|
22
|
+
readonly hostLoadEnvironment?: Readonly<Record<string, string>>;
|
|
8
23
|
readonly processRunner?: ProviderProcessRunner;
|
|
9
24
|
readonly signal?: AbortSignal;
|
|
25
|
+
/**
|
|
26
|
+
* Restarts the attempt's host runtime stack when the workspace changed since it was
|
|
27
|
+
* launched (an uncommitted edit, an in-progress merge), so validation and repair
|
|
28
|
+
* turns run against the current source. Resolves to the refreshed runtime
|
|
29
|
+
* environment and why the stack restarted, or null when the stack is current or
|
|
30
|
+
* there is no configured project.
|
|
31
|
+
*/
|
|
32
|
+
refreshRuntimeEnvironment?(signal?: AbortSignal): Promise<RuntimeEnvironmentRefresh | null>;
|
|
33
|
+
/**
|
|
34
|
+
* The runtime environment keys that name the configured project's live stack (its URLs and
|
|
35
|
+
* ports). A failed restart withholds them from the repair turn, since the stack is down.
|
|
36
|
+
*/
|
|
37
|
+
readonly runtimeStackEnvironmentKeys?: readonly string[];
|
|
10
38
|
emit(event: RunnerDispatchEvent): Promise<void>;
|
|
11
39
|
}
|
|
12
40
|
export interface ProviderCliDraftContext {
|
|
13
41
|
readonly dispatch: RunOnceDispatchPacket;
|
|
14
42
|
readonly worktree: WorktreeHandle;
|
|
15
43
|
readonly runtimeEnvironment?: Readonly<Record<string, string>>;
|
|
44
|
+
/** Host load governor variables for the completion MCP server only (decision 0013). */
|
|
45
|
+
readonly hostLoadEnvironment?: Readonly<Record<string, string>>;
|
|
16
46
|
readonly processRunner?: ProviderProcessRunner;
|
|
17
47
|
readonly signal?: AbortSignal;
|
|
18
48
|
emit(event: RunnerDispatchEvent): Promise<void>;
|
|
@@ -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;
|