context-mode 2.1.5 → 2.1.7
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 +411 -168
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +98 -98
- package/opencode/plugin.js +800 -377
- package/package.json +1 -1
- package/pi/index.js +724 -380
- package/qwen-extension.json +1 -1
- package/run.mjs +335 -74
- package/search.mjs +335 -74
- package/server.mjs +517 -231
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 readFileSync14, 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,8 +382,14 @@ 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"]);
|
|
392
|
+
var PLUGIN_MARKETPLACE_NAME = "context-mode";
|
|
378
393
|
var AGENT_HOME_DIR = Object.freeze({
|
|
379
394
|
"claude-code": [".claude"],
|
|
380
395
|
codex: [".codex"],
|
|
@@ -407,6 +422,90 @@ var OPS_SPLIT_FILES = Object.freeze([
|
|
|
407
422
|
"v1-remove.ts",
|
|
408
423
|
"uninstall.ts"
|
|
409
424
|
]);
|
|
425
|
+
var unsupported = (h2) => Object.freeze(h2);
|
|
426
|
+
var UNSUPPORTED_HOSTS = Object.freeze([
|
|
427
|
+
unsupported({
|
|
428
|
+
id: "antigravity",
|
|
429
|
+
name: "Antigravity",
|
|
430
|
+
clientNames: ["antigravity", "antigravity-client", "antigravity-cli", "agy"],
|
|
431
|
+
envVars: ["ANTIGRAVITY_CLI_ALIAS"],
|
|
432
|
+
pluginPaths: [[".gemini", "config", "plugins"], [".gemini", "antigravity", "plugins"], [".gemini", "antigravity-cli", "plugins"], [".gemini", "antigravity-ide", "plugins"]],
|
|
433
|
+
configDirs: [".gemini/antigravity", ".gemini/antigravity-cli", ".gemini/config"],
|
|
434
|
+
binaries: ["agy"],
|
|
435
|
+
source: "v1.0.169:src/adapters/client-map.ts:15-17; detect.ts:156,481-483; #1340"
|
|
436
|
+
}),
|
|
437
|
+
unsupported({
|
|
438
|
+
id: "cursor",
|
|
439
|
+
name: "Cursor",
|
|
440
|
+
clientNames: ["cursor-vscode"],
|
|
441
|
+
envVars: ["CURSOR_TRACE_ID", "CURSOR_CLI", "CURSOR_CWD"],
|
|
442
|
+
pluginPaths: [],
|
|
443
|
+
configDirs: [".cursor"],
|
|
444
|
+
binaries: [],
|
|
445
|
+
source: "v1.0.169:src/adapters/client-map.ts:18; detect.ts:163-165,584"
|
|
446
|
+
}),
|
|
447
|
+
unsupported({
|
|
448
|
+
id: "omp",
|
|
449
|
+
name: "OMP (oh-my-pi)",
|
|
450
|
+
clientNames: ["omp-coding-agent"],
|
|
451
|
+
envVars: [],
|
|
452
|
+
pluginPaths: [],
|
|
453
|
+
configDirs: [".omp"],
|
|
454
|
+
binaries: ["omp"],
|
|
455
|
+
source: "v1.0.169:src/adapters/client-map.ts:37; detect.ts:543 (PI_CODING_AGENT_DIR is not a signal: supported Pi reads it too)"
|
|
456
|
+
}),
|
|
457
|
+
unsupported({
|
|
458
|
+
id: "openclaw",
|
|
459
|
+
name: "OpenClaw",
|
|
460
|
+
clientNames: [],
|
|
461
|
+
envVars: [],
|
|
462
|
+
pluginPaths: [],
|
|
463
|
+
configDirs: [".openclaw"],
|
|
464
|
+
binaries: [],
|
|
465
|
+
source: "v1.0.169:src/adapters/detect.ts:252,575 (the runtime sets no env var)"
|
|
466
|
+
}),
|
|
467
|
+
unsupported({
|
|
468
|
+
id: "kimi",
|
|
469
|
+
name: "Kimi Code",
|
|
470
|
+
clientNames: ["kimi-code", "kimi"],
|
|
471
|
+
envVars: [],
|
|
472
|
+
pluginPaths: [],
|
|
473
|
+
configDirs: [".kimi-code"],
|
|
474
|
+
binaries: ["kimi"],
|
|
475
|
+
source: "v1.0.169:src/adapters/client-map.ts:42-44; detect.ts:567; adapters/kimi/index.ts:127"
|
|
476
|
+
}),
|
|
477
|
+
unsupported({
|
|
478
|
+
id: "kilo",
|
|
479
|
+
name: "Kilo Code",
|
|
480
|
+
clientNames: ["kilo code"],
|
|
481
|
+
envVars: ["KILO", "KILO_PID"],
|
|
482
|
+
pluginPaths: [],
|
|
483
|
+
configDirs: [".config/kilo"],
|
|
484
|
+
binaries: [],
|
|
485
|
+
source: "v1.0.169:src/adapters/client-map.ts:28; detect.ts:170-171,592"
|
|
486
|
+
}),
|
|
487
|
+
unsupported({
|
|
488
|
+
id: "zed",
|
|
489
|
+
name: "Zed",
|
|
490
|
+
clientNames: ["zed"],
|
|
491
|
+
envVars: ["ZED_SESSION_ID", "ZED_TERM"],
|
|
492
|
+
pluginPaths: [],
|
|
493
|
+
configDirs: [".config/zed"],
|
|
494
|
+
binaries: [],
|
|
495
|
+
source: "v1.0.169:src/adapters/client-map.ts:38-39; detect.ts:189-190,616"
|
|
496
|
+
}),
|
|
497
|
+
unsupported({
|
|
498
|
+
id: "jetbrains-copilot",
|
|
499
|
+
name: "JetBrains Copilot",
|
|
500
|
+
clientNames: ["jetbrains client", "intellij idea", "pycharm"],
|
|
501
|
+
envVars: ["IDEA_INITIAL_DIRECTORY"],
|
|
502
|
+
pluginPaths: [],
|
|
503
|
+
configDirs: [".config/JetBrains"],
|
|
504
|
+
binaries: [],
|
|
505
|
+
source: "v1.0.169:src/adapters/client-map.ts:23-25; detect.ts:213,600"
|
|
506
|
+
})
|
|
507
|
+
]);
|
|
508
|
+
var SUPPORTED_AGENTS_DOCS_URL = "https://github.com/mksglu/context-mode/blob/main/docs/install/README.md";
|
|
410
509
|
var HOOK_HOST_FILE = Object.freeze({
|
|
411
510
|
"claude-code": { root: "plugin", file: ["hooks", "claude-code.json"], key: ["hooks"], shape: "nested", timeoutKey: "timeout", matcher: true },
|
|
412
511
|
codex: { root: "home", file: [".codex", "hooks.json"], key: ["hooks"], shape: "nested", timeoutKey: "timeout", matcher: true },
|
|
@@ -480,6 +579,8 @@ var SETTINGS_FILE = "settings.json";
|
|
|
480
579
|
var CLAUDE_USER_CONFIG_FILE = ".claude.json";
|
|
481
580
|
var HOOKS_JSON_FILE = "hooks.json";
|
|
482
581
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
582
|
+
var SETUP_BACKUP_DIR_NAME = "backups";
|
|
583
|
+
var SETUP_MANIFEST_FILE = "manifest.json";
|
|
483
584
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
484
585
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
485
586
|
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
@@ -564,6 +665,8 @@ var ATOMIC_TMP_MARK = ".cm-tmp-";
|
|
|
564
665
|
var JSON_INDENT_UNIT = " ";
|
|
565
666
|
var MCP_COMMAND_FIELD = "command";
|
|
566
667
|
var MCP_ARGS_FIELD = "args";
|
|
668
|
+
var MCP_ENV_FIELD = "env";
|
|
669
|
+
var MCP_ENV_VARS_FIELD = "env_vars";
|
|
567
670
|
var ZCODE_MCP_FEATURE_KEY = Object.freeze(["features", "mcp"]);
|
|
568
671
|
var CODEX_OMIT_TOOLS_FROM_FIELD = "omit_tools_from";
|
|
569
672
|
var CODEX_OMIT_DEFERRED = Object.freeze(["deferred"]);
|
|
@@ -1678,10 +1781,51 @@ function getAdapter(id) {
|
|
|
1678
1781
|
return BY_ID.get(id);
|
|
1679
1782
|
}
|
|
1680
1783
|
|
|
1784
|
+
// src/core/contracts/agents.ts
|
|
1785
|
+
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
1786
|
+
|
|
1787
|
+
// src/core/ops/unsupported-host.ts
|
|
1788
|
+
var SUPPORTED_AGENTS_LINE = `Supported agents: ${AGENT_IDS.join(", ")} (${SUPPORTED_AGENTS_DOCS_URL}).`;
|
|
1789
|
+
function UNSUPPORTED_HOST_LINE(name) {
|
|
1790
|
+
return `${name} is not a supported host today. The MCP server runs here; hooks are not checked. ${SUPPORTED_AGENTS_LINE}`;
|
|
1791
|
+
}
|
|
1792
|
+
function UNSUPPORTED_SETUP_LINE(name) {
|
|
1793
|
+
return `${name} is not a supported host today. Setup writes nothing for it. ${SUPPORTED_AGENTS_LINE}`;
|
|
1794
|
+
}
|
|
1795
|
+
function segmentsOf(dir) {
|
|
1796
|
+
let parts = [dir];
|
|
1797
|
+
for (const sep3 of V1_PATH_SEPS) parts = parts.flatMap((p3) => p3.split(sep3));
|
|
1798
|
+
return parts;
|
|
1799
|
+
}
|
|
1800
|
+
function hasRun(parts, run) {
|
|
1801
|
+
for (let i2 = 0; i2 + run.length <= parts.length; i2++) if (run.every((seg, k) => parts[i2 + k] === seg)) return true;
|
|
1802
|
+
return false;
|
|
1803
|
+
}
|
|
1804
|
+
function unsupportedHostOf(sig) {
|
|
1805
|
+
if (sig.clientName !== void 0 && sig.clientName !== "") {
|
|
1806
|
+
const n3 = sig.clientName.toLowerCase();
|
|
1807
|
+
const hit = UNSUPPORTED_HOSTS.find((h2) => h2.clientNames.includes(n3));
|
|
1808
|
+
if (hit !== void 0) return hit;
|
|
1809
|
+
}
|
|
1810
|
+
if (sig.bundleDir !== void 0) {
|
|
1811
|
+
const parts = segmentsOf(sig.bundleDir);
|
|
1812
|
+
const hit = UNSUPPORTED_HOSTS.find((h2) => h2.pluginPaths.some((p3) => hasRun(parts, p3)));
|
|
1813
|
+
if (hit !== void 0) return hit;
|
|
1814
|
+
}
|
|
1815
|
+
if (sig.clientName !== void 0 && sig.clientName !== "") return void 0;
|
|
1816
|
+
const env = sig.env;
|
|
1817
|
+
if (env === void 0) return void 0;
|
|
1818
|
+
return UNSUPPORTED_HOSTS.find((h2) => h2.envVars.some((v) => env[v] !== void 0 && env[v] !== ""));
|
|
1819
|
+
}
|
|
1820
|
+
function unsupportedHostByName(name) {
|
|
1821
|
+
const n3 = name.toLowerCase();
|
|
1822
|
+
return UNSUPPORTED_HOSTS.find((h2) => h2.id === n3 || h2.clientNames.includes(n3) || h2.binaries.includes(n3));
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1681
1825
|
// src/cli/args.ts
|
|
1682
1826
|
var COMMANDS = ["setup", "doctor", "upgrade"];
|
|
1683
1827
|
var ALL_COMMANDS = ["setup", "doctor", "upgrade", "server", "mcp", "hook", "help"];
|
|
1684
|
-
var
|
|
1828
|
+
var AGENT_IDS2 = ADAPTERS.map((a2) => a2.id);
|
|
1685
1829
|
var COMMON = ["--help", "-h", "--json", "--yes", "-y", "--no-input", "--debug", "--quiet", "-q", "--verbose", "--no-color", "--agents"];
|
|
1686
1830
|
var FLAGS = {
|
|
1687
1831
|
setup: [...COMMON, "--dry-run", "--list", "--remove", "--repair", "--print"],
|
|
@@ -1692,6 +1836,11 @@ var VALUE_FLAGS = /* @__PURE__ */ new Set(["--agents", "--tag", "--print"]);
|
|
|
1692
1836
|
var TAG_RE = /^[a-z0-9][a-z0-9.+-]*$/i;
|
|
1693
1837
|
var UsageError = class extends Error {
|
|
1694
1838
|
};
|
|
1839
|
+
function badAgent(name) {
|
|
1840
|
+
const h2 = unsupportedHostByName(name);
|
|
1841
|
+
if (h2 !== void 0) return new UsageError(UNSUPPORTED_SETUP_LINE(h2.name));
|
|
1842
|
+
return new UsageError(`unknown agent "${name}".${suggest(name, AGENT_IDS2)} ${SUPPORTED_AGENTS_LINE} Run context-mode setup --list.`);
|
|
1843
|
+
}
|
|
1695
1844
|
function distance(a2, b3) {
|
|
1696
1845
|
const row = Array.from({ length: b3.length + 1 }, (_2, i2) => i2);
|
|
1697
1846
|
for (let i2 = 1; i2 <= a2.length; i2++) {
|
|
@@ -1776,13 +1925,13 @@ function parseFlags(cmd, argv) {
|
|
|
1776
1925
|
f2.tag = value;
|
|
1777
1926
|
break;
|
|
1778
1927
|
case "--print":
|
|
1779
|
-
if (!
|
|
1928
|
+
if (!AGENT_IDS2.includes(value)) throw badAgent(value);
|
|
1780
1929
|
f2.print = value;
|
|
1781
1930
|
break;
|
|
1782
1931
|
case "--agents": {
|
|
1783
1932
|
const ids = value.split(",").map((s) => s.trim()).filter(Boolean);
|
|
1784
1933
|
for (const id of ids) {
|
|
1785
|
-
if (!
|
|
1934
|
+
if (!AGENT_IDS2.includes(id)) throw badAgent(id);
|
|
1786
1935
|
}
|
|
1787
1936
|
f2.agents = [...new Set(ids)];
|
|
1788
1937
|
break;
|
|
@@ -1884,7 +2033,7 @@ Examples:
|
|
|
1884
2033
|
// src/cli/commands.ts
|
|
1885
2034
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
1886
2035
|
import { createHash as createHash2 } from "node:crypto";
|
|
1887
|
-
import { existsSync as
|
|
2036
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1888
2037
|
import os from "node:os";
|
|
1889
2038
|
import path13 from "node:path";
|
|
1890
2039
|
|
|
@@ -4708,7 +4857,8 @@ import { basename, dirname as dirname2, join as join2, posix, resolve, win32 } f
|
|
|
4708
4857
|
|
|
4709
4858
|
// src/core/contracts/errors.ts
|
|
4710
4859
|
var ERROR_TEXT = Object.freeze({
|
|
4711
|
-
NODE_TOO_OLD: "
|
|
4860
|
+
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.",
|
|
4861
|
+
// #1328 D-NODE-OLD-1
|
|
4712
4862
|
NO_SQLITE: "node:sqlite failed to load. Fix: run ctx_doctor.",
|
|
4713
4863
|
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
4864
|
// D-ORPHAN-WAL-1
|
|
@@ -4778,7 +4928,7 @@ var CtxError = class extends Error {
|
|
|
4778
4928
|
};
|
|
4779
4929
|
|
|
4780
4930
|
// src/core/project/config-dir.ts
|
|
4781
|
-
var { mkdirSync, realpathSync } = process.getBuiltinModule("node:fs");
|
|
4931
|
+
var { existsSync: existsSync2, mkdirSync, readFileSync, readdirSync: readdirSync2, realpathSync } = process.getBuiltinModule("node:fs");
|
|
4782
4932
|
function homeDirOf(env, platform = process.platform) {
|
|
4783
4933
|
const set2 = (v) => v !== void 0 && v !== "";
|
|
4784
4934
|
if (platform === "win32") {
|
|
@@ -4832,6 +4982,11 @@ function claudeDirOf(env, home) {
|
|
|
4832
4982
|
const dir = env[CLAUDE_CONFIG_DIR_ENV];
|
|
4833
4983
|
return dir !== void 0 && dir !== "" ? dir : join2(home, ...AGENT_HOME_DIR["claude-code"]);
|
|
4834
4984
|
}
|
|
4985
|
+
function claudeProfileEnv(env, platform = process.platform) {
|
|
4986
|
+
const dir = env[CLAUDE_CONFIG_DIR_ENV];
|
|
4987
|
+
if (dir === void 0 || dir === "" || platform === "win32") return "";
|
|
4988
|
+
return `${CLAUDE_CONFIG_DIR_ENV}='${dir.split("'").join(`'"'"'`)}' `;
|
|
4989
|
+
}
|
|
4835
4990
|
function opencodeDirOf(env, home) {
|
|
4836
4991
|
const own2 = env[OPENCODE_CONFIG_DIR_ENV];
|
|
4837
4992
|
if (own2 !== void 0 && own2 !== "") return own2;
|
|
@@ -4861,18 +5016,53 @@ function dataRootOf(env, home) {
|
|
|
4861
5016
|
|
|
4862
5017
|
// src/core/ops/doctor-issue.ts
|
|
4863
5018
|
import { spawnSync } from "node:child_process";
|
|
4864
|
-
import { closeSync as closeSync2, existsSync as
|
|
4865
|
-
import { delimiter, join as
|
|
5019
|
+
import { closeSync as closeSync2, existsSync as existsSync10, fstatSync, mkdirSync as mkdirSync4, openSync as openSync2, readFileSync as readFileSync7, readSync as readSync2, realpathSync as realpathSync5, writeFileSync as writeFileSync2 } from "node:fs";
|
|
5020
|
+
import { delimiter, join as join11 } from "node:path";
|
|
4866
5021
|
|
|
4867
5022
|
// src/core/hooks/fallback.ts
|
|
4868
|
-
import { join as
|
|
5023
|
+
import { join as join5, resolve as resolve2 } from "node:path";
|
|
4869
5024
|
|
|
4870
5025
|
// src/core/policy/read-media.ts
|
|
4871
5026
|
import { extname } from "node:path";
|
|
4872
5027
|
var { closeSync, openSync, readSync } = process.getBuiltinModule("node:fs");
|
|
4873
5028
|
|
|
5029
|
+
// src/core/policy/own-file.ts
|
|
5030
|
+
import { extname as extname2, join as join4 } from "node:path";
|
|
5031
|
+
|
|
5032
|
+
// src/core/project/contain.ts
|
|
5033
|
+
import { dirname as dirname3, join as join3, relative, sep } from "node:path";
|
|
5034
|
+
var { lstatSync: lstatSync2, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
5035
|
+
function components(p3) {
|
|
5036
|
+
return p3.split(sep).filter((c3) => c3 !== "");
|
|
5037
|
+
}
|
|
5038
|
+
function reachedThroughLink(root, p3) {
|
|
5039
|
+
const rel = relative(root, p3);
|
|
5040
|
+
const steps = components(rel);
|
|
5041
|
+
if (rel === "" || steps[0] === ".." || rel === p3) return false;
|
|
5042
|
+
let at = root;
|
|
5043
|
+
for (const step of steps) {
|
|
5044
|
+
at = join3(at, step);
|
|
5045
|
+
try {
|
|
5046
|
+
if (lstatSync2(at).isSymbolicLink()) return true;
|
|
5047
|
+
} catch {
|
|
5048
|
+
return false;
|
|
5049
|
+
}
|
|
5050
|
+
}
|
|
5051
|
+
return false;
|
|
5052
|
+
}
|
|
5053
|
+
|
|
4874
5054
|
// src/core/hooks/fallback.ts
|
|
4875
5055
|
var fs = process.getBuiltinModule("node:fs");
|
|
5056
|
+
function nodeTooOld(version) {
|
|
5057
|
+
const a2 = (version.startsWith("v") ? version.slice(1) : version).split(".");
|
|
5058
|
+
const b3 = NODE_MIN.split(".");
|
|
5059
|
+
for (let i2 = 0; i2 < b3.length; i2++) {
|
|
5060
|
+
const x2 = Number(a2[i2] ?? 0) || 0;
|
|
5061
|
+
const y2 = Number(b3[i2]);
|
|
5062
|
+
if (x2 !== y2) return x2 < y2;
|
|
5063
|
+
}
|
|
5064
|
+
return false;
|
|
5065
|
+
}
|
|
4876
5066
|
|
|
4877
5067
|
// src/core/store/schema.ts
|
|
4878
5068
|
var PRAGMAS = `
|
|
@@ -4961,20 +5151,43 @@ CREATE VIRTUAL TABLE line_units USING fts5(
|
|
|
4961
5151
|
`;
|
|
4962
5152
|
|
|
4963
5153
|
// src/core/store/db.ts
|
|
4964
|
-
var { existsSync:
|
|
5154
|
+
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
4965
5155
|
|
|
4966
5156
|
// src/core/ops/doctor-config.ts
|
|
4967
|
-
import { existsSync as
|
|
4968
|
-
import { join as
|
|
5157
|
+
import { existsSync as existsSync9, readdirSync as readdirSync5, readFileSync as readFileSync6 } from "node:fs";
|
|
5158
|
+
import { dirname as dirname7, join as join10 } from "node:path";
|
|
5159
|
+
|
|
5160
|
+
// src/core/ops/host-text.ts
|
|
5161
|
+
var BOM_CODE = 65279;
|
|
5162
|
+
var CR_CODE = 13;
|
|
5163
|
+
var CRLF = "\r\n";
|
|
5164
|
+
var LF = "\n";
|
|
5165
|
+
function hostLayout(raw) {
|
|
5166
|
+
let crlf = 0;
|
|
5167
|
+
let lf = 0;
|
|
5168
|
+
for (let i2 = raw.indexOf(LF); i2 >= 0; i2 = raw.indexOf(LF, i2 + 1)) {
|
|
5169
|
+
if (i2 > 0 && raw.charCodeAt(i2 - 1) === CR_CODE) crlf += 1;
|
|
5170
|
+
else lf += 1;
|
|
5171
|
+
}
|
|
5172
|
+
return { bom: raw.length > 0 && raw.charCodeAt(0) === BOM_CODE, crlf: crlf > 0 && crlf >= lf };
|
|
5173
|
+
}
|
|
5174
|
+
function hostText(raw) {
|
|
5175
|
+
const bare = raw.length > 0 && raw.charCodeAt(0) === BOM_CODE ? raw.slice(1) : raw;
|
|
5176
|
+
return bare.indexOf(CRLF) < 0 ? bare : bare.split(CRLF).join(LF);
|
|
5177
|
+
}
|
|
5178
|
+
function withLayout(text2, layout) {
|
|
5179
|
+
const eol = layout.crlf ? text2.split(LF).join(CRLF) : text2;
|
|
5180
|
+
return layout.bom ? String.fromCharCode(BOM_CODE) + eol : eol;
|
|
5181
|
+
}
|
|
4969
5182
|
|
|
4970
5183
|
// src/core/ops/detect-v1.ts
|
|
4971
|
-
import { existsSync as
|
|
5184
|
+
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync3, readFileSync as readFileSync3 } from "node:fs";
|
|
4972
5185
|
import { tmpdir } from "node:os";
|
|
4973
|
-
import { join as
|
|
5186
|
+
import { join as join8 } from "node:path";
|
|
4974
5187
|
|
|
4975
5188
|
// src/core/ops/host-config.ts
|
|
4976
|
-
import { existsSync as
|
|
4977
|
-
import { dirname as
|
|
5189
|
+
import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
|
|
5190
|
+
import { dirname as dirname5, join as join7 } from "node:path";
|
|
4978
5191
|
|
|
4979
5192
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
4980
5193
|
var KEYS2 = {
|
|
@@ -7083,33 +7296,10 @@ function atomicWriteFile(file, text2, opts = {}) {
|
|
|
7083
7296
|
}
|
|
7084
7297
|
|
|
7085
7298
|
// src/core/ops/bundle-dir.ts
|
|
7086
|
-
import { existsSync as
|
|
7087
|
-
import { dirname as
|
|
7299
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
7300
|
+
import { dirname as dirname4, join as join6 } from "node:path";
|
|
7088
7301
|
import { fileURLToPath } from "node:url";
|
|
7089
7302
|
|
|
7090
|
-
// src/core/ops/host-text.ts
|
|
7091
|
-
var BOM_CODE = 65279;
|
|
7092
|
-
var CR_CODE = 13;
|
|
7093
|
-
var CRLF = "\r\n";
|
|
7094
|
-
var LF = "\n";
|
|
7095
|
-
function hostLayout(raw) {
|
|
7096
|
-
let crlf = 0;
|
|
7097
|
-
let lf = 0;
|
|
7098
|
-
for (let i2 = raw.indexOf(LF); i2 >= 0; i2 = raw.indexOf(LF, i2 + 1)) {
|
|
7099
|
-
if (i2 > 0 && raw.charCodeAt(i2 - 1) === CR_CODE) crlf += 1;
|
|
7100
|
-
else lf += 1;
|
|
7101
|
-
}
|
|
7102
|
-
return { bom: raw.length > 0 && raw.charCodeAt(0) === BOM_CODE, crlf: crlf > 0 && crlf >= lf };
|
|
7103
|
-
}
|
|
7104
|
-
function hostText(raw) {
|
|
7105
|
-
const bare = raw.length > 0 && raw.charCodeAt(0) === BOM_CODE ? raw.slice(1) : raw;
|
|
7106
|
-
return bare.indexOf(CRLF) < 0 ? bare : bare.split(CRLF).join(LF);
|
|
7107
|
-
}
|
|
7108
|
-
function withLayout(text2, layout) {
|
|
7109
|
-
const eol = layout.crlf ? text2.split(LF).join(CRLF) : text2;
|
|
7110
|
-
return layout.bom ? String.fromCharCode(BOM_CODE) + eol : eol;
|
|
7111
|
-
}
|
|
7112
|
-
|
|
7113
7303
|
// src/core/ops/host-config.ts
|
|
7114
7304
|
function stripJsonComments(text2) {
|
|
7115
7305
|
let out2 = "";
|
|
@@ -7480,28 +7670,6 @@ function editHostConfigText(agent, path15, text2, format, wanted) {
|
|
|
7480
7670
|
return applyEdits(agent, path15, text2, format, wanted);
|
|
7481
7671
|
}
|
|
7482
7672
|
|
|
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
7673
|
// src/core/ops/detect-v1.ts
|
|
7506
7674
|
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7507
7675
|
var keyPath = (...parts) => parts.join(".");
|
|
@@ -7545,14 +7713,14 @@ function stripJsonc(text2) {
|
|
|
7545
7713
|
}
|
|
7546
7714
|
function readJson(file) {
|
|
7547
7715
|
try {
|
|
7548
|
-
return JSON.parse(stripJsonc(hostText(
|
|
7716
|
+
return JSON.parse(stripJsonc(hostText(readFileSync3(file, "utf8"))));
|
|
7549
7717
|
} catch {
|
|
7550
7718
|
return void 0;
|
|
7551
7719
|
}
|
|
7552
7720
|
}
|
|
7553
7721
|
function readText(file) {
|
|
7554
7722
|
try {
|
|
7555
|
-
return hostText(
|
|
7723
|
+
return hostText(readFileSync3(file, "utf8"));
|
|
7556
7724
|
} catch {
|
|
7557
7725
|
return "";
|
|
7558
7726
|
}
|
|
@@ -7609,7 +7777,7 @@ function flatCommands(events2, prefix) {
|
|
|
7609
7777
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
7610
7778
|
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep3) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep3) + sep3));
|
|
7611
7779
|
function dataDir(dir, reason, out2) {
|
|
7612
|
-
if (
|
|
7780
|
+
if (existsSync6(dir)) out2.push(finding(dir, "", reason));
|
|
7613
7781
|
}
|
|
7614
7782
|
function mcpEntry(file, doc, out2) {
|
|
7615
7783
|
if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
|
|
@@ -7617,7 +7785,7 @@ function mcpEntry(file, doc, out2) {
|
|
|
7617
7785
|
}
|
|
7618
7786
|
}
|
|
7619
7787
|
function claudeShapeSettings(agentHome, out2) {
|
|
7620
|
-
const file =
|
|
7788
|
+
const file = join8(agentHome, SETTINGS_FILE);
|
|
7621
7789
|
const doc = readJson(file);
|
|
7622
7790
|
for (const c3 of nestedCommands(doc)) {
|
|
7623
7791
|
if (c3.command.includes(V1_CACHE_HEAL_NAME)) out2.push(finding(file, c3.path, V1_REASON.cacheHealHook));
|
|
@@ -7637,63 +7805,64 @@ function v1HookFile(file, out2) {
|
|
|
7637
7805
|
function scanClaudeCode(home, agentHome, out2) {
|
|
7638
7806
|
claudeShapeSettings(agentHome, out2);
|
|
7639
7807
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
7640
|
-
const file =
|
|
7641
|
-
if (
|
|
7808
|
+
const file = join8(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
7809
|
+
if (existsSync6(file)) out2.push(finding(file, "", V1_REASON.cacheHealFile));
|
|
7642
7810
|
}
|
|
7643
|
-
const userFile =
|
|
7811
|
+
const userFile = join8(home, CLAUDE_USER_CONFIG_FILE);
|
|
7644
7812
|
mcpEntry(userFile, readJson(userFile), out2);
|
|
7645
|
-
dataDir(
|
|
7813
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7646
7814
|
}
|
|
7647
7815
|
function scanCodex(agentHome, out2) {
|
|
7648
|
-
const hooksFile =
|
|
7816
|
+
const hooksFile = join8(agentHome, HOOKS_JSON_FILE);
|
|
7649
7817
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7650
7818
|
if (c3.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c3.command)) {
|
|
7651
7819
|
out2.push(finding(hooksFile, c3.path, V1_REASON.codexHook));
|
|
7652
7820
|
}
|
|
7653
7821
|
}
|
|
7654
|
-
const tomlFile =
|
|
7822
|
+
const tomlFile = join8(agentHome, CONFIG_TOML_FILE);
|
|
7655
7823
|
const config = readTomlValue(tomlFile);
|
|
7656
7824
|
for (const span of readTomlTables(tomlFile)) {
|
|
7657
7825
|
if (span.path[0] !== V1_TOML_SECTION_ROOT || span.path[1] !== SERVER_KEY) continue;
|
|
7658
7826
|
if (span.path.length === 2 && isV2McpTable(hostConfigValueAt(config, span.path))) continue;
|
|
7827
|
+
if (span.path.length === 3 && span.path[2] === MCP_ENV_FIELD && isV2McpTable(hostConfigValueAt(config, span.path.slice(0, 2)))) continue;
|
|
7659
7828
|
out2.push(finding(tomlFile, span.header.trim(), V1_REASON.codexToml));
|
|
7660
7829
|
}
|
|
7661
|
-
dataDir(
|
|
7830
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7662
7831
|
}
|
|
7663
7832
|
function scanGemini(agentHome, out2) {
|
|
7664
|
-
const file =
|
|
7833
|
+
const file = join8(agentHome, SETTINGS_FILE);
|
|
7665
7834
|
for (const c3 of nestedCommands(readJson(file))) {
|
|
7666
7835
|
if (c3.command.includes(SERVER_KEY)) out2.push(finding(file, c3.path, V1_REASON.hook));
|
|
7667
7836
|
}
|
|
7668
|
-
dataDir(
|
|
7837
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
|
|
7669
7838
|
}
|
|
7670
7839
|
function scanVscode(agentHome, project, out2) {
|
|
7671
7840
|
if (project !== void 0) {
|
|
7672
|
-
v1HookFile(
|
|
7673
|
-
const mcpFile =
|
|
7841
|
+
v1HookFile(join8(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7842
|
+
const mcpFile = join8(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
7674
7843
|
const doc = readJson(mcpFile);
|
|
7675
7844
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
7676
7845
|
const entry2 = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
7677
7846
|
if (isObj(entry2) && (entry2.command === V1_BIN_COMMAND || listOf(entry2.args).some((a2) => a2 === V1_BIN_COMMAND))) {
|
|
7678
7847
|
out2.push(finding(mcpFile, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
7679
7848
|
}
|
|
7680
|
-
const sessions =
|
|
7849
|
+
const sessions = join8(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
7681
7850
|
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out2);
|
|
7682
7851
|
}
|
|
7683
|
-
dataDir(
|
|
7852
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7684
7853
|
}
|
|
7685
7854
|
function jsonFiles(dir) {
|
|
7686
7855
|
try {
|
|
7687
|
-
return
|
|
7856
|
+
return readdirSync3(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
7688
7857
|
} catch {
|
|
7689
7858
|
return [];
|
|
7690
7859
|
}
|
|
7691
7860
|
}
|
|
7692
7861
|
function scanKiro(agentHome, project, out2) {
|
|
7693
|
-
const agentsDir =
|
|
7694
|
-
const defaultFile =
|
|
7862
|
+
const agentsDir = join8(agentHome, KIRO_AGENTS_DIR);
|
|
7863
|
+
const defaultFile = join8(agentHome, ...KIRO_AGENT_FILE);
|
|
7695
7864
|
for (const name of jsonFiles(agentsDir)) {
|
|
7696
|
-
const file =
|
|
7865
|
+
const file = join8(agentsDir, name);
|
|
7697
7866
|
const doc = readJson(file);
|
|
7698
7867
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
7699
7868
|
out2.push(finding(file, "", V1_REASON.kiroAgentFile));
|
|
@@ -7704,31 +7873,31 @@ function scanKiro(agentHome, project, out2) {
|
|
|
7704
7873
|
if (isV1Hook(c3.command)) out2.push(finding(file, c3.path, V1_REASON.kiroHook));
|
|
7705
7874
|
}
|
|
7706
7875
|
}
|
|
7707
|
-
const steeringDocs = [
|
|
7708
|
-
if (project !== void 0) steeringDocs.push(
|
|
7876
|
+
const steeringDocs = [join8(agentHome, ...KIRO_STEERING_FILE)];
|
|
7877
|
+
if (project !== void 0) steeringDocs.push(join8(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
7709
7878
|
for (const file of steeringDocs) {
|
|
7710
|
-
if (
|
|
7879
|
+
if (existsSync6(file)) out2.push(finding(file, "", V1_REASON.kiroSteering));
|
|
7711
7880
|
}
|
|
7712
|
-
dataDir(
|
|
7881
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7713
7882
|
}
|
|
7714
7883
|
function piNpmIsCurrent(piAgentDir) {
|
|
7715
|
-
const doc = readJson(
|
|
7884
|
+
const doc = readJson(join8(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
7716
7885
|
const version = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
7717
7886
|
return Number.parseInt(version, 10) >= PI_CURRENT_MAJOR;
|
|
7718
7887
|
}
|
|
7719
7888
|
function scanPi(piAgentDir, agentHome, out2) {
|
|
7720
|
-
const file =
|
|
7889
|
+
const file = join8(piAgentDir, SETTINGS_FILE);
|
|
7721
7890
|
const doc = readJson(file);
|
|
7722
7891
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
|
|
7723
7892
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
7724
7893
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
|
|
7725
7894
|
if (spec === PI_GIT_PACKAGE) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piGit));
|
|
7726
7895
|
});
|
|
7727
|
-
dataDir(
|
|
7896
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7728
7897
|
}
|
|
7729
7898
|
function scanOpencode(agentHome, out2) {
|
|
7730
7899
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
7731
|
-
const file =
|
|
7900
|
+
const file = join8(agentHome, name);
|
|
7732
7901
|
const doc = readJson(file);
|
|
7733
7902
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
7734
7903
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i2) => {
|
|
@@ -7739,13 +7908,13 @@ function scanOpencode(agentHome, out2) {
|
|
|
7739
7908
|
}
|
|
7740
7909
|
}
|
|
7741
7910
|
function scanZcode(agentHome, out2) {
|
|
7742
|
-
const configFile =
|
|
7911
|
+
const configFile = join8(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
7743
7912
|
const config = readJson(configFile);
|
|
7744
7913
|
const events2 = isObj(config) && isObj(config[HOOKS_KEY]) ? config[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
7745
7914
|
for (const c3 of flatCommands(events2, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
7746
7915
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(configFile, c3.path, V1_REASON.zcodeHook));
|
|
7747
7916
|
}
|
|
7748
|
-
const hooksFile =
|
|
7917
|
+
const hooksFile = join8(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
7749
7918
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7750
7919
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(hooksFile, c3.path, V1_REASON.zcodeHook));
|
|
7751
7920
|
}
|
|
@@ -7769,14 +7938,14 @@ function firstTmpMatch(dir) {
|
|
|
7769
7938
|
}
|
|
7770
7939
|
}
|
|
7771
7940
|
function scanAll(home, tmp, out2) {
|
|
7772
|
-
const root =
|
|
7773
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
7941
|
+
const root = join8(home, DATA_ROOT.slice(1));
|
|
7942
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join8(root, name), V1_REASON.dataRoot, out2);
|
|
7774
7943
|
if (firstTmpMatch(tmp) !== null) out2.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
7775
7944
|
}
|
|
7776
7945
|
function detectV1(agent, home, scope = {}) {
|
|
7777
7946
|
const out2 = [];
|
|
7778
7947
|
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 :
|
|
7948
|
+
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
7949
|
switch (agent) {
|
|
7781
7950
|
case "claude-code":
|
|
7782
7951
|
scanClaudeCode(home, agentHome, out2);
|
|
@@ -7789,11 +7958,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7789
7958
|
break;
|
|
7790
7959
|
case "qwen":
|
|
7791
7960
|
claudeShapeSettings(agentHome, out2);
|
|
7792
|
-
dataDir(
|
|
7961
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7793
7962
|
break;
|
|
7794
7963
|
case "copilot-cli":
|
|
7795
|
-
v1HookFile(
|
|
7796
|
-
dataDir(
|
|
7964
|
+
v1HookFile(join8(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7965
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7797
7966
|
break;
|
|
7798
7967
|
case "vscode":
|
|
7799
7968
|
scanVscode(agentHome, project, out2);
|
|
@@ -7802,7 +7971,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7802
7971
|
scanKiro(agentHome, project, out2);
|
|
7803
7972
|
break;
|
|
7804
7973
|
case "pi":
|
|
7805
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
7974
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join8(agentHome, PI_AGENT_DIR), agentHome, out2);
|
|
7806
7975
|
break;
|
|
7807
7976
|
// D-WIN-PIDIR-1: empty is unset
|
|
7808
7977
|
case "opencode":
|
|
@@ -7817,12 +7986,12 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7817
7986
|
}
|
|
7818
7987
|
|
|
7819
7988
|
// src/core/ops/plugin-root.ts
|
|
7820
|
-
import { existsSync as
|
|
7821
|
-
import { dirname as dirname6, isAbsolute, join as
|
|
7989
|
+
import { existsSync as existsSync7, readdirSync as readdirSync4, readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
|
|
7990
|
+
import { dirname as dirname6, isAbsolute, join as join9, sep as sep2 } from "node:path";
|
|
7822
7991
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
7823
7992
|
|
|
7824
7993
|
// src/setup/pi-gate.ts
|
|
7825
|
-
import { existsSync as
|
|
7994
|
+
import { existsSync as existsSync8, readFileSync as readFileSync5, realpathSync as realpathSync4 } from "node:fs";
|
|
7826
7995
|
import path3 from "node:path";
|
|
7827
7996
|
var OWN_FILE = "pi/index.js";
|
|
7828
7997
|
var EXTENSIONS_KEY = "extensions";
|
|
@@ -7831,9 +8000,9 @@ var TRUST_FILE = "trust.json";
|
|
|
7831
8000
|
var ALWAYS = "always";
|
|
7832
8001
|
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
7833
8002
|
function load(file) {
|
|
7834
|
-
if (!
|
|
8003
|
+
if (!existsSync8(file)) return void 0;
|
|
7835
8004
|
try {
|
|
7836
|
-
return { file, doc: parseHostConfig("pi", file, hostText(
|
|
8005
|
+
return { file, doc: parseHostConfig("pi", file, hostText(readFileSync5(file, "utf8")), "json") };
|
|
7837
8006
|
} catch {
|
|
7838
8007
|
return void 0;
|
|
7839
8008
|
}
|
|
@@ -7941,7 +8110,7 @@ function formUrl(title, summary) {
|
|
|
7941
8110
|
}
|
|
7942
8111
|
|
|
7943
8112
|
// src/setup/registry.ts
|
|
7944
|
-
import { existsSync as
|
|
8113
|
+
import { existsSync as existsSync11, realpathSync as realpathSync6 } from "node:fs";
|
|
7945
8114
|
import path4 from "node:path";
|
|
7946
8115
|
|
|
7947
8116
|
// src/setup/hook-shapes.ts
|
|
@@ -8001,7 +8170,7 @@ var SERVER_BUNDLE = "server.mjs";
|
|
|
8001
8170
|
var HOOK_BUNDLE = "hook.mjs";
|
|
8002
8171
|
var AGENT_FLAG = "--agent";
|
|
8003
8172
|
var LOCK_FILE = "setup.lock";
|
|
8004
|
-
var BACKUP_DIR =
|
|
8173
|
+
var BACKUP_DIR = SETUP_BACKUP_DIR_NAME;
|
|
8005
8174
|
var PLUGIN_ID = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
8006
8175
|
var SKILLS_DIR_NAME = "skills";
|
|
8007
8176
|
var INSTRUCTION_FILES = Object.freeze([
|
|
@@ -8078,7 +8247,7 @@ var NATIVE_PLUGIN = {
|
|
|
8078
8247
|
};
|
|
8079
8248
|
var CELLAR_SEGMENT = "/Cellar/";
|
|
8080
8249
|
var NODE_BIN = ["bin", "node"];
|
|
8081
|
-
var REAL_FS = { exists:
|
|
8250
|
+
var REAL_FS = { exists: existsSync11, real: (p3) => realpathSync6.native(p3) };
|
|
8082
8251
|
function stableNodePath(execPath, fs2 = REAL_FS) {
|
|
8083
8252
|
const at = execPath.indexOf(CELLAR_SEGMENT);
|
|
8084
8253
|
if (at < 0) return execPath;
|
|
@@ -8118,7 +8287,10 @@ function configFor(ctx, id) {
|
|
|
8118
8287
|
const file = id === "vscode" ? ownMcpFileOf(id, own2.file, ctx.env, ctx.home) : agentPath(ctx, id, own2.file);
|
|
8119
8288
|
const format = file.endsWith(".toml") ? "toml" : id === "vscode" ? "jsonc" : "json";
|
|
8120
8289
|
const also = own2.also?.map(([k, v]) => [k, v]);
|
|
8121
|
-
|
|
8290
|
+
const codexHome = id === "codex" ? ctx.env[CODEX_HOME_ENV2] : void 0;
|
|
8291
|
+
const base = ownMcpValue(id, node, server);
|
|
8292
|
+
const value = codexHome !== void 0 && codexHome !== "" ? { ...base, [MCP_ENV_FIELD]: { [CODEX_HOME_ENV2]: codexHome } } : base;
|
|
8293
|
+
return { file, format, key: own2.key, value, ...also ? { also } : {} };
|
|
8122
8294
|
}
|
|
8123
8295
|
if (id === "opencode") {
|
|
8124
8296
|
return {
|
|
@@ -8152,7 +8324,16 @@ function cliFor(ctx, id) {
|
|
|
8152
8324
|
function copyFor(ctx, id) {
|
|
8153
8325
|
if (id !== "claude-code") return void 0;
|
|
8154
8326
|
const file = path4.join(claudeDirOf(ctx.env, ctx.home), HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE);
|
|
8155
|
-
return {
|
|
8327
|
+
return {
|
|
8328
|
+
host: "Claude Code",
|
|
8329
|
+
bin: "claude",
|
|
8330
|
+
plugin: PLUGIN_ID,
|
|
8331
|
+
file,
|
|
8332
|
+
refresh: ["plugin", "update", PLUGIN_ID],
|
|
8333
|
+
enable: ["plugin", "enable", PLUGIN_ID],
|
|
8334
|
+
marketplace: ["plugin", "marketplace", "update", PLUGIN_MARKETPLACE_NAME],
|
|
8335
|
+
profile: claudeProfileEnv(ctx.env, ctx.platform ?? process.platform)
|
|
8336
|
+
};
|
|
8156
8337
|
}
|
|
8157
8338
|
var LIST = {
|
|
8158
8339
|
"claude-code": { bin: "claude", args: ["plugin", "list"] },
|
|
@@ -8268,7 +8449,7 @@ function assertWritable(row, file) {
|
|
|
8268
8449
|
}
|
|
8269
8450
|
|
|
8270
8451
|
// src/setup/gemini-gate.ts
|
|
8271
|
-
import { existsSync as
|
|
8452
|
+
import { existsSync as existsSync12, readFileSync as readFileSync8 } from "node:fs";
|
|
8272
8453
|
import path5 from "node:path";
|
|
8273
8454
|
var GEMINI_DIR = ".gemini";
|
|
8274
8455
|
var SETTINGS_FILE2 = "settings.json";
|
|
@@ -8288,9 +8469,9 @@ function systemDefaultsPath(env) {
|
|
|
8288
8469
|
return set2 ? set2 : path5.join(path5.dirname(systemSettingsPath(env)), SYSTEM_DEFAULTS_FILE);
|
|
8289
8470
|
}
|
|
8290
8471
|
function load2(file) {
|
|
8291
|
-
if (!
|
|
8472
|
+
if (!existsSync12(file)) return void 0;
|
|
8292
8473
|
try {
|
|
8293
|
-
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(
|
|
8474
|
+
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync8(file, "utf8")), "jsonc") };
|
|
8294
8475
|
} catch {
|
|
8295
8476
|
return void 0;
|
|
8296
8477
|
}
|
|
@@ -8322,7 +8503,7 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
8322
8503
|
}
|
|
8323
8504
|
|
|
8324
8505
|
// src/setup/zcode-gate.ts
|
|
8325
|
-
import { existsSync as
|
|
8506
|
+
import { existsSync as existsSync13, readFileSync as readFileSync9 } from "node:fs";
|
|
8326
8507
|
import path6 from "node:path";
|
|
8327
8508
|
var OWN_AGENT2 = "zcode";
|
|
8328
8509
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
@@ -8414,10 +8595,10 @@ function zcodeSchemaBad(doc) {
|
|
|
8414
8595
|
}
|
|
8415
8596
|
function zcodeConfigGate(home) {
|
|
8416
8597
|
const file = path6.join(home, ".zcode", "cli", "config.json");
|
|
8417
|
-
if (!
|
|
8598
|
+
if (!existsSync13(file)) return void 0;
|
|
8418
8599
|
let doc;
|
|
8419
8600
|
try {
|
|
8420
|
-
doc = parseHostConfig(OWN_AGENT2, file, hostText(
|
|
8601
|
+
doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync9(file, "utf8")), "json");
|
|
8421
8602
|
} catch {
|
|
8422
8603
|
return void 0;
|
|
8423
8604
|
}
|
|
@@ -8427,7 +8608,7 @@ function zcodeConfigGate(home) {
|
|
|
8427
8608
|
}
|
|
8428
8609
|
|
|
8429
8610
|
// src/setup/vscode-gate.ts
|
|
8430
|
-
import { existsSync as
|
|
8611
|
+
import { existsSync as existsSync14, readFileSync as readFileSync10 } from "node:fs";
|
|
8431
8612
|
import path7 from "node:path";
|
|
8432
8613
|
var SETTINGS_FILE3 = "settings.json";
|
|
8433
8614
|
var WORKSPACE_DIR = ".vscode";
|
|
@@ -8436,9 +8617,9 @@ var LOCATIONS_KEY = "chat.hookFilesLocations";
|
|
|
8436
8617
|
var OWN_LOCATION = "~/.copilot/hooks";
|
|
8437
8618
|
var MANAGED_KEYS = ["allowManagedHooksOnly", "strictPluginOnlyCustomization"];
|
|
8438
8619
|
function load3(file) {
|
|
8439
|
-
if (!
|
|
8620
|
+
if (!existsSync14(file)) return void 0;
|
|
8440
8621
|
try {
|
|
8441
|
-
return { file, doc: parseHostConfig("vscode", file, hostText(
|
|
8622
|
+
return { file, doc: parseHostConfig("vscode", file, hostText(readFileSync10(file, "utf8")), "jsonc") };
|
|
8442
8623
|
} catch {
|
|
8443
8624
|
return void 0;
|
|
8444
8625
|
}
|
|
@@ -8478,7 +8659,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
|
|
|
8478
8659
|
}
|
|
8479
8660
|
|
|
8480
8661
|
// src/setup/qwen-gate.ts
|
|
8481
|
-
import { existsSync as
|
|
8662
|
+
import { existsSync as existsSync15, readFileSync as readFileSync11 } from "node:fs";
|
|
8482
8663
|
import path8 from "node:path";
|
|
8483
8664
|
var KEY = "disableAllHooks";
|
|
8484
8665
|
var SETTINGS = "settings.json";
|
|
@@ -8494,10 +8675,10 @@ function settingsFiles(env, home, cwd, platform) {
|
|
|
8494
8675
|
}
|
|
8495
8676
|
function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
|
|
8496
8677
|
for (const file of settingsFiles(env, home, cwd, platform)) {
|
|
8497
|
-
if (!
|
|
8678
|
+
if (!existsSync15(file)) continue;
|
|
8498
8679
|
let value;
|
|
8499
8680
|
try {
|
|
8500
|
-
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(
|
|
8681
|
+
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(readFileSync11(file, "utf8")), "jsonc"), [KEY]);
|
|
8501
8682
|
} catch {
|
|
8502
8683
|
continue;
|
|
8503
8684
|
}
|
|
@@ -8508,7 +8689,7 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
|
|
|
8508
8689
|
|
|
8509
8690
|
// src/setup/codex-trust.ts
|
|
8510
8691
|
import { createHash } from "node:crypto";
|
|
8511
|
-
import { existsSync as
|
|
8692
|
+
import { existsSync as existsSync16, realpathSync as realpathSync7 } from "node:fs";
|
|
8512
8693
|
import path10 from "node:path";
|
|
8513
8694
|
import { spawn, spawnSync as spawnSync3 } from "node:child_process";
|
|
8514
8695
|
|
|
@@ -8617,7 +8798,7 @@ function snake(name) {
|
|
|
8617
8798
|
function realFile(file) {
|
|
8618
8799
|
let dir = path10.resolve(file);
|
|
8619
8800
|
const rest = [];
|
|
8620
|
-
while (!
|
|
8801
|
+
while (!existsSync16(dir) && path10.dirname(dir) !== dir) {
|
|
8621
8802
|
rest.unshift(path10.basename(dir));
|
|
8622
8803
|
dir = path10.dirname(dir);
|
|
8623
8804
|
}
|
|
@@ -8917,7 +9098,7 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
8917
9098
|
|
|
8918
9099
|
// src/setup/engine.ts
|
|
8919
9100
|
import { spawn as spawn3, spawnSync as spawnSync4 } from "node:child_process";
|
|
8920
|
-
import { closeSync as closeSync3, existsSync as
|
|
9101
|
+
import { closeSync as closeSync3, existsSync as existsSync17, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync3, readFileSync as readFileSync12, readSync as readSync3, readdirSync as readdirSync6, realpathSync as realpathSync9, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
8921
9102
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8922
9103
|
import path12 from "node:path";
|
|
8923
9104
|
|
|
@@ -8992,7 +9173,7 @@ var HOOK_ROUNDS = 5;
|
|
|
8992
9173
|
var P95 = 0.95;
|
|
8993
9174
|
var VERIFY_TIMEOUT_MS = 1e4;
|
|
8994
9175
|
var INSTALL_TIMEOUT_MS = 12e4;
|
|
8995
|
-
var MANIFEST =
|
|
9176
|
+
var MANIFEST = SETUP_MANIFEST_FILE;
|
|
8996
9177
|
var MANIFEST_DONE = "manifest.removed.json";
|
|
8997
9178
|
var FILES = "files";
|
|
8998
9179
|
var V1_HOOK_MARK = "context-mode hook";
|
|
@@ -9015,9 +9196,9 @@ function isNativeBinary(file) {
|
|
|
9015
9196
|
function owningPackage(dir) {
|
|
9016
9197
|
for (let d = dir; ; d = path12.dirname(d)) {
|
|
9017
9198
|
const f2 = path12.join(d, "package.json");
|
|
9018
|
-
if (
|
|
9199
|
+
if (existsSync17(f2)) {
|
|
9019
9200
|
try {
|
|
9020
|
-
return String(JSON.parse(hostText(
|
|
9201
|
+
return String(JSON.parse(hostText(readFileSync12(f2, "utf8"))).name);
|
|
9021
9202
|
} catch {
|
|
9022
9203
|
return void 0;
|
|
9023
9204
|
}
|
|
@@ -9033,7 +9214,7 @@ function hostBin(bin, env, platform = process.platform) {
|
|
|
9033
9214
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
9034
9215
|
const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
|
|
9035
9216
|
for (const f2 of [own2, ...real2.extra.map((p3) => path12.join(dir, ...p3))]) {
|
|
9036
|
-
if (!f2 || !
|
|
9217
|
+
if (!f2 || !existsSync17(f2) || !statSync2(f2).isFile()) continue;
|
|
9037
9218
|
const file = realpathSync9(f2);
|
|
9038
9219
|
if (isNativeBinary(file) || owningPackage(path12.dirname(file)) === real2.pkg) return { file, shims };
|
|
9039
9220
|
shims.push(f2);
|
|
@@ -9050,10 +9231,10 @@ function runBin(bin, args, env, input, timeout = VERIFY_TIMEOUT_MS) {
|
|
|
9050
9231
|
return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout, maxBuffer: Infinity });
|
|
9051
9232
|
}
|
|
9052
9233
|
function readOr(file) {
|
|
9053
|
-
return
|
|
9234
|
+
return existsSync17(file) ? hostText(readFileSync12(file, "utf8")) : void 0;
|
|
9054
9235
|
}
|
|
9055
9236
|
function readRaw(file) {
|
|
9056
|
-
return
|
|
9237
|
+
return existsSync17(file) ? readFileSync12(file, "utf8") : void 0;
|
|
9057
9238
|
}
|
|
9058
9239
|
var atomicWrite = atomicWriteFile;
|
|
9059
9240
|
function pidAlive(pid) {
|
|
@@ -9198,7 +9379,7 @@ function isNativeSpec(e) {
|
|
|
9198
9379
|
function isStaleOwnPlugin(e, entry2) {
|
|
9199
9380
|
if (typeof e !== "string" || e === entry2 || !path12.isAbsolute(e)) return false;
|
|
9200
9381
|
if (e === path12.join(entry2, ...OPENCODE_PLUGIN_PATH)) return true;
|
|
9201
|
-
if (
|
|
9382
|
+
if (existsSync17(e)) return false;
|
|
9202
9383
|
const seg = e.split("\\").join("/").split("/");
|
|
9203
9384
|
const n3 = seg.length;
|
|
9204
9385
|
if (n3 >= 3 && seg[n3 - 1] === "plugin.js" && seg[n3 - 2] === "opencode" && seg[n3 - 3] === "context-mode") return true;
|
|
@@ -9262,8 +9443,8 @@ function planSkills(row, edits) {
|
|
|
9262
9443
|
const s = row.skillInstall;
|
|
9263
9444
|
if (s.kind !== "dir") return;
|
|
9264
9445
|
for (const f2 of s.files) {
|
|
9265
|
-
if (!
|
|
9266
|
-
const after = renderSkill(
|
|
9446
|
+
if (!existsSync17(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
|
|
9447
|
+
const after = renderSkill(readFileSync12(f2.src, "utf8"), s.prefixes);
|
|
9267
9448
|
const before = readRaw(f2.file);
|
|
9268
9449
|
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
9450
|
}
|
|
@@ -9275,7 +9456,7 @@ function planRow(row, listed, stale, env, disabled = false) {
|
|
|
9275
9456
|
const before = readOr(c3.file);
|
|
9276
9457
|
let res;
|
|
9277
9458
|
try {
|
|
9278
|
-
res = editHostConfigText(row.id, c3.file, before ?? "", c3.format,
|
|
9459
|
+
res = editHostConfigText(row.id, c3.file, before ?? "", c3.format, ownConfigEdits(row, c3, before ?? ""));
|
|
9279
9460
|
} catch (e) {
|
|
9280
9461
|
if (e instanceof CtxError) throw new Error(parseFail(row, c3.file));
|
|
9281
9462
|
throw e;
|
|
@@ -9289,7 +9470,7 @@ function planRow(row, listed, stale, env, disabled = false) {
|
|
|
9289
9470
|
planHookInstall(row, edits, env);
|
|
9290
9471
|
planSkills(row, edits);
|
|
9291
9472
|
const cli = row.config || !row.cli || listed ? [] : row.cli.install;
|
|
9292
|
-
const refresh = listed && stale && row.copy ? [row.copy.refresh] : [];
|
|
9473
|
+
const refresh = listed && stale && row.copy ? [row.copy.marketplace, row.copy.refresh] : [];
|
|
9293
9474
|
if (listed && disabled && row.copy) refresh.push(row.copy.enable);
|
|
9294
9475
|
return { edits, cli, refresh };
|
|
9295
9476
|
}
|
|
@@ -9397,13 +9578,16 @@ function hookEnabledCheck(row, status) {
|
|
|
9397
9578
|
}
|
|
9398
9579
|
function packageVersion(pkgDir) {
|
|
9399
9580
|
try {
|
|
9400
|
-
const v = JSON.parse(hostText(
|
|
9581
|
+
const v = JSON.parse(hostText(readFileSync12(path12.join(pkgDir, "package.json"), "utf8"))).version;
|
|
9401
9582
|
return typeof v === "string" ? v : void 0;
|
|
9402
9583
|
} catch {
|
|
9403
9584
|
return void 0;
|
|
9404
9585
|
}
|
|
9405
9586
|
}
|
|
9406
|
-
function
|
|
9587
|
+
function copyFix(c3) {
|
|
9588
|
+
return `${c3.profile}${c3.bin} ${c3.marketplace.join(" ")} && ${c3.profile}${c3.bin} ${c3.refresh.join(" ")}`;
|
|
9589
|
+
}
|
|
9590
|
+
function staleCopy(row, pkgDir) {
|
|
9407
9591
|
const c3 = row.copy;
|
|
9408
9592
|
const pkg = packageVersion(pkgDir);
|
|
9409
9593
|
const text2 = c3 ? readOr(c3.file) : void 0;
|
|
@@ -9413,14 +9597,32 @@ function copyCheck(row, pkgDir) {
|
|
|
9413
9597
|
const doc = JSON.parse(text2);
|
|
9414
9598
|
entries = isObj5(doc) && isObj5(doc.plugins) ? doc.plugins[c3.plugin] : void 0;
|
|
9415
9599
|
} catch {
|
|
9416
|
-
return { name: "copy", ok: false, detail: `${c3.file} is not valid JSON; run ${c3
|
|
9600
|
+
return { name: "copy", ok: false, detail: `${c3.file} is not valid JSON; run ${copyFix(c3)}` };
|
|
9417
9601
|
}
|
|
9418
9602
|
if (!Array.isArray(entries)) return void 0;
|
|
9419
9603
|
const versions = entries.filter(isObj5).map((e) => e.version).filter((v) => typeof v === "string");
|
|
9420
9604
|
if (!versions.length) return void 0;
|
|
9421
9605
|
const old = versions.find((v) => v !== pkg);
|
|
9422
|
-
|
|
9423
|
-
|
|
9606
|
+
return old === void 0 ? { name: "copy", ok: true } : { old, pkg };
|
|
9607
|
+
}
|
|
9608
|
+
function copyCheck(row, pkgDir) {
|
|
9609
|
+
const r2 = staleCopy(row, pkgDir);
|
|
9610
|
+
if (r2 === void 0 || "name" in r2) return r2;
|
|
9611
|
+
const c3 = row.copy;
|
|
9612
|
+
return { name: "copy", ok: false, detail: `${c3.host} runs context-mode ${r2.old}, the installed package is ${r2.pkg}; run ${copyFix(c3)}` };
|
|
9613
|
+
}
|
|
9614
|
+
function copyWarn(row, pkgDir, refreshNotes) {
|
|
9615
|
+
const r2 = staleCopy(row, pkgDir);
|
|
9616
|
+
if (r2 === void 0 || "name" in r2) return void 0;
|
|
9617
|
+
const c3 = row.copy;
|
|
9618
|
+
const why = refreshNotes.length ? ` (${refreshNotes.join("; ")})` : "";
|
|
9619
|
+
return { name: "copy", ok: true, warn: true, detail: `${c3.host} still runs context-mode ${r2.old}, the installed package is ${r2.pkg}${why}; run ${copyFix(c3)}` };
|
|
9620
|
+
}
|
|
9621
|
+
function degradedDetail(node, env) {
|
|
9622
|
+
const r2 = spawnSync4(node, ["-p", "process.version"], { env, encoding: "utf8", timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
|
|
9623
|
+
const v = `${r2.stdout ?? ""}`.trim();
|
|
9624
|
+
if (v && nodeTooOld(v)) return `Node too old: ${D2_NODE_DETAIL(v)}. Fix: ${D2_NODE_FIX}`;
|
|
9625
|
+
return `only ctx_doctor is served: ${D2_SQLITE_DETAIL} under ${node}${v ? ` ${v}` : ""}. Fix: ${D2_SQLITE_FIX}`;
|
|
9424
9626
|
}
|
|
9425
9627
|
function mcpCheck(cmd, env) {
|
|
9426
9628
|
return new Promise((resolve3) => {
|
|
@@ -9462,7 +9664,7 @@ function mcpCheck(cmd, env) {
|
|
|
9462
9664
|
const want = [...TOOL_ORDER].sort();
|
|
9463
9665
|
const got = [...tools].sort();
|
|
9464
9666
|
const ok = JSON.stringify(got) === JSON.stringify(want);
|
|
9465
|
-
done(ok, ok ? void 0 : `tools/list returned ${got.join(",")}, expected ${want.join(",")}`);
|
|
9667
|
+
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
9668
|
}
|
|
9467
9669
|
}
|
|
9468
9670
|
});
|
|
@@ -9513,11 +9715,29 @@ function hookCheck(row, env) {
|
|
|
9513
9715
|
}
|
|
9514
9716
|
return best;
|
|
9515
9717
|
}
|
|
9718
|
+
function ownConfigEdits(row, c3, text2) {
|
|
9719
|
+
const edits = configEdits(c3);
|
|
9720
|
+
if (row.id !== "codex" || !isObj5(c3.value)) return edits;
|
|
9721
|
+
let cur;
|
|
9722
|
+
try {
|
|
9723
|
+
cur = hostConfigValueAt(parseHostConfig(row.id, c3.file, text2, c3.format), c3.key);
|
|
9724
|
+
} catch {
|
|
9725
|
+
return edits;
|
|
9726
|
+
}
|
|
9727
|
+
if (!isObj5(cur)) return edits;
|
|
9728
|
+
const value = { ...c3.value };
|
|
9729
|
+
const userEnv = cur[MCP_ENV_FIELD];
|
|
9730
|
+
const ownEnv = value[MCP_ENV_FIELD];
|
|
9731
|
+
if (isObj5(userEnv) || isObj5(ownEnv)) value[MCP_ENV_FIELD] = { ...isObj5(userEnv) ? userEnv : {}, ...isObj5(ownEnv) ? ownEnv : {} };
|
|
9732
|
+
if (Array.isArray(cur[MCP_ENV_VARS_FIELD])) value[MCP_ENV_VARS_FIELD] = cur[MCP_ENV_VARS_FIELD];
|
|
9733
|
+
return [[c3.key, value], ...edits.slice(1)];
|
|
9734
|
+
}
|
|
9516
9735
|
function parseCheck(row) {
|
|
9517
9736
|
const c3 = row.config;
|
|
9518
9737
|
if (!c3) return { name: "parse", ok: true };
|
|
9519
9738
|
try {
|
|
9520
|
-
const
|
|
9739
|
+
const text2 = readOr(c3.file) ?? "";
|
|
9740
|
+
const r2 = editHostConfigText(row.id, c3.file, text2, c3.format, ownConfigEdits(row, c3, text2));
|
|
9521
9741
|
return { name: "parse", ok: r2.edits.length === 0, detail: r2.edits.length ? "entry differs after write" : void 0 };
|
|
9522
9742
|
} catch (e) {
|
|
9523
9743
|
return { name: "parse", ok: false, detail: e.message };
|
|
@@ -9568,7 +9788,7 @@ var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
|
|
|
9568
9788
|
var NOT_SEEN_LINE = "not seen yet, run one tool call";
|
|
9569
9789
|
function hookSeenCheck(row, dataRoot) {
|
|
9570
9790
|
const base = path12.join(dataRoot, PROJECTS_DIR_NAME);
|
|
9571
|
-
const dirs =
|
|
9791
|
+
const dirs = existsSync17(base) ? readdirSync6(base) : [];
|
|
9572
9792
|
let sqlite;
|
|
9573
9793
|
try {
|
|
9574
9794
|
sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -9577,7 +9797,7 @@ function hookSeenCheck(row, dataRoot) {
|
|
|
9577
9797
|
}
|
|
9578
9798
|
for (const d of dirs) {
|
|
9579
9799
|
const file = path12.join(base, d, DB_FILE_NAME);
|
|
9580
|
-
if (!sqlite || !
|
|
9800
|
+
if (!sqlite || !existsSync17(file)) continue;
|
|
9581
9801
|
let db;
|
|
9582
9802
|
try {
|
|
9583
9803
|
db = new sqlite.DatabaseSync(file, { readOnly: true });
|
|
@@ -9594,17 +9814,17 @@ function skillsCheck(row, pkgDir) {
|
|
|
9594
9814
|
const s = row.skillInstall;
|
|
9595
9815
|
if (s.kind === "package") {
|
|
9596
9816
|
const files = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE));
|
|
9597
|
-
const miss = files.filter((f2) => !
|
|
9817
|
+
const miss = files.filter((f2) => !existsSync17(f2));
|
|
9598
9818
|
if (miss.length) return { name: "skills", ok: false, detail: `missing ${miss.join(", ")}` };
|
|
9599
9819
|
const own2 = getAdapter(row.id).toolNamePrefix + SKILL_TOOL_STEM;
|
|
9600
9820
|
const foreign = [...new Set(ADAPTERS.map((r2) => r2.toolNamePrefix + SKILL_TOOL_STEM))].filter((n3) => n3 !== SKILL_TOOL_STEM && n3 !== own2);
|
|
9601
9821
|
const bad2 = files.filter((f2) => {
|
|
9602
|
-
const t2 =
|
|
9822
|
+
const t2 = readFileSync12(f2, "utf8");
|
|
9603
9823
|
return !t2.includes(own2) && foreign.some((n3) => t2.includes(n3));
|
|
9604
9824
|
});
|
|
9605
9825
|
return { name: "skills", ok: bad2.length === 0, detail: bad2.length ? `${bad2.join(", ")} without the ${own2}* tool name` : void 0 };
|
|
9606
9826
|
}
|
|
9607
|
-
const bad = s.files.filter((f2) => readRaw(f2.file) !== (
|
|
9827
|
+
const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync17(f2.src) ? renderSkill(readFileSync12(f2.src, "utf8"), s.prefixes) : void 0));
|
|
9608
9828
|
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
9829
|
}
|
|
9610
9830
|
var CODEX_CONFIG_FILE2 = "config.toml";
|
|
@@ -9884,7 +10104,7 @@ function undo(dir, entries, env) {
|
|
|
9884
10104
|
continue;
|
|
9885
10105
|
}
|
|
9886
10106
|
if (!e.file) continue;
|
|
9887
|
-
if (e.existed && e.backup) atomicWrite(e.file,
|
|
10107
|
+
if (e.existed && e.backup) atomicWrite(e.file, readFileSync12(path12.join(dir, e.backup), "utf8"));
|
|
9888
10108
|
else unlinkWithRetry(e.file);
|
|
9889
10109
|
}
|
|
9890
10110
|
}
|
|
@@ -9899,7 +10119,7 @@ function takeLock(root, runId) {
|
|
|
9899
10119
|
if (e.code !== "EEXIST") throw e;
|
|
9900
10120
|
let pid = 0;
|
|
9901
10121
|
try {
|
|
9902
|
-
pid = Number(JSON.parse(
|
|
10122
|
+
pid = Number(JSON.parse(readFileSync12(file, "utf8")).pid);
|
|
9903
10123
|
} catch {
|
|
9904
10124
|
}
|
|
9905
10125
|
if (pid && pidAlive(pid)) return `setup lock ${file} is held by pid ${pid}; wait for that run or remove the lock`;
|
|
@@ -9917,14 +10137,16 @@ function agentHomeDir(id, ctx) {
|
|
|
9917
10137
|
return path12.join(ctx.home, ...AGENT_HOME_DIR[id]);
|
|
9918
10138
|
}
|
|
9919
10139
|
function detectAgents(reg, ctx) {
|
|
9920
|
-
return reg.filter((r2) =>
|
|
10140
|
+
return reg.filter((r2) => existsSync17(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
|
|
9921
10141
|
}
|
|
9922
10142
|
async function runSetup(opts) {
|
|
9923
10143
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9924
10144
|
const runId = opts.runId ?? (/* @__PURE__ */ new Date()).toISOString().split(":").join("-").split(".").join("-");
|
|
9925
10145
|
const reg = buildRegistry(ctx);
|
|
10146
|
+
const nodeVersion = opts.nodeVersion ?? process.version;
|
|
10147
|
+
if (nodeTooOld(nodeVersion)) return { exitCode: 1, agents: [], error: formatError("NODE_TOO_OLD", { v: nodeVersion }) };
|
|
9926
10148
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9927
|
-
if (!
|
|
10149
|
+
if (!existsSync17(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9928
10150
|
}
|
|
9929
10151
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9930
10152
|
const root = dataRootOf(ctx.env, ctx.home);
|
|
@@ -9995,13 +10217,23 @@ async function setupRow(row, ctx, run, dryRun) {
|
|
|
9995
10217
|
if (!installExitOk(r2.status, r2.status === WIN_EXIT_CRASH && listCheck(row, ctx.env)?.ok === true)) throw new Error(`${row.cli.bin} ${args.join(" ")} exited ${r2.status}: ${`${r2.stderr}`.trim()}`);
|
|
9996
10218
|
}
|
|
9997
10219
|
if (plan.cli.length) for (const args of row.cli.remove) run.record({ agent: row.id, undo: { bin: row.cli.bin, args } });
|
|
10220
|
+
const refreshNotes = [];
|
|
9998
10221
|
for (const args of plan.refresh) {
|
|
9999
10222
|
const r2 = runBin(row.cli.bin, args, ctx.env, void 0, INSTALL_TIMEOUT_MS);
|
|
10000
|
-
|
|
10223
|
+
const failed = `${row.cli.bin} ${args.join(" ")} exited ${r2.status}: ${`${r2.stderr}`.trim()}`;
|
|
10224
|
+
if (r2.status !== 0 && !isCopyRefresh(row, args)) throw new Error(failed);
|
|
10225
|
+
if (r2.status !== 0) {
|
|
10226
|
+
refreshNotes.push(failed);
|
|
10227
|
+
continue;
|
|
10228
|
+
}
|
|
10001
10229
|
run.record({ agent: row.id, ran: { bin: row.cli.bin, args } });
|
|
10002
10230
|
}
|
|
10003
10231
|
res.changes.push(...await enableCopilotHooks(row, ctx, run));
|
|
10004
10232
|
res.checks = await verifyRow(row, ctx);
|
|
10233
|
+
if (plan.refresh.length) {
|
|
10234
|
+
const w = copyWarn(row, ctx.pkgDir, refreshNotes);
|
|
10235
|
+
if (w) res.checks = res.checks.map((c3) => c3.name === "copy" ? w : c3);
|
|
10236
|
+
}
|
|
10005
10237
|
const bad = res.checks.filter((c3) => !c3.ok);
|
|
10006
10238
|
if (bad.length) throw new Error(bad.map((c3) => `${c3.name}: ${c3.detail}`).join("; "));
|
|
10007
10239
|
} catch (e) {
|
|
@@ -10018,7 +10250,7 @@ async function runDoctor(opts) {
|
|
|
10018
10250
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
10019
10251
|
const reg = buildRegistry(ctx);
|
|
10020
10252
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
10021
|
-
if (!
|
|
10253
|
+
if (!existsSync17(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
10022
10254
|
}
|
|
10023
10255
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
10024
10256
|
const run = new Run(dataRootOf(ctx.env, ctx.home), "doctor");
|
|
@@ -10078,7 +10310,12 @@ function isRefresh(row, c3) {
|
|
|
10078
10310
|
const r2 = row.copy;
|
|
10079
10311
|
if (r2 === void 0 || c3.command === void 0) return false;
|
|
10080
10312
|
const cmd = c3.command.join(" ");
|
|
10081
|
-
return
|
|
10313
|
+
return isCopyRefresh(row, c3.command.slice(1)) || cmd === [r2.bin, ...r2.enable].join(" ");
|
|
10314
|
+
}
|
|
10315
|
+
function isCopyRefresh(row, args) {
|
|
10316
|
+
const r2 = row.copy;
|
|
10317
|
+
const a2 = args.join(" ");
|
|
10318
|
+
return r2 !== void 0 && (a2 === r2.refresh.join(" ") || a2 === r2.marketplace.join(" "));
|
|
10082
10319
|
}
|
|
10083
10320
|
function isTrust(row, c3) {
|
|
10084
10321
|
const h2 = row.hookInstall;
|
|
@@ -10088,14 +10325,14 @@ function runRemove(opts) {
|
|
|
10088
10325
|
const env = opts.env ?? process.env;
|
|
10089
10326
|
const root = dataRootOf(env, opts.home);
|
|
10090
10327
|
const base = path12.join(root, BACKUP_DIR);
|
|
10091
|
-
if (!
|
|
10328
|
+
if (!existsSync17(base)) return { exitCode: 0, restored: 0 };
|
|
10092
10329
|
const held = takeLock(root, "remove");
|
|
10093
10330
|
if (held) return { exitCode: 1, restored: 0, error: held };
|
|
10094
10331
|
let restored = 0;
|
|
10095
10332
|
try {
|
|
10096
|
-
const runs =
|
|
10333
|
+
const runs = readdirSync6(base).map((r2) => path12.join(base, r2)).filter((d) => existsSync17(path12.join(d, MANIFEST))).sort().reverse();
|
|
10097
10334
|
for (const dir of runs) {
|
|
10098
|
-
const m3 = JSON.parse(
|
|
10335
|
+
const m3 = JSON.parse(readFileSync12(path12.join(dir, MANIFEST), "utf8"));
|
|
10099
10336
|
undo(dir, m3.entries, env);
|
|
10100
10337
|
restored += m3.entries.length;
|
|
10101
10338
|
renameWithRetry(path12.join(dir, MANIFEST), path12.join(dir, MANIFEST_DONE));
|
|
@@ -10107,7 +10344,7 @@ function runRemove(opts) {
|
|
|
10107
10344
|
}
|
|
10108
10345
|
|
|
10109
10346
|
// src/setup/print.ts
|
|
10110
|
-
import { readFileSync as
|
|
10347
|
+
import { readFileSync as readFileSync13 } from "node:fs";
|
|
10111
10348
|
var SHELL_SAFE_PUNCT = "@%+=:,./-_";
|
|
10112
10349
|
function isShellSafe(s) {
|
|
10113
10350
|
if (s === "") return false;
|
|
@@ -10135,7 +10372,7 @@ function printPlan(row, env) {
|
|
|
10135
10372
|
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
10373
|
const sk = row.skillInstall;
|
|
10137
10374
|
if (sk.kind === "dir") {
|
|
10138
|
-
for (const f2 of sk.files) steps.push({ kind: "skill", file: f2.file, block: renderSkill(
|
|
10375
|
+
for (const f2 of sk.files) steps.push({ kind: "skill", file: f2.file, block: renderSkill(readFileSync13(f2.src, "utf8"), sk.prefixes) });
|
|
10139
10376
|
}
|
|
10140
10377
|
return { agent: row.id, steps, verify: `context-mode doctor --agents ${row.id}` };
|
|
10141
10378
|
}
|
|
@@ -10438,6 +10675,10 @@ async function setup(ui) {
|
|
|
10438
10675
|
if (f2.print) return printManual(ui, f2.print);
|
|
10439
10676
|
if (f2.list) return list(ui);
|
|
10440
10677
|
if (f2.remove) return remove(ui);
|
|
10678
|
+
if (nodeTooOld(process.version)) {
|
|
10679
|
+
err(`context-mode: ${formatError("NODE_TOO_OLD", { v: process.version })}`);
|
|
10680
|
+
return EXIT_FAIL;
|
|
10681
|
+
}
|
|
10441
10682
|
if (f2.dryRun) {
|
|
10442
10683
|
const plan = await apply(ui, f2.agents, true);
|
|
10443
10684
|
if (f2.json) out(JSON.stringify({ command: "setup", dryRun: true, ...plan }));
|
|
@@ -10502,11 +10743,13 @@ async function doctor(ui) {
|
|
|
10502
10743
|
}
|
|
10503
10744
|
});
|
|
10504
10745
|
spin.stop();
|
|
10746
|
+
const other = res.agents.length === 0 ? unsupportedHostOf({ env: process.env }) : void 0;
|
|
10747
|
+
if (other !== void 0 && !ui.f.json) out(UNSUPPORTED_HOST_LINE(other.name));
|
|
10505
10748
|
if (!res.agents.length && !res.error && !ui.f.json) {
|
|
10506
10749
|
out("No agents found. Run context-mode setup --list.");
|
|
10507
10750
|
return EXIT_OK;
|
|
10508
10751
|
}
|
|
10509
|
-
const code = await finish({ ...ui, clack: void 0 }, "doctor", res, false);
|
|
10752
|
+
const code = await finish({ ...ui, clack: void 0 }, "doctor", other === void 0 ? res : { ...res, unsupportedHost: other.id }, false);
|
|
10510
10753
|
const p3 = ui.clack;
|
|
10511
10754
|
if (!p3 || code === EXIT_OK) return code;
|
|
10512
10755
|
let worst = code;
|
|
@@ -10557,7 +10800,7 @@ async function upgrade(ui) {
|
|
|
10557
10800
|
}
|
|
10558
10801
|
const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
|
|
10559
10802
|
const cli = path13.join(root, "context-mode", "cli.mjs");
|
|
10560
|
-
if (!root || !
|
|
10803
|
+
if (!root || !existsSync18(cli)) {
|
|
10561
10804
|
err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
|
|
10562
10805
|
return EXIT_FAIL;
|
|
10563
10806
|
}
|
|
@@ -10655,7 +10898,7 @@ function main() {
|
|
|
10655
10898
|
const dir = path14.dirname(realpathSync11(fileURLToPath3(import.meta.url)));
|
|
10656
10899
|
let version = "";
|
|
10657
10900
|
try {
|
|
10658
|
-
version = String(JSON.parse(
|
|
10901
|
+
version = String(JSON.parse(readFileSync14(path14.join(dir, PACKAGE_FILE), "utf8")).version);
|
|
10659
10902
|
} catch (err2) {
|
|
10660
10903
|
process.stderr.write(`${SERVER_KEY}: cannot read ${PACKAGE_FILE}: ${err2.message}
|
|
10661
10904
|
`);
|