@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,211 @@
1
+ /**
2
+ * Codebase indexing helper functions
3
+ * Utility functions for file scanning and language detection
4
+ */
5
+
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ import ignore, { type Ignore } from 'ignore';
9
+
10
+ /**
11
+ * Detect programming language from file extension
12
+ */
13
+ export function detectLanguage(filePath: string): string | undefined {
14
+ const ext = path.extname(filePath).toLowerCase();
15
+ const languageMap: Record<string, string> = {
16
+ '.ts': 'TypeScript',
17
+ '.tsx': 'TSX',
18
+ '.js': 'JavaScript',
19
+ '.jsx': 'JSX',
20
+ '.py': 'Python',
21
+ '.java': 'Java',
22
+ '.go': 'Go',
23
+ '.rs': 'Rust',
24
+ '.c': 'C',
25
+ '.cpp': 'C++',
26
+ '.cs': 'C#',
27
+ '.rb': 'Ruby',
28
+ '.php': 'PHP',
29
+ '.swift': 'Swift',
30
+ '.kt': 'Kotlin',
31
+ '.md': 'Markdown',
32
+ '.json': 'JSON',
33
+ '.yaml': 'YAML',
34
+ '.yml': 'YAML',
35
+ '.toml': 'TOML',
36
+ '.sql': 'SQL',
37
+ '.sh': 'Shell',
38
+ '.bash': 'Bash',
39
+ };
40
+ return languageMap[ext];
41
+ }
42
+
43
+ /**
44
+ * Check if file is text-based (not binary)
45
+ */
46
+ export function isTextFile(filePath: string): boolean {
47
+ const textExtensions = new Set([
48
+ '.ts',
49
+ '.tsx',
50
+ '.js',
51
+ '.jsx',
52
+ '.py',
53
+ '.java',
54
+ '.go',
55
+ '.rs',
56
+ '.c',
57
+ '.cpp',
58
+ '.h',
59
+ '.hpp',
60
+ '.cs',
61
+ '.rb',
62
+ '.php',
63
+ '.swift',
64
+ '.kt',
65
+ '.md',
66
+ '.txt',
67
+ '.json',
68
+ '.yaml',
69
+ '.yml',
70
+ '.toml',
71
+ '.xml',
72
+ '.sql',
73
+ '.sh',
74
+ '.bash',
75
+ '.zsh',
76
+ '.fish',
77
+ '.dockerfile',
78
+ '.gitignore',
79
+ '.env',
80
+ '.env.example',
81
+ '.env.local',
82
+ '.env.development',
83
+ '.env.production',
84
+ ]);
85
+
86
+ const ext = path.extname(filePath).toLowerCase();
87
+ return textExtensions.has(ext) || !ext; // Files without extension might be text
88
+ }
89
+
90
+ /**
91
+ * Load .gitignore file and create ignore filter
92
+ */
93
+ export function loadGitignore(codebaseRoot: string): Ignore {
94
+ const ig = ignore();
95
+
96
+ // Add default ignore patterns
97
+ ig.add([
98
+ 'node_modules',
99
+ '.git',
100
+ '.svn',
101
+ '.hg',
102
+ '.DS_Store',
103
+ '.idea',
104
+ '.vscode',
105
+ '*.suo',
106
+ '*.ntvs*',
107
+ '*.njsproj',
108
+ '*.sln',
109
+ '*.swp',
110
+ '.sylphx-flow',
111
+ '.cache',
112
+ 'dist',
113
+ 'build',
114
+ 'coverage',
115
+ '.nyc_output',
116
+ ]);
117
+
118
+ const gitignorePath = path.join(codebaseRoot, '.gitignore');
119
+
120
+ if (fs.existsSync(gitignorePath)) {
121
+ try {
122
+ const content = fs.readFileSync(gitignorePath, 'utf8');
123
+ ig.add(content);
124
+ } catch (error) {
125
+ console.warn(`[WARN] Failed to read .gitignore: ${error}`);
126
+ }
127
+ }
128
+
129
+ return ig;
130
+ }
131
+
132
+ /**
133
+ * Scan directory recursively for files
134
+ */
135
+ export interface ScanOptions {
136
+ ignoreFilter?: Ignore;
137
+ codebaseRoot?: string;
138
+ }
139
+
140
+ export interface ScanResult {
141
+ path: string;
142
+ absolutePath: string;
143
+ content: string;
144
+ size: number;
145
+ mtime: number;
146
+ }
147
+
148
+ /**
149
+ * Scan files in directory with .gitignore support
150
+ */
151
+ export function scanFiles(dir: string, options: ScanOptions = {}): ScanResult[] {
152
+ const results: ScanResult[] = [];
153
+ const ignoreFilter = options.ignoreFilter;
154
+ const codebaseRoot = options.codebaseRoot || dir;
155
+
156
+ function scan(currentDir: string) {
157
+ const entries = fs.readdirSync(currentDir, { withFileTypes: true });
158
+
159
+ for (const entry of entries) {
160
+ const fullPath = path.join(currentDir, entry.name);
161
+ const relativePath = path.relative(codebaseRoot, fullPath);
162
+
163
+ // Skip ignored files
164
+ if (ignoreFilter?.ignores(relativePath)) {
165
+ continue;
166
+ }
167
+
168
+ if (entry.isDirectory()) {
169
+ scan(fullPath);
170
+ } else if (entry.isFile()) {
171
+ try {
172
+ const stats = fs.statSync(fullPath);
173
+ const _ext = path.extname(fullPath);
174
+
175
+ // Only process text files
176
+ if (!isTextFile(fullPath)) {
177
+ continue;
178
+ }
179
+
180
+ const content = fs.readFileSync(fullPath, 'utf8');
181
+
182
+ results.push({
183
+ path: relativePath,
184
+ absolutePath: fullPath,
185
+ content,
186
+ size: stats.size,
187
+ mtime: stats.mtimeMs,
188
+ });
189
+ } catch (error) {
190
+ console.warn(`[WARN] Failed to read file: ${relativePath}`, error);
191
+ }
192
+ }
193
+ }
194
+ }
195
+
196
+ scan(dir);
197
+ return results;
198
+ }
199
+
200
+ /**
201
+ * Calculate simple hash for file content (for change detection)
202
+ */
203
+ export function simpleHash(content: string): string {
204
+ let hash = 0;
205
+ for (let i = 0; i < content.length; i++) {
206
+ const char = content.charCodeAt(i);
207
+ hash = (hash << 5) - hash + char;
208
+ hash &= hash; // Convert to 32-bit integer
209
+ }
210
+ return hash.toString(36);
211
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Modern console UI utilities
3
+ * Progressive output with beautiful formatting
4
+ */
5
+
6
+ import chalk from 'chalk';
7
+
8
+ export const ui = {
9
+ // Headers
10
+ header: (text: string) => {
11
+ console.log('');
12
+ console.log(chalk.cyan.bold(`▸ ${text}`));
13
+ },
14
+
15
+ subheader: (text: string) => {
16
+ console.log(chalk.gray(` ${text}`));
17
+ },
18
+
19
+ // Status messages
20
+ success: (text: string) => {
21
+ console.log(chalk.green(`✓ ${text}`));
22
+ },
23
+
24
+ error: (text: string) => {
25
+ console.log(chalk.red(`✗ ${text}`));
26
+ },
27
+
28
+ warning: (text: string) => {
29
+ console.log(chalk.yellow(`⚠ ${text}`));
30
+ },
31
+
32
+ info: (text: string) => {
33
+ console.log(chalk.cyan(`ℹ ${text}`));
34
+ },
35
+
36
+ // Progress
37
+ step: (text: string) => {
38
+ console.log(chalk.gray(` • ${text}`));
39
+ },
40
+
41
+ loading: (text: string) => {
42
+ console.log(chalk.cyan(`⏳ ${text}`));
43
+ },
44
+
45
+ // Fields
46
+ field: (label: string, value: string, secret = false) => {
47
+ const displayValue = secret ? '•'.repeat(Math.min(8, value.length)) : value;
48
+ console.log(` ${chalk.gray(label)}: ${chalk.white(displayValue)}`);
49
+ },
50
+
51
+ // Dividers
52
+ divider: () => {
53
+ console.log(chalk.gray(' ─'.repeat(40)));
54
+ },
55
+
56
+ spacer: () => {
57
+ console.log('');
58
+ },
59
+
60
+ // Lists
61
+ list: (items: string[]) => {
62
+ items.forEach((item) => {
63
+ console.log(chalk.gray(` • ${item}`));
64
+ });
65
+ },
66
+
67
+ // Input prompt (for simple inputs)
68
+ prompt: (label: string, required = false) => {
69
+ const indicator = required ? chalk.red('*') : '';
70
+ return `${chalk.cyan('❯')} ${label}${indicator}: `;
71
+ },
72
+
73
+ // Section
74
+ section: (title: string, content: () => void) => {
75
+ console.log('');
76
+ console.log(chalk.cyan.bold(`▸ ${title}`));
77
+ content();
78
+ },
79
+ };
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Database Error Handling - Simplified System
3
+ * Replaces complex error hierarchy with simplified database-specific errors
4
+ */
5
+
6
+ import {
7
+ AppError,
8
+ createDatabaseError,
9
+ createValidationError,
10
+ ErrorCategory,
11
+ ErrorHandler,
12
+ ErrorSeverity,
13
+ DatabaseError as SimplifiedDatabaseError,
14
+ ValidationError as SimplifiedValidationError,
15
+ } from './simplified-errors.js';
16
+
17
+ /**
18
+ * Simplified Database Error with additional database context
19
+ */
20
+ export class DatabaseError extends SimplifiedDatabaseError {
21
+ constructor(
22
+ message: string,
23
+ operation?: string,
24
+ cause?: Error,
25
+ context?: Record<string, unknown>
26
+ ) {
27
+ super(message, operation, context?.query as string);
28
+ this.cause = cause;
29
+ if (context) {
30
+ this.context = { ...this.context, ...context };
31
+ }
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Database-specific validation error
37
+ */
38
+ export class ValidationError extends SimplifiedValidationError {
39
+ constructor(message: string, field: string, value?: unknown, cause?: Error) {
40
+ super(message, field, value);
41
+ this.cause = cause;
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Database connection error
47
+ */
48
+ export class ConnectionError extends AppError {
49
+ constructor(message: string, connectionDetails?: Record<string, unknown>, cause?: Error) {
50
+ super(
51
+ message,
52
+ 'CONNECTION_ERROR',
53
+ ErrorCategory.NETWORK,
54
+ ErrorSeverity.HIGH,
55
+ connectionDetails,
56
+ cause
57
+ );
58
+ this.name = 'ConnectionError';
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Database migration error
64
+ */
65
+ export class MigrationError extends AppError {
66
+ public readonly migrationName?: string;
67
+
68
+ constructor(message: string, migrationName?: string, cause?: Error) {
69
+ super(
70
+ message,
71
+ 'MIGRATION_ERROR',
72
+ ErrorCategory.DATABASE,
73
+ ErrorSeverity.HIGH,
74
+ { migrationName },
75
+ cause
76
+ );
77
+ this.migrationName = migrationName;
78
+ this.name = 'MigrationError';
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Execute database operation with comprehensive error handling
84
+ */
85
+ export async function executeOperation<T>(
86
+ operation: string,
87
+ fn: () => Promise<T>,
88
+ context?: Record<string, unknown>
89
+ ): Promise<T> {
90
+ const result = await ErrorHandler.execute(fn, { operation, ...context });
91
+
92
+ if (result.success) {
93
+ return result.data;
94
+ }
95
+
96
+ // Convert to appropriate database error type
97
+ if (result.error instanceof AppError) {
98
+ throw result.error;
99
+ }
100
+
101
+ // Unknown error - wrap in DatabaseError
102
+ throw createDatabaseError(result.error.message, operation, context?.query as string);
103
+ }
104
+
105
+ /**
106
+ * Type guard functions for database errors
107
+ */
108
+ export function isDatabaseError(error: unknown): error is DatabaseError {
109
+ return error instanceof DatabaseError;
110
+ }
111
+
112
+ export function isValidationError(error: unknown): error is ValidationError {
113
+ return error instanceof ValidationError;
114
+ }
115
+
116
+ export function isConnectionError(error: unknown): error is ConnectionError {
117
+ return error instanceof ConnectionError;
118
+ }
119
+
120
+ export function isMigrationError(error: unknown): error is MigrationError {
121
+ return error instanceof MigrationError;
122
+ }
123
+
124
+ /**
125
+ * Convenience functions for creating database errors
126
+ */
127
+ export const createMigrationError = (
128
+ message: string,
129
+ migrationName?: string,
130
+ cause?: Error
131
+ ): MigrationError => new MigrationError(message, migrationName, cause);
132
+
133
+ export const createConnectionError = (
134
+ message: string,
135
+ connectionDetails?: Record<string, unknown>,
136
+ cause?: Error
137
+ ): ConnectionError => new ConnectionError(message, connectionDetails, cause);
138
+
139
+ // Re-export for backward compatibility
140
+ export { createDatabaseError, createValidationError, ErrorHandler, AppError };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Debug Logger
3
+ * Uses industry-standard 'debug' package
4
+ *
5
+ * Usage:
6
+ * DEBUG=* bun ./packages/flow/src/index.ts // All debug logs
7
+ * DEBUG=sylphx:* bun ... // All sylphx namespaces
8
+ * DEBUG=sylphx:search:* bun ... // Search namespace
9
+ * (no DEBUG) bun ... // No debug logs
10
+ *
11
+ * Examples:
12
+ * import { createLogger } from '../utils/debug-logger.js';
13
+ *
14
+ * const log = createLogger('search:indexing');
15
+ * log('Indexing started:', filePath);
16
+ *
17
+ * Features from 'debug' package:
18
+ * - Color-coded namespaces
19
+ * - Timestamp support (DEBUG_COLORS=no for no color)
20
+ * - Wildcard matching (DEBUG=sylphx:*)
21
+ * - Conditional logging (no performance impact when disabled)
22
+ * - Industry standard (used by Express, Socket.io, etc.)
23
+ */
24
+
25
+ import debug from 'debug';
26
+
27
+ /**
28
+ * Create a logger for a specific namespace
29
+ * Namespace will be prefixed with 'sylphx:'
30
+ *
31
+ * @example
32
+ * const log = createLogger('search:indexing');
33
+ * log('Indexing started:', filePath);
34
+ *
35
+ * // Enable with:
36
+ * // DEBUG=sylphx:search:indexing bun ./packages/flow/src/index.ts
37
+ */
38
+ export function createLogger(namespace: string) {
39
+ return debug(`sylphx:${namespace}`);
40
+ }
41
+
42
+ /**
43
+ * For backwards compatibility
44
+ * @deprecated Use createLogger instead
45
+ */
46
+ export function debugLog(namespace: string, ...args: any[]) {
47
+ const log = debug(`sylphx:${namespace}`);
48
+ log(...args);
49
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Legacy error handling utilities
3
+ * @deprecated Use core/functional/error-handler.ts instead
4
+ *
5
+ * MIGRATION PATH:
6
+ * 1. Replace CLIError with cliError from error-types.ts
7
+ * 2. Replace handleError with exitWithError from error-handler.ts
8
+ * 3. Replace createAsyncHandler with createAsyncHandler from error-handler.ts
9
+ *
10
+ * Kept for backward compatibility during migration
11
+ */
12
+
13
+ export class CLIError extends Error {
14
+ constructor(
15
+ message: string,
16
+ public code?: string
17
+ ) {
18
+ super(message);
19
+ this.name = 'CLIError';
20
+ }
21
+ }
22
+
23
+ /**
24
+ * @deprecated Use exitWithError from core/functional/error-handler.ts
25
+ */
26
+ export function handleError(error: unknown, context?: string): never {
27
+ const message = error instanceof Error ? error.message : String(error);
28
+ const contextMsg = context ? ` (${context})` : '';
29
+
30
+ console.error(`✗ Error${contextMsg}: ${message}`);
31
+
32
+ if (error instanceof CLIError && error.code) {
33
+ console.error(` Code: ${error.code}`);
34
+ }
35
+
36
+ process.exit(1);
37
+ }
38
+
39
+ /**
40
+ * @deprecated Use createAsyncHandler from core/functional/error-handler.ts
41
+ */
42
+ export function createAsyncHandler<T extends Record<string, any>>(
43
+ handler: (options: T) => Promise<void>,
44
+ context?: string
45
+ ) {
46
+ return async (options: T): Promise<void> => {
47
+ try {
48
+ await handler(options);
49
+ } catch (error) {
50
+ handleError(error, context);
51
+ }
52
+ };
53
+ }