@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.
Files changed (96) hide show
  1. package/README.md +323 -0
  2. package/__tests__/hooks/bash-safety.test.ts +289 -0
  3. package/__tests__/hooks/file-organization.test.ts +335 -0
  4. package/__tests__/hooks/git-commit.test.ts +336 -0
  5. package/__tests__/hooks/index.ts +23 -0
  6. package/__tests__/hooks/session-hooks.test.ts +357 -0
  7. package/__tests__/hooks/task-hooks.test.ts +193 -0
  8. package/docs/EVENTS_IMPLEMENTATION_SUMMARY.md +388 -0
  9. package/docs/EVENTS_QUICK_REFERENCE.md +470 -0
  10. package/docs/EVENTS_README.md +352 -0
  11. package/package.json +39 -0
  12. package/src/core/config/defaults.ts +207 -0
  13. package/src/core/config/index.ts +15 -0
  14. package/src/core/config/loader.ts +271 -0
  15. package/src/core/config/schema.ts +188 -0
  16. package/src/core/config/validator.ts +209 -0
  17. package/src/core/event-bus.ts +236 -0
  18. package/src/core/index.ts +22 -0
  19. package/src/core/interfaces/agent.interface.ts +251 -0
  20. package/src/core/interfaces/coordinator.interface.ts +363 -0
  21. package/src/core/interfaces/event.interface.ts +267 -0
  22. package/src/core/interfaces/index.ts +19 -0
  23. package/src/core/interfaces/memory.interface.ts +332 -0
  24. package/src/core/interfaces/task.interface.ts +223 -0
  25. package/src/core/orchestrator/event-coordinator.ts +122 -0
  26. package/src/core/orchestrator/health-monitor.ts +214 -0
  27. package/src/core/orchestrator/index.ts +89 -0
  28. package/src/core/orchestrator/lifecycle-manager.ts +263 -0
  29. package/src/core/orchestrator/session-manager.ts +279 -0
  30. package/src/core/orchestrator/task-manager.ts +317 -0
  31. package/src/events/domain-events.ts +584 -0
  32. package/src/events/event-store.test.ts +387 -0
  33. package/src/events/event-store.ts +588 -0
  34. package/src/events/example-usage.ts +293 -0
  35. package/src/events/index.ts +90 -0
  36. package/src/events/projections.ts +561 -0
  37. package/src/events/state-reconstructor.ts +349 -0
  38. package/src/events.ts +367 -0
  39. package/src/hooks/INTEGRATION.md +658 -0
  40. package/src/hooks/README.md +532 -0
  41. package/src/hooks/example-usage.ts +499 -0
  42. package/src/hooks/executor.ts +379 -0
  43. package/src/hooks/hooks.test.ts +421 -0
  44. package/src/hooks/index.ts +131 -0
  45. package/src/hooks/registry.ts +333 -0
  46. package/src/hooks/safety/bash-safety.ts +604 -0
  47. package/src/hooks/safety/file-organization.ts +473 -0
  48. package/src/hooks/safety/git-commit.ts +623 -0
  49. package/src/hooks/safety/index.ts +46 -0
  50. package/src/hooks/session-hooks.ts +559 -0
  51. package/src/hooks/task-hooks.ts +513 -0
  52. package/src/hooks/types.ts +357 -0
  53. package/src/hooks/verify-exports.test.ts +125 -0
  54. package/src/index.ts +195 -0
  55. package/src/mcp/connection-pool.ts +438 -0
  56. package/src/mcp/index.ts +183 -0
  57. package/src/mcp/server.ts +774 -0
  58. package/src/mcp/session-manager.ts +428 -0
  59. package/src/mcp/tool-registry.ts +566 -0
  60. package/src/mcp/transport/http.ts +557 -0
  61. package/src/mcp/transport/index.ts +294 -0
  62. package/src/mcp/transport/stdio.ts +324 -0
  63. package/src/mcp/transport/websocket.ts +484 -0
  64. package/src/mcp/types.ts +565 -0
  65. package/src/plugin-interface.ts +663 -0
  66. package/src/plugin-loader.ts +638 -0
  67. package/src/plugin-registry.ts +604 -0
  68. package/src/plugins/index.ts +34 -0
  69. package/src/plugins/official/hive-mind-plugin.ts +330 -0
  70. package/src/plugins/official/index.ts +24 -0
  71. package/src/plugins/official/maestro-plugin.ts +508 -0
  72. package/src/plugins/types.ts +108 -0
  73. package/src/resilience/bulkhead.ts +277 -0
  74. package/src/resilience/circuit-breaker.ts +326 -0
  75. package/src/resilience/index.ts +26 -0
  76. package/src/resilience/rate-limiter.ts +420 -0
  77. package/src/resilience/retry.ts +224 -0
  78. package/src/security/index.ts +39 -0
  79. package/src/security/input-validation.ts +265 -0
  80. package/src/security/secure-random.ts +159 -0
  81. package/src/services/index.ts +16 -0
  82. package/src/services/v3-progress.service.ts +505 -0
  83. package/src/types/agent.types.ts +144 -0
  84. package/src/types/index.ts +22 -0
  85. package/src/types/mcp.types.ts +300 -0
  86. package/src/types/memory.types.ts +263 -0
  87. package/src/types/swarm.types.ts +255 -0
  88. package/src/types/task.types.ts +205 -0
  89. package/src/types.ts +367 -0
  90. package/src/utils/secure-logger.d.ts +69 -0
  91. package/src/utils/secure-logger.d.ts.map +1 -0
  92. package/src/utils/secure-logger.js +208 -0
  93. package/src/utils/secure-logger.js.map +1 -0
  94. package/src/utils/secure-logger.ts +257 -0
  95. package/tmp.json +0 -0
  96. package/tsconfig.json +9 -0
@@ -0,0 +1,663 @@
1
+ /**
2
+ * V3 Plugin Interface
3
+ * Domain-Driven Design - Plugin-Based Architecture (ADR-004)
4
+ *
5
+ * Microkernel pattern for extensible Claude-Flow V3
6
+ * Enables modular extension points for agents, tasks, MCP tools, CLI commands, and memory backends
7
+ */
8
+
9
+ import type { IEventBus } from './core/interfaces/event.interface.js';
10
+ import type { IAgentConfig } from './core/interfaces/agent.interface.js';
11
+ import type { MCPTool } from './types/mcp.types.js';
12
+
13
+ /**
14
+ * Logger interface for plugin context
15
+ */
16
+ export interface ILogger {
17
+ debug(message: string, ...args: unknown[]): void;
18
+ info(message: string, ...args: unknown[]): void;
19
+ warn(message: string, ...args: unknown[]): void;
20
+ error(message: string, ...args: unknown[]): void;
21
+ }
22
+
23
+ /**
24
+ * Service container for dependency injection
25
+ */
26
+ export interface ServiceContainer {
27
+ /**
28
+ * Register a service in the container
29
+ */
30
+ register<T>(name: string, service: T): void;
31
+
32
+ /**
33
+ * Get a service from the container
34
+ */
35
+ get<T>(name: string): T | undefined;
36
+
37
+ /**
38
+ * Check if a service is registered
39
+ */
40
+ has(name: string): boolean;
41
+
42
+ /**
43
+ * Get all registered service names
44
+ */
45
+ getServiceNames(): string[];
46
+ }
47
+
48
+ /**
49
+ * Plugin configuration
50
+ */
51
+ export interface PluginConfig {
52
+ /**
53
+ * Plugin-specific configuration
54
+ */
55
+ [key: string]: unknown;
56
+
57
+ /**
58
+ * Enable/disable features
59
+ */
60
+ features?: Record<string, boolean>;
61
+
62
+ /**
63
+ * Resource limits
64
+ */
65
+ resources?: {
66
+ maxMemoryMb?: number;
67
+ maxCpuPercent?: number;
68
+ };
69
+ }
70
+
71
+ /**
72
+ * Plugin context provided during initialization
73
+ * Contains services and resources available to plugins
74
+ */
75
+ export interface PluginContext {
76
+ /**
77
+ * Plugin-specific configuration
78
+ */
79
+ config: PluginConfig;
80
+
81
+ /**
82
+ * Event bus for pub/sub communication
83
+ */
84
+ eventBus: IEventBus;
85
+
86
+ /**
87
+ * Logger instance
88
+ */
89
+ logger: ILogger;
90
+
91
+ /**
92
+ * Service container for dependency injection
93
+ */
94
+ services: ServiceContainer;
95
+ }
96
+
97
+ /**
98
+ * Agent type definition for plugin registration
99
+ */
100
+ export interface AgentTypeDefinition {
101
+ /**
102
+ * Unique type identifier
103
+ */
104
+ type: string;
105
+
106
+ /**
107
+ * Human-readable name
108
+ */
109
+ name: string;
110
+
111
+ /**
112
+ * Description of agent capabilities
113
+ */
114
+ description: string;
115
+
116
+ /**
117
+ * Default configuration for this agent type
118
+ */
119
+ defaultConfig: Partial<IAgentConfig>;
120
+
121
+ /**
122
+ * Required capabilities for this agent type
123
+ */
124
+ requiredCapabilities?: string[];
125
+
126
+ /**
127
+ * Optional metadata
128
+ */
129
+ metadata?: Record<string, unknown>;
130
+ }
131
+
132
+ /**
133
+ * Task type definition for plugin registration
134
+ */
135
+ export interface TaskTypeDefinition {
136
+ /**
137
+ * Unique type identifier
138
+ */
139
+ type: string;
140
+
141
+ /**
142
+ * Human-readable name
143
+ */
144
+ name: string;
145
+
146
+ /**
147
+ * Description of task purpose
148
+ */
149
+ description: string;
150
+
151
+ /**
152
+ * Default priority (0-100)
153
+ */
154
+ defaultPriority: number;
155
+
156
+ /**
157
+ * Default timeout in milliseconds
158
+ */
159
+ defaultTimeout: number;
160
+
161
+ /**
162
+ * Required agent capabilities to execute this task
163
+ */
164
+ requiredCapabilities?: string[];
165
+
166
+ /**
167
+ * Task input schema (JSON Schema)
168
+ */
169
+ inputSchema?: {
170
+ type: 'object';
171
+ properties: Record<string, unknown>;
172
+ required?: string[];
173
+ };
174
+
175
+ /**
176
+ * Optional metadata
177
+ */
178
+ metadata?: Record<string, unknown>;
179
+ }
180
+
181
+ /**
182
+ * MCP tool definition for plugin registration
183
+ */
184
+ export interface MCPToolDefinition extends MCPTool {
185
+ /**
186
+ * Plugin that registered this tool
187
+ */
188
+ pluginName?: string;
189
+
190
+ /**
191
+ * Tool version
192
+ */
193
+ version?: string;
194
+
195
+ /**
196
+ * Optional metadata
197
+ */
198
+ metadata?: Record<string, unknown>;
199
+ }
200
+
201
+ /**
202
+ * CLI command definition for plugin registration
203
+ */
204
+ export interface CLICommandDefinition {
205
+ /**
206
+ * Command name
207
+ */
208
+ name: string;
209
+
210
+ /**
211
+ * Command description
212
+ */
213
+ description: string;
214
+
215
+ /**
216
+ * Command aliases
217
+ */
218
+ aliases?: string[];
219
+
220
+ /**
221
+ * Command options
222
+ */
223
+ options?: CLICommandOption[];
224
+
225
+ /**
226
+ * Command arguments
227
+ */
228
+ arguments?: CLICommandArgument[];
229
+
230
+ /**
231
+ * Command handler function
232
+ */
233
+ handler: (args: CLICommandArgs) => Promise<void> | void;
234
+
235
+ /**
236
+ * Optional metadata
237
+ */
238
+ metadata?: Record<string, unknown>;
239
+ }
240
+
241
+ /**
242
+ * CLI command option
243
+ */
244
+ export interface CLICommandOption {
245
+ /**
246
+ * Option name (without dashes)
247
+ */
248
+ name: string;
249
+
250
+ /**
251
+ * Short flag (single character)
252
+ */
253
+ short?: string;
254
+
255
+ /**
256
+ * Option description
257
+ */
258
+ description: string;
259
+
260
+ /**
261
+ * Option type
262
+ */
263
+ type: 'string' | 'number' | 'boolean';
264
+
265
+ /**
266
+ * Default value
267
+ */
268
+ default?: string | number | boolean;
269
+
270
+ /**
271
+ * Is this option required?
272
+ */
273
+ required?: boolean;
274
+ }
275
+
276
+ /**
277
+ * CLI command argument
278
+ */
279
+ export interface CLICommandArgument {
280
+ /**
281
+ * Argument name
282
+ */
283
+ name: string;
284
+
285
+ /**
286
+ * Argument description
287
+ */
288
+ description: string;
289
+
290
+ /**
291
+ * Is this argument required?
292
+ */
293
+ required?: boolean;
294
+
295
+ /**
296
+ * Default value
297
+ */
298
+ default?: string;
299
+
300
+ /**
301
+ * Allowed values (for validation)
302
+ */
303
+ choices?: string[];
304
+ }
305
+
306
+ /**
307
+ * CLI command parsed arguments
308
+ */
309
+ export interface CLICommandArgs {
310
+ /**
311
+ * Positional arguments
312
+ */
313
+ _: string[];
314
+
315
+ /**
316
+ * Named options
317
+ */
318
+ [key: string]: unknown;
319
+ }
320
+
321
+ /**
322
+ * Memory backend factory for plugin registration
323
+ */
324
+ export interface MemoryBackendFactory {
325
+ /**
326
+ * Backend name
327
+ */
328
+ name: string;
329
+
330
+ /**
331
+ * Backend description
332
+ */
333
+ description: string;
334
+
335
+ /**
336
+ * Create a new backend instance
337
+ */
338
+ create(config: MemoryBackendConfig): Promise<IMemoryBackend>;
339
+
340
+ /**
341
+ * Backend capabilities
342
+ */
343
+ capabilities: {
344
+ supportsVectorSearch: boolean;
345
+ supportsFullText: boolean;
346
+ supportsTransactions: boolean;
347
+ supportsPersistence: boolean;
348
+ };
349
+
350
+ /**
351
+ * Optional metadata
352
+ */
353
+ metadata?: Record<string, unknown>;
354
+ }
355
+
356
+ /**
357
+ * Memory backend configuration
358
+ */
359
+ export interface MemoryBackendConfig {
360
+ /**
361
+ * Storage path or connection string
362
+ */
363
+ path?: string;
364
+
365
+ /**
366
+ * Backend-specific options
367
+ */
368
+ options?: Record<string, unknown>;
369
+
370
+ /**
371
+ * Resource limits
372
+ */
373
+ limits?: {
374
+ maxMemoryMb?: number;
375
+ maxStorageMb?: number;
376
+ };
377
+ }
378
+
379
+ /**
380
+ * Memory backend interface
381
+ */
382
+ export interface IMemoryBackend {
383
+ /**
384
+ * Initialize the backend
385
+ */
386
+ initialize(): Promise<void>;
387
+
388
+ /**
389
+ * Shutdown the backend
390
+ */
391
+ shutdown(): Promise<void>;
392
+
393
+ /**
394
+ * Store a memory entry
395
+ */
396
+ store(key: string, value: unknown, metadata?: Record<string, unknown>): Promise<void>;
397
+
398
+ /**
399
+ * Retrieve a memory entry
400
+ */
401
+ retrieve(key: string): Promise<unknown | null>;
402
+
403
+ /**
404
+ * Delete a memory entry
405
+ */
406
+ delete(key: string): Promise<boolean>;
407
+
408
+ /**
409
+ * Search memory entries
410
+ */
411
+ search(query: string, options?: MemorySearchOptions): Promise<MemorySearchResult[]>;
412
+
413
+ /**
414
+ * Clear all memory entries
415
+ */
416
+ clear(): Promise<void>;
417
+
418
+ /**
419
+ * Get backend statistics
420
+ */
421
+ getStats(): Promise<MemoryBackendStats>;
422
+ }
423
+
424
+ /**
425
+ * Memory search options
426
+ */
427
+ export interface MemorySearchOptions {
428
+ /**
429
+ * Maximum number of results
430
+ */
431
+ limit?: number;
432
+
433
+ /**
434
+ * Result offset for pagination
435
+ */
436
+ offset?: number;
437
+
438
+ /**
439
+ * Minimum similarity score (0-1)
440
+ */
441
+ minScore?: number;
442
+
443
+ /**
444
+ * Filter by metadata
445
+ */
446
+ filter?: Record<string, unknown>;
447
+ }
448
+
449
+ /**
450
+ * Memory search result
451
+ */
452
+ export interface MemorySearchResult {
453
+ /**
454
+ * Memory key
455
+ */
456
+ key: string;
457
+
458
+ /**
459
+ * Memory value
460
+ */
461
+ value: unknown;
462
+
463
+ /**
464
+ * Similarity score (0-1)
465
+ */
466
+ score: number;
467
+
468
+ /**
469
+ * Associated metadata
470
+ */
471
+ metadata?: Record<string, unknown>;
472
+ }
473
+
474
+ /**
475
+ * Memory backend statistics
476
+ */
477
+ export interface MemoryBackendStats {
478
+ /**
479
+ * Total number of entries
480
+ */
481
+ entryCount: number;
482
+
483
+ /**
484
+ * Total storage size in bytes
485
+ */
486
+ sizeBytes: number;
487
+
488
+ /**
489
+ * Memory usage in bytes
490
+ */
491
+ memoryUsageBytes: number;
492
+
493
+ /**
494
+ * Backend-specific metrics
495
+ */
496
+ metrics?: Record<string, number>;
497
+ }
498
+
499
+ /**
500
+ * Core ClaudeFlowPlugin interface
501
+ * All plugins must implement this interface
502
+ */
503
+ export interface ClaudeFlowPlugin {
504
+ /**
505
+ * Unique plugin name
506
+ */
507
+ readonly name: string;
508
+
509
+ /**
510
+ * Plugin version (semver)
511
+ */
512
+ readonly version: string;
513
+
514
+ /**
515
+ * Optional plugin dependencies
516
+ * List of plugin names that must be loaded before this plugin
517
+ */
518
+ readonly dependencies?: string[];
519
+
520
+ /**
521
+ * Plugin description
522
+ */
523
+ readonly description?: string;
524
+
525
+ /**
526
+ * Plugin author
527
+ */
528
+ readonly author?: string;
529
+
530
+ /**
531
+ * Initialize the plugin
532
+ * Called after all dependencies are loaded
533
+ */
534
+ initialize(context: PluginContext): Promise<void>;
535
+
536
+ /**
537
+ * Shutdown the plugin
538
+ * Called during system shutdown
539
+ */
540
+ shutdown(): Promise<void>;
541
+
542
+ /**
543
+ * Register custom agent types (optional)
544
+ * @returns Array of agent type definitions
545
+ */
546
+ registerAgentTypes?(): AgentTypeDefinition[];
547
+
548
+ /**
549
+ * Register custom task types (optional)
550
+ * @returns Array of task type definitions
551
+ */
552
+ registerTaskTypes?(): TaskTypeDefinition[];
553
+
554
+ /**
555
+ * Register MCP tools (optional)
556
+ * @returns Array of MCP tool definitions
557
+ */
558
+ registerMCPTools?(): MCPToolDefinition[];
559
+
560
+ /**
561
+ * Register CLI commands (optional)
562
+ * @returns Array of CLI command definitions
563
+ */
564
+ registerCLICommands?(): CLICommandDefinition[];
565
+
566
+ /**
567
+ * Register memory backends (optional)
568
+ * @returns Array of memory backend factories
569
+ */
570
+ registerMemoryBackends?(): MemoryBackendFactory[];
571
+
572
+ /**
573
+ * Optional health check
574
+ * @returns true if plugin is healthy, false otherwise
575
+ */
576
+ healthCheck?(): Promise<boolean>;
577
+
578
+ /**
579
+ * Optional plugin metadata
580
+ */
581
+ metadata?: Record<string, unknown>;
582
+ }
583
+
584
+ /**
585
+ * Plugin lifecycle state
586
+ */
587
+ export type PluginLifecycleState =
588
+ | 'uninitialized'
589
+ | 'initializing'
590
+ | 'initialized'
591
+ | 'shutting-down'
592
+ | 'shutdown'
593
+ | 'error';
594
+
595
+ /**
596
+ * Plugin info for registry tracking
597
+ */
598
+ export interface PluginInfo {
599
+ /**
600
+ * Plugin instance
601
+ */
602
+ plugin: ClaudeFlowPlugin;
603
+
604
+ /**
605
+ * Current lifecycle state
606
+ */
607
+ state: PluginLifecycleState;
608
+
609
+ /**
610
+ * Initialization timestamp
611
+ */
612
+ initializedAt?: Date;
613
+
614
+ /**
615
+ * Shutdown timestamp
616
+ */
617
+ shutdownAt?: Date;
618
+
619
+ /**
620
+ * Plugin context
621
+ */
622
+ context?: PluginContext;
623
+
624
+ /**
625
+ * Error if state is 'error'
626
+ */
627
+ error?: Error;
628
+
629
+ /**
630
+ * Plugin metrics
631
+ */
632
+ metrics?: {
633
+ agentTypesRegistered: number;
634
+ taskTypesRegistered: number;
635
+ mcpToolsRegistered: number;
636
+ cliCommandsRegistered: number;
637
+ memoryBackendsRegistered: number;
638
+ };
639
+ }
640
+
641
+ /**
642
+ * Plugin error types
643
+ */
644
+ export class PluginError extends Error {
645
+ constructor(
646
+ message: string,
647
+ public readonly pluginName: string,
648
+ public readonly code: PluginErrorCode,
649
+ public readonly cause?: Error
650
+ ) {
651
+ super(message);
652
+ this.name = 'PluginError';
653
+ }
654
+ }
655
+
656
+ export type PluginErrorCode =
657
+ | 'INITIALIZATION_FAILED'
658
+ | 'SHUTDOWN_FAILED'
659
+ | 'DEPENDENCY_NOT_FOUND'
660
+ | 'CIRCULAR_DEPENDENCY'
661
+ | 'INVALID_PLUGIN'
662
+ | 'DUPLICATE_PLUGIN'
663
+ | 'HEALTH_CHECK_FAILED';