aicodeman 0.2.8

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 (246) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +403 -0
  3. package/dist/ai-checker-base.d.ts +175 -0
  4. package/dist/ai-checker-base.d.ts.map +1 -0
  5. package/dist/ai-checker-base.js +424 -0
  6. package/dist/ai-checker-base.js.map +1 -0
  7. package/dist/ai-idle-checker.d.ts +53 -0
  8. package/dist/ai-idle-checker.d.ts.map +1 -0
  9. package/dist/ai-idle-checker.js +141 -0
  10. package/dist/ai-idle-checker.js.map +1 -0
  11. package/dist/ai-plan-checker.d.ts +52 -0
  12. package/dist/ai-plan-checker.d.ts.map +1 -0
  13. package/dist/ai-plan-checker.js +103 -0
  14. package/dist/ai-plan-checker.js.map +1 -0
  15. package/dist/bash-tool-parser.d.ts +191 -0
  16. package/dist/bash-tool-parser.d.ts.map +1 -0
  17. package/dist/bash-tool-parser.js +598 -0
  18. package/dist/bash-tool-parser.js.map +1 -0
  19. package/dist/cli.d.ts +12 -0
  20. package/dist/cli.d.ts.map +1 -0
  21. package/dist/cli.js +460 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/config/buffer-limits.d.ts +59 -0
  24. package/dist/config/buffer-limits.d.ts.map +1 -0
  25. package/dist/config/buffer-limits.js +74 -0
  26. package/dist/config/buffer-limits.js.map +1 -0
  27. package/dist/config/map-limits.d.ts +40 -0
  28. package/dist/config/map-limits.d.ts.map +1 -0
  29. package/dist/config/map-limits.js +52 -0
  30. package/dist/config/map-limits.js.map +1 -0
  31. package/dist/file-stream-manager.d.ts +148 -0
  32. package/dist/file-stream-manager.d.ts.map +1 -0
  33. package/dist/file-stream-manager.js +351 -0
  34. package/dist/file-stream-manager.js.map +1 -0
  35. package/dist/hooks-config.d.ts +31 -0
  36. package/dist/hooks-config.d.ts.map +1 -0
  37. package/dist/hooks-config.js +115 -0
  38. package/dist/hooks-config.js.map +1 -0
  39. package/dist/image-watcher.d.ts +86 -0
  40. package/dist/image-watcher.d.ts.map +1 -0
  41. package/dist/image-watcher.js +275 -0
  42. package/dist/image-watcher.js.map +1 -0
  43. package/dist/index.d.ts +11 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +54 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/mux-factory.d.ts +13 -0
  48. package/dist/mux-factory.d.ts.map +1 -0
  49. package/dist/mux-factory.js +19 -0
  50. package/dist/mux-factory.js.map +1 -0
  51. package/dist/mux-interface.d.ts +145 -0
  52. package/dist/mux-interface.d.ts.map +1 -0
  53. package/dist/mux-interface.js +9 -0
  54. package/dist/mux-interface.js.map +1 -0
  55. package/dist/plan-orchestrator.d.ts +123 -0
  56. package/dist/plan-orchestrator.d.ts.map +1 -0
  57. package/dist/plan-orchestrator.js +500 -0
  58. package/dist/plan-orchestrator.js.map +1 -0
  59. package/dist/prompts/index.d.ts +9 -0
  60. package/dist/prompts/index.d.ts.map +1 -0
  61. package/dist/prompts/index.js +9 -0
  62. package/dist/prompts/index.js.map +1 -0
  63. package/dist/prompts/planner.d.ts +14 -0
  64. package/dist/prompts/planner.d.ts.map +1 -0
  65. package/dist/prompts/planner.js +83 -0
  66. package/dist/prompts/planner.js.map +1 -0
  67. package/dist/prompts/research-agent.d.ts +10 -0
  68. package/dist/prompts/research-agent.d.ts.map +1 -0
  69. package/dist/prompts/research-agent.js +143 -0
  70. package/dist/prompts/research-agent.js.map +1 -0
  71. package/dist/push-store.d.ts +41 -0
  72. package/dist/push-store.d.ts.map +1 -0
  73. package/dist/push-store.js +168 -0
  74. package/dist/push-store.js.map +1 -0
  75. package/dist/ralph-config.d.ts +67 -0
  76. package/dist/ralph-config.d.ts.map +1 -0
  77. package/dist/ralph-config.js +134 -0
  78. package/dist/ralph-config.js.map +1 -0
  79. package/dist/ralph-loop.d.ts +124 -0
  80. package/dist/ralph-loop.d.ts.map +1 -0
  81. package/dist/ralph-loop.js +418 -0
  82. package/dist/ralph-loop.js.map +1 -0
  83. package/dist/ralph-tracker.d.ts +1081 -0
  84. package/dist/ralph-tracker.d.ts.map +1 -0
  85. package/dist/ralph-tracker.js +3343 -0
  86. package/dist/ralph-tracker.js.map +1 -0
  87. package/dist/respawn-controller.d.ts +1182 -0
  88. package/dist/respawn-controller.d.ts.map +1 -0
  89. package/dist/respawn-controller.js +2754 -0
  90. package/dist/respawn-controller.js.map +1 -0
  91. package/dist/run-summary.d.ts +123 -0
  92. package/dist/run-summary.d.ts.map +1 -0
  93. package/dist/run-summary.js +325 -0
  94. package/dist/run-summary.js.map +1 -0
  95. package/dist/session-lifecycle-log.d.ts +36 -0
  96. package/dist/session-lifecycle-log.d.ts.map +1 -0
  97. package/dist/session-lifecycle-log.js +101 -0
  98. package/dist/session-lifecycle-log.js.map +1 -0
  99. package/dist/session-manager.d.ts +97 -0
  100. package/dist/session-manager.d.ts.map +1 -0
  101. package/dist/session-manager.js +224 -0
  102. package/dist/session-manager.js.map +1 -0
  103. package/dist/session.d.ts +686 -0
  104. package/dist/session.d.ts.map +1 -0
  105. package/dist/session.js +2025 -0
  106. package/dist/session.js.map +1 -0
  107. package/dist/state-store.d.ts +189 -0
  108. package/dist/state-store.d.ts.map +1 -0
  109. package/dist/state-store.js +730 -0
  110. package/dist/state-store.js.map +1 -0
  111. package/dist/subagent-watcher.d.ts +345 -0
  112. package/dist/subagent-watcher.d.ts.map +1 -0
  113. package/dist/subagent-watcher.js +1469 -0
  114. package/dist/subagent-watcher.js.map +1 -0
  115. package/dist/task-queue.d.ts +108 -0
  116. package/dist/task-queue.d.ts.map +1 -0
  117. package/dist/task-queue.js +235 -0
  118. package/dist/task-queue.js.map +1 -0
  119. package/dist/task-tracker.d.ts +306 -0
  120. package/dist/task-tracker.d.ts.map +1 -0
  121. package/dist/task-tracker.js +488 -0
  122. package/dist/task-tracker.js.map +1 -0
  123. package/dist/task.d.ts +73 -0
  124. package/dist/task.d.ts.map +1 -0
  125. package/dist/task.js +177 -0
  126. package/dist/task.js.map +1 -0
  127. package/dist/team-watcher.d.ts +53 -0
  128. package/dist/team-watcher.d.ts.map +1 -0
  129. package/dist/team-watcher.js +313 -0
  130. package/dist/team-watcher.js.map +1 -0
  131. package/dist/templates/case-template.md +461 -0
  132. package/dist/templates/claude-md.d.ts +26 -0
  133. package/dist/templates/claude-md.d.ts.map +1 -0
  134. package/dist/templates/claude-md.js +74 -0
  135. package/dist/templates/claude-md.js.map +1 -0
  136. package/dist/tmux-manager.d.ts +181 -0
  137. package/dist/tmux-manager.d.ts.map +1 -0
  138. package/dist/tmux-manager.js +1405 -0
  139. package/dist/tmux-manager.js.map +1 -0
  140. package/dist/transcript-watcher.d.ts +110 -0
  141. package/dist/transcript-watcher.d.ts.map +1 -0
  142. package/dist/transcript-watcher.js +338 -0
  143. package/dist/transcript-watcher.js.map +1 -0
  144. package/dist/tunnel-manager.d.ts +54 -0
  145. package/dist/tunnel-manager.d.ts.map +1 -0
  146. package/dist/tunnel-manager.js +251 -0
  147. package/dist/tunnel-manager.js.map +1 -0
  148. package/dist/types.d.ts +1139 -0
  149. package/dist/types.d.ts.map +1 -0
  150. package/dist/types.js +215 -0
  151. package/dist/types.js.map +1 -0
  152. package/dist/utils/buffer-accumulator.d.ts +111 -0
  153. package/dist/utils/buffer-accumulator.d.ts.map +1 -0
  154. package/dist/utils/buffer-accumulator.js +172 -0
  155. package/dist/utils/buffer-accumulator.js.map +1 -0
  156. package/dist/utils/claude-cli-resolver.d.ts +26 -0
  157. package/dist/utils/claude-cli-resolver.d.ts.map +1 -0
  158. package/dist/utils/claude-cli-resolver.js +78 -0
  159. package/dist/utils/claude-cli-resolver.js.map +1 -0
  160. package/dist/utils/cleanup-manager.d.ts +165 -0
  161. package/dist/utils/cleanup-manager.d.ts.map +1 -0
  162. package/dist/utils/cleanup-manager.js +274 -0
  163. package/dist/utils/cleanup-manager.js.map +1 -0
  164. package/dist/utils/index.d.ts +19 -0
  165. package/dist/utils/index.d.ts.map +1 -0
  166. package/dist/utils/index.js +19 -0
  167. package/dist/utils/index.js.map +1 -0
  168. package/dist/utils/lru-map.d.ts +140 -0
  169. package/dist/utils/lru-map.d.ts.map +1 -0
  170. package/dist/utils/lru-map.js +234 -0
  171. package/dist/utils/lru-map.js.map +1 -0
  172. package/dist/utils/nice-wrapper.d.ts +13 -0
  173. package/dist/utils/nice-wrapper.d.ts.map +1 -0
  174. package/dist/utils/nice-wrapper.js +17 -0
  175. package/dist/utils/nice-wrapper.js.map +1 -0
  176. package/dist/utils/opencode-cli-resolver.d.ts +21 -0
  177. package/dist/utils/opencode-cli-resolver.d.ts.map +1 -0
  178. package/dist/utils/opencode-cli-resolver.js +67 -0
  179. package/dist/utils/opencode-cli-resolver.js.map +1 -0
  180. package/dist/utils/regex-patterns.d.ts +64 -0
  181. package/dist/utils/regex-patterns.d.ts.map +1 -0
  182. package/dist/utils/regex-patterns.js +74 -0
  183. package/dist/utils/regex-patterns.js.map +1 -0
  184. package/dist/utils/stale-expiration-map.d.ts +159 -0
  185. package/dist/utils/stale-expiration-map.d.ts.map +1 -0
  186. package/dist/utils/stale-expiration-map.js +277 -0
  187. package/dist/utils/stale-expiration-map.js.map +1 -0
  188. package/dist/utils/string-similarity.d.ts +108 -0
  189. package/dist/utils/string-similarity.d.ts.map +1 -0
  190. package/dist/utils/string-similarity.js +189 -0
  191. package/dist/utils/string-similarity.js.map +1 -0
  192. package/dist/utils/token-validation.d.ts +39 -0
  193. package/dist/utils/token-validation.d.ts.map +1 -0
  194. package/dist/utils/token-validation.js +59 -0
  195. package/dist/utils/token-validation.js.map +1 -0
  196. package/dist/utils/type-safety.d.ts +33 -0
  197. package/dist/utils/type-safety.d.ts.map +1 -0
  198. package/dist/utils/type-safety.js +35 -0
  199. package/dist/utils/type-safety.js.map +1 -0
  200. package/dist/web/public/app.js +491 -0
  201. package/dist/web/public/app.js.br +0 -0
  202. package/dist/web/public/app.js.gz +0 -0
  203. package/dist/web/public/index.html +1675 -0
  204. package/dist/web/public/index.html.br +0 -0
  205. package/dist/web/public/index.html.gz +0 -0
  206. package/dist/web/public/manifest.json +8 -0
  207. package/dist/web/public/mobile.css +1 -0
  208. package/dist/web/public/mobile.css.br +0 -0
  209. package/dist/web/public/mobile.css.gz +0 -0
  210. package/dist/web/public/ralph-wizard.js +1037 -0
  211. package/dist/web/public/ralph-wizard.js.br +0 -0
  212. package/dist/web/public/ralph-wizard.js.gz +0 -0
  213. package/dist/web/public/styles.css +1 -0
  214. package/dist/web/public/styles.css.br +0 -0
  215. package/dist/web/public/styles.css.gz +0 -0
  216. package/dist/web/public/sw.js +67 -0
  217. package/dist/web/public/sw.js.br +0 -0
  218. package/dist/web/public/sw.js.gz +0 -0
  219. package/dist/web/public/upload.html +155 -0
  220. package/dist/web/public/upload.html.br +0 -0
  221. package/dist/web/public/upload.html.gz +0 -0
  222. package/dist/web/public/vendor/xterm-addon-fit.min.js +1 -0
  223. package/dist/web/public/vendor/xterm-addon-fit.min.js.br +0 -0
  224. package/dist/web/public/vendor/xterm-addon-fit.min.js.gz +0 -0
  225. package/dist/web/public/vendor/xterm-addon-unicode11.min.js +1 -0
  226. package/dist/web/public/vendor/xterm-addon-unicode11.min.js.br +0 -0
  227. package/dist/web/public/vendor/xterm-addon-unicode11.min.js.gz +0 -0
  228. package/dist/web/public/vendor/xterm-addon-webgl.min.js +2 -0
  229. package/dist/web/public/vendor/xterm-addon-webgl.min.js.br +0 -0
  230. package/dist/web/public/vendor/xterm-addon-webgl.min.js.gz +0 -0
  231. package/dist/web/public/vendor/xterm.css +209 -0
  232. package/dist/web/public/vendor/xterm.css.br +0 -0
  233. package/dist/web/public/vendor/xterm.css.gz +0 -0
  234. package/dist/web/public/vendor/xterm.min.js +9 -0
  235. package/dist/web/public/vendor/xterm.min.js.br +0 -0
  236. package/dist/web/public/vendor/xterm.min.js.gz +0 -0
  237. package/dist/web/schemas.d.ts +479 -0
  238. package/dist/web/schemas.d.ts.map +1 -0
  239. package/dist/web/schemas.js +448 -0
  240. package/dist/web/schemas.js.map +1 -0
  241. package/dist/web/server.d.ts +207 -0
  242. package/dist/web/server.d.ts.map +1 -0
  243. package/dist/web/server.js +5784 -0
  244. package/dist/web/server.js.map +1 -0
  245. package/package.json +110 -0
  246. package/scripts/postinstall.js +390 -0
@@ -0,0 +1,189 @@
1
+ /**
2
+ * @fileoverview String similarity utilities for fuzzy matching.
3
+ *
4
+ * Provides Levenshtein distance and similarity scoring for:
5
+ * - Completion phrase fuzzy matching
6
+ * - Todo content deduplication
7
+ *
8
+ * @module utils/string-similarity
9
+ */
10
+ /**
11
+ * Calculate the Levenshtein (edit) distance between two strings.
12
+ * This is the minimum number of single-character edits (insertions,
13
+ * deletions, or substitutions) required to change one string into the other.
14
+ *
15
+ * Uses Wagner-Fischer algorithm with O(min(m,n)) space optimization.
16
+ *
17
+ * @param a - First string
18
+ * @param b - Second string
19
+ * @returns The edit distance (0 = identical)
20
+ *
21
+ * @example
22
+ * levenshteinDistance('hello', 'hello') // 0
23
+ * levenshteinDistance('hello', 'helo') // 1 (one deletion)
24
+ * levenshteinDistance('COMPLETE', 'COMPLET') // 1 (one deletion)
25
+ */
26
+ export function levenshteinDistance(a, b) {
27
+ // Ensure a is the shorter string for space efficiency
28
+ if (a.length > b.length) {
29
+ [a, b] = [b, a];
30
+ }
31
+ const m = a.length;
32
+ const n = b.length;
33
+ // Early exit for identical strings
34
+ if (a === b)
35
+ return 0;
36
+ // Early exit for empty strings
37
+ if (m === 0)
38
+ return n;
39
+ // Use single array (space optimization)
40
+ let prev = new Array(m + 1);
41
+ let curr = new Array(m + 1);
42
+ // Initialize first row
43
+ for (let i = 0; i <= m; i++) {
44
+ prev[i] = i;
45
+ }
46
+ // Fill the matrix row by row
47
+ for (let j = 1; j <= n; j++) {
48
+ curr[0] = j;
49
+ for (let i = 1; i <= m; i++) {
50
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
51
+ curr[i] = Math.min(prev[i] + 1, // deletion
52
+ curr[i - 1] + 1, // insertion
53
+ prev[i - 1] + cost // substitution
54
+ );
55
+ }
56
+ // Swap rows
57
+ [prev, curr] = [curr, prev];
58
+ }
59
+ return prev[m];
60
+ }
61
+ /**
62
+ * Calculate similarity ratio between two strings (0 to 1).
63
+ * Uses Levenshtein distance normalized by the longer string's length.
64
+ *
65
+ * @param a - First string
66
+ * @param b - Second string
67
+ * @returns Similarity ratio (1.0 = identical, 0.0 = completely different)
68
+ *
69
+ * @example
70
+ * stringSimilarity('hello', 'hello') // 1.0
71
+ * stringSimilarity('hello', 'helo') // 0.8 (4/5 similar)
72
+ * stringSimilarity('abc', 'xyz') // 0.0 (3 edits, length 3)
73
+ */
74
+ export function stringSimilarity(a, b) {
75
+ if (a === b)
76
+ return 1.0;
77
+ if (a.length === 0 && b.length === 0)
78
+ return 1.0;
79
+ if (a.length === 0 || b.length === 0)
80
+ return 0.0;
81
+ const distance = levenshteinDistance(a, b);
82
+ const maxLength = Math.max(a.length, b.length);
83
+ return 1 - distance / maxLength;
84
+ }
85
+ /**
86
+ * Check if two strings are similar within a given threshold.
87
+ *
88
+ * @param a - First string
89
+ * @param b - Second string
90
+ * @param threshold - Minimum similarity ratio (default: 0.85 = 85% similar)
91
+ * @returns True if similarity >= threshold
92
+ *
93
+ * @example
94
+ * isSimilar('COMPLETE', 'COMPLET', 0.85) // true (87.5% similar)
95
+ * isSimilar('COMPLETE', 'DONE', 0.85) // false (0% similar)
96
+ */
97
+ export function isSimilar(a, b, threshold = 0.85) {
98
+ return stringSimilarity(a, b) >= threshold;
99
+ }
100
+ /**
101
+ * Check if two strings are similar with edit distance tolerance.
102
+ * More intuitive for short strings than percentage-based threshold.
103
+ *
104
+ * @param a - First string
105
+ * @param b - Second string
106
+ * @param maxDistance - Maximum allowed edit distance (default: 2)
107
+ * @returns True if edit distance <= maxDistance
108
+ *
109
+ * @example
110
+ * isSimilarByDistance('COMPLETE', 'COMPLET', 2) // true (distance 1)
111
+ * isSimilarByDistance('COMPLETE', 'COMP', 2) // false (distance 4)
112
+ */
113
+ export function isSimilarByDistance(a, b, maxDistance = 2) {
114
+ return levenshteinDistance(a, b) <= maxDistance;
115
+ }
116
+ /**
117
+ * Normalize a completion phrase for comparison.
118
+ * Handles variations in case, whitespace, and separators.
119
+ *
120
+ * @param phrase - Raw completion phrase
121
+ * @returns Normalized phrase (uppercase, no separators)
122
+ *
123
+ * @example
124
+ * normalizePhrase('task_done') // 'TASKDONE'
125
+ * normalizePhrase('TASK-DONE') // 'TASKDONE'
126
+ * normalizePhrase('Task Done') // 'TASKDONE'
127
+ */
128
+ export function normalizePhrase(phrase) {
129
+ return phrase
130
+ .toUpperCase()
131
+ .replace(/[\s_\-.]+/g, '') // Remove whitespace, underscores, hyphens, dots
132
+ .trim();
133
+ }
134
+ /**
135
+ * Check if two completion phrases match with fuzzy tolerance.
136
+ *
137
+ * First normalizes both phrases, then checks:
138
+ * 1. Exact match after normalization
139
+ * 2. Edit distance <= maxDistance for typo tolerance
140
+ *
141
+ * @param phrase1 - First phrase to compare
142
+ * @param phrase2 - Second phrase to compare
143
+ * @param maxDistance - Maximum edit distance for fuzzy match (default: 2)
144
+ * @returns True if phrases match (exact or fuzzy)
145
+ *
146
+ * @example
147
+ * fuzzyPhraseMatch('COMPLETE', 'COMPLETE') // true (exact)
148
+ * fuzzyPhraseMatch('COMPLETE', 'COMPLET') // true (typo)
149
+ * fuzzyPhraseMatch('TASK_DONE', 'TASKDONE') // true (separator)
150
+ * fuzzyPhraseMatch('COMPLETE', 'FINISHED') // false (different word)
151
+ */
152
+ export function fuzzyPhraseMatch(phrase1, phrase2, maxDistance = 2) {
153
+ const norm1 = normalizePhrase(phrase1);
154
+ const norm2 = normalizePhrase(phrase2);
155
+ // Exact match after normalization
156
+ if (norm1 === norm2)
157
+ return true;
158
+ // For short phrases (< 6 chars), require exact match to avoid false positives
159
+ // e.g., "DONE" shouldn't match "DENY"
160
+ if (norm1.length < 6 || norm2.length < 6) {
161
+ return false;
162
+ }
163
+ // Fuzzy match with edit distance
164
+ return isSimilarByDistance(norm1, norm2, maxDistance);
165
+ }
166
+ /**
167
+ * Generate a content hash for todo deduplication.
168
+ * Normalizes content and generates a simple hash.
169
+ *
170
+ * @param content - Todo item content
171
+ * @returns Normalized hash string for comparison
172
+ */
173
+ export function todoContentHash(content) {
174
+ // Normalize: lowercase, collapse whitespace, remove punctuation
175
+ const normalized = content
176
+ .toLowerCase()
177
+ .replace(/\s+/g, ' ')
178
+ .replace(/[^\w\s]/g, '')
179
+ .trim();
180
+ // Simple hash using reduce (fast, good enough for deduplication)
181
+ let hash = 0;
182
+ for (let i = 0; i < normalized.length; i++) {
183
+ const char = normalized.charCodeAt(i);
184
+ hash = (hash << 5) - hash + char;
185
+ hash = hash & hash; // Convert to 32-bit integer
186
+ }
187
+ return hash.toString(36);
188
+ }
189
+ //# sourceMappingURL=string-similarity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-similarity.js","sourceRoot":"","sources":["../../src/utils/string-similarity.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,mBAAmB,CAAC,CAAS,EAAE,CAAS;IACtD,sDAAsD;IACtD,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;QACxB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACnB,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IAEnB,mCAAmC;IACnC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAEtB,+BAA+B;IAC/B,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAEtB,wCAAwC;IACxC,IAAI,IAAI,GAAG,IAAI,KAAK,CAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IACpC,IAAI,IAAI,GAAG,IAAI,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IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,iCAAiC;IACjC,OAAO,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,gEAAgE;IAChE,MAAM,UAAU,GAAG,OAAO;SACvB,WAAW,EAAE;SACb,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,IAAI,EAAE,CAAC;IAEV,iEAAiE;IACjE,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACtC,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;QACjC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,4BAA4B;IAClD,CAAC;IACD,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @fileoverview Token validation utilities.
3
+ *
4
+ * Centralizes token count validation logic used across the codebase.
5
+ * Claude's context window is ~200k tokens, so 500k is a generous upper bound.
6
+ *
7
+ * @module utils/token-validation
8
+ */
9
+ /**
10
+ * Maximum tokens allowed per session.
11
+ * Claude's context is ~200k, so 500k is a safe upper bound for validation.
12
+ */
13
+ export declare const MAX_SESSION_TOKENS = 500000;
14
+ /**
15
+ * Validates token counts are within acceptable bounds.
16
+ * Rejects negative values and values exceeding MAX_SESSION_TOKENS.
17
+ *
18
+ * @param inputTokens - Input token count to validate
19
+ * @param outputTokens - Output token count to validate
20
+ * @returns Object with isValid flag and optional error reason
21
+ */
22
+ export declare function validateTokenCounts(inputTokens: number, outputTokens: number): {
23
+ isValid: boolean;
24
+ reason?: string;
25
+ };
26
+ /**
27
+ * Validates token counts and cost for restoration/persistence.
28
+ * Returns true if all values are valid.
29
+ *
30
+ * @param inputTokens - Input token count
31
+ * @param outputTokens - Output token count
32
+ * @param cost - Cost value (must be non-negative)
33
+ * @returns Object with isValid flag and optional error reason
34
+ */
35
+ export declare function validateTokensAndCost(inputTokens: number, outputTokens: number, cost: number): {
36
+ isValid: boolean;
37
+ reason?: string;
38
+ };
39
+ //# sourceMappingURL=token-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-validation.d.ts","sourceRoot":"","sources":["../../src/utils/token-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,eAAO,MAAM,kBAAkB,SAAU,CAAC;AAE1C;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAgBpH;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,GACX;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAcvC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @fileoverview Token validation utilities.
3
+ *
4
+ * Centralizes token count validation logic used across the codebase.
5
+ * Claude's context window is ~200k tokens, so 500k is a generous upper bound.
6
+ *
7
+ * @module utils/token-validation
8
+ */
9
+ /**
10
+ * Maximum tokens allowed per session.
11
+ * Claude's context is ~200k, so 500k is a safe upper bound for validation.
12
+ */
13
+ export const MAX_SESSION_TOKENS = 500_000;
14
+ /**
15
+ * Validates token counts are within acceptable bounds.
16
+ * Rejects negative values and values exceeding MAX_SESSION_TOKENS.
17
+ *
18
+ * @param inputTokens - Input token count to validate
19
+ * @param outputTokens - Output token count to validate
20
+ * @returns Object with isValid flag and optional error reason
21
+ */
22
+ export function validateTokenCounts(inputTokens, outputTokens) {
23
+ if (inputTokens < 0 || outputTokens < 0) {
24
+ return {
25
+ isValid: false,
26
+ reason: `Negative token values: input=${inputTokens}, output=${outputTokens}`,
27
+ };
28
+ }
29
+ if (inputTokens > MAX_SESSION_TOKENS || outputTokens > MAX_SESSION_TOKENS) {
30
+ return {
31
+ isValid: false,
32
+ reason: `Token values exceed maximum (${MAX_SESSION_TOKENS}): input=${inputTokens}, output=${outputTokens}`,
33
+ };
34
+ }
35
+ return { isValid: true };
36
+ }
37
+ /**
38
+ * Validates token counts and cost for restoration/persistence.
39
+ * Returns true if all values are valid.
40
+ *
41
+ * @param inputTokens - Input token count
42
+ * @param outputTokens - Output token count
43
+ * @param cost - Cost value (must be non-negative)
44
+ * @returns Object with isValid flag and optional error reason
45
+ */
46
+ export function validateTokensAndCost(inputTokens, outputTokens, cost) {
47
+ const tokenValidation = validateTokenCounts(inputTokens, outputTokens);
48
+ if (!tokenValidation.isValid) {
49
+ return tokenValidation;
50
+ }
51
+ if (cost < 0) {
52
+ return {
53
+ isValid: false,
54
+ reason: `Negative cost value: ${cost}`,
55
+ };
56
+ }
57
+ return { isValid: true };
58
+ }
59
+ //# sourceMappingURL=token-validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-validation.js","sourceRoot":"","sources":["../../src/utils/token-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,WAAmB,EAAE,YAAoB;IAC3E,IAAI,WAAW,GAAG,CAAC,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;QACxC,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,gCAAgC,WAAW,YAAY,YAAY,EAAE;SAC9E,CAAC;IACJ,CAAC;IAED,IAAI,WAAW,GAAG,kBAAkB,IAAI,YAAY,GAAG,kBAAkB,EAAE,CAAC;QAC1E,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,gCAAgC,kBAAkB,YAAY,WAAW,YAAY,YAAY,EAAE;SAC5G,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CACnC,WAAmB,EACnB,YAAoB,EACpB,IAAY;IAEZ,MAAM,eAAe,GAAG,mBAAmB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IACvE,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;QAC7B,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACb,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,wBAAwB,IAAI,EAAE;SACvC,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @fileoverview Type safety utilities for exhaustive checking.
3
+ *
4
+ * @module utils/type-safety
5
+ */
6
+ /**
7
+ * Assert that a value should never occur at runtime.
8
+ * Used in switch/case default blocks to ensure exhaustive handling.
9
+ *
10
+ * If TypeScript sees a code path where `value` is not `never`,
11
+ * it will report a compile-time error, catching missing cases.
12
+ *
13
+ * @param value - The value that should be of type `never`
14
+ * @param message - Optional custom error message
15
+ * @throws Error if called at runtime (indicates unhandled case)
16
+ *
17
+ * @example
18
+ * type Status = 'active' | 'inactive' | 'pending';
19
+ * function handleStatus(status: Status): void {
20
+ * switch (status) {
21
+ * case 'active': // handle active
22
+ * break;
23
+ * case 'inactive': // handle inactive
24
+ * break;
25
+ * case 'pending': // handle pending
26
+ * break;
27
+ * default:
28
+ * assertNever(status); // Compile error if case is missing
29
+ * }
30
+ * }
31
+ */
32
+ export declare function assertNever(value: never, message?: string): never;
33
+ //# sourceMappingURL=type-safety.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-safety.d.ts","sourceRoot":"","sources":["../../src/utils/type-safety.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAEjE"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @fileoverview Type safety utilities for exhaustive checking.
3
+ *
4
+ * @module utils/type-safety
5
+ */
6
+ /**
7
+ * Assert that a value should never occur at runtime.
8
+ * Used in switch/case default blocks to ensure exhaustive handling.
9
+ *
10
+ * If TypeScript sees a code path where `value` is not `never`,
11
+ * it will report a compile-time error, catching missing cases.
12
+ *
13
+ * @param value - The value that should be of type `never`
14
+ * @param message - Optional custom error message
15
+ * @throws Error if called at runtime (indicates unhandled case)
16
+ *
17
+ * @example
18
+ * type Status = 'active' | 'inactive' | 'pending';
19
+ * function handleStatus(status: Status): void {
20
+ * switch (status) {
21
+ * case 'active': // handle active
22
+ * break;
23
+ * case 'inactive': // handle inactive
24
+ * break;
25
+ * case 'pending': // handle pending
26
+ * break;
27
+ * default:
28
+ * assertNever(status); // Compile error if case is missing
29
+ * }
30
+ * }
31
+ */
32
+ export function assertNever(value, message) {
33
+ throw new Error(message ?? `Unexpected value: ${JSON.stringify(value)}`);
34
+ }
35
+ //# sourceMappingURL=type-safety.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-safety.js","sourceRoot":"","sources":["../../src/utils/type-safety.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,WAAW,CAAC,KAAY,EAAE,OAAgB;IACxD,MAAM,IAAI,KAAK,CAAC,OAAO,IAAI,qBAAqB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAC3E,CAAC"}