cmp-standards 2.7.0 → 2.8.0
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 +633 -633
- package/dist/cache/EmbeddingCache.d.ts +110 -0
- package/dist/cache/EmbeddingCache.d.ts.map +1 -0
- package/dist/cache/EmbeddingCache.js +239 -0
- package/dist/cache/EmbeddingCache.js.map +1 -0
- package/dist/cache/index.d.ts +6 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +6 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cli/index.js +0 -0
- package/dist/db/cloud.d.ts +1 -0
- package/dist/db/cloud.d.ts.map +1 -1
- package/dist/db/drizzle-client.d.ts +10 -1
- package/dist/db/drizzle-client.d.ts.map +1 -1
- package/dist/db/drizzle-client.js +57 -3
- package/dist/db/drizzle-client.js.map +1 -1
- package/dist/db/errors.d.ts +13 -1
- package/dist/db/errors.d.ts.map +1 -1
- package/dist/db/errors.js +49 -5
- package/dist/db/errors.js.map +1 -1
- package/dist/db/migrations.d.ts +42 -0
- package/dist/db/migrations.d.ts.map +1 -0
- package/dist/db/migrations.js +173 -0
- package/dist/db/migrations.js.map +1 -0
- package/dist/db/turso-client.d.ts +15 -3
- package/dist/db/turso-client.d.ts.map +1 -1
- package/dist/db/turso-client.js +50 -39
- package/dist/db/turso-client.js.map +1 -1
- package/dist/eslint/rules/no-async-useeffect.js +6 -6
- package/dist/events/EventBus.d.ts +97 -0
- package/dist/events/EventBus.d.ts.map +1 -0
- package/dist/events/EventBus.js +256 -0
- package/dist/events/EventBus.js.map +1 -0
- package/dist/events/index.d.ts +7 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +9 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/types.d.ts +989 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/events/types.js +136 -0
- package/dist/events/types.js.map +1 -0
- package/dist/experts/ConsensusEngine.d.ts +57 -0
- package/dist/experts/ConsensusEngine.d.ts.map +1 -0
- package/dist/experts/ConsensusEngine.js +146 -0
- package/dist/experts/ConsensusEngine.js.map +1 -0
- package/dist/experts/ExpertPanelService.d.ts +84 -0
- package/dist/experts/ExpertPanelService.d.ts.map +1 -0
- package/dist/experts/ExpertPanelService.js +204 -0
- package/dist/experts/ExpertPanelService.js.map +1 -0
- package/dist/experts/ExpertRouter.d.ts +68 -0
- package/dist/experts/ExpertRouter.d.ts.map +1 -0
- package/dist/experts/ExpertRouter.js +374 -0
- package/dist/experts/ExpertRouter.js.map +1 -0
- package/dist/experts/VoteCollector.d.ts +58 -0
- package/dist/experts/VoteCollector.d.ts.map +1 -0
- package/dist/experts/VoteCollector.js +146 -0
- package/dist/experts/VoteCollector.js.map +1 -0
- package/dist/experts/index.d.ts +9 -0
- package/dist/experts/index.d.ts.map +1 -0
- package/dist/experts/index.js +13 -0
- package/dist/experts/index.js.map +1 -0
- package/dist/hooks/cloud-pre-tool-use.js +20 -20
- package/dist/hooks/expert-review.d.ts +74 -0
- package/dist/hooks/expert-review.d.ts.map +1 -0
- package/dist/hooks/expert-review.js +220 -0
- package/dist/hooks/expert-review.js.map +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +450 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +50 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/mcp/schemas.d.ts +278 -0
- package/dist/mcp/schemas.d.ts.map +1 -0
- package/dist/mcp/schemas.js +166 -0
- package/dist/mcp/schemas.js.map +1 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +14 -3
- package/dist/mcp/server.js.map +1 -1
- package/dist/patterns/feedback-loop.d.ts +264 -0
- package/dist/patterns/feedback-loop.d.ts.map +1 -0
- package/dist/patterns/feedback-loop.js +329 -0
- package/dist/patterns/feedback-loop.js.map +1 -0
- package/dist/patterns/index.d.ts +9 -0
- package/dist/patterns/index.d.ts.map +1 -0
- package/dist/patterns/index.js +9 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/patterns/lifecycle.d.ts +88 -0
- package/dist/patterns/lifecycle.d.ts.map +1 -0
- package/dist/patterns/lifecycle.js +284 -0
- package/dist/patterns/lifecycle.js.map +1 -0
- package/dist/patterns/registry.d.ts +142 -0
- package/dist/patterns/registry.d.ts.map +1 -0
- package/dist/patterns/registry.js +442 -0
- package/dist/patterns/registry.js.map +1 -0
- package/dist/performance/Debouncer.d.ts +91 -0
- package/dist/performance/Debouncer.d.ts.map +1 -0
- package/dist/performance/Debouncer.js +198 -0
- package/dist/performance/Debouncer.js.map +1 -0
- package/dist/performance/MemoryDecay.d.ts +82 -0
- package/dist/performance/MemoryDecay.d.ts.map +1 -0
- package/dist/performance/MemoryDecay.js +153 -0
- package/dist/performance/MemoryDecay.js.map +1 -0
- package/dist/performance/index.d.ts +7 -0
- package/dist/performance/index.d.ts.map +1 -0
- package/dist/performance/index.js +9 -0
- package/dist/performance/index.js.map +1 -0
- package/dist/schema/expert-types.d.ts +395 -0
- package/dist/schema/expert-types.d.ts.map +1 -0
- package/dist/schema/expert-types.js +250 -0
- package/dist/schema/expert-types.js.map +1 -0
- package/dist/services/ContextGenerator.js +7 -7
- package/dist/services/PlanManager.d.ts +1 -1
- package/dist/services/PlanManager.d.ts.map +1 -1
- package/dist/services/PlanManager.js +26 -6
- package/dist/services/PlanManager.js.map +1 -1
- package/dist/services/ProjectScaffold.js +76 -76
- package/dist/services/memory-router.js +35 -35
- package/dist/services/pattern-tracker.js +90 -90
- package/dist/services/semantic-search.js +2 -2
- package/package.json +105 -104
- package/standards/README.md +50 -50
- package/standards/experts/expert-routing.md +215 -215
- package/standards/general/code-quality.md +86 -86
- package/standards/general/memory-usage.md +205 -205
- package/standards/general/sync-workflow.md +235 -235
- package/standards/general/workflow.md +82 -82
- package/standards/hooks/mandatory-tracking.md +446 -446
- package/standards/infrastructure/cloud-database.md +287 -287
- package/standards/mcp/server-design.md +243 -243
- package/standards/mcp/tool-patterns.md +354 -354
- package/standards/skills/skill-structure.md +286 -286
- package/standards/skills/workflow-design.md +323 -323
- package/standards/tools/tool-design.md +297 -297
- package/templates/agents/architecture-expert.md +61 -61
- package/templates/agents/database-expert.md +62 -62
- package/templates/agents/documentation-expert.md +57 -57
- package/templates/agents/memory-expert.md +88 -88
- package/templates/agents/performance-expert.md +61 -61
- package/templates/agents/security-expert.md +59 -59
- package/templates/agents/ux-expert.md +63 -63
- package/templates/agents/worker.md +75 -75
- package/templates/ai-skills/SKILL_TEMPLATE.md +55 -55
- package/templates/claude-settings.json +72 -72
- package/templates/commands/experts.md +138 -138
- package/templates/hooks/README.md +158 -158
- package/templates/hooks/project.config.json.template +77 -77
- package/templates/hooks/settings.local.json.template +57 -57
- package/templates/memory-config.json +56 -56
- package/templates/memory-config.schema.json +212 -212
- package/templates/settings.json +58 -58
- package/templates/skills/continue.md +205 -205
- package/templates/workflows/business-improvement.md +264 -264
- package/templates/workflows/expert-review.md +153 -153
- package/templates/workflows/internal-app.md +245 -245
- package/templates/workflows/sync-docs.md +187 -187
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file EventBus - In-memory event bus for cmp-standards v2.8
|
|
3
|
+
* @description Decoupled event-driven architecture for expert panel orchestration
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* - Type-safe event publishing and subscribing
|
|
7
|
+
* - Parallel handler execution with Promise.allSettled
|
|
8
|
+
* - Event history for debugging
|
|
9
|
+
* - Handler timeout protection
|
|
10
|
+
* - Correlation ID tracking for request tracing
|
|
11
|
+
*/
|
|
12
|
+
import { Event, EventType, EventHandler } from './types.js';
|
|
13
|
+
export interface EventBusConfig {
|
|
14
|
+
/** Maximum events to keep in history */
|
|
15
|
+
historyLimit: number;
|
|
16
|
+
/** Handler execution timeout in ms */
|
|
17
|
+
handlerTimeout: number;
|
|
18
|
+
/** Enable debug logging */
|
|
19
|
+
debug: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare class EventBus {
|
|
22
|
+
private handlers;
|
|
23
|
+
private history;
|
|
24
|
+
private config;
|
|
25
|
+
private handlerLastUsed;
|
|
26
|
+
private cleanupInterval;
|
|
27
|
+
constructor(config?: Partial<EventBusConfig>);
|
|
28
|
+
/**
|
|
29
|
+
* Cleanup stale handlers (not used in 30 minutes)
|
|
30
|
+
*/
|
|
31
|
+
private cleanupStaleHandlers;
|
|
32
|
+
/**
|
|
33
|
+
* Stop the cleanup interval (for cleanup on shutdown)
|
|
34
|
+
*/
|
|
35
|
+
destroy(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Subscribe to an event type
|
|
38
|
+
* @returns Unsubscribe function
|
|
39
|
+
*/
|
|
40
|
+
subscribe<T extends EventType>(eventType: T, handler: EventHandler<Extract<Event, {
|
|
41
|
+
type: T;
|
|
42
|
+
}>>): () => void;
|
|
43
|
+
/**
|
|
44
|
+
* Publish an event to all subscribers
|
|
45
|
+
* Handlers are executed in parallel with timeout protection
|
|
46
|
+
*/
|
|
47
|
+
publish<T extends Event>(event: T): Promise<{
|
|
48
|
+
success: boolean;
|
|
49
|
+
handlerResults: PromiseSettledResult<void>[];
|
|
50
|
+
duration: number;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Publish and wait for all handlers, throwing on any failure
|
|
54
|
+
*/
|
|
55
|
+
publishStrict<T extends Event>(event: T): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Execute handler with timeout protection
|
|
58
|
+
*/
|
|
59
|
+
private executeWithTimeout;
|
|
60
|
+
/**
|
|
61
|
+
* Add event to history with limit enforcement
|
|
62
|
+
*/
|
|
63
|
+
private addToHistory;
|
|
64
|
+
/**
|
|
65
|
+
* Get event history, optionally filtered by type
|
|
66
|
+
*/
|
|
67
|
+
getHistory(type?: EventType): Event[];
|
|
68
|
+
/**
|
|
69
|
+
* Get events by correlation ID (for request tracing)
|
|
70
|
+
*/
|
|
71
|
+
getByCorrelationId(correlationId: string): Event[];
|
|
72
|
+
/**
|
|
73
|
+
* Clear all handlers and history
|
|
74
|
+
*/
|
|
75
|
+
clear(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Get handler count for a specific event type
|
|
78
|
+
*/
|
|
79
|
+
getHandlerCount(type: EventType): number;
|
|
80
|
+
/**
|
|
81
|
+
* Check if there are any handlers for an event type
|
|
82
|
+
*/
|
|
83
|
+
hasHandlers(type: EventType): boolean;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get or create the global EventBus instance
|
|
87
|
+
*/
|
|
88
|
+
export declare function getEventBus(config?: Partial<EventBusConfig>): EventBus;
|
|
89
|
+
/**
|
|
90
|
+
* Reset the global EventBus (useful for testing)
|
|
91
|
+
*/
|
|
92
|
+
export declare function resetEventBus(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Create and publish an event in one call
|
|
95
|
+
*/
|
|
96
|
+
export declare function emitEvent(eventData: Omit<Event, 'metadata'>, source: string, correlationId?: string): Promise<void>;
|
|
97
|
+
//# sourceMappingURL=EventBus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventBus.d.ts","sourceRoot":"","sources":["../../src/events/EventBus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,KAAK,EACL,SAAS,EACT,YAAY,EAGb,MAAM,YAAY,CAAA;AAMnB,MAAM,WAAW,cAAc;IAC7B,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAA;IACpB,sCAAsC;IACtC,cAAc,EAAE,MAAM,CAAA;IACtB,2BAA2B;IAC3B,KAAK,EAAE,OAAO,CAAA;CACf;AAYD,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAsB;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,QAAQ,CAKtE;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAKpC;AAMD;;GAEG;AACH,wBAAsB,SAAS,CAC7B,SAAS,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,EAClC,MAAM,EAAE,MAAM,EACd,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC,CAQf"}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file EventBus - In-memory event bus for cmp-standards v2.8
|
|
3
|
+
* @description Decoupled event-driven architecture for expert panel orchestration
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* - Type-safe event publishing and subscribing
|
|
7
|
+
* - Parallel handler execution with Promise.allSettled
|
|
8
|
+
* - Event history for debugging
|
|
9
|
+
* - Handler timeout protection
|
|
10
|
+
* - Correlation ID tracking for request tracing
|
|
11
|
+
*/
|
|
12
|
+
import { createEventMetadata, } from './types.js';
|
|
13
|
+
const DEFAULT_CONFIG = {
|
|
14
|
+
historyLimit: 100,
|
|
15
|
+
handlerTimeout: 5000,
|
|
16
|
+
debug: false,
|
|
17
|
+
};
|
|
18
|
+
// =============================================================================
|
|
19
|
+
// EventBus Implementation
|
|
20
|
+
// =============================================================================
|
|
21
|
+
export class EventBus {
|
|
22
|
+
handlers = {};
|
|
23
|
+
history = [];
|
|
24
|
+
config;
|
|
25
|
+
handlerLastUsed = new Map(); // Track handler activity
|
|
26
|
+
cleanupInterval = null;
|
|
27
|
+
constructor(config = {}) {
|
|
28
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
29
|
+
// Start auto-cleanup every 5 minutes
|
|
30
|
+
this.cleanupInterval = setInterval(() => {
|
|
31
|
+
this.cleanupStaleHandlers();
|
|
32
|
+
}, 5 * 60 * 1000);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Cleanup stale handlers (not used in 30 minutes)
|
|
36
|
+
*/
|
|
37
|
+
cleanupStaleHandlers() {
|
|
38
|
+
const now = Date.now();
|
|
39
|
+
const staleThreshold = 30 * 60 * 1000; // 30 minutes
|
|
40
|
+
let removed = 0;
|
|
41
|
+
for (const [handlerId, lastUsed] of this.handlerLastUsed) {
|
|
42
|
+
if (now - lastUsed > staleThreshold) {
|
|
43
|
+
// Remove handler from all event types
|
|
44
|
+
for (const eventType of Object.keys(this.handlers)) {
|
|
45
|
+
const handlers = this.handlers[eventType];
|
|
46
|
+
if (handlers) {
|
|
47
|
+
const idx = handlers.findIndex((h) => h._id === handlerId);
|
|
48
|
+
if (idx > -1) {
|
|
49
|
+
handlers.splice(idx, 1);
|
|
50
|
+
removed++;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
this.handlerLastUsed.delete(handlerId);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (this.config.debug && removed > 0) {
|
|
58
|
+
console.log(`[EventBus] Cleaned up ${removed} stale handlers`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Stop the cleanup interval (for cleanup on shutdown)
|
|
63
|
+
*/
|
|
64
|
+
destroy() {
|
|
65
|
+
if (this.cleanupInterval) {
|
|
66
|
+
clearInterval(this.cleanupInterval);
|
|
67
|
+
this.cleanupInterval = null;
|
|
68
|
+
}
|
|
69
|
+
this.clear();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Subscribe to an event type
|
|
73
|
+
* @returns Unsubscribe function
|
|
74
|
+
*/
|
|
75
|
+
subscribe(eventType, handler) {
|
|
76
|
+
if (!this.handlers[eventType]) {
|
|
77
|
+
this.handlers[eventType] = [];
|
|
78
|
+
}
|
|
79
|
+
// Add unique ID for tracking
|
|
80
|
+
const handlerId = Symbol('handler');
|
|
81
|
+
handler._id = handlerId;
|
|
82
|
+
this.handlerLastUsed.set(handlerId, Date.now());
|
|
83
|
+
// Type assertion needed due to TypeScript limitations with mapped types
|
|
84
|
+
const handlers = this.handlers[eventType];
|
|
85
|
+
handlers.push(handler);
|
|
86
|
+
if (this.config.debug) {
|
|
87
|
+
console.log(`[EventBus] Subscribed to ${eventType}`);
|
|
88
|
+
}
|
|
89
|
+
// Return unsubscribe function
|
|
90
|
+
return () => {
|
|
91
|
+
const index = handlers.indexOf(handler);
|
|
92
|
+
if (index > -1) {
|
|
93
|
+
handlers.splice(index, 1);
|
|
94
|
+
this.handlerLastUsed.delete(handlerId);
|
|
95
|
+
if (this.config.debug) {
|
|
96
|
+
console.log(`[EventBus] Unsubscribed from ${eventType}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Publish an event to all subscribers
|
|
103
|
+
* Handlers are executed in parallel with timeout protection
|
|
104
|
+
*/
|
|
105
|
+
async publish(event) {
|
|
106
|
+
const startTime = Date.now();
|
|
107
|
+
// Add to history
|
|
108
|
+
this.addToHistory(event);
|
|
109
|
+
const handlers = this.handlers[event.type];
|
|
110
|
+
if (!handlers || handlers.length === 0) {
|
|
111
|
+
if (this.config.debug) {
|
|
112
|
+
console.log(`[EventBus] No handlers for ${event.type}`);
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
success: true,
|
|
116
|
+
handlerResults: [],
|
|
117
|
+
duration: Date.now() - startTime,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (this.config.debug) {
|
|
121
|
+
console.log(`[EventBus] Publishing ${event.type} to ${handlers.length} handlers`);
|
|
122
|
+
}
|
|
123
|
+
// Execute all handlers in parallel with timeout
|
|
124
|
+
const handlerPromises = handlers.map(handler => {
|
|
125
|
+
// Update last used time
|
|
126
|
+
const handlerId = handler._id;
|
|
127
|
+
if (handlerId) {
|
|
128
|
+
this.handlerLastUsed.set(handlerId, Date.now());
|
|
129
|
+
}
|
|
130
|
+
return this.executeWithTimeout(handler, event);
|
|
131
|
+
});
|
|
132
|
+
const results = await Promise.allSettled(handlerPromises);
|
|
133
|
+
const failedCount = results.filter(r => r.status === 'rejected').length;
|
|
134
|
+
const duration = Date.now() - startTime;
|
|
135
|
+
if (this.config.debug) {
|
|
136
|
+
console.log(`[EventBus] ${event.type} completed in ${duration}ms ` +
|
|
137
|
+
`(${handlers.length - failedCount}/${handlers.length} succeeded)`);
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
success: failedCount === 0,
|
|
141
|
+
handlerResults: results,
|
|
142
|
+
duration,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Publish and wait for all handlers, throwing on any failure
|
|
147
|
+
*/
|
|
148
|
+
async publishStrict(event) {
|
|
149
|
+
const result = await this.publish(event);
|
|
150
|
+
if (!result.success) {
|
|
151
|
+
const errors = result.handlerResults
|
|
152
|
+
.filter((r) => r.status === 'rejected')
|
|
153
|
+
.map(r => r.reason);
|
|
154
|
+
throw new AggregateError(errors, `Event ${event.type} failed with ${errors.length} handler errors`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Execute handler with timeout protection
|
|
159
|
+
*/
|
|
160
|
+
async executeWithTimeout(handler, event) {
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
const timeoutId = setTimeout(() => {
|
|
163
|
+
reject(new Error(`Handler timeout after ${this.config.handlerTimeout}ms`));
|
|
164
|
+
}, this.config.handlerTimeout);
|
|
165
|
+
Promise.resolve(handler(event))
|
|
166
|
+
.then(() => {
|
|
167
|
+
clearTimeout(timeoutId);
|
|
168
|
+
resolve();
|
|
169
|
+
})
|
|
170
|
+
.catch(error => {
|
|
171
|
+
clearTimeout(timeoutId);
|
|
172
|
+
reject(error);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Add event to history with limit enforcement
|
|
178
|
+
*/
|
|
179
|
+
addToHistory(event) {
|
|
180
|
+
this.history.push(event);
|
|
181
|
+
if (this.history.length > this.config.historyLimit) {
|
|
182
|
+
this.history.shift();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get event history, optionally filtered by type
|
|
187
|
+
*/
|
|
188
|
+
getHistory(type) {
|
|
189
|
+
if (!type)
|
|
190
|
+
return [...this.history];
|
|
191
|
+
return this.history.filter(e => e.type === type);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get events by correlation ID (for request tracing)
|
|
195
|
+
*/
|
|
196
|
+
getByCorrelationId(correlationId) {
|
|
197
|
+
return this.history.filter(e => e.metadata.correlationId === correlationId);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Clear all handlers and history
|
|
201
|
+
*/
|
|
202
|
+
clear() {
|
|
203
|
+
this.handlers = {};
|
|
204
|
+
this.history = [];
|
|
205
|
+
this.handlerLastUsed.clear();
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Get handler count for a specific event type
|
|
209
|
+
*/
|
|
210
|
+
getHandlerCount(type) {
|
|
211
|
+
return this.handlers[type]?.length ?? 0;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Check if there are any handlers for an event type
|
|
215
|
+
*/
|
|
216
|
+
hasHandlers(type) {
|
|
217
|
+
return this.getHandlerCount(type) > 0;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// =============================================================================
|
|
221
|
+
// Singleton Instance
|
|
222
|
+
// =============================================================================
|
|
223
|
+
let globalEventBus = null;
|
|
224
|
+
/**
|
|
225
|
+
* Get or create the global EventBus instance
|
|
226
|
+
*/
|
|
227
|
+
export function getEventBus(config) {
|
|
228
|
+
if (!globalEventBus) {
|
|
229
|
+
globalEventBus = new EventBus(config);
|
|
230
|
+
}
|
|
231
|
+
return globalEventBus;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Reset the global EventBus (useful for testing)
|
|
235
|
+
*/
|
|
236
|
+
export function resetEventBus() {
|
|
237
|
+
if (globalEventBus) {
|
|
238
|
+
globalEventBus.clear();
|
|
239
|
+
}
|
|
240
|
+
globalEventBus = null;
|
|
241
|
+
}
|
|
242
|
+
// =============================================================================
|
|
243
|
+
// Helper Functions
|
|
244
|
+
// =============================================================================
|
|
245
|
+
/**
|
|
246
|
+
* Create and publish an event in one call
|
|
247
|
+
*/
|
|
248
|
+
export async function emitEvent(eventData, source, correlationId) {
|
|
249
|
+
const bus = getEventBus();
|
|
250
|
+
const event = {
|
|
251
|
+
...eventData,
|
|
252
|
+
metadata: createEventMetadata(source, correlationId),
|
|
253
|
+
};
|
|
254
|
+
await bus.publish(event);
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=EventBus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventBus.js","sourceRoot":"","sources":["../../src/events/EventBus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAKL,mBAAmB,GACpB,MAAM,YAAY,CAAA;AAenB,MAAM,cAAc,GAAmB;IACrC,YAAY,EAAE,GAAG;IACjB,cAAc,EAAE,IAAI;IACpB,KAAK,EAAE,KAAK;CACb,CAAA;AAED,gFAAgF;AAChF,0BAA0B;AAC1B,gFAAgF;AAEhF,MAAM,OAAO,QAAQ;IACX,QAAQ,GAAoB,EAAE,CAAA;IAC9B,OAAO,GAAY,EAAE,CAAA;IACrB,MAAM,CAAgB;IACtB,eAAe,GAAG,IAAI,GAAG,EAAkB,CAAA,CAAE,yBAAyB;IACtE,eAAe,GAA0C,IAAI,CAAA;IAErE,YAAY,SAAkC,EAAE;QAC9C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAA;QAE9C,qCAAqC;QACrC,IAAI,CAAC,eAAe,GAAG,WAAW,CAAC,GAAG,EAAE;YACtC,IAAI,CAAC,oBAAoB,EAAE,CAAA;QAC7B,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IACnB,CA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AA;IAC9B,CAAC;IAED;;OAEG;IACH,eAAe,CAAC,IAAe;QAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC,CAAA;IACzC,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,IAAe;QACzB,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACvC,CAAC;CACF;AAED,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAEhF,IAAI,cAAc,GAAoB,IAAI,CAAA;AAE1C;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,MAAgC;IAC1D,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,cAAc,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAA;IACvC,CAAC;IACD,OAAO,cAAc,CAAA;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,IAAI,cAAc,EAAE,CAAC;QACnB,cAAc,CAAC,KAAK,EAAE,CAAA;IACxB,CAAC;IACD,cAAc,GAAG,IAAI,CAAA;AACvB,CAAC;AAED,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,SAAkC,EAClC,MAAc,EACd,aAAsB;IAEtB,MAAM,GAAG,GAAG,WAAW,EAAE,CAAA;IACzB,MAAM,KAAK,GAAG;QACZ,GAAG,SAAS;QACZ,QAAQ,EAAE,mBAAmB,CAAC,MAAM,EAAE,aAAa,CAAC;KACjC,CAAA;IAErB,MAAM,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC1B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Events Module - cmp-standards v2.8
|
|
3
|
+
* @description Event-driven architecture for expert panel orchestration
|
|
4
|
+
*/
|
|
5
|
+
export * from './types.js';
|
|
6
|
+
export { EventBus, EventBusConfig, getEventBus, resetEventBus, emitEvent, } from './EventBus.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,YAAY,CAAA;AAG1B,OAAO,EACL,QAAQ,EACR,cAAc,EACd,WAAW,EACX,aAAa,EACb,SAAS,GACV,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Events Module - cmp-standards v2.8
|
|
3
|
+
* @description Event-driven architecture for expert panel orchestration
|
|
4
|
+
*/
|
|
5
|
+
// Types
|
|
6
|
+
export * from './types.js';
|
|
7
|
+
// EventBus
|
|
8
|
+
export { EventBus, getEventBus, resetEventBus, emitEvent, } from './EventBus.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,QAAQ;AACR,cAAc,YAAY,CAAA;AAE1B,WAAW;AACX,OAAO,EACL,QAAQ,EAER,WAAW,EACX,aAAa,EACb,SAAS,GACV,MAAM,eAAe,CAAA"}
|