context-mode 2.0.2 → 2.1.1
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 +6 -2
- package/.claude-plugin/plugin.json +5 -2
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +87 -91
- package/SHA256SUMS +18 -21
- package/cli.mjs +244 -118
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +87 -84
- package/opencode/plugin.js +316 -214
- package/package.json +1 -2
- package/pi/index.js +364 -262
- package/qwen-extension.json +1 -1
- package/run.mjs +66 -21
- package/search.mjs +66 -21
- package/server.mjs +349 -247
- package/skills/ctx-doctor/SKILL.md +1 -1
- package/skills/ctx-stats/SKILL.md +1 -1
- package/skills/ctx-upgrade/SKILL.md +1 -1
- package/claude-code/skills/ctx-doctor/SKILL.md +0 -6
- package/claude-code/skills/ctx-stats/SKILL.md +0 -6
- package/claude-code/skills/ctx-upgrade/SKILL.md +0 -6
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
|
|
|
@@ -630,7 +645,7 @@ function outputOf(resp) {
|
|
|
630
645
|
function textSlot(r2) {
|
|
631
646
|
const file = r2.file;
|
|
632
647
|
if (r2.type === "text" && typeof file === "object" && file !== null && typeof file.content === "string") {
|
|
633
|
-
return { text: file.content, put: (o2, output) => ({ ...o2, file:
|
|
648
|
+
return { text: file.content, put: (o2, output) => ({ ...o2, file: readFile(o2.file, output) }) };
|
|
634
649
|
}
|
|
635
650
|
if (isGrepContent(r2)) return { text: r2.content, put: (o2, output) => ({ ...o2, content: output }) };
|
|
636
651
|
if (Array.isArray(r2.filenames) && r2.filenames.every((f2) => typeof f2 === "string")) {
|
|
@@ -639,13 +654,35 @@ function textSlot(r2) {
|
|
|
639
654
|
if (typeof r2.result === "string") return { text: r2.result, put: (o2, output) => ({ ...o2, result: output }) };
|
|
640
655
|
return null;
|
|
641
656
|
}
|
|
657
|
+
function readFile(file, output) {
|
|
658
|
+
const start = typeof file.startLine === "number" ? file.startLine : 1;
|
|
659
|
+
const lines = String(file.content).split("\n");
|
|
660
|
+
const read = typeof file.numLines === "number" ? file.numLines : lines.length;
|
|
661
|
+
const out2 = output.split("\n");
|
|
662
|
+
const run = firstRun(lines, out2);
|
|
663
|
+
if (run === null) return { ...file, content: output, startLine: start + read, numLines: out2.length };
|
|
664
|
+
const kept = out2.slice(0, run.length);
|
|
665
|
+
if (run.length < out2.length) kept.push(out2[out2.length - 1]);
|
|
666
|
+
return { ...file, content: kept.join("\n"), startLine: start + run.at, numLines: kept.length };
|
|
667
|
+
}
|
|
668
|
+
function firstRun(lines, out2) {
|
|
669
|
+
let best = null;
|
|
670
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
671
|
+
if (lines[i2] !== out2[0]) continue;
|
|
672
|
+
let n3 = 1;
|
|
673
|
+
while (n3 < out2.length && i2 + n3 < lines.length && lines[i2 + n3] === out2[n3]) n3++;
|
|
674
|
+
if (best === null || n3 > best.length) best = { at: i2, length: n3 };
|
|
675
|
+
if (n3 === out2.length) break;
|
|
676
|
+
}
|
|
677
|
+
return best;
|
|
678
|
+
}
|
|
642
679
|
function isShellShape(resp) {
|
|
643
680
|
const r2 = resp;
|
|
644
681
|
return typeof r2.stdout === "string" || typeof r2.stderr === "string";
|
|
645
682
|
}
|
|
646
683
|
function isGrepContent(resp) {
|
|
647
684
|
const r2 = resp;
|
|
648
|
-
return r2.mode === "content" && typeof r2.content === "string";
|
|
685
|
+
return (r2.mode === "content" || r2.mode === "count") && typeof r2.content === "string";
|
|
649
686
|
}
|
|
650
687
|
function blocksOf(resp) {
|
|
651
688
|
const parts = [];
|
|
@@ -661,6 +698,7 @@ function readResult(resp) {
|
|
|
661
698
|
const text2 = outputOf(resp);
|
|
662
699
|
const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
|
|
663
700
|
const info = { isError, bytes: Buffer.byteLength(text2), text: text2 };
|
|
701
|
+
if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && isShellShape(resp)) info.shape = resp;
|
|
664
702
|
if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && !isShellShape(resp)) {
|
|
665
703
|
if (textSlot(resp) !== null) info.shape = resp;
|
|
666
704
|
else info.keep = true;
|
|
@@ -700,8 +738,11 @@ function decodeClaudeShape(raw, agent, ownPrefix, sources2) {
|
|
|
700
738
|
return ev;
|
|
701
739
|
}
|
|
702
740
|
function replaceShape(ev, output) {
|
|
703
|
-
if (ev.tool?.canonicalName === "Bash") return { stdout: output, stderr: "", interrupted: false };
|
|
704
741
|
const shape = ev.result?.shape;
|
|
742
|
+
if (ev.tool?.canonicalName === "Bash") {
|
|
743
|
+
const { persistedOutputPath: _p, persistedOutputSize: _s, ...host } = shape ?? {};
|
|
744
|
+
return { interrupted: false, ...host, stdout: output, stderr: "" };
|
|
745
|
+
}
|
|
705
746
|
const slot = shape === void 0 ? null : textSlot(shape);
|
|
706
747
|
if (shape !== void 0 && slot !== null) return slot.put(shape, output);
|
|
707
748
|
if (ev.result?.blocks === true) return [{ type: "text", text: output }];
|
|
@@ -1096,7 +1137,8 @@ function encode6(ev, d, _extra) {
|
|
|
1096
1137
|
}
|
|
1097
1138
|
|
|
1098
1139
|
// src/adapters/kiro.ts
|
|
1099
|
-
var TOOL_NAME_PREFIX7 = "
|
|
1140
|
+
var TOOL_NAME_PREFIX7 = "mcp_context_mode_";
|
|
1141
|
+
var LEGACY_TOOL_NAME_PREFIX = "mcp_context-mode_";
|
|
1100
1142
|
var KIRO_EVENTS = {
|
|
1101
1143
|
SessionStart: "SessionStart",
|
|
1102
1144
|
agentSpawn: "SessionStart",
|
|
@@ -1108,6 +1150,7 @@ var KIRO_EVENTS = {
|
|
|
1108
1150
|
PostToolUse: "PostToolUse",
|
|
1109
1151
|
postToolUse: "PostToolUse"
|
|
1110
1152
|
};
|
|
1153
|
+
var PROMPT_FIELD = "prompt";
|
|
1111
1154
|
var PROMPT_ENV = "USER_PROMPT";
|
|
1112
1155
|
var MCP_PREFIX3 = "mcp_";
|
|
1113
1156
|
var SHELL_TOOL_NAMES4 = Object.freeze(["execute_bash", "execute_pwsh", "shell"]);
|
|
@@ -1116,6 +1159,7 @@ var MCP_SEP3 = "_";
|
|
|
1116
1159
|
var KIRO_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1117
1160
|
function canonicalName5(name) {
|
|
1118
1161
|
if (name.startsWith(TOOL_NAME_PREFIX7)) return name.slice(TOOL_NAME_PREFIX7.length);
|
|
1162
|
+
if (name.startsWith(LEGACY_TOOL_NAME_PREFIX)) return name.slice(LEGACY_TOOL_NAME_PREFIX.length);
|
|
1119
1163
|
if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
|
|
1120
1164
|
if (!name.startsWith(MCP_PREFIX3)) return name;
|
|
1121
1165
|
const rest = name.slice(MCP_PREFIX3.length);
|
|
@@ -1136,7 +1180,8 @@ function decode7(raw) {
|
|
|
1136
1180
|
const ev = { event, agent: "kiro", sessionId: String(p3.session_id ?? ""), cwd: String(p3.cwd ?? "") };
|
|
1137
1181
|
if (event === "SessionStart" && typeof p3.source === "string" && KIRO_SOURCES[p3.source] !== void 0) ev.source = KIRO_SOURCES[p3.source];
|
|
1138
1182
|
if (event === "UserPromptSubmit") {
|
|
1139
|
-
const
|
|
1183
|
+
const field2 = p3[PROMPT_FIELD];
|
|
1184
|
+
const prompt = typeof field2 === "string" ? field2 : process.env[PROMPT_ENV];
|
|
1140
1185
|
if (prompt !== void 0) ev.prompt = prompt;
|
|
1141
1186
|
}
|
|
1142
1187
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
@@ -1148,7 +1193,7 @@ function decode7(raw) {
|
|
|
1148
1193
|
return ev;
|
|
1149
1194
|
}
|
|
1150
1195
|
function encode7(ev, d, _extra) {
|
|
1151
|
-
if (ev.event === "UserPromptSubmit") return { stdout: "", exitCode: 0 };
|
|
1196
|
+
if (ev.event === "UserPromptSubmit") return { stdout: d.kind === "hint" ? d.text : "", exitCode: 0 };
|
|
1152
1197
|
switch (d.kind) {
|
|
1153
1198
|
case "allow":
|
|
1154
1199
|
return { stdout: "", exitCode: 0 };
|
|
@@ -1317,8 +1362,8 @@ var ADAPTERS = Object.freeze([
|
|
|
1317
1362
|
hookTimeoutMs: HOOK_TIMEOUT_MS,
|
|
1318
1363
|
denyChannel: "deny-reason",
|
|
1319
1364
|
hookChannel: { kind: "package", path: "hooks/claude-code.json" },
|
|
1320
|
-
skillChannel: { kind: "package", path: "
|
|
1321
|
-
// ADR-0020, D-
|
|
1365
|
+
skillChannel: { kind: "package", path: "skills" },
|
|
1366
|
+
// ADR-0020, D-R33-CC-SKILLS-1: Claude Code always loads <plugin>/skills, shared with gemini and qwen
|
|
1322
1367
|
decode,
|
|
1323
1368
|
encode
|
|
1324
1369
|
},
|
|
@@ -1713,7 +1758,7 @@ Examples:
|
|
|
1713
1758
|
// src/cli/commands.ts
|
|
1714
1759
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
1715
1760
|
import { createHash as createHash2 } from "node:crypto";
|
|
1716
|
-
import { existsSync as
|
|
1761
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1717
1762
|
import os from "node:os";
|
|
1718
1763
|
import path13 from "node:path";
|
|
1719
1764
|
|
|
@@ -4629,14 +4674,29 @@ function copilotDirOf(env, home) {
|
|
|
4629
4674
|
function kiroDirOf(env, home, platform = process.platform) {
|
|
4630
4675
|
const p3 = platform === "win32" ? win32 : posix;
|
|
4631
4676
|
const fallback = p3.join(home, ...AGENT_HOME_DIR.kiro);
|
|
4632
|
-
const dir = env[KIRO_HOME_ENV];
|
|
4677
|
+
const dir = env[KIRO_HOME_ENV]?.trim();
|
|
4633
4678
|
if (dir === void 0 || dir === "" || !p3.isAbsolute(dir)) return fallback;
|
|
4634
4679
|
if (platform === "win32" && p3.parse(dir).root.length < 2) return fallback;
|
|
4635
4680
|
const abs = p3.resolve(dir);
|
|
4636
|
-
|
|
4637
|
-
const
|
|
4681
|
+
const real2 = platform === process.platform ? realOrSelf : (x2) => x2;
|
|
4682
|
+
const target = real2(abs);
|
|
4683
|
+
if (p3.parse(target).root === target) return fallback;
|
|
4684
|
+
const up = p3.relative(target, real2(p3.resolve(home)));
|
|
4638
4685
|
if (!p3.isAbsolute(up) && up.split(p3.sep)[0] !== "..") return fallback;
|
|
4639
|
-
return
|
|
4686
|
+
return abs;
|
|
4687
|
+
}
|
|
4688
|
+
function realOrSelf(path15) {
|
|
4689
|
+
const tail = [];
|
|
4690
|
+
for (let at = path15; ; ) {
|
|
4691
|
+
try {
|
|
4692
|
+
return join2(realpathSync.native(at), ...tail.reverse());
|
|
4693
|
+
} catch {
|
|
4694
|
+
const up = dirname2(at);
|
|
4695
|
+
if (up === at) return path15;
|
|
4696
|
+
tail.push(basename(at));
|
|
4697
|
+
at = up;
|
|
4698
|
+
}
|
|
4699
|
+
}
|
|
4640
4700
|
}
|
|
4641
4701
|
function claudeDirOf(env, home) {
|
|
4642
4702
|
const dir = env[CLAUDE_CONFIG_DIR_ENV];
|
|
@@ -4667,8 +4727,8 @@ function ownMcpFileOf(agent, file, env, home) {
|
|
|
4667
4727
|
|
|
4668
4728
|
// src/core/ops/doctor-issue.ts
|
|
4669
4729
|
import { spawnSync } from "node:child_process";
|
|
4670
|
-
import { closeSync, existsSync as
|
|
4671
|
-
import { delimiter, join as
|
|
4730
|
+
import { closeSync, existsSync as existsSync8, fstatSync, mkdirSync as mkdirSync4, openSync, readFileSync as readFileSync4, readSync, realpathSync as realpathSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
4731
|
+
import { delimiter, join as join9 } from "node:path";
|
|
4672
4732
|
|
|
4673
4733
|
// src/core/hooks/fallback.ts
|
|
4674
4734
|
import { join as join3, resolve as resolve2 } from "node:path";
|
|
@@ -4764,17 +4824,17 @@ CREATE VIRTUAL TABLE line_units USING fts5(
|
|
|
4764
4824
|
var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
4765
4825
|
|
|
4766
4826
|
// src/core/ops/doctor-config.ts
|
|
4767
|
-
import { existsSync as
|
|
4768
|
-
import { join as
|
|
4827
|
+
import { existsSync as existsSync7, readdirSync as readdirSync4 } from "node:fs";
|
|
4828
|
+
import { join as join8 } from "node:path";
|
|
4769
4829
|
|
|
4770
4830
|
// src/core/ops/detect-v1.ts
|
|
4771
|
-
import { existsSync as
|
|
4831
|
+
import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
4772
4832
|
import { tmpdir } from "node:os";
|
|
4773
|
-
import { join as
|
|
4833
|
+
import { join as join6 } from "node:path";
|
|
4774
4834
|
|
|
4775
4835
|
// src/core/ops/host-config.ts
|
|
4776
|
-
import { existsSync as
|
|
4777
|
-
import { dirname as
|
|
4836
|
+
import { existsSync as existsSync4, readFileSync } from "node:fs";
|
|
4837
|
+
import { dirname as dirname4, join as join5 } from "node:path";
|
|
4778
4838
|
|
|
4779
4839
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
4780
4840
|
var KEYS2 = {
|
|
@@ -6882,6 +6942,11 @@ function atomicWriteFile(file, text2, opts = {}) {
|
|
|
6882
6942
|
}
|
|
6883
6943
|
}
|
|
6884
6944
|
|
|
6945
|
+
// src/core/ops/bundle-dir.ts
|
|
6946
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
6947
|
+
import { dirname as dirname3, join as join4 } from "node:path";
|
|
6948
|
+
import { fileURLToPath } from "node:url";
|
|
6949
|
+
|
|
6885
6950
|
// src/core/ops/host-text.ts
|
|
6886
6951
|
var BOM_CODE = 65279;
|
|
6887
6952
|
var CR_CODE = 13;
|
|
@@ -7383,7 +7448,7 @@ function flatCommands(events2, prefix) {
|
|
|
7383
7448
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
7384
7449
|
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep2) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep2) + sep2));
|
|
7385
7450
|
function dataDir(dir, reason, out2) {
|
|
7386
|
-
if (
|
|
7451
|
+
if (existsSync5(dir)) out2.push(finding(dir, "", reason));
|
|
7387
7452
|
}
|
|
7388
7453
|
function mcpEntry(file, doc, out2) {
|
|
7389
7454
|
if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
|
|
@@ -7391,7 +7456,7 @@ function mcpEntry(file, doc, out2) {
|
|
|
7391
7456
|
}
|
|
7392
7457
|
}
|
|
7393
7458
|
function claudeShapeSettings(agentHome, out2) {
|
|
7394
|
-
const file =
|
|
7459
|
+
const file = join6(agentHome, SETTINGS_FILE);
|
|
7395
7460
|
const doc = readJson(file);
|
|
7396
7461
|
for (const c3 of nestedCommands(doc)) {
|
|
7397
7462
|
if (c3.command.includes(V1_CACHE_HEAL_NAME)) out2.push(finding(file, c3.path, V1_REASON.cacheHealHook));
|
|
@@ -7411,49 +7476,49 @@ function v1HookFile(file, out2) {
|
|
|
7411
7476
|
function scanClaudeCode(home, agentHome, out2) {
|
|
7412
7477
|
claudeShapeSettings(agentHome, out2);
|
|
7413
7478
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
7414
|
-
const file =
|
|
7415
|
-
if (
|
|
7479
|
+
const file = join6(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
7480
|
+
if (existsSync5(file)) out2.push(finding(file, "", V1_REASON.cacheHealFile));
|
|
7416
7481
|
}
|
|
7417
|
-
const userFile =
|
|
7482
|
+
const userFile = join6(home, CLAUDE_USER_CONFIG_FILE);
|
|
7418
7483
|
mcpEntry(userFile, readJson(userFile), out2);
|
|
7419
|
-
dataDir(
|
|
7484
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7420
7485
|
}
|
|
7421
7486
|
function scanCodex(agentHome, out2) {
|
|
7422
|
-
const hooksFile =
|
|
7487
|
+
const hooksFile = join6(agentHome, HOOKS_JSON_FILE);
|
|
7423
7488
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7424
7489
|
if (c3.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c3.command)) {
|
|
7425
7490
|
out2.push(finding(hooksFile, c3.path, V1_REASON.codexHook));
|
|
7426
7491
|
}
|
|
7427
7492
|
}
|
|
7428
|
-
const tomlFile =
|
|
7493
|
+
const tomlFile = join6(agentHome, CONFIG_TOML_FILE);
|
|
7429
7494
|
const config = readTomlValue(tomlFile);
|
|
7430
7495
|
for (const span of readTomlTables(tomlFile)) {
|
|
7431
7496
|
if (span.path[0] !== V1_TOML_SECTION_ROOT || span.path[1] !== SERVER_KEY) continue;
|
|
7432
7497
|
if (span.path.length === 2 && isV2McpTable(hostConfigValueAt(config, span.path))) continue;
|
|
7433
7498
|
out2.push(finding(tomlFile, span.header.trim(), V1_REASON.codexToml));
|
|
7434
7499
|
}
|
|
7435
|
-
dataDir(
|
|
7500
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7436
7501
|
}
|
|
7437
7502
|
function scanGemini(agentHome, out2) {
|
|
7438
|
-
const file =
|
|
7503
|
+
const file = join6(agentHome, SETTINGS_FILE);
|
|
7439
7504
|
for (const c3 of nestedCommands(readJson(file))) {
|
|
7440
7505
|
if (c3.command.includes(SERVER_KEY)) out2.push(finding(file, c3.path, V1_REASON.hook));
|
|
7441
7506
|
}
|
|
7442
|
-
dataDir(
|
|
7507
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
|
|
7443
7508
|
}
|
|
7444
7509
|
function scanVscode(agentHome, project, out2) {
|
|
7445
7510
|
if (project !== void 0) {
|
|
7446
|
-
v1HookFile(
|
|
7447
|
-
const mcpFile =
|
|
7511
|
+
v1HookFile(join6(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7512
|
+
const mcpFile = join6(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
7448
7513
|
const doc = readJson(mcpFile);
|
|
7449
7514
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
7450
7515
|
const entry2 = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
7451
7516
|
if (isObj(entry2) && (entry2.command === V1_BIN_COMMAND || listOf(entry2.args).some((a2) => a2 === V1_BIN_COMMAND))) {
|
|
7452
7517
|
out2.push(finding(mcpFile, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
7453
7518
|
}
|
|
7454
|
-
dataDir(
|
|
7519
|
+
dataDir(join6(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7455
7520
|
}
|
|
7456
|
-
dataDir(
|
|
7521
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7457
7522
|
}
|
|
7458
7523
|
function jsonFiles(dir) {
|
|
7459
7524
|
try {
|
|
@@ -7463,10 +7528,10 @@ function jsonFiles(dir) {
|
|
|
7463
7528
|
}
|
|
7464
7529
|
}
|
|
7465
7530
|
function scanKiro(agentHome, project, out2) {
|
|
7466
|
-
const agentsDir =
|
|
7467
|
-
const defaultFile =
|
|
7531
|
+
const agentsDir = join6(agentHome, KIRO_AGENTS_DIR);
|
|
7532
|
+
const defaultFile = join6(agentHome, ...KIRO_AGENT_FILE);
|
|
7468
7533
|
for (const name of jsonFiles(agentsDir)) {
|
|
7469
|
-
const file =
|
|
7534
|
+
const file = join6(agentsDir, name);
|
|
7470
7535
|
const doc = readJson(file);
|
|
7471
7536
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
7472
7537
|
out2.push(finding(file, "", V1_REASON.kiroAgentFile));
|
|
@@ -7477,25 +7542,25 @@ function scanKiro(agentHome, project, out2) {
|
|
|
7477
7542
|
if (isV1Hook(c3.command)) out2.push(finding(file, c3.path, V1_REASON.kiroHook));
|
|
7478
7543
|
}
|
|
7479
7544
|
}
|
|
7480
|
-
const steeringDocs = [
|
|
7481
|
-
if (project !== void 0) steeringDocs.push(
|
|
7545
|
+
const steeringDocs = [join6(agentHome, ...KIRO_STEERING_FILE)];
|
|
7546
|
+
if (project !== void 0) steeringDocs.push(join6(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
7482
7547
|
for (const file of steeringDocs) {
|
|
7483
|
-
if (
|
|
7548
|
+
if (existsSync5(file)) out2.push(finding(file, "", V1_REASON.kiroSteering));
|
|
7484
7549
|
}
|
|
7485
|
-
dataDir(
|
|
7550
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7486
7551
|
}
|
|
7487
7552
|
function scanPi(piAgentDir, agentHome, out2) {
|
|
7488
|
-
const file =
|
|
7553
|
+
const file = join6(piAgentDir, SETTINGS_FILE);
|
|
7489
7554
|
const doc = readJson(file);
|
|
7490
7555
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
|
|
7491
7556
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
7492
7557
|
if (spec === V1_PI_PACKAGE) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
|
|
7493
7558
|
});
|
|
7494
|
-
dataDir(
|
|
7559
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7495
7560
|
}
|
|
7496
7561
|
function scanOpencode(agentHome, out2) {
|
|
7497
7562
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
7498
|
-
const file =
|
|
7563
|
+
const file = join6(agentHome, name);
|
|
7499
7564
|
const doc = readJson(file);
|
|
7500
7565
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
7501
7566
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i2) => {
|
|
@@ -7505,13 +7570,13 @@ function scanOpencode(agentHome, out2) {
|
|
|
7505
7570
|
}
|
|
7506
7571
|
}
|
|
7507
7572
|
function scanZcode(agentHome, out2) {
|
|
7508
|
-
const configFile =
|
|
7573
|
+
const configFile = join6(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
7509
7574
|
const config = readJson(configFile);
|
|
7510
7575
|
const events2 = isObj(config) && isObj(config[HOOKS_KEY]) ? config[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
7511
7576
|
for (const c3 of flatCommands(events2, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
7512
7577
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(configFile, c3.path, V1_REASON.zcodeHook));
|
|
7513
7578
|
}
|
|
7514
|
-
const hooksFile =
|
|
7579
|
+
const hooksFile = join6(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
7515
7580
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7516
7581
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(hooksFile, c3.path, V1_REASON.zcodeHook));
|
|
7517
7582
|
}
|
|
@@ -7535,14 +7600,14 @@ function firstTmpMatch(dir) {
|
|
|
7535
7600
|
}
|
|
7536
7601
|
}
|
|
7537
7602
|
function scanAll(home, tmp, out2) {
|
|
7538
|
-
const root =
|
|
7539
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
7603
|
+
const root = join6(home, DATA_ROOT.slice(1));
|
|
7604
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join6(root, name), V1_REASON.dataRoot, out2);
|
|
7540
7605
|
if (firstTmpMatch(tmp) !== null) out2.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
7541
7606
|
}
|
|
7542
7607
|
function detectV1(agent, home, scope = {}) {
|
|
7543
7608
|
const out2 = [];
|
|
7544
7609
|
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 :
|
|
7610
|
+
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
7611
|
switch (agent) {
|
|
7547
7612
|
case "claude-code":
|
|
7548
7613
|
scanClaudeCode(home, agentHome, out2);
|
|
@@ -7555,11 +7620,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7555
7620
|
break;
|
|
7556
7621
|
case "qwen":
|
|
7557
7622
|
claudeShapeSettings(agentHome, out2);
|
|
7558
|
-
dataDir(
|
|
7623
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7559
7624
|
break;
|
|
7560
7625
|
case "copilot-cli":
|
|
7561
|
-
v1HookFile(
|
|
7562
|
-
dataDir(
|
|
7626
|
+
v1HookFile(join6(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7627
|
+
dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7563
7628
|
break;
|
|
7564
7629
|
case "vscode":
|
|
7565
7630
|
scanVscode(agentHome, project, out2);
|
|
@@ -7568,7 +7633,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7568
7633
|
scanKiro(agentHome, project, out2);
|
|
7569
7634
|
break;
|
|
7570
7635
|
case "pi":
|
|
7571
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
7636
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join6(agentHome, PI_AGENT_DIR), agentHome, out2);
|
|
7572
7637
|
break;
|
|
7573
7638
|
// D-WIN-PIDIR-1: empty is unset
|
|
7574
7639
|
case "opencode":
|
|
@@ -7583,9 +7648,9 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7583
7648
|
}
|
|
7584
7649
|
|
|
7585
7650
|
// src/core/ops/plugin-root.ts
|
|
7586
|
-
import { existsSync as
|
|
7587
|
-
import { dirname as
|
|
7588
|
-
import { fileURLToPath } from "node:url";
|
|
7651
|
+
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
|
|
7652
|
+
import { dirname as dirname5, isAbsolute, join as join7, sep } from "node:path";
|
|
7653
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
7589
7654
|
|
|
7590
7655
|
// src/core/ops/doctor-config.ts
|
|
7591
7656
|
var [PART_MCP, PART_HOOKS, PART_TIMEOUT] = D3_PARTS;
|
|
@@ -7904,7 +7969,7 @@ function assertWritable(row, file) {
|
|
|
7904
7969
|
}
|
|
7905
7970
|
|
|
7906
7971
|
// src/setup/gemini-gate.ts
|
|
7907
|
-
import { existsSync as
|
|
7972
|
+
import { existsSync as existsSync9, readFileSync as readFileSync5 } from "node:fs";
|
|
7908
7973
|
import path4 from "node:path";
|
|
7909
7974
|
var GEMINI_DIR = ".gemini";
|
|
7910
7975
|
var SETTINGS_FILE2 = "settings.json";
|
|
@@ -7918,7 +7983,7 @@ function systemSettingsPath(env) {
|
|
|
7918
7983
|
return "/etc/gemini-cli/settings.json";
|
|
7919
7984
|
}
|
|
7920
7985
|
function load(file) {
|
|
7921
|
-
if (!
|
|
7986
|
+
if (!existsSync9(file)) return void 0;
|
|
7922
7987
|
try {
|
|
7923
7988
|
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync5(file, "utf8")), "jsonc") };
|
|
7924
7989
|
} catch {
|
|
@@ -7952,7 +8017,7 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
7952
8017
|
}
|
|
7953
8018
|
|
|
7954
8019
|
// src/setup/zcode-gate.ts
|
|
7955
|
-
import { existsSync as
|
|
8020
|
+
import { existsSync as existsSync10, readFileSync as readFileSync6 } from "node:fs";
|
|
7956
8021
|
import path5 from "node:path";
|
|
7957
8022
|
var OWN_AGENT2 = "zcode";
|
|
7958
8023
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
@@ -8044,7 +8109,7 @@ function zcodeSchemaBad(doc) {
|
|
|
8044
8109
|
}
|
|
8045
8110
|
function zcodeConfigGate(home) {
|
|
8046
8111
|
const file = path5.join(home, ".zcode", "cli", "config.json");
|
|
8047
|
-
if (!
|
|
8112
|
+
if (!existsSync10(file)) return void 0;
|
|
8048
8113
|
let doc;
|
|
8049
8114
|
try {
|
|
8050
8115
|
doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync6(file, "utf8")), "json");
|
|
@@ -8057,7 +8122,7 @@ function zcodeConfigGate(home) {
|
|
|
8057
8122
|
}
|
|
8058
8123
|
|
|
8059
8124
|
// src/setup/pi-gate.ts
|
|
8060
|
-
import { existsSync as
|
|
8125
|
+
import { existsSync as existsSync11, readFileSync as readFileSync7, realpathSync as realpathSync4 } from "node:fs";
|
|
8061
8126
|
import path6 from "node:path";
|
|
8062
8127
|
var OWN_FILE = "pi/index.js";
|
|
8063
8128
|
var EXTENSIONS_KEY = "extensions";
|
|
@@ -8066,7 +8131,7 @@ var TRUST_FILE = "trust.json";
|
|
|
8066
8131
|
var ALWAYS = "always";
|
|
8067
8132
|
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
8068
8133
|
function load2(file) {
|
|
8069
|
-
if (!
|
|
8134
|
+
if (!existsSync11(file)) return void 0;
|
|
8070
8135
|
try {
|
|
8071
8136
|
return { file, doc: parseHostConfig("pi", file, hostText(readFileSync7(file, "utf8")), "json") };
|
|
8072
8137
|
} catch {
|
|
@@ -8157,7 +8222,7 @@ function piSettingsGate(env, home, pkgDir, cwd) {
|
|
|
8157
8222
|
}
|
|
8158
8223
|
|
|
8159
8224
|
// src/setup/vscode-gate.ts
|
|
8160
|
-
import { existsSync as
|
|
8225
|
+
import { existsSync as existsSync12, readFileSync as readFileSync8 } from "node:fs";
|
|
8161
8226
|
import path7 from "node:path";
|
|
8162
8227
|
var SETTINGS_FILE3 = "settings.json";
|
|
8163
8228
|
var WORKSPACE_DIR = ".vscode";
|
|
@@ -8166,7 +8231,7 @@ var LOCATIONS_KEY = "chat.hookFilesLocations";
|
|
|
8166
8231
|
var OWN_LOCATION = "~/.copilot/hooks";
|
|
8167
8232
|
var MANAGED_KEYS = ["allowManagedHooksOnly", "strictPluginOnlyCustomization"];
|
|
8168
8233
|
function load3(file) {
|
|
8169
|
-
if (!
|
|
8234
|
+
if (!existsSync12(file)) return void 0;
|
|
8170
8235
|
try {
|
|
8171
8236
|
return { file, doc: parseHostConfig("vscode", file, hostText(readFileSync8(file, "utf8")), "jsonc") };
|
|
8172
8237
|
} catch {
|
|
@@ -8208,7 +8273,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
|
|
|
8208
8273
|
}
|
|
8209
8274
|
|
|
8210
8275
|
// src/setup/qwen-gate.ts
|
|
8211
|
-
import { existsSync as
|
|
8276
|
+
import { existsSync as existsSync13, readFileSync as readFileSync9 } from "node:fs";
|
|
8212
8277
|
import path8 from "node:path";
|
|
8213
8278
|
var KEY = "disableAllHooks";
|
|
8214
8279
|
var SETTINGS = "settings.json";
|
|
@@ -8224,7 +8289,7 @@ function settingsFiles(env, home, cwd, platform) {
|
|
|
8224
8289
|
}
|
|
8225
8290
|
function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
|
|
8226
8291
|
for (const file of settingsFiles(env, home, cwd, platform)) {
|
|
8227
|
-
if (!
|
|
8292
|
+
if (!existsSync13(file)) continue;
|
|
8228
8293
|
let value;
|
|
8229
8294
|
try {
|
|
8230
8295
|
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(readFileSync9(file, "utf8")), "jsonc"), [KEY]);
|
|
@@ -8238,7 +8303,7 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
|
|
|
8238
8303
|
|
|
8239
8304
|
// src/setup/codex-trust.ts
|
|
8240
8305
|
import { createHash } from "node:crypto";
|
|
8241
|
-
import { existsSync as
|
|
8306
|
+
import { existsSync as existsSync14, realpathSync as realpathSync5 } from "node:fs";
|
|
8242
8307
|
import path10 from "node:path";
|
|
8243
8308
|
import { spawn, spawnSync as spawnSync3 } from "node:child_process";
|
|
8244
8309
|
|
|
@@ -8329,6 +8394,7 @@ var isObj3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
|
8329
8394
|
var TRUST_KEY = ["hooks", "state"];
|
|
8330
8395
|
var CODEX_TRUST_PATH = TRUST_KEY.join(".") + ".";
|
|
8331
8396
|
var HASH_FIELD = "trusted_hash";
|
|
8397
|
+
var CONTENT_HASH_FIELD = "trusted_content_hash";
|
|
8332
8398
|
var HASH_PREFIX = "sha256:";
|
|
8333
8399
|
function sortKeys(v) {
|
|
8334
8400
|
if (Array.isArray(v)) return v.map(sortKeys);
|
|
@@ -8346,7 +8412,7 @@ function snake(name) {
|
|
|
8346
8412
|
function realFile(file) {
|
|
8347
8413
|
let dir = path10.resolve(file);
|
|
8348
8414
|
const rest = [];
|
|
8349
|
-
while (!
|
|
8415
|
+
while (!existsSync14(dir) && path10.dirname(dir) !== dir) {
|
|
8350
8416
|
rest.unshift(path10.basename(dir));
|
|
8351
8417
|
dir = path10.dirname(dir);
|
|
8352
8418
|
}
|
|
@@ -8415,6 +8481,7 @@ var LIST_TIMEOUT_MS = 15e3;
|
|
|
8415
8481
|
var EXIT_GRACE_MS = 5e3;
|
|
8416
8482
|
var PLUGIN_SOURCE = "plugin";
|
|
8417
8483
|
var TRUSTED = "trusted";
|
|
8484
|
+
var UNTRUSTED = "untrusted";
|
|
8418
8485
|
function pluginHooksFromReply(m3, pluginId) {
|
|
8419
8486
|
const out2 = [];
|
|
8420
8487
|
if (!isObj3(m3) || !isObj3(m3.result) || !Array.isArray(m3.result.data)) return out2;
|
|
@@ -8424,7 +8491,8 @@ function pluginHooksFromReply(m3, pluginId) {
|
|
|
8424
8491
|
if (!isObj3(h2) || h2.source !== PLUGIN_SOURCE || h2.pluginId !== pluginId) continue;
|
|
8425
8492
|
if (typeof h2.key !== "string" || typeof h2.currentHash !== "string") continue;
|
|
8426
8493
|
if (out2.some((x2) => x2.key === h2.key)) continue;
|
|
8427
|
-
|
|
8494
|
+
const status = typeof h2.trustStatus === "string" ? h2.trustStatus : UNTRUSTED;
|
|
8495
|
+
out2.push({ key: h2.key, hash: h2.currentHash, trusted: status === TRUSTED, status });
|
|
8428
8496
|
}
|
|
8429
8497
|
}
|
|
8430
8498
|
return out2;
|
|
@@ -8521,15 +8589,30 @@ function hookHashOf(currentHash) {
|
|
|
8521
8589
|
const cut = currentHash.indexOf(HASH_PART_SEP);
|
|
8522
8590
|
return cut < 0 ? currentHash : currentHash.slice(0, cut);
|
|
8523
8591
|
}
|
|
8524
|
-
function
|
|
8525
|
-
|
|
8592
|
+
function contentHashOf(currentHash) {
|
|
8593
|
+
const cut = currentHash.indexOf(HASH_PART_SEP);
|
|
8594
|
+
return cut < 0 ? void 0 : currentHash.slice(cut + 1);
|
|
8595
|
+
}
|
|
8596
|
+
function pluginTrustEntries(hooks, doc) {
|
|
8597
|
+
const states = isObj3(doc) && isObj3(doc.hooks) && isObj3(doc.hooks.state) ? doc.hooks.state : {};
|
|
8598
|
+
return hooks.filter((h2) => !h2.trusted).map((h2) => {
|
|
8599
|
+
const old = isObj3(states[h2.key]) ? states[h2.key] : {};
|
|
8600
|
+
const content = contentHashOf(h2.hash);
|
|
8601
|
+
const row = { ...old, [HASH_FIELD]: hookHashOf(h2.hash) };
|
|
8602
|
+
if (content !== void 0) row[CONTENT_HASH_FIELD] = content;
|
|
8603
|
+
return [[...TRUST_KEY, h2.key], row];
|
|
8604
|
+
});
|
|
8526
8605
|
}
|
|
8527
8606
|
var CODEX_PLUGIN_ID = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
8528
8607
|
var CODEX_UNTRUSTED_FIX = "run: context-mode setup";
|
|
8529
8608
|
function untrustedPluginHooksDetail(hooks) {
|
|
8530
8609
|
const bad = hooks.filter((h2) => !h2.trusted);
|
|
8531
8610
|
if (!bad.length) return void 0;
|
|
8532
|
-
|
|
8611
|
+
const counts = /* @__PURE__ */ new Map();
|
|
8612
|
+
for (const h2 of bad) counts.set(h2.status, (counts.get(h2.status) ?? 0) + 1);
|
|
8613
|
+
const words = [...counts].sort((a2, b3) => b3[1] - a2[1] || (a2[0] < b3[0] ? -1 : 1));
|
|
8614
|
+
const state = words.length === 1 ? words[0][0] : `${words.map(([w]) => w).join(" or ")} (${words.map(([w, n3]) => `${n3} ${w}`).join(", ")})`;
|
|
8615
|
+
return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks ${state}, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
|
|
8533
8616
|
}
|
|
8534
8617
|
|
|
8535
8618
|
// src/setup/copilot-hooks.ts
|
|
@@ -8629,7 +8712,7 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
8629
8712
|
|
|
8630
8713
|
// src/setup/engine.ts
|
|
8631
8714
|
import { spawn as spawn3, spawnSync as spawnSync4 } from "node:child_process";
|
|
8632
|
-
import { closeSync as closeSync2, existsSync as
|
|
8715
|
+
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
8716
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8634
8717
|
import path12 from "node:path";
|
|
8635
8718
|
|
|
@@ -8727,7 +8810,7 @@ function isNativeBinary(file) {
|
|
|
8727
8810
|
function owningPackage(dir) {
|
|
8728
8811
|
for (let d = dir; ; d = path12.dirname(d)) {
|
|
8729
8812
|
const f2 = path12.join(d, "package.json");
|
|
8730
|
-
if (
|
|
8813
|
+
if (existsSync15(f2)) {
|
|
8731
8814
|
try {
|
|
8732
8815
|
return String(JSON.parse(hostText(readFileSync10(f2, "utf8"))).name);
|
|
8733
8816
|
} catch {
|
|
@@ -8745,7 +8828,7 @@ function hostBin(bin, env, platform = process.platform) {
|
|
|
8745
8828
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
8746
8829
|
const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
|
|
8747
8830
|
for (const f2 of [own2, ...real2.extra.map((p3) => path12.join(dir, ...p3))]) {
|
|
8748
|
-
if (!f2 || !
|
|
8831
|
+
if (!f2 || !existsSync15(f2) || !statSync2(f2).isFile()) continue;
|
|
8749
8832
|
const file = realpathSync7(f2);
|
|
8750
8833
|
if (isNativeBinary(file) || owningPackage(path12.dirname(file)) === real2.pkg) return { file, shims };
|
|
8751
8834
|
shims.push(f2);
|
|
@@ -8762,10 +8845,10 @@ function runBin(bin, args, env, input, timeout = VERIFY_TIMEOUT_MS) {
|
|
|
8762
8845
|
return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout });
|
|
8763
8846
|
}
|
|
8764
8847
|
function readOr(file) {
|
|
8765
|
-
return
|
|
8848
|
+
return existsSync15(file) ? hostText(readFileSync10(file, "utf8")) : void 0;
|
|
8766
8849
|
}
|
|
8767
8850
|
function readRaw(file) {
|
|
8768
|
-
return
|
|
8851
|
+
return existsSync15(file) ? readFileSync10(file, "utf8") : void 0;
|
|
8769
8852
|
}
|
|
8770
8853
|
var atomicWrite = atomicWriteFile;
|
|
8771
8854
|
function pidAlive(pid) {
|
|
@@ -8910,7 +8993,7 @@ function isNativeSpec(e) {
|
|
|
8910
8993
|
function isStaleOwnPlugin(e, entry2) {
|
|
8911
8994
|
if (typeof e !== "string" || e === entry2 || !path12.isAbsolute(e)) return false;
|
|
8912
8995
|
if (e === path12.join(entry2, ...OPENCODE_PLUGIN_PATH)) return true;
|
|
8913
|
-
if (
|
|
8996
|
+
if (existsSync15(e)) return false;
|
|
8914
8997
|
const seg = e.split("\\").join("/").split("/");
|
|
8915
8998
|
const n3 = seg.length;
|
|
8916
8999
|
if (n3 >= 3 && seg[n3 - 1] === "plugin.js" && seg[n3 - 2] === "opencode" && seg[n3 - 3] === "context-mode") return true;
|
|
@@ -8974,7 +9057,7 @@ function planSkills(row, edits) {
|
|
|
8974
9057
|
const s = row.skillInstall;
|
|
8975
9058
|
if (s.kind !== "dir") return;
|
|
8976
9059
|
for (const f2 of s.files) {
|
|
8977
|
-
if (!
|
|
9060
|
+
if (!existsSync15(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
|
|
8978
9061
|
const after = renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes);
|
|
8979
9062
|
const before = readRaw(f2.file);
|
|
8980
9063
|
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 +9117,48 @@ function opencodeMajor(bin, env) {
|
|
|
9034
9117
|
const digits = text2.split("").filter((c3) => c3 >= "0" && c3 <= "9" || c3 === ".").join("");
|
|
9035
9118
|
return Number(digits.split(".")[0]);
|
|
9036
9119
|
}
|
|
9037
|
-
function opencodeListArgs(
|
|
9038
|
-
return
|
|
9120
|
+
function opencodeListArgs(major) {
|
|
9121
|
+
return major >= 2 ? ["mcp", "list", "--standalone"] : ["mcp", "list", "--pure"];
|
|
9122
|
+
}
|
|
9123
|
+
var OC2_CONFIG_ARGS = ["debug", "config", "--standalone"];
|
|
9124
|
+
function opencode2ListCheck(bin, env) {
|
|
9125
|
+
const r2 = runBin(bin, OC2_CONFIG_ARGS, env);
|
|
9126
|
+
const what = `${bin} ${OC2_CONFIG_ARGS.join(" ")}`;
|
|
9127
|
+
let docs;
|
|
9128
|
+
try {
|
|
9129
|
+
docs = JSON.parse(`${r2.stdout}`);
|
|
9130
|
+
} catch {
|
|
9131
|
+
docs = void 0;
|
|
9132
|
+
}
|
|
9133
|
+
if (r2.status !== 0) return { name: "list", ok: false, detail: `${what} exited ${r2.status}: ${`${r2.stderr}`.trim().split("\n")[0] ?? ""}` };
|
|
9134
|
+
if (!Array.isArray(docs)) return { name: "list", ok: false, detail: `${what} printed no config list: ${`${r2.stdout}`.trim().split("\n")[0] ?? ""}` };
|
|
9135
|
+
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]));
|
|
9136
|
+
const read = docs.filter(isObj5).map((d) => d.path).filter((p3) => typeof p3 === "string");
|
|
9137
|
+
return { name: "list", ok: listed, detail: listed ? void 0 : `${what} does not load mcp.servers.${SERVER_KEY}; it read: ${read.join(", ") || "no config"}` };
|
|
9138
|
+
}
|
|
9139
|
+
var HOST_BROKEN = {
|
|
9140
|
+
copilot: { text: "no platform package found", fix: "npm install -g @github/copilot" }
|
|
9141
|
+
};
|
|
9142
|
+
var HOST_BROKEN_PREFIX = "host broken: run ";
|
|
9143
|
+
function hostBroken(bin, out2) {
|
|
9144
|
+
const b3 = HOST_BROKEN[bin];
|
|
9145
|
+
if (!b3 || !out2.includes(b3.text)) return void 0;
|
|
9146
|
+
return `${HOST_BROKEN_PREFIX}${b3.fix} (${out2.trim().split("\n")[0]})`;
|
|
9039
9147
|
}
|
|
9040
9148
|
function listState(row, env) {
|
|
9041
|
-
|
|
9149
|
+
let l0 = row.listCommand;
|
|
9042
9150
|
if (!l0 || !hostBin(l0.bin, env).file) return { status: void 0 };
|
|
9043
|
-
|
|
9151
|
+
if (row.id === "opencode") {
|
|
9152
|
+
const major = opencodeMajor(l0.bin, env);
|
|
9153
|
+
if (major >= 2) return { check: opencode2ListCheck(l0.bin, env), status: void 0 };
|
|
9154
|
+
l0 = { bin: l0.bin, args: opencodeListArgs(major) };
|
|
9155
|
+
}
|
|
9156
|
+
const l2 = l0;
|
|
9044
9157
|
const r2 = runBin(l2.bin, l2.args, env);
|
|
9045
|
-
const
|
|
9158
|
+
const out2 = `${r2.stdout}${r2.stderr}`;
|
|
9159
|
+
const ok = r2.status === 0 && out2.includes("context-mode");
|
|
9046
9160
|
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 };
|
|
9161
|
+
return { check, status: r2.status === 0 ? statusOf(row, `${r2.stdout}`) : void 0, broken: r2.status === 0 ? void 0 : hostBroken(l2.bin, out2) };
|
|
9048
9162
|
}
|
|
9049
9163
|
var DISABLE_ALL_HOOKS = "disableAllHooks";
|
|
9050
9164
|
var SETTINGS_FILES = ["settings.json", "settings.local.json"];
|
|
@@ -9223,7 +9337,7 @@ function hookRegisteredCheck(row, env, list2) {
|
|
|
9223
9337
|
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
9338
|
const issue = h2.kind === "plugin-list" ? pluginListIssue(h2) : h2.kind === "file" && row.id === "kiro" ? kiroDisabledIssue(h2) : void 0;
|
|
9225
9339
|
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
|
|
9340
|
+
return { name: "hook-registered", ok: false, detail: issue ?? `${h2.file} lacks the context-mode hook entry${oc2 ? "; run: opencode plugin add context-mode" : ""}` };
|
|
9227
9341
|
}
|
|
9228
9342
|
function hookRunsCheck(row, env) {
|
|
9229
9343
|
const root = mkdtempSync(path12.join(tmpdir2(), "cm-doctor-runs-"));
|
|
@@ -9249,7 +9363,7 @@ var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
|
|
|
9249
9363
|
var NOT_SEEN_LINE = "not seen yet, run one tool call";
|
|
9250
9364
|
function hookSeenCheck(row, home) {
|
|
9251
9365
|
const base = path12.join(home, STATE_DIR, PROJECTS_DIR_NAME);
|
|
9252
|
-
const dirs =
|
|
9366
|
+
const dirs = existsSync15(base) ? readdirSync5(base) : [];
|
|
9253
9367
|
let sqlite;
|
|
9254
9368
|
try {
|
|
9255
9369
|
sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -9258,7 +9372,7 @@ function hookSeenCheck(row, home) {
|
|
|
9258
9372
|
}
|
|
9259
9373
|
for (const d of dirs) {
|
|
9260
9374
|
const file = path12.join(base, d, DB_FILE_NAME);
|
|
9261
|
-
if (!sqlite || !
|
|
9375
|
+
if (!sqlite || !existsSync15(file)) continue;
|
|
9262
9376
|
let db;
|
|
9263
9377
|
try {
|
|
9264
9378
|
db = new sqlite.DatabaseSync(file, { readOnly: true });
|
|
@@ -9270,13 +9384,22 @@ function hookSeenCheck(row, home) {
|
|
|
9270
9384
|
}
|
|
9271
9385
|
return { name: "hook-seen", ok: true, warn: true, detail: NOT_SEEN_LINE };
|
|
9272
9386
|
}
|
|
9387
|
+
var SKILL_TOOL_STEM = "ctx_";
|
|
9273
9388
|
function skillsCheck(row, pkgDir) {
|
|
9274
9389
|
const s = row.skillInstall;
|
|
9275
9390
|
if (s.kind === "package") {
|
|
9276
|
-
const
|
|
9277
|
-
|
|
9391
|
+
const files = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE));
|
|
9392
|
+
const miss = files.filter((f2) => !existsSync15(f2));
|
|
9393
|
+
if (miss.length) return { name: "skills", ok: false, detail: `missing ${miss.join(", ")}` };
|
|
9394
|
+
const own2 = getAdapter(row.id).toolNamePrefix + SKILL_TOOL_STEM;
|
|
9395
|
+
const foreign = [...new Set(ADAPTERS.map((r2) => r2.toolNamePrefix + SKILL_TOOL_STEM))].filter((n3) => n3 !== SKILL_TOOL_STEM && n3 !== own2);
|
|
9396
|
+
const bad2 = files.filter((f2) => {
|
|
9397
|
+
const t2 = readFileSync10(f2, "utf8");
|
|
9398
|
+
return !t2.includes(own2) && foreign.some((n3) => t2.includes(n3));
|
|
9399
|
+
});
|
|
9400
|
+
return { name: "skills", ok: bad2.length === 0, detail: bad2.length ? `${bad2.join(", ")} without the ${own2}* tool name` : void 0 };
|
|
9278
9401
|
}
|
|
9279
|
-
const bad = s.files.filter((f2) => readRaw(f2.file) !== (
|
|
9402
|
+
const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync15(f2.src) ? renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes) : void 0));
|
|
9280
9403
|
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
9404
|
}
|
|
9282
9405
|
var PLUGIN_ENABLED = "enabled";
|
|
@@ -9382,7 +9505,7 @@ function trustPluginHooks(row, ctx, apply2, hooks) {
|
|
|
9382
9505
|
const text2 = readOr(file);
|
|
9383
9506
|
let edit;
|
|
9384
9507
|
try {
|
|
9385
|
-
edit = editHostConfigText(row.id, file, text2 ?? "", "toml", pluginTrustEntries(hooks));
|
|
9508
|
+
edit = editHostConfigText(row.id, file, text2 ?? "", "toml", pluginTrustEntries(hooks, text2 ? parseHostConfig(row.id, file, text2, "toml") : void 0));
|
|
9386
9509
|
} catch (e) {
|
|
9387
9510
|
if (e instanceof CtxError) throw new Error(parseFail(row, file));
|
|
9388
9511
|
throw e;
|
|
@@ -9560,14 +9683,14 @@ function agentHomeDir(id, ctx) {
|
|
|
9560
9683
|
return path12.join(ctx.home, ...AGENT_HOME_DIR[id]);
|
|
9561
9684
|
}
|
|
9562
9685
|
function detectAgents(reg, ctx) {
|
|
9563
|
-
return reg.filter((r2) =>
|
|
9686
|
+
return reg.filter((r2) => existsSync15(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
|
|
9564
9687
|
}
|
|
9565
9688
|
async function runSetup(opts) {
|
|
9566
9689
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9567
9690
|
const runId = opts.runId ?? (/* @__PURE__ */ new Date()).toISOString().split(":").join("-").split(".").join("-");
|
|
9568
9691
|
const reg = buildRegistry(ctx);
|
|
9569
9692
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9570
|
-
if (!
|
|
9693
|
+
if (!existsSync15(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9571
9694
|
}
|
|
9572
9695
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9573
9696
|
const root = path12.join(ctx.home, STATE_DIR);
|
|
@@ -9615,7 +9738,8 @@ async function setupRow(row, ctx, run, dryRun) {
|
|
|
9615
9738
|
if (!row.config && !row.cli) return { ...res, status: "SKIPPED", reason: `${row.id}: no setup path in the registry` };
|
|
9616
9739
|
let plan;
|
|
9617
9740
|
try {
|
|
9618
|
-
const ls = needsBin ? listState(row, ctx.env) : { status: void 0, check: void 0 };
|
|
9741
|
+
const ls = needsBin ? listState(row, ctx.env) : { status: void 0, check: void 0, broken: void 0 };
|
|
9742
|
+
if (ls.broken) return { ...res, status: "SKIPPED", reason: ls.broken };
|
|
9619
9743
|
const listed = ls.check?.ok === true;
|
|
9620
9744
|
plan = planRow(row, listed, copyCheck(row, ctx.pkgDir)?.ok === false, ctx.env, listed && ls.status === "disabled");
|
|
9621
9745
|
} catch (e) {
|
|
@@ -9648,6 +9772,8 @@ async function setupRow(row, ctx, run, dryRun) {
|
|
|
9648
9772
|
if (bad.length) throw new Error(bad.map((c3) => `${c3.name}: ${c3.detail}`).join("; "));
|
|
9649
9773
|
} catch (e) {
|
|
9650
9774
|
run.rollback(row.id, ctx.env);
|
|
9775
|
+
const broken = row.cli ? hostBroken(row.cli.bin, e.message) : void 0;
|
|
9776
|
+
if (broken) return { ...res, status: "SKIPPED", reason: broken };
|
|
9651
9777
|
return { ...res, status: "FAIL", reason: e.message, rolledBack: true };
|
|
9652
9778
|
}
|
|
9653
9779
|
return res;
|
|
@@ -9658,7 +9784,7 @@ async function runDoctor(opts) {
|
|
|
9658
9784
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9659
9785
|
const reg = buildRegistry(ctx);
|
|
9660
9786
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9661
|
-
if (!
|
|
9787
|
+
if (!existsSync15(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9662
9788
|
}
|
|
9663
9789
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9664
9790
|
const run = new Run(path12.join(ctx.home, STATE_DIR), "doctor");
|
|
@@ -9702,7 +9828,7 @@ function notSetUpReason(row, res, env) {
|
|
|
9702
9828
|
const h2 = row.hookInstall;
|
|
9703
9829
|
const missing = row.id === "opencode" && h2.kind === "plugin-list" && res.changes.some((c3) => c3.path === h2.key[0]);
|
|
9704
9830
|
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
|
|
9831
|
+
return oc2 ? `${NOT_SET_UP_REASON}, or run: opencode plugin add context-mode` : NOT_SET_UP_REASON;
|
|
9706
9832
|
}
|
|
9707
9833
|
function hasPluginIssue(row) {
|
|
9708
9834
|
const h2 = row.hookInstall;
|
|
@@ -9726,12 +9852,12 @@ function runRemove(opts) {
|
|
|
9726
9852
|
const env = opts.env ?? process.env;
|
|
9727
9853
|
const root = path12.join(opts.home, STATE_DIR);
|
|
9728
9854
|
const base = path12.join(root, BACKUP_DIR);
|
|
9729
|
-
if (!
|
|
9855
|
+
if (!existsSync15(base)) return { exitCode: 0, restored: 0 };
|
|
9730
9856
|
const held = takeLock(root, "remove");
|
|
9731
9857
|
if (held) return { exitCode: 1, restored: 0, error: held };
|
|
9732
9858
|
let restored = 0;
|
|
9733
9859
|
try {
|
|
9734
|
-
const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) =>
|
|
9860
|
+
const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) => existsSync15(path12.join(d, MANIFEST))).sort().reverse();
|
|
9735
9861
|
for (const dir of runs) {
|
|
9736
9862
|
const m3 = JSON.parse(readFileSync10(path12.join(dir, MANIFEST), "utf8"));
|
|
9737
9863
|
undo(dir, m3.entries, env);
|
|
@@ -10195,7 +10321,7 @@ async function upgrade(ui) {
|
|
|
10195
10321
|
}
|
|
10196
10322
|
const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
|
|
10197
10323
|
const cli = path13.join(root, "context-mode", "cli.mjs");
|
|
10198
|
-
if (!root || !
|
|
10324
|
+
if (!root || !existsSync16(cli)) {
|
|
10199
10325
|
err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
|
|
10200
10326
|
return EXIT_FAIL;
|
|
10201
10327
|
}
|
|
@@ -10290,7 +10416,7 @@ function route(argv, version) {
|
|
|
10290
10416
|
` };
|
|
10291
10417
|
}
|
|
10292
10418
|
function main() {
|
|
10293
|
-
const dir = path14.dirname(realpathSync9(
|
|
10419
|
+
const dir = path14.dirname(realpathSync9(fileURLToPath3(import.meta.url)));
|
|
10294
10420
|
let version = "";
|
|
10295
10421
|
try {
|
|
10296
10422
|
version = String(JSON.parse(readFileSync12(path14.join(dir, PACKAGE_FILE), "utf8")).version);
|
|
@@ -10329,7 +10455,7 @@ function main() {
|
|
|
10329
10455
|
process.exitCode = signal === "SIGINT" ? EXIT_SIGINT2 : code ?? EXIT_FAIL2;
|
|
10330
10456
|
});
|
|
10331
10457
|
}
|
|
10332
|
-
if (isEntry(import.meta.main, process.argv[1],
|
|
10458
|
+
if (isEntry(import.meta.main, process.argv[1], fileURLToPath3(import.meta.url))) main();
|
|
10333
10459
|
export {
|
|
10334
10460
|
HELP2 as HELP,
|
|
10335
10461
|
V1_PLATFORM_AGENT,
|