context-mode 2.1.1 → 2.1.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/README.md +73 -73
- package/SHA256SUMS +15 -15
- package/cli.mjs +148 -138
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +81 -81
- package/opencode/plugin.js +305 -216
- package/package.json +1 -1
- package/pi/index.js +359 -268
- package/qwen-extension.json +1 -1
- package/run.mjs +3 -2
- package/search.mjs +3 -2
- package/server.mjs +335 -250
package/opencode/plugin.js
CHANGED
|
@@ -426,7 +426,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
426
426
|
var DECISION_LABEL_JOIN = " | ";
|
|
427
427
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
428
428
|
var RELEASE_BRANCH = "release";
|
|
429
|
-
var BUNDLE_SHA = true ? "
|
|
429
|
+
var BUNDLE_SHA = true ? "1ce32b37e98bfffd69edcd071b13e1e2d43a0ae9" : void 0;
|
|
430
430
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
431
431
|
var DOCTOR_LABEL = Object.freeze({
|
|
432
432
|
D1: "version",
|
|
@@ -743,6 +743,11 @@ var V1_CACHE_HEAL_NAME = "context-mode-cache-heal";
|
|
|
743
743
|
var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
|
|
744
744
|
var V1_STATUSLINE_COMMAND = "context-mode statusline";
|
|
745
745
|
var V1_PI_PACKAGE = "npm:context-mode";
|
|
746
|
+
var PI_NPM_DIR = "npm";
|
|
747
|
+
var PI_NODE_MODULES_DIR = "node_modules";
|
|
748
|
+
var PI_PACKAGE_JSON_FILE = "package.json";
|
|
749
|
+
var PI_LIST_COMMAND = "pi list";
|
|
750
|
+
var PI_CURRENT_MAJOR = 2;
|
|
746
751
|
var V1_OPENCODE_PLUGIN_SPEC = "context-mode";
|
|
747
752
|
var V1_TMP_PREFIX = "context-mode-";
|
|
748
753
|
var V1_TOML_SECTION_ROOT = "mcp_servers";
|
|
@@ -1658,7 +1663,7 @@ var PI_EVENTS = {
|
|
|
1658
1663
|
tool_call: { event: "PreToolUse" },
|
|
1659
1664
|
tool_result: { event: "PostToolUse" }
|
|
1660
1665
|
};
|
|
1661
|
-
var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read" };
|
|
1666
|
+
var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
|
|
1662
1667
|
function record(v) {
|
|
1663
1668
|
return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
|
|
1664
1669
|
}
|
|
@@ -1928,8 +1933,9 @@ var ADAPTERS = Object.freeze([
|
|
|
1928
1933
|
installMode: "in-process",
|
|
1929
1934
|
projectSource: "pi:ctx.cwd",
|
|
1930
1935
|
toolNamePrefix: TOOL_NAME_PREFIX9,
|
|
1931
|
-
nativeTools: { shell: ["bash"], read: ["read"] },
|
|
1936
|
+
nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
|
|
1932
1937
|
execReadOnlyHint: false,
|
|
1938
|
+
// D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
|
|
1933
1939
|
eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
|
|
1934
1940
|
compactDelivery: "pi-flag",
|
|
1935
1941
|
compactSummary: "none",
|
|
@@ -3328,21 +3334,21 @@ function kiroDirOf(env, home, platform = process.platform) {
|
|
|
3328
3334
|
if (dir === void 0 || dir === "" || !p.isAbsolute(dir)) return fallback;
|
|
3329
3335
|
if (platform === "win32" && p.parse(dir).root.length < 2) return fallback;
|
|
3330
3336
|
const abs = p.resolve(dir);
|
|
3331
|
-
const
|
|
3332
|
-
const target =
|
|
3337
|
+
const real3 = platform === process.platform ? realOrSelf : (x) => x;
|
|
3338
|
+
const target = real3(abs);
|
|
3333
3339
|
if (p.parse(target).root === target) return fallback;
|
|
3334
|
-
const up = p.relative(target,
|
|
3340
|
+
const up = p.relative(target, real3(p.resolve(home)));
|
|
3335
3341
|
if (!p.isAbsolute(up) && up.split(p.sep)[0] !== "..") return fallback;
|
|
3336
3342
|
return abs;
|
|
3337
3343
|
}
|
|
3338
|
-
function realOrSelf(
|
|
3344
|
+
function realOrSelf(path8) {
|
|
3339
3345
|
const tail = [];
|
|
3340
|
-
for (let at2 =
|
|
3346
|
+
for (let at2 = path8; ; ) {
|
|
3341
3347
|
try {
|
|
3342
3348
|
return join(realpathSync.native(at2), ...tail.reverse());
|
|
3343
3349
|
} catch {
|
|
3344
3350
|
const up = dirname(at2);
|
|
3345
|
-
if (up === at2) return
|
|
3351
|
+
if (up === at2) return path8;
|
|
3346
3352
|
tail.push(basename(at2));
|
|
3347
3353
|
at2 = up;
|
|
3348
3354
|
}
|
|
@@ -3467,10 +3473,10 @@ function readPluginAgent(claudeDir, type) {
|
|
|
3467
3473
|
}
|
|
3468
3474
|
return null;
|
|
3469
3475
|
}
|
|
3470
|
-
function readAgentFile(
|
|
3476
|
+
function readAgentFile(path8) {
|
|
3471
3477
|
let text;
|
|
3472
3478
|
try {
|
|
3473
|
-
text = readFileSync(
|
|
3479
|
+
text = readFileSync(path8, "utf8");
|
|
3474
3480
|
} catch {
|
|
3475
3481
|
return null;
|
|
3476
3482
|
}
|
|
@@ -3733,12 +3739,12 @@ function readUserDeny(projectDir, agent) {
|
|
|
3733
3739
|
}
|
|
3734
3740
|
return out;
|
|
3735
3741
|
}
|
|
3736
|
-
function tokenize(glob,
|
|
3742
|
+
function tokenize(glob, path8) {
|
|
3737
3743
|
const toks = [];
|
|
3738
3744
|
let i = 0;
|
|
3739
3745
|
while (i < glob.length) {
|
|
3740
3746
|
const c = glob[i];
|
|
3741
|
-
if (c === "*" &&
|
|
3747
|
+
if (c === "*" && path8 && glob[i + 1] === "*") {
|
|
3742
3748
|
const dir = glob[i + "**".length] === "/";
|
|
3743
3749
|
toks.push({ t: dir ? "globstarDir" : "globstar" });
|
|
3744
3750
|
i += dir ? "**/".length : "**".length;
|
|
@@ -3752,8 +3758,8 @@ function tokenize(glob, path7) {
|
|
|
3752
3758
|
}
|
|
3753
3759
|
return toks;
|
|
3754
3760
|
}
|
|
3755
|
-
function globMatch(glob, text,
|
|
3756
|
-
const toks = tokenize(glob,
|
|
3761
|
+
function globMatch(glob, text, path8) {
|
|
3762
|
+
const toks = tokenize(glob, path8);
|
|
3757
3763
|
const n = text.length;
|
|
3758
3764
|
let next = new Uint8Array(n + 1);
|
|
3759
3765
|
next[n] = 1;
|
|
@@ -3769,10 +3775,10 @@ function globMatch(glob, text, path7) {
|
|
|
3769
3775
|
cur[j] = has3 && ch === tok.c ? next[j + 1] : 0;
|
|
3770
3776
|
break;
|
|
3771
3777
|
case "any1":
|
|
3772
|
-
cur[j] = has3 && !(
|
|
3778
|
+
cur[j] = has3 && !(path8 && ch === "/") ? next[j + 1] : 0;
|
|
3773
3779
|
break;
|
|
3774
3780
|
case "star":
|
|
3775
|
-
cur[j] = next[j] || (has3 && !(
|
|
3781
|
+
cur[j] = next[j] || (has3 && !(path8 && ch === "/") ? cur[j + 1] : 0);
|
|
3776
3782
|
break;
|
|
3777
3783
|
case "globstar":
|
|
3778
3784
|
cur[j] = next[j] || (has3 ? cur[j + 1] : 0);
|
|
@@ -3852,8 +3858,8 @@ var READ_DENY_TEMPLATE = 'context-mode: {size}-byte file, over the one-read limi
|
|
|
3852
3858
|
// src/core/policy/read-deny.ts
|
|
3853
3859
|
var SIZE = "{size}";
|
|
3854
3860
|
var PATH = "{path}";
|
|
3855
|
-
function READ_DENY_MESSAGE(
|
|
3856
|
-
return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(
|
|
3861
|
+
function READ_DENY_MESSAGE(path8, size, prefix = "") {
|
|
3862
|
+
return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path8);
|
|
3857
3863
|
}
|
|
3858
3864
|
|
|
3859
3865
|
// src/core/policy/decide.ts
|
|
@@ -4561,9 +4567,9 @@ function readUserVersion(raw) {
|
|
|
4561
4567
|
const row5 = raw.prepare("PRAGMA user_version").get();
|
|
4562
4568
|
return row5.user_version;
|
|
4563
4569
|
}
|
|
4564
|
-
function createAtomically(sqlite,
|
|
4570
|
+
function createAtomically(sqlite, path8) {
|
|
4565
4571
|
const { randomUUID } = process.getBuiltinModule("node:crypto");
|
|
4566
|
-
const tmp =
|
|
4572
|
+
const tmp = path8 + "." + randomUUID() + DB_TMP_SUFFIX;
|
|
4567
4573
|
try {
|
|
4568
4574
|
const raw = new sqlite.DatabaseSync(tmp, { timeout: DB_TIMEOUT_MS });
|
|
4569
4575
|
try {
|
|
@@ -4572,7 +4578,7 @@ function createAtomically(sqlite, path7) {
|
|
|
4572
4578
|
raw.close();
|
|
4573
4579
|
}
|
|
4574
4580
|
try {
|
|
4575
|
-
linkSync(tmp,
|
|
4581
|
+
linkSync(tmp, path8);
|
|
4576
4582
|
} catch (err) {
|
|
4577
4583
|
if (err.code !== "EEXIST") throw err;
|
|
4578
4584
|
}
|
|
@@ -4580,11 +4586,11 @@ function createAtomically(sqlite, path7) {
|
|
|
4580
4586
|
for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
|
|
4581
4587
|
}
|
|
4582
4588
|
}
|
|
4583
|
-
function openWritable(sqlite,
|
|
4589
|
+
function openWritable(sqlite, path8) {
|
|
4584
4590
|
let raw = null;
|
|
4585
4591
|
try {
|
|
4586
|
-
if (!existsSync2(
|
|
4587
|
-
raw = new sqlite.DatabaseSync(
|
|
4592
|
+
if (!existsSync2(path8)) createAtomically(sqlite, path8);
|
|
4593
|
+
raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS });
|
|
4588
4594
|
applyMigrations(raw, readUserVersion(raw));
|
|
4589
4595
|
return raw;
|
|
4590
4596
|
} catch (err) {
|
|
@@ -4592,8 +4598,8 @@ function openWritable(sqlite, path7) {
|
|
|
4592
4598
|
throw err;
|
|
4593
4599
|
}
|
|
4594
4600
|
}
|
|
4595
|
-
function openReadOnly(sqlite,
|
|
4596
|
-
const raw = new sqlite.DatabaseSync(
|
|
4601
|
+
function openReadOnly(sqlite, path8) {
|
|
4602
|
+
const raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
|
|
4597
4603
|
try {
|
|
4598
4604
|
const found = readUserVersion(raw);
|
|
4599
4605
|
if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
|
|
@@ -4607,20 +4613,20 @@ async function openDb(project, opts) {
|
|
|
4607
4613
|
if (isBelow(process.version, NODE_MIN)) throw new CtxError("NODE_TOO_OLD", { v: process.version });
|
|
4608
4614
|
const sqlite = await loadSqlite();
|
|
4609
4615
|
mkdirSync2(project.projectDir, { recursive: true });
|
|
4610
|
-
const
|
|
4611
|
-
const sibling = existsSync2(
|
|
4612
|
-
if (sibling && !existsSync2(
|
|
4616
|
+
const path8 = project.dbPath;
|
|
4617
|
+
const sibling = existsSync2(path8 + DB_WAL_SUFFIX) || existsSync2(path8 + DB_SHM_SUFFIX);
|
|
4618
|
+
if (sibling && !existsSync2(path8)) {
|
|
4613
4619
|
throw new CtxError("DB_GONE");
|
|
4614
4620
|
}
|
|
4615
4621
|
try {
|
|
4616
4622
|
let raw;
|
|
4617
4623
|
if (opts?.readOnly === true) {
|
|
4618
|
-
if (!existsSync2(
|
|
4619
|
-
raw = openReadOnly(sqlite,
|
|
4624
|
+
if (!existsSync2(path8)) openWritable(sqlite, path8).close();
|
|
4625
|
+
raw = openReadOnly(sqlite, path8);
|
|
4620
4626
|
} else {
|
|
4621
|
-
raw = openWritable(sqlite,
|
|
4627
|
+
raw = openWritable(sqlite, path8);
|
|
4622
4628
|
}
|
|
4623
|
-
return { raw, projectKey: project.projectKey, path:
|
|
4629
|
+
return { raw, projectKey: project.projectKey, path: path8, ...opts?.readOnly === true ? { readOnly: true } : {} };
|
|
4624
4630
|
} catch (err) {
|
|
4625
4631
|
if (isCorrupt(err)) throw new CtxError("DB_CORRUPT");
|
|
4626
4632
|
throw err;
|
|
@@ -7415,8 +7421,8 @@ function buildCandidates(rows, sessionId) {
|
|
|
7415
7421
|
edits.set(r.path, { row: r, count: (edits.get(r.path)?.count ?? 0) + 1 });
|
|
7416
7422
|
}
|
|
7417
7423
|
const changedFiles = [];
|
|
7418
|
-
for (const [
|
|
7419
|
-
const c = make("changed_files", e.row, "edited " +
|
|
7424
|
+
for (const [path8, e] of edits) {
|
|
7425
|
+
const c = make("changed_files", e.row, "edited " + path8 + " x" + e.count, e.count, path8);
|
|
7420
7426
|
changedFiles.push({ ...c, editCount: e.count });
|
|
7421
7427
|
}
|
|
7422
7428
|
changedFiles.sort((a, b) => a.seq - b.seq);
|
|
@@ -8750,9 +8756,13 @@ async function preToolUse(ev, row5, project, env) {
|
|
|
8750
8756
|
const userDeny = readUserDeny(project.worktree, ev.agent);
|
|
8751
8757
|
const decision0 = decide(ev, row5, userDeny);
|
|
8752
8758
|
let decision = decision0;
|
|
8753
|
-
if (decision0.kind === "deny" && isSubagentCall(ev)) {
|
|
8754
|
-
const
|
|
8755
|
-
|
|
8759
|
+
if (decision0.kind === "deny" && isSubagentCall(ev) && !isUserPolicyDeny(decision0.reason, row5)) {
|
|
8760
|
+
const set3 = toolSetForAgentType(ev, { projectDir: project.worktree, env });
|
|
8761
|
+
const subCase = pickSubagentCase(ev, set3);
|
|
8762
|
+
const tool = ev.tool;
|
|
8763
|
+
const runs = set3 !== null || (ev.agentType ?? "") !== "" && hasReplace(row5);
|
|
8764
|
+
if (subCase === "B" && tool !== void 0 && isShell(tool, row5)) decision = caseB(ev, row5, decision0, userDeny);
|
|
8765
|
+
else if (subCase !== "A" && runs) decision = ALLOW2;
|
|
8756
8766
|
}
|
|
8757
8767
|
return decision;
|
|
8758
8768
|
}
|
|
@@ -9614,10 +9624,10 @@ function assignProp(target, prop, value) {
|
|
|
9614
9624
|
configurable: true
|
|
9615
9625
|
});
|
|
9616
9626
|
}
|
|
9617
|
-
function getElementAtPath(obj,
|
|
9618
|
-
if (!
|
|
9627
|
+
function getElementAtPath(obj, path8) {
|
|
9628
|
+
if (!path8)
|
|
9619
9629
|
return obj;
|
|
9620
|
-
return
|
|
9630
|
+
return path8.reduce((acc, key) => acc?.[key], obj);
|
|
9621
9631
|
}
|
|
9622
9632
|
function promiseAllObject(promisesObj) {
|
|
9623
9633
|
const keys = Object.keys(promisesObj);
|
|
@@ -9937,11 +9947,11 @@ function aborted(x, startIndex = 0) {
|
|
|
9937
9947
|
}
|
|
9938
9948
|
return false;
|
|
9939
9949
|
}
|
|
9940
|
-
function prefixIssues(
|
|
9950
|
+
function prefixIssues(path8, issues) {
|
|
9941
9951
|
return issues.map((iss) => {
|
|
9942
9952
|
var _a;
|
|
9943
9953
|
(_a = iss).path ?? (_a.path = []);
|
|
9944
|
-
iss.path.unshift(
|
|
9954
|
+
iss.path.unshift(path8);
|
|
9945
9955
|
return iss;
|
|
9946
9956
|
});
|
|
9947
9957
|
}
|
|
@@ -10078,7 +10088,7 @@ function treeifyError(error40, _mapper) {
|
|
|
10078
10088
|
return issue2.message;
|
|
10079
10089
|
};
|
|
10080
10090
|
const result = { errors: [] };
|
|
10081
|
-
const processError = (error41,
|
|
10091
|
+
const processError = (error41, path8 = []) => {
|
|
10082
10092
|
var _a, _b;
|
|
10083
10093
|
for (const issue2 of error41.issues) {
|
|
10084
10094
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
@@ -10088,7 +10098,7 @@ function treeifyError(error40, _mapper) {
|
|
|
10088
10098
|
} else if (issue2.code === "invalid_element") {
|
|
10089
10099
|
processError({ issues: issue2.issues }, issue2.path);
|
|
10090
10100
|
} else {
|
|
10091
|
-
const fullpath = [...
|
|
10101
|
+
const fullpath = [...path8, ...issue2.path];
|
|
10092
10102
|
if (fullpath.length === 0) {
|
|
10093
10103
|
result.errors.push(mapper(issue2));
|
|
10094
10104
|
continue;
|
|
@@ -10118,9 +10128,9 @@ function treeifyError(error40, _mapper) {
|
|
|
10118
10128
|
processError(error40);
|
|
10119
10129
|
return result;
|
|
10120
10130
|
}
|
|
10121
|
-
function toDotPath(
|
|
10131
|
+
function toDotPath(path8) {
|
|
10122
10132
|
const segs = [];
|
|
10123
|
-
for (const seg of
|
|
10133
|
+
for (const seg of path8) {
|
|
10124
10134
|
if (typeof seg === "number")
|
|
10125
10135
|
segs.push(`[${seg}]`);
|
|
10126
10136
|
else if (typeof seg === "symbol")
|
|
@@ -20338,19 +20348,19 @@ function steeringFiles(worktree) {
|
|
|
20338
20348
|
function readAutoMemory(project) {
|
|
20339
20349
|
const rows = [];
|
|
20340
20350
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
20341
|
-
const
|
|
20342
|
-
if (!isInside(project.worktree,
|
|
20351
|
+
const path8 = join7(project.worktree, ...segs);
|
|
20352
|
+
if (!isInside(project.worktree, path8)) continue;
|
|
20343
20353
|
try {
|
|
20344
|
-
const st = statSync4(
|
|
20354
|
+
const st = statSync4(path8);
|
|
20345
20355
|
if (!st.isFile()) continue;
|
|
20346
20356
|
rows.push({
|
|
20347
20357
|
origin: "memory",
|
|
20348
20358
|
ts: Math.trunc(st.mtimeMs),
|
|
20349
20359
|
seq: null,
|
|
20350
20360
|
sourceId: null,
|
|
20351
|
-
path:
|
|
20361
|
+
path: path8,
|
|
20352
20362
|
label: segs.join("/"),
|
|
20353
|
-
text: readFileSync5(
|
|
20363
|
+
text: readFileSync5(path8, "utf8")
|
|
20354
20364
|
});
|
|
20355
20365
|
} catch {
|
|
20356
20366
|
}
|
|
@@ -20920,7 +20930,7 @@ var ctxBatch = Object.freeze({
|
|
|
20920
20930
|
});
|
|
20921
20931
|
|
|
20922
20932
|
// src/core/tools/doctor.ts
|
|
20923
|
-
import { readdirSync as readdirSync6, readFileSync as
|
|
20933
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync14, existsSync as existsSync15 } from "node:fs";
|
|
20924
20934
|
import { basename as basename5, join as join17 } from "node:path";
|
|
20925
20935
|
|
|
20926
20936
|
// src/core/ops/bundle-dir.ts
|
|
@@ -20946,7 +20956,7 @@ function ownBundleDir() {
|
|
|
20946
20956
|
}
|
|
20947
20957
|
|
|
20948
20958
|
// src/core/ops/doctor-config.ts
|
|
20949
|
-
import { existsSync as
|
|
20959
|
+
import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
|
|
20950
20960
|
import { join as join12 } from "node:path";
|
|
20951
20961
|
|
|
20952
20962
|
// src/core/ops/detect-v1.ts
|
|
@@ -23065,15 +23075,15 @@ function atomicWriteFile(file2, text, opts = {}) {
|
|
|
23065
23075
|
}
|
|
23066
23076
|
|
|
23067
23077
|
// src/core/ops/host-config.ts
|
|
23068
|
-
function formatOf(
|
|
23069
|
-
if (
|
|
23070
|
-
if (
|
|
23078
|
+
function formatOf(path8) {
|
|
23079
|
+
if (path8.endsWith(JSONC_EXT)) return "jsonc";
|
|
23080
|
+
if (path8.endsWith(TOML_EXT)) return "toml";
|
|
23071
23081
|
return "json";
|
|
23072
23082
|
}
|
|
23073
|
-
function readHostConfig(agent,
|
|
23074
|
-
let file2 =
|
|
23083
|
+
function readHostConfig(agent, path8) {
|
|
23084
|
+
let file2 = path8;
|
|
23075
23085
|
if (agent === "opencode") {
|
|
23076
|
-
const jsonc = join9(dirname6(
|
|
23086
|
+
const jsonc = join9(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
|
|
23077
23087
|
if (existsSync4(jsonc)) file2 = jsonc;
|
|
23078
23088
|
}
|
|
23079
23089
|
const raw = existsSync4(file2) ? readFileSync6(file2, "utf8") : "";
|
|
@@ -23237,14 +23247,14 @@ function scanToml(text) {
|
|
|
23237
23247
|
continue;
|
|
23238
23248
|
}
|
|
23239
23249
|
if (!node.resolvedKey.every((seg) => typeof seg === "string")) continue;
|
|
23240
|
-
const
|
|
23241
|
-
for (const kv of node.body) addKey(
|
|
23250
|
+
const path8 = node.resolvedKey;
|
|
23251
|
+
for (const kv of node.body) addKey(path8, kv);
|
|
23242
23252
|
if (node.kind !== "standard") continue;
|
|
23243
23253
|
const start = lineStartOf(text, node.range[0]);
|
|
23244
23254
|
const headEnd = lineEndOf(text, node.key.range[1]);
|
|
23245
23255
|
const last2 = node.body[node.body.length - 1];
|
|
23246
23256
|
tables.push({
|
|
23247
|
-
path:
|
|
23257
|
+
path: path8,
|
|
23248
23258
|
header: text.slice(start, text[headEnd - 1] === "\n" ? headEnd - 1 : headEnd),
|
|
23249
23259
|
start,
|
|
23250
23260
|
end: last2 === void 0 ? headEnd : lineEndOf(text, last2.range[1])
|
|
@@ -23255,16 +23265,16 @@ function scanToml(text) {
|
|
|
23255
23265
|
function tomlTableSpans(text) {
|
|
23256
23266
|
return scanToml(text).tables;
|
|
23257
23267
|
}
|
|
23258
|
-
function parseHostConfig(agent,
|
|
23268
|
+
function parseHostConfig(agent, path8, text, format) {
|
|
23259
23269
|
try {
|
|
23260
23270
|
return format === "toml" ? scanToml(text).value : scanJson(text, format).value;
|
|
23261
23271
|
} catch {
|
|
23262
|
-
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path:
|
|
23272
|
+
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path8, format });
|
|
23263
23273
|
}
|
|
23264
23274
|
}
|
|
23265
|
-
function hostConfigValueAt(value,
|
|
23275
|
+
function hostConfigValueAt(value, path8) {
|
|
23266
23276
|
let cur = value;
|
|
23267
|
-
for (const seg of
|
|
23277
|
+
for (const seg of path8) {
|
|
23268
23278
|
if (!isPlainObject3(cur)) return void 0;
|
|
23269
23279
|
cur = cur[seg];
|
|
23270
23280
|
}
|
|
@@ -23297,32 +23307,32 @@ function indentUnit(root, clean) {
|
|
|
23297
23307
|
function render(value, unit, base) {
|
|
23298
23308
|
return JSON.stringify(value, null, unit).split("\n").join("\n" + base);
|
|
23299
23309
|
}
|
|
23300
|
-
function nest(
|
|
23310
|
+
function nest(path8, value) {
|
|
23301
23311
|
let out = value;
|
|
23302
|
-
for (let k =
|
|
23312
|
+
for (let k = path8.length - 1; k >= 0; k -= 1) out = { [path8[k]]: out };
|
|
23303
23313
|
return out;
|
|
23304
23314
|
}
|
|
23305
|
-
function setJsonText(text, format,
|
|
23315
|
+
function setJsonText(text, format, path8, value) {
|
|
23306
23316
|
const doc = scanJson(text, format);
|
|
23307
23317
|
const unit = indentUnit(doc.root, doc.clean);
|
|
23308
|
-
if (doc.root === null) return render(nest(
|
|
23318
|
+
if (doc.root === null) return render(nest(path8, value), unit, "") + "\n";
|
|
23309
23319
|
let node = doc.root;
|
|
23310
23320
|
let depth = 0;
|
|
23311
|
-
while (depth <
|
|
23312
|
-
const hit = node.members.find((m) => m.key ===
|
|
23321
|
+
while (depth < path8.length && node.kind === "object") {
|
|
23322
|
+
const hit = node.members.find((m) => m.key === path8[depth]);
|
|
23313
23323
|
if (hit === void 0) break;
|
|
23314
23324
|
node = hit.node;
|
|
23315
23325
|
depth += 1;
|
|
23316
23326
|
}
|
|
23317
|
-
if (depth ===
|
|
23327
|
+
if (depth === path8.length) {
|
|
23318
23328
|
return text.slice(0, node.start) + render(value, unit, lineIndent(doc.clean, node.start)) + text.slice(node.end);
|
|
23319
23329
|
}
|
|
23320
|
-
if (node.kind !== "object") throw new SyntaxError("not an object at " +
|
|
23321
|
-
const rest = nest(
|
|
23330
|
+
if (node.kind !== "object") throw new SyntaxError("not an object at " + path8.slice(0, depth).join("."));
|
|
23331
|
+
const rest = nest(path8.slice(depth + 1), value);
|
|
23322
23332
|
const last2 = node.members[node.members.length - 1];
|
|
23323
23333
|
if (last2 === void 0) {
|
|
23324
23334
|
const base2 = lineIndent(doc.clean, node.start);
|
|
23325
|
-
const member2 = "\n" + base2 + unit + JSON.stringify(
|
|
23335
|
+
const member2 = "\n" + base2 + unit + JSON.stringify(path8[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
|
|
23326
23336
|
return text.slice(0, node.start + 1) + member2 + text.slice(node.end - 1);
|
|
23327
23337
|
}
|
|
23328
23338
|
const base = lineIndent(doc.clean, last2.keyStart);
|
|
@@ -23330,7 +23340,7 @@ function setJsonText(text, format, path7, value) {
|
|
|
23330
23340
|
while (" \r\n".includes(doc.clean[at2])) at2 += 1;
|
|
23331
23341
|
const trailing = doc.clean[at2] === ",";
|
|
23332
23342
|
const insertAt = trailing ? at2 + 1 : last2.node.end;
|
|
23333
|
-
const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(
|
|
23343
|
+
const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path8[depth]) + ": " + render(rest, unit, base);
|
|
23334
23344
|
return text.slice(0, insertAt) + member + text.slice(insertAt);
|
|
23335
23345
|
}
|
|
23336
23346
|
function tomlScalar(v) {
|
|
@@ -23348,17 +23358,17 @@ function tomlHeaderKey(seg) {
|
|
|
23348
23358
|
}
|
|
23349
23359
|
return seg;
|
|
23350
23360
|
}
|
|
23351
|
-
function tomlBlock(
|
|
23352
|
-
let out = "[" +
|
|
23361
|
+
function tomlBlock(path8, value) {
|
|
23362
|
+
let out = "[" + path8.map(tomlHeaderKey).join(".") + "]\n";
|
|
23353
23363
|
const subs = [];
|
|
23354
23364
|
for (const [k, v] of Object.entries(value)) {
|
|
23355
|
-
if (isPlainObject3(v)) subs.push(tomlBlock([...
|
|
23365
|
+
if (isPlainObject3(v)) subs.push(tomlBlock([...path8, k], v));
|
|
23356
23366
|
else out += tomlHeaderKey(k) + " = " + tomlScalar(v) + "\n";
|
|
23357
23367
|
}
|
|
23358
23368
|
return [out, ...subs].join("\n");
|
|
23359
23369
|
}
|
|
23360
|
-
function under(
|
|
23361
|
-
return
|
|
23370
|
+
function under(path8, prefix) {
|
|
23371
|
+
return path8.length >= prefix.length && prefix.every((seg, k) => path8[k] === seg);
|
|
23362
23372
|
}
|
|
23363
23373
|
function keyLineRange(text, k) {
|
|
23364
23374
|
const ls = lineStartOf(text, k.start);
|
|
@@ -23375,10 +23385,10 @@ function withValueAt(root, rel, value) {
|
|
|
23375
23385
|
else base[rel[0]] = next;
|
|
23376
23386
|
return base;
|
|
23377
23387
|
}
|
|
23378
|
-
function replaceToml(text, doc,
|
|
23379
|
-
const block = value === void 0 ? "" : tomlBlock(
|
|
23380
|
-
const owned = doc.tables.filter((t) => under(t.path,
|
|
23381
|
-
const cuts = doc.keys.filter((k) => under(k.full,
|
|
23388
|
+
function replaceToml(text, doc, path8, value) {
|
|
23389
|
+
const block = value === void 0 ? "" : tomlBlock(path8, value);
|
|
23390
|
+
const owned = doc.tables.filter((t) => under(t.path, path8));
|
|
23391
|
+
const cuts = doc.keys.filter((k) => under(k.full, path8) && !under(k.base, path8)).map((k) => [...keyLineRange(text, k), ""]);
|
|
23382
23392
|
owned.forEach((t, n) => cuts.push([t.start, t.end, n === 0 ? block : ""]));
|
|
23383
23393
|
cuts.sort((a, b) => b[0] - a[0]);
|
|
23384
23394
|
let out = text;
|
|
@@ -23388,27 +23398,27 @@ function replaceToml(text, doc, path7, value) {
|
|
|
23388
23398
|
return out + sep4 + block;
|
|
23389
23399
|
}
|
|
23390
23400
|
var tableLike = (v) => v === void 0 || isPlainObject3(v);
|
|
23391
|
-
function setTomlText(text,
|
|
23401
|
+
function setTomlText(text, path8, value) {
|
|
23392
23402
|
if (value !== void 0 && !isPlainObject3(value)) throw new SyntaxError("TOML edits replace a whole table");
|
|
23393
23403
|
const doc = scanToml(text);
|
|
23394
|
-
const cur = hostConfigValueAt(doc.value,
|
|
23404
|
+
const cur = hostConfigValueAt(doc.value, path8);
|
|
23395
23405
|
if (sameValue(cur, value)) return text;
|
|
23396
|
-
const inline = doc.keys.find((k) => k.inline && k.full.length <
|
|
23406
|
+
const inline = doc.keys.find((k) => k.inline && k.full.length < path8.length && under(path8, k.full));
|
|
23397
23407
|
if (inline !== void 0) {
|
|
23398
|
-
const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full),
|
|
23408
|
+
const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path8.slice(inline.full.length), value);
|
|
23399
23409
|
return replaceToml(text, doc, inline.full, whole2);
|
|
23400
23410
|
}
|
|
23401
23411
|
if (isPlainObject3(cur) && isPlainObject3(value)) {
|
|
23402
23412
|
const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
|
|
23403
23413
|
if (names.every((k) => tableLike(cur[k]) && tableLike(value[k]))) {
|
|
23404
23414
|
let out = text;
|
|
23405
|
-
for (const k of names) out = setTomlText(out, [...
|
|
23415
|
+
for (const k of names) out = setTomlText(out, [...path8, k], value[k]);
|
|
23406
23416
|
return out;
|
|
23407
23417
|
}
|
|
23408
23418
|
}
|
|
23409
|
-
return replaceToml(text, doc,
|
|
23419
|
+
return replaceToml(text, doc, path8, value);
|
|
23410
23420
|
}
|
|
23411
|
-
function setText(agent,
|
|
23421
|
+
function setText(agent, path8, text, format, key, value) {
|
|
23412
23422
|
try {
|
|
23413
23423
|
if (format !== "toml") return setJsonText(text, format, key, value);
|
|
23414
23424
|
const out = setTomlText(text, key, value);
|
|
@@ -23417,7 +23427,7 @@ function setText(agent, path7, text, format, key, value) {
|
|
|
23417
23427
|
if (!sameValue(landed, value) && !(emptyTable && landed === void 0)) throw new SyntaxError("edit did not land");
|
|
23418
23428
|
return out;
|
|
23419
23429
|
} catch {
|
|
23420
|
-
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path:
|
|
23430
|
+
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path8, format });
|
|
23421
23431
|
}
|
|
23422
23432
|
}
|
|
23423
23433
|
function serverScript() {
|
|
@@ -23464,14 +23474,14 @@ function ownTargets(agent, accept) {
|
|
|
23464
23474
|
if (agent === "pi") return [listTarget(PI_PACKAGES_KEY, PI_GIT_PACKAGE, V1_PI_PACKAGE)];
|
|
23465
23475
|
return [];
|
|
23466
23476
|
}
|
|
23467
|
-
function applyEdits(agent,
|
|
23468
|
-
const parsed = parseHostConfig(agent,
|
|
23477
|
+
function applyEdits(agent, path8, text, format, wanted) {
|
|
23478
|
+
const parsed = parseHostConfig(agent, path8, text, format);
|
|
23469
23479
|
let out = text;
|
|
23470
23480
|
const edits = [];
|
|
23471
23481
|
for (const [key, after] of wanted) {
|
|
23472
23482
|
const before = hostConfigValueAt(parsed, key);
|
|
23473
23483
|
if (sameValue(before, after)) continue;
|
|
23474
|
-
out = setText(agent,
|
|
23484
|
+
out = setText(agent, path8, out, format, key, after);
|
|
23475
23485
|
edits.push({ path: key.join("."), before, after });
|
|
23476
23486
|
}
|
|
23477
23487
|
return { text: out, format, edits };
|
|
@@ -23492,7 +23502,7 @@ function writeHostConfigEdit(_requested, current, patch) {
|
|
|
23492
23502
|
// src/core/ops/detect-v1.ts
|
|
23493
23503
|
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
23494
23504
|
var keyPath = (...parts) => parts.join(".");
|
|
23495
|
-
var finding = (file2,
|
|
23505
|
+
var finding = (file2, path8, reason) => ({ file: file2, path: path8, reason });
|
|
23496
23506
|
function stripJsonc(text) {
|
|
23497
23507
|
let out = "";
|
|
23498
23508
|
let inStr = false;
|
|
@@ -23697,12 +23707,17 @@ function scanKiro(agentHome, project, out) {
|
|
|
23697
23707
|
}
|
|
23698
23708
|
dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23699
23709
|
}
|
|
23710
|
+
function piNpmIsCurrent(piAgentDir) {
|
|
23711
|
+
const doc = readJson(join10(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
23712
|
+
const version2 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
23713
|
+
return Number.parseInt(version2, 10) >= PI_CURRENT_MAJOR;
|
|
23714
|
+
}
|
|
23700
23715
|
function scanPi(piAgentDir, agentHome, out) {
|
|
23701
23716
|
const file2 = join10(piAgentDir, SETTINGS_FILE);
|
|
23702
23717
|
const doc = readJson(file2);
|
|
23703
23718
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
23704
23719
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
23705
|
-
if (spec === V1_PI_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
23720
|
+
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
23706
23721
|
});
|
|
23707
23722
|
dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23708
23723
|
}
|
|
@@ -23799,8 +23814,8 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23799
23814
|
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
|
|
23800
23815
|
import { dirname as dirname7, isAbsolute as isAbsolute2, join as join11, sep as sep3 } from "node:path";
|
|
23801
23816
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
23802
|
-
function missing(agent,
|
|
23803
|
-
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path:
|
|
23817
|
+
function missing(agent, path8) {
|
|
23818
|
+
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
23804
23819
|
}
|
|
23805
23820
|
var parseOrNull = (text) => {
|
|
23806
23821
|
try {
|
|
@@ -23829,9 +23844,9 @@ function recordedInstalls(text) {
|
|
|
23829
23844
|
}
|
|
23830
23845
|
return out;
|
|
23831
23846
|
}
|
|
23832
|
-
var realOrNull = (
|
|
23847
|
+
var realOrNull = (path8) => {
|
|
23833
23848
|
try {
|
|
23834
|
-
return realpathSync4.native(
|
|
23849
|
+
return realpathSync4.native(path8);
|
|
23835
23850
|
} catch {
|
|
23836
23851
|
return null;
|
|
23837
23852
|
}
|
|
@@ -23929,14 +23944,83 @@ function candidate(adapter, env, worktree) {
|
|
|
23929
23944
|
}
|
|
23930
23945
|
}
|
|
23931
23946
|
function resolvePluginRoot(adapter, env, worktree) {
|
|
23932
|
-
const
|
|
23947
|
+
const path8 = candidate(adapter, env, worktree);
|
|
23933
23948
|
try {
|
|
23934
|
-
return realpathSync4.native(
|
|
23949
|
+
return realpathSync4.native(path8);
|
|
23935
23950
|
} catch {
|
|
23936
|
-
throw missing(adapter.id,
|
|
23951
|
+
throw missing(adapter.id, path8);
|
|
23937
23952
|
}
|
|
23938
23953
|
}
|
|
23939
23954
|
|
|
23955
|
+
// src/setup/pi-gate.ts
|
|
23956
|
+
import { existsSync as existsSync7, readFileSync as readFileSync9, realpathSync as realpathSync5 } from "node:fs";
|
|
23957
|
+
import path4 from "node:path";
|
|
23958
|
+
var EXTENSIONS_KEY = "extensions";
|
|
23959
|
+
var PROJECT_DIR = ".pi";
|
|
23960
|
+
var TRUST_FILE = "trust.json";
|
|
23961
|
+
var ALWAYS = "always";
|
|
23962
|
+
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
23963
|
+
function load(file2) {
|
|
23964
|
+
if (!existsSync7(file2)) return void 0;
|
|
23965
|
+
try {
|
|
23966
|
+
return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync9(file2, "utf8")), "json") };
|
|
23967
|
+
} catch {
|
|
23968
|
+
return void 0;
|
|
23969
|
+
}
|
|
23970
|
+
}
|
|
23971
|
+
var real2 = (p) => {
|
|
23972
|
+
try {
|
|
23973
|
+
return realpathSync5(p);
|
|
23974
|
+
} catch {
|
|
23975
|
+
return path4.resolve(p);
|
|
23976
|
+
}
|
|
23977
|
+
};
|
|
23978
|
+
function sourceName(source) {
|
|
23979
|
+
let s = source;
|
|
23980
|
+
for (const p of SOURCE_PREFIXES) if (s.startsWith(p)) s = s.slice(p.length);
|
|
23981
|
+
const last2 = s.split("/").pop() ?? "";
|
|
23982
|
+
const at2 = last2.indexOf("@", 1);
|
|
23983
|
+
const name = at2 > 0 ? last2.slice(0, at2) : last2;
|
|
23984
|
+
return name.endsWith(".git") ? name.slice(0, -4) : name;
|
|
23985
|
+
}
|
|
23986
|
+
function isOwn(source, pkgDir) {
|
|
23987
|
+
if (typeof source !== "string") return false;
|
|
23988
|
+
return real2(source) === real2(pkgDir) || sourceName(source) === SERVER_KEY;
|
|
23989
|
+
}
|
|
23990
|
+
function ownEntries(src, pkgDir) {
|
|
23991
|
+
const list4 = hostConfigValueAt(src.doc, [PI_PACKAGES_KEY]);
|
|
23992
|
+
if (!Array.isArray(list4)) return [];
|
|
23993
|
+
const out = [];
|
|
23994
|
+
for (const e of list4) {
|
|
23995
|
+
const obj = typeof e === "object" && e !== null && !Array.isArray(e) ? e : void 0;
|
|
23996
|
+
if (!isOwn(obj ? obj[PI_PACKAGE_SOURCE_KEY] : e, pkgDir)) continue;
|
|
23997
|
+
const ext = obj?.[EXTENSIONS_KEY];
|
|
23998
|
+
out.push({ source: src, patterns: Array.isArray(ext) ? ext.filter((x) => typeof x === "string") : void 0 });
|
|
23999
|
+
}
|
|
24000
|
+
return out;
|
|
24001
|
+
}
|
|
24002
|
+
function projectTrusted(agentDir, userDoc, cwd) {
|
|
24003
|
+
const trust = load(path4.join(agentDir, TRUST_FILE));
|
|
24004
|
+
const entries = /* @__PURE__ */ new Map();
|
|
24005
|
+
if (trust && typeof trust.doc === "object" && trust.doc !== null) for (const [k, v] of Object.entries(trust.doc)) entries.set(real2(k), v);
|
|
24006
|
+
let dir = real2(cwd);
|
|
24007
|
+
for (; ; ) {
|
|
24008
|
+
const v = entries.get(dir);
|
|
24009
|
+
if (v === true || v === false) return v;
|
|
24010
|
+
const up = path4.dirname(dir);
|
|
24011
|
+
if (up === dir) break;
|
|
24012
|
+
dir = up;
|
|
24013
|
+
}
|
|
24014
|
+
return hostConfigValueAt(userDoc, ["defaultProjectTrust"]) === ALWAYS;
|
|
24015
|
+
}
|
|
24016
|
+
function piInstalledIn(env, home, pkgDir, cwd) {
|
|
24017
|
+
const agentDir = piAgentDirOf(env, home);
|
|
24018
|
+
const user = load(path4.join(agentDir, SETTINGS_FILE));
|
|
24019
|
+
const project = load(path4.join(cwd, PROJECT_DIR, SETTINGS_FILE));
|
|
24020
|
+
if (project && projectTrusted(agentDir, user?.doc, cwd) && ownEntries(project, pkgDir).length > 0) return project.file;
|
|
24021
|
+
return user && ownEntries(user, pkgDir).length > 0 ? user.file : void 0;
|
|
24022
|
+
}
|
|
24023
|
+
|
|
23940
24024
|
// src/core/ops/doctor-config.ts
|
|
23941
24025
|
var [PART_MCP, PART_HOOKS, PART_TIMEOUT] = D3_PARTS;
|
|
23942
24026
|
var isObject4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -24037,14 +24121,14 @@ function codexNativeDir(env, home) {
|
|
|
24037
24121
|
}
|
|
24038
24122
|
if (enabled !== true) return null;
|
|
24039
24123
|
const cache = join12(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
24040
|
-
if (!
|
|
24124
|
+
if (!existsSync8(cache)) return null;
|
|
24041
24125
|
const found = [];
|
|
24042
24126
|
for (const market of readdirSync4(cache)) {
|
|
24043
24127
|
const plugin = join12(cache, market, SERVER_KEY);
|
|
24044
|
-
if (!
|
|
24128
|
+
if (!existsSync8(plugin)) continue;
|
|
24045
24129
|
for (const version2 of readdirSync4(plugin).sort()) {
|
|
24046
24130
|
const dir = join12(plugin, version2, CODEX_PLUGIN_SUBDIR);
|
|
24047
|
-
if (
|
|
24131
|
+
if (existsSync8(join12(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
24048
24132
|
}
|
|
24049
24133
|
}
|
|
24050
24134
|
return found.length === 0 ? null : found[found.length - 1];
|
|
@@ -24135,12 +24219,17 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
24135
24219
|
const choice = marketplaceChoice(env, worktree);
|
|
24136
24220
|
if ("installs" in choice) return fail2("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
|
|
24137
24221
|
}
|
|
24222
|
+
if (row5.id === "pi") return checkPiInstall(env, home, worktree);
|
|
24138
24223
|
const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
|
|
24139
|
-
|
|
24140
|
-
if (parts.length === 0) return read3 === null ? pass("D3") : { ...pass("D3"), detail: read3 };
|
|
24224
|
+
if (parts.length === 0) return pass("D3");
|
|
24141
24225
|
const detail = D3_DETAIL(parts);
|
|
24142
24226
|
const fix = parts.includes(PART_MCP) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
|
|
24143
|
-
return fail2("D3",
|
|
24227
|
+
return fail2("D3", detail, fix);
|
|
24228
|
+
}
|
|
24229
|
+
function checkPiInstall(env, home, worktree) {
|
|
24230
|
+
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
24231
|
+
if (found !== void 0) return { ...pass("D3"), detail: found };
|
|
24232
|
+
return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join12(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
|
|
24144
24233
|
}
|
|
24145
24234
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
24146
24235
|
const findings = detectV1(agent, home, scope);
|
|
@@ -24193,7 +24282,7 @@ function configPaths(row5, env, worktree) {
|
|
|
24193
24282
|
}
|
|
24194
24283
|
|
|
24195
24284
|
// src/core/ops/doctor-db.ts
|
|
24196
|
-
import { existsSync as
|
|
24285
|
+
import { existsSync as existsSync9, statSync as statSync5 } from "node:fs";
|
|
24197
24286
|
var unknown2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
|
|
24198
24287
|
var pass2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
|
|
24199
24288
|
var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -24212,8 +24301,8 @@ async function loadSqlite2() {
|
|
|
24212
24301
|
return null;
|
|
24213
24302
|
}
|
|
24214
24303
|
}
|
|
24215
|
-
function openRead(sqlite,
|
|
24216
|
-
return new sqlite.DatabaseSync(
|
|
24304
|
+
function openRead(sqlite, path8) {
|
|
24305
|
+
return new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
|
|
24217
24306
|
}
|
|
24218
24307
|
var cell = (row5) => Object.values(row5)[0];
|
|
24219
24308
|
function readSchema(raw) {
|
|
@@ -24234,16 +24323,16 @@ function failsOnCorrupt(step) {
|
|
|
24234
24323
|
function orphanFiles(dbPath) {
|
|
24235
24324
|
const files = [];
|
|
24236
24325
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
24237
|
-
const
|
|
24238
|
-
if (
|
|
24326
|
+
const path8 = dbPath + suffix;
|
|
24327
|
+
if (existsSync9(path8)) files.push({ path: path8, bytes: statSync5(path8).size });
|
|
24239
24328
|
}
|
|
24240
|
-
return files.length > 0 && !
|
|
24329
|
+
return files.length > 0 && !existsSync9(dbPath) ? files : [];
|
|
24241
24330
|
}
|
|
24242
24331
|
async function checkDb(project) {
|
|
24243
24332
|
const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
|
|
24244
24333
|
const orphan = orphanFiles(project.dbPath);
|
|
24245
24334
|
if (orphan.length > 0) return { row: fail3(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
|
|
24246
|
-
if (!
|
|
24335
|
+
if (!existsSync9(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
24247
24336
|
const sqlite = await loadSqlite2();
|
|
24248
24337
|
if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
|
|
24249
24338
|
let raw = null;
|
|
@@ -24269,7 +24358,7 @@ async function checkDb(project) {
|
|
|
24269
24358
|
}
|
|
24270
24359
|
}
|
|
24271
24360
|
async function checkIndex(project) {
|
|
24272
|
-
if (!
|
|
24361
|
+
if (!existsSync9(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
|
|
24273
24362
|
const sqlite = await loadSqlite2();
|
|
24274
24363
|
if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
|
|
24275
24364
|
let raw = null;
|
|
@@ -24286,7 +24375,7 @@ async function checkIndex(project) {
|
|
|
24286
24375
|
}
|
|
24287
24376
|
|
|
24288
24377
|
// src/core/ops/doctor-env.ts
|
|
24289
|
-
import { existsSync as
|
|
24378
|
+
import { existsSync as existsSync10, readFileSync as readFileSync10, realpathSync as realpathSync6 } from "node:fs";
|
|
24290
24379
|
import { isAbsolute as isAbsolute3, join as join13, relative as relative2 } from "node:path";
|
|
24291
24380
|
function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
24292
24381
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
@@ -24299,7 +24388,7 @@ function fail4(id2, detail, fixCommand) {
|
|
|
24299
24388
|
}
|
|
24300
24389
|
function bundleVersion(bundleDir2) {
|
|
24301
24390
|
try {
|
|
24302
|
-
const v = JSON.parse(
|
|
24391
|
+
const v = JSON.parse(readFileSync10(join13(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24303
24392
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24304
24393
|
} catch {
|
|
24305
24394
|
return void 0;
|
|
@@ -24449,8 +24538,8 @@ function checkMcp(ctx) {
|
|
|
24449
24538
|
return named2 || versioned ? pass3("D6") : unknown3("D6", D6_UNKNOWN_DETAIL);
|
|
24450
24539
|
}
|
|
24451
24540
|
function piCwdInside(worktree, piCwd) {
|
|
24452
|
-
if (piCwd === void 0 || !
|
|
24453
|
-
const rel = relative2(worktree,
|
|
24541
|
+
if (piCwd === void 0 || !existsSync10(piCwd)) return false;
|
|
24542
|
+
const rel = relative2(worktree, realpathSync6.native(piCwd));
|
|
24454
24543
|
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
24455
24544
|
}
|
|
24456
24545
|
function checkProject(i) {
|
|
@@ -24470,20 +24559,20 @@ function checkShell(env) {
|
|
|
24470
24559
|
}
|
|
24471
24560
|
|
|
24472
24561
|
// src/core/ops/doctor-hook.ts
|
|
24473
|
-
import { existsSync as
|
|
24562
|
+
import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync11, realpathSync as realpathSync8, rmSync as rmSync2 } from "node:fs";
|
|
24474
24563
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24475
|
-
import
|
|
24564
|
+
import path7 from "node:path";
|
|
24476
24565
|
|
|
24477
24566
|
// src/setup/codex-trust.ts
|
|
24478
24567
|
import { createHash } from "node:crypto";
|
|
24479
|
-
import { existsSync as
|
|
24480
|
-
import
|
|
24568
|
+
import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
|
|
24569
|
+
import path6 from "node:path";
|
|
24481
24570
|
import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
|
|
24482
24571
|
|
|
24483
24572
|
// src/setup/spawn-bin.ts
|
|
24484
24573
|
import { spawnSync } from "node:child_process";
|
|
24485
24574
|
import { accessSync as accessSync2, constants as fsc, statSync as statSync6 } from "node:fs";
|
|
24486
|
-
import
|
|
24575
|
+
import path5 from "node:path";
|
|
24487
24576
|
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
24488
24577
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
24489
24578
|
var DEFAULT_COMSPEC = "cmd.exe";
|
|
@@ -24494,10 +24583,10 @@ function whichBin(bin, env, platform = process.platform) {
|
|
|
24494
24583
|
const get = (k) => envGet(env, k);
|
|
24495
24584
|
const win = platform === "win32";
|
|
24496
24585
|
const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
|
|
24497
|
-
const names = win &&
|
|
24586
|
+
const names = win && path5.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
|
|
24498
24587
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
24499
24588
|
for (const n of names) {
|
|
24500
|
-
const f =
|
|
24589
|
+
const f = path5.join(dir, n);
|
|
24501
24590
|
try {
|
|
24502
24591
|
accessSync2(f, fsc.X_OK);
|
|
24503
24592
|
if (statSync6(f).isFile()) return f;
|
|
@@ -24538,7 +24627,7 @@ function winCmdLine(file2, args, env = {}) {
|
|
|
24538
24627
|
return `"${[file2, ...args].map(q).join(" ")}"`;
|
|
24539
24628
|
}
|
|
24540
24629
|
function spawnForm(file2, args, env, platform = process.platform) {
|
|
24541
|
-
if (platform === "win32" && WIN_SHIM_EXTS.includes(
|
|
24630
|
+
if (platform === "win32" && WIN_SHIM_EXTS.includes(path5.extname(file2).toLowerCase())) {
|
|
24542
24631
|
return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file2, args, env)], windowsVerbatimArguments: true };
|
|
24543
24632
|
}
|
|
24544
24633
|
return { command: file2, args, windowsVerbatimArguments: false };
|
|
@@ -24562,10 +24651,10 @@ function codexHomeFromReply(out) {
|
|
|
24562
24651
|
return void 0;
|
|
24563
24652
|
}
|
|
24564
24653
|
function sameDir(a, b, platform = process.platform) {
|
|
24565
|
-
if (platform !== "win32") return
|
|
24654
|
+
if (platform !== "win32") return path6.posix.normalize(a) === path6.posix.normalize(b);
|
|
24566
24655
|
const norm2 = (p) => {
|
|
24567
24656
|
const bare2 = p.startsWith(WIN_VERBATIM_PREFIX) ? p.slice(WIN_VERBATIM_PREFIX.length) : p;
|
|
24568
|
-
const n =
|
|
24657
|
+
const n = path6.win32.normalize(bare2).toLowerCase();
|
|
24569
24658
|
return n.length > 3 && n.endsWith("\\") ? n.slice(0, -1) : n;
|
|
24570
24659
|
};
|
|
24571
24660
|
return norm2(a) === norm2(b);
|
|
@@ -24698,11 +24787,11 @@ function isObject5(v) {
|
|
|
24698
24787
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
24699
24788
|
}
|
|
24700
24789
|
function loadFixture(bundleDir2, agent) {
|
|
24701
|
-
const file2 =
|
|
24702
|
-
if (!
|
|
24790
|
+
const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
24791
|
+
if (!existsSync12(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
24703
24792
|
let all;
|
|
24704
24793
|
try {
|
|
24705
|
-
all = JSON.parse(hostText(
|
|
24794
|
+
all = JSON.parse(hostText(readFileSync11(file2, "utf8")));
|
|
24706
24795
|
} catch (err) {
|
|
24707
24796
|
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
24708
24797
|
}
|
|
@@ -24764,7 +24853,7 @@ function isNativeShape(agent, stdout, exitCode, killed, event) {
|
|
|
24764
24853
|
var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
|
|
24765
24854
|
function readProbePayload(cwd) {
|
|
24766
24855
|
const content = Array.from({ length: READ_PROBE_LINES }, (_, n) => "d5 read probe line " + n + " ".padEnd(20, "x")).join("\n");
|
|
24767
|
-
const filePath =
|
|
24856
|
+
const filePath = path7.join(cwd, "d5-read-probe.txt");
|
|
24768
24857
|
return {
|
|
24769
24858
|
session_id: "d5-read-probe",
|
|
24770
24859
|
transcript_path: "",
|
|
@@ -24791,9 +24880,9 @@ function isReadShape(stdout) {
|
|
|
24791
24880
|
return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
|
|
24792
24881
|
}
|
|
24793
24882
|
async function readProbeOk(i, timeoutMs) {
|
|
24794
|
-
const home = mkdtempSync(
|
|
24883
|
+
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-read-"));
|
|
24795
24884
|
try {
|
|
24796
|
-
const r = await runProcess([process.execPath,
|
|
24885
|
+
const r = await runProcess([process.execPath, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
24797
24886
|
cwd: i.bundleDir,
|
|
24798
24887
|
env: { ...i.env, HOME: home, USERPROFILE: home },
|
|
24799
24888
|
signal: i.signal,
|
|
@@ -24811,7 +24900,7 @@ function codexHookJournaled(db) {
|
|
|
24811
24900
|
}
|
|
24812
24901
|
function realDir(p) {
|
|
24813
24902
|
try {
|
|
24814
|
-
return
|
|
24903
|
+
return realpathSync8(p);
|
|
24815
24904
|
} catch {
|
|
24816
24905
|
return p;
|
|
24817
24906
|
}
|
|
@@ -24838,7 +24927,7 @@ async function checkHookRoundTrip(i) {
|
|
|
24838
24927
|
const trust = await codexPluginTrust(i);
|
|
24839
24928
|
if (trust !== null) return trust;
|
|
24840
24929
|
}
|
|
24841
|
-
if (i.agent === "codex" &&
|
|
24930
|
+
if (i.agent === "codex" && existsSync12(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
24842
24931
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
24843
24932
|
}
|
|
24844
24933
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
@@ -24858,7 +24947,7 @@ async function checkHookRoundTrip(i) {
|
|
|
24858
24947
|
let ms = 0;
|
|
24859
24948
|
for (let n = 1; n <= maxPairs; n++) {
|
|
24860
24949
|
const start = now();
|
|
24861
|
-
const r = await runProcess([process.execPath,
|
|
24950
|
+
const r = await runProcess([process.execPath, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
24862
24951
|
cwd: i.bundleDir,
|
|
24863
24952
|
env: i.env,
|
|
24864
24953
|
signal: i.signal,
|
|
@@ -24877,11 +24966,11 @@ async function checkHookRoundTrip(i) {
|
|
|
24877
24966
|
}
|
|
24878
24967
|
|
|
24879
24968
|
// src/core/ops/db-heal.ts
|
|
24880
|
-
import { existsSync as
|
|
24969
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
|
|
24881
24970
|
import { basename as basename4, dirname as dirname8, join as join15 } from "node:path";
|
|
24882
24971
|
|
|
24883
24972
|
// src/core/store/owners.ts
|
|
24884
|
-
import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as
|
|
24973
|
+
import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync12, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
24885
24974
|
import { basename as basename3, join as join14 } from "node:path";
|
|
24886
24975
|
function ownersDir(configDir, projectKey) {
|
|
24887
24976
|
return join14(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
@@ -24915,7 +25004,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
24915
25004
|
const file2 = join14(dir, name);
|
|
24916
25005
|
let text;
|
|
24917
25006
|
try {
|
|
24918
|
-
text =
|
|
25007
|
+
text = readFileSync12(file2, "utf8");
|
|
24919
25008
|
} catch (err) {
|
|
24920
25009
|
if (errCode2(err) === "ENOENT") continue;
|
|
24921
25010
|
throw err;
|
|
@@ -24961,7 +25050,7 @@ function renameAside(dbPath) {
|
|
|
24961
25050
|
const ts = String(Date.now());
|
|
24962
25051
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
24963
25052
|
const file2 = dbPath + suffix;
|
|
24964
|
-
if (
|
|
25053
|
+
if (existsSync13(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
24965
25054
|
}
|
|
24966
25055
|
return ts;
|
|
24967
25056
|
}
|
|
@@ -25068,7 +25157,7 @@ function buildReportHead(input) {
|
|
|
25068
25157
|
|
|
25069
25158
|
// src/core/ops/doctor-issue.ts
|
|
25070
25159
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
25071
|
-
import { closeSync, existsSync as
|
|
25160
|
+
import { closeSync, existsSync as existsSync14, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync13, readSync, realpathSync as realpathSync9, writeFileSync as writeFileSync3 } from "node:fs";
|
|
25072
25161
|
import { delimiter, join as join16 } from "node:path";
|
|
25073
25162
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
25074
25163
|
function tildeOf(env) {
|
|
@@ -25076,8 +25165,8 @@ function tildeOf(env) {
|
|
|
25076
25165
|
if (home === null || home === "") return (t) => t;
|
|
25077
25166
|
const homes = [home];
|
|
25078
25167
|
try {
|
|
25079
|
-
const
|
|
25080
|
-
if (
|
|
25168
|
+
const real3 = realpathSync9.native(home);
|
|
25169
|
+
if (real3 !== home) homes.push(real3);
|
|
25081
25170
|
} catch {
|
|
25082
25171
|
}
|
|
25083
25172
|
homes.sort((a, b) => b.length - a.length);
|
|
@@ -25110,7 +25199,7 @@ function onPath(env, tool) {
|
|
|
25110
25199
|
const out = [];
|
|
25111
25200
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
25112
25201
|
if (dir === "") continue;
|
|
25113
|
-
for (const n of names) if (
|
|
25202
|
+
for (const n of names) if (existsSync14(join16(dir, n))) {
|
|
25114
25203
|
out.push(join16(dir, n));
|
|
25115
25204
|
break;
|
|
25116
25205
|
}
|
|
@@ -25119,7 +25208,7 @@ function onPath(env, tool) {
|
|
|
25119
25208
|
}
|
|
25120
25209
|
function hookLogTail(env) {
|
|
25121
25210
|
const file2 = hookLogPath(env);
|
|
25122
|
-
if (file2 === "" || !
|
|
25211
|
+
if (file2 === "" || !existsSync14(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
25123
25212
|
try {
|
|
25124
25213
|
const fd = openSync(file2, "r");
|
|
25125
25214
|
try {
|
|
@@ -25139,7 +25228,7 @@ function hookLogTail(env) {
|
|
|
25139
25228
|
}
|
|
25140
25229
|
async function journalRows(ctx) {
|
|
25141
25230
|
const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
25142
|
-
if (!
|
|
25231
|
+
if (!existsSync14(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
25143
25232
|
try {
|
|
25144
25233
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
25145
25234
|
try {
|
|
@@ -25165,13 +25254,13 @@ function agentConfig(adapter, env, worktree) {
|
|
|
25165
25254
|
for (const f of files) {
|
|
25166
25255
|
if (seen.has(f.path)) continue;
|
|
25167
25256
|
seen.add(f.path);
|
|
25168
|
-
if (!
|
|
25257
|
+
if (!existsSync14(f.path)) {
|
|
25169
25258
|
out.push(`${f.label}: ${f.path} (absent)`);
|
|
25170
25259
|
continue;
|
|
25171
25260
|
}
|
|
25172
25261
|
let text = "";
|
|
25173
25262
|
try {
|
|
25174
|
-
text =
|
|
25263
|
+
text = readFileSync13(f.path, "utf8");
|
|
25175
25264
|
} catch (err) {
|
|
25176
25265
|
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
25177
25266
|
continue;
|
|
@@ -25270,7 +25359,7 @@ async function guard(id2, run) {
|
|
|
25270
25359
|
}
|
|
25271
25360
|
}
|
|
25272
25361
|
async function codexDb(ctx, adapter) {
|
|
25273
|
-
if (adapter.id !== "codex" || !
|
|
25362
|
+
if (adapter.id !== "codex" || !existsSync15(ctx.project.dbPath)) return null;
|
|
25274
25363
|
try {
|
|
25275
25364
|
return await openDb(ctx.project, { readOnly: true });
|
|
25276
25365
|
} catch {
|
|
@@ -25301,10 +25390,10 @@ async function hookRow(ctx, adapter, host) {
|
|
|
25301
25390
|
}
|
|
25302
25391
|
function ownServerId(configDir, projectKey) {
|
|
25303
25392
|
const dir = join17(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
25304
|
-
if (!
|
|
25393
|
+
if (!existsSync15(dir)) return "";
|
|
25305
25394
|
for (const name of readdirSync6(dir)) {
|
|
25306
25395
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
25307
|
-
if (
|
|
25396
|
+
if (readFileSync14(join17(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
25308
25397
|
}
|
|
25309
25398
|
return "";
|
|
25310
25399
|
}
|
|
@@ -25360,7 +25449,7 @@ async function doctorReply(ctx, host) {
|
|
|
25360
25449
|
const adapter = getAdapter(ctx.project.agent);
|
|
25361
25450
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
25362
25451
|
const failed2 = rows.some((r) => r.status === "FAIL");
|
|
25363
|
-
const command = `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
25452
|
+
const command = adapter.id === "pi" ? failed2 ? NATIVE_INSTALL.pi[0] : PI_LIST_COMMAND : `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
25364
25453
|
const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
|
|
25365
25454
|
const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
|
|
25366
25455
|
const table3 = buildReport(input);
|
|
@@ -25387,7 +25476,7 @@ async function doctorReply(ctx, host) {
|
|
|
25387
25476
|
return { text, isError: false, sandboxBytes: bytes5 };
|
|
25388
25477
|
}
|
|
25389
25478
|
async function handler2(_input, ctx) {
|
|
25390
|
-
return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd:
|
|
25479
|
+
return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: ctx.piCwd });
|
|
25391
25480
|
}
|
|
25392
25481
|
var ctxDoctor = Object.freeze({
|
|
25393
25482
|
name: "ctx_doctor",
|
|
@@ -25399,7 +25488,7 @@ var ctxDoctor = Object.freeze({
|
|
|
25399
25488
|
});
|
|
25400
25489
|
|
|
25401
25490
|
// src/core/tools/execute.ts
|
|
25402
|
-
import { existsSync as
|
|
25491
|
+
import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
25403
25492
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
25404
25493
|
import { dirname as dirname10, join as join18, parse as parse3, resolve as resolve6 } from "node:path";
|
|
25405
25494
|
|
|
@@ -25485,7 +25574,7 @@ function schemaLine(issue2) {
|
|
|
25485
25574
|
}
|
|
25486
25575
|
function fileError(given, abs, root) {
|
|
25487
25576
|
let dir = abs;
|
|
25488
|
-
while (!
|
|
25577
|
+
while (!existsSync16(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
|
|
25489
25578
|
if (isInside(root, dir)) return null;
|
|
25490
25579
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
25491
25580
|
}
|
|
@@ -25602,19 +25691,19 @@ var ctxExecute = {
|
|
|
25602
25691
|
};
|
|
25603
25692
|
|
|
25604
25693
|
// src/core/tools/index.ts
|
|
25605
|
-
import { existsSync as
|
|
25694
|
+
import { existsSync as existsSync17, readFileSync as readFileSync16, statSync as statSync8 } from "node:fs";
|
|
25606
25695
|
import { dirname as dirname11, extname, join as join20, relative as relative3, resolve as resolve7 } from "node:path";
|
|
25607
25696
|
|
|
25608
25697
|
// src/core/index/walk.ts
|
|
25609
|
-
import { readdirSync as readdirSync7, readFileSync as
|
|
25698
|
+
import { readdirSync as readdirSync7, readFileSync as readFileSync15, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
|
|
25610
25699
|
import { join as join19 } from "node:path";
|
|
25611
25700
|
var GITIGNORE = ".gitignore";
|
|
25612
25701
|
var GIT_DIR = ".git";
|
|
25613
25702
|
function walkDir(root, containmentRoot) {
|
|
25614
|
-
const
|
|
25615
|
-
if (!isInside(containmentRoot,
|
|
25703
|
+
const real3 = realpathSync10(root);
|
|
25704
|
+
if (!isInside(containmentRoot, real3)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
|
|
25616
25705
|
const found = [];
|
|
25617
|
-
visit(
|
|
25706
|
+
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
25618
25707
|
found.sort(compareFound);
|
|
25619
25708
|
return found.map((f) => ({ absPath: f.absPath, relPath: join19(...f.dir, f.name) }));
|
|
25620
25709
|
}
|
|
@@ -25628,14 +25717,14 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
25628
25717
|
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join19(abs, GITIGNORE), rel)) : parent;
|
|
25629
25718
|
for (const e of entries) {
|
|
25630
25719
|
if (e.name === GIT_DIR) continue;
|
|
25631
|
-
const
|
|
25720
|
+
const path8 = join19(abs, e.name);
|
|
25632
25721
|
let isDir = e.isDirectory();
|
|
25633
25722
|
let isFile = e.isFile();
|
|
25634
|
-
let target =
|
|
25723
|
+
let target = path8;
|
|
25635
25724
|
if (e.isSymbolicLink()) {
|
|
25636
25725
|
let resolved;
|
|
25637
25726
|
try {
|
|
25638
|
-
resolved =
|
|
25727
|
+
resolved = realpathSync10(path8);
|
|
25639
25728
|
} catch {
|
|
25640
25729
|
continue;
|
|
25641
25730
|
}
|
|
@@ -25648,12 +25737,12 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
25648
25737
|
const segs = rel.concat(e.name);
|
|
25649
25738
|
if (ignored(rules, segs, isDir)) continue;
|
|
25650
25739
|
if (isFile) {
|
|
25651
|
-
found.push({ dir: rel, name: e.name, absPath:
|
|
25740
|
+
found.push({ dir: rel, name: e.name, absPath: path8 });
|
|
25652
25741
|
} else if (isDir) {
|
|
25653
|
-
const key = e.isSymbolicLink() ? target :
|
|
25742
|
+
const key = e.isSymbolicLink() ? target : realpathSync10(path8);
|
|
25654
25743
|
if (seen.has(key)) continue;
|
|
25655
25744
|
seen.add(key);
|
|
25656
|
-
visit(
|
|
25745
|
+
visit(path8, segs, rules, contain, seen, found);
|
|
25657
25746
|
}
|
|
25658
25747
|
}
|
|
25659
25748
|
}
|
|
@@ -25668,7 +25757,7 @@ function compareFound(a, b) {
|
|
|
25668
25757
|
function readRules(file2, base) {
|
|
25669
25758
|
let body;
|
|
25670
25759
|
try {
|
|
25671
|
-
body =
|
|
25760
|
+
body = readFileSync15(file2, "utf8");
|
|
25672
25761
|
} catch {
|
|
25673
25762
|
return [];
|
|
25674
25763
|
}
|
|
@@ -25844,12 +25933,12 @@ function tlsName(host) {
|
|
|
25844
25933
|
function request(u, conn, proxy, signal) {
|
|
25845
25934
|
const host = bare(u.hostname);
|
|
25846
25935
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
25847
|
-
const
|
|
25936
|
+
const path8 = u.pathname + u.search;
|
|
25848
25937
|
return new Promise((resolve8, reject) => {
|
|
25849
25938
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
25850
25939
|
if (proxy === void 0) {
|
|
25851
25940
|
const mod = u.protocol === "https:" ? https : http;
|
|
25852
|
-
const req = mod.request({ host: conn.address, port, path:
|
|
25941
|
+
const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
25853
25942
|
req.on("response", resolve8).on("error", onErr).end();
|
|
25854
25943
|
return;
|
|
25855
25944
|
}
|
|
@@ -25871,7 +25960,7 @@ function request(u, conn, proxy, signal) {
|
|
|
25871
25960
|
const req = https.request({
|
|
25872
25961
|
host,
|
|
25873
25962
|
port,
|
|
25874
|
-
path:
|
|
25963
|
+
path: path8,
|
|
25875
25964
|
signal,
|
|
25876
25965
|
headers: { host: u.host },
|
|
25877
25966
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
@@ -29751,14 +29840,14 @@ function kindOfType(contentType) {
|
|
|
29751
29840
|
}
|
|
29752
29841
|
function readUtf8(absPath) {
|
|
29753
29842
|
try {
|
|
29754
|
-
return utf8.decode(
|
|
29843
|
+
return utf8.decode(readFileSync16(absPath));
|
|
29755
29844
|
} catch {
|
|
29756
29845
|
return void 0;
|
|
29757
29846
|
}
|
|
29758
29847
|
}
|
|
29759
29848
|
function missingOrOutside(given, abs, root) {
|
|
29760
29849
|
let dir = abs;
|
|
29761
|
-
while (!
|
|
29850
|
+
while (!existsSync17(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
|
|
29762
29851
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
29763
29852
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
29764
29853
|
}
|
|
@@ -30309,11 +30398,11 @@ var ctxStats = Object.freeze({
|
|
|
30309
30398
|
});
|
|
30310
30399
|
|
|
30311
30400
|
// src/core/tools/upgrade.ts
|
|
30312
|
-
import { existsSync as
|
|
30401
|
+
import { existsSync as existsSync23, realpathSync as realpathSync11, rmSync as rmSync10 } from "node:fs";
|
|
30313
30402
|
import { basename as basename7, dirname as dirname13, join as join26 } from "node:path";
|
|
30314
30403
|
|
|
30315
30404
|
// src/core/ops/host-write.ts
|
|
30316
|
-
import { copyFileSync, existsSync as
|
|
30405
|
+
import { copyFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
30317
30406
|
import { dirname as dirname12, join as join21 } from "node:path";
|
|
30318
30407
|
function defaultWrite(file2, text) {
|
|
30319
30408
|
writeFileSync5(file2, text, "utf8");
|
|
@@ -30342,7 +30431,7 @@ function toRow(file2, edit) {
|
|
|
30342
30431
|
function writeWithRollback(file2, text, write2, atomic) {
|
|
30343
30432
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
30344
30433
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
30345
|
-
const had =
|
|
30434
|
+
const had = existsSync18(file2);
|
|
30346
30435
|
mkdirSync7(dirname12(file2), { recursive: true });
|
|
30347
30436
|
if (had) copyFileSync(file2, trash);
|
|
30348
30437
|
try {
|
|
@@ -30372,7 +30461,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
30372
30461
|
if (requested === null) return [];
|
|
30373
30462
|
const current = readHostConfig(row5.id, requested);
|
|
30374
30463
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
30375
|
-
const exists =
|
|
30464
|
+
const exists = existsSync18(current.path);
|
|
30376
30465
|
if (exists && result.text === current.text) return [];
|
|
30377
30466
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
30378
30467
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -30380,15 +30469,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
30380
30469
|
}
|
|
30381
30470
|
|
|
30382
30471
|
// src/core/ops/plugin-swap.ts
|
|
30383
|
-
import { existsSync as
|
|
30472
|
+
import { existsSync as existsSync19, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
30384
30473
|
import { basename as basename6, join as join22, win32 as win322 } from "node:path";
|
|
30385
|
-
function linkTarget(
|
|
30386
|
-
if (!isLink(
|
|
30387
|
-
const target = readlinkSync(
|
|
30474
|
+
function linkTarget(path8, win) {
|
|
30475
|
+
if (!isLink(path8)) return null;
|
|
30476
|
+
const target = readlinkSync(path8);
|
|
30388
30477
|
return win ? win322.basename(target) : target;
|
|
30389
30478
|
}
|
|
30390
|
-
function isLink(
|
|
30391
|
-
return lstatSync(
|
|
30479
|
+
function isLink(path8) {
|
|
30480
|
+
return lstatSync(path8, { throwIfNoEntry: false })?.isSymbolicLink() === true;
|
|
30392
30481
|
}
|
|
30393
30482
|
function generations(agentDir) {
|
|
30394
30483
|
return readdirSync8(agentDir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).filter((name) => !name.startsWith(UPGRADE_FETCH_DIR_PREFIX) && !name.endsWith(UPGRADE_TRASH_SUFFIX)).sort();
|
|
@@ -30401,7 +30490,7 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
30401
30490
|
}
|
|
30402
30491
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
30403
30492
|
const next = join22(agentDir, sha);
|
|
30404
|
-
if (!
|
|
30493
|
+
if (!existsSync19(next) || !lstatSync(next).isDirectory()) {
|
|
30405
30494
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
|
|
30406
30495
|
}
|
|
30407
30496
|
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
@@ -30421,12 +30510,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
30421
30510
|
if (before !== null) keep.add(before);
|
|
30422
30511
|
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join22(agentDir, name));
|
|
30423
30512
|
for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
|
|
30424
|
-
const previous = before !== null &&
|
|
30513
|
+
const previous = before !== null && existsSync19(join22(agentDir, before)) ? join22(agentDir, before) : null;
|
|
30425
30514
|
return { current: next, previous, removed };
|
|
30426
30515
|
}
|
|
30427
30516
|
|
|
30428
30517
|
// src/core/ops/release-fetch.ts
|
|
30429
|
-
import { existsSync as
|
|
30518
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
|
|
30430
30519
|
import { join as join23 } from "node:path";
|
|
30431
30520
|
function failed(r) {
|
|
30432
30521
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -30450,7 +30539,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
30450
30539
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url2, fetchDir], agentDir, childEnv, signal);
|
|
30451
30540
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
30452
30541
|
const dir = join23(agentDir, sha);
|
|
30453
|
-
if (
|
|
30542
|
+
if (existsSync20(dir)) rmSync7(fetchDir, { recursive: true, force: true });
|
|
30454
30543
|
else renameWithRetry(fetchDir, dir, opts);
|
|
30455
30544
|
return { sha, dir };
|
|
30456
30545
|
} catch (e) {
|
|
@@ -30460,7 +30549,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
30460
30549
|
}
|
|
30461
30550
|
|
|
30462
30551
|
// src/core/ops/uninstall.ts
|
|
30463
|
-
import { existsSync as
|
|
30552
|
+
import { existsSync as existsSync21, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
30464
30553
|
import { join as join24 } from "node:path";
|
|
30465
30554
|
function row2(area, before, after) {
|
|
30466
30555
|
return { area, before, after };
|
|
@@ -30494,7 +30583,7 @@ function removeCache(adapter, env, configDir) {
|
|
|
30494
30583
|
}
|
|
30495
30584
|
case "plugin": {
|
|
30496
30585
|
const agentDir = join24(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
30497
|
-
if (!
|
|
30586
|
+
if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
30498
30587
|
rmSync8(agentDir, { recursive: true, force: true });
|
|
30499
30588
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
30500
30589
|
}
|
|
@@ -30513,7 +30602,7 @@ function isObj3(v) {
|
|
|
30513
30602
|
function piSource(entry) {
|
|
30514
30603
|
return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
|
|
30515
30604
|
}
|
|
30516
|
-
function
|
|
30605
|
+
function ownEntries2(agent, env) {
|
|
30517
30606
|
const home = requireHomeDir(env);
|
|
30518
30607
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
30519
30608
|
if (mcp !== void 0) {
|
|
@@ -30521,10 +30610,10 @@ function ownEntries(agent, env) {
|
|
|
30521
30610
|
const inner = mcp.key.slice(1, -1);
|
|
30522
30611
|
const own2 = mcp.key[mcp.key.length - 1];
|
|
30523
30612
|
const holder = (v) => inner.reduce((cur, k) => isObj3(cur) ? cur[k] : void 0, v);
|
|
30524
|
-
const without = (v,
|
|
30613
|
+
const without = (v, path8) => {
|
|
30525
30614
|
const o = v;
|
|
30526
|
-
if (
|
|
30527
|
-
return { ...o, [
|
|
30615
|
+
if (path8.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own2));
|
|
30616
|
+
return { ...o, [path8[0]]: without(o[path8[0]], path8.slice(1)) };
|
|
30528
30617
|
};
|
|
30529
30618
|
return [{
|
|
30530
30619
|
file: ownMcpFileOf(agent, mcp.file, env, home),
|
|
@@ -30561,7 +30650,7 @@ function ownEntries(agent, env) {
|
|
|
30561
30650
|
}
|
|
30562
30651
|
function removeOwnEntries(agent, env) {
|
|
30563
30652
|
const rows = [];
|
|
30564
|
-
for (const entry of
|
|
30653
|
+
for (const entry of ownEntries2(agent, env)) {
|
|
30565
30654
|
const current = readHostConfig(agent, entry.file);
|
|
30566
30655
|
if (current.text === "") continue;
|
|
30567
30656
|
const value = hostConfigValueAt(parseHostConfig(agent, current.path, current.text, current.format), [entry.key]);
|
|
@@ -30574,7 +30663,7 @@ function removeOwnEntries(agent, env) {
|
|
|
30574
30663
|
function removeProjectData(configDir, projectKey) {
|
|
30575
30664
|
const projects = join24(configDir, PROJECTS_DIR_NAME);
|
|
30576
30665
|
const dir = join24(projects, projectKey);
|
|
30577
|
-
if (!
|
|
30666
|
+
if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
30578
30667
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
30579
30668
|
for (const name of readdirSync9(dir)) {
|
|
30580
30669
|
if (name !== OWNERS_DIR_NAME) rmSync8(join24(dir, name), { recursive: true, force: true });
|
|
@@ -30590,7 +30679,7 @@ function runUninstall(input) {
|
|
|
30590
30679
|
}
|
|
30591
30680
|
|
|
30592
30681
|
// src/core/ops/v1-remove.ts
|
|
30593
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
30682
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync17, rmSync as rmSync9 } from "node:fs";
|
|
30594
30683
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
30595
30684
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
30596
30685
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -30620,8 +30709,8 @@ function cutTomlTable(text, header) {
|
|
|
30620
30709
|
function writeAtomic(file2, text) {
|
|
30621
30710
|
atomicWriteFile(file2, text);
|
|
30622
30711
|
}
|
|
30623
|
-
function locate(doc,
|
|
30624
|
-
const segs =
|
|
30712
|
+
function locate(doc, path8) {
|
|
30713
|
+
const segs = path8.split(V1_KEY_PATH_SEP);
|
|
30625
30714
|
let cur = doc;
|
|
30626
30715
|
for (const seg of segs.slice(0, -1)) {
|
|
30627
30716
|
if (Array.isArray(cur)) cur = cur[Number(seg)];
|
|
@@ -30634,8 +30723,8 @@ function locate(doc, path7) {
|
|
|
30634
30723
|
return null;
|
|
30635
30724
|
}
|
|
30636
30725
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
30637
|
-
const layout = hostLayout(
|
|
30638
|
-
const text = hostText(
|
|
30726
|
+
const layout = hostLayout(readFileSync17(file2, "utf8"));
|
|
30727
|
+
const text = hostText(readFileSync17(file2, "utf8"));
|
|
30639
30728
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
30640
30729
|
const hit = /* @__PURE__ */ new Set();
|
|
30641
30730
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -30671,19 +30760,19 @@ function removeV1(agent, findings) {
|
|
|
30671
30760
|
for (const f of findings) {
|
|
30672
30761
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
30673
30762
|
else if (f.path === "") {
|
|
30674
|
-
if (
|
|
30763
|
+
if (existsSync22(f.file)) {
|
|
30675
30764
|
moveAside(f.file, undo);
|
|
30676
30765
|
done.set(f, UPGRADE_REMOVED);
|
|
30677
30766
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
30678
30767
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
30679
30768
|
}
|
|
30680
30769
|
for (const [file2, list4] of entries) {
|
|
30681
|
-
if (!
|
|
30770
|
+
if (!existsSync22(file2)) {
|
|
30682
30771
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
30683
30772
|
continue;
|
|
30684
30773
|
}
|
|
30685
30774
|
if (file2.endsWith(TOML_EXT)) {
|
|
30686
|
-
const rawToml =
|
|
30775
|
+
const rawToml = readFileSync17(file2, "utf8");
|
|
30687
30776
|
const tomlLayout = hostLayout(rawToml);
|
|
30688
30777
|
let text = hostText(rawToml);
|
|
30689
30778
|
for (const f of list4) {
|
|
@@ -30711,7 +30800,7 @@ function removeV1(agent, findings) {
|
|
|
30711
30800
|
},
|
|
30712
30801
|
rollback() {
|
|
30713
30802
|
for (const u of undo.splice(0).reverse()) {
|
|
30714
|
-
if (!
|
|
30803
|
+
if (!existsSync22(u.trash)) continue;
|
|
30715
30804
|
rmSync9(u.target, { recursive: true, force: true });
|
|
30716
30805
|
renameWithRetry(u.trash, u.target);
|
|
30717
30806
|
}
|
|
@@ -30721,7 +30810,7 @@ function removeV1(agent, findings) {
|
|
|
30721
30810
|
|
|
30722
30811
|
// src/core/ops/verify-sums.ts
|
|
30723
30812
|
import { createHash as createHash2 } from "node:crypto";
|
|
30724
|
-
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as
|
|
30813
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync18 } from "node:fs";
|
|
30725
30814
|
import { join as join25 } from "node:path";
|
|
30726
30815
|
function mismatch() {
|
|
30727
30816
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
@@ -30753,14 +30842,14 @@ function verifySums(dir) {
|
|
|
30753
30842
|
const sumsPath = join25(dir, RELEASE_SUMS_FILE);
|
|
30754
30843
|
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
30755
30844
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
30756
|
-
const sums = parseSums(
|
|
30845
|
+
const sums = parseSums(readFileSync18(sumsPath, "utf8"));
|
|
30757
30846
|
const files = /* @__PURE__ */ new Map();
|
|
30758
30847
|
walk3(dir, "", files);
|
|
30759
30848
|
if (files.size !== sums.size) throw mismatch();
|
|
30760
30849
|
for (const [rel, abs] of files) {
|
|
30761
30850
|
const want = sums.get(rel);
|
|
30762
30851
|
if (want === void 0) throw mismatch();
|
|
30763
|
-
const got = createHash2(SUMS_HASH_ALGORITHM).update(
|
|
30852
|
+
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync18(abs)).digest(HASH_ENCODING);
|
|
30764
30853
|
if (got !== want) throw mismatch();
|
|
30765
30854
|
}
|
|
30766
30855
|
}
|
|
@@ -30789,7 +30878,7 @@ function pluginRootRow(adapter, env) {
|
|
|
30789
30878
|
}
|
|
30790
30879
|
function isCurrent(agentDir, dir) {
|
|
30791
30880
|
const link = join26(agentDir, PLUGIN_CURRENT_LINK);
|
|
30792
|
-
return
|
|
30881
|
+
return existsSync23(link) && realpathSync11.native(link) === realpathSync11.native(dir);
|
|
30793
30882
|
}
|
|
30794
30883
|
async function checkout(adapter, deps) {
|
|
30795
30884
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|