context-mode 2.2.1 → 2.2.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/cli.mjs CHANGED
@@ -16,16 +16,9 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
16
16
  var SERVER_KEY = "context-mode";
17
17
  var TOOL_ORDER = Object.freeze(["ctx_execute", "ctx_batch", "ctx_index", "ctx_search", "ctx_resume", "ctx_stats", "ctx_doctor", "ctx_upgrade", "ctx_purge"]);
18
18
  var OUTPUT_CAP = 16384;
19
- var REPLACE_TRIGGER_BYTES_DEFAULT = 4096;
20
- var REPLACE_TRIGGER_ENV = "CTX_REPLACE_TRIGGER_BYTES";
21
- function readReplaceTrigger(raw) {
22
- if (raw === void 0 || raw.trim() === "") return REPLACE_TRIGGER_BYTES_DEFAULT;
23
- const n3 = Number(raw);
24
- return Number.isSafeInteger(n3) && n3 > 0 ? n3 : REPLACE_TRIGGER_BYTES_DEFAULT;
25
- }
26
- var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
27
19
  var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
28
20
  var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
21
+ var SKILL_LOAD_TOOLS = Object.freeze(["Skill"]);
29
22
  var WEIGHT = Object.freeze({ toolerr: 900, decision: 700, prompt: 500, edit: 400, index: 200 });
30
23
  var DECAY_X1000 = Object.freeze([
31
24
  1e3,
@@ -169,6 +162,7 @@ var EXEC_LANGUAGES = Object.freeze(["shell", "powershell", "javascript", "typesc
169
162
  var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
170
163
  var PLAIN_OUTPUT_ENV = Object.freeze({ NO_COLOR: "1", FORCE_COLOR: "0" });
171
164
  var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
165
+ var HOST_SESSION_META = Object.freeze({ zcode: "session_id" });
172
166
  var NODE_MIN = "24.15.0";
173
167
  var DATA_ROOT = "~/.context-mode";
174
168
  var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
@@ -515,6 +509,7 @@ var OPENCODE_CONFIG_DIR_ENV = "OPENCODE_CONFIG_DIR";
515
509
  var APPDATA_ENV = "APPDATA";
516
510
  var VSCODE_USER_DIR_SEGMENTS = Object.freeze(["Code", "User"]);
517
511
  var XDG_CONFIG_HOME_ENV = "XDG_CONFIG_HOME";
512
+ var PI_CONFIG_DIR_ENV = "PI_CONFIG_DIR";
518
513
  var CONFIG_TOML_FILE = "config.toml";
519
514
  var CONFIG_JSON_FILE = "config.json";
520
515
  var ZCODE_CLI_DIR = "cli";
@@ -691,6 +686,7 @@ var SHELL_TOOL_NAMES = Object.freeze(["Bash", "PowerShell"]);
691
686
  var POWERSHELL_TOOL = "PowerShell";
692
687
  var SHELL_CANONICAL = "Bash";
693
688
  var CLAUDE_SHAPE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse"];
689
+ var FAILURE_EVENT = "PostToolUseFailure";
694
690
  var MCP_PREFIX = "mcp__";
695
691
  var MCP_SEP = "__";
696
692
  var CLAUDE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
@@ -864,7 +860,14 @@ function requireFields(raw) {
864
860
  }
865
861
  function decode(raw) {
866
862
  requireFields(raw);
867
- const ev = decodeClaudeShape(raw, "claude-code", TOOL_NAME_PREFIX, CLAUDE_SOURCES);
863
+ const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
864
+ const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
865
+ const ev = decodeClaudeShape(payload, "claude-code", TOOL_NAME_PREFIX, CLAUDE_SOURCES);
866
+ if (failure) {
867
+ const error = raw.error;
868
+ const text2 = typeof error === "string" ? error : error === void 0 ? "" : JSON.stringify(error);
869
+ ev.result = { isError: true, bytes: Buffer.byteLength(text2), text: text2, keep: true };
870
+ }
868
871
  if (ev.tool !== void 0 && ev.tool.name === POWERSHELL_TOOL) ev.tool.canonicalName = SHELL_CANONICAL;
869
872
  if (ev.cwd === "") ev.cwd = process.env.CLAUDE_PROJECT_DIR || process.cwd();
870
873
  if (ev.event === "PostToolUse" && ev.tool !== void 0 && ev.tool.callId === void 0) {
@@ -1043,9 +1046,9 @@ var NATIVE_TO_CANONICAL2 = {
1043
1046
  grep_search: "Grep",
1044
1047
  web_fetch: "WebFetch"
1045
1048
  };
1046
- var FAILURE_EVENT = "PostToolUseFailure";
1049
+ var FAILURE_EVENT2 = "PostToolUseFailure";
1047
1050
  function decode4(raw) {
1048
- const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
1051
+ const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT2;
1049
1052
  const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
1050
1053
  const ev = decodeClaudeShape(payload, "qwen", TOOL_NAME_PREFIX4, QWEN_SOURCES);
1051
1054
  if (ev.tool !== void 0 && Object.hasOwn(NATIVE_TO_CANONICAL2, ev.tool.name)) ev.tool.canonicalName = NATIVE_TO_CANONICAL2[ev.tool.name];
@@ -1365,12 +1368,12 @@ var TOOL_NAME_PREFIX8 = "mcp__context-mode__";
1365
1368
  var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
1366
1369
  var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
1367
1370
  var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
1368
- var FAILURE_EVENT2 = "PostToolUseFailure";
1371
+ var FAILURE_EVENT3 = "PostToolUseFailure";
1369
1372
  function decode8(raw) {
1370
1373
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("zcode: hook payload is not a JSON object");
1371
1374
  const p3 = { ...raw };
1372
1375
  for (const [snake2, camel] of Object.entries(TWINS)) if (p3[snake2] === void 0) p3[snake2] = p3[camel];
1373
- const failure = p3.hook_event_name === FAILURE_EVENT2;
1376
+ const failure = p3.hook_event_name === FAILURE_EVENT3;
1374
1377
  if (failure) p3.hook_event_name = "PostToolUse";
1375
1378
  const toolName = typeof p3.tool_name === "string" ? p3.tool_name : "";
1376
1379
  const prefix = toolName.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX8;
@@ -1461,7 +1464,8 @@ var OPENCODE_EVENTS = {
1461
1464
  var SHELL_TOOL_NAME = "bash";
1462
1465
  var READ_TOOL_NAME = "read";
1463
1466
  var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
1464
- var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n3) => [n3, "Bash"])) };
1467
+ var SKILL_TOOL_NAME = "skill";
1468
+ var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", [SKILL_TOOL_NAME]: "Skill", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n3) => [n3, "Bash"])) };
1465
1469
  function toCanonicalTool(name) {
1466
1470
  if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
1467
1471
  return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
@@ -4910,7 +4914,8 @@ var ERROR_TEXT = Object.freeze({
4910
4914
  NO_RUNTIME: "No <lang> runtime on PATH. Fix: install it or pick another language.",
4911
4915
  FETCH_FAILED: "Fetch failed: <code>. Fix: check the URL or proxy.",
4912
4916
  SSRF: "Blocked private address <host>. Fix: use a public URL.",
4913
- OUTSIDE_ROOT: "Path <p> is outside the project. Fix: use a path inside <root>.",
4917
+ OUTSIDE_ROOT: "Path <p> is outside the project and the folders added to this session. Fix: use a path inside <root>, or add its folder to the session (Claude Code /add-dir, Codex --add-dir).",
4918
+ // #1398 D-1398-HOST-ROOTS-1
4914
4919
  INVALID_ARGS: "Invalid argument <field>. Fix: <action>.",
4915
4920
  ONE_OF_INPUT: "Pass exactly one of <names>. Fix: drop the extra field.",
4916
4921
  SPAWN_FAILED: "Failed to start the process: <detail>. Fix: check the command and PATH.",
@@ -5047,6 +5052,13 @@ function piAgentDirOf(env, home) {
5047
5052
  const dir = env[PI_AGENT_DIR_ENV];
5048
5053
  return dir !== void 0 && dir !== "" ? dir : join2(home, ...AGENT_HOME_DIR.pi, PI_AGENT_DIR);
5049
5054
  }
5055
+ function ompConfigRootOf(env, home) {
5056
+ const dir = env[PI_CONFIG_DIR_ENV];
5057
+ return dir !== void 0 && dir !== "" ? join2(home, dir) : join2(home, ...AGENT_HOME_DIR.omp);
5058
+ }
5059
+ function ompAgentDirOf(env, home) {
5060
+ return join2(ompConfigRootOf(env, home), PI_AGENT_DIR);
5061
+ }
5050
5062
  function vscodeUserDirOf(env, home, platform = process.platform) {
5051
5063
  const set2 = (v) => v !== void 0 && v !== "";
5052
5064
  const p3 = platform === "win32" ? win32 : posix;
@@ -8200,8 +8212,8 @@ var ENABLED_PROVIDERS = "enabledProviders";
8200
8212
  var DISABLED_PROVIDERS = "disabledProviders";
8201
8213
  var CLAUDE_PROVIDER = "claude";
8202
8214
  var ALL_PROVIDERS = ["*", "all"];
8203
- function ompImportFiles(home) {
8204
- const agentDir = join11(home, ...AGENT_HOME_DIR.omp, PI_AGENT_DIR);
8215
+ function ompImportFiles(env, home) {
8216
+ const agentDir = ompAgentDirOf(env, home);
8205
8217
  return { config: join11(agentDir, OMP_CONFIG_FILE), mcp: join11(agentDir, OMP_MCP_FILE), claude: join11(home, CLAUDE_USER_CONFIG_FILE) };
8206
8218
  }
8207
8219
  function readText2(file) {
@@ -8623,7 +8635,9 @@ function copyFor(ctx, id) {
8623
8635
  }
8624
8636
  var LIST = {
8625
8637
  "claude-code": { bin: "claude", args: ["plugin", "list"] },
8626
- codex: { bin: "codex", args: ["mcp", "list"] },
8638
+ // D-1413-CODEX-LIST-1 (#1413): `mcp list` runs OAuth discovery (network, 5 s cap per server) and keyring reads for every
8639
+ // server; `mcp get <name> --json` loads the same servers, plugin servers too, and looks up the exact name (no auth).
8640
+ codex: { bin: "codex", args: ["mcp", "get", SERVER_KEY, "--json"], reader: "codex-mcp-get" },
8627
8641
  gemini: { bin: "gemini", args: ["extensions", "list"] },
8628
8642
  qwen: { bin: "qwen", args: ["extensions", "list"] },
8629
8643
  "copilot-cli": { bin: "copilot", args: ["mcp", "list"] },
@@ -8707,7 +8721,7 @@ function buildRegistry(ctx) {
8707
8721
  ...hookInstall.kind === "package" ? [] : [hookInstall.file],
8708
8722
  ...hookInstall.kind === "file" && hookInstall.trust ? [hookInstall.trust] : [],
8709
8723
  ...skillInstall.kind === "dir" ? skillInstall.files.map((f2) => f2.file) : [],
8710
- ...id === "omp" ? [ompImportFiles(ctx.home).mcp] : []
8724
+ ...id === "omp" ? [ompImportFiles(ctx.env, ctx.home).mcp] : []
8711
8725
  // ADR-0026 decision 11: disabledServers, only when OMP imports us
8712
8726
  ];
8713
8727
  const out2 = {
@@ -9758,7 +9772,7 @@ function planSkills(row, edits) {
9758
9772
  }
9759
9773
  }
9760
9774
  function planOmpImport(row, edits, ctx) {
9761
- const files = ompImportFiles(ctx.home);
9775
+ const files = ompImportFiles(ctx.env, ctx.home);
9762
9776
  if (!ompImportsUs(files, ctx.env)) return;
9763
9777
  planJsonKeys(row, edits, files.mcp, "json", (doc) => {
9764
9778
  const cur = Array.isArray(doc[OMP_DISABLED_SERVERS_KEY]) ? doc[OMP_DISABLED_SERVERS_KEY] : [];
@@ -9864,6 +9878,17 @@ function hostBroken(bin, out2) {
9864
9878
  const lines = out2.trim().split("\n");
9865
9879
  return `${b3.prefix}${b3.fix} (${(lines.find((l) => l.includes(b3.text)) ?? lines[0]).trim()})`;
9866
9880
  }
9881
+ function codexGetCheck(what, r2) {
9882
+ let doc;
9883
+ try {
9884
+ doc = JSON.parse(`${r2.stdout}`);
9885
+ } catch {
9886
+ doc = void 0;
9887
+ }
9888
+ if (r2.status === 0 && isObj5(doc) && doc.name === SERVER_KEY) return { name: "list", ok: true };
9889
+ const host = `${r2.stderr}`.split("\n").map((l) => l.trim()).filter(Boolean).slice(0, 3).join(" ") || `${r2.stdout}`.trim().split("\n")[0] || `exit ${r2.status}`;
9890
+ return { name: "list", ok: false, detail: `${what} does not find ${SERVER_KEY}: ${host}` };
9891
+ }
9867
9892
  function listState(row, env) {
9868
9893
  const l = row.listCommand;
9869
9894
  if (!l || !hostBin(l.bin, env).file) return { status: void 0 };
@@ -9872,9 +9897,14 @@ function listState(row, env) {
9872
9897
  return { check: "major" in v ? opencodeListCheck(l.bin, v.major, env) : { name: "list", ok: false, detail: v.error }, status: void 0 };
9873
9898
  }
9874
9899
  const r2 = runBin(l.bin, l.args, env);
9900
+ const what = `${l.bin} ${l.args.join(" ")}`;
9901
+ if (r2.error?.code === "ETIMEDOUT") {
9902
+ return { check: { name: "list", ok: false, detail: `${what} did not answer in ${VERIFY_TIMEOUT_MS / 1e3} s (${r2.signal ?? "timeout"}); run it in a terminal` }, status: void 0 };
9903
+ }
9904
+ if (l.reader === "codex-mcp-get") return { check: codexGetCheck(what, r2), status: void 0 };
9875
9905
  const out2 = `${r2.stdout}${r2.stderr}`;
9876
9906
  const ok = r2.status === 0 && out2.includes("context-mode");
9877
- const check = { name: "list", ok, detail: ok ? void 0 : `${l.bin} ${l.args.join(" ")} does not list context-mode` };
9907
+ const check = { name: "list", ok, detail: ok ? void 0 : `${what} does not list context-mode` };
9878
9908
  return { check, status: r2.status === 0 ? statusOf(row, `${r2.stdout}`) : void 0, broken: r2.status === 0 ? void 0 : hostBroken(l.bin, out2) };
9879
9909
  }
9880
9910
  var DISABLE_ALL_HOOKS = "disableAllHooks";
@@ -10081,7 +10111,7 @@ function hookRegisteredCheck(row, env, list2) {
10081
10111
  const l = row.listCommand;
10082
10112
  if (!l) return { name: "hook-registered", ok: false, detail: `no list command for ${row.id}` };
10083
10113
  if (!list2) return { name: "hook-registered", ok: false, detail: `${l.bin} is not on PATH, so the hooks cannot be checked` };
10084
- return { name: "hook-registered", ok: list2.ok, detail: list2.ok ? void 0 : `${l.bin} ${l.args.join(" ")} does not list context-mode (hooks ship in ${h2.via})` };
10114
+ return { name: "hook-registered", ok: list2.ok, detail: list2.ok ? void 0 : `${list2.detail ?? `${l.bin} ${l.args.join(" ")} does not list context-mode`} (hooks ship in ${h2.via})` };
10085
10115
  }
10086
10116
  const edits = [];
10087
10117
  try {
@@ -11,5 +11,5 @@
11
11
  }
12
12
  },
13
13
  "name": "context-mode",
14
- "version": "2.2.1"
14
+ "version": "2.2.3"
15
15
  }
@@ -11,5 +11,5 @@
11
11
  }
12
12
  },
13
13
  "name": "context-mode",
14
- "version": "2.2.1"
14
+ "version": "2.2.3"
15
15
  }