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.
Files changed (134) hide show
  1. package/README.md +36 -40
  2. package/SECURITY.md +28 -10
  3. package/THIRD_PARTY_NOTICES.md +40 -3
  4. package/dist/native/linux-arm64/tg-hook +0 -0
  5. package/dist/native/linux-x64/tg-hook +0 -0
  6. package/dist/ort-wasm-simd-threaded.mjs +59 -0
  7. package/dist/token-goat-chunk-3CHUNJ2O.mjs +53 -0
  8. package/dist/token-goat-chunk-3Z5S4KGM.mjs +918 -0
  9. package/dist/token-goat-chunk-4FVIAHSI.mjs +211 -0
  10. package/dist/{token-goat-chunk-66LODAUT.mjs → token-goat-chunk-4JJS54TR.mjs} +4 -3
  11. package/dist/token-goat-chunk-4LCCNRTG.mjs +313 -0
  12. package/dist/token-goat-chunk-54K3EUV3.mjs +35 -0
  13. package/dist/token-goat-chunk-56EIMS3E.mjs +159 -0
  14. package/dist/token-goat-chunk-5BCIJXMO.mjs +609 -0
  15. package/dist/token-goat-chunk-5KDMCMF2.mjs +362 -0
  16. package/dist/token-goat-chunk-5RG5SBL6.mjs +221 -0
  17. package/dist/{token-goat-chunk-RRNZMM3A.mjs → token-goat-chunk-5Y6ZYL6U.mjs} +21 -2
  18. package/dist/{token-goat-chunk-NILVK7XM.mjs → token-goat-chunk-64FBPDTK.mjs} +12 -6
  19. package/dist/{token-goat-chunk-LEG3JNJ6.mjs → token-goat-chunk-664RTTUV.mjs} +31 -15
  20. package/dist/token-goat-chunk-67TQJ76B.mjs +57 -0
  21. package/dist/token-goat-chunk-6QMAS7AB.mjs +42 -0
  22. package/dist/token-goat-chunk-7BXSNBY5.mjs +253 -0
  23. package/dist/{token-goat-chunk-F7QZRIWM.mjs → token-goat-chunk-7F2UBPD3.mjs} +42 -35
  24. package/dist/{token-goat-chunk-CC2PYJM7.mjs → token-goat-chunk-7IN2MKDS.mjs} +718 -595
  25. package/dist/token-goat-chunk-7NADEDKJ.mjs +124 -0
  26. package/dist/{token-goat-chunk-6SGLIPQB.mjs → token-goat-chunk-A3CK6N5Z.mjs} +621 -72
  27. package/dist/{token-goat-chunk-HXNAC4ZF.mjs → token-goat-chunk-AFLYLHDH.mjs} +48 -33
  28. package/dist/token-goat-chunk-AM5V6GSX.mjs +367 -0
  29. package/dist/{token-goat-chunk-I7CB3X4K.mjs → token-goat-chunk-APGZXSPS.mjs} +44 -148
  30. package/dist/{token-goat-chunk-BJBRGPBX.mjs → token-goat-chunk-ARDNEC2U.mjs} +11 -7
  31. package/dist/token-goat-chunk-ATCPY7EQ.mjs +134 -0
  32. package/dist/token-goat-chunk-B2RZZCSS.mjs +354 -0
  33. package/dist/{token-goat-chunk-QM76S6YS.mjs → token-goat-chunk-B45VMIIH.mjs} +6 -5
  34. package/dist/token-goat-chunk-BPGCUMR7.mjs +30 -0
  35. package/dist/{token-goat-chunk-GGLEE35R.mjs → token-goat-chunk-C63JQV5K.mjs} +49 -10
  36. package/dist/{token-goat-chunk-RJH64KQH.mjs → token-goat-chunk-COBQGL5S.mjs} +2661 -2440
  37. package/dist/token-goat-chunk-COTXZHTS.mjs +39 -0
  38. package/dist/token-goat-chunk-CYCEYAEO.mjs +265 -0
  39. package/dist/token-goat-chunk-CZ3LUXYZ.mjs +4115 -0
  40. package/dist/token-goat-chunk-DZX2YDPT.mjs +15 -0
  41. package/dist/token-goat-chunk-E3OQX2XT.mjs +824 -0
  42. package/dist/token-goat-chunk-EFHMMIGP.mjs +68 -0
  43. package/dist/token-goat-chunk-ETBHVDB6.mjs +328 -0
  44. package/dist/token-goat-chunk-EVMZJ27Z.mjs +147 -0
  45. package/dist/token-goat-chunk-EXKGNHEG.mjs +2096 -0
  46. package/dist/{token-goat-chunk-6Z5ULNE5.mjs → token-goat-chunk-FBNQNSJK.mjs} +2490 -4957
  47. package/dist/{token-goat-chunk-NMTKNYGF.mjs → token-goat-chunk-FNFBKLRD.mjs} +74 -9
  48. package/dist/{token-goat-chunk-XI2VFAV6.mjs → token-goat-chunk-FZ3NEW5O.mjs} +33 -19
  49. package/dist/token-goat-chunk-G5PJ7AGM.mjs +36 -0
  50. package/dist/{token-goat-chunk-VE27HPIF.mjs → token-goat-chunk-GFBSN7BD.mjs} +30 -398
  51. package/dist/{token-goat-chunk-L45ZQRT7.mjs → token-goat-chunk-GOLEOXZP.mjs} +780 -786
  52. package/dist/token-goat-chunk-H2K3QP6H.mjs +24 -0
  53. package/dist/token-goat-chunk-H2PHHGM5.mjs +188 -0
  54. package/dist/token-goat-chunk-HAVAOB3S.mjs +87 -0
  55. package/dist/token-goat-chunk-HG45AF2B.mjs +2228 -0
  56. package/dist/{token-goat-chunk-CBMY2FGI.mjs → token-goat-chunk-HOJLCGDP.mjs} +17113 -15554
  57. package/dist/{token-goat-chunk-HUDC5GS5.mjs → token-goat-chunk-HYBFA5X3.mjs} +120 -19
  58. package/dist/token-goat-chunk-IVALLT3S.mjs +48 -0
  59. package/dist/token-goat-chunk-IVE6U7KV.mjs +53 -0
  60. package/dist/{token-goat-chunk-UBUKHVYW.mjs → token-goat-chunk-IVKIZWAB.mjs} +3 -3
  61. package/dist/{token-goat-chunk-4JMWPWCS.mjs → token-goat-chunk-JB6QN6VF.mjs} +6 -4
  62. package/dist/{token-goat-chunk-Q4S3UQGO.mjs → token-goat-chunk-JDHE26RP.mjs} +10 -3
  63. package/dist/{token-goat-chunk-7R2XYKC5.mjs → token-goat-chunk-JDU3EXSU.mjs} +14 -10
  64. package/dist/token-goat-chunk-JDWCRD6M.mjs +253 -0
  65. package/dist/{token-goat-chunk-XBESNWEX.mjs → token-goat-chunk-JN4XMLSD.mjs} +7 -4
  66. package/dist/token-goat-chunk-JTQQGXZH.mjs +733 -0
  67. package/dist/token-goat-chunk-KKUFXAPD.mjs +25 -0
  68. package/dist/token-goat-chunk-KQNZDCBD.mjs +47 -0
  69. package/dist/{token-goat-chunk-4RN64ZND.mjs → token-goat-chunk-KWPNJBDH.mjs} +28 -3
  70. package/dist/token-goat-chunk-LOBGHXPB.mjs +242 -0
  71. package/dist/token-goat-chunk-MKPF4CL5.mjs +37 -0
  72. package/dist/token-goat-chunk-MNWKPRAL.mjs +13 -0
  73. package/dist/{token-goat-chunk-YWSP6IU7.mjs → token-goat-chunk-N2NMER56.mjs} +25 -15
  74. package/dist/token-goat-chunk-NYKZLXMK.mjs +218 -0
  75. package/dist/token-goat-chunk-OJBNYTJP.mjs +3087 -0
  76. package/dist/token-goat-chunk-P4QMM4WK.mjs +295 -0
  77. package/dist/token-goat-chunk-PD5VKH46.mjs +184 -0
  78. package/dist/token-goat-chunk-PEPTHRFF.mjs +129 -0
  79. package/dist/{token-goat-chunk-VWZKZPSR.mjs → token-goat-chunk-PU7V3FD6.mjs} +8752 -11098
  80. package/dist/token-goat-chunk-PY533T7F.mjs +46 -0
  81. package/dist/token-goat-chunk-Q5VTGRH7.mjs +761 -0
  82. package/dist/{token-goat-chunk-IHKZ3QNA.mjs → token-goat-chunk-QCLDAQTS.mjs} +33 -19
  83. package/dist/{token-goat-chunk-LKSXAMJB.mjs → token-goat-chunk-QSBRTGM2.mjs} +9 -2
  84. package/dist/{token-goat-chunk-4STDIGYC.mjs → token-goat-chunk-RC35RBUL.mjs} +7 -5
  85. package/dist/{token-goat-chunk-D5ICEPSB.mjs → token-goat-chunk-RHXKCZX3.mjs} +887 -507
  86. package/dist/{token-goat-chunk-RSS3TLXU.mjs → token-goat-chunk-RZRTDST7.mjs} +17 -7
  87. package/dist/{token-goat-chunk-MAMQPC43.mjs → token-goat-chunk-SJHWVNDQ.mjs} +15 -21
  88. package/dist/token-goat-chunk-SMVRN2HU.mjs +188 -0
  89. package/dist/{token-goat-chunk-EL7M26WP.mjs → token-goat-chunk-SQSSNQPE.mjs} +2100 -1442
  90. package/dist/{token-goat-chunk-OZRSREKR.mjs → token-goat-chunk-T4FK7VOV.mjs} +3 -3
  91. package/dist/token-goat-chunk-U4N3BN2W.mjs +92 -0
  92. package/dist/token-goat-chunk-UA5V6P3P.mjs +122 -0
  93. package/dist/{token-goat-chunk-XKY4VKJ4.mjs → token-goat-chunk-UQ5UK2T7.mjs} +15 -4
  94. package/dist/token-goat-chunk-USILZ3T3.mjs +53 -0
  95. package/dist/token-goat-chunk-VES7EL7O.mjs +205 -0
  96. package/dist/{token-goat-chunk-M56BWPBN.mjs → token-goat-chunk-VL3YIFHZ.mjs} +550 -49
  97. package/dist/{token-goat-chunk-IZXKVT4A.mjs → token-goat-chunk-VPBBTSJR.mjs} +362 -128
  98. package/dist/{token-goat-chunk-F2ARFHLJ.mjs → token-goat-chunk-W3QCJS6G.mjs} +10 -2
  99. package/dist/{token-goat-chunk-FSTWAOW6.mjs → token-goat-chunk-WY3L4DVT.mjs} +11 -5
  100. package/dist/{token-goat-chunk-OSUFN2FV.mjs → token-goat-chunk-XB5KKOCG.mjs} +5 -25
  101. package/dist/token-goat-chunk-XKI4SEMX.mjs +66 -0
  102. package/dist/token-goat-chunk-XU4P6Z24.mjs +133 -0
  103. package/dist/{token-goat-chunk-6CCQDAYY.mjs → token-goat-chunk-Y776AENC.mjs} +138 -33
  104. package/dist/token-goat-chunk-YARZFCZS.mjs +359 -0
  105. package/dist/{token-goat-chunk-EEIDFMEM.mjs → token-goat-chunk-YZAAZU2S.mjs} +12 -3
  106. package/dist/{token-goat-chunk-E3K3BTEQ.mjs → token-goat-chunk-Z44YO3QZ.mjs} +12 -6
  107. package/dist/token-goat-chunk-Z57YODA2.mjs +35 -0
  108. package/dist/{token-goat-chunk-DA43OE7L.mjs → token-goat-chunk-ZCDTCVIS.mjs} +49 -30
  109. package/dist/token-goat-chunk-ZEJVMUQH.mjs +48 -0
  110. package/dist/{token-goat-chunk-BGHSSJUA.mjs → token-goat-chunk-ZFOBKUWH.mjs} +1 -1
  111. package/dist/token-goat-chunk-ZMBL6UVV.mjs +110 -0
  112. package/dist/{token-goat-chunk-SJEKA7Y2.mjs → token-goat-chunk-ZQSJMO2R.mjs} +381 -201
  113. package/dist/token-goat-hook-client.cjs +539 -0
  114. package/dist/token-goat-hook-client.mjs +26 -0
  115. package/dist/token-goat-hook.mjs +48 -28
  116. package/dist/token-goat.core.mjs +10 -45
  117. package/docs/C4_RUNTIME_ARCHITECTURE.md +3 -3
  118. package/docs/cli.md +82 -47
  119. package/docs/install.md +58 -23
  120. package/docs/security.md +7 -7
  121. package/package.json +17 -7
  122. package/scripts/verify-native-dist.mjs +386 -0
  123. package/dist/token-goat-chunk-4JJBFT7V.mjs +0 -20
  124. package/dist/token-goat-chunk-5NNYIUGV.mjs +0 -143
  125. package/dist/token-goat-chunk-6DQNNFJ6.mjs +0 -294
  126. package/dist/token-goat-chunk-7MAFDRVR.mjs +0 -47
  127. package/dist/token-goat-chunk-BCN2YQC6.mjs +0 -32
  128. package/dist/token-goat-chunk-D7GHQKQD.mjs +0 -30
  129. package/dist/token-goat-chunk-GMOUBOX4.mjs +0 -386
  130. package/dist/token-goat-chunk-IFORDBGC.mjs +0 -192
  131. package/dist/token-goat-chunk-JXK2HQXS.mjs +0 -318
  132. package/dist/token-goat-chunk-L7SDVGBT.mjs +0 -430
  133. package/dist/token-goat-chunk-MMLMALWK.mjs +0 -1381
  134. package/dist/token-goat-chunk-MVSWBNMD.mjs +0 -1985
@@ -1,430 +0,0 @@
1
- import { createRequire as __cjsRequire } from 'node:module';
2
- const require = __cjsRequire(import.meta.url);
3
- import {
4
- computeAdaptiveBudget,
5
- getContextPressure,
6
- isNoisePath,
7
- listSiblingSessionStates,
8
- loadSessionCache
9
- } from "./token-goat-chunk-6CCQDAYY.mjs";
10
- import {
11
- WEB_FETCH_KEY_SEP,
12
- getSessionBashOutputs,
13
- getSessionBashReruns,
14
- getSessionFiles,
15
- getSessionWebFetches
16
- } from "./token-goat-chunk-GGLEE35R.mjs";
17
- import {
18
- getBashOutput
19
- } from "./token-goat-chunk-HXNAC4ZF.mjs";
20
- import {
21
- findProject,
22
- loadConfig
23
- } from "./token-goat-chunk-CC2PYJM7.mjs";
24
- import {
25
- atomicWriteText,
26
- dataDir,
27
- ensureDirSync,
28
- foldPath,
29
- runGit,
30
- toKB,
31
- withFileLock
32
- } from "./token-goat-chunk-L45ZQRT7.mjs";
33
- import {
34
- displaySafePath,
35
- displaySafeText,
36
- neutralizeSpokenMarkers
37
- } from "./token-goat-chunk-NMTKNYGF.mjs";
38
- import {
39
- init_define_import_meta_env
40
- } from "./token-goat-chunk-A37V4PBF.mjs";
41
-
42
- // src/manifest.ts
43
- init_define_import_meta_env();
44
- import { spawnSync } from "node:child_process";
45
-
46
- // src/project_memory.ts
47
- init_define_import_meta_env();
48
- import * as fs from "node:fs";
49
- import * as path from "node:path";
50
- var MAX_ENTRIES = 30;
51
- var MAX_VALUE_LEN = 300;
52
- var MAX_TOTAL_CHARS = 4e3;
53
- var KEY_RE = /^[A-Za-z0-9_-]{1,80}$/;
54
- function ordinal(a, b) {
55
- return a < b ? -1 : a > b ? 1 : 0;
56
- }
57
- function memoryPath(projectHash) {
58
- return path.join(dataDir(), "projects", `${projectHash}_memory.toml`);
59
- }
60
- function validateKey(key) {
61
- if (!KEY_RE.test(key)) {
62
- throw new Error(
63
- `Invalid memory key ${JSON.stringify(key)}: use only letters, digits, hyphens, underscores (max 80 chars)`
64
- );
65
- }
66
- }
67
- function parseTOML(content) {
68
- const result = {};
69
- for (const line of content.split("\n")) {
70
- const trimmed = line.trim();
71
- if (!trimmed || trimmed.startsWith("#")) {
72
- continue;
73
- }
74
- const match = trimmed.match(/^([A-Za-z0-9_-]+)\s*=\s*"(.*)"\s*$/);
75
- if (match) {
76
- const [, key, value] = match;
77
- if (key && value !== void 0) {
78
- const unescaped = value.replace(/\\([\\nrt"])/g, (_, c) => {
79
- switch (c) {
80
- case "\\":
81
- return "\\";
82
- case "n":
83
- return "\n";
84
- case "r":
85
- return "\r";
86
- case '"':
87
- return '"';
88
- default:
89
- return _;
90
- }
91
- });
92
- result[key] = unescaped;
93
- }
94
- }
95
- }
96
- return result;
97
- }
98
- function loadRaw(filePath) {
99
- try {
100
- if (!fs.existsSync(filePath)) {
101
- return {};
102
- }
103
- const content = fs.readFileSync(filePath, "utf-8");
104
- return parseTOML(content);
105
- } catch {
106
- return {};
107
- }
108
- }
109
- function save(filePath, entries) {
110
- const lines = [];
111
- const sorted = Object.entries(entries).sort(([a], [b]) => ordinal(a, b));
112
- for (const [k, v] of sorted) {
113
- const escaped = v.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\r/g, "\\r").replace(/\n/g, "\\n");
114
- lines.push(`${k} = "${escaped}"`);
115
- }
116
- const content = lines.length > 0 ? lines.join("\n") + "\n" : "";
117
- const dir = path.dirname(filePath);
118
- ensureDirSync(dir);
119
- atomicWriteText(filePath, content);
120
- }
121
- function loadEntries(projectHash) {
122
- return loadRaw(memoryPath(projectHash));
123
- }
124
- function setEntry(projectHash, key, value) {
125
- validateKey(key);
126
- const p = memoryPath(projectHash);
127
- const dir = path.dirname(p);
128
- ensureDirSync(dir);
129
- const doSet = () => {
130
- const entries = loadRaw(p);
131
- const isNewKey = !(key in entries);
132
- if (isNewKey && Object.keys(entries).length >= MAX_ENTRIES) {
133
- const keysToKeep = MAX_ENTRIES - 1;
134
- const allKeys = Object.keys(entries).sort((a, b) => ordinal(a, b));
135
- for (const k of allKeys.slice(keysToKeep)) {
136
- delete entries[k];
137
- }
138
- }
139
- entries[key] = value;
140
- save(p, entries);
141
- return true;
142
- };
143
- if (withFileLock(`${p}.lock`, doSet) === void 0) doSet();
144
- }
145
- function unsetEntry(projectHash, key) {
146
- validateKey(key);
147
- const p = memoryPath(projectHash);
148
- const doUnset = () => {
149
- const entries = loadRaw(p);
150
- if (key in entries) {
151
- delete entries[key];
152
- save(p, entries);
153
- }
154
- return true;
155
- };
156
- if (withFileLock(`${p}.lock`, doUnset) === void 0) doUnset();
157
- }
158
- function clearAll(projectHash) {
159
- const p = memoryPath(projectHash);
160
- const doClear = () => {
161
- if (fs.existsSync(p)) {
162
- save(p, {});
163
- }
164
- return true;
165
- };
166
- if (withFileLock(`${p}.lock`, doClear) === void 0) doClear();
167
- }
168
- function buildInjection(projectHash) {
169
- try {
170
- const entries = loadEntries(projectHash);
171
- if (Object.keys(entries).length === 0) {
172
- return null;
173
- }
174
- const header = '### Project notes (`token-goat note set <key> "<finding>"`)';
175
- const lines = [header];
176
- let total = header.length;
177
- let skipped = 0;
178
- const entries_list = Object.entries(entries).sort(([a], [b]) => ordinal(a, b)).slice(0, MAX_ENTRIES);
179
- for (const [key, val] of entries_list) {
180
- const display = val.length <= MAX_VALUE_LEN ? val : val.slice(0, MAX_VALUE_LEN) + "\u2026";
181
- const line = `- **${key}**: ${display}`;
182
- if (total + line.length + 1 > MAX_TOTAL_CHARS) {
183
- skipped++;
184
- continue;
185
- }
186
- lines.push(line);
187
- total += line.length + 1;
188
- }
189
- if (skipped > 0) {
190
- while (lines.length > 1 && total + `- (+${skipped} more memory entries omitted -- total size limit reached)`.length + 1 > MAX_TOTAL_CHARS) {
191
- const popped = lines.pop();
192
- total -= popped.length + 1;
193
- skipped++;
194
- }
195
- lines.push(`- (+${skipped} more memory entries omitted -- total size limit reached)`);
196
- }
197
- return lines.join("\n");
198
- } catch {
199
- return null;
200
- }
201
- }
202
- function projectNotesFor(cwd) {
203
- if (cwd === void 0) return null;
204
- try {
205
- const project = findProject(cwd);
206
- return project === null ? null : buildInjection(project.hash);
207
- } catch {
208
- return null;
209
- }
210
- }
211
-
212
- // src/manifest.ts
213
- var MEM_EPOCH_TIMEOUT_MS = 800;
214
- var MAX_ROWS = 40;
215
- function appendCappedSection(lines, header, rows, cap) {
216
- if (rows.length === 0) return;
217
- lines.push("");
218
- lines.push(header);
219
- for (const row of rows.slice(0, cap)) lines.push(row);
220
- if (rows.length > cap) lines.push(`- ...and ${rows.length - cap} more`);
221
- }
222
- function renderReadRow(entry) {
223
- const kb = Math.max(1, toKB(entry.sizeBytes));
224
- const plural = entry.readCount === 1 ? "read" : "reads";
225
- const edited = entry.wasEdited ? ", edited" : "";
226
- return `- ${displaySafePath(entry.path)} (${kb}kb, ${entry.readCount} ${plural}${edited})`;
227
- }
228
- function renderSymbolReadRow(entry) {
229
- return `- ${displaySafePath(entry.path)} (symbols: ${(entry.symbols_read ?? []).map(displaySafeText).join(", ")})`;
230
- }
231
- function mergeManifestFiles(parent, siblingFiles) {
232
- const byPath = /* @__PURE__ */ new Map();
233
- for (const f of parent) byPath.set(foldPath(f.path), f);
234
- for (const f of siblingFiles) {
235
- const key = foldPath(f.path);
236
- const prev = byPath.get(key);
237
- if (prev === void 0) {
238
- byPath.set(key, f);
239
- continue;
240
- }
241
- const mergedSymbols = [.../* @__PURE__ */ new Set([...prev.symbols_read ?? [], ...f.symbols_read ?? []])];
242
- byPath.set(key, {
243
- path: prev.path,
244
- readCount: Math.max(prev.readCount, f.readCount),
245
- lastReadAt: Math.max(prev.lastReadAt, f.lastReadAt),
246
- wasEdited: prev.wasEdited || f.wasEdited,
247
- sizeBytes: f.lastReadAt >= prev.lastReadAt ? f.sizeBytes : prev.sizeBytes,
248
- ...prev.wasTruncated || f.wasTruncated ? { wasTruncated: true } : {},
249
- ...mergedSymbols.length > 0 ? { symbols_read: mergedSymbols } : {}
250
- });
251
- }
252
- return Array.from(byPath.values());
253
- }
254
- function renderWebFetchRow(key, cacheId) {
255
- const [url = key, prompt = ""] = key.split(WEB_FETCH_KEY_SEP);
256
- const promptSuffix = prompt ? `, prompt: ${neutralizeSpokenMarkers(JSON.stringify(prompt))}` : "";
257
- return `- ${displaySafeText(url)} (cacheId: ${cacheId}${promptSuffix})`;
258
- }
259
- function selectManifestFiles(siblings) {
260
- const ownFiles = [...getSessionFiles().values()];
261
- const siblingFiles = siblings.flatMap((s) => s.files);
262
- const files = siblingFiles.length > 0 ? mergeManifestFiles(ownFiles, siblingFiles) : ownFiles;
263
- const editedFiles = files.filter((f) => f.wasEdited);
264
- const readFiles = files.filter((f) => f.readCount > 0 && !f.wasEdited && !isNoisePath(f.path));
265
- const symbolOnlyFiles = files.filter((f) => f.readCount === 0 && !f.wasEdited && (f.symbols_read?.length ?? 0) > 0);
266
- return { files, readFiles, editedFiles, symbolOnlyFiles };
267
- }
268
- function selectManifestWebFetches(siblings) {
269
- const merged = /* @__PURE__ */ new Map();
270
- for (const sibling of siblings) for (const [key, cacheId] of sibling.webFetches) merged.set(key, cacheId);
271
- for (const [key, cacheId] of getSessionWebFetches()) merged.set(key, cacheId);
272
- return [...merged.entries()];
273
- }
274
- function manifestPrintedPaths(sessionId, limit, cwd, transcriptPath) {
275
- const { printed } = buildManifestParts(sessionId, cwd, transcriptPath);
276
- return printed.slice(0, limit);
277
- }
278
- function buildManifestParts(sessionId, cwd, transcriptPath) {
279
- const siblings = sessionId !== void 0 ? listSiblingSessionStates(sessionId) : [];
280
- const { files, readFiles, editedFiles, symbolOnlyFiles } = selectManifestFiles(siblings);
281
- const webFetches = selectManifestWebFetches(siblings);
282
- const lines = [];
283
- lines.push("## Session context");
284
- lines.push(`Files read: ${readFiles.length}`);
285
- lines.push(`Files edited: ${editedFiles.length}`);
286
- const fileRows = [];
287
- const appendFileSection = (header, entries, render) => {
288
- const rows = entries.map(render);
289
- appendCappedSection(lines, header, rows, MAX_ROWS);
290
- for (let i = 0; i < Math.min(rows.length, MAX_ROWS); i++) fileRows.push({ path: displaySafePath(entries[i].path), row: rows[i] });
291
- };
292
- appendFileSection("### Edited files", editedFiles, (entry) => `- ${displaySafePath(entry.path)}`);
293
- const notes = projectNotesFor(cwd);
294
- if (notes !== null) lines.push("", notes);
295
- appendFileSection("### Surgically read files (symbol/section reads, never read whole)", symbolOnlyFiles, renderSymbolReadRow);
296
- appendFileSection("### Read files", readFiles, renderReadRow);
297
- appendCappedSection(lines, "### Web URLs fetched", webFetches.map(([key, cacheId]) => renderWebFetchRow(key, cacheId)), MAX_ROWS);
298
- lines.push(...buildSafeToDiscardSection(files));
299
- lines.push(...buildMemEpochSection());
300
- const text = capManifestChars(lines.join("\n"), sessionId, cwd, transcriptPath);
301
- const seen = /* @__PURE__ */ new Set();
302
- const printed = [];
303
- for (const { path: path2, row } of fileRows) {
304
- if (seen.has(path2) || !(text.includes(row + "\n") || text.endsWith(row))) continue;
305
- seen.add(path2);
306
- printed.push(path2);
307
- }
308
- return { text, printed };
309
- }
310
- function buildManifest(sessionId, cwd, transcriptPath) {
311
- return buildManifestParts(sessionId, cwd, transcriptPath).text;
312
- }
313
- function gitDirtySignals(cwd) {
314
- const timeoutMs = loadConfig().hints.git_hint_max_ms;
315
- let hasPendingDiff = false;
316
- try {
317
- const diffResult = runGit(["diff", "--no-color", "--stat", "HEAD"], { cwd, timeoutMs });
318
- hasPendingDiff = diffResult.exitCode === 0 && diffResult.stdout.trim() !== "";
319
- } catch {
320
- }
321
- let hasUncommittedChanges = false;
322
- try {
323
- const statusResult = runGit(["status", "--porcelain"], { cwd, timeoutMs });
324
- hasUncommittedChanges = statusResult.exitCode === 0 && statusResult.stdout.trim() !== "";
325
- } catch {
326
- }
327
- return { hasPendingDiff, hasUncommittedChanges };
328
- }
329
- function adaptiveCharBonus(sessionId, cwd, transcriptPath) {
330
- if (!cwd) return 0;
331
- const cache = loadSessionCache(sessionId ?? "") ?? {};
332
- const ageSecs = cache.created_ts !== void 0 ? Math.max(0, Date.now() / 1e3 - cache.created_ts) : 0;
333
- const contextPressure = getContextPressure(cache, transcriptPath);
334
- const { hasPendingDiff, hasUncommittedChanges } = gitDirtySignals(cwd);
335
- if (!hasPendingDiff && !hasUncommittedChanges) return 0;
336
- const baseline = computeAdaptiveBudget(cache, ageSecs, { contextPressure });
337
- const withGitSignal = computeAdaptiveBudget(cache, ageSecs, { hasPendingDiff, hasUncommittedChanges, contextPressure });
338
- const deltaTokens = Math.max(0, withGitSignal - baseline);
339
- return deltaTokens * 3;
340
- }
341
- function capManifestChars(manifest, sessionId, cwd, transcriptPath) {
342
- const cap = loadConfig().compact_assist.max_manifest_chars;
343
- if (cap <= 0) return manifest;
344
- if (manifest.length <= cap) return manifest;
345
- const effectiveCap = cap + adaptiveCharBonus(sessionId, cwd, transcriptPath);
346
- if (manifest.length <= effectiveCap) return manifest;
347
- const omitted = manifest.length - effectiveCap;
348
- return manifest.slice(0, effectiveCap) + `
349
- ...(manifest truncated at ${effectiveCap} chars; ${omitted} chars omitted)`;
350
- }
351
- function buildSafeToDiscardSection(files) {
352
- const rerunHashes = getSessionBashReruns();
353
- const bashOutputs = getSessionBashOutputs();
354
- const rerunHashSet = new Set(rerunHashes);
355
- const rerunRows = [];
356
- for (const hash of rerunHashes) {
357
- const id = bashOutputs.find(([h]) => h === hash)?.[1];
358
- if (id === void 0) continue;
359
- const entry = getBashOutput(id);
360
- if (entry === null) continue;
361
- const flatCommand = neutralizeSpokenMarkers(entry.command.replace(/[\t\r\n]+/g, " "));
362
- rerunRows.push("- `" + flatCommand + "` \u2014 an older run of this exact command was superseded; recall the surviving copy with `bash-output " + id + " --full`");
363
- }
364
- const supersededReadRows = [];
365
- for (const f of files) {
366
- if (f.readCount > 1 || f.wasEdited) {
367
- const reason = f.wasEdited ? "edited after being read" : "re-read " + f.readCount + "x";
368
- supersededReadRows.push("- " + displaySafePath(f.path) + " (" + reason + " \u2014 only the latest content already in context is current)");
369
- }
370
- }
371
- const cachedOutputRows = [];
372
- for (const [hash, id] of bashOutputs) {
373
- if (rerunHashSet.has(hash)) continue;
374
- const entry = getBashOutput(id);
375
- if (entry === null) continue;
376
- const flatCommand = neutralizeSpokenMarkers(entry.command.replace(/[\t\r\n]+/g, " "));
377
- cachedOutputRows.push("- `" + flatCommand + "` \u2014 recallable via `bash-output " + id + " --full`");
378
- }
379
- const total = rerunRows.length + supersededReadRows.length + cachedOutputRows.length;
380
- if (total === 0) return [];
381
- const lines = [];
382
- lines.push("");
383
- lines.push("### SAFE_TO_DISCARD (" + total + " items \u2014 provably inert; each is recallable, not gone)");
384
- appendCappedSection(lines, "Superseded reruns (" + rerunRows.length + "):", rerunRows, MAX_ROWS);
385
- appendCappedSection(lines, "Superseded file reads (" + supersededReadRows.length + "):", supersededReadRows, MAX_ROWS);
386
- appendCappedSection(lines, "Other cached bash outputs (" + cachedOutputRows.length + "):", cachedOutputRows, MAX_ROWS);
387
- return lines;
388
- }
389
- function buildMemEpochSection() {
390
- let result;
391
- try {
392
- result = spawnSync("mem", ["epoch"], {
393
- encoding: "utf-8",
394
- timeout: MEM_EPOCH_TIMEOUT_MS,
395
- windowsHide: true
396
- });
397
- } catch {
398
- return [];
399
- }
400
- if (result.error !== void 0 || result.status !== 0) return [];
401
- const stdout = typeof result.stdout === "string" ? result.stdout.trim() : "";
402
- if (!/^\d+$/.test(stdout)) return [];
403
- return [
404
- "",
405
- "### mem epoch",
406
- `mem epoch: ${stdout} (no live TGMEM block is tracked in this session -- only the epoch counter is folded in; see buildMemEpochSection's doc comment)`
407
- ];
408
- }
409
- var MANIFEST_PREAMBLE = "When summarizing this session, keep the file paths and symbol names below exactly as written -- they are the handles the next turn needs to resume work. Do not paraphrase them into prose.";
410
- var MANIFEST_RECOVERY_PREAMBLE = "The conversation was just compacted. Below is what this session touched, recovered from token-goat's own ledger rather than from the summary -- use it to re-establish paths and symbol names the summary may have dropped.";
411
- var BUDGET_ESCALATION_MARKER = "TG-BUDGET-ESCALATION:";
412
- function summaryBudgetDirective(budgetChars) {
413
- if (budgetChars <= 0) return "";
414
- return ` Aim for at most ${budgetChars} characters. Prefer a shorter summary that keeps every path, symbol, command and decision over a longer one that reproduces tool output verbatim: cite the recall id (\`token-goat bash-output <id> --full\`) rather than quoting the output again. If this session genuinely cannot be summarized within that target without losing state the next turn needs, exceed it and open the summary with a single line reading \`${BUDGET_ESCALATION_MARKER} <one-sentence reason>\`.`;
415
- }
416
-
417
- export {
418
- loadEntries,
419
- setEntry,
420
- unsetEntry,
421
- clearAll,
422
- projectNotesFor,
423
- renderWebFetchRow,
424
- manifestPrintedPaths,
425
- buildManifest,
426
- MANIFEST_PREAMBLE,
427
- MANIFEST_RECOVERY_PREAMBLE,
428
- BUDGET_ESCALATION_MARKER,
429
- summaryBudgetDirective
430
- };