2026-03-01 04:01:58 +01:00
|
|
|
/**
|
2026-03-03 22:40:18 +01:00
|
|
|
* @fileoverview Session lifecycle audit types.
|
|
|
|
|
*
|
|
|
|
|
* Types for the append-only JSONL audit log at `~/.codeman/session-lifecycle.jsonl`.
|
|
|
|
|
* Records session creation, PTY launch/exit, server start/stop, tmux recovery,
|
|
|
|
|
* and QR auth events. Written by `SessionLifecycleLog`, read for debugging.
|
|
|
|
|
*
|
|
|
|
|
* Key exports:
|
|
|
|
|
* - LifecycleEventType — union of 11 event types (created, started, exit, qr_auth, etc.)
|
|
|
|
|
* - LifecycleEntry — a single timestamped log entry with event, sessionId, and optional metadata
|
|
|
|
|
*
|
|
|
|
|
* No dependencies on other domain modules. LifecycleEntry.sessionId links
|
|
|
|
|
* back to SessionState.id for correlation.
|
2026-03-01 04:01:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** Types of session lifecycle events recorded to the audit log */
|
|
|
|
|
export type LifecycleEventType =
|
|
|
|
|
| 'created' // Session object created
|
|
|
|
|
| 'started' // PTY process launched (interactive/shell/prompt)
|
|
|
|
|
| 'exit' // PTY process exited (with exit code)
|
|
|
|
|
| 'deleted' // cleanupSession() called — session removed
|
|
|
|
|
| 'detached' // Server shutdown — PTY left alive in tmux for recovery
|
|
|
|
|
| 'recovered' // Session restored from tmux on server restart
|
|
|
|
|
| 'stale_cleaned' // Removed from state.json by cleanupStaleSessions()
|
|
|
|
|
| 'mux_died' // tmux session died (detected by reconciliation)
|
|
|
|
|
| 'server_started' // Server started (marker for restart detection)
|
2026-03-01 06:05:26 +01:00
|
|
|
| 'server_stopped' // Server shutting down
|
|
|
|
|
| 'qr_auth'; // Device authenticated via QR code scan
|
2026-03-01 04:01:58 +01:00
|
|
|
|
|
|
|
|
/** A single entry in the session lifecycle audit log */
|
|
|
|
|
export interface LifecycleEntry {
|
|
|
|
|
ts: number;
|
|
|
|
|
event: LifecycleEventType;
|
|
|
|
|
sessionId: string;
|
|
|
|
|
name?: string;
|
|
|
|
|
mode?: string;
|
|
|
|
|
reason?: string;
|
|
|
|
|
exitCode?: number | null;
|
|
|
|
|
extra?: Record<string, unknown>;
|
|
|
|
|
}
|