context-mode 2.2.0 → 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 +75 -75
- package/SHA256SUMS +17 -17
- package/cli.mjs +29 -15
- 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 +876 -436
- package/package.json +1 -1
- package/pi/index.js +1041 -584
- package/qwen-extension.json +1 -1
- package/run.mjs +92 -30
- package/search.mjs +92 -30
- package/server.mjs +291 -101
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,9 +11343,17 @@ 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";
|
|
11353
|
+
var DB_LINK_DENIED_CODES = ["EACCES", "EPERM", "ENOSYS", "ENOTSUP", "EOPNOTSUPP"];
|
|
11354
|
+
var DB_PUBLISH_CLAIM_SUFFIX = ".publish";
|
|
11355
|
+
var DB_CLAIM_BUSY_CODES = ["EEXIST", "EPERM"];
|
|
11356
|
+
var DB_PUBLISH_POLL_MS = 5;
|
|
11345
11357
|
var SQLITE_PRIMARY_CODE_MASK = 255;
|
|
11346
11358
|
var SQLITE_CORRUPT_CODE = 11;
|
|
11347
11359
|
var SQLITE_NOTADB_CODE = 26;
|
|
@@ -11381,6 +11393,7 @@ var SEARCH_WRAPPER_FILE = "search.mjs";
|
|
|
11381
11393
|
var RUN_WRAPPER_AGENT = "claude-code";
|
|
11382
11394
|
var RUN_SESSION_PREFIX = "mcp:";
|
|
11383
11395
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
11396
|
+
var HOST_SESSION_META = Object.freeze({ zcode: "session_id" });
|
|
11384
11397
|
var NODE_MIN = "24.15.0";
|
|
11385
11398
|
var DATA_ROOT = "~/.context-mode";
|
|
11386
11399
|
var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
|
|
@@ -11405,6 +11418,7 @@ var FRONTMATTER_FENCE = "---";
|
|
|
11405
11418
|
var FRONTMATTER_TOOLS_KEY = "tools";
|
|
11406
11419
|
var FRONTMATTER_DISALLOWED_KEY = "disallowedTools";
|
|
11407
11420
|
var MCP_SERVER_TOOL_PREFIX = "mcp__";
|
|
11421
|
+
var PLUGIN_CALL_ID_PREFIX = "toolu_plugin_";
|
|
11408
11422
|
var MCP_NAME_JOIN = "__";
|
|
11409
11423
|
var GEMINI_MCP_PREFIX = "mcp_";
|
|
11410
11424
|
var GEMINI_NAME_EXTRA_CHARS = "_-.:";
|
|
@@ -11626,7 +11640,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
11626
11640
|
var DECISION_OPTION_KEY = "option";
|
|
11627
11641
|
var DECISION_LABEL_JOIN = " | ";
|
|
11628
11642
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
11629
|
-
var BUNDLE_SHA = true ? "
|
|
11643
|
+
var BUNDLE_SHA = true ? "ae2e1bb106e462a19ab3c042e371cd8a7f691074" : void 0;
|
|
11630
11644
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
11631
11645
|
var DOCTOR_LABEL = Object.freeze({
|
|
11632
11646
|
D1: "version",
|
|
@@ -11737,6 +11751,10 @@ function D7_DETAIL(got) {
|
|
|
11737
11751
|
return `resolved project source ${got} does not match the host's actual cwd`;
|
|
11738
11752
|
}
|
|
11739
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";
|
|
11740
11758
|
function D8_STALE_SCHEMA_DETAIL(got, want) {
|
|
11741
11759
|
return `stale schema (v${got}, expected v${want})`;
|
|
11742
11760
|
}
|
|
@@ -12418,7 +12436,7 @@ var CtxError = class extends Error {
|
|
|
12418
12436
|
};
|
|
12419
12437
|
|
|
12420
12438
|
// src/core/hooks/dispatch.ts
|
|
12421
|
-
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";
|
|
12422
12440
|
|
|
12423
12441
|
// src/core/contracts/agents.ts
|
|
12424
12442
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode", "omp"];
|
|
@@ -12429,6 +12447,7 @@ var SHELL_TOOL_NAMES = Object.freeze(["Bash", "PowerShell"]);
|
|
|
12429
12447
|
var POWERSHELL_TOOL = "PowerShell";
|
|
12430
12448
|
var SHELL_CANONICAL = "Bash";
|
|
12431
12449
|
var CLAUDE_SHAPE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse"];
|
|
12450
|
+
var FAILURE_EVENT = "PostToolUseFailure";
|
|
12432
12451
|
var MCP_PREFIX = "mcp__";
|
|
12433
12452
|
var MCP_SEP = "__";
|
|
12434
12453
|
var CLAUDE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
@@ -12602,7 +12621,14 @@ function requireFields(raw) {
|
|
|
12602
12621
|
}
|
|
12603
12622
|
function decode2(raw) {
|
|
12604
12623
|
requireFields(raw);
|
|
12605
|
-
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
|
+
}
|
|
12606
12632
|
if (ev.tool !== void 0 && ev.tool.name === POWERSHELL_TOOL) ev.tool.canonicalName = SHELL_CANONICAL;
|
|
12607
12633
|
if (ev.cwd === "") ev.cwd = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
12608
12634
|
if (ev.event === "PostToolUse" && ev.tool !== void 0 && ev.tool.callId === void 0) {
|
|
@@ -12781,9 +12807,9 @@ var NATIVE_TO_CANONICAL3 = {
|
|
|
12781
12807
|
grep_search: "Grep",
|
|
12782
12808
|
web_fetch: "WebFetch"
|
|
12783
12809
|
};
|
|
12784
|
-
var
|
|
12810
|
+
var FAILURE_EVENT2 = "PostToolUseFailure";
|
|
12785
12811
|
function decode5(raw) {
|
|
12786
|
-
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;
|
|
12787
12813
|
const payload = failure3 ? { ...raw, hook_event_name: "PostToolUse" } : raw;
|
|
12788
12814
|
const ev = decodeClaudeShape(payload, "qwen", TOOL_NAME_PREFIX5, QWEN_SOURCES);
|
|
12789
12815
|
if (ev.tool !== void 0 && Object.hasOwn(NATIVE_TO_CANONICAL3, ev.tool.name)) ev.tool.canonicalName = NATIVE_TO_CANONICAL3[ev.tool.name];
|
|
@@ -13103,12 +13129,12 @@ var TOOL_NAME_PREFIX9 = "mcp__context-mode__";
|
|
|
13103
13129
|
var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
13104
13130
|
var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
13105
13131
|
var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
|
|
13106
|
-
var
|
|
13132
|
+
var FAILURE_EVENT3 = "PostToolUseFailure";
|
|
13107
13133
|
function decode9(raw) {
|
|
13108
13134
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("zcode: hook payload is not a JSON object");
|
|
13109
13135
|
const p = { ...raw };
|
|
13110
13136
|
for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
|
|
13111
|
-
const failure3 = p.hook_event_name ===
|
|
13137
|
+
const failure3 = p.hook_event_name === FAILURE_EVENT3;
|
|
13112
13138
|
if (failure3) p.hook_event_name = "PostToolUse";
|
|
13113
13139
|
const toolName2 = typeof p.tool_name === "string" ? p.tool_name : "";
|
|
13114
13140
|
const prefix = toolName2.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX9;
|
|
@@ -13137,7 +13163,8 @@ var OPENCODE_EVENTS = {
|
|
|
13137
13163
|
var SHELL_TOOL_NAME = "bash";
|
|
13138
13164
|
var READ_TOOL_NAME = "read";
|
|
13139
13165
|
var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
13140
|
-
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"])) };
|
|
13141
13168
|
function toCanonicalTool(name) {
|
|
13142
13169
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
13143
13170
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
|
|
@@ -14886,8 +14913,12 @@ var CC_READ_ONLY_DENY = Object.freeze(["Agent", "Artifact", "ArtifactComments",
|
|
|
14886
14913
|
var CLAUDE_CODE_BUILT_INS = Object.freeze({
|
|
14887
14914
|
"general-purpose": { tools: null, disallowed: [] },
|
|
14888
14915
|
fork: { tools: null, disallowed: [] },
|
|
14916
|
+
claude: { tools: null, disallowed: [] },
|
|
14889
14917
|
Explore: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
|
|
14890
|
-
Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] }
|
|
14918
|
+
Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
|
|
14919
|
+
"claude-code-guide": { tools: ["Glob", "Grep", "Read", "WebFetch", "WebSearch"], disallowed: [] },
|
|
14920
|
+
"statusline-setup": { tools: ["Read", "Edit"], disallowed: [] },
|
|
14921
|
+
"web-fetch": { tools: ["WebFetch"], disallowed: [] }
|
|
14891
14922
|
});
|
|
14892
14923
|
var BUILT_IN_AGENT = "claude-code";
|
|
14893
14924
|
function isSubagentCall(ev) {
|
|
@@ -15088,13 +15119,15 @@ function unique(names) {
|
|
|
15088
15119
|
// src/core/policy/unwrap.ts
|
|
15089
15120
|
var NONE = "";
|
|
15090
15121
|
var WRAPPERS = Object.freeze({
|
|
15091
|
-
sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE },
|
|
15092
|
-
env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE },
|
|
15093
|
-
time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE },
|
|
15094
|
-
nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE },
|
|
15095
|
-
timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE },
|
|
15096
|
-
command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV" },
|
|
15097
|
-
xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE }
|
|
15122
|
+
sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
15123
|
+
env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
15124
|
+
time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
15125
|
+
nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
15126
|
+
timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE, subcommands: [] },
|
|
15127
|
+
command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV", subcommands: [] },
|
|
15128
|
+
xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
15129
|
+
// #1388: rtk (rtk-ai/rtk) runs the inner command as-is under `proxy` / `bypass`; its other subcommands are rtk's own.
|
|
15130
|
+
rtk: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: NONE, subcommands: ["proxy", "bypass"] }
|
|
15098
15131
|
});
|
|
15099
15132
|
var SHELLS = ["bash", "sh", "zsh"];
|
|
15100
15133
|
var SCRIPT_FLAG = "c";
|
|
@@ -15117,6 +15150,10 @@ function isDuration(s) {
|
|
|
15117
15150
|
}
|
|
15118
15151
|
function peel(w, args) {
|
|
15119
15152
|
let k = 0;
|
|
15153
|
+
if (w.subcommands.length > 0) {
|
|
15154
|
+
if (args.length === 0 || !w.subcommands.includes(args[0])) return null;
|
|
15155
|
+
k = 1;
|
|
15156
|
+
}
|
|
15120
15157
|
while (k < args.length) {
|
|
15121
15158
|
const a = args[k];
|
|
15122
15159
|
if (a === LONG_OPT2) {
|
|
@@ -15870,7 +15907,7 @@ function dumpTarget(name, args) {
|
|
|
15870
15907
|
}
|
|
15871
15908
|
|
|
15872
15909
|
// src/core/project/resolve.ts
|
|
15873
|
-
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";
|
|
15874
15911
|
|
|
15875
15912
|
// src/core/project/sha256.ts
|
|
15876
15913
|
var K = new Uint32Array([
|
|
@@ -16025,12 +16062,7 @@ function dirOf(kind, src) {
|
|
|
16025
16062
|
}
|
|
16026
16063
|
}
|
|
16027
16064
|
function gitDirs(dir) {
|
|
16028
|
-
let cur;
|
|
16029
|
-
try {
|
|
16030
|
-
cur = realpathSync3.native(dir);
|
|
16031
|
-
} catch {
|
|
16032
|
-
throw new CtxError("NO_GIT_DIR", { path: dir });
|
|
16033
|
-
}
|
|
16065
|
+
let cur = nearestRealDir(dir);
|
|
16034
16066
|
const start = cur;
|
|
16035
16067
|
for (; ; ) {
|
|
16036
16068
|
const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
|
|
@@ -16043,6 +16075,18 @@ function gitDirs(dir) {
|
|
|
16043
16075
|
cur = up;
|
|
16044
16076
|
}
|
|
16045
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
|
+
}
|
|
16046
16090
|
function gitDirAt(dotGit) {
|
|
16047
16091
|
let gitDir;
|
|
16048
16092
|
try {
|
|
@@ -16105,7 +16149,7 @@ function resolveProject(agent, src) {
|
|
|
16105
16149
|
},
|
|
16106
16150
|
worktree,
|
|
16107
16151
|
get containmentRoot() {
|
|
16108
|
-
root ??= plain ?? containmentRootOf(
|
|
16152
|
+
root ??= plain ?? containmentRootOf(worktree, commonDir);
|
|
16109
16153
|
return root;
|
|
16110
16154
|
},
|
|
16111
16155
|
agent,
|
|
@@ -16252,7 +16296,7 @@ function openReadOnlyHandle(sqlite, path8, opts = {}) {
|
|
|
16252
16296
|
}
|
|
16253
16297
|
|
|
16254
16298
|
// src/core/store/db.ts
|
|
16255
|
-
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
16299
|
+
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, renameSync, rmSync, statSync: statSync3 } = process.getBuiltinModule("node:fs");
|
|
16256
16300
|
function versionParts(v) {
|
|
16257
16301
|
const bare2 = v.startsWith("v") ? v.slice(1) : v;
|
|
16258
16302
|
return bare2.split(".").map((p) => Number.parseInt(p, 10));
|
|
@@ -16284,6 +16328,34 @@ function readUserVersion(raw) {
|
|
|
16284
16328
|
const row5 = raw.prepare("PRAGMA user_version").get();
|
|
16285
16329
|
return row5.user_version;
|
|
16286
16330
|
}
|
|
16331
|
+
function errCode(err) {
|
|
16332
|
+
return err.code ?? "";
|
|
16333
|
+
}
|
|
16334
|
+
function publishWithoutLink(tmp, path8) {
|
|
16335
|
+
const claim4 = path8 + DB_PUBLISH_CLAIM_SUFFIX;
|
|
16336
|
+
const start = Date.now();
|
|
16337
|
+
for (; ; ) {
|
|
16338
|
+
if (existsSync3(path8)) return;
|
|
16339
|
+
try {
|
|
16340
|
+
mkdirSync2(claim4);
|
|
16341
|
+
} catch (err) {
|
|
16342
|
+
if (!DB_CLAIM_BUSY_CODES.includes(errCode(err))) throw err;
|
|
16343
|
+
if (Date.now() - start < DB_TIMEOUT_MS) {
|
|
16344
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, DB_PUBLISH_POLL_MS);
|
|
16345
|
+
continue;
|
|
16346
|
+
}
|
|
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`);
|
|
16350
|
+
}
|
|
16351
|
+
try {
|
|
16352
|
+
if (!existsSync3(path8)) renameSync(tmp, path8);
|
|
16353
|
+
} finally {
|
|
16354
|
+
rmSync(claim4, { recursive: true, force: true });
|
|
16355
|
+
}
|
|
16356
|
+
return;
|
|
16357
|
+
}
|
|
16358
|
+
}
|
|
16287
16359
|
function createAtomically(sqlite, path8) {
|
|
16288
16360
|
const { randomUUID: randomUUID2 } = process.getBuiltinModule("node:crypto");
|
|
16289
16361
|
const tmp = path8 + "." + randomUUID2() + DB_TMP_SUFFIX;
|
|
@@ -16297,7 +16369,9 @@ function createAtomically(sqlite, path8) {
|
|
|
16297
16369
|
try {
|
|
16298
16370
|
linkSync(tmp, path8);
|
|
16299
16371
|
} catch (err) {
|
|
16300
|
-
|
|
16372
|
+
const code = errCode(err);
|
|
16373
|
+
if (DB_LINK_DENIED_CODES.includes(code)) publishWithoutLink(tmp, path8);
|
|
16374
|
+
else if (code !== "EEXIST") throw err;
|
|
16301
16375
|
}
|
|
16302
16376
|
} finally {
|
|
16303
16377
|
for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
|
|
@@ -16396,9 +16470,9 @@ var COLUMNS = "events(session_id, worktree, agent, kind, tool, key, path, ok, ex
|
|
|
16396
16470
|
var INSERT_SQL = "INSERT INTO " + COLUMNS;
|
|
16397
16471
|
var INSERT_COST_SQL = "INSERT OR IGNORE INTO " + COLUMNS;
|
|
16398
16472
|
var COST_SEQ_SQL = "SELECT seq FROM events WHERE kind = 'cost' AND session_id = ? AND turn = ?";
|
|
16399
|
-
function appendEvent(db, row5) {
|
|
16473
|
+
function appendEvent(db, row5, at2) {
|
|
16400
16474
|
return withWrite(db, (h) => {
|
|
16401
|
-
const now = Date.now();
|
|
16475
|
+
const now = at2 ?? Date.now();
|
|
16402
16476
|
const isCost = row5.kind === "cost";
|
|
16403
16477
|
const res = h.raw.prepare(isCost ? INSERT_COST_SQL : INSERT_SQL).run(
|
|
16404
16478
|
row5.session_id,
|
|
@@ -16488,9 +16562,15 @@ function readLastPrompt(db, sessionId) {
|
|
|
16488
16562
|
const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq DESC LIMIT 1").get(sessionId);
|
|
16489
16563
|
return row5 === void 0 ? "" : row5.body;
|
|
16490
16564
|
}
|
|
16491
|
-
function readRecallRows(db, sessionId, worktree, limit) {
|
|
16565
|
+
function readRecallRows(db, sessionId, worktree, limit, maxSeq = Number.MAX_SAFE_INTEGER) {
|
|
16492
16566
|
if (sessionId === "") return [];
|
|
16493
|
-
return db.raw.prepare(
|
|
16567
|
+
return db.raw.prepare(
|
|
16568
|
+
"SELECT * FROM events WHERE kind <> 'cost' AND ((session_id = ? AND seq <= ?) OR (worktree = ? AND session_id <> ?)) ORDER BY seq DESC LIMIT ?"
|
|
16569
|
+
).all(sessionId, maxSeq, worktree, sessionId, limit);
|
|
16570
|
+
}
|
|
16571
|
+
function readMaxSeq(db) {
|
|
16572
|
+
const row5 = db.raw.prepare("SELECT COALESCE(MAX(seq), 0) AS n FROM events").get();
|
|
16573
|
+
return Number(row5.n);
|
|
16494
16574
|
}
|
|
16495
16575
|
function hasAgentRows(db, worktree, agent) {
|
|
16496
16576
|
return db.raw.prepare("SELECT 1 FROM events WHERE worktree = ? AND agent = ? LIMIT 1").get(worktree, agent) !== void 0;
|
|
@@ -16498,6 +16578,10 @@ function hasAgentRows(db, worktree, agent) {
|
|
|
16498
16578
|
function hasSessionRows(db, sessionId) {
|
|
16499
16579
|
return db.raw.prepare("SELECT 1 FROM events WHERE session_id = ? LIMIT 1").get(sessionId) !== void 0;
|
|
16500
16580
|
}
|
|
16581
|
+
function lastSessionSeq(db, sessionId) {
|
|
16582
|
+
const row5 = db.raw.prepare("SELECT MAX(seq) AS m FROM events WHERE session_id = ?").get(sessionId);
|
|
16583
|
+
return row5?.m ?? 0;
|
|
16584
|
+
}
|
|
16501
16585
|
|
|
16502
16586
|
// src/core/store/snippet.ts
|
|
16503
16587
|
var K1 = 1.2;
|
|
@@ -18494,18 +18578,6 @@ function reserveSource(db, src, chunks) {
|
|
|
18494
18578
|
return Number(row5.id);
|
|
18495
18579
|
});
|
|
18496
18580
|
}
|
|
18497
|
-
function finishReserved(db, id, src, chunks, units) {
|
|
18498
|
-
try {
|
|
18499
|
-
insertChunks(db, id, src, chunks);
|
|
18500
|
-
insertUnits(db, id, src.sessionId, units);
|
|
18501
|
-
} catch (err) {
|
|
18502
|
-
withWrite(db, (h) => {
|
|
18503
|
-
deleteChunkRows(h.raw, { sourceId: id });
|
|
18504
|
-
h.raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
|
|
18505
|
-
});
|
|
18506
|
-
throw err;
|
|
18507
|
-
}
|
|
18508
|
-
}
|
|
18509
18581
|
function insertChunks(db, id, src, chunks) {
|
|
18510
18582
|
const batches = [];
|
|
18511
18583
|
let batch = [];
|
|
@@ -18944,43 +19016,53 @@ function parseSourceHandle(s) {
|
|
|
18944
19016
|
function pathLabel(p) {
|
|
18945
19017
|
return p.includes("\\") ? p.split("\\").join("/") : p;
|
|
18946
19018
|
}
|
|
18947
|
-
|
|
18948
|
-
|
|
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;
|
|
18949
19024
|
}
|
|
18950
|
-
function storedLabel(db, source) {
|
|
18951
|
-
if (labelStored(db, source)) return source;
|
|
19025
|
+
function storedLabel(db, source, w = EVERY_ROW) {
|
|
19026
|
+
if (labelStored(db, source, w)) return source;
|
|
18952
19027
|
const canon = pathLabel(source);
|
|
18953
|
-
return canon !== source && labelStored(db, canon) ? canon : source;
|
|
19028
|
+
return canon !== source && labelStored(db, canon, w) ? canon : source;
|
|
18954
19029
|
}
|
|
18955
|
-
function newestId(db, label2) {
|
|
18956
|
-
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) });
|
|
18957
19032
|
return row5 === void 0 ? null : Number(row5.id);
|
|
18958
19033
|
}
|
|
18959
|
-
function labelOfId(db, id) {
|
|
18960
|
-
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) });
|
|
18961
19036
|
return row5 === void 0 ? null : row5.label;
|
|
18962
19037
|
}
|
|
18963
|
-
function
|
|
18964
|
-
const named2 = storedLabel(db, source);
|
|
19038
|
+
function pickIn(db, source, suffix, w) {
|
|
19039
|
+
const named2 = storedLabel(db, source, w);
|
|
18965
19040
|
const id = parseSourceHandle(source);
|
|
18966
|
-
const own4 = newestId(db, named2);
|
|
19041
|
+
const own4 = newestId(db, named2, w);
|
|
18967
19042
|
if (own4 !== null) {
|
|
18968
|
-
const otherLabel = id === null || id === own4 ? null : labelOfId(db, id);
|
|
19043
|
+
const otherLabel = id === null || id === own4 ? null : labelOfId(db, id, EVERY_ROW);
|
|
18969
19044
|
return { label: named2, id: own4, via: "label", other: otherLabel === null || otherLabel === named2 ? null : { id, label: otherLabel } };
|
|
18970
19045
|
}
|
|
18971
19046
|
if (id !== null) {
|
|
18972
|
-
const label2 = labelOfId(db, id);
|
|
19047
|
+
const label2 = labelOfId(db, id, w);
|
|
18973
19048
|
if (label2 !== null) return { label: label2, id, via: "handle", other: null };
|
|
18974
19049
|
}
|
|
18975
19050
|
if (suffix) {
|
|
18976
19051
|
const prefix = named2 + LABEL_SUFFIX_SEP;
|
|
18977
|
-
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) });
|
|
18978
19053
|
for (const r of rows) {
|
|
18979
19054
|
if (r.label.lastIndexOf(LABEL_SUFFIX_SEP) === named2.length) return { label: r.label, id: Number(r.id), via: "suffix", other: null };
|
|
18980
19055
|
}
|
|
18981
19056
|
}
|
|
18982
19057
|
return { label: source, id: null, via: "none", other: null };
|
|
18983
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
|
+
}
|
|
18984
19066
|
function collisionLine(value, pick4) {
|
|
18985
19067
|
if (pick4.other === null || pick4.id === null) return null;
|
|
18986
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) + ".");
|
|
@@ -19075,51 +19157,26 @@ function recallQueryText(prompt) {
|
|
|
19075
19157
|
if (cur !== "" && kept.size < RECALL_QUERY_MAX_TERMS) add(cur);
|
|
19076
19158
|
return [...kept.size > 0 ? kept : all].join(" ");
|
|
19077
19159
|
}
|
|
19078
|
-
function
|
|
19160
|
+
function readMaxSourceId(db) {
|
|
19161
|
+
const row5 = db.raw.prepare("SELECT COALESCE(MAX(id), 0) AS n FROM sources").get();
|
|
19162
|
+
return Number(row5.n);
|
|
19163
|
+
}
|
|
19164
|
+
function queryUnits(db, sessionId, q, limit, maxSourceId = Number.MAX_SAFE_INTEGER) {
|
|
19079
19165
|
const match = searchTerms(q).join(" OR ");
|
|
19080
19166
|
if (match === "" || sessionId === "") return [];
|
|
19081
19167
|
const rows = db.raw.prepare(
|
|
19082
|
-
"SELECT u.source_id AS source_id, u.ord AS ord, u.body AS body, -bm25(line_units) AS score, s.label AS label FROM line_units u JOIN sources s ON s.id = u.source_id WHERE line_units MATCH ? AND u.session_id = ? ORDER BY bm25(line_units) LIMIT ?"
|
|
19083
|
-
).all(match, sessionId, limit);
|
|
19168
|
+
"SELECT u.source_id AS source_id, u.ord AS ord, u.body AS body, -bm25(line_units) AS score, s.label AS label FROM line_units u JOIN sources s ON s.id = u.source_id WHERE line_units MATCH ? AND u.session_id = ? AND s.id <= ? ORDER BY bm25(line_units) LIMIT ?"
|
|
19169
|
+
).all(match, sessionId, maxSourceId, limit);
|
|
19084
19170
|
return rows.map((r) => ({ sourceId: Number(r.source_id), ord: Number(r.ord), label: r.label, body: r.body, score: r.score }));
|
|
19085
19171
|
}
|
|
19086
19172
|
|
|
19087
|
-
// src/core/index/units.ts
|
|
19088
|
-
function indentOf(line) {
|
|
19089
|
-
let n = 0;
|
|
19090
|
-
while (n < line.length && (line[n] === " " || line[n] === " ")) n++;
|
|
19091
|
-
return n;
|
|
19092
|
-
}
|
|
19093
|
-
function buildUnits(text) {
|
|
19094
|
-
const lines = text.split("\n");
|
|
19095
|
-
const stack2 = [];
|
|
19096
|
-
const out = [];
|
|
19097
|
-
let left = UNITS_ANCESTOR_FACTOR * Buffer.byteLength(text, "utf8");
|
|
19098
|
-
for (let i = 0; i < lines.length; i++) {
|
|
19099
|
-
const line = lines[i].endsWith("\r") ? lines[i].slice(0, -1) : lines[i];
|
|
19100
|
-
const indent = indentOf(line);
|
|
19101
|
-
if (indent === line.length) continue;
|
|
19102
|
-
while (stack2.length > 0 && stack2[stack2.length - 1].indent >= indent) stack2.pop();
|
|
19103
|
-
const bytes5 = Buffer.byteLength(line, "utf8");
|
|
19104
|
-
let size = bytes5;
|
|
19105
|
-
let from = stack2.length;
|
|
19106
|
-
while (from > 0) {
|
|
19107
|
-
const add = stack2[from - 1].bytes + 1;
|
|
19108
|
-
if (size + add > RECALL_BUDGET_BYTES || size - bytes5 + add > left) break;
|
|
19109
|
-
size += add;
|
|
19110
|
-
from--;
|
|
19111
|
-
}
|
|
19112
|
-
left -= size - bytes5;
|
|
19113
|
-
out.push({ ord: i, body: [...stack2.slice(from).map((s) => s.line), line].join("\n") });
|
|
19114
|
-
stack2.push({ indent, line, bytes: bytes5 });
|
|
19115
|
-
}
|
|
19116
|
-
return out;
|
|
19117
|
-
}
|
|
19118
|
-
|
|
19119
19173
|
// src/core/compaction/candidates.ts
|
|
19120
19174
|
function firstLine2(body) {
|
|
19121
|
-
const
|
|
19122
|
-
|
|
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", " ");
|
|
19123
19180
|
}
|
|
19124
19181
|
function make(section, row5, text, repeatCount, query) {
|
|
19125
19182
|
const bytes5 = Buffer.byteLength(text, "utf8");
|
|
@@ -19662,7 +19719,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
19662
19719
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
19663
19720
|
return { end: start + r.read, written: r.written };
|
|
19664
19721
|
}
|
|
19665
|
-
function merge2(src, blocks,
|
|
19722
|
+
function merge2(src, blocks, join30, cap, lineCut) {
|
|
19666
19723
|
const out = [];
|
|
19667
19724
|
const scratch = new Uint8Array(cap);
|
|
19668
19725
|
let wide;
|
|
@@ -19672,7 +19729,7 @@ function merge2(src, blocks, join29, cap, lineCut) {
|
|
|
19672
19729
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
19673
19730
|
};
|
|
19674
19731
|
for (const b of blocks) {
|
|
19675
|
-
if (cur !== void 0 && !
|
|
19732
|
+
if (cur !== void 0 && !join30) {
|
|
19676
19733
|
emit(cur.start, cur.end, curBytes);
|
|
19677
19734
|
cur = void 0;
|
|
19678
19735
|
}
|
|
@@ -19993,37 +20050,204 @@ function lineShape(text) {
|
|
|
19993
20050
|
return { header, units };
|
|
19994
20051
|
}
|
|
19995
20052
|
|
|
19996
|
-
// src/core/
|
|
19997
|
-
|
|
19998
|
-
|
|
19999
|
-
|
|
20000
|
-
|
|
20001
|
-
|
|
20002
|
-
|
|
20003
|
-
|
|
20004
|
-
label: label2,
|
|
20005
|
-
bytes: Buffer.byteLength(text, "utf8"),
|
|
20006
|
-
chunkCount: chunks.length,
|
|
20007
|
-
createdAt: Date.now()
|
|
20008
|
-
}, chunks);
|
|
20009
|
-
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;
|
|
20010
20061
|
}
|
|
20011
|
-
function
|
|
20012
|
-
|
|
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;
|
|
20013
20086
|
}
|
|
20014
20087
|
|
|
20015
|
-
// src/core/hooks/
|
|
20016
|
-
|
|
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
|
+
}
|
|
20017
20139
|
try {
|
|
20018
|
-
|
|
20019
|
-
|
|
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);
|
|
20020
20157
|
} catch (err) {
|
|
20021
|
-
|
|
20022
|
-
|
|
20158
|
+
if (!isBusy(err)) throw err;
|
|
20159
|
+
spool(project, cur.op);
|
|
20160
|
+
return cur.op.t === "src" ? cur.op.id : null;
|
|
20023
20161
|
}
|
|
20024
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;
|
|
20201
|
+
}
|
|
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
|
|
20025
20249
|
function appendDetached(project, sessionId, row5) {
|
|
20026
|
-
|
|
20250
|
+
writeDetached(project, { t: "row", row: row5, at: Date.now() }, "journal");
|
|
20027
20251
|
}
|
|
20028
20252
|
|
|
20029
20253
|
// src/core/hooks/handle-query.ts
|
|
@@ -20114,7 +20338,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
20114
20338
|
}
|
|
20115
20339
|
|
|
20116
20340
|
// src/core/hooks/fallback.ts
|
|
20117
|
-
import { join as
|
|
20341
|
+
import { join as join8, resolve as resolve7 } from "node:path";
|
|
20118
20342
|
var fs = process.getBuiltinModule("node:fs");
|
|
20119
20343
|
function isRec(v) {
|
|
20120
20344
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -20142,9 +20366,9 @@ function homeOf(env) {
|
|
|
20142
20366
|
}
|
|
20143
20367
|
function hookLogPath(env) {
|
|
20144
20368
|
const dir = env[DATA_DIR_ENV];
|
|
20145
|
-
if (dir !== void 0 && dir !== "") return
|
|
20369
|
+
if (dir !== void 0 && dir !== "") return join8(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
|
|
20146
20370
|
const home = homeOf(env);
|
|
20147
|
-
return home === "" ? "" :
|
|
20371
|
+
return home === "" ? "" : join8(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
|
|
20148
20372
|
}
|
|
20149
20373
|
function errorLabel(err) {
|
|
20150
20374
|
const code = isRec(err) ? err.code : void 0;
|
|
@@ -20155,7 +20379,7 @@ function logHookError(env, agent, stage, err) {
|
|
|
20155
20379
|
try {
|
|
20156
20380
|
const file2 = hookLogPath(env);
|
|
20157
20381
|
if (file2 === "") return;
|
|
20158
|
-
fs.mkdirSync(
|
|
20382
|
+
fs.mkdirSync(join8(file2, ".."), { recursive: true });
|
|
20159
20383
|
const line = JSON.stringify({
|
|
20160
20384
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
20161
20385
|
agent,
|
|
@@ -20269,14 +20493,14 @@ function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
|
20269
20493
|
var { read: read2, writeSync } = process.getBuiltinModule("node:fs");
|
|
20270
20494
|
|
|
20271
20495
|
// src/core/hooks/dispatch.ts
|
|
20272
|
-
var { lstatSync: lstatSync2, readFileSync:
|
|
20496
|
+
var { lstatSync: lstatSync2, readFileSync: readFileSync6 } = process.getBuiltinModule("node:fs");
|
|
20273
20497
|
var ALLOW2 = { kind: "allow" };
|
|
20274
20498
|
var EMPTY5 = { stdout: "", exitCode: 0 };
|
|
20275
20499
|
var DIGIT_0 = 48;
|
|
20276
20500
|
function isAgentId(s) {
|
|
20277
20501
|
return AGENT_IDS.includes(s);
|
|
20278
20502
|
}
|
|
20279
|
-
function
|
|
20503
|
+
function message2(err) {
|
|
20280
20504
|
return err instanceof Error ? err.message : String(err);
|
|
20281
20505
|
}
|
|
20282
20506
|
function str2(v) {
|
|
@@ -20290,7 +20514,7 @@ async function handleHook(agent, raw, env) {
|
|
|
20290
20514
|
const row5 = getAdapter(agent);
|
|
20291
20515
|
const report2 = (stage, err, line) => {
|
|
20292
20516
|
logHookError(env, agent, stage, err);
|
|
20293
|
-
process.stderr.write(line ?? "hooks: " + stage + " failed: " +
|
|
20517
|
+
process.stderr.write(line ?? "hooks: " + stage + " failed: " + message2(err) + "\n");
|
|
20294
20518
|
};
|
|
20295
20519
|
const fail7 = (stage, err, line) => {
|
|
20296
20520
|
report2(stage, err, line);
|
|
@@ -20316,7 +20540,7 @@ async function handleHook(agent, raw, env) {
|
|
|
20316
20540
|
const argv = agent === "vscode" ? [WORKSPACE_FOLDER_FLAG, ev.cwd] : process.argv;
|
|
20317
20541
|
project = resolveProject(agent, { env, argv, cwd: ev.cwd, piCwd: getAdapter(agent).projectSource === "pi:ctx.cwd" ? ev.cwd : void 0 });
|
|
20318
20542
|
} catch (err) {
|
|
20319
|
-
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");
|
|
20320
20544
|
}
|
|
20321
20545
|
let decision;
|
|
20322
20546
|
const settle3 = {};
|
|
@@ -20361,13 +20585,14 @@ function compactText(db, ev, row5) {
|
|
|
20361
20585
|
return renderState(readSessionEvents(db, ev.sessionId), ev.turn ?? 0, void 0, row5.toolNamePrefix);
|
|
20362
20586
|
}
|
|
20363
20587
|
async function sessionStart(ev, row5, project) {
|
|
20364
|
-
if (ev.source === "compact" && hasRecall(row5)) markCompacted(await
|
|
20588
|
+
if (ev.source === "compact" && hasRecall(row5)) markCompacted(await hookDb(project), ev.sessionId);
|
|
20365
20589
|
if (ev.source === "compact" && row5.compactDelivery === "sessionstart") {
|
|
20366
|
-
const db2 = await
|
|
20367
|
-
|
|
20368
|
-
|
|
20590
|
+
const db2 = await hookDb(project);
|
|
20591
|
+
const onceKey = COMPACT_STATE_KEY + ":" + lastSessionSeq(db2, ev.sessionId);
|
|
20592
|
+
if (!shouldHint(db2, ev.sessionId, onceKey)) return ALLOW2;
|
|
20593
|
+
return { kind: "hint", text: compactText(db2, ev, row5), onceKey };
|
|
20369
20594
|
}
|
|
20370
|
-
const db = await
|
|
20595
|
+
const db = await hookDb(project);
|
|
20371
20596
|
if (row5.compactDelivery === "opencode-cache" && metaTake(db, PENDING_COMPACT_META_PREFIX + ev.sessionId) !== null) {
|
|
20372
20597
|
return { kind: "hint", text: compactText(db, ev, row5), onceKey: PENDING_COMPACT_KEY };
|
|
20373
20598
|
}
|
|
@@ -20395,7 +20620,7 @@ async function userPromptSubmit(ev, row5, project) {
|
|
|
20395
20620
|
});
|
|
20396
20621
|
echoDetached(ev, project, body);
|
|
20397
20622
|
if (row5.compactDelivery === "pending-flag") {
|
|
20398
|
-
const db = await
|
|
20623
|
+
const db = await hookDb(project);
|
|
20399
20624
|
if (metaTake(db, PENDING_COMPACT_META_PREFIX + ev.sessionId) !== null) {
|
|
20400
20625
|
return { kind: "hint", text: compactText(db, ev, row5), onceKey: PENDING_COMPACT_KEY };
|
|
20401
20626
|
}
|
|
@@ -20405,14 +20630,29 @@ async function userPromptSubmit(ev, row5, project) {
|
|
|
20405
20630
|
}
|
|
20406
20631
|
async function firstTurnResume(ev, row5, project) {
|
|
20407
20632
|
if (row5.eventMap.SessionStart !== void 0 || ev.sessionId === "") return null;
|
|
20408
|
-
const db = await
|
|
20633
|
+
const db = await hookDb(project);
|
|
20409
20634
|
if (hasSessionRows(db, ev.sessionId)) return null;
|
|
20410
20635
|
if (!shouldHint(db, ev.sessionId, RESUME_HINT_KEY)) return null;
|
|
20411
20636
|
if (!hasAgentRows(db, project.worktree, ev.agent)) return null;
|
|
20412
20637
|
return { kind: "hint", text: withPrefix(RESUME_HINT, row5), onceKey: RESUME_HINT_KEY };
|
|
20413
20638
|
}
|
|
20414
20639
|
function markCompacted(db, sessionId) {
|
|
20415
|
-
if (sessionId
|
|
20640
|
+
if (sessionId === "") return;
|
|
20641
|
+
metaSet(db, COMPACTED_META_PREFIX + sessionId, JSON.stringify({ seq: readMaxSeq(db), source: readMaxSourceId(db) }));
|
|
20642
|
+
}
|
|
20643
|
+
function compactBoundary(value) {
|
|
20644
|
+
const all = { seq: Number.MAX_SAFE_INTEGER, source: Number.MAX_SAFE_INTEGER };
|
|
20645
|
+
try {
|
|
20646
|
+
const v = JSON.parse(value);
|
|
20647
|
+
if (typeof v !== "object" || v === null) return all;
|
|
20648
|
+
const { seq, source } = v;
|
|
20649
|
+
return {
|
|
20650
|
+
seq: typeof seq === "number" ? seq : all.seq,
|
|
20651
|
+
source: typeof source === "number" ? source : all.source
|
|
20652
|
+
};
|
|
20653
|
+
} catch {
|
|
20654
|
+
return all;
|
|
20655
|
+
}
|
|
20416
20656
|
}
|
|
20417
20657
|
function seenSeqs(value) {
|
|
20418
20658
|
if (value === null) return [];
|
|
@@ -20434,14 +20674,17 @@ function seenUnitKeys(value) {
|
|
|
20434
20674
|
}
|
|
20435
20675
|
async function recall(ev, row5, project, prompt) {
|
|
20436
20676
|
if (!hasRecall(row5) || ev.sessionId === "") return ALLOW2;
|
|
20437
|
-
const db = await
|
|
20438
|
-
|
|
20677
|
+
const db = await hookDb(project);
|
|
20678
|
+
const compacted = metaGet(db, COMPACTED_META_PREFIX + ev.sessionId);
|
|
20679
|
+
if (compacted === null) return ALLOW2;
|
|
20680
|
+
const boundary = compactBoundary(compacted);
|
|
20439
20681
|
const seenKey = RECALL_SEEN_META_PREFIX + ev.sessionId;
|
|
20440
20682
|
const seen = seenSeqs(metaGet(db, seenKey));
|
|
20441
20683
|
const unitsKey = RECALL_UNITS_SEEN_META_PREFIX + ev.sessionId;
|
|
20442
20684
|
const seenUnits = seenUnitKeys(metaGet(db, unitsKey));
|
|
20443
|
-
const units = queryUnits(db, ev.sessionId, recallQueryText(prompt), RECALL_UNIT_CANDIDATES);
|
|
20444
|
-
const
|
|
20685
|
+
const units = queryUnits(db, ev.sessionId, recallQueryText(prompt), RECALL_UNIT_CANDIDATES, boundary.source);
|
|
20686
|
+
const rows = readRecallRows(db, ev.sessionId, project.worktree, RECALL_MAX_ROWS, boundary.seq);
|
|
20687
|
+
const picked = pickRecall(rows, prompt, new Set(seen), units, new Set(seenUnits));
|
|
20445
20688
|
if (picked.text === "") return ALLOW2;
|
|
20446
20689
|
if (picked.seqs.length > 0) metaSet(db, seenKey, JSON.stringify([...seen, ...picked.seqs]));
|
|
20447
20690
|
if (picked.units !== void 0) metaSet(db, unitsKey, JSON.stringify([...seenUnits, ...picked.units]));
|
|
@@ -20464,7 +20707,7 @@ function readOptions(value) {
|
|
|
20464
20707
|
function echoDetached(ev, project, prompt) {
|
|
20465
20708
|
if (ev.sessionId === "") return;
|
|
20466
20709
|
const key = optionsKey(ev.sessionId);
|
|
20467
|
-
void
|
|
20710
|
+
void hookDb(project).then((db) => {
|
|
20468
20711
|
if (metaGet(db, key) === null) return;
|
|
20469
20712
|
const taken = metaTake(db, key);
|
|
20470
20713
|
const offered = taken === null ? null : readOptions(taken);
|
|
@@ -20472,12 +20715,12 @@ function echoDetached(ev, project, prompt) {
|
|
|
20472
20715
|
const part = optionEchoDecision(prompt, offered.labels, offered.seq);
|
|
20473
20716
|
if (part !== null) writeDecisions(db, ev, project, [part]);
|
|
20474
20717
|
}).catch((err) => {
|
|
20475
|
-
process.stderr.write("hooks: decision write failed: " +
|
|
20718
|
+
process.stderr.write("hooks: decision write failed: " + message2(err) + "\n");
|
|
20476
20719
|
});
|
|
20477
20720
|
}
|
|
20478
20721
|
function writeDecisions(db, ev, project, parts) {
|
|
20479
20722
|
for (const part of parts) {
|
|
20480
|
-
|
|
20723
|
+
writeOrSpool(project, db, { t: "row", at: Date.now(), row: {
|
|
20481
20724
|
session_id: ev.sessionId,
|
|
20482
20725
|
worktree: project.worktree,
|
|
20483
20726
|
agent: ev.agent,
|
|
@@ -20492,22 +20735,22 @@ function writeDecisions(db, ev, project, parts) {
|
|
|
20492
20735
|
turn: ev.turn ?? 0,
|
|
20493
20736
|
sandbox_bytes: 0,
|
|
20494
20737
|
returned_bytes: 0
|
|
20495
|
-
});
|
|
20496
|
-
|
|
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 });
|
|
20497
20740
|
}
|
|
20498
20741
|
}
|
|
20499
20742
|
function askDetached(ev, project, tool, text) {
|
|
20500
20743
|
const parts = answerDecisions(text);
|
|
20501
20744
|
const labels = parts.length === 0 ? askOptionLabels(tool.input) : [];
|
|
20502
20745
|
if (parts.length === 0 && labels.length === 0) return;
|
|
20503
|
-
void
|
|
20746
|
+
void hookDb(project).then((db) => {
|
|
20504
20747
|
if (parts.length > 0) return writeDecisions(db, ev, project, parts);
|
|
20505
20748
|
const prompts = readSessionEvents(db, ev.sessionId, "prompt");
|
|
20506
20749
|
const last2 = prompts[prompts.length - 1];
|
|
20507
20750
|
if (last2 === void 0 || ev.sessionId === "") return;
|
|
20508
20751
|
metaSet(db, optionsKey(ev.sessionId), JSON.stringify({ seq: last2.seq, labels }));
|
|
20509
20752
|
}).catch((err) => {
|
|
20510
|
-
process.stderr.write("hooks: decision write failed: " +
|
|
20753
|
+
process.stderr.write("hooks: decision write failed: " + message2(err) + "\n");
|
|
20511
20754
|
});
|
|
20512
20755
|
}
|
|
20513
20756
|
function toolSetSources(ev, project, env) {
|
|
@@ -20543,7 +20786,7 @@ function caseB(ev, row5, d0, userDeny) {
|
|
|
20543
20786
|
if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
|
|
20544
20787
|
const command = tool.input.command;
|
|
20545
20788
|
if (typeof command !== "string") return d0;
|
|
20546
|
-
const wrapper = '"' +
|
|
20789
|
+
const wrapper = '"' + join9(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
|
|
20547
20790
|
const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
|
|
20548
20791
|
return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
|
|
20549
20792
|
}
|
|
@@ -20584,7 +20827,8 @@ async function postToolUse(ev, row5, project, env, settle3) {
|
|
|
20584
20827
|
const tool = ev.tool;
|
|
20585
20828
|
if (tool === void 0 || tool.canonicalName.startsWith(OWN_TOOL_PREFIX)) return ALLOW2;
|
|
20586
20829
|
const result = ev.result ?? { isError: false, bytes: 0 };
|
|
20587
|
-
const
|
|
20830
|
+
const whole2 = wholeOutput(result, ev.sessionId, env);
|
|
20831
|
+
const text = whole2.text;
|
|
20588
20832
|
if (result.persistedPath !== void 0) result.bytes = Buffer.byteLength(text);
|
|
20589
20833
|
if (tool.canonicalName === DECISION_TOOL) askDetached(ev, project, tool, text);
|
|
20590
20834
|
const kind = journalKind(tool, row5, result.isError);
|
|
@@ -20611,7 +20855,7 @@ async function postToolUse(ev, row5, project, env, settle3) {
|
|
|
20611
20855
|
};
|
|
20612
20856
|
let decision;
|
|
20613
20857
|
try {
|
|
20614
|
-
decision = await postReplace(ev, row5, project, env, tool, result, text);
|
|
20858
|
+
decision = await postReplace(ev, row5, project, env, tool, result, text, whole2.file);
|
|
20615
20859
|
} catch (err) {
|
|
20616
20860
|
journal(result.bytes);
|
|
20617
20861
|
throw err;
|
|
@@ -20625,56 +20869,112 @@ function ownRead(ev, tool, env) {
|
|
|
20625
20869
|
const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
|
|
20626
20870
|
return p !== void 0 && isOwnFile(ev.agent, ev.cwd, p, env);
|
|
20627
20871
|
}
|
|
20628
|
-
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
20872
|
+
async function postReplace(ev, row5, project, env, tool, result, text, persistedFile) {
|
|
20629
20873
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
20630
20874
|
if (boundedRead(tool)) return ALLOW2;
|
|
20875
|
+
if (ompRangedRead(ev, tool)) return ALLOW2;
|
|
20631
20876
|
if (ownRead(ev, tool, env)) return ALLOW2;
|
|
20877
|
+
if (SKILL_LOAD_TOOLS.includes(tool.canonicalName)) return ALLOW2;
|
|
20632
20878
|
if (result.keep === true) return ALLOW2;
|
|
20633
20879
|
if (!hasReplace(row5)) return ALLOW2;
|
|
20634
20880
|
let label2;
|
|
20635
20881
|
let caller = { ctx: true, shell: true, read: false };
|
|
20882
|
+
let canRead = true;
|
|
20636
20883
|
if (isSubagentCall(ev)) {
|
|
20637
20884
|
const set3 = toolSetForAgentType(ev, toolSetSources(ev, project, env));
|
|
20638
20885
|
const subCase = pickSubagentCase(ev, set3);
|
|
20639
20886
|
const has3 = (names) => set3 !== null && names.some((n) => set3.includes(n));
|
|
20887
|
+
canRead = has3(row5.nativeTools.read ?? []);
|
|
20640
20888
|
caller = {
|
|
20641
20889
|
ctx: subCase === "A",
|
|
20642
20890
|
shell: has3(row5.nativeTools.shell),
|
|
20643
20891
|
read: RANGE_READ_TOOLS.includes(tool.canonicalName) && has3(row5.nativeTools.read ?? [])
|
|
20644
20892
|
};
|
|
20893
|
+
if (set3 !== null && !caller.ctx && !caller.shell && !caller.read) return ALLOW2;
|
|
20645
20894
|
label2 = SUBAGENT_SOURCE_PREFIX + tool.canonicalName + ":" + (tool.callId ?? String(ev.turn ?? 0));
|
|
20646
20895
|
} else {
|
|
20647
20896
|
label2 = mainLabel(tool, ev);
|
|
20648
20897
|
}
|
|
20649
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;
|
|
20650
20899
|
const chunks = chunkText(text, "text", REPLACE_CHUNK_BYTES);
|
|
20651
|
-
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 };
|
|
20652
20902
|
let sourceId;
|
|
20653
20903
|
if (result.bytes <= SYNC_INDEX_MAX_BYTES) {
|
|
20654
|
-
sourceId =
|
|
20655
|
-
insertUnits(db, sourceId, ev.sessionId, buildUnits(text));
|
|
20904
|
+
sourceId = writeOrSpool(project, db, op, chunks);
|
|
20656
20905
|
} else {
|
|
20657
|
-
sourceId =
|
|
20658
|
-
indexDetached(project,
|
|
20906
|
+
sourceId = reserveOrSpool(project, db, op, chunks);
|
|
20907
|
+
if (sourceId !== null) indexDetached(project, { ...op, id: sourceId }, chunks);
|
|
20659
20908
|
}
|
|
20660
|
-
|
|
20909
|
+
if (pluginMcpCall(tool)) return ALLOW2;
|
|
20910
|
+
const handle = sourceId === null ? label2 : sourceHandle(sourceId);
|
|
20661
20911
|
const prompt = await lastPrompt(project, ev.sessionId);
|
|
20662
20912
|
const rankQuery = prompt.trim() === "" ? void 0 : intent + " " + prompt;
|
|
20663
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);
|
|
20664
20914
|
const budget = replaceBudget(handleLine, moreLine2(intent, label2));
|
|
20665
|
-
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) : "");
|
|
20666
20916
|
const digest = shapeDigest(text, rankQuery ?? intent, SHAPE_RETURN_BYTES);
|
|
20667
20917
|
if (digest !== null) return { kind: "replace", output: replaceOutput(digest, pointer) };
|
|
20668
20918
|
const selected = selectChunksInMemory(chunks, intent, budget, label2, rankQuery);
|
|
20669
20919
|
return { kind: "replace", output: selected.more !== null ? replaceOutput(selected.text, pointer) : selected.text };
|
|
20670
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
|
+
}
|
|
20671
20924
|
function searchTwin(handle, intent, project) {
|
|
20672
20925
|
const terms = Buffer.byteLength(intent, "utf8") > ECHO_MAX_BYTES ? "" : intent;
|
|
20673
|
-
return SEARCH_TWIN_LINE(
|
|
20926
|
+
return SEARCH_TWIN_LINE(join9(dirname4(process.argv[1] ?? ""), SEARCH_WRAPPER_FILE), handle, terms, project.worktree);
|
|
20674
20927
|
}
|
|
20675
20928
|
function boundedRead(tool) {
|
|
20676
20929
|
return RANGE_READ_TOOLS.includes(tool.canonicalName) && READ_RANGE_KEYS.some((k) => tool.input[k] !== void 0 && tool.input[k] !== null);
|
|
20677
20930
|
}
|
|
20931
|
+
function ompRangedRead(ev, tool) {
|
|
20932
|
+
if (ev.agent !== "omp" || !RANGE_READ_TOOLS.includes(tool.canonicalName)) return false;
|
|
20933
|
+
const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
|
|
20934
|
+
if (p === void 0 || !rangedPathSuffix(p)) return false;
|
|
20935
|
+
try {
|
|
20936
|
+
return lstatSync2(resolve8(ev.cwd, p), { throwIfNoEntry: false }) === void 0;
|
|
20937
|
+
} catch {
|
|
20938
|
+
return false;
|
|
20939
|
+
}
|
|
20940
|
+
}
|
|
20941
|
+
function rangedPathSuffix(path8) {
|
|
20942
|
+
let cut = path8.lastIndexOf(":");
|
|
20943
|
+
let sel = path8.slice(cut + 1);
|
|
20944
|
+
if (sel.toLowerCase() === "raw") {
|
|
20945
|
+
cut = path8.lastIndexOf(":", cut - 1);
|
|
20946
|
+
sel = path8.slice(cut + 1, path8.length - 4);
|
|
20947
|
+
}
|
|
20948
|
+
if (cut <= 0 || !rangeList(sel)) return false;
|
|
20949
|
+
let file2 = path8.slice(0, cut);
|
|
20950
|
+
if (file2.toLowerCase().endsWith(":raw")) file2 = file2.slice(0, -4);
|
|
20951
|
+
return file2.length > 1 || !asciiLetter(file2);
|
|
20952
|
+
}
|
|
20953
|
+
function rangeList(sel) {
|
|
20954
|
+
return sel !== "" && sel.split(",").every(rangeItem);
|
|
20955
|
+
}
|
|
20956
|
+
function rangeItem(item) {
|
|
20957
|
+
if (item.startsWith("-")) return digitsOnly(item.slice(1));
|
|
20958
|
+
let i = 0;
|
|
20959
|
+
while (i < item.length && digit(item[i])) i++;
|
|
20960
|
+
if (i === 0) return false;
|
|
20961
|
+
if (i === item.length) return true;
|
|
20962
|
+
const op = item[i];
|
|
20963
|
+
const rest = item.slice(i + 1);
|
|
20964
|
+
return op === "-" && (rest === "" || digitsOnly(rest)) || op === "+" && digitsOnly(rest);
|
|
20965
|
+
}
|
|
20966
|
+
function digitsOnly(s) {
|
|
20967
|
+
if (s === "") return false;
|
|
20968
|
+
for (const c of s) if (!digit(c)) return false;
|
|
20969
|
+
return true;
|
|
20970
|
+
}
|
|
20971
|
+
function digit(c) {
|
|
20972
|
+
return c >= "0" && c <= "9";
|
|
20973
|
+
}
|
|
20974
|
+
function asciiLetter(s) {
|
|
20975
|
+
const c = s.toLowerCase();
|
|
20976
|
+
return c.length === 1 && c >= "a" && c <= "z";
|
|
20977
|
+
}
|
|
20678
20978
|
function replaceOutput(body, handleLine) {
|
|
20679
20979
|
return body === "" ? handleLine : body + "\n" + handleLine;
|
|
20680
20980
|
}
|
|
@@ -20683,7 +20983,7 @@ function replaceBudget(handleLine, more) {
|
|
|
20683
20983
|
}
|
|
20684
20984
|
function hostToolResult(file2, sessionId, env) {
|
|
20685
20985
|
if (sessionId === "" || sessionId.includes(sep3) || sessionId.includes("/")) return false;
|
|
20686
|
-
const projects =
|
|
20986
|
+
const projects = join9(claudeDirOf(env, homeDirOf(env) ?? ""), PROJECTS_DIR_NAME);
|
|
20687
20987
|
const steps = relative3(projects, resolve8(file2)).split(sep3);
|
|
20688
20988
|
if (steps.length !== 4 || steps.includes("..") || steps.includes("")) return false;
|
|
20689
20989
|
if (steps[1] !== sessionId || steps[2] !== CLAUDE_TOOL_RESULTS_DIR_NAME) return false;
|
|
@@ -20692,20 +20992,20 @@ function hostToolResult(file2, sessionId, env) {
|
|
|
20692
20992
|
}
|
|
20693
20993
|
function wholeOutput(result, sessionId, env) {
|
|
20694
20994
|
const head2 = result.text ?? "";
|
|
20695
|
-
if (result.persistedPath === void 0) return head2;
|
|
20995
|
+
if (result.persistedPath === void 0) return { text: head2 };
|
|
20696
20996
|
try {
|
|
20697
20997
|
if (!hostToolResult(result.persistedPath, sessionId, env)) {
|
|
20698
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"));
|
|
20699
|
-
return head2;
|
|
20999
|
+
return { text: head2 };
|
|
20700
21000
|
}
|
|
20701
|
-
return
|
|
21001
|
+
return { text: readFileSync6(result.persistedPath, "utf8"), file: result.persistedPath };
|
|
20702
21002
|
} catch {
|
|
20703
|
-
return head2;
|
|
21003
|
+
return { text: head2 };
|
|
20704
21004
|
}
|
|
20705
21005
|
}
|
|
20706
21006
|
async function lastPrompt(project, sessionId) {
|
|
20707
21007
|
try {
|
|
20708
|
-
return readLastPrompt(await
|
|
21008
|
+
return readLastPrompt(await hookDb(project), sessionId);
|
|
20709
21009
|
} catch {
|
|
20710
21010
|
return "";
|
|
20711
21011
|
}
|
|
@@ -20716,18 +21016,23 @@ function mainLabel(tool, ev) {
|
|
|
20716
21016
|
const head2 = (tool.canonicalName + ":" + (nl < 0 ? cmd : cmd.slice(0, nl))).slice(0, SOURCE_LABEL_MAX_CHARS);
|
|
20717
21017
|
return head2 + "#" + (tool.callId ?? String(ev.turn ?? 0));
|
|
20718
21018
|
}
|
|
20719
|
-
function indexDetached(project,
|
|
20720
|
-
|
|
20721
|
-
|
|
20722
|
-
|
|
20723
|
-
|
|
20724
|
-
|
|
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
|
+
}
|
|
20725
21030
|
}
|
|
20726
21031
|
function sourceRowOf(project, sessionId, label2) {
|
|
20727
21032
|
return { sessionId, worktree: project.worktree, agent: project.agent, kind: "content", label: label2, createdAt: Date.now() };
|
|
20728
21033
|
}
|
|
20729
21034
|
async function preCompact(ev, row5, project) {
|
|
20730
|
-
const db = await
|
|
21035
|
+
const db = await hookDb(project);
|
|
20731
21036
|
metaSet(db, PENDING_COMPACT_META_PREFIX + ev.sessionId, PENDING_COMPACT_FLAG);
|
|
20732
21037
|
if (hasRecall(row5)) markCompacted(db, ev.sessionId);
|
|
20733
21038
|
return ALLOW2;
|
|
@@ -20809,7 +21114,7 @@ function buildChildEnv(parent, extra) {
|
|
|
20809
21114
|
}
|
|
20810
21115
|
|
|
20811
21116
|
// src/core/sandbox/runtimes.ts
|
|
20812
|
-
import { accessSync, constants as fsConstants, statSync as
|
|
21117
|
+
import { accessSync, constants as fsConstants, statSync as statSync5 } from "node:fs";
|
|
20813
21118
|
import path from "node:path";
|
|
20814
21119
|
|
|
20815
21120
|
// src/core/sandbox/path-entries.ts
|
|
@@ -20854,7 +21159,7 @@ function fileNames(name, pathExt) {
|
|
|
20854
21159
|
function probe(full) {
|
|
20855
21160
|
let st;
|
|
20856
21161
|
try {
|
|
20857
|
-
st =
|
|
21162
|
+
st = statSync5(full, { throwIfNoEntry: false });
|
|
20858
21163
|
} catch {
|
|
20859
21164
|
return "unreadable";
|
|
20860
21165
|
}
|
|
@@ -21049,8 +21354,8 @@ function runProcess(argv, o) {
|
|
|
21049
21354
|
}
|
|
21050
21355
|
|
|
21051
21356
|
// src/core/index/auto-memory.ts
|
|
21052
|
-
import { readdirSync as
|
|
21053
|
-
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";
|
|
21054
21359
|
var MEMORY_FILES = Object.freeze([
|
|
21055
21360
|
Object.freeze(["CLAUDE.md"]),
|
|
21056
21361
|
Object.freeze(["CLAUDE.local.md"]),
|
|
@@ -21064,7 +21369,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
21064
21369
|
var MD = ".md";
|
|
21065
21370
|
function steeringFiles(worktree) {
|
|
21066
21371
|
try {
|
|
21067
|
-
return
|
|
21372
|
+
return readdirSync4(join10(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
21068
21373
|
} catch {
|
|
21069
21374
|
return [];
|
|
21070
21375
|
}
|
|
@@ -21072,10 +21377,10 @@ function steeringFiles(worktree) {
|
|
|
21072
21377
|
function readAutoMemory(project) {
|
|
21073
21378
|
const rows = [];
|
|
21074
21379
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
21075
|
-
const path8 =
|
|
21380
|
+
const path8 = join10(project.worktree, ...segs);
|
|
21076
21381
|
if (!isInside(project.worktree, path8)) continue;
|
|
21077
21382
|
try {
|
|
21078
|
-
const st =
|
|
21383
|
+
const st = statSync6(path8);
|
|
21079
21384
|
if (!st.isFile()) continue;
|
|
21080
21385
|
rows.push({
|
|
21081
21386
|
origin: "memory",
|
|
@@ -21084,7 +21389,7 @@ function readAutoMemory(project) {
|
|
|
21084
21389
|
sourceId: null,
|
|
21085
21390
|
path: path8,
|
|
21086
21391
|
label: segs.join("/"),
|
|
21087
|
-
text:
|
|
21392
|
+
text: readFileSync7(path8, "utf8")
|
|
21088
21393
|
});
|
|
21089
21394
|
} catch {
|
|
21090
21395
|
}
|
|
@@ -21145,15 +21450,43 @@ function sourceCount(db, scope, ctx, source) {
|
|
|
21145
21450
|
});
|
|
21146
21451
|
return Number(row5.n);
|
|
21147
21452
|
}
|
|
21148
|
-
function zeroHits(db, scope, ctx, source, mem, offset = 0) {
|
|
21149
|
-
const
|
|
21150
|
-
|
|
21151
|
-
|
|
21453
|
+
function zeroHits(db, scope, ctx, source, mem, nm, queries, offset = 0) {
|
|
21454
|
+
const inScope = sourceCount(db, scope, ctx, source);
|
|
21455
|
+
const n = inScope + mem.rows.length;
|
|
21456
|
+
const head2 = 'No hits in scope "' + scope + '" across ' + n + " source(s).";
|
|
21457
|
+
const pick4 = nm.pick;
|
|
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
|
+
}
|
|
21461
|
+
if (pick4.id !== null) {
|
|
21462
|
+
const wider = scope === "session" && sourceCount(db, "worktree", ctx, source) > 0 ? "worktree" : "project";
|
|
21463
|
+
return reply(head2 + "\nSource " + JSON.stringify(nm.arg) + ' is stored in scope "' + wider + '": ' + callText(queries, wider, nm.arg, "") + " searches it.", false);
|
|
21464
|
+
}
|
|
21465
|
+
return reply(head2 + "\n" + unknownSource(db, scope, ctx, nm.arg), true);
|
|
21466
|
+
}
|
|
21467
|
+
var STORED_SOURCES = `
|
|
21468
|
+
SELECT MAX(id) AS id, label FROM sources
|
|
21469
|
+
WHERE (:scope <> 'session' OR session_id = :session_id)
|
|
21470
|
+
AND (:scope <> 'worktree' OR worktree = :worktree)
|
|
21471
|
+
GROUP BY label ORDER BY MAX(id) DESC LIMIT :limit`;
|
|
21472
|
+
var STORED_SOURCES_SHOWN = 5;
|
|
21473
|
+
function unknownSource(db, scope, ctx, given) {
|
|
21474
|
+
const line = "Source " + JSON.stringify(given) + ' is not a stored source in scope "' + scope + '".';
|
|
21475
|
+
const rows = db.raw.prepare(STORED_SOURCES).all({
|
|
21476
|
+
scope,
|
|
21477
|
+
session_id: ctx.sessionId,
|
|
21478
|
+
worktree: ctx.project.worktree,
|
|
21479
|
+
limit: STORED_SOURCES_SHOWN + 1
|
|
21480
|
+
});
|
|
21481
|
+
if (rows.length === 0) return line + '\nctx_index stores one: ctx_index({content:"...", source:' + JSON.stringify(given) + "}).";
|
|
21482
|
+
const names = rows.slice(0, STORED_SOURCES_SHOWN).map((r) => isLongLabel(r.label) ? sourceHandle(Number(r.id)) : JSON.stringify(r.label));
|
|
21483
|
+
const more = rows.length > STORED_SOURCES_SHOWN ? ", ..." : "";
|
|
21484
|
+
return line + "\nStored sources, newest first: " + names.join(", ") + more + ". " + callText([], scope, void 0, 'sort:"timeline"') + " lists them all.";
|
|
21152
21485
|
}
|
|
21153
21486
|
function named(given, pick4) {
|
|
21154
|
-
if (given === void 0 || pick4 === null) return { arg: given, note: null };
|
|
21487
|
+
if (given === void 0 || pick4 === null) return { arg: given, note: null, pick: null };
|
|
21155
21488
|
const arg = pick4.id !== null && isLongLabel(given) ? sourceHandle(pick4.id) : given;
|
|
21156
|
-
return { arg, note: collisionLine(given, pick4) };
|
|
21489
|
+
return { arg, note: collisionLine(given, pick4), pick: pick4 };
|
|
21157
21490
|
}
|
|
21158
21491
|
function sourceCard(db, id, input, scope, arg) {
|
|
21159
21492
|
const row5 = sourceCardRow(db, id);
|
|
@@ -21285,7 +21618,7 @@ function relevance(db, given, scope, ctx, nm, ms, indexed) {
|
|
|
21285
21618
|
});
|
|
21286
21619
|
const take = fetched.map((h) => replyHits(h, size));
|
|
21287
21620
|
const pages = fetched.map((h, i) => h.slice(0, take[i]));
|
|
21288
|
-
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, ms, offset);
|
|
21621
|
+
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, ms, nm, input.queries, offset);
|
|
21289
21622
|
const moreLine3 = (q, pos) => "More: " + callText([q], scope, nm.arg, "offset:" + pos);
|
|
21290
21623
|
let reserve = 0;
|
|
21291
21624
|
for (const q of input.queries) reserve += bytes2(moreLine3(q, offset + size)) + 1;
|
|
@@ -21355,7 +21688,7 @@ function timelineLine(r) {
|
|
|
21355
21688
|
}
|
|
21356
21689
|
function timeline(db, input, scope, ctx, nm, ms) {
|
|
21357
21690
|
const page2 = ftsQueryTimeline(db, scope, ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, input.after ?? null, input.source, ms.rows);
|
|
21358
|
-
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source, ms);
|
|
21691
|
+
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source, ms, nm, input.queries);
|
|
21359
21692
|
const moreLine3 = (ts) => "more: " + callText(input.queries, scope, nm.arg, 'sort:"timeline", after:' + ts);
|
|
21360
21693
|
const reserve = bytes2(moreLine3(page2.rows[page2.rows.length - 1].ts)) + 1;
|
|
21361
21694
|
const lines = nm.note === null ? [] : [nm.note];
|
|
@@ -21409,7 +21742,8 @@ async function handler(input, ctx) {
|
|
|
21409
21742
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
21410
21743
|
try {
|
|
21411
21744
|
const given = input.source;
|
|
21412
|
-
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;
|
|
21413
21747
|
if (pick4 !== null) input = { ...input, source: pick4.label };
|
|
21414
21748
|
const nm = named(given, pick4);
|
|
21415
21749
|
const indexed = pick4 !== null && pick4.id !== null;
|
|
@@ -21658,19 +21992,19 @@ var ctxBatch = Object.freeze({
|
|
|
21658
21992
|
});
|
|
21659
21993
|
|
|
21660
21994
|
// src/core/tools/doctor.ts
|
|
21661
|
-
import { readdirSync as
|
|
21662
|
-
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";
|
|
21663
21997
|
|
|
21664
21998
|
// src/core/ops/bundle-dir.ts
|
|
21665
21999
|
import { existsSync as existsSync4 } from "node:fs";
|
|
21666
|
-
import { dirname as dirname5, join as
|
|
22000
|
+
import { dirname as dirname5, join as join11 } from "node:path";
|
|
21667
22001
|
import { fileURLToPath } from "node:url";
|
|
21668
22002
|
function bundleDirOf(argv1, moduleFile) {
|
|
21669
22003
|
const own4 = dirname5(argv1);
|
|
21670
|
-
if (existsSync4(
|
|
22004
|
+
if (existsSync4(join11(own4, SERVER_ENTRY_FILE))) return own4;
|
|
21671
22005
|
let dir = dirname5(moduleFile);
|
|
21672
22006
|
for (; ; ) {
|
|
21673
|
-
if (existsSync4(
|
|
22007
|
+
if (existsSync4(join11(dir, SERVER_ENTRY_FILE))) return dir;
|
|
21674
22008
|
const up = dirname5(dir);
|
|
21675
22009
|
if (up === dir) return own4;
|
|
21676
22010
|
dir = up;
|
|
@@ -21684,17 +22018,17 @@ function ownBundleDir() {
|
|
|
21684
22018
|
}
|
|
21685
22019
|
|
|
21686
22020
|
// src/core/ops/doctor-config.ts
|
|
21687
|
-
import { existsSync as existsSync11, readdirSync as
|
|
21688
|
-
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";
|
|
21689
22023
|
|
|
21690
22024
|
// src/core/ops/detect-v1.ts
|
|
21691
|
-
import { existsSync as existsSync6, opendirSync, readdirSync as
|
|
22025
|
+
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync5, readFileSync as readFileSync9 } from "node:fs";
|
|
21692
22026
|
import { tmpdir } from "node:os";
|
|
21693
|
-
import { join as
|
|
22027
|
+
import { join as join13 } from "node:path";
|
|
21694
22028
|
|
|
21695
22029
|
// src/core/ops/host-config.ts
|
|
21696
|
-
import { existsSync as existsSync5, readFileSync as
|
|
21697
|
-
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";
|
|
21698
22032
|
|
|
21699
22033
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
21700
22034
|
var KEYS2 = {
|
|
@@ -23740,16 +24074,16 @@ function parseTOML(code, options) {
|
|
|
23740
24074
|
}
|
|
23741
24075
|
|
|
23742
24076
|
// src/core/ops/atomic-file.ts
|
|
23743
|
-
import { mkdirSync as
|
|
24077
|
+
import { mkdirSync as mkdirSync4, renameSync as renameSync3, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
23744
24078
|
import path3 from "node:path";
|
|
23745
24079
|
function sleepSync(ms) {
|
|
23746
24080
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
23747
24081
|
}
|
|
23748
|
-
function
|
|
24082
|
+
function errCode2(e) {
|
|
23749
24083
|
return e.code;
|
|
23750
24084
|
}
|
|
23751
24085
|
function renameWithRetry(from, to, opts = {}) {
|
|
23752
|
-
const rename = opts.rename ??
|
|
24086
|
+
const rename = opts.rename ?? renameSync3;
|
|
23753
24087
|
const sleep2 = opts.sleep ?? sleepSync;
|
|
23754
24088
|
const win = (opts.platform ?? process.platform) === "win32";
|
|
23755
24089
|
for (let attempt = 0; ; attempt += 1) {
|
|
@@ -23757,14 +24091,14 @@ function renameWithRetry(from, to, opts = {}) {
|
|
|
23757
24091
|
rename(from, to);
|
|
23758
24092
|
return;
|
|
23759
24093
|
} catch (e) {
|
|
23760
|
-
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(
|
|
24094
|
+
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
|
|
23761
24095
|
if (!busy || attempt >= ATOMIC_RENAME_RETRIES) throw e;
|
|
23762
24096
|
sleep2(ATOMIC_RENAME_DELAY_MS);
|
|
23763
24097
|
}
|
|
23764
24098
|
}
|
|
23765
24099
|
}
|
|
23766
24100
|
function unlinkWithRetry(file2, opts = {}) {
|
|
23767
|
-
const unlink = opts.unlink ??
|
|
24101
|
+
const unlink = opts.unlink ?? unlinkSync2;
|
|
23768
24102
|
const sleep2 = opts.sleep ?? sleepSync;
|
|
23769
24103
|
const win = (opts.platform ?? process.platform) === "win32";
|
|
23770
24104
|
for (let attempt = 0; ; attempt += 1) {
|
|
@@ -23772,15 +24106,15 @@ function unlinkWithRetry(file2, opts = {}) {
|
|
|
23772
24106
|
unlink(file2);
|
|
23773
24107
|
return;
|
|
23774
24108
|
} catch (e) {
|
|
23775
|
-
if (
|
|
23776
|
-
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(
|
|
24109
|
+
if (errCode2(e) === "ENOENT") return;
|
|
24110
|
+
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
|
|
23777
24111
|
if (!busy || attempt >= ATOMIC_RENAME_RETRIES) throw replaceFailure(file2, e);
|
|
23778
24112
|
sleep2(ATOMIC_RENAME_DELAY_MS);
|
|
23779
24113
|
}
|
|
23780
24114
|
}
|
|
23781
24115
|
}
|
|
23782
24116
|
function replaceFailure(file2, e) {
|
|
23783
|
-
const busy = ATOMIC_RENAME_BUSY_CODES.includes(
|
|
24117
|
+
const busy = ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
|
|
23784
24118
|
const cause = e.message;
|
|
23785
24119
|
return new Error(busy ? `Could not replace ${file2}: ${cause}. Fix: close the program using ${file2}, then re-run` : `Could not write ${file2}: ${cause}. Fix: check the path and its permissions, then re-run`, { cause: e });
|
|
23786
24120
|
}
|
|
@@ -23791,10 +24125,10 @@ function removeTmpFile(tmp, opts = {}) {
|
|
|
23791
24125
|
}
|
|
23792
24126
|
}
|
|
23793
24127
|
function atomicWriteFile(file2, text, opts = {}) {
|
|
23794
|
-
|
|
24128
|
+
mkdirSync4(path3.dirname(file2), { recursive: true });
|
|
23795
24129
|
const tmp = path3.join(path3.dirname(file2), `${ATOMIC_TMP_PREFIX}${path3.basename(file2)}${ATOMIC_TMP_MARK}${process.pid}`);
|
|
23796
24130
|
try {
|
|
23797
|
-
|
|
24131
|
+
writeFileSync2(tmp, text);
|
|
23798
24132
|
renameWithRetry(tmp, file2, opts);
|
|
23799
24133
|
} catch (e) {
|
|
23800
24134
|
removeTmpFile(tmp, opts);
|
|
@@ -23811,10 +24145,10 @@ function formatOf(path8) {
|
|
|
23811
24145
|
function readHostConfig(agent, path8) {
|
|
23812
24146
|
let file2 = path8;
|
|
23813
24147
|
if (agent === "opencode") {
|
|
23814
|
-
const jsonc =
|
|
24148
|
+
const jsonc = join12(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
|
|
23815
24149
|
if (existsSync5(jsonc)) file2 = jsonc;
|
|
23816
24150
|
}
|
|
23817
|
-
const raw = existsSync5(file2) ?
|
|
24151
|
+
const raw = existsSync5(file2) ? readFileSync8(file2, "utf8") : "";
|
|
23818
24152
|
return { agent, text: hostText(raw), format: agent === "opencode" && !file2.endsWith(TOML_EXT) ? "jsonc" : formatOf(file2), path: file2, layout: hostLayout(raw) };
|
|
23819
24153
|
}
|
|
23820
24154
|
function stripJsonComments(text) {
|
|
@@ -24159,7 +24493,7 @@ function setText(agent, path8, text, format, key, value) {
|
|
|
24159
24493
|
}
|
|
24160
24494
|
}
|
|
24161
24495
|
function serverScript() {
|
|
24162
|
-
return
|
|
24496
|
+
return join12(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
24163
24497
|
}
|
|
24164
24498
|
function isNodeCommand(command) {
|
|
24165
24499
|
if (typeof command !== "string") return false;
|
|
@@ -24286,14 +24620,14 @@ function stripJsonc(text) {
|
|
|
24286
24620
|
}
|
|
24287
24621
|
function readJson(file2) {
|
|
24288
24622
|
try {
|
|
24289
|
-
return JSON.parse(stripJsonc(hostText(
|
|
24623
|
+
return JSON.parse(stripJsonc(hostText(readFileSync9(file2, "utf8"))));
|
|
24290
24624
|
} catch {
|
|
24291
24625
|
return void 0;
|
|
24292
24626
|
}
|
|
24293
24627
|
}
|
|
24294
24628
|
function readText(file2) {
|
|
24295
24629
|
try {
|
|
24296
|
-
return hostText(
|
|
24630
|
+
return hostText(readFileSync9(file2, "utf8"));
|
|
24297
24631
|
} catch {
|
|
24298
24632
|
return "";
|
|
24299
24633
|
}
|
|
@@ -24358,7 +24692,7 @@ function mcpEntry(file2, doc, out) {
|
|
|
24358
24692
|
}
|
|
24359
24693
|
}
|
|
24360
24694
|
function claudeShapeSettings(agentHome, out) {
|
|
24361
|
-
const file2 =
|
|
24695
|
+
const file2 = join13(agentHome, SETTINGS_FILE);
|
|
24362
24696
|
const doc = readJson(file2);
|
|
24363
24697
|
for (const c of nestedCommands(doc)) {
|
|
24364
24698
|
if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
|
|
@@ -24378,63 +24712,63 @@ function v1HookFile(file2, out) {
|
|
|
24378
24712
|
function scanClaudeCode(home, agentHome, out) {
|
|
24379
24713
|
claudeShapeSettings(agentHome, out);
|
|
24380
24714
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
24381
|
-
const file2 =
|
|
24715
|
+
const file2 = join13(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
24382
24716
|
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
24383
24717
|
}
|
|
24384
|
-
const userFile =
|
|
24718
|
+
const userFile = join13(home, CLAUDE_USER_CONFIG_FILE);
|
|
24385
24719
|
mcpEntry(userFile, readJson(userFile), out);
|
|
24386
|
-
dataDir(
|
|
24720
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24387
24721
|
}
|
|
24388
24722
|
function scanCodex(agentHome, out) {
|
|
24389
|
-
const hooksFile =
|
|
24723
|
+
const hooksFile = join13(agentHome, HOOKS_JSON_FILE);
|
|
24390
24724
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
24391
24725
|
if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
|
|
24392
24726
|
out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
|
|
24393
24727
|
}
|
|
24394
24728
|
}
|
|
24395
|
-
const tomlFile =
|
|
24729
|
+
const tomlFile = join13(agentHome, CONFIG_TOML_FILE);
|
|
24396
24730
|
const config4 = readTomlValue(tomlFile);
|
|
24397
24731
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
24398
24732
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
24399
24733
|
if (isV2McpTable(hostConfigValueAt(config4, span2.path.slice(0, 2)))) continue;
|
|
24400
24734
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
24401
24735
|
}
|
|
24402
|
-
dataDir(
|
|
24736
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24403
24737
|
}
|
|
24404
24738
|
function scanGemini(agentHome, out) {
|
|
24405
|
-
const file2 =
|
|
24739
|
+
const file2 = join13(agentHome, SETTINGS_FILE);
|
|
24406
24740
|
for (const c of nestedCommands(readJson(file2))) {
|
|
24407
24741
|
if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
|
|
24408
24742
|
}
|
|
24409
|
-
dataDir(
|
|
24743
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
|
|
24410
24744
|
}
|
|
24411
24745
|
function scanVscode(agentHome, project, out) {
|
|
24412
24746
|
if (project !== void 0) {
|
|
24413
|
-
v1HookFile(
|
|
24414
|
-
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);
|
|
24415
24749
|
const doc = readJson(mcpFile2);
|
|
24416
24750
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
24417
24751
|
const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
24418
24752
|
if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
|
|
24419
24753
|
out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
24420
24754
|
}
|
|
24421
|
-
const sessions =
|
|
24755
|
+
const sessions = join13(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
24422
24756
|
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out);
|
|
24423
24757
|
}
|
|
24424
|
-
dataDir(
|
|
24758
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
24425
24759
|
}
|
|
24426
24760
|
function jsonFiles(dir) {
|
|
24427
24761
|
try {
|
|
24428
|
-
return
|
|
24762
|
+
return readdirSync5(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
24429
24763
|
} catch {
|
|
24430
24764
|
return [];
|
|
24431
24765
|
}
|
|
24432
24766
|
}
|
|
24433
24767
|
function scanKiro(agentHome, project, out) {
|
|
24434
|
-
const agentsDir =
|
|
24435
|
-
const defaultFile =
|
|
24768
|
+
const agentsDir = join13(agentHome, KIRO_AGENTS_DIR);
|
|
24769
|
+
const defaultFile = join13(agentHome, ...KIRO_AGENT_FILE);
|
|
24436
24770
|
for (const name of jsonFiles(agentsDir)) {
|
|
24437
|
-
const file2 =
|
|
24771
|
+
const file2 = join13(agentsDir, name);
|
|
24438
24772
|
const doc = readJson(file2);
|
|
24439
24773
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
24440
24774
|
out.push(finding(file2, "", V1_REASON.kiroAgentFile));
|
|
@@ -24445,31 +24779,31 @@ function scanKiro(agentHome, project, out) {
|
|
|
24445
24779
|
if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
|
|
24446
24780
|
}
|
|
24447
24781
|
}
|
|
24448
|
-
const steeringDocs = [
|
|
24449
|
-
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));
|
|
24450
24784
|
for (const file2 of steeringDocs) {
|
|
24451
24785
|
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
24452
24786
|
}
|
|
24453
|
-
dataDir(
|
|
24787
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24454
24788
|
}
|
|
24455
24789
|
function piNpmIsCurrent(piAgentDir) {
|
|
24456
|
-
const doc = readJson(
|
|
24790
|
+
const doc = readJson(join13(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
24457
24791
|
const version4 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
24458
24792
|
return Number.parseInt(version4, 10) >= PI_CURRENT_MAJOR;
|
|
24459
24793
|
}
|
|
24460
24794
|
function scanPi(piAgentDir, agentHome, out) {
|
|
24461
|
-
const file2 =
|
|
24795
|
+
const file2 = join13(piAgentDir, SETTINGS_FILE);
|
|
24462
24796
|
const doc = readJson(file2);
|
|
24463
24797
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
24464
24798
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
24465
24799
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
24466
24800
|
if (spec === PI_GIT_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piGit));
|
|
24467
24801
|
});
|
|
24468
|
-
dataDir(
|
|
24802
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24469
24803
|
}
|
|
24470
24804
|
function scanOpencode(agentHome, out) {
|
|
24471
24805
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
24472
|
-
const file2 =
|
|
24806
|
+
const file2 = join13(agentHome, name);
|
|
24473
24807
|
const doc = readJson(file2);
|
|
24474
24808
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
24475
24809
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
|
|
@@ -24480,13 +24814,13 @@ function scanOpencode(agentHome, out) {
|
|
|
24480
24814
|
}
|
|
24481
24815
|
}
|
|
24482
24816
|
function scanZcode(agentHome, out) {
|
|
24483
|
-
const configFile =
|
|
24817
|
+
const configFile = join13(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
24484
24818
|
const config4 = readJson(configFile);
|
|
24485
24819
|
const events = isObj(config4) && isObj(config4[HOOKS_KEY]) ? config4[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
24486
24820
|
for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
24487
24821
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
|
|
24488
24822
|
}
|
|
24489
|
-
const hooksFile =
|
|
24823
|
+
const hooksFile = join13(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
24490
24824
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
24491
24825
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
|
|
24492
24826
|
}
|
|
@@ -24510,14 +24844,14 @@ function firstTmpMatch(dir) {
|
|
|
24510
24844
|
}
|
|
24511
24845
|
}
|
|
24512
24846
|
function scanAll(home, tmp, out) {
|
|
24513
|
-
const root =
|
|
24514
|
-
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);
|
|
24515
24849
|
if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
24516
24850
|
}
|
|
24517
24851
|
function detectV1(agent, home, scope = {}) {
|
|
24518
24852
|
const out = [];
|
|
24519
24853
|
const project = scope.project;
|
|
24520
|
-
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]);
|
|
24521
24855
|
switch (agent) {
|
|
24522
24856
|
case "claude-code":
|
|
24523
24857
|
scanClaudeCode(home, agentHome, out);
|
|
@@ -24530,11 +24864,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24530
24864
|
break;
|
|
24531
24865
|
case "qwen":
|
|
24532
24866
|
claudeShapeSettings(agentHome, out);
|
|
24533
|
-
dataDir(
|
|
24867
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24534
24868
|
break;
|
|
24535
24869
|
case "copilot-cli":
|
|
24536
|
-
v1HookFile(
|
|
24537
|
-
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);
|
|
24538
24872
|
break;
|
|
24539
24873
|
case "vscode":
|
|
24540
24874
|
scanVscode(agentHome, project, out);
|
|
@@ -24543,7 +24877,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24543
24877
|
scanKiro(agentHome, project, out);
|
|
24544
24878
|
break;
|
|
24545
24879
|
case "pi":
|
|
24546
|
-
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);
|
|
24547
24881
|
break;
|
|
24548
24882
|
// D-WIN-PIDIR-1: empty is unset
|
|
24549
24883
|
case "opencode":
|
|
@@ -24558,8 +24892,8 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24558
24892
|
}
|
|
24559
24893
|
|
|
24560
24894
|
// src/core/ops/plugin-root.ts
|
|
24561
|
-
import { existsSync as existsSync7, readdirSync as
|
|
24562
|
-
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";
|
|
24563
24897
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
24564
24898
|
function missing(agent, path8) {
|
|
24565
24899
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
@@ -24600,15 +24934,15 @@ var realOrNull = (path8) => {
|
|
|
24600
24934
|
};
|
|
24601
24935
|
var readOrNull = (file2) => {
|
|
24602
24936
|
try {
|
|
24603
|
-
return
|
|
24937
|
+
return readFileSync10(file2, "utf8");
|
|
24604
24938
|
} catch {
|
|
24605
24939
|
return null;
|
|
24606
24940
|
}
|
|
24607
24941
|
};
|
|
24608
24942
|
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
24609
24943
|
function enabledPlugins(claudeDir, project) {
|
|
24610
|
-
const files = [
|
|
24611
|
-
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));
|
|
24612
24946
|
const out = {};
|
|
24613
24947
|
for (const file2 of files) {
|
|
24614
24948
|
const text = readOrNull(file2);
|
|
@@ -24624,7 +24958,7 @@ function marketplaceChoice(env, worktree) {
|
|
|
24624
24958
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
24625
24959
|
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
24626
24960
|
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
24627
|
-
const record6 = readOrNull(
|
|
24961
|
+
const record6 = readOrNull(join14(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
24628
24962
|
const recorded = record6 === null ? [] : recordedInstalls(record6);
|
|
24629
24963
|
if (recorded.length === 0) return { record: false };
|
|
24630
24964
|
const live = recorded.filter((r) => existsSync7(r.installPath));
|
|
@@ -24647,18 +24981,18 @@ function marketplaceChoice(env, worktree) {
|
|
|
24647
24981
|
}
|
|
24648
24982
|
function marketplaceRoot(adapter, env, worktree) {
|
|
24649
24983
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
24650
|
-
const plugins =
|
|
24651
|
-
const cache =
|
|
24984
|
+
const plugins = join14(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
24985
|
+
const cache = join14(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
24652
24986
|
const script = process.argv[1];
|
|
24653
24987
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
24654
24988
|
const choice = marketplaceChoice(env, worktree);
|
|
24655
24989
|
if ("root" in choice) return choice.root;
|
|
24656
24990
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
24657
24991
|
const cacheReal = realOrNull(cache);
|
|
24658
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync7(
|
|
24659
|
-
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);
|
|
24660
24994
|
if (!existsSync7(cache)) throw missing(adapter.id, pattern);
|
|
24661
|
-
const found =
|
|
24995
|
+
const found = readdirSync6(cache).sort().map((marketplace) => join14(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync7(dir));
|
|
24662
24996
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
24663
24997
|
return found[0];
|
|
24664
24998
|
}
|
|
@@ -24671,12 +25005,12 @@ function configEntryRoot(adapter, env) {
|
|
|
24671
25005
|
const value = parseHostConfig(adapter.id, file2, current.text, current.format);
|
|
24672
25006
|
const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
|
|
24673
25007
|
const script = Array.isArray(args) ? args[0] : void 0;
|
|
24674
|
-
if (typeof script !== "string" || !
|
|
25008
|
+
if (typeof script !== "string" || !isAbsolute4(script)) throw missing(adapter.id, file2);
|
|
24675
25009
|
return dirname7(script);
|
|
24676
25010
|
}
|
|
24677
25011
|
function packageDirOf(dir) {
|
|
24678
25012
|
for (let cur = dir; ; ) {
|
|
24679
|
-
if (existsSync7(
|
|
25013
|
+
if (existsSync7(join14(cur, D1_PACKAGE_FILE))) return cur;
|
|
24680
25014
|
const up = dirname7(cur);
|
|
24681
25015
|
if (up === cur) return dir;
|
|
24682
25016
|
cur = up;
|
|
@@ -24691,9 +25025,9 @@ function candidate(adapter, env, worktree) {
|
|
|
24691
25025
|
case "hooks+mcp":
|
|
24692
25026
|
return configEntryRoot(adapter, env);
|
|
24693
25027
|
case "extension":
|
|
24694
|
-
return
|
|
25028
|
+
return join14(adapter.id === "gemini" ? geminiDirOf(env, requireHomeDir(env)) : join14(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id]), EXTENSIONS_DIR_NAME, PLUGIN_NAME);
|
|
24695
25029
|
case "plugin":
|
|
24696
|
-
return
|
|
25030
|
+
return join14(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
24697
25031
|
case "in-process":
|
|
24698
25032
|
return packageDirOf(dirname7(fileURLToPath2(import.meta.url)));
|
|
24699
25033
|
}
|
|
@@ -24708,7 +25042,7 @@ function resolvePluginRoot(adapter, env, worktree) {
|
|
|
24708
25042
|
}
|
|
24709
25043
|
|
|
24710
25044
|
// src/setup/pi-gate.ts
|
|
24711
|
-
import { existsSync as existsSync8, readFileSync as
|
|
25045
|
+
import { existsSync as existsSync8, readFileSync as readFileSync11, realpathSync as realpathSync5 } from "node:fs";
|
|
24712
25046
|
import path4 from "node:path";
|
|
24713
25047
|
var EXTENSIONS_KEY = "extensions";
|
|
24714
25048
|
var PROJECT_DIR = ".pi";
|
|
@@ -24718,7 +25052,7 @@ var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
|
24718
25052
|
function load(file2) {
|
|
24719
25053
|
if (!existsSync8(file2)) return void 0;
|
|
24720
25054
|
try {
|
|
24721
|
-
return { file: file2, doc: parseHostConfig("pi", file2, hostText(
|
|
25055
|
+
return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync11(file2, "utf8")), "json") };
|
|
24722
25056
|
} catch {
|
|
24723
25057
|
return void 0;
|
|
24724
25058
|
}
|
|
@@ -24777,8 +25111,8 @@ function piInstalledIn(env, home, pkgDir, cwd) {
|
|
|
24777
25111
|
}
|
|
24778
25112
|
|
|
24779
25113
|
// src/core/ops/doctor-env.ts
|
|
24780
|
-
import { existsSync as existsSync9, readFileSync as
|
|
24781
|
-
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";
|
|
24782
25116
|
function pass(id, detail = DOCTOR_PASS_DETAIL) {
|
|
24783
25117
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
24784
25118
|
}
|
|
@@ -24793,7 +25127,7 @@ function warn(id, detail, fixCommand) {
|
|
|
24793
25127
|
}
|
|
24794
25128
|
function bundleVersion(bundleDir2) {
|
|
24795
25129
|
try {
|
|
24796
|
-
const v = JSON.parse(
|
|
25130
|
+
const v = JSON.parse(readFileSync12(join15(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24797
25131
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24798
25132
|
} catch {
|
|
24799
25133
|
return void 0;
|
|
@@ -24947,7 +25281,7 @@ function checkMcp(ctx, adapter) {
|
|
|
24947
25281
|
function piCwdInside(worktree, piCwd) {
|
|
24948
25282
|
if (piCwd === void 0 || !existsSync9(piCwd)) return false;
|
|
24949
25283
|
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
24950
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
25284
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute5(rel);
|
|
24951
25285
|
}
|
|
24952
25286
|
function checkProject(i) {
|
|
24953
25287
|
const bad = fail2("D7", D7_DETAIL(i.project.source), D7_FIX);
|
|
@@ -24955,6 +25289,20 @@ function checkProject(i) {
|
|
|
24955
25289
|
if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
|
|
24956
25290
|
return pass("D7");
|
|
24957
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
|
+
}
|
|
24958
25306
|
function checkMode(adapter, hostPermission) {
|
|
24959
25307
|
if (hostPermission === "missing") return fail2("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
|
|
24960
25308
|
if (hostPermission === "wired") return pass("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
|
|
@@ -24977,8 +25325,8 @@ function checkRuntimes(env, shellRow) {
|
|
|
24977
25325
|
}
|
|
24978
25326
|
|
|
24979
25327
|
// src/core/ops/omp-import.ts
|
|
24980
|
-
import { join as
|
|
24981
|
-
var { existsSync: existsSync10, readFileSync:
|
|
25328
|
+
import { join as join16 } from "node:path";
|
|
25329
|
+
var { existsSync: existsSync10, readFileSync: readFileSync13 } = process.getBuiltinModule("node:fs");
|
|
24982
25330
|
var OMP_DISABLED_SERVERS_KEY = "disabledServers";
|
|
24983
25331
|
var OMP_MCP_FILE = "mcp.json";
|
|
24984
25332
|
var OMP_CONFIG_FILE = "config.yml";
|
|
@@ -24987,12 +25335,12 @@ var DISABLED_PROVIDERS = "disabledProviders";
|
|
|
24987
25335
|
var CLAUDE_PROVIDER = "claude";
|
|
24988
25336
|
var ALL_PROVIDERS = ["*", "all"];
|
|
24989
25337
|
function ompImportFiles(home) {
|
|
24990
|
-
const agentDir =
|
|
24991
|
-
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) };
|
|
24992
25340
|
}
|
|
24993
25341
|
function readText2(file2) {
|
|
24994
25342
|
try {
|
|
24995
|
-
return existsSync10(file2) ? hostText(
|
|
25343
|
+
return existsSync10(file2) ? hostText(readFileSync13(file2, "utf8")) : void 0;
|
|
24996
25344
|
} catch {
|
|
24997
25345
|
return void 0;
|
|
24998
25346
|
}
|
|
@@ -25120,11 +25468,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
25120
25468
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
25121
25469
|
function mcpFile(row5, home, env) {
|
|
25122
25470
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
25123
|
-
if (row5.id === "codex") return
|
|
25471
|
+
if (row5.id === "codex") return join17(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
25124
25472
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
25125
|
-
if (row5.id === "opencode") return
|
|
25473
|
+
if (row5.id === "opencode") return join17(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
25126
25474
|
if (row5.id === "pi") {
|
|
25127
|
-
return
|
|
25475
|
+
return join17(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
25128
25476
|
}
|
|
25129
25477
|
return null;
|
|
25130
25478
|
}
|
|
@@ -25137,27 +25485,27 @@ function codexNativeDir(env, home) {
|
|
|
25137
25485
|
const codexDir = codexDirOf(env, home);
|
|
25138
25486
|
let enabled;
|
|
25139
25487
|
try {
|
|
25140
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
25488
|
+
enabled = hostConfigValueAt(readParsed("codex", join17(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
25141
25489
|
} catch {
|
|
25142
25490
|
return null;
|
|
25143
25491
|
}
|
|
25144
25492
|
if (enabled !== true) return null;
|
|
25145
|
-
const cache =
|
|
25493
|
+
const cache = join17(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
25146
25494
|
if (!existsSync11(cache)) return null;
|
|
25147
25495
|
const found = [];
|
|
25148
|
-
for (const market of
|
|
25149
|
-
const plugin =
|
|
25496
|
+
for (const market of readdirSync7(cache)) {
|
|
25497
|
+
const plugin = join17(cache, market, SERVER_KEY);
|
|
25150
25498
|
if (!existsSync11(plugin)) continue;
|
|
25151
|
-
for (const version4 of
|
|
25152
|
-
const dir =
|
|
25153
|
-
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);
|
|
25154
25502
|
}
|
|
25155
25503
|
}
|
|
25156
25504
|
return found.length === 0 ? null : found[found.length - 1];
|
|
25157
25505
|
}
|
|
25158
25506
|
function nativeMcpWrong(dir, row5) {
|
|
25159
25507
|
try {
|
|
25160
|
-
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]);
|
|
25161
25509
|
if (!isObject4(entry)) return true;
|
|
25162
25510
|
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
25163
25511
|
const script = args[0];
|
|
@@ -25228,17 +25576,17 @@ function opencodePluginDirs(configDir, worktree) {
|
|
|
25228
25576
|
return [configDir, opencodeProjectDir(worktree)];
|
|
25229
25577
|
}
|
|
25230
25578
|
function opencodeProjectDir(worktree) {
|
|
25231
|
-
return
|
|
25579
|
+
return join17(worktree, OPENCODE_PROJECT_DIR);
|
|
25232
25580
|
}
|
|
25233
25581
|
function packageResolves(fromDir) {
|
|
25234
25582
|
for (let d = fromDir; ; d = dirname8(d)) {
|
|
25235
|
-
if (existsSync11(
|
|
25583
|
+
if (existsSync11(join17(d, NODE_MODULES_DIR, SERVER_KEY, PACKAGE_JSON_FILE))) return true;
|
|
25236
25584
|
if (dirname8(d) === d) return false;
|
|
25237
25585
|
}
|
|
25238
25586
|
}
|
|
25239
25587
|
function opencodeDirPlugins(dirs) {
|
|
25240
25588
|
const bundle = opencodePluginFile();
|
|
25241
|
-
const ownFile =
|
|
25589
|
+
const ownFile = join17(bundle, ...OPENCODE_PLUGIN_PATH).split("\\").join("/");
|
|
25242
25590
|
const isModule = (p) => OWN_PLUGIN_MODULES.includes(p);
|
|
25243
25591
|
const isPath = (p) => {
|
|
25244
25592
|
if (p === ownFile || p === `${FILE_URL_PREFIX}${ownFile}`) return true;
|
|
@@ -25248,20 +25596,20 @@ function opencodeDirPlugins(dirs) {
|
|
|
25248
25596
|
};
|
|
25249
25597
|
const out = [];
|
|
25250
25598
|
for (const dir of dirs) {
|
|
25251
|
-
const pdir =
|
|
25599
|
+
const pdir = join17(dir, OPENCODE_PLUGINS_DIR);
|
|
25252
25600
|
let names;
|
|
25253
25601
|
try {
|
|
25254
|
-
names =
|
|
25602
|
+
names = readdirSync7(pdir);
|
|
25255
25603
|
} catch {
|
|
25256
25604
|
continue;
|
|
25257
25605
|
}
|
|
25258
25606
|
for (const name of names) {
|
|
25259
|
-
const loose = OPENCODE_PLUGIN_EXTS.some((x) => name.endsWith(x)) ? [
|
|
25260
|
-
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}`))];
|
|
25261
25609
|
for (const f of files) {
|
|
25262
25610
|
let text;
|
|
25263
25611
|
try {
|
|
25264
|
-
const b =
|
|
25612
|
+
const b = readFileSync14(f);
|
|
25265
25613
|
if (b.length > OPENCODE_DIR_FILE_MAX) continue;
|
|
25266
25614
|
text = b.toString("utf8");
|
|
25267
25615
|
} catch {
|
|
@@ -25272,7 +25620,7 @@ function opencodeDirPlugins(dirs) {
|
|
|
25272
25620
|
const loads = lits.some((p) => {
|
|
25273
25621
|
if (isModule(p)) return packageResolves(dirname8(f));
|
|
25274
25622
|
const bare2 = p.startsWith(FILE_URL_PREFIX) ? p.slice(FILE_URL_PREFIX.length) : p;
|
|
25275
|
-
return existsSync11(
|
|
25623
|
+
return existsSync11(isAbsolute6(bare2) ? bare2 : resolve9(dirname8(f), bare2));
|
|
25276
25624
|
});
|
|
25277
25625
|
out.push({ file: f, loads });
|
|
25278
25626
|
}
|
|
@@ -25291,18 +25639,18 @@ function opencodeMcpOwn(entry) {
|
|
|
25291
25639
|
}
|
|
25292
25640
|
function opencodeFileValue(file2) {
|
|
25293
25641
|
if (!existsSync11(file2)) return {};
|
|
25294
|
-
return parseHostConfig("opencode", file2, hostText(
|
|
25642
|
+
return parseHostConfig("opencode", file2, hostText(readFileSync14(file2, "utf8")), "jsonc");
|
|
25295
25643
|
}
|
|
25296
25644
|
function opencodeValueListed(value) {
|
|
25297
25645
|
const bundle = opencodePluginFile();
|
|
25298
|
-
const own4 = [bundle,
|
|
25646
|
+
const own4 = [bundle, join17(bundle, ...OPENCODE_PLUGIN_PATH)];
|
|
25299
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;
|
|
25300
25648
|
const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
|
|
25301
25649
|
return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
|
|
25302
25650
|
}
|
|
25303
25651
|
function opencodeListed(file2, worktree) {
|
|
25304
25652
|
const dirs = [dirname8(file2), worktree];
|
|
25305
|
-
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;
|
|
25306
25654
|
return opencodeDirPlugin(opencodePluginDirs(dirname8(file2), worktree)) !== void 0;
|
|
25307
25655
|
}
|
|
25308
25656
|
function mcpWrong(row5, home, env, worktree) {
|
|
@@ -25324,7 +25672,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
25324
25672
|
function hookFile(row5, spec, home, env, worktree) {
|
|
25325
25673
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
25326
25674
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
25327
|
-
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);
|
|
25328
25676
|
return file2;
|
|
25329
25677
|
}
|
|
25330
25678
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -25335,7 +25683,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
25335
25683
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
25336
25684
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
25337
25685
|
if (row5.id === "codex") {
|
|
25338
|
-
const config4 = readParsed(row5.id,
|
|
25686
|
+
const config4 = readParsed(row5.id, join17(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
25339
25687
|
if (hostConfigValueAt(config4, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
25340
25688
|
}
|
|
25341
25689
|
} catch {
|
|
@@ -25380,13 +25728,13 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
25380
25728
|
function checkPiInstall(env, home, worktree) {
|
|
25381
25729
|
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
25382
25730
|
if (found !== void 0) return { ...pass2("D3"), detail: found };
|
|
25383
|
-
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]);
|
|
25384
25732
|
}
|
|
25385
25733
|
var OMP_PLUGINS_DIR = "plugins";
|
|
25386
25734
|
var OMP_LOCK_FILE = "omp-plugins.lock.json";
|
|
25387
25735
|
function readJson2(file2) {
|
|
25388
25736
|
try {
|
|
25389
|
-
const doc = JSON.parse(
|
|
25737
|
+
const doc = JSON.parse(readFileSync14(file2, "utf8"));
|
|
25390
25738
|
return typeof doc === "object" && doc !== null ? doc : void 0;
|
|
25391
25739
|
} catch {
|
|
25392
25740
|
return void 0;
|
|
@@ -25397,9 +25745,9 @@ function ownEntry(doc, key) {
|
|
|
25397
25745
|
return typeof map2 === "object" && map2 !== null ? map2[SERVER_KEY] : void 0;
|
|
25398
25746
|
}
|
|
25399
25747
|
function checkOmpInstall(home) {
|
|
25400
|
-
const dir =
|
|
25401
|
-
const lock =
|
|
25402
|
-
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);
|
|
25403
25751
|
const entry = ownEntry(readJson2(lock), "plugins");
|
|
25404
25752
|
const missing2 = (file2) => fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + file2, NATIVE_INSTALL.omp[0]);
|
|
25405
25753
|
if (typeof entry !== "object" || entry === null) return missing2(lock);
|
|
@@ -25436,10 +25784,10 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
25436
25784
|
}
|
|
25437
25785
|
function checkDoubleFire(agent, worktree) {
|
|
25438
25786
|
if (agent !== "claude-code" && agent !== "vscode") return pass2("D5b");
|
|
25439
|
-
const claude = parsedOrNull(agent,
|
|
25787
|
+
const claude = parsedOrNull(agent, join17(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
25440
25788
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
25441
25789
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
25442
|
-
const vscode = parsedOrNull(agent,
|
|
25790
|
+
const vscode = parsedOrNull(agent, join17(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
25443
25791
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
25444
25792
|
return hooksOn && useClaudeHooks ? fail3("D5b", D5B_DETAIL, D5B_FIX) : pass2("D5b");
|
|
25445
25793
|
}
|
|
@@ -25450,7 +25798,7 @@ function configPaths(row5, env, worktree) {
|
|
|
25450
25798
|
const mcp = mcpFile(row5, home, env);
|
|
25451
25799
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
25452
25800
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
25453
|
-
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) });
|
|
25454
25802
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
25455
25803
|
if (spec !== null) {
|
|
25456
25804
|
try {
|
|
@@ -25470,7 +25818,7 @@ function configPaths(row5, env, worktree) {
|
|
|
25470
25818
|
}
|
|
25471
25819
|
|
|
25472
25820
|
// src/core/ops/doctor-db.ts
|
|
25473
|
-
import { existsSync as existsSync12, statSync as
|
|
25821
|
+
import { existsSync as existsSync12, statSync as statSync7 } from "node:fs";
|
|
25474
25822
|
var unknown3 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
|
|
25475
25823
|
var pass3 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
|
|
25476
25824
|
var fail4 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -25481,7 +25829,7 @@ function isCorrupt2(err) {
|
|
|
25481
25829
|
const primary = code & SQLITE_PRIMARY_CODE_MASK;
|
|
25482
25830
|
return primary === SQLITE_CORRUPT_CODE || primary === SQLITE_NOTADB_CODE;
|
|
25483
25831
|
}
|
|
25484
|
-
var
|
|
25832
|
+
var message3 = (err) => err instanceof Error ? err.message : String(err);
|
|
25485
25833
|
async function loadSqlite2() {
|
|
25486
25834
|
try {
|
|
25487
25835
|
return await import(SQLITE_MODULE);
|
|
@@ -25512,7 +25860,7 @@ function orphanFiles(dbPath) {
|
|
|
25512
25860
|
const files = [];
|
|
25513
25861
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
25514
25862
|
const path8 = dbPath + suffix;
|
|
25515
|
-
if (existsSync12(path8)) files.push({ path: path8, bytes:
|
|
25863
|
+
if (existsSync12(path8)) files.push({ path: path8, bytes: statSync7(path8).size });
|
|
25516
25864
|
}
|
|
25517
25865
|
return files.length > 0 && !existsSync12(dbPath) ? files : [];
|
|
25518
25866
|
}
|
|
@@ -25540,7 +25888,7 @@ async function checkDb(project) {
|
|
|
25540
25888
|
return { row: pass3("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
25541
25889
|
} catch (err) {
|
|
25542
25890
|
if (isCorrupt2(err)) return { row: fail4(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale: false, integrityFailed: true, orphan: [] };
|
|
25543
|
-
return { row: unknown3("D8",
|
|
25891
|
+
return { row: unknown3("D8", message3(err)), ...clean };
|
|
25544
25892
|
} finally {
|
|
25545
25893
|
raw?.close();
|
|
25546
25894
|
}
|
|
@@ -25556,14 +25904,14 @@ async function checkIndex(project) {
|
|
|
25556
25904
|
const chunks = Number(cell(raw.prepare("SELECT count(*) FROM chunks").get()));
|
|
25557
25905
|
return pass3("D9", D9_INDEX_DETAIL(sources, chunks));
|
|
25558
25906
|
} catch (err) {
|
|
25559
|
-
return unknown3("D9",
|
|
25907
|
+
return unknown3("D9", message3(err));
|
|
25560
25908
|
} finally {
|
|
25561
25909
|
raw?.close();
|
|
25562
25910
|
}
|
|
25563
25911
|
}
|
|
25564
25912
|
|
|
25565
25913
|
// src/core/ops/doctor-hook.ts
|
|
25566
|
-
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";
|
|
25567
25915
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
25568
25916
|
import path7 from "node:path";
|
|
25569
25917
|
|
|
@@ -27397,7 +27745,7 @@ import { spawn as spawn3, spawnSync as spawnSync2 } from "node:child_process";
|
|
|
27397
27745
|
|
|
27398
27746
|
// src/setup/spawn-bin.ts
|
|
27399
27747
|
import { spawnSync } from "node:child_process";
|
|
27400
|
-
import { accessSync as accessSync2, constants as fsc, statSync as
|
|
27748
|
+
import { accessSync as accessSync2, constants as fsc, statSync as statSync8 } from "node:fs";
|
|
27401
27749
|
import path5 from "node:path";
|
|
27402
27750
|
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
27403
27751
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
@@ -27415,7 +27763,7 @@ function whichBin(bin, env, platform = process.platform) {
|
|
|
27415
27763
|
const f = path5.join(dir, n);
|
|
27416
27764
|
try {
|
|
27417
27765
|
accessSync2(f, fsc.X_OK);
|
|
27418
|
-
if (
|
|
27766
|
+
if (statSync8(f).isFile()) return f;
|
|
27419
27767
|
} catch {
|
|
27420
27768
|
}
|
|
27421
27769
|
}
|
|
@@ -27617,7 +27965,7 @@ function loadFixture(bundleDir2, agent) {
|
|
|
27617
27965
|
if (!existsSync14(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
27618
27966
|
let all;
|
|
27619
27967
|
try {
|
|
27620
|
-
all = JSON.parse(hostText(
|
|
27968
|
+
all = JSON.parse(hostText(readFileSync15(file2, "utf8")));
|
|
27621
27969
|
} catch (err) {
|
|
27622
27970
|
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
27623
27971
|
}
|
|
@@ -27709,7 +28057,7 @@ async function mediaProbe(i, timeoutMs) {
|
|
|
27709
28057
|
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-media-"));
|
|
27710
28058
|
try {
|
|
27711
28059
|
const filePath = path7.join(home, "d5-media-probe.png");
|
|
27712
|
-
|
|
28060
|
+
writeFileSync3(filePath, Buffer.concat([PNG_SIGNATURE, Buffer.alloc(OUTPUT_CAP + 1)]));
|
|
27713
28061
|
const node3 = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home });
|
|
27714
28062
|
const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
27715
28063
|
cwd: i.bundleDir,
|
|
@@ -27736,9 +28084,9 @@ async function ownProbe(i, timeoutMs) {
|
|
|
27736
28084
|
try {
|
|
27737
28085
|
const cfg = path7.join(home, ".claude");
|
|
27738
28086
|
const refs = path7.join(cfg, "skills", "d5-probe", "references");
|
|
27739
|
-
|
|
28087
|
+
mkdirSync5(refs, { recursive: true });
|
|
27740
28088
|
const filePath = path7.join(refs, "d5-own-probe.md");
|
|
27741
|
-
|
|
28089
|
+
writeFileSync3(filePath, "# d5 own probe\n".repeat(Math.ceil((OUTPUT_CAP + 1) / 15)));
|
|
27742
28090
|
const node3 = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, CLAUDE_CONFIG_DIR: cfg });
|
|
27743
28091
|
const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
27744
28092
|
cwd: i.bundleDir,
|
|
@@ -27892,24 +28240,24 @@ async function checkHookRoundTrip(i) {
|
|
|
27892
28240
|
}
|
|
27893
28241
|
|
|
27894
28242
|
// src/core/ops/db-heal.ts
|
|
27895
|
-
import { existsSync as existsSync15, mkdirSync as
|
|
27896
|
-
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";
|
|
27897
28245
|
|
|
27898
28246
|
// src/core/store/owners.ts
|
|
27899
|
-
import { mkdirSync as
|
|
27900
|
-
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";
|
|
27901
28249
|
function ownersDir(configDir, projectKey) {
|
|
27902
|
-
return
|
|
28250
|
+
return join18(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
27903
28251
|
}
|
|
27904
28252
|
function ownerFile(configDir, projectKey, serverId) {
|
|
27905
|
-
return
|
|
28253
|
+
return join18(ownersDir(configDir, projectKey), serverId + OWNER_PID_EXT);
|
|
27906
28254
|
}
|
|
27907
|
-
function
|
|
28255
|
+
function errCode3(err) {
|
|
27908
28256
|
return err.code;
|
|
27909
28257
|
}
|
|
27910
28258
|
function writeOwnerPid(configDir, projectKey, serverId) {
|
|
27911
|
-
|
|
27912
|
-
|
|
28259
|
+
mkdirSync6(ownersDir(configDir, projectKey), { recursive: true });
|
|
28260
|
+
writeFileSync4(ownerFile(configDir, projectKey, serverId), String(process.pid), "utf8");
|
|
27913
28261
|
}
|
|
27914
28262
|
function removeOwnerPid(configDir, projectKey, serverId) {
|
|
27915
28263
|
rmSync3(ownerFile(configDir, projectKey, serverId), { force: true });
|
|
@@ -27920,8 +28268,8 @@ function isLive(pid) {
|
|
|
27920
28268
|
process.kill(pid, 0);
|
|
27921
28269
|
return true;
|
|
27922
28270
|
} catch (err) {
|
|
27923
|
-
if (
|
|
27924
|
-
if (
|
|
28271
|
+
if (errCode3(err) === "ESRCH") return false;
|
|
28272
|
+
if (errCode3(err) === "EPERM") return true;
|
|
27925
28273
|
throw err;
|
|
27926
28274
|
}
|
|
27927
28275
|
}
|
|
@@ -27929,20 +28277,20 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
27929
28277
|
const dir = ownersDir(configDir, projectKey);
|
|
27930
28278
|
let names;
|
|
27931
28279
|
try {
|
|
27932
|
-
names =
|
|
28280
|
+
names = readdirSync8(dir);
|
|
27933
28281
|
} catch (err) {
|
|
27934
|
-
if (
|
|
28282
|
+
if (errCode3(err) === "ENOENT") return [];
|
|
27935
28283
|
throw err;
|
|
27936
28284
|
}
|
|
27937
28285
|
const live = [];
|
|
27938
28286
|
for (const name of names) {
|
|
27939
28287
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
27940
|
-
const file2 =
|
|
28288
|
+
const file2 = join18(dir, name);
|
|
27941
28289
|
let text;
|
|
27942
28290
|
try {
|
|
27943
|
-
text =
|
|
28291
|
+
text = readFileSync16(file2, "utf8");
|
|
27944
28292
|
} catch (err) {
|
|
27945
|
-
if (
|
|
28293
|
+
if (errCode3(err) === "ENOENT") continue;
|
|
27946
28294
|
throw err;
|
|
27947
28295
|
}
|
|
27948
28296
|
const serverId = basename3(name, OWNER_PID_EXT);
|
|
@@ -28009,11 +28357,11 @@ function utcStamp(now) {
|
|
|
28009
28357
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
28010
28358
|
}
|
|
28011
28359
|
function makeOrphanDir(projectDir) {
|
|
28012
|
-
const base =
|
|
28360
|
+
const base = join19(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
28013
28361
|
for (let n = 1; ; n += 1) {
|
|
28014
28362
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
28015
28363
|
try {
|
|
28016
|
-
|
|
28364
|
+
mkdirSync7(dir);
|
|
28017
28365
|
return dir;
|
|
28018
28366
|
} catch (err) {
|
|
28019
28367
|
if (err.code !== "EEXIST") throw err;
|
|
@@ -28026,7 +28374,7 @@ async function healOrphan(project, files, row5) {
|
|
|
28026
28374
|
try {
|
|
28027
28375
|
dir = makeOrphanDir(dirname9(project.dbPath));
|
|
28028
28376
|
for (const f of files) {
|
|
28029
|
-
const to =
|
|
28377
|
+
const to = join19(dir, basename4(f.path));
|
|
28030
28378
|
renameWithRetry(f.path, to);
|
|
28031
28379
|
moved.push({ path: to, bytes: f.bytes });
|
|
28032
28380
|
}
|
|
@@ -28044,8 +28392,8 @@ function keyIsTyped(key) {
|
|
|
28044
28392
|
if (key.length === 0) return false;
|
|
28045
28393
|
for (const ch of key) {
|
|
28046
28394
|
const upper = ch >= "A" && ch <= "Z";
|
|
28047
|
-
const
|
|
28048
|
-
if (!upper && !
|
|
28395
|
+
const digit2 = ch >= "0" && ch <= "9";
|
|
28396
|
+
if (!upper && !digit2 && ch !== "_") return false;
|
|
28049
28397
|
}
|
|
28050
28398
|
return true;
|
|
28051
28399
|
}
|
|
@@ -28124,8 +28472,8 @@ function unsupportedHostOf(sig) {
|
|
|
28124
28472
|
|
|
28125
28473
|
// src/core/ops/doctor-issue.ts
|
|
28126
28474
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
28127
|
-
import { closeSync as closeSync2, existsSync as existsSync16, fstatSync, mkdirSync as
|
|
28128
|
-
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";
|
|
28129
28477
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
28130
28478
|
function tildeOf(env) {
|
|
28131
28479
|
const home = homeDirOf(env);
|
|
@@ -28181,8 +28529,8 @@ function onPath(env, tool) {
|
|
|
28181
28529
|
const out = [];
|
|
28182
28530
|
for (const dir of (envValue(env, "PATH") ?? "").split(delimiter)) {
|
|
28183
28531
|
if (dir === "") continue;
|
|
28184
|
-
for (const n of names) if (existsSync16(
|
|
28185
|
-
out.push(
|
|
28532
|
+
for (const n of names) if (existsSync16(join20(dir, n))) {
|
|
28533
|
+
out.push(join20(dir, n));
|
|
28186
28534
|
break;
|
|
28187
28535
|
}
|
|
28188
28536
|
}
|
|
@@ -28210,9 +28558,11 @@ function hookLogTail(env) {
|
|
|
28210
28558
|
}
|
|
28211
28559
|
async function journalRows(ctx) {
|
|
28212
28560
|
const head2 = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
28213
|
-
|
|
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})`];
|
|
28214
28564
|
try {
|
|
28215
|
-
const db = await openDb(
|
|
28565
|
+
const db = await openDb(p.project, { readOnly: true });
|
|
28216
28566
|
try {
|
|
28217
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();
|
|
28218
28568
|
const cell5 = (v) => v === null || v === void 0 ? "" : String(v);
|
|
@@ -28228,8 +28578,8 @@ function agentConfig(adapter, env, worktree) {
|
|
|
28228
28578
|
const home = homeDirOf(env);
|
|
28229
28579
|
const files = configPaths(adapter, env, worktree);
|
|
28230
28580
|
if (home !== null) {
|
|
28231
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
28232
|
-
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) });
|
|
28233
28583
|
}
|
|
28234
28584
|
const out = [];
|
|
28235
28585
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -28242,7 +28592,7 @@ function agentConfig(adapter, env, worktree) {
|
|
|
28242
28592
|
}
|
|
28243
28593
|
let text = "";
|
|
28244
28594
|
try {
|
|
28245
|
-
text =
|
|
28595
|
+
text = readFileSync17(f.path, "utf8");
|
|
28246
28596
|
} catch (err) {
|
|
28247
28597
|
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
28248
28598
|
continue;
|
|
@@ -28271,6 +28621,7 @@ async function buildIssueBody(i) {
|
|
|
28271
28621
|
const failRows = i.rows.filter((r) => r.status !== "PASS");
|
|
28272
28622
|
const envNames = DOCTOR_ENV_NAMES.map((n) => i.env[n] === void 0 ? `${n} (unset)` : `${n}=${i.env[n]}`);
|
|
28273
28623
|
const pathTools = DOCTOR_PATH_TOOLS.map((t) => `PATH holds ${t}: ${onPath(i.env, t).join(", ") || "(absent)"}`);
|
|
28624
|
+
const p = projectOrMissing(i.ctx);
|
|
28274
28625
|
const sections = {
|
|
28275
28626
|
"Summary": [summaryOf(agent, i.rows, i.unsupported)],
|
|
28276
28627
|
"ctx-report": [i.table],
|
|
@@ -28281,7 +28632,7 @@ async function buildIssueBody(i) {
|
|
|
28281
28632
|
],
|
|
28282
28633
|
"Hook errors": ["hook-errors.log, last " + DOCTOR_HOOK_LOG_LINES + " lines (UTC):", "```", ...hookLogTail(i.env), "```"],
|
|
28283
28634
|
"Journal rows": ["events, newest first, last " + DOCTOR_JOURNAL_ROWS + " (bodies stay local):", ...await journalRows(i.ctx)],
|
|
28284
|
-
"Agent config": agentConfig(i.adapter, i.env,
|
|
28635
|
+
"Agent config": agentConfig(i.adapter, i.env, "project" in p ? p.project.worktree : process.cwd()),
|
|
28285
28636
|
"Expected": ["Expected: <the agent fills this in: what should happen, with the byte count>"],
|
|
28286
28637
|
"Steps": [
|
|
28287
28638
|
"Reproduced: <yes (2 of 2) or 1 of 2>",
|
|
@@ -28302,7 +28653,7 @@ async function buildIssueBody(i) {
|
|
|
28302
28653
|
`git: ${gitVersion(i.env)}`,
|
|
28303
28654
|
...pathTools,
|
|
28304
28655
|
...envNames,
|
|
28305
|
-
`Project: ${
|
|
28656
|
+
"project" in p ? `Project: ${p.project.worktree} (key ${p.project.projectKey})` : `Project: ${D7_NO_PROJECT_DETAIL(p.missing)}`,
|
|
28306
28657
|
"Filed by: <your agent name, version, model id>"
|
|
28307
28658
|
]
|
|
28308
28659
|
};
|
|
@@ -28313,10 +28664,10 @@ async function buildIssueBody(i) {
|
|
|
28313
28664
|
async function writeIssueReport(i) {
|
|
28314
28665
|
const tilde = tildeOf(i.env);
|
|
28315
28666
|
const body = await buildIssueBody(i);
|
|
28316
|
-
const dir =
|
|
28317
|
-
|
|
28318
|
-
const file2 =
|
|
28319
|
-
|
|
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);
|
|
28320
28671
|
const shown2 = tilde(file2);
|
|
28321
28672
|
const title = issueTitle(i.adapter.id, i.rows, i.unsupported);
|
|
28322
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}`];
|
|
@@ -28328,6 +28679,25 @@ function formUrl(title, summary) {
|
|
|
28328
28679
|
return full.length < ISSUE_URL_MAX ? full : base;
|
|
28329
28680
|
}
|
|
28330
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
|
+
|
|
28331
28701
|
// src/core/tools/doctor.ts
|
|
28332
28702
|
var ctxDoctorSchema = external_exports.object({}).strict();
|
|
28333
28703
|
function lineOf2(err) {
|
|
@@ -28341,10 +28711,10 @@ async function guard(id, run) {
|
|
|
28341
28711
|
return { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail: lineOf2(err) };
|
|
28342
28712
|
}
|
|
28343
28713
|
}
|
|
28344
|
-
async function codexDb(
|
|
28345
|
-
if (adapter.id !== "codex" || !existsSync17(
|
|
28714
|
+
async function codexDb(project, adapter) {
|
|
28715
|
+
if (adapter.id !== "codex" || !existsSync17(project.dbPath)) return null;
|
|
28346
28716
|
try {
|
|
28347
|
-
return await openDb(
|
|
28717
|
+
return await openDb(project, { readOnly: true });
|
|
28348
28718
|
} catch {
|
|
28349
28719
|
return null;
|
|
28350
28720
|
}
|
|
@@ -28355,12 +28725,12 @@ function d1UpdateCommand(agent, env, other) {
|
|
|
28355
28725
|
function unsupportedRow(id, h) {
|
|
28356
28726
|
return { id, label: DOCTOR_LABEL[id], status: "WARN", detail: UNSUPPORTED_HOST_LINE(h.name) };
|
|
28357
28727
|
}
|
|
28358
|
-
async function hookRow(ctx, adapter, host) {
|
|
28359
|
-
const db = await codexDb(
|
|
28728
|
+
async function hookRow(ctx, project, adapter, host) {
|
|
28729
|
+
const db = await codexDb(project, adapter);
|
|
28360
28730
|
const runStart = Date.now();
|
|
28361
28731
|
try {
|
|
28362
28732
|
const row5 = await checkHookRoundTrip({
|
|
28363
|
-
worktree:
|
|
28733
|
+
worktree: project.worktree,
|
|
28364
28734
|
agent: adapter.id,
|
|
28365
28735
|
bundleDir: host.bundleDir,
|
|
28366
28736
|
env: buildChildEnv(host.env),
|
|
@@ -28378,18 +28748,20 @@ async function hookRow(ctx, adapter, host) {
|
|
|
28378
28748
|
}
|
|
28379
28749
|
}
|
|
28380
28750
|
function ownServerId(configDir, projectKey) {
|
|
28381
|
-
const dir =
|
|
28751
|
+
const dir = join21(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
28382
28752
|
if (!existsSync17(dir)) return "";
|
|
28383
|
-
for (const name of
|
|
28753
|
+
for (const name of readdirSync9(dir)) {
|
|
28384
28754
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
28385
|
-
if (
|
|
28755
|
+
if (readFileSync18(join21(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
28386
28756
|
}
|
|
28387
28757
|
return "";
|
|
28388
28758
|
}
|
|
28389
28759
|
async function runDoctorChecks(ctx, adapter, host0) {
|
|
28390
28760
|
const host = adapter.id === "codex" ? { ...host0, env: { ...host0.env, CODEX_HOME: codexRunDirOf(host0.env, homeDirOf(host0.env) ?? "", host0.bundleDir) } } : host0;
|
|
28391
28761
|
const env = host.env;
|
|
28392
|
-
const
|
|
28762
|
+
const p = projectOrMissing(ctx);
|
|
28763
|
+
if ("missing" in p) return noProjectRows(ctx, adapter, host, p.missing);
|
|
28764
|
+
const project = p.project;
|
|
28393
28765
|
const other = adapter.installMode === "in-process" ? void 0 : unsupportedHostOf({ clientName: ctx.clientInfo?.name, bundleDir: host.bundleDir, env });
|
|
28394
28766
|
let integrityFailed = false;
|
|
28395
28767
|
let orphan = [];
|
|
@@ -28399,7 +28771,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
28399
28771
|
D3: () => other !== void 0 ? unsupportedRow("D3", other) : checkHostConfig(adapter, env, project.worktree),
|
|
28400
28772
|
// D-UNSUPPORTED-HOSTS-1
|
|
28401
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)) }),
|
|
28402
|
-
D5: () => other !== void 0 ? unsupportedRow("D5", other) : hookRow(ctx, adapter, host),
|
|
28774
|
+
D5: () => other !== void 0 ? unsupportedRow("D5", other) : hookRow(ctx, project, adapter, host),
|
|
28403
28775
|
D5b: () => checkDoubleFire(adapter.id, project.worktree),
|
|
28404
28776
|
D6: () => checkMcp(ctx, adapter),
|
|
28405
28777
|
D7: () => checkProject({ project, adapter, piCwd: host.piCwd }),
|
|
@@ -28429,6 +28801,28 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
28429
28801
|
});
|
|
28430
28802
|
return rows;
|
|
28431
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
|
+
}
|
|
28432
28826
|
function reportEnv(env) {
|
|
28433
28827
|
const out = {};
|
|
28434
28828
|
for (const key of Object.keys(REPORT_ENV_ENUMS)) {
|
|
@@ -28438,7 +28832,7 @@ function reportEnv(env) {
|
|
|
28438
28832
|
return out;
|
|
28439
28833
|
}
|
|
28440
28834
|
async function doctorReply(ctx, host) {
|
|
28441
|
-
const adapter = getAdapter(ctx.project.agent);
|
|
28835
|
+
const adapter = getAdapter(ctx.agent ?? ctx.project.agent);
|
|
28442
28836
|
const runtime = runtimeInfo(host.env, ctx.signal);
|
|
28443
28837
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
28444
28838
|
const failed = rows.some((r) => r.status === "FAIL");
|
|
@@ -28460,9 +28854,11 @@ async function doctorReply(ctx, host) {
|
|
|
28460
28854
|
const whole2 = [envLine2, table3, ...docs, ...info, ...notes].join("\n");
|
|
28461
28855
|
const bytes5 = Buffer.byteLength(whole2, "utf8");
|
|
28462
28856
|
if (bytes5 <= REPORT_CAP) return { text: whole2, isError: false, sandboxBytes: bytes5 };
|
|
28463
|
-
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);
|
|
28464
28860
|
try {
|
|
28465
|
-
indexText(db,
|
|
28861
|
+
indexText(db, p.project, ctx.sessionId, REPORT_SOURCE_LABEL, whole2, "text");
|
|
28466
28862
|
} finally {
|
|
28467
28863
|
closeDb(db);
|
|
28468
28864
|
}
|
|
@@ -28487,9 +28883,9 @@ var ctxDoctor = Object.freeze({
|
|
|
28487
28883
|
});
|
|
28488
28884
|
|
|
28489
28885
|
// src/core/tools/execute.ts
|
|
28490
|
-
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";
|
|
28491
28887
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
28492
|
-
import { dirname as dirname12, join as
|
|
28888
|
+
import { dirname as dirname12, join as join22, parse as parse3, resolve as resolve11 } from "node:path";
|
|
28493
28889
|
|
|
28494
28890
|
// src/core/sandbox/win-build.ts
|
|
28495
28891
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -28658,9 +29054,9 @@ async function handler3(raw, ctx) {
|
|
|
28658
29054
|
if (takesDashC(input.language, runtime)) {
|
|
28659
29055
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
28660
29056
|
} else {
|
|
28661
|
-
tmpDir = mkdtempSync2(
|
|
28662
|
-
const file2 =
|
|
28663
|
-
|
|
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");
|
|
28664
29060
|
argv = scriptArgv(input.language, runtime, file2);
|
|
28665
29061
|
}
|
|
28666
29062
|
if (input.background === true) {
|
|
@@ -28695,12 +29091,12 @@ var ctxExecute = {
|
|
|
28695
29091
|
};
|
|
28696
29092
|
|
|
28697
29093
|
// src/core/tools/index.ts
|
|
28698
|
-
import { existsSync as existsSync19, readFileSync as
|
|
28699
|
-
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";
|
|
28700
29096
|
|
|
28701
29097
|
// src/core/index/walk.ts
|
|
28702
|
-
import { readdirSync as
|
|
28703
|
-
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";
|
|
28704
29100
|
var GITIGNORE = ".gitignore";
|
|
28705
29101
|
var GIT_DIR = ".git";
|
|
28706
29102
|
function walkDir(root, containmentRoot) {
|
|
@@ -28709,19 +29105,19 @@ function walkDir(root, containmentRoot) {
|
|
|
28709
29105
|
const found = [];
|
|
28710
29106
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
28711
29107
|
found.sort(compareFound);
|
|
28712
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
29108
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join23(...f.dir, f.name) }));
|
|
28713
29109
|
}
|
|
28714
29110
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
28715
29111
|
let entries;
|
|
28716
29112
|
try {
|
|
28717
|
-
entries =
|
|
29113
|
+
entries = readdirSync10(abs, { withFileTypes: true });
|
|
28718
29114
|
} catch {
|
|
28719
29115
|
return;
|
|
28720
29116
|
}
|
|
28721
|
-
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;
|
|
28722
29118
|
for (const e of entries) {
|
|
28723
29119
|
if (e.name === GIT_DIR) continue;
|
|
28724
|
-
const path8 =
|
|
29120
|
+
const path8 = join23(abs, e.name);
|
|
28725
29121
|
let isDir = e.isDirectory();
|
|
28726
29122
|
let isFile = e.isFile();
|
|
28727
29123
|
let target = path8;
|
|
@@ -28733,7 +29129,7 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
28733
29129
|
continue;
|
|
28734
29130
|
}
|
|
28735
29131
|
if (!isInside(contain, resolved)) continue;
|
|
28736
|
-
const st =
|
|
29132
|
+
const st = statSync9(resolved);
|
|
28737
29133
|
isDir = st.isDirectory();
|
|
28738
29134
|
isFile = st.isFile();
|
|
28739
29135
|
target = resolved;
|
|
@@ -28761,7 +29157,7 @@ function compareFound(a, b) {
|
|
|
28761
29157
|
function readRules(file2, base) {
|
|
28762
29158
|
let body;
|
|
28763
29159
|
try {
|
|
28764
|
-
body =
|
|
29160
|
+
body = readFileSync19(file2, "utf8");
|
|
28765
29161
|
} catch {
|
|
28766
29162
|
return [];
|
|
28767
29163
|
}
|
|
@@ -28844,12 +29240,13 @@ function globSeg(pat, name) {
|
|
|
28844
29240
|
}
|
|
28845
29241
|
|
|
28846
29242
|
// src/core/sandbox/fetch.ts
|
|
28847
|
-
import {
|
|
29243
|
+
import { randomBytes } from "node:crypto";
|
|
29244
|
+
import { readFileSync as readFileSync20 } from "node:fs";
|
|
28848
29245
|
import { lookup } from "node:dns/promises";
|
|
28849
29246
|
import http from "node:http";
|
|
28850
29247
|
import https from "node:https";
|
|
28851
29248
|
import { BlockList, isIP } from "node:net";
|
|
28852
|
-
import { join as
|
|
29249
|
+
import { join as join24 } from "node:path";
|
|
28853
29250
|
import { connect as tlsConnect } from "node:tls";
|
|
28854
29251
|
var PRIVATE_RANGES = [
|
|
28855
29252
|
["127.0.0.0", 8, "ipv4"],
|
|
@@ -28878,6 +29275,26 @@ var PRIVATE_RANGES = [
|
|
|
28878
29275
|
];
|
|
28879
29276
|
var BLOCKED = new BlockList();
|
|
28880
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
|
+
}
|
|
28881
29298
|
var STATUS_OK_FIRST = 200;
|
|
28882
29299
|
var STATUS_OK_END = 300;
|
|
28883
29300
|
var STATUS_REDIRECT = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
@@ -28888,7 +29305,7 @@ function baseHeaders() {
|
|
|
28888
29305
|
if (namedHeaders === void 0) {
|
|
28889
29306
|
let version4 = UA_DEV_VERSION;
|
|
28890
29307
|
try {
|
|
28891
|
-
const v = JSON.parse(
|
|
29308
|
+
const v = JSON.parse(readFileSync20(join24(ownBundleDir(), D1_PACKAGE_FILE), "utf8")).version;
|
|
28892
29309
|
if (typeof v === "string" && v !== "") version4 = v;
|
|
28893
29310
|
} catch {
|
|
28894
29311
|
}
|
|
@@ -28980,8 +29397,15 @@ function checkAddress(hostname2, address) {
|
|
|
28980
29397
|
throw new CtxError("SSRF", { host: hostname2 });
|
|
28981
29398
|
}
|
|
28982
29399
|
}
|
|
28983
|
-
async function
|
|
28984
|
-
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) {
|
|
28985
29409
|
let addrs;
|
|
28986
29410
|
try {
|
|
28987
29411
|
addrs = await lookup(host, { all: true });
|
|
@@ -28990,9 +29414,26 @@ async function resolveTarget(u, signal) {
|
|
|
28990
29414
|
}
|
|
28991
29415
|
if (signal.aborted) throw fail6("ABORT_ERR");
|
|
28992
29416
|
if (addrs.length === 0) throw fail6("ENOTFOUND");
|
|
28993
|
-
|
|
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);
|
|
28994
29423
|
return { host, port: u.port === "" ? defaultPort(u.protocol) : Number(u.port), address: addrs[0].address };
|
|
28995
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
|
+
}
|
|
28996
29437
|
function tlsName(host) {
|
|
28997
29438
|
return isIP(host) === 0 ? host : void 0;
|
|
28998
29439
|
}
|
|
@@ -29050,9 +29491,8 @@ async function safeFetch(url4, signal) {
|
|
|
29050
29491
|
for (let hop = 0; ; hop += 1) {
|
|
29051
29492
|
if (signal.aborted) throw fail6("ABORT_ERR");
|
|
29052
29493
|
const proxy = pickProxy(current);
|
|
29053
|
-
|
|
29054
|
-
|
|
29055
|
-
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);
|
|
29056
29496
|
const res = await request(current, conn, proxy, signal);
|
|
29057
29497
|
const status = res.statusCode ?? 0;
|
|
29058
29498
|
const location = res.headers.location;
|
|
@@ -29201,7 +29641,7 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
29201
29641
|
readNgramReferences(ngramCount - dictSize + dict1AtomCount, dictSize + dict2AtomCount);
|
|
29202
29642
|
readNgramReferences(dictSize - dict1AtomCount, dict1AtomCount);
|
|
29203
29643
|
const pool = new Uint16Array(poolSize);
|
|
29204
|
-
let
|
|
29644
|
+
let write = 0;
|
|
29205
29645
|
for (let index = 0; index < ngramIndex; index++) {
|
|
29206
29646
|
for (let half = 0; half < 2; half++) {
|
|
29207
29647
|
const source = references[index * 2 + half];
|
|
@@ -29210,9 +29650,9 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
29210
29650
|
let read3 = start[source];
|
|
29211
29651
|
const readEnd = read3 + length[source];
|
|
29212
29652
|
while (read3 < readEnd)
|
|
29213
|
-
pool[
|
|
29653
|
+
pool[write++] = pool[read3++];
|
|
29214
29654
|
} else {
|
|
29215
|
-
pool[
|
|
29655
|
+
pool[write++] = value;
|
|
29216
29656
|
}
|
|
29217
29657
|
}
|
|
29218
29658
|
}
|
|
@@ -29436,8 +29876,8 @@ var EntityDecoder = class {
|
|
|
29436
29876
|
while (offset < inputLength) {
|
|
29437
29877
|
const char = input.charCodeAt(offset);
|
|
29438
29878
|
if (isNumber2(char) || isHexadecimalCharacter(char)) {
|
|
29439
|
-
const
|
|
29440
|
-
result = result * 16 +
|
|
29879
|
+
const digit2 = char <= CharCodes.NINE ? char - CharCodes.ZERO : (char | TO_LOWER_BIT) - CharCodes.LOWER_A + 10;
|
|
29880
|
+
result = result * 16 + digit2;
|
|
29441
29881
|
consumed += 1;
|
|
29442
29882
|
offset += 1;
|
|
29443
29883
|
} else {
|
|
@@ -29465,13 +29905,13 @@ var EntityDecoder = class {
|
|
|
29465
29905
|
let { result } = this;
|
|
29466
29906
|
let { consumed } = this;
|
|
29467
29907
|
while (offset < inputLength) {
|
|
29468
|
-
const
|
|
29469
|
-
if (
|
|
29908
|
+
const digit2 = input.charCodeAt(offset) - CharCodes.ZERO;
|
|
29909
|
+
if (digit2 >>> 0 > 9) {
|
|
29470
29910
|
this.result = result;
|
|
29471
29911
|
this.consumed = consumed;
|
|
29472
|
-
return this.emitNumericEntity(
|
|
29912
|
+
return this.emitNumericEntity(digit2 + CharCodes.ZERO, 2);
|
|
29473
29913
|
}
|
|
29474
|
-
result = result * 10 +
|
|
29914
|
+
result = result * 10 + digit2;
|
|
29475
29915
|
consumed += 1;
|
|
29476
29916
|
offset += 1;
|
|
29477
29917
|
}
|
|
@@ -32906,7 +33346,7 @@ function kindOfType(contentType) {
|
|
|
32906
33346
|
}
|
|
32907
33347
|
function readUtf8(absPath) {
|
|
32908
33348
|
try {
|
|
32909
|
-
return utf8.decode(
|
|
33349
|
+
return utf8.decode(readFileSync21(absPath));
|
|
32910
33350
|
} catch {
|
|
32911
33351
|
return void 0;
|
|
32912
33352
|
}
|
|
@@ -32921,10 +33361,10 @@ function pathItems(input, project) {
|
|
|
32921
33361
|
const abs = resolve12(project.worktree, input.path);
|
|
32922
33362
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
32923
33363
|
const base = relative5(project.worktree, abs);
|
|
32924
|
-
if (
|
|
33364
|
+
if (statSync10(abs).isDirectory()) {
|
|
32925
33365
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
32926
33366
|
sourceKind: "path",
|
|
32927
|
-
label: pathLabel(
|
|
33367
|
+
label: pathLabel(join25(base, f.relPath)),
|
|
32928
33368
|
kind: kindOfPath(f.relPath),
|
|
32929
33369
|
read: () => readUtf8(f.absPath)
|
|
32930
33370
|
}));
|
|
@@ -33048,7 +33488,7 @@ function purgeScope(db, scope, input) {
|
|
|
33048
33488
|
const chunks = deleteChunkRows(raw, "all");
|
|
33049
33489
|
return changes(raw, "DELETE FROM events") + chunks + changes(raw, "DELETE FROM sources");
|
|
33050
33490
|
}
|
|
33051
|
-
function
|
|
33491
|
+
function isBusy2(err) {
|
|
33052
33492
|
const code = err?.errcode;
|
|
33053
33493
|
return typeof code === "number" && (code & SQLITE_PRIMARY_CODE_MASK) === SQLITE_BUSY_CODE;
|
|
33054
33494
|
}
|
|
@@ -33066,7 +33506,7 @@ async function handler5(input, ctx) {
|
|
|
33066
33506
|
closeDb(db);
|
|
33067
33507
|
}
|
|
33068
33508
|
} catch (err) {
|
|
33069
|
-
if (
|
|
33509
|
+
if (isBusy2(err)) return reply2(PURGE_BUSY_LINE, true);
|
|
33070
33510
|
throw err;
|
|
33071
33511
|
}
|
|
33072
33512
|
}
|
|
@@ -33464,22 +33904,22 @@ var ctxStats = Object.freeze({
|
|
|
33464
33904
|
});
|
|
33465
33905
|
|
|
33466
33906
|
// src/core/ops/host-write.ts
|
|
33467
|
-
import { copyFileSync, existsSync as existsSync20, mkdirSync as
|
|
33468
|
-
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";
|
|
33469
33909
|
function defaultWrite(file2, text) {
|
|
33470
|
-
|
|
33910
|
+
writeFileSync7(file2, text, "utf8");
|
|
33471
33911
|
}
|
|
33472
33912
|
function hostConfigPath(agent, home, env) {
|
|
33473
33913
|
const own4 = OWN_MCP_ENTRY[agent];
|
|
33474
33914
|
if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
|
|
33475
33915
|
switch (agent) {
|
|
33476
33916
|
case "opencode":
|
|
33477
|
-
return
|
|
33917
|
+
return join26(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
33478
33918
|
// D-WIN-OPENCODE-DIR-1
|
|
33479
33919
|
case "pi":
|
|
33480
|
-
return
|
|
33920
|
+
return join26(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
33481
33921
|
case "gemini":
|
|
33482
|
-
return
|
|
33922
|
+
return join26(geminiDirOf(env, home), SETTINGS_FILE);
|
|
33483
33923
|
// D-R38-GEMINI-HOME-1
|
|
33484
33924
|
case "copilot-cli":
|
|
33485
33925
|
return null;
|
|
@@ -33487,7 +33927,7 @@ function hostConfigPath(agent, home, env) {
|
|
|
33487
33927
|
return null;
|
|
33488
33928
|
// ADR-0026 decision 8 (D-OMP-UPGRADE-1): OMP loads the plugin from its own store; no MCP entry, nothing under ~/.pi
|
|
33489
33929
|
default:
|
|
33490
|
-
return
|
|
33930
|
+
return join26(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
33491
33931
|
}
|
|
33492
33932
|
}
|
|
33493
33933
|
function cell3(value) {
|
|
@@ -33496,14 +33936,14 @@ function cell3(value) {
|
|
|
33496
33936
|
function toRow(file2, edit) {
|
|
33497
33937
|
return { area: file2 + UPGRADE_AREA_KEY_SEP + edit.path, before: cell3(edit.before), after: cell3(edit.after) };
|
|
33498
33938
|
}
|
|
33499
|
-
function writeWithRollback(file2, text,
|
|
33939
|
+
function writeWithRollback(file2, text, write, atomic) {
|
|
33500
33940
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
33501
33941
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
33502
33942
|
const had = existsSync20(file2);
|
|
33503
|
-
|
|
33943
|
+
mkdirSync9(dirname14(file2), { recursive: true });
|
|
33504
33944
|
if (had) copyFileSync(file2, trash);
|
|
33505
33945
|
try {
|
|
33506
|
-
|
|
33946
|
+
write(tmp, text);
|
|
33507
33947
|
renameWithRetry(tmp, file2, atomic);
|
|
33508
33948
|
} catch (err) {
|
|
33509
33949
|
removeTmpFile(tmp, atomic);
|
|
@@ -33537,15 +33977,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
33537
33977
|
}
|
|
33538
33978
|
|
|
33539
33979
|
// src/core/ops/uninstall.ts
|
|
33540
|
-
import { existsSync as existsSync21, readdirSync as
|
|
33541
|
-
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";
|
|
33542
33982
|
function row2(area, before, after) {
|
|
33543
33983
|
return { area, before, after };
|
|
33544
33984
|
}
|
|
33545
33985
|
function stopServers(configDir, projectKey) {
|
|
33546
33986
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
33547
|
-
const dir =
|
|
33548
|
-
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");
|
|
33549
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 };
|
|
33550
33990
|
}
|
|
33551
33991
|
function rootOrNull(adapter, env) {
|
|
@@ -33563,14 +34003,14 @@ function removeCache(adapter, env, configDir) {
|
|
|
33563
34003
|
const root = rootOrNull(adapter, env);
|
|
33564
34004
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
33565
34005
|
if (adapter.installMode === "marketplace") {
|
|
33566
|
-
const cache =
|
|
34006
|
+
const cache = join27(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
33567
34007
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
33568
34008
|
}
|
|
33569
34009
|
rmSync6(root, { recursive: true, force: true });
|
|
33570
34010
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
33571
34011
|
}
|
|
33572
34012
|
case "plugin": {
|
|
33573
|
-
const agentDir =
|
|
34013
|
+
const agentDir = join27(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
33574
34014
|
if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
33575
34015
|
rmSync6(agentDir, { recursive: true, force: true });
|
|
33576
34016
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
@@ -33616,7 +34056,7 @@ function ownEntries2(agent, env) {
|
|
|
33616
34056
|
}
|
|
33617
34057
|
if (agent === "opencode") {
|
|
33618
34058
|
return [{
|
|
33619
|
-
file:
|
|
34059
|
+
file: join27(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
33620
34060
|
// D-WIN-OPENCODE-DIR-1
|
|
33621
34061
|
key: OPENCODE_PLUGIN_KEY,
|
|
33622
34062
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -33627,7 +34067,7 @@ function ownEntries2(agent, env) {
|
|
|
33627
34067
|
if (agent === "pi") {
|
|
33628
34068
|
const agentDir = piAgentDirOf(env, home);
|
|
33629
34069
|
return [{
|
|
33630
|
-
file:
|
|
34070
|
+
file: join27(agentDir, SETTINGS_FILE),
|
|
33631
34071
|
key: PI_PACKAGES_KEY,
|
|
33632
34072
|
shown: PI_PACKAGES_KEY,
|
|
33633
34073
|
has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
|
|
@@ -33658,12 +34098,12 @@ function removeOwnEntries(agent, env) {
|
|
|
33658
34098
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
33659
34099
|
}
|
|
33660
34100
|
function removeProjectData(configDir, projectKey) {
|
|
33661
|
-
const projects =
|
|
33662
|
-
const dir =
|
|
34101
|
+
const projects = join27(configDir, PROJECTS_DIR_NAME);
|
|
34102
|
+
const dir = join27(projects, projectKey);
|
|
33663
34103
|
if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
33664
34104
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
33665
|
-
for (const name of
|
|
33666
|
-
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 });
|
|
33667
34107
|
}
|
|
33668
34108
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
33669
34109
|
}
|
|
@@ -33671,12 +34111,12 @@ function runUninstall(input) {
|
|
|
33671
34111
|
const configDir = resolveConfigDir(input.env);
|
|
33672
34112
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
33673
34113
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
33674
|
-
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));
|
|
33675
34115
|
return { rows, stopped: stop.stopped };
|
|
33676
34116
|
}
|
|
33677
34117
|
|
|
33678
34118
|
// src/core/ops/v1-remove.ts
|
|
33679
|
-
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";
|
|
33680
34120
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
33681
34121
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
33682
34122
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -33727,8 +34167,8 @@ function locate(doc, path8) {
|
|
|
33727
34167
|
return null;
|
|
33728
34168
|
}
|
|
33729
34169
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
33730
|
-
const layout = hostLayout(
|
|
33731
|
-
const text = hostText(
|
|
34170
|
+
const layout = hostLayout(readFileSync22(file2, "utf8"));
|
|
34171
|
+
const text = hostText(readFileSync22(file2, "utf8"));
|
|
33732
34172
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
33733
34173
|
const hit = /* @__PURE__ */ new Set();
|
|
33734
34174
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -33778,7 +34218,7 @@ function removeV1(agent, findings, project) {
|
|
|
33778
34218
|
continue;
|
|
33779
34219
|
}
|
|
33780
34220
|
if (file2.endsWith(TOML_EXT)) {
|
|
33781
|
-
const rawToml =
|
|
34221
|
+
const rawToml = readFileSync22(file2, "utf8");
|
|
33782
34222
|
const tomlLayout = hostLayout(rawToml);
|
|
33783
34223
|
let text = hostText(rawToml);
|
|
33784
34224
|
for (const f of list4) {
|
|
@@ -33938,7 +34378,7 @@ function checkCall(tool, input) {
|
|
|
33938
34378
|
// src/entries/server.ts
|
|
33939
34379
|
import { randomUUID } from "node:crypto";
|
|
33940
34380
|
import { existsSync as existsSync24, realpathSync as realpathSync12, rmSync as rmSync9 } from "node:fs";
|
|
33941
|
-
import { dirname as dirname15, join as
|
|
34381
|
+
import { dirname as dirname15, join as join29 } from "node:path";
|
|
33942
34382
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
33943
34383
|
|
|
33944
34384
|
// node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
@@ -34586,8 +35026,8 @@ function prefixIssues2(path8, issues) {
|
|
|
34586
35026
|
return iss;
|
|
34587
35027
|
});
|
|
34588
35028
|
}
|
|
34589
|
-
function unwrapMessage2(
|
|
34590
|
-
return typeof
|
|
35029
|
+
function unwrapMessage2(message4) {
|
|
35030
|
+
return typeof message4 === "string" ? message4 : message4?.message;
|
|
34591
35031
|
}
|
|
34592
35032
|
function sizeCaps(defChecks) {
|
|
34593
35033
|
const caps = [];
|
|
@@ -34617,7 +35057,7 @@ function finalizeIssue2(iss, ctx, config4) {
|
|
|
34617
35057
|
iss.schema = iss.inst;
|
|
34618
35058
|
}
|
|
34619
35059
|
const schemaError = iss.schema !== iss.inst ? iss.schema?._zod.def?.error : void 0;
|
|
34620
|
-
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";
|
|
34621
35061
|
const full = {};
|
|
34622
35062
|
for (const k of Object.keys(iss)) {
|
|
34623
35063
|
if (k === "inst" || k === "schema" || k === "continue" || k === "input" || k === "__proto__")
|
|
@@ -34625,7 +35065,7 @@ function finalizeIssue2(iss, ctx, config4) {
|
|
|
34625
35065
|
full[k] = iss[k];
|
|
34626
35066
|
}
|
|
34627
35067
|
full.path ?? (full.path = []);
|
|
34628
|
-
full.message =
|
|
35068
|
+
full.message = message4;
|
|
34629
35069
|
if (ctx?.reportInput) {
|
|
34630
35070
|
full.input = iss.input;
|
|
34631
35071
|
}
|
|
@@ -34784,7 +35224,7 @@ function defineBound(proto, key, fn) {
|
|
|
34784
35224
|
}
|
|
34785
35225
|
});
|
|
34786
35226
|
}
|
|
34787
|
-
function
|
|
35227
|
+
function claim2(inst, sentinel) {
|
|
34788
35228
|
const proto = Object.getPrototypeOf(inst);
|
|
34789
35229
|
return sentinel in proto ? void 0 : proto;
|
|
34790
35230
|
}
|
|
@@ -34830,7 +35270,7 @@ function defineLazyInternal(inst, key, compute) {
|
|
|
34830
35270
|
});
|
|
34831
35271
|
}
|
|
34832
35272
|
function installLazyProp(inst, key, make2, enumerable) {
|
|
34833
|
-
const proto =
|
|
35273
|
+
const proto = claim2(inst, key);
|
|
34834
35274
|
if (!proto)
|
|
34835
35275
|
return;
|
|
34836
35276
|
Object.defineProperty(proto, key, {
|
|
@@ -38434,12 +38874,12 @@ function initializeContext(params) {
|
|
|
38434
38874
|
external: params?.external ?? void 0
|
|
38435
38875
|
};
|
|
38436
38876
|
}
|
|
38437
|
-
function handleUnrepresentable(schema, ctx, json2, params,
|
|
38438
|
-
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;
|
|
38439
38879
|
if (result === "any")
|
|
38440
38880
|
return false;
|
|
38441
38881
|
if (result === void 0 || result === "throw")
|
|
38442
|
-
throw new Error(
|
|
38882
|
+
throw new Error(message4);
|
|
38443
38883
|
Object.assign(json2, result);
|
|
38444
38884
|
return true;
|
|
38445
38885
|
}
|
|
@@ -42167,8 +42607,8 @@ function prefixIssues3(path8, issues) {
|
|
|
42167
42607
|
return iss;
|
|
42168
42608
|
});
|
|
42169
42609
|
}
|
|
42170
|
-
function unwrapMessage3(
|
|
42171
|
-
return typeof
|
|
42610
|
+
function unwrapMessage3(message4) {
|
|
42611
|
+
return typeof message4 === "string" ? message4 : message4?.message;
|
|
42172
42612
|
}
|
|
42173
42613
|
function sizeCaps2(defChecks) {
|
|
42174
42614
|
const caps = [];
|
|
@@ -42198,7 +42638,7 @@ function finalizeIssue3(iss, ctx, config4) {
|
|
|
42198
42638
|
iss.schema = iss.inst;
|
|
42199
42639
|
}
|
|
42200
42640
|
const schemaError = iss.schema !== iss.inst ? iss.schema?._zod.def?.error : void 0;
|
|
42201
|
-
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";
|
|
42202
42642
|
const full = {};
|
|
42203
42643
|
for (const k of Object.keys(iss)) {
|
|
42204
42644
|
if (k === "inst" || k === "schema" || k === "continue" || k === "input" || k === "__proto__")
|
|
@@ -42206,7 +42646,7 @@ function finalizeIssue3(iss, ctx, config4) {
|
|
|
42206
42646
|
full[k] = iss[k];
|
|
42207
42647
|
}
|
|
42208
42648
|
full.path ?? (full.path = []);
|
|
42209
|
-
full.message =
|
|
42649
|
+
full.message = message4;
|
|
42210
42650
|
if (ctx?.reportInput) {
|
|
42211
42651
|
full.input = iss.input;
|
|
42212
42652
|
}
|
|
@@ -42365,7 +42805,7 @@ function defineBound2(proto, key, fn) {
|
|
|
42365
42805
|
}
|
|
42366
42806
|
});
|
|
42367
42807
|
}
|
|
42368
|
-
function
|
|
42808
|
+
function claim3(inst, sentinel) {
|
|
42369
42809
|
const proto = Object.getPrototypeOf(inst);
|
|
42370
42810
|
return sentinel in proto ? void 0 : proto;
|
|
42371
42811
|
}
|
|
@@ -42411,7 +42851,7 @@ function defineLazyInternal2(inst, key, compute) {
|
|
|
42411
42851
|
});
|
|
42412
42852
|
}
|
|
42413
42853
|
function installLazyProp2(inst, key, make2, enumerable) {
|
|
42414
|
-
const proto =
|
|
42854
|
+
const proto = claim3(inst, key);
|
|
42415
42855
|
if (!proto)
|
|
42416
42856
|
return;
|
|
42417
42857
|
Object.defineProperty(proto, key, {
|
|
@@ -45925,12 +46365,12 @@ function initializeContext2(params) {
|
|
|
45925
46365
|
external: params?.external ?? void 0
|
|
45926
46366
|
};
|
|
45927
46367
|
}
|
|
45928
|
-
function handleUnrepresentable2(schema, ctx, json2, params,
|
|
45929
|
-
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;
|
|
45930
46370
|
if (result === "any")
|
|
45931
46371
|
return false;
|
|
45932
46372
|
if (result === void 0 || result === "throw")
|
|
45933
|
-
throw new Error(
|
|
46373
|
+
throw new Error(message4);
|
|
45934
46374
|
Object.assign(json2, result);
|
|
45935
46375
|
return true;
|
|
45936
46376
|
}
|
|
@@ -48257,8 +48697,8 @@ var OAuthError = class OAuthError2 extends Error {
|
|
|
48257
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)`");
|
|
48258
48698
|
return brandedHasInstance(this, value);
|
|
48259
48699
|
}
|
|
48260
|
-
constructor(code,
|
|
48261
|
-
super(
|
|
48700
|
+
constructor(code, message4, errorUri) {
|
|
48701
|
+
super(message4);
|
|
48262
48702
|
this.code = code;
|
|
48263
48703
|
this.errorUri = errorUri;
|
|
48264
48704
|
this.name = "OAuthError";
|
|
@@ -48334,8 +48774,8 @@ var SdkError = class extends Error {
|
|
|
48334
48774
|
* failure as `{ cause }` so it is reachable through the `Error.cause` chain that
|
|
48335
48775
|
* loggers and error trackers walk.
|
|
48336
48776
|
*/
|
|
48337
|
-
constructor(code,
|
|
48338
|
-
super(
|
|
48777
|
+
constructor(code, message4, data, options) {
|
|
48778
|
+
super(message4, options);
|
|
48339
48779
|
this.code = code;
|
|
48340
48780
|
this.data = data;
|
|
48341
48781
|
this.name = "SdkError";
|
|
@@ -48349,8 +48789,8 @@ var SdkHttpError = class extends SdkError {
|
|
|
48349
48789
|
/**
|
|
48350
48790
|
* @param options - Standard `ErrorOptions`, forwarded to `Error` (see {@linkcode SdkError}).
|
|
48351
48791
|
*/
|
|
48352
|
-
constructor(code,
|
|
48353
|
-
super(code,
|
|
48792
|
+
constructor(code, message4, data, options) {
|
|
48793
|
+
super(code, message4, data, options);
|
|
48354
48794
|
this.name = "SdkHttpError";
|
|
48355
48795
|
}
|
|
48356
48796
|
get status() {
|
|
@@ -50535,8 +50975,8 @@ var ProtocolError = class ProtocolError2 extends Error {
|
|
|
50535
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)`");
|
|
50536
50976
|
return brandedHasInstance(this, value);
|
|
50537
50977
|
}
|
|
50538
|
-
constructor(code,
|
|
50539
|
-
super(
|
|
50978
|
+
constructor(code, message4, data) {
|
|
50979
|
+
super(message4);
|
|
50540
50980
|
this.code = code;
|
|
50541
50981
|
this.data = data;
|
|
50542
50982
|
this.name = "ProtocolError";
|
|
@@ -50545,35 +50985,35 @@ var ProtocolError = class ProtocolError2 extends Error {
|
|
|
50545
50985
|
/**
|
|
50546
50986
|
* Factory method to create the appropriate error type based on the error code and data
|
|
50547
50987
|
*/
|
|
50548
|
-
static fromError(code,
|
|
50988
|
+
static fromError(code, message4, data) {
|
|
50549
50989
|
if (code === ProtocolErrorCode.UrlElicitationRequired && data) {
|
|
50550
50990
|
const errorData = data;
|
|
50551
|
-
if (errorData.elicitations) return new UrlElicitationRequiredError(errorData.elicitations,
|
|
50991
|
+
if (errorData.elicitations) return new UrlElicitationRequiredError(errorData.elicitations, message4);
|
|
50552
50992
|
}
|
|
50553
50993
|
if (code === ProtocolErrorCode.UnsupportedProtocolVersion && data) {
|
|
50554
50994
|
const errorData = data;
|
|
50555
50995
|
if (Array.isArray(errorData.supported) && typeof errorData.requested === "string") return new UnsupportedProtocolVersionError({
|
|
50556
50996
|
supported: errorData.supported,
|
|
50557
50997
|
requested: errorData.requested
|
|
50558
|
-
},
|
|
50998
|
+
}, message4);
|
|
50559
50999
|
}
|
|
50560
51000
|
if (code === ProtocolErrorCode.InvalidParams || code === ProtocolErrorCode.ResourceNotFound) {
|
|
50561
51001
|
const errorData = data;
|
|
50562
|
-
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);
|
|
50563
51003
|
}
|
|
50564
51004
|
if (code === ProtocolErrorCode.MissingRequiredClientCapability && data) {
|
|
50565
51005
|
const errorData = data;
|
|
50566
|
-
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);
|
|
50567
51007
|
}
|
|
50568
|
-
return new ProtocolError2(code,
|
|
51008
|
+
return new ProtocolError2(code, message4, data);
|
|
50569
51009
|
}
|
|
50570
51010
|
};
|
|
50571
51011
|
var ResourceNotFoundError = class extends ProtocolError {
|
|
50572
51012
|
static {
|
|
50573
51013
|
Object.defineProperty(this, "mcpBrand", { value: "mcp.ResourceNotFoundError" });
|
|
50574
51014
|
}
|
|
50575
|
-
constructor(uri,
|
|
50576
|
-
super(ProtocolErrorCode.InvalidParams,
|
|
51015
|
+
constructor(uri, message4 = `Resource not found: ${uri}`) {
|
|
51016
|
+
super(ProtocolErrorCode.InvalidParams, message4, { uri });
|
|
50577
51017
|
}
|
|
50578
51018
|
/** The URI that was requested and not found. */
|
|
50579
51019
|
get uri() {
|
|
@@ -50584,8 +51024,8 @@ var UrlElicitationRequiredError = class extends ProtocolError {
|
|
|
50584
51024
|
static {
|
|
50585
51025
|
Object.defineProperty(this, "mcpBrand", { value: "mcp.UrlElicitationRequiredError" });
|
|
50586
51026
|
}
|
|
50587
|
-
constructor(elicitations,
|
|
50588
|
-
super(ProtocolErrorCode.UrlElicitationRequired,
|
|
51027
|
+
constructor(elicitations, message4 = `URL elicitation${elicitations.length > 1 ? "s" : ""} required`) {
|
|
51028
|
+
super(ProtocolErrorCode.UrlElicitationRequired, message4, { elicitations });
|
|
50589
51029
|
}
|
|
50590
51030
|
get elicitations() {
|
|
50591
51031
|
return this.data?.elicitations ?? [];
|
|
@@ -50595,8 +51035,8 @@ var UnsupportedProtocolVersionError = class extends ProtocolError {
|
|
|
50595
51035
|
static {
|
|
50596
51036
|
Object.defineProperty(this, "mcpBrand", { value: "mcp.UnsupportedProtocolVersionError" });
|
|
50597
51037
|
}
|
|
50598
|
-
constructor(data,
|
|
50599
|
-
super(ProtocolErrorCode.UnsupportedProtocolVersion,
|
|
51038
|
+
constructor(data, message4 = `Unsupported protocol version: ${data.requested}`) {
|
|
51039
|
+
super(ProtocolErrorCode.UnsupportedProtocolVersion, message4, data);
|
|
50600
51040
|
}
|
|
50601
51041
|
/**
|
|
50602
51042
|
* Protocol versions the receiver supports.
|
|
@@ -50615,8 +51055,8 @@ var MissingRequiredClientCapabilityError = class extends ProtocolError {
|
|
|
50615
51055
|
static {
|
|
50616
51056
|
Object.defineProperty(this, "mcpBrand", { value: "mcp.MissingRequiredClientCapabilityError" });
|
|
50617
51057
|
}
|
|
50618
|
-
constructor(data,
|
|
50619
|
-
super(ProtocolErrorCode.MissingRequiredClientCapability,
|
|
51058
|
+
constructor(data, message4 = `Missing required client capabilities: ${Object.keys(data.requiredCapabilities).join(", ")}`) {
|
|
51059
|
+
super(ProtocolErrorCode.MissingRequiredClientCapability, message4, data);
|
|
50620
51060
|
}
|
|
50621
51061
|
/**
|
|
50622
51062
|
* The capabilities the server requires from the client to process the
|
|
@@ -51869,17 +52309,17 @@ var RESERVED_ENVELOPE_META_KEYS = [
|
|
|
51869
52309
|
LOG_LEVEL_META_KEY
|
|
51870
52310
|
];
|
|
51871
52311
|
var RETRY_PARAMS_KEYS = ["inputResponses", "requestState"];
|
|
51872
|
-
function liftWireOnlyMaterial(
|
|
51873
|
-
const params =
|
|
52312
|
+
function liftWireOnlyMaterial(message4, kind) {
|
|
52313
|
+
const params = message4.params;
|
|
51874
52314
|
if (!isPlainObject$1(params)) return {
|
|
51875
|
-
message:
|
|
52315
|
+
message: message4,
|
|
51876
52316
|
lifted: {}
|
|
51877
52317
|
};
|
|
51878
52318
|
const meta3 = params._meta;
|
|
51879
52319
|
const envelopeKeys = isPlainObject$1(meta3) ? RESERVED_ENVELOPE_META_KEYS.filter((key) => key in meta3) : [];
|
|
51880
52320
|
const retryKeys = kind === "request" ? RETRY_PARAMS_KEYS.filter((key) => key in params) : [];
|
|
51881
52321
|
if (envelopeKeys.length === 0 && retryKeys.length === 0) return {
|
|
51882
|
-
message:
|
|
52322
|
+
message: message4,
|
|
51883
52323
|
lifted: {}
|
|
51884
52324
|
};
|
|
51885
52325
|
const lifted = {};
|
|
@@ -51902,7 +52342,7 @@ function liftWireOnlyMaterial(message3, kind) {
|
|
|
51902
52342
|
}
|
|
51903
52343
|
return {
|
|
51904
52344
|
message: {
|
|
51905
|
-
...
|
|
52345
|
+
...message4,
|
|
51906
52346
|
params: nextParams
|
|
51907
52347
|
},
|
|
51908
52348
|
lifted
|
|
@@ -52032,12 +52472,12 @@ var Protocol = class {
|
|
|
52032
52472
|
* byte-identical. User-supplied `_meta` keys are spread last so they win
|
|
52033
52473
|
* over the auto-attached envelope keys.
|
|
52034
52474
|
*/
|
|
52035
|
-
_envelopeOutbound(
|
|
52475
|
+
_envelopeOutbound(message4) {
|
|
52036
52476
|
const envelope = this._outboundMetaEnvelope();
|
|
52037
|
-
if (envelope === void 0) return
|
|
52038
|
-
const params =
|
|
52477
|
+
if (envelope === void 0) return message4;
|
|
52478
|
+
const params = message4.params ?? {};
|
|
52039
52479
|
return {
|
|
52040
|
-
...
|
|
52480
|
+
...message4,
|
|
52041
52481
|
params: {
|
|
52042
52482
|
...params,
|
|
52043
52483
|
_meta: {
|
|
@@ -52136,12 +52576,12 @@ var Protocol = class {
|
|
|
52136
52576
|
this._onerror(error42);
|
|
52137
52577
|
};
|
|
52138
52578
|
const _onmessage = this._transport?.onmessage;
|
|
52139
|
-
this._transport.onmessage = (
|
|
52140
|
-
_onmessage?.(
|
|
52141
|
-
if (isJSONRPCResultResponse(
|
|
52142
|
-
else if (isJSONRPCRequest(
|
|
52143
|
-
else if (isJSONRPCNotification(
|
|
52144
|
-
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)}`));
|
|
52145
52585
|
};
|
|
52146
52586
|
transport.setSupportedProtocolVersions?.(this._supportedProtocolVersions);
|
|
52147
52587
|
await this._transport.start();
|
|
@@ -52203,13 +52643,13 @@ var Protocol = class {
|
|
|
52203
52643
|
return;
|
|
52204
52644
|
}
|
|
52205
52645
|
const capturedTransport = this._transport;
|
|
52206
|
-
const sendErrorResponse = (code,
|
|
52646
|
+
const sendErrorResponse = (code, message4, data) => {
|
|
52207
52647
|
const errorResponse = {
|
|
52208
52648
|
jsonrpc: "2.0",
|
|
52209
52649
|
id: request2.id,
|
|
52210
52650
|
error: {
|
|
52211
52651
|
code,
|
|
52212
|
-
message:
|
|
52652
|
+
message: message4,
|
|
52213
52653
|
...data !== void 0 && { data }
|
|
52214
52654
|
}
|
|
52215
52655
|
};
|
|
@@ -52803,8 +53243,8 @@ var ReadBuffer = class {
|
|
|
52803
53243
|
function deserializeMessage(line) {
|
|
52804
53244
|
return JSONRPCMessageSchema.parse(JSON.parse(line));
|
|
52805
53245
|
}
|
|
52806
|
-
function serializeMessage(
|
|
52807
|
-
return JSON.stringify(
|
|
53246
|
+
function serializeMessage(message4) {
|
|
53247
|
+
return JSON.stringify(message4) + "\n";
|
|
52808
53248
|
}
|
|
52809
53249
|
var TOOL_NAME_REGEX = /^[A-Za-z0-9._-]{1,128}$/;
|
|
52810
53250
|
function validateToolName(name) {
|
|
@@ -54055,11 +54495,11 @@ var require_errors = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
54055
54495
|
if (schemaPath) schPath = (0, codegen_1.str)`${schPath}${(0, util_1.getErrorPath)(schemaPath, util_1.Type.Str)}`;
|
|
54056
54496
|
return [E.schemaPath, schPath];
|
|
54057
54497
|
}
|
|
54058
|
-
function extraErrorProps(cxt, { params, message:
|
|
54498
|
+
function extraErrorProps(cxt, { params, message: message4 }, keyValues) {
|
|
54059
54499
|
const { keyword, data, schemaValue, it } = cxt;
|
|
54060
54500
|
const { opts, propertyName, topSchemaRef, schemaPath } = it;
|
|
54061
54501
|
keyValues.push([E.keyword, keyword], [E.params, typeof params == "function" ? params(cxt) : params || (0, codegen_1._)`{}`]);
|
|
54062
|
-
if (opts.messages) keyValues.push([E.message, typeof
|
|
54502
|
+
if (opts.messages) keyValues.push([E.message, typeof message4 == "function" ? message4(cxt) : message4]);
|
|
54063
54503
|
if (opts.verbose) keyValues.push([E.schema, schemaValue], [E.parentSchema, (0, codegen_1._)`${topSchemaRef}${schemaPath}`], [names_1.default.data, data]);
|
|
54064
54504
|
if (propertyName) keyValues.push([E.propertyName, propertyName]);
|
|
54065
54505
|
}
|
|
@@ -56383,9 +56823,9 @@ var require_core$3 = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
56383
56823
|
}
|
|
56384
56824
|
const valid = this.validate($schema, schema);
|
|
56385
56825
|
if (!valid && throwOrLogError) {
|
|
56386
|
-
const
|
|
56387
|
-
if (this.opts.validateSchema === "log") this.logger.error(
|
|
56388
|
-
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);
|
|
56389
56829
|
}
|
|
56390
56830
|
return valid;
|
|
56391
56831
|
}
|
|
@@ -59925,8 +60365,8 @@ function stampSubscriptionId(notification, subscriptionId) {
|
|
|
59925
60365
|
}
|
|
59926
60366
|
};
|
|
59927
60367
|
}
|
|
59928
|
-
function parseListenFilter(
|
|
59929
|
-
const outcome = codecForVersion(MODERN_WIRE_REVISION).validateRequest("subscriptions/listen",
|
|
60368
|
+
function parseListenFilter(message4) {
|
|
60369
|
+
const outcome = codecForVersion(MODERN_WIRE_REVISION).validateRequest("subscriptions/listen", message4);
|
|
59930
60370
|
return outcome.ok ? outcome.value.params?.notifications : void 0;
|
|
59931
60371
|
}
|
|
59932
60372
|
var CHANGE_NOTIFICATION_METHODS = /* @__PURE__ */ new Set([
|
|
@@ -59981,31 +60421,31 @@ var StdioListenRouter = class {
|
|
|
59981
60421
|
* open (deliver unadvertised types); the entry guarantees capabilities are
|
|
59982
60422
|
* set before any listen request is routed here.
|
|
59983
60423
|
*/
|
|
59984
|
-
serve(
|
|
60424
|
+
serve(message4) {
|
|
59985
60425
|
if (this._serverCapabilities === void 0) throw new Error("StdioListenRouter.serve() called before setServerCapabilities(); refusing to honor a filter without capabilities");
|
|
59986
60426
|
if (this._subs.size >= this._maxSubscriptions) return {
|
|
59987
60427
|
jsonrpc: "2.0",
|
|
59988
|
-
id:
|
|
60428
|
+
id: message4.id,
|
|
59989
60429
|
error: {
|
|
59990
60430
|
code: -32603,
|
|
59991
60431
|
message: "Subscription limit reached"
|
|
59992
60432
|
}
|
|
59993
60433
|
};
|
|
59994
|
-
const filter2 = parseListenFilter(
|
|
60434
|
+
const filter2 = parseListenFilter(message4);
|
|
59995
60435
|
if (filter2 === void 0) return {
|
|
59996
60436
|
jsonrpc: "2.0",
|
|
59997
|
-
id:
|
|
60437
|
+
id: message4.id,
|
|
59998
60438
|
error: {
|
|
59999
60439
|
code: -32602,
|
|
60000
60440
|
message: "Invalid params: 'notifications' is required and must be a valid SubscriptionFilter"
|
|
60001
60441
|
}
|
|
60002
60442
|
};
|
|
60003
60443
|
const honored = honoredSubset(filter2, this._serverCapabilities);
|
|
60004
|
-
this._subs.set(
|
|
60444
|
+
this._subs.set(message4.id, honored);
|
|
60005
60445
|
return stampSubscriptionId({
|
|
60006
60446
|
method: "notifications/subscriptions/acknowledged",
|
|
60007
60447
|
params: { notifications: honored }
|
|
60008
|
-
},
|
|
60448
|
+
}, message4.id);
|
|
60009
60449
|
}
|
|
60010
60450
|
/**
|
|
60011
60451
|
* Tear down one subscription (inbound `notifications/cancelled`). Returns
|
|
@@ -60024,15 +60464,15 @@ var StdioListenRouter = class {
|
|
|
60024
60464
|
* - For any other outbound message, returns `'passthrough'` (the entry
|
|
60025
60465
|
* forwards it as-is).
|
|
60026
60466
|
*/
|
|
60027
|
-
routeOutbound(
|
|
60028
|
-
if (!CHANGE_NOTIFICATION_METHODS.has(
|
|
60029
|
-
const uriParam =
|
|
60467
|
+
routeOutbound(message4) {
|
|
60468
|
+
if (!CHANGE_NOTIFICATION_METHODS.has(message4.method)) return "passthrough";
|
|
60469
|
+
const uriParam = message4.params?.["uri"];
|
|
60030
60470
|
const uri = typeof uriParam === "string" ? uriParam : void 0;
|
|
60031
|
-
const event = notificationToServerEvent(
|
|
60471
|
+
const event = notificationToServerEvent(message4.method, uri);
|
|
60032
60472
|
const out = [];
|
|
60033
60473
|
for (const [subscriptionId, filter2] of this._subs) if (listenFilterAccepts(filter2, event)) out.push(stampSubscriptionId({
|
|
60034
|
-
method:
|
|
60035
|
-
params:
|
|
60474
|
+
method: message4.method,
|
|
60475
|
+
params: message4.params ?? {}
|
|
60036
60476
|
}, subscriptionId));
|
|
60037
60477
|
return out;
|
|
60038
60478
|
}
|
|
@@ -60109,15 +60549,15 @@ function syntheticElicitationId() {
|
|
|
60109
60549
|
const hex = [...bytes5].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
60110
60550
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
60111
60551
|
}
|
|
60112
|
-
function legacyShimFailure(method,
|
|
60552
|
+
function legacyShimFailure(method, message4) {
|
|
60113
60553
|
if (method === "tools/call") return {
|
|
60114
60554
|
content: [{
|
|
60115
60555
|
type: "text",
|
|
60116
|
-
text:
|
|
60556
|
+
text: message4
|
|
60117
60557
|
}],
|
|
60118
60558
|
isError: true
|
|
60119
60559
|
};
|
|
60120
|
-
throw new ProtocolError(ProtocolErrorCode.InternalError,
|
|
60560
|
+
throw new ProtocolError(ProtocolErrorCode.InternalError, message4);
|
|
60121
60561
|
}
|
|
60122
60562
|
var LegacyInputRequiredShim = class {
|
|
60123
60563
|
constructor(_host) {
|
|
@@ -61536,9 +61976,9 @@ var StdioServerTransport = class {
|
|
|
61536
61976
|
}
|
|
61537
61977
|
processReadBuffer() {
|
|
61538
61978
|
while (true) try {
|
|
61539
|
-
const
|
|
61540
|
-
if (
|
|
61541
|
-
this.onmessage?.(
|
|
61979
|
+
const message4 = this._readBuffer.readMessage();
|
|
61980
|
+
if (message4 === null) break;
|
|
61981
|
+
this.onmessage?.(message4);
|
|
61542
61982
|
} catch (error42) {
|
|
61543
61983
|
this.onerror?.(error42);
|
|
61544
61984
|
}
|
|
@@ -61555,10 +61995,10 @@ var StdioServerTransport = class {
|
|
|
61555
61995
|
this._readBuffer.clear();
|
|
61556
61996
|
this.onclose?.();
|
|
61557
61997
|
}
|
|
61558
|
-
send(
|
|
61998
|
+
send(message4) {
|
|
61559
61999
|
if (this._closed) return Promise.reject(/* @__PURE__ */ new Error("StdioServerTransport is closed"));
|
|
61560
62000
|
return new Promise((resolve13, reject) => {
|
|
61561
|
-
const json2 = serializeMessage(
|
|
62001
|
+
const json2 = serializeMessage(message4);
|
|
61562
62002
|
let settled = false;
|
|
61563
62003
|
const onError = (error42) => {
|
|
61564
62004
|
if (settled) return;
|
|
@@ -61600,27 +62040,27 @@ var StdioConnectionChannel = class {
|
|
|
61600
62040
|
}
|
|
61601
62041
|
async start() {
|
|
61602
62042
|
}
|
|
61603
|
-
async send(
|
|
61604
|
-
if (isJSONRPCResultResponse(
|
|
61605
|
-
const { id } =
|
|
62043
|
+
async send(message4, options) {
|
|
62044
|
+
if (isJSONRPCResultResponse(message4) || isJSONRPCErrorResponse(message4)) {
|
|
62045
|
+
const { id } = message4;
|
|
61606
62046
|
if (id !== void 0) this._settle(id);
|
|
61607
62047
|
}
|
|
61608
62048
|
if (this._closed) return;
|
|
61609
|
-
if (this._outboundIntercept?.(
|
|
61610
|
-
return this._wire.send(
|
|
62049
|
+
if (this._outboundIntercept?.(message4) === "handled") return;
|
|
62050
|
+
return this._wire.send(message4, options);
|
|
61611
62051
|
}
|
|
61612
62052
|
setProtocolVersion = (version4) => {
|
|
61613
62053
|
this._wire.setProtocolVersion?.(version4);
|
|
61614
62054
|
};
|
|
61615
62055
|
/** Forwards one inbound message to the connected instance. */
|
|
61616
|
-
deliver(
|
|
62056
|
+
deliver(message4, extra) {
|
|
61617
62057
|
if (this._closed) return;
|
|
61618
|
-
if (isJSONRPCRequest(
|
|
61619
|
-
else if (isJSONRPCNotification(
|
|
61620
|
-
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;
|
|
61621
62061
|
if (cancelledId !== void 0) this._settle(cancelledId);
|
|
61622
62062
|
}
|
|
61623
|
-
this.onmessage?.(
|
|
62063
|
+
this.onmessage?.(message4, extra);
|
|
61624
62064
|
}
|
|
61625
62065
|
/**
|
|
61626
62066
|
* Resolves once every request delivered to the instance has been answered
|
|
@@ -61666,9 +62106,9 @@ var StdioConnectionChannel = class {
|
|
|
61666
62106
|
for (const waiter of waiters) waiter();
|
|
61667
62107
|
}
|
|
61668
62108
|
};
|
|
61669
|
-
function classifyOpeningMessage(
|
|
61670
|
-
const params =
|
|
61671
|
-
if (
|
|
62109
|
+
function classifyOpeningMessage(message4) {
|
|
62110
|
+
const params = message4.params;
|
|
62111
|
+
if (message4.method === "initialize" && !carriesValidModernEnvelopeClaim(params)) {
|
|
61672
62112
|
const requestedVersion = params !== null && typeof params === "object" && typeof params.protocolVersion === "string" ? params.protocolVersion : void 0;
|
|
61673
62113
|
return {
|
|
61674
62114
|
kind: "legacy",
|
|
@@ -61713,19 +62153,19 @@ function serveStdio(factory, options = {}) {
|
|
|
61713
62153
|
} catch {
|
|
61714
62154
|
}
|
|
61715
62155
|
};
|
|
61716
|
-
const writeErrorResponse = (id, code,
|
|
62156
|
+
const writeErrorResponse = (id, code, message4, data) => wire.send({
|
|
61717
62157
|
jsonrpc: "2.0",
|
|
61718
62158
|
id,
|
|
61719
62159
|
error: {
|
|
61720
62160
|
code,
|
|
61721
|
-
message:
|
|
62161
|
+
message: message4,
|
|
61722
62162
|
...data !== void 0 && { data }
|
|
61723
62163
|
}
|
|
61724
62164
|
}).catch((error42) => reportError(toError(error42)));
|
|
61725
62165
|
const listenRouter = new StdioListenRouter(options.maxSubscriptions ?? DEFAULT_MAX_SUBSCRIPTIONS);
|
|
61726
|
-
const modernOutboundIntercept = (
|
|
61727
|
-
if (!isJSONRPCNotification(
|
|
61728
|
-
const routed = listenRouter.routeOutbound(
|
|
62166
|
+
const modernOutboundIntercept = (message4) => {
|
|
62167
|
+
if (!isJSONRPCNotification(message4)) return void 0;
|
|
62168
|
+
const routed = listenRouter.routeOutbound(message4);
|
|
61729
62169
|
if (routed === "passthrough") return void 0;
|
|
61730
62170
|
for (const stamped of routed) wire.send({
|
|
61731
62171
|
jsonrpc: "2.0",
|
|
@@ -61733,18 +62173,18 @@ function serveStdio(factory, options = {}) {
|
|
|
61733
62173
|
}).catch((error42) => reportError(toError(error42)));
|
|
61734
62174
|
return "handled";
|
|
61735
62175
|
};
|
|
61736
|
-
const tryServeListen = async (
|
|
61737
|
-
if (isJSONRPCRequest(
|
|
61738
|
-
const meta3 = requestMetaOf(
|
|
61739
|
-
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] : {
|
|
61740
62180
|
key: "_meta",
|
|
61741
62181
|
problem: "the per-request envelope is required on protocol revision 2026-07-28"
|
|
61742
62182
|
};
|
|
61743
|
-
const claimedVersion = envelopeClaimVersion(
|
|
62183
|
+
const claimedVersion = envelopeClaimVersion(message4.params);
|
|
61744
62184
|
let reply4;
|
|
61745
62185
|
if (issue4 !== void 0) reply4 = {
|
|
61746
62186
|
jsonrpc: "2.0",
|
|
61747
|
-
id:
|
|
62187
|
+
id: message4.id,
|
|
61748
62188
|
error: {
|
|
61749
62189
|
code: -32602,
|
|
61750
62190
|
message: `Invalid _meta envelope: ${issue4.key}: ${issue4.problem}`
|
|
@@ -61757,14 +62197,14 @@ function serveStdio(factory, options = {}) {
|
|
|
61757
62197
|
});
|
|
61758
62198
|
reply4 = {
|
|
61759
62199
|
jsonrpc: "2.0",
|
|
61760
|
-
id:
|
|
62200
|
+
id: message4.id,
|
|
61761
62201
|
error: {
|
|
61762
62202
|
code: error42.code,
|
|
61763
62203
|
message: error42.message,
|
|
61764
62204
|
data: error42.data
|
|
61765
62205
|
}
|
|
61766
62206
|
};
|
|
61767
|
-
} else reply4 = listenRouter.serve(
|
|
62207
|
+
} else reply4 = listenRouter.serve(message4);
|
|
61768
62208
|
await wire.send("error" in reply4 ? reply4 : {
|
|
61769
62209
|
jsonrpc: "2.0",
|
|
61770
62210
|
method: reply4.method,
|
|
@@ -61772,8 +62212,8 @@ function serveStdio(factory, options = {}) {
|
|
|
61772
62212
|
}).catch((error42) => reportError(toError(error42)));
|
|
61773
62213
|
return true;
|
|
61774
62214
|
}
|
|
61775
|
-
if (isJSONRPCNotification(
|
|
61776
|
-
const cancelledId =
|
|
62215
|
+
if (isJSONRPCNotification(message4) && message4.method === "notifications/cancelled") {
|
|
62216
|
+
const cancelledId = message4.params?.requestId;
|
|
61777
62217
|
if (cancelledId !== void 0 && listenRouter.cancel(cancelledId)) return true;
|
|
61778
62218
|
}
|
|
61779
62219
|
return false;
|
|
@@ -61819,44 +62259,44 @@ function serveStdio(factory, options = {}) {
|
|
|
61819
62259
|
discarding = void 0;
|
|
61820
62260
|
}
|
|
61821
62261
|
};
|
|
61822
|
-
const processMessage = async (
|
|
62262
|
+
const processMessage = async (message4) => {
|
|
61823
62263
|
if (state.phase === "closed") return;
|
|
61824
62264
|
if (state.phase === "pinned") {
|
|
61825
|
-
if (state.era === "modern" && isJSONRPCRequest(
|
|
61826
|
-
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);
|
|
61827
62267
|
return;
|
|
61828
62268
|
}
|
|
61829
|
-
if (state.era === "modern" && await tryServeListen(
|
|
62269
|
+
if (state.era === "modern" && await tryServeListen(message4)) return;
|
|
61830
62270
|
if (isTornDown()) return;
|
|
61831
|
-
state.instance.channel.deliver(
|
|
62271
|
+
state.instance.channel.deliver(message4);
|
|
61832
62272
|
return;
|
|
61833
62273
|
}
|
|
61834
|
-
if (!isJSONRPCRequest(
|
|
62274
|
+
if (!isJSONRPCRequest(message4) && !isJSONRPCNotification(message4)) {
|
|
61835
62275
|
reportError(/* @__PURE__ */ new Error("Discarded a JSON-RPC response received before the connection negotiated an era"));
|
|
61836
62276
|
return;
|
|
61837
62277
|
}
|
|
61838
|
-
const opening = classifyOpeningMessage(
|
|
62278
|
+
const opening = classifyOpeningMessage(message4);
|
|
61839
62279
|
switch (opening.kind) {
|
|
61840
62280
|
case "invalid-envelope": {
|
|
61841
62281
|
const detail = `Invalid _meta envelope for protocol revision 2026-07-28: ${opening.issue.key}: ${opening.issue.problem}`;
|
|
61842
|
-
if (isJSONRPCRequest(
|
|
62282
|
+
if (isJSONRPCRequest(message4)) await writeErrorResponse(message4.id, ProtocolErrorCode.InvalidParams, detail, { envelope: opening.issue });
|
|
61843
62283
|
else reportError(/* @__PURE__ */ new Error(`Discarded a notification with a malformed envelope: ${detail}`));
|
|
61844
62284
|
return;
|
|
61845
62285
|
}
|
|
61846
62286
|
case "unsupported-revision":
|
|
61847
|
-
if (isJSONRPCRequest(
|
|
62287
|
+
if (isJSONRPCRequest(message4)) {
|
|
61848
62288
|
const error42 = new UnsupportedProtocolVersionError({
|
|
61849
62289
|
supported: [...SUPPORTED_MODERN_PROTOCOL_VERSIONS],
|
|
61850
62290
|
requested: opening.requested
|
|
61851
62291
|
});
|
|
61852
62292
|
reportError(error42);
|
|
61853
|
-
await writeErrorResponse(
|
|
62293
|
+
await writeErrorResponse(message4.id, error42.code, error42.message, error42.data);
|
|
61854
62294
|
} else reportError(/* @__PURE__ */ new Error(`Discarded a notification claiming unsupported protocol revision ${opening.requested}`));
|
|
61855
62295
|
return;
|
|
61856
62296
|
case "modern":
|
|
61857
|
-
if (isJSONRPCRequest(
|
|
62297
|
+
if (isJSONRPCRequest(message4) && message4.method === "server/discover") {
|
|
61858
62298
|
if (state.phase === "probe") {
|
|
61859
|
-
state.instance.channel.deliver(
|
|
62299
|
+
state.instance.channel.deliver(message4, { classification: opening.classification });
|
|
61860
62300
|
return;
|
|
61861
62301
|
}
|
|
61862
62302
|
const instance = await connectInstance("modern", opening.revision);
|
|
@@ -61868,12 +62308,12 @@ function serveStdio(factory, options = {}) {
|
|
|
61868
62308
|
phase: "probe",
|
|
61869
62309
|
instance
|
|
61870
62310
|
};
|
|
61871
|
-
instance.channel.deliver(
|
|
62311
|
+
instance.channel.deliver(message4, { classification: opening.classification });
|
|
61872
62312
|
return;
|
|
61873
62313
|
}
|
|
61874
62314
|
if (state.phase === "probe") {
|
|
61875
|
-
if (isJSONRPCNotification(
|
|
61876
|
-
state.instance.channel.deliver(
|
|
62315
|
+
if (isJSONRPCNotification(message4)) {
|
|
62316
|
+
state.instance.channel.deliver(message4, { classification: opening.classification });
|
|
61877
62317
|
return;
|
|
61878
62318
|
}
|
|
61879
62319
|
state = {
|
|
@@ -61893,13 +62333,13 @@ function serveStdio(factory, options = {}) {
|
|
|
61893
62333
|
instance
|
|
61894
62334
|
};
|
|
61895
62335
|
}
|
|
61896
|
-
if (await tryServeListen(
|
|
62336
|
+
if (await tryServeListen(message4)) return;
|
|
61897
62337
|
if (isTornDown()) return;
|
|
61898
|
-
state.instance.channel.deliver(
|
|
62338
|
+
state.instance.channel.deliver(message4, { classification: opening.classification });
|
|
61899
62339
|
return;
|
|
61900
62340
|
case "legacy": {
|
|
61901
62341
|
if (legacyMode === "reject") {
|
|
61902
|
-
if (isJSONRPCRequest(
|
|
62342
|
+
if (isJSONRPCRequest(message4)) await answerLegacyRejection(message4, opening.reason, opening.requestedVersion);
|
|
61903
62343
|
return;
|
|
61904
62344
|
}
|
|
61905
62345
|
if (state.phase === "probe") {
|
|
@@ -61917,7 +62357,7 @@ function serveStdio(factory, options = {}) {
|
|
|
61917
62357
|
era: "legacy",
|
|
61918
62358
|
instance
|
|
61919
62359
|
};
|
|
61920
|
-
state.instance.channel.deliver(
|
|
62360
|
+
state.instance.channel.deliver(message4);
|
|
61921
62361
|
return;
|
|
61922
62362
|
}
|
|
61923
62363
|
}
|
|
@@ -61929,11 +62369,11 @@ function serveStdio(factory, options = {}) {
|
|
|
61929
62369
|
pumping = true;
|
|
61930
62370
|
try {
|
|
61931
62371
|
while (queue.length > 0) {
|
|
61932
|
-
const
|
|
62372
|
+
const message4 = queue.shift();
|
|
61933
62373
|
try {
|
|
61934
|
-
await processMessage(
|
|
62374
|
+
await processMessage(message4);
|
|
61935
62375
|
} catch (error42) {
|
|
61936
|
-
if (isJSONRPCRequest(
|
|
62376
|
+
if (isJSONRPCRequest(message4)) await writeErrorResponse(message4.id, ProtocolErrorCode.InternalError, "Internal server error");
|
|
61937
62377
|
reportError(toError(error42));
|
|
61938
62378
|
}
|
|
61939
62379
|
}
|
|
@@ -61950,8 +62390,8 @@ function serveStdio(factory, options = {}) {
|
|
|
61950
62390
|
if (current.phase === "probe" || current.phase === "pinned") await current.instance.product.close().catch((error42) => reportError(toError(error42)));
|
|
61951
62391
|
await wire.close().catch((error42) => reportError(toError(error42)));
|
|
61952
62392
|
};
|
|
61953
|
-
wire.onmessage = (
|
|
61954
|
-
queue.push(
|
|
62393
|
+
wire.onmessage = (message4) => {
|
|
62394
|
+
queue.push(message4);
|
|
61955
62395
|
pump();
|
|
61956
62396
|
};
|
|
61957
62397
|
wire.onerror = (error42) => {
|
|
@@ -62003,8 +62443,8 @@ function installExitGuard(opts) {
|
|
|
62003
62443
|
}
|
|
62004
62444
|
|
|
62005
62445
|
// src/core/store/cleanup.ts
|
|
62006
|
-
import { existsSync as existsSync23, readdirSync as
|
|
62007
|
-
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";
|
|
62008
62448
|
function deleteSource(raw, id) {
|
|
62009
62449
|
raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
|
|
62010
62450
|
deleteChunkRows(raw, { sourceId: id });
|
|
@@ -62060,8 +62500,8 @@ function lastAccess(raw) {
|
|
|
62060
62500
|
return row5.t;
|
|
62061
62501
|
}
|
|
62062
62502
|
function sweepOne(configDir, projectKey, cutoff) {
|
|
62063
|
-
const dir =
|
|
62064
|
-
const db = openForSweep(
|
|
62503
|
+
const dir = join28(configDir, PROJECTS_DIR_NAME, projectKey);
|
|
62504
|
+
const db = openForSweep(join28(dir, DB_FILE_NAME), projectKey);
|
|
62065
62505
|
let dead;
|
|
62066
62506
|
try {
|
|
62067
62507
|
dead = withWrite(db, (h) => listLiveOwners(configDir, projectKey).length === 0 && lastAccess(h.raw) < cutoff);
|
|
@@ -62074,7 +62514,7 @@ function sweepOne(configDir, projectKey, cutoff) {
|
|
|
62074
62514
|
function sweepDeadProjects(configDir) {
|
|
62075
62515
|
let entries;
|
|
62076
62516
|
try {
|
|
62077
|
-
entries =
|
|
62517
|
+
entries = readdirSync12(join28(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
|
|
62078
62518
|
} catch (err) {
|
|
62079
62519
|
if (err.code === "ENOENT") return [];
|
|
62080
62520
|
throw err;
|
|
@@ -62154,6 +62594,9 @@ function metaNumber(meta3, key) {
|
|
|
62154
62594
|
function sessionIdOf(meta3, agent, env, serverId) {
|
|
62155
62595
|
const fromMeta = metaString(meta3, "sessionId");
|
|
62156
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;
|
|
62157
62600
|
const key = agent === void 0 ? void 0 : HOST_SESSION_ENV[agent];
|
|
62158
62601
|
const fromHost = key === void 0 ? void 0 : env[key];
|
|
62159
62602
|
if (typeof fromHost === "string" && fromHost !== "") return fromHost;
|
|
@@ -62243,7 +62686,7 @@ async function startServer(argv, env) {
|
|
|
62243
62686
|
return db;
|
|
62244
62687
|
}
|
|
62245
62688
|
function stopMarker(configDir, projectKey) {
|
|
62246
|
-
return
|
|
62689
|
+
return join29(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
|
|
62247
62690
|
}
|
|
62248
62691
|
function stopRequested() {
|
|
62249
62692
|
const configDir = resolveConfigDir(process.env);
|
|
@@ -62269,6 +62712,8 @@ async function startServer(argv, env) {
|
|
|
62269
62712
|
get project() {
|
|
62270
62713
|
return projectOf();
|
|
62271
62714
|
},
|
|
62715
|
+
...agent === void 0 ? {} : { agent },
|
|
62716
|
+
// D-1410-DOCTOR-NO-PROJECT-1
|
|
62272
62717
|
sessionId: sessionIdOf(meta3, agent, env, serverId),
|
|
62273
62718
|
turn: metaNumber(meta3, "turn") ?? 0,
|
|
62274
62719
|
signal: req.mcpReq.signal,
|
|
@@ -62372,6 +62817,18 @@ function appendPayload(base, payload) {
|
|
|
62372
62817
|
const text = str3(base);
|
|
62373
62818
|
return text === "" ? payload : text + "\n\n" + payload;
|
|
62374
62819
|
}
|
|
62820
|
+
var SECTION = "context_mode";
|
|
62821
|
+
function deliver(event, payload) {
|
|
62822
|
+
const options = event.systemPromptOptions;
|
|
62823
|
+
const sections = field(options, "sections");
|
|
62824
|
+
if (typeof sections === "object" && sections !== null && !Array.isArray(sections) && field(options, "forceSystemPrompt") === void 0) {
|
|
62825
|
+
const named2 = sections;
|
|
62826
|
+
if (payload === "") delete named2[SECTION];
|
|
62827
|
+
else named2[SECTION] = payload;
|
|
62828
|
+
return {};
|
|
62829
|
+
}
|
|
62830
|
+
return payload === "" ? {} : { systemPrompt: appendPayload(event.systemPrompt, payload) };
|
|
62831
|
+
}
|
|
62375
62832
|
function textOf2(content) {
|
|
62376
62833
|
if (typeof content === "string") return content;
|
|
62377
62834
|
if (!Array.isArray(content)) return "";
|
|
@@ -62475,13 +62932,13 @@ function hostExtension(pi, host = "pi") {
|
|
|
62475
62932
|
openPrompt = prompt;
|
|
62476
62933
|
if (!rerun) turn += 1;
|
|
62477
62934
|
registerTools();
|
|
62478
|
-
const withPayload = () => (
|
|
62935
|
+
const withPayload = () => deliver(event, payload);
|
|
62479
62936
|
if (rerun && payload !== "") return withPayload();
|
|
62480
62937
|
let out;
|
|
62481
62938
|
try {
|
|
62482
62939
|
out = await hook({ type: compactPending ? "session_compact" : "session_start" }, turn);
|
|
62483
62940
|
} catch {
|
|
62484
|
-
return
|
|
62941
|
+
return withPayload();
|
|
62485
62942
|
}
|
|
62486
62943
|
const compactTurn = compactPending;
|
|
62487
62944
|
compactPending = false;
|