/** * Standing orders (Studio OS behaviour 10) — the store. * * Plain-words rules for when the operator is busy or away, kept as STRUCTURED rules the operator * confirmed (never a guess: the seat's parse is shown back and only the confirmed rule is stored). * * The durable record is the AUDIT TRAIL, like retry lineage and guidance (`GuidanceIndex`): every * change is one entry — `standing-order.created {standingOrder, rule}`, `standing-order.retired`, * `standing-order.away {away}`, `standing-order.notified {standingOrder, messageId, text}` (the * queued outbox) — and this class is the in-memory fold of them, hydrated once at boot. No file of * its own under the state home (a new top-level entry there is one core's worker fence refuses). * * THE INVARIANT lives here as a validation (`refusal`) and again in the evaluator: an order never * approves the deliver gate and never approves a finding. It approves a plan approval only as a * TRUST RECEIPT (brainstorm idea 13): one project, one preset, and the lowest band (`0-19`) — and * the evaluator re-reads the open plan gate's own band and risk before it answers. */ import { z } from 'zod'; import type { AuditLog } from '../api/audit.js'; import type { Actor } from '../core/types.js'; export declare const StandingOrderRuleSchema: z.ZodObject<{ scope: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"all">; }, "strict", z.ZodTypeAny, { kind: "all"; }, { kind: "all"; }>, z.ZodObject<{ kind: z.ZodLiteral<"project">; projectId: z.ZodString; }, "strict", z.ZodTypeAny, { kind: "project"; projectId: string; }, { kind: "project"; projectId: string; }>]>; trigger: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"gate">; phase: z.ZodString; band: z.ZodOptional; preset: z.ZodOptional; }, "strict", z.ZodTypeAny, { kind: "gate"; phase: string; preset?: string | undefined; band?: string | undefined; }, { kind: "gate"; phase: string; preset?: string | undefined; band?: string | undefined; }>, z.ZodObject<{ kind: z.ZodLiteral<"finding">; severity: z.ZodEnum<["high", "medium", "*"]>; }, "strict", z.ZodTypeAny, { kind: "finding"; severity: "*" | "high" | "medium"; }, { kind: "finding"; severity: "*" | "high" | "medium"; }>]>; action: z.ZodEnum<["approve", "hold", "notify"]>; activeWhen: z.ZodEnum<["away", "always"]>; }, "strict", z.ZodTypeAny, { scope: { kind: "all"; } | { kind: "project"; projectId: string; }; action: "notify" | "approve" | "hold"; trigger: { kind: "gate"; phase: string; preset?: string | undefined; band?: string | undefined; } | { kind: "finding"; severity: "*" | "high" | "medium"; }; activeWhen: "always" | "away"; }, { scope: { kind: "all"; } | { kind: "project"; projectId: string; }; action: "notify" | "approve" | "hold"; trigger: { kind: "gate"; phase: string; preset?: string | undefined; band?: string | undefined; } | { kind: "finding"; severity: "*" | "high" | "medium"; }; activeWhen: "always" | "away"; }>; export type StandingOrderRule = z.infer; export interface StandingOrder { id: string; /** The operator's own words. */ text: string; rule: StandingOrderRule; createdAt: number; } /** A message an order wants sent. Outbound is only ever QUEUED — no sender exists. */ export interface QueuedMessage { id: string; orderId: string; orderText: string; runId: string | null; text: string; at: number; status: 'queued'; } export interface StandingOrdersState { away: boolean; awaySince: number | null; orders: StandingOrder[]; outbox: QueuedMessage[]; } /** The phase name a plan-approval trust order triggers on. */ export declare const PLAN_APPROVAL_PHASE = "plan_approval"; /** The only band whose plan approval an order may answer: the lowest. */ export declare const TRUSTED_PLAN_BAND = "0-19"; /** Why a rule may not be stored, or null. The code invariant, stated once for creation. */ export declare function refusal(rule: StandingOrderRule): string | null; /** The trail actions this store folds, oldest first. */ export declare const STANDING_ORDER_ACTIONS: readonly ["standing-order.created", "standing-order.retired", "standing-order.away", "standing-order.notified"]; export declare function orderActor(o: Pick): Actor; export declare class StandingOrderStore { private readonly audit; private state; constructor(audit: Pick); /** Fold the trail's standing-order entries (best-effort: an unreadable trail starts empty, said). */ hydrate(trail: Pick, log?: (msg: string) => void): Promise; private fold; /** Record one change and fold it, so memory and the trail cannot disagree. */ private write; snapshot(): StandingOrdersState; get away(): boolean; orders(): readonly StandingOrder[]; /** Returns whether the flag changed. */ setAway(away: boolean, actor: Actor): boolean; add(text: string, rule: StandingOrderRule, actor: Actor): StandingOrder; remove(id: string, actor: Actor): boolean; /** Queue a message an order wants sent — recorded as the order's `standing-order.notified`. */ queue(o: StandingOrder, runId: string, text: string): QueuedMessage; } //# sourceMappingURL=store.d.ts.map