import { type WorkItem, type WorkItemSource, type WorkItemStatus } from './store.js'; import { type WorkItemAttemptEvidence } from './attempt-evidence.js'; export type { WorkItemAttemptEvidence } from './attempt-evidence.js'; /** Declaration provenance that cannot be derived from attempt receipts alone. */ export interface DeriveWorkItemOptions { blockDeclared?: boolean; reviewBounceDeclared?: boolean; } /** * Pure derivation: given an item's current status, its provenance, and the * terminal receipts of its linked sessions **ordered newest-first** (as * `listSessionsByWorkItem` returns them, by `last_activity DESC`), return the * status the item SHOULD have. Never yields a sticky terminal — `done` is a * policy/human decision layered on top by the TRUST hook. */ export declare function deriveWorkItemStatus(current: WorkItemStatus, attempts: readonly WorkItemAttemptEvidence[], source?: WorkItemSource, opts?: DeriveWorkItemOptions): WorkItemStatus; export interface ReconcileResult { item: WorkItem; changed: boolean; } /** * Reconcile a single work item from its linked sessions, then apply the TRUST * auto-close hook. Returns the (possibly updated) item and whether anything * changed, or undefined if the id is unknown. A no-op when the derived status * already matches — no write, no `updated_at` churn, no events. */ export declare function reconcileWorkItem(id: string): ReconcileResult | undefined; export interface ReconcileSweepResult { checked: number; changed: number; } /** * Reconcile every non-sticky item. Invoked at gateway startup right after * `recoverStaleSessions()` (the exact moment `running` sessions became * `interrupted`, so their items must move to `blocked`) and periodically by * `startWorkItemReconciler` (so settles reach `in_review`/`done` while the * gateway runs, not just at the next boot). One indexed session query per * candidate — negligible at this table's scale (see GRS-003a's note). */ export declare function reconcileActiveWorkItems(): ReconcileSweepResult; /** * Startup hook: repair the run ledger, reconcile work items, and log a one-line * summary. Best-effort — a reconcile failure must never block gateway boot * (mirrors the cron consumer's guard). Returns the count of items whose status * changed (0 on any error); a settled run is a ledger repair, not a status * change, so those are deliberately not counted. */ export declare function reconcileWorkItemsOnStartup(): number; /** * Periodic work-item reconcile (GRS-021a): without it, a session that settles * mid-process would only reach `in_review`/`done` at the NEXT boot or the next * mint-time reconcile — a stale ledger, the exact failure Todos exist to kill. * Same primitive as the gateway's status reconciler (unref'd interval, one * guarded sweep per tick, ticks never overlap because the sweep is synchronous). * Returns a stop function. */ export declare function startWorkItemReconciler(intervalMs?: number): () => void; //# sourceMappingURL=reconcile.d.ts.map