context-mode 2.1.5 → 2.1.6
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 +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.zcode-plugin/plugin.json +1 -1
- package/README.md +72 -72
- package/SHA256SUMS +16 -16
- package/cli.mjs +199 -133
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +98 -98
- package/opencode/plugin.js +575 -341
- package/package.json +1 -1
- package/pi/index.js +491 -336
- package/qwen-extension.json +1 -1
- package/run.mjs +205 -67
- package/search.mjs +205 -67
- package/server.mjs +260 -163
package/cli.mjs
CHANGED
|
@@ -88,7 +88,7 @@ var require_src = __commonJS({
|
|
|
88
88
|
|
|
89
89
|
// src/entries/cli.ts
|
|
90
90
|
import { spawn as spawn4 } from "node:child_process";
|
|
91
|
-
import { readFileSync as
|
|
91
|
+
import { readFileSync as readFileSync13, realpathSync as realpathSync11 } from "node:fs";
|
|
92
92
|
import path14 from "node:path";
|
|
93
93
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
94
94
|
|
|
@@ -96,6 +96,14 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
|
96
96
|
var SERVER_KEY = "context-mode";
|
|
97
97
|
var TOOL_ORDER = Object.freeze(["ctx_execute", "ctx_batch", "ctx_index", "ctx_search", "ctx_resume", "ctx_stats", "ctx_doctor", "ctx_upgrade", "ctx_purge"]);
|
|
98
98
|
var OUTPUT_CAP = 16384;
|
|
99
|
+
var REPLACE_TRIGGER_BYTES_DEFAULT = 4096;
|
|
100
|
+
var REPLACE_TRIGGER_ENV = "CTX_REPLACE_TRIGGER_BYTES";
|
|
101
|
+
function readReplaceTrigger(raw) {
|
|
102
|
+
if (raw === void 0 || raw.trim() === "") return REPLACE_TRIGGER_BYTES_DEFAULT;
|
|
103
|
+
const n3 = Number(raw);
|
|
104
|
+
return Number.isSafeInteger(n3) && n3 > 0 ? n3 : REPLACE_TRIGGER_BYTES_DEFAULT;
|
|
105
|
+
}
|
|
106
|
+
var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
|
|
99
107
|
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
100
108
|
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
101
109
|
var WEIGHT = Object.freeze({ toolerr: 900, decision: 700, prompt: 500, edit: 400, index: 200 });
|
|
@@ -255,6 +263,7 @@ function readHintEvery(raw) {
|
|
|
255
263
|
return Number.isSafeInteger(n3) && n3 > 0 ? n3 : MCP_HINT_EVERY_DEFAULT;
|
|
256
264
|
}
|
|
257
265
|
var MCP_HINT_EVERY = readHintEvery(process.env.CTX_MCP_HINT_EVERY);
|
|
266
|
+
var SHARED_SKILLS_DIR = Object.freeze([".agents", "skills"]);
|
|
258
267
|
var DENY_WHAT = Object.freeze({
|
|
259
268
|
curl: "This curl/wget call",
|
|
260
269
|
http: "This inline HTTP call",
|
|
@@ -316,10 +325,10 @@ var READ_MEDIA_BY_AGENT = Object.freeze({
|
|
|
316
325
|
opencode: READ_IMAGES_AND_PDF,
|
|
317
326
|
pi: READ_IMAGES,
|
|
318
327
|
vscode: READ_IMAGES,
|
|
328
|
+
zcode: READ_IMAGES,
|
|
319
329
|
"copilot-cli": [],
|
|
320
330
|
codex: [],
|
|
321
|
-
kiro: []
|
|
322
|
-
zcode: []
|
|
331
|
+
kiro: []
|
|
323
332
|
});
|
|
324
333
|
var OWN_TOOL_PREFIX = "ctx_";
|
|
325
334
|
var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
|
|
@@ -373,7 +382,12 @@ var REPORT_POINTER = `ctx_search({queries:["FAIL","PASS","UNKNOWN"], source:${JS
|
|
|
373
382
|
var GIT_LS_REMOTE_TAG_ARGS = Object.freeze(["--tags", "--refs"]);
|
|
374
383
|
var RELEASE_TAG_PATTERN = "v*";
|
|
375
384
|
var D1_GIT_CHECK_FIX = `git ls-remote --tags --refs ${RELEASE_REPO_URL} "${RELEASE_TAG_PATTERN}"`;
|
|
376
|
-
var D2_NODE_FIX = `install
|
|
385
|
+
var D2_NODE_FIX = `nvm install ${NODE_MIN.split(".")[0]}, or install it from https://nodejs.org`;
|
|
386
|
+
function D2_NODE_DETAIL(version) {
|
|
387
|
+
return `Context Mode needs Node ${NODE_MIN} or newer; you have ${version}`;
|
|
388
|
+
}
|
|
389
|
+
var D2_SQLITE_DETAIL = "node:sqlite failed to load";
|
|
390
|
+
var D2_SQLITE_FIX = "run ctx_doctor";
|
|
377
391
|
var D3_PARTS = Object.freeze(["MCP entry", "hook entries", "hook timeout"]);
|
|
378
392
|
var AGENT_HOME_DIR = Object.freeze({
|
|
379
393
|
"claude-code": [".claude"],
|
|
@@ -480,6 +494,8 @@ var SETTINGS_FILE = "settings.json";
|
|
|
480
494
|
var CLAUDE_USER_CONFIG_FILE = ".claude.json";
|
|
481
495
|
var HOOKS_JSON_FILE = "hooks.json";
|
|
482
496
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
497
|
+
var SETUP_BACKUP_DIR_NAME = "backups";
|
|
498
|
+
var SETUP_MANIFEST_FILE = "manifest.json";
|
|
483
499
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
484
500
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
485
501
|
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
@@ -564,6 +580,8 @@ var ATOMIC_TMP_MARK = ".cm-tmp-";
|
|
|
564
580
|
var JSON_INDENT_UNIT = " ";
|
|
565
581
|
var MCP_COMMAND_FIELD = "command";
|
|
566
582
|
var MCP_ARGS_FIELD = "args";
|
|
583
|
+
var MCP_ENV_FIELD = "env";
|
|
584
|
+
var MCP_ENV_VARS_FIELD = "env_vars";
|
|
567
585
|
var ZCODE_MCP_FEATURE_KEY = Object.freeze(["features", "mcp"]);
|
|
568
586
|
var CODEX_OMIT_TOOLS_FROM_FIELD = "omit_tools_from";
|
|
569
587
|
var CODEX_OMIT_DEFERRED = Object.freeze(["deferred"]);
|
|
@@ -1884,7 +1902,7 @@ Examples:
|
|
|
1884
1902
|
// src/cli/commands.ts
|
|
1885
1903
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
1886
1904
|
import { createHash as createHash2 } from "node:crypto";
|
|
1887
|
-
import { existsSync as
|
|
1905
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1888
1906
|
import os from "node:os";
|
|
1889
1907
|
import path13 from "node:path";
|
|
1890
1908
|
|
|
@@ -4708,7 +4726,8 @@ import { basename, dirname as dirname2, join as join2, posix, resolve, win32 } f
|
|
|
4708
4726
|
|
|
4709
4727
|
// src/core/contracts/errors.ts
|
|
4710
4728
|
var ERROR_TEXT = Object.freeze({
|
|
4711
|
-
NODE_TOO_OLD: "
|
|
4729
|
+
NODE_TOO_OLD: "Context Mode needs Node 24.15.0 or newer; you have <v>. Fix: nvm install 24, or install it from https://nodejs.org.",
|
|
4730
|
+
// #1328 D-NODE-OLD-1
|
|
4712
4731
|
NO_SQLITE: "node:sqlite failed to load. Fix: run ctx_doctor.",
|
|
4713
4732
|
DB_GONE: "context.db is gone and its WAL file is still in place. Fix: run ctx_doctor once; it keeps the WAL file in a dated folder and starts a new index.",
|
|
4714
4733
|
// D-ORPHAN-WAL-1
|
|
@@ -4778,7 +4797,7 @@ var CtxError = class extends Error {
|
|
|
4778
4797
|
};
|
|
4779
4798
|
|
|
4780
4799
|
// src/core/project/config-dir.ts
|
|
4781
|
-
var { mkdirSync, realpathSync } = process.getBuiltinModule("node:fs");
|
|
4800
|
+
var { existsSync: existsSync2, mkdirSync, readFileSync, readdirSync: readdirSync2, realpathSync } = process.getBuiltinModule("node:fs");
|
|
4782
4801
|
function homeDirOf(env, platform = process.platform) {
|
|
4783
4802
|
const set2 = (v) => v !== void 0 && v !== "";
|
|
4784
4803
|
if (platform === "win32") {
|
|
@@ -4861,18 +4880,53 @@ function dataRootOf(env, home) {
|
|
|
4861
4880
|
|
|
4862
4881
|
// src/core/ops/doctor-issue.ts
|
|
4863
4882
|
import { spawnSync } from "node:child_process";
|
|
4864
|
-
import { closeSync as closeSync2, existsSync as
|
|
4865
|
-
import { delimiter, join as
|
|
4883
|
+
import { closeSync as closeSync2, existsSync as existsSync10, fstatSync, mkdirSync as mkdirSync4, openSync as openSync2, readFileSync as readFileSync6, readSync as readSync2, realpathSync as realpathSync5, writeFileSync as writeFileSync2 } from "node:fs";
|
|
4884
|
+
import { delimiter, join as join11 } from "node:path";
|
|
4866
4885
|
|
|
4867
4886
|
// src/core/hooks/fallback.ts
|
|
4868
|
-
import { join as
|
|
4887
|
+
import { join as join5, resolve as resolve2 } from "node:path";
|
|
4869
4888
|
|
|
4870
4889
|
// src/core/policy/read-media.ts
|
|
4871
4890
|
import { extname } from "node:path";
|
|
4872
4891
|
var { closeSync, openSync, readSync } = process.getBuiltinModule("node:fs");
|
|
4873
4892
|
|
|
4893
|
+
// src/core/policy/own-file.ts
|
|
4894
|
+
import { extname as extname2, join as join4 } from "node:path";
|
|
4895
|
+
|
|
4896
|
+
// src/core/project/contain.ts
|
|
4897
|
+
import { dirname as dirname3, join as join3, relative, sep } from "node:path";
|
|
4898
|
+
var { lstatSync: lstatSync2, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
4899
|
+
function components(p3) {
|
|
4900
|
+
return p3.split(sep).filter((c3) => c3 !== "");
|
|
4901
|
+
}
|
|
4902
|
+
function reachedThroughLink(root, p3) {
|
|
4903
|
+
const rel = relative(root, p3);
|
|
4904
|
+
const steps = components(rel);
|
|
4905
|
+
if (rel === "" || steps[0] === ".." || rel === p3) return false;
|
|
4906
|
+
let at = root;
|
|
4907
|
+
for (const step of steps) {
|
|
4908
|
+
at = join3(at, step);
|
|
4909
|
+
try {
|
|
4910
|
+
if (lstatSync2(at).isSymbolicLink()) return true;
|
|
4911
|
+
} catch {
|
|
4912
|
+
return false;
|
|
4913
|
+
}
|
|
4914
|
+
}
|
|
4915
|
+
return false;
|
|
4916
|
+
}
|
|
4917
|
+
|
|
4874
4918
|
// src/core/hooks/fallback.ts
|
|
4875
4919
|
var fs = process.getBuiltinModule("node:fs");
|
|
4920
|
+
function nodeTooOld(version) {
|
|
4921
|
+
const a2 = (version.startsWith("v") ? version.slice(1) : version).split(".");
|
|
4922
|
+
const b3 = NODE_MIN.split(".");
|
|
4923
|
+
for (let i2 = 0; i2 < b3.length; i2++) {
|
|
4924
|
+
const x2 = Number(a2[i2] ?? 0) || 0;
|
|
4925
|
+
const y2 = Number(b3[i2]);
|
|
4926
|
+
if (x2 !== y2) return x2 < y2;
|
|
4927
|
+
}
|
|
4928
|
+
return false;
|
|
4929
|
+
}
|
|
4876
4930
|
|
|
4877
4931
|
// src/core/store/schema.ts
|
|
4878
4932
|
var PRAGMAS = `
|
|
@@ -4961,20 +5015,20 @@ CREATE VIRTUAL TABLE line_units USING fts5(
|
|
|
4961
5015
|
`;
|
|
4962
5016
|
|
|
4963
5017
|
// src/core/store/db.ts
|
|
4964
|
-
var { existsSync:
|
|
5018
|
+
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
4965
5019
|
|
|
4966
5020
|
// src/core/ops/doctor-config.ts
|
|
4967
|
-
import { existsSync as
|
|
4968
|
-
import { join as
|
|
5021
|
+
import { existsSync as existsSync9, readdirSync as readdirSync5 } from "node:fs";
|
|
5022
|
+
import { join as join10 } from "node:path";
|
|
4969
5023
|
|
|
4970
5024
|
// src/core/ops/detect-v1.ts
|
|
4971
|
-
import { existsSync as
|
|
5025
|
+
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync3, readFileSync as readFileSync3 } from "node:fs";
|
|
4972
5026
|
import { tmpdir } from "node:os";
|
|
4973
|
-
import { join as
|
|
5027
|
+
import { join as join8 } from "node:path";
|
|
4974
5028
|
|
|
4975
5029
|
// src/core/ops/host-config.ts
|
|
4976
|
-
import { existsSync as
|
|
4977
|
-
import { dirname as
|
|
5030
|
+
import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
|
|
5031
|
+
import { dirname as dirname5, join as join7 } from "node:path";
|
|
4978
5032
|
|
|
4979
5033
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
4980
5034
|
var KEYS2 = {
|
|
@@ -7083,8 +7137,8 @@ function atomicWriteFile(file, text2, opts = {}) {
|
|
|
7083
7137
|
}
|
|
7084
7138
|
|
|
7085
7139
|
// src/core/ops/bundle-dir.ts
|
|
7086
|
-
import { existsSync as
|
|
7087
|
-
import { dirname as
|
|
7140
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
7141
|
+
import { dirname as dirname4, join as join6 } from "node:path";
|
|
7088
7142
|
import { fileURLToPath } from "node:url";
|
|
7089
7143
|
|
|
7090
7144
|
// src/core/ops/host-text.ts
|
|
@@ -7480,28 +7534,6 @@ function editHostConfigText(agent, path15, text2, format, wanted) {
|
|
|
7480
7534
|
return applyEdits(agent, path15, text2, format, wanted);
|
|
7481
7535
|
}
|
|
7482
7536
|
|
|
7483
|
-
// src/core/project/contain.ts
|
|
7484
|
-
import { dirname as dirname5, join as join6, relative, sep } from "node:path";
|
|
7485
|
-
var { lstatSync: lstatSync2, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
7486
|
-
function components(p3) {
|
|
7487
|
-
return p3.split(sep).filter((c3) => c3 !== "");
|
|
7488
|
-
}
|
|
7489
|
-
function reachedThroughLink(root, p3) {
|
|
7490
|
-
const rel = relative(root, p3);
|
|
7491
|
-
const steps = components(rel);
|
|
7492
|
-
if (rel === "" || steps[0] === ".." || rel === p3) return false;
|
|
7493
|
-
let at = root;
|
|
7494
|
-
for (const step of steps) {
|
|
7495
|
-
at = join6(at, step);
|
|
7496
|
-
try {
|
|
7497
|
-
if (lstatSync2(at).isSymbolicLink()) return true;
|
|
7498
|
-
} catch {
|
|
7499
|
-
return false;
|
|
7500
|
-
}
|
|
7501
|
-
}
|
|
7502
|
-
return false;
|
|
7503
|
-
}
|
|
7504
|
-
|
|
7505
7537
|
// src/core/ops/detect-v1.ts
|
|
7506
7538
|
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7507
7539
|
var keyPath = (...parts) => parts.join(".");
|
|
@@ -7545,14 +7577,14 @@ function stripJsonc(text2) {
|
|
|
7545
7577
|
}
|
|
7546
7578
|
function readJson(file) {
|
|
7547
7579
|
try {
|
|
7548
|
-
return JSON.parse(stripJsonc(hostText(
|
|
7580
|
+
return JSON.parse(stripJsonc(hostText(readFileSync3(file, "utf8"))));
|
|
7549
7581
|
} catch {
|
|
7550
7582
|
return void 0;
|
|
7551
7583
|
}
|
|
7552
7584
|
}
|
|
7553
7585
|
function readText(file) {
|
|
7554
7586
|
try {
|
|
7555
|
-
return hostText(
|
|
7587
|
+
return hostText(readFileSync3(file, "utf8"));
|
|
7556
7588
|
} catch {
|
|
7557
7589
|
return "";
|
|
7558
7590
|
}
|
|
@@ -7609,7 +7641,7 @@ function flatCommands(events2, prefix) {
|
|
|
7609
7641
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
7610
7642
|
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep3) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep3) + sep3));
|
|
7611
7643
|
function dataDir(dir, reason, out2) {
|
|
7612
|
-
if (
|
|
7644
|
+
if (existsSync6(dir)) out2.push(finding(dir, "", reason));
|
|
7613
7645
|
}
|
|
7614
7646
|
function mcpEntry(file, doc, out2) {
|
|
7615
7647
|
if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
|
|
@@ -7617,7 +7649,7 @@ function mcpEntry(file, doc, out2) {
|
|
|
7617
7649
|
}
|
|
7618
7650
|
}
|
|
7619
7651
|
function claudeShapeSettings(agentHome, out2) {
|
|
7620
|
-
const file =
|
|
7652
|
+
const file = join8(agentHome, SETTINGS_FILE);
|
|
7621
7653
|
const doc = readJson(file);
|
|
7622
7654
|
for (const c3 of nestedCommands(doc)) {
|
|
7623
7655
|
if (c3.command.includes(V1_CACHE_HEAL_NAME)) out2.push(finding(file, c3.path, V1_REASON.cacheHealHook));
|
|
@@ -7637,63 +7669,64 @@ function v1HookFile(file, out2) {
|
|
|
7637
7669
|
function scanClaudeCode(home, agentHome, out2) {
|
|
7638
7670
|
claudeShapeSettings(agentHome, out2);
|
|
7639
7671
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
7640
|
-
const file =
|
|
7641
|
-
if (
|
|
7672
|
+
const file = join8(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
7673
|
+
if (existsSync6(file)) out2.push(finding(file, "", V1_REASON.cacheHealFile));
|
|
7642
7674
|
}
|
|
7643
|
-
const userFile =
|
|
7675
|
+
const userFile = join8(home, CLAUDE_USER_CONFIG_FILE);
|
|
7644
7676
|
mcpEntry(userFile, readJson(userFile), out2);
|
|
7645
|
-
dataDir(
|
|
7677
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7646
7678
|
}
|
|
7647
7679
|
function scanCodex(agentHome, out2) {
|
|
7648
|
-
const hooksFile =
|
|
7680
|
+
const hooksFile = join8(agentHome, HOOKS_JSON_FILE);
|
|
7649
7681
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7650
7682
|
if (c3.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c3.command)) {
|
|
7651
7683
|
out2.push(finding(hooksFile, c3.path, V1_REASON.codexHook));
|
|
7652
7684
|
}
|
|
7653
7685
|
}
|
|
7654
|
-
const tomlFile =
|
|
7686
|
+
const tomlFile = join8(agentHome, CONFIG_TOML_FILE);
|
|
7655
7687
|
const config = readTomlValue(tomlFile);
|
|
7656
7688
|
for (const span of readTomlTables(tomlFile)) {
|
|
7657
7689
|
if (span.path[0] !== V1_TOML_SECTION_ROOT || span.path[1] !== SERVER_KEY) continue;
|
|
7658
7690
|
if (span.path.length === 2 && isV2McpTable(hostConfigValueAt(config, span.path))) continue;
|
|
7691
|
+
if (span.path.length === 3 && span.path[2] === MCP_ENV_FIELD && isV2McpTable(hostConfigValueAt(config, span.path.slice(0, 2)))) continue;
|
|
7659
7692
|
out2.push(finding(tomlFile, span.header.trim(), V1_REASON.codexToml));
|
|
7660
7693
|
}
|
|
7661
|
-
dataDir(
|
|
7694
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7662
7695
|
}
|
|
7663
7696
|
function scanGemini(agentHome, out2) {
|
|
7664
|
-
const file =
|
|
7697
|
+
const file = join8(agentHome, SETTINGS_FILE);
|
|
7665
7698
|
for (const c3 of nestedCommands(readJson(file))) {
|
|
7666
7699
|
if (c3.command.includes(SERVER_KEY)) out2.push(finding(file, c3.path, V1_REASON.hook));
|
|
7667
7700
|
}
|
|
7668
|
-
dataDir(
|
|
7701
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
|
|
7669
7702
|
}
|
|
7670
7703
|
function scanVscode(agentHome, project, out2) {
|
|
7671
7704
|
if (project !== void 0) {
|
|
7672
|
-
v1HookFile(
|
|
7673
|
-
const mcpFile =
|
|
7705
|
+
v1HookFile(join8(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7706
|
+
const mcpFile = join8(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
7674
7707
|
const doc = readJson(mcpFile);
|
|
7675
7708
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
7676
7709
|
const entry2 = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
7677
7710
|
if (isObj(entry2) && (entry2.command === V1_BIN_COMMAND || listOf(entry2.args).some((a2) => a2 === V1_BIN_COMMAND))) {
|
|
7678
7711
|
out2.push(finding(mcpFile, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
7679
7712
|
}
|
|
7680
|
-
const sessions =
|
|
7713
|
+
const sessions = join8(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
7681
7714
|
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out2);
|
|
7682
7715
|
}
|
|
7683
|
-
dataDir(
|
|
7716
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7684
7717
|
}
|
|
7685
7718
|
function jsonFiles(dir) {
|
|
7686
7719
|
try {
|
|
7687
|
-
return
|
|
7720
|
+
return readdirSync3(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
7688
7721
|
} catch {
|
|
7689
7722
|
return [];
|
|
7690
7723
|
}
|
|
7691
7724
|
}
|
|
7692
7725
|
function scanKiro(agentHome, project, out2) {
|
|
7693
|
-
const agentsDir =
|
|
7694
|
-
const defaultFile =
|
|
7726
|
+
const agentsDir = join8(agentHome, KIRO_AGENTS_DIR);
|
|
7727
|
+
const defaultFile = join8(agentHome, ...KIRO_AGENT_FILE);
|
|
7695
7728
|
for (const name of jsonFiles(agentsDir)) {
|
|
7696
|
-
const file =
|
|
7729
|
+
const file = join8(agentsDir, name);
|
|
7697
7730
|
const doc = readJson(file);
|
|
7698
7731
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
7699
7732
|
out2.push(finding(file, "", V1_REASON.kiroAgentFile));
|
|
@@ -7704,31 +7737,31 @@ function scanKiro(agentHome, project, out2) {
|
|
|
7704
7737
|
if (isV1Hook(c3.command)) out2.push(finding(file, c3.path, V1_REASON.kiroHook));
|
|
7705
7738
|
}
|
|
7706
7739
|
}
|
|
7707
|
-
const steeringDocs = [
|
|
7708
|
-
if (project !== void 0) steeringDocs.push(
|
|
7740
|
+
const steeringDocs = [join8(agentHome, ...KIRO_STEERING_FILE)];
|
|
7741
|
+
if (project !== void 0) steeringDocs.push(join8(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
7709
7742
|
for (const file of steeringDocs) {
|
|
7710
|
-
if (
|
|
7743
|
+
if (existsSync6(file)) out2.push(finding(file, "", V1_REASON.kiroSteering));
|
|
7711
7744
|
}
|
|
7712
|
-
dataDir(
|
|
7745
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7713
7746
|
}
|
|
7714
7747
|
function piNpmIsCurrent(piAgentDir) {
|
|
7715
|
-
const doc = readJson(
|
|
7748
|
+
const doc = readJson(join8(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
7716
7749
|
const version = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
7717
7750
|
return Number.parseInt(version, 10) >= PI_CURRENT_MAJOR;
|
|
7718
7751
|
}
|
|
7719
7752
|
function scanPi(piAgentDir, agentHome, out2) {
|
|
7720
|
-
const file =
|
|
7753
|
+
const file = join8(piAgentDir, SETTINGS_FILE);
|
|
7721
7754
|
const doc = readJson(file);
|
|
7722
7755
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
|
|
7723
7756
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
7724
7757
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
|
|
7725
7758
|
if (spec === PI_GIT_PACKAGE) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piGit));
|
|
7726
7759
|
});
|
|
7727
|
-
dataDir(
|
|
7760
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7728
7761
|
}
|
|
7729
7762
|
function scanOpencode(agentHome, out2) {
|
|
7730
7763
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
7731
|
-
const file =
|
|
7764
|
+
const file = join8(agentHome, name);
|
|
7732
7765
|
const doc = readJson(file);
|
|
7733
7766
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
7734
7767
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i2) => {
|
|
@@ -7739,13 +7772,13 @@ function scanOpencode(agentHome, out2) {
|
|
|
7739
7772
|
}
|
|
7740
7773
|
}
|
|
7741
7774
|
function scanZcode(agentHome, out2) {
|
|
7742
|
-
const configFile =
|
|
7775
|
+
const configFile = join8(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
7743
7776
|
const config = readJson(configFile);
|
|
7744
7777
|
const events2 = isObj(config) && isObj(config[HOOKS_KEY]) ? config[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
7745
7778
|
for (const c3 of flatCommands(events2, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
7746
7779
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(configFile, c3.path, V1_REASON.zcodeHook));
|
|
7747
7780
|
}
|
|
7748
|
-
const hooksFile =
|
|
7781
|
+
const hooksFile = join8(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
7749
7782
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7750
7783
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(hooksFile, c3.path, V1_REASON.zcodeHook));
|
|
7751
7784
|
}
|
|
@@ -7769,14 +7802,14 @@ function firstTmpMatch(dir) {
|
|
|
7769
7802
|
}
|
|
7770
7803
|
}
|
|
7771
7804
|
function scanAll(home, tmp, out2) {
|
|
7772
|
-
const root =
|
|
7773
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
7805
|
+
const root = join8(home, DATA_ROOT.slice(1));
|
|
7806
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join8(root, name), V1_REASON.dataRoot, out2);
|
|
7774
7807
|
if (firstTmpMatch(tmp) !== null) out2.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
7775
7808
|
}
|
|
7776
7809
|
function detectV1(agent, home, scope = {}) {
|
|
7777
7810
|
const out2 = [];
|
|
7778
7811
|
const project = scope.project;
|
|
7779
|
-
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir :
|
|
7812
|
+
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir : join8(home, ...AGENT_HOME_DIR[agent]);
|
|
7780
7813
|
switch (agent) {
|
|
7781
7814
|
case "claude-code":
|
|
7782
7815
|
scanClaudeCode(home, agentHome, out2);
|
|
@@ -7789,11 +7822,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7789
7822
|
break;
|
|
7790
7823
|
case "qwen":
|
|
7791
7824
|
claudeShapeSettings(agentHome, out2);
|
|
7792
|
-
dataDir(
|
|
7825
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7793
7826
|
break;
|
|
7794
7827
|
case "copilot-cli":
|
|
7795
|
-
v1HookFile(
|
|
7796
|
-
dataDir(
|
|
7828
|
+
v1HookFile(join8(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7829
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7797
7830
|
break;
|
|
7798
7831
|
case "vscode":
|
|
7799
7832
|
scanVscode(agentHome, project, out2);
|
|
@@ -7802,7 +7835,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7802
7835
|
scanKiro(agentHome, project, out2);
|
|
7803
7836
|
break;
|
|
7804
7837
|
case "pi":
|
|
7805
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
7838
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join8(agentHome, PI_AGENT_DIR), agentHome, out2);
|
|
7806
7839
|
break;
|
|
7807
7840
|
// D-WIN-PIDIR-1: empty is unset
|
|
7808
7841
|
case "opencode":
|
|
@@ -7817,12 +7850,12 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7817
7850
|
}
|
|
7818
7851
|
|
|
7819
7852
|
// src/core/ops/plugin-root.ts
|
|
7820
|
-
import { existsSync as
|
|
7821
|
-
import { dirname as dirname6, isAbsolute, join as
|
|
7853
|
+
import { existsSync as existsSync7, readdirSync as readdirSync4, readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
|
|
7854
|
+
import { dirname as dirname6, isAbsolute, join as join9, sep as sep2 } from "node:path";
|
|
7822
7855
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
7823
7856
|
|
|
7824
7857
|
// src/setup/pi-gate.ts
|
|
7825
|
-
import { existsSync as
|
|
7858
|
+
import { existsSync as existsSync8, readFileSync as readFileSync5, realpathSync as realpathSync4 } from "node:fs";
|
|
7826
7859
|
import path3 from "node:path";
|
|
7827
7860
|
var OWN_FILE = "pi/index.js";
|
|
7828
7861
|
var EXTENSIONS_KEY = "extensions";
|
|
@@ -7831,9 +7864,9 @@ var TRUST_FILE = "trust.json";
|
|
|
7831
7864
|
var ALWAYS = "always";
|
|
7832
7865
|
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
7833
7866
|
function load(file) {
|
|
7834
|
-
if (!
|
|
7867
|
+
if (!existsSync8(file)) return void 0;
|
|
7835
7868
|
try {
|
|
7836
|
-
return { file, doc: parseHostConfig("pi", file, hostText(
|
|
7869
|
+
return { file, doc: parseHostConfig("pi", file, hostText(readFileSync5(file, "utf8")), "json") };
|
|
7837
7870
|
} catch {
|
|
7838
7871
|
return void 0;
|
|
7839
7872
|
}
|
|
@@ -7941,7 +7974,7 @@ function formUrl(title, summary) {
|
|
|
7941
7974
|
}
|
|
7942
7975
|
|
|
7943
7976
|
// src/setup/registry.ts
|
|
7944
|
-
import { existsSync as
|
|
7977
|
+
import { existsSync as existsSync11, realpathSync as realpathSync6 } from "node:fs";
|
|
7945
7978
|
import path4 from "node:path";
|
|
7946
7979
|
|
|
7947
7980
|
// src/setup/hook-shapes.ts
|
|
@@ -8001,7 +8034,7 @@ var SERVER_BUNDLE = "server.mjs";
|
|
|
8001
8034
|
var HOOK_BUNDLE = "hook.mjs";
|
|
8002
8035
|
var AGENT_FLAG = "--agent";
|
|
8003
8036
|
var LOCK_FILE = "setup.lock";
|
|
8004
|
-
var BACKUP_DIR =
|
|
8037
|
+
var BACKUP_DIR = SETUP_BACKUP_DIR_NAME;
|
|
8005
8038
|
var PLUGIN_ID = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
8006
8039
|
var SKILLS_DIR_NAME = "skills";
|
|
8007
8040
|
var INSTRUCTION_FILES = Object.freeze([
|
|
@@ -8078,7 +8111,7 @@ var NATIVE_PLUGIN = {
|
|
|
8078
8111
|
};
|
|
8079
8112
|
var CELLAR_SEGMENT = "/Cellar/";
|
|
8080
8113
|
var NODE_BIN = ["bin", "node"];
|
|
8081
|
-
var REAL_FS = { exists:
|
|
8114
|
+
var REAL_FS = { exists: existsSync11, real: (p3) => realpathSync6.native(p3) };
|
|
8082
8115
|
function stableNodePath(execPath, fs2 = REAL_FS) {
|
|
8083
8116
|
const at = execPath.indexOf(CELLAR_SEGMENT);
|
|
8084
8117
|
if (at < 0) return execPath;
|
|
@@ -8118,7 +8151,10 @@ function configFor(ctx, id) {
|
|
|
8118
8151
|
const file = id === "vscode" ? ownMcpFileOf(id, own2.file, ctx.env, ctx.home) : agentPath(ctx, id, own2.file);
|
|
8119
8152
|
const format = file.endsWith(".toml") ? "toml" : id === "vscode" ? "jsonc" : "json";
|
|
8120
8153
|
const also = own2.also?.map(([k, v]) => [k, v]);
|
|
8121
|
-
|
|
8154
|
+
const codexHome = id === "codex" ? ctx.env[CODEX_HOME_ENV2] : void 0;
|
|
8155
|
+
const base = ownMcpValue(id, node, server);
|
|
8156
|
+
const value = codexHome !== void 0 && codexHome !== "" ? { ...base, [MCP_ENV_FIELD]: { [CODEX_HOME_ENV2]: codexHome } } : base;
|
|
8157
|
+
return { file, format, key: own2.key, value, ...also ? { also } : {} };
|
|
8122
8158
|
}
|
|
8123
8159
|
if (id === "opencode") {
|
|
8124
8160
|
return {
|
|
@@ -8268,7 +8304,7 @@ function assertWritable(row, file) {
|
|
|
8268
8304
|
}
|
|
8269
8305
|
|
|
8270
8306
|
// src/setup/gemini-gate.ts
|
|
8271
|
-
import { existsSync as
|
|
8307
|
+
import { existsSync as existsSync12, readFileSync as readFileSync7 } from "node:fs";
|
|
8272
8308
|
import path5 from "node:path";
|
|
8273
8309
|
var GEMINI_DIR = ".gemini";
|
|
8274
8310
|
var SETTINGS_FILE2 = "settings.json";
|
|
@@ -8288,9 +8324,9 @@ function systemDefaultsPath(env) {
|
|
|
8288
8324
|
return set2 ? set2 : path5.join(path5.dirname(systemSettingsPath(env)), SYSTEM_DEFAULTS_FILE);
|
|
8289
8325
|
}
|
|
8290
8326
|
function load2(file) {
|
|
8291
|
-
if (!
|
|
8327
|
+
if (!existsSync12(file)) return void 0;
|
|
8292
8328
|
try {
|
|
8293
|
-
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(
|
|
8329
|
+
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync7(file, "utf8")), "jsonc") };
|
|
8294
8330
|
} catch {
|
|
8295
8331
|
return void 0;
|
|
8296
8332
|
}
|
|
@@ -8322,7 +8358,7 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
8322
8358
|
}
|
|
8323
8359
|
|
|
8324
8360
|
// src/setup/zcode-gate.ts
|
|
8325
|
-
import { existsSync as
|
|
8361
|
+
import { existsSync as existsSync13, readFileSync as readFileSync8 } from "node:fs";
|
|
8326
8362
|
import path6 from "node:path";
|
|
8327
8363
|
var OWN_AGENT2 = "zcode";
|
|
8328
8364
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
@@ -8414,10 +8450,10 @@ function zcodeSchemaBad(doc) {
|
|
|
8414
8450
|
}
|
|
8415
8451
|
function zcodeConfigGate(home) {
|
|
8416
8452
|
const file = path6.join(home, ".zcode", "cli", "config.json");
|
|
8417
|
-
if (!
|
|
8453
|
+
if (!existsSync13(file)) return void 0;
|
|
8418
8454
|
let doc;
|
|
8419
8455
|
try {
|
|
8420
|
-
doc = parseHostConfig(OWN_AGENT2, file, hostText(
|
|
8456
|
+
doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync8(file, "utf8")), "json");
|
|
8421
8457
|
} catch {
|
|
8422
8458
|
return void 0;
|
|
8423
8459
|
}
|
|
@@ -8427,7 +8463,7 @@ function zcodeConfigGate(home) {
|
|
|
8427
8463
|
}
|
|
8428
8464
|
|
|
8429
8465
|
// src/setup/vscode-gate.ts
|
|
8430
|
-
import { existsSync as
|
|
8466
|
+
import { existsSync as existsSync14, readFileSync as readFileSync9 } from "node:fs";
|
|
8431
8467
|
import path7 from "node:path";
|
|
8432
8468
|
var SETTINGS_FILE3 = "settings.json";
|
|
8433
8469
|
var WORKSPACE_DIR = ".vscode";
|
|
@@ -8436,9 +8472,9 @@ var LOCATIONS_KEY = "chat.hookFilesLocations";
|
|
|
8436
8472
|
var OWN_LOCATION = "~/.copilot/hooks";
|
|
8437
8473
|
var MANAGED_KEYS = ["allowManagedHooksOnly", "strictPluginOnlyCustomization"];
|
|
8438
8474
|
function load3(file) {
|
|
8439
|
-
if (!
|
|
8475
|
+
if (!existsSync14(file)) return void 0;
|
|
8440
8476
|
try {
|
|
8441
|
-
return { file, doc: parseHostConfig("vscode", file, hostText(
|
|
8477
|
+
return { file, doc: parseHostConfig("vscode", file, hostText(readFileSync9(file, "utf8")), "jsonc") };
|
|
8442
8478
|
} catch {
|
|
8443
8479
|
return void 0;
|
|
8444
8480
|
}
|
|
@@ -8478,7 +8514,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
|
|
|
8478
8514
|
}
|
|
8479
8515
|
|
|
8480
8516
|
// src/setup/qwen-gate.ts
|
|
8481
|
-
import { existsSync as
|
|
8517
|
+
import { existsSync as existsSync15, readFileSync as readFileSync10 } from "node:fs";
|
|
8482
8518
|
import path8 from "node:path";
|
|
8483
8519
|
var KEY = "disableAllHooks";
|
|
8484
8520
|
var SETTINGS = "settings.json";
|
|
@@ -8494,10 +8530,10 @@ function settingsFiles(env, home, cwd, platform) {
|
|
|
8494
8530
|
}
|
|
8495
8531
|
function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
|
|
8496
8532
|
for (const file of settingsFiles(env, home, cwd, platform)) {
|
|
8497
|
-
if (!
|
|
8533
|
+
if (!existsSync15(file)) continue;
|
|
8498
8534
|
let value;
|
|
8499
8535
|
try {
|
|
8500
|
-
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(
|
|
8536
|
+
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(readFileSync10(file, "utf8")), "jsonc"), [KEY]);
|
|
8501
8537
|
} catch {
|
|
8502
8538
|
continue;
|
|
8503
8539
|
}
|
|
@@ -8508,7 +8544,7 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
|
|
|
8508
8544
|
|
|
8509
8545
|
// src/setup/codex-trust.ts
|
|
8510
8546
|
import { createHash } from "node:crypto";
|
|
8511
|
-
import { existsSync as
|
|
8547
|
+
import { existsSync as existsSync16, realpathSync as realpathSync7 } from "node:fs";
|
|
8512
8548
|
import path10 from "node:path";
|
|
8513
8549
|
import { spawn, spawnSync as spawnSync3 } from "node:child_process";
|
|
8514
8550
|
|
|
@@ -8617,7 +8653,7 @@ function snake(name) {
|
|
|
8617
8653
|
function realFile(file) {
|
|
8618
8654
|
let dir = path10.resolve(file);
|
|
8619
8655
|
const rest = [];
|
|
8620
|
-
while (!
|
|
8656
|
+
while (!existsSync16(dir) && path10.dirname(dir) !== dir) {
|
|
8621
8657
|
rest.unshift(path10.basename(dir));
|
|
8622
8658
|
dir = path10.dirname(dir);
|
|
8623
8659
|
}
|
|
@@ -8917,7 +8953,7 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
8917
8953
|
|
|
8918
8954
|
// src/setup/engine.ts
|
|
8919
8955
|
import { spawn as spawn3, spawnSync as spawnSync4 } from "node:child_process";
|
|
8920
|
-
import { closeSync as closeSync3, existsSync as
|
|
8956
|
+
import { closeSync as closeSync3, existsSync as existsSync17, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync3, readFileSync as readFileSync11, readSync as readSync3, readdirSync as readdirSync6, realpathSync as realpathSync9, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
8921
8957
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8922
8958
|
import path12 from "node:path";
|
|
8923
8959
|
|
|
@@ -8992,7 +9028,7 @@ var HOOK_ROUNDS = 5;
|
|
|
8992
9028
|
var P95 = 0.95;
|
|
8993
9029
|
var VERIFY_TIMEOUT_MS = 1e4;
|
|
8994
9030
|
var INSTALL_TIMEOUT_MS = 12e4;
|
|
8995
|
-
var MANIFEST =
|
|
9031
|
+
var MANIFEST = SETUP_MANIFEST_FILE;
|
|
8996
9032
|
var MANIFEST_DONE = "manifest.removed.json";
|
|
8997
9033
|
var FILES = "files";
|
|
8998
9034
|
var V1_HOOK_MARK = "context-mode hook";
|
|
@@ -9015,9 +9051,9 @@ function isNativeBinary(file) {
|
|
|
9015
9051
|
function owningPackage(dir) {
|
|
9016
9052
|
for (let d = dir; ; d = path12.dirname(d)) {
|
|
9017
9053
|
const f2 = path12.join(d, "package.json");
|
|
9018
|
-
if (
|
|
9054
|
+
if (existsSync17(f2)) {
|
|
9019
9055
|
try {
|
|
9020
|
-
return String(JSON.parse(hostText(
|
|
9056
|
+
return String(JSON.parse(hostText(readFileSync11(f2, "utf8"))).name);
|
|
9021
9057
|
} catch {
|
|
9022
9058
|
return void 0;
|
|
9023
9059
|
}
|
|
@@ -9033,7 +9069,7 @@ function hostBin(bin, env, platform = process.platform) {
|
|
|
9033
9069
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
9034
9070
|
const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
|
|
9035
9071
|
for (const f2 of [own2, ...real2.extra.map((p3) => path12.join(dir, ...p3))]) {
|
|
9036
|
-
if (!f2 || !
|
|
9072
|
+
if (!f2 || !existsSync17(f2) || !statSync2(f2).isFile()) continue;
|
|
9037
9073
|
const file = realpathSync9(f2);
|
|
9038
9074
|
if (isNativeBinary(file) || owningPackage(path12.dirname(file)) === real2.pkg) return { file, shims };
|
|
9039
9075
|
shims.push(f2);
|
|
@@ -9050,10 +9086,10 @@ function runBin(bin, args, env, input, timeout = VERIFY_TIMEOUT_MS) {
|
|
|
9050
9086
|
return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout, maxBuffer: Infinity });
|
|
9051
9087
|
}
|
|
9052
9088
|
function readOr(file) {
|
|
9053
|
-
return
|
|
9089
|
+
return existsSync17(file) ? hostText(readFileSync11(file, "utf8")) : void 0;
|
|
9054
9090
|
}
|
|
9055
9091
|
function readRaw(file) {
|
|
9056
|
-
return
|
|
9092
|
+
return existsSync17(file) ? readFileSync11(file, "utf8") : void 0;
|
|
9057
9093
|
}
|
|
9058
9094
|
var atomicWrite = atomicWriteFile;
|
|
9059
9095
|
function pidAlive(pid) {
|
|
@@ -9198,7 +9234,7 @@ function isNativeSpec(e) {
|
|
|
9198
9234
|
function isStaleOwnPlugin(e, entry2) {
|
|
9199
9235
|
if (typeof e !== "string" || e === entry2 || !path12.isAbsolute(e)) return false;
|
|
9200
9236
|
if (e === path12.join(entry2, ...OPENCODE_PLUGIN_PATH)) return true;
|
|
9201
|
-
if (
|
|
9237
|
+
if (existsSync17(e)) return false;
|
|
9202
9238
|
const seg = e.split("\\").join("/").split("/");
|
|
9203
9239
|
const n3 = seg.length;
|
|
9204
9240
|
if (n3 >= 3 && seg[n3 - 1] === "plugin.js" && seg[n3 - 2] === "opencode" && seg[n3 - 3] === "context-mode") return true;
|
|
@@ -9262,8 +9298,8 @@ function planSkills(row, edits) {
|
|
|
9262
9298
|
const s = row.skillInstall;
|
|
9263
9299
|
if (s.kind !== "dir") return;
|
|
9264
9300
|
for (const f2 of s.files) {
|
|
9265
|
-
if (!
|
|
9266
|
-
const after = renderSkill(
|
|
9301
|
+
if (!existsSync17(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
|
|
9302
|
+
const after = renderSkill(readFileSync11(f2.src, "utf8"), s.prefixes);
|
|
9267
9303
|
const before = readRaw(f2.file);
|
|
9268
9304
|
if (before !== after) edits.push({ plain: true, file: f2.file, before, after, changes: [{ file: f2.file, path: f2.name, before: before === void 0 ? null : "old", after: "SKILL.md" }] });
|
|
9269
9305
|
}
|
|
@@ -9275,7 +9311,7 @@ function planRow(row, listed, stale, env, disabled = false) {
|
|
|
9275
9311
|
const before = readOr(c3.file);
|
|
9276
9312
|
let res;
|
|
9277
9313
|
try {
|
|
9278
|
-
res = editHostConfigText(row.id, c3.file, before ?? "", c3.format,
|
|
9314
|
+
res = editHostConfigText(row.id, c3.file, before ?? "", c3.format, ownConfigEdits(row, c3, before ?? ""));
|
|
9279
9315
|
} catch (e) {
|
|
9280
9316
|
if (e instanceof CtxError) throw new Error(parseFail(row, c3.file));
|
|
9281
9317
|
throw e;
|
|
@@ -9397,7 +9433,7 @@ function hookEnabledCheck(row, status) {
|
|
|
9397
9433
|
}
|
|
9398
9434
|
function packageVersion(pkgDir) {
|
|
9399
9435
|
try {
|
|
9400
|
-
const v = JSON.parse(hostText(
|
|
9436
|
+
const v = JSON.parse(hostText(readFileSync11(path12.join(pkgDir, "package.json"), "utf8"))).version;
|
|
9401
9437
|
return typeof v === "string" ? v : void 0;
|
|
9402
9438
|
} catch {
|
|
9403
9439
|
return void 0;
|
|
@@ -9422,6 +9458,12 @@ function copyCheck(row, pkgDir) {
|
|
|
9422
9458
|
if (old === void 0) return { name: "copy", ok: true };
|
|
9423
9459
|
return { name: "copy", ok: false, detail: `${c3.host} runs context-mode ${old}, the installed package is ${pkg}; run ${c3.bin} ${c3.refresh.join(" ")}` };
|
|
9424
9460
|
}
|
|
9461
|
+
function degradedDetail(node, env) {
|
|
9462
|
+
const r2 = spawnSync4(node, ["-p", "process.version"], { env, encoding: "utf8", timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
|
|
9463
|
+
const v = `${r2.stdout ?? ""}`.trim();
|
|
9464
|
+
if (v && nodeTooOld(v)) return `Node too old: ${D2_NODE_DETAIL(v)}. Fix: ${D2_NODE_FIX}`;
|
|
9465
|
+
return `only ctx_doctor is served: ${D2_SQLITE_DETAIL} under ${node}${v ? ` ${v}` : ""}. Fix: ${D2_SQLITE_FIX}`;
|
|
9466
|
+
}
|
|
9425
9467
|
function mcpCheck(cmd, env) {
|
|
9426
9468
|
return new Promise((resolve3) => {
|
|
9427
9469
|
const child = spawn3(cmd[0], cmd.slice(1), { env, stdio: ["pipe", "pipe", "ignore"], detached: process.platform !== "win32", windowsHide: true });
|
|
@@ -9462,7 +9504,7 @@ function mcpCheck(cmd, env) {
|
|
|
9462
9504
|
const want = [...TOOL_ORDER].sort();
|
|
9463
9505
|
const got = [...tools].sort();
|
|
9464
9506
|
const ok = JSON.stringify(got) === JSON.stringify(want);
|
|
9465
|
-
done(ok, ok ? void 0 : `tools/list returned ${got.join(",")}, expected ${want.join(",")}`);
|
|
9507
|
+
done(ok, ok ? void 0 : got.length === 1 && got[0] === "ctx_doctor" ? degradedDetail(cmd[0], env) : `tools/list returned ${got.join(",")}, expected ${want.join(",")}`);
|
|
9466
9508
|
}
|
|
9467
9509
|
}
|
|
9468
9510
|
});
|
|
@@ -9513,11 +9555,29 @@ function hookCheck(row, env) {
|
|
|
9513
9555
|
}
|
|
9514
9556
|
return best;
|
|
9515
9557
|
}
|
|
9558
|
+
function ownConfigEdits(row, c3, text2) {
|
|
9559
|
+
const edits = configEdits(c3);
|
|
9560
|
+
if (row.id !== "codex" || !isObj5(c3.value)) return edits;
|
|
9561
|
+
let cur;
|
|
9562
|
+
try {
|
|
9563
|
+
cur = hostConfigValueAt(parseHostConfig(row.id, c3.file, text2, c3.format), c3.key);
|
|
9564
|
+
} catch {
|
|
9565
|
+
return edits;
|
|
9566
|
+
}
|
|
9567
|
+
if (!isObj5(cur)) return edits;
|
|
9568
|
+
const value = { ...c3.value };
|
|
9569
|
+
const userEnv = cur[MCP_ENV_FIELD];
|
|
9570
|
+
const ownEnv = value[MCP_ENV_FIELD];
|
|
9571
|
+
if (isObj5(userEnv) || isObj5(ownEnv)) value[MCP_ENV_FIELD] = { ...isObj5(userEnv) ? userEnv : {}, ...isObj5(ownEnv) ? ownEnv : {} };
|
|
9572
|
+
if (Array.isArray(cur[MCP_ENV_VARS_FIELD])) value[MCP_ENV_VARS_FIELD] = cur[MCP_ENV_VARS_FIELD];
|
|
9573
|
+
return [[c3.key, value], ...edits.slice(1)];
|
|
9574
|
+
}
|
|
9516
9575
|
function parseCheck(row) {
|
|
9517
9576
|
const c3 = row.config;
|
|
9518
9577
|
if (!c3) return { name: "parse", ok: true };
|
|
9519
9578
|
try {
|
|
9520
|
-
const
|
|
9579
|
+
const text2 = readOr(c3.file) ?? "";
|
|
9580
|
+
const r2 = editHostConfigText(row.id, c3.file, text2, c3.format, ownConfigEdits(row, c3, text2));
|
|
9521
9581
|
return { name: "parse", ok: r2.edits.length === 0, detail: r2.edits.length ? "entry differs after write" : void 0 };
|
|
9522
9582
|
} catch (e) {
|
|
9523
9583
|
return { name: "parse", ok: false, detail: e.message };
|
|
@@ -9568,7 +9628,7 @@ var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
|
|
|
9568
9628
|
var NOT_SEEN_LINE = "not seen yet, run one tool call";
|
|
9569
9629
|
function hookSeenCheck(row, dataRoot) {
|
|
9570
9630
|
const base = path12.join(dataRoot, PROJECTS_DIR_NAME);
|
|
9571
|
-
const dirs =
|
|
9631
|
+
const dirs = existsSync17(base) ? readdirSync6(base) : [];
|
|
9572
9632
|
let sqlite;
|
|
9573
9633
|
try {
|
|
9574
9634
|
sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -9577,7 +9637,7 @@ function hookSeenCheck(row, dataRoot) {
|
|
|
9577
9637
|
}
|
|
9578
9638
|
for (const d of dirs) {
|
|
9579
9639
|
const file = path12.join(base, d, DB_FILE_NAME);
|
|
9580
|
-
if (!sqlite || !
|
|
9640
|
+
if (!sqlite || !existsSync17(file)) continue;
|
|
9581
9641
|
let db;
|
|
9582
9642
|
try {
|
|
9583
9643
|
db = new sqlite.DatabaseSync(file, { readOnly: true });
|
|
@@ -9594,17 +9654,17 @@ function skillsCheck(row, pkgDir) {
|
|
|
9594
9654
|
const s = row.skillInstall;
|
|
9595
9655
|
if (s.kind === "package") {
|
|
9596
9656
|
const files = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE));
|
|
9597
|
-
const miss = files.filter((f2) => !
|
|
9657
|
+
const miss = files.filter((f2) => !existsSync17(f2));
|
|
9598
9658
|
if (miss.length) return { name: "skills", ok: false, detail: `missing ${miss.join(", ")}` };
|
|
9599
9659
|
const own2 = getAdapter(row.id).toolNamePrefix + SKILL_TOOL_STEM;
|
|
9600
9660
|
const foreign = [...new Set(ADAPTERS.map((r2) => r2.toolNamePrefix + SKILL_TOOL_STEM))].filter((n3) => n3 !== SKILL_TOOL_STEM && n3 !== own2);
|
|
9601
9661
|
const bad2 = files.filter((f2) => {
|
|
9602
|
-
const t2 =
|
|
9662
|
+
const t2 = readFileSync11(f2, "utf8");
|
|
9603
9663
|
return !t2.includes(own2) && foreign.some((n3) => t2.includes(n3));
|
|
9604
9664
|
});
|
|
9605
9665
|
return { name: "skills", ok: bad2.length === 0, detail: bad2.length ? `${bad2.join(", ")} without the ${own2}* tool name` : void 0 };
|
|
9606
9666
|
}
|
|
9607
|
-
const bad = s.files.filter((f2) => readRaw(f2.file) !== (
|
|
9667
|
+
const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync17(f2.src) ? renderSkill(readFileSync11(f2.src, "utf8"), s.prefixes) : void 0));
|
|
9608
9668
|
return { name: "skills", ok: bad.length === 0, detail: bad.length ? `${bad.map((f2) => f2.file).join(", ")} missing or without the ${s.prefixes.join(" / ") || "plain"} tool prefix` : void 0 };
|
|
9609
9669
|
}
|
|
9610
9670
|
var CODEX_CONFIG_FILE2 = "config.toml";
|
|
@@ -9884,7 +9944,7 @@ function undo(dir, entries, env) {
|
|
|
9884
9944
|
continue;
|
|
9885
9945
|
}
|
|
9886
9946
|
if (!e.file) continue;
|
|
9887
|
-
if (e.existed && e.backup) atomicWrite(e.file,
|
|
9947
|
+
if (e.existed && e.backup) atomicWrite(e.file, readFileSync11(path12.join(dir, e.backup), "utf8"));
|
|
9888
9948
|
else unlinkWithRetry(e.file);
|
|
9889
9949
|
}
|
|
9890
9950
|
}
|
|
@@ -9899,7 +9959,7 @@ function takeLock(root, runId) {
|
|
|
9899
9959
|
if (e.code !== "EEXIST") throw e;
|
|
9900
9960
|
let pid = 0;
|
|
9901
9961
|
try {
|
|
9902
|
-
pid = Number(JSON.parse(
|
|
9962
|
+
pid = Number(JSON.parse(readFileSync11(file, "utf8")).pid);
|
|
9903
9963
|
} catch {
|
|
9904
9964
|
}
|
|
9905
9965
|
if (pid && pidAlive(pid)) return `setup lock ${file} is held by pid ${pid}; wait for that run or remove the lock`;
|
|
@@ -9917,14 +9977,16 @@ function agentHomeDir(id, ctx) {
|
|
|
9917
9977
|
return path12.join(ctx.home, ...AGENT_HOME_DIR[id]);
|
|
9918
9978
|
}
|
|
9919
9979
|
function detectAgents(reg, ctx) {
|
|
9920
|
-
return reg.filter((r2) =>
|
|
9980
|
+
return reg.filter((r2) => existsSync17(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
|
|
9921
9981
|
}
|
|
9922
9982
|
async function runSetup(opts) {
|
|
9923
9983
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9924
9984
|
const runId = opts.runId ?? (/* @__PURE__ */ new Date()).toISOString().split(":").join("-").split(".").join("-");
|
|
9925
9985
|
const reg = buildRegistry(ctx);
|
|
9986
|
+
const nodeVersion = opts.nodeVersion ?? process.version;
|
|
9987
|
+
if (nodeTooOld(nodeVersion)) return { exitCode: 1, agents: [], error: formatError("NODE_TOO_OLD", { v: nodeVersion }) };
|
|
9926
9988
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9927
|
-
if (!
|
|
9989
|
+
if (!existsSync17(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9928
9990
|
}
|
|
9929
9991
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9930
9992
|
const root = dataRootOf(ctx.env, ctx.home);
|
|
@@ -10018,7 +10080,7 @@ async function runDoctor(opts) {
|
|
|
10018
10080
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
10019
10081
|
const reg = buildRegistry(ctx);
|
|
10020
10082
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
10021
|
-
if (!
|
|
10083
|
+
if (!existsSync17(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
10022
10084
|
}
|
|
10023
10085
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
10024
10086
|
const run = new Run(dataRootOf(ctx.env, ctx.home), "doctor");
|
|
@@ -10088,14 +10150,14 @@ function runRemove(opts) {
|
|
|
10088
10150
|
const env = opts.env ?? process.env;
|
|
10089
10151
|
const root = dataRootOf(env, opts.home);
|
|
10090
10152
|
const base = path12.join(root, BACKUP_DIR);
|
|
10091
|
-
if (!
|
|
10153
|
+
if (!existsSync17(base)) return { exitCode: 0, restored: 0 };
|
|
10092
10154
|
const held = takeLock(root, "remove");
|
|
10093
10155
|
if (held) return { exitCode: 1, restored: 0, error: held };
|
|
10094
10156
|
let restored = 0;
|
|
10095
10157
|
try {
|
|
10096
|
-
const runs =
|
|
10158
|
+
const runs = readdirSync6(base).map((r2) => path12.join(base, r2)).filter((d) => existsSync17(path12.join(d, MANIFEST))).sort().reverse();
|
|
10097
10159
|
for (const dir of runs) {
|
|
10098
|
-
const m3 = JSON.parse(
|
|
10160
|
+
const m3 = JSON.parse(readFileSync11(path12.join(dir, MANIFEST), "utf8"));
|
|
10099
10161
|
undo(dir, m3.entries, env);
|
|
10100
10162
|
restored += m3.entries.length;
|
|
10101
10163
|
renameWithRetry(path12.join(dir, MANIFEST), path12.join(dir, MANIFEST_DONE));
|
|
@@ -10107,7 +10169,7 @@ function runRemove(opts) {
|
|
|
10107
10169
|
}
|
|
10108
10170
|
|
|
10109
10171
|
// src/setup/print.ts
|
|
10110
|
-
import { readFileSync as
|
|
10172
|
+
import { readFileSync as readFileSync12 } from "node:fs";
|
|
10111
10173
|
var SHELL_SAFE_PUNCT = "@%+=:,./-_";
|
|
10112
10174
|
function isShellSafe(s) {
|
|
10113
10175
|
if (s === "") return false;
|
|
@@ -10135,7 +10197,7 @@ function printPlan(row, env) {
|
|
|
10135
10197
|
else if (h2.kind === "plugin-list") steps.push({ kind: "hook", file: h2.file, block: JSON.stringify({ [h2.key[0]]: [h2.entry] }, null, 2) + "\n" });
|
|
10136
10198
|
const sk = row.skillInstall;
|
|
10137
10199
|
if (sk.kind === "dir") {
|
|
10138
|
-
for (const f2 of sk.files) steps.push({ kind: "skill", file: f2.file, block: renderSkill(
|
|
10200
|
+
for (const f2 of sk.files) steps.push({ kind: "skill", file: f2.file, block: renderSkill(readFileSync12(f2.src, "utf8"), sk.prefixes) });
|
|
10139
10201
|
}
|
|
10140
10202
|
return { agent: row.id, steps, verify: `context-mode doctor --agents ${row.id}` };
|
|
10141
10203
|
}
|
|
@@ -10438,6 +10500,10 @@ async function setup(ui) {
|
|
|
10438
10500
|
if (f2.print) return printManual(ui, f2.print);
|
|
10439
10501
|
if (f2.list) return list(ui);
|
|
10440
10502
|
if (f2.remove) return remove(ui);
|
|
10503
|
+
if (nodeTooOld(process.version)) {
|
|
10504
|
+
err(`context-mode: ${formatError("NODE_TOO_OLD", { v: process.version })}`);
|
|
10505
|
+
return EXIT_FAIL;
|
|
10506
|
+
}
|
|
10441
10507
|
if (f2.dryRun) {
|
|
10442
10508
|
const plan = await apply(ui, f2.agents, true);
|
|
10443
10509
|
if (f2.json) out(JSON.stringify({ command: "setup", dryRun: true, ...plan }));
|
|
@@ -10557,7 +10623,7 @@ async function upgrade(ui) {
|
|
|
10557
10623
|
}
|
|
10558
10624
|
const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
|
|
10559
10625
|
const cli = path13.join(root, "context-mode", "cli.mjs");
|
|
10560
|
-
if (!root || !
|
|
10626
|
+
if (!root || !existsSync18(cli)) {
|
|
10561
10627
|
err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
|
|
10562
10628
|
return EXIT_FAIL;
|
|
10563
10629
|
}
|
|
@@ -10655,7 +10721,7 @@ function main() {
|
|
|
10655
10721
|
const dir = path14.dirname(realpathSync11(fileURLToPath3(import.meta.url)));
|
|
10656
10722
|
let version = "";
|
|
10657
10723
|
try {
|
|
10658
|
-
version = String(JSON.parse(
|
|
10724
|
+
version = String(JSON.parse(readFileSync13(path14.join(dir, PACKAGE_FILE), "utf8")).version);
|
|
10659
10725
|
} catch (err2) {
|
|
10660
10726
|
process.stderr.write(`${SERVER_KEY}: cannot read ${PACKAGE_FILE}: ${err2.message}
|
|
10661
10727
|
`);
|