context-mode 2.1.1 → 2.1.3
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 +164 -144
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +85 -85
- package/opencode/plugin.js +348 -228
- package/package.json +1 -1
- package/pi/index.js +402 -280
- package/qwen-extension.json +1 -1
- package/run.mjs +19 -8
- package/search.mjs +19 -8
- package/server.mjs +374 -262
package/pi/index.js
CHANGED
|
@@ -657,10 +657,10 @@ function assignProp(target, prop, value) {
|
|
|
657
657
|
configurable: true
|
|
658
658
|
});
|
|
659
659
|
}
|
|
660
|
-
function getElementAtPath(obj,
|
|
661
|
-
if (!
|
|
660
|
+
function getElementAtPath(obj, path8) {
|
|
661
|
+
if (!path8)
|
|
662
662
|
return obj;
|
|
663
|
-
return
|
|
663
|
+
return path8.reduce((acc, key) => acc?.[key], obj);
|
|
664
664
|
}
|
|
665
665
|
function promiseAllObject(promisesObj) {
|
|
666
666
|
const keys = Object.keys(promisesObj);
|
|
@@ -980,11 +980,11 @@ function aborted(x, startIndex = 0) {
|
|
|
980
980
|
}
|
|
981
981
|
return false;
|
|
982
982
|
}
|
|
983
|
-
function prefixIssues(
|
|
983
|
+
function prefixIssues(path8, issues) {
|
|
984
984
|
return issues.map((iss) => {
|
|
985
985
|
var _a5;
|
|
986
986
|
(_a5 = iss).path ?? (_a5.path = []);
|
|
987
|
-
iss.path.unshift(
|
|
987
|
+
iss.path.unshift(path8);
|
|
988
988
|
return iss;
|
|
989
989
|
});
|
|
990
990
|
}
|
|
@@ -1121,7 +1121,7 @@ function treeifyError(error42, _mapper) {
|
|
|
1121
1121
|
return issue4.message;
|
|
1122
1122
|
};
|
|
1123
1123
|
const result = { errors: [] };
|
|
1124
|
-
const processError = (error43,
|
|
1124
|
+
const processError = (error43, path8 = []) => {
|
|
1125
1125
|
var _a5, _b;
|
|
1126
1126
|
for (const issue4 of error43.issues) {
|
|
1127
1127
|
if (issue4.code === "invalid_union" && issue4.errors.length) {
|
|
@@ -1131,7 +1131,7 @@ function treeifyError(error42, _mapper) {
|
|
|
1131
1131
|
} else if (issue4.code === "invalid_element") {
|
|
1132
1132
|
processError({ issues: issue4.issues }, issue4.path);
|
|
1133
1133
|
} else {
|
|
1134
|
-
const fullpath = [...
|
|
1134
|
+
const fullpath = [...path8, ...issue4.path];
|
|
1135
1135
|
if (fullpath.length === 0) {
|
|
1136
1136
|
result.errors.push(mapper(issue4));
|
|
1137
1137
|
continue;
|
|
@@ -1161,9 +1161,9 @@ function treeifyError(error42, _mapper) {
|
|
|
1161
1161
|
processError(error42);
|
|
1162
1162
|
return result;
|
|
1163
1163
|
}
|
|
1164
|
-
function toDotPath(
|
|
1164
|
+
function toDotPath(path8) {
|
|
1165
1165
|
const segs = [];
|
|
1166
|
-
for (const seg of
|
|
1166
|
+
for (const seg of path8) {
|
|
1167
1167
|
if (typeof seg === "number")
|
|
1168
1168
|
segs.push(`[${seg}]`);
|
|
1169
1169
|
else if (typeof seg === "symbol")
|
|
@@ -11163,6 +11163,8 @@ var STATE_CLOSE_TAG = "</context_mode_state>";
|
|
|
11163
11163
|
var INDEX_WRITE_CHUNK = 1048576;
|
|
11164
11164
|
var SYNC_INDEX_MAX_BYTES = 65536;
|
|
11165
11165
|
var REPLACE_TRIGGER_BYTES = 4096;
|
|
11166
|
+
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
11167
|
+
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
11166
11168
|
var REPLACE_RETURN_BYTES = 96;
|
|
11167
11169
|
var SHAPE_RETURN_BYTES = 256;
|
|
11168
11170
|
var REPLACE_CHUNK_BYTES = 48;
|
|
@@ -11571,7 +11573,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
11571
11573
|
var DECISION_LABEL_JOIN = " | ";
|
|
11572
11574
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
11573
11575
|
var RELEASE_BRANCH = "release";
|
|
11574
|
-
var BUNDLE_SHA = true ? "
|
|
11576
|
+
var BUNDLE_SHA = true ? "83f2da691359eaaf61f7baba841dea1942d3ccc1" : void 0;
|
|
11575
11577
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
11576
11578
|
var DOCTOR_LABEL = Object.freeze({
|
|
11577
11579
|
D1: "version",
|
|
@@ -11835,6 +11837,7 @@ var REGEX_SPECIAL_CHARS = ".*+?^${}()|[]\\";
|
|
|
11835
11837
|
var REGEX_ESCAPE = "\\";
|
|
11836
11838
|
var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
|
|
11837
11839
|
var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
|
|
11840
|
+
var D5_READ_RANGE_DETAIL = "PostToolUse Read with offset/limit over the replace trigger came back replaced: a bounded Read must reach the model whole";
|
|
11838
11841
|
var D5_READ_SHAPE_DETAIL = `PostToolUse Read replace is not Read's output shape {type:"text", file:{filePath, content, numLines, startLine, totalLines}}: Claude Code drops it and shows a hook warning`;
|
|
11839
11842
|
function D5_SLOW_DETAIL(ms) {
|
|
11840
11843
|
return `hook round trip took ${ms} ms over bare node, over ${HOOK_P95_MS} ms`;
|
|
@@ -11893,6 +11896,11 @@ var V1_CACHE_HEAL_NAME = "context-mode-cache-heal";
|
|
|
11893
11896
|
var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
|
|
11894
11897
|
var V1_STATUSLINE_COMMAND = "context-mode statusline";
|
|
11895
11898
|
var V1_PI_PACKAGE = "npm:context-mode";
|
|
11899
|
+
var PI_NPM_DIR = "npm";
|
|
11900
|
+
var PI_NODE_MODULES_DIR = "node_modules";
|
|
11901
|
+
var PI_PACKAGE_JSON_FILE = "package.json";
|
|
11902
|
+
var PI_LIST_COMMAND = "pi list";
|
|
11903
|
+
var PI_CURRENT_MAJOR = 2;
|
|
11896
11904
|
var V1_OPENCODE_PLUGIN_SPEC = "context-mode";
|
|
11897
11905
|
var V1_TMP_PREFIX = "context-mode-";
|
|
11898
11906
|
var V1_TOML_SECTION_ROOT = "mcp_servers";
|
|
@@ -12109,7 +12117,7 @@ var PI_EVENTS = {
|
|
|
12109
12117
|
tool_call: { event: "PreToolUse" },
|
|
12110
12118
|
tool_result: { event: "PostToolUse" }
|
|
12111
12119
|
};
|
|
12112
|
-
var NATIVE_TO_CANONICAL = { bash: "Bash", read: "Read" };
|
|
12120
|
+
var NATIVE_TO_CANONICAL = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
|
|
12113
12121
|
function record2(v) {
|
|
12114
12122
|
return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
|
|
12115
12123
|
}
|
|
@@ -12572,6 +12580,14 @@ function canonicalName3(name) {
|
|
|
12572
12580
|
if (Object.hasOwn(NATIVE_TO_CANONICAL4, name)) return NATIVE_TO_CANONICAL4[name];
|
|
12573
12581
|
return name;
|
|
12574
12582
|
}
|
|
12583
|
+
var isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
12584
|
+
function viewRange(name, input) {
|
|
12585
|
+
const r = input.view_range;
|
|
12586
|
+
if (name !== "view" || !Array.isArray(r) || !isNum(r[0])) return input;
|
|
12587
|
+
const out = { ...input, offset: r[0] };
|
|
12588
|
+
if (isNum(r[1]) && r[1] >= r[0]) out.limit = r[1] - r[0] + 1;
|
|
12589
|
+
return out;
|
|
12590
|
+
}
|
|
12575
12591
|
function readArgs(v) {
|
|
12576
12592
|
if (isRecord(v)) return v;
|
|
12577
12593
|
if (typeof v !== "string") return {};
|
|
@@ -12616,7 +12632,7 @@ function decode6(raw) {
|
|
|
12616
12632
|
if (event === "UserPromptSubmit" && typeof raw.prompt === "string") ev.prompt = raw.prompt;
|
|
12617
12633
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
12618
12634
|
const toolName2 = String(raw[k.tool] ?? "");
|
|
12619
|
-
const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: readArgs(raw[k.args]) };
|
|
12635
|
+
const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: viewRange(toolName2, readArgs(raw[k.args])) };
|
|
12620
12636
|
ev.tool = tool;
|
|
12621
12637
|
}
|
|
12622
12638
|
if (event === "PostToolUse") ev.result = readResult4(raw[k.result], native.casing, native.failure);
|
|
@@ -12664,18 +12680,18 @@ function canonicalName4(name) {
|
|
|
12664
12680
|
if (sep4 <= 0 || sep4 === rest.length - 1) return name;
|
|
12665
12681
|
return "mcp:" + rest.slice(0, sep4) + ":" + rest.slice(sep4 + MCP_SEP2.length);
|
|
12666
12682
|
}
|
|
12667
|
-
var
|
|
12683
|
+
var isNum2 = (v) => typeof v === "number" && Number.isFinite(v);
|
|
12668
12684
|
function policyInput(name, canonical, input) {
|
|
12669
12685
|
if (canonical === "Read" && READ_TOOL_NAMES.includes(name)) {
|
|
12670
12686
|
const out = { ...input };
|
|
12671
12687
|
if (name === "read_file") {
|
|
12672
12688
|
if (typeof input.filePath === "string") out.file_path = input.filePath;
|
|
12673
|
-
if (
|
|
12674
|
-
if (
|
|
12675
|
-
} else if (Array.isArray(input.view_range) &&
|
|
12689
|
+
if (isNum2(input.startLine)) out.offset = input.startLine;
|
|
12690
|
+
if (isNum2(input.startLine) && isNum2(input.endLine) && input.endLine >= input.startLine) out.limit = input.endLine - input.startLine + 1;
|
|
12691
|
+
} else if (Array.isArray(input.view_range) && isNum2(input.view_range[0])) {
|
|
12676
12692
|
out.offset = input.view_range[0];
|
|
12677
12693
|
const end = input.view_range[1];
|
|
12678
|
-
if (
|
|
12694
|
+
if (isNum2(end) && end >= input.view_range[0]) out.limit = end - input.view_range[0] + 1;
|
|
12679
12695
|
}
|
|
12680
12696
|
return out;
|
|
12681
12697
|
}
|
|
@@ -13077,8 +13093,9 @@ var ADAPTERS = Object.freeze([
|
|
|
13077
13093
|
installMode: "in-process",
|
|
13078
13094
|
projectSource: "pi:ctx.cwd",
|
|
13079
13095
|
toolNamePrefix: TOOL_NAME_PREFIX,
|
|
13080
|
-
nativeTools: { shell: ["bash"], read: ["read"] },
|
|
13096
|
+
nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
|
|
13081
13097
|
execReadOnlyHint: false,
|
|
13098
|
+
// D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
|
|
13082
13099
|
eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
|
|
13083
13100
|
compactDelivery: "pi-flag",
|
|
13084
13101
|
compactSummary: "none",
|
|
@@ -14477,21 +14494,21 @@ function kiroDirOf(env, home, platform = process.platform) {
|
|
|
14477
14494
|
if (dir === void 0 || dir === "" || !p.isAbsolute(dir)) return fallback;
|
|
14478
14495
|
if (platform === "win32" && p.parse(dir).root.length < 2) return fallback;
|
|
14479
14496
|
const abs = p.resolve(dir);
|
|
14480
|
-
const
|
|
14481
|
-
const target =
|
|
14497
|
+
const real3 = platform === process.platform ? realOrSelf : (x) => x;
|
|
14498
|
+
const target = real3(abs);
|
|
14482
14499
|
if (p.parse(target).root === target) return fallback;
|
|
14483
|
-
const up = p.relative(target,
|
|
14500
|
+
const up = p.relative(target, real3(p.resolve(home)));
|
|
14484
14501
|
if (!p.isAbsolute(up) && up.split(p.sep)[0] !== "..") return fallback;
|
|
14485
14502
|
return abs;
|
|
14486
14503
|
}
|
|
14487
|
-
function realOrSelf(
|
|
14504
|
+
function realOrSelf(path8) {
|
|
14488
14505
|
const tail = [];
|
|
14489
|
-
for (let at2 =
|
|
14506
|
+
for (let at2 = path8; ; ) {
|
|
14490
14507
|
try {
|
|
14491
14508
|
return join(realpathSync.native(at2), ...tail.reverse());
|
|
14492
14509
|
} catch {
|
|
14493
14510
|
const up = dirname(at2);
|
|
14494
|
-
if (up === at2) return
|
|
14511
|
+
if (up === at2) return path8;
|
|
14495
14512
|
tail.push(basename(at2));
|
|
14496
14513
|
at2 = up;
|
|
14497
14514
|
}
|
|
@@ -14616,10 +14633,10 @@ function readPluginAgent(claudeDir, type) {
|
|
|
14616
14633
|
}
|
|
14617
14634
|
return null;
|
|
14618
14635
|
}
|
|
14619
|
-
function readAgentFile(
|
|
14636
|
+
function readAgentFile(path8) {
|
|
14620
14637
|
let text;
|
|
14621
14638
|
try {
|
|
14622
|
-
text = readFileSync(
|
|
14639
|
+
text = readFileSync(path8, "utf8");
|
|
14623
14640
|
} catch {
|
|
14624
14641
|
return null;
|
|
14625
14642
|
}
|
|
@@ -14882,12 +14899,12 @@ function readUserDeny(projectDir, agent) {
|
|
|
14882
14899
|
}
|
|
14883
14900
|
return out;
|
|
14884
14901
|
}
|
|
14885
|
-
function tokenize(glob,
|
|
14902
|
+
function tokenize(glob, path8) {
|
|
14886
14903
|
const toks = [];
|
|
14887
14904
|
let i = 0;
|
|
14888
14905
|
while (i < glob.length) {
|
|
14889
14906
|
const c = glob[i];
|
|
14890
|
-
if (c === "*" &&
|
|
14907
|
+
if (c === "*" && path8 && glob[i + 1] === "*") {
|
|
14891
14908
|
const dir = glob[i + "**".length] === "/";
|
|
14892
14909
|
toks.push({ t: dir ? "globstarDir" : "globstar" });
|
|
14893
14910
|
i += dir ? "**/".length : "**".length;
|
|
@@ -14901,8 +14918,8 @@ function tokenize(glob, path7) {
|
|
|
14901
14918
|
}
|
|
14902
14919
|
return toks;
|
|
14903
14920
|
}
|
|
14904
|
-
function globMatch(glob, text,
|
|
14905
|
-
const toks = tokenize(glob,
|
|
14921
|
+
function globMatch(glob, text, path8) {
|
|
14922
|
+
const toks = tokenize(glob, path8);
|
|
14906
14923
|
const n = text.length;
|
|
14907
14924
|
let next = new Uint8Array(n + 1);
|
|
14908
14925
|
next[n] = 1;
|
|
@@ -14918,10 +14935,10 @@ function globMatch(glob, text, path7) {
|
|
|
14918
14935
|
cur[j] = has3 && ch === tok.c ? next[j + 1] : 0;
|
|
14919
14936
|
break;
|
|
14920
14937
|
case "any1":
|
|
14921
|
-
cur[j] = has3 && !(
|
|
14938
|
+
cur[j] = has3 && !(path8 && ch === "/") ? next[j + 1] : 0;
|
|
14922
14939
|
break;
|
|
14923
14940
|
case "star":
|
|
14924
|
-
cur[j] = next[j] || (has3 && !(
|
|
14941
|
+
cur[j] = next[j] || (has3 && !(path8 && ch === "/") ? cur[j + 1] : 0);
|
|
14925
14942
|
break;
|
|
14926
14943
|
case "globstar":
|
|
14927
14944
|
cur[j] = next[j] || (has3 ? cur[j + 1] : 0);
|
|
@@ -15001,8 +15018,8 @@ var READ_DENY_TEMPLATE = 'context-mode: {size}-byte file, over the one-read limi
|
|
|
15001
15018
|
// src/core/policy/read-deny.ts
|
|
15002
15019
|
var SIZE = "{size}";
|
|
15003
15020
|
var PATH = "{path}";
|
|
15004
|
-
function READ_DENY_MESSAGE(
|
|
15005
|
-
return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(
|
|
15021
|
+
function READ_DENY_MESSAGE(path8, size, prefix = "") {
|
|
15022
|
+
return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path8);
|
|
15006
15023
|
}
|
|
15007
15024
|
|
|
15008
15025
|
// src/core/policy/decide.ts
|
|
@@ -15710,9 +15727,9 @@ function readUserVersion(raw) {
|
|
|
15710
15727
|
const row5 = raw.prepare("PRAGMA user_version").get();
|
|
15711
15728
|
return row5.user_version;
|
|
15712
15729
|
}
|
|
15713
|
-
function createAtomically(sqlite,
|
|
15730
|
+
function createAtomically(sqlite, path8) {
|
|
15714
15731
|
const { randomUUID: randomUUID2 } = process.getBuiltinModule("node:crypto");
|
|
15715
|
-
const tmp =
|
|
15732
|
+
const tmp = path8 + "." + randomUUID2() + DB_TMP_SUFFIX;
|
|
15716
15733
|
try {
|
|
15717
15734
|
const raw = new sqlite.DatabaseSync(tmp, { timeout: DB_TIMEOUT_MS });
|
|
15718
15735
|
try {
|
|
@@ -15721,7 +15738,7 @@ function createAtomically(sqlite, path7) {
|
|
|
15721
15738
|
raw.close();
|
|
15722
15739
|
}
|
|
15723
15740
|
try {
|
|
15724
|
-
linkSync(tmp,
|
|
15741
|
+
linkSync(tmp, path8);
|
|
15725
15742
|
} catch (err) {
|
|
15726
15743
|
if (err.code !== "EEXIST") throw err;
|
|
15727
15744
|
}
|
|
@@ -15729,11 +15746,11 @@ function createAtomically(sqlite, path7) {
|
|
|
15729
15746
|
for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
|
|
15730
15747
|
}
|
|
15731
15748
|
}
|
|
15732
|
-
function openWritable(sqlite,
|
|
15749
|
+
function openWritable(sqlite, path8) {
|
|
15733
15750
|
let raw = null;
|
|
15734
15751
|
try {
|
|
15735
|
-
if (!existsSync2(
|
|
15736
|
-
raw = new sqlite.DatabaseSync(
|
|
15752
|
+
if (!existsSync2(path8)) createAtomically(sqlite, path8);
|
|
15753
|
+
raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS });
|
|
15737
15754
|
applyMigrations(raw, readUserVersion(raw));
|
|
15738
15755
|
return raw;
|
|
15739
15756
|
} catch (err) {
|
|
@@ -15741,8 +15758,8 @@ function openWritable(sqlite, path7) {
|
|
|
15741
15758
|
throw err;
|
|
15742
15759
|
}
|
|
15743
15760
|
}
|
|
15744
|
-
function openReadOnly(sqlite,
|
|
15745
|
-
const raw = new sqlite.DatabaseSync(
|
|
15761
|
+
function openReadOnly(sqlite, path8) {
|
|
15762
|
+
const raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
|
|
15746
15763
|
try {
|
|
15747
15764
|
const found = readUserVersion(raw);
|
|
15748
15765
|
if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
|
|
@@ -15756,20 +15773,20 @@ async function openDb(project, opts) {
|
|
|
15756
15773
|
if (isBelow(process.version, NODE_MIN)) throw new CtxError("NODE_TOO_OLD", { v: process.version });
|
|
15757
15774
|
const sqlite = await loadSqlite();
|
|
15758
15775
|
mkdirSync2(project.projectDir, { recursive: true });
|
|
15759
|
-
const
|
|
15760
|
-
const sibling = existsSync2(
|
|
15761
|
-
if (sibling && !existsSync2(
|
|
15776
|
+
const path8 = project.dbPath;
|
|
15777
|
+
const sibling = existsSync2(path8 + DB_WAL_SUFFIX) || existsSync2(path8 + DB_SHM_SUFFIX);
|
|
15778
|
+
if (sibling && !existsSync2(path8)) {
|
|
15762
15779
|
throw new CtxError("DB_GONE");
|
|
15763
15780
|
}
|
|
15764
15781
|
try {
|
|
15765
15782
|
let raw;
|
|
15766
15783
|
if (opts?.readOnly === true) {
|
|
15767
|
-
if (!existsSync2(
|
|
15768
|
-
raw = openReadOnly(sqlite,
|
|
15784
|
+
if (!existsSync2(path8)) openWritable(sqlite, path8).close();
|
|
15785
|
+
raw = openReadOnly(sqlite, path8);
|
|
15769
15786
|
} else {
|
|
15770
|
-
raw = openWritable(sqlite,
|
|
15787
|
+
raw = openWritable(sqlite, path8);
|
|
15771
15788
|
}
|
|
15772
|
-
return { raw, projectKey: project.projectKey, path:
|
|
15789
|
+
return { raw, projectKey: project.projectKey, path: path8, ...opts?.readOnly === true ? { readOnly: true } : {} };
|
|
15773
15790
|
} catch (err) {
|
|
15774
15791
|
if (isCorrupt(err)) throw new CtxError("DB_CORRUPT");
|
|
15775
15792
|
throw err;
|
|
@@ -18564,8 +18581,8 @@ function buildCandidates(rows, sessionId) {
|
|
|
18564
18581
|
edits.set(r.path, { row: r, count: (edits.get(r.path)?.count ?? 0) + 1 });
|
|
18565
18582
|
}
|
|
18566
18583
|
const changedFiles = [];
|
|
18567
|
-
for (const [
|
|
18568
|
-
const c = make("changed_files", e.row, "edited " +
|
|
18584
|
+
for (const [path8, e] of edits) {
|
|
18585
|
+
const c = make("changed_files", e.row, "edited " + path8 + " x" + e.count, e.count, path8);
|
|
18569
18586
|
changedFiles.push({ ...c, editCount: e.count });
|
|
18570
18587
|
}
|
|
18571
18588
|
changedFiles.sort((a, b) => a.seq - b.seq);
|
|
@@ -19899,9 +19916,13 @@ async function preToolUse(ev, row5, project, env) {
|
|
|
19899
19916
|
const userDeny = readUserDeny(project.worktree, ev.agent);
|
|
19900
19917
|
const decision0 = decide(ev, row5, userDeny);
|
|
19901
19918
|
let decision = decision0;
|
|
19902
|
-
if (decision0.kind === "deny" && isSubagentCall(ev)) {
|
|
19903
|
-
const
|
|
19904
|
-
|
|
19919
|
+
if (decision0.kind === "deny" && isSubagentCall(ev) && !isUserPolicyDeny(decision0.reason, row5)) {
|
|
19920
|
+
const set3 = toolSetForAgentType(ev, { projectDir: project.worktree, env });
|
|
19921
|
+
const subCase = pickSubagentCase(ev, set3);
|
|
19922
|
+
const tool = ev.tool;
|
|
19923
|
+
const runs = set3 !== null || (ev.agentType ?? "") !== "" && hasReplace(row5);
|
|
19924
|
+
if (subCase === "B" && tool !== void 0 && isShell(tool, row5)) decision = caseB(ev, row5, decision0, userDeny);
|
|
19925
|
+
else if (subCase !== "A" && runs) decision = ALLOW2;
|
|
19905
19926
|
}
|
|
19906
19927
|
return decision;
|
|
19907
19928
|
}
|
|
@@ -19998,6 +20019,7 @@ async function postToolUse(ev, row5, project, env, settle3) {
|
|
|
19998
20019
|
}
|
|
19999
20020
|
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
20000
20021
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
20022
|
+
if (boundedRead(tool)) return ALLOW2;
|
|
20001
20023
|
if (result.keep === true) return ALLOW2;
|
|
20002
20024
|
if (!hasReplace(row5)) return ALLOW2;
|
|
20003
20025
|
let label2;
|
|
@@ -20029,6 +20051,9 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
|
20029
20051
|
const selected = selectChunksInMemory(chunks, intent, budget, label2, rankQuery);
|
|
20030
20052
|
return { kind: "replace", output: selected.more !== null ? replaceOutput(selected.text, handleLine) : selected.text };
|
|
20031
20053
|
}
|
|
20054
|
+
function boundedRead(tool) {
|
|
20055
|
+
return RANGE_READ_TOOLS.includes(tool.canonicalName) && READ_RANGE_KEYS.some((k) => tool.input[k] !== void 0 && tool.input[k] !== null);
|
|
20056
|
+
}
|
|
20032
20057
|
function replaceOutput(body, handleLine) {
|
|
20033
20058
|
return body === "" ? handleLine : body + "\n" + handleLine;
|
|
20034
20059
|
}
|
|
@@ -20348,19 +20373,19 @@ function steeringFiles(worktree) {
|
|
|
20348
20373
|
function readAutoMemory(project) {
|
|
20349
20374
|
const rows = [];
|
|
20350
20375
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
20351
|
-
const
|
|
20352
|
-
if (!isInside(project.worktree,
|
|
20376
|
+
const path8 = join7(project.worktree, ...segs);
|
|
20377
|
+
if (!isInside(project.worktree, path8)) continue;
|
|
20353
20378
|
try {
|
|
20354
|
-
const st = statSync4(
|
|
20379
|
+
const st = statSync4(path8);
|
|
20355
20380
|
if (!st.isFile()) continue;
|
|
20356
20381
|
rows.push({
|
|
20357
20382
|
origin: "memory",
|
|
20358
20383
|
ts: Math.trunc(st.mtimeMs),
|
|
20359
20384
|
seq: null,
|
|
20360
20385
|
sourceId: null,
|
|
20361
|
-
path:
|
|
20386
|
+
path: path8,
|
|
20362
20387
|
label: segs.join("/"),
|
|
20363
|
-
text: readFileSync5(
|
|
20388
|
+
text: readFileSync5(path8, "utf8")
|
|
20364
20389
|
});
|
|
20365
20390
|
} catch {
|
|
20366
20391
|
}
|
|
@@ -20930,7 +20955,7 @@ var ctxBatch = Object.freeze({
|
|
|
20930
20955
|
});
|
|
20931
20956
|
|
|
20932
20957
|
// src/core/tools/doctor.ts
|
|
20933
|
-
import { readdirSync as readdirSync6, readFileSync as
|
|
20958
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync14, existsSync as existsSync15 } from "node:fs";
|
|
20934
20959
|
import { basename as basename5, join as join17 } from "node:path";
|
|
20935
20960
|
|
|
20936
20961
|
// src/core/ops/bundle-dir.ts
|
|
@@ -20956,7 +20981,7 @@ function ownBundleDir() {
|
|
|
20956
20981
|
}
|
|
20957
20982
|
|
|
20958
20983
|
// src/core/ops/doctor-config.ts
|
|
20959
|
-
import { existsSync as
|
|
20984
|
+
import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
|
|
20960
20985
|
import { join as join12 } from "node:path";
|
|
20961
20986
|
|
|
20962
20987
|
// src/core/ops/detect-v1.ts
|
|
@@ -23075,15 +23100,15 @@ function atomicWriteFile(file2, text, opts = {}) {
|
|
|
23075
23100
|
}
|
|
23076
23101
|
|
|
23077
23102
|
// src/core/ops/host-config.ts
|
|
23078
|
-
function formatOf(
|
|
23079
|
-
if (
|
|
23080
|
-
if (
|
|
23103
|
+
function formatOf(path8) {
|
|
23104
|
+
if (path8.endsWith(JSONC_EXT)) return "jsonc";
|
|
23105
|
+
if (path8.endsWith(TOML_EXT)) return "toml";
|
|
23081
23106
|
return "json";
|
|
23082
23107
|
}
|
|
23083
|
-
function readHostConfig(agent,
|
|
23084
|
-
let file2 =
|
|
23108
|
+
function readHostConfig(agent, path8) {
|
|
23109
|
+
let file2 = path8;
|
|
23085
23110
|
if (agent === "opencode") {
|
|
23086
|
-
const jsonc = join9(dirname6(
|
|
23111
|
+
const jsonc = join9(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
|
|
23087
23112
|
if (existsSync4(jsonc)) file2 = jsonc;
|
|
23088
23113
|
}
|
|
23089
23114
|
const raw = existsSync4(file2) ? readFileSync6(file2, "utf8") : "";
|
|
@@ -23247,14 +23272,14 @@ function scanToml(text) {
|
|
|
23247
23272
|
continue;
|
|
23248
23273
|
}
|
|
23249
23274
|
if (!node3.resolvedKey.every((seg) => typeof seg === "string")) continue;
|
|
23250
|
-
const
|
|
23251
|
-
for (const kv of node3.body) addKey(
|
|
23275
|
+
const path8 = node3.resolvedKey;
|
|
23276
|
+
for (const kv of node3.body) addKey(path8, kv);
|
|
23252
23277
|
if (node3.kind !== "standard") continue;
|
|
23253
23278
|
const start = lineStartOf(text, node3.range[0]);
|
|
23254
23279
|
const headEnd = lineEndOf(text, node3.key.range[1]);
|
|
23255
23280
|
const last2 = node3.body[node3.body.length - 1];
|
|
23256
23281
|
tables.push({
|
|
23257
|
-
path:
|
|
23282
|
+
path: path8,
|
|
23258
23283
|
header: text.slice(start, text[headEnd - 1] === "\n" ? headEnd - 1 : headEnd),
|
|
23259
23284
|
start,
|
|
23260
23285
|
end: last2 === void 0 ? headEnd : lineEndOf(text, last2.range[1])
|
|
@@ -23265,16 +23290,16 @@ function scanToml(text) {
|
|
|
23265
23290
|
function tomlTableSpans(text) {
|
|
23266
23291
|
return scanToml(text).tables;
|
|
23267
23292
|
}
|
|
23268
|
-
function parseHostConfig(agent,
|
|
23293
|
+
function parseHostConfig(agent, path8, text, format) {
|
|
23269
23294
|
try {
|
|
23270
23295
|
return format === "toml" ? scanToml(text).value : scanJson(text, format).value;
|
|
23271
23296
|
} catch {
|
|
23272
|
-
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path:
|
|
23297
|
+
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path8, format });
|
|
23273
23298
|
}
|
|
23274
23299
|
}
|
|
23275
|
-
function hostConfigValueAt(value,
|
|
23300
|
+
function hostConfigValueAt(value, path8) {
|
|
23276
23301
|
let cur = value;
|
|
23277
|
-
for (const seg of
|
|
23302
|
+
for (const seg of path8) {
|
|
23278
23303
|
if (!isPlainObject3(cur)) return void 0;
|
|
23279
23304
|
cur = cur[seg];
|
|
23280
23305
|
}
|
|
@@ -23307,32 +23332,32 @@ function indentUnit(root, clean) {
|
|
|
23307
23332
|
function render(value, unit, base) {
|
|
23308
23333
|
return JSON.stringify(value, null, unit).split("\n").join("\n" + base);
|
|
23309
23334
|
}
|
|
23310
|
-
function nest(
|
|
23335
|
+
function nest(path8, value) {
|
|
23311
23336
|
let out = value;
|
|
23312
|
-
for (let k =
|
|
23337
|
+
for (let k = path8.length - 1; k >= 0; k -= 1) out = { [path8[k]]: out };
|
|
23313
23338
|
return out;
|
|
23314
23339
|
}
|
|
23315
|
-
function setJsonText(text, format,
|
|
23340
|
+
function setJsonText(text, format, path8, value) {
|
|
23316
23341
|
const doc = scanJson(text, format);
|
|
23317
23342
|
const unit = indentUnit(doc.root, doc.clean);
|
|
23318
|
-
if (doc.root === null) return render(nest(
|
|
23343
|
+
if (doc.root === null) return render(nest(path8, value), unit, "") + "\n";
|
|
23319
23344
|
let node3 = doc.root;
|
|
23320
23345
|
let depth = 0;
|
|
23321
|
-
while (depth <
|
|
23322
|
-
const hit = node3.members.find((m) => m.key ===
|
|
23346
|
+
while (depth < path8.length && node3.kind === "object") {
|
|
23347
|
+
const hit = node3.members.find((m) => m.key === path8[depth]);
|
|
23323
23348
|
if (hit === void 0) break;
|
|
23324
23349
|
node3 = hit.node;
|
|
23325
23350
|
depth += 1;
|
|
23326
23351
|
}
|
|
23327
|
-
if (depth ===
|
|
23352
|
+
if (depth === path8.length) {
|
|
23328
23353
|
return text.slice(0, node3.start) + render(value, unit, lineIndent(doc.clean, node3.start)) + text.slice(node3.end);
|
|
23329
23354
|
}
|
|
23330
|
-
if (node3.kind !== "object") throw new SyntaxError("not an object at " +
|
|
23331
|
-
const rest = nest(
|
|
23355
|
+
if (node3.kind !== "object") throw new SyntaxError("not an object at " + path8.slice(0, depth).join("."));
|
|
23356
|
+
const rest = nest(path8.slice(depth + 1), value);
|
|
23332
23357
|
const last2 = node3.members[node3.members.length - 1];
|
|
23333
23358
|
if (last2 === void 0) {
|
|
23334
23359
|
const base2 = lineIndent(doc.clean, node3.start);
|
|
23335
|
-
const member2 = "\n" + base2 + unit + JSON.stringify(
|
|
23360
|
+
const member2 = "\n" + base2 + unit + JSON.stringify(path8[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
|
|
23336
23361
|
return text.slice(0, node3.start + 1) + member2 + text.slice(node3.end - 1);
|
|
23337
23362
|
}
|
|
23338
23363
|
const base = lineIndent(doc.clean, last2.keyStart);
|
|
@@ -23340,7 +23365,7 @@ function setJsonText(text, format, path7, value) {
|
|
|
23340
23365
|
while (" \r\n".includes(doc.clean[at2])) at2 += 1;
|
|
23341
23366
|
const trailing = doc.clean[at2] === ",";
|
|
23342
23367
|
const insertAt = trailing ? at2 + 1 : last2.node.end;
|
|
23343
|
-
const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(
|
|
23368
|
+
const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path8[depth]) + ": " + render(rest, unit, base);
|
|
23344
23369
|
return text.slice(0, insertAt) + member + text.slice(insertAt);
|
|
23345
23370
|
}
|
|
23346
23371
|
function tomlScalar(v) {
|
|
@@ -23358,17 +23383,17 @@ function tomlHeaderKey(seg) {
|
|
|
23358
23383
|
}
|
|
23359
23384
|
return seg;
|
|
23360
23385
|
}
|
|
23361
|
-
function tomlBlock(
|
|
23362
|
-
let out = "[" +
|
|
23386
|
+
function tomlBlock(path8, value) {
|
|
23387
|
+
let out = "[" + path8.map(tomlHeaderKey).join(".") + "]\n";
|
|
23363
23388
|
const subs = [];
|
|
23364
23389
|
for (const [k, v] of Object.entries(value)) {
|
|
23365
|
-
if (isPlainObject3(v)) subs.push(tomlBlock([...
|
|
23390
|
+
if (isPlainObject3(v)) subs.push(tomlBlock([...path8, k], v));
|
|
23366
23391
|
else out += tomlHeaderKey(k) + " = " + tomlScalar(v) + "\n";
|
|
23367
23392
|
}
|
|
23368
23393
|
return [out, ...subs].join("\n");
|
|
23369
23394
|
}
|
|
23370
|
-
function under(
|
|
23371
|
-
return
|
|
23395
|
+
function under(path8, prefix) {
|
|
23396
|
+
return path8.length >= prefix.length && prefix.every((seg, k) => path8[k] === seg);
|
|
23372
23397
|
}
|
|
23373
23398
|
function keyLineRange(text, k) {
|
|
23374
23399
|
const ls = lineStartOf(text, k.start);
|
|
@@ -23385,10 +23410,10 @@ function withValueAt(root, rel, value) {
|
|
|
23385
23410
|
else base[rel[0]] = next;
|
|
23386
23411
|
return base;
|
|
23387
23412
|
}
|
|
23388
|
-
function replaceToml(text, doc,
|
|
23389
|
-
const block = value === void 0 ? "" : tomlBlock(
|
|
23390
|
-
const owned = doc.tables.filter((t) => under(t.path,
|
|
23391
|
-
const cuts = doc.keys.filter((k) => under(k.full,
|
|
23413
|
+
function replaceToml(text, doc, path8, value) {
|
|
23414
|
+
const block = value === void 0 ? "" : tomlBlock(path8, value);
|
|
23415
|
+
const owned = doc.tables.filter((t) => under(t.path, path8));
|
|
23416
|
+
const cuts = doc.keys.filter((k) => under(k.full, path8) && !under(k.base, path8)).map((k) => [...keyLineRange(text, k), ""]);
|
|
23392
23417
|
owned.forEach((t, n) => cuts.push([t.start, t.end, n === 0 ? block : ""]));
|
|
23393
23418
|
cuts.sort((a, b) => b[0] - a[0]);
|
|
23394
23419
|
let out = text;
|
|
@@ -23398,27 +23423,27 @@ function replaceToml(text, doc, path7, value) {
|
|
|
23398
23423
|
return out + sep4 + block;
|
|
23399
23424
|
}
|
|
23400
23425
|
var tableLike = (v) => v === void 0 || isPlainObject3(v);
|
|
23401
|
-
function setTomlText(text,
|
|
23426
|
+
function setTomlText(text, path8, value) {
|
|
23402
23427
|
if (value !== void 0 && !isPlainObject3(value)) throw new SyntaxError("TOML edits replace a whole table");
|
|
23403
23428
|
const doc = scanToml(text);
|
|
23404
|
-
const cur = hostConfigValueAt(doc.value,
|
|
23429
|
+
const cur = hostConfigValueAt(doc.value, path8);
|
|
23405
23430
|
if (sameValue(cur, value)) return text;
|
|
23406
|
-
const inline = doc.keys.find((k) => k.inline && k.full.length <
|
|
23431
|
+
const inline = doc.keys.find((k) => k.inline && k.full.length < path8.length && under(path8, k.full));
|
|
23407
23432
|
if (inline !== void 0) {
|
|
23408
|
-
const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full),
|
|
23433
|
+
const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path8.slice(inline.full.length), value);
|
|
23409
23434
|
return replaceToml(text, doc, inline.full, whole2);
|
|
23410
23435
|
}
|
|
23411
23436
|
if (isPlainObject3(cur) && isPlainObject3(value)) {
|
|
23412
23437
|
const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
|
|
23413
23438
|
if (names.every((k) => tableLike(cur[k]) && tableLike(value[k]))) {
|
|
23414
23439
|
let out = text;
|
|
23415
|
-
for (const k of names) out = setTomlText(out, [...
|
|
23440
|
+
for (const k of names) out = setTomlText(out, [...path8, k], value[k]);
|
|
23416
23441
|
return out;
|
|
23417
23442
|
}
|
|
23418
23443
|
}
|
|
23419
|
-
return replaceToml(text, doc,
|
|
23444
|
+
return replaceToml(text, doc, path8, value);
|
|
23420
23445
|
}
|
|
23421
|
-
function setText(agent,
|
|
23446
|
+
function setText(agent, path8, text, format, key, value) {
|
|
23422
23447
|
try {
|
|
23423
23448
|
if (format !== "toml") return setJsonText(text, format, key, value);
|
|
23424
23449
|
const out = setTomlText(text, key, value);
|
|
@@ -23427,7 +23452,7 @@ function setText(agent, path7, text, format, key, value) {
|
|
|
23427
23452
|
if (!sameValue(landed, value) && !(emptyTable && landed === void 0)) throw new SyntaxError("edit did not land");
|
|
23428
23453
|
return out;
|
|
23429
23454
|
} catch {
|
|
23430
|
-
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path:
|
|
23455
|
+
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path8, format });
|
|
23431
23456
|
}
|
|
23432
23457
|
}
|
|
23433
23458
|
function serverScript() {
|
|
@@ -23474,14 +23499,14 @@ function ownTargets(agent, accept) {
|
|
|
23474
23499
|
if (agent === "pi") return [listTarget(PI_PACKAGES_KEY, PI_GIT_PACKAGE, V1_PI_PACKAGE)];
|
|
23475
23500
|
return [];
|
|
23476
23501
|
}
|
|
23477
|
-
function applyEdits(agent,
|
|
23478
|
-
const parsed = parseHostConfig(agent,
|
|
23502
|
+
function applyEdits(agent, path8, text, format, wanted) {
|
|
23503
|
+
const parsed = parseHostConfig(agent, path8, text, format);
|
|
23479
23504
|
let out = text;
|
|
23480
23505
|
const edits = [];
|
|
23481
23506
|
for (const [key, after] of wanted) {
|
|
23482
23507
|
const before = hostConfigValueAt(parsed, key);
|
|
23483
23508
|
if (sameValue(before, after)) continue;
|
|
23484
|
-
out = setText(agent,
|
|
23509
|
+
out = setText(agent, path8, out, format, key, after);
|
|
23485
23510
|
edits.push({ path: key.join("."), before, after });
|
|
23486
23511
|
}
|
|
23487
23512
|
return { text: out, format, edits };
|
|
@@ -23502,7 +23527,7 @@ function writeHostConfigEdit(_requested, current, patch) {
|
|
|
23502
23527
|
// src/core/ops/detect-v1.ts
|
|
23503
23528
|
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
23504
23529
|
var keyPath = (...parts) => parts.join(".");
|
|
23505
|
-
var finding = (file2,
|
|
23530
|
+
var finding = (file2, path8, reason) => ({ file: file2, path: path8, reason });
|
|
23506
23531
|
function stripJsonc(text) {
|
|
23507
23532
|
let out = "";
|
|
23508
23533
|
let inStr = false;
|
|
@@ -23707,12 +23732,17 @@ function scanKiro(agentHome, project, out) {
|
|
|
23707
23732
|
}
|
|
23708
23733
|
dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23709
23734
|
}
|
|
23735
|
+
function piNpmIsCurrent(piAgentDir) {
|
|
23736
|
+
const doc = readJson(join10(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
23737
|
+
const version4 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
23738
|
+
return Number.parseInt(version4, 10) >= PI_CURRENT_MAJOR;
|
|
23739
|
+
}
|
|
23710
23740
|
function scanPi(piAgentDir, agentHome, out) {
|
|
23711
23741
|
const file2 = join10(piAgentDir, SETTINGS_FILE);
|
|
23712
23742
|
const doc = readJson(file2);
|
|
23713
23743
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
23714
23744
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
23715
|
-
if (spec === V1_PI_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
23745
|
+
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
23716
23746
|
});
|
|
23717
23747
|
dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23718
23748
|
}
|
|
@@ -23809,8 +23839,8 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23809
23839
|
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
|
|
23810
23840
|
import { dirname as dirname7, isAbsolute as isAbsolute2, join as join11, sep as sep3 } from "node:path";
|
|
23811
23841
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
23812
|
-
function missing(agent,
|
|
23813
|
-
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path:
|
|
23842
|
+
function missing(agent, path8) {
|
|
23843
|
+
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
23814
23844
|
}
|
|
23815
23845
|
var parseOrNull = (text) => {
|
|
23816
23846
|
try {
|
|
@@ -23839,9 +23869,9 @@ function recordedInstalls(text) {
|
|
|
23839
23869
|
}
|
|
23840
23870
|
return out;
|
|
23841
23871
|
}
|
|
23842
|
-
var realOrNull = (
|
|
23872
|
+
var realOrNull = (path8) => {
|
|
23843
23873
|
try {
|
|
23844
|
-
return realpathSync4.native(
|
|
23874
|
+
return realpathSync4.native(path8);
|
|
23845
23875
|
} catch {
|
|
23846
23876
|
return null;
|
|
23847
23877
|
}
|
|
@@ -23939,12 +23969,81 @@ function candidate(adapter, env, worktree) {
|
|
|
23939
23969
|
}
|
|
23940
23970
|
}
|
|
23941
23971
|
function resolvePluginRoot(adapter, env, worktree) {
|
|
23942
|
-
const
|
|
23972
|
+
const path8 = candidate(adapter, env, worktree);
|
|
23943
23973
|
try {
|
|
23944
|
-
return realpathSync4.native(
|
|
23974
|
+
return realpathSync4.native(path8);
|
|
23945
23975
|
} catch {
|
|
23946
|
-
throw missing(adapter.id,
|
|
23976
|
+
throw missing(adapter.id, path8);
|
|
23977
|
+
}
|
|
23978
|
+
}
|
|
23979
|
+
|
|
23980
|
+
// src/setup/pi-gate.ts
|
|
23981
|
+
import { existsSync as existsSync7, readFileSync as readFileSync9, realpathSync as realpathSync5 } from "node:fs";
|
|
23982
|
+
import path4 from "node:path";
|
|
23983
|
+
var EXTENSIONS_KEY = "extensions";
|
|
23984
|
+
var PROJECT_DIR = ".pi";
|
|
23985
|
+
var TRUST_FILE = "trust.json";
|
|
23986
|
+
var ALWAYS = "always";
|
|
23987
|
+
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
23988
|
+
function load(file2) {
|
|
23989
|
+
if (!existsSync7(file2)) return void 0;
|
|
23990
|
+
try {
|
|
23991
|
+
return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync9(file2, "utf8")), "json") };
|
|
23992
|
+
} catch {
|
|
23993
|
+
return void 0;
|
|
23994
|
+
}
|
|
23995
|
+
}
|
|
23996
|
+
var real2 = (p) => {
|
|
23997
|
+
try {
|
|
23998
|
+
return realpathSync5(p);
|
|
23999
|
+
} catch {
|
|
24000
|
+
return path4.resolve(p);
|
|
24001
|
+
}
|
|
24002
|
+
};
|
|
24003
|
+
function sourceName(source) {
|
|
24004
|
+
let s = source;
|
|
24005
|
+
for (const p of SOURCE_PREFIXES) if (s.startsWith(p)) s = s.slice(p.length);
|
|
24006
|
+
const last2 = s.split("/").pop() ?? "";
|
|
24007
|
+
const at2 = last2.indexOf("@", 1);
|
|
24008
|
+
const name = at2 > 0 ? last2.slice(0, at2) : last2;
|
|
24009
|
+
return name.endsWith(".git") ? name.slice(0, -4) : name;
|
|
24010
|
+
}
|
|
24011
|
+
function isOwn(source, pkgDir) {
|
|
24012
|
+
if (typeof source !== "string") return false;
|
|
24013
|
+
return real2(source) === real2(pkgDir) || sourceName(source) === SERVER_KEY;
|
|
24014
|
+
}
|
|
24015
|
+
function ownEntries(src, pkgDir) {
|
|
24016
|
+
const list4 = hostConfigValueAt(src.doc, [PI_PACKAGES_KEY]);
|
|
24017
|
+
if (!Array.isArray(list4)) return [];
|
|
24018
|
+
const out = [];
|
|
24019
|
+
for (const e of list4) {
|
|
24020
|
+
const obj = typeof e === "object" && e !== null && !Array.isArray(e) ? e : void 0;
|
|
24021
|
+
if (!isOwn(obj ? obj[PI_PACKAGE_SOURCE_KEY] : e, pkgDir)) continue;
|
|
24022
|
+
const ext = obj?.[EXTENSIONS_KEY];
|
|
24023
|
+
out.push({ source: src, patterns: Array.isArray(ext) ? ext.filter((x) => typeof x === "string") : void 0 });
|
|
23947
24024
|
}
|
|
24025
|
+
return out;
|
|
24026
|
+
}
|
|
24027
|
+
function projectTrusted(agentDir, userDoc, cwd) {
|
|
24028
|
+
const trust = load(path4.join(agentDir, TRUST_FILE));
|
|
24029
|
+
const entries = /* @__PURE__ */ new Map();
|
|
24030
|
+
if (trust && typeof trust.doc === "object" && trust.doc !== null) for (const [k, v] of Object.entries(trust.doc)) entries.set(real2(k), v);
|
|
24031
|
+
let dir = real2(cwd);
|
|
24032
|
+
for (; ; ) {
|
|
24033
|
+
const v = entries.get(dir);
|
|
24034
|
+
if (v === true || v === false) return v;
|
|
24035
|
+
const up = path4.dirname(dir);
|
|
24036
|
+
if (up === dir) break;
|
|
24037
|
+
dir = up;
|
|
24038
|
+
}
|
|
24039
|
+
return hostConfigValueAt(userDoc, ["defaultProjectTrust"]) === ALWAYS;
|
|
24040
|
+
}
|
|
24041
|
+
function piInstalledIn(env, home, pkgDir, cwd) {
|
|
24042
|
+
const agentDir = piAgentDirOf(env, home);
|
|
24043
|
+
const user = load(path4.join(agentDir, SETTINGS_FILE));
|
|
24044
|
+
const project = load(path4.join(cwd, PROJECT_DIR, SETTINGS_FILE));
|
|
24045
|
+
if (project && projectTrusted(agentDir, user?.doc, cwd) && ownEntries(project, pkgDir).length > 0) return project.file;
|
|
24046
|
+
return user && ownEntries(user, pkgDir).length > 0 ? user.file : void 0;
|
|
23948
24047
|
}
|
|
23949
24048
|
|
|
23950
24049
|
// src/core/ops/doctor-config.ts
|
|
@@ -24047,14 +24146,14 @@ function codexNativeDir(env, home) {
|
|
|
24047
24146
|
}
|
|
24048
24147
|
if (enabled !== true) return null;
|
|
24049
24148
|
const cache = join12(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
24050
|
-
if (!
|
|
24149
|
+
if (!existsSync8(cache)) return null;
|
|
24051
24150
|
const found = [];
|
|
24052
24151
|
for (const market of readdirSync4(cache)) {
|
|
24053
24152
|
const plugin = join12(cache, market, SERVER_KEY);
|
|
24054
|
-
if (!
|
|
24153
|
+
if (!existsSync8(plugin)) continue;
|
|
24055
24154
|
for (const version4 of readdirSync4(plugin).sort()) {
|
|
24056
24155
|
const dir = join12(plugin, version4, CODEX_PLUGIN_SUBDIR);
|
|
24057
|
-
if (
|
|
24156
|
+
if (existsSync8(join12(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
24058
24157
|
}
|
|
24059
24158
|
}
|
|
24060
24159
|
return found.length === 0 ? null : found[found.length - 1];
|
|
@@ -24145,12 +24244,17 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
24145
24244
|
const choice = marketplaceChoice(env, worktree);
|
|
24146
24245
|
if ("installs" in choice) return fail2("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
|
|
24147
24246
|
}
|
|
24247
|
+
if (row5.id === "pi") return checkPiInstall(env, home, worktree);
|
|
24148
24248
|
const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
|
|
24149
|
-
|
|
24150
|
-
if (parts.length === 0) return read3 === null ? pass("D3") : { ...pass("D3"), detail: read3 };
|
|
24249
|
+
if (parts.length === 0) return pass("D3");
|
|
24151
24250
|
const detail = D3_DETAIL(parts);
|
|
24152
24251
|
const fix = parts.includes(PART_MCP) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
|
|
24153
|
-
return fail2("D3",
|
|
24252
|
+
return fail2("D3", detail, fix);
|
|
24253
|
+
}
|
|
24254
|
+
function checkPiInstall(env, home, worktree) {
|
|
24255
|
+
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
24256
|
+
if (found !== void 0) return { ...pass("D3"), detail: found };
|
|
24257
|
+
return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join12(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
|
|
24154
24258
|
}
|
|
24155
24259
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
24156
24260
|
const findings = detectV1(agent, home, scope);
|
|
@@ -24203,7 +24307,7 @@ function configPaths(row5, env, worktree) {
|
|
|
24203
24307
|
}
|
|
24204
24308
|
|
|
24205
24309
|
// src/core/ops/doctor-db.ts
|
|
24206
|
-
import { existsSync as
|
|
24310
|
+
import { existsSync as existsSync9, statSync as statSync5 } from "node:fs";
|
|
24207
24311
|
var unknown2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
|
|
24208
24312
|
var pass2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
|
|
24209
24313
|
var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -24222,8 +24326,8 @@ async function loadSqlite2() {
|
|
|
24222
24326
|
return null;
|
|
24223
24327
|
}
|
|
24224
24328
|
}
|
|
24225
|
-
function openRead(sqlite,
|
|
24226
|
-
return new sqlite.DatabaseSync(
|
|
24329
|
+
function openRead(sqlite, path8) {
|
|
24330
|
+
return new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
|
|
24227
24331
|
}
|
|
24228
24332
|
var cell = (row5) => Object.values(row5)[0];
|
|
24229
24333
|
function readSchema(raw) {
|
|
@@ -24244,16 +24348,16 @@ function failsOnCorrupt(step) {
|
|
|
24244
24348
|
function orphanFiles(dbPath) {
|
|
24245
24349
|
const files = [];
|
|
24246
24350
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
24247
|
-
const
|
|
24248
|
-
if (
|
|
24351
|
+
const path8 = dbPath + suffix;
|
|
24352
|
+
if (existsSync9(path8)) files.push({ path: path8, bytes: statSync5(path8).size });
|
|
24249
24353
|
}
|
|
24250
|
-
return files.length > 0 && !
|
|
24354
|
+
return files.length > 0 && !existsSync9(dbPath) ? files : [];
|
|
24251
24355
|
}
|
|
24252
24356
|
async function checkDb(project) {
|
|
24253
24357
|
const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
|
|
24254
24358
|
const orphan = orphanFiles(project.dbPath);
|
|
24255
24359
|
if (orphan.length > 0) return { row: fail3(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
|
|
24256
|
-
if (!
|
|
24360
|
+
if (!existsSync9(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
24257
24361
|
const sqlite = await loadSqlite2();
|
|
24258
24362
|
if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
|
|
24259
24363
|
let raw = null;
|
|
@@ -24279,7 +24383,7 @@ async function checkDb(project) {
|
|
|
24279
24383
|
}
|
|
24280
24384
|
}
|
|
24281
24385
|
async function checkIndex(project) {
|
|
24282
|
-
if (!
|
|
24386
|
+
if (!existsSync9(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
|
|
24283
24387
|
const sqlite = await loadSqlite2();
|
|
24284
24388
|
if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
|
|
24285
24389
|
let raw = null;
|
|
@@ -24296,7 +24400,7 @@ async function checkIndex(project) {
|
|
|
24296
24400
|
}
|
|
24297
24401
|
|
|
24298
24402
|
// src/core/ops/doctor-env.ts
|
|
24299
|
-
import { existsSync as
|
|
24403
|
+
import { existsSync as existsSync10, readFileSync as readFileSync10, realpathSync as realpathSync6 } from "node:fs";
|
|
24300
24404
|
import { isAbsolute as isAbsolute3, join as join13, relative as relative2 } from "node:path";
|
|
24301
24405
|
function pass3(id, detail = DOCTOR_PASS_DETAIL) {
|
|
24302
24406
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
@@ -24309,7 +24413,7 @@ function fail4(id, detail, fixCommand) {
|
|
|
24309
24413
|
}
|
|
24310
24414
|
function bundleVersion(bundleDir2) {
|
|
24311
24415
|
try {
|
|
24312
|
-
const v = JSON.parse(
|
|
24416
|
+
const v = JSON.parse(readFileSync10(join13(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24313
24417
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24314
24418
|
} catch {
|
|
24315
24419
|
return void 0;
|
|
@@ -24459,8 +24563,8 @@ function checkMcp(ctx) {
|
|
|
24459
24563
|
return named2 || versioned ? pass3("D6") : unknown3("D6", D6_UNKNOWN_DETAIL);
|
|
24460
24564
|
}
|
|
24461
24565
|
function piCwdInside(worktree, piCwd) {
|
|
24462
|
-
if (piCwd === void 0 || !
|
|
24463
|
-
const rel = relative2(worktree,
|
|
24566
|
+
if (piCwd === void 0 || !existsSync10(piCwd)) return false;
|
|
24567
|
+
const rel = relative2(worktree, realpathSync6.native(piCwd));
|
|
24464
24568
|
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
24465
24569
|
}
|
|
24466
24570
|
function checkProject(i) {
|
|
@@ -24480,20 +24584,20 @@ function checkShell(env) {
|
|
|
24480
24584
|
}
|
|
24481
24585
|
|
|
24482
24586
|
// src/core/ops/doctor-hook.ts
|
|
24483
|
-
import { existsSync as
|
|
24587
|
+
import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync11, realpathSync as realpathSync8, rmSync as rmSync2 } from "node:fs";
|
|
24484
24588
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24485
|
-
import
|
|
24589
|
+
import path7 from "node:path";
|
|
24486
24590
|
|
|
24487
24591
|
// src/setup/codex-trust.ts
|
|
24488
24592
|
import { createHash } from "node:crypto";
|
|
24489
|
-
import { existsSync as
|
|
24490
|
-
import
|
|
24593
|
+
import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
|
|
24594
|
+
import path6 from "node:path";
|
|
24491
24595
|
import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
|
|
24492
24596
|
|
|
24493
24597
|
// src/setup/spawn-bin.ts
|
|
24494
24598
|
import { spawnSync } from "node:child_process";
|
|
24495
24599
|
import { accessSync as accessSync2, constants as fsc, statSync as statSync6 } from "node:fs";
|
|
24496
|
-
import
|
|
24600
|
+
import path5 from "node:path";
|
|
24497
24601
|
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
24498
24602
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
24499
24603
|
var DEFAULT_COMSPEC = "cmd.exe";
|
|
@@ -24504,10 +24608,10 @@ function whichBin(bin, env, platform = process.platform) {
|
|
|
24504
24608
|
const get = (k) => envGet(env, k);
|
|
24505
24609
|
const win = platform === "win32";
|
|
24506
24610
|
const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
|
|
24507
|
-
const names = win &&
|
|
24611
|
+
const names = win && path5.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
|
|
24508
24612
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
24509
24613
|
for (const n of names) {
|
|
24510
|
-
const f =
|
|
24614
|
+
const f = path5.join(dir, n);
|
|
24511
24615
|
try {
|
|
24512
24616
|
accessSync2(f, fsc.X_OK);
|
|
24513
24617
|
if (statSync6(f).isFile()) return f;
|
|
@@ -24548,7 +24652,7 @@ function winCmdLine(file2, args, env = {}) {
|
|
|
24548
24652
|
return `"${[file2, ...args].map(q).join(" ")}"`;
|
|
24549
24653
|
}
|
|
24550
24654
|
function spawnForm(file2, args, env, platform = process.platform) {
|
|
24551
|
-
if (platform === "win32" && WIN_SHIM_EXTS.includes(
|
|
24655
|
+
if (platform === "win32" && WIN_SHIM_EXTS.includes(path5.extname(file2).toLowerCase())) {
|
|
24552
24656
|
return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file2, args, env)], windowsVerbatimArguments: true };
|
|
24553
24657
|
}
|
|
24554
24658
|
return { command: file2, args, windowsVerbatimArguments: false };
|
|
@@ -24572,10 +24676,10 @@ function codexHomeFromReply(out) {
|
|
|
24572
24676
|
return void 0;
|
|
24573
24677
|
}
|
|
24574
24678
|
function sameDir(a, b, platform = process.platform) {
|
|
24575
|
-
if (platform !== "win32") return
|
|
24679
|
+
if (platform !== "win32") return path6.posix.normalize(a) === path6.posix.normalize(b);
|
|
24576
24680
|
const norm2 = (p) => {
|
|
24577
24681
|
const bare2 = p.startsWith(WIN_VERBATIM_PREFIX) ? p.slice(WIN_VERBATIM_PREFIX.length) : p;
|
|
24578
|
-
const n =
|
|
24682
|
+
const n = path6.win32.normalize(bare2).toLowerCase();
|
|
24579
24683
|
return n.length > 3 && n.endsWith("\\") ? n.slice(0, -1) : n;
|
|
24580
24684
|
};
|
|
24581
24685
|
return norm2(a) === norm2(b);
|
|
@@ -24708,11 +24812,11 @@ function isObject5(v) {
|
|
|
24708
24812
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
24709
24813
|
}
|
|
24710
24814
|
function loadFixture(bundleDir2, agent) {
|
|
24711
|
-
const file2 =
|
|
24712
|
-
if (!
|
|
24815
|
+
const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
24816
|
+
if (!existsSync12(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
24713
24817
|
let all;
|
|
24714
24818
|
try {
|
|
24715
|
-
all = JSON.parse(hostText(
|
|
24819
|
+
all = JSON.parse(hostText(readFileSync11(file2, "utf8")));
|
|
24716
24820
|
} catch (err) {
|
|
24717
24821
|
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
24718
24822
|
}
|
|
@@ -24772,9 +24876,9 @@ function isNativeShape(agent, stdout, exitCode, killed, event) {
|
|
|
24772
24876
|
}
|
|
24773
24877
|
}
|
|
24774
24878
|
var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
|
|
24775
|
-
function readProbePayload(cwd) {
|
|
24879
|
+
function readProbePayload(cwd, ranged) {
|
|
24776
24880
|
const content = Array.from({ length: READ_PROBE_LINES }, (_, n) => "d5 read probe line " + n + " ".padEnd(20, "x")).join("\n");
|
|
24777
|
-
const filePath =
|
|
24881
|
+
const filePath = path7.join(cwd, "d5-read-probe.txt");
|
|
24778
24882
|
return {
|
|
24779
24883
|
session_id: "d5-read-probe",
|
|
24780
24884
|
transcript_path: "",
|
|
@@ -24782,7 +24886,7 @@ function readProbePayload(cwd) {
|
|
|
24782
24886
|
hook_event_name: "PostToolUse",
|
|
24783
24887
|
tool_name: "Read",
|
|
24784
24888
|
tool_use_id: "toolu_d5_read_probe",
|
|
24785
|
-
tool_input: { file_path: filePath },
|
|
24889
|
+
tool_input: ranged ? { file_path: filePath, offset: 1, limit: READ_PROBE_LINES } : { file_path: filePath },
|
|
24786
24890
|
tool_response: { type: "text", file: { filePath, content, numLines: READ_PROBE_LINES, startLine: 1, totalLines: READ_PROBE_LINES } }
|
|
24787
24891
|
};
|
|
24788
24892
|
}
|
|
@@ -24800,28 +24904,43 @@ function isReadShape(stdout) {
|
|
|
24800
24904
|
const f = r.file;
|
|
24801
24905
|
return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
|
|
24802
24906
|
}
|
|
24803
|
-
async function
|
|
24804
|
-
const home = mkdtempSync(
|
|
24907
|
+
async function readProbe(i, timeoutMs, ranged) {
|
|
24908
|
+
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-read-"));
|
|
24805
24909
|
try {
|
|
24806
|
-
const r = await runProcess([process.execPath,
|
|
24910
|
+
const r = await runProcess([process.execPath, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
24807
24911
|
cwd: i.bundleDir,
|
|
24808
24912
|
env: { ...i.env, HOME: home, USERPROFILE: home },
|
|
24809
24913
|
signal: i.signal,
|
|
24810
24914
|
timeoutMs,
|
|
24811
|
-
stdin: JSON.stringify(readProbePayload(i.worktree ?? home))
|
|
24915
|
+
stdin: JSON.stringify(readProbePayload(i.worktree ?? home, ranged))
|
|
24812
24916
|
});
|
|
24813
|
-
return
|
|
24917
|
+
return r.stdout.toString("utf8");
|
|
24814
24918
|
} finally {
|
|
24815
24919
|
rmSync2(home, { recursive: true, force: true });
|
|
24816
24920
|
}
|
|
24817
24921
|
}
|
|
24922
|
+
function isPassThrough(stdout) {
|
|
24923
|
+
if (stdout.trim() === "") return true;
|
|
24924
|
+
let out;
|
|
24925
|
+
try {
|
|
24926
|
+
out = JSON.parse(stdout);
|
|
24927
|
+
} catch {
|
|
24928
|
+
return false;
|
|
24929
|
+
}
|
|
24930
|
+
return !isObject5(out) || !isObject5(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput");
|
|
24931
|
+
}
|
|
24932
|
+
async function readProbeDetail(i, timeoutMs) {
|
|
24933
|
+
if (!isReadShape(await readProbe(i, timeoutMs, false))) return D5_READ_SHAPE_DETAIL;
|
|
24934
|
+
if (!isPassThrough(await readProbe(i, timeoutMs, true))) return D5_READ_RANGE_DETAIL;
|
|
24935
|
+
return null;
|
|
24936
|
+
}
|
|
24818
24937
|
function codexHookJournaled(db) {
|
|
24819
24938
|
if (db === null) return false;
|
|
24820
24939
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
24821
24940
|
}
|
|
24822
24941
|
function realDir(p) {
|
|
24823
24942
|
try {
|
|
24824
|
-
return
|
|
24943
|
+
return realpathSync8(p);
|
|
24825
24944
|
} catch {
|
|
24826
24945
|
return p;
|
|
24827
24946
|
}
|
|
@@ -24848,7 +24967,7 @@ async function checkHookRoundTrip(i) {
|
|
|
24848
24967
|
const trust = await codexPluginTrust(i);
|
|
24849
24968
|
if (trust !== null) return trust;
|
|
24850
24969
|
}
|
|
24851
|
-
if (i.agent === "codex" &&
|
|
24970
|
+
if (i.agent === "codex" && existsSync12(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
24852
24971
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
24853
24972
|
}
|
|
24854
24973
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
@@ -24868,7 +24987,7 @@ async function checkHookRoundTrip(i) {
|
|
|
24868
24987
|
let ms = 0;
|
|
24869
24988
|
for (let n = 1; n <= maxPairs; n++) {
|
|
24870
24989
|
const start = now();
|
|
24871
|
-
const r = await runProcess([process.execPath,
|
|
24990
|
+
const r = await runProcess([process.execPath, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
24872
24991
|
cwd: i.bundleDir,
|
|
24873
24992
|
env: i.env,
|
|
24874
24993
|
signal: i.signal,
|
|
@@ -24882,16 +25001,17 @@ async function checkHookRoundTrip(i) {
|
|
|
24882
25001
|
if (n >= minPairs && ms <= HOOK_P95_MS) break;
|
|
24883
25002
|
}
|
|
24884
25003
|
if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
|
|
24885
|
-
|
|
25004
|
+
const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : null;
|
|
25005
|
+
if (readDetail !== null) return row("FAIL", readDetail, D5_FIX);
|
|
24886
25006
|
return row("PASS", DOCTOR_PASS_DETAIL);
|
|
24887
25007
|
}
|
|
24888
25008
|
|
|
24889
25009
|
// src/core/ops/db-heal.ts
|
|
24890
|
-
import { existsSync as
|
|
25010
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
|
|
24891
25011
|
import { basename as basename4, dirname as dirname8, join as join15 } from "node:path";
|
|
24892
25012
|
|
|
24893
25013
|
// src/core/store/owners.ts
|
|
24894
|
-
import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as
|
|
25014
|
+
import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync12, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
24895
25015
|
import { basename as basename3, join as join14 } from "node:path";
|
|
24896
25016
|
function ownersDir(configDir, projectKey) {
|
|
24897
25017
|
return join14(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
@@ -24935,7 +25055,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
24935
25055
|
const file2 = join14(dir, name);
|
|
24936
25056
|
let text;
|
|
24937
25057
|
try {
|
|
24938
|
-
text =
|
|
25058
|
+
text = readFileSync12(file2, "utf8");
|
|
24939
25059
|
} catch (err) {
|
|
24940
25060
|
if (errCode2(err) === "ENOENT") continue;
|
|
24941
25061
|
throw err;
|
|
@@ -24981,7 +25101,7 @@ function renameAside(dbPath) {
|
|
|
24981
25101
|
const ts = String(Date.now());
|
|
24982
25102
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
24983
25103
|
const file2 = dbPath + suffix;
|
|
24984
|
-
if (
|
|
25104
|
+
if (existsSync13(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
24985
25105
|
}
|
|
24986
25106
|
return ts;
|
|
24987
25107
|
}
|
|
@@ -25088,7 +25208,7 @@ function buildReportHead(input) {
|
|
|
25088
25208
|
|
|
25089
25209
|
// src/core/ops/doctor-issue.ts
|
|
25090
25210
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
25091
|
-
import { closeSync, existsSync as
|
|
25211
|
+
import { closeSync, existsSync as existsSync14, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync13, readSync, realpathSync as realpathSync9, writeFileSync as writeFileSync3 } from "node:fs";
|
|
25092
25212
|
import { delimiter, join as join16 } from "node:path";
|
|
25093
25213
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
25094
25214
|
function tildeOf(env) {
|
|
@@ -25096,8 +25216,8 @@ function tildeOf(env) {
|
|
|
25096
25216
|
if (home === null || home === "") return (t) => t;
|
|
25097
25217
|
const homes = [home];
|
|
25098
25218
|
try {
|
|
25099
|
-
const
|
|
25100
|
-
if (
|
|
25219
|
+
const real3 = realpathSync9.native(home);
|
|
25220
|
+
if (real3 !== home) homes.push(real3);
|
|
25101
25221
|
} catch {
|
|
25102
25222
|
}
|
|
25103
25223
|
homes.sort((a, b) => b.length - a.length);
|
|
@@ -25130,7 +25250,7 @@ function onPath(env, tool) {
|
|
|
25130
25250
|
const out = [];
|
|
25131
25251
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
25132
25252
|
if (dir === "") continue;
|
|
25133
|
-
for (const n of names) if (
|
|
25253
|
+
for (const n of names) if (existsSync14(join16(dir, n))) {
|
|
25134
25254
|
out.push(join16(dir, n));
|
|
25135
25255
|
break;
|
|
25136
25256
|
}
|
|
@@ -25139,7 +25259,7 @@ function onPath(env, tool) {
|
|
|
25139
25259
|
}
|
|
25140
25260
|
function hookLogTail(env) {
|
|
25141
25261
|
const file2 = hookLogPath(env);
|
|
25142
|
-
if (file2 === "" || !
|
|
25262
|
+
if (file2 === "" || !existsSync14(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
25143
25263
|
try {
|
|
25144
25264
|
const fd = openSync(file2, "r");
|
|
25145
25265
|
try {
|
|
@@ -25159,7 +25279,7 @@ function hookLogTail(env) {
|
|
|
25159
25279
|
}
|
|
25160
25280
|
async function journalRows(ctx) {
|
|
25161
25281
|
const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
25162
|
-
if (!
|
|
25282
|
+
if (!existsSync14(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
25163
25283
|
try {
|
|
25164
25284
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
25165
25285
|
try {
|
|
@@ -25185,13 +25305,13 @@ function agentConfig(adapter, env, worktree) {
|
|
|
25185
25305
|
for (const f of files) {
|
|
25186
25306
|
if (seen.has(f.path)) continue;
|
|
25187
25307
|
seen.add(f.path);
|
|
25188
|
-
if (!
|
|
25308
|
+
if (!existsSync14(f.path)) {
|
|
25189
25309
|
out.push(`${f.label}: ${f.path} (absent)`);
|
|
25190
25310
|
continue;
|
|
25191
25311
|
}
|
|
25192
25312
|
let text = "";
|
|
25193
25313
|
try {
|
|
25194
|
-
text =
|
|
25314
|
+
text = readFileSync13(f.path, "utf8");
|
|
25195
25315
|
} catch (err) {
|
|
25196
25316
|
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
25197
25317
|
continue;
|
|
@@ -25290,7 +25410,7 @@ async function guard(id, run) {
|
|
|
25290
25410
|
}
|
|
25291
25411
|
}
|
|
25292
25412
|
async function codexDb(ctx, adapter) {
|
|
25293
|
-
if (adapter.id !== "codex" || !
|
|
25413
|
+
if (adapter.id !== "codex" || !existsSync15(ctx.project.dbPath)) return null;
|
|
25294
25414
|
try {
|
|
25295
25415
|
return await openDb(ctx.project, { readOnly: true });
|
|
25296
25416
|
} catch {
|
|
@@ -25321,10 +25441,10 @@ async function hookRow(ctx, adapter, host) {
|
|
|
25321
25441
|
}
|
|
25322
25442
|
function ownServerId(configDir, projectKey) {
|
|
25323
25443
|
const dir = join17(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
25324
|
-
if (!
|
|
25444
|
+
if (!existsSync15(dir)) return "";
|
|
25325
25445
|
for (const name of readdirSync6(dir)) {
|
|
25326
25446
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
25327
|
-
if (
|
|
25447
|
+
if (readFileSync14(join17(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
25328
25448
|
}
|
|
25329
25449
|
return "";
|
|
25330
25450
|
}
|
|
@@ -25380,7 +25500,7 @@ async function doctorReply(ctx, host) {
|
|
|
25380
25500
|
const adapter = getAdapter(ctx.project.agent);
|
|
25381
25501
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
25382
25502
|
const failed2 = rows.some((r) => r.status === "FAIL");
|
|
25383
|
-
const command = `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
25503
|
+
const command = adapter.id === "pi" ? failed2 ? NATIVE_INSTALL.pi[0] : PI_LIST_COMMAND : `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
25384
25504
|
const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
|
|
25385
25505
|
const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
|
|
25386
25506
|
const table3 = buildReport(input);
|
|
@@ -25407,7 +25527,7 @@ async function doctorReply(ctx, host) {
|
|
|
25407
25527
|
return { text, isError: false, sandboxBytes: bytes5 };
|
|
25408
25528
|
}
|
|
25409
25529
|
async function handler2(_input, ctx) {
|
|
25410
|
-
return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd:
|
|
25530
|
+
return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: ctx.piCwd });
|
|
25411
25531
|
}
|
|
25412
25532
|
var ctxDoctor = Object.freeze({
|
|
25413
25533
|
name: "ctx_doctor",
|
|
@@ -25419,7 +25539,7 @@ var ctxDoctor = Object.freeze({
|
|
|
25419
25539
|
});
|
|
25420
25540
|
|
|
25421
25541
|
// src/core/tools/execute.ts
|
|
25422
|
-
import { existsSync as
|
|
25542
|
+
import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
25423
25543
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
25424
25544
|
import { dirname as dirname10, join as join18, parse as parse3, resolve as resolve6 } from "node:path";
|
|
25425
25545
|
|
|
@@ -25505,7 +25625,7 @@ function schemaLine(issue4) {
|
|
|
25505
25625
|
}
|
|
25506
25626
|
function fileError(given, abs, root) {
|
|
25507
25627
|
let dir = abs;
|
|
25508
|
-
while (!
|
|
25628
|
+
while (!existsSync16(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
|
|
25509
25629
|
if (isInside(root, dir)) return null;
|
|
25510
25630
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
25511
25631
|
}
|
|
@@ -25622,19 +25742,19 @@ var ctxExecute = {
|
|
|
25622
25742
|
};
|
|
25623
25743
|
|
|
25624
25744
|
// src/core/tools/index.ts
|
|
25625
|
-
import { existsSync as
|
|
25745
|
+
import { existsSync as existsSync17, readFileSync as readFileSync16, statSync as statSync8 } from "node:fs";
|
|
25626
25746
|
import { dirname as dirname11, extname, join as join20, relative as relative3, resolve as resolve7 } from "node:path";
|
|
25627
25747
|
|
|
25628
25748
|
// src/core/index/walk.ts
|
|
25629
|
-
import { readdirSync as readdirSync7, readFileSync as
|
|
25749
|
+
import { readdirSync as readdirSync7, readFileSync as readFileSync15, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
|
|
25630
25750
|
import { join as join19 } from "node:path";
|
|
25631
25751
|
var GITIGNORE = ".gitignore";
|
|
25632
25752
|
var GIT_DIR = ".git";
|
|
25633
25753
|
function walkDir(root, containmentRoot) {
|
|
25634
|
-
const
|
|
25635
|
-
if (!isInside(containmentRoot,
|
|
25754
|
+
const real3 = realpathSync10(root);
|
|
25755
|
+
if (!isInside(containmentRoot, real3)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
|
|
25636
25756
|
const found = [];
|
|
25637
|
-
visit(
|
|
25757
|
+
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
25638
25758
|
found.sort(compareFound);
|
|
25639
25759
|
return found.map((f) => ({ absPath: f.absPath, relPath: join19(...f.dir, f.name) }));
|
|
25640
25760
|
}
|
|
@@ -25648,14 +25768,14 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
25648
25768
|
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join19(abs, GITIGNORE), rel)) : parent;
|
|
25649
25769
|
for (const e of entries) {
|
|
25650
25770
|
if (e.name === GIT_DIR) continue;
|
|
25651
|
-
const
|
|
25771
|
+
const path8 = join19(abs, e.name);
|
|
25652
25772
|
let isDir = e.isDirectory();
|
|
25653
25773
|
let isFile = e.isFile();
|
|
25654
|
-
let target =
|
|
25774
|
+
let target = path8;
|
|
25655
25775
|
if (e.isSymbolicLink()) {
|
|
25656
25776
|
let resolved;
|
|
25657
25777
|
try {
|
|
25658
|
-
resolved =
|
|
25778
|
+
resolved = realpathSync10(path8);
|
|
25659
25779
|
} catch {
|
|
25660
25780
|
continue;
|
|
25661
25781
|
}
|
|
@@ -25668,12 +25788,12 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
25668
25788
|
const segs = rel.concat(e.name);
|
|
25669
25789
|
if (ignored(rules, segs, isDir)) continue;
|
|
25670
25790
|
if (isFile) {
|
|
25671
|
-
found.push({ dir: rel, name: e.name, absPath:
|
|
25791
|
+
found.push({ dir: rel, name: e.name, absPath: path8 });
|
|
25672
25792
|
} else if (isDir) {
|
|
25673
|
-
const key = e.isSymbolicLink() ? target :
|
|
25793
|
+
const key = e.isSymbolicLink() ? target : realpathSync10(path8);
|
|
25674
25794
|
if (seen.has(key)) continue;
|
|
25675
25795
|
seen.add(key);
|
|
25676
|
-
visit(
|
|
25796
|
+
visit(path8, segs, rules, contain, seen, found);
|
|
25677
25797
|
}
|
|
25678
25798
|
}
|
|
25679
25799
|
}
|
|
@@ -25688,7 +25808,7 @@ function compareFound(a, b) {
|
|
|
25688
25808
|
function readRules(file2, base) {
|
|
25689
25809
|
let body;
|
|
25690
25810
|
try {
|
|
25691
|
-
body =
|
|
25811
|
+
body = readFileSync15(file2, "utf8");
|
|
25692
25812
|
} catch {
|
|
25693
25813
|
return [];
|
|
25694
25814
|
}
|
|
@@ -25864,12 +25984,12 @@ function tlsName(host) {
|
|
|
25864
25984
|
function request(u, conn, proxy, signal) {
|
|
25865
25985
|
const host = bare(u.hostname);
|
|
25866
25986
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
25867
|
-
const
|
|
25987
|
+
const path8 = u.pathname + u.search;
|
|
25868
25988
|
return new Promise((resolve8, reject) => {
|
|
25869
25989
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
25870
25990
|
if (proxy === void 0) {
|
|
25871
25991
|
const mod = u.protocol === "https:" ? https : http;
|
|
25872
|
-
const req = mod.request({ host: conn.address, port, path:
|
|
25992
|
+
const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
25873
25993
|
req.on("response", resolve8).on("error", onErr).end();
|
|
25874
25994
|
return;
|
|
25875
25995
|
}
|
|
@@ -25891,7 +26011,7 @@ function request(u, conn, proxy, signal) {
|
|
|
25891
26011
|
const req = https.request({
|
|
25892
26012
|
host,
|
|
25893
26013
|
port,
|
|
25894
|
-
path:
|
|
26014
|
+
path: path8,
|
|
25895
26015
|
signal,
|
|
25896
26016
|
headers: { host: u.host },
|
|
25897
26017
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
@@ -29771,14 +29891,14 @@ function kindOfType(contentType) {
|
|
|
29771
29891
|
}
|
|
29772
29892
|
function readUtf8(absPath) {
|
|
29773
29893
|
try {
|
|
29774
|
-
return utf8.decode(
|
|
29894
|
+
return utf8.decode(readFileSync16(absPath));
|
|
29775
29895
|
} catch {
|
|
29776
29896
|
return void 0;
|
|
29777
29897
|
}
|
|
29778
29898
|
}
|
|
29779
29899
|
function missingOrOutside(given, abs, root) {
|
|
29780
29900
|
let dir = abs;
|
|
29781
|
-
while (!
|
|
29901
|
+
while (!existsSync17(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
|
|
29782
29902
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
29783
29903
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
29784
29904
|
}
|
|
@@ -30329,11 +30449,11 @@ var ctxStats = Object.freeze({
|
|
|
30329
30449
|
});
|
|
30330
30450
|
|
|
30331
30451
|
// src/core/tools/upgrade.ts
|
|
30332
|
-
import { existsSync as
|
|
30452
|
+
import { existsSync as existsSync23, realpathSync as realpathSync11, rmSync as rmSync10 } from "node:fs";
|
|
30333
30453
|
import { basename as basename7, dirname as dirname13, join as join26 } from "node:path";
|
|
30334
30454
|
|
|
30335
30455
|
// src/core/ops/host-write.ts
|
|
30336
|
-
import { copyFileSync, existsSync as
|
|
30456
|
+
import { copyFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
30337
30457
|
import { dirname as dirname12, join as join21 } from "node:path";
|
|
30338
30458
|
function defaultWrite(file2, text) {
|
|
30339
30459
|
writeFileSync5(file2, text, "utf8");
|
|
@@ -30362,7 +30482,7 @@ function toRow(file2, edit) {
|
|
|
30362
30482
|
function writeWithRollback(file2, text, write2, atomic) {
|
|
30363
30483
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
30364
30484
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
30365
|
-
const had =
|
|
30485
|
+
const had = existsSync18(file2);
|
|
30366
30486
|
mkdirSync7(dirname12(file2), { recursive: true });
|
|
30367
30487
|
if (had) copyFileSync(file2, trash);
|
|
30368
30488
|
try {
|
|
@@ -30392,7 +30512,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
30392
30512
|
if (requested === null) return [];
|
|
30393
30513
|
const current = readHostConfig(row5.id, requested);
|
|
30394
30514
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
30395
|
-
const exists =
|
|
30515
|
+
const exists = existsSync18(current.path);
|
|
30396
30516
|
if (exists && result.text === current.text) return [];
|
|
30397
30517
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
30398
30518
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -30400,15 +30520,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
30400
30520
|
}
|
|
30401
30521
|
|
|
30402
30522
|
// src/core/ops/plugin-swap.ts
|
|
30403
|
-
import { existsSync as
|
|
30523
|
+
import { existsSync as existsSync19, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
30404
30524
|
import { basename as basename6, join as join22, win32 as win322 } from "node:path";
|
|
30405
|
-
function linkTarget(
|
|
30406
|
-
if (!isLink(
|
|
30407
|
-
const target = readlinkSync(
|
|
30525
|
+
function linkTarget(path8, win) {
|
|
30526
|
+
if (!isLink(path8)) return null;
|
|
30527
|
+
const target = readlinkSync(path8);
|
|
30408
30528
|
return win ? win322.basename(target) : target;
|
|
30409
30529
|
}
|
|
30410
|
-
function isLink(
|
|
30411
|
-
return lstatSync(
|
|
30530
|
+
function isLink(path8) {
|
|
30531
|
+
return lstatSync(path8, { throwIfNoEntry: false })?.isSymbolicLink() === true;
|
|
30412
30532
|
}
|
|
30413
30533
|
function generations(agentDir) {
|
|
30414
30534
|
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();
|
|
@@ -30421,7 +30541,7 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
30421
30541
|
}
|
|
30422
30542
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
30423
30543
|
const next = join22(agentDir, sha);
|
|
30424
|
-
if (!
|
|
30544
|
+
if (!existsSync19(next) || !lstatSync(next).isDirectory()) {
|
|
30425
30545
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
|
|
30426
30546
|
}
|
|
30427
30547
|
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
@@ -30441,12 +30561,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
30441
30561
|
if (before !== null) keep.add(before);
|
|
30442
30562
|
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join22(agentDir, name));
|
|
30443
30563
|
for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
|
|
30444
|
-
const previous = before !== null &&
|
|
30564
|
+
const previous = before !== null && existsSync19(join22(agentDir, before)) ? join22(agentDir, before) : null;
|
|
30445
30565
|
return { current: next, previous, removed };
|
|
30446
30566
|
}
|
|
30447
30567
|
|
|
30448
30568
|
// src/core/ops/release-fetch.ts
|
|
30449
|
-
import { existsSync as
|
|
30569
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
|
|
30450
30570
|
import { join as join23 } from "node:path";
|
|
30451
30571
|
function failed(r) {
|
|
30452
30572
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -30470,7 +30590,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
30470
30590
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
|
|
30471
30591
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
30472
30592
|
const dir = join23(agentDir, sha);
|
|
30473
|
-
if (
|
|
30593
|
+
if (existsSync20(dir)) rmSync7(fetchDir, { recursive: true, force: true });
|
|
30474
30594
|
else renameWithRetry(fetchDir, dir, opts);
|
|
30475
30595
|
return { sha, dir };
|
|
30476
30596
|
} catch (e) {
|
|
@@ -30480,7 +30600,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
30480
30600
|
}
|
|
30481
30601
|
|
|
30482
30602
|
// src/core/ops/uninstall.ts
|
|
30483
|
-
import { existsSync as
|
|
30603
|
+
import { existsSync as existsSync21, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
30484
30604
|
import { join as join24 } from "node:path";
|
|
30485
30605
|
function row2(area, before, after) {
|
|
30486
30606
|
return { area, before, after };
|
|
@@ -30514,7 +30634,7 @@ function removeCache(adapter, env, configDir) {
|
|
|
30514
30634
|
}
|
|
30515
30635
|
case "plugin": {
|
|
30516
30636
|
const agentDir = join24(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
30517
|
-
if (!
|
|
30637
|
+
if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
30518
30638
|
rmSync8(agentDir, { recursive: true, force: true });
|
|
30519
30639
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
30520
30640
|
}
|
|
@@ -30533,7 +30653,7 @@ function isObj3(v) {
|
|
|
30533
30653
|
function piSource(entry) {
|
|
30534
30654
|
return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
|
|
30535
30655
|
}
|
|
30536
|
-
function
|
|
30656
|
+
function ownEntries2(agent, env) {
|
|
30537
30657
|
const home = requireHomeDir(env);
|
|
30538
30658
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
30539
30659
|
if (mcp !== void 0) {
|
|
@@ -30541,10 +30661,10 @@ function ownEntries(agent, env) {
|
|
|
30541
30661
|
const inner = mcp.key.slice(1, -1);
|
|
30542
30662
|
const own4 = mcp.key[mcp.key.length - 1];
|
|
30543
30663
|
const holder = (v) => inner.reduce((cur, k) => isObj3(cur) ? cur[k] : void 0, v);
|
|
30544
|
-
const without = (v,
|
|
30664
|
+
const without = (v, path8) => {
|
|
30545
30665
|
const o = v;
|
|
30546
|
-
if (
|
|
30547
|
-
return { ...o, [
|
|
30666
|
+
if (path8.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own4));
|
|
30667
|
+
return { ...o, [path8[0]]: without(o[path8[0]], path8.slice(1)) };
|
|
30548
30668
|
};
|
|
30549
30669
|
return [{
|
|
30550
30670
|
file: ownMcpFileOf(agent, mcp.file, env, home),
|
|
@@ -30581,7 +30701,7 @@ function ownEntries(agent, env) {
|
|
|
30581
30701
|
}
|
|
30582
30702
|
function removeOwnEntries(agent, env) {
|
|
30583
30703
|
const rows = [];
|
|
30584
|
-
for (const entry of
|
|
30704
|
+
for (const entry of ownEntries2(agent, env)) {
|
|
30585
30705
|
const current = readHostConfig(agent, entry.file);
|
|
30586
30706
|
if (current.text === "") continue;
|
|
30587
30707
|
const value = hostConfigValueAt(parseHostConfig(agent, current.path, current.text, current.format), [entry.key]);
|
|
@@ -30594,7 +30714,7 @@ function removeOwnEntries(agent, env) {
|
|
|
30594
30714
|
function removeProjectData(configDir, projectKey) {
|
|
30595
30715
|
const projects = join24(configDir, PROJECTS_DIR_NAME);
|
|
30596
30716
|
const dir = join24(projects, projectKey);
|
|
30597
|
-
if (!
|
|
30717
|
+
if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
30598
30718
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
30599
30719
|
for (const name of readdirSync9(dir)) {
|
|
30600
30720
|
if (name !== OWNERS_DIR_NAME) rmSync8(join24(dir, name), { recursive: true, force: true });
|
|
@@ -30610,7 +30730,7 @@ function runUninstall(input) {
|
|
|
30610
30730
|
}
|
|
30611
30731
|
|
|
30612
30732
|
// src/core/ops/v1-remove.ts
|
|
30613
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
30733
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync17, rmSync as rmSync9 } from "node:fs";
|
|
30614
30734
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
30615
30735
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
30616
30736
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -30640,8 +30760,8 @@ function cutTomlTable(text, header) {
|
|
|
30640
30760
|
function writeAtomic(file2, text) {
|
|
30641
30761
|
atomicWriteFile(file2, text);
|
|
30642
30762
|
}
|
|
30643
|
-
function locate(doc,
|
|
30644
|
-
const segs =
|
|
30763
|
+
function locate(doc, path8) {
|
|
30764
|
+
const segs = path8.split(V1_KEY_PATH_SEP);
|
|
30645
30765
|
let cur = doc;
|
|
30646
30766
|
for (const seg of segs.slice(0, -1)) {
|
|
30647
30767
|
if (Array.isArray(cur)) cur = cur[Number(seg)];
|
|
@@ -30654,8 +30774,8 @@ function locate(doc, path7) {
|
|
|
30654
30774
|
return null;
|
|
30655
30775
|
}
|
|
30656
30776
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
30657
|
-
const layout = hostLayout(
|
|
30658
|
-
const text = hostText(
|
|
30777
|
+
const layout = hostLayout(readFileSync17(file2, "utf8"));
|
|
30778
|
+
const text = hostText(readFileSync17(file2, "utf8"));
|
|
30659
30779
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
30660
30780
|
const hit = /* @__PURE__ */ new Set();
|
|
30661
30781
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -30691,19 +30811,19 @@ function removeV1(agent, findings) {
|
|
|
30691
30811
|
for (const f of findings) {
|
|
30692
30812
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
30693
30813
|
else if (f.path === "") {
|
|
30694
|
-
if (
|
|
30814
|
+
if (existsSync22(f.file)) {
|
|
30695
30815
|
moveAside(f.file, undo);
|
|
30696
30816
|
done.set(f, UPGRADE_REMOVED);
|
|
30697
30817
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
30698
30818
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
30699
30819
|
}
|
|
30700
30820
|
for (const [file2, list4] of entries) {
|
|
30701
|
-
if (!
|
|
30821
|
+
if (!existsSync22(file2)) {
|
|
30702
30822
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
30703
30823
|
continue;
|
|
30704
30824
|
}
|
|
30705
30825
|
if (file2.endsWith(TOML_EXT)) {
|
|
30706
|
-
const rawToml =
|
|
30826
|
+
const rawToml = readFileSync17(file2, "utf8");
|
|
30707
30827
|
const tomlLayout = hostLayout(rawToml);
|
|
30708
30828
|
let text = hostText(rawToml);
|
|
30709
30829
|
for (const f of list4) {
|
|
@@ -30731,7 +30851,7 @@ function removeV1(agent, findings) {
|
|
|
30731
30851
|
},
|
|
30732
30852
|
rollback() {
|
|
30733
30853
|
for (const u of undo.splice(0).reverse()) {
|
|
30734
|
-
if (!
|
|
30854
|
+
if (!existsSync22(u.trash)) continue;
|
|
30735
30855
|
rmSync9(u.target, { recursive: true, force: true });
|
|
30736
30856
|
renameWithRetry(u.trash, u.target);
|
|
30737
30857
|
}
|
|
@@ -30741,7 +30861,7 @@ function removeV1(agent, findings) {
|
|
|
30741
30861
|
|
|
30742
30862
|
// src/core/ops/verify-sums.ts
|
|
30743
30863
|
import { createHash as createHash2 } from "node:crypto";
|
|
30744
|
-
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as
|
|
30864
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync18 } from "node:fs";
|
|
30745
30865
|
import { join as join25 } from "node:path";
|
|
30746
30866
|
function mismatch() {
|
|
30747
30867
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
@@ -30773,14 +30893,14 @@ function verifySums(dir) {
|
|
|
30773
30893
|
const sumsPath = join25(dir, RELEASE_SUMS_FILE);
|
|
30774
30894
|
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
30775
30895
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
30776
|
-
const sums = parseSums(
|
|
30896
|
+
const sums = parseSums(readFileSync18(sumsPath, "utf8"));
|
|
30777
30897
|
const files = /* @__PURE__ */ new Map();
|
|
30778
30898
|
walk3(dir, "", files);
|
|
30779
30899
|
if (files.size !== sums.size) throw mismatch();
|
|
30780
30900
|
for (const [rel, abs] of files) {
|
|
30781
30901
|
const want = sums.get(rel);
|
|
30782
30902
|
if (want === void 0) throw mismatch();
|
|
30783
|
-
const got = createHash2(SUMS_HASH_ALGORITHM).update(
|
|
30903
|
+
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync18(abs)).digest(HASH_ENCODING);
|
|
30784
30904
|
if (got !== want) throw mismatch();
|
|
30785
30905
|
}
|
|
30786
30906
|
}
|
|
@@ -30809,7 +30929,7 @@ function pluginRootRow(adapter, env) {
|
|
|
30809
30929
|
}
|
|
30810
30930
|
function isCurrent(agentDir, dir) {
|
|
30811
30931
|
const link = join26(agentDir, PLUGIN_CURRENT_LINK);
|
|
30812
|
-
return
|
|
30932
|
+
return existsSync23(link) && realpathSync11.native(link) === realpathSync11.native(dir);
|
|
30813
30933
|
}
|
|
30814
30934
|
async function checkout(adapter, deps) {
|
|
30815
30935
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
@@ -30929,7 +31049,7 @@ function checkCall(tool, input) {
|
|
|
30929
31049
|
|
|
30930
31050
|
// src/entries/server.ts
|
|
30931
31051
|
import { randomUUID } from "node:crypto";
|
|
30932
|
-
import { existsSync as
|
|
31052
|
+
import { existsSync as existsSync25, realpathSync as realpathSync13, rmSync as rmSync12 } from "node:fs";
|
|
30933
31053
|
import { dirname as dirname14, join as join28 } from "node:path";
|
|
30934
31054
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
30935
31055
|
|
|
@@ -31227,10 +31347,10 @@ function mergeDefs(...defs) {
|
|
|
31227
31347
|
function cloneDef(schema) {
|
|
31228
31348
|
return mergeDefs(schema._zod.def);
|
|
31229
31349
|
}
|
|
31230
|
-
function getElementAtPath2(obj,
|
|
31231
|
-
if (!
|
|
31350
|
+
function getElementAtPath2(obj, path8) {
|
|
31351
|
+
if (!path8)
|
|
31232
31352
|
return obj;
|
|
31233
|
-
return
|
|
31353
|
+
return path8.reduce((acc, key) => acc?.[key], obj);
|
|
31234
31354
|
}
|
|
31235
31355
|
function promiseAllObject2(promisesObj) {
|
|
31236
31356
|
const keys = Object.keys(promisesObj);
|
|
@@ -31570,11 +31690,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
31570
31690
|
}
|
|
31571
31691
|
return false;
|
|
31572
31692
|
}
|
|
31573
|
-
function prefixIssues2(
|
|
31693
|
+
function prefixIssues2(path8, issues) {
|
|
31574
31694
|
return issues.map((iss) => {
|
|
31575
31695
|
var _a5;
|
|
31576
31696
|
(_a5 = iss).path ?? (_a5.path = []);
|
|
31577
|
-
iss.path.unshift(
|
|
31697
|
+
iss.path.unshift(path8);
|
|
31578
31698
|
return iss;
|
|
31579
31699
|
});
|
|
31580
31700
|
}
|
|
@@ -32035,16 +32155,16 @@ function flattenError2(error42, mapper = (issue4) => issue4.message) {
|
|
|
32035
32155
|
}
|
|
32036
32156
|
function formatError3(error42, mapper = (issue4) => issue4.message) {
|
|
32037
32157
|
const fieldErrors = { _errors: [] };
|
|
32038
|
-
const processError = (error43,
|
|
32158
|
+
const processError = (error43, path8 = []) => {
|
|
32039
32159
|
for (const issue4 of error43.issues) {
|
|
32040
32160
|
if (issue4.code === "invalid_union" && issue4.errors.length) {
|
|
32041
|
-
issue4.errors.map((issues) => processError({ issues }, [...
|
|
32161
|
+
issue4.errors.map((issues) => processError({ issues }, [...path8, ...issue4.path]));
|
|
32042
32162
|
} else if (issue4.code === "invalid_key") {
|
|
32043
|
-
processError({ issues: issue4.issues }, [...
|
|
32163
|
+
processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
|
|
32044
32164
|
} else if (issue4.code === "invalid_element") {
|
|
32045
|
-
processError({ issues: issue4.issues }, [...
|
|
32165
|
+
processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
|
|
32046
32166
|
} else {
|
|
32047
|
-
const fullpath = [...
|
|
32167
|
+
const fullpath = [...path8, ...issue4.path];
|
|
32048
32168
|
if (fullpath.length === 0) {
|
|
32049
32169
|
fieldErrors._errors.push(mapper(issue4));
|
|
32050
32170
|
} else {
|
|
@@ -38808,10 +38928,10 @@ function mergeDefs2(...defs) {
|
|
|
38808
38928
|
function cloneDef2(schema) {
|
|
38809
38929
|
return mergeDefs2(schema._zod.def);
|
|
38810
38930
|
}
|
|
38811
|
-
function getElementAtPath3(obj,
|
|
38812
|
-
if (!
|
|
38931
|
+
function getElementAtPath3(obj, path8) {
|
|
38932
|
+
if (!path8)
|
|
38813
38933
|
return obj;
|
|
38814
|
-
return
|
|
38934
|
+
return path8.reduce((acc, key) => acc?.[key], obj);
|
|
38815
38935
|
}
|
|
38816
38936
|
function promiseAllObject3(promisesObj) {
|
|
38817
38937
|
const keys = Object.keys(promisesObj);
|
|
@@ -39151,11 +39271,11 @@ function explicitlyAborted2(x, startIndex = 0) {
|
|
|
39151
39271
|
}
|
|
39152
39272
|
return false;
|
|
39153
39273
|
}
|
|
39154
|
-
function prefixIssues3(
|
|
39274
|
+
function prefixIssues3(path8, issues) {
|
|
39155
39275
|
return issues.map((iss) => {
|
|
39156
39276
|
var _a5;
|
|
39157
39277
|
(_a5 = iss).path ?? (_a5.path = []);
|
|
39158
|
-
iss.path.unshift(
|
|
39278
|
+
iss.path.unshift(path8);
|
|
39159
39279
|
return iss;
|
|
39160
39280
|
});
|
|
39161
39281
|
}
|
|
@@ -39613,16 +39733,16 @@ function flattenError3(error42, mapper = (issue4) => issue4.message) {
|
|
|
39613
39733
|
}
|
|
39614
39734
|
function formatError4(error42, mapper = (issue4) => issue4.message) {
|
|
39615
39735
|
const fieldErrors = { _errors: [] };
|
|
39616
|
-
const processError = (error43,
|
|
39736
|
+
const processError = (error43, path8 = []) => {
|
|
39617
39737
|
for (const issue4 of error43.issues) {
|
|
39618
39738
|
if (issue4.code === "invalid_union" && issue4.errors.length) {
|
|
39619
|
-
issue4.errors.map((issues) => processError({ issues }, [...
|
|
39739
|
+
issue4.errors.map((issues) => processError({ issues }, [...path8, ...issue4.path]));
|
|
39620
39740
|
} else if (issue4.code === "invalid_key") {
|
|
39621
|
-
processError({ issues: issue4.issues }, [...
|
|
39741
|
+
processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
|
|
39622
39742
|
} else if (issue4.code === "invalid_element") {
|
|
39623
|
-
processError({ issues: issue4.issues }, [...
|
|
39743
|
+
processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
|
|
39624
39744
|
} else {
|
|
39625
|
-
const fullpath = [...
|
|
39745
|
+
const fullpath = [...path8, ...issue4.path];
|
|
39626
39746
|
if (fullpath.length === 0) {
|
|
39627
39747
|
fieldErrors._errors.push(mapper(issue4));
|
|
39628
39748
|
} else {
|
|
@@ -47838,9 +47958,9 @@ var rev2026Codec = {
|
|
|
47838
47958
|
});
|
|
47839
47959
|
const parsed = buildSchemas2026().RequestMetaEnvelopeSchema.safeParse(meta3);
|
|
47840
47960
|
if (!parsed.success) for (const issue4 of parsed.error.issues) {
|
|
47841
|
-
const
|
|
47842
|
-
const key =
|
|
47843
|
-
if (
|
|
47961
|
+
const path8 = issue4.path.map(String);
|
|
47962
|
+
const key = path8.length > 0 ? path8.join(".") : "_meta";
|
|
47963
|
+
if (path8.length === 1 && issues.some((existing) => existing.key === key && existing.problem === "missing")) continue;
|
|
47844
47964
|
issues.push({
|
|
47845
47965
|
key,
|
|
47846
47966
|
problem: issue4.message
|
|
@@ -48167,29 +48287,29 @@ var PERMITTED_X_MCP_HEADER_TYPES = /* @__PURE__ */ new Set([
|
|
|
48167
48287
|
function scanXMcpHeaderDeclarations(inputSchema) {
|
|
48168
48288
|
const declarations = [];
|
|
48169
48289
|
const seenLower = /* @__PURE__ */ new Map();
|
|
48170
|
-
const visit2 = (node3,
|
|
48290
|
+
const visit2 = (node3, path8, reachable) => {
|
|
48171
48291
|
if (node3 === null || typeof node3 !== "object") return void 0;
|
|
48172
48292
|
const schema = node3;
|
|
48173
48293
|
if (X_MCP_HEADER_KEY in schema) {
|
|
48174
|
-
if (!reachable ||
|
|
48294
|
+
if (!reachable || path8.length === 0) return `${pathName(path8)}: x-mcp-header is only permitted on properties statically reachable via a chain of 'properties' keys (not under items, additionalProperties, oneOf/anyOf/allOf/not, if/then/else, or $ref)`;
|
|
48175
48295
|
const raw = schema[X_MCP_HEADER_KEY];
|
|
48176
|
-
if (typeof raw !== "string" || raw.length === 0) return `${pathName(
|
|
48177
|
-
if (!RFC9110_TOKEN.test(raw)) return `${pathName(
|
|
48296
|
+
if (typeof raw !== "string" || raw.length === 0) return `${pathName(path8)}: x-mcp-header MUST be a non-empty string`;
|
|
48297
|
+
if (!RFC9110_TOKEN.test(raw)) return `${pathName(path8)}: x-mcp-header '${raw}' is not a valid RFC 9110 token (no spaces, control characters or HTTP delimiters)`;
|
|
48178
48298
|
const type = typeof schema.type === "string" ? schema.type : void 0;
|
|
48179
|
-
if (type === void 0 || !PERMITTED_X_MCP_HEADER_TYPES.has(type)) return `${pathName(
|
|
48299
|
+
if (type === void 0 || !PERMITTED_X_MCP_HEADER_TYPES.has(type)) return `${pathName(path8)}: x-mcp-header is only permitted on primitive-typed properties (string, integer, boolean); got ${type ?? "<none>"}`;
|
|
48180
48300
|
const lower = raw.toLowerCase();
|
|
48181
48301
|
const prior = seenLower.get(lower);
|
|
48182
48302
|
if (prior !== void 0) return `x-mcp-header '${raw}' is not case-insensitively unique (also declared as '${prior}')`;
|
|
48183
48303
|
seenLower.set(lower, raw);
|
|
48184
48304
|
declarations.push({
|
|
48185
|
-
path:
|
|
48305
|
+
path: path8,
|
|
48186
48306
|
headerName: raw,
|
|
48187
48307
|
type
|
|
48188
48308
|
});
|
|
48189
48309
|
}
|
|
48190
48310
|
const properties = schema.properties;
|
|
48191
48311
|
if (properties !== null && typeof properties === "object") for (const [key, child] of Object.entries(properties)) {
|
|
48192
|
-
const fault$1 = visit2(child, [...
|
|
48312
|
+
const fault$1 = visit2(child, [...path8, key], reachable);
|
|
48193
48313
|
if (fault$1 !== void 0) return fault$1;
|
|
48194
48314
|
}
|
|
48195
48315
|
for (const k of NON_REACHABLE_SUBSCHEMA_KEYWORDS) {
|
|
@@ -48197,7 +48317,7 @@ function scanXMcpHeaderDeclarations(inputSchema) {
|
|
|
48197
48317
|
if (sub === void 0) continue;
|
|
48198
48318
|
const branches = Array.isArray(sub) ? sub : sub !== null && typeof sub === "object" && OBJECT_VALUED_SUBSCHEMA_KEYWORDS.has(k) ? Object.values(sub) : [sub];
|
|
48199
48319
|
for (const branch of branches) {
|
|
48200
|
-
const fault$1 = visit2(branch, [...
|
|
48320
|
+
const fault$1 = visit2(branch, [...path8, `<${k}>`], false);
|
|
48201
48321
|
if (fault$1 !== void 0) return fault$1;
|
|
48202
48322
|
}
|
|
48203
48323
|
}
|
|
@@ -48237,8 +48357,8 @@ var OBJECT_VALUED_SUBSCHEMA_KEYWORDS = /* @__PURE__ */ new Set([
|
|
|
48237
48357
|
"$defs",
|
|
48238
48358
|
"definitions"
|
|
48239
48359
|
]);
|
|
48240
|
-
function pathName(
|
|
48241
|
-
return
|
|
48360
|
+
function pathName(path8) {
|
|
48361
|
+
return path8.length === 0 ? "<root>" : path8.join(".");
|
|
48242
48362
|
}
|
|
48243
48363
|
var HEADER_MISMATCH_ERROR_CODE = -32020;
|
|
48244
48364
|
var INBOUND_VALIDATION_LADDER = [
|
|
@@ -48527,7 +48647,7 @@ var PROPERTY_KEYS_BY_TYPE = {
|
|
|
48527
48647
|
array: shapeKeys([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema])
|
|
48528
48648
|
};
|
|
48529
48649
|
var SUPPORTED_STRING_FORMATS = new Set(StringSchemaSchema.shape.format.unwrap().options);
|
|
48530
|
-
function walkProperty(node3,
|
|
48650
|
+
function walkProperty(node3, path8, vendor, unsupported) {
|
|
48531
48651
|
if (!isJsonObject(node3)) return node3;
|
|
48532
48652
|
const allowedKeys = typeof node3.type === "string" && Object.hasOwn(PROPERTY_KEYS_BY_TYPE, node3.type) ? PROPERTY_KEYS_BY_TYPE[node3.type] : void 0;
|
|
48533
48653
|
if (allowedKeys === void 0) return node3;
|
|
@@ -48535,8 +48655,8 @@ function walkProperty(node3, path7, vendor, unsupported) {
|
|
|
48535
48655
|
for (const [key, value] of Object.entries(node3)) if (allowedKeys.has(key) || isAnnotationOnlyJsonSchemaKeyword(key)) pruned[key] = value;
|
|
48536
48656
|
else if (key === "pattern" && node3.type === "string" && typeof node3.format === "string") {
|
|
48537
48657
|
if (!SUPPORTED_STRING_FORMATS.has(node3.format)) pruned[key] = value;
|
|
48538
|
-
else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor)) unsupported.push(`${
|
|
48539
|
-
} else unsupported.push(`${
|
|
48658
|
+
else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor)) unsupported.push(`${path8}.${key}`);
|
|
48659
|
+
} else unsupported.push(`${path8}.${key}`);
|
|
48540
48660
|
return pruned;
|
|
48541
48661
|
}
|
|
48542
48662
|
function walkRequestedSchema(converted, vendor) {
|
|
@@ -48553,11 +48673,11 @@ function describeUnsupportedProperties(pruned, fallback) {
|
|
|
48553
48673
|
const offenders = Object.entries(pruned.properties).filter(([, node3]) => !parseSchema(PrimitiveSchemaDefinitionSchema, node3).success).map(([name]) => `properties.${name}`);
|
|
48554
48674
|
return offenders.length > 0 ? offenders.join(", ") : fallback;
|
|
48555
48675
|
}
|
|
48556
|
-
function findDroppedConstraintPaths(original, parsed,
|
|
48557
|
-
if (Array.isArray(original) && Array.isArray(parsed)) return original.flatMap((item, index) => findDroppedConstraintPaths(item, parsed[index], `${
|
|
48676
|
+
function findDroppedConstraintPaths(original, parsed, path8 = "") {
|
|
48677
|
+
if (Array.isArray(original) && Array.isArray(parsed)) return original.flatMap((item, index) => findDroppedConstraintPaths(item, parsed[index], `${path8}[${index}]`));
|
|
48558
48678
|
if (!isJsonObject(original) || !isJsonObject(parsed)) return [];
|
|
48559
48679
|
return Object.entries(original).flatMap(([key, value]) => {
|
|
48560
|
-
const childPath =
|
|
48680
|
+
const childPath = path8 ? `${path8}.${key}` : key;
|
|
48561
48681
|
if (!Object.prototype.hasOwnProperty.call(parsed, key)) return isAnnotationOnlyJsonSchemaKeyword(key) ? [] : [childPath];
|
|
48562
48682
|
return findDroppedConstraintPaths(value, parsed[key], childPath);
|
|
48563
48683
|
});
|
|
@@ -52645,8 +52765,8 @@ var require_utils = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
|
52645
52765
|
for (let i = 0; i < str4.length; i++) if (str4[i] === token) ind++;
|
|
52646
52766
|
return ind;
|
|
52647
52767
|
}
|
|
52648
|
-
function removeDotSegments(
|
|
52649
|
-
let input =
|
|
52768
|
+
function removeDotSegments(path8) {
|
|
52769
|
+
let input = path8;
|
|
52650
52770
|
const output = [];
|
|
52651
52771
|
let nextSlash = -1;
|
|
52652
52772
|
let len = 0;
|
|
@@ -52799,8 +52919,8 @@ var require_schemes = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
|
52799
52919
|
wsComponent.secure = void 0;
|
|
52800
52920
|
}
|
|
52801
52921
|
if (wsComponent.resourceName) {
|
|
52802
|
-
const [
|
|
52803
|
-
wsComponent.path =
|
|
52922
|
+
const [path8, query] = wsComponent.resourceName.split("?");
|
|
52923
|
+
wsComponent.path = path8 && path8 !== "/" ? path8 : void 0;
|
|
52804
52924
|
wsComponent.query = query;
|
|
52805
52925
|
wsComponent.resourceName = void 0;
|
|
52806
52926
|
}
|
|
@@ -58995,7 +59115,7 @@ function installExitGuard(opts) {
|
|
|
58995
59115
|
}
|
|
58996
59116
|
|
|
58997
59117
|
// src/core/store/cleanup.ts
|
|
58998
|
-
import { existsSync as
|
|
59118
|
+
import { existsSync as existsSync24, readdirSync as readdirSync11, rmSync as rmSync11 } from "node:fs";
|
|
58999
59119
|
import { join as join27 } from "node:path";
|
|
59000
59120
|
function deleteSource(raw, id) {
|
|
59001
59121
|
raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
|
|
@@ -59031,7 +59151,7 @@ function userVersion(raw) {
|
|
|
59031
59151
|
return raw.prepare("PRAGMA user_version").get().user_version;
|
|
59032
59152
|
}
|
|
59033
59153
|
function openForSweep(dbPath, projectKey) {
|
|
59034
|
-
if (!
|
|
59154
|
+
if (!existsSync24(dbPath) && (existsSync24(dbPath + DB_WAL_SUFFIX) || existsSync24(dbPath + DB_SHM_SUFFIX))) {
|
|
59035
59155
|
throw new CtxError("DB_GONE");
|
|
59036
59156
|
}
|
|
59037
59157
|
const sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -59085,12 +59205,12 @@ function sweepDeadProjects(configDir) {
|
|
|
59085
59205
|
}
|
|
59086
59206
|
|
|
59087
59207
|
// src/entries/is-entry.ts
|
|
59088
|
-
import { realpathSync as
|
|
59208
|
+
import { realpathSync as realpathSync12 } from "node:fs";
|
|
59089
59209
|
function isEntry(main, argv1, self) {
|
|
59090
59210
|
if (main !== void 0) return main;
|
|
59091
59211
|
if (argv1 === void 0 || argv1 === "") return false;
|
|
59092
59212
|
try {
|
|
59093
|
-
return
|
|
59213
|
+
return realpathSync12(argv1) === realpathSync12(self);
|
|
59094
59214
|
} catch {
|
|
59095
59215
|
return false;
|
|
59096
59216
|
}
|
|
@@ -59166,7 +59286,7 @@ function workspaceFromMeta(meta3) {
|
|
|
59166
59286
|
}
|
|
59167
59287
|
function realOrSame(p) {
|
|
59168
59288
|
try {
|
|
59169
|
-
return
|
|
59289
|
+
return realpathSync13.native(p);
|
|
59170
59290
|
} catch {
|
|
59171
59291
|
return p;
|
|
59172
59292
|
}
|
|
@@ -59214,7 +59334,7 @@ async function startServer(argv, env) {
|
|
|
59214
59334
|
opening.catch(() => pending.delete(project.dbPath));
|
|
59215
59335
|
}
|
|
59216
59336
|
const db = await opening;
|
|
59217
|
-
if (!
|
|
59337
|
+
if (!existsSync25(db.path)) throw new CtxError("DB_GONE");
|
|
59218
59338
|
return db;
|
|
59219
59339
|
}
|
|
59220
59340
|
function stopMarker(configDir, projectKey) {
|
|
@@ -59222,7 +59342,7 @@ async function startServer(argv, env) {
|
|
|
59222
59342
|
}
|
|
59223
59343
|
function stopRequested() {
|
|
59224
59344
|
const configDir = resolveConfigDir(process.env);
|
|
59225
|
-
return held.some((db) =>
|
|
59345
|
+
return held.some((db) => existsSync25(stopMarker(configDir, db.projectKey)));
|
|
59226
59346
|
}
|
|
59227
59347
|
async function journal(project, ctx, name, reply4) {
|
|
59228
59348
|
const db = await ownDb(project);
|
|
@@ -59384,7 +59504,9 @@ function piExtension(pi) {
|
|
|
59384
59504
|
turn,
|
|
59385
59505
|
// #1182: Pi's abort signal reaches the handler, which kills the process tree and replies "Cancelled.".
|
|
59386
59506
|
signal: signal ?? new AbortController().signal,
|
|
59387
|
-
protocolVersion: ""
|
|
59507
|
+
protocolVersion: "",
|
|
59508
|
+
piCwd: cwd === "" ? void 0 : cwd
|
|
59509
|
+
// D-R38-PI-D7-1 (#1312): ctx_doctor D7 compares against Pi's live ctx.cwd
|
|
59388
59510
|
};
|
|
59389
59511
|
let reply4;
|
|
59390
59512
|
try {
|