context-mode 2.1.1 → 2.1.3
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/README.md +73 -73
- package/SHA256SUMS +15 -15
- package/cli.mjs +164 -144
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +85 -85
- package/opencode/plugin.js +348 -228
- package/package.json +1 -1
- package/pi/index.js +402 -280
- package/qwen-extension.json +1 -1
- package/run.mjs +19 -8
- package/search.mjs +19 -8
- package/server.mjs +374 -262
package/cli.mjs
CHANGED
|
@@ -96,6 +96,8 @@ 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 RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
100
|
+
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
99
101
|
var WEIGHT = Object.freeze({ toolerr: 900, decision: 700, prompt: 500, edit: 400, index: 200 });
|
|
100
102
|
var DECAY_X1000 = Object.freeze([
|
|
101
103
|
1e3,
|
|
@@ -434,6 +436,10 @@ var V1_CACHE_HEAL_NAME = "context-mode-cache-heal";
|
|
|
434
436
|
var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
|
|
435
437
|
var V1_STATUSLINE_COMMAND = "context-mode statusline";
|
|
436
438
|
var V1_PI_PACKAGE = "npm:context-mode";
|
|
439
|
+
var PI_NPM_DIR = "npm";
|
|
440
|
+
var PI_NODE_MODULES_DIR = "node_modules";
|
|
441
|
+
var PI_PACKAGE_JSON_FILE = "package.json";
|
|
442
|
+
var PI_CURRENT_MAJOR = 2;
|
|
437
443
|
var V1_OPENCODE_PLUGIN_SPEC = "context-mode";
|
|
438
444
|
var V1_TMP_PREFIX = "context-mode-";
|
|
439
445
|
var V1_TOML_SECTION_ROOT = "mcp_servers";
|
|
@@ -944,6 +950,14 @@ function canonicalName3(name) {
|
|
|
944
950
|
if (Object.hasOwn(NATIVE_TO_CANONICAL3, name)) return NATIVE_TO_CANONICAL3[name];
|
|
945
951
|
return name;
|
|
946
952
|
}
|
|
953
|
+
var isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
954
|
+
function viewRange(name, input) {
|
|
955
|
+
const r2 = input.view_range;
|
|
956
|
+
if (name !== "view" || !Array.isArray(r2) || !isNum(r2[0])) return input;
|
|
957
|
+
const out2 = { ...input, offset: r2[0] };
|
|
958
|
+
if (isNum(r2[1]) && r2[1] >= r2[0]) out2.limit = r2[1] - r2[0] + 1;
|
|
959
|
+
return out2;
|
|
960
|
+
}
|
|
947
961
|
function readArgs(v) {
|
|
948
962
|
if (isRecord(v)) return v;
|
|
949
963
|
if (typeof v !== "string") return {};
|
|
@@ -988,7 +1002,7 @@ function decode5(raw) {
|
|
|
988
1002
|
if (event === "UserPromptSubmit" && typeof raw.prompt === "string") ev.prompt = raw.prompt;
|
|
989
1003
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
990
1004
|
const toolName = String(raw[k.tool] ?? "");
|
|
991
|
-
const tool = { name: toolName, canonicalName: canonicalName3(toolName), input: readArgs(raw[k.args]) };
|
|
1005
|
+
const tool = { name: toolName, canonicalName: canonicalName3(toolName), input: viewRange(toolName, readArgs(raw[k.args])) };
|
|
992
1006
|
ev.tool = tool;
|
|
993
1007
|
}
|
|
994
1008
|
if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
|
|
@@ -1036,18 +1050,18 @@ function canonicalName4(name) {
|
|
|
1036
1050
|
if (sep2 <= 0 || sep2 === rest.length - 1) return name;
|
|
1037
1051
|
return "mcp:" + rest.slice(0, sep2) + ":" + rest.slice(sep2 + MCP_SEP2.length);
|
|
1038
1052
|
}
|
|
1039
|
-
var
|
|
1053
|
+
var isNum2 = (v) => typeof v === "number" && Number.isFinite(v);
|
|
1040
1054
|
function policyInput(name, canonical, input) {
|
|
1041
1055
|
if (canonical === "Read" && READ_TOOL_NAMES.includes(name)) {
|
|
1042
1056
|
const out2 = { ...input };
|
|
1043
1057
|
if (name === "read_file") {
|
|
1044
1058
|
if (typeof input.filePath === "string") out2.file_path = input.filePath;
|
|
1045
|
-
if (
|
|
1046
|
-
if (
|
|
1047
|
-
} else if (Array.isArray(input.view_range) &&
|
|
1059
|
+
if (isNum2(input.startLine)) out2.offset = input.startLine;
|
|
1060
|
+
if (isNum2(input.startLine) && isNum2(input.endLine) && input.endLine >= input.startLine) out2.limit = input.endLine - input.startLine + 1;
|
|
1061
|
+
} else if (Array.isArray(input.view_range) && isNum2(input.view_range[0])) {
|
|
1048
1062
|
out2.offset = input.view_range[0];
|
|
1049
1063
|
const end = input.view_range[1];
|
|
1050
|
-
if (
|
|
1064
|
+
if (isNum2(end) && end >= input.view_range[0]) out2.limit = end - input.view_range[0] + 1;
|
|
1051
1065
|
}
|
|
1052
1066
|
return out2;
|
|
1053
1067
|
}
|
|
@@ -1237,7 +1251,7 @@ var PI_EVENTS = {
|
|
|
1237
1251
|
tool_call: { event: "PreToolUse" },
|
|
1238
1252
|
tool_result: { event: "PostToolUse" }
|
|
1239
1253
|
};
|
|
1240
|
-
var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read" };
|
|
1254
|
+
var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
|
|
1241
1255
|
function record(v) {
|
|
1242
1256
|
return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
|
|
1243
1257
|
}
|
|
@@ -1507,8 +1521,9 @@ var ADAPTERS = Object.freeze([
|
|
|
1507
1521
|
installMode: "in-process",
|
|
1508
1522
|
projectSource: "pi:ctx.cwd",
|
|
1509
1523
|
toolNamePrefix: TOOL_NAME_PREFIX9,
|
|
1510
|
-
nativeTools: { shell: ["bash"], read: ["read"] },
|
|
1524
|
+
nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
|
|
1511
1525
|
execReadOnlyHint: false,
|
|
1526
|
+
// D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
|
|
1512
1527
|
eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
|
|
1513
1528
|
compactDelivery: "pi-flag",
|
|
1514
1529
|
compactSummary: "none",
|
|
@@ -4727,7 +4742,7 @@ function ownMcpFileOf(agent, file, env, home) {
|
|
|
4727
4742
|
|
|
4728
4743
|
// src/core/ops/doctor-issue.ts
|
|
4729
4744
|
import { spawnSync } from "node:child_process";
|
|
4730
|
-
import { closeSync, existsSync as
|
|
4745
|
+
import { closeSync, existsSync as existsSync9, fstatSync, mkdirSync as mkdirSync4, openSync, readFileSync as readFileSync5, readSync, realpathSync as realpathSync4, writeFileSync as writeFileSync2 } from "node:fs";
|
|
4731
4746
|
import { delimiter, join as join9 } from "node:path";
|
|
4732
4747
|
|
|
4733
4748
|
// src/core/hooks/fallback.ts
|
|
@@ -4824,7 +4839,7 @@ CREATE VIRTUAL TABLE line_units USING fts5(
|
|
|
4824
4839
|
var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
4825
4840
|
|
|
4826
4841
|
// src/core/ops/doctor-config.ts
|
|
4827
|
-
import { existsSync as
|
|
4842
|
+
import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
|
|
4828
4843
|
import { join as join8 } from "node:path";
|
|
4829
4844
|
|
|
4830
4845
|
// src/core/ops/detect-v1.ts
|
|
@@ -7549,12 +7564,17 @@ function scanKiro(agentHome, project, out2) {
|
|
|
7549
7564
|
}
|
|
7550
7565
|
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7551
7566
|
}
|
|
7567
|
+
function piNpmIsCurrent(piAgentDir) {
|
|
7568
|
+
const doc = readJson(join6(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
7569
|
+
const version = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
7570
|
+
return Number.parseInt(version, 10) >= PI_CURRENT_MAJOR;
|
|
7571
|
+
}
|
|
7552
7572
|
function scanPi(piAgentDir, agentHome, out2) {
|
|
7553
7573
|
const file = join6(piAgentDir, SETTINGS_FILE);
|
|
7554
7574
|
const doc = readJson(file);
|
|
7555
7575
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
|
|
7556
7576
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
7557
|
-
if (spec === V1_PI_PACKAGE) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
|
|
7577
|
+
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
|
|
7558
7578
|
});
|
|
7559
7579
|
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7560
7580
|
}
|
|
@@ -7652,6 +7672,106 @@ import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as
|
|
|
7652
7672
|
import { dirname as dirname5, isAbsolute, join as join7, sep } from "node:path";
|
|
7653
7673
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
7654
7674
|
|
|
7675
|
+
// src/setup/pi-gate.ts
|
|
7676
|
+
import { existsSync as existsSync7, readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
|
|
7677
|
+
import path3 from "node:path";
|
|
7678
|
+
var OWN_FILE = "pi/index.js";
|
|
7679
|
+
var EXTENSIONS_KEY = "extensions";
|
|
7680
|
+
var PROJECT_DIR = ".pi";
|
|
7681
|
+
var TRUST_FILE = "trust.json";
|
|
7682
|
+
var ALWAYS = "always";
|
|
7683
|
+
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
7684
|
+
function load(file) {
|
|
7685
|
+
if (!existsSync7(file)) return void 0;
|
|
7686
|
+
try {
|
|
7687
|
+
return { file, doc: parseHostConfig("pi", file, hostText(readFileSync4(file, "utf8")), "json") };
|
|
7688
|
+
} catch {
|
|
7689
|
+
return void 0;
|
|
7690
|
+
}
|
|
7691
|
+
}
|
|
7692
|
+
var real = (p3) => {
|
|
7693
|
+
try {
|
|
7694
|
+
return realpathSync3(p3);
|
|
7695
|
+
} catch {
|
|
7696
|
+
return path3.resolve(p3);
|
|
7697
|
+
}
|
|
7698
|
+
};
|
|
7699
|
+
function sourceName(source) {
|
|
7700
|
+
let s = source;
|
|
7701
|
+
for (const p3 of SOURCE_PREFIXES) if (s.startsWith(p3)) s = s.slice(p3.length);
|
|
7702
|
+
const last2 = s.split("/").pop() ?? "";
|
|
7703
|
+
const at = last2.indexOf("@", 1);
|
|
7704
|
+
const name = at > 0 ? last2.slice(0, at) : last2;
|
|
7705
|
+
return name.endsWith(".git") ? name.slice(0, -4) : name;
|
|
7706
|
+
}
|
|
7707
|
+
function isOwn(source, pkgDir) {
|
|
7708
|
+
if (typeof source !== "string") return false;
|
|
7709
|
+
return real(source) === real(pkgDir) || sourceName(source) === SERVER_KEY;
|
|
7710
|
+
}
|
|
7711
|
+
function ownEntries(src, pkgDir) {
|
|
7712
|
+
const list2 = hostConfigValueAt(src.doc, [PI_PACKAGES_KEY]);
|
|
7713
|
+
if (!Array.isArray(list2)) return [];
|
|
7714
|
+
const out2 = [];
|
|
7715
|
+
for (const e of list2) {
|
|
7716
|
+
const obj = typeof e === "object" && e !== null && !Array.isArray(e) ? e : void 0;
|
|
7717
|
+
if (!isOwn(obj ? obj[PI_PACKAGE_SOURCE_KEY] : e, pkgDir)) continue;
|
|
7718
|
+
const ext = obj?.[EXTENSIONS_KEY];
|
|
7719
|
+
out2.push({ source: src, patterns: Array.isArray(ext) ? ext.filter((x2) => typeof x2 === "string") : void 0 });
|
|
7720
|
+
}
|
|
7721
|
+
return out2;
|
|
7722
|
+
}
|
|
7723
|
+
function matchesAny(patterns, pkgDir) {
|
|
7724
|
+
const abs = path3.join(pkgDir, OWN_FILE).split(path3.sep).join("/");
|
|
7725
|
+
return patterns.some((p3) => {
|
|
7726
|
+
const g2 = p3.startsWith("./") ? p3.slice(2) : p3;
|
|
7727
|
+
return [OWN_FILE, path3.posix.basename(OWN_FILE), abs].some((c3) => path3.posix.matchesGlob(c3, g2));
|
|
7728
|
+
});
|
|
7729
|
+
}
|
|
7730
|
+
var exactAny = (patterns, pkgDir) => {
|
|
7731
|
+
const abs = path3.join(pkgDir, OWN_FILE).split(path3.sep).join("/");
|
|
7732
|
+
return patterns.some((p3) => {
|
|
7733
|
+
const g2 = p3.startsWith("./") ? p3.slice(2) : p3;
|
|
7734
|
+
return g2 === OWN_FILE || g2 === abs;
|
|
7735
|
+
});
|
|
7736
|
+
};
|
|
7737
|
+
function loads(patterns, pkgDir) {
|
|
7738
|
+
if (patterns.length === 0) return false;
|
|
7739
|
+
const by = (c3) => patterns.filter((p3) => p3.startsWith(c3)).map((p3) => p3.slice(1));
|
|
7740
|
+
const includes = patterns.filter((p3) => !"+-!".includes(p3[0] ?? ""));
|
|
7741
|
+
let on = includes.length === 0 || matchesAny(includes, pkgDir);
|
|
7742
|
+
if (matchesAny(by("!"), pkgDir)) on = false;
|
|
7743
|
+
if (exactAny(by("+"), pkgDir)) on = true;
|
|
7744
|
+
if (exactAny(by("-"), pkgDir)) on = false;
|
|
7745
|
+
return on;
|
|
7746
|
+
}
|
|
7747
|
+
function projectTrusted(agentDir, userDoc, cwd) {
|
|
7748
|
+
const trust = load(path3.join(agentDir, TRUST_FILE));
|
|
7749
|
+
const entries = /* @__PURE__ */ new Map();
|
|
7750
|
+
if (trust && typeof trust.doc === "object" && trust.doc !== null) for (const [k, v] of Object.entries(trust.doc)) entries.set(real(k), v);
|
|
7751
|
+
let dir = real(cwd);
|
|
7752
|
+
for (; ; ) {
|
|
7753
|
+
const v = entries.get(dir);
|
|
7754
|
+
if (v === true || v === false) return v;
|
|
7755
|
+
const up = path3.dirname(dir);
|
|
7756
|
+
if (up === dir) break;
|
|
7757
|
+
dir = up;
|
|
7758
|
+
}
|
|
7759
|
+
return hostConfigValueAt(userDoc, ["defaultProjectTrust"]) === ALWAYS;
|
|
7760
|
+
}
|
|
7761
|
+
function piSettingsGate(env, home, pkgDir, cwd) {
|
|
7762
|
+
const agentDir = piAgentDirOf(env, home);
|
|
7763
|
+
const user = load(path3.join(agentDir, SETTINGS_FILE));
|
|
7764
|
+
const project = load(path3.join(cwd, PROJECT_DIR, SETTINGS_FILE));
|
|
7765
|
+
const projectOwn = project && projectTrusted(agentDir, user?.doc, cwd) ? ownEntries(project, pkgDir) : [];
|
|
7766
|
+
const effective = projectOwn.length ? projectOwn : user ? ownEntries(user, pkgDir) : [];
|
|
7767
|
+
for (const e of effective) {
|
|
7768
|
+
if (e.patterns !== void 0 && !loads(e.patterns, pkgDir)) {
|
|
7769
|
+
return `${e.source.file}: the packages[] entry for context-mode has extensions ${JSON.stringify(e.patterns)}, which leaves out ${OWN_FILE}, so pi loads no hook; remove the "extensions" filter from that entry`;
|
|
7770
|
+
}
|
|
7771
|
+
}
|
|
7772
|
+
return void 0;
|
|
7773
|
+
}
|
|
7774
|
+
|
|
7655
7775
|
// src/core/ops/doctor-config.ts
|
|
7656
7776
|
var [PART_MCP, PART_HOOKS, PART_TIMEOUT] = D3_PARTS;
|
|
7657
7777
|
function composeMatcher(row, event) {
|
|
@@ -7672,7 +7792,7 @@ function formUrl(title, summary) {
|
|
|
7672
7792
|
}
|
|
7673
7793
|
|
|
7674
7794
|
// src/setup/registry.ts
|
|
7675
|
-
import
|
|
7795
|
+
import path4 from "node:path";
|
|
7676
7796
|
|
|
7677
7797
|
// src/setup/hook-shapes.ts
|
|
7678
7798
|
var MS_PER_SECOND = 1e3;
|
|
@@ -7758,11 +7878,11 @@ var OPENCODE_HOME_SEGS = AGENT_HOME_DIR.opencode;
|
|
|
7758
7878
|
function agentPath(ctx, id, rel) {
|
|
7759
7879
|
const segs = typeof rel === "string" ? rel.split("/") : [...rel];
|
|
7760
7880
|
const codexHome = ctx.env[CODEX_HOME_ENV2];
|
|
7761
|
-
if (id === "codex" && segs[0] === CODEX_DIR && codexHome !== void 0 && codexHome !== "") return
|
|
7762
|
-
if (id === "copilot-cli" && segs[0] === COPILOT_DIR) return
|
|
7763
|
-
if (id === "kiro" && segs[0] === KIRO_DIR) return
|
|
7764
|
-
if (id === "opencode" && segs[0] === OPENCODE_HOME_SEGS[0] && segs[1] === OPENCODE_HOME_SEGS[1]) return
|
|
7765
|
-
return
|
|
7881
|
+
if (id === "codex" && segs[0] === CODEX_DIR && codexHome !== void 0 && codexHome !== "") return path4.join(codexHome, ...segs.slice(1));
|
|
7882
|
+
if (id === "copilot-cli" && segs[0] === COPILOT_DIR) return path4.join(copilotDirOf(ctx.env, ctx.home), ...segs.slice(1));
|
|
7883
|
+
if (id === "kiro" && segs[0] === KIRO_DIR) return path4.join(kiroDirOf(ctx.env, ctx.home), ...segs.slice(1));
|
|
7884
|
+
if (id === "opencode" && segs[0] === OPENCODE_HOME_SEGS[0] && segs[1] === OPENCODE_HOME_SEGS[1]) return path4.join(opencodeDirOf(ctx.env, ctx.home), ...segs.slice(2));
|
|
7885
|
+
return path4.join(ctx.home, ...segs);
|
|
7766
7886
|
}
|
|
7767
7887
|
function renderSkill(text2, prefix) {
|
|
7768
7888
|
const prefixes = typeof prefix === "string" ? [prefix] : prefix;
|
|
@@ -7792,12 +7912,12 @@ function extensionPlugin(bin, id) {
|
|
|
7792
7912
|
};
|
|
7793
7913
|
}
|
|
7794
7914
|
var NATIVE_PLUGIN = {
|
|
7795
|
-
codex: { bin: "codex", args: ["plugin", "list"], plugin: PLUGIN_ID, hooksVia: ".codex-plugin", skillsVia:
|
|
7915
|
+
codex: { bin: "codex", args: ["plugin", "list"], plugin: PLUGIN_ID, hooksVia: ".codex-plugin", skillsVia: path4.join("codex", SKILLS_DIR_NAME), format: "table", hookTrust: true },
|
|
7796
7916
|
qwen: extensionPlugin("qwen", "qwen"),
|
|
7797
7917
|
gemini: extensionPlugin("gemini", "gemini")
|
|
7798
7918
|
};
|
|
7799
7919
|
function serverCmd(ctx, id) {
|
|
7800
|
-
return [process.execPath,
|
|
7920
|
+
return [process.execPath, path4.join(ctx.pkgDir, SERVER_BUNDLE), AGENT_FLAG, id];
|
|
7801
7921
|
}
|
|
7802
7922
|
function hookCommandString(row) {
|
|
7803
7923
|
const [node, file, flag, id] = row.hookCommand ?? [];
|
|
@@ -7824,7 +7944,7 @@ function configFor(ctx, id) {
|
|
|
7824
7944
|
}
|
|
7825
7945
|
if (id === "opencode") {
|
|
7826
7946
|
return {
|
|
7827
|
-
file:
|
|
7947
|
+
file: path4.join(opencodeDirOf(ctx.env, ctx.home), OPENCODE_BASE_CONFIG_FILE),
|
|
7828
7948
|
format: "jsonc",
|
|
7829
7949
|
key: ["mcp", SERVER_KEY],
|
|
7830
7950
|
value: { type: "local", command: [node, server, flag, agent], enabled: true }
|
|
@@ -7853,7 +7973,7 @@ function cliFor(ctx, id) {
|
|
|
7853
7973
|
}
|
|
7854
7974
|
function copyFor(ctx, id) {
|
|
7855
7975
|
if (id !== "claude-code") return void 0;
|
|
7856
|
-
const file =
|
|
7976
|
+
const file = path4.join(claudeDirOf(ctx.env, ctx.home), HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE);
|
|
7857
7977
|
return { host: "Claude Code", bin: "claude", plugin: PLUGIN_ID, file, refresh: ["plugin", "update", PLUGIN_ID], enable: ["plugin", "enable", PLUGIN_ID] };
|
|
7858
7978
|
}
|
|
7859
7979
|
var LIST = {
|
|
@@ -7874,11 +7994,11 @@ function hookFilesFor(ctx, id) {
|
|
|
7874
7994
|
case "copilot-cli":
|
|
7875
7995
|
return [{ file: agentPath(ctx, id, [COPILOT_DIR, "hooks", "context-mode.json"]), mode: "rewrite" }];
|
|
7876
7996
|
case "claude-code":
|
|
7877
|
-
return [{ file:
|
|
7997
|
+
return [{ file: path4.join(claudeDirOf(ctx.env, home), "settings.json"), mode: "drop" }];
|
|
7878
7998
|
case "gemini":
|
|
7879
|
-
return [{ file:
|
|
7999
|
+
return [{ file: path4.join(home, ".gemini", "settings.json"), mode: "drop" }];
|
|
7880
8000
|
case "qwen":
|
|
7881
|
-
return [{ file:
|
|
8001
|
+
return [{ file: path4.join(home, ".qwen", "settings.json"), mode: "drop" }];
|
|
7882
8002
|
default:
|
|
7883
8003
|
return [];
|
|
7884
8004
|
}
|
|
@@ -7889,13 +8009,13 @@ function hookInstallFor(ctx, row, command) {
|
|
|
7889
8009
|
const shape = HOOK_SHAPES[row.id];
|
|
7890
8010
|
if (!shape) throw new Error(`setup: ${row.id} has a home-file hook channel and no hook shape`);
|
|
7891
8011
|
const file = agentPath(ctx, row.id, ch.path);
|
|
7892
|
-
if (row.id === "codex") return { kind: "file", file, shape: shape(row, command), command, trust:
|
|
8012
|
+
if (row.id === "codex") return { kind: "file", file, shape: shape(row, command), command, trust: path4.join(path4.dirname(file), CODEX_CONFIG_FILE) };
|
|
7893
8013
|
return { kind: "file", file, shape: shape(row, command), command };
|
|
7894
8014
|
}
|
|
7895
8015
|
if (row.id === "opencode") {
|
|
7896
8016
|
return {
|
|
7897
8017
|
kind: "plugin-list",
|
|
7898
|
-
file:
|
|
8018
|
+
file: path4.join(opencodeDirOf(ctx.env, ctx.home), OPENCODE_BASE_CONFIG_FILE),
|
|
7899
8019
|
key: ["plugin"],
|
|
7900
8020
|
entry: ctx.pkgDir
|
|
7901
8021
|
};
|
|
@@ -7911,11 +8031,11 @@ function skillInstallFor(ctx, row) {
|
|
|
7911
8031
|
const ch = row.skillChannel;
|
|
7912
8032
|
if (ch.kind === "package") return { kind: "package", via: ch.path };
|
|
7913
8033
|
const dir = agentPath(ctx, row.id, ch.path);
|
|
7914
|
-
const src =
|
|
8034
|
+
const src = path4.join(ctx.pkgDir, bareSkillDir());
|
|
7915
8035
|
return { kind: "dir", dir, prefixes: skillDirPrefixes(ch.path), files: COMMAND_SKILLS.map((name) => ({
|
|
7916
8036
|
name,
|
|
7917
|
-
src:
|
|
7918
|
-
file:
|
|
8037
|
+
src: path4.join(src, name, SKILL_FILE),
|
|
8038
|
+
file: path4.join(dir, name, SKILL_FILE)
|
|
7919
8039
|
})) };
|
|
7920
8040
|
}
|
|
7921
8041
|
function buildRegistry(ctx) {
|
|
@@ -7923,7 +8043,7 @@ function buildRegistry(ctx) {
|
|
|
7923
8043
|
const id = row.id;
|
|
7924
8044
|
const config = configFor(ctx, id);
|
|
7925
8045
|
const hookFiles = hookFilesFor(ctx, id);
|
|
7926
|
-
const runCommand2 = [process.execPath,
|
|
8046
|
+
const runCommand2 = [process.execPath, path4.join(ctx.pkgDir, HOOK_BUNDLE), AGENT_FLAG, id];
|
|
7927
8047
|
const bareNode = id === "codex" && (ctx.platform ?? process.platform) === "win32";
|
|
7928
8048
|
const hookCommand = bareNode ? [HOST_NODE_COMMAND, ...runCommand2.slice(1)] : runCommand2;
|
|
7929
8049
|
const command = `${bareNode ? HOST_NODE_COMMAND : `"${hookCommand[0]}"`} "${hookCommand[1]}" ${AGENT_FLAG} ${id}`;
|
|
@@ -7949,7 +8069,7 @@ function buildRegistry(ctx) {
|
|
|
7949
8069
|
hookInstall,
|
|
7950
8070
|
skillInstall,
|
|
7951
8071
|
hookRunCommand: runCommand2,
|
|
7952
|
-
allowedWrites: [...new Set(writes.map((f2) =>
|
|
8072
|
+
allowedWrites: [...new Set(writes.map((f2) => path4.resolve(f2)))],
|
|
7953
8073
|
goldenPayload: golden(row, ctx.home)
|
|
7954
8074
|
};
|
|
7955
8075
|
if (copilotSettings) out2.copilotSettings = copilotSettings;
|
|
@@ -7962,15 +8082,15 @@ function buildRegistry(ctx) {
|
|
|
7962
8082
|
});
|
|
7963
8083
|
}
|
|
7964
8084
|
function assertWritable(row, file) {
|
|
7965
|
-
const abs =
|
|
7966
|
-
if (INSTRUCTION_FILES.includes(
|
|
8085
|
+
const abs = path4.resolve(file);
|
|
8086
|
+
if (INSTRUCTION_FILES.includes(path4.basename(abs)) || !row.allowedWrites.includes(abs)) {
|
|
7967
8087
|
throw new Error(`setup: write to ${abs} is not allowed for ${row.id}`);
|
|
7968
8088
|
}
|
|
7969
8089
|
}
|
|
7970
8090
|
|
|
7971
8091
|
// src/setup/gemini-gate.ts
|
|
7972
|
-
import { existsSync as
|
|
7973
|
-
import
|
|
8092
|
+
import { existsSync as existsSync10, readFileSync as readFileSync6 } from "node:fs";
|
|
8093
|
+
import path5 from "node:path";
|
|
7974
8094
|
var GEMINI_DIR = ".gemini";
|
|
7975
8095
|
var SETTINGS_FILE2 = "settings.json";
|
|
7976
8096
|
var SYSTEM_PATH_ENV = "GEMINI_CLI_SYSTEM_SETTINGS_PATH";
|
|
@@ -7982,16 +8102,16 @@ function systemSettingsPath(env) {
|
|
|
7982
8102
|
if (process.platform === "win32") return "C:\\ProgramData\\gemini-cli\\settings.json";
|
|
7983
8103
|
return "/etc/gemini-cli/settings.json";
|
|
7984
8104
|
}
|
|
7985
|
-
function
|
|
7986
|
-
if (!
|
|
8105
|
+
function load2(file) {
|
|
8106
|
+
if (!existsSync10(file)) return void 0;
|
|
7987
8107
|
try {
|
|
7988
|
-
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(
|
|
8108
|
+
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync6(file, "utf8")), "jsonc") };
|
|
7989
8109
|
} catch {
|
|
7990
8110
|
return void 0;
|
|
7991
8111
|
}
|
|
7992
8112
|
}
|
|
7993
8113
|
function sources(env, home, cwd) {
|
|
7994
|
-
return [
|
|
8114
|
+
return [path5.join(home, GEMINI_DIR, SETTINGS_FILE2), path5.join(cwd, GEMINI_DIR, SETTINGS_FILE2), systemSettingsPath(env)].map(load2).filter((s) => s !== void 0);
|
|
7995
8115
|
}
|
|
7996
8116
|
function ownHookEntry(entry2) {
|
|
7997
8117
|
return typeof entry2 === "string" && entry2.includes(HOOK_BUNDLE) && entry2.includes(`${AGENT_FLAG} ${OWN_AGENT}`);
|
|
@@ -8017,8 +8137,8 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
8017
8137
|
}
|
|
8018
8138
|
|
|
8019
8139
|
// src/setup/zcode-gate.ts
|
|
8020
|
-
import { existsSync as
|
|
8021
|
-
import
|
|
8140
|
+
import { existsSync as existsSync11, readFileSync as readFileSync7 } from "node:fs";
|
|
8141
|
+
import path6 from "node:path";
|
|
8022
8142
|
var OWN_AGENT2 = "zcode";
|
|
8023
8143
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
8024
8144
|
var HOOK_TYPES = ["process", "command"];
|
|
@@ -8108,11 +8228,11 @@ function zcodeSchemaBad(doc) {
|
|
|
8108
8228
|
);
|
|
8109
8229
|
}
|
|
8110
8230
|
function zcodeConfigGate(home) {
|
|
8111
|
-
const file =
|
|
8112
|
-
if (!
|
|
8231
|
+
const file = path6.join(home, ".zcode", "cli", "config.json");
|
|
8232
|
+
if (!existsSync11(file)) return void 0;
|
|
8113
8233
|
let doc;
|
|
8114
8234
|
try {
|
|
8115
|
-
doc = parseHostConfig(OWN_AGENT2, file, hostText(
|
|
8235
|
+
doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync7(file, "utf8")), "json");
|
|
8116
8236
|
} catch {
|
|
8117
8237
|
return void 0;
|
|
8118
8238
|
}
|
|
@@ -8121,106 +8241,6 @@ function zcodeConfigGate(home) {
|
|
|
8121
8241
|
return `${file}: ${bad.key} ${bad.why}, so zcode drops the whole config.json and runs no context-mode hook; fix or remove that key`;
|
|
8122
8242
|
}
|
|
8123
8243
|
|
|
8124
|
-
// src/setup/pi-gate.ts
|
|
8125
|
-
import { existsSync as existsSync11, readFileSync as readFileSync7, realpathSync as realpathSync4 } from "node:fs";
|
|
8126
|
-
import path6 from "node:path";
|
|
8127
|
-
var OWN_FILE = "pi/index.js";
|
|
8128
|
-
var EXTENSIONS_KEY = "extensions";
|
|
8129
|
-
var PROJECT_DIR = ".pi";
|
|
8130
|
-
var TRUST_FILE = "trust.json";
|
|
8131
|
-
var ALWAYS = "always";
|
|
8132
|
-
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
8133
|
-
function load2(file) {
|
|
8134
|
-
if (!existsSync11(file)) return void 0;
|
|
8135
|
-
try {
|
|
8136
|
-
return { file, doc: parseHostConfig("pi", file, hostText(readFileSync7(file, "utf8")), "json") };
|
|
8137
|
-
} catch {
|
|
8138
|
-
return void 0;
|
|
8139
|
-
}
|
|
8140
|
-
}
|
|
8141
|
-
var real = (p3) => {
|
|
8142
|
-
try {
|
|
8143
|
-
return realpathSync4(p3);
|
|
8144
|
-
} catch {
|
|
8145
|
-
return path6.resolve(p3);
|
|
8146
|
-
}
|
|
8147
|
-
};
|
|
8148
|
-
function sourceName(source) {
|
|
8149
|
-
let s = source;
|
|
8150
|
-
for (const p3 of SOURCE_PREFIXES) if (s.startsWith(p3)) s = s.slice(p3.length);
|
|
8151
|
-
const last2 = s.split("/").pop() ?? "";
|
|
8152
|
-
const at = last2.indexOf("@", 1);
|
|
8153
|
-
const name = at > 0 ? last2.slice(0, at) : last2;
|
|
8154
|
-
return name.endsWith(".git") ? name.slice(0, -4) : name;
|
|
8155
|
-
}
|
|
8156
|
-
function isOwn(source, pkgDir) {
|
|
8157
|
-
if (typeof source !== "string") return false;
|
|
8158
|
-
return real(source) === real(pkgDir) || sourceName(source) === SERVER_KEY;
|
|
8159
|
-
}
|
|
8160
|
-
function ownEntries(src, pkgDir) {
|
|
8161
|
-
const list2 = hostConfigValueAt(src.doc, [PI_PACKAGES_KEY]);
|
|
8162
|
-
if (!Array.isArray(list2)) return [];
|
|
8163
|
-
const out2 = [];
|
|
8164
|
-
for (const e of list2) {
|
|
8165
|
-
const obj = typeof e === "object" && e !== null && !Array.isArray(e) ? e : void 0;
|
|
8166
|
-
if (!isOwn(obj ? obj[PI_PACKAGE_SOURCE_KEY] : e, pkgDir)) continue;
|
|
8167
|
-
const ext = obj?.[EXTENSIONS_KEY];
|
|
8168
|
-
out2.push({ source: src, patterns: Array.isArray(ext) ? ext.filter((x2) => typeof x2 === "string") : void 0 });
|
|
8169
|
-
}
|
|
8170
|
-
return out2;
|
|
8171
|
-
}
|
|
8172
|
-
function matchesAny(patterns, pkgDir) {
|
|
8173
|
-
const abs = path6.join(pkgDir, OWN_FILE).split(path6.sep).join("/");
|
|
8174
|
-
return patterns.some((p3) => {
|
|
8175
|
-
const g2 = p3.startsWith("./") ? p3.slice(2) : p3;
|
|
8176
|
-
return [OWN_FILE, path6.posix.basename(OWN_FILE), abs].some((c3) => path6.posix.matchesGlob(c3, g2));
|
|
8177
|
-
});
|
|
8178
|
-
}
|
|
8179
|
-
var exactAny = (patterns, pkgDir) => {
|
|
8180
|
-
const abs = path6.join(pkgDir, OWN_FILE).split(path6.sep).join("/");
|
|
8181
|
-
return patterns.some((p3) => {
|
|
8182
|
-
const g2 = p3.startsWith("./") ? p3.slice(2) : p3;
|
|
8183
|
-
return g2 === OWN_FILE || g2 === abs;
|
|
8184
|
-
});
|
|
8185
|
-
};
|
|
8186
|
-
function loads(patterns, pkgDir) {
|
|
8187
|
-
if (patterns.length === 0) return false;
|
|
8188
|
-
const by = (c3) => patterns.filter((p3) => p3.startsWith(c3)).map((p3) => p3.slice(1));
|
|
8189
|
-
const includes = patterns.filter((p3) => !"+-!".includes(p3[0] ?? ""));
|
|
8190
|
-
let on = includes.length === 0 || matchesAny(includes, pkgDir);
|
|
8191
|
-
if (matchesAny(by("!"), pkgDir)) on = false;
|
|
8192
|
-
if (exactAny(by("+"), pkgDir)) on = true;
|
|
8193
|
-
if (exactAny(by("-"), pkgDir)) on = false;
|
|
8194
|
-
return on;
|
|
8195
|
-
}
|
|
8196
|
-
function projectTrusted(agentDir, userDoc, cwd) {
|
|
8197
|
-
const trust = load2(path6.join(agentDir, TRUST_FILE));
|
|
8198
|
-
const entries = /* @__PURE__ */ new Map();
|
|
8199
|
-
if (trust && typeof trust.doc === "object" && trust.doc !== null) for (const [k, v] of Object.entries(trust.doc)) entries.set(real(k), v);
|
|
8200
|
-
let dir = real(cwd);
|
|
8201
|
-
for (; ; ) {
|
|
8202
|
-
const v = entries.get(dir);
|
|
8203
|
-
if (v === true || v === false) return v;
|
|
8204
|
-
const up = path6.dirname(dir);
|
|
8205
|
-
if (up === dir) break;
|
|
8206
|
-
dir = up;
|
|
8207
|
-
}
|
|
8208
|
-
return hostConfigValueAt(userDoc, ["defaultProjectTrust"]) === ALWAYS;
|
|
8209
|
-
}
|
|
8210
|
-
function piSettingsGate(env, home, pkgDir, cwd) {
|
|
8211
|
-
const agentDir = piAgentDirOf(env, home);
|
|
8212
|
-
const user = load2(path6.join(agentDir, SETTINGS_FILE));
|
|
8213
|
-
const project = load2(path6.join(cwd, PROJECT_DIR, SETTINGS_FILE));
|
|
8214
|
-
const projectOwn = project && projectTrusted(agentDir, user?.doc, cwd) ? ownEntries(project, pkgDir) : [];
|
|
8215
|
-
const effective = projectOwn.length ? projectOwn : user ? ownEntries(user, pkgDir) : [];
|
|
8216
|
-
for (const e of effective) {
|
|
8217
|
-
if (e.patterns !== void 0 && !loads(e.patterns, pkgDir)) {
|
|
8218
|
-
return `${e.source.file}: the packages[] entry for context-mode has extensions ${JSON.stringify(e.patterns)}, which leaves out ${OWN_FILE}, so pi loads no hook; remove the "extensions" filter from that entry`;
|
|
8219
|
-
}
|
|
8220
|
-
}
|
|
8221
|
-
return void 0;
|
|
8222
|
-
}
|
|
8223
|
-
|
|
8224
8244
|
// src/setup/vscode-gate.ts
|
|
8225
8245
|
import { existsSync as existsSync12, readFileSync as readFileSync8 } from "node:fs";
|
|
8226
8246
|
import path7 from "node:path";
|
package/copilot/plugin.json
CHANGED
package/gemini-extension.json
CHANGED