token-goat 2.6.30 → 2.6.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +55 -16
  2. package/SECURITY.md +136 -0
  3. package/dist/{token-goat-hook-chunk-KNVHTGEX.mjs → token-goat-chunk-3KW5C2KQ.mjs} +1 -1
  4. package/dist/{token-goat-hook-chunk-7WC2H3EW.mjs → token-goat-chunk-3UOG7PSZ.mjs} +12 -3
  5. package/dist/{token-goat-hook-chunk-FKZ5RBT4.mjs → token-goat-chunk-4M7PSAO3.mjs} +8 -8
  6. package/dist/token-goat-chunk-5EXIMDHA.mjs +5113 -0
  7. package/dist/token-goat-chunk-DFBD2FFU.mjs +9627 -0
  8. package/dist/token-goat-chunk-DNEPSN3P.mjs +156 -0
  9. package/dist/token-goat-chunk-GWZJ5SI2.mjs +13684 -0
  10. package/dist/token-goat-chunk-N53GXI2Z.mjs +9660 -0
  11. package/dist/token-goat-chunk-O7TGKV5I.mjs +901 -0
  12. package/dist/token-goat-chunk-RD6O3PJU.mjs +15606 -0
  13. package/dist/token-goat-chunk-TBCLQTPG.mjs +24 -0
  14. package/dist/token-goat-chunk-W3MX4LQV.mjs +707 -0
  15. package/dist/token-goat-chunk-X5OPORR4.mjs +18331 -0
  16. package/dist/{token-goat-hook-chunk-ZRJUZZQE.mjs → token-goat-chunk-YWYITDOS.mjs} +5 -6
  17. package/dist/{token-goat-hook-chunk-XNZLMFQ2.mjs → token-goat-hook-chunk-6NF4WM2U.mjs} +2772 -883
  18. package/dist/token-goat-hook-chunk-ANFXTEQO.mjs +23 -0
  19. package/dist/token-goat-hook-chunk-DHW6SRHR.mjs +5099 -0
  20. package/dist/token-goat-hook-chunk-DJZGX27J.mjs +9624 -0
  21. package/dist/token-goat-hook-chunk-J2ZK2FYW.mjs +33 -0
  22. package/dist/token-goat-hook-chunk-K33JMLL7.mjs +63 -0
  23. package/dist/token-goat-hook-chunk-LFYT4DLB.mjs +901 -0
  24. package/dist/token-goat-hook-chunk-PCP4W65Z.mjs +112 -0
  25. package/dist/token-goat-hook-chunk-Q5URQRIF.mjs +9660 -0
  26. package/dist/{token-goat-hook-chunk-FMQ37OQD.mjs → token-goat-hook-chunk-TBJ5PUPQ.mjs} +28 -26
  27. package/dist/token-goat-hook-chunk-TKXOXN4J.mjs +14860 -0
  28. package/dist/token-goat-hook-chunk-UXD3B4OY.mjs +156 -0
  29. package/dist/token-goat-hook-chunk-VHZECEQD.mjs +13684 -0
  30. package/dist/token-goat-hook-chunk-WBTHUYJP.mjs +18329 -0
  31. package/dist/token-goat-hook.mjs +7 -4
  32. package/dist/token-goat.core.mjs +14 -89574
  33. package/package.json +15 -6
  34. package/dist/token-goat-hook-chunk-4SM2PAR6.mjs +0 -33590
  35. package/dist/token-goat-hook-chunk-5B3OWRNC.mjs +0 -145
  36. package/dist/token-goat-hook-chunk-VKAQNN2R.mjs +0 -24416
@@ -1,145 +0,0 @@
1
- import { createRequire as __cjsRequire } from 'node:module';
2
- const require = __cjsRequire(import.meta.url);
3
- import {
4
- findProject,
5
- isBlobStale,
6
- loadBlob,
7
- recordStat,
8
- redactSecrets,
9
- shortFingerprint,
10
- storeBlob
11
- } from "./token-goat-hook-chunk-4SM2PAR6.mjs";
12
- import {
13
- init_define_import_meta_env
14
- } from "./token-goat-hook-chunk-7WC2H3EW.mjs";
15
-
16
- // src/content_store.ts
17
- init_define_import_meta_env();
18
- import { deflateRawSync } from "node:zlib";
19
- import * as path from "node:path";
20
- var CONTENT_MAX_INPUT_CHARS = 512 * 1024;
21
- var CONTENT_MAX_ITEMS = 256;
22
- var CONTENT_MAX_BYTES = 32 * 1024 * 1024;
23
- var CONTENT_MAX_ITEM_BYTES = CONTENT_MAX_INPUT_CHARS * 7;
24
- var CONTENT_SUBDIR = "content";
25
- var TEXT_BYTES_PER_TOKEN = 4;
26
- var BASE64URL_BYTES_PER_TOKEN = 1.45;
27
- function estimateTextTokens(bytes) {
28
- return Math.round(bytes / TEXT_BYTES_PER_TOKEN);
29
- }
30
- function estimateBase64urlTokens(bytes) {
31
- return Math.round(bytes / BASE64URL_BYTES_PER_TOKEN);
32
- }
33
- function assertInput(text) {
34
- if (text.length > CONTENT_MAX_INPUT_CHARS) {
35
- throw new Error(`text exceeds the ${CONTENT_MAX_INPUT_CHARS}-character safety limit`);
36
- }
37
- }
38
- function contentId(text) {
39
- return `tg_${shortFingerprint(text)}`;
40
- }
41
- function normalizeProjectRoot(projectRoot) {
42
- const candidate = path.resolve(projectRoot ?? process.cwd());
43
- return findProject(candidate)?.root ?? candidate;
44
- }
45
- function handoffId(name, projectRoot) {
46
- return `tg_handoff_${shortFingerprint(`${projectRoot}\0${name}`)}`;
47
- }
48
- function storeContent(text) {
49
- const id = contentId(text);
50
- const value = { kind: "content", id, text, createdAt: Date.now() };
51
- const ok = storeBlob(CONTENT_SUBDIR, id, value, {
52
- maxCount: CONTENT_MAX_ITEMS,
53
- maxBytes: CONTENT_MAX_BYTES,
54
- maxBytesPerItem: CONTENT_MAX_ITEM_BYTES
55
- });
56
- if (!ok) throw new Error("unable to persist compressed content within the local cache bounds");
57
- return id;
58
- }
59
- function readContent(id) {
60
- if (!/^tg_[0-9a-f]{16}$/.test(id)) return null;
61
- if (isBlobStale(CONTENT_SUBDIR, id)) return null;
62
- const value = loadBlob(CONTENT_SUBDIR, id);
63
- if (value === null || typeof value !== "object" || value === null) return null;
64
- const entry = value;
65
- return entry.kind === "content" && entry.id === id && typeof entry.text === "string" ? entry.text : null;
66
- }
67
- function compressText(text) {
68
- assertInput(text);
69
- const safeText = redactSecrets(text).text;
70
- const id = storeContent(safeText);
71
- const compact = deflateRawSync(Buffer.from(safeText, "utf8"), { level: 9 }).toString("base64url");
72
- const originalBytes = Buffer.byteLength(safeText, "utf8");
73
- const compactBytes = Buffer.byteLength(compact, "utf8");
74
- const bytesSaved = Math.max(0, originalBytes - compactBytes);
75
- const tokensSaved = estimateTextTokens(originalBytes) - estimateBase64urlTokens(compactBytes);
76
- const inlineWins = tokensSaved > 0;
77
- recordStat("content_compress", inlineWins ? bytesSaved : 0, inlineWins ? tokensSaved : 0);
78
- return {
79
- id,
80
- compact,
81
- encoding: "deflate-raw-base64url",
82
- originalBytes,
83
- compactBytes,
84
- bytesSaved,
85
- tokensSaved,
86
- inlineWins,
87
- recovery: `token-goat retrieve ${id}`
88
- };
89
- }
90
- function retrieveText(id) {
91
- const text = readContent(id);
92
- if (text === null) return null;
93
- recordStat("content_retrieve");
94
- return text;
95
- }
96
- function createHandoff(name, text, projectRoot) {
97
- if (!/^[A-Za-z0-9._-]{1,128}$/.test(name)) {
98
- throw new Error("handoff name must be 1-128 characters using letters, numbers, dot, underscore, or hyphen");
99
- }
100
- assertInput(text);
101
- const root = normalizeProjectRoot(projectRoot);
102
- const safeText = redactSecrets(text).text;
103
- const contentIdValue = storeContent(safeText);
104
- const id = handoffId(name, root);
105
- const value = {
106
- kind: "handoff",
107
- id,
108
- name,
109
- projectRoot: root,
110
- contentId: contentIdValue,
111
- // Keep the handoff independently resolvable if the generic content entry
112
- // is later evicted from the shared bounded cache.
113
- text: safeText,
114
- createdAt: Date.now()
115
- };
116
- const ok = storeBlob(CONTENT_SUBDIR, id, value, {
117
- maxCount: CONTENT_MAX_ITEMS,
118
- maxBytes: CONTENT_MAX_BYTES,
119
- maxBytesPerItem: CONTENT_MAX_ITEM_BYTES
120
- });
121
- if (!ok) throw new Error("unable to persist handoff within the local cache bounds");
122
- recordStat("handoff_create");
123
- return { id, name, contentId: contentIdValue, projectRoot: root, recovery: `token-goat handoff-resolve ${name}` };
124
- }
125
- function resolveHandoff(name, opts = {}) {
126
- const root = normalizeProjectRoot(opts.projectRoot);
127
- const id = handoffId(name, root);
128
- if (isBlobStale(CONTENT_SUBDIR, id)) return null;
129
- const value = loadBlob(CONTENT_SUBDIR, id);
130
- if (value === null || typeof value !== "object" || value === null) return null;
131
- const entry = value;
132
- if (entry.kind !== "handoff" || entry.projectRoot !== root || typeof entry.contentId !== "string" || typeof entry.text !== "string") return null;
133
- const text = entry.text;
134
- recordStat("handoff_resolve");
135
- if (opts.full === true) return text;
136
- return compressText(text);
137
- }
138
-
139
- export {
140
- CONTENT_MAX_INPUT_CHARS,
141
- compressText,
142
- retrieveText,
143
- createHandoff,
144
- resolveHandoff
145
- };