context-mode 2.0.0-next.11 → 2.0.0-next.12
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/SHA256SUMS +14 -14
- package/cli.mjs +34 -3
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +88 -84
- package/opencode/plugin.js +335 -143
- package/package.json +1 -1
- package/pi/index.js +386 -181
- package/qwen-extension.json +1 -1
- package/run.mjs +41 -12
- package/search.mjs +41 -12
- package/server.mjs +162 -86
package/opencode/plugin.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import{createRequire as __cmRequire}from"node:module";if(typeof process.getBuiltinModule!=="function")process.getBuiltinModule=(id)=>__cmRequire(import.meta.url)(id);
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __export = (target, all) => {
|
|
3
4
|
for (var name in all)
|
|
@@ -248,6 +249,33 @@ var DENY_WEBFETCH_TOOLS = Object.freeze(["ctx_index", "ctx_search"]);
|
|
|
248
249
|
var USER_DENY_REASON_PREFIX = "Blocked by security policy: matches deny pattern ";
|
|
249
250
|
var POLICY_UNREADABLE_LINE = "context-mode: your deny rules could not be read. Fix: run ctx_doctor.";
|
|
250
251
|
var PARSE_ERROR_DENY_LINE = "context-mode: could not parse this command; it may be blocked by your own rules. Run it through ctx_execute instead.";
|
|
252
|
+
var HOOK_ERROR_LOG_FILE = "hook-errors.log";
|
|
253
|
+
var HOOK_LOG_TAIL_BYTES = 65536;
|
|
254
|
+
var HOOK_FAIL_TOOL_KEYS = Object.freeze(["tool_name", "toolName", "tool"]);
|
|
255
|
+
var HOOK_FAIL_EVENT_KEYS = Object.freeze(["hook_event_name", "hookEventName", "type"]);
|
|
256
|
+
var HOOK_FAIL_INPUT_KEYS = Object.freeze(["tool_input", "toolArgs", "input", "args"]);
|
|
257
|
+
var HOOK_FAIL_CWD_KEYS = Object.freeze(["cwd", "directory"]);
|
|
258
|
+
var HOOK_FAIL_PRE_EVENTS = Object.freeze(["pretooluse", "beforetool", "tool_call", "execute.before", "tool.execute.before"]);
|
|
259
|
+
var HOOK_FAULT_ENV = "CM_HOOK_FAULT";
|
|
260
|
+
var HOOK_FAULT_STAGES = Object.freeze(["decode", "project", "policy", "store", "encode"]);
|
|
261
|
+
var HOOK_FAIL_TOOLS = Object.freeze({
|
|
262
|
+
shell: Object.freeze(["Bash", "bash", "shell"]),
|
|
263
|
+
read: Object.freeze(["Read", "read_file"]),
|
|
264
|
+
grep: Object.freeze(["Grep", "grep_search"]),
|
|
265
|
+
fetch: Object.freeze(["WebFetch", "web_fetch", "fetch"])
|
|
266
|
+
});
|
|
267
|
+
function HOOK_FAIL_LINE(label, prefix) {
|
|
268
|
+
return `${DENY_PREFIX}the hook failed (${label}). Fix: run ${prefix}ctx_doctor.`;
|
|
269
|
+
}
|
|
270
|
+
var HOOK_FAIL_REDIRECT = Object.freeze({
|
|
271
|
+
read: "Read the file in parts with offset and limit, or process it with ctx_execute(language, code); only what you print comes back.",
|
|
272
|
+
shell: "Run the command with ctx_execute(language, code) or ctx_batch instead; only the part that matches your intent comes back.",
|
|
273
|
+
grep: "Search with ctx_execute(language, code), or index the files with ctx_index and query them with ctx_search.",
|
|
274
|
+
fetch: "Index the URL with ctx_index and query it with ctx_search."
|
|
275
|
+
});
|
|
276
|
+
function D5_LAST_HOOK_ERROR(ts, stage, label) {
|
|
277
|
+
return `; last hook error ${ts} at ${stage} (${label}), stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
278
|
+
}
|
|
251
279
|
var BOUNDED_COMMANDS = Object.freeze(["pwd", "whoami", "uname", "id", "realpath", "ln"]);
|
|
252
280
|
var BOUNDED_GIT_SUBCOMMANDS = Object.freeze(["status"]);
|
|
253
281
|
var VERSION_PROBE_FLAGS = Object.freeze(["--version", "-v"]);
|
|
@@ -330,7 +358,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
330
358
|
var DECISION_LABEL_JOIN = " | ";
|
|
331
359
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
332
360
|
var RELEASE_BRANCH = "release";
|
|
333
|
-
var BUNDLE_SHA = true ? "
|
|
361
|
+
var BUNDLE_SHA = true ? "c8f6a68d0aea0fbe994c9e6a4c2d674a7f3260ac" : void 0;
|
|
334
362
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
335
363
|
var DOCTOR_LABEL = Object.freeze({
|
|
336
364
|
D1: "version",
|
|
@@ -755,7 +783,7 @@ var CtxError = class extends Error {
|
|
|
755
783
|
};
|
|
756
784
|
|
|
757
785
|
// src/core/hooks/dispatch.ts
|
|
758
|
-
import { dirname as dirname3, join as
|
|
786
|
+
import { dirname as dirname3, join as join6 } from "node:path";
|
|
759
787
|
|
|
760
788
|
// src/core/contracts/agents.ts
|
|
761
789
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
@@ -2547,6 +2575,7 @@ function pipeline(p) {
|
|
|
2547
2575
|
all.push(...last2.cmds);
|
|
2548
2576
|
const t = at(p);
|
|
2549
2577
|
if (t !== void 0 && t.kind === "op" && PIPES.includes(t.text)) {
|
|
2578
|
+
for (const c of last2.cmds) c.pipesOut = true;
|
|
2550
2579
|
p.i++;
|
|
2551
2580
|
continue;
|
|
2552
2581
|
}
|
|
@@ -2865,7 +2894,7 @@ var WRAPPERS = Object.freeze({
|
|
|
2865
2894
|
command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV" },
|
|
2866
2895
|
xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE }
|
|
2867
2896
|
});
|
|
2868
|
-
var SHELLS = ["bash", "sh"];
|
|
2897
|
+
var SHELLS = ["bash", "sh", "zsh"];
|
|
2869
2898
|
var SCRIPT_FLAG = "c";
|
|
2870
2899
|
var SHELL_LABEL_SUFFIX = " -c";
|
|
2871
2900
|
var SHELL_VALUE_OPTS = ["-o", "+o", "-O", "+O"];
|
|
@@ -3065,23 +3094,23 @@ function globMatch(glob, text, path5) {
|
|
|
3065
3094
|
const cur = new Uint8Array(n + 1);
|
|
3066
3095
|
let acc = 0;
|
|
3067
3096
|
for (let j = n; j >= 0; j--) {
|
|
3068
|
-
const
|
|
3069
|
-
const ch =
|
|
3097
|
+
const has3 = j < n;
|
|
3098
|
+
const ch = has3 ? text[j] : "";
|
|
3070
3099
|
switch (tok.t) {
|
|
3071
3100
|
case "lit":
|
|
3072
|
-
cur[j] =
|
|
3101
|
+
cur[j] = has3 && ch === tok.c ? next[j + 1] : 0;
|
|
3073
3102
|
break;
|
|
3074
3103
|
case "any1":
|
|
3075
|
-
cur[j] =
|
|
3104
|
+
cur[j] = has3 && !(path5 && ch === "/") ? next[j + 1] : 0;
|
|
3076
3105
|
break;
|
|
3077
3106
|
case "star":
|
|
3078
|
-
cur[j] = next[j] || (
|
|
3107
|
+
cur[j] = next[j] || (has3 && !(path5 && ch === "/") ? cur[j + 1] : 0);
|
|
3079
3108
|
break;
|
|
3080
3109
|
case "globstar":
|
|
3081
|
-
cur[j] = next[j] || (
|
|
3110
|
+
cur[j] = next[j] || (has3 ? cur[j + 1] : 0);
|
|
3082
3111
|
break;
|
|
3083
3112
|
case "globstarDir":
|
|
3084
|
-
if (
|
|
3113
|
+
if (has3 && ch === "/" && next[j + 1]) acc = 1;
|
|
3085
3114
|
cur[j] = next[j] || acc;
|
|
3086
3115
|
break;
|
|
3087
3116
|
}
|
|
@@ -3312,6 +3341,7 @@ function inlineHttp(raw) {
|
|
|
3312
3341
|
}
|
|
3313
3342
|
return false;
|
|
3314
3343
|
}
|
|
3344
|
+
var CD_COMMAND = "cd";
|
|
3315
3345
|
function fileSize(abs) {
|
|
3316
3346
|
try {
|
|
3317
3347
|
const st = statSync(abs);
|
|
@@ -3333,17 +3363,24 @@ function read(ev, row5, input) {
|
|
|
3333
3363
|
}
|
|
3334
3364
|
function shellDump(cmds, cwd, row5) {
|
|
3335
3365
|
if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3366
|
+
let dir = cwd;
|
|
3367
|
+
let verdict = null;
|
|
3368
|
+
for (const c of cmds) {
|
|
3369
|
+
const name = c.argv0.toLowerCase();
|
|
3370
|
+
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve(dir, c.args[0]);
|
|
3371
|
+
if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
|
|
3372
|
+
if (!has(SHELL_DUMP_COMMANDS, name)) continue;
|
|
3373
|
+
const d = dumpTarget(name, c.args);
|
|
3374
|
+
if (d === null) continue;
|
|
3375
|
+
if (d.bounded) {
|
|
3376
|
+
verdict = ALLOW;
|
|
3377
|
+
continue;
|
|
3378
|
+
}
|
|
3379
|
+
const abs = resolve(dir, d.file);
|
|
3380
|
+
const size = fileSize(abs);
|
|
3381
|
+
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
3382
|
+
}
|
|
3383
|
+
return verdict;
|
|
3347
3384
|
}
|
|
3348
3385
|
var allDigits2 = (s) => s !== "" && [...s].every((ch) => ch >= "0" && ch <= "9");
|
|
3349
3386
|
function countFlag(a) {
|
|
@@ -6263,10 +6300,10 @@ function queryStems(q) {
|
|
|
6263
6300
|
var TYPO_MIN_LEN = 5;
|
|
6264
6301
|
var TYPO_MAX_DIST = 2;
|
|
6265
6302
|
function typoTerms(db, words) {
|
|
6266
|
-
const
|
|
6303
|
+
const has3 = stmt(db.raw, "SELECT 1 AS x FROM chunks_vocab WHERE term = ?");
|
|
6267
6304
|
const near = stmt(db.raw, "SELECT term, doc, length(term) AS n FROM chunks_vocab WHERE length(term) BETWEEN ? AND ?");
|
|
6268
6305
|
const stems = queryStems(words.join(" "));
|
|
6269
|
-
const miss = stems.map((stem) =>
|
|
6306
|
+
const miss = stems.map((stem) => has3.get(stem) === void 0 && [...stem].length >= TYPO_MIN_LEN);
|
|
6270
6307
|
if (!miss.includes(true)) return null;
|
|
6271
6308
|
const lens = stems.filter((_, i) => miss[i]).map((stem) => stem.length);
|
|
6272
6309
|
const rows = near.all(Math.min(...lens) - TYPO_MAX_DIST, Math.max(...lens) + TYPO_MAX_DIST);
|
|
@@ -7109,7 +7146,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
7109
7146
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
7110
7147
|
return { end: start + r.read, written: r.written };
|
|
7111
7148
|
}
|
|
7112
|
-
function merge(src, blocks,
|
|
7149
|
+
function merge(src, blocks, join23, cap, lineCut) {
|
|
7113
7150
|
const out = [];
|
|
7114
7151
|
const scratch = new Uint8Array(cap);
|
|
7115
7152
|
let wide;
|
|
@@ -7119,7 +7156,7 @@ function merge(src, blocks, join22, cap, lineCut) {
|
|
|
7119
7156
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes4 });
|
|
7120
7157
|
};
|
|
7121
7158
|
for (const b of blocks) {
|
|
7122
|
-
if (cur !== void 0 && !
|
|
7159
|
+
if (cur !== void 0 && !join23) {
|
|
7123
7160
|
emit(cur.start, cur.end, curBytes);
|
|
7124
7161
|
cur = void 0;
|
|
7125
7162
|
}
|
|
@@ -7560,6 +7597,148 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
7560
7597
|
return db.raw.isTransaction ? decide2(db) : withWrite(db, decide2);
|
|
7561
7598
|
}
|
|
7562
7599
|
|
|
7600
|
+
// src/core/hooks/fallback.ts
|
|
7601
|
+
import { join as join5, resolve as resolve3 } from "node:path";
|
|
7602
|
+
var fs = process.getBuiltinModule("node:fs");
|
|
7603
|
+
function isRec(v) {
|
|
7604
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7605
|
+
}
|
|
7606
|
+
function firstString(o, keys) {
|
|
7607
|
+
for (const k of keys) if (typeof o[k] === "string") return o[k];
|
|
7608
|
+
return "";
|
|
7609
|
+
}
|
|
7610
|
+
function inputOf(o) {
|
|
7611
|
+
for (const k of HOOK_FAIL_INPUT_KEYS) {
|
|
7612
|
+
let v = o[k];
|
|
7613
|
+
if (typeof v === "string") {
|
|
7614
|
+
try {
|
|
7615
|
+
v = JSON.parse(v);
|
|
7616
|
+
} catch {
|
|
7617
|
+
v = void 0;
|
|
7618
|
+
}
|
|
7619
|
+
}
|
|
7620
|
+
if (isRec(v)) return v;
|
|
7621
|
+
}
|
|
7622
|
+
return {};
|
|
7623
|
+
}
|
|
7624
|
+
function homeOf(env) {
|
|
7625
|
+
return env.HOME ?? env.USERPROFILE ?? "";
|
|
7626
|
+
}
|
|
7627
|
+
function hookLogPath(env) {
|
|
7628
|
+
const home = homeOf(env);
|
|
7629
|
+
return home === "" ? "" : join5(home, DATA_ROOT.slice(1), HOOK_ERROR_LOG_FILE);
|
|
7630
|
+
}
|
|
7631
|
+
function errorLabel(err) {
|
|
7632
|
+
const code = isRec(err) ? err.code : void 0;
|
|
7633
|
+
if (typeof code === "string" && code !== "") return code;
|
|
7634
|
+
return err instanceof Error ? err.name : "Error";
|
|
7635
|
+
}
|
|
7636
|
+
function logHookError(env, agent, stage, err) {
|
|
7637
|
+
try {
|
|
7638
|
+
const file2 = hookLogPath(env);
|
|
7639
|
+
if (file2 === "") return;
|
|
7640
|
+
fs.mkdirSync(join5(file2, ".."), { recursive: true });
|
|
7641
|
+
const line = JSON.stringify({
|
|
7642
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7643
|
+
agent,
|
|
7644
|
+
stage,
|
|
7645
|
+
label: errorLabel(err),
|
|
7646
|
+
message: err instanceof Error ? err.message : String(err),
|
|
7647
|
+
stack: err instanceof Error ? err.stack ?? "" : ""
|
|
7648
|
+
});
|
|
7649
|
+
fs.appendFileSync(file2, line + "\n");
|
|
7650
|
+
} catch {
|
|
7651
|
+
process.stderr.write("hooks: " + stage + " failed: " + (err instanceof Error ? err.message : String(err)) + "\n");
|
|
7652
|
+
}
|
|
7653
|
+
}
|
|
7654
|
+
function lastHookError(env) {
|
|
7655
|
+
try {
|
|
7656
|
+
const file2 = hookLogPath(env);
|
|
7657
|
+
if (file2 === "" || !fs.existsSync(file2)) return null;
|
|
7658
|
+
const fd = fs.openSync(file2, "r");
|
|
7659
|
+
try {
|
|
7660
|
+
const size = fs.fstatSync(fd).size;
|
|
7661
|
+
const start = Math.max(0, size - HOOK_LOG_TAIL_BYTES);
|
|
7662
|
+
const buf = Buffer.alloc(size - start);
|
|
7663
|
+
fs.readSync(fd, buf, 0, buf.length, start);
|
|
7664
|
+
const lines = buf.toString("utf8").split("\n");
|
|
7665
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
7666
|
+
try {
|
|
7667
|
+
const j = JSON.parse(lines[i] ?? "");
|
|
7668
|
+
if (typeof j.ts === "string" && typeof j.stage === "string" && typeof j.label === "string") return { ts: j.ts, stage: j.stage, label: j.label };
|
|
7669
|
+
} catch {
|
|
7670
|
+
}
|
|
7671
|
+
}
|
|
7672
|
+
return null;
|
|
7673
|
+
} finally {
|
|
7674
|
+
fs.closeSync(fd);
|
|
7675
|
+
}
|
|
7676
|
+
} catch {
|
|
7677
|
+
return null;
|
|
7678
|
+
}
|
|
7679
|
+
}
|
|
7680
|
+
var fired = false;
|
|
7681
|
+
function fault(env, stage) {
|
|
7682
|
+
if (fired || env[HOOK_FAULT_ENV] !== stage) return;
|
|
7683
|
+
fired = true;
|
|
7684
|
+
throw new Error("injected fault at " + stage);
|
|
7685
|
+
}
|
|
7686
|
+
function nodeTooOld(version2) {
|
|
7687
|
+
const a = (version2.startsWith("v") ? version2.slice(1) : version2).split(".");
|
|
7688
|
+
const b = NODE_MIN.split(".");
|
|
7689
|
+
for (let i = 0; i < b.length; i++) {
|
|
7690
|
+
const x = Number(a[i] ?? 0) || 0;
|
|
7691
|
+
const y = Number(b[i]);
|
|
7692
|
+
if (x !== y) return x < y;
|
|
7693
|
+
}
|
|
7694
|
+
return false;
|
|
7695
|
+
}
|
|
7696
|
+
function has2(list3, name) {
|
|
7697
|
+
return list3 !== void 0 && list3.some((n) => n.toLowerCase() === name);
|
|
7698
|
+
}
|
|
7699
|
+
function kindOf(row5, name) {
|
|
7700
|
+
const n = name.toLowerCase();
|
|
7701
|
+
if (has2(row5.nativeTools.shell, n) || has2(HOOK_FAIL_TOOLS.shell, n)) return "shell";
|
|
7702
|
+
if (has2(row5.nativeTools.read, n) || has2(HOOK_FAIL_TOOLS.read, n)) return "read";
|
|
7703
|
+
if (has2(row5.nativeTools.grep, n) || has2(HOOK_FAIL_TOOLS.grep, n)) return "grep";
|
|
7704
|
+
if (has2(row5.nativeTools.webfetch, n) || has2(HOOK_FAIL_TOOLS.fetch, n)) return "fetch";
|
|
7705
|
+
return null;
|
|
7706
|
+
}
|
|
7707
|
+
function isPreTool(row5, event) {
|
|
7708
|
+
const e = event.toLowerCase();
|
|
7709
|
+
return HOOK_FAIL_PRE_EVENTS.includes(e) || (row5.eventMap.PreToolUse ?? "").toLowerCase() === e;
|
|
7710
|
+
}
|
|
7711
|
+
function bigRead(input, cwd) {
|
|
7712
|
+
if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
|
|
7713
|
+
const p = firstString(input, READ_PATH_KEYS);
|
|
7714
|
+
if (p === "") return false;
|
|
7715
|
+
try {
|
|
7716
|
+
const st = fs.statSync(resolve3(cwd, p));
|
|
7717
|
+
return st.isFile() && st.size > OUTPUT_CAP;
|
|
7718
|
+
} catch {
|
|
7719
|
+
return false;
|
|
7720
|
+
}
|
|
7721
|
+
}
|
|
7722
|
+
function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
7723
|
+
const row5 = getAdapter(agent);
|
|
7724
|
+
const allow = () => row5.encode({ event: "PreToolUse", agent, sessionId: "", cwd: "", turn: 0 }, { kind: "allow" });
|
|
7725
|
+
try {
|
|
7726
|
+
if (!isRec(raw)) return allow();
|
|
7727
|
+
if (!isPreTool(row5, firstString(raw, HOOK_FAIL_EVENT_KEYS))) return allow();
|
|
7728
|
+
const name = firstString(raw, HOOK_FAIL_TOOL_KEYS);
|
|
7729
|
+
if (name === "" || name.includes(OWN_TOOL_PREFIX)) return allow();
|
|
7730
|
+
const kind = kindOf(row5, name);
|
|
7731
|
+
if (kind === null) return allow();
|
|
7732
|
+
const cwd = firstString(raw, HOOK_FAIL_CWD_KEYS) || cwdFallback;
|
|
7733
|
+
if (kind === "read" && !bigRead(inputOf(raw), cwd)) return allow();
|
|
7734
|
+
const redirect = kind === "read" ? HOOK_FAIL_REDIRECT.read : HOOK_FAIL_REDIRECT[kind];
|
|
7735
|
+
const reason = prefixToolNames(redirect, row5.toolNamePrefix) + "\n" + HOOK_FAIL_LINE(errorLabel(err), row5.toolNamePrefix);
|
|
7736
|
+
return row5.encode({ event: "PreToolUse", agent, sessionId: "", cwd, turn: 0 }, { kind: "deny", reason });
|
|
7737
|
+
} catch {
|
|
7738
|
+
return { stdout: "", exitCode: 0 };
|
|
7739
|
+
}
|
|
7740
|
+
}
|
|
7741
|
+
|
|
7563
7742
|
// src/core/hooks/io.ts
|
|
7564
7743
|
var { read: read2, writeSync } = process.getBuiltinModule("node:fs");
|
|
7565
7744
|
|
|
@@ -7583,29 +7762,40 @@ async function handleHook(agent, raw, env) {
|
|
|
7583
7762
|
return EMPTY4;
|
|
7584
7763
|
}
|
|
7585
7764
|
const row5 = getAdapter(agent);
|
|
7765
|
+
const fail7 = (stage, err, line) => {
|
|
7766
|
+
logHookError(env, agent, stage, err);
|
|
7767
|
+
process.stderr.write(line ?? "hooks: " + stage + " failed: " + message(err) + "\n");
|
|
7768
|
+
return failureOutput(agent, raw, err);
|
|
7769
|
+
};
|
|
7770
|
+
if (nodeTooOld(process.version)) return fail7("node", new CtxError("NODE_TOO_OLD", { v: process.version }));
|
|
7586
7771
|
let ev;
|
|
7587
7772
|
try {
|
|
7773
|
+
fault(env, "decode");
|
|
7588
7774
|
ev = row5.decode(raw);
|
|
7589
7775
|
} catch (err) {
|
|
7590
|
-
|
|
7591
|
-
return row5.encode({ event: "PreToolUse", agent, sessionId: "", cwd: "", turn: 0 }, ALLOW2);
|
|
7776
|
+
return fail7("decode", err);
|
|
7592
7777
|
}
|
|
7593
7778
|
let project;
|
|
7594
7779
|
try {
|
|
7780
|
+
fault(env, "project");
|
|
7595
7781
|
const argv = agent === "vscode" ? [WORKSPACE_FOLDER_FLAG, ev.cwd] : process.argv;
|
|
7596
7782
|
project = resolveProject(agent, { env, argv, cwd: ev.cwd, piCwd: agent === "pi" ? ev.cwd : void 0 });
|
|
7597
7783
|
} catch (err) {
|
|
7598
|
-
|
|
7599
|
-
return row5.encode(ev, ALLOW2);
|
|
7784
|
+
return fail7("project", err, "hooks: no project: " + String(err.code ?? "ERROR") + " " + message(err) + "\n");
|
|
7600
7785
|
}
|
|
7601
7786
|
let decision;
|
|
7602
7787
|
try {
|
|
7788
|
+
fault(env, "policy");
|
|
7603
7789
|
decision = await dispatch(ev, row5, project, env);
|
|
7604
7790
|
} catch (err) {
|
|
7605
|
-
|
|
7606
|
-
|
|
7791
|
+
return fail7("store", err);
|
|
7792
|
+
}
|
|
7793
|
+
try {
|
|
7794
|
+
fault(env, "encode");
|
|
7795
|
+
return row5.encode(ev, decision);
|
|
7796
|
+
} catch (err) {
|
|
7797
|
+
return fail7("encode", err);
|
|
7607
7798
|
}
|
|
7608
|
-
return row5.encode(ev, decision);
|
|
7609
7799
|
}
|
|
7610
7800
|
function dispatch(ev, row5, project, env) {
|
|
7611
7801
|
switch (ev.event) {
|
|
@@ -7806,7 +7996,7 @@ function caseB(ev, row5, d0, userDeny) {
|
|
|
7806
7996
|
if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
|
|
7807
7997
|
const command = tool.input.command;
|
|
7808
7998
|
if (typeof command !== "string") return d0;
|
|
7809
|
-
const wrapper = '"' +
|
|
7999
|
+
const wrapper = '"' + join6(dirname3(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
|
|
7810
8000
|
const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
|
|
7811
8001
|
return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
|
|
7812
8002
|
}
|
|
@@ -19275,10 +19465,10 @@ function startArgv(argv) {
|
|
|
19275
19465
|
return sh === null ? null : [sh, ...argv];
|
|
19276
19466
|
}
|
|
19277
19467
|
function runProcess(argv, o) {
|
|
19278
|
-
return new Promise((
|
|
19468
|
+
return new Promise((resolve6) => {
|
|
19279
19469
|
const isWin2 = process.platform === "win32";
|
|
19280
19470
|
const start = startArgv(argv);
|
|
19281
|
-
if (start === null) return
|
|
19471
|
+
if (start === null) return resolve6(NOT_STARTED);
|
|
19282
19472
|
let child;
|
|
19283
19473
|
try {
|
|
19284
19474
|
child = spawn(start[0], start.slice(1), {
|
|
@@ -19292,7 +19482,7 @@ function runProcess(argv, o) {
|
|
|
19292
19482
|
windowsHide: true
|
|
19293
19483
|
});
|
|
19294
19484
|
} catch {
|
|
19295
|
-
return
|
|
19485
|
+
return resolve6(NOT_STARTED);
|
|
19296
19486
|
}
|
|
19297
19487
|
const stdoutChunks = [];
|
|
19298
19488
|
const stderrChunks = [];
|
|
@@ -19317,7 +19507,7 @@ function runProcess(argv, o) {
|
|
|
19317
19507
|
settled = true;
|
|
19318
19508
|
clearTimeout(timer);
|
|
19319
19509
|
o.signal.removeEventListener("abort", onAbort);
|
|
19320
|
-
|
|
19510
|
+
resolve6({
|
|
19321
19511
|
stdout: Buffer.concat(stdoutChunks),
|
|
19322
19512
|
stderr: Buffer.concat(stderrChunks),
|
|
19323
19513
|
exitCode,
|
|
@@ -19339,7 +19529,7 @@ function runProcess(argv, o) {
|
|
|
19339
19529
|
|
|
19340
19530
|
// src/core/index/auto-memory.ts
|
|
19341
19531
|
import { readFileSync as readFileSync5, statSync as statSync4 } from "node:fs";
|
|
19342
|
-
import { join as
|
|
19532
|
+
import { join as join7 } from "node:path";
|
|
19343
19533
|
var CLAUDE_CODE_MEMORY_FILES = Object.freeze([
|
|
19344
19534
|
Object.freeze(["CLAUDE.md"]),
|
|
19345
19535
|
Object.freeze(["CLAUDE.local.md"]),
|
|
@@ -19349,7 +19539,7 @@ function readAutoMemory(project) {
|
|
|
19349
19539
|
if (project.agent !== "claude-code") return [];
|
|
19350
19540
|
const rows = [];
|
|
19351
19541
|
for (const segs of CLAUDE_CODE_MEMORY_FILES) {
|
|
19352
|
-
const path5 =
|
|
19542
|
+
const path5 = join7(project.worktree, ...segs);
|
|
19353
19543
|
if (!isInside(project.worktree, path5)) continue;
|
|
19354
19544
|
try {
|
|
19355
19545
|
const st = statSync4(path5);
|
|
@@ -19780,19 +19970,19 @@ var ctxBatch = Object.freeze({
|
|
|
19780
19970
|
|
|
19781
19971
|
// src/core/tools/doctor.ts
|
|
19782
19972
|
import { readdirSync as readdirSync4, readFileSync as readFileSync11, existsSync as existsSync10 } from "node:fs";
|
|
19783
|
-
import { basename as basename3, dirname as dirname6, join as
|
|
19973
|
+
import { basename as basename3, dirname as dirname6, join as join13 } from "node:path";
|
|
19784
19974
|
|
|
19785
19975
|
// src/core/ops/doctor-config.ts
|
|
19786
|
-
import { join as
|
|
19976
|
+
import { join as join11 } from "node:path";
|
|
19787
19977
|
|
|
19788
19978
|
// src/core/ops/detect-v1.ts
|
|
19789
19979
|
import { existsSync as existsSync4, opendirSync, readdirSync, readFileSync as readFileSync7 } from "node:fs";
|
|
19790
19980
|
import { tmpdir } from "node:os";
|
|
19791
|
-
import { join as
|
|
19981
|
+
import { join as join9 } from "node:path";
|
|
19792
19982
|
|
|
19793
19983
|
// src/core/ops/host-config.ts
|
|
19794
19984
|
import { existsSync as existsSync3, readFileSync as readFileSync6 } from "node:fs";
|
|
19795
|
-
import { dirname as dirname4, join as
|
|
19985
|
+
import { dirname as dirname4, join as join8 } from "node:path";
|
|
19796
19986
|
|
|
19797
19987
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
19798
19988
|
var KEYS2 = {
|
|
@@ -21909,7 +22099,7 @@ function formatOf(path5) {
|
|
|
21909
22099
|
function readHostConfig(agent, path5) {
|
|
21910
22100
|
let file2 = path5;
|
|
21911
22101
|
if (agent === "opencode") {
|
|
21912
|
-
const jsonc =
|
|
22102
|
+
const jsonc = join8(dirname4(path5), OPENCODE_CONFIG_FILES[0]);
|
|
21913
22103
|
if (existsSync3(jsonc)) file2 = jsonc;
|
|
21914
22104
|
}
|
|
21915
22105
|
const raw = existsSync3(file2) ? readFileSync6(file2, "utf8") : "";
|
|
@@ -22260,7 +22450,7 @@ function setText(agent, path5, text, format, key, value) {
|
|
|
22260
22450
|
}
|
|
22261
22451
|
}
|
|
22262
22452
|
function serverScript() {
|
|
22263
|
-
return
|
|
22453
|
+
return join8(dirname4(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
22264
22454
|
}
|
|
22265
22455
|
function listTarget(key, own2, v1) {
|
|
22266
22456
|
return {
|
|
@@ -22411,7 +22601,7 @@ function mcpEntry(file2, doc, out) {
|
|
|
22411
22601
|
}
|
|
22412
22602
|
}
|
|
22413
22603
|
function claudeShapeSettings(agentHome, out) {
|
|
22414
|
-
const file2 =
|
|
22604
|
+
const file2 = join9(agentHome, SETTINGS_FILE);
|
|
22415
22605
|
const doc = readJson(file2);
|
|
22416
22606
|
for (const c of nestedCommands(doc)) {
|
|
22417
22607
|
if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
|
|
@@ -22431,46 +22621,46 @@ function v1HookFile(file2, out) {
|
|
|
22431
22621
|
function scanClaudeCode(home, agentHome, out) {
|
|
22432
22622
|
claudeShapeSettings(agentHome, out);
|
|
22433
22623
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
22434
|
-
const file2 =
|
|
22624
|
+
const file2 = join9(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
22435
22625
|
if (existsSync4(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
22436
22626
|
}
|
|
22437
|
-
const userFile =
|
|
22627
|
+
const userFile = join9(home, CLAUDE_USER_CONFIG_FILE);
|
|
22438
22628
|
mcpEntry(userFile, readJson(userFile), out);
|
|
22439
|
-
dataDir(
|
|
22629
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
22440
22630
|
}
|
|
22441
22631
|
function scanCodex(agentHome, out) {
|
|
22442
|
-
const hooksFile =
|
|
22632
|
+
const hooksFile = join9(agentHome, HOOKS_JSON_FILE);
|
|
22443
22633
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
22444
22634
|
if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
|
|
22445
22635
|
out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
|
|
22446
22636
|
}
|
|
22447
22637
|
}
|
|
22448
|
-
const tomlFile =
|
|
22638
|
+
const tomlFile = join9(agentHome, CONFIG_TOML_FILE);
|
|
22449
22639
|
for (const span of readTomlTables(tomlFile)) {
|
|
22450
22640
|
if (tomlHeaderText(span.path).startsWith(V1_TOML_SECTION_PREFIX)) out.push(finding(tomlFile, span.header.trim(), V1_REASON.codexToml));
|
|
22451
22641
|
}
|
|
22452
|
-
dataDir(
|
|
22642
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
22453
22643
|
}
|
|
22454
22644
|
function scanGemini(agentHome, out) {
|
|
22455
|
-
const file2 =
|
|
22645
|
+
const file2 = join9(agentHome, SETTINGS_FILE);
|
|
22456
22646
|
for (const c of nestedCommands(readJson(file2))) {
|
|
22457
22647
|
if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
|
|
22458
22648
|
}
|
|
22459
|
-
dataDir(
|
|
22649
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
|
|
22460
22650
|
}
|
|
22461
22651
|
function scanVscode(agentHome, project, out) {
|
|
22462
22652
|
if (project !== void 0) {
|
|
22463
|
-
v1HookFile(
|
|
22464
|
-
const mcpFile2 =
|
|
22653
|
+
v1HookFile(join9(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
22654
|
+
const mcpFile2 = join9(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
22465
22655
|
const doc = readJson(mcpFile2);
|
|
22466
22656
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
22467
22657
|
const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
22468
22658
|
if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
|
|
22469
22659
|
out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
22470
22660
|
}
|
|
22471
|
-
dataDir(
|
|
22661
|
+
dataDir(join9(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
22472
22662
|
}
|
|
22473
|
-
dataDir(
|
|
22663
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
22474
22664
|
}
|
|
22475
22665
|
function jsonFiles(dir) {
|
|
22476
22666
|
try {
|
|
@@ -22480,10 +22670,10 @@ function jsonFiles(dir) {
|
|
|
22480
22670
|
}
|
|
22481
22671
|
}
|
|
22482
22672
|
function scanKiro(agentHome, project, out) {
|
|
22483
|
-
const agentsDir =
|
|
22484
|
-
const defaultFile =
|
|
22673
|
+
const agentsDir = join9(agentHome, KIRO_AGENTS_DIR);
|
|
22674
|
+
const defaultFile = join9(agentHome, ...KIRO_AGENT_FILE);
|
|
22485
22675
|
for (const name of jsonFiles(agentsDir)) {
|
|
22486
|
-
const file2 =
|
|
22676
|
+
const file2 = join9(agentsDir, name);
|
|
22487
22677
|
const doc = readJson(file2);
|
|
22488
22678
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
22489
22679
|
out.push(finding(file2, "", V1_REASON.kiroAgentFile));
|
|
@@ -22494,25 +22684,25 @@ function scanKiro(agentHome, project, out) {
|
|
|
22494
22684
|
if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
|
|
22495
22685
|
}
|
|
22496
22686
|
}
|
|
22497
|
-
const steeringDocs = [
|
|
22498
|
-
if (project !== void 0) steeringDocs.push(
|
|
22687
|
+
const steeringDocs = [join9(agentHome, ...KIRO_STEERING_FILE)];
|
|
22688
|
+
if (project !== void 0) steeringDocs.push(join9(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
22499
22689
|
for (const file2 of steeringDocs) {
|
|
22500
22690
|
if (existsSync4(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
22501
22691
|
}
|
|
22502
|
-
dataDir(
|
|
22692
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
22503
22693
|
}
|
|
22504
22694
|
function scanPi(piAgentDir, agentHome, out) {
|
|
22505
|
-
const file2 =
|
|
22695
|
+
const file2 = join9(piAgentDir, SETTINGS_FILE);
|
|
22506
22696
|
const doc = readJson(file2);
|
|
22507
22697
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
22508
22698
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
22509
22699
|
if (spec === V1_PI_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
22510
22700
|
});
|
|
22511
|
-
dataDir(
|
|
22701
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
22512
22702
|
}
|
|
22513
22703
|
function scanOpencode(agentHome, out) {
|
|
22514
22704
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
22515
|
-
const file2 =
|
|
22705
|
+
const file2 = join9(agentHome, name);
|
|
22516
22706
|
const doc = readJson(file2);
|
|
22517
22707
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
22518
22708
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
|
|
@@ -22522,13 +22712,13 @@ function scanOpencode(agentHome, out) {
|
|
|
22522
22712
|
}
|
|
22523
22713
|
}
|
|
22524
22714
|
function scanZcode(agentHome, out) {
|
|
22525
|
-
const configFile =
|
|
22715
|
+
const configFile = join9(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
22526
22716
|
const config2 = readJson(configFile);
|
|
22527
22717
|
const events = isObj(config2) && isObj(config2[HOOKS_KEY]) ? config2[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
22528
22718
|
for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
22529
22719
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
|
|
22530
22720
|
}
|
|
22531
|
-
const hooksFile =
|
|
22721
|
+
const hooksFile = join9(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
22532
22722
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
22533
22723
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
|
|
22534
22724
|
}
|
|
@@ -22552,14 +22742,14 @@ function firstTmpMatch(dir) {
|
|
|
22552
22742
|
}
|
|
22553
22743
|
}
|
|
22554
22744
|
function scanAll(home, tmp, out) {
|
|
22555
|
-
const root =
|
|
22556
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
22745
|
+
const root = join9(home, DATA_ROOT.slice(1));
|
|
22746
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join9(root, name), V1_REASON.dataRoot, out);
|
|
22557
22747
|
if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
22558
22748
|
}
|
|
22559
22749
|
function detectV1(agent, home, scope = {}) {
|
|
22560
22750
|
const out = [];
|
|
22561
22751
|
const project = scope.project;
|
|
22562
|
-
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : 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 :
|
|
22752
|
+
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : 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 : join9(home, ...AGENT_HOME_DIR[agent]);
|
|
22563
22753
|
switch (agent) {
|
|
22564
22754
|
case "claude-code":
|
|
22565
22755
|
scanClaudeCode(home, agentHome, out);
|
|
@@ -22572,11 +22762,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
22572
22762
|
break;
|
|
22573
22763
|
case "qwen":
|
|
22574
22764
|
claudeShapeSettings(agentHome, out);
|
|
22575
|
-
dataDir(
|
|
22765
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
22576
22766
|
break;
|
|
22577
22767
|
case "copilot-cli":
|
|
22578
|
-
v1HookFile(
|
|
22579
|
-
dataDir(
|
|
22768
|
+
v1HookFile(join9(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
22769
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
22580
22770
|
break;
|
|
22581
22771
|
case "vscode":
|
|
22582
22772
|
scanVscode(agentHome, project, out);
|
|
@@ -22585,7 +22775,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
22585
22775
|
scanKiro(agentHome, project, out);
|
|
22586
22776
|
break;
|
|
22587
22777
|
case "pi":
|
|
22588
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
22778
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join9(agentHome, PI_AGENT_DIR), agentHome, out);
|
|
22589
22779
|
break;
|
|
22590
22780
|
// D-WIN-PIDIR-1: empty is unset
|
|
22591
22781
|
case "opencode":
|
|
@@ -22601,7 +22791,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
22601
22791
|
|
|
22602
22792
|
// src/core/ops/plugin-root.ts
|
|
22603
22793
|
import { existsSync as existsSync5, readdirSync as readdirSync2, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
|
|
22604
|
-
import { dirname as dirname5, isAbsolute as isAbsolute2, join as
|
|
22794
|
+
import { dirname as dirname5, isAbsolute as isAbsolute2, join as join10, sep as sep3 } from "node:path";
|
|
22605
22795
|
import { fileURLToPath } from "node:url";
|
|
22606
22796
|
function missing(agent, path5) {
|
|
22607
22797
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path5 });
|
|
@@ -22637,13 +22827,13 @@ var realOrNull = (path5) => {
|
|
|
22637
22827
|
};
|
|
22638
22828
|
function marketplaceRoot(adapter, env) {
|
|
22639
22829
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
22640
|
-
const plugins =
|
|
22641
|
-
const cache =
|
|
22830
|
+
const plugins = join10(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
22831
|
+
const cache = join10(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
22642
22832
|
const script = process.argv[1];
|
|
22643
22833
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname5(script));
|
|
22644
22834
|
let record4 = null;
|
|
22645
22835
|
try {
|
|
22646
|
-
record4 = readFileSync8(
|
|
22836
|
+
record4 = readFileSync8(join10(plugins, INSTALLED_PLUGINS_FILE), "utf8");
|
|
22647
22837
|
} catch {
|
|
22648
22838
|
record4 = null;
|
|
22649
22839
|
}
|
|
@@ -22656,10 +22846,10 @@ function marketplaceRoot(adapter, env) {
|
|
|
22656
22846
|
throw missing(adapter.id, recorded.join(", "));
|
|
22657
22847
|
}
|
|
22658
22848
|
const cacheReal = realOrNull(cache);
|
|
22659
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep3) && existsSync5(
|
|
22660
|
-
const pattern =
|
|
22849
|
+
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep3) && existsSync5(join10(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
22850
|
+
const pattern = join10(cache, "*", PLUGIN_NAME);
|
|
22661
22851
|
if (!existsSync5(cache)) throw missing(adapter.id, pattern);
|
|
22662
|
-
const found = readdirSync2(cache).sort().map((marketplace) =>
|
|
22852
|
+
const found = readdirSync2(cache).sort().map((marketplace) => join10(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync5(dir));
|
|
22663
22853
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
22664
22854
|
return found[0];
|
|
22665
22855
|
}
|
|
@@ -22684,9 +22874,9 @@ function candidate(adapter, env) {
|
|
|
22684
22874
|
case "hooks+mcp":
|
|
22685
22875
|
return configEntryRoot(adapter, env);
|
|
22686
22876
|
case "extension":
|
|
22687
|
-
return
|
|
22877
|
+
return join10(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id], EXTENSIONS_DIR_NAME, PLUGIN_NAME);
|
|
22688
22878
|
case "plugin":
|
|
22689
|
-
return
|
|
22879
|
+
return join10(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
22690
22880
|
case "in-process":
|
|
22691
22881
|
return dirname5(fileURLToPath(import.meta.url));
|
|
22692
22882
|
}
|
|
@@ -22777,11 +22967,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
22777
22967
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
22778
22968
|
function mcpFile(row5, home, env) {
|
|
22779
22969
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
22780
|
-
if (row5.id === "codex") return
|
|
22970
|
+
if (row5.id === "codex") return join11(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
22781
22971
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
22782
|
-
if (row5.id === "opencode") return
|
|
22972
|
+
if (row5.id === "opencode") return join11(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
22783
22973
|
if (row5.id === "pi") {
|
|
22784
|
-
return
|
|
22974
|
+
return join11(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
22785
22975
|
}
|
|
22786
22976
|
return null;
|
|
22787
22977
|
}
|
|
@@ -22804,10 +22994,10 @@ function hookParts(row5, home, env, worktree) {
|
|
|
22804
22994
|
let block;
|
|
22805
22995
|
try {
|
|
22806
22996
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env) : spec.root === "home" ? home : worktree;
|
|
22807
|
-
const file2 = row5.id === "codex" ?
|
|
22997
|
+
const file2 = row5.id === "codex" ? join11(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join11(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join11(kiroDirOf(env, home), ...spec.file.slice(1)) : join11(root, ...spec.file);
|
|
22808
22998
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
22809
22999
|
if (row5.id === "codex") {
|
|
22810
|
-
const config2 = readParsed(row5.id,
|
|
23000
|
+
const config2 = readParsed(row5.id, join11(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
22811
23001
|
if (hostConfigValueAt(config2, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
22812
23002
|
}
|
|
22813
23003
|
} catch {
|
|
@@ -22858,10 +23048,10 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
22858
23048
|
}
|
|
22859
23049
|
function checkDoubleFire(agent, worktree) {
|
|
22860
23050
|
if (agent !== "claude-code" && agent !== "vscode") return pass("D5b");
|
|
22861
|
-
const claude = parsedOrNull(agent,
|
|
23051
|
+
const claude = parsedOrNull(agent, join11(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
22862
23052
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
22863
23053
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
22864
|
-
const vscode = parsedOrNull(agent,
|
|
23054
|
+
const vscode = parsedOrNull(agent, join11(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
22865
23055
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
22866
23056
|
return hooksOn && useClaudeHooks ? fail2("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
|
|
22867
23057
|
}
|
|
@@ -23090,9 +23280,9 @@ import { existsSync as existsSync9, rmSync as rmSync3 } from "node:fs";
|
|
|
23090
23280
|
|
|
23091
23281
|
// src/core/store/owners.ts
|
|
23092
23282
|
import { mkdirSync as mkdirSync4, readdirSync as readdirSync3, readFileSync as readFileSync10, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
23093
|
-
import { basename as basename2, join as
|
|
23283
|
+
import { basename as basename2, join as join12 } from "node:path";
|
|
23094
23284
|
function ownersDir(configDir, projectKey) {
|
|
23095
|
-
return
|
|
23285
|
+
return join12(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
23096
23286
|
}
|
|
23097
23287
|
function errCode2(err) {
|
|
23098
23288
|
return err.code;
|
|
@@ -23120,7 +23310,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
23120
23310
|
const live = [];
|
|
23121
23311
|
for (const name of names) {
|
|
23122
23312
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
23123
|
-
const file2 =
|
|
23313
|
+
const file2 = join12(dir, name);
|
|
23124
23314
|
let text;
|
|
23125
23315
|
try {
|
|
23126
23316
|
text = readFileSync10(file2, "utf8");
|
|
@@ -23260,7 +23450,7 @@ async function codexDb(ctx, adapter) {
|
|
|
23260
23450
|
async function hookRow(ctx, adapter, host) {
|
|
23261
23451
|
const db = await codexDb(ctx, adapter);
|
|
23262
23452
|
try {
|
|
23263
|
-
|
|
23453
|
+
const row5 = await checkHookRoundTrip({
|
|
23264
23454
|
agent: adapter.id,
|
|
23265
23455
|
bundleDir: host.bundleDir,
|
|
23266
23456
|
env: buildChildEnv(host.env),
|
|
@@ -23269,16 +23459,18 @@ async function hookRow(ctx, adapter, host) {
|
|
|
23269
23459
|
// same Codex dir D3 reads (D-N6-CODEX-HOME-2)
|
|
23270
23460
|
db
|
|
23271
23461
|
});
|
|
23462
|
+
const last2 = lastHookError(host.env);
|
|
23463
|
+
return last2 === null ? row5 : { ...row5, detail: row5.detail + D5_LAST_HOOK_ERROR(last2.ts, last2.stage, last2.label) };
|
|
23272
23464
|
} finally {
|
|
23273
23465
|
if (db !== null) closeDb(db);
|
|
23274
23466
|
}
|
|
23275
23467
|
}
|
|
23276
23468
|
function ownServerId(configDir, projectKey) {
|
|
23277
|
-
const dir =
|
|
23469
|
+
const dir = join13(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
23278
23470
|
if (!existsSync10(dir)) return "";
|
|
23279
23471
|
for (const name of readdirSync4(dir)) {
|
|
23280
23472
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
23281
|
-
if (readFileSync11(
|
|
23473
|
+
if (readFileSync11(join13(dir, name), "utf8").trim() === String(process.pid)) return basename3(name, OWNER_PID_EXT);
|
|
23282
23474
|
}
|
|
23283
23475
|
return "";
|
|
23284
23476
|
}
|
|
@@ -23352,7 +23544,7 @@ var ctxDoctor = Object.freeze({
|
|
|
23352
23544
|
// src/core/tools/execute.ts
|
|
23353
23545
|
import { existsSync as existsSync11, mkdtempSync, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
23354
23546
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
23355
|
-
import { dirname as dirname7, join as
|
|
23547
|
+
import { dirname as dirname7, join as join14, parse as parse3, resolve as resolve4 } from "node:path";
|
|
23356
23548
|
|
|
23357
23549
|
// src/core/sandbox/win-build.ts
|
|
23358
23550
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -23498,7 +23690,7 @@ async function handler3(raw, ctx) {
|
|
|
23498
23690
|
const cwd = ctx.project.worktree;
|
|
23499
23691
|
const extra = { ...PLAIN_OUTPUT_ENV2 };
|
|
23500
23692
|
if (input.file !== void 0) {
|
|
23501
|
-
const abs =
|
|
23693
|
+
const abs = resolve4(cwd, input.file);
|
|
23502
23694
|
const bad = fileError(input.file, abs, ctx.project.containmentRoot);
|
|
23503
23695
|
if (bad !== null) return fail5(bad);
|
|
23504
23696
|
extra.CTX_FILE = abs;
|
|
@@ -23515,8 +23707,8 @@ async function handler3(raw, ctx) {
|
|
|
23515
23707
|
if (takesDashC(input.language, runtime)) {
|
|
23516
23708
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
23517
23709
|
} else {
|
|
23518
|
-
tmpDir = mkdtempSync(
|
|
23519
|
-
const file2 =
|
|
23710
|
+
tmpDir = mkdtempSync(join14(tmpdir2(), TMP_PREFIX));
|
|
23711
|
+
const file2 = join14(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
23520
23712
|
writeFileSync3(file2, scriptText(input.language, input.code), "utf8");
|
|
23521
23713
|
argv = scriptArgv(input.language, runtime, file2);
|
|
23522
23714
|
}
|
|
@@ -23552,11 +23744,11 @@ var ctxExecute = {
|
|
|
23552
23744
|
|
|
23553
23745
|
// src/core/tools/index.ts
|
|
23554
23746
|
import { existsSync as existsSync12, readFileSync as readFileSync13, statSync as statSync6 } from "node:fs";
|
|
23555
|
-
import { dirname as dirname8, extname, join as
|
|
23747
|
+
import { dirname as dirname8, extname, join as join16, relative as relative3, resolve as resolve5 } from "node:path";
|
|
23556
23748
|
|
|
23557
23749
|
// src/core/index/walk.ts
|
|
23558
23750
|
import { readdirSync as readdirSync5, readFileSync as readFileSync12, realpathSync as realpathSync6, statSync as statSync5 } from "node:fs";
|
|
23559
|
-
import { join as
|
|
23751
|
+
import { join as join15 } from "node:path";
|
|
23560
23752
|
var GITIGNORE = ".gitignore";
|
|
23561
23753
|
var GIT_DIR = ".git";
|
|
23562
23754
|
function walkDir(root, containmentRoot) {
|
|
@@ -23565,7 +23757,7 @@ function walkDir(root, containmentRoot) {
|
|
|
23565
23757
|
const found = [];
|
|
23566
23758
|
visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
|
|
23567
23759
|
found.sort(compareFound);
|
|
23568
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
23760
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join15(...f.dir, f.name) }));
|
|
23569
23761
|
}
|
|
23570
23762
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
23571
23763
|
let entries;
|
|
@@ -23574,10 +23766,10 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
23574
23766
|
} catch {
|
|
23575
23767
|
return;
|
|
23576
23768
|
}
|
|
23577
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
23769
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join15(abs, GITIGNORE), rel)) : parent;
|
|
23578
23770
|
for (const e of entries) {
|
|
23579
23771
|
if (e.name === GIT_DIR) continue;
|
|
23580
|
-
const path5 =
|
|
23772
|
+
const path5 = join15(abs, e.name);
|
|
23581
23773
|
let isDir = e.isDirectory();
|
|
23582
23774
|
let isFile = e.isFile();
|
|
23583
23775
|
let target = path5;
|
|
@@ -23794,18 +23986,18 @@ function request(u, conn, proxy, signal) {
|
|
|
23794
23986
|
const host = bare(u.hostname);
|
|
23795
23987
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
23796
23988
|
const path5 = u.pathname + u.search;
|
|
23797
|
-
return new Promise((
|
|
23989
|
+
return new Promise((resolve6, reject) => {
|
|
23798
23990
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
23799
23991
|
if (proxy === void 0) {
|
|
23800
23992
|
const mod = u.protocol === "https:" ? https : http;
|
|
23801
23993
|
const req = mod.request({ host: conn.address, port, path: path5, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
23802
|
-
req.on("response",
|
|
23994
|
+
req.on("response", resolve6).on("error", onErr).end();
|
|
23803
23995
|
return;
|
|
23804
23996
|
}
|
|
23805
23997
|
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
23806
23998
|
if (u.protocol === "http:") {
|
|
23807
23999
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
23808
|
-
req.on("response",
|
|
24000
|
+
req.on("response", resolve6).on("error", onErr).end();
|
|
23809
24001
|
return;
|
|
23810
24002
|
}
|
|
23811
24003
|
const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
|
|
@@ -23825,16 +24017,16 @@ function request(u, conn, proxy, signal) {
|
|
|
23825
24017
|
headers: { host: u.host },
|
|
23826
24018
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
23827
24019
|
});
|
|
23828
|
-
req.on("response",
|
|
24020
|
+
req.on("response", resolve6).on("error", onErr).end();
|
|
23829
24021
|
});
|
|
23830
24022
|
tunnel.end();
|
|
23831
24023
|
});
|
|
23832
24024
|
}
|
|
23833
24025
|
function readBody(res) {
|
|
23834
|
-
return new Promise((
|
|
24026
|
+
return new Promise((resolve6, reject) => {
|
|
23835
24027
|
const parts = [];
|
|
23836
24028
|
res.on("data", (b) => parts.push(b));
|
|
23837
|
-
res.on("end", () =>
|
|
24029
|
+
res.on("end", () => resolve6(Buffer.concat(parts)));
|
|
23838
24030
|
res.on("error", (err) => reject(fail6(causeCode(err))));
|
|
23839
24031
|
res.on("aborted", () => reject(fail6("ECONNRESET")));
|
|
23840
24032
|
});
|
|
@@ -23911,13 +24103,13 @@ function missingOrOutside(given, abs, root) {
|
|
|
23911
24103
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
23912
24104
|
}
|
|
23913
24105
|
function pathItems(input, project) {
|
|
23914
|
-
const abs =
|
|
24106
|
+
const abs = resolve5(project.worktree, input.path);
|
|
23915
24107
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
23916
24108
|
const base = relative3(project.worktree, abs);
|
|
23917
24109
|
if (statSync6(abs).isDirectory()) {
|
|
23918
24110
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
23919
24111
|
sourceKind: "path",
|
|
23920
|
-
label:
|
|
24112
|
+
label: join16(base, f.relPath),
|
|
23921
24113
|
kind: kindOfPath(f.relPath),
|
|
23922
24114
|
read: () => readUtf8(f.absPath)
|
|
23923
24115
|
}));
|
|
@@ -24150,11 +24342,11 @@ var ctxStats = Object.freeze({
|
|
|
24150
24342
|
|
|
24151
24343
|
// src/core/tools/upgrade.ts
|
|
24152
24344
|
import { existsSync as existsSync18, realpathSync as realpathSync7, rmSync as rmSync9 } from "node:fs";
|
|
24153
|
-
import { basename as basename5, dirname as dirname10, join as
|
|
24345
|
+
import { basename as basename5, dirname as dirname10, join as join22 } from "node:path";
|
|
24154
24346
|
|
|
24155
24347
|
// src/core/ops/host-write.ts
|
|
24156
24348
|
import { copyFileSync, existsSync as existsSync13, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
24157
|
-
import { dirname as dirname9, join as
|
|
24349
|
+
import { dirname as dirname9, join as join17 } from "node:path";
|
|
24158
24350
|
function defaultWrite(file2, text) {
|
|
24159
24351
|
writeFileSync4(file2, text, "utf8");
|
|
24160
24352
|
}
|
|
@@ -24163,14 +24355,14 @@ function hostConfigPath(agent, home, env) {
|
|
|
24163
24355
|
if (own2 !== void 0) return ownMcpFileOf(agent, own2.file, env, home);
|
|
24164
24356
|
switch (agent) {
|
|
24165
24357
|
case "opencode":
|
|
24166
|
-
return
|
|
24358
|
+
return join17(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
24167
24359
|
// D-WIN-OPENCODE-DIR-1
|
|
24168
24360
|
case "pi":
|
|
24169
|
-
return
|
|
24361
|
+
return join17(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
24170
24362
|
case "copilot-cli":
|
|
24171
24363
|
return null;
|
|
24172
24364
|
default:
|
|
24173
|
-
return
|
|
24365
|
+
return join17(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
24174
24366
|
}
|
|
24175
24367
|
}
|
|
24176
24368
|
function cell2(value) {
|
|
@@ -24221,7 +24413,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
24221
24413
|
|
|
24222
24414
|
// src/core/ops/plugin-swap.ts
|
|
24223
24415
|
import { existsSync as existsSync14, lstatSync, readdirSync as readdirSync6, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
24224
|
-
import { basename as basename4, join as
|
|
24416
|
+
import { basename as basename4, join as join18, win32 as win322 } from "node:path";
|
|
24225
24417
|
function linkTarget(path5, win) {
|
|
24226
24418
|
if (!isLink(path5)) return null;
|
|
24227
24419
|
const target = readlinkSync(path5);
|
|
@@ -24240,11 +24432,11 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
24240
24432
|
else renameWithRetry(old, link, opts);
|
|
24241
24433
|
}
|
|
24242
24434
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
24243
|
-
const next =
|
|
24435
|
+
const next = join18(agentDir, sha);
|
|
24244
24436
|
if (!existsSync14(next) || !lstatSync(next).isDirectory()) {
|
|
24245
24437
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename4(agentDir), path: next });
|
|
24246
24438
|
}
|
|
24247
|
-
const link =
|
|
24439
|
+
const link = join18(agentDir, PLUGIN_CURRENT_LINK);
|
|
24248
24440
|
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
24249
24441
|
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
24250
24442
|
settleLinks(link, tmp, old, opts);
|
|
@@ -24259,15 +24451,15 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
24259
24451
|
if (before !== null) unlinkSync2(old);
|
|
24260
24452
|
const keep = /* @__PURE__ */ new Set([sha]);
|
|
24261
24453
|
if (before !== null) keep.add(before);
|
|
24262
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) =>
|
|
24454
|
+
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join18(agentDir, name));
|
|
24263
24455
|
for (const dir of removed) rmSync5(dir, { recursive: true, force: true });
|
|
24264
|
-
const previous = before !== null && existsSync14(
|
|
24456
|
+
const previous = before !== null && existsSync14(join18(agentDir, before)) ? join18(agentDir, before) : null;
|
|
24265
24457
|
return { current: next, previous, removed };
|
|
24266
24458
|
}
|
|
24267
24459
|
|
|
24268
24460
|
// src/core/ops/release-fetch.ts
|
|
24269
24461
|
import { existsSync as existsSync15, mkdirSync as mkdirSync6, rmSync as rmSync6 } from "node:fs";
|
|
24270
|
-
import { join as
|
|
24462
|
+
import { join as join19 } from "node:path";
|
|
24271
24463
|
function failed(r) {
|
|
24272
24464
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
24273
24465
|
const status = r.killed ?? String(r.exitCode);
|
|
@@ -24279,9 +24471,9 @@ async function git2(bin, args, cwd, env, signal) {
|
|
|
24279
24471
|
return r.stdout.toString().trim();
|
|
24280
24472
|
}
|
|
24281
24473
|
async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
24282
|
-
const agentDir =
|
|
24474
|
+
const agentDir = join19(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
24283
24475
|
mkdirSync6(agentDir, { recursive: true });
|
|
24284
|
-
const fetchDir =
|
|
24476
|
+
const fetchDir = join19(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
24285
24477
|
rmSync6(fetchDir, { recursive: true, force: true });
|
|
24286
24478
|
const gitBin = findRuntime(GIT_BIN, env);
|
|
24287
24479
|
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -24289,7 +24481,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
24289
24481
|
try {
|
|
24290
24482
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url2, fetchDir], agentDir, childEnv, signal);
|
|
24291
24483
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
24292
|
-
const dir =
|
|
24484
|
+
const dir = join19(agentDir, sha);
|
|
24293
24485
|
if (existsSync15(dir)) rmSync6(fetchDir, { recursive: true, force: true });
|
|
24294
24486
|
else renameWithRetry(fetchDir, dir, opts);
|
|
24295
24487
|
return { sha, dir };
|
|
@@ -24301,14 +24493,14 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
24301
24493
|
|
|
24302
24494
|
// src/core/ops/uninstall.ts
|
|
24303
24495
|
import { existsSync as existsSync16, readdirSync as readdirSync7, rmSync as rmSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
24304
|
-
import { join as
|
|
24496
|
+
import { join as join20 } from "node:path";
|
|
24305
24497
|
function row2(area, before, after) {
|
|
24306
24498
|
return { area, before, after };
|
|
24307
24499
|
}
|
|
24308
24500
|
function stopServers(configDir, projectKey) {
|
|
24309
24501
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
24310
|
-
const dir =
|
|
24311
|
-
for (const serverId of stopped) writeFileSync5(
|
|
24502
|
+
const dir = join20(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
24503
|
+
for (const serverId of stopped) writeFileSync5(join20(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
24312
24504
|
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 };
|
|
24313
24505
|
}
|
|
24314
24506
|
function rootOrNull(adapter, env) {
|
|
@@ -24329,7 +24521,7 @@ function removeCache(adapter, env, configDir) {
|
|
|
24329
24521
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
24330
24522
|
}
|
|
24331
24523
|
case "plugin": {
|
|
24332
|
-
const agentDir =
|
|
24524
|
+
const agentDir = join20(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
24333
24525
|
if (!existsSync16(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
24334
24526
|
rmSync7(agentDir, { recursive: true, force: true });
|
|
24335
24527
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
@@ -24375,7 +24567,7 @@ function ownEntries(agent, env) {
|
|
|
24375
24567
|
}
|
|
24376
24568
|
if (agent === "opencode") {
|
|
24377
24569
|
return [{
|
|
24378
|
-
file:
|
|
24570
|
+
file: join20(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
24379
24571
|
// D-WIN-OPENCODE-DIR-1
|
|
24380
24572
|
key: OPENCODE_PLUGIN_KEY,
|
|
24381
24573
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -24386,7 +24578,7 @@ function ownEntries(agent, env) {
|
|
|
24386
24578
|
if (agent === "pi") {
|
|
24387
24579
|
const agentDir = piAgentDirOf(env, home);
|
|
24388
24580
|
return [{
|
|
24389
|
-
file:
|
|
24581
|
+
file: join20(agentDir, SETTINGS_FILE),
|
|
24390
24582
|
key: PI_PACKAGES_KEY,
|
|
24391
24583
|
shown: PI_PACKAGES_KEY,
|
|
24392
24584
|
has: (v) => Array.isArray(v) && v.some((x) => piSource(x) === PI_GIT_PACKAGE),
|
|
@@ -24408,12 +24600,12 @@ function removeOwnEntries(agent, env) {
|
|
|
24408
24600
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
24409
24601
|
}
|
|
24410
24602
|
function removeProjectData(configDir, projectKey) {
|
|
24411
|
-
const projects =
|
|
24412
|
-
const dir =
|
|
24603
|
+
const projects = join20(configDir, PROJECTS_DIR_NAME);
|
|
24604
|
+
const dir = join20(projects, projectKey);
|
|
24413
24605
|
if (!existsSync16(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
24414
24606
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
24415
24607
|
for (const name of readdirSync7(dir)) {
|
|
24416
|
-
if (name !== OWNERS_DIR_NAME) rmSync7(
|
|
24608
|
+
if (name !== OWNERS_DIR_NAME) rmSync7(join20(dir, name), { recursive: true, force: true });
|
|
24417
24609
|
}
|
|
24418
24610
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
24419
24611
|
}
|
|
@@ -24421,7 +24613,7 @@ function runUninstall(input) {
|
|
|
24421
24613
|
const configDir = resolveConfigDir(input.env);
|
|
24422
24614
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
24423
24615
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
24424
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
24616
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join20(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
24425
24617
|
return { rows, stopped: stop.stopped };
|
|
24426
24618
|
}
|
|
24427
24619
|
|
|
@@ -24558,7 +24750,7 @@ function removeV1(agent, findings) {
|
|
|
24558
24750
|
// src/core/ops/verify-sums.ts
|
|
24559
24751
|
import { createHash } from "node:crypto";
|
|
24560
24752
|
import { lstatSync as lstatSync2, readdirSync as readdirSync8, readFileSync as readFileSync15 } from "node:fs";
|
|
24561
|
-
import { join as
|
|
24753
|
+
import { join as join21 } from "node:path";
|
|
24562
24754
|
function mismatch() {
|
|
24563
24755
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
24564
24756
|
}
|
|
@@ -24579,14 +24771,14 @@ function walk(dir, prefix, out) {
|
|
|
24579
24771
|
for (const entry of readdirSync8(dir, { withFileTypes: true })) {
|
|
24580
24772
|
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
24581
24773
|
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
24582
|
-
const abs =
|
|
24774
|
+
const abs = join21(dir, entry.name);
|
|
24583
24775
|
if (entry.isDirectory()) walk(abs, rel, out);
|
|
24584
24776
|
else if (entry.isFile()) out.set(rel, abs);
|
|
24585
24777
|
else throw mismatch();
|
|
24586
24778
|
}
|
|
24587
24779
|
}
|
|
24588
24780
|
function verifySums(dir) {
|
|
24589
|
-
const sumsPath =
|
|
24781
|
+
const sumsPath = join21(dir, RELEASE_SUMS_FILE);
|
|
24590
24782
|
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
24591
24783
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
24592
24784
|
const sums = parseSums(readFileSync15(sumsPath, "utf8"));
|
|
@@ -24624,7 +24816,7 @@ function pluginRootRow(adapter, env) {
|
|
|
24624
24816
|
return root === own2 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own2)];
|
|
24625
24817
|
}
|
|
24626
24818
|
function isCurrent(agentDir, dir) {
|
|
24627
|
-
const link =
|
|
24819
|
+
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
24628
24820
|
return existsSync18(link) && realpathSync7.native(link) === realpathSync7.native(dir);
|
|
24629
24821
|
}
|
|
24630
24822
|
async function checkout(adapter, deps) {
|