import type { BehaviorInput, GameAction, Position, } from '../behavior-plugin/index.js'; import { behaviorDistance } from './model.js'; const MOVE_TARGET_EPSILON = 10; /** Activation-local semantic move dedupe driven only by authoritative State/Event. */ export class SemanticMoveGate { private target?: Position; private stopOnPlayer = false; private submittedEpoch?: number; clear(): void { this.target = undefined; this.submittedEpoch = undefined; } propose( input: Readonly, target: Readonly, stopOnPlayer = false, thinkingContent?: string, ): Readonly | undefined { const terminalMovement = input.events.some((event) => ( event.type === 'move_end' || event.type === 'move_interrupted' )); if (terminalMovement || ( this.submittedEpoch !== undefined && input.epochId > this.submittedEpoch && input.gameState.you?.activity?.kind !== 'moving' )) this.clear(); const repeats = this.target !== undefined && behaviorDistance(this.target, target) <= MOVE_TARGET_EPSILON && this.stopOnPlayer === stopOnPlayer; if (repeats && input.gameState.you?.activity?.kind === 'moving') return undefined; this.target = { x: target.x, y: target.y }; this.stopOnPlayer = stopOnPlayer; this.submittedEpoch = input.epochId; return { action: 'move', target_x: target.x, target_y: target.y, ...(stopOnPlayer ? { stop_on_player: true } : {}), ...(thinkingContent ? { thinking_content: thinkingContent } : {}), }; } }