/** * Single owner of multi-file compilation. Parses every reachable agency * file from an entry, builds a shared SymbolTable, runs the per-variable * dep graphs (static + global) plus topological sort, and produces an * `InitPlan` per module that codegen consumes to drive its centralized * init. * * Both `lib/cli/commands.ts:compile()` (CLI: writes files to disk) and * `lib/compiler/compile.ts:compileSource()` (in-memory: returns a string) * call this helper, then walk the result's modules and codegen each. The * recursive `compile()` cascade that used to re-enter per file is gone — * the closure is built once, in one place. * * Errors surface as exceptions of type `CompileClosureError`. The CLI * path turns them into stderr + `process.exit(1)`; the in-memory path * returns them as `CompileFailure`. */ import type { AgencyProgram, AgencyNode } from "../types.js"; import { AgencyConfig } from "../config.js"; import { SymbolTable } from "../symbolTable.js"; import { type ImportAliasResolver, type InitDepGraph } from "./initDepGraph.js"; export declare class CompileClosureError extends Error { constructor(message: string); } /** * The per-module init plan codegen consumes. For Phase A (static) and * Phase B (global), captures: * - `localOrder`: the topsort-ordered subset of local var names in * this module. Codegen emits assignments in this order rather than * source order. * - `awaitModules`: other modules whose init must complete before * this module's local init body runs. Computed from cross-module * edges in the dep graph. Codegen emits an `await * .__initializeStatic(ctx)` at the head of this * module's `__initializeStatic` for each entry. */ export type ModuleInitPhasePlan = { localOrder: string[]; awaitModules: string[]; }; export type ModuleInitPlan = { moduleId: string; static: ModuleInitPhasePlan; global: ModuleInitPhasePlan; }; export type CompiledClosure = { /** Map from absolute module path to parsed program. */ programs: Record; /** Shared symbol table for the entire closure. */ symbolTable: SymbolTable; /** The entry module's absolute path. */ entryModuleId: string; /** Static dep graph (Phase A). */ staticGraph: InitDepGraph; /** Global dep graph (Phase B). */ globalGraph: InitDepGraph; /** Resolver used by codegen for PR-1 thread-through. */ resolver: ImportAliasResolver; /** Topsort-derived per-module init plans. Keyed by moduleId. */ plans: Record; }; /** * Parse + analyze the entry's full import closure. Throws * `CompileClosureError` for parse failures, cycle errors, or * static-references-global violations. The caller decides how to * surface the error (CLI: exit; in-memory: collect). */ export declare function buildCompiledClosure(entryFile: string | string[], config: AgencyConfig): CompiledClosure; export declare function agencyImportTargets(program: AgencyProgram, moduleId: string): string[]; /** * The one source of truth for "what is an import edge". Recognizes * importStatement, importNodeStatement, AND exportFromStatement — a * hand-rolled importStatement-only scan lets `export { x } from "zod"` * escape, which for splice eligibility means a generator reaching * JavaScript at compile time. * * Exported for `lib/compiler/splice/eligibility.ts`, the second caller * `loadModule`'s comment below anticipated. Note this is the SINGULAR * extractor: `agencyImportTargets` (plural) pre-filters std::, pkg::, and * non-Agency targets, which is exactly the set eligibility must inspect. */ export declare function agencyImportTarget(node: AgencyNode): string | null; /** * True when the program has any pkg:: import edge. Routed through the * SAME extraction as the closure walker (agencyImportTarget), which * recognizes importStatement, importNodeStatement, AND * exportFromStatement — a hand-rolled importStatement-only scan would let * `export { x } from "pkg::…"` escape the incremental-build never-skip. * One source of truth for "what is an import edge". */ export declare function programHasPkgImport(program: AgencyProgram): boolean; /** * Convenience: build the closure and look up one module's plan, or an * empty default if the module isn't in the closure. Used by codegen * entry points that already have a CompiledClosure on hand. */ export declare function planFor(closure: CompiledClosure, moduleId: string): ModuleInitPlan;