@loucompanion/forge-bridge 0.1.4-dev.e83e5bc6ecce → 0.1.4-dev.ec3460040366
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 +142 -1
- package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
- package/dist/bridge/bridge-chat-provider-command.js +132 -0
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +88 -14
- package/dist/bridge/bridge.service.js +406 -345
- package/dist/bridge/bridge.types.d.ts +16 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.d.ts +3 -0
- package/dist/bridge/runner-host-capabilities.js +13 -0
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +11 -1
- package/dist/cleanup/cleanup.service.js +80 -62
- package/dist/cleanup/cleanup.types.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.js +30 -9
- package/dist/cli/cli.help.js +74 -12
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +142 -185
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +6 -0
- package/dist/cli/local-config.js +32 -4
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.js +9 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-facts.d.ts +2 -1
- package/dist/runtime/host-load-admission.d.ts +18 -3
- package/dist/runtime/host-load-admission.js +19 -4
- package/dist/runtime/host-load-child-environment.d.ts +11 -6
- package/dist/runtime/host-load-child-environment.js +22 -11
- package/dist/runtime/host-load-governor-config.d.ts +19 -1
- package/dist/runtime/host-load-governor-config.js +37 -0
- package/dist/runtime/host-load-governor.d.ts +14 -0
- package/dist/runtime/host-load-governor.js +139 -26
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +80 -0
- package/dist/runtime/host-load-sampler.d.ts +34 -4
- package/dist/runtime/host-load-sampler.js +73 -7
- package/dist/runtime/host-load-step-class.d.ts +3 -1
- package/dist/runtime/host-load-step-class.js +60 -5
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +26 -0
- package/dist/runtime/host-load-token-ledger.js +93 -61
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +29 -1
- package/dist/runtime/host-runtime-lease.d.ts +62 -4
- package/dist/runtime/host-runtime-lease.js +235 -168
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +36 -0
- package/dist/runtime/managed-command-teardown.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/sandbox/host-capacity-broker.d.ts +10 -2
- package/dist/sandbox/host-capacity-broker.js +27 -6
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.js +2 -6
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +0 -7
- package/dist/session/managed-attempt-tools.js +58 -91
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +5 -0
- package/dist/session/managed-build-receipt.js +8 -3
- package/dist/session/managed-command-host-load.d.ts +2 -0
- package/dist/session/managed-command-host-load.js +2 -1
- package/dist/session/phase-completion.artifacts.js +2 -1
- package/dist/session/phase-completion.d.ts +8 -0
- package/dist/session/phase-completion.js +1 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.runtime.d.ts +0 -8
- package/dist/session/phase-completion.runtime.js +43 -197
- package/dist/session/phase-completion.schemas.js +25 -23
- package/dist/session/phase-completion.validation.js +3 -1
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.js +10 -10
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +30 -14
- package/dist/session/pre-publication-validation.js +207 -134
- package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
- package/dist/session/provider-cli/claude-background-work.js +181 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
- package/dist/session/provider-cli/provider-cli.process.js +39 -430
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +71 -31
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
- package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
- package/dist/session/provider-cli/provider-cli.service.js +78 -171
- package/dist/session/provider-cli/provider-cli.types.d.ts +26 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -0
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +42 -14
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +6 -1
- package/dist/session/session.service.d.ts +9 -2
- package/dist/session/session.service.js +169 -66
- package/dist/session/session.types.js +4 -4
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.js +14 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +33 -0
- package/dist/worktree/wip-git.js +122 -0
- package/dist/worktree/wip-refs.d.ts +62 -0
- package/dist/worktree/wip-refs.js +119 -0
- package/dist/worktree/wip-restore.d.ts +38 -0
- package/dist/worktree/wip-restore.js +190 -0
- package/dist/worktree/wip-snapshot.d.ts +50 -0
- package/dist/worktree/wip-snapshot.js +268 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +34 -0
- package/dist/worktree/worktree-origin-sync.js +127 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +98 -0
- package/dist/worktree/worktree-wip.d.ts +50 -0
- package/dist/worktree/worktree-wip.js +185 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +27 -5
- package/dist/worktree/worktree.service.js +110 -181
- package/dist/worktree/worktree.types.d.ts +31 -0
- package/package.json +2 -2
|
@@ -2,7 +2,6 @@ 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
5
|
import { sandboxHostLoadGateFromEnvironment } from "../sandbox-host-capacity-gate.js";
|
|
7
6
|
import { buildSpecBody, selectLaneCommand } from "../../worktree/artifact-injector.js";
|
|
8
7
|
import { defaultWorktreeCoordinatorStateRoot } from "../../worktree/worktree-paths.js";
|
|
@@ -11,14 +10,14 @@ import { ForgeFailureError } from "../session.types.js";
|
|
|
11
10
|
import { cleanupCompletionTools, commitWorktreeChanges, completionPhaseFromArtifact, emitArchitectStructuredEvents, emitCompletionArtifactRecorded, emitDecomposeGateArtifacts, emitDraftGateArtifacts, emitPhaseCompletionEvent, emitPhaseGateEvents, emitQaArtifactRecorded, emitQaStructuredEvents, enforceQaBrowserLaunchTargetGate, LiveArchitectArtifactEmitter, LiveCompletionArtifactEmitter, LiveQaArtifactEmitter, readCompletionArtifactsForRun, readQaCompletionArtifactBundle, waitForCompletionArtifact } from "./provider-cli.artifacts.js";
|
|
12
11
|
import { diffClaimedChangedFiles, findUnpublishedWorktreePaths, normalizeChangedFilePath, stagePublishableWorktreeChangeSet, } from "../publishable-worktree-changes.js";
|
|
13
12
|
import { DeterministicProviderCliService } from "./provider-cli.deterministic.js";
|
|
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 { buildArchitectPrompt, buildConflictResolvePrompt, buildDebugCyclePrompt, buildDevelopCyclePrompt, buildDraftPrompt, buildDraftSpec, buildImplementationPrompt, buildProviderCliPrompt, buildProviderCliCommand, durableDraftInput, buildPullRequestCheckRepairPrompt, buildPullRequestCommentsPrompt, buildQaPrompt, formatProviderCliCommandForCheckpoint, isDecomposeDraftDispatch, isPullRequestCheckRepairDispatch, isPullRequestCommentsDispatch, shouldPipePromptToStdin, usesManagedWindowsHost } from "./provider-cli.prompts.js";
|
|
15
14
|
import { isTransientCodexProviderNotFoundFailure, providerCompletionToolMissingFailure, recoveringProviderProcessRunner, StreamingProviderProcessRunner } from "./provider-cli.process.js";
|
|
16
|
-
import {
|
|
17
|
-
import { clip, createProviderOutputState, parseJsonLine } from "./provider-output-state.js";
|
|
15
|
+
import { admitUserConfigIsolatedProvider, emitProviderUsageEvent, providerProcessEnv } from "./provider-cli.runtime.js";
|
|
16
|
+
import { clip, clipTail, createProviderOutputState, parseJsonLine } from "./provider-output-state.js";
|
|
18
17
|
import { writeCiRepairReadinessManifest } from "./ci-repair-readiness.js";
|
|
19
18
|
import { assertRepairHeadEpoch } from "./provider-cli.repair-epoch.js";
|
|
20
|
-
import {
|
|
21
|
-
|
|
19
|
+
import { PrePublicationValidator } from "../pre-publication-validation.js";
|
|
20
|
+
import { prePublicationRepairTurnsFromEnvironment, prepareRepairTurnLaunch, validatePrePublicationWithRepair, } from "./pre-publication-repair.js";
|
|
22
21
|
const maxQaCompletionRecoveryTurns = 2;
|
|
23
22
|
function assertCommentRepairArtifactMatchesDispatch(dispatch, artifact) {
|
|
24
23
|
const pullRequest = dispatch.pullRequest;
|
|
@@ -214,22 +213,6 @@ async function pushWorktreeBranch(git, worktreePath, branchName, repoPath, coord
|
|
|
214
213
|
function providerOwnsBranchPublication(context) {
|
|
215
214
|
return context.dispatch.sandbox?.executionMode !== "docker";
|
|
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
|
-
};
|
|
222
|
-
if (context.processRunner)
|
|
223
|
-
return { baselineRevision, environment, processRunner: context.processRunner, hostLoadOwner };
|
|
224
|
-
if (context.dispatch.sandbox?.executionMode !== "docker")
|
|
225
|
-
return { baselineRevision, environment, hostLoadOwner };
|
|
226
|
-
const expectedSandboxId = context.dispatch.sandbox.dispatchAttemptId;
|
|
227
|
-
const observedSandboxId = context.runtimeEnvironment?.FORGE_SANDBOX_ID ?? process.env.FORGE_SANDBOX_ID;
|
|
228
|
-
if (observedSandboxId !== expectedSandboxId) {
|
|
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");
|
|
230
|
-
}
|
|
231
|
-
return { baselineRevision, environment, processRunner: defaultRunner, hostLoadOwner };
|
|
232
|
-
}
|
|
233
216
|
function remoteTrackingRefspec(branchName) {
|
|
234
217
|
return `refs/heads/${branchName}:refs/remotes/origin/${branchName}`;
|
|
235
218
|
}
|
|
@@ -264,11 +247,6 @@ function providerCliExitFailure(command, result) {
|
|
|
264
247
|
}
|
|
265
248
|
return new Error(`${command} exited ${result.exitCode}${suffix}`);
|
|
266
249
|
}
|
|
267
|
-
function clipTail(value, maximumLength) {
|
|
268
|
-
if (value.length <= maximumLength)
|
|
269
|
-
return value;
|
|
270
|
-
return `...${value.slice(-(maximumLength - 3))}`;
|
|
271
|
-
}
|
|
272
250
|
/**
|
|
273
251
|
* Capacity is trusted only when a nonzero provider process writes one of the
|
|
274
252
|
* narrow service-level messages to stderr. Stdout can contain arbitrary agent
|
|
@@ -571,24 +549,25 @@ export class ProcessBackedProviderCliService {
|
|
|
571
549
|
providerToolHeartbeatIntervalMs;
|
|
572
550
|
publicationCoordinator;
|
|
573
551
|
prePublicationValidator;
|
|
552
|
+
prePublicationRepairTurns;
|
|
574
553
|
constructor(processRunner = new StreamingProviderProcessRunner(), git = new GitClient(), providerToolHeartbeatIntervalMs = defaultProviderToolHeartbeatIntervalMs, publicationCoordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
575
554
|
// The Docker sandbox worker (`forge` run-once via ForgeBridgeCliService) builds
|
|
576
555
|
// this default. A container cannot reach the host ledger, so when the host
|
|
577
556
|
// bridge enabled it, its steps ask the bridge for tokens over the sandbox
|
|
578
557
|
// channel (decision 0013); elsewhere the gate is absent and validation is ungated.
|
|
579
|
-
prePublicationValidator = new PrePublicationValidator(undefined, undefined, undefined, sandboxHostLoadGateFromEnvironment())) {
|
|
558
|
+
prePublicationValidator = new PrePublicationValidator(undefined, undefined, undefined, sandboxHostLoadGateFromEnvironment()), prePublicationRepairTurns = prePublicationRepairTurnsFromEnvironment()) {
|
|
580
559
|
this.processRunner = processRunner;
|
|
581
560
|
this.git = git;
|
|
582
561
|
this.providerToolHeartbeatIntervalMs = providerToolHeartbeatIntervalMs;
|
|
583
562
|
this.publicationCoordinator = publicationCoordinator;
|
|
584
563
|
this.prePublicationValidator = prePublicationValidator;
|
|
564
|
+
this.prePublicationRepairTurns = prePublicationRepairTurns;
|
|
585
565
|
}
|
|
586
566
|
async runDraft(context) {
|
|
587
|
-
const { dispatch } = context;
|
|
567
|
+
const { dispatch, worktree } = admitUserConfigIsolatedProvider(context);
|
|
588
568
|
if (!dispatch.draft) {
|
|
589
569
|
throw new Error("Draft dispatch context is missing.");
|
|
590
570
|
}
|
|
591
|
-
const { worktree } = context;
|
|
592
571
|
const metadataRoot = path.join(worktree.worktreePath, ".forge", "work-items", dispatch.workItem.id);
|
|
593
572
|
await fs.mkdir(metadataRoot, { recursive: true });
|
|
594
573
|
await fs.writeFile(path.join(metadataRoot, "draft-input.json"), JSON.stringify(durableDraftInput(dispatch), null, 2) + "\n", "utf8");
|
|
@@ -763,7 +742,7 @@ export class ProcessBackedProviderCliService {
|
|
|
763
742
|
}
|
|
764
743
|
}
|
|
765
744
|
async runImplementation(context) {
|
|
766
|
-
const { dispatch, worktree } = context;
|
|
745
|
+
const { dispatch, worktree } = admitUserConfigIsolatedProvider(context);
|
|
767
746
|
const validationBaselineRevision = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
768
747
|
const phase = completionPhaseFromDispatch(dispatch);
|
|
769
748
|
const developCycle = usesDevelopCycleCompletion(dispatch);
|
|
@@ -843,9 +822,8 @@ export class ProcessBackedProviderCliService {
|
|
|
843
822
|
await liveCompletionEvents.stop();
|
|
844
823
|
await cleanupCompletionTools(completionTools, context.emit);
|
|
845
824
|
}
|
|
846
|
-
if (result.exitCode !== 0)
|
|
825
|
+
if (result.exitCode !== 0)
|
|
847
826
|
throw providerCliExitFailure(command.command, result);
|
|
848
|
-
}
|
|
849
827
|
await context.emit({
|
|
850
828
|
role: "runner",
|
|
851
829
|
kind: "checkpoint",
|
|
@@ -915,7 +893,7 @@ export class ProcessBackedProviderCliService {
|
|
|
915
893
|
};
|
|
916
894
|
}
|
|
917
895
|
async runArchitect(context) {
|
|
918
|
-
const { dispatch, worktree } = context;
|
|
896
|
+
const { dispatch, worktree } = admitUserConfigIsolatedProvider(context);
|
|
919
897
|
const metadataRoot = path.join(worktree.worktreePath, ".forge", "work-items", dispatch.workItem.id);
|
|
920
898
|
await fs.mkdir(metadataRoot, { recursive: true });
|
|
921
899
|
const laneCommand = selectLaneCommand(dispatch.artifacts, dispatch.execution.lane, dispatch.cycleRun.phase);
|
|
@@ -1020,7 +998,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1020
998
|
};
|
|
1021
999
|
}
|
|
1022
1000
|
async runQa(context) {
|
|
1023
|
-
const { dispatch, worktree } = context;
|
|
1001
|
+
const { dispatch, worktree } = admitUserConfigIsolatedProvider(context);
|
|
1024
1002
|
const metadataRoot = path.join(worktree.worktreePath, ".forge", "work-items", dispatch.workItem.id);
|
|
1025
1003
|
await fs.mkdir(metadataRoot, { recursive: true });
|
|
1026
1004
|
const laneCommand = selectLaneCommand(dispatch.artifacts, dispatch.execution.lane, dispatch.cycleRun.phase);
|
|
@@ -1145,12 +1123,13 @@ export class ProcessBackedProviderCliService {
|
|
|
1145
1123
|
return await this.runPullRequestRepair(context, "conflict_resolve");
|
|
1146
1124
|
}
|
|
1147
1125
|
async runPullRequestRepair(context, route) {
|
|
1148
|
-
const { dispatch, worktree } = context;
|
|
1126
|
+
const { dispatch, worktree } = admitUserConfigIsolatedProvider(context);
|
|
1149
1127
|
const { expectedRepairHeadSha, preparedHeadSha } = await assertRepairHeadEpoch(context, this.git);
|
|
1150
1128
|
const repairChecks = route === "ci_repair" || isPullRequestCheckRepairDispatch(dispatch);
|
|
1151
1129
|
const addressComments = !repairChecks && isPullRequestCommentsDispatch(dispatch);
|
|
1152
1130
|
let repairSpec = null;
|
|
1153
1131
|
let repairEnvironment = context.runtimeEnvironment;
|
|
1132
|
+
let ciRepairSpecPath = null;
|
|
1154
1133
|
let completionTools = null;
|
|
1155
1134
|
if (repairChecks) {
|
|
1156
1135
|
const metadataRoot = path.join(worktree.worktreePath, ".forge", "work-items", dispatch.workItem.id);
|
|
@@ -1161,6 +1140,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1161
1140
|
}
|
|
1162
1141
|
const specBody = buildSpecBody(laneCommand, dispatch.workItem, "ci_repair");
|
|
1163
1142
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
1143
|
+
ciRepairSpecPath = specPath;
|
|
1164
1144
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
1165
1145
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), `${JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" })}\n`, "utf8");
|
|
1166
1146
|
repairSpec = {
|
|
@@ -1315,6 +1295,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1315
1295
|
: addressComments
|
|
1316
1296
|
? "comment_repair"
|
|
1317
1297
|
: "conflict_repair";
|
|
1298
|
+
const readinessSpecPath = ciRepairSpecPath;
|
|
1318
1299
|
await this.validatePrePublicationWithRecovery({
|
|
1319
1300
|
context,
|
|
1320
1301
|
validationProfile,
|
|
@@ -1322,6 +1303,10 @@ export class ProcessBackedProviderCliService {
|
|
|
1322
1303
|
outputState,
|
|
1323
1304
|
preparedHeadSha,
|
|
1324
1305
|
repairScope: "pull_request",
|
|
1306
|
+
...(readinessSpecPath ? {
|
|
1307
|
+
// The readiness manifest records the attempt URLs; a restart must not leave it pointing at the old stack.
|
|
1308
|
+
onRuntimeEnvironmentRefreshed: async (runtimeEnvironment) => (await writeCiRepairReadinessManifest(dispatch, worktree.worktreePath, readinessSpecPath, runtimeEnvironment)).environment,
|
|
1309
|
+
} : {}),
|
|
1325
1310
|
});
|
|
1326
1311
|
const stagedChangeSet = await stagePublishableWorktreeChangeSet(this.git, worktree.worktreePath);
|
|
1327
1312
|
const stagedChangedFiles = stagedChangeSet.publishable;
|
|
@@ -1590,141 +1575,75 @@ export class ProcessBackedProviderCliService {
|
|
|
1590
1575
|
return artifact;
|
|
1591
1576
|
}
|
|
1592
1577
|
async validatePrePublicationWithRecovery(options) {
|
|
1593
|
-
const
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1578
|
+
const processRunner = recoveringProviderProcessRunner(options.context.processRunner ?? this.processRunner);
|
|
1579
|
+
await validatePrePublicationWithRepair(options, {
|
|
1580
|
+
validator: this.prePublicationValidator,
|
|
1581
|
+
defaultProcessRunner: this.processRunner,
|
|
1582
|
+
maxRepairTurns: this.prePublicationRepairTurns,
|
|
1583
|
+
runRepairTurn: async (turn) => await this.runPrePublicationRepairTurn(options, processRunner, turn),
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* Resumes the provider thread for one in-place repair turn; the turn must leave HEAD where it was.
|
|
1588
|
+
* The turn launches with its own Forge MCP server (prepareRepairTurnLaunch), removed when it exits.
|
|
1589
|
+
*/
|
|
1590
|
+
async runPrePublicationRepairTurn(options, processRunner, turn) {
|
|
1591
|
+
const { context, outputState, preparedHeadSha } = options;
|
|
1592
|
+
const { worktree } = context;
|
|
1593
|
+
const { repairTurn: nextRepairTurn, maxRepairTurns, environment } = turn;
|
|
1594
|
+
const { repairDispatch, providerPrompt, pipePromptToStdin, completionTools, command } = await prepareRepairTurnLaunch(context, turn);
|
|
1595
|
+
const toolHeartbeat = new ProviderToolActivityHeartbeat(outputState, context.emit, this.providerToolHeartbeatIntervalMs);
|
|
1596
|
+
let result;
|
|
1597
|
+
let providerStarted = false;
|
|
1598
|
+
try {
|
|
1599
|
+
result = await processRunner.run({
|
|
1600
|
+
command: command.command,
|
|
1601
|
+
args: command.args,
|
|
1602
|
+
cwd: worktree.worktreePath,
|
|
1603
|
+
env: environment,
|
|
1604
|
+
resumesProviderThread: Boolean(repairDispatch.session.resumeProviderThreadId),
|
|
1605
|
+
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1606
|
+
}, {
|
|
1607
|
+
onStarted: async () => {
|
|
1602
1608
|
await context.emit({
|
|
1603
1609
|
role: "runner",
|
|
1604
1610
|
kind: "checkpoint",
|
|
1605
|
-
content: `
|
|
1606
|
-
eventType: "
|
|
1607
|
-
data: JSON.stringify({ repairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1611
|
+
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxRepairTurns} is supervised and ready.`,
|
|
1612
|
+
eventType: "provider_cli_started",
|
|
1608
1613
|
});
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1614
|
+
providerStarted = true;
|
|
1615
|
+
},
|
|
1616
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1617
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1618
|
+
onStdoutLine: async (line) => {
|
|
1619
|
+
await toolHeartbeat.consume(line);
|
|
1620
|
+
},
|
|
1621
|
+
}, context.signal);
|
|
1622
|
+
}
|
|
1623
|
+
finally {
|
|
1624
|
+
toolHeartbeat.stop();
|
|
1625
|
+
try {
|
|
1626
|
+
if (providerStarted) {
|
|
1616
1627
|
await context.emit({
|
|
1617
1628
|
role: "runner",
|
|
1618
|
-
kind: "
|
|
1619
|
-
content: `
|
|
1620
|
-
eventType: "
|
|
1621
|
-
data: JSON.stringify({ checkId: error.checkId, repairTurns: repairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1629
|
+
kind: "checkpoint",
|
|
1630
|
+
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxRepairTurns} exited.`,
|
|
1631
|
+
eventType: "provider_cli_completed",
|
|
1622
1632
|
});
|
|
1623
|
-
throw error;
|
|
1624
|
-
}
|
|
1625
|
-
const providerThreadId = outputState.providerThreadId?.trim();
|
|
1626
|
-
if (!providerThreadId) {
|
|
1627
|
-
throw new Error(`prepublication_repair_unavailable: ${error.message}; provider did not report a resumable thread id, so Forge preserved the dirty worktree without starting a blind replacement run.`, { cause: error });
|
|
1628
|
-
}
|
|
1629
|
-
const nextRepairTurn = repairTurn + 1;
|
|
1630
|
-
const focusedPrompt = buildPrePublicationRepairPrompt(error, nextRepairTurn, repairScope);
|
|
1631
|
-
const repairDispatch = {
|
|
1632
|
-
...dispatch,
|
|
1633
|
-
session: { ...dispatch.session, resumeProviderThreadId: providerThreadId },
|
|
1634
|
-
};
|
|
1635
|
-
const providerPrompt = buildProviderCliPrompt(repairDispatch, focusedPrompt, repairEnvironment);
|
|
1636
|
-
const pipePromptToStdin = shouldPipePromptToStdin(repairDispatch.execution.provider, providerPrompt, usesManagedWindowsHost(repairDispatch));
|
|
1637
|
-
const command = buildProviderCliCommand(repairDispatch, {
|
|
1638
|
-
worktreePath: worktree.worktreePath,
|
|
1639
|
-
prompt: focusedPrompt,
|
|
1640
|
-
promptFromStdin: pipePromptToStdin,
|
|
1641
|
-
runtimeEnvironment: repairEnvironment,
|
|
1642
|
-
});
|
|
1643
|
-
await context.emit({
|
|
1644
|
-
role: "runner",
|
|
1645
|
-
kind: "checkpoint",
|
|
1646
|
-
content: `Resuming ${dispatch.execution.provider} ${outputState.sessionLabel ?? "provider thread"} for bounded pre-publication repair ${nextRepairTurn}/${maxPrePublicationRepairTurns} after '${error.checkId}' failed.`,
|
|
1647
|
-
eventType: "prepublication_repair_started",
|
|
1648
|
-
data: JSON.stringify({ checkId: error.checkId, repairTurn: nextRepairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1649
|
-
});
|
|
1650
|
-
const toolHeartbeat = new ProviderToolActivityHeartbeat(outputState, context.emit, this.providerToolHeartbeatIntervalMs);
|
|
1651
|
-
let result;
|
|
1652
|
-
let providerStarted = false;
|
|
1653
|
-
try {
|
|
1654
|
-
result = await processRunner.run({
|
|
1655
|
-
command: command.command,
|
|
1656
|
-
args: command.args,
|
|
1657
|
-
cwd: worktree.worktreePath,
|
|
1658
|
-
env: environment,
|
|
1659
|
-
resumesProviderThread: Boolean(repairDispatch.session.resumeProviderThreadId),
|
|
1660
|
-
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1661
|
-
}, {
|
|
1662
|
-
onStarted: async () => {
|
|
1663
|
-
await context.emit({
|
|
1664
|
-
role: "runner",
|
|
1665
|
-
kind: "checkpoint",
|
|
1666
|
-
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxPrePublicationRepairTurns} is supervised and ready.`,
|
|
1667
|
-
eventType: "provider_cli_started",
|
|
1668
|
-
});
|
|
1669
|
-
providerStarted = true;
|
|
1670
|
-
},
|
|
1671
|
-
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1672
|
-
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1673
|
-
onStdoutLine: async (line) => {
|
|
1674
|
-
await toolHeartbeat.consume(line);
|
|
1675
|
-
},
|
|
1676
|
-
}, context.signal);
|
|
1677
|
-
}
|
|
1678
|
-
finally {
|
|
1679
|
-
toolHeartbeat.stop();
|
|
1680
|
-
if (providerStarted) {
|
|
1681
|
-
await context.emit({
|
|
1682
|
-
role: "runner",
|
|
1683
|
-
kind: "checkpoint",
|
|
1684
|
-
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxPrePublicationRepairTurns} exited.`,
|
|
1685
|
-
eventType: "provider_cli_completed",
|
|
1686
|
-
});
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
if (result.exitCode !== 0)
|
|
1690
|
-
throw providerCliExitFailure(command.command, result);
|
|
1691
|
-
const postRepairHeadSha = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
1692
|
-
if (postRepairHeadSha.toLowerCase() !== preparedHeadSha.toLowerCase()) {
|
|
1693
|
-
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 });
|
|
1694
1633
|
}
|
|
1695
1634
|
}
|
|
1635
|
+
finally {
|
|
1636
|
+
await cleanupCompletionTools(completionTools, context.emit);
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
if (result.exitCode !== 0)
|
|
1640
|
+
throw providerCliExitFailure(command.command, result);
|
|
1641
|
+
const postRepairHeadSha = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
1642
|
+
if (postRepairHeadSha.toLowerCase() !== preparedHeadSha.toLowerCase()) {
|
|
1643
|
+
throw new Error(`provider_publication_boundary_violation: pre-publication repair changed HEAD from ${preparedHeadSha} to ${postRepairHeadSha}; Forge requires provider changes to remain uncommitted and unpushed until validation passes.`, { cause: turn.failure });
|
|
1696
1644
|
}
|
|
1697
1645
|
}
|
|
1698
1646
|
}
|
|
1699
|
-
function buildPrePublicationRepairPrompt(error, repairTurn, repairScope) {
|
|
1700
|
-
const invocation = [error.command, ...error.args].join(" ");
|
|
1701
|
-
const priorWork = repairScope === "implementation"
|
|
1702
|
-
? "Keep the completed implementation and its Forge-owned completion artifacts intact."
|
|
1703
|
-
: "Keep the existing PR-comment or CI repairs intact.";
|
|
1704
|
-
return [
|
|
1705
|
-
`Forge pre-publication validation failed after your ${repairScope === "implementation" ? "implementation" : "PR repair"} turn.`,
|
|
1706
|
-
`This is bounded in-place repair turn ${repairTurn}/${maxPrePublicationRepairTurns}.`,
|
|
1707
|
-
`Failed check: ${error.checkId}`,
|
|
1708
|
-
`Command: ${invocation}`,
|
|
1709
|
-
`Exit code: ${error.exitCode}`,
|
|
1710
|
-
"Diagnostics:",
|
|
1711
|
-
error.detail || "The validation command returned no diagnostic output.",
|
|
1712
|
-
"Fix the root cause in the current worktree and run the focused failing check.",
|
|
1713
|
-
`${priorWork} Do not commit, push, rebase, or modify Forge-owned protocol artifacts.`,
|
|
1714
|
-
"When the focused check passes, stop; Bridge will rerun the complete required pre-publication profile and owns commit/push.",
|
|
1715
|
-
].join("\n\n");
|
|
1716
|
-
}
|
|
1717
|
-
function publicationCapabilities(context, runtimeEnvironment) {
|
|
1718
|
-
const capabilities = new Set();
|
|
1719
|
-
const launchTarget = context.dispatch.qaBrowser?.launchTarget;
|
|
1720
|
-
if (runtimeEnvironment?.FORGE_PLAYWRIGHT_CONFIG
|
|
1721
|
-
|| launchTarget?.url
|
|
1722
|
-
|| launchTarget?.command
|
|
1723
|
-
|| launchTarget?.managed_runtime_port) {
|
|
1724
|
-
capabilities.add("browser_launch");
|
|
1725
|
-
}
|
|
1726
|
-
return capabilities;
|
|
1727
|
-
}
|
|
1728
1647
|
async function stageDraftAttachments(dispatch, metadataRoot) {
|
|
1729
1648
|
const attachments = dispatch.draft?.attachments ?? [];
|
|
1730
1649
|
const stageable = attachments.filter((attachment) => (attachment.kind === "text" && typeof attachment.textContent === "string")
|
|
@@ -1786,18 +1705,6 @@ function clipFileName(fileName, maxLength) {
|
|
|
1786
1705
|
const maxStemLength = Math.max(1, maxLength - extension.length);
|
|
1787
1706
|
return `${stem.slice(0, maxStemLength)}${extension}`;
|
|
1788
1707
|
}
|
|
1789
|
-
const providerPromptStdinThreshold = 8_000;
|
|
1790
|
-
function shouldPipePromptToStdin(provider, prompt, force = false) {
|
|
1791
|
-
const normalized = provider.trim().toLowerCase();
|
|
1792
|
-
if (normalized === "claude") {
|
|
1793
|
-
return true;
|
|
1794
|
-
}
|
|
1795
|
-
return normalized === "codex"
|
|
1796
|
-
&& (force || Buffer.byteLength(prompt, "utf8") > providerPromptStdinThreshold);
|
|
1797
|
-
}
|
|
1798
|
-
function usesManagedWindowsHost(dispatch) {
|
|
1799
|
-
return process.platform === "win32" && dispatch.sandbox?.executionMode === "host";
|
|
1800
|
-
}
|
|
1801
1708
|
function isFakeWorkerModel(model) {
|
|
1802
1709
|
return model.trim().toLowerCase() === fakeWorkerModel;
|
|
1803
1710
|
}
|
|
@@ -1,6 +1,19 @@
|
|
|
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;
|
|
@@ -9,6 +22,19 @@ export interface ProviderCliRunContext {
|
|
|
9
22
|
readonly hostLoadEnvironment?: Readonly<Record<string, string>>;
|
|
10
23
|
readonly processRunner?: ProviderProcessRunner;
|
|
11
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[];
|
|
12
38
|
emit(event: RunnerDispatchEvent): Promise<void>;
|
|
13
39
|
}
|
|
14
40
|
export interface ProviderCliDraftContext {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Windows environment a provider child (and every tool it runs, such as dotnet and pwsh)
|
|
3
|
+
* gets from the Bridge. Provider children start from an allowlist, not the Bridge's whole
|
|
4
|
+
* environment, so each variable Windows tools expect must be listed here or defaulted below.
|
|
5
|
+
*/
|
|
6
|
+
export declare const windowsAllowedProviderParentEnvNames: readonly ["SystemRoot", "SystemDrive", "ComSpec", "PATHEXT", "APPDATA", "LOCALAPPDATA", "USERNAME", "USERDOMAIN", "HOMEDRIVE", "HOMEPATH", "ProgramData", "ProgramFiles", "ProgramFiles(x86)", "ProgramW6432", "PROCESSOR_ARCHITECTURE", "PROCESSOR_IDENTIFIER", "NUMBER_OF_PROCESSORS", "ALLUSERSPROFILE", "PUBLIC", "CommonProgramFiles", "CommonProgramFiles(x86)", "CommonProgramW6432", "OS", "windir", "DOTNET_ROOT", "DOTNET_ROOT(x86)", "DOTNET_CLI_HOME", "NUGET_PACKAGES", "NUGET_HTTP_CACHE_PATH", "CLAUDE_CODE_GIT_BASH_PATH"];
|
|
7
|
+
/** Fills in the Windows system, machine, profile and .NET variables a provider child needs. */
|
|
8
|
+
export declare function normalizeWindowsProviderEnvironment(env: NodeJS.ProcessEnv, parentEnv: NodeJS.ProcessEnv, homeDir: string, arch: string): void;
|
|
9
|
+
/** A case-insensitive, non-blank environment lookup (Windows variable names ignore case). */
|
|
10
|
+
export declare function readEnvironmentValue(env: NodeJS.ProcessEnv, name: string): string | undefined;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* The Windows environment a provider child (and every tool it runs, such as dotnet and pwsh)
|
|
4
|
+
* gets from the Bridge. Provider children start from an allowlist, not the Bridge's whole
|
|
5
|
+
* environment, so each variable Windows tools expect must be listed here or defaulted below.
|
|
6
|
+
*/
|
|
7
|
+
export const windowsAllowedProviderParentEnvNames = [
|
|
8
|
+
"SystemRoot",
|
|
9
|
+
"SystemDrive",
|
|
10
|
+
"ComSpec",
|
|
11
|
+
"PATHEXT",
|
|
12
|
+
"APPDATA",
|
|
13
|
+
"LOCALAPPDATA",
|
|
14
|
+
"USERNAME",
|
|
15
|
+
"USERDOMAIN",
|
|
16
|
+
"HOMEDRIVE",
|
|
17
|
+
"HOMEPATH",
|
|
18
|
+
"ProgramData",
|
|
19
|
+
"ProgramFiles",
|
|
20
|
+
"ProgramFiles(x86)",
|
|
21
|
+
"ProgramW6432",
|
|
22
|
+
// The .NET SDK reads these during startup (the MSI workload installer behind
|
|
23
|
+
// `dotnet --info` and `dotnet workload` throws on a missing PROCESSOR_ARCHITECTURE),
|
|
24
|
+
// and other Windows tools expect the standard machine variables too.
|
|
25
|
+
"PROCESSOR_ARCHITECTURE",
|
|
26
|
+
"PROCESSOR_IDENTIFIER",
|
|
27
|
+
"NUMBER_OF_PROCESSORS",
|
|
28
|
+
"ALLUSERSPROFILE",
|
|
29
|
+
"PUBLIC",
|
|
30
|
+
"CommonProgramFiles",
|
|
31
|
+
"CommonProgramFiles(x86)",
|
|
32
|
+
"CommonProgramW6432",
|
|
33
|
+
"OS",
|
|
34
|
+
"windir",
|
|
35
|
+
"DOTNET_ROOT",
|
|
36
|
+
"DOTNET_ROOT(x86)",
|
|
37
|
+
"DOTNET_CLI_HOME",
|
|
38
|
+
"NUGET_PACKAGES",
|
|
39
|
+
"NUGET_HTTP_CACHE_PATH",
|
|
40
|
+
"CLAUDE_CODE_GIT_BASH_PATH"
|
|
41
|
+
];
|
|
42
|
+
/** Fills in the Windows system, machine, profile and .NET variables a provider child needs. */
|
|
43
|
+
export function normalizeWindowsProviderEnvironment(env, parentEnv, homeDir, arch) {
|
|
44
|
+
const systemRoot = normalizeWindowsSystemEnvironment(env, parentEnv);
|
|
45
|
+
normalizeWindowsProgramFolders(env, parentEnv);
|
|
46
|
+
normalizeWindowsMachineEnvironment(env, parentEnv, systemRoot, arch);
|
|
47
|
+
normalizeWindowsProfileEnvironment(env, parentEnv, homeDir);
|
|
48
|
+
setEnvironmentValueIfMissing(env, "DOTNET_NOLOGO", "1");
|
|
49
|
+
setEnvironmentValueIfMissing(env, "DOTNET_CLI_TELEMETRY_OPTOUT", "1");
|
|
50
|
+
setEnvironmentValueIfMissing(env, "DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "1");
|
|
51
|
+
setEnvironmentValueIfMissing(env, "NUGET_XMLDOC_MODE", "skip");
|
|
52
|
+
}
|
|
53
|
+
function normalizeWindowsSystemEnvironment(env, parentEnv) {
|
|
54
|
+
const systemRoot = readEnvironmentValue(env, "SystemRoot") ?? readEnvironmentValue(parentEnv, "SystemRoot") ?? "C:\\Windows";
|
|
55
|
+
const systemDrive = path.win32.parse(systemRoot).root.replace(/\\$/, "") || "C:";
|
|
56
|
+
setEnvironmentValueIfMissing(env, "SystemRoot", systemRoot);
|
|
57
|
+
setEnvironmentValueIfMissing(env, "SystemDrive", readEnvironmentValue(parentEnv, "SystemDrive") ?? systemDrive);
|
|
58
|
+
setEnvironmentValueIfMissing(env, "ComSpec", readEnvironmentValue(parentEnv, "ComSpec") ?? path.win32.join(systemRoot, "System32", "cmd.exe"));
|
|
59
|
+
setEnvironmentValueIfMissing(env, "PATHEXT", readEnvironmentValue(parentEnv, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL");
|
|
60
|
+
return systemRoot;
|
|
61
|
+
}
|
|
62
|
+
function normalizeWindowsProgramFolders(env, parentEnv) {
|
|
63
|
+
const systemDriveRoot = `${readEnvironmentValue(env, "SystemDrive") ?? "C:"}\\`;
|
|
64
|
+
const defaultProgramFiles = path.win32.join(systemDriveRoot, "Program Files");
|
|
65
|
+
const defaultProgramData = path.win32.join(systemDriveRoot, "ProgramData");
|
|
66
|
+
const programFiles = readEnvironmentValue(env, "ProgramFiles")
|
|
67
|
+
?? readEnvironmentValue(parentEnv, "ProgramFiles")
|
|
68
|
+
?? defaultProgramFiles;
|
|
69
|
+
setEnvironmentValueIfMissing(env, "ProgramFiles", programFiles);
|
|
70
|
+
setEnvironmentValueIfMissing(env, "ProgramW6432", readEnvironmentValue(parentEnv, "ProgramW6432") ?? defaultProgramFiles);
|
|
71
|
+
setEnvironmentValueIfMissing(env, "ProgramFiles(x86)", readEnvironmentValue(parentEnv, "ProgramFiles(x86)") ?? path.win32.join(systemDriveRoot, "Program Files (x86)"));
|
|
72
|
+
setEnvironmentValueIfMissing(env, "ProgramData", readEnvironmentValue(parentEnv, "ProgramData") ?? defaultProgramData);
|
|
73
|
+
setEnvironmentValueIfMissing(env, "ALLUSERSPROFILE", readEnvironmentValue(parentEnv, "ALLUSERSPROFILE") ?? readEnvironmentValue(env, "ProgramData") ?? defaultProgramData);
|
|
74
|
+
}
|
|
75
|
+
function normalizeWindowsMachineEnvironment(env, parentEnv, systemRoot, arch) {
|
|
76
|
+
setEnvironmentValueIfMissing(env, "windir", readEnvironmentValue(parentEnv, "windir") ?? systemRoot);
|
|
77
|
+
setEnvironmentValueIfMissing(env, "OS", readEnvironmentValue(parentEnv, "OS") ?? "Windows_NT");
|
|
78
|
+
const processorArchitecture = readEnvironmentValue(parentEnv, "PROCESSOR_ARCHITECTURE") ?? windowsProcessorArchitecture(arch);
|
|
79
|
+
if (processorArchitecture) {
|
|
80
|
+
setEnvironmentValueIfMissing(env, "PROCESSOR_ARCHITECTURE", processorArchitecture);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** The PROCESSOR_ARCHITECTURE value Windows sets for a native process of this architecture. */
|
|
84
|
+
function windowsProcessorArchitecture(arch) {
|
|
85
|
+
switch (arch) {
|
|
86
|
+
case "x64": return "AMD64";
|
|
87
|
+
case "arm64": return "ARM64";
|
|
88
|
+
case "ia32": return "x86";
|
|
89
|
+
default: return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function normalizeWindowsProfileEnvironment(env, parentEnv, homeDir) {
|
|
93
|
+
const userProfile = resolveWindowsUserProfile(env, parentEnv, homeDir);
|
|
94
|
+
if (userProfile) {
|
|
95
|
+
setEnvironmentValueIfMissing(env, "USERPROFILE", userProfile);
|
|
96
|
+
setEnvironmentValueIfMissing(env, "HOME", userProfile);
|
|
97
|
+
setEnvironmentValueIfMissing(env, "DOTNET_CLI_HOME", userProfile);
|
|
98
|
+
setEnvironmentValueIfMissing(env, "NUGET_PACKAGES", path.win32.join(userProfile, ".nuget", "packages"));
|
|
99
|
+
const parsed = path.win32.parse(userProfile);
|
|
100
|
+
if (parsed.root) {
|
|
101
|
+
setEnvironmentValueIfMissing(env, "HOMEDRIVE", parsed.root.replace(/\\$/, ""));
|
|
102
|
+
setEnvironmentValueIfMissing(env, "HOMEPATH", userProfile.slice(parsed.root.length - (parsed.root.endsWith("\\") ? 1 : 0)) || "\\");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const appData = readEnvironmentValue(env, "APPDATA")
|
|
106
|
+
?? readEnvironmentValue(parentEnv, "APPDATA")
|
|
107
|
+
?? (userProfile ? path.win32.join(userProfile, "AppData", "Roaming") : undefined);
|
|
108
|
+
const localAppData = readEnvironmentValue(env, "LOCALAPPDATA")
|
|
109
|
+
?? readEnvironmentValue(parentEnv, "LOCALAPPDATA")
|
|
110
|
+
?? (userProfile ? path.win32.join(userProfile, "AppData", "Local") : undefined);
|
|
111
|
+
if (appData) {
|
|
112
|
+
setEnvironmentValueIfMissing(env, "APPDATA", appData);
|
|
113
|
+
}
|
|
114
|
+
if (localAppData) {
|
|
115
|
+
setEnvironmentValueIfMissing(env, "LOCALAPPDATA", localAppData);
|
|
116
|
+
setEnvironmentValueIfMissing(env, "NUGET_HTTP_CACHE_PATH", path.win32.join(localAppData, "NuGet", "v3-cache"));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function resolveWindowsUserProfile(env, parentEnv, homeDir) {
|
|
120
|
+
const existing = readEnvironmentValue(env, "USERPROFILE") ?? readEnvironmentValue(parentEnv, "USERPROFILE");
|
|
121
|
+
if (existing) {
|
|
122
|
+
return existing;
|
|
123
|
+
}
|
|
124
|
+
const home = readEnvironmentValue(env, "HOME") ?? readEnvironmentValue(parentEnv, "HOME");
|
|
125
|
+
if (home && path.win32.isAbsolute(home)) {
|
|
126
|
+
return home;
|
|
127
|
+
}
|
|
128
|
+
const homeDrive = readEnvironmentValue(env, "HOMEDRIVE") ?? readEnvironmentValue(parentEnv, "HOMEDRIVE");
|
|
129
|
+
const homePath = readEnvironmentValue(env, "HOMEPATH") ?? readEnvironmentValue(parentEnv, "HOMEPATH");
|
|
130
|
+
if (homeDrive && homePath) {
|
|
131
|
+
return `${homeDrive}${homePath}`;
|
|
132
|
+
}
|
|
133
|
+
if (homeDir && path.win32.isAbsolute(homeDir)) {
|
|
134
|
+
return homeDir;
|
|
135
|
+
}
|
|
136
|
+
const systemDrive = readEnvironmentValue(env, "SystemDrive") ?? readEnvironmentValue(parentEnv, "SystemDrive") ?? "C:";
|
|
137
|
+
const username = readEnvironmentValue(env, "USERNAME") ?? readEnvironmentValue(parentEnv, "USERNAME");
|
|
138
|
+
return username ? path.win32.join(systemDrive, "Users", username) : undefined;
|
|
139
|
+
}
|
|
140
|
+
/** A case-insensitive, non-blank environment lookup (Windows variable names ignore case). */
|
|
141
|
+
export function readEnvironmentValue(env, name) {
|
|
142
|
+
const entry = Object.entries(env).find(([key]) => key.toLowerCase() === name.toLowerCase());
|
|
143
|
+
const value = entry?.[1];
|
|
144
|
+
return typeof value === "string" && value.trim().length > 0 ? value : undefined;
|
|
145
|
+
}
|
|
146
|
+
function setEnvironmentValueIfMissing(env, name, value) {
|
|
147
|
+
if (readEnvironmentValue(env, name)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
env[name] = value;
|
|
151
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type LaunchCommand } from "../../shared/process/windows-launch.js";
|
|
2
|
+
export declare function resolveWindowsProviderLaunch(command: string, args: readonly string[]): Promise<LaunchCommand>;
|
|
3
|
+
export declare function resolveCodexNpmDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
|
|
4
|
+
/**
|
|
5
|
+
* npm installs of Claude Code (`npm i -g @anthropic-ai/claude-code`) put a `claude.cmd` shim on
|
|
6
|
+
* PATH; launch its cli.js directly for the same Job Object reasons as Codex. The native installer
|
|
7
|
+
* ships `claude.exe`, which is preferred by PATH resolution and needs no rewrite.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveClaudeNpmDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
|
|
10
|
+
/**
|
|
11
|
+
* Avoids cmd.exe's nested-quote handling for package-manager shims. That
|
|
12
|
+
* quoting loses executable paths containing spaces after the command is
|
|
13
|
+
* wrapped by the Windows Job Object supervisor.
|
|
14
|
+
*
|
|
15
|
+
* Launches the entry point the shim itself runs. A Windows Node install ships
|
|
16
|
+
* both npm's own CLI and Corepack's npm shim next to `npm.cmd`, and `npm.cmd`
|
|
17
|
+
* runs npm's CLI. Launching Corepack's shim instead would apply Corepack's
|
|
18
|
+
* strict `packageManager` check: in a repository whose root pins pnpm, an npm
|
|
19
|
+
* package below it (with its own package-lock) is refused although its scripts
|
|
20
|
+
* pass when npm runs them. A shim that names none of the candidates prefers
|
|
21
|
+
* the tool's own CLI over Corepack's.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolvePackageManagerDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
|