context-mode 2.0.0-next.34 → 2.0.0-next.37
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 +392 -111
- package/SHA256SUMS +16 -16
- package/cli.mjs +2 -1
- package/copilot/plugin.json +1 -1
- package/fixtures/hook-roundtrip.json +113 -0
- package/gemini-extension.json +1 -1
- package/hook.mjs +60 -58
- package/opencode/plugin.js +403 -183
- package/package.json +1 -1
- package/pi/index.js +443 -219
- package/qwen-extension.json +1 -1
- package/run.mjs +5 -2
- package/search.mjs +5 -2
- package/server.mjs +430 -206
package/opencode/plugin.js
CHANGED
|
@@ -425,7 +425,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
425
425
|
var DECISION_LABEL_JOIN = " | ";
|
|
426
426
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
427
427
|
var RELEASE_BRANCH = "release";
|
|
428
|
-
var BUNDLE_SHA = true ? "
|
|
428
|
+
var BUNDLE_SHA = true ? "2ed67370714045804b7620af1f3af2c9eabc1713" : void 0;
|
|
429
429
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
430
430
|
var DOCTOR_LABEL = Object.freeze({
|
|
431
431
|
D1: "version",
|
|
@@ -448,6 +448,8 @@ var REPORT_HEADER = "| Check | Status | Detail | Fix |";
|
|
|
448
448
|
var REPORT_HEADER_RULE = "|---|---|---|---|";
|
|
449
449
|
var REPORT_COMMAND_PREFIX = "Run in a terminal: ";
|
|
450
450
|
var ECHO_MAX_BYTES = 256;
|
|
451
|
+
var LABEL_PREVIEW_BYTES = 32;
|
|
452
|
+
var LABEL_PAGE_BYTES = 8192;
|
|
451
453
|
var REPORT_SOURCE_LABEL = "ctx_doctor:report";
|
|
452
454
|
var REPORT_REST_PREFIX = "Rows not shown here are stored in full. Read them with: ";
|
|
453
455
|
var REPORT_POINTER = `ctx_search({queries:["FAIL","PASS","UNKNOWN"], source:${JSON.stringify(REPORT_SOURCE_LABEL)}})`;
|
|
@@ -544,6 +546,19 @@ function D8_HEALED_RECREATE_DETAIL(ts) {
|
|
|
544
546
|
}
|
|
545
547
|
var INTEGRITY_OK = "ok";
|
|
546
548
|
var HEAL_BACKUP_SUFFIX = ".bak";
|
|
549
|
+
var orphanList = (files) => files.map((f) => `${f.path} (${f.bytes} bytes)`).join(", ");
|
|
550
|
+
var ORPHAN_DIR_PREFIX = "orphan-";
|
|
551
|
+
function D8_ORPHAN_DETAIL(files) {
|
|
552
|
+
return `context.db is gone, its WAL files are still here: ${orphanList(files)}`;
|
|
553
|
+
}
|
|
554
|
+
var D8_ORPHAN_FIX = "run ctx_doctor once; it keeps these files in a dated folder and starts a new index";
|
|
555
|
+
function D8_ORPHAN_HEALED_DETAIL(dir, moved, dbPath) {
|
|
556
|
+
return `moved the WAL files of the missing context.db, whole and unchanged, to ${dir}: ${orphanList(moved)}; new index at ${dbPath}; the old WAL is kept there, to restore it put the original context.db back next to it`;
|
|
557
|
+
}
|
|
558
|
+
var D8_ORPHAN_HEALED_FIX = "run ctx_doctor again; D8 then reads PASS";
|
|
559
|
+
function D8_ORPHAN_MOVE_FAILED(detail, cause) {
|
|
560
|
+
return `${detail}; moving them aside failed: ${cause}`;
|
|
561
|
+
}
|
|
547
562
|
function D9_INDEX_DETAIL(sources, chunks) {
|
|
548
563
|
return `${sources} sources, ${chunks} chunks indexed`;
|
|
549
564
|
}
|
|
@@ -921,7 +936,8 @@ var DOCTOR_LOG_TAIL_BYTES = 262144;
|
|
|
921
936
|
var ERROR_TEXT = Object.freeze({
|
|
922
937
|
NODE_TOO_OLD: "Node <v> is below 24.15.0. Fix: install Node 24.15.0 or later.",
|
|
923
938
|
NO_SQLITE: "node:sqlite failed to load. Fix: run ctx_doctor.",
|
|
924
|
-
DB_GONE: "context.db
|
|
939
|
+
DB_GONE: "context.db is gone and its WAL file is still in place. Fix: run ctx_doctor once; it keeps the WAL file in a dated folder and starts a new index.",
|
|
940
|
+
// D-ORPHAN-WAL-1
|
|
925
941
|
NO_PROJECT: "Project source <kind> is missing. Fix: run ctx_doctor.",
|
|
926
942
|
UNKNOWN_FIELD: 'Unknown field "<f>". Fix: use "queries".',
|
|
927
943
|
TIMEOUT: "Timed out after <ms> ms. Fix: pass background: true.",
|
|
@@ -2525,8 +2541,8 @@ function jqWhitelisted(filter2) {
|
|
|
2525
2541
|
const bar2 = s.indexOf(JQ_WHITELIST.pipeLength.charAt(0));
|
|
2526
2542
|
if (bar2 < 0) return jqPath(s);
|
|
2527
2543
|
const left = s.slice(0, bar2).trim();
|
|
2528
|
-
const
|
|
2529
|
-
return (left === JQ_WHITELIST.identity || jqPath(left)) && s.slice(bar2 + 1).trim() ===
|
|
2544
|
+
const right2 = JQ_WHITELIST.pipeLength.slice(1).trim();
|
|
2545
|
+
return (left === JQ_WHITELIST.identity || jqPath(left)) && s.slice(bar2 + 1).trim() === right2;
|
|
2530
2546
|
}
|
|
2531
2547
|
function isBoundedSink(c) {
|
|
2532
2548
|
const name = c.argv0.toLowerCase();
|
|
@@ -3728,7 +3744,7 @@ function matchesAnyDenyPattern(text, patterns, subject = BASH_SUBJECT) {
|
|
|
3728
3744
|
// src/prompt/_generated.ts
|
|
3729
3745
|
var INSTRUCTIONS = "context-mode keeps large output out of the conversation.\n\nWhen a step counts, sums, filters or finds something in over about 20 lines of data (logs, test or build output, big JSON or CSV, long files, web pages), use ctx_execute and print only the answer, not a raw Bash or Read result.\n\nA large tool result is indexed and cut to its best-matching parts; ctx_search finds the rest. A large file's Read is denied: use offset and limit, or ctx_execute with file set. Use normal tools for small output and edits.\n";
|
|
3730
3746
|
var TOOL_DESCRIPTIONS = Object.freeze({
|
|
3731
|
-
ctx_execute: 'Example: `ctx_execute({language:"shell",code:"git log --oneline -5"})`. Required: language, code.\
|
|
3747
|
+
ctx_execute: 'Example: `ctx_execute({language:"shell",code:"git log --oneline -5"})`. Required: language, code.\nWrite code that prints only the answer, not the raw data. Runs code in a sandboxed subprocess in the project directory (shell, powershell, javascript, typescript, python, or another runtime on PATH); only what the code prints comes back. For a large file, set `file` to its local path: the code gets it in the CTX_FILE environment variable. Set `intent` when output may be large: the matching sections come back and the full output is indexed for ctx_search. `timeoutMs` defaults to and caps at 600000; then the whole process tree is killed.',
|
|
3732
3748
|
ctx_batch: 'Example: `ctx_batch({commands:["git log --oneline -5"],queries:["recent changes"]})`. Required: commands, queries.\nRuns several shell commands, then answers several search queries over their combined output, in one call. Use it to collect facts from more than one command at once, for example test results plus recent commits, when you need specific answers rather than the full text. Returns the matching sections and a one-line footer.',
|
|
3733
3749
|
ctx_index: 'Example: `ctx_index({path:"docs/api.md"})`. Required: one of path, content, url.\nStores content so it can be searched later: a local file or folder (nested .gitignore files are respected), raw text, or a URL, which is fetched and converted to Markdown. Use it for documentation or large files you will query more than once, then use ctx_search instead of reading the content again. Returns the source label and how many chunks were stored.',
|
|
3734
3750
|
ctx_search: 'Example: `ctx_search({queries:["auth middleware"]})`. Required: queries.\nSearches content stored with ctx_index and earlier sandbox output in this project. Pass several queries in one call. By default it searches the current worktree; set `scope` to `project` for all worktrees or `session` for this session only. Results from the current session rank first, then by relevance, ranked with measurably better recall than plain keyword search. Set `sort` to `timeline` for oldest-first order across this session, prior sessions and memory, paged with `after`; `offset` is for relevance order only. Set `source` to `decision` to search only rows where the user answered a question. Every hit names its source. When nothing matches, the reply states the scope and how many sources are indexed.',
|
|
@@ -6606,6 +6622,7 @@ var PORTER_MATCH = `
|
|
|
6606
6622
|
AND (:scope <> 'session' OR chunks.session_id = :session_id)
|
|
6607
6623
|
AND (:scope <> 'worktree' OR chunks.worktree = :worktree)
|
|
6608
6624
|
AND (:source IS NULL OR s.label = :source)
|
|
6625
|
+
AND (:ids IS NULL OR s.id IN (SELECT value FROM json_each(:ids)))
|
|
6609
6626
|
${NOT_RAW}`;
|
|
6610
6627
|
var PORTER_ORDER = `
|
|
6611
6628
|
ORDER BY (session_id = :session_id) DESC, (worktree = :worktree) DESC, full DESC, score DESC, source_id DESC, ord ASC`;
|
|
@@ -6634,6 +6651,7 @@ WHERE chunks_tri MATCH :match
|
|
|
6634
6651
|
AND (:scope <> 'session' OR c.session_id = :session_id)
|
|
6635
6652
|
AND (:scope <> 'worktree' OR c.worktree = :worktree)
|
|
6636
6653
|
AND (:source IS NULL OR s.label = :source)
|
|
6654
|
+
AND (:ids IS NULL OR s.id IN (SELECT value FROM json_each(:ids)))
|
|
6637
6655
|
${NOT_RAW}
|
|
6638
6656
|
ORDER BY bm25(chunks_tri, 1.0, ${TITLE_WEIGHT}) ASC, c.source_id DESC, c.ord ASC`;
|
|
6639
6657
|
var PAGE_ROWS = `
|
|
@@ -6906,10 +6924,18 @@ function typoTerms(db, words) {
|
|
|
6906
6924
|
});
|
|
6907
6925
|
return changed ? out.map((t) => `"${t.replaceAll('"', '""')}"*`) : null;
|
|
6908
6926
|
}
|
|
6909
|
-
|
|
6927
|
+
var LABEL_SERIAL = `
|
|
6928
|
+
SELECT COALESCE(MAX(CAST(substr(label, length(:prefix) + 1) AS INTEGER)), 0) + 1 AS n
|
|
6929
|
+
FROM sources WHERE session_id = :session_id AND substr(label, 1, length(:prefix)) = :prefix`;
|
|
6930
|
+
function nextLabelSerial(db, sessionId, prefix) {
|
|
6931
|
+
const row5 = stmt(db.raw, LABEL_SERIAL).get({ session_id: sessionId, prefix });
|
|
6932
|
+
return Number(row5.n);
|
|
6933
|
+
}
|
|
6934
|
+
function ftsQuery(db, q, scope, ctx, sessionId, limit, offset, source, sourceIds) {
|
|
6910
6935
|
const terms = searchTerms(q);
|
|
6911
6936
|
if (terms.length === 0) return [];
|
|
6912
|
-
const
|
|
6937
|
+
const ids = sourceIds === void 0 ? null : JSON.stringify(sourceIds);
|
|
6938
|
+
const filter2 = { scope, session_id: sessionId, worktree: ctx.worktree, source: source ?? null, ids };
|
|
6913
6939
|
const rrf = scope === "project" ? { k: RRF_K } : {};
|
|
6914
6940
|
const porter = (t) => stmt(db.raw, porterRankSql(scope)).all({ ...filter2, match: t.join(" OR "), all: t.join(" "), ...rrf });
|
|
6915
6941
|
let pList = porter(terms);
|
|
@@ -7115,20 +7141,84 @@ function storedLabel(db, source) {
|
|
|
7115
7141
|
const canon = pathLabel(source);
|
|
7116
7142
|
return canon !== source && labelStored(db, canon) ? canon : source;
|
|
7117
7143
|
}
|
|
7118
|
-
function
|
|
7144
|
+
function newestId(db, label2) {
|
|
7145
|
+
const row5 = stmt(db.raw, "SELECT id FROM sources WHERE label = ? ORDER BY id DESC LIMIT 1").get(label2);
|
|
7146
|
+
return row5 === void 0 ? null : Number(row5.id);
|
|
7147
|
+
}
|
|
7148
|
+
function labelOfId(db, id2) {
|
|
7149
|
+
const row5 = stmt(db.raw, "SELECT label FROM sources WHERE id = ?").get(id2);
|
|
7150
|
+
return row5 === void 0 ? null : row5.label;
|
|
7151
|
+
}
|
|
7152
|
+
function pickSource(db, source, suffix = true) {
|
|
7153
|
+
const named2 = storedLabel(db, source);
|
|
7119
7154
|
const id2 = parseSourceHandle(source);
|
|
7155
|
+
const own2 = newestId(db, named2);
|
|
7156
|
+
if (own2 !== null) {
|
|
7157
|
+
const otherLabel = id2 === null || id2 === own2 ? null : labelOfId(db, id2);
|
|
7158
|
+
return { label: named2, id: own2, via: "label", other: otherLabel === null || otherLabel === named2 ? null : { id: id2, label: otherLabel } };
|
|
7159
|
+
}
|
|
7120
7160
|
if (id2 !== null) {
|
|
7121
|
-
const
|
|
7122
|
-
if (
|
|
7161
|
+
const label2 = labelOfId(db, id2);
|
|
7162
|
+
if (label2 !== null) return { label: label2, id: id2, via: "handle", other: null };
|
|
7123
7163
|
}
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7164
|
+
if (suffix) {
|
|
7165
|
+
const prefix = named2 + LABEL_SUFFIX_SEP;
|
|
7166
|
+
const rows = stmt(db.raw, "SELECT id, label FROM sources WHERE substr(label, 1, ?) = ? ORDER BY id DESC").all(prefix.length, prefix);
|
|
7167
|
+
for (const r of rows) {
|
|
7168
|
+
if (r.label.lastIndexOf(LABEL_SUFFIX_SEP) === named2.length) return { label: r.label, id: Number(r.id), via: "suffix", other: null };
|
|
7169
|
+
}
|
|
7130
7170
|
}
|
|
7131
|
-
return source;
|
|
7171
|
+
return { label: source, id: null, via: "none", other: null };
|
|
7172
|
+
}
|
|
7173
|
+
function collisionLine(value, pick2) {
|
|
7174
|
+
if (pick2.other === null || pick2.id === null) return null;
|
|
7175
|
+
return "Source " + JSON.stringify(value) + ": used the label " + shownLabel(pick2.label, null) + " (" + sourceHandle(pick2.id) + "); handle " + sourceHandle(pick2.other.id) + " is " + shownLabel(pick2.other.label, null) + (isLongLabel(pick2.other.label) ? ", search it by its full label." : ", search it with source:" + JSON.stringify(pick2.other.label) + ".");
|
|
7176
|
+
}
|
|
7177
|
+
function labelPage(label2, offset, max) {
|
|
7178
|
+
const buf = Buffer.from(label2, "utf8");
|
|
7179
|
+
let start = Math.min(offset, buf.length);
|
|
7180
|
+
while (start < buf.length && (buf[start] & 192) === 128) start++;
|
|
7181
|
+
let end = Math.min(start + max, buf.length);
|
|
7182
|
+
while (end < buf.length && end > start && (buf[end] & 192) === 128) end--;
|
|
7183
|
+
return { text: buf.subarray(start, end).toString("utf8"), next: end < buf.length ? end : null, total: buf.length };
|
|
7184
|
+
}
|
|
7185
|
+
function groupDigits(n) {
|
|
7186
|
+
const s = String(Math.trunc(n));
|
|
7187
|
+
let out = "";
|
|
7188
|
+
for (let i = 0; i < s.length; i++) {
|
|
7189
|
+
if (i > 0 && (s.length - i) % 3 === 0) out += ",";
|
|
7190
|
+
out += s[i];
|
|
7191
|
+
}
|
|
7192
|
+
return out;
|
|
7193
|
+
}
|
|
7194
|
+
function headBytes(s, max) {
|
|
7195
|
+
let out = "";
|
|
7196
|
+
let used = 0;
|
|
7197
|
+
for (const ch of s) {
|
|
7198
|
+
const n = Buffer.byteLength(ch, "utf8");
|
|
7199
|
+
if (used + n > max) break;
|
|
7200
|
+
out += ch;
|
|
7201
|
+
used += n;
|
|
7202
|
+
}
|
|
7203
|
+
return out;
|
|
7204
|
+
}
|
|
7205
|
+
function isLongLabel(label2) {
|
|
7206
|
+
return Buffer.byteLength(label2, "utf8") > ECHO_MAX_BYTES;
|
|
7207
|
+
}
|
|
7208
|
+
function labelPreview(label2) {
|
|
7209
|
+
return "label (" + groupDigits(Buffer.byteLength(label2, "utf8")) + " B): " + headBytes(label2, LABEL_PREVIEW_BYTES) + "\u2026";
|
|
7210
|
+
}
|
|
7211
|
+
function shownLabel(label2, id2) {
|
|
7212
|
+
if (!isLongLabel(label2)) return label2;
|
|
7213
|
+
return (id2 === null ? "" : sourceHandle(id2) + " ") + "[" + labelPreview(label2) + "]";
|
|
7214
|
+
}
|
|
7215
|
+
function indexedLabelLine(label2, id2) {
|
|
7216
|
+
if (!isLongLabel(label2)) return "Label: " + label2;
|
|
7217
|
+
return "Its label (" + groupDigits(Buffer.byteLength(label2, "utf8")) + " B): " + headBytes(label2, LABEL_PREVIEW_BYTES) + "\u2026; ctx_search({queries:[], source:" + JSON.stringify(sourceHandle(id2)) + "}) reads it whole.";
|
|
7218
|
+
}
|
|
7219
|
+
function sourceCardRow(db, id2) {
|
|
7220
|
+
const row5 = stmt(db.raw, "SELECT label, bytes_total, chunk_count, kind FROM sources WHERE id = ?").get(id2);
|
|
7221
|
+
return row5 === void 0 ? null : { label: row5.label, bytes: Number(row5.bytes_total), chunks: Number(row5.chunk_count), kind: row5.kind };
|
|
7132
7222
|
}
|
|
7133
7223
|
function listSessionSources(db, sessionId, limit) {
|
|
7134
7224
|
const rows = stmt(db.raw, "SELECT id, label, bytes_total FROM sources WHERE session_id = ? ORDER BY id DESC LIMIT ?").all(sessionId, limit);
|
|
@@ -7705,8 +7795,8 @@ function rawEnd(src, from, name) {
|
|
|
7705
7795
|
let k = src.indexOf("</", from);
|
|
7706
7796
|
while (k >= 0) {
|
|
7707
7797
|
const after = k + "</".length + name.length;
|
|
7708
|
-
const
|
|
7709
|
-
if (
|
|
7798
|
+
const named2 = src.slice(k + "</".length, after).toLowerCase() === name;
|
|
7799
|
+
if (named2 && (after >= src.length || !isNameChar(src[after]))) {
|
|
7710
7800
|
const gt = src.indexOf(">", after);
|
|
7711
7801
|
return gt < 0 ? src.length : gt + 1;
|
|
7712
7802
|
}
|
|
@@ -7733,7 +7823,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
7733
7823
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
7734
7824
|
return { end: start + r.read, written: r.written };
|
|
7735
7825
|
}
|
|
7736
|
-
function merge(src, blocks,
|
|
7826
|
+
function merge(src, blocks, join26, cap, lineCut) {
|
|
7737
7827
|
const out = [];
|
|
7738
7828
|
const scratch = new Uint8Array(cap);
|
|
7739
7829
|
let wide;
|
|
@@ -7743,7 +7833,7 @@ function merge(src, blocks, join25, cap, lineCut) {
|
|
|
7743
7833
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
7744
7834
|
};
|
|
7745
7835
|
for (const b of blocks) {
|
|
7746
|
-
if (cur !== void 0 && !
|
|
7836
|
+
if (cur !== void 0 && !join26) {
|
|
7747
7837
|
emit(cur.start, cur.end, curBytes);
|
|
7748
7838
|
cur = void 0;
|
|
7749
7839
|
}
|
|
@@ -7941,24 +8031,24 @@ function jsonShape(text, query) {
|
|
|
7941
8031
|
}
|
|
7942
8032
|
if (outliers.size === 0 || outliers.size > SHAPE_RARE_UNITS_MAX) return null;
|
|
7943
8033
|
const keyScore = rankTexts(keys, query, "any");
|
|
7944
|
-
const
|
|
8034
|
+
const named2 = new Set(keys.filter((_, i) => keyScore[i] > 0));
|
|
7945
8035
|
const units = [...outliers.entries()].map(([i, skewed]) => ({
|
|
7946
8036
|
pos: i,
|
|
7947
8037
|
rank: JSON.stringify(objs[i]),
|
|
7948
|
-
render: (budget) => renderRow(i, objs[i], skewed,
|
|
8038
|
+
render: (budget) => renderRow(i, objs[i], skewed, named2, budget)
|
|
7949
8039
|
}));
|
|
7950
8040
|
return { header: schemaOf(objs.length, keys) + ", " + outliers.size + " rare:", units };
|
|
7951
8041
|
}
|
|
7952
|
-
function renderRow(i, row5, skewed,
|
|
8042
|
+
function renderRow(i, row5, skewed, named2, budget) {
|
|
7953
8043
|
const prefix = "[" + i + "] ";
|
|
7954
|
-
const body = fitRow(row5, skewed,
|
|
8044
|
+
const body = fitRow(row5, skewed, named2, budget - bytes(prefix));
|
|
7955
8045
|
return body === null ? null : prefix + body;
|
|
7956
8046
|
}
|
|
7957
|
-
function fitRow(row5, skewed,
|
|
8047
|
+
function fitRow(row5, skewed, named2, budget) {
|
|
7958
8048
|
const whole2 = JSON.stringify(row5);
|
|
7959
8049
|
if (bytes(whole2) <= budget) return whole2;
|
|
7960
8050
|
const own2 = Object.keys(row5);
|
|
7961
|
-
const tier = (k) => skewed.includes(k) ? 0 :
|
|
8051
|
+
const tier = (k) => skewed.includes(k) ? 0 : named2.has(k) ? 1 : typeof row5[k] !== "object" || row5[k] === null ? 2 : 3;
|
|
7962
8052
|
const order = [...own2].sort((a, b) => tier(a) - tier(b) || own2.indexOf(a) - own2.indexOf(b));
|
|
7963
8053
|
const field = (k) => JSON.stringify(k) + ":" + JSON.stringify(row5[k]);
|
|
7964
8054
|
const chosen = /* @__PURE__ */ new Set();
|
|
@@ -7980,11 +8070,11 @@ function jsonExtremes(text, query) {
|
|
|
7980
8070
|
const parsedRows = jsonRows(text);
|
|
7981
8071
|
if (parsedRows === null) return null;
|
|
7982
8072
|
const { objs, keys } = parsedRows;
|
|
7983
|
-
const
|
|
8073
|
+
const named2 = namedKeys(keys, query);
|
|
7984
8074
|
const picks = /* @__PURE__ */ new Map();
|
|
7985
8075
|
let used = 0;
|
|
7986
8076
|
for (const k of keys) {
|
|
7987
|
-
if (!
|
|
8077
|
+
if (!named2.has(k) || used >= SHAPE_EXTREME_KEYS) continue;
|
|
7988
8078
|
if (!objs.every((o) => typeof o[k] === "number" && Number.isFinite(o[k]))) continue;
|
|
7989
8079
|
let hi = 0, lo = 0;
|
|
7990
8080
|
for (let i = 1; i < objs.length; i++) {
|
|
@@ -8000,7 +8090,7 @@ function jsonExtremes(text, query) {
|
|
|
8000
8090
|
const units = [...picks.entries()].map(([i, k]) => ({
|
|
8001
8091
|
pos: i,
|
|
8002
8092
|
rank: "",
|
|
8003
|
-
render: (budget) => renderRow(i, objs[i], [k],
|
|
8093
|
+
render: (budget) => renderRow(i, objs[i], [k], named2, budget)
|
|
8004
8094
|
}));
|
|
8005
8095
|
return { header: schemaOf(objs.length, keys) + ", extremes of " + [...new Set(picks.values())].join(",") + ":", units, direct: true };
|
|
8006
8096
|
}
|
|
@@ -11640,14 +11730,14 @@ var $ZodIntersection = /* @__PURE__ */ $constructor("$ZodIntersection", (inst, d
|
|
|
11640
11730
|
inst._zod.parse = (payload, ctx) => {
|
|
11641
11731
|
const input = payload.value;
|
|
11642
11732
|
const left = def.left._zod.run({ value: input, issues: [] }, ctx);
|
|
11643
|
-
const
|
|
11644
|
-
const async = left instanceof Promise ||
|
|
11733
|
+
const right2 = def.right._zod.run({ value: input, issues: [] }, ctx);
|
|
11734
|
+
const async = left instanceof Promise || right2 instanceof Promise;
|
|
11645
11735
|
if (async) {
|
|
11646
|
-
return Promise.all([left,
|
|
11647
|
-
return handleIntersectionResults(payload, left2,
|
|
11736
|
+
return Promise.all([left, right2]).then(([left2, right3]) => {
|
|
11737
|
+
return handleIntersectionResults(payload, left2, right3);
|
|
11648
11738
|
});
|
|
11649
11739
|
}
|
|
11650
|
-
return handleIntersectionResults(payload, left,
|
|
11740
|
+
return handleIntersectionResults(payload, left, right2);
|
|
11651
11741
|
};
|
|
11652
11742
|
});
|
|
11653
11743
|
function mergeValues(a, b) {
|
|
@@ -11694,16 +11784,16 @@ function mergeValues(a, b) {
|
|
|
11694
11784
|
}
|
|
11695
11785
|
return { valid: false, mergeErrorPath: [] };
|
|
11696
11786
|
}
|
|
11697
|
-
function handleIntersectionResults(result, left,
|
|
11787
|
+
function handleIntersectionResults(result, left, right2) {
|
|
11698
11788
|
if (left.issues.length) {
|
|
11699
11789
|
result.issues.push(...left.issues);
|
|
11700
11790
|
}
|
|
11701
|
-
if (
|
|
11702
|
-
result.issues.push(...
|
|
11791
|
+
if (right2.issues.length) {
|
|
11792
|
+
result.issues.push(...right2.issues);
|
|
11703
11793
|
}
|
|
11704
11794
|
if (aborted(result))
|
|
11705
11795
|
return result;
|
|
11706
|
-
const merged = mergeValues(left.value,
|
|
11796
|
+
const merged = mergeValues(left.value, right2.value);
|
|
11707
11797
|
if (!merged.valid) {
|
|
11708
11798
|
throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
|
|
11709
11799
|
}
|
|
@@ -17770,11 +17860,11 @@ function _discriminatedUnion(Class2, discriminator, options, params) {
|
|
|
17770
17860
|
...normalizeParams(params)
|
|
17771
17861
|
});
|
|
17772
17862
|
}
|
|
17773
|
-
function _intersection(Class2, left,
|
|
17863
|
+
function _intersection(Class2, left, right2) {
|
|
17774
17864
|
return new Class2({
|
|
17775
17865
|
type: "intersection",
|
|
17776
17866
|
left,
|
|
17777
|
-
right
|
|
17867
|
+
right: right2
|
|
17778
17868
|
});
|
|
17779
17869
|
}
|
|
17780
17870
|
function _tuple(Class2, items, _paramsOrRest, _params) {
|
|
@@ -19452,11 +19542,11 @@ var ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def
|
|
|
19452
19542
|
$ZodIntersection.init(inst, def);
|
|
19453
19543
|
ZodType.init(inst, def);
|
|
19454
19544
|
});
|
|
19455
|
-
function intersection(left,
|
|
19545
|
+
function intersection(left, right2) {
|
|
19456
19546
|
return new ZodIntersection({
|
|
19457
19547
|
type: "intersection",
|
|
19458
19548
|
left,
|
|
19459
|
-
right
|
|
19549
|
+
right: right2
|
|
19460
19550
|
});
|
|
19461
19551
|
}
|
|
19462
19552
|
var ZodTuple = /* @__PURE__ */ $constructor("ZodTuple", (inst, def) => {
|
|
@@ -20198,8 +20288,27 @@ function sourceCount(db, scope, ctx, source) {
|
|
|
20198
20288
|
});
|
|
20199
20289
|
return Number(row5.n);
|
|
20200
20290
|
}
|
|
20201
|
-
function zeroHits(db, scope, ctx, source) {
|
|
20202
|
-
|
|
20291
|
+
function zeroHits(db, scope, ctx, source, offset = 0) {
|
|
20292
|
+
const n = sourceCount(db, scope, ctx, source);
|
|
20293
|
+
if (offset > 0) return reply("No more hits past offset " + offset + ' in scope "' + scope + '" across ' + n + " source(s).", false);
|
|
20294
|
+
return reply('No hits in scope "' + scope + '" across ' + n + " source(s).", false);
|
|
20295
|
+
}
|
|
20296
|
+
function named(given, pick2) {
|
|
20297
|
+
if (given === void 0 || pick2 === null) return { arg: given, note: null };
|
|
20298
|
+
const arg = pick2.id !== null && isLongLabel(given) ? sourceHandle(pick2.id) : given;
|
|
20299
|
+
return { arg, note: collisionLine(given, pick2) };
|
|
20300
|
+
}
|
|
20301
|
+
function sourceCard(db, id2, input, scope, arg) {
|
|
20302
|
+
const row5 = sourceCardRow(db, id2);
|
|
20303
|
+
if (row5 === null) return null;
|
|
20304
|
+
const pg = labelPage(row5.label, input.offset ?? 0, LABEL_PAGE_BYTES);
|
|
20305
|
+
const lines = [
|
|
20306
|
+
"Source " + sourceHandle(id2) + ": label " + groupDigits(pg.total) + " B, " + row5.chunks + " chunk(s), " + groupDigits(row5.bytes) + " B of " + row5.kind + ".",
|
|
20307
|
+
"Label:",
|
|
20308
|
+
pg.text
|
|
20309
|
+
];
|
|
20310
|
+
if (pg.next !== null) lines.push("More: " + callText([], scope, arg, "offset:" + pg.next));
|
|
20311
|
+
return reply(lines.join("\n"), false);
|
|
20203
20312
|
}
|
|
20204
20313
|
function callText(queries, scope, source, cursor) {
|
|
20205
20314
|
const src = source === void 0 ? "" : ", source:" + JSON.stringify(source);
|
|
@@ -20230,7 +20339,7 @@ WHERE label = :source
|
|
|
20230
20339
|
AND (:scope <> 'session' OR session_id = :session_id)
|
|
20231
20340
|
AND (:scope <> 'worktree' OR worktree = :worktree)
|
|
20232
20341
|
ORDER BY id DESC LIMIT 1`;
|
|
20233
|
-
function jsonRowsReply(db, input, scope, ctx) {
|
|
20342
|
+
function jsonRowsReply(db, input, scope, ctx, nm) {
|
|
20234
20343
|
if (input.source === void 0 || input.source === DECISION_SOURCE || input.queries.length === 0) return null;
|
|
20235
20344
|
const src = db.raw.prepare(JSON_SOURCE).get({ source: input.source, scope, session_id: ctx.sessionId, worktree: ctx.project.worktree });
|
|
20236
20345
|
if (src === void 0 || Number(src.bytes_total) > JSON_SOURCE_MAX_BYTES) return null;
|
|
@@ -20241,25 +20350,27 @@ function jsonRowsReply(db, input, scope, ctx) {
|
|
|
20241
20350
|
const texts = objs.map((o) => JSON.stringify(o));
|
|
20242
20351
|
const offset = input.offset ?? 0;
|
|
20243
20352
|
const out = [objs.length + " objects {" + keys.join(",") + "}"];
|
|
20353
|
+
const name = shownLabel(input.source, Number(src.id));
|
|
20244
20354
|
let shown2 = 0;
|
|
20245
20355
|
let more = false;
|
|
20246
20356
|
for (const q of input.queries) {
|
|
20247
20357
|
const scores = rankTexts(texts, q, "any");
|
|
20248
20358
|
const order = objs.map((_, i) => i).filter((i) => scores[i] > 0).sort((a, b) => scores[b] - scores[a] || a - b);
|
|
20249
|
-
const
|
|
20359
|
+
const named2 = namedKeys(keys, q);
|
|
20250
20360
|
out.push("Query " + JSON.stringify(q) + ":");
|
|
20251
20361
|
for (const i of order.slice(offset, offset + JSON_ROWS_PAGE)) {
|
|
20252
|
-
const row5 = fitRow(objs[i], [],
|
|
20362
|
+
const row5 = fitRow(objs[i], [], named2, SNIPPET_MAX_BYTES);
|
|
20253
20363
|
if (row5 === null) continue;
|
|
20254
|
-
out.push(
|
|
20364
|
+
out.push(name + " [" + i + "]: " + row5);
|
|
20255
20365
|
shown2++;
|
|
20256
20366
|
}
|
|
20257
20367
|
if (order.length > offset + JSON_ROWS_PAGE) {
|
|
20258
|
-
out.push("More: " + callText([q], scope,
|
|
20368
|
+
out.push("More: " + callText([q], scope, nm.arg, "offset:" + (offset + JSON_ROWS_PAGE)));
|
|
20259
20369
|
more = true;
|
|
20260
20370
|
}
|
|
20261
20371
|
}
|
|
20262
|
-
|
|
20372
|
+
if (shown2 === 0 && !more) return null;
|
|
20373
|
+
return reply((nm.note === null ? out : [nm.note, ...out]).join("\n"), false);
|
|
20263
20374
|
}
|
|
20264
20375
|
var SMALL_SOURCE_SHARE = 0.5;
|
|
20265
20376
|
var SOURCE_BYTES = "SELECT id, bytes_total FROM sources WHERE id IN (SELECT value FROM json_each(:ids))";
|
|
@@ -20278,23 +20389,23 @@ function replyHits(hits, size) {
|
|
|
20278
20389
|
while (n < size && n < hits.length && hits[n].full === true) n++;
|
|
20279
20390
|
return n;
|
|
20280
20391
|
}
|
|
20281
|
-
function relevance(db, given, scope, ctx) {
|
|
20392
|
+
function relevance(db, given, scope, ctx, nm) {
|
|
20282
20393
|
const input = { ...given, queries: decisionQueries(given) };
|
|
20283
20394
|
const offset = input.offset ?? 0;
|
|
20284
20395
|
const size = pageSize(input);
|
|
20285
20396
|
const fetched = input.queries.map((q) => page(db, q, input, scope, ctx, offset, 1));
|
|
20286
20397
|
const take = fetched.map((h) => replyHits(h, size));
|
|
20287
20398
|
const pages = fetched.map((h, i) => h.slice(0, take[i]));
|
|
20288
|
-
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source);
|
|
20289
|
-
const moreLine3 = (q, pos) => "More: " + callText([q], scope,
|
|
20399
|
+
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, offset);
|
|
20400
|
+
const moreLine3 = (q, pos) => "More: " + callText([q], scope, nm.arg, "offset:" + pos);
|
|
20290
20401
|
let reserve = 0;
|
|
20291
20402
|
for (const q of input.queries) reserve += bytes2(moreLine3(q, offset + size)) + 1;
|
|
20292
20403
|
const total = input.source === DECISION_SOURCE ? /* @__PURE__ */ new Map() : sourceBytes(db, [...new Set(pages.flat().map((h) => h.sourceId))]);
|
|
20293
20404
|
const spent = /* @__PURE__ */ new Map();
|
|
20294
|
-
const lines = [];
|
|
20405
|
+
const lines = nm.note === null ? [] : [nm.note];
|
|
20295
20406
|
const more = [];
|
|
20296
20407
|
const shown2 = /* @__PURE__ */ new Set();
|
|
20297
|
-
let used = 0;
|
|
20408
|
+
let used = nm.note === null ? 0 : bytes2(nm.note) + 1;
|
|
20298
20409
|
let stopped = false;
|
|
20299
20410
|
input.queries.forEach((q, qi) => {
|
|
20300
20411
|
const hits = pages[qi];
|
|
@@ -20312,10 +20423,11 @@ function relevance(db, given, scope, ctx) {
|
|
|
20312
20423
|
const hit = hits[i];
|
|
20313
20424
|
const key = hit.sourceId + ":" + hit.ord;
|
|
20314
20425
|
if (shown2.has(key)) {
|
|
20315
|
-
|
|
20426
|
+
const name = shownLabel(hit.label, hit.sourceId);
|
|
20427
|
+
again.set(name, [...again.get(name) ?? [], hit.ord]);
|
|
20316
20428
|
continue;
|
|
20317
20429
|
}
|
|
20318
|
-
const line = hit.label + " #" + hit.ord + ": " + hit.snippet;
|
|
20430
|
+
const line = shownLabel(hit.label, hit.sourceId) + " #" + hit.ord + ": " + hit.snippet;
|
|
20319
20431
|
if (used + bytes2(line) + 1 + reserve > OUTPUT_CAP) {
|
|
20320
20432
|
cut = offset + i;
|
|
20321
20433
|
stopped = true;
|
|
@@ -20343,23 +20455,23 @@ function relevance(db, given, scope, ctx) {
|
|
|
20343
20455
|
const moreLines = [];
|
|
20344
20456
|
const byPos = /* @__PURE__ */ new Map();
|
|
20345
20457
|
for (const m of more) byPos.set(m.pos, [...byPos.get(m.pos) ?? [], m.q]);
|
|
20346
|
-
for (const [pos, qs] of byPos) moreLines.push("More: " + callText(qs, scope,
|
|
20458
|
+
for (const [pos, qs] of byPos) moreLines.push("More: " + callText(qs, scope, nm.arg, "offset:" + pos));
|
|
20347
20459
|
return reply(lines.concat(moreLines).join("\n"), false);
|
|
20348
20460
|
}
|
|
20349
20461
|
function timelineLine(r) {
|
|
20350
20462
|
const nl = r.text.indexOf("\n");
|
|
20351
20463
|
const first = nl < 0 ? r.text : r.text.slice(0, nl);
|
|
20352
20464
|
const seq = r.seq === null ? "" : " #" + r.seq;
|
|
20353
|
-
return "[" + new Date(r.ts).toISOString() + "] " + r.label + seq + " " + first;
|
|
20465
|
+
return "[" + new Date(r.ts).toISOString() + "] " + shownLabel(r.label, r.sourceId) + seq + " " + first;
|
|
20354
20466
|
}
|
|
20355
|
-
function timeline(db, input, scope, ctx) {
|
|
20467
|
+
function timeline(db, input, scope, ctx, nm) {
|
|
20356
20468
|
const memory = scope === "session" ? [] : readAutoMemory(ctx.project);
|
|
20357
20469
|
const page2 = ftsQueryTimeline(db, scope, ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, input.after ?? null, input.source, memory);
|
|
20358
20470
|
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source);
|
|
20359
|
-
const moreLine3 = (ts) => "more: " + callText(input.queries, scope,
|
|
20471
|
+
const moreLine3 = (ts) => "more: " + callText(input.queries, scope, nm.arg, 'sort:"timeline", after:' + ts);
|
|
20360
20472
|
const reserve = bytes2(moreLine3(page2.rows[page2.rows.length - 1].ts)) + 1;
|
|
20361
|
-
const lines = [];
|
|
20362
|
-
let used = 0;
|
|
20473
|
+
const lines = nm.note === null ? [] : [nm.note];
|
|
20474
|
+
let used = nm.note === null ? 0 : bytes2(nm.note) + 1;
|
|
20363
20475
|
let lastTs = null;
|
|
20364
20476
|
let more = page2.more;
|
|
20365
20477
|
let i = 0;
|
|
@@ -20395,9 +20507,16 @@ async function handler(input, ctx) {
|
|
|
20395
20507
|
const scope = input.scope ?? "worktree";
|
|
20396
20508
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
20397
20509
|
try {
|
|
20398
|
-
|
|
20399
|
-
|
|
20400
|
-
|
|
20510
|
+
const given = input.source;
|
|
20511
|
+
const pick2 = given !== void 0 && given !== DECISION_SOURCE ? pickSource(db, given) : null;
|
|
20512
|
+
if (pick2 !== null) input = { ...input, source: pick2.label };
|
|
20513
|
+
const nm = named(given, pick2);
|
|
20514
|
+
if (sort === "timeline") return timeline(db, input, scope, ctx, nm);
|
|
20515
|
+
if (pick2 !== null && pick2.id !== null && input.queries.length === 0) {
|
|
20516
|
+
const card = sourceCard(db, pick2.id, input, scope, nm.arg);
|
|
20517
|
+
if (card !== null) return card;
|
|
20518
|
+
}
|
|
20519
|
+
return jsonRowsReply(db, input, scope, ctx, nm) ?? relevance(db, input, scope, ctx, nm);
|
|
20401
20520
|
} finally {
|
|
20402
20521
|
closeDb(db);
|
|
20403
20522
|
}
|
|
@@ -20418,6 +20537,7 @@ var ctxBatchSchema = external_exports.object({
|
|
|
20418
20537
|
}, { error: unknownField }).strict();
|
|
20419
20538
|
var TOOL = "ctx_batch";
|
|
20420
20539
|
var LABEL_PREFIX = TOOL + ":";
|
|
20540
|
+
var LABEL_SEP = ":";
|
|
20421
20541
|
var SHELL = "shell";
|
|
20422
20542
|
var SHELL_INLINE_FLAG = "-c";
|
|
20423
20543
|
var MARKER = "$ ";
|
|
@@ -20485,6 +20605,7 @@ function indexCombined(db, ctx, label2, ran, deadline, budgetBytes) {
|
|
|
20485
20605
|
const display = shown(chunks, ran.map((r) => r.head));
|
|
20486
20606
|
const bodies = /* @__PURE__ */ new Map();
|
|
20487
20607
|
const raw = /* @__PURE__ */ new Map();
|
|
20608
|
+
const ids = [];
|
|
20488
20609
|
let total = 0;
|
|
20489
20610
|
for (const c of chunks) total += c.bytes;
|
|
20490
20611
|
let indexed = 0;
|
|
@@ -20505,6 +20626,7 @@ function indexCombined(db, ctx, label2, ran, deadline, budgetBytes) {
|
|
|
20505
20626
|
chunkCount: group.length,
|
|
20506
20627
|
createdAt: Date.now()
|
|
20507
20628
|
}, group);
|
|
20629
|
+
ids.push(id2);
|
|
20508
20630
|
for (const c of group) {
|
|
20509
20631
|
bodies.set(chunkKey(id2, c.ord), display[c.ord]);
|
|
20510
20632
|
raw.set(chunkKey(id2, c.ord), c.text);
|
|
@@ -20517,25 +20639,25 @@ function indexCombined(db, ctx, label2, ran, deadline, budgetBytes) {
|
|
|
20517
20639
|
for (const c of chunks) {
|
|
20518
20640
|
if (queued + c.bytes > budgetBytes) {
|
|
20519
20641
|
const stop2 = flush() ? "budget" : "deadline";
|
|
20520
|
-
return { bodies, raw, indexed, total, stop: stop2 };
|
|
20642
|
+
return { bodies, raw, ids, indexed, total, stop: stop2 };
|
|
20521
20643
|
}
|
|
20522
|
-
if (group.length > 0 && groupBytes + c.bytes > INDEX_WRITE_CHUNK && !flush()) return { bodies, raw, indexed, total, stop: "deadline" };
|
|
20644
|
+
if (group.length > 0 && groupBytes + c.bytes > INDEX_WRITE_CHUNK && !flush()) return { bodies, raw, ids, indexed, total, stop: "deadline" };
|
|
20523
20645
|
group.push(c);
|
|
20524
20646
|
groupBytes += c.bytes;
|
|
20525
20647
|
queued += c.bytes;
|
|
20526
20648
|
}
|
|
20527
20649
|
const stop = flush() ? null : "deadline";
|
|
20528
|
-
return { bodies, raw, indexed, total, stop };
|
|
20650
|
+
return { bodies, raw, ids, indexed, total, stop };
|
|
20529
20651
|
}
|
|
20530
20652
|
function bytes3(s) {
|
|
20531
20653
|
return Buffer.byteLength(s, "utf8");
|
|
20532
20654
|
}
|
|
20533
|
-
function answer(db, ctx,
|
|
20655
|
+
function answer(db, ctx, ownIds, queries, share, own2) {
|
|
20534
20656
|
const seen = /* @__PURE__ */ new Set();
|
|
20535
20657
|
const lines = [];
|
|
20536
20658
|
for (const [qi, q] of queries.entries()) {
|
|
20537
20659
|
if (ctx.signal.aborted) break;
|
|
20538
|
-
let hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0,
|
|
20660
|
+
let hits = ownIds.length === 0 ? [] : ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0, void 0, ownIds);
|
|
20539
20661
|
if (hits.length === 0) hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0);
|
|
20540
20662
|
const head = "## " + (bytes3(q) > ECHO_MAX_BYTES ? "query " + (qi + 1) : q);
|
|
20541
20663
|
let used = bytes3(head) + 1;
|
|
@@ -20574,9 +20696,10 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
20574
20696
|
const ran = pool.results;
|
|
20575
20697
|
const last2 = ran[ran.length - 1];
|
|
20576
20698
|
const sandboxBytes = ran.reduce((n, r) => n + r.bytes, 0);
|
|
20577
|
-
const label2 = LABEL_PREFIX + ctx.turn;
|
|
20578
20699
|
try {
|
|
20579
20700
|
const db = await openDb(ctx.project);
|
|
20701
|
+
const turnPrefix = LABEL_PREFIX + ctx.turn + LABEL_SEP;
|
|
20702
|
+
const label2 = turnPrefix + nextLabelSerial(db, ctx.sessionId, turnPrefix);
|
|
20580
20703
|
let sections;
|
|
20581
20704
|
let idx;
|
|
20582
20705
|
const exitLine = last2.exitCode === null || last2.exitCode === 0 ? null : "exit " + last2.exitCode;
|
|
@@ -20592,7 +20715,7 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
20592
20715
|
notice = cut === null ? stop : cause === null ? cut : cause + " " + cut;
|
|
20593
20716
|
const fixed = (exitLine === null ? 0 : bytes3(exitLine) + 1) + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
|
|
20594
20717
|
const share = Math.floor((OUTPUT_CAP - fixed) / queries.length);
|
|
20595
|
-
const answered = answer(db, ctx,
|
|
20718
|
+
const answered = answer(db, ctx, idx.ids, queries, share, idx.bodies);
|
|
20596
20719
|
sections = answered.lines;
|
|
20597
20720
|
const unseen = [...idx.bodies].filter(([k, text]) => text !== "" && !answered.seen.has(k)).map(([k]) => idx.raw.get(k));
|
|
20598
20721
|
const unseenBytes = unseen.reduce((n, t) => n + bytes3(t) + 1, 0);
|
|
@@ -20629,7 +20752,7 @@ var ctxBatch = Object.freeze({
|
|
|
20629
20752
|
|
|
20630
20753
|
// src/core/tools/doctor.ts
|
|
20631
20754
|
import { readdirSync as readdirSync5, readFileSync as readFileSync13, existsSync as existsSync13 } from "node:fs";
|
|
20632
|
-
import { basename as
|
|
20755
|
+
import { basename as basename5, dirname as dirname8, join as join16 } from "node:path";
|
|
20633
20756
|
|
|
20634
20757
|
// src/core/ops/doctor-config.ts
|
|
20635
20758
|
import { existsSync as existsSync6, readdirSync as readdirSync3 } from "node:fs";
|
|
@@ -21630,9 +21753,9 @@ var Tokenizer = class {
|
|
|
21630
21753
|
cp = this.nextCode();
|
|
21631
21754
|
}
|
|
21632
21755
|
const { out } = this.parseDigits(cp, isDigit4);
|
|
21633
|
-
const
|
|
21634
|
-
if (minus)
|
|
21635
|
-
const value = Number(leftMinus ? String.fromCodePoint(CodePoint.DASH, ...left, CodePoint.LATIN_SMALL_E, ...
|
|
21756
|
+
const right2 = out;
|
|
21757
|
+
if (minus) right2.unshift(CodePoint.DASH);
|
|
21758
|
+
const value = Number(leftMinus ? String.fromCodePoint(CodePoint.DASH, ...left, CodePoint.LATIN_SMALL_E, ...right2) : String.fromCodePoint(...left, CodePoint.LATIN_SMALL_E, ...right2));
|
|
21636
21759
|
this.endToken("Float", "start", value);
|
|
21637
21760
|
return this.back("DATA");
|
|
21638
21761
|
}
|
|
@@ -23813,7 +23936,7 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
23813
23936
|
const read3 = row5.id === "pi" ? mcpFile(row5, home, env) : null;
|
|
23814
23937
|
if (parts.length === 0) return read3 === null ? pass("D3") : { ...pass("D3"), detail: read3 };
|
|
23815
23938
|
const detail = D3_DETAIL(parts);
|
|
23816
|
-
const fix = parts.includes(PART_MCP)
|
|
23939
|
+
const fix = parts.includes(PART_MCP) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
|
|
23817
23940
|
return fail2("D3", read3 === null ? detail : detail + D4_REASON_JOIN + read3, fix);
|
|
23818
23941
|
}
|
|
23819
23942
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
@@ -23867,7 +23990,7 @@ function configPaths(row5, env, worktree) {
|
|
|
23867
23990
|
}
|
|
23868
23991
|
|
|
23869
23992
|
// src/core/ops/doctor-db.ts
|
|
23870
|
-
import { existsSync as existsSync7 } from "node:fs";
|
|
23993
|
+
import { existsSync as existsSync7, statSync as statSync5 } from "node:fs";
|
|
23871
23994
|
var unknown2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
|
|
23872
23995
|
var pass2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
|
|
23873
23996
|
var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -23905,8 +24028,18 @@ function failsOnCorrupt(step) {
|
|
|
23905
24028
|
throw err;
|
|
23906
24029
|
}
|
|
23907
24030
|
}
|
|
24031
|
+
function orphanFiles(dbPath) {
|
|
24032
|
+
const files = [];
|
|
24033
|
+
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
24034
|
+
const path7 = dbPath + suffix;
|
|
24035
|
+
if (existsSync7(path7)) files.push({ path: path7, bytes: statSync5(path7).size });
|
|
24036
|
+
}
|
|
24037
|
+
return files.length > 0 && !existsSync7(dbPath) ? files : [];
|
|
24038
|
+
}
|
|
23908
24039
|
async function checkDb(project) {
|
|
23909
|
-
const clean = { schemaStale: false, integrityFailed: false };
|
|
24040
|
+
const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
|
|
24041
|
+
const orphan = orphanFiles(project.dbPath);
|
|
24042
|
+
if (orphan.length > 0) return { row: fail3(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
|
|
23910
24043
|
if (!existsSync7(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
23911
24044
|
const sqlite = await loadSqlite2();
|
|
23912
24045
|
if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
|
|
@@ -23922,11 +24055,11 @@ async function checkDb(project) {
|
|
|
23922
24055
|
}
|
|
23923
24056
|
const schemaStale = got !== null && got !== SCHEMA_VERSION;
|
|
23924
24057
|
const integrityFailed = failsOnCorrupt(() => !integrityOk(db));
|
|
23925
|
-
if (integrityFailed) return { row: fail3(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale, integrityFailed };
|
|
23926
|
-
if (schemaStale && got !== null) return { row: fail3(D8_STALE_SCHEMA_DETAIL(got, SCHEMA_VERSION), DOCTOR_FIX_UPGRADE), schemaStale, integrityFailed };
|
|
24058
|
+
if (integrityFailed) return { row: fail3(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale, integrityFailed, orphan: [] };
|
|
24059
|
+
if (schemaStale && got !== null) return { row: fail3(D8_STALE_SCHEMA_DETAIL(got, SCHEMA_VERSION), DOCTOR_FIX_UPGRADE), schemaStale, integrityFailed, orphan: [] };
|
|
23927
24060
|
return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
23928
24061
|
} catch (err) {
|
|
23929
|
-
if (isCorrupt2(err)) return { row: fail3(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale: false, integrityFailed: true };
|
|
24062
|
+
if (isCorrupt2(err)) return { row: fail3(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale: false, integrityFailed: true, orphan: [] };
|
|
23930
24063
|
return { row: unknown2("D8", message2(err)), ...clean };
|
|
23931
24064
|
} finally {
|
|
23932
24065
|
raw?.close();
|
|
@@ -23994,7 +24127,8 @@ function fetchCause(err, timeoutMs) {
|
|
|
23994
24127
|
const cause = err instanceof Error && err.cause instanceof Error ? err.cause : err;
|
|
23995
24128
|
const code = typeof cause === "object" && cause !== null && "code" in cause && typeof cause.code === "string" ? cause.code : "";
|
|
23996
24129
|
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
23997
|
-
|
|
24130
|
+
const parts = code !== "" && !msg.includes(code) ? [code, msg] : [msg];
|
|
24131
|
+
return D1_NPM_ERROR(parts.filter((part) => part !== "").join(" "));
|
|
23998
24132
|
}
|
|
23999
24133
|
async function npmLatest(url2, tag2, signal, timeoutMs) {
|
|
24000
24134
|
try {
|
|
@@ -24107,9 +24241,9 @@ async function checkNode(i) {
|
|
|
24107
24241
|
return pass3("D2", bun.length === 0 ? DOCTOR_PASS_DETAIL : bun.join(D4_REASON_JOIN));
|
|
24108
24242
|
}
|
|
24109
24243
|
function checkMcp(ctx) {
|
|
24110
|
-
const
|
|
24244
|
+
const named2 = ctx.clientInfo !== void 0 && ctx.clientInfo.name !== "";
|
|
24111
24245
|
const versioned = ctx.protocolVersion !== void 0 && ctx.protocolVersion !== "";
|
|
24112
|
-
return
|
|
24246
|
+
return named2 || versioned ? pass3("D6") : unknown3("D6", D6_UNKNOWN_DETAIL);
|
|
24113
24247
|
}
|
|
24114
24248
|
function piCwdInside(worktree, piCwd) {
|
|
24115
24249
|
if (piCwd === void 0 || !existsSync8(piCwd)) return false;
|
|
@@ -24144,7 +24278,7 @@ import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
|
|
|
24144
24278
|
|
|
24145
24279
|
// src/setup/spawn-bin.ts
|
|
24146
24280
|
import { spawnSync } from "node:child_process";
|
|
24147
|
-
import { accessSync as accessSync2, constants as fsc, statSync as
|
|
24281
|
+
import { accessSync as accessSync2, constants as fsc, statSync as statSync6 } from "node:fs";
|
|
24148
24282
|
import path4 from "node:path";
|
|
24149
24283
|
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
24150
24284
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
@@ -24162,7 +24296,7 @@ function whichBin(bin, env, platform = process.platform) {
|
|
|
24162
24296
|
const f = path4.join(dir, n);
|
|
24163
24297
|
try {
|
|
24164
24298
|
accessSync2(f, fsc.X_OK);
|
|
24165
|
-
if (
|
|
24299
|
+
if (statSync6(f).isFile()) return f;
|
|
24166
24300
|
} catch {
|
|
24167
24301
|
}
|
|
24168
24302
|
}
|
|
@@ -24370,19 +24504,52 @@ function loadFixture(bundleDir2, agent) {
|
|
|
24370
24504
|
}
|
|
24371
24505
|
return { event: e.event, payload: e.payload };
|
|
24372
24506
|
}
|
|
24373
|
-
|
|
24374
|
-
|
|
24375
|
-
|
|
24376
|
-
|
|
24507
|
+
var CWD_KEY = {
|
|
24508
|
+
"claude-code": "cwd",
|
|
24509
|
+
codex: "cwd",
|
|
24510
|
+
gemini: "cwd",
|
|
24511
|
+
qwen: "cwd",
|
|
24512
|
+
"copilot-cli": "cwd",
|
|
24513
|
+
vscode: "cwd",
|
|
24514
|
+
kiro: "cwd",
|
|
24515
|
+
zcode: "cwd",
|
|
24516
|
+
pi: "cwd",
|
|
24517
|
+
opencode: "directory"
|
|
24518
|
+
};
|
|
24519
|
+
function payloadFor(agent, payload, worktree) {
|
|
24520
|
+
return worktree !== void 0 && isObject5(payload) ? { ...payload, [CWD_KEY[agent]]: worktree } : payload;
|
|
24521
|
+
}
|
|
24522
|
+
var SHAPE = {
|
|
24523
|
+
"claude-code": "claude",
|
|
24524
|
+
codex: "claude",
|
|
24525
|
+
qwen: "claude",
|
|
24526
|
+
vscode: "claude",
|
|
24527
|
+
zcode: "claude",
|
|
24528
|
+
gemini: "gemini",
|
|
24529
|
+
"copilot-cli": "copilot",
|
|
24530
|
+
kiro: "text",
|
|
24531
|
+
pi: "text",
|
|
24532
|
+
opencode: "text"
|
|
24533
|
+
};
|
|
24534
|
+
var COPILOT_KEYS = ["permissionDecision", "additionalContext", "modifiedResult"];
|
|
24535
|
+
function isNativeShape(agent, stdout, exitCode, killed, event) {
|
|
24377
24536
|
if (killed !== null || exitCode !== 0 && exitCode !== 2) return false;
|
|
24378
|
-
if (stdout.length === 0) return true;
|
|
24537
|
+
if (stdout.length === 0 || SHAPE[agent] === "text") return true;
|
|
24379
24538
|
let out;
|
|
24380
24539
|
try {
|
|
24381
24540
|
out = JSON.parse(stdout);
|
|
24382
24541
|
} catch {
|
|
24383
24542
|
return false;
|
|
24384
24543
|
}
|
|
24385
|
-
|
|
24544
|
+
if (!isObject5(out)) return false;
|
|
24545
|
+
switch (SHAPE[agent]) {
|
|
24546
|
+
case "claude":
|
|
24547
|
+
return isObject5(out.hookSpecificOutput) && out.hookSpecificOutput.hookEventName === event;
|
|
24548
|
+
case "gemini":
|
|
24549
|
+
return typeof out.decision === "string" || isObject5(out.hookSpecificOutput);
|
|
24550
|
+
default:
|
|
24551
|
+
return COPILOT_KEYS.some((k) => Object.hasOwn(out, k));
|
|
24552
|
+
}
|
|
24386
24553
|
}
|
|
24387
24554
|
function codexHookJournaled(db) {
|
|
24388
24555
|
if (db === null) return false;
|
|
@@ -24426,9 +24593,10 @@ async function checkHookRoundTrip(i) {
|
|
|
24426
24593
|
const fixed = i.samples === void 0 ? null : Math.max(1, i.samples);
|
|
24427
24594
|
const maxPairs = fixed ?? D5_MAX_PAIRS;
|
|
24428
24595
|
const minPairs = fixed ?? D5_MIN_PAIRS;
|
|
24596
|
+
const timeoutMs = i.timeoutMs ?? HOOK_TIMEOUT_MS;
|
|
24429
24597
|
const bareMs = i.bareMs ?? (async () => {
|
|
24430
24598
|
const t = performance.now();
|
|
24431
|
-
await runProcess([process.execPath, "-e", ""], { cwd: i.bundleDir, env: i.env, signal: i.signal, timeoutMs
|
|
24599
|
+
await runProcess([process.execPath, "-e", ""], { cwd: i.bundleDir, env: i.env, signal: i.signal, timeoutMs });
|
|
24432
24600
|
return performance.now() - t;
|
|
24433
24601
|
});
|
|
24434
24602
|
const hookWalls = [];
|
|
@@ -24440,11 +24608,11 @@ async function checkHookRoundTrip(i) {
|
|
|
24440
24608
|
cwd: i.bundleDir,
|
|
24441
24609
|
env: i.env,
|
|
24442
24610
|
signal: i.signal,
|
|
24443
|
-
timeoutMs
|
|
24444
|
-
stdin: JSON.stringify(payloadFor(fixture.payload, i.worktree))
|
|
24611
|
+
timeoutMs,
|
|
24612
|
+
stdin: JSON.stringify(payloadFor(i.agent, fixture.payload, i.worktree))
|
|
24445
24613
|
});
|
|
24446
24614
|
hookWalls.push(now() - start);
|
|
24447
|
-
if (!isNativeShape(r.stdout.toString("utf8"), r.exitCode, r.killed, fixture.event)) return row("FAIL", D5_SHAPE_DETAIL, D5_FIX);
|
|
24615
|
+
if (!isNativeShape(i.agent, r.stdout.toString("utf8"), r.exitCode, r.killed, fixture.event)) return row("FAIL", D5_SHAPE_DETAIL, D5_FIX);
|
|
24448
24616
|
bareWalls.push(await bareMs());
|
|
24449
24617
|
ms = Math.max(0, Math.round(Math.min(...hookWalls) - Math.min(...bareWalls)));
|
|
24450
24618
|
if (n >= minPairs && ms <= HOOK_P95_MS) break;
|
|
@@ -24454,7 +24622,8 @@ async function checkHookRoundTrip(i) {
|
|
|
24454
24622
|
}
|
|
24455
24623
|
|
|
24456
24624
|
// src/core/ops/db-heal.ts
|
|
24457
|
-
import { existsSync as existsSync11, rmSync as rmSync3 } from "node:fs";
|
|
24625
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync5, rmSync as rmSync3 } from "node:fs";
|
|
24626
|
+
import { basename as basename4, dirname as dirname7, join as join14 } from "node:path";
|
|
24458
24627
|
|
|
24459
24628
|
// src/core/store/owners.ts
|
|
24460
24629
|
import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as readFileSync11, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
@@ -24556,6 +24725,39 @@ async function healD8(input) {
|
|
|
24556
24725
|
closeDb(await openDb(project));
|
|
24557
24726
|
return { ...row5, status: "FAIL", detail: D8_HEALED_RECREATE_DETAIL(ts) };
|
|
24558
24727
|
}
|
|
24728
|
+
function utcStamp(now) {
|
|
24729
|
+
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
24730
|
+
}
|
|
24731
|
+
function makeOrphanDir(projectDir) {
|
|
24732
|
+
const base = join14(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
24733
|
+
for (let n = 1; ; n += 1) {
|
|
24734
|
+
const dir = n === 1 ? base : base + "-" + String(n);
|
|
24735
|
+
try {
|
|
24736
|
+
mkdirSync5(dir);
|
|
24737
|
+
return dir;
|
|
24738
|
+
} catch (err) {
|
|
24739
|
+
if (err.code !== "EEXIST") throw err;
|
|
24740
|
+
}
|
|
24741
|
+
}
|
|
24742
|
+
}
|
|
24743
|
+
async function healOrphan(project, files, row5) {
|
|
24744
|
+
const moved = [];
|
|
24745
|
+
let dir = "";
|
|
24746
|
+
try {
|
|
24747
|
+
dir = makeOrphanDir(dirname7(project.dbPath));
|
|
24748
|
+
for (const f of files) {
|
|
24749
|
+
const to = join14(dir, basename4(f.path));
|
|
24750
|
+
renameWithRetry(f.path, to);
|
|
24751
|
+
moved.push({ path: to, bytes: f.bytes });
|
|
24752
|
+
}
|
|
24753
|
+
closeDb(await openDb(project));
|
|
24754
|
+
} catch (err) {
|
|
24755
|
+
const cause = err instanceof CtxError ? err.toLine() : err instanceof Error ? err.message : String(err);
|
|
24756
|
+
const at2 = moved.length > 0 ? D8_ORPHAN_HEALED_DETAIL(dir, moved, project.dbPath) : row5.detail;
|
|
24757
|
+
return { ...row5, detail: D8_ORPHAN_MOVE_FAILED(at2, cause) };
|
|
24758
|
+
}
|
|
24759
|
+
return { ...row5, status: "FAIL", detail: D8_ORPHAN_HEALED_DETAIL(dir, moved, project.dbPath), fixCommand: D8_ORPHAN_HEALED_FIX };
|
|
24760
|
+
}
|
|
24559
24761
|
|
|
24560
24762
|
// src/core/ops/report.ts
|
|
24561
24763
|
function keyIsTyped(key) {
|
|
@@ -24611,8 +24813,8 @@ function buildReportHead(input) {
|
|
|
24611
24813
|
|
|
24612
24814
|
// src/core/ops/doctor-issue.ts
|
|
24613
24815
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
24614
|
-
import { closeSync, existsSync as existsSync12, fstatSync, mkdirSync as
|
|
24615
|
-
import { delimiter, join as
|
|
24816
|
+
import { closeSync, existsSync as existsSync12, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync12, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
|
|
24817
|
+
import { delimiter, join as join15 } from "node:path";
|
|
24616
24818
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
24617
24819
|
function tildeOf(env) {
|
|
24618
24820
|
const home = homeDirOf(env);
|
|
@@ -24629,9 +24831,9 @@ function tildeOf(env) {
|
|
|
24629
24831
|
}
|
|
24630
24832
|
function maskLine(line) {
|
|
24631
24833
|
const lower = line.toLowerCase();
|
|
24632
|
-
const
|
|
24834
|
+
const named2 = DOCTOR_SECRET_WORDS.some((w) => lower.includes(w));
|
|
24633
24835
|
const token = TOKEN_PREFIXES.some((p) => line.includes(p));
|
|
24634
|
-
if (!
|
|
24836
|
+
if (!named2 && !token) return line;
|
|
24635
24837
|
const at2 = Math.max(line.indexOf(":"), line.indexOf("="));
|
|
24636
24838
|
return at2 === -1 ? DOCTOR_MASK : line.slice(0, at2 + 1) + " " + DOCTOR_MASK;
|
|
24637
24839
|
}
|
|
@@ -24653,8 +24855,8 @@ function onPath(env, tool) {
|
|
|
24653
24855
|
const out = [];
|
|
24654
24856
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
24655
24857
|
if (dir === "") continue;
|
|
24656
|
-
for (const n of names) if (existsSync12(
|
|
24657
|
-
out.push(
|
|
24858
|
+
for (const n of names) if (existsSync12(join15(dir, n))) {
|
|
24859
|
+
out.push(join15(dir, n));
|
|
24658
24860
|
break;
|
|
24659
24861
|
}
|
|
24660
24862
|
}
|
|
@@ -24700,8 +24902,8 @@ function agentConfig(adapter, env, worktree) {
|
|
|
24700
24902
|
const home = homeDirOf(env);
|
|
24701
24903
|
const files = configPaths(adapter, env, worktree);
|
|
24702
24904
|
if (home !== null) {
|
|
24703
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
24704
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
24905
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join15(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
24906
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join15(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
24705
24907
|
}
|
|
24706
24908
|
const out = [];
|
|
24707
24909
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -24784,9 +24986,9 @@ async function buildIssueBody(i) {
|
|
|
24784
24986
|
async function writeIssueReport(i) {
|
|
24785
24987
|
const tilde = tildeOf(i.env);
|
|
24786
24988
|
const body = await buildIssueBody(i);
|
|
24787
|
-
const dir =
|
|
24788
|
-
|
|
24789
|
-
const file2 =
|
|
24989
|
+
const dir = join15(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
24990
|
+
mkdirSync6(dir, { recursive: true });
|
|
24991
|
+
const file2 = join15(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
24790
24992
|
writeFileSync3(file2, body);
|
|
24791
24993
|
const shown2 = tilde(file2);
|
|
24792
24994
|
const title = issueTitle(i.adapter.id, i.rows);
|
|
@@ -24843,11 +25045,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
24843
25045
|
}
|
|
24844
25046
|
}
|
|
24845
25047
|
function ownServerId(configDir, projectKey) {
|
|
24846
|
-
const dir =
|
|
25048
|
+
const dir = join16(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
24847
25049
|
if (!existsSync13(dir)) return "";
|
|
24848
25050
|
for (const name of readdirSync5(dir)) {
|
|
24849
25051
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
24850
|
-
if (readFileSync13(
|
|
25052
|
+
if (readFileSync13(join16(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
24851
25053
|
}
|
|
24852
25054
|
return "";
|
|
24853
25055
|
}
|
|
@@ -24856,6 +25058,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
24856
25058
|
const env = host.env;
|
|
24857
25059
|
const project = ctx.project;
|
|
24858
25060
|
let integrityFailed = false;
|
|
25061
|
+
let orphan = [];
|
|
24859
25062
|
const checks = {
|
|
24860
25063
|
D1: () => checkVersion({ bundleSha: BUNDLE_SHA, version: bundleVersion(host.bundleDir), registryUrl: D1_REGISTRY_URL, timeoutMs: DOCTOR_GIT_TIMEOUT_MS, env: buildChildEnv(env), cwd: project.worktree, signal: ctx.signal }),
|
|
24861
25064
|
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
@@ -24868,6 +25071,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
24868
25071
|
D8: async () => {
|
|
24869
25072
|
const r = await checkDb(project);
|
|
24870
25073
|
integrityFailed = r.integrityFailed;
|
|
25074
|
+
orphan = r.orphan;
|
|
24871
25075
|
return r.row;
|
|
24872
25076
|
},
|
|
24873
25077
|
D9: () => checkIndex(project),
|
|
@@ -24876,8 +25080,13 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
24876
25080
|
};
|
|
24877
25081
|
const rows = [];
|
|
24878
25082
|
for (const id2 of DOCTOR_CHECK_ORDER) rows.push(await guard(id2, checks[id2]));
|
|
24879
|
-
if (!integrityFailed) return rows;
|
|
24880
25083
|
const at2 = DOCTOR_CHECK_ORDER.indexOf("D8");
|
|
25084
|
+
if (orphan.length > 0) {
|
|
25085
|
+
const files = orphan;
|
|
25086
|
+
rows[at2] = await guard("D8", () => healOrphan(project, files, rows[at2]));
|
|
25087
|
+
return rows;
|
|
25088
|
+
}
|
|
25089
|
+
if (!integrityFailed) return rows;
|
|
24881
25090
|
rows[at2] = await guard("D8", () => {
|
|
24882
25091
|
const configDir = resolveConfigDir(env);
|
|
24883
25092
|
return healD8({ project, configDir, serverId: ownServerId(configDir, project.projectKey), row: rows[at2] });
|
|
@@ -24923,7 +25132,7 @@ async function doctorReply(ctx, host) {
|
|
|
24923
25132
|
return { text, isError: false, sandboxBytes: bytes5 };
|
|
24924
25133
|
}
|
|
24925
25134
|
async function handler2(_input, ctx) {
|
|
24926
|
-
return doctorReply(ctx, { env: process.env, bundleDir:
|
|
25135
|
+
return doctorReply(ctx, { env: process.env, bundleDir: dirname8(process.argv[1]), piCwd: void 0 });
|
|
24927
25136
|
}
|
|
24928
25137
|
var ctxDoctor = Object.freeze({
|
|
24929
25138
|
name: "ctx_doctor",
|
|
@@ -24937,7 +25146,7 @@ var ctxDoctor = Object.freeze({
|
|
|
24937
25146
|
// src/core/tools/execute.ts
|
|
24938
25147
|
import { existsSync as existsSync14, mkdtempSync, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
24939
25148
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24940
|
-
import { dirname as
|
|
25149
|
+
import { dirname as dirname9, join as join17, parse as parse3, resolve as resolve6 } from "node:path";
|
|
24941
25150
|
|
|
24942
25151
|
// src/core/sandbox/win-build.ts
|
|
24943
25152
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -25021,7 +25230,7 @@ function schemaLine(issue2) {
|
|
|
25021
25230
|
}
|
|
25022
25231
|
function fileError(given, abs, root) {
|
|
25023
25232
|
let dir = abs;
|
|
25024
|
-
while (!existsSync14(dir) &&
|
|
25233
|
+
while (!existsSync14(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
|
|
25025
25234
|
if (isInside(root, dir)) return null;
|
|
25026
25235
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
25027
25236
|
}
|
|
@@ -25102,8 +25311,8 @@ async function handler3(raw, ctx) {
|
|
|
25102
25311
|
if (takesDashC(input.language, runtime)) {
|
|
25103
25312
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
25104
25313
|
} else {
|
|
25105
|
-
tmpDir = mkdtempSync(
|
|
25106
|
-
const file2 =
|
|
25314
|
+
tmpDir = mkdtempSync(join17(tmpdir2(), TMP_PREFIX));
|
|
25315
|
+
const file2 = join17(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
25107
25316
|
writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
|
|
25108
25317
|
argv = scriptArgv(input.language, runtime, file2);
|
|
25109
25318
|
}
|
|
@@ -25138,12 +25347,12 @@ var ctxExecute = {
|
|
|
25138
25347
|
};
|
|
25139
25348
|
|
|
25140
25349
|
// src/core/tools/index.ts
|
|
25141
|
-
import { existsSync as existsSync15, readFileSync as readFileSync15, statSync as
|
|
25142
|
-
import { dirname as
|
|
25350
|
+
import { existsSync as existsSync15, readFileSync as readFileSync15, statSync as statSync8 } from "node:fs";
|
|
25351
|
+
import { dirname as dirname10, extname, join as join19, relative as relative3, resolve as resolve7 } from "node:path";
|
|
25143
25352
|
|
|
25144
25353
|
// src/core/index/walk.ts
|
|
25145
|
-
import { readdirSync as readdirSync6, readFileSync as readFileSync14, realpathSync as realpathSync9, statSync as
|
|
25146
|
-
import { join as
|
|
25354
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync14, realpathSync as realpathSync9, statSync as statSync7 } from "node:fs";
|
|
25355
|
+
import { join as join18 } from "node:path";
|
|
25147
25356
|
var GITIGNORE = ".gitignore";
|
|
25148
25357
|
var GIT_DIR = ".git";
|
|
25149
25358
|
function walkDir(root, containmentRoot) {
|
|
@@ -25152,7 +25361,7 @@ function walkDir(root, containmentRoot) {
|
|
|
25152
25361
|
const found = [];
|
|
25153
25362
|
visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
|
|
25154
25363
|
found.sort(compareFound);
|
|
25155
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
25364
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join18(...f.dir, f.name) }));
|
|
25156
25365
|
}
|
|
25157
25366
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
25158
25367
|
let entries;
|
|
@@ -25161,10 +25370,10 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
25161
25370
|
} catch {
|
|
25162
25371
|
return;
|
|
25163
25372
|
}
|
|
25164
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
25373
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join18(abs, GITIGNORE), rel)) : parent;
|
|
25165
25374
|
for (const e of entries) {
|
|
25166
25375
|
if (e.name === GIT_DIR) continue;
|
|
25167
|
-
const path7 =
|
|
25376
|
+
const path7 = join18(abs, e.name);
|
|
25168
25377
|
let isDir = e.isDirectory();
|
|
25169
25378
|
let isFile = e.isFile();
|
|
25170
25379
|
let target = path7;
|
|
@@ -25176,7 +25385,7 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
25176
25385
|
continue;
|
|
25177
25386
|
}
|
|
25178
25387
|
if (!isInside(contain, resolved)) continue;
|
|
25179
|
-
const st =
|
|
25388
|
+
const st = statSync7(resolved);
|
|
25180
25389
|
isDir = st.isDirectory();
|
|
25181
25390
|
isFile = st.isFile();
|
|
25182
25391
|
target = resolved;
|
|
@@ -29294,7 +29503,7 @@ function readUtf8(absPath) {
|
|
|
29294
29503
|
}
|
|
29295
29504
|
function missingOrOutside(given, abs, root) {
|
|
29296
29505
|
let dir = abs;
|
|
29297
|
-
while (!existsSync15(dir) &&
|
|
29506
|
+
while (!existsSync15(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
|
|
29298
29507
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
29299
29508
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
29300
29509
|
}
|
|
@@ -29302,10 +29511,10 @@ function pathItems(input, project) {
|
|
|
29302
29511
|
const abs = resolve7(project.worktree, input.path);
|
|
29303
29512
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
29304
29513
|
const base = relative3(project.worktree, abs);
|
|
29305
|
-
if (
|
|
29514
|
+
if (statSync8(abs).isDirectory()) {
|
|
29306
29515
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
29307
29516
|
sourceKind: "path",
|
|
29308
|
-
label: pathLabel(
|
|
29517
|
+
label: pathLabel(join19(base, f.relPath)),
|
|
29309
29518
|
kind: kindOfPath(f.relPath),
|
|
29310
29519
|
read: () => readUtf8(f.absPath)
|
|
29311
29520
|
}));
|
|
@@ -29377,8 +29586,9 @@ async function handler4(input, ctx) {
|
|
|
29377
29586
|
} finally {
|
|
29378
29587
|
closeDb(db);
|
|
29379
29588
|
}
|
|
29380
|
-
const
|
|
29381
|
-
const
|
|
29589
|
+
const head = "Indexed " + sources + " source(s), " + chunks + " chunk(s) from ";
|
|
29590
|
+
const first = sources === 1 && lastId > 0 ? head + sourceHandle(lastId) + ". " + indexedLabelLine(from, lastId) : head + shownLabel(from, null) + ".";
|
|
29591
|
+
const line = [first, ...notes].join("\n");
|
|
29382
29592
|
return {
|
|
29383
29593
|
text: capBytes(line, OUTPUT_CAP).text,
|
|
29384
29594
|
isError: false,
|
|
@@ -29422,7 +29632,7 @@ function purgeScope(db, scope, input) {
|
|
|
29422
29632
|
const raw = db.raw;
|
|
29423
29633
|
if (scope === "session") return changes(raw, "DELETE FROM events WHERE session_id = ?", input.session);
|
|
29424
29634
|
if (scope === "source") {
|
|
29425
|
-
const label2 =
|
|
29635
|
+
const label2 = pickSource(db, input.source, false).label;
|
|
29426
29636
|
return deleteChunkRows(raw, { label: label2 }) + changes(raw, "DELETE FROM sources WHERE label = ?", label2);
|
|
29427
29637
|
}
|
|
29428
29638
|
const chunks = deleteChunkRows(raw, "all");
|
|
@@ -29621,6 +29831,9 @@ function bytes4(n) {
|
|
|
29621
29831
|
}
|
|
29622
29832
|
return v.toFixed(1) + " " + UNITS[u];
|
|
29623
29833
|
}
|
|
29834
|
+
function right(v, width) {
|
|
29835
|
+
return " " + v.padStart(width - 1);
|
|
29836
|
+
}
|
|
29624
29837
|
function pct(t) {
|
|
29625
29838
|
return (t.saved * PERCENT_SCALE / Math.max(1, t.produced)).toFixed(1) + "%";
|
|
29626
29839
|
}
|
|
@@ -29644,8 +29857,8 @@ function plural(n, word) {
|
|
|
29644
29857
|
}
|
|
29645
29858
|
function table2(title, rows) {
|
|
29646
29859
|
const max = Math.max(0, ...rows.map((r) => r.saved));
|
|
29647
|
-
const head = " " + title.padEnd(LABEL_W) + "Calls"
|
|
29648
|
-
return [head, ...rows.map((r) => (" " + label(r.name) + count(r.calls)
|
|
29860
|
+
const head = " " + title.padEnd(LABEL_W) + right("Calls", STATS_CALLS_W) + right("Made", NUM_W) + right("Sent", NUM_W) + right("Kept out", NUM_W) + right("%", PCT_W);
|
|
29861
|
+
return [head, ...rows.map((r) => (" " + label(r.name) + right(count(r.calls), STATS_CALLS_W) + right(bytes4(r.produced), NUM_W) + right(bytes4(r.returned), NUM_W) + right(bytes4(r.saved), NUM_W) + right(pct(r), PCT_W) + " " + bar(r.saved, max, STATS_ROW_BAR)).trimEnd())];
|
|
29649
29862
|
}
|
|
29650
29863
|
function bySaved(a, b) {
|
|
29651
29864
|
return b.saved - a.saved || b.produced - a.produced || a.returned - b.returned || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
@@ -29657,14 +29870,14 @@ function joinIndex(tools) {
|
|
|
29657
29870
|
const idx = tools.filter((t2) => STATS_INDEX_TOOLS.includes(t2.name));
|
|
29658
29871
|
if (idx.length <= 1) return tools;
|
|
29659
29872
|
const t = sum(idx);
|
|
29660
|
-
const one = { name: STATS_INDEX_TOOLS.join(" + ").replace(" + ctx_", " + "), ...t, saved: t.produced - t.returned };
|
|
29873
|
+
const one = { name: STATS_INDEX_TOOLS.join(" + ").replace(" + ctx_", " + "), ...t, saved: Math.max(0, t.produced - t.returned) };
|
|
29661
29874
|
return [...tools.filter((x) => !idx.includes(x)), one];
|
|
29662
29875
|
}
|
|
29663
29876
|
function toolRows(tools) {
|
|
29664
|
-
const
|
|
29665
|
-
const zero =
|
|
29877
|
+
const named2 = joinIndex(tools.map((t) => ({ ...t, saved: Math.max(0, t.produced - t.returned) }))).map((t) => ({ ...t, name: toolName(t.name) })).sort(bySaved);
|
|
29878
|
+
const zero = named2.filter((t) => t.saved <= 0);
|
|
29666
29879
|
const fold2 = zero.length > 1 ? zero : [];
|
|
29667
|
-
const keep =
|
|
29880
|
+
const keep = named2.filter((t) => !fold2.includes(t));
|
|
29668
29881
|
const room = fold2.length > 0 ? STATS_MAX_TOOL_ROWS - 1 : STATS_MAX_TOOL_ROWS;
|
|
29669
29882
|
const over = keep.length > room;
|
|
29670
29883
|
const shown2 = over ? keep.slice(0, STATS_MAX_TOOL_ROWS - 1) : keep;
|
|
@@ -29732,7 +29945,7 @@ function lastDays(week, allCalls) {
|
|
|
29732
29945
|
return [
|
|
29733
29946
|
head,
|
|
29734
29947
|
...card,
|
|
29735
|
-
...week.flatMap((d, i) => saved[i] > 0 ? [" " + mmdd(d.day) + " " + stack(STATS_WAYS.map(([w]) => d.ways[w]), max, STATS_DAY_BAR).padEnd(STATS_DAY_BAR) + bytes4(saved[i])
|
|
29948
|
+
...week.flatMap((d, i) => saved[i] > 0 ? [" " + mmdd(d.day) + " " + stack(STATS_WAYS.map(([w]) => d.ways[w]), max, STATS_DAY_BAR).padEnd(STATS_DAY_BAR) + right(bytes4(saved[i]), NUM_W)] : []),
|
|
29736
29949
|
" " + STATS_WAYS.map(([, ch, name]) => `${ch} ${name}`).join(" "),
|
|
29737
29950
|
""
|
|
29738
29951
|
];
|
|
@@ -29760,8 +29973,8 @@ function report(f, sessionId, agent) {
|
|
|
29760
29973
|
...head,
|
|
29761
29974
|
`${scopeName} \xB7 ${plural(focus.calls, "call")}${extra}`,
|
|
29762
29975
|
` ${bytes4(focus.produced)} became ${bytes4(focus.returned)}: ${bytes4(focus.saved)} kept out (${pct(focus)})`,
|
|
29763
|
-
" " + "Without context-mode".padEnd(LABEL_W) + "|" + bar(focus.produced, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.produced)
|
|
29764
|
-
" " + "With context-mode".padEnd(LABEL_W) + "|" + bar(focus.returned, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.returned)
|
|
29976
|
+
" " + "Without context-mode".padEnd(LABEL_W) + "|" + bar(focus.produced, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + right(bytes4(focus.produced), NUM_W),
|
|
29977
|
+
" " + "With context-mode".padEnd(LABEL_W) + "|" + bar(focus.returned, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + right(bytes4(focus.returned), NUM_W),
|
|
29765
29978
|
...focus.saved > 0 ? [windowLine(focus.saved), STATS_TOKEN_NOTE] : [],
|
|
29766
29979
|
...hookLine(f.redirected, f.replaced),
|
|
29767
29980
|
"",
|
|
@@ -29775,7 +29988,7 @@ function report(f, sessionId, agent) {
|
|
|
29775
29988
|
"",
|
|
29776
29989
|
...f.top.length > 0 ? [
|
|
29777
29990
|
"Largest single outputs (made \u2192 sent to the chat)",
|
|
29778
|
-
...f.top.map((t) => " " + label(toolName(t.name)) + bytes4(t.produced)
|
|
29991
|
+
...f.top.map((t) => " " + label(toolName(t.name)) + right(bytes4(t.produced), NUM_W) + " \u2192 " + right(bytes4(t.returned), NUM_W)),
|
|
29779
29992
|
""
|
|
29780
29993
|
] : []
|
|
29781
29994
|
];
|
|
@@ -29784,10 +29997,10 @@ function report(f, sessionId, agent) {
|
|
|
29784
29997
|
if (!agents.has(agent)) agents.set(agent, EMPTY5);
|
|
29785
29998
|
lines.push("By agent (this project)", ...table2("Agent", [...agents].map(([name, t]) => ({ name, ...t })).sort(bySaved)), "");
|
|
29786
29999
|
const maxKind = Math.max(0, ...[...f.kinds.values()].map((k) => k.project));
|
|
29787
|
-
lines.push("Kept in the session journal", " " + "Journal".padEnd(LABEL_W) + "Session"
|
|
30000
|
+
lines.push("Kept in the session journal", " " + "Journal".padEnd(LABEL_W) + right("Session", STATS_KIND_W) + right("Project", STATS_KIND_W));
|
|
29788
30001
|
for (const [kind, name] of STATS_KIND_LABELS) {
|
|
29789
30002
|
const k = f.kinds.get(kind) ?? { session: 0, project: 0 };
|
|
29790
|
-
lines.push((" " + label(name) + int2(k.session)
|
|
30003
|
+
lines.push((" " + label(name) + right(int2(k.session), STATS_KIND_W) + right(int2(k.project), STATS_KIND_W) + " " + bar(k.project, maxKind, STATS_KIND_BAR)).trimEnd());
|
|
29791
30004
|
}
|
|
29792
30005
|
lines.push("", ...STATS_JOURNAL_HINTS.map((h) => " " + h), "");
|
|
29793
30006
|
lines.push(
|
|
@@ -29804,7 +30017,14 @@ async function handler7(_input, ctx) {
|
|
|
29804
30017
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
29805
30018
|
let facts;
|
|
29806
30019
|
try {
|
|
29807
|
-
|
|
30020
|
+
db.raw.exec("BEGIN DEFERRED");
|
|
30021
|
+
try {
|
|
30022
|
+
facts = readFacts(db.raw, ctx.sessionId);
|
|
30023
|
+
db.raw.exec("COMMIT");
|
|
30024
|
+
} catch (err) {
|
|
30025
|
+
if (db.raw.isTransaction) db.raw.exec("ROLLBACK");
|
|
30026
|
+
throw err;
|
|
30027
|
+
}
|
|
29808
30028
|
} finally {
|
|
29809
30029
|
closeDb(db);
|
|
29810
30030
|
}
|
|
@@ -29835,11 +30055,11 @@ var ctxStats = Object.freeze({
|
|
|
29835
30055
|
|
|
29836
30056
|
// src/core/tools/upgrade.ts
|
|
29837
30057
|
import { existsSync as existsSync21, realpathSync as realpathSync10, rmSync as rmSync9 } from "node:fs";
|
|
29838
|
-
import { basename as
|
|
30058
|
+
import { basename as basename7, dirname as dirname12, join as join25 } from "node:path";
|
|
29839
30059
|
|
|
29840
30060
|
// src/core/ops/host-write.ts
|
|
29841
|
-
import { copyFileSync, existsSync as existsSync16, mkdirSync as
|
|
29842
|
-
import { dirname as
|
|
30061
|
+
import { copyFileSync, existsSync as existsSync16, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
30062
|
+
import { dirname as dirname11, join as join20 } from "node:path";
|
|
29843
30063
|
function defaultWrite(file2, text) {
|
|
29844
30064
|
writeFileSync5(file2, text, "utf8");
|
|
29845
30065
|
}
|
|
@@ -29848,14 +30068,14 @@ function hostConfigPath(agent, home, env) {
|
|
|
29848
30068
|
if (own2 !== void 0) return ownMcpFileOf(agent, own2.file, env, home);
|
|
29849
30069
|
switch (agent) {
|
|
29850
30070
|
case "opencode":
|
|
29851
|
-
return
|
|
30071
|
+
return join20(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
29852
30072
|
// D-WIN-OPENCODE-DIR-1
|
|
29853
30073
|
case "pi":
|
|
29854
|
-
return
|
|
30074
|
+
return join20(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
29855
30075
|
case "copilot-cli":
|
|
29856
30076
|
return null;
|
|
29857
30077
|
default:
|
|
29858
|
-
return
|
|
30078
|
+
return join20(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
29859
30079
|
}
|
|
29860
30080
|
}
|
|
29861
30081
|
function cell3(value) {
|
|
@@ -29868,7 +30088,7 @@ function writeWithRollback(file2, text, write2, atomic) {
|
|
|
29868
30088
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
29869
30089
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
29870
30090
|
const had = existsSync16(file2);
|
|
29871
|
-
|
|
30091
|
+
mkdirSync7(dirname11(file2), { recursive: true });
|
|
29872
30092
|
if (had) copyFileSync(file2, trash);
|
|
29873
30093
|
try {
|
|
29874
30094
|
write2(tmp, text);
|
|
@@ -29906,7 +30126,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
29906
30126
|
|
|
29907
30127
|
// src/core/ops/plugin-swap.ts
|
|
29908
30128
|
import { existsSync as existsSync17, lstatSync, readdirSync as readdirSync7, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
29909
|
-
import { basename as
|
|
30129
|
+
import { basename as basename6, join as join21, win32 as win322 } from "node:path";
|
|
29910
30130
|
function linkTarget(path7, win) {
|
|
29911
30131
|
if (!isLink(path7)) return null;
|
|
29912
30132
|
const target = readlinkSync(path7);
|
|
@@ -29925,11 +30145,11 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
29925
30145
|
else renameWithRetry(old, link, opts);
|
|
29926
30146
|
}
|
|
29927
30147
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
29928
|
-
const next =
|
|
30148
|
+
const next = join21(agentDir, sha);
|
|
29929
30149
|
if (!existsSync17(next) || !lstatSync(next).isDirectory()) {
|
|
29930
|
-
throw new CtxError("PLUGIN_ROOT_MISSING", { agent:
|
|
30150
|
+
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
|
|
29931
30151
|
}
|
|
29932
|
-
const link =
|
|
30152
|
+
const link = join21(agentDir, PLUGIN_CURRENT_LINK);
|
|
29933
30153
|
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
29934
30154
|
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
29935
30155
|
settleLinks(link, tmp, old, opts);
|
|
@@ -29944,15 +30164,15 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
29944
30164
|
if (before !== null) unlinkSync2(old);
|
|
29945
30165
|
const keep = /* @__PURE__ */ new Set([sha]);
|
|
29946
30166
|
if (before !== null) keep.add(before);
|
|
29947
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) =>
|
|
30167
|
+
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join21(agentDir, name));
|
|
29948
30168
|
for (const dir of removed) rmSync5(dir, { recursive: true, force: true });
|
|
29949
|
-
const previous = before !== null && existsSync17(
|
|
30169
|
+
const previous = before !== null && existsSync17(join21(agentDir, before)) ? join21(agentDir, before) : null;
|
|
29950
30170
|
return { current: next, previous, removed };
|
|
29951
30171
|
}
|
|
29952
30172
|
|
|
29953
30173
|
// src/core/ops/release-fetch.ts
|
|
29954
|
-
import { existsSync as existsSync18, mkdirSync as
|
|
29955
|
-
import { join as
|
|
30174
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync8, rmSync as rmSync6 } from "node:fs";
|
|
30175
|
+
import { join as join22 } from "node:path";
|
|
29956
30176
|
function failed(r) {
|
|
29957
30177
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
29958
30178
|
const status = r.killed ?? String(r.exitCode);
|
|
@@ -29964,9 +30184,9 @@ async function git2(bin, args, cwd, env, signal) {
|
|
|
29964
30184
|
return r.stdout.toString().trim();
|
|
29965
30185
|
}
|
|
29966
30186
|
async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
29967
|
-
const agentDir =
|
|
29968
|
-
|
|
29969
|
-
const fetchDir =
|
|
30187
|
+
const agentDir = join22(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
30188
|
+
mkdirSync8(agentDir, { recursive: true });
|
|
30189
|
+
const fetchDir = join22(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
29970
30190
|
rmSync6(fetchDir, { recursive: true, force: true });
|
|
29971
30191
|
const gitBin = findRuntime(GIT_BIN, env);
|
|
29972
30192
|
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -29974,7 +30194,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
29974
30194
|
try {
|
|
29975
30195
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url2, fetchDir], agentDir, childEnv, signal);
|
|
29976
30196
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
29977
|
-
const dir =
|
|
30197
|
+
const dir = join22(agentDir, sha);
|
|
29978
30198
|
if (existsSync18(dir)) rmSync6(fetchDir, { recursive: true, force: true });
|
|
29979
30199
|
else renameWithRetry(fetchDir, dir, opts);
|
|
29980
30200
|
return { sha, dir };
|
|
@@ -29986,14 +30206,14 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
29986
30206
|
|
|
29987
30207
|
// src/core/ops/uninstall.ts
|
|
29988
30208
|
import { existsSync as existsSync19, readdirSync as readdirSync8, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "node:fs";
|
|
29989
|
-
import { join as
|
|
30209
|
+
import { join as join23 } from "node:path";
|
|
29990
30210
|
function row2(area, before, after) {
|
|
29991
30211
|
return { area, before, after };
|
|
29992
30212
|
}
|
|
29993
30213
|
function stopServers(configDir, projectKey) {
|
|
29994
30214
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
29995
|
-
const dir =
|
|
29996
|
-
for (const serverId of stopped) writeFileSync6(
|
|
30215
|
+
const dir = join23(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
30216
|
+
for (const serverId of stopped) writeFileSync6(join23(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
29997
30217
|
return stopped.length === 0 ? { row: row2(UPGRADE_SERVER_AREA, "", UPGRADE_NOT_FOUND), stopped } : { row: row2(UPGRADE_SERVER_AREA, UPGRADE_SERVER_RUNNING, UPGRADE_SERVER_STOPPED), stopped };
|
|
29998
30218
|
}
|
|
29999
30219
|
function rootOrNull(adapter, env) {
|
|
@@ -30011,14 +30231,14 @@ function removeCache(adapter, env, configDir) {
|
|
|
30011
30231
|
const root = rootOrNull(adapter, env);
|
|
30012
30232
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
30013
30233
|
if (adapter.installMode === "marketplace") {
|
|
30014
|
-
const cache =
|
|
30234
|
+
const cache = join23(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
30015
30235
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
30016
30236
|
}
|
|
30017
30237
|
rmSync7(root, { recursive: true, force: true });
|
|
30018
30238
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
30019
30239
|
}
|
|
30020
30240
|
case "plugin": {
|
|
30021
|
-
const agentDir =
|
|
30241
|
+
const agentDir = join23(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
30022
30242
|
if (!existsSync19(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
30023
30243
|
rmSync7(agentDir, { recursive: true, force: true });
|
|
30024
30244
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
@@ -30064,7 +30284,7 @@ function ownEntries(agent, env) {
|
|
|
30064
30284
|
}
|
|
30065
30285
|
if (agent === "opencode") {
|
|
30066
30286
|
return [{
|
|
30067
|
-
file:
|
|
30287
|
+
file: join23(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
30068
30288
|
// D-WIN-OPENCODE-DIR-1
|
|
30069
30289
|
key: OPENCODE_PLUGIN_KEY,
|
|
30070
30290
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -30075,7 +30295,7 @@ function ownEntries(agent, env) {
|
|
|
30075
30295
|
if (agent === "pi") {
|
|
30076
30296
|
const agentDir = piAgentDirOf(env, home);
|
|
30077
30297
|
return [{
|
|
30078
|
-
file:
|
|
30298
|
+
file: join23(agentDir, SETTINGS_FILE),
|
|
30079
30299
|
key: PI_PACKAGES_KEY,
|
|
30080
30300
|
shown: PI_PACKAGES_KEY,
|
|
30081
30301
|
has: (v) => Array.isArray(v) && v.some((x) => piSource(x) === PI_GIT_PACKAGE),
|
|
@@ -30097,12 +30317,12 @@ function removeOwnEntries(agent, env) {
|
|
|
30097
30317
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
30098
30318
|
}
|
|
30099
30319
|
function removeProjectData(configDir, projectKey) {
|
|
30100
|
-
const projects =
|
|
30101
|
-
const dir =
|
|
30320
|
+
const projects = join23(configDir, PROJECTS_DIR_NAME);
|
|
30321
|
+
const dir = join23(projects, projectKey);
|
|
30102
30322
|
if (!existsSync19(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
30103
30323
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
30104
30324
|
for (const name of readdirSync8(dir)) {
|
|
30105
|
-
if (name !== OWNERS_DIR_NAME) rmSync7(
|
|
30325
|
+
if (name !== OWNERS_DIR_NAME) rmSync7(join23(dir, name), { recursive: true, force: true });
|
|
30106
30326
|
}
|
|
30107
30327
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
30108
30328
|
}
|
|
@@ -30110,7 +30330,7 @@ function runUninstall(input) {
|
|
|
30110
30330
|
const configDir = resolveConfigDir(input.env);
|
|
30111
30331
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
30112
30332
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
30113
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
30333
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join23(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
30114
30334
|
return { rows, stopped: stop.stopped };
|
|
30115
30335
|
}
|
|
30116
30336
|
|
|
@@ -30247,7 +30467,7 @@ function removeV1(agent, findings) {
|
|
|
30247
30467
|
// src/core/ops/verify-sums.ts
|
|
30248
30468
|
import { createHash as createHash2 } from "node:crypto";
|
|
30249
30469
|
import { lstatSync as lstatSync2, readdirSync as readdirSync9, readFileSync as readFileSync17 } from "node:fs";
|
|
30250
|
-
import { join as
|
|
30470
|
+
import { join as join24 } from "node:path";
|
|
30251
30471
|
function mismatch() {
|
|
30252
30472
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
30253
30473
|
}
|
|
@@ -30268,14 +30488,14 @@ function walk3(dir, prefix, out) {
|
|
|
30268
30488
|
for (const entry of readdirSync9(dir, { withFileTypes: true })) {
|
|
30269
30489
|
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
30270
30490
|
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
30271
|
-
const abs =
|
|
30491
|
+
const abs = join24(dir, entry.name);
|
|
30272
30492
|
if (entry.isDirectory()) walk3(abs, rel, out);
|
|
30273
30493
|
else if (entry.isFile()) out.set(rel, abs);
|
|
30274
30494
|
else throw mismatch();
|
|
30275
30495
|
}
|
|
30276
30496
|
}
|
|
30277
30497
|
function verifySums(dir) {
|
|
30278
|
-
const sumsPath =
|
|
30498
|
+
const sumsPath = join24(dir, RELEASE_SUMS_FILE);
|
|
30279
30499
|
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
30280
30500
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
30281
30501
|
const sums = parseSums(readFileSync17(sumsPath, "utf8"));
|
|
@@ -30299,7 +30519,7 @@ function row4(area, before, after) {
|
|
|
30299
30519
|
return { area, before, after };
|
|
30300
30520
|
}
|
|
30301
30521
|
function bundleDir() {
|
|
30302
|
-
return
|
|
30522
|
+
return dirname12(process.argv[1] ?? "");
|
|
30303
30523
|
}
|
|
30304
30524
|
function pluginRootRow(adapter, env) {
|
|
30305
30525
|
const own2 = bundleDir();
|
|
@@ -30313,12 +30533,12 @@ function pluginRootRow(adapter, env) {
|
|
|
30313
30533
|
return root === own2 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own2)];
|
|
30314
30534
|
}
|
|
30315
30535
|
function isCurrent(agentDir, dir) {
|
|
30316
|
-
const link =
|
|
30536
|
+
const link = join25(agentDir, PLUGIN_CURRENT_LINK);
|
|
30317
30537
|
return existsSync21(link) && realpathSync10.native(link) === realpathSync10.native(dir);
|
|
30318
30538
|
}
|
|
30319
30539
|
async function checkout(adapter, deps) {
|
|
30320
30540
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
30321
|
-
const agentDir =
|
|
30541
|
+
const agentDir = dirname12(fetched.dir);
|
|
30322
30542
|
try {
|
|
30323
30543
|
verifySums(fetched.dir);
|
|
30324
30544
|
} catch (err) {
|
|
@@ -30346,7 +30566,7 @@ async function upgrade(adapter, deps, home) {
|
|
|
30346
30566
|
return rows;
|
|
30347
30567
|
} catch (err) {
|
|
30348
30568
|
removal?.rollback();
|
|
30349
|
-
if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir,
|
|
30569
|
+
if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename7(done.swap.previous));
|
|
30350
30570
|
throw err;
|
|
30351
30571
|
}
|
|
30352
30572
|
}
|