summaryrefslogtreecommitdiff
path: root/makima/migrations/20250117000000_history_tables.sql
diff options
context:
space:
mode:
authorsoryu <soryu@soryu.co>2026-01-15 22:33:47 +0000
committerGitHub <noreply@github.com>2026-01-15 22:33:47 +0000
commit6ee2e75834bff187b8c262e0798ef365bc21cd59 (patch)
treed4bd61c7740835acfc9a9dff952d1d088ff6d535 /makima/migrations/20250117000000_history_tables.sql
parent908973b5c08a8b7b624880843c512e8bddf37896 (diff)
downloadsoryu-6ee2e75834bff187b8c262e0798ef365bc21cd59.tar.gz
soryu-6ee2e75834bff187b8c262e0798ef365bc21cd59.zip
Add resume and history system for makima (#1)
This PR implements a comprehensive resume and history system that enables: 1. **History Viewing** - View complete conversation history for contracts across all phases - View conversation history for individual tasks - View task output/tool call history with timestamps - View checkpoint history - Timeline view showing all activities 2. **Resume System** - Resume interrupted supervisor conversations with full context - Resume interrupted task conversations - Resume from specific checkpoints - Continue tasks from previous task state (worktree inheritance) 3. **Rewind/Restore Features** - Rewind code to any checkpoint (git restore) - Rewind conversation to any point - Create new branches from historical points - Fork tasks from any point in history - New migration: 20250117000000_history_tables.sql - conversation_snapshots table for storing conversation state - history_events table for unified timeline - Added forking fields to tasks table - Added conversation_snapshot_id to task_checkpoints - ConversationSnapshot, HistoryEvent, ConversationMessage - Request/response types for resume and rewind operations - Query filter types for history endpoints - CRUD functions for conversation_snapshots - CRUD functions for history_events - Task conversation retrieval from task_events - GET /api/v1/contracts/{id}/history - GET /api/v1/contracts/{id}/supervisor/conversation - GET /api/v1/mesh/tasks/{id}/conversation - GET /api/v1/timeline - POST /api/v1/contracts/{id}/supervisor/resume - POST /api/v1/mesh/tasks/{id}/rewind - POST /api/v1/mesh/tasks/{id}/fork - POST /api/v1/mesh/tasks/{id}/checkpoints/{cid}/resume - POST /api/v1/mesh/tasks/{id}/checkpoints/{cid}/branch - POST /api/v1/contracts/{id}/supervisor/conversation/rewind - task-history: View task conversation history - task-checkpoints: List task checkpoints - resume: Resume supervisor after interruption - task-resume-from: Resume task from checkpoint - task-rewind: Rewind task code to checkpoint - task-fork: Fork task from historical point - rewind-conversation: Rewind supervisor conversation
Diffstat (limited to 'makima/migrations/20250117000000_history_tables.sql')
-rw-r--r--makima/migrations/20250117000000_history_tables.sql55
1 files changed, 55 insertions, 0 deletions
diff --git a/makima/migrations/20250117000000_history_tables.sql b/makima/migrations/20250117000000_history_tables.sql
new file mode 100644
index 0000000..60e371c
--- /dev/null
+++ b/makima/migrations/20250117000000_history_tables.sql
@@ -0,0 +1,55 @@
+-- History tables for Resume and History System
+-- Enables conversation rewind, snapshots, and unified event timeline
+
+-- 1. Conversation Snapshots table
+-- Stores conversation state at specific points for rewind capability
+CREATE TABLE IF NOT EXISTS conversation_snapshots (
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+ task_id UUID NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
+ checkpoint_id UUID REFERENCES task_checkpoints(id) ON DELETE SET NULL,
+ snapshot_type VARCHAR(50) NOT NULL, -- 'auto', 'manual', 'checkpoint'
+ message_count INTEGER NOT NULL,
+ conversation_state JSONB NOT NULL, -- Full conversation at this point
+ metadata JSONB, -- Additional context (token count, cost, etc.)
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
+);
+
+CREATE INDEX idx_conversation_snapshots_task ON conversation_snapshots(task_id);
+CREATE INDEX idx_conversation_snapshots_checkpoint ON conversation_snapshots(checkpoint_id);
+CREATE INDEX idx_conversation_snapshots_created ON conversation_snapshots(created_at DESC);
+
+-- 2. History Events table
+-- Unified event stream for timeline views
+CREATE TABLE IF NOT EXISTS history_events (
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+ owner_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ contract_id UUID REFERENCES contracts(id) ON DELETE CASCADE,
+ task_id UUID REFERENCES tasks(id) ON DELETE CASCADE,
+ event_type VARCHAR(50) NOT NULL, -- 'task', 'chat', 'checkpoint', 'phase', 'file'
+ event_subtype VARCHAR(50), -- Specific event: 'created', 'completed', 'message', etc.
+ phase VARCHAR(50), -- Contract phase when event occurred
+ event_data JSONB NOT NULL, -- Event-specific data
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
+);
+
+CREATE INDEX idx_history_events_contract ON history_events(contract_id, created_at DESC);
+CREATE INDEX idx_history_events_task ON history_events(task_id, created_at DESC);
+CREATE INDEX idx_history_events_owner ON history_events(owner_id, created_at DESC);
+CREATE INDEX idx_history_events_type ON history_events(event_type, created_at DESC);
+
+-- 3. Alter task_checkpoints - add conversation snapshot reference
+ALTER TABLE task_checkpoints
+ ADD COLUMN IF NOT EXISTS conversation_snapshot_id UUID REFERENCES conversation_snapshots(id) ON DELETE SET NULL;
+
+-- 4. Alter tasks - add forking fields
+ALTER TABLE tasks
+ ADD COLUMN IF NOT EXISTS forked_from_task_id UUID REFERENCES tasks(id) ON DELETE SET NULL,
+ ADD COLUMN IF NOT EXISTS forked_at_checkpoint_id UUID REFERENCES task_checkpoints(id) ON DELETE SET NULL;
+
+CREATE INDEX IF NOT EXISTS idx_tasks_forked_from ON tasks(forked_from_task_id) WHERE forked_from_task_id IS NOT NULL;
+
+-- Comments for documentation
+COMMENT ON TABLE conversation_snapshots IS 'Stores conversation state at specific points for rewind/resume capability';
+COMMENT ON TABLE history_events IS 'Unified event stream for timeline views across contracts and tasks';
+COMMENT ON COLUMN conversation_snapshots.snapshot_type IS 'Type: auto (periodic), manual (user-triggered), checkpoint (at git checkpoint)';
+COMMENT ON COLUMN history_events.event_type IS 'Category: task, chat, checkpoint, phase, file';