context-mode 2.0.1 → 2.1.0

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
@@ -90,7 +90,7 @@ var require_src = __commonJS({
90
90
  import { spawn as spawn4 } from "node:child_process";
91
91
  import { readFileSync as readFileSync12, realpathSync as realpathSync9 } from "node:fs";
92
92
  import path14 from "node:path";
93
- import { fileURLToPath as fileURLToPath2 } from "node:url";
93
+ import { fileURLToPath as fileURLToPath3 } from "node:url";
94
94
 
95
95
  // src/core/contracts/constants.ts
96
96
  var SERVER_KEY = "context-mode";
@@ -408,8 +408,8 @@ var DB_SIBLING_SUFFIXES = Object.freeze(["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]);
408
408
  var UPGRADE_HOST_COMMAND = Object.freeze({
409
409
  "claude-code": "claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",
410
410
  codex: "rewrite config.toml's [mcp_servers.context-mode*] block to the v2 entry, then restart Codex",
411
- gemini: "gemini extensions install https://github.com/mksglu/context-mode --ref release --auto-update",
412
- qwen: "qwen extensions install https://github.com/mksglu/context-mode --ref release --auto-update"
411
+ gemini: "gemini extensions install https://github.com/mksglu/context-mode --auto-update",
412
+ qwen: "qwen extensions install https://github.com/mksglu/context-mode --auto-update"
413
413
  });
414
414
  var V1_SCRIPT_NAMES = Object.freeze([
415
415
  "afteragentresponse.mjs",
@@ -469,6 +469,7 @@ var HOOKS_KEY = "hooks";
469
469
  var STATUS_LINE_KEY = "statusLine";
470
470
  var PI_PACKAGES_KEY = "packages";
471
471
  var OPENCODE_PLUGIN_KEY = "plugin";
472
+ var OPENCODE_NPM_SPEC_PREFIX = `${SERVER_KEY}@`;
472
473
  var V1_DATA_DIR_NAME = "context-mode";
473
474
  var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
474
475
  var V1_SESSIONS_DIR_NAME = "sessions";
@@ -542,6 +543,7 @@ var DOCTOR_DOCS_LABEL = "Docs: ";
542
543
  var DOCTOR_REPORT_LINE = "Report file: ";
543
544
  var DOCTOR_GH_LINE = "File it: ";
544
545
  var DOCTOR_URL_LINE = "Or open: ";
546
+ var DOCTOR_RULES_LINE = "Rules: ";
545
547
  var DOCTOR_GH_NEXT = " --";
546
548
  var DOCTOR_NOTE_PREFIXES = Object.freeze([
547
549
  DOCTOR_ENV_PREFIX,
@@ -549,10 +551,23 @@ var DOCTOR_NOTE_PREFIXES = Object.freeze([
549
551
  DOCTOR_REPORT_LINE,
550
552
  DOCTOR_GH_LINE,
551
553
  DOCTOR_GH_NEXT.trim(),
552
- DOCTOR_URL_LINE
554
+ DOCTOR_URL_LINE,
555
+ DOCTOR_RULES_LINE
553
556
  ]);
554
557
  var ISSUE_REPO_SLUG = "mksglu/context-mode";
555
558
  var ISSUE_FORM_FILE = "agent-report.yml";
559
+ var ISSUE_GUIDE_URL = `https://github.com/${ISSUE_REPO_SLUG}/blob/main/.github/AGENT_ISSUE.md`;
560
+ var ISSUE_AGENT_RULES = Object.freeze([
561
+ 'Search for the same problem first: `gh issue list -R mksglu/context-mode --state all --search "<check id or error>"`. When one matches, add your facts there as a comment.',
562
+ "File one bug per issue.",
563
+ "Call the `ctx_doctor` tool and paste its full output unchanged in the `ctx-report` field.",
564
+ "Give the versions: context-mode, the agent, the OS and arch, and Node.",
565
+ "Write numbered repro steps that start from a fresh project (`mktemp -d`) and the agent's own install command.",
566
+ "Give the exact command and its exact output in a fenced code block.",
567
+ "Say what you expected and what happened instead.",
568
+ "Name the source file and line when you found the cause.",
569
+ "Replace every secret with `<masked>` and the home folder with `~` before you send."
570
+ ]);
556
571
  var ISSUE_URL_MAX = 8e3;
557
572
  var ISSUE_FORM_HEADINGS = Object.freeze([
558
573
  "Summary",
@@ -579,16 +594,16 @@ var DOCTOR_ENV_NAMES = Object.freeze([
579
594
  var DOCTOR_PATH_TOOLS = Object.freeze(["node", "git", "sh"]);
580
595
  var DOCTOR_SECRET_WORDS = Object.freeze(["token", "secret", "password", "apikey", "api_key", "authorization", "bearer"]);
581
596
  var NATIVE_INSTALL = Object.freeze({
582
- "claude-code": ["claude plugin marketplace add mksglu/context-mode#release", "claude plugin install context-mode@context-mode"],
583
- codex: ["codex plugin marketplace add mksglu/context-mode@release", "codex plugin add context-mode@context-mode"],
584
- gemini: ["gemini extensions install https://github.com/mksglu/context-mode --ref release"],
585
- qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release"],
586
- opencode: ["opencode plugin add context-mode@next"],
587
- pi: ["pi install npm:context-mode@next"],
588
- "copilot-cli": ["npm i -g context-mode@next", "context-mode setup --agents copilot-cli"],
589
- vscode: ["npm i -g context-mode@next", "context-mode setup --agents vscode"],
590
- kiro: ["npm i -g context-mode@next", "context-mode setup --agents kiro"],
591
- zcode: ["npm i -g context-mode@next", "context-mode setup --agents zcode"]
597
+ "claude-code": ["claude plugin marketplace add mksglu/context-mode", "claude plugin install context-mode@context-mode"],
598
+ codex: ["codex plugin marketplace add mksglu/context-mode", "codex plugin add context-mode@context-mode"],
599
+ gemini: ["gemini extensions install https://github.com/mksglu/context-mode"],
600
+ qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode"],
601
+ opencode: ["opencode plugin add context-mode"],
602
+ pi: ["pi install npm:context-mode"],
603
+ "copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
604
+ vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
605
+ kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
606
+ zcode: ["npm i -g context-mode", "context-mode setup --agents zcode"]
592
607
  });
593
608
  var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
594
609
 
@@ -621,9 +636,28 @@ function outputOf(resp) {
621
636
  return err2 === "" ? out2 : out2 === "" ? err2 : out2 + "\n" + err2;
622
637
  }
623
638
  }
624
- if (typeof resp === "object" && resp !== null && isGrepContent(resp)) return resp.content;
639
+ if (typeof resp === "object" && resp !== null && !Array.isArray(resp)) {
640
+ const slot = textSlot(resp);
641
+ if (slot !== null) return slot.text;
642
+ }
625
643
  return JSON.stringify(resp);
626
644
  }
645
+ function textSlot(r2) {
646
+ const file = r2.file;
647
+ if (r2.type === "text" && typeof file === "object" && file !== null && typeof file.content === "string") {
648
+ return { text: file.content, put: (o2, output) => ({ ...o2, file: { ...o2.file, content: output } }) };
649
+ }
650
+ if (isGrepContent(r2)) return { text: r2.content, put: (o2, output) => ({ ...o2, content: output }) };
651
+ if (Array.isArray(r2.filenames) && r2.filenames.every((f2) => typeof f2 === "string")) {
652
+ return { text: r2.filenames.join("\n"), put: (o2, output) => ({ ...o2, filenames: output.split("\n") }) };
653
+ }
654
+ if (typeof r2.result === "string") return { text: r2.result, put: (o2, output) => ({ ...o2, result: output }) };
655
+ return null;
656
+ }
657
+ function isShellShape(resp) {
658
+ const r2 = resp;
659
+ return typeof r2.stdout === "string" || typeof r2.stderr === "string";
660
+ }
627
661
  function isGrepContent(resp) {
628
662
  const r2 = resp;
629
663
  return r2.mode === "content" && typeof r2.content === "string";
@@ -642,7 +676,10 @@ function readResult(resp) {
642
676
  const text2 = outputOf(resp);
643
677
  const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
644
678
  const info = { isError, bytes: Buffer.byteLength(text2), text: text2 };
645
- if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && isGrepContent(resp)) info.shape = resp;
679
+ if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && !isShellShape(resp)) {
680
+ if (textSlot(resp) !== null) info.shape = resp;
681
+ else info.keep = true;
682
+ }
646
683
  if (Array.isArray(resp)) {
647
684
  info.blocks = true;
648
685
  if (blocksOf(resp).keep) info.keep = true;
@@ -679,7 +716,9 @@ function decodeClaudeShape(raw, agent, ownPrefix, sources2) {
679
716
  }
680
717
  function replaceShape(ev, output) {
681
718
  if (ev.tool?.canonicalName === "Bash") return { stdout: output, stderr: "", interrupted: false };
682
- if (ev.result?.shape !== void 0) return { ...ev.result.shape, content: output };
719
+ const shape = ev.result?.shape;
720
+ const slot = shape === void 0 ? null : textSlot(shape);
721
+ if (shape !== void 0 && slot !== null) return slot.put(shape, output);
683
722
  if (ev.result?.blocks === true) return [{ type: "text", text: output }];
684
723
  return output;
685
724
  }
@@ -1072,7 +1111,8 @@ function encode6(ev, d, _extra) {
1072
1111
  }
1073
1112
 
1074
1113
  // src/adapters/kiro.ts
1075
- var TOOL_NAME_PREFIX7 = "mcp_context-mode_";
1114
+ var TOOL_NAME_PREFIX7 = "mcp_context_mode_";
1115
+ var LEGACY_TOOL_NAME_PREFIX = "mcp_context-mode_";
1076
1116
  var KIRO_EVENTS = {
1077
1117
  SessionStart: "SessionStart",
1078
1118
  agentSpawn: "SessionStart",
@@ -1084,6 +1124,7 @@ var KIRO_EVENTS = {
1084
1124
  PostToolUse: "PostToolUse",
1085
1125
  postToolUse: "PostToolUse"
1086
1126
  };
1127
+ var PROMPT_FIELD = "prompt";
1087
1128
  var PROMPT_ENV = "USER_PROMPT";
1088
1129
  var MCP_PREFIX3 = "mcp_";
1089
1130
  var SHELL_TOOL_NAMES4 = Object.freeze(["execute_bash", "execute_pwsh", "shell"]);
@@ -1092,6 +1133,7 @@ var MCP_SEP3 = "_";
1092
1133
  var KIRO_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
1093
1134
  function canonicalName5(name) {
1094
1135
  if (name.startsWith(TOOL_NAME_PREFIX7)) return name.slice(TOOL_NAME_PREFIX7.length);
1136
+ if (name.startsWith(LEGACY_TOOL_NAME_PREFIX)) return name.slice(LEGACY_TOOL_NAME_PREFIX.length);
1095
1137
  if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
1096
1138
  if (!name.startsWith(MCP_PREFIX3)) return name;
1097
1139
  const rest = name.slice(MCP_PREFIX3.length);
@@ -1112,7 +1154,8 @@ function decode7(raw) {
1112
1154
  const ev = { event, agent: "kiro", sessionId: String(p3.session_id ?? ""), cwd: String(p3.cwd ?? "") };
1113
1155
  if (event === "SessionStart" && typeof p3.source === "string" && KIRO_SOURCES[p3.source] !== void 0) ev.source = KIRO_SOURCES[p3.source];
1114
1156
  if (event === "UserPromptSubmit") {
1115
- const prompt = process.env[PROMPT_ENV];
1157
+ const field2 = p3[PROMPT_FIELD];
1158
+ const prompt = typeof field2 === "string" ? field2 : process.env[PROMPT_ENV];
1116
1159
  if (prompt !== void 0) ev.prompt = prompt;
1117
1160
  }
1118
1161
  if (event === "PreToolUse" || event === "PostToolUse") {
@@ -1124,7 +1167,7 @@ function decode7(raw) {
1124
1167
  return ev;
1125
1168
  }
1126
1169
  function encode7(ev, d, _extra) {
1127
- if (ev.event === "UserPromptSubmit") return { stdout: "", exitCode: 0 };
1170
+ if (ev.event === "UserPromptSubmit") return { stdout: d.kind === "hint" ? d.text : "", exitCode: 0 };
1128
1171
  switch (d.kind) {
1129
1172
  case "allow":
1130
1173
  return { stdout: "", exitCode: 0 };
@@ -1689,7 +1732,7 @@ Examples:
1689
1732
  // src/cli/commands.ts
1690
1733
  import { spawnSync as spawnSync5 } from "node:child_process";
1691
1734
  import { createHash as createHash2 } from "node:crypto";
1692
- import { existsSync as existsSync15, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
1735
+ import { existsSync as existsSync16, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
1693
1736
  import os from "node:os";
1694
1737
  import path13 from "node:path";
1695
1738
 
@@ -4605,14 +4648,29 @@ function copilotDirOf(env, home) {
4605
4648
  function kiroDirOf(env, home, platform = process.platform) {
4606
4649
  const p3 = platform === "win32" ? win32 : posix;
4607
4650
  const fallback = p3.join(home, ...AGENT_HOME_DIR.kiro);
4608
- const dir = env[KIRO_HOME_ENV];
4651
+ const dir = env[KIRO_HOME_ENV]?.trim();
4609
4652
  if (dir === void 0 || dir === "" || !p3.isAbsolute(dir)) return fallback;
4610
4653
  if (platform === "win32" && p3.parse(dir).root.length < 2) return fallback;
4611
4654
  const abs = p3.resolve(dir);
4612
- if (p3.dirname(abs) === abs) return fallback;
4613
- const up = p3.relative(abs, p3.resolve(home));
4655
+ const real2 = platform === process.platform ? realOrSelf : (x2) => x2;
4656
+ const target = real2(abs);
4657
+ if (p3.parse(target).root === target) return fallback;
4658
+ const up = p3.relative(target, real2(p3.resolve(home)));
4614
4659
  if (!p3.isAbsolute(up) && up.split(p3.sep)[0] !== "..") return fallback;
4615
- return dir;
4660
+ return abs;
4661
+ }
4662
+ function realOrSelf(path15) {
4663
+ const tail = [];
4664
+ for (let at = path15; ; ) {
4665
+ try {
4666
+ return join2(realpathSync.native(at), ...tail.reverse());
4667
+ } catch {
4668
+ const up = dirname2(at);
4669
+ if (up === at) return path15;
4670
+ tail.push(basename(at));
4671
+ at = up;
4672
+ }
4673
+ }
4616
4674
  }
4617
4675
  function claudeDirOf(env, home) {
4618
4676
  const dir = env[CLAUDE_CONFIG_DIR_ENV];
@@ -4643,8 +4701,8 @@ function ownMcpFileOf(agent, file, env, home) {
4643
4701
 
4644
4702
  // src/core/ops/doctor-issue.ts
4645
4703
  import { spawnSync } from "node:child_process";
4646
- import { closeSync, existsSync as existsSync7, fstatSync, mkdirSync as mkdirSync4, openSync, readFileSync as readFileSync4, readSync, realpathSync as realpathSync3, writeFileSync as writeFileSync2 } from "node:fs";
4647
- import { delimiter, join as join8 } from "node:path";
4704
+ import { closeSync, existsSync as existsSync8, fstatSync, mkdirSync as mkdirSync4, openSync, readFileSync as readFileSync4, readSync, realpathSync as realpathSync3, writeFileSync as writeFileSync2 } from "node:fs";
4705
+ import { delimiter, join as join9 } from "node:path";
4648
4706
 
4649
4707
  // src/core/hooks/fallback.ts
4650
4708
  import { join as join3, resolve as resolve2 } from "node:path";
@@ -4740,17 +4798,17 @@ CREATE VIRTUAL TABLE line_units USING fts5(
4740
4798
  var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
4741
4799
 
4742
4800
  // src/core/ops/doctor-config.ts
4743
- import { existsSync as existsSync6, readdirSync as readdirSync4 } from "node:fs";
4744
- import { join as join7 } from "node:path";
4801
+ import { existsSync as existsSync7, readdirSync as readdirSync4 } from "node:fs";
4802
+ import { join as join8 } from "node:path";
4745
4803
 
4746
4804
  // src/core/ops/detect-v1.ts
4747
- import { existsSync as existsSync4, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
4805
+ import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
4748
4806
  import { tmpdir } from "node:os";
4749
- import { join as join5 } from "node:path";
4807
+ import { join as join6 } from "node:path";
4750
4808
 
4751
4809
  // src/core/ops/host-config.ts
4752
- import { existsSync as existsSync3, readFileSync } from "node:fs";
4753
- import { dirname as dirname3, join as join4 } from "node:path";
4810
+ import { existsSync as existsSync4, readFileSync } from "node:fs";
4811
+ import { dirname as dirname4, join as join5 } from "node:path";
4754
4812
 
4755
4813
  // node_modules/eslint-visitor-keys/lib/visitor-keys.js
4756
4814
  var KEYS2 = {
@@ -6858,6 +6916,11 @@ function atomicWriteFile(file, text2, opts = {}) {
6858
6916
  }
6859
6917
  }
6860
6918
 
6919
+ // src/core/ops/bundle-dir.ts
6920
+ import { existsSync as existsSync3 } from "node:fs";
6921
+ import { dirname as dirname3, join as join4 } from "node:path";
6922
+ import { fileURLToPath } from "node:url";
6923
+
6861
6924
  // src/core/ops/host-text.ts
6862
6925
  var BOM_CODE = 65279;
6863
6926
  var CR_CODE = 13;
@@ -7359,7 +7422,7 @@ function flatCommands(events2, prefix) {
7359
7422
  var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
7360
7423
  var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep2) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep2) + sep2));
7361
7424
  function dataDir(dir, reason, out2) {
7362
- if (existsSync4(dir)) out2.push(finding(dir, "", reason));
7425
+ if (existsSync5(dir)) out2.push(finding(dir, "", reason));
7363
7426
  }
7364
7427
  function mcpEntry(file, doc, out2) {
7365
7428
  if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
@@ -7367,7 +7430,7 @@ function mcpEntry(file, doc, out2) {
7367
7430
  }
7368
7431
  }
7369
7432
  function claudeShapeSettings(agentHome, out2) {
7370
- const file = join5(agentHome, SETTINGS_FILE);
7433
+ const file = join6(agentHome, SETTINGS_FILE);
7371
7434
  const doc = readJson(file);
7372
7435
  for (const c3 of nestedCommands(doc)) {
7373
7436
  if (c3.command.includes(V1_CACHE_HEAL_NAME)) out2.push(finding(file, c3.path, V1_REASON.cacheHealHook));
@@ -7387,49 +7450,49 @@ function v1HookFile(file, out2) {
7387
7450
  function scanClaudeCode(home, agentHome, out2) {
7388
7451
  claudeShapeSettings(agentHome, out2);
7389
7452
  for (const ext of V1_CACHE_HEAL_EXTS) {
7390
- const file = join5(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
7391
- if (existsSync4(file)) out2.push(finding(file, "", V1_REASON.cacheHealFile));
7453
+ const file = join6(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
7454
+ if (existsSync5(file)) out2.push(finding(file, "", V1_REASON.cacheHealFile));
7392
7455
  }
7393
- const userFile = join5(home, CLAUDE_USER_CONFIG_FILE);
7456
+ const userFile = join6(home, CLAUDE_USER_CONFIG_FILE);
7394
7457
  mcpEntry(userFile, readJson(userFile), out2);
7395
- dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7458
+ dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7396
7459
  }
7397
7460
  function scanCodex(agentHome, out2) {
7398
- const hooksFile = join5(agentHome, HOOKS_JSON_FILE);
7461
+ const hooksFile = join6(agentHome, HOOKS_JSON_FILE);
7399
7462
  for (const c3 of nestedCommands(readJson(hooksFile))) {
7400
7463
  if (c3.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c3.command)) {
7401
7464
  out2.push(finding(hooksFile, c3.path, V1_REASON.codexHook));
7402
7465
  }
7403
7466
  }
7404
- const tomlFile = join5(agentHome, CONFIG_TOML_FILE);
7467
+ const tomlFile = join6(agentHome, CONFIG_TOML_FILE);
7405
7468
  const config = readTomlValue(tomlFile);
7406
7469
  for (const span of readTomlTables(tomlFile)) {
7407
7470
  if (span.path[0] !== V1_TOML_SECTION_ROOT || span.path[1] !== SERVER_KEY) continue;
7408
7471
  if (span.path.length === 2 && isV2McpTable(hostConfigValueAt(config, span.path))) continue;
7409
7472
  out2.push(finding(tomlFile, span.header.trim(), V1_REASON.codexToml));
7410
7473
  }
7411
- dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7474
+ dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7412
7475
  }
7413
7476
  function scanGemini(agentHome, out2) {
7414
- const file = join5(agentHome, SETTINGS_FILE);
7477
+ const file = join6(agentHome, SETTINGS_FILE);
7415
7478
  for (const c3 of nestedCommands(readJson(file))) {
7416
7479
  if (c3.command.includes(SERVER_KEY)) out2.push(finding(file, c3.path, V1_REASON.hook));
7417
7480
  }
7418
- dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
7481
+ dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
7419
7482
  }
7420
7483
  function scanVscode(agentHome, project, out2) {
7421
7484
  if (project !== void 0) {
7422
- v1HookFile(join5(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
7423
- const mcpFile = join5(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
7485
+ v1HookFile(join6(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
7486
+ const mcpFile = join6(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
7424
7487
  const doc = readJson(mcpFile);
7425
7488
  const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
7426
7489
  const entry2 = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
7427
7490
  if (isObj(entry2) && (entry2.command === V1_BIN_COMMAND || listOf(entry2.args).some((a2) => a2 === V1_BIN_COMMAND))) {
7428
7491
  out2.push(finding(mcpFile, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
7429
7492
  }
7430
- dataDir(join5(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
7493
+ dataDir(join6(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
7431
7494
  }
7432
- dataDir(join5(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
7495
+ dataDir(join6(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
7433
7496
  }
7434
7497
  function jsonFiles(dir) {
7435
7498
  try {
@@ -7439,10 +7502,10 @@ function jsonFiles(dir) {
7439
7502
  }
7440
7503
  }
7441
7504
  function scanKiro(agentHome, project, out2) {
7442
- const agentsDir = join5(agentHome, KIRO_AGENTS_DIR);
7443
- const defaultFile = join5(agentHome, ...KIRO_AGENT_FILE);
7505
+ const agentsDir = join6(agentHome, KIRO_AGENTS_DIR);
7506
+ const defaultFile = join6(agentHome, ...KIRO_AGENT_FILE);
7444
7507
  for (const name of jsonFiles(agentsDir)) {
7445
- const file = join5(agentsDir, name);
7508
+ const file = join6(agentsDir, name);
7446
7509
  const doc = readJson(file);
7447
7510
  if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
7448
7511
  out2.push(finding(file, "", V1_REASON.kiroAgentFile));
@@ -7453,25 +7516,25 @@ function scanKiro(agentHome, project, out2) {
7453
7516
  if (isV1Hook(c3.command)) out2.push(finding(file, c3.path, V1_REASON.kiroHook));
7454
7517
  }
7455
7518
  }
7456
- const steeringDocs = [join5(agentHome, ...KIRO_STEERING_FILE)];
7457
- if (project !== void 0) steeringDocs.push(join5(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
7519
+ const steeringDocs = [join6(agentHome, ...KIRO_STEERING_FILE)];
7520
+ if (project !== void 0) steeringDocs.push(join6(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
7458
7521
  for (const file of steeringDocs) {
7459
- if (existsSync4(file)) out2.push(finding(file, "", V1_REASON.kiroSteering));
7522
+ if (existsSync5(file)) out2.push(finding(file, "", V1_REASON.kiroSteering));
7460
7523
  }
7461
- dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7524
+ dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7462
7525
  }
7463
7526
  function scanPi(piAgentDir, agentHome, out2) {
7464
- const file = join5(piAgentDir, SETTINGS_FILE);
7527
+ const file = join6(piAgentDir, SETTINGS_FILE);
7465
7528
  const doc = readJson(file);
7466
7529
  listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
7467
7530
  const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
7468
7531
  if (spec === V1_PI_PACKAGE) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
7469
7532
  });
7470
- dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7533
+ dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7471
7534
  }
7472
7535
  function scanOpencode(agentHome, out2) {
7473
7536
  for (const name of OPENCODE_CONFIG_FILES) {
7474
- const file = join5(agentHome, name);
7537
+ const file = join6(agentHome, name);
7475
7538
  const doc = readJson(file);
7476
7539
  if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
7477
7540
  doc[OPENCODE_PLUGIN_KEY].forEach((spec, i2) => {
@@ -7481,13 +7544,13 @@ function scanOpencode(agentHome, out2) {
7481
7544
  }
7482
7545
  }
7483
7546
  function scanZcode(agentHome, out2) {
7484
- const configFile = join5(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
7547
+ const configFile = join6(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
7485
7548
  const config = readJson(configFile);
7486
7549
  const events2 = isObj(config) && isObj(config[HOOKS_KEY]) ? config[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
7487
7550
  for (const c3 of flatCommands(events2, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
7488
7551
  if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(configFile, c3.path, V1_REASON.zcodeHook));
7489
7552
  }
7490
- const hooksFile = join5(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
7553
+ const hooksFile = join6(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
7491
7554
  for (const c3 of nestedCommands(readJson(hooksFile))) {
7492
7555
  if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(hooksFile, c3.path, V1_REASON.zcodeHook));
7493
7556
  }
@@ -7511,14 +7574,14 @@ function firstTmpMatch(dir) {
7511
7574
  }
7512
7575
  }
7513
7576
  function scanAll(home, tmp, out2) {
7514
- const root = join5(home, DATA_ROOT.slice(1));
7515
- for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join5(root, name), V1_REASON.dataRoot, out2);
7577
+ const root = join6(home, DATA_ROOT.slice(1));
7578
+ for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join6(root, name), V1_REASON.dataRoot, out2);
7516
7579
  if (firstTmpMatch(tmp) !== null) out2.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
7517
7580
  }
7518
7581
  function detectV1(agent, home, scope = {}) {
7519
7582
  const out2 = [];
7520
7583
  const project = scope.project;
7521
- const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir : join5(home, ...AGENT_HOME_DIR[agent]);
7584
+ const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir : join6(home, ...AGENT_HOME_DIR[agent]);
7522
7585
  switch (agent) {
7523
7586
  case "claude-code":
7524
7587
  scanClaudeCode(home, agentHome, out2);
@@ -7531,11 +7594,11 @@ function detectV1(agent, home, scope = {}) {
7531
7594
  break;
7532
7595
  case "qwen":
7533
7596
  claudeShapeSettings(agentHome, out2);
7534
- dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7597
+ dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7535
7598
  break;
7536
7599
  case "copilot-cli":
7537
- v1HookFile(join5(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
7538
- dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7600
+ v1HookFile(join6(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
7601
+ dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7539
7602
  break;
7540
7603
  case "vscode":
7541
7604
  scanVscode(agentHome, project, out2);
@@ -7544,7 +7607,7 @@ function detectV1(agent, home, scope = {}) {
7544
7607
  scanKiro(agentHome, project, out2);
7545
7608
  break;
7546
7609
  case "pi":
7547
- scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join5(agentHome, PI_AGENT_DIR), agentHome, out2);
7610
+ scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join6(agentHome, PI_AGENT_DIR), agentHome, out2);
7548
7611
  break;
7549
7612
  // D-WIN-PIDIR-1: empty is unset
7550
7613
  case "opencode":
@@ -7559,9 +7622,9 @@ function detectV1(agent, home, scope = {}) {
7559
7622
  }
7560
7623
 
7561
7624
  // src/core/ops/plugin-root.ts
7562
- import { existsSync as existsSync5, readdirSync as readdirSync3, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
7563
- import { dirname as dirname4, isAbsolute, join as join6, sep } from "node:path";
7564
- import { fileURLToPath } from "node:url";
7625
+ import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
7626
+ import { dirname as dirname5, isAbsolute, join as join7, sep } from "node:path";
7627
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
7565
7628
 
7566
7629
  // src/core/ops/doctor-config.ts
7567
7630
  var [PART_MCP, PART_HOOKS, PART_TIMEOUT] = D3_PARTS;
@@ -7880,7 +7943,7 @@ function assertWritable(row, file) {
7880
7943
  }
7881
7944
 
7882
7945
  // src/setup/gemini-gate.ts
7883
- import { existsSync as existsSync8, readFileSync as readFileSync5 } from "node:fs";
7946
+ import { existsSync as existsSync9, readFileSync as readFileSync5 } from "node:fs";
7884
7947
  import path4 from "node:path";
7885
7948
  var GEMINI_DIR = ".gemini";
7886
7949
  var SETTINGS_FILE2 = "settings.json";
@@ -7894,7 +7957,7 @@ function systemSettingsPath(env) {
7894
7957
  return "/etc/gemini-cli/settings.json";
7895
7958
  }
7896
7959
  function load(file) {
7897
- if (!existsSync8(file)) return void 0;
7960
+ if (!existsSync9(file)) return void 0;
7898
7961
  try {
7899
7962
  return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync5(file, "utf8")), "jsonc") };
7900
7963
  } catch {
@@ -7928,7 +7991,7 @@ function geminiSettingsGate(env, home, cwd) {
7928
7991
  }
7929
7992
 
7930
7993
  // src/setup/zcode-gate.ts
7931
- import { existsSync as existsSync9, readFileSync as readFileSync6 } from "node:fs";
7994
+ import { existsSync as existsSync10, readFileSync as readFileSync6 } from "node:fs";
7932
7995
  import path5 from "node:path";
7933
7996
  var OWN_AGENT2 = "zcode";
7934
7997
  var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
@@ -8020,7 +8083,7 @@ function zcodeSchemaBad(doc) {
8020
8083
  }
8021
8084
  function zcodeConfigGate(home) {
8022
8085
  const file = path5.join(home, ".zcode", "cli", "config.json");
8023
- if (!existsSync9(file)) return void 0;
8086
+ if (!existsSync10(file)) return void 0;
8024
8087
  let doc;
8025
8088
  try {
8026
8089
  doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync6(file, "utf8")), "json");
@@ -8033,7 +8096,7 @@ function zcodeConfigGate(home) {
8033
8096
  }
8034
8097
 
8035
8098
  // src/setup/pi-gate.ts
8036
- import { existsSync as existsSync10, readFileSync as readFileSync7, realpathSync as realpathSync4 } from "node:fs";
8099
+ import { existsSync as existsSync11, readFileSync as readFileSync7, realpathSync as realpathSync4 } from "node:fs";
8037
8100
  import path6 from "node:path";
8038
8101
  var OWN_FILE = "pi/index.js";
8039
8102
  var EXTENSIONS_KEY = "extensions";
@@ -8042,7 +8105,7 @@ var TRUST_FILE = "trust.json";
8042
8105
  var ALWAYS = "always";
8043
8106
  var SOURCE_PREFIXES = ["npm:", "git:"];
8044
8107
  function load2(file) {
8045
- if (!existsSync10(file)) return void 0;
8108
+ if (!existsSync11(file)) return void 0;
8046
8109
  try {
8047
8110
  return { file, doc: parseHostConfig("pi", file, hostText(readFileSync7(file, "utf8")), "json") };
8048
8111
  } catch {
@@ -8133,7 +8196,7 @@ function piSettingsGate(env, home, pkgDir, cwd) {
8133
8196
  }
8134
8197
 
8135
8198
  // src/setup/vscode-gate.ts
8136
- import { existsSync as existsSync11, readFileSync as readFileSync8 } from "node:fs";
8199
+ import { existsSync as existsSync12, readFileSync as readFileSync8 } from "node:fs";
8137
8200
  import path7 from "node:path";
8138
8201
  var SETTINGS_FILE3 = "settings.json";
8139
8202
  var WORKSPACE_DIR = ".vscode";
@@ -8142,7 +8205,7 @@ var LOCATIONS_KEY = "chat.hookFilesLocations";
8142
8205
  var OWN_LOCATION = "~/.copilot/hooks";
8143
8206
  var MANAGED_KEYS = ["allowManagedHooksOnly", "strictPluginOnlyCustomization"];
8144
8207
  function load3(file) {
8145
- if (!existsSync11(file)) return void 0;
8208
+ if (!existsSync12(file)) return void 0;
8146
8209
  try {
8147
8210
  return { file, doc: parseHostConfig("vscode", file, hostText(readFileSync8(file, "utf8")), "jsonc") };
8148
8211
  } catch {
@@ -8184,7 +8247,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
8184
8247
  }
8185
8248
 
8186
8249
  // src/setup/qwen-gate.ts
8187
- import { existsSync as existsSync12, readFileSync as readFileSync9 } from "node:fs";
8250
+ import { existsSync as existsSync13, readFileSync as readFileSync9 } from "node:fs";
8188
8251
  import path8 from "node:path";
8189
8252
  var KEY = "disableAllHooks";
8190
8253
  var SETTINGS = "settings.json";
@@ -8200,7 +8263,7 @@ function settingsFiles(env, home, cwd, platform) {
8200
8263
  }
8201
8264
  function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
8202
8265
  for (const file of settingsFiles(env, home, cwd, platform)) {
8203
- if (!existsSync12(file)) continue;
8266
+ if (!existsSync13(file)) continue;
8204
8267
  let value;
8205
8268
  try {
8206
8269
  value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(readFileSync9(file, "utf8")), "jsonc"), [KEY]);
@@ -8214,7 +8277,7 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
8214
8277
 
8215
8278
  // src/setup/codex-trust.ts
8216
8279
  import { createHash } from "node:crypto";
8217
- import { existsSync as existsSync13, realpathSync as realpathSync5 } from "node:fs";
8280
+ import { existsSync as existsSync14, realpathSync as realpathSync5 } from "node:fs";
8218
8281
  import path10 from "node:path";
8219
8282
  import { spawn, spawnSync as spawnSync3 } from "node:child_process";
8220
8283
 
@@ -8305,6 +8368,7 @@ var isObj3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
8305
8368
  var TRUST_KEY = ["hooks", "state"];
8306
8369
  var CODEX_TRUST_PATH = TRUST_KEY.join(".") + ".";
8307
8370
  var HASH_FIELD = "trusted_hash";
8371
+ var CONTENT_HASH_FIELD = "trusted_content_hash";
8308
8372
  var HASH_PREFIX = "sha256:";
8309
8373
  function sortKeys(v) {
8310
8374
  if (Array.isArray(v)) return v.map(sortKeys);
@@ -8322,7 +8386,7 @@ function snake(name) {
8322
8386
  function realFile(file) {
8323
8387
  let dir = path10.resolve(file);
8324
8388
  const rest = [];
8325
- while (!existsSync13(dir) && path10.dirname(dir) !== dir) {
8389
+ while (!existsSync14(dir) && path10.dirname(dir) !== dir) {
8326
8390
  rest.unshift(path10.basename(dir));
8327
8391
  dir = path10.dirname(dir);
8328
8392
  }
@@ -8391,6 +8455,7 @@ var LIST_TIMEOUT_MS = 15e3;
8391
8455
  var EXIT_GRACE_MS = 5e3;
8392
8456
  var PLUGIN_SOURCE = "plugin";
8393
8457
  var TRUSTED = "trusted";
8458
+ var UNTRUSTED = "untrusted";
8394
8459
  function pluginHooksFromReply(m3, pluginId) {
8395
8460
  const out2 = [];
8396
8461
  if (!isObj3(m3) || !isObj3(m3.result) || !Array.isArray(m3.result.data)) return out2;
@@ -8400,7 +8465,8 @@ function pluginHooksFromReply(m3, pluginId) {
8400
8465
  if (!isObj3(h2) || h2.source !== PLUGIN_SOURCE || h2.pluginId !== pluginId) continue;
8401
8466
  if (typeof h2.key !== "string" || typeof h2.currentHash !== "string") continue;
8402
8467
  if (out2.some((x2) => x2.key === h2.key)) continue;
8403
- out2.push({ key: h2.key, hash: h2.currentHash, trusted: h2.trustStatus === TRUSTED });
8468
+ const status = typeof h2.trustStatus === "string" ? h2.trustStatus : UNTRUSTED;
8469
+ out2.push({ key: h2.key, hash: h2.currentHash, trusted: status === TRUSTED, status });
8404
8470
  }
8405
8471
  }
8406
8472
  return out2;
@@ -8497,15 +8563,30 @@ function hookHashOf(currentHash) {
8497
8563
  const cut = currentHash.indexOf(HASH_PART_SEP);
8498
8564
  return cut < 0 ? currentHash : currentHash.slice(0, cut);
8499
8565
  }
8500
- function pluginTrustEntries(hooks) {
8501
- return hooks.filter((h2) => !h2.trusted).map((h2) => [[...TRUST_KEY, h2.key], { [HASH_FIELD]: hookHashOf(h2.hash) }]);
8566
+ function contentHashOf(currentHash) {
8567
+ const cut = currentHash.indexOf(HASH_PART_SEP);
8568
+ return cut < 0 ? void 0 : currentHash.slice(cut + 1);
8569
+ }
8570
+ function pluginTrustEntries(hooks, doc) {
8571
+ const states = isObj3(doc) && isObj3(doc.hooks) && isObj3(doc.hooks.state) ? doc.hooks.state : {};
8572
+ return hooks.filter((h2) => !h2.trusted).map((h2) => {
8573
+ const old = isObj3(states[h2.key]) ? states[h2.key] : {};
8574
+ const content = contentHashOf(h2.hash);
8575
+ const row = { ...old, [HASH_FIELD]: hookHashOf(h2.hash) };
8576
+ if (content !== void 0) row[CONTENT_HASH_FIELD] = content;
8577
+ return [[...TRUST_KEY, h2.key], row];
8578
+ });
8502
8579
  }
8503
8580
  var CODEX_PLUGIN_ID = `${SERVER_KEY}@${SERVER_KEY}`;
8504
8581
  var CODEX_UNTRUSTED_FIX = "run: context-mode setup";
8505
8582
  function untrustedPluginHooksDetail(hooks) {
8506
8583
  const bad = hooks.filter((h2) => !h2.trusted);
8507
8584
  if (!bad.length) return void 0;
8508
- return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks untrusted, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
8585
+ const counts = /* @__PURE__ */ new Map();
8586
+ for (const h2 of bad) counts.set(h2.status, (counts.get(h2.status) ?? 0) + 1);
8587
+ const words = [...counts].sort((a2, b3) => b3[1] - a2[1] || (a2[0] < b3[0] ? -1 : 1));
8588
+ const state = words.length === 1 ? words[0][0] : `${words.map(([w]) => w).join(" or ")} (${words.map(([w, n3]) => `${n3} ${w}`).join(", ")})`;
8589
+ return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks ${state}, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
8509
8590
  }
8510
8591
 
8511
8592
  // src/setup/copilot-hooks.ts
@@ -8605,7 +8686,7 @@ function listCopilotHooks(env, file, cwd) {
8605
8686
 
8606
8687
  // src/setup/engine.ts
8607
8688
  import { spawn as spawn3, spawnSync as spawnSync4 } from "node:child_process";
8608
- import { closeSync as closeSync2, existsSync as existsSync14, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync2, readFileSync as readFileSync10, readSync as readSync2, readdirSync as readdirSync5, realpathSync as realpathSync7, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
8689
+ import { closeSync as closeSync2, existsSync as existsSync15, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync2, readFileSync as readFileSync10, readSync as readSync2, readdirSync as readdirSync5, realpathSync as realpathSync7, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
8609
8690
  import { tmpdir as tmpdir2 } from "node:os";
8610
8691
  import path12 from "node:path";
8611
8692
 
@@ -8703,7 +8784,7 @@ function isNativeBinary(file) {
8703
8784
  function owningPackage(dir) {
8704
8785
  for (let d = dir; ; d = path12.dirname(d)) {
8705
8786
  const f2 = path12.join(d, "package.json");
8706
- if (existsSync14(f2)) {
8787
+ if (existsSync15(f2)) {
8707
8788
  try {
8708
8789
  return String(JSON.parse(hostText(readFileSync10(f2, "utf8"))).name);
8709
8790
  } catch {
@@ -8721,7 +8802,7 @@ function hostBin(bin, env, platform = process.platform) {
8721
8802
  for (const dir of pathEntries(get("PATH") ?? "", platform)) {
8722
8803
  const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
8723
8804
  for (const f2 of [own2, ...real2.extra.map((p3) => path12.join(dir, ...p3))]) {
8724
- if (!f2 || !existsSync14(f2) || !statSync2(f2).isFile()) continue;
8805
+ if (!f2 || !existsSync15(f2) || !statSync2(f2).isFile()) continue;
8725
8806
  const file = realpathSync7(f2);
8726
8807
  if (isNativeBinary(file) || owningPackage(path12.dirname(file)) === real2.pkg) return { file, shims };
8727
8808
  shims.push(f2);
@@ -8738,10 +8819,10 @@ function runBin(bin, args, env, input, timeout = VERIFY_TIMEOUT_MS) {
8738
8819
  return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout });
8739
8820
  }
8740
8821
  function readOr(file) {
8741
- return existsSync14(file) ? hostText(readFileSync10(file, "utf8")) : void 0;
8822
+ return existsSync15(file) ? hostText(readFileSync10(file, "utf8")) : void 0;
8742
8823
  }
8743
8824
  function readRaw(file) {
8744
- return existsSync14(file) ? readFileSync10(file, "utf8") : void 0;
8825
+ return existsSync15(file) ? readFileSync10(file, "utf8") : void 0;
8745
8826
  }
8746
8827
  var atomicWrite = atomicWriteFile;
8747
8828
  function pidAlive(pid) {
@@ -8886,7 +8967,7 @@ function isNativeSpec(e) {
8886
8967
  function isStaleOwnPlugin(e, entry2) {
8887
8968
  if (typeof e !== "string" || e === entry2 || !path12.isAbsolute(e)) return false;
8888
8969
  if (e === path12.join(entry2, ...OPENCODE_PLUGIN_PATH)) return true;
8889
- if (existsSync14(e)) return false;
8970
+ if (existsSync15(e)) return false;
8890
8971
  const seg = e.split("\\").join("/").split("/");
8891
8972
  const n3 = seg.length;
8892
8973
  if (n3 >= 3 && seg[n3 - 1] === "plugin.js" && seg[n3 - 2] === "opencode" && seg[n3 - 3] === "context-mode") return true;
@@ -8950,7 +9031,7 @@ function planSkills(row, edits) {
8950
9031
  const s = row.skillInstall;
8951
9032
  if (s.kind !== "dir") return;
8952
9033
  for (const f2 of s.files) {
8953
- if (!existsSync14(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
9034
+ if (!existsSync15(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
8954
9035
  const after = renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes);
8955
9036
  const before = readRaw(f2.file);
8956
9037
  if (before !== after) edits.push({ plain: true, file: f2.file, before, after, changes: [{ file: f2.file, path: f2.name, before: before === void 0 ? null : "old", after: "SKILL.md" }] });
@@ -9010,17 +9091,48 @@ function opencodeMajor(bin, env) {
9010
9091
  const digits = text2.split("").filter((c3) => c3 >= "0" && c3 <= "9" || c3 === ".").join("");
9011
9092
  return Number(digits.split(".")[0]);
9012
9093
  }
9013
- function opencodeListArgs(bin, env) {
9014
- return opencodeMajor(bin, env) >= 2 ? ["mcp", "list", "--standalone"] : ["mcp", "list", "--pure"];
9094
+ function opencodeListArgs(major) {
9095
+ return major >= 2 ? ["mcp", "list", "--standalone"] : ["mcp", "list", "--pure"];
9096
+ }
9097
+ var OC2_CONFIG_ARGS = ["debug", "config", "--standalone"];
9098
+ function opencode2ListCheck(bin, env) {
9099
+ const r2 = runBin(bin, OC2_CONFIG_ARGS, env);
9100
+ const what = `${bin} ${OC2_CONFIG_ARGS.join(" ")}`;
9101
+ let docs;
9102
+ try {
9103
+ docs = JSON.parse(`${r2.stdout}`);
9104
+ } catch {
9105
+ docs = void 0;
9106
+ }
9107
+ if (r2.status !== 0) return { name: "list", ok: false, detail: `${what} exited ${r2.status}: ${`${r2.stderr}`.trim().split("\n")[0] ?? ""}` };
9108
+ if (!Array.isArray(docs)) return { name: "list", ok: false, detail: `${what} printed no config list: ${`${r2.stdout}`.trim().split("\n")[0] ?? ""}` };
9109
+ const listed = docs.some((d) => isObj5(d) && isObj5(d.info) && isObj5(d.info.mcp) && isObj5(d.info.mcp.servers) && isObj5(d.info.mcp.servers[SERVER_KEY]));
9110
+ const read = docs.filter(isObj5).map((d) => d.path).filter((p3) => typeof p3 === "string");
9111
+ return { name: "list", ok: listed, detail: listed ? void 0 : `${what} does not load mcp.servers.${SERVER_KEY}; it read: ${read.join(", ") || "no config"}` };
9112
+ }
9113
+ var HOST_BROKEN = {
9114
+ copilot: { text: "no platform package found", fix: "npm install -g @github/copilot" }
9115
+ };
9116
+ var HOST_BROKEN_PREFIX = "host broken: run ";
9117
+ function hostBroken(bin, out2) {
9118
+ const b3 = HOST_BROKEN[bin];
9119
+ if (!b3 || !out2.includes(b3.text)) return void 0;
9120
+ return `${HOST_BROKEN_PREFIX}${b3.fix} (${out2.trim().split("\n")[0]})`;
9015
9121
  }
9016
9122
  function listState(row, env) {
9017
- const l0 = row.listCommand;
9123
+ let l0 = row.listCommand;
9018
9124
  if (!l0 || !hostBin(l0.bin, env).file) return { status: void 0 };
9019
- const l2 = row.id === "opencode" ? { bin: l0.bin, args: opencodeListArgs(l0.bin, env) } : l0;
9125
+ if (row.id === "opencode") {
9126
+ const major = opencodeMajor(l0.bin, env);
9127
+ if (major >= 2) return { check: opencode2ListCheck(l0.bin, env), status: void 0 };
9128
+ l0 = { bin: l0.bin, args: opencodeListArgs(major) };
9129
+ }
9130
+ const l2 = l0;
9020
9131
  const r2 = runBin(l2.bin, l2.args, env);
9021
- const ok = r2.status === 0 && `${r2.stdout}${r2.stderr}`.includes("context-mode");
9132
+ const out2 = `${r2.stdout}${r2.stderr}`;
9133
+ const ok = r2.status === 0 && out2.includes("context-mode");
9022
9134
  const check = { name: "list", ok, detail: ok ? void 0 : `${l2.bin} ${l2.args.join(" ")} does not list context-mode` };
9023
- return { check, status: r2.status === 0 ? statusOf(row, `${r2.stdout}`) : void 0 };
9135
+ return { check, status: r2.status === 0 ? statusOf(row, `${r2.stdout}`) : void 0, broken: r2.status === 0 ? void 0 : hostBroken(l2.bin, out2) };
9024
9136
  }
9025
9137
  var DISABLE_ALL_HOOKS = "disableAllHooks";
9026
9138
  var SETTINGS_FILES = ["settings.json", "settings.local.json"];
@@ -9199,7 +9311,7 @@ function hookRegisteredCheck(row, env, list2) {
9199
9311
  if (trust && edits.every((e) => e.file === trust && e.changes.every((c3) => isTrust(row, c3)))) return { name: "hook-registered", ok: false, detail: `${h2.file}: the context-mode hooks are not trusted in ${trust}; re-run setup` };
9200
9312
  const issue = h2.kind === "plugin-list" ? pluginListIssue(h2) : h2.kind === "file" && row.id === "kiro" ? kiroDisabledIssue(h2) : void 0;
9201
9313
  const oc2 = issue === void 0 && row.id === "opencode" && h2.kind === "plugin-list" && hostBin("opencode", env).file !== void 0 && opencodeMajor("opencode", env) >= 2;
9202
- return { name: "hook-registered", ok: false, detail: issue ?? `${h2.file} lacks the context-mode hook entry${oc2 ? "; run: opencode plugin add context-mode@next" : ""}` };
9314
+ return { name: "hook-registered", ok: false, detail: issue ?? `${h2.file} lacks the context-mode hook entry${oc2 ? "; run: opencode plugin add context-mode" : ""}` };
9203
9315
  }
9204
9316
  function hookRunsCheck(row, env) {
9205
9317
  const root = mkdtempSync(path12.join(tmpdir2(), "cm-doctor-runs-"));
@@ -9225,7 +9337,7 @@ var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
9225
9337
  var NOT_SEEN_LINE = "not seen yet, run one tool call";
9226
9338
  function hookSeenCheck(row, home) {
9227
9339
  const base = path12.join(home, STATE_DIR, PROJECTS_DIR_NAME);
9228
- const dirs = existsSync14(base) ? readdirSync5(base) : [];
9340
+ const dirs = existsSync15(base) ? readdirSync5(base) : [];
9229
9341
  let sqlite;
9230
9342
  try {
9231
9343
  sqlite = process.getBuiltinModule("node:sqlite");
@@ -9234,7 +9346,7 @@ function hookSeenCheck(row, home) {
9234
9346
  }
9235
9347
  for (const d of dirs) {
9236
9348
  const file = path12.join(base, d, DB_FILE_NAME);
9237
- if (!sqlite || !existsSync14(file)) continue;
9349
+ if (!sqlite || !existsSync15(file)) continue;
9238
9350
  let db;
9239
9351
  try {
9240
9352
  db = new sqlite.DatabaseSync(file, { readOnly: true });
@@ -9249,10 +9361,10 @@ function hookSeenCheck(row, home) {
9249
9361
  function skillsCheck(row, pkgDir) {
9250
9362
  const s = row.skillInstall;
9251
9363
  if (s.kind === "package") {
9252
- const miss = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE)).filter((f2) => !existsSync14(f2));
9364
+ const miss = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE)).filter((f2) => !existsSync15(f2));
9253
9365
  return { name: "skills", ok: miss.length === 0, detail: miss.length ? `missing ${miss.join(", ")}` : void 0 };
9254
9366
  }
9255
- const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync14(f2.src) ? renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes) : void 0));
9367
+ const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync15(f2.src) ? renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes) : void 0));
9256
9368
  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 };
9257
9369
  }
9258
9370
  var PLUGIN_ENABLED = "enabled";
@@ -9358,7 +9470,7 @@ function trustPluginHooks(row, ctx, apply2, hooks) {
9358
9470
  const text2 = readOr(file);
9359
9471
  let edit;
9360
9472
  try {
9361
- edit = editHostConfigText(row.id, file, text2 ?? "", "toml", pluginTrustEntries(hooks));
9473
+ edit = editHostConfigText(row.id, file, text2 ?? "", "toml", pluginTrustEntries(hooks, text2 ? parseHostConfig(row.id, file, text2, "toml") : void 0));
9362
9474
  } catch (e) {
9363
9475
  if (e instanceof CtxError) throw new Error(parseFail(row, file));
9364
9476
  throw e;
@@ -9536,14 +9648,14 @@ function agentHomeDir(id, ctx) {
9536
9648
  return path12.join(ctx.home, ...AGENT_HOME_DIR[id]);
9537
9649
  }
9538
9650
  function detectAgents(reg, ctx) {
9539
- return reg.filter((r2) => existsSync14(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
9651
+ return reg.filter((r2) => existsSync15(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
9540
9652
  }
9541
9653
  async function runSetup(opts) {
9542
9654
  const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
9543
9655
  const runId = opts.runId ?? (/* @__PURE__ */ new Date()).toISOString().split(":").join("-").split(".").join("-");
9544
9656
  const reg = buildRegistry(ctx);
9545
9657
  for (const f2 of ["server.mjs", "hook.mjs"]) {
9546
- if (!existsSync14(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
9658
+ if (!existsSync15(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
9547
9659
  }
9548
9660
  const ids = opts.agents ?? detectAgents(reg, ctx);
9549
9661
  const root = path12.join(ctx.home, STATE_DIR);
@@ -9591,7 +9703,8 @@ async function setupRow(row, ctx, run, dryRun) {
9591
9703
  if (!row.config && !row.cli) return { ...res, status: "SKIPPED", reason: `${row.id}: no setup path in the registry` };
9592
9704
  let plan;
9593
9705
  try {
9594
- const ls = needsBin ? listState(row, ctx.env) : { status: void 0, check: void 0 };
9706
+ const ls = needsBin ? listState(row, ctx.env) : { status: void 0, check: void 0, broken: void 0 };
9707
+ if (ls.broken) return { ...res, status: "SKIPPED", reason: ls.broken };
9595
9708
  const listed = ls.check?.ok === true;
9596
9709
  plan = planRow(row, listed, copyCheck(row, ctx.pkgDir)?.ok === false, ctx.env, listed && ls.status === "disabled");
9597
9710
  } catch (e) {
@@ -9624,6 +9737,8 @@ async function setupRow(row, ctx, run, dryRun) {
9624
9737
  if (bad.length) throw new Error(bad.map((c3) => `${c3.name}: ${c3.detail}`).join("; "));
9625
9738
  } catch (e) {
9626
9739
  run.rollback(row.id, ctx.env);
9740
+ const broken = row.cli ? hostBroken(row.cli.bin, e.message) : void 0;
9741
+ if (broken) return { ...res, status: "SKIPPED", reason: broken };
9627
9742
  return { ...res, status: "FAIL", reason: e.message, rolledBack: true };
9628
9743
  }
9629
9744
  return res;
@@ -9634,7 +9749,7 @@ async function runDoctor(opts) {
9634
9749
  const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
9635
9750
  const reg = buildRegistry(ctx);
9636
9751
  for (const f2 of ["server.mjs", "hook.mjs"]) {
9637
- if (!existsSync14(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
9752
+ if (!existsSync15(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
9638
9753
  }
9639
9754
  const ids = opts.agents ?? detectAgents(reg, ctx);
9640
9755
  const run = new Run(path12.join(ctx.home, STATE_DIR), "doctor");
@@ -9678,7 +9793,7 @@ function notSetUpReason(row, res, env) {
9678
9793
  const h2 = row.hookInstall;
9679
9794
  const missing = row.id === "opencode" && h2.kind === "plugin-list" && res.changes.some((c3) => c3.path === h2.key[0]);
9680
9795
  const oc2 = missing && hostBin("opencode", env).file !== void 0 && opencodeMajor("opencode", env) >= 2;
9681
- return oc2 ? `${NOT_SET_UP_REASON}, or run: opencode plugin add context-mode@next` : NOT_SET_UP_REASON;
9796
+ return oc2 ? `${NOT_SET_UP_REASON}, or run: opencode plugin add context-mode` : NOT_SET_UP_REASON;
9682
9797
  }
9683
9798
  function hasPluginIssue(row) {
9684
9799
  const h2 = row.hookInstall;
@@ -9702,12 +9817,12 @@ function runRemove(opts) {
9702
9817
  const env = opts.env ?? process.env;
9703
9818
  const root = path12.join(opts.home, STATE_DIR);
9704
9819
  const base = path12.join(root, BACKUP_DIR);
9705
- if (!existsSync14(base)) return { exitCode: 0, restored: 0 };
9820
+ if (!existsSync15(base)) return { exitCode: 0, restored: 0 };
9706
9821
  const held = takeLock(root, "remove");
9707
9822
  if (held) return { exitCode: 1, restored: 0, error: held };
9708
9823
  let restored = 0;
9709
9824
  try {
9710
- const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) => existsSync14(path12.join(d, MANIFEST))).sort().reverse();
9825
+ const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) => existsSync15(path12.join(d, MANIFEST))).sort().reverse();
9711
9826
  for (const dir of runs) {
9712
9827
  const m3 = JSON.parse(readFileSync10(path12.join(dir, MANIFEST), "utf8"));
9713
9828
  undo(dir, m3.entries, env);
@@ -10171,7 +10286,7 @@ async function upgrade(ui) {
10171
10286
  }
10172
10287
  const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
10173
10288
  const cli = path13.join(root, "context-mode", "cli.mjs");
10174
- if (!root || !existsSync15(cli)) {
10289
+ if (!root || !existsSync16(cli)) {
10175
10290
  err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
10176
10291
  return EXIT_FAIL;
10177
10292
  }
@@ -10266,7 +10381,7 @@ function route(argv, version) {
10266
10381
  ` };
10267
10382
  }
10268
10383
  function main() {
10269
- const dir = path14.dirname(realpathSync9(fileURLToPath2(import.meta.url)));
10384
+ const dir = path14.dirname(realpathSync9(fileURLToPath3(import.meta.url)));
10270
10385
  let version = "";
10271
10386
  try {
10272
10387
  version = String(JSON.parse(readFileSync12(path14.join(dir, PACKAGE_FILE), "utf8")).version);
@@ -10305,7 +10420,7 @@ function main() {
10305
10420
  process.exitCode = signal === "SIGINT" ? EXIT_SIGINT2 : code ?? EXIT_FAIL2;
10306
10421
  });
10307
10422
  }
10308
- if (isEntry(import.meta.main, process.argv[1], fileURLToPath2(import.meta.url))) main();
10423
+ if (isEntry(import.meta.main, process.argv[1], fileURLToPath3(import.meta.url))) main();
10309
10424
  export {
10310
10425
  HELP2 as HELP,
10311
10426
  V1_PLATFORM_AGENT,