import type { BehaviorInputFieldSpec, BehaviorReadApi, } from '../behavior-plugin/index.js'; export type { StrategyMemory, StrategyMemoryValue } from '../strategy-memory.js'; import type { GameEvent, ObservationFrame, } from '../module-input/index.js'; import type { ClawclawResourceLocalizations } from '../resource-metadata.js'; export const TRIGGER_PLUGIN_API_VERSION = 4 as const; /** Hard upper bound for one Reflex activation, regardless of module or runtime override. */ export const MAX_TRIGGER_RUNTIME_MS = 120_000; export { hasValidClawclawResourceLocalizations, resolveClawclawResourceMetadata, } from '../resource-metadata.js'; export type { ClawclawLocalizedResourceText, ClawclawResolvedResourceMetadata, ClawclawResourceLocalizations, ClawclawResourceMetadata, } from '../resource-metadata.js'; export type { BehaviorInputFieldSpec, BehaviorReadApi, } from '../behavior-plugin/index.js'; export type { BehaviorScope, GameEvent, GameState, KnownPlayer, ObservationFrame, PlayerRef, Position, VisualCorpse, VisualObservation, VisualPlayer, VisualPosition, VisibleCorpse, VisiblePlayer, } from '../module-input/index.js'; /** How a matched Trigger becomes eligible to fire again. */ export type TriggerRearm = 'after_clear' | 'after_cooldown'; /** * Statically readable description and safe defaults for one Trigger. * * `defaultReflexPriority` is only relative to other Reflex activations. It * never changes the fixed Runtime control order of reflex > short > long. */ export interface ClawclawTriggerManifest { readonly apiVersion: typeof TRIGGER_PLUGIN_API_VERSION; readonly id: string; readonly name: string; readonly description: string; readonly localizations?: ClawclawResourceLocalizations; /** Rule parameters delivered through TriggerInput.input. Every field needs a default. */ readonly inputs: readonly BehaviorInputFieldSpec[]; /** Backend-pushed Event types observed by this Trigger. Empty means frame-only. */ readonly consumes: readonly string[]; /** Default fixed Behavior binding; effective configuration may replace this binding. */ readonly defaultBehavior: string; readonly defaultBehaviorInput: Readonly>; /** Relative priority among Reflex activations only. */ readonly defaultReflexPriority: number; readonly defaultCooldownMs: number; readonly defaultRearm: TriggerRearm; readonly defaultMaxRuntimeMs: number; } /** Static configuration of the named Trigger exported by a Strategy file. */ export type StrategyTriggerManifest = Pick & Partial> & { readonly id?: never }; /** * One immutable observation frame, backend-pushed Runtime Events, and configured rule * parameters. Perception and Trigger receive the same frame independently; * `events` never contains output from any Runtime computation plugin. */ export interface TriggerInput< TInput extends Readonly> = Readonly>, > { readonly cycle?: import('../module-input/index.js').ProcessingCycleInfo; readonly frame: Readonly; readonly events: readonly Readonly[]; readonly input: Readonly; } export type TriggerResetReason = | 'phase_changed' | 'trajectory_gap' | 'segment_ending' | 'shutdown'; /** Read-only game queries plus private memory shared with the same resource's Behavior. */ export type TriggerReadApi = BehaviorReadApi; /** * One rule match. The target Behavior and Reflex priority deliberately do not * appear here: Runtime takes both from the effective, already-authorized * Trigger configuration. */ export interface TriggerMatch { readonly reason: string; readonly evidence?: Readonly>; /** Dynamic values merged over the configured default Behavior input. */ readonly behaviorInput?: Readonly>; } /** Public authoring surface for one rule; game writes remain Behavior Actions. */ export abstract class ClawclawTrigger< TInput extends Readonly> = Readonly>, > { static readonly manifest?: ClawclawTriggerManifest | StrategyTriggerManifest; abstract evaluate( input: Readonly>, api: TriggerReadApi, ): TriggerMatch | void | Promise; /** Clears private cross-frame rule state at an observation boundary. */ reset?(reason: TriggerResetReason): void | Promise; } export interface ClawclawTriggerClass< TInput extends Readonly> = Readonly>, > { readonly manifest?: ClawclawTriggerManifest | StrategyTriggerManifest; new(): ClawclawTrigger; }