/** * v0.3.0 — `_events.jsonl` append/query. * * Two scopes: * - Chief session events: //.solosquad/sessions/.events.jsonl * - Per-workflow events: //workflows//_events.jsonl * * Per docs/plan/v0.3-pm-mode-orchestration.md §4.4 + PoC #2 (auth, rate-limit, * mid-stream kill scenarios all surface here). task_id-based dedup so a * task_notification line that re-arrives across a retry isn't double-counted. * * v1.2.10 — the session-driver event namespace was renamed `pm.*` → `chief.*` * to match the v1.1 Chief rebrand. New events emit `chief.*`; readers that scan * pre-v1.2.10 logs (`workflow-reconciler`) accept BOTH the legacy `pm.*` and the * new `chief.*` kinds. The on-disk file path (`.events.jsonl`) is * unchanged, and archive.sqlite never indexed these kinds — so no external * consumer breaks. */ export type EventKind = "chief.message_in" | "chief.message_out" | "chief.error" | "chief.auth_expired" | "chief.session_lost" | "chief.session_rotated" | "chief.rate_limit" | "chief.usage" | "spawn.start" | "spawn.complete" | "spawn.fail" | "workflow.stage_started" | "workflow.stage_completed" | "workflow.stage_needs_revision"; export interface BaseEvent { ts: string; kind: EventKind; } export interface ChiefMessageInEvent extends BaseEvent { kind: "chief.message_in"; text: string; userId: string; } export interface ChiefMessageOutEvent extends BaseEvent { kind: "chief.message_out"; text: string; costUsd: number; durationMs: number; userId: string; } export interface ChiefErrorEvent extends BaseEvent { kind: "chief.error"; reason: string; exitCode?: number | null; signal?: string | null; stderrTail?: string; userId: string; } export interface ChiefAuthExpiredEvent extends BaseEvent { kind: "chief.auth_expired"; userId: string; } export interface ChiefSessionLostEvent extends BaseEvent { kind: "chief.session_lost"; oldSessionId: string; newSessionId: string; userId: string; } export interface ChiefSessionRotatedEvent extends BaseEvent { kind: "chief.session_rotated"; oldSessionId: string; newSessionId: string; reason: string; userId: string; } export interface ChiefRateLimitEvent extends BaseEvent { kind: "chief.rate_limit"; resetsAt?: number; rateLimitType?: string; userId: string; } /** * v1.4.0 (S-2a) — passive token-usage telemetry for a completed Chief turn. * Captured from the stream-json `result` line's `usage` block. OBSERVATION * ONLY — no session rotation acts on this (that is S-2b, deferred to v1.4.x). * `contextTokens` ≈ the prompt size that went into the model this turn * (input + cache_read + cache_creation), i.e. a proxy for context-window * occupancy that §5.5 leading-indicator and a future S-2b threshold can read. */ export interface ChiefUsageEvent extends BaseEvent { kind: "chief.usage"; userId: string; contextTokens: number; inputTokens: number; outputTokens: number; cacheReadTokens: number; cacheCreationTokens: number; costUsd: number; } export interface SpawnStartEvent extends BaseEvent { kind: "spawn.start"; taskId: string; toolUseId: string; agent: string; description: string; /** v0.3.0+: workflow stage this spawn belongs to (parsed from Chief's [stage:] marker). */ stageId?: string; /** v0.3.0+: workflow id (parsed from Chief's [stage: wf:] marker). */ workflowId?: string; } export interface SpawnCompleteEvent extends BaseEvent { kind: "spawn.complete"; taskId: string; toolUseId: string; totalTokens?: number; toolUses?: number; durationMs?: number; } export interface SpawnFailEvent extends BaseEvent { kind: "spawn.fail"; taskId: string; toolUseId: string; status: string; } export interface WorkflowStageEvent extends BaseEvent { kind: "workflow.stage_started" | "workflow.stage_completed" | "workflow.stage_needs_revision"; workflowId: string; stageId: string; agent?: string; } export type AnyEvent = ChiefMessageInEvent | ChiefMessageOutEvent | ChiefErrorEvent | ChiefAuthExpiredEvent | ChiefSessionLostEvent | ChiefSessionRotatedEvent | ChiefRateLimitEvent | ChiefUsageEvent | SpawnStartEvent | SpawnCompleteEvent | SpawnFailEvent | WorkflowStageEvent; export interface EventSink { append(ev: AnyEvent): void; list(): AnyEvent[]; } export declare function chiefEventsPath(workspace: string, orgSlug: string, userId: string): string; /** * @deprecated v1.2.10 — renamed to {@link chiefEventsPath}. Retained as an * alias so the immutable autonomous-engine module (`src/engine/**`, which must * not be edited per AGENTS.md) keeps compiling against the old symbol. New * call sites should import `chiefEventsPath`. */ export declare const pmEventsPath: typeof chiefEventsPath; export declare function workflowEventsPath(workspace: string, orgSlug: string, workflowId: string): string; export declare class FileEventSink implements EventSink { private readonly filePath; private readonly seenTaskNotifications; constructor(filePath: string); append(ev: AnyEvent): void; list(): AnyEvent[]; } /** In-memory sink for unit tests. */ export declare class MemoryEventSink implements EventSink { readonly history: AnyEvent[]; private readonly seen; append(ev: AnyEvent): void; list(): AnyEvent[]; } export declare function nowIso(): string;