context-mode 2.0.0-next.34 → 2.0.0-next.38
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 +395 -112
- package/SHA256SUMS +16 -16
- package/cli.mjs +2 -1
- package/copilot/plugin.json +1 -1
- package/fixtures/hook-roundtrip.json +113 -0
- package/gemini-extension.json +1 -1
- package/hook.mjs +60 -58
- package/opencode/plugin.js +483 -211
- package/package.json +1 -1
- package/pi/index.js +524 -248
- package/qwen-extension.json +1 -1
- package/run.mjs +6 -3
- package/search.mjs +6 -3
- package/server.mjs +508 -232
package/server.mjs
CHANGED
|
@@ -8,7 +8,7 @@ var __export = (target, all) => {
|
|
|
8
8
|
// src/entries/server.ts
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
10
|
import { existsSync as existsSync23, realpathSync as realpathSync12, rmSync as rmSync11 } from "node:fs";
|
|
11
|
-
import { dirname as
|
|
11
|
+
import { dirname as dirname12, join as join24 } from "node:path";
|
|
12
12
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13
13
|
|
|
14
14
|
// node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
@@ -2882,14 +2882,14 @@ var $ZodIntersection = /* @__PURE__ */ $constructor("$ZodIntersection", (inst, d
|
|
|
2882
2882
|
inst._zod.parse = (payload, ctx) => {
|
|
2883
2883
|
const input = payload.value;
|
|
2884
2884
|
const left = def.left._zod.run({ value: input, issues: [] }, ctx);
|
|
2885
|
-
const
|
|
2886
|
-
const async = left instanceof Promise ||
|
|
2885
|
+
const right2 = def.right._zod.run({ value: input, issues: [] }, ctx);
|
|
2886
|
+
const async = left instanceof Promise || right2 instanceof Promise;
|
|
2887
2887
|
if (async) {
|
|
2888
|
-
return Promise.all([left,
|
|
2889
|
-
return handleIntersectionResults(payload, left2,
|
|
2888
|
+
return Promise.all([left, right2]).then(([left2, right3]) => {
|
|
2889
|
+
return handleIntersectionResults(payload, left2, right3);
|
|
2890
2890
|
});
|
|
2891
2891
|
}
|
|
2892
|
-
return handleIntersectionResults(payload, left,
|
|
2892
|
+
return handleIntersectionResults(payload, left, right2);
|
|
2893
2893
|
};
|
|
2894
2894
|
});
|
|
2895
2895
|
function mergeValues(a, b) {
|
|
@@ -2940,7 +2940,7 @@ function mergeValues(a, b) {
|
|
|
2940
2940
|
}
|
|
2941
2941
|
return { valid: false, mergeErrorPath: [] };
|
|
2942
2942
|
}
|
|
2943
|
-
function handleIntersectionResults(result, left,
|
|
2943
|
+
function handleIntersectionResults(result, left, right2) {
|
|
2944
2944
|
const unrecKeys = /* @__PURE__ */ new Map();
|
|
2945
2945
|
let unrecIssue;
|
|
2946
2946
|
const keyIssues = /* @__PURE__ */ new Map();
|
|
@@ -2968,7 +2968,7 @@ function handleIntersectionResults(result, left, right) {
|
|
|
2968
2968
|
if (!collect(iss, "l"))
|
|
2969
2969
|
result.issues.push(iss);
|
|
2970
2970
|
}
|
|
2971
|
-
for (const iss of
|
|
2971
|
+
for (const iss of right2.issues) {
|
|
2972
2972
|
if (!collect(iss, "r"))
|
|
2973
2973
|
result.issues.push(iss);
|
|
2974
2974
|
}
|
|
@@ -2982,7 +2982,7 @@ function handleIntersectionResults(result, left, right) {
|
|
|
2982
2982
|
result.issues.push(keyIssues.get(k));
|
|
2983
2983
|
}
|
|
2984
2984
|
}
|
|
2985
|
-
const merged = mergeValues(left.value,
|
|
2985
|
+
const merged = mergeValues(left.value, right2.value);
|
|
2986
2986
|
if (!merged.valid) {
|
|
2987
2987
|
if (aborted(result))
|
|
2988
2988
|
return result;
|
|
@@ -3372,11 +3372,11 @@ var $ZodPipe = /* @__PURE__ */ $constructor("$ZodPipe", (inst, def) => {
|
|
|
3372
3372
|
defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
|
|
3373
3373
|
inst._zod.parse = (payload, ctx) => {
|
|
3374
3374
|
if (ctx.direction === "backward") {
|
|
3375
|
-
const
|
|
3376
|
-
if (
|
|
3377
|
-
return
|
|
3375
|
+
const right2 = def.out._zod.run(payload, ctx);
|
|
3376
|
+
if (right2 instanceof Promise) {
|
|
3377
|
+
return right2.then((right3) => handlePipeResult(right3, def.in, ctx));
|
|
3378
3378
|
}
|
|
3379
|
-
return handlePipeResult(
|
|
3379
|
+
return handlePipeResult(right2, def.in, ctx);
|
|
3380
3380
|
}
|
|
3381
3381
|
const left = def.in._zod.run(payload, ctx);
|
|
3382
3382
|
if (left instanceof Promise) {
|
|
@@ -6346,11 +6346,11 @@ var ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def
|
|
|
6346
6346
|
ZodType.init(inst, def);
|
|
6347
6347
|
inst._zod.processJSONSchema = (ctx, json2, params) => intersectionProcessor(inst, ctx, json2, params);
|
|
6348
6348
|
});
|
|
6349
|
-
function intersection(left,
|
|
6349
|
+
function intersection(left, right2) {
|
|
6350
6350
|
return new ZodIntersection({
|
|
6351
6351
|
type: "intersection",
|
|
6352
6352
|
left,
|
|
6353
|
-
right
|
|
6353
|
+
right: right2
|
|
6354
6354
|
});
|
|
6355
6355
|
}
|
|
6356
6356
|
var ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
|
|
@@ -10411,14 +10411,14 @@ var $ZodIntersection2 = /* @__PURE__ */ $constructor2("$ZodIntersection", (inst,
|
|
|
10411
10411
|
inst._zod.parse = (payload, ctx) => {
|
|
10412
10412
|
const input = payload.value;
|
|
10413
10413
|
const left = def.left._zod.run({ value: input, issues: [] }, ctx);
|
|
10414
|
-
const
|
|
10415
|
-
const async = left instanceof Promise ||
|
|
10414
|
+
const right2 = def.right._zod.run({ value: input, issues: [] }, ctx);
|
|
10415
|
+
const async = left instanceof Promise || right2 instanceof Promise;
|
|
10416
10416
|
if (async) {
|
|
10417
|
-
return Promise.all([left,
|
|
10418
|
-
return handleIntersectionResults2(payload, left2,
|
|
10417
|
+
return Promise.all([left, right2]).then(([left2, right3]) => {
|
|
10418
|
+
return handleIntersectionResults2(payload, left2, right3);
|
|
10419
10419
|
});
|
|
10420
10420
|
}
|
|
10421
|
-
return handleIntersectionResults2(payload, left,
|
|
10421
|
+
return handleIntersectionResults2(payload, left, right2);
|
|
10422
10422
|
};
|
|
10423
10423
|
});
|
|
10424
10424
|
function mergeValues2(a, b) {
|
|
@@ -10469,7 +10469,7 @@ function mergeValues2(a, b) {
|
|
|
10469
10469
|
}
|
|
10470
10470
|
return { valid: false, mergeErrorPath: [] };
|
|
10471
10471
|
}
|
|
10472
|
-
function handleIntersectionResults2(result, left,
|
|
10472
|
+
function handleIntersectionResults2(result, left, right2) {
|
|
10473
10473
|
const unrecKeys = /* @__PURE__ */ new Map();
|
|
10474
10474
|
let unrecIssue;
|
|
10475
10475
|
const keyIssues = /* @__PURE__ */ new Map();
|
|
@@ -10497,7 +10497,7 @@ function handleIntersectionResults2(result, left, right) {
|
|
|
10497
10497
|
if (!collect(iss, "l"))
|
|
10498
10498
|
result.issues.push(iss);
|
|
10499
10499
|
}
|
|
10500
|
-
for (const iss of
|
|
10500
|
+
for (const iss of right2.issues) {
|
|
10501
10501
|
if (!collect(iss, "r"))
|
|
10502
10502
|
result.issues.push(iss);
|
|
10503
10503
|
}
|
|
@@ -10511,7 +10511,7 @@ function handleIntersectionResults2(result, left, right) {
|
|
|
10511
10511
|
result.issues.push(keyIssues.get(k));
|
|
10512
10512
|
}
|
|
10513
10513
|
}
|
|
10514
|
-
const merged = mergeValues2(left.value,
|
|
10514
|
+
const merged = mergeValues2(left.value, right2.value);
|
|
10515
10515
|
if (!merged.valid) {
|
|
10516
10516
|
if (aborted2(result))
|
|
10517
10517
|
return result;
|
|
@@ -10901,11 +10901,11 @@ var $ZodPipe2 = /* @__PURE__ */ $constructor2("$ZodPipe", (inst, def) => {
|
|
|
10901
10901
|
defineLazyInternal2(inst, "propValues", (zod) => zod.def.in._zod.propValues);
|
|
10902
10902
|
inst._zod.parse = (payload, ctx) => {
|
|
10903
10903
|
if (ctx.direction === "backward") {
|
|
10904
|
-
const
|
|
10905
|
-
if (
|
|
10906
|
-
return
|
|
10904
|
+
const right2 = def.out._zod.run(payload, ctx);
|
|
10905
|
+
if (right2 instanceof Promise) {
|
|
10906
|
+
return right2.then((right3) => handlePipeResult2(right3, def.in, ctx));
|
|
10907
10907
|
}
|
|
10908
|
-
return handlePipeResult2(
|
|
10908
|
+
return handlePipeResult2(right2, def.in, ctx);
|
|
10909
10909
|
}
|
|
10910
10910
|
const left = def.in._zod.run(payload, ctx);
|
|
10911
10911
|
if (left instanceof Promise) {
|
|
@@ -13961,11 +13961,11 @@ var ZodIntersection2 = /* @__PURE__ */ $constructor2("ZodIntersection", (inst, d
|
|
|
13961
13961
|
ZodType2.init(inst, def);
|
|
13962
13962
|
inst._zod.processJSONSchema = (ctx, json2, params) => intersectionProcessor2(inst, ctx, json2, params);
|
|
13963
13963
|
});
|
|
13964
|
-
function intersection2(left,
|
|
13964
|
+
function intersection2(left, right2) {
|
|
13965
13965
|
return new ZodIntersection2({
|
|
13966
13966
|
type: "intersection",
|
|
13967
13967
|
left,
|
|
13968
|
-
right
|
|
13968
|
+
right: right2
|
|
13969
13969
|
});
|
|
13970
13970
|
}
|
|
13971
13971
|
var ZodRecord2 = /* @__PURE__ */ $constructor2("ZodRecord", (inst, def) => {
|
|
@@ -28405,7 +28405,7 @@ var DECISION_SOURCE = "decision";
|
|
|
28405
28405
|
var DECISION_USER_LABEL = "decision (user)";
|
|
28406
28406
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
28407
28407
|
var RELEASE_BRANCH = "release";
|
|
28408
|
-
var BUNDLE_SHA = true ? "
|
|
28408
|
+
var BUNDLE_SHA = true ? "ede83923546ab97898750ef7cebe34cf82e9534c" : void 0;
|
|
28409
28409
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
28410
28410
|
var DOCTOR_LABEL = Object.freeze({
|
|
28411
28411
|
D1: "version",
|
|
@@ -28428,6 +28428,8 @@ var REPORT_HEADER = "| Check | Status | Detail | Fix |";
|
|
|
28428
28428
|
var REPORT_HEADER_RULE = "|---|---|---|---|";
|
|
28429
28429
|
var REPORT_COMMAND_PREFIX = "Run in a terminal: ";
|
|
28430
28430
|
var ECHO_MAX_BYTES = 256;
|
|
28431
|
+
var LABEL_PREVIEW_BYTES = 32;
|
|
28432
|
+
var LABEL_PAGE_BYTES = 8192;
|
|
28431
28433
|
var REPORT_SOURCE_LABEL = "ctx_doctor:report";
|
|
28432
28434
|
var REPORT_REST_PREFIX = "Rows not shown here are stored in full. Read them with: ";
|
|
28433
28435
|
var REPORT_POINTER = `ctx_search({queries:["FAIL","PASS","UNKNOWN"], source:${JSON.stringify(REPORT_SOURCE_LABEL)}})`;
|
|
@@ -28524,6 +28526,23 @@ function D8_HEALED_RECREATE_DETAIL(ts) {
|
|
|
28524
28526
|
}
|
|
28525
28527
|
var INTEGRITY_OK = "ok";
|
|
28526
28528
|
var HEAL_BACKUP_SUFFIX = ".bak";
|
|
28529
|
+
var orphanList = (files) => files.map((f) => `${f.path} (${f.bytes} bytes)`).join(", ");
|
|
28530
|
+
var ORPHAN_DIR_PREFIX = "orphan-";
|
|
28531
|
+
function D8_ORPHAN_DETAIL(files) {
|
|
28532
|
+
return `context.db is gone, its WAL files are still here: ${orphanList(files)}`;
|
|
28533
|
+
}
|
|
28534
|
+
var D8_ORPHAN_FIX = "run ctx_doctor once; it keeps these files in a dated folder and starts a new index";
|
|
28535
|
+
function D8_ORPHAN_HEALED_DETAIL(dir, moved, dbPath) {
|
|
28536
|
+
return `moved the WAL files of the missing context.db, whole and unchanged, to ${dir}: ${orphanList(moved)}; new index at ${dbPath}; the old WAL is kept there, to restore it put the original context.db back next to it`;
|
|
28537
|
+
}
|
|
28538
|
+
var D8_ORPHAN_HEALED_FIX = "run ctx_doctor again; D8 then reads PASS";
|
|
28539
|
+
function D8_ORPHAN_MOVE_FAILED(detail, cause) {
|
|
28540
|
+
return `${detail}; moving them aside failed: ${cause}`;
|
|
28541
|
+
}
|
|
28542
|
+
var DOCTOR_TOOL_NAME = "ctx_doctor";
|
|
28543
|
+
function JOURNAL_SKIPPED_LINE(cause) {
|
|
28544
|
+
return `Journal row for this call skipped: ${cause}`;
|
|
28545
|
+
}
|
|
28527
28546
|
function D9_INDEX_DETAIL(sources, chunks) {
|
|
28528
28547
|
return `${sources} sources, ${chunks} chunks indexed`;
|
|
28529
28548
|
}
|
|
@@ -28901,7 +28920,8 @@ var DOCTOR_LOG_TAIL_BYTES = 262144;
|
|
|
28901
28920
|
var ERROR_TEXT = Object.freeze({
|
|
28902
28921
|
NODE_TOO_OLD: "Node <v> is below 24.15.0. Fix: install Node 24.15.0 or later.",
|
|
28903
28922
|
NO_SQLITE: "node:sqlite failed to load. Fix: run ctx_doctor.",
|
|
28904
|
-
DB_GONE: "context.db
|
|
28923
|
+
DB_GONE: "context.db is gone and its WAL file is still in place. Fix: run ctx_doctor once; it keeps the WAL file in a dated folder and starts a new index.",
|
|
28924
|
+
// D-ORPHAN-WAL-1
|
|
28905
28925
|
NO_PROJECT: "Project source <kind> is missing. Fix: run ctx_doctor.",
|
|
28906
28926
|
UNKNOWN_FIELD: 'Unknown field "<f>". Fix: use "queries".',
|
|
28907
28927
|
TIMEOUT: "Timed out after <ms> ms. Fix: pass background: true.",
|
|
@@ -31626,6 +31646,7 @@ var PORTER_MATCH = `
|
|
|
31626
31646
|
AND (:scope <> 'session' OR chunks.session_id = :session_id)
|
|
31627
31647
|
AND (:scope <> 'worktree' OR chunks.worktree = :worktree)
|
|
31628
31648
|
AND (:source IS NULL OR s.label = :source)
|
|
31649
|
+
AND (:ids IS NULL OR s.id IN (SELECT value FROM json_each(:ids)))
|
|
31629
31650
|
${NOT_RAW}`;
|
|
31630
31651
|
var PORTER_ORDER = `
|
|
31631
31652
|
ORDER BY (session_id = :session_id) DESC, (worktree = :worktree) DESC, full DESC, score DESC, source_id DESC, ord ASC`;
|
|
@@ -31654,6 +31675,7 @@ WHERE chunks_tri MATCH :match
|
|
|
31654
31675
|
AND (:scope <> 'session' OR c.session_id = :session_id)
|
|
31655
31676
|
AND (:scope <> 'worktree' OR c.worktree = :worktree)
|
|
31656
31677
|
AND (:source IS NULL OR s.label = :source)
|
|
31678
|
+
AND (:ids IS NULL OR s.id IN (SELECT value FROM json_each(:ids)))
|
|
31657
31679
|
${NOT_RAW}
|
|
31658
31680
|
ORDER BY bm25(chunks_tri, 1.0, ${TITLE_WEIGHT}) ASC, c.source_id DESC, c.ord ASC`;
|
|
31659
31681
|
var PAGE_ROWS = `
|
|
@@ -31914,10 +31936,18 @@ function typoTerms(db, words) {
|
|
|
31914
31936
|
});
|
|
31915
31937
|
return changed ? out.map((t) => `"${t.replaceAll('"', '""')}"*`) : null;
|
|
31916
31938
|
}
|
|
31917
|
-
|
|
31939
|
+
var LABEL_SERIAL = `
|
|
31940
|
+
SELECT COALESCE(MAX(CAST(substr(label, length(:prefix) + 1) AS INTEGER)), 0) + 1 AS n
|
|
31941
|
+
FROM sources WHERE session_id = :session_id AND substr(label, 1, length(:prefix)) = :prefix`;
|
|
31942
|
+
function nextLabelSerial(db, sessionId, prefix) {
|
|
31943
|
+
const row5 = stmt(db.raw, LABEL_SERIAL).get({ session_id: sessionId, prefix });
|
|
31944
|
+
return Number(row5.n);
|
|
31945
|
+
}
|
|
31946
|
+
function ftsQuery(db, q, scope, ctx, sessionId, limit, offset, source, sourceIds) {
|
|
31918
31947
|
const terms = searchTerms(q);
|
|
31919
31948
|
if (terms.length === 0) return [];
|
|
31920
|
-
const
|
|
31949
|
+
const ids = sourceIds === void 0 ? null : JSON.stringify(sourceIds);
|
|
31950
|
+
const filter2 = { scope, session_id: sessionId, worktree: ctx.worktree, source: source ?? null, ids };
|
|
31921
31951
|
const rrf = scope === "project" ? { k: RRF_K } : {};
|
|
31922
31952
|
const porter = (t) => stmt(db.raw, porterRankSql(scope)).all({ ...filter2, match: t.join(" OR "), all: t.join(" "), ...rrf });
|
|
31923
31953
|
let pList = porter(terms);
|
|
@@ -32123,20 +32153,84 @@ function storedLabel(db, source) {
|
|
|
32123
32153
|
const canon = pathLabel(source);
|
|
32124
32154
|
return canon !== source && labelStored(db, canon) ? canon : source;
|
|
32125
32155
|
}
|
|
32126
|
-
function
|
|
32156
|
+
function newestId(db, label2) {
|
|
32157
|
+
const row5 = stmt(db.raw, "SELECT id FROM sources WHERE label = ? ORDER BY id DESC LIMIT 1").get(label2);
|
|
32158
|
+
return row5 === void 0 ? null : Number(row5.id);
|
|
32159
|
+
}
|
|
32160
|
+
function labelOfId(db, id) {
|
|
32161
|
+
const row5 = stmt(db.raw, "SELECT label FROM sources WHERE id = ?").get(id);
|
|
32162
|
+
return row5 === void 0 ? null : row5.label;
|
|
32163
|
+
}
|
|
32164
|
+
function pickSource(db, source, suffix = true) {
|
|
32165
|
+
const named2 = storedLabel(db, source);
|
|
32127
32166
|
const id = parseSourceHandle(source);
|
|
32167
|
+
const own4 = newestId(db, named2);
|
|
32168
|
+
if (own4 !== null) {
|
|
32169
|
+
const otherLabel = id === null || id === own4 ? null : labelOfId(db, id);
|
|
32170
|
+
return { label: named2, id: own4, via: "label", other: otherLabel === null || otherLabel === named2 ? null : { id, label: otherLabel } };
|
|
32171
|
+
}
|
|
32128
32172
|
if (id !== null) {
|
|
32129
|
-
const
|
|
32130
|
-
if (
|
|
32173
|
+
const label2 = labelOfId(db, id);
|
|
32174
|
+
if (label2 !== null) return { label: label2, id, via: "handle", other: null };
|
|
32131
32175
|
}
|
|
32132
|
-
|
|
32133
|
-
|
|
32134
|
-
|
|
32135
|
-
|
|
32136
|
-
|
|
32137
|
-
|
|
32176
|
+
if (suffix) {
|
|
32177
|
+
const prefix = named2 + LABEL_SUFFIX_SEP;
|
|
32178
|
+
const rows = stmt(db.raw, "SELECT id, label FROM sources WHERE substr(label, 1, ?) = ? ORDER BY id DESC").all(prefix.length, prefix);
|
|
32179
|
+
for (const r of rows) {
|
|
32180
|
+
if (r.label.lastIndexOf(LABEL_SUFFIX_SEP) === named2.length) return { label: r.label, id: Number(r.id), via: "suffix", other: null };
|
|
32181
|
+
}
|
|
32138
32182
|
}
|
|
32139
|
-
return source;
|
|
32183
|
+
return { label: source, id: null, via: "none", other: null };
|
|
32184
|
+
}
|
|
32185
|
+
function collisionLine(value, pick4) {
|
|
32186
|
+
if (pick4.other === null || pick4.id === null) return null;
|
|
32187
|
+
return "Source " + JSON.stringify(value) + ": used the label " + shownLabel(pick4.label, null) + " (" + sourceHandle(pick4.id) + "); handle " + sourceHandle(pick4.other.id) + " is " + shownLabel(pick4.other.label, null) + (isLongLabel(pick4.other.label) ? ", search it by its full label." : ", search it with source:" + JSON.stringify(pick4.other.label) + ".");
|
|
32188
|
+
}
|
|
32189
|
+
function labelPage(label2, offset, max) {
|
|
32190
|
+
const buf = Buffer.from(label2, "utf8");
|
|
32191
|
+
let start = Math.min(offset, buf.length);
|
|
32192
|
+
while (start < buf.length && (buf[start] & 192) === 128) start++;
|
|
32193
|
+
let end = Math.min(start + max, buf.length);
|
|
32194
|
+
while (end < buf.length && end > start && (buf[end] & 192) === 128) end--;
|
|
32195
|
+
return { text: buf.subarray(start, end).toString("utf8"), next: end < buf.length ? end : null, total: buf.length };
|
|
32196
|
+
}
|
|
32197
|
+
function groupDigits(n) {
|
|
32198
|
+
const s = String(Math.trunc(n));
|
|
32199
|
+
let out = "";
|
|
32200
|
+
for (let i = 0; i < s.length; i++) {
|
|
32201
|
+
if (i > 0 && (s.length - i) % 3 === 0) out += ",";
|
|
32202
|
+
out += s[i];
|
|
32203
|
+
}
|
|
32204
|
+
return out;
|
|
32205
|
+
}
|
|
32206
|
+
function headBytes(s, max) {
|
|
32207
|
+
let out = "";
|
|
32208
|
+
let used = 0;
|
|
32209
|
+
for (const ch of s) {
|
|
32210
|
+
const n = Buffer.byteLength(ch, "utf8");
|
|
32211
|
+
if (used + n > max) break;
|
|
32212
|
+
out += ch;
|
|
32213
|
+
used += n;
|
|
32214
|
+
}
|
|
32215
|
+
return out;
|
|
32216
|
+
}
|
|
32217
|
+
function isLongLabel(label2) {
|
|
32218
|
+
return Buffer.byteLength(label2, "utf8") > ECHO_MAX_BYTES;
|
|
32219
|
+
}
|
|
32220
|
+
function labelPreview(label2) {
|
|
32221
|
+
return "label (" + groupDigits(Buffer.byteLength(label2, "utf8")) + " B): " + headBytes(label2, LABEL_PREVIEW_BYTES) + "\u2026";
|
|
32222
|
+
}
|
|
32223
|
+
function shownLabel(label2, id) {
|
|
32224
|
+
if (!isLongLabel(label2)) return label2;
|
|
32225
|
+
return (id === null ? "" : sourceHandle(id) + " ") + "[" + labelPreview(label2) + "]";
|
|
32226
|
+
}
|
|
32227
|
+
function indexedLabelLine(label2, id) {
|
|
32228
|
+
if (!isLongLabel(label2)) return "Label: " + label2;
|
|
32229
|
+
return "Its label (" + groupDigits(Buffer.byteLength(label2, "utf8")) + " B): " + headBytes(label2, LABEL_PREVIEW_BYTES) + "\u2026; ctx_search({queries:[], source:" + JSON.stringify(sourceHandle(id)) + "}) reads it whole.";
|
|
32230
|
+
}
|
|
32231
|
+
function sourceCardRow(db, id) {
|
|
32232
|
+
const row5 = stmt(db.raw, "SELECT label, bytes_total, chunk_count, kind FROM sources WHERE id = ?").get(id);
|
|
32233
|
+
return row5 === void 0 ? null : { label: row5.label, bytes: Number(row5.bytes_total), chunks: Number(row5.chunk_count), kind: row5.kind };
|
|
32140
32234
|
}
|
|
32141
32235
|
function listSessionSources(db, sessionId, limit) {
|
|
32142
32236
|
const rows = stmt(db.raw, "SELECT id, label, bytes_total FROM sources WHERE session_id = ? ORDER BY id DESC LIMIT ?").all(sessionId, limit);
|
|
@@ -35160,14 +35254,14 @@ var $ZodIntersection3 = /* @__PURE__ */ $constructor3("$ZodIntersection", (inst,
|
|
|
35160
35254
|
inst._zod.parse = (payload, ctx) => {
|
|
35161
35255
|
const input = payload.value;
|
|
35162
35256
|
const left = def.left._zod.run({ value: input, issues: [] }, ctx);
|
|
35163
|
-
const
|
|
35164
|
-
const async = left instanceof Promise ||
|
|
35257
|
+
const right2 = def.right._zod.run({ value: input, issues: [] }, ctx);
|
|
35258
|
+
const async = left instanceof Promise || right2 instanceof Promise;
|
|
35165
35259
|
if (async) {
|
|
35166
|
-
return Promise.all([left,
|
|
35167
|
-
return handleIntersectionResults3(payload, left2,
|
|
35260
|
+
return Promise.all([left, right2]).then(([left2, right3]) => {
|
|
35261
|
+
return handleIntersectionResults3(payload, left2, right3);
|
|
35168
35262
|
});
|
|
35169
35263
|
}
|
|
35170
|
-
return handleIntersectionResults3(payload, left,
|
|
35264
|
+
return handleIntersectionResults3(payload, left, right2);
|
|
35171
35265
|
};
|
|
35172
35266
|
});
|
|
35173
35267
|
function mergeValues3(a, b) {
|
|
@@ -35214,16 +35308,16 @@ function mergeValues3(a, b) {
|
|
|
35214
35308
|
}
|
|
35215
35309
|
return { valid: false, mergeErrorPath: [] };
|
|
35216
35310
|
}
|
|
35217
|
-
function handleIntersectionResults3(result, left,
|
|
35311
|
+
function handleIntersectionResults3(result, left, right2) {
|
|
35218
35312
|
if (left.issues.length) {
|
|
35219
35313
|
result.issues.push(...left.issues);
|
|
35220
35314
|
}
|
|
35221
|
-
if (
|
|
35222
|
-
result.issues.push(...
|
|
35315
|
+
if (right2.issues.length) {
|
|
35316
|
+
result.issues.push(...right2.issues);
|
|
35223
35317
|
}
|
|
35224
35318
|
if (aborted3(result))
|
|
35225
35319
|
return result;
|
|
35226
|
-
const merged = mergeValues3(left.value,
|
|
35320
|
+
const merged = mergeValues3(left.value, right2.value);
|
|
35227
35321
|
if (!merged.valid) {
|
|
35228
35322
|
throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
|
|
35229
35323
|
}
|
|
@@ -41290,11 +41384,11 @@ function _discriminatedUnion(Class4, discriminator, options, params) {
|
|
|
41290
41384
|
...normalizeParams3(params)
|
|
41291
41385
|
});
|
|
41292
41386
|
}
|
|
41293
|
-
function _intersection(Class4, left,
|
|
41387
|
+
function _intersection(Class4, left, right2) {
|
|
41294
41388
|
return new Class4({
|
|
41295
41389
|
type: "intersection",
|
|
41296
41390
|
left,
|
|
41297
|
-
right
|
|
41391
|
+
right: right2
|
|
41298
41392
|
});
|
|
41299
41393
|
}
|
|
41300
41394
|
function _tuple(Class4, items, _paramsOrRest, _params) {
|
|
@@ -42972,11 +43066,11 @@ var ZodIntersection3 = /* @__PURE__ */ $constructor3("ZodIntersection", (inst, d
|
|
|
42972
43066
|
$ZodIntersection3.init(inst, def);
|
|
42973
43067
|
ZodType3.init(inst, def);
|
|
42974
43068
|
});
|
|
42975
|
-
function intersection3(left,
|
|
43069
|
+
function intersection3(left, right2) {
|
|
42976
43070
|
return new ZodIntersection3({
|
|
42977
43071
|
type: "intersection",
|
|
42978
43072
|
left,
|
|
42979
|
-
right
|
|
43073
|
+
right: right2
|
|
42980
43074
|
});
|
|
42981
43075
|
}
|
|
42982
43076
|
var ZodTuple = /* @__PURE__ */ $constructor3("ZodTuple", (inst, def) => {
|
|
@@ -43441,10 +43535,10 @@ config3(en_default3());
|
|
|
43441
43535
|
// src/prompt/_generated.ts
|
|
43442
43536
|
var INSTRUCTIONS = "context-mode keeps large output out of the conversation.\n\nWhen a step counts, sums, filters or finds something in over about 20 lines of data (logs, test or build output, big JSON or CSV, long files, web pages), use ctx_execute and print only the answer, not a raw Bash or Read result.\n\nA large tool result is indexed and cut to its best-matching parts; ctx_search finds the rest. A large file's Read is denied: use offset and limit, or ctx_execute with file set. Use normal tools for small output and edits.\n";
|
|
43443
43537
|
var TOOL_DESCRIPTIONS = Object.freeze({
|
|
43444
|
-
ctx_execute: 'Example: `ctx_execute({language:"shell",code:"git log --oneline -5"})`. Required: language, code.\
|
|
43538
|
+
ctx_execute: 'Example: `ctx_execute({language:"shell",code:"git log --oneline -5"})`. Required: language, code.\nWrite code that prints only the answer, not the raw data. Runs code in a sandboxed subprocess in the project directory (shell, powershell, javascript, typescript, python, or another runtime on PATH); only what the code prints comes back. For a large file, set `file` to its local path: the code gets it in the CTX_FILE environment variable. Set `intent` when output may be large: the matching sections come back and the full output is indexed for ctx_search. `timeoutMs` defaults to and caps at 600000; then the whole process tree is killed.',
|
|
43445
43539
|
ctx_batch: 'Example: `ctx_batch({commands:["git log --oneline -5"],queries:["recent changes"]})`. Required: commands, queries.\nRuns several shell commands, then answers several search queries over their combined output, in one call. Use it to collect facts from more than one command at once, for example test results plus recent commits, when you need specific answers rather than the full text. Returns the matching sections and a one-line footer.',
|
|
43446
43540
|
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.',
|
|
43447
|
-
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.',
|
|
43541
|
+
ctx_search: 'Example: `ctx_search({queries:["auth middleware"]})`. Required: queries.\nSearches content stored with ctx_index and earlier sandbox output in this project. Memory files such as AGENTS.md are searched too. 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.',
|
|
43448
43542
|
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.",
|
|
43449
43543
|
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.",
|
|
43450
43544
|
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, the fix and a docs link. Use it when the user asks whether context-mode works, or after a context-mode error. Run each Fix first, then call ctx_doctor again. If a FAIL stays, show the user the report file it names (it holds paths and environment details) and ask before you run the printed gh issue command.\n",
|
|
@@ -43702,8 +43796,8 @@ function rawEnd(src, from, name) {
|
|
|
43702
43796
|
let k = src.indexOf("</", from);
|
|
43703
43797
|
while (k >= 0) {
|
|
43704
43798
|
const after = k + "</".length + name.length;
|
|
43705
|
-
const
|
|
43706
|
-
if (
|
|
43799
|
+
const named2 = src.slice(k + "</".length, after).toLowerCase() === name;
|
|
43800
|
+
if (named2 && (after >= src.length || !isNameChar(src[after]))) {
|
|
43707
43801
|
const gt = src.indexOf(">", after);
|
|
43708
43802
|
return gt < 0 ? src.length : gt + 1;
|
|
43709
43803
|
}
|
|
@@ -43730,7 +43824,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
43730
43824
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
43731
43825
|
return { end: start + r.read, written: r.written };
|
|
43732
43826
|
}
|
|
43733
|
-
function merge4(src, blocks,
|
|
43827
|
+
function merge4(src, blocks, join25, cap, lineCut) {
|
|
43734
43828
|
const out = [];
|
|
43735
43829
|
const scratch = new Uint8Array(cap);
|
|
43736
43830
|
let wide;
|
|
@@ -43740,7 +43834,7 @@ function merge4(src, blocks, join24, cap, lineCut) {
|
|
|
43740
43834
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
43741
43835
|
};
|
|
43742
43836
|
for (const b of blocks) {
|
|
43743
|
-
if (cur !== void 0 && !
|
|
43837
|
+
if (cur !== void 0 && !join25) {
|
|
43744
43838
|
emit(cur.start, cur.end, curBytes);
|
|
43745
43839
|
cur = void 0;
|
|
43746
43840
|
}
|
|
@@ -44009,17 +44103,29 @@ function runProcess(argv, o) {
|
|
|
44009
44103
|
}
|
|
44010
44104
|
|
|
44011
44105
|
// src/core/index/auto-memory.ts
|
|
44012
|
-
import { readFileSync as readFileSync3, statSync as statSync3 } from "node:fs";
|
|
44106
|
+
import { readdirSync as readdirSync3, readFileSync as readFileSync3, statSync as statSync3 } from "node:fs";
|
|
44013
44107
|
import { join as join5 } from "node:path";
|
|
44014
|
-
var
|
|
44108
|
+
var MEMORY_FILES = Object.freeze([
|
|
44015
44109
|
Object.freeze(["CLAUDE.md"]),
|
|
44016
44110
|
Object.freeze(["CLAUDE.local.md"]),
|
|
44017
|
-
Object.freeze([".claude", "CLAUDE.md"])
|
|
44111
|
+
Object.freeze([".claude", "CLAUDE.md"]),
|
|
44112
|
+
Object.freeze(["AGENTS.md"]),
|
|
44113
|
+
Object.freeze(["GEMINI.md"]),
|
|
44114
|
+
Object.freeze(["QWEN.md"]),
|
|
44115
|
+
Object.freeze([".github", "copilot-instructions.md"])
|
|
44018
44116
|
]);
|
|
44117
|
+
var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
44118
|
+
var MD = ".md";
|
|
44119
|
+
function steeringFiles(worktree) {
|
|
44120
|
+
try {
|
|
44121
|
+
return readdirSync3(join5(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
44122
|
+
} catch {
|
|
44123
|
+
return [];
|
|
44124
|
+
}
|
|
44125
|
+
}
|
|
44019
44126
|
function readAutoMemory(project) {
|
|
44020
|
-
if (project.agent !== "claude-code") return [];
|
|
44021
44127
|
const rows = [];
|
|
44022
|
-
for (const segs of
|
|
44128
|
+
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
44023
44129
|
const path7 = join5(project.worktree, ...segs);
|
|
44024
44130
|
if (!isInside(project.worktree, path7)) continue;
|
|
44025
44131
|
try {
|
|
@@ -44039,6 +44145,20 @@ function readAutoMemory(project) {
|
|
|
44039
44145
|
}
|
|
44040
44146
|
return rows;
|
|
44041
44147
|
}
|
|
44148
|
+
function memoryChunks(rows) {
|
|
44149
|
+
const out = [];
|
|
44150
|
+
rows.forEach((r, i) => {
|
|
44151
|
+
for (const c of chunkText(r.text, "md")) out.push({ fileNo: i + 1, label: r.label, ord: c.ord, text: c.text });
|
|
44152
|
+
});
|
|
44153
|
+
return out;
|
|
44154
|
+
}
|
|
44155
|
+
function memoryHits(chunks, q, limit) {
|
|
44156
|
+
if (chunks.length === 0) return [];
|
|
44157
|
+
const texts = chunks.map((c) => c.text);
|
|
44158
|
+
const any3 = rankTexts(texts, q, "any");
|
|
44159
|
+
const all = rankTexts(texts, q, "all");
|
|
44160
|
+
return chunks.map((c, i) => ({ c, s: any3[i], full: all[i] > 0 })).filter((e) => e.s > 0).sort((a, b) => Number(b.full) - Number(a.full) || b.s - a.s || a.c.fileNo - b.c.fileNo || a.c.ord - b.c.ord).slice(0, limit).map((e) => ({ sourceId: -e.c.fileNo, label: "memory " + e.c.label, ord: e.c.ord, snippet: highlight(e.c.text, q, SNIPPET_MAX_BYTES), score: e.s, full: e.full }));
|
|
44161
|
+
}
|
|
44042
44162
|
|
|
44043
44163
|
// src/core/index/shape.ts
|
|
44044
44164
|
var SHAPE_MIN_ROWS = 20;
|
|
@@ -44071,11 +44191,11 @@ function jsonRows(text) {
|
|
|
44071
44191
|
}
|
|
44072
44192
|
return { objs, keys };
|
|
44073
44193
|
}
|
|
44074
|
-
function fitRow(row5, skewed,
|
|
44194
|
+
function fitRow(row5, skewed, named2, budget) {
|
|
44075
44195
|
const whole2 = JSON.stringify(row5);
|
|
44076
44196
|
if (bytes(whole2) <= budget) return whole2;
|
|
44077
44197
|
const own4 = Object.keys(row5);
|
|
44078
|
-
const tier = (k) => skewed.includes(k) ? 0 :
|
|
44198
|
+
const tier = (k) => skewed.includes(k) ? 0 : named2.has(k) ? 1 : typeof row5[k] !== "object" || row5[k] === null ? 2 : 3;
|
|
44079
44199
|
const order = [...own4].sort((a, b) => tier(a) - tier(b) || own4.indexOf(a) - own4.indexOf(b));
|
|
44080
44200
|
const field = (k) => JSON.stringify(k) + ":" + JSON.stringify(row5[k]);
|
|
44081
44201
|
const chosen = /* @__PURE__ */ new Set();
|
|
@@ -44129,8 +44249,27 @@ function sourceCount(db, scope, ctx, source) {
|
|
|
44129
44249
|
});
|
|
44130
44250
|
return Number(row5.n);
|
|
44131
44251
|
}
|
|
44132
|
-
function zeroHits(db, scope, ctx, source) {
|
|
44133
|
-
|
|
44252
|
+
function zeroHits(db, scope, ctx, source, offset = 0) {
|
|
44253
|
+
const n = sourceCount(db, scope, ctx, source);
|
|
44254
|
+
if (offset > 0) return reply("No more hits past offset " + offset + ' in scope "' + scope + '" across ' + n + " source(s).", false);
|
|
44255
|
+
return reply('No hits in scope "' + scope + '" across ' + n + " source(s).", false);
|
|
44256
|
+
}
|
|
44257
|
+
function named(given, pick4) {
|
|
44258
|
+
if (given === void 0 || pick4 === null) return { arg: given, note: null };
|
|
44259
|
+
const arg = pick4.id !== null && isLongLabel(given) ? sourceHandle(pick4.id) : given;
|
|
44260
|
+
return { arg, note: collisionLine(given, pick4) };
|
|
44261
|
+
}
|
|
44262
|
+
function sourceCard(db, id, input, scope, arg) {
|
|
44263
|
+
const row5 = sourceCardRow(db, id);
|
|
44264
|
+
if (row5 === null) return null;
|
|
44265
|
+
const pg = labelPage(row5.label, input.offset ?? 0, LABEL_PAGE_BYTES);
|
|
44266
|
+
const lines = [
|
|
44267
|
+
"Source " + sourceHandle(id) + ": label " + groupDigits(pg.total) + " B, " + row5.chunks + " chunk(s), " + groupDigits(row5.bytes) + " B of " + row5.kind + ".",
|
|
44268
|
+
"Label:",
|
|
44269
|
+
pg.text
|
|
44270
|
+
];
|
|
44271
|
+
if (pg.next !== null) lines.push("More: " + callText([], scope, arg, "offset:" + pg.next));
|
|
44272
|
+
return reply(lines.join("\n"), false);
|
|
44134
44273
|
}
|
|
44135
44274
|
function callText(queries, scope, source, cursor) {
|
|
44136
44275
|
const src = source === void 0 ? "" : ", source:" + JSON.stringify(source);
|
|
@@ -44161,7 +44300,7 @@ WHERE label = :source
|
|
|
44161
44300
|
AND (:scope <> 'session' OR session_id = :session_id)
|
|
44162
44301
|
AND (:scope <> 'worktree' OR worktree = :worktree)
|
|
44163
44302
|
ORDER BY id DESC LIMIT 1`;
|
|
44164
|
-
function jsonRowsReply(db, input, scope, ctx) {
|
|
44303
|
+
function jsonRowsReply(db, input, scope, ctx, nm) {
|
|
44165
44304
|
if (input.source === void 0 || input.source === DECISION_SOURCE || input.queries.length === 0) return null;
|
|
44166
44305
|
const src = db.raw.prepare(JSON_SOURCE).get({ source: input.source, scope, session_id: ctx.sessionId, worktree: ctx.project.worktree });
|
|
44167
44306
|
if (src === void 0 || Number(src.bytes_total) > JSON_SOURCE_MAX_BYTES) return null;
|
|
@@ -44172,25 +44311,27 @@ function jsonRowsReply(db, input, scope, ctx) {
|
|
|
44172
44311
|
const texts = objs.map((o) => JSON.stringify(o));
|
|
44173
44312
|
const offset = input.offset ?? 0;
|
|
44174
44313
|
const out = [objs.length + " objects {" + keys.join(",") + "}"];
|
|
44314
|
+
const name = shownLabel(input.source, Number(src.id));
|
|
44175
44315
|
let shown2 = 0;
|
|
44176
44316
|
let more = false;
|
|
44177
44317
|
for (const q of input.queries) {
|
|
44178
44318
|
const scores = rankTexts(texts, q, "any");
|
|
44179
44319
|
const order = objs.map((_, i) => i).filter((i) => scores[i] > 0).sort((a, b) => scores[b] - scores[a] || a - b);
|
|
44180
|
-
const
|
|
44320
|
+
const named2 = namedKeys(keys, q);
|
|
44181
44321
|
out.push("Query " + JSON.stringify(q) + ":");
|
|
44182
44322
|
for (const i of order.slice(offset, offset + JSON_ROWS_PAGE)) {
|
|
44183
|
-
const row5 = fitRow(objs[i], [],
|
|
44323
|
+
const row5 = fitRow(objs[i], [], named2, SNIPPET_MAX_BYTES);
|
|
44184
44324
|
if (row5 === null) continue;
|
|
44185
|
-
out.push(
|
|
44325
|
+
out.push(name + " [" + i + "]: " + row5);
|
|
44186
44326
|
shown2++;
|
|
44187
44327
|
}
|
|
44188
44328
|
if (order.length > offset + JSON_ROWS_PAGE) {
|
|
44189
|
-
out.push("More: " + callText([q], scope,
|
|
44329
|
+
out.push("More: " + callText([q], scope, nm.arg, "offset:" + (offset + JSON_ROWS_PAGE)));
|
|
44190
44330
|
more = true;
|
|
44191
44331
|
}
|
|
44192
44332
|
}
|
|
44193
|
-
|
|
44333
|
+
if (shown2 === 0 && !more) return null;
|
|
44334
|
+
return reply((nm.note === null ? out : [nm.note, ...out]).join("\n"), false);
|
|
44194
44335
|
}
|
|
44195
44336
|
var SMALL_SOURCE_SHARE = 0.5;
|
|
44196
44337
|
var SOURCE_BYTES = "SELECT id, bytes_total FROM sources WHERE id IN (SELECT value FROM json_each(:ids))";
|
|
@@ -44209,23 +44350,49 @@ function replyHits(hits, size) {
|
|
|
44209
44350
|
while (n < size && n < hits.length && hits[n].full === true) n++;
|
|
44210
44351
|
return n;
|
|
44211
44352
|
}
|
|
44212
|
-
|
|
44353
|
+
var MEMORY_HITS = 2;
|
|
44354
|
+
function mergeMemory(content, memory) {
|
|
44355
|
+
const out = [];
|
|
44356
|
+
let c = 0;
|
|
44357
|
+
let m = 0;
|
|
44358
|
+
let lastMem = true;
|
|
44359
|
+
while (c < content.length || m < memory.length) {
|
|
44360
|
+
const rank = (h) => h === void 0 ? -1 : h.full === true ? 1 : 0;
|
|
44361
|
+
const rc = rank(content[c]);
|
|
44362
|
+
const rm = rank(memory[m]);
|
|
44363
|
+
const mem = rc < 0 || rm > rc || rm === rc && !lastMem;
|
|
44364
|
+
if (mem) {
|
|
44365
|
+
out.push(memory[m++]);
|
|
44366
|
+
lastMem = true;
|
|
44367
|
+
} else {
|
|
44368
|
+
out.push(content[c++]);
|
|
44369
|
+
lastMem = false;
|
|
44370
|
+
}
|
|
44371
|
+
}
|
|
44372
|
+
return out;
|
|
44373
|
+
}
|
|
44374
|
+
var contentIn = (hits, n) => hits.slice(0, n).filter((h) => h.sourceId > 0).length;
|
|
44375
|
+
function relevance(db, given, scope, ctx, nm) {
|
|
44213
44376
|
const input = { ...given, queries: decisionQueries(given) };
|
|
44214
44377
|
const offset = input.offset ?? 0;
|
|
44215
44378
|
const size = pageSize(input);
|
|
44216
|
-
const
|
|
44379
|
+
const mem = offset === 0 && scope !== "session" && input.source === void 0 ? memoryChunks(readAutoMemory(ctx.project)) : [];
|
|
44380
|
+
const fetched = input.queries.map((q) => {
|
|
44381
|
+
const content = page(db, q, input, scope, ctx, offset, 1);
|
|
44382
|
+
return mem.length === 0 ? content : mergeMemory(content, memoryHits(mem, q, MEMORY_HITS));
|
|
44383
|
+
});
|
|
44217
44384
|
const take = fetched.map((h) => replyHits(h, size));
|
|
44218
44385
|
const pages = fetched.map((h, i) => h.slice(0, take[i]));
|
|
44219
|
-
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source);
|
|
44220
|
-
const moreLine3 = (q, pos) => "More: " + callText([q], scope,
|
|
44386
|
+
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, offset);
|
|
44387
|
+
const moreLine3 = (q, pos) => "More: " + callText([q], scope, nm.arg, "offset:" + pos);
|
|
44221
44388
|
let reserve = 0;
|
|
44222
44389
|
for (const q of input.queries) reserve += bytes2(moreLine3(q, offset + size)) + 1;
|
|
44223
44390
|
const total = input.source === DECISION_SOURCE ? /* @__PURE__ */ new Map() : sourceBytes(db, [...new Set(pages.flat().map((h) => h.sourceId))]);
|
|
44224
44391
|
const spent = /* @__PURE__ */ new Map();
|
|
44225
|
-
const lines = [];
|
|
44392
|
+
const lines = nm.note === null ? [] : [nm.note];
|
|
44226
44393
|
const more = [];
|
|
44227
44394
|
const shown2 = /* @__PURE__ */ new Set();
|
|
44228
|
-
let used = 0;
|
|
44395
|
+
let used = nm.note === null ? 0 : bytes2(nm.note) + 1;
|
|
44229
44396
|
let stopped = false;
|
|
44230
44397
|
input.queries.forEach((q, qi) => {
|
|
44231
44398
|
const hits = pages[qi];
|
|
@@ -44243,18 +44410,19 @@ function relevance(db, given, scope, ctx) {
|
|
|
44243
44410
|
const hit = hits[i];
|
|
44244
44411
|
const key = hit.sourceId + ":" + hit.ord;
|
|
44245
44412
|
if (shown2.has(key)) {
|
|
44246
|
-
|
|
44413
|
+
const name = shownLabel(hit.label, hit.sourceId);
|
|
44414
|
+
again.set(name, [...again.get(name) ?? [], hit.ord]);
|
|
44247
44415
|
continue;
|
|
44248
44416
|
}
|
|
44249
|
-
const line = hit.label + " #" + hit.ord + ": " + hit.snippet;
|
|
44417
|
+
const line = shownLabel(hit.label, hit.sourceId) + " #" + hit.ord + ": " + hit.snippet;
|
|
44250
44418
|
if (used + bytes2(line) + 1 + reserve > OUTPUT_CAP) {
|
|
44251
|
-
cut = offset + i;
|
|
44419
|
+
cut = offset + contentIn(hits, i);
|
|
44252
44420
|
stopped = true;
|
|
44253
44421
|
break;
|
|
44254
44422
|
}
|
|
44255
44423
|
const room = total.get(hit.sourceId);
|
|
44256
44424
|
if (room !== void 0 && mine.has(hit.sourceId) && (spent.get(hit.sourceId) ?? 0) + bytes2(line) + 1 > room * SMALL_SOURCE_SHARE * (qi + 1) / input.queries.length) {
|
|
44257
|
-
cut = offset + i;
|
|
44425
|
+
cut = offset + contentIn(hits, i);
|
|
44258
44426
|
break;
|
|
44259
44427
|
}
|
|
44260
44428
|
lines.push(line);
|
|
@@ -44269,28 +44437,28 @@ function relevance(db, given, scope, ctx) {
|
|
|
44269
44437
|
used += bytes2(line) + 1;
|
|
44270
44438
|
}
|
|
44271
44439
|
if (cut >= 0) more.push({ q, pos: cut });
|
|
44272
|
-
else if (fetched[qi].length > take[qi]) more.push({ q, pos: offset + take[qi] });
|
|
44440
|
+
else if (contentIn(fetched[qi], fetched[qi].length) > contentIn(fetched[qi], take[qi])) more.push({ q, pos: offset + contentIn(fetched[qi], take[qi]) });
|
|
44273
44441
|
});
|
|
44274
44442
|
const moreLines = [];
|
|
44275
44443
|
const byPos = /* @__PURE__ */ new Map();
|
|
44276
44444
|
for (const m of more) byPos.set(m.pos, [...byPos.get(m.pos) ?? [], m.q]);
|
|
44277
|
-
for (const [pos, qs] of byPos) moreLines.push("More: " + callText(qs, scope,
|
|
44445
|
+
for (const [pos, qs] of byPos) moreLines.push("More: " + callText(qs, scope, nm.arg, "offset:" + pos));
|
|
44278
44446
|
return reply(lines.concat(moreLines).join("\n"), false);
|
|
44279
44447
|
}
|
|
44280
44448
|
function timelineLine(r) {
|
|
44281
44449
|
const nl = r.text.indexOf("\n");
|
|
44282
44450
|
const first = nl < 0 ? r.text : r.text.slice(0, nl);
|
|
44283
44451
|
const seq = r.seq === null ? "" : " #" + r.seq;
|
|
44284
|
-
return "[" + new Date(r.ts).toISOString() + "] " + r.label + seq + " " + first;
|
|
44452
|
+
return "[" + new Date(r.ts).toISOString() + "] " + shownLabel(r.label, r.sourceId) + seq + " " + first;
|
|
44285
44453
|
}
|
|
44286
|
-
function timeline(db, input, scope, ctx) {
|
|
44454
|
+
function timeline(db, input, scope, ctx, nm) {
|
|
44287
44455
|
const memory = scope === "session" ? [] : readAutoMemory(ctx.project);
|
|
44288
44456
|
const page2 = ftsQueryTimeline(db, scope, ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, input.after ?? null, input.source, memory);
|
|
44289
44457
|
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source);
|
|
44290
|
-
const moreLine3 = (ts) => "more: " + callText(input.queries, scope,
|
|
44458
|
+
const moreLine3 = (ts) => "more: " + callText(input.queries, scope, nm.arg, 'sort:"timeline", after:' + ts);
|
|
44291
44459
|
const reserve = bytes2(moreLine3(page2.rows[page2.rows.length - 1].ts)) + 1;
|
|
44292
|
-
const lines = [];
|
|
44293
|
-
let used = 0;
|
|
44460
|
+
const lines = nm.note === null ? [] : [nm.note];
|
|
44461
|
+
let used = nm.note === null ? 0 : bytes2(nm.note) + 1;
|
|
44294
44462
|
let lastTs = null;
|
|
44295
44463
|
let more = page2.more;
|
|
44296
44464
|
let i = 0;
|
|
@@ -44326,9 +44494,16 @@ async function handler(input, ctx) {
|
|
|
44326
44494
|
const scope = input.scope ?? "worktree";
|
|
44327
44495
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
44328
44496
|
try {
|
|
44329
|
-
|
|
44330
|
-
|
|
44331
|
-
|
|
44497
|
+
const given = input.source;
|
|
44498
|
+
const pick4 = given !== void 0 && given !== DECISION_SOURCE ? pickSource(db, given) : null;
|
|
44499
|
+
if (pick4 !== null) input = { ...input, source: pick4.label };
|
|
44500
|
+
const nm = named(given, pick4);
|
|
44501
|
+
if (sort === "timeline") return timeline(db, input, scope, ctx, nm);
|
|
44502
|
+
if (pick4 !== null && pick4.id !== null && input.queries.length === 0) {
|
|
44503
|
+
const card = sourceCard(db, pick4.id, input, scope, nm.arg);
|
|
44504
|
+
if (card !== null) return card;
|
|
44505
|
+
}
|
|
44506
|
+
return jsonRowsReply(db, input, scope, ctx, nm) ?? relevance(db, input, scope, ctx, nm);
|
|
44332
44507
|
} finally {
|
|
44333
44508
|
closeDb(db);
|
|
44334
44509
|
}
|
|
@@ -44349,6 +44524,7 @@ var ctxBatchSchema = external_exports.object({
|
|
|
44349
44524
|
}, { error: unknownField }).strict();
|
|
44350
44525
|
var TOOL = "ctx_batch";
|
|
44351
44526
|
var LABEL_PREFIX = TOOL + ":";
|
|
44527
|
+
var LABEL_SEP = ":";
|
|
44352
44528
|
var SHELL = "shell";
|
|
44353
44529
|
var SHELL_INLINE_FLAG = "-c";
|
|
44354
44530
|
var MARKER = "$ ";
|
|
@@ -44416,6 +44592,7 @@ function indexCombined(db, ctx, label2, ran, deadline, budgetBytes) {
|
|
|
44416
44592
|
const display = shown(chunks, ran.map((r) => r.head));
|
|
44417
44593
|
const bodies = /* @__PURE__ */ new Map();
|
|
44418
44594
|
const raw = /* @__PURE__ */ new Map();
|
|
44595
|
+
const ids = [];
|
|
44419
44596
|
let total = 0;
|
|
44420
44597
|
for (const c of chunks) total += c.bytes;
|
|
44421
44598
|
let indexed = 0;
|
|
@@ -44436,6 +44613,7 @@ function indexCombined(db, ctx, label2, ran, deadline, budgetBytes) {
|
|
|
44436
44613
|
chunkCount: group.length,
|
|
44437
44614
|
createdAt: Date.now()
|
|
44438
44615
|
}, group);
|
|
44616
|
+
ids.push(id);
|
|
44439
44617
|
for (const c of group) {
|
|
44440
44618
|
bodies.set(chunkKey(id, c.ord), display[c.ord]);
|
|
44441
44619
|
raw.set(chunkKey(id, c.ord), c.text);
|
|
@@ -44448,25 +44626,25 @@ function indexCombined(db, ctx, label2, ran, deadline, budgetBytes) {
|
|
|
44448
44626
|
for (const c of chunks) {
|
|
44449
44627
|
if (queued + c.bytes > budgetBytes) {
|
|
44450
44628
|
const stop2 = flush() ? "budget" : "deadline";
|
|
44451
|
-
return { bodies, raw, indexed, total, stop: stop2 };
|
|
44629
|
+
return { bodies, raw, ids, indexed, total, stop: stop2 };
|
|
44452
44630
|
}
|
|
44453
|
-
if (group.length > 0 && groupBytes + c.bytes > INDEX_WRITE_CHUNK && !flush()) return { bodies, raw, indexed, total, stop: "deadline" };
|
|
44631
|
+
if (group.length > 0 && groupBytes + c.bytes > INDEX_WRITE_CHUNK && !flush()) return { bodies, raw, ids, indexed, total, stop: "deadline" };
|
|
44454
44632
|
group.push(c);
|
|
44455
44633
|
groupBytes += c.bytes;
|
|
44456
44634
|
queued += c.bytes;
|
|
44457
44635
|
}
|
|
44458
44636
|
const stop = flush() ? null : "deadline";
|
|
44459
|
-
return { bodies, raw, indexed, total, stop };
|
|
44637
|
+
return { bodies, raw, ids, indexed, total, stop };
|
|
44460
44638
|
}
|
|
44461
44639
|
function bytes3(s) {
|
|
44462
44640
|
return Buffer.byteLength(s, "utf8");
|
|
44463
44641
|
}
|
|
44464
|
-
function answer(db, ctx,
|
|
44642
|
+
function answer(db, ctx, ownIds, queries, share, own4) {
|
|
44465
44643
|
const seen = /* @__PURE__ */ new Set();
|
|
44466
44644
|
const lines = [];
|
|
44467
44645
|
for (const [qi, q] of queries.entries()) {
|
|
44468
44646
|
if (ctx.signal.aborted) break;
|
|
44469
|
-
let hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0,
|
|
44647
|
+
let hits = ownIds.length === 0 ? [] : ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0, void 0, ownIds);
|
|
44470
44648
|
if (hits.length === 0) hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0);
|
|
44471
44649
|
const head = "## " + (bytes3(q) > ECHO_MAX_BYTES ? "query " + (qi + 1) : q);
|
|
44472
44650
|
let used = bytes3(head) + 1;
|
|
@@ -44505,9 +44683,10 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
44505
44683
|
const ran = pool.results;
|
|
44506
44684
|
const last2 = ran[ran.length - 1];
|
|
44507
44685
|
const sandboxBytes = ran.reduce((n, r) => n + r.bytes, 0);
|
|
44508
|
-
const label2 = LABEL_PREFIX + ctx.turn;
|
|
44509
44686
|
try {
|
|
44510
44687
|
const db = await openDb(ctx.project);
|
|
44688
|
+
const turnPrefix = LABEL_PREFIX + ctx.turn + LABEL_SEP;
|
|
44689
|
+
const label2 = turnPrefix + nextLabelSerial(db, ctx.sessionId, turnPrefix);
|
|
44511
44690
|
let sections;
|
|
44512
44691
|
let idx;
|
|
44513
44692
|
const exitLine = last2.exitCode === null || last2.exitCode === 0 ? null : "exit " + last2.exitCode;
|
|
@@ -44523,7 +44702,7 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
44523
44702
|
notice = cut === null ? stop : cause === null ? cut : cause + " " + cut;
|
|
44524
44703
|
const fixed = (exitLine === null ? 0 : bytes3(exitLine) + 1) + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
|
|
44525
44704
|
const share = Math.floor((OUTPUT_CAP - fixed) / queries.length);
|
|
44526
|
-
const answered = answer(db, ctx,
|
|
44705
|
+
const answered = answer(db, ctx, idx.ids, queries, share, idx.bodies);
|
|
44527
44706
|
sections = answered.lines;
|
|
44528
44707
|
const unseen = [...idx.bodies].filter(([k, text]) => text !== "" && !answered.seen.has(k)).map(([k]) => idx.raw.get(k));
|
|
44529
44708
|
const unseenBytes = unseen.reduce((n, t) => n + bytes3(t) + 1, 0);
|
|
@@ -44559,8 +44738,8 @@ var ctxBatch = Object.freeze({
|
|
|
44559
44738
|
});
|
|
44560
44739
|
|
|
44561
44740
|
// src/core/tools/doctor.ts
|
|
44562
|
-
import { readdirSync as
|
|
44563
|
-
import { basename as
|
|
44741
|
+
import { readdirSync as readdirSync7, readFileSync as readFileSync10, existsSync as existsSync14 } from "node:fs";
|
|
44742
|
+
import { basename as basename5, dirname as dirname7, join as join14 } from "node:path";
|
|
44564
44743
|
|
|
44565
44744
|
// src/adapters/claude-code.ts
|
|
44566
44745
|
var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
@@ -45449,11 +45628,11 @@ function getAdapter(id) {
|
|
|
45449
45628
|
}
|
|
45450
45629
|
|
|
45451
45630
|
// src/core/ops/doctor-config.ts
|
|
45452
|
-
import { existsSync as existsSync7, readdirSync as
|
|
45631
|
+
import { existsSync as existsSync7, readdirSync as readdirSync6 } from "node:fs";
|
|
45453
45632
|
import { join as join9 } from "node:path";
|
|
45454
45633
|
|
|
45455
45634
|
// src/core/ops/detect-v1.ts
|
|
45456
|
-
import { existsSync as existsSync5, opendirSync, readdirSync as
|
|
45635
|
+
import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync4, readFileSync as readFileSync5 } from "node:fs";
|
|
45457
45636
|
import { tmpdir } from "node:os";
|
|
45458
45637
|
import { join as join7 } from "node:path";
|
|
45459
45638
|
|
|
@@ -46447,9 +46626,9 @@ var Tokenizer = class {
|
|
|
46447
46626
|
cp = this.nextCode();
|
|
46448
46627
|
}
|
|
46449
46628
|
const { out } = this.parseDigits(cp, isDigit);
|
|
46450
|
-
const
|
|
46451
|
-
if (minus)
|
|
46452
|
-
const value = Number(leftMinus ? String.fromCodePoint(CodePoint.DASH, ...left, CodePoint.LATIN_SMALL_E, ...
|
|
46629
|
+
const right2 = out;
|
|
46630
|
+
if (minus) right2.unshift(CodePoint.DASH);
|
|
46631
|
+
const value = Number(leftMinus ? String.fromCodePoint(CodePoint.DASH, ...left, CodePoint.LATIN_SMALL_E, ...right2) : String.fromCodePoint(...left, CodePoint.LATIN_SMALL_E, ...right2));
|
|
46453
46632
|
this.endToken("Float", "start", value);
|
|
46454
46633
|
return this.back("DATA");
|
|
46455
46634
|
}
|
|
@@ -48196,7 +48375,7 @@ function scanVscode(agentHome, project, out) {
|
|
|
48196
48375
|
}
|
|
48197
48376
|
function jsonFiles(dir) {
|
|
48198
48377
|
try {
|
|
48199
|
-
return
|
|
48378
|
+
return readdirSync4(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
48200
48379
|
} catch {
|
|
48201
48380
|
return [];
|
|
48202
48381
|
}
|
|
@@ -48322,7 +48501,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
48322
48501
|
}
|
|
48323
48502
|
|
|
48324
48503
|
// src/core/ops/plugin-root.ts
|
|
48325
|
-
import { existsSync as existsSync6, readdirSync as
|
|
48504
|
+
import { existsSync as existsSync6, readdirSync as readdirSync5, readFileSync as readFileSync6, realpathSync as realpathSync4 } from "node:fs";
|
|
48326
48505
|
import { dirname as dirname5, isAbsolute, join as join8, sep as sep2 } from "node:path";
|
|
48327
48506
|
import { fileURLToPath } from "node:url";
|
|
48328
48507
|
function missing(agent, path7) {
|
|
@@ -48422,7 +48601,7 @@ function marketplaceRoot(adapter, env, worktree) {
|
|
|
48422
48601
|
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep2) && existsSync6(join8(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
48423
48602
|
const pattern = join8(cache, "*", PLUGIN_NAME);
|
|
48424
48603
|
if (!existsSync6(cache)) throw missing(adapter.id, pattern);
|
|
48425
|
-
const found =
|
|
48604
|
+
const found = readdirSync5(cache).sort().map((marketplace) => join8(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync6(dir));
|
|
48426
48605
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
48427
48606
|
return found[0];
|
|
48428
48607
|
}
|
|
@@ -48565,10 +48744,10 @@ function codexNativeDir(env, home) {
|
|
|
48565
48744
|
const cache = join9(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
48566
48745
|
if (!existsSync7(cache)) return null;
|
|
48567
48746
|
const found = [];
|
|
48568
|
-
for (const market of
|
|
48747
|
+
for (const market of readdirSync6(cache)) {
|
|
48569
48748
|
const plugin = join9(cache, market, SERVER_KEY);
|
|
48570
48749
|
if (!existsSync7(plugin)) continue;
|
|
48571
|
-
for (const version4 of
|
|
48750
|
+
for (const version4 of readdirSync6(plugin).sort()) {
|
|
48572
48751
|
const dir = join9(plugin, version4, CODEX_PLUGIN_SUBDIR);
|
|
48573
48752
|
if (existsSync7(join9(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
48574
48753
|
}
|
|
@@ -48653,7 +48832,7 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
48653
48832
|
const read = row5.id === "pi" ? mcpFile(row5, home, env) : null;
|
|
48654
48833
|
if (parts.length === 0) return read === null ? pass("D3") : { ...pass("D3"), detail: read };
|
|
48655
48834
|
const detail = D3_DETAIL(parts);
|
|
48656
|
-
const fix = parts.includes(PART_MCP)
|
|
48835
|
+
const fix = parts.includes(PART_MCP) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
|
|
48657
48836
|
return fail("D3", read === null ? detail : detail + D4_REASON_JOIN + read, fix);
|
|
48658
48837
|
}
|
|
48659
48838
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
@@ -48707,7 +48886,7 @@ function configPaths(row5, env, worktree) {
|
|
|
48707
48886
|
}
|
|
48708
48887
|
|
|
48709
48888
|
// src/core/ops/doctor-db.ts
|
|
48710
|
-
import { existsSync as existsSync8 } from "node:fs";
|
|
48889
|
+
import { existsSync as existsSync8, statSync as statSync4 } from "node:fs";
|
|
48711
48890
|
var unknown4 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
|
|
48712
48891
|
var pass2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
|
|
48713
48892
|
var fail2 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -48745,8 +48924,18 @@ function failsOnCorrupt(step) {
|
|
|
48745
48924
|
throw err;
|
|
48746
48925
|
}
|
|
48747
48926
|
}
|
|
48927
|
+
function orphanFiles(dbPath) {
|
|
48928
|
+
const files = [];
|
|
48929
|
+
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
48930
|
+
const path7 = dbPath + suffix;
|
|
48931
|
+
if (existsSync8(path7)) files.push({ path: path7, bytes: statSync4(path7).size });
|
|
48932
|
+
}
|
|
48933
|
+
return files.length > 0 && !existsSync8(dbPath) ? files : [];
|
|
48934
|
+
}
|
|
48748
48935
|
async function checkDb(project) {
|
|
48749
|
-
const clean = { schemaStale: false, integrityFailed: false };
|
|
48936
|
+
const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
|
|
48937
|
+
const orphan = orphanFiles(project.dbPath);
|
|
48938
|
+
if (orphan.length > 0) return { row: fail2(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
|
|
48750
48939
|
if (!existsSync8(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
48751
48940
|
const sqlite = await loadSqlite2();
|
|
48752
48941
|
if (sqlite === null) return { row: unknown4("D8", D2_SQLITE_DETAIL), ...clean };
|
|
@@ -48762,11 +48951,11 @@ async function checkDb(project) {
|
|
|
48762
48951
|
}
|
|
48763
48952
|
const schemaStale = got !== null && got !== SCHEMA_VERSION;
|
|
48764
48953
|
const integrityFailed = failsOnCorrupt(() => !integrityOk(db));
|
|
48765
|
-
if (integrityFailed) return { row: fail2(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale, integrityFailed };
|
|
48766
|
-
if (schemaStale && got !== null) return { row: fail2(D8_STALE_SCHEMA_DETAIL(got, SCHEMA_VERSION), DOCTOR_FIX_UPGRADE), schemaStale, integrityFailed };
|
|
48954
|
+
if (integrityFailed) return { row: fail2(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale, integrityFailed, orphan: [] };
|
|
48955
|
+
if (schemaStale && got !== null) return { row: fail2(D8_STALE_SCHEMA_DETAIL(got, SCHEMA_VERSION), DOCTOR_FIX_UPGRADE), schemaStale, integrityFailed, orphan: [] };
|
|
48767
48956
|
return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
48768
48957
|
} catch (err) {
|
|
48769
|
-
if (isCorrupt2(err)) return { row: fail2(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale: false, integrityFailed: true };
|
|
48958
|
+
if (isCorrupt2(err)) return { row: fail2(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale: false, integrityFailed: true, orphan: [] };
|
|
48770
48959
|
return { row: unknown4("D8", message(err)), ...clean };
|
|
48771
48960
|
} finally {
|
|
48772
48961
|
raw?.close();
|
|
@@ -48834,7 +49023,8 @@ function fetchCause(err, timeoutMs) {
|
|
|
48834
49023
|
const cause = err instanceof Error && err.cause instanceof Error ? err.cause : err;
|
|
48835
49024
|
const code = typeof cause === "object" && cause !== null && "code" in cause && typeof cause.code === "string" ? cause.code : "";
|
|
48836
49025
|
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
48837
|
-
|
|
49026
|
+
const parts = code !== "" && !msg.includes(code) ? [code, msg] : [msg];
|
|
49027
|
+
return D1_NPM_ERROR(parts.filter((part) => part !== "").join(" "));
|
|
48838
49028
|
}
|
|
48839
49029
|
async function npmLatest(url4, tag, signal, timeoutMs) {
|
|
48840
49030
|
try {
|
|
@@ -48947,9 +49137,9 @@ async function checkNode(i) {
|
|
|
48947
49137
|
return pass3("D2", bun.length === 0 ? DOCTOR_PASS_DETAIL : bun.join(D4_REASON_JOIN));
|
|
48948
49138
|
}
|
|
48949
49139
|
function checkMcp(ctx) {
|
|
48950
|
-
const
|
|
49140
|
+
const named2 = ctx.clientInfo !== void 0 && ctx.clientInfo.name !== "";
|
|
48951
49141
|
const versioned = ctx.protocolVersion !== void 0 && ctx.protocolVersion !== "";
|
|
48952
|
-
return
|
|
49142
|
+
return named2 || versioned ? pass3("D6") : unknown5("D6", D6_UNKNOWN_DETAIL);
|
|
48953
49143
|
}
|
|
48954
49144
|
function piCwdInside(worktree, piCwd) {
|
|
48955
49145
|
if (piCwd === void 0 || !existsSync9(piCwd)) return false;
|
|
@@ -48984,7 +49174,7 @@ import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
|
|
|
48984
49174
|
|
|
48985
49175
|
// src/setup/spawn-bin.ts
|
|
48986
49176
|
import { spawnSync } from "node:child_process";
|
|
48987
|
-
import { accessSync as accessSync2, constants as fsc, statSync as
|
|
49177
|
+
import { accessSync as accessSync2, constants as fsc, statSync as statSync5 } from "node:fs";
|
|
48988
49178
|
import path4 from "node:path";
|
|
48989
49179
|
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
48990
49180
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
@@ -49002,7 +49192,7 @@ function whichBin(bin, env, platform = process.platform) {
|
|
|
49002
49192
|
const f = path4.join(dir, n);
|
|
49003
49193
|
try {
|
|
49004
49194
|
accessSync2(f, fsc.X_OK);
|
|
49005
|
-
if (
|
|
49195
|
+
if (statSync5(f).isFile()) return f;
|
|
49006
49196
|
} catch {
|
|
49007
49197
|
}
|
|
49008
49198
|
}
|
|
@@ -49210,19 +49400,52 @@ function loadFixture(bundleDir2, agent) {
|
|
|
49210
49400
|
}
|
|
49211
49401
|
return { event: e.event, payload: e.payload };
|
|
49212
49402
|
}
|
|
49213
|
-
|
|
49214
|
-
|
|
49215
|
-
|
|
49216
|
-
|
|
49403
|
+
var CWD_KEY = {
|
|
49404
|
+
"claude-code": "cwd",
|
|
49405
|
+
codex: "cwd",
|
|
49406
|
+
gemini: "cwd",
|
|
49407
|
+
qwen: "cwd",
|
|
49408
|
+
"copilot-cli": "cwd",
|
|
49409
|
+
vscode: "cwd",
|
|
49410
|
+
kiro: "cwd",
|
|
49411
|
+
zcode: "cwd",
|
|
49412
|
+
pi: "cwd",
|
|
49413
|
+
opencode: "directory"
|
|
49414
|
+
};
|
|
49415
|
+
function payloadFor(agent, payload, worktree) {
|
|
49416
|
+
return worktree !== void 0 && isObject5(payload) ? { ...payload, [CWD_KEY[agent]]: worktree } : payload;
|
|
49417
|
+
}
|
|
49418
|
+
var SHAPE = {
|
|
49419
|
+
"claude-code": "claude",
|
|
49420
|
+
codex: "claude",
|
|
49421
|
+
qwen: "claude",
|
|
49422
|
+
vscode: "claude",
|
|
49423
|
+
zcode: "claude",
|
|
49424
|
+
gemini: "gemini",
|
|
49425
|
+
"copilot-cli": "copilot",
|
|
49426
|
+
kiro: "text",
|
|
49427
|
+
pi: "text",
|
|
49428
|
+
opencode: "text"
|
|
49429
|
+
};
|
|
49430
|
+
var COPILOT_KEYS = ["permissionDecision", "additionalContext", "modifiedResult"];
|
|
49431
|
+
function isNativeShape(agent, stdout, exitCode, killed, event) {
|
|
49217
49432
|
if (killed !== null || exitCode !== 0 && exitCode !== 2) return false;
|
|
49218
|
-
if (stdout.length === 0) return true;
|
|
49433
|
+
if (stdout.length === 0 || SHAPE[agent] === "text") return true;
|
|
49219
49434
|
let out;
|
|
49220
49435
|
try {
|
|
49221
49436
|
out = JSON.parse(stdout);
|
|
49222
49437
|
} catch {
|
|
49223
49438
|
return false;
|
|
49224
49439
|
}
|
|
49225
|
-
|
|
49440
|
+
if (!isObject5(out)) return false;
|
|
49441
|
+
switch (SHAPE[agent]) {
|
|
49442
|
+
case "claude":
|
|
49443
|
+
return isObject5(out.hookSpecificOutput) && out.hookSpecificOutput.hookEventName === event;
|
|
49444
|
+
case "gemini":
|
|
49445
|
+
return typeof out.decision === "string" || isObject5(out.hookSpecificOutput);
|
|
49446
|
+
default:
|
|
49447
|
+
return COPILOT_KEYS.some((k) => Object.hasOwn(out, k));
|
|
49448
|
+
}
|
|
49226
49449
|
}
|
|
49227
49450
|
function codexHookJournaled(db) {
|
|
49228
49451
|
if (db === null) return false;
|
|
@@ -49266,9 +49489,10 @@ async function checkHookRoundTrip(i) {
|
|
|
49266
49489
|
const fixed = i.samples === void 0 ? null : Math.max(1, i.samples);
|
|
49267
49490
|
const maxPairs = fixed ?? D5_MAX_PAIRS;
|
|
49268
49491
|
const minPairs = fixed ?? D5_MIN_PAIRS;
|
|
49492
|
+
const timeoutMs = i.timeoutMs ?? HOOK_TIMEOUT_MS;
|
|
49269
49493
|
const bareMs = i.bareMs ?? (async () => {
|
|
49270
49494
|
const t = performance.now();
|
|
49271
|
-
await runProcess([process.execPath, "-e", ""], { cwd: i.bundleDir, env: i.env, signal: i.signal, timeoutMs
|
|
49495
|
+
await runProcess([process.execPath, "-e", ""], { cwd: i.bundleDir, env: i.env, signal: i.signal, timeoutMs });
|
|
49272
49496
|
return performance.now() - t;
|
|
49273
49497
|
});
|
|
49274
49498
|
const hookWalls = [];
|
|
@@ -49280,11 +49504,11 @@ async function checkHookRoundTrip(i) {
|
|
|
49280
49504
|
cwd: i.bundleDir,
|
|
49281
49505
|
env: i.env,
|
|
49282
49506
|
signal: i.signal,
|
|
49283
|
-
timeoutMs
|
|
49284
|
-
stdin: JSON.stringify(payloadFor(fixture.payload, i.worktree))
|
|
49507
|
+
timeoutMs,
|
|
49508
|
+
stdin: JSON.stringify(payloadFor(i.agent, fixture.payload, i.worktree))
|
|
49285
49509
|
});
|
|
49286
49510
|
hookWalls.push(now() - start);
|
|
49287
|
-
if (!isNativeShape(r.stdout.toString("utf8"), r.exitCode, r.killed, fixture.event)) return row("FAIL", D5_SHAPE_DETAIL, D5_FIX);
|
|
49511
|
+
if (!isNativeShape(i.agent, r.stdout.toString("utf8"), r.exitCode, r.killed, fixture.event)) return row("FAIL", D5_SHAPE_DETAIL, D5_FIX);
|
|
49288
49512
|
bareWalls.push(await bareMs());
|
|
49289
49513
|
ms = Math.max(0, Math.round(Math.min(...hookWalls) - Math.min(...bareWalls)));
|
|
49290
49514
|
if (n >= minPairs && ms <= HOOK_P95_MS) break;
|
|
@@ -49331,7 +49555,8 @@ function lastHookError(env) {
|
|
|
49331
49555
|
}
|
|
49332
49556
|
|
|
49333
49557
|
// src/core/ops/db-heal.ts
|
|
49334
|
-
import { existsSync as existsSync12, rmSync as rmSync4 } from "node:fs";
|
|
49558
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
|
|
49559
|
+
import { basename as basename4, dirname as dirname6, join as join12 } from "node:path";
|
|
49335
49560
|
function integrityOk2(rows) {
|
|
49336
49561
|
return rows.length === 1 && rows[0].integrity_check === INTEGRITY_OK;
|
|
49337
49562
|
}
|
|
@@ -49384,6 +49609,39 @@ async function healD8(input) {
|
|
|
49384
49609
|
closeDb(await openDb(project));
|
|
49385
49610
|
return { ...row5, status: "FAIL", detail: D8_HEALED_RECREATE_DETAIL(ts) };
|
|
49386
49611
|
}
|
|
49612
|
+
function utcStamp(now) {
|
|
49613
|
+
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
49614
|
+
}
|
|
49615
|
+
function makeOrphanDir(projectDir) {
|
|
49616
|
+
const base = join12(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
49617
|
+
for (let n = 1; ; n += 1) {
|
|
49618
|
+
const dir = n === 1 ? base : base + "-" + String(n);
|
|
49619
|
+
try {
|
|
49620
|
+
mkdirSync5(dir);
|
|
49621
|
+
return dir;
|
|
49622
|
+
} catch (err) {
|
|
49623
|
+
if (err.code !== "EEXIST") throw err;
|
|
49624
|
+
}
|
|
49625
|
+
}
|
|
49626
|
+
}
|
|
49627
|
+
async function healOrphan(project, files, row5) {
|
|
49628
|
+
const moved = [];
|
|
49629
|
+
let dir = "";
|
|
49630
|
+
try {
|
|
49631
|
+
dir = makeOrphanDir(dirname6(project.dbPath));
|
|
49632
|
+
for (const f of files) {
|
|
49633
|
+
const to = join12(dir, basename4(f.path));
|
|
49634
|
+
renameWithRetry(f.path, to);
|
|
49635
|
+
moved.push({ path: to, bytes: f.bytes });
|
|
49636
|
+
}
|
|
49637
|
+
closeDb(await openDb(project));
|
|
49638
|
+
} catch (err) {
|
|
49639
|
+
const cause = err instanceof CtxError ? err.toLine() : err instanceof Error ? err.message : String(err);
|
|
49640
|
+
const at = moved.length > 0 ? D8_ORPHAN_HEALED_DETAIL(dir, moved, project.dbPath) : row5.detail;
|
|
49641
|
+
return { ...row5, detail: D8_ORPHAN_MOVE_FAILED(at, cause) };
|
|
49642
|
+
}
|
|
49643
|
+
return { ...row5, status: "FAIL", detail: D8_ORPHAN_HEALED_DETAIL(dir, moved, project.dbPath), fixCommand: D8_ORPHAN_HEALED_FIX };
|
|
49644
|
+
}
|
|
49387
49645
|
|
|
49388
49646
|
// src/core/ops/report.ts
|
|
49389
49647
|
function keyIsTyped(key) {
|
|
@@ -49439,8 +49697,8 @@ function buildReportHead(input) {
|
|
|
49439
49697
|
|
|
49440
49698
|
// src/core/ops/doctor-issue.ts
|
|
49441
49699
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
49442
|
-
import { closeSync, existsSync as existsSync13, fstatSync, mkdirSync as
|
|
49443
|
-
import { delimiter, join as
|
|
49700
|
+
import { closeSync, existsSync as existsSync13, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync9, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
|
|
49701
|
+
import { delimiter, join as join13 } from "node:path";
|
|
49444
49702
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
49445
49703
|
function tildeOf(env) {
|
|
49446
49704
|
const home = homeDirOf(env);
|
|
@@ -49457,9 +49715,9 @@ function tildeOf(env) {
|
|
|
49457
49715
|
}
|
|
49458
49716
|
function maskLine(line) {
|
|
49459
49717
|
const lower = line.toLowerCase();
|
|
49460
|
-
const
|
|
49718
|
+
const named2 = DOCTOR_SECRET_WORDS.some((w) => lower.includes(w));
|
|
49461
49719
|
const token = TOKEN_PREFIXES.some((p) => line.includes(p));
|
|
49462
|
-
if (!
|
|
49720
|
+
if (!named2 && !token) return line;
|
|
49463
49721
|
const at = Math.max(line.indexOf(":"), line.indexOf("="));
|
|
49464
49722
|
return at === -1 ? DOCTOR_MASK : line.slice(0, at + 1) + " " + DOCTOR_MASK;
|
|
49465
49723
|
}
|
|
@@ -49481,8 +49739,8 @@ function onPath(env, tool) {
|
|
|
49481
49739
|
const out = [];
|
|
49482
49740
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
49483
49741
|
if (dir === "") continue;
|
|
49484
|
-
for (const n of names) if (existsSync13(
|
|
49485
|
-
out.push(
|
|
49742
|
+
for (const n of names) if (existsSync13(join13(dir, n))) {
|
|
49743
|
+
out.push(join13(dir, n));
|
|
49486
49744
|
break;
|
|
49487
49745
|
}
|
|
49488
49746
|
}
|
|
@@ -49528,8 +49786,8 @@ function agentConfig(adapter, env, worktree) {
|
|
|
49528
49786
|
const home = homeDirOf(env);
|
|
49529
49787
|
const files = configPaths(adapter, env, worktree);
|
|
49530
49788
|
if (home !== null) {
|
|
49531
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
49532
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
49789
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join13(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
49790
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join13(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
49533
49791
|
}
|
|
49534
49792
|
const out = [];
|
|
49535
49793
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -49612,9 +49870,9 @@ async function buildIssueBody(i) {
|
|
|
49612
49870
|
async function writeIssueReport(i) {
|
|
49613
49871
|
const tilde = tildeOf(i.env);
|
|
49614
49872
|
const body = await buildIssueBody(i);
|
|
49615
|
-
const dir =
|
|
49616
|
-
|
|
49617
|
-
const file2 =
|
|
49873
|
+
const dir = join13(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
49874
|
+
mkdirSync6(dir, { recursive: true });
|
|
49875
|
+
const file2 = join13(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
49618
49876
|
writeFileSync3(file2, body);
|
|
49619
49877
|
const shown2 = tilde(file2);
|
|
49620
49878
|
const title = issueTitle(i.adapter.id, i.rows);
|
|
@@ -49690,11 +49948,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
49690
49948
|
}
|
|
49691
49949
|
}
|
|
49692
49950
|
function ownServerId(configDir, projectKey) {
|
|
49693
|
-
const dir =
|
|
49951
|
+
const dir = join14(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
49694
49952
|
if (!existsSync14(dir)) return "";
|
|
49695
|
-
for (const name of
|
|
49953
|
+
for (const name of readdirSync7(dir)) {
|
|
49696
49954
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
49697
|
-
if (readFileSync10(
|
|
49955
|
+
if (readFileSync10(join14(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
49698
49956
|
}
|
|
49699
49957
|
return "";
|
|
49700
49958
|
}
|
|
@@ -49703,6 +49961,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
49703
49961
|
const env = host.env;
|
|
49704
49962
|
const project = ctx.project;
|
|
49705
49963
|
let integrityFailed = false;
|
|
49964
|
+
let orphan = [];
|
|
49706
49965
|
const checks = {
|
|
49707
49966
|
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 }),
|
|
49708
49967
|
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
@@ -49715,6 +49974,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
49715
49974
|
D8: async () => {
|
|
49716
49975
|
const r = await checkDb(project);
|
|
49717
49976
|
integrityFailed = r.integrityFailed;
|
|
49977
|
+
orphan = r.orphan;
|
|
49718
49978
|
return r.row;
|
|
49719
49979
|
},
|
|
49720
49980
|
D9: () => checkIndex(project),
|
|
@@ -49723,8 +49983,13 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
49723
49983
|
};
|
|
49724
49984
|
const rows = [];
|
|
49725
49985
|
for (const id of DOCTOR_CHECK_ORDER) rows.push(await guard(id, checks[id]));
|
|
49726
|
-
if (!integrityFailed) return rows;
|
|
49727
49986
|
const at = DOCTOR_CHECK_ORDER.indexOf("D8");
|
|
49987
|
+
if (orphan.length > 0) {
|
|
49988
|
+
const files = orphan;
|
|
49989
|
+
rows[at] = await guard("D8", () => healOrphan(project, files, rows[at]));
|
|
49990
|
+
return rows;
|
|
49991
|
+
}
|
|
49992
|
+
if (!integrityFailed) return rows;
|
|
49728
49993
|
rows[at] = await guard("D8", () => {
|
|
49729
49994
|
const configDir = resolveConfigDir(env);
|
|
49730
49995
|
return healD8({ project, configDir, serverId: ownServerId(configDir, project.projectKey), row: rows[at] });
|
|
@@ -49770,7 +50035,7 @@ async function doctorReply(ctx, host) {
|
|
|
49770
50035
|
return { text, isError: false, sandboxBytes: bytes5 };
|
|
49771
50036
|
}
|
|
49772
50037
|
async function handler2(_input, ctx) {
|
|
49773
|
-
return doctorReply(ctx, { env: process.env, bundleDir:
|
|
50038
|
+
return doctorReply(ctx, { env: process.env, bundleDir: dirname7(process.argv[1]), piCwd: void 0 });
|
|
49774
50039
|
}
|
|
49775
50040
|
var ctxDoctor = Object.freeze({
|
|
49776
50041
|
name: "ctx_doctor",
|
|
@@ -49784,7 +50049,7 @@ var ctxDoctor = Object.freeze({
|
|
|
49784
50049
|
// src/core/tools/execute.ts
|
|
49785
50050
|
import { existsSync as existsSync15, mkdtempSync, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
49786
50051
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
49787
|
-
import { dirname as
|
|
50052
|
+
import { dirname as dirname8, join as join15, parse as parse5, resolve as resolve4 } from "node:path";
|
|
49788
50053
|
|
|
49789
50054
|
// src/core/index/select.ts
|
|
49790
50055
|
var READ_CHUNKS = "SELECT ord, body FROM chunks WHERE source_id = ?";
|
|
@@ -49907,7 +50172,7 @@ function schemaLine(issue4) {
|
|
|
49907
50172
|
}
|
|
49908
50173
|
function fileError(given, abs, root) {
|
|
49909
50174
|
let dir = abs;
|
|
49910
|
-
while (!existsSync15(dir) &&
|
|
50175
|
+
while (!existsSync15(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
|
|
49911
50176
|
if (isInside(root, dir)) return null;
|
|
49912
50177
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
49913
50178
|
}
|
|
@@ -49988,8 +50253,8 @@ async function handler3(raw, ctx) {
|
|
|
49988
50253
|
if (takesDashC(input.language, runtime)) {
|
|
49989
50254
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
49990
50255
|
} else {
|
|
49991
|
-
tmpDir = mkdtempSync(
|
|
49992
|
-
const file2 =
|
|
50256
|
+
tmpDir = mkdtempSync(join15(tmpdir2(), TMP_PREFIX));
|
|
50257
|
+
const file2 = join15(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
49993
50258
|
writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
|
|
49994
50259
|
argv = scriptArgv(input.language, runtime, file2);
|
|
49995
50260
|
}
|
|
@@ -50024,12 +50289,12 @@ var ctxExecute = {
|
|
|
50024
50289
|
};
|
|
50025
50290
|
|
|
50026
50291
|
// src/core/tools/index.ts
|
|
50027
|
-
import { existsSync as existsSync16, readFileSync as readFileSync12, statSync as
|
|
50028
|
-
import { dirname as
|
|
50292
|
+
import { existsSync as existsSync16, readFileSync as readFileSync12, statSync as statSync7 } from "node:fs";
|
|
50293
|
+
import { dirname as dirname9, extname, join as join17, relative as relative2, resolve as resolve5 } from "node:path";
|
|
50029
50294
|
|
|
50030
50295
|
// src/core/index/walk.ts
|
|
50031
|
-
import { readdirSync as
|
|
50032
|
-
import { join as
|
|
50296
|
+
import { readdirSync as readdirSync8, readFileSync as readFileSync11, realpathSync as realpathSync9, statSync as statSync6 } from "node:fs";
|
|
50297
|
+
import { join as join16 } from "node:path";
|
|
50033
50298
|
var GITIGNORE = ".gitignore";
|
|
50034
50299
|
var GIT_DIR = ".git";
|
|
50035
50300
|
function walkDir(root, containmentRoot) {
|
|
@@ -50038,19 +50303,19 @@ function walkDir(root, containmentRoot) {
|
|
|
50038
50303
|
const found = [];
|
|
50039
50304
|
visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
|
|
50040
50305
|
found.sort(compareFound);
|
|
50041
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
50306
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join16(...f.dir, f.name) }));
|
|
50042
50307
|
}
|
|
50043
50308
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
50044
50309
|
let entries;
|
|
50045
50310
|
try {
|
|
50046
|
-
entries =
|
|
50311
|
+
entries = readdirSync8(abs, { withFileTypes: true });
|
|
50047
50312
|
} catch {
|
|
50048
50313
|
return;
|
|
50049
50314
|
}
|
|
50050
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
50315
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join16(abs, GITIGNORE), rel)) : parent;
|
|
50051
50316
|
for (const e of entries) {
|
|
50052
50317
|
if (e.name === GIT_DIR) continue;
|
|
50053
|
-
const path7 =
|
|
50318
|
+
const path7 = join16(abs, e.name);
|
|
50054
50319
|
let isDir = e.isDirectory();
|
|
50055
50320
|
let isFile = e.isFile();
|
|
50056
50321
|
let target = path7;
|
|
@@ -50062,7 +50327,7 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
50062
50327
|
continue;
|
|
50063
50328
|
}
|
|
50064
50329
|
if (!isInside(contain, resolved)) continue;
|
|
50065
|
-
const st =
|
|
50330
|
+
const st = statSync6(resolved);
|
|
50066
50331
|
isDir = st.isDirectory();
|
|
50067
50332
|
isFile = st.isFile();
|
|
50068
50333
|
target = resolved;
|
|
@@ -54180,7 +54445,7 @@ function readUtf8(absPath) {
|
|
|
54180
54445
|
}
|
|
54181
54446
|
function missingOrOutside(given, abs, root) {
|
|
54182
54447
|
let dir = abs;
|
|
54183
|
-
while (!existsSync16(dir) &&
|
|
54448
|
+
while (!existsSync16(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
|
|
54184
54449
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
54185
54450
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
54186
54451
|
}
|
|
@@ -54188,10 +54453,10 @@ function pathItems(input, project) {
|
|
|
54188
54453
|
const abs = resolve5(project.worktree, input.path);
|
|
54189
54454
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
54190
54455
|
const base = relative2(project.worktree, abs);
|
|
54191
|
-
if (
|
|
54456
|
+
if (statSync7(abs).isDirectory()) {
|
|
54192
54457
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
54193
54458
|
sourceKind: "path",
|
|
54194
|
-
label: pathLabel(
|
|
54459
|
+
label: pathLabel(join17(base, f.relPath)),
|
|
54195
54460
|
kind: kindOfPath(f.relPath),
|
|
54196
54461
|
read: () => readUtf8(f.absPath)
|
|
54197
54462
|
}));
|
|
@@ -54263,8 +54528,9 @@ async function handler4(input, ctx) {
|
|
|
54263
54528
|
} finally {
|
|
54264
54529
|
closeDb(db);
|
|
54265
54530
|
}
|
|
54266
|
-
const
|
|
54267
|
-
const
|
|
54531
|
+
const head = "Indexed " + sources + " source(s), " + chunks + " chunk(s) from ";
|
|
54532
|
+
const first = sources === 1 && lastId > 0 ? head + sourceHandle(lastId) + ". " + indexedLabelLine(from, lastId) : head + shownLabel(from, null) + ".";
|
|
54533
|
+
const line = [first, ...notes].join("\n");
|
|
54268
54534
|
return {
|
|
54269
54535
|
text: capBytes(line, OUTPUT_CAP).text,
|
|
54270
54536
|
isError: false,
|
|
@@ -54308,7 +54574,7 @@ function purgeScope(db, scope, input) {
|
|
|
54308
54574
|
const raw = db.raw;
|
|
54309
54575
|
if (scope === "session") return changes(raw, "DELETE FROM events WHERE session_id = ?", input.session);
|
|
54310
54576
|
if (scope === "source") {
|
|
54311
|
-
const label2 =
|
|
54577
|
+
const label2 = pickSource(db, input.source, false).label;
|
|
54312
54578
|
return deleteChunkRows(raw, { label: label2 }) + changes(raw, "DELETE FROM sources WHERE label = ?", label2);
|
|
54313
54579
|
}
|
|
54314
54580
|
const chunks = deleteChunkRows(raw, "all");
|
|
@@ -54772,6 +55038,9 @@ function bytes4(n) {
|
|
|
54772
55038
|
}
|
|
54773
55039
|
return v.toFixed(1) + " " + UNITS[u];
|
|
54774
55040
|
}
|
|
55041
|
+
function right(v, width) {
|
|
55042
|
+
return " " + v.padStart(width - 1);
|
|
55043
|
+
}
|
|
54775
55044
|
function pct(t) {
|
|
54776
55045
|
return (t.saved * PERCENT_SCALE / Math.max(1, t.produced)).toFixed(1) + "%";
|
|
54777
55046
|
}
|
|
@@ -54795,8 +55064,8 @@ function plural(n, word) {
|
|
|
54795
55064
|
}
|
|
54796
55065
|
function table2(title, rows) {
|
|
54797
55066
|
const max = Math.max(0, ...rows.map((r) => r.saved));
|
|
54798
|
-
const head = " " + title.padEnd(LABEL_W) + "Calls"
|
|
54799
|
-
return [head, ...rows.map((r) => (" " + label(r.name) + count(r.calls)
|
|
55067
|
+
const head = " " + title.padEnd(LABEL_W) + right("Calls", STATS_CALLS_W) + right("Made", NUM_W) + right("Sent", NUM_W) + right("Kept out", NUM_W) + right("%", PCT_W);
|
|
55068
|
+
return [head, ...rows.map((r) => (" " + label(r.name) + right(count(r.calls), STATS_CALLS_W) + right(bytes4(r.produced), NUM_W) + right(bytes4(r.returned), NUM_W) + right(bytes4(r.saved), NUM_W) + right(pct(r), PCT_W) + " " + bar(r.saved, max, STATS_ROW_BAR)).trimEnd())];
|
|
54800
55069
|
}
|
|
54801
55070
|
function bySaved(a, b) {
|
|
54802
55071
|
return b.saved - a.saved || b.produced - a.produced || a.returned - b.returned || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
@@ -54808,14 +55077,14 @@ function joinIndex(tools) {
|
|
|
54808
55077
|
const idx = tools.filter((t2) => STATS_INDEX_TOOLS.includes(t2.name));
|
|
54809
55078
|
if (idx.length <= 1) return tools;
|
|
54810
55079
|
const t = sum(idx);
|
|
54811
|
-
const one = { name: STATS_INDEX_TOOLS.join(" + ").replace(" + ctx_", " + "), ...t, saved: t.produced - t.returned };
|
|
55080
|
+
const one = { name: STATS_INDEX_TOOLS.join(" + ").replace(" + ctx_", " + "), ...t, saved: Math.max(0, t.produced - t.returned) };
|
|
54812
55081
|
return [...tools.filter((x) => !idx.includes(x)), one];
|
|
54813
55082
|
}
|
|
54814
55083
|
function toolRows(tools) {
|
|
54815
|
-
const
|
|
54816
|
-
const zero =
|
|
55084
|
+
const named2 = joinIndex(tools.map((t) => ({ ...t, saved: Math.max(0, t.produced - t.returned) }))).map((t) => ({ ...t, name: toolName(t.name) })).sort(bySaved);
|
|
55085
|
+
const zero = named2.filter((t) => t.saved <= 0);
|
|
54817
55086
|
const fold = zero.length > 1 ? zero : [];
|
|
54818
|
-
const keep =
|
|
55087
|
+
const keep = named2.filter((t) => !fold.includes(t));
|
|
54819
55088
|
const room = fold.length > 0 ? STATS_MAX_TOOL_ROWS - 1 : STATS_MAX_TOOL_ROWS;
|
|
54820
55089
|
const over = keep.length > room;
|
|
54821
55090
|
const shown2 = over ? keep.slice(0, STATS_MAX_TOOL_ROWS - 1) : keep;
|
|
@@ -54883,7 +55152,7 @@ function lastDays(week, allCalls) {
|
|
|
54883
55152
|
return [
|
|
54884
55153
|
head,
|
|
54885
55154
|
...card,
|
|
54886
|
-
...week.flatMap((d, i) => saved[i] > 0 ? [" " + mmdd(d.day) + " " + stack(STATS_WAYS.map(([w]) => d.ways[w]), max, STATS_DAY_BAR).padEnd(STATS_DAY_BAR) + bytes4(saved[i])
|
|
55155
|
+
...week.flatMap((d, i) => saved[i] > 0 ? [" " + mmdd(d.day) + " " + stack(STATS_WAYS.map(([w]) => d.ways[w]), max, STATS_DAY_BAR).padEnd(STATS_DAY_BAR) + right(bytes4(saved[i]), NUM_W)] : []),
|
|
54887
55156
|
" " + STATS_WAYS.map(([, ch, name]) => `${ch} ${name}`).join(" "),
|
|
54888
55157
|
""
|
|
54889
55158
|
];
|
|
@@ -54911,8 +55180,8 @@ function report(f, sessionId, agent) {
|
|
|
54911
55180
|
...head,
|
|
54912
55181
|
`${scopeName} \xB7 ${plural(focus.calls, "call")}${extra}`,
|
|
54913
55182
|
` ${bytes4(focus.produced)} became ${bytes4(focus.returned)}: ${bytes4(focus.saved)} kept out (${pct(focus)})`,
|
|
54914
|
-
" " + "Without context-mode".padEnd(LABEL_W) + "|" + bar(focus.produced, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.produced)
|
|
54915
|
-
" " + "With context-mode".padEnd(LABEL_W) + "|" + bar(focus.returned, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.returned)
|
|
55183
|
+
" " + "Without context-mode".padEnd(LABEL_W) + "|" + bar(focus.produced, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + right(bytes4(focus.produced), NUM_W),
|
|
55184
|
+
" " + "With context-mode".padEnd(LABEL_W) + "|" + bar(focus.returned, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + right(bytes4(focus.returned), NUM_W),
|
|
54916
55185
|
...focus.saved > 0 ? [windowLine(focus.saved), STATS_TOKEN_NOTE] : [],
|
|
54917
55186
|
...hookLine(f.redirected, f.replaced),
|
|
54918
55187
|
"",
|
|
@@ -54926,7 +55195,7 @@ function report(f, sessionId, agent) {
|
|
|
54926
55195
|
"",
|
|
54927
55196
|
...f.top.length > 0 ? [
|
|
54928
55197
|
"Largest single outputs (made \u2192 sent to the chat)",
|
|
54929
|
-
...f.top.map((t) => " " + label(toolName(t.name)) + bytes4(t.produced)
|
|
55198
|
+
...f.top.map((t) => " " + label(toolName(t.name)) + right(bytes4(t.produced), NUM_W) + " \u2192 " + right(bytes4(t.returned), NUM_W)),
|
|
54930
55199
|
""
|
|
54931
55200
|
] : []
|
|
54932
55201
|
];
|
|
@@ -54935,10 +55204,10 @@ function report(f, sessionId, agent) {
|
|
|
54935
55204
|
if (!agents.has(agent)) agents.set(agent, EMPTY3);
|
|
54936
55205
|
lines.push("By agent (this project)", ...table2("Agent", [...agents].map(([name, t]) => ({ name, ...t })).sort(bySaved)), "");
|
|
54937
55206
|
const maxKind = Math.max(0, ...[...f.kinds.values()].map((k) => k.project));
|
|
54938
|
-
lines.push("Kept in the session journal", " " + "Journal".padEnd(LABEL_W) + "Session"
|
|
55207
|
+
lines.push("Kept in the session journal", " " + "Journal".padEnd(LABEL_W) + right("Session", STATS_KIND_W) + right("Project", STATS_KIND_W));
|
|
54939
55208
|
for (const [kind, name] of STATS_KIND_LABELS) {
|
|
54940
55209
|
const k = f.kinds.get(kind) ?? { session: 0, project: 0 };
|
|
54941
|
-
lines.push((" " + label(name) + int4(k.session)
|
|
55210
|
+
lines.push((" " + label(name) + right(int4(k.session), STATS_KIND_W) + right(int4(k.project), STATS_KIND_W) + " " + bar(k.project, maxKind, STATS_KIND_BAR)).trimEnd());
|
|
54942
55211
|
}
|
|
54943
55212
|
lines.push("", ...STATS_JOURNAL_HINTS.map((h) => " " + h), "");
|
|
54944
55213
|
lines.push(
|
|
@@ -54955,7 +55224,14 @@ async function handler7(_input, ctx) {
|
|
|
54955
55224
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
54956
55225
|
let facts;
|
|
54957
55226
|
try {
|
|
54958
|
-
|
|
55227
|
+
db.raw.exec("BEGIN DEFERRED");
|
|
55228
|
+
try {
|
|
55229
|
+
facts = readFacts(db.raw, ctx.sessionId);
|
|
55230
|
+
db.raw.exec("COMMIT");
|
|
55231
|
+
} catch (err) {
|
|
55232
|
+
if (db.raw.isTransaction) db.raw.exec("ROLLBACK");
|
|
55233
|
+
throw err;
|
|
55234
|
+
}
|
|
54959
55235
|
} finally {
|
|
54960
55236
|
closeDb(db);
|
|
54961
55237
|
}
|
|
@@ -54986,11 +55262,11 @@ var ctxStats = Object.freeze({
|
|
|
54986
55262
|
|
|
54987
55263
|
// src/core/tools/upgrade.ts
|
|
54988
55264
|
import { existsSync as existsSync22, realpathSync as realpathSync10, rmSync as rmSync10 } from "node:fs";
|
|
54989
|
-
import { basename as
|
|
55265
|
+
import { basename as basename7, dirname as dirname11, join as join23 } from "node:path";
|
|
54990
55266
|
|
|
54991
55267
|
// src/core/ops/host-write.ts
|
|
54992
|
-
import { copyFileSync, existsSync as existsSync17, mkdirSync as
|
|
54993
|
-
import { dirname as
|
|
55268
|
+
import { copyFileSync, existsSync as existsSync17, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
55269
|
+
import { dirname as dirname10, join as join18 } from "node:path";
|
|
54994
55270
|
function defaultWrite(file2, text) {
|
|
54995
55271
|
writeFileSync5(file2, text, "utf8");
|
|
54996
55272
|
}
|
|
@@ -54999,14 +55275,14 @@ function hostConfigPath(agent, home, env) {
|
|
|
54999
55275
|
if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
|
|
55000
55276
|
switch (agent) {
|
|
55001
55277
|
case "opencode":
|
|
55002
|
-
return
|
|
55278
|
+
return join18(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
55003
55279
|
// D-WIN-OPENCODE-DIR-1
|
|
55004
55280
|
case "pi":
|
|
55005
|
-
return
|
|
55281
|
+
return join18(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
55006
55282
|
case "copilot-cli":
|
|
55007
55283
|
return null;
|
|
55008
55284
|
default:
|
|
55009
|
-
return
|
|
55285
|
+
return join18(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
55010
55286
|
}
|
|
55011
55287
|
}
|
|
55012
55288
|
function cell3(value) {
|
|
@@ -55019,7 +55295,7 @@ function writeWithRollback(file2, text, write, atomic) {
|
|
|
55019
55295
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
55020
55296
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
55021
55297
|
const had = existsSync17(file2);
|
|
55022
|
-
|
|
55298
|
+
mkdirSync7(dirname10(file2), { recursive: true });
|
|
55023
55299
|
if (had) copyFileSync(file2, trash);
|
|
55024
55300
|
try {
|
|
55025
55301
|
write(tmp, text);
|
|
@@ -55056,8 +55332,8 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
55056
55332
|
}
|
|
55057
55333
|
|
|
55058
55334
|
// src/core/ops/plugin-swap.ts
|
|
55059
|
-
import { existsSync as existsSync18, lstatSync, readdirSync as
|
|
55060
|
-
import { basename as
|
|
55335
|
+
import { existsSync as existsSync18, lstatSync, readdirSync as readdirSync9, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
55336
|
+
import { basename as basename6, join as join19, win32 as win322 } from "node:path";
|
|
55061
55337
|
function linkTarget(path7, win) {
|
|
55062
55338
|
if (!isLink(path7)) return null;
|
|
55063
55339
|
const target = readlinkSync(path7);
|
|
@@ -55067,7 +55343,7 @@ function isLink(path7) {
|
|
|
55067
55343
|
return lstatSync(path7, { throwIfNoEntry: false })?.isSymbolicLink() === true;
|
|
55068
55344
|
}
|
|
55069
55345
|
function generations(agentDir) {
|
|
55070
|
-
return
|
|
55346
|
+
return readdirSync9(agentDir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).filter((name) => !name.startsWith(UPGRADE_FETCH_DIR_PREFIX) && !name.endsWith(UPGRADE_TRASH_SUFFIX)).sort();
|
|
55071
55347
|
}
|
|
55072
55348
|
function settleLinks(link, tmp, old, opts) {
|
|
55073
55349
|
if (isLink(tmp)) unlinkSync2(tmp);
|
|
@@ -55076,11 +55352,11 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
55076
55352
|
else renameWithRetry(old, link, opts);
|
|
55077
55353
|
}
|
|
55078
55354
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
55079
|
-
const next =
|
|
55355
|
+
const next = join19(agentDir, sha);
|
|
55080
55356
|
if (!existsSync18(next) || !lstatSync(next).isDirectory()) {
|
|
55081
|
-
throw new CtxError("PLUGIN_ROOT_MISSING", { agent:
|
|
55357
|
+
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
|
|
55082
55358
|
}
|
|
55083
|
-
const link =
|
|
55359
|
+
const link = join19(agentDir, PLUGIN_CURRENT_LINK);
|
|
55084
55360
|
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
55085
55361
|
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
55086
55362
|
settleLinks(link, tmp, old, opts);
|
|
@@ -55095,15 +55371,15 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
55095
55371
|
if (before !== null) unlinkSync2(old);
|
|
55096
55372
|
const keep = /* @__PURE__ */ new Set([sha]);
|
|
55097
55373
|
if (before !== null) keep.add(before);
|
|
55098
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) =>
|
|
55374
|
+
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join19(agentDir, name));
|
|
55099
55375
|
for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
|
|
55100
|
-
const previous = before !== null && existsSync18(
|
|
55376
|
+
const previous = before !== null && existsSync18(join19(agentDir, before)) ? join19(agentDir, before) : null;
|
|
55101
55377
|
return { current: next, previous, removed };
|
|
55102
55378
|
}
|
|
55103
55379
|
|
|
55104
55380
|
// src/core/ops/release-fetch.ts
|
|
55105
|
-
import { existsSync as existsSync19, mkdirSync as
|
|
55106
|
-
import { join as
|
|
55381
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
|
|
55382
|
+
import { join as join20 } from "node:path";
|
|
55107
55383
|
function failed(r) {
|
|
55108
55384
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
55109
55385
|
const status = r.killed ?? String(r.exitCode);
|
|
@@ -55115,9 +55391,9 @@ async function git2(bin, args, cwd, env, signal) {
|
|
|
55115
55391
|
return r.stdout.toString().trim();
|
|
55116
55392
|
}
|
|
55117
55393
|
async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
55118
|
-
const agentDir =
|
|
55119
|
-
|
|
55120
|
-
const fetchDir =
|
|
55394
|
+
const agentDir = join20(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
55395
|
+
mkdirSync8(agentDir, { recursive: true });
|
|
55396
|
+
const fetchDir = join20(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
55121
55397
|
rmSync7(fetchDir, { recursive: true, force: true });
|
|
55122
55398
|
const gitBin = findRuntime(GIT_BIN, env);
|
|
55123
55399
|
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -55125,7 +55401,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
55125
55401
|
try {
|
|
55126
55402
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
|
|
55127
55403
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
55128
|
-
const dir =
|
|
55404
|
+
const dir = join20(agentDir, sha);
|
|
55129
55405
|
if (existsSync19(dir)) rmSync7(fetchDir, { recursive: true, force: true });
|
|
55130
55406
|
else renameWithRetry(fetchDir, dir, opts);
|
|
55131
55407
|
return { sha, dir };
|
|
@@ -55136,15 +55412,15 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
55136
55412
|
}
|
|
55137
55413
|
|
|
55138
55414
|
// src/core/ops/uninstall.ts
|
|
55139
|
-
import { existsSync as existsSync20, readdirSync as
|
|
55140
|
-
import { join as
|
|
55415
|
+
import { existsSync as existsSync20, readdirSync as readdirSync10, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
55416
|
+
import { join as join21 } from "node:path";
|
|
55141
55417
|
function row2(area, before, after) {
|
|
55142
55418
|
return { area, before, after };
|
|
55143
55419
|
}
|
|
55144
55420
|
function stopServers(configDir, projectKey) {
|
|
55145
55421
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
55146
|
-
const dir =
|
|
55147
|
-
for (const serverId of stopped) writeFileSync6(
|
|
55422
|
+
const dir = join21(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
55423
|
+
for (const serverId of stopped) writeFileSync6(join21(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
55148
55424
|
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 };
|
|
55149
55425
|
}
|
|
55150
55426
|
function rootOrNull(adapter, env) {
|
|
@@ -55162,14 +55438,14 @@ function removeCache(adapter, env, configDir) {
|
|
|
55162
55438
|
const root = rootOrNull(adapter, env);
|
|
55163
55439
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
55164
55440
|
if (adapter.installMode === "marketplace") {
|
|
55165
|
-
const cache =
|
|
55441
|
+
const cache = join21(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
55166
55442
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
55167
55443
|
}
|
|
55168
55444
|
rmSync8(root, { recursive: true, force: true });
|
|
55169
55445
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
55170
55446
|
}
|
|
55171
55447
|
case "plugin": {
|
|
55172
|
-
const agentDir =
|
|
55448
|
+
const agentDir = join21(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
55173
55449
|
if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
55174
55450
|
rmSync8(agentDir, { recursive: true, force: true });
|
|
55175
55451
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
@@ -55215,7 +55491,7 @@ function ownEntries(agent, env) {
|
|
|
55215
55491
|
}
|
|
55216
55492
|
if (agent === "opencode") {
|
|
55217
55493
|
return [{
|
|
55218
|
-
file:
|
|
55494
|
+
file: join21(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
55219
55495
|
// D-WIN-OPENCODE-DIR-1
|
|
55220
55496
|
key: OPENCODE_PLUGIN_KEY,
|
|
55221
55497
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -55226,7 +55502,7 @@ function ownEntries(agent, env) {
|
|
|
55226
55502
|
if (agent === "pi") {
|
|
55227
55503
|
const agentDir = piAgentDirOf(env, home);
|
|
55228
55504
|
return [{
|
|
55229
|
-
file:
|
|
55505
|
+
file: join21(agentDir, SETTINGS_FILE),
|
|
55230
55506
|
key: PI_PACKAGES_KEY,
|
|
55231
55507
|
shown: PI_PACKAGES_KEY,
|
|
55232
55508
|
has: (v) => Array.isArray(v) && v.some((x) => piSource(x) === PI_GIT_PACKAGE),
|
|
@@ -55248,12 +55524,12 @@ function removeOwnEntries(agent, env) {
|
|
|
55248
55524
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
55249
55525
|
}
|
|
55250
55526
|
function removeProjectData(configDir, projectKey) {
|
|
55251
|
-
const projects =
|
|
55252
|
-
const dir =
|
|
55527
|
+
const projects = join21(configDir, PROJECTS_DIR_NAME);
|
|
55528
|
+
const dir = join21(projects, projectKey);
|
|
55253
55529
|
if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
55254
55530
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
55255
|
-
for (const name of
|
|
55256
|
-
if (name !== OWNERS_DIR_NAME) rmSync8(
|
|
55531
|
+
for (const name of readdirSync10(dir)) {
|
|
55532
|
+
if (name !== OWNERS_DIR_NAME) rmSync8(join21(dir, name), { recursive: true, force: true });
|
|
55257
55533
|
}
|
|
55258
55534
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
55259
55535
|
}
|
|
@@ -55261,7 +55537,7 @@ function runUninstall(input) {
|
|
|
55261
55537
|
const configDir = resolveConfigDir(input.env);
|
|
55262
55538
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
55263
55539
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
55264
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
55540
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join21(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
55265
55541
|
return { rows, stopped: stop.stopped };
|
|
55266
55542
|
}
|
|
55267
55543
|
|
|
@@ -55397,8 +55673,8 @@ function removeV1(agent, findings) {
|
|
|
55397
55673
|
|
|
55398
55674
|
// src/core/ops/verify-sums.ts
|
|
55399
55675
|
import { createHash as createHash2 } from "node:crypto";
|
|
55400
|
-
import { lstatSync as lstatSync2, readdirSync as
|
|
55401
|
-
import { join as
|
|
55676
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync11, readFileSync as readFileSync14 } from "node:fs";
|
|
55677
|
+
import { join as join22 } from "node:path";
|
|
55402
55678
|
function mismatch() {
|
|
55403
55679
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
55404
55680
|
}
|
|
@@ -55416,17 +55692,17 @@ function parseSums(text) {
|
|
|
55416
55692
|
return sums;
|
|
55417
55693
|
}
|
|
55418
55694
|
function walk2(dir, prefix, out) {
|
|
55419
|
-
for (const entry of
|
|
55695
|
+
for (const entry of readdirSync11(dir, { withFileTypes: true })) {
|
|
55420
55696
|
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
55421
55697
|
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
55422
|
-
const abs =
|
|
55698
|
+
const abs = join22(dir, entry.name);
|
|
55423
55699
|
if (entry.isDirectory()) walk2(abs, rel, out);
|
|
55424
55700
|
else if (entry.isFile()) out.set(rel, abs);
|
|
55425
55701
|
else throw mismatch();
|
|
55426
55702
|
}
|
|
55427
55703
|
}
|
|
55428
55704
|
function verifySums(dir) {
|
|
55429
|
-
const sumsPath =
|
|
55705
|
+
const sumsPath = join22(dir, RELEASE_SUMS_FILE);
|
|
55430
55706
|
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
55431
55707
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
55432
55708
|
const sums = parseSums(readFileSync14(sumsPath, "utf8"));
|
|
@@ -55450,7 +55726,7 @@ function row4(area, before, after) {
|
|
|
55450
55726
|
return { area, before, after };
|
|
55451
55727
|
}
|
|
55452
55728
|
function bundleDir() {
|
|
55453
|
-
return
|
|
55729
|
+
return dirname11(process.argv[1] ?? "");
|
|
55454
55730
|
}
|
|
55455
55731
|
function pluginRootRow(adapter, env) {
|
|
55456
55732
|
const own4 = bundleDir();
|
|
@@ -55464,12 +55740,12 @@ function pluginRootRow(adapter, env) {
|
|
|
55464
55740
|
return root === own4 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own4)];
|
|
55465
55741
|
}
|
|
55466
55742
|
function isCurrent(agentDir, dir) {
|
|
55467
|
-
const link =
|
|
55743
|
+
const link = join23(agentDir, PLUGIN_CURRENT_LINK);
|
|
55468
55744
|
return existsSync22(link) && realpathSync10.native(link) === realpathSync10.native(dir);
|
|
55469
55745
|
}
|
|
55470
55746
|
async function checkout(adapter, deps) {
|
|
55471
55747
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
55472
|
-
const agentDir =
|
|
55748
|
+
const agentDir = dirname11(fetched.dir);
|
|
55473
55749
|
try {
|
|
55474
55750
|
verifySums(fetched.dir);
|
|
55475
55751
|
} catch (err) {
|
|
@@ -55497,7 +55773,7 @@ async function upgrade(adapter, deps, home) {
|
|
|
55497
55773
|
return rows;
|
|
55498
55774
|
} catch (err) {
|
|
55499
55775
|
removal?.rollback();
|
|
55500
|
-
if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir,
|
|
55776
|
+
if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename7(done.swap.previous));
|
|
55501
55777
|
throw err;
|
|
55502
55778
|
}
|
|
55503
55779
|
}
|
|
@@ -55674,7 +55950,7 @@ function workspaceCwdOf(meta3, spawnCwd, script) {
|
|
|
55674
55950
|
const fromHost = workspaceFromMeta(meta3);
|
|
55675
55951
|
if (fromHost !== void 0) return fromHost;
|
|
55676
55952
|
if (script === void 0 || script === "") return spawnCwd;
|
|
55677
|
-
return realOrSame(spawnCwd) === realOrSame(
|
|
55953
|
+
return realOrSame(spawnCwd) === realOrSame(dirname12(script)) ? "" : spawnCwd;
|
|
55678
55954
|
}
|
|
55679
55955
|
function errorReply(err) {
|
|
55680
55956
|
if (err instanceof CtxError) return { text: err.toLine(), isError: true, sandboxBytes: 0 };
|
|
@@ -55717,7 +55993,7 @@ async function startServer(argv, env) {
|
|
|
55717
55993
|
return db;
|
|
55718
55994
|
}
|
|
55719
55995
|
function stopMarker(configDir, projectKey) {
|
|
55720
|
-
return
|
|
55996
|
+
return join24(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
|
|
55721
55997
|
}
|
|
55722
55998
|
function stopRequested() {
|
|
55723
55999
|
const configDir = resolveConfigDir(process.env);
|
|
@@ -55773,7 +56049,7 @@ async function startServer(argv, env) {
|
|
|
55773
56049
|
try {
|
|
55774
56050
|
await journal(resolved, ctx, tool.name, reply4);
|
|
55775
56051
|
} catch (err) {
|
|
55776
|
-
reply4 = errorReply(err);
|
|
56052
|
+
reply4 = tool.name === DOCTOR_TOOL_NAME ? { ...reply4, text: reply4.text + "\n" + JOURNAL_SKIPPED_LINE(errorReply(err).text) } : errorReply(err);
|
|
55777
56053
|
}
|
|
55778
56054
|
}
|
|
55779
56055
|
}
|