context-mode 2.0.2 → 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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +87 -91
- package/SHA256SUMS +15 -15
- package/cli.mjs +203 -112
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +84 -84
- package/opencode/plugin.js +285 -209
- package/package.json +1 -1
- package/pi/index.js +333 -257
- package/qwen-extension.json +1 -1
- package/run.mjs +35 -16
- package/search.mjs +35 -16
- package/server.mjs +318 -242
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
|
|
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 --
|
|
412
|
-
qwen: "qwen extensions install https://github.com/mksglu/context-mode --
|
|
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
|
|
583
|
-
codex: ["codex plugin marketplace add mksglu/context-mode
|
|
584
|
-
gemini: ["gemini extensions install https://github.com/mksglu/context-mode
|
|
585
|
-
qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode
|
|
586
|
-
opencode: ["opencode plugin add context-mode
|
|
587
|
-
pi: ["pi install npm:context-mode
|
|
588
|
-
"copilot-cli": ["npm i -g context-mode
|
|
589
|
-
vscode: ["npm i -g context-mode
|
|
590
|
-
kiro: ["npm i -g context-mode
|
|
591
|
-
zcode: ["npm i -g context-mode
|
|
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
|
|
|
@@ -1096,7 +1111,8 @@ function encode6(ev, d, _extra) {
|
|
|
1096
1111
|
}
|
|
1097
1112
|
|
|
1098
1113
|
// src/adapters/kiro.ts
|
|
1099
|
-
var TOOL_NAME_PREFIX7 = "
|
|
1114
|
+
var TOOL_NAME_PREFIX7 = "mcp_context_mode_";
|
|
1115
|
+
var LEGACY_TOOL_NAME_PREFIX = "mcp_context-mode_";
|
|
1100
1116
|
var KIRO_EVENTS = {
|
|
1101
1117
|
SessionStart: "SessionStart",
|
|
1102
1118
|
agentSpawn: "SessionStart",
|
|
@@ -1108,6 +1124,7 @@ var KIRO_EVENTS = {
|
|
|
1108
1124
|
PostToolUse: "PostToolUse",
|
|
1109
1125
|
postToolUse: "PostToolUse"
|
|
1110
1126
|
};
|
|
1127
|
+
var PROMPT_FIELD = "prompt";
|
|
1111
1128
|
var PROMPT_ENV = "USER_PROMPT";
|
|
1112
1129
|
var MCP_PREFIX3 = "mcp_";
|
|
1113
1130
|
var SHELL_TOOL_NAMES4 = Object.freeze(["execute_bash", "execute_pwsh", "shell"]);
|
|
@@ -1116,6 +1133,7 @@ var MCP_SEP3 = "_";
|
|
|
1116
1133
|
var KIRO_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1117
1134
|
function canonicalName5(name) {
|
|
1118
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);
|
|
1119
1137
|
if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
|
|
1120
1138
|
if (!name.startsWith(MCP_PREFIX3)) return name;
|
|
1121
1139
|
const rest = name.slice(MCP_PREFIX3.length);
|
|
@@ -1136,7 +1154,8 @@ function decode7(raw) {
|
|
|
1136
1154
|
const ev = { event, agent: "kiro", sessionId: String(p3.session_id ?? ""), cwd: String(p3.cwd ?? "") };
|
|
1137
1155
|
if (event === "SessionStart" && typeof p3.source === "string" && KIRO_SOURCES[p3.source] !== void 0) ev.source = KIRO_SOURCES[p3.source];
|
|
1138
1156
|
if (event === "UserPromptSubmit") {
|
|
1139
|
-
const
|
|
1157
|
+
const field2 = p3[PROMPT_FIELD];
|
|
1158
|
+
const prompt = typeof field2 === "string" ? field2 : process.env[PROMPT_ENV];
|
|
1140
1159
|
if (prompt !== void 0) ev.prompt = prompt;
|
|
1141
1160
|
}
|
|
1142
1161
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
@@ -1148,7 +1167,7 @@ function decode7(raw) {
|
|
|
1148
1167
|
return ev;
|
|
1149
1168
|
}
|
|
1150
1169
|
function encode7(ev, d, _extra) {
|
|
1151
|
-
if (ev.event === "UserPromptSubmit") return { stdout: "", exitCode: 0 };
|
|
1170
|
+
if (ev.event === "UserPromptSubmit") return { stdout: d.kind === "hint" ? d.text : "", exitCode: 0 };
|
|
1152
1171
|
switch (d.kind) {
|
|
1153
1172
|
case "allow":
|
|
1154
1173
|
return { stdout: "", exitCode: 0 };
|
|
@@ -1713,7 +1732,7 @@ Examples:
|
|
|
1713
1732
|
// src/cli/commands.ts
|
|
1714
1733
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
1715
1734
|
import { createHash as createHash2 } from "node:crypto";
|
|
1716
|
-
import { existsSync as
|
|
1735
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1717
1736
|
import os from "node:os";
|
|
1718
1737
|
import path13 from "node:path";
|
|
1719
1738
|
|
|
@@ -4629,14 +4648,29 @@ function copilotDirOf(env, home) {
|
|
|
4629
4648
|
function kiroDirOf(env, home, platform = process.platform) {
|
|
4630
4649
|
const p3 = platform === "win32" ? win32 : posix;
|
|
4631
4650
|
const fallback = p3.join(home, ...AGENT_HOME_DIR.kiro);
|
|
4632
|
-
const dir = env[KIRO_HOME_ENV];
|
|
4651
|
+
const dir = env[KIRO_HOME_ENV]?.trim();
|
|
4633
4652
|
if (dir === void 0 || dir === "" || !p3.isAbsolute(dir)) return fallback;
|
|
4634
4653
|
if (platform === "win32" && p3.parse(dir).root.length < 2) return fallback;
|
|
4635
4654
|
const abs = p3.resolve(dir);
|
|
4636
|
-
|
|
4637
|
-
const
|
|
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)));
|
|
4638
4659
|
if (!p3.isAbsolute(up) && up.split(p3.sep)[0] !== "..") return fallback;
|
|
4639
|
-
return
|
|
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
|
+
}
|
|
4640
4674
|
}
|
|
4641
4675
|
function claudeDirOf(env, home) {
|
|
4642
4676
|
const dir = env[CLAUDE_CONFIG_DIR_ENV];
|
|
@@ -4667,8 +4701,8 @@ function ownMcpFileOf(agent, file, env, home) {
|
|
|
4667
4701
|
|
|
4668
4702
|
// src/core/ops/doctor-issue.ts
|
|
4669
4703
|
import { spawnSync } from "node:child_process";
|
|
4670
|
-
import { closeSync, existsSync as
|
|
4671
|
-
import { delimiter, join as
|
|
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";
|
|
4672
4706
|
|
|
4673
4707
|
// src/core/hooks/fallback.ts
|
|
4674
4708
|
import { join as join3, resolve as resolve2 } from "node:path";
|
|
@@ -4764,17 +4798,17 @@ CREATE VIRTUAL TABLE line_units USING fts5(
|
|
|
4764
4798
|
var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
4765
4799
|
|
|
4766
4800
|
// src/core/ops/doctor-config.ts
|
|
4767
|
-
import { existsSync as
|
|
4768
|
-
import { join as
|
|
4801
|
+
import { existsSync as existsSync7, readdirSync as readdirSync4 } from "node:fs";
|
|
4802
|
+
import { join as join8 } from "node:path";
|
|
4769
4803
|
|
|
4770
4804
|
// src/core/ops/detect-v1.ts
|
|
4771
|
-
import { existsSync as
|
|
4805
|
+
import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
4772
4806
|
import { tmpdir } from "node:os";
|
|
4773
|
-
import { join as
|
|
4807
|
+
import { join as join6 } from "node:path";
|
|
4774
4808
|
|
|
4775
4809
|
// src/core/ops/host-config.ts
|
|
4776
|
-
import { existsSync as
|
|
4777
|
-
import { dirname as
|
|
4810
|
+
import { existsSync as existsSync4, readFileSync } from "node:fs";
|
|
4811
|
+
import { dirname as dirname4, join as join5 } from "node:path";
|
|
4778
4812
|
|
|
4779
4813
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
4780
4814
|
var KEYS2 = {
|
|
@@ -6882,6 +6916,11 @@ function atomicWriteFile(file, text2, opts = {}) {
|
|
|
6882
6916
|
}
|
|
6883
6917
|
}
|
|
6884
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
|
+
|
|
6885
6924
|
// src/core/ops/host-text.ts
|
|
6886
6925
|
var BOM_CODE = 65279;
|
|
6887
6926
|
var CR_CODE = 13;
|
|
@@ -7383,7 +7422,7 @@ function flatCommands(events2, prefix) {
|
|
|
7383
7422
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
7384
7423
|
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep2) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep2) + sep2));
|
|
7385
7424
|
function dataDir(dir, reason, out2) {
|
|
7386
|
-
if (
|
|
7425
|
+
if (existsSync5(dir)) out2.push(finding(dir, "", reason));
|
|
7387
7426
|
}
|
|
7388
7427
|
function mcpEntry(file, doc, out2) {
|
|
7389
7428
|
if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
|
|
@@ -7391,7 +7430,7 @@ function mcpEntry(file, doc, out2) {
|
|
|
7391
7430
|
}
|
|
7392
7431
|
}
|
|
7393
7432
|
function claudeShapeSettings(agentHome, out2) {
|
|
7394
|
-
const file =
|
|
7433
|
+
const file = join6(agentHome, SETTINGS_FILE);
|
|
7395
7434
|
const doc = readJson(file);
|
|
7396
7435
|
for (const c3 of nestedCommands(doc)) {
|
|
7397
7436
|
if (c3.command.includes(V1_CACHE_HEAL_NAME)) out2.push(finding(file, c3.path, V1_REASON.cacheHealHook));
|
|
@@ -7411,49 +7450,49 @@ function v1HookFile(file, out2) {
|
|
|
7411
7450
|
function scanClaudeCode(home, agentHome, out2) {
|
|
7412
7451
|
claudeShapeSettings(agentHome, out2);
|
|
7413
7452
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
7414
|
-
const file =
|
|
7415
|
-
if (
|
|
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));
|
|
7416
7455
|
}
|
|
7417
|
-
const userFile =
|
|
7456
|
+
const userFile = join6(home, CLAUDE_USER_CONFIG_FILE);
|
|
7418
7457
|
mcpEntry(userFile, readJson(userFile), out2);
|
|
7419
|
-
dataDir(
|
|
7458
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7420
7459
|
}
|
|
7421
7460
|
function scanCodex(agentHome, out2) {
|
|
7422
|
-
const hooksFile =
|
|
7461
|
+
const hooksFile = join6(agentHome, HOOKS_JSON_FILE);
|
|
7423
7462
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7424
7463
|
if (c3.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c3.command)) {
|
|
7425
7464
|
out2.push(finding(hooksFile, c3.path, V1_REASON.codexHook));
|
|
7426
7465
|
}
|
|
7427
7466
|
}
|
|
7428
|
-
const tomlFile =
|
|
7467
|
+
const tomlFile = join6(agentHome, CONFIG_TOML_FILE);
|
|
7429
7468
|
const config = readTomlValue(tomlFile);
|
|
7430
7469
|
for (const span of readTomlTables(tomlFile)) {
|
|
7431
7470
|
if (span.path[0] !== V1_TOML_SECTION_ROOT || span.path[1] !== SERVER_KEY) continue;
|
|
7432
7471
|
if (span.path.length === 2 && isV2McpTable(hostConfigValueAt(config, span.path))) continue;
|
|
7433
7472
|
out2.push(finding(tomlFile, span.header.trim(), V1_REASON.codexToml));
|
|
7434
7473
|
}
|
|
7435
|
-
dataDir(
|
|
7474
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7436
7475
|
}
|
|
7437
7476
|
function scanGemini(agentHome, out2) {
|
|
7438
|
-
const file =
|
|
7477
|
+
const file = join6(agentHome, SETTINGS_FILE);
|
|
7439
7478
|
for (const c3 of nestedCommands(readJson(file))) {
|
|
7440
7479
|
if (c3.command.includes(SERVER_KEY)) out2.push(finding(file, c3.path, V1_REASON.hook));
|
|
7441
7480
|
}
|
|
7442
|
-
dataDir(
|
|
7481
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
|
|
7443
7482
|
}
|
|
7444
7483
|
function scanVscode(agentHome, project, out2) {
|
|
7445
7484
|
if (project !== void 0) {
|
|
7446
|
-
v1HookFile(
|
|
7447
|
-
const mcpFile =
|
|
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);
|
|
7448
7487
|
const doc = readJson(mcpFile);
|
|
7449
7488
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
7450
7489
|
const entry2 = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
7451
7490
|
if (isObj(entry2) && (entry2.command === V1_BIN_COMMAND || listOf(entry2.args).some((a2) => a2 === V1_BIN_COMMAND))) {
|
|
7452
7491
|
out2.push(finding(mcpFile, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
7453
7492
|
}
|
|
7454
|
-
dataDir(
|
|
7493
|
+
dataDir(join6(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7455
7494
|
}
|
|
7456
|
-
dataDir(
|
|
7495
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7457
7496
|
}
|
|
7458
7497
|
function jsonFiles(dir) {
|
|
7459
7498
|
try {
|
|
@@ -7463,10 +7502,10 @@ function jsonFiles(dir) {
|
|
|
7463
7502
|
}
|
|
7464
7503
|
}
|
|
7465
7504
|
function scanKiro(agentHome, project, out2) {
|
|
7466
|
-
const agentsDir =
|
|
7467
|
-
const defaultFile =
|
|
7505
|
+
const agentsDir = join6(agentHome, KIRO_AGENTS_DIR);
|
|
7506
|
+
const defaultFile = join6(agentHome, ...KIRO_AGENT_FILE);
|
|
7468
7507
|
for (const name of jsonFiles(agentsDir)) {
|
|
7469
|
-
const file =
|
|
7508
|
+
const file = join6(agentsDir, name);
|
|
7470
7509
|
const doc = readJson(file);
|
|
7471
7510
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
7472
7511
|
out2.push(finding(file, "", V1_REASON.kiroAgentFile));
|
|
@@ -7477,25 +7516,25 @@ function scanKiro(agentHome, project, out2) {
|
|
|
7477
7516
|
if (isV1Hook(c3.command)) out2.push(finding(file, c3.path, V1_REASON.kiroHook));
|
|
7478
7517
|
}
|
|
7479
7518
|
}
|
|
7480
|
-
const steeringDocs = [
|
|
7481
|
-
if (project !== void 0) steeringDocs.push(
|
|
7519
|
+
const steeringDocs = [join6(agentHome, ...KIRO_STEERING_FILE)];
|
|
7520
|
+
if (project !== void 0) steeringDocs.push(join6(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
7482
7521
|
for (const file of steeringDocs) {
|
|
7483
|
-
if (
|
|
7522
|
+
if (existsSync5(file)) out2.push(finding(file, "", V1_REASON.kiroSteering));
|
|
7484
7523
|
}
|
|
7485
|
-
dataDir(
|
|
7524
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7486
7525
|
}
|
|
7487
7526
|
function scanPi(piAgentDir, agentHome, out2) {
|
|
7488
|
-
const file =
|
|
7527
|
+
const file = join6(piAgentDir, SETTINGS_FILE);
|
|
7489
7528
|
const doc = readJson(file);
|
|
7490
7529
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
|
|
7491
7530
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
7492
7531
|
if (spec === V1_PI_PACKAGE) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
|
|
7493
7532
|
});
|
|
7494
|
-
dataDir(
|
|
7533
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7495
7534
|
}
|
|
7496
7535
|
function scanOpencode(agentHome, out2) {
|
|
7497
7536
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
7498
|
-
const file =
|
|
7537
|
+
const file = join6(agentHome, name);
|
|
7499
7538
|
const doc = readJson(file);
|
|
7500
7539
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
7501
7540
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i2) => {
|
|
@@ -7505,13 +7544,13 @@ function scanOpencode(agentHome, out2) {
|
|
|
7505
7544
|
}
|
|
7506
7545
|
}
|
|
7507
7546
|
function scanZcode(agentHome, out2) {
|
|
7508
|
-
const configFile =
|
|
7547
|
+
const configFile = join6(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
7509
7548
|
const config = readJson(configFile);
|
|
7510
7549
|
const events2 = isObj(config) && isObj(config[HOOKS_KEY]) ? config[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
7511
7550
|
for (const c3 of flatCommands(events2, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
7512
7551
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(configFile, c3.path, V1_REASON.zcodeHook));
|
|
7513
7552
|
}
|
|
7514
|
-
const hooksFile =
|
|
7553
|
+
const hooksFile = join6(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
7515
7554
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7516
7555
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(hooksFile, c3.path, V1_REASON.zcodeHook));
|
|
7517
7556
|
}
|
|
@@ -7535,14 +7574,14 @@ function firstTmpMatch(dir) {
|
|
|
7535
7574
|
}
|
|
7536
7575
|
}
|
|
7537
7576
|
function scanAll(home, tmp, out2) {
|
|
7538
|
-
const root =
|
|
7539
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
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);
|
|
7540
7579
|
if (firstTmpMatch(tmp) !== null) out2.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
7541
7580
|
}
|
|
7542
7581
|
function detectV1(agent, home, scope = {}) {
|
|
7543
7582
|
const out2 = [];
|
|
7544
7583
|
const project = scope.project;
|
|
7545
|
-
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 :
|
|
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]);
|
|
7546
7585
|
switch (agent) {
|
|
7547
7586
|
case "claude-code":
|
|
7548
7587
|
scanClaudeCode(home, agentHome, out2);
|
|
@@ -7555,11 +7594,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7555
7594
|
break;
|
|
7556
7595
|
case "qwen":
|
|
7557
7596
|
claudeShapeSettings(agentHome, out2);
|
|
7558
|
-
dataDir(
|
|
7597
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7559
7598
|
break;
|
|
7560
7599
|
case "copilot-cli":
|
|
7561
|
-
v1HookFile(
|
|
7562
|
-
dataDir(
|
|
7600
|
+
v1HookFile(join6(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7601
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7563
7602
|
break;
|
|
7564
7603
|
case "vscode":
|
|
7565
7604
|
scanVscode(agentHome, project, out2);
|
|
@@ -7568,7 +7607,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7568
7607
|
scanKiro(agentHome, project, out2);
|
|
7569
7608
|
break;
|
|
7570
7609
|
case "pi":
|
|
7571
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
7610
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join6(agentHome, PI_AGENT_DIR), agentHome, out2);
|
|
7572
7611
|
break;
|
|
7573
7612
|
// D-WIN-PIDIR-1: empty is unset
|
|
7574
7613
|
case "opencode":
|
|
@@ -7583,9 +7622,9 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7583
7622
|
}
|
|
7584
7623
|
|
|
7585
7624
|
// src/core/ops/plugin-root.ts
|
|
7586
|
-
import { existsSync as
|
|
7587
|
-
import { dirname as
|
|
7588
|
-
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";
|
|
7589
7628
|
|
|
7590
7629
|
// src/core/ops/doctor-config.ts
|
|
7591
7630
|
var [PART_MCP, PART_HOOKS, PART_TIMEOUT] = D3_PARTS;
|
|
@@ -7904,7 +7943,7 @@ function assertWritable(row, file) {
|
|
|
7904
7943
|
}
|
|
7905
7944
|
|
|
7906
7945
|
// src/setup/gemini-gate.ts
|
|
7907
|
-
import { existsSync as
|
|
7946
|
+
import { existsSync as existsSync9, readFileSync as readFileSync5 } from "node:fs";
|
|
7908
7947
|
import path4 from "node:path";
|
|
7909
7948
|
var GEMINI_DIR = ".gemini";
|
|
7910
7949
|
var SETTINGS_FILE2 = "settings.json";
|
|
@@ -7918,7 +7957,7 @@ function systemSettingsPath(env) {
|
|
|
7918
7957
|
return "/etc/gemini-cli/settings.json";
|
|
7919
7958
|
}
|
|
7920
7959
|
function load(file) {
|
|
7921
|
-
if (!
|
|
7960
|
+
if (!existsSync9(file)) return void 0;
|
|
7922
7961
|
try {
|
|
7923
7962
|
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync5(file, "utf8")), "jsonc") };
|
|
7924
7963
|
} catch {
|
|
@@ -7952,7 +7991,7 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
7952
7991
|
}
|
|
7953
7992
|
|
|
7954
7993
|
// src/setup/zcode-gate.ts
|
|
7955
|
-
import { existsSync as
|
|
7994
|
+
import { existsSync as existsSync10, readFileSync as readFileSync6 } from "node:fs";
|
|
7956
7995
|
import path5 from "node:path";
|
|
7957
7996
|
var OWN_AGENT2 = "zcode";
|
|
7958
7997
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
@@ -8044,7 +8083,7 @@ function zcodeSchemaBad(doc) {
|
|
|
8044
8083
|
}
|
|
8045
8084
|
function zcodeConfigGate(home) {
|
|
8046
8085
|
const file = path5.join(home, ".zcode", "cli", "config.json");
|
|
8047
|
-
if (!
|
|
8086
|
+
if (!existsSync10(file)) return void 0;
|
|
8048
8087
|
let doc;
|
|
8049
8088
|
try {
|
|
8050
8089
|
doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync6(file, "utf8")), "json");
|
|
@@ -8057,7 +8096,7 @@ function zcodeConfigGate(home) {
|
|
|
8057
8096
|
}
|
|
8058
8097
|
|
|
8059
8098
|
// src/setup/pi-gate.ts
|
|
8060
|
-
import { existsSync as
|
|
8099
|
+
import { existsSync as existsSync11, readFileSync as readFileSync7, realpathSync as realpathSync4 } from "node:fs";
|
|
8061
8100
|
import path6 from "node:path";
|
|
8062
8101
|
var OWN_FILE = "pi/index.js";
|
|
8063
8102
|
var EXTENSIONS_KEY = "extensions";
|
|
@@ -8066,7 +8105,7 @@ var TRUST_FILE = "trust.json";
|
|
|
8066
8105
|
var ALWAYS = "always";
|
|
8067
8106
|
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
8068
8107
|
function load2(file) {
|
|
8069
|
-
if (!
|
|
8108
|
+
if (!existsSync11(file)) return void 0;
|
|
8070
8109
|
try {
|
|
8071
8110
|
return { file, doc: parseHostConfig("pi", file, hostText(readFileSync7(file, "utf8")), "json") };
|
|
8072
8111
|
} catch {
|
|
@@ -8157,7 +8196,7 @@ function piSettingsGate(env, home, pkgDir, cwd) {
|
|
|
8157
8196
|
}
|
|
8158
8197
|
|
|
8159
8198
|
// src/setup/vscode-gate.ts
|
|
8160
|
-
import { existsSync as
|
|
8199
|
+
import { existsSync as existsSync12, readFileSync as readFileSync8 } from "node:fs";
|
|
8161
8200
|
import path7 from "node:path";
|
|
8162
8201
|
var SETTINGS_FILE3 = "settings.json";
|
|
8163
8202
|
var WORKSPACE_DIR = ".vscode";
|
|
@@ -8166,7 +8205,7 @@ var LOCATIONS_KEY = "chat.hookFilesLocations";
|
|
|
8166
8205
|
var OWN_LOCATION = "~/.copilot/hooks";
|
|
8167
8206
|
var MANAGED_KEYS = ["allowManagedHooksOnly", "strictPluginOnlyCustomization"];
|
|
8168
8207
|
function load3(file) {
|
|
8169
|
-
if (!
|
|
8208
|
+
if (!existsSync12(file)) return void 0;
|
|
8170
8209
|
try {
|
|
8171
8210
|
return { file, doc: parseHostConfig("vscode", file, hostText(readFileSync8(file, "utf8")), "jsonc") };
|
|
8172
8211
|
} catch {
|
|
@@ -8208,7 +8247,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
|
|
|
8208
8247
|
}
|
|
8209
8248
|
|
|
8210
8249
|
// src/setup/qwen-gate.ts
|
|
8211
|
-
import { existsSync as
|
|
8250
|
+
import { existsSync as existsSync13, readFileSync as readFileSync9 } from "node:fs";
|
|
8212
8251
|
import path8 from "node:path";
|
|
8213
8252
|
var KEY = "disableAllHooks";
|
|
8214
8253
|
var SETTINGS = "settings.json";
|
|
@@ -8224,7 +8263,7 @@ function settingsFiles(env, home, cwd, platform) {
|
|
|
8224
8263
|
}
|
|
8225
8264
|
function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
|
|
8226
8265
|
for (const file of settingsFiles(env, home, cwd, platform)) {
|
|
8227
|
-
if (!
|
|
8266
|
+
if (!existsSync13(file)) continue;
|
|
8228
8267
|
let value;
|
|
8229
8268
|
try {
|
|
8230
8269
|
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(readFileSync9(file, "utf8")), "jsonc"), [KEY]);
|
|
@@ -8238,7 +8277,7 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
|
|
|
8238
8277
|
|
|
8239
8278
|
// src/setup/codex-trust.ts
|
|
8240
8279
|
import { createHash } from "node:crypto";
|
|
8241
|
-
import { existsSync as
|
|
8280
|
+
import { existsSync as existsSync14, realpathSync as realpathSync5 } from "node:fs";
|
|
8242
8281
|
import path10 from "node:path";
|
|
8243
8282
|
import { spawn, spawnSync as spawnSync3 } from "node:child_process";
|
|
8244
8283
|
|
|
@@ -8329,6 +8368,7 @@ var isObj3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
|
8329
8368
|
var TRUST_KEY = ["hooks", "state"];
|
|
8330
8369
|
var CODEX_TRUST_PATH = TRUST_KEY.join(".") + ".";
|
|
8331
8370
|
var HASH_FIELD = "trusted_hash";
|
|
8371
|
+
var CONTENT_HASH_FIELD = "trusted_content_hash";
|
|
8332
8372
|
var HASH_PREFIX = "sha256:";
|
|
8333
8373
|
function sortKeys(v) {
|
|
8334
8374
|
if (Array.isArray(v)) return v.map(sortKeys);
|
|
@@ -8346,7 +8386,7 @@ function snake(name) {
|
|
|
8346
8386
|
function realFile(file) {
|
|
8347
8387
|
let dir = path10.resolve(file);
|
|
8348
8388
|
const rest = [];
|
|
8349
|
-
while (!
|
|
8389
|
+
while (!existsSync14(dir) && path10.dirname(dir) !== dir) {
|
|
8350
8390
|
rest.unshift(path10.basename(dir));
|
|
8351
8391
|
dir = path10.dirname(dir);
|
|
8352
8392
|
}
|
|
@@ -8415,6 +8455,7 @@ var LIST_TIMEOUT_MS = 15e3;
|
|
|
8415
8455
|
var EXIT_GRACE_MS = 5e3;
|
|
8416
8456
|
var PLUGIN_SOURCE = "plugin";
|
|
8417
8457
|
var TRUSTED = "trusted";
|
|
8458
|
+
var UNTRUSTED = "untrusted";
|
|
8418
8459
|
function pluginHooksFromReply(m3, pluginId) {
|
|
8419
8460
|
const out2 = [];
|
|
8420
8461
|
if (!isObj3(m3) || !isObj3(m3.result) || !Array.isArray(m3.result.data)) return out2;
|
|
@@ -8424,7 +8465,8 @@ function pluginHooksFromReply(m3, pluginId) {
|
|
|
8424
8465
|
if (!isObj3(h2) || h2.source !== PLUGIN_SOURCE || h2.pluginId !== pluginId) continue;
|
|
8425
8466
|
if (typeof h2.key !== "string" || typeof h2.currentHash !== "string") continue;
|
|
8426
8467
|
if (out2.some((x2) => x2.key === h2.key)) continue;
|
|
8427
|
-
|
|
8468
|
+
const status = typeof h2.trustStatus === "string" ? h2.trustStatus : UNTRUSTED;
|
|
8469
|
+
out2.push({ key: h2.key, hash: h2.currentHash, trusted: status === TRUSTED, status });
|
|
8428
8470
|
}
|
|
8429
8471
|
}
|
|
8430
8472
|
return out2;
|
|
@@ -8521,15 +8563,30 @@ function hookHashOf(currentHash) {
|
|
|
8521
8563
|
const cut = currentHash.indexOf(HASH_PART_SEP);
|
|
8522
8564
|
return cut < 0 ? currentHash : currentHash.slice(0, cut);
|
|
8523
8565
|
}
|
|
8524
|
-
function
|
|
8525
|
-
|
|
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
|
+
});
|
|
8526
8579
|
}
|
|
8527
8580
|
var CODEX_PLUGIN_ID = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
8528
8581
|
var CODEX_UNTRUSTED_FIX = "run: context-mode setup";
|
|
8529
8582
|
function untrustedPluginHooksDetail(hooks) {
|
|
8530
8583
|
const bad = hooks.filter((h2) => !h2.trusted);
|
|
8531
8584
|
if (!bad.length) return void 0;
|
|
8532
|
-
|
|
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}`;
|
|
8533
8590
|
}
|
|
8534
8591
|
|
|
8535
8592
|
// src/setup/copilot-hooks.ts
|
|
@@ -8629,7 +8686,7 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
8629
8686
|
|
|
8630
8687
|
// src/setup/engine.ts
|
|
8631
8688
|
import { spawn as spawn3, spawnSync as spawnSync4 } from "node:child_process";
|
|
8632
|
-
import { closeSync as closeSync2, existsSync as
|
|
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";
|
|
8633
8690
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8634
8691
|
import path12 from "node:path";
|
|
8635
8692
|
|
|
@@ -8727,7 +8784,7 @@ function isNativeBinary(file) {
|
|
|
8727
8784
|
function owningPackage(dir) {
|
|
8728
8785
|
for (let d = dir; ; d = path12.dirname(d)) {
|
|
8729
8786
|
const f2 = path12.join(d, "package.json");
|
|
8730
|
-
if (
|
|
8787
|
+
if (existsSync15(f2)) {
|
|
8731
8788
|
try {
|
|
8732
8789
|
return String(JSON.parse(hostText(readFileSync10(f2, "utf8"))).name);
|
|
8733
8790
|
} catch {
|
|
@@ -8745,7 +8802,7 @@ function hostBin(bin, env, platform = process.platform) {
|
|
|
8745
8802
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
8746
8803
|
const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
|
|
8747
8804
|
for (const f2 of [own2, ...real2.extra.map((p3) => path12.join(dir, ...p3))]) {
|
|
8748
|
-
if (!f2 || !
|
|
8805
|
+
if (!f2 || !existsSync15(f2) || !statSync2(f2).isFile()) continue;
|
|
8749
8806
|
const file = realpathSync7(f2);
|
|
8750
8807
|
if (isNativeBinary(file) || owningPackage(path12.dirname(file)) === real2.pkg) return { file, shims };
|
|
8751
8808
|
shims.push(f2);
|
|
@@ -8762,10 +8819,10 @@ function runBin(bin, args, env, input, timeout = VERIFY_TIMEOUT_MS) {
|
|
|
8762
8819
|
return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout });
|
|
8763
8820
|
}
|
|
8764
8821
|
function readOr(file) {
|
|
8765
|
-
return
|
|
8822
|
+
return existsSync15(file) ? hostText(readFileSync10(file, "utf8")) : void 0;
|
|
8766
8823
|
}
|
|
8767
8824
|
function readRaw(file) {
|
|
8768
|
-
return
|
|
8825
|
+
return existsSync15(file) ? readFileSync10(file, "utf8") : void 0;
|
|
8769
8826
|
}
|
|
8770
8827
|
var atomicWrite = atomicWriteFile;
|
|
8771
8828
|
function pidAlive(pid) {
|
|
@@ -8910,7 +8967,7 @@ function isNativeSpec(e) {
|
|
|
8910
8967
|
function isStaleOwnPlugin(e, entry2) {
|
|
8911
8968
|
if (typeof e !== "string" || e === entry2 || !path12.isAbsolute(e)) return false;
|
|
8912
8969
|
if (e === path12.join(entry2, ...OPENCODE_PLUGIN_PATH)) return true;
|
|
8913
|
-
if (
|
|
8970
|
+
if (existsSync15(e)) return false;
|
|
8914
8971
|
const seg = e.split("\\").join("/").split("/");
|
|
8915
8972
|
const n3 = seg.length;
|
|
8916
8973
|
if (n3 >= 3 && seg[n3 - 1] === "plugin.js" && seg[n3 - 2] === "opencode" && seg[n3 - 3] === "context-mode") return true;
|
|
@@ -8974,7 +9031,7 @@ function planSkills(row, edits) {
|
|
|
8974
9031
|
const s = row.skillInstall;
|
|
8975
9032
|
if (s.kind !== "dir") return;
|
|
8976
9033
|
for (const f2 of s.files) {
|
|
8977
|
-
if (!
|
|
9034
|
+
if (!existsSync15(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
|
|
8978
9035
|
const after = renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes);
|
|
8979
9036
|
const before = readRaw(f2.file);
|
|
8980
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" }] });
|
|
@@ -9034,17 +9091,48 @@ function opencodeMajor(bin, env) {
|
|
|
9034
9091
|
const digits = text2.split("").filter((c3) => c3 >= "0" && c3 <= "9" || c3 === ".").join("");
|
|
9035
9092
|
return Number(digits.split(".")[0]);
|
|
9036
9093
|
}
|
|
9037
|
-
function opencodeListArgs(
|
|
9038
|
-
return
|
|
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]})`;
|
|
9039
9121
|
}
|
|
9040
9122
|
function listState(row, env) {
|
|
9041
|
-
|
|
9123
|
+
let l0 = row.listCommand;
|
|
9042
9124
|
if (!l0 || !hostBin(l0.bin, env).file) return { status: void 0 };
|
|
9043
|
-
|
|
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;
|
|
9044
9131
|
const r2 = runBin(l2.bin, l2.args, env);
|
|
9045
|
-
const
|
|
9132
|
+
const out2 = `${r2.stdout}${r2.stderr}`;
|
|
9133
|
+
const ok = r2.status === 0 && out2.includes("context-mode");
|
|
9046
9134
|
const check = { name: "list", ok, detail: ok ? void 0 : `${l2.bin} ${l2.args.join(" ")} does not list context-mode` };
|
|
9047
|
-
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) };
|
|
9048
9136
|
}
|
|
9049
9137
|
var DISABLE_ALL_HOOKS = "disableAllHooks";
|
|
9050
9138
|
var SETTINGS_FILES = ["settings.json", "settings.local.json"];
|
|
@@ -9223,7 +9311,7 @@ function hookRegisteredCheck(row, env, list2) {
|
|
|
9223
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` };
|
|
9224
9312
|
const issue = h2.kind === "plugin-list" ? pluginListIssue(h2) : h2.kind === "file" && row.id === "kiro" ? kiroDisabledIssue(h2) : void 0;
|
|
9225
9313
|
const oc2 = issue === void 0 && row.id === "opencode" && h2.kind === "plugin-list" && hostBin("opencode", env).file !== void 0 && opencodeMajor("opencode", env) >= 2;
|
|
9226
|
-
return { name: "hook-registered", ok: false, detail: issue ?? `${h2.file} lacks the context-mode hook entry${oc2 ? "; run: opencode plugin add context-mode
|
|
9314
|
+
return { name: "hook-registered", ok: false, detail: issue ?? `${h2.file} lacks the context-mode hook entry${oc2 ? "; run: opencode plugin add context-mode" : ""}` };
|
|
9227
9315
|
}
|
|
9228
9316
|
function hookRunsCheck(row, env) {
|
|
9229
9317
|
const root = mkdtempSync(path12.join(tmpdir2(), "cm-doctor-runs-"));
|
|
@@ -9249,7 +9337,7 @@ var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
|
|
|
9249
9337
|
var NOT_SEEN_LINE = "not seen yet, run one tool call";
|
|
9250
9338
|
function hookSeenCheck(row, home) {
|
|
9251
9339
|
const base = path12.join(home, STATE_DIR, PROJECTS_DIR_NAME);
|
|
9252
|
-
const dirs =
|
|
9340
|
+
const dirs = existsSync15(base) ? readdirSync5(base) : [];
|
|
9253
9341
|
let sqlite;
|
|
9254
9342
|
try {
|
|
9255
9343
|
sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -9258,7 +9346,7 @@ function hookSeenCheck(row, home) {
|
|
|
9258
9346
|
}
|
|
9259
9347
|
for (const d of dirs) {
|
|
9260
9348
|
const file = path12.join(base, d, DB_FILE_NAME);
|
|
9261
|
-
if (!sqlite || !
|
|
9349
|
+
if (!sqlite || !existsSync15(file)) continue;
|
|
9262
9350
|
let db;
|
|
9263
9351
|
try {
|
|
9264
9352
|
db = new sqlite.DatabaseSync(file, { readOnly: true });
|
|
@@ -9273,10 +9361,10 @@ function hookSeenCheck(row, home) {
|
|
|
9273
9361
|
function skillsCheck(row, pkgDir) {
|
|
9274
9362
|
const s = row.skillInstall;
|
|
9275
9363
|
if (s.kind === "package") {
|
|
9276
|
-
const miss = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE)).filter((f2) => !
|
|
9364
|
+
const miss = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE)).filter((f2) => !existsSync15(f2));
|
|
9277
9365
|
return { name: "skills", ok: miss.length === 0, detail: miss.length ? `missing ${miss.join(", ")}` : void 0 };
|
|
9278
9366
|
}
|
|
9279
|
-
const bad = s.files.filter((f2) => readRaw(f2.file) !== (
|
|
9367
|
+
const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync15(f2.src) ? renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes) : void 0));
|
|
9280
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 };
|
|
9281
9369
|
}
|
|
9282
9370
|
var PLUGIN_ENABLED = "enabled";
|
|
@@ -9382,7 +9470,7 @@ function trustPluginHooks(row, ctx, apply2, hooks) {
|
|
|
9382
9470
|
const text2 = readOr(file);
|
|
9383
9471
|
let edit;
|
|
9384
9472
|
try {
|
|
9385
|
-
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));
|
|
9386
9474
|
} catch (e) {
|
|
9387
9475
|
if (e instanceof CtxError) throw new Error(parseFail(row, file));
|
|
9388
9476
|
throw e;
|
|
@@ -9560,14 +9648,14 @@ function agentHomeDir(id, ctx) {
|
|
|
9560
9648
|
return path12.join(ctx.home, ...AGENT_HOME_DIR[id]);
|
|
9561
9649
|
}
|
|
9562
9650
|
function detectAgents(reg, ctx) {
|
|
9563
|
-
return reg.filter((r2) =>
|
|
9651
|
+
return reg.filter((r2) => existsSync15(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
|
|
9564
9652
|
}
|
|
9565
9653
|
async function runSetup(opts) {
|
|
9566
9654
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9567
9655
|
const runId = opts.runId ?? (/* @__PURE__ */ new Date()).toISOString().split(":").join("-").split(".").join("-");
|
|
9568
9656
|
const reg = buildRegistry(ctx);
|
|
9569
9657
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9570
|
-
if (!
|
|
9658
|
+
if (!existsSync15(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9571
9659
|
}
|
|
9572
9660
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9573
9661
|
const root = path12.join(ctx.home, STATE_DIR);
|
|
@@ -9615,7 +9703,8 @@ async function setupRow(row, ctx, run, dryRun) {
|
|
|
9615
9703
|
if (!row.config && !row.cli) return { ...res, status: "SKIPPED", reason: `${row.id}: no setup path in the registry` };
|
|
9616
9704
|
let plan;
|
|
9617
9705
|
try {
|
|
9618
|
-
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 };
|
|
9619
9708
|
const listed = ls.check?.ok === true;
|
|
9620
9709
|
plan = planRow(row, listed, copyCheck(row, ctx.pkgDir)?.ok === false, ctx.env, listed && ls.status === "disabled");
|
|
9621
9710
|
} catch (e) {
|
|
@@ -9648,6 +9737,8 @@ async function setupRow(row, ctx, run, dryRun) {
|
|
|
9648
9737
|
if (bad.length) throw new Error(bad.map((c3) => `${c3.name}: ${c3.detail}`).join("; "));
|
|
9649
9738
|
} catch (e) {
|
|
9650
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 };
|
|
9651
9742
|
return { ...res, status: "FAIL", reason: e.message, rolledBack: true };
|
|
9652
9743
|
}
|
|
9653
9744
|
return res;
|
|
@@ -9658,7 +9749,7 @@ async function runDoctor(opts) {
|
|
|
9658
9749
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9659
9750
|
const reg = buildRegistry(ctx);
|
|
9660
9751
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9661
|
-
if (!
|
|
9752
|
+
if (!existsSync15(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9662
9753
|
}
|
|
9663
9754
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9664
9755
|
const run = new Run(path12.join(ctx.home, STATE_DIR), "doctor");
|
|
@@ -9702,7 +9793,7 @@ function notSetUpReason(row, res, env) {
|
|
|
9702
9793
|
const h2 = row.hookInstall;
|
|
9703
9794
|
const missing = row.id === "opencode" && h2.kind === "plugin-list" && res.changes.some((c3) => c3.path === h2.key[0]);
|
|
9704
9795
|
const oc2 = missing && hostBin("opencode", env).file !== void 0 && opencodeMajor("opencode", env) >= 2;
|
|
9705
|
-
return oc2 ? `${NOT_SET_UP_REASON}, or run: opencode plugin add context-mode
|
|
9796
|
+
return oc2 ? `${NOT_SET_UP_REASON}, or run: opencode plugin add context-mode` : NOT_SET_UP_REASON;
|
|
9706
9797
|
}
|
|
9707
9798
|
function hasPluginIssue(row) {
|
|
9708
9799
|
const h2 = row.hookInstall;
|
|
@@ -9726,12 +9817,12 @@ function runRemove(opts) {
|
|
|
9726
9817
|
const env = opts.env ?? process.env;
|
|
9727
9818
|
const root = path12.join(opts.home, STATE_DIR);
|
|
9728
9819
|
const base = path12.join(root, BACKUP_DIR);
|
|
9729
|
-
if (!
|
|
9820
|
+
if (!existsSync15(base)) return { exitCode: 0, restored: 0 };
|
|
9730
9821
|
const held = takeLock(root, "remove");
|
|
9731
9822
|
if (held) return { exitCode: 1, restored: 0, error: held };
|
|
9732
9823
|
let restored = 0;
|
|
9733
9824
|
try {
|
|
9734
|
-
const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) =>
|
|
9825
|
+
const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) => existsSync15(path12.join(d, MANIFEST))).sort().reverse();
|
|
9735
9826
|
for (const dir of runs) {
|
|
9736
9827
|
const m3 = JSON.parse(readFileSync10(path12.join(dir, MANIFEST), "utf8"));
|
|
9737
9828
|
undo(dir, m3.entries, env);
|
|
@@ -10195,7 +10286,7 @@ async function upgrade(ui) {
|
|
|
10195
10286
|
}
|
|
10196
10287
|
const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
|
|
10197
10288
|
const cli = path13.join(root, "context-mode", "cli.mjs");
|
|
10198
|
-
if (!root || !
|
|
10289
|
+
if (!root || !existsSync16(cli)) {
|
|
10199
10290
|
err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
|
|
10200
10291
|
return EXIT_FAIL;
|
|
10201
10292
|
}
|
|
@@ -10290,7 +10381,7 @@ function route(argv, version) {
|
|
|
10290
10381
|
` };
|
|
10291
10382
|
}
|
|
10292
10383
|
function main() {
|
|
10293
|
-
const dir = path14.dirname(realpathSync9(
|
|
10384
|
+
const dir = path14.dirname(realpathSync9(fileURLToPath3(import.meta.url)));
|
|
10294
10385
|
let version = "";
|
|
10295
10386
|
try {
|
|
10296
10387
|
version = String(JSON.parse(readFileSync12(path14.join(dir, PACKAGE_FILE), "utf8")).version);
|
|
@@ -10329,7 +10420,7 @@ function main() {
|
|
|
10329
10420
|
process.exitCode = signal === "SIGINT" ? EXIT_SIGINT2 : code ?? EXIT_FAIL2;
|
|
10330
10421
|
});
|
|
10331
10422
|
}
|
|
10332
|
-
if (isEntry(import.meta.main, process.argv[1],
|
|
10423
|
+
if (isEntry(import.meta.main, process.argv[1], fileURLToPath3(import.meta.url))) main();
|
|
10333
10424
|
export {
|
|
10334
10425
|
HELP2 as HELP,
|
|
10335
10426
|
V1_PLATFORM_AGENT,
|