import type { GameState, ObservationFrame } from '../module-input/index.js'; import type { BehaviorInputFieldSpec } from '../behavior-plugin/index.js'; import type { ClawclawResourceLocalizations } from '../resource-metadata.js'; import type { ReminderFact, ReminderTaskChange } from './reminder.js'; import type { ReactionActivation, ReactionBehaviorBinding } from './reaction.js'; import type { StrategyMemory } from '../strategy-memory.js'; /** Unified perception contract with optional fixed Reflex bindings. */ export const PERCEPTION_MODULE_API_VERSION = 3 as const; export type PerceptionStrategyBinding = ReactionBehaviorBinding; export interface PerceptionStrategyActivation { readonly strategy: string; readonly input?: Readonly>; readonly reason?: string; } export interface PerceptionModuleManifest { readonly apiVersion: typeof PERCEPTION_MODULE_API_VERSION; readonly id: string; readonly name?: string; readonly description: string; readonly localizations?: ClawclawResourceLocalizations; readonly consumes?: readonly string[]; readonly produces?: readonly string[]; readonly inputs?: readonly BehaviorInputFieldSpec[]; readonly config?: Readonly>; readonly strategies?: Readonly>; readonly behaviors?: Readonly>; } export interface PerceptionModuleInput { readonly source?: Readonly<{ epochId: number; frameSeq: number; connectionId: string; backendTick?: number; receivedAtMs: number; observedAtMs?: number }>; /** Explicit boundaries; the host does not erase module state on a phase change. */ readonly lifecycle?: readonly PerceptionLifecycleChange[]; readonly roomState?: Readonly> | null; readonly queueState?: Readonly> | null; /** Source facts keep their own accepted State boundary, distinct from gameState. */ readonly eventStates?: Readonly> | null>>; readonly cycle?: import('../module-input/index.js').ProcessingCycleInfo; readonly moduleId: string; readonly scope: Readonly<{ sessionId: string; segmentId: string }>; readonly gameState: Readonly | null; readonly frame: Readonly | null; /** Original Source/backend facts only; never another perception's output or a forwarded copy. */ readonly events: readonly Readonly[]; /** Compared independently against this module's own durable task baseline. */ readonly taskChanges: readonly ReminderTaskChange[]; readonly boundary: 'initial' | 'recovery' | null; readonly nowMs: number; readonly config: Readonly>; readonly state: unknown; /** Equipped, loadable dependencies; independent of the automatic-activation switch. */ readonly availableBindings?: readonly string[]; readonly availableBehaviors?: readonly string[]; readonly availableStrategies?: readonly string[]; readonly enabledBindings?: readonly string[]; } export interface PerceptionModuleApi { readonly spatial?: import('../behavior-plugin/index.js').SpatialApi; /** Shared with a unique explicitly bound strategy; otherwise module-private. */ readonly memory: StrategyMemory; } export interface PerceptionModuleEvent { readonly type: string; readonly key: string; /** false retains the event for a later wake; omit the event to produce no notification. */ readonly wakeAgent?: boolean; readonly payload: Readonly>; readonly occurredAt?: string; } export interface PerceptionModuleResult { readonly state?: unknown; readonly events?: readonly PerceptionModuleEvent[]; /** Requires host registration authority; user manifests cannot grant it. */ readonly forwards?: readonly { readonly eventId: string }[]; /** Keys in manifest.behaviors; never arbitrary strategy names or executable Actions. */ readonly activations?: readonly (PerceptionStrategyActivation | ReactionActivation)[]; } export type PerceptionLifecycleChange = | Readonly<{ kind: 'initial' | 'recovery' | 'observation_gap' | 'observer_died' | 'segment_ending' | 'snapshot_requested' }> | Readonly<{ kind: 'phase_changed'; from: string; to: string }>;