context-mode 2.0.0-next.28 → 2.0.0-next.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +86 -83
- package/SHA256SUMS +19 -19
- package/claude-code/skills/ctx-stats/SKILL.md +2 -2
- package/cli.mjs +20 -0
- package/codex/skills/ctx-stats/SKILL.md +2 -2
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +71 -71
- package/opencode/plugin.js +501 -234
- package/package.json +1 -1
- package/pi/index.js +580 -314
- package/pi/skills/ctx-stats/SKILL.md +2 -2
- package/qwen-extension.json +1 -1
- package/run.mjs +21 -1
- package/search.mjs +21 -1
- package/server.mjs +529 -263
- package/skills/ctx-stats/SKILL.md +2 -2
package/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 existsSync22, realpathSync as realpathSync11, rmSync as rmSync11 } from "node:fs";
|
|
11
|
-
import { dirname as dirname11, join as
|
|
11
|
+
import { dirname as dirname11, join as join22 } 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
|
|
@@ -715,14 +715,14 @@ function codePointLength(str) {
|
|
|
715
715
|
const units = str.length;
|
|
716
716
|
if (!highSurrogate.test(str))
|
|
717
717
|
return units;
|
|
718
|
-
let
|
|
718
|
+
let count2 = units;
|
|
719
719
|
for (let i = 0; i < units - 1; i++) {
|
|
720
720
|
if ((str.charCodeAt(i) & 64512) === 55296 && (str.charCodeAt(i + 1) & 64512) === 56320) {
|
|
721
|
-
|
|
721
|
+
count2--;
|
|
722
722
|
i++;
|
|
723
723
|
}
|
|
724
724
|
}
|
|
725
|
-
return
|
|
725
|
+
return count2;
|
|
726
726
|
}
|
|
727
727
|
function getLengthableOrigin(input) {
|
|
728
728
|
if (Array.isArray(input))
|
|
@@ -771,16 +771,16 @@ function cleanEnum(obj) {
|
|
|
771
771
|
}
|
|
772
772
|
function base64ToUint8Array(base645) {
|
|
773
773
|
const binaryString = atob(base645);
|
|
774
|
-
const
|
|
774
|
+
const bytes5 = new Uint8Array(binaryString.length);
|
|
775
775
|
for (let i = 0; i < binaryString.length; i++) {
|
|
776
|
-
|
|
776
|
+
bytes5[i] = binaryString.charCodeAt(i);
|
|
777
777
|
}
|
|
778
|
-
return
|
|
778
|
+
return bytes5;
|
|
779
779
|
}
|
|
780
|
-
function uint8ArrayToBase64(
|
|
780
|
+
function uint8ArrayToBase64(bytes5) {
|
|
781
781
|
let binaryString = "";
|
|
782
|
-
for (let i = 0; i <
|
|
783
|
-
binaryString += String.fromCharCode(
|
|
782
|
+
for (let i = 0; i < bytes5.length; i++) {
|
|
783
|
+
binaryString += String.fromCharCode(bytes5[i]);
|
|
784
784
|
}
|
|
785
785
|
return btoa(binaryString);
|
|
786
786
|
}
|
|
@@ -789,30 +789,30 @@ function base64urlToUint8Array(base64url5) {
|
|
|
789
789
|
const padding = "=".repeat((4 - base645.length % 4) % 4);
|
|
790
790
|
return base64ToUint8Array(base645 + padding);
|
|
791
791
|
}
|
|
792
|
-
function uint8ArrayToBase64url(
|
|
793
|
-
return uint8ArrayToBase64(
|
|
792
|
+
function uint8ArrayToBase64url(bytes5) {
|
|
793
|
+
return uint8ArrayToBase64(bytes5).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
794
794
|
}
|
|
795
795
|
function hexToUint8Array(hex) {
|
|
796
796
|
const cleanHex = hex.replace(/^0x/, "");
|
|
797
797
|
if (cleanHex.length % 2 !== 0) {
|
|
798
798
|
throw new Error("Invalid hex string length");
|
|
799
799
|
}
|
|
800
|
-
const
|
|
800
|
+
const bytes5 = new Uint8Array(cleanHex.length / 2);
|
|
801
801
|
for (let i = 0; i < cleanHex.length; i += 2) {
|
|
802
|
-
|
|
802
|
+
bytes5[i / 2] = Number.parseInt(cleanHex.slice(i, i + 2), 16);
|
|
803
803
|
}
|
|
804
|
-
return
|
|
804
|
+
return bytes5;
|
|
805
805
|
}
|
|
806
|
-
function uint8ArrayToHex(
|
|
807
|
-
return Array.from(
|
|
806
|
+
function uint8ArrayToHex(bytes5) {
|
|
807
|
+
return Array.from(bytes5).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
808
808
|
}
|
|
809
809
|
var Class = class {
|
|
810
810
|
constructor(..._args) {
|
|
811
811
|
}
|
|
812
812
|
};
|
|
813
|
-
function members(proto,
|
|
814
|
-
for (const key in
|
|
815
|
-
const desc = Object.getOwnPropertyDescriptor(
|
|
813
|
+
function members(proto, table3) {
|
|
814
|
+
for (const key in table3) {
|
|
815
|
+
const desc = Object.getOwnPropertyDescriptor(table3, key);
|
|
816
816
|
if (desc.get)
|
|
817
817
|
Object.defineProperty(proto, key, { ...desc, enumerable: false });
|
|
818
818
|
else
|
|
@@ -827,10 +827,10 @@ function hide(inst, key, value) {
|
|
|
827
827
|
return own(inst, key, value, false);
|
|
828
828
|
}
|
|
829
829
|
// @__NO_SIDE_EFFECTS__
|
|
830
|
-
function derived(computes,
|
|
830
|
+
function derived(computes, table3) {
|
|
831
831
|
for (const key in computes) {
|
|
832
832
|
const compute = computes[key];
|
|
833
|
-
Object.defineProperty(
|
|
833
|
+
Object.defineProperty(table3, key, {
|
|
834
834
|
configurable: true,
|
|
835
835
|
enumerable: true,
|
|
836
836
|
get() {
|
|
@@ -841,7 +841,7 @@ function derived(computes, table2) {
|
|
|
841
841
|
}
|
|
842
842
|
});
|
|
843
843
|
}
|
|
844
|
-
return
|
|
844
|
+
return table3;
|
|
845
845
|
}
|
|
846
846
|
function defineBound(proto, key, fn) {
|
|
847
847
|
Object.defineProperty(proto, key, {
|
|
@@ -8296,14 +8296,14 @@ function codePointLength2(str) {
|
|
|
8296
8296
|
const units = str.length;
|
|
8297
8297
|
if (!highSurrogate2.test(str))
|
|
8298
8298
|
return units;
|
|
8299
|
-
let
|
|
8299
|
+
let count2 = units;
|
|
8300
8300
|
for (let i = 0; i < units - 1; i++) {
|
|
8301
8301
|
if ((str.charCodeAt(i) & 64512) === 55296 && (str.charCodeAt(i + 1) & 64512) === 56320) {
|
|
8302
|
-
|
|
8302
|
+
count2--;
|
|
8303
8303
|
i++;
|
|
8304
8304
|
}
|
|
8305
8305
|
}
|
|
8306
|
-
return
|
|
8306
|
+
return count2;
|
|
8307
8307
|
}
|
|
8308
8308
|
function getLengthableOrigin2(input) {
|
|
8309
8309
|
if (Array.isArray(input))
|
|
@@ -8352,16 +8352,16 @@ function cleanEnum2(obj) {
|
|
|
8352
8352
|
}
|
|
8353
8353
|
function base64ToUint8Array2(base645) {
|
|
8354
8354
|
const binaryString = atob(base645);
|
|
8355
|
-
const
|
|
8355
|
+
const bytes5 = new Uint8Array(binaryString.length);
|
|
8356
8356
|
for (let i = 0; i < binaryString.length; i++) {
|
|
8357
|
-
|
|
8357
|
+
bytes5[i] = binaryString.charCodeAt(i);
|
|
8358
8358
|
}
|
|
8359
|
-
return
|
|
8359
|
+
return bytes5;
|
|
8360
8360
|
}
|
|
8361
|
-
function uint8ArrayToBase642(
|
|
8361
|
+
function uint8ArrayToBase642(bytes5) {
|
|
8362
8362
|
let binaryString = "";
|
|
8363
|
-
for (let i = 0; i <
|
|
8364
|
-
binaryString += String.fromCharCode(
|
|
8363
|
+
for (let i = 0; i < bytes5.length; i++) {
|
|
8364
|
+
binaryString += String.fromCharCode(bytes5[i]);
|
|
8365
8365
|
}
|
|
8366
8366
|
return btoa(binaryString);
|
|
8367
8367
|
}
|
|
@@ -8370,30 +8370,30 @@ function base64urlToUint8Array2(base64url5) {
|
|
|
8370
8370
|
const padding = "=".repeat((4 - base645.length % 4) % 4);
|
|
8371
8371
|
return base64ToUint8Array2(base645 + padding);
|
|
8372
8372
|
}
|
|
8373
|
-
function uint8ArrayToBase64url2(
|
|
8374
|
-
return uint8ArrayToBase642(
|
|
8373
|
+
function uint8ArrayToBase64url2(bytes5) {
|
|
8374
|
+
return uint8ArrayToBase642(bytes5).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
8375
8375
|
}
|
|
8376
8376
|
function hexToUint8Array2(hex) {
|
|
8377
8377
|
const cleanHex = hex.replace(/^0x/, "");
|
|
8378
8378
|
if (cleanHex.length % 2 !== 0) {
|
|
8379
8379
|
throw new Error("Invalid hex string length");
|
|
8380
8380
|
}
|
|
8381
|
-
const
|
|
8381
|
+
const bytes5 = new Uint8Array(cleanHex.length / 2);
|
|
8382
8382
|
for (let i = 0; i < cleanHex.length; i += 2) {
|
|
8383
|
-
|
|
8383
|
+
bytes5[i / 2] = Number.parseInt(cleanHex.slice(i, i + 2), 16);
|
|
8384
8384
|
}
|
|
8385
|
-
return
|
|
8385
|
+
return bytes5;
|
|
8386
8386
|
}
|
|
8387
|
-
function uint8ArrayToHex2(
|
|
8388
|
-
return Array.from(
|
|
8387
|
+
function uint8ArrayToHex2(bytes5) {
|
|
8388
|
+
return Array.from(bytes5).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
8389
8389
|
}
|
|
8390
8390
|
var Class2 = class {
|
|
8391
8391
|
constructor(..._args) {
|
|
8392
8392
|
}
|
|
8393
8393
|
};
|
|
8394
|
-
function members2(proto,
|
|
8395
|
-
for (const key in
|
|
8396
|
-
const desc = Object.getOwnPropertyDescriptor(
|
|
8394
|
+
function members2(proto, table3) {
|
|
8395
|
+
for (const key in table3) {
|
|
8396
|
+
const desc = Object.getOwnPropertyDescriptor(table3, key);
|
|
8397
8397
|
if (desc.get)
|
|
8398
8398
|
Object.defineProperty(proto, key, { ...desc, enumerable: false });
|
|
8399
8399
|
else
|
|
@@ -8408,10 +8408,10 @@ function hide2(inst, key, value) {
|
|
|
8408
8408
|
return own2(inst, key, value, false);
|
|
8409
8409
|
}
|
|
8410
8410
|
// @__NO_SIDE_EFFECTS__
|
|
8411
|
-
function derived2(computes,
|
|
8411
|
+
function derived2(computes, table3) {
|
|
8412
8412
|
for (const key in computes) {
|
|
8413
8413
|
const compute = computes[key];
|
|
8414
|
-
Object.defineProperty(
|
|
8414
|
+
Object.defineProperty(table3, key, {
|
|
8415
8415
|
configurable: true,
|
|
8416
8416
|
enumerable: true,
|
|
8417
8417
|
get() {
|
|
@@ -8422,7 +8422,7 @@ function derived2(computes, table2) {
|
|
|
8422
8422
|
}
|
|
8423
8423
|
});
|
|
8424
8424
|
}
|
|
8425
|
-
return
|
|
8425
|
+
return table3;
|
|
8426
8426
|
}
|
|
8427
8427
|
function defineBound2(proto, key, fn) {
|
|
8428
8428
|
Object.defineProperty(proto, key, {
|
|
@@ -19358,9 +19358,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
19358
19358
|
}
|
|
19359
19359
|
};
|
|
19360
19360
|
var Label = class extends Node2 {
|
|
19361
|
-
constructor(
|
|
19361
|
+
constructor(label2) {
|
|
19362
19362
|
super();
|
|
19363
|
-
this.label =
|
|
19363
|
+
this.label = label2;
|
|
19364
19364
|
this.names = {};
|
|
19365
19365
|
}
|
|
19366
19366
|
render({ _n }) {
|
|
@@ -19368,9 +19368,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
19368
19368
|
}
|
|
19369
19369
|
};
|
|
19370
19370
|
var Break = class extends Node2 {
|
|
19371
|
-
constructor(
|
|
19371
|
+
constructor(label2) {
|
|
19372
19372
|
super();
|
|
19373
|
-
this.label =
|
|
19373
|
+
this.label = label2;
|
|
19374
19374
|
this.names = {};
|
|
19375
19375
|
}
|
|
19376
19376
|
render({ _n }) {
|
|
@@ -19735,11 +19735,11 @@ var require_codegen = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
19735
19735
|
endFor() {
|
|
19736
19736
|
return this._endBlockNode(For);
|
|
19737
19737
|
}
|
|
19738
|
-
label(
|
|
19739
|
-
return this._leafNode(new Label(
|
|
19738
|
+
label(label2) {
|
|
19739
|
+
return this._leafNode(new Label(label2));
|
|
19740
19740
|
}
|
|
19741
|
-
break(
|
|
19742
|
-
return this._leafNode(new Break(
|
|
19741
|
+
break(label2) {
|
|
19742
|
+
return this._leafNode(new Break(label2));
|
|
19743
19743
|
}
|
|
19744
19744
|
return(value) {
|
|
19745
19745
|
const node3 = new Return();
|
|
@@ -20877,15 +20877,15 @@ var require_resolve = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
20877
20877
|
return false;
|
|
20878
20878
|
}
|
|
20879
20879
|
function countKeys(schema) {
|
|
20880
|
-
let
|
|
20880
|
+
let count2 = 0;
|
|
20881
20881
|
for (const key in schema) {
|
|
20882
20882
|
if (key === "$ref") return Infinity;
|
|
20883
|
-
|
|
20883
|
+
count2++;
|
|
20884
20884
|
if (SIMPLE_INLINED.has(key)) continue;
|
|
20885
|
-
if (typeof schema[key] == "object") (0, util_1.eachItem)(schema[key], (sch) =>
|
|
20886
|
-
if (
|
|
20885
|
+
if (typeof schema[key] == "object") (0, util_1.eachItem)(schema[key], (sch) => count2 += countKeys(sch));
|
|
20886
|
+
if (count2 === Infinity) return Infinity;
|
|
20887
20887
|
}
|
|
20888
|
-
return
|
|
20888
|
+
return count2;
|
|
20889
20889
|
}
|
|
20890
20890
|
function getFullPath(resolver, id = "", normalize2) {
|
|
20891
20891
|
if (normalize2 !== false) id = normalizeId(id);
|
|
@@ -23485,8 +23485,8 @@ var require_contains = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
23485
23485
|
cxt.result(valid, () => cxt.reset());
|
|
23486
23486
|
function validateItemsWithCount() {
|
|
23487
23487
|
const schValid = gen.name("_valid");
|
|
23488
|
-
const
|
|
23489
|
-
validateItems(schValid, () => gen.if(schValid, () => checkLimits(
|
|
23488
|
+
const count2 = gen.let("count", 0);
|
|
23489
|
+
validateItems(schValid, () => gen.if(schValid, () => checkLimits(count2)));
|
|
23490
23490
|
}
|
|
23491
23491
|
function validateItems(_valid, block) {
|
|
23492
23492
|
gen.forRange("i", 0, len, (i) => {
|
|
@@ -23499,13 +23499,13 @@ var require_contains = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
23499
23499
|
block();
|
|
23500
23500
|
});
|
|
23501
23501
|
}
|
|
23502
|
-
function checkLimits(
|
|
23503
|
-
gen.code((0, codegen_1._)`${
|
|
23504
|
-
if (max === void 0) gen.if((0, codegen_1._)`${
|
|
23502
|
+
function checkLimits(count2) {
|
|
23503
|
+
gen.code((0, codegen_1._)`${count2}++`);
|
|
23504
|
+
if (max === void 0) gen.if((0, codegen_1._)`${count2} >= ${min}`, () => gen.assign(valid, true).break());
|
|
23505
23505
|
else {
|
|
23506
|
-
gen.if((0, codegen_1._)`${
|
|
23506
|
+
gen.if((0, codegen_1._)`${count2} > ${max}`, () => gen.assign(valid, false).break());
|
|
23507
23507
|
if (min === 1) gen.assign(valid, true);
|
|
23508
|
-
else gen.if((0, codegen_1._)`${
|
|
23508
|
+
else gen.if((0, codegen_1._)`${count2} >= ${min}`, () => gen.assign(valid, true));
|
|
23509
23509
|
}
|
|
23510
23510
|
}
|
|
23511
23511
|
}
|
|
@@ -26172,11 +26172,11 @@ function coerceEmbeddedInputRequest(method, key, entry) {
|
|
|
26172
26172
|
function syntheticElicitationId() {
|
|
26173
26173
|
const webCrypto = globalThis.crypto;
|
|
26174
26174
|
if (webCrypto?.randomUUID !== void 0) return webCrypto.randomUUID();
|
|
26175
|
-
const
|
|
26176
|
-
webCrypto.getRandomValues(
|
|
26177
|
-
|
|
26178
|
-
|
|
26179
|
-
const hex = [...
|
|
26175
|
+
const bytes5 = new Uint8Array(16);
|
|
26176
|
+
webCrypto.getRandomValues(bytes5);
|
|
26177
|
+
bytes5[6] = bytes5[6] & 15 | 64;
|
|
26178
|
+
bytes5[8] = bytes5[8] & 63 | 128;
|
|
26179
|
+
const hex = [...bytes5].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
26180
26180
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
26181
26181
|
}
|
|
26182
26182
|
function legacyShimFailure(method, message2) {
|
|
@@ -26908,23 +26908,23 @@ function discoverAdvertisedCapabilities(capabilities) {
|
|
|
26908
26908
|
return { ...capabilities };
|
|
26909
26909
|
}
|
|
26910
26910
|
function toolInputElementCount(value, max) {
|
|
26911
|
-
let
|
|
26911
|
+
let count2 = 0;
|
|
26912
26912
|
const stack = [value];
|
|
26913
26913
|
while (stack.length > 0) {
|
|
26914
26914
|
const node3 = stack.pop();
|
|
26915
26915
|
if (node3 === null || typeof node3 !== "object") continue;
|
|
26916
26916
|
if (Array.isArray(node3)) for (const child of node3) {
|
|
26917
|
-
if (++
|
|
26917
|
+
if (++count2 > max) return count2;
|
|
26918
26918
|
if (child !== null && typeof child === "object") stack.push(child);
|
|
26919
26919
|
}
|
|
26920
26920
|
else for (const key in node3) {
|
|
26921
26921
|
if (!Object.prototype.hasOwnProperty.call(node3, key)) continue;
|
|
26922
|
-
if (++
|
|
26922
|
+
if (++count2 > max) return count2;
|
|
26923
26923
|
const child = node3[key];
|
|
26924
26924
|
if (child !== null && typeof child === "object") stack.push(child);
|
|
26925
26925
|
}
|
|
26926
26926
|
}
|
|
26927
|
-
return
|
|
26927
|
+
return count2;
|
|
26928
26928
|
}
|
|
26929
26929
|
function resolveMaxToolInputElements(value) {
|
|
26930
26930
|
if (value === void 0 || value === Infinity) return void 0;
|
|
@@ -28296,11 +28296,11 @@ var HOOK_FAIL_REDIRECT = Object.freeze({
|
|
|
28296
28296
|
grep: "Search with ctx_execute(language, code), or index the files with ctx_index and query them with ctx_search.",
|
|
28297
28297
|
fetch: "Index the URL with ctx_index and query it with ctx_search."
|
|
28298
28298
|
});
|
|
28299
|
-
function D5_LAST_HOOK_ERROR(ts, stage,
|
|
28300
|
-
return `; last hook error ${ts} at ${stage} (${
|
|
28299
|
+
function D5_LAST_HOOK_ERROR(ts, stage, label2) {
|
|
28300
|
+
return `; last hook error ${ts} at ${stage} (${label2}), stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
28301
28301
|
}
|
|
28302
|
-
function D5_PAST_HOOK_ERROR(ts, stage,
|
|
28303
|
-
return `; past hook error ${ts} at ${stage} (${
|
|
28302
|
+
function D5_PAST_HOOK_ERROR(ts, stage, label2) {
|
|
28303
|
+
return `; past hook error ${ts} at ${stage} (${label2}), before this run, stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
28304
28304
|
}
|
|
28305
28305
|
var BOUNDED_COMMANDS = Object.freeze(["pwd", "whoami", "uname", "id", "realpath", "ln"]);
|
|
28306
28306
|
var BOUNDED_GIT_SUBCOMMANDS = Object.freeze(["status"]);
|
|
@@ -28340,6 +28340,42 @@ function STATS_SUMMARY(allTimePct, sessionPct) {
|
|
|
28340
28340
|
}
|
|
28341
28341
|
var STATS_COLUMNS = Object.freeze(["Scope", "Produced", "Returned", "Saved", "Reduction %"]);
|
|
28342
28342
|
var STATS_NO_DATA = "no data \u2014 no tool calls recorded yet";
|
|
28343
|
+
var STATS_WIDTH = 80;
|
|
28344
|
+
var STATS_BYTES_PER_TOKEN = 4;
|
|
28345
|
+
var STATS_MAX_TOOL_ROWS = 12;
|
|
28346
|
+
var STATS_LABEL_W = 21;
|
|
28347
|
+
var STATS_LABEL_MAX = 20;
|
|
28348
|
+
var STATS_CALLS_W = 7;
|
|
28349
|
+
var STATS_NUM_W = 11;
|
|
28350
|
+
var STATS_PCT_W = 8;
|
|
28351
|
+
var STATS_KIND_W = 9;
|
|
28352
|
+
var STATS_HEAD_BAR = 40;
|
|
28353
|
+
var STATS_ROW_BAR = 8;
|
|
28354
|
+
var STATS_KIND_BAR = 20;
|
|
28355
|
+
var STATS_KIB = 1024;
|
|
28356
|
+
var STATS_MILLION = 1e6;
|
|
28357
|
+
var STATS_MS_PER_MINUTE = 6e4;
|
|
28358
|
+
var STATS_MINUTES_PER_HOUR = 60;
|
|
28359
|
+
var STATS_HOURS_PER_DAY = 24;
|
|
28360
|
+
var STATS_CLOCK_DIGITS = 2;
|
|
28361
|
+
var STATS_REPORT_TITLE = "context-mode stats";
|
|
28362
|
+
var STATS_EMPTY_LINES = Object.freeze([
|
|
28363
|
+
"Ready. Your savings show up here after the first tool call.",
|
|
28364
|
+
"Large outputs from ctx_execute, ctx_batch and ctx_index stay in the",
|
|
28365
|
+
"sandbox, and only the short answer goes to the chat."
|
|
28366
|
+
]);
|
|
28367
|
+
var STATS_KIND_LABELS = Object.freeze([
|
|
28368
|
+
["cmd", "Tool runs"],
|
|
28369
|
+
["index", "Content indexed"],
|
|
28370
|
+
["edit", "File edits"],
|
|
28371
|
+
["toolerr", "Errors kept"],
|
|
28372
|
+
["decision", "Your decisions"],
|
|
28373
|
+
["prompt", "Your prompts"]
|
|
28374
|
+
]);
|
|
28375
|
+
var STATS_JOURNAL_HINTS = Object.freeze([
|
|
28376
|
+
"ctx_resume brings back your last task, files changed and open errors",
|
|
28377
|
+
"after a compact or a restart; ctx_search finds indexed content by words."
|
|
28378
|
+
]);
|
|
28343
28379
|
var PURGE_SCOPES = Object.freeze(["session", "source", "project"]);
|
|
28344
28380
|
var PURGE_NO_SCOPE_LINE = "ctx_purge: pick one scope \u2014 session, source, or project.";
|
|
28345
28381
|
var PURGE_MANY_SCOPES_LINE = "ctx_purge: pick only one scope \u2014 session, source, or project.";
|
|
@@ -28351,7 +28387,7 @@ var DECISION_SOURCE = "decision";
|
|
|
28351
28387
|
var DECISION_USER_LABEL = "decision (user)";
|
|
28352
28388
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
28353
28389
|
var RELEASE_BRANCH = "release";
|
|
28354
|
-
var BUNDLE_SHA = true ? "
|
|
28390
|
+
var BUNDLE_SHA = true ? "dd54e208f8debb1c4601659ee632ada9a3612e45" : void 0;
|
|
28355
28391
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
28356
28392
|
var DOCTOR_LABEL = Object.freeze({
|
|
28357
28393
|
D1: "version",
|
|
@@ -28381,9 +28417,49 @@ function DOCTOR_FAIL_LINE(host, check2, cause, command) {
|
|
|
28381
28417
|
return `FAIL ${host}: ${check2} \u2014 ${cause}. Fix: ${command}`;
|
|
28382
28418
|
}
|
|
28383
28419
|
var DOCTOR_FIX_UPGRADE = "run ctx_upgrade";
|
|
28384
|
-
var D1_NO_NETWORK_DETAIL = "no network";
|
|
28385
28420
|
var D1_DEV_BUILD_DETAIL = "dev build";
|
|
28386
28421
|
var D1_UPDATE_DETAIL = "update available";
|
|
28422
|
+
var D1_SHORT_SHA_LEN = 7;
|
|
28423
|
+
var D1_PACKAGE_FILE = "package.json";
|
|
28424
|
+
function D1_PREFIX(version4, sha) {
|
|
28425
|
+
return `${version4 ?? "bundle"} (${sha.slice(0, D1_SHORT_SHA_LEN)})`;
|
|
28426
|
+
}
|
|
28427
|
+
var D1_GIT_PASS = "latest on the release branch";
|
|
28428
|
+
function D1_NPM_PASS(tag) {
|
|
28429
|
+
return `latest ${tag} on npm`;
|
|
28430
|
+
}
|
|
28431
|
+
function D1_NPM_UPDATE(tag, latest) {
|
|
28432
|
+
return `${D1_UPDATE_DETAIL}, ${tag} on npm is ${latest}`;
|
|
28433
|
+
}
|
|
28434
|
+
var D1_LATEST_UNKNOWN = "latest unknown";
|
|
28435
|
+
var D1_GIT_MISSING = "git not found on PATH";
|
|
28436
|
+
function D1_GIT_EXIT(code, stderrLine) {
|
|
28437
|
+
return stderrLine === "" ? `git exit ${code}` : `git exit ${code}: ${stderrLine}`;
|
|
28438
|
+
}
|
|
28439
|
+
function D1_GIT_TIMEOUT(ms) {
|
|
28440
|
+
return `git timed out after ${ms} ms`;
|
|
28441
|
+
}
|
|
28442
|
+
var D1_GIT_CANCEL = "git stopped by cancel";
|
|
28443
|
+
var D1_GIT_NO_START = "git did not start";
|
|
28444
|
+
var D1_GIT_NO_SHA = "git answered no sha";
|
|
28445
|
+
function D1_NPM_TIMEOUT(ms) {
|
|
28446
|
+
return `npm registry timed out after ${ms} ms`;
|
|
28447
|
+
}
|
|
28448
|
+
function D1_NPM_HTTP(status) {
|
|
28449
|
+
return `npm registry answered HTTP ${status}`;
|
|
28450
|
+
}
|
|
28451
|
+
function D1_NPM_ERROR(cause) {
|
|
28452
|
+
return `npm registry: ${cause}`;
|
|
28453
|
+
}
|
|
28454
|
+
function D1_NPM_NO_TAG(tag) {
|
|
28455
|
+
return `npm registry answered no ${tag} version`;
|
|
28456
|
+
}
|
|
28457
|
+
var D1_CAUSE_JOIN = "; ";
|
|
28458
|
+
var D1_GIT_CHECK_FIX = `git ls-remote ${RELEASE_REPO_URL} ${RELEASE_BRANCH}`;
|
|
28459
|
+
var D1_NPM_CHECK_FIX = "npm view context-mode dist-tags";
|
|
28460
|
+
var D1_REGISTRY_URL = "https://registry.npmjs.org/-/package/context-mode/dist-tags";
|
|
28461
|
+
var D1_PRERELEASE_SEP = "-";
|
|
28462
|
+
var D1_DEFAULT_TAG = "latest";
|
|
28387
28463
|
var GIT_LS_REMOTE = "ls-remote";
|
|
28388
28464
|
var D2_NODE_FIX = `install Node ${NODE_MIN} or later`;
|
|
28389
28465
|
function D2_NODE_DETAIL(version4) {
|
|
@@ -29649,7 +29725,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
29649
29725
|
terms = given.filter((t) => t.text.length >= 5).map((t) => ({ ...t, text: t.text.slice(0, Math.max(4, t.text.length - 2)) }));
|
|
29650
29726
|
pos = terms.map(find2);
|
|
29651
29727
|
}
|
|
29652
|
-
const
|
|
29728
|
+
const count2 = (ti, a, b) => {
|
|
29653
29729
|
const ps = pos[ti];
|
|
29654
29730
|
let lo = 0, hi = ps.length;
|
|
29655
29731
|
while (lo < hi) {
|
|
@@ -29664,7 +29740,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
29664
29740
|
const N = blocks.length;
|
|
29665
29741
|
const blen = blocks.map((bk2) => rangeBytes(bk2.first, bk2.last));
|
|
29666
29742
|
const avg = blen.reduce((a, b) => a + b, 0) / N || 1;
|
|
29667
|
-
const tf = blocks.map((bk2) => terms.map((_, ti) =>
|
|
29743
|
+
const tf = blocks.map((bk2) => terms.map((_, ti) => count2(ti, ls[bk2.first], le[bk2.last])));
|
|
29668
29744
|
const idf = terms.map((_, ti) => {
|
|
29669
29745
|
let df = 0;
|
|
29670
29746
|
for (let k = 0; k < N; k++) if (tf[k][ti] > 0) df++;
|
|
@@ -29686,7 +29762,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
29686
29762
|
const lineScore = (i) => {
|
|
29687
29763
|
let s = 0;
|
|
29688
29764
|
terms.forEach((_, ti) => {
|
|
29689
|
-
if (
|
|
29765
|
+
if (count2(ti, ls[i], le[i]) > 0) s += weight(ti, bk.code);
|
|
29690
29766
|
});
|
|
29691
29767
|
return s;
|
|
29692
29768
|
};
|
|
@@ -29694,7 +29770,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
29694
29770
|
let at = -1;
|
|
29695
29771
|
let w = -1;
|
|
29696
29772
|
terms.forEach((_, ti) => {
|
|
29697
|
-
const c =
|
|
29773
|
+
const c = count2(ti, ls[i], le[i]);
|
|
29698
29774
|
if (c === 0 || weight(ti, bk.code) <= w) return;
|
|
29699
29775
|
const ps = pos[ti];
|
|
29700
29776
|
let lo = 0, hi = ps.length;
|
|
@@ -31932,8 +32008,8 @@ function parseSourceHandle(s) {
|
|
|
31932
32008
|
function pathLabel(p) {
|
|
31933
32009
|
return p.includes("\\") ? p.split("\\").join("/") : p;
|
|
31934
32010
|
}
|
|
31935
|
-
function labelStored(db,
|
|
31936
|
-
return stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = ? LIMIT 1").get(
|
|
32011
|
+
function labelStored(db, label2) {
|
|
32012
|
+
return stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = ? LIMIT 1").get(label2) !== void 0;
|
|
31937
32013
|
}
|
|
31938
32014
|
function storedLabel(db, source) {
|
|
31939
32015
|
if (labelStored(db, source)) return source;
|
|
@@ -35951,8 +36027,8 @@ function az_default() {
|
|
|
35951
36027
|
}
|
|
35952
36028
|
|
|
35953
36029
|
// node_modules/zod/v4/locales/be.js
|
|
35954
|
-
function getBelarusianPlural(
|
|
35955
|
-
const absCount = Math.abs(
|
|
36030
|
+
function getBelarusianPlural(count2, one, few, many) {
|
|
36031
|
+
const absCount = Math.abs(count2);
|
|
35956
36032
|
const lastDigit = absCount % 10;
|
|
35957
36033
|
const lastTwoDigits = absCount % 100;
|
|
35958
36034
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -39097,8 +39173,8 @@ function pt_default() {
|
|
|
39097
39173
|
}
|
|
39098
39174
|
|
|
39099
39175
|
// node_modules/zod/v4/locales/ru.js
|
|
39100
|
-
function getRussianPlural(
|
|
39101
|
-
const absCount = Math.abs(
|
|
39176
|
+
function getRussianPlural(count2, one, few, many) {
|
|
39177
|
+
const absCount = Math.abs(count2);
|
|
39102
39178
|
const lastDigit = absCount % 10;
|
|
39103
39179
|
const lastTwoDigits = absCount % 100;
|
|
39104
39180
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -43263,7 +43339,7 @@ var TOOL_DESCRIPTIONS = Object.freeze({
|
|
|
43263
43339
|
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.',
|
|
43264
43340
|
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.',
|
|
43265
43341
|
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.",
|
|
43266
|
-
ctx_stats: "Example: `ctx_stats({})`. Required: none.\nReports
|
|
43342
|
+
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.",
|
|
43267
43343
|
ctx_doctor: "Example: `ctx_doctor({})`. Required: none.\nChecks this context-mode install and reports a table with one row per check: version, Node and node:sqlite, host config and hooks for this agent, MCP connection, project and worktree, database health, index contents, and hook timing. Each failed row names its cause and the fix in one line. It changes nothing. Use it when the user asks whether context-mode works, or after a context-mode error.",
|
|
43268
43344
|
ctx_upgrade: "Example: `ctx_upgrade({})`. Required: none.\nUpdates context-mode to the latest release for this agent and rewrites only context-mode's own entries in the host config. User entries and user settings such as hook timeouts are kept, and old entries are erased. Returns a table of what changed and whether a restart is needed. Use it only when the user asks to update context-mode.",
|
|
43269
43345
|
ctx_purge: 'Example: `ctx_purge({source:"old-docs"})`. Required: one of session, source, project.\nDeletes stored data: one session, one indexed source, or everything stored for this project. This cannot be undone. Use it only when the user asks to forget or reset data.'
|
|
@@ -43301,8 +43377,8 @@ function mdChunks(src, cap, lineCut) {
|
|
|
43301
43377
|
const stack = [];
|
|
43302
43378
|
let title = "";
|
|
43303
43379
|
let run = [];
|
|
43304
|
-
const push = (text,
|
|
43305
|
-
out.push({ ord: out.length, text, bytes:
|
|
43380
|
+
const push = (text, bytes5) => {
|
|
43381
|
+
out.push({ ord: out.length, text, bytes: bytes5, title });
|
|
43306
43382
|
};
|
|
43307
43383
|
const flush = () => {
|
|
43308
43384
|
if (run.length === 0) return;
|
|
@@ -43352,19 +43428,19 @@ function lineBlocks(src, md) {
|
|
|
43352
43428
|
let fenceInfo;
|
|
43353
43429
|
const close = () => {
|
|
43354
43430
|
if (start >= 0) {
|
|
43355
|
-
const
|
|
43356
|
-
if (heading !== void 0)
|
|
43357
|
-
if (fenceInfo !== void 0)
|
|
43358
|
-
out.push(
|
|
43431
|
+
const span2 = { start, end };
|
|
43432
|
+
if (heading !== void 0) span2.heading = heading;
|
|
43433
|
+
if (fenceInfo !== void 0) span2.fence = fenceInfo;
|
|
43434
|
+
out.push(span2);
|
|
43359
43435
|
}
|
|
43360
43436
|
start = -1;
|
|
43361
43437
|
heading = void 0;
|
|
43362
43438
|
fenceInfo = void 0;
|
|
43363
43439
|
};
|
|
43364
|
-
const add = (from, to,
|
|
43440
|
+
const add = (from, to, table3) => {
|
|
43365
43441
|
if (start < 0) start = from;
|
|
43366
43442
|
end = to;
|
|
43367
|
-
inTable =
|
|
43443
|
+
inTable = table3;
|
|
43368
43444
|
};
|
|
43369
43445
|
let pos = 0;
|
|
43370
43446
|
while (pos <= src.length) {
|
|
@@ -43385,9 +43461,9 @@ function lineBlocks(src, md) {
|
|
|
43385
43461
|
} else {
|
|
43386
43462
|
const opener = md ? fenceOf(line) : "";
|
|
43387
43463
|
const head = md && opener === "" ? headingOf(line) : void 0;
|
|
43388
|
-
const
|
|
43389
|
-
if (md && start >= 0 && (
|
|
43390
|
-
add(pos, eol,
|
|
43464
|
+
const table3 = md && opener === "" && head === void 0 && line.includes("|");
|
|
43465
|
+
if (md && start >= 0 && (table3 !== inTable || opener !== "" || head !== void 0)) close();
|
|
43466
|
+
add(pos, eol, table3);
|
|
43391
43467
|
fence = opener;
|
|
43392
43468
|
if (opener !== "") fenceInfo = { fence: opener, openEnd: eol, closeStart: -1 };
|
|
43393
43469
|
if (head !== void 0) {
|
|
@@ -43547,17 +43623,17 @@ function cutPoint(src, start, end, scratch) {
|
|
|
43547
43623
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
43548
43624
|
return { end: start + r.read, written: r.written };
|
|
43549
43625
|
}
|
|
43550
|
-
function merge4(src, blocks,
|
|
43626
|
+
function merge4(src, blocks, join23, cap, lineCut) {
|
|
43551
43627
|
const out = [];
|
|
43552
43628
|
const scratch = new Uint8Array(cap);
|
|
43553
43629
|
let wide;
|
|
43554
43630
|
let cur;
|
|
43555
43631
|
let curBytes = 0;
|
|
43556
|
-
const emit = (start, end,
|
|
43557
|
-
out.push({ ord: out.length, text: src.slice(start, end), bytes:
|
|
43632
|
+
const emit = (start, end, bytes5) => {
|
|
43633
|
+
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
43558
43634
|
};
|
|
43559
43635
|
for (const b of blocks) {
|
|
43560
|
-
if (cur !== void 0 && !
|
|
43636
|
+
if (cur !== void 0 && !join23) {
|
|
43561
43637
|
emit(cur.start, cur.end, curBytes);
|
|
43562
43638
|
cur = void 0;
|
|
43563
43639
|
}
|
|
@@ -43572,15 +43648,15 @@ function merge4(src, blocks, join22, cap, lineCut) {
|
|
|
43572
43648
|
cur = void 0;
|
|
43573
43649
|
}
|
|
43574
43650
|
let start = b.start;
|
|
43575
|
-
let
|
|
43576
|
-
while (
|
|
43651
|
+
let bytes5 = utf8Bytes(src.slice(b.start, b.end));
|
|
43652
|
+
while (bytes5 > cap) {
|
|
43577
43653
|
const cut = cutPoint(src, start, b.end, scratch);
|
|
43578
43654
|
const nl = lineCut ? src.lastIndexOf("\n", cut.end - 1) : -1;
|
|
43579
43655
|
if (nl > start) {
|
|
43580
43656
|
const w = utf8Bytes(src.slice(start, nl + 1));
|
|
43581
43657
|
emit(start, nl + 1, w);
|
|
43582
43658
|
start = nl + 1;
|
|
43583
|
-
|
|
43659
|
+
bytes5 -= w;
|
|
43584
43660
|
continue;
|
|
43585
43661
|
}
|
|
43586
43662
|
if (lineCut) {
|
|
@@ -43590,23 +43666,23 @@ function merge4(src, blocks, join22, cap, lineCut) {
|
|
|
43590
43666
|
if (w <= MAX_CHUNK_BYTES) {
|
|
43591
43667
|
emit(start, lineEnd, w);
|
|
43592
43668
|
start = lineEnd;
|
|
43593
|
-
|
|
43669
|
+
bytes5 -= w;
|
|
43594
43670
|
continue;
|
|
43595
43671
|
}
|
|
43596
43672
|
wide ??= new Uint8Array(MAX_CHUNK_BYTES);
|
|
43597
43673
|
const big = cutPoint(src, start, lineEnd, wide);
|
|
43598
43674
|
emit(start, big.end, big.written);
|
|
43599
43675
|
start = big.end;
|
|
43600
|
-
|
|
43676
|
+
bytes5 -= big.written;
|
|
43601
43677
|
continue;
|
|
43602
43678
|
}
|
|
43603
43679
|
emit(start, cut.end, cut.written);
|
|
43604
43680
|
start = cut.end;
|
|
43605
|
-
|
|
43681
|
+
bytes5 -= cut.written;
|
|
43606
43682
|
}
|
|
43607
43683
|
if (start >= b.end) continue;
|
|
43608
43684
|
cur = { start, end: b.end };
|
|
43609
|
-
curBytes =
|
|
43685
|
+
curBytes = bytes5;
|
|
43610
43686
|
}
|
|
43611
43687
|
if (cur !== void 0) emit(cur.start, cur.end, curBytes);
|
|
43612
43688
|
return out;
|
|
@@ -44081,7 +44157,7 @@ function relevance(db, given, scope, ctx) {
|
|
|
44081
44157
|
mine.add(hit.sourceId);
|
|
44082
44158
|
}
|
|
44083
44159
|
if (again.size > 0) {
|
|
44084
|
-
const line = "Same as above: " + [...again].map(([
|
|
44160
|
+
const line = "Same as above: " + [...again].map(([label2, ords]) => label2 + " (chunk " + ords.join(",") + ")").join("; ");
|
|
44085
44161
|
lines.push(line);
|
|
44086
44162
|
used += bytes2(line) + 1;
|
|
44087
44163
|
}
|
|
@@ -44228,7 +44304,7 @@ function shown(chunks, heads) {
|
|
|
44228
44304
|
return c.text;
|
|
44229
44305
|
});
|
|
44230
44306
|
}
|
|
44231
|
-
function indexCombined(db, ctx,
|
|
44307
|
+
function indexCombined(db, ctx, label2, ran, deadline, budgetBytes) {
|
|
44232
44308
|
const chunks = chunkText(ran.map((r) => r.block).join(BLOCK_SEP), "text");
|
|
44233
44309
|
const display = shown(chunks, ran.map((r) => r.head));
|
|
44234
44310
|
const bodies = /* @__PURE__ */ new Map();
|
|
@@ -44248,7 +44324,7 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
|
|
|
44248
44324
|
worktree: ctx.project.worktree,
|
|
44249
44325
|
agent: ctx.project.agent,
|
|
44250
44326
|
kind: "content",
|
|
44251
|
-
label,
|
|
44327
|
+
label: label2,
|
|
44252
44328
|
bytes: groupBytes,
|
|
44253
44329
|
chunkCount: group.length,
|
|
44254
44330
|
createdAt: Date.now()
|
|
@@ -44278,12 +44354,12 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
|
|
|
44278
44354
|
function bytes3(s) {
|
|
44279
44355
|
return Buffer.byteLength(s, "utf8");
|
|
44280
44356
|
}
|
|
44281
|
-
function answer(db, ctx,
|
|
44357
|
+
function answer(db, ctx, label2, queries, share, own4) {
|
|
44282
44358
|
const seen = /* @__PURE__ */ new Set();
|
|
44283
44359
|
const lines = [];
|
|
44284
44360
|
for (const [qi, q] of queries.entries()) {
|
|
44285
44361
|
if (ctx.signal.aborted) break;
|
|
44286
|
-
let hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0,
|
|
44362
|
+
let hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0, label2);
|
|
44287
44363
|
if (hits.length === 0) hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0);
|
|
44288
44364
|
const head = "## " + (bytes3(q) > ECHO_MAX_BYTES ? "query " + (qi + 1) : q);
|
|
44289
44365
|
let used = bytes3(head) + 1;
|
|
@@ -44322,17 +44398,17 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
44322
44398
|
const ran = pool.results;
|
|
44323
44399
|
const last2 = ran[ran.length - 1];
|
|
44324
44400
|
const sandboxBytes = ran.reduce((n, r) => n + r.bytes, 0);
|
|
44325
|
-
const
|
|
44401
|
+
const label2 = LABEL_PREFIX + ctx.turn;
|
|
44326
44402
|
try {
|
|
44327
44403
|
const db = await openDb(ctx.project);
|
|
44328
44404
|
let sections;
|
|
44329
44405
|
let idx;
|
|
44330
44406
|
const exitLine = last2.exitCode === null || last2.exitCode === 0 ? null : "exit " + last2.exitCode;
|
|
44331
|
-
const footer = "more: ctx_search({queries:[...], source:" + JSON.stringify(
|
|
44407
|
+
const footer = "more: ctx_search({queries:[...], source:" + JSON.stringify(label2) + "})";
|
|
44332
44408
|
let notice;
|
|
44333
44409
|
let showMore;
|
|
44334
44410
|
try {
|
|
44335
|
-
idx = indexCombined(db, ctx,
|
|
44411
|
+
idx = indexCombined(db, ctx, label2, ran, deadline, budgetBytes);
|
|
44336
44412
|
const stop = last2.error;
|
|
44337
44413
|
const cut = idx.indexed < idx.total ? "Indexed " + idx.indexed + " of " + idx.total + " B." : null;
|
|
44338
44414
|
const timeout = formatError3("TIMEOUT", { ms: boundMs });
|
|
@@ -44340,7 +44416,7 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
44340
44416
|
notice = cut === null ? stop : cause === null ? cut : cause + " " + cut;
|
|
44341
44417
|
const fixed = (exitLine === null ? 0 : bytes3(exitLine) + 1) + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
|
|
44342
44418
|
const share = Math.floor((OUTPUT_CAP - fixed) / queries.length);
|
|
44343
|
-
const answered = answer(db, ctx,
|
|
44419
|
+
const answered = answer(db, ctx, label2, queries, share, idx.bodies);
|
|
44344
44420
|
sections = answered.lines;
|
|
44345
44421
|
const unseen = [...idx.bodies].filter(([k, text]) => text !== "" && !answered.seen.has(k)).map(([k]) => idx.raw.get(k));
|
|
44346
44422
|
const unseenBytes = unseen.reduce((n, t) => n + bytes3(t) + 1, 0);
|
|
@@ -44376,8 +44452,8 @@ var ctxBatch = Object.freeze({
|
|
|
44376
44452
|
});
|
|
44377
44453
|
|
|
44378
44454
|
// src/core/tools/doctor.ts
|
|
44379
|
-
import { readdirSync as readdirSync6, readFileSync as
|
|
44380
|
-
import { basename as basename4, dirname as dirname6, join as
|
|
44455
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync9, existsSync as existsSync13 } from "node:fs";
|
|
44456
|
+
import { basename as basename4, dirname as dirname6, join as join12 } from "node:path";
|
|
44381
44457
|
|
|
44382
44458
|
// src/adapters/claude-code.ts
|
|
44383
44459
|
var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
@@ -46433,7 +46509,7 @@ var Tokenizer = class {
|
|
|
46433
46509
|
hasUnderscore
|
|
46434
46510
|
};
|
|
46435
46511
|
}
|
|
46436
|
-
parseUnicode(
|
|
46512
|
+
parseUnicode(count2) {
|
|
46437
46513
|
const startLoc = this.codePointIterator.start;
|
|
46438
46514
|
const start = this.codePointIterator.end;
|
|
46439
46515
|
let charCount = 0;
|
|
@@ -46444,7 +46520,7 @@ var Tokenizer = class {
|
|
|
46444
46520
|
return this.reportParseError("invalid-char-in-escape-sequence");
|
|
46445
46521
|
}
|
|
46446
46522
|
charCount++;
|
|
46447
|
-
if (charCount >=
|
|
46523
|
+
if (charCount >= count2) break;
|
|
46448
46524
|
}
|
|
46449
46525
|
const end = this.codePointIterator.end;
|
|
46450
46526
|
const code = this.text.slice(start, end);
|
|
@@ -47210,17 +47286,17 @@ function generateConvertTOMLValue(convertValue) {
|
|
|
47210
47286
|
return baseTable;
|
|
47211
47287
|
},
|
|
47212
47288
|
TOMLTable(node3, baseTable = {}) {
|
|
47213
|
-
const
|
|
47214
|
-
for (const body of node3.body) resolveValue(body,
|
|
47289
|
+
const table3 = getTable(baseTable, resolveValue(node3.key), node3.kind === "array");
|
|
47290
|
+
for (const body of node3.body) resolveValue(body, table3);
|
|
47215
47291
|
return baseTable;
|
|
47216
47292
|
},
|
|
47217
47293
|
TOMLArray(node3) {
|
|
47218
47294
|
return node3.elements.map((e) => resolveValue(e));
|
|
47219
47295
|
},
|
|
47220
47296
|
TOMLInlineTable(node3) {
|
|
47221
|
-
const
|
|
47222
|
-
for (const body of node3.body) resolveValue(body,
|
|
47223
|
-
return
|
|
47297
|
+
const table3 = {};
|
|
47298
|
+
for (const body of node3.body) resolveValue(body, table3);
|
|
47299
|
+
return table3;
|
|
47224
47300
|
},
|
|
47225
47301
|
TOMLKey(node3) {
|
|
47226
47302
|
return node3.keys.map((key) => resolveValue(key));
|
|
@@ -47983,10 +48059,10 @@ function scanCodex(agentHome, out) {
|
|
|
47983
48059
|
}
|
|
47984
48060
|
const tomlFile = join7(agentHome, CONFIG_TOML_FILE);
|
|
47985
48061
|
const config4 = readTomlValue(tomlFile);
|
|
47986
|
-
for (const
|
|
47987
|
-
if (
|
|
47988
|
-
if (
|
|
47989
|
-
out.push(finding(tomlFile,
|
|
48062
|
+
for (const span2 of readTomlTables(tomlFile)) {
|
|
48063
|
+
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
48064
|
+
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config4, span2.path))) continue;
|
|
48065
|
+
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
47990
48066
|
}
|
|
47991
48067
|
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
47992
48068
|
}
|
|
@@ -48575,29 +48651,92 @@ async function checkIndex(project) {
|
|
|
48575
48651
|
}
|
|
48576
48652
|
|
|
48577
48653
|
// src/core/ops/doctor-env.ts
|
|
48578
|
-
import { existsSync as existsSync9, realpathSync as realpathSync5 } from "node:fs";
|
|
48579
|
-
import { isAbsolute as isAbsolute2, relative } from "node:path";
|
|
48654
|
+
import { existsSync as existsSync9, readFileSync as readFileSync7, realpathSync as realpathSync5 } from "node:fs";
|
|
48655
|
+
import { isAbsolute as isAbsolute2, join as join10, relative } from "node:path";
|
|
48580
48656
|
function pass3(id, detail = DOCTOR_PASS_DETAIL) {
|
|
48581
48657
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
48582
48658
|
}
|
|
48583
|
-
function unknown5(id, detail) {
|
|
48584
|
-
return { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail };
|
|
48659
|
+
function unknown5(id, detail, fixCommand) {
|
|
48660
|
+
return fixCommand === void 0 ? { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail } : { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail, fixCommand };
|
|
48585
48661
|
}
|
|
48586
48662
|
function fail3(id, detail, fixCommand) {
|
|
48587
48663
|
return { id, label: DOCTOR_LABEL[id], status: "FAIL", detail, fixCommand };
|
|
48588
48664
|
}
|
|
48665
|
+
function bundleVersion(bundleDir2) {
|
|
48666
|
+
try {
|
|
48667
|
+
const v = JSON.parse(readFileSync7(join10(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
48668
|
+
return typeof v === "string" && v !== "" ? v : void 0;
|
|
48669
|
+
} catch {
|
|
48670
|
+
return void 0;
|
|
48671
|
+
}
|
|
48672
|
+
}
|
|
48673
|
+
function channelOf(version4) {
|
|
48674
|
+
const at = version4.indexOf(D1_PRERELEASE_SEP);
|
|
48675
|
+
if (at < 0) return D1_DEFAULT_TAG;
|
|
48676
|
+
const pre = version4.slice(at + 1);
|
|
48677
|
+
const dot = pre.indexOf(".");
|
|
48678
|
+
const tag = dot < 0 ? pre : pre.slice(0, dot);
|
|
48679
|
+
return tag === "" ? D1_DEFAULT_TAG : tag;
|
|
48680
|
+
}
|
|
48681
|
+
function firstLine2(b) {
|
|
48682
|
+
const text = b.toString("utf8").trim();
|
|
48683
|
+
const nl = text.indexOf("\n");
|
|
48684
|
+
return (nl < 0 ? text : text.slice(0, nl)).trim();
|
|
48685
|
+
}
|
|
48686
|
+
function gitCause(r, timeoutMs) {
|
|
48687
|
+
if (r.killed === "timeout") return D1_GIT_TIMEOUT(timeoutMs);
|
|
48688
|
+
if (r.killed === "cancel") return D1_GIT_CANCEL;
|
|
48689
|
+
if (r.exitCode === null) return D1_GIT_NO_START;
|
|
48690
|
+
return D1_GIT_EXIT(r.exitCode, firstLine2(r.stderr));
|
|
48691
|
+
}
|
|
48692
|
+
function fetchCause(err, timeoutMs) {
|
|
48693
|
+
const name = err instanceof Error ? err.name : "";
|
|
48694
|
+
if (name === "TimeoutError") return D1_NPM_TIMEOUT(timeoutMs);
|
|
48695
|
+
const cause = err instanceof Error && err.cause instanceof Error ? err.cause : err;
|
|
48696
|
+
const code = typeof cause === "object" && cause !== null && "code" in cause && typeof cause.code === "string" ? cause.code : "";
|
|
48697
|
+
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
48698
|
+
return D1_NPM_ERROR(code !== "" && !msg.includes(code) ? `${code} ${msg}` : msg);
|
|
48699
|
+
}
|
|
48700
|
+
async function npmLatest(url4, tag, signal, timeoutMs) {
|
|
48701
|
+
try {
|
|
48702
|
+
const res = await fetch(url4, { signal: AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) });
|
|
48703
|
+
if (!res.ok) return { ok: false, cause: D1_NPM_HTTP(res.status) };
|
|
48704
|
+
const body = await res.json();
|
|
48705
|
+
const v = typeof body === "object" && body !== null ? body[tag] : void 0;
|
|
48706
|
+
return typeof v === "string" && v !== "" ? { ok: true, version: v } : { ok: false, cause: D1_NPM_NO_TAG(tag) };
|
|
48707
|
+
} catch (err) {
|
|
48708
|
+
return { ok: false, cause: fetchCause(err, timeoutMs) };
|
|
48709
|
+
}
|
|
48710
|
+
}
|
|
48589
48711
|
async function checkVersion(i) {
|
|
48590
48712
|
if (i.bundleSha === void 0) return unknown5("D1", D1_DEV_BUILD_DETAIL);
|
|
48591
|
-
const
|
|
48592
|
-
|
|
48593
|
-
|
|
48594
|
-
|
|
48595
|
-
|
|
48596
|
-
|
|
48597
|
-
|
|
48598
|
-
|
|
48599
|
-
|
|
48600
|
-
|
|
48713
|
+
const head = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
48714
|
+
const git3 = findRuntime(GIT_BIN, i.env);
|
|
48715
|
+
let cause = D1_GIT_MISSING;
|
|
48716
|
+
if (git3 !== null) {
|
|
48717
|
+
const r = await runProcess([git3, GIT_LS_REMOTE, RELEASE_REPO_URL, RELEASE_BRANCH], {
|
|
48718
|
+
cwd: i.cwd,
|
|
48719
|
+
env: { ...i.env, ...GIT_NO_PROMPT_ENV },
|
|
48720
|
+
signal: i.signal,
|
|
48721
|
+
timeoutMs: i.timeoutMs
|
|
48722
|
+
});
|
|
48723
|
+
if (r.exitCode === 0 && r.killed === null) {
|
|
48724
|
+
const latest = r.stdout.toString("utf8").split(LS_REMOTE_FIELD_SEP)[0];
|
|
48725
|
+
if (latest.length === GIT_SHA_HEX_LEN) {
|
|
48726
|
+
return latest === i.bundleSha ? pass3("D1", head + D1_GIT_PASS) : fail3("D1", head + D1_UPDATE_DETAIL, DOCTOR_FIX_UPGRADE);
|
|
48727
|
+
}
|
|
48728
|
+
cause = D1_GIT_NO_SHA;
|
|
48729
|
+
} else {
|
|
48730
|
+
cause = gitCause(r, i.timeoutMs);
|
|
48731
|
+
}
|
|
48732
|
+
}
|
|
48733
|
+
const handFix = git3 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX;
|
|
48734
|
+
if (i.version === void 0) return unknown5("D1", head + D1_LATEST_UNKNOWN + ", " + cause, handFix);
|
|
48735
|
+
const tag = channelOf(i.version);
|
|
48736
|
+
const npm = await npmLatest(i.registryUrl, tag, i.signal, i.timeoutMs);
|
|
48737
|
+
if (!npm.ok) return unknown5("D1", head + D1_LATEST_UNKNOWN + ", " + cause + D1_CAUSE_JOIN + npm.cause, handFix);
|
|
48738
|
+
if (npm.version === i.version) return pass3("D1", head + D1_NPM_PASS(tag) + D1_CAUSE_JOIN + cause);
|
|
48739
|
+
return fail3("D1", head + D1_NPM_UPDATE(tag, npm.version) + D1_CAUSE_JOIN + cause, DOCTOR_FIX_UPGRADE);
|
|
48601
48740
|
}
|
|
48602
48741
|
function numbers(v) {
|
|
48603
48742
|
const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
|
|
@@ -48654,7 +48793,7 @@ function checkShell(env) {
|
|
|
48654
48793
|
}
|
|
48655
48794
|
|
|
48656
48795
|
// src/core/ops/doctor-hook.ts
|
|
48657
|
-
import { existsSync as existsSync11, readFileSync as
|
|
48796
|
+
import { existsSync as existsSync11, readFileSync as readFileSync8, realpathSync as realpathSync7 } from "node:fs";
|
|
48658
48797
|
import path6 from "node:path";
|
|
48659
48798
|
|
|
48660
48799
|
// src/setup/codex-trust.ts
|
|
@@ -48879,7 +49018,7 @@ function loadFixture(bundleDir2, agent) {
|
|
|
48879
49018
|
if (!existsSync11(file2)) return null;
|
|
48880
49019
|
let all;
|
|
48881
49020
|
try {
|
|
48882
|
-
all = JSON.parse(hostText(
|
|
49021
|
+
all = JSON.parse(hostText(readFileSync8(file2, "utf8")));
|
|
48883
49022
|
} catch {
|
|
48884
49023
|
return null;
|
|
48885
49024
|
}
|
|
@@ -48972,14 +49111,14 @@ async function checkHookRoundTrip(i) {
|
|
|
48972
49111
|
}
|
|
48973
49112
|
|
|
48974
49113
|
// src/core/hooks/fallback.ts
|
|
48975
|
-
import { join as
|
|
49114
|
+
import { join as join11, resolve as resolve3 } from "node:path";
|
|
48976
49115
|
var fs = process.getBuiltinModule("node:fs");
|
|
48977
49116
|
function homeOf(env) {
|
|
48978
49117
|
return env.HOME ?? env.USERPROFILE ?? "";
|
|
48979
49118
|
}
|
|
48980
49119
|
function hookLogPath(env) {
|
|
48981
49120
|
const home = homeOf(env);
|
|
48982
|
-
return home === "" ? "" :
|
|
49121
|
+
return home === "" ? "" : join11(home, DATA_ROOT.slice(1), HOOK_ERROR_LOG_FILE);
|
|
48983
49122
|
}
|
|
48984
49123
|
function lastHookError(env) {
|
|
48985
49124
|
try {
|
|
@@ -49111,14 +49250,14 @@ function buildReportHead(input) {
|
|
|
49111
49250
|
}
|
|
49112
49251
|
|
|
49113
49252
|
// src/core/index/text.ts
|
|
49114
|
-
function storeText(db, project, sessionId, sourceKind,
|
|
49253
|
+
function storeText(db, project, sessionId, sourceKind, label2, text, kind, chunks = chunkText(text, kind)) {
|
|
49115
49254
|
const sourceId = ftsInsert(db, {
|
|
49116
49255
|
projectKey: project.projectKey,
|
|
49117
49256
|
sessionId,
|
|
49118
49257
|
worktree: project.worktree,
|
|
49119
49258
|
agent: project.agent,
|
|
49120
49259
|
kind: sourceKind,
|
|
49121
|
-
label,
|
|
49260
|
+
label: label2,
|
|
49122
49261
|
bytes: Buffer.byteLength(text, "utf8"),
|
|
49123
49262
|
chunkCount: chunks.length,
|
|
49124
49263
|
createdAt: Date.now()
|
|
@@ -49173,11 +49312,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
49173
49312
|
}
|
|
49174
49313
|
}
|
|
49175
49314
|
function ownServerId(configDir, projectKey) {
|
|
49176
|
-
const dir =
|
|
49315
|
+
const dir = join12(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
49177
49316
|
if (!existsSync13(dir)) return "";
|
|
49178
49317
|
for (const name of readdirSync6(dir)) {
|
|
49179
49318
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
49180
|
-
if (
|
|
49319
|
+
if (readFileSync9(join12(dir, name), "utf8").trim() === String(process.pid)) return basename4(name, OWNER_PID_EXT);
|
|
49181
49320
|
}
|
|
49182
49321
|
return "";
|
|
49183
49322
|
}
|
|
@@ -49187,7 +49326,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
49187
49326
|
const project = ctx.project;
|
|
49188
49327
|
let integrityFailed = false;
|
|
49189
49328
|
const checks = {
|
|
49190
|
-
D1: () => checkVersion({ bundleSha: BUNDLE_SHA, env: buildChildEnv(env), cwd: project.worktree, signal: ctx.signal }),
|
|
49329
|
+
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 }),
|
|
49191
49330
|
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
49192
49331
|
D3: () => checkHostConfig(adapter, env, project.worktree),
|
|
49193
49332
|
D4: () => checkV1Leftovers(adapter.id, requireHomeDir(env), { project: project.worktree, piAgentDir: piAgentDirOf(env, requireHomeDir(env)), claudeDir: claudeDirOf(env, requireHomeDir(env)), codexDir: codexDirOf(env, requireHomeDir(env)), copilotDir: copilotDirOf(env, requireHomeDir(env)), kiroDir: kiroDirOf(env, requireHomeDir(env)), opencodeDir: opencodeDirOf(env, requireHomeDir(env)) }),
|
|
@@ -49229,8 +49368,8 @@ async function handler2(_input, ctx) {
|
|
|
49229
49368
|
const command = `context-mode ${rows.some((r) => r.status === "FAIL") ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
49230
49369
|
const input = { agent: adapter.id, rows, env: reportEnv(process.env), command };
|
|
49231
49370
|
const whole = buildReport(input);
|
|
49232
|
-
const
|
|
49233
|
-
if (
|
|
49371
|
+
const bytes5 = Buffer.byteLength(whole, "utf8");
|
|
49372
|
+
if (bytes5 <= REPORT_CAP) return { text: whole, isError: false, sandboxBytes: bytes5 };
|
|
49234
49373
|
const db = await openDb(ctx.project);
|
|
49235
49374
|
try {
|
|
49236
49375
|
indexText(db, ctx.project, ctx.sessionId, REPORT_SOURCE_LABEL, whole, "text");
|
|
@@ -49238,7 +49377,7 @@ async function handler2(_input, ctx) {
|
|
|
49238
49377
|
closeDb(db);
|
|
49239
49378
|
}
|
|
49240
49379
|
const text = buildReportHead(input);
|
|
49241
|
-
return { text, isError: false, sandboxBytes:
|
|
49380
|
+
return { text, isError: false, sandboxBytes: bytes5 };
|
|
49242
49381
|
}
|
|
49243
49382
|
var ctxDoctor = Object.freeze({
|
|
49244
49383
|
name: "ctx_doctor",
|
|
@@ -49252,7 +49391,7 @@ var ctxDoctor = Object.freeze({
|
|
|
49252
49391
|
// src/core/tools/execute.ts
|
|
49253
49392
|
import { existsSync as existsSync14, mkdtempSync, rmSync as rmSync5, writeFileSync as writeFileSync3 } from "node:fs";
|
|
49254
49393
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
49255
|
-
import { dirname as dirname7, join as
|
|
49394
|
+
import { dirname as dirname7, join as join13, parse as parse5, resolve as resolve4 } from "node:path";
|
|
49256
49395
|
|
|
49257
49396
|
// src/core/index/select.ts
|
|
49258
49397
|
var READ_CHUNKS = "SELECT ord, body FROM chunks WHERE source_id = ?";
|
|
@@ -49266,7 +49405,7 @@ function selectChunks(db, sourceId, intent, budget) {
|
|
|
49266
49405
|
const row5 = db.raw.prepare(READ_LABEL).get(sourceId);
|
|
49267
49406
|
return select(chunks, intent, budget, row5?.label);
|
|
49268
49407
|
}
|
|
49269
|
-
function select(chunks, intent, budget,
|
|
49408
|
+
function select(chunks, intent, budget, label2, rankQuery) {
|
|
49270
49409
|
if (chunks.length === 0) return { text: "", more: null };
|
|
49271
49410
|
const texts = chunks.map((c) => c.text);
|
|
49272
49411
|
const scores = rankQuery === void 0 ? rankTexts(texts, intent) : rankTexts(texts, rankQuery, "any");
|
|
@@ -49285,10 +49424,10 @@ function select(chunks, intent, budget, label, rankQuery) {
|
|
|
49285
49424
|
}
|
|
49286
49425
|
picked.sort((a, b) => a.ord - b.ord);
|
|
49287
49426
|
const text = picked.map((c) => c.text).join(SEP);
|
|
49288
|
-
return { text, more: skipped ? moreLine(intent,
|
|
49427
|
+
return { text, more: skipped ? moreLine(intent, label2) : null };
|
|
49289
49428
|
}
|
|
49290
|
-
function moreLine(intent,
|
|
49291
|
-
const source =
|
|
49429
|
+
function moreLine(intent, label2) {
|
|
49430
|
+
const source = label2 === void 0 ? "" : ", source:" + JSON.stringify(label2);
|
|
49292
49431
|
const query = Buffer.byteLength(intent, "utf8") > ECHO_MAX_BYTES ? "..." : JSON.stringify(intent);
|
|
49293
49432
|
return "ctx_search({queries:[" + query + "]" + source + "})";
|
|
49294
49433
|
}
|
|
@@ -49401,8 +49540,8 @@ function sourceLabel(code) {
|
|
|
49401
49540
|
const first = nl < 0 ? code : code.slice(0, nl);
|
|
49402
49541
|
return Array.from(TOOL2 + ":" + first).slice(0, SOURCE_LABEL_MAX_CHARS).join("");
|
|
49403
49542
|
}
|
|
49404
|
-
function moreReserve(intent,
|
|
49405
|
-
return Buffer.byteLength(moreLine(intent,
|
|
49543
|
+
function moreReserve(intent, label2) {
|
|
49544
|
+
return Buffer.byteLength(moreLine(intent, label2), "utf8");
|
|
49406
49545
|
}
|
|
49407
49546
|
function spawnFailed(argv0, cwd) {
|
|
49408
49547
|
return new CtxError("SPAWN_FAILED", { detail: argv0 + " gave no exit code in " + cwd }).toLine();
|
|
@@ -49419,12 +49558,12 @@ async function finish(input, ctx, r, exitCode, journal) {
|
|
|
49419
49558
|
if (intent === "" && fits) {
|
|
49420
49559
|
return { text: direct, isError, sandboxBytes: fullBytes, journal };
|
|
49421
49560
|
}
|
|
49422
|
-
const
|
|
49423
|
-
const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent,
|
|
49561
|
+
const label2 = sourceLabel(input.code);
|
|
49562
|
+
const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent, label2);
|
|
49424
49563
|
const db = await openDb(ctx.project);
|
|
49425
49564
|
let picked;
|
|
49426
49565
|
try {
|
|
49427
|
-
const { sourceId } = indexText(db, ctx.project, ctx.sessionId,
|
|
49566
|
+
const { sourceId } = indexText(db, ctx.project, ctx.sessionId, label2, combined, "text");
|
|
49428
49567
|
picked = selectChunks(db, sourceId, intent, budget);
|
|
49429
49568
|
} finally {
|
|
49430
49569
|
closeDb(db);
|
|
@@ -49456,8 +49595,8 @@ async function handler3(raw, ctx) {
|
|
|
49456
49595
|
if (takesDashC(input.language, runtime)) {
|
|
49457
49596
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
49458
49597
|
} else {
|
|
49459
|
-
tmpDir = mkdtempSync(
|
|
49460
|
-
const file2 =
|
|
49598
|
+
tmpDir = mkdtempSync(join13(tmpdir2(), TMP_PREFIX));
|
|
49599
|
+
const file2 = join13(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
49461
49600
|
writeFileSync3(file2, scriptText(input.language, input.code), "utf8");
|
|
49462
49601
|
argv = scriptArgv(input.language, runtime, file2);
|
|
49463
49602
|
}
|
|
@@ -49492,12 +49631,12 @@ var ctxExecute = {
|
|
|
49492
49631
|
};
|
|
49493
49632
|
|
|
49494
49633
|
// src/core/tools/index.ts
|
|
49495
|
-
import { existsSync as existsSync15, readFileSync as
|
|
49496
|
-
import { dirname as dirname8, extname, join as
|
|
49634
|
+
import { existsSync as existsSync15, readFileSync as readFileSync11, statSync as statSync6 } from "node:fs";
|
|
49635
|
+
import { dirname as dirname8, extname, join as join15, relative as relative2, resolve as resolve5 } from "node:path";
|
|
49497
49636
|
|
|
49498
49637
|
// src/core/index/walk.ts
|
|
49499
|
-
import { readdirSync as readdirSync7, readFileSync as
|
|
49500
|
-
import { join as
|
|
49638
|
+
import { readdirSync as readdirSync7, readFileSync as readFileSync10, realpathSync as realpathSync8, statSync as statSync5 } from "node:fs";
|
|
49639
|
+
import { join as join14 } from "node:path";
|
|
49501
49640
|
var GITIGNORE = ".gitignore";
|
|
49502
49641
|
var GIT_DIR = ".git";
|
|
49503
49642
|
function walkDir(root, containmentRoot) {
|
|
@@ -49506,7 +49645,7 @@ function walkDir(root, containmentRoot) {
|
|
|
49506
49645
|
const found = [];
|
|
49507
49646
|
visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
|
|
49508
49647
|
found.sort(compareFound);
|
|
49509
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
49648
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join14(...f.dir, f.name) }));
|
|
49510
49649
|
}
|
|
49511
49650
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
49512
49651
|
let entries;
|
|
@@ -49515,10 +49654,10 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
49515
49654
|
} catch {
|
|
49516
49655
|
return;
|
|
49517
49656
|
}
|
|
49518
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
49657
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join14(abs, GITIGNORE), rel)) : parent;
|
|
49519
49658
|
for (const e of entries) {
|
|
49520
49659
|
if (e.name === GIT_DIR) continue;
|
|
49521
|
-
const path7 =
|
|
49660
|
+
const path7 = join14(abs, e.name);
|
|
49522
49661
|
let isDir = e.isDirectory();
|
|
49523
49662
|
let isFile = e.isFile();
|
|
49524
49663
|
let target = path7;
|
|
@@ -49558,7 +49697,7 @@ function compareFound(a, b) {
|
|
|
49558
49697
|
function readRules(file2, base) {
|
|
49559
49698
|
let body;
|
|
49560
49699
|
try {
|
|
49561
|
-
body =
|
|
49700
|
+
body = readFileSync10(file2, "utf8");
|
|
49562
49701
|
} catch {
|
|
49563
49702
|
return [];
|
|
49564
49703
|
}
|
|
@@ -49868,14 +50007,14 @@ function replaceCodePointXML(codePoint) {
|
|
|
49868
50007
|
|
|
49869
50008
|
// node_modules/entities/dist/internal/decode-shared.js
|
|
49870
50009
|
var BASE91_INVERSE = /* @__PURE__ */ (() => {
|
|
49871
|
-
const
|
|
50010
|
+
const table3 = new Uint8Array(127);
|
|
49872
50011
|
let code = 0;
|
|
49873
50012
|
for (let char = 33; char <= 126; char++) {
|
|
49874
50013
|
if (char !== 34 && char !== 36 && char !== 92) {
|
|
49875
|
-
|
|
50014
|
+
table3[char] = code++;
|
|
49876
50015
|
}
|
|
49877
50016
|
}
|
|
49878
|
-
return
|
|
50017
|
+
return table3;
|
|
49879
50018
|
})();
|
|
49880
50019
|
function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCount, dictSize) {
|
|
49881
50020
|
const base = 91;
|
|
@@ -49893,10 +50032,10 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
49893
50032
|
single.fill(-1, dictSize + dict2AtomCount, slotCount);
|
|
49894
50033
|
const start = new Int32Array(slotCount);
|
|
49895
50034
|
const length = new Int32Array(slotCount);
|
|
49896
|
-
function decodeDelta(
|
|
50035
|
+
function decodeDelta(count2, off) {
|
|
49897
50036
|
let previous = 0;
|
|
49898
50037
|
let slot = off;
|
|
49899
|
-
const end = off +
|
|
50038
|
+
const end = off + count2;
|
|
49900
50039
|
while (slot < end) {
|
|
49901
50040
|
const code = BASE91_INVERSE[input.charCodeAt(pos++)];
|
|
49902
50041
|
if (code < 89) {
|
|
@@ -49919,8 +50058,8 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
49919
50058
|
const references = new Int32Array(ngramCount * 2);
|
|
49920
50059
|
let poolSize = 0;
|
|
49921
50060
|
let ngramIndex = 0;
|
|
49922
|
-
function readNgramReferences(
|
|
49923
|
-
for (let index = 0; index <
|
|
50061
|
+
function readNgramReferences(count2, startSlot) {
|
|
50062
|
+
for (let index = 0; index < count2; index++) {
|
|
49924
50063
|
const slot = startSlot + index;
|
|
49925
50064
|
const a = readSlotCode();
|
|
49926
50065
|
const b = readSlotCode();
|
|
@@ -53628,8 +53767,8 @@ var EXT_KIND = Object.freeze({ ".md": "md", ".html": "html", ".htm": "html" });
|
|
|
53628
53767
|
var TYPE_KIND = Object.freeze({ "text/html": "html", "text/markdown": "md" });
|
|
53629
53768
|
var DEFAULT_CONTENT_LABEL = "content";
|
|
53630
53769
|
var utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
53631
|
-
function userLabel(
|
|
53632
|
-
return
|
|
53770
|
+
function userLabel(label2) {
|
|
53771
|
+
return label2 === DECISION_SOURCE ? DECISION_USER_LABEL : label2;
|
|
53633
53772
|
}
|
|
53634
53773
|
function kindOfPath(p) {
|
|
53635
53774
|
return EXT_KIND[extname(p).toLowerCase()] ?? "text";
|
|
@@ -53641,7 +53780,7 @@ function kindOfType(contentType) {
|
|
|
53641
53780
|
}
|
|
53642
53781
|
function readUtf8(absPath) {
|
|
53643
53782
|
try {
|
|
53644
|
-
return utf8.decode(
|
|
53783
|
+
return utf8.decode(readFileSync11(absPath));
|
|
53645
53784
|
} catch {
|
|
53646
53785
|
return void 0;
|
|
53647
53786
|
}
|
|
@@ -53659,7 +53798,7 @@ function pathItems(input, project) {
|
|
|
53659
53798
|
if (statSync6(abs).isDirectory()) {
|
|
53660
53799
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
53661
53800
|
sourceKind: "path",
|
|
53662
|
-
label: pathLabel(
|
|
53801
|
+
label: pathLabel(join15(base, f.relPath)),
|
|
53663
53802
|
kind: kindOfPath(f.relPath),
|
|
53664
53803
|
read: () => readUtf8(f.absPath)
|
|
53665
53804
|
}));
|
|
@@ -53669,9 +53808,9 @@ function pathItems(input, project) {
|
|
|
53669
53808
|
async function itemsOf(input, ctx) {
|
|
53670
53809
|
if (input.content !== void 0) {
|
|
53671
53810
|
const text2 = input.content;
|
|
53672
|
-
const
|
|
53811
|
+
const label3 = input.source ?? DEFAULT_CONTENT_LABEL;
|
|
53673
53812
|
const kind = hasMdStructure(text2) ? "md" : "text";
|
|
53674
|
-
return { items: [{ sourceKind: "content", label:
|
|
53813
|
+
return { items: [{ sourceKind: "content", label: label3, kind, read: () => text2 }], from: label3 };
|
|
53675
53814
|
}
|
|
53676
53815
|
if (input.path !== void 0) {
|
|
53677
53816
|
const items = pathItems({ ...input, path: input.path }, ctx.project);
|
|
@@ -53679,8 +53818,8 @@ async function itemsOf(input, ctx) {
|
|
|
53679
53818
|
}
|
|
53680
53819
|
const res = await safeFetch(input.url ?? "", AbortSignal.any([ctx.signal, AbortSignal.timeout(EXEC_TIMEOUT_MS)]));
|
|
53681
53820
|
const text = res.body.toString("utf8");
|
|
53682
|
-
const
|
|
53683
|
-
return { items: [{ sourceKind: "url", label, kind: kindOfType(res.contentType), read: () => text, base:
|
|
53821
|
+
const label2 = res.finalUrl;
|
|
53822
|
+
return { items: [{ sourceKind: "url", label: label2, kind: kindOfType(res.contentType), read: () => text, base: label2 }], from: label2 };
|
|
53684
53823
|
}
|
|
53685
53824
|
async function handler4(input, ctx) {
|
|
53686
53825
|
const given = INPUT_FIELDS.filter((f) => input[f] !== void 0);
|
|
@@ -53692,14 +53831,14 @@ async function handler4(input, ctx) {
|
|
|
53692
53831
|
const db = await openDb(ctx.project);
|
|
53693
53832
|
let sources = 0;
|
|
53694
53833
|
let chunks = 0;
|
|
53695
|
-
let
|
|
53834
|
+
let bytes5 = 0;
|
|
53696
53835
|
let lastId = 0;
|
|
53697
53836
|
const notes = [];
|
|
53698
53837
|
try {
|
|
53699
53838
|
for (const it of items) {
|
|
53700
53839
|
const text = it.read();
|
|
53701
53840
|
if (text === void 0) continue;
|
|
53702
|
-
|
|
53841
|
+
bytes5 += Buffer.byteLength(text, "utf8");
|
|
53703
53842
|
if (it.kind === "html") {
|
|
53704
53843
|
let readable;
|
|
53705
53844
|
try {
|
|
@@ -53736,7 +53875,7 @@ async function handler4(input, ctx) {
|
|
|
53736
53875
|
return {
|
|
53737
53876
|
text: capBytes(line, OUTPUT_CAP).text,
|
|
53738
53877
|
isError: false,
|
|
53739
|
-
sandboxBytes:
|
|
53878
|
+
sandboxBytes: bytes5,
|
|
53740
53879
|
journal: { kind: "index", key: from, path: from, exit_code: null }
|
|
53741
53880
|
};
|
|
53742
53881
|
} catch (err) {
|
|
@@ -53776,8 +53915,8 @@ function purgeScope(db, scope, input) {
|
|
|
53776
53915
|
const raw = db.raw;
|
|
53777
53916
|
if (scope === "session") return changes(raw, "DELETE FROM events WHERE session_id = ?", input.session);
|
|
53778
53917
|
if (scope === "source") {
|
|
53779
|
-
const
|
|
53780
|
-
return deleteChunkRows(raw, { label }) + changes(raw, "DELETE FROM sources WHERE label = ?",
|
|
53918
|
+
const label2 = storedLabel(db, input.source);
|
|
53919
|
+
return deleteChunkRows(raw, { label: label2 }) + changes(raw, "DELETE FROM sources WHERE label = ?", label2);
|
|
53781
53920
|
}
|
|
53782
53921
|
const chunks = deleteChunkRows(raw, "all");
|
|
53783
53922
|
return changes(raw, "DELETE FROM events") + chunks + changes(raw, "DELETE FROM sources");
|
|
@@ -53814,14 +53953,14 @@ var ctxPurge = Object.freeze({
|
|
|
53814
53953
|
});
|
|
53815
53954
|
|
|
53816
53955
|
// src/core/compaction/candidates.ts
|
|
53817
|
-
function
|
|
53956
|
+
function firstLine3(body) {
|
|
53818
53957
|
const nl = body.indexOf("\n");
|
|
53819
53958
|
return (nl < 0 ? body : body.slice(0, nl)).replaceAll("\r", " ");
|
|
53820
53959
|
}
|
|
53821
53960
|
function make(section, row5, text, repeatCount, query) {
|
|
53822
|
-
const
|
|
53823
|
-
if (
|
|
53824
|
-
return { section, seq: row5.seq, turn: row5.turn, text, bytes:
|
|
53961
|
+
const bytes5 = Buffer.byteLength(text, "utf8");
|
|
53962
|
+
if (bytes5 < 1) throw new Error("compaction: empty candidate line (DECISIONS-r9 M9).");
|
|
53963
|
+
return { section, seq: row5.seq, turn: row5.turn, text, bytes: bytes5, repeatCount, pinned: section === "last_request", query };
|
|
53825
53964
|
}
|
|
53826
53965
|
function capSection(list3) {
|
|
53827
53966
|
return list3.length > MAX_CANDIDATES ? list3.slice(list3.length - MAX_CANDIDATES) : list3;
|
|
@@ -53834,8 +53973,8 @@ function buildCandidates(rows, sessionId) {
|
|
|
53834
53973
|
const own4 = rows.filter((r) => r.session_id === sessionId).sort((a, b) => a.seq - b.seq);
|
|
53835
53974
|
const prompts = own4.filter((r) => r.kind === "prompt");
|
|
53836
53975
|
const last2 = prompts.length > 0 ? prompts[prompts.length - 1] : void 0;
|
|
53837
|
-
const lastRequest = last2 === void 0 ? null : make("last_request", last2, "now: " +
|
|
53838
|
-
const earlierRequests = prompts.slice(0, prompts.length - 1).map((r) => make("earlier_requests", r, "asked #" + r.seq + ": " +
|
|
53976
|
+
const lastRequest = last2 === void 0 ? null : make("last_request", last2, "now: " + firstLine3(last2.body), 1, null);
|
|
53977
|
+
const earlierRequests = prompts.slice(0, prompts.length - 1).map((r) => make("earlier_requests", r, "asked #" + r.seq + ": " + firstLine3(r.body), 1, null));
|
|
53839
53978
|
const failures = /* @__PURE__ */ new Map();
|
|
53840
53979
|
const lastOk = /* @__PURE__ */ new Map();
|
|
53841
53980
|
for (const r of own4) {
|
|
@@ -53870,7 +54009,7 @@ function buildCandidates(rows, sessionId) {
|
|
|
53870
54009
|
decided.set(key, { row: r, count: (decided.get(key)?.count ?? 0) + 1 });
|
|
53871
54010
|
}
|
|
53872
54011
|
const decisions = [];
|
|
53873
|
-
for (const [key, d] of decided) decisions.push(make("decisions", d.row, "decided #" + d.row.seq + ": " +
|
|
54012
|
+
for (const [key, d] of decided) decisions.push(make("decisions", d.row, "decided #" + d.row.seq + ": " + firstLine3(d.row.body), d.count, key));
|
|
53874
54013
|
decisions.sort((a, b) => a.seq - b.seq);
|
|
53875
54014
|
const indexedSources = own4.filter((r) => r.kind === "index").map((r) => make("indexed_sources", r, "indexed " + (r.key ?? ""), 1, r.key));
|
|
53876
54015
|
const set3 = {
|
|
@@ -54124,14 +54263,40 @@ var ctxResume = Object.freeze({
|
|
|
54124
54263
|
var ctxStatsSchema = external_exports.object({}, {
|
|
54125
54264
|
error: (issue4) => issue4.code === "unrecognized_keys" ? STATS_UNKNOWN_FIELD_LINE : void 0
|
|
54126
54265
|
}).strict();
|
|
54127
|
-
var
|
|
54266
|
+
var CALLS = "tool IS NOT NULL AND kind <> 'cost' AND tool <> 'ctx_stats'";
|
|
54267
|
+
var GROUPS = `SELECT session_id, agent, COUNT(*) AS calls, COALESCE(SUM(sandbox_bytes), 0) AS produced, COALESCE(SUM(returned_bytes), 0) AS returned FROM events WHERE ${CALLS} GROUP BY session_id, agent ORDER BY agent, session_id`;
|
|
54268
|
+
var TOOLS = `SELECT tool, COUNT(*) AS calls, COALESCE(SUM(sandbox_bytes), 0) AS produced, COALESCE(SUM(returned_bytes), 0) AS returned FROM events WHERE ${CALLS} GROUP BY tool`;
|
|
54269
|
+
var KINDS = "SELECT kind, COALESCE(SUM(session_id = ?), 0) AS s, COUNT(*) AS p FROM events WHERE kind <> 'cost' AND (tool IS NULL OR tool <> 'ctx_stats') GROUP BY kind";
|
|
54270
|
+
var META = `SELECT COUNT(DISTINCT session_id) AS sessions, COUNT(DISTINCT agent) AS agents, COUNT(DISTINCT created_at / ${MS_PER_DAY}) AS days FROM events WHERE ${CALLS}`;
|
|
54271
|
+
var SPAN = "SELECT COALESCE(MAX(created_at) - MIN(created_at), 0) AS span FROM events WHERE session_id = ? AND kind <> 'cost'";
|
|
54272
|
+
var SOURCES = "SELECT COUNT(*) AS n, COALESCE(SUM(chunk_count), 0) AS chunks, COALESCE(SUM(bytes_total), 0) AS bytes FROM sources";
|
|
54128
54273
|
var EMPTY3 = Object.freeze({ calls: 0, produced: 0, returned: 0, saved: 0 });
|
|
54129
|
-
function
|
|
54130
|
-
|
|
54131
|
-
|
|
54132
|
-
|
|
54133
|
-
|
|
54134
|
-
|
|
54274
|
+
function totals(r) {
|
|
54275
|
+
const produced = Number(r.produced);
|
|
54276
|
+
const returned = Number(r.returned);
|
|
54277
|
+
return { calls: Number(r.calls), produced, returned, saved: Math.max(0, produced - returned) };
|
|
54278
|
+
}
|
|
54279
|
+
function readFacts(raw, sessionId) {
|
|
54280
|
+
const groups = raw.prepare(GROUPS).all().map((r) => ({ session: String(r.session_id), agent: String(r.agent), ...totals(r) }));
|
|
54281
|
+
const tools = raw.prepare(TOOLS).all().map((r) => ({ name: String(r.tool), ...totals(r) }));
|
|
54282
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
54283
|
+
for (const r of raw.prepare(KINDS).all(sessionId)) kinds.set(String(r.kind), { session: Number(r.s), project: Number(r.p) });
|
|
54284
|
+
const meta3 = raw.prepare(META).get();
|
|
54285
|
+
const span2 = Number(raw.prepare(SPAN).get(sessionId).span);
|
|
54286
|
+
const src = raw.prepare(SOURCES).get();
|
|
54287
|
+
const pages = raw.prepare("PRAGMA page_count").get();
|
|
54288
|
+
const size = raw.prepare("PRAGMA page_size").get();
|
|
54289
|
+
return {
|
|
54290
|
+
groups,
|
|
54291
|
+
tools,
|
|
54292
|
+
kinds,
|
|
54293
|
+
span: span2,
|
|
54294
|
+
sessions: Number(meta3.sessions),
|
|
54295
|
+
agents: Number(meta3.agents),
|
|
54296
|
+
days: Number(meta3.days),
|
|
54297
|
+
sources: { count: Number(src.n), chunks: Number(src.chunks), bytes: Number(src.bytes) },
|
|
54298
|
+
dbBytes: Number(pages.page_count) * Number(size.page_size)
|
|
54299
|
+
};
|
|
54135
54300
|
}
|
|
54136
54301
|
function sum(groups) {
|
|
54137
54302
|
return groups.reduce((t, g) => ({
|
|
@@ -54145,23 +54310,123 @@ function reductionPct(t) {
|
|
|
54145
54310
|
if (t.calls === 0) return 0;
|
|
54146
54311
|
return Number((t.saved * PERCENT_SCALE / Math.max(1, t.produced)).toFixed(1));
|
|
54147
54312
|
}
|
|
54148
|
-
function tableRow(
|
|
54313
|
+
function tableRow(label2, t) {
|
|
54149
54314
|
const last2 = t.calls === 0 ? STATS_NO_DATA : String(reductionPct(t));
|
|
54150
|
-
return "| " + [
|
|
54315
|
+
return "| " + [label2, t.produced + " B", t.returned + " B", t.saved + " B", last2].join(" | ") + " |";
|
|
54316
|
+
}
|
|
54317
|
+
var UNITS = ["KB", "MB", "GB", "TB"];
|
|
54318
|
+
var LABEL_W = STATS_LABEL_W;
|
|
54319
|
+
var NUM_W = STATS_NUM_W;
|
|
54320
|
+
var PCT_W = STATS_PCT_W;
|
|
54321
|
+
var INT = new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 });
|
|
54322
|
+
function int4(n) {
|
|
54323
|
+
return INT.format(Math.round(n));
|
|
54324
|
+
}
|
|
54325
|
+
function count(n) {
|
|
54326
|
+
return n < STATS_MILLION ? int4(n) : (n / STATS_MILLION).toFixed(1) + "M";
|
|
54327
|
+
}
|
|
54328
|
+
function bytes4(n) {
|
|
54329
|
+
if (n < STATS_KIB) return int4(n) + " B";
|
|
54330
|
+
let v = n / STATS_KIB;
|
|
54331
|
+
let u = 0;
|
|
54332
|
+
while (v >= STATS_KIB && u < UNITS.length - 1) {
|
|
54333
|
+
v /= STATS_KIB;
|
|
54334
|
+
u++;
|
|
54335
|
+
}
|
|
54336
|
+
return v.toFixed(1) + " " + UNITS[u];
|
|
54337
|
+
}
|
|
54338
|
+
function pct(t) {
|
|
54339
|
+
return (t.saved * PERCENT_SCALE / Math.max(1, t.produced)).toFixed(1) + "%";
|
|
54340
|
+
}
|
|
54341
|
+
function bar(value, max, width, fill = "\u2588", rest = "") {
|
|
54342
|
+
const n = value <= 0 || max <= 0 ? 0 : Math.min(width, Math.max(1, Math.round(value / max * width)));
|
|
54343
|
+
return fill.repeat(n) + rest.repeat(width - n);
|
|
54344
|
+
}
|
|
54345
|
+
function label(s) {
|
|
54346
|
+
const chars = [...s];
|
|
54347
|
+
return (chars.length > STATS_LABEL_MAX ? chars.slice(0, STATS_LABEL_MAX - 1).join("") + "\u2026" : s).padEnd(LABEL_W);
|
|
54348
|
+
}
|
|
54349
|
+
function span(ms) {
|
|
54350
|
+
const min = Math.floor(ms / STATS_MS_PER_MINUTE);
|
|
54351
|
+
if (min < 1) return "<1m";
|
|
54352
|
+
if (min < STATS_MINUTES_PER_HOUR) return min + "m";
|
|
54353
|
+
const h = Math.floor(min / STATS_MINUTES_PER_HOUR);
|
|
54354
|
+
return h < STATS_HOURS_PER_DAY ? `${h}h ${String(min % STATS_MINUTES_PER_HOUR).padStart(STATS_CLOCK_DIGITS, "0")}m` : `${Math.floor(h / STATS_HOURS_PER_DAY)}d ${h % STATS_HOURS_PER_DAY}h`;
|
|
54355
|
+
}
|
|
54356
|
+
function plural(n, word) {
|
|
54357
|
+
return `${int4(n)} ${word}${n === 1 ? "" : "s"}`;
|
|
54358
|
+
}
|
|
54359
|
+
function table2(title, rows) {
|
|
54360
|
+
const max = Math.max(0, ...rows.map((r) => r.saved));
|
|
54361
|
+
const head = " " + title.padEnd(LABEL_W) + "Calls".padStart(STATS_CALLS_W) + "Produced".padStart(NUM_W) + "Returned".padStart(NUM_W) + "Saved".padStart(NUM_W) + "%".padStart(PCT_W);
|
|
54362
|
+
return [head, ...rows.map((r) => (" " + label(r.name) + count(r.calls).padStart(STATS_CALLS_W) + bytes4(r.produced).padStart(NUM_W) + bytes4(r.returned).padStart(NUM_W) + bytes4(r.saved).padStart(NUM_W) + pct(r).padStart(PCT_W) + " " + bar(r.saved, max, STATS_ROW_BAR)).trimEnd())];
|
|
54363
|
+
}
|
|
54364
|
+
function bySaved(a, b) {
|
|
54365
|
+
return b.saved - a.saved || b.produced - a.produced || a.returned - b.returned || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
54366
|
+
}
|
|
54367
|
+
function toolRows(tools) {
|
|
54368
|
+
const named = tools.map((t) => ({ ...t, name: t.name.startsWith("ctx_") ? t.name : "hook " + t.name })).sort(bySaved);
|
|
54369
|
+
if (named.length <= STATS_MAX_TOOL_ROWS) return named;
|
|
54370
|
+
const rest = named.slice(STATS_MAX_TOOL_ROWS - 1);
|
|
54371
|
+
return [...named.slice(0, STATS_MAX_TOOL_ROWS - 1), { name: `other (${rest.length} tools)`, ...sum(rest) }];
|
|
54372
|
+
}
|
|
54373
|
+
function fit(line) {
|
|
54374
|
+
const chars = [...line];
|
|
54375
|
+
return chars.length <= STATS_WIDTH ? line : chars.slice(0, STATS_WIDTH - 1).join("") + "\u2026";
|
|
54376
|
+
}
|
|
54377
|
+
function report(f, sessionId, agent) {
|
|
54378
|
+
const head = [STATS_REPORT_TITLE, "\u2500".repeat(STATS_WIDTH), ""];
|
|
54379
|
+
const project = sum(f.groups);
|
|
54380
|
+
if (project.calls === 0) return [...head, ...STATS_EMPTY_LINES].join("\n");
|
|
54381
|
+
const session = sum(f.groups.filter((g) => g.session === sessionId));
|
|
54382
|
+
const [scopeName, focus] = session.calls > 0 ? ["This session", session] : ["This project", project];
|
|
54383
|
+
const top = Math.max(focus.produced, focus.returned);
|
|
54384
|
+
const extra = session.calls > 0 ? ` \xB7 ${span(f.span)} active` : "";
|
|
54385
|
+
const lines = [
|
|
54386
|
+
...head,
|
|
54387
|
+
`${scopeName} \xB7 ${plural(focus.calls, "call")}${extra}`,
|
|
54388
|
+
" " + "Without context-mode".padEnd(LABEL_W) + "|" + bar(focus.produced, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.produced).padStart(NUM_W),
|
|
54389
|
+
" " + "With context-mode".padEnd(LABEL_W) + "|" + bar(focus.returned, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.returned).padStart(NUM_W),
|
|
54390
|
+
` ${bytes4(focus.saved)} saved (${pct(focus)}) \xB7 about ${int4(focus.saved / STATS_BYTES_PER_TOKEN)} tokens kept out of the chat`,
|
|
54391
|
+
"",
|
|
54392
|
+
...table2("Scope", [{ name: "session", ...session }, { name: "project", ...project }, { name: "all-time", ...project }]),
|
|
54393
|
+
"",
|
|
54394
|
+
"Where the savings came from (this project)",
|
|
54395
|
+
...table2("Tool", toolRows(f.tools)),
|
|
54396
|
+
""
|
|
54397
|
+
];
|
|
54398
|
+
const agents = /* @__PURE__ */ new Map();
|
|
54399
|
+
for (const g of f.groups) agents.set(g.agent, sum([agents.get(g.agent) ?? EMPTY3, g]));
|
|
54400
|
+
if (!agents.has(agent)) agents.set(agent, EMPTY3);
|
|
54401
|
+
lines.push(...table2("Agent", [...agents].map(([name, t]) => ({ name, ...t })).sort(bySaved)), "");
|
|
54402
|
+
const maxKind = Math.max(0, ...[...f.kinds.values()].map((k) => k.project));
|
|
54403
|
+
lines.push("Kept in the session journal", " " + "Journal".padEnd(LABEL_W) + "Session".padStart(STATS_KIND_W) + "Project".padStart(STATS_KIND_W));
|
|
54404
|
+
for (const [kind, name] of STATS_KIND_LABELS) {
|
|
54405
|
+
const k = f.kinds.get(kind) ?? { session: 0, project: 0 };
|
|
54406
|
+
lines.push((" " + label(name) + int4(k.session).padStart(STATS_KIND_W) + int4(k.project).padStart(STATS_KIND_W) + " " + bar(k.project, maxKind, STATS_KIND_BAR)).trimEnd());
|
|
54407
|
+
}
|
|
54408
|
+
lines.push("", ...STATS_JOURNAL_HINTS.map((h) => " " + h), "");
|
|
54409
|
+
lines.push(
|
|
54410
|
+
" " + "Indexed sources".padEnd(LABEL_W) + `${int4(f.sources.count)} \xB7 ${plural(f.sources.chunks, "chunk")} \xB7 ${bytes4(f.sources.bytes)} of content`,
|
|
54411
|
+
" " + "Database file".padEnd(LABEL_W) + bytes4(f.dbBytes),
|
|
54412
|
+
" " + "Sessions".padEnd(LABEL_W) + `${int4(f.sessions)} \xB7 agents ${int4(f.agents)} \xB7 active days ${int4(f.days)}`
|
|
54413
|
+
);
|
|
54414
|
+
return lines.map(fit).join("\n");
|
|
54151
54415
|
}
|
|
54152
54416
|
async function handler7(_input, ctx) {
|
|
54153
54417
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
54154
|
-
let
|
|
54418
|
+
let facts;
|
|
54155
54419
|
try {
|
|
54156
|
-
|
|
54420
|
+
facts = readFacts(db.raw, ctx.sessionId);
|
|
54157
54421
|
} finally {
|
|
54158
54422
|
closeDb(db);
|
|
54159
54423
|
}
|
|
54424
|
+
const groups = facts.groups;
|
|
54160
54425
|
const session = sum(groups.filter((g) => g.session === ctx.sessionId));
|
|
54161
54426
|
const project = sum(groups);
|
|
54162
54427
|
const allTime = project;
|
|
54163
54428
|
const agentIds = [.../* @__PURE__ */ new Set([...groups.map((g) => g.agent), ctx.project.agent])].sort();
|
|
54164
|
-
const
|
|
54429
|
+
const mdTable = [
|
|
54165
54430
|
"| " + STATS_COLUMNS.join(" | ") + " |",
|
|
54166
54431
|
"|" + STATS_COLUMNS.map(() => "---").join("|") + "|",
|
|
54167
54432
|
tableRow("session", session),
|
|
@@ -54170,7 +54435,8 @@ async function handler7(_input, ctx) {
|
|
|
54170
54435
|
...agentIds.map((a) => tableRow("agent " + a, sum(groups.filter((g) => g.agent === a))))
|
|
54171
54436
|
].join("\n");
|
|
54172
54437
|
const summary = STATS_SUMMARY(reductionPct(allTime), reductionPct(session));
|
|
54173
|
-
|
|
54438
|
+
const text = summary + "\n\n```text\n" + report(facts, ctx.sessionId, ctx.project.agent) + "\n```\n\n" + mdTable;
|
|
54439
|
+
return { text: capBytes(text, OUTPUT_CAP).text, isError: false, sandboxBytes: 0 };
|
|
54174
54440
|
}
|
|
54175
54441
|
var ctxStats = Object.freeze({
|
|
54176
54442
|
name: "ctx_stats",
|
|
@@ -54182,11 +54448,11 @@ var ctxStats = Object.freeze({
|
|
|
54182
54448
|
|
|
54183
54449
|
// src/core/tools/upgrade.ts
|
|
54184
54450
|
import { existsSync as existsSync21, realpathSync as realpathSync9, rmSync as rmSync10 } from "node:fs";
|
|
54185
|
-
import { basename as basename6, dirname as dirname10, join as
|
|
54451
|
+
import { basename as basename6, dirname as dirname10, join as join21 } from "node:path";
|
|
54186
54452
|
|
|
54187
54453
|
// src/core/ops/host-write.ts
|
|
54188
54454
|
import { copyFileSync, existsSync as existsSync16, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
54189
|
-
import { dirname as dirname9, join as
|
|
54455
|
+
import { dirname as dirname9, join as join16 } from "node:path";
|
|
54190
54456
|
function defaultWrite(file2, text) {
|
|
54191
54457
|
writeFileSync4(file2, text, "utf8");
|
|
54192
54458
|
}
|
|
@@ -54195,14 +54461,14 @@ function hostConfigPath(agent, home, env) {
|
|
|
54195
54461
|
if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
|
|
54196
54462
|
switch (agent) {
|
|
54197
54463
|
case "opencode":
|
|
54198
|
-
return
|
|
54464
|
+
return join16(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
54199
54465
|
// D-WIN-OPENCODE-DIR-1
|
|
54200
54466
|
case "pi":
|
|
54201
|
-
return
|
|
54467
|
+
return join16(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
54202
54468
|
case "copilot-cli":
|
|
54203
54469
|
return null;
|
|
54204
54470
|
default:
|
|
54205
|
-
return
|
|
54471
|
+
return join16(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
54206
54472
|
}
|
|
54207
54473
|
}
|
|
54208
54474
|
function cell3(value) {
|
|
@@ -54253,7 +54519,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
54253
54519
|
|
|
54254
54520
|
// src/core/ops/plugin-swap.ts
|
|
54255
54521
|
import { existsSync as existsSync17, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
54256
|
-
import { basename as basename5, join as
|
|
54522
|
+
import { basename as basename5, join as join17, win32 as win322 } from "node:path";
|
|
54257
54523
|
function linkTarget(path7, win) {
|
|
54258
54524
|
if (!isLink(path7)) return null;
|
|
54259
54525
|
const target = readlinkSync(path7);
|
|
@@ -54272,11 +54538,11 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
54272
54538
|
else renameWithRetry(old, link, opts);
|
|
54273
54539
|
}
|
|
54274
54540
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
54275
|
-
const next =
|
|
54541
|
+
const next = join17(agentDir, sha);
|
|
54276
54542
|
if (!existsSync17(next) || !lstatSync(next).isDirectory()) {
|
|
54277
54543
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename5(agentDir), path: next });
|
|
54278
54544
|
}
|
|
54279
|
-
const link =
|
|
54545
|
+
const link = join17(agentDir, PLUGIN_CURRENT_LINK);
|
|
54280
54546
|
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
54281
54547
|
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
54282
54548
|
settleLinks(link, tmp, old, opts);
|
|
@@ -54291,15 +54557,15 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
54291
54557
|
if (before !== null) unlinkSync2(old);
|
|
54292
54558
|
const keep = /* @__PURE__ */ new Set([sha]);
|
|
54293
54559
|
if (before !== null) keep.add(before);
|
|
54294
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) =>
|
|
54560
|
+
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join17(agentDir, name));
|
|
54295
54561
|
for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
|
|
54296
|
-
const previous = before !== null && existsSync17(
|
|
54562
|
+
const previous = before !== null && existsSync17(join17(agentDir, before)) ? join17(agentDir, before) : null;
|
|
54297
54563
|
return { current: next, previous, removed };
|
|
54298
54564
|
}
|
|
54299
54565
|
|
|
54300
54566
|
// src/core/ops/release-fetch.ts
|
|
54301
54567
|
import { existsSync as existsSync18, mkdirSync as mkdirSync6, rmSync as rmSync7 } from "node:fs";
|
|
54302
|
-
import { join as
|
|
54568
|
+
import { join as join18 } from "node:path";
|
|
54303
54569
|
function failed(r) {
|
|
54304
54570
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
54305
54571
|
const status = r.killed ?? String(r.exitCode);
|
|
@@ -54311,9 +54577,9 @@ async function git2(bin, args, cwd, env, signal) {
|
|
|
54311
54577
|
return r.stdout.toString().trim();
|
|
54312
54578
|
}
|
|
54313
54579
|
async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
54314
|
-
const agentDir =
|
|
54580
|
+
const agentDir = join18(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
54315
54581
|
mkdirSync6(agentDir, { recursive: true });
|
|
54316
|
-
const fetchDir =
|
|
54582
|
+
const fetchDir = join18(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
54317
54583
|
rmSync7(fetchDir, { recursive: true, force: true });
|
|
54318
54584
|
const gitBin = findRuntime(GIT_BIN, env);
|
|
54319
54585
|
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -54321,7 +54587,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
54321
54587
|
try {
|
|
54322
54588
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
|
|
54323
54589
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
54324
|
-
const dir =
|
|
54590
|
+
const dir = join18(agentDir, sha);
|
|
54325
54591
|
if (existsSync18(dir)) rmSync7(fetchDir, { recursive: true, force: true });
|
|
54326
54592
|
else renameWithRetry(fetchDir, dir, opts);
|
|
54327
54593
|
return { sha, dir };
|
|
@@ -54333,14 +54599,14 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
54333
54599
|
|
|
54334
54600
|
// src/core/ops/uninstall.ts
|
|
54335
54601
|
import { existsSync as existsSync19, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync5 } from "node:fs";
|
|
54336
|
-
import { join as
|
|
54602
|
+
import { join as join19 } from "node:path";
|
|
54337
54603
|
function row2(area, before, after) {
|
|
54338
54604
|
return { area, before, after };
|
|
54339
54605
|
}
|
|
54340
54606
|
function stopServers(configDir, projectKey) {
|
|
54341
54607
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
54342
|
-
const dir =
|
|
54343
|
-
for (const serverId of stopped) writeFileSync5(
|
|
54608
|
+
const dir = join19(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
54609
|
+
for (const serverId of stopped) writeFileSync5(join19(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
54344
54610
|
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 };
|
|
54345
54611
|
}
|
|
54346
54612
|
function rootOrNull(adapter, env) {
|
|
@@ -54358,14 +54624,14 @@ function removeCache(adapter, env, configDir) {
|
|
|
54358
54624
|
const root = rootOrNull(adapter, env);
|
|
54359
54625
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
54360
54626
|
if (adapter.installMode === "marketplace") {
|
|
54361
|
-
const cache =
|
|
54627
|
+
const cache = join19(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
54362
54628
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
54363
54629
|
}
|
|
54364
54630
|
rmSync8(root, { recursive: true, force: true });
|
|
54365
54631
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
54366
54632
|
}
|
|
54367
54633
|
case "plugin": {
|
|
54368
|
-
const agentDir =
|
|
54634
|
+
const agentDir = join19(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
54369
54635
|
if (!existsSync19(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
54370
54636
|
rmSync8(agentDir, { recursive: true, force: true });
|
|
54371
54637
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
@@ -54411,7 +54677,7 @@ function ownEntries(agent, env) {
|
|
|
54411
54677
|
}
|
|
54412
54678
|
if (agent === "opencode") {
|
|
54413
54679
|
return [{
|
|
54414
|
-
file:
|
|
54680
|
+
file: join19(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
54415
54681
|
// D-WIN-OPENCODE-DIR-1
|
|
54416
54682
|
key: OPENCODE_PLUGIN_KEY,
|
|
54417
54683
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -54422,7 +54688,7 @@ function ownEntries(agent, env) {
|
|
|
54422
54688
|
if (agent === "pi") {
|
|
54423
54689
|
const agentDir = piAgentDirOf(env, home);
|
|
54424
54690
|
return [{
|
|
54425
|
-
file:
|
|
54691
|
+
file: join19(agentDir, SETTINGS_FILE),
|
|
54426
54692
|
key: PI_PACKAGES_KEY,
|
|
54427
54693
|
shown: PI_PACKAGES_KEY,
|
|
54428
54694
|
has: (v) => Array.isArray(v) && v.some((x) => piSource(x) === PI_GIT_PACKAGE),
|
|
@@ -54444,12 +54710,12 @@ function removeOwnEntries(agent, env) {
|
|
|
54444
54710
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
54445
54711
|
}
|
|
54446
54712
|
function removeProjectData(configDir, projectKey) {
|
|
54447
|
-
const projects =
|
|
54448
|
-
const dir =
|
|
54713
|
+
const projects = join19(configDir, PROJECTS_DIR_NAME);
|
|
54714
|
+
const dir = join19(projects, projectKey);
|
|
54449
54715
|
if (!existsSync19(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
54450
54716
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
54451
54717
|
for (const name of readdirSync9(dir)) {
|
|
54452
|
-
if (name !== OWNERS_DIR_NAME) rmSync8(
|
|
54718
|
+
if (name !== OWNERS_DIR_NAME) rmSync8(join19(dir, name), { recursive: true, force: true });
|
|
54453
54719
|
}
|
|
54454
54720
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
54455
54721
|
}
|
|
@@ -54457,12 +54723,12 @@ function runUninstall(input) {
|
|
|
54457
54723
|
const configDir = resolveConfigDir(input.env);
|
|
54458
54724
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
54459
54725
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
54460
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
54726
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join19(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
54461
54727
|
return { rows, stopped: stop.stopped };
|
|
54462
54728
|
}
|
|
54463
54729
|
|
|
54464
54730
|
// src/core/ops/v1-remove.ts
|
|
54465
|
-
import { copyFileSync as copyFileSync2, existsSync as existsSync20, readFileSync as
|
|
54731
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync20, readFileSync as readFileSync12, rmSync as rmSync9 } from "node:fs";
|
|
54466
54732
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
54467
54733
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
54468
54734
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -54481,13 +54747,13 @@ function keepOriginal(file2, kept, undo) {
|
|
|
54481
54747
|
undo.push({ trash, target: file2 });
|
|
54482
54748
|
}
|
|
54483
54749
|
function cutTomlTable(text, header) {
|
|
54484
|
-
let
|
|
54750
|
+
let span2;
|
|
54485
54751
|
try {
|
|
54486
|
-
|
|
54752
|
+
span2 = tomlTableSpans(text).find((t) => t.header.trim() === header);
|
|
54487
54753
|
} catch {
|
|
54488
54754
|
return null;
|
|
54489
54755
|
}
|
|
54490
|
-
return
|
|
54756
|
+
return span2 === void 0 ? null : text.slice(0, span2.start) + text.slice(span2.end);
|
|
54491
54757
|
}
|
|
54492
54758
|
function writeAtomic(file2, text) {
|
|
54493
54759
|
atomicWriteFile(file2, text);
|
|
@@ -54506,8 +54772,8 @@ function locate(doc, path7) {
|
|
|
54506
54772
|
return null;
|
|
54507
54773
|
}
|
|
54508
54774
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
54509
|
-
const layout = hostLayout(
|
|
54510
|
-
const text = hostText(
|
|
54775
|
+
const layout = hostLayout(readFileSync12(file2, "utf8"));
|
|
54776
|
+
const text = hostText(readFileSync12(file2, "utf8"));
|
|
54511
54777
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
54512
54778
|
const hit = /* @__PURE__ */ new Set();
|
|
54513
54779
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -54555,7 +54821,7 @@ function removeV1(agent, findings) {
|
|
|
54555
54821
|
continue;
|
|
54556
54822
|
}
|
|
54557
54823
|
if (file2.endsWith(TOML_EXT)) {
|
|
54558
|
-
const rawToml =
|
|
54824
|
+
const rawToml = readFileSync12(file2, "utf8");
|
|
54559
54825
|
const tomlLayout = hostLayout(rawToml);
|
|
54560
54826
|
let text = hostText(rawToml);
|
|
54561
54827
|
for (const f of list3) {
|
|
@@ -54593,8 +54859,8 @@ function removeV1(agent, findings) {
|
|
|
54593
54859
|
|
|
54594
54860
|
// src/core/ops/verify-sums.ts
|
|
54595
54861
|
import { createHash as createHash2 } from "node:crypto";
|
|
54596
|
-
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as
|
|
54597
|
-
import { join as
|
|
54862
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync13 } from "node:fs";
|
|
54863
|
+
import { join as join20 } from "node:path";
|
|
54598
54864
|
function mismatch() {
|
|
54599
54865
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
54600
54866
|
}
|
|
@@ -54615,24 +54881,24 @@ function walk2(dir, prefix, out) {
|
|
|
54615
54881
|
for (const entry of readdirSync10(dir, { withFileTypes: true })) {
|
|
54616
54882
|
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
54617
54883
|
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
54618
|
-
const abs =
|
|
54884
|
+
const abs = join20(dir, entry.name);
|
|
54619
54885
|
if (entry.isDirectory()) walk2(abs, rel, out);
|
|
54620
54886
|
else if (entry.isFile()) out.set(rel, abs);
|
|
54621
54887
|
else throw mismatch();
|
|
54622
54888
|
}
|
|
54623
54889
|
}
|
|
54624
54890
|
function verifySums(dir) {
|
|
54625
|
-
const sumsPath =
|
|
54891
|
+
const sumsPath = join20(dir, RELEASE_SUMS_FILE);
|
|
54626
54892
|
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
54627
54893
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
54628
|
-
const sums = parseSums(
|
|
54894
|
+
const sums = parseSums(readFileSync13(sumsPath, "utf8"));
|
|
54629
54895
|
const files = /* @__PURE__ */ new Map();
|
|
54630
54896
|
walk2(dir, "", files);
|
|
54631
54897
|
if (files.size !== sums.size) throw mismatch();
|
|
54632
54898
|
for (const [rel, abs] of files) {
|
|
54633
54899
|
const want = sums.get(rel);
|
|
54634
54900
|
if (want === void 0) throw mismatch();
|
|
54635
|
-
const got = createHash2(SUMS_HASH_ALGORITHM).update(
|
|
54901
|
+
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync13(abs)).digest(HASH_ENCODING);
|
|
54636
54902
|
if (got !== want) throw mismatch();
|
|
54637
54903
|
}
|
|
54638
54904
|
}
|
|
@@ -54660,7 +54926,7 @@ function pluginRootRow(adapter, env) {
|
|
|
54660
54926
|
return root === own4 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own4)];
|
|
54661
54927
|
}
|
|
54662
54928
|
function isCurrent(agentDir, dir) {
|
|
54663
|
-
const link =
|
|
54929
|
+
const link = join21(agentDir, PLUGIN_CURRENT_LINK);
|
|
54664
54930
|
return existsSync21(link) && realpathSync9.native(link) === realpathSync9.native(dir);
|
|
54665
54931
|
}
|
|
54666
54932
|
async function checkout(adapter, deps) {
|
|
@@ -54757,7 +55023,7 @@ function define(name) {
|
|
|
54757
55023
|
handler: built.handler
|
|
54758
55024
|
};
|
|
54759
55025
|
}
|
|
54760
|
-
var
|
|
55026
|
+
var TOOLS2 = Object.freeze(TOOL_ORDER.map(define));
|
|
54761
55027
|
function callExample(tool) {
|
|
54762
55028
|
const a = tool.description.indexOf("`");
|
|
54763
55029
|
const b = tool.description.indexOf("`", a + 1);
|
|
@@ -54880,7 +55146,7 @@ function errorReply(err) {
|
|
|
54880
55146
|
async function startServer(argv, env) {
|
|
54881
55147
|
const serverId = randomUUID();
|
|
54882
55148
|
const degraded = await isDegraded();
|
|
54883
|
-
const tools = degraded ?
|
|
55149
|
+
const tools = degraded ? TOOLS2.filter((t) => t.name === "ctx_doctor") : TOOLS2;
|
|
54884
55150
|
const pending = /* @__PURE__ */ new Map();
|
|
54885
55151
|
const held = [];
|
|
54886
55152
|
let cleaned = false;
|
|
@@ -54913,7 +55179,7 @@ async function startServer(argv, env) {
|
|
|
54913
55179
|
return db;
|
|
54914
55180
|
}
|
|
54915
55181
|
function stopMarker(configDir, projectKey) {
|
|
54916
|
-
return
|
|
55182
|
+
return join22(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
|
|
54917
55183
|
}
|
|
54918
55184
|
function stopRequested() {
|
|
54919
55185
|
const configDir = resolveConfigDir(process.env);
|