@sylphx/flow 1.1.1 → 1.3.0

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 (47) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/package.json +1 -1
  3. package/src/commands/flow-command.ts +28 -0
  4. package/src/commands/hook-command.ts +10 -230
  5. package/src/composables/index.ts +0 -1
  6. package/src/config/servers.ts +35 -78
  7. package/src/core/interfaces.ts +0 -33
  8. package/src/domains/index.ts +0 -2
  9. package/src/index.ts +0 -4
  10. package/src/services/mcp-service.ts +0 -16
  11. package/src/targets/claude-code.ts +3 -9
  12. package/src/targets/functional/claude-code-logic.ts +4 -22
  13. package/src/targets/opencode.ts +0 -6
  14. package/src/types/mcp.types.ts +29 -38
  15. package/src/types/target.types.ts +0 -2
  16. package/src/types.ts +0 -1
  17. package/src/utils/sync-utils.ts +106 -0
  18. package/src/commands/codebase-command.ts +0 -168
  19. package/src/commands/knowledge-command.ts +0 -161
  20. package/src/composables/useTargetConfig.ts +0 -45
  21. package/src/core/formatting/bytes.test.ts +0 -115
  22. package/src/core/validation/limit.test.ts +0 -155
  23. package/src/core/validation/query.test.ts +0 -44
  24. package/src/domains/codebase/index.ts +0 -5
  25. package/src/domains/codebase/tools.ts +0 -139
  26. package/src/domains/knowledge/index.ts +0 -10
  27. package/src/domains/knowledge/resources.ts +0 -537
  28. package/src/domains/knowledge/tools.ts +0 -174
  29. package/src/services/search/base-indexer.ts +0 -156
  30. package/src/services/search/codebase-indexer-types.ts +0 -38
  31. package/src/services/search/codebase-indexer.ts +0 -647
  32. package/src/services/search/embeddings-provider.ts +0 -455
  33. package/src/services/search/embeddings.ts +0 -316
  34. package/src/services/search/functional-indexer.ts +0 -323
  35. package/src/services/search/index.ts +0 -27
  36. package/src/services/search/indexer.ts +0 -380
  37. package/src/services/search/knowledge-indexer.ts +0 -422
  38. package/src/services/search/semantic-search.ts +0 -244
  39. package/src/services/search/tfidf.ts +0 -559
  40. package/src/services/search/unified-search-service.ts +0 -888
  41. package/src/services/storage/cache-storage.ts +0 -487
  42. package/src/services/storage/drizzle-storage.ts +0 -581
  43. package/src/services/storage/index.ts +0 -15
  44. package/src/services/storage/lancedb-vector-storage.ts +0 -494
  45. package/src/services/storage/memory-storage.ts +0 -268
  46. package/src/services/storage/separated-storage.ts +0 -467
  47. package/src/services/storage/vector-storage.ts +0 -13
@@ -1,467 +0,0 @@
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
- }
@@ -1,13 +0,0 @@
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';