/** * Agentic QE v3 - Base Domain Interface * Template for all domain implementations */ import { DomainName, DomainEvent } from '../shared/types'; import { DomainPlugin, DomainHealth, EventBus, MemoryBackend } from '../kernel/interfaces'; /** * Abstract base class for domain plugins */ export abstract class BaseDomainPlugin implements DomainPlugin { protected _initialized = false; protected _health: DomainHealth = { status: 'healthy', agents: { total: 0, active: 0, idle: 0, failed: 0 }, errors: [], }; constructor( protected readonly eventBus: EventBus, protected readonly memory: MemoryBackend ) {} abstract get name(): DomainName; abstract get version(): string; abstract get dependencies(): DomainName[]; isReady(): boolean { return this._initialized; } getHealth(): DomainHealth { return { ...this._health }; } async initialize(): Promise { if (this._initialized) return; await this.onInitialize(); this.subscribeToEvents(); this._initialized = true; } async dispose(): Promise { await this.onDispose(); this._initialized = false; } async handleEvent(event: DomainEvent): Promise { await this.onEvent(event); } abstract getAPI(): T; // Override in subclasses protected async onInitialize(): Promise {} protected async onDispose(): Promise {} protected async onEvent(_event: DomainEvent): Promise {} protected subscribeToEvents(): void {} // Helper methods protected async publishEvent(type: string, payload: T): Promise { const event: DomainEvent = { id: crypto.randomUUID(), type, timestamp: new Date(), source: this.name, payload, }; await this.eventBus.publish(event); } protected updateHealth(updates: Partial): void { this._health = { ...this._health, ...updates }; } }