@sylphx/flow 1.8.0 → 1.8.1
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.
- package/CHANGELOG.md +52 -0
- package/assets/output-styles/silent.md +141 -8
- package/assets/rules/core.md +19 -2
- package/package.json +2 -12
- package/src/commands/flow/execute.ts +470 -0
- package/src/commands/flow/index.ts +11 -0
- package/src/commands/flow/prompt.ts +35 -0
- package/src/commands/flow/setup.ts +312 -0
- package/src/commands/flow/targets.ts +18 -0
- package/src/commands/flow/types.ts +47 -0
- package/src/commands/flow-command.ts +18 -967
- package/src/commands/flow-orchestrator.ts +14 -5
- package/src/commands/hook-command.ts +1 -1
- package/src/commands/init-core.ts +12 -3
- package/src/commands/run-command.ts +1 -1
- package/src/config/rules.ts +1 -1
- package/src/core/error-handling.ts +1 -1
- package/src/core/loop-controller.ts +1 -1
- package/src/core/state-detector.ts +1 -1
- package/src/core/target-manager.ts +1 -1
- package/src/index.ts +1 -1
- package/src/shared/files/index.ts +1 -1
- package/src/shared/processing/index.ts +1 -1
- package/src/targets/claude-code.ts +3 -3
- package/src/targets/opencode.ts +3 -3
- package/src/utils/agent-enhancer.ts +2 -2
- package/src/utils/{mcp-config.ts → config/mcp-config.ts} +4 -4
- package/src/utils/{paths.ts → config/paths.ts} +1 -1
- package/src/utils/{settings.ts → config/settings.ts} +1 -1
- package/src/utils/{target-config.ts → config/target-config.ts} +5 -5
- package/src/utils/{target-utils.ts → config/target-utils.ts} +3 -3
- package/src/utils/display/banner.ts +25 -0
- package/src/utils/display/status.ts +55 -0
- package/src/utils/{file-operations.ts → files/file-operations.ts} +2 -2
- package/src/utils/files/jsonc.ts +36 -0
- package/src/utils/{sync-utils.ts → files/sync-utils.ts} +3 -3
- package/src/utils/index.ts +42 -61
- package/src/utils/version.ts +47 -0
- package/src/components/benchmark-monitor.tsx +0 -331
- package/src/components/reindex-progress.tsx +0 -261
- package/src/composables/functional/index.ts +0 -14
- package/src/composables/functional/useEnvironment.ts +0 -171
- package/src/composables/functional/useFileSystem.ts +0 -139
- package/src/composables/index.ts +0 -4
- package/src/composables/useEnv.ts +0 -13
- package/src/composables/useRuntimeConfig.ts +0 -27
- package/src/core/ai-sdk.ts +0 -603
- package/src/core/app-factory.ts +0 -381
- package/src/core/builtin-agents.ts +0 -9
- package/src/core/command-system.ts +0 -550
- package/src/core/config-system.ts +0 -550
- package/src/core/connection-pool.ts +0 -390
- package/src/core/di-container.ts +0 -155
- package/src/core/headless-display.ts +0 -96
- package/src/core/interfaces/index.ts +0 -22
- package/src/core/interfaces/repository.interface.ts +0 -91
- package/src/core/interfaces/service.interface.ts +0 -133
- package/src/core/interfaces.ts +0 -96
- package/src/core/result.ts +0 -351
- package/src/core/service-config.ts +0 -252
- package/src/core/session-service.ts +0 -121
- package/src/core/storage-factory.ts +0 -115
- package/src/core/stream-handler.ts +0 -288
- package/src/core/type-utils.ts +0 -427
- package/src/core/unified-storage.ts +0 -456
- package/src/core/validation/limit.ts +0 -46
- package/src/core/validation/query.ts +0 -20
- package/src/db/auto-migrate.ts +0 -322
- package/src/db/base-database-client.ts +0 -144
- package/src/db/cache-db.ts +0 -218
- package/src/db/cache-schema.ts +0 -75
- package/src/db/database.ts +0 -70
- package/src/db/index.ts +0 -252
- package/src/db/memory-db.ts +0 -153
- package/src/db/memory-schema.ts +0 -29
- package/src/db/schema.ts +0 -289
- package/src/db/session-repository.ts +0 -733
- package/src/domains/index.ts +0 -6
- package/src/domains/utilities/index.ts +0 -6
- package/src/domains/utilities/time/index.ts +0 -5
- package/src/domains/utilities/time/tools.ts +0 -291
- package/src/services/agent-service.ts +0 -273
- package/src/services/evaluation-service.ts +0 -271
- package/src/services/functional/evaluation-logic.ts +0 -296
- package/src/services/functional/file-processor.ts +0 -273
- package/src/services/functional/index.ts +0 -12
- package/src/services/memory.service.ts +0 -476
- package/src/types/api/batch.ts +0 -108
- package/src/types/api/errors.ts +0 -118
- package/src/types/api/index.ts +0 -55
- package/src/types/api/requests.ts +0 -76
- package/src/types/api/responses.ts +0 -180
- package/src/types/api/websockets.ts +0 -85
- package/src/types/benchmark.ts +0 -49
- package/src/types/database.types.ts +0 -510
- package/src/types/memory-types.ts +0 -63
- package/src/utils/advanced-tokenizer.ts +0 -191
- package/src/utils/ai-model-fetcher.ts +0 -19
- package/src/utils/async-file-operations.ts +0 -516
- package/src/utils/audio-player.ts +0 -345
- package/src/utils/codebase-helpers.ts +0 -211
- package/src/utils/console-ui.ts +0 -79
- package/src/utils/database-errors.ts +0 -140
- package/src/utils/debug-logger.ts +0 -49
- package/src/utils/file-scanner.ts +0 -259
- package/src/utils/help.ts +0 -20
- package/src/utils/immutable-cache.ts +0 -106
- package/src/utils/jsonc.ts +0 -158
- package/src/utils/memory-tui.ts +0 -414
- package/src/utils/models-dev.ts +0 -91
- package/src/utils/parallel-operations.ts +0 -487
- package/src/utils/process-manager.ts +0 -155
- package/src/utils/prompts.ts +0 -120
- package/src/utils/search-tool-builder.ts +0 -214
- package/src/utils/session-manager.ts +0 -168
- package/src/utils/session-title.ts +0 -87
- package/src/utils/simplified-errors.ts +0 -410
- package/src/utils/template-engine.ts +0 -94
- package/src/utils/test-audio.ts +0 -71
- package/src/utils/todo-context.ts +0 -46
- package/src/utils/token-counter.ts +0 -288
- /package/src/utils/{cli-output.ts → display/cli-output.ts} +0 -0
- /package/src/utils/{logger.ts → display/logger.ts} +0 -0
- /package/src/utils/{notifications.ts → display/notifications.ts} +0 -0
- /package/src/utils/{secret-utils.ts → security/secret-utils.ts} +0 -0
- /package/src/utils/{security.ts → security/security.ts} +0 -0
package/src/core/app-factory.ts
DELETED
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Application Factory - 應用工廠
|
|
3
|
-
* Feature-first, composable, functional architecture
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { CommandOptions } from '../types/cli.types.js';
|
|
7
|
-
import { setupGlobalErrorHandlers } from './error-handling.js';
|
|
8
|
-
import { logger } from '../utils/logger.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Application interface
|
|
12
|
-
*/
|
|
13
|
-
export interface Application {
|
|
14
|
-
name: string;
|
|
15
|
-
version: string;
|
|
16
|
-
start(options?: CommandOptions): Promise<void>;
|
|
17
|
-
stop(): Promise<void>;
|
|
18
|
-
isRunning(): boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Application configuration
|
|
23
|
-
*/
|
|
24
|
-
export interface AppConfig {
|
|
25
|
-
name: string;
|
|
26
|
-
version: string;
|
|
27
|
-
description?: string;
|
|
28
|
-
commands?: Map<string, CommandHandler>;
|
|
29
|
-
middleware?: Middleware[];
|
|
30
|
-
plugins?: Plugin[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Command handler
|
|
35
|
-
*/
|
|
36
|
-
export type CommandHandler = (options: CommandOptions) => Promise<void>;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Middleware interface
|
|
40
|
-
*/
|
|
41
|
-
export interface Middleware {
|
|
42
|
-
name: string;
|
|
43
|
-
before?: (options: CommandOptions) => Promise<void>;
|
|
44
|
-
after?: (result: unknown, options: CommandOptions) => Promise<void>;
|
|
45
|
-
onError?: (error: Error, options: CommandOptions) => Promise<void>;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Plugin interface
|
|
50
|
-
*/
|
|
51
|
-
export interface Plugin {
|
|
52
|
-
name: string;
|
|
53
|
-
version: string;
|
|
54
|
-
install(app: Application): Promise<void>;
|
|
55
|
-
uninstall?(app: Application): Promise<void>;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Base application implementation
|
|
60
|
-
*/
|
|
61
|
-
export class BaseApplication implements Application {
|
|
62
|
-
public readonly name: string;
|
|
63
|
-
public readonly version: string;
|
|
64
|
-
private running = false;
|
|
65
|
-
private commands = new Map<string, CommandHandler>();
|
|
66
|
-
private middleware: Middleware[] = [];
|
|
67
|
-
private plugins = new Set<Plugin>();
|
|
68
|
-
|
|
69
|
-
constructor(config: AppConfig) {
|
|
70
|
-
this.name = config.name;
|
|
71
|
-
this.version = config.version;
|
|
72
|
-
|
|
73
|
-
// Setup global error handling
|
|
74
|
-
setupGlobalErrorHandlers();
|
|
75
|
-
|
|
76
|
-
// Register commands
|
|
77
|
-
if (config.commands) {
|
|
78
|
-
for (const [name, handler] of config.commands) {
|
|
79
|
-
this.commands.set(name, handler);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Register middleware
|
|
84
|
-
if (config.middleware) {
|
|
85
|
-
this.middleware.push(...config.middleware);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Install plugins
|
|
89
|
-
if (config.plugins) {
|
|
90
|
-
for (const plugin of config.plugins) {
|
|
91
|
-
void this.installPlugin(plugin);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
logger.info('Application initialized', {
|
|
96
|
-
name: this.name,
|
|
97
|
-
version: this.version,
|
|
98
|
-
commands: this.commands.size,
|
|
99
|
-
middleware: this.middleware.length,
|
|
100
|
-
plugins: config.plugins?.length || 0,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async start(options?: CommandOptions): Promise<void> {
|
|
105
|
-
if (this.running) {
|
|
106
|
-
logger.warn('Application is already running');
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
logger.info('Starting application', { options });
|
|
111
|
-
|
|
112
|
-
try {
|
|
113
|
-
// Execute before middleware
|
|
114
|
-
for (const middleware of this.middleware) {
|
|
115
|
-
if (middleware.before && options) {
|
|
116
|
-
await middleware.before(options);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Execute command if specified
|
|
121
|
-
if (options?.command && this.commands.has(options.command)) {
|
|
122
|
-
const handler = this.commands.get(options.command)!;
|
|
123
|
-
await handler(options);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
this.running = true;
|
|
127
|
-
logger.info('Application started successfully');
|
|
128
|
-
|
|
129
|
-
} catch (error) {
|
|
130
|
-
// Execute error middleware
|
|
131
|
-
for (const middleware of this.middleware) {
|
|
132
|
-
if (middleware.onError && options) {
|
|
133
|
-
await middleware.onError(error instanceof Error ? error : new Error(String(error)), options);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
throw error;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
async stop(): Promise<void> {
|
|
141
|
-
if (!this.running) {
|
|
142
|
-
logger.warn('Application is not running');
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
logger.info('Stopping application');
|
|
147
|
-
|
|
148
|
-
// Uninstall plugins
|
|
149
|
-
for (const plugin of this.plugins) {
|
|
150
|
-
if (plugin.uninstall) {
|
|
151
|
-
await plugin.uninstall(this);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
this.running = false;
|
|
156
|
-
logger.info('Application stopped');
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
isRunning(): boolean {
|
|
160
|
-
return this.running;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
registerCommand(name: string, handler: CommandHandler): void {
|
|
164
|
-
this.commands.set(name, handler);
|
|
165
|
-
logger.debug('Command registered', { name });
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
unregisterCommand(name: string): boolean {
|
|
169
|
-
const result = this.commands.delete(name);
|
|
170
|
-
if (result) {
|
|
171
|
-
logger.debug('Command unregistered', { name });
|
|
172
|
-
}
|
|
173
|
-
return result;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
addMiddleware(middleware: Middleware): void {
|
|
177
|
-
this.middleware.push(middleware);
|
|
178
|
-
logger.debug('Middleware added', { name: middleware.name });
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
removeMiddleware(name: string): boolean {
|
|
182
|
-
const index = this.middleware.findIndex(m => m.name === name);
|
|
183
|
-
if (index > -1) {
|
|
184
|
-
this.middleware.splice(index, 1);
|
|
185
|
-
logger.debug('Middleware removed', { name });
|
|
186
|
-
return true;
|
|
187
|
-
}
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
async installPlugin(plugin: Plugin): Promise<void> {
|
|
192
|
-
if (this.plugins.has(plugin)) {
|
|
193
|
-
logger.warn('Plugin already installed', { name: plugin.name });
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
await plugin.install(this);
|
|
198
|
-
this.plugins.add(plugin);
|
|
199
|
-
logger.info('Plugin installed', { name: plugin.name, version: plugin.version });
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
async uninstallPlugin(plugin: Plugin): Promise<void> {
|
|
203
|
-
if (!this.plugins.has(plugin)) {
|
|
204
|
-
logger.warn('Plugin not installed', { name: plugin.name });
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (plugin.uninstall) {
|
|
209
|
-
await plugin.uninstall(this);
|
|
210
|
-
}
|
|
211
|
-
this.plugins.delete(plugin);
|
|
212
|
-
logger.info('Plugin uninstalled', { name: plugin.name });
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
getCommands(): string[] {
|
|
216
|
-
return Array.from(this.commands.keys());
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
getMiddleware(): string[] {
|
|
220
|
-
return this.middleware.map(m => m.name);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
getPlugins(): Array<{ name: string; version: string }> {
|
|
224
|
-
return Array.from(this.plugins).map(p => ({ name: p.name, version: p.version }));
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Built-in middleware - moved before factory to fix hoisting
|
|
230
|
-
*/
|
|
231
|
-
|
|
232
|
-
const loggingMiddleware: Middleware = {
|
|
233
|
-
name: 'logging',
|
|
234
|
-
before: async (options: CommandOptions) => {
|
|
235
|
-
logger.debug('Executing command', { command: options.command, options });
|
|
236
|
-
},
|
|
237
|
-
after: async (result, options: CommandOptions) => {
|
|
238
|
-
logger.debug('Command completed', { command: options.command, result });
|
|
239
|
-
},
|
|
240
|
-
onError: async (error, options: CommandOptions) => {
|
|
241
|
-
logger.error('Command failed', { command: options.command, error: error.message });
|
|
242
|
-
},
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
const validationMiddleware: Middleware = {
|
|
246
|
-
name: 'validation',
|
|
247
|
-
before: async (options: CommandOptions) => {
|
|
248
|
-
// Basic validation
|
|
249
|
-
if (options.command && typeof options.command !== 'string') {
|
|
250
|
-
throw new Error('Command must be a string');
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (options.concurrency && (typeof options.concurrency !== 'number' || options.concurrency < 1)) {
|
|
254
|
-
throw new Error('Concurrency must be a positive number');
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (options.delay && (typeof options.delay !== 'number' || options.delay < 0)) {
|
|
258
|
-
throw new Error('Delay must be a non-negative number');
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
const corsMiddleware: Middleware = {
|
|
264
|
-
name: 'cors',
|
|
265
|
-
before: async (options: CommandOptions) => {
|
|
266
|
-
// CORS headers would be set here for web applications
|
|
267
|
-
logger.debug('CORS middleware applied');
|
|
268
|
-
},
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Application factory
|
|
273
|
-
*/
|
|
274
|
-
export class ApplicationFactory {
|
|
275
|
-
private static defaultConfig: Partial<AppConfig> = {
|
|
276
|
-
middleware: [
|
|
277
|
-
loggingMiddleware,
|
|
278
|
-
validationMiddleware,
|
|
279
|
-
],
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
static create(config: AppConfig): Application {
|
|
283
|
-
const finalConfig = {
|
|
284
|
-
...this.defaultConfig,
|
|
285
|
-
...config,
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
return new BaseApplication(finalConfig);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
static createCLIApp(config: Omit<AppConfig, 'name' | 'version'> & {
|
|
292
|
-
name: string;
|
|
293
|
-
version: string;
|
|
294
|
-
}): Application {
|
|
295
|
-
return this.create({
|
|
296
|
-
...config,
|
|
297
|
-
commands: config.commands || new Map(),
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
static createWebApp(config: Omit<AppConfig, 'name' | 'version'> & {
|
|
302
|
-
name: string;
|
|
303
|
-
version: string;
|
|
304
|
-
}): Application {
|
|
305
|
-
return this.create({
|
|
306
|
-
...config,
|
|
307
|
-
middleware: [
|
|
308
|
-
loggingMiddleware,
|
|
309
|
-
validationMiddleware,
|
|
310
|
-
corsMiddleware,
|
|
311
|
-
],
|
|
312
|
-
...config,
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Common plugins
|
|
319
|
-
*/
|
|
320
|
-
|
|
321
|
-
export const LoggingPlugin: Plugin = {
|
|
322
|
-
name: 'logging',
|
|
323
|
-
version: '1.0.0',
|
|
324
|
-
async install(app: Application): Promise<void> {
|
|
325
|
-
logger.info('Logging plugin installed');
|
|
326
|
-
// Additional logging setup could go here
|
|
327
|
-
},
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
export const StoragePlugin: Plugin = {
|
|
331
|
-
name: 'storage',
|
|
332
|
-
version: '1.0.0',
|
|
333
|
-
async install(app: Application): Promise<void> {
|
|
334
|
-
// Initialize storage systems
|
|
335
|
-
logger.info('Storage plugin installed');
|
|
336
|
-
},
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
export const CachePlugin: Plugin = {
|
|
340
|
-
name: 'cache',
|
|
341
|
-
version: '1.0.0',
|
|
342
|
-
async install(app: Application): Promise<void> {
|
|
343
|
-
// Initialize cache systems
|
|
344
|
-
logger.info('Cache plugin installed');
|
|
345
|
-
},
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Utility functions
|
|
350
|
-
*/
|
|
351
|
-
|
|
352
|
-
export const CommandUtils = {
|
|
353
|
-
registerCommands(app: Application, commands: Record<string, CommandHandler>): void {
|
|
354
|
-
for (const [name, handler] of Object.entries(commands)) {
|
|
355
|
-
app.registerCommand(name, handler);
|
|
356
|
-
}
|
|
357
|
-
},
|
|
358
|
-
|
|
359
|
-
createCommandHandler(
|
|
360
|
-
handler: (options: CommandOptions) => Promise<void>,
|
|
361
|
-
options?: {
|
|
362
|
-
name?: string;
|
|
363
|
-
description?: string;
|
|
364
|
-
validate?: (options: CommandOptions) => boolean;
|
|
365
|
-
transform?: (options: CommandOptions) => CommandOptions;
|
|
366
|
-
}
|
|
367
|
-
): CommandHandler {
|
|
368
|
-
return async (opts: CommandOptions): Promise<void> => {
|
|
369
|
-
// Validate
|
|
370
|
-
if (options?.validate && !options.validate(opts)) {
|
|
371
|
-
throw new Error(`Validation failed for command: ${options.name || 'unknown'}`);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// Transform
|
|
375
|
-
const finalOpts = options?.transform ? options.transform(opts) : opts;
|
|
376
|
-
|
|
377
|
-
// Execute
|
|
378
|
-
await handler(finalOpts);
|
|
379
|
-
};
|
|
380
|
-
},
|
|
381
|
-
} as const;
|