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/pi/index.js
CHANGED
|
@@ -988,14 +988,14 @@ function prefixIssues(path8, issues) {
|
|
|
988
988
|
return iss;
|
|
989
989
|
});
|
|
990
990
|
}
|
|
991
|
-
function unwrapMessage(
|
|
992
|
-
return typeof
|
|
991
|
+
function unwrapMessage(message4) {
|
|
992
|
+
return typeof message4 === "string" ? message4 : message4?.message;
|
|
993
993
|
}
|
|
994
994
|
function finalizeIssue(iss, ctx, config4) {
|
|
995
995
|
const full = { ...iss, path: iss.path ?? [] };
|
|
996
996
|
if (!iss.message) {
|
|
997
|
-
const
|
|
998
|
-
full.message =
|
|
997
|
+
const message4 = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config4.customError?.(iss)) ?? unwrapMessage(config4.localeError?.(iss)) ?? "Invalid input";
|
|
998
|
+
full.message = message4;
|
|
999
999
|
}
|
|
1000
1000
|
delete full.inst;
|
|
1001
1001
|
delete full.continue;
|
|
@@ -11172,6 +11172,7 @@ function readReplaceTrigger(raw) {
|
|
|
11172
11172
|
var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
|
|
11173
11173
|
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
11174
11174
|
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
11175
|
+
var SKILL_LOAD_TOOLS = Object.freeze(["Skill"]);
|
|
11175
11176
|
var REPLACE_RETURN_BYTES = 96;
|
|
11176
11177
|
var SHAPE_RETURN_BYTES = 256;
|
|
11177
11178
|
var REPLACE_CHUNK_BYTES = 48;
|
|
@@ -11185,6 +11186,9 @@ function SUBAGENT_HANDLE_LINE(handle, bytes5, read3) {
|
|
|
11185
11186
|
function SEARCH_TWIN_LINE(searchPath, handle, terms, projectDir) {
|
|
11186
11187
|
return " Or run: node " + shellWord(searchPath) + " " + handle + " " + shellWord(terms) + " " + shellWord(projectDir);
|
|
11187
11188
|
}
|
|
11189
|
+
function PERSISTED_FILE_LINE(file2) {
|
|
11190
|
+
return " The whole output is also in " + JSON.stringify(file2) + "; Read it with offset and limit.";
|
|
11191
|
+
}
|
|
11188
11192
|
function shellWord(s) {
|
|
11189
11193
|
return "'" + s.split("'").join("'\\''") + "'";
|
|
11190
11194
|
}
|
|
@@ -11339,6 +11343,10 @@ var KILL_GRACE_MS = 1e3;
|
|
|
11339
11343
|
var PIPE_EOF_GRACE_MS = 250;
|
|
11340
11344
|
var PIPE_DRAIN_MAX_MS = 2e3;
|
|
11341
11345
|
var DB_TIMEOUT_MS = 5e3;
|
|
11346
|
+
var HOOK_BUSY_MS = 250;
|
|
11347
|
+
var HOOK_SPOOL_DIR = "pending";
|
|
11348
|
+
var SPOOL_CLAIM_STALE_MS = 3e4;
|
|
11349
|
+
var SPOOL_DRAIN_MS = 1e3;
|
|
11342
11350
|
var DB_WAL_SUFFIX = "-wal";
|
|
11343
11351
|
var DB_SHM_SUFFIX = "-shm";
|
|
11344
11352
|
var DB_TMP_SUFFIX = ".tmp";
|
|
@@ -11385,6 +11393,7 @@ var SEARCH_WRAPPER_FILE = "search.mjs";
|
|
|
11385
11393
|
var RUN_WRAPPER_AGENT = "claude-code";
|
|
11386
11394
|
var RUN_SESSION_PREFIX = "mcp:";
|
|
11387
11395
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
11396
|
+
var HOST_SESSION_META = Object.freeze({ zcode: "session_id" });
|
|
11388
11397
|
var NODE_MIN = "24.15.0";
|
|
11389
11398
|
var DATA_ROOT = "~/.context-mode";
|
|
11390
11399
|
var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
|
|
@@ -11409,6 +11418,7 @@ var FRONTMATTER_FENCE = "---";
|
|
|
11409
11418
|
var FRONTMATTER_TOOLS_KEY = "tools";
|
|
11410
11419
|
var FRONTMATTER_DISALLOWED_KEY = "disallowedTools";
|
|
11411
11420
|
var MCP_SERVER_TOOL_PREFIX = "mcp__";
|
|
11421
|
+
var PLUGIN_CALL_ID_PREFIX = "toolu_plugin_";
|
|
11412
11422
|
var MCP_NAME_JOIN = "__";
|
|
11413
11423
|
var GEMINI_MCP_PREFIX = "mcp_";
|
|
11414
11424
|
var GEMINI_NAME_EXTRA_CHARS = "_-.:";
|
|
@@ -11630,7 +11640,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
11630
11640
|
var DECISION_OPTION_KEY = "option";
|
|
11631
11641
|
var DECISION_LABEL_JOIN = " | ";
|
|
11632
11642
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
11633
|
-
var BUNDLE_SHA = true ? "
|
|
11643
|
+
var BUNDLE_SHA = true ? "ae2e1bb106e462a19ab3c042e371cd8a7f691074" : void 0;
|
|
11634
11644
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
11635
11645
|
var DOCTOR_LABEL = Object.freeze({
|
|
11636
11646
|
D1: "version",
|
|
@@ -11741,6 +11751,10 @@ function D7_DETAIL(got) {
|
|
|
11741
11751
|
return `resolved project source ${got} does not match the host's actual cwd`;
|
|
11742
11752
|
}
|
|
11743
11753
|
var D7_FIX = "restart the agent in the correct directory";
|
|
11754
|
+
function D7_NO_PROJECT_DETAIL(kind) {
|
|
11755
|
+
return `Project source ${kind} is missing`;
|
|
11756
|
+
}
|
|
11757
|
+
var DOCTOR_NEEDS_PROJECT_DETAIL = "runs once the project resolves; D7 names the project source";
|
|
11744
11758
|
function D8_STALE_SCHEMA_DETAIL(got, want) {
|
|
11745
11759
|
return `stale schema (v${got}, expected v${want})`;
|
|
11746
11760
|
}
|
|
@@ -12422,7 +12436,7 @@ var CtxError = class extends Error {
|
|
|
12422
12436
|
};
|
|
12423
12437
|
|
|
12424
12438
|
// src/core/hooks/dispatch.ts
|
|
12425
|
-
import { dirname as dirname4, join as
|
|
12439
|
+
import { dirname as dirname4, join as join9, relative as relative3, resolve as resolve8, sep as sep3 } from "node:path";
|
|
12426
12440
|
|
|
12427
12441
|
// src/core/contracts/agents.ts
|
|
12428
12442
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode", "omp"];
|
|
@@ -12433,6 +12447,7 @@ var SHELL_TOOL_NAMES = Object.freeze(["Bash", "PowerShell"]);
|
|
|
12433
12447
|
var POWERSHELL_TOOL = "PowerShell";
|
|
12434
12448
|
var SHELL_CANONICAL = "Bash";
|
|
12435
12449
|
var CLAUDE_SHAPE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse"];
|
|
12450
|
+
var FAILURE_EVENT = "PostToolUseFailure";
|
|
12436
12451
|
var MCP_PREFIX = "mcp__";
|
|
12437
12452
|
var MCP_SEP = "__";
|
|
12438
12453
|
var CLAUDE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
@@ -12606,7 +12621,14 @@ function requireFields(raw) {
|
|
|
12606
12621
|
}
|
|
12607
12622
|
function decode2(raw) {
|
|
12608
12623
|
requireFields(raw);
|
|
12609
|
-
const
|
|
12624
|
+
const failure3 = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
|
|
12625
|
+
const payload = failure3 ? { ...raw, hook_event_name: "PostToolUse" } : raw;
|
|
12626
|
+
const ev = decodeClaudeShape(payload, "claude-code", TOOL_NAME_PREFIX2, CLAUDE_SOURCES);
|
|
12627
|
+
if (failure3) {
|
|
12628
|
+
const error42 = raw.error;
|
|
12629
|
+
const text = typeof error42 === "string" ? error42 : error42 === void 0 ? "" : JSON.stringify(error42);
|
|
12630
|
+
ev.result = { isError: true, bytes: Buffer.byteLength(text), text, keep: true };
|
|
12631
|
+
}
|
|
12610
12632
|
if (ev.tool !== void 0 && ev.tool.name === POWERSHELL_TOOL) ev.tool.canonicalName = SHELL_CANONICAL;
|
|
12611
12633
|
if (ev.cwd === "") ev.cwd = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
12612
12634
|
if (ev.event === "PostToolUse" && ev.tool !== void 0 && ev.tool.callId === void 0) {
|
|
@@ -12785,9 +12807,9 @@ var NATIVE_TO_CANONICAL3 = {
|
|
|
12785
12807
|
grep_search: "Grep",
|
|
12786
12808
|
web_fetch: "WebFetch"
|
|
12787
12809
|
};
|
|
12788
|
-
var
|
|
12810
|
+
var FAILURE_EVENT2 = "PostToolUseFailure";
|
|
12789
12811
|
function decode5(raw) {
|
|
12790
|
-
const failure3 = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name ===
|
|
12812
|
+
const failure3 = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT2;
|
|
12791
12813
|
const payload = failure3 ? { ...raw, hook_event_name: "PostToolUse" } : raw;
|
|
12792
12814
|
const ev = decodeClaudeShape(payload, "qwen", TOOL_NAME_PREFIX5, QWEN_SOURCES);
|
|
12793
12815
|
if (ev.tool !== void 0 && Object.hasOwn(NATIVE_TO_CANONICAL3, ev.tool.name)) ev.tool.canonicalName = NATIVE_TO_CANONICAL3[ev.tool.name];
|
|
@@ -13107,12 +13129,12 @@ var TOOL_NAME_PREFIX9 = "mcp__context-mode__";
|
|
|
13107
13129
|
var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
13108
13130
|
var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
13109
13131
|
var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
|
|
13110
|
-
var
|
|
13132
|
+
var FAILURE_EVENT3 = "PostToolUseFailure";
|
|
13111
13133
|
function decode9(raw) {
|
|
13112
13134
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("zcode: hook payload is not a JSON object");
|
|
13113
13135
|
const p = { ...raw };
|
|
13114
13136
|
for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
|
|
13115
|
-
const failure3 = p.hook_event_name ===
|
|
13137
|
+
const failure3 = p.hook_event_name === FAILURE_EVENT3;
|
|
13116
13138
|
if (failure3) p.hook_event_name = "PostToolUse";
|
|
13117
13139
|
const toolName2 = typeof p.tool_name === "string" ? p.tool_name : "";
|
|
13118
13140
|
const prefix = toolName2.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX9;
|
|
@@ -13141,7 +13163,8 @@ var OPENCODE_EVENTS = {
|
|
|
13141
13163
|
var SHELL_TOOL_NAME = "bash";
|
|
13142
13164
|
var READ_TOOL_NAME = "read";
|
|
13143
13165
|
var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
13144
|
-
var
|
|
13166
|
+
var SKILL_TOOL_NAME = "skill";
|
|
13167
|
+
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", [SKILL_TOOL_NAME]: "Skill", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
|
|
13145
13168
|
function toCanonicalTool(name) {
|
|
13146
13169
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
13147
13170
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
|
|
@@ -15884,7 +15907,7 @@ function dumpTarget(name, args) {
|
|
|
15884
15907
|
}
|
|
15885
15908
|
|
|
15886
15909
|
// src/core/project/resolve.ts
|
|
15887
|
-
import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve6 } from "node:path";
|
|
15910
|
+
import { basename as basename2, dirname as dirname3, isAbsolute as isAbsolute3, join as join6, resolve as resolve6 } from "node:path";
|
|
15888
15911
|
|
|
15889
15912
|
// src/core/project/sha256.ts
|
|
15890
15913
|
var K = new Uint32Array([
|
|
@@ -16039,12 +16062,7 @@ function dirOf(kind, src) {
|
|
|
16039
16062
|
}
|
|
16040
16063
|
}
|
|
16041
16064
|
function gitDirs(dir) {
|
|
16042
|
-
let cur;
|
|
16043
|
-
try {
|
|
16044
|
-
cur = realpathSync3.native(dir);
|
|
16045
|
-
} catch {
|
|
16046
|
-
throw new CtxError("NO_GIT_DIR", { path: dir });
|
|
16047
|
-
}
|
|
16065
|
+
let cur = nearestRealDir(dir);
|
|
16048
16066
|
const start = cur;
|
|
16049
16067
|
for (; ; ) {
|
|
16050
16068
|
const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
|
|
@@ -16057,6 +16075,18 @@ function gitDirs(dir) {
|
|
|
16057
16075
|
cur = up;
|
|
16058
16076
|
}
|
|
16059
16077
|
}
|
|
16078
|
+
function nearestRealDir(dir) {
|
|
16079
|
+
const walk3 = isAbsolute3(dir);
|
|
16080
|
+
for (let d = walk3 ? resolve6(dir) : dir; ; ) {
|
|
16081
|
+
try {
|
|
16082
|
+
return realpathSync3.native(d);
|
|
16083
|
+
} catch {
|
|
16084
|
+
const up = dirname3(d);
|
|
16085
|
+
if (!walk3 || up === d) throw new CtxError("NO_GIT_DIR", { path: dir });
|
|
16086
|
+
d = up;
|
|
16087
|
+
}
|
|
16088
|
+
}
|
|
16089
|
+
}
|
|
16060
16090
|
function gitDirAt(dotGit) {
|
|
16061
16091
|
let gitDir;
|
|
16062
16092
|
try {
|
|
@@ -16119,7 +16149,7 @@ function resolveProject(agent, src) {
|
|
|
16119
16149
|
},
|
|
16120
16150
|
worktree,
|
|
16121
16151
|
get containmentRoot() {
|
|
16122
|
-
root ??= plain ?? containmentRootOf(
|
|
16152
|
+
root ??= plain ?? containmentRootOf(worktree, commonDir);
|
|
16123
16153
|
return root;
|
|
16124
16154
|
},
|
|
16125
16155
|
agent,
|
|
@@ -16302,26 +16332,26 @@ function errCode(err) {
|
|
|
16302
16332
|
return err.code ?? "";
|
|
16303
16333
|
}
|
|
16304
16334
|
function publishWithoutLink(tmp, path8) {
|
|
16305
|
-
const
|
|
16335
|
+
const claim4 = path8 + DB_PUBLISH_CLAIM_SUFFIX;
|
|
16306
16336
|
const start = Date.now();
|
|
16307
16337
|
for (; ; ) {
|
|
16308
16338
|
if (existsSync3(path8)) return;
|
|
16309
16339
|
try {
|
|
16310
|
-
mkdirSync2(
|
|
16340
|
+
mkdirSync2(claim4);
|
|
16311
16341
|
} catch (err) {
|
|
16312
16342
|
if (!DB_CLAIM_BUSY_CODES.includes(errCode(err))) throw err;
|
|
16313
16343
|
if (Date.now() - start < DB_TIMEOUT_MS) {
|
|
16314
16344
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, DB_PUBLISH_POLL_MS);
|
|
16315
16345
|
continue;
|
|
16316
16346
|
}
|
|
16317
|
-
const held = statSync3(
|
|
16318
|
-
if (held !== void 0 && held.mtimeMs < start) rmSync(
|
|
16319
|
-
throw new Error(`context.db was not published within ${DB_TIMEOUT_MS} ms: ${
|
|
16347
|
+
const held = statSync3(claim4, { throwIfNoEntry: false });
|
|
16348
|
+
if (held !== void 0 && held.mtimeMs < start) rmSync(claim4, { recursive: true, force: true });
|
|
16349
|
+
throw new Error(`context.db was not published within ${DB_TIMEOUT_MS} ms: ${claim4} was held; open again`);
|
|
16320
16350
|
}
|
|
16321
16351
|
try {
|
|
16322
16352
|
if (!existsSync3(path8)) renameSync(tmp, path8);
|
|
16323
16353
|
} finally {
|
|
16324
|
-
rmSync(
|
|
16354
|
+
rmSync(claim4, { recursive: true, force: true });
|
|
16325
16355
|
}
|
|
16326
16356
|
return;
|
|
16327
16357
|
}
|
|
@@ -16440,9 +16470,9 @@ var COLUMNS = "events(session_id, worktree, agent, kind, tool, key, path, ok, ex
|
|
|
16440
16470
|
var INSERT_SQL = "INSERT INTO " + COLUMNS;
|
|
16441
16471
|
var INSERT_COST_SQL = "INSERT OR IGNORE INTO " + COLUMNS;
|
|
16442
16472
|
var COST_SEQ_SQL = "SELECT seq FROM events WHERE kind = 'cost' AND session_id = ? AND turn = ?";
|
|
16443
|
-
function appendEvent(db, row5) {
|
|
16473
|
+
function appendEvent(db, row5, at2) {
|
|
16444
16474
|
return withWrite(db, (h) => {
|
|
16445
|
-
const now = Date.now();
|
|
16475
|
+
const now = at2 ?? Date.now();
|
|
16446
16476
|
const isCost = row5.kind === "cost";
|
|
16447
16477
|
const res = h.raw.prepare(isCost ? INSERT_COST_SQL : INSERT_SQL).run(
|
|
16448
16478
|
row5.session_id,
|
|
@@ -18548,18 +18578,6 @@ function reserveSource(db, src, chunks) {
|
|
|
18548
18578
|
return Number(row5.id);
|
|
18549
18579
|
});
|
|
18550
18580
|
}
|
|
18551
|
-
function finishReserved(db, id, src, chunks, units) {
|
|
18552
|
-
try {
|
|
18553
|
-
insertChunks(db, id, src, chunks);
|
|
18554
|
-
insertUnits(db, id, src.sessionId, units);
|
|
18555
|
-
} catch (err) {
|
|
18556
|
-
withWrite(db, (h) => {
|
|
18557
|
-
deleteChunkRows(h.raw, { sourceId: id });
|
|
18558
|
-
h.raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
|
|
18559
|
-
});
|
|
18560
|
-
throw err;
|
|
18561
|
-
}
|
|
18562
|
-
}
|
|
18563
18581
|
function insertChunks(db, id, src, chunks) {
|
|
18564
18582
|
const batches = [];
|
|
18565
18583
|
let batch = [];
|
|
@@ -18998,43 +19016,53 @@ function parseSourceHandle(s) {
|
|
|
18998
19016
|
function pathLabel(p) {
|
|
18999
19017
|
return p.includes("\\") ? p.split("\\").join("/") : p;
|
|
19000
19018
|
}
|
|
19001
|
-
|
|
19002
|
-
|
|
19019
|
+
var EVERY_ROW = { scope: "project", sessionId: "", worktree: "" };
|
|
19020
|
+
var IN_SCOPE = "(:scope <> 'session' OR session_id = :session_id) AND (:scope <> 'worktree' OR worktree = :worktree)";
|
|
19021
|
+
var scopeArgs = (w) => ({ scope: w.scope, session_id: w.sessionId, worktree: w.worktree });
|
|
19022
|
+
function labelStored(db, label2, w) {
|
|
19023
|
+
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;
|
|
19003
19024
|
}
|
|
19004
|
-
function storedLabel(db, source) {
|
|
19005
|
-
if (labelStored(db, source)) return source;
|
|
19025
|
+
function storedLabel(db, source, w = EVERY_ROW) {
|
|
19026
|
+
if (labelStored(db, source, w)) return source;
|
|
19006
19027
|
const canon = pathLabel(source);
|
|
19007
|
-
return canon !== source && labelStored(db, canon) ? canon : source;
|
|
19028
|
+
return canon !== source && labelStored(db, canon, w) ? canon : source;
|
|
19008
19029
|
}
|
|
19009
|
-
function newestId(db, label2) {
|
|
19010
|
-
const row5 = stmt(db.raw, "SELECT id FROM sources WHERE label =
|
|
19030
|
+
function newestId(db, label2, w) {
|
|
19031
|
+
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) });
|
|
19011
19032
|
return row5 === void 0 ? null : Number(row5.id);
|
|
19012
19033
|
}
|
|
19013
|
-
function labelOfId(db, id) {
|
|
19014
|
-
const row5 = stmt(db.raw, "SELECT label FROM sources WHERE id =
|
|
19034
|
+
function labelOfId(db, id, w) {
|
|
19035
|
+
const row5 = stmt(db.raw, "SELECT label FROM sources WHERE id = :id AND " + IN_SCOPE).get({ id, ...scopeArgs(w) });
|
|
19015
19036
|
return row5 === void 0 ? null : row5.label;
|
|
19016
19037
|
}
|
|
19017
|
-
function
|
|
19018
|
-
const named2 = storedLabel(db, source);
|
|
19038
|
+
function pickIn(db, source, suffix, w) {
|
|
19039
|
+
const named2 = storedLabel(db, source, w);
|
|
19019
19040
|
const id = parseSourceHandle(source);
|
|
19020
|
-
const own4 = newestId(db, named2);
|
|
19041
|
+
const own4 = newestId(db, named2, w);
|
|
19021
19042
|
if (own4 !== null) {
|
|
19022
|
-
const otherLabel = id === null || id === own4 ? null : labelOfId(db, id);
|
|
19043
|
+
const otherLabel = id === null || id === own4 ? null : labelOfId(db, id, EVERY_ROW);
|
|
19023
19044
|
return { label: named2, id: own4, via: "label", other: otherLabel === null || otherLabel === named2 ? null : { id, label: otherLabel } };
|
|
19024
19045
|
}
|
|
19025
19046
|
if (id !== null) {
|
|
19026
|
-
const label2 = labelOfId(db, id);
|
|
19047
|
+
const label2 = labelOfId(db, id, w);
|
|
19027
19048
|
if (label2 !== null) return { label: label2, id, via: "handle", other: null };
|
|
19028
19049
|
}
|
|
19029
19050
|
if (suffix) {
|
|
19030
19051
|
const prefix = named2 + LABEL_SUFFIX_SEP;
|
|
19031
|
-
const rows = stmt(db.raw, "SELECT id, label FROM sources WHERE substr(label, 1,
|
|
19052
|
+
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) });
|
|
19032
19053
|
for (const r of rows) {
|
|
19033
19054
|
if (r.label.lastIndexOf(LABEL_SUFFIX_SEP) === named2.length) return { label: r.label, id: Number(r.id), via: "suffix", other: null };
|
|
19034
19055
|
}
|
|
19035
19056
|
}
|
|
19036
19057
|
return { label: source, id: null, via: "none", other: null };
|
|
19037
19058
|
}
|
|
19059
|
+
function pickSource(db, source, suffix = true, w = EVERY_ROW) {
|
|
19060
|
+
if (w.scope !== "project") {
|
|
19061
|
+
const here = pickIn(db, source, suffix, w);
|
|
19062
|
+
if (here.via !== "none") return here;
|
|
19063
|
+
}
|
|
19064
|
+
return pickIn(db, source, suffix, EVERY_ROW);
|
|
19065
|
+
}
|
|
19038
19066
|
function collisionLine(value, pick4) {
|
|
19039
19067
|
if (pick4.other === null || pick4.id === null) return null;
|
|
19040
19068
|
return "Source " + JSON.stringify(value) + ": used the label " + shownLabel(pick4.label, null) + " (" + sourceHandle(pick4.id) + "); handle " + sourceHandle(pick4.other.id) + " is " + shownLabel(pick4.other.label, null) + (isLongLabel(pick4.other.label) ? ", search it by its full label." : ", search it with source:" + JSON.stringify(pick4.other.label) + ".");
|
|
@@ -19142,42 +19170,13 @@ function queryUnits(db, sessionId, q, limit, maxSourceId = Number.MAX_SAFE_INTEG
|
|
|
19142
19170
|
return rows.map((r) => ({ sourceId: Number(r.source_id), ord: Number(r.ord), label: r.label, body: r.body, score: r.score }));
|
|
19143
19171
|
}
|
|
19144
19172
|
|
|
19145
|
-
// src/core/index/units.ts
|
|
19146
|
-
function indentOf(line) {
|
|
19147
|
-
let n = 0;
|
|
19148
|
-
while (n < line.length && (line[n] === " " || line[n] === " ")) n++;
|
|
19149
|
-
return n;
|
|
19150
|
-
}
|
|
19151
|
-
function buildUnits(text) {
|
|
19152
|
-
const lines = text.split("\n");
|
|
19153
|
-
const stack2 = [];
|
|
19154
|
-
const out = [];
|
|
19155
|
-
let left = UNITS_ANCESTOR_FACTOR * Buffer.byteLength(text, "utf8");
|
|
19156
|
-
for (let i = 0; i < lines.length; i++) {
|
|
19157
|
-
const line = lines[i].endsWith("\r") ? lines[i].slice(0, -1) : lines[i];
|
|
19158
|
-
const indent = indentOf(line);
|
|
19159
|
-
if (indent === line.length) continue;
|
|
19160
|
-
while (stack2.length > 0 && stack2[stack2.length - 1].indent >= indent) stack2.pop();
|
|
19161
|
-
const bytes5 = Buffer.byteLength(line, "utf8");
|
|
19162
|
-
let size = bytes5;
|
|
19163
|
-
let from = stack2.length;
|
|
19164
|
-
while (from > 0) {
|
|
19165
|
-
const add = stack2[from - 1].bytes + 1;
|
|
19166
|
-
if (size + add > RECALL_BUDGET_BYTES || size - bytes5 + add > left) break;
|
|
19167
|
-
size += add;
|
|
19168
|
-
from--;
|
|
19169
|
-
}
|
|
19170
|
-
left -= size - bytes5;
|
|
19171
|
-
out.push({ ord: i, body: [...stack2.slice(from).map((s) => s.line), line].join("\n") });
|
|
19172
|
-
stack2.push({ indent, line, bytes: bytes5 });
|
|
19173
|
-
}
|
|
19174
|
-
return out;
|
|
19175
|
-
}
|
|
19176
|
-
|
|
19177
19173
|
// src/core/compaction/candidates.ts
|
|
19178
19174
|
function firstLine2(body) {
|
|
19179
|
-
const
|
|
19180
|
-
|
|
19175
|
+
const i = body.length - body.trimStart().length;
|
|
19176
|
+
if (i === body.length) return "";
|
|
19177
|
+
const start = i === 0 ? 0 : body.lastIndexOf("\n", i) + 1;
|
|
19178
|
+
const nl = body.indexOf("\n", i);
|
|
19179
|
+
return (start === 0 && nl < 0 ? body : body.slice(start, nl < 0 ? body.length : nl)).replaceAll("\r", " ");
|
|
19181
19180
|
}
|
|
19182
19181
|
function make(section, row5, text, repeatCount, query) {
|
|
19183
19182
|
const bytes5 = Buffer.byteLength(text, "utf8");
|
|
@@ -19720,7 +19719,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
19720
19719
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
19721
19720
|
return { end: start + r.read, written: r.written };
|
|
19722
19721
|
}
|
|
19723
|
-
function merge2(src, blocks,
|
|
19722
|
+
function merge2(src, blocks, join30, cap, lineCut) {
|
|
19724
19723
|
const out = [];
|
|
19725
19724
|
const scratch = new Uint8Array(cap);
|
|
19726
19725
|
let wide;
|
|
@@ -19730,7 +19729,7 @@ function merge2(src, blocks, join29, cap, lineCut) {
|
|
|
19730
19729
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
19731
19730
|
};
|
|
19732
19731
|
for (const b of blocks) {
|
|
19733
|
-
if (cur !== void 0 && !
|
|
19732
|
+
if (cur !== void 0 && !join30) {
|
|
19734
19733
|
emit(cur.start, cur.end, curBytes);
|
|
19735
19734
|
cur = void 0;
|
|
19736
19735
|
}
|
|
@@ -20051,37 +20050,204 @@ function lineShape(text) {
|
|
|
20051
20050
|
return { header, units };
|
|
20052
20051
|
}
|
|
20053
20052
|
|
|
20054
|
-
// src/core/
|
|
20055
|
-
|
|
20056
|
-
|
|
20057
|
-
|
|
20058
|
-
|
|
20059
|
-
|
|
20060
|
-
|
|
20061
|
-
|
|
20062
|
-
label: label2,
|
|
20063
|
-
bytes: Buffer.byteLength(text, "utf8"),
|
|
20064
|
-
chunkCount: chunks.length,
|
|
20065
|
-
createdAt: Date.now()
|
|
20066
|
-
}, chunks);
|
|
20067
|
-
return { sourceId, chunks: chunks.length };
|
|
20053
|
+
// src/core/hooks/spool.ts
|
|
20054
|
+
import { join as join7 } from "node:path";
|
|
20055
|
+
|
|
20056
|
+
// src/core/index/units.ts
|
|
20057
|
+
function indentOf(line) {
|
|
20058
|
+
let n = 0;
|
|
20059
|
+
while (n < line.length && (line[n] === " " || line[n] === " ")) n++;
|
|
20060
|
+
return n;
|
|
20068
20061
|
}
|
|
20069
|
-
function
|
|
20070
|
-
|
|
20062
|
+
function buildUnits(text) {
|
|
20063
|
+
const lines = text.split("\n");
|
|
20064
|
+
const stack2 = [];
|
|
20065
|
+
const out = [];
|
|
20066
|
+
let left = UNITS_ANCESTOR_FACTOR * Buffer.byteLength(text, "utf8");
|
|
20067
|
+
for (let i = 0; i < lines.length; i++) {
|
|
20068
|
+
const line = lines[i].endsWith("\r") ? lines[i].slice(0, -1) : lines[i];
|
|
20069
|
+
const indent = indentOf(line);
|
|
20070
|
+
if (indent === line.length) continue;
|
|
20071
|
+
while (stack2.length > 0 && stack2[stack2.length - 1].indent >= indent) stack2.pop();
|
|
20072
|
+
const bytes5 = Buffer.byteLength(line, "utf8");
|
|
20073
|
+
let size = bytes5;
|
|
20074
|
+
let from = stack2.length;
|
|
20075
|
+
while (from > 0) {
|
|
20076
|
+
const add = stack2[from - 1].bytes + 1;
|
|
20077
|
+
if (size + add > RECALL_BUDGET_BYTES || size - bytes5 + add > left) break;
|
|
20078
|
+
size += add;
|
|
20079
|
+
from--;
|
|
20080
|
+
}
|
|
20081
|
+
left -= size - bytes5;
|
|
20082
|
+
out.push({ ord: i, body: [...stack2.slice(from).map((s) => s.line), line].join("\n") });
|
|
20083
|
+
stack2.push({ indent, line, bytes: bytes5 });
|
|
20084
|
+
}
|
|
20085
|
+
return out;
|
|
20071
20086
|
}
|
|
20072
20087
|
|
|
20073
|
-
// src/core/hooks/
|
|
20074
|
-
|
|
20088
|
+
// src/core/hooks/spool.ts
|
|
20089
|
+
var { mkdirSync: mkdirSync3, readdirSync: readdirSync3, readFileSync: readFileSync5, renameSync: renameSync2, statSync: statSync4, unlinkSync, utimesSync, writeFileSync } = process.getBuiltinModule("node:fs");
|
|
20090
|
+
var OP_SUFFIX = ".json";
|
|
20091
|
+
var CLAIM_SUFFIX = ".claim";
|
|
20092
|
+
var TMP_SUFFIX = ".tmp";
|
|
20093
|
+
var BAD_SUFFIX = ".bad";
|
|
20094
|
+
var NAME_TIME_DIGITS = 15;
|
|
20095
|
+
var NAME_SEQ_DIGITS = 6;
|
|
20096
|
+
var nameSeq = 0;
|
|
20097
|
+
function isBusy(err) {
|
|
20098
|
+
const code = err?.errcode;
|
|
20099
|
+
return typeof code === "number" && (code & SQLITE_PRIMARY_CODE_MASK) === SQLITE_BUSY_CODE;
|
|
20100
|
+
}
|
|
20101
|
+
function message(err) {
|
|
20102
|
+
return err instanceof Error ? err.message : String(err);
|
|
20103
|
+
}
|
|
20104
|
+
async function hookDb(project) {
|
|
20105
|
+
const db = await openDb(project);
|
|
20106
|
+
db.raw.exec("PRAGMA busy_timeout = " + String(HOOK_BUSY_MS));
|
|
20107
|
+
return db;
|
|
20108
|
+
}
|
|
20109
|
+
function spoolDir(project) {
|
|
20110
|
+
return join7(project.projectDir, HOOK_SPOOL_DIR);
|
|
20111
|
+
}
|
|
20112
|
+
function spool(project, op) {
|
|
20113
|
+
const dir = spoolDir(project);
|
|
20114
|
+
mkdirSync3(dir, { recursive: true });
|
|
20115
|
+
const name = String(Date.now()).padStart(NAME_TIME_DIGITS, "0") + "-" + String(process.pid) + "-" + String(nameSeq++).padStart(NAME_SEQ_DIGITS, "0");
|
|
20116
|
+
const tmp = join7(dir, name + TMP_SUFFIX);
|
|
20117
|
+
writeFileSync(tmp, JSON.stringify(op));
|
|
20118
|
+
renameSync2(tmp, join7(dir, name + OP_SUFFIX));
|
|
20119
|
+
}
|
|
20120
|
+
function runOp(db, op, chunks, cur) {
|
|
20121
|
+
if (op.t === "row") {
|
|
20122
|
+
appendEvent(db, op.row, op.at);
|
|
20123
|
+
return null;
|
|
20124
|
+
}
|
|
20125
|
+
const c = chunks ?? chunkText(op.text, "text", op.max);
|
|
20126
|
+
let id = op.id;
|
|
20127
|
+
if (id === null) {
|
|
20128
|
+
id = reserveSource(db, op.src, c);
|
|
20129
|
+
cur.op = { ...op, id };
|
|
20130
|
+
} else if (chunks === void 0) {
|
|
20131
|
+
const sid = id;
|
|
20132
|
+
const gone = withWrite(db, (h) => {
|
|
20133
|
+
if (h.raw.prepare("SELECT 1 AS x FROM sources WHERE id = ?").get(sid) === void 0) return true;
|
|
20134
|
+
deleteChunkRows(h.raw, { sourceId: sid });
|
|
20135
|
+
return false;
|
|
20136
|
+
});
|
|
20137
|
+
if (gone) return null;
|
|
20138
|
+
}
|
|
20075
20139
|
try {
|
|
20076
|
-
|
|
20077
|
-
|
|
20140
|
+
insertChunks(db, id, op.src, c);
|
|
20141
|
+
if (op.units) insertUnits(db, id, op.src.sessionId, buildUnits(op.text));
|
|
20142
|
+
} catch (err) {
|
|
20143
|
+
if (isBusy(err)) throw err;
|
|
20144
|
+
const sid = id;
|
|
20145
|
+
withWrite(db, (h) => {
|
|
20146
|
+
deleteChunkRows(h.raw, { sourceId: sid });
|
|
20147
|
+
h.raw.prepare("DELETE FROM sources WHERE id = ?").run(sid);
|
|
20148
|
+
});
|
|
20149
|
+
throw err;
|
|
20150
|
+
}
|
|
20151
|
+
return id;
|
|
20152
|
+
}
|
|
20153
|
+
function writeOrSpool(project, db, op, chunks) {
|
|
20154
|
+
const cur = { op };
|
|
20155
|
+
try {
|
|
20156
|
+
return runOp(db, op, chunks, cur);
|
|
20078
20157
|
} catch (err) {
|
|
20079
|
-
|
|
20080
|
-
|
|
20158
|
+
if (!isBusy(err)) throw err;
|
|
20159
|
+
spool(project, cur.op);
|
|
20160
|
+
return cur.op.t === "src" ? cur.op.id : null;
|
|
20161
|
+
}
|
|
20162
|
+
}
|
|
20163
|
+
function writeDetached(project, op, what, chunks) {
|
|
20164
|
+
void (async () => {
|
|
20165
|
+
try {
|
|
20166
|
+
const db = await hookDb(project);
|
|
20167
|
+
if (drain(project, db)) spool(project, op);
|
|
20168
|
+
else writeOrSpool(project, db, op, chunks);
|
|
20169
|
+
} catch (err) {
|
|
20170
|
+
try {
|
|
20171
|
+
if (!isBusy(err)) throw err;
|
|
20172
|
+
spool(project, op);
|
|
20173
|
+
} catch (e) {
|
|
20174
|
+
process.stderr.write("hooks: " + what + " write failed: " + message(e) + "\n");
|
|
20175
|
+
}
|
|
20176
|
+
}
|
|
20177
|
+
})();
|
|
20178
|
+
}
|
|
20179
|
+
function claim(dir, name) {
|
|
20180
|
+
let base = name;
|
|
20181
|
+
if (name.endsWith(OP_SUFFIX + CLAIM_SUFFIX)) {
|
|
20182
|
+
const path8 = join7(dir, name);
|
|
20183
|
+
try {
|
|
20184
|
+
if (Date.now() - statSync4(path8).mtimeMs < SPOOL_CLAIM_STALE_MS) return null;
|
|
20185
|
+
base = name.slice(0, -CLAIM_SUFFIX.length);
|
|
20186
|
+
renameSync2(path8, join7(dir, base));
|
|
20187
|
+
} catch {
|
|
20188
|
+
return null;
|
|
20189
|
+
}
|
|
20190
|
+
} else if (!name.endsWith(OP_SUFFIX)) {
|
|
20191
|
+
return null;
|
|
20192
|
+
}
|
|
20193
|
+
const claimed = join7(dir, base + CLAIM_SUFFIX);
|
|
20194
|
+
try {
|
|
20195
|
+
renameSync2(join7(dir, base), claimed);
|
|
20196
|
+
const now = /* @__PURE__ */ new Date();
|
|
20197
|
+
utimesSync(claimed, now, now);
|
|
20198
|
+
return claimed;
|
|
20199
|
+
} catch {
|
|
20200
|
+
return null;
|
|
20081
20201
|
}
|
|
20082
20202
|
}
|
|
20203
|
+
function drain(project, db) {
|
|
20204
|
+
const dir = spoolDir(project);
|
|
20205
|
+
let names;
|
|
20206
|
+
try {
|
|
20207
|
+
names = readdirSync3(dir);
|
|
20208
|
+
} catch {
|
|
20209
|
+
return false;
|
|
20210
|
+
}
|
|
20211
|
+
const start = Date.now();
|
|
20212
|
+
for (const name of names.sort()) {
|
|
20213
|
+
if (Date.now() - start > SPOOL_DRAIN_MS) return false;
|
|
20214
|
+
const claimed = claim(dir, name);
|
|
20215
|
+
if (claimed === null) continue;
|
|
20216
|
+
const base = claimed.slice(0, -CLAIM_SUFFIX.length);
|
|
20217
|
+
let op;
|
|
20218
|
+
try {
|
|
20219
|
+
op = JSON.parse(readFileSync5(claimed, "utf8"));
|
|
20220
|
+
} catch (err) {
|
|
20221
|
+
process.stderr.write("hooks: pending write unreadable: " + message(err) + "\n");
|
|
20222
|
+
renameSync2(claimed, base + BAD_SUFFIX);
|
|
20223
|
+
continue;
|
|
20224
|
+
}
|
|
20225
|
+
const cur = { op };
|
|
20226
|
+
try {
|
|
20227
|
+
runOp(db, op, void 0, cur);
|
|
20228
|
+
} catch (err) {
|
|
20229
|
+
if (isBusy(err)) {
|
|
20230
|
+
if (cur.op === op) {
|
|
20231
|
+
renameSync2(claimed, base);
|
|
20232
|
+
} else {
|
|
20233
|
+
writeFileSync(base + TMP_SUFFIX, JSON.stringify(cur.op));
|
|
20234
|
+
renameSync2(base + TMP_SUFFIX, base);
|
|
20235
|
+
unlinkSync(claimed);
|
|
20236
|
+
}
|
|
20237
|
+
return true;
|
|
20238
|
+
}
|
|
20239
|
+
process.stderr.write("hooks: pending write failed: " + message(err) + "\n");
|
|
20240
|
+
renameSync2(claimed, base + BAD_SUFFIX);
|
|
20241
|
+
continue;
|
|
20242
|
+
}
|
|
20243
|
+
unlinkSync(claimed);
|
|
20244
|
+
}
|
|
20245
|
+
return false;
|
|
20246
|
+
}
|
|
20247
|
+
|
|
20248
|
+
// src/core/hooks/detached.ts
|
|
20083
20249
|
function appendDetached(project, sessionId, row5) {
|
|
20084
|
-
|
|
20250
|
+
writeDetached(project, { t: "row", row: row5, at: Date.now() }, "journal");
|
|
20085
20251
|
}
|
|
20086
20252
|
|
|
20087
20253
|
// src/core/hooks/handle-query.ts
|
|
@@ -20172,7 +20338,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
20172
20338
|
}
|
|
20173
20339
|
|
|
20174
20340
|
// src/core/hooks/fallback.ts
|
|
20175
|
-
import { join as
|
|
20341
|
+
import { join as join8, resolve as resolve7 } from "node:path";
|
|
20176
20342
|
var fs = process.getBuiltinModule("node:fs");
|
|
20177
20343
|
function isRec(v) {
|
|
20178
20344
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -20200,9 +20366,9 @@ function homeOf(env) {
|
|
|
20200
20366
|
}
|
|
20201
20367
|
function hookLogPath(env) {
|
|
20202
20368
|
const dir = env[DATA_DIR_ENV];
|
|
20203
|
-
if (dir !== void 0 && dir !== "") return
|
|
20369
|
+
if (dir !== void 0 && dir !== "") return join8(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
|
|
20204
20370
|
const home = homeOf(env);
|
|
20205
|
-
return home === "" ? "" :
|
|
20371
|
+
return home === "" ? "" : join8(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
|
|
20206
20372
|
}
|
|
20207
20373
|
function errorLabel(err) {
|
|
20208
20374
|
const code = isRec(err) ? err.code : void 0;
|
|
@@ -20213,7 +20379,7 @@ function logHookError(env, agent, stage, err) {
|
|
|
20213
20379
|
try {
|
|
20214
20380
|
const file2 = hookLogPath(env);
|
|
20215
20381
|
if (file2 === "") return;
|
|
20216
|
-
fs.mkdirSync(
|
|
20382
|
+
fs.mkdirSync(join8(file2, ".."), { recursive: true });
|
|
20217
20383
|
const line = JSON.stringify({
|
|
20218
20384
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
20219
20385
|
agent,
|
|
@@ -20327,14 +20493,14 @@ function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
|
20327
20493
|
var { read: read2, writeSync } = process.getBuiltinModule("node:fs");
|
|
20328
20494
|
|
|
20329
20495
|
// src/core/hooks/dispatch.ts
|
|
20330
|
-
var { lstatSync: lstatSync2, readFileSync:
|
|
20496
|
+
var { lstatSync: lstatSync2, readFileSync: readFileSync6 } = process.getBuiltinModule("node:fs");
|
|
20331
20497
|
var ALLOW2 = { kind: "allow" };
|
|
20332
20498
|
var EMPTY5 = { stdout: "", exitCode: 0 };
|
|
20333
20499
|
var DIGIT_0 = 48;
|
|
20334
20500
|
function isAgentId(s) {
|
|
20335
20501
|
return AGENT_IDS.includes(s);
|
|
20336
20502
|
}
|
|
20337
|
-
function
|
|
20503
|
+
function message2(err) {
|
|
20338
20504
|
return err instanceof Error ? err.message : String(err);
|
|
20339
20505
|
}
|
|
20340
20506
|
function str2(v) {
|
|
@@ -20348,7 +20514,7 @@ async function handleHook(agent, raw, env) {
|
|
|
20348
20514
|
const row5 = getAdapter(agent);
|
|
20349
20515
|
const report2 = (stage, err, line) => {
|
|
20350
20516
|
logHookError(env, agent, stage, err);
|
|
20351
|
-
process.stderr.write(line ?? "hooks: " + stage + " failed: " +
|
|
20517
|
+
process.stderr.write(line ?? "hooks: " + stage + " failed: " + message2(err) + "\n");
|
|
20352
20518
|
};
|
|
20353
20519
|
const fail7 = (stage, err, line) => {
|
|
20354
20520
|
report2(stage, err, line);
|
|
@@ -20374,7 +20540,7 @@ async function handleHook(agent, raw, env) {
|
|
|
20374
20540
|
const argv = agent === "vscode" ? [WORKSPACE_FOLDER_FLAG, ev.cwd] : process.argv;
|
|
20375
20541
|
project = resolveProject(agent, { env, argv, cwd: ev.cwd, piCwd: getAdapter(agent).projectSource === "pi:ctx.cwd" ? ev.cwd : void 0 });
|
|
20376
20542
|
} catch (err) {
|
|
20377
|
-
return fail7("project", err, "hooks: no project: " + String(err.code ?? "ERROR") + " " +
|
|
20543
|
+
return fail7("project", err, "hooks: no project: " + String(err.code ?? "ERROR") + " " + message2(err) + "\n");
|
|
20378
20544
|
}
|
|
20379
20545
|
let decision;
|
|
20380
20546
|
const settle3 = {};
|
|
@@ -20419,14 +20585,14 @@ function compactText(db, ev, row5) {
|
|
|
20419
20585
|
return renderState(readSessionEvents(db, ev.sessionId), ev.turn ?? 0, void 0, row5.toolNamePrefix);
|
|
20420
20586
|
}
|
|
20421
20587
|
async function sessionStart(ev, row5, project) {
|
|
20422
|
-
if (ev.source === "compact" && hasRecall(row5)) markCompacted(await
|
|
20588
|
+
if (ev.source === "compact" && hasRecall(row5)) markCompacted(await hookDb(project), ev.sessionId);
|
|
20423
20589
|
if (ev.source === "compact" && row5.compactDelivery === "sessionstart") {
|
|
20424
|
-
const db2 = await
|
|
20590
|
+
const db2 = await hookDb(project);
|
|
20425
20591
|
const onceKey = COMPACT_STATE_KEY + ":" + lastSessionSeq(db2, ev.sessionId);
|
|
20426
20592
|
if (!shouldHint(db2, ev.sessionId, onceKey)) return ALLOW2;
|
|
20427
20593
|
return { kind: "hint", text: compactText(db2, ev, row5), onceKey };
|
|
20428
20594
|
}
|
|
20429
|
-
const db = await
|
|
20595
|
+
const db = await hookDb(project);
|
|
20430
20596
|
if (row5.compactDelivery === "opencode-cache" && metaTake(db, PENDING_COMPACT_META_PREFIX + ev.sessionId) !== null) {
|
|
20431
20597
|
return { kind: "hint", text: compactText(db, ev, row5), onceKey: PENDING_COMPACT_KEY };
|
|
20432
20598
|
}
|
|
@@ -20454,7 +20620,7 @@ async function userPromptSubmit(ev, row5, project) {
|
|
|
20454
20620
|
});
|
|
20455
20621
|
echoDetached(ev, project, body);
|
|
20456
20622
|
if (row5.compactDelivery === "pending-flag") {
|
|
20457
|
-
const db = await
|
|
20623
|
+
const db = await hookDb(project);
|
|
20458
20624
|
if (metaTake(db, PENDING_COMPACT_META_PREFIX + ev.sessionId) !== null) {
|
|
20459
20625
|
return { kind: "hint", text: compactText(db, ev, row5), onceKey: PENDING_COMPACT_KEY };
|
|
20460
20626
|
}
|
|
@@ -20464,7 +20630,7 @@ async function userPromptSubmit(ev, row5, project) {
|
|
|
20464
20630
|
}
|
|
20465
20631
|
async function firstTurnResume(ev, row5, project) {
|
|
20466
20632
|
if (row5.eventMap.SessionStart !== void 0 || ev.sessionId === "") return null;
|
|
20467
|
-
const db = await
|
|
20633
|
+
const db = await hookDb(project);
|
|
20468
20634
|
if (hasSessionRows(db, ev.sessionId)) return null;
|
|
20469
20635
|
if (!shouldHint(db, ev.sessionId, RESUME_HINT_KEY)) return null;
|
|
20470
20636
|
if (!hasAgentRows(db, project.worktree, ev.agent)) return null;
|
|
@@ -20508,7 +20674,7 @@ function seenUnitKeys(value) {
|
|
|
20508
20674
|
}
|
|
20509
20675
|
async function recall(ev, row5, project, prompt) {
|
|
20510
20676
|
if (!hasRecall(row5) || ev.sessionId === "") return ALLOW2;
|
|
20511
|
-
const db = await
|
|
20677
|
+
const db = await hookDb(project);
|
|
20512
20678
|
const compacted = metaGet(db, COMPACTED_META_PREFIX + ev.sessionId);
|
|
20513
20679
|
if (compacted === null) return ALLOW2;
|
|
20514
20680
|
const boundary = compactBoundary(compacted);
|
|
@@ -20541,7 +20707,7 @@ function readOptions(value) {
|
|
|
20541
20707
|
function echoDetached(ev, project, prompt) {
|
|
20542
20708
|
if (ev.sessionId === "") return;
|
|
20543
20709
|
const key = optionsKey(ev.sessionId);
|
|
20544
|
-
void
|
|
20710
|
+
void hookDb(project).then((db) => {
|
|
20545
20711
|
if (metaGet(db, key) === null) return;
|
|
20546
20712
|
const taken = metaTake(db, key);
|
|
20547
20713
|
const offered = taken === null ? null : readOptions(taken);
|
|
@@ -20549,12 +20715,12 @@ function echoDetached(ev, project, prompt) {
|
|
|
20549
20715
|
const part = optionEchoDecision(prompt, offered.labels, offered.seq);
|
|
20550
20716
|
if (part !== null) writeDecisions(db, ev, project, [part]);
|
|
20551
20717
|
}).catch((err) => {
|
|
20552
|
-
process.stderr.write("hooks: decision write failed: " +
|
|
20718
|
+
process.stderr.write("hooks: decision write failed: " + message2(err) + "\n");
|
|
20553
20719
|
});
|
|
20554
20720
|
}
|
|
20555
20721
|
function writeDecisions(db, ev, project, parts) {
|
|
20556
20722
|
for (const part of parts) {
|
|
20557
|
-
|
|
20723
|
+
writeOrSpool(project, db, { t: "row", at: Date.now(), row: {
|
|
20558
20724
|
session_id: ev.sessionId,
|
|
20559
20725
|
worktree: project.worktree,
|
|
20560
20726
|
agent: ev.agent,
|
|
@@ -20569,22 +20735,22 @@ function writeDecisions(db, ev, project, parts) {
|
|
|
20569
20735
|
turn: ev.turn ?? 0,
|
|
20570
20736
|
sandbox_bytes: 0,
|
|
20571
20737
|
returned_bytes: 0
|
|
20572
|
-
});
|
|
20573
|
-
|
|
20738
|
+
} });
|
|
20739
|
+
writeOrSpool(project, db, { t: "src", id: null, src: sourceRowOf(project, ev.sessionId, DECISION_SOURCE), text: part.body, max: MAX_CHUNK_BYTES, units: false });
|
|
20574
20740
|
}
|
|
20575
20741
|
}
|
|
20576
20742
|
function askDetached(ev, project, tool, text) {
|
|
20577
20743
|
const parts = answerDecisions(text);
|
|
20578
20744
|
const labels = parts.length === 0 ? askOptionLabels(tool.input) : [];
|
|
20579
20745
|
if (parts.length === 0 && labels.length === 0) return;
|
|
20580
|
-
void
|
|
20746
|
+
void hookDb(project).then((db) => {
|
|
20581
20747
|
if (parts.length > 0) return writeDecisions(db, ev, project, parts);
|
|
20582
20748
|
const prompts = readSessionEvents(db, ev.sessionId, "prompt");
|
|
20583
20749
|
const last2 = prompts[prompts.length - 1];
|
|
20584
20750
|
if (last2 === void 0 || ev.sessionId === "") return;
|
|
20585
20751
|
metaSet(db, optionsKey(ev.sessionId), JSON.stringify({ seq: last2.seq, labels }));
|
|
20586
20752
|
}).catch((err) => {
|
|
20587
|
-
process.stderr.write("hooks: decision write failed: " +
|
|
20753
|
+
process.stderr.write("hooks: decision write failed: " + message2(err) + "\n");
|
|
20588
20754
|
});
|
|
20589
20755
|
}
|
|
20590
20756
|
function toolSetSources(ev, project, env) {
|
|
@@ -20620,7 +20786,7 @@ function caseB(ev, row5, d0, userDeny) {
|
|
|
20620
20786
|
if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
|
|
20621
20787
|
const command = tool.input.command;
|
|
20622
20788
|
if (typeof command !== "string") return d0;
|
|
20623
|
-
const wrapper = '"' +
|
|
20789
|
+
const wrapper = '"' + join9(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
|
|
20624
20790
|
const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
|
|
20625
20791
|
return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
|
|
20626
20792
|
}
|
|
@@ -20661,7 +20827,8 @@ async function postToolUse(ev, row5, project, env, settle3) {
|
|
|
20661
20827
|
const tool = ev.tool;
|
|
20662
20828
|
if (tool === void 0 || tool.canonicalName.startsWith(OWN_TOOL_PREFIX)) return ALLOW2;
|
|
20663
20829
|
const result = ev.result ?? { isError: false, bytes: 0 };
|
|
20664
|
-
const
|
|
20830
|
+
const whole2 = wholeOutput(result, ev.sessionId, env);
|
|
20831
|
+
const text = whole2.text;
|
|
20665
20832
|
if (result.persistedPath !== void 0) result.bytes = Buffer.byteLength(text);
|
|
20666
20833
|
if (tool.canonicalName === DECISION_TOOL) askDetached(ev, project, tool, text);
|
|
20667
20834
|
const kind = journalKind(tool, row5, result.isError);
|
|
@@ -20688,7 +20855,7 @@ async function postToolUse(ev, row5, project, env, settle3) {
|
|
|
20688
20855
|
};
|
|
20689
20856
|
let decision;
|
|
20690
20857
|
try {
|
|
20691
|
-
decision = await postReplace(ev, row5, project, env, tool, result, text);
|
|
20858
|
+
decision = await postReplace(ev, row5, project, env, tool, result, text, whole2.file);
|
|
20692
20859
|
} catch (err) {
|
|
20693
20860
|
journal(result.bytes);
|
|
20694
20861
|
throw err;
|
|
@@ -20702,19 +20869,22 @@ function ownRead(ev, tool, env) {
|
|
|
20702
20869
|
const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
|
|
20703
20870
|
return p !== void 0 && isOwnFile(ev.agent, ev.cwd, p, env);
|
|
20704
20871
|
}
|
|
20705
|
-
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
20872
|
+
async function postReplace(ev, row5, project, env, tool, result, text, persistedFile) {
|
|
20706
20873
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
20707
20874
|
if (boundedRead(tool)) return ALLOW2;
|
|
20708
20875
|
if (ompRangedRead(ev, tool)) return ALLOW2;
|
|
20709
20876
|
if (ownRead(ev, tool, env)) return ALLOW2;
|
|
20877
|
+
if (SKILL_LOAD_TOOLS.includes(tool.canonicalName)) return ALLOW2;
|
|
20710
20878
|
if (result.keep === true) return ALLOW2;
|
|
20711
20879
|
if (!hasReplace(row5)) return ALLOW2;
|
|
20712
20880
|
let label2;
|
|
20713
20881
|
let caller = { ctx: true, shell: true, read: false };
|
|
20882
|
+
let canRead = true;
|
|
20714
20883
|
if (isSubagentCall(ev)) {
|
|
20715
20884
|
const set3 = toolSetForAgentType(ev, toolSetSources(ev, project, env));
|
|
20716
20885
|
const subCase = pickSubagentCase(ev, set3);
|
|
20717
20886
|
const has3 = (names) => set3 !== null && names.some((n) => set3.includes(n));
|
|
20887
|
+
canRead = has3(row5.nativeTools.read ?? []);
|
|
20718
20888
|
caller = {
|
|
20719
20889
|
ctx: subCase === "A",
|
|
20720
20890
|
shell: has3(row5.nativeTools.shell),
|
|
@@ -20727,29 +20897,33 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
|
20727
20897
|
}
|
|
20728
20898
|
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;
|
|
20729
20899
|
const chunks = chunkText(text, "text", REPLACE_CHUNK_BYTES);
|
|
20730
|
-
const db = await
|
|
20900
|
+
const db = await hookDb(project);
|
|
20901
|
+
const op = { t: "src", id: null, src: sourceRowOf(project, ev.sessionId, label2), text, max: REPLACE_CHUNK_BYTES, units: true };
|
|
20731
20902
|
let sourceId;
|
|
20732
20903
|
if (result.bytes <= SYNC_INDEX_MAX_BYTES) {
|
|
20733
|
-
sourceId =
|
|
20734
|
-
insertUnits(db, sourceId, ev.sessionId, buildUnits(text));
|
|
20904
|
+
sourceId = writeOrSpool(project, db, op, chunks);
|
|
20735
20905
|
} else {
|
|
20736
|
-
sourceId =
|
|
20737
|
-
indexDetached(project,
|
|
20906
|
+
sourceId = reserveOrSpool(project, db, op, chunks);
|
|
20907
|
+
if (sourceId !== null) indexDetached(project, { ...op, id: sourceId }, chunks);
|
|
20738
20908
|
}
|
|
20739
|
-
|
|
20909
|
+
if (pluginMcpCall(tool)) return ALLOW2;
|
|
20910
|
+
const handle = sourceId === null ? label2 : sourceHandle(sourceId);
|
|
20740
20911
|
const prompt = await lastPrompt(project, ev.sessionId);
|
|
20741
20912
|
const rankQuery = prompt.trim() === "" ? void 0 : intent + " " + prompt;
|
|
20742
20913
|
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);
|
|
20743
20914
|
const budget = replaceBudget(handleLine, moreLine2(intent, label2));
|
|
20744
|
-
const pointer = handleLine + (caller.shell && ev.agent === RUN_WRAPPER_AGENT ? searchTwin(handle, intent, project) : "");
|
|
20915
|
+
const pointer = handleLine + (caller.shell && ev.agent === RUN_WRAPPER_AGENT && sourceId !== null ? searchTwin(handle, intent, project) : "") + (persistedFile !== void 0 && canRead ? PERSISTED_FILE_LINE(persistedFile) : "");
|
|
20745
20916
|
const digest = shapeDigest(text, rankQuery ?? intent, SHAPE_RETURN_BYTES);
|
|
20746
20917
|
if (digest !== null) return { kind: "replace", output: replaceOutput(digest, pointer) };
|
|
20747
20918
|
const selected = selectChunksInMemory(chunks, intent, budget, label2, rankQuery);
|
|
20748
20919
|
return { kind: "replace", output: selected.more !== null ? replaceOutput(selected.text, pointer) : selected.text };
|
|
20749
20920
|
}
|
|
20921
|
+
function pluginMcpCall(tool) {
|
|
20922
|
+
return tool.callId !== void 0 && tool.callId.startsWith(PLUGIN_CALL_ID_PREFIX) && tool.name.startsWith(MCP_SERVER_TOOL_PREFIX);
|
|
20923
|
+
}
|
|
20750
20924
|
function searchTwin(handle, intent, project) {
|
|
20751
20925
|
const terms = Buffer.byteLength(intent, "utf8") > ECHO_MAX_BYTES ? "" : intent;
|
|
20752
|
-
return SEARCH_TWIN_LINE(
|
|
20926
|
+
return SEARCH_TWIN_LINE(join9(dirname4(process.argv[1] ?? ""), SEARCH_WRAPPER_FILE), handle, terms, project.worktree);
|
|
20753
20927
|
}
|
|
20754
20928
|
function boundedRead(tool) {
|
|
20755
20929
|
return RANGE_READ_TOOLS.includes(tool.canonicalName) && READ_RANGE_KEYS.some((k) => tool.input[k] !== void 0 && tool.input[k] !== null);
|
|
@@ -20809,7 +20983,7 @@ function replaceBudget(handleLine, more) {
|
|
|
20809
20983
|
}
|
|
20810
20984
|
function hostToolResult(file2, sessionId, env) {
|
|
20811
20985
|
if (sessionId === "" || sessionId.includes(sep3) || sessionId.includes("/")) return false;
|
|
20812
|
-
const projects =
|
|
20986
|
+
const projects = join9(claudeDirOf(env, homeDirOf(env) ?? ""), PROJECTS_DIR_NAME);
|
|
20813
20987
|
const steps = relative3(projects, resolve8(file2)).split(sep3);
|
|
20814
20988
|
if (steps.length !== 4 || steps.includes("..") || steps.includes("")) return false;
|
|
20815
20989
|
if (steps[1] !== sessionId || steps[2] !== CLAUDE_TOOL_RESULTS_DIR_NAME) return false;
|
|
@@ -20818,20 +20992,20 @@ function hostToolResult(file2, sessionId, env) {
|
|
|
20818
20992
|
}
|
|
20819
20993
|
function wholeOutput(result, sessionId, env) {
|
|
20820
20994
|
const head2 = result.text ?? "";
|
|
20821
|
-
if (result.persistedPath === void 0) return head2;
|
|
20995
|
+
if (result.persistedPath === void 0) return { text: head2 };
|
|
20822
20996
|
try {
|
|
20823
20997
|
if (!hostToolResult(result.persistedPath, sessionId, env)) {
|
|
20824
20998
|
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"));
|
|
20825
|
-
return head2;
|
|
20999
|
+
return { text: head2 };
|
|
20826
21000
|
}
|
|
20827
|
-
return
|
|
21001
|
+
return { text: readFileSync6(result.persistedPath, "utf8"), file: result.persistedPath };
|
|
20828
21002
|
} catch {
|
|
20829
|
-
return head2;
|
|
21003
|
+
return { text: head2 };
|
|
20830
21004
|
}
|
|
20831
21005
|
}
|
|
20832
21006
|
async function lastPrompt(project, sessionId) {
|
|
20833
21007
|
try {
|
|
20834
|
-
return readLastPrompt(await
|
|
21008
|
+
return readLastPrompt(await hookDb(project), sessionId);
|
|
20835
21009
|
} catch {
|
|
20836
21010
|
return "";
|
|
20837
21011
|
}
|
|
@@ -20842,18 +21016,23 @@ function mainLabel(tool, ev) {
|
|
|
20842
21016
|
const head2 = (tool.canonicalName + ":" + (nl < 0 ? cmd : cmd.slice(0, nl))).slice(0, SOURCE_LABEL_MAX_CHARS);
|
|
20843
21017
|
return head2 + "#" + (tool.callId ?? String(ev.turn ?? 0));
|
|
20844
21018
|
}
|
|
20845
|
-
function indexDetached(project,
|
|
20846
|
-
|
|
20847
|
-
|
|
20848
|
-
|
|
20849
|
-
|
|
20850
|
-
|
|
21019
|
+
function indexDetached(project, op, chunks) {
|
|
21020
|
+
writeDetached(project, op, "index", chunks);
|
|
21021
|
+
}
|
|
21022
|
+
function reserveOrSpool(project, db, op, chunks) {
|
|
21023
|
+
try {
|
|
21024
|
+
return reserveSource(db, op.src, chunks);
|
|
21025
|
+
} catch (err) {
|
|
21026
|
+
if (!isBusy(err)) throw err;
|
|
21027
|
+
spool(project, op);
|
|
21028
|
+
return null;
|
|
21029
|
+
}
|
|
20851
21030
|
}
|
|
20852
21031
|
function sourceRowOf(project, sessionId, label2) {
|
|
20853
21032
|
return { sessionId, worktree: project.worktree, agent: project.agent, kind: "content", label: label2, createdAt: Date.now() };
|
|
20854
21033
|
}
|
|
20855
21034
|
async function preCompact(ev, row5, project) {
|
|
20856
|
-
const db = await
|
|
21035
|
+
const db = await hookDb(project);
|
|
20857
21036
|
metaSet(db, PENDING_COMPACT_META_PREFIX + ev.sessionId, PENDING_COMPACT_FLAG);
|
|
20858
21037
|
if (hasRecall(row5)) markCompacted(db, ev.sessionId);
|
|
20859
21038
|
return ALLOW2;
|
|
@@ -20935,7 +21114,7 @@ function buildChildEnv(parent, extra) {
|
|
|
20935
21114
|
}
|
|
20936
21115
|
|
|
20937
21116
|
// src/core/sandbox/runtimes.ts
|
|
20938
|
-
import { accessSync, constants as fsConstants, statSync as
|
|
21117
|
+
import { accessSync, constants as fsConstants, statSync as statSync5 } from "node:fs";
|
|
20939
21118
|
import path from "node:path";
|
|
20940
21119
|
|
|
20941
21120
|
// src/core/sandbox/path-entries.ts
|
|
@@ -20980,7 +21159,7 @@ function fileNames(name, pathExt) {
|
|
|
20980
21159
|
function probe(full) {
|
|
20981
21160
|
let st;
|
|
20982
21161
|
try {
|
|
20983
|
-
st =
|
|
21162
|
+
st = statSync5(full, { throwIfNoEntry: false });
|
|
20984
21163
|
} catch {
|
|
20985
21164
|
return "unreadable";
|
|
20986
21165
|
}
|
|
@@ -21175,8 +21354,8 @@ function runProcess(argv, o) {
|
|
|
21175
21354
|
}
|
|
21176
21355
|
|
|
21177
21356
|
// src/core/index/auto-memory.ts
|
|
21178
|
-
import { readdirSync as
|
|
21179
|
-
import { join as
|
|
21357
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync7, statSync as statSync6 } from "node:fs";
|
|
21358
|
+
import { join as join10 } from "node:path";
|
|
21180
21359
|
var MEMORY_FILES = Object.freeze([
|
|
21181
21360
|
Object.freeze(["CLAUDE.md"]),
|
|
21182
21361
|
Object.freeze(["CLAUDE.local.md"]),
|
|
@@ -21190,7 +21369,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
21190
21369
|
var MD = ".md";
|
|
21191
21370
|
function steeringFiles(worktree) {
|
|
21192
21371
|
try {
|
|
21193
|
-
return
|
|
21372
|
+
return readdirSync4(join10(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
21194
21373
|
} catch {
|
|
21195
21374
|
return [];
|
|
21196
21375
|
}
|
|
@@ -21198,10 +21377,10 @@ function steeringFiles(worktree) {
|
|
|
21198
21377
|
function readAutoMemory(project) {
|
|
21199
21378
|
const rows = [];
|
|
21200
21379
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
21201
|
-
const path8 =
|
|
21380
|
+
const path8 = join10(project.worktree, ...segs);
|
|
21202
21381
|
if (!isInside(project.worktree, path8)) continue;
|
|
21203
21382
|
try {
|
|
21204
|
-
const st =
|
|
21383
|
+
const st = statSync6(path8);
|
|
21205
21384
|
if (!st.isFile()) continue;
|
|
21206
21385
|
rows.push({
|
|
21207
21386
|
origin: "memory",
|
|
@@ -21210,7 +21389,7 @@ function readAutoMemory(project) {
|
|
|
21210
21389
|
sourceId: null,
|
|
21211
21390
|
path: path8,
|
|
21212
21391
|
label: segs.join("/"),
|
|
21213
|
-
text:
|
|
21392
|
+
text: readFileSync7(path8, "utf8")
|
|
21214
21393
|
});
|
|
21215
21394
|
} catch {
|
|
21216
21395
|
}
|
|
@@ -21274,10 +21453,11 @@ function sourceCount(db, scope, ctx, source) {
|
|
|
21274
21453
|
function zeroHits(db, scope, ctx, source, mem, nm, queries, offset = 0) {
|
|
21275
21454
|
const inScope = sourceCount(db, scope, ctx, source);
|
|
21276
21455
|
const n = inScope + mem.rows.length;
|
|
21277
|
-
if (offset > 0) return reply("No more hits past offset " + offset + ' in scope "' + scope + '" across ' + n + " source(s).", false);
|
|
21278
21456
|
const head2 = 'No hits in scope "' + scope + '" across ' + n + " source(s).";
|
|
21279
21457
|
const pick4 = nm.pick;
|
|
21280
|
-
if (pick4 === null || mem.named || inScope > 0)
|
|
21458
|
+
if (pick4 === null || mem.named || inScope > 0) {
|
|
21459
|
+
return reply(offset > 0 ? "No more hits past offset " + offset + ' in scope "' + scope + '" across ' + n + " source(s)." : head2, false);
|
|
21460
|
+
}
|
|
21281
21461
|
if (pick4.id !== null) {
|
|
21282
21462
|
const wider = scope === "session" && sourceCount(db, "worktree", ctx, source) > 0 ? "worktree" : "project";
|
|
21283
21463
|
return reply(head2 + "\nSource " + JSON.stringify(nm.arg) + ' is stored in scope "' + wider + '": ' + callText(queries, wider, nm.arg, "") + " searches it.", false);
|
|
@@ -21562,7 +21742,8 @@ async function handler(input, ctx) {
|
|
|
21562
21742
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
21563
21743
|
try {
|
|
21564
21744
|
const given = input.source;
|
|
21565
|
-
const
|
|
21745
|
+
const within = { scope, sessionId: ctx.sessionId, worktree: ctx.project.worktree };
|
|
21746
|
+
const pick4 = given !== void 0 && given !== DECISION_SOURCE ? pickSource(db, given, true, within) : null;
|
|
21566
21747
|
if (pick4 !== null) input = { ...input, source: pick4.label };
|
|
21567
21748
|
const nm = named(given, pick4);
|
|
21568
21749
|
const indexed = pick4 !== null && pick4.id !== null;
|
|
@@ -21811,19 +21992,19 @@ var ctxBatch = Object.freeze({
|
|
|
21811
21992
|
});
|
|
21812
21993
|
|
|
21813
21994
|
// src/core/tools/doctor.ts
|
|
21814
|
-
import { readdirSync as
|
|
21815
|
-
import { basename as basename5, join as
|
|
21995
|
+
import { readdirSync as readdirSync9, readFileSync as readFileSync18, existsSync as existsSync17 } from "node:fs";
|
|
21996
|
+
import { basename as basename5, join as join21 } from "node:path";
|
|
21816
21997
|
|
|
21817
21998
|
// src/core/ops/bundle-dir.ts
|
|
21818
21999
|
import { existsSync as existsSync4 } from "node:fs";
|
|
21819
|
-
import { dirname as dirname5, join as
|
|
22000
|
+
import { dirname as dirname5, join as join11 } from "node:path";
|
|
21820
22001
|
import { fileURLToPath } from "node:url";
|
|
21821
22002
|
function bundleDirOf(argv1, moduleFile) {
|
|
21822
22003
|
const own4 = dirname5(argv1);
|
|
21823
|
-
if (existsSync4(
|
|
22004
|
+
if (existsSync4(join11(own4, SERVER_ENTRY_FILE))) return own4;
|
|
21824
22005
|
let dir = dirname5(moduleFile);
|
|
21825
22006
|
for (; ; ) {
|
|
21826
|
-
if (existsSync4(
|
|
22007
|
+
if (existsSync4(join11(dir, SERVER_ENTRY_FILE))) return dir;
|
|
21827
22008
|
const up = dirname5(dir);
|
|
21828
22009
|
if (up === dir) return own4;
|
|
21829
22010
|
dir = up;
|
|
@@ -21837,17 +22018,17 @@ function ownBundleDir() {
|
|
|
21837
22018
|
}
|
|
21838
22019
|
|
|
21839
22020
|
// src/core/ops/doctor-config.ts
|
|
21840
|
-
import { existsSync as existsSync11, readdirSync as
|
|
21841
|
-
import { dirname as dirname8, isAbsolute as
|
|
22021
|
+
import { existsSync as existsSync11, readdirSync as readdirSync7, readFileSync as readFileSync14 } from "node:fs";
|
|
22022
|
+
import { dirname as dirname8, isAbsolute as isAbsolute6, join as join17, resolve as resolve9 } from "node:path";
|
|
21842
22023
|
|
|
21843
22024
|
// src/core/ops/detect-v1.ts
|
|
21844
|
-
import { existsSync as existsSync6, opendirSync, readdirSync as
|
|
22025
|
+
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync5, readFileSync as readFileSync9 } from "node:fs";
|
|
21845
22026
|
import { tmpdir } from "node:os";
|
|
21846
|
-
import { join as
|
|
22027
|
+
import { join as join13 } from "node:path";
|
|
21847
22028
|
|
|
21848
22029
|
// src/core/ops/host-config.ts
|
|
21849
|
-
import { existsSync as existsSync5, readFileSync as
|
|
21850
|
-
import { dirname as dirname6, join as
|
|
22030
|
+
import { existsSync as existsSync5, readFileSync as readFileSync8 } from "node:fs";
|
|
22031
|
+
import { dirname as dirname6, join as join12 } from "node:path";
|
|
21851
22032
|
|
|
21852
22033
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
21853
22034
|
var KEYS2 = {
|
|
@@ -23893,7 +24074,7 @@ function parseTOML(code, options) {
|
|
|
23893
24074
|
}
|
|
23894
24075
|
|
|
23895
24076
|
// src/core/ops/atomic-file.ts
|
|
23896
|
-
import { mkdirSync as
|
|
24077
|
+
import { mkdirSync as mkdirSync4, renameSync as renameSync3, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
23897
24078
|
import path3 from "node:path";
|
|
23898
24079
|
function sleepSync(ms) {
|
|
23899
24080
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
@@ -23902,7 +24083,7 @@ function errCode2(e) {
|
|
|
23902
24083
|
return e.code;
|
|
23903
24084
|
}
|
|
23904
24085
|
function renameWithRetry(from, to, opts = {}) {
|
|
23905
|
-
const rename = opts.rename ??
|
|
24086
|
+
const rename = opts.rename ?? renameSync3;
|
|
23906
24087
|
const sleep2 = opts.sleep ?? sleepSync;
|
|
23907
24088
|
const win = (opts.platform ?? process.platform) === "win32";
|
|
23908
24089
|
for (let attempt = 0; ; attempt += 1) {
|
|
@@ -23917,7 +24098,7 @@ function renameWithRetry(from, to, opts = {}) {
|
|
|
23917
24098
|
}
|
|
23918
24099
|
}
|
|
23919
24100
|
function unlinkWithRetry(file2, opts = {}) {
|
|
23920
|
-
const unlink = opts.unlink ??
|
|
24101
|
+
const unlink = opts.unlink ?? unlinkSync2;
|
|
23921
24102
|
const sleep2 = opts.sleep ?? sleepSync;
|
|
23922
24103
|
const win = (opts.platform ?? process.platform) === "win32";
|
|
23923
24104
|
for (let attempt = 0; ; attempt += 1) {
|
|
@@ -23944,10 +24125,10 @@ function removeTmpFile(tmp, opts = {}) {
|
|
|
23944
24125
|
}
|
|
23945
24126
|
}
|
|
23946
24127
|
function atomicWriteFile(file2, text, opts = {}) {
|
|
23947
|
-
|
|
24128
|
+
mkdirSync4(path3.dirname(file2), { recursive: true });
|
|
23948
24129
|
const tmp = path3.join(path3.dirname(file2), `${ATOMIC_TMP_PREFIX}${path3.basename(file2)}${ATOMIC_TMP_MARK}${process.pid}`);
|
|
23949
24130
|
try {
|
|
23950
|
-
|
|
24131
|
+
writeFileSync2(tmp, text);
|
|
23951
24132
|
renameWithRetry(tmp, file2, opts);
|
|
23952
24133
|
} catch (e) {
|
|
23953
24134
|
removeTmpFile(tmp, opts);
|
|
@@ -23964,10 +24145,10 @@ function formatOf(path8) {
|
|
|
23964
24145
|
function readHostConfig(agent, path8) {
|
|
23965
24146
|
let file2 = path8;
|
|
23966
24147
|
if (agent === "opencode") {
|
|
23967
|
-
const jsonc =
|
|
24148
|
+
const jsonc = join12(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
|
|
23968
24149
|
if (existsSync5(jsonc)) file2 = jsonc;
|
|
23969
24150
|
}
|
|
23970
|
-
const raw = existsSync5(file2) ?
|
|
24151
|
+
const raw = existsSync5(file2) ? readFileSync8(file2, "utf8") : "";
|
|
23971
24152
|
return { agent, text: hostText(raw), format: agent === "opencode" && !file2.endsWith(TOML_EXT) ? "jsonc" : formatOf(file2), path: file2, layout: hostLayout(raw) };
|
|
23972
24153
|
}
|
|
23973
24154
|
function stripJsonComments(text) {
|
|
@@ -24312,7 +24493,7 @@ function setText(agent, path8, text, format, key, value) {
|
|
|
24312
24493
|
}
|
|
24313
24494
|
}
|
|
24314
24495
|
function serverScript() {
|
|
24315
|
-
return
|
|
24496
|
+
return join12(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
24316
24497
|
}
|
|
24317
24498
|
function isNodeCommand(command) {
|
|
24318
24499
|
if (typeof command !== "string") return false;
|
|
@@ -24439,14 +24620,14 @@ function stripJsonc(text) {
|
|
|
24439
24620
|
}
|
|
24440
24621
|
function readJson(file2) {
|
|
24441
24622
|
try {
|
|
24442
|
-
return JSON.parse(stripJsonc(hostText(
|
|
24623
|
+
return JSON.parse(stripJsonc(hostText(readFileSync9(file2, "utf8"))));
|
|
24443
24624
|
} catch {
|
|
24444
24625
|
return void 0;
|
|
24445
24626
|
}
|
|
24446
24627
|
}
|
|
24447
24628
|
function readText(file2) {
|
|
24448
24629
|
try {
|
|
24449
|
-
return hostText(
|
|
24630
|
+
return hostText(readFileSync9(file2, "utf8"));
|
|
24450
24631
|
} catch {
|
|
24451
24632
|
return "";
|
|
24452
24633
|
}
|
|
@@ -24511,7 +24692,7 @@ function mcpEntry(file2, doc, out) {
|
|
|
24511
24692
|
}
|
|
24512
24693
|
}
|
|
24513
24694
|
function claudeShapeSettings(agentHome, out) {
|
|
24514
|
-
const file2 =
|
|
24695
|
+
const file2 = join13(agentHome, SETTINGS_FILE);
|
|
24515
24696
|
const doc = readJson(file2);
|
|
24516
24697
|
for (const c of nestedCommands(doc)) {
|
|
24517
24698
|
if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
|
|
@@ -24531,63 +24712,63 @@ function v1HookFile(file2, out) {
|
|
|
24531
24712
|
function scanClaudeCode(home, agentHome, out) {
|
|
24532
24713
|
claudeShapeSettings(agentHome, out);
|
|
24533
24714
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
24534
|
-
const file2 =
|
|
24715
|
+
const file2 = join13(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
24535
24716
|
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
24536
24717
|
}
|
|
24537
|
-
const userFile =
|
|
24718
|
+
const userFile = join13(home, CLAUDE_USER_CONFIG_FILE);
|
|
24538
24719
|
mcpEntry(userFile, readJson(userFile), out);
|
|
24539
|
-
dataDir(
|
|
24720
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24540
24721
|
}
|
|
24541
24722
|
function scanCodex(agentHome, out) {
|
|
24542
|
-
const hooksFile =
|
|
24723
|
+
const hooksFile = join13(agentHome, HOOKS_JSON_FILE);
|
|
24543
24724
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
24544
24725
|
if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
|
|
24545
24726
|
out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
|
|
24546
24727
|
}
|
|
24547
24728
|
}
|
|
24548
|
-
const tomlFile =
|
|
24729
|
+
const tomlFile = join13(agentHome, CONFIG_TOML_FILE);
|
|
24549
24730
|
const config4 = readTomlValue(tomlFile);
|
|
24550
24731
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
24551
24732
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
24552
24733
|
if (isV2McpTable(hostConfigValueAt(config4, span2.path.slice(0, 2)))) continue;
|
|
24553
24734
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
24554
24735
|
}
|
|
24555
|
-
dataDir(
|
|
24736
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24556
24737
|
}
|
|
24557
24738
|
function scanGemini(agentHome, out) {
|
|
24558
|
-
const file2 =
|
|
24739
|
+
const file2 = join13(agentHome, SETTINGS_FILE);
|
|
24559
24740
|
for (const c of nestedCommands(readJson(file2))) {
|
|
24560
24741
|
if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
|
|
24561
24742
|
}
|
|
24562
|
-
dataDir(
|
|
24743
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
|
|
24563
24744
|
}
|
|
24564
24745
|
function scanVscode(agentHome, project, out) {
|
|
24565
24746
|
if (project !== void 0) {
|
|
24566
|
-
v1HookFile(
|
|
24567
|
-
const mcpFile2 =
|
|
24747
|
+
v1HookFile(join13(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
24748
|
+
const mcpFile2 = join13(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
24568
24749
|
const doc = readJson(mcpFile2);
|
|
24569
24750
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
24570
24751
|
const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
24571
24752
|
if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
|
|
24572
24753
|
out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
24573
24754
|
}
|
|
24574
|
-
const sessions =
|
|
24755
|
+
const sessions = join13(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
24575
24756
|
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out);
|
|
24576
24757
|
}
|
|
24577
|
-
dataDir(
|
|
24758
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
24578
24759
|
}
|
|
24579
24760
|
function jsonFiles(dir) {
|
|
24580
24761
|
try {
|
|
24581
|
-
return
|
|
24762
|
+
return readdirSync5(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
24582
24763
|
} catch {
|
|
24583
24764
|
return [];
|
|
24584
24765
|
}
|
|
24585
24766
|
}
|
|
24586
24767
|
function scanKiro(agentHome, project, out) {
|
|
24587
|
-
const agentsDir =
|
|
24588
|
-
const defaultFile =
|
|
24768
|
+
const agentsDir = join13(agentHome, KIRO_AGENTS_DIR);
|
|
24769
|
+
const defaultFile = join13(agentHome, ...KIRO_AGENT_FILE);
|
|
24589
24770
|
for (const name of jsonFiles(agentsDir)) {
|
|
24590
|
-
const file2 =
|
|
24771
|
+
const file2 = join13(agentsDir, name);
|
|
24591
24772
|
const doc = readJson(file2);
|
|
24592
24773
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
24593
24774
|
out.push(finding(file2, "", V1_REASON.kiroAgentFile));
|
|
@@ -24598,31 +24779,31 @@ function scanKiro(agentHome, project, out) {
|
|
|
24598
24779
|
if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
|
|
24599
24780
|
}
|
|
24600
24781
|
}
|
|
24601
|
-
const steeringDocs = [
|
|
24602
|
-
if (project !== void 0) steeringDocs.push(
|
|
24782
|
+
const steeringDocs = [join13(agentHome, ...KIRO_STEERING_FILE)];
|
|
24783
|
+
if (project !== void 0) steeringDocs.push(join13(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
24603
24784
|
for (const file2 of steeringDocs) {
|
|
24604
24785
|
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
24605
24786
|
}
|
|
24606
|
-
dataDir(
|
|
24787
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24607
24788
|
}
|
|
24608
24789
|
function piNpmIsCurrent(piAgentDir) {
|
|
24609
|
-
const doc = readJson(
|
|
24790
|
+
const doc = readJson(join13(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
24610
24791
|
const version4 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
24611
24792
|
return Number.parseInt(version4, 10) >= PI_CURRENT_MAJOR;
|
|
24612
24793
|
}
|
|
24613
24794
|
function scanPi(piAgentDir, agentHome, out) {
|
|
24614
|
-
const file2 =
|
|
24795
|
+
const file2 = join13(piAgentDir, SETTINGS_FILE);
|
|
24615
24796
|
const doc = readJson(file2);
|
|
24616
24797
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
24617
24798
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
24618
24799
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
24619
24800
|
if (spec === PI_GIT_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piGit));
|
|
24620
24801
|
});
|
|
24621
|
-
dataDir(
|
|
24802
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24622
24803
|
}
|
|
24623
24804
|
function scanOpencode(agentHome, out) {
|
|
24624
24805
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
24625
|
-
const file2 =
|
|
24806
|
+
const file2 = join13(agentHome, name);
|
|
24626
24807
|
const doc = readJson(file2);
|
|
24627
24808
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
24628
24809
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
|
|
@@ -24633,13 +24814,13 @@ function scanOpencode(agentHome, out) {
|
|
|
24633
24814
|
}
|
|
24634
24815
|
}
|
|
24635
24816
|
function scanZcode(agentHome, out) {
|
|
24636
|
-
const configFile =
|
|
24817
|
+
const configFile = join13(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
24637
24818
|
const config4 = readJson(configFile);
|
|
24638
24819
|
const events = isObj(config4) && isObj(config4[HOOKS_KEY]) ? config4[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
24639
24820
|
for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
24640
24821
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
|
|
24641
24822
|
}
|
|
24642
|
-
const hooksFile =
|
|
24823
|
+
const hooksFile = join13(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
24643
24824
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
24644
24825
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
|
|
24645
24826
|
}
|
|
@@ -24663,14 +24844,14 @@ function firstTmpMatch(dir) {
|
|
|
24663
24844
|
}
|
|
24664
24845
|
}
|
|
24665
24846
|
function scanAll(home, tmp, out) {
|
|
24666
|
-
const root =
|
|
24667
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
24847
|
+
const root = join13(home, DATA_ROOT.slice(1));
|
|
24848
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join13(root, name), V1_REASON.dataRoot, out);
|
|
24668
24849
|
if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
24669
24850
|
}
|
|
24670
24851
|
function detectV1(agent, home, scope = {}) {
|
|
24671
24852
|
const out = [];
|
|
24672
24853
|
const project = scope.project;
|
|
24673
|
-
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 :
|
|
24854
|
+
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]);
|
|
24674
24855
|
switch (agent) {
|
|
24675
24856
|
case "claude-code":
|
|
24676
24857
|
scanClaudeCode(home, agentHome, out);
|
|
@@ -24683,11 +24864,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24683
24864
|
break;
|
|
24684
24865
|
case "qwen":
|
|
24685
24866
|
claudeShapeSettings(agentHome, out);
|
|
24686
|
-
dataDir(
|
|
24867
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24687
24868
|
break;
|
|
24688
24869
|
case "copilot-cli":
|
|
24689
|
-
v1HookFile(
|
|
24690
|
-
dataDir(
|
|
24870
|
+
v1HookFile(join13(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
24871
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24691
24872
|
break;
|
|
24692
24873
|
case "vscode":
|
|
24693
24874
|
scanVscode(agentHome, project, out);
|
|
@@ -24696,7 +24877,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24696
24877
|
scanKiro(agentHome, project, out);
|
|
24697
24878
|
break;
|
|
24698
24879
|
case "pi":
|
|
24699
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
24880
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join13(agentHome, PI_AGENT_DIR), agentHome, out);
|
|
24700
24881
|
break;
|
|
24701
24882
|
// D-WIN-PIDIR-1: empty is unset
|
|
24702
24883
|
case "opencode":
|
|
@@ -24711,8 +24892,8 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24711
24892
|
}
|
|
24712
24893
|
|
|
24713
24894
|
// src/core/ops/plugin-root.ts
|
|
24714
|
-
import { existsSync as existsSync7, readdirSync as
|
|
24715
|
-
import { dirname as dirname7, isAbsolute as
|
|
24895
|
+
import { existsSync as existsSync7, readdirSync as readdirSync6, readFileSync as readFileSync10, realpathSync as realpathSync4 } from "node:fs";
|
|
24896
|
+
import { dirname as dirname7, isAbsolute as isAbsolute4, join as join14, sep as sep4 } from "node:path";
|
|
24716
24897
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
24717
24898
|
function missing(agent, path8) {
|
|
24718
24899
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
@@ -24753,15 +24934,15 @@ var realOrNull = (path8) => {
|
|
|
24753
24934
|
};
|
|
24754
24935
|
var readOrNull = (file2) => {
|
|
24755
24936
|
try {
|
|
24756
|
-
return
|
|
24937
|
+
return readFileSync10(file2, "utf8");
|
|
24757
24938
|
} catch {
|
|
24758
24939
|
return null;
|
|
24759
24940
|
}
|
|
24760
24941
|
};
|
|
24761
24942
|
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
24762
24943
|
function enabledPlugins(claudeDir, project) {
|
|
24763
|
-
const files = [
|
|
24764
|
-
if (project !== void 0) files.push(
|
|
24944
|
+
const files = [join14(claudeDir, SETTINGS_FILE)];
|
|
24945
|
+
if (project !== void 0) files.push(join14(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join14(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
|
|
24765
24946
|
const out = {};
|
|
24766
24947
|
for (const file2 of files) {
|
|
24767
24948
|
const text = readOrNull(file2);
|
|
@@ -24777,7 +24958,7 @@ function marketplaceChoice(env, worktree) {
|
|
|
24777
24958
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
24778
24959
|
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
24779
24960
|
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
24780
|
-
const record6 = readOrNull(
|
|
24961
|
+
const record6 = readOrNull(join14(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
24781
24962
|
const recorded = record6 === null ? [] : recordedInstalls(record6);
|
|
24782
24963
|
if (recorded.length === 0) return { record: false };
|
|
24783
24964
|
const live = recorded.filter((r) => existsSync7(r.installPath));
|
|
@@ -24800,18 +24981,18 @@ function marketplaceChoice(env, worktree) {
|
|
|
24800
24981
|
}
|
|
24801
24982
|
function marketplaceRoot(adapter, env, worktree) {
|
|
24802
24983
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
24803
|
-
const plugins =
|
|
24804
|
-
const cache =
|
|
24984
|
+
const plugins = join14(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
24985
|
+
const cache = join14(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
24805
24986
|
const script = process.argv[1];
|
|
24806
24987
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
24807
24988
|
const choice = marketplaceChoice(env, worktree);
|
|
24808
24989
|
if ("root" in choice) return choice.root;
|
|
24809
24990
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
24810
24991
|
const cacheReal = realOrNull(cache);
|
|
24811
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync7(
|
|
24812
|
-
const pattern =
|
|
24992
|
+
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync7(join14(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
24993
|
+
const pattern = join14(cache, "*", PLUGIN_NAME);
|
|
24813
24994
|
if (!existsSync7(cache)) throw missing(adapter.id, pattern);
|
|
24814
|
-
const found =
|
|
24995
|
+
const found = readdirSync6(cache).sort().map((marketplace) => join14(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync7(dir));
|
|
24815
24996
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
24816
24997
|
return found[0];
|
|
24817
24998
|
}
|
|
@@ -24824,12 +25005,12 @@ function configEntryRoot(adapter, env) {
|
|
|
24824
25005
|
const value = parseHostConfig(adapter.id, file2, current.text, current.format);
|
|
24825
25006
|
const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
|
|
24826
25007
|
const script = Array.isArray(args) ? args[0] : void 0;
|
|
24827
|
-
if (typeof script !== "string" || !
|
|
25008
|
+
if (typeof script !== "string" || !isAbsolute4(script)) throw missing(adapter.id, file2);
|
|
24828
25009
|
return dirname7(script);
|
|
24829
25010
|
}
|
|
24830
25011
|
function packageDirOf(dir) {
|
|
24831
25012
|
for (let cur = dir; ; ) {
|
|
24832
|
-
if (existsSync7(
|
|
25013
|
+
if (existsSync7(join14(cur, D1_PACKAGE_FILE))) return cur;
|
|
24833
25014
|
const up = dirname7(cur);
|
|
24834
25015
|
if (up === cur) return dir;
|
|
24835
25016
|
cur = up;
|
|
@@ -24844,9 +25025,9 @@ function candidate(adapter, env, worktree) {
|
|
|
24844
25025
|
case "hooks+mcp":
|
|
24845
25026
|
return configEntryRoot(adapter, env);
|
|
24846
25027
|
case "extension":
|
|
24847
|
-
return
|
|
25028
|
+
return join14(adapter.id === "gemini" ? geminiDirOf(env, requireHomeDir(env)) : join14(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id]), EXTENSIONS_DIR_NAME, PLUGIN_NAME);
|
|
24848
25029
|
case "plugin":
|
|
24849
|
-
return
|
|
25030
|
+
return join14(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
24850
25031
|
case "in-process":
|
|
24851
25032
|
return packageDirOf(dirname7(fileURLToPath2(import.meta.url)));
|
|
24852
25033
|
}
|
|
@@ -24861,7 +25042,7 @@ function resolvePluginRoot(adapter, env, worktree) {
|
|
|
24861
25042
|
}
|
|
24862
25043
|
|
|
24863
25044
|
// src/setup/pi-gate.ts
|
|
24864
|
-
import { existsSync as existsSync8, readFileSync as
|
|
25045
|
+
import { existsSync as existsSync8, readFileSync as readFileSync11, realpathSync as realpathSync5 } from "node:fs";
|
|
24865
25046
|
import path4 from "node:path";
|
|
24866
25047
|
var EXTENSIONS_KEY = "extensions";
|
|
24867
25048
|
var PROJECT_DIR = ".pi";
|
|
@@ -24871,7 +25052,7 @@ var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
|
24871
25052
|
function load(file2) {
|
|
24872
25053
|
if (!existsSync8(file2)) return void 0;
|
|
24873
25054
|
try {
|
|
24874
|
-
return { file: file2, doc: parseHostConfig("pi", file2, hostText(
|
|
25055
|
+
return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync11(file2, "utf8")), "json") };
|
|
24875
25056
|
} catch {
|
|
24876
25057
|
return void 0;
|
|
24877
25058
|
}
|
|
@@ -24930,8 +25111,8 @@ function piInstalledIn(env, home, pkgDir, cwd) {
|
|
|
24930
25111
|
}
|
|
24931
25112
|
|
|
24932
25113
|
// src/core/ops/doctor-env.ts
|
|
24933
|
-
import { existsSync as existsSync9, readFileSync as
|
|
24934
|
-
import { isAbsolute as
|
|
25114
|
+
import { existsSync as existsSync9, readFileSync as readFileSync12, realpathSync as realpathSync6 } from "node:fs";
|
|
25115
|
+
import { isAbsolute as isAbsolute5, join as join15, relative as relative4 } from "node:path";
|
|
24935
25116
|
function pass(id, detail = DOCTOR_PASS_DETAIL) {
|
|
24936
25117
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
24937
25118
|
}
|
|
@@ -24946,7 +25127,7 @@ function warn(id, detail, fixCommand) {
|
|
|
24946
25127
|
}
|
|
24947
25128
|
function bundleVersion(bundleDir2) {
|
|
24948
25129
|
try {
|
|
24949
|
-
const v = JSON.parse(
|
|
25130
|
+
const v = JSON.parse(readFileSync12(join15(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24950
25131
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24951
25132
|
} catch {
|
|
24952
25133
|
return void 0;
|
|
@@ -25100,7 +25281,7 @@ function checkMcp(ctx, adapter) {
|
|
|
25100
25281
|
function piCwdInside(worktree, piCwd) {
|
|
25101
25282
|
if (piCwd === void 0 || !existsSync9(piCwd)) return false;
|
|
25102
25283
|
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
25103
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
25284
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute5(rel);
|
|
25104
25285
|
}
|
|
25105
25286
|
function checkProject(i) {
|
|
25106
25287
|
const bad = fail2("D7", D7_DETAIL(i.project.source), D7_FIX);
|
|
@@ -25108,6 +25289,20 @@ function checkProject(i) {
|
|
|
25108
25289
|
if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
|
|
25109
25290
|
return pass("D7");
|
|
25110
25291
|
}
|
|
25292
|
+
function projectOrMissing(ctx) {
|
|
25293
|
+
try {
|
|
25294
|
+
return { project: ctx.project };
|
|
25295
|
+
} catch (err) {
|
|
25296
|
+
if (err instanceof CtxError && err.code === "NO_PROJECT") return { missing: String(err.vars.kind) };
|
|
25297
|
+
throw err;
|
|
25298
|
+
}
|
|
25299
|
+
}
|
|
25300
|
+
function noProjectRow(kind) {
|
|
25301
|
+
return fail2("D7", D7_NO_PROJECT_DETAIL(kind), D7_FIX);
|
|
25302
|
+
}
|
|
25303
|
+
function needsProjectRow(id) {
|
|
25304
|
+
return unknown2(id, DOCTOR_NEEDS_PROJECT_DETAIL);
|
|
25305
|
+
}
|
|
25111
25306
|
function checkMode(adapter, hostPermission) {
|
|
25112
25307
|
if (hostPermission === "missing") return fail2("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
|
|
25113
25308
|
if (hostPermission === "wired") return pass("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
|
|
@@ -25130,8 +25325,8 @@ function checkRuntimes(env, shellRow) {
|
|
|
25130
25325
|
}
|
|
25131
25326
|
|
|
25132
25327
|
// src/core/ops/omp-import.ts
|
|
25133
|
-
import { join as
|
|
25134
|
-
var { existsSync: existsSync10, readFileSync:
|
|
25328
|
+
import { join as join16 } from "node:path";
|
|
25329
|
+
var { existsSync: existsSync10, readFileSync: readFileSync13 } = process.getBuiltinModule("node:fs");
|
|
25135
25330
|
var OMP_DISABLED_SERVERS_KEY = "disabledServers";
|
|
25136
25331
|
var OMP_MCP_FILE = "mcp.json";
|
|
25137
25332
|
var OMP_CONFIG_FILE = "config.yml";
|
|
@@ -25140,12 +25335,12 @@ var DISABLED_PROVIDERS = "disabledProviders";
|
|
|
25140
25335
|
var CLAUDE_PROVIDER = "claude";
|
|
25141
25336
|
var ALL_PROVIDERS = ["*", "all"];
|
|
25142
25337
|
function ompImportFiles(home) {
|
|
25143
|
-
const agentDir =
|
|
25144
|
-
return { config:
|
|
25338
|
+
const agentDir = join16(home, ...AGENT_HOME_DIR.omp, PI_AGENT_DIR);
|
|
25339
|
+
return { config: join16(agentDir, OMP_CONFIG_FILE), mcp: join16(agentDir, OMP_MCP_FILE), claude: join16(home, CLAUDE_USER_CONFIG_FILE) };
|
|
25145
25340
|
}
|
|
25146
25341
|
function readText2(file2) {
|
|
25147
25342
|
try {
|
|
25148
|
-
return existsSync10(file2) ? hostText(
|
|
25343
|
+
return existsSync10(file2) ? hostText(readFileSync13(file2, "utf8")) : void 0;
|
|
25149
25344
|
} catch {
|
|
25150
25345
|
return void 0;
|
|
25151
25346
|
}
|
|
@@ -25273,11 +25468,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
25273
25468
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
25274
25469
|
function mcpFile(row5, home, env) {
|
|
25275
25470
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
25276
|
-
if (row5.id === "codex") return
|
|
25471
|
+
if (row5.id === "codex") return join17(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
25277
25472
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
25278
|
-
if (row5.id === "opencode") return
|
|
25473
|
+
if (row5.id === "opencode") return join17(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
25279
25474
|
if (row5.id === "pi") {
|
|
25280
|
-
return
|
|
25475
|
+
return join17(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
25281
25476
|
}
|
|
25282
25477
|
return null;
|
|
25283
25478
|
}
|
|
@@ -25290,27 +25485,27 @@ function codexNativeDir(env, home) {
|
|
|
25290
25485
|
const codexDir = codexDirOf(env, home);
|
|
25291
25486
|
let enabled;
|
|
25292
25487
|
try {
|
|
25293
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
25488
|
+
enabled = hostConfigValueAt(readParsed("codex", join17(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
25294
25489
|
} catch {
|
|
25295
25490
|
return null;
|
|
25296
25491
|
}
|
|
25297
25492
|
if (enabled !== true) return null;
|
|
25298
|
-
const cache =
|
|
25493
|
+
const cache = join17(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
25299
25494
|
if (!existsSync11(cache)) return null;
|
|
25300
25495
|
const found = [];
|
|
25301
|
-
for (const market of
|
|
25302
|
-
const plugin =
|
|
25496
|
+
for (const market of readdirSync7(cache)) {
|
|
25497
|
+
const plugin = join17(cache, market, SERVER_KEY);
|
|
25303
25498
|
if (!existsSync11(plugin)) continue;
|
|
25304
|
-
for (const version4 of
|
|
25305
|
-
const dir =
|
|
25306
|
-
if (existsSync11(
|
|
25499
|
+
for (const version4 of readdirSync7(plugin).sort()) {
|
|
25500
|
+
const dir = join17(plugin, version4, CODEX_PLUGIN_SUBDIR);
|
|
25501
|
+
if (existsSync11(join17(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
25307
25502
|
}
|
|
25308
25503
|
}
|
|
25309
25504
|
return found.length === 0 ? null : found[found.length - 1];
|
|
25310
25505
|
}
|
|
25311
25506
|
function nativeMcpWrong(dir, row5) {
|
|
25312
25507
|
try {
|
|
25313
|
-
const entry = hostConfigValueAt(readParsed(row5.id,
|
|
25508
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join17(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
25314
25509
|
if (!isObject4(entry)) return true;
|
|
25315
25510
|
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
25316
25511
|
const script = args[0];
|
|
@@ -25381,17 +25576,17 @@ function opencodePluginDirs(configDir, worktree) {
|
|
|
25381
25576
|
return [configDir, opencodeProjectDir(worktree)];
|
|
25382
25577
|
}
|
|
25383
25578
|
function opencodeProjectDir(worktree) {
|
|
25384
|
-
return
|
|
25579
|
+
return join17(worktree, OPENCODE_PROJECT_DIR);
|
|
25385
25580
|
}
|
|
25386
25581
|
function packageResolves(fromDir) {
|
|
25387
25582
|
for (let d = fromDir; ; d = dirname8(d)) {
|
|
25388
|
-
if (existsSync11(
|
|
25583
|
+
if (existsSync11(join17(d, NODE_MODULES_DIR, SERVER_KEY, PACKAGE_JSON_FILE))) return true;
|
|
25389
25584
|
if (dirname8(d) === d) return false;
|
|
25390
25585
|
}
|
|
25391
25586
|
}
|
|
25392
25587
|
function opencodeDirPlugins(dirs) {
|
|
25393
25588
|
const bundle = opencodePluginFile();
|
|
25394
|
-
const ownFile =
|
|
25589
|
+
const ownFile = join17(bundle, ...OPENCODE_PLUGIN_PATH).split("\\").join("/");
|
|
25395
25590
|
const isModule = (p) => OWN_PLUGIN_MODULES.includes(p);
|
|
25396
25591
|
const isPath = (p) => {
|
|
25397
25592
|
if (p === ownFile || p === `${FILE_URL_PREFIX}${ownFile}`) return true;
|
|
@@ -25401,20 +25596,20 @@ function opencodeDirPlugins(dirs) {
|
|
|
25401
25596
|
};
|
|
25402
25597
|
const out = [];
|
|
25403
25598
|
for (const dir of dirs) {
|
|
25404
|
-
const pdir =
|
|
25599
|
+
const pdir = join17(dir, OPENCODE_PLUGINS_DIR);
|
|
25405
25600
|
let names;
|
|
25406
25601
|
try {
|
|
25407
|
-
names =
|
|
25602
|
+
names = readdirSync7(pdir);
|
|
25408
25603
|
} catch {
|
|
25409
25604
|
continue;
|
|
25410
25605
|
}
|
|
25411
25606
|
for (const name of names) {
|
|
25412
|
-
const loose = OPENCODE_PLUGIN_EXTS.some((x) => name.endsWith(x)) ? [
|
|
25413
|
-
const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x) =>
|
|
25607
|
+
const loose = OPENCODE_PLUGIN_EXTS.some((x) => name.endsWith(x)) ? [join17(pdir, name)] : [];
|
|
25608
|
+
const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x) => join17(pdir, name, `${OPENCODE_PLUGIN_INDEX}${x}`))];
|
|
25414
25609
|
for (const f of files) {
|
|
25415
25610
|
let text;
|
|
25416
25611
|
try {
|
|
25417
|
-
const b =
|
|
25612
|
+
const b = readFileSync14(f);
|
|
25418
25613
|
if (b.length > OPENCODE_DIR_FILE_MAX) continue;
|
|
25419
25614
|
text = b.toString("utf8");
|
|
25420
25615
|
} catch {
|
|
@@ -25425,7 +25620,7 @@ function opencodeDirPlugins(dirs) {
|
|
|
25425
25620
|
const loads = lits.some((p) => {
|
|
25426
25621
|
if (isModule(p)) return packageResolves(dirname8(f));
|
|
25427
25622
|
const bare2 = p.startsWith(FILE_URL_PREFIX) ? p.slice(FILE_URL_PREFIX.length) : p;
|
|
25428
|
-
return existsSync11(
|
|
25623
|
+
return existsSync11(isAbsolute6(bare2) ? bare2 : resolve9(dirname8(f), bare2));
|
|
25429
25624
|
});
|
|
25430
25625
|
out.push({ file: f, loads });
|
|
25431
25626
|
}
|
|
@@ -25444,18 +25639,18 @@ function opencodeMcpOwn(entry) {
|
|
|
25444
25639
|
}
|
|
25445
25640
|
function opencodeFileValue(file2) {
|
|
25446
25641
|
if (!existsSync11(file2)) return {};
|
|
25447
|
-
return parseHostConfig("opencode", file2, hostText(
|
|
25642
|
+
return parseHostConfig("opencode", file2, hostText(readFileSync14(file2, "utf8")), "jsonc");
|
|
25448
25643
|
}
|
|
25449
25644
|
function opencodeValueListed(value) {
|
|
25450
25645
|
const bundle = opencodePluginFile();
|
|
25451
|
-
const own4 = [bundle,
|
|
25646
|
+
const own4 = [bundle, join17(bundle, ...OPENCODE_PLUGIN_PATH)];
|
|
25452
25647
|
if ([OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list2(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own4)))) return true;
|
|
25453
25648
|
const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
|
|
25454
25649
|
return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
|
|
25455
25650
|
}
|
|
25456
25651
|
function opencodeListed(file2, worktree) {
|
|
25457
25652
|
const dirs = [dirname8(file2), worktree];
|
|
25458
|
-
if (dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(
|
|
25653
|
+
if (dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(join17(dir, name)))))) return true;
|
|
25459
25654
|
return opencodeDirPlugin(opencodePluginDirs(dirname8(file2), worktree)) !== void 0;
|
|
25460
25655
|
}
|
|
25461
25656
|
function mcpWrong(row5, home, env, worktree) {
|
|
@@ -25477,7 +25672,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
25477
25672
|
function hookFile(row5, spec, home, env, worktree) {
|
|
25478
25673
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
25479
25674
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
25480
|
-
const file2 = native !== null ?
|
|
25675
|
+
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);
|
|
25481
25676
|
return file2;
|
|
25482
25677
|
}
|
|
25483
25678
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -25488,7 +25683,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
25488
25683
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
25489
25684
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
25490
25685
|
if (row5.id === "codex") {
|
|
25491
|
-
const config4 = readParsed(row5.id,
|
|
25686
|
+
const config4 = readParsed(row5.id, join17(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
25492
25687
|
if (hostConfigValueAt(config4, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
25493
25688
|
}
|
|
25494
25689
|
} catch {
|
|
@@ -25533,13 +25728,13 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
25533
25728
|
function checkPiInstall(env, home, worktree) {
|
|
25534
25729
|
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
25535
25730
|
if (found !== void 0) return { ...pass2("D3"), detail: found };
|
|
25536
|
-
return fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN +
|
|
25731
|
+
return fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join17(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
|
|
25537
25732
|
}
|
|
25538
25733
|
var OMP_PLUGINS_DIR = "plugins";
|
|
25539
25734
|
var OMP_LOCK_FILE = "omp-plugins.lock.json";
|
|
25540
25735
|
function readJson2(file2) {
|
|
25541
25736
|
try {
|
|
25542
|
-
const doc = JSON.parse(
|
|
25737
|
+
const doc = JSON.parse(readFileSync14(file2, "utf8"));
|
|
25543
25738
|
return typeof doc === "object" && doc !== null ? doc : void 0;
|
|
25544
25739
|
} catch {
|
|
25545
25740
|
return void 0;
|
|
@@ -25550,9 +25745,9 @@ function ownEntry(doc, key) {
|
|
|
25550
25745
|
return typeof map2 === "object" && map2 !== null ? map2[SERVER_KEY] : void 0;
|
|
25551
25746
|
}
|
|
25552
25747
|
function checkOmpInstall(home) {
|
|
25553
|
-
const dir =
|
|
25554
|
-
const lock =
|
|
25555
|
-
const pkg =
|
|
25748
|
+
const dir = join17(home, ...AGENT_HOME_DIR.omp, OMP_PLUGINS_DIR);
|
|
25749
|
+
const lock = join17(dir, OMP_LOCK_FILE);
|
|
25750
|
+
const pkg = join17(dir, PI_PACKAGE_JSON_FILE);
|
|
25556
25751
|
const entry = ownEntry(readJson2(lock), "plugins");
|
|
25557
25752
|
const missing2 = (file2) => fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + file2, NATIVE_INSTALL.omp[0]);
|
|
25558
25753
|
if (typeof entry !== "object" || entry === null) return missing2(lock);
|
|
@@ -25589,10 +25784,10 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
25589
25784
|
}
|
|
25590
25785
|
function checkDoubleFire(agent, worktree) {
|
|
25591
25786
|
if (agent !== "claude-code" && agent !== "vscode") return pass2("D5b");
|
|
25592
|
-
const claude = parsedOrNull(agent,
|
|
25787
|
+
const claude = parsedOrNull(agent, join17(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
25593
25788
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
25594
25789
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
25595
|
-
const vscode = parsedOrNull(agent,
|
|
25790
|
+
const vscode = parsedOrNull(agent, join17(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
25596
25791
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
25597
25792
|
return hooksOn && useClaudeHooks ? fail3("D5b", D5B_DETAIL, D5B_FIX) : pass2("D5b");
|
|
25598
25793
|
}
|
|
@@ -25603,7 +25798,7 @@ function configPaths(row5, env, worktree) {
|
|
|
25603
25798
|
const mcp = mcpFile(row5, home, env);
|
|
25604
25799
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
25605
25800
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
25606
|
-
if (native !== null) out.push({ label: "Codex plugin MCP", path:
|
|
25801
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join17(native, CODEX_PLUGIN_MCP_FILE) });
|
|
25607
25802
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
25608
25803
|
if (spec !== null) {
|
|
25609
25804
|
try {
|
|
@@ -25623,7 +25818,7 @@ function configPaths(row5, env, worktree) {
|
|
|
25623
25818
|
}
|
|
25624
25819
|
|
|
25625
25820
|
// src/core/ops/doctor-db.ts
|
|
25626
|
-
import { existsSync as existsSync12, statSync as
|
|
25821
|
+
import { existsSync as existsSync12, statSync as statSync7 } from "node:fs";
|
|
25627
25822
|
var unknown3 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
|
|
25628
25823
|
var pass3 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
|
|
25629
25824
|
var fail4 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -25634,7 +25829,7 @@ function isCorrupt2(err) {
|
|
|
25634
25829
|
const primary = code & SQLITE_PRIMARY_CODE_MASK;
|
|
25635
25830
|
return primary === SQLITE_CORRUPT_CODE || primary === SQLITE_NOTADB_CODE;
|
|
25636
25831
|
}
|
|
25637
|
-
var
|
|
25832
|
+
var message3 = (err) => err instanceof Error ? err.message : String(err);
|
|
25638
25833
|
async function loadSqlite2() {
|
|
25639
25834
|
try {
|
|
25640
25835
|
return await import(SQLITE_MODULE);
|
|
@@ -25665,7 +25860,7 @@ function orphanFiles(dbPath) {
|
|
|
25665
25860
|
const files = [];
|
|
25666
25861
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
25667
25862
|
const path8 = dbPath + suffix;
|
|
25668
|
-
if (existsSync12(path8)) files.push({ path: path8, bytes:
|
|
25863
|
+
if (existsSync12(path8)) files.push({ path: path8, bytes: statSync7(path8).size });
|
|
25669
25864
|
}
|
|
25670
25865
|
return files.length > 0 && !existsSync12(dbPath) ? files : [];
|
|
25671
25866
|
}
|
|
@@ -25693,7 +25888,7 @@ async function checkDb(project) {
|
|
|
25693
25888
|
return { row: pass3("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
25694
25889
|
} catch (err) {
|
|
25695
25890
|
if (isCorrupt2(err)) return { row: fail4(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale: false, integrityFailed: true, orphan: [] };
|
|
25696
|
-
return { row: unknown3("D8",
|
|
25891
|
+
return { row: unknown3("D8", message3(err)), ...clean };
|
|
25697
25892
|
} finally {
|
|
25698
25893
|
raw?.close();
|
|
25699
25894
|
}
|
|
@@ -25709,14 +25904,14 @@ async function checkIndex(project) {
|
|
|
25709
25904
|
const chunks = Number(cell(raw.prepare("SELECT count(*) FROM chunks").get()));
|
|
25710
25905
|
return pass3("D9", D9_INDEX_DETAIL(sources, chunks));
|
|
25711
25906
|
} catch (err) {
|
|
25712
|
-
return unknown3("D9",
|
|
25907
|
+
return unknown3("D9", message3(err));
|
|
25713
25908
|
} finally {
|
|
25714
25909
|
raw?.close();
|
|
25715
25910
|
}
|
|
25716
25911
|
}
|
|
25717
25912
|
|
|
25718
25913
|
// src/core/ops/doctor-hook.ts
|
|
25719
|
-
import { existsSync as existsSync14, mkdirSync as
|
|
25914
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync5, mkdtempSync, readFileSync as readFileSync15, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
25720
25915
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
25721
25916
|
import path7 from "node:path";
|
|
25722
25917
|
|
|
@@ -27550,7 +27745,7 @@ import { spawn as spawn3, spawnSync as spawnSync2 } from "node:child_process";
|
|
|
27550
27745
|
|
|
27551
27746
|
// src/setup/spawn-bin.ts
|
|
27552
27747
|
import { spawnSync } from "node:child_process";
|
|
27553
|
-
import { accessSync as accessSync2, constants as fsc, statSync as
|
|
27748
|
+
import { accessSync as accessSync2, constants as fsc, statSync as statSync8 } from "node:fs";
|
|
27554
27749
|
import path5 from "node:path";
|
|
27555
27750
|
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
27556
27751
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
@@ -27568,7 +27763,7 @@ function whichBin(bin, env, platform = process.platform) {
|
|
|
27568
27763
|
const f = path5.join(dir, n);
|
|
27569
27764
|
try {
|
|
27570
27765
|
accessSync2(f, fsc.X_OK);
|
|
27571
|
-
if (
|
|
27766
|
+
if (statSync8(f).isFile()) return f;
|
|
27572
27767
|
} catch {
|
|
27573
27768
|
}
|
|
27574
27769
|
}
|
|
@@ -27770,7 +27965,7 @@ function loadFixture(bundleDir2, agent) {
|
|
|
27770
27965
|
if (!existsSync14(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
27771
27966
|
let all;
|
|
27772
27967
|
try {
|
|
27773
|
-
all = JSON.parse(hostText(
|
|
27968
|
+
all = JSON.parse(hostText(readFileSync15(file2, "utf8")));
|
|
27774
27969
|
} catch (err) {
|
|
27775
27970
|
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
27776
27971
|
}
|
|
@@ -27862,7 +28057,7 @@ async function mediaProbe(i, timeoutMs) {
|
|
|
27862
28057
|
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-media-"));
|
|
27863
28058
|
try {
|
|
27864
28059
|
const filePath = path7.join(home, "d5-media-probe.png");
|
|
27865
|
-
|
|
28060
|
+
writeFileSync3(filePath, Buffer.concat([PNG_SIGNATURE, Buffer.alloc(OUTPUT_CAP + 1)]));
|
|
27866
28061
|
const node3 = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home });
|
|
27867
28062
|
const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
27868
28063
|
cwd: i.bundleDir,
|
|
@@ -27889,9 +28084,9 @@ async function ownProbe(i, timeoutMs) {
|
|
|
27889
28084
|
try {
|
|
27890
28085
|
const cfg = path7.join(home, ".claude");
|
|
27891
28086
|
const refs = path7.join(cfg, "skills", "d5-probe", "references");
|
|
27892
|
-
|
|
28087
|
+
mkdirSync5(refs, { recursive: true });
|
|
27893
28088
|
const filePath = path7.join(refs, "d5-own-probe.md");
|
|
27894
|
-
|
|
28089
|
+
writeFileSync3(filePath, "# d5 own probe\n".repeat(Math.ceil((OUTPUT_CAP + 1) / 15)));
|
|
27895
28090
|
const node3 = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, CLAUDE_CONFIG_DIR: cfg });
|
|
27896
28091
|
const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
27897
28092
|
cwd: i.bundleDir,
|
|
@@ -28045,24 +28240,24 @@ async function checkHookRoundTrip(i) {
|
|
|
28045
28240
|
}
|
|
28046
28241
|
|
|
28047
28242
|
// src/core/ops/db-heal.ts
|
|
28048
|
-
import { existsSync as existsSync15, mkdirSync as
|
|
28049
|
-
import { basename as basename4, dirname as dirname9, join as
|
|
28243
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync7, rmSync as rmSync4 } from "node:fs";
|
|
28244
|
+
import { basename as basename4, dirname as dirname9, join as join19 } from "node:path";
|
|
28050
28245
|
|
|
28051
28246
|
// src/core/store/owners.ts
|
|
28052
|
-
import { mkdirSync as
|
|
28053
|
-
import { basename as basename3, join as
|
|
28247
|
+
import { mkdirSync as mkdirSync6, readdirSync as readdirSync8, readFileSync as readFileSync16, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
28248
|
+
import { basename as basename3, join as join18 } from "node:path";
|
|
28054
28249
|
function ownersDir(configDir, projectKey) {
|
|
28055
|
-
return
|
|
28250
|
+
return join18(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
28056
28251
|
}
|
|
28057
28252
|
function ownerFile(configDir, projectKey, serverId) {
|
|
28058
|
-
return
|
|
28253
|
+
return join18(ownersDir(configDir, projectKey), serverId + OWNER_PID_EXT);
|
|
28059
28254
|
}
|
|
28060
28255
|
function errCode3(err) {
|
|
28061
28256
|
return err.code;
|
|
28062
28257
|
}
|
|
28063
28258
|
function writeOwnerPid(configDir, projectKey, serverId) {
|
|
28064
|
-
|
|
28065
|
-
|
|
28259
|
+
mkdirSync6(ownersDir(configDir, projectKey), { recursive: true });
|
|
28260
|
+
writeFileSync4(ownerFile(configDir, projectKey, serverId), String(process.pid), "utf8");
|
|
28066
28261
|
}
|
|
28067
28262
|
function removeOwnerPid(configDir, projectKey, serverId) {
|
|
28068
28263
|
rmSync3(ownerFile(configDir, projectKey, serverId), { force: true });
|
|
@@ -28082,7 +28277,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
28082
28277
|
const dir = ownersDir(configDir, projectKey);
|
|
28083
28278
|
let names;
|
|
28084
28279
|
try {
|
|
28085
|
-
names =
|
|
28280
|
+
names = readdirSync8(dir);
|
|
28086
28281
|
} catch (err) {
|
|
28087
28282
|
if (errCode3(err) === "ENOENT") return [];
|
|
28088
28283
|
throw err;
|
|
@@ -28090,10 +28285,10 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
28090
28285
|
const live = [];
|
|
28091
28286
|
for (const name of names) {
|
|
28092
28287
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
28093
|
-
const file2 =
|
|
28288
|
+
const file2 = join18(dir, name);
|
|
28094
28289
|
let text;
|
|
28095
28290
|
try {
|
|
28096
|
-
text =
|
|
28291
|
+
text = readFileSync16(file2, "utf8");
|
|
28097
28292
|
} catch (err) {
|
|
28098
28293
|
if (errCode3(err) === "ENOENT") continue;
|
|
28099
28294
|
throw err;
|
|
@@ -28162,11 +28357,11 @@ function utcStamp(now) {
|
|
|
28162
28357
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
28163
28358
|
}
|
|
28164
28359
|
function makeOrphanDir(projectDir) {
|
|
28165
|
-
const base =
|
|
28360
|
+
const base = join19(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
28166
28361
|
for (let n = 1; ; n += 1) {
|
|
28167
28362
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
28168
28363
|
try {
|
|
28169
|
-
|
|
28364
|
+
mkdirSync7(dir);
|
|
28170
28365
|
return dir;
|
|
28171
28366
|
} catch (err) {
|
|
28172
28367
|
if (err.code !== "EEXIST") throw err;
|
|
@@ -28179,7 +28374,7 @@ async function healOrphan(project, files, row5) {
|
|
|
28179
28374
|
try {
|
|
28180
28375
|
dir = makeOrphanDir(dirname9(project.dbPath));
|
|
28181
28376
|
for (const f of files) {
|
|
28182
|
-
const to =
|
|
28377
|
+
const to = join19(dir, basename4(f.path));
|
|
28183
28378
|
renameWithRetry(f.path, to);
|
|
28184
28379
|
moved.push({ path: to, bytes: f.bytes });
|
|
28185
28380
|
}
|
|
@@ -28277,8 +28472,8 @@ function unsupportedHostOf(sig) {
|
|
|
28277
28472
|
|
|
28278
28473
|
// src/core/ops/doctor-issue.ts
|
|
28279
28474
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
28280
|
-
import { closeSync as closeSync2, existsSync as existsSync16, fstatSync, mkdirSync as
|
|
28281
|
-
import { delimiter, dirname as dirname10, join as
|
|
28475
|
+
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";
|
|
28476
|
+
import { delimiter, dirname as dirname10, join as join20 } from "node:path";
|
|
28282
28477
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
28283
28478
|
function tildeOf(env) {
|
|
28284
28479
|
const home = homeDirOf(env);
|
|
@@ -28334,8 +28529,8 @@ function onPath(env, tool) {
|
|
|
28334
28529
|
const out = [];
|
|
28335
28530
|
for (const dir of (envValue(env, "PATH") ?? "").split(delimiter)) {
|
|
28336
28531
|
if (dir === "") continue;
|
|
28337
|
-
for (const n of names) if (existsSync16(
|
|
28338
|
-
out.push(
|
|
28532
|
+
for (const n of names) if (existsSync16(join20(dir, n))) {
|
|
28533
|
+
out.push(join20(dir, n));
|
|
28339
28534
|
break;
|
|
28340
28535
|
}
|
|
28341
28536
|
}
|
|
@@ -28363,9 +28558,11 @@ function hookLogTail(env) {
|
|
|
28363
28558
|
}
|
|
28364
28559
|
async function journalRows(ctx) {
|
|
28365
28560
|
const head2 = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
28366
|
-
|
|
28561
|
+
const p = projectOrMissing(ctx);
|
|
28562
|
+
if ("missing" in p) return [`(no project: ${D7_NO_PROJECT_DETAIL(p.missing)})`];
|
|
28563
|
+
if (!existsSync16(p.project.dbPath)) return [`(context.db is absent at ${p.project.dbPath})`];
|
|
28367
28564
|
try {
|
|
28368
|
-
const db = await openDb(
|
|
28565
|
+
const db = await openDb(p.project, { readOnly: true });
|
|
28369
28566
|
try {
|
|
28370
28567
|
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();
|
|
28371
28568
|
const cell5 = (v) => v === null || v === void 0 ? "" : String(v);
|
|
@@ -28381,8 +28578,8 @@ function agentConfig(adapter, env, worktree) {
|
|
|
28381
28578
|
const home = homeDirOf(env);
|
|
28382
28579
|
const files = configPaths(adapter, env, worktree);
|
|
28383
28580
|
if (home !== null) {
|
|
28384
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
28385
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
28581
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join20(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
28582
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join20(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
28386
28583
|
}
|
|
28387
28584
|
const out = [];
|
|
28388
28585
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -28395,7 +28592,7 @@ function agentConfig(adapter, env, worktree) {
|
|
|
28395
28592
|
}
|
|
28396
28593
|
let text = "";
|
|
28397
28594
|
try {
|
|
28398
|
-
text =
|
|
28595
|
+
text = readFileSync17(f.path, "utf8");
|
|
28399
28596
|
} catch (err) {
|
|
28400
28597
|
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
28401
28598
|
continue;
|
|
@@ -28424,6 +28621,7 @@ async function buildIssueBody(i) {
|
|
|
28424
28621
|
const failRows = i.rows.filter((r) => r.status !== "PASS");
|
|
28425
28622
|
const envNames = DOCTOR_ENV_NAMES.map((n) => i.env[n] === void 0 ? `${n} (unset)` : `${n}=${i.env[n]}`);
|
|
28426
28623
|
const pathTools = DOCTOR_PATH_TOOLS.map((t) => `PATH holds ${t}: ${onPath(i.env, t).join(", ") || "(absent)"}`);
|
|
28624
|
+
const p = projectOrMissing(i.ctx);
|
|
28427
28625
|
const sections = {
|
|
28428
28626
|
"Summary": [summaryOf(agent, i.rows, i.unsupported)],
|
|
28429
28627
|
"ctx-report": [i.table],
|
|
@@ -28434,7 +28632,7 @@ async function buildIssueBody(i) {
|
|
|
28434
28632
|
],
|
|
28435
28633
|
"Hook errors": ["hook-errors.log, last " + DOCTOR_HOOK_LOG_LINES + " lines (UTC):", "```", ...hookLogTail(i.env), "```"],
|
|
28436
28634
|
"Journal rows": ["events, newest first, last " + DOCTOR_JOURNAL_ROWS + " (bodies stay local):", ...await journalRows(i.ctx)],
|
|
28437
|
-
"Agent config": agentConfig(i.adapter, i.env,
|
|
28635
|
+
"Agent config": agentConfig(i.adapter, i.env, "project" in p ? p.project.worktree : process.cwd()),
|
|
28438
28636
|
"Expected": ["Expected: <the agent fills this in: what should happen, with the byte count>"],
|
|
28439
28637
|
"Steps": [
|
|
28440
28638
|
"Reproduced: <yes (2 of 2) or 1 of 2>",
|
|
@@ -28455,7 +28653,7 @@ async function buildIssueBody(i) {
|
|
|
28455
28653
|
`git: ${gitVersion(i.env)}`,
|
|
28456
28654
|
...pathTools,
|
|
28457
28655
|
...envNames,
|
|
28458
|
-
`Project: ${
|
|
28656
|
+
"project" in p ? `Project: ${p.project.worktree} (key ${p.project.projectKey})` : `Project: ${D7_NO_PROJECT_DETAIL(p.missing)}`,
|
|
28459
28657
|
"Filed by: <your agent name, version, model id>"
|
|
28460
28658
|
]
|
|
28461
28659
|
};
|
|
@@ -28466,10 +28664,10 @@ async function buildIssueBody(i) {
|
|
|
28466
28664
|
async function writeIssueReport(i) {
|
|
28467
28665
|
const tilde = tildeOf(i.env);
|
|
28468
28666
|
const body = await buildIssueBody(i);
|
|
28469
|
-
const dir =
|
|
28470
|
-
|
|
28471
|
-
const file2 =
|
|
28472
|
-
|
|
28667
|
+
const dir = join20(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
28668
|
+
mkdirSync8(dir, { recursive: true });
|
|
28669
|
+
const file2 = join20(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
28670
|
+
writeFileSync5(file2, body);
|
|
28473
28671
|
const shown2 = tilde(file2);
|
|
28474
28672
|
const title = issueTitle(i.adapter.id, i.rows, i.unsupported);
|
|
28475
28673
|
const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
|
|
@@ -28481,6 +28679,25 @@ function formUrl(title, summary) {
|
|
|
28481
28679
|
return full.length < ISSUE_URL_MAX ? full : base;
|
|
28482
28680
|
}
|
|
28483
28681
|
|
|
28682
|
+
// src/core/index/text.ts
|
|
28683
|
+
function storeText(db, project, sessionId, sourceKind, label2, text, kind, chunks = chunkText(text, kind)) {
|
|
28684
|
+
const sourceId = ftsInsert(db, {
|
|
28685
|
+
projectKey: project.projectKey,
|
|
28686
|
+
sessionId,
|
|
28687
|
+
worktree: project.worktree,
|
|
28688
|
+
agent: project.agent,
|
|
28689
|
+
kind: sourceKind,
|
|
28690
|
+
label: label2,
|
|
28691
|
+
bytes: Buffer.byteLength(text, "utf8"),
|
|
28692
|
+
chunkCount: chunks.length,
|
|
28693
|
+
createdAt: Date.now()
|
|
28694
|
+
}, chunks);
|
|
28695
|
+
return { sourceId, chunks: chunks.length };
|
|
28696
|
+
}
|
|
28697
|
+
function indexText(db, ctx, sessionId, source, text, kind, chunks) {
|
|
28698
|
+
return storeText(db, ctx, sessionId, "content", source, text, kind, chunks);
|
|
28699
|
+
}
|
|
28700
|
+
|
|
28484
28701
|
// src/core/tools/doctor.ts
|
|
28485
28702
|
var ctxDoctorSchema = external_exports.object({}).strict();
|
|
28486
28703
|
function lineOf2(err) {
|
|
@@ -28494,10 +28711,10 @@ async function guard(id, run) {
|
|
|
28494
28711
|
return { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail: lineOf2(err) };
|
|
28495
28712
|
}
|
|
28496
28713
|
}
|
|
28497
|
-
async function codexDb(
|
|
28498
|
-
if (adapter.id !== "codex" || !existsSync17(
|
|
28714
|
+
async function codexDb(project, adapter) {
|
|
28715
|
+
if (adapter.id !== "codex" || !existsSync17(project.dbPath)) return null;
|
|
28499
28716
|
try {
|
|
28500
|
-
return await openDb(
|
|
28717
|
+
return await openDb(project, { readOnly: true });
|
|
28501
28718
|
} catch {
|
|
28502
28719
|
return null;
|
|
28503
28720
|
}
|
|
@@ -28508,12 +28725,12 @@ function d1UpdateCommand(agent, env, other) {
|
|
|
28508
28725
|
function unsupportedRow(id, h) {
|
|
28509
28726
|
return { id, label: DOCTOR_LABEL[id], status: "WARN", detail: UNSUPPORTED_HOST_LINE(h.name) };
|
|
28510
28727
|
}
|
|
28511
|
-
async function hookRow(ctx, adapter, host) {
|
|
28512
|
-
const db = await codexDb(
|
|
28728
|
+
async function hookRow(ctx, project, adapter, host) {
|
|
28729
|
+
const db = await codexDb(project, adapter);
|
|
28513
28730
|
const runStart = Date.now();
|
|
28514
28731
|
try {
|
|
28515
28732
|
const row5 = await checkHookRoundTrip({
|
|
28516
|
-
worktree:
|
|
28733
|
+
worktree: project.worktree,
|
|
28517
28734
|
agent: adapter.id,
|
|
28518
28735
|
bundleDir: host.bundleDir,
|
|
28519
28736
|
env: buildChildEnv(host.env),
|
|
@@ -28531,18 +28748,20 @@ async function hookRow(ctx, adapter, host) {
|
|
|
28531
28748
|
}
|
|
28532
28749
|
}
|
|
28533
28750
|
function ownServerId(configDir, projectKey) {
|
|
28534
|
-
const dir =
|
|
28751
|
+
const dir = join21(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
28535
28752
|
if (!existsSync17(dir)) return "";
|
|
28536
|
-
for (const name of
|
|
28753
|
+
for (const name of readdirSync9(dir)) {
|
|
28537
28754
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
28538
|
-
if (
|
|
28755
|
+
if (readFileSync18(join21(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
28539
28756
|
}
|
|
28540
28757
|
return "";
|
|
28541
28758
|
}
|
|
28542
28759
|
async function runDoctorChecks(ctx, adapter, host0) {
|
|
28543
28760
|
const host = adapter.id === "codex" ? { ...host0, env: { ...host0.env, CODEX_HOME: codexRunDirOf(host0.env, homeDirOf(host0.env) ?? "", host0.bundleDir) } } : host0;
|
|
28544
28761
|
const env = host.env;
|
|
28545
|
-
const
|
|
28762
|
+
const p = projectOrMissing(ctx);
|
|
28763
|
+
if ("missing" in p) return noProjectRows(ctx, adapter, host, p.missing);
|
|
28764
|
+
const project = p.project;
|
|
28546
28765
|
const other = adapter.installMode === "in-process" ? void 0 : unsupportedHostOf({ clientName: ctx.clientInfo?.name, bundleDir: host.bundleDir, env });
|
|
28547
28766
|
let integrityFailed = false;
|
|
28548
28767
|
let orphan = [];
|
|
@@ -28552,7 +28771,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
28552
28771
|
D3: () => other !== void 0 ? unsupportedRow("D3", other) : checkHostConfig(adapter, env, project.worktree),
|
|
28553
28772
|
// D-UNSUPPORTED-HOSTS-1
|
|
28554
28773
|
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)) }),
|
|
28555
|
-
D5: () => other !== void 0 ? unsupportedRow("D5", other) : hookRow(ctx, adapter, host),
|
|
28774
|
+
D5: () => other !== void 0 ? unsupportedRow("D5", other) : hookRow(ctx, project, adapter, host),
|
|
28556
28775
|
D5b: () => checkDoubleFire(adapter.id, project.worktree),
|
|
28557
28776
|
D6: () => checkMcp(ctx, adapter),
|
|
28558
28777
|
D7: () => checkProject({ project, adapter, piCwd: host.piCwd }),
|
|
@@ -28582,6 +28801,28 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
28582
28801
|
});
|
|
28583
28802
|
return rows;
|
|
28584
28803
|
}
|
|
28804
|
+
async function noProjectRows(ctx, adapter, host, missing2) {
|
|
28805
|
+
const env = host.env;
|
|
28806
|
+
const other = adapter.installMode === "in-process" ? void 0 : unsupportedHostOf({ clientName: ctx.clientInfo?.name, bundleDir: host.bundleDir, env });
|
|
28807
|
+
const wait = (id) => () => needsProjectRow(id);
|
|
28808
|
+
const checks = {
|
|
28809
|
+
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) }),
|
|
28810
|
+
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
28811
|
+
D3: other !== void 0 ? () => unsupportedRow("D3", other) : wait("D3"),
|
|
28812
|
+
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)) }),
|
|
28813
|
+
D5: other !== void 0 ? () => unsupportedRow("D5", other) : wait("D5"),
|
|
28814
|
+
D5b: wait("D5b"),
|
|
28815
|
+
D6: () => checkMcp(ctx, adapter),
|
|
28816
|
+
D7: () => noProjectRow(missing2),
|
|
28817
|
+
D8: wait("D8"),
|
|
28818
|
+
D9: wait("D9"),
|
|
28819
|
+
D10: () => checkMode(adapter, ctx.hostPermission),
|
|
28820
|
+
D11: () => checkRuntimes(env, checkShell(env))
|
|
28821
|
+
};
|
|
28822
|
+
const rows = [];
|
|
28823
|
+
for (const id of DOCTOR_CHECK_ORDER) rows.push(await guard(id, checks[id]));
|
|
28824
|
+
return rows;
|
|
28825
|
+
}
|
|
28585
28826
|
function reportEnv(env) {
|
|
28586
28827
|
const out = {};
|
|
28587
28828
|
for (const key of Object.keys(REPORT_ENV_ENUMS)) {
|
|
@@ -28591,7 +28832,7 @@ function reportEnv(env) {
|
|
|
28591
28832
|
return out;
|
|
28592
28833
|
}
|
|
28593
28834
|
async function doctorReply(ctx, host) {
|
|
28594
|
-
const adapter = getAdapter(ctx.project.agent);
|
|
28835
|
+
const adapter = getAdapter(ctx.agent ?? ctx.project.agent);
|
|
28595
28836
|
const runtime = runtimeInfo(host.env, ctx.signal);
|
|
28596
28837
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
28597
28838
|
const failed = rows.some((r) => r.status === "FAIL");
|
|
@@ -28613,9 +28854,11 @@ async function doctorReply(ctx, host) {
|
|
|
28613
28854
|
const whole2 = [envLine2, table3, ...docs, ...info, ...notes].join("\n");
|
|
28614
28855
|
const bytes5 = Buffer.byteLength(whole2, "utf8");
|
|
28615
28856
|
if (bytes5 <= REPORT_CAP) return { text: whole2, isError: false, sandboxBytes: bytes5 };
|
|
28616
|
-
const
|
|
28857
|
+
const p = projectOrMissing(ctx);
|
|
28858
|
+
if ("missing" in p) return { text: whole2, isError: false, sandboxBytes: bytes5 };
|
|
28859
|
+
const db = await openDb(p.project);
|
|
28617
28860
|
try {
|
|
28618
|
-
indexText(db,
|
|
28861
|
+
indexText(db, p.project, ctx.sessionId, REPORT_SOURCE_LABEL, whole2, "text");
|
|
28619
28862
|
} finally {
|
|
28620
28863
|
closeDb(db);
|
|
28621
28864
|
}
|
|
@@ -28640,9 +28883,9 @@ var ctxDoctor = Object.freeze({
|
|
|
28640
28883
|
});
|
|
28641
28884
|
|
|
28642
28885
|
// src/core/tools/execute.ts
|
|
28643
|
-
import { existsSync as existsSync18, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as
|
|
28886
|
+
import { existsSync as existsSync18, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync6 } from "node:fs";
|
|
28644
28887
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
28645
|
-
import { dirname as dirname12, join as
|
|
28888
|
+
import { dirname as dirname12, join as join22, parse as parse3, resolve as resolve11 } from "node:path";
|
|
28646
28889
|
|
|
28647
28890
|
// src/core/sandbox/win-build.ts
|
|
28648
28891
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -28811,9 +29054,9 @@ async function handler3(raw, ctx) {
|
|
|
28811
29054
|
if (takesDashC(input.language, runtime)) {
|
|
28812
29055
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
28813
29056
|
} else {
|
|
28814
|
-
tmpDir = mkdtempSync2(
|
|
28815
|
-
const file2 =
|
|
28816
|
-
|
|
29057
|
+
tmpDir = mkdtempSync2(join22(tmpdir3(), TMP_PREFIX));
|
|
29058
|
+
const file2 = join22(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
29059
|
+
writeFileSync6(file2, scriptText(input.language, input.code), "utf8");
|
|
28817
29060
|
argv = scriptArgv(input.language, runtime, file2);
|
|
28818
29061
|
}
|
|
28819
29062
|
if (input.background === true) {
|
|
@@ -28848,12 +29091,12 @@ var ctxExecute = {
|
|
|
28848
29091
|
};
|
|
28849
29092
|
|
|
28850
29093
|
// src/core/tools/index.ts
|
|
28851
|
-
import { existsSync as existsSync19, readFileSync as
|
|
28852
|
-
import { dirname as dirname13, extname as extname3, join as
|
|
29094
|
+
import { existsSync as existsSync19, readFileSync as readFileSync21, statSync as statSync10 } from "node:fs";
|
|
29095
|
+
import { dirname as dirname13, extname as extname3, join as join25, relative as relative5, resolve as resolve12 } from "node:path";
|
|
28853
29096
|
|
|
28854
29097
|
// src/core/index/walk.ts
|
|
28855
|
-
import { readdirSync as
|
|
28856
|
-
import { join as
|
|
29098
|
+
import { readdirSync as readdirSync10, readFileSync as readFileSync19, realpathSync as realpathSync10, statSync as statSync9 } from "node:fs";
|
|
29099
|
+
import { join as join23 } from "node:path";
|
|
28857
29100
|
var GITIGNORE = ".gitignore";
|
|
28858
29101
|
var GIT_DIR = ".git";
|
|
28859
29102
|
function walkDir(root, containmentRoot) {
|
|
@@ -28862,19 +29105,19 @@ function walkDir(root, containmentRoot) {
|
|
|
28862
29105
|
const found = [];
|
|
28863
29106
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
28864
29107
|
found.sort(compareFound);
|
|
28865
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
29108
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join23(...f.dir, f.name) }));
|
|
28866
29109
|
}
|
|
28867
29110
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
28868
29111
|
let entries;
|
|
28869
29112
|
try {
|
|
28870
|
-
entries =
|
|
29113
|
+
entries = readdirSync10(abs, { withFileTypes: true });
|
|
28871
29114
|
} catch {
|
|
28872
29115
|
return;
|
|
28873
29116
|
}
|
|
28874
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
29117
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join23(abs, GITIGNORE), rel)) : parent;
|
|
28875
29118
|
for (const e of entries) {
|
|
28876
29119
|
if (e.name === GIT_DIR) continue;
|
|
28877
|
-
const path8 =
|
|
29120
|
+
const path8 = join23(abs, e.name);
|
|
28878
29121
|
let isDir = e.isDirectory();
|
|
28879
29122
|
let isFile = e.isFile();
|
|
28880
29123
|
let target = path8;
|
|
@@ -28886,7 +29129,7 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
28886
29129
|
continue;
|
|
28887
29130
|
}
|
|
28888
29131
|
if (!isInside(contain, resolved)) continue;
|
|
28889
|
-
const st =
|
|
29132
|
+
const st = statSync9(resolved);
|
|
28890
29133
|
isDir = st.isDirectory();
|
|
28891
29134
|
isFile = st.isFile();
|
|
28892
29135
|
target = resolved;
|
|
@@ -28914,7 +29157,7 @@ function compareFound(a, b) {
|
|
|
28914
29157
|
function readRules(file2, base) {
|
|
28915
29158
|
let body;
|
|
28916
29159
|
try {
|
|
28917
|
-
body =
|
|
29160
|
+
body = readFileSync19(file2, "utf8");
|
|
28918
29161
|
} catch {
|
|
28919
29162
|
return [];
|
|
28920
29163
|
}
|
|
@@ -28997,12 +29240,13 @@ function globSeg(pat, name) {
|
|
|
28997
29240
|
}
|
|
28998
29241
|
|
|
28999
29242
|
// src/core/sandbox/fetch.ts
|
|
29000
|
-
import {
|
|
29243
|
+
import { randomBytes } from "node:crypto";
|
|
29244
|
+
import { readFileSync as readFileSync20 } from "node:fs";
|
|
29001
29245
|
import { lookup } from "node:dns/promises";
|
|
29002
29246
|
import http from "node:http";
|
|
29003
29247
|
import https from "node:https";
|
|
29004
29248
|
import { BlockList, isIP } from "node:net";
|
|
29005
|
-
import { join as
|
|
29249
|
+
import { join as join24 } from "node:path";
|
|
29006
29250
|
import { connect as tlsConnect } from "node:tls";
|
|
29007
29251
|
var PRIVATE_RANGES = [
|
|
29008
29252
|
["127.0.0.0", 8, "ipv4"],
|
|
@@ -29031,6 +29275,26 @@ var PRIVATE_RANGES = [
|
|
|
29031
29275
|
];
|
|
29032
29276
|
var BLOCKED = new BlockList();
|
|
29033
29277
|
for (const [net, prefix, type] of PRIVATE_RANGES) BLOCKED.addSubnet(net, prefix, type);
|
|
29278
|
+
var FAKE_IP_POOL = new BlockList();
|
|
29279
|
+
FAKE_IP_POOL.addSubnet("198.18.0.0", 15, "ipv4");
|
|
29280
|
+
var FAKE_IP_PROBE_TLD = ".invalid";
|
|
29281
|
+
var FAKE_IP_PROBE_BYTES = 8;
|
|
29282
|
+
var FAKE_IP_PROBE_MS = 1500;
|
|
29283
|
+
var fakeIpProbe;
|
|
29284
|
+
function inFakeIpPool(address) {
|
|
29285
|
+
return isIP(address) === 4 && FAKE_IP_POOL.check(address, "ipv4");
|
|
29286
|
+
}
|
|
29287
|
+
function fakeIpResolver() {
|
|
29288
|
+
fakeIpProbe ??= new Promise((resolve13) => {
|
|
29289
|
+
const timer = setTimeout(() => resolve13(false), FAKE_IP_PROBE_MS);
|
|
29290
|
+
timer.unref();
|
|
29291
|
+
lookup(randomBytes(FAKE_IP_PROBE_BYTES).toString("hex") + FAKE_IP_PROBE_TLD, { all: true }).then(
|
|
29292
|
+
(addrs) => resolve13(addrs.length > 0 && addrs.every((a) => inFakeIpPool(a.address))),
|
|
29293
|
+
() => resolve13(false)
|
|
29294
|
+
).finally(() => clearTimeout(timer));
|
|
29295
|
+
});
|
|
29296
|
+
return fakeIpProbe;
|
|
29297
|
+
}
|
|
29034
29298
|
var STATUS_OK_FIRST = 200;
|
|
29035
29299
|
var STATUS_OK_END = 300;
|
|
29036
29300
|
var STATUS_REDIRECT = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
@@ -29041,7 +29305,7 @@ function baseHeaders() {
|
|
|
29041
29305
|
if (namedHeaders === void 0) {
|
|
29042
29306
|
let version4 = UA_DEV_VERSION;
|
|
29043
29307
|
try {
|
|
29044
|
-
const v = JSON.parse(
|
|
29308
|
+
const v = JSON.parse(readFileSync20(join24(ownBundleDir(), D1_PACKAGE_FILE), "utf8")).version;
|
|
29045
29309
|
if (typeof v === "string" && v !== "") version4 = v;
|
|
29046
29310
|
} catch {
|
|
29047
29311
|
}
|
|
@@ -29133,8 +29397,15 @@ function checkAddress(hostname2, address) {
|
|
|
29133
29397
|
throw new CtxError("SSRF", { host: hostname2 });
|
|
29134
29398
|
}
|
|
29135
29399
|
}
|
|
29136
|
-
async function
|
|
29137
|
-
const
|
|
29400
|
+
async function checkResolved(host, addrs, signal) {
|
|
29401
|
+
const pooled = isIP(host) === 0 ? addrs.filter((a) => inFakeIpPool(a.address)) : [];
|
|
29402
|
+
for (const a of addrs) if (!pooled.includes(a)) checkAddress(host, a.address);
|
|
29403
|
+
if (pooled.length === 0) return;
|
|
29404
|
+
const fakeIp = await fakeIpResolver();
|
|
29405
|
+
if (signal.aborted) throw fail6("ABORT_ERR");
|
|
29406
|
+
if (!fakeIp) checkAddress(host, pooled[0].address);
|
|
29407
|
+
}
|
|
29408
|
+
async function lookupAll(host, signal) {
|
|
29138
29409
|
let addrs;
|
|
29139
29410
|
try {
|
|
29140
29411
|
addrs = await lookup(host, { all: true });
|
|
@@ -29143,9 +29414,26 @@ async function resolveTarget(u, signal) {
|
|
|
29143
29414
|
}
|
|
29144
29415
|
if (signal.aborted) throw fail6("ABORT_ERR");
|
|
29145
29416
|
if (addrs.length === 0) throw fail6("ENOTFOUND");
|
|
29146
|
-
|
|
29417
|
+
return addrs;
|
|
29418
|
+
}
|
|
29419
|
+
async function resolveTarget(u, signal, checked) {
|
|
29420
|
+
const host = bare(u.hostname);
|
|
29421
|
+
const addrs = await lookupAll(host, signal);
|
|
29422
|
+
if (checked) await checkResolved(host, addrs, signal);
|
|
29147
29423
|
return { host, port: u.port === "" ? defaultPort(u.protocol) : Number(u.port), address: addrs[0].address };
|
|
29148
29424
|
}
|
|
29425
|
+
async function checkProxiedTarget(u, signal) {
|
|
29426
|
+
const host = bare(u.hostname);
|
|
29427
|
+
if (isIP(host) !== 0) return checkAddress(host, host);
|
|
29428
|
+
let addrs;
|
|
29429
|
+
try {
|
|
29430
|
+
addrs = await lookupAll(host, signal);
|
|
29431
|
+
} catch (err) {
|
|
29432
|
+
if (signal.aborted) throw err;
|
|
29433
|
+
return;
|
|
29434
|
+
}
|
|
29435
|
+
await checkResolved(host, addrs, signal);
|
|
29436
|
+
}
|
|
29149
29437
|
function tlsName(host) {
|
|
29150
29438
|
return isIP(host) === 0 ? host : void 0;
|
|
29151
29439
|
}
|
|
@@ -29203,9 +29491,8 @@ async function safeFetch(url4, signal) {
|
|
|
29203
29491
|
for (let hop = 0; ; hop += 1) {
|
|
29204
29492
|
if (signal.aborted) throw fail6("ABORT_ERR");
|
|
29205
29493
|
const proxy = pickProxy(current);
|
|
29206
|
-
|
|
29207
|
-
|
|
29208
|
-
const conn = await resolveTarget(proxy === void 0 ? current : proxy.url, signal);
|
|
29494
|
+
if (proxy !== void 0) await checkProxiedTarget(current, signal);
|
|
29495
|
+
const conn = await resolveTarget(proxy === void 0 ? current : proxy.url, signal, proxy === void 0);
|
|
29209
29496
|
const res = await request(current, conn, proxy, signal);
|
|
29210
29497
|
const status = res.statusCode ?? 0;
|
|
29211
29498
|
const location = res.headers.location;
|
|
@@ -29354,7 +29641,7 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
29354
29641
|
readNgramReferences(ngramCount - dictSize + dict1AtomCount, dictSize + dict2AtomCount);
|
|
29355
29642
|
readNgramReferences(dictSize - dict1AtomCount, dict1AtomCount);
|
|
29356
29643
|
const pool = new Uint16Array(poolSize);
|
|
29357
|
-
let
|
|
29644
|
+
let write = 0;
|
|
29358
29645
|
for (let index = 0; index < ngramIndex; index++) {
|
|
29359
29646
|
for (let half = 0; half < 2; half++) {
|
|
29360
29647
|
const source = references[index * 2 + half];
|
|
@@ -29363,9 +29650,9 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
29363
29650
|
let read3 = start[source];
|
|
29364
29651
|
const readEnd = read3 + length[source];
|
|
29365
29652
|
while (read3 < readEnd)
|
|
29366
|
-
pool[
|
|
29653
|
+
pool[write++] = pool[read3++];
|
|
29367
29654
|
} else {
|
|
29368
|
-
pool[
|
|
29655
|
+
pool[write++] = value;
|
|
29369
29656
|
}
|
|
29370
29657
|
}
|
|
29371
29658
|
}
|
|
@@ -33059,7 +33346,7 @@ function kindOfType(contentType) {
|
|
|
33059
33346
|
}
|
|
33060
33347
|
function readUtf8(absPath) {
|
|
33061
33348
|
try {
|
|
33062
|
-
return utf8.decode(
|
|
33349
|
+
return utf8.decode(readFileSync21(absPath));
|
|
33063
33350
|
} catch {
|
|
33064
33351
|
return void 0;
|
|
33065
33352
|
}
|
|
@@ -33074,10 +33361,10 @@ function pathItems(input, project) {
|
|
|
33074
33361
|
const abs = resolve12(project.worktree, input.path);
|
|
33075
33362
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
33076
33363
|
const base = relative5(project.worktree, abs);
|
|
33077
|
-
if (
|
|
33364
|
+
if (statSync10(abs).isDirectory()) {
|
|
33078
33365
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
33079
33366
|
sourceKind: "path",
|
|
33080
|
-
label: pathLabel(
|
|
33367
|
+
label: pathLabel(join25(base, f.relPath)),
|
|
33081
33368
|
kind: kindOfPath(f.relPath),
|
|
33082
33369
|
read: () => readUtf8(f.absPath)
|
|
33083
33370
|
}));
|
|
@@ -33201,7 +33488,7 @@ function purgeScope(db, scope, input) {
|
|
|
33201
33488
|
const chunks = deleteChunkRows(raw, "all");
|
|
33202
33489
|
return changes(raw, "DELETE FROM events") + chunks + changes(raw, "DELETE FROM sources");
|
|
33203
33490
|
}
|
|
33204
|
-
function
|
|
33491
|
+
function isBusy2(err) {
|
|
33205
33492
|
const code = err?.errcode;
|
|
33206
33493
|
return typeof code === "number" && (code & SQLITE_PRIMARY_CODE_MASK) === SQLITE_BUSY_CODE;
|
|
33207
33494
|
}
|
|
@@ -33219,7 +33506,7 @@ async function handler5(input, ctx) {
|
|
|
33219
33506
|
closeDb(db);
|
|
33220
33507
|
}
|
|
33221
33508
|
} catch (err) {
|
|
33222
|
-
if (
|
|
33509
|
+
if (isBusy2(err)) return reply2(PURGE_BUSY_LINE, true);
|
|
33223
33510
|
throw err;
|
|
33224
33511
|
}
|
|
33225
33512
|
}
|
|
@@ -33617,22 +33904,22 @@ var ctxStats = Object.freeze({
|
|
|
33617
33904
|
});
|
|
33618
33905
|
|
|
33619
33906
|
// src/core/ops/host-write.ts
|
|
33620
|
-
import { copyFileSync, existsSync as existsSync20, mkdirSync as
|
|
33621
|
-
import { dirname as dirname14, join as
|
|
33907
|
+
import { copyFileSync, existsSync as existsSync20, mkdirSync as mkdirSync9, writeFileSync as writeFileSync7 } from "node:fs";
|
|
33908
|
+
import { dirname as dirname14, join as join26 } from "node:path";
|
|
33622
33909
|
function defaultWrite(file2, text) {
|
|
33623
|
-
|
|
33910
|
+
writeFileSync7(file2, text, "utf8");
|
|
33624
33911
|
}
|
|
33625
33912
|
function hostConfigPath(agent, home, env) {
|
|
33626
33913
|
const own4 = OWN_MCP_ENTRY[agent];
|
|
33627
33914
|
if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
|
|
33628
33915
|
switch (agent) {
|
|
33629
33916
|
case "opencode":
|
|
33630
|
-
return
|
|
33917
|
+
return join26(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
33631
33918
|
// D-WIN-OPENCODE-DIR-1
|
|
33632
33919
|
case "pi":
|
|
33633
|
-
return
|
|
33920
|
+
return join26(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
33634
33921
|
case "gemini":
|
|
33635
|
-
return
|
|
33922
|
+
return join26(geminiDirOf(env, home), SETTINGS_FILE);
|
|
33636
33923
|
// D-R38-GEMINI-HOME-1
|
|
33637
33924
|
case "copilot-cli":
|
|
33638
33925
|
return null;
|
|
@@ -33640,7 +33927,7 @@ function hostConfigPath(agent, home, env) {
|
|
|
33640
33927
|
return null;
|
|
33641
33928
|
// ADR-0026 decision 8 (D-OMP-UPGRADE-1): OMP loads the plugin from its own store; no MCP entry, nothing under ~/.pi
|
|
33642
33929
|
default:
|
|
33643
|
-
return
|
|
33930
|
+
return join26(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
33644
33931
|
}
|
|
33645
33932
|
}
|
|
33646
33933
|
function cell3(value) {
|
|
@@ -33649,14 +33936,14 @@ function cell3(value) {
|
|
|
33649
33936
|
function toRow(file2, edit) {
|
|
33650
33937
|
return { area: file2 + UPGRADE_AREA_KEY_SEP + edit.path, before: cell3(edit.before), after: cell3(edit.after) };
|
|
33651
33938
|
}
|
|
33652
|
-
function writeWithRollback(file2, text,
|
|
33939
|
+
function writeWithRollback(file2, text, write, atomic) {
|
|
33653
33940
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
33654
33941
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
33655
33942
|
const had = existsSync20(file2);
|
|
33656
|
-
|
|
33943
|
+
mkdirSync9(dirname14(file2), { recursive: true });
|
|
33657
33944
|
if (had) copyFileSync(file2, trash);
|
|
33658
33945
|
try {
|
|
33659
|
-
|
|
33946
|
+
write(tmp, text);
|
|
33660
33947
|
renameWithRetry(tmp, file2, atomic);
|
|
33661
33948
|
} catch (err) {
|
|
33662
33949
|
removeTmpFile(tmp, atomic);
|
|
@@ -33690,15 +33977,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
33690
33977
|
}
|
|
33691
33978
|
|
|
33692
33979
|
// src/core/ops/uninstall.ts
|
|
33693
|
-
import { existsSync as existsSync21, readdirSync as
|
|
33694
|
-
import { join as
|
|
33980
|
+
import { existsSync as existsSync21, readdirSync as readdirSync11, rmSync as rmSync6, writeFileSync as writeFileSync8 } from "node:fs";
|
|
33981
|
+
import { join as join27 } from "node:path";
|
|
33695
33982
|
function row2(area, before, after) {
|
|
33696
33983
|
return { area, before, after };
|
|
33697
33984
|
}
|
|
33698
33985
|
function stopServers(configDir, projectKey) {
|
|
33699
33986
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
33700
|
-
const dir =
|
|
33701
|
-
for (const serverId of stopped)
|
|
33987
|
+
const dir = join27(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
33988
|
+
for (const serverId of stopped) writeFileSync8(join27(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
33702
33989
|
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 };
|
|
33703
33990
|
}
|
|
33704
33991
|
function rootOrNull(adapter, env) {
|
|
@@ -33716,14 +34003,14 @@ function removeCache(adapter, env, configDir) {
|
|
|
33716
34003
|
const root = rootOrNull(adapter, env);
|
|
33717
34004
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
33718
34005
|
if (adapter.installMode === "marketplace") {
|
|
33719
|
-
const cache =
|
|
34006
|
+
const cache = join27(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
33720
34007
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
33721
34008
|
}
|
|
33722
34009
|
rmSync6(root, { recursive: true, force: true });
|
|
33723
34010
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
33724
34011
|
}
|
|
33725
34012
|
case "plugin": {
|
|
33726
|
-
const agentDir =
|
|
34013
|
+
const agentDir = join27(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
33727
34014
|
if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
33728
34015
|
rmSync6(agentDir, { recursive: true, force: true });
|
|
33729
34016
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
@@ -33769,7 +34056,7 @@ function ownEntries2(agent, env) {
|
|
|
33769
34056
|
}
|
|
33770
34057
|
if (agent === "opencode") {
|
|
33771
34058
|
return [{
|
|
33772
|
-
file:
|
|
34059
|
+
file: join27(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
33773
34060
|
// D-WIN-OPENCODE-DIR-1
|
|
33774
34061
|
key: OPENCODE_PLUGIN_KEY,
|
|
33775
34062
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -33780,7 +34067,7 @@ function ownEntries2(agent, env) {
|
|
|
33780
34067
|
if (agent === "pi") {
|
|
33781
34068
|
const agentDir = piAgentDirOf(env, home);
|
|
33782
34069
|
return [{
|
|
33783
|
-
file:
|
|
34070
|
+
file: join27(agentDir, SETTINGS_FILE),
|
|
33784
34071
|
key: PI_PACKAGES_KEY,
|
|
33785
34072
|
shown: PI_PACKAGES_KEY,
|
|
33786
34073
|
has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
|
|
@@ -33811,12 +34098,12 @@ function removeOwnEntries(agent, env) {
|
|
|
33811
34098
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
33812
34099
|
}
|
|
33813
34100
|
function removeProjectData(configDir, projectKey) {
|
|
33814
|
-
const projects =
|
|
33815
|
-
const dir =
|
|
34101
|
+
const projects = join27(configDir, PROJECTS_DIR_NAME);
|
|
34102
|
+
const dir = join27(projects, projectKey);
|
|
33816
34103
|
if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
33817
34104
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
33818
|
-
for (const name of
|
|
33819
|
-
if (name !== OWNERS_DIR_NAME) rmSync6(
|
|
34105
|
+
for (const name of readdirSync11(dir)) {
|
|
34106
|
+
if (name !== OWNERS_DIR_NAME) rmSync6(join27(dir, name), { recursive: true, force: true });
|
|
33820
34107
|
}
|
|
33821
34108
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
33822
34109
|
}
|
|
@@ -33824,12 +34111,12 @@ function runUninstall(input) {
|
|
|
33824
34111
|
const configDir = resolveConfigDir(input.env);
|
|
33825
34112
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
33826
34113
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
33827
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
34114
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join27(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
33828
34115
|
return { rows, stopped: stop.stopped };
|
|
33829
34116
|
}
|
|
33830
34117
|
|
|
33831
34118
|
// src/core/ops/v1-remove.ts
|
|
33832
|
-
import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as
|
|
34119
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync22, rmSync as rmSync7 } from "node:fs";
|
|
33833
34120
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
33834
34121
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
33835
34122
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -33880,8 +34167,8 @@ function locate(doc, path8) {
|
|
|
33880
34167
|
return null;
|
|
33881
34168
|
}
|
|
33882
34169
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
33883
|
-
const layout = hostLayout(
|
|
33884
|
-
const text = hostText(
|
|
34170
|
+
const layout = hostLayout(readFileSync22(file2, "utf8"));
|
|
34171
|
+
const text = hostText(readFileSync22(file2, "utf8"));
|
|
33885
34172
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
33886
34173
|
const hit = /* @__PURE__ */ new Set();
|
|
33887
34174
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -33931,7 +34218,7 @@ function removeV1(agent, findings, project) {
|
|
|
33931
34218
|
continue;
|
|
33932
34219
|
}
|
|
33933
34220
|
if (file2.endsWith(TOML_EXT)) {
|
|
33934
|
-
const rawToml =
|
|
34221
|
+
const rawToml = readFileSync22(file2, "utf8");
|
|
33935
34222
|
const tomlLayout = hostLayout(rawToml);
|
|
33936
34223
|
let text = hostText(rawToml);
|
|
33937
34224
|
for (const f of list4) {
|
|
@@ -34091,7 +34378,7 @@ function checkCall(tool, input) {
|
|
|
34091
34378
|
// src/entries/server.ts
|
|
34092
34379
|
import { randomUUID } from "node:crypto";
|
|
34093
34380
|
import { existsSync as existsSync24, realpathSync as realpathSync12, rmSync as rmSync9 } from "node:fs";
|
|
34094
|
-
import { dirname as dirname15, join as
|
|
34381
|
+
import { dirname as dirname15, join as join29 } from "node:path";
|
|
34095
34382
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
34096
34383
|
|
|
34097
34384
|
// node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
@@ -34739,8 +35026,8 @@ function prefixIssues2(path8, issues) {
|
|
|
34739
35026
|
return iss;
|
|
34740
35027
|
});
|
|
34741
35028
|
}
|
|
34742
|
-
function unwrapMessage2(
|
|
34743
|
-
return typeof
|
|
35029
|
+
function unwrapMessage2(message4) {
|
|
35030
|
+
return typeof message4 === "string" ? message4 : message4?.message;
|
|
34744
35031
|
}
|
|
34745
35032
|
function sizeCaps(defChecks) {
|
|
34746
35033
|
const caps = [];
|
|
@@ -34770,7 +35057,7 @@ function finalizeIssue2(iss, ctx, config4) {
|
|
|
34770
35057
|
iss.schema = iss.inst;
|
|
34771
35058
|
}
|
|
34772
35059
|
const schemaError = iss.schema !== iss.inst ? iss.schema?._zod.def?.error : void 0;
|
|
34773
|
-
const
|
|
35060
|
+
const message4 = iss.message ? iss.message : unwrapMessage2(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage2(schemaError?.(iss)) ?? unwrapMessage2(ctx?.error?.(iss)) ?? unwrapMessage2(config4.customError?.(iss)) ?? unwrapMessage2(config4.localeError?.(iss)) ?? "Invalid input";
|
|
34774
35061
|
const full = {};
|
|
34775
35062
|
for (const k of Object.keys(iss)) {
|
|
34776
35063
|
if (k === "inst" || k === "schema" || k === "continue" || k === "input" || k === "__proto__")
|
|
@@ -34778,7 +35065,7 @@ function finalizeIssue2(iss, ctx, config4) {
|
|
|
34778
35065
|
full[k] = iss[k];
|
|
34779
35066
|
}
|
|
34780
35067
|
full.path ?? (full.path = []);
|
|
34781
|
-
full.message =
|
|
35068
|
+
full.message = message4;
|
|
34782
35069
|
if (ctx?.reportInput) {
|
|
34783
35070
|
full.input = iss.input;
|
|
34784
35071
|
}
|
|
@@ -34937,7 +35224,7 @@ function defineBound(proto, key, fn) {
|
|
|
34937
35224
|
}
|
|
34938
35225
|
});
|
|
34939
35226
|
}
|
|
34940
|
-
function
|
|
35227
|
+
function claim2(inst, sentinel) {
|
|
34941
35228
|
const proto = Object.getPrototypeOf(inst);
|
|
34942
35229
|
return sentinel in proto ? void 0 : proto;
|
|
34943
35230
|
}
|
|
@@ -34983,7 +35270,7 @@ function defineLazyInternal(inst, key, compute) {
|
|
|
34983
35270
|
});
|
|
34984
35271
|
}
|
|
34985
35272
|
function installLazyProp(inst, key, make2, enumerable) {
|
|
34986
|
-
const proto =
|
|
35273
|
+
const proto = claim2(inst, key);
|
|
34987
35274
|
if (!proto)
|
|
34988
35275
|
return;
|
|
34989
35276
|
Object.defineProperty(proto, key, {
|
|
@@ -38587,12 +38874,12 @@ function initializeContext(params) {
|
|
|
38587
38874
|
external: params?.external ?? void 0
|
|
38588
38875
|
};
|
|
38589
38876
|
}
|
|
38590
|
-
function handleUnrepresentable(schema, ctx, json2, params,
|
|
38591
|
-
const result = typeof ctx.unrepresentable === "function" ? ctx.unrepresentable({ zodSchema: schema, path: params.path, message:
|
|
38877
|
+
function handleUnrepresentable(schema, ctx, json2, params, message4) {
|
|
38878
|
+
const result = typeof ctx.unrepresentable === "function" ? ctx.unrepresentable({ zodSchema: schema, path: params.path, message: message4 }) : ctx.unrepresentable;
|
|
38592
38879
|
if (result === "any")
|
|
38593
38880
|
return false;
|
|
38594
38881
|
if (result === void 0 || result === "throw")
|
|
38595
|
-
throw new Error(
|
|
38882
|
+
throw new Error(message4);
|
|
38596
38883
|
Object.assign(json2, result);
|
|
38597
38884
|
return true;
|
|
38598
38885
|
}
|
|
@@ -42320,8 +42607,8 @@ function prefixIssues3(path8, issues) {
|
|
|
42320
42607
|
return iss;
|
|
42321
42608
|
});
|
|
42322
42609
|
}
|
|
42323
|
-
function unwrapMessage3(
|
|
42324
|
-
return typeof
|
|
42610
|
+
function unwrapMessage3(message4) {
|
|
42611
|
+
return typeof message4 === "string" ? message4 : message4?.message;
|
|
42325
42612
|
}
|
|
42326
42613
|
function sizeCaps2(defChecks) {
|
|
42327
42614
|
const caps = [];
|
|
@@ -42351,7 +42638,7 @@ function finalizeIssue3(iss, ctx, config4) {
|
|
|
42351
42638
|
iss.schema = iss.inst;
|
|
42352
42639
|
}
|
|
42353
42640
|
const schemaError = iss.schema !== iss.inst ? iss.schema?._zod.def?.error : void 0;
|
|
42354
|
-
const
|
|
42641
|
+
const message4 = iss.message ? iss.message : unwrapMessage3(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage3(schemaError?.(iss)) ?? unwrapMessage3(ctx?.error?.(iss)) ?? unwrapMessage3(config4.customError?.(iss)) ?? unwrapMessage3(config4.localeError?.(iss)) ?? "Invalid input";
|
|
42355
42642
|
const full = {};
|
|
42356
42643
|
for (const k of Object.keys(iss)) {
|
|
42357
42644
|
if (k === "inst" || k === "schema" || k === "continue" || k === "input" || k === "__proto__")
|
|
@@ -42359,7 +42646,7 @@ function finalizeIssue3(iss, ctx, config4) {
|
|
|
42359
42646
|
full[k] = iss[k];
|
|
42360
42647
|
}
|
|
42361
42648
|
full.path ?? (full.path = []);
|
|
42362
|
-
full.message =
|
|
42649
|
+
full.message = message4;
|
|
42363
42650
|
if (ctx?.reportInput) {
|
|
42364
42651
|
full.input = iss.input;
|
|
42365
42652
|
}
|
|
@@ -42518,7 +42805,7 @@ function defineBound2(proto, key, fn) {
|
|
|
42518
42805
|
}
|
|
42519
42806
|
});
|
|
42520
42807
|
}
|
|
42521
|
-
function
|
|
42808
|
+
function claim3(inst, sentinel) {
|
|
42522
42809
|
const proto = Object.getPrototypeOf(inst);
|
|
42523
42810
|
return sentinel in proto ? void 0 : proto;
|
|
42524
42811
|
}
|
|
@@ -42564,7 +42851,7 @@ function defineLazyInternal2(inst, key, compute) {
|
|
|
42564
42851
|
});
|
|
42565
42852
|
}
|
|
42566
42853
|
function installLazyProp2(inst, key, make2, enumerable) {
|
|
42567
|
-
const proto =
|
|
42854
|
+
const proto = claim3(inst, key);
|
|
42568
42855
|
if (!proto)
|
|
42569
42856
|
return;
|
|
42570
42857
|
Object.defineProperty(proto, key, {
|
|
@@ -46078,12 +46365,12 @@ function initializeContext2(params) {
|
|
|
46078
46365
|
external: params?.external ?? void 0
|
|
46079
46366
|
};
|
|
46080
46367
|
}
|
|
46081
|
-
function handleUnrepresentable2(schema, ctx, json2, params,
|
|
46082
|
-
const result = typeof ctx.unrepresentable === "function" ? ctx.unrepresentable({ zodSchema: schema, path: params.path, message:
|
|
46368
|
+
function handleUnrepresentable2(schema, ctx, json2, params, message4) {
|
|
46369
|
+
const result = typeof ctx.unrepresentable === "function" ? ctx.unrepresentable({ zodSchema: schema, path: params.path, message: message4 }) : ctx.unrepresentable;
|
|
46083
46370
|
if (result === "any")
|
|
46084
46371
|
return false;
|
|
46085
46372
|
if (result === void 0 || result === "throw")
|
|
46086
|
-
throw new Error(
|
|
46373
|
+
throw new Error(message4);
|
|
46087
46374
|
Object.assign(json2, result);
|
|
46088
46375
|
return true;
|
|
46089
46376
|
}
|
|
@@ -48410,8 +48697,8 @@ var OAuthError = class OAuthError2 extends Error {
|
|
|
48410
48697
|
if (typeof this !== "function") throw new TypeError("isInstance must be called on the class (e.g. `SdkError.isInstance(value)`); for callbacks use `v => SdkError.isInstance(v)`");
|
|
48411
48698
|
return brandedHasInstance(this, value);
|
|
48412
48699
|
}
|
|
48413
|
-
constructor(code,
|
|
48414
|
-
super(
|
|
48700
|
+
constructor(code, message4, errorUri) {
|
|
48701
|
+
super(message4);
|
|
48415
48702
|
this.code = code;
|
|
48416
48703
|
this.errorUri = errorUri;
|
|
48417
48704
|
this.name = "OAuthError";
|
|
@@ -48487,8 +48774,8 @@ var SdkError = class extends Error {
|
|
|
48487
48774
|
* failure as `{ cause }` so it is reachable through the `Error.cause` chain that
|
|
48488
48775
|
* loggers and error trackers walk.
|
|
48489
48776
|
*/
|
|
48490
|
-
constructor(code,
|
|
48491
|
-
super(
|
|
48777
|
+
constructor(code, message4, data, options) {
|
|
48778
|
+
super(message4, options);
|
|
48492
48779
|
this.code = code;
|
|
48493
48780
|
this.data = data;
|
|
48494
48781
|
this.name = "SdkError";
|
|
@@ -48502,8 +48789,8 @@ var SdkHttpError = class extends SdkError {
|
|
|
48502
48789
|
/**
|
|
48503
48790
|
* @param options - Standard `ErrorOptions`, forwarded to `Error` (see {@linkcode SdkError}).
|
|
48504
48791
|
*/
|
|
48505
|
-
constructor(code,
|
|
48506
|
-
super(code,
|
|
48792
|
+
constructor(code, message4, data, options) {
|
|
48793
|
+
super(code, message4, data, options);
|
|
48507
48794
|
this.name = "SdkHttpError";
|
|
48508
48795
|
}
|
|
48509
48796
|
get status() {
|
|
@@ -50688,8 +50975,8 @@ var ProtocolError = class ProtocolError2 extends Error {
|
|
|
50688
50975
|
if (typeof this !== "function") throw new TypeError("isInstance must be called on the class (e.g. `SdkError.isInstance(value)`); for callbacks use `v => SdkError.isInstance(v)`");
|
|
50689
50976
|
return brandedHasInstance(this, value);
|
|
50690
50977
|
}
|
|
50691
|
-
constructor(code,
|
|
50692
|
-
super(
|
|
50978
|
+
constructor(code, message4, data) {
|
|
50979
|
+
super(message4);
|
|
50693
50980
|
this.code = code;
|
|
50694
50981
|
this.data = data;
|
|
50695
50982
|
this.name = "ProtocolError";
|
|
@@ -50698,35 +50985,35 @@ var ProtocolError = class ProtocolError2 extends Error {
|
|
|
50698
50985
|
/**
|
|
50699
50986
|
* Factory method to create the appropriate error type based on the error code and data
|
|
50700
50987
|
*/
|
|
50701
|
-
static fromError(code,
|
|
50988
|
+
static fromError(code, message4, data) {
|
|
50702
50989
|
if (code === ProtocolErrorCode.UrlElicitationRequired && data) {
|
|
50703
50990
|
const errorData = data;
|
|
50704
|
-
if (errorData.elicitations) return new UrlElicitationRequiredError(errorData.elicitations,
|
|
50991
|
+
if (errorData.elicitations) return new UrlElicitationRequiredError(errorData.elicitations, message4);
|
|
50705
50992
|
}
|
|
50706
50993
|
if (code === ProtocolErrorCode.UnsupportedProtocolVersion && data) {
|
|
50707
50994
|
const errorData = data;
|
|
50708
50995
|
if (Array.isArray(errorData.supported) && typeof errorData.requested === "string") return new UnsupportedProtocolVersionError({
|
|
50709
50996
|
supported: errorData.supported,
|
|
50710
50997
|
requested: errorData.requested
|
|
50711
|
-
},
|
|
50998
|
+
}, message4);
|
|
50712
50999
|
}
|
|
50713
51000
|
if (code === ProtocolErrorCode.InvalidParams || code === ProtocolErrorCode.ResourceNotFound) {
|
|
50714
51001
|
const errorData = data;
|
|
50715
|
-
if (typeof errorData?.uri === "string" && (code === ProtocolErrorCode.ResourceNotFound || Object.keys(errorData).length === 1)) return new ResourceNotFoundError(errorData.uri,
|
|
51002
|
+
if (typeof errorData?.uri === "string" && (code === ProtocolErrorCode.ResourceNotFound || Object.keys(errorData).length === 1)) return new ResourceNotFoundError(errorData.uri, message4);
|
|
50716
51003
|
}
|
|
50717
51004
|
if (code === ProtocolErrorCode.MissingRequiredClientCapability && data) {
|
|
50718
51005
|
const errorData = data;
|
|
50719
|
-
if (errorData.requiredCapabilities !== null && typeof errorData.requiredCapabilities === "object" && !Array.isArray(errorData.requiredCapabilities)) return new MissingRequiredClientCapabilityError({ requiredCapabilities: errorData.requiredCapabilities },
|
|
51006
|
+
if (errorData.requiredCapabilities !== null && typeof errorData.requiredCapabilities === "object" && !Array.isArray(errorData.requiredCapabilities)) return new MissingRequiredClientCapabilityError({ requiredCapabilities: errorData.requiredCapabilities }, message4);
|
|
50720
51007
|
}
|
|
50721
|
-
return new ProtocolError2(code,
|
|
51008
|
+
return new ProtocolError2(code, message4, data);
|
|
50722
51009
|
}
|
|
50723
51010
|
};
|
|
50724
51011
|
var ResourceNotFoundError = class extends ProtocolError {
|
|
50725
51012
|
static {
|
|
50726
51013
|
Object.defineProperty(this, "mcpBrand", { value: "mcp.ResourceNotFoundError" });
|
|
50727
51014
|
}
|
|
50728
|
-
constructor(uri,
|
|
50729
|
-
super(ProtocolErrorCode.InvalidParams,
|
|
51015
|
+
constructor(uri, message4 = `Resource not found: ${uri}`) {
|
|
51016
|
+
super(ProtocolErrorCode.InvalidParams, message4, { uri });
|
|
50730
51017
|
}
|
|
50731
51018
|
/** The URI that was requested and not found. */
|
|
50732
51019
|
get uri() {
|
|
@@ -50737,8 +51024,8 @@ var UrlElicitationRequiredError = class extends ProtocolError {
|
|
|
50737
51024
|
static {
|
|
50738
51025
|
Object.defineProperty(this, "mcpBrand", { value: "mcp.UrlElicitationRequiredError" });
|
|
50739
51026
|
}
|
|
50740
|
-
constructor(elicitations,
|
|
50741
|
-
super(ProtocolErrorCode.UrlElicitationRequired,
|
|
51027
|
+
constructor(elicitations, message4 = `URL elicitation${elicitations.length > 1 ? "s" : ""} required`) {
|
|
51028
|
+
super(ProtocolErrorCode.UrlElicitationRequired, message4, { elicitations });
|
|
50742
51029
|
}
|
|
50743
51030
|
get elicitations() {
|
|
50744
51031
|
return this.data?.elicitations ?? [];
|
|
@@ -50748,8 +51035,8 @@ var UnsupportedProtocolVersionError = class extends ProtocolError {
|
|
|
50748
51035
|
static {
|
|
50749
51036
|
Object.defineProperty(this, "mcpBrand", { value: "mcp.UnsupportedProtocolVersionError" });
|
|
50750
51037
|
}
|
|
50751
|
-
constructor(data,
|
|
50752
|
-
super(ProtocolErrorCode.UnsupportedProtocolVersion,
|
|
51038
|
+
constructor(data, message4 = `Unsupported protocol version: ${data.requested}`) {
|
|
51039
|
+
super(ProtocolErrorCode.UnsupportedProtocolVersion, message4, data);
|
|
50753
51040
|
}
|
|
50754
51041
|
/**
|
|
50755
51042
|
* Protocol versions the receiver supports.
|
|
@@ -50768,8 +51055,8 @@ var MissingRequiredClientCapabilityError = class extends ProtocolError {
|
|
|
50768
51055
|
static {
|
|
50769
51056
|
Object.defineProperty(this, "mcpBrand", { value: "mcp.MissingRequiredClientCapabilityError" });
|
|
50770
51057
|
}
|
|
50771
|
-
constructor(data,
|
|
50772
|
-
super(ProtocolErrorCode.MissingRequiredClientCapability,
|
|
51058
|
+
constructor(data, message4 = `Missing required client capabilities: ${Object.keys(data.requiredCapabilities).join(", ")}`) {
|
|
51059
|
+
super(ProtocolErrorCode.MissingRequiredClientCapability, message4, data);
|
|
50773
51060
|
}
|
|
50774
51061
|
/**
|
|
50775
51062
|
* The capabilities the server requires from the client to process the
|
|
@@ -52022,17 +52309,17 @@ var RESERVED_ENVELOPE_META_KEYS = [
|
|
|
52022
52309
|
LOG_LEVEL_META_KEY
|
|
52023
52310
|
];
|
|
52024
52311
|
var RETRY_PARAMS_KEYS = ["inputResponses", "requestState"];
|
|
52025
|
-
function liftWireOnlyMaterial(
|
|
52026
|
-
const params =
|
|
52312
|
+
function liftWireOnlyMaterial(message4, kind) {
|
|
52313
|
+
const params = message4.params;
|
|
52027
52314
|
if (!isPlainObject$1(params)) return {
|
|
52028
|
-
message:
|
|
52315
|
+
message: message4,
|
|
52029
52316
|
lifted: {}
|
|
52030
52317
|
};
|
|
52031
52318
|
const meta3 = params._meta;
|
|
52032
52319
|
const envelopeKeys = isPlainObject$1(meta3) ? RESERVED_ENVELOPE_META_KEYS.filter((key) => key in meta3) : [];
|
|
52033
52320
|
const retryKeys = kind === "request" ? RETRY_PARAMS_KEYS.filter((key) => key in params) : [];
|
|
52034
52321
|
if (envelopeKeys.length === 0 && retryKeys.length === 0) return {
|
|
52035
|
-
message:
|
|
52322
|
+
message: message4,
|
|
52036
52323
|
lifted: {}
|
|
52037
52324
|
};
|
|
52038
52325
|
const lifted = {};
|
|
@@ -52055,7 +52342,7 @@ function liftWireOnlyMaterial(message3, kind) {
|
|
|
52055
52342
|
}
|
|
52056
52343
|
return {
|
|
52057
52344
|
message: {
|
|
52058
|
-
...
|
|
52345
|
+
...message4,
|
|
52059
52346
|
params: nextParams
|
|
52060
52347
|
},
|
|
52061
52348
|
lifted
|
|
@@ -52185,12 +52472,12 @@ var Protocol = class {
|
|
|
52185
52472
|
* byte-identical. User-supplied `_meta` keys are spread last so they win
|
|
52186
52473
|
* over the auto-attached envelope keys.
|
|
52187
52474
|
*/
|
|
52188
|
-
_envelopeOutbound(
|
|
52475
|
+
_envelopeOutbound(message4) {
|
|
52189
52476
|
const envelope = this._outboundMetaEnvelope();
|
|
52190
|
-
if (envelope === void 0) return
|
|
52191
|
-
const params =
|
|
52477
|
+
if (envelope === void 0) return message4;
|
|
52478
|
+
const params = message4.params ?? {};
|
|
52192
52479
|
return {
|
|
52193
|
-
...
|
|
52480
|
+
...message4,
|
|
52194
52481
|
params: {
|
|
52195
52482
|
...params,
|
|
52196
52483
|
_meta: {
|
|
@@ -52289,12 +52576,12 @@ var Protocol = class {
|
|
|
52289
52576
|
this._onerror(error42);
|
|
52290
52577
|
};
|
|
52291
52578
|
const _onmessage = this._transport?.onmessage;
|
|
52292
|
-
this._transport.onmessage = (
|
|
52293
|
-
_onmessage?.(
|
|
52294
|
-
if (isJSONRPCResultResponse(
|
|
52295
|
-
else if (isJSONRPCRequest(
|
|
52296
|
-
else if (isJSONRPCNotification(
|
|
52297
|
-
else this._onerror(/* @__PURE__ */ new Error(`Unknown message type: ${JSON.stringify(
|
|
52579
|
+
this._transport.onmessage = (message4, extra) => {
|
|
52580
|
+
_onmessage?.(message4, extra);
|
|
52581
|
+
if (isJSONRPCResultResponse(message4) || isJSONRPCErrorResponse(message4)) this._onresponse(message4);
|
|
52582
|
+
else if (isJSONRPCRequest(message4)) this._onrequest(message4, extra);
|
|
52583
|
+
else if (isJSONRPCNotification(message4)) this._onnotification(message4, extra);
|
|
52584
|
+
else this._onerror(/* @__PURE__ */ new Error(`Unknown message type: ${JSON.stringify(message4)}`));
|
|
52298
52585
|
};
|
|
52299
52586
|
transport.setSupportedProtocolVersions?.(this._supportedProtocolVersions);
|
|
52300
52587
|
await this._transport.start();
|
|
@@ -52356,13 +52643,13 @@ var Protocol = class {
|
|
|
52356
52643
|
return;
|
|
52357
52644
|
}
|
|
52358
52645
|
const capturedTransport = this._transport;
|
|
52359
|
-
const sendErrorResponse = (code,
|
|
52646
|
+
const sendErrorResponse = (code, message4, data) => {
|
|
52360
52647
|
const errorResponse = {
|
|
52361
52648
|
jsonrpc: "2.0",
|
|
52362
52649
|
id: request2.id,
|
|
52363
52650
|
error: {
|
|
52364
52651
|
code,
|
|
52365
|
-
message:
|
|
52652
|
+
message: message4,
|
|
52366
52653
|
...data !== void 0 && { data }
|
|
52367
52654
|
}
|
|
52368
52655
|
};
|
|
@@ -52956,8 +53243,8 @@ var ReadBuffer = class {
|
|
|
52956
53243
|
function deserializeMessage(line) {
|
|
52957
53244
|
return JSONRPCMessageSchema.parse(JSON.parse(line));
|
|
52958
53245
|
}
|
|
52959
|
-
function serializeMessage(
|
|
52960
|
-
return JSON.stringify(
|
|
53246
|
+
function serializeMessage(message4) {
|
|
53247
|
+
return JSON.stringify(message4) + "\n";
|
|
52961
53248
|
}
|
|
52962
53249
|
var TOOL_NAME_REGEX = /^[A-Za-z0-9._-]{1,128}$/;
|
|
52963
53250
|
function validateToolName(name) {
|
|
@@ -54208,11 +54495,11 @@ var require_errors = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
54208
54495
|
if (schemaPath) schPath = (0, codegen_1.str)`${schPath}${(0, util_1.getErrorPath)(schemaPath, util_1.Type.Str)}`;
|
|
54209
54496
|
return [E.schemaPath, schPath];
|
|
54210
54497
|
}
|
|
54211
|
-
function extraErrorProps(cxt, { params, message:
|
|
54498
|
+
function extraErrorProps(cxt, { params, message: message4 }, keyValues) {
|
|
54212
54499
|
const { keyword, data, schemaValue, it } = cxt;
|
|
54213
54500
|
const { opts, propertyName, topSchemaRef, schemaPath } = it;
|
|
54214
54501
|
keyValues.push([E.keyword, keyword], [E.params, typeof params == "function" ? params(cxt) : params || (0, codegen_1._)`{}`]);
|
|
54215
|
-
if (opts.messages) keyValues.push([E.message, typeof
|
|
54502
|
+
if (opts.messages) keyValues.push([E.message, typeof message4 == "function" ? message4(cxt) : message4]);
|
|
54216
54503
|
if (opts.verbose) keyValues.push([E.schema, schemaValue], [E.parentSchema, (0, codegen_1._)`${topSchemaRef}${schemaPath}`], [names_1.default.data, data]);
|
|
54217
54504
|
if (propertyName) keyValues.push([E.propertyName, propertyName]);
|
|
54218
54505
|
}
|
|
@@ -56536,9 +56823,9 @@ var require_core$3 = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
56536
56823
|
}
|
|
56537
56824
|
const valid = this.validate($schema, schema);
|
|
56538
56825
|
if (!valid && throwOrLogError) {
|
|
56539
|
-
const
|
|
56540
|
-
if (this.opts.validateSchema === "log") this.logger.error(
|
|
56541
|
-
else throw new Error(
|
|
56826
|
+
const message4 = "schema is invalid: " + this.errorsText();
|
|
56827
|
+
if (this.opts.validateSchema === "log") this.logger.error(message4);
|
|
56828
|
+
else throw new Error(message4);
|
|
56542
56829
|
}
|
|
56543
56830
|
return valid;
|
|
56544
56831
|
}
|
|
@@ -60078,8 +60365,8 @@ function stampSubscriptionId(notification, subscriptionId) {
|
|
|
60078
60365
|
}
|
|
60079
60366
|
};
|
|
60080
60367
|
}
|
|
60081
|
-
function parseListenFilter(
|
|
60082
|
-
const outcome = codecForVersion(MODERN_WIRE_REVISION).validateRequest("subscriptions/listen",
|
|
60368
|
+
function parseListenFilter(message4) {
|
|
60369
|
+
const outcome = codecForVersion(MODERN_WIRE_REVISION).validateRequest("subscriptions/listen", message4);
|
|
60083
60370
|
return outcome.ok ? outcome.value.params?.notifications : void 0;
|
|
60084
60371
|
}
|
|
60085
60372
|
var CHANGE_NOTIFICATION_METHODS = /* @__PURE__ */ new Set([
|
|
@@ -60134,31 +60421,31 @@ var StdioListenRouter = class {
|
|
|
60134
60421
|
* open (deliver unadvertised types); the entry guarantees capabilities are
|
|
60135
60422
|
* set before any listen request is routed here.
|
|
60136
60423
|
*/
|
|
60137
|
-
serve(
|
|
60424
|
+
serve(message4) {
|
|
60138
60425
|
if (this._serverCapabilities === void 0) throw new Error("StdioListenRouter.serve() called before setServerCapabilities(); refusing to honor a filter without capabilities");
|
|
60139
60426
|
if (this._subs.size >= this._maxSubscriptions) return {
|
|
60140
60427
|
jsonrpc: "2.0",
|
|
60141
|
-
id:
|
|
60428
|
+
id: message4.id,
|
|
60142
60429
|
error: {
|
|
60143
60430
|
code: -32603,
|
|
60144
60431
|
message: "Subscription limit reached"
|
|
60145
60432
|
}
|
|
60146
60433
|
};
|
|
60147
|
-
const filter2 = parseListenFilter(
|
|
60434
|
+
const filter2 = parseListenFilter(message4);
|
|
60148
60435
|
if (filter2 === void 0) return {
|
|
60149
60436
|
jsonrpc: "2.0",
|
|
60150
|
-
id:
|
|
60437
|
+
id: message4.id,
|
|
60151
60438
|
error: {
|
|
60152
60439
|
code: -32602,
|
|
60153
60440
|
message: "Invalid params: 'notifications' is required and must be a valid SubscriptionFilter"
|
|
60154
60441
|
}
|
|
60155
60442
|
};
|
|
60156
60443
|
const honored = honoredSubset(filter2, this._serverCapabilities);
|
|
60157
|
-
this._subs.set(
|
|
60444
|
+
this._subs.set(message4.id, honored);
|
|
60158
60445
|
return stampSubscriptionId({
|
|
60159
60446
|
method: "notifications/subscriptions/acknowledged",
|
|
60160
60447
|
params: { notifications: honored }
|
|
60161
|
-
},
|
|
60448
|
+
}, message4.id);
|
|
60162
60449
|
}
|
|
60163
60450
|
/**
|
|
60164
60451
|
* Tear down one subscription (inbound `notifications/cancelled`). Returns
|
|
@@ -60177,15 +60464,15 @@ var StdioListenRouter = class {
|
|
|
60177
60464
|
* - For any other outbound message, returns `'passthrough'` (the entry
|
|
60178
60465
|
* forwards it as-is).
|
|
60179
60466
|
*/
|
|
60180
|
-
routeOutbound(
|
|
60181
|
-
if (!CHANGE_NOTIFICATION_METHODS.has(
|
|
60182
|
-
const uriParam =
|
|
60467
|
+
routeOutbound(message4) {
|
|
60468
|
+
if (!CHANGE_NOTIFICATION_METHODS.has(message4.method)) return "passthrough";
|
|
60469
|
+
const uriParam = message4.params?.["uri"];
|
|
60183
60470
|
const uri = typeof uriParam === "string" ? uriParam : void 0;
|
|
60184
|
-
const event = notificationToServerEvent(
|
|
60471
|
+
const event = notificationToServerEvent(message4.method, uri);
|
|
60185
60472
|
const out = [];
|
|
60186
60473
|
for (const [subscriptionId, filter2] of this._subs) if (listenFilterAccepts(filter2, event)) out.push(stampSubscriptionId({
|
|
60187
|
-
method:
|
|
60188
|
-
params:
|
|
60474
|
+
method: message4.method,
|
|
60475
|
+
params: message4.params ?? {}
|
|
60189
60476
|
}, subscriptionId));
|
|
60190
60477
|
return out;
|
|
60191
60478
|
}
|
|
@@ -60262,15 +60549,15 @@ function syntheticElicitationId() {
|
|
|
60262
60549
|
const hex = [...bytes5].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
60263
60550
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
60264
60551
|
}
|
|
60265
|
-
function legacyShimFailure(method,
|
|
60552
|
+
function legacyShimFailure(method, message4) {
|
|
60266
60553
|
if (method === "tools/call") return {
|
|
60267
60554
|
content: [{
|
|
60268
60555
|
type: "text",
|
|
60269
|
-
text:
|
|
60556
|
+
text: message4
|
|
60270
60557
|
}],
|
|
60271
60558
|
isError: true
|
|
60272
60559
|
};
|
|
60273
|
-
throw new ProtocolError(ProtocolErrorCode.InternalError,
|
|
60560
|
+
throw new ProtocolError(ProtocolErrorCode.InternalError, message4);
|
|
60274
60561
|
}
|
|
60275
60562
|
var LegacyInputRequiredShim = class {
|
|
60276
60563
|
constructor(_host) {
|
|
@@ -61689,9 +61976,9 @@ var StdioServerTransport = class {
|
|
|
61689
61976
|
}
|
|
61690
61977
|
processReadBuffer() {
|
|
61691
61978
|
while (true) try {
|
|
61692
|
-
const
|
|
61693
|
-
if (
|
|
61694
|
-
this.onmessage?.(
|
|
61979
|
+
const message4 = this._readBuffer.readMessage();
|
|
61980
|
+
if (message4 === null) break;
|
|
61981
|
+
this.onmessage?.(message4);
|
|
61695
61982
|
} catch (error42) {
|
|
61696
61983
|
this.onerror?.(error42);
|
|
61697
61984
|
}
|
|
@@ -61708,10 +61995,10 @@ var StdioServerTransport = class {
|
|
|
61708
61995
|
this._readBuffer.clear();
|
|
61709
61996
|
this.onclose?.();
|
|
61710
61997
|
}
|
|
61711
|
-
send(
|
|
61998
|
+
send(message4) {
|
|
61712
61999
|
if (this._closed) return Promise.reject(/* @__PURE__ */ new Error("StdioServerTransport is closed"));
|
|
61713
62000
|
return new Promise((resolve13, reject) => {
|
|
61714
|
-
const json2 = serializeMessage(
|
|
62001
|
+
const json2 = serializeMessage(message4);
|
|
61715
62002
|
let settled = false;
|
|
61716
62003
|
const onError = (error42) => {
|
|
61717
62004
|
if (settled) return;
|
|
@@ -61753,27 +62040,27 @@ var StdioConnectionChannel = class {
|
|
|
61753
62040
|
}
|
|
61754
62041
|
async start() {
|
|
61755
62042
|
}
|
|
61756
|
-
async send(
|
|
61757
|
-
if (isJSONRPCResultResponse(
|
|
61758
|
-
const { id } =
|
|
62043
|
+
async send(message4, options) {
|
|
62044
|
+
if (isJSONRPCResultResponse(message4) || isJSONRPCErrorResponse(message4)) {
|
|
62045
|
+
const { id } = message4;
|
|
61759
62046
|
if (id !== void 0) this._settle(id);
|
|
61760
62047
|
}
|
|
61761
62048
|
if (this._closed) return;
|
|
61762
|
-
if (this._outboundIntercept?.(
|
|
61763
|
-
return this._wire.send(
|
|
62049
|
+
if (this._outboundIntercept?.(message4) === "handled") return;
|
|
62050
|
+
return this._wire.send(message4, options);
|
|
61764
62051
|
}
|
|
61765
62052
|
setProtocolVersion = (version4) => {
|
|
61766
62053
|
this._wire.setProtocolVersion?.(version4);
|
|
61767
62054
|
};
|
|
61768
62055
|
/** Forwards one inbound message to the connected instance. */
|
|
61769
|
-
deliver(
|
|
62056
|
+
deliver(message4, extra) {
|
|
61770
62057
|
if (this._closed) return;
|
|
61771
|
-
if (isJSONRPCRequest(
|
|
61772
|
-
else if (isJSONRPCNotification(
|
|
61773
|
-
const cancelledId =
|
|
62058
|
+
if (isJSONRPCRequest(message4)) this._pendingRequests.add(message4.id);
|
|
62059
|
+
else if (isJSONRPCNotification(message4) && message4.method === "notifications/cancelled") {
|
|
62060
|
+
const cancelledId = message4.params?.requestId;
|
|
61774
62061
|
if (cancelledId !== void 0) this._settle(cancelledId);
|
|
61775
62062
|
}
|
|
61776
|
-
this.onmessage?.(
|
|
62063
|
+
this.onmessage?.(message4, extra);
|
|
61777
62064
|
}
|
|
61778
62065
|
/**
|
|
61779
62066
|
* Resolves once every request delivered to the instance has been answered
|
|
@@ -61819,9 +62106,9 @@ var StdioConnectionChannel = class {
|
|
|
61819
62106
|
for (const waiter of waiters) waiter();
|
|
61820
62107
|
}
|
|
61821
62108
|
};
|
|
61822
|
-
function classifyOpeningMessage(
|
|
61823
|
-
const params =
|
|
61824
|
-
if (
|
|
62109
|
+
function classifyOpeningMessage(message4) {
|
|
62110
|
+
const params = message4.params;
|
|
62111
|
+
if (message4.method === "initialize" && !carriesValidModernEnvelopeClaim(params)) {
|
|
61825
62112
|
const requestedVersion = params !== null && typeof params === "object" && typeof params.protocolVersion === "string" ? params.protocolVersion : void 0;
|
|
61826
62113
|
return {
|
|
61827
62114
|
kind: "legacy",
|
|
@@ -61866,19 +62153,19 @@ function serveStdio(factory, options = {}) {
|
|
|
61866
62153
|
} catch {
|
|
61867
62154
|
}
|
|
61868
62155
|
};
|
|
61869
|
-
const writeErrorResponse = (id, code,
|
|
62156
|
+
const writeErrorResponse = (id, code, message4, data) => wire.send({
|
|
61870
62157
|
jsonrpc: "2.0",
|
|
61871
62158
|
id,
|
|
61872
62159
|
error: {
|
|
61873
62160
|
code,
|
|
61874
|
-
message:
|
|
62161
|
+
message: message4,
|
|
61875
62162
|
...data !== void 0 && { data }
|
|
61876
62163
|
}
|
|
61877
62164
|
}).catch((error42) => reportError(toError(error42)));
|
|
61878
62165
|
const listenRouter = new StdioListenRouter(options.maxSubscriptions ?? DEFAULT_MAX_SUBSCRIPTIONS);
|
|
61879
|
-
const modernOutboundIntercept = (
|
|
61880
|
-
if (!isJSONRPCNotification(
|
|
61881
|
-
const routed = listenRouter.routeOutbound(
|
|
62166
|
+
const modernOutboundIntercept = (message4) => {
|
|
62167
|
+
if (!isJSONRPCNotification(message4)) return void 0;
|
|
62168
|
+
const routed = listenRouter.routeOutbound(message4);
|
|
61882
62169
|
if (routed === "passthrough") return void 0;
|
|
61883
62170
|
for (const stamped of routed) wire.send({
|
|
61884
62171
|
jsonrpc: "2.0",
|
|
@@ -61886,18 +62173,18 @@ function serveStdio(factory, options = {}) {
|
|
|
61886
62173
|
}).catch((error42) => reportError(toError(error42)));
|
|
61887
62174
|
return "handled";
|
|
61888
62175
|
};
|
|
61889
|
-
const tryServeListen = async (
|
|
61890
|
-
if (isJSONRPCRequest(
|
|
61891
|
-
const meta3 = requestMetaOf(
|
|
61892
|
-
const issue4 = hasEnvelopeClaim(
|
|
62176
|
+
const tryServeListen = async (message4) => {
|
|
62177
|
+
if (isJSONRPCRequest(message4) && message4.method === "subscriptions/listen") {
|
|
62178
|
+
const meta3 = requestMetaOf(message4.params);
|
|
62179
|
+
const issue4 = hasEnvelopeClaim(message4.params) ? (meta3 === void 0 ? [] : validateEnvelopeMeta(meta3))[0] : {
|
|
61893
62180
|
key: "_meta",
|
|
61894
62181
|
problem: "the per-request envelope is required on protocol revision 2026-07-28"
|
|
61895
62182
|
};
|
|
61896
|
-
const claimedVersion = envelopeClaimVersion(
|
|
62183
|
+
const claimedVersion = envelopeClaimVersion(message4.params);
|
|
61897
62184
|
let reply4;
|
|
61898
62185
|
if (issue4 !== void 0) reply4 = {
|
|
61899
62186
|
jsonrpc: "2.0",
|
|
61900
|
-
id:
|
|
62187
|
+
id: message4.id,
|
|
61901
62188
|
error: {
|
|
61902
62189
|
code: -32602,
|
|
61903
62190
|
message: `Invalid _meta envelope: ${issue4.key}: ${issue4.problem}`
|
|
@@ -61910,14 +62197,14 @@ function serveStdio(factory, options = {}) {
|
|
|
61910
62197
|
});
|
|
61911
62198
|
reply4 = {
|
|
61912
62199
|
jsonrpc: "2.0",
|
|
61913
|
-
id:
|
|
62200
|
+
id: message4.id,
|
|
61914
62201
|
error: {
|
|
61915
62202
|
code: error42.code,
|
|
61916
62203
|
message: error42.message,
|
|
61917
62204
|
data: error42.data
|
|
61918
62205
|
}
|
|
61919
62206
|
};
|
|
61920
|
-
} else reply4 = listenRouter.serve(
|
|
62207
|
+
} else reply4 = listenRouter.serve(message4);
|
|
61921
62208
|
await wire.send("error" in reply4 ? reply4 : {
|
|
61922
62209
|
jsonrpc: "2.0",
|
|
61923
62210
|
method: reply4.method,
|
|
@@ -61925,8 +62212,8 @@ function serveStdio(factory, options = {}) {
|
|
|
61925
62212
|
}).catch((error42) => reportError(toError(error42)));
|
|
61926
62213
|
return true;
|
|
61927
62214
|
}
|
|
61928
|
-
if (isJSONRPCNotification(
|
|
61929
|
-
const cancelledId =
|
|
62215
|
+
if (isJSONRPCNotification(message4) && message4.method === "notifications/cancelled") {
|
|
62216
|
+
const cancelledId = message4.params?.requestId;
|
|
61930
62217
|
if (cancelledId !== void 0 && listenRouter.cancel(cancelledId)) return true;
|
|
61931
62218
|
}
|
|
61932
62219
|
return false;
|
|
@@ -61972,44 +62259,44 @@ function serveStdio(factory, options = {}) {
|
|
|
61972
62259
|
discarding = void 0;
|
|
61973
62260
|
}
|
|
61974
62261
|
};
|
|
61975
|
-
const processMessage = async (
|
|
62262
|
+
const processMessage = async (message4) => {
|
|
61976
62263
|
if (state.phase === "closed") return;
|
|
61977
62264
|
if (state.phase === "pinned") {
|
|
61978
|
-
if (state.era === "modern" && isJSONRPCRequest(
|
|
61979
|
-
await answerLegacyRejection(
|
|
62265
|
+
if (state.era === "modern" && isJSONRPCRequest(message4) && message4.method === "initialize" && !carriesValidModernEnvelopeClaim(message4.params)) {
|
|
62266
|
+
await answerLegacyRejection(message4, "initialize", message4.params !== null && typeof message4.params === "object" && typeof message4.params.protocolVersion === "string" ? message4.params.protocolVersion : void 0);
|
|
61980
62267
|
return;
|
|
61981
62268
|
}
|
|
61982
|
-
if (state.era === "modern" && await tryServeListen(
|
|
62269
|
+
if (state.era === "modern" && await tryServeListen(message4)) return;
|
|
61983
62270
|
if (isTornDown()) return;
|
|
61984
|
-
state.instance.channel.deliver(
|
|
62271
|
+
state.instance.channel.deliver(message4);
|
|
61985
62272
|
return;
|
|
61986
62273
|
}
|
|
61987
|
-
if (!isJSONRPCRequest(
|
|
62274
|
+
if (!isJSONRPCRequest(message4) && !isJSONRPCNotification(message4)) {
|
|
61988
62275
|
reportError(/* @__PURE__ */ new Error("Discarded a JSON-RPC response received before the connection negotiated an era"));
|
|
61989
62276
|
return;
|
|
61990
62277
|
}
|
|
61991
|
-
const opening = classifyOpeningMessage(
|
|
62278
|
+
const opening = classifyOpeningMessage(message4);
|
|
61992
62279
|
switch (opening.kind) {
|
|
61993
62280
|
case "invalid-envelope": {
|
|
61994
62281
|
const detail = `Invalid _meta envelope for protocol revision 2026-07-28: ${opening.issue.key}: ${opening.issue.problem}`;
|
|
61995
|
-
if (isJSONRPCRequest(
|
|
62282
|
+
if (isJSONRPCRequest(message4)) await writeErrorResponse(message4.id, ProtocolErrorCode.InvalidParams, detail, { envelope: opening.issue });
|
|
61996
62283
|
else reportError(/* @__PURE__ */ new Error(`Discarded a notification with a malformed envelope: ${detail}`));
|
|
61997
62284
|
return;
|
|
61998
62285
|
}
|
|
61999
62286
|
case "unsupported-revision":
|
|
62000
|
-
if (isJSONRPCRequest(
|
|
62287
|
+
if (isJSONRPCRequest(message4)) {
|
|
62001
62288
|
const error42 = new UnsupportedProtocolVersionError({
|
|
62002
62289
|
supported: [...SUPPORTED_MODERN_PROTOCOL_VERSIONS],
|
|
62003
62290
|
requested: opening.requested
|
|
62004
62291
|
});
|
|
62005
62292
|
reportError(error42);
|
|
62006
|
-
await writeErrorResponse(
|
|
62293
|
+
await writeErrorResponse(message4.id, error42.code, error42.message, error42.data);
|
|
62007
62294
|
} else reportError(/* @__PURE__ */ new Error(`Discarded a notification claiming unsupported protocol revision ${opening.requested}`));
|
|
62008
62295
|
return;
|
|
62009
62296
|
case "modern":
|
|
62010
|
-
if (isJSONRPCRequest(
|
|
62297
|
+
if (isJSONRPCRequest(message4) && message4.method === "server/discover") {
|
|
62011
62298
|
if (state.phase === "probe") {
|
|
62012
|
-
state.instance.channel.deliver(
|
|
62299
|
+
state.instance.channel.deliver(message4, { classification: opening.classification });
|
|
62013
62300
|
return;
|
|
62014
62301
|
}
|
|
62015
62302
|
const instance = await connectInstance("modern", opening.revision);
|
|
@@ -62021,12 +62308,12 @@ function serveStdio(factory, options = {}) {
|
|
|
62021
62308
|
phase: "probe",
|
|
62022
62309
|
instance
|
|
62023
62310
|
};
|
|
62024
|
-
instance.channel.deliver(
|
|
62311
|
+
instance.channel.deliver(message4, { classification: opening.classification });
|
|
62025
62312
|
return;
|
|
62026
62313
|
}
|
|
62027
62314
|
if (state.phase === "probe") {
|
|
62028
|
-
if (isJSONRPCNotification(
|
|
62029
|
-
state.instance.channel.deliver(
|
|
62315
|
+
if (isJSONRPCNotification(message4)) {
|
|
62316
|
+
state.instance.channel.deliver(message4, { classification: opening.classification });
|
|
62030
62317
|
return;
|
|
62031
62318
|
}
|
|
62032
62319
|
state = {
|
|
@@ -62046,13 +62333,13 @@ function serveStdio(factory, options = {}) {
|
|
|
62046
62333
|
instance
|
|
62047
62334
|
};
|
|
62048
62335
|
}
|
|
62049
|
-
if (await tryServeListen(
|
|
62336
|
+
if (await tryServeListen(message4)) return;
|
|
62050
62337
|
if (isTornDown()) return;
|
|
62051
|
-
state.instance.channel.deliver(
|
|
62338
|
+
state.instance.channel.deliver(message4, { classification: opening.classification });
|
|
62052
62339
|
return;
|
|
62053
62340
|
case "legacy": {
|
|
62054
62341
|
if (legacyMode === "reject") {
|
|
62055
|
-
if (isJSONRPCRequest(
|
|
62342
|
+
if (isJSONRPCRequest(message4)) await answerLegacyRejection(message4, opening.reason, opening.requestedVersion);
|
|
62056
62343
|
return;
|
|
62057
62344
|
}
|
|
62058
62345
|
if (state.phase === "probe") {
|
|
@@ -62070,7 +62357,7 @@ function serveStdio(factory, options = {}) {
|
|
|
62070
62357
|
era: "legacy",
|
|
62071
62358
|
instance
|
|
62072
62359
|
};
|
|
62073
|
-
state.instance.channel.deliver(
|
|
62360
|
+
state.instance.channel.deliver(message4);
|
|
62074
62361
|
return;
|
|
62075
62362
|
}
|
|
62076
62363
|
}
|
|
@@ -62082,11 +62369,11 @@ function serveStdio(factory, options = {}) {
|
|
|
62082
62369
|
pumping = true;
|
|
62083
62370
|
try {
|
|
62084
62371
|
while (queue.length > 0) {
|
|
62085
|
-
const
|
|
62372
|
+
const message4 = queue.shift();
|
|
62086
62373
|
try {
|
|
62087
|
-
await processMessage(
|
|
62374
|
+
await processMessage(message4);
|
|
62088
62375
|
} catch (error42) {
|
|
62089
|
-
if (isJSONRPCRequest(
|
|
62376
|
+
if (isJSONRPCRequest(message4)) await writeErrorResponse(message4.id, ProtocolErrorCode.InternalError, "Internal server error");
|
|
62090
62377
|
reportError(toError(error42));
|
|
62091
62378
|
}
|
|
62092
62379
|
}
|
|
@@ -62103,8 +62390,8 @@ function serveStdio(factory, options = {}) {
|
|
|
62103
62390
|
if (current.phase === "probe" || current.phase === "pinned") await current.instance.product.close().catch((error42) => reportError(toError(error42)));
|
|
62104
62391
|
await wire.close().catch((error42) => reportError(toError(error42)));
|
|
62105
62392
|
};
|
|
62106
|
-
wire.onmessage = (
|
|
62107
|
-
queue.push(
|
|
62393
|
+
wire.onmessage = (message4) => {
|
|
62394
|
+
queue.push(message4);
|
|
62108
62395
|
pump();
|
|
62109
62396
|
};
|
|
62110
62397
|
wire.onerror = (error42) => {
|
|
@@ -62156,8 +62443,8 @@ function installExitGuard(opts) {
|
|
|
62156
62443
|
}
|
|
62157
62444
|
|
|
62158
62445
|
// src/core/store/cleanup.ts
|
|
62159
|
-
import { existsSync as existsSync23, readdirSync as
|
|
62160
|
-
import { join as
|
|
62446
|
+
import { existsSync as existsSync23, readdirSync as readdirSync12, rmSync as rmSync8 } from "node:fs";
|
|
62447
|
+
import { join as join28 } from "node:path";
|
|
62161
62448
|
function deleteSource(raw, id) {
|
|
62162
62449
|
raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
|
|
62163
62450
|
deleteChunkRows(raw, { sourceId: id });
|
|
@@ -62213,8 +62500,8 @@ function lastAccess(raw) {
|
|
|
62213
62500
|
return row5.t;
|
|
62214
62501
|
}
|
|
62215
62502
|
function sweepOne(configDir, projectKey, cutoff) {
|
|
62216
|
-
const dir =
|
|
62217
|
-
const db = openForSweep(
|
|
62503
|
+
const dir = join28(configDir, PROJECTS_DIR_NAME, projectKey);
|
|
62504
|
+
const db = openForSweep(join28(dir, DB_FILE_NAME), projectKey);
|
|
62218
62505
|
let dead;
|
|
62219
62506
|
try {
|
|
62220
62507
|
dead = withWrite(db, (h) => listLiveOwners(configDir, projectKey).length === 0 && lastAccess(h.raw) < cutoff);
|
|
@@ -62227,7 +62514,7 @@ function sweepOne(configDir, projectKey, cutoff) {
|
|
|
62227
62514
|
function sweepDeadProjects(configDir) {
|
|
62228
62515
|
let entries;
|
|
62229
62516
|
try {
|
|
62230
|
-
entries =
|
|
62517
|
+
entries = readdirSync12(join28(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
|
|
62231
62518
|
} catch (err) {
|
|
62232
62519
|
if (err.code === "ENOENT") return [];
|
|
62233
62520
|
throw err;
|
|
@@ -62307,6 +62594,9 @@ function metaNumber(meta3, key) {
|
|
|
62307
62594
|
function sessionIdOf(meta3, agent, env, serverId) {
|
|
62308
62595
|
const fromMeta = metaString(meta3, "sessionId");
|
|
62309
62596
|
if (fromMeta !== void 0) return fromMeta;
|
|
62597
|
+
const metaKey = agent === void 0 ? void 0 : HOST_SESSION_META[agent];
|
|
62598
|
+
const fromHostMeta = metaKey === void 0 ? void 0 : metaString(meta3, metaKey);
|
|
62599
|
+
if (fromHostMeta !== void 0) return fromHostMeta;
|
|
62310
62600
|
const key = agent === void 0 ? void 0 : HOST_SESSION_ENV[agent];
|
|
62311
62601
|
const fromHost = key === void 0 ? void 0 : env[key];
|
|
62312
62602
|
if (typeof fromHost === "string" && fromHost !== "") return fromHost;
|
|
@@ -62396,7 +62686,7 @@ async function startServer(argv, env) {
|
|
|
62396
62686
|
return db;
|
|
62397
62687
|
}
|
|
62398
62688
|
function stopMarker(configDir, projectKey) {
|
|
62399
|
-
return
|
|
62689
|
+
return join29(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
|
|
62400
62690
|
}
|
|
62401
62691
|
function stopRequested() {
|
|
62402
62692
|
const configDir = resolveConfigDir(process.env);
|
|
@@ -62422,6 +62712,8 @@ async function startServer(argv, env) {
|
|
|
62422
62712
|
get project() {
|
|
62423
62713
|
return projectOf();
|
|
62424
62714
|
},
|
|
62715
|
+
...agent === void 0 ? {} : { agent },
|
|
62716
|
+
// D-1410-DOCTOR-NO-PROJECT-1
|
|
62425
62717
|
sessionId: sessionIdOf(meta3, agent, env, serverId),
|
|
62426
62718
|
turn: metaNumber(meta3, "turn") ?? 0,
|
|
62427
62719
|
signal: req.mcpReq.signal,
|