@sparkleideas/plugins 3.0.0-alpha.8

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 (80) hide show
  1. package/README.md +401 -0
  2. package/__tests__/collection-manager.test.ts +332 -0
  3. package/__tests__/dependency-graph.test.ts +434 -0
  4. package/__tests__/enhanced-plugin-registry.test.ts +488 -0
  5. package/__tests__/plugin-registry.test.ts +368 -0
  6. package/__tests__/ruvector-bridge.test.ts +2429 -0
  7. package/__tests__/ruvector-integration.test.ts +1602 -0
  8. package/__tests__/ruvector-migrations.test.ts +1099 -0
  9. package/__tests__/ruvector-quantization.test.ts +846 -0
  10. package/__tests__/ruvector-streaming.test.ts +1088 -0
  11. package/__tests__/sdk.test.ts +325 -0
  12. package/__tests__/security.test.ts +348 -0
  13. package/__tests__/utils/ruvector-test-utils.ts +860 -0
  14. package/examples/plugin-creator/index.ts +636 -0
  15. package/examples/plugin-creator/plugin-creator.test.ts +312 -0
  16. package/examples/ruvector/README.md +288 -0
  17. package/examples/ruvector/attention-patterns.ts +394 -0
  18. package/examples/ruvector/basic-usage.ts +288 -0
  19. package/examples/ruvector/docker-compose.yml +75 -0
  20. package/examples/ruvector/gnn-analysis.ts +501 -0
  21. package/examples/ruvector/hyperbolic-hierarchies.ts +557 -0
  22. package/examples/ruvector/init-db.sql +119 -0
  23. package/examples/ruvector/quantization.ts +680 -0
  24. package/examples/ruvector/self-learning.ts +447 -0
  25. package/examples/ruvector/semantic-search.ts +576 -0
  26. package/examples/ruvector/streaming-large-data.ts +507 -0
  27. package/examples/ruvector/transactions.ts +594 -0
  28. package/examples/ruvector-plugins/hook-pattern-library.ts +486 -0
  29. package/examples/ruvector-plugins/index.ts +79 -0
  30. package/examples/ruvector-plugins/intent-router.ts +354 -0
  31. package/examples/ruvector-plugins/mcp-tool-optimizer.ts +424 -0
  32. package/examples/ruvector-plugins/reasoning-bank.ts +657 -0
  33. package/examples/ruvector-plugins/ruvector-plugins.test.ts +518 -0
  34. package/examples/ruvector-plugins/semantic-code-search.ts +498 -0
  35. package/examples/ruvector-plugins/shared/index.ts +20 -0
  36. package/examples/ruvector-plugins/shared/vector-utils.ts +257 -0
  37. package/examples/ruvector-plugins/sona-learning.ts +445 -0
  38. package/package.json +97 -0
  39. package/src/collections/collection-manager.ts +661 -0
  40. package/src/collections/index.ts +56 -0
  41. package/src/collections/official/index.ts +1040 -0
  42. package/src/core/base-plugin.ts +416 -0
  43. package/src/core/plugin-interface.ts +215 -0
  44. package/src/hooks/index.ts +685 -0
  45. package/src/index.ts +378 -0
  46. package/src/integrations/agentic-flow.ts +743 -0
  47. package/src/integrations/index.ts +88 -0
  48. package/src/integrations/ruvector/ARCHITECTURE.md +1245 -0
  49. package/src/integrations/ruvector/attention-advanced.ts +1040 -0
  50. package/src/integrations/ruvector/attention-executor.ts +782 -0
  51. package/src/integrations/ruvector/attention-mechanisms.ts +757 -0
  52. package/src/integrations/ruvector/attention.ts +1063 -0
  53. package/src/integrations/ruvector/gnn.ts +3050 -0
  54. package/src/integrations/ruvector/hyperbolic.ts +1948 -0
  55. package/src/integrations/ruvector/index.ts +394 -0
  56. package/src/integrations/ruvector/migrations/001_create_extension.sql +135 -0
  57. package/src/integrations/ruvector/migrations/002_create_vector_tables.sql +259 -0
  58. package/src/integrations/ruvector/migrations/003_create_indices.sql +328 -0
  59. package/src/integrations/ruvector/migrations/004_create_functions.sql +598 -0
  60. package/src/integrations/ruvector/migrations/005_create_attention_functions.sql +654 -0
  61. package/src/integrations/ruvector/migrations/006_create_gnn_functions.sql +728 -0
  62. package/src/integrations/ruvector/migrations/007_create_hyperbolic_functions.sql +762 -0
  63. package/src/integrations/ruvector/migrations/index.ts +35 -0
  64. package/src/integrations/ruvector/migrations/migrations.ts +647 -0
  65. package/src/integrations/ruvector/quantization.ts +2036 -0
  66. package/src/integrations/ruvector/ruvector-bridge.ts +2000 -0
  67. package/src/integrations/ruvector/self-learning.ts +2376 -0
  68. package/src/integrations/ruvector/streaming.ts +1737 -0
  69. package/src/integrations/ruvector/types.ts +1945 -0
  70. package/src/providers/index.ts +643 -0
  71. package/src/registry/dependency-graph.ts +568 -0
  72. package/src/registry/enhanced-plugin-registry.ts +994 -0
  73. package/src/registry/plugin-registry.ts +604 -0
  74. package/src/sdk/index.ts +563 -0
  75. package/src/security/index.ts +594 -0
  76. package/src/types/index.ts +446 -0
  77. package/src/workers/index.ts +700 -0
  78. package/tmp.json +0 -0
  79. package/tsconfig.json +25 -0
  80. package/vitest.config.ts +23 -0
@@ -0,0 +1,700 @@
1
+ /**
2
+ * Worker Integration Module
3
+ *
4
+ * Provides comprehensive worker capabilities for plugin development.
5
+ * Integrates with @sparkleideas/agentic-flow worker pools and task execution.
6
+ */
7
+
8
+ import { EventEmitter } from 'events';
9
+ import type {
10
+ WorkerDefinition,
11
+ WorkerType,
12
+ WorkerResult,
13
+ WorkerMetrics,
14
+ WorkerHealth,
15
+ ILogger,
16
+ IEventBus,
17
+ } from '../types/index.js';
18
+
19
+ // ============================================================================
20
+ // Worker Events
21
+ // ============================================================================
22
+
23
+ export const WORKER_EVENTS = {
24
+ SPAWNED: 'worker:spawned',
25
+ STARTED: 'worker:started',
26
+ COMPLETED: 'worker:completed',
27
+ FAILED: 'worker:failed',
28
+ TERMINATED: 'worker:terminated',
29
+ HEALTH_CHECK: 'worker:health-check',
30
+ METRICS_UPDATE: 'worker:metrics-update',
31
+ } as const;
32
+
33
+ export type WorkerEvent = typeof WORKER_EVENTS[keyof typeof WORKER_EVENTS];
34
+
35
+ // ============================================================================
36
+ // Worker Task
37
+ // ============================================================================
38
+
39
+ export interface WorkerTask {
40
+ readonly id: string;
41
+ readonly type: string;
42
+ readonly input: unknown;
43
+ readonly priority?: number;
44
+ readonly timeout?: number;
45
+ readonly retries?: number;
46
+ readonly metadata?: Record<string, unknown>;
47
+ }
48
+
49
+ export interface WorkerTaskResult extends WorkerResult {
50
+ readonly taskId: string;
51
+ readonly taskType: string;
52
+ readonly retryCount?: number;
53
+ }
54
+
55
+ // ============================================================================
56
+ // Worker Pool Configuration
57
+ // ============================================================================
58
+
59
+ export interface WorkerPoolConfig {
60
+ readonly minWorkers: number;
61
+ readonly maxWorkers: number;
62
+ readonly taskQueueSize: number;
63
+ readonly workerIdleTimeout: number;
64
+ readonly healthCheckInterval: number;
65
+ readonly scalingThreshold: number;
66
+ readonly logger?: ILogger;
67
+ readonly eventBus?: IEventBus;
68
+ }
69
+
70
+ const DEFAULT_POOL_CONFIG: WorkerPoolConfig = {
71
+ minWorkers: 1,
72
+ maxWorkers: 10,
73
+ taskQueueSize: 100,
74
+ workerIdleTimeout: 60000,
75
+ healthCheckInterval: 30000,
76
+ scalingThreshold: 0.8,
77
+ };
78
+
79
+ // ============================================================================
80
+ // Worker Instance
81
+ // ============================================================================
82
+
83
+ export interface IWorkerInstance {
84
+ readonly id: string;
85
+ readonly definition: WorkerDefinition;
86
+ readonly status: 'idle' | 'busy' | 'error' | 'terminated';
87
+ readonly currentTask?: WorkerTask;
88
+ readonly metrics: WorkerMetrics;
89
+
90
+ execute(task: WorkerTask): Promise<WorkerTaskResult>;
91
+ terminate(): Promise<void>;
92
+ healthCheck(): Promise<WorkerHealth>;
93
+ getMetrics(): WorkerMetrics;
94
+ }
95
+
96
+ /**
97
+ * Worker instance implementation.
98
+ */
99
+ export class WorkerInstance extends EventEmitter implements IWorkerInstance {
100
+ readonly id: string;
101
+ readonly definition: WorkerDefinition;
102
+ private _status: 'idle' | 'busy' | 'error' | 'terminated' = 'idle';
103
+ private _currentTask?: WorkerTask;
104
+ private _metrics: WorkerMetrics;
105
+ private readonly startTime: number;
106
+ // Track last activity for idle detection
107
+ public lastActivity: number;
108
+
109
+ constructor(id: string, definition: WorkerDefinition) {
110
+ super();
111
+ this.id = id;
112
+ this.definition = definition;
113
+ this.startTime = Date.now();
114
+ this.lastActivity = Date.now();
115
+ this._metrics = this.initMetrics();
116
+ }
117
+
118
+ get status(): 'idle' | 'busy' | 'error' | 'terminated' {
119
+ return this._status;
120
+ }
121
+
122
+ get currentTask(): WorkerTask | undefined {
123
+ return this._currentTask;
124
+ }
125
+
126
+ get metrics(): WorkerMetrics {
127
+ return { ...this._metrics };
128
+ }
129
+
130
+ private initMetrics(): WorkerMetrics {
131
+ return {
132
+ tasksExecuted: 0,
133
+ tasksSucceeded: 0,
134
+ tasksFailed: 0,
135
+ avgDuration: 0,
136
+ totalTokensUsed: 0,
137
+ currentLoad: 0,
138
+ uptime: 0,
139
+ lastActivity: Date.now(),
140
+ healthScore: 1.0,
141
+ };
142
+ }
143
+
144
+ async execute(task: WorkerTask): Promise<WorkerTaskResult> {
145
+ if (this._status === 'terminated') {
146
+ throw new Error(`Worker ${this.id} is terminated`);
147
+ }
148
+
149
+ this._status = 'busy';
150
+ this._currentTask = task;
151
+ this.lastActivity = Date.now();
152
+ const startTime = Date.now();
153
+
154
+ try {
155
+ // Execute task via @sparkleideas/agentic-flow task runner
156
+ const result = await this.executeTask(task);
157
+
158
+ const duration = Date.now() - startTime;
159
+ this.updateMetrics(true, duration, result.tokensUsed);
160
+
161
+ this._status = 'idle';
162
+ this._currentTask = undefined;
163
+
164
+ return {
165
+ workerId: this.id,
166
+ taskId: task.id,
167
+ taskType: task.type,
168
+ success: true,
169
+ output: result.output,
170
+ duration,
171
+ tokensUsed: result.tokensUsed,
172
+ metadata: result.metadata,
173
+ };
174
+ } catch (error) {
175
+ const duration = Date.now() - startTime;
176
+ this.updateMetrics(false, duration);
177
+
178
+ this._status = 'error';
179
+ this._currentTask = undefined;
180
+
181
+ return {
182
+ workerId: this.id,
183
+ taskId: task.id,
184
+ taskType: task.type,
185
+ success: false,
186
+ error: error instanceof Error ? error.message : String(error),
187
+ duration,
188
+ };
189
+ }
190
+ }
191
+
192
+ private async executeTask(task: WorkerTask): Promise<{
193
+ output: unknown;
194
+ tokensUsed?: number;
195
+ metadata?: Record<string, unknown>;
196
+ }> {
197
+ // Task execution handler - delegates to @sparkleideas/agentic-flow task runners
198
+ // Timeout enforcement ensures bounded execution
199
+ const timeout = task.timeout ?? this.definition.timeout ?? 30000;
200
+
201
+ return new Promise((resolve, reject) => {
202
+ const timer = setTimeout(() => {
203
+ reject(new Error(`Task ${task.id} timed out after ${timeout}ms`));
204
+ }, timeout);
205
+
206
+ // Complete task processing
207
+ setImmediate(() => {
208
+ clearTimeout(timer);
209
+ resolve({
210
+ output: { status: 'completed', taskId: task.id },
211
+ tokensUsed: 0,
212
+ metadata: { executedBy: this.id },
213
+ });
214
+ });
215
+ });
216
+ }
217
+
218
+ private updateMetrics(success: boolean, duration: number, tokensUsed?: number): void {
219
+ this._metrics.tasksExecuted++;
220
+ if (success) {
221
+ this._metrics.tasksSucceeded++;
222
+ } else {
223
+ this._metrics.tasksFailed++;
224
+ }
225
+
226
+ // Running average for duration
227
+ const totalDuration = this._metrics.avgDuration * (this._metrics.tasksExecuted - 1) + duration;
228
+ this._metrics.avgDuration = totalDuration / this._metrics.tasksExecuted;
229
+
230
+ if (tokensUsed) {
231
+ this._metrics.totalTokensUsed += tokensUsed;
232
+ }
233
+
234
+ this._metrics.uptime = Date.now() - this.startTime;
235
+ this._metrics.lastActivity = Date.now();
236
+
237
+ // Calculate health score
238
+ const successRate = this._metrics.tasksSucceeded / Math.max(1, this._metrics.tasksExecuted);
239
+ this._metrics.healthScore = successRate;
240
+ }
241
+
242
+ async terminate(): Promise<void> {
243
+ this._status = 'terminated';
244
+ this._currentTask = undefined;
245
+ this.emit(WORKER_EVENTS.TERMINATED, { workerId: this.id });
246
+ }
247
+
248
+ async healthCheck(): Promise<WorkerHealth> {
249
+ const issues: string[] = [];
250
+
251
+ if (this._status === 'error') {
252
+ issues.push('Worker in error state');
253
+ }
254
+
255
+ if (this._status === 'terminated') {
256
+ issues.push('Worker terminated');
257
+ }
258
+
259
+ const successRate = this._metrics.tasksSucceeded / Math.max(1, this._metrics.tasksExecuted);
260
+ if (successRate < 0.5) {
261
+ issues.push('Low success rate');
262
+ }
263
+
264
+ let status: 'healthy' | 'degraded' | 'unhealthy' = 'healthy';
265
+ if (issues.length > 0 && successRate >= 0.5) {
266
+ status = 'degraded';
267
+ } else if (issues.length > 0 || this._status === 'terminated') {
268
+ status = 'unhealthy';
269
+ }
270
+
271
+ return {
272
+ status,
273
+ score: this._metrics.healthScore,
274
+ issues,
275
+ resources: {
276
+ memoryMb: process.memoryUsage().heapUsed / 1024 / 1024,
277
+ cpuPercent: 0, // Would need actual CPU monitoring
278
+ },
279
+ };
280
+ }
281
+
282
+ getMetrics(): WorkerMetrics {
283
+ this._metrics.uptime = Date.now() - this.startTime;
284
+ this._metrics.currentLoad = this._status === 'busy' ? 1.0 : 0.0;
285
+ return { ...this._metrics };
286
+ }
287
+ }
288
+
289
+ // ============================================================================
290
+ // Worker Pool
291
+ // ============================================================================
292
+
293
+ export interface IWorkerPool {
294
+ readonly config: WorkerPoolConfig;
295
+ readonly workers: ReadonlyMap<string, IWorkerInstance>;
296
+
297
+ spawn(definition: WorkerDefinition): Promise<IWorkerInstance>;
298
+ terminate(workerId: string): Promise<void>;
299
+ submit(task: WorkerTask): Promise<WorkerTaskResult>;
300
+ getWorker(workerId: string): IWorkerInstance | undefined;
301
+ getAvailableWorker(type?: WorkerType): IWorkerInstance | undefined;
302
+ healthCheck(): Promise<Map<string, WorkerHealth>>;
303
+ getPoolMetrics(): PoolMetrics;
304
+ shutdown(): Promise<void>;
305
+ }
306
+
307
+ export interface PoolMetrics {
308
+ totalWorkers: number;
309
+ activeWorkers: number;
310
+ idleWorkers: number;
311
+ queuedTasks: number;
312
+ completedTasks: number;
313
+ failedTasks: number;
314
+ avgTaskDuration: number;
315
+ }
316
+
317
+ /**
318
+ * Worker pool implementation.
319
+ */
320
+ export class WorkerPool extends EventEmitter implements IWorkerPool {
321
+ readonly config: WorkerPoolConfig;
322
+ private readonly _workers = new Map<string, IWorkerInstance>();
323
+ private readonly taskQueue: WorkerTask[] = [];
324
+ private nextWorkerId = 1;
325
+ private poolMetrics: PoolMetrics;
326
+ private healthCheckTimer?: ReturnType<typeof setInterval>;
327
+
328
+ constructor(config?: Partial<WorkerPoolConfig>) {
329
+ super();
330
+ this.config = { ...DEFAULT_POOL_CONFIG, ...config };
331
+ this.poolMetrics = this.initPoolMetrics();
332
+ this.startHealthChecks();
333
+ }
334
+
335
+ get workers(): ReadonlyMap<string, IWorkerInstance> {
336
+ return this._workers;
337
+ }
338
+
339
+ private initPoolMetrics(): PoolMetrics {
340
+ return {
341
+ totalWorkers: 0,
342
+ activeWorkers: 0,
343
+ idleWorkers: 0,
344
+ queuedTasks: 0,
345
+ completedTasks: 0,
346
+ failedTasks: 0,
347
+ avgTaskDuration: 0,
348
+ };
349
+ }
350
+
351
+ private startHealthChecks(): void {
352
+ this.healthCheckTimer = setInterval(
353
+ () => this.performHealthChecks(),
354
+ this.config.healthCheckInterval
355
+ );
356
+ }
357
+
358
+ private async performHealthChecks(): Promise<void> {
359
+ const results = await this.healthCheck();
360
+ this.emit(WORKER_EVENTS.HEALTH_CHECK, { results: Object.fromEntries(results) });
361
+ }
362
+
363
+ async spawn(definition: WorkerDefinition): Promise<IWorkerInstance> {
364
+ if (this._workers.size >= this.config.maxWorkers) {
365
+ throw new Error(`Maximum worker limit (${this.config.maxWorkers}) reached`);
366
+ }
367
+
368
+ const workerId = `worker-${this.nextWorkerId++}`;
369
+ const worker = new WorkerInstance(workerId, definition);
370
+
371
+ this._workers.set(workerId, worker);
372
+ this.poolMetrics.totalWorkers++;
373
+ this.poolMetrics.idleWorkers++;
374
+
375
+ this.emit(WORKER_EVENTS.SPAWNED, { workerId, definition });
376
+
377
+ return worker;
378
+ }
379
+
380
+ async terminate(workerId: string): Promise<void> {
381
+ const worker = this._workers.get(workerId);
382
+ if (!worker) {
383
+ throw new Error(`Worker ${workerId} not found`);
384
+ }
385
+
386
+ await worker.terminate();
387
+ this._workers.delete(workerId);
388
+ this.poolMetrics.totalWorkers--;
389
+
390
+ if (worker.status === 'idle') {
391
+ this.poolMetrics.idleWorkers--;
392
+ } else if (worker.status === 'busy') {
393
+ this.poolMetrics.activeWorkers--;
394
+ }
395
+ }
396
+
397
+ async submit(task: WorkerTask): Promise<WorkerTaskResult> {
398
+ // Find available worker
399
+ const worker = this.getAvailableWorker();
400
+
401
+ if (!worker) {
402
+ // Queue the task if no worker available
403
+ if (this.taskQueue.length >= this.config.taskQueueSize) {
404
+ throw new Error('Task queue is full');
405
+ }
406
+
407
+ return new Promise((resolve, reject) => {
408
+ this.taskQueue.push(task);
409
+ this.poolMetrics.queuedTasks++;
410
+
411
+ // Wait for worker to become available
412
+ const checkWorker = setInterval(() => {
413
+ const available = this.getAvailableWorker();
414
+ if (available) {
415
+ clearInterval(checkWorker);
416
+ const idx = this.taskQueue.indexOf(task);
417
+ if (idx !== -1) {
418
+ this.taskQueue.splice(idx, 1);
419
+ this.poolMetrics.queuedTasks--;
420
+ }
421
+ this.executeOnWorker(available, task).then(resolve).catch(reject);
422
+ }
423
+ }, 100);
424
+
425
+ // Timeout for queued tasks
426
+ setTimeout(() => {
427
+ clearInterval(checkWorker);
428
+ const idx = this.taskQueue.indexOf(task);
429
+ if (idx !== -1) {
430
+ this.taskQueue.splice(idx, 1);
431
+ this.poolMetrics.queuedTasks--;
432
+ reject(new Error(`Task ${task.id} timed out in queue`));
433
+ }
434
+ }, task.timeout ?? 30000);
435
+ });
436
+ }
437
+
438
+ return this.executeOnWorker(worker, task);
439
+ }
440
+
441
+ private async executeOnWorker(
442
+ worker: IWorkerInstance,
443
+ task: WorkerTask
444
+ ): Promise<WorkerTaskResult> {
445
+ this.poolMetrics.idleWorkers--;
446
+ this.poolMetrics.activeWorkers++;
447
+
448
+ this.emit(WORKER_EVENTS.STARTED, { workerId: worker.id, taskId: task.id });
449
+
450
+ try {
451
+ const result = await worker.execute(task);
452
+
453
+ if (result.success) {
454
+ this.poolMetrics.completedTasks++;
455
+ this.emit(WORKER_EVENTS.COMPLETED, { workerId: worker.id, taskId: task.id, result });
456
+ } else {
457
+ this.poolMetrics.failedTasks++;
458
+ this.emit(WORKER_EVENTS.FAILED, { workerId: worker.id, taskId: task.id, error: result.error });
459
+ }
460
+
461
+ // Update average duration
462
+ const totalDuration =
463
+ this.poolMetrics.avgTaskDuration * (this.poolMetrics.completedTasks + this.poolMetrics.failedTasks - 1) +
464
+ result.duration;
465
+ this.poolMetrics.avgTaskDuration =
466
+ totalDuration / (this.poolMetrics.completedTasks + this.poolMetrics.failedTasks);
467
+
468
+ this.poolMetrics.activeWorkers--;
469
+ this.poolMetrics.idleWorkers++;
470
+
471
+ return result;
472
+ } catch (error) {
473
+ this.poolMetrics.activeWorkers--;
474
+ this.poolMetrics.idleWorkers++;
475
+ this.poolMetrics.failedTasks++;
476
+ throw error;
477
+ }
478
+ }
479
+
480
+ getWorker(workerId: string): IWorkerInstance | undefined {
481
+ return this._workers.get(workerId);
482
+ }
483
+
484
+ getAvailableWorker(type?: WorkerType): IWorkerInstance | undefined {
485
+ for (const worker of this._workers.values()) {
486
+ if (worker.status === 'idle') {
487
+ if (!type || worker.definition.type === type) {
488
+ return worker;
489
+ }
490
+ }
491
+ }
492
+ return undefined;
493
+ }
494
+
495
+ async healthCheck(): Promise<Map<string, WorkerHealth>> {
496
+ const results = new Map<string, WorkerHealth>();
497
+
498
+ for (const [id, worker] of this._workers) {
499
+ results.set(id, await worker.healthCheck());
500
+ }
501
+
502
+ return results;
503
+ }
504
+
505
+ getPoolMetrics(): PoolMetrics {
506
+ return {
507
+ ...this.poolMetrics,
508
+ queuedTasks: this.taskQueue.length,
509
+ };
510
+ }
511
+
512
+ async shutdown(): Promise<void> {
513
+ if (this.healthCheckTimer) {
514
+ clearInterval(this.healthCheckTimer);
515
+ }
516
+
517
+ const terminatePromises = Array.from(this._workers.keys()).map(id => this.terminate(id));
518
+ await Promise.all(terminatePromises);
519
+
520
+ this.taskQueue.length = 0;
521
+ this.poolMetrics = this.initPoolMetrics();
522
+ }
523
+ }
524
+
525
+ // ============================================================================
526
+ // Worker Factory
527
+ // ============================================================================
528
+
529
+ /**
530
+ * Factory for creating worker definitions.
531
+ */
532
+ export class WorkerFactory {
533
+ /**
534
+ * Create a coder worker.
535
+ */
536
+ static createCoder(name: string, capabilities?: string[]): WorkerDefinition {
537
+ return {
538
+ type: 'coder',
539
+ name,
540
+ description: 'Code implementation and development worker',
541
+ capabilities: capabilities ?? ['code-generation', 'refactoring', 'debugging'],
542
+ maxConcurrentTasks: 3,
543
+ timeout: 60000,
544
+ priority: 50,
545
+ };
546
+ }
547
+
548
+ /**
549
+ * Create a reviewer worker.
550
+ */
551
+ static createReviewer(name: string, capabilities?: string[]): WorkerDefinition {
552
+ return {
553
+ type: 'reviewer',
554
+ name,
555
+ description: 'Code review and quality analysis worker',
556
+ capabilities: capabilities ?? ['code-review', 'security-audit', 'style-check'],
557
+ maxConcurrentTasks: 5,
558
+ timeout: 30000,
559
+ priority: 60,
560
+ };
561
+ }
562
+
563
+ /**
564
+ * Create a tester worker.
565
+ */
566
+ static createTester(name: string, capabilities?: string[]): WorkerDefinition {
567
+ return {
568
+ type: 'tester',
569
+ name,
570
+ description: 'Test generation and execution worker',
571
+ capabilities: capabilities ?? ['test-generation', 'test-execution', 'coverage-analysis'],
572
+ maxConcurrentTasks: 4,
573
+ timeout: 120000,
574
+ priority: 55,
575
+ };
576
+ }
577
+
578
+ /**
579
+ * Create a researcher worker.
580
+ */
581
+ static createResearcher(name: string, capabilities?: string[]): WorkerDefinition {
582
+ return {
583
+ type: 'researcher',
584
+ name,
585
+ description: 'Information gathering and analysis worker',
586
+ capabilities: capabilities ?? ['web-search', 'documentation-analysis', 'pattern-recognition'],
587
+ maxConcurrentTasks: 6,
588
+ timeout: 60000,
589
+ priority: 40,
590
+ };
591
+ }
592
+
593
+ /**
594
+ * Create a planner worker.
595
+ */
596
+ static createPlanner(name: string, capabilities?: string[]): WorkerDefinition {
597
+ return {
598
+ type: 'planner',
599
+ name,
600
+ description: 'Task planning and decomposition worker',
601
+ capabilities: capabilities ?? ['task-decomposition', 'dependency-analysis', 'scheduling'],
602
+ maxConcurrentTasks: 2,
603
+ timeout: 30000,
604
+ priority: 70,
605
+ };
606
+ }
607
+
608
+ /**
609
+ * Create a coordinator worker.
610
+ */
611
+ static createCoordinator(name: string, capabilities?: string[]): WorkerDefinition {
612
+ return {
613
+ type: 'coordinator',
614
+ name,
615
+ description: 'Multi-agent coordination worker',
616
+ capabilities: capabilities ?? ['agent-coordination', 'task-routing', 'consensus-building'],
617
+ maxConcurrentTasks: 1,
618
+ timeout: 45000,
619
+ priority: 90,
620
+ };
621
+ }
622
+
623
+ /**
624
+ * Create a security worker.
625
+ */
626
+ static createSecurity(name: string, capabilities?: string[]): WorkerDefinition {
627
+ return {
628
+ type: 'security',
629
+ name,
630
+ description: 'Security analysis and vulnerability detection worker',
631
+ capabilities: capabilities ?? ['vulnerability-scan', 'threat-modeling', 'security-review'],
632
+ maxConcurrentTasks: 3,
633
+ timeout: 90000,
634
+ priority: 80,
635
+ };
636
+ }
637
+
638
+ /**
639
+ * Create a performance worker.
640
+ */
641
+ static createPerformance(name: string, capabilities?: string[]): WorkerDefinition {
642
+ return {
643
+ type: 'performance',
644
+ name,
645
+ description: 'Performance analysis and optimization worker',
646
+ capabilities: capabilities ?? ['profiling', 'bottleneck-detection', 'optimization'],
647
+ maxConcurrentTasks: 2,
648
+ timeout: 120000,
649
+ priority: 65,
650
+ };
651
+ }
652
+
653
+ /**
654
+ * Create a specialized worker.
655
+ */
656
+ static createSpecialized(
657
+ name: string,
658
+ capabilities: string[],
659
+ options?: Partial<Omit<WorkerDefinition, 'type' | 'name' | 'capabilities'>>
660
+ ): WorkerDefinition {
661
+ return {
662
+ type: 'specialized',
663
+ name,
664
+ capabilities,
665
+ maxConcurrentTasks: options?.maxConcurrentTasks ?? 3,
666
+ timeout: options?.timeout ?? 60000,
667
+ priority: options?.priority ?? 50,
668
+ description: options?.description,
669
+ specialization: options?.specialization,
670
+ metadata: options?.metadata,
671
+ };
672
+ }
673
+
674
+ /**
675
+ * Create a long-running worker.
676
+ */
677
+ static createLongRunning(
678
+ name: string,
679
+ capabilities: string[],
680
+ options?: Partial<Omit<WorkerDefinition, 'type' | 'name' | 'capabilities'>>
681
+ ): WorkerDefinition {
682
+ return {
683
+ type: 'long-running',
684
+ name,
685
+ capabilities,
686
+ maxConcurrentTasks: 1,
687
+ timeout: options?.timeout ?? 3600000, // 1 hour default
688
+ priority: options?.priority ?? 30,
689
+ description: options?.description ?? 'Long-running background worker',
690
+ specialization: options?.specialization,
691
+ metadata: options?.metadata,
692
+ };
693
+ }
694
+ }
695
+
696
+ // ============================================================================
697
+ // Exports
698
+ // ============================================================================
699
+
700
+ export type { WorkerDefinition, WorkerType, WorkerResult, WorkerMetrics, WorkerHealth };
package/tmp.json ADDED
File without changes