context-mode 2.1.1 → 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 +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 +148 -138
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +81 -81
- package/opencode/plugin.js +305 -216
- package/package.json +1 -1
- package/pi/index.js +359 -268
- package/qwen-extension.json +1 -1
- package/run.mjs +3 -2
- package/search.mjs +3 -2
- package/server.mjs +335 -250
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";
|
|
@@ -1237,7 +1241,7 @@ var PI_EVENTS = {
|
|
|
1237
1241
|
tool_call: { event: "PreToolUse" },
|
|
1238
1242
|
tool_result: { event: "PostToolUse" }
|
|
1239
1243
|
};
|
|
1240
|
-
var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read" };
|
|
1244
|
+
var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
|
|
1241
1245
|
function record(v) {
|
|
1242
1246
|
return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
|
|
1243
1247
|
}
|
|
@@ -1507,8 +1511,9 @@ var ADAPTERS = Object.freeze([
|
|
|
1507
1511
|
installMode: "in-process",
|
|
1508
1512
|
projectSource: "pi:ctx.cwd",
|
|
1509
1513
|
toolNamePrefix: TOOL_NAME_PREFIX9,
|
|
1510
|
-
nativeTools: { shell: ["bash"], read: ["read"] },
|
|
1514
|
+
nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
|
|
1511
1515
|
execReadOnlyHint: false,
|
|
1516
|
+
// D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
|
|
1512
1517
|
eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
|
|
1513
1518
|
compactDelivery: "pi-flag",
|
|
1514
1519
|
compactSummary: "none",
|
|
@@ -4727,7 +4732,7 @@ function ownMcpFileOf(agent, file, env, home) {
|
|
|
4727
4732
|
|
|
4728
4733
|
// src/core/ops/doctor-issue.ts
|
|
4729
4734
|
import { spawnSync } from "node:child_process";
|
|
4730
|
-
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";
|
|
4731
4736
|
import { delimiter, join as join9 } from "node:path";
|
|
4732
4737
|
|
|
4733
4738
|
// src/core/hooks/fallback.ts
|
|
@@ -4824,7 +4829,7 @@ CREATE VIRTUAL TABLE line_units USING fts5(
|
|
|
4824
4829
|
var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
4825
4830
|
|
|
4826
4831
|
// src/core/ops/doctor-config.ts
|
|
4827
|
-
import { existsSync as
|
|
4832
|
+
import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
|
|
4828
4833
|
import { join as join8 } from "node:path";
|
|
4829
4834
|
|
|
4830
4835
|
// src/core/ops/detect-v1.ts
|
|
@@ -7549,12 +7554,17 @@ function scanKiro(agentHome, project, out2) {
|
|
|
7549
7554
|
}
|
|
7550
7555
|
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7551
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
|
+
}
|
|
7552
7562
|
function scanPi(piAgentDir, agentHome, out2) {
|
|
7553
7563
|
const file = join6(piAgentDir, SETTINGS_FILE);
|
|
7554
7564
|
const doc = readJson(file);
|
|
7555
7565
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
|
|
7556
7566
|
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));
|
|
7567
|
+
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
|
|
7558
7568
|
});
|
|
7559
7569
|
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7560
7570
|
}
|
|
@@ -7652,6 +7662,106 @@ import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as
|
|
|
7652
7662
|
import { dirname as dirname5, isAbsolute, join as join7, sep } from "node:path";
|
|
7653
7663
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
7654
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
|
+
|
|
7655
7765
|
// src/core/ops/doctor-config.ts
|
|
7656
7766
|
var [PART_MCP, PART_HOOKS, PART_TIMEOUT] = D3_PARTS;
|
|
7657
7767
|
function composeMatcher(row, event) {
|
|
@@ -7672,7 +7782,7 @@ function formUrl(title, summary) {
|
|
|
7672
7782
|
}
|
|
7673
7783
|
|
|
7674
7784
|
// src/setup/registry.ts
|
|
7675
|
-
import
|
|
7785
|
+
import path4 from "node:path";
|
|
7676
7786
|
|
|
7677
7787
|
// src/setup/hook-shapes.ts
|
|
7678
7788
|
var MS_PER_SECOND = 1e3;
|
|
@@ -7758,11 +7868,11 @@ var OPENCODE_HOME_SEGS = AGENT_HOME_DIR.opencode;
|
|
|
7758
7868
|
function agentPath(ctx, id, rel) {
|
|
7759
7869
|
const segs = typeof rel === "string" ? rel.split("/") : [...rel];
|
|
7760
7870
|
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
|
|
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);
|
|
7766
7876
|
}
|
|
7767
7877
|
function renderSkill(text2, prefix) {
|
|
7768
7878
|
const prefixes = typeof prefix === "string" ? [prefix] : prefix;
|
|
@@ -7792,12 +7902,12 @@ function extensionPlugin(bin, id) {
|
|
|
7792
7902
|
};
|
|
7793
7903
|
}
|
|
7794
7904
|
var NATIVE_PLUGIN = {
|
|
7795
|
-
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 },
|
|
7796
7906
|
qwen: extensionPlugin("qwen", "qwen"),
|
|
7797
7907
|
gemini: extensionPlugin("gemini", "gemini")
|
|
7798
7908
|
};
|
|
7799
7909
|
function serverCmd(ctx, id) {
|
|
7800
|
-
return [process.execPath,
|
|
7910
|
+
return [process.execPath, path4.join(ctx.pkgDir, SERVER_BUNDLE), AGENT_FLAG, id];
|
|
7801
7911
|
}
|
|
7802
7912
|
function hookCommandString(row) {
|
|
7803
7913
|
const [node, file, flag, id] = row.hookCommand ?? [];
|
|
@@ -7824,7 +7934,7 @@ function configFor(ctx, id) {
|
|
|
7824
7934
|
}
|
|
7825
7935
|
if (id === "opencode") {
|
|
7826
7936
|
return {
|
|
7827
|
-
file:
|
|
7937
|
+
file: path4.join(opencodeDirOf(ctx.env, ctx.home), OPENCODE_BASE_CONFIG_FILE),
|
|
7828
7938
|
format: "jsonc",
|
|
7829
7939
|
key: ["mcp", SERVER_KEY],
|
|
7830
7940
|
value: { type: "local", command: [node, server, flag, agent], enabled: true }
|
|
@@ -7853,7 +7963,7 @@ function cliFor(ctx, id) {
|
|
|
7853
7963
|
}
|
|
7854
7964
|
function copyFor(ctx, id) {
|
|
7855
7965
|
if (id !== "claude-code") return void 0;
|
|
7856
|
-
const file =
|
|
7966
|
+
const file = path4.join(claudeDirOf(ctx.env, ctx.home), HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE);
|
|
7857
7967
|
return { host: "Claude Code", bin: "claude", plugin: PLUGIN_ID, file, refresh: ["plugin", "update", PLUGIN_ID], enable: ["plugin", "enable", PLUGIN_ID] };
|
|
7858
7968
|
}
|
|
7859
7969
|
var LIST = {
|
|
@@ -7874,11 +7984,11 @@ function hookFilesFor(ctx, id) {
|
|
|
7874
7984
|
case "copilot-cli":
|
|
7875
7985
|
return [{ file: agentPath(ctx, id, [COPILOT_DIR, "hooks", "context-mode.json"]), mode: "rewrite" }];
|
|
7876
7986
|
case "claude-code":
|
|
7877
|
-
return [{ file:
|
|
7987
|
+
return [{ file: path4.join(claudeDirOf(ctx.env, home), "settings.json"), mode: "drop" }];
|
|
7878
7988
|
case "gemini":
|
|
7879
|
-
return [{ file:
|
|
7989
|
+
return [{ file: path4.join(home, ".gemini", "settings.json"), mode: "drop" }];
|
|
7880
7990
|
case "qwen":
|
|
7881
|
-
return [{ file:
|
|
7991
|
+
return [{ file: path4.join(home, ".qwen", "settings.json"), mode: "drop" }];
|
|
7882
7992
|
default:
|
|
7883
7993
|
return [];
|
|
7884
7994
|
}
|
|
@@ -7889,13 +7999,13 @@ function hookInstallFor(ctx, row, command) {
|
|
|
7889
7999
|
const shape = HOOK_SHAPES[row.id];
|
|
7890
8000
|
if (!shape) throw new Error(`setup: ${row.id} has a home-file hook channel and no hook shape`);
|
|
7891
8001
|
const file = agentPath(ctx, row.id, ch.path);
|
|
7892
|
-
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) };
|
|
7893
8003
|
return { kind: "file", file, shape: shape(row, command), command };
|
|
7894
8004
|
}
|
|
7895
8005
|
if (row.id === "opencode") {
|
|
7896
8006
|
return {
|
|
7897
8007
|
kind: "plugin-list",
|
|
7898
|
-
file:
|
|
8008
|
+
file: path4.join(opencodeDirOf(ctx.env, ctx.home), OPENCODE_BASE_CONFIG_FILE),
|
|
7899
8009
|
key: ["plugin"],
|
|
7900
8010
|
entry: ctx.pkgDir
|
|
7901
8011
|
};
|
|
@@ -7911,11 +8021,11 @@ function skillInstallFor(ctx, row) {
|
|
|
7911
8021
|
const ch = row.skillChannel;
|
|
7912
8022
|
if (ch.kind === "package") return { kind: "package", via: ch.path };
|
|
7913
8023
|
const dir = agentPath(ctx, row.id, ch.path);
|
|
7914
|
-
const src =
|
|
8024
|
+
const src = path4.join(ctx.pkgDir, bareSkillDir());
|
|
7915
8025
|
return { kind: "dir", dir, prefixes: skillDirPrefixes(ch.path), files: COMMAND_SKILLS.map((name) => ({
|
|
7916
8026
|
name,
|
|
7917
|
-
src:
|
|
7918
|
-
file:
|
|
8027
|
+
src: path4.join(src, name, SKILL_FILE),
|
|
8028
|
+
file: path4.join(dir, name, SKILL_FILE)
|
|
7919
8029
|
})) };
|
|
7920
8030
|
}
|
|
7921
8031
|
function buildRegistry(ctx) {
|
|
@@ -7923,7 +8033,7 @@ function buildRegistry(ctx) {
|
|
|
7923
8033
|
const id = row.id;
|
|
7924
8034
|
const config = configFor(ctx, id);
|
|
7925
8035
|
const hookFiles = hookFilesFor(ctx, id);
|
|
7926
|
-
const runCommand2 = [process.execPath,
|
|
8036
|
+
const runCommand2 = [process.execPath, path4.join(ctx.pkgDir, HOOK_BUNDLE), AGENT_FLAG, id];
|
|
7927
8037
|
const bareNode = id === "codex" && (ctx.platform ?? process.platform) === "win32";
|
|
7928
8038
|
const hookCommand = bareNode ? [HOST_NODE_COMMAND, ...runCommand2.slice(1)] : runCommand2;
|
|
7929
8039
|
const command = `${bareNode ? HOST_NODE_COMMAND : `"${hookCommand[0]}"`} "${hookCommand[1]}" ${AGENT_FLAG} ${id}`;
|
|
@@ -7949,7 +8059,7 @@ function buildRegistry(ctx) {
|
|
|
7949
8059
|
hookInstall,
|
|
7950
8060
|
skillInstall,
|
|
7951
8061
|
hookRunCommand: runCommand2,
|
|
7952
|
-
allowedWrites: [...new Set(writes.map((f2) =>
|
|
8062
|
+
allowedWrites: [...new Set(writes.map((f2) => path4.resolve(f2)))],
|
|
7953
8063
|
goldenPayload: golden(row, ctx.home)
|
|
7954
8064
|
};
|
|
7955
8065
|
if (copilotSettings) out2.copilotSettings = copilotSettings;
|
|
@@ -7962,15 +8072,15 @@ function buildRegistry(ctx) {
|
|
|
7962
8072
|
});
|
|
7963
8073
|
}
|
|
7964
8074
|
function assertWritable(row, file) {
|
|
7965
|
-
const abs =
|
|
7966
|
-
if (INSTRUCTION_FILES.includes(
|
|
8075
|
+
const abs = path4.resolve(file);
|
|
8076
|
+
if (INSTRUCTION_FILES.includes(path4.basename(abs)) || !row.allowedWrites.includes(abs)) {
|
|
7967
8077
|
throw new Error(`setup: write to ${abs} is not allowed for ${row.id}`);
|
|
7968
8078
|
}
|
|
7969
8079
|
}
|
|
7970
8080
|
|
|
7971
8081
|
// src/setup/gemini-gate.ts
|
|
7972
|
-
import { existsSync as
|
|
7973
|
-
import
|
|
8082
|
+
import { existsSync as existsSync10, readFileSync as readFileSync6 } from "node:fs";
|
|
8083
|
+
import path5 from "node:path";
|
|
7974
8084
|
var GEMINI_DIR = ".gemini";
|
|
7975
8085
|
var SETTINGS_FILE2 = "settings.json";
|
|
7976
8086
|
var SYSTEM_PATH_ENV = "GEMINI_CLI_SYSTEM_SETTINGS_PATH";
|
|
@@ -7982,16 +8092,16 @@ function systemSettingsPath(env) {
|
|
|
7982
8092
|
if (process.platform === "win32") return "C:\\ProgramData\\gemini-cli\\settings.json";
|
|
7983
8093
|
return "/etc/gemini-cli/settings.json";
|
|
7984
8094
|
}
|
|
7985
|
-
function
|
|
7986
|
-
if (!
|
|
8095
|
+
function load2(file) {
|
|
8096
|
+
if (!existsSync10(file)) return void 0;
|
|
7987
8097
|
try {
|
|
7988
|
-
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(
|
|
8098
|
+
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync6(file, "utf8")), "jsonc") };
|
|
7989
8099
|
} catch {
|
|
7990
8100
|
return void 0;
|
|
7991
8101
|
}
|
|
7992
8102
|
}
|
|
7993
8103
|
function sources(env, home, cwd) {
|
|
7994
|
-
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);
|
|
7995
8105
|
}
|
|
7996
8106
|
function ownHookEntry(entry2) {
|
|
7997
8107
|
return typeof entry2 === "string" && entry2.includes(HOOK_BUNDLE) && entry2.includes(`${AGENT_FLAG} ${OWN_AGENT}`);
|
|
@@ -8017,8 +8127,8 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
8017
8127
|
}
|
|
8018
8128
|
|
|
8019
8129
|
// src/setup/zcode-gate.ts
|
|
8020
|
-
import { existsSync as
|
|
8021
|
-
import
|
|
8130
|
+
import { existsSync as existsSync11, readFileSync as readFileSync7 } from "node:fs";
|
|
8131
|
+
import path6 from "node:path";
|
|
8022
8132
|
var OWN_AGENT2 = "zcode";
|
|
8023
8133
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
8024
8134
|
var HOOK_TYPES = ["process", "command"];
|
|
@@ -8108,11 +8218,11 @@ function zcodeSchemaBad(doc) {
|
|
|
8108
8218
|
);
|
|
8109
8219
|
}
|
|
8110
8220
|
function zcodeConfigGate(home) {
|
|
8111
|
-
const file =
|
|
8112
|
-
if (!
|
|
8221
|
+
const file = path6.join(home, ".zcode", "cli", "config.json");
|
|
8222
|
+
if (!existsSync11(file)) return void 0;
|
|
8113
8223
|
let doc;
|
|
8114
8224
|
try {
|
|
8115
|
-
doc = parseHostConfig(OWN_AGENT2, file, hostText(
|
|
8225
|
+
doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync7(file, "utf8")), "json");
|
|
8116
8226
|
} catch {
|
|
8117
8227
|
return void 0;
|
|
8118
8228
|
}
|
|
@@ -8121,106 +8231,6 @@ function zcodeConfigGate(home) {
|
|
|
8121
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`;
|
|
8122
8232
|
}
|
|
8123
8233
|
|
|
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
8234
|
// src/setup/vscode-gate.ts
|
|
8225
8235
|
import { existsSync as existsSync12, readFileSync as readFileSync8 } from "node:fs";
|
|
8226
8236
|
import path7 from "node:path";
|
package/copilot/plugin.json
CHANGED
package/gemini-extension.json
CHANGED