import type { AgencyProgram, Assignment, PromptSegment, TypeAliasEntry } from "../types.js"; export type OptimizeTarget = { id: string; kind: "variable"; file: string; absoluteFile: string; scope: string; name: string; valueKind: "string" | "multilineString" | "literal"; /** The plain text for text targets, with interpolations rendered as * `${expr}` (the `expected`-guard contract); the EXACT source slice, * quotes intact, for literal targets. */ value: string; /** The interpolations a text target carries, as canonical expression * text, sorted. A replacement must keep exactly these. Empty for * literal targets. */ interpolations: string[]; /** Parseable type text proposals are probed against (constraint.ts). * `null` means FREEFORM for text targets (today's string-only semantics, * interpolation rule and all) and UNCONSTRAINED for literal targets (any * literal accepted). Consumers must branch on `valueKind` first. */ declaredType: string | null; }; export type OptimizeSourceFile = { file: string; absoluteFile: string; source: string; sha256: string; }; export type OptimizeTargetSet = { baseDir: string; entryFile: string; /** The node each candidate runs, from the `file.agency:node` target; `main` when unset. */ entryNode?: string; files: Record; targets: OptimizeTarget[]; /** Global type aliases visible across the import closure, in the exact * registry shape the typechecker consumes (`TypeAliasEntry`). Built by the * compiler's own pipeline (SymbolTable + buildCompilationUnit), plain * data — serializable. Consumed by the typed-target probe (constraint.ts). */ typeAliases: Record; }; export type DiscoverOptimizeTargetsOptions = { baseDir?: string; }; /** A discovered target paired with its `Assignment` node in the parsed * program, for consumers (like the source mutator) that edit the AST. */ export type OptimizeTargetNode = { target: OptimizeTarget; assignment: Assignment; }; /** * Discovers optimize targets across the local Agency import closure of * `entryFile`. This is the single parse pass over the closure: when * `options.baseDir` is omitted, the base/working directory is computed from * the walked closure itself (its common ancestor directory, unless that * lies inside the current working directory, in which case cwd wins) — so * callers never need a second closure walk to pick a working dir. */ export declare function discoverOptimizeTargets(entryFile: string, options?: DiscoverOptimizeTargetsOptions): OptimizeTargetSet; /** * Collects the optimize targets declared in one parsed program, paired with * their `Assignment` nodes. Discovery uses the target halves; the source * mutator uses the assignment nodes to replace initializers and this same * function to refresh target entries after rendering a candidate. */ export declare function collectTargets(program: AgencyProgram, file: string, absoluteFile: string, typeAliases: Record, priorTargets?: Record): OptimizeTargetNode[]; /** * Renders a string literal's segments as the plain text a mutator model * sees: text verbatim, interpolations as `${expr}`. This is * `OptimizeTarget.value` for text targets and what `expected` guards * compare against. The model returns text in the same form, and every * `${...}` in what it returns is read as an interpolation, so a literal * `${` in a target's text cannot survive a mutation; see * `literalInterpolationWarnings`. */ export declare function promptSegmentsToString(segments: PromptSegment[]): string; /** * One warning per text target whose text contains a literal `${`. The * mutator reads every `${...}` it writes as an interpolation, so such a * target cannot be reproduced faithfully; say `${` another way. */ export declare function literalInterpolationWarnings(targets: OptimizeTarget[]): string[]; /** A relpath→source map for a target set (e.g. the unchanged baseline file set). */ export declare function fileMap(source: OptimizeTargetSet): Record;