Sessions
Register, heartbeat, end — plus session context, tasks, and plans.
A session row tracks one AI session: who ran it, in which terminal window
(immorterm_id), when it started, whether it's still breathing.
POST /api/v1/sessions
Register a session. Alias: POST /api/v1/sessions/register.
Body: { session_id, user_id?, immorterm_id?, terminal_name?, ai_tool?, project_context?, registry_snapshot? }.
Response: { "status": "registered", "session_id": "…" }.
GET /api/v1/sessions
List sessions. Query params: user_id, hours_ago (default 72), status,
ai_tool, immorterm_id, limit (default 20).
Response:
Optional per-session fields (ended_at, files_edited, last_active,
title, registry_snapshot) appear when set. terminal_name falls back to
the display name in ~/.immorterm/registry.json when the DB value is empty.
Free-tier gating: sessions older than the retention window are still
listed but marked "accessible": false, "requires_pro": true; the response
gains gated_count + upgrade.
POST /api/v1/sessions/end
Mark a session ended. Sets ended_at (idempotent — first write wins) and
status = 'ended', and merges exit_reason into metadata (last write
wins). Body: { session_id, user_id?, exit_reason? } where exit_reason
is the triggering event ("SessionEnd", "Stop", "PreCompact",
"/exit", …).
Response: { "status": "ended", "session_id", "ended_at", "exit_reason" } —
or { "status": "not_found", "session_id" }.
POST /api/v1/sessions/heartbeat
Keep a session alive and optionally update its running stats. Body:
{ session_id, summary?, edit_count?, files_edited?, registry_snapshot? }.
Response: { "status": "ok" }.
GET /api/v1/sessions/context
Full context for resuming a session — summary, facts, decisions, code
changes. Query params: user_id, session_id, immorterm_id. Returns the
same JSON as the get_session_context MCP tool.
GET /api/v1/sessions/tasks
Tasks for a session. Query params: user_id, session_id,
immorterm_id. Returns the same JSON as the list_tasks MCP tool.
POST /api/v1/tasks/reconcile
Archives stale tasks — type='task' memories with status
pending/in_progress older than stale_days. Run by the digest daemon
on a schedule. Query params: user_id, stale_days (default 7).
Response: { "archived": N }.
GET /api/v1/plans
Stored plans. Query params: user_id, session_id, immorterm_id,
query, limit (default 3). Returns the same JSON as the get_plan MCP
tool.