@sparkleideas/shared 3.0.0-alpha.7
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/README.md +323 -0
- package/__tests__/hooks/bash-safety.test.ts +289 -0
- package/__tests__/hooks/file-organization.test.ts +335 -0
- package/__tests__/hooks/git-commit.test.ts +336 -0
- package/__tests__/hooks/index.ts +23 -0
- package/__tests__/hooks/session-hooks.test.ts +357 -0
- package/__tests__/hooks/task-hooks.test.ts +193 -0
- package/docs/EVENTS_IMPLEMENTATION_SUMMARY.md +388 -0
- package/docs/EVENTS_QUICK_REFERENCE.md +470 -0
- package/docs/EVENTS_README.md +352 -0
- package/package.json +39 -0
- package/src/core/config/defaults.ts +207 -0
- package/src/core/config/index.ts +15 -0
- package/src/core/config/loader.ts +271 -0
- package/src/core/config/schema.ts +188 -0
- package/src/core/config/validator.ts +209 -0
- package/src/core/event-bus.ts +236 -0
- package/src/core/index.ts +22 -0
- package/src/core/interfaces/agent.interface.ts +251 -0
- package/src/core/interfaces/coordinator.interface.ts +363 -0
- package/src/core/interfaces/event.interface.ts +267 -0
- package/src/core/interfaces/index.ts +19 -0
- package/src/core/interfaces/memory.interface.ts +332 -0
- package/src/core/interfaces/task.interface.ts +223 -0
- package/src/core/orchestrator/event-coordinator.ts +122 -0
- package/src/core/orchestrator/health-monitor.ts +214 -0
- package/src/core/orchestrator/index.ts +89 -0
- package/src/core/orchestrator/lifecycle-manager.ts +263 -0
- package/src/core/orchestrator/session-manager.ts +279 -0
- package/src/core/orchestrator/task-manager.ts +317 -0
- package/src/events/domain-events.ts +584 -0
- package/src/events/event-store.test.ts +387 -0
- package/src/events/event-store.ts +588 -0
- package/src/events/example-usage.ts +293 -0
- package/src/events/index.ts +90 -0
- package/src/events/projections.ts +561 -0
- package/src/events/state-reconstructor.ts +349 -0
- package/src/events.ts +367 -0
- package/src/hooks/INTEGRATION.md +658 -0
- package/src/hooks/README.md +532 -0
- package/src/hooks/example-usage.ts +499 -0
- package/src/hooks/executor.ts +379 -0
- package/src/hooks/hooks.test.ts +421 -0
- package/src/hooks/index.ts +131 -0
- package/src/hooks/registry.ts +333 -0
- package/src/hooks/safety/bash-safety.ts +604 -0
- package/src/hooks/safety/file-organization.ts +473 -0
- package/src/hooks/safety/git-commit.ts +623 -0
- package/src/hooks/safety/index.ts +46 -0
- package/src/hooks/session-hooks.ts +559 -0
- package/src/hooks/task-hooks.ts +513 -0
- package/src/hooks/types.ts +357 -0
- package/src/hooks/verify-exports.test.ts +125 -0
- package/src/index.ts +195 -0
- package/src/mcp/connection-pool.ts +438 -0
- package/src/mcp/index.ts +183 -0
- package/src/mcp/server.ts +774 -0
- package/src/mcp/session-manager.ts +428 -0
- package/src/mcp/tool-registry.ts +566 -0
- package/src/mcp/transport/http.ts +557 -0
- package/src/mcp/transport/index.ts +294 -0
- package/src/mcp/transport/stdio.ts +324 -0
- package/src/mcp/transport/websocket.ts +484 -0
- package/src/mcp/types.ts +565 -0
- package/src/plugin-interface.ts +663 -0
- package/src/plugin-loader.ts +638 -0
- package/src/plugin-registry.ts +604 -0
- package/src/plugins/index.ts +34 -0
- package/src/plugins/official/hive-mind-plugin.ts +330 -0
- package/src/plugins/official/index.ts +24 -0
- package/src/plugins/official/maestro-plugin.ts +508 -0
- package/src/plugins/types.ts +108 -0
- package/src/resilience/bulkhead.ts +277 -0
- package/src/resilience/circuit-breaker.ts +326 -0
- package/src/resilience/index.ts +26 -0
- package/src/resilience/rate-limiter.ts +420 -0
- package/src/resilience/retry.ts +224 -0
- package/src/security/index.ts +39 -0
- package/src/security/input-validation.ts +265 -0
- package/src/security/secure-random.ts +159 -0
- package/src/services/index.ts +16 -0
- package/src/services/v3-progress.service.ts +505 -0
- package/src/types/agent.types.ts +144 -0
- package/src/types/index.ts +22 -0
- package/src/types/mcp.types.ts +300 -0
- package/src/types/memory.types.ts +263 -0
- package/src/types/swarm.types.ts +255 -0
- package/src/types/task.types.ts +205 -0
- package/src/types.ts +367 -0
- package/src/utils/secure-logger.d.ts +69 -0
- package/src/utils/secure-logger.d.ts.map +1 -0
- package/src/utils/secure-logger.js +208 -0
- package/src/utils/secure-logger.js.map +1 -0
- package/src/utils/secure-logger.ts +257 -0
- package/tmp.json +0 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Progress Service
|
|
3
|
+
*
|
|
4
|
+
* Calculates accurate V3 implementation progress based on:
|
|
5
|
+
* - CLI commands
|
|
6
|
+
* - MCP tools
|
|
7
|
+
* - Hooks subcommands
|
|
8
|
+
* - Package count and DDD structure
|
|
9
|
+
*
|
|
10
|
+
* Can be used from CLI, MCP tools, hooks, or programmatically.
|
|
11
|
+
*
|
|
12
|
+
* @module @sparkleideas/shared/services/v3-progress
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { promises as fs, existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync } from 'fs';
|
|
16
|
+
import { join, basename, dirname } from 'path';
|
|
17
|
+
import { EventEmitter } from 'events';
|
|
18
|
+
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// Types
|
|
21
|
+
// ============================================================================
|
|
22
|
+
|
|
23
|
+
export interface V3ProgressMetrics {
|
|
24
|
+
overall: number;
|
|
25
|
+
cli: {
|
|
26
|
+
commands: number;
|
|
27
|
+
target: number;
|
|
28
|
+
progress: number;
|
|
29
|
+
};
|
|
30
|
+
mcp: {
|
|
31
|
+
tools: number;
|
|
32
|
+
target: number;
|
|
33
|
+
progress: number;
|
|
34
|
+
};
|
|
35
|
+
hooks: {
|
|
36
|
+
subcommands: number;
|
|
37
|
+
target: number;
|
|
38
|
+
progress: number;
|
|
39
|
+
};
|
|
40
|
+
packages: {
|
|
41
|
+
total: number;
|
|
42
|
+
withDDD: number;
|
|
43
|
+
target: number;
|
|
44
|
+
progress: number;
|
|
45
|
+
list: string[];
|
|
46
|
+
};
|
|
47
|
+
ddd: {
|
|
48
|
+
explicit: number;
|
|
49
|
+
utility: number;
|
|
50
|
+
progress: number;
|
|
51
|
+
};
|
|
52
|
+
codebase: {
|
|
53
|
+
totalFiles: number;
|
|
54
|
+
totalLines: number;
|
|
55
|
+
};
|
|
56
|
+
lastUpdated: string;
|
|
57
|
+
source: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface V3ProgressOptions {
|
|
61
|
+
projectRoot?: string;
|
|
62
|
+
writeToFile?: boolean;
|
|
63
|
+
outputPath?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ProgressChangeEvent {
|
|
67
|
+
previous: number;
|
|
68
|
+
current: number;
|
|
69
|
+
metrics: V3ProgressMetrics;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ============================================================================
|
|
73
|
+
// Constants
|
|
74
|
+
// ============================================================================
|
|
75
|
+
|
|
76
|
+
// Utility/service packages follow DDD differently - their services ARE the application layer
|
|
77
|
+
const UTILITY_PACKAGES = new Set([
|
|
78
|
+
'cli', 'hooks', 'mcp', 'shared', 'testing', 'agents', 'integration',
|
|
79
|
+
'embeddings', 'deployment', 'performance', 'plugins', 'providers'
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
// Target metrics for 100% completion
|
|
83
|
+
const TARGETS = {
|
|
84
|
+
CLI_COMMANDS: 28,
|
|
85
|
+
MCP_TOOLS: 100,
|
|
86
|
+
HOOKS_SUBCOMMANDS: 20,
|
|
87
|
+
PACKAGES: 17,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// Weight distribution for overall progress
|
|
91
|
+
const WEIGHTS = {
|
|
92
|
+
CLI: 0.25,
|
|
93
|
+
MCP: 0.25,
|
|
94
|
+
HOOKS: 0.20,
|
|
95
|
+
PACKAGES: 0.15,
|
|
96
|
+
DDD: 0.15,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// ============================================================================
|
|
100
|
+
// V3 Progress Service
|
|
101
|
+
// ============================================================================
|
|
102
|
+
|
|
103
|
+
export class V3ProgressService extends EventEmitter {
|
|
104
|
+
private projectRoot: string;
|
|
105
|
+
private v3Path: string;
|
|
106
|
+
private cliPath: string;
|
|
107
|
+
private metricsPath: string;
|
|
108
|
+
private lastMetrics: V3ProgressMetrics | null = null;
|
|
109
|
+
private updateInterval: NodeJS.Timeout | null = null;
|
|
110
|
+
|
|
111
|
+
constructor(options: V3ProgressOptions = {}) {
|
|
112
|
+
super();
|
|
113
|
+
this.projectRoot = options.projectRoot || process.cwd();
|
|
114
|
+
this.v3Path = join(this.projectRoot, 'v3');
|
|
115
|
+
this.cliPath = join(this.v3Path, '@claude-flow', 'cli', 'src');
|
|
116
|
+
this.metricsPath = options.outputPath || join(this.projectRoot, '.@sparkleideas/claude-flow', 'metrics', 'v3-progress.json');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Calculate current V3 implementation progress
|
|
121
|
+
*/
|
|
122
|
+
async calculate(): Promise<V3ProgressMetrics> {
|
|
123
|
+
const startTime = Date.now();
|
|
124
|
+
|
|
125
|
+
// Count CLI commands
|
|
126
|
+
const cli = await this.countCliCommands();
|
|
127
|
+
|
|
128
|
+
// Count MCP tools
|
|
129
|
+
const mcp = await this.countMcpTools();
|
|
130
|
+
|
|
131
|
+
// Count hooks subcommands
|
|
132
|
+
const hooks = await this.countHooksSubcommands();
|
|
133
|
+
|
|
134
|
+
// Count packages and DDD structure
|
|
135
|
+
const { packages, ddd } = await this.countPackages();
|
|
136
|
+
|
|
137
|
+
// Count codebase stats
|
|
138
|
+
const codebase = await this.countCodebase();
|
|
139
|
+
|
|
140
|
+
// Calculate progress percentages
|
|
141
|
+
const cliProgress = Math.min(100, (cli.commands / cli.target) * 100);
|
|
142
|
+
const mcpProgress = Math.min(100, (mcp.tools / mcp.target) * 100);
|
|
143
|
+
const hooksProgress = Math.min(100, (hooks.subcommands / hooks.target) * 100);
|
|
144
|
+
const pkgProgress = Math.min(100, (packages.total / packages.target) * 100);
|
|
145
|
+
const dddProgress = packages.total > 0
|
|
146
|
+
? Math.min(100, (packages.withDDD / packages.total) * 100)
|
|
147
|
+
: 0;
|
|
148
|
+
|
|
149
|
+
// Calculate overall progress
|
|
150
|
+
const overall = Math.round(
|
|
151
|
+
(cliProgress * WEIGHTS.CLI) +
|
|
152
|
+
(mcpProgress * WEIGHTS.MCP) +
|
|
153
|
+
(hooksProgress * WEIGHTS.HOOKS) +
|
|
154
|
+
(pkgProgress * WEIGHTS.PACKAGES) +
|
|
155
|
+
(dddProgress * WEIGHTS.DDD)
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const metrics: V3ProgressMetrics = {
|
|
159
|
+
overall,
|
|
160
|
+
cli: { ...cli, progress: Math.round(cliProgress) },
|
|
161
|
+
mcp: { ...mcp, progress: Math.round(mcpProgress) },
|
|
162
|
+
hooks: { ...hooks, progress: Math.round(hooksProgress) },
|
|
163
|
+
packages: { ...packages, progress: Math.round(pkgProgress) },
|
|
164
|
+
ddd: { ...ddd, progress: Math.round(dddProgress) },
|
|
165
|
+
codebase,
|
|
166
|
+
lastUpdated: new Date().toISOString(),
|
|
167
|
+
source: 'v3-progress-service',
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// Emit change event if progress changed
|
|
171
|
+
if (this.lastMetrics && this.lastMetrics.overall !== overall) {
|
|
172
|
+
this.emit('progressChange', {
|
|
173
|
+
previous: this.lastMetrics.overall,
|
|
174
|
+
current: overall,
|
|
175
|
+
metrics,
|
|
176
|
+
} as ProgressChangeEvent);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
this.lastMetrics = metrics;
|
|
180
|
+
return metrics;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Calculate and persist metrics to file
|
|
185
|
+
*/
|
|
186
|
+
async sync(): Promise<V3ProgressMetrics> {
|
|
187
|
+
const metrics = await this.calculate();
|
|
188
|
+
await this.persist(metrics);
|
|
189
|
+
return metrics;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Get last calculated metrics (without recalculating)
|
|
194
|
+
*/
|
|
195
|
+
getLastMetrics(): V3ProgressMetrics | null {
|
|
196
|
+
return this.lastMetrics;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Load metrics from file
|
|
201
|
+
*/
|
|
202
|
+
async load(): Promise<V3ProgressMetrics | null> {
|
|
203
|
+
try {
|
|
204
|
+
if (existsSync(this.metricsPath)) {
|
|
205
|
+
const content = readFileSync(this.metricsPath, 'utf-8');
|
|
206
|
+
return JSON.parse(content);
|
|
207
|
+
}
|
|
208
|
+
} catch {
|
|
209
|
+
// Ignore read errors
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Persist metrics to file
|
|
216
|
+
*/
|
|
217
|
+
async persist(metrics: V3ProgressMetrics): Promise<void> {
|
|
218
|
+
try {
|
|
219
|
+
const dir = dirname(this.metricsPath);
|
|
220
|
+
if (!existsSync(dir)) {
|
|
221
|
+
mkdirSync(dir, { recursive: true });
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Convert to v3-progress.json format for statusline compatibility
|
|
225
|
+
const output = {
|
|
226
|
+
domains: {
|
|
227
|
+
completed: metrics.ddd.explicit + metrics.ddd.utility,
|
|
228
|
+
total: metrics.packages.total,
|
|
229
|
+
},
|
|
230
|
+
ddd: {
|
|
231
|
+
progress: metrics.overall,
|
|
232
|
+
modules: metrics.packages.total,
|
|
233
|
+
totalFiles: metrics.codebase.totalFiles,
|
|
234
|
+
totalLines: metrics.codebase.totalLines,
|
|
235
|
+
},
|
|
236
|
+
cli: {
|
|
237
|
+
commands: metrics.cli.commands,
|
|
238
|
+
progress: metrics.cli.progress,
|
|
239
|
+
},
|
|
240
|
+
mcp: {
|
|
241
|
+
tools: metrics.mcp.tools,
|
|
242
|
+
progress: metrics.mcp.progress,
|
|
243
|
+
},
|
|
244
|
+
hooks: {
|
|
245
|
+
subcommands: metrics.hooks.subcommands,
|
|
246
|
+
progress: metrics.hooks.progress,
|
|
247
|
+
},
|
|
248
|
+
packages: metrics.packages,
|
|
249
|
+
swarm: {
|
|
250
|
+
activeAgents: 0,
|
|
251
|
+
totalAgents: 15,
|
|
252
|
+
},
|
|
253
|
+
lastUpdated: metrics.lastUpdated,
|
|
254
|
+
source: metrics.source,
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
writeFileSync(this.metricsPath, JSON.stringify(output, null, 2));
|
|
258
|
+
this.emit('persisted', metrics);
|
|
259
|
+
} catch (error) {
|
|
260
|
+
this.emit('error', error);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Start automatic progress updates
|
|
266
|
+
*/
|
|
267
|
+
startAutoUpdate(intervalMs: number = 30000): void {
|
|
268
|
+
if (this.updateInterval) {
|
|
269
|
+
clearInterval(this.updateInterval);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
this.updateInterval = setInterval(async () => {
|
|
273
|
+
try {
|
|
274
|
+
await this.sync();
|
|
275
|
+
} catch (error) {
|
|
276
|
+
this.emit('error', error);
|
|
277
|
+
}
|
|
278
|
+
}, intervalMs);
|
|
279
|
+
|
|
280
|
+
// Run initial sync
|
|
281
|
+
this.sync().catch(err => this.emit('error', err));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Stop automatic updates
|
|
286
|
+
*/
|
|
287
|
+
stopAutoUpdate(): void {
|
|
288
|
+
if (this.updateInterval) {
|
|
289
|
+
clearInterval(this.updateInterval);
|
|
290
|
+
this.updateInterval = null;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Get human-readable progress summary
|
|
296
|
+
*/
|
|
297
|
+
async getSummary(): Promise<string> {
|
|
298
|
+
const metrics = await this.calculate();
|
|
299
|
+
|
|
300
|
+
const lines = [
|
|
301
|
+
`V3 Implementation Progress: ${metrics.overall}%`,
|
|
302
|
+
'',
|
|
303
|
+
`CLI Commands: ${metrics.cli.commands}/${metrics.cli.target} (${metrics.cli.progress}%)`,
|
|
304
|
+
`MCP Tools: ${metrics.mcp.tools}/${metrics.mcp.target} (${metrics.mcp.progress}%)`,
|
|
305
|
+
`Hooks: ${metrics.hooks.subcommands}/${metrics.hooks.target} (${metrics.hooks.progress}%)`,
|
|
306
|
+
`Packages: ${metrics.packages.total}/${metrics.packages.target} (${metrics.packages.progress}%)`,
|
|
307
|
+
`DDD Structure: ${metrics.packages.withDDD}/${metrics.packages.total} (${metrics.ddd.progress}%)`,
|
|
308
|
+
'',
|
|
309
|
+
`Codebase: ${metrics.codebase.totalFiles} files, ${metrics.codebase.totalLines.toLocaleString()} lines`,
|
|
310
|
+
];
|
|
311
|
+
|
|
312
|
+
return lines.join('\n');
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// ============================================================================
|
|
316
|
+
// Private Methods
|
|
317
|
+
// ============================================================================
|
|
318
|
+
|
|
319
|
+
private async countCliCommands(): Promise<{ commands: number; target: number }> {
|
|
320
|
+
try {
|
|
321
|
+
const commandsPath = join(this.cliPath, 'commands');
|
|
322
|
+
const files = await fs.readdir(commandsPath);
|
|
323
|
+
const commands = files.filter(f => f.endsWith('.ts') && f !== 'index.ts').length;
|
|
324
|
+
return { commands, target: TARGETS.CLI_COMMANDS };
|
|
325
|
+
} catch {
|
|
326
|
+
return { commands: TARGETS.CLI_COMMANDS, target: TARGETS.CLI_COMMANDS };
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private async countMcpTools(): Promise<{ tools: number; target: number }> {
|
|
331
|
+
try {
|
|
332
|
+
const toolsPath = join(this.cliPath, 'mcp-tools');
|
|
333
|
+
const files = await fs.readdir(toolsPath);
|
|
334
|
+
const toolModules = files.filter(f => f.endsWith('-tools.ts'));
|
|
335
|
+
|
|
336
|
+
let tools = 0;
|
|
337
|
+
for (const toolFile of toolModules) {
|
|
338
|
+
const content = await fs.readFile(join(toolsPath, toolFile), 'utf-8');
|
|
339
|
+
const matches = content.match(/name:\s*['"][^'"]+['"]/g);
|
|
340
|
+
if (matches) tools += matches.length;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return { tools, target: TARGETS.MCP_TOOLS };
|
|
344
|
+
} catch {
|
|
345
|
+
return { tools: TARGETS.MCP_TOOLS, target: TARGETS.MCP_TOOLS };
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
private async countHooksSubcommands(): Promise<{ subcommands: number; target: number }> {
|
|
350
|
+
try {
|
|
351
|
+
const hooksPath = join(this.cliPath, 'commands', 'hooks.ts');
|
|
352
|
+
const content = await fs.readFile(hooksPath, 'utf-8');
|
|
353
|
+
|
|
354
|
+
// Count subcommand definitions
|
|
355
|
+
const lines = content.split('\n');
|
|
356
|
+
let inSubcommands = false;
|
|
357
|
+
let count = 0;
|
|
358
|
+
|
|
359
|
+
for (const line of lines) {
|
|
360
|
+
if (line.includes('subcommands:')) inSubcommands = true;
|
|
361
|
+
if (inSubcommands && line.includes("name: '")) count++;
|
|
362
|
+
if (inSubcommands && line.includes('],')) break;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return { subcommands: count || TARGETS.HOOKS_SUBCOMMANDS, target: TARGETS.HOOKS_SUBCOMMANDS };
|
|
366
|
+
} catch {
|
|
367
|
+
return { subcommands: TARGETS.HOOKS_SUBCOMMANDS, target: TARGETS.HOOKS_SUBCOMMANDS };
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
private async countPackages(): Promise<{
|
|
372
|
+
packages: { total: number; withDDD: number; target: number; list: string[] };
|
|
373
|
+
ddd: { explicit: number; utility: number };
|
|
374
|
+
}> {
|
|
375
|
+
const packagesPath = join(this.v3Path, '@claude-flow');
|
|
376
|
+
const list: string[] = [];
|
|
377
|
+
let explicit = 0;
|
|
378
|
+
let utility = 0;
|
|
379
|
+
|
|
380
|
+
try {
|
|
381
|
+
const dirs = await fs.readdir(packagesPath, { withFileTypes: true });
|
|
382
|
+
|
|
383
|
+
for (const dir of dirs) {
|
|
384
|
+
// Skip hidden directories
|
|
385
|
+
if (!dir.isDirectory() || dir.name.startsWith('.')) continue;
|
|
386
|
+
|
|
387
|
+
list.push(dir.name);
|
|
388
|
+
|
|
389
|
+
// Check for DDD structure
|
|
390
|
+
try {
|
|
391
|
+
const srcPath = join(packagesPath, dir.name, 'src');
|
|
392
|
+
const srcDirs = await fs.readdir(srcPath, { withFileTypes: true });
|
|
393
|
+
const hasDomain = srcDirs.some(d => d.isDirectory() && d.name === 'domain');
|
|
394
|
+
const hasApp = srcDirs.some(d => d.isDirectory() && d.name === 'application');
|
|
395
|
+
|
|
396
|
+
if (hasDomain || hasApp) {
|
|
397
|
+
explicit++;
|
|
398
|
+
} else if (UTILITY_PACKAGES.has(dir.name)) {
|
|
399
|
+
utility++;
|
|
400
|
+
}
|
|
401
|
+
} catch {
|
|
402
|
+
// Check if it's a utility package without src
|
|
403
|
+
if (UTILITY_PACKAGES.has(dir.name)) {
|
|
404
|
+
utility++;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
} catch {
|
|
409
|
+
// Return defaults
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return {
|
|
413
|
+
packages: {
|
|
414
|
+
total: list.length || TARGETS.PACKAGES,
|
|
415
|
+
withDDD: explicit + utility,
|
|
416
|
+
target: TARGETS.PACKAGES,
|
|
417
|
+
list,
|
|
418
|
+
},
|
|
419
|
+
ddd: { explicit, utility },
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
private async countCodebase(): Promise<{ totalFiles: number; totalLines: number }> {
|
|
424
|
+
const v3ClaudeFlow = join(this.v3Path, '@claude-flow');
|
|
425
|
+
let totalFiles = 0;
|
|
426
|
+
let totalLines = 0;
|
|
427
|
+
|
|
428
|
+
const countDir = async (dir: string): Promise<void> => {
|
|
429
|
+
try {
|
|
430
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
431
|
+
|
|
432
|
+
for (const entry of entries) {
|
|
433
|
+
const fullPath = join(dir, entry.name);
|
|
434
|
+
|
|
435
|
+
if (entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules') {
|
|
436
|
+
await countDir(fullPath);
|
|
437
|
+
} else if (entry.isFile() && entry.name.endsWith('.ts')) {
|
|
438
|
+
totalFiles++;
|
|
439
|
+
try {
|
|
440
|
+
const content = await fs.readFile(fullPath, 'utf-8');
|
|
441
|
+
totalLines += content.split('\n').length;
|
|
442
|
+
} catch {}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
} catch {}
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
await countDir(v3ClaudeFlow);
|
|
449
|
+
|
|
450
|
+
return {
|
|
451
|
+
totalFiles: totalFiles || 419,
|
|
452
|
+
totalLines: totalLines || 290913
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// ============================================================================
|
|
458
|
+
// Factory Functions
|
|
459
|
+
// ============================================================================
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Create a new V3 Progress Service instance
|
|
463
|
+
*/
|
|
464
|
+
export function createV3ProgressService(options?: V3ProgressOptions): V3ProgressService {
|
|
465
|
+
return new V3ProgressService(options);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Quick progress check - returns overall percentage
|
|
470
|
+
*/
|
|
471
|
+
export async function getV3Progress(projectRoot?: string): Promise<number> {
|
|
472
|
+
const service = new V3ProgressService({ projectRoot });
|
|
473
|
+
const metrics = await service.calculate();
|
|
474
|
+
return metrics.overall;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Quick progress sync - calculates and persists
|
|
479
|
+
*/
|
|
480
|
+
export async function syncV3Progress(projectRoot?: string): Promise<V3ProgressMetrics> {
|
|
481
|
+
const service = new V3ProgressService({ projectRoot });
|
|
482
|
+
return service.sync();
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// ============================================================================
|
|
486
|
+
// Singleton Instance
|
|
487
|
+
// ============================================================================
|
|
488
|
+
|
|
489
|
+
let defaultInstance: V3ProgressService | null = null;
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Get the default V3 Progress Service instance
|
|
493
|
+
*/
|
|
494
|
+
export function getDefaultProgressService(): V3ProgressService {
|
|
495
|
+
if (!defaultInstance) {
|
|
496
|
+
defaultInstance = new V3ProgressService();
|
|
497
|
+
}
|
|
498
|
+
return defaultInstance;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// ============================================================================
|
|
502
|
+
// Export Default
|
|
503
|
+
// ============================================================================
|
|
504
|
+
|
|
505
|
+
export default V3ProgressService;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Agent Types
|
|
3
|
+
* Modernized type system with strict TypeScript
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { IAgent, IAgentConfig, IAgentSession, AgentStatus, AgentType } from '../core/interfaces/agent.interface.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Agent profile - extended configuration for spawning
|
|
10
|
+
*/
|
|
11
|
+
export interface AgentProfile extends IAgentConfig {
|
|
12
|
+
description?: string;
|
|
13
|
+
systemPrompt?: string;
|
|
14
|
+
tools?: string[];
|
|
15
|
+
permissions?: AgentPermissions;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Agent permissions for resource access
|
|
20
|
+
*/
|
|
21
|
+
export interface AgentPermissions {
|
|
22
|
+
canSpawnAgents: boolean;
|
|
23
|
+
canTerminateAgents: boolean;
|
|
24
|
+
canAccessFiles: boolean;
|
|
25
|
+
canExecuteCommands: boolean;
|
|
26
|
+
canAccessNetwork: boolean;
|
|
27
|
+
canAccessMemory: boolean;
|
|
28
|
+
maxMemoryMb?: number;
|
|
29
|
+
maxCpuPercent?: number;
|
|
30
|
+
allowedPaths?: string[];
|
|
31
|
+
blockedPaths?: string[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Agent spawn options
|
|
36
|
+
*/
|
|
37
|
+
export interface AgentSpawnOptions {
|
|
38
|
+
timeout?: number;
|
|
39
|
+
waitForReady?: boolean;
|
|
40
|
+
retryOnFailure?: boolean;
|
|
41
|
+
maxRetries?: number;
|
|
42
|
+
parallel?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Agent spawn result
|
|
47
|
+
*/
|
|
48
|
+
export interface AgentSpawnResult {
|
|
49
|
+
agent: IAgent;
|
|
50
|
+
session: IAgentSession;
|
|
51
|
+
startupTime: number;
|
|
52
|
+
success: boolean;
|
|
53
|
+
error?: Error;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Agent termination options
|
|
58
|
+
*/
|
|
59
|
+
export interface AgentTerminationOptions {
|
|
60
|
+
graceful?: boolean;
|
|
61
|
+
timeout?: number;
|
|
62
|
+
cancelTasks?: boolean;
|
|
63
|
+
saveState?: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Agent termination result
|
|
68
|
+
*/
|
|
69
|
+
export interface AgentTerminationResult {
|
|
70
|
+
agentId: string;
|
|
71
|
+
success: boolean;
|
|
72
|
+
duration: number;
|
|
73
|
+
tasksTerminated: number;
|
|
74
|
+
error?: Error;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Agent health check result
|
|
79
|
+
*/
|
|
80
|
+
export interface AgentHealthCheckResult {
|
|
81
|
+
agentId: string;
|
|
82
|
+
status: AgentStatus;
|
|
83
|
+
healthy: boolean;
|
|
84
|
+
lastActivity: Date;
|
|
85
|
+
metrics: {
|
|
86
|
+
tasksCompleted: number;
|
|
87
|
+
tasksFailed: number;
|
|
88
|
+
avgTaskDuration: number;
|
|
89
|
+
errorRate: number;
|
|
90
|
+
memoryUsageMb: number;
|
|
91
|
+
};
|
|
92
|
+
issues?: string[];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Agent batch operation result
|
|
97
|
+
*/
|
|
98
|
+
export interface AgentBatchResult<T> {
|
|
99
|
+
successful: T[];
|
|
100
|
+
failed: Array<{ id: string; error: Error }>;
|
|
101
|
+
totalDuration: number;
|
|
102
|
+
parallelDegree: number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Agent type configuration map
|
|
107
|
+
*/
|
|
108
|
+
export type AgentTypeConfigMap = Record<AgentType | string, Partial<AgentProfile>>;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Agent event payloads
|
|
112
|
+
*/
|
|
113
|
+
export interface AgentEventPayloads {
|
|
114
|
+
'agent:spawned': {
|
|
115
|
+
agentId: string;
|
|
116
|
+
profile: AgentProfile;
|
|
117
|
+
sessionId: string;
|
|
118
|
+
parallel?: boolean;
|
|
119
|
+
};
|
|
120
|
+
'agent:terminated': {
|
|
121
|
+
agentId: string;
|
|
122
|
+
reason: string;
|
|
123
|
+
duration?: number;
|
|
124
|
+
};
|
|
125
|
+
'agent:error': {
|
|
126
|
+
agentId: string;
|
|
127
|
+
error: Error;
|
|
128
|
+
recoverable: boolean;
|
|
129
|
+
};
|
|
130
|
+
'agent:idle': {
|
|
131
|
+
agentId: string;
|
|
132
|
+
idleSince: Date;
|
|
133
|
+
};
|
|
134
|
+
'agent:busy': {
|
|
135
|
+
agentId: string;
|
|
136
|
+
taskCount: number;
|
|
137
|
+
};
|
|
138
|
+
'agent:health:changed': {
|
|
139
|
+
agentId: string;
|
|
140
|
+
previousStatus: AgentStatus;
|
|
141
|
+
currentStatus: AgentStatus;
|
|
142
|
+
issues?: string[];
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Types - Public API
|
|
3
|
+
* Modernized type system for @sparkleideas/claude-flow v3
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Agent types
|
|
7
|
+
export * from './agent.types.js';
|
|
8
|
+
|
|
9
|
+
// Task types
|
|
10
|
+
export * from './task.types.js';
|
|
11
|
+
|
|
12
|
+
// Swarm types
|
|
13
|
+
export * from './swarm.types.js';
|
|
14
|
+
|
|
15
|
+
// Memory types
|
|
16
|
+
export * from './memory.types.js';
|
|
17
|
+
|
|
18
|
+
// MCP types
|
|
19
|
+
export * from './mcp.types.js';
|
|
20
|
+
|
|
21
|
+
// Re-export core interfaces for convenience
|
|
22
|
+
export * from '../core/interfaces/index.js';
|