/** * Pure compilation pipeline for Agency source strings. * No process.exit(), no console.log(). Returns errors as data. */ import { AgencyConfig } from "../config/config.js"; import { ImportPolicy } from "../importPaths.js"; type CompileSuccess = { success: true; code: string; moduleId: string; /** Multi-file compiles only (compileValidatedClosure): compiled JS for * every non-entry module in the closure, keyed by the POSIX relative * path its import rewrites point at ("helper.js"). The runtime * materializes these beside the entry script. */ modules?: Record; /** Multi-file compiles only: where the entry script sits in that same * layout ("sub/main.js"), so its relative imports resolve. Absent means * the entry is materialized alone at the root. */ entryPath?: string; /** Multi-file compiles only: the absolute compiled paths of the trusted * modules this program loads (docs/dev/runtime/trusted-modules.md), * sorted. Empty or absent when it loads none. */ trustedModules?: string[]; }; type CompileFailure = { success: false; errors: string[]; }; export type CompileResult = CompileSuccess | CompileFailure; export type CompileSourceOptions = AgencyConfig & { /** * Declarative import policy. Disallowed imports cause compilation to * fail with one error per violating import path. * See `lib/importPaths.ts` for the ImportPolicy shape. */ imports?: ImportPolicy; /** * Real on-disk path of the file to compile. Given it, `compileSource` compiles * at that path — where sibling `.agency` files live — so relative imports * resolve. Without it, `source` is written to an isolated temp file, so * relative imports cannot resolve (single-file compile). A host that stores * multi-file agents on disk passes this to compile each file against its real * neighbors. * * When set, the file at this path is authoritative: it is parsed AND used for * symbol/import resolution, so the two can't diverge. The `source` argument is * ignored (pass the file's contents for clarity, but the disk file wins). */ sourcePath?: string; /** Stable module identity for checkpoint fingerprints. Omit for ephemeral * subprocess programs whose generated module id is intentionally random. */ fingerprintModuleId?: string; /** Import specifiers in this source that name a trusted module, mapped to * that module's absolute compiled path. Set by compileValidatedClosure * from the validator's record; each such import is emitted as the * compiled path instead of a mirrored sibling. */ trustedImports?: Record; }; export { typeCheckSource, getEffectsFromSource, getEffectsFromSourceAt } from "./typecheck.js"; export type { TypeCheckDiagnostic, TypeCheckReport } from "./typecheck.js"; export declare function compileSource(source: string, config: CompileSourceOptions): CompileResult;