// Shared notebook types. The on-disk format described in // docs/proposals/devmode-annotate/01-on-disk-format.md is the canonical // contract — these types are the runtime mirror of that schema. // // Re-exported from the package entrypoint so the HUD package // (@llui/devmode-annotate) and the MCP server (@llui/mcp) can pull from // one source. export type Author = 'human' | 'llm' export type NoteKind = 'rect' | 'element' | 'text' | 'capture' | 'reply' /** Every {@link NoteKind}, as a runtime list — so a validator (e.g. the MCP * `llui_list_notes` input schema) enumerates exactly the kinds the type admits. */ export const NOTE_KINDS = [ 'rect', 'element', 'text', 'capture', 'reply', ] as const satisfies readonly NoteKind[] // `satisfies` above rejects a listed kind the type lacks; this rejects a list // that misses one of the type's kinds (a compile error naming it). type UnlistedNoteKind = Exclude const _everyNoteKindListed: [UnlistedNoteKind] extends [never] ? true : UnlistedNoteKind = true /** Whether `v` is a {@link NoteKind} — the check for any kind read from outside * the type system (a filename, parsed frontmatter, a request). */ export function isNoteKind(v: unknown): v is NoteKind { return NOTE_KINDS.some((kind) => kind === v) } export type NoteIntent = 'task' | 'note' export type NoteStatus = | 'open' | 'claimed' | 'in-progress' | 'proposed' | 'accepted' | 'applied' | 'rejected' | 'wontfix' | 'failed' export interface StatusTransition { ts: string noteId: string from: NoteStatus | null to: NoteStatus by: Author | 'system' reason?: string } export interface ProposedDiff { files: Array<{ path: string; patch: string }> summary: string confidence: 'high' | 'medium' | 'low' } export type CaptureLevel = 'standard' | 'verbose' export interface NoteRect { x: number y: number w: number h: number } export type Annotation = | ({ type: 'rect' } & NoteRect & { label?: string }) | { type: 'element'; selector: string; bbox: NoteRect; label?: string } export interface AgentSchemaSummary { msg: string fields: Record } export interface ComponentMetaRef { file: string line: number name: string } export interface NoteFrontmatter { // Identity (server-assigned on POST /_llui/notes) id: string ts: string author: Author kind: NoteKind captureLevel: CaptureLevel // Location url: string route: string | null routeParams: Record viewport: { w: number; h: number; dpr: number } // Component context (null when no element was targeted) componentPath: string[] | null componentMeta: ComponentMetaRef | null // Annotations baked into the screenshot annotations: Annotation[] // Files screenshot: string | null // Agent surface available at target element agentSchemas: AgentSchemaSummary[] // Versioning llui: { runtime: string; compiler: string } // Cross-references (optional) fulfillsRequestId?: string // Task-mode (P6) — optional, present when the note participates in // the task workflow. `intent: 'task'` puts the note in the status // machine; `kind: 'reply'` with `replyTo` set is the LLM's response. intent?: NoteIntent replyTo?: string proposedDiff?: ProposedDiff /** When true (default true for HUD-originated tasks), the router * spawns the LLM with its resume-previous-conversation flag (e.g. * `claude --continue`) so the LLM keeps prior context. Presets * without a resume flag treat this as a no-op. */ resume?: boolean /** Name of the resume chain this task participates in. The router * keeps a map of chain name → last session id and passes the * corresponding id via `--resume` when `resume: true`. Lets the * user maintain independent conversation threads (e.g. "refactor", * "ui-polish") without them stomping on each other. Default * `'default'`. */ chainName?: string } export type LogLevel = 'log' | 'warn' | 'error' | 'info' | 'debug' export interface MessageLogEntry { ts: string component: string msg: unknown } export interface PendingMessage { component: string msg: unknown } export interface PendingEffectEntry { id: string component: string effect: unknown sinceMs: number } export interface RecentEffectEntry { ts: string component: string effect: unknown outcome: 'ok' | 'error' | 'cancelled' error?: string } export interface DirtyTraceEntry { component: string pathsTracked: string[] mask: number maskHi?: number lastFlippedBits: string[] } export interface StructuralSnapshot { branches: Array<{ at: string; activeArm: string }> shows: Array<{ at: string; visible: boolean }> eachKeys: Array<{ at: string; keys: string[] }> } export interface SourceMapEntry { selector: string file: string line: number componentPath: string[] } export interface RuntimeErrorEntry { ts: string kind: 'runtime' | 'compiler' file?: string line?: number message: string stack?: string } export interface ConsoleLogEntry { ts: string level: LogLevel text: string } export interface VerboseNoteBody { scopeTree?: Array<{ id: string parent: string | null component: string key?: string }> bindings?: { total: number hottest: Array<{ component: string; path: string; firesPerSec: number }> lastCycleMs: number } agentBridge?: { connectedAgents: string[] pendingToolCalls: number recentMsgs: Array<{ ts: string; direction: 'in' | 'out'; payload: unknown }> } transitionsInFlight?: Array<{ component: string; name: string; progress: number }> foreignInstances?: Array<{ component: string; library: string }> } export interface NoteBody { stateSnapshot?: unknown messageLog?: MessageLogEntry[] consoleLog?: ConsoleLogEntry[] pendingMessages?: PendingMessage[] effects?: { pending: PendingEffectEntry[] recent: RecentEffectEntry[] } dirtyTrace?: DirtyTraceEntry[] structuralAt?: StructuralSnapshot sourceMap?: SourceMapEntry[] errors?: RuntimeErrorEntry[] /** Captured user interactions from the HUD's repro recorder. The * LLM uses this to understand what the developer did before the * bug appeared. Times are milliseconds from the start of the * recording, not absolute. */ repro?: ReproEvent[] verbose?: VerboseNoteBody } export type ReproEvent = | { type: 'click'; t: number; selector: string } | { type: 'input'; t: number; selector: string; value?: string; redacted?: boolean } | { type: 'keydown'; t: number; key: string; mods?: string } | { type: 'route'; t: number; pathname: string } // -- HTTP transport shapes ------------------------------------------------- export interface CreateNoteRequest { body: string frontmatter: Omit noteBody: NoteBody screenshot?: string } export interface CreateNoteResponse { id: string filename: string path: string sessionId: string } export interface CaptureRequestPayload { route?: string url?: string selector?: string annotate?: Annotation[] prose?: string waitForMessage?: string captureLevel?: CaptureLevel timeoutMs?: number } export interface CaptureRequestResponse { requestId: string status: 'fulfilled' | 'timeout' | 'no-client' note?: CreateNoteResponse } export interface NoteSummary { id: string sessionId: string filename: string ts: string author: Author kind: NoteKind url: string componentPath: string[] | null preview: string hasScreenshot: boolean /** Frontmatter shortcuts surfaced in the list so the HUD can * rehydrate trackedTasks + chainHistories on reload without * fetching each note individually. Optional for back-compat with * servers that don't populate them. */ intent?: NoteIntent chainName?: string /** For reply notes only — the original task this reply addresses. */ replyTo?: string /** For reply notes only — the LLM's one-line summary of the * proposed change (extracted from proposedDiff). */ proposedSummary?: string } export interface ListNotesQuery { sessionId?: string author?: Author kind?: NoteKind | NoteKind[] since?: string limit?: number } /** A note file that matched the canonical filename but could not be parsed * (corrupt frontmatter, torn write, hand-edited). Surfaced rather than * silently dropped so a broken note is visible instead of vanishing. */ export interface ListNotesError { filename: string message: string } export interface ListNotesResponse { sessionId: string notes: NoteSummary[] total: number /** Present (and non-empty) only when one or more note files failed to * parse. Absent on the clean path so existing consumers are unaffected. */ errors?: ListNotesError[] } export interface CurrentSessionResponse { sessionId: string startedAt: string notesDir: string } // -- SSE event union ------------------------------------------------------- export type SseRole = 'hud' | 'mcp' | 'viewer' export type ServerEvent = | { type: 'note-created'; id: string; filename: string; author: Author } | { type: 'note-updated'; id: string; sessionId: string } | { type: 'note-deleted'; id: string; sessionId: string } | { type: 'task-progress' noteId: string elapsedMs: number /** Token counters from the LLM stream. * - `in`: latest cumulative input_tokens (context size). Grows * monotonically across the conversation. * - `out`: sum of all output_tokens generated so far. * - `cacheRead`: prompt-cache hits, if the model reports them * (claude's `cache_read_input_tokens`). Shows how much * of the context was served from cache vs. reprocessed. */ tokens?: { in: number; out: number; cacheRead?: number } toolSummary?: string } | { type: 'capture-request'; requestId: string; payload: CaptureRequestPayload } | { type: 'capture-request-cancelled'; requestId: string } | { type: 'session-rotated'; sessionId: string } | { type: 'status-changed' noteId: string from: NoteStatus | null to: NoteStatus /** Optional human-readable context — e.g. the LLM's proposed-fix * summary, a failure message, or a git-apply conflict. The HUD * surfaces this verbatim in its status line. */ reason?: string }