/** * refactor.ts — detect duplicated event logic worth consolidating. * * Copy-pasted command sequences are the most common source of event-logic rot: * the same shop/heal/cutscene block lives in five NPCs and they drift apart. * This finds identical contiguous command runs shared across events / common * events and suggests extracting them into a Common Event (called with command * 117), so a fix happens in one place. * * Read-only analysis (roadmap #9). It proposes; the editor tools act. */ import type { RawCommand } from "./eventAst.js"; export interface RefactorSource { label: string; commands: RawCommand[]; } export interface DuplicateOccurrence { label: string; startIndex: number; } export interface DuplicateBlock { length: number; occurrences: DuplicateOccurrence[]; /** Command codes of the shared run, for a quick eyeball. */ codes: number[]; suggestion: string; } export interface RefactorReport { blockCount: number; duplicateBlocks: DuplicateBlock[]; } /** * Find identical command runs of at least `minLen` shared by 2+ locations. * Reports each maximal run once with all the places it appears. */ export declare function detectDuplicates(sources: RefactorSource[], minLen?: number, maxResults?: number): RefactorReport;