oh-my-copilot 5.29.0 → 5.29.2
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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +6 -0
- package/bridge/claude-md-coordinator.cjs +2 -2
- package/bridge/cli.cjs +38838 -38373
- package/bridge/mcp-server.cjs +53 -21
- package/bridge/runtime-cli.cjs +1414 -784
- package/bridge/team-mcp.cjs +154 -97
- package/bridge/team.js +946 -314
- package/copilot/agents/analyst.md +1 -1
- package/copilot/agents/architect.md +1 -1
- package/copilot/agents/code-reviewer.md +1 -1
- package/copilot/agents/code-simplifier.md +1 -1
- package/copilot/agents/critic.md +1 -1
- package/copilot/agents/debugger.md +1 -1
- package/copilot/agents/designer.md +1 -1
- package/copilot/agents/devils-advocate.md +1 -1
- package/copilot/agents/document-specialist.md +1 -1
- package/copilot/agents/executor.md +1 -1
- package/copilot/agents/explore.md +1 -1
- package/copilot/agents/git-master.md +1 -1
- package/copilot/agents/planner.md +1 -1
- package/copilot/agents/qa-tester.md +1 -1
- package/copilot/agents/scientist.md +1 -1
- package/copilot/agents/security-reviewer.md +1 -1
- package/copilot/agents/test-engineer.md +1 -1
- package/copilot/agents/tracer.md +1 -1
- package/copilot/agents/verifier.md +1 -1
- package/copilot/agents/writer.md +1 -1
- package/dist/__tests__/copilot-agents-manifest.test.js +7 -4
- package/dist/__tests__/copilot-agents-manifest.test.js.map +1 -1
- package/dist/__tests__/setup/stub-copilot-catalogue.d.ts +2 -0
- package/dist/__tests__/setup/stub-copilot-catalogue.d.ts.map +1 -0
- package/dist/__tests__/setup/stub-copilot-catalogue.js +12 -0
- package/dist/__tests__/setup/stub-copilot-catalogue.js.map +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +7 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/config/copilot-models.json +18 -5
- package/dist/copilot-run/__tests__/model-catalogue.test.d.ts +2 -0
- package/dist/copilot-run/__tests__/model-catalogue.test.d.ts.map +1 -0
- package/dist/copilot-run/__tests__/model-catalogue.test.js +277 -0
- package/dist/copilot-run/__tests__/model-catalogue.test.js.map +1 -0
- package/dist/copilot-run/job.d.ts.map +1 -1
- package/dist/copilot-run/job.js +2 -2
- package/dist/copilot-run/job.js.map +1 -1
- package/dist/copilot-run/model-catalogue.d.ts +119 -0
- package/dist/copilot-run/model-catalogue.d.ts.map +1 -0
- package/dist/copilot-run/model-catalogue.js +318 -0
- package/dist/copilot-run/model-catalogue.js.map +1 -0
- package/dist/factory/bench/model-probe.js +4 -4
- package/dist/factory/bench/model-probe.js.map +1 -1
- package/dist/factory/run/sandbox-exec.js +4 -4
- package/dist/factory/run/sandbox-exec.js.map +1 -1
- package/dist/graph/__tests__/runtime/executors/agent.test.js +1 -1
- package/dist/graph/__tests__/runtime/executors/agent.test.js.map +1 -1
- package/dist/graph/runtime/executors/agent.d.ts +1 -1
- package/dist/graph/runtime/executors/agent.js +3 -3
- package/dist/graph/runtime/executors/agent.js.map +1 -1
- package/dist/installer/__tests__/copilot-agent-models.test.js +79 -9
- package/dist/installer/__tests__/copilot-agent-models.test.js.map +1 -1
- package/dist/installer/__tests__/setup-copilot-catalogue.test.d.ts +2 -0
- package/dist/installer/__tests__/setup-copilot-catalogue.test.d.ts.map +1 -0
- package/dist/installer/__tests__/setup-copilot-catalogue.test.js +33 -0
- package/dist/installer/__tests__/setup-copilot-catalogue.test.js.map +1 -0
- package/dist/installer/copilot-agent-models.d.ts +23 -5
- package/dist/installer/copilot-agent-models.d.ts.map +1 -1
- package/dist/installer/copilot-agent-models.js +67 -13
- package/dist/installer/copilot-agent-models.js.map +1 -1
- package/dist/installer/index.d.ts +13 -0
- package/dist/installer/index.d.ts.map +1 -1
- package/dist/installer/index.js +32 -4
- package/dist/installer/index.js.map +1 -1
- package/dist/platform/process-utils.d.ts.map +1 -1
- package/dist/platform/process-utils.js +3 -1
- package/dist/platform/process-utils.js.map +1 -1
- package/dist/smoke/__tests__/copilot-sdk-driver.test.js +112 -1
- package/dist/smoke/__tests__/copilot-sdk-driver.test.js.map +1 -1
- package/dist/smoke/copilot-sandbox-lane-scenario.d.ts +1 -1
- package/dist/smoke/copilot-sandbox-lane-scenario.d.ts.map +1 -1
- package/dist/smoke/copilot-sandbox-lane-scenario.js +4 -3
- package/dist/smoke/copilot-sandbox-lane-scenario.js.map +1 -1
- package/dist/smoke/copilot-sdk-driver.d.ts +40 -1
- package/dist/smoke/copilot-sdk-driver.d.ts.map +1 -1
- package/dist/smoke/copilot-sdk-driver.js +126 -8
- package/dist/smoke/copilot-sdk-driver.js.map +1 -1
- package/dist/smoke/copilot-sdk-scenarios.d.ts +2 -0
- package/dist/smoke/copilot-sdk-scenarios.d.ts.map +1 -1
- package/dist/smoke/copilot-sdk-scenarios.js +3 -1
- package/dist/smoke/copilot-sdk-scenarios.js.map +1 -1
- package/dist/team/__tests__/copilot-model-resolution.test.d.ts +2 -0
- package/dist/team/__tests__/copilot-model-resolution.test.d.ts.map +1 -0
- package/dist/team/__tests__/copilot-model-resolution.test.js +93 -0
- package/dist/team/__tests__/copilot-model-resolution.test.js.map +1 -0
- package/dist/team/__tests__/model-contract.test.js +3 -3
- package/dist/team/__tests__/model-contract.test.js.map +1 -1
- package/dist/team/__tests__/runtime-v2.sdk-defaults.test.js +11 -1
- package/dist/team/__tests__/runtime-v2.sdk-defaults.test.js.map +1 -1
- package/dist/team/__tests__/scaling-launch-config.test.js +1 -0
- package/dist/team/__tests__/scaling-launch-config.test.js.map +1 -1
- package/dist/team/__tests__/sdk-transport.runtime.test.js +27 -1
- package/dist/team/__tests__/sdk-transport.runtime.test.js.map +1 -1
- package/dist/team/model-contract.d.ts +40 -2
- package/dist/team/model-contract.d.ts.map +1 -1
- package/dist/team/model-contract.js +51 -9
- package/dist/team/model-contract.js.map +1 -1
- package/dist/team/runtime-v2.d.ts +28 -5
- package/dist/team/runtime-v2.d.ts.map +1 -1
- package/dist/team/runtime-v2.js +67 -10
- package/dist/team/runtime-v2.js.map +1 -1
- package/dist/team/scaling.d.ts.map +1 -1
- package/dist/team/scaling.js +8 -1
- package/dist/team/scaling.js.map +1 -1
- package/dist/team/sdk-host.d.ts.map +1 -1
- package/dist/team/sdk-host.js +2 -2
- package/dist/team/sdk-host.js.map +1 -1
- package/docs/CLAUDE.md +1 -1
- package/docs/DEVELOPERS.md +1 -1
- package/docs/FIELD-TESTING.md +1 -1
- package/docs/MIGRATION.md +26 -1
- package/docs/REFERENCE.md +25 -4
- package/docs/TOOLS.md +1 -1
- package/package.json +3 -15
- package/plugin.json +1 -1
- package/scripts/build-cli.mjs +1 -1
- package/skills/statechart/scripts/statechart +21 -10
- package/skills/statechart/scripts/test/cli.test.ts +3 -3
package/bridge/runtime-cli.cjs
CHANGED
|
@@ -42,6 +42,14 @@ function hardenWindowsExeSearch() {
|
|
|
42
42
|
}
|
|
43
43
|
process.env[VARIABLE] = "1";
|
|
44
44
|
}
|
|
45
|
+
function childEnv(env) {
|
|
46
|
+
const out = {};
|
|
47
|
+
for (const [key, value] of Object.entries(env)) {
|
|
48
|
+
if (process.platform !== "win32" || !isVariable(key)) out[key] = value;
|
|
49
|
+
}
|
|
50
|
+
if (process.platform === "win32") out[VARIABLE] = "1";
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
45
53
|
function envValue(env, name) {
|
|
46
54
|
const key = Object.keys(env).find((k) => k.toUpperCase() === name);
|
|
47
55
|
const value = key === void 0 ? void 0 : env[key];
|
|
@@ -889,8 +897,8 @@ function getProjectIdentifier(worktreeRoot) {
|
|
|
889
897
|
} catch (error) {
|
|
890
898
|
if (!isDefinitiveGitExit(error)) cacheable = false;
|
|
891
899
|
}
|
|
892
|
-
const
|
|
893
|
-
const hash = (0, import_crypto.createHash)("sha256").update(
|
|
900
|
+
const source2 = remoteUrl || primaryRoot;
|
|
901
|
+
const hash = (0, import_crypto.createHash)("sha256").update(source2).digest("hex").slice(0, 16);
|
|
894
902
|
const dirName = (0, import_path2.basename)(primaryRoot).replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
895
903
|
const identifier = `${dirName}-${hash}`;
|
|
896
904
|
if (cacheable) {
|
|
@@ -2485,13 +2493,13 @@ function loadJsoncFile(path5) {
|
|
|
2485
2493
|
return null;
|
|
2486
2494
|
}
|
|
2487
2495
|
}
|
|
2488
|
-
function deepMerge(target,
|
|
2496
|
+
function deepMerge(target, source2) {
|
|
2489
2497
|
const result = { ...target };
|
|
2490
2498
|
const mutableResult = result;
|
|
2491
|
-
for (const key of Object.keys(
|
|
2499
|
+
for (const key of Object.keys(source2)) {
|
|
2492
2500
|
if (key === "__proto__" || key === "constructor" || key === "prototype")
|
|
2493
2501
|
continue;
|
|
2494
|
-
const sourceValue =
|
|
2502
|
+
const sourceValue = source2[key];
|
|
2495
2503
|
const targetValue = mutableResult[key];
|
|
2496
2504
|
if (sourceValue !== void 0 && typeof sourceValue === "object" && sourceValue !== null && !Array.isArray(sourceValue) && typeof targetValue === "object" && targetValue !== null && !Array.isArray(targetValue)) {
|
|
2497
2505
|
mutableResult[key] = deepMerge(
|
|
@@ -2794,10 +2802,10 @@ function isAutopilotWorkflowSequence(stages) {
|
|
|
2794
2802
|
(sequence) => stages.length === sequence.length && stages.every((stage, index) => typeof stage === "string" && stage === sequence[index])
|
|
2795
2803
|
);
|
|
2796
2804
|
}
|
|
2797
|
-
function workflowError(
|
|
2798
|
-
throw new Error(`[OMC] ${
|
|
2805
|
+
function workflowError(source2, path5, message) {
|
|
2806
|
+
throw new Error(`[OMC] ${source2} ${path5}: ${message}`);
|
|
2799
2807
|
}
|
|
2800
|
-
function validateAutopilotWorkflows(config,
|
|
2808
|
+
function validateAutopilotWorkflows(config, source2) {
|
|
2801
2809
|
if (!config || typeof config !== "object" || Array.isArray(config)) return;
|
|
2802
2810
|
const autopilot = config.autopilot;
|
|
2803
2811
|
if (autopilot === void 0) return;
|
|
@@ -2805,34 +2813,34 @@ function validateAutopilotWorkflows(config, source) {
|
|
|
2805
2813
|
const workflows = autopilot.workflows;
|
|
2806
2814
|
if (workflows === void 0) return;
|
|
2807
2815
|
if (!workflows || typeof workflows !== "object" || Array.isArray(workflows)) {
|
|
2808
|
-
workflowError(
|
|
2816
|
+
workflowError(source2, "autopilot.workflows", "must be an object map");
|
|
2809
2817
|
}
|
|
2810
2818
|
for (const [name, profile] of Object.entries(workflows)) {
|
|
2811
2819
|
const path5 = `autopilot.workflows.${name}`;
|
|
2812
2820
|
if (!AUTOPILOT_WORKFLOW_NAME.test(name)) {
|
|
2813
|
-
workflowError(
|
|
2821
|
+
workflowError(source2, path5, "name must match ^[a-z][a-z0-9-]{0,62}$");
|
|
2814
2822
|
}
|
|
2815
2823
|
if (AUTOPILOT_WORKFLOW_RESERVED_NAMES.has(name)) {
|
|
2816
|
-
workflowError(
|
|
2824
|
+
workflowError(source2, path5, `name "${name}" is reserved`);
|
|
2817
2825
|
}
|
|
2818
2826
|
if (!profile || typeof profile !== "object" || Array.isArray(profile)) {
|
|
2819
|
-
workflowError(
|
|
2827
|
+
workflowError(source2, path5, "must be an object");
|
|
2820
2828
|
}
|
|
2821
2829
|
const profileRecord = profile;
|
|
2822
2830
|
for (const key of Object.keys(profileRecord)) {
|
|
2823
2831
|
if (key !== "version" && key !== "stages") {
|
|
2824
|
-
workflowError(
|
|
2832
|
+
workflowError(source2, `${path5}.${key}`, "unknown profile key");
|
|
2825
2833
|
}
|
|
2826
2834
|
}
|
|
2827
2835
|
if (profileRecord.version !== 1) {
|
|
2828
|
-
workflowError(
|
|
2836
|
+
workflowError(source2, `${path5}.version`, "must be the number 1");
|
|
2829
2837
|
}
|
|
2830
2838
|
if (!Array.isArray(profileRecord.stages)) {
|
|
2831
|
-
workflowError(
|
|
2839
|
+
workflowError(source2, `${path5}.stages`, "must be an array");
|
|
2832
2840
|
}
|
|
2833
2841
|
if (!isAutopilotWorkflowSequence(profileRecord.stages)) {
|
|
2834
2842
|
workflowError(
|
|
2835
|
-
|
|
2843
|
+
source2,
|
|
2836
2844
|
`${path5}.stages`,
|
|
2837
2845
|
"must be one of: [ralplan, execution], [ralplan, execution, ralph], [ralplan, execution, qa], [ralplan, execution, ralph, qa]"
|
|
2838
2846
|
);
|
|
@@ -3415,7 +3423,7 @@ async function withProcessIdentityFileLock(lockPath, fn, timeoutMs = 1e4) {
|
|
|
3415
3423
|
continue;
|
|
3416
3424
|
}
|
|
3417
3425
|
if (Date.now() >= deadline) throw new Error("process_identity_lock_timeout");
|
|
3418
|
-
await new Promise((
|
|
3426
|
+
await new Promise((resolve22) => setTimeout(resolve22, 25));
|
|
3419
3427
|
continue;
|
|
3420
3428
|
}
|
|
3421
3429
|
try {
|
|
@@ -3436,7 +3444,7 @@ async function withProcessIdentityFileLock(lockPath, fn, timeoutMs = 1e4) {
|
|
|
3436
3444
|
}
|
|
3437
3445
|
}
|
|
3438
3446
|
if (Date.now() >= deadline) throw new Error("process_identity_lock_timeout");
|
|
3439
|
-
await new Promise((
|
|
3447
|
+
await new Promise((resolve22) => setTimeout(resolve22, 25));
|
|
3440
3448
|
}
|
|
3441
3449
|
}
|
|
3442
3450
|
return await fn();
|
|
@@ -6672,17 +6680,30 @@ var init_copilot_models = __esm({
|
|
|
6672
6680
|
"claude-opus-5.5",
|
|
6673
6681
|
"claude-haiku-5.5",
|
|
6674
6682
|
"claude-haiku-4.5",
|
|
6683
|
+
"claude-sonnet-5",
|
|
6684
|
+
"claude-fable-5.2",
|
|
6675
6685
|
"gpt-6.1-sol",
|
|
6686
|
+
"gpt-6.2-astra",
|
|
6687
|
+
"gpt-6.1-terra",
|
|
6676
6688
|
"gpt-6-astra",
|
|
6677
6689
|
"gpt-6-luna",
|
|
6690
|
+
"gpt-5.6-luna",
|
|
6678
6691
|
"gpt-5.3-codex",
|
|
6679
|
-
"gemini-3.8-flash"
|
|
6692
|
+
"gemini-3.8-flash",
|
|
6693
|
+
"gemini-4-hydrogen",
|
|
6694
|
+
"mai-code-2",
|
|
6695
|
+
"mai-code-2-flash",
|
|
6696
|
+
"mai-code-1.1-flash",
|
|
6697
|
+
"grok-4.7",
|
|
6698
|
+
"grok-4.6",
|
|
6699
|
+
"kimi-k3"
|
|
6680
6700
|
],
|
|
6701
|
+
unconfirmedModels: ["claude-fable-5.2", "gpt-6.2-astra"],
|
|
6681
6702
|
tiers: {
|
|
6682
|
-
opus: ["claude-opus-5.5", "gpt-6.1-sol", "claude-sonnet-5.5"],
|
|
6683
|
-
sonnet: ["claude-sonnet-5.5", "
|
|
6684
|
-
haiku: ["
|
|
6685
|
-
fable: ["claude-
|
|
6703
|
+
opus: ["claude-opus-5.5", "gpt-6.1-sol", "claude-sonnet-5.5", "mai-code-2"],
|
|
6704
|
+
sonnet: ["mai-code-2", "claude-sonnet-5.5", "mai-code-2-flash"],
|
|
6705
|
+
haiku: ["mai-code-2-flash", "claude-haiku-5.5", "gpt-6-luna"],
|
|
6706
|
+
fable: ["claude-fable-5.2", "gpt-6.2-astra"]
|
|
6686
6707
|
}
|
|
6687
6708
|
};
|
|
6688
6709
|
}
|
|
@@ -6784,12 +6805,31 @@ function clearResolvedPathCache() {
|
|
|
6784
6805
|
function shouldUseClaudeBareMode(env = process.env) {
|
|
6785
6806
|
return typeof env.ANTHROPIC_API_KEY === "string" && env.ANTHROPIC_API_KEY.trim().length > 0;
|
|
6786
6807
|
}
|
|
6808
|
+
function resolveCopilotModel(model, catalogue) {
|
|
6809
|
+
const tier = model.toLowerCase();
|
|
6810
|
+
if (!Object.hasOwn(COPILOT_TIER_MODELS, tier)) return { model: toCopilotModelId(model), status: "passthrough" };
|
|
6811
|
+
const ids = COPILOT_TIER_MODELS[tier];
|
|
6812
|
+
if (!catalogue) {
|
|
6813
|
+
const confirmed = ids.find((id) => !COPILOT_UNCONFIRMED_MODELS.has(id));
|
|
6814
|
+
return confirmed ? { model: confirmed, tier, status: "unverified" } : { model: void 0, tier, status: "unavailable" };
|
|
6815
|
+
}
|
|
6816
|
+
const hit = ids.find((id) => catalogue.has(id));
|
|
6817
|
+
return hit ? { model: hit, tier, status: "available" } : { model: void 0, tier, status: "unavailable" };
|
|
6818
|
+
}
|
|
6819
|
+
function copilotTierModels(tier) {
|
|
6820
|
+
return COPILOT_TIER_MODELS[tier.toLowerCase()] ?? [];
|
|
6821
|
+
}
|
|
6787
6822
|
function toCopilotModelId(model) {
|
|
6788
6823
|
const key = model.toLowerCase();
|
|
6789
|
-
if (Object.hasOwn(
|
|
6824
|
+
if (Object.hasOwn(COPILOT_TIER_MODELS, key)) return COPILOT_TIER_MODELS[key][0];
|
|
6790
6825
|
if (!/^claude-/.test(model)) return model;
|
|
6791
6826
|
return model.replace(/\[1m\]$/i, "").replace(/-\d{8}$/, "").replace(/^(claude-[a-z]+)-(\d+)-(\d+)(?=$|-[a-z])/, "$1-$2.$3");
|
|
6792
6827
|
}
|
|
6828
|
+
function warnUnavailableCopilotTier(tier, warn = (line) => console.warn(line)) {
|
|
6829
|
+
if (warnedUnavailableTiers.has(tier)) return;
|
|
6830
|
+
warnedUnavailableTiers.add(tier);
|
|
6831
|
+
warn(`[omg] your Copilot plan offers no confirmed model of tier "${tier}" (${copilotTierModels(tier).join(", ")}); passing no model, the session default applies`);
|
|
6832
|
+
}
|
|
6793
6833
|
function resolveWorkerPermissionFlags(agentType, perms) {
|
|
6794
6834
|
if (agentType !== "copilot" || !perms) return [];
|
|
6795
6835
|
return [
|
|
@@ -6825,7 +6865,7 @@ function resolveValidatedBinaryPath(agentType) {
|
|
|
6825
6865
|
return resolveCliBinaryPath(contract.binary);
|
|
6826
6866
|
}
|
|
6827
6867
|
function buildLaunchArgs(agentType, config) {
|
|
6828
|
-
return getContract(agentType).buildLaunchArgs(config.model, config.reasoningEffort, config.extraFlags);
|
|
6868
|
+
return getContract(agentType).buildLaunchArgs(config.model, config.reasoningEffort, config.extraFlags, config.copilotCatalogue);
|
|
6829
6869
|
}
|
|
6830
6870
|
function buildWorkerArgv(agentType, config) {
|
|
6831
6871
|
validateTeamName2(config.teamName);
|
|
@@ -6988,7 +7028,7 @@ function getPromptModeArgs(agentType, instruction) {
|
|
|
6988
7028
|
}
|
|
6989
7029
|
return [instruction];
|
|
6990
7030
|
}
|
|
6991
|
-
var import_path21, import_os5, resolvedPathCache, UNTRUSTED_PATH_PATTERNS, UNTRUSTED_WINDOWS_PATH_PATTERNS, COPILOT_WORKER_BASE_FLAGS,
|
|
7031
|
+
var import_path21, import_os5, resolvedPathCache, UNTRUSTED_PATH_PATTERNS, UNTRUSTED_WINDOWS_PATH_PATTERNS, COPILOT_WORKER_BASE_FLAGS, COPILOT_TIER_MODELS, COPILOT_UNCONFIRMED_MODELS, warnedUnavailableTiers, CONTRACTS, WORKER_MODEL_ENV_ALLOWLIST, CLAUDE_WORKER_ENV_ALLOWLIST;
|
|
6992
7032
|
var init_model_contract = __esm({
|
|
6993
7033
|
"src/team/model-contract.ts"() {
|
|
6994
7034
|
"use strict";
|
|
@@ -7013,9 +7053,9 @@ var init_model_contract = __esm({
|
|
|
7013
7053
|
/[\\/]Downloads[\\/]/i
|
|
7014
7054
|
];
|
|
7015
7055
|
COPILOT_WORKER_BASE_FLAGS = ["--allow-all-tools", "--allow-all-paths", "--allow-all-urls", "--no-ask-user"];
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
);
|
|
7056
|
+
COPILOT_TIER_MODELS = copilot_models_default.tiers;
|
|
7057
|
+
COPILOT_UNCONFIRMED_MODELS = new Set(copilot_models_default.unconfirmedModels);
|
|
7058
|
+
warnedUnavailableTiers = /* @__PURE__ */ new Set();
|
|
7019
7059
|
CONTRACTS = {
|
|
7020
7060
|
claude: {
|
|
7021
7061
|
agentType: "claude",
|
|
@@ -7048,9 +7088,13 @@ var init_model_contract = __esm({
|
|
|
7048
7088
|
// explicit allow set instead, and permissions.workerDenyTools/Urls arrive via
|
|
7049
7089
|
// extraFlags (deny rules win over allow rules in Copilot). Copilot has no verified
|
|
7050
7090
|
// reasoning-effort flag, so per-role reasoningEffort (upstream #4206) is not forwarded.
|
|
7051
|
-
buildLaunchArgs(model, _reasoningEffort, extraFlags = []) {
|
|
7091
|
+
buildLaunchArgs(model, _reasoningEffort, extraFlags = [], copilotCatalogue) {
|
|
7052
7092
|
const args = [...COPILOT_WORKER_BASE_FLAGS];
|
|
7053
|
-
if (model)
|
|
7093
|
+
if (model) {
|
|
7094
|
+
const resolved = resolveCopilotModel(model, copilotCatalogue);
|
|
7095
|
+
if (resolved.model) args.push("--model", resolved.model);
|
|
7096
|
+
else if (resolved.tier) warnUnavailableCopilotTier(resolved.tier);
|
|
7097
|
+
}
|
|
7054
7098
|
return [...args, ...extraFlags];
|
|
7055
7099
|
},
|
|
7056
7100
|
parseOutput(rawOutput) {
|
|
@@ -8265,7 +8309,7 @@ var init_process_utils = __esm({
|
|
|
8265
8309
|
import_path24 = require("path");
|
|
8266
8310
|
import_util2 = require("util");
|
|
8267
8311
|
fsPromises = __toESM(require("fs/promises"), 1);
|
|
8268
|
-
execFileAsync2 = (0, import_util2.promisify)(import_child_process6.execFile);
|
|
8312
|
+
execFileAsync2 = ((...args) => (0, import_util2.promisify)(import_child_process6.execFile)(...args));
|
|
8269
8313
|
}
|
|
8270
8314
|
});
|
|
8271
8315
|
|
|
@@ -8302,7 +8346,7 @@ async function renameWithRetry(tempPath, filePath, maxAttempts = 10, delayMs = 3
|
|
|
8302
8346
|
}
|
|
8303
8347
|
lastError = error;
|
|
8304
8348
|
if (attempt < maxAttempts - 1) {
|
|
8305
|
-
await new Promise((
|
|
8349
|
+
await new Promise((resolve22) => setTimeout(resolve22, delayMs));
|
|
8306
8350
|
}
|
|
8307
8351
|
}
|
|
8308
8352
|
}
|
|
@@ -8504,10 +8548,10 @@ async function atomicWriteJson(filePath, data, hooks) {
|
|
|
8504
8548
|
}
|
|
8505
8549
|
}
|
|
8506
8550
|
}
|
|
8507
|
-
function renameSyncRetryingWin32Sharing(rename8,
|
|
8551
|
+
function renameSyncRetryingWin32Sharing(rename8, source2, destination) {
|
|
8508
8552
|
for (let attempt = 0; ; attempt++) {
|
|
8509
8553
|
try {
|
|
8510
|
-
rename8(
|
|
8554
|
+
rename8(source2, destination);
|
|
8511
8555
|
return;
|
|
8512
8556
|
} catch (error) {
|
|
8513
8557
|
const code = error.code;
|
|
@@ -8588,6 +8632,10 @@ function atomicWriteFileSync(filePath, content, hooks, operations) {
|
|
|
8588
8632
|
}
|
|
8589
8633
|
}
|
|
8590
8634
|
}
|
|
8635
|
+
function atomicWriteJsonSync(filePath, data, hooks, operations) {
|
|
8636
|
+
const jsonContent = JSON.stringify(data, null, 2);
|
|
8637
|
+
atomicWriteFileSync(filePath, jsonContent, hooks, operations);
|
|
8638
|
+
}
|
|
8591
8639
|
var fs, fsSync, path2, crypto, RENAME_RETRY_WAIT, ATOMIC_BATCH_MAX_CONTENT_BYTES;
|
|
8592
8640
|
var init_atomic_write = __esm({
|
|
8593
8641
|
"src/lib/atomic-write.ts"() {
|
|
@@ -8767,7 +8815,7 @@ function withFileLockSync(lockPath, fn, opts) {
|
|
|
8767
8815
|
}
|
|
8768
8816
|
}
|
|
8769
8817
|
function sleep(ms) {
|
|
8770
|
-
return new Promise((
|
|
8818
|
+
return new Promise((resolve22) => setTimeout(resolve22, ms));
|
|
8771
8819
|
}
|
|
8772
8820
|
async function acquireFileLock(lockPath, opts) {
|
|
8773
8821
|
const staleLockMs = opts?.staleLockMs ?? DEFAULT_STALE_LOCK_MS;
|
|
@@ -8968,9 +9016,11 @@ var init_host_load_gate = __esm({
|
|
|
8968
9016
|
});
|
|
8969
9017
|
|
|
8970
9018
|
// src/copilot-run/names.ts
|
|
9019
|
+
var COPILOT_RUN_ALLOW_ENV;
|
|
8971
9020
|
var init_names = __esm({
|
|
8972
9021
|
"src/copilot-run/names.ts"() {
|
|
8973
9022
|
"use strict";
|
|
9023
|
+
COPILOT_RUN_ALLOW_ENV = "OMG_COPILOT_RUN_ALLOW";
|
|
8974
9024
|
}
|
|
8975
9025
|
});
|
|
8976
9026
|
|
|
@@ -9063,7 +9113,7 @@ function canon(p, platform = process.platform) {
|
|
|
9063
9113
|
const out = (0, import_path28.resolve)(p).split(import_path28.sep).join("/");
|
|
9064
9114
|
return platform === "win32" ? out.toLowerCase() : out;
|
|
9065
9115
|
}
|
|
9066
|
-
var import_fs26, import_path28, FACTORY_RUN_SCENARIOS, SANDBOX_LANE_SCENARIO, CLI_SCENARIOS, ALL_SCENARIOS, OPT_IN_SCENARIOS, KNOWN_SCENARIOS, PLUGIN_NAME, DELEGATE_AGENT, SDK_PACKAGE, SDK_MISSING_DETAIL, NO_SHELL_OR_WRITE_TOOLS, NO_WRITE_TOOLS, denyAll, GUARDRAIL_COMMAND, FILETOOLS_DIR, FILETOOLS_FILES, FILETOOLS_MARKER, PROMPT_CONTEXT_PREFIX, EVENTS_MISSING_FILE, EVENTS_SHELL_TOKEN, FACTORY_RUN_FILE, FACTORY_RUN_ISSUE_BODY, SCENARIOS, NO_CASSETTE_SCENARIOS;
|
|
9116
|
+
var import_fs26, import_path28, FACTORY_RUN_SCENARIOS, SANDBOX_LANE_SCENARIO, CLI_SCENARIOS, ALL_SCENARIOS, OPT_IN_SCENARIOS, KNOWN_SCENARIOS, PLUGIN_NAME, DELEGATE_AGENT, SDK_PACKAGE, SDK_INSTALL_COMMAND, SDK_MISSING_DETAIL, NO_SHELL_OR_WRITE_TOOLS, NO_WRITE_TOOLS, denyAll, GUARDRAIL_COMMAND, FILETOOLS_DIR, FILETOOLS_FILES, FILETOOLS_MARKER, PROMPT_CONTEXT_PREFIX, EVENTS_MISSING_FILE, EVENTS_SHELL_TOKEN, FACTORY_RUN_FILE, FACTORY_RUN_ISSUE_BODY, SCENARIOS, RUNTIME_MIN_MAX_CREDITS, NO_CASSETTE_SCENARIOS;
|
|
9067
9117
|
var init_copilot_sdk_scenarios = __esm({
|
|
9068
9118
|
"src/smoke/copilot-sdk-scenarios.ts"() {
|
|
9069
9119
|
"use strict";
|
|
@@ -9081,7 +9131,8 @@ var init_copilot_sdk_scenarios = __esm({
|
|
|
9081
9131
|
PLUGIN_NAME = "oh-my-copilot";
|
|
9082
9132
|
DELEGATE_AGENT = "oh-my-copilot:architect";
|
|
9083
9133
|
SDK_PACKAGE = "@github/copilot-sdk";
|
|
9084
|
-
|
|
9134
|
+
SDK_INSTALL_COMMAND = `npm i -g ${SDK_PACKAGE} --omit=optional --ignore-scripts`;
|
|
9135
|
+
SDK_MISSING_DETAIL = `${SDK_PACKAGE} not installed \u2014 ${SDK_INSTALL_COMMAND}`;
|
|
9085
9136
|
NO_SHELL_OR_WRITE_TOOLS = ["powershell", "shell", "create", "edit"];
|
|
9086
9137
|
NO_WRITE_TOOLS = ["create", "edit"];
|
|
9087
9138
|
denyAll = () => false;
|
|
@@ -9227,6 +9278,7 @@ var init_copilot_sdk_scenarios = __esm({
|
|
|
9227
9278
|
permit: denyAll
|
|
9228
9279
|
}
|
|
9229
9280
|
};
|
|
9281
|
+
RUNTIME_MIN_MAX_CREDITS = 30;
|
|
9230
9282
|
NO_CASSETTE_SCENARIOS = ["chain", ...CLI_SCENARIOS];
|
|
9231
9283
|
}
|
|
9232
9284
|
});
|
|
@@ -9236,6 +9288,10 @@ function isCredentialEnvKey(key) {
|
|
|
9236
9288
|
const upper = key.toUpperCase();
|
|
9237
9289
|
return CREDENTIAL_ENV.includes(upper) || SECRET_NAME.test(upper) || upper.startsWith("GIT_CONFIG") || upper.startsWith("GCM_");
|
|
9238
9290
|
}
|
|
9291
|
+
function isStrippedEnvKey(key) {
|
|
9292
|
+
const upper = process.platform === "win32" ? key.toUpperCase() : key;
|
|
9293
|
+
return STRIPPED_ENV_EXACT.includes(upper) || STRIPPED_ENV_PREFIXES.some((p) => upper.startsWith(p));
|
|
9294
|
+
}
|
|
9239
9295
|
function resolveDefaultPluginRoot(env = process.env) {
|
|
9240
9296
|
const fromEnv = env[OMC_PLUGIN_ROOT_ENV]?.trim();
|
|
9241
9297
|
if (fromEnv) return (0, import_path29.resolve)(fromEnv);
|
|
@@ -9283,7 +9339,32 @@ function cassetteRuntimeEnv(env, mode) {
|
|
|
9283
9339
|
out.COPILOT_CLI_DISABLE_WEBSOCKET_RESPONSES = "1";
|
|
9284
9340
|
return out;
|
|
9285
9341
|
}
|
|
9286
|
-
|
|
9342
|
+
function buildSessionEnv(base, home, opts = {}) {
|
|
9343
|
+
const env = {};
|
|
9344
|
+
const replay = isReplayEnv(base);
|
|
9345
|
+
for (const [key, value] of Object.entries(base)) {
|
|
9346
|
+
if (isStrippedEnvKey(key)) continue;
|
|
9347
|
+
if (replay && (isCredentialEnvKey(key) || key.toUpperCase() === HMAC_KEY_ENV)) continue;
|
|
9348
|
+
if (opts.hasLogin && LOGIN_SHADOWING_TOKENS.includes(key.toUpperCase())) continue;
|
|
9349
|
+
env[key] = value;
|
|
9350
|
+
}
|
|
9351
|
+
env.COPILOT_HOME = home;
|
|
9352
|
+
Object.assign(env, SMOKE_SET_ENV);
|
|
9353
|
+
if (opts.session) Object.assign(env, SESSION_SET_ENV);
|
|
9354
|
+
return env;
|
|
9355
|
+
}
|
|
9356
|
+
function loginIdentity(userConfigDir) {
|
|
9357
|
+
try {
|
|
9358
|
+
const parsed = parseJsonc((0, import_fs27.readFileSync)((0, import_path29.join)(userConfigDir, "config.json"), "utf-8"));
|
|
9359
|
+
if (!parsed || typeof parsed !== "object") return {};
|
|
9360
|
+
const out = {};
|
|
9361
|
+
for (const key of ["loggedInUsers", "lastLoggedInUser"]) if (parsed[key] !== void 0) out[key] = parsed[key];
|
|
9362
|
+
return out;
|
|
9363
|
+
} catch {
|
|
9364
|
+
return {};
|
|
9365
|
+
}
|
|
9366
|
+
}
|
|
9367
|
+
var import_fs27, import_path29, import_url4, STRIPPED_ENV_EXACT, STRIPPED_ENV_PREFIXES, LOGIN_SHADOWING_TOKENS, SMOKE_SET_ENV, SESSION_SET_ENV, CREDENTIAL_ENV, SECRET_NAME, CASSETTE_ENV, HMAC_KEY_ENV, REPLAY_HMAC_KEY;
|
|
9287
9368
|
var init_copilot_session_env = __esm({
|
|
9288
9369
|
"src/smoke/copilot-session-env.ts"() {
|
|
9289
9370
|
"use strict";
|
|
@@ -9294,6 +9375,25 @@ var init_copilot_session_env = __esm({
|
|
|
9294
9375
|
init_env_vars();
|
|
9295
9376
|
init_jsonc();
|
|
9296
9377
|
init_copilot_sdk_scenarios();
|
|
9378
|
+
STRIPPED_ENV_EXACT = [
|
|
9379
|
+
"DISABLE_OMC",
|
|
9380
|
+
"CLAUDECODE",
|
|
9381
|
+
"CLAUDE_SESSION_ID",
|
|
9382
|
+
"CLAUDE_PLUGIN_ROOT",
|
|
9383
|
+
"NODE_OPTIONS",
|
|
9384
|
+
"COPILOT_HOME",
|
|
9385
|
+
"COPILOT_OFFLINE",
|
|
9386
|
+
"COPILOT_MODEL",
|
|
9387
|
+
COPILOT_RUN_ALLOW_ENV
|
|
9388
|
+
];
|
|
9389
|
+
STRIPPED_ENV_PREFIXES = ["OMC_", "CLAUDE_CODE_", "COPILOT_PROVIDER_"];
|
|
9390
|
+
LOGIN_SHADOWING_TOKENS = ["GH_TOKEN", "GITHUB_TOKEN"];
|
|
9391
|
+
SMOKE_SET_ENV = {
|
|
9392
|
+
COPILOT_ALLOW_ALL: "false",
|
|
9393
|
+
COPILOT_AUTO_UPDATE: "false",
|
|
9394
|
+
NO_COLOR: "1"
|
|
9395
|
+
};
|
|
9396
|
+
SESSION_SET_ENV = { OMC_HOOK_FAIL_CLOSED: "1" };
|
|
9297
9397
|
CREDENTIAL_ENV = [
|
|
9298
9398
|
"GH_TOKEN",
|
|
9299
9399
|
"GITHUB_TOKEN",
|
|
@@ -9478,8 +9578,8 @@ function buildWindowsSupervisorSource() {
|
|
|
9478
9578
|
"} catch { if ($pi.hProcess -ne [IntPtr]::Zero) { if ($jobAssigned) { [O]::TerminateJobObject($job, 1) | Out-Null } else { [O]::TerminateProcess($pi.hProcess, 1) | Out-Null }; [O]::WaitForSingleObject($pi.hProcess, 5000) | Out-Null }; throw } finally { if ($envPtr -ne [IntPtr]::Zero) { [Runtime.InteropServices.Marshal]::FreeHGlobal($envPtr) }; if ($pi.hThread -ne [IntPtr]::Zero) { [O]::CloseHandle($pi.hThread) | Out-Null }; if ($pi.hProcess -ne [IntPtr]::Zero) { [O]::CloseHandle($pi.hProcess) | Out-Null }; if ($job -ne [IntPtr]::Zero) { [O]::CloseHandle($job) | Out-Null } }"
|
|
9479
9579
|
].join("\n");
|
|
9480
9580
|
}
|
|
9481
|
-
function encodePowerShell(
|
|
9482
|
-
const compressed = (0, import_node_zlib.gzipSync)(Buffer.from(
|
|
9581
|
+
function encodePowerShell(source2) {
|
|
9582
|
+
const compressed = (0, import_node_zlib.gzipSync)(Buffer.from(source2, "utf8")).toString("base64");
|
|
9483
9583
|
const loader = [
|
|
9484
9584
|
'$ErrorActionPreference = "Stop"',
|
|
9485
9585
|
`$memory = [IO.MemoryStream]::new([Convert]::FromBase64String('${compressed}'))`,
|
|
@@ -9495,7 +9595,7 @@ function canonicalAuthorityDigest(input) {
|
|
|
9495
9595
|
return (0, import_node_crypto5.createHash)("sha256").update(payload, "utf8").digest("hex");
|
|
9496
9596
|
}
|
|
9497
9597
|
function sleep2(ms) {
|
|
9498
|
-
return new Promise((
|
|
9598
|
+
return new Promise((resolve22) => setTimeout(resolve22, ms));
|
|
9499
9599
|
}
|
|
9500
9600
|
function isExactText(value) {
|
|
9501
9601
|
return typeof value === "string" && value.length > 0 && value === value.trim();
|
|
@@ -10958,11 +11058,11 @@ async function runWorkerLaunchBootstrap(value) {
|
|
|
10958
11058
|
let resolveCompletion;
|
|
10959
11059
|
let resolveWindowsReady;
|
|
10960
11060
|
let resolveWindowsTerminal;
|
|
10961
|
-
const windowsReady = new Promise((
|
|
10962
|
-
resolveWindowsReady =
|
|
11061
|
+
const windowsReady = new Promise((resolve22) => {
|
|
11062
|
+
resolveWindowsReady = resolve22;
|
|
10963
11063
|
});
|
|
10964
|
-
const windowsTerminal = new Promise((
|
|
10965
|
-
resolveWindowsTerminal =
|
|
11064
|
+
const windowsTerminal = new Promise((resolve22) => {
|
|
11065
|
+
resolveWindowsTerminal = resolve22;
|
|
10966
11066
|
});
|
|
10967
11067
|
if (process.platform === "win32") child.stderr?.resume();
|
|
10968
11068
|
if (providerGate) {
|
|
@@ -10978,9 +11078,9 @@ async function runWorkerLaunchBootstrap(value) {
|
|
|
10978
11078
|
});
|
|
10979
11079
|
}
|
|
10980
11080
|
let windowsTerminationProofWrite = Promise.resolve();
|
|
10981
|
-
const windowsStdoutClosed = new Promise((
|
|
10982
|
-
if (process.platform !== "win32" || !child.stdout)
|
|
10983
|
-
else child.stdout.once("close", () =>
|
|
11081
|
+
const windowsStdoutClosed = new Promise((resolve22) => {
|
|
11082
|
+
if (process.platform !== "win32" || !child.stdout) resolve22();
|
|
11083
|
+
else child.stdout.once("close", () => resolve22());
|
|
10984
11084
|
});
|
|
10985
11085
|
if (process.platform === "win32" && child.stdout) {
|
|
10986
11086
|
let buffered = "";
|
|
@@ -11030,8 +11130,8 @@ async function runWorkerLaunchBootstrap(value) {
|
|
|
11030
11130
|
}
|
|
11031
11131
|
});
|
|
11032
11132
|
}
|
|
11033
|
-
const completion = new Promise((
|
|
11034
|
-
resolveCompletion =
|
|
11133
|
+
const completion = new Promise((resolve22) => {
|
|
11134
|
+
resolveCompletion = resolve22;
|
|
11035
11135
|
child.once(process.platform === "win32" ? "close" : "exit", async (exitCode, signal) => {
|
|
11036
11136
|
if (settled && process.platform === "win32" || childExitObserved) return;
|
|
11037
11137
|
childExitObserved = true;
|
|
@@ -11090,7 +11190,7 @@ async function runWorkerLaunchBootstrap(value) {
|
|
|
11090
11190
|
written_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
11091
11191
|
}).catch(() => void 0);
|
|
11092
11192
|
await invocation.cleanup().catch(() => void 0);
|
|
11093
|
-
|
|
11193
|
+
resolve22(gateCleanupRequired ? cleanupVerified ? { outcome: "provider_spawn_failed" } : { outcome: "provider_cleanup_unverified" } : cleanupVerified ? { outcome: "ran", exitCode: effectiveExitCode, signal: effectiveSignal } : { outcome: "provider_cleanup_unverified" });
|
|
11094
11194
|
});
|
|
11095
11195
|
child.once("error", async () => {
|
|
11096
11196
|
if (settled) return;
|
|
@@ -11108,7 +11208,7 @@ async function runWorkerLaunchBootstrap(value) {
|
|
|
11108
11208
|
written_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
11109
11209
|
}).catch(() => void 0);
|
|
11110
11210
|
await invocation.cleanup().catch(() => void 0);
|
|
11111
|
-
|
|
11211
|
+
resolve22({ outcome: "provider_spawn_failed" });
|
|
11112
11212
|
});
|
|
11113
11213
|
});
|
|
11114
11214
|
const terminateProvider = async () => {
|
|
@@ -11143,7 +11243,7 @@ async function runWorkerLaunchBootstrap(value) {
|
|
|
11143
11243
|
}
|
|
11144
11244
|
return await Promise.race([
|
|
11145
11245
|
windowsTerminal,
|
|
11146
|
-
new Promise((
|
|
11246
|
+
new Promise((resolve22) => setTimeout(() => resolve22(false), 5e3))
|
|
11147
11247
|
]);
|
|
11148
11248
|
}
|
|
11149
11249
|
if (child.pid && providerStartIdentity && launchGroup) {
|
|
@@ -11155,11 +11255,11 @@ async function runWorkerLaunchBootstrap(value) {
|
|
|
11155
11255
|
force: true
|
|
11156
11256
|
});
|
|
11157
11257
|
await terminationResult;
|
|
11158
|
-
const completed = await new Promise((
|
|
11159
|
-
const timer = setTimeout(() =>
|
|
11258
|
+
const completed = await new Promise((resolve22) => {
|
|
11259
|
+
const timer = setTimeout(() => resolve22(false), 2e3);
|
|
11160
11260
|
void completion.then((result) => {
|
|
11161
11261
|
clearTimeout(timer);
|
|
11162
|
-
|
|
11262
|
+
resolve22(result.outcome !== "provider_cleanup_unverified");
|
|
11163
11263
|
});
|
|
11164
11264
|
});
|
|
11165
11265
|
return completed;
|
|
@@ -11178,20 +11278,20 @@ async function runWorkerLaunchBootstrap(value) {
|
|
|
11178
11278
|
if (!providerGate || providerGate.destroyed) return false;
|
|
11179
11279
|
let callbackCalled = false;
|
|
11180
11280
|
let callbackError = false;
|
|
11181
|
-
const closeResultPromise = new Promise((
|
|
11182
|
-
providerGateOperationResolve =
|
|
11281
|
+
const closeResultPromise = new Promise((resolve22) => {
|
|
11282
|
+
providerGateOperationResolve = resolve22;
|
|
11183
11283
|
const finish = (error) => {
|
|
11184
11284
|
providerGateError ??= error ?? null;
|
|
11185
11285
|
providerGateOperationResolve = null;
|
|
11186
11286
|
callbackCalled = true;
|
|
11187
11287
|
callbackError = providerGateError !== null;
|
|
11188
|
-
|
|
11288
|
+
resolve22(!callbackError);
|
|
11189
11289
|
};
|
|
11190
11290
|
try {
|
|
11191
11291
|
providerGate.end(finish);
|
|
11192
11292
|
} catch {
|
|
11193
11293
|
providerGateOperationResolve = null;
|
|
11194
|
-
|
|
11294
|
+
resolve22(false);
|
|
11195
11295
|
}
|
|
11196
11296
|
});
|
|
11197
11297
|
providerGateOperationPromise = closeResultPromise;
|
|
@@ -11215,8 +11315,8 @@ async function runWorkerLaunchBootstrap(value) {
|
|
|
11215
11315
|
if (providerGateReleased) return providerGateError === null;
|
|
11216
11316
|
if (providerGateReleaseAttempted || providerGateClosed || !providerGate || providerGate.destroyed) return false;
|
|
11217
11317
|
providerGateReleaseAttempted = true;
|
|
11218
|
-
const releasePromise = new Promise((
|
|
11219
|
-
providerGateOperationResolve =
|
|
11318
|
+
const releasePromise = new Promise((resolve22) => {
|
|
11319
|
+
providerGateOperationResolve = resolve22;
|
|
11220
11320
|
try {
|
|
11221
11321
|
providerGate.end("release\n", (error) => {
|
|
11222
11322
|
providerGateError ??= error ?? null;
|
|
@@ -11226,11 +11326,11 @@ async function runWorkerLaunchBootstrap(value) {
|
|
|
11226
11326
|
providerGateReleased = true;
|
|
11227
11327
|
terminateProviderOnGateError = null;
|
|
11228
11328
|
}
|
|
11229
|
-
|
|
11329
|
+
resolve22(released);
|
|
11230
11330
|
});
|
|
11231
11331
|
} catch {
|
|
11232
11332
|
providerGateOperationResolve = null;
|
|
11233
|
-
|
|
11333
|
+
resolve22(false);
|
|
11234
11334
|
}
|
|
11235
11335
|
});
|
|
11236
11336
|
providerGateOperationPromise = releasePromise;
|
|
@@ -11259,9 +11359,9 @@ async function runWorkerLaunchBootstrap(value) {
|
|
|
11259
11359
|
for (const signal of cleanupSignals) process.removeListener(signal, onBootstrapSignal);
|
|
11260
11360
|
});
|
|
11261
11361
|
}
|
|
11262
|
-
const spawned = await new Promise((
|
|
11263
|
-
child.once("spawn", () =>
|
|
11264
|
-
child.once("error", () =>
|
|
11362
|
+
const spawned = await new Promise((resolve22) => {
|
|
11363
|
+
child.once("spawn", () => resolve22(true));
|
|
11364
|
+
child.once("error", () => resolve22(false));
|
|
11265
11365
|
});
|
|
11266
11366
|
if (!spawned) {
|
|
11267
11367
|
await completion;
|
|
@@ -11270,7 +11370,7 @@ async function runWorkerLaunchBootstrap(value) {
|
|
|
11270
11370
|
if (process.platform === "win32") {
|
|
11271
11371
|
const ready = await Promise.race([
|
|
11272
11372
|
windowsReady,
|
|
11273
|
-
new Promise((
|
|
11373
|
+
new Promise((resolve22) => setTimeout(() => resolve22(false), 1e4))
|
|
11274
11374
|
]);
|
|
11275
11375
|
if (!ready || !providerPid || !providerStartIdentity || settled) {
|
|
11276
11376
|
return cleanupProvider("provider_spawn_failed");
|
|
@@ -11305,7 +11405,7 @@ async function runWorkerLaunchBootstrap(value) {
|
|
|
11305
11405
|
if (!await releaseProviderGate() || providerGateError !== null) {
|
|
11306
11406
|
return cleanupProvider("provider_spawn_failed");
|
|
11307
11407
|
}
|
|
11308
|
-
if (!spec.release_after_spawn) await new Promise((
|
|
11408
|
+
if (!spec.release_after_spawn) await new Promise((resolve22) => setTimeout(resolve22, 75));
|
|
11309
11409
|
if (settled) return { completion };
|
|
11310
11410
|
}
|
|
11311
11411
|
if (invocation.completionPath && (0, import_node_fs6.existsSync)(invocation.completionPath)) {
|
|
@@ -16495,7 +16595,7 @@ async function withDispatchLock(teamName, cwd, fn) {
|
|
|
16495
16595
|
);
|
|
16496
16596
|
}
|
|
16497
16597
|
const jitter = 0.5 + Math.random() * 0.5;
|
|
16498
|
-
await new Promise((
|
|
16598
|
+
await new Promise((resolve22) => setTimeout(resolve22, Math.floor(pollMs * jitter)));
|
|
16499
16599
|
pollMs = Math.min(pollMs * 2, DISPATCH_LOCK_MAX_POLL_MS);
|
|
16500
16600
|
}
|
|
16501
16601
|
}
|
|
@@ -17151,7 +17251,7 @@ async function writeAtomic2(path5, data) {
|
|
|
17151
17251
|
const delay = WIN32_RENAME_RETRY_DELAYS_MS[attempt];
|
|
17152
17252
|
const code = error.code ?? "";
|
|
17153
17253
|
if (process.platform !== "win32" || delay === void 0 || !WIN32_RENAME_RETRY_CODES.has(code)) throw error;
|
|
17154
|
-
await new Promise((
|
|
17254
|
+
await new Promise((resolve22) => setTimeout(resolve22, delay));
|
|
17155
17255
|
}
|
|
17156
17256
|
}
|
|
17157
17257
|
} finally {
|
|
@@ -20282,8 +20382,8 @@ async function startMergeOrchestrator(config) {
|
|
|
20282
20382
|
let persisted = { lastShas: {} };
|
|
20283
20383
|
if ((0, import_node_fs14.existsSync)(persistedPath)) {
|
|
20284
20384
|
try {
|
|
20285
|
-
const { readFileSync:
|
|
20286
|
-
persisted = JSON.parse(
|
|
20385
|
+
const { readFileSync: readFileSync33 } = await import("node:fs");
|
|
20386
|
+
persisted = JSON.parse(readFileSync33(persistedPath, "utf-8"));
|
|
20287
20387
|
} catch {
|
|
20288
20388
|
persisted = { lastShas: {} };
|
|
20289
20389
|
}
|
|
@@ -20667,8 +20767,8 @@ ${dirtyFiles.map((f) => `- \`${f}\``).join("\n")}`;
|
|
|
20667
20767
|
return false;
|
|
20668
20768
|
}
|
|
20669
20769
|
})(),
|
|
20670
|
-
new Promise((
|
|
20671
|
-
const t = setTimeout(() =>
|
|
20770
|
+
new Promise((resolve22) => {
|
|
20771
|
+
const t = setTimeout(() => resolve22(false), remaining);
|
|
20672
20772
|
if (typeof t.unref === "function") t.unref();
|
|
20673
20773
|
})
|
|
20674
20774
|
]);
|
|
@@ -20730,8 +20830,8 @@ async function recoverFromRestart(config) {
|
|
|
20730
20830
|
let persistedShasLoaded = 0;
|
|
20731
20831
|
if ((0, import_node_fs14.existsSync)(persistedPath)) {
|
|
20732
20832
|
try {
|
|
20733
|
-
const { readFileSync:
|
|
20734
|
-
const persisted = JSON.parse(
|
|
20833
|
+
const { readFileSync: readFileSync33 } = await import("node:fs");
|
|
20834
|
+
const persisted = JSON.parse(readFileSync33(persistedPath, "utf-8"));
|
|
20735
20835
|
persistedShasLoaded = Object.keys(persisted.lastShas ?? {}).length;
|
|
20736
20836
|
} catch {
|
|
20737
20837
|
persistedShasLoaded = 0;
|
|
@@ -20799,421 +20899,36 @@ var init_merge_orchestrator = __esm({
|
|
|
20799
20899
|
}
|
|
20800
20900
|
});
|
|
20801
20901
|
|
|
20802
|
-
// src/
|
|
20803
|
-
function
|
|
20804
|
-
|
|
20805
|
-
|
|
20806
|
-
|
|
20807
|
-
|
|
20902
|
+
// src/copilot-run/timeout.ts
|
|
20903
|
+
function withTimeout(promise, ms, label) {
|
|
20904
|
+
let timer;
|
|
20905
|
+
return Promise.race([
|
|
20906
|
+
promise,
|
|
20907
|
+
new Promise((_, reject) => {
|
|
20908
|
+
timer = setTimeout(() => reject(new Error(`${label} timed out after ${ms} ms`)), ms);
|
|
20909
|
+
})
|
|
20910
|
+
]).finally(() => clearTimeout(timer));
|
|
20808
20911
|
}
|
|
20809
|
-
var
|
|
20810
|
-
var
|
|
20811
|
-
"src/
|
|
20912
|
+
var errText;
|
|
20913
|
+
var init_timeout = __esm({
|
|
20914
|
+
"src/copilot-run/timeout.ts"() {
|
|
20812
20915
|
"use strict";
|
|
20813
|
-
|
|
20814
|
-
import_promises17 = require("fs/promises");
|
|
20815
|
-
init_model_contract();
|
|
20816
|
-
init_loader();
|
|
20817
|
-
init_host_detection();
|
|
20818
|
-
init_types();
|
|
20819
|
-
init_types2();
|
|
20820
|
-
init_role_router();
|
|
20821
|
-
init_team_ops();
|
|
20822
|
-
init_types3();
|
|
20823
|
-
init_monitor();
|
|
20824
|
-
init_tmux_session();
|
|
20825
|
-
init_herdr_session();
|
|
20826
|
-
init_state_paths();
|
|
20827
|
-
init_worker_bootstrap();
|
|
20828
|
-
init_sdk_transport();
|
|
20829
|
-
init_git_worktree();
|
|
20830
|
-
init_worktree_paths();
|
|
20831
|
-
init_team_owner_epoch();
|
|
20832
|
-
init_runtime_owner_client();
|
|
20833
|
-
init_worker_launch_ack();
|
|
20834
|
-
init_team_instance();
|
|
20916
|
+
errText = (err) => err instanceof Error ? err.message : String(err);
|
|
20835
20917
|
}
|
|
20836
20918
|
});
|
|
20837
20919
|
|
|
20838
|
-
// src/
|
|
20839
|
-
|
|
20840
|
-
|
|
20841
|
-
outcome: "failed",
|
|
20842
|
-
committed: false,
|
|
20843
|
-
error,
|
|
20844
|
-
message,
|
|
20845
|
-
...reservationsWritten ? { reservationsWritten: true } : {},
|
|
20846
|
-
requestId: input.requestId,
|
|
20847
|
-
recoveryId: input.recoveryId,
|
|
20848
|
-
teamName: input.teamName,
|
|
20849
|
-
workerName: input.workerName,
|
|
20850
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
20851
|
-
};
|
|
20852
|
-
}
|
|
20853
|
-
async function runRecoverySaga(input, deps) {
|
|
20854
|
-
const persistPhase = (value, continuation, adoption, services2 = "not_started") => {
|
|
20855
|
-
writeRecoveryPhase(deps.cwd, { schema_version: 1, kind: "phase", request_id: input.requestId, recovery_id: input.recoveryId, team_name: input.teamName, worker_name: input.workerName, phase: value, continuation, adoption, services: services2, manifest: "not_started", updated_at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
20856
|
-
};
|
|
20857
|
-
const finalize = (result2, _continuation, _adoption, _services = "terminal_degraded") => result2;
|
|
20858
|
-
const liveness = await deps.getLiveness(input.teamName, input.workerName);
|
|
20859
|
-
const committedReplacement = liveness === "alive" ? await deps.isCommittedReplacement?.(input) ?? false : false;
|
|
20860
|
-
if (liveness === "unknown") return finalize(failure(input, "worker_liveness_unknown"), "none", "not_started");
|
|
20861
|
-
if (liveness === "alive" && !committedReplacement) {
|
|
20862
|
-
if (!input.originalPaneId?.trim()) return finalize(failure(input, "worker_liveness_unknown"), "none", "not_started");
|
|
20863
|
-
return finalize({ outcome: "already_running", committed: true, oldPaneId: null, newPaneId: input.originalPaneId, requeuedTaskIds: [], continuationSequenceByTask: {}, stateRevision: 0, activation: "active", manifestSync: "synced", servicesSync: "synced", warnings: [], requestId: input.requestId, recoveryId: input.recoveryId, teamName: input.teamName, workerName: input.workerName, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }, "none", "not_started", "synced");
|
|
20864
|
-
}
|
|
20865
|
-
if (!input.originalPaneId?.trim()) return finalize(failure(input, "worker_liveness_unknown"), "none", "not_started");
|
|
20866
|
-
const tasks = await deps.listOwnedInProgressTasks(input.teamName, input.workerName);
|
|
20867
|
-
if (tasks.length === 0) persistPhase("reserved", "none", "not_started");
|
|
20868
|
-
const checks = await Promise.all(tasks.map((task) => deps.validateCheckpoint(input.teamName, task)));
|
|
20869
|
-
const rejected = checks.find((check) => !check.ok);
|
|
20870
|
-
if (rejected) return finalize(failure(input, rejected.error), "selected", "not_started");
|
|
20871
|
-
persistPhase("reserved", tasks.length ? "selected" : "none", "not_started");
|
|
20872
|
-
const adoptionTokenHash = (0, import_node_crypto10.createHash)("sha256").update(input.adoptionToken).digest("hex");
|
|
20873
|
-
const sequences = {};
|
|
20874
|
-
for (const task of tasks) {
|
|
20875
|
-
const result2 = await deps.requeue(input, task.id, adoptionTokenHash);
|
|
20876
|
-
if (!result2.ok) return finalize(failure(input, result2.error, void 0, Object.keys(sequences).length > 0), "reserved", "not_started");
|
|
20877
|
-
sequences[task.id] = result2.sequence;
|
|
20878
|
-
try {
|
|
20879
|
-
persistPhase("requeued", "reserved", "not_started");
|
|
20880
|
-
} catch (error) {
|
|
20881
|
-
return finalize(failure(input, "invalid_persisted_state", error instanceof Error ? error.message : String(error), true), "reserved", "not_started");
|
|
20882
|
-
}
|
|
20883
|
-
}
|
|
20884
|
-
const pane = await deps.spawnGatedPane(input);
|
|
20885
|
-
if (!pane.ok) return finalize(failure(input, pane.error), tasks.length ? "reserved" : "none", "not_started");
|
|
20886
|
-
if (!pane.paneId.trim()) return finalize(failure(input, "spawn_failed"), tasks.length ? "reserved" : "none", "not_started");
|
|
20887
|
-
let persisted;
|
|
20888
|
-
if (pane.committed) {
|
|
20889
|
-
persisted = { stateRevision: pane.stateRevision ?? 0, manifestSync: pane.manifestSync ?? "repair_required" };
|
|
20890
|
-
} else {
|
|
20891
|
-
try {
|
|
20892
|
-
persisted = await deps.persistActive(input, pane.paneId);
|
|
20893
|
-
} catch (error) {
|
|
20894
|
-
await deps.killAttemptPane(pane.paneAttemptId);
|
|
20895
|
-
return finalize(failure(input, "config_commit_failed", error instanceof Error ? error.message : String(error)), tasks.length ? "reserved" : "none", "not_started");
|
|
20896
|
-
}
|
|
20897
|
-
}
|
|
20898
|
-
if (persisted.manifestSync !== "synced") {
|
|
20899
|
-
return finalize({ ...failure(input, "config_commit_failed", "Replacement config committed but manifest projection requires repair."), outcome: "commit_unknown" }, tasks.length ? "reserved" : "none", tasks.length ? "pending" : "not_started");
|
|
20900
|
-
}
|
|
20901
|
-
const activated = await deps.activatePane(input, pane.paneAttemptId);
|
|
20902
|
-
if (!activated.ok) {
|
|
20903
|
-
return finalize({ ...failure(input, activated.error), outcome: "commit_unknown", message: "Replacement was committed but activation remains pending." }, tasks.length ? "reserved" : "none", tasks.length ? "pending" : "not_started");
|
|
20904
|
-
}
|
|
20905
|
-
persistPhase("ready", tasks.length ? "reserved" : "none", tasks.length ? "pending" : "not_started");
|
|
20906
|
-
let continuations = [];
|
|
20907
|
-
if (tasks.length) {
|
|
20908
|
-
const adopted = await deps.adoptAll(input, { recoveryId: input.recoveryId, requestId: input.requestId, replacementGeneration: input.replacementGeneration, adoptionToken: input.adoptionToken }, tasks.map((task) => task.id));
|
|
20909
|
-
if (!adopted.ok) {
|
|
20910
|
-
return finalize({ ...failure(input, adopted.error), outcome: "commit_unknown", message: "Replacement was committed but continuation adoption remains pending." }, "reserved", "pending");
|
|
20911
|
-
}
|
|
20912
|
-
continuations = adopted.continuations;
|
|
20913
|
-
persistPhase("adopted", "adopted", "adopted");
|
|
20914
|
-
}
|
|
20915
|
-
const services = await deps.repairServices(input);
|
|
20916
|
-
if (services === "synced") {
|
|
20917
|
-
await deps.writeRun(input, pane.paneAttemptId, continuations);
|
|
20918
|
-
} else {
|
|
20919
|
-
persistPhase("services_pending", tasks.length ? "adopted" : "none", tasks.length ? "adopted" : "not_started", "repair_required");
|
|
20920
|
-
}
|
|
20921
|
-
const result = { outcome: "recovered", committed: true, oldPaneId: input.originalPaneId, newPaneId: pane.paneId, requeuedTaskIds: tasks.map((task) => task.id), continuationSequenceByTask: sequences, stateRevision: persisted.stateRevision, activation: services === "synced" ? "active" : "services_pending", manifestSync: persisted.manifestSync, servicesSync: services, warnings: services === "synced" ? [] : ["services_pending"], requestId: input.requestId, recoveryId: input.recoveryId, teamName: input.teamName, workerName: input.workerName, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
20922
|
-
return finalize(result, tasks.length ? "adopted" : "none", tasks.length ? "adopted" : "not_started", services);
|
|
20923
|
-
}
|
|
20924
|
-
var import_node_crypto10;
|
|
20925
|
-
var init_recovery_saga = __esm({
|
|
20926
|
-
"src/team/recovery-saga.ts"() {
|
|
20920
|
+
// src/utils/url.ts
|
|
20921
|
+
var init_url = __esm({
|
|
20922
|
+
"src/utils/url.ts"() {
|
|
20927
20923
|
"use strict";
|
|
20928
|
-
import_node_crypto10 = require("node:crypto");
|
|
20929
|
-
init_recovery_request_store();
|
|
20930
20924
|
}
|
|
20931
20925
|
});
|
|
20932
20926
|
|
|
20933
|
-
// src/
|
|
20934
|
-
|
|
20935
|
-
|
|
20936
|
-
|
|
20937
|
-
|
|
20938
|
-
await (0, import_promises18.rename)(temporary, path5);
|
|
20939
|
-
}
|
|
20940
|
-
async function waitForRecoveryGateRecord(path5, expected, timeoutMs, pollIntervalMs = 100) {
|
|
20941
|
-
const deadline = Date.now() + timeoutMs;
|
|
20942
|
-
while (Date.now() < deadline) {
|
|
20943
|
-
try {
|
|
20944
|
-
const value = JSON.parse(await (0, import_promises18.readFile)(path5, "utf8"));
|
|
20945
|
-
if (value.recovery_id === expected.recovery_id && value.worker_name === expected.worker_name && value.replacement_generation === expected.replacement_generation && value.pane_attempt_id === expected.pane_attempt_id && value.launch_attempt_id === expected.launch_attempt_id && value.launch_nonce === expected.launch_nonce) return true;
|
|
20946
|
-
} catch {
|
|
20947
|
-
}
|
|
20948
|
-
await new Promise((resolve21) => setTimeout(resolve21, pollIntervalMs));
|
|
20949
|
-
}
|
|
20950
|
-
return false;
|
|
20951
|
-
}
|
|
20952
|
-
async function runWorkerActivationGate(gate) {
|
|
20953
|
-
if (gate.providerArgv.length === 0 || !gate.providerArgv[0]) return { outcome: "invalid_provider_argv" };
|
|
20954
|
-
const launchAttempt = gate.launchAttempt;
|
|
20955
|
-
const launchContext = launchAttempt?.context;
|
|
20956
|
-
if (!launchAttempt || launchContext?.kind !== "recovery" || launchAttempt.worker_name !== gate.workerName || launchContext.recovery_id !== gate.recoveryId || launchContext.replacement_generation !== gate.replacementGeneration || launchContext.pane_attempt_id !== gate.paneAttemptId) return { outcome: "superseded" };
|
|
20957
|
-
if (process.platform === "win32") return { outcome: "provider_cleanup_unverified" };
|
|
20958
|
-
const expected = {
|
|
20959
|
-
recovery_id: gate.recoveryId,
|
|
20960
|
-
worker_name: gate.workerName,
|
|
20961
|
-
replacement_generation: gate.replacementGeneration,
|
|
20962
|
-
pane_attempt_id: gate.paneAttemptId,
|
|
20963
|
-
launch_attempt_id: launchAttempt.attempt_id,
|
|
20964
|
-
launch_nonce: launchAttempt.nonce,
|
|
20965
|
-
written_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
20966
|
-
};
|
|
20967
|
-
const timeoutMs = gate.timeoutMs ?? 3e4;
|
|
20968
|
-
const pollIntervalMs = gate.pollIntervalMs ?? 100;
|
|
20969
|
-
await writeAtomic3(gate.readyPath, expected);
|
|
20970
|
-
if (!await waitForRecoveryGateRecord(gate.activatePath, expected, timeoutMs, pollIntervalMs)) return { outcome: "activation_timeout" };
|
|
20971
|
-
await writeAtomic3(`${gate.readyPath}.adoption-ready`, { ...expected, written_at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
20972
|
-
if (!await waitForRecoveryGateRecord(gate.runPath, expected, timeoutMs, pollIntervalMs)) return { outcome: "run_timeout" };
|
|
20973
|
-
const fenced = await withWorkerLaunchAttemptFence(launchAttempt, async () => {
|
|
20974
|
-
const {
|
|
20975
|
-
OMC_RECOVERY_GATE_SPEC: _recoveryGateSpec,
|
|
20976
|
-
OMC_RECOVERY_GATE_SPEC_B64: _encodedRecoveryGateSpec,
|
|
20977
|
-
[WORKER_LAUNCH_RECOVERY_GATE_CONTAINED_ENV]: containedByBootstrap,
|
|
20978
|
-
...providerProcessEnv
|
|
20979
|
-
} = process.env;
|
|
20980
|
-
const containedByDurableBootstrap = containedByBootstrap === "1";
|
|
20981
|
-
const providerEnv = { ...providerProcessEnv, ...gate.env };
|
|
20982
|
-
delete providerEnv[WORKER_LAUNCH_RECOVERY_GATE_CONTAINED_ENV];
|
|
20983
|
-
const invocation = await materializeProviderSpawnInvocation(buildProviderSpawnInvocation(gate.providerArgv, process.platform, providerEnv), {
|
|
20984
|
-
superviseProcessTree: true,
|
|
20985
|
-
completionIdentity: buildWorkerLaunchBootstrapSpec(
|
|
20986
|
-
launchAttempt,
|
|
20987
|
-
gate.providerArgv,
|
|
20988
|
-
gate.cwd,
|
|
20989
|
-
{ providerEnv }
|
|
20990
|
-
)
|
|
20991
|
-
});
|
|
20992
|
-
const child = (0, import_node_child_process8.spawn)(invocation.command, invocation.args, {
|
|
20993
|
-
cwd: gate.cwd,
|
|
20994
|
-
env: buildProviderSpawnEnvironment(providerEnv, invocation),
|
|
20995
|
-
stdio: "inherit",
|
|
20996
|
-
windowsVerbatimArguments: invocation.windowsVerbatimArguments,
|
|
20997
|
-
// A recovery gate already runs inside the durable worker-launch
|
|
20998
|
-
// bootstrap group. Keep the actual provider in that group so teardown's
|
|
20999
|
-
// group-absence proof covers the provider rather than only the gate.
|
|
21000
|
-
// Direct gate callers retain the pre-bootstrap detached cleanup path.
|
|
21001
|
-
detached: process.platform !== "win32" && !containedByDurableBootstrap
|
|
21002
|
-
});
|
|
21003
|
-
let settled = false;
|
|
21004
|
-
let providerPid;
|
|
21005
|
-
let providerStartIdentity = null;
|
|
21006
|
-
let providerProcessGroupId;
|
|
21007
|
-
let supervisedExitCode = null;
|
|
21008
|
-
let supervisorTimer;
|
|
21009
|
-
let terminationResult = null;
|
|
21010
|
-
let finishCompletion;
|
|
21011
|
-
const completion = new Promise((resolve21) => {
|
|
21012
|
-
const finish = async (result, terminal) => {
|
|
21013
|
-
if (settled) return;
|
|
21014
|
-
settled = true;
|
|
21015
|
-
if (supervisorTimer) clearInterval(supervisorTimer);
|
|
21016
|
-
try {
|
|
21017
|
-
await writeAtomic3(`${gate.runPath}.terminal`, {
|
|
21018
|
-
...expected,
|
|
21019
|
-
provider_pid: child.pid ?? null,
|
|
21020
|
-
...terminal,
|
|
21021
|
-
...providerProcessGroupId !== void 0 ? { process_group_id: providerProcessGroupId } : {},
|
|
21022
|
-
written_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
21023
|
-
});
|
|
21024
|
-
} catch {
|
|
21025
|
-
}
|
|
21026
|
-
await invocation.cleanup().catch(() => void 0);
|
|
21027
|
-
resolve21(result);
|
|
21028
|
-
};
|
|
21029
|
-
finishCompletion = finish;
|
|
21030
|
-
child.once("exit", async (exitCode, signal) => {
|
|
21031
|
-
const effectiveExitCode = supervisedExitCode ?? exitCode;
|
|
21032
|
-
const effectiveSignal = supervisedExitCode === null ? signal : null;
|
|
21033
|
-
const cleanupVerified = terminationResult ? await terminationResult === "terminated" : false;
|
|
21034
|
-
await finish(
|
|
21035
|
-
cleanupVerified ? { outcome: "ran", exitCode: effectiveExitCode, signal: effectiveSignal } : { outcome: "provider_cleanup_unverified" },
|
|
21036
|
-
{
|
|
21037
|
-
outcome: cleanupVerified ? "exit" : "cleanup_unverified",
|
|
21038
|
-
cleanup_verified: cleanupVerified,
|
|
21039
|
-
exit_code: effectiveExitCode,
|
|
21040
|
-
signal: effectiveSignal
|
|
21041
|
-
}
|
|
21042
|
-
);
|
|
21043
|
-
});
|
|
21044
|
-
child.once("error", () => {
|
|
21045
|
-
void finish({ outcome: "provider_spawn_failed" }, { outcome: "error", cleanup_verified: false });
|
|
21046
|
-
});
|
|
21047
|
-
});
|
|
21048
|
-
const terminateProvider = async () => {
|
|
21049
|
-
if (settled) return true;
|
|
21050
|
-
if (providerPid && providerStartIdentity) {
|
|
21051
|
-
terminationResult ??= terminateOwnedProcessTree({
|
|
21052
|
-
pid: providerPid,
|
|
21053
|
-
expectedStartIdentity: providerStartIdentity,
|
|
21054
|
-
deadlineAt: new Date(Date.now() + 2e3).toISOString(),
|
|
21055
|
-
force: true
|
|
21056
|
-
});
|
|
21057
|
-
const terminated = await terminationResult === "terminated";
|
|
21058
|
-
const completed2 = await new Promise((resolve21) => {
|
|
21059
|
-
const timer = setTimeout(() => resolve21(false), 2e3);
|
|
21060
|
-
void completion.then((result) => {
|
|
21061
|
-
clearTimeout(timer);
|
|
21062
|
-
resolve21(result.outcome !== "provider_cleanup_unverified");
|
|
21063
|
-
});
|
|
21064
|
-
});
|
|
21065
|
-
return terminated && completed2;
|
|
21066
|
-
}
|
|
21067
|
-
try {
|
|
21068
|
-
if (child.pid && process.platform !== "win32") {
|
|
21069
|
-
try {
|
|
21070
|
-
process.kill(-child.pid, "SIGKILL");
|
|
21071
|
-
} catch {
|
|
21072
|
-
child.kill("SIGKILL");
|
|
21073
|
-
}
|
|
21074
|
-
} else {
|
|
21075
|
-
child.kill("SIGKILL");
|
|
21076
|
-
}
|
|
21077
|
-
} catch {
|
|
21078
|
-
}
|
|
21079
|
-
const completed = await new Promise((resolve21) => {
|
|
21080
|
-
const timer = setTimeout(() => resolve21(false), 2e3);
|
|
21081
|
-
void completion.then(() => {
|
|
21082
|
-
clearTimeout(timer);
|
|
21083
|
-
resolve21(true);
|
|
21084
|
-
});
|
|
21085
|
-
if (settled) {
|
|
21086
|
-
clearTimeout(timer);
|
|
21087
|
-
resolve21(true);
|
|
21088
|
-
}
|
|
21089
|
-
});
|
|
21090
|
-
return completed;
|
|
21091
|
-
};
|
|
21092
|
-
const cleanupSignals = ["SIGHUP", "SIGINT", "SIGTERM"];
|
|
21093
|
-
const onGateSignal = () => {
|
|
21094
|
-
void terminateProvider();
|
|
21095
|
-
};
|
|
21096
|
-
const ownsSignalLifecycle = Boolean(process.env.OMC_RECOVERY_GATE_SPEC || process.env.OMC_RECOVERY_GATE_SPEC_B64);
|
|
21097
|
-
if (ownsSignalLifecycle) {
|
|
21098
|
-
for (const signal of cleanupSignals) process.once(signal, onGateSignal);
|
|
21099
|
-
void completion.finally(() => {
|
|
21100
|
-
for (const signal of cleanupSignals) process.removeListener(signal, onGateSignal);
|
|
21101
|
-
});
|
|
21102
|
-
}
|
|
21103
|
-
const spawned = await new Promise((resolve21) => {
|
|
21104
|
-
child.once("spawn", () => resolve21(true));
|
|
21105
|
-
child.once("error", () => resolve21(false));
|
|
21106
|
-
});
|
|
21107
|
-
if (!spawned) {
|
|
21108
|
-
const failed = await completion;
|
|
21109
|
-
await invocation.cleanup();
|
|
21110
|
-
return failed.outcome === "provider_spawn_failed" ? { outcome: "provider_spawn_failed" } : failed;
|
|
21111
|
-
}
|
|
21112
|
-
try {
|
|
21113
|
-
providerPid = child.pid;
|
|
21114
|
-
providerStartIdentity = providerPid ? getProcessStartIdentitySync(providerPid) : null;
|
|
21115
|
-
providerProcessGroupId = providerPid ? captureOwnedProcessGroup(providerPid)?.processGroupId : void 0;
|
|
21116
|
-
if (!providerPid || !providerStartIdentity || settled || !isProcessAlive(providerPid)) {
|
|
21117
|
-
if (!await terminateProvider()) return { outcome: "provider_cleanup_unverified" };
|
|
21118
|
-
return { outcome: "provider_spawn_failed" };
|
|
21119
|
-
}
|
|
21120
|
-
if (!providerProcessGroupId) {
|
|
21121
|
-
if (!await terminateProvider()) return { outcome: "provider_cleanup_unverified" };
|
|
21122
|
-
return { outcome: "provider_spawn_failed" };
|
|
21123
|
-
}
|
|
21124
|
-
if (containedByDurableBootstrap) {
|
|
21125
|
-
const gateProcessGroupId = captureOwnedProcessGroup(process.pid)?.processGroupId;
|
|
21126
|
-
if (!gateProcessGroupId || gateProcessGroupId !== providerProcessGroupId) {
|
|
21127
|
-
if (!await terminateProvider()) return { outcome: "provider_cleanup_unverified" };
|
|
21128
|
-
return { outcome: "provider_cleanup_unverified" };
|
|
21129
|
-
}
|
|
21130
|
-
}
|
|
21131
|
-
await new Promise((resolve21) => setTimeout(resolve21, 150));
|
|
21132
|
-
if (settled) return await completion;
|
|
21133
|
-
const reboundIdentity = getProcessStartIdentitySync(providerPid);
|
|
21134
|
-
if (!reboundIdentity || reboundIdentity !== providerStartIdentity || !isProcessAlive(providerPid)) {
|
|
21135
|
-
if (!await terminateProvider()) return { outcome: "provider_cleanup_unverified" };
|
|
21136
|
-
return { outcome: "provider_spawn_failed" };
|
|
21137
|
-
}
|
|
21138
|
-
if (invocation.completionPath && await (0, import_promises18.readFile)(invocation.completionPath, "utf8").then(() => true).catch(() => false)) {
|
|
21139
|
-
const exitCode = await readProviderCompletionExitCode(
|
|
21140
|
-
invocation.completionPath,
|
|
21141
|
-
invocation.completionBinding
|
|
21142
|
-
);
|
|
21143
|
-
if (exitCode !== void 0) supervisedExitCode = exitCode;
|
|
21144
|
-
if (!await terminateProvider()) return { outcome: "provider_cleanup_unverified" };
|
|
21145
|
-
return { outcome: "provider_spawn_failed" };
|
|
21146
|
-
}
|
|
21147
|
-
await writeAtomic3(`${gate.runPath}.launched`, {
|
|
21148
|
-
...expected,
|
|
21149
|
-
provider_pid: providerPid,
|
|
21150
|
-
provider_start_identity: providerStartIdentity,
|
|
21151
|
-
process_group_id: providerProcessGroupId,
|
|
21152
|
-
written_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
21153
|
-
...invocation.completionPath ? { supervisor_completion_path: invocation.completionPath } : {}
|
|
21154
|
-
});
|
|
21155
|
-
if (invocation.completionPath) {
|
|
21156
|
-
let pollingCompletion = false;
|
|
21157
|
-
supervisorTimer = setInterval(() => {
|
|
21158
|
-
if (pollingCompletion || settled || !providerStartIdentity || !providerPid) return;
|
|
21159
|
-
pollingCompletion = true;
|
|
21160
|
-
void (0, import_promises18.readFile)(invocation.completionPath, "utf8").then(async () => {
|
|
21161
|
-
const exitCode = await readProviderCompletionExitCode(
|
|
21162
|
-
invocation.completionPath,
|
|
21163
|
-
invocation.completionBinding
|
|
21164
|
-
);
|
|
21165
|
-
if (exitCode === void 0) return;
|
|
21166
|
-
supervisedExitCode = exitCode;
|
|
21167
|
-
const cleaned = await terminateProvider();
|
|
21168
|
-
if (!cleaned && !settled) {
|
|
21169
|
-
await finishCompletion(
|
|
21170
|
-
{ outcome: "provider_cleanup_unverified" },
|
|
21171
|
-
{ outcome: "cleanup_unverified", cleanup_verified: false, exit_code: exitCode, signal: null }
|
|
21172
|
-
);
|
|
21173
|
-
}
|
|
21174
|
-
}).catch(() => void 0).finally(() => {
|
|
21175
|
-
pollingCompletion = false;
|
|
21176
|
-
});
|
|
21177
|
-
}, pollIntervalMs);
|
|
21178
|
-
supervisorTimer.unref();
|
|
21179
|
-
}
|
|
21180
|
-
return { completion };
|
|
21181
|
-
} catch {
|
|
21182
|
-
if (!await terminateProvider()) return { outcome: "provider_cleanup_unverified" };
|
|
21183
|
-
return { outcome: "provider_spawn_failed" };
|
|
21184
|
-
}
|
|
21185
|
-
});
|
|
21186
|
-
if (!fenced.ok) return { outcome: "superseded" };
|
|
21187
|
-
if ("completion" in fenced.value) {
|
|
21188
|
-
if (!fenced.value.completion) return { outcome: "provider_spawn_failed" };
|
|
21189
|
-
return await fenced.value.completion;
|
|
21190
|
-
}
|
|
21191
|
-
return fenced.value;
|
|
21192
|
-
}
|
|
21193
|
-
var import_node_child_process8, import_promises18, import_node_path15;
|
|
21194
|
-
var init_worker_activation_gate = __esm({
|
|
21195
|
-
"src/team/worker-activation-gate.ts"() {
|
|
21196
|
-
"use strict";
|
|
21197
|
-
import_node_child_process8 = require("node:child_process");
|
|
21198
|
-
import_promises18 = require("node:fs/promises");
|
|
21199
|
-
import_node_path15 = require("node:path");
|
|
21200
|
-
init_worker_launch_ack();
|
|
21201
|
-
init_process_utils();
|
|
21202
|
-
}
|
|
21203
|
-
});
|
|
21204
|
-
|
|
21205
|
-
// src/utils/url.ts
|
|
21206
|
-
var init_url = __esm({
|
|
21207
|
-
"src/utils/url.ts"() {
|
|
21208
|
-
"use strict";
|
|
21209
|
-
}
|
|
21210
|
-
});
|
|
21211
|
-
|
|
21212
|
-
// src/providers/remote-url.ts
|
|
21213
|
-
var init_remote_url = __esm({
|
|
21214
|
-
"src/providers/remote-url.ts"() {
|
|
21215
|
-
"use strict";
|
|
21216
|
-
init_url();
|
|
20927
|
+
// src/providers/remote-url.ts
|
|
20928
|
+
var init_remote_url = __esm({
|
|
20929
|
+
"src/providers/remote-url.ts"() {
|
|
20930
|
+
"use strict";
|
|
20931
|
+
init_url();
|
|
21217
20932
|
}
|
|
21218
20933
|
});
|
|
21219
20934
|
|
|
@@ -21464,13 +21179,13 @@ var init_routes = __esm({
|
|
|
21464
21179
|
});
|
|
21465
21180
|
|
|
21466
21181
|
// src/forge/ado/guard.ts
|
|
21467
|
-
var import_fs35, import_os9,
|
|
21182
|
+
var import_fs35, import_os9, import_path39, MAX_BODY_BYTES;
|
|
21468
21183
|
var init_guard = __esm({
|
|
21469
21184
|
"src/forge/ado/guard.ts"() {
|
|
21470
21185
|
"use strict";
|
|
21471
21186
|
import_fs35 = require("fs");
|
|
21472
21187
|
import_os9 = require("os");
|
|
21473
|
-
|
|
21188
|
+
import_path39 = require("path");
|
|
21474
21189
|
init_routes();
|
|
21475
21190
|
MAX_BODY_BYTES = 1024 * 1024;
|
|
21476
21191
|
}
|
|
@@ -21490,13 +21205,13 @@ var init_exec = __esm({
|
|
|
21490
21205
|
});
|
|
21491
21206
|
|
|
21492
21207
|
// src/ship/config.ts
|
|
21493
|
-
var import_fs36, import_os10,
|
|
21208
|
+
var import_fs36, import_os10, import_path40, OMG_REPOSITORY_REQUIRED_CHECKS, DEFAULT_SHIP_CONFIG;
|
|
21494
21209
|
var init_config2 = __esm({
|
|
21495
21210
|
"src/ship/config.ts"() {
|
|
21496
21211
|
"use strict";
|
|
21497
21212
|
import_fs36 = require("fs");
|
|
21498
21213
|
import_os10 = require("os");
|
|
21499
|
-
|
|
21214
|
+
import_path40 = require("path");
|
|
21500
21215
|
init_jsonc();
|
|
21501
21216
|
init_loader();
|
|
21502
21217
|
init_project_config_path();
|
|
@@ -21599,10 +21314,50 @@ var init_sdk_policy = __esm({
|
|
|
21599
21314
|
});
|
|
21600
21315
|
|
|
21601
21316
|
// src/copilot-run/sandbox.ts
|
|
21602
|
-
|
|
21317
|
+
function envValue2(env, name) {
|
|
21318
|
+
const key = Object.keys(env).find((k) => k.toUpperCase() === name);
|
|
21319
|
+
const value = key === void 0 ? void 0 : env[key];
|
|
21320
|
+
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
21321
|
+
}
|
|
21322
|
+
function secretValues(env) {
|
|
21323
|
+
return ["COPILOT_GITHUB_TOKEN", "GH_TOKEN", "GITHUB_TOKEN"].map((n) => envValue2(env, n)).filter((v) => v !== void 0 && v.length >= 8);
|
|
21324
|
+
}
|
|
21325
|
+
function scrubTokens(text2, secrets) {
|
|
21326
|
+
let out = text2;
|
|
21327
|
+
for (const s of secrets) out = out.split(s).join("[redacted]");
|
|
21328
|
+
return out.replace(TOKEN_PATTERN, "[redacted]");
|
|
21329
|
+
}
|
|
21330
|
+
function relocatedProfileEnv(jobHome) {
|
|
21331
|
+
const profile = (0, import_node_path15.join)(jobHome, "profile");
|
|
21332
|
+
const tmp = (0, import_node_path15.join)(jobHome, "tmp");
|
|
21333
|
+
return {
|
|
21334
|
+
TEMP: tmp,
|
|
21335
|
+
TMP: tmp,
|
|
21336
|
+
TMPDIR: tmp,
|
|
21337
|
+
USERPROFILE: profile,
|
|
21338
|
+
HOME: profile,
|
|
21339
|
+
XDG_CONFIG_HOME: (0, import_node_path15.join)(profile, ".config"),
|
|
21340
|
+
GIT_CONFIG_GLOBAL: (0, import_node_path15.join)(jobHome, "git", "config"),
|
|
21341
|
+
NODE_DISABLE_COMPILE_CACHE: "1",
|
|
21342
|
+
// The runtime's cache would follow the host LOCALAPPDATA (allowlisted for MXC): keep it, and the sandboxed MCP cache grant
|
|
21343
|
+
// anchored on it, in the job home but outside the lane-writable profile: the runtime loads code from its pkg dir.
|
|
21344
|
+
COPILOT_CACHE_HOME: (0, import_node_path15.join)(jobHome, ".cache", "copilot")
|
|
21345
|
+
};
|
|
21346
|
+
}
|
|
21347
|
+
function allowlistSessionEnv(env, jobHome) {
|
|
21348
|
+
const allow = new Set([...SESSION_ENV_ALLOWLIST, ...Object.keys(SMOKE_SET_ENV), "COPILOT_HOME"].map((k) => k.toUpperCase()));
|
|
21349
|
+
const out = {};
|
|
21350
|
+
for (const [key, value] of Object.entries(env)) {
|
|
21351
|
+
const upper = key.toUpperCase();
|
|
21352
|
+
if (allow.has(upper) || upper.startsWith("LC_") || upper.startsWith("OMC_")) out[key] = value;
|
|
21353
|
+
}
|
|
21354
|
+
return { ...out, ...relocatedProfileEnv(jobHome) };
|
|
21355
|
+
}
|
|
21356
|
+
var import_node_path15, DEFAULT_SANDBOX_SETTINGS, SESSION_ENV_ALLOWLIST, TOKEN_PATTERN;
|
|
21603
21357
|
var init_sandbox = __esm({
|
|
21604
21358
|
"src/copilot-run/sandbox.ts"() {
|
|
21605
21359
|
"use strict";
|
|
21360
|
+
import_node_path15 = require("node:path");
|
|
21606
21361
|
init_config2();
|
|
21607
21362
|
init_project_config_path();
|
|
21608
21363
|
init_copilot_session_env();
|
|
@@ -21620,10 +21375,71 @@ var init_sandbox = __esm({
|
|
|
21620
21375
|
extraReadonlyPaths: [],
|
|
21621
21376
|
extraReadwritePaths: []
|
|
21622
21377
|
});
|
|
21378
|
+
SESSION_ENV_ALLOWLIST = [
|
|
21379
|
+
// TEMP, TMP and TMPDIR are not passed: relocatedProfileEnv points them at the job's own temp dir.
|
|
21380
|
+
"PATH",
|
|
21381
|
+
"PATHEXT",
|
|
21382
|
+
"SystemRoot",
|
|
21383
|
+
"windir",
|
|
21384
|
+
"ComSpec",
|
|
21385
|
+
"LANG",
|
|
21386
|
+
// Non-secret OS variables shells and git expect.
|
|
21387
|
+
"SystemDrive",
|
|
21388
|
+
"ProgramFiles",
|
|
21389
|
+
"ProgramFiles(x86)",
|
|
21390
|
+
"ProgramW6432",
|
|
21391
|
+
"ProgramData",
|
|
21392
|
+
"CommonProgramFiles",
|
|
21393
|
+
// The runtime reaches Copilot through a proxy and a private CA with these; the shells inherit them (proxyCaEnv).
|
|
21394
|
+
"HTTPS_PROXY",
|
|
21395
|
+
"HTTP_PROXY",
|
|
21396
|
+
"NO_PROXY",
|
|
21397
|
+
"NODE_EXTRA_CA_CERTS",
|
|
21398
|
+
"SSL_CERT_FILE",
|
|
21399
|
+
"SSL_CERT_DIR",
|
|
21400
|
+
"NUMBER_OF_PROCESSORS",
|
|
21401
|
+
"PROCESSOR_ARCHITECTURE",
|
|
21402
|
+
"OS",
|
|
21403
|
+
"USERNAME",
|
|
21404
|
+
"USER",
|
|
21405
|
+
"LOGNAME",
|
|
21406
|
+
"TERM",
|
|
21407
|
+
"TZ",
|
|
21408
|
+
// A path, not a secret: the Windows sandbox needs it (MXC_REQUIRED_ENV) and grants %LOCALAPPDATA%\Programs read-only from it.
|
|
21409
|
+
// The HOST value is kept on purpose: per-user tools on PATH live under Programs. Lane-launched code that resolves host
|
|
21410
|
+
// paths from it (python-repl/paths.ts, utils/paths.ts getDataDir/getStateDir) finds them, but sandboxed writes there
|
|
21411
|
+
// are denied, so the effect is breakage or shared read state, never escalation.
|
|
21412
|
+
"LOCALAPPDATA"
|
|
21413
|
+
];
|
|
21414
|
+
TOKEN_PATTERN = /\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,})/g;
|
|
21623
21415
|
}
|
|
21624
21416
|
});
|
|
21625
21417
|
|
|
21626
21418
|
// src/smoke/process-utils.ts
|
|
21419
|
+
function killProcessTree2(pid, spawnSyncFn, platform = process.platform, killFn = (p, sig) => {
|
|
21420
|
+
process.kill(p, sig);
|
|
21421
|
+
}) {
|
|
21422
|
+
if (!pid) return;
|
|
21423
|
+
if (platform === "win32") {
|
|
21424
|
+
try {
|
|
21425
|
+
spawnSyncFn("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true, timeout: 1e4 });
|
|
21426
|
+
} catch {
|
|
21427
|
+
}
|
|
21428
|
+
return;
|
|
21429
|
+
}
|
|
21430
|
+
try {
|
|
21431
|
+
killFn(-pid, "SIGKILL");
|
|
21432
|
+
return;
|
|
21433
|
+
} catch {
|
|
21434
|
+
}
|
|
21435
|
+
try {
|
|
21436
|
+
killFn(pid, "SIGKILL");
|
|
21437
|
+
} catch {
|
|
21438
|
+
}
|
|
21439
|
+
}
|
|
21440
|
+
function hasExited(child) {
|
|
21441
|
+
return child.exitCode !== null && child.exitCode !== void 0 || child.signalCode !== null && child.signalCode !== void 0;
|
|
21442
|
+
}
|
|
21627
21443
|
var DEFAULT_MAX_OUTPUT;
|
|
21628
21444
|
var init_process_utils2 = __esm({
|
|
21629
21445
|
"src/smoke/process-utils.ts"() {
|
|
@@ -21636,9 +21452,9 @@ var init_process_utils2 = __esm({
|
|
|
21636
21452
|
function getRuntimePackageVersion() {
|
|
21637
21453
|
try {
|
|
21638
21454
|
const __filename2 = (0, import_url7.fileURLToPath)(importMetaUrl);
|
|
21639
|
-
const __dirname2 = (0,
|
|
21455
|
+
const __dirname2 = (0, import_path41.dirname)(__filename2);
|
|
21640
21456
|
for (let i = 0; i < 5; i++) {
|
|
21641
|
-
const candidate = (0,
|
|
21457
|
+
const candidate = (0, import_path41.join)(__dirname2, ...Array(i + 1).fill(".."), "package.json");
|
|
21642
21458
|
try {
|
|
21643
21459
|
const pkg = JSON.parse((0, import_fs37.readFileSync)(candidate, "utf-8"));
|
|
21644
21460
|
if (pkg.name && pkg.version) {
|
|
@@ -21660,18 +21476,18 @@ function getRuntimePackageVersion() {
|
|
|
21660
21476
|
}
|
|
21661
21477
|
return "unknown";
|
|
21662
21478
|
}
|
|
21663
|
-
var import_fs37,
|
|
21479
|
+
var import_fs37, import_path41, import_url7;
|
|
21664
21480
|
var init_version = __esm({
|
|
21665
21481
|
"src/lib/version.ts"() {
|
|
21666
21482
|
"use strict";
|
|
21667
21483
|
import_fs37 = require("fs");
|
|
21668
|
-
|
|
21484
|
+
import_path41 = require("path");
|
|
21669
21485
|
import_url7 = require("url");
|
|
21670
21486
|
}
|
|
21671
21487
|
});
|
|
21672
21488
|
|
|
21673
21489
|
// src/smoke/replay/redact.ts
|
|
21674
|
-
function userHomePatterns(win, pct,
|
|
21490
|
+
function userHomePatterns(win, pct, posix3, posixFlags) {
|
|
21675
21491
|
return [
|
|
21676
21492
|
// The separator spelling is captured once, so `\n` after an escaped `\\` is not taken for a tail separator.
|
|
21677
21493
|
// `\` doubles per JSON level, so any run of backslashes is a separator. The one after `Users` may be either
|
|
@@ -21680,7 +21496,7 @@ function userHomePatterns(win, pct, posix2, posixFlags) {
|
|
|
21680
21496
|
// Percent-encoded (`file:///c%3A/Users/...`, `C%3A%5CUsers%5C...`, `%2Fhome%2Fname`).
|
|
21681
21497
|
new RegExp(String.raw`(?<head>(?:\b[A-Za-z]%3A${PCT_SEP}Users|%2F(?:home|Users))${PCT_SEP}(?!<user>)${pct})(?:${PCT_SEP}${PCT_SEG})*`, "gi"),
|
|
21682
21498
|
// POSIX, Git Bash (`/c/Users/...`) and WSL (`/mnt/c/Users/...`).
|
|
21683
|
-
new RegExp(String.raw`(?<head>(?<![\w.$}-])\/(?:home|Users|(?:mnt\/)?[A-Za-z]\/Users)\/(?!<user>)${
|
|
21499
|
+
new RegExp(String.raw`(?<head>(?<![\w.$}-])\/(?:home|Users|(?:mnt\/)?[A-Za-z]\/Users)\/(?!<user>)${posix3})(?:\/${POSIX_SEG})*`, posixFlags)
|
|
21684
21500
|
];
|
|
21685
21501
|
}
|
|
21686
21502
|
function knownUserHomePatterns(user) {
|
|
@@ -22217,25 +22033,25 @@ function readJsonFile(path5, where) {
|
|
|
22217
22033
|
}
|
|
22218
22034
|
}
|
|
22219
22035
|
function readCassette(dir) {
|
|
22220
|
-
if ((0, import_fs38.existsSync)((0,
|
|
22036
|
+
if ((0, import_fs38.existsSync)((0, import_path42.join)(dir, REDACTION_FAILED_MARKER))) {
|
|
22221
22037
|
throw new CassetteFormatError(`${dir}: redaction gate failed for this cassette (${REDACTION_FAILED_MARKER} marker); re-record or fix it and re-run verify`);
|
|
22222
22038
|
}
|
|
22223
|
-
const manifestPath = (0,
|
|
22039
|
+
const manifestPath = (0, import_path42.join)(dir, MANIFEST_FILE);
|
|
22224
22040
|
if (!(0, import_fs38.existsSync)(manifestPath)) throw new CassetteFormatError(`${dir}: no ${MANIFEST_FILE}`);
|
|
22225
22041
|
const manifest = parseManifest(readJsonFile(manifestPath, MANIFEST_FILE));
|
|
22226
|
-
const interactionsPath = (0,
|
|
22042
|
+
const interactionsPath = (0, import_path42.join)(dir, INTERACTIONS_FILE);
|
|
22227
22043
|
const interactions = (0, import_fs38.existsSync)(interactionsPath) ? parseJsonl((0, import_fs38.readFileSync)(interactionsPath, "utf-8"), INTERACTIONS_FILE).map((v, i) => parseInteraction(v, `${INTERACTIONS_FILE}:${i + 1}`)) : [];
|
|
22228
22044
|
checkConsistency(manifest, interactions);
|
|
22229
22045
|
const cassette = { manifest, interactions };
|
|
22230
|
-
const eventsDir = (0,
|
|
22046
|
+
const eventsDir = (0, import_path42.join)(dir, EVENTS_DIR);
|
|
22231
22047
|
if ((0, import_fs38.existsSync)(eventsDir)) {
|
|
22232
22048
|
cassette.events = {};
|
|
22233
22049
|
for (const name of (0, import_fs38.readdirSync)(eventsDir).sort()) {
|
|
22234
22050
|
if (!name.endsWith(".jsonl")) continue;
|
|
22235
|
-
cassette.events[name.slice(0, -".jsonl".length)] = parseJsonl((0, import_fs38.readFileSync)((0,
|
|
22051
|
+
cassette.events[name.slice(0, -".jsonl".length)] = parseJsonl((0, import_fs38.readFileSync)((0, import_path42.join)(eventsDir, name), "utf-8"), `${EVENTS_DIR}/${name}`);
|
|
22236
22052
|
}
|
|
22237
22053
|
}
|
|
22238
|
-
const reportPath = (0,
|
|
22054
|
+
const reportPath = (0, import_path42.join)(dir, REPORT_FILE);
|
|
22239
22055
|
if ((0, import_fs38.existsSync)(reportPath)) cassette.report = readJsonFile(reportPath, REPORT_FILE);
|
|
22240
22056
|
return cassette;
|
|
22241
22057
|
}
|
|
@@ -22386,8 +22202,8 @@ function gateFiles(files, options = {}) {
|
|
|
22386
22202
|
}
|
|
22387
22203
|
function relativeFiles(root, current = root) {
|
|
22388
22204
|
return (0, import_fs38.readdirSync)(current, { withFileTypes: true }).flatMap((entry) => {
|
|
22389
|
-
const path5 = (0,
|
|
22390
|
-
return entry.isDirectory() ? relativeFiles(root, path5) : [(0,
|
|
22205
|
+
const path5 = (0, import_path42.join)(current, entry.name);
|
|
22206
|
+
return entry.isDirectory() ? relativeFiles(root, path5) : [(0, import_path42.relative)(root, path5).split("\\").join("/")];
|
|
22391
22207
|
});
|
|
22392
22208
|
}
|
|
22393
22209
|
function writeCassette(dir, cassette, options = {}) {
|
|
@@ -22397,26 +22213,26 @@ function writeCassette(dir, cassette, options = {}) {
|
|
|
22397
22213
|
if ((0, import_fs38.existsSync)(dir) && (0, import_fs38.readdirSync)(dir).length > 0 && !options.overwrite) {
|
|
22398
22214
|
throw new CassetteFormatError(`${dir}: not empty (pass overwrite to replace the recording)`);
|
|
22399
22215
|
}
|
|
22400
|
-
if ((0, import_fs38.existsSync)((0,
|
|
22216
|
+
if ((0, import_fs38.existsSync)((0, import_path42.join)(dir, REDACTION_FAILED_MARKER))) {
|
|
22401
22217
|
throw new CassetteFormatError(`${dir}: holds a ${REDACTION_FAILED_MARKER} marker; remove it after fixing the cassette`);
|
|
22402
22218
|
}
|
|
22403
22219
|
const stale = (0, import_fs38.existsSync)(dir) ? relativeFiles(dir).filter((rel) => !files.has(rel)) : [];
|
|
22404
22220
|
if (stale.length > 0) throw new CassetteFormatError(`${dir}: holds file(s) this recording does not replace: ${stale.join(", ")}; remove them first`);
|
|
22405
22221
|
const written = [];
|
|
22406
22222
|
for (const [rel, content] of files) {
|
|
22407
|
-
const path5 = (0,
|
|
22408
|
-
(0, import_fs38.mkdirSync)((0,
|
|
22223
|
+
const path5 = (0, import_path42.join)(dir, ...rel.split("/"));
|
|
22224
|
+
(0, import_fs38.mkdirSync)((0, import_path42.join)(path5, ".."), { recursive: true });
|
|
22409
22225
|
atomicWriteFileSync(path5, content);
|
|
22410
22226
|
written.push(path5);
|
|
22411
22227
|
}
|
|
22412
22228
|
return written;
|
|
22413
22229
|
}
|
|
22414
|
-
var import_fs38,
|
|
22230
|
+
var import_fs38, import_path42, CASSETTE_FORMAT, CASSETTE_VERSION, MANIFEST_FILE, INTERACTIONS_FILE, EVENTS_DIR, REPORT_FILE, REDACTION_FAILED_MARKER, GLOBAL_STREAM, CassetteFormatError, CassetteGateError, RESPONSE_KINDS, SAFE_ID, isRecord4, isStringMap, isCount, toJsonl, MAX_DECODE_DEPTH;
|
|
22415
22231
|
var init_cassette = __esm({
|
|
22416
22232
|
"src/smoke/replay/cassette.ts"() {
|
|
22417
22233
|
"use strict";
|
|
22418
22234
|
import_fs38 = require("fs");
|
|
22419
|
-
|
|
22235
|
+
import_path42 = require("path");
|
|
22420
22236
|
init_atomic_write();
|
|
22421
22237
|
init_redact();
|
|
22422
22238
|
CASSETTE_FORMAT = "omg-copilot-cassette";
|
|
@@ -22522,12 +22338,12 @@ function diffExcerpt(recorded, live) {
|
|
|
22522
22338
|
function liveKey(sessionId, agentId) {
|
|
22523
22339
|
return `${sessionId}\0${agentId ?? ""}`;
|
|
22524
22340
|
}
|
|
22525
|
-
var import_fs39,
|
|
22341
|
+
var import_fs39, import_path43, GLOBAL_STREAM2, MISS_STATUS, EXCERPT_CHARS, CLAIMS_DIR, SESSIONS_DIR, MISSES_FILE, DRIFT_FILE, SERVED_FILE, StreamPositions, ReplayMatcher;
|
|
22526
22342
|
var init_matcher = __esm({
|
|
22527
22343
|
"src/smoke/replay/matcher.ts"() {
|
|
22528
22344
|
"use strict";
|
|
22529
22345
|
import_fs39 = require("fs");
|
|
22530
|
-
|
|
22346
|
+
import_path43 = require("path");
|
|
22531
22347
|
init_append_no_follow();
|
|
22532
22348
|
GLOBAL_STREAM2 = "global";
|
|
22533
22349
|
MISS_STATUS = 418;
|
|
@@ -22540,7 +22356,7 @@ var init_matcher = __esm({
|
|
|
22540
22356
|
StreamPositions = class {
|
|
22541
22357
|
constructor(stateDir) {
|
|
22542
22358
|
this.stateDir = stateDir;
|
|
22543
|
-
(0, import_fs39.mkdirSync)((0,
|
|
22359
|
+
(0, import_fs39.mkdirSync)((0, import_path43.join)(stateDir, SESSIONS_DIR), { recursive: true });
|
|
22544
22360
|
}
|
|
22545
22361
|
sessionOrdinals = /* @__PURE__ */ new Map();
|
|
22546
22362
|
agentPaths = /* @__PURE__ */ new Map();
|
|
@@ -22572,11 +22388,11 @@ var init_matcher = __esm({
|
|
|
22572
22388
|
* sdk hosts.
|
|
22573
22389
|
*/
|
|
22574
22390
|
allocateOrdinal(sessionId) {
|
|
22575
|
-
const dir = (0,
|
|
22391
|
+
const dir = (0, import_path43.join)(this.stateDir, SESSIONS_DIR);
|
|
22576
22392
|
for (let n = (0, import_fs39.readdirSync)(dir).length + 1; ; n += 1) {
|
|
22577
22393
|
let fd;
|
|
22578
22394
|
try {
|
|
22579
|
-
fd = openAppendExclusive((0,
|
|
22395
|
+
fd = openAppendExclusive((0, import_path43.join)(dir, String(n)));
|
|
22580
22396
|
} catch (err) {
|
|
22581
22397
|
if (err.code === "EEXIST") continue;
|
|
22582
22398
|
throw err;
|
|
@@ -22609,11 +22425,11 @@ var init_matcher = __esm({
|
|
|
22609
22425
|
this.byStream.set(it.stream, list);
|
|
22610
22426
|
}
|
|
22611
22427
|
for (const list of this.byStream.values()) list.sort((a, b) => a.seq - b.seq);
|
|
22612
|
-
(0, import_fs39.mkdirSync)((0,
|
|
22428
|
+
(0, import_fs39.mkdirSync)((0, import_path43.join)(this.stateDir, CLAIMS_DIR), { recursive: true });
|
|
22613
22429
|
this.positions = new StreamPositions(this.stateDir);
|
|
22614
22430
|
for (const file of [MISSES_FILE, DRIFT_FILE, SERVED_FILE]) {
|
|
22615
22431
|
try {
|
|
22616
|
-
(0, import_fs39.closeSync)(openAppendExclusive((0,
|
|
22432
|
+
(0, import_fs39.closeSync)(openAppendExclusive((0, import_path43.join)(this.stateDir, file)));
|
|
22617
22433
|
} catch (err) {
|
|
22618
22434
|
if (err.code !== "EEXIST") throw err;
|
|
22619
22435
|
}
|
|
@@ -22713,7 +22529,7 @@ var init_matcher = __esm({
|
|
|
22713
22529
|
claim(stream, req) {
|
|
22714
22530
|
let fd;
|
|
22715
22531
|
try {
|
|
22716
|
-
fd = openAppendExclusive((0,
|
|
22532
|
+
fd = openAppendExclusive((0, import_path43.join)(this.stateDir, CLAIMS_DIR, stream.id));
|
|
22717
22533
|
} catch (err) {
|
|
22718
22534
|
if (err.code === "EEXIST") return false;
|
|
22719
22535
|
throw err;
|
|
@@ -22739,7 +22555,7 @@ var init_matcher = __esm({
|
|
|
22739
22555
|
for (const d of drift) this.append(DRIFT_FILE, d);
|
|
22740
22556
|
}
|
|
22741
22557
|
append(file, value) {
|
|
22742
|
-
if (!appendFileNoFollow((0,
|
|
22558
|
+
if (!appendFileNoFollow((0, import_path43.join)(this.stateDir, file), `${JSON.stringify(value)}
|
|
22743
22559
|
`)) {
|
|
22744
22560
|
throw new Error(`${file} is not a regular file`);
|
|
22745
22561
|
}
|
|
@@ -22802,7 +22618,7 @@ function readCassetteConfig(env) {
|
|
|
22802
22618
|
const state = env[CASSETTE_ENV.state];
|
|
22803
22619
|
if (!state) throw new CassetteConfigError(`${CASSETTE_ENV.mode}=${mode} needs ${CASSETTE_ENV.state}`);
|
|
22804
22620
|
if (mode === "record" && env.CI && env.CI !== "false") throw new CassetteConfigError("recording a cassette is refused under CI");
|
|
22805
|
-
if (mode === "record" && /[\\/]fixtures[\\/]cassettes(?:[\\/]|$)/i.test((0,
|
|
22621
|
+
if (mode === "record" && /[\\/]fixtures[\\/]cassettes(?:[\\/]|$)/i.test((0, import_path44.resolve)(dir))) {
|
|
22806
22622
|
throw new CassetteConfigError(`refusing to record into the fixtures dir ${dir}; record elsewhere and import`);
|
|
22807
22623
|
}
|
|
22808
22624
|
const match = env[CASSETTE_ENV.match];
|
|
@@ -22812,8 +22628,8 @@ function readCassetteConfig(env) {
|
|
|
22812
22628
|
const dirs = env[CASSETTE_ENV.dirs];
|
|
22813
22629
|
return {
|
|
22814
22630
|
mode,
|
|
22815
|
-
dir: (0,
|
|
22816
|
-
stateDir: (0,
|
|
22631
|
+
dir: (0, import_path44.resolve)(dir),
|
|
22632
|
+
stateDir: (0, import_path44.resolve)(state),
|
|
22817
22633
|
scenario: env[CASSETTE_ENV.scenario] || void 0,
|
|
22818
22634
|
...match ? { matchMode: match } : {},
|
|
22819
22635
|
...dirs ? { dirs: parseCassetteDirs(dirs) } : {}
|
|
@@ -22981,11 +22797,11 @@ function replayResponse(res, dirs) {
|
|
|
22981
22797
|
return new Response([204, 205, 304].includes(res.status) ? null : body, { status: res.status, headers });
|
|
22982
22798
|
}
|
|
22983
22799
|
function deferred() {
|
|
22984
|
-
let
|
|
22800
|
+
let resolve22;
|
|
22985
22801
|
const promise = new Promise((r) => {
|
|
22986
|
-
|
|
22802
|
+
resolve22 = r;
|
|
22987
22803
|
});
|
|
22988
|
-
return { promise, resolve:
|
|
22804
|
+
return { promise, resolve: resolve22 };
|
|
22989
22805
|
}
|
|
22990
22806
|
function createRecordingHandler(Base, recorderOf) {
|
|
22991
22807
|
class RecordingHandler extends Base {
|
|
@@ -23024,7 +22840,7 @@ function createReplayHandler(Base, replayerOf) {
|
|
|
23024
22840
|
return new ReplayHandler();
|
|
23025
22841
|
}
|
|
23026
22842
|
function loadReplayCassette(config) {
|
|
23027
|
-
const dir = config.scenario && !(0, import_fs40.existsSync)((0,
|
|
22843
|
+
const dir = config.scenario && !(0, import_fs40.existsSync)((0, import_path44.join)(config.dir, MANIFEST_FILE)) ? (0, import_path44.join)(config.dir, config.scenario) : config.dir;
|
|
23028
22844
|
const cassette = readCassette(dir);
|
|
23029
22845
|
if (cassette.manifest.platform !== process.platform) {
|
|
23030
22846
|
throw new CassetteConfigError(`${dir}: cassette recorded on ${cassette.manifest.platform}, cannot replay on ${process.platform}`);
|
|
@@ -23051,7 +22867,7 @@ function withCassette(loaded2, env = process.env, options = {}) {
|
|
|
23051
22867
|
const matchMode = options.matchMode ?? config.matchMode ?? "tolerant";
|
|
23052
22868
|
if (mode === "record") announceRecording(config);
|
|
23053
22869
|
const replayerFor = (scenario, stateDir) => {
|
|
23054
|
-
if (!scenario && !(0, import_fs40.existsSync)((0,
|
|
22870
|
+
if (!scenario && !(0, import_fs40.existsSync)((0, import_path44.join)(config.dir, MANIFEST_FILE))) return null;
|
|
23055
22871
|
const key = JSON.stringify([config.dir, stateDir, scenario, matchMode, dirs]);
|
|
23056
22872
|
const replayer = replayers.get(key) ?? new CassetteReplayer(loadReplayCassette({ ...config, scenario, stateDir }), stateDir, matchMode, dirs);
|
|
23057
22873
|
replayers.set(key, replayer);
|
|
@@ -23082,14 +22898,14 @@ function withCassette(loaded2, env = process.env, options = {}) {
|
|
|
23082
22898
|
const recorders = /* @__PURE__ */ new Map();
|
|
23083
22899
|
const recorder = (ctx) => {
|
|
23084
22900
|
const { scenario, stateDir } = target(ctx);
|
|
23085
|
-
if (!scenario && (0,
|
|
22901
|
+
if (!scenario && (0, import_path44.basename)(stateDir) === UNSCOPED_STATE_DIR) return null;
|
|
23086
22902
|
const existing = recorders.get(stateDir);
|
|
23087
22903
|
if (existing) return existing.rec;
|
|
23088
|
-
const part = (0,
|
|
22904
|
+
const part = (0, import_path44.join)(stateDir, RECORD_PARTS_DIR, `${process.pid}-${++recordParts}`);
|
|
23089
22905
|
const created = { rec: newRecorder(scenario, stateDir), part };
|
|
23090
22906
|
recorders.set(stateDir, created);
|
|
23091
22907
|
try {
|
|
23092
|
-
(0, import_fs40.mkdirSync)((0,
|
|
22908
|
+
(0, import_fs40.mkdirSync)((0, import_path44.dirname)(part), { recursive: true });
|
|
23093
22909
|
(0, import_fs40.writeFileSync)(`${part}${RECORD_STARTED_SUFFIX}`, `${process.pid}
|
|
23094
22910
|
`);
|
|
23095
22911
|
} catch {
|
|
@@ -23112,7 +22928,7 @@ function withCassette(loaded2, env = process.env, options = {}) {
|
|
|
23112
22928
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
23113
22929
|
errors.push(error);
|
|
23114
22930
|
try {
|
|
23115
|
-
(0, import_fs40.mkdirSync)((0,
|
|
22931
|
+
(0, import_fs40.mkdirSync)((0, import_path44.dirname)(part), { recursive: true });
|
|
23116
22932
|
(0, import_fs40.writeFileSync)(`${part}${RECORD_FAILED_SUFFIX}`, `${error.message}
|
|
23117
22933
|
`);
|
|
23118
22934
|
} catch {
|
|
@@ -23137,7 +22953,7 @@ function withCassette(loaded2, env = process.env, options = {}) {
|
|
|
23137
22953
|
}
|
|
23138
22954
|
setCassetteScenario(scenario, stateDir) {
|
|
23139
22955
|
const slot = this.cassetteSlot;
|
|
23140
|
-
const dir = (0,
|
|
22956
|
+
const dir = (0, import_path44.resolve)(stateDir);
|
|
23141
22957
|
const replayer = mode === "replay" ? replayerFor(scenario, dir) : null;
|
|
23142
22958
|
Object.assign(slot, { scenario, stateDir: dir, replayer });
|
|
23143
22959
|
}
|
|
@@ -23152,13 +22968,13 @@ function withCassette(loaded2, env = process.env, options = {}) {
|
|
|
23152
22968
|
module: { ...loaded2.module, CopilotClient: CassetteClient, RuntimeConnection }
|
|
23153
22969
|
};
|
|
23154
22970
|
}
|
|
23155
|
-
var import_fs40, import_os11,
|
|
22971
|
+
var import_fs40, import_os11, import_path44, REQUEST_HANDLER_MISSING, RECORD_PARTS_DIR, RECORD_FAILED_SUFFIX, RECORD_STARTED_SUFFIX, UNSCOPED_STATE_DIR, NO_SCENARIO_MISS, CassetteConfigError, isRecord5, DeltaTracker, WS_REFUSED, extraDenyLiterals, CassetteRecorder, CassetteReplayer, replayers, recordParts, announced;
|
|
23156
22972
|
var init_handler = __esm({
|
|
23157
22973
|
"src/smoke/replay/handler.ts"() {
|
|
23158
22974
|
"use strict";
|
|
23159
22975
|
import_fs40 = require("fs");
|
|
23160
22976
|
import_os11 = require("os");
|
|
23161
|
-
|
|
22977
|
+
import_path44 = require("path");
|
|
23162
22978
|
init_version();
|
|
23163
22979
|
init_copilot_session_env();
|
|
23164
22980
|
init_cassette();
|
|
@@ -23333,180 +23149,954 @@ var init_handler = __esm({
|
|
|
23333
23149
|
return result.kind === "miss" ? missResponse(result.body) : replayResponse(result.interaction.res, this.dirs);
|
|
23334
23150
|
}
|
|
23335
23151
|
};
|
|
23336
|
-
replayers = /* @__PURE__ */ new Map();
|
|
23337
|
-
recordParts = 0;
|
|
23338
|
-
announced = /* @__PURE__ */ new Set();
|
|
23339
|
-
}
|
|
23340
|
-
});
|
|
23341
|
-
|
|
23342
|
-
// src/smoke/replay/run.ts
|
|
23343
|
-
var import_fs41,
|
|
23344
|
-
var init_run = __esm({
|
|
23345
|
-
"src/smoke/replay/run.ts"() {
|
|
23346
|
-
"use strict";
|
|
23347
|
-
import_fs41 = require("fs");
|
|
23348
|
-
|
|
23349
|
-
init_copilot_session_env();
|
|
23350
|
-
init_cassette();
|
|
23351
|
-
init_handler();
|
|
23352
|
-
init_matcher();
|
|
23353
|
-
}
|
|
23354
|
-
});
|
|
23355
|
-
|
|
23356
|
-
// src/smoke/copilot-sdk-driver.ts
|
|
23357
|
-
function isSdkModule(mod) {
|
|
23358
|
-
const m = mod;
|
|
23359
|
-
return !!m && typeof m.CopilotClient === "function" && typeof m.RuntimeConnection?.forStdio === "function";
|
|
23360
|
-
}
|
|
23361
|
-
function readPkg(dir) {
|
|
23362
|
-
try {
|
|
23363
|
-
return JSON.parse((0, import_fs42.readFileSync)((0,
|
|
23364
|
-
} catch {
|
|
23365
|
-
return null;
|
|
23366
|
-
}
|
|
23367
|
-
}
|
|
23368
|
-
function versionAbove(file) {
|
|
23369
|
-
let dir = (0,
|
|
23370
|
-
for (let i = 0; i < 6; i++) {
|
|
23371
|
-
const pkg = readPkg(dir);
|
|
23372
|
-
if (pkg?.name === SDK_PACKAGE) return pkg.version ?? null;
|
|
23373
|
-
const parent = (0,
|
|
23374
|
-
if (parent === dir) break;
|
|
23375
|
-
dir = parent;
|
|
23376
|
-
}
|
|
23377
|
-
return null;
|
|
23378
|
-
}
|
|
23379
|
-
function nodeResolvedVersion() {
|
|
23380
|
-
const bases = [];
|
|
23381
|
-
try {
|
|
23382
|
-
bases.push(importMetaUrl);
|
|
23383
|
-
} catch {
|
|
23384
|
-
}
|
|
23385
|
-
if (typeof __filename !== "undefined") bases.push(__filename);
|
|
23386
|
-
for (const base of bases) {
|
|
23387
|
-
try {
|
|
23388
|
-
return versionAbove((0, import_module.createRequire)(base).resolve(SDK_PACKAGE));
|
|
23389
|
-
} catch {
|
|
23152
|
+
replayers = /* @__PURE__ */ new Map();
|
|
23153
|
+
recordParts = 0;
|
|
23154
|
+
announced = /* @__PURE__ */ new Set();
|
|
23155
|
+
}
|
|
23156
|
+
});
|
|
23157
|
+
|
|
23158
|
+
// src/smoke/replay/run.ts
|
|
23159
|
+
var import_fs41, import_path45;
|
|
23160
|
+
var init_run = __esm({
|
|
23161
|
+
"src/smoke/replay/run.ts"() {
|
|
23162
|
+
"use strict";
|
|
23163
|
+
import_fs41 = require("fs");
|
|
23164
|
+
import_path45 = require("path");
|
|
23165
|
+
init_copilot_session_env();
|
|
23166
|
+
init_cassette();
|
|
23167
|
+
init_handler();
|
|
23168
|
+
init_matcher();
|
|
23169
|
+
}
|
|
23170
|
+
});
|
|
23171
|
+
|
|
23172
|
+
// src/smoke/copilot-sdk-driver.ts
|
|
23173
|
+
function isSdkModule(mod) {
|
|
23174
|
+
const m = mod;
|
|
23175
|
+
return !!m && typeof m.CopilotClient === "function" && typeof m.RuntimeConnection?.forStdio === "function";
|
|
23176
|
+
}
|
|
23177
|
+
function readPkg(dir) {
|
|
23178
|
+
try {
|
|
23179
|
+
return JSON.parse((0, import_fs42.readFileSync)((0, import_path46.join)(dir, "package.json"), "utf-8"));
|
|
23180
|
+
} catch {
|
|
23181
|
+
return null;
|
|
23182
|
+
}
|
|
23183
|
+
}
|
|
23184
|
+
function versionAbove(file) {
|
|
23185
|
+
let dir = (0, import_path46.dirname)(file);
|
|
23186
|
+
for (let i = 0; i < 6; i++) {
|
|
23187
|
+
const pkg = readPkg(dir);
|
|
23188
|
+
if (pkg?.name === SDK_PACKAGE) return pkg.version ?? null;
|
|
23189
|
+
const parent = (0, import_path46.dirname)(dir);
|
|
23190
|
+
if (parent === dir) break;
|
|
23191
|
+
dir = parent;
|
|
23192
|
+
}
|
|
23193
|
+
return null;
|
|
23194
|
+
}
|
|
23195
|
+
function nodeResolvedVersion() {
|
|
23196
|
+
const bases = [];
|
|
23197
|
+
try {
|
|
23198
|
+
bases.push(importMetaUrl);
|
|
23199
|
+
} catch {
|
|
23200
|
+
}
|
|
23201
|
+
if (typeof __filename !== "undefined") bases.push(__filename);
|
|
23202
|
+
for (const base of bases) {
|
|
23203
|
+
try {
|
|
23204
|
+
return versionAbove((0, import_module.createRequire)(base).resolve(SDK_PACKAGE));
|
|
23205
|
+
} catch {
|
|
23206
|
+
}
|
|
23207
|
+
}
|
|
23208
|
+
return null;
|
|
23209
|
+
}
|
|
23210
|
+
function globalModuleRoots(env, platform = process.platform) {
|
|
23211
|
+
return platform === "win32" && env.APPDATA ? [(0, import_path46.join)(env.APPDATA, "npm", "node_modules")] : [];
|
|
23212
|
+
}
|
|
23213
|
+
function satisfiesSdkRange(version) {
|
|
23214
|
+
const m = /^(\d+)\.(\d+)\.(\d+)$/.exec(String(version ?? "").trim());
|
|
23215
|
+
const min = SDK_MIN_VERSION.split(".").map(Number);
|
|
23216
|
+
if (!m) return false;
|
|
23217
|
+
const [major, minor, patch] = [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
23218
|
+
if (major !== min[0]) return false;
|
|
23219
|
+
return minor > min[1] || minor === min[1] && patch >= min[2];
|
|
23220
|
+
}
|
|
23221
|
+
function insideDir(dir, file) {
|
|
23222
|
+
const real = (p) => {
|
|
23223
|
+
try {
|
|
23224
|
+
return import_fs42.realpathSync.native(p);
|
|
23225
|
+
} catch {
|
|
23226
|
+
return (0, import_path46.resolve)(p);
|
|
23227
|
+
}
|
|
23228
|
+
};
|
|
23229
|
+
const rel = (0, import_path46.relative)(real(dir), real((0, import_path46.resolve)(dir, file)));
|
|
23230
|
+
return rel !== "" && !rel.startsWith("..") && !(0, import_path46.isAbsolute)(rel);
|
|
23231
|
+
}
|
|
23232
|
+
function exportPath(target, condition) {
|
|
23233
|
+
if (typeof target === "string") return target;
|
|
23234
|
+
const cond = target?.[condition];
|
|
23235
|
+
if (typeof cond === "string") return cond;
|
|
23236
|
+
return typeof cond?.default === "string" ? cond.default : void 0;
|
|
23237
|
+
}
|
|
23238
|
+
function npmRootG(env, spawnSync8) {
|
|
23239
|
+
const res = process.platform === "win32" ? spawnSync8("npm root -g", { env, encoding: "utf8", timeout: 15e3, windowsHide: true, shell: true }) : spawnSync8("npm", ["root", "-g"], { env, encoding: "utf8", timeout: 15e3 });
|
|
23240
|
+
const out = String(res.stdout ?? "").trim();
|
|
23241
|
+
return res.status === 0 && out ? out : null;
|
|
23242
|
+
}
|
|
23243
|
+
async function importFromDir(dir) {
|
|
23244
|
+
const pkg = readPkg(dir);
|
|
23245
|
+
if (pkg?.name !== SDK_PACKAGE || !satisfiesSdkRange(pkg.version)) return null;
|
|
23246
|
+
const exp = pkg.exports && typeof pkg.exports === "object" ? pkg.exports["."] : pkg.exports;
|
|
23247
|
+
const esmEntry = exportPath(exp, "import") ?? pkg.main ?? "dist/index.js";
|
|
23248
|
+
const cjsEntry = exportPath(exp, "require") ?? pkg.main ?? "index.js";
|
|
23249
|
+
if (!insideDir(dir, esmEntry) || !insideDir(dir, cjsEntry)) return null;
|
|
23250
|
+
let mod;
|
|
23251
|
+
try {
|
|
23252
|
+
mod = await import((0, import_url8.pathToFileURL)((0, import_path46.resolve)(dir, esmEntry)).href);
|
|
23253
|
+
} catch {
|
|
23254
|
+
mod = (0, import_module.createRequire)((0, import_path46.join)(dir, "package.json"))((0, import_path46.resolve)(dir, cjsEntry));
|
|
23255
|
+
}
|
|
23256
|
+
return isSdkModule(mod) ? { module: mod, version: pkg.version ?? null, from: dir } : null;
|
|
23257
|
+
}
|
|
23258
|
+
function resolveShimTarget(shim, read = (p) => (0, import_fs42.readFileSync)(p, "utf-8"), exists = import_fs42.existsSync) {
|
|
23259
|
+
let text2;
|
|
23260
|
+
try {
|
|
23261
|
+
text2 = read(shim);
|
|
23262
|
+
} catch {
|
|
23263
|
+
return null;
|
|
23264
|
+
}
|
|
23265
|
+
const patterns = [
|
|
23266
|
+
/"%~?dp0%\\?([^"%*]+?\.(?:js|exe))"/i,
|
|
23267
|
+
// cmd-shim: "%dp0%\node_modules\...\loader.js"
|
|
23268
|
+
/\$basedir[\\/]([^"$*]+?\.(?:js|exe))"/i
|
|
23269
|
+
// ps1 shim: "$basedir/node_modules/.../loader.js"
|
|
23270
|
+
];
|
|
23271
|
+
for (const re of patterns) {
|
|
23272
|
+
const m = re.exec(text2);
|
|
23273
|
+
if (!m) continue;
|
|
23274
|
+
const target = (0, import_path46.resolve)((0, import_path46.dirname)(shim), m[1].replace(/\\/g, "/"));
|
|
23275
|
+
if (exists(target)) return target;
|
|
23276
|
+
}
|
|
23277
|
+
return null;
|
|
23278
|
+
}
|
|
23279
|
+
async function loadCopilotSdk(env = process.env, spawnSync8 = import_child_process10.spawnSync) {
|
|
23280
|
+
const found = await findCopilotSdk(env, spawnSync8);
|
|
23281
|
+
return found ? withCassette(found, env) : null;
|
|
23282
|
+
}
|
|
23283
|
+
async function findCopilotSdk(env, spawnSync8) {
|
|
23284
|
+
const spec = SDK_PACKAGE;
|
|
23285
|
+
try {
|
|
23286
|
+
const mod = await import(spec);
|
|
23287
|
+
if (isSdkModule(mod)) return { module: mod, version: nodeResolvedVersion(), from: "node resolution" };
|
|
23288
|
+
} catch {
|
|
23289
|
+
}
|
|
23290
|
+
const tried = /* @__PURE__ */ new Set();
|
|
23291
|
+
const tryRoot = async (root) => {
|
|
23292
|
+
if (!root || tried.has(root)) return null;
|
|
23293
|
+
tried.add(root);
|
|
23294
|
+
const dir = (0, import_path46.join)(root, ...SDK_PACKAGE.split("/"));
|
|
23295
|
+
if (!(0, import_fs42.existsSync)((0, import_path46.join)(dir, "package.json"))) return null;
|
|
23296
|
+
try {
|
|
23297
|
+
return await importFromDir(dir);
|
|
23298
|
+
} catch {
|
|
23299
|
+
return null;
|
|
23300
|
+
}
|
|
23301
|
+
};
|
|
23302
|
+
for (const root of globalModuleRoots(env)) {
|
|
23303
|
+
const hit = await tryRoot(root);
|
|
23304
|
+
if (hit) return hit;
|
|
23305
|
+
}
|
|
23306
|
+
return tryRoot(npmRootG(env, spawnSync8));
|
|
23307
|
+
}
|
|
23308
|
+
function withTimeout2(promise, ms, label) {
|
|
23309
|
+
let timer;
|
|
23310
|
+
return Promise.race([
|
|
23311
|
+
promise,
|
|
23312
|
+
new Promise((_, reject) => {
|
|
23313
|
+
timer = setTimeout(() => reject(new TimeoutError(`${label} timed out after ${ms} ms`)), ms);
|
|
23314
|
+
})
|
|
23315
|
+
]).finally(() => clearTimeout(timer));
|
|
23316
|
+
}
|
|
23317
|
+
function errText2(err) {
|
|
23318
|
+
return err instanceof Error ? err.message : String(err);
|
|
23319
|
+
}
|
|
23320
|
+
function runtimePid(client) {
|
|
23321
|
+
const pid = client.cliProcess?.pid;
|
|
23322
|
+
return typeof pid === "number" && pid > 0 ? pid : void 0;
|
|
23323
|
+
}
|
|
23324
|
+
function sdkProtocolMismatch(err) {
|
|
23325
|
+
const m = /SDK protocol version mismatch: SDK supports versions (\d+)-(\d+), but server (?:reports version (\d+)|does not report)/.exec(errText2(err));
|
|
23326
|
+
return m ? { sdkMin: Number(m[1]), sdkMax: Number(m[2]), server: m[3] === void 0 ? null : Number(m[3]) } : null;
|
|
23327
|
+
}
|
|
23328
|
+
function rethrowSdkStartError(err) {
|
|
23329
|
+
const m = sdkProtocolMismatch(err);
|
|
23330
|
+
if (!m) throw err;
|
|
23331
|
+
const sdk = m.sdkMin === m.sdkMax ? `protocol ${m.sdkMax}` : `protocols ${m.sdkMin}-${m.sdkMax}`;
|
|
23332
|
+
const olderCli = m.sdkMax === 3 ? `use @github/copilot <=${LAST_PROTOCOL3_CLI} (npm i -g @github/copilot@${LAST_PROTOCOL3_CLI})` : `use an older @github/copilot that speaks protocol ${m.sdkMax}`;
|
|
23333
|
+
const fix = m.server !== null && m.server > m.sdkMax ? `Update ${SDK_PACKAGE} when a version supporting protocol ${m.server} is available, or ${olderCli}.` : `Update the Copilot CLI (npm i -g @github/copilot) or use a ${SDK_PACKAGE} that matches it.`;
|
|
23334
|
+
throw new Error(
|
|
23335
|
+
`Copilot SDK/CLI protocol mismatch: ${SDK_PACKAGE} speaks ${sdk}, the Copilot CLI ${m.server === null ? "reports no protocol version" : `speaks protocol ${m.server}`}. ${fix}`,
|
|
23336
|
+
{ cause: err }
|
|
23337
|
+
);
|
|
23338
|
+
}
|
|
23339
|
+
async function probeSdkProtocol(loaded2, bin, opts = {}) {
|
|
23340
|
+
const stopMs = opts.stopTimeoutMs ?? PROBE_STOP_TIMEOUT_MS;
|
|
23341
|
+
const killTree = opts.killTree ?? ((pid) => killProcessTree2(pid, import_child_process10.spawnSync));
|
|
23342
|
+
const home = (0, import_fs42.mkdtempSync)((0, import_path46.join)((0, import_os12.tmpdir)(), "omg-sdk-probe-"));
|
|
23343
|
+
let client;
|
|
23344
|
+
try {
|
|
23345
|
+
const env = childEnv(allowlistSessionEnv(buildSessionEnv(opts.env ?? process.env, home, { session: false }), home));
|
|
23346
|
+
(0, import_fs42.mkdirSync)(env.XDG_CONFIG_HOME, { recursive: true });
|
|
23347
|
+
(0, import_fs42.mkdirSync)((0, import_path46.dirname)(env.GIT_CONFIG_GLOBAL), { recursive: true });
|
|
23348
|
+
(0, import_fs42.mkdirSync)(env.TEMP, { recursive: true });
|
|
23349
|
+
const { CopilotClient, RuntimeConnection } = loaded2.module;
|
|
23350
|
+
client = new CopilotClient({
|
|
23351
|
+
connection: RuntimeConnection.forStdio({ path: bin, args: [], env }),
|
|
23352
|
+
baseDirectory: home,
|
|
23353
|
+
workingDirectory: home
|
|
23354
|
+
});
|
|
23355
|
+
await withTimeout2(client.start().catch(rethrowSdkStartError), opts.startTimeoutMs ?? PROBE_START_TIMEOUT_MS, "client.start()");
|
|
23356
|
+
return null;
|
|
23357
|
+
} catch (err) {
|
|
23358
|
+
if (err instanceof TimeoutError) return `${PROBE_TIMEOUT_REASON}: ${err.message} (${bin})`;
|
|
23359
|
+
return sdkProtocolMismatch(err instanceof Error ? err.cause : void 0) ? errText2(err) : null;
|
|
23360
|
+
} finally {
|
|
23361
|
+
if (client) {
|
|
23362
|
+
const proc = client.cliProcess;
|
|
23363
|
+
const pid = runtimePid(client);
|
|
23364
|
+
try {
|
|
23365
|
+
await withTimeout2(client.stop(), stopMs, "client.stop()");
|
|
23366
|
+
} catch {
|
|
23367
|
+
try {
|
|
23368
|
+
await withTimeout2(client.forceStop?.() ?? Promise.resolve(), stopMs, "client.forceStop()");
|
|
23369
|
+
} catch {
|
|
23370
|
+
}
|
|
23371
|
+
}
|
|
23372
|
+
if (proc && pid && !hasExited(proc)) {
|
|
23373
|
+
try {
|
|
23374
|
+
killTree(pid);
|
|
23375
|
+
} catch {
|
|
23376
|
+
}
|
|
23377
|
+
}
|
|
23378
|
+
}
|
|
23379
|
+
try {
|
|
23380
|
+
(0, import_fs42.rmSync)(home, { recursive: true, force: true });
|
|
23381
|
+
} catch {
|
|
23382
|
+
}
|
|
23383
|
+
}
|
|
23384
|
+
}
|
|
23385
|
+
async function memoSdkProtocolProbe(loaded2, bin, probe = probeSdkProtocol) {
|
|
23386
|
+
let key;
|
|
23387
|
+
try {
|
|
23388
|
+
const real = (0, import_fs42.realpathSync)(bin);
|
|
23389
|
+
const st = (0, import_fs42.statSync)(real);
|
|
23390
|
+
key = `${real}\0${st.size}\0${st.mtimeMs}\0${loaded2.version ?? ""}`;
|
|
23391
|
+
} catch {
|
|
23392
|
+
return probe(loaded2, bin);
|
|
23393
|
+
}
|
|
23394
|
+
let pending = probeMemo.get(key);
|
|
23395
|
+
if (!pending) {
|
|
23396
|
+
pending = probe(loaded2, bin).catch(() => null);
|
|
23397
|
+
probeMemo.set(key, pending);
|
|
23398
|
+
}
|
|
23399
|
+
const result = await pending;
|
|
23400
|
+
if (result?.startsWith(PROBE_TIMEOUT_REASON)) probeMemo.delete(key);
|
|
23401
|
+
return result;
|
|
23402
|
+
}
|
|
23403
|
+
var import_child_process10, import_crypto11, import_fs42, import_module, import_os12, import_path46, import_url8, SDK_MIN_VERSION, TimeoutError, LAST_PROTOCOL3_CLI, PROBE_START_TIMEOUT_MS, PROBE_STOP_TIMEOUT_MS, PROBE_TIMEOUT_REASON, probeMemo;
|
|
23404
|
+
var init_copilot_sdk_driver = __esm({
|
|
23405
|
+
"src/smoke/copilot-sdk-driver.ts"() {
|
|
23406
|
+
"use strict";
|
|
23407
|
+
import_child_process10 = require("child_process");
|
|
23408
|
+
import_crypto11 = require("crypto");
|
|
23409
|
+
import_fs42 = require("fs");
|
|
23410
|
+
import_module = require("module");
|
|
23411
|
+
import_os12 = require("os");
|
|
23412
|
+
import_path46 = require("path");
|
|
23413
|
+
import_url8 = require("url");
|
|
23414
|
+
init_sandbox();
|
|
23415
|
+
init_copilot_session_eval();
|
|
23416
|
+
init_copilot_sdk_scenarios();
|
|
23417
|
+
init_process_utils2();
|
|
23418
|
+
init_copilot_session_env();
|
|
23419
|
+
init_windows_search();
|
|
23420
|
+
init_handler();
|
|
23421
|
+
init_run();
|
|
23422
|
+
SDK_MIN_VERSION = "1.0.16";
|
|
23423
|
+
TimeoutError = class extends Error {
|
|
23424
|
+
};
|
|
23425
|
+
LAST_PROTOCOL3_CLI = "1.0.112";
|
|
23426
|
+
PROBE_START_TIMEOUT_MS = 15e3;
|
|
23427
|
+
PROBE_STOP_TIMEOUT_MS = 5e3;
|
|
23428
|
+
PROBE_TIMEOUT_REASON = "copilot_sdk_probe_timeout";
|
|
23429
|
+
probeMemo = /* @__PURE__ */ new Map();
|
|
23430
|
+
}
|
|
23431
|
+
});
|
|
23432
|
+
|
|
23433
|
+
// src/smoke/copilot-binary.ts
|
|
23434
|
+
function resolveCopilotBinary(override, env, deps = {}) {
|
|
23435
|
+
const exists = deps.existsSync ?? import_fs43.existsSync;
|
|
23436
|
+
const resolve22 = deps.resolveExecutable ?? ((name) => resolveExecutable(name));
|
|
23437
|
+
const list = deps.readdirSync ?? ((p) => (0, import_fs43.readdirSync)(p));
|
|
23438
|
+
const platform = deps.platform ?? process.platform;
|
|
23439
|
+
if (override) {
|
|
23440
|
+
if (exists(override)) return { bin: override, source: "override" };
|
|
23441
|
+
const found = resolve22(override);
|
|
23442
|
+
return found ? { bin: found, source: "override" } : { bin: null, source: null };
|
|
23443
|
+
}
|
|
23444
|
+
const onPath = resolve22("copilot");
|
|
23445
|
+
if (onPath) return { bin: onPath, source: "path" };
|
|
23446
|
+
const envPath = env.COPILOT_CLI_PATH?.trim();
|
|
23447
|
+
if (envPath && exists(envPath)) return { bin: envPath, source: "COPILOT_CLI_PATH" };
|
|
23448
|
+
if (platform === "win32" && env.LOCALAPPDATA) {
|
|
23449
|
+
const packagesDir = (0, import_path47.join)(env.LOCALAPPDATA, "Microsoft", "WinGet", "Packages");
|
|
23450
|
+
try {
|
|
23451
|
+
for (const entry of list(packagesDir).filter((name) => /^GitHub\.Copilot/i.test(name)).sort()) {
|
|
23452
|
+
const candidate = (0, import_path47.join)(packagesDir, entry, "copilot.exe");
|
|
23453
|
+
if (exists(candidate)) return { bin: candidate, source: "winget" };
|
|
23454
|
+
}
|
|
23455
|
+
} catch {
|
|
23456
|
+
}
|
|
23457
|
+
}
|
|
23458
|
+
return { bin: null, source: null };
|
|
23459
|
+
}
|
|
23460
|
+
var import_fs43, import_path47;
|
|
23461
|
+
var init_copilot_binary = __esm({
|
|
23462
|
+
"src/smoke/copilot-binary.ts"() {
|
|
23463
|
+
"use strict";
|
|
23464
|
+
import_fs43 = require("fs");
|
|
23465
|
+
import_path47 = require("path");
|
|
23466
|
+
init_executable_resolution();
|
|
23467
|
+
}
|
|
23468
|
+
});
|
|
23469
|
+
|
|
23470
|
+
// src/copilot-run/model-catalogue.ts
|
|
23471
|
+
function redactCatalogueDetail(text2, env = process.env) {
|
|
23472
|
+
const clean = scrubTokens(text2, secretValues(env)).replace(/\s+/g, " ").trim();
|
|
23473
|
+
return clean.length > DETAIL_MAX_CHARS ? `${clean.slice(0, DETAIL_MAX_CHARS - 3)}...` : clean;
|
|
23474
|
+
}
|
|
23475
|
+
function copilotCatalogueCacheFile() {
|
|
23476
|
+
return (0, import_node_path16.join)(getGlobalOmcStateRoot(), "copilot-models-cache.json");
|
|
23477
|
+
}
|
|
23478
|
+
function catalogueFromListModels(entries) {
|
|
23479
|
+
if (!Array.isArray(entries)) return [];
|
|
23480
|
+
const ids = [];
|
|
23481
|
+
for (const entry of entries) {
|
|
23482
|
+
if (typeof entry?.id !== "string" || !entry.id) continue;
|
|
23483
|
+
if (entry.policy?.state === "disabled") continue;
|
|
23484
|
+
ids.push(entry.id);
|
|
23485
|
+
}
|
|
23486
|
+
return ids;
|
|
23487
|
+
}
|
|
23488
|
+
function readCatalogueCache(file, now, ttlMs = CATALOGUE_TTL_MS, failureTtlMs = CATALOGUE_FAILURE_TTL_MS) {
|
|
23489
|
+
let parsed;
|
|
23490
|
+
try {
|
|
23491
|
+
parsed = JSON.parse((0, import_node_fs15.readFileSync)(file, "utf-8"));
|
|
23492
|
+
} catch {
|
|
23493
|
+
return { fresh: null, stale: null };
|
|
23494
|
+
}
|
|
23495
|
+
const models = Array.isArray(parsed?.models) && parsed.models.every((m) => typeof m === "string") && parsed.models.length > 0 ? parsed.models : null;
|
|
23496
|
+
const fetchedAt = typeof parsed?.fetchedAt === "string" ? Date.parse(parsed.fetchedAt) : NaN;
|
|
23497
|
+
const failedAt = typeof parsed?.failedAt === "string" ? Date.parse(parsed.failedAt) : NaN;
|
|
23498
|
+
const isFresh = models !== null && Number.isFinite(fetchedAt) && now - fetchedAt >= 0 && now - fetchedAt < ttlMs;
|
|
23499
|
+
const recentFailure = Number.isFinite(failedAt) && now - failedAt >= 0 && now - failedAt < failureTtlMs ? typeof parsed.detail === "string" ? parsed.detail : "the last read failed" : void 0;
|
|
23500
|
+
return {
|
|
23501
|
+
fresh: isFresh ? models : null,
|
|
23502
|
+
stale: isFresh ? null : models,
|
|
23503
|
+
...typeof parsed.fetchedAt === "string" ? { fetchedAt: parsed.fetchedAt } : {},
|
|
23504
|
+
...recentFailure ? { recentFailure } : {}
|
|
23505
|
+
};
|
|
23506
|
+
}
|
|
23507
|
+
async function loadCopilotCatalogueWith(deps) {
|
|
23508
|
+
const now = deps.now();
|
|
23509
|
+
const cache = readCatalogueCache(deps.file, now, deps.ttlMs, deps.failureTtlMs);
|
|
23510
|
+
if (cache.fresh) return { catalogue: new Set(cache.fresh), source: "cache", detail: `cached in ${deps.file}` };
|
|
23511
|
+
const fromStale = (why2) => cache.stale ? { catalogue: new Set(cache.stale), source: "stale-cache", detail: `${why2}; using the stale cached catalogue` } : { catalogue: null, source: "none", detail: why2 };
|
|
23512
|
+
if (cache.recentFailure) return fromStale(`the Copilot model catalogue could not be read recently (${cache.recentFailure})`);
|
|
23513
|
+
let outcome;
|
|
23514
|
+
try {
|
|
23515
|
+
outcome = await deps.fetch();
|
|
23516
|
+
} catch (error) {
|
|
23517
|
+
outcome = { error: errText(error) };
|
|
23518
|
+
}
|
|
23519
|
+
if ("models" in outcome && outcome.models.length > 0) {
|
|
23520
|
+
try {
|
|
23521
|
+
(0, import_node_fs15.mkdirSync)((0, import_node_path16.dirname)(deps.file), { recursive: true });
|
|
23522
|
+
atomicWriteJsonSync(deps.file, { fetchedAt: new Date(deps.now()).toISOString(), models: outcome.models });
|
|
23523
|
+
} catch {
|
|
23524
|
+
}
|
|
23525
|
+
return { catalogue: new Set(outcome.models), source: "live", detail: `listModels() offers ${outcome.models.length} models` };
|
|
23526
|
+
}
|
|
23527
|
+
const why = redactCatalogueDetail("error" in outcome ? outcome.error : "listModels() returned no models", deps.env);
|
|
23528
|
+
const latest = readCatalogueCache(deps.file, deps.now(), deps.ttlMs, deps.failureTtlMs);
|
|
23529
|
+
if (latest.fresh) return { catalogue: new Set(latest.fresh), source: "cache", detail: `cached in ${deps.file}` };
|
|
23530
|
+
if (latest.stale && latest.fetchedAt !== cache.fetchedAt) {
|
|
23531
|
+
return { catalogue: new Set(latest.stale), source: "stale-cache", detail: `the Copilot model catalogue could not be read (${why}); using the stale cached catalogue` };
|
|
23532
|
+
}
|
|
23533
|
+
try {
|
|
23534
|
+
(0, import_node_fs15.mkdirSync)((0, import_node_path16.dirname)(deps.file), { recursive: true });
|
|
23535
|
+
atomicWriteJsonSync(deps.file, {
|
|
23536
|
+
...cache.stale ? { fetchedAt: cache.fetchedAt, models: cache.stale } : {},
|
|
23537
|
+
failedAt: new Date(now).toISOString(),
|
|
23538
|
+
detail: why
|
|
23539
|
+
});
|
|
23540
|
+
} catch {
|
|
23541
|
+
}
|
|
23542
|
+
return fromStale(`the Copilot model catalogue could not be read (${why})`);
|
|
23543
|
+
}
|
|
23544
|
+
function readCopilotCatalogueCacheOnly(file, now) {
|
|
23545
|
+
const cache = readCatalogueCache(file, now);
|
|
23546
|
+
if (cache.fresh) return { catalogue: new Set(cache.fresh), source: "cache", detail: `cached in ${file}` };
|
|
23547
|
+
if (cache.stale) return { catalogue: new Set(cache.stale), source: "stale-cache", detail: `stale cache in ${file}` };
|
|
23548
|
+
return { catalogue: null, source: "none", detail: `no cached Copilot model catalogue in ${file}` };
|
|
23549
|
+
}
|
|
23550
|
+
function defaultFetchDeps() {
|
|
23551
|
+
const env = process.env;
|
|
23552
|
+
return {
|
|
23553
|
+
env,
|
|
23554
|
+
platform: process.platform,
|
|
23555
|
+
loadSdk: () => loadCopilotSdk(env, cappedSpawnSync),
|
|
23556
|
+
resolveBin: () => resolveCopilotBinary(void 0, env).bin,
|
|
23557
|
+
userConfigDir: () => getCopilotConfigDir(),
|
|
23558
|
+
killTree: (pid) => killProcessTree2(pid, import_node_child_process8.spawnSync),
|
|
23559
|
+
tmpRoot: (0, import_node_os4.tmpdir)()
|
|
23560
|
+
};
|
|
23561
|
+
}
|
|
23562
|
+
async function stopCatalogueClient(client, killTree, boundMs) {
|
|
23563
|
+
const end = Date.now() + boundMs;
|
|
23564
|
+
try {
|
|
23565
|
+
await withTimeout(Promise.resolve().then(() => client.stop()), boundMs, "client.stop()");
|
|
23566
|
+
} catch {
|
|
23567
|
+
try {
|
|
23568
|
+
await withTimeout(Promise.resolve().then(() => client.forceStop?.()), Math.max(1, end - Date.now()), "client.forceStop()");
|
|
23569
|
+
} catch {
|
|
23570
|
+
}
|
|
23571
|
+
}
|
|
23572
|
+
const proc = client.cliProcess;
|
|
23573
|
+
const pid = runtimePid(client);
|
|
23574
|
+
if (proc && pid && !hasExited(proc)) {
|
|
23575
|
+
try {
|
|
23576
|
+
killTree(pid);
|
|
23577
|
+
} catch {
|
|
23578
|
+
}
|
|
23579
|
+
}
|
|
23580
|
+
}
|
|
23581
|
+
function sweepStaleJobDirs(jobRoot) {
|
|
23582
|
+
try {
|
|
23583
|
+
for (const name of (0, import_node_fs15.readdirSync)(jobRoot)) {
|
|
23584
|
+
if (!name.startsWith("list-")) continue;
|
|
23585
|
+
const dir = (0, import_node_path16.join)(jobRoot, name);
|
|
23586
|
+
try {
|
|
23587
|
+
if (Date.now() - (0, import_node_fs15.statSync)(dir).mtimeMs > STALE_JOB_DIR_MS) (0, import_node_fs15.rmSync)(dir, { recursive: true, force: true });
|
|
23588
|
+
} catch {
|
|
23589
|
+
}
|
|
23590
|
+
}
|
|
23591
|
+
} catch {
|
|
23592
|
+
}
|
|
23593
|
+
}
|
|
23594
|
+
async function fetchCopilotCatalogue(opts = {}) {
|
|
23595
|
+
hardenWindowsExeSearch();
|
|
23596
|
+
const deps = { ...defaultFetchDeps(), ...opts.deps };
|
|
23597
|
+
const jobRoot = (0, import_node_path16.join)(deps.tmpRoot, "omg-model-catalogue");
|
|
23598
|
+
sweepStaleJobDirs(jobRoot);
|
|
23599
|
+
const jobHome = (0, import_node_path16.join)(jobRoot, `list-${(0, import_node_crypto10.randomBytes)(4).toString("hex")}`);
|
|
23600
|
+
const workDir = (0, import_node_path16.join)(jobHome, "work");
|
|
23601
|
+
let client = null;
|
|
23602
|
+
let cancelled = false;
|
|
23603
|
+
const read = async () => {
|
|
23604
|
+
(0, import_node_fs15.mkdirSync)(workDir, { recursive: true });
|
|
23605
|
+
const loaded2 = await deps.loadSdk().catch(() => null);
|
|
23606
|
+
if (cancelled) return { error: "cancelled" };
|
|
23607
|
+
if (!loaded2) return { error: `@github/copilot-sdk is not installed or could not be loaded (${SDK_INSTALL_COMMAND})` };
|
|
23608
|
+
const found = opts.cliPath && (0, import_node_fs15.existsSync)(opts.cliPath) ? opts.cliPath : deps.resolveBin();
|
|
23609
|
+
const bin = found && deps.platform === "win32" && /\.(cmd|bat|ps1)$/i.test(found) ? resolveShimTarget(found) : found;
|
|
23610
|
+
if (!bin) return { error: "the copilot CLI was not found" };
|
|
23611
|
+
const ident = loginIdentity(deps.userConfigDir());
|
|
23612
|
+
(0, import_node_fs15.writeFileSync)((0, import_node_path16.join)(jobHome, "config.json"), `${JSON.stringify({ ...ident, trustedFolders: [workDir] }, null, 2)}
|
|
23613
|
+
`);
|
|
23614
|
+
const env = childEnv(allowlistSessionEnv(buildSessionEnv(deps.env, jobHome, { session: false, hasLogin: ident.loggedInUsers !== void 0 }), jobHome));
|
|
23615
|
+
(0, import_node_fs15.mkdirSync)(env.XDG_CONFIG_HOME, { recursive: true });
|
|
23616
|
+
(0, import_node_fs15.mkdirSync)((0, import_node_path16.dirname)(env.GIT_CONFIG_GLOBAL), { recursive: true });
|
|
23617
|
+
(0, import_node_fs15.mkdirSync)(env.TEMP, { recursive: true });
|
|
23618
|
+
const { CopilotClient, RuntimeConnection } = loaded2.module;
|
|
23619
|
+
const c = new CopilotClient({
|
|
23620
|
+
connection: RuntimeConnection.forStdio({ path: bin, args: ["--max-ai-credits", String(RUNTIME_MIN_MAX_CREDITS)], env }),
|
|
23621
|
+
baseDirectory: jobHome,
|
|
23622
|
+
workingDirectory: workDir
|
|
23623
|
+
});
|
|
23624
|
+
client = c;
|
|
23625
|
+
await c.start().catch(rethrowSdkStartError);
|
|
23626
|
+
return { models: catalogueFromListModels(await c.listModels()) };
|
|
23627
|
+
};
|
|
23628
|
+
let result;
|
|
23629
|
+
try {
|
|
23630
|
+
result = await withTimeout(read(), opts.deadlineMs ?? FETCH_DEADLINE_MS, "reading the Copilot model catalogue");
|
|
23631
|
+
} catch (error) {
|
|
23632
|
+
result = { error: errText(error) };
|
|
23633
|
+
}
|
|
23634
|
+
cancelled = true;
|
|
23635
|
+
const started = client;
|
|
23636
|
+
const done = (async () => {
|
|
23637
|
+
if (started) await stopCatalogueClient(started, deps.killTree, opts.cleanupMs ?? CLEANUP_BOUND_MS);
|
|
23638
|
+
try {
|
|
23639
|
+
(0, import_node_fs15.rmSync)(jobHome, { recursive: true, force: true });
|
|
23640
|
+
} catch {
|
|
23641
|
+
}
|
|
23642
|
+
try {
|
|
23643
|
+
(0, import_node_fs15.rmdirSync)(jobRoot);
|
|
23644
|
+
} catch {
|
|
23645
|
+
}
|
|
23646
|
+
})();
|
|
23647
|
+
opts.onCleanup?.(done);
|
|
23648
|
+
return result;
|
|
23649
|
+
}
|
|
23650
|
+
function loadCopilotCatalogue() {
|
|
23651
|
+
memo ??= source.load().catch((error) => ({ catalogue: null, source: "none", detail: redactCatalogueDetail(errText(error)) }));
|
|
23652
|
+
return memo;
|
|
23653
|
+
}
|
|
23654
|
+
async function teamCopilotCatalogue(warn = (line) => console.warn(line)) {
|
|
23655
|
+
const result = await loadCopilotCatalogue();
|
|
23656
|
+
if (!result.catalogue && !warnedUnreadable) {
|
|
23657
|
+
warnedUnreadable = true;
|
|
23658
|
+
warn(`[omg] ${result.detail}; Copilot tier aliases use each tier's first confirmed model`);
|
|
23659
|
+
}
|
|
23660
|
+
return result.catalogue;
|
|
23661
|
+
}
|
|
23662
|
+
var import_node_child_process8, import_node_crypto10, import_node_fs15, import_node_os4, import_node_path16, CATALOGUE_TTL_MS, CATALOGUE_FAILURE_TTL_MS, FETCH_DEADLINE_MS, STALE_JOB_DIR_MS, CLEANUP_BOUND_MS, NPM_ROOT_TIMEOUT_MS, DETAIL_MAX_CHARS, cappedSpawnSync, defaultSource, source, memo, warnedUnreadable;
|
|
23663
|
+
var init_model_catalogue = __esm({
|
|
23664
|
+
"src/copilot-run/model-catalogue.ts"() {
|
|
23665
|
+
"use strict";
|
|
23666
|
+
import_node_child_process8 = require("node:child_process");
|
|
23667
|
+
import_node_crypto10 = require("node:crypto");
|
|
23668
|
+
import_node_fs15 = require("node:fs");
|
|
23669
|
+
import_node_os4 = require("node:os");
|
|
23670
|
+
import_node_path16 = require("node:path");
|
|
23671
|
+
init_atomic_write();
|
|
23672
|
+
init_paths();
|
|
23673
|
+
init_timeout();
|
|
23674
|
+
init_sandbox();
|
|
23675
|
+
init_copilot_sdk_driver();
|
|
23676
|
+
init_copilot_sdk_scenarios();
|
|
23677
|
+
init_copilot_session_env();
|
|
23678
|
+
init_process_utils2();
|
|
23679
|
+
init_windows_search();
|
|
23680
|
+
init_copilot_binary();
|
|
23681
|
+
init_config_dir();
|
|
23682
|
+
CATALOGUE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
23683
|
+
CATALOGUE_FAILURE_TTL_MS = 60 * 60 * 1e3;
|
|
23684
|
+
FETCH_DEADLINE_MS = 2e4;
|
|
23685
|
+
STALE_JOB_DIR_MS = 60 * 60 * 1e3;
|
|
23686
|
+
CLEANUP_BOUND_MS = 5e3;
|
|
23687
|
+
NPM_ROOT_TIMEOUT_MS = 3e3;
|
|
23688
|
+
DETAIL_MAX_CHARS = 300;
|
|
23689
|
+
cappedSpawnSync = ((command, a, b) => Array.isArray(a) ? (0, import_node_child_process8.spawnSync)(command, a, { ...b, timeout: NPM_ROOT_TIMEOUT_MS }) : (0, import_node_child_process8.spawnSync)(command, { ...a, timeout: NPM_ROOT_TIMEOUT_MS }));
|
|
23690
|
+
defaultSource = {
|
|
23691
|
+
load: () => loadCopilotCatalogueWith({ file: copilotCatalogueCacheFile(), now: Date.now, fetch: () => fetchCopilotCatalogue() }),
|
|
23692
|
+
readCached: () => readCopilotCatalogueCacheOnly(copilotCatalogueCacheFile(), Date.now())
|
|
23693
|
+
};
|
|
23694
|
+
source = defaultSource;
|
|
23695
|
+
warnedUnreadable = false;
|
|
23696
|
+
}
|
|
23697
|
+
});
|
|
23698
|
+
|
|
23699
|
+
// src/team/scaling.ts
|
|
23700
|
+
function scaleUpFenceBlocks(config) {
|
|
23701
|
+
const attempt = config.active_scale_up;
|
|
23702
|
+
if (!attempt) return false;
|
|
23703
|
+
if (attempt.phase === "committed") return false;
|
|
23704
|
+
return true;
|
|
23705
|
+
}
|
|
23706
|
+
var import_path48, import_promises17;
|
|
23707
|
+
var init_scaling = __esm({
|
|
23708
|
+
"src/team/scaling.ts"() {
|
|
23709
|
+
"use strict";
|
|
23710
|
+
import_path48 = require("path");
|
|
23711
|
+
import_promises17 = require("fs/promises");
|
|
23712
|
+
init_model_contract();
|
|
23713
|
+
init_model_catalogue();
|
|
23714
|
+
init_loader();
|
|
23715
|
+
init_host_detection();
|
|
23716
|
+
init_types();
|
|
23717
|
+
init_types2();
|
|
23718
|
+
init_role_router();
|
|
23719
|
+
init_team_ops();
|
|
23720
|
+
init_types3();
|
|
23721
|
+
init_monitor();
|
|
23722
|
+
init_tmux_session();
|
|
23723
|
+
init_herdr_session();
|
|
23724
|
+
init_state_paths();
|
|
23725
|
+
init_worker_bootstrap();
|
|
23726
|
+
init_sdk_transport();
|
|
23727
|
+
init_git_worktree();
|
|
23728
|
+
init_worktree_paths();
|
|
23729
|
+
init_team_owner_epoch();
|
|
23730
|
+
init_runtime_owner_client();
|
|
23731
|
+
init_worker_launch_ack();
|
|
23732
|
+
init_team_instance();
|
|
23733
|
+
}
|
|
23734
|
+
});
|
|
23735
|
+
|
|
23736
|
+
// src/team/recovery-saga.ts
|
|
23737
|
+
function failure(input, error, message, reservationsWritten = false) {
|
|
23738
|
+
return {
|
|
23739
|
+
outcome: "failed",
|
|
23740
|
+
committed: false,
|
|
23741
|
+
error,
|
|
23742
|
+
message,
|
|
23743
|
+
...reservationsWritten ? { reservationsWritten: true } : {},
|
|
23744
|
+
requestId: input.requestId,
|
|
23745
|
+
recoveryId: input.recoveryId,
|
|
23746
|
+
teamName: input.teamName,
|
|
23747
|
+
workerName: input.workerName,
|
|
23748
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
23749
|
+
};
|
|
23750
|
+
}
|
|
23751
|
+
async function runRecoverySaga(input, deps) {
|
|
23752
|
+
const persistPhase = (value, continuation, adoption, services2 = "not_started") => {
|
|
23753
|
+
writeRecoveryPhase(deps.cwd, { schema_version: 1, kind: "phase", request_id: input.requestId, recovery_id: input.recoveryId, team_name: input.teamName, worker_name: input.workerName, phase: value, continuation, adoption, services: services2, manifest: "not_started", updated_at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
23754
|
+
};
|
|
23755
|
+
const finalize = (result2, _continuation, _adoption, _services = "terminal_degraded") => result2;
|
|
23756
|
+
const liveness = await deps.getLiveness(input.teamName, input.workerName);
|
|
23757
|
+
const committedReplacement = liveness === "alive" ? await deps.isCommittedReplacement?.(input) ?? false : false;
|
|
23758
|
+
if (liveness === "unknown") return finalize(failure(input, "worker_liveness_unknown"), "none", "not_started");
|
|
23759
|
+
if (liveness === "alive" && !committedReplacement) {
|
|
23760
|
+
if (!input.originalPaneId?.trim()) return finalize(failure(input, "worker_liveness_unknown"), "none", "not_started");
|
|
23761
|
+
return finalize({ outcome: "already_running", committed: true, oldPaneId: null, newPaneId: input.originalPaneId, requeuedTaskIds: [], continuationSequenceByTask: {}, stateRevision: 0, activation: "active", manifestSync: "synced", servicesSync: "synced", warnings: [], requestId: input.requestId, recoveryId: input.recoveryId, teamName: input.teamName, workerName: input.workerName, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }, "none", "not_started", "synced");
|
|
23762
|
+
}
|
|
23763
|
+
if (!input.originalPaneId?.trim()) return finalize(failure(input, "worker_liveness_unknown"), "none", "not_started");
|
|
23764
|
+
const tasks = await deps.listOwnedInProgressTasks(input.teamName, input.workerName);
|
|
23765
|
+
if (tasks.length === 0) persistPhase("reserved", "none", "not_started");
|
|
23766
|
+
const checks = await Promise.all(tasks.map((task) => deps.validateCheckpoint(input.teamName, task)));
|
|
23767
|
+
const rejected = checks.find((check) => !check.ok);
|
|
23768
|
+
if (rejected) return finalize(failure(input, rejected.error), "selected", "not_started");
|
|
23769
|
+
persistPhase("reserved", tasks.length ? "selected" : "none", "not_started");
|
|
23770
|
+
const adoptionTokenHash = (0, import_node_crypto11.createHash)("sha256").update(input.adoptionToken).digest("hex");
|
|
23771
|
+
const sequences = {};
|
|
23772
|
+
for (const task of tasks) {
|
|
23773
|
+
const result2 = await deps.requeue(input, task.id, adoptionTokenHash);
|
|
23774
|
+
if (!result2.ok) return finalize(failure(input, result2.error, void 0, Object.keys(sequences).length > 0), "reserved", "not_started");
|
|
23775
|
+
sequences[task.id] = result2.sequence;
|
|
23776
|
+
try {
|
|
23777
|
+
persistPhase("requeued", "reserved", "not_started");
|
|
23778
|
+
} catch (error) {
|
|
23779
|
+
return finalize(failure(input, "invalid_persisted_state", error instanceof Error ? error.message : String(error), true), "reserved", "not_started");
|
|
23780
|
+
}
|
|
23781
|
+
}
|
|
23782
|
+
const pane = await deps.spawnGatedPane(input);
|
|
23783
|
+
if (!pane.ok) return finalize(failure(input, pane.error), tasks.length ? "reserved" : "none", "not_started");
|
|
23784
|
+
if (!pane.paneId.trim()) return finalize(failure(input, "spawn_failed"), tasks.length ? "reserved" : "none", "not_started");
|
|
23785
|
+
let persisted;
|
|
23786
|
+
if (pane.committed) {
|
|
23787
|
+
persisted = { stateRevision: pane.stateRevision ?? 0, manifestSync: pane.manifestSync ?? "repair_required" };
|
|
23788
|
+
} else {
|
|
23789
|
+
try {
|
|
23790
|
+
persisted = await deps.persistActive(input, pane.paneId);
|
|
23791
|
+
} catch (error) {
|
|
23792
|
+
await deps.killAttemptPane(pane.paneAttemptId);
|
|
23793
|
+
return finalize(failure(input, "config_commit_failed", error instanceof Error ? error.message : String(error)), tasks.length ? "reserved" : "none", "not_started");
|
|
23794
|
+
}
|
|
23795
|
+
}
|
|
23796
|
+
if (persisted.manifestSync !== "synced") {
|
|
23797
|
+
return finalize({ ...failure(input, "config_commit_failed", "Replacement config committed but manifest projection requires repair."), outcome: "commit_unknown" }, tasks.length ? "reserved" : "none", tasks.length ? "pending" : "not_started");
|
|
23798
|
+
}
|
|
23799
|
+
const activated = await deps.activatePane(input, pane.paneAttemptId);
|
|
23800
|
+
if (!activated.ok) {
|
|
23801
|
+
return finalize({ ...failure(input, activated.error), outcome: "commit_unknown", message: "Replacement was committed but activation remains pending." }, tasks.length ? "reserved" : "none", tasks.length ? "pending" : "not_started");
|
|
23802
|
+
}
|
|
23803
|
+
persistPhase("ready", tasks.length ? "reserved" : "none", tasks.length ? "pending" : "not_started");
|
|
23804
|
+
let continuations = [];
|
|
23805
|
+
if (tasks.length) {
|
|
23806
|
+
const adopted = await deps.adoptAll(input, { recoveryId: input.recoveryId, requestId: input.requestId, replacementGeneration: input.replacementGeneration, adoptionToken: input.adoptionToken }, tasks.map((task) => task.id));
|
|
23807
|
+
if (!adopted.ok) {
|
|
23808
|
+
return finalize({ ...failure(input, adopted.error), outcome: "commit_unknown", message: "Replacement was committed but continuation adoption remains pending." }, "reserved", "pending");
|
|
23809
|
+
}
|
|
23810
|
+
continuations = adopted.continuations;
|
|
23811
|
+
persistPhase("adopted", "adopted", "adopted");
|
|
23812
|
+
}
|
|
23813
|
+
const services = await deps.repairServices(input);
|
|
23814
|
+
if (services === "synced") {
|
|
23815
|
+
await deps.writeRun(input, pane.paneAttemptId, continuations);
|
|
23816
|
+
} else {
|
|
23817
|
+
persistPhase("services_pending", tasks.length ? "adopted" : "none", tasks.length ? "adopted" : "not_started", "repair_required");
|
|
23818
|
+
}
|
|
23819
|
+
const result = { outcome: "recovered", committed: true, oldPaneId: input.originalPaneId, newPaneId: pane.paneId, requeuedTaskIds: tasks.map((task) => task.id), continuationSequenceByTask: sequences, stateRevision: persisted.stateRevision, activation: services === "synced" ? "active" : "services_pending", manifestSync: persisted.manifestSync, servicesSync: services, warnings: services === "synced" ? [] : ["services_pending"], requestId: input.requestId, recoveryId: input.recoveryId, teamName: input.teamName, workerName: input.workerName, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
23820
|
+
return finalize(result, tasks.length ? "adopted" : "none", tasks.length ? "adopted" : "not_started", services);
|
|
23821
|
+
}
|
|
23822
|
+
var import_node_crypto11;
|
|
23823
|
+
var init_recovery_saga = __esm({
|
|
23824
|
+
"src/team/recovery-saga.ts"() {
|
|
23825
|
+
"use strict";
|
|
23826
|
+
import_node_crypto11 = require("node:crypto");
|
|
23827
|
+
init_recovery_request_store();
|
|
23828
|
+
}
|
|
23829
|
+
});
|
|
23830
|
+
|
|
23831
|
+
// src/team/worker-activation-gate.ts
|
|
23832
|
+
async function writeAtomic3(path5, value) {
|
|
23833
|
+
await (0, import_promises18.mkdir)((0, import_node_path17.dirname)(path5), { recursive: true });
|
|
23834
|
+
const temporary = `${path5}.tmp.${process.pid}.${Date.now()}`;
|
|
23835
|
+
await (0, import_promises18.writeFile)(temporary, JSON.stringify(value), "utf8");
|
|
23836
|
+
await (0, import_promises18.rename)(temporary, path5);
|
|
23837
|
+
}
|
|
23838
|
+
async function waitForRecoveryGateRecord(path5, expected, timeoutMs, pollIntervalMs = 100) {
|
|
23839
|
+
const deadline = Date.now() + timeoutMs;
|
|
23840
|
+
while (Date.now() < deadline) {
|
|
23841
|
+
try {
|
|
23842
|
+
const value = JSON.parse(await (0, import_promises18.readFile)(path5, "utf8"));
|
|
23843
|
+
if (value.recovery_id === expected.recovery_id && value.worker_name === expected.worker_name && value.replacement_generation === expected.replacement_generation && value.pane_attempt_id === expected.pane_attempt_id && value.launch_attempt_id === expected.launch_attempt_id && value.launch_nonce === expected.launch_nonce) return true;
|
|
23844
|
+
} catch {
|
|
23845
|
+
}
|
|
23846
|
+
await new Promise((resolve22) => setTimeout(resolve22, pollIntervalMs));
|
|
23847
|
+
}
|
|
23848
|
+
return false;
|
|
23849
|
+
}
|
|
23850
|
+
async function runWorkerActivationGate(gate) {
|
|
23851
|
+
if (gate.providerArgv.length === 0 || !gate.providerArgv[0]) return { outcome: "invalid_provider_argv" };
|
|
23852
|
+
const launchAttempt = gate.launchAttempt;
|
|
23853
|
+
const launchContext = launchAttempt?.context;
|
|
23854
|
+
if (!launchAttempt || launchContext?.kind !== "recovery" || launchAttempt.worker_name !== gate.workerName || launchContext.recovery_id !== gate.recoveryId || launchContext.replacement_generation !== gate.replacementGeneration || launchContext.pane_attempt_id !== gate.paneAttemptId) return { outcome: "superseded" };
|
|
23855
|
+
if (process.platform === "win32") return { outcome: "provider_cleanup_unverified" };
|
|
23856
|
+
const expected = {
|
|
23857
|
+
recovery_id: gate.recoveryId,
|
|
23858
|
+
worker_name: gate.workerName,
|
|
23859
|
+
replacement_generation: gate.replacementGeneration,
|
|
23860
|
+
pane_attempt_id: gate.paneAttemptId,
|
|
23861
|
+
launch_attempt_id: launchAttempt.attempt_id,
|
|
23862
|
+
launch_nonce: launchAttempt.nonce,
|
|
23863
|
+
written_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
23864
|
+
};
|
|
23865
|
+
const timeoutMs = gate.timeoutMs ?? 3e4;
|
|
23866
|
+
const pollIntervalMs = gate.pollIntervalMs ?? 100;
|
|
23867
|
+
await writeAtomic3(gate.readyPath, expected);
|
|
23868
|
+
if (!await waitForRecoveryGateRecord(gate.activatePath, expected, timeoutMs, pollIntervalMs)) return { outcome: "activation_timeout" };
|
|
23869
|
+
await writeAtomic3(`${gate.readyPath}.adoption-ready`, { ...expected, written_at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
23870
|
+
if (!await waitForRecoveryGateRecord(gate.runPath, expected, timeoutMs, pollIntervalMs)) return { outcome: "run_timeout" };
|
|
23871
|
+
const fenced = await withWorkerLaunchAttemptFence(launchAttempt, async () => {
|
|
23872
|
+
const {
|
|
23873
|
+
OMC_RECOVERY_GATE_SPEC: _recoveryGateSpec,
|
|
23874
|
+
OMC_RECOVERY_GATE_SPEC_B64: _encodedRecoveryGateSpec,
|
|
23875
|
+
[WORKER_LAUNCH_RECOVERY_GATE_CONTAINED_ENV]: containedByBootstrap,
|
|
23876
|
+
...providerProcessEnv
|
|
23877
|
+
} = process.env;
|
|
23878
|
+
const containedByDurableBootstrap = containedByBootstrap === "1";
|
|
23879
|
+
const providerEnv = { ...providerProcessEnv, ...gate.env };
|
|
23880
|
+
delete providerEnv[WORKER_LAUNCH_RECOVERY_GATE_CONTAINED_ENV];
|
|
23881
|
+
const invocation = await materializeProviderSpawnInvocation(buildProviderSpawnInvocation(gate.providerArgv, process.platform, providerEnv), {
|
|
23882
|
+
superviseProcessTree: true,
|
|
23883
|
+
completionIdentity: buildWorkerLaunchBootstrapSpec(
|
|
23884
|
+
launchAttempt,
|
|
23885
|
+
gate.providerArgv,
|
|
23886
|
+
gate.cwd,
|
|
23887
|
+
{ providerEnv }
|
|
23888
|
+
)
|
|
23889
|
+
});
|
|
23890
|
+
const child = (0, import_node_child_process9.spawn)(invocation.command, invocation.args, {
|
|
23891
|
+
cwd: gate.cwd,
|
|
23892
|
+
env: buildProviderSpawnEnvironment(providerEnv, invocation),
|
|
23893
|
+
stdio: "inherit",
|
|
23894
|
+
windowsVerbatimArguments: invocation.windowsVerbatimArguments,
|
|
23895
|
+
// A recovery gate already runs inside the durable worker-launch
|
|
23896
|
+
// bootstrap group. Keep the actual provider in that group so teardown's
|
|
23897
|
+
// group-absence proof covers the provider rather than only the gate.
|
|
23898
|
+
// Direct gate callers retain the pre-bootstrap detached cleanup path.
|
|
23899
|
+
detached: process.platform !== "win32" && !containedByDurableBootstrap
|
|
23900
|
+
});
|
|
23901
|
+
let settled = false;
|
|
23902
|
+
let providerPid;
|
|
23903
|
+
let providerStartIdentity = null;
|
|
23904
|
+
let providerProcessGroupId;
|
|
23905
|
+
let supervisedExitCode = null;
|
|
23906
|
+
let supervisorTimer;
|
|
23907
|
+
let terminationResult = null;
|
|
23908
|
+
let finishCompletion;
|
|
23909
|
+
const completion = new Promise((resolve22) => {
|
|
23910
|
+
const finish = async (result, terminal) => {
|
|
23911
|
+
if (settled) return;
|
|
23912
|
+
settled = true;
|
|
23913
|
+
if (supervisorTimer) clearInterval(supervisorTimer);
|
|
23914
|
+
try {
|
|
23915
|
+
await writeAtomic3(`${gate.runPath}.terminal`, {
|
|
23916
|
+
...expected,
|
|
23917
|
+
provider_pid: child.pid ?? null,
|
|
23918
|
+
...terminal,
|
|
23919
|
+
...providerProcessGroupId !== void 0 ? { process_group_id: providerProcessGroupId } : {},
|
|
23920
|
+
written_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
23921
|
+
});
|
|
23922
|
+
} catch {
|
|
23923
|
+
}
|
|
23924
|
+
await invocation.cleanup().catch(() => void 0);
|
|
23925
|
+
resolve22(result);
|
|
23926
|
+
};
|
|
23927
|
+
finishCompletion = finish;
|
|
23928
|
+
child.once("exit", async (exitCode, signal) => {
|
|
23929
|
+
const effectiveExitCode = supervisedExitCode ?? exitCode;
|
|
23930
|
+
const effectiveSignal = supervisedExitCode === null ? signal : null;
|
|
23931
|
+
const cleanupVerified = terminationResult ? await terminationResult === "terminated" : false;
|
|
23932
|
+
await finish(
|
|
23933
|
+
cleanupVerified ? { outcome: "ran", exitCode: effectiveExitCode, signal: effectiveSignal } : { outcome: "provider_cleanup_unverified" },
|
|
23934
|
+
{
|
|
23935
|
+
outcome: cleanupVerified ? "exit" : "cleanup_unverified",
|
|
23936
|
+
cleanup_verified: cleanupVerified,
|
|
23937
|
+
exit_code: effectiveExitCode,
|
|
23938
|
+
signal: effectiveSignal
|
|
23939
|
+
}
|
|
23940
|
+
);
|
|
23941
|
+
});
|
|
23942
|
+
child.once("error", () => {
|
|
23943
|
+
void finish({ outcome: "provider_spawn_failed" }, { outcome: "error", cleanup_verified: false });
|
|
23944
|
+
});
|
|
23945
|
+
});
|
|
23946
|
+
const terminateProvider = async () => {
|
|
23947
|
+
if (settled) return true;
|
|
23948
|
+
if (providerPid && providerStartIdentity) {
|
|
23949
|
+
terminationResult ??= terminateOwnedProcessTree({
|
|
23950
|
+
pid: providerPid,
|
|
23951
|
+
expectedStartIdentity: providerStartIdentity,
|
|
23952
|
+
deadlineAt: new Date(Date.now() + 2e3).toISOString(),
|
|
23953
|
+
force: true
|
|
23954
|
+
});
|
|
23955
|
+
const terminated = await terminationResult === "terminated";
|
|
23956
|
+
const completed2 = await new Promise((resolve22) => {
|
|
23957
|
+
const timer = setTimeout(() => resolve22(false), 2e3);
|
|
23958
|
+
void completion.then((result) => {
|
|
23959
|
+
clearTimeout(timer);
|
|
23960
|
+
resolve22(result.outcome !== "provider_cleanup_unverified");
|
|
23961
|
+
});
|
|
23962
|
+
});
|
|
23963
|
+
return terminated && completed2;
|
|
23964
|
+
}
|
|
23965
|
+
try {
|
|
23966
|
+
if (child.pid && process.platform !== "win32") {
|
|
23967
|
+
try {
|
|
23968
|
+
process.kill(-child.pid, "SIGKILL");
|
|
23969
|
+
} catch {
|
|
23970
|
+
child.kill("SIGKILL");
|
|
23971
|
+
}
|
|
23972
|
+
} else {
|
|
23973
|
+
child.kill("SIGKILL");
|
|
23974
|
+
}
|
|
23975
|
+
} catch {
|
|
23976
|
+
}
|
|
23977
|
+
const completed = await new Promise((resolve22) => {
|
|
23978
|
+
const timer = setTimeout(() => resolve22(false), 2e3);
|
|
23979
|
+
void completion.then(() => {
|
|
23980
|
+
clearTimeout(timer);
|
|
23981
|
+
resolve22(true);
|
|
23982
|
+
});
|
|
23983
|
+
if (settled) {
|
|
23984
|
+
clearTimeout(timer);
|
|
23985
|
+
resolve22(true);
|
|
23986
|
+
}
|
|
23987
|
+
});
|
|
23988
|
+
return completed;
|
|
23989
|
+
};
|
|
23990
|
+
const cleanupSignals = ["SIGHUP", "SIGINT", "SIGTERM"];
|
|
23991
|
+
const onGateSignal = () => {
|
|
23992
|
+
void terminateProvider();
|
|
23993
|
+
};
|
|
23994
|
+
const ownsSignalLifecycle = Boolean(process.env.OMC_RECOVERY_GATE_SPEC || process.env.OMC_RECOVERY_GATE_SPEC_B64);
|
|
23995
|
+
if (ownsSignalLifecycle) {
|
|
23996
|
+
for (const signal of cleanupSignals) process.once(signal, onGateSignal);
|
|
23997
|
+
void completion.finally(() => {
|
|
23998
|
+
for (const signal of cleanupSignals) process.removeListener(signal, onGateSignal);
|
|
23999
|
+
});
|
|
23390
24000
|
}
|
|
23391
|
-
|
|
23392
|
-
|
|
23393
|
-
|
|
23394
|
-
|
|
23395
|
-
|
|
23396
|
-
|
|
23397
|
-
|
|
23398
|
-
|
|
23399
|
-
const min = SDK_MIN_VERSION.split(".").map(Number);
|
|
23400
|
-
if (!m) return false;
|
|
23401
|
-
const [major, minor, patch] = [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
23402
|
-
if (major !== min[0]) return false;
|
|
23403
|
-
return minor > min[1] || minor === min[1] && patch >= min[2];
|
|
23404
|
-
}
|
|
23405
|
-
function insideDir(dir, file) {
|
|
23406
|
-
const real = (p) => {
|
|
23407
|
-
try {
|
|
23408
|
-
return import_fs42.realpathSync.native(p);
|
|
23409
|
-
} catch {
|
|
23410
|
-
return (0, import_path47.resolve)(p);
|
|
24001
|
+
const spawned = await new Promise((resolve22) => {
|
|
24002
|
+
child.once("spawn", () => resolve22(true));
|
|
24003
|
+
child.once("error", () => resolve22(false));
|
|
24004
|
+
});
|
|
24005
|
+
if (!spawned) {
|
|
24006
|
+
const failed = await completion;
|
|
24007
|
+
await invocation.cleanup();
|
|
24008
|
+
return failed.outcome === "provider_spawn_failed" ? { outcome: "provider_spawn_failed" } : failed;
|
|
23411
24009
|
}
|
|
23412
|
-
};
|
|
23413
|
-
const rel = (0, import_path47.relative)(real(dir), real((0, import_path47.resolve)(dir, file)));
|
|
23414
|
-
return rel !== "" && !rel.startsWith("..") && !(0, import_path47.isAbsolute)(rel);
|
|
23415
|
-
}
|
|
23416
|
-
function exportPath(target, condition) {
|
|
23417
|
-
if (typeof target === "string") return target;
|
|
23418
|
-
const cond = target?.[condition];
|
|
23419
|
-
if (typeof cond === "string") return cond;
|
|
23420
|
-
return typeof cond?.default === "string" ? cond.default : void 0;
|
|
23421
|
-
}
|
|
23422
|
-
function npmRootG(env, spawnSync7) {
|
|
23423
|
-
const res = process.platform === "win32" ? spawnSync7("npm root -g", { env, encoding: "utf8", timeout: 15e3, windowsHide: true, shell: true }) : spawnSync7("npm", ["root", "-g"], { env, encoding: "utf8", timeout: 15e3 });
|
|
23424
|
-
const out = String(res.stdout ?? "").trim();
|
|
23425
|
-
return res.status === 0 && out ? out : null;
|
|
23426
|
-
}
|
|
23427
|
-
async function importFromDir(dir) {
|
|
23428
|
-
const pkg = readPkg(dir);
|
|
23429
|
-
if (pkg?.name !== SDK_PACKAGE || !satisfiesSdkRange(pkg.version)) return null;
|
|
23430
|
-
const exp = pkg.exports && typeof pkg.exports === "object" ? pkg.exports["."] : pkg.exports;
|
|
23431
|
-
const esmEntry = exportPath(exp, "import") ?? pkg.main ?? "dist/index.js";
|
|
23432
|
-
const cjsEntry = exportPath(exp, "require") ?? pkg.main ?? "index.js";
|
|
23433
|
-
if (!insideDir(dir, esmEntry) || !insideDir(dir, cjsEntry)) return null;
|
|
23434
|
-
let mod;
|
|
23435
|
-
try {
|
|
23436
|
-
mod = await import((0, import_url8.pathToFileURL)((0, import_path47.resolve)(dir, esmEntry)).href);
|
|
23437
|
-
} catch {
|
|
23438
|
-
mod = (0, import_module.createRequire)((0, import_path47.join)(dir, "package.json"))((0, import_path47.resolve)(dir, cjsEntry));
|
|
23439
|
-
}
|
|
23440
|
-
return isSdkModule(mod) ? { module: mod, version: pkg.version ?? null, from: dir } : null;
|
|
23441
|
-
}
|
|
23442
|
-
function resolveShimTarget(shim, read = (p) => (0, import_fs42.readFileSync)(p, "utf-8"), exists = import_fs42.existsSync) {
|
|
23443
|
-
let text2;
|
|
23444
|
-
try {
|
|
23445
|
-
text2 = read(shim);
|
|
23446
|
-
} catch {
|
|
23447
|
-
return null;
|
|
23448
|
-
}
|
|
23449
|
-
const patterns = [
|
|
23450
|
-
/"%~?dp0%\\?([^"%*]+?\.(?:js|exe))"/i,
|
|
23451
|
-
// cmd-shim: "%dp0%\node_modules\...\loader.js"
|
|
23452
|
-
/\$basedir[\\/]([^"$*]+?\.(?:js|exe))"/i
|
|
23453
|
-
// ps1 shim: "$basedir/node_modules/.../loader.js"
|
|
23454
|
-
];
|
|
23455
|
-
for (const re of patterns) {
|
|
23456
|
-
const m = re.exec(text2);
|
|
23457
|
-
if (!m) continue;
|
|
23458
|
-
const target = (0, import_path47.resolve)((0, import_path47.dirname)(shim), m[1].replace(/\\/g, "/"));
|
|
23459
|
-
if (exists(target)) return target;
|
|
23460
|
-
}
|
|
23461
|
-
return null;
|
|
23462
|
-
}
|
|
23463
|
-
async function loadCopilotSdk(env = process.env, spawnSync7 = import_child_process10.spawnSync) {
|
|
23464
|
-
const found = await findCopilotSdk(env, spawnSync7);
|
|
23465
|
-
return found ? withCassette(found, env) : null;
|
|
23466
|
-
}
|
|
23467
|
-
async function findCopilotSdk(env, spawnSync7) {
|
|
23468
|
-
const spec = SDK_PACKAGE;
|
|
23469
|
-
try {
|
|
23470
|
-
const mod = await import(spec);
|
|
23471
|
-
if (isSdkModule(mod)) return { module: mod, version: nodeResolvedVersion(), from: "node resolution" };
|
|
23472
|
-
} catch {
|
|
23473
|
-
}
|
|
23474
|
-
const tried = /* @__PURE__ */ new Set();
|
|
23475
|
-
const tryRoot = async (root) => {
|
|
23476
|
-
if (!root || tried.has(root)) return null;
|
|
23477
|
-
tried.add(root);
|
|
23478
|
-
const dir = (0, import_path47.join)(root, ...SDK_PACKAGE.split("/"));
|
|
23479
|
-
if (!(0, import_fs42.existsSync)((0, import_path47.join)(dir, "package.json"))) return null;
|
|
23480
24010
|
try {
|
|
23481
|
-
|
|
24011
|
+
providerPid = child.pid;
|
|
24012
|
+
providerStartIdentity = providerPid ? getProcessStartIdentitySync(providerPid) : null;
|
|
24013
|
+
providerProcessGroupId = providerPid ? captureOwnedProcessGroup(providerPid)?.processGroupId : void 0;
|
|
24014
|
+
if (!providerPid || !providerStartIdentity || settled || !isProcessAlive(providerPid)) {
|
|
24015
|
+
if (!await terminateProvider()) return { outcome: "provider_cleanup_unverified" };
|
|
24016
|
+
return { outcome: "provider_spawn_failed" };
|
|
24017
|
+
}
|
|
24018
|
+
if (!providerProcessGroupId) {
|
|
24019
|
+
if (!await terminateProvider()) return { outcome: "provider_cleanup_unverified" };
|
|
24020
|
+
return { outcome: "provider_spawn_failed" };
|
|
24021
|
+
}
|
|
24022
|
+
if (containedByDurableBootstrap) {
|
|
24023
|
+
const gateProcessGroupId = captureOwnedProcessGroup(process.pid)?.processGroupId;
|
|
24024
|
+
if (!gateProcessGroupId || gateProcessGroupId !== providerProcessGroupId) {
|
|
24025
|
+
if (!await terminateProvider()) return { outcome: "provider_cleanup_unverified" };
|
|
24026
|
+
return { outcome: "provider_cleanup_unverified" };
|
|
24027
|
+
}
|
|
24028
|
+
}
|
|
24029
|
+
await new Promise((resolve22) => setTimeout(resolve22, 150));
|
|
24030
|
+
if (settled) return await completion;
|
|
24031
|
+
const reboundIdentity = getProcessStartIdentitySync(providerPid);
|
|
24032
|
+
if (!reboundIdentity || reboundIdentity !== providerStartIdentity || !isProcessAlive(providerPid)) {
|
|
24033
|
+
if (!await terminateProvider()) return { outcome: "provider_cleanup_unverified" };
|
|
24034
|
+
return { outcome: "provider_spawn_failed" };
|
|
24035
|
+
}
|
|
24036
|
+
if (invocation.completionPath && await (0, import_promises18.readFile)(invocation.completionPath, "utf8").then(() => true).catch(() => false)) {
|
|
24037
|
+
const exitCode = await readProviderCompletionExitCode(
|
|
24038
|
+
invocation.completionPath,
|
|
24039
|
+
invocation.completionBinding
|
|
24040
|
+
);
|
|
24041
|
+
if (exitCode !== void 0) supervisedExitCode = exitCode;
|
|
24042
|
+
if (!await terminateProvider()) return { outcome: "provider_cleanup_unverified" };
|
|
24043
|
+
return { outcome: "provider_spawn_failed" };
|
|
24044
|
+
}
|
|
24045
|
+
await writeAtomic3(`${gate.runPath}.launched`, {
|
|
24046
|
+
...expected,
|
|
24047
|
+
provider_pid: providerPid,
|
|
24048
|
+
provider_start_identity: providerStartIdentity,
|
|
24049
|
+
process_group_id: providerProcessGroupId,
|
|
24050
|
+
written_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24051
|
+
...invocation.completionPath ? { supervisor_completion_path: invocation.completionPath } : {}
|
|
24052
|
+
});
|
|
24053
|
+
if (invocation.completionPath) {
|
|
24054
|
+
let pollingCompletion = false;
|
|
24055
|
+
supervisorTimer = setInterval(() => {
|
|
24056
|
+
if (pollingCompletion || settled || !providerStartIdentity || !providerPid) return;
|
|
24057
|
+
pollingCompletion = true;
|
|
24058
|
+
void (0, import_promises18.readFile)(invocation.completionPath, "utf8").then(async () => {
|
|
24059
|
+
const exitCode = await readProviderCompletionExitCode(
|
|
24060
|
+
invocation.completionPath,
|
|
24061
|
+
invocation.completionBinding
|
|
24062
|
+
);
|
|
24063
|
+
if (exitCode === void 0) return;
|
|
24064
|
+
supervisedExitCode = exitCode;
|
|
24065
|
+
const cleaned = await terminateProvider();
|
|
24066
|
+
if (!cleaned && !settled) {
|
|
24067
|
+
await finishCompletion(
|
|
24068
|
+
{ outcome: "provider_cleanup_unverified" },
|
|
24069
|
+
{ outcome: "cleanup_unverified", cleanup_verified: false, exit_code: exitCode, signal: null }
|
|
24070
|
+
);
|
|
24071
|
+
}
|
|
24072
|
+
}).catch(() => void 0).finally(() => {
|
|
24073
|
+
pollingCompletion = false;
|
|
24074
|
+
});
|
|
24075
|
+
}, pollIntervalMs);
|
|
24076
|
+
supervisorTimer.unref();
|
|
24077
|
+
}
|
|
24078
|
+
return { completion };
|
|
23482
24079
|
} catch {
|
|
23483
|
-
return
|
|
24080
|
+
if (!await terminateProvider()) return { outcome: "provider_cleanup_unverified" };
|
|
24081
|
+
return { outcome: "provider_spawn_failed" };
|
|
23484
24082
|
}
|
|
23485
|
-
};
|
|
23486
|
-
|
|
23487
|
-
|
|
23488
|
-
if (
|
|
24083
|
+
});
|
|
24084
|
+
if (!fenced.ok) return { outcome: "superseded" };
|
|
24085
|
+
if ("completion" in fenced.value) {
|
|
24086
|
+
if (!fenced.value.completion) return { outcome: "provider_spawn_failed" };
|
|
24087
|
+
return await fenced.value.completion;
|
|
23489
24088
|
}
|
|
23490
|
-
return
|
|
24089
|
+
return fenced.value;
|
|
23491
24090
|
}
|
|
23492
|
-
var
|
|
23493
|
-
var
|
|
23494
|
-
"src/
|
|
24091
|
+
var import_node_child_process9, import_promises18, import_node_path17;
|
|
24092
|
+
var init_worker_activation_gate = __esm({
|
|
24093
|
+
"src/team/worker-activation-gate.ts"() {
|
|
23495
24094
|
"use strict";
|
|
23496
|
-
|
|
23497
|
-
|
|
23498
|
-
|
|
23499
|
-
|
|
23500
|
-
|
|
23501
|
-
import_path47 = require("path");
|
|
23502
|
-
import_url8 = require("url");
|
|
23503
|
-
init_sandbox();
|
|
23504
|
-
init_copilot_session_eval();
|
|
23505
|
-
init_copilot_sdk_scenarios();
|
|
23506
|
-
init_process_utils2();
|
|
23507
|
-
init_handler();
|
|
23508
|
-
init_run();
|
|
23509
|
-
SDK_MIN_VERSION = "1.0.16";
|
|
24095
|
+
import_node_child_process9 = require("node:child_process");
|
|
24096
|
+
import_promises18 = require("node:fs/promises");
|
|
24097
|
+
import_node_path17 = require("node:path");
|
|
24098
|
+
init_worker_launch_ack();
|
|
24099
|
+
init_process_utils();
|
|
23510
24100
|
}
|
|
23511
24101
|
});
|
|
23512
24102
|
|
|
@@ -23524,6 +24114,14 @@ function buildStartupInboxTrigger(cwd, teamName, workerName, attemptId, platform
|
|
|
23524
24114
|
if (platform !== "win32" || message.length <= 200) return message;
|
|
23525
24115
|
return `Read workers/${workerName}/inbox.md under the OMC_TEAM_STATE_ROOT environment variable; execute now, report concrete progress.${suffix}`;
|
|
23526
24116
|
}
|
|
24117
|
+
async function resolveSdkWorkerModel(sdkModel, model) {
|
|
24118
|
+
if (sdkModel !== void 0) return sdkModel;
|
|
24119
|
+
if (!model) return void 0;
|
|
24120
|
+
const catalogue = copilotTierModels(model).length > 0 ? await teamCopilotCatalogue() : null;
|
|
24121
|
+
const resolved = resolveCopilotModel(model, catalogue);
|
|
24122
|
+
if (!resolved.model && resolved.tier) warnUnavailableCopilotTier(resolved.tier);
|
|
24123
|
+
return resolved.model;
|
|
24124
|
+
}
|
|
23527
24125
|
function hasRequiredRecoveryPaneIdentities(result) {
|
|
23528
24126
|
if (result.outcome !== "recovered" && result.outcome !== "already_running")
|
|
23529
24127
|
return true;
|
|
@@ -23744,7 +24342,7 @@ async function reconcileCommittedTeamServices(config, cwd) {
|
|
|
23744
24342
|
}
|
|
23745
24343
|
}
|
|
23746
24344
|
function resolveLeaderBranch(cwd) {
|
|
23747
|
-
const out = (0,
|
|
24345
|
+
const out = (0, import_node_child_process10.execFileSync)("git", ["branch", "--show-current"], {
|
|
23748
24346
|
cwd,
|
|
23749
24347
|
encoding: "utf-8",
|
|
23750
24348
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -24069,7 +24667,7 @@ async function waitForStartupEvidenceBudget(hasEvidence, budgetMs, delayMs = WOR
|
|
|
24069
24667
|
const remainingMs = deadline - Date.now();
|
|
24070
24668
|
if (remainingMs <= 0) return false;
|
|
24071
24669
|
await new Promise(
|
|
24072
|
-
(
|
|
24670
|
+
(resolve22) => setTimeout(resolve22, Math.min(delayMs, remainingMs))
|
|
24073
24671
|
);
|
|
24074
24672
|
}
|
|
24075
24673
|
}
|
|
@@ -24270,10 +24868,27 @@ async function resolveTeamTransport(input) {
|
|
|
24270
24868
|
return pane(
|
|
24271
24869
|
`contract_roles:${[...new Set(input.explicitContractRoles)].join(",")}`
|
|
24272
24870
|
);
|
|
24273
|
-
|
|
24274
|
-
|
|
24871
|
+
const sdk = await input.sdkAvailable().catch(() => false);
|
|
24872
|
+
if (typeof sdk === "string")
|
|
24873
|
+
return pane(
|
|
24874
|
+
sdk.startsWith(PROBE_TIMEOUT_REASON) ? sdk : `copilot_sdk_protocol_mismatch: ${sdk}`
|
|
24875
|
+
);
|
|
24876
|
+
if (!sdk) return pane("copilot_sdk_not_installed");
|
|
24275
24877
|
return { transport: "sdk", requested };
|
|
24276
24878
|
}
|
|
24879
|
+
async function defaultSdkAvailable(deps = {}) {
|
|
24880
|
+
const loaded2 = await (deps.load ?? (() => loadCopilotSdk()))();
|
|
24881
|
+
if (!loaded2) return false;
|
|
24882
|
+
let found;
|
|
24883
|
+
try {
|
|
24884
|
+
found = (deps.resolveBin ?? (() => resolveValidatedBinaryPath("copilot")))();
|
|
24885
|
+
} catch {
|
|
24886
|
+
return true;
|
|
24887
|
+
}
|
|
24888
|
+
const bin = found && /\.(cmd|bat|ps1)$/i.test(found) ? resolveShimTarget(found) : found;
|
|
24889
|
+
if (!bin) return true;
|
|
24890
|
+
return await (deps.probe ?? memoSdkProtocolProbe)(loaded2, bin) ?? true;
|
|
24891
|
+
}
|
|
24277
24892
|
async function runBoundedLaunches(jobs, concurrency, launch, record) {
|
|
24278
24893
|
const width = Math.max(
|
|
24279
24894
|
1,
|
|
@@ -24300,7 +24915,7 @@ async function runBoundedLaunches(jobs, concurrency, launch, record) {
|
|
|
24300
24915
|
return { errors };
|
|
24301
24916
|
}
|
|
24302
24917
|
function inspectLeaderCheckoutForWorktrees(cwd) {
|
|
24303
|
-
const run = (args) => (0,
|
|
24918
|
+
const run = (args) => (0, import_node_child_process10.execFileSync)("git", args, {
|
|
24304
24919
|
cwd,
|
|
24305
24920
|
encoding: "utf-8",
|
|
24306
24921
|
stdio: ["ignore", "pipe", "ignore"],
|
|
@@ -24340,6 +24955,13 @@ function resolveSdkDefaultWorktreeMode(input) {
|
|
|
24340
24955
|
}
|
|
24341
24956
|
return { mode: "disabled" };
|
|
24342
24957
|
}
|
|
24958
|
+
function needsTeamCopilotCatalogue(assignments, sdkModelPinned) {
|
|
24959
|
+
if (sdkModelPinned) return false;
|
|
24960
|
+
for (const a of assignments) {
|
|
24961
|
+
if (a.agentType === "copilot" && typeof a.model === "string" && copilotTierModels(a.model).length > 0) return true;
|
|
24962
|
+
}
|
|
24963
|
+
return false;
|
|
24964
|
+
}
|
|
24343
24965
|
function resolveSdkTeamSettings(pluginCfg) {
|
|
24344
24966
|
const sdk = pluginCfg.team?.sdk ?? {};
|
|
24345
24967
|
const envNumber = (key) => {
|
|
@@ -24428,8 +25050,10 @@ async function spawnSdkV2Worker(opts, sdk) {
|
|
|
24428
25050
|
startupFailureReason: `sdk_copilot_shim_unresolved:${binary}`
|
|
24429
25051
|
};
|
|
24430
25052
|
}
|
|
24431
|
-
const
|
|
24432
|
-
|
|
25053
|
+
const model = await resolveSdkWorkerModel(
|
|
25054
|
+
sdk.model,
|
|
25055
|
+
opts.launchDescriptor.model
|
|
25056
|
+
);
|
|
24433
25057
|
const workerCwd = opts.workerCwd ?? opts.cwd;
|
|
24434
25058
|
const launch = await launchSdkHost({
|
|
24435
25059
|
leaderCwd: opts.cwd,
|
|
@@ -24926,8 +25550,8 @@ async function recordRecoveryPaneRollbackFailure(input, recoveryId, pending, rea
|
|
|
24926
25550
|
recordedAt
|
|
24927
25551
|
)
|
|
24928
25552
|
);
|
|
24929
|
-
const candidate = `${path5}.candidate.${process.pid}.${(0,
|
|
24930
|
-
await (0, import_promises19.mkdir)((0,
|
|
25553
|
+
const candidate = `${path5}.candidate.${process.pid}.${(0, import_node_crypto12.randomUUID)()}`;
|
|
25554
|
+
await (0, import_promises19.mkdir)((0, import_path49.join)(path5, ".."), { recursive: true });
|
|
24931
25555
|
const handle = await (0, import_promises19.open)(candidate, "wx", 384);
|
|
24932
25556
|
try {
|
|
24933
25557
|
await handle.writeFile(
|
|
@@ -24971,8 +25595,8 @@ async function recordUnaddressableRecoveryPaneFailure(input, recoveryId, paneAtt
|
|
|
24971
25595
|
recordedAt
|
|
24972
25596
|
)
|
|
24973
25597
|
);
|
|
24974
|
-
const candidate = `${path5}.candidate.${process.pid}.${(0,
|
|
24975
|
-
await (0, import_promises19.mkdir)((0,
|
|
25598
|
+
const candidate = `${path5}.candidate.${process.pid}.${(0, import_node_crypto12.randomUUID)()}`;
|
|
25599
|
+
await (0, import_promises19.mkdir)((0, import_path49.join)(path5, ".."), { recursive: true });
|
|
24976
25600
|
const handle = await (0, import_promises19.open)(candidate, "wx", 384);
|
|
24977
25601
|
const boundedSplit = split ? {
|
|
24978
25602
|
...split,
|
|
@@ -25369,11 +25993,11 @@ async function readOrCreateRecoveryAttempt(input, recoveryId, replacementGenerat
|
|
|
25369
25993
|
recovery_id: recoveryId,
|
|
25370
25994
|
worker_name: input.workerName,
|
|
25371
25995
|
replacement_generation: replacementGeneration,
|
|
25372
|
-
adoption_token: (0,
|
|
25996
|
+
adoption_token: (0, import_node_crypto12.randomUUID)(),
|
|
25373
25997
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
25374
25998
|
};
|
|
25375
|
-
await (0, import_promises19.mkdir)((0,
|
|
25376
|
-
const candidate = `${path5}.candidate.${process.pid}.${(0,
|
|
25999
|
+
await (0, import_promises19.mkdir)((0, import_path49.join)(path5, ".."), { recursive: true });
|
|
26000
|
+
const candidate = `${path5}.candidate.${process.pid}.${(0, import_node_crypto12.randomUUID)()}`;
|
|
25377
26001
|
const candidateHandle = await (0, import_promises19.open)(candidate, "wx", 384);
|
|
25378
26002
|
try {
|
|
25379
26003
|
await candidateHandle.writeFile(JSON.stringify(secret, null, 2), "utf8");
|
|
@@ -25402,14 +26026,14 @@ async function readOrCreateRecoveryAttempt(input, recoveryId, replacementGenerat
|
|
|
25402
26026
|
}
|
|
25403
26027
|
}
|
|
25404
26028
|
function waitForBootstrapRecoveryEvidence(delayMs, signal) {
|
|
25405
|
-
return new Promise((
|
|
26029
|
+
return new Promise((resolve22, reject) => {
|
|
25406
26030
|
if (signal?.aborted) {
|
|
25407
26031
|
reject(signal.reason ?? new Error("bootstrap_recovery_evidence_aborted"));
|
|
25408
26032
|
return;
|
|
25409
26033
|
}
|
|
25410
26034
|
const timer = setTimeout(() => {
|
|
25411
26035
|
signal?.removeEventListener("abort", onAbort);
|
|
25412
|
-
|
|
26036
|
+
resolve22();
|
|
25413
26037
|
}, delayMs);
|
|
25414
26038
|
const onAbort = () => {
|
|
25415
26039
|
clearTimeout(timer);
|
|
@@ -25478,7 +26102,7 @@ function isCanonicalBootstrapCandidate(value, expectedEpoch) {
|
|
|
25478
26102
|
if (!candidate || candidate.schema_version !== 1 || candidate.expected_epoch !== expectedEpoch || typeof candidate.request_id !== "string" || candidate.request_id.length === 0 || typeof candidate.recovery_id !== "string" || candidate.recovery_id.length === 0 || typeof candidate.team_name !== "string" || candidate.team_name.length === 0 || typeof candidate.worker_name !== "string" || candidate.worker_name.length === 0 || !isValidTeamInstanceId(candidate.instance_id) || typeof candidate.nonce !== "string" || candidate.nonce.length === 0 || typeof candidate.pid !== "number" || !Number.isSafeInteger(candidate.pid) || candidate.pid < 1 || typeof candidate.process_started_at !== "string" || candidate.process_started_at.length === 0 || typeof candidate.predecessor_epoch !== "number" || !Number.isSafeInteger(candidate.predecessor_epoch) || candidate.predecessor_epoch < 0 || candidate.expected_epoch !== candidate.predecessor_epoch + 1 || candidate.predecessor_epoch === 0 && (candidate.predecessor_nonce !== null || candidate.predecessor_pid !== null || candidate.predecessor_process_started_at !== null) || candidate.predecessor_epoch > 0 && (typeof candidate.predecessor_nonce !== "string" || candidate.predecessor_nonce.length === 0 || typeof candidate.predecessor_pid !== "number" || !Number.isSafeInteger(candidate.predecessor_pid) || candidate.predecessor_pid < 1 || typeof candidate.predecessor_process_started_at !== "string" || candidate.predecessor_process_started_at.length === 0) || typeof candidate.created_at !== "string" || !Number.isFinite(Date.parse(candidate.created_at)) || typeof candidate.payload_hash !== "string")
|
|
25479
26103
|
return false;
|
|
25480
26104
|
const { payload_hash, ...unsigned } = candidate;
|
|
25481
|
-
return (0,
|
|
26105
|
+
return (0, import_node_crypto12.createHash)("sha256").update(JSON.stringify(unsigned)).digest("hex") === payload_hash;
|
|
25482
26106
|
}
|
|
25483
26107
|
async function readRecoveryOwnerBootstrapCandidate(teamName, cwd, expectedEpoch, nonce) {
|
|
25484
26108
|
try {
|
|
@@ -25548,7 +26172,7 @@ async function isExactDeadOrphanBootstrapCandidate(teamName, cwd, input, config,
|
|
|
25548
26172
|
function isExactRecoverySidecar(value, task, input, active, replacementGeneration, adoptionToken) {
|
|
25549
26173
|
const sidecar = value;
|
|
25550
26174
|
const persisted = task.recovery_reservation ?? task.recovery_adoption;
|
|
25551
|
-
if (!sidecar || !persisted || sidecar.schema_version !== 1 || sidecar.recovery_id !== active.recovery_id || sidecar.request_id !== input.requestId || sidecar.task_id !== task.id || sidecar.old_owner !== input.workerName || typeof sidecar.old_task_version !== "number" || !Number.isSafeInteger(sidecar.old_task_version) || sidecar.old_task_version < 1 || typeof sidecar.old_claim_token !== "string" || sidecar.old_claim_token.length === 0 || typeof sidecar.old_claim_leased_until !== "string" || !Number.isFinite(Date.parse(sidecar.old_claim_leased_until)) || typeof sidecar.continuation_sequence !== "number" || !Number.isSafeInteger(sidecar.continuation_sequence) || sidecar.continuation_sequence < 1 || typeof sidecar.checkpoint_path !== "string" || sidecar.checkpoint_path.length === 0 || typeof sidecar.checkpoint_hash !== "string" || !/^[a-f0-9]{64}$/.test(sidecar.checkpoint_hash) || sidecar.replacement_worker !== input.workerName || sidecar.replacement_generation !== replacementGeneration || sidecar.adoption_token_hash !== (0,
|
|
26175
|
+
if (!sidecar || !persisted || sidecar.schema_version !== 1 || sidecar.recovery_id !== active.recovery_id || sidecar.request_id !== input.requestId || sidecar.task_id !== task.id || sidecar.old_owner !== input.workerName || typeof sidecar.old_task_version !== "number" || !Number.isSafeInteger(sidecar.old_task_version) || sidecar.old_task_version < 1 || typeof sidecar.old_claim_token !== "string" || sidecar.old_claim_token.length === 0 || typeof sidecar.old_claim_leased_until !== "string" || !Number.isFinite(Date.parse(sidecar.old_claim_leased_until)) || typeof sidecar.continuation_sequence !== "number" || !Number.isSafeInteger(sidecar.continuation_sequence) || sidecar.continuation_sequence < 1 || typeof sidecar.checkpoint_path !== "string" || sidecar.checkpoint_path.length === 0 || typeof sidecar.checkpoint_hash !== "string" || !/^[a-f0-9]{64}$/.test(sidecar.checkpoint_hash) || sidecar.replacement_worker !== input.workerName || sidecar.replacement_generation !== replacementGeneration || sidecar.adoption_token_hash !== (0, import_node_crypto12.createHash)("sha256").update(adoptionToken).digest("hex") || typeof sidecar.created_at !== "string" || !Number.isFinite(Date.parse(sidecar.created_at)))
|
|
25552
26176
|
return false;
|
|
25553
26177
|
const sameReservation = persisted.recovery_id === sidecar.recovery_id && persisted.request_id === sidecar.request_id && persisted.continuation_sequence === sidecar.continuation_sequence && persisted.checkpoint_path === sidecar.checkpoint_path && persisted.checkpoint_hash === sidecar.checkpoint_hash && persisted.replacement_worker === sidecar.replacement_worker && persisted.replacement_generation === sidecar.replacement_generation;
|
|
25554
26178
|
if (!sameReservation) return false;
|
|
@@ -25837,7 +26461,7 @@ async function executeRecoverDeadWorkerV2Owner(input) {
|
|
|
25837
26461
|
input.cwd,
|
|
25838
26462
|
input.requestId
|
|
25839
26463
|
);
|
|
25840
|
-
const recoveryId = reservation?.recovery_id ?? (0,
|
|
26464
|
+
const recoveryId = reservation?.recovery_id ?? (0, import_node_crypto12.randomUUID)();
|
|
25841
26465
|
let ownerBound = false;
|
|
25842
26466
|
try {
|
|
25843
26467
|
if (!isValidTeamInstanceId(input.instanceId)) {
|
|
@@ -26555,7 +27179,7 @@ async function executeRecoverDeadWorkerV2Owner(input) {
|
|
|
26555
27179
|
} catch {
|
|
26556
27180
|
return { ok: false, error: "launch_descriptor_unresolvable" };
|
|
26557
27181
|
}
|
|
26558
|
-
const paneAttemptId = (0,
|
|
27182
|
+
const paneAttemptId = (0, import_node_crypto12.randomUUID)();
|
|
26559
27183
|
const livePaneIds = [];
|
|
26560
27184
|
for (const candidate of config.workers) {
|
|
26561
27185
|
if (!candidate.pane_id || candidate.name === sagaInput2.workerName)
|
|
@@ -26805,7 +27429,7 @@ async function executeRecoverDeadWorkerV2Owner(input) {
|
|
|
26805
27429
|
launch_nonce: pending.startupContext.attempt.nonce,
|
|
26806
27430
|
written_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
26807
27431
|
};
|
|
26808
|
-
await (0, import_promises19.mkdir)((0,
|
|
27432
|
+
await (0, import_promises19.mkdir)((0, import_path49.join)(pending.gate.activatePath, ".."), { recursive: true });
|
|
26809
27433
|
await (0, import_promises19.writeFile)(
|
|
26810
27434
|
pending.gate.activatePath,
|
|
26811
27435
|
JSON.stringify(record),
|
|
@@ -27006,7 +27630,7 @@ ${recoveryContract}` : ""}`;
|
|
|
27006
27630
|
const launchedRecord = JSON.parse(
|
|
27007
27631
|
await (0, import_promises19.readFile)(launchedPath, "utf8")
|
|
27008
27632
|
);
|
|
27009
|
-
providerLive = Number.isInteger(launchedRecord.provider_pid) && typeof launchedRecord.provider_start_identity === "string" && (launchedRecord.supervisor_completion_path === void 0 || typeof launchedRecord.supervisor_completion_path === "string" && launchedRecord.supervisor_completion_path.trim().length > 0 && !(0,
|
|
27633
|
+
providerLive = Number.isInteger(launchedRecord.provider_pid) && typeof launchedRecord.provider_start_identity === "string" && (launchedRecord.supervisor_completion_path === void 0 || typeof launchedRecord.supervisor_completion_path === "string" && launchedRecord.supervisor_completion_path.trim().length > 0 && !(0, import_fs44.existsSync)(launchedRecord.supervisor_completion_path)) && await isProcessIdentityLive(
|
|
27010
27634
|
launchedRecord.provider_pid,
|
|
27011
27635
|
launchedRecord.provider_start_identity,
|
|
27012
27636
|
Date.now() + 1e3
|
|
@@ -27137,7 +27761,7 @@ async function rollbackUnpersistedNativeWorktreeStartup(teamName, cwd, cause, in
|
|
|
27137
27761
|
const writeFailureMarker = async (extra = {}) => {
|
|
27138
27762
|
await (0, import_promises19.mkdir)(teamRoot, { recursive: true });
|
|
27139
27763
|
await (0, import_promises19.writeFile)(
|
|
27140
|
-
(0,
|
|
27764
|
+
(0, import_path49.join)(teamRoot, "startup-failure.json"),
|
|
27141
27765
|
JSON.stringify(
|
|
27142
27766
|
{
|
|
27143
27767
|
reason: "startup_failed_before_config_persisted",
|
|
@@ -27175,7 +27799,7 @@ async function rollbackUnpersistedNativeWorktreeStartup(teamName, cwd, cause, in
|
|
|
27175
27799
|
}
|
|
27176
27800
|
}
|
|
27177
27801
|
await (0, import_promises19.rm)(teamRoot, { recursive: true, force: true });
|
|
27178
|
-
if ((0,
|
|
27802
|
+
if ((0, import_fs44.existsSync)(teamRoot)) {
|
|
27179
27803
|
await writeFailureMarker({
|
|
27180
27804
|
rollback_error: "startup_state_removal_unverified"
|
|
27181
27805
|
});
|
|
@@ -27202,7 +27826,7 @@ async function writeStartedStartupRollbackEvidence(args) {
|
|
|
27202
27826
|
const teamRoot = absPath(args.cwd, TeamPaths.root(args.teamName));
|
|
27203
27827
|
await (0, import_promises19.mkdir)(teamRoot, { recursive: true });
|
|
27204
27828
|
await (0, import_promises19.writeFile)(
|
|
27205
|
-
(0,
|
|
27829
|
+
(0, import_path49.join)(teamRoot, "startup-failure.json"),
|
|
27206
27830
|
JSON.stringify(
|
|
27207
27831
|
{
|
|
27208
27832
|
reason: args.markerReason ?? "startup_rollback_cleanup_incomplete",
|
|
@@ -27473,7 +28097,7 @@ async function startTeamV2(config) {
|
|
|
27473
28097
|
}
|
|
27474
28098
|
const instance = createTeamInstanceBinding({
|
|
27475
28099
|
teamName: sanitized,
|
|
27476
|
-
cwd: (0,
|
|
28100
|
+
cwd: (0, import_path49.resolve)(config.cwd),
|
|
27477
28101
|
...config.instanceId !== void 0 ? { instanceId: config.instanceId } : {}
|
|
27478
28102
|
});
|
|
27479
28103
|
const leaderCwd = instance.cwd;
|
|
@@ -27605,7 +28229,7 @@ async function startTeamV2(config) {
|
|
|
27605
28229
|
explicitContractRoles: [...startupAssignments].flatMap(
|
|
27606
28230
|
([workerName, a]) => a.role && shouldInjectContract(a.role, a.agentType) && !inferredContractRoles.has(workerName) ? [a.role] : []
|
|
27607
28231
|
),
|
|
27608
|
-
sdkAvailable: config.sdkAvailable ?? (
|
|
28232
|
+
sdkAvailable: config.sdkAvailable ?? (() => defaultSdkAvailable())
|
|
27609
28233
|
});
|
|
27610
28234
|
if (transportDecision.requested === "auto" && transportDecision.fallbackReason && !transportDecision.fallbackReason.startsWith("host_")) {
|
|
27611
28235
|
process.stderr.write(
|
|
@@ -27666,6 +28290,10 @@ async function startTeamV2(config) {
|
|
|
27666
28290
|
const missing = missingBinaryReasons.map(({ agentType, reason }) => `${agentType}:${reason}`).join(";");
|
|
27667
28291
|
throw new Error(`cli_binary_preflight_failed:${missing}`);
|
|
27668
28292
|
}
|
|
28293
|
+
const copilotCatalogue = needsTeamCopilotCatalogue(
|
|
28294
|
+
startupAssignments.values(),
|
|
28295
|
+
sdkMode && !!sdkSettings?.model
|
|
28296
|
+
) ? await teamCopilotCatalogue() : null;
|
|
27669
28297
|
try {
|
|
27670
28298
|
await cleanupStaleReservations(sanitized, leaderCwd);
|
|
27671
28299
|
} catch {
|
|
@@ -27698,7 +28326,7 @@ async function startTeamV2(config) {
|
|
|
27698
28326
|
try {
|
|
27699
28327
|
const pendingConfig = buildTeamInstancePendingConfig(instance);
|
|
27700
28328
|
const pendingConfigPath = absPath(leaderCwd, TeamPaths.config(sanitized));
|
|
27701
|
-
await (0, import_promises19.mkdir)((0,
|
|
28329
|
+
await (0, import_promises19.mkdir)((0, import_path49.join)(pendingConfigPath, ".."), { recursive: true });
|
|
27702
28330
|
await (0, import_promises19.writeFile)(
|
|
27703
28331
|
pendingConfigPath,
|
|
27704
28332
|
JSON.stringify(pendingConfig, null, 2),
|
|
@@ -27719,7 +28347,7 @@ async function startTeamV2(config) {
|
|
|
27719
28347
|
recursive: true
|
|
27720
28348
|
});
|
|
27721
28349
|
await (0, import_promises19.mkdir)(
|
|
27722
|
-
(0,
|
|
28350
|
+
(0, import_path49.join)(getOmcRoot(leaderCwd), "state", "team", sanitized, "mailbox"),
|
|
27723
28351
|
{ recursive: true }
|
|
27724
28352
|
);
|
|
27725
28353
|
for (let i = 0; i < config.tasks.length; i++) {
|
|
@@ -27770,7 +28398,7 @@ async function startTeamV2(config) {
|
|
|
27770
28398
|
if (!assignment)
|
|
27771
28399
|
throw new Error(`Missing startup assignment for ${workerName}`);
|
|
27772
28400
|
const worktree = workerWorktrees.get(workerName);
|
|
27773
|
-
const verdictAssignmentId = taskIndex !== void 0 ? (0,
|
|
28401
|
+
const verdictAssignmentId = taskIndex !== void 0 ? (0, import_node_crypto12.randomUUID)() : void 0;
|
|
27774
28402
|
const outputFile = taskIndex !== void 0 && assignment.role && shouldInjectContract(assignment.role, assignment.agentType) ? cliWorkerOutputFilePath(
|
|
27775
28403
|
teamStateRoot(leaderCwd, sanitized),
|
|
27776
28404
|
workerName,
|
|
@@ -27806,6 +28434,7 @@ async function startTeamV2(config) {
|
|
|
27806
28434
|
resolvedBinaryPath: binary,
|
|
27807
28435
|
model: assignment.model,
|
|
27808
28436
|
reasoningEffort: assignment.reasoningEffort,
|
|
28437
|
+
copilotCatalogue,
|
|
27809
28438
|
...permissionFlags.length > 0 ? { extraFlags: permissionFlags } : {}
|
|
27810
28439
|
},
|
|
27811
28440
|
promptArgs
|
|
@@ -27951,7 +28580,7 @@ async function startTeamV2(config) {
|
|
|
27951
28580
|
service_descriptor: config.autoMerge ? {
|
|
27952
28581
|
schema_version: 1,
|
|
27953
28582
|
service_generation: 1,
|
|
27954
|
-
service_attempt_id: (0,
|
|
28583
|
+
service_attempt_id: (0, import_node_crypto12.randomUUID)(),
|
|
27955
28584
|
auto_merge_enabled: true,
|
|
27956
28585
|
workspace_root: leaderCwd,
|
|
27957
28586
|
leader_branch: autoMergeLeaderBranch,
|
|
@@ -27959,7 +28588,7 @@ async function startTeamV2(config) {
|
|
|
27959
28588
|
} : {
|
|
27960
28589
|
schema_version: 1,
|
|
27961
28590
|
service_generation: 1,
|
|
27962
|
-
service_attempt_id: (0,
|
|
28591
|
+
service_attempt_id: (0, import_node_crypto12.randomUUID)(),
|
|
27963
28592
|
auto_merge_enabled: false,
|
|
27964
28593
|
workspace_root: leaderCwd,
|
|
27965
28594
|
cadence_policy: "disabled"
|
|
@@ -28307,7 +28936,7 @@ function cursorTransitionFailureMarkerPath(outputFile) {
|
|
|
28307
28936
|
return `${outputFile}.transition-failure`;
|
|
28308
28937
|
}
|
|
28309
28938
|
function cursorTransitionFailureMarkerKey(input) {
|
|
28310
|
-
return (0,
|
|
28939
|
+
return (0, import_node_crypto12.createHash)("sha256").update(
|
|
28311
28940
|
JSON.stringify([
|
|
28312
28941
|
input.instanceId,
|
|
28313
28942
|
input.workerName,
|
|
@@ -28345,7 +28974,7 @@ function nonCursorVerdictFileIdentity(stats) {
|
|
|
28345
28974
|
].join("-");
|
|
28346
28975
|
}
|
|
28347
28976
|
function fingerprintCliWorkerVerdictArtifact(raw, stats) {
|
|
28348
|
-
const contentSha256 = (0,
|
|
28977
|
+
const contentSha256 = (0, import_node_crypto12.createHash)("sha256").update(raw, "utf8").digest("hex");
|
|
28349
28978
|
return `${contentSha256}-${nonCursorVerdictFileIdentity(stats)}`;
|
|
28350
28979
|
}
|
|
28351
28980
|
async function readNonCursorVerdictArtifact(outputFile) {
|
|
@@ -28460,7 +29089,7 @@ async function processCliWorkerVerdictsUnderLock(teamName, cwd, expectedInstance
|
|
|
28460
29089
|
const { rename: rename8 } = await import("fs/promises");
|
|
28461
29090
|
const {
|
|
28462
29091
|
renameSync: renameSync5,
|
|
28463
|
-
readFileSync:
|
|
29092
|
+
readFileSync: readFileSync33,
|
|
28464
29093
|
existsSync: fsExistsSync
|
|
28465
29094
|
} = await import("fs");
|
|
28466
29095
|
const { withFileLockSync: withFileLockSync2 } = await Promise.resolve().then(() => (init_file_lock(), file_lock_exports));
|
|
@@ -28559,7 +29188,7 @@ async function processCliWorkerVerdictsUnderLock(teamName, cwd, expectedInstance
|
|
|
28559
29188
|
return;
|
|
28560
29189
|
}
|
|
28561
29190
|
}
|
|
28562
|
-
const raw =
|
|
29191
|
+
const raw = readFileSync33(outputFile, "utf-8");
|
|
28563
29192
|
parseCliWorkerVerdict(raw);
|
|
28564
29193
|
renameSync5(outputFile, processingOutputFile);
|
|
28565
29194
|
verdictFile = processingOutputFile;
|
|
@@ -29429,7 +30058,7 @@ async function monitorTeamV2(teamName, cwd, expectedInstanceId) {
|
|
|
29429
30058
|
}
|
|
29430
30059
|
}
|
|
29431
30060
|
const leaderInbox = await readLeaderInbox(
|
|
29432
|
-
(0,
|
|
30061
|
+
(0, import_path49.dirname)(absPath(cwd, TeamPaths.mailbox(sanitized, "leader-fixed")))
|
|
29433
30062
|
);
|
|
29434
30063
|
if (leaderInbox.length > 0) {
|
|
29435
30064
|
const sdkTeam = config.workers.some(
|
|
@@ -29596,7 +30225,7 @@ async function cleanupStaleReservations(teamName, cwd) {
|
|
|
29596
30225
|
cwd,
|
|
29597
30226
|
TeamPaths.teamInstanceReservation(workspaceHash, sanitized)
|
|
29598
30227
|
);
|
|
29599
|
-
if (!(0,
|
|
30228
|
+
if (!(0, import_fs44.existsSync)(reservationPath2)) return;
|
|
29600
30229
|
const contentStr = await (0, import_promises19.readFile)(reservationPath2, "utf-8");
|
|
29601
30230
|
const reservation = JSON.parse(contentStr);
|
|
29602
30231
|
if (!(reservation && typeof reservation === "object" && !Array.isArray(reservation) && "owner" in reservation && typeof reservation.owner === "object")) {
|
|
@@ -29771,7 +30400,7 @@ async function shutdownTeamV2(teamName, cwd, options = {}) {
|
|
|
29771
30400
|
const processStartedAt = currentProcessStartIdentity();
|
|
29772
30401
|
if (!processStartedAt)
|
|
29773
30402
|
throw new Error("process_start_identity_unavailable");
|
|
29774
|
-
ownedShutdownNonce = (0,
|
|
30403
|
+
ownedShutdownNonce = (0, import_node_crypto12.randomUUID)();
|
|
29775
30404
|
const nextRevision = current.stateRevision + 1;
|
|
29776
30405
|
const next = {
|
|
29777
30406
|
...current.config,
|
|
@@ -29913,7 +30542,7 @@ async function shutdownTeamV2(teamName, cwd, options = {}) {
|
|
|
29913
30542
|
};
|
|
29914
30543
|
if (!config) {
|
|
29915
30544
|
const cleanupSafety = inspectTeamWorktreeCleanupSafety(sanitized, cwd);
|
|
29916
|
-
if (cleanupSafety.hasEvidence || (0,
|
|
30545
|
+
if (cleanupSafety.hasEvidence || (0, import_fs44.existsSync)(absPath(cwd, TeamPaths.root(sanitized)))) {
|
|
29917
30546
|
process.stderr.write(
|
|
29918
30547
|
"[team/runtime-v2] preserving team state because config is missing and worktree cleanup evidence remains\n"
|
|
29919
30548
|
);
|
|
@@ -30380,12 +31009,12 @@ If you accept, exit your session. If you reject, remain active for task work and
|
|
|
30380
31009
|
}
|
|
30381
31010
|
);
|
|
30382
31011
|
}
|
|
30383
|
-
var
|
|
31012
|
+
var import_path49, import_fs44, import_promises19, import_perf_hooks, import_node_child_process10, import_node_crypto12, orchestratorByTeam, cadenceByTeam, MONITOR_SIGNAL_STALE_MS, WORKER_STARTUP_EVIDENCE_POLL_INTERVAL_MS, WORKER_STARTUP_EVIDENCE_POLICIES, ENGAGED_PANE_RECHECK_TIMEOUT_ENV, MAX_ENGAGED_PANE_RECHECK_BUDGET_MS, CLAIM_ERROR_CAPTURE_MAX, CLAIM_ERROR_JSON_LINES_MAX, CLAIM_ERROR_LINE_MAX, CLAIM_ERROR_CODES, DEFAULT_SDK_LAUNCH_CONCURRENCY, DEFAULT_SDK_MAX_CREDITS_PER_WORKER, pendingRecoveryPanes, BOOTSTRAP_RECOVERY_EVIDENCE_POLL_MS, BOOTSTRAP_RECOVERY_EVIDENCE_MAX_WAIT_MS, TEAM_INSTANCE_FINAL_DISPOSAL_AUTHORIZATION, CURSOR_RUNTIME_POLICY_SKIP_REASON, CURSOR_RUNTIME_POLICY_SKIP_PROVENANCE, CURSOR_DELEGATION_EVIDENCE_LINE;
|
|
30384
31013
|
var init_runtime_v2 = __esm({
|
|
30385
31014
|
"src/team/runtime-v2.ts"() {
|
|
30386
31015
|
"use strict";
|
|
30387
|
-
|
|
30388
|
-
|
|
31016
|
+
import_path49 = require("path");
|
|
31017
|
+
import_fs44 = require("fs");
|
|
30389
31018
|
import_promises19 = require("fs/promises");
|
|
30390
31019
|
import_perf_hooks = require("perf_hooks");
|
|
30391
31020
|
init_state_paths();
|
|
@@ -30417,10 +31046,10 @@ var init_runtime_v2 = __esm({
|
|
|
30417
31046
|
init_cli_worker_contract();
|
|
30418
31047
|
init_merge_orchestrator();
|
|
30419
31048
|
init_leader_inbox();
|
|
30420
|
-
|
|
31049
|
+
import_node_child_process10 = require("node:child_process");
|
|
30421
31050
|
init_runtime_flags();
|
|
30422
31051
|
init_worker_commit_cadence();
|
|
30423
|
-
|
|
31052
|
+
import_node_crypto12 = require("node:crypto");
|
|
30424
31053
|
init_recovery_request_store();
|
|
30425
31054
|
init_runtime_owner_client();
|
|
30426
31055
|
init_scaling();
|
|
@@ -30434,6 +31063,7 @@ var init_runtime_v2 = __esm({
|
|
|
30434
31063
|
init_worker_launch_ack();
|
|
30435
31064
|
init_sdk_transport();
|
|
30436
31065
|
init_model_contract();
|
|
31066
|
+
init_model_catalogue();
|
|
30437
31067
|
init_copilot_sdk_driver();
|
|
30438
31068
|
init_host_signal();
|
|
30439
31069
|
init_copilot_session_env();
|
|
@@ -30580,10 +31210,10 @@ __export(runtime_cli_exports, {
|
|
|
30580
31210
|
});
|
|
30581
31211
|
module.exports = __toCommonJS(runtime_cli_exports);
|
|
30582
31212
|
init_windows_search();
|
|
30583
|
-
var
|
|
30584
|
-
var
|
|
31213
|
+
var import_node_crypto13 = require("node:crypto");
|
|
31214
|
+
var import_fs45 = require("fs");
|
|
30585
31215
|
var import_promises20 = require("fs/promises");
|
|
30586
|
-
var
|
|
31216
|
+
var import_path50 = require("path");
|
|
30587
31217
|
init_events();
|
|
30588
31218
|
|
|
30589
31219
|
// src/team/leader-nudge-guidance.ts
|
|
@@ -30831,18 +31461,18 @@ function expandTokensDeep(obj, workspace) {
|
|
|
30831
31461
|
}
|
|
30832
31462
|
return obj;
|
|
30833
31463
|
}
|
|
30834
|
-
function deepMergeGuards(target,
|
|
31464
|
+
function deepMergeGuards(target, source2) {
|
|
30835
31465
|
const result = { ...target };
|
|
30836
|
-
if (
|
|
30837
|
-
result.factcheck = { ...result.factcheck, ...
|
|
31466
|
+
if (source2.factcheck) {
|
|
31467
|
+
result.factcheck = { ...result.factcheck, ...source2.factcheck };
|
|
30838
31468
|
}
|
|
30839
|
-
if (
|
|
31469
|
+
if (source2.sentinel) {
|
|
30840
31470
|
result.sentinel = {
|
|
30841
31471
|
...result.sentinel,
|
|
30842
|
-
...
|
|
31472
|
+
...source2.sentinel,
|
|
30843
31473
|
readiness: {
|
|
30844
31474
|
...result.sentinel.readiness,
|
|
30845
|
-
...
|
|
31475
|
+
...source2.sentinel.readiness ?? {}
|
|
30846
31476
|
}
|
|
30847
31477
|
};
|
|
30848
31478
|
}
|
|
@@ -31142,7 +31772,7 @@ async function waitForSentinelReadiness(options = {}) {
|
|
|
31142
31772
|
}
|
|
31143
31773
|
const deadline = startedAt + timeoutMs;
|
|
31144
31774
|
while (Date.now() < deadline) {
|
|
31145
|
-
await new Promise((
|
|
31775
|
+
await new Promise((resolve22) => setTimeout(resolve22, pollIntervalMs));
|
|
31146
31776
|
attempts += 1;
|
|
31147
31777
|
latest = checkSentinelReadiness(options);
|
|
31148
31778
|
if (latest.ready) {
|
|
@@ -31234,10 +31864,10 @@ function areAllAuthoritativeWorkersDead(refresh, workers) {
|
|
|
31234
31864
|
return classifyAllDeadRecoveryEvidence(refresh, workers, true) === "all_dead";
|
|
31235
31865
|
}
|
|
31236
31866
|
function validateCanonicalRecoveryIntent(teamName, cwd, pathRecoveryId, path5) {
|
|
31237
|
-
const intent = parseRecoveryIntent((0,
|
|
31867
|
+
const intent = parseRecoveryIntent((0, import_fs45.readFileSync)(path5, "utf8"));
|
|
31238
31868
|
if (intent.team_name !== teamName || intent.recovery_id !== pathRecoveryId) throw new Error("invalid_persisted_state");
|
|
31239
31869
|
const reservation = readRecoveryRequestReservation(cwd, intent.request_id);
|
|
31240
|
-
const workspaceHash = (0,
|
|
31870
|
+
const workspaceHash = (0, import_node_crypto13.createHash)("sha256").update(cwd).digest("hex");
|
|
31241
31871
|
const expectedPayloadHash = canonicalRecoveryPayloadHash({
|
|
31242
31872
|
operation: "recover-worker",
|
|
31243
31873
|
workspaceHash,
|
|
@@ -31269,14 +31899,14 @@ async function processPendingRecoveryIntents(teamName, cwd, execute = handleReco
|
|
|
31269
31899
|
const root = absPath(cwd, TeamPaths.recoveryIntents(teamName));
|
|
31270
31900
|
let names;
|
|
31271
31901
|
try {
|
|
31272
|
-
names = (0,
|
|
31902
|
+
names = (0, import_fs45.readdirSync)(root).filter((name) => name.endsWith(".json")).sort();
|
|
31273
31903
|
} catch {
|
|
31274
31904
|
return;
|
|
31275
31905
|
}
|
|
31276
31906
|
for (const name of names) {
|
|
31277
|
-
const path5 = (0,
|
|
31907
|
+
const path5 = (0, import_path50.join)(root, name);
|
|
31278
31908
|
try {
|
|
31279
|
-
const pathRecoveryId = (0,
|
|
31909
|
+
const pathRecoveryId = (0, import_path50.basename)(name, ".json");
|
|
31280
31910
|
const intent = validateCanonicalRecoveryIntent(teamName, cwd, pathRecoveryId, path5);
|
|
31281
31911
|
if (intent.instance_id.toLowerCase() !== normalizedExpectedInstanceId) continue;
|
|
31282
31912
|
if (!await assertRuntimeInstance(teamName, cwd, normalizedExpectedInstanceId)) continue;
|
|
@@ -31346,17 +31976,17 @@ async function updateAllDeadRecoveryGrace(teamName, cwd, evidence, nowMs = Date.
|
|
|
31346
31976
|
}
|
|
31347
31977
|
function canonicalRecoveryIntentEntryId(name, path5) {
|
|
31348
31978
|
if (!name.endsWith(".json")) return null;
|
|
31349
|
-
const recoveryId = (0,
|
|
31979
|
+
const recoveryId = (0, import_path50.basename)(name, ".json");
|
|
31350
31980
|
if (name !== `${recoveryId}.json` || !isSafeRecoveryRequestId(recoveryId)) return null;
|
|
31351
31981
|
try {
|
|
31352
|
-
return (0,
|
|
31982
|
+
return (0, import_fs45.lstatSync)(path5).isFile() ? recoveryId : null;
|
|
31353
31983
|
} catch {
|
|
31354
31984
|
return null;
|
|
31355
31985
|
}
|
|
31356
31986
|
}
|
|
31357
31987
|
function hasVerifiedTerminalRepairForMalformedIntent(teamName, cwd, recoveryId, path5) {
|
|
31358
31988
|
try {
|
|
31359
|
-
const raw = JSON.parse((0,
|
|
31989
|
+
const raw = JSON.parse((0, import_fs45.readFileSync)(path5, "utf8"));
|
|
31360
31990
|
if (raw.team_name !== teamName || raw.recovery_id !== recoveryId || typeof raw.request_id !== "string" || !isSafeRecoveryRequestId(raw.request_id) || typeof raw.worker_name !== "string" || raw.worker_name.length === 0) return false;
|
|
31361
31991
|
const final = readRecoveryFinalState(cwd, raw.request_id);
|
|
31362
31992
|
return final.kind === "valid" && final.final.recovery_id === recoveryId && final.final.team_name === teamName && final.final.worker_name === raw.worker_name;
|
|
@@ -31366,7 +31996,7 @@ function hasVerifiedTerminalRepairForMalformedIntent(teamName, cwd, recoveryId,
|
|
|
31366
31996
|
}
|
|
31367
31997
|
function malformedIntentMayPredateDeadline(path5, deadlineAt) {
|
|
31368
31998
|
try {
|
|
31369
|
-
const metadata = (0,
|
|
31999
|
+
const metadata = (0, import_fs45.lstatSync)(path5);
|
|
31370
32000
|
if (Number.isFinite(metadata.mtimeMs) && metadata.mtimeMs <= deadlineAt) return true;
|
|
31371
32001
|
if (Number.isFinite(metadata.birthtimeMs) && metadata.birthtimeMs > 0) {
|
|
31372
32002
|
return metadata.birthtimeMs <= deadlineAt;
|
|
@@ -31381,14 +32011,14 @@ function canonicalRecoveryAdmissionEntryId(name, path5) {
|
|
|
31381
32011
|
const requestId = name.slice(0, -".pending.json".length);
|
|
31382
32012
|
if (name !== `${requestId}.pending.json` || !isSafeRecoveryRequestId(requestId)) return null;
|
|
31383
32013
|
try {
|
|
31384
|
-
return (0,
|
|
32014
|
+
return (0, import_fs45.lstatSync)(path5).isFile() ? requestId : null;
|
|
31385
32015
|
} catch {
|
|
31386
32016
|
return null;
|
|
31387
32017
|
}
|
|
31388
32018
|
}
|
|
31389
32019
|
function malformedAdmissionMayPredateDeadline(path5, deadlineAt) {
|
|
31390
32020
|
try {
|
|
31391
|
-
const metadata = (0,
|
|
32021
|
+
const metadata = (0, import_fs45.lstatSync)(path5);
|
|
31392
32022
|
if (!metadata.isFile()) return true;
|
|
31393
32023
|
if (Number.isFinite(metadata.mtimeMs) && metadata.mtimeMs <= deadlineAt) return true;
|
|
31394
32024
|
if (Number.isFinite(metadata.birthtimeMs) && metadata.birthtimeMs > 0) {
|
|
@@ -31405,12 +32035,12 @@ function hasPendingRecoveryIntentBeforeDeadline(teamName, cwd, deadlineAt, expec
|
|
|
31405
32035
|
const root = absPath(cwd, TeamPaths.recoveryIntents(teamName));
|
|
31406
32036
|
let names;
|
|
31407
32037
|
try {
|
|
31408
|
-
names = (0,
|
|
32038
|
+
names = (0, import_fs45.readdirSync)(root).filter((name) => name.endsWith(".json"));
|
|
31409
32039
|
} catch {
|
|
31410
32040
|
return false;
|
|
31411
32041
|
}
|
|
31412
32042
|
for (const name of names) {
|
|
31413
|
-
const path5 = (0,
|
|
32043
|
+
const path5 = (0, import_path50.join)(root, name);
|
|
31414
32044
|
const recoveryId = canonicalRecoveryIntentEntryId(name, path5);
|
|
31415
32045
|
if (!recoveryId) continue;
|
|
31416
32046
|
try {
|
|
@@ -31428,16 +32058,16 @@ function hasPendingRecoveryIntentBeforeDeadline(teamName, cwd, deadlineAt, expec
|
|
|
31428
32058
|
function hasPendingRecoveryAdmissionBeforeDeadline(teamName, cwd, deadlineAt, expectedInstanceId) {
|
|
31429
32059
|
const normalizedExpectedInstanceId = normalizeRuntimeInstanceId(expectedInstanceId);
|
|
31430
32060
|
if (!normalizedExpectedInstanceId) return true;
|
|
31431
|
-
const workspaceHash = (0,
|
|
32061
|
+
const workspaceHash = (0, import_node_crypto13.createHash)("sha256").update(cwd).digest("hex");
|
|
31432
32062
|
const root = absPath(cwd, TeamPaths.recoveryRequestsRoot());
|
|
31433
32063
|
let names;
|
|
31434
32064
|
try {
|
|
31435
|
-
names = (0,
|
|
32065
|
+
names = (0, import_fs45.readdirSync)(root).filter((name) => name.endsWith(".pending.json"));
|
|
31436
32066
|
} catch {
|
|
31437
32067
|
return false;
|
|
31438
32068
|
}
|
|
31439
32069
|
for (const name of names) {
|
|
31440
|
-
const path5 = (0,
|
|
32070
|
+
const path5 = (0, import_path50.join)(root, name);
|
|
31441
32071
|
const requestId = canonicalRecoveryAdmissionEntryId(name, path5);
|
|
31442
32072
|
if (!requestId) continue;
|
|
31443
32073
|
try {
|
|
@@ -31515,7 +32145,7 @@ async function runPersistentRecoveryOwnerLoop(input, options = {}) {
|
|
|
31515
32145
|
const reconcileServices = options.reconcileServices ?? reconcileCommittedTeamServices;
|
|
31516
32146
|
const monitor = options.monitor ?? monitorTeamV2;
|
|
31517
32147
|
const sleep4 = options.sleep ?? (async (ms) => {
|
|
31518
|
-
await new Promise((
|
|
32148
|
+
await new Promise((resolve22) => setTimeout(resolve22, ms));
|
|
31519
32149
|
});
|
|
31520
32150
|
const shutdown = options.shutdown ?? shutdownTeamV2;
|
|
31521
32151
|
let iteration = 0;
|
|
@@ -31656,7 +32286,7 @@ async function writeResultArtifact(output, finishedAt, jobId = process.env.OMC_J
|
|
|
31656
32286
|
if (!output.instanceId || !isValidTeamInstanceId(output.instanceId)) {
|
|
31657
32287
|
throw new Error("result_artifact_instance_identity_missing");
|
|
31658
32288
|
}
|
|
31659
|
-
const resultPath = (0,
|
|
32289
|
+
const resultPath = (0, import_path50.join)(omcJobsDir, `${jobId}-result.json`);
|
|
31660
32290
|
const tmpPath = `${resultPath}.tmp`;
|
|
31661
32291
|
await (0, import_promises20.writeFile)(
|
|
31662
32292
|
tmpPath,
|
|
@@ -31731,7 +32361,7 @@ async function writePanesFile(jobId, instanceId, teamName, cwd, paneIds, leaderP
|
|
|
31731
32361
|
if (authoritativePaneIds.some((paneId) => !paneIds.includes(paneId))) {
|
|
31732
32362
|
throw new Error("pane_artifact_missing_runtime_pane");
|
|
31733
32363
|
}
|
|
31734
|
-
const panesPath = (0,
|
|
32364
|
+
const panesPath = (0, import_path50.join)(omcJobsDir, `${jobId}-panes.json`);
|
|
31735
32365
|
await (0, import_promises20.writeFile)(
|
|
31736
32366
|
panesPath + ".tmp",
|
|
31737
32367
|
JSON.stringify({
|
|
@@ -31769,7 +32399,7 @@ function isTerseFinalSummary(summary) {
|
|
|
31769
32399
|
function readTaskOutputFallback(outputsDir, teamName, taskId) {
|
|
31770
32400
|
let entries;
|
|
31771
32401
|
try {
|
|
31772
|
-
entries = (0,
|
|
32402
|
+
entries = (0, import_fs45.readdirSync)(outputsDir);
|
|
31773
32403
|
} catch {
|
|
31774
32404
|
return null;
|
|
31775
32405
|
}
|
|
@@ -31778,16 +32408,16 @@ function readTaskOutputFallback(outputsDir, teamName, taskId) {
|
|
|
31778
32408
|
if (candidates.length === 0) return null;
|
|
31779
32409
|
let newest = null;
|
|
31780
32410
|
for (const name of candidates) {
|
|
31781
|
-
const full = (0,
|
|
32411
|
+
const full = (0, import_path50.join)(outputsDir, name);
|
|
31782
32412
|
try {
|
|
31783
|
-
const mtime = (0,
|
|
32413
|
+
const mtime = (0, import_fs45.statSync)(full).mtimeMs;
|
|
31784
32414
|
if (!newest || mtime > newest.mtime) newest = { path: full, mtime };
|
|
31785
32415
|
} catch {
|
|
31786
32416
|
}
|
|
31787
32417
|
}
|
|
31788
32418
|
if (!newest) return null;
|
|
31789
32419
|
try {
|
|
31790
|
-
const content = (0,
|
|
32420
|
+
const content = (0, import_fs45.readFileSync)(newest.path, "utf-8").trim();
|
|
31791
32421
|
if (content.length === 0) return null;
|
|
31792
32422
|
return content.length > MAX_FALLBACK_SUMMARY_CHARS ? content.slice(0, MAX_FALLBACK_SUMMARY_CHARS) + "\n... (truncated)" : content;
|
|
31793
32423
|
} catch {
|
|
@@ -31795,14 +32425,14 @@ function readTaskOutputFallback(outputsDir, teamName, taskId) {
|
|
|
31795
32425
|
}
|
|
31796
32426
|
}
|
|
31797
32427
|
function collectTaskResults(stateRoot) {
|
|
31798
|
-
const tasksDir = (0,
|
|
31799
|
-
const teamName = (0,
|
|
31800
|
-
const outputsDir = (0,
|
|
32428
|
+
const tasksDir = (0, import_path50.join)(stateRoot, "tasks");
|
|
32429
|
+
const teamName = (0, import_path50.basename)(stateRoot);
|
|
32430
|
+
const outputsDir = (0, import_path50.join)(stateRoot, "..", "..", "..", "outputs");
|
|
31801
32431
|
try {
|
|
31802
|
-
const files = (0,
|
|
32432
|
+
const files = (0, import_fs45.readdirSync)(tasksDir).filter((f) => f.endsWith(".json"));
|
|
31803
32433
|
return files.map((f) => {
|
|
31804
32434
|
try {
|
|
31805
|
-
const raw = (0,
|
|
32435
|
+
const raw = (0, import_fs45.readFileSync)((0, import_path50.join)(tasksDir, f), "utf-8");
|
|
31806
32436
|
const task = JSON.parse(raw);
|
|
31807
32437
|
const taskId = task.id ?? f.replace(".json", "");
|
|
31808
32438
|
let summary = task.result ?? task.summary ?? "";
|
|
@@ -31837,8 +32467,8 @@ function createRuntimeStartupShutdownBarrier() {
|
|
|
31837
32467
|
let settled = false;
|
|
31838
32468
|
let requested = false;
|
|
31839
32469
|
let resolveCompletion;
|
|
31840
|
-
const completion = new Promise((
|
|
31841
|
-
resolveCompletion =
|
|
32470
|
+
const completion = new Promise((resolve22) => {
|
|
32471
|
+
resolveCompletion = resolve22;
|
|
31842
32472
|
});
|
|
31843
32473
|
return {
|
|
31844
32474
|
requestShutdown: () => {
|
|
@@ -32148,7 +32778,7 @@ async function main() {
|
|
|
32148
32778
|
if (snap.allTasksTerminal) {
|
|
32149
32779
|
const hasFailures = snap.tasks.failed > 0;
|
|
32150
32780
|
if (!hasFailures) {
|
|
32151
|
-
const sentinelLogPath = (0,
|
|
32781
|
+
const sentinelLogPath = (0, import_path50.join)(cwd, "sentinel_stop.jsonl");
|
|
32152
32782
|
const gateResult = await waitForSentinelReadiness({
|
|
32153
32783
|
workspace: cwd,
|
|
32154
32784
|
logPath: sentinelLogPath,
|