context-mode 2.0.0-next.29 → 2.0.0-next.32
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 +84 -83
- package/SHA256SUMS +19 -19
- package/claude-code/skills/ctx-stats/SKILL.md +2 -2
- package/cli.mjs +342 -152
- package/codex/skills/ctx-stats/SKILL.md +2 -2
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +75 -75
- package/opencode/plugin.js +1063 -309
- package/package.json +1 -1
- package/pi/index.js +1178 -425
- package/pi/skills/ctx-stats/SKILL.md +2 -2
- package/qwen-extension.json +1 -1
- package/run.mjs +84 -3
- package/search.mjs +84 -3
- package/server.mjs +1118 -365
- package/skills/ctx-stats/SKILL.md +2 -2
package/server.mjs
CHANGED
|
@@ -7,8 +7,8 @@ var __export = (target, all) => {
|
|
|
7
7
|
|
|
8
8
|
// src/entries/server.ts
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
|
-
import { existsSync as
|
|
11
|
-
import { dirname as dirname11, join as
|
|
10
|
+
import { existsSync as existsSync23, realpathSync as realpathSync12, rmSync as rmSync11 } from "node:fs";
|
|
11
|
+
import { dirname as dirname11, join as join23 } 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, {
|
|
@@ -3487,17 +3487,17 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
3487
3487
|
var NONE = 0;
|
|
3488
3488
|
var ASSUMED = 1;
|
|
3489
3489
|
var PROVEN = 2;
|
|
3490
|
-
function isRecursive(inst,
|
|
3490
|
+
function isRecursive(inst, stack2, resolve6) {
|
|
3491
3491
|
const cached4 = recursive.get(inst);
|
|
3492
3492
|
if (cached4 !== void 0)
|
|
3493
3493
|
return cached4 ? PROVEN : NONE;
|
|
3494
|
-
if (
|
|
3494
|
+
if (stack2.has(inst))
|
|
3495
3495
|
return PROVEN;
|
|
3496
|
-
|
|
3496
|
+
stack2.add(inst);
|
|
3497
3497
|
let result = NONE;
|
|
3498
3498
|
const check2 = (child) => {
|
|
3499
3499
|
if (result !== PROVEN && child?._zod) {
|
|
3500
|
-
const answer2 = isRecursive(child,
|
|
3500
|
+
const answer2 = isRecursive(child, stack2, resolve6);
|
|
3501
3501
|
if (answer2 > result)
|
|
3502
3502
|
result = answer2;
|
|
3503
3503
|
}
|
|
@@ -3508,7 +3508,7 @@ function isRecursive(inst, stack, resolve6) {
|
|
|
3508
3508
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
3509
3509
|
if (spread && !desc.enumerable)
|
|
3510
3510
|
continue;
|
|
3511
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value,
|
|
3511
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack2, resolve6) : NONE;
|
|
3512
3512
|
if (child > answer2)
|
|
3513
3513
|
answer2 = child;
|
|
3514
3514
|
}
|
|
@@ -3573,7 +3573,7 @@ function isRecursive(inst, stack, resolve6) {
|
|
|
3573
3573
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
3574
3574
|
case "lazy": {
|
|
3575
3575
|
const inner = def._cachedInner ?? (resolve6 ? inst._zod.innerType : void 0);
|
|
3576
|
-
merge5(inner ? isRecursive(inner,
|
|
3576
|
+
merge5(inner ? isRecursive(inner, stack2, false) : ASSUMED);
|
|
3577
3577
|
break;
|
|
3578
3578
|
}
|
|
3579
3579
|
// a leaf by choice: `parts` are regex fragments, not data positions
|
|
@@ -3616,7 +3616,7 @@ function isRecursive(inst, stack, resolve6) {
|
|
|
3616
3616
|
}
|
|
3617
3617
|
}
|
|
3618
3618
|
}
|
|
3619
|
-
|
|
3619
|
+
stack2.delete(inst);
|
|
3620
3620
|
return settle(inst, result);
|
|
3621
3621
|
}
|
|
3622
3622
|
function settle(inst, answer2) {
|
|
@@ -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, {
|
|
@@ -11016,17 +11016,17 @@ var recursive2 = /* @__PURE__ */ new WeakMap();
|
|
|
11016
11016
|
var NONE2 = 0;
|
|
11017
11017
|
var ASSUMED2 = 1;
|
|
11018
11018
|
var PROVEN2 = 2;
|
|
11019
|
-
function isRecursive2(inst,
|
|
11019
|
+
function isRecursive2(inst, stack2, resolve6) {
|
|
11020
11020
|
const cached4 = recursive2.get(inst);
|
|
11021
11021
|
if (cached4 !== void 0)
|
|
11022
11022
|
return cached4 ? PROVEN2 : NONE2;
|
|
11023
|
-
if (
|
|
11023
|
+
if (stack2.has(inst))
|
|
11024
11024
|
return PROVEN2;
|
|
11025
|
-
|
|
11025
|
+
stack2.add(inst);
|
|
11026
11026
|
let result = NONE2;
|
|
11027
11027
|
const check2 = (child) => {
|
|
11028
11028
|
if (result !== PROVEN2 && child?._zod) {
|
|
11029
|
-
const answer2 = isRecursive2(child,
|
|
11029
|
+
const answer2 = isRecursive2(child, stack2, resolve6);
|
|
11030
11030
|
if (answer2 > result)
|
|
11031
11031
|
result = answer2;
|
|
11032
11032
|
}
|
|
@@ -11037,7 +11037,7 @@ function isRecursive2(inst, stack, resolve6) {
|
|
|
11037
11037
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
11038
11038
|
if (spread && !desc.enumerable)
|
|
11039
11039
|
continue;
|
|
11040
|
-
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value,
|
|
11040
|
+
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack2, resolve6) : NONE2;
|
|
11041
11041
|
if (child > answer2)
|
|
11042
11042
|
answer2 = child;
|
|
11043
11043
|
}
|
|
@@ -11102,7 +11102,7 @@ function isRecursive2(inst, stack, resolve6) {
|
|
|
11102
11102
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
11103
11103
|
case "lazy": {
|
|
11104
11104
|
const inner = def._cachedInner ?? (resolve6 ? inst._zod.innerType : void 0);
|
|
11105
|
-
merge5(inner ? isRecursive2(inner,
|
|
11105
|
+
merge5(inner ? isRecursive2(inner, stack2, false) : ASSUMED2);
|
|
11106
11106
|
break;
|
|
11107
11107
|
}
|
|
11108
11108
|
// a leaf by choice: `parts` are regex fragments, not data positions
|
|
@@ -11145,7 +11145,7 @@ function isRecursive2(inst, stack, resolve6) {
|
|
|
11145
11145
|
}
|
|
11146
11146
|
}
|
|
11147
11147
|
}
|
|
11148
|
-
|
|
11148
|
+
stack2.delete(inst);
|
|
11149
11149
|
return settle2(inst, result);
|
|
11150
11150
|
}
|
|
11151
11151
|
function settle2(inst, answer2) {
|
|
@@ -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
|
|
26912
|
-
const
|
|
26913
|
-
while (
|
|
26914
|
-
const node3 =
|
|
26911
|
+
let count2 = 0;
|
|
26912
|
+
const stack2 = [value];
|
|
26913
|
+
while (stack2.length > 0) {
|
|
26914
|
+
const node3 = stack2.pop();
|
|
26915
26915
|
if (node3 === null || typeof node3 !== "object") continue;
|
|
26916
26916
|
if (Array.isArray(node3)) for (const child of node3) {
|
|
26917
|
-
if (++
|
|
26918
|
-
if (child !== null && typeof child === "object")
|
|
26917
|
+
if (++count2 > max) return count2;
|
|
26918
|
+
if (child !== null && typeof child === "object") stack2.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
|
-
if (child !== null && typeof child === "object")
|
|
26924
|
+
if (child !== null && typeof child === "object") stack2.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;
|
|
@@ -26997,9 +26997,9 @@ var McpServer = class {
|
|
|
26997
26997
|
resolveScopeChallenge = (context) => {
|
|
26998
26998
|
switch (context.request.method) {
|
|
26999
26999
|
case "tools/call": {
|
|
27000
|
-
const
|
|
27001
|
-
if (typeof
|
|
27002
|
-
const tool = this._registeredTools[
|
|
27000
|
+
const toolName2 = context.request.params?.name;
|
|
27001
|
+
if (typeof toolName2 !== "string") return;
|
|
27002
|
+
const tool = this._registeredTools[toolName2];
|
|
27003
27003
|
if (tool === void 0 || !tool.enabled) return;
|
|
27004
27004
|
return tool.scopeChallenge?.(context);
|
|
27005
27005
|
}
|
|
@@ -27083,23 +27083,23 @@ var McpServer = class {
|
|
|
27083
27083
|
/**
|
|
27084
27084
|
* Validates tool input arguments against the tool's input schema.
|
|
27085
27085
|
*/
|
|
27086
|
-
async validateToolInput(tool, args,
|
|
27087
|
-
if (this._maxToolInputElements !== void 0 && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid arguments for tool ${
|
|
27086
|
+
async validateToolInput(tool, args, toolName2) {
|
|
27087
|
+
if (this._maxToolInputElements !== void 0 && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid arguments for tool ${toolName2}: arguments contain more than the maximum of ${this._maxToolInputElements} elements`);
|
|
27088
27088
|
if (!tool.inputSchema) return;
|
|
27089
27089
|
const parseResult = await validateStandardSchema(tool.inputSchema, args ?? {});
|
|
27090
|
-
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${
|
|
27090
|
+
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${toolName2}: ${parseResult.error}`);
|
|
27091
27091
|
return parseResult.data;
|
|
27092
27092
|
}
|
|
27093
27093
|
/**
|
|
27094
27094
|
* Validates tool output against the tool's output schema.
|
|
27095
27095
|
*/
|
|
27096
|
-
async validateToolOutput(tool, result,
|
|
27096
|
+
async validateToolOutput(tool, result, toolName2) {
|
|
27097
27097
|
if (!tool.outputSchema) return;
|
|
27098
27098
|
if (isInputRequiredResult(result)) return;
|
|
27099
27099
|
if (result.isError) return;
|
|
27100
|
-
if (result.structuredContent === void 0) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Tool ${
|
|
27100
|
+
if (result.structuredContent === void 0) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Tool ${toolName2} has an output schema but no structured content was provided`);
|
|
27101
27101
|
const parseResult = await validateStandardSchema(tool.outputSchema, result.structuredContent);
|
|
27102
|
-
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${
|
|
27102
|
+
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${toolName2}: ${parseResult.error}`);
|
|
27103
27103
|
}
|
|
27104
27104
|
/**
|
|
27105
27105
|
* Executes a tool handler.
|
|
@@ -28246,6 +28246,7 @@ var SOURCE_LABEL_MAX_CHARS = 80;
|
|
|
28246
28246
|
var CANCELLED_LINE = "Cancelled.";
|
|
28247
28247
|
var BACKGROUND_REPLY_PREFIX = "started in background, pid ";
|
|
28248
28248
|
var PLAIN_OUTPUT_ENV = Object.freeze({ NO_COLOR: "1", FORCE_COLOR: "0" });
|
|
28249
|
+
var RUN_LABEL_PREFIX = "run.mjs:";
|
|
28249
28250
|
var RUN_SESSION_PREFIX = "mcp:";
|
|
28250
28251
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
28251
28252
|
var NODE_MIN = "24.15.0";
|
|
@@ -28296,11 +28297,11 @@ var HOOK_FAIL_REDIRECT = Object.freeze({
|
|
|
28296
28297
|
grep: "Search with ctx_execute(language, code), or index the files with ctx_index and query them with ctx_search.",
|
|
28297
28298
|
fetch: "Index the URL with ctx_index and query it with ctx_search."
|
|
28298
28299
|
});
|
|
28299
|
-
function D5_LAST_HOOK_ERROR(ts, stage,
|
|
28300
|
-
return `; last hook error ${ts} at ${stage} (${
|
|
28300
|
+
function D5_LAST_HOOK_ERROR(ts, stage, label2) {
|
|
28301
|
+
return `; last hook error ${ts} at ${stage} (${label2}), stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
28301
28302
|
}
|
|
28302
|
-
function D5_PAST_HOOK_ERROR(ts, stage,
|
|
28303
|
-
return `; past hook error ${ts} at ${stage} (${
|
|
28303
|
+
function D5_PAST_HOOK_ERROR(ts, stage, label2) {
|
|
28304
|
+
return `; past hook error ${ts} at ${stage} (${label2}), before this run, stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
28304
28305
|
}
|
|
28305
28306
|
var BOUNDED_COMMANDS = Object.freeze(["pwd", "whoami", "uname", "id", "realpath", "ln"]);
|
|
28306
28307
|
var BOUNDED_GIT_SUBCOMMANDS = Object.freeze(["status"]);
|
|
@@ -28340,6 +28341,59 @@ function STATS_SUMMARY(allTimePct, sessionPct) {
|
|
|
28340
28341
|
}
|
|
28341
28342
|
var STATS_COLUMNS = Object.freeze(["Scope", "Produced", "Returned", "Saved", "Reduction %"]);
|
|
28342
28343
|
var STATS_NO_DATA = "no data \u2014 no tool calls recorded yet";
|
|
28344
|
+
var STATS_WIDTH = 80;
|
|
28345
|
+
var STATS_BYTES_PER_TOKEN = 4;
|
|
28346
|
+
var STATS_MAX_TOOL_ROWS = 12;
|
|
28347
|
+
var STATS_LABEL_W = 21;
|
|
28348
|
+
var STATS_LABEL_MAX = 20;
|
|
28349
|
+
var STATS_CALLS_W = 7;
|
|
28350
|
+
var STATS_NUM_W = 11;
|
|
28351
|
+
var STATS_PCT_W = 8;
|
|
28352
|
+
var STATS_KIND_W = 9;
|
|
28353
|
+
var STATS_HEAD_BAR = 40;
|
|
28354
|
+
var STATS_ROW_BAR = 8;
|
|
28355
|
+
var STATS_KIND_BAR = 20;
|
|
28356
|
+
var STATS_KIB = 1024;
|
|
28357
|
+
var STATS_MILLION = 1e6;
|
|
28358
|
+
var STATS_MS_PER_MINUTE = 6e4;
|
|
28359
|
+
var STATS_MINUTES_PER_HOUR = 60;
|
|
28360
|
+
var STATS_HOURS_PER_DAY = 24;
|
|
28361
|
+
var STATS_CLOCK_DIGITS = 2;
|
|
28362
|
+
var STATS_REPORT_TITLE = "context-mode stats";
|
|
28363
|
+
var STATS_EMPTY_LINES = Object.freeze([
|
|
28364
|
+
"Ready. Your savings show up here after the first tool call.",
|
|
28365
|
+
"Large outputs from ctx_execute, ctx_batch and ctx_index stay in the",
|
|
28366
|
+
"sandbox, and only the short answer goes to the chat."
|
|
28367
|
+
]);
|
|
28368
|
+
var STATS_KIND_LABELS = Object.freeze([
|
|
28369
|
+
// D-STATS-FIX-1 (8): the first five rows are call kinds, so they add up to the calls of the scope line.
|
|
28370
|
+
["index", "Content indexed"],
|
|
28371
|
+
["edit", "File edits"],
|
|
28372
|
+
["toolerr", "Issues kept"],
|
|
28373
|
+
["decision", "Your decisions"],
|
|
28374
|
+
["cmd", "Other tool calls"],
|
|
28375
|
+
["prompt", "Your prompts"]
|
|
28376
|
+
]);
|
|
28377
|
+
var STATS_JOURNAL_HINTS = Object.freeze([
|
|
28378
|
+
"ctx_resume brings back your last task, files changed and open issues",
|
|
28379
|
+
"after a compact or a restart; ctx_search finds indexed content by words."
|
|
28380
|
+
]);
|
|
28381
|
+
var STATS_WINDOW_TOKENS = 2e5;
|
|
28382
|
+
var STATS_THOUSAND = 1e3;
|
|
28383
|
+
var STATS_WHOLE_FROM = 10;
|
|
28384
|
+
var STATS_DAYS = 7;
|
|
28385
|
+
var STATS_TOP_OUTPUTS = 3;
|
|
28386
|
+
var STATS_CARD_W = 19;
|
|
28387
|
+
var STATS_DAY_BAR = 48;
|
|
28388
|
+
var STATS_TOKEN_NOTE = " (at 4 bytes per token; a Claude context window is 200K tokens)";
|
|
28389
|
+
var STATS_WAYS = Object.freeze([
|
|
28390
|
+
["sandbox", "\u2588", "sandbox run"],
|
|
28391
|
+
["index", "\u2593", "index + search"],
|
|
28392
|
+
["redirect", "\u2592", "hook sent to sandbox"],
|
|
28393
|
+
["replace", "\u2591", "hook cut down"]
|
|
28394
|
+
]);
|
|
28395
|
+
var STATS_INDEX_TOOLS = Object.freeze(["ctx_index", "ctx_search"]);
|
|
28396
|
+
var STATS_FOOTER_URL = "https://contextmode.ai/?utm_source=ctx_stats&utm_medium=stats&utm_content=footer";
|
|
28343
28397
|
var PURGE_SCOPES = Object.freeze(["session", "source", "project"]);
|
|
28344
28398
|
var PURGE_NO_SCOPE_LINE = "ctx_purge: pick one scope \u2014 session, source, or project.";
|
|
28345
28399
|
var PURGE_MANY_SCOPES_LINE = "ctx_purge: pick only one scope \u2014 session, source, or project.";
|
|
@@ -28351,7 +28405,7 @@ var DECISION_SOURCE = "decision";
|
|
|
28351
28405
|
var DECISION_USER_LABEL = "decision (user)";
|
|
28352
28406
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
28353
28407
|
var RELEASE_BRANCH = "release";
|
|
28354
|
-
var BUNDLE_SHA = true ? "
|
|
28408
|
+
var BUNDLE_SHA = true ? "feb8de116956b3d3eff56c7d5ed2d840483d0cd4" : void 0;
|
|
28355
28409
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
28356
28410
|
var DOCTOR_LABEL = Object.freeze({
|
|
28357
28411
|
D1: "version",
|
|
@@ -28381,9 +28435,49 @@ function DOCTOR_FAIL_LINE(host, check2, cause, command) {
|
|
|
28381
28435
|
return `FAIL ${host}: ${check2} \u2014 ${cause}. Fix: ${command}`;
|
|
28382
28436
|
}
|
|
28383
28437
|
var DOCTOR_FIX_UPGRADE = "run ctx_upgrade";
|
|
28384
|
-
var
|
|
28385
|
-
var D1_DEV_BUILD_DETAIL = "dev build";
|
|
28438
|
+
var D1_DEV_BUILD_DETAIL = "dev build: source checkout; release builds stamp the sha";
|
|
28386
28439
|
var D1_UPDATE_DETAIL = "update available";
|
|
28440
|
+
var D1_SHORT_SHA_LEN = 7;
|
|
28441
|
+
var D1_PACKAGE_FILE = "package.json";
|
|
28442
|
+
function D1_PREFIX(version4, sha) {
|
|
28443
|
+
return `${version4 ?? "bundle"} (${sha.slice(0, D1_SHORT_SHA_LEN)})`;
|
|
28444
|
+
}
|
|
28445
|
+
var D1_GIT_PASS = "latest on the release branch";
|
|
28446
|
+
function D1_NPM_PASS(tag) {
|
|
28447
|
+
return `latest ${tag} on npm`;
|
|
28448
|
+
}
|
|
28449
|
+
function D1_NPM_UPDATE(tag, latest) {
|
|
28450
|
+
return `${D1_UPDATE_DETAIL}, ${tag} on npm is ${latest}`;
|
|
28451
|
+
}
|
|
28452
|
+
var D1_LATEST_UNKNOWN = "latest unknown";
|
|
28453
|
+
var D1_GIT_MISSING = "git not found on PATH";
|
|
28454
|
+
function D1_GIT_EXIT(code, stderrLine) {
|
|
28455
|
+
return stderrLine === "" ? `git exit ${code}` : `git exit ${code}: ${stderrLine}`;
|
|
28456
|
+
}
|
|
28457
|
+
function D1_GIT_TIMEOUT(ms) {
|
|
28458
|
+
return `git timed out after ${ms} ms`;
|
|
28459
|
+
}
|
|
28460
|
+
var D1_GIT_CANCEL = "git stopped by cancel";
|
|
28461
|
+
var D1_GIT_NO_START = "git did not start";
|
|
28462
|
+
var D1_GIT_NO_SHA = "git answered no sha";
|
|
28463
|
+
function D1_NPM_TIMEOUT(ms) {
|
|
28464
|
+
return `npm registry timed out after ${ms} ms`;
|
|
28465
|
+
}
|
|
28466
|
+
function D1_NPM_HTTP(status) {
|
|
28467
|
+
return `npm registry answered HTTP ${status}`;
|
|
28468
|
+
}
|
|
28469
|
+
function D1_NPM_ERROR(cause) {
|
|
28470
|
+
return `npm registry: ${cause}`;
|
|
28471
|
+
}
|
|
28472
|
+
function D1_NPM_NO_TAG(tag) {
|
|
28473
|
+
return `npm registry answered no ${tag} version`;
|
|
28474
|
+
}
|
|
28475
|
+
var D1_CAUSE_JOIN = "; ";
|
|
28476
|
+
var D1_GIT_CHECK_FIX = `git ls-remote ${RELEASE_REPO_URL} ${RELEASE_BRANCH}`;
|
|
28477
|
+
var D1_NPM_CHECK_FIX = "npm view context-mode dist-tags";
|
|
28478
|
+
var D1_REGISTRY_URL = "https://registry.npmjs.org/-/package/context-mode/dist-tags";
|
|
28479
|
+
var D1_PRERELEASE_SEP = "-";
|
|
28480
|
+
var D1_DEFAULT_TAG = "latest";
|
|
28387
28481
|
var GIT_LS_REMOTE = "ls-remote";
|
|
28388
28482
|
var D2_NODE_FIX = `install Node ${NODE_MIN} or later`;
|
|
28389
28483
|
function D2_NODE_DETAIL(version4) {
|
|
@@ -28672,7 +28766,7 @@ var V1_REASON = Object.freeze({
|
|
|
28672
28766
|
dataDir: "old context-mode data dir <agent home>/context-mode/",
|
|
28673
28767
|
dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
|
|
28674
28768
|
dataRoot: "old context-mode content under ~/.context-mode/",
|
|
28675
|
-
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only,
|
|
28769
|
+
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep"
|
|
28676
28770
|
});
|
|
28677
28771
|
var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering]);
|
|
28678
28772
|
var PLUGIN_NAME = SERVER_KEY;
|
|
@@ -28713,6 +28807,85 @@ var REPORT_ENV_PREFIX = "env.";
|
|
|
28713
28807
|
var REPORT_ENV_ENUMS = Object.freeze({
|
|
28714
28808
|
NODE_ENV: Object.freeze(["development", "production", "test"])
|
|
28715
28809
|
});
|
|
28810
|
+
var DOCTOR_ENV_PREFIX = "Environment: ";
|
|
28811
|
+
var DOCTOR_DOCS_URL = "https://contextmode.ai/docs/engine/doctor";
|
|
28812
|
+
var DOCTOR_DOCS_ANCHOR = "checks";
|
|
28813
|
+
function DOCTOR_DOCS_LINK(check2) {
|
|
28814
|
+
return `${DOCTOR_DOCS_URL}?utm_source=ctx_doctor&utm_medium=doctor&utm_content=${check2}#${DOCTOR_DOCS_ANCHOR}`;
|
|
28815
|
+
}
|
|
28816
|
+
var DOCTOR_DOCS_LABEL = "Docs: ";
|
|
28817
|
+
function D3_NO_SETUP_FIX(agent) {
|
|
28818
|
+
return `context-mode setup --agents ${agent}`;
|
|
28819
|
+
}
|
|
28820
|
+
function D5_FIXTURE_FILE_ABSENT(file2) {
|
|
28821
|
+
return `hook fixture ${file2} is absent: the round trip needs it`;
|
|
28822
|
+
}
|
|
28823
|
+
function D5_FIXTURE_PARSE(file2, cause) {
|
|
28824
|
+
return `the hook fixture file ${file2} failed to parse: ${cause}`;
|
|
28825
|
+
}
|
|
28826
|
+
function D5_FIXTURE_AGENT_ABSENT(file2, keys) {
|
|
28827
|
+
return `the hook fixture file ${file2} records payloads for ${keys.join(", ") || "zero agents"} only`;
|
|
28828
|
+
}
|
|
28829
|
+
var DOCTOR_REPORTS_DIR = "reports";
|
|
28830
|
+
var DOCTOR_REPORT_FILE_PREFIX = "doctor-";
|
|
28831
|
+
var DOCTOR_REPORT_LINE = "Report file: ";
|
|
28832
|
+
var DOCTOR_GH_LINE = "File it: ";
|
|
28833
|
+
var DOCTOR_URL_LINE = "Or open: ";
|
|
28834
|
+
var DOCTOR_GH_NEXT = " --";
|
|
28835
|
+
var DOCTOR_NOTE_PREFIXES = Object.freeze([
|
|
28836
|
+
DOCTOR_ENV_PREFIX,
|
|
28837
|
+
DOCTOR_DOCS_LABEL,
|
|
28838
|
+
DOCTOR_REPORT_LINE,
|
|
28839
|
+
DOCTOR_GH_LINE,
|
|
28840
|
+
DOCTOR_GH_NEXT.trim(),
|
|
28841
|
+
DOCTOR_URL_LINE
|
|
28842
|
+
]);
|
|
28843
|
+
var ISSUE_REPO_SLUG = "mksglu/context-mode";
|
|
28844
|
+
var ISSUE_FORM_FILE = "agent-report.yml";
|
|
28845
|
+
var ISSUE_URL_MAX = 8e3;
|
|
28846
|
+
var ISSUE_FORM_HEADINGS = Object.freeze([
|
|
28847
|
+
"Summary",
|
|
28848
|
+
"ctx-report",
|
|
28849
|
+
"What happened",
|
|
28850
|
+
"Hook errors",
|
|
28851
|
+
"Journal rows",
|
|
28852
|
+
"Agent config",
|
|
28853
|
+
"Expected",
|
|
28854
|
+
"Steps",
|
|
28855
|
+
"Environment"
|
|
28856
|
+
]);
|
|
28857
|
+
var DOCTOR_HOOK_LOG_LINES = 50;
|
|
28858
|
+
var DOCTOR_JOURNAL_ROWS = 30;
|
|
28859
|
+
var DOCTOR_CONFIG_LINES = 40;
|
|
28860
|
+
var DOCTOR_ENV_NAMES = Object.freeze([
|
|
28861
|
+
"CODEX_HOME",
|
|
28862
|
+
"CLAUDE_CONFIG_DIR",
|
|
28863
|
+
"CLAUDE_PLUGIN_ROOT",
|
|
28864
|
+
"COPILOT_HOME",
|
|
28865
|
+
"KIRO_HOME",
|
|
28866
|
+
"OPENCODE_CONFIG_DIR",
|
|
28867
|
+
"PI_CODING_AGENT_DIR",
|
|
28868
|
+
"XDG_CONFIG_HOME",
|
|
28869
|
+
"SHELL"
|
|
28870
|
+
]);
|
|
28871
|
+
var DOCTOR_PATH_TOOLS = Object.freeze(["node", "git", "sh"]);
|
|
28872
|
+
var DOCTOR_SECRET_WORDS = Object.freeze(["token", "secret", "password", "apikey", "api_key", "authorization", "bearer"]);
|
|
28873
|
+
var DOCTOR_MASK = "<masked>";
|
|
28874
|
+
var NATIVE_INSTALL = Object.freeze({
|
|
28875
|
+
"claude-code": ["claude plugin marketplace add mksglu/context-mode#release", "claude plugin install context-mode@context-mode"],
|
|
28876
|
+
codex: ["codex plugin marketplace add mksglu/context-mode@release", "codex plugin add context-mode@context-mode"],
|
|
28877
|
+
gemini: ["gemini extensions install https://github.com/mksglu/context-mode --ref release"],
|
|
28878
|
+
qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release"],
|
|
28879
|
+
opencode: ["opencode plugin add context-mode@next"],
|
|
28880
|
+
pi: ["pi install npm:context-mode@next"],
|
|
28881
|
+
"copilot-cli": ["npm i -g context-mode@next", "context-mode setup --agents copilot-cli"],
|
|
28882
|
+
vscode: ["npm i -g context-mode@next", "context-mode setup --agents vscode"],
|
|
28883
|
+
kiro: ["npm i -g context-mode@next", "context-mode setup --agents kiro"],
|
|
28884
|
+
zcode: ["npm i -g context-mode@next", "context-mode setup --agents zcode"]
|
|
28885
|
+
});
|
|
28886
|
+
var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
|
|
28887
|
+
var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
|
|
28888
|
+
var DOCTOR_LOG_TAIL_BYTES = 262144;
|
|
28716
28889
|
|
|
28717
28890
|
// src/core/contracts/errors.ts
|
|
28718
28891
|
var ERROR_TEXT = Object.freeze({
|
|
@@ -29462,8 +29635,8 @@ function firstLine(file2) {
|
|
|
29462
29635
|
return line === "" ? null : line;
|
|
29463
29636
|
}
|
|
29464
29637
|
function git(dir, args) {
|
|
29465
|
-
const { spawnSync:
|
|
29466
|
-
const r =
|
|
29638
|
+
const { spawnSync: spawnSync4 } = process.getBuiltinModule("node:child_process");
|
|
29639
|
+
const r = spawnSync4("git", args, { cwd: dir, shell: false, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
29467
29640
|
if (r.error !== void 0 || r.status !== 0) throw new CtxError("NO_GIT_DIR", { path: dir });
|
|
29468
29641
|
return r.stdout.split("\n").filter((l) => l !== "");
|
|
29469
29642
|
}
|
|
@@ -29649,7 +29822,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
29649
29822
|
terms = given.filter((t) => t.text.length >= 5).map((t) => ({ ...t, text: t.text.slice(0, Math.max(4, t.text.length - 2)) }));
|
|
29650
29823
|
pos = terms.map(find2);
|
|
29651
29824
|
}
|
|
29652
|
-
const
|
|
29825
|
+
const count2 = (ti, a, b) => {
|
|
29653
29826
|
const ps = pos[ti];
|
|
29654
29827
|
let lo = 0, hi = ps.length;
|
|
29655
29828
|
while (lo < hi) {
|
|
@@ -29664,7 +29837,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
29664
29837
|
const N = blocks.length;
|
|
29665
29838
|
const blen = blocks.map((bk2) => rangeBytes(bk2.first, bk2.last));
|
|
29666
29839
|
const avg = blen.reduce((a, b) => a + b, 0) / N || 1;
|
|
29667
|
-
const tf = blocks.map((bk2) => terms.map((_, ti) =>
|
|
29840
|
+
const tf = blocks.map((bk2) => terms.map((_, ti) => count2(ti, ls[bk2.first], le[bk2.last])));
|
|
29668
29841
|
const idf = terms.map((_, ti) => {
|
|
29669
29842
|
let df = 0;
|
|
29670
29843
|
for (let k = 0; k < N; k++) if (tf[k][ti] > 0) df++;
|
|
@@ -29686,7 +29859,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
29686
29859
|
const lineScore = (i) => {
|
|
29687
29860
|
let s = 0;
|
|
29688
29861
|
terms.forEach((_, ti) => {
|
|
29689
|
-
if (
|
|
29862
|
+
if (count2(ti, ls[i], le[i]) > 0) s += weight(ti, bk.code);
|
|
29690
29863
|
});
|
|
29691
29864
|
return s;
|
|
29692
29865
|
};
|
|
@@ -29694,7 +29867,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
29694
29867
|
let at = -1;
|
|
29695
29868
|
let w = -1;
|
|
29696
29869
|
terms.forEach((_, ti) => {
|
|
29697
|
-
const c =
|
|
29870
|
+
const c = count2(ti, ls[i], le[i]);
|
|
29698
29871
|
if (c === 0 || weight(ti, bk.code) <= w) return;
|
|
29699
29872
|
const ps = pos[ti];
|
|
29700
29873
|
let lo = 0, hi = ps.length;
|
|
@@ -31651,8 +31824,8 @@ function trigramMatch(q) {
|
|
|
31651
31824
|
const words = blankTokens(q);
|
|
31652
31825
|
const kept = words.filter((w) => !STOPWORDS.has(w.toLowerCase()));
|
|
31653
31826
|
const parts = new Set((kept.length > 0 ? kept : words).filter((w) => [...w].length >= 3));
|
|
31654
|
-
const
|
|
31655
|
-
if (words.length > 1 && [...
|
|
31827
|
+
const whole2 = words.join(" ");
|
|
31828
|
+
if (words.length > 1 && [...whole2].length >= 3) parts.add(whole2);
|
|
31656
31829
|
return [...parts].map((w) => `"${w.replaceAll('"', '""')}"`).join(" OR ");
|
|
31657
31830
|
}
|
|
31658
31831
|
function editDistance(a, b, max) {
|
|
@@ -31932,8 +32105,8 @@ function parseSourceHandle(s) {
|
|
|
31932
32105
|
function pathLabel(p) {
|
|
31933
32106
|
return p.includes("\\") ? p.split("\\").join("/") : p;
|
|
31934
32107
|
}
|
|
31935
|
-
function labelStored(db,
|
|
31936
|
-
return stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = ? LIMIT 1").get(
|
|
32108
|
+
function labelStored(db, label2) {
|
|
32109
|
+
return stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = ? LIMIT 1").get(label2) !== void 0;
|
|
31937
32110
|
}
|
|
31938
32111
|
function storedLabel(db, source) {
|
|
31939
32112
|
if (labelStored(db, source)) return source;
|
|
@@ -35951,8 +36124,8 @@ function az_default() {
|
|
|
35951
36124
|
}
|
|
35952
36125
|
|
|
35953
36126
|
// node_modules/zod/v4/locales/be.js
|
|
35954
|
-
function getBelarusianPlural(
|
|
35955
|
-
const absCount = Math.abs(
|
|
36127
|
+
function getBelarusianPlural(count2, one, few, many) {
|
|
36128
|
+
const absCount = Math.abs(count2);
|
|
35956
36129
|
const lastDigit = absCount % 10;
|
|
35957
36130
|
const lastTwoDigits = absCount % 100;
|
|
35958
36131
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -39097,8 +39270,8 @@ function pt_default() {
|
|
|
39097
39270
|
}
|
|
39098
39271
|
|
|
39099
39272
|
// node_modules/zod/v4/locales/ru.js
|
|
39100
|
-
function getRussianPlural(
|
|
39101
|
-
const absCount = Math.abs(
|
|
39273
|
+
function getRussianPlural(count2, one, few, many) {
|
|
39274
|
+
const absCount = Math.abs(count2);
|
|
39102
39275
|
const lastDigit = absCount % 10;
|
|
39103
39276
|
const lastTwoDigits = absCount % 100;
|
|
39104
39277
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -43263,8 +43436,8 @@ var TOOL_DESCRIPTIONS = Object.freeze({
|
|
|
43263
43436
|
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
43437
|
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
43438
|
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
|
|
43267
|
-
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
|
|
43439
|
+
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.",
|
|
43440
|
+
ctx_doctor: "Example: `ctx_doctor({})`. Required: none.\nChecks this context-mode install and reports a table with one row per check: version, Node and node:sqlite, host config and hooks for this agent, MCP connection, project and worktree, database health, index contents, and hook timing. Each failed row names its cause, the fix and a docs link. Use it when the user asks whether context-mode works, or after a context-mode error. Run each Fix first, then call ctx_doctor again. If a FAIL stays, show the user the report file it names (it holds paths and environment details) and ask before you run the printed gh issue command.\n",
|
|
43268
43441
|
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
43442
|
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.'
|
|
43270
43443
|
});
|
|
@@ -43298,11 +43471,11 @@ function chunkText(text, kind, maxBytes = MAX_CHUNK_BYTES) {
|
|
|
43298
43471
|
}
|
|
43299
43472
|
function mdChunks(src, cap, lineCut) {
|
|
43300
43473
|
const out = [];
|
|
43301
|
-
const
|
|
43474
|
+
const stack2 = [];
|
|
43302
43475
|
let title = "";
|
|
43303
43476
|
let run = [];
|
|
43304
|
-
const push = (text,
|
|
43305
|
-
out.push({ ord: out.length, text, bytes:
|
|
43477
|
+
const push = (text, bytes5) => {
|
|
43478
|
+
out.push({ ord: out.length, text, bytes: bytes5, title });
|
|
43306
43479
|
};
|
|
43307
43480
|
const flush = () => {
|
|
43308
43481
|
if (run.length === 0) return;
|
|
@@ -43312,9 +43485,9 @@ function mdChunks(src, cap, lineCut) {
|
|
|
43312
43485
|
for (const b of lineBlocks(src, true)) {
|
|
43313
43486
|
if (b.heading !== void 0) {
|
|
43314
43487
|
flush();
|
|
43315
|
-
while (
|
|
43316
|
-
|
|
43317
|
-
title =
|
|
43488
|
+
while (stack2.length > 0 && stack2[stack2.length - 1].level >= b.heading.level) stack2.pop();
|
|
43489
|
+
stack2.push(b.heading);
|
|
43490
|
+
title = stack2.map((h) => h.text).join(" > ");
|
|
43318
43491
|
}
|
|
43319
43492
|
if (b.fence !== void 0 && utf8Bytes(src.slice(b.start, b.end)) > cap) {
|
|
43320
43493
|
const pieces = fencePieces(src, b, b.fence, cap);
|
|
@@ -43352,19 +43525,19 @@ function lineBlocks(src, md) {
|
|
|
43352
43525
|
let fenceInfo;
|
|
43353
43526
|
const close = () => {
|
|
43354
43527
|
if (start >= 0) {
|
|
43355
|
-
const
|
|
43356
|
-
if (heading !== void 0)
|
|
43357
|
-
if (fenceInfo !== void 0)
|
|
43358
|
-
out.push(
|
|
43528
|
+
const span2 = { start, end };
|
|
43529
|
+
if (heading !== void 0) span2.heading = heading;
|
|
43530
|
+
if (fenceInfo !== void 0) span2.fence = fenceInfo;
|
|
43531
|
+
out.push(span2);
|
|
43359
43532
|
}
|
|
43360
43533
|
start = -1;
|
|
43361
43534
|
heading = void 0;
|
|
43362
43535
|
fenceInfo = void 0;
|
|
43363
43536
|
};
|
|
43364
|
-
const add = (from, to,
|
|
43537
|
+
const add = (from, to, table3) => {
|
|
43365
43538
|
if (start < 0) start = from;
|
|
43366
43539
|
end = to;
|
|
43367
|
-
inTable =
|
|
43540
|
+
inTable = table3;
|
|
43368
43541
|
};
|
|
43369
43542
|
let pos = 0;
|
|
43370
43543
|
while (pos <= src.length) {
|
|
@@ -43385,9 +43558,9 @@ function lineBlocks(src, md) {
|
|
|
43385
43558
|
} else {
|
|
43386
43559
|
const opener = md ? fenceOf(line) : "";
|
|
43387
43560
|
const head = md && opener === "" ? headingOf(line) : void 0;
|
|
43388
|
-
const
|
|
43389
|
-
if (md && start >= 0 && (
|
|
43390
|
-
add(pos, eol,
|
|
43561
|
+
const table3 = md && opener === "" && head === void 0 && line.includes("|");
|
|
43562
|
+
if (md && start >= 0 && (table3 !== inTable || opener !== "" || head !== void 0)) close();
|
|
43563
|
+
add(pos, eol, table3);
|
|
43391
43564
|
fence = opener;
|
|
43392
43565
|
if (opener !== "") fenceInfo = { fence: opener, openEnd: eol, closeStart: -1 };
|
|
43393
43566
|
if (head !== void 0) {
|
|
@@ -43547,17 +43720,17 @@ function cutPoint(src, start, end, scratch) {
|
|
|
43547
43720
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
43548
43721
|
return { end: start + r.read, written: r.written };
|
|
43549
43722
|
}
|
|
43550
|
-
function merge4(src, blocks,
|
|
43723
|
+
function merge4(src, blocks, join24, cap, lineCut) {
|
|
43551
43724
|
const out = [];
|
|
43552
43725
|
const scratch = new Uint8Array(cap);
|
|
43553
43726
|
let wide;
|
|
43554
43727
|
let cur;
|
|
43555
43728
|
let curBytes = 0;
|
|
43556
|
-
const emit = (start, end,
|
|
43557
|
-
out.push({ ord: out.length, text: src.slice(start, end), bytes:
|
|
43729
|
+
const emit = (start, end, bytes5) => {
|
|
43730
|
+
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
43558
43731
|
};
|
|
43559
43732
|
for (const b of blocks) {
|
|
43560
|
-
if (cur !== void 0 && !
|
|
43733
|
+
if (cur !== void 0 && !join24) {
|
|
43561
43734
|
emit(cur.start, cur.end, curBytes);
|
|
43562
43735
|
cur = void 0;
|
|
43563
43736
|
}
|
|
@@ -43572,15 +43745,15 @@ function merge4(src, blocks, join22, cap, lineCut) {
|
|
|
43572
43745
|
cur = void 0;
|
|
43573
43746
|
}
|
|
43574
43747
|
let start = b.start;
|
|
43575
|
-
let
|
|
43576
|
-
while (
|
|
43748
|
+
let bytes5 = utf8Bytes(src.slice(b.start, b.end));
|
|
43749
|
+
while (bytes5 > cap) {
|
|
43577
43750
|
const cut = cutPoint(src, start, b.end, scratch);
|
|
43578
43751
|
const nl = lineCut ? src.lastIndexOf("\n", cut.end - 1) : -1;
|
|
43579
43752
|
if (nl > start) {
|
|
43580
43753
|
const w = utf8Bytes(src.slice(start, nl + 1));
|
|
43581
43754
|
emit(start, nl + 1, w);
|
|
43582
43755
|
start = nl + 1;
|
|
43583
|
-
|
|
43756
|
+
bytes5 -= w;
|
|
43584
43757
|
continue;
|
|
43585
43758
|
}
|
|
43586
43759
|
if (lineCut) {
|
|
@@ -43590,23 +43763,23 @@ function merge4(src, blocks, join22, cap, lineCut) {
|
|
|
43590
43763
|
if (w <= MAX_CHUNK_BYTES) {
|
|
43591
43764
|
emit(start, lineEnd, w);
|
|
43592
43765
|
start = lineEnd;
|
|
43593
|
-
|
|
43766
|
+
bytes5 -= w;
|
|
43594
43767
|
continue;
|
|
43595
43768
|
}
|
|
43596
43769
|
wide ??= new Uint8Array(MAX_CHUNK_BYTES);
|
|
43597
43770
|
const big = cutPoint(src, start, lineEnd, wide);
|
|
43598
43771
|
emit(start, big.end, big.written);
|
|
43599
43772
|
start = big.end;
|
|
43600
|
-
|
|
43773
|
+
bytes5 -= big.written;
|
|
43601
43774
|
continue;
|
|
43602
43775
|
}
|
|
43603
43776
|
emit(start, cut.end, cut.written);
|
|
43604
43777
|
start = cut.end;
|
|
43605
|
-
|
|
43778
|
+
bytes5 -= cut.written;
|
|
43606
43779
|
}
|
|
43607
43780
|
if (start >= b.end) continue;
|
|
43608
43781
|
cur = { start, end: b.end };
|
|
43609
|
-
curBytes =
|
|
43782
|
+
curBytes = bytes5;
|
|
43610
43783
|
}
|
|
43611
43784
|
if (cur !== void 0) emit(cur.start, cur.end, curBytes);
|
|
43612
43785
|
return out;
|
|
@@ -43655,9 +43828,9 @@ import { accessSync, constants as fsConstants, statSync as statSync2 } from "nod
|
|
|
43655
43828
|
import path from "node:path";
|
|
43656
43829
|
|
|
43657
43830
|
// src/core/sandbox/path-entries.ts
|
|
43658
|
-
function pathEntries(value, platform = process.platform,
|
|
43831
|
+
function pathEntries(value, platform = process.platform, delimiter2 = platform === "win32" ? ";" : ":") {
|
|
43659
43832
|
const win = platform === "win32";
|
|
43660
|
-
return value.split(
|
|
43833
|
+
return value.split(delimiter2).map((e) => win && e.length >= 2 && e.startsWith('"') && e.endsWith('"') ? e.slice(1, -1) : e).filter(Boolean);
|
|
43661
43834
|
}
|
|
43662
43835
|
|
|
43663
43836
|
// src/core/sandbox/runtimes.ts
|
|
@@ -43889,8 +44062,8 @@ function jsonRows(text) {
|
|
|
43889
44062
|
return { objs, keys };
|
|
43890
44063
|
}
|
|
43891
44064
|
function fitRow(row5, skewed, named, budget) {
|
|
43892
|
-
const
|
|
43893
|
-
if (bytes(
|
|
44065
|
+
const whole2 = JSON.stringify(row5);
|
|
44066
|
+
if (bytes(whole2) <= budget) return whole2;
|
|
43894
44067
|
const own4 = Object.keys(row5);
|
|
43895
44068
|
const tier = (k) => skewed.includes(k) ? 0 : named.has(k) ? 1 : typeof row5[k] !== "object" || row5[k] === null ? 2 : 3;
|
|
43896
44069
|
const order = [...own4].sort((a, b) => tier(a) - tier(b) || own4.indexOf(a) - own4.indexOf(b));
|
|
@@ -44081,7 +44254,7 @@ function relevance(db, given, scope, ctx) {
|
|
|
44081
44254
|
mine.add(hit.sourceId);
|
|
44082
44255
|
}
|
|
44083
44256
|
if (again.size > 0) {
|
|
44084
|
-
const line = "Same as above: " + [...again].map(([
|
|
44257
|
+
const line = "Same as above: " + [...again].map(([label2, ords]) => label2 + " (chunk " + ords.join(",") + ")").join("; ");
|
|
44085
44258
|
lines.push(line);
|
|
44086
44259
|
used += bytes2(line) + 1;
|
|
44087
44260
|
}
|
|
@@ -44228,7 +44401,7 @@ function shown(chunks, heads) {
|
|
|
44228
44401
|
return c.text;
|
|
44229
44402
|
});
|
|
44230
44403
|
}
|
|
44231
|
-
function indexCombined(db, ctx,
|
|
44404
|
+
function indexCombined(db, ctx, label2, ran, deadline, budgetBytes) {
|
|
44232
44405
|
const chunks = chunkText(ran.map((r) => r.block).join(BLOCK_SEP), "text");
|
|
44233
44406
|
const display = shown(chunks, ran.map((r) => r.head));
|
|
44234
44407
|
const bodies = /* @__PURE__ */ new Map();
|
|
@@ -44248,7 +44421,7 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
|
|
|
44248
44421
|
worktree: ctx.project.worktree,
|
|
44249
44422
|
agent: ctx.project.agent,
|
|
44250
44423
|
kind: "content",
|
|
44251
|
-
label,
|
|
44424
|
+
label: label2,
|
|
44252
44425
|
bytes: groupBytes,
|
|
44253
44426
|
chunkCount: group.length,
|
|
44254
44427
|
createdAt: Date.now()
|
|
@@ -44278,12 +44451,12 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
|
|
|
44278
44451
|
function bytes3(s) {
|
|
44279
44452
|
return Buffer.byteLength(s, "utf8");
|
|
44280
44453
|
}
|
|
44281
|
-
function answer(db, ctx,
|
|
44454
|
+
function answer(db, ctx, label2, queries, share, own4) {
|
|
44282
44455
|
const seen = /* @__PURE__ */ new Set();
|
|
44283
44456
|
const lines = [];
|
|
44284
44457
|
for (const [qi, q] of queries.entries()) {
|
|
44285
44458
|
if (ctx.signal.aborted) break;
|
|
44286
|
-
let hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0,
|
|
44459
|
+
let hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0, label2);
|
|
44287
44460
|
if (hits.length === 0) hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0);
|
|
44288
44461
|
const head = "## " + (bytes3(q) > ECHO_MAX_BYTES ? "query " + (qi + 1) : q);
|
|
44289
44462
|
let used = bytes3(head) + 1;
|
|
@@ -44322,17 +44495,17 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
44322
44495
|
const ran = pool.results;
|
|
44323
44496
|
const last2 = ran[ran.length - 1];
|
|
44324
44497
|
const sandboxBytes = ran.reduce((n, r) => n + r.bytes, 0);
|
|
44325
|
-
const
|
|
44498
|
+
const label2 = LABEL_PREFIX + ctx.turn;
|
|
44326
44499
|
try {
|
|
44327
44500
|
const db = await openDb(ctx.project);
|
|
44328
44501
|
let sections;
|
|
44329
44502
|
let idx;
|
|
44330
44503
|
const exitLine = last2.exitCode === null || last2.exitCode === 0 ? null : "exit " + last2.exitCode;
|
|
44331
|
-
const footer = "more: ctx_search({queries:[...], source:" + JSON.stringify(
|
|
44504
|
+
const footer = "more: ctx_search({queries:[...], source:" + JSON.stringify(label2) + "})";
|
|
44332
44505
|
let notice;
|
|
44333
44506
|
let showMore;
|
|
44334
44507
|
try {
|
|
44335
|
-
idx = indexCombined(db, ctx,
|
|
44508
|
+
idx = indexCombined(db, ctx, label2, ran, deadline, budgetBytes);
|
|
44336
44509
|
const stop = last2.error;
|
|
44337
44510
|
const cut = idx.indexed < idx.total ? "Indexed " + idx.indexed + " of " + idx.total + " B." : null;
|
|
44338
44511
|
const timeout = formatError3("TIMEOUT", { ms: boundMs });
|
|
@@ -44340,7 +44513,7 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
44340
44513
|
notice = cut === null ? stop : cause === null ? cut : cause + " " + cut;
|
|
44341
44514
|
const fixed = (exitLine === null ? 0 : bytes3(exitLine) + 1) + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
|
|
44342
44515
|
const share = Math.floor((OUTPUT_CAP - fixed) / queries.length);
|
|
44343
|
-
const answered = answer(db, ctx,
|
|
44516
|
+
const answered = answer(db, ctx, label2, queries, share, idx.bodies);
|
|
44344
44517
|
sections = answered.lines;
|
|
44345
44518
|
const unseen = [...idx.bodies].filter(([k, text]) => text !== "" && !answered.seen.has(k)).map(([k]) => idx.raw.get(k));
|
|
44346
44519
|
const unseenBytes = unseen.reduce((n, t) => n + bytes3(t) + 1, 0);
|
|
@@ -44376,8 +44549,8 @@ var ctxBatch = Object.freeze({
|
|
|
44376
44549
|
});
|
|
44377
44550
|
|
|
44378
44551
|
// src/core/tools/doctor.ts
|
|
44379
|
-
import { readdirSync as readdirSync6, readFileSync as
|
|
44380
|
-
import { basename as basename4, dirname as dirname6, join as
|
|
44552
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync10, existsSync as existsSync14 } from "node:fs";
|
|
44553
|
+
import { basename as basename4, dirname as dirname6, join as join13 } from "node:path";
|
|
44381
44554
|
|
|
44382
44555
|
// src/adapters/claude-code.ts
|
|
44383
44556
|
var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
@@ -44705,8 +44878,8 @@ function decode7(raw) {
|
|
|
44705
44878
|
if (event === "SessionStart" && typeof raw.source === "string" && COPILOT_SOURCES[raw.source] !== void 0) ev.source = COPILOT_SOURCES[raw.source];
|
|
44706
44879
|
if (event === "UserPromptSubmit" && typeof raw.prompt === "string") ev.prompt = raw.prompt;
|
|
44707
44880
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
44708
|
-
const
|
|
44709
|
-
const tool = { name:
|
|
44881
|
+
const toolName2 = String(raw[k.tool] ?? "");
|
|
44882
|
+
const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: readArgs(raw[k.args]) };
|
|
44710
44883
|
ev.tool = tool;
|
|
44711
44884
|
}
|
|
44712
44885
|
if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
|
|
@@ -44820,9 +44993,9 @@ function decodeCamel(p, name) {
|
|
|
44820
44993
|
if (event === "SessionStart" && typeof p.source === "string" && SESSION_SOURCES[p.source] !== void 0) ev.source = SESSION_SOURCES[p.source];
|
|
44821
44994
|
if (event === "UserPromptSubmit" && typeof p.prompt === "string") ev.prompt = p.prompt;
|
|
44822
44995
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
44823
|
-
const
|
|
44824
|
-
const canonical = canonicalName4(
|
|
44825
|
-
ev.tool = { name:
|
|
44996
|
+
const toolName2 = String(p.toolName ?? "");
|
|
44997
|
+
const canonical = canonicalName4(toolName2);
|
|
44998
|
+
ev.tool = { name: toolName2, canonicalName: canonical, input: policyInput(toolName2, canonical, readArgs2(p.toolArgs)) };
|
|
44826
44999
|
}
|
|
44827
45000
|
if (event === "PostToolUse") ev.result = readCamelResult(p.toolResult);
|
|
44828
45001
|
return ev;
|
|
@@ -46433,7 +46606,7 @@ var Tokenizer = class {
|
|
|
46433
46606
|
hasUnderscore
|
|
46434
46607
|
};
|
|
46435
46608
|
}
|
|
46436
|
-
parseUnicode(
|
|
46609
|
+
parseUnicode(count2) {
|
|
46437
46610
|
const startLoc = this.codePointIterator.start;
|
|
46438
46611
|
const start = this.codePointIterator.end;
|
|
46439
46612
|
let charCount = 0;
|
|
@@ -46444,7 +46617,7 @@ var Tokenizer = class {
|
|
|
46444
46617
|
return this.reportParseError("invalid-char-in-escape-sequence");
|
|
46445
46618
|
}
|
|
46446
46619
|
charCount++;
|
|
46447
|
-
if (charCount >=
|
|
46620
|
+
if (charCount >= count2) break;
|
|
46448
46621
|
}
|
|
46449
46622
|
const end = this.codePointIterator.end;
|
|
46450
46623
|
const code = this.text.slice(start, end);
|
|
@@ -47210,17 +47383,17 @@ function generateConvertTOMLValue(convertValue) {
|
|
|
47210
47383
|
return baseTable;
|
|
47211
47384
|
},
|
|
47212
47385
|
TOMLTable(node3, baseTable = {}) {
|
|
47213
|
-
const
|
|
47214
|
-
for (const body of node3.body) resolveValue(body,
|
|
47386
|
+
const table3 = getTable(baseTable, resolveValue(node3.key), node3.kind === "array");
|
|
47387
|
+
for (const body of node3.body) resolveValue(body, table3);
|
|
47215
47388
|
return baseTable;
|
|
47216
47389
|
},
|
|
47217
47390
|
TOMLArray(node3) {
|
|
47218
47391
|
return node3.elements.map((e) => resolveValue(e));
|
|
47219
47392
|
},
|
|
47220
47393
|
TOMLInlineTable(node3) {
|
|
47221
|
-
const
|
|
47222
|
-
for (const body of node3.body) resolveValue(body,
|
|
47223
|
-
return
|
|
47394
|
+
const table3 = {};
|
|
47395
|
+
for (const body of node3.body) resolveValue(body, table3);
|
|
47396
|
+
return table3;
|
|
47224
47397
|
},
|
|
47225
47398
|
TOMLKey(node3) {
|
|
47226
47399
|
return node3.keys.map((key) => resolveValue(key));
|
|
@@ -47738,8 +47911,8 @@ function setTomlText(text, path7, value) {
|
|
|
47738
47911
|
if (sameValue(cur, value)) return text;
|
|
47739
47912
|
const inline = doc.keys.find((k) => k.inline && k.full.length < path7.length && under(path7, k.full));
|
|
47740
47913
|
if (inline !== void 0) {
|
|
47741
|
-
const
|
|
47742
|
-
return replaceToml(text, doc, inline.full,
|
|
47914
|
+
const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path7.slice(inline.full.length), value);
|
|
47915
|
+
return replaceToml(text, doc, inline.full, whole2);
|
|
47743
47916
|
}
|
|
47744
47917
|
if (isPlainObject6(cur) && isPlainObject6(value)) {
|
|
47745
47918
|
const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
|
|
@@ -47983,10 +48156,10 @@ function scanCodex(agentHome, out) {
|
|
|
47983
48156
|
}
|
|
47984
48157
|
const tomlFile = join7(agentHome, CONFIG_TOML_FILE);
|
|
47985
48158
|
const config4 = readTomlValue(tomlFile);
|
|
47986
|
-
for (const
|
|
47987
|
-
if (
|
|
47988
|
-
if (
|
|
47989
|
-
out.push(finding(tomlFile,
|
|
48159
|
+
for (const span2 of readTomlTables(tomlFile)) {
|
|
48160
|
+
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
48161
|
+
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config4, span2.path))) continue;
|
|
48162
|
+
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
47990
48163
|
}
|
|
47991
48164
|
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
47992
48165
|
}
|
|
@@ -48418,14 +48591,18 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
48418
48591
|
return true;
|
|
48419
48592
|
}
|
|
48420
48593
|
}
|
|
48594
|
+
function hookFile(row5, spec, home, env, worktree) {
|
|
48595
|
+
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
48596
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
48597
|
+
const file2 = native !== null ? join9(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join9(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join9(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join9(kiroDirOf(env, home), ...spec.file.slice(1)) : join9(root, ...spec.file);
|
|
48598
|
+
return file2;
|
|
48599
|
+
}
|
|
48421
48600
|
function hookParts(row5, home, env, worktree) {
|
|
48422
48601
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
48423
48602
|
if (spec === null) return [];
|
|
48424
48603
|
let block;
|
|
48425
48604
|
try {
|
|
48426
|
-
const
|
|
48427
|
-
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
48428
|
-
const file2 = native !== null ? join9(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join9(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join9(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join9(kiroDirOf(env, home), ...spec.file.slice(1)) : join9(root, ...spec.file);
|
|
48605
|
+
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
48429
48606
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
48430
48607
|
if (row5.id === "codex") {
|
|
48431
48608
|
const config4 = readParsed(row5.id, join9(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
@@ -48466,12 +48643,15 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
48466
48643
|
const read = row5.id === "pi" ? mcpFile(row5, home, env) : null;
|
|
48467
48644
|
if (parts.length === 0) return read === null ? pass("D3") : { ...pass("D3"), detail: read };
|
|
48468
48645
|
const detail = D3_DETAIL(parts);
|
|
48469
|
-
|
|
48646
|
+
const fix = parts.includes(PART_MCP) && parts.includes(PART_HOOKS) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
|
|
48647
|
+
return fail("D3", read === null ? detail : detail + D4_REASON_JOIN + read, fix);
|
|
48470
48648
|
}
|
|
48471
48649
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
48472
48650
|
const findings = detectV1(agent, home, scope);
|
|
48473
48651
|
if (findings.length === 0) return pass("D4");
|
|
48474
|
-
|
|
48652
|
+
const detail = findings.map((f) => f.reason).join(D4_REASON_JOIN);
|
|
48653
|
+
if (findings.every((f) => f.reason === V1_REASON.tmpFile)) return { ...pass("D4"), detail };
|
|
48654
|
+
return fail("D4", detail, DOCTOR_FIX_UPGRADE);
|
|
48475
48655
|
}
|
|
48476
48656
|
function parsedOrNull(agent, file2, jsonc) {
|
|
48477
48657
|
try {
|
|
@@ -48490,6 +48670,31 @@ function checkDoubleFire(agent, worktree) {
|
|
|
48490
48670
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
48491
48671
|
return hooksOn && useClaudeHooks ? fail("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
|
|
48492
48672
|
}
|
|
48673
|
+
function configPaths(row5, env, worktree) {
|
|
48674
|
+
const home = homeDirOf(env);
|
|
48675
|
+
if (home === null) return [];
|
|
48676
|
+
const out = [];
|
|
48677
|
+
const mcp = mcpFile(row5, home, env);
|
|
48678
|
+
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
48679
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
48680
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join9(native, CODEX_PLUGIN_MCP_FILE) });
|
|
48681
|
+
const spec = HOOK_HOST_FILE[row5.id];
|
|
48682
|
+
if (spec !== null) {
|
|
48683
|
+
try {
|
|
48684
|
+
out.push({ label: "hook entries", path: hookFile(row5, spec, home, env, worktree) });
|
|
48685
|
+
} catch (err) {
|
|
48686
|
+
out.push({ label: "hook entries", path: err instanceof Error ? err.message : String(err) });
|
|
48687
|
+
}
|
|
48688
|
+
}
|
|
48689
|
+
if (spec !== null && spec.root === "plugin" || row5.installMode === "marketplace" || row5.installMode === "plugin") {
|
|
48690
|
+
try {
|
|
48691
|
+
out.push({ label: "plugin root", path: resolvePluginRoot(row5, env, worktree) });
|
|
48692
|
+
} catch (err) {
|
|
48693
|
+
out.push({ label: "plugin root", path: err instanceof Error ? err.message : String(err) });
|
|
48694
|
+
}
|
|
48695
|
+
}
|
|
48696
|
+
return out.filter((e, i) => out.findIndex((o) => o.path === e.path) === i);
|
|
48697
|
+
}
|
|
48493
48698
|
|
|
48494
48699
|
// src/core/ops/doctor-db.ts
|
|
48495
48700
|
import { existsSync as existsSync8 } from "node:fs";
|
|
@@ -48575,29 +48780,92 @@ async function checkIndex(project) {
|
|
|
48575
48780
|
}
|
|
48576
48781
|
|
|
48577
48782
|
// 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";
|
|
48783
|
+
import { existsSync as existsSync9, readFileSync as readFileSync7, realpathSync as realpathSync5 } from "node:fs";
|
|
48784
|
+
import { isAbsolute as isAbsolute2, join as join10, relative } from "node:path";
|
|
48580
48785
|
function pass3(id, detail = DOCTOR_PASS_DETAIL) {
|
|
48581
48786
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
48582
48787
|
}
|
|
48583
|
-
function unknown5(id, detail) {
|
|
48584
|
-
return { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail };
|
|
48788
|
+
function unknown5(id, detail, fixCommand) {
|
|
48789
|
+
return fixCommand === void 0 ? { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail } : { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail, fixCommand };
|
|
48585
48790
|
}
|
|
48586
48791
|
function fail3(id, detail, fixCommand) {
|
|
48587
48792
|
return { id, label: DOCTOR_LABEL[id], status: "FAIL", detail, fixCommand };
|
|
48588
48793
|
}
|
|
48794
|
+
function bundleVersion(bundleDir2) {
|
|
48795
|
+
try {
|
|
48796
|
+
const v = JSON.parse(readFileSync7(join10(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
48797
|
+
return typeof v === "string" && v !== "" ? v : void 0;
|
|
48798
|
+
} catch {
|
|
48799
|
+
return void 0;
|
|
48800
|
+
}
|
|
48801
|
+
}
|
|
48802
|
+
function channelOf(version4) {
|
|
48803
|
+
const at = version4.indexOf(D1_PRERELEASE_SEP);
|
|
48804
|
+
if (at < 0) return D1_DEFAULT_TAG;
|
|
48805
|
+
const pre = version4.slice(at + 1);
|
|
48806
|
+
const dot = pre.indexOf(".");
|
|
48807
|
+
const tag = dot < 0 ? pre : pre.slice(0, dot);
|
|
48808
|
+
return tag === "" ? D1_DEFAULT_TAG : tag;
|
|
48809
|
+
}
|
|
48810
|
+
function firstLine2(b) {
|
|
48811
|
+
const text = b.toString("utf8").trim();
|
|
48812
|
+
const nl = text.indexOf("\n");
|
|
48813
|
+
return (nl < 0 ? text : text.slice(0, nl)).trim();
|
|
48814
|
+
}
|
|
48815
|
+
function gitCause(r, timeoutMs) {
|
|
48816
|
+
if (r.killed === "timeout") return D1_GIT_TIMEOUT(timeoutMs);
|
|
48817
|
+
if (r.killed === "cancel") return D1_GIT_CANCEL;
|
|
48818
|
+
if (r.exitCode === null) return D1_GIT_NO_START;
|
|
48819
|
+
return D1_GIT_EXIT(r.exitCode, firstLine2(r.stderr));
|
|
48820
|
+
}
|
|
48821
|
+
function fetchCause(err, timeoutMs) {
|
|
48822
|
+
const name = err instanceof Error ? err.name : "";
|
|
48823
|
+
if (name === "TimeoutError") return D1_NPM_TIMEOUT(timeoutMs);
|
|
48824
|
+
const cause = err instanceof Error && err.cause instanceof Error ? err.cause : err;
|
|
48825
|
+
const code = typeof cause === "object" && cause !== null && "code" in cause && typeof cause.code === "string" ? cause.code : "";
|
|
48826
|
+
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
48827
|
+
return D1_NPM_ERROR(code !== "" && !msg.includes(code) ? `${code} ${msg}` : msg);
|
|
48828
|
+
}
|
|
48829
|
+
async function npmLatest(url4, tag, signal, timeoutMs) {
|
|
48830
|
+
try {
|
|
48831
|
+
const res = await fetch(url4, { signal: AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) });
|
|
48832
|
+
if (!res.ok) return { ok: false, cause: D1_NPM_HTTP(res.status) };
|
|
48833
|
+
const body = await res.json();
|
|
48834
|
+
const v = typeof body === "object" && body !== null ? body[tag] : void 0;
|
|
48835
|
+
return typeof v === "string" && v !== "" ? { ok: true, version: v } : { ok: false, cause: D1_NPM_NO_TAG(tag) };
|
|
48836
|
+
} catch (err) {
|
|
48837
|
+
return { ok: false, cause: fetchCause(err, timeoutMs) };
|
|
48838
|
+
}
|
|
48839
|
+
}
|
|
48589
48840
|
async function checkVersion(i) {
|
|
48590
48841
|
if (i.bundleSha === void 0) return unknown5("D1", D1_DEV_BUILD_DETAIL);
|
|
48591
|
-
const
|
|
48592
|
-
|
|
48593
|
-
|
|
48594
|
-
|
|
48595
|
-
|
|
48596
|
-
|
|
48597
|
-
|
|
48598
|
-
|
|
48599
|
-
|
|
48600
|
-
|
|
48842
|
+
const head = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
48843
|
+
const git3 = findRuntime(GIT_BIN, i.env);
|
|
48844
|
+
let cause = D1_GIT_MISSING;
|
|
48845
|
+
if (git3 !== null) {
|
|
48846
|
+
const r = await runProcess([git3, GIT_LS_REMOTE, RELEASE_REPO_URL, RELEASE_BRANCH], {
|
|
48847
|
+
cwd: i.cwd,
|
|
48848
|
+
env: { ...i.env, ...GIT_NO_PROMPT_ENV },
|
|
48849
|
+
signal: i.signal,
|
|
48850
|
+
timeoutMs: i.timeoutMs
|
|
48851
|
+
});
|
|
48852
|
+
if (r.exitCode === 0 && r.killed === null) {
|
|
48853
|
+
const latest = r.stdout.toString("utf8").split(LS_REMOTE_FIELD_SEP)[0];
|
|
48854
|
+
if (latest.length === GIT_SHA_HEX_LEN) {
|
|
48855
|
+
return latest === i.bundleSha ? pass3("D1", head + D1_GIT_PASS) : fail3("D1", head + D1_UPDATE_DETAIL, DOCTOR_FIX_UPGRADE);
|
|
48856
|
+
}
|
|
48857
|
+
cause = D1_GIT_NO_SHA;
|
|
48858
|
+
} else {
|
|
48859
|
+
cause = gitCause(r, i.timeoutMs);
|
|
48860
|
+
}
|
|
48861
|
+
}
|
|
48862
|
+
const handFix = git3 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX;
|
|
48863
|
+
if (i.version === void 0) return unknown5("D1", head + D1_LATEST_UNKNOWN + ", " + cause, handFix);
|
|
48864
|
+
const tag = channelOf(i.version);
|
|
48865
|
+
const npm = await npmLatest(i.registryUrl, tag, i.signal, i.timeoutMs);
|
|
48866
|
+
if (!npm.ok) return unknown5("D1", head + D1_LATEST_UNKNOWN + ", " + cause + D1_CAUSE_JOIN + npm.cause, handFix);
|
|
48867
|
+
if (npm.version === i.version) return pass3("D1", head + D1_NPM_PASS(tag) + D1_CAUSE_JOIN + cause);
|
|
48868
|
+
return fail3("D1", head + D1_NPM_UPDATE(tag, npm.version) + D1_CAUSE_JOIN + cause, DOCTOR_FIX_UPGRADE);
|
|
48601
48869
|
}
|
|
48602
48870
|
function numbers(v) {
|
|
48603
48871
|
const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
|
|
@@ -48654,7 +48922,7 @@ function checkShell(env) {
|
|
|
48654
48922
|
}
|
|
48655
48923
|
|
|
48656
48924
|
// src/core/ops/doctor-hook.ts
|
|
48657
|
-
import { existsSync as existsSync11, readFileSync as
|
|
48925
|
+
import { existsSync as existsSync11, readFileSync as readFileSync8, realpathSync as realpathSync7 } from "node:fs";
|
|
48658
48926
|
import path6 from "node:path";
|
|
48659
48927
|
|
|
48660
48928
|
// src/setup/codex-trust.ts
|
|
@@ -48876,16 +49144,19 @@ function isObject5(v) {
|
|
|
48876
49144
|
}
|
|
48877
49145
|
function loadFixture(bundleDir2, agent) {
|
|
48878
49146
|
const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
48879
|
-
if (!existsSync11(file2)) return
|
|
49147
|
+
if (!existsSync11(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
48880
49148
|
let all;
|
|
48881
49149
|
try {
|
|
48882
|
-
all = JSON.parse(hostText(
|
|
48883
|
-
} catch {
|
|
48884
|
-
return
|
|
49150
|
+
all = JSON.parse(hostText(readFileSync8(file2, "utf8")));
|
|
49151
|
+
} catch (err) {
|
|
49152
|
+
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
48885
49153
|
}
|
|
48886
|
-
if (!isObject5(all)
|
|
49154
|
+
if (!isObject5(all)) return { cause: D5_FIXTURE_PARSE(file2, "top level is not an object") };
|
|
49155
|
+
if (!Object.hasOwn(all, agent)) return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": " + D5_FIXTURE_AGENT_ABSENT(file2, Object.keys(all)) };
|
|
48887
49156
|
const e = all[agent];
|
|
48888
|
-
if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload"))
|
|
49157
|
+
if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) {
|
|
49158
|
+
return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": the entry lacks an event name or a payload" };
|
|
49159
|
+
}
|
|
48889
49160
|
return { event: e.event, payload: e.payload };
|
|
48890
49161
|
}
|
|
48891
49162
|
function payloadFor(payload, worktree) {
|
|
@@ -48939,7 +49210,7 @@ async function checkHookRoundTrip(i) {
|
|
|
48939
49210
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
48940
49211
|
}
|
|
48941
49212
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
48942
|
-
if (
|
|
49213
|
+
if ("cause" in fixture) return row("UNKNOWN", fixture.cause);
|
|
48943
49214
|
const now = i.now ?? (() => performance.now());
|
|
48944
49215
|
const fixed = i.samples === void 0 ? null : Math.max(1, i.samples);
|
|
48945
49216
|
const maxPairs = fixed ?? D5_MAX_PAIRS;
|
|
@@ -48972,14 +49243,14 @@ async function checkHookRoundTrip(i) {
|
|
|
48972
49243
|
}
|
|
48973
49244
|
|
|
48974
49245
|
// src/core/hooks/fallback.ts
|
|
48975
|
-
import { join as
|
|
49246
|
+
import { join as join11, resolve as resolve3 } from "node:path";
|
|
48976
49247
|
var fs = process.getBuiltinModule("node:fs");
|
|
48977
49248
|
function homeOf(env) {
|
|
48978
49249
|
return env.HOME ?? env.USERPROFILE ?? "";
|
|
48979
49250
|
}
|
|
48980
49251
|
function hookLogPath(env) {
|
|
48981
49252
|
const home = homeOf(env);
|
|
48982
|
-
return home === "" ? "" :
|
|
49253
|
+
return home === "" ? "" : join11(home, DATA_ROOT.slice(1), HOOK_ERROR_LOG_FILE);
|
|
48983
49254
|
}
|
|
48984
49255
|
function lastHookError(env) {
|
|
48985
49256
|
try {
|
|
@@ -49079,8 +49350,13 @@ function envLine(key, value) {
|
|
|
49079
49350
|
const typedValue = allowed !== void 0 && allowed.includes(value) ? value : REPORT_INVALID;
|
|
49080
49351
|
return REPORT_ENV_PREFIX + typedKey + ": " + typedValue;
|
|
49081
49352
|
}
|
|
49353
|
+
function fixCell(agent, row5) {
|
|
49354
|
+
if (row5.status === "PASS") return "";
|
|
49355
|
+
if (row5.status === "FAIL") return DOCTOR_FAIL_LINE(agent, row5.id, row5.detail, row5.fixCommand ?? "");
|
|
49356
|
+
return row5.fixCommand === void 0 ? "" : "Fix: " + row5.fixCommand;
|
|
49357
|
+
}
|
|
49082
49358
|
function rowLine(agent, row5) {
|
|
49083
|
-
const fix =
|
|
49359
|
+
const fix = fixCell(agent, row5);
|
|
49084
49360
|
return "| " + [row5.id + " " + row5.label, row5.status, row5.detail, fix].join(" | ") + " |";
|
|
49085
49361
|
}
|
|
49086
49362
|
function buildReport(input) {
|
|
@@ -49110,15 +49386,205 @@ function buildReportHead(input) {
|
|
|
49110
49386
|
return lines.concat(tail).join("\n");
|
|
49111
49387
|
}
|
|
49112
49388
|
|
|
49389
|
+
// src/core/ops/doctor-issue.ts
|
|
49390
|
+
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
49391
|
+
import { closeSync, existsSync as existsSync13, fstatSync, mkdirSync as mkdirSync5, openSync, readFileSync as readFileSync9, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
|
|
49392
|
+
import { delimiter, join as join12 } from "node:path";
|
|
49393
|
+
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
49394
|
+
function tildeOf(env) {
|
|
49395
|
+
const home = homeDirOf(env);
|
|
49396
|
+
if (home === null || home === "") return (t) => t;
|
|
49397
|
+
const homes = [home];
|
|
49398
|
+
try {
|
|
49399
|
+
const real2 = realpathSync8.native(home);
|
|
49400
|
+
if (real2 !== home) homes.push(real2);
|
|
49401
|
+
} catch {
|
|
49402
|
+
}
|
|
49403
|
+
homes.sort((a, b) => b.length - a.length);
|
|
49404
|
+
const slash = (rest) => rest.replace(/^[^\s"'`|)>,;]*/, (run) => run.replace(/\\/g, "/"));
|
|
49405
|
+
return (t) => homes.reduce((acc, h) => acc.split(h).map((piece, n) => n === 0 ? piece : slash(piece)).join("~"), t);
|
|
49406
|
+
}
|
|
49407
|
+
function maskLine(line) {
|
|
49408
|
+
const lower = line.toLowerCase();
|
|
49409
|
+
const named = DOCTOR_SECRET_WORDS.some((w) => lower.includes(w));
|
|
49410
|
+
const token = TOKEN_PREFIXES.some((p) => line.includes(p));
|
|
49411
|
+
if (!named && !token) return line;
|
|
49412
|
+
const at = Math.max(line.indexOf(":"), line.indexOf("="));
|
|
49413
|
+
return at === -1 ? DOCTOR_MASK : line.slice(0, at + 1) + " " + DOCTOR_MASK;
|
|
49414
|
+
}
|
|
49415
|
+
function environmentLine(ctx, adapter, env, version4) {
|
|
49416
|
+
const sha = BUNDLE_SHA === void 0 ? "dev build" : BUNDLE_SHA.slice(0, 7);
|
|
49417
|
+
const client = ctx.clientInfo;
|
|
49418
|
+
const agent = client === void 0 ? adapter.id : client.name === adapter.id ? `${adapter.id} ${client.version}` : `${adapter.id} ${client.version} (client ${client.name})`;
|
|
49419
|
+
const shell = env.SHELL ?? env.ComSpec ?? "sh";
|
|
49420
|
+
return `${DOCTOR_ENV_PREFIX}context-mode ${version4 ?? "source checkout"} (${sha}), agent ${agent}
|
|
49421
|
+
${DOCTOR_ENV_PREFIX}${process.platform}-${process.arch}, Node ${process.version}, shell ${shell}`;
|
|
49422
|
+
}
|
|
49423
|
+
function gitVersion(env) {
|
|
49424
|
+
const r = spawnSync3("git", ["--version"], { env, encoding: "utf8", timeout: DOCTOR_GIT_VERSION_TIMEOUT_MS, windowsHide: true });
|
|
49425
|
+
if (r.status === 0) return `${r.stdout}`.trim();
|
|
49426
|
+
return `git --version: ${r.error ? r.error.message : `exit ${r.status}`}`;
|
|
49427
|
+
}
|
|
49428
|
+
function onPath(env, tool) {
|
|
49429
|
+
const names = process.platform === "win32" ? [tool + EXE_SUFFIX, tool + ".cmd", tool] : [tool];
|
|
49430
|
+
const out = [];
|
|
49431
|
+
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
49432
|
+
if (dir === "") continue;
|
|
49433
|
+
for (const n of names) if (existsSync13(join12(dir, n))) {
|
|
49434
|
+
out.push(join12(dir, n));
|
|
49435
|
+
break;
|
|
49436
|
+
}
|
|
49437
|
+
}
|
|
49438
|
+
return out;
|
|
49439
|
+
}
|
|
49440
|
+
function hookLogTail(env) {
|
|
49441
|
+
const file2 = hookLogPath(env);
|
|
49442
|
+
if (file2 === "" || !existsSync13(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
49443
|
+
try {
|
|
49444
|
+
const fd = openSync(file2, "r");
|
|
49445
|
+
try {
|
|
49446
|
+
const size = fstatSync(fd).size;
|
|
49447
|
+
const start = Math.max(0, size - DOCTOR_LOG_TAIL_BYTES);
|
|
49448
|
+
const buf = Buffer.alloc(size - start);
|
|
49449
|
+
readSync(fd, buf, 0, buf.length, start);
|
|
49450
|
+
const lines = buf.toString("utf8").split("\n").filter((l) => l.trim() !== "");
|
|
49451
|
+
if (start > 0) lines.shift();
|
|
49452
|
+
return lines.slice(-DOCTOR_HOOK_LOG_LINES).map(maskLine);
|
|
49453
|
+
} finally {
|
|
49454
|
+
closeSync(fd);
|
|
49455
|
+
}
|
|
49456
|
+
} catch (err) {
|
|
49457
|
+
return [`hook-errors.log read: ${err instanceof Error ? err.message : String(err)}`];
|
|
49458
|
+
}
|
|
49459
|
+
}
|
|
49460
|
+
async function journalRows(ctx) {
|
|
49461
|
+
const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
49462
|
+
if (!existsSync13(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
49463
|
+
try {
|
|
49464
|
+
const db = await openDb(ctx.project, { readOnly: true });
|
|
49465
|
+
try {
|
|
49466
|
+
const rows = db.raw.prepare(`SELECT kind, tool, bytes, ok, exit_code, created_at FROM events ORDER BY seq DESC LIMIT ${DOCTOR_JOURNAL_ROWS}`).all();
|
|
49467
|
+
const cell5 = (v) => v === null || v === void 0 ? "" : String(v);
|
|
49468
|
+
return head.concat(rows.map((r) => `| ${cell5(r.kind)} | ${cell5(r.tool)} | ${cell5(r.bytes)} | ${cell5(r.ok)} | ${cell5(r.exit_code)} | ${typeof r.created_at === "number" ? new Date(r.created_at).toISOString() : cell5(r.created_at)} |`));
|
|
49469
|
+
} finally {
|
|
49470
|
+
closeDb(db);
|
|
49471
|
+
}
|
|
49472
|
+
} catch (err) {
|
|
49473
|
+
return [`journal read: ${err instanceof Error ? err.message : String(err)}`];
|
|
49474
|
+
}
|
|
49475
|
+
}
|
|
49476
|
+
function agentConfig(adapter, env, worktree) {
|
|
49477
|
+
const home = homeDirOf(env);
|
|
49478
|
+
const files = configPaths(adapter, env, worktree);
|
|
49479
|
+
if (home !== null) {
|
|
49480
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join12(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
49481
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join12(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
49482
|
+
}
|
|
49483
|
+
const out = [];
|
|
49484
|
+
const seen = /* @__PURE__ */ new Set();
|
|
49485
|
+
for (const f of files) {
|
|
49486
|
+
if (seen.has(f.path)) continue;
|
|
49487
|
+
seen.add(f.path);
|
|
49488
|
+
if (!existsSync13(f.path)) {
|
|
49489
|
+
out.push(`${f.label}: ${f.path} (absent)`);
|
|
49490
|
+
continue;
|
|
49491
|
+
}
|
|
49492
|
+
let text = "";
|
|
49493
|
+
try {
|
|
49494
|
+
text = readFileSync9(f.path, "utf8");
|
|
49495
|
+
} catch (err) {
|
|
49496
|
+
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
49497
|
+
continue;
|
|
49498
|
+
}
|
|
49499
|
+
const hit = text.split("\n").filter((l) => l.includes("context-mode") || l.includes("hook.mjs") || adapter.id === "codex" && l.includes("trust"));
|
|
49500
|
+
out.push(`${f.label}: ${f.path} (${hit.length} matching lines)`);
|
|
49501
|
+
for (const l of hit.slice(0, DOCTOR_CONFIG_LINES)) out.push(" " + maskLine(l.trimEnd()));
|
|
49502
|
+
}
|
|
49503
|
+
return out;
|
|
49504
|
+
}
|
|
49505
|
+
function failing(rows) {
|
|
49506
|
+
return rows.filter((r) => r.status === "FAIL");
|
|
49507
|
+
}
|
|
49508
|
+
function issueTitle(agent, rows) {
|
|
49509
|
+
return `ctx_doctor ${agent}: ${failing(rows).map((r) => `${r.id} ${r.label}`).join(", ")} FAIL`;
|
|
49510
|
+
}
|
|
49511
|
+
function summaryOf(agent, rows) {
|
|
49512
|
+
const f = failing(rows)[0];
|
|
49513
|
+
return f === void 0 ? `ctx_doctor ${agent}` : `${f.id} ${f.label} FAIL on ${agent}: ${f.detail}`;
|
|
49514
|
+
}
|
|
49515
|
+
async function buildIssueBody(i) {
|
|
49516
|
+
const tilde = tildeOf(i.env);
|
|
49517
|
+
const agent = i.adapter.id;
|
|
49518
|
+
const install = NATIVE_INSTALL[agent] ?? [];
|
|
49519
|
+
const failRows = i.rows.filter((r) => r.status !== "PASS");
|
|
49520
|
+
const envNames = DOCTOR_ENV_NAMES.map((n) => i.env[n] === void 0 ? `${n} (unset)` : `${n}=${i.env[n]}`);
|
|
49521
|
+
const pathTools = DOCTOR_PATH_TOOLS.map((t) => `PATH holds ${t}: ${onPath(i.env, t).join(", ") || "(absent)"}`);
|
|
49522
|
+
const sections = {
|
|
49523
|
+
"Summary": [summaryOf(agent, i.rows)],
|
|
49524
|
+
"ctx-report": [i.table],
|
|
49525
|
+
"What happened": [
|
|
49526
|
+
"Rows that need a look:",
|
|
49527
|
+
...failRows.map((r) => `- ${r.id} ${r.label} ${r.status}: ${r.detail}${r.fixCommand ? ` (Fix: ${r.fixCommand})` : ""}`),
|
|
49528
|
+
"Error code and text: <the agent fills this in: the exact error the user saw>"
|
|
49529
|
+
],
|
|
49530
|
+
"Hook errors": ["hook-errors.log, last " + DOCTOR_HOOK_LOG_LINES + " lines (UTC):", "```", ...hookLogTail(i.env), "```"],
|
|
49531
|
+
"Journal rows": ["events, newest first, last " + DOCTOR_JOURNAL_ROWS + " (bodies stay local):", ...await journalRows(i.ctx)],
|
|
49532
|
+
"Agent config": agentConfig(i.adapter, i.env, i.ctx.project.worktree),
|
|
49533
|
+
"Expected": ["Expected: <the agent fills this in: what should happen, with the byte count>"],
|
|
49534
|
+
"Steps": [
|
|
49535
|
+
"Reproduced: <yes (2 of 2) or 1 of 2>",
|
|
49536
|
+
"Prompt or command: <the agent fills this in: the exact prompt or command>",
|
|
49537
|
+
"Actual: <the agent fills this in: what context-mode did, with the byte count>",
|
|
49538
|
+
"Repro script (fresh HOME, native install for " + agent + "):",
|
|
49539
|
+
"```sh",
|
|
49540
|
+
'export HOME="$(mktemp -d)"',
|
|
49541
|
+
'cd "$HOME"',
|
|
49542
|
+
...install,
|
|
49543
|
+
"<the command or prompt above>",
|
|
49544
|
+
"```"
|
|
49545
|
+
],
|
|
49546
|
+
"Environment": [
|
|
49547
|
+
i.envLine,
|
|
49548
|
+
`context-mode bundle: ${i.bundleDir}`,
|
|
49549
|
+
`Install route: ${install.join(" && ")}`,
|
|
49550
|
+
`git: ${gitVersion(i.env)}`,
|
|
49551
|
+
...pathTools,
|
|
49552
|
+
...envNames,
|
|
49553
|
+
`Project: ${i.ctx.project.worktree} (key ${i.ctx.project.projectKey})`,
|
|
49554
|
+
"Filed by: <your agent name, version, model id>"
|
|
49555
|
+
]
|
|
49556
|
+
};
|
|
49557
|
+
const out = [];
|
|
49558
|
+
for (const h of ISSUE_FORM_HEADINGS) out.push(`### ${h}`, "", ...sections[h] ?? [], "");
|
|
49559
|
+
return tilde(out.join("\n"));
|
|
49560
|
+
}
|
|
49561
|
+
async function writeIssueReport(i) {
|
|
49562
|
+
const tilde = tildeOf(i.env);
|
|
49563
|
+
const body = await buildIssueBody(i);
|
|
49564
|
+
const dir = join12(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
49565
|
+
mkdirSync5(dir, { recursive: true });
|
|
49566
|
+
const file2 = join12(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
49567
|
+
writeFileSync3(file2, body);
|
|
49568
|
+
const shown2 = tilde(file2);
|
|
49569
|
+
const title = issueTitle(i.adapter.id, i.rows);
|
|
49570
|
+
const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
|
|
49571
|
+
return [DOCTOR_REPORT_LINE + shown2, DOCTOR_GH_LINE + gh[0], gh[1], gh[2], DOCTOR_URL_LINE + formUrl(title, summaryOf(i.adapter.id, i.rows))];
|
|
49572
|
+
}
|
|
49573
|
+
function formUrl(title, summary) {
|
|
49574
|
+
const base = `${ISSUE_FORM_URL}&title=${encodeURIComponent(title)}`;
|
|
49575
|
+
const full = `${base}&summary=${encodeURIComponent(summary)}`;
|
|
49576
|
+
return full.length < ISSUE_URL_MAX ? full : base;
|
|
49577
|
+
}
|
|
49578
|
+
|
|
49113
49579
|
// src/core/index/text.ts
|
|
49114
|
-
function storeText(db, project, sessionId, sourceKind,
|
|
49580
|
+
function storeText(db, project, sessionId, sourceKind, label2, text, kind, chunks = chunkText(text, kind)) {
|
|
49115
49581
|
const sourceId = ftsInsert(db, {
|
|
49116
49582
|
projectKey: project.projectKey,
|
|
49117
49583
|
sessionId,
|
|
49118
49584
|
worktree: project.worktree,
|
|
49119
49585
|
agent: project.agent,
|
|
49120
49586
|
kind: sourceKind,
|
|
49121
|
-
label,
|
|
49587
|
+
label: label2,
|
|
49122
49588
|
bytes: Buffer.byteLength(text, "utf8"),
|
|
49123
49589
|
chunkCount: chunks.length,
|
|
49124
49590
|
createdAt: Date.now()
|
|
@@ -49143,7 +49609,7 @@ async function guard(id, run) {
|
|
|
49143
49609
|
}
|
|
49144
49610
|
}
|
|
49145
49611
|
async function codexDb(ctx, adapter) {
|
|
49146
|
-
if (adapter.id !== "codex" || !
|
|
49612
|
+
if (adapter.id !== "codex" || !existsSync14(ctx.project.dbPath)) return null;
|
|
49147
49613
|
try {
|
|
49148
49614
|
return await openDb(ctx.project, { readOnly: true });
|
|
49149
49615
|
} catch {
|
|
@@ -49173,11 +49639,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
49173
49639
|
}
|
|
49174
49640
|
}
|
|
49175
49641
|
function ownServerId(configDir, projectKey) {
|
|
49176
|
-
const dir =
|
|
49177
|
-
if (!
|
|
49642
|
+
const dir = join13(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
49643
|
+
if (!existsSync14(dir)) return "";
|
|
49178
49644
|
for (const name of readdirSync6(dir)) {
|
|
49179
49645
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
49180
|
-
if (
|
|
49646
|
+
if (readFileSync10(join13(dir, name), "utf8").trim() === String(process.pid)) return basename4(name, OWNER_PID_EXT);
|
|
49181
49647
|
}
|
|
49182
49648
|
return "";
|
|
49183
49649
|
}
|
|
@@ -49187,7 +49653,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
49187
49653
|
const project = ctx.project;
|
|
49188
49654
|
let integrityFailed = false;
|
|
49189
49655
|
const checks = {
|
|
49190
|
-
D1: () => checkVersion({ bundleSha: BUNDLE_SHA, env: buildChildEnv(env), cwd: project.worktree, signal: ctx.signal }),
|
|
49656
|
+
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
49657
|
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
49192
49658
|
D3: () => checkHostConfig(adapter, env, project.worktree),
|
|
49193
49659
|
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)) }),
|
|
@@ -49222,23 +49688,38 @@ function reportEnv(env) {
|
|
|
49222
49688
|
}
|
|
49223
49689
|
return out;
|
|
49224
49690
|
}
|
|
49225
|
-
async function
|
|
49691
|
+
async function doctorReply(ctx, host) {
|
|
49226
49692
|
const adapter = getAdapter(ctx.project.agent);
|
|
49227
|
-
const host = { env: process.env, bundleDir: dirname6(process.argv[1]), piCwd: void 0 };
|
|
49228
49693
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
49229
|
-
const
|
|
49230
|
-
const
|
|
49231
|
-
const
|
|
49232
|
-
const
|
|
49233
|
-
|
|
49694
|
+
const failed2 = rows.some((r) => r.status === "FAIL");
|
|
49695
|
+
const command = `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
49696
|
+
const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
|
|
49697
|
+
const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
|
|
49698
|
+
const table3 = buildReport(input);
|
|
49699
|
+
let notes = [];
|
|
49700
|
+
if (failed2) {
|
|
49701
|
+
try {
|
|
49702
|
+
notes = await writeIssueReport({ ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
|
|
49703
|
+
} catch (err) {
|
|
49704
|
+
notes = [`Report file: ${lineOf(err)}`];
|
|
49705
|
+
}
|
|
49706
|
+
}
|
|
49707
|
+
const look = rows.find((r) => r.status === "FAIL") ?? rows.find((r) => r.status !== "PASS");
|
|
49708
|
+
const docs = look === void 0 ? [] : [DOCTOR_DOCS_LABEL + DOCTOR_DOCS_LINK(look.id)];
|
|
49709
|
+
const whole2 = [envLine2, table3, ...docs, ...notes].join("\n");
|
|
49710
|
+
const bytes5 = Buffer.byteLength(whole2, "utf8");
|
|
49711
|
+
if (bytes5 <= REPORT_CAP) return { text: whole2, isError: false, sandboxBytes: bytes5 };
|
|
49234
49712
|
const db = await openDb(ctx.project);
|
|
49235
49713
|
try {
|
|
49236
|
-
indexText(db, ctx.project, ctx.sessionId, REPORT_SOURCE_LABEL,
|
|
49714
|
+
indexText(db, ctx.project, ctx.sessionId, REPORT_SOURCE_LABEL, whole2, "text");
|
|
49237
49715
|
} finally {
|
|
49238
49716
|
closeDb(db);
|
|
49239
49717
|
}
|
|
49240
|
-
const text = buildReportHead(input);
|
|
49241
|
-
return { text, isError: false, sandboxBytes:
|
|
49718
|
+
const text = [envLine2, buildReportHead(input), ...docs, ...notes].join("\n");
|
|
49719
|
+
return { text, isError: false, sandboxBytes: bytes5 };
|
|
49720
|
+
}
|
|
49721
|
+
async function handler2(_input, ctx) {
|
|
49722
|
+
return doctorReply(ctx, { env: process.env, bundleDir: dirname6(process.argv[1]), piCwd: void 0 });
|
|
49242
49723
|
}
|
|
49243
49724
|
var ctxDoctor = Object.freeze({
|
|
49244
49725
|
name: "ctx_doctor",
|
|
@@ -49250,9 +49731,9 @@ var ctxDoctor = Object.freeze({
|
|
|
49250
49731
|
});
|
|
49251
49732
|
|
|
49252
49733
|
// src/core/tools/execute.ts
|
|
49253
|
-
import { existsSync as
|
|
49734
|
+
import { existsSync as existsSync15, mkdtempSync, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
49254
49735
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
49255
|
-
import { dirname as dirname7, join as
|
|
49736
|
+
import { dirname as dirname7, join as join14, parse as parse5, resolve as resolve4 } from "node:path";
|
|
49256
49737
|
|
|
49257
49738
|
// src/core/index/select.ts
|
|
49258
49739
|
var READ_CHUNKS = "SELECT ord, body FROM chunks WHERE source_id = ?";
|
|
@@ -49266,7 +49747,7 @@ function selectChunks(db, sourceId, intent, budget) {
|
|
|
49266
49747
|
const row5 = db.raw.prepare(READ_LABEL).get(sourceId);
|
|
49267
49748
|
return select(chunks, intent, budget, row5?.label);
|
|
49268
49749
|
}
|
|
49269
|
-
function select(chunks, intent, budget,
|
|
49750
|
+
function select(chunks, intent, budget, label2, rankQuery) {
|
|
49270
49751
|
if (chunks.length === 0) return { text: "", more: null };
|
|
49271
49752
|
const texts = chunks.map((c) => c.text);
|
|
49272
49753
|
const scores = rankQuery === void 0 ? rankTexts(texts, intent) : rankTexts(texts, rankQuery, "any");
|
|
@@ -49285,10 +49766,10 @@ function select(chunks, intent, budget, label, rankQuery) {
|
|
|
49285
49766
|
}
|
|
49286
49767
|
picked.sort((a, b) => a.ord - b.ord);
|
|
49287
49768
|
const text = picked.map((c) => c.text).join(SEP);
|
|
49288
|
-
return { text, more: skipped ? moreLine(intent,
|
|
49769
|
+
return { text, more: skipped ? moreLine(intent, label2) : null };
|
|
49289
49770
|
}
|
|
49290
|
-
function moreLine(intent,
|
|
49291
|
-
const source =
|
|
49771
|
+
function moreLine(intent, label2) {
|
|
49772
|
+
const source = label2 === void 0 ? "" : ", source:" + JSON.stringify(label2);
|
|
49292
49773
|
const query = Buffer.byteLength(intent, "utf8") > ECHO_MAX_BYTES ? "..." : JSON.stringify(intent);
|
|
49293
49774
|
return "ctx_search({queries:[" + query + "]" + source + "})";
|
|
49294
49775
|
}
|
|
@@ -49375,7 +49856,7 @@ function schemaLine(issue4) {
|
|
|
49375
49856
|
}
|
|
49376
49857
|
function fileError(given, abs, root) {
|
|
49377
49858
|
let dir = abs;
|
|
49378
|
-
while (!
|
|
49859
|
+
while (!existsSync15(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
|
|
49379
49860
|
if (isInside(root, dir)) return null;
|
|
49380
49861
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
49381
49862
|
}
|
|
@@ -49401,8 +49882,8 @@ function sourceLabel(code) {
|
|
|
49401
49882
|
const first = nl < 0 ? code : code.slice(0, nl);
|
|
49402
49883
|
return Array.from(TOOL2 + ":" + first).slice(0, SOURCE_LABEL_MAX_CHARS).join("");
|
|
49403
49884
|
}
|
|
49404
|
-
function moreReserve(intent,
|
|
49405
|
-
return Buffer.byteLength(moreLine(intent,
|
|
49885
|
+
function moreReserve(intent, label2) {
|
|
49886
|
+
return Buffer.byteLength(moreLine(intent, label2), "utf8");
|
|
49406
49887
|
}
|
|
49407
49888
|
function spawnFailed(argv0, cwd) {
|
|
49408
49889
|
return new CtxError("SPAWN_FAILED", { detail: argv0 + " gave no exit code in " + cwd }).toLine();
|
|
@@ -49419,12 +49900,12 @@ async function finish(input, ctx, r, exitCode, journal) {
|
|
|
49419
49900
|
if (intent === "" && fits) {
|
|
49420
49901
|
return { text: direct, isError, sandboxBytes: fullBytes, journal };
|
|
49421
49902
|
}
|
|
49422
|
-
const
|
|
49423
|
-
const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent,
|
|
49903
|
+
const label2 = sourceLabel(input.code);
|
|
49904
|
+
const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent, label2);
|
|
49424
49905
|
const db = await openDb(ctx.project);
|
|
49425
49906
|
let picked;
|
|
49426
49907
|
try {
|
|
49427
|
-
const { sourceId } = indexText(db, ctx.project, ctx.sessionId,
|
|
49908
|
+
const { sourceId } = indexText(db, ctx.project, ctx.sessionId, label2, combined, "text");
|
|
49428
49909
|
picked = selectChunks(db, sourceId, intent, budget);
|
|
49429
49910
|
} finally {
|
|
49430
49911
|
closeDb(db);
|
|
@@ -49456,9 +49937,9 @@ async function handler3(raw, ctx) {
|
|
|
49456
49937
|
if (takesDashC(input.language, runtime)) {
|
|
49457
49938
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
49458
49939
|
} else {
|
|
49459
|
-
tmpDir = mkdtempSync(
|
|
49460
|
-
const file2 =
|
|
49461
|
-
|
|
49940
|
+
tmpDir = mkdtempSync(join14(tmpdir2(), TMP_PREFIX));
|
|
49941
|
+
const file2 = join14(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
49942
|
+
writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
|
|
49462
49943
|
argv = scriptArgv(input.language, runtime, file2);
|
|
49463
49944
|
}
|
|
49464
49945
|
if (input.background === true) {
|
|
@@ -49492,21 +49973,21 @@ var ctxExecute = {
|
|
|
49492
49973
|
};
|
|
49493
49974
|
|
|
49494
49975
|
// src/core/tools/index.ts
|
|
49495
|
-
import { existsSync as
|
|
49496
|
-
import { dirname as dirname8, extname, join as
|
|
49976
|
+
import { existsSync as existsSync16, readFileSync as readFileSync12, statSync as statSync6 } from "node:fs";
|
|
49977
|
+
import { dirname as dirname8, extname, join as join16, relative as relative2, resolve as resolve5 } from "node:path";
|
|
49497
49978
|
|
|
49498
49979
|
// src/core/index/walk.ts
|
|
49499
|
-
import { readdirSync as readdirSync7, readFileSync as
|
|
49500
|
-
import { join as
|
|
49980
|
+
import { readdirSync as readdirSync7, readFileSync as readFileSync11, realpathSync as realpathSync9, statSync as statSync5 } from "node:fs";
|
|
49981
|
+
import { join as join15 } from "node:path";
|
|
49501
49982
|
var GITIGNORE = ".gitignore";
|
|
49502
49983
|
var GIT_DIR = ".git";
|
|
49503
49984
|
function walkDir(root, containmentRoot) {
|
|
49504
|
-
const real2 =
|
|
49985
|
+
const real2 = realpathSync9(root);
|
|
49505
49986
|
if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
|
|
49506
49987
|
const found = [];
|
|
49507
49988
|
visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
|
|
49508
49989
|
found.sort(compareFound);
|
|
49509
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
49990
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join15(...f.dir, f.name) }));
|
|
49510
49991
|
}
|
|
49511
49992
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
49512
49993
|
let entries;
|
|
@@ -49515,17 +49996,17 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
49515
49996
|
} catch {
|
|
49516
49997
|
return;
|
|
49517
49998
|
}
|
|
49518
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
49999
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join15(abs, GITIGNORE), rel)) : parent;
|
|
49519
50000
|
for (const e of entries) {
|
|
49520
50001
|
if (e.name === GIT_DIR) continue;
|
|
49521
|
-
const path7 =
|
|
50002
|
+
const path7 = join15(abs, e.name);
|
|
49522
50003
|
let isDir = e.isDirectory();
|
|
49523
50004
|
let isFile = e.isFile();
|
|
49524
50005
|
let target = path7;
|
|
49525
50006
|
if (e.isSymbolicLink()) {
|
|
49526
50007
|
let resolved;
|
|
49527
50008
|
try {
|
|
49528
|
-
resolved =
|
|
50009
|
+
resolved = realpathSync9(path7);
|
|
49529
50010
|
} catch {
|
|
49530
50011
|
continue;
|
|
49531
50012
|
}
|
|
@@ -49540,7 +50021,7 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
49540
50021
|
if (isFile) {
|
|
49541
50022
|
found.push({ dir: rel, name: e.name, absPath: path7 });
|
|
49542
50023
|
} else if (isDir) {
|
|
49543
|
-
const key = e.isSymbolicLink() ? target :
|
|
50024
|
+
const key = e.isSymbolicLink() ? target : realpathSync9(path7);
|
|
49544
50025
|
if (seen.has(key)) continue;
|
|
49545
50026
|
seen.add(key);
|
|
49546
50027
|
visit(path7, segs, rules, contain, seen, found);
|
|
@@ -49558,7 +50039,7 @@ function compareFound(a, b) {
|
|
|
49558
50039
|
function readRules(file2, base) {
|
|
49559
50040
|
let body;
|
|
49560
50041
|
try {
|
|
49561
|
-
body =
|
|
50042
|
+
body = readFileSync11(file2, "utf8");
|
|
49562
50043
|
} catch {
|
|
49563
50044
|
return [];
|
|
49564
50045
|
}
|
|
@@ -49868,14 +50349,14 @@ function replaceCodePointXML(codePoint) {
|
|
|
49868
50349
|
|
|
49869
50350
|
// node_modules/entities/dist/internal/decode-shared.js
|
|
49870
50351
|
var BASE91_INVERSE = /* @__PURE__ */ (() => {
|
|
49871
|
-
const
|
|
50352
|
+
const table3 = new Uint8Array(127);
|
|
49872
50353
|
let code = 0;
|
|
49873
50354
|
for (let char = 33; char <= 126; char++) {
|
|
49874
50355
|
if (char !== 34 && char !== 36 && char !== 92) {
|
|
49875
|
-
|
|
50356
|
+
table3[char] = code++;
|
|
49876
50357
|
}
|
|
49877
50358
|
}
|
|
49878
|
-
return
|
|
50359
|
+
return table3;
|
|
49879
50360
|
})();
|
|
49880
50361
|
function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCount, dictSize) {
|
|
49881
50362
|
const base = 91;
|
|
@@ -49893,10 +50374,10 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
49893
50374
|
single.fill(-1, dictSize + dict2AtomCount, slotCount);
|
|
49894
50375
|
const start = new Int32Array(slotCount);
|
|
49895
50376
|
const length = new Int32Array(slotCount);
|
|
49896
|
-
function decodeDelta(
|
|
50377
|
+
function decodeDelta(count2, off) {
|
|
49897
50378
|
let previous = 0;
|
|
49898
50379
|
let slot = off;
|
|
49899
|
-
const end = off +
|
|
50380
|
+
const end = off + count2;
|
|
49900
50381
|
while (slot < end) {
|
|
49901
50382
|
const code = BASE91_INVERSE[input.charCodeAt(pos++)];
|
|
49902
50383
|
if (code < 89) {
|
|
@@ -49919,8 +50400,8 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
49919
50400
|
const references = new Int32Array(ngramCount * 2);
|
|
49920
50401
|
let poolSize = 0;
|
|
49921
50402
|
let ngramIndex = 0;
|
|
49922
|
-
function readNgramReferences(
|
|
49923
|
-
for (let index = 0; index <
|
|
50403
|
+
function readNgramReferences(count2, startSlot) {
|
|
50404
|
+
for (let index = 0; index < count2; index++) {
|
|
49924
50405
|
const slot = startSlot + index;
|
|
49925
50406
|
const a = readSlotCode();
|
|
49926
50407
|
const b = readSlotCode();
|
|
@@ -53628,8 +54109,8 @@ var EXT_KIND = Object.freeze({ ".md": "md", ".html": "html", ".htm": "html" });
|
|
|
53628
54109
|
var TYPE_KIND = Object.freeze({ "text/html": "html", "text/markdown": "md" });
|
|
53629
54110
|
var DEFAULT_CONTENT_LABEL = "content";
|
|
53630
54111
|
var utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
53631
|
-
function userLabel(
|
|
53632
|
-
return
|
|
54112
|
+
function userLabel(label2) {
|
|
54113
|
+
return label2 === DECISION_SOURCE ? DECISION_USER_LABEL : label2;
|
|
53633
54114
|
}
|
|
53634
54115
|
function kindOfPath(p) {
|
|
53635
54116
|
return EXT_KIND[extname(p).toLowerCase()] ?? "text";
|
|
@@ -53641,14 +54122,14 @@ function kindOfType(contentType) {
|
|
|
53641
54122
|
}
|
|
53642
54123
|
function readUtf8(absPath) {
|
|
53643
54124
|
try {
|
|
53644
|
-
return utf8.decode(
|
|
54125
|
+
return utf8.decode(readFileSync12(absPath));
|
|
53645
54126
|
} catch {
|
|
53646
54127
|
return void 0;
|
|
53647
54128
|
}
|
|
53648
54129
|
}
|
|
53649
54130
|
function missingOrOutside(given, abs, root) {
|
|
53650
54131
|
let dir = abs;
|
|
53651
|
-
while (!
|
|
54132
|
+
while (!existsSync16(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
|
|
53652
54133
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
53653
54134
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
53654
54135
|
}
|
|
@@ -53659,7 +54140,7 @@ function pathItems(input, project) {
|
|
|
53659
54140
|
if (statSync6(abs).isDirectory()) {
|
|
53660
54141
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
53661
54142
|
sourceKind: "path",
|
|
53662
|
-
label: pathLabel(
|
|
54143
|
+
label: pathLabel(join16(base, f.relPath)),
|
|
53663
54144
|
kind: kindOfPath(f.relPath),
|
|
53664
54145
|
read: () => readUtf8(f.absPath)
|
|
53665
54146
|
}));
|
|
@@ -53669,9 +54150,9 @@ function pathItems(input, project) {
|
|
|
53669
54150
|
async function itemsOf(input, ctx) {
|
|
53670
54151
|
if (input.content !== void 0) {
|
|
53671
54152
|
const text2 = input.content;
|
|
53672
|
-
const
|
|
54153
|
+
const label3 = input.source ?? DEFAULT_CONTENT_LABEL;
|
|
53673
54154
|
const kind = hasMdStructure(text2) ? "md" : "text";
|
|
53674
|
-
return { items: [{ sourceKind: "content", label:
|
|
54155
|
+
return { items: [{ sourceKind: "content", label: label3, kind, read: () => text2 }], from: label3 };
|
|
53675
54156
|
}
|
|
53676
54157
|
if (input.path !== void 0) {
|
|
53677
54158
|
const items = pathItems({ ...input, path: input.path }, ctx.project);
|
|
@@ -53679,8 +54160,8 @@ async function itemsOf(input, ctx) {
|
|
|
53679
54160
|
}
|
|
53680
54161
|
const res = await safeFetch(input.url ?? "", AbortSignal.any([ctx.signal, AbortSignal.timeout(EXEC_TIMEOUT_MS)]));
|
|
53681
54162
|
const text = res.body.toString("utf8");
|
|
53682
|
-
const
|
|
53683
|
-
return { items: [{ sourceKind: "url", label, kind: kindOfType(res.contentType), read: () => text, base:
|
|
54163
|
+
const label2 = res.finalUrl;
|
|
54164
|
+
return { items: [{ sourceKind: "url", label: label2, kind: kindOfType(res.contentType), read: () => text, base: label2 }], from: label2 };
|
|
53684
54165
|
}
|
|
53685
54166
|
async function handler4(input, ctx) {
|
|
53686
54167
|
const given = INPUT_FIELDS.filter((f) => input[f] !== void 0);
|
|
@@ -53692,14 +54173,14 @@ async function handler4(input, ctx) {
|
|
|
53692
54173
|
const db = await openDb(ctx.project);
|
|
53693
54174
|
let sources = 0;
|
|
53694
54175
|
let chunks = 0;
|
|
53695
|
-
let
|
|
54176
|
+
let bytes5 = 0;
|
|
53696
54177
|
let lastId = 0;
|
|
53697
54178
|
const notes = [];
|
|
53698
54179
|
try {
|
|
53699
54180
|
for (const it of items) {
|
|
53700
54181
|
const text = it.read();
|
|
53701
54182
|
if (text === void 0) continue;
|
|
53702
|
-
|
|
54183
|
+
bytes5 += Buffer.byteLength(text, "utf8");
|
|
53703
54184
|
if (it.kind === "html") {
|
|
53704
54185
|
let readable;
|
|
53705
54186
|
try {
|
|
@@ -53736,7 +54217,7 @@ async function handler4(input, ctx) {
|
|
|
53736
54217
|
return {
|
|
53737
54218
|
text: capBytes(line, OUTPUT_CAP).text,
|
|
53738
54219
|
isError: false,
|
|
53739
|
-
sandboxBytes:
|
|
54220
|
+
sandboxBytes: bytes5,
|
|
53740
54221
|
journal: { kind: "index", key: from, path: from, exit_code: null }
|
|
53741
54222
|
};
|
|
53742
54223
|
} catch (err) {
|
|
@@ -53776,8 +54257,8 @@ function purgeScope(db, scope, input) {
|
|
|
53776
54257
|
const raw = db.raw;
|
|
53777
54258
|
if (scope === "session") return changes(raw, "DELETE FROM events WHERE session_id = ?", input.session);
|
|
53778
54259
|
if (scope === "source") {
|
|
53779
|
-
const
|
|
53780
|
-
return deleteChunkRows(raw, { label }) + changes(raw, "DELETE FROM sources WHERE label = ?",
|
|
54260
|
+
const label2 = storedLabel(db, input.source);
|
|
54261
|
+
return deleteChunkRows(raw, { label: label2 }) + changes(raw, "DELETE FROM sources WHERE label = ?", label2);
|
|
53781
54262
|
}
|
|
53782
54263
|
const chunks = deleteChunkRows(raw, "all");
|
|
53783
54264
|
return changes(raw, "DELETE FROM events") + chunks + changes(raw, "DELETE FROM sources");
|
|
@@ -53814,14 +54295,14 @@ var ctxPurge = Object.freeze({
|
|
|
53814
54295
|
});
|
|
53815
54296
|
|
|
53816
54297
|
// src/core/compaction/candidates.ts
|
|
53817
|
-
function
|
|
54298
|
+
function firstLine3(body) {
|
|
53818
54299
|
const nl = body.indexOf("\n");
|
|
53819
54300
|
return (nl < 0 ? body : body.slice(0, nl)).replaceAll("\r", " ");
|
|
53820
54301
|
}
|
|
53821
54302
|
function make(section, row5, text, repeatCount, query) {
|
|
53822
|
-
const
|
|
53823
|
-
if (
|
|
53824
|
-
return { section, seq: row5.seq, turn: row5.turn, text, bytes:
|
|
54303
|
+
const bytes5 = Buffer.byteLength(text, "utf8");
|
|
54304
|
+
if (bytes5 < 1) throw new Error("compaction: empty candidate line (DECISIONS-r9 M9).");
|
|
54305
|
+
return { section, seq: row5.seq, turn: row5.turn, text, bytes: bytes5, repeatCount, pinned: section === "last_request", query };
|
|
53825
54306
|
}
|
|
53826
54307
|
function capSection(list3) {
|
|
53827
54308
|
return list3.length > MAX_CANDIDATES ? list3.slice(list3.length - MAX_CANDIDATES) : list3;
|
|
@@ -53834,8 +54315,8 @@ function buildCandidates(rows, sessionId) {
|
|
|
53834
54315
|
const own4 = rows.filter((r) => r.session_id === sessionId).sort((a, b) => a.seq - b.seq);
|
|
53835
54316
|
const prompts = own4.filter((r) => r.kind === "prompt");
|
|
53836
54317
|
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 + ": " +
|
|
54318
|
+
const lastRequest = last2 === void 0 ? null : make("last_request", last2, "now: " + firstLine3(last2.body), 1, null);
|
|
54319
|
+
const earlierRequests = prompts.slice(0, prompts.length - 1).map((r) => make("earlier_requests", r, "asked #" + r.seq + ": " + firstLine3(r.body), 1, null));
|
|
53839
54320
|
const failures = /* @__PURE__ */ new Map();
|
|
53840
54321
|
const lastOk = /* @__PURE__ */ new Map();
|
|
53841
54322
|
for (const r of own4) {
|
|
@@ -53870,7 +54351,7 @@ function buildCandidates(rows, sessionId) {
|
|
|
53870
54351
|
decided.set(key, { row: r, count: (decided.get(key)?.count ?? 0) + 1 });
|
|
53871
54352
|
}
|
|
53872
54353
|
const decisions = [];
|
|
53873
|
-
for (const [key, d] of decided) decisions.push(make("decisions", d.row, "decided #" + d.row.seq + ": " +
|
|
54354
|
+
for (const [key, d] of decided) decisions.push(make("decisions", d.row, "decided #" + d.row.seq + ": " + firstLine3(d.row.body), d.count, key));
|
|
53874
54355
|
decisions.sort((a, b) => a.seq - b.seq);
|
|
53875
54356
|
const indexedSources = own4.filter((r) => r.kind === "index").map((r) => make("indexed_sources", r, "indexed " + (r.key ?? ""), 1, r.key));
|
|
53876
54357
|
const set3 = {
|
|
@@ -54124,14 +54605,83 @@ var ctxResume = Object.freeze({
|
|
|
54124
54605
|
var ctxStatsSchema = external_exports.object({}, {
|
|
54125
54606
|
error: (issue4) => issue4.code === "unrecognized_keys" ? STATS_UNKNOWN_FIELD_LINE : void 0
|
|
54126
54607
|
}).strict();
|
|
54127
|
-
var
|
|
54608
|
+
var CALLS = "tool IS NOT NULL AND kind <> 'cost' AND tool <> 'ctx_stats'";
|
|
54609
|
+
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`;
|
|
54610
|
+
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`;
|
|
54611
|
+
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";
|
|
54612
|
+
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}`;
|
|
54613
|
+
var SPAN = "SELECT COALESCE(MAX(created_at) - MIN(created_at), 0) AS span FROM events WHERE session_id = ? AND kind <> 'cost'";
|
|
54614
|
+
var SOURCES = "SELECT COUNT(*) AS n, COALESCE(SUM(chunk_count), 0) AS chunks, COALESCE(SUM(bytes_total), 0) AS bytes FROM sources";
|
|
54615
|
+
var HOST = "tool NOT LIKE 'ctx\\_%' ESCAPE '\\'";
|
|
54616
|
+
var REPLACED = `SELECT COUNT(*) AS n FROM events WHERE ${CALLS} AND ${HOST} AND returned_bytes < sandbox_bytes`;
|
|
54617
|
+
var RUNS = "FROM sources WHERE substr(label, 1, ?) = ?";
|
|
54618
|
+
var REDIRECTED = `SELECT COUNT(*) AS n, COALESCE(MAX(created_ts), 0) AS last ${RUNS}`;
|
|
54619
|
+
var LAST = `SELECT COALESCE(MAX(created_at), 0) AS last FROM events WHERE ${CALLS}`;
|
|
54620
|
+
var WEEK = `SELECT created_at / ${MS_PER_DAY} AS day, tool, COUNT(*) AS calls, COALESCE(SUM(sandbox_bytes), 0) AS produced, COALESCE(SUM(returned_bytes), 0) AS returned FROM events WHERE ${CALLS} AND created_at >= ? GROUP BY day, tool`;
|
|
54621
|
+
var WEEK_RUNS = `SELECT created_ts / ${MS_PER_DAY} AS day, COUNT(*) AS calls, COALESCE(SUM(MAX(0, bytes_total - ${OUTPUT_CAP})), 0) AS saved ${RUNS} AND created_ts >= ? GROUP BY day`;
|
|
54622
|
+
var TOP = `SELECT tool, 1 AS calls, sandbox_bytes AS produced, returned_bytes AS returned FROM events WHERE ${CALLS} AND sandbox_bytes > 0 ORDER BY sandbox_bytes DESC, seq ASC LIMIT ${STATS_TOP_OUTPUTS}`;
|
|
54623
|
+
function wayOf(tool) {
|
|
54624
|
+
if (STATS_INDEX_TOOLS.includes(tool)) return "index";
|
|
54625
|
+
return tool.startsWith("ctx_") ? "sandbox" : "replace";
|
|
54626
|
+
}
|
|
54627
|
+
function readWeek(raw, lastMs) {
|
|
54628
|
+
const last2 = Math.floor(lastMs / MS_PER_DAY);
|
|
54629
|
+
const first = last2 - STATS_DAYS + 1;
|
|
54630
|
+
const days = Array.from({ length: STATS_DAYS }, (_, i) => ({
|
|
54631
|
+
day: first + i,
|
|
54632
|
+
calls: 0,
|
|
54633
|
+
ways: { sandbox: 0, index: 0, redirect: 0, replace: 0 }
|
|
54634
|
+
}));
|
|
54635
|
+
const net = /* @__PURE__ */ new Map();
|
|
54636
|
+
for (const r of raw.prepare(WEEK).all(first * MS_PER_DAY)) {
|
|
54637
|
+
const d = days[Number(r.day) - first];
|
|
54638
|
+
if (d === void 0) continue;
|
|
54639
|
+
d.calls += Number(r.calls);
|
|
54640
|
+
const key = `${d.day}:${wayOf(String(r.tool))}`;
|
|
54641
|
+
net.set(key, (net.get(key) ?? 0) + Number(r.produced) - Number(r.returned));
|
|
54642
|
+
}
|
|
54643
|
+
for (const d of days) for (const [way] of STATS_WAYS) d.ways[way] = Math.max(0, net.get(`${d.day}:${way}`) ?? 0);
|
|
54644
|
+
for (const r of raw.prepare(WEEK_RUNS).all(RUN_LABEL_PREFIX.length, RUN_LABEL_PREFIX, first * MS_PER_DAY)) {
|
|
54645
|
+
const d = days[Number(r.day) - first];
|
|
54646
|
+
if (d === void 0) continue;
|
|
54647
|
+
d.calls += Number(r.calls);
|
|
54648
|
+
d.ways.redirect += Number(r.saved);
|
|
54649
|
+
}
|
|
54650
|
+
return days;
|
|
54651
|
+
}
|
|
54128
54652
|
var EMPTY3 = Object.freeze({ calls: 0, produced: 0, returned: 0, saved: 0 });
|
|
54129
|
-
function
|
|
54130
|
-
|
|
54131
|
-
|
|
54132
|
-
|
|
54133
|
-
|
|
54134
|
-
|
|
54653
|
+
function totals(r) {
|
|
54654
|
+
const produced = Number(r.produced);
|
|
54655
|
+
const returned = Number(r.returned);
|
|
54656
|
+
return { calls: Number(r.calls), produced, returned, saved: Math.max(0, produced - returned) };
|
|
54657
|
+
}
|
|
54658
|
+
function readFacts(raw, sessionId) {
|
|
54659
|
+
const groups = raw.prepare(GROUPS).all().map((r) => ({ session: String(r.session_id), agent: String(r.agent), ...totals(r) }));
|
|
54660
|
+
const tools = raw.prepare(TOOLS).all().map((r) => ({ name: String(r.tool), ...totals(r) }));
|
|
54661
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
54662
|
+
for (const r of raw.prepare(KINDS).all(sessionId)) kinds.set(String(r.kind), { session: Number(r.s), project: Number(r.p) });
|
|
54663
|
+
const meta3 = raw.prepare(META).get();
|
|
54664
|
+
const span2 = Number(raw.prepare(SPAN).get(sessionId).span);
|
|
54665
|
+
const src = raw.prepare(SOURCES).get();
|
|
54666
|
+
const runs = raw.prepare(REDIRECTED).get(RUN_LABEL_PREFIX.length, RUN_LABEL_PREFIX);
|
|
54667
|
+
const last2 = Math.max(Number(raw.prepare(LAST).get().last), Number(runs.last));
|
|
54668
|
+
const pages = raw.prepare("PRAGMA page_count").get();
|
|
54669
|
+
const size = raw.prepare("PRAGMA page_size").get();
|
|
54670
|
+
return {
|
|
54671
|
+
groups,
|
|
54672
|
+
tools,
|
|
54673
|
+
kinds,
|
|
54674
|
+
span: span2,
|
|
54675
|
+
sessions: Number(meta3.sessions),
|
|
54676
|
+
agents: Number(meta3.agents),
|
|
54677
|
+
days: Number(meta3.days),
|
|
54678
|
+
sources: { count: Number(src.n), chunks: Number(src.chunks), bytes: Number(src.bytes) },
|
|
54679
|
+
dbBytes: Number(pages.page_count) * Number(size.page_size),
|
|
54680
|
+
top: raw.prepare(TOP).all().map((r) => ({ name: String(r.tool), ...totals(r) })),
|
|
54681
|
+
replaced: Number(raw.prepare(REPLACED).get().n),
|
|
54682
|
+
redirected: Number(runs.n),
|
|
54683
|
+
week: readWeek(raw, last2)
|
|
54684
|
+
};
|
|
54135
54685
|
}
|
|
54136
54686
|
function sum(groups) {
|
|
54137
54687
|
return groups.reduce((t, g) => ({
|
|
@@ -54145,23 +54695,225 @@ function reductionPct(t) {
|
|
|
54145
54695
|
if (t.calls === 0) return 0;
|
|
54146
54696
|
return Number((t.saved * PERCENT_SCALE / Math.max(1, t.produced)).toFixed(1));
|
|
54147
54697
|
}
|
|
54148
|
-
function tableRow(
|
|
54698
|
+
function tableRow(label2, t) {
|
|
54149
54699
|
const last2 = t.calls === 0 ? STATS_NO_DATA : String(reductionPct(t));
|
|
54150
|
-
return "| " + [
|
|
54700
|
+
return "| " + [label2, t.produced + " B", t.returned + " B", t.saved + " B", last2].join(" | ") + " |";
|
|
54701
|
+
}
|
|
54702
|
+
var UNITS = ["KB", "MB", "GB", "TB"];
|
|
54703
|
+
var LABEL_W = STATS_LABEL_W;
|
|
54704
|
+
var NUM_W = STATS_NUM_W;
|
|
54705
|
+
var PCT_W = STATS_PCT_W;
|
|
54706
|
+
var INT = new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 });
|
|
54707
|
+
function int4(n) {
|
|
54708
|
+
return INT.format(Math.round(n));
|
|
54709
|
+
}
|
|
54710
|
+
function count(n) {
|
|
54711
|
+
return n < STATS_MILLION ? int4(n) : (n / STATS_MILLION).toFixed(1) + "M";
|
|
54712
|
+
}
|
|
54713
|
+
function bytes4(n) {
|
|
54714
|
+
if (n < 0) return "-" + bytes4(-n);
|
|
54715
|
+
if (n < STATS_KIB) return int4(n) + " B";
|
|
54716
|
+
let v = n / STATS_KIB;
|
|
54717
|
+
let u = 0;
|
|
54718
|
+
while (v >= STATS_KIB && u < UNITS.length - 1) {
|
|
54719
|
+
v /= STATS_KIB;
|
|
54720
|
+
u++;
|
|
54721
|
+
}
|
|
54722
|
+
return v.toFixed(1) + " " + UNITS[u];
|
|
54723
|
+
}
|
|
54724
|
+
function pct(t) {
|
|
54725
|
+
return (t.saved * PERCENT_SCALE / Math.max(1, t.produced)).toFixed(1) + "%";
|
|
54726
|
+
}
|
|
54727
|
+
function bar(value, max, width, fill = "\u2588", rest = "") {
|
|
54728
|
+
const n = value <= 0 || max <= 0 ? 0 : Math.min(width, Math.max(1, Math.round(value / max * width)));
|
|
54729
|
+
return fill.repeat(n) + rest.repeat(width - n);
|
|
54730
|
+
}
|
|
54731
|
+
function label(s) {
|
|
54732
|
+
const chars = [...s];
|
|
54733
|
+
return (chars.length > STATS_LABEL_MAX ? chars.slice(0, STATS_LABEL_MAX - 1).join("") + "\u2026" : s).padEnd(LABEL_W);
|
|
54734
|
+
}
|
|
54735
|
+
function span(ms) {
|
|
54736
|
+
const min = Math.floor(ms / STATS_MS_PER_MINUTE);
|
|
54737
|
+
if (min < 1) return "<1m";
|
|
54738
|
+
if (min < STATS_MINUTES_PER_HOUR) return min + "m";
|
|
54739
|
+
const h = Math.floor(min / STATS_MINUTES_PER_HOUR);
|
|
54740
|
+
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`;
|
|
54741
|
+
}
|
|
54742
|
+
function plural(n, word) {
|
|
54743
|
+
return `${int4(n)} ${word}${n === 1 ? "" : "s"}`;
|
|
54744
|
+
}
|
|
54745
|
+
function table2(title, rows) {
|
|
54746
|
+
const max = Math.max(0, ...rows.map((r) => r.saved));
|
|
54747
|
+
const head = " " + title.padEnd(LABEL_W) + "Calls".padStart(STATS_CALLS_W) + "Made".padStart(NUM_W) + "Sent".padStart(NUM_W) + "Kept out".padStart(NUM_W) + "%".padStart(PCT_W);
|
|
54748
|
+
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())];
|
|
54749
|
+
}
|
|
54750
|
+
function bySaved(a, b) {
|
|
54751
|
+
return b.saved - a.saved || b.produced - a.produced || a.returned - b.returned || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
54752
|
+
}
|
|
54753
|
+
function toolName(tool) {
|
|
54754
|
+
return tool.startsWith("ctx_") ? tool : "hook " + tool;
|
|
54755
|
+
}
|
|
54756
|
+
function joinIndex(tools) {
|
|
54757
|
+
const idx = tools.filter((t2) => STATS_INDEX_TOOLS.includes(t2.name));
|
|
54758
|
+
if (idx.length <= 1) return tools;
|
|
54759
|
+
const t = sum(idx);
|
|
54760
|
+
const one = { name: STATS_INDEX_TOOLS.join(" + ").replace(" + ctx_", " + "), ...t, saved: t.produced - t.returned };
|
|
54761
|
+
return [...tools.filter((x) => !idx.includes(x)), one];
|
|
54762
|
+
}
|
|
54763
|
+
function toolRows(tools) {
|
|
54764
|
+
const named = joinIndex(tools.map((t) => ({ ...t, saved: t.produced - t.returned }))).map((t) => ({ ...t, name: toolName(t.name) })).sort(bySaved);
|
|
54765
|
+
const zero = named.filter((t) => t.saved <= 0);
|
|
54766
|
+
const fold = zero.length > 1 ? zero : [];
|
|
54767
|
+
const keep = named.filter((t) => !fold.includes(t));
|
|
54768
|
+
const room = fold.length > 0 ? STATS_MAX_TOOL_ROWS - 1 : STATS_MAX_TOOL_ROWS;
|
|
54769
|
+
const over = keep.length > room;
|
|
54770
|
+
const shown2 = over ? keep.slice(0, STATS_MAX_TOOL_ROWS - 1) : keep;
|
|
54771
|
+
const rest = over ? [...keep.slice(STATS_MAX_TOOL_ROWS - 1), ...fold] : fold;
|
|
54772
|
+
return rest.length === 0 ? shown2 : [...shown2, { name: `other (${plural(rest.length, "tool")})`, ...sum(rest) }];
|
|
54773
|
+
}
|
|
54774
|
+
var TOKEN_UNITS = ["K", "M", "B", "T"];
|
|
54775
|
+
function whole(v) {
|
|
54776
|
+
return v >= STATS_WHOLE_FROM ? int4(v) : v.toFixed(1);
|
|
54777
|
+
}
|
|
54778
|
+
function tokens(n) {
|
|
54779
|
+
if (n < STATS_THOUSAND) return int4(n);
|
|
54780
|
+
let v = n / STATS_THOUSAND;
|
|
54781
|
+
let u = 0;
|
|
54782
|
+
while (v >= STATS_THOUSAND && u < TOKEN_UNITS.length - 1) {
|
|
54783
|
+
v /= STATS_THOUSAND;
|
|
54784
|
+
u++;
|
|
54785
|
+
}
|
|
54786
|
+
return whole(v) + TOKEN_UNITS[u];
|
|
54787
|
+
}
|
|
54788
|
+
function windowLine(saved) {
|
|
54789
|
+
const t = saved / STATS_BYTES_PER_TOKEN;
|
|
54790
|
+
const share = t / STATS_WINDOW_TOKENS;
|
|
54791
|
+
const win = `a ${tokens(STATS_WINDOW_TOKENS)} window`;
|
|
54792
|
+
const head = ` about ${tokens(t)} tokens kept out`;
|
|
54793
|
+
if (share >= 1) return `${head}, ${whole(share)} times ${win}`;
|
|
54794
|
+
const p = share * PERCENT_SCALE;
|
|
54795
|
+
return p * STATS_WHOLE_FROM < 1 ? head : `${head}, ${whole(p)}% of ${win}`;
|
|
54796
|
+
}
|
|
54797
|
+
function ymd(day) {
|
|
54798
|
+
return new Date(day * MS_PER_DAY).toISOString().slice(0, "yyyy-mm-dd".length);
|
|
54799
|
+
}
|
|
54800
|
+
function mmdd(day) {
|
|
54801
|
+
return ymd(day).slice("yyyy-".length);
|
|
54802
|
+
}
|
|
54803
|
+
function stack(parts, max, width) {
|
|
54804
|
+
let total = 0;
|
|
54805
|
+
let at = 0;
|
|
54806
|
+
let out = "";
|
|
54807
|
+
parts.forEach((v, i) => {
|
|
54808
|
+
total += v;
|
|
54809
|
+
const end = max <= 0 ? 0 : Math.round(total / max * width);
|
|
54810
|
+
if (end > at) {
|
|
54811
|
+
out += STATS_WAYS[i][1].repeat(end - at);
|
|
54812
|
+
at = end;
|
|
54813
|
+
}
|
|
54814
|
+
});
|
|
54815
|
+
if (out === "" && total > 0) out = STATS_WAYS[parts.indexOf(Math.max(...parts))][1];
|
|
54816
|
+
return out;
|
|
54817
|
+
}
|
|
54818
|
+
function cards(cells) {
|
|
54819
|
+
return (" " + cells.map((c) => c.padEnd(STATS_CARD_W)).join("")).trimEnd();
|
|
54820
|
+
}
|
|
54821
|
+
function lastDays(week, allCalls) {
|
|
54822
|
+
const saved = week.map((d) => STATS_WAYS.reduce((t, [w]) => t + d.ways[w], 0));
|
|
54823
|
+
const all = saved.reduce((a, b) => a + b, 0);
|
|
54824
|
+
const calls = week.reduce((a, d) => a + d.calls, 0);
|
|
54825
|
+
const max = Math.max(0, ...saved);
|
|
54826
|
+
const head = `Last ${STATS_DAYS} days of use \xB7 ${ymd(week[0].day)} to ${ymd(week[week.length - 1].day)}`;
|
|
54827
|
+
const card = calls < allCalls ? [
|
|
54828
|
+
cards(["Kept out", "Tokens kept out", "Calls", "Kept out per call"]),
|
|
54829
|
+
cards([bytes4(all), "about " + tokens(all / STATS_BYTES_PER_TOKEN), count(calls), bytes4(calls > 0 ? all / calls : 0)]),
|
|
54830
|
+
""
|
|
54831
|
+
] : [];
|
|
54832
|
+
return [
|
|
54833
|
+
head,
|
|
54834
|
+
...card,
|
|
54835
|
+
...week.flatMap((d, i) => saved[i] > 0 ? [" " + mmdd(d.day) + " " + stack(STATS_WAYS.map(([w]) => d.ways[w]), max, STATS_DAY_BAR).padEnd(STATS_DAY_BAR) + bytes4(saved[i]).padStart(NUM_W)] : []),
|
|
54836
|
+
" " + STATS_WAYS.map(([, ch, name]) => `${ch} ${name}`).join(" "),
|
|
54837
|
+
""
|
|
54838
|
+
];
|
|
54839
|
+
}
|
|
54840
|
+
function hookLine(redirected, replaced) {
|
|
54841
|
+
const all = redirected + replaced;
|
|
54842
|
+
if (all === 0) return [];
|
|
54843
|
+
const parts = [...redirected > 0 ? [`${int4(redirected)} sent to the sandbox`] : [], ...replaced > 0 ? [`${int4(replaced)} cut down`] : []];
|
|
54844
|
+
const what = plural(all, "large output");
|
|
54845
|
+
return [parts.length === 1 ? ` Project hooks: ${what} ${parts[0].replace(/^[\d,]+ /, "")}` : ` Project hooks: ${what} kept out \xB7 ${parts.join(", ")}`];
|
|
54846
|
+
}
|
|
54847
|
+
function fit(line) {
|
|
54848
|
+
const chars = [...line];
|
|
54849
|
+
return chars.length <= STATS_WIDTH ? line : chars.slice(0, STATS_WIDTH - 1).join("") + "\u2026";
|
|
54850
|
+
}
|
|
54851
|
+
function report(f, sessionId, agent) {
|
|
54852
|
+
const head = [STATS_REPORT_TITLE, "\u2500".repeat(STATS_WIDTH), ""];
|
|
54853
|
+
const project = sum(f.groups);
|
|
54854
|
+
if (project.calls === 0) return [...head, ...STATS_EMPTY_LINES].join("\n");
|
|
54855
|
+
const session = sum(f.groups.filter((g) => g.session === sessionId));
|
|
54856
|
+
const [scopeName, focus] = session.calls > 0 ? ["This session", session] : ["This project", project];
|
|
54857
|
+
const top = Math.max(focus.produced, focus.returned);
|
|
54858
|
+
const extra = session.calls > 0 ? ` \xB7 ${span(f.span)} active` : "";
|
|
54859
|
+
const lines = [
|
|
54860
|
+
...head,
|
|
54861
|
+
`${scopeName} \xB7 ${plural(focus.calls, "call")}${extra}`,
|
|
54862
|
+
` ${bytes4(focus.produced)} became ${bytes4(focus.returned)}: ${bytes4(focus.saved)} kept out (${pct(focus)})`,
|
|
54863
|
+
" " + "Without context-mode".padEnd(LABEL_W) + "|" + bar(focus.produced, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.produced).padStart(NUM_W),
|
|
54864
|
+
" " + "With context-mode".padEnd(LABEL_W) + "|" + bar(focus.returned, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.returned).padStart(NUM_W),
|
|
54865
|
+
...focus.saved > 0 ? [windowLine(focus.saved), STATS_TOKEN_NOTE] : [],
|
|
54866
|
+
...hookLine(f.redirected, f.replaced),
|
|
54867
|
+
"",
|
|
54868
|
+
...lastDays(f.week, project.calls + f.redirected),
|
|
54869
|
+
// D-STATS-FIX-1 (5): one DB per project holds every session of it, so project and all-time are one row.
|
|
54870
|
+
"By scope",
|
|
54871
|
+
...table2("Scope", [{ name: "session", ...session }, { name: "project (all-time)", ...project }]),
|
|
54872
|
+
"",
|
|
54873
|
+
"By tool (this project)",
|
|
54874
|
+
...table2("Tool", toolRows(f.tools)),
|
|
54875
|
+
"",
|
|
54876
|
+
...f.top.length > 0 ? [
|
|
54877
|
+
"Largest single outputs (made \u2192 sent to the chat)",
|
|
54878
|
+
...f.top.map((t) => " " + label(toolName(t.name)) + bytes4(t.produced).padStart(NUM_W) + " \u2192 " + bytes4(t.returned).padStart(NUM_W)),
|
|
54879
|
+
""
|
|
54880
|
+
] : []
|
|
54881
|
+
];
|
|
54882
|
+
const agents = /* @__PURE__ */ new Map();
|
|
54883
|
+
for (const g of f.groups) agents.set(g.agent, sum([agents.get(g.agent) ?? EMPTY3, g]));
|
|
54884
|
+
if (!agents.has(agent)) agents.set(agent, EMPTY3);
|
|
54885
|
+
lines.push("By agent (this project)", ...table2("Agent", [...agents].map(([name, t]) => ({ name, ...t })).sort(bySaved)), "");
|
|
54886
|
+
const maxKind = Math.max(0, ...[...f.kinds.values()].map((k) => k.project));
|
|
54887
|
+
lines.push("Kept in the session journal", " " + "Journal".padEnd(LABEL_W) + "Session".padStart(STATS_KIND_W) + "Project".padStart(STATS_KIND_W));
|
|
54888
|
+
for (const [kind, name] of STATS_KIND_LABELS) {
|
|
54889
|
+
const k = f.kinds.get(kind) ?? { session: 0, project: 0 };
|
|
54890
|
+
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());
|
|
54891
|
+
}
|
|
54892
|
+
lines.push("", ...STATS_JOURNAL_HINTS.map((h) => " " + h), "");
|
|
54893
|
+
lines.push(
|
|
54894
|
+
" " + "Index and search".padEnd(LABEL_W) + `${plural(f.sources.count, "source")} \xB7 ${plural(f.sources.chunks, "chunk")} \xB7 ${bytes4(f.sources.bytes)} \xB7 ${plural(f.tools.find((t) => t.name === "ctx_search")?.calls ?? 0, "ctx_search call")}`,
|
|
54895
|
+
" " + "Database file".padEnd(LABEL_W) + bytes4(f.dbBytes),
|
|
54896
|
+
" " + "Sessions".padEnd(LABEL_W) + `${int4(f.sessions)} \xB7 agents ${int4(f.agents)} \xB7 active days ${int4(f.days)}`,
|
|
54897
|
+
"",
|
|
54898
|
+
STATS_FOOTER_URL,
|
|
54899
|
+
"github.com/" + ISSUE_REPO_SLUG
|
|
54900
|
+
);
|
|
54901
|
+
return lines.map(fit).join("\n");
|
|
54151
54902
|
}
|
|
54152
54903
|
async function handler7(_input, ctx) {
|
|
54153
54904
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
54154
|
-
let
|
|
54905
|
+
let facts;
|
|
54155
54906
|
try {
|
|
54156
|
-
|
|
54907
|
+
facts = readFacts(db.raw, ctx.sessionId);
|
|
54157
54908
|
} finally {
|
|
54158
54909
|
closeDb(db);
|
|
54159
54910
|
}
|
|
54911
|
+
const groups = facts.groups;
|
|
54160
54912
|
const session = sum(groups.filter((g) => g.session === ctx.sessionId));
|
|
54161
54913
|
const project = sum(groups);
|
|
54162
54914
|
const allTime = project;
|
|
54163
54915
|
const agentIds = [.../* @__PURE__ */ new Set([...groups.map((g) => g.agent), ctx.project.agent])].sort();
|
|
54164
|
-
const
|
|
54916
|
+
const mdTable = [
|
|
54165
54917
|
"| " + STATS_COLUMNS.join(" | ") + " |",
|
|
54166
54918
|
"|" + STATS_COLUMNS.map(() => "---").join("|") + "|",
|
|
54167
54919
|
tableRow("session", session),
|
|
@@ -54170,7 +54922,8 @@ async function handler7(_input, ctx) {
|
|
|
54170
54922
|
...agentIds.map((a) => tableRow("agent " + a, sum(groups.filter((g) => g.agent === a))))
|
|
54171
54923
|
].join("\n");
|
|
54172
54924
|
const summary = STATS_SUMMARY(reductionPct(allTime), reductionPct(session));
|
|
54173
|
-
|
|
54925
|
+
const text = summary + "\n\n```text\n" + report(facts, ctx.sessionId, ctx.project.agent) + "\n```\n\n" + mdTable;
|
|
54926
|
+
return { text: capBytes(text, OUTPUT_CAP).text, isError: false, sandboxBytes: 0 };
|
|
54174
54927
|
}
|
|
54175
54928
|
var ctxStats = Object.freeze({
|
|
54176
54929
|
name: "ctx_stats",
|
|
@@ -54181,28 +54934,28 @@ var ctxStats = Object.freeze({
|
|
|
54181
54934
|
});
|
|
54182
54935
|
|
|
54183
54936
|
// src/core/tools/upgrade.ts
|
|
54184
|
-
import { existsSync as
|
|
54185
|
-
import { basename as basename6, dirname as dirname10, join as
|
|
54937
|
+
import { existsSync as existsSync22, realpathSync as realpathSync10, rmSync as rmSync10 } from "node:fs";
|
|
54938
|
+
import { basename as basename6, dirname as dirname10, join as join22 } from "node:path";
|
|
54186
54939
|
|
|
54187
54940
|
// src/core/ops/host-write.ts
|
|
54188
|
-
import { copyFileSync, existsSync as
|
|
54189
|
-
import { dirname as dirname9, join as
|
|
54941
|
+
import { copyFileSync, existsSync as existsSync17, mkdirSync as mkdirSync6, writeFileSync as writeFileSync5 } from "node:fs";
|
|
54942
|
+
import { dirname as dirname9, join as join17 } from "node:path";
|
|
54190
54943
|
function defaultWrite(file2, text) {
|
|
54191
|
-
|
|
54944
|
+
writeFileSync5(file2, text, "utf8");
|
|
54192
54945
|
}
|
|
54193
54946
|
function hostConfigPath(agent, home, env) {
|
|
54194
54947
|
const own4 = OWN_MCP_ENTRY[agent];
|
|
54195
54948
|
if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
|
|
54196
54949
|
switch (agent) {
|
|
54197
54950
|
case "opencode":
|
|
54198
|
-
return
|
|
54951
|
+
return join17(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
54199
54952
|
// D-WIN-OPENCODE-DIR-1
|
|
54200
54953
|
case "pi":
|
|
54201
|
-
return
|
|
54954
|
+
return join17(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
54202
54955
|
case "copilot-cli":
|
|
54203
54956
|
return null;
|
|
54204
54957
|
default:
|
|
54205
|
-
return
|
|
54958
|
+
return join17(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
54206
54959
|
}
|
|
54207
54960
|
}
|
|
54208
54961
|
function cell3(value) {
|
|
@@ -54214,8 +54967,8 @@ function toRow(file2, edit) {
|
|
|
54214
54967
|
function writeWithRollback(file2, text, write, atomic) {
|
|
54215
54968
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
54216
54969
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
54217
|
-
const had =
|
|
54218
|
-
|
|
54970
|
+
const had = existsSync17(file2);
|
|
54971
|
+
mkdirSync6(dirname9(file2), { recursive: true });
|
|
54219
54972
|
if (had) copyFileSync(file2, trash);
|
|
54220
54973
|
try {
|
|
54221
54974
|
write(tmp, text);
|
|
@@ -54244,7 +54997,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
54244
54997
|
if (requested === null) return [];
|
|
54245
54998
|
const current = readHostConfig(row5.id, requested);
|
|
54246
54999
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
54247
|
-
const exists =
|
|
55000
|
+
const exists = existsSync17(current.path);
|
|
54248
55001
|
if (exists && result.text === current.text) return [];
|
|
54249
55002
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
54250
55003
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -54252,8 +55005,8 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
54252
55005
|
}
|
|
54253
55006
|
|
|
54254
55007
|
// src/core/ops/plugin-swap.ts
|
|
54255
|
-
import { existsSync as
|
|
54256
|
-
import { basename as basename5, join as
|
|
55008
|
+
import { existsSync as existsSync18, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
55009
|
+
import { basename as basename5, join as join18, win32 as win322 } from "node:path";
|
|
54257
55010
|
function linkTarget(path7, win) {
|
|
54258
55011
|
if (!isLink(path7)) return null;
|
|
54259
55012
|
const target = readlinkSync(path7);
|
|
@@ -54272,11 +55025,11 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
54272
55025
|
else renameWithRetry(old, link, opts);
|
|
54273
55026
|
}
|
|
54274
55027
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
54275
|
-
const next =
|
|
54276
|
-
if (!
|
|
55028
|
+
const next = join18(agentDir, sha);
|
|
55029
|
+
if (!existsSync18(next) || !lstatSync(next).isDirectory()) {
|
|
54277
55030
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename5(agentDir), path: next });
|
|
54278
55031
|
}
|
|
54279
|
-
const link =
|
|
55032
|
+
const link = join18(agentDir, PLUGIN_CURRENT_LINK);
|
|
54280
55033
|
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
54281
55034
|
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
54282
55035
|
settleLinks(link, tmp, old, opts);
|
|
@@ -54291,15 +55044,15 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
54291
55044
|
if (before !== null) unlinkSync2(old);
|
|
54292
55045
|
const keep = /* @__PURE__ */ new Set([sha]);
|
|
54293
55046
|
if (before !== null) keep.add(before);
|
|
54294
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) =>
|
|
55047
|
+
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join18(agentDir, name));
|
|
54295
55048
|
for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
|
|
54296
|
-
const previous = before !== null &&
|
|
55049
|
+
const previous = before !== null && existsSync18(join18(agentDir, before)) ? join18(agentDir, before) : null;
|
|
54297
55050
|
return { current: next, previous, removed };
|
|
54298
55051
|
}
|
|
54299
55052
|
|
|
54300
55053
|
// src/core/ops/release-fetch.ts
|
|
54301
|
-
import { existsSync as
|
|
54302
|
-
import { join as
|
|
55054
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync7, rmSync as rmSync7 } from "node:fs";
|
|
55055
|
+
import { join as join19 } from "node:path";
|
|
54303
55056
|
function failed(r) {
|
|
54304
55057
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
54305
55058
|
const status = r.killed ?? String(r.exitCode);
|
|
@@ -54311,9 +55064,9 @@ async function git2(bin, args, cwd, env, signal) {
|
|
|
54311
55064
|
return r.stdout.toString().trim();
|
|
54312
55065
|
}
|
|
54313
55066
|
async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
54314
|
-
const agentDir =
|
|
54315
|
-
|
|
54316
|
-
const fetchDir =
|
|
55067
|
+
const agentDir = join19(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
55068
|
+
mkdirSync7(agentDir, { recursive: true });
|
|
55069
|
+
const fetchDir = join19(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
54317
55070
|
rmSync7(fetchDir, { recursive: true, force: true });
|
|
54318
55071
|
const gitBin = findRuntime(GIT_BIN, env);
|
|
54319
55072
|
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -54321,8 +55074,8 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
54321
55074
|
try {
|
|
54322
55075
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
|
|
54323
55076
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
54324
|
-
const dir =
|
|
54325
|
-
if (
|
|
55077
|
+
const dir = join19(agentDir, sha);
|
|
55078
|
+
if (existsSync19(dir)) rmSync7(fetchDir, { recursive: true, force: true });
|
|
54326
55079
|
else renameWithRetry(fetchDir, dir, opts);
|
|
54327
55080
|
return { sha, dir };
|
|
54328
55081
|
} catch (e) {
|
|
@@ -54332,15 +55085,15 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
54332
55085
|
}
|
|
54333
55086
|
|
|
54334
55087
|
// src/core/ops/uninstall.ts
|
|
54335
|
-
import { existsSync as
|
|
54336
|
-
import { join as
|
|
55088
|
+
import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
55089
|
+
import { join as join20 } from "node:path";
|
|
54337
55090
|
function row2(area, before, after) {
|
|
54338
55091
|
return { area, before, after };
|
|
54339
55092
|
}
|
|
54340
55093
|
function stopServers(configDir, projectKey) {
|
|
54341
55094
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
54342
|
-
const dir =
|
|
54343
|
-
for (const serverId of stopped)
|
|
55095
|
+
const dir = join20(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
55096
|
+
for (const serverId of stopped) writeFileSync6(join20(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
54344
55097
|
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
55098
|
}
|
|
54346
55099
|
function rootOrNull(adapter, env) {
|
|
@@ -54358,15 +55111,15 @@ function removeCache(adapter, env, configDir) {
|
|
|
54358
55111
|
const root = rootOrNull(adapter, env);
|
|
54359
55112
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
54360
55113
|
if (adapter.installMode === "marketplace") {
|
|
54361
|
-
const cache =
|
|
55114
|
+
const cache = join20(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
54362
55115
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
54363
55116
|
}
|
|
54364
55117
|
rmSync8(root, { recursive: true, force: true });
|
|
54365
55118
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
54366
55119
|
}
|
|
54367
55120
|
case "plugin": {
|
|
54368
|
-
const agentDir =
|
|
54369
|
-
if (!
|
|
55121
|
+
const agentDir = join20(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
55122
|
+
if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
54370
55123
|
rmSync8(agentDir, { recursive: true, force: true });
|
|
54371
55124
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
54372
55125
|
}
|
|
@@ -54411,7 +55164,7 @@ function ownEntries(agent, env) {
|
|
|
54411
55164
|
}
|
|
54412
55165
|
if (agent === "opencode") {
|
|
54413
55166
|
return [{
|
|
54414
|
-
file:
|
|
55167
|
+
file: join20(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
54415
55168
|
// D-WIN-OPENCODE-DIR-1
|
|
54416
55169
|
key: OPENCODE_PLUGIN_KEY,
|
|
54417
55170
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -54422,7 +55175,7 @@ function ownEntries(agent, env) {
|
|
|
54422
55175
|
if (agent === "pi") {
|
|
54423
55176
|
const agentDir = piAgentDirOf(env, home);
|
|
54424
55177
|
return [{
|
|
54425
|
-
file:
|
|
55178
|
+
file: join20(agentDir, SETTINGS_FILE),
|
|
54426
55179
|
key: PI_PACKAGES_KEY,
|
|
54427
55180
|
shown: PI_PACKAGES_KEY,
|
|
54428
55181
|
has: (v) => Array.isArray(v) && v.some((x) => piSource(x) === PI_GIT_PACKAGE),
|
|
@@ -54444,12 +55197,12 @@ function removeOwnEntries(agent, env) {
|
|
|
54444
55197
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
54445
55198
|
}
|
|
54446
55199
|
function removeProjectData(configDir, projectKey) {
|
|
54447
|
-
const projects =
|
|
54448
|
-
const dir =
|
|
54449
|
-
if (!
|
|
55200
|
+
const projects = join20(configDir, PROJECTS_DIR_NAME);
|
|
55201
|
+
const dir = join20(projects, projectKey);
|
|
55202
|
+
if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
54450
55203
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
54451
55204
|
for (const name of readdirSync9(dir)) {
|
|
54452
|
-
if (name !== OWNERS_DIR_NAME) rmSync8(
|
|
55205
|
+
if (name !== OWNERS_DIR_NAME) rmSync8(join20(dir, name), { recursive: true, force: true });
|
|
54453
55206
|
}
|
|
54454
55207
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
54455
55208
|
}
|
|
@@ -54457,12 +55210,12 @@ function runUninstall(input) {
|
|
|
54457
55210
|
const configDir = resolveConfigDir(input.env);
|
|
54458
55211
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
54459
55212
|
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,
|
|
55213
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join20(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
54461
55214
|
return { rows, stopped: stop.stopped };
|
|
54462
55215
|
}
|
|
54463
55216
|
|
|
54464
55217
|
// src/core/ops/v1-remove.ts
|
|
54465
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
55218
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync13, rmSync as rmSync9 } from "node:fs";
|
|
54466
55219
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
54467
55220
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
54468
55221
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -54481,13 +55234,13 @@ function keepOriginal(file2, kept, undo) {
|
|
|
54481
55234
|
undo.push({ trash, target: file2 });
|
|
54482
55235
|
}
|
|
54483
55236
|
function cutTomlTable(text, header) {
|
|
54484
|
-
let
|
|
55237
|
+
let span2;
|
|
54485
55238
|
try {
|
|
54486
|
-
|
|
55239
|
+
span2 = tomlTableSpans(text).find((t) => t.header.trim() === header);
|
|
54487
55240
|
} catch {
|
|
54488
55241
|
return null;
|
|
54489
55242
|
}
|
|
54490
|
-
return
|
|
55243
|
+
return span2 === void 0 ? null : text.slice(0, span2.start) + text.slice(span2.end);
|
|
54491
55244
|
}
|
|
54492
55245
|
function writeAtomic(file2, text) {
|
|
54493
55246
|
atomicWriteFile(file2, text);
|
|
@@ -54506,8 +55259,8 @@ function locate(doc, path7) {
|
|
|
54506
55259
|
return null;
|
|
54507
55260
|
}
|
|
54508
55261
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
54509
|
-
const layout = hostLayout(
|
|
54510
|
-
const text = hostText(
|
|
55262
|
+
const layout = hostLayout(readFileSync13(file2, "utf8"));
|
|
55263
|
+
const text = hostText(readFileSync13(file2, "utf8"));
|
|
54511
55264
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
54512
55265
|
const hit = /* @__PURE__ */ new Set();
|
|
54513
55266
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -54543,19 +55296,19 @@ function removeV1(agent, findings) {
|
|
|
54543
55296
|
for (const f of findings) {
|
|
54544
55297
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
54545
55298
|
else if (f.path === "") {
|
|
54546
|
-
if (
|
|
55299
|
+
if (existsSync21(f.file)) {
|
|
54547
55300
|
moveAside(f.file, undo);
|
|
54548
55301
|
done.set(f, UPGRADE_REMOVED);
|
|
54549
55302
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
54550
55303
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
54551
55304
|
}
|
|
54552
55305
|
for (const [file2, list3] of entries) {
|
|
54553
|
-
if (!
|
|
55306
|
+
if (!existsSync21(file2)) {
|
|
54554
55307
|
for (const f of list3) done.set(f, UPGRADE_NOT_FOUND);
|
|
54555
55308
|
continue;
|
|
54556
55309
|
}
|
|
54557
55310
|
if (file2.endsWith(TOML_EXT)) {
|
|
54558
|
-
const rawToml =
|
|
55311
|
+
const rawToml = readFileSync13(file2, "utf8");
|
|
54559
55312
|
const tomlLayout = hostLayout(rawToml);
|
|
54560
55313
|
let text = hostText(rawToml);
|
|
54561
55314
|
for (const f of list3) {
|
|
@@ -54583,7 +55336,7 @@ function removeV1(agent, findings) {
|
|
|
54583
55336
|
},
|
|
54584
55337
|
rollback() {
|
|
54585
55338
|
for (const u of undo.splice(0).reverse()) {
|
|
54586
|
-
if (!
|
|
55339
|
+
if (!existsSync21(u.trash)) continue;
|
|
54587
55340
|
rmSync9(u.target, { recursive: true, force: true });
|
|
54588
55341
|
renameWithRetry(u.trash, u.target);
|
|
54589
55342
|
}
|
|
@@ -54593,8 +55346,8 @@ function removeV1(agent, findings) {
|
|
|
54593
55346
|
|
|
54594
55347
|
// src/core/ops/verify-sums.ts
|
|
54595
55348
|
import { createHash as createHash2 } from "node:crypto";
|
|
54596
|
-
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as
|
|
54597
|
-
import { join as
|
|
55349
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync14 } from "node:fs";
|
|
55350
|
+
import { join as join21 } from "node:path";
|
|
54598
55351
|
function mismatch() {
|
|
54599
55352
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
54600
55353
|
}
|
|
@@ -54615,24 +55368,24 @@ function walk2(dir, prefix, out) {
|
|
|
54615
55368
|
for (const entry of readdirSync10(dir, { withFileTypes: true })) {
|
|
54616
55369
|
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
54617
55370
|
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
54618
|
-
const abs =
|
|
55371
|
+
const abs = join21(dir, entry.name);
|
|
54619
55372
|
if (entry.isDirectory()) walk2(abs, rel, out);
|
|
54620
55373
|
else if (entry.isFile()) out.set(rel, abs);
|
|
54621
55374
|
else throw mismatch();
|
|
54622
55375
|
}
|
|
54623
55376
|
}
|
|
54624
55377
|
function verifySums(dir) {
|
|
54625
|
-
const sumsPath =
|
|
55378
|
+
const sumsPath = join21(dir, RELEASE_SUMS_FILE);
|
|
54626
55379
|
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
54627
55380
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
54628
|
-
const sums = parseSums(
|
|
55381
|
+
const sums = parseSums(readFileSync14(sumsPath, "utf8"));
|
|
54629
55382
|
const files = /* @__PURE__ */ new Map();
|
|
54630
55383
|
walk2(dir, "", files);
|
|
54631
55384
|
if (files.size !== sums.size) throw mismatch();
|
|
54632
55385
|
for (const [rel, abs] of files) {
|
|
54633
55386
|
const want = sums.get(rel);
|
|
54634
55387
|
if (want === void 0) throw mismatch();
|
|
54635
|
-
const got = createHash2(SUMS_HASH_ALGORITHM).update(
|
|
55388
|
+
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync14(abs)).digest(HASH_ENCODING);
|
|
54636
55389
|
if (got !== want) throw mismatch();
|
|
54637
55390
|
}
|
|
54638
55391
|
}
|
|
@@ -54660,8 +55413,8 @@ function pluginRootRow(adapter, env) {
|
|
|
54660
55413
|
return root === own4 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own4)];
|
|
54661
55414
|
}
|
|
54662
55415
|
function isCurrent(agentDir, dir) {
|
|
54663
|
-
const link =
|
|
54664
|
-
return
|
|
55416
|
+
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
55417
|
+
return existsSync22(link) && realpathSync10.native(link) === realpathSync10.native(dir);
|
|
54665
55418
|
}
|
|
54666
55419
|
async function checkout(adapter, deps) {
|
|
54667
55420
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
@@ -54757,7 +55510,7 @@ function define(name) {
|
|
|
54757
55510
|
handler: built.handler
|
|
54758
55511
|
};
|
|
54759
55512
|
}
|
|
54760
|
-
var
|
|
55513
|
+
var TOOLS2 = Object.freeze(TOOL_ORDER.map(define));
|
|
54761
55514
|
function callExample(tool) {
|
|
54762
55515
|
const a = tool.description.indexOf("`");
|
|
54763
55516
|
const b = tool.description.indexOf("`", a + 1);
|
|
@@ -54780,12 +55533,12 @@ function checkCall(tool, input) {
|
|
|
54780
55533
|
}
|
|
54781
55534
|
|
|
54782
55535
|
// src/entries/is-entry.ts
|
|
54783
|
-
import { realpathSync as
|
|
55536
|
+
import { realpathSync as realpathSync11 } from "node:fs";
|
|
54784
55537
|
function isEntry(main, argv1, self) {
|
|
54785
55538
|
if (main !== void 0) return main;
|
|
54786
55539
|
if (argv1 === void 0 || argv1 === "") return false;
|
|
54787
55540
|
try {
|
|
54788
|
-
return
|
|
55541
|
+
return realpathSync11(argv1) === realpathSync11(self);
|
|
54789
55542
|
} catch {
|
|
54790
55543
|
return false;
|
|
54791
55544
|
}
|
|
@@ -54861,7 +55614,7 @@ function workspaceFromMeta(meta3) {
|
|
|
54861
55614
|
}
|
|
54862
55615
|
function realOrSame(p) {
|
|
54863
55616
|
try {
|
|
54864
|
-
return
|
|
55617
|
+
return realpathSync12.native(p);
|
|
54865
55618
|
} catch {
|
|
54866
55619
|
return p;
|
|
54867
55620
|
}
|
|
@@ -54880,7 +55633,7 @@ function errorReply(err) {
|
|
|
54880
55633
|
async function startServer(argv, env) {
|
|
54881
55634
|
const serverId = randomUUID();
|
|
54882
55635
|
const degraded = await isDegraded();
|
|
54883
|
-
const tools = degraded ?
|
|
55636
|
+
const tools = degraded ? TOOLS2.filter((t) => t.name === "ctx_doctor") : TOOLS2;
|
|
54884
55637
|
const pending = /* @__PURE__ */ new Map();
|
|
54885
55638
|
const held = [];
|
|
54886
55639
|
let cleaned = false;
|
|
@@ -54909,15 +55662,15 @@ async function startServer(argv, env) {
|
|
|
54909
55662
|
opening.catch(() => pending.delete(project.dbPath));
|
|
54910
55663
|
}
|
|
54911
55664
|
const db = await opening;
|
|
54912
|
-
if (!
|
|
55665
|
+
if (!existsSync23(db.path)) throw new CtxError("DB_GONE");
|
|
54913
55666
|
return db;
|
|
54914
55667
|
}
|
|
54915
55668
|
function stopMarker(configDir, projectKey) {
|
|
54916
|
-
return
|
|
55669
|
+
return join23(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
|
|
54917
55670
|
}
|
|
54918
55671
|
function stopRequested() {
|
|
54919
55672
|
const configDir = resolveConfigDir(process.env);
|
|
54920
|
-
return held.some((db) =>
|
|
55673
|
+
return held.some((db) => existsSync23(stopMarker(configDir, db.projectKey)));
|
|
54921
55674
|
}
|
|
54922
55675
|
async function journal(project, ctx, name, reply4) {
|
|
54923
55676
|
const db = await ownDb(project);
|