import { CompiledWorkflow, Ctx, Engine, InMemoryStore, JournalEntry, Json, ModelSpec, RunHandle, RunOptions, ScriptRejected, ScriptRunner } from "@rulvar/core"; //#region src/compile.d.ts /** * The exact curated sandbox global set, in canonical order. * The worker binds the ctx methods as bare globals under these names and * the API card teaches exactly this list. */ declare const SANDBOX_GLOBALS: readonly string[]; /** One machine-readable compileScript diagnostic (carried by ScriptRejected). */ interface ScriptDiagnostic { ruleId: string; message: string; line?: number; column?: number; } interface CompileScriptOptions { /** Dynamic-import specifiers permitted in the source; default [] (none). */ allowImports?: string[]; } /** * Validates and compiles planner-generated source into a CompiledWorkflow. * The source is an async function body over the sandbox * globals; its `return` value is the workflow result. The compiled form is * pure data (the source is evaluated only inside the worker sandbox); * machine scripts run under errorPolicy 'lenient'. */ declare function compileScript(source: string, o?: CompileScriptOptions): CompiledWorkflow; /** Typed accessor for the diagnostics carried on a ScriptRejected. */ declare function scriptDiagnosticsOf(error: ScriptRejected): ScriptDiagnostic[]; //#endregion //#region src/api-card.d.ts /** Renders the sandbox-dialect API card; pure and byte-stable. */ declare function apiCard(): string; //#endregion //#region src/plan.d.ts /** One repair-loop diagnostic: lint and compile findings share the shape. */ interface PlanDiagnostic { ruleId: string; message: string; line?: number; column?: number; severity: "error" | "warning"; } interface PlanOptions { /** The planner model; otherwise the chain resolves role 'plan'. */ model?: ModelSpec; /** Registered profile names to advertise; default: every profile. */ profiles?: string[]; /** * Self-repair rounds from JSON diagnostics; default 3 (Appendix A). A * nonnegative integer (zero means a single draft, no repair), refused * as a ConfigError before the runId derivation, store lookup, and any * provider dispatch. */ repairRounds?: number; /** * Run options of the planning conversation itself, applied at GENESIS * only: the first plan() of a goal starts the journal with them, and * budgetUsd becomes the run's immutable ceiling B0, recorded in * RunMeta. A later plan() of the same goal resumes the existing * journal under its RECORDED ceiling: a differing explicit budgetUsd * warns (RULVAR_PLAN_BUDGET_DRIFT) and never tops up or replaces the * frozen value, and limits/deadlineAt/signal do not apply to a * resumed journal (core resume semantics; cancel through the handle). * The runId stays goal-derived (planRunIdOf) and is not overridable. * Absent options, the planning run is UNBOUNDED, as before. */ run?: Pick; } interface RunPlannedOptions { /** Options of the planning conversation (see plan()). */ plan?: PlanOptions; /** * RunOptions of the generated workflow's execution run, passed to * engine.run verbatim (budgetUsd here is the EXECUTION ceiling, * independent of the planning ceiling). Absent, the execution run is * UNBOUNDED, as before. */ run?: RunOptions; } interface PlanResult { source: string; workflow: CompiledWorkflow; /** Diagnostics of the ACCEPTED draft: advisories only, never errors. */ lint: PlanDiagnostic[]; } /** The deterministic planner runId: one goal, one journal. */ declare function planRunIdOf(goal: string): string; /** * The model may fence the script; the extractor takes the first fenced * block when one exists, else the whole reply, and is deterministic. */ declare function extractScript(reply: string): string; /** * Lints a script BODY with the workflows preset plus compileScript. * The body is wrapped in an async function for parsing (top-level * return/await are legal in the dialect); reported lines shift back so * they index into the body source. */ declare function lintScript(source: string): { diagnostics: PlanDiagnostic[]; errors: PlanDiagnostic[]; workflow?: CompiledWorkflow; }; declare function plan(engine: Engine, goal: string, o?: PlanOptions): Promise; /** * plan-then-run in one call (amended during M6-T05: * the composition is async because planning itself is a run). * options.plan bounds the planning conversation, options.run bounds the * generated workflow's execution; the two ceilings are independent, and * the bare form without options runs BOTH legs unbounded, as before. */ declare function runPlanned(engine: Engine, goal: string, args?: Json, options?: RunPlannedOptions): Promise>; //#endregion //#region src/cassettes.d.ts /** The M3-convention cassette normalization: wall clock and spans only. */ declare function normalizeCassetteEntries(entries: readonly JournalEntry[]): JournalEntry[]; declare const SANDBOX_DETERMINISM_RUN_ID = "m6-sandbox-determinism"; /** A script exercising agents, parallel, step, and every seeded shim. */ declare const SANDBOX_DETERMINISM_SOURCE: string; /** * One fresh sandbox-determinism run on a fresh store; two invocations * with the same worker produce byte-identical normalized journals (the * cassette assertion). The adapter factory keeps @rulvar/testing out of * the planner's dependency graph. */ declare function runSandboxDeterminism(options: { workerUrl: URL; makeAdapter: () => unknown; modelRef: string; }): Promise; declare const SELF_REPAIR_GOAL = "m6 cassette: summarize the corpus"; /** The failing first draft: bare Date.now trips rulvar/no-bare-date. */ declare const SELF_REPAIR_BAD_DRAFT: string; /** The repaired draft the fake planner returns once diagnostics arrive. */ declare const SELF_REPAIR_GOOD_DRAFT: string; declare const SELF_REPAIR_RUN_ID: string; /** * One planner-self-repair run: the first draft fails lint, the JSON * diagnostics ride the repair prompt, the second draft compiles. Returns * the normalized planning journal plus the plan result. */ declare function runPlannerSelfRepair(options: { makeAdapter: () => unknown; modelRef: string; store?: InMemoryStore; seedEntries?: JournalEntry[]; }): Promise<{ entries: JournalEntry[]; planned: PlanResult; engine: Engine; }>; /** The cassette file shape shared with the M3 sets. */ interface M6CassetteFixture { id: string; note: string; entries: JournalEntry[]; extra?: Json; } //#endregion //#region src/sandbox-runner.d.ts declare const DEFAULT_SANDBOX_TIMEOUT_MS = 3e5; declare const DEFAULT_SANDBOX_MEMORY_MB = 512; interface WorkerSandboxRunnerOptions { /** Wall-clock ceiling for one execution; default 300000 (Appendix A). */ timeoutMs?: number; /** Worker old-generation heap ceiling; default 512 (Appendix A). */ memoryMb?: number; /** * The worker entry module; defaults to the built sandbox-worker.js next * to this module. Tests running from source point at the built dist. */ workerUrl?: URL; /** * Node CLI options for the worker thread; default `[]` (an isolated * list). Without an explicit value Node would hand the worker * `process.execArgv`, and host-only launch flags break a file-entry * worker before the first sandbox operation: `--input-type=module` * (any ESM stdin or `--eval` host) is rejected for file entries, and * an inherited `--eval` carries the host's whole source text (v1.24.1 * review P2-2). Hosts that need loader, coverage, or instrumentation * flags inside the worker opt in explicitly; the list is passed to the * worker verbatim. */ execArgv?: readonly string[]; } /** Accepts CompiledWorkflow ONLY: feeding a closure is a type error. */ declare class WorkerSandboxRunner implements ScriptRunner { private readonly timeoutMs; private readonly memoryMb; private readonly workerUrl; private readonly execArgv; constructor(options?: WorkerSandboxRunnerOptions); execute(wf: CompiledWorkflow, ctx: Ctx, args: A): Promise; } //#endregion export { type CompileScriptOptions, DEFAULT_SANDBOX_MEMORY_MB, DEFAULT_SANDBOX_TIMEOUT_MS, type M6CassetteFixture, type PlanDiagnostic, type PlanOptions, type PlanResult, type RunPlannedOptions, SANDBOX_DETERMINISM_RUN_ID, SANDBOX_DETERMINISM_SOURCE, SANDBOX_GLOBALS, SELF_REPAIR_BAD_DRAFT, SELF_REPAIR_GOAL, SELF_REPAIR_GOOD_DRAFT, SELF_REPAIR_RUN_ID, type ScriptDiagnostic, WorkerSandboxRunner, type WorkerSandboxRunnerOptions, apiCard, compileScript, extractScript, lintScript, normalizeCassetteEntries, plan, planRunIdOf, runPlanned, runPlannerSelfRepair, runSandboxDeterminism, scriptDiagnosticsOf };