@loucompanion/forge-bridge 0.1.4-dev.c2f22d1dd395 → 0.1.4-dev.ccffca94938b
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 +57 -2
- package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
- package/dist/bridge/bridge-chat-provider-command.js +137 -0
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -1
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +73 -2
- package/dist/bridge/bridge.service.js +312 -119
- 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 +5 -0
- package/dist/bridge/runner-host-capabilities.js +17 -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-facts.d.ts +2 -1
- package/dist/runtime/host-load-admission.d.ts +67 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +184 -0
- package/dist/runtime/host-load-governor.js +632 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +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 +75 -2
- package/dist/runtime/host-load-sampler.js +142 -8
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-pressure-stall.d.ts +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 +113 -0
- package/dist/sandbox/host-capacity-broker.js +334 -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/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +2 -0
- package/dist/session/managed-attempt-tools.js +157 -39
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +7 -0
- package/dist/session/phase-completion.artifacts.js +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 +208 -231
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +49 -93
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -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 +32 -20
- package/dist/session/pre-publication-validation.js +195 -158
- package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
- package/dist/session/provider-cli/claude-background-work.js +180 -0
- 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.d.ts +2 -1
- package/dist/session/provider-cli/provider-cli.artifacts.js +20 -7
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +73 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +39 -17
- package/dist/session/provider-cli/provider-cli.process.js +136 -345
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +65 -10
- package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +142 -162
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +8 -0
- package/dist/session/provider-cli/provider-output-state.js +15 -0
- package/dist/session/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 +238 -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 +12 -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/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 +5 -6
- 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
|
@@ -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>;
|
|
@@ -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,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True while an attempt-owned managed command (a receipt under
|
|
3
|
+
* `<FORGE_LOG_DIR>/managed-commands/`) is still starting, queued or running.
|
|
4
|
+
* Unreadable or stale receipts do not count.
|
|
5
|
+
*/
|
|
6
|
+
export declare function hasNonterminalManagedCommand(logDirectory: string | undefined, nowMs?: number): Promise<boolean>;
|
|
7
|
+
/** A stream event that shows the provider is working on a turn: model output or a tool result. */
|
|
8
|
+
export declare function isProviderTurnActivity(line: string): boolean;
|
|
9
|
+
export declare function isProviderTerminalFailure(line: string): boolean;
|
|
10
|
+
export declare function isProviderTerminalSuccess(line: string): boolean;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const nonterminalManagedCommandStatuses = new Set(["starting", "running", "waiting_for_build_slot"]);
|
|
4
|
+
// A running receipt is rewritten every 5 s. One that has not changed for a minute
|
|
5
|
+
// belongs to a command whose supervisor is gone, so it no longer holds the provider open.
|
|
6
|
+
const runningReceiptStaleMs = 60_000;
|
|
7
|
+
// Starting and queued receipts are written once. They hold the provider open for at most
|
|
8
|
+
// the command's own timeout (the managed-command maximum when absent) plus a margin.
|
|
9
|
+
const maximumManagedCommandTimeoutMs = 2 * 60 * 60_000;
|
|
10
|
+
const queuedReceiptMarginMs = 60_000;
|
|
11
|
+
/**
|
|
12
|
+
* True while an attempt-owned managed command (a receipt under
|
|
13
|
+
* `<FORGE_LOG_DIR>/managed-commands/`) is still starting, queued or running.
|
|
14
|
+
* Unreadable or stale receipts do not count.
|
|
15
|
+
*/
|
|
16
|
+
export async function hasNonterminalManagedCommand(logDirectory, nowMs = Date.now()) {
|
|
17
|
+
if (!logDirectory?.trim())
|
|
18
|
+
return false;
|
|
19
|
+
const directory = path.join(logDirectory, "managed-commands");
|
|
20
|
+
const names = await fs.readdir(directory).catch(() => []);
|
|
21
|
+
for (const name of names) {
|
|
22
|
+
if (!name.endsWith(".receipt.json"))
|
|
23
|
+
continue;
|
|
24
|
+
if (await receiptHoldsProvider(path.join(directory, name), nowMs))
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
async function receiptHoldsProvider(receiptPath, nowMs) {
|
|
30
|
+
try {
|
|
31
|
+
const [stat, content] = await Promise.all([fs.stat(receiptPath), fs.readFile(receiptPath, "utf8")]);
|
|
32
|
+
const receipt = JSON.parse(content);
|
|
33
|
+
const status = typeof receipt.status === "string" ? receipt.status : "";
|
|
34
|
+
if (!nonterminalManagedCommandStatuses.has(status))
|
|
35
|
+
return false;
|
|
36
|
+
const ageMs = nowMs - stat.mtimeMs;
|
|
37
|
+
if (status === "running")
|
|
38
|
+
return ageMs <= runningReceiptStaleMs;
|
|
39
|
+
const timeoutMs = typeof receipt.timeout_ms === "number" && Number.isFinite(receipt.timeout_ms)
|
|
40
|
+
? receipt.timeout_ms
|
|
41
|
+
: maximumManagedCommandTimeoutMs;
|
|
42
|
+
return ageMs <= timeoutMs + queuedReceiptMarginMs;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** A stream event that shows the provider is working on a turn: model output or a tool result. */
|
|
49
|
+
export function isProviderTurnActivity(line) {
|
|
50
|
+
const trimmed = line.trim();
|
|
51
|
+
if (!trimmed.startsWith("{"))
|
|
52
|
+
return false;
|
|
53
|
+
try {
|
|
54
|
+
const event = JSON.parse(trimmed);
|
|
55
|
+
return event.type === "assistant"
|
|
56
|
+
|| event.type === "user"
|
|
57
|
+
|| (event.type === "system" && event.subtype === "init")
|
|
58
|
+
|| event.type === "turn.started"
|
|
59
|
+
|| event.type === "item.started";
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function isProviderTerminalFailure(line) {
|
|
66
|
+
const trimmed = line.trim();
|
|
67
|
+
if (!trimmed.startsWith("{"))
|
|
68
|
+
return false;
|
|
69
|
+
try {
|
|
70
|
+
const event = JSON.parse(trimmed);
|
|
71
|
+
// The same events the output parsers report as provider errors.
|
|
72
|
+
return event.type === "turn.failed"
|
|
73
|
+
|| event.type === "error"
|
|
74
|
+
|| (event.type === "result" && (event.subtype !== "success" || event.is_error === true));
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export function isProviderTerminalSuccess(line) {
|
|
81
|
+
const trimmed = line.trim();
|
|
82
|
+
if (!trimmed.startsWith("{"))
|
|
83
|
+
return false;
|
|
84
|
+
try {
|
|
85
|
+
const event = JSON.parse(trimmed);
|
|
86
|
+
return event.type === "turn.completed"
|
|
87
|
+
|| (event.type === "result" && event.subtype === "success" && event.is_error !== true);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ChildProcess } from "node:child_process";
|
|
2
|
+
/**
|
|
3
|
+
* How long Forge keeps waiting, once the provider's root process has exited, for its output
|
|
4
|
+
* pipes to reach end-of-file. Node reports a child's "close" only after every copy of its
|
|
5
|
+
* stdout and stderr write ends is closed, and a descendant that escaped the provider's
|
|
6
|
+
* supervision can hold an inherited copy for as long as it runs: on Windows, a process that a
|
|
7
|
+
* Microsoft Store app-execution alias (`...\WindowsApps\pwsh.exe`) created outside the provider's
|
|
8
|
+
* Job Object; elsewhere, one that left the provider's process group. Output the root wrote
|
|
9
|
+
* before it exited drains within this grace. After it, Forge closes its read ends, so the run
|
|
10
|
+
* settles on the root's exit instead of on that descendant's.
|
|
11
|
+
*/
|
|
12
|
+
export declare const PROVIDER_OUTPUT_PIPE_RELEASE_GRACE_MS = 5000;
|
|
13
|
+
export interface OutputPipeReleaseFields {
|
|
14
|
+
/** Present when Forge closed the provider's output pipes because they outlived its root process. */
|
|
15
|
+
readonly outputPipesReleasedAfterExit?: true;
|
|
16
|
+
}
|
|
17
|
+
/** Closes a child's output pipes a bounded grace after the child exits, unless they close first. */
|
|
18
|
+
export declare class OutputPipeRelease {
|
|
19
|
+
private readonly child;
|
|
20
|
+
private readonly graceMs;
|
|
21
|
+
private readonly onRelease;
|
|
22
|
+
private timer;
|
|
23
|
+
private released;
|
|
24
|
+
constructor(child: ChildProcess, graceMs: number, onRelease: (message: string) => void);
|
|
25
|
+
resultFields(): OutputPipeReleaseFields;
|
|
26
|
+
stop(): void;
|
|
27
|
+
private arm;
|
|
28
|
+
private release;
|
|
29
|
+
}
|
|
30
|
+
export declare function readProcessLines(stream: NodeJS.ReadableStream, onLine: (line: string) => Promise<void> | void): Promise<void>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import readline from "node:readline";
|
|
2
|
+
/**
|
|
3
|
+
* How long Forge keeps waiting, once the provider's root process has exited, for its output
|
|
4
|
+
* pipes to reach end-of-file. Node reports a child's "close" only after every copy of its
|
|
5
|
+
* stdout and stderr write ends is closed, and a descendant that escaped the provider's
|
|
6
|
+
* supervision can hold an inherited copy for as long as it runs: on Windows, a process that a
|
|
7
|
+
* Microsoft Store app-execution alias (`...\WindowsApps\pwsh.exe`) created outside the provider's
|
|
8
|
+
* Job Object; elsewhere, one that left the provider's process group. Output the root wrote
|
|
9
|
+
* before it exited drains within this grace. After it, Forge closes its read ends, so the run
|
|
10
|
+
* settles on the root's exit instead of on that descendant's.
|
|
11
|
+
*/
|
|
12
|
+
export const PROVIDER_OUTPUT_PIPE_RELEASE_GRACE_MS = 5_000;
|
|
13
|
+
/** Closes a child's output pipes a bounded grace after the child exits, unless they close first. */
|
|
14
|
+
export class OutputPipeRelease {
|
|
15
|
+
child;
|
|
16
|
+
graceMs;
|
|
17
|
+
onRelease;
|
|
18
|
+
timer = null;
|
|
19
|
+
released = false;
|
|
20
|
+
constructor(child, graceMs, onRelease) {
|
|
21
|
+
this.child = child;
|
|
22
|
+
this.graceMs = graceMs;
|
|
23
|
+
this.onRelease = onRelease;
|
|
24
|
+
child.once("exit", () => this.arm());
|
|
25
|
+
child.once("close", () => this.stop());
|
|
26
|
+
}
|
|
27
|
+
resultFields() {
|
|
28
|
+
return this.released ? { outputPipesReleasedAfterExit: true } : {};
|
|
29
|
+
}
|
|
30
|
+
stop() {
|
|
31
|
+
if (!this.timer)
|
|
32
|
+
return;
|
|
33
|
+
clearTimeout(this.timer);
|
|
34
|
+
this.timer = null;
|
|
35
|
+
}
|
|
36
|
+
arm() {
|
|
37
|
+
if (this.timer || this.released)
|
|
38
|
+
return;
|
|
39
|
+
this.timer = setTimeout(() => this.release(), Math.max(0, this.graceMs));
|
|
40
|
+
}
|
|
41
|
+
release() {
|
|
42
|
+
this.timer = null;
|
|
43
|
+
// fd 0 is the child's input; Node's "close" waits only for the others.
|
|
44
|
+
const open = this.child.stdio.slice(1).filter(stream => stream && !stream.destroyed);
|
|
45
|
+
if (open.length === 0)
|
|
46
|
+
return;
|
|
47
|
+
this.released = true;
|
|
48
|
+
this.onRelease(`forge-bridge: the provider's output pipes were still open ${this.graceMs} ms after its process exited, `
|
|
49
|
+
+ "so a descendant outside its supervision still holds them. Forge closed them to settle the run.");
|
|
50
|
+
for (const stream of open)
|
|
51
|
+
stream?.destroy();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export async function readProcessLines(stream, onLine) {
|
|
55
|
+
const reader = readline.createInterface({ input: stream });
|
|
56
|
+
// readline finishes on "end" only. A stream OutputPipeRelease destroys closes without one;
|
|
57
|
+
// closing the reader then still delivers every line already read.
|
|
58
|
+
stream.once("close", () => reader.close());
|
|
59
|
+
try {
|
|
60
|
+
for await (const line of reader) {
|
|
61
|
+
await onLine(line);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
reader.close();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { RunnerDispatchEvent } from "../session.types.js";
|
|
2
2
|
import { type ProviderUsage } from "./provider-usage.js";
|
|
3
3
|
export declare function messageFromError(error: unknown): string;
|
|
4
|
+
/** Keeps the end of `value`, where a process's failure detail is, within `maximumLength`. */
|
|
5
|
+
export declare function clipTail(value: string, maximumLength: number): string;
|
|
4
6
|
export declare function clip(value: string, maxLength: number): string;
|
|
5
7
|
export interface ProviderOutputState {
|
|
6
8
|
readonly sessionLabel: string | null;
|
|
@@ -9,6 +11,12 @@ export interface ProviderOutputState {
|
|
|
9
11
|
finalMessage: string | null;
|
|
10
12
|
/** True only while the provider has reported a tool/command start without a matching completion. */
|
|
11
13
|
readonly hasActiveToolCall: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Forgets tool calls a previous provider generation started but never completed. A
|
|
16
|
+
* generation that exits mid-call reports no completion, and the next generation must not
|
|
17
|
+
* inherit that call as still in flight.
|
|
18
|
+
*/
|
|
19
|
+
resetActiveToolCalls(): void;
|
|
12
20
|
/** Accumulated provider-reported token usage for this run, or null when none was reported. */
|
|
13
21
|
readonly usage: ProviderUsage | null;
|
|
14
22
|
consume(line: string): readonly RunnerDispatchEvent[];
|
|
@@ -2,6 +2,12 @@ import { addUsage, emptyUsage, readUsageNumber } from "./provider-usage.js";
|
|
|
2
2
|
export function messageFromError(error) {
|
|
3
3
|
return error instanceof Error ? error.message : String(error);
|
|
4
4
|
}
|
|
5
|
+
/** Keeps the end of `value`, where a process's failure detail is, within `maximumLength`. */
|
|
6
|
+
export function clipTail(value, maximumLength) {
|
|
7
|
+
if (value.length <= maximumLength)
|
|
8
|
+
return value;
|
|
9
|
+
return `...${value.slice(-(maximumLength - 3))}`;
|
|
10
|
+
}
|
|
5
11
|
export function clip(value, maxLength) {
|
|
6
12
|
if (maxLength <= 0) {
|
|
7
13
|
return "";
|
|
@@ -43,6 +49,9 @@ class CursorStreamJsonState {
|
|
|
43
49
|
get hasActiveToolCall() {
|
|
44
50
|
return this.activeToolCallCount > 0;
|
|
45
51
|
}
|
|
52
|
+
resetActiveToolCalls() {
|
|
53
|
+
this.activeToolCallCount = 0;
|
|
54
|
+
}
|
|
46
55
|
consume(line) {
|
|
47
56
|
const event = parseJsonLine(line);
|
|
48
57
|
if (!event) {
|
|
@@ -264,6 +273,9 @@ class ClaudeStreamJsonState {
|
|
|
264
273
|
get hasActiveToolCall() {
|
|
265
274
|
return this.activeToolUses.size > 0;
|
|
266
275
|
}
|
|
276
|
+
resetActiveToolCalls() {
|
|
277
|
+
this.activeToolUses.clear();
|
|
278
|
+
}
|
|
267
279
|
consume(line) {
|
|
268
280
|
const event = parseJsonLine(line);
|
|
269
281
|
if (!event) {
|
|
@@ -544,6 +556,9 @@ class CodexJsonState {
|
|
|
544
556
|
get hasActiveToolCall() {
|
|
545
557
|
return this.activeToolCallCount > 0;
|
|
546
558
|
}
|
|
559
|
+
resetActiveToolCalls() {
|
|
560
|
+
this.activeToolCallCount = 0;
|
|
561
|
+
}
|
|
547
562
|
consume(line) {
|
|
548
563
|
const event = parseJsonLine(line);
|
|
549
564
|
if (!event) {
|
|
@@ -16,7 +16,16 @@ export interface PublishableWorktreeChangeSet {
|
|
|
16
16
|
* `.forge/` file that differs from HEAD is an author edit and must be published.
|
|
17
17
|
*/
|
|
18
18
|
export declare function isNonPublishableWorktreeChange(relativePath: string, status: string): boolean;
|
|
19
|
-
/**
|
|
19
|
+
/** `.local/`, `.forge/work-items/` and `.forge/stories/`: never published, even during a merge. */
|
|
20
|
+
export declare function isRuntimeOnlyPath(relativePath: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Stages every publishable worktree change in the real index and returns both sets.
|
|
23
|
+
*
|
|
24
|
+
* During an in-progress merge it first refuses unresolved conflicts, and afterwards
|
|
25
|
+
* restores merge-owned paths that the exclusion unstaged back to HEAD (the story side),
|
|
26
|
+
* such as `.forge/` files the target branch added (#491). Runtime-only paths are never
|
|
27
|
+
* restored.
|
|
28
|
+
*/
|
|
20
29
|
export declare function stagePublishableWorktreeChangeSet(git: Pick<GitClient, "run">, worktreePath: string): Promise<PublishableWorktreeChangeSet>;
|
|
21
30
|
/**
|
|
22
31
|
* Computes the same change set as {@link stagePublishableWorktreeChangeSet} without
|
|
@@ -3,6 +3,7 @@ import os from "node:os";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { GitClient } from "../shared/git/git.js";
|
|
5
5
|
import { NodeProcessRunner } from "../shared/process/process.js";
|
|
6
|
+
import { assertNoUnresolvedMergeConflicts, restoreMergeOwnedPaths } from "./provider-cli/provider-cli.merge-integrity.js";
|
|
6
7
|
/**
|
|
7
8
|
* Forge runtime output that is never published, whether or not the target repository
|
|
8
9
|
* tracks other `.forge/` content. Completion artifacts and evidence live here.
|
|
@@ -20,7 +21,7 @@ const resetBatchSize = 200;
|
|
|
20
21
|
*/
|
|
21
22
|
export function isNonPublishableWorktreeChange(relativePath, status) {
|
|
22
23
|
const normalized = relativePath.trim().replaceAll("\\", "/");
|
|
23
|
-
if (
|
|
24
|
+
if (isRuntimeOnlyPath(normalized)) {
|
|
24
25
|
return true;
|
|
25
26
|
}
|
|
26
27
|
if (normalized === ".forge" || normalized.startsWith(".forge/")) {
|
|
@@ -28,16 +29,31 @@ export function isNonPublishableWorktreeChange(relativePath, status) {
|
|
|
28
29
|
}
|
|
29
30
|
return false;
|
|
30
31
|
}
|
|
31
|
-
/**
|
|
32
|
+
/** `.local/`, `.forge/work-items/` and `.forge/stories/`: never published, even during a merge. */
|
|
33
|
+
export function isRuntimeOnlyPath(relativePath) {
|
|
34
|
+
const normalizedPath = normalizeChangedFilePath(relativePath);
|
|
35
|
+
return normalizedPath === ".local" || runtimeOnlyPathPrefixes.some(prefix => normalizedPath.startsWith(prefix));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Stages every publishable worktree change in the real index and returns both sets.
|
|
39
|
+
*
|
|
40
|
+
* During an in-progress merge it first refuses unresolved conflicts, and afterwards
|
|
41
|
+
* restores merge-owned paths that the exclusion unstaged back to HEAD (the story side),
|
|
42
|
+
* such as `.forge/` files the target branch added (#491). Runtime-only paths are never
|
|
43
|
+
* restored.
|
|
44
|
+
*/
|
|
32
45
|
export async function stagePublishableWorktreeChangeSet(git, worktreePath) {
|
|
46
|
+
await assertNoUnresolvedMergeConflicts(git, worktreePath);
|
|
33
47
|
await git.run(worktreePath, ["add", "-A"]);
|
|
34
|
-
const
|
|
48
|
+
const excludedChanges = (await readStagedChanges(git, worktreePath))
|
|
35
49
|
.filter(change => isNonPublishableWorktreeChange(change.path, change.status))
|
|
36
50
|
.map(change => change.path);
|
|
37
|
-
for (let index = 0; index <
|
|
38
|
-
const batch =
|
|
51
|
+
for (let index = 0; index < excludedChanges.length; index += resetBatchSize) {
|
|
52
|
+
const batch = excludedChanges.slice(index, index + resetBatchSize).map(filePath => `:(literal)${filePath}`);
|
|
39
53
|
await git.run(worktreePath, ["reset", "-q", "--", ...batch]);
|
|
40
54
|
}
|
|
55
|
+
const restored = new Set(await restoreMergeOwnedPaths(git, worktreePath, excludedChanges.filter(filePath => !isRuntimeOnlyPath(filePath))));
|
|
56
|
+
const excluded = excludedChanges.filter(filePath => !restored.has(filePath));
|
|
41
57
|
const publishable = (await git.run(worktreePath, ["diff", "--cached", "--name-only"]))
|
|
42
58
|
.split(/\r?\n/)
|
|
43
59
|
.map(line => line.trim())
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type HostLoadAcquireOptions, type HostLoadAdmission, type HostLoadStepGate, type HostLoadStepRequest } from "../runtime/host-load-governor.js";
|
|
2
|
+
export interface SandboxHostCapacityGateOptions {
|
|
3
|
+
readonly write?: (line: string) => void;
|
|
4
|
+
readonly responseRoot?: string;
|
|
5
|
+
readonly pollMs?: number;
|
|
6
|
+
/** Fails closed if the bridge never answers (the host enforces its own maximum wait first). */
|
|
7
|
+
readonly maxWaitMs?: number;
|
|
8
|
+
/** Owner of authentic replies (root in the container; tests use their own uid). */
|
|
9
|
+
readonly trustedOwnerUid?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class SandboxBrokeredHostLoadGate implements HostLoadStepGate {
|
|
12
|
+
readonly enabled = true;
|
|
13
|
+
private readonly write;
|
|
14
|
+
private readonly responseRoot;
|
|
15
|
+
private readonly pollMs;
|
|
16
|
+
private readonly trustedOwnerUid;
|
|
17
|
+
readonly maxWaitMs: number;
|
|
18
|
+
constructor(options?: SandboxHostCapacityGateOptions);
|
|
19
|
+
acquire(request: HostLoadStepRequest, options?: HostLoadAcquireOptions): Promise<HostLoadAdmission>;
|
|
20
|
+
private admission;
|
|
21
|
+
private send;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The brokered gate when the host bridge enabled it for this sandbox. The
|
|
25
|
+
* variable is removed once read, so commands the sandbox runs never inherit it
|
|
26
|
+
* (a nested Forge process must not queue behind its parent's token).
|
|
27
|
+
*/
|
|
28
|
+
export declare function sandboxHostLoadGateFromEnvironment(environment?: NodeJS.ProcessEnv): HostLoadStepGate | undefined;
|
|
29
|
+
/** Test support: forgets the cached gate. */
|
|
30
|
+
export declare function resetSandboxHostLoadGateForTesting(): void;
|