@sylphx/flow 1.0.1 → 1.0.3

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 (229) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +10 -9
  3. package/src/commands/codebase-command.ts +168 -0
  4. package/src/commands/flow-command.ts +1137 -0
  5. package/src/commands/flow-orchestrator.ts +296 -0
  6. package/src/commands/hook-command.ts +444 -0
  7. package/src/commands/init-command.ts +92 -0
  8. package/src/commands/init-core.ts +322 -0
  9. package/src/commands/knowledge-command.ts +161 -0
  10. package/src/commands/run-command.ts +120 -0
  11. package/src/components/benchmark-monitor.tsx +331 -0
  12. package/src/components/reindex-progress.tsx +261 -0
  13. package/src/composables/functional/index.ts +14 -0
  14. package/src/composables/functional/useEnvironment.ts +171 -0
  15. package/src/composables/functional/useFileSystem.ts +139 -0
  16. package/src/composables/index.ts +5 -0
  17. package/src/composables/useEnv.ts +13 -0
  18. package/src/composables/useRuntimeConfig.ts +27 -0
  19. package/src/composables/useTargetConfig.ts +45 -0
  20. package/src/config/ai-config.ts +376 -0
  21. package/src/config/constants.ts +35 -0
  22. package/src/config/index.ts +27 -0
  23. package/src/config/rules.ts +43 -0
  24. package/src/config/servers.ts +371 -0
  25. package/src/config/targets.ts +126 -0
  26. package/src/core/agent-loader.ts +141 -0
  27. package/src/core/agent-manager.ts +174 -0
  28. package/src/core/ai-sdk.ts +603 -0
  29. package/src/core/app-factory.ts +381 -0
  30. package/src/core/builtin-agents.ts +9 -0
  31. package/src/core/command-system.ts +550 -0
  32. package/src/core/config-system.ts +550 -0
  33. package/src/core/connection-pool.ts +390 -0
  34. package/src/core/di-container.ts +155 -0
  35. package/src/core/error-handling.ts +519 -0
  36. package/src/core/formatting/bytes.test.ts +115 -0
  37. package/src/core/formatting/bytes.ts +64 -0
  38. package/src/core/functional/async.ts +313 -0
  39. package/src/core/functional/either.ts +109 -0
  40. package/src/core/functional/error-handler.ts +135 -0
  41. package/src/core/functional/error-types.ts +311 -0
  42. package/src/core/functional/index.ts +19 -0
  43. package/src/core/functional/option.ts +142 -0
  44. package/src/core/functional/pipe.ts +189 -0
  45. package/src/core/functional/result.ts +204 -0
  46. package/src/core/functional/validation.ts +138 -0
  47. package/src/core/headless-display.ts +96 -0
  48. package/src/core/index.ts +6 -0
  49. package/src/core/installers/file-installer.ts +303 -0
  50. package/src/core/installers/mcp-installer.ts +213 -0
  51. package/src/core/interfaces/index.ts +22 -0
  52. package/src/core/interfaces/repository.interface.ts +91 -0
  53. package/src/core/interfaces/service.interface.ts +133 -0
  54. package/src/core/interfaces.ts +129 -0
  55. package/src/core/loop-controller.ts +200 -0
  56. package/src/core/result.ts +351 -0
  57. package/src/core/rule-loader.ts +147 -0
  58. package/src/core/rule-manager.ts +240 -0
  59. package/src/core/service-config.ts +252 -0
  60. package/src/core/session-service.ts +121 -0
  61. package/src/core/state-detector.ts +389 -0
  62. package/src/core/storage-factory.ts +115 -0
  63. package/src/core/stream-handler.ts +288 -0
  64. package/src/core/target-manager.ts +161 -0
  65. package/src/core/type-utils.ts +427 -0
  66. package/src/core/unified-storage.ts +456 -0
  67. package/src/core/upgrade-manager.ts +300 -0
  68. package/src/core/validation/limit.test.ts +155 -0
  69. package/src/core/validation/limit.ts +46 -0
  70. package/src/core/validation/query.test.ts +44 -0
  71. package/src/core/validation/query.ts +20 -0
  72. package/src/db/auto-migrate.ts +322 -0
  73. package/src/db/base-database-client.ts +144 -0
  74. package/src/db/cache-db.ts +218 -0
  75. package/src/db/cache-schema.ts +75 -0
  76. package/src/db/database.ts +70 -0
  77. package/src/db/index.ts +252 -0
  78. package/src/db/memory-db.ts +153 -0
  79. package/src/db/memory-schema.ts +29 -0
  80. package/src/db/schema.ts +289 -0
  81. package/src/db/session-repository.ts +733 -0
  82. package/src/domains/codebase/index.ts +5 -0
  83. package/src/domains/codebase/tools.ts +139 -0
  84. package/src/domains/index.ts +8 -0
  85. package/src/domains/knowledge/index.ts +10 -0
  86. package/src/domains/knowledge/resources.ts +537 -0
  87. package/src/domains/knowledge/tools.ts +174 -0
  88. package/src/domains/utilities/index.ts +6 -0
  89. package/src/domains/utilities/time/index.ts +5 -0
  90. package/src/domains/utilities/time/tools.ts +291 -0
  91. package/src/index.ts +211 -0
  92. package/src/services/agent-service.ts +273 -0
  93. package/src/services/claude-config-service.ts +252 -0
  94. package/src/services/config-service.ts +258 -0
  95. package/src/services/evaluation-service.ts +271 -0
  96. package/src/services/functional/evaluation-logic.ts +296 -0
  97. package/src/services/functional/file-processor.ts +273 -0
  98. package/src/services/functional/index.ts +12 -0
  99. package/src/services/index.ts +13 -0
  100. package/src/services/mcp-service.ts +432 -0
  101. package/src/services/memory.service.ts +476 -0
  102. package/src/services/search/base-indexer.ts +156 -0
  103. package/src/services/search/codebase-indexer-types.ts +38 -0
  104. package/src/services/search/codebase-indexer.ts +647 -0
  105. package/src/services/search/embeddings-provider.ts +455 -0
  106. package/src/services/search/embeddings.ts +316 -0
  107. package/src/services/search/functional-indexer.ts +323 -0
  108. package/src/services/search/index.ts +27 -0
  109. package/src/services/search/indexer.ts +380 -0
  110. package/src/services/search/knowledge-indexer.ts +422 -0
  111. package/src/services/search/semantic-search.ts +244 -0
  112. package/src/services/search/tfidf.ts +559 -0
  113. package/src/services/search/unified-search-service.ts +888 -0
  114. package/src/services/smart-config-service.ts +385 -0
  115. package/src/services/storage/cache-storage.ts +487 -0
  116. package/src/services/storage/drizzle-storage.ts +581 -0
  117. package/src/services/storage/index.ts +15 -0
  118. package/src/services/storage/lancedb-vector-storage.ts +494 -0
  119. package/src/services/storage/memory-storage.ts +268 -0
  120. package/src/services/storage/separated-storage.ts +467 -0
  121. package/src/services/storage/vector-storage.ts +13 -0
  122. package/src/shared/agents/index.ts +63 -0
  123. package/src/shared/files/index.ts +99 -0
  124. package/src/shared/index.ts +32 -0
  125. package/src/shared/logging/index.ts +24 -0
  126. package/src/shared/processing/index.ts +153 -0
  127. package/src/shared/types/index.ts +25 -0
  128. package/src/targets/claude-code.ts +574 -0
  129. package/src/targets/functional/claude-code-logic.ts +185 -0
  130. package/src/targets/functional/index.ts +6 -0
  131. package/src/targets/opencode.ts +529 -0
  132. package/src/types/agent.types.ts +32 -0
  133. package/src/types/api/batch.ts +108 -0
  134. package/src/types/api/errors.ts +118 -0
  135. package/src/types/api/index.ts +55 -0
  136. package/src/types/api/requests.ts +76 -0
  137. package/src/types/api/responses.ts +180 -0
  138. package/src/types/api/websockets.ts +85 -0
  139. package/src/types/api.types.ts +9 -0
  140. package/src/types/benchmark.ts +49 -0
  141. package/src/types/cli.types.ts +87 -0
  142. package/src/types/common.types.ts +35 -0
  143. package/src/types/database.types.ts +510 -0
  144. package/src/types/mcp-config.types.ts +448 -0
  145. package/src/types/mcp.types.ts +69 -0
  146. package/src/types/memory-types.ts +63 -0
  147. package/src/types/provider.types.ts +28 -0
  148. package/src/types/rule.types.ts +24 -0
  149. package/src/types/session.types.ts +214 -0
  150. package/src/types/target-config.types.ts +295 -0
  151. package/src/types/target.types.ts +140 -0
  152. package/src/types/todo.types.ts +25 -0
  153. package/src/types.ts +40 -0
  154. package/src/utils/advanced-tokenizer.ts +191 -0
  155. package/src/utils/agent-enhancer.ts +114 -0
  156. package/src/utils/ai-model-fetcher.ts +19 -0
  157. package/src/utils/async-file-operations.ts +516 -0
  158. package/src/utils/audio-player.ts +345 -0
  159. package/src/utils/cli-output.ts +266 -0
  160. package/src/utils/codebase-helpers.ts +211 -0
  161. package/src/utils/console-ui.ts +79 -0
  162. package/src/utils/database-errors.ts +140 -0
  163. package/src/utils/debug-logger.ts +49 -0
  164. package/src/utils/error-handler.ts +53 -0
  165. package/src/utils/file-operations.ts +310 -0
  166. package/src/utils/file-scanner.ts +259 -0
  167. package/src/utils/functional/array.ts +355 -0
  168. package/src/utils/functional/index.ts +15 -0
  169. package/src/utils/functional/object.ts +279 -0
  170. package/src/utils/functional/string.ts +281 -0
  171. package/src/utils/functional.ts +543 -0
  172. package/src/utils/help.ts +20 -0
  173. package/src/utils/immutable-cache.ts +106 -0
  174. package/src/utils/index.ts +78 -0
  175. package/src/utils/jsonc.ts +158 -0
  176. package/src/utils/logger.ts +396 -0
  177. package/src/utils/mcp-config.ts +249 -0
  178. package/src/utils/memory-tui.ts +414 -0
  179. package/src/utils/models-dev.ts +91 -0
  180. package/src/utils/notifications.ts +169 -0
  181. package/src/utils/object-utils.ts +51 -0
  182. package/src/utils/parallel-operations.ts +487 -0
  183. package/src/utils/paths.ts +143 -0
  184. package/src/utils/process-manager.ts +155 -0
  185. package/src/utils/prompts.ts +120 -0
  186. package/src/utils/search-tool-builder.ts +214 -0
  187. package/src/utils/secret-utils.ts +179 -0
  188. package/src/utils/security.ts +537 -0
  189. package/src/utils/session-manager.ts +168 -0
  190. package/src/utils/session-title.ts +87 -0
  191. package/src/utils/settings.ts +182 -0
  192. package/src/utils/simplified-errors.ts +410 -0
  193. package/src/utils/sync-utils.ts +159 -0
  194. package/src/utils/target-config.ts +570 -0
  195. package/src/utils/target-utils.ts +394 -0
  196. package/src/utils/template-engine.ts +94 -0
  197. package/src/utils/test-audio.ts +71 -0
  198. package/src/utils/todo-context.ts +46 -0
  199. package/src/utils/token-counter.ts +288 -0
  200. package/dist/index.d.ts +0 -10
  201. package/dist/index.js +0 -59554
  202. package/dist/lancedb.linux-x64-gnu-b7f0jgsz.node +0 -0
  203. package/dist/lancedb.linux-x64-musl-tgcv22rx.node +0 -0
  204. package/dist/shared/chunk-25dwp0dp.js +0 -89
  205. package/dist/shared/chunk-3pjb6063.js +0 -208
  206. package/dist/shared/chunk-4d6ydpw7.js +0 -2854
  207. package/dist/shared/chunk-4wjcadjk.js +0 -225
  208. package/dist/shared/chunk-5j4w74t6.js +0 -30
  209. package/dist/shared/chunk-5j8m3dh3.js +0 -58
  210. package/dist/shared/chunk-5thh3qem.js +0 -91
  211. package/dist/shared/chunk-6g9xy73m.js +0 -252
  212. package/dist/shared/chunk-7eq34c42.js +0 -23
  213. package/dist/shared/chunk-c2gwgx3r.js +0 -115
  214. package/dist/shared/chunk-cjd3mk4c.js +0 -1320
  215. package/dist/shared/chunk-g5cv6703.js +0 -368
  216. package/dist/shared/chunk-hpkhykhq.js +0 -574
  217. package/dist/shared/chunk-m2322pdk.js +0 -122
  218. package/dist/shared/chunk-nd5fdvaq.js +0 -26
  219. package/dist/shared/chunk-pgd3m6zf.js +0 -108
  220. package/dist/shared/chunk-qk8n91hw.js +0 -494
  221. package/dist/shared/chunk-rkkn8szp.js +0 -16855
  222. package/dist/shared/chunk-t16rfxh0.js +0 -61
  223. package/dist/shared/chunk-t4fbfa5v.js +0 -19
  224. package/dist/shared/chunk-t77h86w6.js +0 -276
  225. package/dist/shared/chunk-v0ez4aef.js +0 -71
  226. package/dist/shared/chunk-v29j2r3s.js +0 -32051
  227. package/dist/shared/chunk-vfbc6ew5.js +0 -765
  228. package/dist/shared/chunk-vmeqwm1c.js +0 -204
  229. package/dist/shared/chunk-x66eh37x.js +0 -137
@@ -0,0 +1,467 @@
1
+ /**
2
+ * Separated storage implementation - 分離式存儲
3
+ * Memory 數據存儲在 memory.db (應該上 Git)
4
+ * Cache 數據存儲在 cache.db (不應該上 Git)
5
+ *
6
+ * This file now acts as a compatibility layer that delegates to the specialized storage modules
7
+ */
8
+
9
+ import {
10
+ CacheStorage,
11
+ type CodebaseFileEntry,
12
+ type TfidfDocumentEntry,
13
+ type TfidfIdfEntry,
14
+ type TfidfTermEntry,
15
+ } from './cache-storage.js';
16
+ import { type MemoryEntry, MemoryStorage } from './memory-storage.js';
17
+
18
+ export type {
19
+ CodebaseFileEntry,
20
+ TfidfDocumentEntry,
21
+ TfidfIdfEntry,
22
+ TfidfTermEntry,
23
+ } from './cache-storage.js';
24
+ // Re-export interfaces for backward compatibility
25
+ export type { MemoryEntry } from './memory-storage.js';
26
+
27
+ /**
28
+ * Separated storage implementation - Compatibility Layer
29
+ *
30
+ * This class maintains backward compatibility while delegating to the specialized
31
+ * storage modules. New code should use MemoryStorage and CacheStorage directly.
32
+ */
33
+ export class SeparatedMemoryStorage {
34
+ private memoryStorage: MemoryStorage;
35
+ private cacheStorage: CacheStorage;
36
+
37
+ constructor() {
38
+ this.memoryStorage = new MemoryStorage();
39
+ this.cacheStorage = new CacheStorage();
40
+ }
41
+
42
+ async initialize(): Promise<void> {
43
+ await Promise.all([this.memoryStorage.initialize(), this.cacheStorage.initialize()]);
44
+ }
45
+
46
+ // === Memory Operations (delegated to MemoryStorage) ===
47
+
48
+ /**
49
+ * Set a memory entry
50
+ */
51
+ async set(key: string, value: any, namespace = 'default'): Promise<void> {
52
+ return this.memoryStorage.set(key, value, namespace);
53
+ }
54
+
55
+ /**
56
+ * Get a memory entry
57
+ */
58
+ async get(key: string, namespace = 'default'): Promise<MemoryEntry | null> {
59
+ return this.memoryStorage.get(key, namespace);
60
+ }
61
+
62
+ /**
63
+ * Get all memory entries
64
+ */
65
+ async getAll(namespace?: string): Promise<MemoryEntry[]> {
66
+ return this.memoryStorage.getAll(namespace);
67
+ }
68
+
69
+ /**
70
+ * Search memory entries
71
+ */
72
+ async search(pattern: string, namespace?: string): Promise<MemoryEntry[]> {
73
+ return this.memoryStorage.search(pattern, namespace);
74
+ }
75
+
76
+ /**
77
+ * Delete a memory entry
78
+ */
79
+ async delete(key: string, namespace = 'default'): Promise<boolean> {
80
+ return this.memoryStorage.delete(key, namespace);
81
+ }
82
+
83
+ /**
84
+ * Clear all memory entries in a namespace
85
+ */
86
+ async clear(namespace = 'default'): Promise<void> {
87
+ return this.memoryStorage.clear(namespace);
88
+ }
89
+
90
+ /**
91
+ * Get memory statistics
92
+ */
93
+ async getStats(namespace?: string): Promise<{
94
+ totalEntries: number;
95
+ namespaces: string[];
96
+ }> {
97
+ return this.memoryStorage.getStats(namespace);
98
+ }
99
+
100
+ // === Codebase Files Operations (delegated to CacheStorage) ===
101
+
102
+ /**
103
+ * Store a codebase file entry
104
+ */
105
+ async setCodebaseFile(
106
+ path: string,
107
+ mtime: number,
108
+ hash: string,
109
+ content?: string,
110
+ language?: string,
111
+ size?: number
112
+ ): Promise<void> {
113
+ const indexedAt = new Date().toISOString();
114
+ return this.cacheStorage.setCodebaseFile({
115
+ path,
116
+ mtime,
117
+ hash,
118
+ content,
119
+ language,
120
+ size,
121
+ indexedAt,
122
+ });
123
+ }
124
+
125
+ /**
126
+ * Get a codebase file entry
127
+ */
128
+ async getCodebaseFile(path: string): Promise<CodebaseFileEntry | null> {
129
+ return this.cacheStorage.getCodebaseFile(path);
130
+ }
131
+
132
+ /**
133
+ * Get all codebase files
134
+ */
135
+ async getAllCodebaseFiles(): Promise<CodebaseFileEntry[]> {
136
+ return this.cacheStorage.getAllCodebaseFiles();
137
+ }
138
+
139
+ /**
140
+ * Delete a codebase file entry
141
+ */
142
+ async deleteCodebaseFile(path: string): Promise<boolean> {
143
+ return this.cacheStorage.deleteCodebaseFile(path);
144
+ }
145
+
146
+ /**
147
+ * Clear all codebase files
148
+ */
149
+ async clearCodebaseFiles(): Promise<void> {
150
+ return this.cacheStorage.clearCodebaseFiles();
151
+ }
152
+
153
+ // === Metadata Operations (delegated to CacheStorage) ===
154
+
155
+ /**
156
+ * Set metadata value
157
+ */
158
+ async setMetadata(key: string, value: string): Promise<void> {
159
+ return this.cacheStorage.setMetadata(key, value);
160
+ }
161
+
162
+ /**
163
+ * Get metadata value
164
+ */
165
+ async getMetadata(key: string): Promise<string | null> {
166
+ return this.cacheStorage.getMetadata(key);
167
+ }
168
+
169
+ /**
170
+ * Get all metadata
171
+ */
172
+ async getAllMetadata(): Promise<Record<string, string>> {
173
+ return this.cacheStorage.getAllMetadata();
174
+ }
175
+
176
+ /**
177
+ * Delete metadata
178
+ */
179
+ async deleteMetadata(key: string): Promise<boolean> {
180
+ return this.cacheStorage.deleteMetadata(key);
181
+ }
182
+
183
+ // === TF-IDF Terms Operations (delegated to CacheStorage) ===
184
+
185
+ /**
186
+ * Store TF-IDF terms for a file
187
+ */
188
+ async setTfidfTerms(
189
+ terms: Array<{ filePath: string; term: string; frequency: number }>
190
+ ): Promise<void> {
191
+ return this.cacheStorage.setTfidfTerms(terms);
192
+ }
193
+
194
+ /**
195
+ * Get TF-IDF terms for a file
196
+ */
197
+ async getTfidfTerms(filePath: string): Promise<TfidfTermEntry[]> {
198
+ return this.cacheStorage.getTfidfTerms(filePath);
199
+ }
200
+
201
+ /**
202
+ * Get TF-IDF terms by term
203
+ */
204
+ async getTfidfTermsByTerm(term: string): Promise<TfidfTermEntry[]> {
205
+ return this.cacheStorage.getTfidfTermsByTerm(term);
206
+ }
207
+
208
+ /**
209
+ * Clear all TF-IDF terms
210
+ */
211
+ async clearTfidfTerms(): Promise<void> {
212
+ return this.cacheStorage.clearTfidfTerms();
213
+ }
214
+
215
+ // === TF-IDF Documents Operations (delegated to CacheStorage) ===
216
+
217
+ /**
218
+ * Store TF-IDF document vector
219
+ */
220
+ async setTfidfDocument(
221
+ filePath: string,
222
+ magnitude: number,
223
+ termCount: number,
224
+ rawTerms: string
225
+ ): Promise<void> {
226
+ return this.cacheStorage.setTfidfDocument({
227
+ filePath,
228
+ magnitude,
229
+ termCount,
230
+ rawTerms,
231
+ });
232
+ }
233
+
234
+ /**
235
+ * Get TF-IDF document (alias for getTfidfDocument for compatibility)
236
+ */
237
+ async getTFIDFDocument(filePath: string): Promise<TfidfDocumentEntry | null> {
238
+ return this.cacheStorage.getTfidfDocument(filePath);
239
+ }
240
+
241
+ /**
242
+ * Get all TF-IDF documents
243
+ */
244
+ async getAllTfidfDocuments(): Promise<TfidfDocumentEntry[]> {
245
+ return this.cacheStorage.getAllTfidfDocuments();
246
+ }
247
+
248
+ /**
249
+ * Clear all TF-IDF documents
250
+ */
251
+ async clearTfidfDocuments(): Promise<void> {
252
+ return this.cacheStorage.clearTfidfDocuments();
253
+ }
254
+
255
+ // === TF-IDF IDF Operations (delegated to CacheStorage) ===
256
+
257
+ /**
258
+ * Store IDF value
259
+ */
260
+ async setTfidfIdf(term: string, idfValue: number): Promise<void> {
261
+ return this.cacheStorage.setTfidfIdf({ term, idfValue });
262
+ }
263
+
264
+ /**
265
+ * Get IDF value
266
+ */
267
+ async getTfidfIdf(term: string): Promise<TfidfIdfEntry | null> {
268
+ return this.cacheStorage.getTfidfIdf(term);
269
+ }
270
+
271
+ /**
272
+ * Get all IDF values
273
+ */
274
+ async getAllTfidfIdf(): Promise<TfidfIdfEntry[]> {
275
+ return this.cacheStorage.getAllTfidfIdf();
276
+ }
277
+
278
+ /**
279
+ * Clear all IDF values
280
+ */
281
+ async clearTfidfIdf(): Promise<void> {
282
+ return this.cacheStorage.clearTfidfIdf();
283
+ }
284
+
285
+ // === Utility Operations ===
286
+
287
+ /**
288
+ * Get comprehensive cache statistics
289
+ */
290
+ async getCacheStats(): Promise<{
291
+ codebaseFiles: number;
292
+ metadataEntries: number;
293
+ tfidfTerms: number;
294
+ tfidfDocuments: number;
295
+ tfidfIdfValues: number;
296
+ }> {
297
+ return this.cacheStorage.getStats();
298
+ }
299
+
300
+ /**
301
+ * Clear all cache data
302
+ */
303
+ async clearAllCache(): Promise<void> {
304
+ return this.cacheStorage.clearAll();
305
+ }
306
+
307
+ /**
308
+ * Get comprehensive statistics for both memory and cache
309
+ */
310
+ async getAllStats(): Promise<{
311
+ memory: {
312
+ totalEntries: number;
313
+ namespaces: string[];
314
+ };
315
+ cache: {
316
+ codebaseFiles: number;
317
+ metadataEntries: number;
318
+ tfidfTerms: number;
319
+ tfidfDocuments: number;
320
+ tfidfIdfValues: number;
321
+ };
322
+ }> {
323
+ const [memoryStats, cacheStats] = await Promise.all([
324
+ this.memoryStorage.getStats(),
325
+ this.cacheStorage.getStats(),
326
+ ]);
327
+
328
+ return {
329
+ memory: memoryStats,
330
+ cache: cacheStats,
331
+ };
332
+ }
333
+
334
+ /**
335
+ * Clear all data (both memory and cache)
336
+ */
337
+ async clearAll(): Promise<void> {
338
+ await Promise.all([this.memoryStorage.clear('default'), this.cacheStorage.clearAll()]);
339
+ }
340
+
341
+ // === Additional methods for UnifiedSearchService compatibility ===
342
+
343
+ /**
344
+ * Get codebase index statistics
345
+ */
346
+ async getCodebaseIndexStats(): Promise<{
347
+ indexedAt?: string;
348
+ totalFiles: number;
349
+ totalTerms: number;
350
+ }> {
351
+ const metadata = await this.cacheStorage.getAllMetadata();
352
+ return {
353
+ indexedAt: metadata.indexedAt,
354
+ totalFiles: Number.parseInt(metadata.totalFiles || '0', 10),
355
+ totalTerms: Number.parseInt(metadata.totalTerms || '0', 10),
356
+ };
357
+ }
358
+
359
+ /**
360
+ * Get IDF values (alias for getAllTfidfIdf)
361
+ */
362
+ async getIDFValues(): Promise<Record<string, number>> {
363
+ const entries = await this.cacheStorage.getAllTfidfIdf();
364
+ const idfValues: Record<string, number> = {};
365
+ for (const entry of entries) {
366
+ idfValues[entry.term] = entry.idfValue;
367
+ }
368
+ return idfValues;
369
+ }
370
+
371
+ /**
372
+ * Upsert TF-IDF document (alias for setTfidfDocument)
373
+ */
374
+ async upsertTFIDFDocument(
375
+ filePath: string,
376
+ document: {
377
+ magnitude: number;
378
+ termCount: number;
379
+ rawTerms: Record<string, number>;
380
+ }
381
+ ): Promise<void> {
382
+ return this.cacheStorage.setTfidfDocument({
383
+ filePath,
384
+ magnitude: document.magnitude,
385
+ termCount: document.termCount,
386
+ rawTerms: JSON.stringify(document.rawTerms),
387
+ });
388
+ }
389
+
390
+ /**
391
+ * Upsert codebase file (alias for setCodebaseFile)
392
+ */
393
+ async upsertCodebaseFile(file: {
394
+ path: string;
395
+ mtime: number;
396
+ hash: string;
397
+ content?: string;
398
+ language?: string;
399
+ size?: number;
400
+ indexedAt?: string;
401
+ }): Promise<void> {
402
+ return this.cacheStorage.setCodebaseFile({
403
+ ...file,
404
+ indexedAt: file.indexedAt || new Date().toISOString(),
405
+ });
406
+ }
407
+
408
+ /**
409
+ * Set IDF values (alias for multiple setTfidfIdf calls)
410
+ */
411
+ async setIDFValues(idfValues: Record<string, number>): Promise<void> {
412
+ const promises = Object.entries(idfValues).map(([term, idfValue]) =>
413
+ this.cacheStorage.setTfidfIdf({ term, idfValue })
414
+ );
415
+ await Promise.all(promises);
416
+ }
417
+
418
+ /**
419
+ * Clear codebase index
420
+ */
421
+ async clearCodebaseIndex(): Promise<void> {
422
+ await Promise.all([
423
+ this.cacheStorage.clearCodebaseFiles(),
424
+ this.cacheStorage.clearTfidfTerms(),
425
+ this.cacheStorage.clearTfidfDocuments(),
426
+ this.cacheStorage.clearTfidfIdf(),
427
+ ]);
428
+ }
429
+
430
+ /**
431
+ * Get codebase metadata (alias for getMetadata)
432
+ */
433
+ async getCodebaseMetadata(key: string): Promise<string | null> {
434
+ return this.cacheStorage.getMetadata(key);
435
+ }
436
+
437
+ /**
438
+ * Set codebase metadata (alias for setMetadata)
439
+ */
440
+ async setCodebaseMetadata(key: string, value: string): Promise<void> {
441
+ return this.cacheStorage.setMetadata(key, value);
442
+ }
443
+
444
+ /**
445
+ * Get TF-IDF terms for a file
446
+ */
447
+ async getTFIDFTerms(filePath: string): Promise<Record<string, number>> {
448
+ const entries = await this.cacheStorage.getTfidfTerms(filePath);
449
+ const terms: Record<string, number> = {};
450
+ for (const entry of entries) {
451
+ terms[entry.term] = entry.frequency;
452
+ }
453
+ return terms;
454
+ }
455
+
456
+ /**
457
+ * Set TF-IDF terms (alias for setTfidfTerms)
458
+ */
459
+ async setTFIDFTerms(filePath: string, terms: Record<string, number>): Promise<void> {
460
+ const termsWithFilePath = Object.entries(terms).map(([term, frequency]) => ({
461
+ filePath,
462
+ term,
463
+ frequency,
464
+ }));
465
+ return this.cacheStorage.setTfidfTerms(termsWithFilePath);
466
+ }
467
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Vector storage interface and implementation
3
+ * Uses LanceDB for high-performance local vector database
4
+ */
5
+
6
+ // Re-export from the LanceDB implementation
7
+ export {
8
+ generateMockEmbedding,
9
+ type VectorDocument,
10
+ type VectorSearchResult,
11
+ VectorStorage,
12
+ type VectorStorageMetadata,
13
+ } from './lancedb-vector-storage.js';
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Agent configuration and selection utilities
3
+ */
4
+
5
+ import type { AgentConfig, AgentConfigs } from '../types/index.js';
6
+
7
+ /**
8
+ * Get list of supported agents
9
+ * @param configs - Agent configurations
10
+ * @returns Array of supported agent keys
11
+ */
12
+ export function getSupportedAgents(configs: AgentConfigs): string[] {
13
+ return Object.keys(configs);
14
+ }
15
+
16
+ /**
17
+ * Get configuration for a specific agent
18
+ * @param configs - Agent configurations
19
+ * @param agent - Agent key
20
+ * @returns Agent configuration
21
+ * @throws Error if agent not found
22
+ */
23
+ export function getAgentConfig(configs: AgentConfigs, agent: string): AgentConfig {
24
+ const config = configs[agent];
25
+ if (!config) {
26
+ throw new Error(`Agent configuration not found: ${agent}`);
27
+ }
28
+ return config;
29
+ }
30
+
31
+ /**
32
+ * Prompt user to select an agent (currently defaults to first)
33
+ * @param configs - Agent configurations
34
+ * @param toolName - Name of the tool for display
35
+ * @returns Selected agent key
36
+ */
37
+ export async function promptForAgent(configs: AgentConfigs, toolName: string): Promise<string> {
38
+ const supportedAgents = getSupportedAgents(configs);
39
+
40
+ console.log(`\n📝 ${toolName}`);
41
+ console.log('================');
42
+ console.log('Available agents:');
43
+ supportedAgents.forEach((agent, index) => {
44
+ const config = getAgentConfig(configs, agent);
45
+ console.log(` ${index + 1}. ${config.name} - ${config.description}`);
46
+ });
47
+
48
+ // For now, default to first agent
49
+ // In a real implementation, you might want to use readline or a CLI prompt library
50
+ return supportedAgents[0];
51
+ }
52
+
53
+ /**
54
+ * Detect which agent tool to use
55
+ * @param configs - Agent configurations
56
+ * @param defaultAgent - Default agent to use
57
+ * @returns Agent key
58
+ */
59
+ export function detectAgentTool(_configs: AgentConfigs, defaultAgent = 'opencode'): string {
60
+ // Simple detection logic - could be enhanced
61
+ // For now, return default
62
+ return defaultAgent;
63
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * File collection and information utilities
3
+ */
4
+
5
+ import path from 'node:path';
6
+ import {
7
+ deletePathSafe,
8
+ getFileInfo,
9
+ readDirectorySafe,
10
+ readFileSafe,
11
+ } from '../../utils/file-operations.js';
12
+ import type { ProcessResult } from '../types/index.js';
13
+
14
+ /**
15
+ * Collect files from directory with specified extensions
16
+ * @param dir - Directory to search
17
+ * @param extensions - File extensions to include
18
+ * @returns Array of file paths relative to directory
19
+ */
20
+ export async function collectFiles(dir: string, extensions: string[]): Promise<string[]> {
21
+ try {
22
+ const allFiles = await readDirectorySafe(dir, {
23
+ recursive: true,
24
+ includeFiles: true,
25
+ includeDirectories: false,
26
+ });
27
+
28
+ return allFiles
29
+ .filter((filePath) => extensions.some((ext) => filePath.endsWith(ext)))
30
+ .map((filePath) => path.relative(dir, filePath))
31
+ .sort();
32
+ } catch {
33
+ return [];
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Get local file information including content and modification time
39
+ * @param filePath - Path to file
40
+ * @returns File info with content and mtime, or null if file doesn't exist
41
+ */
42
+ export async function getLocalFileInfo(
43
+ filePath: string
44
+ ): Promise<{ content: string; mtime: Date } | null> {
45
+ const info = await getFileInfo(filePath);
46
+
47
+ if (!info.exists || !info.isFile) {
48
+ return null;
49
+ }
50
+
51
+ const content = await readFileSafe(filePath);
52
+
53
+ if (content === null) {
54
+ return null;
55
+ }
56
+
57
+ return {
58
+ content,
59
+ mtime: info.mtime!,
60
+ };
61
+ }
62
+
63
+ /**
64
+ * Clear obsolete files from target directory
65
+ * @param targetDir - Target directory
66
+ * @param expectedFiles - Set of expected file names
67
+ * @param extensions - Valid file extensions
68
+ * @param results - Array to store process results
69
+ */
70
+ export async function clearObsoleteFiles(
71
+ targetDir: string,
72
+ expectedFiles: Set<string>,
73
+ extensions: string[],
74
+ results: ProcessResult[]
75
+ ): Promise<void> {
76
+ try {
77
+ const items = await readDirectorySafe(targetDir, {
78
+ recursive: false,
79
+ includeFiles: true,
80
+ includeDirectories: false,
81
+ });
82
+
83
+ for (const itemPath of items) {
84
+ const fileName = path.basename(itemPath);
85
+ const hasValidExtension = extensions.some((ext) => fileName.endsWith(ext));
86
+
87
+ if (hasValidExtension && !expectedFiles.has(fileName)) {
88
+ await deletePathSafe(itemPath);
89
+ results.push({
90
+ file: fileName,
91
+ status: 'skipped',
92
+ action: 'Removed obsolete file',
93
+ });
94
+ }
95
+ }
96
+ } catch {
97
+ // Directory doesn't exist, nothing to clear
98
+ }
99
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Shared utilities and types barrel export
3
+ * Provides clean access to all shared functionality
4
+ */
5
+
6
+ // Agent configuration
7
+ export {
8
+ detectAgentTool,
9
+ getAgentConfig,
10
+ getSupportedAgents,
11
+ promptForAgent,
12
+ } from './agents/index.js';
13
+ // File operations
14
+ export {
15
+ clearObsoleteFiles,
16
+ collectFiles,
17
+ getLocalFileInfo,
18
+ } from './files/index.js';
19
+ // Logging
20
+ export { log } from './logging/index.js';
21
+ // Processing utilities
22
+ export {
23
+ displayResults,
24
+ processBatch,
25
+ } from './processing/index.js';
26
+ // Types
27
+ export type {
28
+ AgentConfig,
29
+ AgentConfigs,
30
+ CommonOptions,
31
+ ProcessResult,
32
+ } from './types/index.js';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Logging utilities for console output with colors
3
+ */
4
+
5
+ /**
6
+ * Log a message with color
7
+ * @param message - Message to log
8
+ * @param color - Color name (red, green, yellow, blue, magenta, cyan, white)
9
+ */
10
+ export function log(message: string, color = 'white'): void {
11
+ const colors = {
12
+ red: '\x1b[31m',
13
+ green: '\x1b[32m',
14
+ yellow: '\x1b[33m',
15
+ blue: '\x1b[34m',
16
+ magenta: '\x1b[35m',
17
+ cyan: '\x1b[36m',
18
+ white: '\x1b[37m',
19
+ reset: '\x1b[0m',
20
+ };
21
+
22
+ const colorCode = colors[color as keyof typeof colors] || colors.white;
23
+ console.log(`${colorCode}${message}${colors.reset}`);
24
+ }