token-goat 2.9.19 → 2.9.20

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 (50) hide show
  1. package/README.md +3 -1
  2. package/dist/token-goat-chunk-2CLWWRFR.mjs +26 -0
  3. package/dist/{token-goat-chunk-WKO5TVNA.mjs → token-goat-chunk-2Q3N5KUQ.mjs} +531 -571
  4. package/dist/{token-goat-chunk-DA6TIDLI.mjs → token-goat-chunk-3OGZOFLS.mjs} +18 -13
  5. package/dist/{token-goat-chunk-PIAESKVU.mjs → token-goat-chunk-3VTJC7KU.mjs} +568 -429
  6. package/dist/{token-goat-chunk-ZGQXRYKE.mjs → token-goat-chunk-6LJNM4ZZ.mjs} +1 -1
  7. package/dist/{token-goat-chunk-SOKAPOOC.mjs → token-goat-chunk-74ADIZZX.mjs} +46 -47
  8. package/dist/{token-goat-chunk-LACH3WKS.mjs → token-goat-chunk-ASTBLE2R.mjs} +3 -3
  9. package/dist/{token-goat-chunk-VJQBYSXG.mjs → token-goat-chunk-AU2K2QHR.mjs} +3 -3
  10. package/dist/token-goat-chunk-BQIC3AVL.mjs +292 -0
  11. package/dist/{token-goat-chunk-P46RTOAQ.mjs → token-goat-chunk-CBXLE54Q.mjs} +10 -7
  12. package/dist/{token-goat-chunk-3W5P673V.mjs → token-goat-chunk-DNAF26L4.mjs} +1 -1
  13. package/dist/{token-goat-chunk-FQYMZASI.mjs → token-goat-chunk-DPHJU3P7.mjs} +789 -4456
  14. package/dist/{token-goat-chunk-FX5DHKGF.mjs → token-goat-chunk-DW4VKU7D.mjs} +4 -4
  15. package/dist/token-goat-chunk-DYUBZZNP.mjs +198 -0
  16. package/dist/{token-goat-chunk-EP7TCWHM.mjs → token-goat-chunk-ERGHDBC6.mjs} +70 -65
  17. package/dist/token-goat-chunk-EUZKG7ZO.mjs +304 -0
  18. package/dist/{token-goat-chunk-AVRD7SBO.mjs → token-goat-chunk-FWYZVS3E.mjs} +270 -29
  19. package/dist/token-goat-chunk-G6SYQQO7.mjs +41 -0
  20. package/dist/{token-goat-chunk-62VJ47WN.mjs → token-goat-chunk-GIPMOGOI.mjs} +5 -5
  21. package/dist/{token-goat-chunk-L2UOJBV4.mjs → token-goat-chunk-H4VC5TR6.mjs} +27 -19
  22. package/dist/{token-goat-chunk-2GTB5RBZ.mjs → token-goat-chunk-I5PQRHFE.mjs} +11 -271
  23. package/dist/{token-goat-chunk-MU6I4IDI.mjs → token-goat-chunk-ITWYDOKP.mjs} +11 -7
  24. package/dist/{token-goat-chunk-IBTFGZBX.mjs → token-goat-chunk-K3ZNBN4U.mjs} +2 -2
  25. package/dist/{token-goat-chunk-S7RFIX4Y.mjs → token-goat-chunk-K5XPIUVB.mjs} +45 -14
  26. package/dist/token-goat-chunk-KT75DZK4.mjs +1989 -0
  27. package/dist/{token-goat-chunk-F24NE3FO.mjs → token-goat-chunk-MNJWG2ZO.mjs} +2 -2
  28. package/dist/{token-goat-chunk-NJKNAC37.mjs → token-goat-chunk-MUJV7BR3.mjs} +1 -1
  29. package/dist/{token-goat-chunk-FJZ5MZK7.mjs → token-goat-chunk-ODF7H7WS.mjs} +2 -2
  30. package/dist/{token-goat-chunk-GYC34EGE.mjs → token-goat-chunk-ONMU7BON.mjs} +2 -2
  31. package/dist/{token-goat-chunk-KWM6KBPA.mjs → token-goat-chunk-P4XBHZXU.mjs} +1 -1
  32. package/dist/{token-goat-chunk-7DGTVBWP.mjs → token-goat-chunk-PAVWB4L4.mjs} +159 -1863
  33. package/dist/{token-goat-chunk-DHIXE6GV.mjs → token-goat-chunk-PTW22MRC.mjs} +1 -1
  34. package/dist/token-goat-chunk-SL454EN5.mjs +1816 -0
  35. package/dist/token-goat-chunk-SP5QR2HN.mjs +1379 -0
  36. package/dist/{token-goat-chunk-BTKDZW7F.mjs → token-goat-chunk-T46UKRFM.mjs} +1 -1
  37. package/dist/{token-goat-chunk-JNIFSVWM.mjs → token-goat-chunk-T63VHOL3.mjs} +5 -1
  38. package/dist/token-goat-chunk-VSJGPEBB.mjs +248 -0
  39. package/dist/{token-goat-chunk-EXLLLIC3.mjs → token-goat-chunk-VYXGHGUY.mjs} +3 -3
  40. package/dist/token-goat-chunk-W6QYCWAT.mjs +128 -0
  41. package/dist/{token-goat-chunk-HPMMLV37.mjs → token-goat-chunk-Z4ALQADF.mjs} +256 -341
  42. package/dist/token-goat-chunk-ZHFM4DHJ.mjs +324 -0
  43. package/dist/token-goat-hook.mjs +17 -11
  44. package/dist/token-goat.core.mjs +27 -19
  45. package/docs/C4_RUNTIME_ARCHITECTURE.md +1 -1
  46. package/docs/cli.md +13 -12
  47. package/docs/install.md +1 -1
  48. package/docs/security.md +2 -2
  49. package/package.json +3 -2
  50. package/dist/token-goat-chunk-NYFYIRG3.mjs +0 -35
@@ -1,47 +1,39 @@
1
1
  import { createRequire as __cjsRequire } from 'node:module';
2
2
  const require = __cjsRequire(import.meta.url);
3
3
  import {
4
- accumulateResidentLine,
5
- claudeConfigDir,
6
- createResidentContextStats,
7
4
  enqueueDirtyPathsSafe,
8
- estimateTokens,
9
5
  fenceUntrusted,
10
6
  getToolName,
11
7
  getTrackedFiles,
12
- scanAndRecord,
13
- summarizeResidentContext
14
- } from "./token-goat-chunk-FQYMZASI.mjs";
8
+ scanAndRecord
9
+ } from "./token-goat-chunk-DPHJU3P7.mjs";
15
10
  import {
16
11
  RECALL_DEFAULT_LIMIT,
17
- commandHash,
18
- getBashOutput,
19
12
  indexRecallEntry,
20
13
  listRecentRecall,
21
- normalizeCommandForCacheKey,
22
14
  searchRecall
23
- } from "./token-goat-chunk-7DGTVBWP.mjs";
15
+ } from "./token-goat-chunk-SL454EN5.mjs";
24
16
  import {
25
17
  isBlobStale,
26
18
  loadBlob,
27
19
  redactSecrets,
28
20
  storeBlob
29
- } from "./token-goat-chunk-S7RFIX4Y.mjs";
21
+ } from "./token-goat-chunk-K5XPIUVB.mjs";
30
22
  import {
31
23
  parserFingerprintForLanguage
32
- } from "./token-goat-chunk-EP7TCWHM.mjs";
24
+ } from "./token-goat-chunk-ERGHDBC6.mjs";
33
25
  import {
34
26
  getProjectFileEntries,
35
27
  projectScopeClause
36
- } from "./token-goat-chunk-IBTFGZBX.mjs";
28
+ } from "./token-goat-chunk-K3ZNBN4U.mjs";
37
29
  import {
38
30
  getDb
39
- } from "./token-goat-chunk-JNIFSVWM.mjs";
31
+ } from "./token-goat-chunk-T63VHOL3.mjs";
40
32
  import {
41
33
  fingerprintFile,
42
34
  getDisplayRoot,
43
35
  shortFingerprint
44
- } from "./token-goat-chunk-SOKAPOOC.mjs";
36
+ } from "./token-goat-chunk-74ADIZZX.mjs";
45
37
  import {
46
38
  registerReset
47
39
  } from "./token-goat-chunk-EEIDFMEM.mjs";
@@ -52,7 +44,7 @@ import {
52
44
  foldPath,
53
45
  globalDbPath,
54
46
  pad
55
- } from "./token-goat-chunk-ZGQXRYKE.mjs";
47
+ } from "./token-goat-chunk-6LJNM4ZZ.mjs";
56
48
  import {
57
49
  UNTRUSTED_TOOL_TAG,
58
50
  UNTRUSTED_WEB_TAG,
@@ -132,7 +124,7 @@ var DEFAULT_STDIN_TIMEOUT_MS = 5e3;
132
124
  var MAX_STDIN_WALL_MS = 6e4;
133
125
  var MAX_STDIN_BYTES = 64 * 1024 * 1024;
134
126
  function readStdinJson(timeoutMs = DEFAULT_STDIN_TIMEOUT_MS, maxBytes = MAX_STDIN_BYTES) {
135
- return new Promise((resolve3, reject) => {
127
+ return new Promise((resolve2, reject) => {
136
128
  const chunks = [];
137
129
  let totalBytes = 0;
138
130
  let settled = false;
@@ -178,7 +170,7 @@ function readStdinJson(timeoutMs = DEFAULT_STDIN_TIMEOUT_MS, maxBytes = MAX_STDI
178
170
  return;
179
171
  }
180
172
  try {
181
- resolve3(JSON.parse(text));
173
+ resolve2(JSON.parse(text));
182
174
  } catch (err) {
183
175
  reject(err instanceof Error ? err : new Error(String(err)));
184
176
  }
@@ -972,253 +964,6 @@ function reconcileProject(opts = {}) {
972
964
  };
973
965
  }
974
966
 
975
- // src/waste.ts
976
- init_define_import_meta_env();
977
- import * as fs3 from "node:fs";
978
- import * as path from "node:path";
979
- function projectTranscriptsDir(projectRoot) {
980
- const rootStr = path.resolve(projectRoot);
981
- const slug = rootStr.replace(/[^A-Za-z0-9]/g, "-");
982
- return path.join(claudeConfigDir(), "projects", slug);
983
- }
984
- function findLatestTranscript(projectRoot) {
985
- const dir = projectTranscriptsDir(projectRoot);
986
- let entries;
987
- try {
988
- entries = fs3.readdirSync(dir).filter((f) => f.endsWith(".jsonl"));
989
- } catch {
990
- return null;
991
- }
992
- let best = null;
993
- for (const name of entries) {
994
- const full = path.join(dir, name);
995
- let stat;
996
- try {
997
- stat = fs3.statSync(full);
998
- } catch {
999
- continue;
1000
- }
1001
- if (best === null || stat.mtimeMs > best.mtimeMs) best = { file: full, mtimeMs: stat.mtimeMs };
1002
- }
1003
- return best?.file ?? null;
1004
- }
1005
- function safeStringify(value) {
1006
- try {
1007
- return JSON.stringify(value) ?? "";
1008
- } catch {
1009
- return "";
1010
- }
1011
- }
1012
- var FILE_PATH_TOOLS = /* @__PURE__ */ new Set(["Read", "Edit", "Write", "NotebookEdit", "MultiEdit"]);
1013
- function extractFilePath(name, input) {
1014
- if (!FILE_PATH_TOOLS.has(name)) return null;
1015
- if (input === null || typeof input !== "object") return null;
1016
- const o = input;
1017
- const fp = o["file_path"];
1018
- if (typeof fp === "string") return fp;
1019
- const notebookPath = o["notebook_path"];
1020
- return typeof notebookPath === "string" ? notebookPath : null;
1021
- }
1022
- function extractCommand(name, input) {
1023
- if (name !== "Bash") return null;
1024
- if (input === null || typeof input !== "object") return null;
1025
- const cmd = input["command"];
1026
- return typeof cmd === "string" ? cmd : null;
1027
- }
1028
- function summarizeInput(name, input, filePath, command) {
1029
- if (filePath !== null) return filePath;
1030
- if (command !== null) return command.length > 100 ? `${command.slice(0, 100)}\u2026` : command;
1031
- if (input === null || typeof input !== "object") return "";
1032
- const o = input;
1033
- for (const key of ["pattern", "query", "path", "description", "prompt"]) {
1034
- const v = o[key];
1035
- if (typeof v === "string") return v.length > 100 ? `${v.slice(0, 100)}\u2026` : v;
1036
- }
1037
- const s = safeStringify(input);
1038
- return s.length > 100 ? `${s.slice(0, 100)}\u2026` : s;
1039
- }
1040
- function extractResultText(content) {
1041
- if (typeof content === "string") return content;
1042
- if (Array.isArray(content)) {
1043
- return content.map((b) => {
1044
- if (b !== null && typeof b === "object" && b["type"] === "text") {
1045
- const t = b["text"];
1046
- return typeof t === "string" ? t : "";
1047
- }
1048
- return "";
1049
- }).join("\n");
1050
- }
1051
- return "";
1052
- }
1053
- function parseTranscript(transcriptPath) {
1054
- const raw = fs3.readFileSync(transcriptPath, "utf-8");
1055
- const calls = [];
1056
- const resultTextById = /* @__PURE__ */ new Map();
1057
- const assistantTurns = [];
1058
- const resident = createResidentContextStats();
1059
- let seq = 0;
1060
- for (const line of raw.split("\n")) {
1061
- const trimmed = line.trim();
1062
- if (trimmed === "") continue;
1063
- let obj;
1064
- try {
1065
- obj = JSON.parse(trimmed);
1066
- } catch {
1067
- continue;
1068
- }
1069
- if (obj === null || typeof obj !== "object") continue;
1070
- const o = obj;
1071
- accumulateResidentLine(resident, o, trimmed.length);
1072
- const message = o["message"];
1073
- if (message === null || typeof message !== "object") continue;
1074
- const messageObj = message;
1075
- const content = messageObj["content"];
1076
- if (!Array.isArray(content)) continue;
1077
- const role = typeof messageObj["role"] === "string" ? messageObj["role"] : null;
1078
- const cwd = typeof o["cwd"] === "string" ? o["cwd"] : null;
1079
- let turnTextTokens = 0;
1080
- let sawTextBlock = false;
1081
- for (const block of content) {
1082
- if (block === null || typeof block !== "object") continue;
1083
- const b = block;
1084
- if (b["type"] === "tool_use" && typeof b["id"] === "string" && typeof b["name"] === "string") {
1085
- const name = b["name"];
1086
- const input = b["input"];
1087
- const filePath = extractFilePath(name, input);
1088
- const command = extractCommand(name, input);
1089
- calls.push({
1090
- seq: seq++,
1091
- id: b["id"],
1092
- name,
1093
- input,
1094
- filePath,
1095
- command,
1096
- summary: summarizeInput(name, input, filePath, command),
1097
- cwd
1098
- });
1099
- } else if (b["type"] === "tool_result" && typeof b["tool_use_id"] === "string") {
1100
- const id = b["tool_use_id"];
1101
- if (!resultTextById.has(id)) {
1102
- resultTextById.set(id, extractResultText(b["content"]));
1103
- }
1104
- } else if (role === "assistant" && b["type"] === "text" && typeof b["text"] === "string") {
1105
- sawTextBlock = true;
1106
- turnTextTokens += estimateTokens(b["text"]);
1107
- }
1108
- }
1109
- if (role === "assistant" && sawTextBlock) assistantTurns.push(turnTextTokens);
1110
- }
1111
- return { calls, resultTextById, assistantTurns, resident };
1112
- }
1113
- function costPerCall(parsed) {
1114
- return parsed.calls.map((c) => ({
1115
- ...c,
1116
- tokens: estimateTokens(parsed.resultTextById.get(c.id) ?? "")
1117
- }));
1118
- }
1119
- function aggregateSortedDesc(pairs) {
1120
- return [...pairs].map(([key, tokens]) => ({ key, tokens })).sort((a, b) => b.tokens - a.tokens);
1121
- }
1122
- function tokensByTool(costs) {
1123
- const m = /* @__PURE__ */ new Map();
1124
- for (const c of costs) m.set(c.name, (m.get(c.name) ?? 0) + c.tokens);
1125
- return aggregateSortedDesc(m);
1126
- }
1127
- function tokensByFile(costs) {
1128
- const m = /* @__PURE__ */ new Map();
1129
- for (const c of costs) {
1130
- if (c.filePath === null) continue;
1131
- m.set(c.filePath, (m.get(c.filePath) ?? 0) + c.tokens);
1132
- }
1133
- return aggregateSortedDesc(m);
1134
- }
1135
- function topExpensiveCalls(costs, n) {
1136
- return [...costs].sort((a, b) => b.tokens - a.tokens).slice(0, n);
1137
- }
1138
- function neverTouchedAgain(costs) {
1139
- const readsByFile = /* @__PURE__ */ new Map();
1140
- for (const c of costs) {
1141
- if (c.name !== "Read" || c.filePath === null) continue;
1142
- const arr = readsByFile.get(c.filePath) ?? [];
1143
- arr.push(c);
1144
- readsByFile.set(c.filePath, arr);
1145
- }
1146
- const out = [];
1147
- for (const [filePath, reads] of readsByFile) {
1148
- const firstSeq = Math.min(...reads.map((r) => r.seq));
1149
- const touchedLater = costs.some((c) => {
1150
- if (c.seq <= firstSeq) return false;
1151
- if (c.filePath === filePath) return true;
1152
- return safeStringify(c.input).includes(filePath);
1153
- });
1154
- if (!touchedLater) {
1155
- out.push({ filePath, tokens: reads.reduce((n, r) => n + r.tokens, 0) });
1156
- }
1157
- }
1158
- return out.sort((a, b) => b.tokens - a.tokens);
1159
- }
1160
- async function repeatedUncompressedBashCommands(costs) {
1161
- const groups = /* @__PURE__ */ new Map();
1162
- for (const c of costs) {
1163
- if (c.name !== "Bash" || c.command === null) continue;
1164
- const norm = normalizeCommandForCacheKey(c.command);
1165
- const arr = groups.get(norm) ?? [];
1166
- arr.push(c);
1167
- groups.set(norm, arr);
1168
- }
1169
- const out = [];
1170
- for (const [norm, calls] of groups) {
1171
- if (calls.length < 2) continue;
1172
- let cached = false;
1173
- for (const c of calls) {
1174
- try {
1175
- const hash = await commandHash(c.command, c.cwd);
1176
- if (getBashOutput(hash) !== null) {
1177
- cached = true;
1178
- break;
1179
- }
1180
- } catch {
1181
- }
1182
- }
1183
- if (cached) continue;
1184
- const totalTokens = calls.reduce((n, c) => n + c.tokens, 0);
1185
- out.push({
1186
- normalized: norm,
1187
- count: calls.length,
1188
- totalTokens,
1189
- avgTokens: Math.round(totalTokens / calls.length)
1190
- });
1191
- }
1192
- return out.sort((a, b) => b.totalTokens - a.totalTokens);
1193
- }
1194
- function assistantOutputCost(assistantTurns) {
1195
- const turnCount = assistantTurns.length;
1196
- let generatedTokens = 0;
1197
- let resendCeilingTokens = 0;
1198
- for (let i = 0; i < turnCount; i++) {
1199
- const tokens = assistantTurns[i] ?? 0;
1200
- generatedTokens += tokens;
1201
- resendCeilingTokens += tokens * (turnCount - 1 - i);
1202
- }
1203
- return { turnCount, generatedTokens, resendCeilingTokens };
1204
- }
1205
- async function buildWasteReport(transcriptPath, opts = {}) {
1206
- const parsed = parseTranscript(transcriptPath);
1207
- const costs = costPerCall(parsed);
1208
- const topN = opts.topN ?? 10;
1209
- return {
1210
- transcriptPath,
1211
- totalTokens: costs.reduce((n, c) => n + c.tokens, 0),
1212
- tokensByTool: tokensByTool(costs),
1213
- tokensByFile: tokensByFile(costs),
1214
- topCalls: topExpensiveCalls(costs, topN).map((c) => ({ seq: c.seq, name: c.name, summary: c.summary, tokens: c.tokens })),
1215
- neverTouchedAgain: neverTouchedAgain(costs),
1216
- repeatedUncompressedBash: await repeatedUncompressedBashCommands(costs),
1217
- assistantOutput: assistantOutputCost(parsed.assistantTurns),
1218
- residentContext: summarizeResidentContext(parsed.resident)
1219
- };
1220
- }
1221
-
1222
967
  // src/cli_recall.ts
1223
968
  init_define_import_meta_env();
1224
969
  var RECALL_COMMAND = {
@@ -1294,11 +1039,6 @@ export {
1294
1039
  runReconcile,
1295
1040
  isReconcileClean,
1296
1041
  reconcileProject,
1297
- projectTranscriptsDir,
1298
- findLatestTranscript,
1299
- safeStringify,
1300
- extractResultText,
1301
- buildWasteReport,
1302
1042
  RECALL_COMMAND,
1303
1043
  runRecallCommand,
1304
1044
  MAX_STDIN_BYTES,
@@ -2,22 +2,24 @@ import { createRequire as __cjsRequire } from 'node:module';
2
2
  const require = __cjsRequire(import.meta.url);
3
3
  import {
4
4
  ToolFilter,
5
- capTokens,
6
5
  compressedTokensSaved,
7
6
  deliverCompressed,
8
7
  dispatchArgv,
9
8
  filterByName,
10
- selectFilter,
9
+ selectFilter
10
+ } from "./token-goat-chunk-PAVWB4L4.mjs";
11
+ import {
12
+ capTokens,
11
13
  shlexSplit,
12
14
  storeBashOutputSync
13
- } from "./token-goat-chunk-7DGTVBWP.mjs";
15
+ } from "./token-goat-chunk-SL454EN5.mjs";
14
16
  import {
15
17
  recordStat
16
- } from "./token-goat-chunk-S7RFIX4Y.mjs";
18
+ } from "./token-goat-chunk-K5XPIUVB.mjs";
17
19
  import {
18
20
  detectHarness,
19
21
  loadConfig
20
- } from "./token-goat-chunk-SOKAPOOC.mjs";
22
+ } from "./token-goat-chunk-74ADIZZX.mjs";
21
23
  import {
22
24
  init_define_import_meta_env
23
25
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -160,19 +162,20 @@ function scheduleHeartbeat(startTime, intervalMs, write) {
160
162
  };
161
163
  }
162
164
  function resolveFilter(command, filterName, cwd) {
165
+ const effectiveCwd = cwd ?? process.cwd();
163
166
  let split;
164
167
  try {
165
168
  split = shlexSplit(command);
166
169
  } catch {
167
170
  split = null;
168
171
  }
169
- const argv = split === null ? [command] : dispatchArgv(split, cwd).argv;
172
+ const argv = split === null ? [command] : dispatchArgv(split, effectiveCwd).argv;
170
173
  if (filterName) {
171
174
  const named = filterByName(filterName);
172
175
  if (named !== null) return { filter: named, argv };
173
176
  }
174
177
  if (split === null) return { filter: null, argv };
175
- return { filter: selectFilter(split, cwd), argv };
178
+ return { filter: selectFilter(split, effectiveCwd), argv };
176
179
  }
177
180
  function baseSpawnOptions(timeout, cwd) {
178
181
  return { timeout: timeout * 1e3, cwd };
@@ -332,6 +335,7 @@ export {
332
335
  DEFAULT_TIMEOUT_SECONDS,
333
336
  MAX_CAPTURE_BYTES,
334
337
  DEFAULT_HEARTBEAT_INTERVAL_MS,
338
+ resolveFilter,
335
339
  run,
336
340
  runRaw
337
341
  };
@@ -2,12 +2,12 @@ import { createRequire as __cjsRequire } from 'node:module';
2
2
  const require = __cjsRequire(import.meta.url);
3
3
  import {
4
4
  getDb
5
- } from "./token-goat-chunk-JNIFSVWM.mjs";
5
+ } from "./token-goat-chunk-T63VHOL3.mjs";
6
6
  import {
7
7
  foldPath,
8
8
  globalDbPath,
9
9
  isCaseInsensitiveFs
10
- } from "./token-goat-chunk-ZGQXRYKE.mjs";
10
+ } from "./token-goat-chunk-6LJNM4ZZ.mjs";
11
11
  import {
12
12
  normalizePath
13
13
  } from "./token-goat-chunk-NMTKNYGF.mjs";
@@ -2,11 +2,11 @@ import { createRequire as __cjsRequire } from 'node:module';
2
2
  const require = __cjsRequire(import.meta.url);
3
3
  import {
4
4
  getDb
5
- } from "./token-goat-chunk-JNIFSVWM.mjs";
5
+ } from "./token-goat-chunk-T63VHOL3.mjs";
6
6
  import {
7
7
  getHarnessName,
8
8
  loadConfig
9
- } from "./token-goat-chunk-SOKAPOOC.mjs";
9
+ } from "./token-goat-chunk-74ADIZZX.mjs";
10
10
  import {
11
11
  registerReset
12
12
  } from "./token-goat-chunk-EEIDFMEM.mjs";
@@ -23,7 +23,7 @@ import {
23
23
  extractErrorMessage,
24
24
  sanitizeIdForFilename,
25
25
  tokenGoatHome
26
- } from "./token-goat-chunk-ZGQXRYKE.mjs";
26
+ } from "./token-goat-chunk-6LJNM4ZZ.mjs";
27
27
  import {
28
28
  displaySafeText
29
29
  } from "./token-goat-chunk-NMTKNYGF.mjs";
@@ -54,12 +54,6 @@ function stripAnsiEscapes(s) {
54
54
  }
55
55
  return s.replace(_ANSI_ESCAPE_RE, "");
56
56
  }
57
- function stripAnsi(s) {
58
- if (!s.includes("\x1B")) {
59
- return s;
60
- }
61
- return stripAnsiEscapes(s).replace(_PUA_RE, "");
62
- }
63
57
  function fmtBytes(n) {
64
58
  let value = n;
65
59
  const units = ["B", "KB", "MB", "GB", "TB"];
@@ -75,7 +69,7 @@ function fg(r, g, b) {
75
69
  return `${_E}[38;2;${r};${g};${b}m`;
76
70
  }
77
71
  function vlen(s) {
78
- return stripAnsi(s).length;
72
+ return stripAnsiEscapes(s).replace(_PUA_RE, "").length;
79
73
  }
80
74
  function padR(s, w) {
81
75
  return s + " ".repeat(Math.max(0, w - vlen(s)));
@@ -115,6 +109,41 @@ init_define_import_meta_env();
115
109
  import * as fs from "node:fs";
116
110
  import * as path from "node:path";
117
111
 
112
+ // src/token_estimate.ts
113
+ init_define_import_meta_env();
114
+ var BYTES_PER_TOKEN = {
115
+ text: 4,
116
+ dense: 1.45
117
+ };
118
+ var GUARD_MARGIN = 0.75;
119
+ function creditDivisor(cls = "text") {
120
+ return BYTES_PER_TOKEN[cls];
121
+ }
122
+ function guardDivisor(cls = "text") {
123
+ return BYTES_PER_TOKEN[cls] * GUARD_MARGIN;
124
+ }
125
+ var DENSE_ALPHABET = /^[A-Za-z0-9+/=_-]$/;
126
+ var MIN_DENSE_SAMPLE = 200;
127
+ var MIN_DENSE_DISTINCT = 16;
128
+ var CLASSIFY_SAMPLE_CHARS = 4096;
129
+ function classifyContent(text) {
130
+ const sample = text.slice(0, CLASSIFY_SAMPLE_CHARS);
131
+ if (sample.length < MIN_DENSE_SAMPLE) return "text";
132
+ let whitespace = 0;
133
+ let dense = 0;
134
+ const distinct = /* @__PURE__ */ new Set();
135
+ for (const ch of sample) {
136
+ if (ch === " " || ch === "\n" || ch === " " || ch === "\r") whitespace++;
137
+ else if (DENSE_ALPHABET.test(ch)) {
138
+ dense++;
139
+ distinct.add(ch);
140
+ }
141
+ }
142
+ if (whitespace / sample.length >= 0.05) return "text";
143
+ if (distinct.size < MIN_DENSE_DISTINCT) return "text";
144
+ return dense / sample.length >= 0.95 ? "dense" : "text";
145
+ }
146
+
118
147
  // src/render/stats_renderer.ts
119
148
  init_define_import_meta_env();
120
149
  var _STATS_MESSAGES_FALLBACK = {
@@ -777,7 +806,7 @@ function _renderByProjectSection(stats) {
777
806
  nameColor: C.TEXT_PRIMARY
778
807
  })
779
808
  );
780
- lines.push(`${_M} ${fg(...C.TEXT_DIM)}\u2514\u2500 ${p.hash} ${displaySafeText(stripAnsi(p.path))}${RESET}`);
809
+ lines.push(`${_M} ${fg(...C.TEXT_DIM)}\u2514\u2500 ${p.hash} ${displaySafeText(stripAnsiEscapes(p.path))}${RESET}`);
781
810
  }
782
811
  return lines;
783
812
  }
@@ -871,8 +900,8 @@ var SOURCE_CONTENT = "content";
871
900
  var SOURCE_OTHER = "other";
872
901
  var _BYTES_MODE_ONLY_KINDS = /* @__PURE__ */ new Set(["webfetch_image", "gdrive_image"]);
873
902
  var COUNT_ONLY_KINDS = /* @__PURE__ */ new Set(["secret_redacted"]);
874
- function savedTokensFromBytes(bytes) {
875
- return Math.round(Math.max(0, bytes) / 4);
903
+ function savedTokensFromBytes(bytes, cls = "text") {
904
+ return Math.round(Math.max(0, bytes) / creditDivisor(cls));
876
905
  }
877
906
  var KIND_TO_SOURCE = {
878
907
  image_shrink: SOURCE_IMAGE,
@@ -2141,10 +2170,12 @@ function sweepCacheRoots(extraRoots = []) {
2141
2170
  }
2142
2171
 
2143
2172
  export {
2173
+ BYTES_PER_TOKEN,
2174
+ guardDivisor,
2175
+ classifyContent,
2144
2176
  colorStdout,
2145
2177
  RESET,
2146
2178
  stripAnsiEscapes,
2147
- stripAnsi,
2148
2179
  fg,
2149
2180
  C,
2150
2181
  SOURCE_HINT,