import { EventCatalog } from './framework/events/event-catalog.js'; import type { EventCatalogEntry } from './framework/events/types.js'; import type { EventDeliveryClass } from './framework/events/types.js'; export const CLAWCLAW_VISUAL_EVENT_TYPES = [ 'visual.player_entered', 'visual.player_left', 'visual.player_reappeared', 'visual.corpse_entered', 'visual.corpse_left', 'visual.player_moved', 'visual.player_motion_changed', 'visual.player_stopped', 'visual.player_resumed', 'visual.player_stop_ended', 'visual.no_significant_stop', 'visual.player_area_changed', 'visual.player_position_changed', 'visual.player_turned', 'visual.player_reversed', 'visual.player_wandering', 'visual.players_moving_together', 'visual.players_stopped_moving_together', 'visual.following', 'visual.following_ended', ] as const; export type ClawclawVisualEventType = typeof CLAWCLAW_VISUAL_EVENT_TYPES[number]; export type ClawclawEventDelivery = EventDeliveryClass | Readonly>; export type ClawclawVisualEventDelivery = EventDeliveryClass | Readonly>>; export interface ClawclawEventCatalogOptions { /** Defaults to visible notifications while preserving the producer's wakeAgent choice. */ visualEventDelivery?: ClawclawVisualEventDelivery; /** Additional visual Event types declared by selected user perception modules. */ visualEventTypes?: readonly string[]; /** Events declared by the enabled Intent and Strategy manifests at startup. */ behaviorEventTypes?: readonly string[]; /** Own notification types from equipped unified perceptions. */ perceptionEventTypes?: readonly string[]; } /** * Exhaustive protocol contract for the ClawClaw GameServer stream. Keep this * list in lockstep with backend EventType; every value must be classified * explicitly below so a newly added backend fact cannot silently fall through * the generic internal-only policy. */ export const CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES = [ 'enter_room', 'move_start', 'move_end', 'move_interrupted', 'move', 'task_started', 'task_progress', 'task_completed', 'task_interrupted', 'task_sabotaged', 'task_assigned', 'kill', 'killed', 'murder_witnessed', 'body_dropped', 'warrior_shrimp_self_destruct', 'meeting_start', 'meeting_briefing', 'speech_turn', 'speech_your_turn', 'speech_next_turn', 'speech', 'speech_skipped', 'vote_phase_start', 'vote_cast', 'vote_speech', 'vote_speech_phase_ended', 'exile', 'no_exile', 'meeting_ended', 'meeting_result_pending', 'exile_game_over', 'game_started', 'game_over', 'role_assigned', 'emergency_started', 'emergency_resolved', 'emergency_interrupted', 'player_spotted', 'corpse_spotted', 'octopus_time_start', 'octopus_time_win', 'win_blocked_by_octopus', 'wandering_speech', 'death_speech', 'think', ] as const; /** Backend facts that enter the Agent-visible stream and wake Monitor. */ export const CLAWCLAW_BACKEND_AGENT_EVENT_TYPES = [ 'service_status', 'move_interrupted', 'kill', 'killed', 'murder_witnessed', 'warrior_shrimp_self_destruct', 'body_dropped', 'corpse_spotted', 'octopus_time_start', 'emergency_started', 'emergency_resolved', 'exile', 'no_exile', 'vote_speech_phase_ended', 'death_speech', 'meeting_briefing', 'speech', 'speech_skipped', 'speech_your_turn', 'speech_next_turn', 'vote_phase_start', 'game_over', 'exile_game_over', 'game_started', 'role_assigned', 'emergency_interrupted', 'octopus_time_win', 'win_blocked_by_octopus', 'room.member_joined', 'room.member_status_changed', 'room.member_left', 'room.owner_changed', 'room.full', 'room.type_changed', 'room.chat', 'room.game_starting', 'room.game_started', 'room.game_start_failed', 'room.game_finished', 'room.cooldown', 'room.idle_warning', 'room.self_left', ] as const; /** CCL lifecycle facts with no equivalent backend producer. */ export const CLAWCLAW_LOCAL_AGENT_EVENT_TYPES = [ 'joined', 'room_created', 'room_joined', 'session_resumed', 'session_recovered', 'not_in_queue', 'poll_error', 'error', 'game_start_failed', 'game_over_recovered', 'game_terminal_missing', 'game_stream_disconnected', 'game_stream_reconnected', 'stop_requested', 'quit_requested', 'match_start', 'match_waiting', 'match_timeout', 'match_exited', 'user_left_game', 'session_left', 'quit_failed', 'robot_speak_rule', 'room_attached', 'room_lobby_reconnect_failed', 'room_lobby_missing', 'room_ready_to_start', 'room_returning_to_lobby', 'room_ping_timeout', 'lobby_connection_replaced', 'room_destroyed', 'strategy_alert', 'behavior.started', 'behavior.suspended', 'behavior.restarted', 'behavior.completed', 'behavior.failed', 'behavior.cancelled', 'behavior.replaced', 'players_changed', 'reminder.task', 'reminder.speech', 'perception.module_failed', 'perception.behavior_unavailable', 'emergency_countdown_warning', 'ability.ready', 'ability.unavailable', 'ability.remaining_uses_changed', 'ability.exhausted', ] as const; /** Durable inputs used by projectors, but never sent directly to the Agent. */ export const CLAWCLAW_INTERNAL_BACKEND_EVENT_TYPES = [ 'wandering_speech', 'task_completed', 'task_interrupted', 'task_sabotaged', 'enter_room', 'move_start', 'move_end', 'move', 'task_started', 'task_progress', 'task_assigned', 'speech_turn', 'vote_cast', 'think', 'vote_speech', 'player_spotted', 'meeting_start', 'meeting_started', 'meeting_ended', 'meeting_result_pending', ] as const; export const CLAWCLAW_INTERNAL_LOCAL_EVENT_TYPES = [ 'tasks_changed', 'meeting_state', 'runtime_started', 'runtime_stopped', 'stream_gap', ] as const; const CLAWCLAW_FIXED_EVENT_TYPES = new Set([ ...CLAWCLAW_BACKEND_AGENT_EVENT_TYPES, ...CLAWCLAW_LOCAL_AGENT_EVENT_TYPES, ...CLAWCLAW_INTERNAL_BACKEND_EVENT_TYPES, ...CLAWCLAW_INTERNAL_LOCAL_EVENT_TYPES, ...CLAWCLAW_VISUAL_EVENT_TYPES, ]); /** Player Behavior manifests cannot claim a Host- or backend-owned Event name. */ export function isClawclawFixedEventType(type: string): boolean { return CLAWCLAW_FIXED_EVENT_TYPES.has(type); } export const CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES = new Set([ ...CLAWCLAW_BACKEND_AGENT_EVENT_TYPES, ...CLAWCLAW_LOCAL_AGENT_EVENT_TYPES, ]); function visualDelivery( config: ClawclawVisualEventDelivery | undefined, type: string, ): Pick { const configured = typeof config === 'string' ? config : config?.[type]; return typeof configured === 'object' ? { ...configured } : { deliveryClass: configured ?? 'monitor_and_events' }; } function entries(options: ClawclawEventCatalogOptions = {}): EventCatalogEntry[] { const perceptionOutputTypes = new Set(options.perceptionEventTypes ?? []); const ownOutputDelivery = (type: string) => perceptionOutputTypes.has(type) ? visualDelivery(options.visualEventDelivery, type) : { deliveryClass: 'monitor_and_events' as const }; const visualEventTypes = [...new Set([ ...CLAWCLAW_VISUAL_EVENT_TYPES, ...(options.visualEventTypes ?? []), ])].sort(); const fixedAndVisualTypes = new Set([ ...CLAWCLAW_FIXED_EVENT_TYPES, ...visualEventTypes, ]); const behaviorEventTypes = [...new Set([...(options.behaviorEventTypes ?? []), ...(options.perceptionEventTypes ?? [])])] .filter((type) => !fixedAndVisualTypes.has(type)) .sort(); return [ ...CLAWCLAW_BACKEND_AGENT_EVENT_TYPES.map((type) => ({ type, producer: 'backend_push' as const, deliveryClass: 'monitor_and_events' as const, })), ...CLAWCLAW_LOCAL_AGENT_EVENT_TYPES.map((type) => ({ type, producer: 'local_synth' as const, ...ownOutputDelivery(type), })), ...CLAWCLAW_INTERNAL_BACKEND_EVENT_TYPES.map((type) => ({ type, producer: 'backend_push' as const, deliveryClass: 'internal_only' as const, })), ...CLAWCLAW_INTERNAL_LOCAL_EVENT_TYPES.map((type) => ({ type, producer: 'local_synth' as const, deliveryClass: 'internal_only' as const, })), ...visualEventTypes.map((type) => ({ type, producer: 'local_synth' as const, ...visualDelivery(options.visualEventDelivery, type), })), ...behaviorEventTypes.map((type) => ({ type, producer: 'local_synth' as const, ...ownOutputDelivery(type), })), ]; } export function assertClawclawBackendEventCatalogComplete(): void { const classified = new Set([ ...CLAWCLAW_BACKEND_AGENT_EVENT_TYPES, ...CLAWCLAW_INTERNAL_BACKEND_EVENT_TYPES, ]); const missing = CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES .filter((type) => !classified.has(type)); if (missing.length > 0) { throw new Error(`Unclassified ClawClaw backend Event type(s): ${missing.join(', ')}`); } } export function createClawclawEventCatalog( options: ClawclawEventCatalogOptions = {}, ): EventCatalog { assertClawclawBackendEventCatalogComplete(); return new EventCatalog(entries(options), { unknownDeliveryClass: 'internal_only' }); }