context-mode 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.zcode-plugin/plugin.json +1 -1
- package/README.md +72 -72
- package/SHA256SUMS +17 -17
- package/cli.mjs +17 -6
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +100 -98
- package/hooks/claude-code.json +12 -0
- package/opencode/plugin.js +684 -397
- package/package.json +1 -1
- package/pi/index.js +835 -543
- package/qwen-extension.json +1 -1
- package/run.mjs +32 -14
- package/search.mjs +32 -14
- package/server.mjs +193 -64
package/opencode/plugin.js
CHANGED
|
@@ -33,6 +33,7 @@ function readReplaceTrigger(raw) {
|
|
|
33
33
|
var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
|
|
34
34
|
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
35
35
|
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
36
|
+
var SKILL_LOAD_TOOLS = Object.freeze(["Skill"]);
|
|
36
37
|
var REPLACE_RETURN_BYTES = 96;
|
|
37
38
|
var SHAPE_RETURN_BYTES = 256;
|
|
38
39
|
var REPLACE_CHUNK_BYTES = 48;
|
|
@@ -46,6 +47,9 @@ function SUBAGENT_HANDLE_LINE(handle, bytes5, read3) {
|
|
|
46
47
|
function SEARCH_TWIN_LINE(searchPath, handle, terms, projectDir) {
|
|
47
48
|
return " Or run: node " + shellWord(searchPath) + " " + handle + " " + shellWord(terms) + " " + shellWord(projectDir);
|
|
48
49
|
}
|
|
50
|
+
function PERSISTED_FILE_LINE(file2) {
|
|
51
|
+
return " The whole output is also in " + JSON.stringify(file2) + "; Read it with offset and limit.";
|
|
52
|
+
}
|
|
49
53
|
function shellWord(s) {
|
|
50
54
|
return "'" + s.split("'").join("'\\''") + "'";
|
|
51
55
|
}
|
|
@@ -200,6 +204,10 @@ var KILL_GRACE_MS = 1e3;
|
|
|
200
204
|
var PIPE_EOF_GRACE_MS = 250;
|
|
201
205
|
var PIPE_DRAIN_MAX_MS = 2e3;
|
|
202
206
|
var DB_TIMEOUT_MS = 5e3;
|
|
207
|
+
var HOOK_BUSY_MS = 250;
|
|
208
|
+
var HOOK_SPOOL_DIR = "pending";
|
|
209
|
+
var SPOOL_CLAIM_STALE_MS = 3e4;
|
|
210
|
+
var SPOOL_DRAIN_MS = 1e3;
|
|
203
211
|
var DB_WAL_SUFFIX = "-wal";
|
|
204
212
|
var DB_SHM_SUFFIX = "-shm";
|
|
205
213
|
var DB_TMP_SUFFIX = ".tmp";
|
|
@@ -240,6 +248,7 @@ var RUN_LABEL_PREFIX = "run.mjs:";
|
|
|
240
248
|
var SEARCH_WRAPPER_FILE = "search.mjs";
|
|
241
249
|
var RUN_WRAPPER_AGENT = "claude-code";
|
|
242
250
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
251
|
+
var HOST_SESSION_META = Object.freeze({ zcode: "session_id" });
|
|
243
252
|
var NODE_MIN = "24.15.0";
|
|
244
253
|
var DATA_ROOT = "~/.context-mode";
|
|
245
254
|
var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
|
|
@@ -264,6 +273,7 @@ var FRONTMATTER_FENCE = "---";
|
|
|
264
273
|
var FRONTMATTER_TOOLS_KEY = "tools";
|
|
265
274
|
var FRONTMATTER_DISALLOWED_KEY = "disallowedTools";
|
|
266
275
|
var MCP_SERVER_TOOL_PREFIX = "mcp__";
|
|
276
|
+
var PLUGIN_CALL_ID_PREFIX = "toolu_plugin_";
|
|
267
277
|
var MCP_NAME_JOIN = "__";
|
|
268
278
|
var GEMINI_MCP_PREFIX = "mcp_";
|
|
269
279
|
var GEMINI_NAME_EXTRA_CHARS = "_-.:";
|
|
@@ -485,7 +495,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
485
495
|
var DECISION_OPTION_KEY = "option";
|
|
486
496
|
var DECISION_LABEL_JOIN = " | ";
|
|
487
497
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
488
|
-
var BUNDLE_SHA = true ? "
|
|
498
|
+
var BUNDLE_SHA = true ? "ae2e1bb106e462a19ab3c042e371cd8a7f691074" : void 0;
|
|
489
499
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
490
500
|
var DOCTOR_LABEL = Object.freeze({
|
|
491
501
|
D1: "version",
|
|
@@ -596,6 +606,10 @@ function D7_DETAIL(got) {
|
|
|
596
606
|
return `resolved project source ${got} does not match the host's actual cwd`;
|
|
597
607
|
}
|
|
598
608
|
var D7_FIX = "restart the agent in the correct directory";
|
|
609
|
+
function D7_NO_PROJECT_DETAIL(kind) {
|
|
610
|
+
return `Project source ${kind} is missing`;
|
|
611
|
+
}
|
|
612
|
+
var DOCTOR_NEEDS_PROJECT_DETAIL = "runs once the project resolves; D7 names the project source";
|
|
599
613
|
function D8_STALE_SCHEMA_DETAIL(got, want) {
|
|
600
614
|
return `stale schema (v${got}, expected v${want})`;
|
|
601
615
|
}
|
|
@@ -1155,7 +1169,8 @@ var OPENCODE_EVENTS = {
|
|
|
1155
1169
|
var SHELL_TOOL_NAME = "bash";
|
|
1156
1170
|
var READ_TOOL_NAME = "read";
|
|
1157
1171
|
var SHELL_TOOL_NAMES = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
1158
|
-
var
|
|
1172
|
+
var SKILL_TOOL_NAME = "skill";
|
|
1173
|
+
var NATIVE_TO_CANONICAL = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", [SKILL_TOOL_NAME]: "Skill", ...Object.fromEntries(SHELL_TOOL_NAMES.map((n) => [n, "Bash"])) };
|
|
1159
1174
|
function toCanonicalTool(name) {
|
|
1160
1175
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
1161
1176
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL, name) ? NATIVE_TO_CANONICAL[name] : name;
|
|
@@ -1278,7 +1293,7 @@ var CtxError = class extends Error {
|
|
|
1278
1293
|
};
|
|
1279
1294
|
|
|
1280
1295
|
// src/core/hooks/dispatch.ts
|
|
1281
|
-
import { dirname as dirname4, join as
|
|
1296
|
+
import { dirname as dirname4, join as join9, relative as relative3, resolve as resolve8, sep as sep3 } from "node:path";
|
|
1282
1297
|
|
|
1283
1298
|
// src/core/contracts/agents.ts
|
|
1284
1299
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode", "omp"];
|
|
@@ -1289,6 +1304,7 @@ var SHELL_TOOL_NAMES2 = Object.freeze(["Bash", "PowerShell"]);
|
|
|
1289
1304
|
var POWERSHELL_TOOL = "PowerShell";
|
|
1290
1305
|
var SHELL_CANONICAL = "Bash";
|
|
1291
1306
|
var CLAUDE_SHAPE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse"];
|
|
1307
|
+
var FAILURE_EVENT = "PostToolUseFailure";
|
|
1292
1308
|
var MCP_PREFIX = "mcp__";
|
|
1293
1309
|
var MCP_SEP = "__";
|
|
1294
1310
|
var CLAUDE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
@@ -1462,7 +1478,14 @@ function requireFields(raw) {
|
|
|
1462
1478
|
}
|
|
1463
1479
|
function decode2(raw) {
|
|
1464
1480
|
requireFields(raw);
|
|
1465
|
-
const
|
|
1481
|
+
const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
|
|
1482
|
+
const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
|
|
1483
|
+
const ev = decodeClaudeShape(payload, "claude-code", TOOL_NAME_PREFIX2, CLAUDE_SOURCES);
|
|
1484
|
+
if (failure) {
|
|
1485
|
+
const error40 = raw.error;
|
|
1486
|
+
const text = typeof error40 === "string" ? error40 : error40 === void 0 ? "" : JSON.stringify(error40);
|
|
1487
|
+
ev.result = { isError: true, bytes: Buffer.byteLength(text), text, keep: true };
|
|
1488
|
+
}
|
|
1466
1489
|
if (ev.tool !== void 0 && ev.tool.name === POWERSHELL_TOOL) ev.tool.canonicalName = SHELL_CANONICAL;
|
|
1467
1490
|
if (ev.cwd === "") ev.cwd = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
1468
1491
|
if (ev.event === "PostToolUse" && ev.tool !== void 0 && ev.tool.callId === void 0) {
|
|
@@ -1641,9 +1664,9 @@ var NATIVE_TO_CANONICAL3 = {
|
|
|
1641
1664
|
grep_search: "Grep",
|
|
1642
1665
|
web_fetch: "WebFetch"
|
|
1643
1666
|
};
|
|
1644
|
-
var
|
|
1667
|
+
var FAILURE_EVENT2 = "PostToolUseFailure";
|
|
1645
1668
|
function decode5(raw) {
|
|
1646
|
-
const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name ===
|
|
1669
|
+
const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT2;
|
|
1647
1670
|
const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
|
|
1648
1671
|
const ev = decodeClaudeShape(payload, "qwen", TOOL_NAME_PREFIX5, QWEN_SOURCES);
|
|
1649
1672
|
if (ev.tool !== void 0 && Object.hasOwn(NATIVE_TO_CANONICAL3, ev.tool.name)) ev.tool.canonicalName = NATIVE_TO_CANONICAL3[ev.tool.name];
|
|
@@ -1963,12 +1986,12 @@ var TOOL_NAME_PREFIX9 = "mcp__context-mode__";
|
|
|
1963
1986
|
var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
1964
1987
|
var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1965
1988
|
var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
|
|
1966
|
-
var
|
|
1989
|
+
var FAILURE_EVENT3 = "PostToolUseFailure";
|
|
1967
1990
|
function decode9(raw) {
|
|
1968
1991
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("zcode: hook payload is not a JSON object");
|
|
1969
1992
|
const p = { ...raw };
|
|
1970
1993
|
for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
|
|
1971
|
-
const failure = p.hook_event_name ===
|
|
1994
|
+
const failure = p.hook_event_name === FAILURE_EVENT3;
|
|
1972
1995
|
if (failure) p.hook_event_name = "PostToolUse";
|
|
1973
1996
|
const toolName2 = typeof p.tool_name === "string" ? p.tool_name : "";
|
|
1974
1997
|
const prefix = toolName2.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX9;
|
|
@@ -4738,7 +4761,7 @@ function dumpTarget(name, args) {
|
|
|
4738
4761
|
}
|
|
4739
4762
|
|
|
4740
4763
|
// src/core/project/resolve.ts
|
|
4741
|
-
import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve6 } from "node:path";
|
|
4764
|
+
import { basename as basename2, dirname as dirname3, isAbsolute as isAbsolute3, join as join6, resolve as resolve6 } from "node:path";
|
|
4742
4765
|
|
|
4743
4766
|
// src/core/project/sha256.ts
|
|
4744
4767
|
var K = new Uint32Array([
|
|
@@ -4893,12 +4916,7 @@ function dirOf(kind, src) {
|
|
|
4893
4916
|
}
|
|
4894
4917
|
}
|
|
4895
4918
|
function gitDirs(dir) {
|
|
4896
|
-
let cur;
|
|
4897
|
-
try {
|
|
4898
|
-
cur = realpathSync3.native(dir);
|
|
4899
|
-
} catch {
|
|
4900
|
-
throw new CtxError("NO_GIT_DIR", { path: dir });
|
|
4901
|
-
}
|
|
4919
|
+
let cur = nearestRealDir(dir);
|
|
4902
4920
|
const start = cur;
|
|
4903
4921
|
for (; ; ) {
|
|
4904
4922
|
const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
|
|
@@ -4911,6 +4929,18 @@ function gitDirs(dir) {
|
|
|
4911
4929
|
cur = up;
|
|
4912
4930
|
}
|
|
4913
4931
|
}
|
|
4932
|
+
function nearestRealDir(dir) {
|
|
4933
|
+
const walk3 = isAbsolute3(dir);
|
|
4934
|
+
for (let d = walk3 ? resolve6(dir) : dir; ; ) {
|
|
4935
|
+
try {
|
|
4936
|
+
return realpathSync3.native(d);
|
|
4937
|
+
} catch {
|
|
4938
|
+
const up = dirname3(d);
|
|
4939
|
+
if (!walk3 || up === d) throw new CtxError("NO_GIT_DIR", { path: dir });
|
|
4940
|
+
d = up;
|
|
4941
|
+
}
|
|
4942
|
+
}
|
|
4943
|
+
}
|
|
4914
4944
|
function gitDirAt(dotGit) {
|
|
4915
4945
|
let gitDir;
|
|
4916
4946
|
try {
|
|
@@ -4973,7 +5003,7 @@ function resolveProject(agent, src) {
|
|
|
4973
5003
|
},
|
|
4974
5004
|
worktree,
|
|
4975
5005
|
get containmentRoot() {
|
|
4976
|
-
root ??= plain ?? containmentRootOf(
|
|
5006
|
+
root ??= plain ?? containmentRootOf(worktree, commonDir);
|
|
4977
5007
|
return root;
|
|
4978
5008
|
},
|
|
4979
5009
|
agent,
|
|
@@ -5156,26 +5186,26 @@ function errCode(err) {
|
|
|
5156
5186
|
return err.code ?? "";
|
|
5157
5187
|
}
|
|
5158
5188
|
function publishWithoutLink(tmp, path8) {
|
|
5159
|
-
const
|
|
5189
|
+
const claim2 = path8 + DB_PUBLISH_CLAIM_SUFFIX;
|
|
5160
5190
|
const start = Date.now();
|
|
5161
5191
|
for (; ; ) {
|
|
5162
5192
|
if (existsSync3(path8)) return;
|
|
5163
5193
|
try {
|
|
5164
|
-
mkdirSync2(
|
|
5194
|
+
mkdirSync2(claim2);
|
|
5165
5195
|
} catch (err) {
|
|
5166
5196
|
if (!DB_CLAIM_BUSY_CODES.includes(errCode(err))) throw err;
|
|
5167
5197
|
if (Date.now() - start < DB_TIMEOUT_MS) {
|
|
5168
5198
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, DB_PUBLISH_POLL_MS);
|
|
5169
5199
|
continue;
|
|
5170
5200
|
}
|
|
5171
|
-
const held = statSync3(
|
|
5172
|
-
if (held !== void 0 && held.mtimeMs < start) rmSync(
|
|
5173
|
-
throw new Error(`context.db was not published within ${DB_TIMEOUT_MS} ms: ${
|
|
5201
|
+
const held = statSync3(claim2, { throwIfNoEntry: false });
|
|
5202
|
+
if (held !== void 0 && held.mtimeMs < start) rmSync(claim2, { recursive: true, force: true });
|
|
5203
|
+
throw new Error(`context.db was not published within ${DB_TIMEOUT_MS} ms: ${claim2} was held; open again`);
|
|
5174
5204
|
}
|
|
5175
5205
|
try {
|
|
5176
5206
|
if (!existsSync3(path8)) renameSync(tmp, path8);
|
|
5177
5207
|
} finally {
|
|
5178
|
-
rmSync(
|
|
5208
|
+
rmSync(claim2, { recursive: true, force: true });
|
|
5179
5209
|
}
|
|
5180
5210
|
return;
|
|
5181
5211
|
}
|
|
@@ -5294,9 +5324,9 @@ var COLUMNS = "events(session_id, worktree, agent, kind, tool, key, path, ok, ex
|
|
|
5294
5324
|
var INSERT_SQL = "INSERT INTO " + COLUMNS;
|
|
5295
5325
|
var INSERT_COST_SQL = "INSERT OR IGNORE INTO " + COLUMNS;
|
|
5296
5326
|
var COST_SEQ_SQL = "SELECT seq FROM events WHERE kind = 'cost' AND session_id = ? AND turn = ?";
|
|
5297
|
-
function appendEvent(db, row5) {
|
|
5327
|
+
function appendEvent(db, row5, at2) {
|
|
5298
5328
|
return withWrite(db, (h) => {
|
|
5299
|
-
const now = Date.now();
|
|
5329
|
+
const now = at2 ?? Date.now();
|
|
5300
5330
|
const isCost = row5.kind === "cost";
|
|
5301
5331
|
const res = h.raw.prepare(isCost ? INSERT_COST_SQL : INSERT_SQL).run(
|
|
5302
5332
|
row5.session_id,
|
|
@@ -7402,18 +7432,6 @@ function reserveSource(db, src, chunks) {
|
|
|
7402
7432
|
return Number(row5.id);
|
|
7403
7433
|
});
|
|
7404
7434
|
}
|
|
7405
|
-
function finishReserved(db, id2, src, chunks, units) {
|
|
7406
|
-
try {
|
|
7407
|
-
insertChunks(db, id2, src, chunks);
|
|
7408
|
-
insertUnits(db, id2, src.sessionId, units);
|
|
7409
|
-
} catch (err) {
|
|
7410
|
-
withWrite(db, (h) => {
|
|
7411
|
-
deleteChunkRows(h.raw, { sourceId: id2 });
|
|
7412
|
-
h.raw.prepare("DELETE FROM sources WHERE id = ?").run(id2);
|
|
7413
|
-
});
|
|
7414
|
-
throw err;
|
|
7415
|
-
}
|
|
7416
|
-
}
|
|
7417
7435
|
function insertChunks(db, id2, src, chunks) {
|
|
7418
7436
|
const batches = [];
|
|
7419
7437
|
let batch = [];
|
|
@@ -7852,43 +7870,53 @@ function parseSourceHandle(s) {
|
|
|
7852
7870
|
function pathLabel(p) {
|
|
7853
7871
|
return p.includes("\\") ? p.split("\\").join("/") : p;
|
|
7854
7872
|
}
|
|
7855
|
-
|
|
7856
|
-
|
|
7873
|
+
var EVERY_ROW = { scope: "project", sessionId: "", worktree: "" };
|
|
7874
|
+
var IN_SCOPE = "(:scope <> 'session' OR session_id = :session_id) AND (:scope <> 'worktree' OR worktree = :worktree)";
|
|
7875
|
+
var scopeArgs = (w) => ({ scope: w.scope, session_id: w.sessionId, worktree: w.worktree });
|
|
7876
|
+
function labelStored(db, label2, w) {
|
|
7877
|
+
return stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = :label AND " + IN_SCOPE + " LIMIT 1").get({ label: label2, ...scopeArgs(w) }) !== void 0;
|
|
7857
7878
|
}
|
|
7858
|
-
function storedLabel(db, source) {
|
|
7859
|
-
if (labelStored(db, source)) return source;
|
|
7879
|
+
function storedLabel(db, source, w = EVERY_ROW) {
|
|
7880
|
+
if (labelStored(db, source, w)) return source;
|
|
7860
7881
|
const canon = pathLabel(source);
|
|
7861
|
-
return canon !== source && labelStored(db, canon) ? canon : source;
|
|
7882
|
+
return canon !== source && labelStored(db, canon, w) ? canon : source;
|
|
7862
7883
|
}
|
|
7863
|
-
function newestId(db, label2) {
|
|
7864
|
-
const row5 = stmt(db.raw, "SELECT id FROM sources WHERE label =
|
|
7884
|
+
function newestId(db, label2, w) {
|
|
7885
|
+
const row5 = stmt(db.raw, "SELECT id FROM sources WHERE label = :label AND " + IN_SCOPE + " ORDER BY id DESC LIMIT 1").get({ label: label2, ...scopeArgs(w) });
|
|
7865
7886
|
return row5 === void 0 ? null : Number(row5.id);
|
|
7866
7887
|
}
|
|
7867
|
-
function labelOfId(db, id2) {
|
|
7868
|
-
const row5 = stmt(db.raw, "SELECT label FROM sources WHERE id =
|
|
7888
|
+
function labelOfId(db, id2, w) {
|
|
7889
|
+
const row5 = stmt(db.raw, "SELECT label FROM sources WHERE id = :id AND " + IN_SCOPE).get({ id: id2, ...scopeArgs(w) });
|
|
7869
7890
|
return row5 === void 0 ? null : row5.label;
|
|
7870
7891
|
}
|
|
7871
|
-
function
|
|
7872
|
-
const named2 = storedLabel(db, source);
|
|
7892
|
+
function pickIn(db, source, suffix, w) {
|
|
7893
|
+
const named2 = storedLabel(db, source, w);
|
|
7873
7894
|
const id2 = parseSourceHandle(source);
|
|
7874
|
-
const own2 = newestId(db, named2);
|
|
7895
|
+
const own2 = newestId(db, named2, w);
|
|
7875
7896
|
if (own2 !== null) {
|
|
7876
|
-
const otherLabel = id2 === null || id2 === own2 ? null : labelOfId(db, id2);
|
|
7897
|
+
const otherLabel = id2 === null || id2 === own2 ? null : labelOfId(db, id2, EVERY_ROW);
|
|
7877
7898
|
return { label: named2, id: own2, via: "label", other: otherLabel === null || otherLabel === named2 ? null : { id: id2, label: otherLabel } };
|
|
7878
7899
|
}
|
|
7879
7900
|
if (id2 !== null) {
|
|
7880
|
-
const label2 = labelOfId(db, id2);
|
|
7901
|
+
const label2 = labelOfId(db, id2, w);
|
|
7881
7902
|
if (label2 !== null) return { label: label2, id: id2, via: "handle", other: null };
|
|
7882
7903
|
}
|
|
7883
7904
|
if (suffix) {
|
|
7884
7905
|
const prefix = named2 + LABEL_SUFFIX_SEP;
|
|
7885
|
-
const rows = stmt(db.raw, "SELECT id, label FROM sources WHERE substr(label, 1,
|
|
7906
|
+
const rows = stmt(db.raw, "SELECT id, label FROM sources WHERE substr(label, 1, :n) = :prefix AND " + IN_SCOPE + " ORDER BY id DESC").all({ n: prefix.length, prefix, ...scopeArgs(w) });
|
|
7886
7907
|
for (const r of rows) {
|
|
7887
7908
|
if (r.label.lastIndexOf(LABEL_SUFFIX_SEP) === named2.length) return { label: r.label, id: Number(r.id), via: "suffix", other: null };
|
|
7888
7909
|
}
|
|
7889
7910
|
}
|
|
7890
7911
|
return { label: source, id: null, via: "none", other: null };
|
|
7891
7912
|
}
|
|
7913
|
+
function pickSource(db, source, suffix = true, w = EVERY_ROW) {
|
|
7914
|
+
if (w.scope !== "project") {
|
|
7915
|
+
const here = pickIn(db, source, suffix, w);
|
|
7916
|
+
if (here.via !== "none") return here;
|
|
7917
|
+
}
|
|
7918
|
+
return pickIn(db, source, suffix, EVERY_ROW);
|
|
7919
|
+
}
|
|
7892
7920
|
function collisionLine(value, pick2) {
|
|
7893
7921
|
if (pick2.other === null || pick2.id === null) return null;
|
|
7894
7922
|
return "Source " + JSON.stringify(value) + ": used the label " + shownLabel(pick2.label, null) + " (" + sourceHandle(pick2.id) + "); handle " + sourceHandle(pick2.other.id) + " is " + shownLabel(pick2.other.label, null) + (isLongLabel(pick2.other.label) ? ", search it by its full label." : ", search it with source:" + JSON.stringify(pick2.other.label) + ".");
|
|
@@ -7996,42 +8024,13 @@ function queryUnits(db, sessionId, q, limit, maxSourceId = Number.MAX_SAFE_INTEG
|
|
|
7996
8024
|
return rows.map((r) => ({ sourceId: Number(r.source_id), ord: Number(r.ord), label: r.label, body: r.body, score: r.score }));
|
|
7997
8025
|
}
|
|
7998
8026
|
|
|
7999
|
-
// src/core/index/units.ts
|
|
8000
|
-
function indentOf(line) {
|
|
8001
|
-
let n = 0;
|
|
8002
|
-
while (n < line.length && (line[n] === " " || line[n] === " ")) n++;
|
|
8003
|
-
return n;
|
|
8004
|
-
}
|
|
8005
|
-
function buildUnits(text) {
|
|
8006
|
-
const lines = text.split("\n");
|
|
8007
|
-
const stack2 = [];
|
|
8008
|
-
const out = [];
|
|
8009
|
-
let left = UNITS_ANCESTOR_FACTOR * Buffer.byteLength(text, "utf8");
|
|
8010
|
-
for (let i = 0; i < lines.length; i++) {
|
|
8011
|
-
const line = lines[i].endsWith("\r") ? lines[i].slice(0, -1) : lines[i];
|
|
8012
|
-
const indent = indentOf(line);
|
|
8013
|
-
if (indent === line.length) continue;
|
|
8014
|
-
while (stack2.length > 0 && stack2[stack2.length - 1].indent >= indent) stack2.pop();
|
|
8015
|
-
const bytes5 = Buffer.byteLength(line, "utf8");
|
|
8016
|
-
let size = bytes5;
|
|
8017
|
-
let from = stack2.length;
|
|
8018
|
-
while (from > 0) {
|
|
8019
|
-
const add = stack2[from - 1].bytes + 1;
|
|
8020
|
-
if (size + add > RECALL_BUDGET_BYTES || size - bytes5 + add > left) break;
|
|
8021
|
-
size += add;
|
|
8022
|
-
from--;
|
|
8023
|
-
}
|
|
8024
|
-
left -= size - bytes5;
|
|
8025
|
-
out.push({ ord: i, body: [...stack2.slice(from).map((s) => s.line), line].join("\n") });
|
|
8026
|
-
stack2.push({ indent, line, bytes: bytes5 });
|
|
8027
|
-
}
|
|
8028
|
-
return out;
|
|
8029
|
-
}
|
|
8030
|
-
|
|
8031
8027
|
// src/core/compaction/candidates.ts
|
|
8032
8028
|
function firstLine2(body) {
|
|
8033
|
-
const
|
|
8034
|
-
|
|
8029
|
+
const i = body.length - body.trimStart().length;
|
|
8030
|
+
if (i === body.length) return "";
|
|
8031
|
+
const start = i === 0 ? 0 : body.lastIndexOf("\n", i) + 1;
|
|
8032
|
+
const nl = body.indexOf("\n", i);
|
|
8033
|
+
return (start === 0 && nl < 0 ? body : body.slice(start, nl < 0 ? body.length : nl)).replaceAll("\r", " ");
|
|
8035
8034
|
}
|
|
8036
8035
|
function make(section, row5, text, repeatCount, query) {
|
|
8037
8036
|
const bytes5 = Buffer.byteLength(text, "utf8");
|
|
@@ -8574,7 +8573,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
8574
8573
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
8575
8574
|
return { end: start + r.read, written: r.written };
|
|
8576
8575
|
}
|
|
8577
|
-
function merge(src, blocks,
|
|
8576
|
+
function merge(src, blocks, join28, cap, lineCut) {
|
|
8578
8577
|
const out = [];
|
|
8579
8578
|
const scratch = new Uint8Array(cap);
|
|
8580
8579
|
let wide;
|
|
@@ -8584,7 +8583,7 @@ function merge(src, blocks, join27, cap, lineCut) {
|
|
|
8584
8583
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
8585
8584
|
};
|
|
8586
8585
|
for (const b of blocks) {
|
|
8587
|
-
if (cur !== void 0 && !
|
|
8586
|
+
if (cur !== void 0 && !join28) {
|
|
8588
8587
|
emit(cur.start, cur.end, curBytes);
|
|
8589
8588
|
cur = void 0;
|
|
8590
8589
|
}
|
|
@@ -8905,37 +8904,204 @@ function lineShape(text) {
|
|
|
8905
8904
|
return { header, units };
|
|
8906
8905
|
}
|
|
8907
8906
|
|
|
8908
|
-
// src/core/
|
|
8909
|
-
|
|
8910
|
-
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
|
|
8914
|
-
|
|
8915
|
-
|
|
8916
|
-
label: label2,
|
|
8917
|
-
bytes: Buffer.byteLength(text, "utf8"),
|
|
8918
|
-
chunkCount: chunks.length,
|
|
8919
|
-
createdAt: Date.now()
|
|
8920
|
-
}, chunks);
|
|
8921
|
-
return { sourceId, chunks: chunks.length };
|
|
8907
|
+
// src/core/hooks/spool.ts
|
|
8908
|
+
import { join as join7 } from "node:path";
|
|
8909
|
+
|
|
8910
|
+
// src/core/index/units.ts
|
|
8911
|
+
function indentOf(line) {
|
|
8912
|
+
let n = 0;
|
|
8913
|
+
while (n < line.length && (line[n] === " " || line[n] === " ")) n++;
|
|
8914
|
+
return n;
|
|
8922
8915
|
}
|
|
8923
|
-
function
|
|
8924
|
-
|
|
8916
|
+
function buildUnits(text) {
|
|
8917
|
+
const lines = text.split("\n");
|
|
8918
|
+
const stack2 = [];
|
|
8919
|
+
const out = [];
|
|
8920
|
+
let left = UNITS_ANCESTOR_FACTOR * Buffer.byteLength(text, "utf8");
|
|
8921
|
+
for (let i = 0; i < lines.length; i++) {
|
|
8922
|
+
const line = lines[i].endsWith("\r") ? lines[i].slice(0, -1) : lines[i];
|
|
8923
|
+
const indent = indentOf(line);
|
|
8924
|
+
if (indent === line.length) continue;
|
|
8925
|
+
while (stack2.length > 0 && stack2[stack2.length - 1].indent >= indent) stack2.pop();
|
|
8926
|
+
const bytes5 = Buffer.byteLength(line, "utf8");
|
|
8927
|
+
let size = bytes5;
|
|
8928
|
+
let from = stack2.length;
|
|
8929
|
+
while (from > 0) {
|
|
8930
|
+
const add = stack2[from - 1].bytes + 1;
|
|
8931
|
+
if (size + add > RECALL_BUDGET_BYTES || size - bytes5 + add > left) break;
|
|
8932
|
+
size += add;
|
|
8933
|
+
from--;
|
|
8934
|
+
}
|
|
8935
|
+
left -= size - bytes5;
|
|
8936
|
+
out.push({ ord: i, body: [...stack2.slice(from).map((s) => s.line), line].join("\n") });
|
|
8937
|
+
stack2.push({ indent, line, bytes: bytes5 });
|
|
8938
|
+
}
|
|
8939
|
+
return out;
|
|
8925
8940
|
}
|
|
8926
8941
|
|
|
8927
|
-
// src/core/hooks/
|
|
8928
|
-
|
|
8942
|
+
// src/core/hooks/spool.ts
|
|
8943
|
+
var { mkdirSync: mkdirSync3, readdirSync: readdirSync3, readFileSync: readFileSync5, renameSync: renameSync2, statSync: statSync4, unlinkSync, utimesSync, writeFileSync } = process.getBuiltinModule("node:fs");
|
|
8944
|
+
var OP_SUFFIX = ".json";
|
|
8945
|
+
var CLAIM_SUFFIX = ".claim";
|
|
8946
|
+
var TMP_SUFFIX = ".tmp";
|
|
8947
|
+
var BAD_SUFFIX = ".bad";
|
|
8948
|
+
var NAME_TIME_DIGITS = 15;
|
|
8949
|
+
var NAME_SEQ_DIGITS = 6;
|
|
8950
|
+
var nameSeq = 0;
|
|
8951
|
+
function isBusy(err) {
|
|
8952
|
+
const code = err?.errcode;
|
|
8953
|
+
return typeof code === "number" && (code & SQLITE_PRIMARY_CODE_MASK) === SQLITE_BUSY_CODE;
|
|
8954
|
+
}
|
|
8955
|
+
function message(err) {
|
|
8956
|
+
return err instanceof Error ? err.message : String(err);
|
|
8957
|
+
}
|
|
8958
|
+
async function hookDb(project) {
|
|
8959
|
+
const db = await openDb(project);
|
|
8960
|
+
db.raw.exec("PRAGMA busy_timeout = " + String(HOOK_BUSY_MS));
|
|
8961
|
+
return db;
|
|
8962
|
+
}
|
|
8963
|
+
function spoolDir(project) {
|
|
8964
|
+
return join7(project.projectDir, HOOK_SPOOL_DIR);
|
|
8965
|
+
}
|
|
8966
|
+
function spool(project, op) {
|
|
8967
|
+
const dir = spoolDir(project);
|
|
8968
|
+
mkdirSync3(dir, { recursive: true });
|
|
8969
|
+
const name = String(Date.now()).padStart(NAME_TIME_DIGITS, "0") + "-" + String(process.pid) + "-" + String(nameSeq++).padStart(NAME_SEQ_DIGITS, "0");
|
|
8970
|
+
const tmp = join7(dir, name + TMP_SUFFIX);
|
|
8971
|
+
writeFileSync(tmp, JSON.stringify(op));
|
|
8972
|
+
renameSync2(tmp, join7(dir, name + OP_SUFFIX));
|
|
8973
|
+
}
|
|
8974
|
+
function runOp(db, op, chunks, cur) {
|
|
8975
|
+
if (op.t === "row") {
|
|
8976
|
+
appendEvent(db, op.row, op.at);
|
|
8977
|
+
return null;
|
|
8978
|
+
}
|
|
8979
|
+
const c = chunks ?? chunkText(op.text, "text", op.max);
|
|
8980
|
+
let id2 = op.id;
|
|
8981
|
+
if (id2 === null) {
|
|
8982
|
+
id2 = reserveSource(db, op.src, c);
|
|
8983
|
+
cur.op = { ...op, id: id2 };
|
|
8984
|
+
} else if (chunks === void 0) {
|
|
8985
|
+
const sid = id2;
|
|
8986
|
+
const gone = withWrite(db, (h) => {
|
|
8987
|
+
if (h.raw.prepare("SELECT 1 AS x FROM sources WHERE id = ?").get(sid) === void 0) return true;
|
|
8988
|
+
deleteChunkRows(h.raw, { sourceId: sid });
|
|
8989
|
+
return false;
|
|
8990
|
+
});
|
|
8991
|
+
if (gone) return null;
|
|
8992
|
+
}
|
|
8929
8993
|
try {
|
|
8930
|
-
|
|
8931
|
-
|
|
8994
|
+
insertChunks(db, id2, op.src, c);
|
|
8995
|
+
if (op.units) insertUnits(db, id2, op.src.sessionId, buildUnits(op.text));
|
|
8932
8996
|
} catch (err) {
|
|
8933
|
-
|
|
8934
|
-
|
|
8997
|
+
if (isBusy(err)) throw err;
|
|
8998
|
+
const sid = id2;
|
|
8999
|
+
withWrite(db, (h) => {
|
|
9000
|
+
deleteChunkRows(h.raw, { sourceId: sid });
|
|
9001
|
+
h.raw.prepare("DELETE FROM sources WHERE id = ?").run(sid);
|
|
9002
|
+
});
|
|
9003
|
+
throw err;
|
|
9004
|
+
}
|
|
9005
|
+
return id2;
|
|
9006
|
+
}
|
|
9007
|
+
function writeOrSpool(project, db, op, chunks) {
|
|
9008
|
+
const cur = { op };
|
|
9009
|
+
try {
|
|
9010
|
+
return runOp(db, op, chunks, cur);
|
|
9011
|
+
} catch (err) {
|
|
9012
|
+
if (!isBusy(err)) throw err;
|
|
9013
|
+
spool(project, cur.op);
|
|
9014
|
+
return cur.op.t === "src" ? cur.op.id : null;
|
|
9015
|
+
}
|
|
9016
|
+
}
|
|
9017
|
+
function writeDetached(project, op, what, chunks) {
|
|
9018
|
+
void (async () => {
|
|
9019
|
+
try {
|
|
9020
|
+
const db = await hookDb(project);
|
|
9021
|
+
if (drain(project, db)) spool(project, op);
|
|
9022
|
+
else writeOrSpool(project, db, op, chunks);
|
|
9023
|
+
} catch (err) {
|
|
9024
|
+
try {
|
|
9025
|
+
if (!isBusy(err)) throw err;
|
|
9026
|
+
spool(project, op);
|
|
9027
|
+
} catch (e) {
|
|
9028
|
+
process.stderr.write("hooks: " + what + " write failed: " + message(e) + "\n");
|
|
9029
|
+
}
|
|
9030
|
+
}
|
|
9031
|
+
})();
|
|
9032
|
+
}
|
|
9033
|
+
function claim(dir, name) {
|
|
9034
|
+
let base = name;
|
|
9035
|
+
if (name.endsWith(OP_SUFFIX + CLAIM_SUFFIX)) {
|
|
9036
|
+
const path8 = join7(dir, name);
|
|
9037
|
+
try {
|
|
9038
|
+
if (Date.now() - statSync4(path8).mtimeMs < SPOOL_CLAIM_STALE_MS) return null;
|
|
9039
|
+
base = name.slice(0, -CLAIM_SUFFIX.length);
|
|
9040
|
+
renameSync2(path8, join7(dir, base));
|
|
9041
|
+
} catch {
|
|
9042
|
+
return null;
|
|
9043
|
+
}
|
|
9044
|
+
} else if (!name.endsWith(OP_SUFFIX)) {
|
|
9045
|
+
return null;
|
|
9046
|
+
}
|
|
9047
|
+
const claimed = join7(dir, base + CLAIM_SUFFIX);
|
|
9048
|
+
try {
|
|
9049
|
+
renameSync2(join7(dir, base), claimed);
|
|
9050
|
+
const now = /* @__PURE__ */ new Date();
|
|
9051
|
+
utimesSync(claimed, now, now);
|
|
9052
|
+
return claimed;
|
|
9053
|
+
} catch {
|
|
9054
|
+
return null;
|
|
9055
|
+
}
|
|
9056
|
+
}
|
|
9057
|
+
function drain(project, db) {
|
|
9058
|
+
const dir = spoolDir(project);
|
|
9059
|
+
let names;
|
|
9060
|
+
try {
|
|
9061
|
+
names = readdirSync3(dir);
|
|
9062
|
+
} catch {
|
|
9063
|
+
return false;
|
|
9064
|
+
}
|
|
9065
|
+
const start = Date.now();
|
|
9066
|
+
for (const name of names.sort()) {
|
|
9067
|
+
if (Date.now() - start > SPOOL_DRAIN_MS) return false;
|
|
9068
|
+
const claimed = claim(dir, name);
|
|
9069
|
+
if (claimed === null) continue;
|
|
9070
|
+
const base = claimed.slice(0, -CLAIM_SUFFIX.length);
|
|
9071
|
+
let op;
|
|
9072
|
+
try {
|
|
9073
|
+
op = JSON.parse(readFileSync5(claimed, "utf8"));
|
|
9074
|
+
} catch (err) {
|
|
9075
|
+
process.stderr.write("hooks: pending write unreadable: " + message(err) + "\n");
|
|
9076
|
+
renameSync2(claimed, base + BAD_SUFFIX);
|
|
9077
|
+
continue;
|
|
9078
|
+
}
|
|
9079
|
+
const cur = { op };
|
|
9080
|
+
try {
|
|
9081
|
+
runOp(db, op, void 0, cur);
|
|
9082
|
+
} catch (err) {
|
|
9083
|
+
if (isBusy(err)) {
|
|
9084
|
+
if (cur.op === op) {
|
|
9085
|
+
renameSync2(claimed, base);
|
|
9086
|
+
} else {
|
|
9087
|
+
writeFileSync(base + TMP_SUFFIX, JSON.stringify(cur.op));
|
|
9088
|
+
renameSync2(base + TMP_SUFFIX, base);
|
|
9089
|
+
unlinkSync(claimed);
|
|
9090
|
+
}
|
|
9091
|
+
return true;
|
|
9092
|
+
}
|
|
9093
|
+
process.stderr.write("hooks: pending write failed: " + message(err) + "\n");
|
|
9094
|
+
renameSync2(claimed, base + BAD_SUFFIX);
|
|
9095
|
+
continue;
|
|
9096
|
+
}
|
|
9097
|
+
unlinkSync(claimed);
|
|
8935
9098
|
}
|
|
9099
|
+
return false;
|
|
8936
9100
|
}
|
|
9101
|
+
|
|
9102
|
+
// src/core/hooks/detached.ts
|
|
8937
9103
|
function appendDetached(project, sessionId, row5) {
|
|
8938
|
-
|
|
9104
|
+
writeDetached(project, { t: "row", row: row5, at: Date.now() }, "journal");
|
|
8939
9105
|
}
|
|
8940
9106
|
|
|
8941
9107
|
// src/core/hooks/handle-query.ts
|
|
@@ -9026,7 +9192,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
9026
9192
|
}
|
|
9027
9193
|
|
|
9028
9194
|
// src/core/hooks/fallback.ts
|
|
9029
|
-
import { join as
|
|
9195
|
+
import { join as join8, resolve as resolve7 } from "node:path";
|
|
9030
9196
|
var fs = process.getBuiltinModule("node:fs");
|
|
9031
9197
|
function isRec(v) {
|
|
9032
9198
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -9054,9 +9220,9 @@ function homeOf(env) {
|
|
|
9054
9220
|
}
|
|
9055
9221
|
function hookLogPath(env) {
|
|
9056
9222
|
const dir = env[DATA_DIR_ENV];
|
|
9057
|
-
if (dir !== void 0 && dir !== "") return
|
|
9223
|
+
if (dir !== void 0 && dir !== "") return join8(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
|
|
9058
9224
|
const home = homeOf(env);
|
|
9059
|
-
return home === "" ? "" :
|
|
9225
|
+
return home === "" ? "" : join8(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
|
|
9060
9226
|
}
|
|
9061
9227
|
function errorLabel(err) {
|
|
9062
9228
|
const code = isRec(err) ? err.code : void 0;
|
|
@@ -9067,7 +9233,7 @@ function logHookError(env, agent, stage, err) {
|
|
|
9067
9233
|
try {
|
|
9068
9234
|
const file2 = hookLogPath(env);
|
|
9069
9235
|
if (file2 === "") return;
|
|
9070
|
-
fs.mkdirSync(
|
|
9236
|
+
fs.mkdirSync(join8(file2, ".."), { recursive: true });
|
|
9071
9237
|
const line = JSON.stringify({
|
|
9072
9238
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9073
9239
|
agent,
|
|
@@ -9181,14 +9347,14 @@ function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
|
9181
9347
|
var { read: read2, writeSync } = process.getBuiltinModule("node:fs");
|
|
9182
9348
|
|
|
9183
9349
|
// src/core/hooks/dispatch.ts
|
|
9184
|
-
var { lstatSync: lstatSync2, readFileSync:
|
|
9350
|
+
var { lstatSync: lstatSync2, readFileSync: readFileSync6 } = process.getBuiltinModule("node:fs");
|
|
9185
9351
|
var ALLOW2 = { kind: "allow" };
|
|
9186
9352
|
var EMPTY5 = { stdout: "", exitCode: 0 };
|
|
9187
9353
|
var DIGIT_0 = 48;
|
|
9188
9354
|
function isAgentId(s) {
|
|
9189
9355
|
return AGENT_IDS.includes(s);
|
|
9190
9356
|
}
|
|
9191
|
-
function
|
|
9357
|
+
function message2(err) {
|
|
9192
9358
|
return err instanceof Error ? err.message : String(err);
|
|
9193
9359
|
}
|
|
9194
9360
|
function str2(v) {
|
|
@@ -9202,7 +9368,7 @@ async function handleHook(agent, raw, env) {
|
|
|
9202
9368
|
const row5 = getAdapter(agent);
|
|
9203
9369
|
const report2 = (stage, err, line) => {
|
|
9204
9370
|
logHookError(env, agent, stage, err);
|
|
9205
|
-
process.stderr.write(line ?? "hooks: " + stage + " failed: " +
|
|
9371
|
+
process.stderr.write(line ?? "hooks: " + stage + " failed: " + message2(err) + "\n");
|
|
9206
9372
|
};
|
|
9207
9373
|
const fail7 = (stage, err, line) => {
|
|
9208
9374
|
report2(stage, err, line);
|
|
@@ -9228,7 +9394,7 @@ async function handleHook(agent, raw, env) {
|
|
|
9228
9394
|
const argv = agent === "vscode" ? [WORKSPACE_FOLDER_FLAG, ev.cwd] : process.argv;
|
|
9229
9395
|
project = resolveProject(agent, { env, argv, cwd: ev.cwd, piCwd: getAdapter(agent).projectSource === "pi:ctx.cwd" ? ev.cwd : void 0 });
|
|
9230
9396
|
} catch (err) {
|
|
9231
|
-
return fail7("project", err, "hooks: no project: " + String(err.code ?? "ERROR") + " " +
|
|
9397
|
+
return fail7("project", err, "hooks: no project: " + String(err.code ?? "ERROR") + " " + message2(err) + "\n");
|
|
9232
9398
|
}
|
|
9233
9399
|
let decision;
|
|
9234
9400
|
const settle = {};
|
|
@@ -9273,14 +9439,14 @@ function compactText(db, ev, row5) {
|
|
|
9273
9439
|
return renderState(readSessionEvents(db, ev.sessionId), ev.turn ?? 0, void 0, row5.toolNamePrefix);
|
|
9274
9440
|
}
|
|
9275
9441
|
async function sessionStart(ev, row5, project) {
|
|
9276
|
-
if (ev.source === "compact" && hasRecall(row5)) markCompacted(await
|
|
9442
|
+
if (ev.source === "compact" && hasRecall(row5)) markCompacted(await hookDb(project), ev.sessionId);
|
|
9277
9443
|
if (ev.source === "compact" && row5.compactDelivery === "sessionstart") {
|
|
9278
|
-
const db2 = await
|
|
9444
|
+
const db2 = await hookDb(project);
|
|
9279
9445
|
const onceKey = COMPACT_STATE_KEY + ":" + lastSessionSeq(db2, ev.sessionId);
|
|
9280
9446
|
if (!shouldHint(db2, ev.sessionId, onceKey)) return ALLOW2;
|
|
9281
9447
|
return { kind: "hint", text: compactText(db2, ev, row5), onceKey };
|
|
9282
9448
|
}
|
|
9283
|
-
const db = await
|
|
9449
|
+
const db = await hookDb(project);
|
|
9284
9450
|
if (row5.compactDelivery === "opencode-cache" && metaTake(db, PENDING_COMPACT_META_PREFIX + ev.sessionId) !== null) {
|
|
9285
9451
|
return { kind: "hint", text: compactText(db, ev, row5), onceKey: PENDING_COMPACT_KEY };
|
|
9286
9452
|
}
|
|
@@ -9308,7 +9474,7 @@ async function userPromptSubmit(ev, row5, project) {
|
|
|
9308
9474
|
});
|
|
9309
9475
|
echoDetached(ev, project, body);
|
|
9310
9476
|
if (row5.compactDelivery === "pending-flag") {
|
|
9311
|
-
const db = await
|
|
9477
|
+
const db = await hookDb(project);
|
|
9312
9478
|
if (metaTake(db, PENDING_COMPACT_META_PREFIX + ev.sessionId) !== null) {
|
|
9313
9479
|
return { kind: "hint", text: compactText(db, ev, row5), onceKey: PENDING_COMPACT_KEY };
|
|
9314
9480
|
}
|
|
@@ -9318,7 +9484,7 @@ async function userPromptSubmit(ev, row5, project) {
|
|
|
9318
9484
|
}
|
|
9319
9485
|
async function firstTurnResume(ev, row5, project) {
|
|
9320
9486
|
if (row5.eventMap.SessionStart !== void 0 || ev.sessionId === "") return null;
|
|
9321
|
-
const db = await
|
|
9487
|
+
const db = await hookDb(project);
|
|
9322
9488
|
if (hasSessionRows(db, ev.sessionId)) return null;
|
|
9323
9489
|
if (!shouldHint(db, ev.sessionId, RESUME_HINT_KEY)) return null;
|
|
9324
9490
|
if (!hasAgentRows(db, project.worktree, ev.agent)) return null;
|
|
@@ -9362,7 +9528,7 @@ function seenUnitKeys(value) {
|
|
|
9362
9528
|
}
|
|
9363
9529
|
async function recall(ev, row5, project, prompt) {
|
|
9364
9530
|
if (!hasRecall(row5) || ev.sessionId === "") return ALLOW2;
|
|
9365
|
-
const db = await
|
|
9531
|
+
const db = await hookDb(project);
|
|
9366
9532
|
const compacted = metaGet(db, COMPACTED_META_PREFIX + ev.sessionId);
|
|
9367
9533
|
if (compacted === null) return ALLOW2;
|
|
9368
9534
|
const boundary = compactBoundary(compacted);
|
|
@@ -9395,7 +9561,7 @@ function readOptions(value) {
|
|
|
9395
9561
|
function echoDetached(ev, project, prompt) {
|
|
9396
9562
|
if (ev.sessionId === "") return;
|
|
9397
9563
|
const key = optionsKey(ev.sessionId);
|
|
9398
|
-
void
|
|
9564
|
+
void hookDb(project).then((db) => {
|
|
9399
9565
|
if (metaGet(db, key) === null) return;
|
|
9400
9566
|
const taken = metaTake(db, key);
|
|
9401
9567
|
const offered = taken === null ? null : readOptions(taken);
|
|
@@ -9403,12 +9569,12 @@ function echoDetached(ev, project, prompt) {
|
|
|
9403
9569
|
const part = optionEchoDecision(prompt, offered.labels, offered.seq);
|
|
9404
9570
|
if (part !== null) writeDecisions(db, ev, project, [part]);
|
|
9405
9571
|
}).catch((err) => {
|
|
9406
|
-
process.stderr.write("hooks: decision write failed: " +
|
|
9572
|
+
process.stderr.write("hooks: decision write failed: " + message2(err) + "\n");
|
|
9407
9573
|
});
|
|
9408
9574
|
}
|
|
9409
9575
|
function writeDecisions(db, ev, project, parts) {
|
|
9410
9576
|
for (const part of parts) {
|
|
9411
|
-
|
|
9577
|
+
writeOrSpool(project, db, { t: "row", at: Date.now(), row: {
|
|
9412
9578
|
session_id: ev.sessionId,
|
|
9413
9579
|
worktree: project.worktree,
|
|
9414
9580
|
agent: ev.agent,
|
|
@@ -9423,22 +9589,22 @@ function writeDecisions(db, ev, project, parts) {
|
|
|
9423
9589
|
turn: ev.turn ?? 0,
|
|
9424
9590
|
sandbox_bytes: 0,
|
|
9425
9591
|
returned_bytes: 0
|
|
9426
|
-
});
|
|
9427
|
-
|
|
9592
|
+
} });
|
|
9593
|
+
writeOrSpool(project, db, { t: "src", id: null, src: sourceRowOf(project, ev.sessionId, DECISION_SOURCE), text: part.body, max: MAX_CHUNK_BYTES, units: false });
|
|
9428
9594
|
}
|
|
9429
9595
|
}
|
|
9430
9596
|
function askDetached(ev, project, tool, text) {
|
|
9431
9597
|
const parts = answerDecisions(text);
|
|
9432
9598
|
const labels = parts.length === 0 ? askOptionLabels(tool.input) : [];
|
|
9433
9599
|
if (parts.length === 0 && labels.length === 0) return;
|
|
9434
|
-
void
|
|
9600
|
+
void hookDb(project).then((db) => {
|
|
9435
9601
|
if (parts.length > 0) return writeDecisions(db, ev, project, parts);
|
|
9436
9602
|
const prompts = readSessionEvents(db, ev.sessionId, "prompt");
|
|
9437
9603
|
const last2 = prompts[prompts.length - 1];
|
|
9438
9604
|
if (last2 === void 0 || ev.sessionId === "") return;
|
|
9439
9605
|
metaSet(db, optionsKey(ev.sessionId), JSON.stringify({ seq: last2.seq, labels }));
|
|
9440
9606
|
}).catch((err) => {
|
|
9441
|
-
process.stderr.write("hooks: decision write failed: " +
|
|
9607
|
+
process.stderr.write("hooks: decision write failed: " + message2(err) + "\n");
|
|
9442
9608
|
});
|
|
9443
9609
|
}
|
|
9444
9610
|
function toolSetSources(ev, project, env) {
|
|
@@ -9474,7 +9640,7 @@ function caseB(ev, row5, d0, userDeny) {
|
|
|
9474
9640
|
if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
|
|
9475
9641
|
const command = tool.input.command;
|
|
9476
9642
|
if (typeof command !== "string") return d0;
|
|
9477
|
-
const wrapper = '"' +
|
|
9643
|
+
const wrapper = '"' + join9(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
|
|
9478
9644
|
const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
|
|
9479
9645
|
return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
|
|
9480
9646
|
}
|
|
@@ -9515,7 +9681,8 @@ async function postToolUse(ev, row5, project, env, settle) {
|
|
|
9515
9681
|
const tool = ev.tool;
|
|
9516
9682
|
if (tool === void 0 || tool.canonicalName.startsWith(OWN_TOOL_PREFIX)) return ALLOW2;
|
|
9517
9683
|
const result = ev.result ?? { isError: false, bytes: 0 };
|
|
9518
|
-
const
|
|
9684
|
+
const whole2 = wholeOutput(result, ev.sessionId, env);
|
|
9685
|
+
const text = whole2.text;
|
|
9519
9686
|
if (result.persistedPath !== void 0) result.bytes = Buffer.byteLength(text);
|
|
9520
9687
|
if (tool.canonicalName === DECISION_TOOL) askDetached(ev, project, tool, text);
|
|
9521
9688
|
const kind = journalKind(tool, row5, result.isError);
|
|
@@ -9542,7 +9709,7 @@ async function postToolUse(ev, row5, project, env, settle) {
|
|
|
9542
9709
|
};
|
|
9543
9710
|
let decision;
|
|
9544
9711
|
try {
|
|
9545
|
-
decision = await postReplace(ev, row5, project, env, tool, result, text);
|
|
9712
|
+
decision = await postReplace(ev, row5, project, env, tool, result, text, whole2.file);
|
|
9546
9713
|
} catch (err) {
|
|
9547
9714
|
journal(result.bytes);
|
|
9548
9715
|
throw err;
|
|
@@ -9556,19 +9723,22 @@ function ownRead(ev, tool, env) {
|
|
|
9556
9723
|
const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
|
|
9557
9724
|
return p !== void 0 && isOwnFile(ev.agent, ev.cwd, p, env);
|
|
9558
9725
|
}
|
|
9559
|
-
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
9726
|
+
async function postReplace(ev, row5, project, env, tool, result, text, persistedFile) {
|
|
9560
9727
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
9561
9728
|
if (boundedRead(tool)) return ALLOW2;
|
|
9562
9729
|
if (ompRangedRead(ev, tool)) return ALLOW2;
|
|
9563
9730
|
if (ownRead(ev, tool, env)) return ALLOW2;
|
|
9731
|
+
if (SKILL_LOAD_TOOLS.includes(tool.canonicalName)) return ALLOW2;
|
|
9564
9732
|
if (result.keep === true) return ALLOW2;
|
|
9565
9733
|
if (!hasReplace(row5)) return ALLOW2;
|
|
9566
9734
|
let label2;
|
|
9567
9735
|
let caller = { ctx: true, shell: true, read: false };
|
|
9736
|
+
let canRead = true;
|
|
9568
9737
|
if (isSubagentCall(ev)) {
|
|
9569
9738
|
const set3 = toolSetForAgentType(ev, toolSetSources(ev, project, env));
|
|
9570
9739
|
const subCase = pickSubagentCase(ev, set3);
|
|
9571
9740
|
const has3 = (names) => set3 !== null && names.some((n) => set3.includes(n));
|
|
9741
|
+
canRead = has3(row5.nativeTools.read ?? []);
|
|
9572
9742
|
caller = {
|
|
9573
9743
|
ctx: subCase === "A",
|
|
9574
9744
|
shell: has3(row5.nativeTools.shell),
|
|
@@ -9581,29 +9751,33 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
|
9581
9751
|
}
|
|
9582
9752
|
const intent = [tool.input.description, tool.input.command, tool.input.file_path, tool.input.pattern, tool.input.url, tool.name].map(str2).find((v) => v.trim() !== "") ?? tool.canonicalName;
|
|
9583
9753
|
const chunks = chunkText(text, "text", REPLACE_CHUNK_BYTES);
|
|
9584
|
-
const db = await
|
|
9754
|
+
const db = await hookDb(project);
|
|
9755
|
+
const op = { t: "src", id: null, src: sourceRowOf(project, ev.sessionId, label2), text, max: REPLACE_CHUNK_BYTES, units: true };
|
|
9585
9756
|
let sourceId;
|
|
9586
9757
|
if (result.bytes <= SYNC_INDEX_MAX_BYTES) {
|
|
9587
|
-
sourceId =
|
|
9588
|
-
insertUnits(db, sourceId, ev.sessionId, buildUnits(text));
|
|
9758
|
+
sourceId = writeOrSpool(project, db, op, chunks);
|
|
9589
9759
|
} else {
|
|
9590
|
-
sourceId =
|
|
9591
|
-
indexDetached(project,
|
|
9760
|
+
sourceId = reserveOrSpool(project, db, op, chunks);
|
|
9761
|
+
if (sourceId !== null) indexDetached(project, { ...op, id: sourceId }, chunks);
|
|
9592
9762
|
}
|
|
9593
|
-
|
|
9763
|
+
if (pluginMcpCall(tool)) return ALLOW2;
|
|
9764
|
+
const handle = sourceId === null ? label2 : sourceHandle(sourceId);
|
|
9594
9765
|
const prompt = await lastPrompt(project, ev.sessionId);
|
|
9595
9766
|
const rankQuery = prompt.trim() === "" ? void 0 : intent + " " + prompt;
|
|
9596
9767
|
const handleLine = caller.ctx ? REPLACE_HANDLE_LINE(intent, handle, result.bytes, row5.toolNamePrefix, askedWords(intent, prompt, text)) : SUBAGENT_HANDLE_LINE(handle, result.bytes, caller.read);
|
|
9597
9768
|
const budget = replaceBudget(handleLine, moreLine2(intent, label2));
|
|
9598
|
-
const pointer = handleLine + (caller.shell && ev.agent === RUN_WRAPPER_AGENT ? searchTwin(handle, intent, project) : "");
|
|
9769
|
+
const pointer = handleLine + (caller.shell && ev.agent === RUN_WRAPPER_AGENT && sourceId !== null ? searchTwin(handle, intent, project) : "") + (persistedFile !== void 0 && canRead ? PERSISTED_FILE_LINE(persistedFile) : "");
|
|
9599
9770
|
const digest = shapeDigest(text, rankQuery ?? intent, SHAPE_RETURN_BYTES);
|
|
9600
9771
|
if (digest !== null) return { kind: "replace", output: replaceOutput(digest, pointer) };
|
|
9601
9772
|
const selected = selectChunksInMemory(chunks, intent, budget, label2, rankQuery);
|
|
9602
9773
|
return { kind: "replace", output: selected.more !== null ? replaceOutput(selected.text, pointer) : selected.text };
|
|
9603
9774
|
}
|
|
9775
|
+
function pluginMcpCall(tool) {
|
|
9776
|
+
return tool.callId !== void 0 && tool.callId.startsWith(PLUGIN_CALL_ID_PREFIX) && tool.name.startsWith(MCP_SERVER_TOOL_PREFIX);
|
|
9777
|
+
}
|
|
9604
9778
|
function searchTwin(handle, intent, project) {
|
|
9605
9779
|
const terms = Buffer.byteLength(intent, "utf8") > ECHO_MAX_BYTES ? "" : intent;
|
|
9606
|
-
return SEARCH_TWIN_LINE(
|
|
9780
|
+
return SEARCH_TWIN_LINE(join9(dirname4(process.argv[1] ?? ""), SEARCH_WRAPPER_FILE), handle, terms, project.worktree);
|
|
9607
9781
|
}
|
|
9608
9782
|
function boundedRead(tool) {
|
|
9609
9783
|
return RANGE_READ_TOOLS.includes(tool.canonicalName) && READ_RANGE_KEYS.some((k) => tool.input[k] !== void 0 && tool.input[k] !== null);
|
|
@@ -9663,7 +9837,7 @@ function replaceBudget(handleLine, more) {
|
|
|
9663
9837
|
}
|
|
9664
9838
|
function hostToolResult(file2, sessionId, env) {
|
|
9665
9839
|
if (sessionId === "" || sessionId.includes(sep3) || sessionId.includes("/")) return false;
|
|
9666
|
-
const projects =
|
|
9840
|
+
const projects = join9(claudeDirOf(env, homeDirOf(env) ?? ""), PROJECTS_DIR_NAME);
|
|
9667
9841
|
const steps = relative3(projects, resolve8(file2)).split(sep3);
|
|
9668
9842
|
if (steps.length !== 4 || steps.includes("..") || steps.includes("")) return false;
|
|
9669
9843
|
if (steps[1] !== sessionId || steps[2] !== CLAUDE_TOOL_RESULTS_DIR_NAME) return false;
|
|
@@ -9672,20 +9846,20 @@ function hostToolResult(file2, sessionId, env) {
|
|
|
9672
9846
|
}
|
|
9673
9847
|
function wholeOutput(result, sessionId, env) {
|
|
9674
9848
|
const head2 = result.text ?? "";
|
|
9675
|
-
if (result.persistedPath === void 0) return head2;
|
|
9849
|
+
if (result.persistedPath === void 0) return { text: head2 };
|
|
9676
9850
|
try {
|
|
9677
9851
|
if (!hostToolResult(result.persistedPath, sessionId, env)) {
|
|
9678
9852
|
logHookError(env, "claude-code", "persisted-output", new Error("persisted output path is outside this session's tool-results dir or too large; kept the head"));
|
|
9679
|
-
return head2;
|
|
9853
|
+
return { text: head2 };
|
|
9680
9854
|
}
|
|
9681
|
-
return
|
|
9855
|
+
return { text: readFileSync6(result.persistedPath, "utf8"), file: result.persistedPath };
|
|
9682
9856
|
} catch {
|
|
9683
|
-
return head2;
|
|
9857
|
+
return { text: head2 };
|
|
9684
9858
|
}
|
|
9685
9859
|
}
|
|
9686
9860
|
async function lastPrompt(project, sessionId) {
|
|
9687
9861
|
try {
|
|
9688
|
-
return readLastPrompt(await
|
|
9862
|
+
return readLastPrompt(await hookDb(project), sessionId);
|
|
9689
9863
|
} catch {
|
|
9690
9864
|
return "";
|
|
9691
9865
|
}
|
|
@@ -9696,18 +9870,23 @@ function mainLabel(tool, ev) {
|
|
|
9696
9870
|
const head2 = (tool.canonicalName + ":" + (nl < 0 ? cmd : cmd.slice(0, nl))).slice(0, SOURCE_LABEL_MAX_CHARS);
|
|
9697
9871
|
return head2 + "#" + (tool.callId ?? String(ev.turn ?? 0));
|
|
9698
9872
|
}
|
|
9699
|
-
function indexDetached(project,
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9703
|
-
|
|
9704
|
-
|
|
9873
|
+
function indexDetached(project, op, chunks) {
|
|
9874
|
+
writeDetached(project, op, "index", chunks);
|
|
9875
|
+
}
|
|
9876
|
+
function reserveOrSpool(project, db, op, chunks) {
|
|
9877
|
+
try {
|
|
9878
|
+
return reserveSource(db, op.src, chunks);
|
|
9879
|
+
} catch (err) {
|
|
9880
|
+
if (!isBusy(err)) throw err;
|
|
9881
|
+
spool(project, op);
|
|
9882
|
+
return null;
|
|
9883
|
+
}
|
|
9705
9884
|
}
|
|
9706
9885
|
function sourceRowOf(project, sessionId, label2) {
|
|
9707
9886
|
return { sessionId, worktree: project.worktree, agent: project.agent, kind: "content", label: label2, createdAt: Date.now() };
|
|
9708
9887
|
}
|
|
9709
9888
|
async function preCompact(ev, row5, project) {
|
|
9710
|
-
const db = await
|
|
9889
|
+
const db = await hookDb(project);
|
|
9711
9890
|
metaSet(db, PENDING_COMPACT_META_PREFIX + ev.sessionId, PENDING_COMPACT_FLAG);
|
|
9712
9891
|
if (hasRecall(row5)) markCompacted(db, ev.sessionId);
|
|
9713
9892
|
return ALLOW2;
|
|
@@ -10733,14 +10912,14 @@ function prefixIssues(path8, issues) {
|
|
|
10733
10912
|
return iss;
|
|
10734
10913
|
});
|
|
10735
10914
|
}
|
|
10736
|
-
function unwrapMessage(
|
|
10737
|
-
return typeof
|
|
10915
|
+
function unwrapMessage(message4) {
|
|
10916
|
+
return typeof message4 === "string" ? message4 : message4?.message;
|
|
10738
10917
|
}
|
|
10739
10918
|
function finalizeIssue(iss, ctx, config2) {
|
|
10740
10919
|
const full = { ...iss, path: iss.path ?? [] };
|
|
10741
10920
|
if (!iss.message) {
|
|
10742
|
-
const
|
|
10743
|
-
full.message =
|
|
10921
|
+
const message4 = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config2.customError?.(iss)) ?? unwrapMessage(config2.localeError?.(iss)) ?? "Invalid input";
|
|
10922
|
+
full.message = message4;
|
|
10744
10923
|
}
|
|
10745
10924
|
delete full.inst;
|
|
10746
10925
|
delete full.continue;
|
|
@@ -20928,7 +21107,7 @@ function buildChildEnv(parent, extra) {
|
|
|
20928
21107
|
}
|
|
20929
21108
|
|
|
20930
21109
|
// src/core/sandbox/runtimes.ts
|
|
20931
|
-
import { accessSync, constants as fsConstants, statSync as
|
|
21110
|
+
import { accessSync, constants as fsConstants, statSync as statSync5 } from "node:fs";
|
|
20932
21111
|
import path from "node:path";
|
|
20933
21112
|
|
|
20934
21113
|
// src/core/sandbox/path-entries.ts
|
|
@@ -20973,7 +21152,7 @@ function fileNames(name, pathExt) {
|
|
|
20973
21152
|
function probe(full) {
|
|
20974
21153
|
let st;
|
|
20975
21154
|
try {
|
|
20976
|
-
st =
|
|
21155
|
+
st = statSync5(full, { throwIfNoEntry: false });
|
|
20977
21156
|
} catch {
|
|
20978
21157
|
return "unreadable";
|
|
20979
21158
|
}
|
|
@@ -21168,8 +21347,8 @@ function runProcess(argv, o) {
|
|
|
21168
21347
|
}
|
|
21169
21348
|
|
|
21170
21349
|
// src/core/index/auto-memory.ts
|
|
21171
|
-
import { readdirSync as
|
|
21172
|
-
import { join as
|
|
21350
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync7, statSync as statSync6 } from "node:fs";
|
|
21351
|
+
import { join as join10 } from "node:path";
|
|
21173
21352
|
var MEMORY_FILES = Object.freeze([
|
|
21174
21353
|
Object.freeze(["CLAUDE.md"]),
|
|
21175
21354
|
Object.freeze(["CLAUDE.local.md"]),
|
|
@@ -21183,7 +21362,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
21183
21362
|
var MD = ".md";
|
|
21184
21363
|
function steeringFiles(worktree) {
|
|
21185
21364
|
try {
|
|
21186
|
-
return
|
|
21365
|
+
return readdirSync4(join10(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
21187
21366
|
} catch {
|
|
21188
21367
|
return [];
|
|
21189
21368
|
}
|
|
@@ -21191,10 +21370,10 @@ function steeringFiles(worktree) {
|
|
|
21191
21370
|
function readAutoMemory(project) {
|
|
21192
21371
|
const rows = [];
|
|
21193
21372
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
21194
|
-
const path8 =
|
|
21373
|
+
const path8 = join10(project.worktree, ...segs);
|
|
21195
21374
|
if (!isInside(project.worktree, path8)) continue;
|
|
21196
21375
|
try {
|
|
21197
|
-
const st =
|
|
21376
|
+
const st = statSync6(path8);
|
|
21198
21377
|
if (!st.isFile()) continue;
|
|
21199
21378
|
rows.push({
|
|
21200
21379
|
origin: "memory",
|
|
@@ -21203,7 +21382,7 @@ function readAutoMemory(project) {
|
|
|
21203
21382
|
sourceId: null,
|
|
21204
21383
|
path: path8,
|
|
21205
21384
|
label: segs.join("/"),
|
|
21206
|
-
text:
|
|
21385
|
+
text: readFileSync7(path8, "utf8")
|
|
21207
21386
|
});
|
|
21208
21387
|
} catch {
|
|
21209
21388
|
}
|
|
@@ -21267,10 +21446,11 @@ function sourceCount(db, scope, ctx, source) {
|
|
|
21267
21446
|
function zeroHits(db, scope, ctx, source, mem, nm, queries, offset = 0) {
|
|
21268
21447
|
const inScope = sourceCount(db, scope, ctx, source);
|
|
21269
21448
|
const n = inScope + mem.rows.length;
|
|
21270
|
-
if (offset > 0) return reply("No more hits past offset " + offset + ' in scope "' + scope + '" across ' + n + " source(s).", false);
|
|
21271
21449
|
const head2 = 'No hits in scope "' + scope + '" across ' + n + " source(s).";
|
|
21272
21450
|
const pick2 = nm.pick;
|
|
21273
|
-
if (pick2 === null || mem.named || inScope > 0)
|
|
21451
|
+
if (pick2 === null || mem.named || inScope > 0) {
|
|
21452
|
+
return reply(offset > 0 ? "No more hits past offset " + offset + ' in scope "' + scope + '" across ' + n + " source(s)." : head2, false);
|
|
21453
|
+
}
|
|
21274
21454
|
if (pick2.id !== null) {
|
|
21275
21455
|
const wider = scope === "session" && sourceCount(db, "worktree", ctx, source) > 0 ? "worktree" : "project";
|
|
21276
21456
|
return reply(head2 + "\nSource " + JSON.stringify(nm.arg) + ' is stored in scope "' + wider + '": ' + callText(queries, wider, nm.arg, "") + " searches it.", false);
|
|
@@ -21555,7 +21735,8 @@ async function handler(input, ctx) {
|
|
|
21555
21735
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
21556
21736
|
try {
|
|
21557
21737
|
const given = input.source;
|
|
21558
|
-
const
|
|
21738
|
+
const within = { scope, sessionId: ctx.sessionId, worktree: ctx.project.worktree };
|
|
21739
|
+
const pick2 = given !== void 0 && given !== DECISION_SOURCE ? pickSource(db, given, true, within) : null;
|
|
21559
21740
|
if (pick2 !== null) input = { ...input, source: pick2.label };
|
|
21560
21741
|
const nm = named(given, pick2);
|
|
21561
21742
|
const indexed = pick2 !== null && pick2.id !== null;
|
|
@@ -21804,19 +21985,19 @@ var ctxBatch = Object.freeze({
|
|
|
21804
21985
|
});
|
|
21805
21986
|
|
|
21806
21987
|
// src/core/tools/doctor.ts
|
|
21807
|
-
import { readdirSync as
|
|
21808
|
-
import { basename as basename5, join as
|
|
21988
|
+
import { readdirSync as readdirSync9, readFileSync as readFileSync18, existsSync as existsSync17 } from "node:fs";
|
|
21989
|
+
import { basename as basename5, join as join21 } from "node:path";
|
|
21809
21990
|
|
|
21810
21991
|
// src/core/ops/bundle-dir.ts
|
|
21811
21992
|
import { existsSync as existsSync4 } from "node:fs";
|
|
21812
|
-
import { dirname as dirname5, join as
|
|
21993
|
+
import { dirname as dirname5, join as join11 } from "node:path";
|
|
21813
21994
|
import { fileURLToPath } from "node:url";
|
|
21814
21995
|
function bundleDirOf(argv1, moduleFile) {
|
|
21815
21996
|
const own2 = dirname5(argv1);
|
|
21816
|
-
if (existsSync4(
|
|
21997
|
+
if (existsSync4(join11(own2, SERVER_ENTRY_FILE))) return own2;
|
|
21817
21998
|
let dir = dirname5(moduleFile);
|
|
21818
21999
|
for (; ; ) {
|
|
21819
|
-
if (existsSync4(
|
|
22000
|
+
if (existsSync4(join11(dir, SERVER_ENTRY_FILE))) return dir;
|
|
21820
22001
|
const up = dirname5(dir);
|
|
21821
22002
|
if (up === dir) return own2;
|
|
21822
22003
|
dir = up;
|
|
@@ -21830,17 +22011,17 @@ function ownBundleDir() {
|
|
|
21830
22011
|
}
|
|
21831
22012
|
|
|
21832
22013
|
// src/core/ops/doctor-config.ts
|
|
21833
|
-
import { existsSync as existsSync11, readdirSync as
|
|
21834
|
-
import { dirname as dirname8, isAbsolute as
|
|
22014
|
+
import { existsSync as existsSync11, readdirSync as readdirSync7, readFileSync as readFileSync14 } from "node:fs";
|
|
22015
|
+
import { dirname as dirname8, isAbsolute as isAbsolute6, join as join17, resolve as resolve9 } from "node:path";
|
|
21835
22016
|
|
|
21836
22017
|
// src/core/ops/detect-v1.ts
|
|
21837
|
-
import { existsSync as existsSync6, opendirSync, readdirSync as
|
|
22018
|
+
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync5, readFileSync as readFileSync9 } from "node:fs";
|
|
21838
22019
|
import { tmpdir } from "node:os";
|
|
21839
|
-
import { join as
|
|
22020
|
+
import { join as join13 } from "node:path";
|
|
21840
22021
|
|
|
21841
22022
|
// src/core/ops/host-config.ts
|
|
21842
|
-
import { existsSync as existsSync5, readFileSync as
|
|
21843
|
-
import { dirname as dirname6, join as
|
|
22023
|
+
import { existsSync as existsSync5, readFileSync as readFileSync8 } from "node:fs";
|
|
22024
|
+
import { dirname as dirname6, join as join12 } from "node:path";
|
|
21844
22025
|
|
|
21845
22026
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
21846
22027
|
var KEYS2 = {
|
|
@@ -23886,7 +24067,7 @@ function parseTOML(code, options) {
|
|
|
23886
24067
|
}
|
|
23887
24068
|
|
|
23888
24069
|
// src/core/ops/atomic-file.ts
|
|
23889
|
-
import { mkdirSync as
|
|
24070
|
+
import { mkdirSync as mkdirSync4, renameSync as renameSync3, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
23890
24071
|
import path3 from "node:path";
|
|
23891
24072
|
function sleepSync(ms) {
|
|
23892
24073
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
@@ -23895,7 +24076,7 @@ function errCode2(e) {
|
|
|
23895
24076
|
return e.code;
|
|
23896
24077
|
}
|
|
23897
24078
|
function renameWithRetry(from, to, opts = {}) {
|
|
23898
|
-
const rename = opts.rename ??
|
|
24079
|
+
const rename = opts.rename ?? renameSync3;
|
|
23899
24080
|
const sleep = opts.sleep ?? sleepSync;
|
|
23900
24081
|
const win = (opts.platform ?? process.platform) === "win32";
|
|
23901
24082
|
for (let attempt = 0; ; attempt += 1) {
|
|
@@ -23910,7 +24091,7 @@ function renameWithRetry(from, to, opts = {}) {
|
|
|
23910
24091
|
}
|
|
23911
24092
|
}
|
|
23912
24093
|
function unlinkWithRetry(file2, opts = {}) {
|
|
23913
|
-
const unlink = opts.unlink ??
|
|
24094
|
+
const unlink = opts.unlink ?? unlinkSync2;
|
|
23914
24095
|
const sleep = opts.sleep ?? sleepSync;
|
|
23915
24096
|
const win = (opts.platform ?? process.platform) === "win32";
|
|
23916
24097
|
for (let attempt = 0; ; attempt += 1) {
|
|
@@ -23937,10 +24118,10 @@ function removeTmpFile(tmp, opts = {}) {
|
|
|
23937
24118
|
}
|
|
23938
24119
|
}
|
|
23939
24120
|
function atomicWriteFile(file2, text, opts = {}) {
|
|
23940
|
-
|
|
24121
|
+
mkdirSync4(path3.dirname(file2), { recursive: true });
|
|
23941
24122
|
const tmp = path3.join(path3.dirname(file2), `${ATOMIC_TMP_PREFIX}${path3.basename(file2)}${ATOMIC_TMP_MARK}${process.pid}`);
|
|
23942
24123
|
try {
|
|
23943
|
-
|
|
24124
|
+
writeFileSync2(tmp, text);
|
|
23944
24125
|
renameWithRetry(tmp, file2, opts);
|
|
23945
24126
|
} catch (e) {
|
|
23946
24127
|
removeTmpFile(tmp, opts);
|
|
@@ -23957,10 +24138,10 @@ function formatOf(path8) {
|
|
|
23957
24138
|
function readHostConfig(agent, path8) {
|
|
23958
24139
|
let file2 = path8;
|
|
23959
24140
|
if (agent === "opencode") {
|
|
23960
|
-
const jsonc =
|
|
24141
|
+
const jsonc = join12(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
|
|
23961
24142
|
if (existsSync5(jsonc)) file2 = jsonc;
|
|
23962
24143
|
}
|
|
23963
|
-
const raw = existsSync5(file2) ?
|
|
24144
|
+
const raw = existsSync5(file2) ? readFileSync8(file2, "utf8") : "";
|
|
23964
24145
|
return { agent, text: hostText(raw), format: agent === "opencode" && !file2.endsWith(TOML_EXT) ? "jsonc" : formatOf(file2), path: file2, layout: hostLayout(raw) };
|
|
23965
24146
|
}
|
|
23966
24147
|
function stripJsonComments(text) {
|
|
@@ -24305,7 +24486,7 @@ function setText(agent, path8, text, format, key, value) {
|
|
|
24305
24486
|
}
|
|
24306
24487
|
}
|
|
24307
24488
|
function serverScript() {
|
|
24308
|
-
return
|
|
24489
|
+
return join12(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
24309
24490
|
}
|
|
24310
24491
|
function isNodeCommand(command) {
|
|
24311
24492
|
if (typeof command !== "string") return false;
|
|
@@ -24432,14 +24613,14 @@ function stripJsonc(text) {
|
|
|
24432
24613
|
}
|
|
24433
24614
|
function readJson(file2) {
|
|
24434
24615
|
try {
|
|
24435
|
-
return JSON.parse(stripJsonc(hostText(
|
|
24616
|
+
return JSON.parse(stripJsonc(hostText(readFileSync9(file2, "utf8"))));
|
|
24436
24617
|
} catch {
|
|
24437
24618
|
return void 0;
|
|
24438
24619
|
}
|
|
24439
24620
|
}
|
|
24440
24621
|
function readText(file2) {
|
|
24441
24622
|
try {
|
|
24442
|
-
return hostText(
|
|
24623
|
+
return hostText(readFileSync9(file2, "utf8"));
|
|
24443
24624
|
} catch {
|
|
24444
24625
|
return "";
|
|
24445
24626
|
}
|
|
@@ -24504,7 +24685,7 @@ function mcpEntry(file2, doc, out) {
|
|
|
24504
24685
|
}
|
|
24505
24686
|
}
|
|
24506
24687
|
function claudeShapeSettings(agentHome, out) {
|
|
24507
|
-
const file2 =
|
|
24688
|
+
const file2 = join13(agentHome, SETTINGS_FILE);
|
|
24508
24689
|
const doc = readJson(file2);
|
|
24509
24690
|
for (const c of nestedCommands(doc)) {
|
|
24510
24691
|
if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
|
|
@@ -24524,63 +24705,63 @@ function v1HookFile(file2, out) {
|
|
|
24524
24705
|
function scanClaudeCode(home, agentHome, out) {
|
|
24525
24706
|
claudeShapeSettings(agentHome, out);
|
|
24526
24707
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
24527
|
-
const file2 =
|
|
24708
|
+
const file2 = join13(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
24528
24709
|
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
24529
24710
|
}
|
|
24530
|
-
const userFile =
|
|
24711
|
+
const userFile = join13(home, CLAUDE_USER_CONFIG_FILE);
|
|
24531
24712
|
mcpEntry(userFile, readJson(userFile), out);
|
|
24532
|
-
dataDir(
|
|
24713
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24533
24714
|
}
|
|
24534
24715
|
function scanCodex(agentHome, out) {
|
|
24535
|
-
const hooksFile =
|
|
24716
|
+
const hooksFile = join13(agentHome, HOOKS_JSON_FILE);
|
|
24536
24717
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
24537
24718
|
if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
|
|
24538
24719
|
out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
|
|
24539
24720
|
}
|
|
24540
24721
|
}
|
|
24541
|
-
const tomlFile =
|
|
24722
|
+
const tomlFile = join13(agentHome, CONFIG_TOML_FILE);
|
|
24542
24723
|
const config2 = readTomlValue(tomlFile);
|
|
24543
24724
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
24544
24725
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
24545
24726
|
if (isV2McpTable(hostConfigValueAt(config2, span2.path.slice(0, 2)))) continue;
|
|
24546
24727
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
24547
24728
|
}
|
|
24548
|
-
dataDir(
|
|
24729
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24549
24730
|
}
|
|
24550
24731
|
function scanGemini(agentHome, out) {
|
|
24551
|
-
const file2 =
|
|
24732
|
+
const file2 = join13(agentHome, SETTINGS_FILE);
|
|
24552
24733
|
for (const c of nestedCommands(readJson(file2))) {
|
|
24553
24734
|
if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
|
|
24554
24735
|
}
|
|
24555
|
-
dataDir(
|
|
24736
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
|
|
24556
24737
|
}
|
|
24557
24738
|
function scanVscode(agentHome, project, out) {
|
|
24558
24739
|
if (project !== void 0) {
|
|
24559
|
-
v1HookFile(
|
|
24560
|
-
const mcpFile2 =
|
|
24740
|
+
v1HookFile(join13(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
24741
|
+
const mcpFile2 = join13(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
24561
24742
|
const doc = readJson(mcpFile2);
|
|
24562
24743
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
24563
24744
|
const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
24564
24745
|
if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
|
|
24565
24746
|
out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
24566
24747
|
}
|
|
24567
|
-
const sessions =
|
|
24748
|
+
const sessions = join13(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
24568
24749
|
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out);
|
|
24569
24750
|
}
|
|
24570
|
-
dataDir(
|
|
24751
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
24571
24752
|
}
|
|
24572
24753
|
function jsonFiles(dir) {
|
|
24573
24754
|
try {
|
|
24574
|
-
return
|
|
24755
|
+
return readdirSync5(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
24575
24756
|
} catch {
|
|
24576
24757
|
return [];
|
|
24577
24758
|
}
|
|
24578
24759
|
}
|
|
24579
24760
|
function scanKiro(agentHome, project, out) {
|
|
24580
|
-
const agentsDir =
|
|
24581
|
-
const defaultFile =
|
|
24761
|
+
const agentsDir = join13(agentHome, KIRO_AGENTS_DIR);
|
|
24762
|
+
const defaultFile = join13(agentHome, ...KIRO_AGENT_FILE);
|
|
24582
24763
|
for (const name of jsonFiles(agentsDir)) {
|
|
24583
|
-
const file2 =
|
|
24764
|
+
const file2 = join13(agentsDir, name);
|
|
24584
24765
|
const doc = readJson(file2);
|
|
24585
24766
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
24586
24767
|
out.push(finding(file2, "", V1_REASON.kiroAgentFile));
|
|
@@ -24591,31 +24772,31 @@ function scanKiro(agentHome, project, out) {
|
|
|
24591
24772
|
if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
|
|
24592
24773
|
}
|
|
24593
24774
|
}
|
|
24594
|
-
const steeringDocs = [
|
|
24595
|
-
if (project !== void 0) steeringDocs.push(
|
|
24775
|
+
const steeringDocs = [join13(agentHome, ...KIRO_STEERING_FILE)];
|
|
24776
|
+
if (project !== void 0) steeringDocs.push(join13(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
24596
24777
|
for (const file2 of steeringDocs) {
|
|
24597
24778
|
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
24598
24779
|
}
|
|
24599
|
-
dataDir(
|
|
24780
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24600
24781
|
}
|
|
24601
24782
|
function piNpmIsCurrent(piAgentDir) {
|
|
24602
|
-
const doc = readJson(
|
|
24783
|
+
const doc = readJson(join13(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
24603
24784
|
const version2 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
24604
24785
|
return Number.parseInt(version2, 10) >= PI_CURRENT_MAJOR;
|
|
24605
24786
|
}
|
|
24606
24787
|
function scanPi(piAgentDir, agentHome, out) {
|
|
24607
|
-
const file2 =
|
|
24788
|
+
const file2 = join13(piAgentDir, SETTINGS_FILE);
|
|
24608
24789
|
const doc = readJson(file2);
|
|
24609
24790
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
24610
24791
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
24611
24792
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
24612
24793
|
if (spec === PI_GIT_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piGit));
|
|
24613
24794
|
});
|
|
24614
|
-
dataDir(
|
|
24795
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24615
24796
|
}
|
|
24616
24797
|
function scanOpencode(agentHome, out) {
|
|
24617
24798
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
24618
|
-
const file2 =
|
|
24799
|
+
const file2 = join13(agentHome, name);
|
|
24619
24800
|
const doc = readJson(file2);
|
|
24620
24801
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
24621
24802
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
|
|
@@ -24626,13 +24807,13 @@ function scanOpencode(agentHome, out) {
|
|
|
24626
24807
|
}
|
|
24627
24808
|
}
|
|
24628
24809
|
function scanZcode(agentHome, out) {
|
|
24629
|
-
const configFile =
|
|
24810
|
+
const configFile = join13(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
24630
24811
|
const config2 = readJson(configFile);
|
|
24631
24812
|
const events = isObj(config2) && isObj(config2[HOOKS_KEY]) ? config2[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
24632
24813
|
for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
24633
24814
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
|
|
24634
24815
|
}
|
|
24635
|
-
const hooksFile =
|
|
24816
|
+
const hooksFile = join13(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
24636
24817
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
24637
24818
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
|
|
24638
24819
|
}
|
|
@@ -24656,14 +24837,14 @@ function firstTmpMatch(dir) {
|
|
|
24656
24837
|
}
|
|
24657
24838
|
}
|
|
24658
24839
|
function scanAll(home, tmp, out) {
|
|
24659
|
-
const root =
|
|
24660
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
24840
|
+
const root = join13(home, DATA_ROOT.slice(1));
|
|
24841
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join13(root, name), V1_REASON.dataRoot, out);
|
|
24661
24842
|
if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
24662
24843
|
}
|
|
24663
24844
|
function detectV1(agent, home, scope = {}) {
|
|
24664
24845
|
const out = [];
|
|
24665
24846
|
const project = scope.project;
|
|
24666
|
-
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir :
|
|
24847
|
+
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir : join13(home, ...AGENT_HOME_DIR[agent]);
|
|
24667
24848
|
switch (agent) {
|
|
24668
24849
|
case "claude-code":
|
|
24669
24850
|
scanClaudeCode(home, agentHome, out);
|
|
@@ -24676,11 +24857,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24676
24857
|
break;
|
|
24677
24858
|
case "qwen":
|
|
24678
24859
|
claudeShapeSettings(agentHome, out);
|
|
24679
|
-
dataDir(
|
|
24860
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24680
24861
|
break;
|
|
24681
24862
|
case "copilot-cli":
|
|
24682
|
-
v1HookFile(
|
|
24683
|
-
dataDir(
|
|
24863
|
+
v1HookFile(join13(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
24864
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24684
24865
|
break;
|
|
24685
24866
|
case "vscode":
|
|
24686
24867
|
scanVscode(agentHome, project, out);
|
|
@@ -24689,7 +24870,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24689
24870
|
scanKiro(agentHome, project, out);
|
|
24690
24871
|
break;
|
|
24691
24872
|
case "pi":
|
|
24692
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
24873
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join13(agentHome, PI_AGENT_DIR), agentHome, out);
|
|
24693
24874
|
break;
|
|
24694
24875
|
// D-WIN-PIDIR-1: empty is unset
|
|
24695
24876
|
case "opencode":
|
|
@@ -24704,8 +24885,8 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24704
24885
|
}
|
|
24705
24886
|
|
|
24706
24887
|
// src/core/ops/plugin-root.ts
|
|
24707
|
-
import { existsSync as existsSync7, readdirSync as
|
|
24708
|
-
import { dirname as dirname7, isAbsolute as
|
|
24888
|
+
import { existsSync as existsSync7, readdirSync as readdirSync6, readFileSync as readFileSync10, realpathSync as realpathSync4 } from "node:fs";
|
|
24889
|
+
import { dirname as dirname7, isAbsolute as isAbsolute4, join as join14, sep as sep4 } from "node:path";
|
|
24709
24890
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
24710
24891
|
function missing(agent, path8) {
|
|
24711
24892
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
@@ -24746,15 +24927,15 @@ var realOrNull = (path8) => {
|
|
|
24746
24927
|
};
|
|
24747
24928
|
var readOrNull = (file2) => {
|
|
24748
24929
|
try {
|
|
24749
|
-
return
|
|
24930
|
+
return readFileSync10(file2, "utf8");
|
|
24750
24931
|
} catch {
|
|
24751
24932
|
return null;
|
|
24752
24933
|
}
|
|
24753
24934
|
};
|
|
24754
24935
|
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
24755
24936
|
function enabledPlugins(claudeDir, project) {
|
|
24756
|
-
const files = [
|
|
24757
|
-
if (project !== void 0) files.push(
|
|
24937
|
+
const files = [join14(claudeDir, SETTINGS_FILE)];
|
|
24938
|
+
if (project !== void 0) files.push(join14(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join14(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
|
|
24758
24939
|
const out = {};
|
|
24759
24940
|
for (const file2 of files) {
|
|
24760
24941
|
const text = readOrNull(file2);
|
|
@@ -24770,7 +24951,7 @@ function marketplaceChoice(env, worktree) {
|
|
|
24770
24951
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
24771
24952
|
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
24772
24953
|
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
24773
|
-
const record4 = readOrNull(
|
|
24954
|
+
const record4 = readOrNull(join14(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
24774
24955
|
const recorded = record4 === null ? [] : recordedInstalls(record4);
|
|
24775
24956
|
if (recorded.length === 0) return { record: false };
|
|
24776
24957
|
const live = recorded.filter((r) => existsSync7(r.installPath));
|
|
@@ -24793,18 +24974,18 @@ function marketplaceChoice(env, worktree) {
|
|
|
24793
24974
|
}
|
|
24794
24975
|
function marketplaceRoot(adapter, env, worktree) {
|
|
24795
24976
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
24796
|
-
const plugins =
|
|
24797
|
-
const cache =
|
|
24977
|
+
const plugins = join14(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
24978
|
+
const cache = join14(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
24798
24979
|
const script = process.argv[1];
|
|
24799
24980
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
24800
24981
|
const choice = marketplaceChoice(env, worktree);
|
|
24801
24982
|
if ("root" in choice) return choice.root;
|
|
24802
24983
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
24803
24984
|
const cacheReal = realOrNull(cache);
|
|
24804
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync7(
|
|
24805
|
-
const pattern =
|
|
24985
|
+
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync7(join14(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
24986
|
+
const pattern = join14(cache, "*", PLUGIN_NAME);
|
|
24806
24987
|
if (!existsSync7(cache)) throw missing(adapter.id, pattern);
|
|
24807
|
-
const found =
|
|
24988
|
+
const found = readdirSync6(cache).sort().map((marketplace) => join14(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync7(dir));
|
|
24808
24989
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
24809
24990
|
return found[0];
|
|
24810
24991
|
}
|
|
@@ -24817,12 +24998,12 @@ function configEntryRoot(adapter, env) {
|
|
|
24817
24998
|
const value = parseHostConfig(adapter.id, file2, current.text, current.format);
|
|
24818
24999
|
const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
|
|
24819
25000
|
const script = Array.isArray(args) ? args[0] : void 0;
|
|
24820
|
-
if (typeof script !== "string" || !
|
|
25001
|
+
if (typeof script !== "string" || !isAbsolute4(script)) throw missing(adapter.id, file2);
|
|
24821
25002
|
return dirname7(script);
|
|
24822
25003
|
}
|
|
24823
25004
|
function packageDirOf(dir) {
|
|
24824
25005
|
for (let cur = dir; ; ) {
|
|
24825
|
-
if (existsSync7(
|
|
25006
|
+
if (existsSync7(join14(cur, D1_PACKAGE_FILE))) return cur;
|
|
24826
25007
|
const up = dirname7(cur);
|
|
24827
25008
|
if (up === cur) return dir;
|
|
24828
25009
|
cur = up;
|
|
@@ -24837,9 +25018,9 @@ function candidate(adapter, env, worktree) {
|
|
|
24837
25018
|
case "hooks+mcp":
|
|
24838
25019
|
return configEntryRoot(adapter, env);
|
|
24839
25020
|
case "extension":
|
|
24840
|
-
return
|
|
25021
|
+
return join14(adapter.id === "gemini" ? geminiDirOf(env, requireHomeDir(env)) : join14(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id]), EXTENSIONS_DIR_NAME, PLUGIN_NAME);
|
|
24841
25022
|
case "plugin":
|
|
24842
|
-
return
|
|
25023
|
+
return join14(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
24843
25024
|
case "in-process":
|
|
24844
25025
|
return packageDirOf(dirname7(fileURLToPath2(import.meta.url)));
|
|
24845
25026
|
}
|
|
@@ -24854,7 +25035,7 @@ function resolvePluginRoot(adapter, env, worktree) {
|
|
|
24854
25035
|
}
|
|
24855
25036
|
|
|
24856
25037
|
// src/setup/pi-gate.ts
|
|
24857
|
-
import { existsSync as existsSync8, readFileSync as
|
|
25038
|
+
import { existsSync as existsSync8, readFileSync as readFileSync11, realpathSync as realpathSync5 } from "node:fs";
|
|
24858
25039
|
import path4 from "node:path";
|
|
24859
25040
|
var EXTENSIONS_KEY = "extensions";
|
|
24860
25041
|
var PROJECT_DIR = ".pi";
|
|
@@ -24864,7 +25045,7 @@ var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
|
24864
25045
|
function load(file2) {
|
|
24865
25046
|
if (!existsSync8(file2)) return void 0;
|
|
24866
25047
|
try {
|
|
24867
|
-
return { file: file2, doc: parseHostConfig("pi", file2, hostText(
|
|
25048
|
+
return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync11(file2, "utf8")), "json") };
|
|
24868
25049
|
} catch {
|
|
24869
25050
|
return void 0;
|
|
24870
25051
|
}
|
|
@@ -24923,8 +25104,8 @@ function piInstalledIn(env, home, pkgDir, cwd) {
|
|
|
24923
25104
|
}
|
|
24924
25105
|
|
|
24925
25106
|
// src/core/ops/doctor-env.ts
|
|
24926
|
-
import { existsSync as existsSync9, readFileSync as
|
|
24927
|
-
import { isAbsolute as
|
|
25107
|
+
import { existsSync as existsSync9, readFileSync as readFileSync12, realpathSync as realpathSync6 } from "node:fs";
|
|
25108
|
+
import { isAbsolute as isAbsolute5, join as join15, relative as relative4 } from "node:path";
|
|
24928
25109
|
function pass(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
24929
25110
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
24930
25111
|
}
|
|
@@ -24939,7 +25120,7 @@ function warn(id2, detail, fixCommand) {
|
|
|
24939
25120
|
}
|
|
24940
25121
|
function bundleVersion(bundleDir2) {
|
|
24941
25122
|
try {
|
|
24942
|
-
const v = JSON.parse(
|
|
25123
|
+
const v = JSON.parse(readFileSync12(join15(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24943
25124
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24944
25125
|
} catch {
|
|
24945
25126
|
return void 0;
|
|
@@ -25093,7 +25274,7 @@ function checkMcp(ctx, adapter) {
|
|
|
25093
25274
|
function piCwdInside(worktree, piCwd) {
|
|
25094
25275
|
if (piCwd === void 0 || !existsSync9(piCwd)) return false;
|
|
25095
25276
|
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
25096
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
25277
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute5(rel);
|
|
25097
25278
|
}
|
|
25098
25279
|
function checkProject(i) {
|
|
25099
25280
|
const bad = fail2("D7", D7_DETAIL(i.project.source), D7_FIX);
|
|
@@ -25101,6 +25282,20 @@ function checkProject(i) {
|
|
|
25101
25282
|
if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
|
|
25102
25283
|
return pass("D7");
|
|
25103
25284
|
}
|
|
25285
|
+
function projectOrMissing(ctx) {
|
|
25286
|
+
try {
|
|
25287
|
+
return { project: ctx.project };
|
|
25288
|
+
} catch (err) {
|
|
25289
|
+
if (err instanceof CtxError && err.code === "NO_PROJECT") return { missing: String(err.vars.kind) };
|
|
25290
|
+
throw err;
|
|
25291
|
+
}
|
|
25292
|
+
}
|
|
25293
|
+
function noProjectRow(kind) {
|
|
25294
|
+
return fail2("D7", D7_NO_PROJECT_DETAIL(kind), D7_FIX);
|
|
25295
|
+
}
|
|
25296
|
+
function needsProjectRow(id2) {
|
|
25297
|
+
return unknown2(id2, DOCTOR_NEEDS_PROJECT_DETAIL);
|
|
25298
|
+
}
|
|
25104
25299
|
function checkMode(adapter, hostPermission) {
|
|
25105
25300
|
if (hostPermission === "missing") return fail2("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
|
|
25106
25301
|
if (hostPermission === "wired") return pass("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
|
|
@@ -25123,8 +25318,8 @@ function checkRuntimes(env, shellRow) {
|
|
|
25123
25318
|
}
|
|
25124
25319
|
|
|
25125
25320
|
// src/core/ops/omp-import.ts
|
|
25126
|
-
import { join as
|
|
25127
|
-
var { existsSync: existsSync10, readFileSync:
|
|
25321
|
+
import { join as join16 } from "node:path";
|
|
25322
|
+
var { existsSync: existsSync10, readFileSync: readFileSync13 } = process.getBuiltinModule("node:fs");
|
|
25128
25323
|
var OMP_DISABLED_SERVERS_KEY = "disabledServers";
|
|
25129
25324
|
var OMP_MCP_FILE = "mcp.json";
|
|
25130
25325
|
var OMP_CONFIG_FILE = "config.yml";
|
|
@@ -25133,12 +25328,12 @@ var DISABLED_PROVIDERS = "disabledProviders";
|
|
|
25133
25328
|
var CLAUDE_PROVIDER = "claude";
|
|
25134
25329
|
var ALL_PROVIDERS = ["*", "all"];
|
|
25135
25330
|
function ompImportFiles(home) {
|
|
25136
|
-
const agentDir =
|
|
25137
|
-
return { config:
|
|
25331
|
+
const agentDir = join16(home, ...AGENT_HOME_DIR.omp, PI_AGENT_DIR);
|
|
25332
|
+
return { config: join16(agentDir, OMP_CONFIG_FILE), mcp: join16(agentDir, OMP_MCP_FILE), claude: join16(home, CLAUDE_USER_CONFIG_FILE) };
|
|
25138
25333
|
}
|
|
25139
25334
|
function readText2(file2) {
|
|
25140
25335
|
try {
|
|
25141
|
-
return existsSync10(file2) ? hostText(
|
|
25336
|
+
return existsSync10(file2) ? hostText(readFileSync13(file2, "utf8")) : void 0;
|
|
25142
25337
|
} catch {
|
|
25143
25338
|
return void 0;
|
|
25144
25339
|
}
|
|
@@ -25266,11 +25461,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
25266
25461
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
25267
25462
|
function mcpFile(row5, home, env) {
|
|
25268
25463
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
25269
|
-
if (row5.id === "codex") return
|
|
25464
|
+
if (row5.id === "codex") return join17(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
25270
25465
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
25271
|
-
if (row5.id === "opencode") return
|
|
25466
|
+
if (row5.id === "opencode") return join17(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
25272
25467
|
if (row5.id === "pi") {
|
|
25273
|
-
return
|
|
25468
|
+
return join17(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
25274
25469
|
}
|
|
25275
25470
|
return null;
|
|
25276
25471
|
}
|
|
@@ -25283,27 +25478,27 @@ function codexNativeDir(env, home) {
|
|
|
25283
25478
|
const codexDir = codexDirOf(env, home);
|
|
25284
25479
|
let enabled;
|
|
25285
25480
|
try {
|
|
25286
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
25481
|
+
enabled = hostConfigValueAt(readParsed("codex", join17(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
25287
25482
|
} catch {
|
|
25288
25483
|
return null;
|
|
25289
25484
|
}
|
|
25290
25485
|
if (enabled !== true) return null;
|
|
25291
|
-
const cache =
|
|
25486
|
+
const cache = join17(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
25292
25487
|
if (!existsSync11(cache)) return null;
|
|
25293
25488
|
const found = [];
|
|
25294
|
-
for (const market of
|
|
25295
|
-
const plugin =
|
|
25489
|
+
for (const market of readdirSync7(cache)) {
|
|
25490
|
+
const plugin = join17(cache, market, SERVER_KEY);
|
|
25296
25491
|
if (!existsSync11(plugin)) continue;
|
|
25297
|
-
for (const version2 of
|
|
25298
|
-
const dir =
|
|
25299
|
-
if (existsSync11(
|
|
25492
|
+
for (const version2 of readdirSync7(plugin).sort()) {
|
|
25493
|
+
const dir = join17(plugin, version2, CODEX_PLUGIN_SUBDIR);
|
|
25494
|
+
if (existsSync11(join17(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
25300
25495
|
}
|
|
25301
25496
|
}
|
|
25302
25497
|
return found.length === 0 ? null : found[found.length - 1];
|
|
25303
25498
|
}
|
|
25304
25499
|
function nativeMcpWrong(dir, row5) {
|
|
25305
25500
|
try {
|
|
25306
|
-
const entry = hostConfigValueAt(readParsed(row5.id,
|
|
25501
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join17(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
25307
25502
|
if (!isObject4(entry)) return true;
|
|
25308
25503
|
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
25309
25504
|
const script = args[0];
|
|
@@ -25374,17 +25569,17 @@ function opencodePluginDirs(configDir, worktree) {
|
|
|
25374
25569
|
return [configDir, opencodeProjectDir(worktree)];
|
|
25375
25570
|
}
|
|
25376
25571
|
function opencodeProjectDir(worktree) {
|
|
25377
|
-
return
|
|
25572
|
+
return join17(worktree, OPENCODE_PROJECT_DIR);
|
|
25378
25573
|
}
|
|
25379
25574
|
function packageResolves(fromDir) {
|
|
25380
25575
|
for (let d = fromDir; ; d = dirname8(d)) {
|
|
25381
|
-
if (existsSync11(
|
|
25576
|
+
if (existsSync11(join17(d, NODE_MODULES_DIR, SERVER_KEY, PACKAGE_JSON_FILE))) return true;
|
|
25382
25577
|
if (dirname8(d) === d) return false;
|
|
25383
25578
|
}
|
|
25384
25579
|
}
|
|
25385
25580
|
function opencodeDirPlugins(dirs) {
|
|
25386
25581
|
const bundle = opencodePluginFile();
|
|
25387
|
-
const ownFile =
|
|
25582
|
+
const ownFile = join17(bundle, ...OPENCODE_PLUGIN_PATH).split("\\").join("/");
|
|
25388
25583
|
const isModule = (p) => OWN_PLUGIN_MODULES.includes(p);
|
|
25389
25584
|
const isPath = (p) => {
|
|
25390
25585
|
if (p === ownFile || p === `${FILE_URL_PREFIX}${ownFile}`) return true;
|
|
@@ -25394,20 +25589,20 @@ function opencodeDirPlugins(dirs) {
|
|
|
25394
25589
|
};
|
|
25395
25590
|
const out = [];
|
|
25396
25591
|
for (const dir of dirs) {
|
|
25397
|
-
const pdir =
|
|
25592
|
+
const pdir = join17(dir, OPENCODE_PLUGINS_DIR);
|
|
25398
25593
|
let names;
|
|
25399
25594
|
try {
|
|
25400
|
-
names =
|
|
25595
|
+
names = readdirSync7(pdir);
|
|
25401
25596
|
} catch {
|
|
25402
25597
|
continue;
|
|
25403
25598
|
}
|
|
25404
25599
|
for (const name of names) {
|
|
25405
|
-
const loose = OPENCODE_PLUGIN_EXTS.some((x) => name.endsWith(x)) ? [
|
|
25406
|
-
const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x) =>
|
|
25600
|
+
const loose = OPENCODE_PLUGIN_EXTS.some((x) => name.endsWith(x)) ? [join17(pdir, name)] : [];
|
|
25601
|
+
const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x) => join17(pdir, name, `${OPENCODE_PLUGIN_INDEX}${x}`))];
|
|
25407
25602
|
for (const f of files) {
|
|
25408
25603
|
let text;
|
|
25409
25604
|
try {
|
|
25410
|
-
const b =
|
|
25605
|
+
const b = readFileSync14(f);
|
|
25411
25606
|
if (b.length > OPENCODE_DIR_FILE_MAX) continue;
|
|
25412
25607
|
text = b.toString("utf8");
|
|
25413
25608
|
} catch {
|
|
@@ -25418,7 +25613,7 @@ function opencodeDirPlugins(dirs) {
|
|
|
25418
25613
|
const loads = lits.some((p) => {
|
|
25419
25614
|
if (isModule(p)) return packageResolves(dirname8(f));
|
|
25420
25615
|
const bare2 = p.startsWith(FILE_URL_PREFIX) ? p.slice(FILE_URL_PREFIX.length) : p;
|
|
25421
|
-
return existsSync11(
|
|
25616
|
+
return existsSync11(isAbsolute6(bare2) ? bare2 : resolve9(dirname8(f), bare2));
|
|
25422
25617
|
});
|
|
25423
25618
|
out.push({ file: f, loads });
|
|
25424
25619
|
}
|
|
@@ -25437,18 +25632,18 @@ function opencodeMcpOwn(entry) {
|
|
|
25437
25632
|
}
|
|
25438
25633
|
function opencodeFileValue(file2) {
|
|
25439
25634
|
if (!existsSync11(file2)) return {};
|
|
25440
|
-
return parseHostConfig("opencode", file2, hostText(
|
|
25635
|
+
return parseHostConfig("opencode", file2, hostText(readFileSync14(file2, "utf8")), "jsonc");
|
|
25441
25636
|
}
|
|
25442
25637
|
function opencodeValueListed(value) {
|
|
25443
25638
|
const bundle = opencodePluginFile();
|
|
25444
|
-
const own2 = [bundle,
|
|
25639
|
+
const own2 = [bundle, join17(bundle, ...OPENCODE_PLUGIN_PATH)];
|
|
25445
25640
|
if ([OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list2(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own2)))) return true;
|
|
25446
25641
|
const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
|
|
25447
25642
|
return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
|
|
25448
25643
|
}
|
|
25449
25644
|
function opencodeListed(file2, worktree) {
|
|
25450
25645
|
const dirs = [dirname8(file2), worktree];
|
|
25451
|
-
if (dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(
|
|
25646
|
+
if (dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(join17(dir, name)))))) return true;
|
|
25452
25647
|
return opencodeDirPlugin(opencodePluginDirs(dirname8(file2), worktree)) !== void 0;
|
|
25453
25648
|
}
|
|
25454
25649
|
function mcpWrong(row5, home, env, worktree) {
|
|
@@ -25470,7 +25665,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
25470
25665
|
function hookFile(row5, spec, home, env, worktree) {
|
|
25471
25666
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
25472
25667
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
25473
|
-
const file2 = native !== null ?
|
|
25668
|
+
const file2 = native !== null ? join17(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join17(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join17(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join17(kiroDirOf(env, home), ...spec.file.slice(1)) : join17(root, ...spec.file);
|
|
25474
25669
|
return file2;
|
|
25475
25670
|
}
|
|
25476
25671
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -25481,7 +25676,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
25481
25676
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
25482
25677
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
25483
25678
|
if (row5.id === "codex") {
|
|
25484
|
-
const config2 = readParsed(row5.id,
|
|
25679
|
+
const config2 = readParsed(row5.id, join17(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
25485
25680
|
if (hostConfigValueAt(config2, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
25486
25681
|
}
|
|
25487
25682
|
} catch {
|
|
@@ -25526,13 +25721,13 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
25526
25721
|
function checkPiInstall(env, home, worktree) {
|
|
25527
25722
|
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
25528
25723
|
if (found !== void 0) return { ...pass2("D3"), detail: found };
|
|
25529
|
-
return fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN +
|
|
25724
|
+
return fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join17(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
|
|
25530
25725
|
}
|
|
25531
25726
|
var OMP_PLUGINS_DIR = "plugins";
|
|
25532
25727
|
var OMP_LOCK_FILE = "omp-plugins.lock.json";
|
|
25533
25728
|
function readJson2(file2) {
|
|
25534
25729
|
try {
|
|
25535
|
-
const doc = JSON.parse(
|
|
25730
|
+
const doc = JSON.parse(readFileSync14(file2, "utf8"));
|
|
25536
25731
|
return typeof doc === "object" && doc !== null ? doc : void 0;
|
|
25537
25732
|
} catch {
|
|
25538
25733
|
return void 0;
|
|
@@ -25543,9 +25738,9 @@ function ownEntry(doc, key) {
|
|
|
25543
25738
|
return typeof map2 === "object" && map2 !== null ? map2[SERVER_KEY] : void 0;
|
|
25544
25739
|
}
|
|
25545
25740
|
function checkOmpInstall(home) {
|
|
25546
|
-
const dir =
|
|
25547
|
-
const lock =
|
|
25548
|
-
const pkg =
|
|
25741
|
+
const dir = join17(home, ...AGENT_HOME_DIR.omp, OMP_PLUGINS_DIR);
|
|
25742
|
+
const lock = join17(dir, OMP_LOCK_FILE);
|
|
25743
|
+
const pkg = join17(dir, PI_PACKAGE_JSON_FILE);
|
|
25549
25744
|
const entry = ownEntry(readJson2(lock), "plugins");
|
|
25550
25745
|
const missing2 = (file2) => fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + file2, NATIVE_INSTALL.omp[0]);
|
|
25551
25746
|
if (typeof entry !== "object" || entry === null) return missing2(lock);
|
|
@@ -25582,10 +25777,10 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
25582
25777
|
}
|
|
25583
25778
|
function checkDoubleFire(agent, worktree) {
|
|
25584
25779
|
if (agent !== "claude-code" && agent !== "vscode") return pass2("D5b");
|
|
25585
|
-
const claude = parsedOrNull(agent,
|
|
25780
|
+
const claude = parsedOrNull(agent, join17(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
25586
25781
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
25587
25782
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
25588
|
-
const vscode = parsedOrNull(agent,
|
|
25783
|
+
const vscode = parsedOrNull(agent, join17(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
25589
25784
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
25590
25785
|
return hooksOn && useClaudeHooks ? fail3("D5b", D5B_DETAIL, D5B_FIX) : pass2("D5b");
|
|
25591
25786
|
}
|
|
@@ -25596,7 +25791,7 @@ function configPaths(row5, env, worktree) {
|
|
|
25596
25791
|
const mcp = mcpFile(row5, home, env);
|
|
25597
25792
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
25598
25793
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
25599
|
-
if (native !== null) out.push({ label: "Codex plugin MCP", path:
|
|
25794
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join17(native, CODEX_PLUGIN_MCP_FILE) });
|
|
25600
25795
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
25601
25796
|
if (spec !== null) {
|
|
25602
25797
|
try {
|
|
@@ -25616,7 +25811,7 @@ function configPaths(row5, env, worktree) {
|
|
|
25616
25811
|
}
|
|
25617
25812
|
|
|
25618
25813
|
// src/core/ops/doctor-db.ts
|
|
25619
|
-
import { existsSync as existsSync12, statSync as
|
|
25814
|
+
import { existsSync as existsSync12, statSync as statSync7 } from "node:fs";
|
|
25620
25815
|
var unknown3 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
|
|
25621
25816
|
var pass3 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
|
|
25622
25817
|
var fail4 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -25627,7 +25822,7 @@ function isCorrupt2(err) {
|
|
|
25627
25822
|
const primary = code & SQLITE_PRIMARY_CODE_MASK;
|
|
25628
25823
|
return primary === SQLITE_CORRUPT_CODE || primary === SQLITE_NOTADB_CODE;
|
|
25629
25824
|
}
|
|
25630
|
-
var
|
|
25825
|
+
var message3 = (err) => err instanceof Error ? err.message : String(err);
|
|
25631
25826
|
async function loadSqlite2() {
|
|
25632
25827
|
try {
|
|
25633
25828
|
return await import(SQLITE_MODULE);
|
|
@@ -25658,7 +25853,7 @@ function orphanFiles(dbPath) {
|
|
|
25658
25853
|
const files = [];
|
|
25659
25854
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
25660
25855
|
const path8 = dbPath + suffix;
|
|
25661
|
-
if (existsSync12(path8)) files.push({ path: path8, bytes:
|
|
25856
|
+
if (existsSync12(path8)) files.push({ path: path8, bytes: statSync7(path8).size });
|
|
25662
25857
|
}
|
|
25663
25858
|
return files.length > 0 && !existsSync12(dbPath) ? files : [];
|
|
25664
25859
|
}
|
|
@@ -25686,7 +25881,7 @@ async function checkDb(project) {
|
|
|
25686
25881
|
return { row: pass3("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
25687
25882
|
} catch (err) {
|
|
25688
25883
|
if (isCorrupt2(err)) return { row: fail4(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale: false, integrityFailed: true, orphan: [] };
|
|
25689
|
-
return { row: unknown3("D8",
|
|
25884
|
+
return { row: unknown3("D8", message3(err)), ...clean };
|
|
25690
25885
|
} finally {
|
|
25691
25886
|
raw?.close();
|
|
25692
25887
|
}
|
|
@@ -25702,14 +25897,14 @@ async function checkIndex(project) {
|
|
|
25702
25897
|
const chunks = Number(cell(raw.prepare("SELECT count(*) FROM chunks").get()));
|
|
25703
25898
|
return pass3("D9", D9_INDEX_DETAIL(sources, chunks));
|
|
25704
25899
|
} catch (err) {
|
|
25705
|
-
return unknown3("D9",
|
|
25900
|
+
return unknown3("D9", message3(err));
|
|
25706
25901
|
} finally {
|
|
25707
25902
|
raw?.close();
|
|
25708
25903
|
}
|
|
25709
25904
|
}
|
|
25710
25905
|
|
|
25711
25906
|
// src/core/ops/doctor-hook.ts
|
|
25712
|
-
import { existsSync as existsSync14, mkdirSync as
|
|
25907
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync5, mkdtempSync, readFileSync as readFileSync15, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
25713
25908
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
25714
25909
|
import path7 from "node:path";
|
|
25715
25910
|
|
|
@@ -27543,7 +27738,7 @@ import { spawn as spawn3, spawnSync as spawnSync2 } from "node:child_process";
|
|
|
27543
27738
|
|
|
27544
27739
|
// src/setup/spawn-bin.ts
|
|
27545
27740
|
import { spawnSync } from "node:child_process";
|
|
27546
|
-
import { accessSync as accessSync2, constants as fsc, statSync as
|
|
27741
|
+
import { accessSync as accessSync2, constants as fsc, statSync as statSync8 } from "node:fs";
|
|
27547
27742
|
import path5 from "node:path";
|
|
27548
27743
|
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
27549
27744
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
@@ -27561,7 +27756,7 @@ function whichBin(bin, env, platform = process.platform) {
|
|
|
27561
27756
|
const f = path5.join(dir, n);
|
|
27562
27757
|
try {
|
|
27563
27758
|
accessSync2(f, fsc.X_OK);
|
|
27564
|
-
if (
|
|
27759
|
+
if (statSync8(f).isFile()) return f;
|
|
27565
27760
|
} catch {
|
|
27566
27761
|
}
|
|
27567
27762
|
}
|
|
@@ -27763,7 +27958,7 @@ function loadFixture(bundleDir2, agent) {
|
|
|
27763
27958
|
if (!existsSync14(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
27764
27959
|
let all;
|
|
27765
27960
|
try {
|
|
27766
|
-
all = JSON.parse(hostText(
|
|
27961
|
+
all = JSON.parse(hostText(readFileSync15(file2, "utf8")));
|
|
27767
27962
|
} catch (err) {
|
|
27768
27963
|
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
27769
27964
|
}
|
|
@@ -27855,7 +28050,7 @@ async function mediaProbe(i, timeoutMs) {
|
|
|
27855
28050
|
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-media-"));
|
|
27856
28051
|
try {
|
|
27857
28052
|
const filePath = path7.join(home, "d5-media-probe.png");
|
|
27858
|
-
|
|
28053
|
+
writeFileSync3(filePath, Buffer.concat([PNG_SIGNATURE, Buffer.alloc(OUTPUT_CAP + 1)]));
|
|
27859
28054
|
const node = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home });
|
|
27860
28055
|
const r = await runProcess([node.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
27861
28056
|
cwd: i.bundleDir,
|
|
@@ -27882,9 +28077,9 @@ async function ownProbe(i, timeoutMs) {
|
|
|
27882
28077
|
try {
|
|
27883
28078
|
const cfg = path7.join(home, ".claude");
|
|
27884
28079
|
const refs = path7.join(cfg, "skills", "d5-probe", "references");
|
|
27885
|
-
|
|
28080
|
+
mkdirSync5(refs, { recursive: true });
|
|
27886
28081
|
const filePath = path7.join(refs, "d5-own-probe.md");
|
|
27887
|
-
|
|
28082
|
+
writeFileSync3(filePath, "# d5 own probe\n".repeat(Math.ceil((OUTPUT_CAP + 1) / 15)));
|
|
27888
28083
|
const node = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, CLAUDE_CONFIG_DIR: cfg });
|
|
27889
28084
|
const r = await runProcess([node.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
27890
28085
|
cwd: i.bundleDir,
|
|
@@ -28038,14 +28233,14 @@ async function checkHookRoundTrip(i) {
|
|
|
28038
28233
|
}
|
|
28039
28234
|
|
|
28040
28235
|
// src/core/ops/db-heal.ts
|
|
28041
|
-
import { existsSync as existsSync15, mkdirSync as
|
|
28042
|
-
import { basename as basename4, dirname as dirname9, join as
|
|
28236
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync7, rmSync as rmSync4 } from "node:fs";
|
|
28237
|
+
import { basename as basename4, dirname as dirname9, join as join19 } from "node:path";
|
|
28043
28238
|
|
|
28044
28239
|
// src/core/store/owners.ts
|
|
28045
|
-
import { mkdirSync as
|
|
28046
|
-
import { basename as basename3, join as
|
|
28240
|
+
import { mkdirSync as mkdirSync6, readdirSync as readdirSync8, readFileSync as readFileSync16, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
28241
|
+
import { basename as basename3, join as join18 } from "node:path";
|
|
28047
28242
|
function ownersDir(configDir, projectKey) {
|
|
28048
|
-
return
|
|
28243
|
+
return join18(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
28049
28244
|
}
|
|
28050
28245
|
function errCode3(err) {
|
|
28051
28246
|
return err.code;
|
|
@@ -28065,7 +28260,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
28065
28260
|
const dir = ownersDir(configDir, projectKey);
|
|
28066
28261
|
let names;
|
|
28067
28262
|
try {
|
|
28068
|
-
names =
|
|
28263
|
+
names = readdirSync8(dir);
|
|
28069
28264
|
} catch (err) {
|
|
28070
28265
|
if (errCode3(err) === "ENOENT") return [];
|
|
28071
28266
|
throw err;
|
|
@@ -28073,10 +28268,10 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
28073
28268
|
const live = [];
|
|
28074
28269
|
for (const name of names) {
|
|
28075
28270
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
28076
|
-
const file2 =
|
|
28271
|
+
const file2 = join18(dir, name);
|
|
28077
28272
|
let text;
|
|
28078
28273
|
try {
|
|
28079
|
-
text =
|
|
28274
|
+
text = readFileSync16(file2, "utf8");
|
|
28080
28275
|
} catch (err) {
|
|
28081
28276
|
if (errCode3(err) === "ENOENT") continue;
|
|
28082
28277
|
throw err;
|
|
@@ -28145,11 +28340,11 @@ function utcStamp(now) {
|
|
|
28145
28340
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
28146
28341
|
}
|
|
28147
28342
|
function makeOrphanDir(projectDir) {
|
|
28148
|
-
const base =
|
|
28343
|
+
const base = join19(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
28149
28344
|
for (let n = 1; ; n += 1) {
|
|
28150
28345
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
28151
28346
|
try {
|
|
28152
|
-
|
|
28347
|
+
mkdirSync7(dir);
|
|
28153
28348
|
return dir;
|
|
28154
28349
|
} catch (err) {
|
|
28155
28350
|
if (err.code !== "EEXIST") throw err;
|
|
@@ -28162,7 +28357,7 @@ async function healOrphan(project, files, row5) {
|
|
|
28162
28357
|
try {
|
|
28163
28358
|
dir = makeOrphanDir(dirname9(project.dbPath));
|
|
28164
28359
|
for (const f of files) {
|
|
28165
|
-
const to =
|
|
28360
|
+
const to = join19(dir, basename4(f.path));
|
|
28166
28361
|
renameWithRetry(f.path, to);
|
|
28167
28362
|
moved.push({ path: to, bytes: f.bytes });
|
|
28168
28363
|
}
|
|
@@ -28260,8 +28455,8 @@ function unsupportedHostOf(sig) {
|
|
|
28260
28455
|
|
|
28261
28456
|
// src/core/ops/doctor-issue.ts
|
|
28262
28457
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
28263
|
-
import { closeSync as closeSync2, existsSync as existsSync16, fstatSync, mkdirSync as
|
|
28264
|
-
import { delimiter, dirname as dirname10, join as
|
|
28458
|
+
import { closeSync as closeSync2, existsSync as existsSync16, fstatSync, mkdirSync as mkdirSync8, openSync as openSync2, readFileSync as readFileSync17, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync5 } from "node:fs";
|
|
28459
|
+
import { delimiter, dirname as dirname10, join as join20 } from "node:path";
|
|
28265
28460
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
28266
28461
|
function tildeOf(env) {
|
|
28267
28462
|
const home = homeDirOf(env);
|
|
@@ -28317,8 +28512,8 @@ function onPath(env, tool) {
|
|
|
28317
28512
|
const out = [];
|
|
28318
28513
|
for (const dir of (envValue(env, "PATH") ?? "").split(delimiter)) {
|
|
28319
28514
|
if (dir === "") continue;
|
|
28320
|
-
for (const n of names) if (existsSync16(
|
|
28321
|
-
out.push(
|
|
28515
|
+
for (const n of names) if (existsSync16(join20(dir, n))) {
|
|
28516
|
+
out.push(join20(dir, n));
|
|
28322
28517
|
break;
|
|
28323
28518
|
}
|
|
28324
28519
|
}
|
|
@@ -28346,9 +28541,11 @@ function hookLogTail(env) {
|
|
|
28346
28541
|
}
|
|
28347
28542
|
async function journalRows(ctx) {
|
|
28348
28543
|
const head2 = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
28349
|
-
|
|
28544
|
+
const p = projectOrMissing(ctx);
|
|
28545
|
+
if ("missing" in p) return [`(no project: ${D7_NO_PROJECT_DETAIL(p.missing)})`];
|
|
28546
|
+
if (!existsSync16(p.project.dbPath)) return [`(context.db is absent at ${p.project.dbPath})`];
|
|
28350
28547
|
try {
|
|
28351
|
-
const db = await openDb(
|
|
28548
|
+
const db = await openDb(p.project, { readOnly: true });
|
|
28352
28549
|
try {
|
|
28353
28550
|
const rows = db.raw.prepare(`SELECT kind, tool, bytes, ok, exit_code, created_at FROM events ORDER BY seq DESC LIMIT ${DOCTOR_JOURNAL_ROWS}`).all();
|
|
28354
28551
|
const cell5 = (v) => v === null || v === void 0 ? "" : String(v);
|
|
@@ -28364,8 +28561,8 @@ function agentConfig(adapter, env, worktree) {
|
|
|
28364
28561
|
const home = homeDirOf(env);
|
|
28365
28562
|
const files = configPaths(adapter, env, worktree);
|
|
28366
28563
|
if (home !== null) {
|
|
28367
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
28368
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
28564
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join20(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
28565
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join20(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
28369
28566
|
}
|
|
28370
28567
|
const out = [];
|
|
28371
28568
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -28378,7 +28575,7 @@ function agentConfig(adapter, env, worktree) {
|
|
|
28378
28575
|
}
|
|
28379
28576
|
let text = "";
|
|
28380
28577
|
try {
|
|
28381
|
-
text =
|
|
28578
|
+
text = readFileSync17(f.path, "utf8");
|
|
28382
28579
|
} catch (err) {
|
|
28383
28580
|
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
28384
28581
|
continue;
|
|
@@ -28407,6 +28604,7 @@ async function buildIssueBody(i) {
|
|
|
28407
28604
|
const failRows = i.rows.filter((r) => r.status !== "PASS");
|
|
28408
28605
|
const envNames = DOCTOR_ENV_NAMES.map((n) => i.env[n] === void 0 ? `${n} (unset)` : `${n}=${i.env[n]}`);
|
|
28409
28606
|
const pathTools = DOCTOR_PATH_TOOLS.map((t) => `PATH holds ${t}: ${onPath(i.env, t).join(", ") || "(absent)"}`);
|
|
28607
|
+
const p = projectOrMissing(i.ctx);
|
|
28410
28608
|
const sections = {
|
|
28411
28609
|
"Summary": [summaryOf(agent, i.rows, i.unsupported)],
|
|
28412
28610
|
"ctx-report": [i.table],
|
|
@@ -28417,7 +28615,7 @@ async function buildIssueBody(i) {
|
|
|
28417
28615
|
],
|
|
28418
28616
|
"Hook errors": ["hook-errors.log, last " + DOCTOR_HOOK_LOG_LINES + " lines (UTC):", "```", ...hookLogTail(i.env), "```"],
|
|
28419
28617
|
"Journal rows": ["events, newest first, last " + DOCTOR_JOURNAL_ROWS + " (bodies stay local):", ...await journalRows(i.ctx)],
|
|
28420
|
-
"Agent config": agentConfig(i.adapter, i.env,
|
|
28618
|
+
"Agent config": agentConfig(i.adapter, i.env, "project" in p ? p.project.worktree : process.cwd()),
|
|
28421
28619
|
"Expected": ["Expected: <the agent fills this in: what should happen, with the byte count>"],
|
|
28422
28620
|
"Steps": [
|
|
28423
28621
|
"Reproduced: <yes (2 of 2) or 1 of 2>",
|
|
@@ -28438,7 +28636,7 @@ async function buildIssueBody(i) {
|
|
|
28438
28636
|
`git: ${gitVersion(i.env)}`,
|
|
28439
28637
|
...pathTools,
|
|
28440
28638
|
...envNames,
|
|
28441
|
-
`Project: ${
|
|
28639
|
+
"project" in p ? `Project: ${p.project.worktree} (key ${p.project.projectKey})` : `Project: ${D7_NO_PROJECT_DETAIL(p.missing)}`,
|
|
28442
28640
|
"Filed by: <your agent name, version, model id>"
|
|
28443
28641
|
]
|
|
28444
28642
|
};
|
|
@@ -28449,10 +28647,10 @@ async function buildIssueBody(i) {
|
|
|
28449
28647
|
async function writeIssueReport(i) {
|
|
28450
28648
|
const tilde = tildeOf(i.env);
|
|
28451
28649
|
const body = await buildIssueBody(i);
|
|
28452
|
-
const dir =
|
|
28453
|
-
|
|
28454
|
-
const file2 =
|
|
28455
|
-
|
|
28650
|
+
const dir = join20(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
28651
|
+
mkdirSync8(dir, { recursive: true });
|
|
28652
|
+
const file2 = join20(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
28653
|
+
writeFileSync5(file2, body);
|
|
28456
28654
|
const shown2 = tilde(file2);
|
|
28457
28655
|
const title = issueTitle(i.adapter.id, i.rows, i.unsupported);
|
|
28458
28656
|
const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
|
|
@@ -28464,6 +28662,25 @@ function formUrl(title, summary) {
|
|
|
28464
28662
|
return full.length < ISSUE_URL_MAX ? full : base;
|
|
28465
28663
|
}
|
|
28466
28664
|
|
|
28665
|
+
// src/core/index/text.ts
|
|
28666
|
+
function storeText(db, project, sessionId, sourceKind, label2, text, kind, chunks = chunkText(text, kind)) {
|
|
28667
|
+
const sourceId = ftsInsert(db, {
|
|
28668
|
+
projectKey: project.projectKey,
|
|
28669
|
+
sessionId,
|
|
28670
|
+
worktree: project.worktree,
|
|
28671
|
+
agent: project.agent,
|
|
28672
|
+
kind: sourceKind,
|
|
28673
|
+
label: label2,
|
|
28674
|
+
bytes: Buffer.byteLength(text, "utf8"),
|
|
28675
|
+
chunkCount: chunks.length,
|
|
28676
|
+
createdAt: Date.now()
|
|
28677
|
+
}, chunks);
|
|
28678
|
+
return { sourceId, chunks: chunks.length };
|
|
28679
|
+
}
|
|
28680
|
+
function indexText(db, ctx, sessionId, source, text, kind, chunks) {
|
|
28681
|
+
return storeText(db, ctx, sessionId, "content", source, text, kind, chunks);
|
|
28682
|
+
}
|
|
28683
|
+
|
|
28467
28684
|
// src/core/tools/doctor.ts
|
|
28468
28685
|
var ctxDoctorSchema = external_exports.object({}).strict();
|
|
28469
28686
|
function lineOf2(err) {
|
|
@@ -28477,10 +28694,10 @@ async function guard(id2, run) {
|
|
|
28477
28694
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail: lineOf2(err) };
|
|
28478
28695
|
}
|
|
28479
28696
|
}
|
|
28480
|
-
async function codexDb(
|
|
28481
|
-
if (adapter.id !== "codex" || !existsSync17(
|
|
28697
|
+
async function codexDb(project, adapter) {
|
|
28698
|
+
if (adapter.id !== "codex" || !existsSync17(project.dbPath)) return null;
|
|
28482
28699
|
try {
|
|
28483
|
-
return await openDb(
|
|
28700
|
+
return await openDb(project, { readOnly: true });
|
|
28484
28701
|
} catch {
|
|
28485
28702
|
return null;
|
|
28486
28703
|
}
|
|
@@ -28491,12 +28708,12 @@ function d1UpdateCommand(agent, env, other) {
|
|
|
28491
28708
|
function unsupportedRow(id2, h) {
|
|
28492
28709
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "WARN", detail: UNSUPPORTED_HOST_LINE(h.name) };
|
|
28493
28710
|
}
|
|
28494
|
-
async function hookRow(ctx, adapter, host) {
|
|
28495
|
-
const db = await codexDb(
|
|
28711
|
+
async function hookRow(ctx, project, adapter, host) {
|
|
28712
|
+
const db = await codexDb(project, adapter);
|
|
28496
28713
|
const runStart = Date.now();
|
|
28497
28714
|
try {
|
|
28498
28715
|
const row5 = await checkHookRoundTrip({
|
|
28499
|
-
worktree:
|
|
28716
|
+
worktree: project.worktree,
|
|
28500
28717
|
agent: adapter.id,
|
|
28501
28718
|
bundleDir: host.bundleDir,
|
|
28502
28719
|
env: buildChildEnv(host.env),
|
|
@@ -28514,18 +28731,20 @@ async function hookRow(ctx, adapter, host) {
|
|
|
28514
28731
|
}
|
|
28515
28732
|
}
|
|
28516
28733
|
function ownServerId(configDir, projectKey) {
|
|
28517
|
-
const dir =
|
|
28734
|
+
const dir = join21(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
28518
28735
|
if (!existsSync17(dir)) return "";
|
|
28519
|
-
for (const name of
|
|
28736
|
+
for (const name of readdirSync9(dir)) {
|
|
28520
28737
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
28521
|
-
if (
|
|
28738
|
+
if (readFileSync18(join21(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
28522
28739
|
}
|
|
28523
28740
|
return "";
|
|
28524
28741
|
}
|
|
28525
28742
|
async function runDoctorChecks(ctx, adapter, host0) {
|
|
28526
28743
|
const host = adapter.id === "codex" ? { ...host0, env: { ...host0.env, CODEX_HOME: codexRunDirOf(host0.env, homeDirOf(host0.env) ?? "", host0.bundleDir) } } : host0;
|
|
28527
28744
|
const env = host.env;
|
|
28528
|
-
const
|
|
28745
|
+
const p = projectOrMissing(ctx);
|
|
28746
|
+
if ("missing" in p) return noProjectRows(ctx, adapter, host, p.missing);
|
|
28747
|
+
const project = p.project;
|
|
28529
28748
|
const other = adapter.installMode === "in-process" ? void 0 : unsupportedHostOf({ clientName: ctx.clientInfo?.name, bundleDir: host.bundleDir, env });
|
|
28530
28749
|
let integrityFailed = false;
|
|
28531
28750
|
let orphan = [];
|
|
@@ -28535,7 +28754,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
28535
28754
|
D3: () => other !== void 0 ? unsupportedRow("D3", other) : checkHostConfig(adapter, env, project.worktree),
|
|
28536
28755
|
// D-UNSUPPORTED-HOSTS-1
|
|
28537
28756
|
D4: () => checkV1Leftovers(adapter.id, requireHomeDir(env), { project: project.worktree, piAgentDir: piAgentDirOf(env, requireHomeDir(env)), claudeDir: claudeDirOf(env, requireHomeDir(env)), codexDir: codexDirOf(env, requireHomeDir(env)), geminiDir: geminiDirOf(env, requireHomeDir(env)), copilotDir: copilotDirOf(env, requireHomeDir(env)), kiroDir: kiroDirOf(env, requireHomeDir(env)), opencodeDir: opencodeDirOf(env, requireHomeDir(env)) }),
|
|
28538
|
-
D5: () => other !== void 0 ? unsupportedRow("D5", other) : hookRow(ctx, adapter, host),
|
|
28757
|
+
D5: () => other !== void 0 ? unsupportedRow("D5", other) : hookRow(ctx, project, adapter, host),
|
|
28539
28758
|
D5b: () => checkDoubleFire(adapter.id, project.worktree),
|
|
28540
28759
|
D6: () => checkMcp(ctx, adapter),
|
|
28541
28760
|
D7: () => checkProject({ project, adapter, piCwd: host.piCwd }),
|
|
@@ -28565,6 +28784,28 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
28565
28784
|
});
|
|
28566
28785
|
return rows;
|
|
28567
28786
|
}
|
|
28787
|
+
async function noProjectRows(ctx, adapter, host, missing2) {
|
|
28788
|
+
const env = host.env;
|
|
28789
|
+
const other = adapter.installMode === "in-process" ? void 0 : unsupportedHostOf({ clientName: ctx.clientInfo?.name, bundleDir: host.bundleDir, env });
|
|
28790
|
+
const wait = (id2) => () => needsProjectRow(id2);
|
|
28791
|
+
const checks = {
|
|
28792
|
+
D1: () => checkVersion({ bundleSha: BUNDLE_SHA, version: bundleVersion(host.bundleDir), registryUrl: D1_REGISTRY_URL, timeoutMs: DOCTOR_GIT_TIMEOUT_MS, env: buildChildEnv(env), cwd: process.cwd(), signal: ctx.signal, updateCommand: d1UpdateCommand(adapter.id, env, other) }),
|
|
28793
|
+
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
28794
|
+
D3: other !== void 0 ? () => unsupportedRow("D3", other) : wait("D3"),
|
|
28795
|
+
D4: () => checkV1Leftovers(adapter.id, requireHomeDir(env), { piAgentDir: piAgentDirOf(env, requireHomeDir(env)), claudeDir: claudeDirOf(env, requireHomeDir(env)), codexDir: codexDirOf(env, requireHomeDir(env)), geminiDir: geminiDirOf(env, requireHomeDir(env)), copilotDir: copilotDirOf(env, requireHomeDir(env)), kiroDir: kiroDirOf(env, requireHomeDir(env)), opencodeDir: opencodeDirOf(env, requireHomeDir(env)) }),
|
|
28796
|
+
D5: other !== void 0 ? () => unsupportedRow("D5", other) : wait("D5"),
|
|
28797
|
+
D5b: wait("D5b"),
|
|
28798
|
+
D6: () => checkMcp(ctx, adapter),
|
|
28799
|
+
D7: () => noProjectRow(missing2),
|
|
28800
|
+
D8: wait("D8"),
|
|
28801
|
+
D9: wait("D9"),
|
|
28802
|
+
D10: () => checkMode(adapter, ctx.hostPermission),
|
|
28803
|
+
D11: () => checkRuntimes(env, checkShell(env))
|
|
28804
|
+
};
|
|
28805
|
+
const rows = [];
|
|
28806
|
+
for (const id2 of DOCTOR_CHECK_ORDER) rows.push(await guard(id2, checks[id2]));
|
|
28807
|
+
return rows;
|
|
28808
|
+
}
|
|
28568
28809
|
function reportEnv(env) {
|
|
28569
28810
|
const out = {};
|
|
28570
28811
|
for (const key of Object.keys(REPORT_ENV_ENUMS)) {
|
|
@@ -28574,7 +28815,7 @@ function reportEnv(env) {
|
|
|
28574
28815
|
return out;
|
|
28575
28816
|
}
|
|
28576
28817
|
async function doctorReply(ctx, host) {
|
|
28577
|
-
const adapter = getAdapter(ctx.project.agent);
|
|
28818
|
+
const adapter = getAdapter(ctx.agent ?? ctx.project.agent);
|
|
28578
28819
|
const runtime = runtimeInfo(host.env, ctx.signal);
|
|
28579
28820
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
28580
28821
|
const failed = rows.some((r) => r.status === "FAIL");
|
|
@@ -28596,9 +28837,11 @@ async function doctorReply(ctx, host) {
|
|
|
28596
28837
|
const whole2 = [envLine2, table3, ...docs, ...info, ...notes].join("\n");
|
|
28597
28838
|
const bytes5 = Buffer.byteLength(whole2, "utf8");
|
|
28598
28839
|
if (bytes5 <= REPORT_CAP) return { text: whole2, isError: false, sandboxBytes: bytes5 };
|
|
28599
|
-
const
|
|
28840
|
+
const p = projectOrMissing(ctx);
|
|
28841
|
+
if ("missing" in p) return { text: whole2, isError: false, sandboxBytes: bytes5 };
|
|
28842
|
+
const db = await openDb(p.project);
|
|
28600
28843
|
try {
|
|
28601
|
-
indexText(db,
|
|
28844
|
+
indexText(db, p.project, ctx.sessionId, REPORT_SOURCE_LABEL, whole2, "text");
|
|
28602
28845
|
} finally {
|
|
28603
28846
|
closeDb(db);
|
|
28604
28847
|
}
|
|
@@ -28623,9 +28866,9 @@ var ctxDoctor = Object.freeze({
|
|
|
28623
28866
|
});
|
|
28624
28867
|
|
|
28625
28868
|
// src/core/tools/execute.ts
|
|
28626
|
-
import { existsSync as existsSync18, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as
|
|
28869
|
+
import { existsSync as existsSync18, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync6 } from "node:fs";
|
|
28627
28870
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
28628
|
-
import { dirname as dirname12, join as
|
|
28871
|
+
import { dirname as dirname12, join as join22, parse as parse3, resolve as resolve11 } from "node:path";
|
|
28629
28872
|
|
|
28630
28873
|
// src/core/sandbox/win-build.ts
|
|
28631
28874
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -28794,9 +29037,9 @@ async function handler3(raw, ctx) {
|
|
|
28794
29037
|
if (takesDashC(input.language, runtime)) {
|
|
28795
29038
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
28796
29039
|
} else {
|
|
28797
|
-
tmpDir = mkdtempSync2(
|
|
28798
|
-
const file2 =
|
|
28799
|
-
|
|
29040
|
+
tmpDir = mkdtempSync2(join22(tmpdir3(), TMP_PREFIX));
|
|
29041
|
+
const file2 = join22(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
29042
|
+
writeFileSync6(file2, scriptText(input.language, input.code), "utf8");
|
|
28800
29043
|
argv = scriptArgv(input.language, runtime, file2);
|
|
28801
29044
|
}
|
|
28802
29045
|
if (input.background === true) {
|
|
@@ -28831,12 +29074,12 @@ var ctxExecute = {
|
|
|
28831
29074
|
};
|
|
28832
29075
|
|
|
28833
29076
|
// src/core/tools/index.ts
|
|
28834
|
-
import { existsSync as existsSync19, readFileSync as
|
|
28835
|
-
import { dirname as dirname13, extname as extname3, join as
|
|
29077
|
+
import { existsSync as existsSync19, readFileSync as readFileSync21, statSync as statSync10 } from "node:fs";
|
|
29078
|
+
import { dirname as dirname13, extname as extname3, join as join25, relative as relative5, resolve as resolve12 } from "node:path";
|
|
28836
29079
|
|
|
28837
29080
|
// src/core/index/walk.ts
|
|
28838
|
-
import { readdirSync as
|
|
28839
|
-
import { join as
|
|
29081
|
+
import { readdirSync as readdirSync10, readFileSync as readFileSync19, realpathSync as realpathSync10, statSync as statSync9 } from "node:fs";
|
|
29082
|
+
import { join as join23 } from "node:path";
|
|
28840
29083
|
var GITIGNORE = ".gitignore";
|
|
28841
29084
|
var GIT_DIR = ".git";
|
|
28842
29085
|
function walkDir(root, containmentRoot) {
|
|
@@ -28845,19 +29088,19 @@ function walkDir(root, containmentRoot) {
|
|
|
28845
29088
|
const found = [];
|
|
28846
29089
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
28847
29090
|
found.sort(compareFound);
|
|
28848
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
29091
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join23(...f.dir, f.name) }));
|
|
28849
29092
|
}
|
|
28850
29093
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
28851
29094
|
let entries;
|
|
28852
29095
|
try {
|
|
28853
|
-
entries =
|
|
29096
|
+
entries = readdirSync10(abs, { withFileTypes: true });
|
|
28854
29097
|
} catch {
|
|
28855
29098
|
return;
|
|
28856
29099
|
}
|
|
28857
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
29100
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join23(abs, GITIGNORE), rel)) : parent;
|
|
28858
29101
|
for (const e of entries) {
|
|
28859
29102
|
if (e.name === GIT_DIR) continue;
|
|
28860
|
-
const path8 =
|
|
29103
|
+
const path8 = join23(abs, e.name);
|
|
28861
29104
|
let isDir = e.isDirectory();
|
|
28862
29105
|
let isFile = e.isFile();
|
|
28863
29106
|
let target = path8;
|
|
@@ -28869,7 +29112,7 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
28869
29112
|
continue;
|
|
28870
29113
|
}
|
|
28871
29114
|
if (!isInside(contain, resolved)) continue;
|
|
28872
|
-
const st =
|
|
29115
|
+
const st = statSync9(resolved);
|
|
28873
29116
|
isDir = st.isDirectory();
|
|
28874
29117
|
isFile = st.isFile();
|
|
28875
29118
|
target = resolved;
|
|
@@ -28897,7 +29140,7 @@ function compareFound(a, b) {
|
|
|
28897
29140
|
function readRules(file2, base) {
|
|
28898
29141
|
let body;
|
|
28899
29142
|
try {
|
|
28900
|
-
body =
|
|
29143
|
+
body = readFileSync19(file2, "utf8");
|
|
28901
29144
|
} catch {
|
|
28902
29145
|
return [];
|
|
28903
29146
|
}
|
|
@@ -28980,12 +29223,13 @@ function globSeg(pat, name) {
|
|
|
28980
29223
|
}
|
|
28981
29224
|
|
|
28982
29225
|
// src/core/sandbox/fetch.ts
|
|
28983
|
-
import {
|
|
29226
|
+
import { randomBytes } from "node:crypto";
|
|
29227
|
+
import { readFileSync as readFileSync20 } from "node:fs";
|
|
28984
29228
|
import { lookup } from "node:dns/promises";
|
|
28985
29229
|
import http from "node:http";
|
|
28986
29230
|
import https from "node:https";
|
|
28987
29231
|
import { BlockList, isIP } from "node:net";
|
|
28988
|
-
import { join as
|
|
29232
|
+
import { join as join24 } from "node:path";
|
|
28989
29233
|
import { connect as tlsConnect } from "node:tls";
|
|
28990
29234
|
var PRIVATE_RANGES = [
|
|
28991
29235
|
["127.0.0.0", 8, "ipv4"],
|
|
@@ -29014,6 +29258,26 @@ var PRIVATE_RANGES = [
|
|
|
29014
29258
|
];
|
|
29015
29259
|
var BLOCKED = new BlockList();
|
|
29016
29260
|
for (const [net, prefix, type] of PRIVATE_RANGES) BLOCKED.addSubnet(net, prefix, type);
|
|
29261
|
+
var FAKE_IP_POOL = new BlockList();
|
|
29262
|
+
FAKE_IP_POOL.addSubnet("198.18.0.0", 15, "ipv4");
|
|
29263
|
+
var FAKE_IP_PROBE_TLD = ".invalid";
|
|
29264
|
+
var FAKE_IP_PROBE_BYTES = 8;
|
|
29265
|
+
var FAKE_IP_PROBE_MS = 1500;
|
|
29266
|
+
var fakeIpProbe;
|
|
29267
|
+
function inFakeIpPool(address) {
|
|
29268
|
+
return isIP(address) === 4 && FAKE_IP_POOL.check(address, "ipv4");
|
|
29269
|
+
}
|
|
29270
|
+
function fakeIpResolver() {
|
|
29271
|
+
fakeIpProbe ??= new Promise((resolve14) => {
|
|
29272
|
+
const timer = setTimeout(() => resolve14(false), FAKE_IP_PROBE_MS);
|
|
29273
|
+
timer.unref();
|
|
29274
|
+
lookup(randomBytes(FAKE_IP_PROBE_BYTES).toString("hex") + FAKE_IP_PROBE_TLD, { all: true }).then(
|
|
29275
|
+
(addrs) => resolve14(addrs.length > 0 && addrs.every((a) => inFakeIpPool(a.address))),
|
|
29276
|
+
() => resolve14(false)
|
|
29277
|
+
).finally(() => clearTimeout(timer));
|
|
29278
|
+
});
|
|
29279
|
+
return fakeIpProbe;
|
|
29280
|
+
}
|
|
29017
29281
|
var STATUS_OK_FIRST = 200;
|
|
29018
29282
|
var STATUS_OK_END = 300;
|
|
29019
29283
|
var STATUS_REDIRECT = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
@@ -29024,7 +29288,7 @@ function baseHeaders() {
|
|
|
29024
29288
|
if (namedHeaders === void 0) {
|
|
29025
29289
|
let version2 = UA_DEV_VERSION;
|
|
29026
29290
|
try {
|
|
29027
|
-
const v = JSON.parse(
|
|
29291
|
+
const v = JSON.parse(readFileSync20(join24(ownBundleDir(), D1_PACKAGE_FILE), "utf8")).version;
|
|
29028
29292
|
if (typeof v === "string" && v !== "") version2 = v;
|
|
29029
29293
|
} catch {
|
|
29030
29294
|
}
|
|
@@ -29116,8 +29380,15 @@ function checkAddress(hostname2, address) {
|
|
|
29116
29380
|
throw new CtxError("SSRF", { host: hostname2 });
|
|
29117
29381
|
}
|
|
29118
29382
|
}
|
|
29119
|
-
async function
|
|
29120
|
-
const
|
|
29383
|
+
async function checkResolved(host, addrs, signal) {
|
|
29384
|
+
const pooled = isIP(host) === 0 ? addrs.filter((a) => inFakeIpPool(a.address)) : [];
|
|
29385
|
+
for (const a of addrs) if (!pooled.includes(a)) checkAddress(host, a.address);
|
|
29386
|
+
if (pooled.length === 0) return;
|
|
29387
|
+
const fakeIp = await fakeIpResolver();
|
|
29388
|
+
if (signal.aborted) throw fail6("ABORT_ERR");
|
|
29389
|
+
if (!fakeIp) checkAddress(host, pooled[0].address);
|
|
29390
|
+
}
|
|
29391
|
+
async function lookupAll(host, signal) {
|
|
29121
29392
|
let addrs;
|
|
29122
29393
|
try {
|
|
29123
29394
|
addrs = await lookup(host, { all: true });
|
|
@@ -29126,9 +29397,26 @@ async function resolveTarget(u, signal) {
|
|
|
29126
29397
|
}
|
|
29127
29398
|
if (signal.aborted) throw fail6("ABORT_ERR");
|
|
29128
29399
|
if (addrs.length === 0) throw fail6("ENOTFOUND");
|
|
29129
|
-
|
|
29400
|
+
return addrs;
|
|
29401
|
+
}
|
|
29402
|
+
async function resolveTarget(u, signal, checked) {
|
|
29403
|
+
const host = bare(u.hostname);
|
|
29404
|
+
const addrs = await lookupAll(host, signal);
|
|
29405
|
+
if (checked) await checkResolved(host, addrs, signal);
|
|
29130
29406
|
return { host, port: u.port === "" ? defaultPort(u.protocol) : Number(u.port), address: addrs[0].address };
|
|
29131
29407
|
}
|
|
29408
|
+
async function checkProxiedTarget(u, signal) {
|
|
29409
|
+
const host = bare(u.hostname);
|
|
29410
|
+
if (isIP(host) !== 0) return checkAddress(host, host);
|
|
29411
|
+
let addrs;
|
|
29412
|
+
try {
|
|
29413
|
+
addrs = await lookupAll(host, signal);
|
|
29414
|
+
} catch (err) {
|
|
29415
|
+
if (signal.aborted) throw err;
|
|
29416
|
+
return;
|
|
29417
|
+
}
|
|
29418
|
+
await checkResolved(host, addrs, signal);
|
|
29419
|
+
}
|
|
29132
29420
|
function tlsName(host) {
|
|
29133
29421
|
return isIP(host) === 0 ? host : void 0;
|
|
29134
29422
|
}
|
|
@@ -29186,9 +29474,8 @@ async function safeFetch(url2, signal) {
|
|
|
29186
29474
|
for (let hop = 0; ; hop += 1) {
|
|
29187
29475
|
if (signal.aborted) throw fail6("ABORT_ERR");
|
|
29188
29476
|
const proxy = pickProxy(current);
|
|
29189
|
-
|
|
29190
|
-
|
|
29191
|
-
const conn = await resolveTarget(proxy === void 0 ? current : proxy.url, signal);
|
|
29477
|
+
if (proxy !== void 0) await checkProxiedTarget(current, signal);
|
|
29478
|
+
const conn = await resolveTarget(proxy === void 0 ? current : proxy.url, signal, proxy === void 0);
|
|
29192
29479
|
const res = await request(current, conn, proxy, signal);
|
|
29193
29480
|
const status = res.statusCode ?? 0;
|
|
29194
29481
|
const location = res.headers.location;
|
|
@@ -29337,7 +29624,7 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
29337
29624
|
readNgramReferences(ngramCount - dictSize + dict1AtomCount, dictSize + dict2AtomCount);
|
|
29338
29625
|
readNgramReferences(dictSize - dict1AtomCount, dict1AtomCount);
|
|
29339
29626
|
const pool = new Uint16Array(poolSize);
|
|
29340
|
-
let
|
|
29627
|
+
let write = 0;
|
|
29341
29628
|
for (let index = 0; index < ngramIndex; index++) {
|
|
29342
29629
|
for (let half = 0; half < 2; half++) {
|
|
29343
29630
|
const source = references[index * 2 + half];
|
|
@@ -29346,9 +29633,9 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
29346
29633
|
let read3 = start[source];
|
|
29347
29634
|
const readEnd = read3 + length[source];
|
|
29348
29635
|
while (read3 < readEnd)
|
|
29349
|
-
pool[
|
|
29636
|
+
pool[write++] = pool[read3++];
|
|
29350
29637
|
} else {
|
|
29351
|
-
pool[
|
|
29638
|
+
pool[write++] = value;
|
|
29352
29639
|
}
|
|
29353
29640
|
}
|
|
29354
29641
|
}
|
|
@@ -33042,7 +33329,7 @@ function kindOfType(contentType) {
|
|
|
33042
33329
|
}
|
|
33043
33330
|
function readUtf8(absPath) {
|
|
33044
33331
|
try {
|
|
33045
|
-
return utf8.decode(
|
|
33332
|
+
return utf8.decode(readFileSync21(absPath));
|
|
33046
33333
|
} catch {
|
|
33047
33334
|
return void 0;
|
|
33048
33335
|
}
|
|
@@ -33057,10 +33344,10 @@ function pathItems(input, project) {
|
|
|
33057
33344
|
const abs = resolve12(project.worktree, input.path);
|
|
33058
33345
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
33059
33346
|
const base = relative5(project.worktree, abs);
|
|
33060
|
-
if (
|
|
33347
|
+
if (statSync10(abs).isDirectory()) {
|
|
33061
33348
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
33062
33349
|
sourceKind: "path",
|
|
33063
|
-
label: pathLabel(
|
|
33350
|
+
label: pathLabel(join25(base, f.relPath)),
|
|
33064
33351
|
kind: kindOfPath(f.relPath),
|
|
33065
33352
|
read: () => readUtf8(f.absPath)
|
|
33066
33353
|
}));
|
|
@@ -33184,7 +33471,7 @@ function purgeScope(db, scope, input) {
|
|
|
33184
33471
|
const chunks = deleteChunkRows(raw, "all");
|
|
33185
33472
|
return changes(raw, "DELETE FROM events") + chunks + changes(raw, "DELETE FROM sources");
|
|
33186
33473
|
}
|
|
33187
|
-
function
|
|
33474
|
+
function isBusy2(err) {
|
|
33188
33475
|
const code = err?.errcode;
|
|
33189
33476
|
return typeof code === "number" && (code & SQLITE_PRIMARY_CODE_MASK) === SQLITE_BUSY_CODE;
|
|
33190
33477
|
}
|
|
@@ -33202,7 +33489,7 @@ async function handler5(input, ctx) {
|
|
|
33202
33489
|
closeDb(db);
|
|
33203
33490
|
}
|
|
33204
33491
|
} catch (err) {
|
|
33205
|
-
if (
|
|
33492
|
+
if (isBusy2(err)) return reply2(PURGE_BUSY_LINE, true);
|
|
33206
33493
|
throw err;
|
|
33207
33494
|
}
|
|
33208
33495
|
}
|
|
@@ -33600,22 +33887,22 @@ var ctxStats = Object.freeze({
|
|
|
33600
33887
|
});
|
|
33601
33888
|
|
|
33602
33889
|
// src/core/ops/host-write.ts
|
|
33603
|
-
import { copyFileSync, existsSync as existsSync20, mkdirSync as
|
|
33604
|
-
import { dirname as dirname14, join as
|
|
33890
|
+
import { copyFileSync, existsSync as existsSync20, mkdirSync as mkdirSync9, writeFileSync as writeFileSync7 } from "node:fs";
|
|
33891
|
+
import { dirname as dirname14, join as join26 } from "node:path";
|
|
33605
33892
|
function defaultWrite(file2, text) {
|
|
33606
|
-
|
|
33893
|
+
writeFileSync7(file2, text, "utf8");
|
|
33607
33894
|
}
|
|
33608
33895
|
function hostConfigPath(agent, home, env) {
|
|
33609
33896
|
const own2 = OWN_MCP_ENTRY[agent];
|
|
33610
33897
|
if (own2 !== void 0) return ownMcpFileOf(agent, own2.file, env, home);
|
|
33611
33898
|
switch (agent) {
|
|
33612
33899
|
case "opencode":
|
|
33613
|
-
return
|
|
33900
|
+
return join26(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
33614
33901
|
// D-WIN-OPENCODE-DIR-1
|
|
33615
33902
|
case "pi":
|
|
33616
|
-
return
|
|
33903
|
+
return join26(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
33617
33904
|
case "gemini":
|
|
33618
|
-
return
|
|
33905
|
+
return join26(geminiDirOf(env, home), SETTINGS_FILE);
|
|
33619
33906
|
// D-R38-GEMINI-HOME-1
|
|
33620
33907
|
case "copilot-cli":
|
|
33621
33908
|
return null;
|
|
@@ -33623,7 +33910,7 @@ function hostConfigPath(agent, home, env) {
|
|
|
33623
33910
|
return null;
|
|
33624
33911
|
// ADR-0026 decision 8 (D-OMP-UPGRADE-1): OMP loads the plugin from its own store; no MCP entry, nothing under ~/.pi
|
|
33625
33912
|
default:
|
|
33626
|
-
return
|
|
33913
|
+
return join26(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
33627
33914
|
}
|
|
33628
33915
|
}
|
|
33629
33916
|
function cell3(value) {
|
|
@@ -33632,14 +33919,14 @@ function cell3(value) {
|
|
|
33632
33919
|
function toRow(file2, edit) {
|
|
33633
33920
|
return { area: file2 + UPGRADE_AREA_KEY_SEP + edit.path, before: cell3(edit.before), after: cell3(edit.after) };
|
|
33634
33921
|
}
|
|
33635
|
-
function writeWithRollback(file2, text,
|
|
33922
|
+
function writeWithRollback(file2, text, write, atomic) {
|
|
33636
33923
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
33637
33924
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
33638
33925
|
const had = existsSync20(file2);
|
|
33639
|
-
|
|
33926
|
+
mkdirSync9(dirname14(file2), { recursive: true });
|
|
33640
33927
|
if (had) copyFileSync(file2, trash);
|
|
33641
33928
|
try {
|
|
33642
|
-
|
|
33929
|
+
write(tmp, text);
|
|
33643
33930
|
renameWithRetry(tmp, file2, atomic);
|
|
33644
33931
|
} catch (err) {
|
|
33645
33932
|
removeTmpFile(tmp, atomic);
|
|
@@ -33673,15 +33960,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
33673
33960
|
}
|
|
33674
33961
|
|
|
33675
33962
|
// src/core/ops/uninstall.ts
|
|
33676
|
-
import { existsSync as existsSync21, readdirSync as
|
|
33677
|
-
import { join as
|
|
33963
|
+
import { existsSync as existsSync21, readdirSync as readdirSync11, rmSync as rmSync6, writeFileSync as writeFileSync8 } from "node:fs";
|
|
33964
|
+
import { join as join27 } from "node:path";
|
|
33678
33965
|
function row2(area, before, after) {
|
|
33679
33966
|
return { area, before, after };
|
|
33680
33967
|
}
|
|
33681
33968
|
function stopServers(configDir, projectKey) {
|
|
33682
33969
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
33683
|
-
const dir =
|
|
33684
|
-
for (const serverId of stopped)
|
|
33970
|
+
const dir = join27(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
33971
|
+
for (const serverId of stopped) writeFileSync8(join27(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
33685
33972
|
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 };
|
|
33686
33973
|
}
|
|
33687
33974
|
function rootOrNull(adapter, env) {
|
|
@@ -33699,14 +33986,14 @@ function removeCache(adapter, env, configDir) {
|
|
|
33699
33986
|
const root = rootOrNull(adapter, env);
|
|
33700
33987
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
33701
33988
|
if (adapter.installMode === "marketplace") {
|
|
33702
|
-
const cache =
|
|
33989
|
+
const cache = join27(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
33703
33990
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
33704
33991
|
}
|
|
33705
33992
|
rmSync6(root, { recursive: true, force: true });
|
|
33706
33993
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
33707
33994
|
}
|
|
33708
33995
|
case "plugin": {
|
|
33709
|
-
const agentDir =
|
|
33996
|
+
const agentDir = join27(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
33710
33997
|
if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
33711
33998
|
rmSync6(agentDir, { recursive: true, force: true });
|
|
33712
33999
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
@@ -33752,7 +34039,7 @@ function ownEntries2(agent, env) {
|
|
|
33752
34039
|
}
|
|
33753
34040
|
if (agent === "opencode") {
|
|
33754
34041
|
return [{
|
|
33755
|
-
file:
|
|
34042
|
+
file: join27(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
33756
34043
|
// D-WIN-OPENCODE-DIR-1
|
|
33757
34044
|
key: OPENCODE_PLUGIN_KEY,
|
|
33758
34045
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -33763,7 +34050,7 @@ function ownEntries2(agent, env) {
|
|
|
33763
34050
|
if (agent === "pi") {
|
|
33764
34051
|
const agentDir = piAgentDirOf(env, home);
|
|
33765
34052
|
return [{
|
|
33766
|
-
file:
|
|
34053
|
+
file: join27(agentDir, SETTINGS_FILE),
|
|
33767
34054
|
key: PI_PACKAGES_KEY,
|
|
33768
34055
|
shown: PI_PACKAGES_KEY,
|
|
33769
34056
|
has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
|
|
@@ -33794,12 +34081,12 @@ function removeOwnEntries(agent, env) {
|
|
|
33794
34081
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
33795
34082
|
}
|
|
33796
34083
|
function removeProjectData(configDir, projectKey) {
|
|
33797
|
-
const projects =
|
|
33798
|
-
const dir =
|
|
34084
|
+
const projects = join27(configDir, PROJECTS_DIR_NAME);
|
|
34085
|
+
const dir = join27(projects, projectKey);
|
|
33799
34086
|
if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
33800
34087
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
33801
|
-
for (const name of
|
|
33802
|
-
if (name !== OWNERS_DIR_NAME) rmSync6(
|
|
34088
|
+
for (const name of readdirSync11(dir)) {
|
|
34089
|
+
if (name !== OWNERS_DIR_NAME) rmSync6(join27(dir, name), { recursive: true, force: true });
|
|
33803
34090
|
}
|
|
33804
34091
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
33805
34092
|
}
|
|
@@ -33807,12 +34094,12 @@ function runUninstall(input) {
|
|
|
33807
34094
|
const configDir = resolveConfigDir(input.env);
|
|
33808
34095
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
33809
34096
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
33810
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
34097
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join27(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
33811
34098
|
return { rows, stopped: stop.stopped };
|
|
33812
34099
|
}
|
|
33813
34100
|
|
|
33814
34101
|
// src/core/ops/v1-remove.ts
|
|
33815
|
-
import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as
|
|
34102
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync22, rmSync as rmSync7 } from "node:fs";
|
|
33816
34103
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
33817
34104
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
33818
34105
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -33863,8 +34150,8 @@ function locate(doc, path8) {
|
|
|
33863
34150
|
return null;
|
|
33864
34151
|
}
|
|
33865
34152
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
33866
|
-
const layout = hostLayout(
|
|
33867
|
-
const text = hostText(
|
|
34153
|
+
const layout = hostLayout(readFileSync22(file2, "utf8"));
|
|
34154
|
+
const text = hostText(readFileSync22(file2, "utf8"));
|
|
33868
34155
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
33869
34156
|
const hit = /* @__PURE__ */ new Set();
|
|
33870
34157
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -33914,7 +34201,7 @@ function removeV1(agent, findings, project) {
|
|
|
33914
34201
|
continue;
|
|
33915
34202
|
}
|
|
33916
34203
|
if (file2.endsWith(TOML_EXT)) {
|
|
33917
|
-
const rawToml =
|
|
34204
|
+
const rawToml = readFileSync22(file2, "utf8");
|
|
33918
34205
|
const tomlLayout = hostLayout(rawToml);
|
|
33919
34206
|
let text = hostText(rawToml);
|
|
33920
34207
|
for (const f of list4) {
|
|
@@ -34187,8 +34474,8 @@ async function setupLegacy(app) {
|
|
|
34187
34474
|
"chat.message": async (input, output) => {
|
|
34188
34475
|
const sessionId = input.sessionID ?? "";
|
|
34189
34476
|
turns.set(sessionId, turnOf(sessionId) + 1);
|
|
34190
|
-
const
|
|
34191
|
-
await call({ type: "prompt", sessionID: sessionId, message:
|
|
34477
|
+
const message4 = (output.parts ?? []).filter((p) => p.type === "text").map((p) => p.text ?? "").join("");
|
|
34478
|
+
await call({ type: "prompt", sessionID: sessionId, message: message4, turn: turnOf(sessionId) });
|
|
34192
34479
|
},
|
|
34193
34480
|
// §4.4. Deny (exit 2) throws with the reason; the reason carries any rewritten command (Q3, D-M5-P2-3).
|
|
34194
34481
|
"tool.execute.before": async (input, output) => {
|