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/opencode/plugin.js
CHANGED
|
@@ -426,7 +426,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
426
426
|
var DECISION_LABEL_JOIN = " | ";
|
|
427
427
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
428
428
|
var RELEASE_BRANCH = "release";
|
|
429
|
-
var BUNDLE_SHA = true ? "
|
|
429
|
+
var BUNDLE_SHA = true ? "2652fe27fc5d4e368fdc38eda49d3011d38e631e" : void 0;
|
|
430
430
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
431
431
|
var DOCTOR_LABEL = Object.freeze({
|
|
432
432
|
D1: "version",
|
|
@@ -715,8 +715,8 @@ var UPGRADE_DATA_DELETED = "user data deleted";
|
|
|
715
715
|
var UPGRADE_HOST_COMMAND = Object.freeze({
|
|
716
716
|
"claude-code": "claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",
|
|
717
717
|
codex: "rewrite config.toml's [mcp_servers.context-mode*] block to the v2 entry, then restart Codex",
|
|
718
|
-
gemini: "gemini extensions install https://github.com/mksglu/context-mode --
|
|
719
|
-
qwen: "qwen extensions install https://github.com/mksglu/context-mode --
|
|
718
|
+
gemini: "gemini extensions install https://github.com/mksglu/context-mode --auto-update",
|
|
719
|
+
qwen: "qwen extensions install https://github.com/mksglu/context-mode --auto-update"
|
|
720
720
|
});
|
|
721
721
|
var PI_GIT_PACKAGE = "git:github.com/mksglu/context-mode@release";
|
|
722
722
|
var OPENCODE_GIT_SPEC = "git+https://github.com/mksglu/context-mode.git#release";
|
|
@@ -780,6 +780,9 @@ var HOOKS_KEY = "hooks";
|
|
|
780
780
|
var STATUS_LINE_KEY = "statusLine";
|
|
781
781
|
var PI_PACKAGES_KEY = "packages";
|
|
782
782
|
var OPENCODE_PLUGIN_KEY = "plugin";
|
|
783
|
+
var OPENCODE_PLUGINS_KEY = "plugins";
|
|
784
|
+
var OPENCODE_PACKAGE_FIELD = "package";
|
|
785
|
+
var OPENCODE_NPM_SPEC_PREFIX = `${SERVER_KEY}@`;
|
|
783
786
|
var V1_DATA_DIR_NAME = "context-mode";
|
|
784
787
|
var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
|
|
785
788
|
var V1_SESSIONS_DIR_NAME = "sessions";
|
|
@@ -878,6 +881,7 @@ var DOCTOR_REPORT_FILE_PREFIX = "doctor-";
|
|
|
878
881
|
var DOCTOR_REPORT_LINE = "Report file: ";
|
|
879
882
|
var DOCTOR_GH_LINE = "File it: ";
|
|
880
883
|
var DOCTOR_URL_LINE = "Or open: ";
|
|
884
|
+
var DOCTOR_RULES_LINE = "Rules: ";
|
|
881
885
|
var DOCTOR_GH_NEXT = " --";
|
|
882
886
|
var DOCTOR_NOTE_PREFIXES = Object.freeze([
|
|
883
887
|
DOCTOR_ENV_PREFIX,
|
|
@@ -885,10 +889,23 @@ var DOCTOR_NOTE_PREFIXES = Object.freeze([
|
|
|
885
889
|
DOCTOR_REPORT_LINE,
|
|
886
890
|
DOCTOR_GH_LINE,
|
|
887
891
|
DOCTOR_GH_NEXT.trim(),
|
|
888
|
-
DOCTOR_URL_LINE
|
|
892
|
+
DOCTOR_URL_LINE,
|
|
893
|
+
DOCTOR_RULES_LINE
|
|
889
894
|
]);
|
|
890
895
|
var ISSUE_REPO_SLUG = "mksglu/context-mode";
|
|
891
896
|
var ISSUE_FORM_FILE = "agent-report.yml";
|
|
897
|
+
var ISSUE_GUIDE_URL = `https://github.com/${ISSUE_REPO_SLUG}/blob/main/.github/AGENT_ISSUE.md`;
|
|
898
|
+
var ISSUE_AGENT_RULES = Object.freeze([
|
|
899
|
+
'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.',
|
|
900
|
+
"File one bug per issue.",
|
|
901
|
+
"Call the `ctx_doctor` tool and paste its full output unchanged in the `ctx-report` field.",
|
|
902
|
+
"Give the versions: context-mode, the agent, the OS and arch, and Node.",
|
|
903
|
+
"Write numbered repro steps that start from a fresh project (`mktemp -d`) and the agent's own install command.",
|
|
904
|
+
"Give the exact command and its exact output in a fenced code block.",
|
|
905
|
+
"Say what you expected and what happened instead.",
|
|
906
|
+
"Name the source file and line when you found the cause.",
|
|
907
|
+
"Replace every secret with `<masked>` and the home folder with `~` before you send."
|
|
908
|
+
]);
|
|
892
909
|
var ISSUE_URL_MAX = 8e3;
|
|
893
910
|
var ISSUE_FORM_HEADINGS = Object.freeze([
|
|
894
911
|
"Summary",
|
|
@@ -919,16 +936,16 @@ var DOCTOR_PATH_TOOLS = Object.freeze(["node", "git", "sh"]);
|
|
|
919
936
|
var DOCTOR_SECRET_WORDS = Object.freeze(["token", "secret", "password", "apikey", "api_key", "authorization", "bearer"]);
|
|
920
937
|
var DOCTOR_MASK = "<masked>";
|
|
921
938
|
var NATIVE_INSTALL = Object.freeze({
|
|
922
|
-
"claude-code": ["claude plugin marketplace add mksglu/context-mode
|
|
923
|
-
codex: ["codex plugin marketplace add mksglu/context-mode
|
|
924
|
-
gemini: ["gemini extensions install https://github.com/mksglu/context-mode
|
|
925
|
-
qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode
|
|
926
|
-
opencode: ["opencode plugin add context-mode
|
|
927
|
-
pi: ["pi install npm:context-mode
|
|
928
|
-
"copilot-cli": ["npm i -g context-mode
|
|
929
|
-
vscode: ["npm i -g context-mode
|
|
930
|
-
kiro: ["npm i -g context-mode
|
|
931
|
-
zcode: ["npm i -g context-mode
|
|
939
|
+
"claude-code": ["claude plugin marketplace add mksglu/context-mode", "claude plugin install context-mode@context-mode"],
|
|
940
|
+
codex: ["codex plugin marketplace add mksglu/context-mode", "codex plugin add context-mode@context-mode"],
|
|
941
|
+
gemini: ["gemini extensions install https://github.com/mksglu/context-mode"],
|
|
942
|
+
qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode"],
|
|
943
|
+
opencode: ["opencode plugin add context-mode"],
|
|
944
|
+
pi: ["pi install npm:context-mode"],
|
|
945
|
+
"copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
|
|
946
|
+
vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
|
|
947
|
+
kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
|
|
948
|
+
zcode: ["npm i -g context-mode", "context-mode setup --agents zcode"]
|
|
932
949
|
});
|
|
933
950
|
var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
|
|
934
951
|
var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
|
|
@@ -1049,7 +1066,7 @@ function outputOf(resp) {
|
|
|
1049
1066
|
function textSlot(r) {
|
|
1050
1067
|
const file2 = r.file;
|
|
1051
1068
|
if (r.type === "text" && typeof file2 === "object" && file2 !== null && typeof file2.content === "string") {
|
|
1052
|
-
return { text: file2.content, put: (o, output) => ({ ...o, file:
|
|
1069
|
+
return { text: file2.content, put: (o, output) => ({ ...o, file: readFile(o.file, output) }) };
|
|
1053
1070
|
}
|
|
1054
1071
|
if (isGrepContent(r)) return { text: r.content, put: (o, output) => ({ ...o, content: output }) };
|
|
1055
1072
|
if (Array.isArray(r.filenames) && r.filenames.every((f) => typeof f === "string")) {
|
|
@@ -1058,13 +1075,35 @@ function textSlot(r) {
|
|
|
1058
1075
|
if (typeof r.result === "string") return { text: r.result, put: (o, output) => ({ ...o, result: output }) };
|
|
1059
1076
|
return null;
|
|
1060
1077
|
}
|
|
1078
|
+
function readFile(file2, output) {
|
|
1079
|
+
const start = typeof file2.startLine === "number" ? file2.startLine : 1;
|
|
1080
|
+
const lines = String(file2.content).split("\n");
|
|
1081
|
+
const read3 = typeof file2.numLines === "number" ? file2.numLines : lines.length;
|
|
1082
|
+
const out = output.split("\n");
|
|
1083
|
+
const run = firstRun(lines, out);
|
|
1084
|
+
if (run === null) return { ...file2, content: output, startLine: start + read3, numLines: out.length };
|
|
1085
|
+
const kept = out.slice(0, run.length);
|
|
1086
|
+
if (run.length < out.length) kept.push(out[out.length - 1]);
|
|
1087
|
+
return { ...file2, content: kept.join("\n"), startLine: start + run.at, numLines: kept.length };
|
|
1088
|
+
}
|
|
1089
|
+
function firstRun(lines, out) {
|
|
1090
|
+
let best = null;
|
|
1091
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1092
|
+
if (lines[i] !== out[0]) continue;
|
|
1093
|
+
let n = 1;
|
|
1094
|
+
while (n < out.length && i + n < lines.length && lines[i + n] === out[n]) n++;
|
|
1095
|
+
if (best === null || n > best.length) best = { at: i, length: n };
|
|
1096
|
+
if (n === out.length) break;
|
|
1097
|
+
}
|
|
1098
|
+
return best;
|
|
1099
|
+
}
|
|
1061
1100
|
function isShellShape(resp) {
|
|
1062
1101
|
const r = resp;
|
|
1063
1102
|
return typeof r.stdout === "string" || typeof r.stderr === "string";
|
|
1064
1103
|
}
|
|
1065
1104
|
function isGrepContent(resp) {
|
|
1066
1105
|
const r = resp;
|
|
1067
|
-
return r.mode === "content" && typeof r.content === "string";
|
|
1106
|
+
return (r.mode === "content" || r.mode === "count") && typeof r.content === "string";
|
|
1068
1107
|
}
|
|
1069
1108
|
function blocksOf(resp) {
|
|
1070
1109
|
const parts = [];
|
|
@@ -1080,6 +1119,7 @@ function readResult(resp) {
|
|
|
1080
1119
|
const text = outputOf(resp);
|
|
1081
1120
|
const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
|
|
1082
1121
|
const info = { isError, bytes: Buffer.byteLength(text), text };
|
|
1122
|
+
if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && isShellShape(resp)) info.shape = resp;
|
|
1083
1123
|
if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && !isShellShape(resp)) {
|
|
1084
1124
|
if (textSlot(resp) !== null) info.shape = resp;
|
|
1085
1125
|
else info.keep = true;
|
|
@@ -1119,8 +1159,11 @@ function decodeClaudeShape(raw, agent, ownPrefix, sources) {
|
|
|
1119
1159
|
return ev;
|
|
1120
1160
|
}
|
|
1121
1161
|
function replaceShape(ev, output) {
|
|
1122
|
-
if (ev.tool?.canonicalName === "Bash") return { stdout: output, stderr: "", interrupted: false };
|
|
1123
1162
|
const shape = ev.result?.shape;
|
|
1163
|
+
if (ev.tool?.canonicalName === "Bash") {
|
|
1164
|
+
const { persistedOutputPath: _p, persistedOutputSize: _s, ...host } = shape ?? {};
|
|
1165
|
+
return { interrupted: false, ...host, stdout: output, stderr: "" };
|
|
1166
|
+
}
|
|
1124
1167
|
const slot = shape === void 0 ? null : textSlot(shape);
|
|
1125
1168
|
if (shape !== void 0 && slot !== null) return slot.put(shape, output);
|
|
1126
1169
|
if (ev.result?.blocks === true) return [{ type: "text", text: output }];
|
|
@@ -1515,7 +1558,8 @@ function encode6(ev, d, _extra) {
|
|
|
1515
1558
|
}
|
|
1516
1559
|
|
|
1517
1560
|
// src/adapters/kiro.ts
|
|
1518
|
-
var TOOL_NAME_PREFIX7 = "
|
|
1561
|
+
var TOOL_NAME_PREFIX7 = "mcp_context_mode_";
|
|
1562
|
+
var LEGACY_TOOL_NAME_PREFIX = "mcp_context-mode_";
|
|
1519
1563
|
var KIRO_EVENTS = {
|
|
1520
1564
|
SessionStart: "SessionStart",
|
|
1521
1565
|
agentSpawn: "SessionStart",
|
|
@@ -1527,6 +1571,7 @@ var KIRO_EVENTS = {
|
|
|
1527
1571
|
PostToolUse: "PostToolUse",
|
|
1528
1572
|
postToolUse: "PostToolUse"
|
|
1529
1573
|
};
|
|
1574
|
+
var PROMPT_FIELD = "prompt";
|
|
1530
1575
|
var PROMPT_ENV = "USER_PROMPT";
|
|
1531
1576
|
var MCP_PREFIX3 = "mcp_";
|
|
1532
1577
|
var SHELL_TOOL_NAMES4 = Object.freeze(["execute_bash", "execute_pwsh", "shell"]);
|
|
@@ -1535,6 +1580,7 @@ var MCP_SEP3 = "_";
|
|
|
1535
1580
|
var KIRO_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1536
1581
|
function canonicalName5(name) {
|
|
1537
1582
|
if (name.startsWith(TOOL_NAME_PREFIX7)) return name.slice(TOOL_NAME_PREFIX7.length);
|
|
1583
|
+
if (name.startsWith(LEGACY_TOOL_NAME_PREFIX)) return name.slice(LEGACY_TOOL_NAME_PREFIX.length);
|
|
1538
1584
|
if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
|
|
1539
1585
|
if (!name.startsWith(MCP_PREFIX3)) return name;
|
|
1540
1586
|
const rest = name.slice(MCP_PREFIX3.length);
|
|
@@ -1555,7 +1601,8 @@ function decode7(raw) {
|
|
|
1555
1601
|
const ev = { event, agent: "kiro", sessionId: String(p.session_id ?? ""), cwd: String(p.cwd ?? "") };
|
|
1556
1602
|
if (event === "SessionStart" && typeof p.source === "string" && KIRO_SOURCES[p.source] !== void 0) ev.source = KIRO_SOURCES[p.source];
|
|
1557
1603
|
if (event === "UserPromptSubmit") {
|
|
1558
|
-
const
|
|
1604
|
+
const field = p[PROMPT_FIELD];
|
|
1605
|
+
const prompt = typeof field === "string" ? field : process.env[PROMPT_ENV];
|
|
1559
1606
|
if (prompt !== void 0) ev.prompt = prompt;
|
|
1560
1607
|
}
|
|
1561
1608
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
@@ -1567,7 +1614,7 @@ function decode7(raw) {
|
|
|
1567
1614
|
return ev;
|
|
1568
1615
|
}
|
|
1569
1616
|
function encode7(ev, d, _extra) {
|
|
1570
|
-
if (ev.event === "UserPromptSubmit") return { stdout: "", exitCode: 0 };
|
|
1617
|
+
if (ev.event === "UserPromptSubmit") return { stdout: d.kind === "hint" ? d.text : "", exitCode: 0 };
|
|
1571
1618
|
switch (d.kind) {
|
|
1572
1619
|
case "allow":
|
|
1573
1620
|
return { stdout: "", exitCode: 0 };
|
|
@@ -1736,8 +1783,8 @@ var ADAPTERS = Object.freeze([
|
|
|
1736
1783
|
hookTimeoutMs: HOOK_TIMEOUT_MS,
|
|
1737
1784
|
denyChannel: "deny-reason",
|
|
1738
1785
|
hookChannel: { kind: "package", path: "hooks/claude-code.json" },
|
|
1739
|
-
skillChannel: { kind: "package", path: "
|
|
1740
|
-
// ADR-0020, D-
|
|
1786
|
+
skillChannel: { kind: "package", path: "skills" },
|
|
1787
|
+
// ADR-0020, D-R33-CC-SKILLS-1: Claude Code always loads <plugin>/skills, shared with gemini and qwen
|
|
1741
1788
|
decode,
|
|
1742
1789
|
encode
|
|
1743
1790
|
},
|
|
@@ -1926,7 +1973,7 @@ var DUMP_REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "copilot-cli", "
|
|
|
1926
1973
|
function dumpRunsThenReplaces(row5) {
|
|
1927
1974
|
return DUMP_REPLACE_ROWS.has(row5.id) && hasReplace(row5);
|
|
1928
1975
|
}
|
|
1929
|
-
var RECALL_ROWS = /* @__PURE__ */ new Set(["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "zcode"]);
|
|
1976
|
+
var RECALL_ROWS = /* @__PURE__ */ new Set(["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "zcode", "kiro"]);
|
|
1930
1977
|
function hasRecall(row5) {
|
|
1931
1978
|
return RECALL_ROWS.has(row5.id);
|
|
1932
1979
|
}
|
|
@@ -3277,14 +3324,29 @@ function copilotDirOf(env, home) {
|
|
|
3277
3324
|
function kiroDirOf(env, home, platform = process.platform) {
|
|
3278
3325
|
const p = platform === "win32" ? win32 : posix;
|
|
3279
3326
|
const fallback = p.join(home, ...AGENT_HOME_DIR.kiro);
|
|
3280
|
-
const dir = env[KIRO_HOME_ENV];
|
|
3327
|
+
const dir = env[KIRO_HOME_ENV]?.trim();
|
|
3281
3328
|
if (dir === void 0 || dir === "" || !p.isAbsolute(dir)) return fallback;
|
|
3282
3329
|
if (platform === "win32" && p.parse(dir).root.length < 2) return fallback;
|
|
3283
3330
|
const abs = p.resolve(dir);
|
|
3284
|
-
|
|
3285
|
-
const
|
|
3331
|
+
const real2 = platform === process.platform ? realOrSelf : (x) => x;
|
|
3332
|
+
const target = real2(abs);
|
|
3333
|
+
if (p.parse(target).root === target) return fallback;
|
|
3334
|
+
const up = p.relative(target, real2(p.resolve(home)));
|
|
3286
3335
|
if (!p.isAbsolute(up) && up.split(p.sep)[0] !== "..") return fallback;
|
|
3287
|
-
return
|
|
3336
|
+
return abs;
|
|
3337
|
+
}
|
|
3338
|
+
function realOrSelf(path7) {
|
|
3339
|
+
const tail = [];
|
|
3340
|
+
for (let at2 = path7; ; ) {
|
|
3341
|
+
try {
|
|
3342
|
+
return join(realpathSync.native(at2), ...tail.reverse());
|
|
3343
|
+
} catch {
|
|
3344
|
+
const up = dirname(at2);
|
|
3345
|
+
if (up === at2) return path7;
|
|
3346
|
+
tail.push(basename(at2));
|
|
3347
|
+
at2 = up;
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
3288
3350
|
}
|
|
3289
3351
|
function claudeDirOf(env, home) {
|
|
3290
3352
|
const dir = env[CLAUDE_CONFIG_DIR_ENV];
|
|
@@ -7854,7 +7916,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
7854
7916
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
7855
7917
|
return { end: start + r.read, written: r.written };
|
|
7856
7918
|
}
|
|
7857
|
-
function merge(src, blocks,
|
|
7919
|
+
function merge(src, blocks, join27, cap, lineCut) {
|
|
7858
7920
|
const out = [];
|
|
7859
7921
|
const scratch = new Uint8Array(cap);
|
|
7860
7922
|
let wide;
|
|
@@ -7864,7 +7926,7 @@ function merge(src, blocks, join26, cap, lineCut) {
|
|
|
7864
7926
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
7865
7927
|
};
|
|
7866
7928
|
for (const b of blocks) {
|
|
7867
|
-
if (cur !== void 0 && !
|
|
7929
|
+
if (cur !== void 0 && !join27) {
|
|
7868
7930
|
emit(cur.start, cur.end, curBytes);
|
|
7869
7931
|
cur = void 0;
|
|
7870
7932
|
}
|
|
@@ -20858,21 +20920,43 @@ var ctxBatch = Object.freeze({
|
|
|
20858
20920
|
});
|
|
20859
20921
|
|
|
20860
20922
|
// src/core/tools/doctor.ts
|
|
20861
|
-
import { readdirSync as readdirSync6, readFileSync as readFileSync13, existsSync as
|
|
20862
|
-
import { basename as basename5,
|
|
20923
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync13, existsSync as existsSync14 } from "node:fs";
|
|
20924
|
+
import { basename as basename5, join as join17 } from "node:path";
|
|
20925
|
+
|
|
20926
|
+
// src/core/ops/bundle-dir.ts
|
|
20927
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
20928
|
+
import { dirname as dirname5, join as join8 } from "node:path";
|
|
20929
|
+
import { fileURLToPath } from "node:url";
|
|
20930
|
+
function bundleDirOf(argv1, moduleFile) {
|
|
20931
|
+
const own2 = dirname5(argv1);
|
|
20932
|
+
if (existsSync3(join8(own2, SERVER_ENTRY_FILE))) return own2;
|
|
20933
|
+
let dir = dirname5(moduleFile);
|
|
20934
|
+
for (; ; ) {
|
|
20935
|
+
if (existsSync3(join8(dir, SERVER_ENTRY_FILE))) return dir;
|
|
20936
|
+
const up = dirname5(dir);
|
|
20937
|
+
if (up === dir) return own2;
|
|
20938
|
+
dir = up;
|
|
20939
|
+
}
|
|
20940
|
+
}
|
|
20941
|
+
var memo;
|
|
20942
|
+
function ownBundleDir() {
|
|
20943
|
+
const argv1 = process.argv[1] ?? "";
|
|
20944
|
+
if (memo?.argv1 !== argv1) memo = { argv1, dir: bundleDirOf(argv1, fileURLToPath(import.meta.url)) };
|
|
20945
|
+
return memo.dir;
|
|
20946
|
+
}
|
|
20863
20947
|
|
|
20864
20948
|
// src/core/ops/doctor-config.ts
|
|
20865
|
-
import { existsSync as
|
|
20866
|
-
import { join as
|
|
20949
|
+
import { existsSync as existsSync7, readdirSync as readdirSync4 } from "node:fs";
|
|
20950
|
+
import { join as join12 } from "node:path";
|
|
20867
20951
|
|
|
20868
20952
|
// src/core/ops/detect-v1.ts
|
|
20869
|
-
import { existsSync as
|
|
20953
|
+
import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync7 } from "node:fs";
|
|
20870
20954
|
import { tmpdir } from "node:os";
|
|
20871
|
-
import { join as
|
|
20955
|
+
import { join as join10 } from "node:path";
|
|
20872
20956
|
|
|
20873
20957
|
// src/core/ops/host-config.ts
|
|
20874
|
-
import { existsSync as
|
|
20875
|
-
import { dirname as
|
|
20958
|
+
import { existsSync as existsSync4, readFileSync as readFileSync6 } from "node:fs";
|
|
20959
|
+
import { dirname as dirname6, join as join9 } from "node:path";
|
|
20876
20960
|
|
|
20877
20961
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
20878
20962
|
var KEYS2 = {
|
|
@@ -22989,10 +23073,10 @@ function formatOf(path7) {
|
|
|
22989
23073
|
function readHostConfig(agent, path7) {
|
|
22990
23074
|
let file2 = path7;
|
|
22991
23075
|
if (agent === "opencode") {
|
|
22992
|
-
const jsonc =
|
|
22993
|
-
if (
|
|
23076
|
+
const jsonc = join9(dirname6(path7), OPENCODE_CONFIG_FILES[0]);
|
|
23077
|
+
if (existsSync4(jsonc)) file2 = jsonc;
|
|
22994
23078
|
}
|
|
22995
|
-
const raw =
|
|
23079
|
+
const raw = existsSync4(file2) ? readFileSync6(file2, "utf8") : "";
|
|
22996
23080
|
return { agent, text: hostText(raw), format: agent === "opencode" && !file2.endsWith(TOML_EXT) ? "jsonc" : formatOf(file2), path: file2, layout: hostLayout(raw) };
|
|
22997
23081
|
}
|
|
22998
23082
|
function stripJsonComments(text) {
|
|
@@ -23337,7 +23421,7 @@ function setText(agent, path7, text, format, key, value) {
|
|
|
23337
23421
|
}
|
|
23338
23422
|
}
|
|
23339
23423
|
function serverScript() {
|
|
23340
|
-
return
|
|
23424
|
+
return join9(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
23341
23425
|
}
|
|
23342
23426
|
function isNodeCommand(command) {
|
|
23343
23427
|
if (typeof command !== "string") return false;
|
|
@@ -23353,7 +23437,7 @@ function ownMcpValue(agent, node, server2) {
|
|
|
23353
23437
|
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node, [MCP_ARGS_FIELD]: [server2, AGENT_ARG, agent, ...tail] };
|
|
23354
23438
|
}
|
|
23355
23439
|
function opencodePluginFile() {
|
|
23356
|
-
return
|
|
23440
|
+
return ownBundleDir();
|
|
23357
23441
|
}
|
|
23358
23442
|
function listTarget(key, own2, v1, alt = []) {
|
|
23359
23443
|
return {
|
|
@@ -23512,7 +23596,7 @@ function flatCommands(events, prefix) {
|
|
|
23512
23596
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
23513
23597
|
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep4) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep4) + sep4));
|
|
23514
23598
|
function dataDir(dir, reason, out) {
|
|
23515
|
-
if (
|
|
23599
|
+
if (existsSync5(dir)) out.push(finding(dir, "", reason));
|
|
23516
23600
|
}
|
|
23517
23601
|
function mcpEntry(file2, doc, out) {
|
|
23518
23602
|
if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
|
|
@@ -23520,7 +23604,7 @@ function mcpEntry(file2, doc, out) {
|
|
|
23520
23604
|
}
|
|
23521
23605
|
}
|
|
23522
23606
|
function claudeShapeSettings(agentHome, out) {
|
|
23523
|
-
const file2 =
|
|
23607
|
+
const file2 = join10(agentHome, SETTINGS_FILE);
|
|
23524
23608
|
const doc = readJson(file2);
|
|
23525
23609
|
for (const c of nestedCommands(doc)) {
|
|
23526
23610
|
if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
|
|
@@ -23540,49 +23624,49 @@ function v1HookFile(file2, out) {
|
|
|
23540
23624
|
function scanClaudeCode(home, agentHome, out) {
|
|
23541
23625
|
claudeShapeSettings(agentHome, out);
|
|
23542
23626
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
23543
|
-
const file2 =
|
|
23544
|
-
if (
|
|
23627
|
+
const file2 = join10(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
23628
|
+
if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
23545
23629
|
}
|
|
23546
|
-
const userFile =
|
|
23630
|
+
const userFile = join10(home, CLAUDE_USER_CONFIG_FILE);
|
|
23547
23631
|
mcpEntry(userFile, readJson(userFile), out);
|
|
23548
|
-
dataDir(
|
|
23632
|
+
dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23549
23633
|
}
|
|
23550
23634
|
function scanCodex(agentHome, out) {
|
|
23551
|
-
const hooksFile =
|
|
23635
|
+
const hooksFile = join10(agentHome, HOOKS_JSON_FILE);
|
|
23552
23636
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
23553
23637
|
if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
|
|
23554
23638
|
out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
|
|
23555
23639
|
}
|
|
23556
23640
|
}
|
|
23557
|
-
const tomlFile =
|
|
23641
|
+
const tomlFile = join10(agentHome, CONFIG_TOML_FILE);
|
|
23558
23642
|
const config2 = readTomlValue(tomlFile);
|
|
23559
23643
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
23560
23644
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
23561
23645
|
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config2, span2.path))) continue;
|
|
23562
23646
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
23563
23647
|
}
|
|
23564
|
-
dataDir(
|
|
23648
|
+
dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23565
23649
|
}
|
|
23566
23650
|
function scanGemini(agentHome, out) {
|
|
23567
|
-
const file2 =
|
|
23651
|
+
const file2 = join10(agentHome, SETTINGS_FILE);
|
|
23568
23652
|
for (const c of nestedCommands(readJson(file2))) {
|
|
23569
23653
|
if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
|
|
23570
23654
|
}
|
|
23571
|
-
dataDir(
|
|
23655
|
+
dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
|
|
23572
23656
|
}
|
|
23573
23657
|
function scanVscode(agentHome, project, out) {
|
|
23574
23658
|
if (project !== void 0) {
|
|
23575
|
-
v1HookFile(
|
|
23576
|
-
const mcpFile2 =
|
|
23659
|
+
v1HookFile(join10(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
23660
|
+
const mcpFile2 = join10(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
23577
23661
|
const doc = readJson(mcpFile2);
|
|
23578
23662
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
23579
23663
|
const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
23580
23664
|
if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
|
|
23581
23665
|
out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
23582
23666
|
}
|
|
23583
|
-
dataDir(
|
|
23667
|
+
dataDir(join10(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
23584
23668
|
}
|
|
23585
|
-
dataDir(
|
|
23669
|
+
dataDir(join10(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
23586
23670
|
}
|
|
23587
23671
|
function jsonFiles(dir) {
|
|
23588
23672
|
try {
|
|
@@ -23592,10 +23676,10 @@ function jsonFiles(dir) {
|
|
|
23592
23676
|
}
|
|
23593
23677
|
}
|
|
23594
23678
|
function scanKiro(agentHome, project, out) {
|
|
23595
|
-
const agentsDir =
|
|
23596
|
-
const defaultFile =
|
|
23679
|
+
const agentsDir = join10(agentHome, KIRO_AGENTS_DIR);
|
|
23680
|
+
const defaultFile = join10(agentHome, ...KIRO_AGENT_FILE);
|
|
23597
23681
|
for (const name of jsonFiles(agentsDir)) {
|
|
23598
|
-
const file2 =
|
|
23682
|
+
const file2 = join10(agentsDir, name);
|
|
23599
23683
|
const doc = readJson(file2);
|
|
23600
23684
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
23601
23685
|
out.push(finding(file2, "", V1_REASON.kiroAgentFile));
|
|
@@ -23606,25 +23690,25 @@ function scanKiro(agentHome, project, out) {
|
|
|
23606
23690
|
if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
|
|
23607
23691
|
}
|
|
23608
23692
|
}
|
|
23609
|
-
const steeringDocs = [
|
|
23610
|
-
if (project !== void 0) steeringDocs.push(
|
|
23693
|
+
const steeringDocs = [join10(agentHome, ...KIRO_STEERING_FILE)];
|
|
23694
|
+
if (project !== void 0) steeringDocs.push(join10(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
23611
23695
|
for (const file2 of steeringDocs) {
|
|
23612
|
-
if (
|
|
23696
|
+
if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
23613
23697
|
}
|
|
23614
|
-
dataDir(
|
|
23698
|
+
dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23615
23699
|
}
|
|
23616
23700
|
function scanPi(piAgentDir, agentHome, out) {
|
|
23617
|
-
const file2 =
|
|
23701
|
+
const file2 = join10(piAgentDir, SETTINGS_FILE);
|
|
23618
23702
|
const doc = readJson(file2);
|
|
23619
23703
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
23620
23704
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
23621
23705
|
if (spec === V1_PI_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
23622
23706
|
});
|
|
23623
|
-
dataDir(
|
|
23707
|
+
dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23624
23708
|
}
|
|
23625
23709
|
function scanOpencode(agentHome, out) {
|
|
23626
23710
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
23627
|
-
const file2 =
|
|
23711
|
+
const file2 = join10(agentHome, name);
|
|
23628
23712
|
const doc = readJson(file2);
|
|
23629
23713
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
23630
23714
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
|
|
@@ -23634,13 +23718,13 @@ function scanOpencode(agentHome, out) {
|
|
|
23634
23718
|
}
|
|
23635
23719
|
}
|
|
23636
23720
|
function scanZcode(agentHome, out) {
|
|
23637
|
-
const configFile =
|
|
23721
|
+
const configFile = join10(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
23638
23722
|
const config2 = readJson(configFile);
|
|
23639
23723
|
const events = isObj(config2) && isObj(config2[HOOKS_KEY]) ? config2[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
23640
23724
|
for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
23641
23725
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
|
|
23642
23726
|
}
|
|
23643
|
-
const hooksFile =
|
|
23727
|
+
const hooksFile = join10(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
23644
23728
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
23645
23729
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
|
|
23646
23730
|
}
|
|
@@ -23664,14 +23748,14 @@ function firstTmpMatch(dir) {
|
|
|
23664
23748
|
}
|
|
23665
23749
|
}
|
|
23666
23750
|
function scanAll(home, tmp, out) {
|
|
23667
|
-
const root =
|
|
23668
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
23751
|
+
const root = join10(home, DATA_ROOT.slice(1));
|
|
23752
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join10(root, name), V1_REASON.dataRoot, out);
|
|
23669
23753
|
if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
23670
23754
|
}
|
|
23671
23755
|
function detectV1(agent, home, scope = {}) {
|
|
23672
23756
|
const out = [];
|
|
23673
23757
|
const project = scope.project;
|
|
23674
|
-
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 :
|
|
23758
|
+
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 : join10(home, ...AGENT_HOME_DIR[agent]);
|
|
23675
23759
|
switch (agent) {
|
|
23676
23760
|
case "claude-code":
|
|
23677
23761
|
scanClaudeCode(home, agentHome, out);
|
|
@@ -23684,11 +23768,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23684
23768
|
break;
|
|
23685
23769
|
case "qwen":
|
|
23686
23770
|
claudeShapeSettings(agentHome, out);
|
|
23687
|
-
dataDir(
|
|
23771
|
+
dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23688
23772
|
break;
|
|
23689
23773
|
case "copilot-cli":
|
|
23690
|
-
v1HookFile(
|
|
23691
|
-
dataDir(
|
|
23774
|
+
v1HookFile(join10(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
23775
|
+
dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23692
23776
|
break;
|
|
23693
23777
|
case "vscode":
|
|
23694
23778
|
scanVscode(agentHome, project, out);
|
|
@@ -23697,7 +23781,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23697
23781
|
scanKiro(agentHome, project, out);
|
|
23698
23782
|
break;
|
|
23699
23783
|
case "pi":
|
|
23700
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
23784
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join10(agentHome, PI_AGENT_DIR), agentHome, out);
|
|
23701
23785
|
break;
|
|
23702
23786
|
// D-WIN-PIDIR-1: empty is unset
|
|
23703
23787
|
case "opencode":
|
|
@@ -23712,9 +23796,9 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23712
23796
|
}
|
|
23713
23797
|
|
|
23714
23798
|
// src/core/ops/plugin-root.ts
|
|
23715
|
-
import { existsSync as
|
|
23716
|
-
import { dirname as
|
|
23717
|
-
import { fileURLToPath } from "node:url";
|
|
23799
|
+
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
|
|
23800
|
+
import { dirname as dirname7, isAbsolute as isAbsolute2, join as join11, sep as sep3 } from "node:path";
|
|
23801
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
23718
23802
|
function missing(agent, path7) {
|
|
23719
23803
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path7 });
|
|
23720
23804
|
}
|
|
@@ -23761,8 +23845,8 @@ var readOrNull = (file2) => {
|
|
|
23761
23845
|
};
|
|
23762
23846
|
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
23763
23847
|
function enabledPlugins(claudeDir, project) {
|
|
23764
|
-
const files = [
|
|
23765
|
-
if (project !== void 0) files.push(
|
|
23848
|
+
const files = [join11(claudeDir, SETTINGS_FILE)];
|
|
23849
|
+
if (project !== void 0) files.push(join11(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join11(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
|
|
23766
23850
|
const out = {};
|
|
23767
23851
|
for (const file2 of files) {
|
|
23768
23852
|
const text = readOrNull(file2);
|
|
@@ -23775,13 +23859,13 @@ function enabledPlugins(claudeDir, project) {
|
|
|
23775
23859
|
function marketplaceChoice(env, worktree) {
|
|
23776
23860
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
23777
23861
|
const script = process.argv[1];
|
|
23778
|
-
const ownReal = script === void 0 || script === "" ? null : realOrNull(
|
|
23862
|
+
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
23779
23863
|
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
23780
23864
|
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
23781
|
-
const record4 = readOrNull(
|
|
23865
|
+
const record4 = readOrNull(join11(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
23782
23866
|
const recorded = record4 === null ? [] : recordedInstalls(record4);
|
|
23783
23867
|
if (recorded.length === 0) return { record: false };
|
|
23784
|
-
const live = recorded.filter((r) =>
|
|
23868
|
+
const live = recorded.filter((r) => existsSync6(r.installPath));
|
|
23785
23869
|
const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
|
|
23786
23870
|
if (mine !== void 0) return { root: mine.installPath };
|
|
23787
23871
|
const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
|
|
@@ -23801,18 +23885,18 @@ function marketplaceChoice(env, worktree) {
|
|
|
23801
23885
|
}
|
|
23802
23886
|
function marketplaceRoot(adapter, env, worktree) {
|
|
23803
23887
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
23804
|
-
const plugins =
|
|
23805
|
-
const cache =
|
|
23888
|
+
const plugins = join11(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
23889
|
+
const cache = join11(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
23806
23890
|
const script = process.argv[1];
|
|
23807
|
-
const ownReal = script === void 0 || script === "" ? null : realOrNull(
|
|
23891
|
+
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
23808
23892
|
const choice = marketplaceChoice(env, worktree);
|
|
23809
23893
|
if ("root" in choice) return choice.root;
|
|
23810
23894
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
23811
23895
|
const cacheReal = realOrNull(cache);
|
|
23812
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep3) &&
|
|
23813
|
-
const pattern =
|
|
23814
|
-
if (!
|
|
23815
|
-
const found = readdirSync3(cache).sort().map((marketplace) =>
|
|
23896
|
+
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep3) && existsSync6(join11(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
23897
|
+
const pattern = join11(cache, "*", PLUGIN_NAME);
|
|
23898
|
+
if (!existsSync6(cache)) throw missing(adapter.id, pattern);
|
|
23899
|
+
const found = readdirSync3(cache).sort().map((marketplace) => join11(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync6(dir));
|
|
23816
23900
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
23817
23901
|
return found[0];
|
|
23818
23902
|
}
|
|
@@ -23820,13 +23904,13 @@ function configEntryRoot(adapter, env) {
|
|
|
23820
23904
|
const spec = OWN_MCP_ENTRY[adapter.id];
|
|
23821
23905
|
if (spec === void 0) throw missing(adapter.id, SERVER_KEY);
|
|
23822
23906
|
const file2 = ownMcpFileOf(adapter.id, spec.file, env, requireHomeDir(env));
|
|
23823
|
-
if (!
|
|
23907
|
+
if (!existsSync6(file2)) throw missing(adapter.id, file2);
|
|
23824
23908
|
const current = readHostConfig(adapter.id, file2);
|
|
23825
23909
|
const value = parseHostConfig(adapter.id, file2, current.text, current.format);
|
|
23826
23910
|
const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
|
|
23827
23911
|
const script = Array.isArray(args) ? args[0] : void 0;
|
|
23828
23912
|
if (typeof script !== "string" || !isAbsolute2(script)) throw missing(adapter.id, file2);
|
|
23829
|
-
return
|
|
23913
|
+
return dirname7(script);
|
|
23830
23914
|
}
|
|
23831
23915
|
function candidate(adapter, env, worktree) {
|
|
23832
23916
|
switch (adapter.installMode) {
|
|
@@ -23837,11 +23921,11 @@ function candidate(adapter, env, worktree) {
|
|
|
23837
23921
|
case "hooks+mcp":
|
|
23838
23922
|
return configEntryRoot(adapter, env);
|
|
23839
23923
|
case "extension":
|
|
23840
|
-
return
|
|
23924
|
+
return join11(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id], EXTENSIONS_DIR_NAME, PLUGIN_NAME);
|
|
23841
23925
|
case "plugin":
|
|
23842
|
-
return
|
|
23926
|
+
return join11(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
23843
23927
|
case "in-process":
|
|
23844
|
-
return
|
|
23928
|
+
return dirname7(fileURLToPath2(import.meta.url));
|
|
23845
23929
|
}
|
|
23846
23930
|
}
|
|
23847
23931
|
function resolvePluginRoot(adapter, env, worktree) {
|
|
@@ -23930,11 +24014,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
23930
24014
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
23931
24015
|
function mcpFile(row5, home, env) {
|
|
23932
24016
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
23933
|
-
if (row5.id === "codex") return
|
|
24017
|
+
if (row5.id === "codex") return join12(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
23934
24018
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
23935
|
-
if (row5.id === "opencode") return
|
|
24019
|
+
if (row5.id === "opencode") return join12(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
23936
24020
|
if (row5.id === "pi") {
|
|
23937
|
-
return
|
|
24021
|
+
return join12(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
23938
24022
|
}
|
|
23939
24023
|
return null;
|
|
23940
24024
|
}
|
|
@@ -23947,27 +24031,27 @@ function codexNativeDir(env, home) {
|
|
|
23947
24031
|
const codexDir = codexDirOf(env, home);
|
|
23948
24032
|
let enabled;
|
|
23949
24033
|
try {
|
|
23950
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
24034
|
+
enabled = hostConfigValueAt(readParsed("codex", join12(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
23951
24035
|
} catch {
|
|
23952
24036
|
return null;
|
|
23953
24037
|
}
|
|
23954
24038
|
if (enabled !== true) return null;
|
|
23955
|
-
const cache =
|
|
23956
|
-
if (!
|
|
24039
|
+
const cache = join12(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
24040
|
+
if (!existsSync7(cache)) return null;
|
|
23957
24041
|
const found = [];
|
|
23958
24042
|
for (const market of readdirSync4(cache)) {
|
|
23959
|
-
const plugin =
|
|
23960
|
-
if (!
|
|
24043
|
+
const plugin = join12(cache, market, SERVER_KEY);
|
|
24044
|
+
if (!existsSync7(plugin)) continue;
|
|
23961
24045
|
for (const version2 of readdirSync4(plugin).sort()) {
|
|
23962
|
-
const dir =
|
|
23963
|
-
if (
|
|
24046
|
+
const dir = join12(plugin, version2, CODEX_PLUGIN_SUBDIR);
|
|
24047
|
+
if (existsSync7(join12(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
23964
24048
|
}
|
|
23965
24049
|
}
|
|
23966
24050
|
return found.length === 0 ? null : found[found.length - 1];
|
|
23967
24051
|
}
|
|
23968
24052
|
function nativeMcpWrong(dir, row5) {
|
|
23969
24053
|
try {
|
|
23970
|
-
const entry = hostConfigValueAt(readParsed(row5.id,
|
|
24054
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join12(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
23971
24055
|
if (!isObject4(entry)) return true;
|
|
23972
24056
|
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
23973
24057
|
const script = args[0];
|
|
@@ -23976,6 +24060,17 @@ function nativeMcpWrong(dir, row5) {
|
|
|
23976
24060
|
return true;
|
|
23977
24061
|
}
|
|
23978
24062
|
}
|
|
24063
|
+
function isOwnOpencodeEntry(entry, key, own2) {
|
|
24064
|
+
const spec = isObject4(entry) ? entry[OPENCODE_PACKAGE_FIELD] : entry;
|
|
24065
|
+
if (typeof spec !== "string") return false;
|
|
24066
|
+
if (spec === OPENCODE_GIT_SPEC || spec.startsWith(OPENCODE_NPM_SPEC_PREFIX) || own2.includes(spec)) return true;
|
|
24067
|
+
return key === OPENCODE_PLUGINS_KEY && spec === SERVER_KEY;
|
|
24068
|
+
}
|
|
24069
|
+
function opencodeListed(file2) {
|
|
24070
|
+
const { value } = readParsed("opencode", file2);
|
|
24071
|
+
const own2 = [opencodePluginFile()];
|
|
24072
|
+
return [OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list2(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own2)));
|
|
24073
|
+
}
|
|
23979
24074
|
function mcpWrong(row5, home, env, worktree) {
|
|
23980
24075
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23981
24076
|
if (native !== null) return nativeMcpWrong(native, row5);
|
|
@@ -23985,6 +24080,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
23985
24080
|
resolvePluginRoot(row5, env, worktree);
|
|
23986
24081
|
return false;
|
|
23987
24082
|
}
|
|
24083
|
+
if (row5.id === "opencode") return !opencodeListed(file2);
|
|
23988
24084
|
const cur = readHostConfig(row5.id, file2);
|
|
23989
24085
|
return mergeOwnEntries(row5.id, cur.text, cur.format, row5, { nodePath: true, listEntries: [opencodePluginFile()] }).edits.length > 0;
|
|
23990
24086
|
} catch {
|
|
@@ -23994,7 +24090,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
23994
24090
|
function hookFile(row5, spec, home, env, worktree) {
|
|
23995
24091
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
23996
24092
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23997
|
-
const file2 = native !== null ?
|
|
24093
|
+
const file2 = native !== null ? join12(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join12(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join12(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join12(kiroDirOf(env, home), ...spec.file.slice(1)) : join12(root, ...spec.file);
|
|
23998
24094
|
return file2;
|
|
23999
24095
|
}
|
|
24000
24096
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -24005,7 +24101,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
24005
24101
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
24006
24102
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
24007
24103
|
if (row5.id === "codex") {
|
|
24008
|
-
const config2 = readParsed(row5.id,
|
|
24104
|
+
const config2 = readParsed(row5.id, join12(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
24009
24105
|
if (hostConfigValueAt(config2, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
24010
24106
|
}
|
|
24011
24107
|
} catch {
|
|
@@ -24063,10 +24159,10 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
24063
24159
|
}
|
|
24064
24160
|
function checkDoubleFire(agent, worktree) {
|
|
24065
24161
|
if (agent !== "claude-code" && agent !== "vscode") return pass("D5b");
|
|
24066
|
-
const claude = parsedOrNull(agent,
|
|
24162
|
+
const claude = parsedOrNull(agent, join12(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
24067
24163
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
24068
24164
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
24069
|
-
const vscode = parsedOrNull(agent,
|
|
24165
|
+
const vscode = parsedOrNull(agent, join12(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
24070
24166
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
24071
24167
|
return hooksOn && useClaudeHooks ? fail2("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
|
|
24072
24168
|
}
|
|
@@ -24077,7 +24173,7 @@ function configPaths(row5, env, worktree) {
|
|
|
24077
24173
|
const mcp = mcpFile(row5, home, env);
|
|
24078
24174
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
24079
24175
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24080
|
-
if (native !== null) out.push({ label: "Codex plugin MCP", path:
|
|
24176
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join12(native, CODEX_PLUGIN_MCP_FILE) });
|
|
24081
24177
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
24082
24178
|
if (spec !== null) {
|
|
24083
24179
|
try {
|
|
@@ -24097,7 +24193,7 @@ function configPaths(row5, env, worktree) {
|
|
|
24097
24193
|
}
|
|
24098
24194
|
|
|
24099
24195
|
// src/core/ops/doctor-db.ts
|
|
24100
|
-
import { existsSync as
|
|
24196
|
+
import { existsSync as existsSync8, statSync as statSync5 } from "node:fs";
|
|
24101
24197
|
var unknown2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
|
|
24102
24198
|
var pass2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
|
|
24103
24199
|
var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -24139,15 +24235,15 @@ function orphanFiles(dbPath) {
|
|
|
24139
24235
|
const files = [];
|
|
24140
24236
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
24141
24237
|
const path7 = dbPath + suffix;
|
|
24142
|
-
if (
|
|
24238
|
+
if (existsSync8(path7)) files.push({ path: path7, bytes: statSync5(path7).size });
|
|
24143
24239
|
}
|
|
24144
|
-
return files.length > 0 && !
|
|
24240
|
+
return files.length > 0 && !existsSync8(dbPath) ? files : [];
|
|
24145
24241
|
}
|
|
24146
24242
|
async function checkDb(project) {
|
|
24147
24243
|
const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
|
|
24148
24244
|
const orphan = orphanFiles(project.dbPath);
|
|
24149
24245
|
if (orphan.length > 0) return { row: fail3(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
|
|
24150
|
-
if (!
|
|
24246
|
+
if (!existsSync8(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
24151
24247
|
const sqlite = await loadSqlite2();
|
|
24152
24248
|
if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
|
|
24153
24249
|
let raw = null;
|
|
@@ -24173,7 +24269,7 @@ async function checkDb(project) {
|
|
|
24173
24269
|
}
|
|
24174
24270
|
}
|
|
24175
24271
|
async function checkIndex(project) {
|
|
24176
|
-
if (!
|
|
24272
|
+
if (!existsSync8(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
|
|
24177
24273
|
const sqlite = await loadSqlite2();
|
|
24178
24274
|
if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
|
|
24179
24275
|
let raw = null;
|
|
@@ -24190,8 +24286,8 @@ async function checkIndex(project) {
|
|
|
24190
24286
|
}
|
|
24191
24287
|
|
|
24192
24288
|
// src/core/ops/doctor-env.ts
|
|
24193
|
-
import { existsSync as
|
|
24194
|
-
import { isAbsolute as isAbsolute3, join as
|
|
24289
|
+
import { existsSync as existsSync9, readFileSync as readFileSync9, realpathSync as realpathSync5 } from "node:fs";
|
|
24290
|
+
import { isAbsolute as isAbsolute3, join as join13, relative as relative2 } from "node:path";
|
|
24195
24291
|
function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
24196
24292
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
24197
24293
|
}
|
|
@@ -24203,7 +24299,7 @@ function fail4(id2, detail, fixCommand) {
|
|
|
24203
24299
|
}
|
|
24204
24300
|
function bundleVersion(bundleDir2) {
|
|
24205
24301
|
try {
|
|
24206
|
-
const v = JSON.parse(readFileSync9(
|
|
24302
|
+
const v = JSON.parse(readFileSync9(join13(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24207
24303
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24208
24304
|
} catch {
|
|
24209
24305
|
return void 0;
|
|
@@ -24353,7 +24449,7 @@ function checkMcp(ctx) {
|
|
|
24353
24449
|
return named2 || versioned ? pass3("D6") : unknown3("D6", D6_UNKNOWN_DETAIL);
|
|
24354
24450
|
}
|
|
24355
24451
|
function piCwdInside(worktree, piCwd) {
|
|
24356
|
-
if (piCwd === void 0 || !
|
|
24452
|
+
if (piCwd === void 0 || !existsSync9(piCwd)) return false;
|
|
24357
24453
|
const rel = relative2(worktree, realpathSync5.native(piCwd));
|
|
24358
24454
|
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
24359
24455
|
}
|
|
@@ -24374,13 +24470,13 @@ function checkShell(env) {
|
|
|
24374
24470
|
}
|
|
24375
24471
|
|
|
24376
24472
|
// src/core/ops/doctor-hook.ts
|
|
24377
|
-
import { existsSync as
|
|
24473
|
+
import { existsSync as existsSync11, mkdtempSync, readFileSync as readFileSync10, realpathSync as realpathSync7, rmSync as rmSync2 } from "node:fs";
|
|
24378
24474
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24379
24475
|
import path6 from "node:path";
|
|
24380
24476
|
|
|
24381
24477
|
// src/setup/codex-trust.ts
|
|
24382
24478
|
import { createHash } from "node:crypto";
|
|
24383
|
-
import { existsSync as
|
|
24479
|
+
import { existsSync as existsSync10, realpathSync as realpathSync6 } from "node:fs";
|
|
24384
24480
|
import path5 from "node:path";
|
|
24385
24481
|
import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
|
|
24386
24482
|
|
|
@@ -24478,6 +24574,7 @@ var LIST_TIMEOUT_MS = 15e3;
|
|
|
24478
24574
|
var EXIT_GRACE_MS = 5e3;
|
|
24479
24575
|
var PLUGIN_SOURCE = "plugin";
|
|
24480
24576
|
var TRUSTED = "trusted";
|
|
24577
|
+
var UNTRUSTED = "untrusted";
|
|
24481
24578
|
function pluginHooksFromReply(m, pluginId) {
|
|
24482
24579
|
const out = [];
|
|
24483
24580
|
if (!isObj2(m) || !isObj2(m.result) || !Array.isArray(m.result.data)) return out;
|
|
@@ -24487,7 +24584,8 @@ function pluginHooksFromReply(m, pluginId) {
|
|
|
24487
24584
|
if (!isObj2(h) || h.source !== PLUGIN_SOURCE || h.pluginId !== pluginId) continue;
|
|
24488
24585
|
if (typeof h.key !== "string" || typeof h.currentHash !== "string") continue;
|
|
24489
24586
|
if (out.some((x) => x.key === h.key)) continue;
|
|
24490
|
-
|
|
24587
|
+
const status = typeof h.trustStatus === "string" ? h.trustStatus : UNTRUSTED;
|
|
24588
|
+
out.push({ key: h.key, hash: h.currentHash, trusted: status === TRUSTED, status });
|
|
24491
24589
|
}
|
|
24492
24590
|
}
|
|
24493
24591
|
return out;
|
|
@@ -24580,7 +24678,11 @@ var CODEX_UNTRUSTED_FIX = "run: context-mode setup";
|
|
|
24580
24678
|
function untrustedPluginHooksDetail(hooks) {
|
|
24581
24679
|
const bad = hooks.filter((h) => !h.trusted);
|
|
24582
24680
|
if (!bad.length) return void 0;
|
|
24583
|
-
|
|
24681
|
+
const counts = /* @__PURE__ */ new Map();
|
|
24682
|
+
for (const h of bad) counts.set(h.status, (counts.get(h.status) ?? 0) + 1);
|
|
24683
|
+
const words = [...counts].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1));
|
|
24684
|
+
const state = words.length === 1 ? words[0][0] : `${words.map(([w]) => w).join(" or ")} (${words.map(([w, n]) => `${n} ${w}`).join(", ")})`;
|
|
24685
|
+
return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks ${state}, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
|
|
24584
24686
|
}
|
|
24585
24687
|
|
|
24586
24688
|
// src/core/ops/doctor-hook.ts
|
|
@@ -24597,7 +24699,7 @@ function isObject5(v) {
|
|
|
24597
24699
|
}
|
|
24598
24700
|
function loadFixture(bundleDir2, agent) {
|
|
24599
24701
|
const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
24600
|
-
if (!
|
|
24702
|
+
if (!existsSync11(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
24601
24703
|
let all;
|
|
24602
24704
|
try {
|
|
24603
24705
|
all = JSON.parse(hostText(readFileSync10(file2, "utf8")));
|
|
@@ -24736,7 +24838,7 @@ async function checkHookRoundTrip(i) {
|
|
|
24736
24838
|
const trust = await codexPluginTrust(i);
|
|
24737
24839
|
if (trust !== null) return trust;
|
|
24738
24840
|
}
|
|
24739
|
-
if (i.agent === "codex" &&
|
|
24841
|
+
if (i.agent === "codex" && existsSync11(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
24740
24842
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
24741
24843
|
}
|
|
24742
24844
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
@@ -24775,14 +24877,14 @@ async function checkHookRoundTrip(i) {
|
|
|
24775
24877
|
}
|
|
24776
24878
|
|
|
24777
24879
|
// src/core/ops/db-heal.ts
|
|
24778
|
-
import { existsSync as
|
|
24779
|
-
import { basename as basename4, dirname as
|
|
24880
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
|
|
24881
|
+
import { basename as basename4, dirname as dirname8, join as join15 } from "node:path";
|
|
24780
24882
|
|
|
24781
24883
|
// src/core/store/owners.ts
|
|
24782
24884
|
import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync11, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
24783
|
-
import { basename as basename3, join as
|
|
24885
|
+
import { basename as basename3, join as join14 } from "node:path";
|
|
24784
24886
|
function ownersDir(configDir, projectKey) {
|
|
24785
|
-
return
|
|
24887
|
+
return join14(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
24786
24888
|
}
|
|
24787
24889
|
function errCode2(err) {
|
|
24788
24890
|
return err.code;
|
|
@@ -24810,7 +24912,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
24810
24912
|
const live = [];
|
|
24811
24913
|
for (const name of names) {
|
|
24812
24914
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
24813
|
-
const file2 =
|
|
24915
|
+
const file2 = join14(dir, name);
|
|
24814
24916
|
let text;
|
|
24815
24917
|
try {
|
|
24816
24918
|
text = readFileSync11(file2, "utf8");
|
|
@@ -24859,7 +24961,7 @@ function renameAside(dbPath) {
|
|
|
24859
24961
|
const ts = String(Date.now());
|
|
24860
24962
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
24861
24963
|
const file2 = dbPath + suffix;
|
|
24862
|
-
if (
|
|
24964
|
+
if (existsSync12(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
24863
24965
|
}
|
|
24864
24966
|
return ts;
|
|
24865
24967
|
}
|
|
@@ -24882,7 +24984,7 @@ function utcStamp(now) {
|
|
|
24882
24984
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
24883
24985
|
}
|
|
24884
24986
|
function makeOrphanDir(projectDir) {
|
|
24885
|
-
const base =
|
|
24987
|
+
const base = join15(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
24886
24988
|
for (let n = 1; ; n += 1) {
|
|
24887
24989
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
24888
24990
|
try {
|
|
@@ -24897,9 +24999,9 @@ async function healOrphan(project, files, row5) {
|
|
|
24897
24999
|
const moved = [];
|
|
24898
25000
|
let dir = "";
|
|
24899
25001
|
try {
|
|
24900
|
-
dir = makeOrphanDir(
|
|
25002
|
+
dir = makeOrphanDir(dirname8(project.dbPath));
|
|
24901
25003
|
for (const f of files) {
|
|
24902
|
-
const to =
|
|
25004
|
+
const to = join15(dir, basename4(f.path));
|
|
24903
25005
|
renameWithRetry(f.path, to);
|
|
24904
25006
|
moved.push({ path: to, bytes: f.bytes });
|
|
24905
25007
|
}
|
|
@@ -24966,8 +25068,8 @@ function buildReportHead(input) {
|
|
|
24966
25068
|
|
|
24967
25069
|
// src/core/ops/doctor-issue.ts
|
|
24968
25070
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
24969
|
-
import { closeSync, existsSync as
|
|
24970
|
-
import { delimiter, join as
|
|
25071
|
+
import { closeSync, existsSync as existsSync13, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync12, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
|
|
25072
|
+
import { delimiter, join as join16 } from "node:path";
|
|
24971
25073
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
24972
25074
|
function tildeOf(env) {
|
|
24973
25075
|
const home = homeDirOf(env);
|
|
@@ -25008,8 +25110,8 @@ function onPath(env, tool) {
|
|
|
25008
25110
|
const out = [];
|
|
25009
25111
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
25010
25112
|
if (dir === "") continue;
|
|
25011
|
-
for (const n of names) if (
|
|
25012
|
-
out.push(
|
|
25113
|
+
for (const n of names) if (existsSync13(join16(dir, n))) {
|
|
25114
|
+
out.push(join16(dir, n));
|
|
25013
25115
|
break;
|
|
25014
25116
|
}
|
|
25015
25117
|
}
|
|
@@ -25017,7 +25119,7 @@ function onPath(env, tool) {
|
|
|
25017
25119
|
}
|
|
25018
25120
|
function hookLogTail(env) {
|
|
25019
25121
|
const file2 = hookLogPath(env);
|
|
25020
|
-
if (file2 === "" || !
|
|
25122
|
+
if (file2 === "" || !existsSync13(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
25021
25123
|
try {
|
|
25022
25124
|
const fd = openSync(file2, "r");
|
|
25023
25125
|
try {
|
|
@@ -25037,7 +25139,7 @@ function hookLogTail(env) {
|
|
|
25037
25139
|
}
|
|
25038
25140
|
async function journalRows(ctx) {
|
|
25039
25141
|
const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
25040
|
-
if (!
|
|
25142
|
+
if (!existsSync13(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
25041
25143
|
try {
|
|
25042
25144
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
25043
25145
|
try {
|
|
@@ -25055,15 +25157,15 @@ function agentConfig(adapter, env, worktree) {
|
|
|
25055
25157
|
const home = homeDirOf(env);
|
|
25056
25158
|
const files = configPaths(adapter, env, worktree);
|
|
25057
25159
|
if (home !== null) {
|
|
25058
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
25059
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
25160
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join16(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
25161
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join16(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
25060
25162
|
}
|
|
25061
25163
|
const out = [];
|
|
25062
25164
|
const seen = /* @__PURE__ */ new Set();
|
|
25063
25165
|
for (const f of files) {
|
|
25064
25166
|
if (seen.has(f.path)) continue;
|
|
25065
25167
|
seen.add(f.path);
|
|
25066
|
-
if (!
|
|
25168
|
+
if (!existsSync13(f.path)) {
|
|
25067
25169
|
out.push(`${f.label}: ${f.path} (absent)`);
|
|
25068
25170
|
continue;
|
|
25069
25171
|
}
|
|
@@ -25139,14 +25241,14 @@ async function buildIssueBody(i) {
|
|
|
25139
25241
|
async function writeIssueReport(i) {
|
|
25140
25242
|
const tilde = tildeOf(i.env);
|
|
25141
25243
|
const body = await buildIssueBody(i);
|
|
25142
|
-
const dir =
|
|
25244
|
+
const dir = join16(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
25143
25245
|
mkdirSync6(dir, { recursive: true });
|
|
25144
|
-
const file2 =
|
|
25246
|
+
const file2 = join16(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
25145
25247
|
writeFileSync3(file2, body);
|
|
25146
25248
|
const shown2 = tilde(file2);
|
|
25147
25249
|
const title = issueTitle(i.adapter.id, i.rows);
|
|
25148
25250
|
const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
|
|
25149
|
-
return [DOCTOR_REPORT_LINE + shown2, DOCTOR_GH_LINE + gh[0], gh[1], gh[2], DOCTOR_URL_LINE + formUrl(title, summaryOf(i.adapter.id, i.rows))];
|
|
25251
|
+
return [DOCTOR_REPORT_LINE + shown2, DOCTOR_GH_LINE + gh[0], gh[1], gh[2], DOCTOR_URL_LINE + formUrl(title, summaryOf(i.adapter.id, i.rows)), DOCTOR_RULES_LINE + ISSUE_GUIDE_URL];
|
|
25150
25252
|
}
|
|
25151
25253
|
function formUrl(title, summary) {
|
|
25152
25254
|
const base = `${ISSUE_FORM_URL}&title=${encodeURIComponent(title)}`;
|
|
@@ -25168,7 +25270,7 @@ async function guard(id2, run) {
|
|
|
25168
25270
|
}
|
|
25169
25271
|
}
|
|
25170
25272
|
async function codexDb(ctx, adapter) {
|
|
25171
|
-
if (adapter.id !== "codex" || !
|
|
25273
|
+
if (adapter.id !== "codex" || !existsSync14(ctx.project.dbPath)) return null;
|
|
25172
25274
|
try {
|
|
25173
25275
|
return await openDb(ctx.project, { readOnly: true });
|
|
25174
25276
|
} catch {
|
|
@@ -25198,11 +25300,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
25198
25300
|
}
|
|
25199
25301
|
}
|
|
25200
25302
|
function ownServerId(configDir, projectKey) {
|
|
25201
|
-
const dir =
|
|
25202
|
-
if (!
|
|
25303
|
+
const dir = join17(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
25304
|
+
if (!existsSync14(dir)) return "";
|
|
25203
25305
|
for (const name of readdirSync6(dir)) {
|
|
25204
25306
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
25205
|
-
if (readFileSync13(
|
|
25307
|
+
if (readFileSync13(join17(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
25206
25308
|
}
|
|
25207
25309
|
return "";
|
|
25208
25310
|
}
|
|
@@ -25285,7 +25387,7 @@ async function doctorReply(ctx, host) {
|
|
|
25285
25387
|
return { text, isError: false, sandboxBytes: bytes5 };
|
|
25286
25388
|
}
|
|
25287
25389
|
async function handler2(_input, ctx) {
|
|
25288
|
-
return doctorReply(ctx, { env: process.env, bundleDir:
|
|
25390
|
+
return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: void 0 });
|
|
25289
25391
|
}
|
|
25290
25392
|
var ctxDoctor = Object.freeze({
|
|
25291
25393
|
name: "ctx_doctor",
|
|
@@ -25297,9 +25399,9 @@ var ctxDoctor = Object.freeze({
|
|
|
25297
25399
|
});
|
|
25298
25400
|
|
|
25299
25401
|
// src/core/tools/execute.ts
|
|
25300
|
-
import { existsSync as
|
|
25402
|
+
import { existsSync as existsSync15, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
25301
25403
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
25302
|
-
import { dirname as
|
|
25404
|
+
import { dirname as dirname10, join as join18, parse as parse3, resolve as resolve6 } from "node:path";
|
|
25303
25405
|
|
|
25304
25406
|
// src/core/sandbox/win-build.ts
|
|
25305
25407
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -25383,7 +25485,7 @@ function schemaLine(issue2) {
|
|
|
25383
25485
|
}
|
|
25384
25486
|
function fileError(given, abs, root) {
|
|
25385
25487
|
let dir = abs;
|
|
25386
|
-
while (!
|
|
25488
|
+
while (!existsSync15(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
|
|
25387
25489
|
if (isInside(root, dir)) return null;
|
|
25388
25490
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
25389
25491
|
}
|
|
@@ -25464,8 +25566,8 @@ async function handler3(raw, ctx) {
|
|
|
25464
25566
|
if (takesDashC(input.language, runtime)) {
|
|
25465
25567
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
25466
25568
|
} else {
|
|
25467
|
-
tmpDir = mkdtempSync2(
|
|
25468
|
-
const file2 =
|
|
25569
|
+
tmpDir = mkdtempSync2(join18(tmpdir3(), TMP_PREFIX));
|
|
25570
|
+
const file2 = join18(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
25469
25571
|
writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
|
|
25470
25572
|
argv = scriptArgv(input.language, runtime, file2);
|
|
25471
25573
|
}
|
|
@@ -25500,12 +25602,12 @@ var ctxExecute = {
|
|
|
25500
25602
|
};
|
|
25501
25603
|
|
|
25502
25604
|
// src/core/tools/index.ts
|
|
25503
|
-
import { existsSync as
|
|
25504
|
-
import { dirname as
|
|
25605
|
+
import { existsSync as existsSync16, readFileSync as readFileSync15, statSync as statSync8 } from "node:fs";
|
|
25606
|
+
import { dirname as dirname11, extname, join as join20, relative as relative3, resolve as resolve7 } from "node:path";
|
|
25505
25607
|
|
|
25506
25608
|
// src/core/index/walk.ts
|
|
25507
25609
|
import { readdirSync as readdirSync7, readFileSync as readFileSync14, realpathSync as realpathSync9, statSync as statSync7 } from "node:fs";
|
|
25508
|
-
import { join as
|
|
25610
|
+
import { join as join19 } from "node:path";
|
|
25509
25611
|
var GITIGNORE = ".gitignore";
|
|
25510
25612
|
var GIT_DIR = ".git";
|
|
25511
25613
|
function walkDir(root, containmentRoot) {
|
|
@@ -25514,7 +25616,7 @@ function walkDir(root, containmentRoot) {
|
|
|
25514
25616
|
const found = [];
|
|
25515
25617
|
visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
|
|
25516
25618
|
found.sort(compareFound);
|
|
25517
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
25619
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join19(...f.dir, f.name) }));
|
|
25518
25620
|
}
|
|
25519
25621
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
25520
25622
|
let entries;
|
|
@@ -25523,10 +25625,10 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
25523
25625
|
} catch {
|
|
25524
25626
|
return;
|
|
25525
25627
|
}
|
|
25526
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
25628
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join19(abs, GITIGNORE), rel)) : parent;
|
|
25527
25629
|
for (const e of entries) {
|
|
25528
25630
|
if (e.name === GIT_DIR) continue;
|
|
25529
|
-
const path7 =
|
|
25631
|
+
const path7 = join19(abs, e.name);
|
|
25530
25632
|
let isDir = e.isDirectory();
|
|
25531
25633
|
let isFile = e.isFile();
|
|
25532
25634
|
let target = path7;
|
|
@@ -29656,7 +29758,7 @@ function readUtf8(absPath) {
|
|
|
29656
29758
|
}
|
|
29657
29759
|
function missingOrOutside(given, abs, root) {
|
|
29658
29760
|
let dir = abs;
|
|
29659
|
-
while (!
|
|
29761
|
+
while (!existsSync16(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
|
|
29660
29762
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
29661
29763
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
29662
29764
|
}
|
|
@@ -29667,7 +29769,7 @@ function pathItems(input, project) {
|
|
|
29667
29769
|
if (statSync8(abs).isDirectory()) {
|
|
29668
29770
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
29669
29771
|
sourceKind: "path",
|
|
29670
|
-
label: pathLabel(
|
|
29772
|
+
label: pathLabel(join20(base, f.relPath)),
|
|
29671
29773
|
kind: kindOfPath(f.relPath),
|
|
29672
29774
|
read: () => readUtf8(f.absPath)
|
|
29673
29775
|
}));
|
|
@@ -30207,12 +30309,12 @@ var ctxStats = Object.freeze({
|
|
|
30207
30309
|
});
|
|
30208
30310
|
|
|
30209
30311
|
// src/core/tools/upgrade.ts
|
|
30210
|
-
import { existsSync as
|
|
30211
|
-
import { basename as basename7, dirname as
|
|
30312
|
+
import { existsSync as existsSync22, realpathSync as realpathSync10, rmSync as rmSync10 } from "node:fs";
|
|
30313
|
+
import { basename as basename7, dirname as dirname13, join as join26 } from "node:path";
|
|
30212
30314
|
|
|
30213
30315
|
// src/core/ops/host-write.ts
|
|
30214
|
-
import { copyFileSync, existsSync as
|
|
30215
|
-
import { dirname as
|
|
30316
|
+
import { copyFileSync, existsSync as existsSync17, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
30317
|
+
import { dirname as dirname12, join as join21 } from "node:path";
|
|
30216
30318
|
function defaultWrite(file2, text) {
|
|
30217
30319
|
writeFileSync5(file2, text, "utf8");
|
|
30218
30320
|
}
|
|
@@ -30221,14 +30323,14 @@ function hostConfigPath(agent, home, env) {
|
|
|
30221
30323
|
if (own2 !== void 0) return ownMcpFileOf(agent, own2.file, env, home);
|
|
30222
30324
|
switch (agent) {
|
|
30223
30325
|
case "opencode":
|
|
30224
|
-
return
|
|
30326
|
+
return join21(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
30225
30327
|
// D-WIN-OPENCODE-DIR-1
|
|
30226
30328
|
case "pi":
|
|
30227
|
-
return
|
|
30329
|
+
return join21(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
30228
30330
|
case "copilot-cli":
|
|
30229
30331
|
return null;
|
|
30230
30332
|
default:
|
|
30231
|
-
return
|
|
30333
|
+
return join21(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
30232
30334
|
}
|
|
30233
30335
|
}
|
|
30234
30336
|
function cell3(value) {
|
|
@@ -30240,8 +30342,8 @@ function toRow(file2, edit) {
|
|
|
30240
30342
|
function writeWithRollback(file2, text, write2, atomic) {
|
|
30241
30343
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
30242
30344
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
30243
|
-
const had =
|
|
30244
|
-
mkdirSync7(
|
|
30345
|
+
const had = existsSync17(file2);
|
|
30346
|
+
mkdirSync7(dirname12(file2), { recursive: true });
|
|
30245
30347
|
if (had) copyFileSync(file2, trash);
|
|
30246
30348
|
try {
|
|
30247
30349
|
write2(tmp, text);
|
|
@@ -30270,7 +30372,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
30270
30372
|
if (requested === null) return [];
|
|
30271
30373
|
const current = readHostConfig(row5.id, requested);
|
|
30272
30374
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
30273
|
-
const exists =
|
|
30375
|
+
const exists = existsSync17(current.path);
|
|
30274
30376
|
if (exists && result.text === current.text) return [];
|
|
30275
30377
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
30276
30378
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -30278,8 +30380,8 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
30278
30380
|
}
|
|
30279
30381
|
|
|
30280
30382
|
// src/core/ops/plugin-swap.ts
|
|
30281
|
-
import { existsSync as
|
|
30282
|
-
import { basename as basename6, join as
|
|
30383
|
+
import { existsSync as existsSync18, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
30384
|
+
import { basename as basename6, join as join22, win32 as win322 } from "node:path";
|
|
30283
30385
|
function linkTarget(path7, win) {
|
|
30284
30386
|
if (!isLink(path7)) return null;
|
|
30285
30387
|
const target = readlinkSync(path7);
|
|
@@ -30298,11 +30400,11 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
30298
30400
|
else renameWithRetry(old, link, opts);
|
|
30299
30401
|
}
|
|
30300
30402
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
30301
|
-
const next =
|
|
30302
|
-
if (!
|
|
30403
|
+
const next = join22(agentDir, sha);
|
|
30404
|
+
if (!existsSync18(next) || !lstatSync(next).isDirectory()) {
|
|
30303
30405
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
|
|
30304
30406
|
}
|
|
30305
|
-
const link =
|
|
30407
|
+
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
30306
30408
|
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
30307
30409
|
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
30308
30410
|
settleLinks(link, tmp, old, opts);
|
|
@@ -30317,15 +30419,15 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
30317
30419
|
if (before !== null) unlinkSync2(old);
|
|
30318
30420
|
const keep = /* @__PURE__ */ new Set([sha]);
|
|
30319
30421
|
if (before !== null) keep.add(before);
|
|
30320
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) =>
|
|
30422
|
+
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join22(agentDir, name));
|
|
30321
30423
|
for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
|
|
30322
|
-
const previous = before !== null &&
|
|
30424
|
+
const previous = before !== null && existsSync18(join22(agentDir, before)) ? join22(agentDir, before) : null;
|
|
30323
30425
|
return { current: next, previous, removed };
|
|
30324
30426
|
}
|
|
30325
30427
|
|
|
30326
30428
|
// src/core/ops/release-fetch.ts
|
|
30327
|
-
import { existsSync as
|
|
30328
|
-
import { join as
|
|
30429
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
|
|
30430
|
+
import { join as join23 } from "node:path";
|
|
30329
30431
|
function failed(r) {
|
|
30330
30432
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
30331
30433
|
const status = r.killed ?? String(r.exitCode);
|
|
@@ -30337,9 +30439,9 @@ async function git2(bin, args, cwd, env, signal) {
|
|
|
30337
30439
|
return r.stdout.toString().trim();
|
|
30338
30440
|
}
|
|
30339
30441
|
async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
30340
|
-
const agentDir =
|
|
30442
|
+
const agentDir = join23(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
30341
30443
|
mkdirSync8(agentDir, { recursive: true });
|
|
30342
|
-
const fetchDir =
|
|
30444
|
+
const fetchDir = join23(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
30343
30445
|
rmSync7(fetchDir, { recursive: true, force: true });
|
|
30344
30446
|
const gitBin = findRuntime(GIT_BIN, env);
|
|
30345
30447
|
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -30347,8 +30449,8 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
30347
30449
|
try {
|
|
30348
30450
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url2, fetchDir], agentDir, childEnv, signal);
|
|
30349
30451
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
30350
|
-
const dir =
|
|
30351
|
-
if (
|
|
30452
|
+
const dir = join23(agentDir, sha);
|
|
30453
|
+
if (existsSync19(dir)) rmSync7(fetchDir, { recursive: true, force: true });
|
|
30352
30454
|
else renameWithRetry(fetchDir, dir, opts);
|
|
30353
30455
|
return { sha, dir };
|
|
30354
30456
|
} catch (e) {
|
|
@@ -30358,15 +30460,15 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
30358
30460
|
}
|
|
30359
30461
|
|
|
30360
30462
|
// src/core/ops/uninstall.ts
|
|
30361
|
-
import { existsSync as
|
|
30362
|
-
import { join as
|
|
30463
|
+
import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
30464
|
+
import { join as join24 } from "node:path";
|
|
30363
30465
|
function row2(area, before, after) {
|
|
30364
30466
|
return { area, before, after };
|
|
30365
30467
|
}
|
|
30366
30468
|
function stopServers(configDir, projectKey) {
|
|
30367
30469
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
30368
|
-
const dir =
|
|
30369
|
-
for (const serverId of stopped) writeFileSync6(
|
|
30470
|
+
const dir = join24(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
30471
|
+
for (const serverId of stopped) writeFileSync6(join24(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
30370
30472
|
return stopped.length === 0 ? { row: row2(UPGRADE_SERVER_AREA, "", UPGRADE_NOT_FOUND), stopped } : { row: row2(UPGRADE_SERVER_AREA, UPGRADE_SERVER_RUNNING, UPGRADE_SERVER_STOPPED), stopped };
|
|
30371
30473
|
}
|
|
30372
30474
|
function rootOrNull(adapter, env) {
|
|
@@ -30384,15 +30486,15 @@ function removeCache(adapter, env, configDir) {
|
|
|
30384
30486
|
const root = rootOrNull(adapter, env);
|
|
30385
30487
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
30386
30488
|
if (adapter.installMode === "marketplace") {
|
|
30387
|
-
const cache =
|
|
30489
|
+
const cache = join24(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
30388
30490
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
30389
30491
|
}
|
|
30390
30492
|
rmSync8(root, { recursive: true, force: true });
|
|
30391
30493
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
30392
30494
|
}
|
|
30393
30495
|
case "plugin": {
|
|
30394
|
-
const agentDir =
|
|
30395
|
-
if (!
|
|
30496
|
+
const agentDir = join24(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
30497
|
+
if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
30396
30498
|
rmSync8(agentDir, { recursive: true, force: true });
|
|
30397
30499
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
30398
30500
|
}
|
|
@@ -30437,7 +30539,7 @@ function ownEntries(agent, env) {
|
|
|
30437
30539
|
}
|
|
30438
30540
|
if (agent === "opencode") {
|
|
30439
30541
|
return [{
|
|
30440
|
-
file:
|
|
30542
|
+
file: join24(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
30441
30543
|
// D-WIN-OPENCODE-DIR-1
|
|
30442
30544
|
key: OPENCODE_PLUGIN_KEY,
|
|
30443
30545
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -30448,7 +30550,7 @@ function ownEntries(agent, env) {
|
|
|
30448
30550
|
if (agent === "pi") {
|
|
30449
30551
|
const agentDir = piAgentDirOf(env, home);
|
|
30450
30552
|
return [{
|
|
30451
|
-
file:
|
|
30553
|
+
file: join24(agentDir, SETTINGS_FILE),
|
|
30452
30554
|
key: PI_PACKAGES_KEY,
|
|
30453
30555
|
shown: PI_PACKAGES_KEY,
|
|
30454
30556
|
has: (v) => Array.isArray(v) && v.some((x) => piSource(x) === PI_GIT_PACKAGE),
|
|
@@ -30470,12 +30572,12 @@ function removeOwnEntries(agent, env) {
|
|
|
30470
30572
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
30471
30573
|
}
|
|
30472
30574
|
function removeProjectData(configDir, projectKey) {
|
|
30473
|
-
const projects =
|
|
30474
|
-
const dir =
|
|
30475
|
-
if (!
|
|
30575
|
+
const projects = join24(configDir, PROJECTS_DIR_NAME);
|
|
30576
|
+
const dir = join24(projects, projectKey);
|
|
30577
|
+
if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
30476
30578
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
30477
30579
|
for (const name of readdirSync9(dir)) {
|
|
30478
|
-
if (name !== OWNERS_DIR_NAME) rmSync8(
|
|
30580
|
+
if (name !== OWNERS_DIR_NAME) rmSync8(join24(dir, name), { recursive: true, force: true });
|
|
30479
30581
|
}
|
|
30480
30582
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
30481
30583
|
}
|
|
@@ -30483,12 +30585,12 @@ function runUninstall(input) {
|
|
|
30483
30585
|
const configDir = resolveConfigDir(input.env);
|
|
30484
30586
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
30485
30587
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
30486
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
30588
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join24(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
30487
30589
|
return { rows, stopped: stop.stopped };
|
|
30488
30590
|
}
|
|
30489
30591
|
|
|
30490
30592
|
// src/core/ops/v1-remove.ts
|
|
30491
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
30593
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync16, rmSync as rmSync9 } from "node:fs";
|
|
30492
30594
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
30493
30595
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
30494
30596
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -30569,14 +30671,14 @@ function removeV1(agent, findings) {
|
|
|
30569
30671
|
for (const f of findings) {
|
|
30570
30672
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
30571
30673
|
else if (f.path === "") {
|
|
30572
|
-
if (
|
|
30674
|
+
if (existsSync21(f.file)) {
|
|
30573
30675
|
moveAside(f.file, undo);
|
|
30574
30676
|
done.set(f, UPGRADE_REMOVED);
|
|
30575
30677
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
30576
30678
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
30577
30679
|
}
|
|
30578
30680
|
for (const [file2, list4] of entries) {
|
|
30579
|
-
if (!
|
|
30681
|
+
if (!existsSync21(file2)) {
|
|
30580
30682
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
30581
30683
|
continue;
|
|
30582
30684
|
}
|
|
@@ -30609,7 +30711,7 @@ function removeV1(agent, findings) {
|
|
|
30609
30711
|
},
|
|
30610
30712
|
rollback() {
|
|
30611
30713
|
for (const u of undo.splice(0).reverse()) {
|
|
30612
|
-
if (!
|
|
30714
|
+
if (!existsSync21(u.trash)) continue;
|
|
30613
30715
|
rmSync9(u.target, { recursive: true, force: true });
|
|
30614
30716
|
renameWithRetry(u.trash, u.target);
|
|
30615
30717
|
}
|
|
@@ -30620,7 +30722,7 @@ function removeV1(agent, findings) {
|
|
|
30620
30722
|
// src/core/ops/verify-sums.ts
|
|
30621
30723
|
import { createHash as createHash2 } from "node:crypto";
|
|
30622
30724
|
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync17 } from "node:fs";
|
|
30623
|
-
import { join as
|
|
30725
|
+
import { join as join25 } from "node:path";
|
|
30624
30726
|
function mismatch() {
|
|
30625
30727
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
30626
30728
|
}
|
|
@@ -30641,14 +30743,14 @@ function walk3(dir, prefix, out) {
|
|
|
30641
30743
|
for (const entry of readdirSync10(dir, { withFileTypes: true })) {
|
|
30642
30744
|
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
30643
30745
|
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
30644
|
-
const abs =
|
|
30746
|
+
const abs = join25(dir, entry.name);
|
|
30645
30747
|
if (entry.isDirectory()) walk3(abs, rel, out);
|
|
30646
30748
|
else if (entry.isFile()) out.set(rel, abs);
|
|
30647
30749
|
else throw mismatch();
|
|
30648
30750
|
}
|
|
30649
30751
|
}
|
|
30650
30752
|
function verifySums(dir) {
|
|
30651
|
-
const sumsPath =
|
|
30753
|
+
const sumsPath = join25(dir, RELEASE_SUMS_FILE);
|
|
30652
30754
|
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
30653
30755
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
30654
30756
|
const sums = parseSums(readFileSync17(sumsPath, "utf8"));
|
|
@@ -30672,7 +30774,7 @@ function row4(area, before, after) {
|
|
|
30672
30774
|
return { area, before, after };
|
|
30673
30775
|
}
|
|
30674
30776
|
function bundleDir() {
|
|
30675
|
-
return
|
|
30777
|
+
return ownBundleDir();
|
|
30676
30778
|
}
|
|
30677
30779
|
function pluginRootRow(adapter, env) {
|
|
30678
30780
|
const own2 = bundleDir();
|
|
@@ -30686,12 +30788,12 @@ function pluginRootRow(adapter, env) {
|
|
|
30686
30788
|
return root === own2 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own2)];
|
|
30687
30789
|
}
|
|
30688
30790
|
function isCurrent(agentDir, dir) {
|
|
30689
|
-
const link =
|
|
30690
|
-
return
|
|
30791
|
+
const link = join26(agentDir, PLUGIN_CURRENT_LINK);
|
|
30792
|
+
return existsSync22(link) && realpathSync10.native(link) === realpathSync10.native(dir);
|
|
30691
30793
|
}
|
|
30692
30794
|
async function checkout(adapter, deps) {
|
|
30693
30795
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
30694
|
-
const agentDir =
|
|
30796
|
+
const agentDir = dirname13(fetched.dir);
|
|
30695
30797
|
try {
|
|
30696
30798
|
verifySums(fetched.dir);
|
|
30697
30799
|
} catch (err) {
|