context-mode 2.1.4 → 2.1.5

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
@@ -297,6 +297,30 @@ var DUMP_COUNT_COMMANDS = Object.freeze(["head", "tail"]);
297
297
  var DUMP_COUNT_FLAGS = Object.freeze(["-n", "-c", "--lines", "--bytes"]);
298
298
  var SED_QUIET_FLAGS = Object.freeze(["-n", "--quiet", "--silent"]);
299
299
  var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path", "filePath"]);
300
+ var READ_MEDIA_TYPES = Object.freeze({
301
+ png: { exts: [".png"], sig: [{ at: 0, bytes: [137, 80, 78, 71, 13, 10, 26, 10] }] },
302
+ jpeg: { exts: [".jpg", ".jpeg"], sig: [{ at: 0, bytes: [255, 216, 255] }] },
303
+ gif: { exts: [".gif"], sig: [{ at: 0, bytes: [71, 73, 70, 56] }] },
304
+ // "GIF8"
305
+ webp: { exts: [".webp"], sig: [{ at: 0, bytes: [82, 73, 70, 70] }, { at: 8, bytes: [87, 69, 66, 80] }] },
306
+ // "RIFF" .... "WEBP"
307
+ pdf: { exts: [".pdf"], sig: [{ at: 0, bytes: [37, 80, 68, 70, 45] }] }
308
+ // "%PDF-"
309
+ });
310
+ var READ_IMAGES = Object.freeze(["png", "jpeg", "gif", "webp"]);
311
+ var READ_IMAGES_AND_PDF = Object.freeze([...READ_IMAGES, "pdf"]);
312
+ var READ_MEDIA_BY_AGENT = Object.freeze({
313
+ "claude-code": READ_IMAGES_AND_PDF,
314
+ gemini: READ_IMAGES_AND_PDF,
315
+ qwen: READ_IMAGES_AND_PDF,
316
+ opencode: READ_IMAGES_AND_PDF,
317
+ pi: READ_IMAGES,
318
+ vscode: READ_IMAGES,
319
+ "copilot-cli": [],
320
+ codex: [],
321
+ kiro: [],
322
+ zcode: []
323
+ });
300
324
  var OWN_TOOL_PREFIX = "ctx_";
301
325
  var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
302
326
  var EDIT_PATH_KEYS = Object.freeze(["file_path", "path"]);
@@ -823,10 +847,17 @@ function encode(ev, d, _extra) {
823
847
  // src/adapters/codex.ts
824
848
  var TOOL_NAME_PREFIX2 = "mcp__context_mode__";
825
849
  var CODEX_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact", fork: "resume" };
850
+ var STOP_EVENT = "Stop";
851
+ var EMPTY = { stdout: "", exitCode: 0 };
826
852
  function decode2(raw) {
853
+ if (typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === STOP_EVENT) {
854
+ const p3 = raw;
855
+ return { event: STOP_EVENT, agent: "codex", sessionId: String(p3.session_id ?? ""), cwd: String(p3.cwd ?? "") };
856
+ }
827
857
  return decodeClaudeShape(raw, "codex", TOOL_NAME_PREFIX2, CODEX_SOURCES);
828
858
  }
829
859
  function encode2(ev, d, _extra) {
860
+ if (ev.event === STOP_EVENT) return EMPTY;
830
861
  return encodeClaudeShape(ev, d, false);
831
862
  }
832
863
 
@@ -842,7 +873,7 @@ var GEMINI_EVENTS = {
842
873
  var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
843
874
  var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
844
875
  var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
845
- var EMPTY = { stdout: "", exitCode: 0 };
876
+ var EMPTY2 = { stdout: "", exitCode: 0 };
846
877
  var GEMINI_REPLACE_LEAD = "the tool ran and succeeded; context-mode indexed its full output, and this is the part that answers the call:\n";
847
878
  function own(p3, key) {
848
879
  return Object.hasOwn(p3, key) ? p3[key] : void 0;
@@ -883,7 +914,13 @@ function readResult2(resp) {
883
914
  const llm = obj === void 0 ? void 0 : own(obj, "llmContent");
884
915
  const text2 = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
885
916
  const err2 = obj === void 0 ? void 0 : own(obj, "error");
886
- return { isError: err2 !== void 0 && err2 !== null, bytes: Buffer.byteLength(text2), text: text2 };
917
+ const info = { isError: err2 !== void 0 && err2 !== null, bytes: Buffer.byteLength(text2), text: text2 };
918
+ if (hasMediaPart(llm)) info.keep = true;
919
+ return info;
920
+ }
921
+ function hasMediaPart(llm) {
922
+ const parts = Array.isArray(llm) ? llm : [llm];
923
+ return parts.some((p3) => typeof p3 === "object" && p3 !== null && (Object.hasOwn(p3, "inlineData") || Object.hasOwn(p3, "fileData")));
887
924
  }
888
925
  var URL_STARTS = ["https://", "http://"];
889
926
  var URL_TRAIL = `.,;:!?)]}>'"`;
@@ -950,15 +987,15 @@ function decode3(raw) {
950
987
  function encode3(ev, d, _extra) {
951
988
  switch (d.kind) {
952
989
  case "allow":
953
- return EMPTY;
990
+ return EMPTY2;
954
991
  case "hint":
955
- if (!HINT_EVENTS.includes(ev.event)) return EMPTY;
992
+ if (!HINT_EVENTS.includes(ev.event)) return EMPTY2;
956
993
  return { stdout: JSON.stringify({ hookSpecificOutput: { additionalContext: d.text } }), exitCode: 0 };
957
994
  case "deny":
958
- if (!DENY_EVENTS.includes(ev.event)) return EMPTY;
995
+ if (!DENY_EVENTS.includes(ev.event)) return EMPTY2;
959
996
  return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
960
997
  case "replace":
961
- if (ev.event !== "PostToolUse") return EMPTY;
998
+ if (ev.event !== "PostToolUse") return EMPTY2;
962
999
  return { stdout: JSON.stringify({ decision: "deny", reason: GEMINI_REPLACE_LEAD + d.output }), exitCode: 0 };
963
1000
  }
964
1001
  }
@@ -1078,21 +1115,21 @@ function decode5(raw) {
1078
1115
  if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
1079
1116
  return ev;
1080
1117
  }
1081
- var EMPTY2 = { stdout: "", exitCode: 0 };
1118
+ var EMPTY3 = { stdout: "", exitCode: 0 };
1082
1119
  function encode5(ev, d, _extra) {
1083
1120
  switch (d.kind) {
1084
1121
  case "allow":
1085
- return EMPTY2;
1122
+ return EMPTY3;
1086
1123
  case "hint":
1087
- return ev.event === "PostToolUse" ? EMPTY2 : { stdout: JSON.stringify({ additionalContext: d.text }), exitCode: 0 };
1124
+ return ev.event === "PostToolUse" ? EMPTY3 : { stdout: JSON.stringify({ additionalContext: d.text }), exitCode: 0 };
1088
1125
  case "deny":
1089
- if (ev.event !== "PreToolUse") return EMPTY2;
1126
+ if (ev.event !== "PreToolUse") return EMPTY3;
1090
1127
  return {
1091
1128
  stdout: JSON.stringify({ permissionDecision: "deny", permissionDecisionReason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }),
1092
1129
  exitCode: 0
1093
1130
  };
1094
1131
  case "replace":
1095
- if (ev.event !== "PostToolUse") return EMPTY2;
1132
+ if (ev.event !== "PostToolUse") return EMPTY3;
1096
1133
  return { stdout: JSON.stringify({ modifiedResult: { resultType: RESULT_SUCCESS, textResultForLlm: d.output } }), exitCode: 0 };
1097
1134
  }
1098
1135
  }
@@ -4824,11 +4861,17 @@ function dataRootOf(env, home) {
4824
4861
 
4825
4862
  // src/core/ops/doctor-issue.ts
4826
4863
  import { spawnSync } from "node:child_process";
4827
- import { closeSync, existsSync as existsSync9, fstatSync, mkdirSync as mkdirSync4, openSync, readFileSync as readFileSync5, readSync, realpathSync as realpathSync5, writeFileSync as writeFileSync2 } from "node:fs";
4864
+ import { closeSync as closeSync2, existsSync as existsSync9, fstatSync, mkdirSync as mkdirSync4, openSync as openSync2, readFileSync as readFileSync5, readSync as readSync2, realpathSync as realpathSync5, writeFileSync as writeFileSync2 } from "node:fs";
4828
4865
  import { delimiter, join as join10 } from "node:path";
4829
4866
 
4830
4867
  // src/core/hooks/fallback.ts
4831
4868
  import { join as join3, resolve as resolve2 } from "node:path";
4869
+
4870
+ // src/core/policy/read-media.ts
4871
+ import { extname } from "node:path";
4872
+ var { closeSync, openSync, readSync } = process.getBuiltinModule("node:fs");
4873
+
4874
+ // src/core/hooks/fallback.ts
4832
4875
  var fs = process.getBuiltinModule("node:fs");
4833
4876
 
4834
4877
  // src/core/store/schema.ts
@@ -8018,7 +8061,7 @@ function extensionPlugin(bin, id) {
8018
8061
  };
8019
8062
  }
8020
8063
  var NATIVE_PLUGIN = {
8021
- codex: { bin: "codex", args: ["plugin", "list"], plugin: PLUGIN_ID, hooksVia: ".codex-plugin", skillsVia: path4.join("codex", SKILLS_DIR_NAME), format: "table", hookTrust: true },
8064
+ codex: { bin: "codex", args: ["plugin", "list", "--json"], plugin: PLUGIN_ID, hooksVia: ".codex-plugin", skillsVia: path4.join("codex", SKILLS_DIR_NAME), format: "codex-json", hookTrust: true },
8022
8065
  qwen: extensionPlugin("qwen", "qwen"),
8023
8066
  gemini: extensionPlugin("gemini", "gemini"),
8024
8067
  // D-R44-ZCODE-NATIVE-1 (host audit zcode-1/2): `zcode plugins install context-mode@context-mode` lists as JSON; ZCode loads
@@ -8874,7 +8917,7 @@ function listCopilotHooks(env, file, cwd) {
8874
8917
 
8875
8918
  // src/setup/engine.ts
8876
8919
  import { spawn as spawn3, spawnSync as spawnSync4 } from "node:child_process";
8877
- import { closeSync as closeSync2, existsSync as existsSync16, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync2, readFileSync as readFileSync10, readSync as readSync2, readdirSync as readdirSync5, realpathSync as realpathSync9, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
8920
+ import { closeSync as closeSync3, existsSync as existsSync16, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync3, readFileSync as readFileSync10, readSync as readSync3, readdirSync as readdirSync5, realpathSync as realpathSync9, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
8878
8921
  import { tmpdir as tmpdir2 } from "node:os";
8879
8922
  import path12 from "node:path";
8880
8923
 
@@ -8960,11 +9003,11 @@ var REAL_HOST = Object.freeze({
8960
9003
  var BINARY_MAGICS = Object.freeze(["cffaedfe", "cefaedfe", "7f454c46", "4d5a"]);
8961
9004
  function isNativeBinary(file) {
8962
9005
  const head = Buffer.alloc(4);
8963
- const fd = openSync2(file, "r");
9006
+ const fd = openSync3(file, "r");
8964
9007
  try {
8965
- readSync2(fd, head, 0, 4, 0);
9008
+ readSync3(fd, head, 0, 4, 0);
8966
9009
  } finally {
8967
- closeSync2(fd);
9010
+ closeSync3(fd);
8968
9011
  }
8969
9012
  const hex = head.toString("hex");
8970
9013
  return BINARY_MAGICS.some((m3) => hex.startsWith(m3));
@@ -9004,7 +9047,7 @@ function installExitOk(status, listed, platform = process.platform) {
9004
9047
  return platform === "win32" && status === WIN_EXIT_CRASH && listed;
9005
9048
  }
9006
9049
  function runBin(bin, args, env, input, timeout = VERIFY_TIMEOUT_MS) {
9007
- return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout });
9050
+ return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout, maxBuffer: Infinity });
9008
9051
  }
9009
9052
  function readOr(file) {
9010
9053
  return existsSync16(file) ? hostText(readFileSync10(file, "utf8")) : void 0;
@@ -9564,16 +9607,21 @@ function skillsCheck(row, pkgDir) {
9564
9607
  const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync16(f2.src) ? renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes) : void 0));
9565
9608
  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 };
9566
9609
  }
9567
- var PLUGIN_ENABLED = "enabled";
9568
- var WORD_TRIM = ",;";
9569
9610
  var CODEX_CONFIG_FILE2 = "config.toml";
9570
9611
  var EXT_ENABLED_USER = "Enabled (User):";
9571
9612
  var EXT_ENABLED_WORKSPACE = "Enabled (Workspace):";
9572
9613
  var EXT_TRUE = "true";
9573
- function tableState(n3, text2) {
9574
- const line = text2.split("\n").find((l2) => l2.split(" ").includes(n3.plugin));
9575
- if (line === void 0) return void 0;
9576
- return line.split(" ").map((w) => trimChars(w, WORD_TRIM)).includes(PLUGIN_ENABLED) ? "enabled" : "disabled";
9614
+ function codexJsonState(n3, text2) {
9615
+ let doc;
9616
+ try {
9617
+ doc = JSON.parse(text2);
9618
+ } catch {
9619
+ return void 0;
9620
+ }
9621
+ const list2 = isObj5(doc) && Array.isArray(doc.installed) ? doc.installed : [];
9622
+ const mine = list2.find((p3) => isObj5(p3) && p3.pluginId === n3.plugin);
9623
+ if (!isObj5(mine)) return void 0;
9624
+ return mine.enabled === true ? "enabled" : "disabled";
9577
9625
  }
9578
9626
  function extensionState(n3, text2) {
9579
9627
  let mine = false;
@@ -9618,9 +9666,15 @@ function nativeState(row, env) {
9618
9666
  const n3 = row.nativePlugin;
9619
9667
  if (!n3 || !hostBin(n3.bin, env).file) return none;
9620
9668
  const r2 = runBin(n3.bin, n3.args, env);
9669
+ const why = r2.error?.code ?? r2.signal;
9670
+ if (why && `${r2.stdout}`.includes(n3.plugin)) {
9671
+ const cmd = [n3.bin, ...n3.args].join(" ");
9672
+ return { ...none, stopped: `${cmd} stopped before it finished (${why}); it names ${n3.plugin}, run ${cmd} in a terminal` };
9673
+ }
9621
9674
  if (r2.status !== 0) return none;
9622
9675
  if (n3.format === "json") return jsonState(n3, `${r2.stdout}`);
9623
- return n3.format === "extension" ? extensionState(n3, `${r2.stdout}${r2.stderr}`) : { state: tableState(n3, `${r2.stdout}`), workspaceOff: false };
9676
+ if (n3.format === "codex-json") return { state: codexJsonState(n3, `${r2.stdout}`), workspaceOff: false };
9677
+ return extensionState(n3, `${r2.stdout}${r2.stderr}`);
9624
9678
  }
9625
9679
  function nativeRow(row, n3) {
9626
9680
  return {
@@ -9634,18 +9688,12 @@ function nativeRow(row, n3) {
9634
9688
  skillInstall: { kind: "package", via: n3.skillsVia }
9635
9689
  };
9636
9690
  }
9637
- function trimChars(w, chars) {
9638
- let a2 = 0;
9639
- let b3 = w.length;
9640
- while (a2 < b3 && chars.includes(w.charAt(a2))) a2++;
9641
- while (b3 > a2 && chars.includes(w.charAt(b3 - 1))) b3--;
9642
- return w.slice(a2, b3);
9643
- }
9644
9691
  async function nativeResult(row, ctx, apply2) {
9645
9692
  const n3 = row.nativePlugin;
9646
- const { state, workspaceOff, hookGate } = nativeState(row, ctx.env);
9693
+ const { state, workspaceOff, hookGate, stopped } = nativeState(row, ctx.env);
9694
+ const bin = n3 ? hostBin(n3.bin, ctx.env).file : void 0;
9695
+ if (stopped) return { id: row.id, status: "FAIL", v1: [], changes: [], checks: [], bin, reason: stopped };
9647
9696
  if (!n3 || state === void 0) return void 0;
9648
- const bin = hostBin(n3.bin, ctx.env).file;
9649
9697
  if (state === "disabled") {
9650
9698
  if (!n3.enable) return void 0;
9651
9699
  return {
@@ -11,5 +11,5 @@
11
11
  }
12
12
  },
13
13
  "name": "context-mode",
14
- "version": "2.1.4"
14
+ "version": "2.1.5"
15
15
  }
@@ -11,5 +11,5 @@
11
11
  }
12
12
  },
13
13
  "name": "context-mode",
14
- "version": "2.1.4"
14
+ "version": "2.1.5"
15
15
  }