context-mode 2.1.10 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +2 -2
- package/.codex-plugin/plugin.json +2 -2
- package/.zcode-plugin/plugin.json +2 -2
- package/README.md +95 -76
- package/SHA256SUMS +21 -20
- package/cli.mjs +428 -92
- package/copilot/plugin.json +2 -2
- package/fixtures/hook-roundtrip.json +13 -0
- package/gemini-extension.json +2 -2
- package/hook.mjs +95 -95
- package/omp/index.js +5 -0
- package/opencode/plugin.js +615 -383
- package/package.json +9 -2
- package/pi/index.js +667 -409
- package/qwen-extension.json +2 -2
- package/run.mjs +77 -32
- package/search.mjs +77 -32
- package/server.mjs +610 -386
- 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/opencode/plugin.js
CHANGED
|
@@ -364,6 +364,7 @@ var READ_MEDIA_BY_AGENT = Object.freeze({
|
|
|
364
364
|
qwen: READ_IMAGES_AND_PDF,
|
|
365
365
|
opencode: READ_IMAGES_AND_PDF,
|
|
366
366
|
pi: READ_IMAGES,
|
|
367
|
+
omp: READ_IMAGES,
|
|
367
368
|
vscode: READ_IMAGES,
|
|
368
369
|
zcode: READ_IMAGES,
|
|
369
370
|
"copilot-cli": [],
|
|
@@ -480,7 +481,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
480
481
|
var DECISION_OPTION_KEY = "option";
|
|
481
482
|
var DECISION_LABEL_JOIN = " | ";
|
|
482
483
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
483
|
-
var BUNDLE_SHA = true ? "
|
|
484
|
+
var BUNDLE_SHA = true ? "9cb2aaa5ebb63491960b3f3e9655a5821383eae4" : void 0;
|
|
484
485
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
485
486
|
var DOCTOR_LABEL = Object.freeze({
|
|
486
487
|
D1: "version",
|
|
@@ -632,7 +633,9 @@ var AGENT_HOME_DIR = Object.freeze({
|
|
|
632
633
|
kiro: [".kiro"],
|
|
633
634
|
zcode: [".zcode"],
|
|
634
635
|
pi: [".pi"],
|
|
635
|
-
opencode: [".config", "opencode"]
|
|
636
|
+
opencode: [".config", "opencode"],
|
|
637
|
+
omp: [".omp"]
|
|
638
|
+
// ADR-0026: OMP data and plugins live under ~/.omp
|
|
636
639
|
});
|
|
637
640
|
var UPGRADE_RESTART_LINE = "restart needed";
|
|
638
641
|
var UPGRADE_HOST_AREA = "host update";
|
|
@@ -720,16 +723,6 @@ var UNSUPPORTED_HOSTS = Object.freeze([
|
|
|
720
723
|
binaries: [],
|
|
721
724
|
source: "v1.0.169:src/adapters/client-map.ts:18; detect.ts:163-165,584"
|
|
722
725
|
}),
|
|
723
|
-
unsupported({
|
|
724
|
-
id: "omp",
|
|
725
|
-
name: "OMP (oh-my-pi)",
|
|
726
|
-
clientNames: ["omp-coding-agent"],
|
|
727
|
-
envVars: [],
|
|
728
|
-
pluginPaths: [],
|
|
729
|
-
configDirs: [".omp"],
|
|
730
|
-
binaries: ["omp"],
|
|
731
|
-
source: "v1.0.169:src/adapters/client-map.ts:37; detect.ts:543 (PI_CODING_AGENT_DIR is not a signal: supported Pi reads it too)"
|
|
732
|
-
}),
|
|
733
726
|
unsupported({
|
|
734
727
|
id: "openclaw",
|
|
735
728
|
name: "OpenClaw",
|
|
@@ -796,7 +789,9 @@ var HOOK_HOST_FILE = Object.freeze({
|
|
|
796
789
|
kiro: { root: "home", file: [".kiro", "hooks", "context-mode.json"], key: ["hooks"], shape: "kiro", timeoutKey: "timeout", matcher: false },
|
|
797
790
|
zcode: { root: "home", file: [".zcode", "cli", "config.json"], key: ["hooks", "events"], shape: "zcode", timeoutKey: "timeoutMs", matcher: true },
|
|
798
791
|
pi: null,
|
|
799
|
-
opencode: null
|
|
792
|
+
opencode: null,
|
|
793
|
+
omp: null
|
|
794
|
+
// ADR-0026: in-process, no hook file
|
|
800
795
|
});
|
|
801
796
|
var TOOL_HOOK_EVENTS = Object.freeze(["PreToolUse", "PostToolUse"]);
|
|
802
797
|
var HOOK_MATCHER_FIELD = "matcher";
|
|
@@ -852,6 +847,12 @@ var D11_POSIX_FIX = "install sh or add it to PATH";
|
|
|
852
847
|
function D11_PASS_DETAIL(shell, win) {
|
|
853
848
|
return `${win ? "Git Bash" : "sh"}: ${shell}`;
|
|
854
849
|
}
|
|
850
|
+
function D11_RUNTIME_DETAIL(lang, unreadable) {
|
|
851
|
+
return `${lang} not found, unreadable on PATH: ${unreadable.join(", ")}`;
|
|
852
|
+
}
|
|
853
|
+
function D11_RUNTIME_FIX(lang) {
|
|
854
|
+
return `install ${lang}, or turn off its app alias and PATH entry that cannot be read`;
|
|
855
|
+
}
|
|
855
856
|
var DB_SIBLING_SUFFIXES = Object.freeze(["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]);
|
|
856
857
|
var HEAL_TMP_SUFFIX = ".heal";
|
|
857
858
|
var HEAL_TS_SEP = ".";
|
|
@@ -863,6 +864,8 @@ var UPGRADE_HOST_COMMAND = Object.freeze({
|
|
|
863
864
|
gemini: "gemini extensions update context-mode",
|
|
864
865
|
qwen: "qwen extensions update context-mode",
|
|
865
866
|
pi: "pi update --extensions",
|
|
867
|
+
omp: "omp plugin upgrade context-mode",
|
|
868
|
+
// ADR-0026 decision 4: OMP native update
|
|
866
869
|
opencode: "opencode plugin update",
|
|
867
870
|
"copilot-cli": "npm i -g context-mode && context-mode setup --agents copilot-cli",
|
|
868
871
|
vscode: "npm i -g context-mode && context-mode setup --agents vscode",
|
|
@@ -906,6 +909,14 @@ var PI_NPM_DIR = "npm";
|
|
|
906
909
|
var PI_NODE_MODULES_DIR = "node_modules";
|
|
907
910
|
var PI_PACKAGE_JSON_FILE = "package.json";
|
|
908
911
|
var PI_LIST_COMMAND = "pi list";
|
|
912
|
+
var OMP_LIST_COMMAND = "omp plugin list";
|
|
913
|
+
var OMP_ENABLE_COMMAND = "omp plugin enable context-mode";
|
|
914
|
+
var OMP_MIN_VERSION = "14.7.0";
|
|
915
|
+
var OMP_FLOOR_INFO = (v) => `OMP ${v} is older than the tested floor ${OMP_MIN_VERSION}. Update it with: omp update`;
|
|
916
|
+
var OMP_CONTENT_INFO = "OMP keeps tool output in content; context-mode writes its notes there.";
|
|
917
|
+
var OMP_PRINT_MODE_INFO = "Print mode sends no prompt event. Use omp or omp --mode rpc to keep prompts.";
|
|
918
|
+
var OMP_SCRIPTS_INFO = "Add < /dev/null in scripts.";
|
|
919
|
+
var OMP_IMPORT_INFO = (claude, mcp) => `OMP also imports context-mode from ${claude}. To run it once, add "context-mode" to disabledServers in ${mcp}.`;
|
|
909
920
|
var PI_CURRENT_MAJOR = 2;
|
|
910
921
|
var V1_OPENCODE_PLUGIN_SPEC = "context-mode";
|
|
911
922
|
var V1_TMP_PREFIX = "context-mode-";
|
|
@@ -1115,6 +1126,8 @@ var NATIVE_INSTALL = Object.freeze({
|
|
|
1115
1126
|
qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode"],
|
|
1116
1127
|
opencode: ["opencode plugin add context-mode"],
|
|
1117
1128
|
pi: ["pi install npm:context-mode"],
|
|
1129
|
+
omp: ["omp plugin install context-mode"],
|
|
1130
|
+
// ADR-0026 decision 4: OMP native install
|
|
1118
1131
|
"copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
|
|
1119
1132
|
vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
|
|
1120
1133
|
kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
|
|
@@ -1264,7 +1277,7 @@ var CtxError = class extends Error {
|
|
|
1264
1277
|
import { dirname as dirname4, join as join8, relative as relative3, resolve as resolve8, sep as sep3 } from "node:path";
|
|
1265
1278
|
|
|
1266
1279
|
// src/core/contracts/agents.ts
|
|
1267
|
-
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
1280
|
+
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode", "omp"];
|
|
1268
1281
|
|
|
1269
1282
|
// src/adapters/claude-code.ts
|
|
1270
1283
|
var TOOL_NAME_PREFIX2 = "mcp__plugin_context-mode_context-mode__";
|
|
@@ -1986,6 +1999,9 @@ function readResult7(p) {
|
|
|
1986
1999
|
if (p.keep === true) info.keep = true;
|
|
1987
2000
|
return info;
|
|
1988
2001
|
}
|
|
2002
|
+
function decodeOmp(raw) {
|
|
2003
|
+
return { ...decode10(raw), agent: "omp" };
|
|
2004
|
+
}
|
|
1989
2005
|
function decode10(raw) {
|
|
1990
2006
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("pi: hook payload is not an object");
|
|
1991
2007
|
const p = raw;
|
|
@@ -2223,14 +2239,36 @@ var ADAPTERS = Object.freeze([
|
|
|
2223
2239
|
decode,
|
|
2224
2240
|
encode,
|
|
2225
2241
|
toCanonicalTool
|
|
2242
|
+
},
|
|
2243
|
+
{
|
|
2244
|
+
// ADR-0026 (D-OMP-ROW-1): OMP runs the Pi extension API in-process, so the row reuses the Pi decode, encode and
|
|
2245
|
+
// permission check; tool names stay bare. Only the entry path and the skills folder are its own.
|
|
2246
|
+
id: "omp",
|
|
2247
|
+
installMode: "in-process",
|
|
2248
|
+
projectSource: "pi:ctx.cwd",
|
|
2249
|
+
toolNamePrefix: TOOL_NAME_PREFIX10,
|
|
2250
|
+
nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
|
|
2251
|
+
execReadOnlyHint: false,
|
|
2252
|
+
eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
|
|
2253
|
+
compactDelivery: "pi-flag",
|
|
2254
|
+
compactSummary: "none",
|
|
2255
|
+
hookTimeoutMs: IN_PROCESS_TIMEOUT_MS,
|
|
2256
|
+
denyChannel: "deny-reason",
|
|
2257
|
+
hookChannel: { kind: "in-process", path: "omp/index.js" },
|
|
2258
|
+
skillChannel: { kind: "package", path: "skills" },
|
|
2259
|
+
// D-OMP-SKILLS-1
|
|
2260
|
+
decode: decodeOmp,
|
|
2261
|
+
encode: encode10,
|
|
2262
|
+
checkPermission
|
|
2263
|
+
// D-OMP-FIRE-1: agent omp in rows
|
|
2226
2264
|
}
|
|
2227
2265
|
]);
|
|
2228
2266
|
var BY_ID = new Map(ADAPTERS.map((r) => [r.id, r]));
|
|
2229
|
-
var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi", "opencode"]);
|
|
2267
|
+
var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi", "opencode", "omp"]);
|
|
2230
2268
|
function hasReplace(row5) {
|
|
2231
2269
|
return REPLACE_ROWS.has(row5.id);
|
|
2232
2270
|
}
|
|
2233
|
-
var DUMP_REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "copilot-cli", "pi"]);
|
|
2271
|
+
var DUMP_REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "copilot-cli", "pi", "omp"]);
|
|
2234
2272
|
function dumpRunsThenReplaces(row5) {
|
|
2235
2273
|
return DUMP_REPLACE_ROWS.has(row5.id) && hasReplace(row5);
|
|
2236
2274
|
}
|
|
@@ -3724,7 +3762,8 @@ function toolSetForAgentType(ev, src) {
|
|
|
3724
3762
|
const type = ev.agentType ?? "";
|
|
3725
3763
|
const def = findDef(type, src) ?? builtIn(ev.agent, type);
|
|
3726
3764
|
if (def === null) return null;
|
|
3727
|
-
const
|
|
3765
|
+
const known = allKnownToolNames(row5);
|
|
3766
|
+
const tools = def.tools === null ? known : def.tools.map((n) => norm(row5, n)).flatMap((n) => [n, ...known.filter((k) => grants(n, k))]);
|
|
3728
3767
|
const deny2 = def.disallowed.map((n) => norm(row5, n));
|
|
3729
3768
|
return unique(tools.filter((n) => !deny2.some((d) => denies(d, n))));
|
|
3730
3769
|
}
|
|
@@ -3880,6 +3919,13 @@ function geminiValid(s) {
|
|
|
3880
3919
|
}
|
|
3881
3920
|
return out;
|
|
3882
3921
|
}
|
|
3922
|
+
function grants(entry, name) {
|
|
3923
|
+
if (!entry.startsWith(MCP_SERVER_TOOL_PREFIX)) return false;
|
|
3924
|
+
const wild = MCP_NAME_JOIN + "*";
|
|
3925
|
+
const server2 = entry.slice(MCP_SERVER_TOOL_PREFIX.length, entry.endsWith(wild) ? -wild.length : entry.length);
|
|
3926
|
+
if (server2 === "" || server2.indexOf("*") >= 0 || server2.indexOf(MCP_NAME_JOIN) >= 0) return false;
|
|
3927
|
+
return name.startsWith(MCP_SERVER_TOOL_PREFIX + server2 + MCP_NAME_JOIN);
|
|
3928
|
+
}
|
|
3883
3929
|
function denies(rule, name) {
|
|
3884
3930
|
if (rule.endsWith("*")) return name.startsWith(rule.slice(0, -1));
|
|
3885
3931
|
if (rule === name) return true;
|
|
@@ -4810,6 +4856,7 @@ function sourceOf(agent) {
|
|
|
4810
4856
|
case "opencode":
|
|
4811
4857
|
return "spawn-cwd";
|
|
4812
4858
|
case "pi":
|
|
4859
|
+
case "omp":
|
|
4813
4860
|
return "pi:ctx.cwd";
|
|
4814
4861
|
}
|
|
4815
4862
|
}
|
|
@@ -8469,7 +8516,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
8469
8516
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
8470
8517
|
return { end: start + r.read, written: r.written };
|
|
8471
8518
|
}
|
|
8472
|
-
function merge(src, blocks,
|
|
8519
|
+
function merge(src, blocks, join27, cap, lineCut) {
|
|
8473
8520
|
const out = [];
|
|
8474
8521
|
const scratch = new Uint8Array(cap);
|
|
8475
8522
|
let wide;
|
|
@@ -8479,7 +8526,7 @@ function merge(src, blocks, join25, cap, lineCut) {
|
|
|
8479
8526
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
8480
8527
|
};
|
|
8481
8528
|
for (const b of blocks) {
|
|
8482
|
-
if (cur !== void 0 && !
|
|
8529
|
+
if (cur !== void 0 && !join27) {
|
|
8483
8530
|
emit(cur.start, cur.end, curBytes);
|
|
8484
8531
|
cur = void 0;
|
|
8485
8532
|
}
|
|
@@ -9121,7 +9168,7 @@ async function handleHook(agent, raw, env) {
|
|
|
9121
9168
|
try {
|
|
9122
9169
|
fault(env, "project");
|
|
9123
9170
|
const argv = agent === "vscode" ? [WORKSPACE_FOLDER_FLAG, ev.cwd] : process.argv;
|
|
9124
|
-
project = resolveProject(agent, { env, argv, cwd: ev.cwd, piCwd: agent === "pi" ? ev.cwd : void 0 });
|
|
9171
|
+
project = resolveProject(agent, { env, argv, cwd: ev.cwd, piCwd: getAdapter(agent).projectSource === "pi:ctx.cwd" ? ev.cwd : void 0 });
|
|
9125
9172
|
} catch (err) {
|
|
9126
9173
|
return fail7("project", err, "hooks: no project: " + String(err.code ?? "ERROR") + " " + message(err) + "\n");
|
|
9127
9174
|
}
|
|
@@ -20797,22 +20844,34 @@ function fileNames(name, pathExt) {
|
|
|
20797
20844
|
if (!isWin() || path.extname(name) !== "") return [name];
|
|
20798
20845
|
return [...pathExt.map((ext) => name + ext), name];
|
|
20799
20846
|
}
|
|
20800
|
-
function
|
|
20801
|
-
|
|
20802
|
-
|
|
20847
|
+
function probe(full) {
|
|
20848
|
+
let st;
|
|
20849
|
+
try {
|
|
20850
|
+
st = statSync3(full, { throwIfNoEntry: false });
|
|
20851
|
+
} catch {
|
|
20852
|
+
return "unreadable";
|
|
20853
|
+
}
|
|
20854
|
+
if (st === void 0 || !st.isFile()) return "absent";
|
|
20803
20855
|
if (isWin()) {
|
|
20804
20856
|
const ext = path.extname(full).toLowerCase();
|
|
20805
|
-
return ext === "" || WIN_STARTABLE_EXT.includes(ext);
|
|
20857
|
+
return ext === "" || WIN_STARTABLE_EXT.includes(ext) ? "runnable" : "absent";
|
|
20806
20858
|
}
|
|
20807
20859
|
try {
|
|
20808
20860
|
accessSync(full, fsConstants.X_OK);
|
|
20809
|
-
return
|
|
20861
|
+
return "runnable";
|
|
20810
20862
|
} catch {
|
|
20811
|
-
return
|
|
20863
|
+
return "absent";
|
|
20812
20864
|
}
|
|
20813
20865
|
}
|
|
20866
|
+
function isRunnable(full) {
|
|
20867
|
+
return probe(full) === "runnable";
|
|
20868
|
+
}
|
|
20814
20869
|
function findRuntime(lang, env = process.env) {
|
|
20815
|
-
|
|
20870
|
+
return lookupRuntime(lang, env).found;
|
|
20871
|
+
}
|
|
20872
|
+
function lookupRuntime(lang, env = process.env) {
|
|
20873
|
+
const unreadable = [];
|
|
20874
|
+
if (isWin() && WIN_SHELL_LANGS.includes(lang)) return { found: findGitBash(env), unreadable };
|
|
20816
20875
|
const dirs = pathEntries(envValue(env, "PATH") ?? "", process.platform, path.delimiter);
|
|
20817
20876
|
const pathExt = isWin() ? (envValue(env, "PATHEXT") ?? PATHEXT_DEFAULT).split(PATHEXT_SEPARATOR).filter((e) => e !== "") : [];
|
|
20818
20877
|
const names = candidates(lang);
|
|
@@ -20821,13 +20880,15 @@ function findRuntime(lang, env = process.env) {
|
|
|
20821
20880
|
for (const name of names) {
|
|
20822
20881
|
for (const file2 of fileNames(name, pathExt)) {
|
|
20823
20882
|
const full = path.join(dir, file2);
|
|
20824
|
-
|
|
20825
|
-
if (
|
|
20883
|
+
const state = probe(full);
|
|
20884
|
+
if (state === "unreadable") unreadable.push(full);
|
|
20885
|
+
if (state !== "runnable") continue;
|
|
20886
|
+
if (!isWin() || path.extname(full) !== "") return { found: full, unreadable };
|
|
20826
20887
|
if (shim === null) shim = full;
|
|
20827
20888
|
}
|
|
20828
20889
|
}
|
|
20829
20890
|
}
|
|
20830
|
-
return shim;
|
|
20891
|
+
return { found: shim, unreadable };
|
|
20831
20892
|
}
|
|
20832
20893
|
function findGitBash(env) {
|
|
20833
20894
|
const git2 = findRuntime(GIT_BIN, env);
|
|
@@ -20907,7 +20968,7 @@ function runProcess(argv, o) {
|
|
|
20907
20968
|
let stopTimer;
|
|
20908
20969
|
const kill = () => {
|
|
20909
20970
|
if (child.pid !== void 0) killTree(child.pid);
|
|
20910
|
-
if (stopTimer === void 0) stopTimer = setTimeout(() => finishHeld(), KILL_GRACE_MS);
|
|
20971
|
+
if (stopTimer === void 0) stopTimer = setTimeout(() => finishHeld(true), KILL_GRACE_MS);
|
|
20911
20972
|
};
|
|
20912
20973
|
const onAbort = () => {
|
|
20913
20974
|
if (killedBy !== null || settled) return;
|
|
@@ -20936,15 +20997,21 @@ function runProcess(argv, o) {
|
|
|
20936
20997
|
...held ? { held: true } : {}
|
|
20937
20998
|
});
|
|
20938
20999
|
};
|
|
20939
|
-
const finishHeld = () => {
|
|
21000
|
+
const finishHeld = (force = false) => {
|
|
20940
21001
|
if (settled) return;
|
|
20941
|
-
|
|
20942
|
-
|
|
20943
|
-
|
|
20944
|
-
|
|
20945
|
-
|
|
21002
|
+
const seen = chunkCount;
|
|
21003
|
+
setImmediate(() => {
|
|
21004
|
+
if (settled || !force && chunkCount !== seen) return;
|
|
21005
|
+
held = exited && killedBy === null && !(child.stdout.readableEnded && child.stderr.readableEnded);
|
|
21006
|
+
child.stdout.destroy();
|
|
21007
|
+
child.stderr.destroy();
|
|
21008
|
+
if (child.pid !== void 0) killTree(child.pid);
|
|
21009
|
+
settle(child.exitCode);
|
|
21010
|
+
});
|
|
20946
21011
|
};
|
|
21012
|
+
let chunkCount = 0;
|
|
20947
21013
|
const bump = () => {
|
|
21014
|
+
chunkCount++;
|
|
20948
21015
|
if (!exited || settled) return;
|
|
20949
21016
|
clearTimeout(graceTimer);
|
|
20950
21017
|
graceTimer = setTimeout(finishHeld, PIPE_EOF_GRACE_MS);
|
|
@@ -20962,7 +21029,7 @@ function runProcess(argv, o) {
|
|
|
20962
21029
|
if (settled) return;
|
|
20963
21030
|
exited = true;
|
|
20964
21031
|
graceTimer = setTimeout(finishHeld, PIPE_EOF_GRACE_MS);
|
|
20965
|
-
drainTimer = setTimeout(finishHeld, PIPE_DRAIN_MAX_MS);
|
|
21032
|
+
drainTimer = setTimeout(() => finishHeld(true), PIPE_DRAIN_MAX_MS);
|
|
20966
21033
|
});
|
|
20967
21034
|
child.on("error", () => settle(null));
|
|
20968
21035
|
child.stdin.on("error", () => {
|
|
@@ -21584,8 +21651,8 @@ var ctxBatch = Object.freeze({
|
|
|
21584
21651
|
});
|
|
21585
21652
|
|
|
21586
21653
|
// src/core/tools/doctor.ts
|
|
21587
|
-
import { readdirSync as readdirSync8, readFileSync as
|
|
21588
|
-
import { basename as basename5, join as
|
|
21654
|
+
import { readdirSync as readdirSync8, readFileSync as readFileSync17, existsSync as existsSync17 } from "node:fs";
|
|
21655
|
+
import { basename as basename5, join as join20 } from "node:path";
|
|
21589
21656
|
|
|
21590
21657
|
// src/core/ops/bundle-dir.ts
|
|
21591
21658
|
import { existsSync as existsSync4 } from "node:fs";
|
|
@@ -21610,8 +21677,8 @@ function ownBundleDir() {
|
|
|
21610
21677
|
}
|
|
21611
21678
|
|
|
21612
21679
|
// src/core/ops/doctor-config.ts
|
|
21613
|
-
import { existsSync as
|
|
21614
|
-
import { dirname as dirname8, isAbsolute as
|
|
21680
|
+
import { existsSync as existsSync11, readdirSync as readdirSync6, readFileSync as readFileSync13 } from "node:fs";
|
|
21681
|
+
import { dirname as dirname8, isAbsolute as isAbsolute5, join as join16, resolve as resolve9 } from "node:path";
|
|
21615
21682
|
|
|
21616
21683
|
// src/core/ops/detect-v1.ts
|
|
21617
21684
|
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync4, readFileSync as readFileSync8 } from "node:fs";
|
|
@@ -24600,6 +24667,14 @@ function configEntryRoot(adapter, env) {
|
|
|
24600
24667
|
if (typeof script !== "string" || !isAbsolute3(script)) throw missing(adapter.id, file2);
|
|
24601
24668
|
return dirname7(script);
|
|
24602
24669
|
}
|
|
24670
|
+
function packageDirOf(dir) {
|
|
24671
|
+
for (let cur = dir; ; ) {
|
|
24672
|
+
if (existsSync7(join13(cur, D1_PACKAGE_FILE))) return cur;
|
|
24673
|
+
const up = dirname7(cur);
|
|
24674
|
+
if (up === cur) return dir;
|
|
24675
|
+
cur = up;
|
|
24676
|
+
}
|
|
24677
|
+
}
|
|
24603
24678
|
function candidate(adapter, env, worktree) {
|
|
24604
24679
|
switch (adapter.installMode) {
|
|
24605
24680
|
case "marketplace":
|
|
@@ -24613,7 +24688,7 @@ function candidate(adapter, env, worktree) {
|
|
|
24613
24688
|
case "plugin":
|
|
24614
24689
|
return join13(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
24615
24690
|
case "in-process":
|
|
24616
|
-
return dirname7(fileURLToPath2(import.meta.url));
|
|
24691
|
+
return packageDirOf(dirname7(fileURLToPath2(import.meta.url)));
|
|
24617
24692
|
}
|
|
24618
24693
|
}
|
|
24619
24694
|
function resolvePluginRoot(adapter, env, worktree) {
|
|
@@ -24694,14 +24769,281 @@ function piInstalledIn(env, home, pkgDir, cwd) {
|
|
|
24694
24769
|
return user && ownEntries(user, pkgDir).length > 0 ? user.file : void 0;
|
|
24695
24770
|
}
|
|
24696
24771
|
|
|
24772
|
+
// src/core/ops/doctor-env.ts
|
|
24773
|
+
import { existsSync as existsSync9, readFileSync as readFileSync11, realpathSync as realpathSync6 } from "node:fs";
|
|
24774
|
+
import { isAbsolute as isAbsolute4, join as join14, relative as relative4 } from "node:path";
|
|
24775
|
+
function pass(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
24776
|
+
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
24777
|
+
}
|
|
24778
|
+
function unknown2(id2, detail, fixCommand) {
|
|
24779
|
+
return fixCommand === void 0 ? { id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail } : { id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail, fixCommand };
|
|
24780
|
+
}
|
|
24781
|
+
function fail2(id2, detail, fixCommand) {
|
|
24782
|
+
return { id: id2, label: DOCTOR_LABEL[id2], status: "FAIL", detail, fixCommand };
|
|
24783
|
+
}
|
|
24784
|
+
function warn(id2, detail, fixCommand) {
|
|
24785
|
+
return { id: id2, label: DOCTOR_LABEL[id2], status: "WARN", detail, fixCommand };
|
|
24786
|
+
}
|
|
24787
|
+
function bundleVersion(bundleDir2) {
|
|
24788
|
+
try {
|
|
24789
|
+
const v = JSON.parse(readFileSync11(join14(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24790
|
+
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24791
|
+
} catch {
|
|
24792
|
+
return void 0;
|
|
24793
|
+
}
|
|
24794
|
+
}
|
|
24795
|
+
function channelOf(version2) {
|
|
24796
|
+
const at2 = version2.indexOf(D1_PRERELEASE_SEP);
|
|
24797
|
+
if (at2 < 0) return D1_DEFAULT_TAG;
|
|
24798
|
+
const pre = version2.slice(at2 + 1);
|
|
24799
|
+
const dot = pre.indexOf(".");
|
|
24800
|
+
const tag2 = dot < 0 ? pre : pre.slice(0, dot);
|
|
24801
|
+
return tag2 === "" ? D1_DEFAULT_TAG : tag2;
|
|
24802
|
+
}
|
|
24803
|
+
function firstLine3(b) {
|
|
24804
|
+
const text = b.toString("utf8").trim();
|
|
24805
|
+
const nl = text.indexOf("\n");
|
|
24806
|
+
return (nl < 0 ? text : text.slice(0, nl)).trim();
|
|
24807
|
+
}
|
|
24808
|
+
function gitCause(r, timeoutMs) {
|
|
24809
|
+
if (r.killed === "timeout") return D1_GIT_TIMEOUT(timeoutMs);
|
|
24810
|
+
if (r.killed === "cancel") return D1_GIT_CANCEL;
|
|
24811
|
+
if (r.exitCode === null) return D1_GIT_NO_START;
|
|
24812
|
+
return D1_GIT_EXIT(r.exitCode, firstLine3(r.stderr));
|
|
24813
|
+
}
|
|
24814
|
+
function fetchCause(err, timeoutMs) {
|
|
24815
|
+
const name = err instanceof Error ? err.name : "";
|
|
24816
|
+
if (name === "TimeoutError") return D1_NPM_TIMEOUT(timeoutMs);
|
|
24817
|
+
const cause = err instanceof Error && err.cause instanceof Error ? err.cause : err;
|
|
24818
|
+
const code = typeof cause === "object" && cause !== null && "code" in cause && typeof cause.code === "string" ? cause.code : "";
|
|
24819
|
+
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
24820
|
+
const parts = code !== "" && !msg.includes(code) ? [code, msg] : [msg];
|
|
24821
|
+
return D1_NPM_ERROR(parts.filter((part) => part !== "").join(" "));
|
|
24822
|
+
}
|
|
24823
|
+
async function npmLatest(url2, tag2, signal, timeoutMs) {
|
|
24824
|
+
try {
|
|
24825
|
+
const res = await fetch(url2, { signal: AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) });
|
|
24826
|
+
if (!res.ok) return { ok: false, cause: D1_NPM_HTTP(res.status) };
|
|
24827
|
+
const body = await res.json();
|
|
24828
|
+
const v = typeof body === "object" && body !== null ? body[tag2] : void 0;
|
|
24829
|
+
return typeof v === "string" && v !== "" ? { ok: true, version: v } : { ok: false, cause: D1_NPM_NO_TAG(tag2) };
|
|
24830
|
+
} catch (err) {
|
|
24831
|
+
return { ok: false, cause: fetchCause(err, timeoutMs) };
|
|
24832
|
+
}
|
|
24833
|
+
}
|
|
24834
|
+
function digits(s) {
|
|
24835
|
+
if (s === "") return false;
|
|
24836
|
+
for (const ch of s) if (ch < "0" || ch > "9") return false;
|
|
24837
|
+
return true;
|
|
24838
|
+
}
|
|
24839
|
+
function parseVersion(v) {
|
|
24840
|
+
const at2 = v.indexOf(D1_PRERELEASE_SEP);
|
|
24841
|
+
const core = (at2 < 0 ? v : v.slice(0, at2)).split(NODE_VERSION_SEP);
|
|
24842
|
+
if (core.length !== 3 || !core.every(digits)) return null;
|
|
24843
|
+
const nums = [Number(core[0]), Number(core[1]), Number(core[2])];
|
|
24844
|
+
if (at2 < 0) return { core: nums, pre: [] };
|
|
24845
|
+
const pre = v.slice(at2 + 1).split(NODE_VERSION_SEP);
|
|
24846
|
+
if (pre[0] === "" || digits(pre[0]) || pre.length > 2) return null;
|
|
24847
|
+
if (pre.length === 1) return { core: nums, pre: [pre[0]] };
|
|
24848
|
+
return digits(pre[1]) ? { core: nums, pre: [pre[0], Number(pre[1])] } : null;
|
|
24849
|
+
}
|
|
24850
|
+
function sign(n) {
|
|
24851
|
+
return n < 0 ? -1 : n > 0 ? 1 : 0;
|
|
24852
|
+
}
|
|
24853
|
+
function compareVersions(a, b) {
|
|
24854
|
+
const x = parseVersion(a);
|
|
24855
|
+
const y = parseVersion(b);
|
|
24856
|
+
if (x === null || y === null) return null;
|
|
24857
|
+
for (let k = 0; k < 3; k++) if (x.core[k] !== y.core[k]) return sign(x.core[k] - y.core[k]);
|
|
24858
|
+
if (x.pre.length === 0 || y.pre.length === 0) return sign(y.pre.length - x.pre.length);
|
|
24859
|
+
if (x.pre[0] !== y.pre[0]) return x.pre[0] < y.pre[0] ? -1 : 1;
|
|
24860
|
+
return sign((x.pre[1] ?? -1) - (y.pre[1] ?? -1));
|
|
24861
|
+
}
|
|
24862
|
+
function highestTag(stdout, tag2) {
|
|
24863
|
+
let best;
|
|
24864
|
+
for (const line of stdout.split("\n")) {
|
|
24865
|
+
const [sha, ref] = line.trim().split(LS_REMOTE_FIELD_SEP);
|
|
24866
|
+
if (sha === void 0 || sha.length !== GIT_SHA_HEX_LEN || ref === void 0 || !ref.startsWith(RELEASE_TAG_REF_PREFIX)) continue;
|
|
24867
|
+
const v = ref.slice(RELEASE_TAG_REF_PREFIX.length);
|
|
24868
|
+
if (parseVersion(v) === null || channelOf(v) !== tag2) continue;
|
|
24869
|
+
if (best === void 0 || compareVersions(v, best) === 1) best = v;
|
|
24870
|
+
}
|
|
24871
|
+
return best;
|
|
24872
|
+
}
|
|
24873
|
+
function versionRow(head2, installed, tag2, source, latest, tail, update) {
|
|
24874
|
+
const cmp = compareVersions(installed, latest) ?? (installed === latest ? 0 : -1);
|
|
24875
|
+
if (cmp === 0) return pass("D1", head2 + D1_LATEST_PASS(tag2, source) + tail);
|
|
24876
|
+
if (cmp > 0) return pass("D1", head2 + D1_LATEST_AHEAD(tag2, source, latest) + tail);
|
|
24877
|
+
return warn("D1", head2 + D1_LATEST_UPDATE(tag2, source, latest) + tail, update);
|
|
24878
|
+
}
|
|
24879
|
+
async function checkVersion(i) {
|
|
24880
|
+
if (i.bundleSha === void 0) return unknown2("D1", D1_DEV_BUILD_DETAIL);
|
|
24881
|
+
const head2 = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
24882
|
+
if (i.version === void 0) return unknown2("D1", head2 + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
|
|
24883
|
+
const tag2 = channelOf(i.version);
|
|
24884
|
+
const update = i.updateCommand ?? DOCTOR_FIX_UPGRADE;
|
|
24885
|
+
const git2 = findRuntime(GIT_BIN, i.env);
|
|
24886
|
+
const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
|
|
24887
|
+
if (npm.ok) return versionRow(head2, i.version, tag2, D1_SOURCE_NPM, npm.version, "", update);
|
|
24888
|
+
let cause = D1_GIT_MISSING;
|
|
24889
|
+
if (git2 !== null) {
|
|
24890
|
+
const r = await runProcess([git2, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
|
|
24891
|
+
cwd: i.cwd,
|
|
24892
|
+
env: { ...i.env, ...GIT_NO_PROMPT_ENV },
|
|
24893
|
+
signal: i.signal,
|
|
24894
|
+
timeoutMs: i.timeoutMs
|
|
24895
|
+
});
|
|
24896
|
+
if (r.exitCode === 0 && r.killed === null) {
|
|
24897
|
+
const latest = highestTag(r.stdout.toString("utf8"), tag2);
|
|
24898
|
+
if (latest !== void 0) return versionRow(head2, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause, update);
|
|
24899
|
+
cause = D1_GIT_NO_TAG(tag2);
|
|
24900
|
+
} else {
|
|
24901
|
+
cause = gitCause(r, i.timeoutMs);
|
|
24902
|
+
}
|
|
24903
|
+
}
|
|
24904
|
+
return unknown2("D1", head2 + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause, git2 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX);
|
|
24905
|
+
}
|
|
24906
|
+
function numbers(v) {
|
|
24907
|
+
const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
|
|
24908
|
+
return bare2.split(NODE_VERSION_SEP).map(Number);
|
|
24909
|
+
}
|
|
24910
|
+
function belowMin(version2) {
|
|
24911
|
+
const got = numbers(version2);
|
|
24912
|
+
const min = numbers(NODE_MIN);
|
|
24913
|
+
for (let k = 0; k < min.length; k++) {
|
|
24914
|
+
const g = got[k] ?? 0;
|
|
24915
|
+
if (g !== min[k]) return g < min[k];
|
|
24916
|
+
}
|
|
24917
|
+
return false;
|
|
24918
|
+
}
|
|
24919
|
+
async function sqliteLoads() {
|
|
24920
|
+
try {
|
|
24921
|
+
await import(SQLITE_MODULE);
|
|
24922
|
+
return true;
|
|
24923
|
+
} catch {
|
|
24924
|
+
return false;
|
|
24925
|
+
}
|
|
24926
|
+
}
|
|
24927
|
+
async function checkNode(i) {
|
|
24928
|
+
const bun = i.bunVersion === void 0 ? [] : [D2_BUN_DETAIL(i.bunVersion)];
|
|
24929
|
+
const withBun = (detail) => [detail, ...bun].join(D4_REASON_JOIN);
|
|
24930
|
+
if (belowMin(i.nodeVersion)) return fail2("D2", withBun(D2_NODE_DETAIL(i.nodeVersion)), D2_NODE_FIX);
|
|
24931
|
+
if (!await sqliteLoads()) return fail2("D2", withBun(D2_SQLITE_DETAIL), D2_SQLITE_FIX);
|
|
24932
|
+
return pass("D2", bun.length === 0 ? DOCTOR_PASS_DETAIL : bun.join(D4_REASON_JOIN));
|
|
24933
|
+
}
|
|
24934
|
+
function checkMcp(ctx, adapter) {
|
|
24935
|
+
const named2 = ctx.clientInfo !== void 0 && ctx.clientInfo.name !== "";
|
|
24936
|
+
const versioned = ctx.protocolVersion !== void 0 && ctx.protocolVersion !== "";
|
|
24937
|
+
if (named2 || versioned) return pass("D6");
|
|
24938
|
+
return adapter?.installMode === "in-process" ? pass("D6", D6_IN_PROCESS_DETAIL) : unknown2("D6", D6_UNKNOWN_DETAIL);
|
|
24939
|
+
}
|
|
24940
|
+
function piCwdInside(worktree, piCwd) {
|
|
24941
|
+
if (piCwd === void 0 || !existsSync9(piCwd)) return false;
|
|
24942
|
+
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
24943
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute4(rel);
|
|
24944
|
+
}
|
|
24945
|
+
function checkProject(i) {
|
|
24946
|
+
const bad = fail2("D7", D7_DETAIL(i.project.source), D7_FIX);
|
|
24947
|
+
if (i.project.source !== i.adapter.projectSource) return bad;
|
|
24948
|
+
if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
|
|
24949
|
+
return pass("D7");
|
|
24950
|
+
}
|
|
24951
|
+
function checkMode(adapter, hostPermission) {
|
|
24952
|
+
if (hostPermission === "missing") return fail2("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
|
|
24953
|
+
if (hostPermission === "wired") return pass("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
|
|
24954
|
+
return pass("D10", D10_DETAIL(adapter.denyChannel));
|
|
24955
|
+
}
|
|
24956
|
+
function checkShell(env) {
|
|
24957
|
+
const win = process.platform === "win32";
|
|
24958
|
+
const shell = findRuntime("shell", env);
|
|
24959
|
+
if (shell !== null) return pass("D11", D11_PASS_DETAIL(shell, win));
|
|
24960
|
+
return win ? fail2("D11", D11_WIN_DETAIL, D11_WIN_FIX) : fail2("D11", D11_POSIX_DETAIL, D11_POSIX_FIX);
|
|
24961
|
+
}
|
|
24962
|
+
function checkRuntimes(env, shellRow) {
|
|
24963
|
+
if (shellRow.status !== "PASS") return shellRow;
|
|
24964
|
+
for (const lang of EXEC_LANGUAGES) {
|
|
24965
|
+
if (lang === "shell") continue;
|
|
24966
|
+
const r = lookupRuntime(lang, env);
|
|
24967
|
+
if (r.found === null && r.unreadable.length > 0) return warn("D11", D11_RUNTIME_DETAIL(lang, r.unreadable), D11_RUNTIME_FIX(lang));
|
|
24968
|
+
}
|
|
24969
|
+
return shellRow;
|
|
24970
|
+
}
|
|
24971
|
+
|
|
24972
|
+
// src/core/ops/omp-import.ts
|
|
24973
|
+
import { join as join15 } from "node:path";
|
|
24974
|
+
var { existsSync: existsSync10, readFileSync: readFileSync12 } = process.getBuiltinModule("node:fs");
|
|
24975
|
+
var OMP_DISABLED_SERVERS_KEY = "disabledServers";
|
|
24976
|
+
var OMP_MCP_FILE = "mcp.json";
|
|
24977
|
+
var OMP_CONFIG_FILE = "config.yml";
|
|
24978
|
+
var ENABLED_PROVIDERS = "enabledProviders";
|
|
24979
|
+
var DISABLED_PROVIDERS = "disabledProviders";
|
|
24980
|
+
var CLAUDE_PROVIDER = "claude";
|
|
24981
|
+
var ALL_PROVIDERS = ["*", "all"];
|
|
24982
|
+
function ompImportFiles(home) {
|
|
24983
|
+
const agentDir = join15(home, ...AGENT_HOME_DIR.omp, PI_AGENT_DIR);
|
|
24984
|
+
return { config: join15(agentDir, OMP_CONFIG_FILE), mcp: join15(agentDir, OMP_MCP_FILE), claude: join15(home, CLAUDE_USER_CONFIG_FILE) };
|
|
24985
|
+
}
|
|
24986
|
+
function readText2(file2) {
|
|
24987
|
+
try {
|
|
24988
|
+
return existsSync10(file2) ? hostText(readFileSync12(file2, "utf8")) : void 0;
|
|
24989
|
+
} catch {
|
|
24990
|
+
return void 0;
|
|
24991
|
+
}
|
|
24992
|
+
}
|
|
24993
|
+
var unquote3 = (s) => {
|
|
24994
|
+
const t = s.trim();
|
|
24995
|
+
const q = t[0];
|
|
24996
|
+
return (q === '"' || q === "'") && t.endsWith(q) && t.length > 1 ? t.slice(1, -1) : t;
|
|
24997
|
+
};
|
|
24998
|
+
var withoutComment = (s) => {
|
|
24999
|
+
const at2 = s.indexOf(" #");
|
|
25000
|
+
return at2 === -1 ? s : s.slice(0, at2);
|
|
25001
|
+
};
|
|
25002
|
+
function yamlTopList(text, key) {
|
|
25003
|
+
const lines = text.split("\n").map((l) => l.endsWith("\r") ? l.slice(0, -1) : l);
|
|
25004
|
+
const head2 = `${key}:`;
|
|
25005
|
+
const at2 = lines.findIndex((l) => l.startsWith(head2));
|
|
25006
|
+
if (at2 === -1) return [];
|
|
25007
|
+
const rest = withoutComment(lines[at2].slice(head2.length)).trim();
|
|
25008
|
+
if (rest.startsWith("[")) {
|
|
25009
|
+
const end = rest.indexOf("]");
|
|
25010
|
+
return (end === -1 ? rest.slice(1) : rest.slice(1, end)).split(",").map(unquote3).filter((x) => x !== "");
|
|
25011
|
+
}
|
|
25012
|
+
if (rest !== "") return [];
|
|
25013
|
+
const out = [];
|
|
25014
|
+
for (const line of lines.slice(at2 + 1)) {
|
|
25015
|
+
const t = line.trim();
|
|
25016
|
+
if (t === "" || t.startsWith("#")) continue;
|
|
25017
|
+
if (line === line.trimStart() && !t.startsWith("-")) break;
|
|
25018
|
+
if (!t.startsWith("-")) break;
|
|
25019
|
+
out.push(unquote3(withoutComment(t.slice(1))));
|
|
25020
|
+
}
|
|
25021
|
+
return out;
|
|
25022
|
+
}
|
|
25023
|
+
function ompImportsUs(files, env) {
|
|
25024
|
+
const config2 = readText2(files.config) ?? "";
|
|
25025
|
+
if (yamlTopList(config2, DISABLED_PROVIDERS).includes(CLAUDE_PROVIDER)) return false;
|
|
25026
|
+
const enabled = yamlTopList(config2, ENABLED_PROVIDERS);
|
|
25027
|
+
const dirSet = env[CLAUDE_CONFIG_DIR_ENV] !== void 0 && env[CLAUDE_CONFIG_DIR_ENV] !== "";
|
|
25028
|
+
if (!dirSet && !enabled.some((p) => p === CLAUDE_PROVIDER || ALL_PROVIDERS.includes(p))) return false;
|
|
25029
|
+
const claude = readText2(files.claude);
|
|
25030
|
+
if (claude === void 0) return false;
|
|
25031
|
+
try {
|
|
25032
|
+
const servers = JSON.parse(claude)[MCP_SERVERS_KEY];
|
|
25033
|
+
return typeof servers === "object" && servers !== null && Object.hasOwn(servers, SERVER_KEY);
|
|
25034
|
+
} catch {
|
|
25035
|
+
return false;
|
|
25036
|
+
}
|
|
25037
|
+
}
|
|
25038
|
+
|
|
24697
25039
|
// src/core/ops/doctor-config.ts
|
|
24698
25040
|
var [PART_MCP, PART_HOOKS, PART_TIMEOUT] = D3_PARTS;
|
|
24699
25041
|
var isObject4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
24700
25042
|
var list2 = (v) => Array.isArray(v) ? v : [];
|
|
24701
|
-
function
|
|
25043
|
+
function pass2(id2) {
|
|
24702
25044
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail: DOCTOR_PASS_DETAIL };
|
|
24703
25045
|
}
|
|
24704
|
-
function
|
|
25046
|
+
function fail3(id2, detail, fixCommand) {
|
|
24705
25047
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "FAIL", detail, fixCommand };
|
|
24706
25048
|
}
|
|
24707
25049
|
function readParsed(agent, file2) {
|
|
@@ -24771,11 +25113,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
24771
25113
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
24772
25114
|
function mcpFile(row5, home, env) {
|
|
24773
25115
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
24774
|
-
if (row5.id === "codex") return
|
|
25116
|
+
if (row5.id === "codex") return join16(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
24775
25117
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
24776
|
-
if (row5.id === "opencode") return
|
|
25118
|
+
if (row5.id === "opencode") return join16(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
24777
25119
|
if (row5.id === "pi") {
|
|
24778
|
-
return
|
|
25120
|
+
return join16(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
24779
25121
|
}
|
|
24780
25122
|
return null;
|
|
24781
25123
|
}
|
|
@@ -24788,27 +25130,27 @@ function codexNativeDir(env, home) {
|
|
|
24788
25130
|
const codexDir = codexDirOf(env, home);
|
|
24789
25131
|
let enabled;
|
|
24790
25132
|
try {
|
|
24791
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
25133
|
+
enabled = hostConfigValueAt(readParsed("codex", join16(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
24792
25134
|
} catch {
|
|
24793
25135
|
return null;
|
|
24794
25136
|
}
|
|
24795
25137
|
if (enabled !== true) return null;
|
|
24796
|
-
const cache =
|
|
24797
|
-
if (!
|
|
25138
|
+
const cache = join16(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
25139
|
+
if (!existsSync11(cache)) return null;
|
|
24798
25140
|
const found = [];
|
|
24799
25141
|
for (const market of readdirSync6(cache)) {
|
|
24800
|
-
const plugin =
|
|
24801
|
-
if (!
|
|
25142
|
+
const plugin = join16(cache, market, SERVER_KEY);
|
|
25143
|
+
if (!existsSync11(plugin)) continue;
|
|
24802
25144
|
for (const version2 of readdirSync6(plugin).sort()) {
|
|
24803
|
-
const dir =
|
|
24804
|
-
if (
|
|
25145
|
+
const dir = join16(plugin, version2, CODEX_PLUGIN_SUBDIR);
|
|
25146
|
+
if (existsSync11(join16(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
24805
25147
|
}
|
|
24806
25148
|
}
|
|
24807
25149
|
return found.length === 0 ? null : found[found.length - 1];
|
|
24808
25150
|
}
|
|
24809
25151
|
function nativeMcpWrong(dir, row5) {
|
|
24810
25152
|
try {
|
|
24811
|
-
const entry = hostConfigValueAt(readParsed(row5.id,
|
|
25153
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join16(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
24812
25154
|
if (!isObject4(entry)) return true;
|
|
24813
25155
|
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
24814
25156
|
const script = args[0];
|
|
@@ -24879,17 +25221,17 @@ function opencodePluginDirs(configDir, worktree) {
|
|
|
24879
25221
|
return [configDir, opencodeProjectDir(worktree)];
|
|
24880
25222
|
}
|
|
24881
25223
|
function opencodeProjectDir(worktree) {
|
|
24882
|
-
return
|
|
25224
|
+
return join16(worktree, OPENCODE_PROJECT_DIR);
|
|
24883
25225
|
}
|
|
24884
25226
|
function packageResolves(fromDir) {
|
|
24885
25227
|
for (let d = fromDir; ; d = dirname8(d)) {
|
|
24886
|
-
if (
|
|
25228
|
+
if (existsSync11(join16(d, NODE_MODULES_DIR, SERVER_KEY, PACKAGE_JSON_FILE))) return true;
|
|
24887
25229
|
if (dirname8(d) === d) return false;
|
|
24888
25230
|
}
|
|
24889
25231
|
}
|
|
24890
25232
|
function opencodeDirPlugins(dirs) {
|
|
24891
25233
|
const bundle = opencodePluginFile();
|
|
24892
|
-
const ownFile =
|
|
25234
|
+
const ownFile = join16(bundle, ...OPENCODE_PLUGIN_PATH).split("\\").join("/");
|
|
24893
25235
|
const isModule = (p) => OWN_PLUGIN_MODULES.includes(p);
|
|
24894
25236
|
const isPath = (p) => {
|
|
24895
25237
|
if (p === ownFile || p === `${FILE_URL_PREFIX}${ownFile}`) return true;
|
|
@@ -24899,7 +25241,7 @@ function opencodeDirPlugins(dirs) {
|
|
|
24899
25241
|
};
|
|
24900
25242
|
const out = [];
|
|
24901
25243
|
for (const dir of dirs) {
|
|
24902
|
-
const pdir =
|
|
25244
|
+
const pdir = join16(dir, OPENCODE_PLUGINS_DIR);
|
|
24903
25245
|
let names;
|
|
24904
25246
|
try {
|
|
24905
25247
|
names = readdirSync6(pdir);
|
|
@@ -24907,12 +25249,12 @@ function opencodeDirPlugins(dirs) {
|
|
|
24907
25249
|
continue;
|
|
24908
25250
|
}
|
|
24909
25251
|
for (const name of names) {
|
|
24910
|
-
const loose = OPENCODE_PLUGIN_EXTS.some((x) => name.endsWith(x)) ? [
|
|
24911
|
-
const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x) =>
|
|
25252
|
+
const loose = OPENCODE_PLUGIN_EXTS.some((x) => name.endsWith(x)) ? [join16(pdir, name)] : [];
|
|
25253
|
+
const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x) => join16(pdir, name, `${OPENCODE_PLUGIN_INDEX}${x}`))];
|
|
24912
25254
|
for (const f of files) {
|
|
24913
25255
|
let text;
|
|
24914
25256
|
try {
|
|
24915
|
-
const b =
|
|
25257
|
+
const b = readFileSync13(f);
|
|
24916
25258
|
if (b.length > OPENCODE_DIR_FILE_MAX) continue;
|
|
24917
25259
|
text = b.toString("utf8");
|
|
24918
25260
|
} catch {
|
|
@@ -24923,7 +25265,7 @@ function opencodeDirPlugins(dirs) {
|
|
|
24923
25265
|
const loads = lits.some((p) => {
|
|
24924
25266
|
if (isModule(p)) return packageResolves(dirname8(f));
|
|
24925
25267
|
const bare2 = p.startsWith(FILE_URL_PREFIX) ? p.slice(FILE_URL_PREFIX.length) : p;
|
|
24926
|
-
return
|
|
25268
|
+
return existsSync11(isAbsolute5(bare2) ? bare2 : resolve9(dirname8(f), bare2));
|
|
24927
25269
|
});
|
|
24928
25270
|
out.push({ file: f, loads });
|
|
24929
25271
|
}
|
|
@@ -24941,19 +25283,19 @@ function opencodeMcpOwn(entry) {
|
|
|
24941
25283
|
return isNodeCommand(node) && typeof script === "string" && lastSegment(script) === SERVER_ENTRY_FILE && flag === AGENT_ARG && agent === "opencode";
|
|
24942
25284
|
}
|
|
24943
25285
|
function opencodeFileValue(file2) {
|
|
24944
|
-
if (!
|
|
24945
|
-
return parseHostConfig("opencode", file2, hostText(
|
|
25286
|
+
if (!existsSync11(file2)) return {};
|
|
25287
|
+
return parseHostConfig("opencode", file2, hostText(readFileSync13(file2, "utf8")), "jsonc");
|
|
24946
25288
|
}
|
|
24947
25289
|
function opencodeValueListed(value) {
|
|
24948
25290
|
const bundle = opencodePluginFile();
|
|
24949
|
-
const own2 = [bundle,
|
|
25291
|
+
const own2 = [bundle, join16(bundle, ...OPENCODE_PLUGIN_PATH)];
|
|
24950
25292
|
if ([OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list2(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own2)))) return true;
|
|
24951
25293
|
const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
|
|
24952
25294
|
return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
|
|
24953
25295
|
}
|
|
24954
25296
|
function opencodeListed(file2, worktree) {
|
|
24955
25297
|
const dirs = [dirname8(file2), worktree];
|
|
24956
|
-
if (dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(
|
|
25298
|
+
if (dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(join16(dir, name)))))) return true;
|
|
24957
25299
|
return opencodeDirPlugin(opencodePluginDirs(dirname8(file2), worktree)) !== void 0;
|
|
24958
25300
|
}
|
|
24959
25301
|
function mcpWrong(row5, home, env, worktree) {
|
|
@@ -24975,7 +25317,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
24975
25317
|
function hookFile(row5, spec, home, env, worktree) {
|
|
24976
25318
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
24977
25319
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24978
|
-
const file2 = native !== null ?
|
|
25320
|
+
const file2 = native !== null ? join16(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join16(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join16(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join16(kiroDirOf(env, home), ...spec.file.slice(1)) : join16(root, ...spec.file);
|
|
24979
25321
|
return file2;
|
|
24980
25322
|
}
|
|
24981
25323
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -24986,7 +25328,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
24986
25328
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
24987
25329
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
24988
25330
|
if (row5.id === "codex") {
|
|
24989
|
-
const config2 = readParsed(row5.id,
|
|
25331
|
+
const config2 = readParsed(row5.id, join16(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
24990
25332
|
if (hostConfigValueAt(config2, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
24991
25333
|
}
|
|
24992
25334
|
} catch {
|
|
@@ -25015,29 +25357,67 @@ function hookParts(row5, home, env, worktree) {
|
|
|
25015
25357
|
}
|
|
25016
25358
|
function checkHostConfig(row5, env, worktree) {
|
|
25017
25359
|
const home = homeDirOf(env);
|
|
25018
|
-
if (home === null) return
|
|
25360
|
+
if (home === null) return fail3("D3", D3_DETAIL(D3_PARTS), DOCTOR_FIX_UPGRADE);
|
|
25019
25361
|
if (row5.installMode === "marketplace") {
|
|
25020
25362
|
const choice = marketplaceChoice(env, worktree);
|
|
25021
|
-
if ("installs" in choice) return
|
|
25363
|
+
if ("installs" in choice) return fail3("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
|
|
25022
25364
|
}
|
|
25023
25365
|
if (row5.id === "pi") return checkPiInstall(env, home, worktree);
|
|
25366
|
+
if (row5.id === "omp") return checkOmpInstall(home);
|
|
25024
25367
|
const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
|
|
25025
|
-
if (parts.length === 0) return
|
|
25368
|
+
if (parts.length === 0) return pass2("D3");
|
|
25026
25369
|
const detail = D3_DETAIL(parts);
|
|
25027
25370
|
const fix = parts.includes(PART_MCP) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
|
|
25028
|
-
return
|
|
25371
|
+
return fail3("D3", detail, fix);
|
|
25029
25372
|
}
|
|
25030
25373
|
function checkPiInstall(env, home, worktree) {
|
|
25031
25374
|
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
25032
|
-
if (found !== void 0) return { ...
|
|
25033
|
-
return
|
|
25375
|
+
if (found !== void 0) return { ...pass2("D3"), detail: found };
|
|
25376
|
+
return fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join16(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
|
|
25377
|
+
}
|
|
25378
|
+
var OMP_PLUGINS_DIR = "plugins";
|
|
25379
|
+
var OMP_LOCK_FILE = "omp-plugins.lock.json";
|
|
25380
|
+
function readJson2(file2) {
|
|
25381
|
+
try {
|
|
25382
|
+
const doc = JSON.parse(readFileSync13(file2, "utf8"));
|
|
25383
|
+
return typeof doc === "object" && doc !== null ? doc : void 0;
|
|
25384
|
+
} catch {
|
|
25385
|
+
return void 0;
|
|
25386
|
+
}
|
|
25387
|
+
}
|
|
25388
|
+
function ownEntry(doc, key) {
|
|
25389
|
+
const map2 = doc?.[key];
|
|
25390
|
+
return typeof map2 === "object" && map2 !== null ? map2[SERVER_KEY] : void 0;
|
|
25391
|
+
}
|
|
25392
|
+
function checkOmpInstall(home) {
|
|
25393
|
+
const dir = join16(home, ...AGENT_HOME_DIR.omp, OMP_PLUGINS_DIR);
|
|
25394
|
+
const lock = join16(dir, OMP_LOCK_FILE);
|
|
25395
|
+
const pkg = join16(dir, PI_PACKAGE_JSON_FILE);
|
|
25396
|
+
const entry = ownEntry(readJson2(lock), "plugins");
|
|
25397
|
+
const missing2 = (file2) => fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + file2, NATIVE_INSTALL.omp[0]);
|
|
25398
|
+
if (typeof entry !== "object" || entry === null) return missing2(lock);
|
|
25399
|
+
if (ownEntry(readJson2(pkg), "dependencies") === void 0) return missing2(pkg);
|
|
25400
|
+
if (entry.enabled !== true) return fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + lock, OMP_ENABLE_COMMAND);
|
|
25401
|
+
return { ...pass2("D3"), detail: lock };
|
|
25402
|
+
}
|
|
25403
|
+
function ompInfoLines(env, version2) {
|
|
25404
|
+
const out = [];
|
|
25405
|
+
if (version2 !== void 0 && compareVersions(version2, OMP_MIN_VERSION) === -1) out.push(OMP_FLOOR_INFO(version2));
|
|
25406
|
+
out.push(OMP_CONTENT_INFO, OMP_PRINT_MODE_INFO, OMP_SCRIPTS_INFO);
|
|
25407
|
+
const home = homeDirOf(env);
|
|
25408
|
+
if (home === null) return out;
|
|
25409
|
+
const files = ompImportFiles(home);
|
|
25410
|
+
if (!ompImportsUs(files, env)) return out;
|
|
25411
|
+
const listed = readJson2(files.mcp)?.[OMP_DISABLED_SERVERS_KEY];
|
|
25412
|
+
if (!(Array.isArray(listed) && listed.includes(SERVER_KEY))) out.push(OMP_IMPORT_INFO(files.claude, files.mcp));
|
|
25413
|
+
return out;
|
|
25034
25414
|
}
|
|
25035
25415
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
25036
25416
|
const findings = detectV1(agent, home, scope);
|
|
25037
|
-
if (findings.length === 0) return
|
|
25417
|
+
if (findings.length === 0) return pass2("D4");
|
|
25038
25418
|
const detail = findings.map((f) => f.reason).join(D4_REASON_JOIN);
|
|
25039
|
-
if (findings.every((f) => f.reason === V1_REASON.tmpFile)) return { ...
|
|
25040
|
-
return { ...
|
|
25419
|
+
if (findings.every((f) => f.reason === V1_REASON.tmpFile)) return { ...pass2("D4"), detail };
|
|
25420
|
+
return { ...fail3("D4", detail, DOCTOR_FIX_UPGRADE), status: "WARN" };
|
|
25041
25421
|
}
|
|
25042
25422
|
function parsedOrNull(agent, file2, jsonc) {
|
|
25043
25423
|
try {
|
|
@@ -25048,13 +25428,13 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
25048
25428
|
}
|
|
25049
25429
|
}
|
|
25050
25430
|
function checkDoubleFire(agent, worktree) {
|
|
25051
|
-
if (agent !== "claude-code" && agent !== "vscode") return
|
|
25052
|
-
const claude = parsedOrNull(agent,
|
|
25431
|
+
if (agent !== "claude-code" && agent !== "vscode") return pass2("D5b");
|
|
25432
|
+
const claude = parsedOrNull(agent, join16(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
25053
25433
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
25054
25434
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
25055
|
-
const vscode = parsedOrNull(agent,
|
|
25435
|
+
const vscode = parsedOrNull(agent, join16(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
25056
25436
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
25057
|
-
return hooksOn && useClaudeHooks ?
|
|
25437
|
+
return hooksOn && useClaudeHooks ? fail3("D5b", D5B_DETAIL, D5B_FIX) : pass2("D5b");
|
|
25058
25438
|
}
|
|
25059
25439
|
function configPaths(row5, env, worktree) {
|
|
25060
25440
|
const home = homeDirOf(env);
|
|
@@ -25063,7 +25443,7 @@ function configPaths(row5, env, worktree) {
|
|
|
25063
25443
|
const mcp = mcpFile(row5, home, env);
|
|
25064
25444
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
25065
25445
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
25066
|
-
if (native !== null) out.push({ label: "Codex plugin MCP", path:
|
|
25446
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join16(native, CODEX_PLUGIN_MCP_FILE) });
|
|
25067
25447
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
25068
25448
|
if (spec !== null) {
|
|
25069
25449
|
try {
|
|
@@ -25083,10 +25463,10 @@ function configPaths(row5, env, worktree) {
|
|
|
25083
25463
|
}
|
|
25084
25464
|
|
|
25085
25465
|
// src/core/ops/doctor-db.ts
|
|
25086
|
-
import { existsSync as
|
|
25087
|
-
var
|
|
25088
|
-
var
|
|
25089
|
-
var
|
|
25466
|
+
import { existsSync as existsSync12, statSync as statSync5 } from "node:fs";
|
|
25467
|
+
var unknown3 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
|
|
25468
|
+
var pass3 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
|
|
25469
|
+
var fail4 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
25090
25470
|
function isCorrupt2(err) {
|
|
25091
25471
|
if (typeof err !== "object" || err === null) return false;
|
|
25092
25472
|
const code = err.errcode;
|
|
@@ -25125,17 +25505,17 @@ function orphanFiles(dbPath) {
|
|
|
25125
25505
|
const files = [];
|
|
25126
25506
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
25127
25507
|
const path8 = dbPath + suffix;
|
|
25128
|
-
if (
|
|
25508
|
+
if (existsSync12(path8)) files.push({ path: path8, bytes: statSync5(path8).size });
|
|
25129
25509
|
}
|
|
25130
|
-
return files.length > 0 && !
|
|
25510
|
+
return files.length > 0 && !existsSync12(dbPath) ? files : [];
|
|
25131
25511
|
}
|
|
25132
25512
|
async function checkDb(project) {
|
|
25133
25513
|
const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
|
|
25134
25514
|
const orphan = orphanFiles(project.dbPath);
|
|
25135
|
-
if (orphan.length > 0) return { row:
|
|
25136
|
-
if (!
|
|
25515
|
+
if (orphan.length > 0) return { row: fail4(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
|
|
25516
|
+
if (!existsSync12(project.dbPath)) return { row: pass3("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
25137
25517
|
const sqlite = await loadSqlite2();
|
|
25138
|
-
if (sqlite === null) return { row:
|
|
25518
|
+
if (sqlite === null) return { row: unknown3("D8", D2_SQLITE_DETAIL), ...clean };
|
|
25139
25519
|
let raw = null;
|
|
25140
25520
|
try {
|
|
25141
25521
|
raw = openRead(sqlite, project.dbPath);
|
|
@@ -25148,226 +25528,35 @@ async function checkDb(project) {
|
|
|
25148
25528
|
}
|
|
25149
25529
|
const schemaStale = got !== null && got !== SCHEMA_VERSION;
|
|
25150
25530
|
const integrityFailed = failsOnCorrupt(() => !integrityOk(db));
|
|
25151
|
-
if (integrityFailed) return { row:
|
|
25152
|
-
if (schemaStale && got !== null) return { row:
|
|
25153
|
-
return { row:
|
|
25531
|
+
if (integrityFailed) return { row: fail4(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale, integrityFailed, orphan: [] };
|
|
25532
|
+
if (schemaStale && got !== null) return { row: fail4(D8_STALE_SCHEMA_DETAIL(got, SCHEMA_VERSION), DOCTOR_FIX_UPGRADE), schemaStale, integrityFailed, orphan: [] };
|
|
25533
|
+
return { row: pass3("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
25154
25534
|
} catch (err) {
|
|
25155
|
-
if (isCorrupt2(err)) return { row:
|
|
25156
|
-
return { row:
|
|
25535
|
+
if (isCorrupt2(err)) return { row: fail4(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale: false, integrityFailed: true, orphan: [] };
|
|
25536
|
+
return { row: unknown3("D8", message2(err)), ...clean };
|
|
25157
25537
|
} finally {
|
|
25158
25538
|
raw?.close();
|
|
25159
25539
|
}
|
|
25160
25540
|
}
|
|
25161
25541
|
async function checkIndex(project) {
|
|
25162
|
-
if (!
|
|
25542
|
+
if (!existsSync12(project.dbPath)) return pass3("D9", D9_INDEX_DETAIL(0, 0));
|
|
25163
25543
|
const sqlite = await loadSqlite2();
|
|
25164
|
-
if (sqlite === null) return
|
|
25544
|
+
if (sqlite === null) return unknown3("D9", D2_SQLITE_DETAIL);
|
|
25165
25545
|
let raw = null;
|
|
25166
25546
|
try {
|
|
25167
25547
|
raw = openRead(sqlite, project.dbPath);
|
|
25168
25548
|
const sources = Number(cell(raw.prepare("SELECT count(*) FROM sources").get()));
|
|
25169
25549
|
const chunks = Number(cell(raw.prepare("SELECT count(*) FROM chunks").get()));
|
|
25170
|
-
return
|
|
25550
|
+
return pass3("D9", D9_INDEX_DETAIL(sources, chunks));
|
|
25171
25551
|
} catch (err) {
|
|
25172
|
-
return
|
|
25552
|
+
return unknown3("D9", message2(err));
|
|
25173
25553
|
} finally {
|
|
25174
25554
|
raw?.close();
|
|
25175
25555
|
}
|
|
25176
25556
|
}
|
|
25177
25557
|
|
|
25178
|
-
// src/core/ops/doctor-env.ts
|
|
25179
|
-
import { existsSync as existsSync11, readFileSync as readFileSync12, realpathSync as realpathSync6 } from "node:fs";
|
|
25180
|
-
import { isAbsolute as isAbsolute5, join as join15, relative as relative4 } from "node:path";
|
|
25181
|
-
function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
25182
|
-
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
25183
|
-
}
|
|
25184
|
-
function unknown3(id2, detail, fixCommand) {
|
|
25185
|
-
return fixCommand === void 0 ? { id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail } : { id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail, fixCommand };
|
|
25186
|
-
}
|
|
25187
|
-
function fail4(id2, detail, fixCommand) {
|
|
25188
|
-
return { id: id2, label: DOCTOR_LABEL[id2], status: "FAIL", detail, fixCommand };
|
|
25189
|
-
}
|
|
25190
|
-
function warn(id2, detail, fixCommand) {
|
|
25191
|
-
return { id: id2, label: DOCTOR_LABEL[id2], status: "WARN", detail, fixCommand };
|
|
25192
|
-
}
|
|
25193
|
-
function bundleVersion(bundleDir2) {
|
|
25194
|
-
try {
|
|
25195
|
-
const v = JSON.parse(readFileSync12(join15(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
25196
|
-
return typeof v === "string" && v !== "" ? v : void 0;
|
|
25197
|
-
} catch {
|
|
25198
|
-
return void 0;
|
|
25199
|
-
}
|
|
25200
|
-
}
|
|
25201
|
-
function channelOf(version2) {
|
|
25202
|
-
const at2 = version2.indexOf(D1_PRERELEASE_SEP);
|
|
25203
|
-
if (at2 < 0) return D1_DEFAULT_TAG;
|
|
25204
|
-
const pre = version2.slice(at2 + 1);
|
|
25205
|
-
const dot = pre.indexOf(".");
|
|
25206
|
-
const tag2 = dot < 0 ? pre : pre.slice(0, dot);
|
|
25207
|
-
return tag2 === "" ? D1_DEFAULT_TAG : tag2;
|
|
25208
|
-
}
|
|
25209
|
-
function firstLine3(b) {
|
|
25210
|
-
const text = b.toString("utf8").trim();
|
|
25211
|
-
const nl = text.indexOf("\n");
|
|
25212
|
-
return (nl < 0 ? text : text.slice(0, nl)).trim();
|
|
25213
|
-
}
|
|
25214
|
-
function gitCause(r, timeoutMs) {
|
|
25215
|
-
if (r.killed === "timeout") return D1_GIT_TIMEOUT(timeoutMs);
|
|
25216
|
-
if (r.killed === "cancel") return D1_GIT_CANCEL;
|
|
25217
|
-
if (r.exitCode === null) return D1_GIT_NO_START;
|
|
25218
|
-
return D1_GIT_EXIT(r.exitCode, firstLine3(r.stderr));
|
|
25219
|
-
}
|
|
25220
|
-
function fetchCause(err, timeoutMs) {
|
|
25221
|
-
const name = err instanceof Error ? err.name : "";
|
|
25222
|
-
if (name === "TimeoutError") return D1_NPM_TIMEOUT(timeoutMs);
|
|
25223
|
-
const cause = err instanceof Error && err.cause instanceof Error ? err.cause : err;
|
|
25224
|
-
const code = typeof cause === "object" && cause !== null && "code" in cause && typeof cause.code === "string" ? cause.code : "";
|
|
25225
|
-
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
25226
|
-
const parts = code !== "" && !msg.includes(code) ? [code, msg] : [msg];
|
|
25227
|
-
return D1_NPM_ERROR(parts.filter((part) => part !== "").join(" "));
|
|
25228
|
-
}
|
|
25229
|
-
async function npmLatest(url2, tag2, signal, timeoutMs) {
|
|
25230
|
-
try {
|
|
25231
|
-
const res = await fetch(url2, { signal: AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) });
|
|
25232
|
-
if (!res.ok) return { ok: false, cause: D1_NPM_HTTP(res.status) };
|
|
25233
|
-
const body = await res.json();
|
|
25234
|
-
const v = typeof body === "object" && body !== null ? body[tag2] : void 0;
|
|
25235
|
-
return typeof v === "string" && v !== "" ? { ok: true, version: v } : { ok: false, cause: D1_NPM_NO_TAG(tag2) };
|
|
25236
|
-
} catch (err) {
|
|
25237
|
-
return { ok: false, cause: fetchCause(err, timeoutMs) };
|
|
25238
|
-
}
|
|
25239
|
-
}
|
|
25240
|
-
function digits(s) {
|
|
25241
|
-
if (s === "") return false;
|
|
25242
|
-
for (const ch of s) if (ch < "0" || ch > "9") return false;
|
|
25243
|
-
return true;
|
|
25244
|
-
}
|
|
25245
|
-
function parseVersion(v) {
|
|
25246
|
-
const at2 = v.indexOf(D1_PRERELEASE_SEP);
|
|
25247
|
-
const core = (at2 < 0 ? v : v.slice(0, at2)).split(NODE_VERSION_SEP);
|
|
25248
|
-
if (core.length !== 3 || !core.every(digits)) return null;
|
|
25249
|
-
const nums = [Number(core[0]), Number(core[1]), Number(core[2])];
|
|
25250
|
-
if (at2 < 0) return { core: nums, pre: [] };
|
|
25251
|
-
const pre = v.slice(at2 + 1).split(NODE_VERSION_SEP);
|
|
25252
|
-
if (pre[0] === "" || digits(pre[0]) || pre.length > 2) return null;
|
|
25253
|
-
if (pre.length === 1) return { core: nums, pre: [pre[0]] };
|
|
25254
|
-
return digits(pre[1]) ? { core: nums, pre: [pre[0], Number(pre[1])] } : null;
|
|
25255
|
-
}
|
|
25256
|
-
function sign(n) {
|
|
25257
|
-
return n < 0 ? -1 : n > 0 ? 1 : 0;
|
|
25258
|
-
}
|
|
25259
|
-
function compareVersions(a, b) {
|
|
25260
|
-
const x = parseVersion(a);
|
|
25261
|
-
const y = parseVersion(b);
|
|
25262
|
-
if (x === null || y === null) return null;
|
|
25263
|
-
for (let k = 0; k < 3; k++) if (x.core[k] !== y.core[k]) return sign(x.core[k] - y.core[k]);
|
|
25264
|
-
if (x.pre.length === 0 || y.pre.length === 0) return sign(y.pre.length - x.pre.length);
|
|
25265
|
-
if (x.pre[0] !== y.pre[0]) return x.pre[0] < y.pre[0] ? -1 : 1;
|
|
25266
|
-
return sign((x.pre[1] ?? -1) - (y.pre[1] ?? -1));
|
|
25267
|
-
}
|
|
25268
|
-
function highestTag(stdout, tag2) {
|
|
25269
|
-
let best;
|
|
25270
|
-
for (const line of stdout.split("\n")) {
|
|
25271
|
-
const [sha, ref] = line.trim().split(LS_REMOTE_FIELD_SEP);
|
|
25272
|
-
if (sha === void 0 || sha.length !== GIT_SHA_HEX_LEN || ref === void 0 || !ref.startsWith(RELEASE_TAG_REF_PREFIX)) continue;
|
|
25273
|
-
const v = ref.slice(RELEASE_TAG_REF_PREFIX.length);
|
|
25274
|
-
if (parseVersion(v) === null || channelOf(v) !== tag2) continue;
|
|
25275
|
-
if (best === void 0 || compareVersions(v, best) === 1) best = v;
|
|
25276
|
-
}
|
|
25277
|
-
return best;
|
|
25278
|
-
}
|
|
25279
|
-
function versionRow(head2, installed, tag2, source, latest, tail, update) {
|
|
25280
|
-
const cmp = compareVersions(installed, latest) ?? (installed === latest ? 0 : -1);
|
|
25281
|
-
if (cmp === 0) return pass3("D1", head2 + D1_LATEST_PASS(tag2, source) + tail);
|
|
25282
|
-
if (cmp > 0) return pass3("D1", head2 + D1_LATEST_AHEAD(tag2, source, latest) + tail);
|
|
25283
|
-
return warn("D1", head2 + D1_LATEST_UPDATE(tag2, source, latest) + tail, update);
|
|
25284
|
-
}
|
|
25285
|
-
async function checkVersion(i) {
|
|
25286
|
-
if (i.bundleSha === void 0) return unknown3("D1", D1_DEV_BUILD_DETAIL);
|
|
25287
|
-
const head2 = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
25288
|
-
if (i.version === void 0) return unknown3("D1", head2 + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
|
|
25289
|
-
const tag2 = channelOf(i.version);
|
|
25290
|
-
const update = i.updateCommand ?? DOCTOR_FIX_UPGRADE;
|
|
25291
|
-
const git2 = findRuntime(GIT_BIN, i.env);
|
|
25292
|
-
const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
|
|
25293
|
-
if (npm.ok) return versionRow(head2, i.version, tag2, D1_SOURCE_NPM, npm.version, "", update);
|
|
25294
|
-
let cause = D1_GIT_MISSING;
|
|
25295
|
-
if (git2 !== null) {
|
|
25296
|
-
const r = await runProcess([git2, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
|
|
25297
|
-
cwd: i.cwd,
|
|
25298
|
-
env: { ...i.env, ...GIT_NO_PROMPT_ENV },
|
|
25299
|
-
signal: i.signal,
|
|
25300
|
-
timeoutMs: i.timeoutMs
|
|
25301
|
-
});
|
|
25302
|
-
if (r.exitCode === 0 && r.killed === null) {
|
|
25303
|
-
const latest = highestTag(r.stdout.toString("utf8"), tag2);
|
|
25304
|
-
if (latest !== void 0) return versionRow(head2, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause, update);
|
|
25305
|
-
cause = D1_GIT_NO_TAG(tag2);
|
|
25306
|
-
} else {
|
|
25307
|
-
cause = gitCause(r, i.timeoutMs);
|
|
25308
|
-
}
|
|
25309
|
-
}
|
|
25310
|
-
return unknown3("D1", head2 + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause, git2 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX);
|
|
25311
|
-
}
|
|
25312
|
-
function numbers(v) {
|
|
25313
|
-
const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
|
|
25314
|
-
return bare2.split(NODE_VERSION_SEP).map(Number);
|
|
25315
|
-
}
|
|
25316
|
-
function belowMin(version2) {
|
|
25317
|
-
const got = numbers(version2);
|
|
25318
|
-
const min = numbers(NODE_MIN);
|
|
25319
|
-
for (let k = 0; k < min.length; k++) {
|
|
25320
|
-
const g = got[k] ?? 0;
|
|
25321
|
-
if (g !== min[k]) return g < min[k];
|
|
25322
|
-
}
|
|
25323
|
-
return false;
|
|
25324
|
-
}
|
|
25325
|
-
async function sqliteLoads() {
|
|
25326
|
-
try {
|
|
25327
|
-
await import(SQLITE_MODULE);
|
|
25328
|
-
return true;
|
|
25329
|
-
} catch {
|
|
25330
|
-
return false;
|
|
25331
|
-
}
|
|
25332
|
-
}
|
|
25333
|
-
async function checkNode(i) {
|
|
25334
|
-
const bun = i.bunVersion === void 0 ? [] : [D2_BUN_DETAIL(i.bunVersion)];
|
|
25335
|
-
const withBun = (detail) => [detail, ...bun].join(D4_REASON_JOIN);
|
|
25336
|
-
if (belowMin(i.nodeVersion)) return fail4("D2", withBun(D2_NODE_DETAIL(i.nodeVersion)), D2_NODE_FIX);
|
|
25337
|
-
if (!await sqliteLoads()) return fail4("D2", withBun(D2_SQLITE_DETAIL), D2_SQLITE_FIX);
|
|
25338
|
-
return pass3("D2", bun.length === 0 ? DOCTOR_PASS_DETAIL : bun.join(D4_REASON_JOIN));
|
|
25339
|
-
}
|
|
25340
|
-
function checkMcp(ctx, adapter) {
|
|
25341
|
-
const named2 = ctx.clientInfo !== void 0 && ctx.clientInfo.name !== "";
|
|
25342
|
-
const versioned = ctx.protocolVersion !== void 0 && ctx.protocolVersion !== "";
|
|
25343
|
-
if (named2 || versioned) return pass3("D6");
|
|
25344
|
-
return adapter?.installMode === "in-process" ? pass3("D6", D6_IN_PROCESS_DETAIL) : unknown3("D6", D6_UNKNOWN_DETAIL);
|
|
25345
|
-
}
|
|
25346
|
-
function piCwdInside(worktree, piCwd) {
|
|
25347
|
-
if (piCwd === void 0 || !existsSync11(piCwd)) return false;
|
|
25348
|
-
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
25349
|
-
return rel === "" || !rel.startsWith("..") && !isAbsolute5(rel);
|
|
25350
|
-
}
|
|
25351
|
-
function checkProject(i) {
|
|
25352
|
-
const bad = fail4("D7", D7_DETAIL(i.project.source), D7_FIX);
|
|
25353
|
-
if (i.project.source !== i.adapter.projectSource) return bad;
|
|
25354
|
-
if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
|
|
25355
|
-
return pass3("D7");
|
|
25356
|
-
}
|
|
25357
|
-
function checkMode(adapter, hostPermission) {
|
|
25358
|
-
if (hostPermission === "missing") return fail4("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
|
|
25359
|
-
if (hostPermission === "wired") return pass3("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
|
|
25360
|
-
return pass3("D10", D10_DETAIL(adapter.denyChannel));
|
|
25361
|
-
}
|
|
25362
|
-
function checkShell(env) {
|
|
25363
|
-
const win = process.platform === "win32";
|
|
25364
|
-
const shell = findRuntime("shell", env);
|
|
25365
|
-
if (shell !== null) return pass3("D11", D11_PASS_DETAIL(shell, win));
|
|
25366
|
-
return win ? fail4("D11", D11_WIN_DETAIL, D11_WIN_FIX) : fail4("D11", D11_POSIX_DETAIL, D11_POSIX_FIX);
|
|
25367
|
-
}
|
|
25368
|
-
|
|
25369
25558
|
// src/core/ops/doctor-hook.ts
|
|
25370
|
-
import { existsSync as
|
|
25559
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync4, mkdtempSync, readFileSync as readFileSync14, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
25371
25560
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
25372
25561
|
import path7 from "node:path";
|
|
25373
25562
|
|
|
@@ -27111,7 +27300,9 @@ var HOST_SHAPES = {
|
|
|
27111
27300
|
kiro: kiro_default,
|
|
27112
27301
|
zcode: zcode_default,
|
|
27113
27302
|
pi: pi_default,
|
|
27114
|
-
opencode: opencode_default
|
|
27303
|
+
opencode: opencode_default,
|
|
27304
|
+
omp: pi_default
|
|
27305
|
+
// ADR-0026: OMP reads the Pi extension reply
|
|
27115
27306
|
};
|
|
27116
27307
|
var NOTE_KEYS = /* @__PURE__ */ new Set(["$schema", "title", "description", "definitions", "default"]);
|
|
27117
27308
|
var RULE_KEYS = /* @__PURE__ */ new Set(["type", "enum", "const", "required", "properties", "additionalProperties", "items", "allOf", "$ref"]);
|
|
@@ -27193,7 +27384,7 @@ function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.e
|
|
|
27193
27384
|
|
|
27194
27385
|
// src/setup/codex-trust.ts
|
|
27195
27386
|
import { createHash } from "node:crypto";
|
|
27196
|
-
import { existsSync as
|
|
27387
|
+
import { existsSync as existsSync13, realpathSync as realpathSync7 } from "node:fs";
|
|
27197
27388
|
import path6 from "node:path";
|
|
27198
27389
|
import { spawn as spawn3, spawnSync as spawnSync2 } from "node:child_process";
|
|
27199
27390
|
|
|
@@ -27416,10 +27607,10 @@ function isObject6(v) {
|
|
|
27416
27607
|
}
|
|
27417
27608
|
function loadFixture(bundleDir2, agent) {
|
|
27418
27609
|
const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
27419
|
-
if (!
|
|
27610
|
+
if (!existsSync14(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
27420
27611
|
let all;
|
|
27421
27612
|
try {
|
|
27422
|
-
all = JSON.parse(hostText(
|
|
27613
|
+
all = JSON.parse(hostText(readFileSync14(file2, "utf8")));
|
|
27423
27614
|
} catch (err) {
|
|
27424
27615
|
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
27425
27616
|
}
|
|
@@ -27441,7 +27632,8 @@ var CWD_KEY = {
|
|
|
27441
27632
|
kiro: "cwd",
|
|
27442
27633
|
zcode: "cwd",
|
|
27443
27634
|
pi: "cwd",
|
|
27444
|
-
opencode: "directory"
|
|
27635
|
+
opencode: "directory",
|
|
27636
|
+
omp: "cwd"
|
|
27445
27637
|
};
|
|
27446
27638
|
function payloadFor(agent, payload, worktree) {
|
|
27447
27639
|
return worktree !== void 0 && isObject6(payload) ? { ...payload, [CWD_KEY[agent]]: worktree } : payload;
|
|
@@ -27633,7 +27825,7 @@ async function codexStopDetail(i, timeoutMs) {
|
|
|
27633
27825
|
timeoutMs,
|
|
27634
27826
|
stdin: JSON.stringify(codexStopPayload(i.worktree ?? home))
|
|
27635
27827
|
});
|
|
27636
|
-
const logged =
|
|
27828
|
+
const logged = existsSync14(path7.join(home, HOOK_ERROR_LOG_FILE));
|
|
27637
27829
|
return !logged && isNativeShape(i.agent, r.stdout.toString("utf8"), r.exitCode, r.killed, "Stop") ? null : D5_STOP_DETAIL;
|
|
27638
27830
|
} finally {
|
|
27639
27831
|
rmSync2(home, { recursive: true, force: true });
|
|
@@ -27644,7 +27836,7 @@ async function checkHookRoundTrip(i) {
|
|
|
27644
27836
|
const trust = await codexPluginTrust(i);
|
|
27645
27837
|
if (trust !== null) return trust;
|
|
27646
27838
|
}
|
|
27647
|
-
if (i.agent === "codex" &&
|
|
27839
|
+
if (i.agent === "codex" && existsSync14(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
27648
27840
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
27649
27841
|
}
|
|
27650
27842
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
@@ -27693,14 +27885,14 @@ async function checkHookRoundTrip(i) {
|
|
|
27693
27885
|
}
|
|
27694
27886
|
|
|
27695
27887
|
// src/core/ops/db-heal.ts
|
|
27696
|
-
import { existsSync as
|
|
27697
|
-
import { basename as basename4, dirname as dirname9, join as
|
|
27888
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync6, rmSync as rmSync4 } from "node:fs";
|
|
27889
|
+
import { basename as basename4, dirname as dirname9, join as join18 } from "node:path";
|
|
27698
27890
|
|
|
27699
27891
|
// src/core/store/owners.ts
|
|
27700
|
-
import { mkdirSync as mkdirSync5, readdirSync as readdirSync7, readFileSync as
|
|
27701
|
-
import { basename as basename3, join as
|
|
27892
|
+
import { mkdirSync as mkdirSync5, readdirSync as readdirSync7, readFileSync as readFileSync15, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
27893
|
+
import { basename as basename3, join as join17 } from "node:path";
|
|
27702
27894
|
function ownersDir(configDir, projectKey) {
|
|
27703
|
-
return
|
|
27895
|
+
return join17(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
27704
27896
|
}
|
|
27705
27897
|
function errCode2(err) {
|
|
27706
27898
|
return err.code;
|
|
@@ -27728,10 +27920,10 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
27728
27920
|
const live = [];
|
|
27729
27921
|
for (const name of names) {
|
|
27730
27922
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
27731
|
-
const file2 =
|
|
27923
|
+
const file2 = join17(dir, name);
|
|
27732
27924
|
let text;
|
|
27733
27925
|
try {
|
|
27734
|
-
text =
|
|
27926
|
+
text = readFileSync15(file2, "utf8");
|
|
27735
27927
|
} catch (err) {
|
|
27736
27928
|
if (errCode2(err) === "ENOENT") continue;
|
|
27737
27929
|
throw err;
|
|
@@ -27777,7 +27969,7 @@ function renameAside(dbPath) {
|
|
|
27777
27969
|
const ts = String(Date.now());
|
|
27778
27970
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
27779
27971
|
const file2 = dbPath + suffix;
|
|
27780
|
-
if (
|
|
27972
|
+
if (existsSync15(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
27781
27973
|
}
|
|
27782
27974
|
return ts;
|
|
27783
27975
|
}
|
|
@@ -27800,7 +27992,7 @@ function utcStamp(now) {
|
|
|
27800
27992
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
27801
27993
|
}
|
|
27802
27994
|
function makeOrphanDir(projectDir) {
|
|
27803
|
-
const base =
|
|
27995
|
+
const base = join18(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
27804
27996
|
for (let n = 1; ; n += 1) {
|
|
27805
27997
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
27806
27998
|
try {
|
|
@@ -27817,7 +28009,7 @@ async function healOrphan(project, files, row5) {
|
|
|
27817
28009
|
try {
|
|
27818
28010
|
dir = makeOrphanDir(dirname9(project.dbPath));
|
|
27819
28011
|
for (const f of files) {
|
|
27820
|
-
const to =
|
|
28012
|
+
const to = join18(dir, basename4(f.path));
|
|
27821
28013
|
renameWithRetry(f.path, to);
|
|
27822
28014
|
moved.push({ path: to, bytes: f.bytes });
|
|
27823
28015
|
}
|
|
@@ -27915,8 +28107,8 @@ function unsupportedHostOf(sig) {
|
|
|
27915
28107
|
|
|
27916
28108
|
// src/core/ops/doctor-issue.ts
|
|
27917
28109
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
27918
|
-
import { closeSync as closeSync2, existsSync as
|
|
27919
|
-
import { delimiter, dirname as dirname10, join as
|
|
28110
|
+
import { closeSync as closeSync2, existsSync as existsSync16, fstatSync, mkdirSync as mkdirSync7, openSync as openSync2, readFileSync as readFileSync16, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync4 } from "node:fs";
|
|
28111
|
+
import { delimiter, dirname as dirname10, join as join19 } from "node:path";
|
|
27920
28112
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
27921
28113
|
function tildeOf(env) {
|
|
27922
28114
|
const home = homeDirOf(env);
|
|
@@ -27972,8 +28164,8 @@ function onPath(env, tool) {
|
|
|
27972
28164
|
const out = [];
|
|
27973
28165
|
for (const dir of (envValue(env, "PATH") ?? "").split(delimiter)) {
|
|
27974
28166
|
if (dir === "") continue;
|
|
27975
|
-
for (const n of names) if (
|
|
27976
|
-
out.push(
|
|
28167
|
+
for (const n of names) if (existsSync16(join19(dir, n))) {
|
|
28168
|
+
out.push(join19(dir, n));
|
|
27977
28169
|
break;
|
|
27978
28170
|
}
|
|
27979
28171
|
}
|
|
@@ -27981,7 +28173,7 @@ function onPath(env, tool) {
|
|
|
27981
28173
|
}
|
|
27982
28174
|
function hookLogTail(env) {
|
|
27983
28175
|
const file2 = hookLogPath(env);
|
|
27984
|
-
if (file2 === "" || !
|
|
28176
|
+
if (file2 === "" || !existsSync16(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
27985
28177
|
try {
|
|
27986
28178
|
const fd = openSync2(file2, "r");
|
|
27987
28179
|
try {
|
|
@@ -28001,7 +28193,7 @@ function hookLogTail(env) {
|
|
|
28001
28193
|
}
|
|
28002
28194
|
async function journalRows(ctx) {
|
|
28003
28195
|
const head2 = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
28004
|
-
if (!
|
|
28196
|
+
if (!existsSync16(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
28005
28197
|
try {
|
|
28006
28198
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
28007
28199
|
try {
|
|
@@ -28019,21 +28211,21 @@ function agentConfig(adapter, env, worktree) {
|
|
|
28019
28211
|
const home = homeDirOf(env);
|
|
28020
28212
|
const files = configPaths(adapter, env, worktree);
|
|
28021
28213
|
if (home !== null) {
|
|
28022
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
28023
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
28214
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join19(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
28215
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join19(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
28024
28216
|
}
|
|
28025
28217
|
const out = [];
|
|
28026
28218
|
const seen = /* @__PURE__ */ new Set();
|
|
28027
28219
|
for (const f of files) {
|
|
28028
28220
|
if (seen.has(f.path)) continue;
|
|
28029
28221
|
seen.add(f.path);
|
|
28030
|
-
if (!
|
|
28222
|
+
if (!existsSync16(f.path)) {
|
|
28031
28223
|
out.push(`${f.label}: ${f.path} (absent)`);
|
|
28032
28224
|
continue;
|
|
28033
28225
|
}
|
|
28034
28226
|
let text = "";
|
|
28035
28227
|
try {
|
|
28036
|
-
text =
|
|
28228
|
+
text = readFileSync16(f.path, "utf8");
|
|
28037
28229
|
} catch (err) {
|
|
28038
28230
|
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
28039
28231
|
continue;
|
|
@@ -28104,9 +28296,9 @@ async function buildIssueBody(i) {
|
|
|
28104
28296
|
async function writeIssueReport(i) {
|
|
28105
28297
|
const tilde = tildeOf(i.env);
|
|
28106
28298
|
const body = await buildIssueBody(i);
|
|
28107
|
-
const dir =
|
|
28299
|
+
const dir = join19(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
28108
28300
|
mkdirSync7(dir, { recursive: true });
|
|
28109
|
-
const file2 =
|
|
28301
|
+
const file2 = join19(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
28110
28302
|
writeFileSync4(file2, body);
|
|
28111
28303
|
const shown2 = tilde(file2);
|
|
28112
28304
|
const title = issueTitle(i.adapter.id, i.rows, i.unsupported);
|
|
@@ -28133,7 +28325,7 @@ async function guard(id2, run) {
|
|
|
28133
28325
|
}
|
|
28134
28326
|
}
|
|
28135
28327
|
async function codexDb(ctx, adapter) {
|
|
28136
|
-
if (adapter.id !== "codex" || !
|
|
28328
|
+
if (adapter.id !== "codex" || !existsSync17(ctx.project.dbPath)) return null;
|
|
28137
28329
|
try {
|
|
28138
28330
|
return await openDb(ctx.project, { readOnly: true });
|
|
28139
28331
|
} catch {
|
|
@@ -28169,11 +28361,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
28169
28361
|
}
|
|
28170
28362
|
}
|
|
28171
28363
|
function ownServerId(configDir, projectKey) {
|
|
28172
|
-
const dir =
|
|
28173
|
-
if (!
|
|
28364
|
+
const dir = join20(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
28365
|
+
if (!existsSync17(dir)) return "";
|
|
28174
28366
|
for (const name of readdirSync8(dir)) {
|
|
28175
28367
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
28176
|
-
if (
|
|
28368
|
+
if (readFileSync17(join20(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
28177
28369
|
}
|
|
28178
28370
|
return "";
|
|
28179
28371
|
}
|
|
@@ -28203,7 +28395,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
28203
28395
|
D9: () => checkIndex(project),
|
|
28204
28396
|
D10: () => checkMode(adapter, ctx.hostPermission),
|
|
28205
28397
|
// D-1331-OC-PERM-1
|
|
28206
|
-
D11: () => checkShell(env)
|
|
28398
|
+
D11: () => checkRuntimes(env, checkShell(env))
|
|
28207
28399
|
};
|
|
28208
28400
|
const rows = [];
|
|
28209
28401
|
for (const id2 of DOCTOR_CHECK_ORDER) rows.push(await guard(id2, checks[id2]));
|
|
@@ -28233,7 +28425,7 @@ async function doctorReply(ctx, host) {
|
|
|
28233
28425
|
const runtime = runtimeInfo(host.env, ctx.signal);
|
|
28234
28426
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
28235
28427
|
const failed = rows.some((r) => r.status === "FAIL");
|
|
28236
|
-
const command = adapter.id === "pi" ? failed ? NATIVE_INSTALL.pi[0] : PI_LIST_COMMAND : `context-mode ${failed ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
28428
|
+
const command = adapter.id === "pi" ? failed ? NATIVE_INSTALL.pi[0] : PI_LIST_COMMAND : adapter.id === "omp" ? ompCommand(rows, failed) : `context-mode ${failed ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
28237
28429
|
const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
|
|
28238
28430
|
const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir), await runtime);
|
|
28239
28431
|
const table3 = buildReport(input);
|
|
@@ -28247,7 +28439,8 @@ async function doctorReply(ctx, host) {
|
|
|
28247
28439
|
}
|
|
28248
28440
|
const look = rows.find((r) => r.status === "FAIL") ?? rows.find((r) => r.status !== "PASS");
|
|
28249
28441
|
const docs = look === void 0 ? [] : [DOCTOR_DOCS_LABEL + DOCTOR_DOCS_LINK(look.id)];
|
|
28250
|
-
const
|
|
28442
|
+
const info = adapter.id === "omp" ? ompInfoLines(host.env, ctx.clientInfo?.version) : [];
|
|
28443
|
+
const whole2 = [envLine2, table3, ...docs, ...info, ...notes].join("\n");
|
|
28251
28444
|
const bytes5 = Buffer.byteLength(whole2, "utf8");
|
|
28252
28445
|
if (bytes5 <= REPORT_CAP) return { text: whole2, isError: false, sandboxBytes: bytes5 };
|
|
28253
28446
|
const db = await openDb(ctx.project);
|
|
@@ -28256,9 +28449,14 @@ async function doctorReply(ctx, host) {
|
|
|
28256
28449
|
} finally {
|
|
28257
28450
|
closeDb(db);
|
|
28258
28451
|
}
|
|
28259
|
-
const text = [envLine2, buildReportHead(input), ...docs, ...notes].join("\n");
|
|
28452
|
+
const text = [envLine2, buildReportHead(input), ...docs, ...info, ...notes].join("\n");
|
|
28260
28453
|
return { text, isError: false, sandboxBytes: bytes5 };
|
|
28261
28454
|
}
|
|
28455
|
+
function ompCommand(rows, failed) {
|
|
28456
|
+
if (!failed) return OMP_LIST_COMMAND;
|
|
28457
|
+
const d3 = rows.find((r) => r.id === "D3" && r.status === "FAIL");
|
|
28458
|
+
return d3?.fixCommand ?? NATIVE_INSTALL.omp[0];
|
|
28459
|
+
}
|
|
28262
28460
|
async function handler2(_input, ctx) {
|
|
28263
28461
|
return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: ctx.piCwd });
|
|
28264
28462
|
}
|
|
@@ -28272,9 +28470,9 @@ var ctxDoctor = Object.freeze({
|
|
|
28272
28470
|
});
|
|
28273
28471
|
|
|
28274
28472
|
// src/core/tools/execute.ts
|
|
28275
|
-
import { existsSync as
|
|
28473
|
+
import { existsSync as existsSync18, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
28276
28474
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
28277
|
-
import { dirname as dirname12, join as
|
|
28475
|
+
import { dirname as dirname12, join as join21, parse as parse3, resolve as resolve11 } from "node:path";
|
|
28278
28476
|
|
|
28279
28477
|
// src/core/sandbox/win-build.ts
|
|
28280
28478
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -28357,7 +28555,7 @@ function schemaLine(issue2) {
|
|
|
28357
28555
|
}
|
|
28358
28556
|
function fileError(given, abs, root) {
|
|
28359
28557
|
let dir = abs;
|
|
28360
|
-
while (!
|
|
28558
|
+
while (!existsSync18(dir) && dirname12(dir) !== dir) dir = dirname12(dir);
|
|
28361
28559
|
if (isInside(root, dir)) return null;
|
|
28362
28560
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
28363
28561
|
}
|
|
@@ -28426,7 +28624,12 @@ async function handler3(raw, ctx) {
|
|
|
28426
28624
|
if (bad !== null) return fail5(bad);
|
|
28427
28625
|
extra.CTX_FILE = abs;
|
|
28428
28626
|
}
|
|
28429
|
-
|
|
28627
|
+
let runtime;
|
|
28628
|
+
try {
|
|
28629
|
+
runtime = findRuntime(input.language);
|
|
28630
|
+
} catch {
|
|
28631
|
+
runtime = null;
|
|
28632
|
+
}
|
|
28430
28633
|
if (runtime === null) return fail5(noRuntimeError(input.language).toLine());
|
|
28431
28634
|
const env = buildChildEnv(process.env, extra);
|
|
28432
28635
|
const timeoutMs = input.timeoutMs ?? EXEC_TIMEOUT_MS;
|
|
@@ -28438,8 +28641,8 @@ async function handler3(raw, ctx) {
|
|
|
28438
28641
|
if (takesDashC(input.language, runtime)) {
|
|
28439
28642
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
28440
28643
|
} else {
|
|
28441
|
-
tmpDir = mkdtempSync2(
|
|
28442
|
-
const file2 =
|
|
28644
|
+
tmpDir = mkdtempSync2(join21(tmpdir3(), TMP_PREFIX));
|
|
28645
|
+
const file2 = join21(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
28443
28646
|
writeFileSync5(file2, scriptText(input.language, input.code), "utf8");
|
|
28444
28647
|
argv = scriptArgv(input.language, runtime, file2);
|
|
28445
28648
|
}
|
|
@@ -28475,12 +28678,12 @@ var ctxExecute = {
|
|
|
28475
28678
|
};
|
|
28476
28679
|
|
|
28477
28680
|
// src/core/tools/index.ts
|
|
28478
|
-
import { existsSync as
|
|
28479
|
-
import { dirname as dirname13, extname as extname3, join as
|
|
28681
|
+
import { existsSync as existsSync19, readFileSync as readFileSync20, statSync as statSync8 } from "node:fs";
|
|
28682
|
+
import { dirname as dirname13, extname as extname3, join as join24, relative as relative5, resolve as resolve12 } from "node:path";
|
|
28480
28683
|
|
|
28481
28684
|
// src/core/index/walk.ts
|
|
28482
|
-
import { readdirSync as readdirSync9, readFileSync as
|
|
28483
|
-
import { join as
|
|
28685
|
+
import { readdirSync as readdirSync9, readFileSync as readFileSync18, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
|
|
28686
|
+
import { join as join22 } from "node:path";
|
|
28484
28687
|
var GITIGNORE = ".gitignore";
|
|
28485
28688
|
var GIT_DIR = ".git";
|
|
28486
28689
|
function walkDir(root, containmentRoot) {
|
|
@@ -28489,7 +28692,7 @@ function walkDir(root, containmentRoot) {
|
|
|
28489
28692
|
const found = [];
|
|
28490
28693
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
28491
28694
|
found.sort(compareFound);
|
|
28492
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
28695
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join22(...f.dir, f.name) }));
|
|
28493
28696
|
}
|
|
28494
28697
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
28495
28698
|
let entries;
|
|
@@ -28498,10 +28701,10 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
28498
28701
|
} catch {
|
|
28499
28702
|
return;
|
|
28500
28703
|
}
|
|
28501
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
28704
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join22(abs, GITIGNORE), rel)) : parent;
|
|
28502
28705
|
for (const e of entries) {
|
|
28503
28706
|
if (e.name === GIT_DIR) continue;
|
|
28504
|
-
const path8 =
|
|
28707
|
+
const path8 = join22(abs, e.name);
|
|
28505
28708
|
let isDir = e.isDirectory();
|
|
28506
28709
|
let isFile = e.isFile();
|
|
28507
28710
|
let target = path8;
|
|
@@ -28541,7 +28744,7 @@ function compareFound(a, b) {
|
|
|
28541
28744
|
function readRules(file2, base) {
|
|
28542
28745
|
let body;
|
|
28543
28746
|
try {
|
|
28544
|
-
body =
|
|
28747
|
+
body = readFileSync18(file2, "utf8");
|
|
28545
28748
|
} catch {
|
|
28546
28749
|
return [];
|
|
28547
28750
|
}
|
|
@@ -28624,10 +28827,12 @@ function globSeg(pat, name) {
|
|
|
28624
28827
|
}
|
|
28625
28828
|
|
|
28626
28829
|
// src/core/sandbox/fetch.ts
|
|
28830
|
+
import { readFileSync as readFileSync19 } from "node:fs";
|
|
28627
28831
|
import { lookup } from "node:dns/promises";
|
|
28628
28832
|
import http from "node:http";
|
|
28629
28833
|
import https from "node:https";
|
|
28630
28834
|
import { BlockList, isIP } from "node:net";
|
|
28835
|
+
import { join as join23 } from "node:path";
|
|
28631
28836
|
import { connect as tlsConnect } from "node:tls";
|
|
28632
28837
|
var PRIVATE_RANGES = [
|
|
28633
28838
|
["127.0.0.0", 8, "ipv4"],
|
|
@@ -28659,6 +28864,21 @@ for (const [net, prefix, type] of PRIVATE_RANGES) BLOCKED.addSubnet(net, prefix,
|
|
|
28659
28864
|
var STATUS_OK_FIRST = 200;
|
|
28660
28865
|
var STATUS_OK_END = 300;
|
|
28661
28866
|
var STATUS_REDIRECT = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
28867
|
+
var UA_HOME = "https://github.com/mksglu/context-mode";
|
|
28868
|
+
var UA_DEV_VERSION = "dev";
|
|
28869
|
+
var namedHeaders;
|
|
28870
|
+
function baseHeaders() {
|
|
28871
|
+
if (namedHeaders === void 0) {
|
|
28872
|
+
let version2 = UA_DEV_VERSION;
|
|
28873
|
+
try {
|
|
28874
|
+
const v = JSON.parse(readFileSync19(join23(ownBundleDir(), D1_PACKAGE_FILE), "utf8")).version;
|
|
28875
|
+
if (typeof v === "string" && v !== "") version2 = v;
|
|
28876
|
+
} catch {
|
|
28877
|
+
}
|
|
28878
|
+
namedHeaders = Object.freeze({ "user-agent": "context-mode/" + version2 + " (+" + UA_HOME + ")", accept: "*/*" });
|
|
28879
|
+
}
|
|
28880
|
+
return namedHeaders;
|
|
28881
|
+
}
|
|
28662
28882
|
function fail6(code) {
|
|
28663
28883
|
return new CtxError("FETCH_FAILED", { code });
|
|
28664
28884
|
}
|
|
@@ -28767,11 +28987,11 @@ function request(u, conn, proxy, signal) {
|
|
|
28767
28987
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
28768
28988
|
if (proxy === void 0) {
|
|
28769
28989
|
const mod = u.protocol === "https:" ? https : http;
|
|
28770
|
-
const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
28990
|
+
const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { ...baseHeaders(), host: u.host } });
|
|
28771
28991
|
req.on("response", resolve14).on("error", onErr).end();
|
|
28772
28992
|
return;
|
|
28773
28993
|
}
|
|
28774
|
-
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
28994
|
+
const proxyHeaders = proxy.auth === void 0 ? { ...baseHeaders() } : { ...baseHeaders(), "proxy-authorization": proxy.auth };
|
|
28775
28995
|
if (u.protocol === "http:") {
|
|
28776
28996
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
28777
28997
|
req.on("response", resolve14).on("error", onErr).end();
|
|
@@ -28791,7 +29011,7 @@ function request(u, conn, proxy, signal) {
|
|
|
28791
29011
|
port,
|
|
28792
29012
|
path: path8,
|
|
28793
29013
|
signal,
|
|
28794
|
-
headers: { host: u.host },
|
|
29014
|
+
headers: { ...baseHeaders(), host: u.host },
|
|
28795
29015
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
28796
29016
|
});
|
|
28797
29017
|
req.on("response", resolve14).on("error", onErr).end();
|
|
@@ -28833,7 +29053,7 @@ async function safeFetch(url2, signal) {
|
|
|
28833
29053
|
}
|
|
28834
29054
|
if (status < STATUS_OK_FIRST || status >= STATUS_OK_END) {
|
|
28835
29055
|
res.resume();
|
|
28836
|
-
throw fail6(status);
|
|
29056
|
+
throw fail6(status + " from " + bare(current.hostname));
|
|
28837
29057
|
}
|
|
28838
29058
|
const body = await readBody(res);
|
|
28839
29059
|
const shown2 = new URL(current.href);
|
|
@@ -32669,14 +32889,14 @@ function kindOfType(contentType) {
|
|
|
32669
32889
|
}
|
|
32670
32890
|
function readUtf8(absPath) {
|
|
32671
32891
|
try {
|
|
32672
|
-
return utf8.decode(
|
|
32892
|
+
return utf8.decode(readFileSync20(absPath));
|
|
32673
32893
|
} catch {
|
|
32674
32894
|
return void 0;
|
|
32675
32895
|
}
|
|
32676
32896
|
}
|
|
32677
32897
|
function missingOrOutside(given, abs, root) {
|
|
32678
32898
|
let dir = abs;
|
|
32679
|
-
while (!
|
|
32899
|
+
while (!existsSync19(dir) && dirname13(dir) !== dir) dir = dirname13(dir);
|
|
32680
32900
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
32681
32901
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
32682
32902
|
}
|
|
@@ -32687,7 +32907,7 @@ function pathItems(input, project) {
|
|
|
32687
32907
|
if (statSync8(abs).isDirectory()) {
|
|
32688
32908
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
32689
32909
|
sourceKind: "path",
|
|
32690
|
-
label: pathLabel(
|
|
32910
|
+
label: pathLabel(join24(base, f.relPath)),
|
|
32691
32911
|
kind: kindOfPath(f.relPath),
|
|
32692
32912
|
read: () => readUtf8(f.absPath)
|
|
32693
32913
|
}));
|
|
@@ -33227,8 +33447,8 @@ var ctxStats = Object.freeze({
|
|
|
33227
33447
|
});
|
|
33228
33448
|
|
|
33229
33449
|
// src/core/ops/host-write.ts
|
|
33230
|
-
import { copyFileSync, existsSync as
|
|
33231
|
-
import { dirname as dirname14, join as
|
|
33450
|
+
import { copyFileSync, existsSync as existsSync20, mkdirSync as mkdirSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
33451
|
+
import { dirname as dirname14, join as join25 } from "node:path";
|
|
33232
33452
|
function defaultWrite(file2, text) {
|
|
33233
33453
|
writeFileSync6(file2, text, "utf8");
|
|
33234
33454
|
}
|
|
@@ -33237,17 +33457,20 @@ function hostConfigPath(agent, home, env) {
|
|
|
33237
33457
|
if (own2 !== void 0) return ownMcpFileOf(agent, own2.file, env, home);
|
|
33238
33458
|
switch (agent) {
|
|
33239
33459
|
case "opencode":
|
|
33240
|
-
return
|
|
33460
|
+
return join25(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
33241
33461
|
// D-WIN-OPENCODE-DIR-1
|
|
33242
33462
|
case "pi":
|
|
33243
|
-
return
|
|
33463
|
+
return join25(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
33244
33464
|
case "gemini":
|
|
33245
|
-
return
|
|
33465
|
+
return join25(geminiDirOf(env, home), SETTINGS_FILE);
|
|
33246
33466
|
// D-R38-GEMINI-HOME-1
|
|
33247
33467
|
case "copilot-cli":
|
|
33248
33468
|
return null;
|
|
33469
|
+
case "omp":
|
|
33470
|
+
return null;
|
|
33471
|
+
// ADR-0026 decision 8 (D-OMP-UPGRADE-1): OMP loads the plugin from its own store; no MCP entry, nothing under ~/.pi
|
|
33249
33472
|
default:
|
|
33250
|
-
return
|
|
33473
|
+
return join25(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
33251
33474
|
}
|
|
33252
33475
|
}
|
|
33253
33476
|
function cell3(value) {
|
|
@@ -33259,7 +33482,7 @@ function toRow(file2, edit) {
|
|
|
33259
33482
|
function writeWithRollback(file2, text, write2, atomic) {
|
|
33260
33483
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
33261
33484
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
33262
|
-
const had =
|
|
33485
|
+
const had = existsSync20(file2);
|
|
33263
33486
|
mkdirSync8(dirname14(file2), { recursive: true });
|
|
33264
33487
|
if (had) copyFileSync(file2, trash);
|
|
33265
33488
|
try {
|
|
@@ -33289,7 +33512,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
33289
33512
|
if (requested === null) return [];
|
|
33290
33513
|
const current = readHostConfig(row5.id, requested);
|
|
33291
33514
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
33292
|
-
const exists =
|
|
33515
|
+
const exists = existsSync20(current.path);
|
|
33293
33516
|
if (exists && result.text === current.text) return [];
|
|
33294
33517
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
33295
33518
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -33297,15 +33520,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
33297
33520
|
}
|
|
33298
33521
|
|
|
33299
33522
|
// src/core/ops/uninstall.ts
|
|
33300
|
-
import { existsSync as
|
|
33301
|
-
import { join as
|
|
33523
|
+
import { existsSync as existsSync21, readdirSync as readdirSync10, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
|
|
33524
|
+
import { join as join26 } from "node:path";
|
|
33302
33525
|
function row2(area, before, after) {
|
|
33303
33526
|
return { area, before, after };
|
|
33304
33527
|
}
|
|
33305
33528
|
function stopServers(configDir, projectKey) {
|
|
33306
33529
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
33307
|
-
const dir =
|
|
33308
|
-
for (const serverId of stopped) writeFileSync7(
|
|
33530
|
+
const dir = join26(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
33531
|
+
for (const serverId of stopped) writeFileSync7(join26(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
33309
33532
|
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 };
|
|
33310
33533
|
}
|
|
33311
33534
|
function rootOrNull(adapter, env) {
|
|
@@ -33323,15 +33546,15 @@ function removeCache(adapter, env, configDir) {
|
|
|
33323
33546
|
const root = rootOrNull(adapter, env);
|
|
33324
33547
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
33325
33548
|
if (adapter.installMode === "marketplace") {
|
|
33326
|
-
const cache =
|
|
33549
|
+
const cache = join26(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
33327
33550
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
33328
33551
|
}
|
|
33329
33552
|
rmSync6(root, { recursive: true, force: true });
|
|
33330
33553
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
33331
33554
|
}
|
|
33332
33555
|
case "plugin": {
|
|
33333
|
-
const agentDir =
|
|
33334
|
-
if (!
|
|
33556
|
+
const agentDir = join26(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
33557
|
+
if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
33335
33558
|
rmSync6(agentDir, { recursive: true, force: true });
|
|
33336
33559
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
33337
33560
|
}
|
|
@@ -33376,7 +33599,7 @@ function ownEntries2(agent, env) {
|
|
|
33376
33599
|
}
|
|
33377
33600
|
if (agent === "opencode") {
|
|
33378
33601
|
return [{
|
|
33379
|
-
file:
|
|
33602
|
+
file: join26(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
33380
33603
|
// D-WIN-OPENCODE-DIR-1
|
|
33381
33604
|
key: OPENCODE_PLUGIN_KEY,
|
|
33382
33605
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -33387,13 +33610,22 @@ function ownEntries2(agent, env) {
|
|
|
33387
33610
|
if (agent === "pi") {
|
|
33388
33611
|
const agentDir = piAgentDirOf(env, home);
|
|
33389
33612
|
return [{
|
|
33390
|
-
file:
|
|
33613
|
+
file: join26(agentDir, SETTINGS_FILE),
|
|
33391
33614
|
key: PI_PACKAGES_KEY,
|
|
33392
33615
|
shown: PI_PACKAGES_KEY,
|
|
33393
33616
|
has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
|
|
33394
33617
|
drop: (v) => v.filter((x) => piSource2(x) !== PI_GIT_PACKAGE)
|
|
33395
33618
|
}];
|
|
33396
33619
|
}
|
|
33620
|
+
if (agent === "omp") {
|
|
33621
|
+
return [{
|
|
33622
|
+
file: ompImportFiles(home).mcp,
|
|
33623
|
+
key: OMP_DISABLED_SERVERS_KEY,
|
|
33624
|
+
shown: OMP_DISABLED_SERVERS_KEY,
|
|
33625
|
+
has: (v) => Array.isArray(v) && v.includes(SERVER_KEY),
|
|
33626
|
+
drop: (v) => v.filter((x) => x !== SERVER_KEY)
|
|
33627
|
+
}];
|
|
33628
|
+
}
|
|
33397
33629
|
return [];
|
|
33398
33630
|
}
|
|
33399
33631
|
function removeOwnEntries(agent, env) {
|
|
@@ -33409,12 +33641,12 @@ function removeOwnEntries(agent, env) {
|
|
|
33409
33641
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
33410
33642
|
}
|
|
33411
33643
|
function removeProjectData(configDir, projectKey) {
|
|
33412
|
-
const projects =
|
|
33413
|
-
const dir =
|
|
33414
|
-
if (!
|
|
33644
|
+
const projects = join26(configDir, PROJECTS_DIR_NAME);
|
|
33645
|
+
const dir = join26(projects, projectKey);
|
|
33646
|
+
if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
33415
33647
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
33416
33648
|
for (const name of readdirSync10(dir)) {
|
|
33417
|
-
if (name !== OWNERS_DIR_NAME) rmSync6(
|
|
33649
|
+
if (name !== OWNERS_DIR_NAME) rmSync6(join26(dir, name), { recursive: true, force: true });
|
|
33418
33650
|
}
|
|
33419
33651
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
33420
33652
|
}
|
|
@@ -33422,12 +33654,12 @@ function runUninstall(input) {
|
|
|
33422
33654
|
const configDir = resolveConfigDir(input.env);
|
|
33423
33655
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
33424
33656
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
33425
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
33657
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join26(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
33426
33658
|
return { rows, stopped: stop.stopped };
|
|
33427
33659
|
}
|
|
33428
33660
|
|
|
33429
33661
|
// src/core/ops/v1-remove.ts
|
|
33430
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
33662
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync21, rmSync as rmSync7 } from "node:fs";
|
|
33431
33663
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
33432
33664
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
33433
33665
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -33439,7 +33671,7 @@ function moveAside(target, undo) {
|
|
|
33439
33671
|
}
|
|
33440
33672
|
function keepAside(target, undo) {
|
|
33441
33673
|
let aside = target + UPGRADE_ASIDE_SUFFIX;
|
|
33442
|
-
for (let n = 2;
|
|
33674
|
+
for (let n = 2; existsSync22(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
|
|
33443
33675
|
renameWithRetry(target, aside);
|
|
33444
33676
|
undo.push({ trash: aside, target, keep: true });
|
|
33445
33677
|
return aside;
|
|
@@ -33478,8 +33710,8 @@ function locate(doc, path8) {
|
|
|
33478
33710
|
return null;
|
|
33479
33711
|
}
|
|
33480
33712
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
33481
|
-
const layout = hostLayout(
|
|
33482
|
-
const text = hostText(
|
|
33713
|
+
const layout = hostLayout(readFileSync21(file2, "utf8"));
|
|
33714
|
+
const text = hostText(readFileSync21(file2, "utf8"));
|
|
33483
33715
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
33484
33716
|
const hit = /* @__PURE__ */ new Set();
|
|
33485
33717
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -33516,20 +33748,20 @@ function removeV1(agent, findings, project) {
|
|
|
33516
33748
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
33517
33749
|
else if (f.path === "") {
|
|
33518
33750
|
if (project !== void 0 && reachedThroughLink(project, f.file)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
33519
|
-
else if (
|
|
33520
|
-
else if (
|
|
33751
|
+
else if (existsSync22(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
|
|
33752
|
+
else if (existsSync22(f.file)) {
|
|
33521
33753
|
moveAside(f.file, undo);
|
|
33522
33754
|
done.set(f, UPGRADE_REMOVED);
|
|
33523
33755
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
33524
33756
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
33525
33757
|
}
|
|
33526
33758
|
for (const [file2, list4] of entries) {
|
|
33527
|
-
if (!
|
|
33759
|
+
if (!existsSync22(file2)) {
|
|
33528
33760
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
33529
33761
|
continue;
|
|
33530
33762
|
}
|
|
33531
33763
|
if (file2.endsWith(TOML_EXT)) {
|
|
33532
|
-
const rawToml =
|
|
33764
|
+
const rawToml = readFileSync21(file2, "utf8");
|
|
33533
33765
|
const tomlLayout = hostLayout(rawToml);
|
|
33534
33766
|
let text = hostText(rawToml);
|
|
33535
33767
|
for (const f of list4) {
|
|
@@ -33557,7 +33789,7 @@ function removeV1(agent, findings, project) {
|
|
|
33557
33789
|
},
|
|
33558
33790
|
rollback() {
|
|
33559
33791
|
for (const u of undo.splice(0).reverse()) {
|
|
33560
|
-
if (!
|
|
33792
|
+
if (!existsSync22(u.trash)) continue;
|
|
33561
33793
|
rmSync7(u.target, { recursive: true, force: true });
|
|
33562
33794
|
renameWithRetry(u.trash, u.target);
|
|
33563
33795
|
}
|