medicine-wheel

session-reader — RISE Specification

Zero-dependency JSONL session event parser — list, filter, analyze, and search across agent session data stored in _sessiondata/ directories.

Version: 0.1.1
Package: medicine-wheel-session-reader
Document ID: rispec-session-reader-v1
Last Updated: 2026-03-06


Desired Outcome

Users create session-aware tools and dashboards where:


Creative Intent

What this enables: Any tool in the Medicine Wheel ecosystem (or beyond) can read and analyze agent session data. Session histories become queryable knowledge — which tools were used, how long sessions lasted, what patterns emerge across conversations.

Structural Tension: Between opaque JSONL blobs (unstructured, hard to query) and structured session intelligence (filterable, searchable, analytics-ready). The session-reader resolves this by parsing JSONL events into typed structures with computed analytics.


Types

Sub-path: medicine-wheel-session-reader/types

interface SessionEvent {
  type: string;                // e.g., "user_message", "tool_call", "assistant_response"
  timestamp: string;           // ISO 8601
  content?: string;
  metadata?: Record<string, unknown>;
}

interface SessionSummary {
  id: string;
  path: string;
  model?: string;
  startTime: string;
  endTime?: string;
  eventCount: number;
  tags?: string[];
}

interface SessionDetail extends SessionSummary {
  events: SessionEvent[];
  analytics: SessionAnalytics;
}

interface SessionAnalytics {
  duration: number;            // Milliseconds
  toolUsage: Record<string, number>;   // Tool name → call count
  eventCounts: Record<string, number>; // Event type → count
  messageCount: number;
  avgResponseTime?: number;    // Milliseconds between user message and response
}

interface SessionFilter {
  model?: string;
  dateFrom?: string;           // ISO 8601
  dateTo?: string;             // ISO 8601
  tags?: string[];
  minEvents?: number;
}

interface SearchResult {
  sessionId: string;
  matches: SearchMatch[];
}

interface SearchMatch {
  eventIndex: number;
  eventType: string;
  snippet: string;             // Context around the match
  timestamp: string;
}

Sessions API

Sub-path: medicine-wheel-session-reader/sessions

Listing

listSessions(dataDir: string, filter?: SessionFilter): Promise<SessionSummary[]>

Scans _sessiondata/ directories for JSONL files, parses headers for summary metadata, and applies filters. Returns summaries sorted by start time (newest first).

Detail

getSession(dataDir: string, sessionId: string): Promise<SessionDetail>

Parses the full JSONL file, computes analytics (tool usage counts, event type counts, duration, average response time), and returns the complete session detail.

searchSessions(dataDir: string, query: string, filter?: SessionFilter): Promise<SearchResult[]>

Scans session content for matching text, returning snippets with surrounding context. Applies session-level filters before content search for efficiency.

Parsing

parseSessionFile(filePath: string): Promise<SessionEvent[]>

Low-level JSONL line-by-line parser using node:readline for memory-efficient streaming of large session files.


Dependencies


Advancing Patterns


Quality Criteria