context-mode 2.0.0-next.28 → 2.0.0-next.30
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 +86 -83
- package/SHA256SUMS +19 -19
- package/claude-code/skills/ctx-stats/SKILL.md +2 -2
- package/cli.mjs +20 -0
- package/codex/skills/ctx-stats/SKILL.md +2 -2
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +71 -71
- package/opencode/plugin.js +501 -234
- package/package.json +1 -1
- package/pi/index.js +580 -314
- package/pi/skills/ctx-stats/SKILL.md +2 -2
- package/qwen-extension.json +1 -1
- package/run.mjs +21 -1
- package/search.mjs +21 -1
- package/server.mjs +529 -263
- package/skills/ctx-stats/SKILL.md +2 -2
package/opencode/plugin.js
CHANGED
|
@@ -27,9 +27,9 @@ var REPLACE_TRIGGER_BYTES = 4096;
|
|
|
27
27
|
var REPLACE_RETURN_BYTES = 96;
|
|
28
28
|
var SHAPE_RETURN_BYTES = 256;
|
|
29
29
|
var REPLACE_CHUNK_BYTES = 48;
|
|
30
|
-
function REPLACE_HANDLE_LINE(intent, handle,
|
|
30
|
+
function REPLACE_HANDLE_LINE(intent, handle, bytes5, prefix = "", asked = "") {
|
|
31
31
|
const queries = asked === "" ? [intent] : [intent, asked];
|
|
32
|
-
return prefix + "ctx_search({queries:[" + queries.map((q) => JSON.stringify(q)).join(",") + "], source:" + JSON.stringify(handle) + "}) searches the whole output (" +
|
|
32
|
+
return prefix + "ctx_search({queries:[" + queries.map((q) => JSON.stringify(q)).join(",") + "], source:" + JSON.stringify(handle) + "}) searches the whole output (" + bytes5 + " B).";
|
|
33
33
|
}
|
|
34
34
|
var HANDLE_PROMPT_WORDS = 3;
|
|
35
35
|
var MAX_CHUNK_BYTES = 4096;
|
|
@@ -188,6 +188,7 @@ var SQLITE_NOTADB_CODE = 26;
|
|
|
188
188
|
var HOOK_P95_MS = 40;
|
|
189
189
|
var HOOK_TIMEOUT_MS = 5e3;
|
|
190
190
|
var IN_PROCESS_TIMEOUT_MS = 0;
|
|
191
|
+
var MS_PER_DAY = 864e5;
|
|
191
192
|
var PROJECT_KEY_HEX_LEN = 16;
|
|
192
193
|
var SCHEMA_VERSION = 6;
|
|
193
194
|
var RETENTION_SIZE_CAP_BYTES = 524288e3;
|
|
@@ -273,8 +274,8 @@ var HOOK_FAIL_TOOLS = Object.freeze({
|
|
|
273
274
|
grep: Object.freeze(["Grep", "grep_search"]),
|
|
274
275
|
fetch: Object.freeze(["WebFetch", "web_fetch", "fetch"])
|
|
275
276
|
});
|
|
276
|
-
function HOOK_FAIL_LINE(
|
|
277
|
-
return `${DENY_PREFIX}the hook failed (${
|
|
277
|
+
function HOOK_FAIL_LINE(label2, prefix) {
|
|
278
|
+
return `${DENY_PREFIX}the hook failed (${label2}). Fix: run ${prefix}ctx_doctor.`;
|
|
278
279
|
}
|
|
279
280
|
var HOOK_FAIL_REDIRECT = Object.freeze({
|
|
280
281
|
read: "Read the file in parts with offset and limit, or process it with ctx_execute(language, code); only what you print comes back.",
|
|
@@ -282,11 +283,11 @@ var HOOK_FAIL_REDIRECT = Object.freeze({
|
|
|
282
283
|
grep: "Search with ctx_execute(language, code), or index the files with ctx_index and query them with ctx_search.",
|
|
283
284
|
fetch: "Index the URL with ctx_index and query it with ctx_search."
|
|
284
285
|
});
|
|
285
|
-
function D5_LAST_HOOK_ERROR(ts, stage,
|
|
286
|
-
return `; last hook error ${ts} at ${stage} (${
|
|
286
|
+
function D5_LAST_HOOK_ERROR(ts, stage, label2) {
|
|
287
|
+
return `; last hook error ${ts} at ${stage} (${label2}), stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
287
288
|
}
|
|
288
|
-
function D5_PAST_HOOK_ERROR(ts, stage,
|
|
289
|
-
return `; past hook error ${ts} at ${stage} (${
|
|
289
|
+
function D5_PAST_HOOK_ERROR(ts, stage, label2) {
|
|
290
|
+
return `; past hook error ${ts} at ${stage} (${label2}), before this run, stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
290
291
|
}
|
|
291
292
|
var BOUNDED_COMMANDS = Object.freeze(["pwd", "whoami", "uname", "id", "realpath", "ln"]);
|
|
292
293
|
var BOUNDED_GIT_SUBCOMMANDS = Object.freeze(["status"]);
|
|
@@ -355,6 +356,42 @@ function STATS_SUMMARY(allTimePct, sessionPct) {
|
|
|
355
356
|
}
|
|
356
357
|
var STATS_COLUMNS = Object.freeze(["Scope", "Produced", "Returned", "Saved", "Reduction %"]);
|
|
357
358
|
var STATS_NO_DATA = "no data \u2014 no tool calls recorded yet";
|
|
359
|
+
var STATS_WIDTH = 80;
|
|
360
|
+
var STATS_BYTES_PER_TOKEN = 4;
|
|
361
|
+
var STATS_MAX_TOOL_ROWS = 12;
|
|
362
|
+
var STATS_LABEL_W = 21;
|
|
363
|
+
var STATS_LABEL_MAX = 20;
|
|
364
|
+
var STATS_CALLS_W = 7;
|
|
365
|
+
var STATS_NUM_W = 11;
|
|
366
|
+
var STATS_PCT_W = 8;
|
|
367
|
+
var STATS_KIND_W = 9;
|
|
368
|
+
var STATS_HEAD_BAR = 40;
|
|
369
|
+
var STATS_ROW_BAR = 8;
|
|
370
|
+
var STATS_KIND_BAR = 20;
|
|
371
|
+
var STATS_KIB = 1024;
|
|
372
|
+
var STATS_MILLION = 1e6;
|
|
373
|
+
var STATS_MS_PER_MINUTE = 6e4;
|
|
374
|
+
var STATS_MINUTES_PER_HOUR = 60;
|
|
375
|
+
var STATS_HOURS_PER_DAY = 24;
|
|
376
|
+
var STATS_CLOCK_DIGITS = 2;
|
|
377
|
+
var STATS_REPORT_TITLE = "context-mode stats";
|
|
378
|
+
var STATS_EMPTY_LINES = Object.freeze([
|
|
379
|
+
"Ready. Your savings show up here after the first tool call.",
|
|
380
|
+
"Large outputs from ctx_execute, ctx_batch and ctx_index stay in the",
|
|
381
|
+
"sandbox, and only the short answer goes to the chat."
|
|
382
|
+
]);
|
|
383
|
+
var STATS_KIND_LABELS = Object.freeze([
|
|
384
|
+
["cmd", "Tool runs"],
|
|
385
|
+
["index", "Content indexed"],
|
|
386
|
+
["edit", "File edits"],
|
|
387
|
+
["toolerr", "Errors kept"],
|
|
388
|
+
["decision", "Your decisions"],
|
|
389
|
+
["prompt", "Your prompts"]
|
|
390
|
+
]);
|
|
391
|
+
var STATS_JOURNAL_HINTS = Object.freeze([
|
|
392
|
+
"ctx_resume brings back your last task, files changed and open errors",
|
|
393
|
+
"after a compact or a restart; ctx_search finds indexed content by words."
|
|
394
|
+
]);
|
|
358
395
|
var PURGE_SCOPES = Object.freeze(["session", "source", "project"]);
|
|
359
396
|
var PURGE_NO_SCOPE_LINE = "ctx_purge: pick one scope \u2014 session, source, or project.";
|
|
360
397
|
var PURGE_MANY_SCOPES_LINE = "ctx_purge: pick only one scope \u2014 session, source, or project.";
|
|
@@ -370,7 +407,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
370
407
|
var DECISION_LABEL_JOIN = " | ";
|
|
371
408
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
372
409
|
var RELEASE_BRANCH = "release";
|
|
373
|
-
var BUNDLE_SHA = true ? "
|
|
410
|
+
var BUNDLE_SHA = true ? "dd54e208f8debb1c4601659ee632ada9a3612e45" : void 0;
|
|
374
411
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
375
412
|
var DOCTOR_LABEL = Object.freeze({
|
|
376
413
|
D1: "version",
|
|
@@ -400,9 +437,49 @@ function DOCTOR_FAIL_LINE(host, check2, cause, command) {
|
|
|
400
437
|
return `FAIL ${host}: ${check2} \u2014 ${cause}. Fix: ${command}`;
|
|
401
438
|
}
|
|
402
439
|
var DOCTOR_FIX_UPGRADE = "run ctx_upgrade";
|
|
403
|
-
var D1_NO_NETWORK_DETAIL = "no network";
|
|
404
440
|
var D1_DEV_BUILD_DETAIL = "dev build";
|
|
405
441
|
var D1_UPDATE_DETAIL = "update available";
|
|
442
|
+
var D1_SHORT_SHA_LEN = 7;
|
|
443
|
+
var D1_PACKAGE_FILE = "package.json";
|
|
444
|
+
function D1_PREFIX(version2, sha) {
|
|
445
|
+
return `${version2 ?? "bundle"} (${sha.slice(0, D1_SHORT_SHA_LEN)})`;
|
|
446
|
+
}
|
|
447
|
+
var D1_GIT_PASS = "latest on the release branch";
|
|
448
|
+
function D1_NPM_PASS(tag2) {
|
|
449
|
+
return `latest ${tag2} on npm`;
|
|
450
|
+
}
|
|
451
|
+
function D1_NPM_UPDATE(tag2, latest) {
|
|
452
|
+
return `${D1_UPDATE_DETAIL}, ${tag2} on npm is ${latest}`;
|
|
453
|
+
}
|
|
454
|
+
var D1_LATEST_UNKNOWN = "latest unknown";
|
|
455
|
+
var D1_GIT_MISSING = "git not found on PATH";
|
|
456
|
+
function D1_GIT_EXIT(code, stderrLine) {
|
|
457
|
+
return stderrLine === "" ? `git exit ${code}` : `git exit ${code}: ${stderrLine}`;
|
|
458
|
+
}
|
|
459
|
+
function D1_GIT_TIMEOUT(ms) {
|
|
460
|
+
return `git timed out after ${ms} ms`;
|
|
461
|
+
}
|
|
462
|
+
var D1_GIT_CANCEL = "git stopped by cancel";
|
|
463
|
+
var D1_GIT_NO_START = "git did not start";
|
|
464
|
+
var D1_GIT_NO_SHA = "git answered no sha";
|
|
465
|
+
function D1_NPM_TIMEOUT(ms) {
|
|
466
|
+
return `npm registry timed out after ${ms} ms`;
|
|
467
|
+
}
|
|
468
|
+
function D1_NPM_HTTP(status) {
|
|
469
|
+
return `npm registry answered HTTP ${status}`;
|
|
470
|
+
}
|
|
471
|
+
function D1_NPM_ERROR(cause) {
|
|
472
|
+
return `npm registry: ${cause}`;
|
|
473
|
+
}
|
|
474
|
+
function D1_NPM_NO_TAG(tag2) {
|
|
475
|
+
return `npm registry answered no ${tag2} version`;
|
|
476
|
+
}
|
|
477
|
+
var D1_CAUSE_JOIN = "; ";
|
|
478
|
+
var D1_GIT_CHECK_FIX = `git ls-remote ${RELEASE_REPO_URL} ${RELEASE_BRANCH}`;
|
|
479
|
+
var D1_NPM_CHECK_FIX = "npm view context-mode dist-tags";
|
|
480
|
+
var D1_REGISTRY_URL = "https://registry.npmjs.org/-/package/context-mode/dist-tags";
|
|
481
|
+
var D1_PRERELEASE_SEP = "-";
|
|
482
|
+
var D1_DEFAULT_TAG = "latest";
|
|
406
483
|
var GIT_LS_REMOTE = "ls-remote";
|
|
407
484
|
var D2_NODE_FIX = `install Node ${NODE_MIN} or later`;
|
|
408
485
|
function D2_NODE_DETAIL(version2) {
|
|
@@ -2338,11 +2415,11 @@ function jqPath(s) {
|
|
|
2338
2415
|
function jqWhitelisted(filter2) {
|
|
2339
2416
|
const s = filter2.trim();
|
|
2340
2417
|
if (s === JQ_WHITELIST.identity || s === JQ_WHITELIST.length) return true;
|
|
2341
|
-
const
|
|
2342
|
-
if (
|
|
2343
|
-
const left = s.slice(0,
|
|
2418
|
+
const bar2 = s.indexOf(JQ_WHITELIST.pipeLength.charAt(0));
|
|
2419
|
+
if (bar2 < 0) return jqPath(s);
|
|
2420
|
+
const left = s.slice(0, bar2).trim();
|
|
2344
2421
|
const right = JQ_WHITELIST.pipeLength.slice(1).trim();
|
|
2345
|
-
return (left === JQ_WHITELIST.identity || jqPath(left)) && s.slice(
|
|
2422
|
+
return (left === JQ_WHITELIST.identity || jqPath(left)) && s.slice(bar2 + 1).trim() === right;
|
|
2346
2423
|
}
|
|
2347
2424
|
function isBoundedSink(c) {
|
|
2348
2425
|
const name = c.argv0.toLowerCase();
|
|
@@ -3549,7 +3626,7 @@ var TOOL_DESCRIPTIONS = Object.freeze({
|
|
|
3549
3626
|
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.',
|
|
3550
3627
|
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.',
|
|
3551
3628
|
ctx_resume: "Example: `ctx_resume({})`. Required: none.\nReturns a summary of up to 2 KB for this session: the last task and user request, files changed, open errors, and search terms for ctx_search. A large row is shown as a pointer line instead of its full text; call `ctx_resume(seq: N)` with that line's number to read the full row. Call it with no `seq` to get the state block on demand. Use it after the conversation was compacted or resumed, before you repeat earlier work.",
|
|
3552
|
-
ctx_stats: "Example: `ctx_stats({})`. Required: none.\nReports
|
|
3629
|
+
ctx_stats: "Example: `ctx_stats({})`. Required: none.\nReports the bytes context-mode kept out of the chat: a text report (bars, per tool, per agent) and a Markdown table. Show the text block to the user unchanged, in a code block. Use it when the user asks what it saved.",
|
|
3553
3630
|
ctx_doctor: "Example: `ctx_doctor({})`. Required: none.\nChecks this context-mode install and reports a table with one row per check: version, Node and node:sqlite, host config and hooks for this agent, MCP connection, project and worktree, database health, index contents, and hook timing. Each failed row names its cause and the fix in one line. It changes nothing. Use it when the user asks whether context-mode works, or after a context-mode error.",
|
|
3554
3631
|
ctx_upgrade: "Example: `ctx_upgrade({})`. Required: none.\nUpdates context-mode to the latest release for this agent and rewrites only context-mode's own entries in the host config. User entries and user settings such as hook timeouts are kept, and old entries are erased. Returns a table of what changed and whether a restart is needed. Use it only when the user asks to update context-mode.",
|
|
3555
3632
|
ctx_purge: 'Example: `ctx_purge({source:"old-docs"})`. Required: one of session, source, project.\nDeletes stored data: one session, one indexed source, or everything stored for this project. This cannot be undone. Use it only when the user asks to forget or reset data.'
|
|
@@ -4628,7 +4705,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
4628
4705
|
terms = given.filter((t) => t.text.length >= 5).map((t) => ({ ...t, text: t.text.slice(0, Math.max(4, t.text.length - 2)) }));
|
|
4629
4706
|
pos = terms.map(find2);
|
|
4630
4707
|
}
|
|
4631
|
-
const
|
|
4708
|
+
const count2 = (ti, a, b) => {
|
|
4632
4709
|
const ps = pos[ti];
|
|
4633
4710
|
let lo = 0, hi = ps.length;
|
|
4634
4711
|
while (lo < hi) {
|
|
@@ -4643,7 +4720,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
4643
4720
|
const N = blocks.length;
|
|
4644
4721
|
const blen = blocks.map((bk2) => rangeBytes(bk2.first, bk2.last));
|
|
4645
4722
|
const avg = blen.reduce((a, b) => a + b, 0) / N || 1;
|
|
4646
|
-
const tf = blocks.map((bk2) => terms.map((_, ti) =>
|
|
4723
|
+
const tf = blocks.map((bk2) => terms.map((_, ti) => count2(ti, ls[bk2.first], le[bk2.last])));
|
|
4647
4724
|
const idf = terms.map((_, ti) => {
|
|
4648
4725
|
let df = 0;
|
|
4649
4726
|
for (let k = 0; k < N; k++) if (tf[k][ti] > 0) df++;
|
|
@@ -4665,7 +4742,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
4665
4742
|
const lineScore = (i) => {
|
|
4666
4743
|
let s = 0;
|
|
4667
4744
|
terms.forEach((_, ti) => {
|
|
4668
|
-
if (
|
|
4745
|
+
if (count2(ti, ls[i], le[i]) > 0) s += weight(ti, bk.code);
|
|
4669
4746
|
});
|
|
4670
4747
|
return s;
|
|
4671
4748
|
};
|
|
@@ -4673,7 +4750,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
4673
4750
|
let at2 = -1;
|
|
4674
4751
|
let w = -1;
|
|
4675
4752
|
terms.forEach((_, ti) => {
|
|
4676
|
-
const c =
|
|
4753
|
+
const c = count2(ti, ls[i], le[i]);
|
|
4677
4754
|
if (c === 0 || weight(ti, bk.code) <= w) return;
|
|
4678
4755
|
const ps = pos[ti];
|
|
4679
4756
|
let lo = 0, hi = ps.length;
|
|
@@ -6923,8 +7000,8 @@ function parseSourceHandle(s) {
|
|
|
6923
7000
|
function pathLabel(p) {
|
|
6924
7001
|
return p.includes("\\") ? p.split("\\").join("/") : p;
|
|
6925
7002
|
}
|
|
6926
|
-
function labelStored(db,
|
|
6927
|
-
return stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = ? LIMIT 1").get(
|
|
7003
|
+
function labelStored(db, label2) {
|
|
7004
|
+
return stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = ? LIMIT 1").get(label2) !== void 0;
|
|
6928
7005
|
}
|
|
6929
7006
|
function storedLabel(db, source) {
|
|
6930
7007
|
if (labelStored(db, source)) return source;
|
|
@@ -6954,9 +7031,9 @@ function insertUnits(db, sourceId, sessionId, units) {
|
|
|
6954
7031
|
let start = 0;
|
|
6955
7032
|
while (start < units.length) {
|
|
6956
7033
|
let end = start;
|
|
6957
|
-
let
|
|
6958
|
-
while (end < units.length && (end === start ||
|
|
6959
|
-
|
|
7034
|
+
let bytes5 = 0;
|
|
7035
|
+
while (end < units.length && (end === start || bytes5 + units[end].body.length <= INDEX_WRITE_CHUNK)) {
|
|
7036
|
+
bytes5 += units[end].body.length;
|
|
6960
7037
|
end++;
|
|
6961
7038
|
}
|
|
6962
7039
|
const from = start;
|
|
@@ -7009,9 +7086,9 @@ function firstLine2(body) {
|
|
|
7009
7086
|
return (nl < 0 ? body : body.slice(0, nl)).replaceAll("\r", " ");
|
|
7010
7087
|
}
|
|
7011
7088
|
function make(section, row5, text, repeatCount, query) {
|
|
7012
|
-
const
|
|
7013
|
-
if (
|
|
7014
|
-
return { section, seq: row5.seq, turn: row5.turn, text, bytes:
|
|
7089
|
+
const bytes5 = Buffer.byteLength(text, "utf8");
|
|
7090
|
+
if (bytes5 < 1) throw new Error("compaction: empty candidate line (DECISIONS-r9 M9).");
|
|
7091
|
+
return { section, seq: row5.seq, turn: row5.turn, text, bytes: bytes5, repeatCount, pinned: section === "last_request", query };
|
|
7015
7092
|
}
|
|
7016
7093
|
function capSection(list4) {
|
|
7017
7094
|
return list4.length > MAX_CANDIDATES ? list4.slice(list4.length - MAX_CANDIDATES) : list4;
|
|
@@ -7303,8 +7380,8 @@ function mdChunks(src, cap, lineCut) {
|
|
|
7303
7380
|
const stack = [];
|
|
7304
7381
|
let title = "";
|
|
7305
7382
|
let run = [];
|
|
7306
|
-
const push2 = (text,
|
|
7307
|
-
out.push({ ord: out.length, text, bytes:
|
|
7383
|
+
const push2 = (text, bytes5) => {
|
|
7384
|
+
out.push({ ord: out.length, text, bytes: bytes5, title });
|
|
7308
7385
|
};
|
|
7309
7386
|
const flush = () => {
|
|
7310
7387
|
if (run.length === 0) return;
|
|
@@ -7354,19 +7431,19 @@ function lineBlocks(src, md) {
|
|
|
7354
7431
|
let fenceInfo;
|
|
7355
7432
|
const close = () => {
|
|
7356
7433
|
if (start >= 0) {
|
|
7357
|
-
const
|
|
7358
|
-
if (heading !== void 0)
|
|
7359
|
-
if (fenceInfo !== void 0)
|
|
7360
|
-
out.push(
|
|
7434
|
+
const span2 = { start, end };
|
|
7435
|
+
if (heading !== void 0) span2.heading = heading;
|
|
7436
|
+
if (fenceInfo !== void 0) span2.fence = fenceInfo;
|
|
7437
|
+
out.push(span2);
|
|
7361
7438
|
}
|
|
7362
7439
|
start = -1;
|
|
7363
7440
|
heading = void 0;
|
|
7364
7441
|
fenceInfo = void 0;
|
|
7365
7442
|
};
|
|
7366
|
-
const add = (from, to,
|
|
7443
|
+
const add = (from, to, table3) => {
|
|
7367
7444
|
if (start < 0) start = from;
|
|
7368
7445
|
end = to;
|
|
7369
|
-
inTable =
|
|
7446
|
+
inTable = table3;
|
|
7370
7447
|
};
|
|
7371
7448
|
let pos = 0;
|
|
7372
7449
|
while (pos <= src.length) {
|
|
@@ -7387,9 +7464,9 @@ function lineBlocks(src, md) {
|
|
|
7387
7464
|
} else {
|
|
7388
7465
|
const opener = md ? fenceOf(line) : "";
|
|
7389
7466
|
const head = md && opener === "" ? headingOf(line) : void 0;
|
|
7390
|
-
const
|
|
7391
|
-
if (md && start >= 0 && (
|
|
7392
|
-
add(pos, eol,
|
|
7467
|
+
const table3 = md && opener === "" && head === void 0 && line.includes("|");
|
|
7468
|
+
if (md && start >= 0 && (table3 !== inTable || opener !== "" || head !== void 0)) close();
|
|
7469
|
+
add(pos, eol, table3);
|
|
7393
7470
|
fence = opener;
|
|
7394
7471
|
if (opener !== "") fenceInfo = { fence: opener, openEnd: eol, closeStart: -1 };
|
|
7395
7472
|
if (head !== void 0) {
|
|
@@ -7549,17 +7626,17 @@ function cutPoint(src, start, end, scratch) {
|
|
|
7549
7626
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
7550
7627
|
return { end: start + r.read, written: r.written };
|
|
7551
7628
|
}
|
|
7552
|
-
function merge(src, blocks,
|
|
7629
|
+
function merge(src, blocks, join24, cap, lineCut) {
|
|
7553
7630
|
const out = [];
|
|
7554
7631
|
const scratch = new Uint8Array(cap);
|
|
7555
7632
|
let wide;
|
|
7556
7633
|
let cur;
|
|
7557
7634
|
let curBytes = 0;
|
|
7558
|
-
const emit = (start, end,
|
|
7559
|
-
out.push({ ord: out.length, text: src.slice(start, end), bytes:
|
|
7635
|
+
const emit = (start, end, bytes5) => {
|
|
7636
|
+
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
7560
7637
|
};
|
|
7561
7638
|
for (const b of blocks) {
|
|
7562
|
-
if (cur !== void 0 && !
|
|
7639
|
+
if (cur !== void 0 && !join24) {
|
|
7563
7640
|
emit(cur.start, cur.end, curBytes);
|
|
7564
7641
|
cur = void 0;
|
|
7565
7642
|
}
|
|
@@ -7574,15 +7651,15 @@ function merge(src, blocks, join23, cap, lineCut) {
|
|
|
7574
7651
|
cur = void 0;
|
|
7575
7652
|
}
|
|
7576
7653
|
let start = b.start;
|
|
7577
|
-
let
|
|
7578
|
-
while (
|
|
7654
|
+
let bytes5 = utf8Bytes(src.slice(b.start, b.end));
|
|
7655
|
+
while (bytes5 > cap) {
|
|
7579
7656
|
const cut = cutPoint(src, start, b.end, scratch);
|
|
7580
7657
|
const nl = lineCut ? src.lastIndexOf("\n", cut.end - 1) : -1;
|
|
7581
7658
|
if (nl > start) {
|
|
7582
7659
|
const w = utf8Bytes(src.slice(start, nl + 1));
|
|
7583
7660
|
emit(start, nl + 1, w);
|
|
7584
7661
|
start = nl + 1;
|
|
7585
|
-
|
|
7662
|
+
bytes5 -= w;
|
|
7586
7663
|
continue;
|
|
7587
7664
|
}
|
|
7588
7665
|
if (lineCut) {
|
|
@@ -7592,23 +7669,23 @@ function merge(src, blocks, join23, cap, lineCut) {
|
|
|
7592
7669
|
if (w <= MAX_CHUNK_BYTES) {
|
|
7593
7670
|
emit(start, lineEnd, w);
|
|
7594
7671
|
start = lineEnd;
|
|
7595
|
-
|
|
7672
|
+
bytes5 -= w;
|
|
7596
7673
|
continue;
|
|
7597
7674
|
}
|
|
7598
7675
|
wide ??= new Uint8Array(MAX_CHUNK_BYTES);
|
|
7599
7676
|
const big = cutPoint(src, start, lineEnd, wide);
|
|
7600
7677
|
emit(start, big.end, big.written);
|
|
7601
7678
|
start = big.end;
|
|
7602
|
-
|
|
7679
|
+
bytes5 -= big.written;
|
|
7603
7680
|
continue;
|
|
7604
7681
|
}
|
|
7605
7682
|
emit(start, cut.end, cut.written);
|
|
7606
7683
|
start = cut.end;
|
|
7607
|
-
|
|
7684
|
+
bytes5 -= cut.written;
|
|
7608
7685
|
}
|
|
7609
7686
|
if (start >= b.end) continue;
|
|
7610
7687
|
cur = { start, end: b.end };
|
|
7611
|
-
curBytes =
|
|
7688
|
+
curBytes = bytes5;
|
|
7612
7689
|
}
|
|
7613
7690
|
if (cur !== void 0) emit(cur.start, cur.end, curBytes);
|
|
7614
7691
|
return out;
|
|
@@ -7629,7 +7706,7 @@ function selectChunks(db, sourceId, intent, budget) {
|
|
|
7629
7706
|
function selectChunksInMemory(chunks, intent, budget, source, rankQuery) {
|
|
7630
7707
|
return select(chunks, intent, budget, source, rankQuery);
|
|
7631
7708
|
}
|
|
7632
|
-
function select(chunks, intent, budget,
|
|
7709
|
+
function select(chunks, intent, budget, label2, rankQuery) {
|
|
7633
7710
|
if (chunks.length === 0) return { text: "", more: null };
|
|
7634
7711
|
const texts = chunks.map((c) => c.text);
|
|
7635
7712
|
const scores = rankQuery === void 0 ? rankTexts(texts, intent) : rankTexts(texts, rankQuery, "any");
|
|
@@ -7648,10 +7725,10 @@ function select(chunks, intent, budget, label, rankQuery) {
|
|
|
7648
7725
|
}
|
|
7649
7726
|
picked.sort((a, b) => a.ord - b.ord);
|
|
7650
7727
|
const text = picked.map((c) => c.text).join(SEP);
|
|
7651
|
-
return { text, more: skipped ? moreLine2(intent,
|
|
7728
|
+
return { text, more: skipped ? moreLine2(intent, label2) : null };
|
|
7652
7729
|
}
|
|
7653
|
-
function moreLine2(intent,
|
|
7654
|
-
const source =
|
|
7730
|
+
function moreLine2(intent, label2) {
|
|
7731
|
+
const source = label2 === void 0 ? "" : ", source:" + JSON.stringify(label2);
|
|
7655
7732
|
const query = Buffer.byteLength(intent, "utf8") > ECHO_MAX_BYTES ? "..." : JSON.stringify(intent);
|
|
7656
7733
|
return "ctx_search({queries:[" + query + "]" + source + "})";
|
|
7657
7734
|
}
|
|
@@ -7699,10 +7776,10 @@ function firstNonSpace(s) {
|
|
|
7699
7776
|
function isPlainObject(v) {
|
|
7700
7777
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7701
7778
|
}
|
|
7702
|
-
function rareOfSkewed(n, counts,
|
|
7703
|
-
if (
|
|
7704
|
-
const sorted = [...
|
|
7705
|
-
if (
|
|
7779
|
+
function rareOfSkewed(n, counts, totals2) {
|
|
7780
|
+
if (totals2.size < 2 || totals2.size > SHAPE_CATEGORICAL_MAX) return [];
|
|
7781
|
+
const sorted = [...totals2.entries()].sort((a, b) => b[1] - a[1]);
|
|
7782
|
+
if (totals2.size <= SHAPE_RARE_MAX + 1) {
|
|
7706
7783
|
if (sorted[0][1] < SHAPE_DOMINANT * n || n - sorted[0][1] > SHAPE_RARE_MAX) return [];
|
|
7707
7784
|
return sorted.slice(1).flatMap(([v]) => counts.get(v) ?? []);
|
|
7708
7785
|
}
|
|
@@ -7737,7 +7814,7 @@ function jsonShape(text, query) {
|
|
|
7737
7814
|
const outliers = /* @__PURE__ */ new Map();
|
|
7738
7815
|
for (const k of keys) {
|
|
7739
7816
|
const counts = /* @__PURE__ */ new Map();
|
|
7740
|
-
const
|
|
7817
|
+
const totals2 = /* @__PURE__ */ new Map();
|
|
7741
7818
|
let scalar = true;
|
|
7742
7819
|
for (let i = 0; i < objs.length && scalar; i++) {
|
|
7743
7820
|
const v = k in objs[i] ? objs[i][k] : void 0;
|
|
@@ -7746,14 +7823,14 @@ function jsonShape(text, query) {
|
|
|
7746
7823
|
break;
|
|
7747
7824
|
}
|
|
7748
7825
|
const s = v === void 0 ? ABSENT : JSON.stringify(v);
|
|
7749
|
-
|
|
7826
|
+
totals2.set(s, (totals2.get(s) ?? 0) + 1);
|
|
7750
7827
|
const at2 = counts.get(s) ?? [];
|
|
7751
7828
|
if (at2.length <= SHAPE_RARE_MAX) at2.push(i);
|
|
7752
7829
|
counts.set(s, at2);
|
|
7753
|
-
if (
|
|
7830
|
+
if (totals2.size > SHAPE_CATEGORICAL_MAX) break;
|
|
7754
7831
|
}
|
|
7755
7832
|
if (!scalar) continue;
|
|
7756
|
-
for (const i of rareOfSkewed(objs.length, counts,
|
|
7833
|
+
for (const i of rareOfSkewed(objs.length, counts, totals2)) outliers.set(i, [...outliers.get(i) ?? [], k]);
|
|
7757
7834
|
}
|
|
7758
7835
|
if (outliers.size === 0 || outliers.size > SHAPE_RARE_UNITS_MAX) return null;
|
|
7759
7836
|
const keyScore = rankTexts(keys, query, "any");
|
|
@@ -7881,14 +7958,14 @@ function lineShape(text) {
|
|
|
7881
7958
|
}
|
|
7882
7959
|
|
|
7883
7960
|
// src/core/index/text.ts
|
|
7884
|
-
function storeText(db, project, sessionId, sourceKind,
|
|
7961
|
+
function storeText(db, project, sessionId, sourceKind, label2, text, kind, chunks = chunkText(text, kind)) {
|
|
7885
7962
|
const sourceId = ftsInsert(db, {
|
|
7886
7963
|
projectKey: project.projectKey,
|
|
7887
7964
|
sessionId,
|
|
7888
7965
|
worktree: project.worktree,
|
|
7889
7966
|
agent: project.agent,
|
|
7890
7967
|
kind: sourceKind,
|
|
7891
|
-
label,
|
|
7968
|
+
label: label2,
|
|
7892
7969
|
bytes: Buffer.byteLength(text, "utf8"),
|
|
7893
7970
|
chunkCount: chunks.length,
|
|
7894
7971
|
createdAt: Date.now()
|
|
@@ -7951,9 +8028,9 @@ function answerDecisions(responseText) {
|
|
|
7951
8028
|
if (!isObject2(parsed)) return [];
|
|
7952
8029
|
const out = [];
|
|
7953
8030
|
for (const [question, value] of answerPairs(parsed[DECISION_ANSWERS_KEY])) {
|
|
7954
|
-
const
|
|
7955
|
-
if (question === "" ||
|
|
7956
|
-
out.push({ key: question, body: "Q: " + question + " \u2192 A: " +
|
|
8031
|
+
const label2 = labelText(value);
|
|
8032
|
+
if (question === "" || label2 === "") continue;
|
|
8033
|
+
out.push({ key: question, body: "Q: " + question + " \u2192 A: " + label2 });
|
|
7957
8034
|
}
|
|
7958
8035
|
return out;
|
|
7959
8036
|
}
|
|
@@ -7973,9 +8050,9 @@ function fold(s) {
|
|
|
7973
8050
|
function optionEchoDecision(prompt, labels, refSeq) {
|
|
7974
8051
|
const p = fold(prompt);
|
|
7975
8052
|
if (p === "") return null;
|
|
7976
|
-
const
|
|
7977
|
-
if (
|
|
7978
|
-
return { key: DECISION_OPTION_KEY, body: "A: " +
|
|
8053
|
+
const label2 = labels.find((l) => fold(l) === p);
|
|
8054
|
+
if (label2 === void 0) return null;
|
|
8055
|
+
return { key: DECISION_OPTION_KEY, body: "A: " + label2 + "\nref: #" + refSeq };
|
|
7979
8056
|
}
|
|
7980
8057
|
|
|
7981
8058
|
// src/core/hooks/throttle.ts
|
|
@@ -7989,9 +8066,9 @@ function takeOnce(db, key) {
|
|
|
7989
8066
|
}
|
|
7990
8067
|
function takeEvery(db, key, everyN) {
|
|
7991
8068
|
const stored = metaGet(db, key);
|
|
7992
|
-
const
|
|
7993
|
-
metaSet(db, key, String(
|
|
7994
|
-
return (
|
|
8069
|
+
const count2 = (stored === null ? 0 : Number.parseInt(stored, 10)) + 1;
|
|
8070
|
+
metaSet(db, key, String(count2));
|
|
8071
|
+
return (count2 - 1) % everyN === 0;
|
|
7995
8072
|
}
|
|
7996
8073
|
function shouldHint(db, sessionId, onceKey, everyN) {
|
|
7997
8074
|
if (sessionId === "") return false;
|
|
@@ -8484,33 +8561,33 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
|
8484
8561
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
8485
8562
|
if (result.keep === true) return ALLOW2;
|
|
8486
8563
|
if (!hasReplace(row5)) return ALLOW2;
|
|
8487
|
-
let
|
|
8564
|
+
let label2;
|
|
8488
8565
|
if (isSubagentCall(ev)) {
|
|
8489
8566
|
const subCase = pickSubagentCase(ev, toolSetForAgentType(ev, { projectDir: project.worktree, env }));
|
|
8490
8567
|
if (subCase === "A") return ALLOW2;
|
|
8491
|
-
|
|
8568
|
+
label2 = SUBAGENT_SOURCE_PREFIX + tool.canonicalName + ":" + String(ev.turn ?? 0);
|
|
8492
8569
|
} else {
|
|
8493
|
-
|
|
8570
|
+
label2 = mainLabel(tool, ev);
|
|
8494
8571
|
}
|
|
8495
8572
|
const intent = [tool.input.description, tool.input.command, tool.input.file_path, tool.input.pattern, tool.input.url].map(str2).find((v) => v.trim() !== "") ?? "";
|
|
8496
8573
|
const chunks = chunkText(text, "text", REPLACE_CHUNK_BYTES);
|
|
8497
8574
|
const db = await openDb(project);
|
|
8498
8575
|
let sourceId;
|
|
8499
8576
|
if (result.bytes <= SYNC_INDEX_MAX_BYTES) {
|
|
8500
|
-
sourceId = indexText(db, project, ev.sessionId,
|
|
8577
|
+
sourceId = indexText(db, project, ev.sessionId, label2, text, "text", chunks).sourceId;
|
|
8501
8578
|
insertUnits(db, sourceId, ev.sessionId, buildUnits(text));
|
|
8502
8579
|
} else {
|
|
8503
|
-
sourceId = reserveSource(db, sourceRowOf(project, ev.sessionId,
|
|
8504
|
-
indexDetached(project, ev.sessionId, sourceId,
|
|
8580
|
+
sourceId = reserveSource(db, sourceRowOf(project, ev.sessionId, label2), chunks);
|
|
8581
|
+
indexDetached(project, ev.sessionId, sourceId, label2, text, chunks);
|
|
8505
8582
|
}
|
|
8506
8583
|
const handle = sourceHandle(sourceId);
|
|
8507
8584
|
const prompt = await lastPrompt(project, ev.sessionId);
|
|
8508
8585
|
const rankQuery = prompt.trim() === "" ? void 0 : intent + " " + prompt;
|
|
8509
8586
|
const handleLine = REPLACE_HANDLE_LINE(intent, handle, result.bytes, row5.toolNamePrefix, askedWords(intent, prompt, text));
|
|
8510
|
-
const budget = replaceBudget(handleLine, moreLine2(intent,
|
|
8587
|
+
const budget = replaceBudget(handleLine, moreLine2(intent, label2));
|
|
8511
8588
|
const digest = shapeDigest(text, rankQuery ?? intent, SHAPE_RETURN_BYTES);
|
|
8512
8589
|
if (digest !== null) return { kind: "replace", output: replaceOutput(digest, handleLine) };
|
|
8513
|
-
const selected = selectChunksInMemory(chunks, intent, budget,
|
|
8590
|
+
const selected = selectChunksInMemory(chunks, intent, budget, label2, rankQuery);
|
|
8514
8591
|
return { kind: "replace", output: selected.more !== null ? replaceOutput(selected.text, handleLine) : selected.text };
|
|
8515
8592
|
}
|
|
8516
8593
|
function replaceOutput(body, handleLine) {
|
|
@@ -8541,15 +8618,15 @@ function mainLabel(tool, ev) {
|
|
|
8541
8618
|
const head = (tool.canonicalName + ":" + (nl < 0 ? cmd : cmd.slice(0, nl))).slice(0, SOURCE_LABEL_MAX_CHARS);
|
|
8542
8619
|
return head + "#" + (tool.callId ?? String(ev.turn ?? 0));
|
|
8543
8620
|
}
|
|
8544
|
-
function indexDetached(project, sessionId, sourceId,
|
|
8621
|
+
function indexDetached(project, sessionId, sourceId, label2, text, chunks) {
|
|
8545
8622
|
void openDb(project).then((db) => {
|
|
8546
|
-
finishReserved(db, sourceId, sourceRowOf(project, sessionId,
|
|
8623
|
+
finishReserved(db, sourceId, sourceRowOf(project, sessionId, label2), chunks, buildUnits(text));
|
|
8547
8624
|
}).catch((err) => {
|
|
8548
8625
|
process.stderr.write("hooks: index write failed: " + message(err) + "\n");
|
|
8549
8626
|
});
|
|
8550
8627
|
}
|
|
8551
|
-
function sourceRowOf(project, sessionId,
|
|
8552
|
-
return { sessionId, worktree: project.worktree, agent: project.agent, kind: "content", label, createdAt: Date.now() };
|
|
8628
|
+
function sourceRowOf(project, sessionId, label2) {
|
|
8629
|
+
return { sessionId, worktree: project.worktree, agent: project.agent, kind: "content", label: label2, createdAt: Date.now() };
|
|
8553
8630
|
}
|
|
8554
8631
|
async function preCompact(ev, row5, project) {
|
|
8555
8632
|
const db = await openDb(project);
|
|
@@ -12430,8 +12507,8 @@ function az_default() {
|
|
|
12430
12507
|
}
|
|
12431
12508
|
|
|
12432
12509
|
// node_modules/zod/v4/locales/be.js
|
|
12433
|
-
function getBelarusianPlural(
|
|
12434
|
-
const absCount = Math.abs(
|
|
12510
|
+
function getBelarusianPlural(count2, one, few, many) {
|
|
12511
|
+
const absCount = Math.abs(count2);
|
|
12435
12512
|
const lastDigit = absCount % 10;
|
|
12436
12513
|
const lastTwoDigits = absCount % 100;
|
|
12437
12514
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -15576,8 +15653,8 @@ function pt_default() {
|
|
|
15576
15653
|
}
|
|
15577
15654
|
|
|
15578
15655
|
// node_modules/zod/v4/locales/ru.js
|
|
15579
|
-
function getRussianPlural(
|
|
15580
|
-
const absCount = Math.abs(
|
|
15656
|
+
function getRussianPlural(count2, one, few, many) {
|
|
15657
|
+
const absCount = Math.abs(count2);
|
|
15581
15658
|
const lastDigit = absCount % 10;
|
|
15582
15659
|
const lastTwoDigits = absCount % 100;
|
|
15583
15660
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -20149,7 +20226,7 @@ function relevance(db, given, scope, ctx) {
|
|
|
20149
20226
|
mine.add(hit.sourceId);
|
|
20150
20227
|
}
|
|
20151
20228
|
if (again.size > 0) {
|
|
20152
|
-
const line = "Same as above: " + [...again].map(([
|
|
20229
|
+
const line = "Same as above: " + [...again].map(([label2, ords]) => label2 + " (chunk " + ords.join(",") + ")").join("; ");
|
|
20153
20230
|
lines.push(line);
|
|
20154
20231
|
used += bytes2(line) + 1;
|
|
20155
20232
|
}
|
|
@@ -20296,7 +20373,7 @@ function shown(chunks, heads) {
|
|
|
20296
20373
|
return c.text;
|
|
20297
20374
|
});
|
|
20298
20375
|
}
|
|
20299
|
-
function indexCombined(db, ctx,
|
|
20376
|
+
function indexCombined(db, ctx, label2, ran, deadline, budgetBytes) {
|
|
20300
20377
|
const chunks = chunkText(ran.map((r) => r.block).join(BLOCK_SEP), "text");
|
|
20301
20378
|
const display = shown(chunks, ran.map((r) => r.head));
|
|
20302
20379
|
const bodies = /* @__PURE__ */ new Map();
|
|
@@ -20316,7 +20393,7 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
|
|
|
20316
20393
|
worktree: ctx.project.worktree,
|
|
20317
20394
|
agent: ctx.project.agent,
|
|
20318
20395
|
kind: "content",
|
|
20319
|
-
label,
|
|
20396
|
+
label: label2,
|
|
20320
20397
|
bytes: groupBytes,
|
|
20321
20398
|
chunkCount: group.length,
|
|
20322
20399
|
createdAt: Date.now()
|
|
@@ -20346,12 +20423,12 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
|
|
|
20346
20423
|
function bytes3(s) {
|
|
20347
20424
|
return Buffer.byteLength(s, "utf8");
|
|
20348
20425
|
}
|
|
20349
|
-
function answer(db, ctx,
|
|
20426
|
+
function answer(db, ctx, label2, queries, share, own2) {
|
|
20350
20427
|
const seen = /* @__PURE__ */ new Set();
|
|
20351
20428
|
const lines = [];
|
|
20352
20429
|
for (const [qi, q] of queries.entries()) {
|
|
20353
20430
|
if (ctx.signal.aborted) break;
|
|
20354
|
-
let hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0,
|
|
20431
|
+
let hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0, label2);
|
|
20355
20432
|
if (hits.length === 0) hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0);
|
|
20356
20433
|
const head = "## " + (bytes3(q) > ECHO_MAX_BYTES ? "query " + (qi + 1) : q);
|
|
20357
20434
|
let used = bytes3(head) + 1;
|
|
@@ -20390,17 +20467,17 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
20390
20467
|
const ran = pool.results;
|
|
20391
20468
|
const last2 = ran[ran.length - 1];
|
|
20392
20469
|
const sandboxBytes = ran.reduce((n, r) => n + r.bytes, 0);
|
|
20393
|
-
const
|
|
20470
|
+
const label2 = LABEL_PREFIX + ctx.turn;
|
|
20394
20471
|
try {
|
|
20395
20472
|
const db = await openDb(ctx.project);
|
|
20396
20473
|
let sections;
|
|
20397
20474
|
let idx;
|
|
20398
20475
|
const exitLine = last2.exitCode === null || last2.exitCode === 0 ? null : "exit " + last2.exitCode;
|
|
20399
|
-
const footer = "more: ctx_search({queries:[...], source:" + JSON.stringify(
|
|
20476
|
+
const footer = "more: ctx_search({queries:[...], source:" + JSON.stringify(label2) + "})";
|
|
20400
20477
|
let notice;
|
|
20401
20478
|
let showMore;
|
|
20402
20479
|
try {
|
|
20403
|
-
idx = indexCombined(db, ctx,
|
|
20480
|
+
idx = indexCombined(db, ctx, label2, ran, deadline, budgetBytes);
|
|
20404
20481
|
const stop = last2.error;
|
|
20405
20482
|
const cut = idx.indexed < idx.total ? "Indexed " + idx.indexed + " of " + idx.total + " B." : null;
|
|
20406
20483
|
const timeout = formatError("TIMEOUT", { ms: boundMs });
|
|
@@ -20408,7 +20485,7 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
20408
20485
|
notice = cut === null ? stop : cause === null ? cut : cause + " " + cut;
|
|
20409
20486
|
const fixed = (exitLine === null ? 0 : bytes3(exitLine) + 1) + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
|
|
20410
20487
|
const share = Math.floor((OUTPUT_CAP - fixed) / queries.length);
|
|
20411
|
-
const answered = answer(db, ctx,
|
|
20488
|
+
const answered = answer(db, ctx, label2, queries, share, idx.bodies);
|
|
20412
20489
|
sections = answered.lines;
|
|
20413
20490
|
const unseen = [...idx.bodies].filter(([k, text]) => text !== "" && !answered.seen.has(k)).map(([k]) => idx.raw.get(k));
|
|
20414
20491
|
const unseenBytes = unseen.reduce((n, t) => n + bytes3(t) + 1, 0);
|
|
@@ -20444,8 +20521,8 @@ var ctxBatch = Object.freeze({
|
|
|
20444
20521
|
});
|
|
20445
20522
|
|
|
20446
20523
|
// src/core/tools/doctor.ts
|
|
20447
|
-
import { readdirSync as readdirSync5, readFileSync as
|
|
20448
|
-
import { basename as basename4, dirname as dirname7, join as
|
|
20524
|
+
import { readdirSync as readdirSync5, readFileSync as readFileSync12, existsSync as existsSync12 } from "node:fs";
|
|
20525
|
+
import { basename as basename4, dirname as dirname7, join as join14 } from "node:path";
|
|
20449
20526
|
|
|
20450
20527
|
// src/core/ops/doctor-config.ts
|
|
20451
20528
|
import { existsSync as existsSync6, readdirSync as readdirSync3 } from "node:fs";
|
|
@@ -21615,7 +21692,7 @@ var Tokenizer = class {
|
|
|
21615
21692
|
hasUnderscore
|
|
21616
21693
|
};
|
|
21617
21694
|
}
|
|
21618
|
-
parseUnicode(
|
|
21695
|
+
parseUnicode(count2) {
|
|
21619
21696
|
const startLoc = this.codePointIterator.start;
|
|
21620
21697
|
const start = this.codePointIterator.end;
|
|
21621
21698
|
let charCount = 0;
|
|
@@ -21626,7 +21703,7 @@ var Tokenizer = class {
|
|
|
21626
21703
|
return this.reportParseError("invalid-char-in-escape-sequence");
|
|
21627
21704
|
}
|
|
21628
21705
|
charCount++;
|
|
21629
|
-
if (charCount >=
|
|
21706
|
+
if (charCount >= count2) break;
|
|
21630
21707
|
}
|
|
21631
21708
|
const end = this.codePointIterator.end;
|
|
21632
21709
|
const code = this.text.slice(start, end);
|
|
@@ -22392,17 +22469,17 @@ function generateConvertTOMLValue(convertValue) {
|
|
|
22392
22469
|
return baseTable;
|
|
22393
22470
|
},
|
|
22394
22471
|
TOMLTable(node, baseTable = {}) {
|
|
22395
|
-
const
|
|
22396
|
-
for (const body of node.body) resolveValue(body,
|
|
22472
|
+
const table3 = getTable(baseTable, resolveValue(node.key), node.kind === "array");
|
|
22473
|
+
for (const body of node.body) resolveValue(body, table3);
|
|
22397
22474
|
return baseTable;
|
|
22398
22475
|
},
|
|
22399
22476
|
TOMLArray(node) {
|
|
22400
22477
|
return node.elements.map((e) => resolveValue(e));
|
|
22401
22478
|
},
|
|
22402
22479
|
TOMLInlineTable(node) {
|
|
22403
|
-
const
|
|
22404
|
-
for (const body of node.body) resolveValue(body,
|
|
22405
|
-
return
|
|
22480
|
+
const table3 = {};
|
|
22481
|
+
for (const body of node.body) resolveValue(body, table3);
|
|
22482
|
+
return table3;
|
|
22406
22483
|
},
|
|
22407
22484
|
TOMLKey(node) {
|
|
22408
22485
|
return node.keys.map((key) => resolveValue(key));
|
|
@@ -23142,10 +23219,10 @@ function scanCodex(agentHome, out) {
|
|
|
23142
23219
|
}
|
|
23143
23220
|
const tomlFile = join9(agentHome, CONFIG_TOML_FILE);
|
|
23144
23221
|
const config2 = readTomlValue(tomlFile);
|
|
23145
|
-
for (const
|
|
23146
|
-
if (
|
|
23147
|
-
if (
|
|
23148
|
-
out.push(finding(tomlFile,
|
|
23222
|
+
for (const span2 of readTomlTables(tomlFile)) {
|
|
23223
|
+
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
23224
|
+
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config2, span2.path))) continue;
|
|
23225
|
+
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
23149
23226
|
}
|
|
23150
23227
|
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23151
23228
|
}
|
|
@@ -23734,29 +23811,92 @@ async function checkIndex(project) {
|
|
|
23734
23811
|
}
|
|
23735
23812
|
|
|
23736
23813
|
// src/core/ops/doctor-env.ts
|
|
23737
|
-
import { existsSync as existsSync8, realpathSync as realpathSync5 } from "node:fs";
|
|
23738
|
-
import { isAbsolute as isAbsolute3, relative as relative2 } from "node:path";
|
|
23814
|
+
import { existsSync as existsSync8, readFileSync as readFileSync9, realpathSync as realpathSync5 } from "node:fs";
|
|
23815
|
+
import { isAbsolute as isAbsolute3, join as join12, relative as relative2 } from "node:path";
|
|
23739
23816
|
function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
23740
23817
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
23741
23818
|
}
|
|
23742
|
-
function unknown3(id2, detail) {
|
|
23743
|
-
return { id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail };
|
|
23819
|
+
function unknown3(id2, detail, fixCommand) {
|
|
23820
|
+
return fixCommand === void 0 ? { id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail } : { id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail, fixCommand };
|
|
23744
23821
|
}
|
|
23745
23822
|
function fail4(id2, detail, fixCommand) {
|
|
23746
23823
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "FAIL", detail, fixCommand };
|
|
23747
23824
|
}
|
|
23825
|
+
function bundleVersion(bundleDir2) {
|
|
23826
|
+
try {
|
|
23827
|
+
const v = JSON.parse(readFileSync9(join12(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
23828
|
+
return typeof v === "string" && v !== "" ? v : void 0;
|
|
23829
|
+
} catch {
|
|
23830
|
+
return void 0;
|
|
23831
|
+
}
|
|
23832
|
+
}
|
|
23833
|
+
function channelOf(version2) {
|
|
23834
|
+
const at2 = version2.indexOf(D1_PRERELEASE_SEP);
|
|
23835
|
+
if (at2 < 0) return D1_DEFAULT_TAG;
|
|
23836
|
+
const pre = version2.slice(at2 + 1);
|
|
23837
|
+
const dot = pre.indexOf(".");
|
|
23838
|
+
const tag2 = dot < 0 ? pre : pre.slice(0, dot);
|
|
23839
|
+
return tag2 === "" ? D1_DEFAULT_TAG : tag2;
|
|
23840
|
+
}
|
|
23841
|
+
function firstLine3(b) {
|
|
23842
|
+
const text = b.toString("utf8").trim();
|
|
23843
|
+
const nl = text.indexOf("\n");
|
|
23844
|
+
return (nl < 0 ? text : text.slice(0, nl)).trim();
|
|
23845
|
+
}
|
|
23846
|
+
function gitCause(r, timeoutMs) {
|
|
23847
|
+
if (r.killed === "timeout") return D1_GIT_TIMEOUT(timeoutMs);
|
|
23848
|
+
if (r.killed === "cancel") return D1_GIT_CANCEL;
|
|
23849
|
+
if (r.exitCode === null) return D1_GIT_NO_START;
|
|
23850
|
+
return D1_GIT_EXIT(r.exitCode, firstLine3(r.stderr));
|
|
23851
|
+
}
|
|
23852
|
+
function fetchCause(err, timeoutMs) {
|
|
23853
|
+
const name = err instanceof Error ? err.name : "";
|
|
23854
|
+
if (name === "TimeoutError") return D1_NPM_TIMEOUT(timeoutMs);
|
|
23855
|
+
const cause = err instanceof Error && err.cause instanceof Error ? err.cause : err;
|
|
23856
|
+
const code = typeof cause === "object" && cause !== null && "code" in cause && typeof cause.code === "string" ? cause.code : "";
|
|
23857
|
+
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
23858
|
+
return D1_NPM_ERROR(code !== "" && !msg.includes(code) ? `${code} ${msg}` : msg);
|
|
23859
|
+
}
|
|
23860
|
+
async function npmLatest(url2, tag2, signal, timeoutMs) {
|
|
23861
|
+
try {
|
|
23862
|
+
const res = await fetch(url2, { signal: AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) });
|
|
23863
|
+
if (!res.ok) return { ok: false, cause: D1_NPM_HTTP(res.status) };
|
|
23864
|
+
const body = await res.json();
|
|
23865
|
+
const v = typeof body === "object" && body !== null ? body[tag2] : void 0;
|
|
23866
|
+
return typeof v === "string" && v !== "" ? { ok: true, version: v } : { ok: false, cause: D1_NPM_NO_TAG(tag2) };
|
|
23867
|
+
} catch (err) {
|
|
23868
|
+
return { ok: false, cause: fetchCause(err, timeoutMs) };
|
|
23869
|
+
}
|
|
23870
|
+
}
|
|
23748
23871
|
async function checkVersion(i) {
|
|
23749
23872
|
if (i.bundleSha === void 0) return unknown3("D1", D1_DEV_BUILD_DETAIL);
|
|
23750
|
-
const
|
|
23751
|
-
|
|
23752
|
-
|
|
23753
|
-
|
|
23754
|
-
|
|
23755
|
-
|
|
23756
|
-
|
|
23757
|
-
|
|
23758
|
-
|
|
23759
|
-
|
|
23873
|
+
const head = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
23874
|
+
const git3 = findRuntime(GIT_BIN, i.env);
|
|
23875
|
+
let cause = D1_GIT_MISSING;
|
|
23876
|
+
if (git3 !== null) {
|
|
23877
|
+
const r = await runProcess([git3, GIT_LS_REMOTE, RELEASE_REPO_URL, RELEASE_BRANCH], {
|
|
23878
|
+
cwd: i.cwd,
|
|
23879
|
+
env: { ...i.env, ...GIT_NO_PROMPT_ENV },
|
|
23880
|
+
signal: i.signal,
|
|
23881
|
+
timeoutMs: i.timeoutMs
|
|
23882
|
+
});
|
|
23883
|
+
if (r.exitCode === 0 && r.killed === null) {
|
|
23884
|
+
const latest = r.stdout.toString("utf8").split(LS_REMOTE_FIELD_SEP)[0];
|
|
23885
|
+
if (latest.length === GIT_SHA_HEX_LEN) {
|
|
23886
|
+
return latest === i.bundleSha ? pass3("D1", head + D1_GIT_PASS) : fail4("D1", head + D1_UPDATE_DETAIL, DOCTOR_FIX_UPGRADE);
|
|
23887
|
+
}
|
|
23888
|
+
cause = D1_GIT_NO_SHA;
|
|
23889
|
+
} else {
|
|
23890
|
+
cause = gitCause(r, i.timeoutMs);
|
|
23891
|
+
}
|
|
23892
|
+
}
|
|
23893
|
+
const handFix = git3 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX;
|
|
23894
|
+
if (i.version === void 0) return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + cause, handFix);
|
|
23895
|
+
const tag2 = channelOf(i.version);
|
|
23896
|
+
const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
|
|
23897
|
+
if (!npm.ok) return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + cause + D1_CAUSE_JOIN + npm.cause, handFix);
|
|
23898
|
+
if (npm.version === i.version) return pass3("D1", head + D1_NPM_PASS(tag2) + D1_CAUSE_JOIN + cause);
|
|
23899
|
+
return fail4("D1", head + D1_NPM_UPDATE(tag2, npm.version) + D1_CAUSE_JOIN + cause, DOCTOR_FIX_UPGRADE);
|
|
23760
23900
|
}
|
|
23761
23901
|
function numbers(v) {
|
|
23762
23902
|
const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
|
|
@@ -23813,7 +23953,7 @@ function checkShell(env) {
|
|
|
23813
23953
|
}
|
|
23814
23954
|
|
|
23815
23955
|
// src/core/ops/doctor-hook.ts
|
|
23816
|
-
import { existsSync as existsSync10, readFileSync as
|
|
23956
|
+
import { existsSync as existsSync10, readFileSync as readFileSync10, realpathSync as realpathSync7 } from "node:fs";
|
|
23817
23957
|
import path6 from "node:path";
|
|
23818
23958
|
|
|
23819
23959
|
// src/setup/codex-trust.ts
|
|
@@ -24038,7 +24178,7 @@ function loadFixture(bundleDir2, agent) {
|
|
|
24038
24178
|
if (!existsSync10(file2)) return null;
|
|
24039
24179
|
let all;
|
|
24040
24180
|
try {
|
|
24041
|
-
all = JSON.parse(hostText(
|
|
24181
|
+
all = JSON.parse(hostText(readFileSync10(file2, "utf8")));
|
|
24042
24182
|
} catch {
|
|
24043
24183
|
return null;
|
|
24044
24184
|
}
|
|
@@ -24134,10 +24274,10 @@ async function checkHookRoundTrip(i) {
|
|
|
24134
24274
|
import { existsSync as existsSync11, rmSync as rmSync3 } from "node:fs";
|
|
24135
24275
|
|
|
24136
24276
|
// src/core/store/owners.ts
|
|
24137
|
-
import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as
|
|
24138
|
-
import { basename as basename3, join as
|
|
24277
|
+
import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as readFileSync11, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
24278
|
+
import { basename as basename3, join as join13 } from "node:path";
|
|
24139
24279
|
function ownersDir(configDir, projectKey) {
|
|
24140
|
-
return
|
|
24280
|
+
return join13(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
24141
24281
|
}
|
|
24142
24282
|
function errCode2(err) {
|
|
24143
24283
|
return err.code;
|
|
@@ -24165,10 +24305,10 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
24165
24305
|
const live = [];
|
|
24166
24306
|
for (const name of names) {
|
|
24167
24307
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
24168
|
-
const file2 =
|
|
24308
|
+
const file2 = join13(dir, name);
|
|
24169
24309
|
let text;
|
|
24170
24310
|
try {
|
|
24171
|
-
text =
|
|
24311
|
+
text = readFileSync11(file2, "utf8");
|
|
24172
24312
|
} catch (err) {
|
|
24173
24313
|
if (errCode2(err) === "ENOENT") continue;
|
|
24174
24314
|
throw err;
|
|
@@ -24325,11 +24465,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
24325
24465
|
}
|
|
24326
24466
|
}
|
|
24327
24467
|
function ownServerId(configDir, projectKey) {
|
|
24328
|
-
const dir =
|
|
24468
|
+
const dir = join14(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
24329
24469
|
if (!existsSync12(dir)) return "";
|
|
24330
24470
|
for (const name of readdirSync5(dir)) {
|
|
24331
24471
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
24332
|
-
if (
|
|
24472
|
+
if (readFileSync12(join14(dir, name), "utf8").trim() === String(process.pid)) return basename4(name, OWNER_PID_EXT);
|
|
24333
24473
|
}
|
|
24334
24474
|
return "";
|
|
24335
24475
|
}
|
|
@@ -24339,7 +24479,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
24339
24479
|
const project = ctx.project;
|
|
24340
24480
|
let integrityFailed = false;
|
|
24341
24481
|
const checks = {
|
|
24342
|
-
D1: () => checkVersion({ bundleSha: BUNDLE_SHA, env: buildChildEnv(env), cwd: project.worktree, signal: ctx.signal }),
|
|
24482
|
+
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 }),
|
|
24343
24483
|
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
24344
24484
|
D3: () => checkHostConfig(adapter, env, project.worktree),
|
|
24345
24485
|
D4: () => checkV1Leftovers(adapter.id, requireHomeDir(env), { project: project.worktree, piAgentDir: piAgentDirOf(env, requireHomeDir(env)), claudeDir: claudeDirOf(env, requireHomeDir(env)), codexDir: codexDirOf(env, requireHomeDir(env)), copilotDir: copilotDirOf(env, requireHomeDir(env)), kiroDir: kiroDirOf(env, requireHomeDir(env)), opencodeDir: opencodeDirOf(env, requireHomeDir(env)) }),
|
|
@@ -24381,8 +24521,8 @@ async function handler2(_input, ctx) {
|
|
|
24381
24521
|
const command = `context-mode ${rows.some((r) => r.status === "FAIL") ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
24382
24522
|
const input = { agent: adapter.id, rows, env: reportEnv(process.env), command };
|
|
24383
24523
|
const whole = buildReport(input);
|
|
24384
|
-
const
|
|
24385
|
-
if (
|
|
24524
|
+
const bytes5 = Buffer.byteLength(whole, "utf8");
|
|
24525
|
+
if (bytes5 <= REPORT_CAP) return { text: whole, isError: false, sandboxBytes: bytes5 };
|
|
24386
24526
|
const db = await openDb(ctx.project);
|
|
24387
24527
|
try {
|
|
24388
24528
|
indexText(db, ctx.project, ctx.sessionId, REPORT_SOURCE_LABEL, whole, "text");
|
|
@@ -24390,7 +24530,7 @@ async function handler2(_input, ctx) {
|
|
|
24390
24530
|
closeDb(db);
|
|
24391
24531
|
}
|
|
24392
24532
|
const text = buildReportHead(input);
|
|
24393
|
-
return { text, isError: false, sandboxBytes:
|
|
24533
|
+
return { text, isError: false, sandboxBytes: bytes5 };
|
|
24394
24534
|
}
|
|
24395
24535
|
var ctxDoctor = Object.freeze({
|
|
24396
24536
|
name: "ctx_doctor",
|
|
@@ -24404,7 +24544,7 @@ var ctxDoctor = Object.freeze({
|
|
|
24404
24544
|
// src/core/tools/execute.ts
|
|
24405
24545
|
import { existsSync as existsSync13, mkdtempSync, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
24406
24546
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24407
|
-
import { dirname as dirname8, join as
|
|
24547
|
+
import { dirname as dirname8, join as join15, parse as parse3, resolve as resolve6 } from "node:path";
|
|
24408
24548
|
|
|
24409
24549
|
// src/core/sandbox/win-build.ts
|
|
24410
24550
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -24514,8 +24654,8 @@ function sourceLabel(code) {
|
|
|
24514
24654
|
const first = nl < 0 ? code : code.slice(0, nl);
|
|
24515
24655
|
return Array.from(TOOL2 + ":" + first).slice(0, SOURCE_LABEL_MAX_CHARS).join("");
|
|
24516
24656
|
}
|
|
24517
|
-
function moreReserve(intent,
|
|
24518
|
-
return Buffer.byteLength(moreLine2(intent,
|
|
24657
|
+
function moreReserve(intent, label2) {
|
|
24658
|
+
return Buffer.byteLength(moreLine2(intent, label2), "utf8");
|
|
24519
24659
|
}
|
|
24520
24660
|
function spawnFailed(argv0, cwd) {
|
|
24521
24661
|
return new CtxError("SPAWN_FAILED", { detail: argv0 + " gave no exit code in " + cwd }).toLine();
|
|
@@ -24532,12 +24672,12 @@ async function finish(input, ctx, r, exitCode, journal) {
|
|
|
24532
24672
|
if (intent === "" && fits) {
|
|
24533
24673
|
return { text: direct, isError, sandboxBytes: fullBytes, journal };
|
|
24534
24674
|
}
|
|
24535
|
-
const
|
|
24536
|
-
const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent,
|
|
24675
|
+
const label2 = sourceLabel(input.code);
|
|
24676
|
+
const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent, label2);
|
|
24537
24677
|
const db = await openDb(ctx.project);
|
|
24538
24678
|
let picked;
|
|
24539
24679
|
try {
|
|
24540
|
-
const { sourceId } = indexText(db, ctx.project, ctx.sessionId,
|
|
24680
|
+
const { sourceId } = indexText(db, ctx.project, ctx.sessionId, label2, combined, "text");
|
|
24541
24681
|
picked = selectChunks(db, sourceId, intent, budget);
|
|
24542
24682
|
} finally {
|
|
24543
24683
|
closeDb(db);
|
|
@@ -24569,8 +24709,8 @@ async function handler3(raw, ctx) {
|
|
|
24569
24709
|
if (takesDashC(input.language, runtime)) {
|
|
24570
24710
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
24571
24711
|
} else {
|
|
24572
|
-
tmpDir = mkdtempSync(
|
|
24573
|
-
const file2 =
|
|
24712
|
+
tmpDir = mkdtempSync(join15(tmpdir2(), TMP_PREFIX));
|
|
24713
|
+
const file2 = join15(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
24574
24714
|
writeFileSync3(file2, scriptText(input.language, input.code), "utf8");
|
|
24575
24715
|
argv = scriptArgv(input.language, runtime, file2);
|
|
24576
24716
|
}
|
|
@@ -24605,12 +24745,12 @@ var ctxExecute = {
|
|
|
24605
24745
|
};
|
|
24606
24746
|
|
|
24607
24747
|
// src/core/tools/index.ts
|
|
24608
|
-
import { existsSync as existsSync14, readFileSync as
|
|
24609
|
-
import { dirname as dirname9, extname, join as
|
|
24748
|
+
import { existsSync as existsSync14, readFileSync as readFileSync14, statSync as statSync7 } from "node:fs";
|
|
24749
|
+
import { dirname as dirname9, extname, join as join17, relative as relative3, resolve as resolve7 } from "node:path";
|
|
24610
24750
|
|
|
24611
24751
|
// src/core/index/walk.ts
|
|
24612
|
-
import { readdirSync as readdirSync6, readFileSync as
|
|
24613
|
-
import { join as
|
|
24752
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync13, realpathSync as realpathSync8, statSync as statSync6 } from "node:fs";
|
|
24753
|
+
import { join as join16 } from "node:path";
|
|
24614
24754
|
var GITIGNORE = ".gitignore";
|
|
24615
24755
|
var GIT_DIR = ".git";
|
|
24616
24756
|
function walkDir(root, containmentRoot) {
|
|
@@ -24619,7 +24759,7 @@ function walkDir(root, containmentRoot) {
|
|
|
24619
24759
|
const found = [];
|
|
24620
24760
|
visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
|
|
24621
24761
|
found.sort(compareFound);
|
|
24622
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
24762
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join16(...f.dir, f.name) }));
|
|
24623
24763
|
}
|
|
24624
24764
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
24625
24765
|
let entries;
|
|
@@ -24628,10 +24768,10 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
24628
24768
|
} catch {
|
|
24629
24769
|
return;
|
|
24630
24770
|
}
|
|
24631
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
24771
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join16(abs, GITIGNORE), rel)) : parent;
|
|
24632
24772
|
for (const e of entries) {
|
|
24633
24773
|
if (e.name === GIT_DIR) continue;
|
|
24634
|
-
const path7 =
|
|
24774
|
+
const path7 = join16(abs, e.name);
|
|
24635
24775
|
let isDir = e.isDirectory();
|
|
24636
24776
|
let isFile = e.isFile();
|
|
24637
24777
|
let target = path7;
|
|
@@ -24671,7 +24811,7 @@ function compareFound(a, b) {
|
|
|
24671
24811
|
function readRules(file2, base) {
|
|
24672
24812
|
let body;
|
|
24673
24813
|
try {
|
|
24674
|
-
body =
|
|
24814
|
+
body = readFileSync13(file2, "utf8");
|
|
24675
24815
|
} catch {
|
|
24676
24816
|
return [];
|
|
24677
24817
|
}
|
|
@@ -24981,14 +25121,14 @@ function replaceCodePointXML(codePoint) {
|
|
|
24981
25121
|
|
|
24982
25122
|
// node_modules/entities/dist/internal/decode-shared.js
|
|
24983
25123
|
var BASE91_INVERSE = /* @__PURE__ */ (() => {
|
|
24984
|
-
const
|
|
25124
|
+
const table3 = new Uint8Array(127);
|
|
24985
25125
|
let code = 0;
|
|
24986
25126
|
for (let char = 33; char <= 126; char++) {
|
|
24987
25127
|
if (char !== 34 && char !== 36 && char !== 92) {
|
|
24988
|
-
|
|
25128
|
+
table3[char] = code++;
|
|
24989
25129
|
}
|
|
24990
25130
|
}
|
|
24991
|
-
return
|
|
25131
|
+
return table3;
|
|
24992
25132
|
})();
|
|
24993
25133
|
function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCount, dictSize) {
|
|
24994
25134
|
const base = 91;
|
|
@@ -25006,10 +25146,10 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
25006
25146
|
single.fill(-1, dictSize + dict2AtomCount, slotCount);
|
|
25007
25147
|
const start = new Int32Array(slotCount);
|
|
25008
25148
|
const length = new Int32Array(slotCount);
|
|
25009
|
-
function decodeDelta(
|
|
25149
|
+
function decodeDelta(count2, off) {
|
|
25010
25150
|
let previous = 0;
|
|
25011
25151
|
let slot = off;
|
|
25012
|
-
const end = off +
|
|
25152
|
+
const end = off + count2;
|
|
25013
25153
|
while (slot < end) {
|
|
25014
25154
|
const code = BASE91_INVERSE[input.charCodeAt(pos++)];
|
|
25015
25155
|
if (code < 89) {
|
|
@@ -25032,8 +25172,8 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
25032
25172
|
const references = new Int32Array(ngramCount * 2);
|
|
25033
25173
|
let poolSize = 0;
|
|
25034
25174
|
let ngramIndex = 0;
|
|
25035
|
-
function readNgramReferences(
|
|
25036
|
-
for (let index = 0; index <
|
|
25175
|
+
function readNgramReferences(count2, startSlot) {
|
|
25176
|
+
for (let index = 0; index < count2; index++) {
|
|
25037
25177
|
const slot = startSlot + index;
|
|
25038
25178
|
const a = readSlotCode();
|
|
25039
25179
|
const b = readSlotCode();
|
|
@@ -27980,11 +28120,11 @@ function getAtomFeed(feedRoot) {
|
|
|
27980
28120
|
if (href2) {
|
|
27981
28121
|
entry.link = href2;
|
|
27982
28122
|
}
|
|
27983
|
-
const description =
|
|
28123
|
+
const description = fetch2("summary", children) || fetch2("content", children);
|
|
27984
28124
|
if (description) {
|
|
27985
28125
|
entry.description = description;
|
|
27986
28126
|
}
|
|
27987
|
-
const pubDate =
|
|
28127
|
+
const pubDate = fetch2("updated", children);
|
|
27988
28128
|
if (pubDate) {
|
|
27989
28129
|
entry.pubDate = new Date(pubDate);
|
|
27990
28130
|
}
|
|
@@ -27998,7 +28138,7 @@ function getAtomFeed(feedRoot) {
|
|
|
27998
28138
|
feed.link = href;
|
|
27999
28139
|
}
|
|
28000
28140
|
addConditionally(feed, "description", "subtitle", childs);
|
|
28001
|
-
const updated =
|
|
28141
|
+
const updated = fetch2("updated", childs);
|
|
28002
28142
|
if (updated) {
|
|
28003
28143
|
feed.updated = new Date(updated);
|
|
28004
28144
|
}
|
|
@@ -28017,7 +28157,7 @@ function getRssFeed(feedRoot) {
|
|
|
28017
28157
|
addConditionally(entry, "title", "title", children);
|
|
28018
28158
|
addConditionally(entry, "link", "link", children);
|
|
28019
28159
|
addConditionally(entry, "description", "description", children);
|
|
28020
|
-
const pubDate =
|
|
28160
|
+
const pubDate = fetch2("pubDate", children) || fetch2("dc:date", children);
|
|
28021
28161
|
if (pubDate)
|
|
28022
28162
|
entry.pubDate = new Date(pubDate);
|
|
28023
28163
|
return entry;
|
|
@@ -28026,7 +28166,7 @@ function getRssFeed(feedRoot) {
|
|
|
28026
28166
|
addConditionally(feed, "title", "title", childs);
|
|
28027
28167
|
addConditionally(feed, "link", "link", childs);
|
|
28028
28168
|
addConditionally(feed, "description", "description", childs);
|
|
28029
|
-
const updated =
|
|
28169
|
+
const updated = fetch2("lastBuildDate", childs);
|
|
28030
28170
|
if (updated) {
|
|
28031
28171
|
feed.updated = new Date(updated);
|
|
28032
28172
|
}
|
|
@@ -28070,11 +28210,11 @@ function getMediaElements(where) {
|
|
|
28070
28210
|
function getOneElement(tagName, node) {
|
|
28071
28211
|
return getElementsByTagName(tagName, node, true, 1)[0];
|
|
28072
28212
|
}
|
|
28073
|
-
function
|
|
28213
|
+
function fetch2(tagName, where, recurse = false) {
|
|
28074
28214
|
return textContent(getElementsByTagName(tagName, where, recurse, 1)).trim();
|
|
28075
28215
|
}
|
|
28076
28216
|
function addConditionally(object2, property, tagName, where, recurse = false) {
|
|
28077
|
-
const value =
|
|
28217
|
+
const value = fetch2(tagName, where, recurse);
|
|
28078
28218
|
if (value)
|
|
28079
28219
|
object2[property] = value;
|
|
28080
28220
|
}
|
|
@@ -28741,8 +28881,8 @@ var EXT_KIND = Object.freeze({ ".md": "md", ".html": "html", ".htm": "html" });
|
|
|
28741
28881
|
var TYPE_KIND = Object.freeze({ "text/html": "html", "text/markdown": "md" });
|
|
28742
28882
|
var DEFAULT_CONTENT_LABEL = "content";
|
|
28743
28883
|
var utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
28744
|
-
function userLabel(
|
|
28745
|
-
return
|
|
28884
|
+
function userLabel(label2) {
|
|
28885
|
+
return label2 === DECISION_SOURCE ? DECISION_USER_LABEL : label2;
|
|
28746
28886
|
}
|
|
28747
28887
|
function kindOfPath(p) {
|
|
28748
28888
|
return EXT_KIND[extname(p).toLowerCase()] ?? "text";
|
|
@@ -28754,7 +28894,7 @@ function kindOfType(contentType) {
|
|
|
28754
28894
|
}
|
|
28755
28895
|
function readUtf8(absPath) {
|
|
28756
28896
|
try {
|
|
28757
|
-
return utf8.decode(
|
|
28897
|
+
return utf8.decode(readFileSync14(absPath));
|
|
28758
28898
|
} catch {
|
|
28759
28899
|
return void 0;
|
|
28760
28900
|
}
|
|
@@ -28772,7 +28912,7 @@ function pathItems(input, project) {
|
|
|
28772
28912
|
if (statSync7(abs).isDirectory()) {
|
|
28773
28913
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
28774
28914
|
sourceKind: "path",
|
|
28775
|
-
label: pathLabel(
|
|
28915
|
+
label: pathLabel(join17(base, f.relPath)),
|
|
28776
28916
|
kind: kindOfPath(f.relPath),
|
|
28777
28917
|
read: () => readUtf8(f.absPath)
|
|
28778
28918
|
}));
|
|
@@ -28782,9 +28922,9 @@ function pathItems(input, project) {
|
|
|
28782
28922
|
async function itemsOf(input, ctx) {
|
|
28783
28923
|
if (input.content !== void 0) {
|
|
28784
28924
|
const text2 = input.content;
|
|
28785
|
-
const
|
|
28925
|
+
const label3 = input.source ?? DEFAULT_CONTENT_LABEL;
|
|
28786
28926
|
const kind = hasMdStructure(text2) ? "md" : "text";
|
|
28787
|
-
return { items: [{ sourceKind: "content", label:
|
|
28927
|
+
return { items: [{ sourceKind: "content", label: label3, kind, read: () => text2 }], from: label3 };
|
|
28788
28928
|
}
|
|
28789
28929
|
if (input.path !== void 0) {
|
|
28790
28930
|
const items = pathItems({ ...input, path: input.path }, ctx.project);
|
|
@@ -28792,8 +28932,8 @@ async function itemsOf(input, ctx) {
|
|
|
28792
28932
|
}
|
|
28793
28933
|
const res = await safeFetch(input.url ?? "", AbortSignal.any([ctx.signal, AbortSignal.timeout(EXEC_TIMEOUT_MS)]));
|
|
28794
28934
|
const text = res.body.toString("utf8");
|
|
28795
|
-
const
|
|
28796
|
-
return { items: [{ sourceKind: "url", label, kind: kindOfType(res.contentType), read: () => text, base:
|
|
28935
|
+
const label2 = res.finalUrl;
|
|
28936
|
+
return { items: [{ sourceKind: "url", label: label2, kind: kindOfType(res.contentType), read: () => text, base: label2 }], from: label2 };
|
|
28797
28937
|
}
|
|
28798
28938
|
async function handler4(input, ctx) {
|
|
28799
28939
|
const given = INPUT_FIELDS.filter((f) => input[f] !== void 0);
|
|
@@ -28805,14 +28945,14 @@ async function handler4(input, ctx) {
|
|
|
28805
28945
|
const db = await openDb(ctx.project);
|
|
28806
28946
|
let sources = 0;
|
|
28807
28947
|
let chunks = 0;
|
|
28808
|
-
let
|
|
28948
|
+
let bytes5 = 0;
|
|
28809
28949
|
let lastId = 0;
|
|
28810
28950
|
const notes = [];
|
|
28811
28951
|
try {
|
|
28812
28952
|
for (const it of items) {
|
|
28813
28953
|
const text = it.read();
|
|
28814
28954
|
if (text === void 0) continue;
|
|
28815
|
-
|
|
28955
|
+
bytes5 += Buffer.byteLength(text, "utf8");
|
|
28816
28956
|
if (it.kind === "html") {
|
|
28817
28957
|
let readable;
|
|
28818
28958
|
try {
|
|
@@ -28849,7 +28989,7 @@ async function handler4(input, ctx) {
|
|
|
28849
28989
|
return {
|
|
28850
28990
|
text: capBytes(line, OUTPUT_CAP).text,
|
|
28851
28991
|
isError: false,
|
|
28852
|
-
sandboxBytes:
|
|
28992
|
+
sandboxBytes: bytes5,
|
|
28853
28993
|
journal: { kind: "index", key: from, path: from, exit_code: null }
|
|
28854
28994
|
};
|
|
28855
28995
|
} catch (err) {
|
|
@@ -28889,8 +29029,8 @@ function purgeScope(db, scope, input) {
|
|
|
28889
29029
|
const raw = db.raw;
|
|
28890
29030
|
if (scope === "session") return changes(raw, "DELETE FROM events WHERE session_id = ?", input.session);
|
|
28891
29031
|
if (scope === "source") {
|
|
28892
|
-
const
|
|
28893
|
-
return deleteChunkRows(raw, { label }) + changes(raw, "DELETE FROM sources WHERE label = ?",
|
|
29032
|
+
const label2 = storedLabel(db, input.source);
|
|
29033
|
+
return deleteChunkRows(raw, { label: label2 }) + changes(raw, "DELETE FROM sources WHERE label = ?", label2);
|
|
28894
29034
|
}
|
|
28895
29035
|
const chunks = deleteChunkRows(raw, "all");
|
|
28896
29036
|
return changes(raw, "DELETE FROM events") + chunks + changes(raw, "DELETE FROM sources");
|
|
@@ -28972,14 +29112,40 @@ var ctxResume = Object.freeze({
|
|
|
28972
29112
|
var ctxStatsSchema = external_exports.object({}, {
|
|
28973
29113
|
error: (issue2) => issue2.code === "unrecognized_keys" ? STATS_UNKNOWN_FIELD_LINE : void 0
|
|
28974
29114
|
}).strict();
|
|
28975
|
-
var
|
|
29115
|
+
var CALLS = "tool IS NOT NULL AND kind <> 'cost' AND tool <> 'ctx_stats'";
|
|
29116
|
+
var GROUPS = `SELECT session_id, agent, COUNT(*) AS calls, COALESCE(SUM(sandbox_bytes), 0) AS produced, COALESCE(SUM(returned_bytes), 0) AS returned FROM events WHERE ${CALLS} GROUP BY session_id, agent ORDER BY agent, session_id`;
|
|
29117
|
+
var TOOLS = `SELECT tool, COUNT(*) AS calls, COALESCE(SUM(sandbox_bytes), 0) AS produced, COALESCE(SUM(returned_bytes), 0) AS returned FROM events WHERE ${CALLS} GROUP BY tool`;
|
|
29118
|
+
var KINDS = "SELECT kind, COALESCE(SUM(session_id = ?), 0) AS s, COUNT(*) AS p FROM events WHERE kind <> 'cost' AND (tool IS NULL OR tool <> 'ctx_stats') GROUP BY kind";
|
|
29119
|
+
var META = `SELECT COUNT(DISTINCT session_id) AS sessions, COUNT(DISTINCT agent) AS agents, COUNT(DISTINCT created_at / ${MS_PER_DAY}) AS days FROM events WHERE ${CALLS}`;
|
|
29120
|
+
var SPAN = "SELECT COALESCE(MAX(created_at) - MIN(created_at), 0) AS span FROM events WHERE session_id = ? AND kind <> 'cost'";
|
|
29121
|
+
var SOURCES = "SELECT COUNT(*) AS n, COALESCE(SUM(chunk_count), 0) AS chunks, COALESCE(SUM(bytes_total), 0) AS bytes FROM sources";
|
|
28976
29122
|
var EMPTY5 = Object.freeze({ calls: 0, produced: 0, returned: 0, saved: 0 });
|
|
28977
|
-
function
|
|
28978
|
-
|
|
28979
|
-
|
|
28980
|
-
|
|
28981
|
-
|
|
28982
|
-
|
|
29123
|
+
function totals(r) {
|
|
29124
|
+
const produced = Number(r.produced);
|
|
29125
|
+
const returned = Number(r.returned);
|
|
29126
|
+
return { calls: Number(r.calls), produced, returned, saved: Math.max(0, produced - returned) };
|
|
29127
|
+
}
|
|
29128
|
+
function readFacts(raw, sessionId) {
|
|
29129
|
+
const groups = raw.prepare(GROUPS).all().map((r) => ({ session: String(r.session_id), agent: String(r.agent), ...totals(r) }));
|
|
29130
|
+
const tools = raw.prepare(TOOLS).all().map((r) => ({ name: String(r.tool), ...totals(r) }));
|
|
29131
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
29132
|
+
for (const r of raw.prepare(KINDS).all(sessionId)) kinds.set(String(r.kind), { session: Number(r.s), project: Number(r.p) });
|
|
29133
|
+
const meta = raw.prepare(META).get();
|
|
29134
|
+
const span2 = Number(raw.prepare(SPAN).get(sessionId).span);
|
|
29135
|
+
const src = raw.prepare(SOURCES).get();
|
|
29136
|
+
const pages = raw.prepare("PRAGMA page_count").get();
|
|
29137
|
+
const size = raw.prepare("PRAGMA page_size").get();
|
|
29138
|
+
return {
|
|
29139
|
+
groups,
|
|
29140
|
+
tools,
|
|
29141
|
+
kinds,
|
|
29142
|
+
span: span2,
|
|
29143
|
+
sessions: Number(meta.sessions),
|
|
29144
|
+
agents: Number(meta.agents),
|
|
29145
|
+
days: Number(meta.days),
|
|
29146
|
+
sources: { count: Number(src.n), chunks: Number(src.chunks), bytes: Number(src.bytes) },
|
|
29147
|
+
dbBytes: Number(pages.page_count) * Number(size.page_size)
|
|
29148
|
+
};
|
|
28983
29149
|
}
|
|
28984
29150
|
function sum(groups) {
|
|
28985
29151
|
return groups.reduce((t, g) => ({
|
|
@@ -28993,23 +29159,123 @@ function reductionPct(t) {
|
|
|
28993
29159
|
if (t.calls === 0) return 0;
|
|
28994
29160
|
return Number((t.saved * PERCENT_SCALE / Math.max(1, t.produced)).toFixed(1));
|
|
28995
29161
|
}
|
|
28996
|
-
function tableRow(
|
|
29162
|
+
function tableRow(label2, t) {
|
|
28997
29163
|
const last2 = t.calls === 0 ? STATS_NO_DATA : String(reductionPct(t));
|
|
28998
|
-
return "| " + [
|
|
29164
|
+
return "| " + [label2, t.produced + " B", t.returned + " B", t.saved + " B", last2].join(" | ") + " |";
|
|
29165
|
+
}
|
|
29166
|
+
var UNITS = ["KB", "MB", "GB", "TB"];
|
|
29167
|
+
var LABEL_W = STATS_LABEL_W;
|
|
29168
|
+
var NUM_W = STATS_NUM_W;
|
|
29169
|
+
var PCT_W = STATS_PCT_W;
|
|
29170
|
+
var INT = new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 });
|
|
29171
|
+
function int2(n) {
|
|
29172
|
+
return INT.format(Math.round(n));
|
|
29173
|
+
}
|
|
29174
|
+
function count(n) {
|
|
29175
|
+
return n < STATS_MILLION ? int2(n) : (n / STATS_MILLION).toFixed(1) + "M";
|
|
29176
|
+
}
|
|
29177
|
+
function bytes4(n) {
|
|
29178
|
+
if (n < STATS_KIB) return int2(n) + " B";
|
|
29179
|
+
let v = n / STATS_KIB;
|
|
29180
|
+
let u = 0;
|
|
29181
|
+
while (v >= STATS_KIB && u < UNITS.length - 1) {
|
|
29182
|
+
v /= STATS_KIB;
|
|
29183
|
+
u++;
|
|
29184
|
+
}
|
|
29185
|
+
return v.toFixed(1) + " " + UNITS[u];
|
|
29186
|
+
}
|
|
29187
|
+
function pct(t) {
|
|
29188
|
+
return (t.saved * PERCENT_SCALE / Math.max(1, t.produced)).toFixed(1) + "%";
|
|
29189
|
+
}
|
|
29190
|
+
function bar(value, max, width, fill = "\u2588", rest = "") {
|
|
29191
|
+
const n = value <= 0 || max <= 0 ? 0 : Math.min(width, Math.max(1, Math.round(value / max * width)));
|
|
29192
|
+
return fill.repeat(n) + rest.repeat(width - n);
|
|
29193
|
+
}
|
|
29194
|
+
function label(s) {
|
|
29195
|
+
const chars = [...s];
|
|
29196
|
+
return (chars.length > STATS_LABEL_MAX ? chars.slice(0, STATS_LABEL_MAX - 1).join("") + "\u2026" : s).padEnd(LABEL_W);
|
|
29197
|
+
}
|
|
29198
|
+
function span(ms) {
|
|
29199
|
+
const min = Math.floor(ms / STATS_MS_PER_MINUTE);
|
|
29200
|
+
if (min < 1) return "<1m";
|
|
29201
|
+
if (min < STATS_MINUTES_PER_HOUR) return min + "m";
|
|
29202
|
+
const h = Math.floor(min / STATS_MINUTES_PER_HOUR);
|
|
29203
|
+
return h < STATS_HOURS_PER_DAY ? `${h}h ${String(min % STATS_MINUTES_PER_HOUR).padStart(STATS_CLOCK_DIGITS, "0")}m` : `${Math.floor(h / STATS_HOURS_PER_DAY)}d ${h % STATS_HOURS_PER_DAY}h`;
|
|
29204
|
+
}
|
|
29205
|
+
function plural(n, word) {
|
|
29206
|
+
return `${int2(n)} ${word}${n === 1 ? "" : "s"}`;
|
|
29207
|
+
}
|
|
29208
|
+
function table2(title, rows) {
|
|
29209
|
+
const max = Math.max(0, ...rows.map((r) => r.saved));
|
|
29210
|
+
const head = " " + title.padEnd(LABEL_W) + "Calls".padStart(STATS_CALLS_W) + "Produced".padStart(NUM_W) + "Returned".padStart(NUM_W) + "Saved".padStart(NUM_W) + "%".padStart(PCT_W);
|
|
29211
|
+
return [head, ...rows.map((r) => (" " + label(r.name) + count(r.calls).padStart(STATS_CALLS_W) + bytes4(r.produced).padStart(NUM_W) + bytes4(r.returned).padStart(NUM_W) + bytes4(r.saved).padStart(NUM_W) + pct(r).padStart(PCT_W) + " " + bar(r.saved, max, STATS_ROW_BAR)).trimEnd())];
|
|
29212
|
+
}
|
|
29213
|
+
function bySaved(a, b) {
|
|
29214
|
+
return b.saved - a.saved || b.produced - a.produced || a.returned - b.returned || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
29215
|
+
}
|
|
29216
|
+
function toolRows(tools) {
|
|
29217
|
+
const named = tools.map((t) => ({ ...t, name: t.name.startsWith("ctx_") ? t.name : "hook " + t.name })).sort(bySaved);
|
|
29218
|
+
if (named.length <= STATS_MAX_TOOL_ROWS) return named;
|
|
29219
|
+
const rest = named.slice(STATS_MAX_TOOL_ROWS - 1);
|
|
29220
|
+
return [...named.slice(0, STATS_MAX_TOOL_ROWS - 1), { name: `other (${rest.length} tools)`, ...sum(rest) }];
|
|
29221
|
+
}
|
|
29222
|
+
function fit(line) {
|
|
29223
|
+
const chars = [...line];
|
|
29224
|
+
return chars.length <= STATS_WIDTH ? line : chars.slice(0, STATS_WIDTH - 1).join("") + "\u2026";
|
|
29225
|
+
}
|
|
29226
|
+
function report(f, sessionId, agent) {
|
|
29227
|
+
const head = [STATS_REPORT_TITLE, "\u2500".repeat(STATS_WIDTH), ""];
|
|
29228
|
+
const project = sum(f.groups);
|
|
29229
|
+
if (project.calls === 0) return [...head, ...STATS_EMPTY_LINES].join("\n");
|
|
29230
|
+
const session = sum(f.groups.filter((g) => g.session === sessionId));
|
|
29231
|
+
const [scopeName, focus] = session.calls > 0 ? ["This session", session] : ["This project", project];
|
|
29232
|
+
const top = Math.max(focus.produced, focus.returned);
|
|
29233
|
+
const extra = session.calls > 0 ? ` \xB7 ${span(f.span)} active` : "";
|
|
29234
|
+
const lines = [
|
|
29235
|
+
...head,
|
|
29236
|
+
`${scopeName} \xB7 ${plural(focus.calls, "call")}${extra}`,
|
|
29237
|
+
" " + "Without context-mode".padEnd(LABEL_W) + "|" + bar(focus.produced, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.produced).padStart(NUM_W),
|
|
29238
|
+
" " + "With context-mode".padEnd(LABEL_W) + "|" + bar(focus.returned, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.returned).padStart(NUM_W),
|
|
29239
|
+
` ${bytes4(focus.saved)} saved (${pct(focus)}) \xB7 about ${int2(focus.saved / STATS_BYTES_PER_TOKEN)} tokens kept out of the chat`,
|
|
29240
|
+
"",
|
|
29241
|
+
...table2("Scope", [{ name: "session", ...session }, { name: "project", ...project }, { name: "all-time", ...project }]),
|
|
29242
|
+
"",
|
|
29243
|
+
"Where the savings came from (this project)",
|
|
29244
|
+
...table2("Tool", toolRows(f.tools)),
|
|
29245
|
+
""
|
|
29246
|
+
];
|
|
29247
|
+
const agents = /* @__PURE__ */ new Map();
|
|
29248
|
+
for (const g of f.groups) agents.set(g.agent, sum([agents.get(g.agent) ?? EMPTY5, g]));
|
|
29249
|
+
if (!agents.has(agent)) agents.set(agent, EMPTY5);
|
|
29250
|
+
lines.push(...table2("Agent", [...agents].map(([name, t]) => ({ name, ...t })).sort(bySaved)), "");
|
|
29251
|
+
const maxKind = Math.max(0, ...[...f.kinds.values()].map((k) => k.project));
|
|
29252
|
+
lines.push("Kept in the session journal", " " + "Journal".padEnd(LABEL_W) + "Session".padStart(STATS_KIND_W) + "Project".padStart(STATS_KIND_W));
|
|
29253
|
+
for (const [kind, name] of STATS_KIND_LABELS) {
|
|
29254
|
+
const k = f.kinds.get(kind) ?? { session: 0, project: 0 };
|
|
29255
|
+
lines.push((" " + label(name) + int2(k.session).padStart(STATS_KIND_W) + int2(k.project).padStart(STATS_KIND_W) + " " + bar(k.project, maxKind, STATS_KIND_BAR)).trimEnd());
|
|
29256
|
+
}
|
|
29257
|
+
lines.push("", ...STATS_JOURNAL_HINTS.map((h) => " " + h), "");
|
|
29258
|
+
lines.push(
|
|
29259
|
+
" " + "Indexed sources".padEnd(LABEL_W) + `${int2(f.sources.count)} \xB7 ${plural(f.sources.chunks, "chunk")} \xB7 ${bytes4(f.sources.bytes)} of content`,
|
|
29260
|
+
" " + "Database file".padEnd(LABEL_W) + bytes4(f.dbBytes),
|
|
29261
|
+
" " + "Sessions".padEnd(LABEL_W) + `${int2(f.sessions)} \xB7 agents ${int2(f.agents)} \xB7 active days ${int2(f.days)}`
|
|
29262
|
+
);
|
|
29263
|
+
return lines.map(fit).join("\n");
|
|
28999
29264
|
}
|
|
29000
29265
|
async function handler7(_input, ctx) {
|
|
29001
29266
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
29002
|
-
let
|
|
29267
|
+
let facts;
|
|
29003
29268
|
try {
|
|
29004
|
-
|
|
29269
|
+
facts = readFacts(db.raw, ctx.sessionId);
|
|
29005
29270
|
} finally {
|
|
29006
29271
|
closeDb(db);
|
|
29007
29272
|
}
|
|
29273
|
+
const groups = facts.groups;
|
|
29008
29274
|
const session = sum(groups.filter((g) => g.session === ctx.sessionId));
|
|
29009
29275
|
const project = sum(groups);
|
|
29010
29276
|
const allTime = project;
|
|
29011
29277
|
const agentIds = [.../* @__PURE__ */ new Set([...groups.map((g) => g.agent), ctx.project.agent])].sort();
|
|
29012
|
-
const
|
|
29278
|
+
const mdTable = [
|
|
29013
29279
|
"| " + STATS_COLUMNS.join(" | ") + " |",
|
|
29014
29280
|
"|" + STATS_COLUMNS.map(() => "---").join("|") + "|",
|
|
29015
29281
|
tableRow("session", session),
|
|
@@ -29018,7 +29284,8 @@ async function handler7(_input, ctx) {
|
|
|
29018
29284
|
...agentIds.map((a) => tableRow("agent " + a, sum(groups.filter((g) => g.agent === a))))
|
|
29019
29285
|
].join("\n");
|
|
29020
29286
|
const summary = STATS_SUMMARY(reductionPct(allTime), reductionPct(session));
|
|
29021
|
-
|
|
29287
|
+
const text = summary + "\n\n```text\n" + report(facts, ctx.sessionId, ctx.project.agent) + "\n```\n\n" + mdTable;
|
|
29288
|
+
return { text: capBytes(text, OUTPUT_CAP).text, isError: false, sandboxBytes: 0 };
|
|
29022
29289
|
}
|
|
29023
29290
|
var ctxStats = Object.freeze({
|
|
29024
29291
|
name: "ctx_stats",
|
|
@@ -29030,11 +29297,11 @@ var ctxStats = Object.freeze({
|
|
|
29030
29297
|
|
|
29031
29298
|
// src/core/tools/upgrade.ts
|
|
29032
29299
|
import { existsSync as existsSync20, realpathSync as realpathSync9, rmSync as rmSync9 } from "node:fs";
|
|
29033
|
-
import { basename as basename6, dirname as dirname11, join as
|
|
29300
|
+
import { basename as basename6, dirname as dirname11, join as join23 } from "node:path";
|
|
29034
29301
|
|
|
29035
29302
|
// src/core/ops/host-write.ts
|
|
29036
29303
|
import { copyFileSync, existsSync as existsSync15, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
29037
|
-
import { dirname as dirname10, join as
|
|
29304
|
+
import { dirname as dirname10, join as join18 } from "node:path";
|
|
29038
29305
|
function defaultWrite(file2, text) {
|
|
29039
29306
|
writeFileSync4(file2, text, "utf8");
|
|
29040
29307
|
}
|
|
@@ -29043,14 +29310,14 @@ function hostConfigPath(agent, home, env) {
|
|
|
29043
29310
|
if (own2 !== void 0) return ownMcpFileOf(agent, own2.file, env, home);
|
|
29044
29311
|
switch (agent) {
|
|
29045
29312
|
case "opencode":
|
|
29046
|
-
return
|
|
29313
|
+
return join18(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
29047
29314
|
// D-WIN-OPENCODE-DIR-1
|
|
29048
29315
|
case "pi":
|
|
29049
|
-
return
|
|
29316
|
+
return join18(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
29050
29317
|
case "copilot-cli":
|
|
29051
29318
|
return null;
|
|
29052
29319
|
default:
|
|
29053
|
-
return
|
|
29320
|
+
return join18(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
29054
29321
|
}
|
|
29055
29322
|
}
|
|
29056
29323
|
function cell3(value) {
|
|
@@ -29101,7 +29368,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
29101
29368
|
|
|
29102
29369
|
// src/core/ops/plugin-swap.ts
|
|
29103
29370
|
import { existsSync as existsSync16, lstatSync, readdirSync as readdirSync7, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
29104
|
-
import { basename as basename5, join as
|
|
29371
|
+
import { basename as basename5, join as join19, win32 as win322 } from "node:path";
|
|
29105
29372
|
function linkTarget(path7, win) {
|
|
29106
29373
|
if (!isLink(path7)) return null;
|
|
29107
29374
|
const target = readlinkSync(path7);
|
|
@@ -29120,11 +29387,11 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
29120
29387
|
else renameWithRetry(old, link, opts);
|
|
29121
29388
|
}
|
|
29122
29389
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
29123
|
-
const next =
|
|
29390
|
+
const next = join19(agentDir, sha);
|
|
29124
29391
|
if (!existsSync16(next) || !lstatSync(next).isDirectory()) {
|
|
29125
29392
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename5(agentDir), path: next });
|
|
29126
29393
|
}
|
|
29127
|
-
const link =
|
|
29394
|
+
const link = join19(agentDir, PLUGIN_CURRENT_LINK);
|
|
29128
29395
|
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
29129
29396
|
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
29130
29397
|
settleLinks(link, tmp, old, opts);
|
|
@@ -29139,15 +29406,15 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
29139
29406
|
if (before !== null) unlinkSync2(old);
|
|
29140
29407
|
const keep = /* @__PURE__ */ new Set([sha]);
|
|
29141
29408
|
if (before !== null) keep.add(before);
|
|
29142
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) =>
|
|
29409
|
+
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join19(agentDir, name));
|
|
29143
29410
|
for (const dir of removed) rmSync5(dir, { recursive: true, force: true });
|
|
29144
|
-
const previous = before !== null && existsSync16(
|
|
29411
|
+
const previous = before !== null && existsSync16(join19(agentDir, before)) ? join19(agentDir, before) : null;
|
|
29145
29412
|
return { current: next, previous, removed };
|
|
29146
29413
|
}
|
|
29147
29414
|
|
|
29148
29415
|
// src/core/ops/release-fetch.ts
|
|
29149
29416
|
import { existsSync as existsSync17, mkdirSync as mkdirSync6, rmSync as rmSync6 } from "node:fs";
|
|
29150
|
-
import { join as
|
|
29417
|
+
import { join as join20 } from "node:path";
|
|
29151
29418
|
function failed(r) {
|
|
29152
29419
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
29153
29420
|
const status = r.killed ?? String(r.exitCode);
|
|
@@ -29159,9 +29426,9 @@ async function git2(bin, args, cwd, env, signal) {
|
|
|
29159
29426
|
return r.stdout.toString().trim();
|
|
29160
29427
|
}
|
|
29161
29428
|
async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
29162
|
-
const agentDir =
|
|
29429
|
+
const agentDir = join20(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
29163
29430
|
mkdirSync6(agentDir, { recursive: true });
|
|
29164
|
-
const fetchDir =
|
|
29431
|
+
const fetchDir = join20(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
29165
29432
|
rmSync6(fetchDir, { recursive: true, force: true });
|
|
29166
29433
|
const gitBin = findRuntime(GIT_BIN, env);
|
|
29167
29434
|
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -29169,7 +29436,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
29169
29436
|
try {
|
|
29170
29437
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url2, fetchDir], agentDir, childEnv, signal);
|
|
29171
29438
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
29172
|
-
const dir =
|
|
29439
|
+
const dir = join20(agentDir, sha);
|
|
29173
29440
|
if (existsSync17(dir)) rmSync6(fetchDir, { recursive: true, force: true });
|
|
29174
29441
|
else renameWithRetry(fetchDir, dir, opts);
|
|
29175
29442
|
return { sha, dir };
|
|
@@ -29181,14 +29448,14 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
29181
29448
|
|
|
29182
29449
|
// src/core/ops/uninstall.ts
|
|
29183
29450
|
import { existsSync as existsSync18, readdirSync as readdirSync8, rmSync as rmSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
29184
|
-
import { join as
|
|
29451
|
+
import { join as join21 } from "node:path";
|
|
29185
29452
|
function row2(area, before, after) {
|
|
29186
29453
|
return { area, before, after };
|
|
29187
29454
|
}
|
|
29188
29455
|
function stopServers(configDir, projectKey) {
|
|
29189
29456
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
29190
|
-
const dir =
|
|
29191
|
-
for (const serverId of stopped) writeFileSync5(
|
|
29457
|
+
const dir = join21(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
29458
|
+
for (const serverId of stopped) writeFileSync5(join21(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
29192
29459
|
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 };
|
|
29193
29460
|
}
|
|
29194
29461
|
function rootOrNull(adapter, env) {
|
|
@@ -29206,14 +29473,14 @@ function removeCache(adapter, env, configDir) {
|
|
|
29206
29473
|
const root = rootOrNull(adapter, env);
|
|
29207
29474
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
29208
29475
|
if (adapter.installMode === "marketplace") {
|
|
29209
|
-
const cache =
|
|
29476
|
+
const cache = join21(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
29210
29477
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
29211
29478
|
}
|
|
29212
29479
|
rmSync7(root, { recursive: true, force: true });
|
|
29213
29480
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
29214
29481
|
}
|
|
29215
29482
|
case "plugin": {
|
|
29216
|
-
const agentDir =
|
|
29483
|
+
const agentDir = join21(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
29217
29484
|
if (!existsSync18(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
29218
29485
|
rmSync7(agentDir, { recursive: true, force: true });
|
|
29219
29486
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
@@ -29259,7 +29526,7 @@ function ownEntries(agent, env) {
|
|
|
29259
29526
|
}
|
|
29260
29527
|
if (agent === "opencode") {
|
|
29261
29528
|
return [{
|
|
29262
|
-
file:
|
|
29529
|
+
file: join21(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
29263
29530
|
// D-WIN-OPENCODE-DIR-1
|
|
29264
29531
|
key: OPENCODE_PLUGIN_KEY,
|
|
29265
29532
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -29270,7 +29537,7 @@ function ownEntries(agent, env) {
|
|
|
29270
29537
|
if (agent === "pi") {
|
|
29271
29538
|
const agentDir = piAgentDirOf(env, home);
|
|
29272
29539
|
return [{
|
|
29273
|
-
file:
|
|
29540
|
+
file: join21(agentDir, SETTINGS_FILE),
|
|
29274
29541
|
key: PI_PACKAGES_KEY,
|
|
29275
29542
|
shown: PI_PACKAGES_KEY,
|
|
29276
29543
|
has: (v) => Array.isArray(v) && v.some((x) => piSource(x) === PI_GIT_PACKAGE),
|
|
@@ -29292,12 +29559,12 @@ function removeOwnEntries(agent, env) {
|
|
|
29292
29559
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
29293
29560
|
}
|
|
29294
29561
|
function removeProjectData(configDir, projectKey) {
|
|
29295
|
-
const projects =
|
|
29296
|
-
const dir =
|
|
29562
|
+
const projects = join21(configDir, PROJECTS_DIR_NAME);
|
|
29563
|
+
const dir = join21(projects, projectKey);
|
|
29297
29564
|
if (!existsSync18(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
29298
29565
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
29299
29566
|
for (const name of readdirSync8(dir)) {
|
|
29300
|
-
if (name !== OWNERS_DIR_NAME) rmSync7(
|
|
29567
|
+
if (name !== OWNERS_DIR_NAME) rmSync7(join21(dir, name), { recursive: true, force: true });
|
|
29301
29568
|
}
|
|
29302
29569
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
29303
29570
|
}
|
|
@@ -29305,12 +29572,12 @@ function runUninstall(input) {
|
|
|
29305
29572
|
const configDir = resolveConfigDir(input.env);
|
|
29306
29573
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
29307
29574
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
29308
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
29575
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join21(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
29309
29576
|
return { rows, stopped: stop.stopped };
|
|
29310
29577
|
}
|
|
29311
29578
|
|
|
29312
29579
|
// src/core/ops/v1-remove.ts
|
|
29313
|
-
import { copyFileSync as copyFileSync2, existsSync as existsSync19, readFileSync as
|
|
29580
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync19, readFileSync as readFileSync15, rmSync as rmSync8 } from "node:fs";
|
|
29314
29581
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
29315
29582
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
29316
29583
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -29329,13 +29596,13 @@ function keepOriginal(file2, kept, undo) {
|
|
|
29329
29596
|
undo.push({ trash, target: file2 });
|
|
29330
29597
|
}
|
|
29331
29598
|
function cutTomlTable(text, header) {
|
|
29332
|
-
let
|
|
29599
|
+
let span2;
|
|
29333
29600
|
try {
|
|
29334
|
-
|
|
29601
|
+
span2 = tomlTableSpans(text).find((t) => t.header.trim() === header);
|
|
29335
29602
|
} catch {
|
|
29336
29603
|
return null;
|
|
29337
29604
|
}
|
|
29338
|
-
return
|
|
29605
|
+
return span2 === void 0 ? null : text.slice(0, span2.start) + text.slice(span2.end);
|
|
29339
29606
|
}
|
|
29340
29607
|
function writeAtomic(file2, text) {
|
|
29341
29608
|
atomicWriteFile(file2, text);
|
|
@@ -29354,8 +29621,8 @@ function locate(doc, path7) {
|
|
|
29354
29621
|
return null;
|
|
29355
29622
|
}
|
|
29356
29623
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
29357
|
-
const layout = hostLayout(
|
|
29358
|
-
const text = hostText(
|
|
29624
|
+
const layout = hostLayout(readFileSync15(file2, "utf8"));
|
|
29625
|
+
const text = hostText(readFileSync15(file2, "utf8"));
|
|
29359
29626
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
29360
29627
|
const hit = /* @__PURE__ */ new Set();
|
|
29361
29628
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -29403,7 +29670,7 @@ function removeV1(agent, findings) {
|
|
|
29403
29670
|
continue;
|
|
29404
29671
|
}
|
|
29405
29672
|
if (file2.endsWith(TOML_EXT)) {
|
|
29406
|
-
const rawToml =
|
|
29673
|
+
const rawToml = readFileSync15(file2, "utf8");
|
|
29407
29674
|
const tomlLayout = hostLayout(rawToml);
|
|
29408
29675
|
let text = hostText(rawToml);
|
|
29409
29676
|
for (const f of list4) {
|
|
@@ -29441,8 +29708,8 @@ function removeV1(agent, findings) {
|
|
|
29441
29708
|
|
|
29442
29709
|
// src/core/ops/verify-sums.ts
|
|
29443
29710
|
import { createHash as createHash2 } from "node:crypto";
|
|
29444
|
-
import { lstatSync as lstatSync2, readdirSync as readdirSync9, readFileSync as
|
|
29445
|
-
import { join as
|
|
29711
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync9, readFileSync as readFileSync16 } from "node:fs";
|
|
29712
|
+
import { join as join22 } from "node:path";
|
|
29446
29713
|
function mismatch() {
|
|
29447
29714
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
29448
29715
|
}
|
|
@@ -29463,24 +29730,24 @@ function walk3(dir, prefix, out) {
|
|
|
29463
29730
|
for (const entry of readdirSync9(dir, { withFileTypes: true })) {
|
|
29464
29731
|
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
29465
29732
|
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
29466
|
-
const abs =
|
|
29733
|
+
const abs = join22(dir, entry.name);
|
|
29467
29734
|
if (entry.isDirectory()) walk3(abs, rel, out);
|
|
29468
29735
|
else if (entry.isFile()) out.set(rel, abs);
|
|
29469
29736
|
else throw mismatch();
|
|
29470
29737
|
}
|
|
29471
29738
|
}
|
|
29472
29739
|
function verifySums(dir) {
|
|
29473
|
-
const sumsPath =
|
|
29740
|
+
const sumsPath = join22(dir, RELEASE_SUMS_FILE);
|
|
29474
29741
|
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
29475
29742
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
29476
|
-
const sums = parseSums(
|
|
29743
|
+
const sums = parseSums(readFileSync16(sumsPath, "utf8"));
|
|
29477
29744
|
const files = /* @__PURE__ */ new Map();
|
|
29478
29745
|
walk3(dir, "", files);
|
|
29479
29746
|
if (files.size !== sums.size) throw mismatch();
|
|
29480
29747
|
for (const [rel, abs] of files) {
|
|
29481
29748
|
const want = sums.get(rel);
|
|
29482
29749
|
if (want === void 0) throw mismatch();
|
|
29483
|
-
const got = createHash2(SUMS_HASH_ALGORITHM).update(
|
|
29750
|
+
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync16(abs)).digest(HASH_ENCODING);
|
|
29484
29751
|
if (got !== want) throw mismatch();
|
|
29485
29752
|
}
|
|
29486
29753
|
}
|
|
@@ -29508,7 +29775,7 @@ function pluginRootRow(adapter, env) {
|
|
|
29508
29775
|
return root === own2 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own2)];
|
|
29509
29776
|
}
|
|
29510
29777
|
function isCurrent(agentDir, dir) {
|
|
29511
|
-
const link =
|
|
29778
|
+
const link = join23(agentDir, PLUGIN_CURRENT_LINK);
|
|
29512
29779
|
return existsSync20(link) && realpathSync9.native(link) === realpathSync9.native(dir);
|
|
29513
29780
|
}
|
|
29514
29781
|
async function checkout(adapter, deps) {
|
|
@@ -29605,7 +29872,7 @@ function define(name) {
|
|
|
29605
29872
|
handler: built.handler
|
|
29606
29873
|
};
|
|
29607
29874
|
}
|
|
29608
|
-
var
|
|
29875
|
+
var TOOLS2 = Object.freeze(TOOL_ORDER.map(define));
|
|
29609
29876
|
function callExample(tool) {
|
|
29610
29877
|
const a = tool.description.indexOf("`");
|
|
29611
29878
|
const b = tool.description.indexOf("`", a + 1);
|
|
@@ -29649,7 +29916,7 @@ async function setupLegacy(app) {
|
|
|
29649
29916
|
function project() {
|
|
29650
29917
|
return resolveProject(AGENT, { env, argv: process.argv, cwd: cwd ?? "" });
|
|
29651
29918
|
}
|
|
29652
|
-
for (const tool of
|
|
29919
|
+
for (const tool of TOOLS2) {
|
|
29653
29920
|
app.tool(tool.name, {
|
|
29654
29921
|
description: tool.description,
|
|
29655
29922
|
args: tool.schema,
|