token-goat 2.9.28 → 2.9.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -40
- package/SECURITY.md +28 -10
- package/THIRD_PARTY_NOTICES.md +40 -3
- package/dist/native/linux-arm64/tg-hook +0 -0
- package/dist/native/linux-x64/tg-hook +0 -0
- package/dist/ort-wasm-simd-threaded.mjs +59 -0
- package/dist/token-goat-chunk-3CHUNJ2O.mjs +53 -0
- package/dist/token-goat-chunk-3Z5S4KGM.mjs +918 -0
- package/dist/token-goat-chunk-4FVIAHSI.mjs +211 -0
- package/dist/{token-goat-chunk-66LODAUT.mjs → token-goat-chunk-4JJS54TR.mjs} +4 -3
- package/dist/token-goat-chunk-4LCCNRTG.mjs +313 -0
- package/dist/token-goat-chunk-54K3EUV3.mjs +35 -0
- package/dist/token-goat-chunk-56EIMS3E.mjs +159 -0
- package/dist/token-goat-chunk-5BCIJXMO.mjs +609 -0
- package/dist/token-goat-chunk-5KDMCMF2.mjs +362 -0
- package/dist/token-goat-chunk-5RG5SBL6.mjs +221 -0
- package/dist/{token-goat-chunk-RRNZMM3A.mjs → token-goat-chunk-5Y6ZYL6U.mjs} +21 -2
- package/dist/{token-goat-chunk-NILVK7XM.mjs → token-goat-chunk-64FBPDTK.mjs} +12 -6
- package/dist/{token-goat-chunk-LEG3JNJ6.mjs → token-goat-chunk-664RTTUV.mjs} +31 -15
- package/dist/token-goat-chunk-67TQJ76B.mjs +57 -0
- package/dist/token-goat-chunk-6QMAS7AB.mjs +42 -0
- package/dist/token-goat-chunk-7BXSNBY5.mjs +253 -0
- package/dist/{token-goat-chunk-F7QZRIWM.mjs → token-goat-chunk-7F2UBPD3.mjs} +42 -35
- package/dist/{token-goat-chunk-CC2PYJM7.mjs → token-goat-chunk-7IN2MKDS.mjs} +718 -595
- package/dist/token-goat-chunk-7NADEDKJ.mjs +124 -0
- package/dist/{token-goat-chunk-6SGLIPQB.mjs → token-goat-chunk-A3CK6N5Z.mjs} +621 -72
- package/dist/{token-goat-chunk-HXNAC4ZF.mjs → token-goat-chunk-AFLYLHDH.mjs} +48 -33
- package/dist/token-goat-chunk-AM5V6GSX.mjs +367 -0
- package/dist/{token-goat-chunk-I7CB3X4K.mjs → token-goat-chunk-APGZXSPS.mjs} +44 -148
- package/dist/{token-goat-chunk-BJBRGPBX.mjs → token-goat-chunk-ARDNEC2U.mjs} +11 -7
- package/dist/token-goat-chunk-ATCPY7EQ.mjs +134 -0
- package/dist/token-goat-chunk-B2RZZCSS.mjs +354 -0
- package/dist/{token-goat-chunk-QM76S6YS.mjs → token-goat-chunk-B45VMIIH.mjs} +6 -5
- package/dist/token-goat-chunk-BPGCUMR7.mjs +30 -0
- package/dist/{token-goat-chunk-GGLEE35R.mjs → token-goat-chunk-C63JQV5K.mjs} +49 -10
- package/dist/{token-goat-chunk-RJH64KQH.mjs → token-goat-chunk-COBQGL5S.mjs} +2661 -2440
- package/dist/token-goat-chunk-COTXZHTS.mjs +39 -0
- package/dist/token-goat-chunk-CYCEYAEO.mjs +265 -0
- package/dist/token-goat-chunk-CZ3LUXYZ.mjs +4115 -0
- package/dist/token-goat-chunk-DZX2YDPT.mjs +15 -0
- package/dist/token-goat-chunk-E3OQX2XT.mjs +824 -0
- package/dist/token-goat-chunk-EFHMMIGP.mjs +68 -0
- package/dist/token-goat-chunk-ETBHVDB6.mjs +328 -0
- package/dist/token-goat-chunk-EVMZJ27Z.mjs +147 -0
- package/dist/token-goat-chunk-EXKGNHEG.mjs +2096 -0
- package/dist/{token-goat-chunk-6Z5ULNE5.mjs → token-goat-chunk-FBNQNSJK.mjs} +2490 -4957
- package/dist/{token-goat-chunk-NMTKNYGF.mjs → token-goat-chunk-FNFBKLRD.mjs} +74 -9
- package/dist/{token-goat-chunk-XI2VFAV6.mjs → token-goat-chunk-FZ3NEW5O.mjs} +33 -19
- package/dist/token-goat-chunk-G5PJ7AGM.mjs +36 -0
- package/dist/{token-goat-chunk-VE27HPIF.mjs → token-goat-chunk-GFBSN7BD.mjs} +30 -398
- package/dist/{token-goat-chunk-L45ZQRT7.mjs → token-goat-chunk-GOLEOXZP.mjs} +780 -786
- package/dist/token-goat-chunk-H2K3QP6H.mjs +24 -0
- package/dist/token-goat-chunk-H2PHHGM5.mjs +188 -0
- package/dist/token-goat-chunk-HAVAOB3S.mjs +87 -0
- package/dist/token-goat-chunk-HG45AF2B.mjs +2228 -0
- package/dist/{token-goat-chunk-CBMY2FGI.mjs → token-goat-chunk-HOJLCGDP.mjs} +17113 -15554
- package/dist/{token-goat-chunk-HUDC5GS5.mjs → token-goat-chunk-HYBFA5X3.mjs} +120 -19
- package/dist/token-goat-chunk-IVALLT3S.mjs +48 -0
- package/dist/token-goat-chunk-IVE6U7KV.mjs +53 -0
- package/dist/{token-goat-chunk-UBUKHVYW.mjs → token-goat-chunk-IVKIZWAB.mjs} +3 -3
- package/dist/{token-goat-chunk-4JMWPWCS.mjs → token-goat-chunk-JB6QN6VF.mjs} +6 -4
- package/dist/{token-goat-chunk-Q4S3UQGO.mjs → token-goat-chunk-JDHE26RP.mjs} +10 -3
- package/dist/{token-goat-chunk-7R2XYKC5.mjs → token-goat-chunk-JDU3EXSU.mjs} +14 -10
- package/dist/token-goat-chunk-JDWCRD6M.mjs +253 -0
- package/dist/{token-goat-chunk-XBESNWEX.mjs → token-goat-chunk-JN4XMLSD.mjs} +7 -4
- package/dist/token-goat-chunk-JTQQGXZH.mjs +733 -0
- package/dist/token-goat-chunk-KKUFXAPD.mjs +25 -0
- package/dist/token-goat-chunk-KQNZDCBD.mjs +47 -0
- package/dist/{token-goat-chunk-4RN64ZND.mjs → token-goat-chunk-KWPNJBDH.mjs} +28 -3
- package/dist/token-goat-chunk-LOBGHXPB.mjs +242 -0
- package/dist/token-goat-chunk-MKPF4CL5.mjs +37 -0
- package/dist/token-goat-chunk-MNWKPRAL.mjs +13 -0
- package/dist/{token-goat-chunk-YWSP6IU7.mjs → token-goat-chunk-N2NMER56.mjs} +25 -15
- package/dist/token-goat-chunk-NYKZLXMK.mjs +218 -0
- package/dist/token-goat-chunk-OJBNYTJP.mjs +3087 -0
- package/dist/token-goat-chunk-P4QMM4WK.mjs +295 -0
- package/dist/token-goat-chunk-PD5VKH46.mjs +184 -0
- package/dist/token-goat-chunk-PEPTHRFF.mjs +129 -0
- package/dist/{token-goat-chunk-VWZKZPSR.mjs → token-goat-chunk-PU7V3FD6.mjs} +8752 -11098
- package/dist/token-goat-chunk-PY533T7F.mjs +46 -0
- package/dist/token-goat-chunk-Q5VTGRH7.mjs +761 -0
- package/dist/{token-goat-chunk-IHKZ3QNA.mjs → token-goat-chunk-QCLDAQTS.mjs} +33 -19
- package/dist/{token-goat-chunk-LKSXAMJB.mjs → token-goat-chunk-QSBRTGM2.mjs} +9 -2
- package/dist/{token-goat-chunk-4STDIGYC.mjs → token-goat-chunk-RC35RBUL.mjs} +7 -5
- package/dist/{token-goat-chunk-D5ICEPSB.mjs → token-goat-chunk-RHXKCZX3.mjs} +887 -507
- package/dist/{token-goat-chunk-RSS3TLXU.mjs → token-goat-chunk-RZRTDST7.mjs} +17 -7
- package/dist/{token-goat-chunk-MAMQPC43.mjs → token-goat-chunk-SJHWVNDQ.mjs} +15 -21
- package/dist/token-goat-chunk-SMVRN2HU.mjs +188 -0
- package/dist/{token-goat-chunk-EL7M26WP.mjs → token-goat-chunk-SQSSNQPE.mjs} +2100 -1442
- package/dist/{token-goat-chunk-OZRSREKR.mjs → token-goat-chunk-T4FK7VOV.mjs} +3 -3
- package/dist/token-goat-chunk-U4N3BN2W.mjs +92 -0
- package/dist/token-goat-chunk-UA5V6P3P.mjs +122 -0
- package/dist/{token-goat-chunk-XKY4VKJ4.mjs → token-goat-chunk-UQ5UK2T7.mjs} +15 -4
- package/dist/token-goat-chunk-USILZ3T3.mjs +53 -0
- package/dist/token-goat-chunk-VES7EL7O.mjs +205 -0
- package/dist/{token-goat-chunk-M56BWPBN.mjs → token-goat-chunk-VL3YIFHZ.mjs} +550 -49
- package/dist/{token-goat-chunk-IZXKVT4A.mjs → token-goat-chunk-VPBBTSJR.mjs} +362 -128
- package/dist/{token-goat-chunk-F2ARFHLJ.mjs → token-goat-chunk-W3QCJS6G.mjs} +10 -2
- package/dist/{token-goat-chunk-FSTWAOW6.mjs → token-goat-chunk-WY3L4DVT.mjs} +11 -5
- package/dist/{token-goat-chunk-OSUFN2FV.mjs → token-goat-chunk-XB5KKOCG.mjs} +5 -25
- package/dist/token-goat-chunk-XKI4SEMX.mjs +66 -0
- package/dist/token-goat-chunk-XU4P6Z24.mjs +133 -0
- package/dist/{token-goat-chunk-6CCQDAYY.mjs → token-goat-chunk-Y776AENC.mjs} +138 -33
- package/dist/token-goat-chunk-YARZFCZS.mjs +359 -0
- package/dist/{token-goat-chunk-EEIDFMEM.mjs → token-goat-chunk-YZAAZU2S.mjs} +12 -3
- package/dist/{token-goat-chunk-E3K3BTEQ.mjs → token-goat-chunk-Z44YO3QZ.mjs} +12 -6
- package/dist/token-goat-chunk-Z57YODA2.mjs +35 -0
- package/dist/{token-goat-chunk-DA43OE7L.mjs → token-goat-chunk-ZCDTCVIS.mjs} +49 -30
- package/dist/token-goat-chunk-ZEJVMUQH.mjs +48 -0
- package/dist/{token-goat-chunk-BGHSSJUA.mjs → token-goat-chunk-ZFOBKUWH.mjs} +1 -1
- package/dist/token-goat-chunk-ZMBL6UVV.mjs +110 -0
- package/dist/{token-goat-chunk-SJEKA7Y2.mjs → token-goat-chunk-ZQSJMO2R.mjs} +381 -201
- package/dist/token-goat-hook-client.cjs +539 -0
- package/dist/token-goat-hook-client.mjs +26 -0
- package/dist/token-goat-hook.mjs +48 -28
- package/dist/token-goat.core.mjs +10 -45
- package/docs/C4_RUNTIME_ARCHITECTURE.md +3 -3
- package/docs/cli.md +82 -47
- package/docs/install.md +58 -23
- package/docs/security.md +7 -7
- package/package.json +17 -7
- package/scripts/verify-native-dist.mjs +386 -0
- package/dist/token-goat-chunk-4JJBFT7V.mjs +0 -20
- package/dist/token-goat-chunk-5NNYIUGV.mjs +0 -143
- package/dist/token-goat-chunk-6DQNNFJ6.mjs +0 -294
- package/dist/token-goat-chunk-7MAFDRVR.mjs +0 -47
- package/dist/token-goat-chunk-BCN2YQC6.mjs +0 -32
- package/dist/token-goat-chunk-D7GHQKQD.mjs +0 -30
- package/dist/token-goat-chunk-GMOUBOX4.mjs +0 -386
- package/dist/token-goat-chunk-IFORDBGC.mjs +0 -192
- package/dist/token-goat-chunk-JXK2HQXS.mjs +0 -318
- package/dist/token-goat-chunk-L7SDVGBT.mjs +0 -430
- package/dist/token-goat-chunk-MMLMALWK.mjs +0 -1381
- package/dist/token-goat-chunk-MVSWBNMD.mjs +0 -1985
|
@@ -6,14 +6,20 @@ import {
|
|
|
6
6
|
pptxOutline,
|
|
7
7
|
pptxSlideText,
|
|
8
8
|
pptxTextGrep
|
|
9
|
-
} from "./token-goat-chunk-
|
|
10
|
-
import "./token-goat-chunk-
|
|
9
|
+
} from "./token-goat-chunk-JDHE26RP.mjs";
|
|
10
|
+
import "./token-goat-chunk-4FVIAHSI.mjs";
|
|
11
|
+
import "./token-goat-chunk-7IN2MKDS.mjs";
|
|
12
|
+
import "./token-goat-chunk-U4N3BN2W.mjs";
|
|
13
|
+
import "./token-goat-chunk-YZAAZU2S.mjs";
|
|
14
|
+
import "./token-goat-chunk-IVE6U7KV.mjs";
|
|
15
|
+
import "./token-goat-chunk-IVKIZWAB.mjs";
|
|
11
16
|
import "./token-goat-chunk-XTQAOTSO.mjs";
|
|
12
17
|
import "./token-goat-chunk-AH6QILZM.mjs";
|
|
13
|
-
import "./token-goat-chunk-L45ZQRT7.mjs";
|
|
14
|
-
import "./token-goat-chunk-NMTKNYGF.mjs";
|
|
15
18
|
import "./token-goat-chunk-Y4AFKTHK.mjs";
|
|
16
|
-
import "./token-goat-chunk-
|
|
19
|
+
import "./token-goat-chunk-GOLEOXZP.mjs";
|
|
20
|
+
import "./token-goat-chunk-AM5V6GSX.mjs";
|
|
21
|
+
import "./token-goat-chunk-FNFBKLRD.mjs";
|
|
22
|
+
import "./token-goat-chunk-VES7EL7O.mjs";
|
|
17
23
|
import "./token-goat-chunk-A37V4PBF.mjs";
|
|
18
24
|
export {
|
|
19
25
|
pptxAllSlidesText,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
init_define_import_meta_env();
|
|
9
9
|
import * as fs from "node:fs";
|
|
10
10
|
import { createRequire } from "node:module";
|
|
11
|
+
import { pathToFileURL } from "node:url";
|
|
11
12
|
var _require = createRequire(import.meta.url);
|
|
12
13
|
function suppressSqliteExperimentalWarning() {
|
|
13
14
|
const original = process.emit;
|
|
@@ -162,18 +163,7 @@ var Statement = class {
|
|
|
162
163
|
get source() {
|
|
163
164
|
return this.#stmt.sourceSQL;
|
|
164
165
|
}
|
|
165
|
-
/**
|
|
166
|
-
* better-sqlite3's `reader` flag: does this statement return rows?
|
|
167
|
-
*
|
|
168
|
-
* `node:sqlite` has no equivalent, so it is derived from the prepared statement's own column
|
|
169
|
-
* count -- SQLite gives a row-producing statement its result columns at prepare time and gives a
|
|
170
|
-
* non-producing one none. That is a derivation, and this is the third defence-in-depth layer in
|
|
171
|
-
* `sqlite_query.ts`'s read-only guard, so it is not taken on faith: the driver tests run both
|
|
172
|
-
* libraries side by side over SELECT, a CTE, VALUES, EXPLAIN, an empty-result SELECT, INSERT,
|
|
173
|
-
* UPDATE, DELETE, CREATE, a reading PRAGMA and an assigning PRAGMA, and require every verdict to
|
|
174
|
-
* agree. If a future SQLite statement form ever breaks the equivalence, that test fails rather
|
|
175
|
-
* than the guard quietly weakening.
|
|
176
|
-
*/
|
|
166
|
+
/** better-sqlite3's `reader` flag: does this statement return rows? `node:sqlite` has no equivalent, so it is derived from the prepared statement's own column count -- SQLite gives a row-producing statement its result columns at prepare time and gives a non-producing one none. That is a derivation, and this is the third defence-in-depth layer in `sqlite_query.ts`'s read-only guard, so it is not taken on faith: the driver tests run both libraries side by side over SELECT, a CTE, VALUES, EXPLAIN, an empty-result SELECT, INSERT, UPDATE, DELETE, CREATE, a reading PRAGMA and an assigning PRAGMA, and require every verdict to agree. If a future SQLite statement form ever breaks the equivalence, that test fails rather than the guard quietly weakening. */
|
|
177
167
|
get reader() {
|
|
178
168
|
return attempt(() => this.#stmt.columns()).length > 0;
|
|
179
169
|
}
|
|
@@ -224,7 +214,8 @@ var Database = class {
|
|
|
224
214
|
if (wantsExisting && dbPath !== ":memory:" && !fs.existsSync(dbPath)) {
|
|
225
215
|
throw new Error("unable to open database file");
|
|
226
216
|
}
|
|
227
|
-
|
|
217
|
+
const target = options.immutable === true ? `${pathToFileURL(dbPath).href}?immutable=1` : dbPath;
|
|
218
|
+
this.#db = attempt(() => new DatabaseSync(target, {
|
|
228
219
|
readOnly: options.readonly === true,
|
|
229
220
|
// sqlite-vec is loaded through db.loadExtension by initConnection, which node:sqlite refuses unless the connection opted in at construction. Harmless when no extension is ever loaded.
|
|
230
221
|
allowExtension: true,
|
|
@@ -269,18 +260,7 @@ var Database = class {
|
|
|
269
260
|
close() {
|
|
270
261
|
attempt(() => this.#db.close());
|
|
271
262
|
}
|
|
272
|
-
/**
|
|
273
|
-
* Wrap `fn` so it runs inside a transaction, committing on return and rolling back on throw.
|
|
274
|
-
*
|
|
275
|
-
* Nesting uses SAVEPOINT, which is what makes it safe for a transactional helper to call another
|
|
276
|
-
* one: an inner `BEGIN` would throw ("cannot start a transaction within a transaction"), an inner
|
|
277
|
-
* SAVEPOINT composes. Whether we are nested is read from SQLite via `isTransaction` rather than
|
|
278
|
-
* tracked in a counter here, so a transaction some other code path opened still nests correctly.
|
|
279
|
-
*
|
|
280
|
-
* The rollback is best-effort and never replaces the caller's error: if the ROLLBACK itself fails
|
|
281
|
-
* -- the connection died, the transaction was already unwound -- the original failure is still
|
|
282
|
-
* what propagates, because that is the one that explains what went wrong.
|
|
283
|
-
*/
|
|
263
|
+
/** Wrap `fn` so it runs inside a transaction, committing on return and rolling back on throw. Nesting uses SAVEPOINT, which is what makes it safe for a transactional helper to call another one: an inner `BEGIN` would throw ("cannot start a transaction within a transaction"), an inner SAVEPOINT composes. Whether we are nested is read from SQLite via `isTransaction` rather than tracked in a counter here, so a transaction some other code path opened still nests correctly. The rollback is best-effort and never replaces the caller's error: if the ROLLBACK itself fails -- the connection died, the transaction was already unwound -- the original failure is still what propagates, because that is the one that explains what went wrong. */
|
|
284
264
|
transaction(fn) {
|
|
285
265
|
const build = (beginSql) => (...args) => {
|
|
286
266
|
if (this.#db.isTransaction) {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
+
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
init_define_import_meta_env
|
|
5
|
+
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
6
|
+
|
|
7
|
+
// src/jsonc_text.ts
|
|
8
|
+
init_define_import_meta_env();
|
|
9
|
+
import { createRequire } from "node:module";
|
|
10
|
+
var jsoncParser;
|
|
11
|
+
function jsonc() {
|
|
12
|
+
jsoncParser ??= createRequire(import.meta.url)("jsonc-parser");
|
|
13
|
+
return jsoncParser;
|
|
14
|
+
}
|
|
15
|
+
var CLOSE_BRACE = 2;
|
|
16
|
+
var CLOSE_BRACKET = 4;
|
|
17
|
+
var COMMA = 5;
|
|
18
|
+
var LINE_COMMENT = 12;
|
|
19
|
+
var BLOCK_COMMENT = 13;
|
|
20
|
+
var LINE_BREAK = 14;
|
|
21
|
+
var WHITESPACE = 15;
|
|
22
|
+
var EOF = 17;
|
|
23
|
+
function jsoncToJson(text) {
|
|
24
|
+
const scanner = jsonc().createScanner(text, false);
|
|
25
|
+
const out = [];
|
|
26
|
+
let heldComma = false;
|
|
27
|
+
let heldTrivia = [];
|
|
28
|
+
for (let kind = scanner.scan(); kind !== EOF; kind = scanner.scan()) {
|
|
29
|
+
if (kind === LINE_COMMENT || kind === BLOCK_COMMENT) continue;
|
|
30
|
+
const raw = text.slice(scanner.getTokenOffset(), scanner.getTokenOffset() + scanner.getTokenLength());
|
|
31
|
+
if (heldComma) {
|
|
32
|
+
if (kind === LINE_BREAK || kind === WHITESPACE) {
|
|
33
|
+
heldTrivia.push(raw);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (kind !== CLOSE_BRACE && kind !== CLOSE_BRACKET) out.push(",");
|
|
37
|
+
out.push(...heldTrivia);
|
|
38
|
+
heldComma = false;
|
|
39
|
+
heldTrivia = [];
|
|
40
|
+
}
|
|
41
|
+
if (kind === COMMA) heldComma = true;
|
|
42
|
+
else out.push(raw);
|
|
43
|
+
}
|
|
44
|
+
if (heldComma) out.push(",", ...heldTrivia);
|
|
45
|
+
return out.join("");
|
|
46
|
+
}
|
|
47
|
+
function stripBom(text) {
|
|
48
|
+
return text.charCodeAt(0) === 65279 ? text.slice(1) : text;
|
|
49
|
+
}
|
|
50
|
+
function parseJsonOrJsonc(raw, opts = {}) {
|
|
51
|
+
const text = stripBom(raw);
|
|
52
|
+
try {
|
|
53
|
+
return JSON.parse(text);
|
|
54
|
+
} catch (strictError) {
|
|
55
|
+
const errors = [];
|
|
56
|
+
jsonc().parse(text, errors, { allowTrailingComma: opts.allowTrailingComma !== false, disallowComments: false, allowEmptyContent: false });
|
|
57
|
+
if (errors.length > 0) throw strictError;
|
|
58
|
+
return JSON.parse(jsoncToJson(text));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export {
|
|
63
|
+
jsonc,
|
|
64
|
+
stripBom,
|
|
65
|
+
parseJsonOrJsonc
|
|
66
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
+
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
BRIDGE_CAPABILITY_MATRIX
|
|
5
|
+
} from "./token-goat-chunk-ETBHVDB6.mjs";
|
|
6
|
+
import {
|
|
7
|
+
PROBE_EVENT_TAGS,
|
|
8
|
+
PROBE_NONCE_ENV,
|
|
9
|
+
probeDir
|
|
10
|
+
} from "./token-goat-chunk-ZEJVMUQH.mjs";
|
|
11
|
+
import "./token-goat-chunk-KKUFXAPD.mjs";
|
|
12
|
+
import {
|
|
13
|
+
HOOK_PROBE_ENV
|
|
14
|
+
} from "./token-goat-chunk-3Z5S4KGM.mjs";
|
|
15
|
+
import "./token-goat-chunk-VL3YIFHZ.mjs";
|
|
16
|
+
import "./token-goat-chunk-XB5KKOCG.mjs";
|
|
17
|
+
import "./token-goat-chunk-U4N3BN2W.mjs";
|
|
18
|
+
import "./token-goat-chunk-YZAAZU2S.mjs";
|
|
19
|
+
import "./token-goat-chunk-GOLEOXZP.mjs";
|
|
20
|
+
import {
|
|
21
|
+
resolveOnPath,
|
|
22
|
+
spawnResolvedSync
|
|
23
|
+
} from "./token-goat-chunk-AM5V6GSX.mjs";
|
|
24
|
+
import {
|
|
25
|
+
displaySafeText
|
|
26
|
+
} from "./token-goat-chunk-FNFBKLRD.mjs";
|
|
27
|
+
import "./token-goat-chunk-VES7EL7O.mjs";
|
|
28
|
+
import {
|
|
29
|
+
init_define_import_meta_env
|
|
30
|
+
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
31
|
+
|
|
32
|
+
// src/doctor_probe.ts
|
|
33
|
+
init_define_import_meta_env();
|
|
34
|
+
import { randomBytes } from "node:crypto";
|
|
35
|
+
import { readdirSync, rmSync } from "node:fs";
|
|
36
|
+
import path from "node:path";
|
|
37
|
+
var PROBE_PROMPT = "Reply with every line of your context that begins with token-goat probe marker, copied exactly, one per line. If there are none, reply NONE.";
|
|
38
|
+
var PROBE_COMMANDS = {
|
|
39
|
+
claudecode: { bin: "claude", args: ["-p", PROBE_PROMPT] },
|
|
40
|
+
codex: { bin: "codex", args: ["exec", PROBE_PROMPT] },
|
|
41
|
+
copilot_cli: { bin: "copilot", args: ["-p", PROBE_PROMPT] }
|
|
42
|
+
};
|
|
43
|
+
function isProbeHarness(name) {
|
|
44
|
+
return Object.prototype.hasOwnProperty.call(PROBE_COMMANDS, name);
|
|
45
|
+
}
|
|
46
|
+
var MISLEADING_ENV = ["TOKEN_GOAT_HARNESS_OVERRIDE", "CLAUDE_CODE_SESSION_ID", "CLAUDE_CODE_VERSION", "CLAUDE_CODE_ENTRYPOINT", "CLAUDECODE", "CODEX_SESSION_ID", "CODEX_SESSION"];
|
|
47
|
+
var PROBE_TIMEOUT_MS = 24e4;
|
|
48
|
+
function classifyProbeEvent(opts) {
|
|
49
|
+
if (!opts.wired) return "not_wired";
|
|
50
|
+
if (opts.stdout.includes(`${opts.nonce}-${opts.tag}`)) return "reached";
|
|
51
|
+
return opts.receipts.has(opts.tag) ? "fired_not_delivered" : "not_fired";
|
|
52
|
+
}
|
|
53
|
+
function probeEnv(nonce, env = process.env) {
|
|
54
|
+
const child = { ...env };
|
|
55
|
+
for (const key of MISLEADING_ENV) delete child[key];
|
|
56
|
+
if (child["TERM_PROGRAM"] === "claude-code") delete child["TERM_PROGRAM"];
|
|
57
|
+
child[PROBE_NONCE_ENV] = nonce;
|
|
58
|
+
child[HOOK_PROBE_ENV] = "1";
|
|
59
|
+
return child;
|
|
60
|
+
}
|
|
61
|
+
function receiptTags(nonce) {
|
|
62
|
+
const tags = /* @__PURE__ */ new Set();
|
|
63
|
+
try {
|
|
64
|
+
for (const name of readdirSync(probeDir())) {
|
|
65
|
+
if (name.startsWith(`${nonce}.`)) tags.add(name.slice(nonce.length + 1));
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
return tags;
|
|
70
|
+
}
|
|
71
|
+
function removeReceipts(nonce) {
|
|
72
|
+
for (const tag of receiptTags(nonce)) rmSync(path.join(probeDir(), `${nonce}.${tag}`), { force: true });
|
|
73
|
+
}
|
|
74
|
+
function tail(text) {
|
|
75
|
+
return text.trim().split(/\r?\n/).slice(-5).join("\n");
|
|
76
|
+
}
|
|
77
|
+
function runProbe(harness, opts = {}) {
|
|
78
|
+
const spec = PROBE_COMMANDS[harness];
|
|
79
|
+
if (spec === void 0) throw new Error(`no headless probe for ${harness}; supported: ${Object.keys(PROBE_COMMANDS).join(", ")}`);
|
|
80
|
+
const command = `${spec.bin} ${spec.args[0] ?? ""} "<probe prompt>"`;
|
|
81
|
+
const implemented = BRIDGE_CAPABILITY_MATRIX.find((r) => r.harness === harness)?.implemented ?? /* @__PURE__ */ new Set();
|
|
82
|
+
const probed = Object.keys(PROBE_EVENT_TAGS);
|
|
83
|
+
const resolved = (opts.resolve ?? resolveOnPath)(spec.bin);
|
|
84
|
+
if (resolved === null) {
|
|
85
|
+
return { harness, command, status: "not_installed", exitCode: null, events: probed.map((event) => ({ event, result: implemented.has(event) ? "not_fired" : "not_wired" })) };
|
|
86
|
+
}
|
|
87
|
+
const nonce = randomBytes(10).toString("hex");
|
|
88
|
+
try {
|
|
89
|
+
const run = spawnResolvedSync(resolved, spec.args, { cwd: opts.cwd ?? process.cwd(), env: probeEnv(nonce), encoding: "utf8", timeout: opts.timeoutMs ?? PROBE_TIMEOUT_MS, windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
|
|
90
|
+
const stdout = run.stdout ?? "";
|
|
91
|
+
const receipts = receiptTags(nonce);
|
|
92
|
+
const events = probed.map((event) => ({ event, result: classifyProbeEvent({ wired: implemented.has(event), nonce, tag: PROBE_EVENT_TAGS[event] ?? "", stdout, receipts }) }));
|
|
93
|
+
const timedOut = run.error?.code === "ETIMEDOUT";
|
|
94
|
+
const status = timedOut ? "timeout" : run.status === 0 ? "ok" : "failed";
|
|
95
|
+
const report = { harness, command, status, exitCode: run.status, events };
|
|
96
|
+
return status === "ok" ? report : { ...report, detail: tail(run.stderr ?? run.error?.message ?? "") };
|
|
97
|
+
} finally {
|
|
98
|
+
removeReceipts(nonce);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
var RESULT_TEXT = {
|
|
102
|
+
reached: "reached the model",
|
|
103
|
+
fired_not_delivered: "hook ran, but the model never saw its output",
|
|
104
|
+
not_fired: "hook did not run",
|
|
105
|
+
not_wired: "not wired for this harness"
|
|
106
|
+
};
|
|
107
|
+
function probePassed(report) {
|
|
108
|
+
return report.status === "ok" && report.events.every((e) => e.result === "reached" || e.result === "not_wired");
|
|
109
|
+
}
|
|
110
|
+
function formatProbeReport(report) {
|
|
111
|
+
const lines = [`Probe: ${report.command} (one real prompt on your account)`];
|
|
112
|
+
if (report.status === "not_installed") lines.push(` [FAIL] ${PROBE_COMMANDS[report.harness]?.bin ?? report.harness} is not on PATH`);
|
|
113
|
+
else if (report.status === "timeout") lines.push(" [FAIL] the harness did not finish in time");
|
|
114
|
+
else if (report.status === "failed") lines.push(` [FAIL] the harness exited with code ${report.exitCode ?? "unknown"}`);
|
|
115
|
+
if (report.status !== "not_installed") {
|
|
116
|
+
for (const e of report.events) {
|
|
117
|
+
const mark = e.result === "reached" ? "[OK] " : e.result === "not_wired" ? "[--] " : "[FAIL]";
|
|
118
|
+
lines.push(` ${mark} ${e.event.padEnd(19)} ${RESULT_TEXT[e.result]}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (report.detail !== void 0 && report.detail !== "") lines.push(...displaySafeText(report.detail).split("\n").map((l) => ` ${l}`));
|
|
122
|
+
return lines.join("\n");
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
PROBE_COMMANDS,
|
|
126
|
+
PROBE_PROMPT,
|
|
127
|
+
classifyProbeEvent,
|
|
128
|
+
formatProbeReport,
|
|
129
|
+
isProbeHarness,
|
|
130
|
+
probeEnv,
|
|
131
|
+
probePassed,
|
|
132
|
+
runProbe
|
|
133
|
+
};
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
2
|
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
readTranscriptTail
|
|
5
|
+
} from "./token-goat-chunk-SJHWVNDQ.mjs";
|
|
6
|
+
import {
|
|
7
|
+
claudeConfigDir
|
|
8
|
+
} from "./token-goat-chunk-BPGCUMR7.mjs";
|
|
3
9
|
import {
|
|
4
10
|
GENERIC_SERVED_OUTPUT_KEY,
|
|
11
|
+
MAX_BASH_START_CWDS,
|
|
5
12
|
MAX_GENERIC_SERVED_OUTPUTS,
|
|
6
13
|
MAX_OUTSTANDING_AGENT_SPAWNS,
|
|
7
14
|
MAX_RANGES_PER_FILE,
|
|
8
15
|
MAX_SEEN_IMAGE_HASHES,
|
|
9
16
|
MAX_SERVED_OUTPUTS_PER_FILE,
|
|
17
|
+
bashStartCwdsAtLoad,
|
|
18
|
+
consumedBashStartCwdKeys,
|
|
10
19
|
consumedCurlDownloadKeys,
|
|
11
20
|
consumedFileLineRangeKeys,
|
|
12
21
|
consumedFileServedOutputKeys,
|
|
@@ -17,49 +26,56 @@ import {
|
|
|
17
26
|
filesFullReadCountAtLoad,
|
|
18
27
|
filesReadCountAtLoad,
|
|
19
28
|
importSessionState,
|
|
29
|
+
markCompacted,
|
|
20
30
|
migrateCurlDownloadKey,
|
|
21
31
|
migrateWebFetchKey,
|
|
22
32
|
outstandingAgentSpawnKey,
|
|
23
33
|
outstandingAgentSpawnsAtLoad,
|
|
24
34
|
pendingLargeFileHintsAtLoad
|
|
25
|
-
} from "./token-goat-chunk-
|
|
26
|
-
import {
|
|
27
|
-
claudeConfigDir,
|
|
28
|
-
readTranscriptTail
|
|
29
|
-
} from "./token-goat-chunk-MAMQPC43.mjs";
|
|
35
|
+
} from "./token-goat-chunk-C63JQV5K.mjs";
|
|
30
36
|
import {
|
|
31
37
|
DEFAULT_MAX_AGE_MS,
|
|
32
38
|
DEFAULT_MAX_COUNT
|
|
33
|
-
} from "./token-goat-chunk-
|
|
39
|
+
} from "./token-goat-chunk-ARDNEC2U.mjs";
|
|
40
|
+
import {
|
|
41
|
+
recordStat
|
|
42
|
+
} from "./token-goat-chunk-3Z5S4KGM.mjs";
|
|
34
43
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} from "./token-goat-chunk-
|
|
44
|
+
redactSecrets,
|
|
45
|
+
redactSerializedJson
|
|
46
|
+
} from "./token-goat-chunk-4FVIAHSI.mjs";
|
|
38
47
|
import {
|
|
39
|
-
detectHarness,
|
|
40
48
|
isAutoTriggerMultiplierExplicit,
|
|
41
49
|
loadConfig,
|
|
42
50
|
shortFingerprint
|
|
43
|
-
} from "./token-goat-chunk-
|
|
51
|
+
} from "./token-goat-chunk-7IN2MKDS.mjs";
|
|
52
|
+
import {
|
|
53
|
+
detectHarness
|
|
54
|
+
} from "./token-goat-chunk-U4N3BN2W.mjs";
|
|
44
55
|
import {
|
|
45
56
|
registerReset
|
|
46
|
-
} from "./token-goat-chunk-
|
|
57
|
+
} from "./token-goat-chunk-YZAAZU2S.mjs";
|
|
47
58
|
import {
|
|
48
59
|
LOCK_WAIT_MS_HARDENED,
|
|
49
60
|
atomicWriteText,
|
|
50
|
-
dataDir,
|
|
51
61
|
ensureDirSync,
|
|
52
|
-
foldPath,
|
|
53
62
|
isCodeFenceDelimiter,
|
|
54
63
|
normalizePathForwardSlash,
|
|
55
64
|
sanitizeIdForFilename,
|
|
56
65
|
stripLower,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
} from "./token-goat-chunk-
|
|
66
|
+
withFileLock,
|
|
67
|
+
withRetryOnLock
|
|
68
|
+
} from "./token-goat-chunk-GOLEOXZP.mjs";
|
|
69
|
+
import {
|
|
70
|
+
foldPath
|
|
71
|
+
} from "./token-goat-chunk-AM5V6GSX.mjs";
|
|
60
72
|
import {
|
|
61
73
|
normalizePath
|
|
62
|
-
} from "./token-goat-chunk-
|
|
74
|
+
} from "./token-goat-chunk-FNFBKLRD.mjs";
|
|
75
|
+
import {
|
|
76
|
+
dataDir,
|
|
77
|
+
tokenGoatHome
|
|
78
|
+
} from "./token-goat-chunk-VES7EL7O.mjs";
|
|
63
79
|
import {
|
|
64
80
|
init_define_import_meta_env
|
|
65
81
|
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
@@ -234,6 +250,7 @@ function coerce(raw) {
|
|
|
234
250
|
cliReads,
|
|
235
251
|
bashReruns,
|
|
236
252
|
pendingLargeFileHints,
|
|
253
|
+
bashStartCwds: asStringPairs(o["bashStartCwds"]),
|
|
237
254
|
grepQueries,
|
|
238
255
|
globQueries,
|
|
239
256
|
outstandingAgentSpawns,
|
|
@@ -325,6 +342,17 @@ function mergeCurlDownloads(disk, mem) {
|
|
|
325
342
|
}
|
|
326
343
|
return Array.from(merged.entries());
|
|
327
344
|
}
|
|
345
|
+
function mergeBashStartCwds(disk, mem) {
|
|
346
|
+
const merged = new Map(disk);
|
|
347
|
+
for (const key of consumedBashStartCwdKeys()) merged.delete(key);
|
|
348
|
+
const atLoad = bashStartCwdsAtLoad();
|
|
349
|
+
for (const [toolUseId, cwd] of mem) {
|
|
350
|
+
if (atLoad.get(toolUseId) === cwd) continue;
|
|
351
|
+
merged.set(toolUseId, cwd);
|
|
352
|
+
}
|
|
353
|
+
const entries = Array.from(merged.entries());
|
|
354
|
+
return entries.length > MAX_BASH_START_CWDS ? entries.slice(entries.length - MAX_BASH_START_CWDS) : entries;
|
|
355
|
+
}
|
|
328
356
|
function mergeOutstandingAgentSpawns(disk, mem) {
|
|
329
357
|
const merged = new Map(disk.map(([prompt, ts]) => [outstandingAgentSpawnKey(prompt, ts), [prompt, ts]]));
|
|
330
358
|
for (const key of consumedOutstandingAgentSpawnKeys()) merged.delete(key);
|
|
@@ -353,6 +381,8 @@ function mergeSessionState(disk, mem) {
|
|
|
353
381
|
const memRanges = (mem.compactedAt ?? 0) === compactedAt ? mem.fileLineRanges ?? [] : [];
|
|
354
382
|
const rawDiskServed = (disk.compactedAt ?? 0) === compactedAt ? disk.fileServedOutputs ?? [] : [];
|
|
355
383
|
const memServed = (mem.compactedAt ?? 0) === compactedAt ? mem.fileServedOutputs ?? [] : [];
|
|
384
|
+
const rawDiskCliReads = (disk.compactedAt ?? 0) === compactedAt ? disk.cliReads ?? [] : [];
|
|
385
|
+
const memCliReads = (mem.compactedAt ?? 0) === compactedAt ? mem.cliReads ?? [] : [];
|
|
356
386
|
const clearedRangeFiles = new Set(consumedFileLineRangeKeys());
|
|
357
387
|
const clearedServedFiles = new Set(consumedFileServedOutputKeys());
|
|
358
388
|
const diskRanges = rawDiskRanges.filter(([path4]) => !clearedRangeFiles.has(path4));
|
|
@@ -367,9 +397,11 @@ function mergeSessionState(disk, mem) {
|
|
|
367
397
|
fileLineRanges: mergeLineRanges(diskRanges, memRanges),
|
|
368
398
|
fileServedOutputs: mergeServedOutputs(diskServed, memServed),
|
|
369
399
|
...compactedAt > 0 ? { compactedAt } : {},
|
|
370
|
-
|
|
400
|
+
// Same epoch filter as the line ranges above: a CLI read recorded before the winning compaction is not in the model's context any more, so merging it back would resurrect the "you already ran this" note the compaction just cleared.
|
|
401
|
+
cliReads: Array.from(/* @__PURE__ */ new Set([...rawDiskCliReads, ...memCliReads])),
|
|
371
402
|
bashReruns: Array.from(/* @__PURE__ */ new Set([...disk.bashReruns ?? [], ...mem.bashReruns ?? []])),
|
|
372
403
|
pendingLargeFileHints: mergePendingLargeFileHints(disk.pendingLargeFileHints ?? [], mem.pendingLargeFileHints ?? []),
|
|
404
|
+
bashStartCwds: mergeBashStartCwds(disk.bashStartCwds ?? [], mem.bashStartCwds ?? []),
|
|
373
405
|
grepQueries: mergePairs(disk.grepQueries ?? [], mem.grepQueries ?? []),
|
|
374
406
|
globQueries: mergePairs(disk.globQueries ?? [], mem.globQueries ?? []),
|
|
375
407
|
outstandingAgentSpawns: mergeOutstandingAgentSpawns(disk.outstandingAgentSpawns ?? [], mem.outstandingAgentSpawns ?? []),
|
|
@@ -392,8 +424,23 @@ function capFiles(s, max) {
|
|
|
392
424
|
}
|
|
393
425
|
function readDiskState(p) {
|
|
394
426
|
try {
|
|
395
|
-
|
|
396
|
-
|
|
427
|
+
return readDiskStateForMerge(p);
|
|
428
|
+
} catch {
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
function readDiskStateForMerge(p) {
|
|
433
|
+
let text = "";
|
|
434
|
+
try {
|
|
435
|
+
withRetryOnLock(() => {
|
|
436
|
+
text = fs.readFileSync(p, "utf8");
|
|
437
|
+
});
|
|
438
|
+
} catch (err) {
|
|
439
|
+
if (err.code === "ENOENT") return null;
|
|
440
|
+
throw err;
|
|
441
|
+
}
|
|
442
|
+
try {
|
|
443
|
+
return coerce(JSON.parse(text));
|
|
397
444
|
} catch {
|
|
398
445
|
return null;
|
|
399
446
|
}
|
|
@@ -424,8 +471,20 @@ function listSiblingSessionStates(sessionId) {
|
|
|
424
471
|
var EMPTY_SESSION = { files: [], hintsShown: [], webFetches: [], bashOutputs: [], curlDownloads: [] };
|
|
425
472
|
function loadSessionState(sessionId) {
|
|
426
473
|
const p = sessionPath(sessionId);
|
|
474
|
+
importSessionState((p ? readDiskState(p) : null) ?? EMPTY_SESSION);
|
|
475
|
+
applySessionCompaction(sessionId);
|
|
476
|
+
}
|
|
477
|
+
var COMPACTED_AT_SUFFIX = ".compacted-at";
|
|
478
|
+
function applySessionCompaction(stateKey) {
|
|
479
|
+
const at = stateKey.indexOf(":agent:");
|
|
480
|
+
if (at < 0) return;
|
|
481
|
+
const p = sessionSidecarPath(stateKey.slice(0, at), COMPACTED_AT_SUFFIX);
|
|
427
482
|
if (!p) return;
|
|
428
|
-
|
|
483
|
+
try {
|
|
484
|
+
const epoch = Number(fs.readFileSync(p, "utf8").trim());
|
|
485
|
+
if (Number.isFinite(epoch) && epoch > 0) markCompacted(epoch);
|
|
486
|
+
} catch {
|
|
487
|
+
}
|
|
429
488
|
}
|
|
430
489
|
function saveSessionState(sessionId) {
|
|
431
490
|
const p = sessionPath(sessionId);
|
|
@@ -435,12 +494,12 @@ function saveSessionState(sessionId) {
|
|
|
435
494
|
if (!fs.existsSync(dir)) ensureDirSync(dir);
|
|
436
495
|
const mem = exportSessionState();
|
|
437
496
|
const writeMerged = () => {
|
|
438
|
-
const disk =
|
|
497
|
+
const disk = readDiskStateForMerge(p);
|
|
439
498
|
const merged = capFiles(disk ? mergeSessionState(disk, mem) : mem, MAX_FILES);
|
|
440
499
|
if (merged.created_ts === void 0) merged.created_ts = Date.now() / 1e3;
|
|
441
500
|
let json;
|
|
442
501
|
try {
|
|
443
|
-
json =
|
|
502
|
+
json = redactSerializedJson(JSON.stringify(merged)).text;
|
|
444
503
|
} catch {
|
|
445
504
|
return true;
|
|
446
505
|
}
|
|
@@ -510,6 +569,36 @@ function sessionSkillPrefix(sessionId, skillName) {
|
|
|
510
569
|
function outputIdFor(sessionId, skillName, contentSha) {
|
|
511
570
|
return `${sessionSkillPrefix(sessionId, skillName)}${contentSha}`;
|
|
512
571
|
}
|
|
572
|
+
var LOAD_RECORD_EXT = ".load";
|
|
573
|
+
function readLoadRecordsSync(dir) {
|
|
574
|
+
const records = [];
|
|
575
|
+
let files;
|
|
576
|
+
try {
|
|
577
|
+
files = readdirSync2(dir);
|
|
578
|
+
} catch {
|
|
579
|
+
return records;
|
|
580
|
+
}
|
|
581
|
+
for (const file of files) {
|
|
582
|
+
if (!file.endsWith(LOAD_RECORD_EXT)) continue;
|
|
583
|
+
try {
|
|
584
|
+
const parsed = JSON.parse(readFileSync2(resolve(dir, file), "utf-8"));
|
|
585
|
+
if (typeof parsed.skillName !== "string" || typeof parsed.bodyOutputId !== "string") continue;
|
|
586
|
+
records.push({ ...parsed, loadId: file.slice(0, -LOAD_RECORD_EXT.length) });
|
|
587
|
+
} catch {
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return records;
|
|
592
|
+
}
|
|
593
|
+
async function sessionLoads(safeSession, name) {
|
|
594
|
+
const metas = await listOutputs();
|
|
595
|
+
const own = metas.filter((m) => m.skillName === name && m.outputId.startsWith(`${safeSession}-`));
|
|
596
|
+
const storedIds = new Set(metas.map((m) => m.outputId));
|
|
597
|
+
const recorded = readLoadRecordsSync(skillOutputsDir()).filter(
|
|
598
|
+
(r) => r.skillName === name && r.loadId.startsWith(`${safeSession}-`) && storedIds.has(r.bodyOutputId)
|
|
599
|
+
);
|
|
600
|
+
return [...own, ...recorded].map((e) => ({ bodyBytes: e.bodyBytes, ts: e.ts }));
|
|
601
|
+
}
|
|
513
602
|
function* contentLineEntries(lines) {
|
|
514
603
|
let inCodeBlock = false;
|
|
515
604
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -645,9 +734,7 @@ async function hasSessionOutput(sessionId, skillName) {
|
|
|
645
734
|
if (!sessionId) return false;
|
|
646
735
|
const name = safeSkillName(skillName);
|
|
647
736
|
if (!name) return false;
|
|
648
|
-
|
|
649
|
-
const metas = await listOutputs();
|
|
650
|
-
return metas.some((m) => m.skillName === name && m.outputId.startsWith(`${safeSession}-`));
|
|
737
|
+
return (await sessionLoads(safeSessionFragment(sessionId), name)).length > 0;
|
|
651
738
|
} catch {
|
|
652
739
|
return false;
|
|
653
740
|
}
|
|
@@ -657,9 +744,7 @@ async function sessionOutputBodyBytes(sessionId, skillName) {
|
|
|
657
744
|
if (!sessionId) return null;
|
|
658
745
|
const name = safeSkillName(skillName);
|
|
659
746
|
if (!name) return null;
|
|
660
|
-
const
|
|
661
|
-
const metas = await listOutputs();
|
|
662
|
-
const matches = metas.filter((m) => m.skillName === name && m.outputId.startsWith(`${safeSession}-`));
|
|
747
|
+
const matches = await sessionLoads(safeSessionFragment(sessionId), name);
|
|
663
748
|
if (matches.length === 0) return null;
|
|
664
749
|
matches.sort((a, b) => b.ts - a.ts);
|
|
665
750
|
return matches[0].bodyBytes;
|
|
@@ -698,13 +783,23 @@ async function storeOutput(sessionId, skillName, body, opts) {
|
|
|
698
783
|
const name = safeSkillName(skillName);
|
|
699
784
|
if (!name) return null;
|
|
700
785
|
const sha = contentHash(body);
|
|
786
|
+
const outId = outputIdFor(sessionId, skillName, sha);
|
|
787
|
+
const dir = skillOutputsDir();
|
|
788
|
+
const ts = Date.now();
|
|
701
789
|
const existing = await findCrossSessionEntry(skillName, sha);
|
|
702
790
|
if (existing) {
|
|
791
|
+
if (existing.outputId !== outId && sessionId) {
|
|
792
|
+
const record = {
|
|
793
|
+
skillName: name,
|
|
794
|
+
contentSha: sha,
|
|
795
|
+
bodyOutputId: existing.outputId,
|
|
796
|
+
bodyBytes: Buffer.byteLength(body, "utf-8"),
|
|
797
|
+
ts
|
|
798
|
+
};
|
|
799
|
+
await atomicWriteText(resolve(dir, `${outId}${LOAD_RECORD_EXT}`), JSON.stringify(record, null, 2));
|
|
800
|
+
}
|
|
703
801
|
return existing;
|
|
704
802
|
}
|
|
705
|
-
const outId = outputIdFor(sessionId, skillName, sha);
|
|
706
|
-
const dir = skillOutputsDir();
|
|
707
|
-
const ts = Date.now();
|
|
708
803
|
const bodyBytes = Buffer.byteLength(body, "utf-8");
|
|
709
804
|
const truncated = bodyBytes > 256 * 1024;
|
|
710
805
|
const redactedBody = redactSecrets(body);
|
|
@@ -1054,6 +1149,13 @@ function pruneSkillOutputs(maxCount = DEFAULT_MAX_COUNT, maxAgeMs = DEFAULT_MAX_
|
|
|
1054
1149
|
removeEntry(entry.outputId);
|
|
1055
1150
|
}
|
|
1056
1151
|
}
|
|
1152
|
+
for (const record of readLoadRecordsSync(dir)) {
|
|
1153
|
+
if (record.ts >= cutoff && existsSync2(resolve(dir, `${record.bodyOutputId}.meta`))) continue;
|
|
1154
|
+
try {
|
|
1155
|
+
unlinkSync(resolve(dir, `${record.loadId}${LOAD_RECORD_EXT}`));
|
|
1156
|
+
} catch {
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1057
1159
|
} catch {
|
|
1058
1160
|
return removed;
|
|
1059
1161
|
}
|
|
@@ -1458,8 +1560,10 @@ export {
|
|
|
1458
1560
|
sessionsDir,
|
|
1459
1561
|
AGENT_SALT_MARKER,
|
|
1460
1562
|
sessionSidecarPath,
|
|
1563
|
+
readSessionStateFile,
|
|
1461
1564
|
listSiblingSessionStates,
|
|
1462
1565
|
loadSessionState,
|
|
1566
|
+
COMPACTED_AT_SUFFIX,
|
|
1463
1567
|
saveSessionState,
|
|
1464
1568
|
CONTEXT_AUTOCOMPACT_TOKENS,
|
|
1465
1569
|
getContextPressure,
|
|
@@ -1473,6 +1577,7 @@ export {
|
|
|
1473
1577
|
SKILLS_OUTPUT_SUBDIR,
|
|
1474
1578
|
skillOutputsDir,
|
|
1475
1579
|
contentHash,
|
|
1580
|
+
safeSkillName,
|
|
1476
1581
|
extractCompactFromMarker,
|
|
1477
1582
|
extractNamedSection,
|
|
1478
1583
|
extractChecklistSection,
|