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/opencode/plugin.js
CHANGED
|
@@ -33,6 +33,7 @@ function readReplaceTrigger(raw) {
|
|
|
33
33
|
var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
|
|
34
34
|
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
35
35
|
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
36
|
+
var SKILL_LOAD_TOOLS = Object.freeze(["Skill"]);
|
|
36
37
|
var REPLACE_RETURN_BYTES = 96;
|
|
37
38
|
var SHAPE_RETURN_BYTES = 256;
|
|
38
39
|
var REPLACE_CHUNK_BYTES = 48;
|
|
@@ -46,6 +47,9 @@ function SUBAGENT_HANDLE_LINE(handle, bytes5, read3) {
|
|
|
46
47
|
function SEARCH_TWIN_LINE(searchPath, handle, terms, projectDir) {
|
|
47
48
|
return " Or run: node " + shellWord(searchPath) + " " + handle + " " + shellWord(terms) + " " + shellWord(projectDir);
|
|
48
49
|
}
|
|
50
|
+
function PERSISTED_FILE_LINE(file2) {
|
|
51
|
+
return " The whole output is also in " + JSON.stringify(file2) + "; Read it with offset and limit.";
|
|
52
|
+
}
|
|
49
53
|
function shellWord(s) {
|
|
50
54
|
return "'" + s.split("'").join("'\\''") + "'";
|
|
51
55
|
}
|
|
@@ -200,9 +204,17 @@ var KILL_GRACE_MS = 1e3;
|
|
|
200
204
|
var PIPE_EOF_GRACE_MS = 250;
|
|
201
205
|
var PIPE_DRAIN_MAX_MS = 2e3;
|
|
202
206
|
var DB_TIMEOUT_MS = 5e3;
|
|
207
|
+
var HOOK_BUSY_MS = 250;
|
|
208
|
+
var HOOK_SPOOL_DIR = "pending";
|
|
209
|
+
var SPOOL_CLAIM_STALE_MS = 3e4;
|
|
210
|
+
var SPOOL_DRAIN_MS = 1e3;
|
|
203
211
|
var DB_WAL_SUFFIX = "-wal";
|
|
204
212
|
var DB_SHM_SUFFIX = "-shm";
|
|
205
213
|
var DB_TMP_SUFFIX = ".tmp";
|
|
214
|
+
var DB_LINK_DENIED_CODES = ["EACCES", "EPERM", "ENOSYS", "ENOTSUP", "EOPNOTSUPP"];
|
|
215
|
+
var DB_PUBLISH_CLAIM_SUFFIX = ".publish";
|
|
216
|
+
var DB_CLAIM_BUSY_CODES = ["EEXIST", "EPERM"];
|
|
217
|
+
var DB_PUBLISH_POLL_MS = 5;
|
|
206
218
|
var SQLITE_PRIMARY_CODE_MASK = 255;
|
|
207
219
|
var SQLITE_CORRUPT_CODE = 11;
|
|
208
220
|
var SQLITE_NOTADB_CODE = 26;
|
|
@@ -236,6 +248,7 @@ var RUN_LABEL_PREFIX = "run.mjs:";
|
|
|
236
248
|
var SEARCH_WRAPPER_FILE = "search.mjs";
|
|
237
249
|
var RUN_WRAPPER_AGENT = "claude-code";
|
|
238
250
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
251
|
+
var HOST_SESSION_META = Object.freeze({ zcode: "session_id" });
|
|
239
252
|
var NODE_MIN = "24.15.0";
|
|
240
253
|
var DATA_ROOT = "~/.context-mode";
|
|
241
254
|
var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
|
|
@@ -260,6 +273,7 @@ var FRONTMATTER_FENCE = "---";
|
|
|
260
273
|
var FRONTMATTER_TOOLS_KEY = "tools";
|
|
261
274
|
var FRONTMATTER_DISALLOWED_KEY = "disallowedTools";
|
|
262
275
|
var MCP_SERVER_TOOL_PREFIX = "mcp__";
|
|
276
|
+
var PLUGIN_CALL_ID_PREFIX = "toolu_plugin_";
|
|
263
277
|
var MCP_NAME_JOIN = "__";
|
|
264
278
|
var GEMINI_MCP_PREFIX = "mcp_";
|
|
265
279
|
var GEMINI_NAME_EXTRA_CHARS = "_-.:";
|
|
@@ -481,7 +495,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
481
495
|
var DECISION_OPTION_KEY = "option";
|
|
482
496
|
var DECISION_LABEL_JOIN = " | ";
|
|
483
497
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
484
|
-
var BUNDLE_SHA = true ? "
|
|
498
|
+
var BUNDLE_SHA = true ? "ae2e1bb106e462a19ab3c042e371cd8a7f691074" : void 0;
|
|
485
499
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
486
500
|
var DOCTOR_LABEL = Object.freeze({
|
|
487
501
|
D1: "version",
|
|
@@ -592,6 +606,10 @@ function D7_DETAIL(got) {
|
|
|
592
606
|
return `resolved project source ${got} does not match the host's actual cwd`;
|
|
593
607
|
}
|
|
594
608
|
var D7_FIX = "restart the agent in the correct directory";
|
|
609
|
+
function D7_NO_PROJECT_DETAIL(kind) {
|
|
610
|
+
return `Project source ${kind} is missing`;
|
|
611
|
+
}
|
|
612
|
+
var DOCTOR_NEEDS_PROJECT_DETAIL = "runs once the project resolves; D7 names the project source";
|
|
595
613
|
function D8_STALE_SCHEMA_DETAIL(got, want) {
|
|
596
614
|
return `stale schema (v${got}, expected v${want})`;
|
|
597
615
|
}
|
|
@@ -1151,7 +1169,8 @@ var OPENCODE_EVENTS = {
|
|
|
1151
1169
|
var SHELL_TOOL_NAME = "bash";
|
|
1152
1170
|
var READ_TOOL_NAME = "read";
|
|
1153
1171
|
var SHELL_TOOL_NAMES = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
1154
|
-
var
|
|
1172
|
+
var SKILL_TOOL_NAME = "skill";
|
|
1173
|
+
var NATIVE_TO_CANONICAL = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", [SKILL_TOOL_NAME]: "Skill", ...Object.fromEntries(SHELL_TOOL_NAMES.map((n) => [n, "Bash"])) };
|
|
1155
1174
|
function toCanonicalTool(name) {
|
|
1156
1175
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
1157
1176
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL, name) ? NATIVE_TO_CANONICAL[name] : name;
|
|
@@ -1274,7 +1293,7 @@ var CtxError = class extends Error {
|
|
|
1274
1293
|
};
|
|
1275
1294
|
|
|
1276
1295
|
// src/core/hooks/dispatch.ts
|
|
1277
|
-
import { dirname as dirname4, join as
|
|
1296
|
+
import { dirname as dirname4, join as join9, relative as relative3, resolve as resolve8, sep as sep3 } from "node:path";
|
|
1278
1297
|
|
|
1279
1298
|
// src/core/contracts/agents.ts
|
|
1280
1299
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode", "omp"];
|
|
@@ -1285,6 +1304,7 @@ var SHELL_TOOL_NAMES2 = Object.freeze(["Bash", "PowerShell"]);
|
|
|
1285
1304
|
var POWERSHELL_TOOL = "PowerShell";
|
|
1286
1305
|
var SHELL_CANONICAL = "Bash";
|
|
1287
1306
|
var CLAUDE_SHAPE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse"];
|
|
1307
|
+
var FAILURE_EVENT = "PostToolUseFailure";
|
|
1288
1308
|
var MCP_PREFIX = "mcp__";
|
|
1289
1309
|
var MCP_SEP = "__";
|
|
1290
1310
|
var CLAUDE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
@@ -1458,7 +1478,14 @@ function requireFields(raw) {
|
|
|
1458
1478
|
}
|
|
1459
1479
|
function decode2(raw) {
|
|
1460
1480
|
requireFields(raw);
|
|
1461
|
-
const
|
|
1481
|
+
const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
|
|
1482
|
+
const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
|
|
1483
|
+
const ev = decodeClaudeShape(payload, "claude-code", TOOL_NAME_PREFIX2, CLAUDE_SOURCES);
|
|
1484
|
+
if (failure) {
|
|
1485
|
+
const error40 = raw.error;
|
|
1486
|
+
const text = typeof error40 === "string" ? error40 : error40 === void 0 ? "" : JSON.stringify(error40);
|
|
1487
|
+
ev.result = { isError: true, bytes: Buffer.byteLength(text), text, keep: true };
|
|
1488
|
+
}
|
|
1462
1489
|
if (ev.tool !== void 0 && ev.tool.name === POWERSHELL_TOOL) ev.tool.canonicalName = SHELL_CANONICAL;
|
|
1463
1490
|
if (ev.cwd === "") ev.cwd = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
1464
1491
|
if (ev.event === "PostToolUse" && ev.tool !== void 0 && ev.tool.callId === void 0) {
|
|
@@ -1637,9 +1664,9 @@ var NATIVE_TO_CANONICAL3 = {
|
|
|
1637
1664
|
grep_search: "Grep",
|
|
1638
1665
|
web_fetch: "WebFetch"
|
|
1639
1666
|
};
|
|
1640
|
-
var
|
|
1667
|
+
var FAILURE_EVENT2 = "PostToolUseFailure";
|
|
1641
1668
|
function decode5(raw) {
|
|
1642
|
-
const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name ===
|
|
1669
|
+
const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT2;
|
|
1643
1670
|
const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
|
|
1644
1671
|
const ev = decodeClaudeShape(payload, "qwen", TOOL_NAME_PREFIX5, QWEN_SOURCES);
|
|
1645
1672
|
if (ev.tool !== void 0 && Object.hasOwn(NATIVE_TO_CANONICAL3, ev.tool.name)) ev.tool.canonicalName = NATIVE_TO_CANONICAL3[ev.tool.name];
|
|
@@ -1959,12 +1986,12 @@ var TOOL_NAME_PREFIX9 = "mcp__context-mode__";
|
|
|
1959
1986
|
var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
1960
1987
|
var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1961
1988
|
var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
|
|
1962
|
-
var
|
|
1989
|
+
var FAILURE_EVENT3 = "PostToolUseFailure";
|
|
1963
1990
|
function decode9(raw) {
|
|
1964
1991
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("zcode: hook payload is not a JSON object");
|
|
1965
1992
|
const p = { ...raw };
|
|
1966
1993
|
for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
|
|
1967
|
-
const failure = p.hook_event_name ===
|
|
1994
|
+
const failure = p.hook_event_name === FAILURE_EVENT3;
|
|
1968
1995
|
if (failure) p.hook_event_name = "PostToolUse";
|
|
1969
1996
|
const toolName2 = typeof p.tool_name === "string" ? p.tool_name : "";
|
|
1970
1997
|
const prefix = toolName2.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX9;
|
|
@@ -3740,8 +3767,12 @@ var CC_READ_ONLY_DENY = Object.freeze(["Agent", "Artifact", "ArtifactComments",
|
|
|
3740
3767
|
var CLAUDE_CODE_BUILT_INS = Object.freeze({
|
|
3741
3768
|
"general-purpose": { tools: null, disallowed: [] },
|
|
3742
3769
|
fork: { tools: null, disallowed: [] },
|
|
3770
|
+
claude: { tools: null, disallowed: [] },
|
|
3743
3771
|
Explore: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
|
|
3744
|
-
Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] }
|
|
3772
|
+
Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
|
|
3773
|
+
"claude-code-guide": { tools: ["Glob", "Grep", "Read", "WebFetch", "WebSearch"], disallowed: [] },
|
|
3774
|
+
"statusline-setup": { tools: ["Read", "Edit"], disallowed: [] },
|
|
3775
|
+
"web-fetch": { tools: ["WebFetch"], disallowed: [] }
|
|
3745
3776
|
});
|
|
3746
3777
|
var BUILT_IN_AGENT = "claude-code";
|
|
3747
3778
|
function isSubagentCall(ev) {
|
|
@@ -3942,13 +3973,15 @@ function unique(names) {
|
|
|
3942
3973
|
// src/core/policy/unwrap.ts
|
|
3943
3974
|
var NONE = "";
|
|
3944
3975
|
var WRAPPERS = Object.freeze({
|
|
3945
|
-
sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE },
|
|
3946
|
-
env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE },
|
|
3947
|
-
time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE },
|
|
3948
|
-
nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE },
|
|
3949
|
-
timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE },
|
|
3950
|
-
command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV" },
|
|
3951
|
-
xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE }
|
|
3976
|
+
sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3977
|
+
env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3978
|
+
time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3979
|
+
nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3980
|
+
timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE, subcommands: [] },
|
|
3981
|
+
command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV", subcommands: [] },
|
|
3982
|
+
xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3983
|
+
// #1388: rtk (rtk-ai/rtk) runs the inner command as-is under `proxy` / `bypass`; its other subcommands are rtk's own.
|
|
3984
|
+
rtk: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: NONE, subcommands: ["proxy", "bypass"] }
|
|
3952
3985
|
});
|
|
3953
3986
|
var SHELLS = ["bash", "sh", "zsh"];
|
|
3954
3987
|
var SCRIPT_FLAG = "c";
|
|
@@ -3971,6 +4004,10 @@ function isDuration(s) {
|
|
|
3971
4004
|
}
|
|
3972
4005
|
function peel(w, args) {
|
|
3973
4006
|
let k = 0;
|
|
4007
|
+
if (w.subcommands.length > 0) {
|
|
4008
|
+
if (args.length === 0 || !w.subcommands.includes(args[0])) return null;
|
|
4009
|
+
k = 1;
|
|
4010
|
+
}
|
|
3974
4011
|
while (k < args.length) {
|
|
3975
4012
|
const a = args[k];
|
|
3976
4013
|
if (a === LONG_OPT2) {
|
|
@@ -4724,7 +4761,7 @@ function dumpTarget(name, args) {
|
|
|
4724
4761
|
}
|
|
4725
4762
|
|
|
4726
4763
|
// src/core/project/resolve.ts
|
|
4727
|
-
import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve6 } from "node:path";
|
|
4764
|
+
import { basename as basename2, dirname as dirname3, isAbsolute as isAbsolute3, join as join6, resolve as resolve6 } from "node:path";
|
|
4728
4765
|
|
|
4729
4766
|
// src/core/project/sha256.ts
|
|
4730
4767
|
var K = new Uint32Array([
|
|
@@ -4879,12 +4916,7 @@ function dirOf(kind, src) {
|
|
|
4879
4916
|
}
|
|
4880
4917
|
}
|
|
4881
4918
|
function gitDirs(dir) {
|
|
4882
|
-
let cur;
|
|
4883
|
-
try {
|
|
4884
|
-
cur = realpathSync3.native(dir);
|
|
4885
|
-
} catch {
|
|
4886
|
-
throw new CtxError("NO_GIT_DIR", { path: dir });
|
|
4887
|
-
}
|
|
4919
|
+
let cur = nearestRealDir(dir);
|
|
4888
4920
|
const start = cur;
|
|
4889
4921
|
for (; ; ) {
|
|
4890
4922
|
const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
|
|
@@ -4897,6 +4929,18 @@ function gitDirs(dir) {
|
|
|
4897
4929
|
cur = up;
|
|
4898
4930
|
}
|
|
4899
4931
|
}
|
|
4932
|
+
function nearestRealDir(dir) {
|
|
4933
|
+
const walk3 = isAbsolute3(dir);
|
|
4934
|
+
for (let d = walk3 ? resolve6(dir) : dir; ; ) {
|
|
4935
|
+
try {
|
|
4936
|
+
return realpathSync3.native(d);
|
|
4937
|
+
} catch {
|
|
4938
|
+
const up = dirname3(d);
|
|
4939
|
+
if (!walk3 || up === d) throw new CtxError("NO_GIT_DIR", { path: dir });
|
|
4940
|
+
d = up;
|
|
4941
|
+
}
|
|
4942
|
+
}
|
|
4943
|
+
}
|
|
4900
4944
|
function gitDirAt(dotGit) {
|
|
4901
4945
|
let gitDir;
|
|
4902
4946
|
try {
|
|
@@ -4959,7 +5003,7 @@ function resolveProject(agent, src) {
|
|
|
4959
5003
|
},
|
|
4960
5004
|
worktree,
|
|
4961
5005
|
get containmentRoot() {
|
|
4962
|
-
root ??= plain ?? containmentRootOf(
|
|
5006
|
+
root ??= plain ?? containmentRootOf(worktree, commonDir);
|
|
4963
5007
|
return root;
|
|
4964
5008
|
},
|
|
4965
5009
|
agent,
|
|
@@ -5106,7 +5150,7 @@ function openReadOnlyHandle(sqlite, path8, opts = {}) {
|
|
|
5106
5150
|
}
|
|
5107
5151
|
|
|
5108
5152
|
// src/core/store/db.ts
|
|
5109
|
-
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
5153
|
+
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, renameSync, rmSync, statSync: statSync3 } = process.getBuiltinModule("node:fs");
|
|
5110
5154
|
function versionParts(v) {
|
|
5111
5155
|
const bare2 = v.startsWith("v") ? v.slice(1) : v;
|
|
5112
5156
|
return bare2.split(".").map((p) => Number.parseInt(p, 10));
|
|
@@ -5138,6 +5182,34 @@ function readUserVersion(raw) {
|
|
|
5138
5182
|
const row5 = raw.prepare("PRAGMA user_version").get();
|
|
5139
5183
|
return row5.user_version;
|
|
5140
5184
|
}
|
|
5185
|
+
function errCode(err) {
|
|
5186
|
+
return err.code ?? "";
|
|
5187
|
+
}
|
|
5188
|
+
function publishWithoutLink(tmp, path8) {
|
|
5189
|
+
const claim2 = path8 + DB_PUBLISH_CLAIM_SUFFIX;
|
|
5190
|
+
const start = Date.now();
|
|
5191
|
+
for (; ; ) {
|
|
5192
|
+
if (existsSync3(path8)) return;
|
|
5193
|
+
try {
|
|
5194
|
+
mkdirSync2(claim2);
|
|
5195
|
+
} catch (err) {
|
|
5196
|
+
if (!DB_CLAIM_BUSY_CODES.includes(errCode(err))) throw err;
|
|
5197
|
+
if (Date.now() - start < DB_TIMEOUT_MS) {
|
|
5198
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, DB_PUBLISH_POLL_MS);
|
|
5199
|
+
continue;
|
|
5200
|
+
}
|
|
5201
|
+
const held = statSync3(claim2, { throwIfNoEntry: false });
|
|
5202
|
+
if (held !== void 0 && held.mtimeMs < start) rmSync(claim2, { recursive: true, force: true });
|
|
5203
|
+
throw new Error(`context.db was not published within ${DB_TIMEOUT_MS} ms: ${claim2} was held; open again`);
|
|
5204
|
+
}
|
|
5205
|
+
try {
|
|
5206
|
+
if (!existsSync3(path8)) renameSync(tmp, path8);
|
|
5207
|
+
} finally {
|
|
5208
|
+
rmSync(claim2, { recursive: true, force: true });
|
|
5209
|
+
}
|
|
5210
|
+
return;
|
|
5211
|
+
}
|
|
5212
|
+
}
|
|
5141
5213
|
function createAtomically(sqlite, path8) {
|
|
5142
5214
|
const { randomUUID } = process.getBuiltinModule("node:crypto");
|
|
5143
5215
|
const tmp = path8 + "." + randomUUID() + DB_TMP_SUFFIX;
|
|
@@ -5151,7 +5223,9 @@ function createAtomically(sqlite, path8) {
|
|
|
5151
5223
|
try {
|
|
5152
5224
|
linkSync(tmp, path8);
|
|
5153
5225
|
} catch (err) {
|
|
5154
|
-
|
|
5226
|
+
const code = errCode(err);
|
|
5227
|
+
if (DB_LINK_DENIED_CODES.includes(code)) publishWithoutLink(tmp, path8);
|
|
5228
|
+
else if (code !== "EEXIST") throw err;
|
|
5155
5229
|
}
|
|
5156
5230
|
} finally {
|
|
5157
5231
|
for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
|
|
@@ -5250,9 +5324,9 @@ var COLUMNS = "events(session_id, worktree, agent, kind, tool, key, path, ok, ex
|
|
|
5250
5324
|
var INSERT_SQL = "INSERT INTO " + COLUMNS;
|
|
5251
5325
|
var INSERT_COST_SQL = "INSERT OR IGNORE INTO " + COLUMNS;
|
|
5252
5326
|
var COST_SEQ_SQL = "SELECT seq FROM events WHERE kind = 'cost' AND session_id = ? AND turn = ?";
|
|
5253
|
-
function appendEvent(db, row5) {
|
|
5327
|
+
function appendEvent(db, row5, at2) {
|
|
5254
5328
|
return withWrite(db, (h) => {
|
|
5255
|
-
const now = Date.now();
|
|
5329
|
+
const now = at2 ?? Date.now();
|
|
5256
5330
|
const isCost = row5.kind === "cost";
|
|
5257
5331
|
const res = h.raw.prepare(isCost ? INSERT_COST_SQL : INSERT_SQL).run(
|
|
5258
5332
|
row5.session_id,
|
|
@@ -5342,9 +5416,15 @@ function readLastPrompt(db, sessionId) {
|
|
|
5342
5416
|
const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq DESC LIMIT 1").get(sessionId);
|
|
5343
5417
|
return row5 === void 0 ? "" : row5.body;
|
|
5344
5418
|
}
|
|
5345
|
-
function readRecallRows(db, sessionId, worktree, limit) {
|
|
5419
|
+
function readRecallRows(db, sessionId, worktree, limit, maxSeq = Number.MAX_SAFE_INTEGER) {
|
|
5346
5420
|
if (sessionId === "") return [];
|
|
5347
|
-
return db.raw.prepare(
|
|
5421
|
+
return db.raw.prepare(
|
|
5422
|
+
"SELECT * FROM events WHERE kind <> 'cost' AND ((session_id = ? AND seq <= ?) OR (worktree = ? AND session_id <> ?)) ORDER BY seq DESC LIMIT ?"
|
|
5423
|
+
).all(sessionId, maxSeq, worktree, sessionId, limit);
|
|
5424
|
+
}
|
|
5425
|
+
function readMaxSeq(db) {
|
|
5426
|
+
const row5 = db.raw.prepare("SELECT COALESCE(MAX(seq), 0) AS n FROM events").get();
|
|
5427
|
+
return Number(row5.n);
|
|
5348
5428
|
}
|
|
5349
5429
|
function hasAgentRows(db, worktree, agent) {
|
|
5350
5430
|
return db.raw.prepare("SELECT 1 FROM events WHERE worktree = ? AND agent = ? LIMIT 1").get(worktree, agent) !== void 0;
|
|
@@ -5352,6 +5432,10 @@ function hasAgentRows(db, worktree, agent) {
|
|
|
5352
5432
|
function hasSessionRows(db, sessionId) {
|
|
5353
5433
|
return db.raw.prepare("SELECT 1 FROM events WHERE session_id = ? LIMIT 1").get(sessionId) !== void 0;
|
|
5354
5434
|
}
|
|
5435
|
+
function lastSessionSeq(db, sessionId) {
|
|
5436
|
+
const row5 = db.raw.prepare("SELECT MAX(seq) AS m FROM events WHERE session_id = ?").get(sessionId);
|
|
5437
|
+
return row5?.m ?? 0;
|
|
5438
|
+
}
|
|
5355
5439
|
|
|
5356
5440
|
// src/core/store/snippet.ts
|
|
5357
5441
|
var K1 = 1.2;
|
|
@@ -7348,18 +7432,6 @@ function reserveSource(db, src, chunks) {
|
|
|
7348
7432
|
return Number(row5.id);
|
|
7349
7433
|
});
|
|
7350
7434
|
}
|
|
7351
|
-
function finishReserved(db, id2, src, chunks, units) {
|
|
7352
|
-
try {
|
|
7353
|
-
insertChunks(db, id2, src, chunks);
|
|
7354
|
-
insertUnits(db, id2, src.sessionId, units);
|
|
7355
|
-
} catch (err) {
|
|
7356
|
-
withWrite(db, (h) => {
|
|
7357
|
-
deleteChunkRows(h.raw, { sourceId: id2 });
|
|
7358
|
-
h.raw.prepare("DELETE FROM sources WHERE id = ?").run(id2);
|
|
7359
|
-
});
|
|
7360
|
-
throw err;
|
|
7361
|
-
}
|
|
7362
|
-
}
|
|
7363
7435
|
function insertChunks(db, id2, src, chunks) {
|
|
7364
7436
|
const batches = [];
|
|
7365
7437
|
let batch = [];
|
|
@@ -7798,43 +7870,53 @@ function parseSourceHandle(s) {
|
|
|
7798
7870
|
function pathLabel(p) {
|
|
7799
7871
|
return p.includes("\\") ? p.split("\\").join("/") : p;
|
|
7800
7872
|
}
|
|
7801
|
-
|
|
7802
|
-
|
|
7873
|
+
var EVERY_ROW = { scope: "project", sessionId: "", worktree: "" };
|
|
7874
|
+
var IN_SCOPE = "(:scope <> 'session' OR session_id = :session_id) AND (:scope <> 'worktree' OR worktree = :worktree)";
|
|
7875
|
+
var scopeArgs = (w) => ({ scope: w.scope, session_id: w.sessionId, worktree: w.worktree });
|
|
7876
|
+
function labelStored(db, label2, w) {
|
|
7877
|
+
return stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = :label AND " + IN_SCOPE + " LIMIT 1").get({ label: label2, ...scopeArgs(w) }) !== void 0;
|
|
7803
7878
|
}
|
|
7804
|
-
function storedLabel(db, source) {
|
|
7805
|
-
if (labelStored(db, source)) return source;
|
|
7879
|
+
function storedLabel(db, source, w = EVERY_ROW) {
|
|
7880
|
+
if (labelStored(db, source, w)) return source;
|
|
7806
7881
|
const canon = pathLabel(source);
|
|
7807
|
-
return canon !== source && labelStored(db, canon) ? canon : source;
|
|
7882
|
+
return canon !== source && labelStored(db, canon, w) ? canon : source;
|
|
7808
7883
|
}
|
|
7809
|
-
function newestId(db, label2) {
|
|
7810
|
-
const row5 = stmt(db.raw, "SELECT id FROM sources WHERE label =
|
|
7884
|
+
function newestId(db, label2, w) {
|
|
7885
|
+
const row5 = stmt(db.raw, "SELECT id FROM sources WHERE label = :label AND " + IN_SCOPE + " ORDER BY id DESC LIMIT 1").get({ label: label2, ...scopeArgs(w) });
|
|
7811
7886
|
return row5 === void 0 ? null : Number(row5.id);
|
|
7812
7887
|
}
|
|
7813
|
-
function labelOfId(db, id2) {
|
|
7814
|
-
const row5 = stmt(db.raw, "SELECT label FROM sources WHERE id =
|
|
7888
|
+
function labelOfId(db, id2, w) {
|
|
7889
|
+
const row5 = stmt(db.raw, "SELECT label FROM sources WHERE id = :id AND " + IN_SCOPE).get({ id: id2, ...scopeArgs(w) });
|
|
7815
7890
|
return row5 === void 0 ? null : row5.label;
|
|
7816
7891
|
}
|
|
7817
|
-
function
|
|
7818
|
-
const named2 = storedLabel(db, source);
|
|
7892
|
+
function pickIn(db, source, suffix, w) {
|
|
7893
|
+
const named2 = storedLabel(db, source, w);
|
|
7819
7894
|
const id2 = parseSourceHandle(source);
|
|
7820
|
-
const own2 = newestId(db, named2);
|
|
7895
|
+
const own2 = newestId(db, named2, w);
|
|
7821
7896
|
if (own2 !== null) {
|
|
7822
|
-
const otherLabel = id2 === null || id2 === own2 ? null : labelOfId(db, id2);
|
|
7897
|
+
const otherLabel = id2 === null || id2 === own2 ? null : labelOfId(db, id2, EVERY_ROW);
|
|
7823
7898
|
return { label: named2, id: own2, via: "label", other: otherLabel === null || otherLabel === named2 ? null : { id: id2, label: otherLabel } };
|
|
7824
7899
|
}
|
|
7825
7900
|
if (id2 !== null) {
|
|
7826
|
-
const label2 = labelOfId(db, id2);
|
|
7901
|
+
const label2 = labelOfId(db, id2, w);
|
|
7827
7902
|
if (label2 !== null) return { label: label2, id: id2, via: "handle", other: null };
|
|
7828
7903
|
}
|
|
7829
7904
|
if (suffix) {
|
|
7830
7905
|
const prefix = named2 + LABEL_SUFFIX_SEP;
|
|
7831
|
-
const rows = stmt(db.raw, "SELECT id, label FROM sources WHERE substr(label, 1,
|
|
7906
|
+
const rows = stmt(db.raw, "SELECT id, label FROM sources WHERE substr(label, 1, :n) = :prefix AND " + IN_SCOPE + " ORDER BY id DESC").all({ n: prefix.length, prefix, ...scopeArgs(w) });
|
|
7832
7907
|
for (const r of rows) {
|
|
7833
7908
|
if (r.label.lastIndexOf(LABEL_SUFFIX_SEP) === named2.length) return { label: r.label, id: Number(r.id), via: "suffix", other: null };
|
|
7834
7909
|
}
|
|
7835
7910
|
}
|
|
7836
7911
|
return { label: source, id: null, via: "none", other: null };
|
|
7837
7912
|
}
|
|
7913
|
+
function pickSource(db, source, suffix = true, w = EVERY_ROW) {
|
|
7914
|
+
if (w.scope !== "project") {
|
|
7915
|
+
const here = pickIn(db, source, suffix, w);
|
|
7916
|
+
if (here.via !== "none") return here;
|
|
7917
|
+
}
|
|
7918
|
+
return pickIn(db, source, suffix, EVERY_ROW);
|
|
7919
|
+
}
|
|
7838
7920
|
function collisionLine(value, pick2) {
|
|
7839
7921
|
if (pick2.other === null || pick2.id === null) return null;
|
|
7840
7922
|
return "Source " + JSON.stringify(value) + ": used the label " + shownLabel(pick2.label, null) + " (" + sourceHandle(pick2.id) + "); handle " + sourceHandle(pick2.other.id) + " is " + shownLabel(pick2.other.label, null) + (isLongLabel(pick2.other.label) ? ", search it by its full label." : ", search it with source:" + JSON.stringify(pick2.other.label) + ".");
|
|
@@ -7929,51 +8011,26 @@ function recallQueryText(prompt) {
|
|
|
7929
8011
|
if (cur !== "" && kept.size < RECALL_QUERY_MAX_TERMS) add(cur);
|
|
7930
8012
|
return [...kept.size > 0 ? kept : all].join(" ");
|
|
7931
8013
|
}
|
|
7932
|
-
function
|
|
8014
|
+
function readMaxSourceId(db) {
|
|
8015
|
+
const row5 = db.raw.prepare("SELECT COALESCE(MAX(id), 0) AS n FROM sources").get();
|
|
8016
|
+
return Number(row5.n);
|
|
8017
|
+
}
|
|
8018
|
+
function queryUnits(db, sessionId, q, limit, maxSourceId = Number.MAX_SAFE_INTEGER) {
|
|
7933
8019
|
const match = searchTerms(q).join(" OR ");
|
|
7934
8020
|
if (match === "" || sessionId === "") return [];
|
|
7935
8021
|
const rows = db.raw.prepare(
|
|
7936
|
-
"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 ?"
|
|
7937
|
-
).all(match, sessionId, limit);
|
|
8022
|
+
"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 ?"
|
|
8023
|
+
).all(match, sessionId, maxSourceId, limit);
|
|
7938
8024
|
return rows.map((r) => ({ sourceId: Number(r.source_id), ord: Number(r.ord), label: r.label, body: r.body, score: r.score }));
|
|
7939
8025
|
}
|
|
7940
8026
|
|
|
7941
|
-
// src/core/index/units.ts
|
|
7942
|
-
function indentOf(line) {
|
|
7943
|
-
let n = 0;
|
|
7944
|
-
while (n < line.length && (line[n] === " " || line[n] === " ")) n++;
|
|
7945
|
-
return n;
|
|
7946
|
-
}
|
|
7947
|
-
function buildUnits(text) {
|
|
7948
|
-
const lines = text.split("\n");
|
|
7949
|
-
const stack2 = [];
|
|
7950
|
-
const out = [];
|
|
7951
|
-
let left = UNITS_ANCESTOR_FACTOR * Buffer.byteLength(text, "utf8");
|
|
7952
|
-
for (let i = 0; i < lines.length; i++) {
|
|
7953
|
-
const line = lines[i].endsWith("\r") ? lines[i].slice(0, -1) : lines[i];
|
|
7954
|
-
const indent = indentOf(line);
|
|
7955
|
-
if (indent === line.length) continue;
|
|
7956
|
-
while (stack2.length > 0 && stack2[stack2.length - 1].indent >= indent) stack2.pop();
|
|
7957
|
-
const bytes5 = Buffer.byteLength(line, "utf8");
|
|
7958
|
-
let size = bytes5;
|
|
7959
|
-
let from = stack2.length;
|
|
7960
|
-
while (from > 0) {
|
|
7961
|
-
const add = stack2[from - 1].bytes + 1;
|
|
7962
|
-
if (size + add > RECALL_BUDGET_BYTES || size - bytes5 + add > left) break;
|
|
7963
|
-
size += add;
|
|
7964
|
-
from--;
|
|
7965
|
-
}
|
|
7966
|
-
left -= size - bytes5;
|
|
7967
|
-
out.push({ ord: i, body: [...stack2.slice(from).map((s) => s.line), line].join("\n") });
|
|
7968
|
-
stack2.push({ indent, line, bytes: bytes5 });
|
|
7969
|
-
}
|
|
7970
|
-
return out;
|
|
7971
|
-
}
|
|
7972
|
-
|
|
7973
8027
|
// src/core/compaction/candidates.ts
|
|
7974
8028
|
function firstLine2(body) {
|
|
7975
|
-
const
|
|
7976
|
-
|
|
8029
|
+
const i = body.length - body.trimStart().length;
|
|
8030
|
+
if (i === body.length) return "";
|
|
8031
|
+
const start = i === 0 ? 0 : body.lastIndexOf("\n", i) + 1;
|
|
8032
|
+
const nl = body.indexOf("\n", i);
|
|
8033
|
+
return (start === 0 && nl < 0 ? body : body.slice(start, nl < 0 ? body.length : nl)).replaceAll("\r", " ");
|
|
7977
8034
|
}
|
|
7978
8035
|
function make(section, row5, text, repeatCount, query) {
|
|
7979
8036
|
const bytes5 = Buffer.byteLength(text, "utf8");
|
|
@@ -8516,7 +8573,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
8516
8573
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
8517
8574
|
return { end: start + r.read, written: r.written };
|
|
8518
8575
|
}
|
|
8519
|
-
function merge(src, blocks,
|
|
8576
|
+
function merge(src, blocks, join28, cap, lineCut) {
|
|
8520
8577
|
const out = [];
|
|
8521
8578
|
const scratch = new Uint8Array(cap);
|
|
8522
8579
|
let wide;
|
|
@@ -8526,7 +8583,7 @@ function merge(src, blocks, join27, cap, lineCut) {
|
|
|
8526
8583
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
8527
8584
|
};
|
|
8528
8585
|
for (const b of blocks) {
|
|
8529
|
-
if (cur !== void 0 && !
|
|
8586
|
+
if (cur !== void 0 && !join28) {
|
|
8530
8587
|
emit(cur.start, cur.end, curBytes);
|
|
8531
8588
|
cur = void 0;
|
|
8532
8589
|
}
|
|
@@ -8847,37 +8904,204 @@ function lineShape(text) {
|
|
|
8847
8904
|
return { header, units };
|
|
8848
8905
|
}
|
|
8849
8906
|
|
|
8850
|
-
// src/core/
|
|
8851
|
-
|
|
8852
|
-
|
|
8853
|
-
|
|
8854
|
-
|
|
8855
|
-
|
|
8856
|
-
|
|
8857
|
-
|
|
8858
|
-
label: label2,
|
|
8859
|
-
bytes: Buffer.byteLength(text, "utf8"),
|
|
8860
|
-
chunkCount: chunks.length,
|
|
8861
|
-
createdAt: Date.now()
|
|
8862
|
-
}, chunks);
|
|
8863
|
-
return { sourceId, chunks: chunks.length };
|
|
8907
|
+
// src/core/hooks/spool.ts
|
|
8908
|
+
import { join as join7 } from "node:path";
|
|
8909
|
+
|
|
8910
|
+
// src/core/index/units.ts
|
|
8911
|
+
function indentOf(line) {
|
|
8912
|
+
let n = 0;
|
|
8913
|
+
while (n < line.length && (line[n] === " " || line[n] === " ")) n++;
|
|
8914
|
+
return n;
|
|
8864
8915
|
}
|
|
8865
|
-
function
|
|
8866
|
-
|
|
8916
|
+
function buildUnits(text) {
|
|
8917
|
+
const lines = text.split("\n");
|
|
8918
|
+
const stack2 = [];
|
|
8919
|
+
const out = [];
|
|
8920
|
+
let left = UNITS_ANCESTOR_FACTOR * Buffer.byteLength(text, "utf8");
|
|
8921
|
+
for (let i = 0; i < lines.length; i++) {
|
|
8922
|
+
const line = lines[i].endsWith("\r") ? lines[i].slice(0, -1) : lines[i];
|
|
8923
|
+
const indent = indentOf(line);
|
|
8924
|
+
if (indent === line.length) continue;
|
|
8925
|
+
while (stack2.length > 0 && stack2[stack2.length - 1].indent >= indent) stack2.pop();
|
|
8926
|
+
const bytes5 = Buffer.byteLength(line, "utf8");
|
|
8927
|
+
let size = bytes5;
|
|
8928
|
+
let from = stack2.length;
|
|
8929
|
+
while (from > 0) {
|
|
8930
|
+
const add = stack2[from - 1].bytes + 1;
|
|
8931
|
+
if (size + add > RECALL_BUDGET_BYTES || size - bytes5 + add > left) break;
|
|
8932
|
+
size += add;
|
|
8933
|
+
from--;
|
|
8934
|
+
}
|
|
8935
|
+
left -= size - bytes5;
|
|
8936
|
+
out.push({ ord: i, body: [...stack2.slice(from).map((s) => s.line), line].join("\n") });
|
|
8937
|
+
stack2.push({ indent, line, bytes: bytes5 });
|
|
8938
|
+
}
|
|
8939
|
+
return out;
|
|
8867
8940
|
}
|
|
8868
8941
|
|
|
8869
|
-
// src/core/hooks/
|
|
8870
|
-
|
|
8942
|
+
// src/core/hooks/spool.ts
|
|
8943
|
+
var { mkdirSync: mkdirSync3, readdirSync: readdirSync3, readFileSync: readFileSync5, renameSync: renameSync2, statSync: statSync4, unlinkSync, utimesSync, writeFileSync } = process.getBuiltinModule("node:fs");
|
|
8944
|
+
var OP_SUFFIX = ".json";
|
|
8945
|
+
var CLAIM_SUFFIX = ".claim";
|
|
8946
|
+
var TMP_SUFFIX = ".tmp";
|
|
8947
|
+
var BAD_SUFFIX = ".bad";
|
|
8948
|
+
var NAME_TIME_DIGITS = 15;
|
|
8949
|
+
var NAME_SEQ_DIGITS = 6;
|
|
8950
|
+
var nameSeq = 0;
|
|
8951
|
+
function isBusy(err) {
|
|
8952
|
+
const code = err?.errcode;
|
|
8953
|
+
return typeof code === "number" && (code & SQLITE_PRIMARY_CODE_MASK) === SQLITE_BUSY_CODE;
|
|
8954
|
+
}
|
|
8955
|
+
function message(err) {
|
|
8956
|
+
return err instanceof Error ? err.message : String(err);
|
|
8957
|
+
}
|
|
8958
|
+
async function hookDb(project) {
|
|
8959
|
+
const db = await openDb(project);
|
|
8960
|
+
db.raw.exec("PRAGMA busy_timeout = " + String(HOOK_BUSY_MS));
|
|
8961
|
+
return db;
|
|
8962
|
+
}
|
|
8963
|
+
function spoolDir(project) {
|
|
8964
|
+
return join7(project.projectDir, HOOK_SPOOL_DIR);
|
|
8965
|
+
}
|
|
8966
|
+
function spool(project, op) {
|
|
8967
|
+
const dir = spoolDir(project);
|
|
8968
|
+
mkdirSync3(dir, { recursive: true });
|
|
8969
|
+
const name = String(Date.now()).padStart(NAME_TIME_DIGITS, "0") + "-" + String(process.pid) + "-" + String(nameSeq++).padStart(NAME_SEQ_DIGITS, "0");
|
|
8970
|
+
const tmp = join7(dir, name + TMP_SUFFIX);
|
|
8971
|
+
writeFileSync(tmp, JSON.stringify(op));
|
|
8972
|
+
renameSync2(tmp, join7(dir, name + OP_SUFFIX));
|
|
8973
|
+
}
|
|
8974
|
+
function runOp(db, op, chunks, cur) {
|
|
8975
|
+
if (op.t === "row") {
|
|
8976
|
+
appendEvent(db, op.row, op.at);
|
|
8977
|
+
return null;
|
|
8978
|
+
}
|
|
8979
|
+
const c = chunks ?? chunkText(op.text, "text", op.max);
|
|
8980
|
+
let id2 = op.id;
|
|
8981
|
+
if (id2 === null) {
|
|
8982
|
+
id2 = reserveSource(db, op.src, c);
|
|
8983
|
+
cur.op = { ...op, id: id2 };
|
|
8984
|
+
} else if (chunks === void 0) {
|
|
8985
|
+
const sid = id2;
|
|
8986
|
+
const gone = withWrite(db, (h) => {
|
|
8987
|
+
if (h.raw.prepare("SELECT 1 AS x FROM sources WHERE id = ?").get(sid) === void 0) return true;
|
|
8988
|
+
deleteChunkRows(h.raw, { sourceId: sid });
|
|
8989
|
+
return false;
|
|
8990
|
+
});
|
|
8991
|
+
if (gone) return null;
|
|
8992
|
+
}
|
|
8871
8993
|
try {
|
|
8872
|
-
|
|
8873
|
-
|
|
8994
|
+
insertChunks(db, id2, op.src, c);
|
|
8995
|
+
if (op.units) insertUnits(db, id2, op.src.sessionId, buildUnits(op.text));
|
|
8874
8996
|
} catch (err) {
|
|
8875
|
-
|
|
8876
|
-
|
|
8997
|
+
if (isBusy(err)) throw err;
|
|
8998
|
+
const sid = id2;
|
|
8999
|
+
withWrite(db, (h) => {
|
|
9000
|
+
deleteChunkRows(h.raw, { sourceId: sid });
|
|
9001
|
+
h.raw.prepare("DELETE FROM sources WHERE id = ?").run(sid);
|
|
9002
|
+
});
|
|
9003
|
+
throw err;
|
|
8877
9004
|
}
|
|
9005
|
+
return id2;
|
|
8878
9006
|
}
|
|
9007
|
+
function writeOrSpool(project, db, op, chunks) {
|
|
9008
|
+
const cur = { op };
|
|
9009
|
+
try {
|
|
9010
|
+
return runOp(db, op, chunks, cur);
|
|
9011
|
+
} catch (err) {
|
|
9012
|
+
if (!isBusy(err)) throw err;
|
|
9013
|
+
spool(project, cur.op);
|
|
9014
|
+
return cur.op.t === "src" ? cur.op.id : null;
|
|
9015
|
+
}
|
|
9016
|
+
}
|
|
9017
|
+
function writeDetached(project, op, what, chunks) {
|
|
9018
|
+
void (async () => {
|
|
9019
|
+
try {
|
|
9020
|
+
const db = await hookDb(project);
|
|
9021
|
+
if (drain(project, db)) spool(project, op);
|
|
9022
|
+
else writeOrSpool(project, db, op, chunks);
|
|
9023
|
+
} catch (err) {
|
|
9024
|
+
try {
|
|
9025
|
+
if (!isBusy(err)) throw err;
|
|
9026
|
+
spool(project, op);
|
|
9027
|
+
} catch (e) {
|
|
9028
|
+
process.stderr.write("hooks: " + what + " write failed: " + message(e) + "\n");
|
|
9029
|
+
}
|
|
9030
|
+
}
|
|
9031
|
+
})();
|
|
9032
|
+
}
|
|
9033
|
+
function claim(dir, name) {
|
|
9034
|
+
let base = name;
|
|
9035
|
+
if (name.endsWith(OP_SUFFIX + CLAIM_SUFFIX)) {
|
|
9036
|
+
const path8 = join7(dir, name);
|
|
9037
|
+
try {
|
|
9038
|
+
if (Date.now() - statSync4(path8).mtimeMs < SPOOL_CLAIM_STALE_MS) return null;
|
|
9039
|
+
base = name.slice(0, -CLAIM_SUFFIX.length);
|
|
9040
|
+
renameSync2(path8, join7(dir, base));
|
|
9041
|
+
} catch {
|
|
9042
|
+
return null;
|
|
9043
|
+
}
|
|
9044
|
+
} else if (!name.endsWith(OP_SUFFIX)) {
|
|
9045
|
+
return null;
|
|
9046
|
+
}
|
|
9047
|
+
const claimed = join7(dir, base + CLAIM_SUFFIX);
|
|
9048
|
+
try {
|
|
9049
|
+
renameSync2(join7(dir, base), claimed);
|
|
9050
|
+
const now = /* @__PURE__ */ new Date();
|
|
9051
|
+
utimesSync(claimed, now, now);
|
|
9052
|
+
return claimed;
|
|
9053
|
+
} catch {
|
|
9054
|
+
return null;
|
|
9055
|
+
}
|
|
9056
|
+
}
|
|
9057
|
+
function drain(project, db) {
|
|
9058
|
+
const dir = spoolDir(project);
|
|
9059
|
+
let names;
|
|
9060
|
+
try {
|
|
9061
|
+
names = readdirSync3(dir);
|
|
9062
|
+
} catch {
|
|
9063
|
+
return false;
|
|
9064
|
+
}
|
|
9065
|
+
const start = Date.now();
|
|
9066
|
+
for (const name of names.sort()) {
|
|
9067
|
+
if (Date.now() - start > SPOOL_DRAIN_MS) return false;
|
|
9068
|
+
const claimed = claim(dir, name);
|
|
9069
|
+
if (claimed === null) continue;
|
|
9070
|
+
const base = claimed.slice(0, -CLAIM_SUFFIX.length);
|
|
9071
|
+
let op;
|
|
9072
|
+
try {
|
|
9073
|
+
op = JSON.parse(readFileSync5(claimed, "utf8"));
|
|
9074
|
+
} catch (err) {
|
|
9075
|
+
process.stderr.write("hooks: pending write unreadable: " + message(err) + "\n");
|
|
9076
|
+
renameSync2(claimed, base + BAD_SUFFIX);
|
|
9077
|
+
continue;
|
|
9078
|
+
}
|
|
9079
|
+
const cur = { op };
|
|
9080
|
+
try {
|
|
9081
|
+
runOp(db, op, void 0, cur);
|
|
9082
|
+
} catch (err) {
|
|
9083
|
+
if (isBusy(err)) {
|
|
9084
|
+
if (cur.op === op) {
|
|
9085
|
+
renameSync2(claimed, base);
|
|
9086
|
+
} else {
|
|
9087
|
+
writeFileSync(base + TMP_SUFFIX, JSON.stringify(cur.op));
|
|
9088
|
+
renameSync2(base + TMP_SUFFIX, base);
|
|
9089
|
+
unlinkSync(claimed);
|
|
9090
|
+
}
|
|
9091
|
+
return true;
|
|
9092
|
+
}
|
|
9093
|
+
process.stderr.write("hooks: pending write failed: " + message(err) + "\n");
|
|
9094
|
+
renameSync2(claimed, base + BAD_SUFFIX);
|
|
9095
|
+
continue;
|
|
9096
|
+
}
|
|
9097
|
+
unlinkSync(claimed);
|
|
9098
|
+
}
|
|
9099
|
+
return false;
|
|
9100
|
+
}
|
|
9101
|
+
|
|
9102
|
+
// src/core/hooks/detached.ts
|
|
8879
9103
|
function appendDetached(project, sessionId, row5) {
|
|
8880
|
-
|
|
9104
|
+
writeDetached(project, { t: "row", row: row5, at: Date.now() }, "journal");
|
|
8881
9105
|
}
|
|
8882
9106
|
|
|
8883
9107
|
// src/core/hooks/handle-query.ts
|
|
@@ -8968,7 +9192,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
8968
9192
|
}
|
|
8969
9193
|
|
|
8970
9194
|
// src/core/hooks/fallback.ts
|
|
8971
|
-
import { join as
|
|
9195
|
+
import { join as join8, resolve as resolve7 } from "node:path";
|
|
8972
9196
|
var fs = process.getBuiltinModule("node:fs");
|
|
8973
9197
|
function isRec(v) {
|
|
8974
9198
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -8996,9 +9220,9 @@ function homeOf(env) {
|
|
|
8996
9220
|
}
|
|
8997
9221
|
function hookLogPath(env) {
|
|
8998
9222
|
const dir = env[DATA_DIR_ENV];
|
|
8999
|
-
if (dir !== void 0 && dir !== "") return
|
|
9223
|
+
if (dir !== void 0 && dir !== "") return join8(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
|
|
9000
9224
|
const home = homeOf(env);
|
|
9001
|
-
return home === "" ? "" :
|
|
9225
|
+
return home === "" ? "" : join8(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
|
|
9002
9226
|
}
|
|
9003
9227
|
function errorLabel(err) {
|
|
9004
9228
|
const code = isRec(err) ? err.code : void 0;
|
|
@@ -9009,7 +9233,7 @@ function logHookError(env, agent, stage, err) {
|
|
|
9009
9233
|
try {
|
|
9010
9234
|
const file2 = hookLogPath(env);
|
|
9011
9235
|
if (file2 === "") return;
|
|
9012
|
-
fs.mkdirSync(
|
|
9236
|
+
fs.mkdirSync(join8(file2, ".."), { recursive: true });
|
|
9013
9237
|
const line = JSON.stringify({
|
|
9014
9238
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9015
9239
|
agent,
|
|
@@ -9123,14 +9347,14 @@ function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
|
9123
9347
|
var { read: read2, writeSync } = process.getBuiltinModule("node:fs");
|
|
9124
9348
|
|
|
9125
9349
|
// src/core/hooks/dispatch.ts
|
|
9126
|
-
var { lstatSync: lstatSync2, readFileSync:
|
|
9350
|
+
var { lstatSync: lstatSync2, readFileSync: readFileSync6 } = process.getBuiltinModule("node:fs");
|
|
9127
9351
|
var ALLOW2 = { kind: "allow" };
|
|
9128
9352
|
var EMPTY5 = { stdout: "", exitCode: 0 };
|
|
9129
9353
|
var DIGIT_0 = 48;
|
|
9130
9354
|
function isAgentId(s) {
|
|
9131
9355
|
return AGENT_IDS.includes(s);
|
|
9132
9356
|
}
|
|
9133
|
-
function
|
|
9357
|
+
function message2(err) {
|
|
9134
9358
|
return err instanceof Error ? err.message : String(err);
|
|
9135
9359
|
}
|
|
9136
9360
|
function str2(v) {
|
|
@@ -9144,7 +9368,7 @@ async function handleHook(agent, raw, env) {
|
|
|
9144
9368
|
const row5 = getAdapter(agent);
|
|
9145
9369
|
const report2 = (stage, err, line) => {
|
|
9146
9370
|
logHookError(env, agent, stage, err);
|
|
9147
|
-
process.stderr.write(line ?? "hooks: " + stage + " failed: " +
|
|
9371
|
+
process.stderr.write(line ?? "hooks: " + stage + " failed: " + message2(err) + "\n");
|
|
9148
9372
|
};
|
|
9149
9373
|
const fail7 = (stage, err, line) => {
|
|
9150
9374
|
report2(stage, err, line);
|
|
@@ -9170,7 +9394,7 @@ async function handleHook(agent, raw, env) {
|
|
|
9170
9394
|
const argv = agent === "vscode" ? [WORKSPACE_FOLDER_FLAG, ev.cwd] : process.argv;
|
|
9171
9395
|
project = resolveProject(agent, { env, argv, cwd: ev.cwd, piCwd: getAdapter(agent).projectSource === "pi:ctx.cwd" ? ev.cwd : void 0 });
|
|
9172
9396
|
} catch (err) {
|
|
9173
|
-
return fail7("project", err, "hooks: no project: " + String(err.code ?? "ERROR") + " " +
|
|
9397
|
+
return fail7("project", err, "hooks: no project: " + String(err.code ?? "ERROR") + " " + message2(err) + "\n");
|
|
9174
9398
|
}
|
|
9175
9399
|
let decision;
|
|
9176
9400
|
const settle = {};
|
|
@@ -9215,13 +9439,14 @@ function compactText(db, ev, row5) {
|
|
|
9215
9439
|
return renderState(readSessionEvents(db, ev.sessionId), ev.turn ?? 0, void 0, row5.toolNamePrefix);
|
|
9216
9440
|
}
|
|
9217
9441
|
async function sessionStart(ev, row5, project) {
|
|
9218
|
-
if (ev.source === "compact" && hasRecall(row5)) markCompacted(await
|
|
9442
|
+
if (ev.source === "compact" && hasRecall(row5)) markCompacted(await hookDb(project), ev.sessionId);
|
|
9219
9443
|
if (ev.source === "compact" && row5.compactDelivery === "sessionstart") {
|
|
9220
|
-
const db2 = await
|
|
9221
|
-
|
|
9222
|
-
|
|
9444
|
+
const db2 = await hookDb(project);
|
|
9445
|
+
const onceKey = COMPACT_STATE_KEY + ":" + lastSessionSeq(db2, ev.sessionId);
|
|
9446
|
+
if (!shouldHint(db2, ev.sessionId, onceKey)) return ALLOW2;
|
|
9447
|
+
return { kind: "hint", text: compactText(db2, ev, row5), onceKey };
|
|
9223
9448
|
}
|
|
9224
|
-
const db = await
|
|
9449
|
+
const db = await hookDb(project);
|
|
9225
9450
|
if (row5.compactDelivery === "opencode-cache" && metaTake(db, PENDING_COMPACT_META_PREFIX + ev.sessionId) !== null) {
|
|
9226
9451
|
return { kind: "hint", text: compactText(db, ev, row5), onceKey: PENDING_COMPACT_KEY };
|
|
9227
9452
|
}
|
|
@@ -9249,7 +9474,7 @@ async function userPromptSubmit(ev, row5, project) {
|
|
|
9249
9474
|
});
|
|
9250
9475
|
echoDetached(ev, project, body);
|
|
9251
9476
|
if (row5.compactDelivery === "pending-flag") {
|
|
9252
|
-
const db = await
|
|
9477
|
+
const db = await hookDb(project);
|
|
9253
9478
|
if (metaTake(db, PENDING_COMPACT_META_PREFIX + ev.sessionId) !== null) {
|
|
9254
9479
|
return { kind: "hint", text: compactText(db, ev, row5), onceKey: PENDING_COMPACT_KEY };
|
|
9255
9480
|
}
|
|
@@ -9259,14 +9484,29 @@ async function userPromptSubmit(ev, row5, project) {
|
|
|
9259
9484
|
}
|
|
9260
9485
|
async function firstTurnResume(ev, row5, project) {
|
|
9261
9486
|
if (row5.eventMap.SessionStart !== void 0 || ev.sessionId === "") return null;
|
|
9262
|
-
const db = await
|
|
9487
|
+
const db = await hookDb(project);
|
|
9263
9488
|
if (hasSessionRows(db, ev.sessionId)) return null;
|
|
9264
9489
|
if (!shouldHint(db, ev.sessionId, RESUME_HINT_KEY)) return null;
|
|
9265
9490
|
if (!hasAgentRows(db, project.worktree, ev.agent)) return null;
|
|
9266
9491
|
return { kind: "hint", text: withPrefix(RESUME_HINT, row5), onceKey: RESUME_HINT_KEY };
|
|
9267
9492
|
}
|
|
9268
9493
|
function markCompacted(db, sessionId) {
|
|
9269
|
-
if (sessionId
|
|
9494
|
+
if (sessionId === "") return;
|
|
9495
|
+
metaSet(db, COMPACTED_META_PREFIX + sessionId, JSON.stringify({ seq: readMaxSeq(db), source: readMaxSourceId(db) }));
|
|
9496
|
+
}
|
|
9497
|
+
function compactBoundary(value) {
|
|
9498
|
+
const all = { seq: Number.MAX_SAFE_INTEGER, source: Number.MAX_SAFE_INTEGER };
|
|
9499
|
+
try {
|
|
9500
|
+
const v = JSON.parse(value);
|
|
9501
|
+
if (typeof v !== "object" || v === null) return all;
|
|
9502
|
+
const { seq, source } = v;
|
|
9503
|
+
return {
|
|
9504
|
+
seq: typeof seq === "number" ? seq : all.seq,
|
|
9505
|
+
source: typeof source === "number" ? source : all.source
|
|
9506
|
+
};
|
|
9507
|
+
} catch {
|
|
9508
|
+
return all;
|
|
9509
|
+
}
|
|
9270
9510
|
}
|
|
9271
9511
|
function seenSeqs(value) {
|
|
9272
9512
|
if (value === null) return [];
|
|
@@ -9288,14 +9528,17 @@ function seenUnitKeys(value) {
|
|
|
9288
9528
|
}
|
|
9289
9529
|
async function recall(ev, row5, project, prompt) {
|
|
9290
9530
|
if (!hasRecall(row5) || ev.sessionId === "") return ALLOW2;
|
|
9291
|
-
const db = await
|
|
9292
|
-
|
|
9531
|
+
const db = await hookDb(project);
|
|
9532
|
+
const compacted = metaGet(db, COMPACTED_META_PREFIX + ev.sessionId);
|
|
9533
|
+
if (compacted === null) return ALLOW2;
|
|
9534
|
+
const boundary = compactBoundary(compacted);
|
|
9293
9535
|
const seenKey = RECALL_SEEN_META_PREFIX + ev.sessionId;
|
|
9294
9536
|
const seen = seenSeqs(metaGet(db, seenKey));
|
|
9295
9537
|
const unitsKey = RECALL_UNITS_SEEN_META_PREFIX + ev.sessionId;
|
|
9296
9538
|
const seenUnits = seenUnitKeys(metaGet(db, unitsKey));
|
|
9297
|
-
const units = queryUnits(db, ev.sessionId, recallQueryText(prompt), RECALL_UNIT_CANDIDATES);
|
|
9298
|
-
const
|
|
9539
|
+
const units = queryUnits(db, ev.sessionId, recallQueryText(prompt), RECALL_UNIT_CANDIDATES, boundary.source);
|
|
9540
|
+
const rows = readRecallRows(db, ev.sessionId, project.worktree, RECALL_MAX_ROWS, boundary.seq);
|
|
9541
|
+
const picked = pickRecall(rows, prompt, new Set(seen), units, new Set(seenUnits));
|
|
9299
9542
|
if (picked.text === "") return ALLOW2;
|
|
9300
9543
|
if (picked.seqs.length > 0) metaSet(db, seenKey, JSON.stringify([...seen, ...picked.seqs]));
|
|
9301
9544
|
if (picked.units !== void 0) metaSet(db, unitsKey, JSON.stringify([...seenUnits, ...picked.units]));
|
|
@@ -9318,7 +9561,7 @@ function readOptions(value) {
|
|
|
9318
9561
|
function echoDetached(ev, project, prompt) {
|
|
9319
9562
|
if (ev.sessionId === "") return;
|
|
9320
9563
|
const key = optionsKey(ev.sessionId);
|
|
9321
|
-
void
|
|
9564
|
+
void hookDb(project).then((db) => {
|
|
9322
9565
|
if (metaGet(db, key) === null) return;
|
|
9323
9566
|
const taken = metaTake(db, key);
|
|
9324
9567
|
const offered = taken === null ? null : readOptions(taken);
|
|
@@ -9326,12 +9569,12 @@ function echoDetached(ev, project, prompt) {
|
|
|
9326
9569
|
const part = optionEchoDecision(prompt, offered.labels, offered.seq);
|
|
9327
9570
|
if (part !== null) writeDecisions(db, ev, project, [part]);
|
|
9328
9571
|
}).catch((err) => {
|
|
9329
|
-
process.stderr.write("hooks: decision write failed: " +
|
|
9572
|
+
process.stderr.write("hooks: decision write failed: " + message2(err) + "\n");
|
|
9330
9573
|
});
|
|
9331
9574
|
}
|
|
9332
9575
|
function writeDecisions(db, ev, project, parts) {
|
|
9333
9576
|
for (const part of parts) {
|
|
9334
|
-
|
|
9577
|
+
writeOrSpool(project, db, { t: "row", at: Date.now(), row: {
|
|
9335
9578
|
session_id: ev.sessionId,
|
|
9336
9579
|
worktree: project.worktree,
|
|
9337
9580
|
agent: ev.agent,
|
|
@@ -9346,22 +9589,22 @@ function writeDecisions(db, ev, project, parts) {
|
|
|
9346
9589
|
turn: ev.turn ?? 0,
|
|
9347
9590
|
sandbox_bytes: 0,
|
|
9348
9591
|
returned_bytes: 0
|
|
9349
|
-
});
|
|
9350
|
-
|
|
9592
|
+
} });
|
|
9593
|
+
writeOrSpool(project, db, { t: "src", id: null, src: sourceRowOf(project, ev.sessionId, DECISION_SOURCE), text: part.body, max: MAX_CHUNK_BYTES, units: false });
|
|
9351
9594
|
}
|
|
9352
9595
|
}
|
|
9353
9596
|
function askDetached(ev, project, tool, text) {
|
|
9354
9597
|
const parts = answerDecisions(text);
|
|
9355
9598
|
const labels = parts.length === 0 ? askOptionLabels(tool.input) : [];
|
|
9356
9599
|
if (parts.length === 0 && labels.length === 0) return;
|
|
9357
|
-
void
|
|
9600
|
+
void hookDb(project).then((db) => {
|
|
9358
9601
|
if (parts.length > 0) return writeDecisions(db, ev, project, parts);
|
|
9359
9602
|
const prompts = readSessionEvents(db, ev.sessionId, "prompt");
|
|
9360
9603
|
const last2 = prompts[prompts.length - 1];
|
|
9361
9604
|
if (last2 === void 0 || ev.sessionId === "") return;
|
|
9362
9605
|
metaSet(db, optionsKey(ev.sessionId), JSON.stringify({ seq: last2.seq, labels }));
|
|
9363
9606
|
}).catch((err) => {
|
|
9364
|
-
process.stderr.write("hooks: decision write failed: " +
|
|
9607
|
+
process.stderr.write("hooks: decision write failed: " + message2(err) + "\n");
|
|
9365
9608
|
});
|
|
9366
9609
|
}
|
|
9367
9610
|
function toolSetSources(ev, project, env) {
|
|
@@ -9397,7 +9640,7 @@ function caseB(ev, row5, d0, userDeny) {
|
|
|
9397
9640
|
if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
|
|
9398
9641
|
const command = tool.input.command;
|
|
9399
9642
|
if (typeof command !== "string") return d0;
|
|
9400
|
-
const wrapper = '"' +
|
|
9643
|
+
const wrapper = '"' + join9(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
|
|
9401
9644
|
const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
|
|
9402
9645
|
return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
|
|
9403
9646
|
}
|
|
@@ -9438,7 +9681,8 @@ async function postToolUse(ev, row5, project, env, settle) {
|
|
|
9438
9681
|
const tool = ev.tool;
|
|
9439
9682
|
if (tool === void 0 || tool.canonicalName.startsWith(OWN_TOOL_PREFIX)) return ALLOW2;
|
|
9440
9683
|
const result = ev.result ?? { isError: false, bytes: 0 };
|
|
9441
|
-
const
|
|
9684
|
+
const whole2 = wholeOutput(result, ev.sessionId, env);
|
|
9685
|
+
const text = whole2.text;
|
|
9442
9686
|
if (result.persistedPath !== void 0) result.bytes = Buffer.byteLength(text);
|
|
9443
9687
|
if (tool.canonicalName === DECISION_TOOL) askDetached(ev, project, tool, text);
|
|
9444
9688
|
const kind = journalKind(tool, row5, result.isError);
|
|
@@ -9465,7 +9709,7 @@ async function postToolUse(ev, row5, project, env, settle) {
|
|
|
9465
9709
|
};
|
|
9466
9710
|
let decision;
|
|
9467
9711
|
try {
|
|
9468
|
-
decision = await postReplace(ev, row5, project, env, tool, result, text);
|
|
9712
|
+
decision = await postReplace(ev, row5, project, env, tool, result, text, whole2.file);
|
|
9469
9713
|
} catch (err) {
|
|
9470
9714
|
journal(result.bytes);
|
|
9471
9715
|
throw err;
|
|
@@ -9479,56 +9723,112 @@ function ownRead(ev, tool, env) {
|
|
|
9479
9723
|
const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
|
|
9480
9724
|
return p !== void 0 && isOwnFile(ev.agent, ev.cwd, p, env);
|
|
9481
9725
|
}
|
|
9482
|
-
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
9726
|
+
async function postReplace(ev, row5, project, env, tool, result, text, persistedFile) {
|
|
9483
9727
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
9484
9728
|
if (boundedRead(tool)) return ALLOW2;
|
|
9729
|
+
if (ompRangedRead(ev, tool)) return ALLOW2;
|
|
9485
9730
|
if (ownRead(ev, tool, env)) return ALLOW2;
|
|
9731
|
+
if (SKILL_LOAD_TOOLS.includes(tool.canonicalName)) return ALLOW2;
|
|
9486
9732
|
if (result.keep === true) return ALLOW2;
|
|
9487
9733
|
if (!hasReplace(row5)) return ALLOW2;
|
|
9488
9734
|
let label2;
|
|
9489
9735
|
let caller = { ctx: true, shell: true, read: false };
|
|
9736
|
+
let canRead = true;
|
|
9490
9737
|
if (isSubagentCall(ev)) {
|
|
9491
9738
|
const set3 = toolSetForAgentType(ev, toolSetSources(ev, project, env));
|
|
9492
9739
|
const subCase = pickSubagentCase(ev, set3);
|
|
9493
9740
|
const has3 = (names) => set3 !== null && names.some((n) => set3.includes(n));
|
|
9741
|
+
canRead = has3(row5.nativeTools.read ?? []);
|
|
9494
9742
|
caller = {
|
|
9495
9743
|
ctx: subCase === "A",
|
|
9496
9744
|
shell: has3(row5.nativeTools.shell),
|
|
9497
9745
|
read: RANGE_READ_TOOLS.includes(tool.canonicalName) && has3(row5.nativeTools.read ?? [])
|
|
9498
9746
|
};
|
|
9747
|
+
if (set3 !== null && !caller.ctx && !caller.shell && !caller.read) return ALLOW2;
|
|
9499
9748
|
label2 = SUBAGENT_SOURCE_PREFIX + tool.canonicalName + ":" + (tool.callId ?? String(ev.turn ?? 0));
|
|
9500
9749
|
} else {
|
|
9501
9750
|
label2 = mainLabel(tool, ev);
|
|
9502
9751
|
}
|
|
9503
9752
|
const intent = [tool.input.description, tool.input.command, tool.input.file_path, tool.input.pattern, tool.input.url, tool.name].map(str2).find((v) => v.trim() !== "") ?? tool.canonicalName;
|
|
9504
9753
|
const chunks = chunkText(text, "text", REPLACE_CHUNK_BYTES);
|
|
9505
|
-
const db = await
|
|
9754
|
+
const db = await hookDb(project);
|
|
9755
|
+
const op = { t: "src", id: null, src: sourceRowOf(project, ev.sessionId, label2), text, max: REPLACE_CHUNK_BYTES, units: true };
|
|
9506
9756
|
let sourceId;
|
|
9507
9757
|
if (result.bytes <= SYNC_INDEX_MAX_BYTES) {
|
|
9508
|
-
sourceId =
|
|
9509
|
-
insertUnits(db, sourceId, ev.sessionId, buildUnits(text));
|
|
9758
|
+
sourceId = writeOrSpool(project, db, op, chunks);
|
|
9510
9759
|
} else {
|
|
9511
|
-
sourceId =
|
|
9512
|
-
indexDetached(project,
|
|
9760
|
+
sourceId = reserveOrSpool(project, db, op, chunks);
|
|
9761
|
+
if (sourceId !== null) indexDetached(project, { ...op, id: sourceId }, chunks);
|
|
9513
9762
|
}
|
|
9514
|
-
|
|
9763
|
+
if (pluginMcpCall(tool)) return ALLOW2;
|
|
9764
|
+
const handle = sourceId === null ? label2 : sourceHandle(sourceId);
|
|
9515
9765
|
const prompt = await lastPrompt(project, ev.sessionId);
|
|
9516
9766
|
const rankQuery = prompt.trim() === "" ? void 0 : intent + " " + prompt;
|
|
9517
9767
|
const handleLine = caller.ctx ? REPLACE_HANDLE_LINE(intent, handle, result.bytes, row5.toolNamePrefix, askedWords(intent, prompt, text)) : SUBAGENT_HANDLE_LINE(handle, result.bytes, caller.read);
|
|
9518
9768
|
const budget = replaceBudget(handleLine, moreLine2(intent, label2));
|
|
9519
|
-
const pointer = handleLine + (caller.shell && ev.agent === RUN_WRAPPER_AGENT ? searchTwin(handle, intent, project) : "");
|
|
9769
|
+
const pointer = handleLine + (caller.shell && ev.agent === RUN_WRAPPER_AGENT && sourceId !== null ? searchTwin(handle, intent, project) : "") + (persistedFile !== void 0 && canRead ? PERSISTED_FILE_LINE(persistedFile) : "");
|
|
9520
9770
|
const digest = shapeDigest(text, rankQuery ?? intent, SHAPE_RETURN_BYTES);
|
|
9521
9771
|
if (digest !== null) return { kind: "replace", output: replaceOutput(digest, pointer) };
|
|
9522
9772
|
const selected = selectChunksInMemory(chunks, intent, budget, label2, rankQuery);
|
|
9523
9773
|
return { kind: "replace", output: selected.more !== null ? replaceOutput(selected.text, pointer) : selected.text };
|
|
9524
9774
|
}
|
|
9775
|
+
function pluginMcpCall(tool) {
|
|
9776
|
+
return tool.callId !== void 0 && tool.callId.startsWith(PLUGIN_CALL_ID_PREFIX) && tool.name.startsWith(MCP_SERVER_TOOL_PREFIX);
|
|
9777
|
+
}
|
|
9525
9778
|
function searchTwin(handle, intent, project) {
|
|
9526
9779
|
const terms = Buffer.byteLength(intent, "utf8") > ECHO_MAX_BYTES ? "" : intent;
|
|
9527
|
-
return SEARCH_TWIN_LINE(
|
|
9780
|
+
return SEARCH_TWIN_LINE(join9(dirname4(process.argv[1] ?? ""), SEARCH_WRAPPER_FILE), handle, terms, project.worktree);
|
|
9528
9781
|
}
|
|
9529
9782
|
function boundedRead(tool) {
|
|
9530
9783
|
return RANGE_READ_TOOLS.includes(tool.canonicalName) && READ_RANGE_KEYS.some((k) => tool.input[k] !== void 0 && tool.input[k] !== null);
|
|
9531
9784
|
}
|
|
9785
|
+
function ompRangedRead(ev, tool) {
|
|
9786
|
+
if (ev.agent !== "omp" || !RANGE_READ_TOOLS.includes(tool.canonicalName)) return false;
|
|
9787
|
+
const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
|
|
9788
|
+
if (p === void 0 || !rangedPathSuffix(p)) return false;
|
|
9789
|
+
try {
|
|
9790
|
+
return lstatSync2(resolve8(ev.cwd, p), { throwIfNoEntry: false }) === void 0;
|
|
9791
|
+
} catch {
|
|
9792
|
+
return false;
|
|
9793
|
+
}
|
|
9794
|
+
}
|
|
9795
|
+
function rangedPathSuffix(path8) {
|
|
9796
|
+
let cut = path8.lastIndexOf(":");
|
|
9797
|
+
let sel = path8.slice(cut + 1);
|
|
9798
|
+
if (sel.toLowerCase() === "raw") {
|
|
9799
|
+
cut = path8.lastIndexOf(":", cut - 1);
|
|
9800
|
+
sel = path8.slice(cut + 1, path8.length - 4);
|
|
9801
|
+
}
|
|
9802
|
+
if (cut <= 0 || !rangeList(sel)) return false;
|
|
9803
|
+
let file2 = path8.slice(0, cut);
|
|
9804
|
+
if (file2.toLowerCase().endsWith(":raw")) file2 = file2.slice(0, -4);
|
|
9805
|
+
return file2.length > 1 || !asciiLetter(file2);
|
|
9806
|
+
}
|
|
9807
|
+
function rangeList(sel) {
|
|
9808
|
+
return sel !== "" && sel.split(",").every(rangeItem);
|
|
9809
|
+
}
|
|
9810
|
+
function rangeItem(item) {
|
|
9811
|
+
if (item.startsWith("-")) return digitsOnly(item.slice(1));
|
|
9812
|
+
let i = 0;
|
|
9813
|
+
while (i < item.length && digit(item[i])) i++;
|
|
9814
|
+
if (i === 0) return false;
|
|
9815
|
+
if (i === item.length) return true;
|
|
9816
|
+
const op = item[i];
|
|
9817
|
+
const rest = item.slice(i + 1);
|
|
9818
|
+
return op === "-" && (rest === "" || digitsOnly(rest)) || op === "+" && digitsOnly(rest);
|
|
9819
|
+
}
|
|
9820
|
+
function digitsOnly(s) {
|
|
9821
|
+
if (s === "") return false;
|
|
9822
|
+
for (const c of s) if (!digit(c)) return false;
|
|
9823
|
+
return true;
|
|
9824
|
+
}
|
|
9825
|
+
function digit(c) {
|
|
9826
|
+
return c >= "0" && c <= "9";
|
|
9827
|
+
}
|
|
9828
|
+
function asciiLetter(s) {
|
|
9829
|
+
const c = s.toLowerCase();
|
|
9830
|
+
return c.length === 1 && c >= "a" && c <= "z";
|
|
9831
|
+
}
|
|
9532
9832
|
function replaceOutput(body, handleLine) {
|
|
9533
9833
|
return body === "" ? handleLine : body + "\n" + handleLine;
|
|
9534
9834
|
}
|
|
@@ -9537,7 +9837,7 @@ function replaceBudget(handleLine, more) {
|
|
|
9537
9837
|
}
|
|
9538
9838
|
function hostToolResult(file2, sessionId, env) {
|
|
9539
9839
|
if (sessionId === "" || sessionId.includes(sep3) || sessionId.includes("/")) return false;
|
|
9540
|
-
const projects =
|
|
9840
|
+
const projects = join9(claudeDirOf(env, homeDirOf(env) ?? ""), PROJECTS_DIR_NAME);
|
|
9541
9841
|
const steps = relative3(projects, resolve8(file2)).split(sep3);
|
|
9542
9842
|
if (steps.length !== 4 || steps.includes("..") || steps.includes("")) return false;
|
|
9543
9843
|
if (steps[1] !== sessionId || steps[2] !== CLAUDE_TOOL_RESULTS_DIR_NAME) return false;
|
|
@@ -9546,20 +9846,20 @@ function hostToolResult(file2, sessionId, env) {
|
|
|
9546
9846
|
}
|
|
9547
9847
|
function wholeOutput(result, sessionId, env) {
|
|
9548
9848
|
const head2 = result.text ?? "";
|
|
9549
|
-
if (result.persistedPath === void 0) return head2;
|
|
9849
|
+
if (result.persistedPath === void 0) return { text: head2 };
|
|
9550
9850
|
try {
|
|
9551
9851
|
if (!hostToolResult(result.persistedPath, sessionId, env)) {
|
|
9552
9852
|
logHookError(env, "claude-code", "persisted-output", new Error("persisted output path is outside this session's tool-results dir or too large; kept the head"));
|
|
9553
|
-
return head2;
|
|
9853
|
+
return { text: head2 };
|
|
9554
9854
|
}
|
|
9555
|
-
return
|
|
9855
|
+
return { text: readFileSync6(result.persistedPath, "utf8"), file: result.persistedPath };
|
|
9556
9856
|
} catch {
|
|
9557
|
-
return head2;
|
|
9857
|
+
return { text: head2 };
|
|
9558
9858
|
}
|
|
9559
9859
|
}
|
|
9560
9860
|
async function lastPrompt(project, sessionId) {
|
|
9561
9861
|
try {
|
|
9562
|
-
return readLastPrompt(await
|
|
9862
|
+
return readLastPrompt(await hookDb(project), sessionId);
|
|
9563
9863
|
} catch {
|
|
9564
9864
|
return "";
|
|
9565
9865
|
}
|
|
@@ -9570,18 +9870,23 @@ function mainLabel(tool, ev) {
|
|
|
9570
9870
|
const head2 = (tool.canonicalName + ":" + (nl < 0 ? cmd : cmd.slice(0, nl))).slice(0, SOURCE_LABEL_MAX_CHARS);
|
|
9571
9871
|
return head2 + "#" + (tool.callId ?? String(ev.turn ?? 0));
|
|
9572
9872
|
}
|
|
9573
|
-
function indexDetached(project,
|
|
9574
|
-
|
|
9575
|
-
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
|
|
9873
|
+
function indexDetached(project, op, chunks) {
|
|
9874
|
+
writeDetached(project, op, "index", chunks);
|
|
9875
|
+
}
|
|
9876
|
+
function reserveOrSpool(project, db, op, chunks) {
|
|
9877
|
+
try {
|
|
9878
|
+
return reserveSource(db, op.src, chunks);
|
|
9879
|
+
} catch (err) {
|
|
9880
|
+
if (!isBusy(err)) throw err;
|
|
9881
|
+
spool(project, op);
|
|
9882
|
+
return null;
|
|
9883
|
+
}
|
|
9579
9884
|
}
|
|
9580
9885
|
function sourceRowOf(project, sessionId, label2) {
|
|
9581
9886
|
return { sessionId, worktree: project.worktree, agent: project.agent, kind: "content", label: label2, createdAt: Date.now() };
|
|
9582
9887
|
}
|
|
9583
9888
|
async function preCompact(ev, row5, project) {
|
|
9584
|
-
const db = await
|
|
9889
|
+
const db = await hookDb(project);
|
|
9585
9890
|
metaSet(db, PENDING_COMPACT_META_PREFIX + ev.sessionId, PENDING_COMPACT_FLAG);
|
|
9586
9891
|
if (hasRecall(row5)) markCompacted(db, ev.sessionId);
|
|
9587
9892
|
return ALLOW2;
|
|
@@ -10607,14 +10912,14 @@ function prefixIssues(path8, issues) {
|
|
|
10607
10912
|
return iss;
|
|
10608
10913
|
});
|
|
10609
10914
|
}
|
|
10610
|
-
function unwrapMessage(
|
|
10611
|
-
return typeof
|
|
10915
|
+
function unwrapMessage(message4) {
|
|
10916
|
+
return typeof message4 === "string" ? message4 : message4?.message;
|
|
10612
10917
|
}
|
|
10613
10918
|
function finalizeIssue(iss, ctx, config2) {
|
|
10614
10919
|
const full = { ...iss, path: iss.path ?? [] };
|
|
10615
10920
|
if (!iss.message) {
|
|
10616
|
-
const
|
|
10617
|
-
full.message =
|
|
10921
|
+
const message4 = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config2.customError?.(iss)) ?? unwrapMessage(config2.localeError?.(iss)) ?? "Invalid input";
|
|
10922
|
+
full.message = message4;
|
|
10618
10923
|
}
|
|
10619
10924
|
delete full.inst;
|
|
10620
10925
|
delete full.continue;
|
|
@@ -20802,7 +21107,7 @@ function buildChildEnv(parent, extra) {
|
|
|
20802
21107
|
}
|
|
20803
21108
|
|
|
20804
21109
|
// src/core/sandbox/runtimes.ts
|
|
20805
|
-
import { accessSync, constants as fsConstants, statSync as
|
|
21110
|
+
import { accessSync, constants as fsConstants, statSync as statSync5 } from "node:fs";
|
|
20806
21111
|
import path from "node:path";
|
|
20807
21112
|
|
|
20808
21113
|
// src/core/sandbox/path-entries.ts
|
|
@@ -20847,7 +21152,7 @@ function fileNames(name, pathExt) {
|
|
|
20847
21152
|
function probe(full) {
|
|
20848
21153
|
let st;
|
|
20849
21154
|
try {
|
|
20850
|
-
st =
|
|
21155
|
+
st = statSync5(full, { throwIfNoEntry: false });
|
|
20851
21156
|
} catch {
|
|
20852
21157
|
return "unreadable";
|
|
20853
21158
|
}
|
|
@@ -21042,8 +21347,8 @@ function runProcess(argv, o) {
|
|
|
21042
21347
|
}
|
|
21043
21348
|
|
|
21044
21349
|
// src/core/index/auto-memory.ts
|
|
21045
|
-
import { readdirSync as
|
|
21046
|
-
import { join as
|
|
21350
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync7, statSync as statSync6 } from "node:fs";
|
|
21351
|
+
import { join as join10 } from "node:path";
|
|
21047
21352
|
var MEMORY_FILES = Object.freeze([
|
|
21048
21353
|
Object.freeze(["CLAUDE.md"]),
|
|
21049
21354
|
Object.freeze(["CLAUDE.local.md"]),
|
|
@@ -21057,7 +21362,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
21057
21362
|
var MD = ".md";
|
|
21058
21363
|
function steeringFiles(worktree) {
|
|
21059
21364
|
try {
|
|
21060
|
-
return
|
|
21365
|
+
return readdirSync4(join10(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
21061
21366
|
} catch {
|
|
21062
21367
|
return [];
|
|
21063
21368
|
}
|
|
@@ -21065,10 +21370,10 @@ function steeringFiles(worktree) {
|
|
|
21065
21370
|
function readAutoMemory(project) {
|
|
21066
21371
|
const rows = [];
|
|
21067
21372
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
21068
|
-
const path8 =
|
|
21373
|
+
const path8 = join10(project.worktree, ...segs);
|
|
21069
21374
|
if (!isInside(project.worktree, path8)) continue;
|
|
21070
21375
|
try {
|
|
21071
|
-
const st =
|
|
21376
|
+
const st = statSync6(path8);
|
|
21072
21377
|
if (!st.isFile()) continue;
|
|
21073
21378
|
rows.push({
|
|
21074
21379
|
origin: "memory",
|
|
@@ -21077,7 +21382,7 @@ function readAutoMemory(project) {
|
|
|
21077
21382
|
sourceId: null,
|
|
21078
21383
|
path: path8,
|
|
21079
21384
|
label: segs.join("/"),
|
|
21080
|
-
text:
|
|
21385
|
+
text: readFileSync7(path8, "utf8")
|
|
21081
21386
|
});
|
|
21082
21387
|
} catch {
|
|
21083
21388
|
}
|
|
@@ -21138,15 +21443,43 @@ function sourceCount(db, scope, ctx, source) {
|
|
|
21138
21443
|
});
|
|
21139
21444
|
return Number(row5.n);
|
|
21140
21445
|
}
|
|
21141
|
-
function zeroHits(db, scope, ctx, source, mem, offset = 0) {
|
|
21142
|
-
const
|
|
21143
|
-
|
|
21144
|
-
|
|
21446
|
+
function zeroHits(db, scope, ctx, source, mem, nm, queries, offset = 0) {
|
|
21447
|
+
const inScope = sourceCount(db, scope, ctx, source);
|
|
21448
|
+
const n = inScope + mem.rows.length;
|
|
21449
|
+
const head2 = 'No hits in scope "' + scope + '" across ' + n + " source(s).";
|
|
21450
|
+
const pick2 = nm.pick;
|
|
21451
|
+
if (pick2 === null || mem.named || inScope > 0) {
|
|
21452
|
+
return reply(offset > 0 ? "No more hits past offset " + offset + ' in scope "' + scope + '" across ' + n + " source(s)." : head2, false);
|
|
21453
|
+
}
|
|
21454
|
+
if (pick2.id !== null) {
|
|
21455
|
+
const wider = scope === "session" && sourceCount(db, "worktree", ctx, source) > 0 ? "worktree" : "project";
|
|
21456
|
+
return reply(head2 + "\nSource " + JSON.stringify(nm.arg) + ' is stored in scope "' + wider + '": ' + callText(queries, wider, nm.arg, "") + " searches it.", false);
|
|
21457
|
+
}
|
|
21458
|
+
return reply(head2 + "\n" + unknownSource(db, scope, ctx, nm.arg), true);
|
|
21459
|
+
}
|
|
21460
|
+
var STORED_SOURCES = `
|
|
21461
|
+
SELECT MAX(id) AS id, label FROM sources
|
|
21462
|
+
WHERE (:scope <> 'session' OR session_id = :session_id)
|
|
21463
|
+
AND (:scope <> 'worktree' OR worktree = :worktree)
|
|
21464
|
+
GROUP BY label ORDER BY MAX(id) DESC LIMIT :limit`;
|
|
21465
|
+
var STORED_SOURCES_SHOWN = 5;
|
|
21466
|
+
function unknownSource(db, scope, ctx, given) {
|
|
21467
|
+
const line = "Source " + JSON.stringify(given) + ' is not a stored source in scope "' + scope + '".';
|
|
21468
|
+
const rows = db.raw.prepare(STORED_SOURCES).all({
|
|
21469
|
+
scope,
|
|
21470
|
+
session_id: ctx.sessionId,
|
|
21471
|
+
worktree: ctx.project.worktree,
|
|
21472
|
+
limit: STORED_SOURCES_SHOWN + 1
|
|
21473
|
+
});
|
|
21474
|
+
if (rows.length === 0) return line + '\nctx_index stores one: ctx_index({content:"...", source:' + JSON.stringify(given) + "}).";
|
|
21475
|
+
const names = rows.slice(0, STORED_SOURCES_SHOWN).map((r) => isLongLabel(r.label) ? sourceHandle(Number(r.id)) : JSON.stringify(r.label));
|
|
21476
|
+
const more = rows.length > STORED_SOURCES_SHOWN ? ", ..." : "";
|
|
21477
|
+
return line + "\nStored sources, newest first: " + names.join(", ") + more + ". " + callText([], scope, void 0, 'sort:"timeline"') + " lists them all.";
|
|
21145
21478
|
}
|
|
21146
21479
|
function named(given, pick2) {
|
|
21147
|
-
if (given === void 0 || pick2 === null) return { arg: given, note: null };
|
|
21480
|
+
if (given === void 0 || pick2 === null) return { arg: given, note: null, pick: null };
|
|
21148
21481
|
const arg = pick2.id !== null && isLongLabel(given) ? sourceHandle(pick2.id) : given;
|
|
21149
|
-
return { arg, note: collisionLine(given, pick2) };
|
|
21482
|
+
return { arg, note: collisionLine(given, pick2), pick: pick2 };
|
|
21150
21483
|
}
|
|
21151
21484
|
function sourceCard(db, id2, input, scope, arg) {
|
|
21152
21485
|
const row5 = sourceCardRow(db, id2);
|
|
@@ -21278,7 +21611,7 @@ function relevance(db, given, scope, ctx, nm, ms, indexed) {
|
|
|
21278
21611
|
});
|
|
21279
21612
|
const take = fetched.map((h) => replyHits(h, size));
|
|
21280
21613
|
const pages = fetched.map((h, i) => h.slice(0, take[i]));
|
|
21281
|
-
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, ms, offset);
|
|
21614
|
+
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, ms, nm, input.queries, offset);
|
|
21282
21615
|
const moreLine3 = (q, pos) => "More: " + callText([q], scope, nm.arg, "offset:" + pos);
|
|
21283
21616
|
let reserve = 0;
|
|
21284
21617
|
for (const q of input.queries) reserve += bytes2(moreLine3(q, offset + size)) + 1;
|
|
@@ -21348,7 +21681,7 @@ function timelineLine(r) {
|
|
|
21348
21681
|
}
|
|
21349
21682
|
function timeline(db, input, scope, ctx, nm, ms) {
|
|
21350
21683
|
const page2 = ftsQueryTimeline(db, scope, ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, input.after ?? null, input.source, ms.rows);
|
|
21351
|
-
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source, ms);
|
|
21684
|
+
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source, ms, nm, input.queries);
|
|
21352
21685
|
const moreLine3 = (ts) => "more: " + callText(input.queries, scope, nm.arg, 'sort:"timeline", after:' + ts);
|
|
21353
21686
|
const reserve = bytes2(moreLine3(page2.rows[page2.rows.length - 1].ts)) + 1;
|
|
21354
21687
|
const lines = nm.note === null ? [] : [nm.note];
|
|
@@ -21402,7 +21735,8 @@ async function handler(input, ctx) {
|
|
|
21402
21735
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
21403
21736
|
try {
|
|
21404
21737
|
const given = input.source;
|
|
21405
|
-
const
|
|
21738
|
+
const within = { scope, sessionId: ctx.sessionId, worktree: ctx.project.worktree };
|
|
21739
|
+
const pick2 = given !== void 0 && given !== DECISION_SOURCE ? pickSource(db, given, true, within) : null;
|
|
21406
21740
|
if (pick2 !== null) input = { ...input, source: pick2.label };
|
|
21407
21741
|
const nm = named(given, pick2);
|
|
21408
21742
|
const indexed = pick2 !== null && pick2.id !== null;
|
|
@@ -21651,19 +21985,19 @@ var ctxBatch = Object.freeze({
|
|
|
21651
21985
|
});
|
|
21652
21986
|
|
|
21653
21987
|
// src/core/tools/doctor.ts
|
|
21654
|
-
import { readdirSync as
|
|
21655
|
-
import { basename as basename5, join as
|
|
21988
|
+
import { readdirSync as readdirSync9, readFileSync as readFileSync18, existsSync as existsSync17 } from "node:fs";
|
|
21989
|
+
import { basename as basename5, join as join21 } from "node:path";
|
|
21656
21990
|
|
|
21657
21991
|
// src/core/ops/bundle-dir.ts
|
|
21658
21992
|
import { existsSync as existsSync4 } from "node:fs";
|
|
21659
|
-
import { dirname as dirname5, join as
|
|
21993
|
+
import { dirname as dirname5, join as join11 } from "node:path";
|
|
21660
21994
|
import { fileURLToPath } from "node:url";
|
|
21661
21995
|
function bundleDirOf(argv1, moduleFile) {
|
|
21662
21996
|
const own2 = dirname5(argv1);
|
|
21663
|
-
if (existsSync4(
|
|
21997
|
+
if (existsSync4(join11(own2, SERVER_ENTRY_FILE))) return own2;
|
|
21664
21998
|
let dir = dirname5(moduleFile);
|
|
21665
21999
|
for (; ; ) {
|
|
21666
|
-
if (existsSync4(
|
|
22000
|
+
if (existsSync4(join11(dir, SERVER_ENTRY_FILE))) return dir;
|
|
21667
22001
|
const up = dirname5(dir);
|
|
21668
22002
|
if (up === dir) return own2;
|
|
21669
22003
|
dir = up;
|
|
@@ -21677,17 +22011,17 @@ function ownBundleDir() {
|
|
|
21677
22011
|
}
|
|
21678
22012
|
|
|
21679
22013
|
// src/core/ops/doctor-config.ts
|
|
21680
|
-
import { existsSync as existsSync11, readdirSync as
|
|
21681
|
-
import { dirname as dirname8, isAbsolute as
|
|
22014
|
+
import { existsSync as existsSync11, readdirSync as readdirSync7, readFileSync as readFileSync14 } from "node:fs";
|
|
22015
|
+
import { dirname as dirname8, isAbsolute as isAbsolute6, join as join17, resolve as resolve9 } from "node:path";
|
|
21682
22016
|
|
|
21683
22017
|
// src/core/ops/detect-v1.ts
|
|
21684
|
-
import { existsSync as existsSync6, opendirSync, readdirSync as
|
|
22018
|
+
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync5, readFileSync as readFileSync9 } from "node:fs";
|
|
21685
22019
|
import { tmpdir } from "node:os";
|
|
21686
|
-
import { join as
|
|
22020
|
+
import { join as join13 } from "node:path";
|
|
21687
22021
|
|
|
21688
22022
|
// src/core/ops/host-config.ts
|
|
21689
|
-
import { existsSync as existsSync5, readFileSync as
|
|
21690
|
-
import { dirname as dirname6, join as
|
|
22023
|
+
import { existsSync as existsSync5, readFileSync as readFileSync8 } from "node:fs";
|
|
22024
|
+
import { dirname as dirname6, join as join12 } from "node:path";
|
|
21691
22025
|
|
|
21692
22026
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
21693
22027
|
var KEYS2 = {
|
|
@@ -23733,16 +24067,16 @@ function parseTOML(code, options) {
|
|
|
23733
24067
|
}
|
|
23734
24068
|
|
|
23735
24069
|
// src/core/ops/atomic-file.ts
|
|
23736
|
-
import { mkdirSync as
|
|
24070
|
+
import { mkdirSync as mkdirSync4, renameSync as renameSync3, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
23737
24071
|
import path3 from "node:path";
|
|
23738
24072
|
function sleepSync(ms) {
|
|
23739
24073
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
23740
24074
|
}
|
|
23741
|
-
function
|
|
24075
|
+
function errCode2(e) {
|
|
23742
24076
|
return e.code;
|
|
23743
24077
|
}
|
|
23744
24078
|
function renameWithRetry(from, to, opts = {}) {
|
|
23745
|
-
const rename = opts.rename ??
|
|
24079
|
+
const rename = opts.rename ?? renameSync3;
|
|
23746
24080
|
const sleep = opts.sleep ?? sleepSync;
|
|
23747
24081
|
const win = (opts.platform ?? process.platform) === "win32";
|
|
23748
24082
|
for (let attempt = 0; ; attempt += 1) {
|
|
@@ -23750,14 +24084,14 @@ function renameWithRetry(from, to, opts = {}) {
|
|
|
23750
24084
|
rename(from, to);
|
|
23751
24085
|
return;
|
|
23752
24086
|
} catch (e) {
|
|
23753
|
-
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(
|
|
24087
|
+
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
|
|
23754
24088
|
if (!busy || attempt >= ATOMIC_RENAME_RETRIES) throw e;
|
|
23755
24089
|
sleep(ATOMIC_RENAME_DELAY_MS);
|
|
23756
24090
|
}
|
|
23757
24091
|
}
|
|
23758
24092
|
}
|
|
23759
24093
|
function unlinkWithRetry(file2, opts = {}) {
|
|
23760
|
-
const unlink = opts.unlink ??
|
|
24094
|
+
const unlink = opts.unlink ?? unlinkSync2;
|
|
23761
24095
|
const sleep = opts.sleep ?? sleepSync;
|
|
23762
24096
|
const win = (opts.platform ?? process.platform) === "win32";
|
|
23763
24097
|
for (let attempt = 0; ; attempt += 1) {
|
|
@@ -23765,15 +24099,15 @@ function unlinkWithRetry(file2, opts = {}) {
|
|
|
23765
24099
|
unlink(file2);
|
|
23766
24100
|
return;
|
|
23767
24101
|
} catch (e) {
|
|
23768
|
-
if (
|
|
23769
|
-
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(
|
|
24102
|
+
if (errCode2(e) === "ENOENT") return;
|
|
24103
|
+
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
|
|
23770
24104
|
if (!busy || attempt >= ATOMIC_RENAME_RETRIES) throw replaceFailure(file2, e);
|
|
23771
24105
|
sleep(ATOMIC_RENAME_DELAY_MS);
|
|
23772
24106
|
}
|
|
23773
24107
|
}
|
|
23774
24108
|
}
|
|
23775
24109
|
function replaceFailure(file2, e) {
|
|
23776
|
-
const busy = ATOMIC_RENAME_BUSY_CODES.includes(
|
|
24110
|
+
const busy = ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
|
|
23777
24111
|
const cause = e.message;
|
|
23778
24112
|
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 });
|
|
23779
24113
|
}
|
|
@@ -23784,10 +24118,10 @@ function removeTmpFile(tmp, opts = {}) {
|
|
|
23784
24118
|
}
|
|
23785
24119
|
}
|
|
23786
24120
|
function atomicWriteFile(file2, text, opts = {}) {
|
|
23787
|
-
|
|
24121
|
+
mkdirSync4(path3.dirname(file2), { recursive: true });
|
|
23788
24122
|
const tmp = path3.join(path3.dirname(file2), `${ATOMIC_TMP_PREFIX}${path3.basename(file2)}${ATOMIC_TMP_MARK}${process.pid}`);
|
|
23789
24123
|
try {
|
|
23790
|
-
|
|
24124
|
+
writeFileSync2(tmp, text);
|
|
23791
24125
|
renameWithRetry(tmp, file2, opts);
|
|
23792
24126
|
} catch (e) {
|
|
23793
24127
|
removeTmpFile(tmp, opts);
|
|
@@ -23804,10 +24138,10 @@ function formatOf(path8) {
|
|
|
23804
24138
|
function readHostConfig(agent, path8) {
|
|
23805
24139
|
let file2 = path8;
|
|
23806
24140
|
if (agent === "opencode") {
|
|
23807
|
-
const jsonc =
|
|
24141
|
+
const jsonc = join12(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
|
|
23808
24142
|
if (existsSync5(jsonc)) file2 = jsonc;
|
|
23809
24143
|
}
|
|
23810
|
-
const raw = existsSync5(file2) ?
|
|
24144
|
+
const raw = existsSync5(file2) ? readFileSync8(file2, "utf8") : "";
|
|
23811
24145
|
return { agent, text: hostText(raw), format: agent === "opencode" && !file2.endsWith(TOML_EXT) ? "jsonc" : formatOf(file2), path: file2, layout: hostLayout(raw) };
|
|
23812
24146
|
}
|
|
23813
24147
|
function stripJsonComments(text) {
|
|
@@ -24152,7 +24486,7 @@ function setText(agent, path8, text, format, key, value) {
|
|
|
24152
24486
|
}
|
|
24153
24487
|
}
|
|
24154
24488
|
function serverScript() {
|
|
24155
|
-
return
|
|
24489
|
+
return join12(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
24156
24490
|
}
|
|
24157
24491
|
function isNodeCommand(command) {
|
|
24158
24492
|
if (typeof command !== "string") return false;
|
|
@@ -24279,14 +24613,14 @@ function stripJsonc(text) {
|
|
|
24279
24613
|
}
|
|
24280
24614
|
function readJson(file2) {
|
|
24281
24615
|
try {
|
|
24282
|
-
return JSON.parse(stripJsonc(hostText(
|
|
24616
|
+
return JSON.parse(stripJsonc(hostText(readFileSync9(file2, "utf8"))));
|
|
24283
24617
|
} catch {
|
|
24284
24618
|
return void 0;
|
|
24285
24619
|
}
|
|
24286
24620
|
}
|
|
24287
24621
|
function readText(file2) {
|
|
24288
24622
|
try {
|
|
24289
|
-
return hostText(
|
|
24623
|
+
return hostText(readFileSync9(file2, "utf8"));
|
|
24290
24624
|
} catch {
|
|
24291
24625
|
return "";
|
|
24292
24626
|
}
|
|
@@ -24351,7 +24685,7 @@ function mcpEntry(file2, doc, out) {
|
|
|
24351
24685
|
}
|
|
24352
24686
|
}
|
|
24353
24687
|
function claudeShapeSettings(agentHome, out) {
|
|
24354
|
-
const file2 =
|
|
24688
|
+
const file2 = join13(agentHome, SETTINGS_FILE);
|
|
24355
24689
|
const doc = readJson(file2);
|
|
24356
24690
|
for (const c of nestedCommands(doc)) {
|
|
24357
24691
|
if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
|
|
@@ -24371,63 +24705,63 @@ function v1HookFile(file2, out) {
|
|
|
24371
24705
|
function scanClaudeCode(home, agentHome, out) {
|
|
24372
24706
|
claudeShapeSettings(agentHome, out);
|
|
24373
24707
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
24374
|
-
const file2 =
|
|
24708
|
+
const file2 = join13(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
24375
24709
|
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
24376
24710
|
}
|
|
24377
|
-
const userFile =
|
|
24711
|
+
const userFile = join13(home, CLAUDE_USER_CONFIG_FILE);
|
|
24378
24712
|
mcpEntry(userFile, readJson(userFile), out);
|
|
24379
|
-
dataDir(
|
|
24713
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24380
24714
|
}
|
|
24381
24715
|
function scanCodex(agentHome, out) {
|
|
24382
|
-
const hooksFile =
|
|
24716
|
+
const hooksFile = join13(agentHome, HOOKS_JSON_FILE);
|
|
24383
24717
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
24384
24718
|
if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
|
|
24385
24719
|
out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
|
|
24386
24720
|
}
|
|
24387
24721
|
}
|
|
24388
|
-
const tomlFile =
|
|
24722
|
+
const tomlFile = join13(agentHome, CONFIG_TOML_FILE);
|
|
24389
24723
|
const config2 = readTomlValue(tomlFile);
|
|
24390
24724
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
24391
24725
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
24392
24726
|
if (isV2McpTable(hostConfigValueAt(config2, span2.path.slice(0, 2)))) continue;
|
|
24393
24727
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
24394
24728
|
}
|
|
24395
|
-
dataDir(
|
|
24729
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24396
24730
|
}
|
|
24397
24731
|
function scanGemini(agentHome, out) {
|
|
24398
|
-
const file2 =
|
|
24732
|
+
const file2 = join13(agentHome, SETTINGS_FILE);
|
|
24399
24733
|
for (const c of nestedCommands(readJson(file2))) {
|
|
24400
24734
|
if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
|
|
24401
24735
|
}
|
|
24402
|
-
dataDir(
|
|
24736
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
|
|
24403
24737
|
}
|
|
24404
24738
|
function scanVscode(agentHome, project, out) {
|
|
24405
24739
|
if (project !== void 0) {
|
|
24406
|
-
v1HookFile(
|
|
24407
|
-
const mcpFile2 =
|
|
24740
|
+
v1HookFile(join13(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
24741
|
+
const mcpFile2 = join13(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
24408
24742
|
const doc = readJson(mcpFile2);
|
|
24409
24743
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
24410
24744
|
const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
24411
24745
|
if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
|
|
24412
24746
|
out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
24413
24747
|
}
|
|
24414
|
-
const sessions =
|
|
24748
|
+
const sessions = join13(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
24415
24749
|
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out);
|
|
24416
24750
|
}
|
|
24417
|
-
dataDir(
|
|
24751
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
24418
24752
|
}
|
|
24419
24753
|
function jsonFiles(dir) {
|
|
24420
24754
|
try {
|
|
24421
|
-
return
|
|
24755
|
+
return readdirSync5(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
24422
24756
|
} catch {
|
|
24423
24757
|
return [];
|
|
24424
24758
|
}
|
|
24425
24759
|
}
|
|
24426
24760
|
function scanKiro(agentHome, project, out) {
|
|
24427
|
-
const agentsDir =
|
|
24428
|
-
const defaultFile =
|
|
24761
|
+
const agentsDir = join13(agentHome, KIRO_AGENTS_DIR);
|
|
24762
|
+
const defaultFile = join13(agentHome, ...KIRO_AGENT_FILE);
|
|
24429
24763
|
for (const name of jsonFiles(agentsDir)) {
|
|
24430
|
-
const file2 =
|
|
24764
|
+
const file2 = join13(agentsDir, name);
|
|
24431
24765
|
const doc = readJson(file2);
|
|
24432
24766
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
24433
24767
|
out.push(finding(file2, "", V1_REASON.kiroAgentFile));
|
|
@@ -24438,31 +24772,31 @@ function scanKiro(agentHome, project, out) {
|
|
|
24438
24772
|
if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
|
|
24439
24773
|
}
|
|
24440
24774
|
}
|
|
24441
|
-
const steeringDocs = [
|
|
24442
|
-
if (project !== void 0) steeringDocs.push(
|
|
24775
|
+
const steeringDocs = [join13(agentHome, ...KIRO_STEERING_FILE)];
|
|
24776
|
+
if (project !== void 0) steeringDocs.push(join13(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
24443
24777
|
for (const file2 of steeringDocs) {
|
|
24444
24778
|
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
24445
24779
|
}
|
|
24446
|
-
dataDir(
|
|
24780
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24447
24781
|
}
|
|
24448
24782
|
function piNpmIsCurrent(piAgentDir) {
|
|
24449
|
-
const doc = readJson(
|
|
24783
|
+
const doc = readJson(join13(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
24450
24784
|
const version2 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
24451
24785
|
return Number.parseInt(version2, 10) >= PI_CURRENT_MAJOR;
|
|
24452
24786
|
}
|
|
24453
24787
|
function scanPi(piAgentDir, agentHome, out) {
|
|
24454
|
-
const file2 =
|
|
24788
|
+
const file2 = join13(piAgentDir, SETTINGS_FILE);
|
|
24455
24789
|
const doc = readJson(file2);
|
|
24456
24790
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
24457
24791
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
24458
24792
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
24459
24793
|
if (spec === PI_GIT_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piGit));
|
|
24460
24794
|
});
|
|
24461
|
-
dataDir(
|
|
24795
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24462
24796
|
}
|
|
24463
24797
|
function scanOpencode(agentHome, out) {
|
|
24464
24798
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
24465
|
-
const file2 =
|
|
24799
|
+
const file2 = join13(agentHome, name);
|
|
24466
24800
|
const doc = readJson(file2);
|
|
24467
24801
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
24468
24802
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
|
|
@@ -24473,13 +24807,13 @@ function scanOpencode(agentHome, out) {
|
|
|
24473
24807
|
}
|
|
24474
24808
|
}
|
|
24475
24809
|
function scanZcode(agentHome, out) {
|
|
24476
|
-
const configFile =
|
|
24810
|
+
const configFile = join13(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
24477
24811
|
const config2 = readJson(configFile);
|
|
24478
24812
|
const events = isObj(config2) && isObj(config2[HOOKS_KEY]) ? config2[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
24479
24813
|
for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
24480
24814
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
|
|
24481
24815
|
}
|
|
24482
|
-
const hooksFile =
|
|
24816
|
+
const hooksFile = join13(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
24483
24817
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
24484
24818
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
|
|
24485
24819
|
}
|
|
@@ -24503,14 +24837,14 @@ function firstTmpMatch(dir) {
|
|
|
24503
24837
|
}
|
|
24504
24838
|
}
|
|
24505
24839
|
function scanAll(home, tmp, out) {
|
|
24506
|
-
const root =
|
|
24507
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
24840
|
+
const root = join13(home, DATA_ROOT.slice(1));
|
|
24841
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join13(root, name), V1_REASON.dataRoot, out);
|
|
24508
24842
|
if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
24509
24843
|
}
|
|
24510
24844
|
function detectV1(agent, home, scope = {}) {
|
|
24511
24845
|
const out = [];
|
|
24512
24846
|
const project = scope.project;
|
|
24513
|
-
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir :
|
|
24847
|
+
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir : join13(home, ...AGENT_HOME_DIR[agent]);
|
|
24514
24848
|
switch (agent) {
|
|
24515
24849
|
case "claude-code":
|
|
24516
24850
|
scanClaudeCode(home, agentHome, out);
|
|
@@ -24523,11 +24857,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24523
24857
|
break;
|
|
24524
24858
|
case "qwen":
|
|
24525
24859
|
claudeShapeSettings(agentHome, out);
|
|
24526
|
-
dataDir(
|
|
24860
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24527
24861
|
break;
|
|
24528
24862
|
case "copilot-cli":
|
|
24529
|
-
v1HookFile(
|
|
24530
|
-
dataDir(
|
|
24863
|
+
v1HookFile(join13(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
24864
|
+
dataDir(join13(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24531
24865
|
break;
|
|
24532
24866
|
case "vscode":
|
|
24533
24867
|
scanVscode(agentHome, project, out);
|
|
@@ -24536,7 +24870,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24536
24870
|
scanKiro(agentHome, project, out);
|
|
24537
24871
|
break;
|
|
24538
24872
|
case "pi":
|
|
24539
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
24873
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join13(agentHome, PI_AGENT_DIR), agentHome, out);
|
|
24540
24874
|
break;
|
|
24541
24875
|
// D-WIN-PIDIR-1: empty is unset
|
|
24542
24876
|
case "opencode":
|
|
@@ -24551,8 +24885,8 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24551
24885
|
}
|
|
24552
24886
|
|
|
24553
24887
|
// src/core/ops/plugin-root.ts
|
|
24554
|
-
import { existsSync as existsSync7, readdirSync as
|
|
24555
|
-
import { dirname as dirname7, isAbsolute as
|
|
24888
|
+
import { existsSync as existsSync7, readdirSync as readdirSync6, readFileSync as readFileSync10, realpathSync as realpathSync4 } from "node:fs";
|
|
24889
|
+
import { dirname as dirname7, isAbsolute as isAbsolute4, join as join14, sep as sep4 } from "node:path";
|
|
24556
24890
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
24557
24891
|
function missing(agent, path8) {
|
|
24558
24892
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
@@ -24593,15 +24927,15 @@ var realOrNull = (path8) => {
|
|
|
24593
24927
|
};
|
|
24594
24928
|
var readOrNull = (file2) => {
|
|
24595
24929
|
try {
|
|
24596
|
-
return
|
|
24930
|
+
return readFileSync10(file2, "utf8");
|
|
24597
24931
|
} catch {
|
|
24598
24932
|
return null;
|
|
24599
24933
|
}
|
|
24600
24934
|
};
|
|
24601
24935
|
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
24602
24936
|
function enabledPlugins(claudeDir, project) {
|
|
24603
|
-
const files = [
|
|
24604
|
-
if (project !== void 0) files.push(
|
|
24937
|
+
const files = [join14(claudeDir, SETTINGS_FILE)];
|
|
24938
|
+
if (project !== void 0) files.push(join14(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join14(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
|
|
24605
24939
|
const out = {};
|
|
24606
24940
|
for (const file2 of files) {
|
|
24607
24941
|
const text = readOrNull(file2);
|
|
@@ -24617,7 +24951,7 @@ function marketplaceChoice(env, worktree) {
|
|
|
24617
24951
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
24618
24952
|
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
24619
24953
|
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
24620
|
-
const record4 = readOrNull(
|
|
24954
|
+
const record4 = readOrNull(join14(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
24621
24955
|
const recorded = record4 === null ? [] : recordedInstalls(record4);
|
|
24622
24956
|
if (recorded.length === 0) return { record: false };
|
|
24623
24957
|
const live = recorded.filter((r) => existsSync7(r.installPath));
|
|
@@ -24640,18 +24974,18 @@ function marketplaceChoice(env, worktree) {
|
|
|
24640
24974
|
}
|
|
24641
24975
|
function marketplaceRoot(adapter, env, worktree) {
|
|
24642
24976
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
24643
|
-
const plugins =
|
|
24644
|
-
const cache =
|
|
24977
|
+
const plugins = join14(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
24978
|
+
const cache = join14(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
24645
24979
|
const script = process.argv[1];
|
|
24646
24980
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
24647
24981
|
const choice = marketplaceChoice(env, worktree);
|
|
24648
24982
|
if ("root" in choice) return choice.root;
|
|
24649
24983
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
24650
24984
|
const cacheReal = realOrNull(cache);
|
|
24651
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync7(
|
|
24652
|
-
const pattern =
|
|
24985
|
+
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync7(join14(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
24986
|
+
const pattern = join14(cache, "*", PLUGIN_NAME);
|
|
24653
24987
|
if (!existsSync7(cache)) throw missing(adapter.id, pattern);
|
|
24654
|
-
const found =
|
|
24988
|
+
const found = readdirSync6(cache).sort().map((marketplace) => join14(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync7(dir));
|
|
24655
24989
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
24656
24990
|
return found[0];
|
|
24657
24991
|
}
|
|
@@ -24664,12 +24998,12 @@ function configEntryRoot(adapter, env) {
|
|
|
24664
24998
|
const value = parseHostConfig(adapter.id, file2, current.text, current.format);
|
|
24665
24999
|
const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
|
|
24666
25000
|
const script = Array.isArray(args) ? args[0] : void 0;
|
|
24667
|
-
if (typeof script !== "string" || !
|
|
25001
|
+
if (typeof script !== "string" || !isAbsolute4(script)) throw missing(adapter.id, file2);
|
|
24668
25002
|
return dirname7(script);
|
|
24669
25003
|
}
|
|
24670
25004
|
function packageDirOf(dir) {
|
|
24671
25005
|
for (let cur = dir; ; ) {
|
|
24672
|
-
if (existsSync7(
|
|
25006
|
+
if (existsSync7(join14(cur, D1_PACKAGE_FILE))) return cur;
|
|
24673
25007
|
const up = dirname7(cur);
|
|
24674
25008
|
if (up === cur) return dir;
|
|
24675
25009
|
cur = up;
|
|
@@ -24684,9 +25018,9 @@ function candidate(adapter, env, worktree) {
|
|
|
24684
25018
|
case "hooks+mcp":
|
|
24685
25019
|
return configEntryRoot(adapter, env);
|
|
24686
25020
|
case "extension":
|
|
24687
|
-
return
|
|
25021
|
+
return join14(adapter.id === "gemini" ? geminiDirOf(env, requireHomeDir(env)) : join14(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id]), EXTENSIONS_DIR_NAME, PLUGIN_NAME);
|
|
24688
25022
|
case "plugin":
|
|
24689
|
-
return
|
|
25023
|
+
return join14(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
24690
25024
|
case "in-process":
|
|
24691
25025
|
return packageDirOf(dirname7(fileURLToPath2(import.meta.url)));
|
|
24692
25026
|
}
|
|
@@ -24701,7 +25035,7 @@ function resolvePluginRoot(adapter, env, worktree) {
|
|
|
24701
25035
|
}
|
|
24702
25036
|
|
|
24703
25037
|
// src/setup/pi-gate.ts
|
|
24704
|
-
import { existsSync as existsSync8, readFileSync as
|
|
25038
|
+
import { existsSync as existsSync8, readFileSync as readFileSync11, realpathSync as realpathSync5 } from "node:fs";
|
|
24705
25039
|
import path4 from "node:path";
|
|
24706
25040
|
var EXTENSIONS_KEY = "extensions";
|
|
24707
25041
|
var PROJECT_DIR = ".pi";
|
|
@@ -24711,7 +25045,7 @@ var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
|
24711
25045
|
function load(file2) {
|
|
24712
25046
|
if (!existsSync8(file2)) return void 0;
|
|
24713
25047
|
try {
|
|
24714
|
-
return { file: file2, doc: parseHostConfig("pi", file2, hostText(
|
|
25048
|
+
return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync11(file2, "utf8")), "json") };
|
|
24715
25049
|
} catch {
|
|
24716
25050
|
return void 0;
|
|
24717
25051
|
}
|
|
@@ -24770,8 +25104,8 @@ function piInstalledIn(env, home, pkgDir, cwd) {
|
|
|
24770
25104
|
}
|
|
24771
25105
|
|
|
24772
25106
|
// src/core/ops/doctor-env.ts
|
|
24773
|
-
import { existsSync as existsSync9, readFileSync as
|
|
24774
|
-
import { isAbsolute as
|
|
25107
|
+
import { existsSync as existsSync9, readFileSync as readFileSync12, realpathSync as realpathSync6 } from "node:fs";
|
|
25108
|
+
import { isAbsolute as isAbsolute5, join as join15, relative as relative4 } from "node:path";
|
|
24775
25109
|
function pass(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
24776
25110
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
24777
25111
|
}
|
|
@@ -24786,7 +25120,7 @@ function warn(id2, detail, fixCommand) {
|
|
|
24786
25120
|
}
|
|
24787
25121
|
function bundleVersion(bundleDir2) {
|
|
24788
25122
|
try {
|
|
24789
|
-
const v = JSON.parse(
|
|
25123
|
+
const v = JSON.parse(readFileSync12(join15(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24790
25124
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24791
25125
|
} catch {
|
|
24792
25126
|
return void 0;
|
|
@@ -24940,7 +25274,7 @@ function checkMcp(ctx, adapter) {
|
|
|
24940
25274
|
function piCwdInside(worktree, piCwd) {
|
|
24941
25275
|
if (piCwd === void 0 || !existsSync9(piCwd)) return false;
|
|
24942
25276
|
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
24943
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
25277
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute5(rel);
|
|
24944
25278
|
}
|
|
24945
25279
|
function checkProject(i) {
|
|
24946
25280
|
const bad = fail2("D7", D7_DETAIL(i.project.source), D7_FIX);
|
|
@@ -24948,6 +25282,20 @@ function checkProject(i) {
|
|
|
24948
25282
|
if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
|
|
24949
25283
|
return pass("D7");
|
|
24950
25284
|
}
|
|
25285
|
+
function projectOrMissing(ctx) {
|
|
25286
|
+
try {
|
|
25287
|
+
return { project: ctx.project };
|
|
25288
|
+
} catch (err) {
|
|
25289
|
+
if (err instanceof CtxError && err.code === "NO_PROJECT") return { missing: String(err.vars.kind) };
|
|
25290
|
+
throw err;
|
|
25291
|
+
}
|
|
25292
|
+
}
|
|
25293
|
+
function noProjectRow(kind) {
|
|
25294
|
+
return fail2("D7", D7_NO_PROJECT_DETAIL(kind), D7_FIX);
|
|
25295
|
+
}
|
|
25296
|
+
function needsProjectRow(id2) {
|
|
25297
|
+
return unknown2(id2, DOCTOR_NEEDS_PROJECT_DETAIL);
|
|
25298
|
+
}
|
|
24951
25299
|
function checkMode(adapter, hostPermission) {
|
|
24952
25300
|
if (hostPermission === "missing") return fail2("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
|
|
24953
25301
|
if (hostPermission === "wired") return pass("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
|
|
@@ -24970,8 +25318,8 @@ function checkRuntimes(env, shellRow) {
|
|
|
24970
25318
|
}
|
|
24971
25319
|
|
|
24972
25320
|
// src/core/ops/omp-import.ts
|
|
24973
|
-
import { join as
|
|
24974
|
-
var { existsSync: existsSync10, readFileSync:
|
|
25321
|
+
import { join as join16 } from "node:path";
|
|
25322
|
+
var { existsSync: existsSync10, readFileSync: readFileSync13 } = process.getBuiltinModule("node:fs");
|
|
24975
25323
|
var OMP_DISABLED_SERVERS_KEY = "disabledServers";
|
|
24976
25324
|
var OMP_MCP_FILE = "mcp.json";
|
|
24977
25325
|
var OMP_CONFIG_FILE = "config.yml";
|
|
@@ -24980,12 +25328,12 @@ var DISABLED_PROVIDERS = "disabledProviders";
|
|
|
24980
25328
|
var CLAUDE_PROVIDER = "claude";
|
|
24981
25329
|
var ALL_PROVIDERS = ["*", "all"];
|
|
24982
25330
|
function ompImportFiles(home) {
|
|
24983
|
-
const agentDir =
|
|
24984
|
-
return { config:
|
|
25331
|
+
const agentDir = join16(home, ...AGENT_HOME_DIR.omp, PI_AGENT_DIR);
|
|
25332
|
+
return { config: join16(agentDir, OMP_CONFIG_FILE), mcp: join16(agentDir, OMP_MCP_FILE), claude: join16(home, CLAUDE_USER_CONFIG_FILE) };
|
|
24985
25333
|
}
|
|
24986
25334
|
function readText2(file2) {
|
|
24987
25335
|
try {
|
|
24988
|
-
return existsSync10(file2) ? hostText(
|
|
25336
|
+
return existsSync10(file2) ? hostText(readFileSync13(file2, "utf8")) : void 0;
|
|
24989
25337
|
} catch {
|
|
24990
25338
|
return void 0;
|
|
24991
25339
|
}
|
|
@@ -25113,11 +25461,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
25113
25461
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
25114
25462
|
function mcpFile(row5, home, env) {
|
|
25115
25463
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
25116
|
-
if (row5.id === "codex") return
|
|
25464
|
+
if (row5.id === "codex") return join17(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
25117
25465
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
25118
|
-
if (row5.id === "opencode") return
|
|
25466
|
+
if (row5.id === "opencode") return join17(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
25119
25467
|
if (row5.id === "pi") {
|
|
25120
|
-
return
|
|
25468
|
+
return join17(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
25121
25469
|
}
|
|
25122
25470
|
return null;
|
|
25123
25471
|
}
|
|
@@ -25130,27 +25478,27 @@ function codexNativeDir(env, home) {
|
|
|
25130
25478
|
const codexDir = codexDirOf(env, home);
|
|
25131
25479
|
let enabled;
|
|
25132
25480
|
try {
|
|
25133
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
25481
|
+
enabled = hostConfigValueAt(readParsed("codex", join17(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
25134
25482
|
} catch {
|
|
25135
25483
|
return null;
|
|
25136
25484
|
}
|
|
25137
25485
|
if (enabled !== true) return null;
|
|
25138
|
-
const cache =
|
|
25486
|
+
const cache = join17(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
25139
25487
|
if (!existsSync11(cache)) return null;
|
|
25140
25488
|
const found = [];
|
|
25141
|
-
for (const market of
|
|
25142
|
-
const plugin =
|
|
25489
|
+
for (const market of readdirSync7(cache)) {
|
|
25490
|
+
const plugin = join17(cache, market, SERVER_KEY);
|
|
25143
25491
|
if (!existsSync11(plugin)) continue;
|
|
25144
|
-
for (const version2 of
|
|
25145
|
-
const dir =
|
|
25146
|
-
if (existsSync11(
|
|
25492
|
+
for (const version2 of readdirSync7(plugin).sort()) {
|
|
25493
|
+
const dir = join17(plugin, version2, CODEX_PLUGIN_SUBDIR);
|
|
25494
|
+
if (existsSync11(join17(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
25147
25495
|
}
|
|
25148
25496
|
}
|
|
25149
25497
|
return found.length === 0 ? null : found[found.length - 1];
|
|
25150
25498
|
}
|
|
25151
25499
|
function nativeMcpWrong(dir, row5) {
|
|
25152
25500
|
try {
|
|
25153
|
-
const entry = hostConfigValueAt(readParsed(row5.id,
|
|
25501
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join17(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
25154
25502
|
if (!isObject4(entry)) return true;
|
|
25155
25503
|
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
25156
25504
|
const script = args[0];
|
|
@@ -25221,17 +25569,17 @@ function opencodePluginDirs(configDir, worktree) {
|
|
|
25221
25569
|
return [configDir, opencodeProjectDir(worktree)];
|
|
25222
25570
|
}
|
|
25223
25571
|
function opencodeProjectDir(worktree) {
|
|
25224
|
-
return
|
|
25572
|
+
return join17(worktree, OPENCODE_PROJECT_DIR);
|
|
25225
25573
|
}
|
|
25226
25574
|
function packageResolves(fromDir) {
|
|
25227
25575
|
for (let d = fromDir; ; d = dirname8(d)) {
|
|
25228
|
-
if (existsSync11(
|
|
25576
|
+
if (existsSync11(join17(d, NODE_MODULES_DIR, SERVER_KEY, PACKAGE_JSON_FILE))) return true;
|
|
25229
25577
|
if (dirname8(d) === d) return false;
|
|
25230
25578
|
}
|
|
25231
25579
|
}
|
|
25232
25580
|
function opencodeDirPlugins(dirs) {
|
|
25233
25581
|
const bundle = opencodePluginFile();
|
|
25234
|
-
const ownFile =
|
|
25582
|
+
const ownFile = join17(bundle, ...OPENCODE_PLUGIN_PATH).split("\\").join("/");
|
|
25235
25583
|
const isModule = (p) => OWN_PLUGIN_MODULES.includes(p);
|
|
25236
25584
|
const isPath = (p) => {
|
|
25237
25585
|
if (p === ownFile || p === `${FILE_URL_PREFIX}${ownFile}`) return true;
|
|
@@ -25241,20 +25589,20 @@ function opencodeDirPlugins(dirs) {
|
|
|
25241
25589
|
};
|
|
25242
25590
|
const out = [];
|
|
25243
25591
|
for (const dir of dirs) {
|
|
25244
|
-
const pdir =
|
|
25592
|
+
const pdir = join17(dir, OPENCODE_PLUGINS_DIR);
|
|
25245
25593
|
let names;
|
|
25246
25594
|
try {
|
|
25247
|
-
names =
|
|
25595
|
+
names = readdirSync7(pdir);
|
|
25248
25596
|
} catch {
|
|
25249
25597
|
continue;
|
|
25250
25598
|
}
|
|
25251
25599
|
for (const name of names) {
|
|
25252
|
-
const loose = OPENCODE_PLUGIN_EXTS.some((x) => name.endsWith(x)) ? [
|
|
25253
|
-
const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x) =>
|
|
25600
|
+
const loose = OPENCODE_PLUGIN_EXTS.some((x) => name.endsWith(x)) ? [join17(pdir, name)] : [];
|
|
25601
|
+
const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x) => join17(pdir, name, `${OPENCODE_PLUGIN_INDEX}${x}`))];
|
|
25254
25602
|
for (const f of files) {
|
|
25255
25603
|
let text;
|
|
25256
25604
|
try {
|
|
25257
|
-
const b =
|
|
25605
|
+
const b = readFileSync14(f);
|
|
25258
25606
|
if (b.length > OPENCODE_DIR_FILE_MAX) continue;
|
|
25259
25607
|
text = b.toString("utf8");
|
|
25260
25608
|
} catch {
|
|
@@ -25265,7 +25613,7 @@ function opencodeDirPlugins(dirs) {
|
|
|
25265
25613
|
const loads = lits.some((p) => {
|
|
25266
25614
|
if (isModule(p)) return packageResolves(dirname8(f));
|
|
25267
25615
|
const bare2 = p.startsWith(FILE_URL_PREFIX) ? p.slice(FILE_URL_PREFIX.length) : p;
|
|
25268
|
-
return existsSync11(
|
|
25616
|
+
return existsSync11(isAbsolute6(bare2) ? bare2 : resolve9(dirname8(f), bare2));
|
|
25269
25617
|
});
|
|
25270
25618
|
out.push({ file: f, loads });
|
|
25271
25619
|
}
|
|
@@ -25284,18 +25632,18 @@ function opencodeMcpOwn(entry) {
|
|
|
25284
25632
|
}
|
|
25285
25633
|
function opencodeFileValue(file2) {
|
|
25286
25634
|
if (!existsSync11(file2)) return {};
|
|
25287
|
-
return parseHostConfig("opencode", file2, hostText(
|
|
25635
|
+
return parseHostConfig("opencode", file2, hostText(readFileSync14(file2, "utf8")), "jsonc");
|
|
25288
25636
|
}
|
|
25289
25637
|
function opencodeValueListed(value) {
|
|
25290
25638
|
const bundle = opencodePluginFile();
|
|
25291
|
-
const own2 = [bundle,
|
|
25639
|
+
const own2 = [bundle, join17(bundle, ...OPENCODE_PLUGIN_PATH)];
|
|
25292
25640
|
if ([OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list2(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own2)))) return true;
|
|
25293
25641
|
const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
|
|
25294
25642
|
return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
|
|
25295
25643
|
}
|
|
25296
25644
|
function opencodeListed(file2, worktree) {
|
|
25297
25645
|
const dirs = [dirname8(file2), worktree];
|
|
25298
|
-
if (dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(
|
|
25646
|
+
if (dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(join17(dir, name)))))) return true;
|
|
25299
25647
|
return opencodeDirPlugin(opencodePluginDirs(dirname8(file2), worktree)) !== void 0;
|
|
25300
25648
|
}
|
|
25301
25649
|
function mcpWrong(row5, home, env, worktree) {
|
|
@@ -25317,7 +25665,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
25317
25665
|
function hookFile(row5, spec, home, env, worktree) {
|
|
25318
25666
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
25319
25667
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
25320
|
-
const file2 = native !== null ?
|
|
25668
|
+
const file2 = native !== null ? join17(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join17(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join17(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join17(kiroDirOf(env, home), ...spec.file.slice(1)) : join17(root, ...spec.file);
|
|
25321
25669
|
return file2;
|
|
25322
25670
|
}
|
|
25323
25671
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -25328,7 +25676,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
25328
25676
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
25329
25677
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
25330
25678
|
if (row5.id === "codex") {
|
|
25331
|
-
const config2 = readParsed(row5.id,
|
|
25679
|
+
const config2 = readParsed(row5.id, join17(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
25332
25680
|
if (hostConfigValueAt(config2, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
25333
25681
|
}
|
|
25334
25682
|
} catch {
|
|
@@ -25373,13 +25721,13 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
25373
25721
|
function checkPiInstall(env, home, worktree) {
|
|
25374
25722
|
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
25375
25723
|
if (found !== void 0) return { ...pass2("D3"), detail: found };
|
|
25376
|
-
return fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN +
|
|
25724
|
+
return fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join17(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
|
|
25377
25725
|
}
|
|
25378
25726
|
var OMP_PLUGINS_DIR = "plugins";
|
|
25379
25727
|
var OMP_LOCK_FILE = "omp-plugins.lock.json";
|
|
25380
25728
|
function readJson2(file2) {
|
|
25381
25729
|
try {
|
|
25382
|
-
const doc = JSON.parse(
|
|
25730
|
+
const doc = JSON.parse(readFileSync14(file2, "utf8"));
|
|
25383
25731
|
return typeof doc === "object" && doc !== null ? doc : void 0;
|
|
25384
25732
|
} catch {
|
|
25385
25733
|
return void 0;
|
|
@@ -25390,9 +25738,9 @@ function ownEntry(doc, key) {
|
|
|
25390
25738
|
return typeof map2 === "object" && map2 !== null ? map2[SERVER_KEY] : void 0;
|
|
25391
25739
|
}
|
|
25392
25740
|
function checkOmpInstall(home) {
|
|
25393
|
-
const dir =
|
|
25394
|
-
const lock =
|
|
25395
|
-
const pkg =
|
|
25741
|
+
const dir = join17(home, ...AGENT_HOME_DIR.omp, OMP_PLUGINS_DIR);
|
|
25742
|
+
const lock = join17(dir, OMP_LOCK_FILE);
|
|
25743
|
+
const pkg = join17(dir, PI_PACKAGE_JSON_FILE);
|
|
25396
25744
|
const entry = ownEntry(readJson2(lock), "plugins");
|
|
25397
25745
|
const missing2 = (file2) => fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + file2, NATIVE_INSTALL.omp[0]);
|
|
25398
25746
|
if (typeof entry !== "object" || entry === null) return missing2(lock);
|
|
@@ -25429,10 +25777,10 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
25429
25777
|
}
|
|
25430
25778
|
function checkDoubleFire(agent, worktree) {
|
|
25431
25779
|
if (agent !== "claude-code" && agent !== "vscode") return pass2("D5b");
|
|
25432
|
-
const claude = parsedOrNull(agent,
|
|
25780
|
+
const claude = parsedOrNull(agent, join17(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
25433
25781
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
25434
25782
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
25435
|
-
const vscode = parsedOrNull(agent,
|
|
25783
|
+
const vscode = parsedOrNull(agent, join17(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
25436
25784
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
25437
25785
|
return hooksOn && useClaudeHooks ? fail3("D5b", D5B_DETAIL, D5B_FIX) : pass2("D5b");
|
|
25438
25786
|
}
|
|
@@ -25443,7 +25791,7 @@ function configPaths(row5, env, worktree) {
|
|
|
25443
25791
|
const mcp = mcpFile(row5, home, env);
|
|
25444
25792
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
25445
25793
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
25446
|
-
if (native !== null) out.push({ label: "Codex plugin MCP", path:
|
|
25794
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join17(native, CODEX_PLUGIN_MCP_FILE) });
|
|
25447
25795
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
25448
25796
|
if (spec !== null) {
|
|
25449
25797
|
try {
|
|
@@ -25463,7 +25811,7 @@ function configPaths(row5, env, worktree) {
|
|
|
25463
25811
|
}
|
|
25464
25812
|
|
|
25465
25813
|
// src/core/ops/doctor-db.ts
|
|
25466
|
-
import { existsSync as existsSync12, statSync as
|
|
25814
|
+
import { existsSync as existsSync12, statSync as statSync7 } from "node:fs";
|
|
25467
25815
|
var unknown3 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
|
|
25468
25816
|
var pass3 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
|
|
25469
25817
|
var fail4 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -25474,7 +25822,7 @@ function isCorrupt2(err) {
|
|
|
25474
25822
|
const primary = code & SQLITE_PRIMARY_CODE_MASK;
|
|
25475
25823
|
return primary === SQLITE_CORRUPT_CODE || primary === SQLITE_NOTADB_CODE;
|
|
25476
25824
|
}
|
|
25477
|
-
var
|
|
25825
|
+
var message3 = (err) => err instanceof Error ? err.message : String(err);
|
|
25478
25826
|
async function loadSqlite2() {
|
|
25479
25827
|
try {
|
|
25480
25828
|
return await import(SQLITE_MODULE);
|
|
@@ -25505,7 +25853,7 @@ function orphanFiles(dbPath) {
|
|
|
25505
25853
|
const files = [];
|
|
25506
25854
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
25507
25855
|
const path8 = dbPath + suffix;
|
|
25508
|
-
if (existsSync12(path8)) files.push({ path: path8, bytes:
|
|
25856
|
+
if (existsSync12(path8)) files.push({ path: path8, bytes: statSync7(path8).size });
|
|
25509
25857
|
}
|
|
25510
25858
|
return files.length > 0 && !existsSync12(dbPath) ? files : [];
|
|
25511
25859
|
}
|
|
@@ -25533,7 +25881,7 @@ async function checkDb(project) {
|
|
|
25533
25881
|
return { row: pass3("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
25534
25882
|
} catch (err) {
|
|
25535
25883
|
if (isCorrupt2(err)) return { row: fail4(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale: false, integrityFailed: true, orphan: [] };
|
|
25536
|
-
return { row: unknown3("D8",
|
|
25884
|
+
return { row: unknown3("D8", message3(err)), ...clean };
|
|
25537
25885
|
} finally {
|
|
25538
25886
|
raw?.close();
|
|
25539
25887
|
}
|
|
@@ -25549,14 +25897,14 @@ async function checkIndex(project) {
|
|
|
25549
25897
|
const chunks = Number(cell(raw.prepare("SELECT count(*) FROM chunks").get()));
|
|
25550
25898
|
return pass3("D9", D9_INDEX_DETAIL(sources, chunks));
|
|
25551
25899
|
} catch (err) {
|
|
25552
|
-
return unknown3("D9",
|
|
25900
|
+
return unknown3("D9", message3(err));
|
|
25553
25901
|
} finally {
|
|
25554
25902
|
raw?.close();
|
|
25555
25903
|
}
|
|
25556
25904
|
}
|
|
25557
25905
|
|
|
25558
25906
|
// src/core/ops/doctor-hook.ts
|
|
25559
|
-
import { existsSync as existsSync14, mkdirSync as
|
|
25907
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync5, mkdtempSync, readFileSync as readFileSync15, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
25560
25908
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
25561
25909
|
import path7 from "node:path";
|
|
25562
25910
|
|
|
@@ -27390,7 +27738,7 @@ import { spawn as spawn3, spawnSync as spawnSync2 } from "node:child_process";
|
|
|
27390
27738
|
|
|
27391
27739
|
// src/setup/spawn-bin.ts
|
|
27392
27740
|
import { spawnSync } from "node:child_process";
|
|
27393
|
-
import { accessSync as accessSync2, constants as fsc, statSync as
|
|
27741
|
+
import { accessSync as accessSync2, constants as fsc, statSync as statSync8 } from "node:fs";
|
|
27394
27742
|
import path5 from "node:path";
|
|
27395
27743
|
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
27396
27744
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
@@ -27408,7 +27756,7 @@ function whichBin(bin, env, platform = process.platform) {
|
|
|
27408
27756
|
const f = path5.join(dir, n);
|
|
27409
27757
|
try {
|
|
27410
27758
|
accessSync2(f, fsc.X_OK);
|
|
27411
|
-
if (
|
|
27759
|
+
if (statSync8(f).isFile()) return f;
|
|
27412
27760
|
} catch {
|
|
27413
27761
|
}
|
|
27414
27762
|
}
|
|
@@ -27610,7 +27958,7 @@ function loadFixture(bundleDir2, agent) {
|
|
|
27610
27958
|
if (!existsSync14(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
27611
27959
|
let all;
|
|
27612
27960
|
try {
|
|
27613
|
-
all = JSON.parse(hostText(
|
|
27961
|
+
all = JSON.parse(hostText(readFileSync15(file2, "utf8")));
|
|
27614
27962
|
} catch (err) {
|
|
27615
27963
|
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
27616
27964
|
}
|
|
@@ -27702,7 +28050,7 @@ async function mediaProbe(i, timeoutMs) {
|
|
|
27702
28050
|
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-media-"));
|
|
27703
28051
|
try {
|
|
27704
28052
|
const filePath = path7.join(home, "d5-media-probe.png");
|
|
27705
|
-
|
|
28053
|
+
writeFileSync3(filePath, Buffer.concat([PNG_SIGNATURE, Buffer.alloc(OUTPUT_CAP + 1)]));
|
|
27706
28054
|
const node = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home });
|
|
27707
28055
|
const r = await runProcess([node.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
27708
28056
|
cwd: i.bundleDir,
|
|
@@ -27729,9 +28077,9 @@ async function ownProbe(i, timeoutMs) {
|
|
|
27729
28077
|
try {
|
|
27730
28078
|
const cfg = path7.join(home, ".claude");
|
|
27731
28079
|
const refs = path7.join(cfg, "skills", "d5-probe", "references");
|
|
27732
|
-
|
|
28080
|
+
mkdirSync5(refs, { recursive: true });
|
|
27733
28081
|
const filePath = path7.join(refs, "d5-own-probe.md");
|
|
27734
|
-
|
|
28082
|
+
writeFileSync3(filePath, "# d5 own probe\n".repeat(Math.ceil((OUTPUT_CAP + 1) / 15)));
|
|
27735
28083
|
const node = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, CLAUDE_CONFIG_DIR: cfg });
|
|
27736
28084
|
const r = await runProcess([node.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
27737
28085
|
cwd: i.bundleDir,
|
|
@@ -27885,16 +28233,16 @@ async function checkHookRoundTrip(i) {
|
|
|
27885
28233
|
}
|
|
27886
28234
|
|
|
27887
28235
|
// src/core/ops/db-heal.ts
|
|
27888
|
-
import { existsSync as existsSync15, mkdirSync as
|
|
27889
|
-
import { basename as basename4, dirname as dirname9, join as
|
|
28236
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync7, rmSync as rmSync4 } from "node:fs";
|
|
28237
|
+
import { basename as basename4, dirname as dirname9, join as join19 } from "node:path";
|
|
27890
28238
|
|
|
27891
28239
|
// src/core/store/owners.ts
|
|
27892
|
-
import { mkdirSync as
|
|
27893
|
-
import { basename as basename3, join as
|
|
28240
|
+
import { mkdirSync as mkdirSync6, readdirSync as readdirSync8, readFileSync as readFileSync16, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
28241
|
+
import { basename as basename3, join as join18 } from "node:path";
|
|
27894
28242
|
function ownersDir(configDir, projectKey) {
|
|
27895
|
-
return
|
|
28243
|
+
return join18(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
27896
28244
|
}
|
|
27897
|
-
function
|
|
28245
|
+
function errCode3(err) {
|
|
27898
28246
|
return err.code;
|
|
27899
28247
|
}
|
|
27900
28248
|
function isLive(pid) {
|
|
@@ -27903,8 +28251,8 @@ function isLive(pid) {
|
|
|
27903
28251
|
process.kill(pid, 0);
|
|
27904
28252
|
return true;
|
|
27905
28253
|
} catch (err) {
|
|
27906
|
-
if (
|
|
27907
|
-
if (
|
|
28254
|
+
if (errCode3(err) === "ESRCH") return false;
|
|
28255
|
+
if (errCode3(err) === "EPERM") return true;
|
|
27908
28256
|
throw err;
|
|
27909
28257
|
}
|
|
27910
28258
|
}
|
|
@@ -27912,20 +28260,20 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
27912
28260
|
const dir = ownersDir(configDir, projectKey);
|
|
27913
28261
|
let names;
|
|
27914
28262
|
try {
|
|
27915
|
-
names =
|
|
28263
|
+
names = readdirSync8(dir);
|
|
27916
28264
|
} catch (err) {
|
|
27917
|
-
if (
|
|
28265
|
+
if (errCode3(err) === "ENOENT") return [];
|
|
27918
28266
|
throw err;
|
|
27919
28267
|
}
|
|
27920
28268
|
const live = [];
|
|
27921
28269
|
for (const name of names) {
|
|
27922
28270
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
27923
|
-
const file2 =
|
|
28271
|
+
const file2 = join18(dir, name);
|
|
27924
28272
|
let text;
|
|
27925
28273
|
try {
|
|
27926
|
-
text =
|
|
28274
|
+
text = readFileSync16(file2, "utf8");
|
|
27927
28275
|
} catch (err) {
|
|
27928
|
-
if (
|
|
28276
|
+
if (errCode3(err) === "ENOENT") continue;
|
|
27929
28277
|
throw err;
|
|
27930
28278
|
}
|
|
27931
28279
|
const serverId = basename3(name, OWNER_PID_EXT);
|
|
@@ -27992,11 +28340,11 @@ function utcStamp(now) {
|
|
|
27992
28340
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
27993
28341
|
}
|
|
27994
28342
|
function makeOrphanDir(projectDir) {
|
|
27995
|
-
const base =
|
|
28343
|
+
const base = join19(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
27996
28344
|
for (let n = 1; ; n += 1) {
|
|
27997
28345
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
27998
28346
|
try {
|
|
27999
|
-
|
|
28347
|
+
mkdirSync7(dir);
|
|
28000
28348
|
return dir;
|
|
28001
28349
|
} catch (err) {
|
|
28002
28350
|
if (err.code !== "EEXIST") throw err;
|
|
@@ -28009,7 +28357,7 @@ async function healOrphan(project, files, row5) {
|
|
|
28009
28357
|
try {
|
|
28010
28358
|
dir = makeOrphanDir(dirname9(project.dbPath));
|
|
28011
28359
|
for (const f of files) {
|
|
28012
|
-
const to =
|
|
28360
|
+
const to = join19(dir, basename4(f.path));
|
|
28013
28361
|
renameWithRetry(f.path, to);
|
|
28014
28362
|
moved.push({ path: to, bytes: f.bytes });
|
|
28015
28363
|
}
|
|
@@ -28027,8 +28375,8 @@ function keyIsTyped(key) {
|
|
|
28027
28375
|
if (key.length === 0) return false;
|
|
28028
28376
|
for (const ch of key) {
|
|
28029
28377
|
const upper = ch >= "A" && ch <= "Z";
|
|
28030
|
-
const
|
|
28031
|
-
if (!upper && !
|
|
28378
|
+
const digit2 = ch >= "0" && ch <= "9";
|
|
28379
|
+
if (!upper && !digit2 && ch !== "_") return false;
|
|
28032
28380
|
}
|
|
28033
28381
|
return true;
|
|
28034
28382
|
}
|
|
@@ -28107,8 +28455,8 @@ function unsupportedHostOf(sig) {
|
|
|
28107
28455
|
|
|
28108
28456
|
// src/core/ops/doctor-issue.ts
|
|
28109
28457
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
28110
|
-
import { closeSync as closeSync2, existsSync as existsSync16, fstatSync, mkdirSync as
|
|
28111
|
-
import { delimiter, dirname as dirname10, join as
|
|
28458
|
+
import { closeSync as closeSync2, existsSync as existsSync16, fstatSync, mkdirSync as mkdirSync8, openSync as openSync2, readFileSync as readFileSync17, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync5 } from "node:fs";
|
|
28459
|
+
import { delimiter, dirname as dirname10, join as join20 } from "node:path";
|
|
28112
28460
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
28113
28461
|
function tildeOf(env) {
|
|
28114
28462
|
const home = homeDirOf(env);
|
|
@@ -28164,8 +28512,8 @@ function onPath(env, tool) {
|
|
|
28164
28512
|
const out = [];
|
|
28165
28513
|
for (const dir of (envValue(env, "PATH") ?? "").split(delimiter)) {
|
|
28166
28514
|
if (dir === "") continue;
|
|
28167
|
-
for (const n of names) if (existsSync16(
|
|
28168
|
-
out.push(
|
|
28515
|
+
for (const n of names) if (existsSync16(join20(dir, n))) {
|
|
28516
|
+
out.push(join20(dir, n));
|
|
28169
28517
|
break;
|
|
28170
28518
|
}
|
|
28171
28519
|
}
|
|
@@ -28193,9 +28541,11 @@ function hookLogTail(env) {
|
|
|
28193
28541
|
}
|
|
28194
28542
|
async function journalRows(ctx) {
|
|
28195
28543
|
const head2 = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
28196
|
-
|
|
28544
|
+
const p = projectOrMissing(ctx);
|
|
28545
|
+
if ("missing" in p) return [`(no project: ${D7_NO_PROJECT_DETAIL(p.missing)})`];
|
|
28546
|
+
if (!existsSync16(p.project.dbPath)) return [`(context.db is absent at ${p.project.dbPath})`];
|
|
28197
28547
|
try {
|
|
28198
|
-
const db = await openDb(
|
|
28548
|
+
const db = await openDb(p.project, { readOnly: true });
|
|
28199
28549
|
try {
|
|
28200
28550
|
const rows = db.raw.prepare(`SELECT kind, tool, bytes, ok, exit_code, created_at FROM events ORDER BY seq DESC LIMIT ${DOCTOR_JOURNAL_ROWS}`).all();
|
|
28201
28551
|
const cell5 = (v) => v === null || v === void 0 ? "" : String(v);
|
|
@@ -28211,8 +28561,8 @@ function agentConfig(adapter, env, worktree) {
|
|
|
28211
28561
|
const home = homeDirOf(env);
|
|
28212
28562
|
const files = configPaths(adapter, env, worktree);
|
|
28213
28563
|
if (home !== null) {
|
|
28214
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
28215
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
28564
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join20(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
28565
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join20(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
28216
28566
|
}
|
|
28217
28567
|
const out = [];
|
|
28218
28568
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -28225,7 +28575,7 @@ function agentConfig(adapter, env, worktree) {
|
|
|
28225
28575
|
}
|
|
28226
28576
|
let text = "";
|
|
28227
28577
|
try {
|
|
28228
|
-
text =
|
|
28578
|
+
text = readFileSync17(f.path, "utf8");
|
|
28229
28579
|
} catch (err) {
|
|
28230
28580
|
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
28231
28581
|
continue;
|
|
@@ -28254,6 +28604,7 @@ async function buildIssueBody(i) {
|
|
|
28254
28604
|
const failRows = i.rows.filter((r) => r.status !== "PASS");
|
|
28255
28605
|
const envNames = DOCTOR_ENV_NAMES.map((n) => i.env[n] === void 0 ? `${n} (unset)` : `${n}=${i.env[n]}`);
|
|
28256
28606
|
const pathTools = DOCTOR_PATH_TOOLS.map((t) => `PATH holds ${t}: ${onPath(i.env, t).join(", ") || "(absent)"}`);
|
|
28607
|
+
const p = projectOrMissing(i.ctx);
|
|
28257
28608
|
const sections = {
|
|
28258
28609
|
"Summary": [summaryOf(agent, i.rows, i.unsupported)],
|
|
28259
28610
|
"ctx-report": [i.table],
|
|
@@ -28264,7 +28615,7 @@ async function buildIssueBody(i) {
|
|
|
28264
28615
|
],
|
|
28265
28616
|
"Hook errors": ["hook-errors.log, last " + DOCTOR_HOOK_LOG_LINES + " lines (UTC):", "```", ...hookLogTail(i.env), "```"],
|
|
28266
28617
|
"Journal rows": ["events, newest first, last " + DOCTOR_JOURNAL_ROWS + " (bodies stay local):", ...await journalRows(i.ctx)],
|
|
28267
|
-
"Agent config": agentConfig(i.adapter, i.env,
|
|
28618
|
+
"Agent config": agentConfig(i.adapter, i.env, "project" in p ? p.project.worktree : process.cwd()),
|
|
28268
28619
|
"Expected": ["Expected: <the agent fills this in: what should happen, with the byte count>"],
|
|
28269
28620
|
"Steps": [
|
|
28270
28621
|
"Reproduced: <yes (2 of 2) or 1 of 2>",
|
|
@@ -28285,7 +28636,7 @@ async function buildIssueBody(i) {
|
|
|
28285
28636
|
`git: ${gitVersion(i.env)}`,
|
|
28286
28637
|
...pathTools,
|
|
28287
28638
|
...envNames,
|
|
28288
|
-
`Project: ${
|
|
28639
|
+
"project" in p ? `Project: ${p.project.worktree} (key ${p.project.projectKey})` : `Project: ${D7_NO_PROJECT_DETAIL(p.missing)}`,
|
|
28289
28640
|
"Filed by: <your agent name, version, model id>"
|
|
28290
28641
|
]
|
|
28291
28642
|
};
|
|
@@ -28296,10 +28647,10 @@ async function buildIssueBody(i) {
|
|
|
28296
28647
|
async function writeIssueReport(i) {
|
|
28297
28648
|
const tilde = tildeOf(i.env);
|
|
28298
28649
|
const body = await buildIssueBody(i);
|
|
28299
|
-
const dir =
|
|
28300
|
-
|
|
28301
|
-
const file2 =
|
|
28302
|
-
|
|
28650
|
+
const dir = join20(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
28651
|
+
mkdirSync8(dir, { recursive: true });
|
|
28652
|
+
const file2 = join20(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
28653
|
+
writeFileSync5(file2, body);
|
|
28303
28654
|
const shown2 = tilde(file2);
|
|
28304
28655
|
const title = issueTitle(i.adapter.id, i.rows, i.unsupported);
|
|
28305
28656
|
const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
|
|
@@ -28311,6 +28662,25 @@ function formUrl(title, summary) {
|
|
|
28311
28662
|
return full.length < ISSUE_URL_MAX ? full : base;
|
|
28312
28663
|
}
|
|
28313
28664
|
|
|
28665
|
+
// src/core/index/text.ts
|
|
28666
|
+
function storeText(db, project, sessionId, sourceKind, label2, text, kind, chunks = chunkText(text, kind)) {
|
|
28667
|
+
const sourceId = ftsInsert(db, {
|
|
28668
|
+
projectKey: project.projectKey,
|
|
28669
|
+
sessionId,
|
|
28670
|
+
worktree: project.worktree,
|
|
28671
|
+
agent: project.agent,
|
|
28672
|
+
kind: sourceKind,
|
|
28673
|
+
label: label2,
|
|
28674
|
+
bytes: Buffer.byteLength(text, "utf8"),
|
|
28675
|
+
chunkCount: chunks.length,
|
|
28676
|
+
createdAt: Date.now()
|
|
28677
|
+
}, chunks);
|
|
28678
|
+
return { sourceId, chunks: chunks.length };
|
|
28679
|
+
}
|
|
28680
|
+
function indexText(db, ctx, sessionId, source, text, kind, chunks) {
|
|
28681
|
+
return storeText(db, ctx, sessionId, "content", source, text, kind, chunks);
|
|
28682
|
+
}
|
|
28683
|
+
|
|
28314
28684
|
// src/core/tools/doctor.ts
|
|
28315
28685
|
var ctxDoctorSchema = external_exports.object({}).strict();
|
|
28316
28686
|
function lineOf2(err) {
|
|
@@ -28324,10 +28694,10 @@ async function guard(id2, run) {
|
|
|
28324
28694
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail: lineOf2(err) };
|
|
28325
28695
|
}
|
|
28326
28696
|
}
|
|
28327
|
-
async function codexDb(
|
|
28328
|
-
if (adapter.id !== "codex" || !existsSync17(
|
|
28697
|
+
async function codexDb(project, adapter) {
|
|
28698
|
+
if (adapter.id !== "codex" || !existsSync17(project.dbPath)) return null;
|
|
28329
28699
|
try {
|
|
28330
|
-
return await openDb(
|
|
28700
|
+
return await openDb(project, { readOnly: true });
|
|
28331
28701
|
} catch {
|
|
28332
28702
|
return null;
|
|
28333
28703
|
}
|
|
@@ -28338,12 +28708,12 @@ function d1UpdateCommand(agent, env, other) {
|
|
|
28338
28708
|
function unsupportedRow(id2, h) {
|
|
28339
28709
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "WARN", detail: UNSUPPORTED_HOST_LINE(h.name) };
|
|
28340
28710
|
}
|
|
28341
|
-
async function hookRow(ctx, adapter, host) {
|
|
28342
|
-
const db = await codexDb(
|
|
28711
|
+
async function hookRow(ctx, project, adapter, host) {
|
|
28712
|
+
const db = await codexDb(project, adapter);
|
|
28343
28713
|
const runStart = Date.now();
|
|
28344
28714
|
try {
|
|
28345
28715
|
const row5 = await checkHookRoundTrip({
|
|
28346
|
-
worktree:
|
|
28716
|
+
worktree: project.worktree,
|
|
28347
28717
|
agent: adapter.id,
|
|
28348
28718
|
bundleDir: host.bundleDir,
|
|
28349
28719
|
env: buildChildEnv(host.env),
|
|
@@ -28361,18 +28731,20 @@ async function hookRow(ctx, adapter, host) {
|
|
|
28361
28731
|
}
|
|
28362
28732
|
}
|
|
28363
28733
|
function ownServerId(configDir, projectKey) {
|
|
28364
|
-
const dir =
|
|
28734
|
+
const dir = join21(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
28365
28735
|
if (!existsSync17(dir)) return "";
|
|
28366
|
-
for (const name of
|
|
28736
|
+
for (const name of readdirSync9(dir)) {
|
|
28367
28737
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
28368
|
-
if (
|
|
28738
|
+
if (readFileSync18(join21(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
28369
28739
|
}
|
|
28370
28740
|
return "";
|
|
28371
28741
|
}
|
|
28372
28742
|
async function runDoctorChecks(ctx, adapter, host0) {
|
|
28373
28743
|
const host = adapter.id === "codex" ? { ...host0, env: { ...host0.env, CODEX_HOME: codexRunDirOf(host0.env, homeDirOf(host0.env) ?? "", host0.bundleDir) } } : host0;
|
|
28374
28744
|
const env = host.env;
|
|
28375
|
-
const
|
|
28745
|
+
const p = projectOrMissing(ctx);
|
|
28746
|
+
if ("missing" in p) return noProjectRows(ctx, adapter, host, p.missing);
|
|
28747
|
+
const project = p.project;
|
|
28376
28748
|
const other = adapter.installMode === "in-process" ? void 0 : unsupportedHostOf({ clientName: ctx.clientInfo?.name, bundleDir: host.bundleDir, env });
|
|
28377
28749
|
let integrityFailed = false;
|
|
28378
28750
|
let orphan = [];
|
|
@@ -28382,7 +28754,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
28382
28754
|
D3: () => other !== void 0 ? unsupportedRow("D3", other) : checkHostConfig(adapter, env, project.worktree),
|
|
28383
28755
|
// D-UNSUPPORTED-HOSTS-1
|
|
28384
28756
|
D4: () => checkV1Leftovers(adapter.id, requireHomeDir(env), { project: project.worktree, piAgentDir: piAgentDirOf(env, requireHomeDir(env)), claudeDir: claudeDirOf(env, requireHomeDir(env)), codexDir: codexDirOf(env, requireHomeDir(env)), geminiDir: geminiDirOf(env, requireHomeDir(env)), copilotDir: copilotDirOf(env, requireHomeDir(env)), kiroDir: kiroDirOf(env, requireHomeDir(env)), opencodeDir: opencodeDirOf(env, requireHomeDir(env)) }),
|
|
28385
|
-
D5: () => other !== void 0 ? unsupportedRow("D5", other) : hookRow(ctx, adapter, host),
|
|
28757
|
+
D5: () => other !== void 0 ? unsupportedRow("D5", other) : hookRow(ctx, project, adapter, host),
|
|
28386
28758
|
D5b: () => checkDoubleFire(adapter.id, project.worktree),
|
|
28387
28759
|
D6: () => checkMcp(ctx, adapter),
|
|
28388
28760
|
D7: () => checkProject({ project, adapter, piCwd: host.piCwd }),
|
|
@@ -28412,6 +28784,28 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
28412
28784
|
});
|
|
28413
28785
|
return rows;
|
|
28414
28786
|
}
|
|
28787
|
+
async function noProjectRows(ctx, adapter, host, missing2) {
|
|
28788
|
+
const env = host.env;
|
|
28789
|
+
const other = adapter.installMode === "in-process" ? void 0 : unsupportedHostOf({ clientName: ctx.clientInfo?.name, bundleDir: host.bundleDir, env });
|
|
28790
|
+
const wait = (id2) => () => needsProjectRow(id2);
|
|
28791
|
+
const checks = {
|
|
28792
|
+
D1: () => checkVersion({ bundleSha: BUNDLE_SHA, version: bundleVersion(host.bundleDir), registryUrl: D1_REGISTRY_URL, timeoutMs: DOCTOR_GIT_TIMEOUT_MS, env: buildChildEnv(env), cwd: process.cwd(), signal: ctx.signal, updateCommand: d1UpdateCommand(adapter.id, env, other) }),
|
|
28793
|
+
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
28794
|
+
D3: other !== void 0 ? () => unsupportedRow("D3", other) : wait("D3"),
|
|
28795
|
+
D4: () => checkV1Leftovers(adapter.id, requireHomeDir(env), { piAgentDir: piAgentDirOf(env, requireHomeDir(env)), claudeDir: claudeDirOf(env, requireHomeDir(env)), codexDir: codexDirOf(env, requireHomeDir(env)), geminiDir: geminiDirOf(env, requireHomeDir(env)), copilotDir: copilotDirOf(env, requireHomeDir(env)), kiroDir: kiroDirOf(env, requireHomeDir(env)), opencodeDir: opencodeDirOf(env, requireHomeDir(env)) }),
|
|
28796
|
+
D5: other !== void 0 ? () => unsupportedRow("D5", other) : wait("D5"),
|
|
28797
|
+
D5b: wait("D5b"),
|
|
28798
|
+
D6: () => checkMcp(ctx, adapter),
|
|
28799
|
+
D7: () => noProjectRow(missing2),
|
|
28800
|
+
D8: wait("D8"),
|
|
28801
|
+
D9: wait("D9"),
|
|
28802
|
+
D10: () => checkMode(adapter, ctx.hostPermission),
|
|
28803
|
+
D11: () => checkRuntimes(env, checkShell(env))
|
|
28804
|
+
};
|
|
28805
|
+
const rows = [];
|
|
28806
|
+
for (const id2 of DOCTOR_CHECK_ORDER) rows.push(await guard(id2, checks[id2]));
|
|
28807
|
+
return rows;
|
|
28808
|
+
}
|
|
28415
28809
|
function reportEnv(env) {
|
|
28416
28810
|
const out = {};
|
|
28417
28811
|
for (const key of Object.keys(REPORT_ENV_ENUMS)) {
|
|
@@ -28421,7 +28815,7 @@ function reportEnv(env) {
|
|
|
28421
28815
|
return out;
|
|
28422
28816
|
}
|
|
28423
28817
|
async function doctorReply(ctx, host) {
|
|
28424
|
-
const adapter = getAdapter(ctx.project.agent);
|
|
28818
|
+
const adapter = getAdapter(ctx.agent ?? ctx.project.agent);
|
|
28425
28819
|
const runtime = runtimeInfo(host.env, ctx.signal);
|
|
28426
28820
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
28427
28821
|
const failed = rows.some((r) => r.status === "FAIL");
|
|
@@ -28443,9 +28837,11 @@ async function doctorReply(ctx, host) {
|
|
|
28443
28837
|
const whole2 = [envLine2, table3, ...docs, ...info, ...notes].join("\n");
|
|
28444
28838
|
const bytes5 = Buffer.byteLength(whole2, "utf8");
|
|
28445
28839
|
if (bytes5 <= REPORT_CAP) return { text: whole2, isError: false, sandboxBytes: bytes5 };
|
|
28446
|
-
const
|
|
28840
|
+
const p = projectOrMissing(ctx);
|
|
28841
|
+
if ("missing" in p) return { text: whole2, isError: false, sandboxBytes: bytes5 };
|
|
28842
|
+
const db = await openDb(p.project);
|
|
28447
28843
|
try {
|
|
28448
|
-
indexText(db,
|
|
28844
|
+
indexText(db, p.project, ctx.sessionId, REPORT_SOURCE_LABEL, whole2, "text");
|
|
28449
28845
|
} finally {
|
|
28450
28846
|
closeDb(db);
|
|
28451
28847
|
}
|
|
@@ -28470,9 +28866,9 @@ var ctxDoctor = Object.freeze({
|
|
|
28470
28866
|
});
|
|
28471
28867
|
|
|
28472
28868
|
// src/core/tools/execute.ts
|
|
28473
|
-
import { existsSync as existsSync18, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as
|
|
28869
|
+
import { existsSync as existsSync18, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync6 } from "node:fs";
|
|
28474
28870
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
28475
|
-
import { dirname as dirname12, join as
|
|
28871
|
+
import { dirname as dirname12, join as join22, parse as parse3, resolve as resolve11 } from "node:path";
|
|
28476
28872
|
|
|
28477
28873
|
// src/core/sandbox/win-build.ts
|
|
28478
28874
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -28641,9 +29037,9 @@ async function handler3(raw, ctx) {
|
|
|
28641
29037
|
if (takesDashC(input.language, runtime)) {
|
|
28642
29038
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
28643
29039
|
} else {
|
|
28644
|
-
tmpDir = mkdtempSync2(
|
|
28645
|
-
const file2 =
|
|
28646
|
-
|
|
29040
|
+
tmpDir = mkdtempSync2(join22(tmpdir3(), TMP_PREFIX));
|
|
29041
|
+
const file2 = join22(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
29042
|
+
writeFileSync6(file2, scriptText(input.language, input.code), "utf8");
|
|
28647
29043
|
argv = scriptArgv(input.language, runtime, file2);
|
|
28648
29044
|
}
|
|
28649
29045
|
if (input.background === true) {
|
|
@@ -28678,12 +29074,12 @@ var ctxExecute = {
|
|
|
28678
29074
|
};
|
|
28679
29075
|
|
|
28680
29076
|
// src/core/tools/index.ts
|
|
28681
|
-
import { existsSync as existsSync19, readFileSync as
|
|
28682
|
-
import { dirname as dirname13, extname as extname3, join as
|
|
29077
|
+
import { existsSync as existsSync19, readFileSync as readFileSync21, statSync as statSync10 } from "node:fs";
|
|
29078
|
+
import { dirname as dirname13, extname as extname3, join as join25, relative as relative5, resolve as resolve12 } from "node:path";
|
|
28683
29079
|
|
|
28684
29080
|
// src/core/index/walk.ts
|
|
28685
|
-
import { readdirSync as
|
|
28686
|
-
import { join as
|
|
29081
|
+
import { readdirSync as readdirSync10, readFileSync as readFileSync19, realpathSync as realpathSync10, statSync as statSync9 } from "node:fs";
|
|
29082
|
+
import { join as join23 } from "node:path";
|
|
28687
29083
|
var GITIGNORE = ".gitignore";
|
|
28688
29084
|
var GIT_DIR = ".git";
|
|
28689
29085
|
function walkDir(root, containmentRoot) {
|
|
@@ -28692,19 +29088,19 @@ function walkDir(root, containmentRoot) {
|
|
|
28692
29088
|
const found = [];
|
|
28693
29089
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
28694
29090
|
found.sort(compareFound);
|
|
28695
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
29091
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join23(...f.dir, f.name) }));
|
|
28696
29092
|
}
|
|
28697
29093
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
28698
29094
|
let entries;
|
|
28699
29095
|
try {
|
|
28700
|
-
entries =
|
|
29096
|
+
entries = readdirSync10(abs, { withFileTypes: true });
|
|
28701
29097
|
} catch {
|
|
28702
29098
|
return;
|
|
28703
29099
|
}
|
|
28704
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
29100
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join23(abs, GITIGNORE), rel)) : parent;
|
|
28705
29101
|
for (const e of entries) {
|
|
28706
29102
|
if (e.name === GIT_DIR) continue;
|
|
28707
|
-
const path8 =
|
|
29103
|
+
const path8 = join23(abs, e.name);
|
|
28708
29104
|
let isDir = e.isDirectory();
|
|
28709
29105
|
let isFile = e.isFile();
|
|
28710
29106
|
let target = path8;
|
|
@@ -28716,7 +29112,7 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
28716
29112
|
continue;
|
|
28717
29113
|
}
|
|
28718
29114
|
if (!isInside(contain, resolved)) continue;
|
|
28719
|
-
const st =
|
|
29115
|
+
const st = statSync9(resolved);
|
|
28720
29116
|
isDir = st.isDirectory();
|
|
28721
29117
|
isFile = st.isFile();
|
|
28722
29118
|
target = resolved;
|
|
@@ -28744,7 +29140,7 @@ function compareFound(a, b) {
|
|
|
28744
29140
|
function readRules(file2, base) {
|
|
28745
29141
|
let body;
|
|
28746
29142
|
try {
|
|
28747
|
-
body =
|
|
29143
|
+
body = readFileSync19(file2, "utf8");
|
|
28748
29144
|
} catch {
|
|
28749
29145
|
return [];
|
|
28750
29146
|
}
|
|
@@ -28827,12 +29223,13 @@ function globSeg(pat, name) {
|
|
|
28827
29223
|
}
|
|
28828
29224
|
|
|
28829
29225
|
// src/core/sandbox/fetch.ts
|
|
28830
|
-
import {
|
|
29226
|
+
import { randomBytes } from "node:crypto";
|
|
29227
|
+
import { readFileSync as readFileSync20 } from "node:fs";
|
|
28831
29228
|
import { lookup } from "node:dns/promises";
|
|
28832
29229
|
import http from "node:http";
|
|
28833
29230
|
import https from "node:https";
|
|
28834
29231
|
import { BlockList, isIP } from "node:net";
|
|
28835
|
-
import { join as
|
|
29232
|
+
import { join as join24 } from "node:path";
|
|
28836
29233
|
import { connect as tlsConnect } from "node:tls";
|
|
28837
29234
|
var PRIVATE_RANGES = [
|
|
28838
29235
|
["127.0.0.0", 8, "ipv4"],
|
|
@@ -28861,6 +29258,26 @@ var PRIVATE_RANGES = [
|
|
|
28861
29258
|
];
|
|
28862
29259
|
var BLOCKED = new BlockList();
|
|
28863
29260
|
for (const [net, prefix, type] of PRIVATE_RANGES) BLOCKED.addSubnet(net, prefix, type);
|
|
29261
|
+
var FAKE_IP_POOL = new BlockList();
|
|
29262
|
+
FAKE_IP_POOL.addSubnet("198.18.0.0", 15, "ipv4");
|
|
29263
|
+
var FAKE_IP_PROBE_TLD = ".invalid";
|
|
29264
|
+
var FAKE_IP_PROBE_BYTES = 8;
|
|
29265
|
+
var FAKE_IP_PROBE_MS = 1500;
|
|
29266
|
+
var fakeIpProbe;
|
|
29267
|
+
function inFakeIpPool(address) {
|
|
29268
|
+
return isIP(address) === 4 && FAKE_IP_POOL.check(address, "ipv4");
|
|
29269
|
+
}
|
|
29270
|
+
function fakeIpResolver() {
|
|
29271
|
+
fakeIpProbe ??= new Promise((resolve14) => {
|
|
29272
|
+
const timer = setTimeout(() => resolve14(false), FAKE_IP_PROBE_MS);
|
|
29273
|
+
timer.unref();
|
|
29274
|
+
lookup(randomBytes(FAKE_IP_PROBE_BYTES).toString("hex") + FAKE_IP_PROBE_TLD, { all: true }).then(
|
|
29275
|
+
(addrs) => resolve14(addrs.length > 0 && addrs.every((a) => inFakeIpPool(a.address))),
|
|
29276
|
+
() => resolve14(false)
|
|
29277
|
+
).finally(() => clearTimeout(timer));
|
|
29278
|
+
});
|
|
29279
|
+
return fakeIpProbe;
|
|
29280
|
+
}
|
|
28864
29281
|
var STATUS_OK_FIRST = 200;
|
|
28865
29282
|
var STATUS_OK_END = 300;
|
|
28866
29283
|
var STATUS_REDIRECT = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
@@ -28871,7 +29288,7 @@ function baseHeaders() {
|
|
|
28871
29288
|
if (namedHeaders === void 0) {
|
|
28872
29289
|
let version2 = UA_DEV_VERSION;
|
|
28873
29290
|
try {
|
|
28874
|
-
const v = JSON.parse(
|
|
29291
|
+
const v = JSON.parse(readFileSync20(join24(ownBundleDir(), D1_PACKAGE_FILE), "utf8")).version;
|
|
28875
29292
|
if (typeof v === "string" && v !== "") version2 = v;
|
|
28876
29293
|
} catch {
|
|
28877
29294
|
}
|
|
@@ -28963,8 +29380,15 @@ function checkAddress(hostname2, address) {
|
|
|
28963
29380
|
throw new CtxError("SSRF", { host: hostname2 });
|
|
28964
29381
|
}
|
|
28965
29382
|
}
|
|
28966
|
-
async function
|
|
28967
|
-
const
|
|
29383
|
+
async function checkResolved(host, addrs, signal) {
|
|
29384
|
+
const pooled = isIP(host) === 0 ? addrs.filter((a) => inFakeIpPool(a.address)) : [];
|
|
29385
|
+
for (const a of addrs) if (!pooled.includes(a)) checkAddress(host, a.address);
|
|
29386
|
+
if (pooled.length === 0) return;
|
|
29387
|
+
const fakeIp = await fakeIpResolver();
|
|
29388
|
+
if (signal.aborted) throw fail6("ABORT_ERR");
|
|
29389
|
+
if (!fakeIp) checkAddress(host, pooled[0].address);
|
|
29390
|
+
}
|
|
29391
|
+
async function lookupAll(host, signal) {
|
|
28968
29392
|
let addrs;
|
|
28969
29393
|
try {
|
|
28970
29394
|
addrs = await lookup(host, { all: true });
|
|
@@ -28973,9 +29397,26 @@ async function resolveTarget(u, signal) {
|
|
|
28973
29397
|
}
|
|
28974
29398
|
if (signal.aborted) throw fail6("ABORT_ERR");
|
|
28975
29399
|
if (addrs.length === 0) throw fail6("ENOTFOUND");
|
|
28976
|
-
|
|
29400
|
+
return addrs;
|
|
29401
|
+
}
|
|
29402
|
+
async function resolveTarget(u, signal, checked) {
|
|
29403
|
+
const host = bare(u.hostname);
|
|
29404
|
+
const addrs = await lookupAll(host, signal);
|
|
29405
|
+
if (checked) await checkResolved(host, addrs, signal);
|
|
28977
29406
|
return { host, port: u.port === "" ? defaultPort(u.protocol) : Number(u.port), address: addrs[0].address };
|
|
28978
29407
|
}
|
|
29408
|
+
async function checkProxiedTarget(u, signal) {
|
|
29409
|
+
const host = bare(u.hostname);
|
|
29410
|
+
if (isIP(host) !== 0) return checkAddress(host, host);
|
|
29411
|
+
let addrs;
|
|
29412
|
+
try {
|
|
29413
|
+
addrs = await lookupAll(host, signal);
|
|
29414
|
+
} catch (err) {
|
|
29415
|
+
if (signal.aborted) throw err;
|
|
29416
|
+
return;
|
|
29417
|
+
}
|
|
29418
|
+
await checkResolved(host, addrs, signal);
|
|
29419
|
+
}
|
|
28979
29420
|
function tlsName(host) {
|
|
28980
29421
|
return isIP(host) === 0 ? host : void 0;
|
|
28981
29422
|
}
|
|
@@ -29033,9 +29474,8 @@ async function safeFetch(url2, signal) {
|
|
|
29033
29474
|
for (let hop = 0; ; hop += 1) {
|
|
29034
29475
|
if (signal.aborted) throw fail6("ABORT_ERR");
|
|
29035
29476
|
const proxy = pickProxy(current);
|
|
29036
|
-
|
|
29037
|
-
|
|
29038
|
-
const conn = await resolveTarget(proxy === void 0 ? current : proxy.url, signal);
|
|
29477
|
+
if (proxy !== void 0) await checkProxiedTarget(current, signal);
|
|
29478
|
+
const conn = await resolveTarget(proxy === void 0 ? current : proxy.url, signal, proxy === void 0);
|
|
29039
29479
|
const res = await request(current, conn, proxy, signal);
|
|
29040
29480
|
const status = res.statusCode ?? 0;
|
|
29041
29481
|
const location = res.headers.location;
|
|
@@ -29184,7 +29624,7 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
29184
29624
|
readNgramReferences(ngramCount - dictSize + dict1AtomCount, dictSize + dict2AtomCount);
|
|
29185
29625
|
readNgramReferences(dictSize - dict1AtomCount, dict1AtomCount);
|
|
29186
29626
|
const pool = new Uint16Array(poolSize);
|
|
29187
|
-
let
|
|
29627
|
+
let write = 0;
|
|
29188
29628
|
for (let index = 0; index < ngramIndex; index++) {
|
|
29189
29629
|
for (let half = 0; half < 2; half++) {
|
|
29190
29630
|
const source = references[index * 2 + half];
|
|
@@ -29193,9 +29633,9 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
29193
29633
|
let read3 = start[source];
|
|
29194
29634
|
const readEnd = read3 + length[source];
|
|
29195
29635
|
while (read3 < readEnd)
|
|
29196
|
-
pool[
|
|
29636
|
+
pool[write++] = pool[read3++];
|
|
29197
29637
|
} else {
|
|
29198
|
-
pool[
|
|
29638
|
+
pool[write++] = value;
|
|
29199
29639
|
}
|
|
29200
29640
|
}
|
|
29201
29641
|
}
|
|
@@ -29419,8 +29859,8 @@ var EntityDecoder = class {
|
|
|
29419
29859
|
while (offset < inputLength) {
|
|
29420
29860
|
const char = input.charCodeAt(offset);
|
|
29421
29861
|
if (isNumber2(char) || isHexadecimalCharacter(char)) {
|
|
29422
|
-
const
|
|
29423
|
-
result = result * 16 +
|
|
29862
|
+
const digit2 = char <= CharCodes.NINE ? char - CharCodes.ZERO : (char | TO_LOWER_BIT) - CharCodes.LOWER_A + 10;
|
|
29863
|
+
result = result * 16 + digit2;
|
|
29424
29864
|
consumed += 1;
|
|
29425
29865
|
offset += 1;
|
|
29426
29866
|
} else {
|
|
@@ -29448,13 +29888,13 @@ var EntityDecoder = class {
|
|
|
29448
29888
|
let { result } = this;
|
|
29449
29889
|
let { consumed } = this;
|
|
29450
29890
|
while (offset < inputLength) {
|
|
29451
|
-
const
|
|
29452
|
-
if (
|
|
29891
|
+
const digit2 = input.charCodeAt(offset) - CharCodes.ZERO;
|
|
29892
|
+
if (digit2 >>> 0 > 9) {
|
|
29453
29893
|
this.result = result;
|
|
29454
29894
|
this.consumed = consumed;
|
|
29455
|
-
return this.emitNumericEntity(
|
|
29895
|
+
return this.emitNumericEntity(digit2 + CharCodes.ZERO, 2);
|
|
29456
29896
|
}
|
|
29457
|
-
result = result * 10 +
|
|
29897
|
+
result = result * 10 + digit2;
|
|
29458
29898
|
consumed += 1;
|
|
29459
29899
|
offset += 1;
|
|
29460
29900
|
}
|
|
@@ -32889,7 +33329,7 @@ function kindOfType(contentType) {
|
|
|
32889
33329
|
}
|
|
32890
33330
|
function readUtf8(absPath) {
|
|
32891
33331
|
try {
|
|
32892
|
-
return utf8.decode(
|
|
33332
|
+
return utf8.decode(readFileSync21(absPath));
|
|
32893
33333
|
} catch {
|
|
32894
33334
|
return void 0;
|
|
32895
33335
|
}
|
|
@@ -32904,10 +33344,10 @@ function pathItems(input, project) {
|
|
|
32904
33344
|
const abs = resolve12(project.worktree, input.path);
|
|
32905
33345
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
32906
33346
|
const base = relative5(project.worktree, abs);
|
|
32907
|
-
if (
|
|
33347
|
+
if (statSync10(abs).isDirectory()) {
|
|
32908
33348
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
32909
33349
|
sourceKind: "path",
|
|
32910
|
-
label: pathLabel(
|
|
33350
|
+
label: pathLabel(join25(base, f.relPath)),
|
|
32911
33351
|
kind: kindOfPath(f.relPath),
|
|
32912
33352
|
read: () => readUtf8(f.absPath)
|
|
32913
33353
|
}));
|
|
@@ -33031,7 +33471,7 @@ function purgeScope(db, scope, input) {
|
|
|
33031
33471
|
const chunks = deleteChunkRows(raw, "all");
|
|
33032
33472
|
return changes(raw, "DELETE FROM events") + chunks + changes(raw, "DELETE FROM sources");
|
|
33033
33473
|
}
|
|
33034
|
-
function
|
|
33474
|
+
function isBusy2(err) {
|
|
33035
33475
|
const code = err?.errcode;
|
|
33036
33476
|
return typeof code === "number" && (code & SQLITE_PRIMARY_CODE_MASK) === SQLITE_BUSY_CODE;
|
|
33037
33477
|
}
|
|
@@ -33049,7 +33489,7 @@ async function handler5(input, ctx) {
|
|
|
33049
33489
|
closeDb(db);
|
|
33050
33490
|
}
|
|
33051
33491
|
} catch (err) {
|
|
33052
|
-
if (
|
|
33492
|
+
if (isBusy2(err)) return reply2(PURGE_BUSY_LINE, true);
|
|
33053
33493
|
throw err;
|
|
33054
33494
|
}
|
|
33055
33495
|
}
|
|
@@ -33447,22 +33887,22 @@ var ctxStats = Object.freeze({
|
|
|
33447
33887
|
});
|
|
33448
33888
|
|
|
33449
33889
|
// src/core/ops/host-write.ts
|
|
33450
|
-
import { copyFileSync, existsSync as existsSync20, mkdirSync as
|
|
33451
|
-
import { dirname as dirname14, join as
|
|
33890
|
+
import { copyFileSync, existsSync as existsSync20, mkdirSync as mkdirSync9, writeFileSync as writeFileSync7 } from "node:fs";
|
|
33891
|
+
import { dirname as dirname14, join as join26 } from "node:path";
|
|
33452
33892
|
function defaultWrite(file2, text) {
|
|
33453
|
-
|
|
33893
|
+
writeFileSync7(file2, text, "utf8");
|
|
33454
33894
|
}
|
|
33455
33895
|
function hostConfigPath(agent, home, env) {
|
|
33456
33896
|
const own2 = OWN_MCP_ENTRY[agent];
|
|
33457
33897
|
if (own2 !== void 0) return ownMcpFileOf(agent, own2.file, env, home);
|
|
33458
33898
|
switch (agent) {
|
|
33459
33899
|
case "opencode":
|
|
33460
|
-
return
|
|
33900
|
+
return join26(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
33461
33901
|
// D-WIN-OPENCODE-DIR-1
|
|
33462
33902
|
case "pi":
|
|
33463
|
-
return
|
|
33903
|
+
return join26(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
33464
33904
|
case "gemini":
|
|
33465
|
-
return
|
|
33905
|
+
return join26(geminiDirOf(env, home), SETTINGS_FILE);
|
|
33466
33906
|
// D-R38-GEMINI-HOME-1
|
|
33467
33907
|
case "copilot-cli":
|
|
33468
33908
|
return null;
|
|
@@ -33470,7 +33910,7 @@ function hostConfigPath(agent, home, env) {
|
|
|
33470
33910
|
return null;
|
|
33471
33911
|
// ADR-0026 decision 8 (D-OMP-UPGRADE-1): OMP loads the plugin from its own store; no MCP entry, nothing under ~/.pi
|
|
33472
33912
|
default:
|
|
33473
|
-
return
|
|
33913
|
+
return join26(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
33474
33914
|
}
|
|
33475
33915
|
}
|
|
33476
33916
|
function cell3(value) {
|
|
@@ -33479,14 +33919,14 @@ function cell3(value) {
|
|
|
33479
33919
|
function toRow(file2, edit) {
|
|
33480
33920
|
return { area: file2 + UPGRADE_AREA_KEY_SEP + edit.path, before: cell3(edit.before), after: cell3(edit.after) };
|
|
33481
33921
|
}
|
|
33482
|
-
function writeWithRollback(file2, text,
|
|
33922
|
+
function writeWithRollback(file2, text, write, atomic) {
|
|
33483
33923
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
33484
33924
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
33485
33925
|
const had = existsSync20(file2);
|
|
33486
|
-
|
|
33926
|
+
mkdirSync9(dirname14(file2), { recursive: true });
|
|
33487
33927
|
if (had) copyFileSync(file2, trash);
|
|
33488
33928
|
try {
|
|
33489
|
-
|
|
33929
|
+
write(tmp, text);
|
|
33490
33930
|
renameWithRetry(tmp, file2, atomic);
|
|
33491
33931
|
} catch (err) {
|
|
33492
33932
|
removeTmpFile(tmp, atomic);
|
|
@@ -33520,15 +33960,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
33520
33960
|
}
|
|
33521
33961
|
|
|
33522
33962
|
// src/core/ops/uninstall.ts
|
|
33523
|
-
import { existsSync as existsSync21, readdirSync as
|
|
33524
|
-
import { join as
|
|
33963
|
+
import { existsSync as existsSync21, readdirSync as readdirSync11, rmSync as rmSync6, writeFileSync as writeFileSync8 } from "node:fs";
|
|
33964
|
+
import { join as join27 } from "node:path";
|
|
33525
33965
|
function row2(area, before, after) {
|
|
33526
33966
|
return { area, before, after };
|
|
33527
33967
|
}
|
|
33528
33968
|
function stopServers(configDir, projectKey) {
|
|
33529
33969
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
33530
|
-
const dir =
|
|
33531
|
-
for (const serverId of stopped)
|
|
33970
|
+
const dir = join27(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
33971
|
+
for (const serverId of stopped) writeFileSync8(join27(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
33532
33972
|
return stopped.length === 0 ? { row: row2(UPGRADE_SERVER_AREA, "", UPGRADE_NOT_FOUND), stopped } : { row: row2(UPGRADE_SERVER_AREA, UPGRADE_SERVER_RUNNING, UPGRADE_SERVER_STOPPED), stopped };
|
|
33533
33973
|
}
|
|
33534
33974
|
function rootOrNull(adapter, env) {
|
|
@@ -33546,14 +33986,14 @@ function removeCache(adapter, env, configDir) {
|
|
|
33546
33986
|
const root = rootOrNull(adapter, env);
|
|
33547
33987
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
33548
33988
|
if (adapter.installMode === "marketplace") {
|
|
33549
|
-
const cache =
|
|
33989
|
+
const cache = join27(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
33550
33990
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
33551
33991
|
}
|
|
33552
33992
|
rmSync6(root, { recursive: true, force: true });
|
|
33553
33993
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
33554
33994
|
}
|
|
33555
33995
|
case "plugin": {
|
|
33556
|
-
const agentDir =
|
|
33996
|
+
const agentDir = join27(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
33557
33997
|
if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
33558
33998
|
rmSync6(agentDir, { recursive: true, force: true });
|
|
33559
33999
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
@@ -33599,7 +34039,7 @@ function ownEntries2(agent, env) {
|
|
|
33599
34039
|
}
|
|
33600
34040
|
if (agent === "opencode") {
|
|
33601
34041
|
return [{
|
|
33602
|
-
file:
|
|
34042
|
+
file: join27(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
33603
34043
|
// D-WIN-OPENCODE-DIR-1
|
|
33604
34044
|
key: OPENCODE_PLUGIN_KEY,
|
|
33605
34045
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -33610,7 +34050,7 @@ function ownEntries2(agent, env) {
|
|
|
33610
34050
|
if (agent === "pi") {
|
|
33611
34051
|
const agentDir = piAgentDirOf(env, home);
|
|
33612
34052
|
return [{
|
|
33613
|
-
file:
|
|
34053
|
+
file: join27(agentDir, SETTINGS_FILE),
|
|
33614
34054
|
key: PI_PACKAGES_KEY,
|
|
33615
34055
|
shown: PI_PACKAGES_KEY,
|
|
33616
34056
|
has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
|
|
@@ -33641,12 +34081,12 @@ function removeOwnEntries(agent, env) {
|
|
|
33641
34081
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
33642
34082
|
}
|
|
33643
34083
|
function removeProjectData(configDir, projectKey) {
|
|
33644
|
-
const projects =
|
|
33645
|
-
const dir =
|
|
34084
|
+
const projects = join27(configDir, PROJECTS_DIR_NAME);
|
|
34085
|
+
const dir = join27(projects, projectKey);
|
|
33646
34086
|
if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
33647
34087
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
33648
|
-
for (const name of
|
|
33649
|
-
if (name !== OWNERS_DIR_NAME) rmSync6(
|
|
34088
|
+
for (const name of readdirSync11(dir)) {
|
|
34089
|
+
if (name !== OWNERS_DIR_NAME) rmSync6(join27(dir, name), { recursive: true, force: true });
|
|
33650
34090
|
}
|
|
33651
34091
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
33652
34092
|
}
|
|
@@ -33654,12 +34094,12 @@ function runUninstall(input) {
|
|
|
33654
34094
|
const configDir = resolveConfigDir(input.env);
|
|
33655
34095
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
33656
34096
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
33657
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
34097
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join27(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
33658
34098
|
return { rows, stopped: stop.stopped };
|
|
33659
34099
|
}
|
|
33660
34100
|
|
|
33661
34101
|
// src/core/ops/v1-remove.ts
|
|
33662
|
-
import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as
|
|
34102
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync22, rmSync as rmSync7 } from "node:fs";
|
|
33663
34103
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
33664
34104
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
33665
34105
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -33710,8 +34150,8 @@ function locate(doc, path8) {
|
|
|
33710
34150
|
return null;
|
|
33711
34151
|
}
|
|
33712
34152
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
33713
|
-
const layout = hostLayout(
|
|
33714
|
-
const text = hostText(
|
|
34153
|
+
const layout = hostLayout(readFileSync22(file2, "utf8"));
|
|
34154
|
+
const text = hostText(readFileSync22(file2, "utf8"));
|
|
33715
34155
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
33716
34156
|
const hit = /* @__PURE__ */ new Set();
|
|
33717
34157
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -33761,7 +34201,7 @@ function removeV1(agent, findings, project) {
|
|
|
33761
34201
|
continue;
|
|
33762
34202
|
}
|
|
33763
34203
|
if (file2.endsWith(TOML_EXT)) {
|
|
33764
|
-
const rawToml =
|
|
34204
|
+
const rawToml = readFileSync22(file2, "utf8");
|
|
33765
34205
|
const tomlLayout = hostLayout(rawToml);
|
|
33766
34206
|
let text = hostText(rawToml);
|
|
33767
34207
|
for (const f of list4) {
|
|
@@ -34034,8 +34474,8 @@ async function setupLegacy(app) {
|
|
|
34034
34474
|
"chat.message": async (input, output) => {
|
|
34035
34475
|
const sessionId = input.sessionID ?? "";
|
|
34036
34476
|
turns.set(sessionId, turnOf(sessionId) + 1);
|
|
34037
|
-
const
|
|
34038
|
-
await call({ type: "prompt", sessionID: sessionId, message:
|
|
34477
|
+
const message4 = (output.parts ?? []).filter((p) => p.type === "text").map((p) => p.text ?? "").join("");
|
|
34478
|
+
await call({ type: "prompt", sessionID: sessionId, message: message4, turn: turnOf(sessionId) });
|
|
34039
34479
|
},
|
|
34040
34480
|
// §4.4. Deny (exit 2) throws with the reason; the reason carries any rewritten command (Q3, D-M5-P2-3).
|
|
34041
34481
|
"tool.execute.before": async (input, output) => {
|