{"version":3,"file":"snapshot-selector-resolver.d.ts","sourceRoot":"","sources":["../../src/core/snapshot-selector-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,gEAAgE;AAChE,eAAO,MAAM,+BAA+B,IAAI,CAAC;AAEjD,qEAAqE;AACrE,MAAM,MAAM,uBAAuB,GAAG,OAAO,GAAG,WAAW,GAAG,WAAW,CAAC;AAE1E;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IAClC,QAAQ,EAAE,qBAAqB,GAAG,SAAS,CAAC;IAC5C,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,KAAK,EAAE,uBAAuB,GAAG,SAAS,CAAC;IAC3C,UAAU,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO/D;AAED,mFAAmF;AACnF,wBAAgB,uBAAuB,CACtC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,SAAS,qBAAqB,EAAE,GACzC,kBAAkB,CAiEpB","sourcesContent":["import type { MemoryHistorySnapshot } from \"./memory.js\";\n\n/** Displayed short ID length used in /memory history output. */\nexport const MEMORY_SNAPSHOT_SHORT_ID_LENGTH = 8;\n\n/** Machine-readable error codes for snapshot selector resolution. */\nexport type SnapshotResolutionError = \"empty\" | \"not_found\" | \"ambiguous\";\n\n/**\n * Result of strict snapshot selector resolution.\n *\n * Contract:\n * - `matchedInput` is always the normalized selector actually evaluated\n * - `resolvedId` is the full `entryId` when resolution succeeds\n * - `candidates` is populated only for ambiguous-prefix failures\n */\nexport interface SnapshotResolution {\n\tsnapshot: MemoryHistorySnapshot | undefined;\n\tmatchedInput: string;\n\tresolvedId: string | undefined;\n\terror: SnapshotResolutionError | undefined;\n\tcandidates: string[];\n}\n\n/**\n * Normalize a raw snapshot selector typed or pasted by the operator.\n *\n * Accepted normalization rules:\n * - trim surrounding whitespace\n * - strip one pair of surrounding brackets copied from `/memory history`\n * - treat `[]` as empty input\n */\nexport function normalizeSnapshotSelector(input: string): string {\n\tconst trimmed = input.trim();\n\tif (trimmed === \"[]\") {\n\t\treturn \"\";\n\t}\n\n\treturn trimmed.replace(/^\\[([^\\]]+)\\]$/, \"$1\").trim();\n}\n\n/** Resolve a snapshot selector against a provided current-branch snapshot list. */\nexport function resolveSnapshotSelector(\n\tselector: string,\n\tsnapshots: readonly MemoryHistorySnapshot[],\n): SnapshotResolution {\n\tconst matchedInput = normalizeSnapshotSelector(selector);\n\tif (!matchedInput) {\n\t\treturn {\n\t\t\tsnapshot: undefined,\n\t\t\tmatchedInput,\n\t\t\tresolvedId: undefined,\n\t\t\terror: \"empty\",\n\t\t\tcandidates: [],\n\t\t};\n\t}\n\n\tconst exactFullMatch = snapshots.find((snapshot) => snapshot.entryId === matchedInput);\n\tif (exactFullMatch) {\n\t\treturn {\n\t\t\tsnapshot: exactFullMatch,\n\t\t\tmatchedInput,\n\t\t\tresolvedId: exactFullMatch.entryId,\n\t\t\terror: undefined,\n\t\t\tcandidates: [],\n\t\t};\n\t}\n\n\tconst exactShortMatch = snapshots.find(\n\t\t(snapshot) => snapshot.entryId.slice(0, MEMORY_SNAPSHOT_SHORT_ID_LENGTH) === matchedInput,\n\t);\n\tif (exactShortMatch) {\n\t\treturn {\n\t\t\tsnapshot: exactShortMatch,\n\t\t\tmatchedInput,\n\t\t\tresolvedId: exactShortMatch.entryId,\n\t\t\terror: undefined,\n\t\t\tcandidates: [],\n\t\t};\n\t}\n\n\tconst prefixMatches = snapshots.filter((snapshot) => snapshot.entryId.startsWith(matchedInput));\n\tif (prefixMatches.length === 1) {\n\t\tconst uniquePrefixMatch = prefixMatches[0]!;\n\t\treturn {\n\t\t\tsnapshot: uniquePrefixMatch,\n\t\t\tmatchedInput,\n\t\t\tresolvedId: uniquePrefixMatch.entryId,\n\t\t\terror: undefined,\n\t\t\tcandidates: [],\n\t\t};\n\t}\n\n\tif (prefixMatches.length > 1) {\n\t\treturn {\n\t\t\tsnapshot: undefined,\n\t\t\tmatchedInput,\n\t\t\tresolvedId: undefined,\n\t\t\terror: \"ambiguous\",\n\t\t\tcandidates: prefixMatches.map((snapshot) => snapshot.entryId),\n\t\t};\n\t}\n\n\treturn {\n\t\tsnapshot: undefined,\n\t\tmatchedInput,\n\t\tresolvedId: undefined,\n\t\terror: \"not_found\",\n\t\tcandidates: [],\n\t};\n}\n"]}