moflo 4.8.19 → 4.8.20
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/.claude/guidance/shipped/moflo.md +45 -0
- package/.claude/helpers/statusline.cjs +1 -1
- package/.claude/workflow-state.json +9 -0
- package/package.json +2 -2
- package/src/@claude-flow/cli/dist/src/init/statusline-generator.js +1 -1
- package/src/@claude-flow/cli/dist/src/services/agentic-flow-bridge.js +5 -3
- package/src/@claude-flow/cli/package.json +1 -1
- package/src/@claude-flow/memory/dist/agent-memory-scope.d.ts +131 -0
- package/src/@claude-flow/memory/dist/agent-memory-scope.js +223 -0
- package/src/@claude-flow/memory/dist/agent-memory-scope.test.d.ts +8 -0
- package/src/@claude-flow/memory/dist/agent-memory-scope.test.js +466 -0
- package/src/@claude-flow/memory/dist/agentdb-adapter.d.ts +165 -0
- package/src/@claude-flow/memory/dist/agentdb-adapter.js +806 -0
- package/src/@claude-flow/memory/dist/agentdb-backend.d.ts +212 -0
- package/src/@claude-flow/memory/dist/agentdb-backend.js +842 -0
- package/src/@claude-flow/memory/dist/agentdb-backend.test.d.ts +7 -0
- package/src/@claude-flow/memory/dist/agentdb-backend.test.js +258 -0
- package/src/@claude-flow/memory/dist/application/commands/delete-memory.command.d.ts +65 -0
- package/src/@claude-flow/memory/dist/application/commands/delete-memory.command.js +129 -0
- package/src/@claude-flow/memory/dist/application/commands/store-memory.command.d.ts +48 -0
- package/src/@claude-flow/memory/dist/application/commands/store-memory.command.js +72 -0
- package/src/@claude-flow/memory/dist/application/index.d.ts +12 -0
- package/src/@claude-flow/memory/dist/application/index.js +15 -0
- package/src/@claude-flow/memory/dist/application/queries/search-memory.query.d.ts +72 -0
- package/src/@claude-flow/memory/dist/application/queries/search-memory.query.js +143 -0
- package/src/@claude-flow/memory/dist/application/services/memory-application-service.d.ts +121 -0
- package/src/@claude-flow/memory/dist/application/services/memory-application-service.js +190 -0
- package/src/@claude-flow/memory/dist/auto-memory-bridge.d.ts +226 -0
- package/src/@claude-flow/memory/dist/auto-memory-bridge.js +709 -0
- package/src/@claude-flow/memory/dist/auto-memory-bridge.test.d.ts +8 -0
- package/src/@claude-flow/memory/dist/auto-memory-bridge.test.js +757 -0
- package/src/@claude-flow/memory/dist/benchmark.test.d.ts +2 -0
- package/src/@claude-flow/memory/dist/benchmark.test.js +277 -0
- package/src/@claude-flow/memory/dist/cache-manager.d.ts +134 -0
- package/src/@claude-flow/memory/dist/cache-manager.js +407 -0
- package/src/@claude-flow/memory/dist/controller-registry.d.ts +216 -0
- package/src/@claude-flow/memory/dist/controller-registry.js +893 -0
- package/src/@claude-flow/memory/dist/controller-registry.test.d.ts +14 -0
- package/src/@claude-flow/memory/dist/controller-registry.test.js +593 -0
- package/src/@claude-flow/memory/dist/database-provider.d.ts +87 -0
- package/src/@claude-flow/memory/dist/database-provider.js +372 -0
- package/src/@claude-flow/memory/dist/database-provider.test.d.ts +7 -0
- package/src/@claude-flow/memory/dist/database-provider.test.js +287 -0
- package/src/@claude-flow/memory/dist/domain/entities/memory-entry.d.ts +143 -0
- package/src/@claude-flow/memory/dist/domain/entities/memory-entry.js +226 -0
- package/src/@claude-flow/memory/dist/domain/index.d.ts +11 -0
- package/src/@claude-flow/memory/dist/domain/index.js +12 -0
- package/src/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.d.ts +102 -0
- package/src/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.js +11 -0
- package/src/@claude-flow/memory/dist/domain/services/memory-domain-service.d.ts +105 -0
- package/src/@claude-flow/memory/dist/domain/services/memory-domain-service.js +297 -0
- package/src/@claude-flow/memory/dist/hnsw-index.d.ts +111 -0
- package/src/@claude-flow/memory/dist/hnsw-index.js +781 -0
- package/src/@claude-flow/memory/dist/hnsw-lite.d.ts +23 -0
- package/src/@claude-flow/memory/dist/hnsw-lite.js +168 -0
- package/src/@claude-flow/memory/dist/index.d.ts +204 -0
- package/src/@claude-flow/memory/dist/index.js +358 -0
- package/src/@claude-flow/memory/dist/infrastructure/index.d.ts +17 -0
- package/src/@claude-flow/memory/dist/infrastructure/index.js +16 -0
- package/src/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.d.ts +66 -0
- package/src/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.js +409 -0
- package/src/@claude-flow/memory/dist/learning-bridge.d.ts +137 -0
- package/src/@claude-flow/memory/dist/learning-bridge.js +335 -0
- package/src/@claude-flow/memory/dist/learning-bridge.test.d.ts +8 -0
- package/src/@claude-flow/memory/dist/learning-bridge.test.js +578 -0
- package/src/@claude-flow/memory/dist/memory-graph.d.ts +100 -0
- package/src/@claude-flow/memory/dist/memory-graph.js +333 -0
- package/src/@claude-flow/memory/dist/memory-graph.test.d.ts +8 -0
- package/src/@claude-flow/memory/dist/memory-graph.test.js +609 -0
- package/src/@claude-flow/memory/dist/migration.d.ts +68 -0
- package/src/@claude-flow/memory/dist/migration.js +513 -0
- package/src/@claude-flow/memory/dist/persistent-sona.d.ts +144 -0
- package/src/@claude-flow/memory/dist/persistent-sona.js +332 -0
- package/src/@claude-flow/memory/dist/query-builder.d.ts +211 -0
- package/src/@claude-flow/memory/dist/query-builder.js +438 -0
- package/src/@claude-flow/memory/dist/rvf-backend.d.ts +51 -0
- package/src/@claude-flow/memory/dist/rvf-backend.js +481 -0
- package/src/@claude-flow/memory/dist/rvf-learning-store.d.ts +139 -0
- package/src/@claude-flow/memory/dist/rvf-learning-store.js +295 -0
- package/src/@claude-flow/memory/dist/rvf-migration.d.ts +45 -0
- package/src/@claude-flow/memory/dist/rvf-migration.js +234 -0
- package/src/@claude-flow/memory/dist/sqljs-backend.d.ts +127 -0
- package/src/@claude-flow/memory/dist/sqljs-backend.js +600 -0
- package/src/@claude-flow/memory/dist/types.d.ts +484 -0
- package/src/@claude-flow/memory/dist/types.js +58 -0
- package/src/@claude-flow/shared/dist/core/config/defaults.d.ts +41 -0
- package/src/@claude-flow/shared/dist/core/config/defaults.js +186 -0
- package/src/@claude-flow/shared/dist/core/config/index.d.ts +8 -0
- package/src/@claude-flow/shared/dist/core/config/index.js +12 -0
- package/src/@claude-flow/shared/dist/core/config/loader.d.ts +45 -0
- package/src/@claude-flow/shared/dist/core/config/loader.js +222 -0
- package/src/@claude-flow/shared/dist/core/config/schema.d.ts +1134 -0
- package/src/@claude-flow/shared/dist/core/config/schema.js +158 -0
- package/src/@claude-flow/shared/dist/core/config/validator.d.ts +92 -0
- package/src/@claude-flow/shared/dist/core/config/validator.js +147 -0
- package/src/@claude-flow/shared/dist/core/event-bus.d.ts +31 -0
- package/src/@claude-flow/shared/dist/core/event-bus.js +197 -0
- package/src/@claude-flow/shared/dist/core/index.d.ts +15 -0
- package/src/@claude-flow/shared/dist/core/index.js +19 -0
- package/src/@claude-flow/shared/dist/core/interfaces/agent.interface.d.ts +200 -0
- package/src/@claude-flow/shared/dist/core/interfaces/agent.interface.js +6 -0
- package/src/@claude-flow/shared/dist/core/interfaces/coordinator.interface.d.ts +310 -0
- package/src/@claude-flow/shared/dist/core/interfaces/coordinator.interface.js +7 -0
- package/src/@claude-flow/shared/dist/core/interfaces/event.interface.d.ts +224 -0
- package/src/@claude-flow/shared/dist/core/interfaces/event.interface.js +46 -0
- package/src/@claude-flow/shared/dist/core/interfaces/index.d.ts +10 -0
- package/src/@claude-flow/shared/dist/core/interfaces/index.js +15 -0
- package/src/@claude-flow/shared/dist/core/interfaces/memory.interface.d.ts +298 -0
- package/src/@claude-flow/shared/dist/core/interfaces/memory.interface.js +7 -0
- package/src/@claude-flow/shared/dist/core/interfaces/task.interface.d.ts +185 -0
- package/src/@claude-flow/shared/dist/core/interfaces/task.interface.js +6 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/event-coordinator.d.ts +35 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/event-coordinator.js +101 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/health-monitor.d.ts +60 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/health-monitor.js +166 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/index.d.ts +46 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/index.js +64 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.d.ts +56 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.js +195 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/session-manager.d.ts +83 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/session-manager.js +193 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/task-manager.d.ts +49 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/task-manager.js +253 -0
- package/src/@claude-flow/shared/dist/events/domain-events.d.ts +282 -0
- package/src/@claude-flow/shared/dist/events/domain-events.js +165 -0
- package/src/@claude-flow/shared/dist/events/event-store.d.ts +126 -0
- package/src/@claude-flow/shared/dist/events/event-store.js +432 -0
- package/src/@claude-flow/shared/dist/events/event-store.test.d.ts +8 -0
- package/src/@claude-flow/shared/dist/events/event-store.test.js +297 -0
- package/src/@claude-flow/shared/dist/events/example-usage.d.ts +10 -0
- package/src/@claude-flow/shared/dist/events/example-usage.js +193 -0
- package/src/@claude-flow/shared/dist/events/index.d.ts +21 -0
- package/src/@claude-flow/shared/dist/events/index.js +22 -0
- package/src/@claude-flow/shared/dist/events/projections.d.ts +177 -0
- package/src/@claude-flow/shared/dist/events/projections.js +421 -0
- package/src/@claude-flow/shared/dist/events/rvf-event-log.d.ts +82 -0
- package/src/@claude-flow/shared/dist/events/rvf-event-log.js +340 -0
- package/src/@claude-flow/shared/dist/events/state-reconstructor.d.ts +101 -0
- package/src/@claude-flow/shared/dist/events/state-reconstructor.js +263 -0
- package/src/@claude-flow/shared/dist/events.d.ts +80 -0
- package/src/@claude-flow/shared/dist/events.js +249 -0
- package/src/@claude-flow/shared/dist/hooks/example-usage.d.ts +42 -0
- package/src/@claude-flow/shared/dist/hooks/example-usage.js +351 -0
- package/src/@claude-flow/shared/dist/hooks/executor.d.ts +100 -0
- package/src/@claude-flow/shared/dist/hooks/executor.js +267 -0
- package/src/@claude-flow/shared/dist/hooks/hooks.test.d.ts +9 -0
- package/src/@claude-flow/shared/dist/hooks/hooks.test.js +322 -0
- package/src/@claude-flow/shared/dist/hooks/index.d.ts +52 -0
- package/src/@claude-flow/shared/dist/hooks/index.js +51 -0
- package/src/@claude-flow/shared/dist/hooks/registry.d.ts +133 -0
- package/src/@claude-flow/shared/dist/hooks/registry.js +277 -0
- package/src/@claude-flow/shared/dist/hooks/safety/bash-safety.d.ts +105 -0
- package/src/@claude-flow/shared/dist/hooks/safety/bash-safety.js +481 -0
- package/src/@claude-flow/shared/dist/hooks/safety/file-organization.d.ts +144 -0
- package/src/@claude-flow/shared/dist/hooks/safety/file-organization.js +328 -0
- package/src/@claude-flow/shared/dist/hooks/safety/git-commit.d.ts +158 -0
- package/src/@claude-flow/shared/dist/hooks/safety/git-commit.js +450 -0
- package/src/@claude-flow/shared/dist/hooks/safety/index.d.ts +17 -0
- package/src/@claude-flow/shared/dist/hooks/safety/index.js +17 -0
- package/src/@claude-flow/shared/dist/hooks/session-hooks.d.ts +234 -0
- package/src/@claude-flow/shared/dist/hooks/session-hooks.js +334 -0
- package/src/@claude-flow/shared/dist/hooks/task-hooks.d.ts +163 -0
- package/src/@claude-flow/shared/dist/hooks/task-hooks.js +326 -0
- package/src/@claude-flow/shared/dist/hooks/types.d.ts +267 -0
- package/src/@claude-flow/shared/dist/hooks/types.js +62 -0
- package/src/@claude-flow/shared/dist/hooks/verify-exports.test.d.ts +9 -0
- package/src/@claude-flow/shared/dist/hooks/verify-exports.test.js +93 -0
- package/src/@claude-flow/shared/dist/index.d.ts +20 -0
- package/src/@claude-flow/shared/dist/index.js +50 -0
- package/src/@claude-flow/shared/dist/mcp/connection-pool.d.ts +98 -0
- package/src/@claude-flow/shared/dist/mcp/connection-pool.js +364 -0
- package/src/@claude-flow/shared/dist/mcp/index.d.ts +69 -0
- package/src/@claude-flow/shared/dist/mcp/index.js +84 -0
- package/src/@claude-flow/shared/dist/mcp/server.d.ts +166 -0
- package/src/@claude-flow/shared/dist/mcp/server.js +593 -0
- package/src/@claude-flow/shared/dist/mcp/session-manager.d.ts +136 -0
- package/src/@claude-flow/shared/dist/mcp/session-manager.js +335 -0
- package/src/@claude-flow/shared/dist/mcp/tool-registry.d.ts +178 -0
- package/src/@claude-flow/shared/dist/mcp/tool-registry.js +439 -0
- package/src/@claude-flow/shared/dist/mcp/transport/http.d.ts +104 -0
- package/src/@claude-flow/shared/dist/mcp/transport/http.js +476 -0
- package/src/@claude-flow/shared/dist/mcp/transport/index.d.ts +102 -0
- package/src/@claude-flow/shared/dist/mcp/transport/index.js +238 -0
- package/src/@claude-flow/shared/dist/mcp/transport/stdio.d.ts +104 -0
- package/src/@claude-flow/shared/dist/mcp/transport/stdio.js +263 -0
- package/src/@claude-flow/shared/dist/mcp/transport/websocket.d.ts +133 -0
- package/src/@claude-flow/shared/dist/mcp/transport/websocket.js +396 -0
- package/src/@claude-flow/shared/dist/mcp/types.d.ts +438 -0
- package/src/@claude-flow/shared/dist/mcp/types.js +54 -0
- package/src/@claude-flow/shared/dist/plugin-interface.d.ts +544 -0
- package/src/@claude-flow/shared/dist/plugin-interface.js +23 -0
- package/src/@claude-flow/shared/dist/plugin-loader.d.ts +139 -0
- package/src/@claude-flow/shared/dist/plugin-loader.js +434 -0
- package/src/@claude-flow/shared/dist/plugin-registry.d.ts +183 -0
- package/src/@claude-flow/shared/dist/plugin-registry.js +457 -0
- package/src/@claude-flow/shared/dist/plugins/index.d.ts +10 -0
- package/src/@claude-flow/shared/dist/plugins/index.js +10 -0
- package/src/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.d.ts +106 -0
- package/src/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.js +241 -0
- package/src/@claude-flow/shared/dist/plugins/official/index.d.ts +10 -0
- package/src/@claude-flow/shared/dist/plugins/official/index.js +10 -0
- package/src/@claude-flow/shared/dist/plugins/official/maestro-plugin.d.ts +121 -0
- package/src/@claude-flow/shared/dist/plugins/official/maestro-plugin.js +355 -0
- package/src/@claude-flow/shared/dist/plugins/types.d.ts +93 -0
- package/src/@claude-flow/shared/dist/plugins/types.js +9 -0
- package/src/@claude-flow/shared/dist/resilience/bulkhead.d.ts +105 -0
- package/src/@claude-flow/shared/dist/resilience/bulkhead.js +206 -0
- package/src/@claude-flow/shared/dist/resilience/circuit-breaker.d.ts +132 -0
- package/src/@claude-flow/shared/dist/resilience/circuit-breaker.js +233 -0
- package/src/@claude-flow/shared/dist/resilience/index.d.ts +19 -0
- package/src/@claude-flow/shared/dist/resilience/index.js +19 -0
- package/src/@claude-flow/shared/dist/resilience/rate-limiter.d.ts +168 -0
- package/src/@claude-flow/shared/dist/resilience/rate-limiter.js +314 -0
- package/src/@claude-flow/shared/dist/resilience/retry.d.ts +91 -0
- package/src/@claude-flow/shared/dist/resilience/retry.js +159 -0
- package/src/@claude-flow/shared/dist/security/index.d.ts +10 -0
- package/src/@claude-flow/shared/dist/security/index.js +12 -0
- package/src/@claude-flow/shared/dist/security/input-validation.d.ts +73 -0
- package/src/@claude-flow/shared/dist/security/input-validation.js +201 -0
- package/src/@claude-flow/shared/dist/security/secure-random.d.ts +92 -0
- package/src/@claude-flow/shared/dist/security/secure-random.js +142 -0
- package/src/@claude-flow/shared/dist/services/index.d.ts +7 -0
- package/src/@claude-flow/shared/dist/services/index.js +7 -0
- package/src/@claude-flow/shared/dist/services/v3-progress.service.d.ts +124 -0
- package/src/@claude-flow/shared/dist/services/v3-progress.service.js +402 -0
- package/src/@claude-flow/shared/dist/types/agent.types.d.ts +137 -0
- package/src/@claude-flow/shared/dist/types/agent.types.js +6 -0
- package/src/@claude-flow/shared/dist/types/index.d.ts +11 -0
- package/src/@claude-flow/shared/dist/types/index.js +17 -0
- package/src/@claude-flow/shared/dist/types/mcp.types.d.ts +266 -0
- package/src/@claude-flow/shared/dist/types/mcp.types.js +7 -0
- package/src/@claude-flow/shared/dist/types/memory.types.d.ts +236 -0
- package/src/@claude-flow/shared/dist/types/memory.types.js +7 -0
- package/src/@claude-flow/shared/dist/types/swarm.types.d.ts +186 -0
- package/src/@claude-flow/shared/dist/types/swarm.types.js +65 -0
- package/src/@claude-flow/shared/dist/types/task.types.d.ts +178 -0
- package/src/@claude-flow/shared/dist/types/task.types.js +32 -0
- package/src/@claude-flow/shared/dist/types.d.ts +197 -0
- package/src/@claude-flow/shared/dist/types.js +21 -0
- package/src/@claude-flow/shared/dist/utils/secure-logger.d.ts +69 -0
- package/src/@claude-flow/shared/dist/utils/secure-logger.js +208 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Event Bus System
|
|
3
|
+
* Event-driven communication for the 15-agent swarm
|
|
4
|
+
*
|
|
5
|
+
* Based on ADR-007 (Event Sourcing for State Changes)
|
|
6
|
+
*/
|
|
7
|
+
import { EventType, EventHandler, SwarmEvent, AgentId } from './types.js';
|
|
8
|
+
export interface IEventBus {
|
|
9
|
+
subscribe<T>(eventType: EventType, handler: EventHandler<T>): () => void;
|
|
10
|
+
subscribeAll(handler: EventHandler): () => void;
|
|
11
|
+
emit<T>(event: SwarmEvent<T>): Promise<void>;
|
|
12
|
+
emitSync<T>(event: SwarmEvent<T>): void;
|
|
13
|
+
getHistory(filter?: EventFilter): SwarmEvent[];
|
|
14
|
+
clear(): void;
|
|
15
|
+
}
|
|
16
|
+
export interface EventFilter {
|
|
17
|
+
types?: EventType[];
|
|
18
|
+
sources?: (AgentId | 'swarm')[];
|
|
19
|
+
since?: number;
|
|
20
|
+
until?: number;
|
|
21
|
+
limit?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface IEventStore {
|
|
24
|
+
append(event: SwarmEvent): Promise<void>;
|
|
25
|
+
getEvents(aggregateId: string, fromVersion?: number): Promise<SwarmEvent[]>;
|
|
26
|
+
getAllEvents(filter?: EventFilter): Promise<SwarmEvent[]>;
|
|
27
|
+
getSnapshot(aggregateId: string): Promise<EventStoreSnapshot | null>;
|
|
28
|
+
saveSnapshot(snapshot: EventStoreSnapshot): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export interface EventStoreSnapshot {
|
|
31
|
+
aggregateId: string;
|
|
32
|
+
version: number;
|
|
33
|
+
state: unknown;
|
|
34
|
+
timestamp: number;
|
|
35
|
+
}
|
|
36
|
+
export declare class EventBus implements IEventBus {
|
|
37
|
+
private handlers;
|
|
38
|
+
private history;
|
|
39
|
+
private maxHistorySize;
|
|
40
|
+
constructor(options?: {
|
|
41
|
+
maxHistorySize?: number;
|
|
42
|
+
});
|
|
43
|
+
subscribe<T>(eventType: EventType, handler: EventHandler<T>): () => void;
|
|
44
|
+
subscribeAll(handler: EventHandler): () => void;
|
|
45
|
+
emit<T>(event: SwarmEvent<T>): Promise<void>;
|
|
46
|
+
emitSync<T>(event: SwarmEvent<T>): void;
|
|
47
|
+
getHistory(filter?: EventFilter): SwarmEvent[];
|
|
48
|
+
clear(): void;
|
|
49
|
+
private addToHistory;
|
|
50
|
+
private safeExecute;
|
|
51
|
+
}
|
|
52
|
+
export declare class InMemoryEventStore implements IEventStore {
|
|
53
|
+
private events;
|
|
54
|
+
private allEvents;
|
|
55
|
+
private snapshots;
|
|
56
|
+
append(event: SwarmEvent): Promise<void>;
|
|
57
|
+
getEvents(aggregateId: string, fromVersion?: number): Promise<SwarmEvent[]>;
|
|
58
|
+
getAllEvents(filter?: EventFilter): Promise<SwarmEvent[]>;
|
|
59
|
+
getSnapshot(aggregateId: string): Promise<EventStoreSnapshot | null>;
|
|
60
|
+
saveSnapshot(snapshot: EventStoreSnapshot): Promise<void>;
|
|
61
|
+
private extractAggregateId;
|
|
62
|
+
}
|
|
63
|
+
export declare function createEvent<T>(type: EventType, source: AgentId | 'swarm', payload: T): SwarmEvent<T>;
|
|
64
|
+
export declare function agentSpawnedEvent(agentId: AgentId, role: string): SwarmEvent;
|
|
65
|
+
export declare function agentStatusChangedEvent(agentId: AgentId, previousStatus: string, newStatus: string): SwarmEvent;
|
|
66
|
+
export declare function agentTaskAssignedEvent(agentId: AgentId, taskId: string): SwarmEvent;
|
|
67
|
+
export declare function agentTaskCompletedEvent(agentId: AgentId, taskId: string, result: unknown): SwarmEvent;
|
|
68
|
+
export declare function agentErrorEvent(agentId: AgentId, error: Error): SwarmEvent;
|
|
69
|
+
export declare function taskCreatedEvent(taskId: string, type: string, title: string): SwarmEvent;
|
|
70
|
+
export declare function taskQueuedEvent(taskId: string, priority: string): SwarmEvent;
|
|
71
|
+
export declare function taskAssignedEvent(taskId: string, agentId: AgentId): SwarmEvent;
|
|
72
|
+
export declare function taskStartedEvent(taskId: string, agentId: AgentId): SwarmEvent;
|
|
73
|
+
export declare function taskCompletedEvent(taskId: string, result: unknown): SwarmEvent;
|
|
74
|
+
export declare function taskFailedEvent(taskId: string, error: Error): SwarmEvent;
|
|
75
|
+
export declare function taskBlockedEvent(taskId: string, blockedBy: string[]): SwarmEvent;
|
|
76
|
+
export declare function swarmInitializedEvent(config: unknown): SwarmEvent;
|
|
77
|
+
export declare function swarmPhaseChangedEvent(previousPhase: string, newPhase: string): SwarmEvent;
|
|
78
|
+
export declare function swarmMilestoneReachedEvent(milestoneId: string, name: string): SwarmEvent;
|
|
79
|
+
export declare function swarmErrorEvent(error: Error): SwarmEvent;
|
|
80
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Event Bus System
|
|
3
|
+
* Event-driven communication for the 15-agent swarm
|
|
4
|
+
*
|
|
5
|
+
* Based on ADR-007 (Event Sourcing for State Changes)
|
|
6
|
+
*/
|
|
7
|
+
// =============================================================================
|
|
8
|
+
// Event Bus Implementation
|
|
9
|
+
// =============================================================================
|
|
10
|
+
export class EventBus {
|
|
11
|
+
handlers = new Map();
|
|
12
|
+
history = [];
|
|
13
|
+
maxHistorySize;
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
this.maxHistorySize = options.maxHistorySize ?? 10000;
|
|
16
|
+
}
|
|
17
|
+
subscribe(eventType, handler) {
|
|
18
|
+
if (!this.handlers.has(eventType)) {
|
|
19
|
+
this.handlers.set(eventType, new Set());
|
|
20
|
+
}
|
|
21
|
+
const handlers = this.handlers.get(eventType);
|
|
22
|
+
handlers.add(handler);
|
|
23
|
+
return () => {
|
|
24
|
+
handlers.delete(handler);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
subscribeAll(handler) {
|
|
28
|
+
if (!this.handlers.has('*')) {
|
|
29
|
+
this.handlers.set('*', new Set());
|
|
30
|
+
}
|
|
31
|
+
const handlers = this.handlers.get('*');
|
|
32
|
+
handlers.add(handler);
|
|
33
|
+
return () => {
|
|
34
|
+
handlers.delete(handler);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async emit(event) {
|
|
38
|
+
this.addToHistory(event);
|
|
39
|
+
const typeHandlers = this.handlers.get(event.type) ?? new Set();
|
|
40
|
+
const allHandlers = this.handlers.get('*') ?? new Set();
|
|
41
|
+
const allPromises = [];
|
|
42
|
+
for (const handler of typeHandlers) {
|
|
43
|
+
allPromises.push(this.safeExecute(handler, event));
|
|
44
|
+
}
|
|
45
|
+
for (const handler of allHandlers) {
|
|
46
|
+
allPromises.push(this.safeExecute(handler, event));
|
|
47
|
+
}
|
|
48
|
+
await Promise.all(allPromises);
|
|
49
|
+
}
|
|
50
|
+
emitSync(event) {
|
|
51
|
+
this.addToHistory(event);
|
|
52
|
+
const typeHandlers = this.handlers.get(event.type) ?? new Set();
|
|
53
|
+
const allHandlers = this.handlers.get('*') ?? new Set();
|
|
54
|
+
for (const handler of typeHandlers) {
|
|
55
|
+
try {
|
|
56
|
+
const result = handler(event);
|
|
57
|
+
if (result instanceof Promise) {
|
|
58
|
+
result.catch(err => console.error(`Event handler error: ${err}`));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
console.error(`Event handler error: ${err}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const handler of allHandlers) {
|
|
66
|
+
try {
|
|
67
|
+
const result = handler(event);
|
|
68
|
+
if (result instanceof Promise) {
|
|
69
|
+
result.catch(err => console.error(`Event handler error: ${err}`));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
console.error(`Event handler error: ${err}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
getHistory(filter) {
|
|
78
|
+
let events = [...this.history];
|
|
79
|
+
if (filter?.types?.length) {
|
|
80
|
+
events = events.filter(e => filter.types.includes(e.type));
|
|
81
|
+
}
|
|
82
|
+
if (filter?.sources?.length) {
|
|
83
|
+
events = events.filter(e => filter.sources.includes(e.source));
|
|
84
|
+
}
|
|
85
|
+
if (filter?.since) {
|
|
86
|
+
events = events.filter(e => e.timestamp >= filter.since);
|
|
87
|
+
}
|
|
88
|
+
if (filter?.until) {
|
|
89
|
+
events = events.filter(e => e.timestamp <= filter.until);
|
|
90
|
+
}
|
|
91
|
+
if (filter?.limit) {
|
|
92
|
+
events = events.slice(-filter.limit);
|
|
93
|
+
}
|
|
94
|
+
return events;
|
|
95
|
+
}
|
|
96
|
+
clear() {
|
|
97
|
+
this.history = [];
|
|
98
|
+
}
|
|
99
|
+
addToHistory(event) {
|
|
100
|
+
this.history.push(event);
|
|
101
|
+
if (this.history.length > this.maxHistorySize) {
|
|
102
|
+
this.history = this.history.slice(-Math.floor(this.maxHistorySize / 2));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async safeExecute(handler, event) {
|
|
106
|
+
try {
|
|
107
|
+
await handler(event);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
console.error(`Event handler error for ${event.type}: ${err}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// =============================================================================
|
|
115
|
+
// In-Memory Event Store
|
|
116
|
+
// =============================================================================
|
|
117
|
+
export class InMemoryEventStore {
|
|
118
|
+
events = new Map();
|
|
119
|
+
allEvents = [];
|
|
120
|
+
snapshots = new Map();
|
|
121
|
+
async append(event) {
|
|
122
|
+
const aggregateId = this.extractAggregateId(event);
|
|
123
|
+
if (!this.events.has(aggregateId)) {
|
|
124
|
+
this.events.set(aggregateId, []);
|
|
125
|
+
}
|
|
126
|
+
this.events.get(aggregateId).push(event);
|
|
127
|
+
this.allEvents.push(event);
|
|
128
|
+
}
|
|
129
|
+
async getEvents(aggregateId, fromVersion) {
|
|
130
|
+
const events = this.events.get(aggregateId) ?? [];
|
|
131
|
+
if (fromVersion !== undefined) {
|
|
132
|
+
return events.slice(fromVersion);
|
|
133
|
+
}
|
|
134
|
+
return events;
|
|
135
|
+
}
|
|
136
|
+
async getAllEvents(filter) {
|
|
137
|
+
let events = [...this.allEvents];
|
|
138
|
+
if (filter?.types?.length) {
|
|
139
|
+
events = events.filter(e => filter.types.includes(e.type));
|
|
140
|
+
}
|
|
141
|
+
if (filter?.sources?.length) {
|
|
142
|
+
events = events.filter(e => filter.sources.includes(e.source));
|
|
143
|
+
}
|
|
144
|
+
if (filter?.since) {
|
|
145
|
+
events = events.filter(e => e.timestamp >= filter.since);
|
|
146
|
+
}
|
|
147
|
+
if (filter?.until) {
|
|
148
|
+
events = events.filter(e => e.timestamp <= filter.until);
|
|
149
|
+
}
|
|
150
|
+
if (filter?.limit) {
|
|
151
|
+
events = events.slice(-filter.limit);
|
|
152
|
+
}
|
|
153
|
+
return events;
|
|
154
|
+
}
|
|
155
|
+
async getSnapshot(aggregateId) {
|
|
156
|
+
return this.snapshots.get(aggregateId) ?? null;
|
|
157
|
+
}
|
|
158
|
+
async saveSnapshot(snapshot) {
|
|
159
|
+
this.snapshots.set(snapshot.aggregateId, snapshot);
|
|
160
|
+
}
|
|
161
|
+
extractAggregateId(event) {
|
|
162
|
+
if (event.source !== 'swarm') {
|
|
163
|
+
return event.source;
|
|
164
|
+
}
|
|
165
|
+
if (typeof event.payload === 'object' && event.payload !== null) {
|
|
166
|
+
const payload = event.payload;
|
|
167
|
+
if ('agentId' in payload)
|
|
168
|
+
return payload.agentId;
|
|
169
|
+
if ('taskId' in payload)
|
|
170
|
+
return payload.taskId;
|
|
171
|
+
}
|
|
172
|
+
return 'swarm';
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// =============================================================================
|
|
176
|
+
// Event Factory Functions
|
|
177
|
+
// =============================================================================
|
|
178
|
+
let eventCounter = 0;
|
|
179
|
+
export function createEvent(type, source, payload) {
|
|
180
|
+
return {
|
|
181
|
+
id: `evt-${Date.now()}-${++eventCounter}`,
|
|
182
|
+
type,
|
|
183
|
+
timestamp: Date.now(),
|
|
184
|
+
source,
|
|
185
|
+
payload
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
// Agent Events
|
|
189
|
+
export function agentSpawnedEvent(agentId, role) {
|
|
190
|
+
return createEvent('agent:spawned', 'swarm', { agentId, role });
|
|
191
|
+
}
|
|
192
|
+
export function agentStatusChangedEvent(agentId, previousStatus, newStatus) {
|
|
193
|
+
return createEvent('agent:status-changed', agentId, { previousStatus, newStatus });
|
|
194
|
+
}
|
|
195
|
+
export function agentTaskAssignedEvent(agentId, taskId) {
|
|
196
|
+
return createEvent('agent:task-assigned', 'swarm', { agentId, taskId });
|
|
197
|
+
}
|
|
198
|
+
export function agentTaskCompletedEvent(agentId, taskId, result) {
|
|
199
|
+
return createEvent('agent:task-completed', agentId, { taskId, result });
|
|
200
|
+
}
|
|
201
|
+
export function agentErrorEvent(agentId, error) {
|
|
202
|
+
return createEvent('agent:error', agentId, {
|
|
203
|
+
message: error.message,
|
|
204
|
+
stack: error.stack
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
// Task Events
|
|
208
|
+
export function taskCreatedEvent(taskId, type, title) {
|
|
209
|
+
return createEvent('task:created', 'swarm', { taskId, type, title });
|
|
210
|
+
}
|
|
211
|
+
export function taskQueuedEvent(taskId, priority) {
|
|
212
|
+
return createEvent('task:queued', 'swarm', { taskId, priority });
|
|
213
|
+
}
|
|
214
|
+
export function taskAssignedEvent(taskId, agentId) {
|
|
215
|
+
return createEvent('task:assigned', 'swarm', { taskId, agentId });
|
|
216
|
+
}
|
|
217
|
+
export function taskStartedEvent(taskId, agentId) {
|
|
218
|
+
return createEvent('task:started', agentId, { taskId });
|
|
219
|
+
}
|
|
220
|
+
export function taskCompletedEvent(taskId, result) {
|
|
221
|
+
return createEvent('task:completed', 'swarm', { taskId, result });
|
|
222
|
+
}
|
|
223
|
+
export function taskFailedEvent(taskId, error) {
|
|
224
|
+
return createEvent('task:failed', 'swarm', {
|
|
225
|
+
taskId,
|
|
226
|
+
error: error.message,
|
|
227
|
+
stack: error.stack
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
export function taskBlockedEvent(taskId, blockedBy) {
|
|
231
|
+
return createEvent('task:blocked', 'swarm', { taskId, blockedBy });
|
|
232
|
+
}
|
|
233
|
+
// Swarm Events
|
|
234
|
+
export function swarmInitializedEvent(config) {
|
|
235
|
+
return createEvent('swarm:initialized', 'swarm', { config });
|
|
236
|
+
}
|
|
237
|
+
export function swarmPhaseChangedEvent(previousPhase, newPhase) {
|
|
238
|
+
return createEvent('swarm:phase-changed', 'swarm', { previousPhase, newPhase });
|
|
239
|
+
}
|
|
240
|
+
export function swarmMilestoneReachedEvent(milestoneId, name) {
|
|
241
|
+
return createEvent('swarm:milestone-reached', 'swarm', { milestoneId, name });
|
|
242
|
+
}
|
|
243
|
+
export function swarmErrorEvent(error) {
|
|
244
|
+
return createEvent('swarm:error', 'swarm', {
|
|
245
|
+
message: error.message,
|
|
246
|
+
stack: error.stack
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Hooks System - Example Usage
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates practical use cases for the hooks system.
|
|
5
|
+
*
|
|
6
|
+
* @module v3/shared/hooks/example-usage
|
|
7
|
+
*/
|
|
8
|
+
export declare function setupSecurityHooks(): {
|
|
9
|
+
registry: import("./registry.js").HookRegistry;
|
|
10
|
+
executor: import("./executor.js").HookExecutor;
|
|
11
|
+
};
|
|
12
|
+
export declare function setupLearningHooks(): {
|
|
13
|
+
registry: import("./registry.js").HookRegistry;
|
|
14
|
+
executor: import("./executor.js").HookExecutor;
|
|
15
|
+
};
|
|
16
|
+
export declare function setupPerformanceHooks(): {
|
|
17
|
+
registry: import("./registry.js").HookRegistry;
|
|
18
|
+
executor: import("./executor.js").HookExecutor;
|
|
19
|
+
performanceMetrics: Map<string, {
|
|
20
|
+
start: number;
|
|
21
|
+
end?: number;
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
24
|
+
export declare function setupFileValidationHooks(): {
|
|
25
|
+
registry: import("./registry.js").HookRegistry;
|
|
26
|
+
executor: import("./executor.js").HookExecutor;
|
|
27
|
+
};
|
|
28
|
+
export declare function setupSessionHooks(): {
|
|
29
|
+
registry: import("./registry.js").HookRegistry;
|
|
30
|
+
executor: import("./executor.js").HookExecutor;
|
|
31
|
+
};
|
|
32
|
+
export declare function setupErrorHooks(): {
|
|
33
|
+
registry: import("./registry.js").HookRegistry;
|
|
34
|
+
executor: import("./executor.js").HookExecutor;
|
|
35
|
+
errorLog: {
|
|
36
|
+
timestamp: Date;
|
|
37
|
+
error: Error;
|
|
38
|
+
context?: string;
|
|
39
|
+
}[];
|
|
40
|
+
};
|
|
41
|
+
export declare function runDemo(): Promise<void>;
|
|
42
|
+
//# sourceMappingURL=example-usage.d.ts.map
|