/** * NormalizedBlock — the flattened, pair-indexed stream the compaction pipeline operates * on (ARCHITECTURE §11). Produced by `normalize(messages)`. * * Distinct from ContentBlock: `bash` is materialized from a `bash` tool_call/result pair * (command + output + exitCode), and `tool_result` carries its name + isError so extractors * don't need to look the call back up. Pure data, wire-safe. */ import { Type, type Static } from '@sinclair/typebox'; // Names are prefixed `Normalized*` to avoid collisions with the parallel ContentBlock // schemas in content.ts when both are re-exported from the barrel. export const NormalizedUserBlockSchema = Type.Object({ kind: Type.Literal('user'), text: Type.String(), }); export const NormalizedAssistantBlockSchema = Type.Object({ kind: Type.Literal('assistant'), text: Type.String(), }); export const NormalizedToolCallBlockSchema = Type.Object({ kind: Type.Literal('tool_call'), name: Type.String(), args: Type.Record(Type.String(), Type.Unknown()), }); export const NormalizedToolResultBlockSchema = Type.Object({ kind: Type.Literal('tool_result'), name: Type.String(), text: Type.String(), isError: Type.Boolean(), }); export const NormalizedBashBlockSchema = Type.Object({ kind: Type.Literal('bash'), command: Type.String(), output: Type.String(), exitCode: Type.Optional(Type.Integer()), }); export const NormalizedThinkingBlockSchema = Type.Object({ kind: Type.Literal('thinking'), text: Type.String(), // Mirrors ThinkingBlockSchema's optional replay/redaction fields (content.ts). Carried // through normalization so compaction can preserve round-trip signatures. thinkingSignature: Type.Optional(Type.String()), redacted: Type.Optional(Type.Boolean()), }); export const NormalizedBlockSchema = Type.Union([ NormalizedUserBlockSchema, NormalizedAssistantBlockSchema, NormalizedToolCallBlockSchema, NormalizedToolResultBlockSchema, NormalizedBashBlockSchema, NormalizedThinkingBlockSchema, ]); export type NormalizedUserBlock = Static; export type NormalizedAssistantBlock = Static; export type NormalizedToolCallBlock = Static; export type NormalizedToolResultBlock = Static; export type NormalizedBashBlock = Static; export type NormalizedThinkingBlock = Static; export type NormalizedBlock = Static;