/** * Runtime shape guard for event-log lines — the read side of the EventStore * trust boundary. * * The per-session JSONL is parsed back into `MoxxyEvent`s on every resume/ * attach (`restoreEvents`), every history page (`readEventPage`), and every * index hydration (`matchingSessionStatsFromLog`). Corrupt-JSON lines were * always skipped, but a structurally-valid-but-wrong-shape line used to be * CAST straight to `MoxxyEvent` and then drive replay and state * reconstruction — e.g. a `compaction` line missing `replacedRange`/`summary` * throws inside `projectMessagesFromLog`'s unconditional * `event.summary.trim()` / `event.replacedRange[0]` dereferences, mid-replay. * This guard closes that gap: wrong-shape lines are skipped with the exact * same semantics as corrupt lines (never throw, never truncate what follows). * * CALIBRATION — why this is a shallow structural check, not a full schema: * * `restoreEvents` REWRITES the repaired log after skipping bad lines, so a * false positive here permanently deletes history. The guard therefore * rejects only shapes that would actively corrupt replay, and tolerates * benign drift: * * - Envelope: strict on the fields the replay machinery itself dereferences * (`id`, `seq`, `ts`, `type` — mirrors dedupe by `id`, ingest/paging/ * re-sequencing key on numeric `seq`). Lenient-if-present on `sessionId` / * `turnId` / `source`: the existing session-ownership path already * tolerates and normalizes a missing `sessionId` * (`eventBelongsToSession`), and none of these are dereferenced in a way * that can throw. * - Unknown `type` with a valid envelope is KEPT, not dropped: every * downstream fold pattern-matches known types and ignores the rest (there * is no exhaustive-switch throw), and the desktop floor mechanism makes * "older core replaying a newer log" a designed scenario — dropping (and * then rewriting away) a newer version's events on rollback would be * silent history loss. This matches the pre-guard behavior for that class * of line exactly. * - Known `type`: the variant's required primitive fields are checked * shallowly (`typeof` / `Array.isArray`), because the projection folds * dereference them unconditionally. Enum-valued strings (`stopReason`, * `decidedBy`, …) are checked as `string` only — a newer version adding an * enum member must not get its events dropped by an older reader. * * LOCKSTEP — the spec map below is typed so it cannot drift from the union: * it is exhaustive over `MoxxyEventType` (adding a variant fails the build * until a spec is added) and each spec's keys must be required non-envelope * keys of that exact variant (renaming/removing a field fails the build). * Listing a field is optional per-variant, so a future required field can be * deliberately left unchecked for back-compat (old logs won't have it) — omit * with a comment when doing so. * * PERFORMANCE — this runs once per line while iterating whole logs on the * replay hot path. It allocates nothing per call: a handful of `typeof` * checks plus an indexed walk over a per-variant spec array precomputed at * module load. (This is also why it is hand-rolled rather than zod: a parsed * schema library allocates per-line result/issue objects and would * deep-validate bulky payloads — attachments, tool outputs — that replay * never dereferences structurally.) */ import type { MoxxyEvent } from '@moxxy/sdk'; /** * True when `value` (a successfully-parsed JSONL line) is structurally safe to * replay as a {@link MoxxyEvent}. See the module doc for what "safe" means — * this is a calibrated floor (reject what corrupts replay, keep benign * drift), not a proof of full conformance: an unknown newer event type with a * valid envelope passes, exactly as it (unvalidated) did before this guard. */ export declare function isMoxxyEventShape(value: unknown): value is MoxxyEvent; //# sourceMappingURL=event-shape.d.ts.map