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"; /** Decoded text for text targets (interpolations rendered as `${...}` — * the `expected`-guard contract); the EXACT source slice, quotes intact, * for literal targets. */ value: 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; 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; }; export declare function sha256Text(value: string): string; /** * 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; /** Absolute base directory of `entryFile`'s local import closure — the seed * directory for a run. Shared by the optimizer (as `source.baseDir`) and by * plain eval, so both compute the same default seed when no explicit one is * given. */ export declare function agentClosureBaseDir(entryFile: string): string; /** * 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 prompt segments back to the decoded target value representation: * literal text with interpolations re-rendered as `${expr}`. This is the * representation stored in `OptimizeTarget.value` and the one `expected` * guards compare against. */ export declare function promptSegmentsToString(segments: PromptSegment[]): string; /** A relpath→source map for a target set (e.g. the unchanged baseline file set). */ export declare function fileMap(source: OptimizeTargetSet): Record;