context-mode 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +6 -2
- package/.claude-plugin/plugin.json +5 -2
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +73 -73
- package/SHA256SUMS +18 -21
- package/cli.mjs +190 -145
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +86 -83
- package/opencode/plugin.js +336 -221
- package/package.json +1 -2
- package/pi/index.js +390 -273
- package/qwen-extension.json +1 -1
- package/run.mjs +34 -7
- package/search.mjs +34 -7
- package/server.mjs +366 -255
- package/skills/ctx-doctor/SKILL.md +1 -1
- package/skills/ctx-stats/SKILL.md +1 -1
- package/skills/ctx-upgrade/SKILL.md +1 -1
- package/claude-code/skills/ctx-doctor/SKILL.md +0 -6
- package/claude-code/skills/ctx-stats/SKILL.md +0 -6
- package/claude-code/skills/ctx-upgrade/SKILL.md +0 -6
package/cli.mjs
CHANGED
|
@@ -434,6 +434,10 @@ var V1_CACHE_HEAL_NAME = "context-mode-cache-heal";
|
|
|
434
434
|
var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
|
|
435
435
|
var V1_STATUSLINE_COMMAND = "context-mode statusline";
|
|
436
436
|
var V1_PI_PACKAGE = "npm:context-mode";
|
|
437
|
+
var PI_NPM_DIR = "npm";
|
|
438
|
+
var PI_NODE_MODULES_DIR = "node_modules";
|
|
439
|
+
var PI_PACKAGE_JSON_FILE = "package.json";
|
|
440
|
+
var PI_CURRENT_MAJOR = 2;
|
|
437
441
|
var V1_OPENCODE_PLUGIN_SPEC = "context-mode";
|
|
438
442
|
var V1_TMP_PREFIX = "context-mode-";
|
|
439
443
|
var V1_TOML_SECTION_ROOT = "mcp_servers";
|
|
@@ -645,7 +649,7 @@ function outputOf(resp) {
|
|
|
645
649
|
function textSlot(r2) {
|
|
646
650
|
const file = r2.file;
|
|
647
651
|
if (r2.type === "text" && typeof file === "object" && file !== null && typeof file.content === "string") {
|
|
648
|
-
return { text: file.content, put: (o2, output) => ({ ...o2, file:
|
|
652
|
+
return { text: file.content, put: (o2, output) => ({ ...o2, file: readFile(o2.file, output) }) };
|
|
649
653
|
}
|
|
650
654
|
if (isGrepContent(r2)) return { text: r2.content, put: (o2, output) => ({ ...o2, content: output }) };
|
|
651
655
|
if (Array.isArray(r2.filenames) && r2.filenames.every((f2) => typeof f2 === "string")) {
|
|
@@ -654,13 +658,35 @@ function textSlot(r2) {
|
|
|
654
658
|
if (typeof r2.result === "string") return { text: r2.result, put: (o2, output) => ({ ...o2, result: output }) };
|
|
655
659
|
return null;
|
|
656
660
|
}
|
|
661
|
+
function readFile(file, output) {
|
|
662
|
+
const start = typeof file.startLine === "number" ? file.startLine : 1;
|
|
663
|
+
const lines = String(file.content).split("\n");
|
|
664
|
+
const read = typeof file.numLines === "number" ? file.numLines : lines.length;
|
|
665
|
+
const out2 = output.split("\n");
|
|
666
|
+
const run = firstRun(lines, out2);
|
|
667
|
+
if (run === null) return { ...file, content: output, startLine: start + read, numLines: out2.length };
|
|
668
|
+
const kept = out2.slice(0, run.length);
|
|
669
|
+
if (run.length < out2.length) kept.push(out2[out2.length - 1]);
|
|
670
|
+
return { ...file, content: kept.join("\n"), startLine: start + run.at, numLines: kept.length };
|
|
671
|
+
}
|
|
672
|
+
function firstRun(lines, out2) {
|
|
673
|
+
let best = null;
|
|
674
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
675
|
+
if (lines[i2] !== out2[0]) continue;
|
|
676
|
+
let n3 = 1;
|
|
677
|
+
while (n3 < out2.length && i2 + n3 < lines.length && lines[i2 + n3] === out2[n3]) n3++;
|
|
678
|
+
if (best === null || n3 > best.length) best = { at: i2, length: n3 };
|
|
679
|
+
if (n3 === out2.length) break;
|
|
680
|
+
}
|
|
681
|
+
return best;
|
|
682
|
+
}
|
|
657
683
|
function isShellShape(resp) {
|
|
658
684
|
const r2 = resp;
|
|
659
685
|
return typeof r2.stdout === "string" || typeof r2.stderr === "string";
|
|
660
686
|
}
|
|
661
687
|
function isGrepContent(resp) {
|
|
662
688
|
const r2 = resp;
|
|
663
|
-
return r2.mode === "content" && typeof r2.content === "string";
|
|
689
|
+
return (r2.mode === "content" || r2.mode === "count") && typeof r2.content === "string";
|
|
664
690
|
}
|
|
665
691
|
function blocksOf(resp) {
|
|
666
692
|
const parts = [];
|
|
@@ -676,6 +702,7 @@ function readResult(resp) {
|
|
|
676
702
|
const text2 = outputOf(resp);
|
|
677
703
|
const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
|
|
678
704
|
const info = { isError, bytes: Buffer.byteLength(text2), text: text2 };
|
|
705
|
+
if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && isShellShape(resp)) info.shape = resp;
|
|
679
706
|
if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && !isShellShape(resp)) {
|
|
680
707
|
if (textSlot(resp) !== null) info.shape = resp;
|
|
681
708
|
else info.keep = true;
|
|
@@ -715,8 +742,11 @@ function decodeClaudeShape(raw, agent, ownPrefix, sources2) {
|
|
|
715
742
|
return ev;
|
|
716
743
|
}
|
|
717
744
|
function replaceShape(ev, output) {
|
|
718
|
-
if (ev.tool?.canonicalName === "Bash") return { stdout: output, stderr: "", interrupted: false };
|
|
719
745
|
const shape = ev.result?.shape;
|
|
746
|
+
if (ev.tool?.canonicalName === "Bash") {
|
|
747
|
+
const { persistedOutputPath: _p, persistedOutputSize: _s, ...host } = shape ?? {};
|
|
748
|
+
return { interrupted: false, ...host, stdout: output, stderr: "" };
|
|
749
|
+
}
|
|
720
750
|
const slot = shape === void 0 ? null : textSlot(shape);
|
|
721
751
|
if (shape !== void 0 && slot !== null) return slot.put(shape, output);
|
|
722
752
|
if (ev.result?.blocks === true) return [{ type: "text", text: output }];
|
|
@@ -1211,7 +1241,7 @@ var PI_EVENTS = {
|
|
|
1211
1241
|
tool_call: { event: "PreToolUse" },
|
|
1212
1242
|
tool_result: { event: "PostToolUse" }
|
|
1213
1243
|
};
|
|
1214
|
-
var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read" };
|
|
1244
|
+
var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
|
|
1215
1245
|
function record(v) {
|
|
1216
1246
|
return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
|
|
1217
1247
|
}
|
|
@@ -1336,8 +1366,8 @@ var ADAPTERS = Object.freeze([
|
|
|
1336
1366
|
hookTimeoutMs: HOOK_TIMEOUT_MS,
|
|
1337
1367
|
denyChannel: "deny-reason",
|
|
1338
1368
|
hookChannel: { kind: "package", path: "hooks/claude-code.json" },
|
|
1339
|
-
skillChannel: { kind: "package", path: "
|
|
1340
|
-
// ADR-0020, D-
|
|
1369
|
+
skillChannel: { kind: "package", path: "skills" },
|
|
1370
|
+
// ADR-0020, D-R33-CC-SKILLS-1: Claude Code always loads <plugin>/skills, shared with gemini and qwen
|
|
1341
1371
|
decode,
|
|
1342
1372
|
encode
|
|
1343
1373
|
},
|
|
@@ -1481,8 +1511,9 @@ var ADAPTERS = Object.freeze([
|
|
|
1481
1511
|
installMode: "in-process",
|
|
1482
1512
|
projectSource: "pi:ctx.cwd",
|
|
1483
1513
|
toolNamePrefix: TOOL_NAME_PREFIX9,
|
|
1484
|
-
nativeTools: { shell: ["bash"], read: ["read"] },
|
|
1514
|
+
nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
|
|
1485
1515
|
execReadOnlyHint: false,
|
|
1516
|
+
// D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
|
|
1486
1517
|
eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
|
|
1487
1518
|
compactDelivery: "pi-flag",
|
|
1488
1519
|
compactSummary: "none",
|
|
@@ -4701,7 +4732,7 @@ function ownMcpFileOf(agent, file, env, home) {
|
|
|
4701
4732
|
|
|
4702
4733
|
// src/core/ops/doctor-issue.ts
|
|
4703
4734
|
import { spawnSync } from "node:child_process";
|
|
4704
|
-
import { closeSync, existsSync as
|
|
4735
|
+
import { closeSync, existsSync as existsSync9, fstatSync, mkdirSync as mkdirSync4, openSync, readFileSync as readFileSync5, readSync, realpathSync as realpathSync4, writeFileSync as writeFileSync2 } from "node:fs";
|
|
4705
4736
|
import { delimiter, join as join9 } from "node:path";
|
|
4706
4737
|
|
|
4707
4738
|
// src/core/hooks/fallback.ts
|
|
@@ -4798,7 +4829,7 @@ CREATE VIRTUAL TABLE line_units USING fts5(
|
|
|
4798
4829
|
var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
4799
4830
|
|
|
4800
4831
|
// src/core/ops/doctor-config.ts
|
|
4801
|
-
import { existsSync as
|
|
4832
|
+
import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
|
|
4802
4833
|
import { join as join8 } from "node:path";
|
|
4803
4834
|
|
|
4804
4835
|
// src/core/ops/detect-v1.ts
|
|
@@ -7523,12 +7554,17 @@ function scanKiro(agentHome, project, out2) {
|
|
|
7523
7554
|
}
|
|
7524
7555
|
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7525
7556
|
}
|
|
7557
|
+
function piNpmIsCurrent(piAgentDir) {
|
|
7558
|
+
const doc = readJson(join6(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
7559
|
+
const version = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
7560
|
+
return Number.parseInt(version, 10) >= PI_CURRENT_MAJOR;
|
|
7561
|
+
}
|
|
7526
7562
|
function scanPi(piAgentDir, agentHome, out2) {
|
|
7527
7563
|
const file = join6(piAgentDir, SETTINGS_FILE);
|
|
7528
7564
|
const doc = readJson(file);
|
|
7529
7565
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
|
|
7530
7566
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
7531
|
-
if (spec === V1_PI_PACKAGE) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
|
|
7567
|
+
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
|
|
7532
7568
|
});
|
|
7533
7569
|
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7534
7570
|
}
|
|
@@ -7626,6 +7662,106 @@ import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as
|
|
|
7626
7662
|
import { dirname as dirname5, isAbsolute, join as join7, sep } from "node:path";
|
|
7627
7663
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
7628
7664
|
|
|
7665
|
+
// src/setup/pi-gate.ts
|
|
7666
|
+
import { existsSync as existsSync7, readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
|
|
7667
|
+
import path3 from "node:path";
|
|
7668
|
+
var OWN_FILE = "pi/index.js";
|
|
7669
|
+
var EXTENSIONS_KEY = "extensions";
|
|
7670
|
+
var PROJECT_DIR = ".pi";
|
|
7671
|
+
var TRUST_FILE = "trust.json";
|
|
7672
|
+
var ALWAYS = "always";
|
|
7673
|
+
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
7674
|
+
function load(file) {
|
|
7675
|
+
if (!existsSync7(file)) return void 0;
|
|
7676
|
+
try {
|
|
7677
|
+
return { file, doc: parseHostConfig("pi", file, hostText(readFileSync4(file, "utf8")), "json") };
|
|
7678
|
+
} catch {
|
|
7679
|
+
return void 0;
|
|
7680
|
+
}
|
|
7681
|
+
}
|
|
7682
|
+
var real = (p3) => {
|
|
7683
|
+
try {
|
|
7684
|
+
return realpathSync3(p3);
|
|
7685
|
+
} catch {
|
|
7686
|
+
return path3.resolve(p3);
|
|
7687
|
+
}
|
|
7688
|
+
};
|
|
7689
|
+
function sourceName(source) {
|
|
7690
|
+
let s = source;
|
|
7691
|
+
for (const p3 of SOURCE_PREFIXES) if (s.startsWith(p3)) s = s.slice(p3.length);
|
|
7692
|
+
const last2 = s.split("/").pop() ?? "";
|
|
7693
|
+
const at = last2.indexOf("@", 1);
|
|
7694
|
+
const name = at > 0 ? last2.slice(0, at) : last2;
|
|
7695
|
+
return name.endsWith(".git") ? name.slice(0, -4) : name;
|
|
7696
|
+
}
|
|
7697
|
+
function isOwn(source, pkgDir) {
|
|
7698
|
+
if (typeof source !== "string") return false;
|
|
7699
|
+
return real(source) === real(pkgDir) || sourceName(source) === SERVER_KEY;
|
|
7700
|
+
}
|
|
7701
|
+
function ownEntries(src, pkgDir) {
|
|
7702
|
+
const list2 = hostConfigValueAt(src.doc, [PI_PACKAGES_KEY]);
|
|
7703
|
+
if (!Array.isArray(list2)) return [];
|
|
7704
|
+
const out2 = [];
|
|
7705
|
+
for (const e of list2) {
|
|
7706
|
+
const obj = typeof e === "object" && e !== null && !Array.isArray(e) ? e : void 0;
|
|
7707
|
+
if (!isOwn(obj ? obj[PI_PACKAGE_SOURCE_KEY] : e, pkgDir)) continue;
|
|
7708
|
+
const ext = obj?.[EXTENSIONS_KEY];
|
|
7709
|
+
out2.push({ source: src, patterns: Array.isArray(ext) ? ext.filter((x2) => typeof x2 === "string") : void 0 });
|
|
7710
|
+
}
|
|
7711
|
+
return out2;
|
|
7712
|
+
}
|
|
7713
|
+
function matchesAny(patterns, pkgDir) {
|
|
7714
|
+
const abs = path3.join(pkgDir, OWN_FILE).split(path3.sep).join("/");
|
|
7715
|
+
return patterns.some((p3) => {
|
|
7716
|
+
const g2 = p3.startsWith("./") ? p3.slice(2) : p3;
|
|
7717
|
+
return [OWN_FILE, path3.posix.basename(OWN_FILE), abs].some((c3) => path3.posix.matchesGlob(c3, g2));
|
|
7718
|
+
});
|
|
7719
|
+
}
|
|
7720
|
+
var exactAny = (patterns, pkgDir) => {
|
|
7721
|
+
const abs = path3.join(pkgDir, OWN_FILE).split(path3.sep).join("/");
|
|
7722
|
+
return patterns.some((p3) => {
|
|
7723
|
+
const g2 = p3.startsWith("./") ? p3.slice(2) : p3;
|
|
7724
|
+
return g2 === OWN_FILE || g2 === abs;
|
|
7725
|
+
});
|
|
7726
|
+
};
|
|
7727
|
+
function loads(patterns, pkgDir) {
|
|
7728
|
+
if (patterns.length === 0) return false;
|
|
7729
|
+
const by = (c3) => patterns.filter((p3) => p3.startsWith(c3)).map((p3) => p3.slice(1));
|
|
7730
|
+
const includes = patterns.filter((p3) => !"+-!".includes(p3[0] ?? ""));
|
|
7731
|
+
let on = includes.length === 0 || matchesAny(includes, pkgDir);
|
|
7732
|
+
if (matchesAny(by("!"), pkgDir)) on = false;
|
|
7733
|
+
if (exactAny(by("+"), pkgDir)) on = true;
|
|
7734
|
+
if (exactAny(by("-"), pkgDir)) on = false;
|
|
7735
|
+
return on;
|
|
7736
|
+
}
|
|
7737
|
+
function projectTrusted(agentDir, userDoc, cwd) {
|
|
7738
|
+
const trust = load(path3.join(agentDir, TRUST_FILE));
|
|
7739
|
+
const entries = /* @__PURE__ */ new Map();
|
|
7740
|
+
if (trust && typeof trust.doc === "object" && trust.doc !== null) for (const [k, v] of Object.entries(trust.doc)) entries.set(real(k), v);
|
|
7741
|
+
let dir = real(cwd);
|
|
7742
|
+
for (; ; ) {
|
|
7743
|
+
const v = entries.get(dir);
|
|
7744
|
+
if (v === true || v === false) return v;
|
|
7745
|
+
const up = path3.dirname(dir);
|
|
7746
|
+
if (up === dir) break;
|
|
7747
|
+
dir = up;
|
|
7748
|
+
}
|
|
7749
|
+
return hostConfigValueAt(userDoc, ["defaultProjectTrust"]) === ALWAYS;
|
|
7750
|
+
}
|
|
7751
|
+
function piSettingsGate(env, home, pkgDir, cwd) {
|
|
7752
|
+
const agentDir = piAgentDirOf(env, home);
|
|
7753
|
+
const user = load(path3.join(agentDir, SETTINGS_FILE));
|
|
7754
|
+
const project = load(path3.join(cwd, PROJECT_DIR, SETTINGS_FILE));
|
|
7755
|
+
const projectOwn = project && projectTrusted(agentDir, user?.doc, cwd) ? ownEntries(project, pkgDir) : [];
|
|
7756
|
+
const effective = projectOwn.length ? projectOwn : user ? ownEntries(user, pkgDir) : [];
|
|
7757
|
+
for (const e of effective) {
|
|
7758
|
+
if (e.patterns !== void 0 && !loads(e.patterns, pkgDir)) {
|
|
7759
|
+
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`;
|
|
7760
|
+
}
|
|
7761
|
+
}
|
|
7762
|
+
return void 0;
|
|
7763
|
+
}
|
|
7764
|
+
|
|
7629
7765
|
// src/core/ops/doctor-config.ts
|
|
7630
7766
|
var [PART_MCP, PART_HOOKS, PART_TIMEOUT] = D3_PARTS;
|
|
7631
7767
|
function composeMatcher(row, event) {
|
|
@@ -7646,7 +7782,7 @@ function formUrl(title, summary) {
|
|
|
7646
7782
|
}
|
|
7647
7783
|
|
|
7648
7784
|
// src/setup/registry.ts
|
|
7649
|
-
import
|
|
7785
|
+
import path4 from "node:path";
|
|
7650
7786
|
|
|
7651
7787
|
// src/setup/hook-shapes.ts
|
|
7652
7788
|
var MS_PER_SECOND = 1e3;
|
|
@@ -7732,11 +7868,11 @@ var OPENCODE_HOME_SEGS = AGENT_HOME_DIR.opencode;
|
|
|
7732
7868
|
function agentPath(ctx, id, rel) {
|
|
7733
7869
|
const segs = typeof rel === "string" ? rel.split("/") : [...rel];
|
|
7734
7870
|
const codexHome = ctx.env[CODEX_HOME_ENV2];
|
|
7735
|
-
if (id === "codex" && segs[0] === CODEX_DIR && codexHome !== void 0 && codexHome !== "") return
|
|
7736
|
-
if (id === "copilot-cli" && segs[0] === COPILOT_DIR) return
|
|
7737
|
-
if (id === "kiro" && segs[0] === KIRO_DIR) return
|
|
7738
|
-
if (id === "opencode" && segs[0] === OPENCODE_HOME_SEGS[0] && segs[1] === OPENCODE_HOME_SEGS[1]) return
|
|
7739
|
-
return
|
|
7871
|
+
if (id === "codex" && segs[0] === CODEX_DIR && codexHome !== void 0 && codexHome !== "") return path4.join(codexHome, ...segs.slice(1));
|
|
7872
|
+
if (id === "copilot-cli" && segs[0] === COPILOT_DIR) return path4.join(copilotDirOf(ctx.env, ctx.home), ...segs.slice(1));
|
|
7873
|
+
if (id === "kiro" && segs[0] === KIRO_DIR) return path4.join(kiroDirOf(ctx.env, ctx.home), ...segs.slice(1));
|
|
7874
|
+
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));
|
|
7875
|
+
return path4.join(ctx.home, ...segs);
|
|
7740
7876
|
}
|
|
7741
7877
|
function renderSkill(text2, prefix) {
|
|
7742
7878
|
const prefixes = typeof prefix === "string" ? [prefix] : prefix;
|
|
@@ -7766,12 +7902,12 @@ function extensionPlugin(bin, id) {
|
|
|
7766
7902
|
};
|
|
7767
7903
|
}
|
|
7768
7904
|
var NATIVE_PLUGIN = {
|
|
7769
|
-
codex: { bin: "codex", args: ["plugin", "list"], plugin: PLUGIN_ID, hooksVia: ".codex-plugin", skillsVia:
|
|
7905
|
+
codex: { bin: "codex", args: ["plugin", "list"], plugin: PLUGIN_ID, hooksVia: ".codex-plugin", skillsVia: path4.join("codex", SKILLS_DIR_NAME), format: "table", hookTrust: true },
|
|
7770
7906
|
qwen: extensionPlugin("qwen", "qwen"),
|
|
7771
7907
|
gemini: extensionPlugin("gemini", "gemini")
|
|
7772
7908
|
};
|
|
7773
7909
|
function serverCmd(ctx, id) {
|
|
7774
|
-
return [process.execPath,
|
|
7910
|
+
return [process.execPath, path4.join(ctx.pkgDir, SERVER_BUNDLE), AGENT_FLAG, id];
|
|
7775
7911
|
}
|
|
7776
7912
|
function hookCommandString(row) {
|
|
7777
7913
|
const [node, file, flag, id] = row.hookCommand ?? [];
|
|
@@ -7798,7 +7934,7 @@ function configFor(ctx, id) {
|
|
|
7798
7934
|
}
|
|
7799
7935
|
if (id === "opencode") {
|
|
7800
7936
|
return {
|
|
7801
|
-
file:
|
|
7937
|
+
file: path4.join(opencodeDirOf(ctx.env, ctx.home), OPENCODE_BASE_CONFIG_FILE),
|
|
7802
7938
|
format: "jsonc",
|
|
7803
7939
|
key: ["mcp", SERVER_KEY],
|
|
7804
7940
|
value: { type: "local", command: [node, server, flag, agent], enabled: true }
|
|
@@ -7827,7 +7963,7 @@ function cliFor(ctx, id) {
|
|
|
7827
7963
|
}
|
|
7828
7964
|
function copyFor(ctx, id) {
|
|
7829
7965
|
if (id !== "claude-code") return void 0;
|
|
7830
|
-
const file =
|
|
7966
|
+
const file = path4.join(claudeDirOf(ctx.env, ctx.home), HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE);
|
|
7831
7967
|
return { host: "Claude Code", bin: "claude", plugin: PLUGIN_ID, file, refresh: ["plugin", "update", PLUGIN_ID], enable: ["plugin", "enable", PLUGIN_ID] };
|
|
7832
7968
|
}
|
|
7833
7969
|
var LIST = {
|
|
@@ -7848,11 +7984,11 @@ function hookFilesFor(ctx, id) {
|
|
|
7848
7984
|
case "copilot-cli":
|
|
7849
7985
|
return [{ file: agentPath(ctx, id, [COPILOT_DIR, "hooks", "context-mode.json"]), mode: "rewrite" }];
|
|
7850
7986
|
case "claude-code":
|
|
7851
|
-
return [{ file:
|
|
7987
|
+
return [{ file: path4.join(claudeDirOf(ctx.env, home), "settings.json"), mode: "drop" }];
|
|
7852
7988
|
case "gemini":
|
|
7853
|
-
return [{ file:
|
|
7989
|
+
return [{ file: path4.join(home, ".gemini", "settings.json"), mode: "drop" }];
|
|
7854
7990
|
case "qwen":
|
|
7855
|
-
return [{ file:
|
|
7991
|
+
return [{ file: path4.join(home, ".qwen", "settings.json"), mode: "drop" }];
|
|
7856
7992
|
default:
|
|
7857
7993
|
return [];
|
|
7858
7994
|
}
|
|
@@ -7863,13 +7999,13 @@ function hookInstallFor(ctx, row, command) {
|
|
|
7863
7999
|
const shape = HOOK_SHAPES[row.id];
|
|
7864
8000
|
if (!shape) throw new Error(`setup: ${row.id} has a home-file hook channel and no hook shape`);
|
|
7865
8001
|
const file = agentPath(ctx, row.id, ch.path);
|
|
7866
|
-
if (row.id === "codex") return { kind: "file", file, shape: shape(row, command), command, trust:
|
|
8002
|
+
if (row.id === "codex") return { kind: "file", file, shape: shape(row, command), command, trust: path4.join(path4.dirname(file), CODEX_CONFIG_FILE) };
|
|
7867
8003
|
return { kind: "file", file, shape: shape(row, command), command };
|
|
7868
8004
|
}
|
|
7869
8005
|
if (row.id === "opencode") {
|
|
7870
8006
|
return {
|
|
7871
8007
|
kind: "plugin-list",
|
|
7872
|
-
file:
|
|
8008
|
+
file: path4.join(opencodeDirOf(ctx.env, ctx.home), OPENCODE_BASE_CONFIG_FILE),
|
|
7873
8009
|
key: ["plugin"],
|
|
7874
8010
|
entry: ctx.pkgDir
|
|
7875
8011
|
};
|
|
@@ -7885,11 +8021,11 @@ function skillInstallFor(ctx, row) {
|
|
|
7885
8021
|
const ch = row.skillChannel;
|
|
7886
8022
|
if (ch.kind === "package") return { kind: "package", via: ch.path };
|
|
7887
8023
|
const dir = agentPath(ctx, row.id, ch.path);
|
|
7888
|
-
const src =
|
|
8024
|
+
const src = path4.join(ctx.pkgDir, bareSkillDir());
|
|
7889
8025
|
return { kind: "dir", dir, prefixes: skillDirPrefixes(ch.path), files: COMMAND_SKILLS.map((name) => ({
|
|
7890
8026
|
name,
|
|
7891
|
-
src:
|
|
7892
|
-
file:
|
|
8027
|
+
src: path4.join(src, name, SKILL_FILE),
|
|
8028
|
+
file: path4.join(dir, name, SKILL_FILE)
|
|
7893
8029
|
})) };
|
|
7894
8030
|
}
|
|
7895
8031
|
function buildRegistry(ctx) {
|
|
@@ -7897,7 +8033,7 @@ function buildRegistry(ctx) {
|
|
|
7897
8033
|
const id = row.id;
|
|
7898
8034
|
const config = configFor(ctx, id);
|
|
7899
8035
|
const hookFiles = hookFilesFor(ctx, id);
|
|
7900
|
-
const runCommand2 = [process.execPath,
|
|
8036
|
+
const runCommand2 = [process.execPath, path4.join(ctx.pkgDir, HOOK_BUNDLE), AGENT_FLAG, id];
|
|
7901
8037
|
const bareNode = id === "codex" && (ctx.platform ?? process.platform) === "win32";
|
|
7902
8038
|
const hookCommand = bareNode ? [HOST_NODE_COMMAND, ...runCommand2.slice(1)] : runCommand2;
|
|
7903
8039
|
const command = `${bareNode ? HOST_NODE_COMMAND : `"${hookCommand[0]}"`} "${hookCommand[1]}" ${AGENT_FLAG} ${id}`;
|
|
@@ -7923,7 +8059,7 @@ function buildRegistry(ctx) {
|
|
|
7923
8059
|
hookInstall,
|
|
7924
8060
|
skillInstall,
|
|
7925
8061
|
hookRunCommand: runCommand2,
|
|
7926
|
-
allowedWrites: [...new Set(writes.map((f2) =>
|
|
8062
|
+
allowedWrites: [...new Set(writes.map((f2) => path4.resolve(f2)))],
|
|
7927
8063
|
goldenPayload: golden(row, ctx.home)
|
|
7928
8064
|
};
|
|
7929
8065
|
if (copilotSettings) out2.copilotSettings = copilotSettings;
|
|
@@ -7936,15 +8072,15 @@ function buildRegistry(ctx) {
|
|
|
7936
8072
|
});
|
|
7937
8073
|
}
|
|
7938
8074
|
function assertWritable(row, file) {
|
|
7939
|
-
const abs =
|
|
7940
|
-
if (INSTRUCTION_FILES.includes(
|
|
8075
|
+
const abs = path4.resolve(file);
|
|
8076
|
+
if (INSTRUCTION_FILES.includes(path4.basename(abs)) || !row.allowedWrites.includes(abs)) {
|
|
7941
8077
|
throw new Error(`setup: write to ${abs} is not allowed for ${row.id}`);
|
|
7942
8078
|
}
|
|
7943
8079
|
}
|
|
7944
8080
|
|
|
7945
8081
|
// src/setup/gemini-gate.ts
|
|
7946
|
-
import { existsSync as
|
|
7947
|
-
import
|
|
8082
|
+
import { existsSync as existsSync10, readFileSync as readFileSync6 } from "node:fs";
|
|
8083
|
+
import path5 from "node:path";
|
|
7948
8084
|
var GEMINI_DIR = ".gemini";
|
|
7949
8085
|
var SETTINGS_FILE2 = "settings.json";
|
|
7950
8086
|
var SYSTEM_PATH_ENV = "GEMINI_CLI_SYSTEM_SETTINGS_PATH";
|
|
@@ -7956,16 +8092,16 @@ function systemSettingsPath(env) {
|
|
|
7956
8092
|
if (process.platform === "win32") return "C:\\ProgramData\\gemini-cli\\settings.json";
|
|
7957
8093
|
return "/etc/gemini-cli/settings.json";
|
|
7958
8094
|
}
|
|
7959
|
-
function
|
|
7960
|
-
if (!
|
|
8095
|
+
function load2(file) {
|
|
8096
|
+
if (!existsSync10(file)) return void 0;
|
|
7961
8097
|
try {
|
|
7962
|
-
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(
|
|
8098
|
+
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync6(file, "utf8")), "jsonc") };
|
|
7963
8099
|
} catch {
|
|
7964
8100
|
return void 0;
|
|
7965
8101
|
}
|
|
7966
8102
|
}
|
|
7967
8103
|
function sources(env, home, cwd) {
|
|
7968
|
-
return [
|
|
8104
|
+
return [path5.join(home, GEMINI_DIR, SETTINGS_FILE2), path5.join(cwd, GEMINI_DIR, SETTINGS_FILE2), systemSettingsPath(env)].map(load2).filter((s) => s !== void 0);
|
|
7969
8105
|
}
|
|
7970
8106
|
function ownHookEntry(entry2) {
|
|
7971
8107
|
return typeof entry2 === "string" && entry2.includes(HOOK_BUNDLE) && entry2.includes(`${AGENT_FLAG} ${OWN_AGENT}`);
|
|
@@ -7991,8 +8127,8 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
7991
8127
|
}
|
|
7992
8128
|
|
|
7993
8129
|
// src/setup/zcode-gate.ts
|
|
7994
|
-
import { existsSync as
|
|
7995
|
-
import
|
|
8130
|
+
import { existsSync as existsSync11, readFileSync as readFileSync7 } from "node:fs";
|
|
8131
|
+
import path6 from "node:path";
|
|
7996
8132
|
var OWN_AGENT2 = "zcode";
|
|
7997
8133
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
7998
8134
|
var HOOK_TYPES = ["process", "command"];
|
|
@@ -8082,11 +8218,11 @@ function zcodeSchemaBad(doc) {
|
|
|
8082
8218
|
);
|
|
8083
8219
|
}
|
|
8084
8220
|
function zcodeConfigGate(home) {
|
|
8085
|
-
const file =
|
|
8086
|
-
if (!
|
|
8221
|
+
const file = path6.join(home, ".zcode", "cli", "config.json");
|
|
8222
|
+
if (!existsSync11(file)) return void 0;
|
|
8087
8223
|
let doc;
|
|
8088
8224
|
try {
|
|
8089
|
-
doc = parseHostConfig(OWN_AGENT2, file, hostText(
|
|
8225
|
+
doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync7(file, "utf8")), "json");
|
|
8090
8226
|
} catch {
|
|
8091
8227
|
return void 0;
|
|
8092
8228
|
}
|
|
@@ -8095,106 +8231,6 @@ function zcodeConfigGate(home) {
|
|
|
8095
8231
|
return `${file}: ${bad.key} ${bad.why}, so zcode drops the whole config.json and runs no context-mode hook; fix or remove that key`;
|
|
8096
8232
|
}
|
|
8097
8233
|
|
|
8098
|
-
// src/setup/pi-gate.ts
|
|
8099
|
-
import { existsSync as existsSync11, readFileSync as readFileSync7, realpathSync as realpathSync4 } from "node:fs";
|
|
8100
|
-
import path6 from "node:path";
|
|
8101
|
-
var OWN_FILE = "pi/index.js";
|
|
8102
|
-
var EXTENSIONS_KEY = "extensions";
|
|
8103
|
-
var PROJECT_DIR = ".pi";
|
|
8104
|
-
var TRUST_FILE = "trust.json";
|
|
8105
|
-
var ALWAYS = "always";
|
|
8106
|
-
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
8107
|
-
function load2(file) {
|
|
8108
|
-
if (!existsSync11(file)) return void 0;
|
|
8109
|
-
try {
|
|
8110
|
-
return { file, doc: parseHostConfig("pi", file, hostText(readFileSync7(file, "utf8")), "json") };
|
|
8111
|
-
} catch {
|
|
8112
|
-
return void 0;
|
|
8113
|
-
}
|
|
8114
|
-
}
|
|
8115
|
-
var real = (p3) => {
|
|
8116
|
-
try {
|
|
8117
|
-
return realpathSync4(p3);
|
|
8118
|
-
} catch {
|
|
8119
|
-
return path6.resolve(p3);
|
|
8120
|
-
}
|
|
8121
|
-
};
|
|
8122
|
-
function sourceName(source) {
|
|
8123
|
-
let s = source;
|
|
8124
|
-
for (const p3 of SOURCE_PREFIXES) if (s.startsWith(p3)) s = s.slice(p3.length);
|
|
8125
|
-
const last2 = s.split("/").pop() ?? "";
|
|
8126
|
-
const at = last2.indexOf("@", 1);
|
|
8127
|
-
const name = at > 0 ? last2.slice(0, at) : last2;
|
|
8128
|
-
return name.endsWith(".git") ? name.slice(0, -4) : name;
|
|
8129
|
-
}
|
|
8130
|
-
function isOwn(source, pkgDir) {
|
|
8131
|
-
if (typeof source !== "string") return false;
|
|
8132
|
-
return real(source) === real(pkgDir) || sourceName(source) === SERVER_KEY;
|
|
8133
|
-
}
|
|
8134
|
-
function ownEntries(src, pkgDir) {
|
|
8135
|
-
const list2 = hostConfigValueAt(src.doc, [PI_PACKAGES_KEY]);
|
|
8136
|
-
if (!Array.isArray(list2)) return [];
|
|
8137
|
-
const out2 = [];
|
|
8138
|
-
for (const e of list2) {
|
|
8139
|
-
const obj = typeof e === "object" && e !== null && !Array.isArray(e) ? e : void 0;
|
|
8140
|
-
if (!isOwn(obj ? obj[PI_PACKAGE_SOURCE_KEY] : e, pkgDir)) continue;
|
|
8141
|
-
const ext = obj?.[EXTENSIONS_KEY];
|
|
8142
|
-
out2.push({ source: src, patterns: Array.isArray(ext) ? ext.filter((x2) => typeof x2 === "string") : void 0 });
|
|
8143
|
-
}
|
|
8144
|
-
return out2;
|
|
8145
|
-
}
|
|
8146
|
-
function matchesAny(patterns, pkgDir) {
|
|
8147
|
-
const abs = path6.join(pkgDir, OWN_FILE).split(path6.sep).join("/");
|
|
8148
|
-
return patterns.some((p3) => {
|
|
8149
|
-
const g2 = p3.startsWith("./") ? p3.slice(2) : p3;
|
|
8150
|
-
return [OWN_FILE, path6.posix.basename(OWN_FILE), abs].some((c3) => path6.posix.matchesGlob(c3, g2));
|
|
8151
|
-
});
|
|
8152
|
-
}
|
|
8153
|
-
var exactAny = (patterns, pkgDir) => {
|
|
8154
|
-
const abs = path6.join(pkgDir, OWN_FILE).split(path6.sep).join("/");
|
|
8155
|
-
return patterns.some((p3) => {
|
|
8156
|
-
const g2 = p3.startsWith("./") ? p3.slice(2) : p3;
|
|
8157
|
-
return g2 === OWN_FILE || g2 === abs;
|
|
8158
|
-
});
|
|
8159
|
-
};
|
|
8160
|
-
function loads(patterns, pkgDir) {
|
|
8161
|
-
if (patterns.length === 0) return false;
|
|
8162
|
-
const by = (c3) => patterns.filter((p3) => p3.startsWith(c3)).map((p3) => p3.slice(1));
|
|
8163
|
-
const includes = patterns.filter((p3) => !"+-!".includes(p3[0] ?? ""));
|
|
8164
|
-
let on = includes.length === 0 || matchesAny(includes, pkgDir);
|
|
8165
|
-
if (matchesAny(by("!"), pkgDir)) on = false;
|
|
8166
|
-
if (exactAny(by("+"), pkgDir)) on = true;
|
|
8167
|
-
if (exactAny(by("-"), pkgDir)) on = false;
|
|
8168
|
-
return on;
|
|
8169
|
-
}
|
|
8170
|
-
function projectTrusted(agentDir, userDoc, cwd) {
|
|
8171
|
-
const trust = load2(path6.join(agentDir, TRUST_FILE));
|
|
8172
|
-
const entries = /* @__PURE__ */ new Map();
|
|
8173
|
-
if (trust && typeof trust.doc === "object" && trust.doc !== null) for (const [k, v] of Object.entries(trust.doc)) entries.set(real(k), v);
|
|
8174
|
-
let dir = real(cwd);
|
|
8175
|
-
for (; ; ) {
|
|
8176
|
-
const v = entries.get(dir);
|
|
8177
|
-
if (v === true || v === false) return v;
|
|
8178
|
-
const up = path6.dirname(dir);
|
|
8179
|
-
if (up === dir) break;
|
|
8180
|
-
dir = up;
|
|
8181
|
-
}
|
|
8182
|
-
return hostConfigValueAt(userDoc, ["defaultProjectTrust"]) === ALWAYS;
|
|
8183
|
-
}
|
|
8184
|
-
function piSettingsGate(env, home, pkgDir, cwd) {
|
|
8185
|
-
const agentDir = piAgentDirOf(env, home);
|
|
8186
|
-
const user = load2(path6.join(agentDir, SETTINGS_FILE));
|
|
8187
|
-
const project = load2(path6.join(cwd, PROJECT_DIR, SETTINGS_FILE));
|
|
8188
|
-
const projectOwn = project && projectTrusted(agentDir, user?.doc, cwd) ? ownEntries(project, pkgDir) : [];
|
|
8189
|
-
const effective = projectOwn.length ? projectOwn : user ? ownEntries(user, pkgDir) : [];
|
|
8190
|
-
for (const e of effective) {
|
|
8191
|
-
if (e.patterns !== void 0 && !loads(e.patterns, pkgDir)) {
|
|
8192
|
-
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`;
|
|
8193
|
-
}
|
|
8194
|
-
}
|
|
8195
|
-
return void 0;
|
|
8196
|
-
}
|
|
8197
|
-
|
|
8198
8234
|
// src/setup/vscode-gate.ts
|
|
8199
8235
|
import { existsSync as existsSync12, readFileSync as readFileSync8 } from "node:fs";
|
|
8200
8236
|
import path7 from "node:path";
|
|
@@ -9358,11 +9394,20 @@ function hookSeenCheck(row, home) {
|
|
|
9358
9394
|
}
|
|
9359
9395
|
return { name: "hook-seen", ok: true, warn: true, detail: NOT_SEEN_LINE };
|
|
9360
9396
|
}
|
|
9397
|
+
var SKILL_TOOL_STEM = "ctx_";
|
|
9361
9398
|
function skillsCheck(row, pkgDir) {
|
|
9362
9399
|
const s = row.skillInstall;
|
|
9363
9400
|
if (s.kind === "package") {
|
|
9364
|
-
const
|
|
9365
|
-
|
|
9401
|
+
const files = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE));
|
|
9402
|
+
const miss = files.filter((f2) => !existsSync15(f2));
|
|
9403
|
+
if (miss.length) return { name: "skills", ok: false, detail: `missing ${miss.join(", ")}` };
|
|
9404
|
+
const own2 = getAdapter(row.id).toolNamePrefix + SKILL_TOOL_STEM;
|
|
9405
|
+
const foreign = [...new Set(ADAPTERS.map((r2) => r2.toolNamePrefix + SKILL_TOOL_STEM))].filter((n3) => n3 !== SKILL_TOOL_STEM && n3 !== own2);
|
|
9406
|
+
const bad2 = files.filter((f2) => {
|
|
9407
|
+
const t2 = readFileSync10(f2, "utf8");
|
|
9408
|
+
return !t2.includes(own2) && foreign.some((n3) => t2.includes(n3));
|
|
9409
|
+
});
|
|
9410
|
+
return { name: "skills", ok: bad2.length === 0, detail: bad2.length ? `${bad2.join(", ")} without the ${own2}* tool name` : void 0 };
|
|
9366
9411
|
}
|
|
9367
9412
|
const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync15(f2.src) ? renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes) : void 0));
|
|
9368
9413
|
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 };
|
package/copilot/plugin.json
CHANGED
package/gemini-extension.json
CHANGED