token-goat 2.9.29 → 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 (131) hide show
  1. package/README.md +34 -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-PGTH2U4C.mjs → token-goat-chunk-4JJS54TR.mjs} +4 -3
  11. package/dist/token-goat-chunk-4LCCNRTG.mjs +313 -0
  12. package/dist/{token-goat-chunk-L7H3U27L.mjs → token-goat-chunk-54K3EUV3.mjs} +1 -1
  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-GLXRTTLE.mjs → token-goat-chunk-64FBPDTK.mjs} +12 -8
  19. package/dist/{token-goat-chunk-G23DWHV4.mjs → token-goat-chunk-664RTTUV.mjs} +28 -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-IVWI2OCK.mjs → token-goat-chunk-7F2UBPD3.mjs} +40 -11
  24. package/dist/{token-goat-chunk-TGOXNAHW.mjs → token-goat-chunk-7IN2MKDS.mjs} +682 -501
  25. package/dist/token-goat-chunk-7NADEDKJ.mjs +124 -0
  26. package/dist/{token-goat-chunk-KOPIR3KZ.mjs → token-goat-chunk-A3CK6N5Z.mjs} +618 -72
  27. package/dist/{token-goat-chunk-O6I2XU4P.mjs → token-goat-chunk-AFLYLHDH.mjs} +44 -31
  28. package/dist/{token-goat-chunk-TCQANXYC.mjs → token-goat-chunk-AM5V6GSX.mjs} +18 -2
  29. package/dist/{token-goat-chunk-E4ZOJIZK.mjs → token-goat-chunk-APGZXSPS.mjs} +39 -146
  30. package/dist/{token-goat-chunk-D4ETHJD6.mjs → token-goat-chunk-ARDNEC2U.mjs} +9 -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-BGYOZ6DO.mjs → token-goat-chunk-B45VMIIH.mjs} +6 -7
  34. package/dist/token-goat-chunk-BPGCUMR7.mjs +30 -0
  35. package/dist/{token-goat-chunk-TDUT2CL6.mjs → token-goat-chunk-C63JQV5K.mjs} +45 -6
  36. package/dist/{token-goat-chunk-ZER6EAXZ.mjs → token-goat-chunk-COBQGL5S.mjs} +2661 -2440
  37. package/dist/token-goat-chunk-COTXZHTS.mjs +39 -0
  38. package/dist/{token-goat-chunk-RQGGMPCR.mjs → token-goat-chunk-CYCEYAEO.mjs} +76 -16
  39. package/dist/token-goat-chunk-CZ3LUXYZ.mjs +4115 -0
  40. package/dist/{token-goat-chunk-ASLWOQ3I.mjs → token-goat-chunk-DZX2YDPT.mjs} +2 -1
  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-RTMVLHWX.mjs → token-goat-chunk-FBNQNSJK.mjs} +2555 -5127
  47. package/dist/{token-goat-chunk-NMTKNYGF.mjs → token-goat-chunk-FNFBKLRD.mjs} +74 -9
  48. package/dist/{token-goat-chunk-RLP6J7WR.mjs → token-goat-chunk-FZ3NEW5O.mjs} +33 -19
  49. package/dist/token-goat-chunk-G5PJ7AGM.mjs +36 -0
  50. package/dist/{token-goat-chunk-DNRPXHYH.mjs → token-goat-chunk-GFBSN7BD.mjs} +29 -401
  51. package/dist/{token-goat-chunk-XYWPOSCN.mjs → token-goat-chunk-GOLEOXZP.mjs} +763 -211
  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-HUYUHODZ.mjs → token-goat-chunk-HOJLCGDP.mjs} +12965 -11748
  57. package/dist/{token-goat-chunk-435UQTKD.mjs → token-goat-chunk-HYBFA5X3.mjs} +118 -19
  58. package/dist/token-goat-chunk-IVALLT3S.mjs +48 -0
  59. package/dist/{token-goat-chunk-UXSXQQIY.mjs → token-goat-chunk-IVKIZWAB.mjs} +3 -3
  60. package/dist/{token-goat-chunk-52NSDWYY.mjs → token-goat-chunk-JB6QN6VF.mjs} +6 -4
  61. package/dist/{token-goat-chunk-HNFZZHFW.mjs → token-goat-chunk-JDHE26RP.mjs} +10 -3
  62. package/dist/{token-goat-chunk-FTP4U4QA.mjs → token-goat-chunk-JDU3EXSU.mjs} +12 -11
  63. package/dist/token-goat-chunk-JDWCRD6M.mjs +253 -0
  64. package/dist/{token-goat-chunk-6AK46ZT7.mjs → token-goat-chunk-JN4XMLSD.mjs} +5 -1
  65. package/dist/token-goat-chunk-JTQQGXZH.mjs +733 -0
  66. package/dist/token-goat-chunk-KKUFXAPD.mjs +25 -0
  67. package/dist/token-goat-chunk-KQNZDCBD.mjs +47 -0
  68. package/dist/{token-goat-chunk-2WOUYWLM.mjs → token-goat-chunk-KWPNJBDH.mjs} +27 -3
  69. package/dist/{token-goat-chunk-DPNLUJWB.mjs → token-goat-chunk-LOBGHXPB.mjs} +30 -8
  70. package/dist/token-goat-chunk-MKPF4CL5.mjs +37 -0
  71. package/dist/token-goat-chunk-MNWKPRAL.mjs +13 -0
  72. package/dist/{token-goat-chunk-DNSPXQXQ.mjs → token-goat-chunk-N2NMER56.mjs} +25 -15
  73. package/dist/token-goat-chunk-NYKZLXMK.mjs +218 -0
  74. package/dist/token-goat-chunk-OJBNYTJP.mjs +3087 -0
  75. package/dist/token-goat-chunk-P4QMM4WK.mjs +295 -0
  76. package/dist/token-goat-chunk-PD5VKH46.mjs +184 -0
  77. package/dist/token-goat-chunk-PEPTHRFF.mjs +129 -0
  78. package/dist/{token-goat-chunk-NMBWLRHW.mjs → token-goat-chunk-PU7V3FD6.mjs} +8721 -11104
  79. package/dist/token-goat-chunk-PY533T7F.mjs +46 -0
  80. package/dist/token-goat-chunk-Q5VTGRH7.mjs +761 -0
  81. package/dist/{token-goat-chunk-67BNIKKO.mjs → token-goat-chunk-QCLDAQTS.mjs} +31 -20
  82. package/dist/{token-goat-chunk-SE6E4BKJ.mjs → token-goat-chunk-QSBRTGM2.mjs} +9 -2
  83. package/dist/{token-goat-chunk-VZQEWRVH.mjs → token-goat-chunk-RC35RBUL.mjs} +4 -4
  84. package/dist/{token-goat-chunk-VMFWNHGR.mjs → token-goat-chunk-RHXKCZX3.mjs} +873 -504
  85. package/dist/{token-goat-chunk-PYSUADX4.mjs → token-goat-chunk-RZRTDST7.mjs} +17 -7
  86. package/dist/{token-goat-chunk-ONXH6NZ5.mjs → token-goat-chunk-SJHWVNDQ.mjs} +15 -21
  87. package/dist/token-goat-chunk-SMVRN2HU.mjs +188 -0
  88. package/dist/{token-goat-chunk-QO3LXVVR.mjs → token-goat-chunk-SQSSNQPE.mjs} +2295 -1718
  89. package/dist/{token-goat-chunk-2AWQ2R5X.mjs → token-goat-chunk-T4FK7VOV.mjs} +2 -2
  90. package/dist/token-goat-chunk-U4N3BN2W.mjs +92 -0
  91. package/dist/token-goat-chunk-UA5V6P3P.mjs +122 -0
  92. package/dist/{token-goat-chunk-UA5BKWWQ.mjs → token-goat-chunk-UQ5UK2T7.mjs} +15 -4
  93. package/dist/token-goat-chunk-USILZ3T3.mjs +53 -0
  94. package/dist/{token-goat-chunk-MELOKFDJ.mjs → token-goat-chunk-VES7EL7O.mjs} +7 -1
  95. package/dist/{token-goat-chunk-7CPMDFGB.mjs → token-goat-chunk-VL3YIFHZ.mjs} +389 -14
  96. package/dist/{token-goat-chunk-E5TK5DNO.mjs → token-goat-chunk-VPBBTSJR.mjs} +356 -129
  97. package/dist/{token-goat-chunk-YOOVFPTP.mjs → token-goat-chunk-W3QCJS6G.mjs} +10 -2
  98. package/dist/{token-goat-chunk-LZNBQTDK.mjs → token-goat-chunk-WY3L4DVT.mjs} +11 -7
  99. package/dist/token-goat-chunk-XKI4SEMX.mjs +66 -0
  100. package/dist/token-goat-chunk-XU4P6Z24.mjs +133 -0
  101. package/dist/{token-goat-chunk-H5J3C56Q.mjs → token-goat-chunk-Y776AENC.mjs} +112 -26
  102. package/dist/token-goat-chunk-YARZFCZS.mjs +359 -0
  103. package/dist/{token-goat-chunk-S4VSXURL.mjs → token-goat-chunk-Z44YO3QZ.mjs} +4 -0
  104. package/dist/token-goat-chunk-Z57YODA2.mjs +35 -0
  105. package/dist/{token-goat-chunk-PQ53BSCF.mjs → token-goat-chunk-ZCDTCVIS.mjs} +48 -29
  106. package/dist/token-goat-chunk-ZEJVMUQH.mjs +48 -0
  107. package/dist/{token-goat-chunk-BGHSSJUA.mjs → token-goat-chunk-ZFOBKUWH.mjs} +1 -1
  108. package/dist/token-goat-chunk-ZMBL6UVV.mjs +110 -0
  109. package/dist/{token-goat-chunk-PKRWMHVP.mjs → token-goat-chunk-ZQSJMO2R.mjs} +338 -170
  110. package/dist/token-goat-hook-client.cjs +87 -23
  111. package/dist/token-goat-hook-client.mjs +3 -3
  112. package/dist/token-goat-hook.mjs +46 -30
  113. package/dist/token-goat.core.mjs +6 -6
  114. package/docs/C4_RUNTIME_ARCHITECTURE.md +1 -1
  115. package/docs/cli.md +80 -46
  116. package/docs/install.md +47 -14
  117. package/docs/security.md +7 -7
  118. package/package.json +17 -7
  119. package/scripts/verify-native-dist.mjs +386 -0
  120. package/dist/token-goat-chunk-2NNUA2LR.mjs +0 -143
  121. package/dist/token-goat-chunk-44BM7DDQ.mjs +0 -294
  122. package/dist/token-goat-chunk-C5YPNZKQ.mjs +0 -318
  123. package/dist/token-goat-chunk-CIQ2FTY3.mjs +0 -1990
  124. package/dist/token-goat-chunk-EUSDXRXU.mjs +0 -1429
  125. package/dist/token-goat-chunk-G7IWXCFF.mjs +0 -456
  126. package/dist/token-goat-chunk-JTKCQMQA.mjs +0 -418
  127. package/dist/token-goat-chunk-ORNFMIER.mjs +0 -295
  128. package/dist/token-goat-chunk-VQ6F6T7X.mjs +0 -36
  129. package/dist/token-goat-chunk-YAGLESS3.mjs +0 -23
  130. package/dist/token-goat-chunk-YKSRAWUU.mjs +0 -33
  131. package/dist/token-goat-chunk-Z6KBMOBI.mjs +0 -53
@@ -1,456 +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-H5J3C56Q.mjs";
10
- import {
11
- WEB_FETCH_KEY_SEP,
12
- getSessionBashOutputs,
13
- getSessionBashReruns,
14
- getSessionFiles,
15
- getSessionWebFetches
16
- } from "./token-goat-chunk-TDUT2CL6.mjs";
17
- import {
18
- getBashOutput
19
- } from "./token-goat-chunk-O6I2XU4P.mjs";
20
- import {
21
- findProject,
22
- loadConfig
23
- } from "./token-goat-chunk-TGOXNAHW.mjs";
24
- import {
25
- LOCK_WAIT_MS_HARDENED,
26
- atomicWriteText,
27
- ensureDirSync,
28
- runGit,
29
- toKB,
30
- withFileLock,
31
- withRetryOnLock
32
- } from "./token-goat-chunk-XYWPOSCN.mjs";
33
- import {
34
- foldPath,
35
- sleepSync
36
- } from "./token-goat-chunk-TCQANXYC.mjs";
37
- import {
38
- displaySafePath,
39
- displaySafeText,
40
- neutralizeSpokenMarkers
41
- } from "./token-goat-chunk-NMTKNYGF.mjs";
42
- import {
43
- dataDir
44
- } from "./token-goat-chunk-MELOKFDJ.mjs";
45
- import {
46
- init_define_import_meta_env
47
- } from "./token-goat-chunk-A37V4PBF.mjs";
48
-
49
- // src/manifest.ts
50
- init_define_import_meta_env();
51
- import { spawnSync } from "node:child_process";
52
-
53
- // src/project_memory.ts
54
- init_define_import_meta_env();
55
- import * as fs from "node:fs";
56
- import * as path from "node:path";
57
- var MAX_ENTRIES = 30;
58
- var MAX_VALUE_LEN = 300;
59
- var MAX_TOTAL_CHARS = 4e3;
60
- var KEY_RE = /^[A-Za-z0-9_-]{1,80}$/;
61
- function ordinal(a, b) {
62
- return a < b ? -1 : a > b ? 1 : 0;
63
- }
64
- function memoryPath(projectHash) {
65
- return path.join(dataDir(), "projects", `${projectHash}_memory.toml`);
66
- }
67
- function validateKey(key) {
68
- if (!KEY_RE.test(key)) {
69
- throw new Error(
70
- `Invalid memory key ${JSON.stringify(key)}: use only letters, digits, hyphens, underscores (max 80 chars)`
71
- );
72
- }
73
- }
74
- function parseTOML(content, unparsed = []) {
75
- const result = {};
76
- for (const [i, line] of content.split("\n").entries()) {
77
- const trimmed = line.trim();
78
- if (!trimmed || trimmed.startsWith("#")) {
79
- continue;
80
- }
81
- const match = trimmed.match(/^([A-Za-z0-9_-]+)\s*=\s*"(.*)"\s*$/);
82
- if (match) {
83
- const [, key, value] = match;
84
- if (key && value !== void 0) {
85
- const unescaped = value.replace(/\\([\\nrt"])/g, (_, c) => {
86
- switch (c) {
87
- case "\\":
88
- return "\\";
89
- case "n":
90
- return "\n";
91
- case "r":
92
- return "\r";
93
- case '"':
94
- return '"';
95
- default:
96
- return _;
97
- }
98
- });
99
- result[key] = unescaped;
100
- }
101
- } else {
102
- unparsed.push(i + 1);
103
- }
104
- }
105
- return result;
106
- }
107
- function loadRaw(filePath, forUpdate = false) {
108
- let content = "";
109
- try {
110
- withRetryOnLock(() => {
111
- content = fs.readFileSync(filePath, "utf-8");
112
- });
113
- } catch (err) {
114
- if (err.code === "ENOENT") return {};
115
- throw err;
116
- }
117
- const unparsed = [];
118
- const entries = parseTOML(content, unparsed);
119
- if (forUpdate && unparsed.length > 0) {
120
- const one = unparsed.length === 1;
121
- throw new Error(`Not updating ${filePath}: ${one ? "line" : "lines"} ${unparsed.join(", ")} ${one ? "is" : "are"} not in the key = "value" form, and saving would drop ${one ? "it" : "them"}. Fix or remove ${one ? "it" : "them"}, then try again.`);
122
- }
123
- return entries;
124
- }
125
- function save(filePath, entries) {
126
- const lines = [];
127
- const sorted = Object.entries(entries).sort(([a], [b]) => ordinal(a, b));
128
- for (const [k, v] of sorted) {
129
- const escaped = v.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\r/g, "\\r").replace(/\n/g, "\\n");
130
- lines.push(`${k} = "${escaped}"`);
131
- }
132
- const content = lines.length > 0 ? lines.join("\n") + "\n" : "";
133
- const dir = path.dirname(filePath);
134
- ensureDirSync(dir);
135
- atomicWriteText(filePath, content);
136
- }
137
- function loadEntries(projectHash) {
138
- return loadRaw(memoryPath(projectHash));
139
- }
140
- function setEntry(projectHash, key, value) {
141
- validateKey(key);
142
- const p = memoryPath(projectHash);
143
- const dir = path.dirname(p);
144
- ensureDirSync(dir);
145
- const doSet = () => {
146
- const entries = loadRaw(p, true);
147
- const isNewKey = !(key in entries);
148
- if (isNewKey && Object.keys(entries).length >= MAX_ENTRIES) {
149
- const keysToKeep = MAX_ENTRIES - 1;
150
- const allKeys = Object.keys(entries).sort((a, b) => ordinal(a, b));
151
- for (const k of allKeys.slice(keysToKeep)) {
152
- delete entries[k];
153
- }
154
- }
155
- entries[key] = value;
156
- save(p, entries);
157
- return true;
158
- };
159
- underNotesLock(p, doSet);
160
- }
161
- function underNotesLock(p, update) {
162
- const lockPath = `${p}.lock`;
163
- ensureDirSync(path.dirname(p));
164
- for (let attempt = 1; attempt <= 3; attempt++) {
165
- if (withFileLock(lockPath, update, { waitMs: LOCK_WAIT_MS_HARDENED }) !== void 0) return;
166
- if (fs.existsSync(lockPath)) break;
167
- if (attempt < 3) sleepSync(50 * attempt);
168
- }
169
- throw new Error(`Could not lock ${p} for writing; no note was changed. Another token-goat process may be writing notes: try again.`);
170
- }
171
- function unsetEntry(projectHash, key) {
172
- validateKey(key);
173
- const p = memoryPath(projectHash);
174
- const doUnset = () => {
175
- const entries = loadRaw(p, true);
176
- if (key in entries) {
177
- delete entries[key];
178
- save(p, entries);
179
- }
180
- return true;
181
- };
182
- underNotesLock(p, doUnset);
183
- }
184
- function clearAll(projectHash) {
185
- const p = memoryPath(projectHash);
186
- const doClear = () => {
187
- if (fs.existsSync(p)) {
188
- save(p, {});
189
- }
190
- return true;
191
- };
192
- underNotesLock(p, doClear);
193
- }
194
- function buildInjection(projectHash) {
195
- try {
196
- const entries = loadEntries(projectHash);
197
- if (Object.keys(entries).length === 0) {
198
- return null;
199
- }
200
- const header = '### Project notes (`token-goat note set <key> "<finding>"`)';
201
- const lines = [header];
202
- let total = header.length;
203
- let skipped = 0;
204
- const entries_list = Object.entries(entries).sort(([a], [b]) => ordinal(a, b)).slice(0, MAX_ENTRIES);
205
- for (const [key, val] of entries_list) {
206
- const display = val.length <= MAX_VALUE_LEN ? val : val.slice(0, MAX_VALUE_LEN) + "\u2026";
207
- const line = `- **${key}**: ${display}`;
208
- if (total + line.length + 1 > MAX_TOTAL_CHARS) {
209
- skipped++;
210
- continue;
211
- }
212
- lines.push(line);
213
- total += line.length + 1;
214
- }
215
- if (skipped > 0) {
216
- while (lines.length > 1 && total + `- (+${skipped} more memory entries omitted -- total size limit reached)`.length + 1 > MAX_TOTAL_CHARS) {
217
- const popped = lines.pop();
218
- total -= popped.length + 1;
219
- skipped++;
220
- }
221
- lines.push(`- (+${skipped} more memory entries omitted -- total size limit reached)`);
222
- }
223
- return lines.join("\n");
224
- } catch {
225
- return null;
226
- }
227
- }
228
- function projectNotesFor(cwd) {
229
- if (cwd === void 0) return null;
230
- try {
231
- const project = findProject(cwd);
232
- return project === null ? null : buildInjection(project.hash);
233
- } catch {
234
- return null;
235
- }
236
- }
237
-
238
- // src/manifest.ts
239
- var MEM_EPOCH_TIMEOUT_MS = 800;
240
- var MAX_ROWS = 40;
241
- function appendCappedSection(lines, header, rows, cap) {
242
- if (rows.length === 0) return;
243
- lines.push("");
244
- lines.push(header);
245
- for (const row of rows.slice(0, cap)) lines.push(row);
246
- if (rows.length > cap) lines.push(`- ...and ${rows.length - cap} more`);
247
- }
248
- function renderReadRow(entry) {
249
- const kb = Math.max(1, toKB(entry.sizeBytes));
250
- const plural = entry.readCount === 1 ? "read" : "reads";
251
- const edited = entry.wasEdited ? ", edited" : "";
252
- return `- ${displaySafePath(entry.path)} (${kb}kb, ${entry.readCount} ${plural}${edited})`;
253
- }
254
- function renderSymbolReadRow(entry) {
255
- return `- ${displaySafePath(entry.path)} (symbols: ${(entry.symbols_read ?? []).map(displaySafeText).join(", ")})`;
256
- }
257
- function mergeManifestFiles(parent, siblingFiles) {
258
- const byPath = /* @__PURE__ */ new Map();
259
- for (const f of parent) byPath.set(foldPath(f.path), f);
260
- for (const f of siblingFiles) {
261
- const key = foldPath(f.path);
262
- const prev = byPath.get(key);
263
- if (prev === void 0) {
264
- byPath.set(key, f);
265
- continue;
266
- }
267
- const mergedSymbols = [.../* @__PURE__ */ new Set([...prev.symbols_read ?? [], ...f.symbols_read ?? []])];
268
- byPath.set(key, {
269
- path: prev.path,
270
- readCount: Math.max(prev.readCount, f.readCount),
271
- lastReadAt: Math.max(prev.lastReadAt, f.lastReadAt),
272
- wasEdited: prev.wasEdited || f.wasEdited,
273
- sizeBytes: f.lastReadAt >= prev.lastReadAt ? f.sizeBytes : prev.sizeBytes,
274
- ...prev.wasTruncated || f.wasTruncated ? { wasTruncated: true } : {},
275
- ...mergedSymbols.length > 0 ? { symbols_read: mergedSymbols } : {}
276
- });
277
- }
278
- return Array.from(byPath.values());
279
- }
280
- function renderWebFetchRow(key, cacheId) {
281
- const [url = key, prompt = ""] = key.split(WEB_FETCH_KEY_SEP);
282
- const promptSuffix = prompt ? `, prompt: ${neutralizeSpokenMarkers(JSON.stringify(prompt))}` : "";
283
- return `- ${displaySafeText(url)} (cacheId: ${cacheId}${promptSuffix})`;
284
- }
285
- function selectManifestFiles(siblings) {
286
- const ownFiles = [...getSessionFiles().values()];
287
- const siblingFiles = siblings.flatMap((s) => s.files);
288
- const files = siblingFiles.length > 0 ? mergeManifestFiles(ownFiles, siblingFiles) : ownFiles;
289
- const editedFiles = files.filter((f) => f.wasEdited);
290
- const readFiles = files.filter((f) => f.readCount > 0 && !f.wasEdited && !isNoisePath(f.path));
291
- const symbolOnlyFiles = files.filter((f) => f.readCount === 0 && !f.wasEdited && (f.symbols_read?.length ?? 0) > 0);
292
- return { files, readFiles, editedFiles, symbolOnlyFiles };
293
- }
294
- function selectManifestWebFetches(siblings) {
295
- const merged = /* @__PURE__ */ new Map();
296
- for (const sibling of siblings) for (const [key, cacheId] of sibling.webFetches) merged.set(key, cacheId);
297
- for (const [key, cacheId] of getSessionWebFetches()) merged.set(key, cacheId);
298
- return [...merged.entries()];
299
- }
300
- function manifestPrintedPaths(sessionId, limit, cwd, transcriptPath) {
301
- const { printed } = buildManifestParts(sessionId, cwd, transcriptPath);
302
- return printed.slice(0, limit);
303
- }
304
- function buildManifestParts(sessionId, cwd, transcriptPath) {
305
- const siblings = sessionId !== void 0 ? listSiblingSessionStates(sessionId) : [];
306
- const { files, readFiles, editedFiles, symbolOnlyFiles } = selectManifestFiles(siblings);
307
- const webFetches = selectManifestWebFetches(siblings);
308
- const lines = [];
309
- lines.push("## Session context");
310
- lines.push(`Files read: ${readFiles.length}`);
311
- lines.push(`Files edited: ${editedFiles.length}`);
312
- const fileRows = [];
313
- const appendFileSection = (header, entries, render) => {
314
- const rows = entries.map(render);
315
- appendCappedSection(lines, header, rows, MAX_ROWS);
316
- for (let i = 0; i < Math.min(rows.length, MAX_ROWS); i++) fileRows.push({ path: displaySafePath(entries[i].path), row: rows[i] });
317
- };
318
- appendFileSection("### Edited files", editedFiles, (entry) => `- ${displaySafePath(entry.path)}`);
319
- const notes = projectNotesFor(cwd);
320
- if (notes !== null) lines.push("", notes);
321
- appendFileSection("### Surgically read files (symbol/section reads, never read whole)", symbolOnlyFiles, renderSymbolReadRow);
322
- appendFileSection("### Read files", readFiles, renderReadRow);
323
- appendCappedSection(lines, "### Web URLs fetched", webFetches.map(([key, cacheId]) => renderWebFetchRow(key, cacheId)), MAX_ROWS);
324
- lines.push(...buildSafeToDiscardSection(files));
325
- lines.push(...buildMemEpochSection());
326
- const text = capManifestChars(lines.join("\n"), sessionId, cwd, transcriptPath);
327
- const seen = /* @__PURE__ */ new Set();
328
- const printed = [];
329
- for (const { path: path2, row } of fileRows) {
330
- if (seen.has(path2) || !(text.includes(row + "\n") || text.endsWith(row))) continue;
331
- seen.add(path2);
332
- printed.push(path2);
333
- }
334
- return { text, printed };
335
- }
336
- function buildManifest(sessionId, cwd, transcriptPath) {
337
- return buildManifestParts(sessionId, cwd, transcriptPath).text;
338
- }
339
- function gitDirtySignals(cwd) {
340
- const timeoutMs = loadConfig().hints.git_hint_max_ms;
341
- let hasPendingDiff = false;
342
- try {
343
- const diffResult = runGit(["diff", "--no-color", "--stat", "HEAD"], { cwd, timeoutMs });
344
- hasPendingDiff = diffResult.exitCode === 0 && diffResult.stdout.trim() !== "";
345
- } catch {
346
- }
347
- let hasUncommittedChanges = false;
348
- try {
349
- const statusResult = runGit(["status", "--porcelain"], { cwd, timeoutMs });
350
- hasUncommittedChanges = statusResult.exitCode === 0 && statusResult.stdout.trim() !== "";
351
- } catch {
352
- }
353
- return { hasPendingDiff, hasUncommittedChanges };
354
- }
355
- function adaptiveCharBonus(sessionId, cwd, transcriptPath) {
356
- if (!cwd) return 0;
357
- const cache = loadSessionCache(sessionId ?? "") ?? {};
358
- const ageSecs = cache.created_ts !== void 0 ? Math.max(0, Date.now() / 1e3 - cache.created_ts) : 0;
359
- const contextPressure = getContextPressure(cache, transcriptPath);
360
- const { hasPendingDiff, hasUncommittedChanges } = gitDirtySignals(cwd);
361
- if (!hasPendingDiff && !hasUncommittedChanges) return 0;
362
- const baseline = computeAdaptiveBudget(cache, ageSecs, { contextPressure });
363
- const withGitSignal = computeAdaptiveBudget(cache, ageSecs, { hasPendingDiff, hasUncommittedChanges, contextPressure });
364
- const deltaTokens = Math.max(0, withGitSignal - baseline);
365
- return deltaTokens * 3;
366
- }
367
- function capManifestChars(manifest, sessionId, cwd, transcriptPath) {
368
- const cap = loadConfig().compact_assist.max_manifest_chars;
369
- if (cap <= 0) return manifest;
370
- if (manifest.length <= cap) return manifest;
371
- const effectiveCap = cap + adaptiveCharBonus(sessionId, cwd, transcriptPath);
372
- if (manifest.length <= effectiveCap) return manifest;
373
- const omitted = manifest.length - effectiveCap;
374
- return manifest.slice(0, effectiveCap) + `
375
- ...(manifest truncated at ${effectiveCap} chars; ${omitted} chars omitted)`;
376
- }
377
- function buildSafeToDiscardSection(files) {
378
- const rerunHashes = getSessionBashReruns();
379
- const bashOutputs = getSessionBashOutputs();
380
- const rerunHashSet = new Set(rerunHashes);
381
- const rerunRows = [];
382
- for (const hash of rerunHashes) {
383
- const id = bashOutputs.find(([h]) => h === hash)?.[1];
384
- if (id === void 0) continue;
385
- const entry = getBashOutput(id);
386
- if (entry === null) continue;
387
- const flatCommand = neutralizeSpokenMarkers(entry.command.replace(/[\t\r\n]+/g, " "));
388
- rerunRows.push("- `" + flatCommand + "` \u2014 an older run of this exact command was superseded; recall the surviving copy with `bash-output " + id + " --full`");
389
- }
390
- const supersededReadRows = [];
391
- for (const f of files) {
392
- if (f.readCount > 1 || f.wasEdited) {
393
- const reason = f.wasEdited ? "edited after being read" : "re-read " + f.readCount + "x";
394
- supersededReadRows.push("- " + displaySafePath(f.path) + " (" + reason + " \u2014 only the latest content already in context is current)");
395
- }
396
- }
397
- const cachedOutputRows = [];
398
- for (const [hash, id] of bashOutputs) {
399
- if (rerunHashSet.has(hash)) continue;
400
- const entry = getBashOutput(id);
401
- if (entry === null) continue;
402
- const flatCommand = neutralizeSpokenMarkers(entry.command.replace(/[\t\r\n]+/g, " "));
403
- cachedOutputRows.push("- `" + flatCommand + "` \u2014 recallable via `bash-output " + id + " --full`");
404
- }
405
- const total = rerunRows.length + supersededReadRows.length + cachedOutputRows.length;
406
- if (total === 0) return [];
407
- const lines = [];
408
- lines.push("");
409
- lines.push("### SAFE_TO_DISCARD (" + total + " items \u2014 provably inert; each is recallable, not gone)");
410
- appendCappedSection(lines, "Superseded reruns (" + rerunRows.length + "):", rerunRows, MAX_ROWS);
411
- appendCappedSection(lines, "Superseded file reads (" + supersededReadRows.length + "):", supersededReadRows, MAX_ROWS);
412
- appendCappedSection(lines, "Other cached bash outputs (" + cachedOutputRows.length + "):", cachedOutputRows, MAX_ROWS);
413
- return lines;
414
- }
415
- function buildMemEpochSection() {
416
- let result;
417
- try {
418
- result = spawnSync("mem", ["epoch"], {
419
- encoding: "utf-8",
420
- timeout: MEM_EPOCH_TIMEOUT_MS,
421
- windowsHide: true
422
- });
423
- } catch {
424
- return [];
425
- }
426
- if (result.error !== void 0 || result.status !== 0) return [];
427
- const stdout = typeof result.stdout === "string" ? result.stdout.trim() : "";
428
- if (!/^\d+$/.test(stdout)) return [];
429
- return [
430
- "",
431
- "### mem epoch",
432
- `mem epoch: ${stdout} (no live TGMEM block is tracked in this session -- only the epoch counter is folded in; see buildMemEpochSection's doc comment)`
433
- ];
434
- }
435
- 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.";
436
- 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.";
437
- var BUDGET_ESCALATION_MARKER = "TG-BUDGET-ESCALATION:";
438
- function summaryBudgetDirective(budgetChars) {
439
- if (budgetChars <= 0) return "";
440
- 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>\`.`;
441
- }
442
-
443
- export {
444
- loadEntries,
445
- setEntry,
446
- unsetEntry,
447
- clearAll,
448
- projectNotesFor,
449
- renderWebFetchRow,
450
- manifestPrintedPaths,
451
- buildManifest,
452
- MANIFEST_PREAMBLE,
453
- MANIFEST_RECOVERY_PREAMBLE,
454
- BUDGET_ESCALATION_MARKER,
455
- summaryBudgetDirective
456
- };