import type { GoalCompletionProposal } from "../core/proposal.js"; import type { OracleDecision } from "./oracle.js"; import type { GoalRecord } from "../store/events.js"; export declare const DEFAULT_GOAL_MAX_TURNS = 80; export declare const DEFAULT_RESUME_TURN_EXTENSION = 12; /** Mirrors the 3b store objective cap so overlay and stream shapes agree. */ export declare const MAX_RUNTIME_GOAL_OBJECTIVE_CHARS = 8192; export type RuntimeGoalStatus = "active" | "ready_for_oracle" | "oracle_failed" | "paused" | "blocked" | "budget_limited" | "complete"; export declare const RUNTIME_GOAL_STATUSES: readonly RuntimeGoalStatus[]; export declare function asRuntimeGoalStatus(value: unknown): RuntimeGoalStatus | undefined; /** zob resume gate: only these statuses may resume (with a reason). */ export declare const RESUMABLE_GOAL_STATUSES: ReadonlySet; export type GoalActivationMode = "manual" | "validation" | "auto"; export declare const GOAL_ACTIVATION_MODES: readonly GoalActivationMode[]; export declare const DEFAULT_GOAL_ACTIVATION_MODE: GoalActivationMode; export declare function asGoalActivationMode(value: unknown): GoalActivationMode | undefined; /** zob parity: exact activation-mode description strings. */ export declare function formatGoalActivationMode(mode: GoalActivationMode | undefined): string; /** zob GoalState gate (structured goal), carried verbatim when present. */ export interface RuntimeGoalGate { readonly originalUserAsk: string; readonly activeGoal: string; readonly constraints: string; readonly expectedOutput: string; readonly validationEvidence: string; readonly setAt: string; } export interface RuntimeGoalUsage { readonly tokensUsed: number; readonly activeSeconds: number; readonly turnsUsed: number; readonly costUsed?: number; } export interface RuntimeGoalLoop { readonly enabled: boolean; readonly maxTurns: number; readonly customMaxTurns?: boolean; } /** * Strict runtime goal (single schema). The 6-key projection is the 3b store * GoalRecord; gate/oracleDecision/completionProposal/usage/loop persist in * the engine-owned runtime overlay next to the goal stream. */ export interface RuntimeGoal { readonly goalId: string; readonly objective: string; readonly status: RuntimeGoalStatus; readonly gate?: RuntimeGoalGate; readonly oracleDecision?: OracleDecision; readonly completionProposal?: GoalCompletionProposal; readonly usage: RuntimeGoalUsage; readonly loop: RuntimeGoalLoop; readonly revision: number; readonly createdAt: number; readonly updatedAt: number; } /** * STRICT normalize (D-G1): the exact key set, a canonical goal id, a * non-empty objective (≤ store cap), an enum status, exact usage/loop/gate * shapes, strictly validated 3a proposal and oracle decision (hash * recompute included), revision ≥ 1, and safe-integer timestamps. Any * deviation resolves to undefined — there is no legacy interpretation. */ export declare function normalizeRuntimeGoal(value: unknown): RuntimeGoal | undefined; export interface CreateRuntimeGoalOptions { /** Canonical goal id (goal_ + 12 lowercase hex); the engine generates it. */ readonly goalId: string; /** Injected epoch-milliseconds timestamp. */ readonly now: number; readonly maxTurns?: number; readonly gate?: RuntimeGoalGate; } /** Build the canonical fresh goal: active, revision 1, zero usage, loop on. */ export declare function createRuntimeGoal(objective: string, options: CreateRuntimeGoalOptions): RuntimeGoal; /** Project the exact 6-key 3b store record (goal_set payload). */ export declare function runtimeGoalToRecord(goal: RuntimeGoal): GoalRecord; /** * Rebuild the degraded runtime view from a bare store record (overlay lost * or stale): status/revision/objective survive, gate/proposal/decision and * usage/loop customizations are gone — completion paths fail closed and * must be re-proposed. */ export declare function runtimeGoalFromRecord(record: GoalRecord): RuntimeGoal; /** zob create gate: creation fails while ANY non-complete goal is active. */ export declare function canCreateRuntimeGoal(existing: RuntimeGoal | undefined): boolean; /** zob pause gate: only an active goal pauses; the loop is switched off. */ export declare function pauseRuntimeGoal(goal: RuntimeGoal, now: number): RuntimeGoal; export interface ResumeRuntimeGoalResult { readonly goal: RuntimeGoal; readonly previousStatus: RuntimeGoalStatus; readonly additionalTurns?: number; } /** * zob resume gate + turn-window rule (D-G5): resume only from * paused/blocked/oracle_failed/budget_limited with a non-empty reason; the * window extends by the default +12 (or the explicit extraTurns, 0 → 1) * when it is exhausted or extraTurns is provided, floored at maxTurns. * Returns undefined when the gate rejects. */ export declare function resumeRuntimeGoal(goal: RuntimeGoal, reason: string, options: { now: number; extraTurns?: number; }): ResumeRuntimeGoalResult | undefined; export interface RuntimeGoalUsageDelta { readonly tokensUsed?: number; readonly activeSeconds?: number; readonly costUsed?: number; } /** * Account usage deltas on an ACTIVE goal (non-active goals are returned * untouched, zob accountElapsed parity). Deltas are clamped to ≥ 0; cost * deltas accumulate as finite non-negative numbers. */ export declare function accountRuntimeGoalUsage(goal: RuntimeGoal, delta: RuntimeGoalUsageDelta, now: number): RuntimeGoal; export interface RuntimeGoalTurnInput { readonly tokensUsed?: number; readonly costUsed?: number; /** True only for goal-continuation turns (zob countAutoTurn). */ readonly countAutoTurn?: boolean; readonly stopReason?: "aborted" | "error"; } export interface RuntimeGoalTurnResult { readonly goal: RuntimeGoal; readonly turnCounted: boolean; readonly turnLimitReached: boolean; readonly statusChangedTo?: RuntimeGoalStatus; } /** * Account one assistant turn purely (D-G4): token/cost deltas accumulate, * auto turns increment turnsUsed, and the zob stop gates apply — aborted → * paused (loop off), provider error → blocked (loop off), turn limit → * blocked (loop off). Non-active goals are never accounted (same reference * returned). */ export declare function accountRuntimeGoalTurn(goal: RuntimeGoal, input: RuntimeGoalTurnInput, now: number): RuntimeGoalTurnResult;