context-mode 2.1.10 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +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 +98 -79
- package/SHA256SUMS +21 -20
- package/cli.mjs +438 -99
- package/copilot/plugin.json +2 -2
- package/fixtures/hook-roundtrip.json +13 -0
- package/gemini-extension.json +2 -2
- package/hook.mjs +97 -97
- package/omp/index.js +5 -0
- package/opencode/plugin.js +823 -438
- package/package.json +9 -2
- package/pi/index.js +888 -465
- package/qwen-extension.json +2 -2
- package/run.mjs +136 -47
- package/search.mjs +136 -47
- package/server.mjs +704 -419
- 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
|
@@ -203,6 +203,10 @@ var DB_TIMEOUT_MS = 5e3;
|
|
|
203
203
|
var DB_WAL_SUFFIX = "-wal";
|
|
204
204
|
var DB_SHM_SUFFIX = "-shm";
|
|
205
205
|
var DB_TMP_SUFFIX = ".tmp";
|
|
206
|
+
var DB_LINK_DENIED_CODES = ["EACCES", "EPERM", "ENOSYS", "ENOTSUP", "EOPNOTSUPP"];
|
|
207
|
+
var DB_PUBLISH_CLAIM_SUFFIX = ".publish";
|
|
208
|
+
var DB_CLAIM_BUSY_CODES = ["EEXIST", "EPERM"];
|
|
209
|
+
var DB_PUBLISH_POLL_MS = 5;
|
|
206
210
|
var SQLITE_PRIMARY_CODE_MASK = 255;
|
|
207
211
|
var SQLITE_CORRUPT_CODE = 11;
|
|
208
212
|
var SQLITE_NOTADB_CODE = 26;
|
|
@@ -364,6 +368,7 @@ var READ_MEDIA_BY_AGENT = Object.freeze({
|
|
|
364
368
|
qwen: READ_IMAGES_AND_PDF,
|
|
365
369
|
opencode: READ_IMAGES_AND_PDF,
|
|
366
370
|
pi: READ_IMAGES,
|
|
371
|
+
omp: READ_IMAGES,
|
|
367
372
|
vscode: READ_IMAGES,
|
|
368
373
|
zcode: READ_IMAGES,
|
|
369
374
|
"copilot-cli": [],
|
|
@@ -480,7 +485,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
480
485
|
var DECISION_OPTION_KEY = "option";
|
|
481
486
|
var DECISION_LABEL_JOIN = " | ";
|
|
482
487
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
483
|
-
var BUNDLE_SHA = true ? "
|
|
488
|
+
var BUNDLE_SHA = true ? "1fce537096e8e2b7d1924c2b5ff2b83287f157ee" : void 0;
|
|
484
489
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
485
490
|
var DOCTOR_LABEL = Object.freeze({
|
|
486
491
|
D1: "version",
|
|
@@ -632,7 +637,9 @@ var AGENT_HOME_DIR = Object.freeze({
|
|
|
632
637
|
kiro: [".kiro"],
|
|
633
638
|
zcode: [".zcode"],
|
|
634
639
|
pi: [".pi"],
|
|
635
|
-
opencode: [".config", "opencode"]
|
|
640
|
+
opencode: [".config", "opencode"],
|
|
641
|
+
omp: [".omp"]
|
|
642
|
+
// ADR-0026: OMP data and plugins live under ~/.omp
|
|
636
643
|
});
|
|
637
644
|
var UPGRADE_RESTART_LINE = "restart needed";
|
|
638
645
|
var UPGRADE_HOST_AREA = "host update";
|
|
@@ -720,16 +727,6 @@ var UNSUPPORTED_HOSTS = Object.freeze([
|
|
|
720
727
|
binaries: [],
|
|
721
728
|
source: "v1.0.169:src/adapters/client-map.ts:18; detect.ts:163-165,584"
|
|
722
729
|
}),
|
|
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
730
|
unsupported({
|
|
734
731
|
id: "openclaw",
|
|
735
732
|
name: "OpenClaw",
|
|
@@ -796,7 +793,9 @@ var HOOK_HOST_FILE = Object.freeze({
|
|
|
796
793
|
kiro: { root: "home", file: [".kiro", "hooks", "context-mode.json"], key: ["hooks"], shape: "kiro", timeoutKey: "timeout", matcher: false },
|
|
797
794
|
zcode: { root: "home", file: [".zcode", "cli", "config.json"], key: ["hooks", "events"], shape: "zcode", timeoutKey: "timeoutMs", matcher: true },
|
|
798
795
|
pi: null,
|
|
799
|
-
opencode: null
|
|
796
|
+
opencode: null,
|
|
797
|
+
omp: null
|
|
798
|
+
// ADR-0026: in-process, no hook file
|
|
800
799
|
});
|
|
801
800
|
var TOOL_HOOK_EVENTS = Object.freeze(["PreToolUse", "PostToolUse"]);
|
|
802
801
|
var HOOK_MATCHER_FIELD = "matcher";
|
|
@@ -852,6 +851,12 @@ var D11_POSIX_FIX = "install sh or add it to PATH";
|
|
|
852
851
|
function D11_PASS_DETAIL(shell, win) {
|
|
853
852
|
return `${win ? "Git Bash" : "sh"}: ${shell}`;
|
|
854
853
|
}
|
|
854
|
+
function D11_RUNTIME_DETAIL(lang, unreadable) {
|
|
855
|
+
return `${lang} not found, unreadable on PATH: ${unreadable.join(", ")}`;
|
|
856
|
+
}
|
|
857
|
+
function D11_RUNTIME_FIX(lang) {
|
|
858
|
+
return `install ${lang}, or turn off its app alias and PATH entry that cannot be read`;
|
|
859
|
+
}
|
|
855
860
|
var DB_SIBLING_SUFFIXES = Object.freeze(["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]);
|
|
856
861
|
var HEAL_TMP_SUFFIX = ".heal";
|
|
857
862
|
var HEAL_TS_SEP = ".";
|
|
@@ -863,6 +868,8 @@ var UPGRADE_HOST_COMMAND = Object.freeze({
|
|
|
863
868
|
gemini: "gemini extensions update context-mode",
|
|
864
869
|
qwen: "qwen extensions update context-mode",
|
|
865
870
|
pi: "pi update --extensions",
|
|
871
|
+
omp: "omp plugin upgrade context-mode",
|
|
872
|
+
// ADR-0026 decision 4: OMP native update
|
|
866
873
|
opencode: "opencode plugin update",
|
|
867
874
|
"copilot-cli": "npm i -g context-mode && context-mode setup --agents copilot-cli",
|
|
868
875
|
vscode: "npm i -g context-mode && context-mode setup --agents vscode",
|
|
@@ -906,6 +913,14 @@ var PI_NPM_DIR = "npm";
|
|
|
906
913
|
var PI_NODE_MODULES_DIR = "node_modules";
|
|
907
914
|
var PI_PACKAGE_JSON_FILE = "package.json";
|
|
908
915
|
var PI_LIST_COMMAND = "pi list";
|
|
916
|
+
var OMP_LIST_COMMAND = "omp plugin list";
|
|
917
|
+
var OMP_ENABLE_COMMAND = "omp plugin enable context-mode";
|
|
918
|
+
var OMP_MIN_VERSION = "14.7.0";
|
|
919
|
+
var OMP_FLOOR_INFO = (v) => `OMP ${v} is older than the tested floor ${OMP_MIN_VERSION}. Update it with: omp update`;
|
|
920
|
+
var OMP_CONTENT_INFO = "OMP keeps tool output in content; context-mode writes its notes there.";
|
|
921
|
+
var OMP_PRINT_MODE_INFO = "Print mode sends no prompt event. Use omp or omp --mode rpc to keep prompts.";
|
|
922
|
+
var OMP_SCRIPTS_INFO = "Add < /dev/null in scripts.";
|
|
923
|
+
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
924
|
var PI_CURRENT_MAJOR = 2;
|
|
910
925
|
var V1_OPENCODE_PLUGIN_SPEC = "context-mode";
|
|
911
926
|
var V1_TMP_PREFIX = "context-mode-";
|
|
@@ -1115,6 +1130,8 @@ var NATIVE_INSTALL = Object.freeze({
|
|
|
1115
1130
|
qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode"],
|
|
1116
1131
|
opencode: ["opencode plugin add context-mode"],
|
|
1117
1132
|
pi: ["pi install npm:context-mode"],
|
|
1133
|
+
omp: ["omp plugin install context-mode"],
|
|
1134
|
+
// ADR-0026 decision 4: OMP native install
|
|
1118
1135
|
"copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
|
|
1119
1136
|
vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
|
|
1120
1137
|
kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
|
|
@@ -1264,7 +1281,7 @@ var CtxError = class extends Error {
|
|
|
1264
1281
|
import { dirname as dirname4, join as join8, relative as relative3, resolve as resolve8, sep as sep3 } from "node:path";
|
|
1265
1282
|
|
|
1266
1283
|
// src/core/contracts/agents.ts
|
|
1267
|
-
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
1284
|
+
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode", "omp"];
|
|
1268
1285
|
|
|
1269
1286
|
// src/adapters/claude-code.ts
|
|
1270
1287
|
var TOOL_NAME_PREFIX2 = "mcp__plugin_context-mode_context-mode__";
|
|
@@ -1986,6 +2003,9 @@ function readResult7(p) {
|
|
|
1986
2003
|
if (p.keep === true) info.keep = true;
|
|
1987
2004
|
return info;
|
|
1988
2005
|
}
|
|
2006
|
+
function decodeOmp(raw) {
|
|
2007
|
+
return { ...decode10(raw), agent: "omp" };
|
|
2008
|
+
}
|
|
1989
2009
|
function decode10(raw) {
|
|
1990
2010
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("pi: hook payload is not an object");
|
|
1991
2011
|
const p = raw;
|
|
@@ -2223,14 +2243,36 @@ var ADAPTERS = Object.freeze([
|
|
|
2223
2243
|
decode,
|
|
2224
2244
|
encode,
|
|
2225
2245
|
toCanonicalTool
|
|
2246
|
+
},
|
|
2247
|
+
{
|
|
2248
|
+
// ADR-0026 (D-OMP-ROW-1): OMP runs the Pi extension API in-process, so the row reuses the Pi decode, encode and
|
|
2249
|
+
// permission check; tool names stay bare. Only the entry path and the skills folder are its own.
|
|
2250
|
+
id: "omp",
|
|
2251
|
+
installMode: "in-process",
|
|
2252
|
+
projectSource: "pi:ctx.cwd",
|
|
2253
|
+
toolNamePrefix: TOOL_NAME_PREFIX10,
|
|
2254
|
+
nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
|
|
2255
|
+
execReadOnlyHint: false,
|
|
2256
|
+
eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
|
|
2257
|
+
compactDelivery: "pi-flag",
|
|
2258
|
+
compactSummary: "none",
|
|
2259
|
+
hookTimeoutMs: IN_PROCESS_TIMEOUT_MS,
|
|
2260
|
+
denyChannel: "deny-reason",
|
|
2261
|
+
hookChannel: { kind: "in-process", path: "omp/index.js" },
|
|
2262
|
+
skillChannel: { kind: "package", path: "skills" },
|
|
2263
|
+
// D-OMP-SKILLS-1
|
|
2264
|
+
decode: decodeOmp,
|
|
2265
|
+
encode: encode10,
|
|
2266
|
+
checkPermission
|
|
2267
|
+
// D-OMP-FIRE-1: agent omp in rows
|
|
2226
2268
|
}
|
|
2227
2269
|
]);
|
|
2228
2270
|
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"]);
|
|
2271
|
+
var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi", "opencode", "omp"]);
|
|
2230
2272
|
function hasReplace(row5) {
|
|
2231
2273
|
return REPLACE_ROWS.has(row5.id);
|
|
2232
2274
|
}
|
|
2233
|
-
var DUMP_REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "copilot-cli", "pi"]);
|
|
2275
|
+
var DUMP_REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "copilot-cli", "pi", "omp"]);
|
|
2234
2276
|
function dumpRunsThenReplaces(row5) {
|
|
2235
2277
|
return DUMP_REPLACE_ROWS.has(row5.id) && hasReplace(row5);
|
|
2236
2278
|
}
|
|
@@ -3702,8 +3744,12 @@ var CC_READ_ONLY_DENY = Object.freeze(["Agent", "Artifact", "ArtifactComments",
|
|
|
3702
3744
|
var CLAUDE_CODE_BUILT_INS = Object.freeze({
|
|
3703
3745
|
"general-purpose": { tools: null, disallowed: [] },
|
|
3704
3746
|
fork: { tools: null, disallowed: [] },
|
|
3747
|
+
claude: { tools: null, disallowed: [] },
|
|
3705
3748
|
Explore: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
|
|
3706
|
-
Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] }
|
|
3749
|
+
Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
|
|
3750
|
+
"claude-code-guide": { tools: ["Glob", "Grep", "Read", "WebFetch", "WebSearch"], disallowed: [] },
|
|
3751
|
+
"statusline-setup": { tools: ["Read", "Edit"], disallowed: [] },
|
|
3752
|
+
"web-fetch": { tools: ["WebFetch"], disallowed: [] }
|
|
3707
3753
|
});
|
|
3708
3754
|
var BUILT_IN_AGENT = "claude-code";
|
|
3709
3755
|
function isSubagentCall(ev) {
|
|
@@ -3724,7 +3770,8 @@ function toolSetForAgentType(ev, src) {
|
|
|
3724
3770
|
const type = ev.agentType ?? "";
|
|
3725
3771
|
const def = findDef(type, src) ?? builtIn(ev.agent, type);
|
|
3726
3772
|
if (def === null) return null;
|
|
3727
|
-
const
|
|
3773
|
+
const known = allKnownToolNames(row5);
|
|
3774
|
+
const tools = def.tools === null ? known : def.tools.map((n) => norm(row5, n)).flatMap((n) => [n, ...known.filter((k) => grants(n, k))]);
|
|
3728
3775
|
const deny2 = def.disallowed.map((n) => norm(row5, n));
|
|
3729
3776
|
return unique(tools.filter((n) => !deny2.some((d) => denies(d, n))));
|
|
3730
3777
|
}
|
|
@@ -3880,6 +3927,13 @@ function geminiValid(s) {
|
|
|
3880
3927
|
}
|
|
3881
3928
|
return out;
|
|
3882
3929
|
}
|
|
3930
|
+
function grants(entry, name) {
|
|
3931
|
+
if (!entry.startsWith(MCP_SERVER_TOOL_PREFIX)) return false;
|
|
3932
|
+
const wild = MCP_NAME_JOIN + "*";
|
|
3933
|
+
const server2 = entry.slice(MCP_SERVER_TOOL_PREFIX.length, entry.endsWith(wild) ? -wild.length : entry.length);
|
|
3934
|
+
if (server2 === "" || server2.indexOf("*") >= 0 || server2.indexOf(MCP_NAME_JOIN) >= 0) return false;
|
|
3935
|
+
return name.startsWith(MCP_SERVER_TOOL_PREFIX + server2 + MCP_NAME_JOIN);
|
|
3936
|
+
}
|
|
3883
3937
|
function denies(rule, name) {
|
|
3884
3938
|
if (rule.endsWith("*")) return name.startsWith(rule.slice(0, -1));
|
|
3885
3939
|
if (rule === name) return true;
|
|
@@ -3896,13 +3950,15 @@ function unique(names) {
|
|
|
3896
3950
|
// src/core/policy/unwrap.ts
|
|
3897
3951
|
var NONE = "";
|
|
3898
3952
|
var WRAPPERS = Object.freeze({
|
|
3899
|
-
sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE },
|
|
3900
|
-
env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE },
|
|
3901
|
-
time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE },
|
|
3902
|
-
nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE },
|
|
3903
|
-
timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE },
|
|
3904
|
-
command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV" },
|
|
3905
|
-
xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE }
|
|
3953
|
+
sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3954
|
+
env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3955
|
+
time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3956
|
+
nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3957
|
+
timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE, subcommands: [] },
|
|
3958
|
+
command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV", subcommands: [] },
|
|
3959
|
+
xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3960
|
+
// #1388: rtk (rtk-ai/rtk) runs the inner command as-is under `proxy` / `bypass`; its other subcommands are rtk's own.
|
|
3961
|
+
rtk: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: NONE, subcommands: ["proxy", "bypass"] }
|
|
3906
3962
|
});
|
|
3907
3963
|
var SHELLS = ["bash", "sh", "zsh"];
|
|
3908
3964
|
var SCRIPT_FLAG = "c";
|
|
@@ -3925,6 +3981,10 @@ function isDuration(s) {
|
|
|
3925
3981
|
}
|
|
3926
3982
|
function peel(w, args) {
|
|
3927
3983
|
let k = 0;
|
|
3984
|
+
if (w.subcommands.length > 0) {
|
|
3985
|
+
if (args.length === 0 || !w.subcommands.includes(args[0])) return null;
|
|
3986
|
+
k = 1;
|
|
3987
|
+
}
|
|
3928
3988
|
while (k < args.length) {
|
|
3929
3989
|
const a = args[k];
|
|
3930
3990
|
if (a === LONG_OPT2) {
|
|
@@ -4810,6 +4870,7 @@ function sourceOf(agent) {
|
|
|
4810
4870
|
case "opencode":
|
|
4811
4871
|
return "spawn-cwd";
|
|
4812
4872
|
case "pi":
|
|
4873
|
+
case "omp":
|
|
4813
4874
|
return "pi:ctx.cwd";
|
|
4814
4875
|
}
|
|
4815
4876
|
}
|
|
@@ -5059,7 +5120,7 @@ function openReadOnlyHandle(sqlite, path8, opts = {}) {
|
|
|
5059
5120
|
}
|
|
5060
5121
|
|
|
5061
5122
|
// src/core/store/db.ts
|
|
5062
|
-
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
5123
|
+
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, renameSync, rmSync, statSync: statSync3 } = process.getBuiltinModule("node:fs");
|
|
5063
5124
|
function versionParts(v) {
|
|
5064
5125
|
const bare2 = v.startsWith("v") ? v.slice(1) : v;
|
|
5065
5126
|
return bare2.split(".").map((p) => Number.parseInt(p, 10));
|
|
@@ -5091,6 +5152,34 @@ function readUserVersion(raw) {
|
|
|
5091
5152
|
const row5 = raw.prepare("PRAGMA user_version").get();
|
|
5092
5153
|
return row5.user_version;
|
|
5093
5154
|
}
|
|
5155
|
+
function errCode(err) {
|
|
5156
|
+
return err.code ?? "";
|
|
5157
|
+
}
|
|
5158
|
+
function publishWithoutLink(tmp, path8) {
|
|
5159
|
+
const claim = path8 + DB_PUBLISH_CLAIM_SUFFIX;
|
|
5160
|
+
const start = Date.now();
|
|
5161
|
+
for (; ; ) {
|
|
5162
|
+
if (existsSync3(path8)) return;
|
|
5163
|
+
try {
|
|
5164
|
+
mkdirSync2(claim);
|
|
5165
|
+
} catch (err) {
|
|
5166
|
+
if (!DB_CLAIM_BUSY_CODES.includes(errCode(err))) throw err;
|
|
5167
|
+
if (Date.now() - start < DB_TIMEOUT_MS) {
|
|
5168
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, DB_PUBLISH_POLL_MS);
|
|
5169
|
+
continue;
|
|
5170
|
+
}
|
|
5171
|
+
const held = statSync3(claim, { throwIfNoEntry: false });
|
|
5172
|
+
if (held !== void 0 && held.mtimeMs < start) rmSync(claim, { recursive: true, force: true });
|
|
5173
|
+
throw new Error(`context.db was not published within ${DB_TIMEOUT_MS} ms: ${claim} was held; open again`);
|
|
5174
|
+
}
|
|
5175
|
+
try {
|
|
5176
|
+
if (!existsSync3(path8)) renameSync(tmp, path8);
|
|
5177
|
+
} finally {
|
|
5178
|
+
rmSync(claim, { recursive: true, force: true });
|
|
5179
|
+
}
|
|
5180
|
+
return;
|
|
5181
|
+
}
|
|
5182
|
+
}
|
|
5094
5183
|
function createAtomically(sqlite, path8) {
|
|
5095
5184
|
const { randomUUID } = process.getBuiltinModule("node:crypto");
|
|
5096
5185
|
const tmp = path8 + "." + randomUUID() + DB_TMP_SUFFIX;
|
|
@@ -5104,7 +5193,9 @@ function createAtomically(sqlite, path8) {
|
|
|
5104
5193
|
try {
|
|
5105
5194
|
linkSync(tmp, path8);
|
|
5106
5195
|
} catch (err) {
|
|
5107
|
-
|
|
5196
|
+
const code = errCode(err);
|
|
5197
|
+
if (DB_LINK_DENIED_CODES.includes(code)) publishWithoutLink(tmp, path8);
|
|
5198
|
+
else if (code !== "EEXIST") throw err;
|
|
5108
5199
|
}
|
|
5109
5200
|
} finally {
|
|
5110
5201
|
for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
|
|
@@ -5295,9 +5386,15 @@ function readLastPrompt(db, sessionId) {
|
|
|
5295
5386
|
const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq DESC LIMIT 1").get(sessionId);
|
|
5296
5387
|
return row5 === void 0 ? "" : row5.body;
|
|
5297
5388
|
}
|
|
5298
|
-
function readRecallRows(db, sessionId, worktree, limit) {
|
|
5389
|
+
function readRecallRows(db, sessionId, worktree, limit, maxSeq = Number.MAX_SAFE_INTEGER) {
|
|
5299
5390
|
if (sessionId === "") return [];
|
|
5300
|
-
return db.raw.prepare(
|
|
5391
|
+
return db.raw.prepare(
|
|
5392
|
+
"SELECT * FROM events WHERE kind <> 'cost' AND ((session_id = ? AND seq <= ?) OR (worktree = ? AND session_id <> ?)) ORDER BY seq DESC LIMIT ?"
|
|
5393
|
+
).all(sessionId, maxSeq, worktree, sessionId, limit);
|
|
5394
|
+
}
|
|
5395
|
+
function readMaxSeq(db) {
|
|
5396
|
+
const row5 = db.raw.prepare("SELECT COALESCE(MAX(seq), 0) AS n FROM events").get();
|
|
5397
|
+
return Number(row5.n);
|
|
5301
5398
|
}
|
|
5302
5399
|
function hasAgentRows(db, worktree, agent) {
|
|
5303
5400
|
return db.raw.prepare("SELECT 1 FROM events WHERE worktree = ? AND agent = ? LIMIT 1").get(worktree, agent) !== void 0;
|
|
@@ -5305,6 +5402,10 @@ function hasAgentRows(db, worktree, agent) {
|
|
|
5305
5402
|
function hasSessionRows(db, sessionId) {
|
|
5306
5403
|
return db.raw.prepare("SELECT 1 FROM events WHERE session_id = ? LIMIT 1").get(sessionId) !== void 0;
|
|
5307
5404
|
}
|
|
5405
|
+
function lastSessionSeq(db, sessionId) {
|
|
5406
|
+
const row5 = db.raw.prepare("SELECT MAX(seq) AS m FROM events WHERE session_id = ?").get(sessionId);
|
|
5407
|
+
return row5?.m ?? 0;
|
|
5408
|
+
}
|
|
5308
5409
|
|
|
5309
5410
|
// src/core/store/snippet.ts
|
|
5310
5411
|
var K1 = 1.2;
|
|
@@ -7882,12 +7983,16 @@ function recallQueryText(prompt) {
|
|
|
7882
7983
|
if (cur !== "" && kept.size < RECALL_QUERY_MAX_TERMS) add(cur);
|
|
7883
7984
|
return [...kept.size > 0 ? kept : all].join(" ");
|
|
7884
7985
|
}
|
|
7885
|
-
function
|
|
7986
|
+
function readMaxSourceId(db) {
|
|
7987
|
+
const row5 = db.raw.prepare("SELECT COALESCE(MAX(id), 0) AS n FROM sources").get();
|
|
7988
|
+
return Number(row5.n);
|
|
7989
|
+
}
|
|
7990
|
+
function queryUnits(db, sessionId, q, limit, maxSourceId = Number.MAX_SAFE_INTEGER) {
|
|
7886
7991
|
const match = searchTerms(q).join(" OR ");
|
|
7887
7992
|
if (match === "" || sessionId === "") return [];
|
|
7888
7993
|
const rows = db.raw.prepare(
|
|
7889
|
-
"SELECT u.source_id AS source_id, u.ord AS ord, u.body AS body, -bm25(line_units) AS score, s.label AS label FROM line_units u JOIN sources s ON s.id = u.source_id WHERE line_units MATCH ? AND u.session_id = ? ORDER BY bm25(line_units) LIMIT ?"
|
|
7890
|
-
).all(match, sessionId, limit);
|
|
7994
|
+
"SELECT u.source_id AS source_id, u.ord AS ord, u.body AS body, -bm25(line_units) AS score, s.label AS label FROM line_units u JOIN sources s ON s.id = u.source_id WHERE line_units MATCH ? AND u.session_id = ? AND s.id <= ? ORDER BY bm25(line_units) LIMIT ?"
|
|
7995
|
+
).all(match, sessionId, maxSourceId, limit);
|
|
7891
7996
|
return rows.map((r) => ({ sourceId: Number(r.source_id), ord: Number(r.ord), label: r.label, body: r.body, score: r.score }));
|
|
7892
7997
|
}
|
|
7893
7998
|
|
|
@@ -8469,7 +8574,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
8469
8574
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
8470
8575
|
return { end: start + r.read, written: r.written };
|
|
8471
8576
|
}
|
|
8472
|
-
function merge(src, blocks,
|
|
8577
|
+
function merge(src, blocks, join27, cap, lineCut) {
|
|
8473
8578
|
const out = [];
|
|
8474
8579
|
const scratch = new Uint8Array(cap);
|
|
8475
8580
|
let wide;
|
|
@@ -8479,7 +8584,7 @@ function merge(src, blocks, join25, cap, lineCut) {
|
|
|
8479
8584
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
8480
8585
|
};
|
|
8481
8586
|
for (const b of blocks) {
|
|
8482
|
-
if (cur !== void 0 && !
|
|
8587
|
+
if (cur !== void 0 && !join27) {
|
|
8483
8588
|
emit(cur.start, cur.end, curBytes);
|
|
8484
8589
|
cur = void 0;
|
|
8485
8590
|
}
|
|
@@ -9121,7 +9226,7 @@ async function handleHook(agent, raw, env) {
|
|
|
9121
9226
|
try {
|
|
9122
9227
|
fault(env, "project");
|
|
9123
9228
|
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 });
|
|
9229
|
+
project = resolveProject(agent, { env, argv, cwd: ev.cwd, piCwd: getAdapter(agent).projectSource === "pi:ctx.cwd" ? ev.cwd : void 0 });
|
|
9125
9230
|
} catch (err) {
|
|
9126
9231
|
return fail7("project", err, "hooks: no project: " + String(err.code ?? "ERROR") + " " + message(err) + "\n");
|
|
9127
9232
|
}
|
|
@@ -9171,8 +9276,9 @@ async function sessionStart(ev, row5, project) {
|
|
|
9171
9276
|
if (ev.source === "compact" && hasRecall(row5)) markCompacted(await openDb(project), ev.sessionId);
|
|
9172
9277
|
if (ev.source === "compact" && row5.compactDelivery === "sessionstart") {
|
|
9173
9278
|
const db2 = await openDb(project);
|
|
9174
|
-
|
|
9175
|
-
|
|
9279
|
+
const onceKey = COMPACT_STATE_KEY + ":" + lastSessionSeq(db2, ev.sessionId);
|
|
9280
|
+
if (!shouldHint(db2, ev.sessionId, onceKey)) return ALLOW2;
|
|
9281
|
+
return { kind: "hint", text: compactText(db2, ev, row5), onceKey };
|
|
9176
9282
|
}
|
|
9177
9283
|
const db = await openDb(project);
|
|
9178
9284
|
if (row5.compactDelivery === "opencode-cache" && metaTake(db, PENDING_COMPACT_META_PREFIX + ev.sessionId) !== null) {
|
|
@@ -9219,7 +9325,22 @@ async function firstTurnResume(ev, row5, project) {
|
|
|
9219
9325
|
return { kind: "hint", text: withPrefix(RESUME_HINT, row5), onceKey: RESUME_HINT_KEY };
|
|
9220
9326
|
}
|
|
9221
9327
|
function markCompacted(db, sessionId) {
|
|
9222
|
-
if (sessionId
|
|
9328
|
+
if (sessionId === "") return;
|
|
9329
|
+
metaSet(db, COMPACTED_META_PREFIX + sessionId, JSON.stringify({ seq: readMaxSeq(db), source: readMaxSourceId(db) }));
|
|
9330
|
+
}
|
|
9331
|
+
function compactBoundary(value) {
|
|
9332
|
+
const all = { seq: Number.MAX_SAFE_INTEGER, source: Number.MAX_SAFE_INTEGER };
|
|
9333
|
+
try {
|
|
9334
|
+
const v = JSON.parse(value);
|
|
9335
|
+
if (typeof v !== "object" || v === null) return all;
|
|
9336
|
+
const { seq, source } = v;
|
|
9337
|
+
return {
|
|
9338
|
+
seq: typeof seq === "number" ? seq : all.seq,
|
|
9339
|
+
source: typeof source === "number" ? source : all.source
|
|
9340
|
+
};
|
|
9341
|
+
} catch {
|
|
9342
|
+
return all;
|
|
9343
|
+
}
|
|
9223
9344
|
}
|
|
9224
9345
|
function seenSeqs(value) {
|
|
9225
9346
|
if (value === null) return [];
|
|
@@ -9242,13 +9363,16 @@ function seenUnitKeys(value) {
|
|
|
9242
9363
|
async function recall(ev, row5, project, prompt) {
|
|
9243
9364
|
if (!hasRecall(row5) || ev.sessionId === "") return ALLOW2;
|
|
9244
9365
|
const db = await openDb(project);
|
|
9245
|
-
|
|
9366
|
+
const compacted = metaGet(db, COMPACTED_META_PREFIX + ev.sessionId);
|
|
9367
|
+
if (compacted === null) return ALLOW2;
|
|
9368
|
+
const boundary = compactBoundary(compacted);
|
|
9246
9369
|
const seenKey = RECALL_SEEN_META_PREFIX + ev.sessionId;
|
|
9247
9370
|
const seen = seenSeqs(metaGet(db, seenKey));
|
|
9248
9371
|
const unitsKey = RECALL_UNITS_SEEN_META_PREFIX + ev.sessionId;
|
|
9249
9372
|
const seenUnits = seenUnitKeys(metaGet(db, unitsKey));
|
|
9250
|
-
const units = queryUnits(db, ev.sessionId, recallQueryText(prompt), RECALL_UNIT_CANDIDATES);
|
|
9251
|
-
const
|
|
9373
|
+
const units = queryUnits(db, ev.sessionId, recallQueryText(prompt), RECALL_UNIT_CANDIDATES, boundary.source);
|
|
9374
|
+
const rows = readRecallRows(db, ev.sessionId, project.worktree, RECALL_MAX_ROWS, boundary.seq);
|
|
9375
|
+
const picked = pickRecall(rows, prompt, new Set(seen), units, new Set(seenUnits));
|
|
9252
9376
|
if (picked.text === "") return ALLOW2;
|
|
9253
9377
|
if (picked.seqs.length > 0) metaSet(db, seenKey, JSON.stringify([...seen, ...picked.seqs]));
|
|
9254
9378
|
if (picked.units !== void 0) metaSet(db, unitsKey, JSON.stringify([...seenUnits, ...picked.units]));
|
|
@@ -9435,6 +9559,7 @@ function ownRead(ev, tool, env) {
|
|
|
9435
9559
|
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
9436
9560
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
9437
9561
|
if (boundedRead(tool)) return ALLOW2;
|
|
9562
|
+
if (ompRangedRead(ev, tool)) return ALLOW2;
|
|
9438
9563
|
if (ownRead(ev, tool, env)) return ALLOW2;
|
|
9439
9564
|
if (result.keep === true) return ALLOW2;
|
|
9440
9565
|
if (!hasReplace(row5)) return ALLOW2;
|
|
@@ -9449,6 +9574,7 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
|
9449
9574
|
shell: has3(row5.nativeTools.shell),
|
|
9450
9575
|
read: RANGE_READ_TOOLS.includes(tool.canonicalName) && has3(row5.nativeTools.read ?? [])
|
|
9451
9576
|
};
|
|
9577
|
+
if (set3 !== null && !caller.ctx && !caller.shell && !caller.read) return ALLOW2;
|
|
9452
9578
|
label2 = SUBAGENT_SOURCE_PREFIX + tool.canonicalName + ":" + (tool.callId ?? String(ev.turn ?? 0));
|
|
9453
9579
|
} else {
|
|
9454
9580
|
label2 = mainLabel(tool, ev);
|
|
@@ -9482,6 +9608,53 @@ function searchTwin(handle, intent, project) {
|
|
|
9482
9608
|
function boundedRead(tool) {
|
|
9483
9609
|
return RANGE_READ_TOOLS.includes(tool.canonicalName) && READ_RANGE_KEYS.some((k) => tool.input[k] !== void 0 && tool.input[k] !== null);
|
|
9484
9610
|
}
|
|
9611
|
+
function ompRangedRead(ev, tool) {
|
|
9612
|
+
if (ev.agent !== "omp" || !RANGE_READ_TOOLS.includes(tool.canonicalName)) return false;
|
|
9613
|
+
const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
|
|
9614
|
+
if (p === void 0 || !rangedPathSuffix(p)) return false;
|
|
9615
|
+
try {
|
|
9616
|
+
return lstatSync2(resolve8(ev.cwd, p), { throwIfNoEntry: false }) === void 0;
|
|
9617
|
+
} catch {
|
|
9618
|
+
return false;
|
|
9619
|
+
}
|
|
9620
|
+
}
|
|
9621
|
+
function rangedPathSuffix(path8) {
|
|
9622
|
+
let cut = path8.lastIndexOf(":");
|
|
9623
|
+
let sel = path8.slice(cut + 1);
|
|
9624
|
+
if (sel.toLowerCase() === "raw") {
|
|
9625
|
+
cut = path8.lastIndexOf(":", cut - 1);
|
|
9626
|
+
sel = path8.slice(cut + 1, path8.length - 4);
|
|
9627
|
+
}
|
|
9628
|
+
if (cut <= 0 || !rangeList(sel)) return false;
|
|
9629
|
+
let file2 = path8.slice(0, cut);
|
|
9630
|
+
if (file2.toLowerCase().endsWith(":raw")) file2 = file2.slice(0, -4);
|
|
9631
|
+
return file2.length > 1 || !asciiLetter(file2);
|
|
9632
|
+
}
|
|
9633
|
+
function rangeList(sel) {
|
|
9634
|
+
return sel !== "" && sel.split(",").every(rangeItem);
|
|
9635
|
+
}
|
|
9636
|
+
function rangeItem(item) {
|
|
9637
|
+
if (item.startsWith("-")) return digitsOnly(item.slice(1));
|
|
9638
|
+
let i = 0;
|
|
9639
|
+
while (i < item.length && digit(item[i])) i++;
|
|
9640
|
+
if (i === 0) return false;
|
|
9641
|
+
if (i === item.length) return true;
|
|
9642
|
+
const op = item[i];
|
|
9643
|
+
const rest = item.slice(i + 1);
|
|
9644
|
+
return op === "-" && (rest === "" || digitsOnly(rest)) || op === "+" && digitsOnly(rest);
|
|
9645
|
+
}
|
|
9646
|
+
function digitsOnly(s) {
|
|
9647
|
+
if (s === "") return false;
|
|
9648
|
+
for (const c of s) if (!digit(c)) return false;
|
|
9649
|
+
return true;
|
|
9650
|
+
}
|
|
9651
|
+
function digit(c) {
|
|
9652
|
+
return c >= "0" && c <= "9";
|
|
9653
|
+
}
|
|
9654
|
+
function asciiLetter(s) {
|
|
9655
|
+
const c = s.toLowerCase();
|
|
9656
|
+
return c.length === 1 && c >= "a" && c <= "z";
|
|
9657
|
+
}
|
|
9485
9658
|
function replaceOutput(body, handleLine) {
|
|
9486
9659
|
return body === "" ? handleLine : body + "\n" + handleLine;
|
|
9487
9660
|
}
|
|
@@ -20755,7 +20928,7 @@ function buildChildEnv(parent, extra) {
|
|
|
20755
20928
|
}
|
|
20756
20929
|
|
|
20757
20930
|
// src/core/sandbox/runtimes.ts
|
|
20758
|
-
import { accessSync, constants as fsConstants, statSync as
|
|
20931
|
+
import { accessSync, constants as fsConstants, statSync as statSync4 } from "node:fs";
|
|
20759
20932
|
import path from "node:path";
|
|
20760
20933
|
|
|
20761
20934
|
// src/core/sandbox/path-entries.ts
|
|
@@ -20797,22 +20970,34 @@ function fileNames(name, pathExt) {
|
|
|
20797
20970
|
if (!isWin() || path.extname(name) !== "") return [name];
|
|
20798
20971
|
return [...pathExt.map((ext) => name + ext), name];
|
|
20799
20972
|
}
|
|
20800
|
-
function
|
|
20801
|
-
|
|
20802
|
-
|
|
20973
|
+
function probe(full) {
|
|
20974
|
+
let st;
|
|
20975
|
+
try {
|
|
20976
|
+
st = statSync4(full, { throwIfNoEntry: false });
|
|
20977
|
+
} catch {
|
|
20978
|
+
return "unreadable";
|
|
20979
|
+
}
|
|
20980
|
+
if (st === void 0 || !st.isFile()) return "absent";
|
|
20803
20981
|
if (isWin()) {
|
|
20804
20982
|
const ext = path.extname(full).toLowerCase();
|
|
20805
|
-
return ext === "" || WIN_STARTABLE_EXT.includes(ext);
|
|
20983
|
+
return ext === "" || WIN_STARTABLE_EXT.includes(ext) ? "runnable" : "absent";
|
|
20806
20984
|
}
|
|
20807
20985
|
try {
|
|
20808
20986
|
accessSync(full, fsConstants.X_OK);
|
|
20809
|
-
return
|
|
20987
|
+
return "runnable";
|
|
20810
20988
|
} catch {
|
|
20811
|
-
return
|
|
20989
|
+
return "absent";
|
|
20812
20990
|
}
|
|
20813
20991
|
}
|
|
20992
|
+
function isRunnable(full) {
|
|
20993
|
+
return probe(full) === "runnable";
|
|
20994
|
+
}
|
|
20814
20995
|
function findRuntime(lang, env = process.env) {
|
|
20815
|
-
|
|
20996
|
+
return lookupRuntime(lang, env).found;
|
|
20997
|
+
}
|
|
20998
|
+
function lookupRuntime(lang, env = process.env) {
|
|
20999
|
+
const unreadable = [];
|
|
21000
|
+
if (isWin() && WIN_SHELL_LANGS.includes(lang)) return { found: findGitBash(env), unreadable };
|
|
20816
21001
|
const dirs = pathEntries(envValue(env, "PATH") ?? "", process.platform, path.delimiter);
|
|
20817
21002
|
const pathExt = isWin() ? (envValue(env, "PATHEXT") ?? PATHEXT_DEFAULT).split(PATHEXT_SEPARATOR).filter((e) => e !== "") : [];
|
|
20818
21003
|
const names = candidates(lang);
|
|
@@ -20821,13 +21006,15 @@ function findRuntime(lang, env = process.env) {
|
|
|
20821
21006
|
for (const name of names) {
|
|
20822
21007
|
for (const file2 of fileNames(name, pathExt)) {
|
|
20823
21008
|
const full = path.join(dir, file2);
|
|
20824
|
-
|
|
20825
|
-
if (
|
|
21009
|
+
const state = probe(full);
|
|
21010
|
+
if (state === "unreadable") unreadable.push(full);
|
|
21011
|
+
if (state !== "runnable") continue;
|
|
21012
|
+
if (!isWin() || path.extname(full) !== "") return { found: full, unreadable };
|
|
20826
21013
|
if (shim === null) shim = full;
|
|
20827
21014
|
}
|
|
20828
21015
|
}
|
|
20829
21016
|
}
|
|
20830
|
-
return shim;
|
|
21017
|
+
return { found: shim, unreadable };
|
|
20831
21018
|
}
|
|
20832
21019
|
function findGitBash(env) {
|
|
20833
21020
|
const git2 = findRuntime(GIT_BIN, env);
|
|
@@ -20907,7 +21094,7 @@ function runProcess(argv, o) {
|
|
|
20907
21094
|
let stopTimer;
|
|
20908
21095
|
const kill = () => {
|
|
20909
21096
|
if (child.pid !== void 0) killTree(child.pid);
|
|
20910
|
-
if (stopTimer === void 0) stopTimer = setTimeout(() => finishHeld(), KILL_GRACE_MS);
|
|
21097
|
+
if (stopTimer === void 0) stopTimer = setTimeout(() => finishHeld(true), KILL_GRACE_MS);
|
|
20911
21098
|
};
|
|
20912
21099
|
const onAbort = () => {
|
|
20913
21100
|
if (killedBy !== null || settled) return;
|
|
@@ -20936,15 +21123,21 @@ function runProcess(argv, o) {
|
|
|
20936
21123
|
...held ? { held: true } : {}
|
|
20937
21124
|
});
|
|
20938
21125
|
};
|
|
20939
|
-
const finishHeld = () => {
|
|
21126
|
+
const finishHeld = (force = false) => {
|
|
20940
21127
|
if (settled) return;
|
|
20941
|
-
|
|
20942
|
-
|
|
20943
|
-
|
|
20944
|
-
|
|
20945
|
-
|
|
21128
|
+
const seen = chunkCount;
|
|
21129
|
+
setImmediate(() => {
|
|
21130
|
+
if (settled || !force && chunkCount !== seen) return;
|
|
21131
|
+
held = exited && killedBy === null && !(child.stdout.readableEnded && child.stderr.readableEnded);
|
|
21132
|
+
child.stdout.destroy();
|
|
21133
|
+
child.stderr.destroy();
|
|
21134
|
+
if (child.pid !== void 0) killTree(child.pid);
|
|
21135
|
+
settle(child.exitCode);
|
|
21136
|
+
});
|
|
20946
21137
|
};
|
|
21138
|
+
let chunkCount = 0;
|
|
20947
21139
|
const bump = () => {
|
|
21140
|
+
chunkCount++;
|
|
20948
21141
|
if (!exited || settled) return;
|
|
20949
21142
|
clearTimeout(graceTimer);
|
|
20950
21143
|
graceTimer = setTimeout(finishHeld, PIPE_EOF_GRACE_MS);
|
|
@@ -20962,7 +21155,7 @@ function runProcess(argv, o) {
|
|
|
20962
21155
|
if (settled) return;
|
|
20963
21156
|
exited = true;
|
|
20964
21157
|
graceTimer = setTimeout(finishHeld, PIPE_EOF_GRACE_MS);
|
|
20965
|
-
drainTimer = setTimeout(finishHeld, PIPE_DRAIN_MAX_MS);
|
|
21158
|
+
drainTimer = setTimeout(() => finishHeld(true), PIPE_DRAIN_MAX_MS);
|
|
20966
21159
|
});
|
|
20967
21160
|
child.on("error", () => settle(null));
|
|
20968
21161
|
child.stdin.on("error", () => {
|
|
@@ -20975,7 +21168,7 @@ function runProcess(argv, o) {
|
|
|
20975
21168
|
}
|
|
20976
21169
|
|
|
20977
21170
|
// src/core/index/auto-memory.ts
|
|
20978
|
-
import { readdirSync as readdirSync3, readFileSync as readFileSync6, statSync as
|
|
21171
|
+
import { readdirSync as readdirSync3, readFileSync as readFileSync6, statSync as statSync5 } from "node:fs";
|
|
20979
21172
|
import { join as join9 } from "node:path";
|
|
20980
21173
|
var MEMORY_FILES = Object.freeze([
|
|
20981
21174
|
Object.freeze(["CLAUDE.md"]),
|
|
@@ -21001,7 +21194,7 @@ function readAutoMemory(project) {
|
|
|
21001
21194
|
const path8 = join9(project.worktree, ...segs);
|
|
21002
21195
|
if (!isInside(project.worktree, path8)) continue;
|
|
21003
21196
|
try {
|
|
21004
|
-
const st =
|
|
21197
|
+
const st = statSync5(path8);
|
|
21005
21198
|
if (!st.isFile()) continue;
|
|
21006
21199
|
rows.push({
|
|
21007
21200
|
origin: "memory",
|
|
@@ -21071,15 +21264,42 @@ function sourceCount(db, scope, ctx, source) {
|
|
|
21071
21264
|
});
|
|
21072
21265
|
return Number(row5.n);
|
|
21073
21266
|
}
|
|
21074
|
-
function zeroHits(db, scope, ctx, source, mem, offset = 0) {
|
|
21075
|
-
const
|
|
21267
|
+
function zeroHits(db, scope, ctx, source, mem, nm, queries, offset = 0) {
|
|
21268
|
+
const inScope = sourceCount(db, scope, ctx, source);
|
|
21269
|
+
const n = inScope + mem.rows.length;
|
|
21076
21270
|
if (offset > 0) return reply("No more hits past offset " + offset + ' in scope "' + scope + '" across ' + n + " source(s).", false);
|
|
21077
|
-
|
|
21271
|
+
const head2 = 'No hits in scope "' + scope + '" across ' + n + " source(s).";
|
|
21272
|
+
const pick2 = nm.pick;
|
|
21273
|
+
if (pick2 === null || mem.named || inScope > 0) return reply(head2, false);
|
|
21274
|
+
if (pick2.id !== null) {
|
|
21275
|
+
const wider = scope === "session" && sourceCount(db, "worktree", ctx, source) > 0 ? "worktree" : "project";
|
|
21276
|
+
return reply(head2 + "\nSource " + JSON.stringify(nm.arg) + ' is stored in scope "' + wider + '": ' + callText(queries, wider, nm.arg, "") + " searches it.", false);
|
|
21277
|
+
}
|
|
21278
|
+
return reply(head2 + "\n" + unknownSource(db, scope, ctx, nm.arg), true);
|
|
21279
|
+
}
|
|
21280
|
+
var STORED_SOURCES = `
|
|
21281
|
+
SELECT MAX(id) AS id, label FROM sources
|
|
21282
|
+
WHERE (:scope <> 'session' OR session_id = :session_id)
|
|
21283
|
+
AND (:scope <> 'worktree' OR worktree = :worktree)
|
|
21284
|
+
GROUP BY label ORDER BY MAX(id) DESC LIMIT :limit`;
|
|
21285
|
+
var STORED_SOURCES_SHOWN = 5;
|
|
21286
|
+
function unknownSource(db, scope, ctx, given) {
|
|
21287
|
+
const line = "Source " + JSON.stringify(given) + ' is not a stored source in scope "' + scope + '".';
|
|
21288
|
+
const rows = db.raw.prepare(STORED_SOURCES).all({
|
|
21289
|
+
scope,
|
|
21290
|
+
session_id: ctx.sessionId,
|
|
21291
|
+
worktree: ctx.project.worktree,
|
|
21292
|
+
limit: STORED_SOURCES_SHOWN + 1
|
|
21293
|
+
});
|
|
21294
|
+
if (rows.length === 0) return line + '\nctx_index stores one: ctx_index({content:"...", source:' + JSON.stringify(given) + "}).";
|
|
21295
|
+
const names = rows.slice(0, STORED_SOURCES_SHOWN).map((r) => isLongLabel(r.label) ? sourceHandle(Number(r.id)) : JSON.stringify(r.label));
|
|
21296
|
+
const more = rows.length > STORED_SOURCES_SHOWN ? ", ..." : "";
|
|
21297
|
+
return line + "\nStored sources, newest first: " + names.join(", ") + more + ". " + callText([], scope, void 0, 'sort:"timeline"') + " lists them all.";
|
|
21078
21298
|
}
|
|
21079
21299
|
function named(given, pick2) {
|
|
21080
|
-
if (given === void 0 || pick2 === null) return { arg: given, note: null };
|
|
21300
|
+
if (given === void 0 || pick2 === null) return { arg: given, note: null, pick: null };
|
|
21081
21301
|
const arg = pick2.id !== null && isLongLabel(given) ? sourceHandle(pick2.id) : given;
|
|
21082
|
-
return { arg, note: collisionLine(given, pick2) };
|
|
21302
|
+
return { arg, note: collisionLine(given, pick2), pick: pick2 };
|
|
21083
21303
|
}
|
|
21084
21304
|
function sourceCard(db, id2, input, scope, arg) {
|
|
21085
21305
|
const row5 = sourceCardRow(db, id2);
|
|
@@ -21211,7 +21431,7 @@ function relevance(db, given, scope, ctx, nm, ms, indexed) {
|
|
|
21211
21431
|
});
|
|
21212
21432
|
const take = fetched.map((h) => replyHits(h, size));
|
|
21213
21433
|
const pages = fetched.map((h, i) => h.slice(0, take[i]));
|
|
21214
|
-
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, ms, offset);
|
|
21434
|
+
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, ms, nm, input.queries, offset);
|
|
21215
21435
|
const moreLine3 = (q, pos) => "More: " + callText([q], scope, nm.arg, "offset:" + pos);
|
|
21216
21436
|
let reserve = 0;
|
|
21217
21437
|
for (const q of input.queries) reserve += bytes2(moreLine3(q, offset + size)) + 1;
|
|
@@ -21281,7 +21501,7 @@ function timelineLine(r) {
|
|
|
21281
21501
|
}
|
|
21282
21502
|
function timeline(db, input, scope, ctx, nm, ms) {
|
|
21283
21503
|
const page2 = ftsQueryTimeline(db, scope, ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, input.after ?? null, input.source, ms.rows);
|
|
21284
|
-
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source, ms);
|
|
21504
|
+
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source, ms, nm, input.queries);
|
|
21285
21505
|
const moreLine3 = (ts) => "more: " + callText(input.queries, scope, nm.arg, 'sort:"timeline", after:' + ts);
|
|
21286
21506
|
const reserve = bytes2(moreLine3(page2.rows[page2.rows.length - 1].ts)) + 1;
|
|
21287
21507
|
const lines = nm.note === null ? [] : [nm.note];
|
|
@@ -21584,8 +21804,8 @@ var ctxBatch = Object.freeze({
|
|
|
21584
21804
|
});
|
|
21585
21805
|
|
|
21586
21806
|
// src/core/tools/doctor.ts
|
|
21587
|
-
import { readdirSync as readdirSync8, readFileSync as
|
|
21588
|
-
import { basename as basename5, join as
|
|
21807
|
+
import { readdirSync as readdirSync8, readFileSync as readFileSync17, existsSync as existsSync17 } from "node:fs";
|
|
21808
|
+
import { basename as basename5, join as join20 } from "node:path";
|
|
21589
21809
|
|
|
21590
21810
|
// src/core/ops/bundle-dir.ts
|
|
21591
21811
|
import { existsSync as existsSync4 } from "node:fs";
|
|
@@ -21610,8 +21830,8 @@ function ownBundleDir() {
|
|
|
21610
21830
|
}
|
|
21611
21831
|
|
|
21612
21832
|
// src/core/ops/doctor-config.ts
|
|
21613
|
-
import { existsSync as
|
|
21614
|
-
import { dirname as dirname8, isAbsolute as
|
|
21833
|
+
import { existsSync as existsSync11, readdirSync as readdirSync6, readFileSync as readFileSync13 } from "node:fs";
|
|
21834
|
+
import { dirname as dirname8, isAbsolute as isAbsolute5, join as join16, resolve as resolve9 } from "node:path";
|
|
21615
21835
|
|
|
21616
21836
|
// src/core/ops/detect-v1.ts
|
|
21617
21837
|
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync4, readFileSync as readFileSync8 } from "node:fs";
|
|
@@ -23666,16 +23886,16 @@ function parseTOML(code, options) {
|
|
|
23666
23886
|
}
|
|
23667
23887
|
|
|
23668
23888
|
// src/core/ops/atomic-file.ts
|
|
23669
|
-
import { mkdirSync as mkdirSync3, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
23889
|
+
import { mkdirSync as mkdirSync3, renameSync as renameSync2, unlinkSync, writeFileSync } from "node:fs";
|
|
23670
23890
|
import path3 from "node:path";
|
|
23671
23891
|
function sleepSync(ms) {
|
|
23672
23892
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
23673
23893
|
}
|
|
23674
|
-
function
|
|
23894
|
+
function errCode2(e) {
|
|
23675
23895
|
return e.code;
|
|
23676
23896
|
}
|
|
23677
23897
|
function renameWithRetry(from, to, opts = {}) {
|
|
23678
|
-
const rename = opts.rename ??
|
|
23898
|
+
const rename = opts.rename ?? renameSync2;
|
|
23679
23899
|
const sleep = opts.sleep ?? sleepSync;
|
|
23680
23900
|
const win = (opts.platform ?? process.platform) === "win32";
|
|
23681
23901
|
for (let attempt = 0; ; attempt += 1) {
|
|
@@ -23683,7 +23903,7 @@ function renameWithRetry(from, to, opts = {}) {
|
|
|
23683
23903
|
rename(from, to);
|
|
23684
23904
|
return;
|
|
23685
23905
|
} catch (e) {
|
|
23686
|
-
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(
|
|
23906
|
+
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
|
|
23687
23907
|
if (!busy || attempt >= ATOMIC_RENAME_RETRIES) throw e;
|
|
23688
23908
|
sleep(ATOMIC_RENAME_DELAY_MS);
|
|
23689
23909
|
}
|
|
@@ -23698,15 +23918,15 @@ function unlinkWithRetry(file2, opts = {}) {
|
|
|
23698
23918
|
unlink(file2);
|
|
23699
23919
|
return;
|
|
23700
23920
|
} catch (e) {
|
|
23701
|
-
if (
|
|
23702
|
-
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(
|
|
23921
|
+
if (errCode2(e) === "ENOENT") return;
|
|
23922
|
+
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
|
|
23703
23923
|
if (!busy || attempt >= ATOMIC_RENAME_RETRIES) throw replaceFailure(file2, e);
|
|
23704
23924
|
sleep(ATOMIC_RENAME_DELAY_MS);
|
|
23705
23925
|
}
|
|
23706
23926
|
}
|
|
23707
23927
|
}
|
|
23708
23928
|
function replaceFailure(file2, e) {
|
|
23709
|
-
const busy = ATOMIC_RENAME_BUSY_CODES.includes(
|
|
23929
|
+
const busy = ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
|
|
23710
23930
|
const cause = e.message;
|
|
23711
23931
|
return new Error(busy ? `Could not replace ${file2}: ${cause}. Fix: close the program using ${file2}, then re-run` : `Could not write ${file2}: ${cause}. Fix: check the path and its permissions, then re-run`, { cause: e });
|
|
23712
23932
|
}
|
|
@@ -24600,6 +24820,14 @@ function configEntryRoot(adapter, env) {
|
|
|
24600
24820
|
if (typeof script !== "string" || !isAbsolute3(script)) throw missing(adapter.id, file2);
|
|
24601
24821
|
return dirname7(script);
|
|
24602
24822
|
}
|
|
24823
|
+
function packageDirOf(dir) {
|
|
24824
|
+
for (let cur = dir; ; ) {
|
|
24825
|
+
if (existsSync7(join13(cur, D1_PACKAGE_FILE))) return cur;
|
|
24826
|
+
const up = dirname7(cur);
|
|
24827
|
+
if (up === cur) return dir;
|
|
24828
|
+
cur = up;
|
|
24829
|
+
}
|
|
24830
|
+
}
|
|
24603
24831
|
function candidate(adapter, env, worktree) {
|
|
24604
24832
|
switch (adapter.installMode) {
|
|
24605
24833
|
case "marketplace":
|
|
@@ -24613,7 +24841,7 @@ function candidate(adapter, env, worktree) {
|
|
|
24613
24841
|
case "plugin":
|
|
24614
24842
|
return join13(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
24615
24843
|
case "in-process":
|
|
24616
|
-
return dirname7(fileURLToPath2(import.meta.url));
|
|
24844
|
+
return packageDirOf(dirname7(fileURLToPath2(import.meta.url)));
|
|
24617
24845
|
}
|
|
24618
24846
|
}
|
|
24619
24847
|
function resolvePluginRoot(adapter, env, worktree) {
|
|
@@ -24694,14 +24922,281 @@ function piInstalledIn(env, home, pkgDir, cwd) {
|
|
|
24694
24922
|
return user && ownEntries(user, pkgDir).length > 0 ? user.file : void 0;
|
|
24695
24923
|
}
|
|
24696
24924
|
|
|
24925
|
+
// src/core/ops/doctor-env.ts
|
|
24926
|
+
import { existsSync as existsSync9, readFileSync as readFileSync11, realpathSync as realpathSync6 } from "node:fs";
|
|
24927
|
+
import { isAbsolute as isAbsolute4, join as join14, relative as relative4 } from "node:path";
|
|
24928
|
+
function pass(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
24929
|
+
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
24930
|
+
}
|
|
24931
|
+
function unknown2(id2, detail, fixCommand) {
|
|
24932
|
+
return fixCommand === void 0 ? { id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail } : { id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail, fixCommand };
|
|
24933
|
+
}
|
|
24934
|
+
function fail2(id2, detail, fixCommand) {
|
|
24935
|
+
return { id: id2, label: DOCTOR_LABEL[id2], status: "FAIL", detail, fixCommand };
|
|
24936
|
+
}
|
|
24937
|
+
function warn(id2, detail, fixCommand) {
|
|
24938
|
+
return { id: id2, label: DOCTOR_LABEL[id2], status: "WARN", detail, fixCommand };
|
|
24939
|
+
}
|
|
24940
|
+
function bundleVersion(bundleDir2) {
|
|
24941
|
+
try {
|
|
24942
|
+
const v = JSON.parse(readFileSync11(join14(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24943
|
+
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24944
|
+
} catch {
|
|
24945
|
+
return void 0;
|
|
24946
|
+
}
|
|
24947
|
+
}
|
|
24948
|
+
function channelOf(version2) {
|
|
24949
|
+
const at2 = version2.indexOf(D1_PRERELEASE_SEP);
|
|
24950
|
+
if (at2 < 0) return D1_DEFAULT_TAG;
|
|
24951
|
+
const pre = version2.slice(at2 + 1);
|
|
24952
|
+
const dot = pre.indexOf(".");
|
|
24953
|
+
const tag2 = dot < 0 ? pre : pre.slice(0, dot);
|
|
24954
|
+
return tag2 === "" ? D1_DEFAULT_TAG : tag2;
|
|
24955
|
+
}
|
|
24956
|
+
function firstLine3(b) {
|
|
24957
|
+
const text = b.toString("utf8").trim();
|
|
24958
|
+
const nl = text.indexOf("\n");
|
|
24959
|
+
return (nl < 0 ? text : text.slice(0, nl)).trim();
|
|
24960
|
+
}
|
|
24961
|
+
function gitCause(r, timeoutMs) {
|
|
24962
|
+
if (r.killed === "timeout") return D1_GIT_TIMEOUT(timeoutMs);
|
|
24963
|
+
if (r.killed === "cancel") return D1_GIT_CANCEL;
|
|
24964
|
+
if (r.exitCode === null) return D1_GIT_NO_START;
|
|
24965
|
+
return D1_GIT_EXIT(r.exitCode, firstLine3(r.stderr));
|
|
24966
|
+
}
|
|
24967
|
+
function fetchCause(err, timeoutMs) {
|
|
24968
|
+
const name = err instanceof Error ? err.name : "";
|
|
24969
|
+
if (name === "TimeoutError") return D1_NPM_TIMEOUT(timeoutMs);
|
|
24970
|
+
const cause = err instanceof Error && err.cause instanceof Error ? err.cause : err;
|
|
24971
|
+
const code = typeof cause === "object" && cause !== null && "code" in cause && typeof cause.code === "string" ? cause.code : "";
|
|
24972
|
+
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
24973
|
+
const parts = code !== "" && !msg.includes(code) ? [code, msg] : [msg];
|
|
24974
|
+
return D1_NPM_ERROR(parts.filter((part) => part !== "").join(" "));
|
|
24975
|
+
}
|
|
24976
|
+
async function npmLatest(url2, tag2, signal, timeoutMs) {
|
|
24977
|
+
try {
|
|
24978
|
+
const res = await fetch(url2, { signal: AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) });
|
|
24979
|
+
if (!res.ok) return { ok: false, cause: D1_NPM_HTTP(res.status) };
|
|
24980
|
+
const body = await res.json();
|
|
24981
|
+
const v = typeof body === "object" && body !== null ? body[tag2] : void 0;
|
|
24982
|
+
return typeof v === "string" && v !== "" ? { ok: true, version: v } : { ok: false, cause: D1_NPM_NO_TAG(tag2) };
|
|
24983
|
+
} catch (err) {
|
|
24984
|
+
return { ok: false, cause: fetchCause(err, timeoutMs) };
|
|
24985
|
+
}
|
|
24986
|
+
}
|
|
24987
|
+
function digits(s) {
|
|
24988
|
+
if (s === "") return false;
|
|
24989
|
+
for (const ch of s) if (ch < "0" || ch > "9") return false;
|
|
24990
|
+
return true;
|
|
24991
|
+
}
|
|
24992
|
+
function parseVersion(v) {
|
|
24993
|
+
const at2 = v.indexOf(D1_PRERELEASE_SEP);
|
|
24994
|
+
const core = (at2 < 0 ? v : v.slice(0, at2)).split(NODE_VERSION_SEP);
|
|
24995
|
+
if (core.length !== 3 || !core.every(digits)) return null;
|
|
24996
|
+
const nums = [Number(core[0]), Number(core[1]), Number(core[2])];
|
|
24997
|
+
if (at2 < 0) return { core: nums, pre: [] };
|
|
24998
|
+
const pre = v.slice(at2 + 1).split(NODE_VERSION_SEP);
|
|
24999
|
+
if (pre[0] === "" || digits(pre[0]) || pre.length > 2) return null;
|
|
25000
|
+
if (pre.length === 1) return { core: nums, pre: [pre[0]] };
|
|
25001
|
+
return digits(pre[1]) ? { core: nums, pre: [pre[0], Number(pre[1])] } : null;
|
|
25002
|
+
}
|
|
25003
|
+
function sign(n) {
|
|
25004
|
+
return n < 0 ? -1 : n > 0 ? 1 : 0;
|
|
25005
|
+
}
|
|
25006
|
+
function compareVersions(a, b) {
|
|
25007
|
+
const x = parseVersion(a);
|
|
25008
|
+
const y = parseVersion(b);
|
|
25009
|
+
if (x === null || y === null) return null;
|
|
25010
|
+
for (let k = 0; k < 3; k++) if (x.core[k] !== y.core[k]) return sign(x.core[k] - y.core[k]);
|
|
25011
|
+
if (x.pre.length === 0 || y.pre.length === 0) return sign(y.pre.length - x.pre.length);
|
|
25012
|
+
if (x.pre[0] !== y.pre[0]) return x.pre[0] < y.pre[0] ? -1 : 1;
|
|
25013
|
+
return sign((x.pre[1] ?? -1) - (y.pre[1] ?? -1));
|
|
25014
|
+
}
|
|
25015
|
+
function highestTag(stdout, tag2) {
|
|
25016
|
+
let best;
|
|
25017
|
+
for (const line of stdout.split("\n")) {
|
|
25018
|
+
const [sha, ref] = line.trim().split(LS_REMOTE_FIELD_SEP);
|
|
25019
|
+
if (sha === void 0 || sha.length !== GIT_SHA_HEX_LEN || ref === void 0 || !ref.startsWith(RELEASE_TAG_REF_PREFIX)) continue;
|
|
25020
|
+
const v = ref.slice(RELEASE_TAG_REF_PREFIX.length);
|
|
25021
|
+
if (parseVersion(v) === null || channelOf(v) !== tag2) continue;
|
|
25022
|
+
if (best === void 0 || compareVersions(v, best) === 1) best = v;
|
|
25023
|
+
}
|
|
25024
|
+
return best;
|
|
25025
|
+
}
|
|
25026
|
+
function versionRow(head2, installed, tag2, source, latest, tail, update) {
|
|
25027
|
+
const cmp = compareVersions(installed, latest) ?? (installed === latest ? 0 : -1);
|
|
25028
|
+
if (cmp === 0) return pass("D1", head2 + D1_LATEST_PASS(tag2, source) + tail);
|
|
25029
|
+
if (cmp > 0) return pass("D1", head2 + D1_LATEST_AHEAD(tag2, source, latest) + tail);
|
|
25030
|
+
return warn("D1", head2 + D1_LATEST_UPDATE(tag2, source, latest) + tail, update);
|
|
25031
|
+
}
|
|
25032
|
+
async function checkVersion(i) {
|
|
25033
|
+
if (i.bundleSha === void 0) return unknown2("D1", D1_DEV_BUILD_DETAIL);
|
|
25034
|
+
const head2 = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
25035
|
+
if (i.version === void 0) return unknown2("D1", head2 + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
|
|
25036
|
+
const tag2 = channelOf(i.version);
|
|
25037
|
+
const update = i.updateCommand ?? DOCTOR_FIX_UPGRADE;
|
|
25038
|
+
const git2 = findRuntime(GIT_BIN, i.env);
|
|
25039
|
+
const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
|
|
25040
|
+
if (npm.ok) return versionRow(head2, i.version, tag2, D1_SOURCE_NPM, npm.version, "", update);
|
|
25041
|
+
let cause = D1_GIT_MISSING;
|
|
25042
|
+
if (git2 !== null) {
|
|
25043
|
+
const r = await runProcess([git2, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
|
|
25044
|
+
cwd: i.cwd,
|
|
25045
|
+
env: { ...i.env, ...GIT_NO_PROMPT_ENV },
|
|
25046
|
+
signal: i.signal,
|
|
25047
|
+
timeoutMs: i.timeoutMs
|
|
25048
|
+
});
|
|
25049
|
+
if (r.exitCode === 0 && r.killed === null) {
|
|
25050
|
+
const latest = highestTag(r.stdout.toString("utf8"), tag2);
|
|
25051
|
+
if (latest !== void 0) return versionRow(head2, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause, update);
|
|
25052
|
+
cause = D1_GIT_NO_TAG(tag2);
|
|
25053
|
+
} else {
|
|
25054
|
+
cause = gitCause(r, i.timeoutMs);
|
|
25055
|
+
}
|
|
25056
|
+
}
|
|
25057
|
+
return unknown2("D1", head2 + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause, git2 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX);
|
|
25058
|
+
}
|
|
25059
|
+
function numbers(v) {
|
|
25060
|
+
const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
|
|
25061
|
+
return bare2.split(NODE_VERSION_SEP).map(Number);
|
|
25062
|
+
}
|
|
25063
|
+
function belowMin(version2) {
|
|
25064
|
+
const got = numbers(version2);
|
|
25065
|
+
const min = numbers(NODE_MIN);
|
|
25066
|
+
for (let k = 0; k < min.length; k++) {
|
|
25067
|
+
const g = got[k] ?? 0;
|
|
25068
|
+
if (g !== min[k]) return g < min[k];
|
|
25069
|
+
}
|
|
25070
|
+
return false;
|
|
25071
|
+
}
|
|
25072
|
+
async function sqliteLoads() {
|
|
25073
|
+
try {
|
|
25074
|
+
await import(SQLITE_MODULE);
|
|
25075
|
+
return true;
|
|
25076
|
+
} catch {
|
|
25077
|
+
return false;
|
|
25078
|
+
}
|
|
25079
|
+
}
|
|
25080
|
+
async function checkNode(i) {
|
|
25081
|
+
const bun = i.bunVersion === void 0 ? [] : [D2_BUN_DETAIL(i.bunVersion)];
|
|
25082
|
+
const withBun = (detail) => [detail, ...bun].join(D4_REASON_JOIN);
|
|
25083
|
+
if (belowMin(i.nodeVersion)) return fail2("D2", withBun(D2_NODE_DETAIL(i.nodeVersion)), D2_NODE_FIX);
|
|
25084
|
+
if (!await sqliteLoads()) return fail2("D2", withBun(D2_SQLITE_DETAIL), D2_SQLITE_FIX);
|
|
25085
|
+
return pass("D2", bun.length === 0 ? DOCTOR_PASS_DETAIL : bun.join(D4_REASON_JOIN));
|
|
25086
|
+
}
|
|
25087
|
+
function checkMcp(ctx, adapter) {
|
|
25088
|
+
const named2 = ctx.clientInfo !== void 0 && ctx.clientInfo.name !== "";
|
|
25089
|
+
const versioned = ctx.protocolVersion !== void 0 && ctx.protocolVersion !== "";
|
|
25090
|
+
if (named2 || versioned) return pass("D6");
|
|
25091
|
+
return adapter?.installMode === "in-process" ? pass("D6", D6_IN_PROCESS_DETAIL) : unknown2("D6", D6_UNKNOWN_DETAIL);
|
|
25092
|
+
}
|
|
25093
|
+
function piCwdInside(worktree, piCwd) {
|
|
25094
|
+
if (piCwd === void 0 || !existsSync9(piCwd)) return false;
|
|
25095
|
+
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
25096
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute4(rel);
|
|
25097
|
+
}
|
|
25098
|
+
function checkProject(i) {
|
|
25099
|
+
const bad = fail2("D7", D7_DETAIL(i.project.source), D7_FIX);
|
|
25100
|
+
if (i.project.source !== i.adapter.projectSource) return bad;
|
|
25101
|
+
if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
|
|
25102
|
+
return pass("D7");
|
|
25103
|
+
}
|
|
25104
|
+
function checkMode(adapter, hostPermission) {
|
|
25105
|
+
if (hostPermission === "missing") return fail2("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
|
|
25106
|
+
if (hostPermission === "wired") return pass("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
|
|
25107
|
+
return pass("D10", D10_DETAIL(adapter.denyChannel));
|
|
25108
|
+
}
|
|
25109
|
+
function checkShell(env) {
|
|
25110
|
+
const win = process.platform === "win32";
|
|
25111
|
+
const shell = findRuntime("shell", env);
|
|
25112
|
+
if (shell !== null) return pass("D11", D11_PASS_DETAIL(shell, win));
|
|
25113
|
+
return win ? fail2("D11", D11_WIN_DETAIL, D11_WIN_FIX) : fail2("D11", D11_POSIX_DETAIL, D11_POSIX_FIX);
|
|
25114
|
+
}
|
|
25115
|
+
function checkRuntimes(env, shellRow) {
|
|
25116
|
+
if (shellRow.status !== "PASS") return shellRow;
|
|
25117
|
+
for (const lang of EXEC_LANGUAGES) {
|
|
25118
|
+
if (lang === "shell") continue;
|
|
25119
|
+
const r = lookupRuntime(lang, env);
|
|
25120
|
+
if (r.found === null && r.unreadable.length > 0) return warn("D11", D11_RUNTIME_DETAIL(lang, r.unreadable), D11_RUNTIME_FIX(lang));
|
|
25121
|
+
}
|
|
25122
|
+
return shellRow;
|
|
25123
|
+
}
|
|
25124
|
+
|
|
25125
|
+
// src/core/ops/omp-import.ts
|
|
25126
|
+
import { join as join15 } from "node:path";
|
|
25127
|
+
var { existsSync: existsSync10, readFileSync: readFileSync12 } = process.getBuiltinModule("node:fs");
|
|
25128
|
+
var OMP_DISABLED_SERVERS_KEY = "disabledServers";
|
|
25129
|
+
var OMP_MCP_FILE = "mcp.json";
|
|
25130
|
+
var OMP_CONFIG_FILE = "config.yml";
|
|
25131
|
+
var ENABLED_PROVIDERS = "enabledProviders";
|
|
25132
|
+
var DISABLED_PROVIDERS = "disabledProviders";
|
|
25133
|
+
var CLAUDE_PROVIDER = "claude";
|
|
25134
|
+
var ALL_PROVIDERS = ["*", "all"];
|
|
25135
|
+
function ompImportFiles(home) {
|
|
25136
|
+
const agentDir = join15(home, ...AGENT_HOME_DIR.omp, PI_AGENT_DIR);
|
|
25137
|
+
return { config: join15(agentDir, OMP_CONFIG_FILE), mcp: join15(agentDir, OMP_MCP_FILE), claude: join15(home, CLAUDE_USER_CONFIG_FILE) };
|
|
25138
|
+
}
|
|
25139
|
+
function readText2(file2) {
|
|
25140
|
+
try {
|
|
25141
|
+
return existsSync10(file2) ? hostText(readFileSync12(file2, "utf8")) : void 0;
|
|
25142
|
+
} catch {
|
|
25143
|
+
return void 0;
|
|
25144
|
+
}
|
|
25145
|
+
}
|
|
25146
|
+
var unquote3 = (s) => {
|
|
25147
|
+
const t = s.trim();
|
|
25148
|
+
const q = t[0];
|
|
25149
|
+
return (q === '"' || q === "'") && t.endsWith(q) && t.length > 1 ? t.slice(1, -1) : t;
|
|
25150
|
+
};
|
|
25151
|
+
var withoutComment = (s) => {
|
|
25152
|
+
const at2 = s.indexOf(" #");
|
|
25153
|
+
return at2 === -1 ? s : s.slice(0, at2);
|
|
25154
|
+
};
|
|
25155
|
+
function yamlTopList(text, key) {
|
|
25156
|
+
const lines = text.split("\n").map((l) => l.endsWith("\r") ? l.slice(0, -1) : l);
|
|
25157
|
+
const head2 = `${key}:`;
|
|
25158
|
+
const at2 = lines.findIndex((l) => l.startsWith(head2));
|
|
25159
|
+
if (at2 === -1) return [];
|
|
25160
|
+
const rest = withoutComment(lines[at2].slice(head2.length)).trim();
|
|
25161
|
+
if (rest.startsWith("[")) {
|
|
25162
|
+
const end = rest.indexOf("]");
|
|
25163
|
+
return (end === -1 ? rest.slice(1) : rest.slice(1, end)).split(",").map(unquote3).filter((x) => x !== "");
|
|
25164
|
+
}
|
|
25165
|
+
if (rest !== "") return [];
|
|
25166
|
+
const out = [];
|
|
25167
|
+
for (const line of lines.slice(at2 + 1)) {
|
|
25168
|
+
const t = line.trim();
|
|
25169
|
+
if (t === "" || t.startsWith("#")) continue;
|
|
25170
|
+
if (line === line.trimStart() && !t.startsWith("-")) break;
|
|
25171
|
+
if (!t.startsWith("-")) break;
|
|
25172
|
+
out.push(unquote3(withoutComment(t.slice(1))));
|
|
25173
|
+
}
|
|
25174
|
+
return out;
|
|
25175
|
+
}
|
|
25176
|
+
function ompImportsUs(files, env) {
|
|
25177
|
+
const config2 = readText2(files.config) ?? "";
|
|
25178
|
+
if (yamlTopList(config2, DISABLED_PROVIDERS).includes(CLAUDE_PROVIDER)) return false;
|
|
25179
|
+
const enabled = yamlTopList(config2, ENABLED_PROVIDERS);
|
|
25180
|
+
const dirSet = env[CLAUDE_CONFIG_DIR_ENV] !== void 0 && env[CLAUDE_CONFIG_DIR_ENV] !== "";
|
|
25181
|
+
if (!dirSet && !enabled.some((p) => p === CLAUDE_PROVIDER || ALL_PROVIDERS.includes(p))) return false;
|
|
25182
|
+
const claude = readText2(files.claude);
|
|
25183
|
+
if (claude === void 0) return false;
|
|
25184
|
+
try {
|
|
25185
|
+
const servers = JSON.parse(claude)[MCP_SERVERS_KEY];
|
|
25186
|
+
return typeof servers === "object" && servers !== null && Object.hasOwn(servers, SERVER_KEY);
|
|
25187
|
+
} catch {
|
|
25188
|
+
return false;
|
|
25189
|
+
}
|
|
25190
|
+
}
|
|
25191
|
+
|
|
24697
25192
|
// src/core/ops/doctor-config.ts
|
|
24698
25193
|
var [PART_MCP, PART_HOOKS, PART_TIMEOUT] = D3_PARTS;
|
|
24699
25194
|
var isObject4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
24700
25195
|
var list2 = (v) => Array.isArray(v) ? v : [];
|
|
24701
|
-
function
|
|
25196
|
+
function pass2(id2) {
|
|
24702
25197
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail: DOCTOR_PASS_DETAIL };
|
|
24703
25198
|
}
|
|
24704
|
-
function
|
|
25199
|
+
function fail3(id2, detail, fixCommand) {
|
|
24705
25200
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "FAIL", detail, fixCommand };
|
|
24706
25201
|
}
|
|
24707
25202
|
function readParsed(agent, file2) {
|
|
@@ -24771,11 +25266,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
24771
25266
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
24772
25267
|
function mcpFile(row5, home, env) {
|
|
24773
25268
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
24774
|
-
if (row5.id === "codex") return
|
|
25269
|
+
if (row5.id === "codex") return join16(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
24775
25270
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
24776
|
-
if (row5.id === "opencode") return
|
|
25271
|
+
if (row5.id === "opencode") return join16(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
24777
25272
|
if (row5.id === "pi") {
|
|
24778
|
-
return
|
|
25273
|
+
return join16(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
24779
25274
|
}
|
|
24780
25275
|
return null;
|
|
24781
25276
|
}
|
|
@@ -24788,27 +25283,27 @@ function codexNativeDir(env, home) {
|
|
|
24788
25283
|
const codexDir = codexDirOf(env, home);
|
|
24789
25284
|
let enabled;
|
|
24790
25285
|
try {
|
|
24791
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
25286
|
+
enabled = hostConfigValueAt(readParsed("codex", join16(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
24792
25287
|
} catch {
|
|
24793
25288
|
return null;
|
|
24794
25289
|
}
|
|
24795
25290
|
if (enabled !== true) return null;
|
|
24796
|
-
const cache =
|
|
24797
|
-
if (!
|
|
25291
|
+
const cache = join16(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
25292
|
+
if (!existsSync11(cache)) return null;
|
|
24798
25293
|
const found = [];
|
|
24799
25294
|
for (const market of readdirSync6(cache)) {
|
|
24800
|
-
const plugin =
|
|
24801
|
-
if (!
|
|
25295
|
+
const plugin = join16(cache, market, SERVER_KEY);
|
|
25296
|
+
if (!existsSync11(plugin)) continue;
|
|
24802
25297
|
for (const version2 of readdirSync6(plugin).sort()) {
|
|
24803
|
-
const dir =
|
|
24804
|
-
if (
|
|
25298
|
+
const dir = join16(plugin, version2, CODEX_PLUGIN_SUBDIR);
|
|
25299
|
+
if (existsSync11(join16(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
24805
25300
|
}
|
|
24806
25301
|
}
|
|
24807
25302
|
return found.length === 0 ? null : found[found.length - 1];
|
|
24808
25303
|
}
|
|
24809
25304
|
function nativeMcpWrong(dir, row5) {
|
|
24810
25305
|
try {
|
|
24811
|
-
const entry = hostConfigValueAt(readParsed(row5.id,
|
|
25306
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join16(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
24812
25307
|
if (!isObject4(entry)) return true;
|
|
24813
25308
|
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
24814
25309
|
const script = args[0];
|
|
@@ -24879,17 +25374,17 @@ function opencodePluginDirs(configDir, worktree) {
|
|
|
24879
25374
|
return [configDir, opencodeProjectDir(worktree)];
|
|
24880
25375
|
}
|
|
24881
25376
|
function opencodeProjectDir(worktree) {
|
|
24882
|
-
return
|
|
25377
|
+
return join16(worktree, OPENCODE_PROJECT_DIR);
|
|
24883
25378
|
}
|
|
24884
25379
|
function packageResolves(fromDir) {
|
|
24885
25380
|
for (let d = fromDir; ; d = dirname8(d)) {
|
|
24886
|
-
if (
|
|
25381
|
+
if (existsSync11(join16(d, NODE_MODULES_DIR, SERVER_KEY, PACKAGE_JSON_FILE))) return true;
|
|
24887
25382
|
if (dirname8(d) === d) return false;
|
|
24888
25383
|
}
|
|
24889
25384
|
}
|
|
24890
25385
|
function opencodeDirPlugins(dirs) {
|
|
24891
25386
|
const bundle = opencodePluginFile();
|
|
24892
|
-
const ownFile =
|
|
25387
|
+
const ownFile = join16(bundle, ...OPENCODE_PLUGIN_PATH).split("\\").join("/");
|
|
24893
25388
|
const isModule = (p) => OWN_PLUGIN_MODULES.includes(p);
|
|
24894
25389
|
const isPath = (p) => {
|
|
24895
25390
|
if (p === ownFile || p === `${FILE_URL_PREFIX}${ownFile}`) return true;
|
|
@@ -24899,7 +25394,7 @@ function opencodeDirPlugins(dirs) {
|
|
|
24899
25394
|
};
|
|
24900
25395
|
const out = [];
|
|
24901
25396
|
for (const dir of dirs) {
|
|
24902
|
-
const pdir =
|
|
25397
|
+
const pdir = join16(dir, OPENCODE_PLUGINS_DIR);
|
|
24903
25398
|
let names;
|
|
24904
25399
|
try {
|
|
24905
25400
|
names = readdirSync6(pdir);
|
|
@@ -24907,12 +25402,12 @@ function opencodeDirPlugins(dirs) {
|
|
|
24907
25402
|
continue;
|
|
24908
25403
|
}
|
|
24909
25404
|
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) =>
|
|
25405
|
+
const loose = OPENCODE_PLUGIN_EXTS.some((x) => name.endsWith(x)) ? [join16(pdir, name)] : [];
|
|
25406
|
+
const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x) => join16(pdir, name, `${OPENCODE_PLUGIN_INDEX}${x}`))];
|
|
24912
25407
|
for (const f of files) {
|
|
24913
25408
|
let text;
|
|
24914
25409
|
try {
|
|
24915
|
-
const b =
|
|
25410
|
+
const b = readFileSync13(f);
|
|
24916
25411
|
if (b.length > OPENCODE_DIR_FILE_MAX) continue;
|
|
24917
25412
|
text = b.toString("utf8");
|
|
24918
25413
|
} catch {
|
|
@@ -24923,7 +25418,7 @@ function opencodeDirPlugins(dirs) {
|
|
|
24923
25418
|
const loads = lits.some((p) => {
|
|
24924
25419
|
if (isModule(p)) return packageResolves(dirname8(f));
|
|
24925
25420
|
const bare2 = p.startsWith(FILE_URL_PREFIX) ? p.slice(FILE_URL_PREFIX.length) : p;
|
|
24926
|
-
return
|
|
25421
|
+
return existsSync11(isAbsolute5(bare2) ? bare2 : resolve9(dirname8(f), bare2));
|
|
24927
25422
|
});
|
|
24928
25423
|
out.push({ file: f, loads });
|
|
24929
25424
|
}
|
|
@@ -24941,19 +25436,19 @@ function opencodeMcpOwn(entry) {
|
|
|
24941
25436
|
return isNodeCommand(node) && typeof script === "string" && lastSegment(script) === SERVER_ENTRY_FILE && flag === AGENT_ARG && agent === "opencode";
|
|
24942
25437
|
}
|
|
24943
25438
|
function opencodeFileValue(file2) {
|
|
24944
|
-
if (!
|
|
24945
|
-
return parseHostConfig("opencode", file2, hostText(
|
|
25439
|
+
if (!existsSync11(file2)) return {};
|
|
25440
|
+
return parseHostConfig("opencode", file2, hostText(readFileSync13(file2, "utf8")), "jsonc");
|
|
24946
25441
|
}
|
|
24947
25442
|
function opencodeValueListed(value) {
|
|
24948
25443
|
const bundle = opencodePluginFile();
|
|
24949
|
-
const own2 = [bundle,
|
|
25444
|
+
const own2 = [bundle, join16(bundle, ...OPENCODE_PLUGIN_PATH)];
|
|
24950
25445
|
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
25446
|
const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
|
|
24952
25447
|
return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
|
|
24953
25448
|
}
|
|
24954
25449
|
function opencodeListed(file2, worktree) {
|
|
24955
25450
|
const dirs = [dirname8(file2), worktree];
|
|
24956
|
-
if (dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(
|
|
25451
|
+
if (dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(join16(dir, name)))))) return true;
|
|
24957
25452
|
return opencodeDirPlugin(opencodePluginDirs(dirname8(file2), worktree)) !== void 0;
|
|
24958
25453
|
}
|
|
24959
25454
|
function mcpWrong(row5, home, env, worktree) {
|
|
@@ -24975,7 +25470,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
24975
25470
|
function hookFile(row5, spec, home, env, worktree) {
|
|
24976
25471
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
24977
25472
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24978
|
-
const file2 = native !== null ?
|
|
25473
|
+
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
25474
|
return file2;
|
|
24980
25475
|
}
|
|
24981
25476
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -24986,7 +25481,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
24986
25481
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
24987
25482
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
24988
25483
|
if (row5.id === "codex") {
|
|
24989
|
-
const config2 = readParsed(row5.id,
|
|
25484
|
+
const config2 = readParsed(row5.id, join16(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
24990
25485
|
if (hostConfigValueAt(config2, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
24991
25486
|
}
|
|
24992
25487
|
} catch {
|
|
@@ -25015,29 +25510,67 @@ function hookParts(row5, home, env, worktree) {
|
|
|
25015
25510
|
}
|
|
25016
25511
|
function checkHostConfig(row5, env, worktree) {
|
|
25017
25512
|
const home = homeDirOf(env);
|
|
25018
|
-
if (home === null) return
|
|
25513
|
+
if (home === null) return fail3("D3", D3_DETAIL(D3_PARTS), DOCTOR_FIX_UPGRADE);
|
|
25019
25514
|
if (row5.installMode === "marketplace") {
|
|
25020
25515
|
const choice = marketplaceChoice(env, worktree);
|
|
25021
|
-
if ("installs" in choice) return
|
|
25516
|
+
if ("installs" in choice) return fail3("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
|
|
25022
25517
|
}
|
|
25023
25518
|
if (row5.id === "pi") return checkPiInstall(env, home, worktree);
|
|
25519
|
+
if (row5.id === "omp") return checkOmpInstall(home);
|
|
25024
25520
|
const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
|
|
25025
|
-
if (parts.length === 0) return
|
|
25521
|
+
if (parts.length === 0) return pass2("D3");
|
|
25026
25522
|
const detail = D3_DETAIL(parts);
|
|
25027
25523
|
const fix = parts.includes(PART_MCP) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
|
|
25028
|
-
return
|
|
25524
|
+
return fail3("D3", detail, fix);
|
|
25029
25525
|
}
|
|
25030
25526
|
function checkPiInstall(env, home, worktree) {
|
|
25031
25527
|
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
25032
|
-
if (found !== void 0) return { ...
|
|
25033
|
-
return
|
|
25528
|
+
if (found !== void 0) return { ...pass2("D3"), detail: found };
|
|
25529
|
+
return fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join16(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
|
|
25530
|
+
}
|
|
25531
|
+
var OMP_PLUGINS_DIR = "plugins";
|
|
25532
|
+
var OMP_LOCK_FILE = "omp-plugins.lock.json";
|
|
25533
|
+
function readJson2(file2) {
|
|
25534
|
+
try {
|
|
25535
|
+
const doc = JSON.parse(readFileSync13(file2, "utf8"));
|
|
25536
|
+
return typeof doc === "object" && doc !== null ? doc : void 0;
|
|
25537
|
+
} catch {
|
|
25538
|
+
return void 0;
|
|
25539
|
+
}
|
|
25540
|
+
}
|
|
25541
|
+
function ownEntry(doc, key) {
|
|
25542
|
+
const map2 = doc?.[key];
|
|
25543
|
+
return typeof map2 === "object" && map2 !== null ? map2[SERVER_KEY] : void 0;
|
|
25544
|
+
}
|
|
25545
|
+
function checkOmpInstall(home) {
|
|
25546
|
+
const dir = join16(home, ...AGENT_HOME_DIR.omp, OMP_PLUGINS_DIR);
|
|
25547
|
+
const lock = join16(dir, OMP_LOCK_FILE);
|
|
25548
|
+
const pkg = join16(dir, PI_PACKAGE_JSON_FILE);
|
|
25549
|
+
const entry = ownEntry(readJson2(lock), "plugins");
|
|
25550
|
+
const missing2 = (file2) => fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + file2, NATIVE_INSTALL.omp[0]);
|
|
25551
|
+
if (typeof entry !== "object" || entry === null) return missing2(lock);
|
|
25552
|
+
if (ownEntry(readJson2(pkg), "dependencies") === void 0) return missing2(pkg);
|
|
25553
|
+
if (entry.enabled !== true) return fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + lock, OMP_ENABLE_COMMAND);
|
|
25554
|
+
return { ...pass2("D3"), detail: lock };
|
|
25555
|
+
}
|
|
25556
|
+
function ompInfoLines(env, version2) {
|
|
25557
|
+
const out = [];
|
|
25558
|
+
if (version2 !== void 0 && compareVersions(version2, OMP_MIN_VERSION) === -1) out.push(OMP_FLOOR_INFO(version2));
|
|
25559
|
+
out.push(OMP_CONTENT_INFO, OMP_PRINT_MODE_INFO, OMP_SCRIPTS_INFO);
|
|
25560
|
+
const home = homeDirOf(env);
|
|
25561
|
+
if (home === null) return out;
|
|
25562
|
+
const files = ompImportFiles(home);
|
|
25563
|
+
if (!ompImportsUs(files, env)) return out;
|
|
25564
|
+
const listed = readJson2(files.mcp)?.[OMP_DISABLED_SERVERS_KEY];
|
|
25565
|
+
if (!(Array.isArray(listed) && listed.includes(SERVER_KEY))) out.push(OMP_IMPORT_INFO(files.claude, files.mcp));
|
|
25566
|
+
return out;
|
|
25034
25567
|
}
|
|
25035
25568
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
25036
25569
|
const findings = detectV1(agent, home, scope);
|
|
25037
|
-
if (findings.length === 0) return
|
|
25570
|
+
if (findings.length === 0) return pass2("D4");
|
|
25038
25571
|
const detail = findings.map((f) => f.reason).join(D4_REASON_JOIN);
|
|
25039
|
-
if (findings.every((f) => f.reason === V1_REASON.tmpFile)) return { ...
|
|
25040
|
-
return { ...
|
|
25572
|
+
if (findings.every((f) => f.reason === V1_REASON.tmpFile)) return { ...pass2("D4"), detail };
|
|
25573
|
+
return { ...fail3("D4", detail, DOCTOR_FIX_UPGRADE), status: "WARN" };
|
|
25041
25574
|
}
|
|
25042
25575
|
function parsedOrNull(agent, file2, jsonc) {
|
|
25043
25576
|
try {
|
|
@@ -25048,13 +25581,13 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
25048
25581
|
}
|
|
25049
25582
|
}
|
|
25050
25583
|
function checkDoubleFire(agent, worktree) {
|
|
25051
|
-
if (agent !== "claude-code" && agent !== "vscode") return
|
|
25052
|
-
const claude = parsedOrNull(agent,
|
|
25584
|
+
if (agent !== "claude-code" && agent !== "vscode") return pass2("D5b");
|
|
25585
|
+
const claude = parsedOrNull(agent, join16(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
25053
25586
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
25054
25587
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
25055
|
-
const vscode = parsedOrNull(agent,
|
|
25588
|
+
const vscode = parsedOrNull(agent, join16(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
25056
25589
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
25057
|
-
return hooksOn && useClaudeHooks ?
|
|
25590
|
+
return hooksOn && useClaudeHooks ? fail3("D5b", D5B_DETAIL, D5B_FIX) : pass2("D5b");
|
|
25058
25591
|
}
|
|
25059
25592
|
function configPaths(row5, env, worktree) {
|
|
25060
25593
|
const home = homeDirOf(env);
|
|
@@ -25063,7 +25596,7 @@ function configPaths(row5, env, worktree) {
|
|
|
25063
25596
|
const mcp = mcpFile(row5, home, env);
|
|
25064
25597
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
25065
25598
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
25066
|
-
if (native !== null) out.push({ label: "Codex plugin MCP", path:
|
|
25599
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join16(native, CODEX_PLUGIN_MCP_FILE) });
|
|
25067
25600
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
25068
25601
|
if (spec !== null) {
|
|
25069
25602
|
try {
|
|
@@ -25083,10 +25616,10 @@ function configPaths(row5, env, worktree) {
|
|
|
25083
25616
|
}
|
|
25084
25617
|
|
|
25085
25618
|
// src/core/ops/doctor-db.ts
|
|
25086
|
-
import { existsSync as
|
|
25087
|
-
var
|
|
25088
|
-
var
|
|
25089
|
-
var
|
|
25619
|
+
import { existsSync as existsSync12, statSync as statSync6 } from "node:fs";
|
|
25620
|
+
var unknown3 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
|
|
25621
|
+
var pass3 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
|
|
25622
|
+
var fail4 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
25090
25623
|
function isCorrupt2(err) {
|
|
25091
25624
|
if (typeof err !== "object" || err === null) return false;
|
|
25092
25625
|
const code = err.errcode;
|
|
@@ -25125,17 +25658,17 @@ function orphanFiles(dbPath) {
|
|
|
25125
25658
|
const files = [];
|
|
25126
25659
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
25127
25660
|
const path8 = dbPath + suffix;
|
|
25128
|
-
if (
|
|
25661
|
+
if (existsSync12(path8)) files.push({ path: path8, bytes: statSync6(path8).size });
|
|
25129
25662
|
}
|
|
25130
|
-
return files.length > 0 && !
|
|
25663
|
+
return files.length > 0 && !existsSync12(dbPath) ? files : [];
|
|
25131
25664
|
}
|
|
25132
25665
|
async function checkDb(project) {
|
|
25133
25666
|
const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
|
|
25134
25667
|
const orphan = orphanFiles(project.dbPath);
|
|
25135
|
-
if (orphan.length > 0) return { row:
|
|
25136
|
-
if (!
|
|
25668
|
+
if (orphan.length > 0) return { row: fail4(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
|
|
25669
|
+
if (!existsSync12(project.dbPath)) return { row: pass3("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
25137
25670
|
const sqlite = await loadSqlite2();
|
|
25138
|
-
if (sqlite === null) return { row:
|
|
25671
|
+
if (sqlite === null) return { row: unknown3("D8", D2_SQLITE_DETAIL), ...clean };
|
|
25139
25672
|
let raw = null;
|
|
25140
25673
|
try {
|
|
25141
25674
|
raw = openRead(sqlite, project.dbPath);
|
|
@@ -25148,226 +25681,35 @@ async function checkDb(project) {
|
|
|
25148
25681
|
}
|
|
25149
25682
|
const schemaStale = got !== null && got !== SCHEMA_VERSION;
|
|
25150
25683
|
const integrityFailed = failsOnCorrupt(() => !integrityOk(db));
|
|
25151
|
-
if (integrityFailed) return { row:
|
|
25152
|
-
if (schemaStale && got !== null) return { row:
|
|
25153
|
-
return { row:
|
|
25684
|
+
if (integrityFailed) return { row: fail4(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale, integrityFailed, orphan: [] };
|
|
25685
|
+
if (schemaStale && got !== null) return { row: fail4(D8_STALE_SCHEMA_DETAIL(got, SCHEMA_VERSION), DOCTOR_FIX_UPGRADE), schemaStale, integrityFailed, orphan: [] };
|
|
25686
|
+
return { row: pass3("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
25154
25687
|
} catch (err) {
|
|
25155
|
-
if (isCorrupt2(err)) return { row:
|
|
25156
|
-
return { row:
|
|
25688
|
+
if (isCorrupt2(err)) return { row: fail4(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale: false, integrityFailed: true, orphan: [] };
|
|
25689
|
+
return { row: unknown3("D8", message2(err)), ...clean };
|
|
25157
25690
|
} finally {
|
|
25158
25691
|
raw?.close();
|
|
25159
25692
|
}
|
|
25160
25693
|
}
|
|
25161
25694
|
async function checkIndex(project) {
|
|
25162
|
-
if (!
|
|
25695
|
+
if (!existsSync12(project.dbPath)) return pass3("D9", D9_INDEX_DETAIL(0, 0));
|
|
25163
25696
|
const sqlite = await loadSqlite2();
|
|
25164
|
-
if (sqlite === null) return
|
|
25697
|
+
if (sqlite === null) return unknown3("D9", D2_SQLITE_DETAIL);
|
|
25165
25698
|
let raw = null;
|
|
25166
25699
|
try {
|
|
25167
25700
|
raw = openRead(sqlite, project.dbPath);
|
|
25168
25701
|
const sources = Number(cell(raw.prepare("SELECT count(*) FROM sources").get()));
|
|
25169
25702
|
const chunks = Number(cell(raw.prepare("SELECT count(*) FROM chunks").get()));
|
|
25170
|
-
return
|
|
25703
|
+
return pass3("D9", D9_INDEX_DETAIL(sources, chunks));
|
|
25171
25704
|
} catch (err) {
|
|
25172
|
-
return
|
|
25705
|
+
return unknown3("D9", message2(err));
|
|
25173
25706
|
} finally {
|
|
25174
25707
|
raw?.close();
|
|
25175
25708
|
}
|
|
25176
25709
|
}
|
|
25177
25710
|
|
|
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
25711
|
// src/core/ops/doctor-hook.ts
|
|
25370
|
-
import { existsSync as
|
|
25712
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync4, mkdtempSync, readFileSync as readFileSync14, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
25371
25713
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
25372
25714
|
import path7 from "node:path";
|
|
25373
25715
|
|
|
@@ -27111,7 +27453,9 @@ var HOST_SHAPES = {
|
|
|
27111
27453
|
kiro: kiro_default,
|
|
27112
27454
|
zcode: zcode_default,
|
|
27113
27455
|
pi: pi_default,
|
|
27114
|
-
opencode: opencode_default
|
|
27456
|
+
opencode: opencode_default,
|
|
27457
|
+
omp: pi_default
|
|
27458
|
+
// ADR-0026: OMP reads the Pi extension reply
|
|
27115
27459
|
};
|
|
27116
27460
|
var NOTE_KEYS = /* @__PURE__ */ new Set(["$schema", "title", "description", "definitions", "default"]);
|
|
27117
27461
|
var RULE_KEYS = /* @__PURE__ */ new Set(["type", "enum", "const", "required", "properties", "additionalProperties", "items", "allOf", "$ref"]);
|
|
@@ -27193,13 +27537,13 @@ function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.e
|
|
|
27193
27537
|
|
|
27194
27538
|
// src/setup/codex-trust.ts
|
|
27195
27539
|
import { createHash } from "node:crypto";
|
|
27196
|
-
import { existsSync as
|
|
27540
|
+
import { existsSync as existsSync13, realpathSync as realpathSync7 } from "node:fs";
|
|
27197
27541
|
import path6 from "node:path";
|
|
27198
27542
|
import { spawn as spawn3, spawnSync as spawnSync2 } from "node:child_process";
|
|
27199
27543
|
|
|
27200
27544
|
// src/setup/spawn-bin.ts
|
|
27201
27545
|
import { spawnSync } from "node:child_process";
|
|
27202
|
-
import { accessSync as accessSync2, constants as fsc, statSync as
|
|
27546
|
+
import { accessSync as accessSync2, constants as fsc, statSync as statSync7 } from "node:fs";
|
|
27203
27547
|
import path5 from "node:path";
|
|
27204
27548
|
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
27205
27549
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
@@ -27217,7 +27561,7 @@ function whichBin(bin, env, platform = process.platform) {
|
|
|
27217
27561
|
const f = path5.join(dir, n);
|
|
27218
27562
|
try {
|
|
27219
27563
|
accessSync2(f, fsc.X_OK);
|
|
27220
|
-
if (
|
|
27564
|
+
if (statSync7(f).isFile()) return f;
|
|
27221
27565
|
} catch {
|
|
27222
27566
|
}
|
|
27223
27567
|
}
|
|
@@ -27416,10 +27760,10 @@ function isObject6(v) {
|
|
|
27416
27760
|
}
|
|
27417
27761
|
function loadFixture(bundleDir2, agent) {
|
|
27418
27762
|
const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
27419
|
-
if (!
|
|
27763
|
+
if (!existsSync14(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
27420
27764
|
let all;
|
|
27421
27765
|
try {
|
|
27422
|
-
all = JSON.parse(hostText(
|
|
27766
|
+
all = JSON.parse(hostText(readFileSync14(file2, "utf8")));
|
|
27423
27767
|
} catch (err) {
|
|
27424
27768
|
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
27425
27769
|
}
|
|
@@ -27441,7 +27785,8 @@ var CWD_KEY = {
|
|
|
27441
27785
|
kiro: "cwd",
|
|
27442
27786
|
zcode: "cwd",
|
|
27443
27787
|
pi: "cwd",
|
|
27444
|
-
opencode: "directory"
|
|
27788
|
+
opencode: "directory",
|
|
27789
|
+
omp: "cwd"
|
|
27445
27790
|
};
|
|
27446
27791
|
function payloadFor(agent, payload, worktree) {
|
|
27447
27792
|
return worktree !== void 0 && isObject6(payload) ? { ...payload, [CWD_KEY[agent]]: worktree } : payload;
|
|
@@ -27633,7 +27978,7 @@ async function codexStopDetail(i, timeoutMs) {
|
|
|
27633
27978
|
timeoutMs,
|
|
27634
27979
|
stdin: JSON.stringify(codexStopPayload(i.worktree ?? home))
|
|
27635
27980
|
});
|
|
27636
|
-
const logged =
|
|
27981
|
+
const logged = existsSync14(path7.join(home, HOOK_ERROR_LOG_FILE));
|
|
27637
27982
|
return !logged && isNativeShape(i.agent, r.stdout.toString("utf8"), r.exitCode, r.killed, "Stop") ? null : D5_STOP_DETAIL;
|
|
27638
27983
|
} finally {
|
|
27639
27984
|
rmSync2(home, { recursive: true, force: true });
|
|
@@ -27644,7 +27989,7 @@ async function checkHookRoundTrip(i) {
|
|
|
27644
27989
|
const trust = await codexPluginTrust(i);
|
|
27645
27990
|
if (trust !== null) return trust;
|
|
27646
27991
|
}
|
|
27647
|
-
if (i.agent === "codex" &&
|
|
27992
|
+
if (i.agent === "codex" && existsSync14(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
27648
27993
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
27649
27994
|
}
|
|
27650
27995
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
@@ -27693,16 +28038,16 @@ async function checkHookRoundTrip(i) {
|
|
|
27693
28038
|
}
|
|
27694
28039
|
|
|
27695
28040
|
// src/core/ops/db-heal.ts
|
|
27696
|
-
import { existsSync as
|
|
27697
|
-
import { basename as basename4, dirname as dirname9, join as
|
|
28041
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync6, rmSync as rmSync4 } from "node:fs";
|
|
28042
|
+
import { basename as basename4, dirname as dirname9, join as join18 } from "node:path";
|
|
27698
28043
|
|
|
27699
28044
|
// src/core/store/owners.ts
|
|
27700
|
-
import { mkdirSync as mkdirSync5, readdirSync as readdirSync7, readFileSync as
|
|
27701
|
-
import { basename as basename3, join as
|
|
28045
|
+
import { mkdirSync as mkdirSync5, readdirSync as readdirSync7, readFileSync as readFileSync15, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
28046
|
+
import { basename as basename3, join as join17 } from "node:path";
|
|
27702
28047
|
function ownersDir(configDir, projectKey) {
|
|
27703
|
-
return
|
|
28048
|
+
return join17(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
27704
28049
|
}
|
|
27705
|
-
function
|
|
28050
|
+
function errCode3(err) {
|
|
27706
28051
|
return err.code;
|
|
27707
28052
|
}
|
|
27708
28053
|
function isLive(pid) {
|
|
@@ -27711,8 +28056,8 @@ function isLive(pid) {
|
|
|
27711
28056
|
process.kill(pid, 0);
|
|
27712
28057
|
return true;
|
|
27713
28058
|
} catch (err) {
|
|
27714
|
-
if (
|
|
27715
|
-
if (
|
|
28059
|
+
if (errCode3(err) === "ESRCH") return false;
|
|
28060
|
+
if (errCode3(err) === "EPERM") return true;
|
|
27716
28061
|
throw err;
|
|
27717
28062
|
}
|
|
27718
28063
|
}
|
|
@@ -27722,18 +28067,18 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
27722
28067
|
try {
|
|
27723
28068
|
names = readdirSync7(dir);
|
|
27724
28069
|
} catch (err) {
|
|
27725
|
-
if (
|
|
28070
|
+
if (errCode3(err) === "ENOENT") return [];
|
|
27726
28071
|
throw err;
|
|
27727
28072
|
}
|
|
27728
28073
|
const live = [];
|
|
27729
28074
|
for (const name of names) {
|
|
27730
28075
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
27731
|
-
const file2 =
|
|
28076
|
+
const file2 = join17(dir, name);
|
|
27732
28077
|
let text;
|
|
27733
28078
|
try {
|
|
27734
|
-
text =
|
|
28079
|
+
text = readFileSync15(file2, "utf8");
|
|
27735
28080
|
} catch (err) {
|
|
27736
|
-
if (
|
|
28081
|
+
if (errCode3(err) === "ENOENT") continue;
|
|
27737
28082
|
throw err;
|
|
27738
28083
|
}
|
|
27739
28084
|
const serverId = basename3(name, OWNER_PID_EXT);
|
|
@@ -27777,7 +28122,7 @@ function renameAside(dbPath) {
|
|
|
27777
28122
|
const ts = String(Date.now());
|
|
27778
28123
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
27779
28124
|
const file2 = dbPath + suffix;
|
|
27780
|
-
if (
|
|
28125
|
+
if (existsSync15(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
27781
28126
|
}
|
|
27782
28127
|
return ts;
|
|
27783
28128
|
}
|
|
@@ -27800,7 +28145,7 @@ function utcStamp(now) {
|
|
|
27800
28145
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
27801
28146
|
}
|
|
27802
28147
|
function makeOrphanDir(projectDir) {
|
|
27803
|
-
const base =
|
|
28148
|
+
const base = join18(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
27804
28149
|
for (let n = 1; ; n += 1) {
|
|
27805
28150
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
27806
28151
|
try {
|
|
@@ -27817,7 +28162,7 @@ async function healOrphan(project, files, row5) {
|
|
|
27817
28162
|
try {
|
|
27818
28163
|
dir = makeOrphanDir(dirname9(project.dbPath));
|
|
27819
28164
|
for (const f of files) {
|
|
27820
|
-
const to =
|
|
28165
|
+
const to = join18(dir, basename4(f.path));
|
|
27821
28166
|
renameWithRetry(f.path, to);
|
|
27822
28167
|
moved.push({ path: to, bytes: f.bytes });
|
|
27823
28168
|
}
|
|
@@ -27835,8 +28180,8 @@ function keyIsTyped(key) {
|
|
|
27835
28180
|
if (key.length === 0) return false;
|
|
27836
28181
|
for (const ch of key) {
|
|
27837
28182
|
const upper = ch >= "A" && ch <= "Z";
|
|
27838
|
-
const
|
|
27839
|
-
if (!upper && !
|
|
28183
|
+
const digit2 = ch >= "0" && ch <= "9";
|
|
28184
|
+
if (!upper && !digit2 && ch !== "_") return false;
|
|
27840
28185
|
}
|
|
27841
28186
|
return true;
|
|
27842
28187
|
}
|
|
@@ -27915,8 +28260,8 @@ function unsupportedHostOf(sig) {
|
|
|
27915
28260
|
|
|
27916
28261
|
// src/core/ops/doctor-issue.ts
|
|
27917
28262
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
27918
|
-
import { closeSync as closeSync2, existsSync as
|
|
27919
|
-
import { delimiter, dirname as dirname10, join as
|
|
28263
|
+
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";
|
|
28264
|
+
import { delimiter, dirname as dirname10, join as join19 } from "node:path";
|
|
27920
28265
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
27921
28266
|
function tildeOf(env) {
|
|
27922
28267
|
const home = homeDirOf(env);
|
|
@@ -27972,8 +28317,8 @@ function onPath(env, tool) {
|
|
|
27972
28317
|
const out = [];
|
|
27973
28318
|
for (const dir of (envValue(env, "PATH") ?? "").split(delimiter)) {
|
|
27974
28319
|
if (dir === "") continue;
|
|
27975
|
-
for (const n of names) if (
|
|
27976
|
-
out.push(
|
|
28320
|
+
for (const n of names) if (existsSync16(join19(dir, n))) {
|
|
28321
|
+
out.push(join19(dir, n));
|
|
27977
28322
|
break;
|
|
27978
28323
|
}
|
|
27979
28324
|
}
|
|
@@ -27981,7 +28326,7 @@ function onPath(env, tool) {
|
|
|
27981
28326
|
}
|
|
27982
28327
|
function hookLogTail(env) {
|
|
27983
28328
|
const file2 = hookLogPath(env);
|
|
27984
|
-
if (file2 === "" || !
|
|
28329
|
+
if (file2 === "" || !existsSync16(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
27985
28330
|
try {
|
|
27986
28331
|
const fd = openSync2(file2, "r");
|
|
27987
28332
|
try {
|
|
@@ -28001,7 +28346,7 @@ function hookLogTail(env) {
|
|
|
28001
28346
|
}
|
|
28002
28347
|
async function journalRows(ctx) {
|
|
28003
28348
|
const head2 = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
28004
|
-
if (!
|
|
28349
|
+
if (!existsSync16(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
28005
28350
|
try {
|
|
28006
28351
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
28007
28352
|
try {
|
|
@@ -28019,21 +28364,21 @@ function agentConfig(adapter, env, worktree) {
|
|
|
28019
28364
|
const home = homeDirOf(env);
|
|
28020
28365
|
const files = configPaths(adapter, env, worktree);
|
|
28021
28366
|
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:
|
|
28367
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join19(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
28368
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join19(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
28024
28369
|
}
|
|
28025
28370
|
const out = [];
|
|
28026
28371
|
const seen = /* @__PURE__ */ new Set();
|
|
28027
28372
|
for (const f of files) {
|
|
28028
28373
|
if (seen.has(f.path)) continue;
|
|
28029
28374
|
seen.add(f.path);
|
|
28030
|
-
if (!
|
|
28375
|
+
if (!existsSync16(f.path)) {
|
|
28031
28376
|
out.push(`${f.label}: ${f.path} (absent)`);
|
|
28032
28377
|
continue;
|
|
28033
28378
|
}
|
|
28034
28379
|
let text = "";
|
|
28035
28380
|
try {
|
|
28036
|
-
text =
|
|
28381
|
+
text = readFileSync16(f.path, "utf8");
|
|
28037
28382
|
} catch (err) {
|
|
28038
28383
|
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
28039
28384
|
continue;
|
|
@@ -28104,9 +28449,9 @@ async function buildIssueBody(i) {
|
|
|
28104
28449
|
async function writeIssueReport(i) {
|
|
28105
28450
|
const tilde = tildeOf(i.env);
|
|
28106
28451
|
const body = await buildIssueBody(i);
|
|
28107
|
-
const dir =
|
|
28452
|
+
const dir = join19(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
28108
28453
|
mkdirSync7(dir, { recursive: true });
|
|
28109
|
-
const file2 =
|
|
28454
|
+
const file2 = join19(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
28110
28455
|
writeFileSync4(file2, body);
|
|
28111
28456
|
const shown2 = tilde(file2);
|
|
28112
28457
|
const title = issueTitle(i.adapter.id, i.rows, i.unsupported);
|
|
@@ -28133,7 +28478,7 @@ async function guard(id2, run) {
|
|
|
28133
28478
|
}
|
|
28134
28479
|
}
|
|
28135
28480
|
async function codexDb(ctx, adapter) {
|
|
28136
|
-
if (adapter.id !== "codex" || !
|
|
28481
|
+
if (adapter.id !== "codex" || !existsSync17(ctx.project.dbPath)) return null;
|
|
28137
28482
|
try {
|
|
28138
28483
|
return await openDb(ctx.project, { readOnly: true });
|
|
28139
28484
|
} catch {
|
|
@@ -28169,11 +28514,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
28169
28514
|
}
|
|
28170
28515
|
}
|
|
28171
28516
|
function ownServerId(configDir, projectKey) {
|
|
28172
|
-
const dir =
|
|
28173
|
-
if (!
|
|
28517
|
+
const dir = join20(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
28518
|
+
if (!existsSync17(dir)) return "";
|
|
28174
28519
|
for (const name of readdirSync8(dir)) {
|
|
28175
28520
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
28176
|
-
if (
|
|
28521
|
+
if (readFileSync17(join20(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
28177
28522
|
}
|
|
28178
28523
|
return "";
|
|
28179
28524
|
}
|
|
@@ -28203,7 +28548,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
28203
28548
|
D9: () => checkIndex(project),
|
|
28204
28549
|
D10: () => checkMode(adapter, ctx.hostPermission),
|
|
28205
28550
|
// D-1331-OC-PERM-1
|
|
28206
|
-
D11: () => checkShell(env)
|
|
28551
|
+
D11: () => checkRuntimes(env, checkShell(env))
|
|
28207
28552
|
};
|
|
28208
28553
|
const rows = [];
|
|
28209
28554
|
for (const id2 of DOCTOR_CHECK_ORDER) rows.push(await guard(id2, checks[id2]));
|
|
@@ -28233,7 +28578,7 @@ async function doctorReply(ctx, host) {
|
|
|
28233
28578
|
const runtime = runtimeInfo(host.env, ctx.signal);
|
|
28234
28579
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
28235
28580
|
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}`;
|
|
28581
|
+
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
28582
|
const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
|
|
28238
28583
|
const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir), await runtime);
|
|
28239
28584
|
const table3 = buildReport(input);
|
|
@@ -28247,7 +28592,8 @@ async function doctorReply(ctx, host) {
|
|
|
28247
28592
|
}
|
|
28248
28593
|
const look = rows.find((r) => r.status === "FAIL") ?? rows.find((r) => r.status !== "PASS");
|
|
28249
28594
|
const docs = look === void 0 ? [] : [DOCTOR_DOCS_LABEL + DOCTOR_DOCS_LINK(look.id)];
|
|
28250
|
-
const
|
|
28595
|
+
const info = adapter.id === "omp" ? ompInfoLines(host.env, ctx.clientInfo?.version) : [];
|
|
28596
|
+
const whole2 = [envLine2, table3, ...docs, ...info, ...notes].join("\n");
|
|
28251
28597
|
const bytes5 = Buffer.byteLength(whole2, "utf8");
|
|
28252
28598
|
if (bytes5 <= REPORT_CAP) return { text: whole2, isError: false, sandboxBytes: bytes5 };
|
|
28253
28599
|
const db = await openDb(ctx.project);
|
|
@@ -28256,9 +28602,14 @@ async function doctorReply(ctx, host) {
|
|
|
28256
28602
|
} finally {
|
|
28257
28603
|
closeDb(db);
|
|
28258
28604
|
}
|
|
28259
|
-
const text = [envLine2, buildReportHead(input), ...docs, ...notes].join("\n");
|
|
28605
|
+
const text = [envLine2, buildReportHead(input), ...docs, ...info, ...notes].join("\n");
|
|
28260
28606
|
return { text, isError: false, sandboxBytes: bytes5 };
|
|
28261
28607
|
}
|
|
28608
|
+
function ompCommand(rows, failed) {
|
|
28609
|
+
if (!failed) return OMP_LIST_COMMAND;
|
|
28610
|
+
const d3 = rows.find((r) => r.id === "D3" && r.status === "FAIL");
|
|
28611
|
+
return d3?.fixCommand ?? NATIVE_INSTALL.omp[0];
|
|
28612
|
+
}
|
|
28262
28613
|
async function handler2(_input, ctx) {
|
|
28263
28614
|
return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: ctx.piCwd });
|
|
28264
28615
|
}
|
|
@@ -28272,9 +28623,9 @@ var ctxDoctor = Object.freeze({
|
|
|
28272
28623
|
});
|
|
28273
28624
|
|
|
28274
28625
|
// src/core/tools/execute.ts
|
|
28275
|
-
import { existsSync as
|
|
28626
|
+
import { existsSync as existsSync18, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
28276
28627
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
28277
|
-
import { dirname as dirname12, join as
|
|
28628
|
+
import { dirname as dirname12, join as join21, parse as parse3, resolve as resolve11 } from "node:path";
|
|
28278
28629
|
|
|
28279
28630
|
// src/core/sandbox/win-build.ts
|
|
28280
28631
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -28357,7 +28708,7 @@ function schemaLine(issue2) {
|
|
|
28357
28708
|
}
|
|
28358
28709
|
function fileError(given, abs, root) {
|
|
28359
28710
|
let dir = abs;
|
|
28360
|
-
while (!
|
|
28711
|
+
while (!existsSync18(dir) && dirname12(dir) !== dir) dir = dirname12(dir);
|
|
28361
28712
|
if (isInside(root, dir)) return null;
|
|
28362
28713
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
28363
28714
|
}
|
|
@@ -28426,7 +28777,12 @@ async function handler3(raw, ctx) {
|
|
|
28426
28777
|
if (bad !== null) return fail5(bad);
|
|
28427
28778
|
extra.CTX_FILE = abs;
|
|
28428
28779
|
}
|
|
28429
|
-
|
|
28780
|
+
let runtime;
|
|
28781
|
+
try {
|
|
28782
|
+
runtime = findRuntime(input.language);
|
|
28783
|
+
} catch {
|
|
28784
|
+
runtime = null;
|
|
28785
|
+
}
|
|
28430
28786
|
if (runtime === null) return fail5(noRuntimeError(input.language).toLine());
|
|
28431
28787
|
const env = buildChildEnv(process.env, extra);
|
|
28432
28788
|
const timeoutMs = input.timeoutMs ?? EXEC_TIMEOUT_MS;
|
|
@@ -28438,8 +28794,8 @@ async function handler3(raw, ctx) {
|
|
|
28438
28794
|
if (takesDashC(input.language, runtime)) {
|
|
28439
28795
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
28440
28796
|
} else {
|
|
28441
|
-
tmpDir = mkdtempSync2(
|
|
28442
|
-
const file2 =
|
|
28797
|
+
tmpDir = mkdtempSync2(join21(tmpdir3(), TMP_PREFIX));
|
|
28798
|
+
const file2 = join21(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
28443
28799
|
writeFileSync5(file2, scriptText(input.language, input.code), "utf8");
|
|
28444
28800
|
argv = scriptArgv(input.language, runtime, file2);
|
|
28445
28801
|
}
|
|
@@ -28475,12 +28831,12 @@ var ctxExecute = {
|
|
|
28475
28831
|
};
|
|
28476
28832
|
|
|
28477
28833
|
// src/core/tools/index.ts
|
|
28478
|
-
import { existsSync as
|
|
28479
|
-
import { dirname as dirname13, extname as extname3, join as
|
|
28834
|
+
import { existsSync as existsSync19, readFileSync as readFileSync20, statSync as statSync9 } from "node:fs";
|
|
28835
|
+
import { dirname as dirname13, extname as extname3, join as join24, relative as relative5, resolve as resolve12 } from "node:path";
|
|
28480
28836
|
|
|
28481
28837
|
// src/core/index/walk.ts
|
|
28482
|
-
import { readdirSync as readdirSync9, readFileSync as
|
|
28483
|
-
import { join as
|
|
28838
|
+
import { readdirSync as readdirSync9, readFileSync as readFileSync18, realpathSync as realpathSync10, statSync as statSync8 } from "node:fs";
|
|
28839
|
+
import { join as join22 } from "node:path";
|
|
28484
28840
|
var GITIGNORE = ".gitignore";
|
|
28485
28841
|
var GIT_DIR = ".git";
|
|
28486
28842
|
function walkDir(root, containmentRoot) {
|
|
@@ -28489,7 +28845,7 @@ function walkDir(root, containmentRoot) {
|
|
|
28489
28845
|
const found = [];
|
|
28490
28846
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
28491
28847
|
found.sort(compareFound);
|
|
28492
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
28848
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join22(...f.dir, f.name) }));
|
|
28493
28849
|
}
|
|
28494
28850
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
28495
28851
|
let entries;
|
|
@@ -28498,10 +28854,10 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
28498
28854
|
} catch {
|
|
28499
28855
|
return;
|
|
28500
28856
|
}
|
|
28501
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
28857
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join22(abs, GITIGNORE), rel)) : parent;
|
|
28502
28858
|
for (const e of entries) {
|
|
28503
28859
|
if (e.name === GIT_DIR) continue;
|
|
28504
|
-
const path8 =
|
|
28860
|
+
const path8 = join22(abs, e.name);
|
|
28505
28861
|
let isDir = e.isDirectory();
|
|
28506
28862
|
let isFile = e.isFile();
|
|
28507
28863
|
let target = path8;
|
|
@@ -28513,7 +28869,7 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
28513
28869
|
continue;
|
|
28514
28870
|
}
|
|
28515
28871
|
if (!isInside(contain, resolved)) continue;
|
|
28516
|
-
const st =
|
|
28872
|
+
const st = statSync8(resolved);
|
|
28517
28873
|
isDir = st.isDirectory();
|
|
28518
28874
|
isFile = st.isFile();
|
|
28519
28875
|
target = resolved;
|
|
@@ -28541,7 +28897,7 @@ function compareFound(a, b) {
|
|
|
28541
28897
|
function readRules(file2, base) {
|
|
28542
28898
|
let body;
|
|
28543
28899
|
try {
|
|
28544
|
-
body =
|
|
28900
|
+
body = readFileSync18(file2, "utf8");
|
|
28545
28901
|
} catch {
|
|
28546
28902
|
return [];
|
|
28547
28903
|
}
|
|
@@ -28624,10 +28980,12 @@ function globSeg(pat, name) {
|
|
|
28624
28980
|
}
|
|
28625
28981
|
|
|
28626
28982
|
// src/core/sandbox/fetch.ts
|
|
28983
|
+
import { readFileSync as readFileSync19 } from "node:fs";
|
|
28627
28984
|
import { lookup } from "node:dns/promises";
|
|
28628
28985
|
import http from "node:http";
|
|
28629
28986
|
import https from "node:https";
|
|
28630
28987
|
import { BlockList, isIP } from "node:net";
|
|
28988
|
+
import { join as join23 } from "node:path";
|
|
28631
28989
|
import { connect as tlsConnect } from "node:tls";
|
|
28632
28990
|
var PRIVATE_RANGES = [
|
|
28633
28991
|
["127.0.0.0", 8, "ipv4"],
|
|
@@ -28659,6 +29017,21 @@ for (const [net, prefix, type] of PRIVATE_RANGES) BLOCKED.addSubnet(net, prefix,
|
|
|
28659
29017
|
var STATUS_OK_FIRST = 200;
|
|
28660
29018
|
var STATUS_OK_END = 300;
|
|
28661
29019
|
var STATUS_REDIRECT = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
29020
|
+
var UA_HOME = "https://github.com/mksglu/context-mode";
|
|
29021
|
+
var UA_DEV_VERSION = "dev";
|
|
29022
|
+
var namedHeaders;
|
|
29023
|
+
function baseHeaders() {
|
|
29024
|
+
if (namedHeaders === void 0) {
|
|
29025
|
+
let version2 = UA_DEV_VERSION;
|
|
29026
|
+
try {
|
|
29027
|
+
const v = JSON.parse(readFileSync19(join23(ownBundleDir(), D1_PACKAGE_FILE), "utf8")).version;
|
|
29028
|
+
if (typeof v === "string" && v !== "") version2 = v;
|
|
29029
|
+
} catch {
|
|
29030
|
+
}
|
|
29031
|
+
namedHeaders = Object.freeze({ "user-agent": "context-mode/" + version2 + " (+" + UA_HOME + ")", accept: "*/*" });
|
|
29032
|
+
}
|
|
29033
|
+
return namedHeaders;
|
|
29034
|
+
}
|
|
28662
29035
|
function fail6(code) {
|
|
28663
29036
|
return new CtxError("FETCH_FAILED", { code });
|
|
28664
29037
|
}
|
|
@@ -28767,11 +29140,11 @@ function request(u, conn, proxy, signal) {
|
|
|
28767
29140
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
28768
29141
|
if (proxy === void 0) {
|
|
28769
29142
|
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 } });
|
|
29143
|
+
const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { ...baseHeaders(), host: u.host } });
|
|
28771
29144
|
req.on("response", resolve14).on("error", onErr).end();
|
|
28772
29145
|
return;
|
|
28773
29146
|
}
|
|
28774
|
-
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
29147
|
+
const proxyHeaders = proxy.auth === void 0 ? { ...baseHeaders() } : { ...baseHeaders(), "proxy-authorization": proxy.auth };
|
|
28775
29148
|
if (u.protocol === "http:") {
|
|
28776
29149
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
28777
29150
|
req.on("response", resolve14).on("error", onErr).end();
|
|
@@ -28791,7 +29164,7 @@ function request(u, conn, proxy, signal) {
|
|
|
28791
29164
|
port,
|
|
28792
29165
|
path: path8,
|
|
28793
29166
|
signal,
|
|
28794
|
-
headers: { host: u.host },
|
|
29167
|
+
headers: { ...baseHeaders(), host: u.host },
|
|
28795
29168
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
28796
29169
|
});
|
|
28797
29170
|
req.on("response", resolve14).on("error", onErr).end();
|
|
@@ -28833,7 +29206,7 @@ async function safeFetch(url2, signal) {
|
|
|
28833
29206
|
}
|
|
28834
29207
|
if (status < STATUS_OK_FIRST || status >= STATUS_OK_END) {
|
|
28835
29208
|
res.resume();
|
|
28836
|
-
throw fail6(status);
|
|
29209
|
+
throw fail6(status + " from " + bare(current.hostname));
|
|
28837
29210
|
}
|
|
28838
29211
|
const body = await readBody(res);
|
|
28839
29212
|
const shown2 = new URL(current.href);
|
|
@@ -29199,8 +29572,8 @@ var EntityDecoder = class {
|
|
|
29199
29572
|
while (offset < inputLength) {
|
|
29200
29573
|
const char = input.charCodeAt(offset);
|
|
29201
29574
|
if (isNumber2(char) || isHexadecimalCharacter(char)) {
|
|
29202
|
-
const
|
|
29203
|
-
result = result * 16 +
|
|
29575
|
+
const digit2 = char <= CharCodes.NINE ? char - CharCodes.ZERO : (char | TO_LOWER_BIT) - CharCodes.LOWER_A + 10;
|
|
29576
|
+
result = result * 16 + digit2;
|
|
29204
29577
|
consumed += 1;
|
|
29205
29578
|
offset += 1;
|
|
29206
29579
|
} else {
|
|
@@ -29228,13 +29601,13 @@ var EntityDecoder = class {
|
|
|
29228
29601
|
let { result } = this;
|
|
29229
29602
|
let { consumed } = this;
|
|
29230
29603
|
while (offset < inputLength) {
|
|
29231
|
-
const
|
|
29232
|
-
if (
|
|
29604
|
+
const digit2 = input.charCodeAt(offset) - CharCodes.ZERO;
|
|
29605
|
+
if (digit2 >>> 0 > 9) {
|
|
29233
29606
|
this.result = result;
|
|
29234
29607
|
this.consumed = consumed;
|
|
29235
|
-
return this.emitNumericEntity(
|
|
29608
|
+
return this.emitNumericEntity(digit2 + CharCodes.ZERO, 2);
|
|
29236
29609
|
}
|
|
29237
|
-
result = result * 10 +
|
|
29610
|
+
result = result * 10 + digit2;
|
|
29238
29611
|
consumed += 1;
|
|
29239
29612
|
offset += 1;
|
|
29240
29613
|
}
|
|
@@ -32669,14 +33042,14 @@ function kindOfType(contentType) {
|
|
|
32669
33042
|
}
|
|
32670
33043
|
function readUtf8(absPath) {
|
|
32671
33044
|
try {
|
|
32672
|
-
return utf8.decode(
|
|
33045
|
+
return utf8.decode(readFileSync20(absPath));
|
|
32673
33046
|
} catch {
|
|
32674
33047
|
return void 0;
|
|
32675
33048
|
}
|
|
32676
33049
|
}
|
|
32677
33050
|
function missingOrOutside(given, abs, root) {
|
|
32678
33051
|
let dir = abs;
|
|
32679
|
-
while (!
|
|
33052
|
+
while (!existsSync19(dir) && dirname13(dir) !== dir) dir = dirname13(dir);
|
|
32680
33053
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
32681
33054
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
32682
33055
|
}
|
|
@@ -32684,10 +33057,10 @@ function pathItems(input, project) {
|
|
|
32684
33057
|
const abs = resolve12(project.worktree, input.path);
|
|
32685
33058
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
32686
33059
|
const base = relative5(project.worktree, abs);
|
|
32687
|
-
if (
|
|
33060
|
+
if (statSync9(abs).isDirectory()) {
|
|
32688
33061
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
32689
33062
|
sourceKind: "path",
|
|
32690
|
-
label: pathLabel(
|
|
33063
|
+
label: pathLabel(join24(base, f.relPath)),
|
|
32691
33064
|
kind: kindOfPath(f.relPath),
|
|
32692
33065
|
read: () => readUtf8(f.absPath)
|
|
32693
33066
|
}));
|
|
@@ -33227,8 +33600,8 @@ var ctxStats = Object.freeze({
|
|
|
33227
33600
|
});
|
|
33228
33601
|
|
|
33229
33602
|
// src/core/ops/host-write.ts
|
|
33230
|
-
import { copyFileSync, existsSync as
|
|
33231
|
-
import { dirname as dirname14, join as
|
|
33603
|
+
import { copyFileSync, existsSync as existsSync20, mkdirSync as mkdirSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
33604
|
+
import { dirname as dirname14, join as join25 } from "node:path";
|
|
33232
33605
|
function defaultWrite(file2, text) {
|
|
33233
33606
|
writeFileSync6(file2, text, "utf8");
|
|
33234
33607
|
}
|
|
@@ -33237,17 +33610,20 @@ function hostConfigPath(agent, home, env) {
|
|
|
33237
33610
|
if (own2 !== void 0) return ownMcpFileOf(agent, own2.file, env, home);
|
|
33238
33611
|
switch (agent) {
|
|
33239
33612
|
case "opencode":
|
|
33240
|
-
return
|
|
33613
|
+
return join25(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
33241
33614
|
// D-WIN-OPENCODE-DIR-1
|
|
33242
33615
|
case "pi":
|
|
33243
|
-
return
|
|
33616
|
+
return join25(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
33244
33617
|
case "gemini":
|
|
33245
|
-
return
|
|
33618
|
+
return join25(geminiDirOf(env, home), SETTINGS_FILE);
|
|
33246
33619
|
// D-R38-GEMINI-HOME-1
|
|
33247
33620
|
case "copilot-cli":
|
|
33248
33621
|
return null;
|
|
33622
|
+
case "omp":
|
|
33623
|
+
return null;
|
|
33624
|
+
// ADR-0026 decision 8 (D-OMP-UPGRADE-1): OMP loads the plugin from its own store; no MCP entry, nothing under ~/.pi
|
|
33249
33625
|
default:
|
|
33250
|
-
return
|
|
33626
|
+
return join25(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
33251
33627
|
}
|
|
33252
33628
|
}
|
|
33253
33629
|
function cell3(value) {
|
|
@@ -33259,7 +33635,7 @@ function toRow(file2, edit) {
|
|
|
33259
33635
|
function writeWithRollback(file2, text, write2, atomic) {
|
|
33260
33636
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
33261
33637
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
33262
|
-
const had =
|
|
33638
|
+
const had = existsSync20(file2);
|
|
33263
33639
|
mkdirSync8(dirname14(file2), { recursive: true });
|
|
33264
33640
|
if (had) copyFileSync(file2, trash);
|
|
33265
33641
|
try {
|
|
@@ -33289,7 +33665,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
33289
33665
|
if (requested === null) return [];
|
|
33290
33666
|
const current = readHostConfig(row5.id, requested);
|
|
33291
33667
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
33292
|
-
const exists =
|
|
33668
|
+
const exists = existsSync20(current.path);
|
|
33293
33669
|
if (exists && result.text === current.text) return [];
|
|
33294
33670
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
33295
33671
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -33297,15 +33673,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
33297
33673
|
}
|
|
33298
33674
|
|
|
33299
33675
|
// src/core/ops/uninstall.ts
|
|
33300
|
-
import { existsSync as
|
|
33301
|
-
import { join as
|
|
33676
|
+
import { existsSync as existsSync21, readdirSync as readdirSync10, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
|
|
33677
|
+
import { join as join26 } from "node:path";
|
|
33302
33678
|
function row2(area, before, after) {
|
|
33303
33679
|
return { area, before, after };
|
|
33304
33680
|
}
|
|
33305
33681
|
function stopServers(configDir, projectKey) {
|
|
33306
33682
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
33307
|
-
const dir =
|
|
33308
|
-
for (const serverId of stopped) writeFileSync7(
|
|
33683
|
+
const dir = join26(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
33684
|
+
for (const serverId of stopped) writeFileSync7(join26(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
33309
33685
|
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
33686
|
}
|
|
33311
33687
|
function rootOrNull(adapter, env) {
|
|
@@ -33323,15 +33699,15 @@ function removeCache(adapter, env, configDir) {
|
|
|
33323
33699
|
const root = rootOrNull(adapter, env);
|
|
33324
33700
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
33325
33701
|
if (adapter.installMode === "marketplace") {
|
|
33326
|
-
const cache =
|
|
33702
|
+
const cache = join26(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
33327
33703
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
33328
33704
|
}
|
|
33329
33705
|
rmSync6(root, { recursive: true, force: true });
|
|
33330
33706
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
33331
33707
|
}
|
|
33332
33708
|
case "plugin": {
|
|
33333
|
-
const agentDir =
|
|
33334
|
-
if (!
|
|
33709
|
+
const agentDir = join26(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
33710
|
+
if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
33335
33711
|
rmSync6(agentDir, { recursive: true, force: true });
|
|
33336
33712
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
33337
33713
|
}
|
|
@@ -33376,7 +33752,7 @@ function ownEntries2(agent, env) {
|
|
|
33376
33752
|
}
|
|
33377
33753
|
if (agent === "opencode") {
|
|
33378
33754
|
return [{
|
|
33379
|
-
file:
|
|
33755
|
+
file: join26(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
33380
33756
|
// D-WIN-OPENCODE-DIR-1
|
|
33381
33757
|
key: OPENCODE_PLUGIN_KEY,
|
|
33382
33758
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -33387,13 +33763,22 @@ function ownEntries2(agent, env) {
|
|
|
33387
33763
|
if (agent === "pi") {
|
|
33388
33764
|
const agentDir = piAgentDirOf(env, home);
|
|
33389
33765
|
return [{
|
|
33390
|
-
file:
|
|
33766
|
+
file: join26(agentDir, SETTINGS_FILE),
|
|
33391
33767
|
key: PI_PACKAGES_KEY,
|
|
33392
33768
|
shown: PI_PACKAGES_KEY,
|
|
33393
33769
|
has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
|
|
33394
33770
|
drop: (v) => v.filter((x) => piSource2(x) !== PI_GIT_PACKAGE)
|
|
33395
33771
|
}];
|
|
33396
33772
|
}
|
|
33773
|
+
if (agent === "omp") {
|
|
33774
|
+
return [{
|
|
33775
|
+
file: ompImportFiles(home).mcp,
|
|
33776
|
+
key: OMP_DISABLED_SERVERS_KEY,
|
|
33777
|
+
shown: OMP_DISABLED_SERVERS_KEY,
|
|
33778
|
+
has: (v) => Array.isArray(v) && v.includes(SERVER_KEY),
|
|
33779
|
+
drop: (v) => v.filter((x) => x !== SERVER_KEY)
|
|
33780
|
+
}];
|
|
33781
|
+
}
|
|
33397
33782
|
return [];
|
|
33398
33783
|
}
|
|
33399
33784
|
function removeOwnEntries(agent, env) {
|
|
@@ -33409,12 +33794,12 @@ function removeOwnEntries(agent, env) {
|
|
|
33409
33794
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
33410
33795
|
}
|
|
33411
33796
|
function removeProjectData(configDir, projectKey) {
|
|
33412
|
-
const projects =
|
|
33413
|
-
const dir =
|
|
33414
|
-
if (!
|
|
33797
|
+
const projects = join26(configDir, PROJECTS_DIR_NAME);
|
|
33798
|
+
const dir = join26(projects, projectKey);
|
|
33799
|
+
if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
33415
33800
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
33416
33801
|
for (const name of readdirSync10(dir)) {
|
|
33417
|
-
if (name !== OWNERS_DIR_NAME) rmSync6(
|
|
33802
|
+
if (name !== OWNERS_DIR_NAME) rmSync6(join26(dir, name), { recursive: true, force: true });
|
|
33418
33803
|
}
|
|
33419
33804
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
33420
33805
|
}
|
|
@@ -33422,12 +33807,12 @@ function runUninstall(input) {
|
|
|
33422
33807
|
const configDir = resolveConfigDir(input.env);
|
|
33423
33808
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
33424
33809
|
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,
|
|
33810
|
+
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
33811
|
return { rows, stopped: stop.stopped };
|
|
33427
33812
|
}
|
|
33428
33813
|
|
|
33429
33814
|
// src/core/ops/v1-remove.ts
|
|
33430
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
33815
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync21, rmSync as rmSync7 } from "node:fs";
|
|
33431
33816
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
33432
33817
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
33433
33818
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -33439,7 +33824,7 @@ function moveAside(target, undo) {
|
|
|
33439
33824
|
}
|
|
33440
33825
|
function keepAside(target, undo) {
|
|
33441
33826
|
let aside = target + UPGRADE_ASIDE_SUFFIX;
|
|
33442
|
-
for (let n = 2;
|
|
33827
|
+
for (let n = 2; existsSync22(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
|
|
33443
33828
|
renameWithRetry(target, aside);
|
|
33444
33829
|
undo.push({ trash: aside, target, keep: true });
|
|
33445
33830
|
return aside;
|
|
@@ -33478,8 +33863,8 @@ function locate(doc, path8) {
|
|
|
33478
33863
|
return null;
|
|
33479
33864
|
}
|
|
33480
33865
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
33481
|
-
const layout = hostLayout(
|
|
33482
|
-
const text = hostText(
|
|
33866
|
+
const layout = hostLayout(readFileSync21(file2, "utf8"));
|
|
33867
|
+
const text = hostText(readFileSync21(file2, "utf8"));
|
|
33483
33868
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
33484
33869
|
const hit = /* @__PURE__ */ new Set();
|
|
33485
33870
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -33516,20 +33901,20 @@ function removeV1(agent, findings, project) {
|
|
|
33516
33901
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
33517
33902
|
else if (f.path === "") {
|
|
33518
33903
|
if (project !== void 0 && reachedThroughLink(project, f.file)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
33519
|
-
else if (
|
|
33520
|
-
else if (
|
|
33904
|
+
else if (existsSync22(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
|
|
33905
|
+
else if (existsSync22(f.file)) {
|
|
33521
33906
|
moveAside(f.file, undo);
|
|
33522
33907
|
done.set(f, UPGRADE_REMOVED);
|
|
33523
33908
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
33524
33909
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
33525
33910
|
}
|
|
33526
33911
|
for (const [file2, list4] of entries) {
|
|
33527
|
-
if (!
|
|
33912
|
+
if (!existsSync22(file2)) {
|
|
33528
33913
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
33529
33914
|
continue;
|
|
33530
33915
|
}
|
|
33531
33916
|
if (file2.endsWith(TOML_EXT)) {
|
|
33532
|
-
const rawToml =
|
|
33917
|
+
const rawToml = readFileSync21(file2, "utf8");
|
|
33533
33918
|
const tomlLayout = hostLayout(rawToml);
|
|
33534
33919
|
let text = hostText(rawToml);
|
|
33535
33920
|
for (const f of list4) {
|
|
@@ -33557,7 +33942,7 @@ function removeV1(agent, findings, project) {
|
|
|
33557
33942
|
},
|
|
33558
33943
|
rollback() {
|
|
33559
33944
|
for (const u of undo.splice(0).reverse()) {
|
|
33560
|
-
if (!
|
|
33945
|
+
if (!existsSync22(u.trash)) continue;
|
|
33561
33946
|
rmSync7(u.target, { recursive: true, force: true });
|
|
33562
33947
|
renameWithRetry(u.trash, u.target);
|
|
33563
33948
|
}
|