From 05b1930e04ac222d73ffb2f45c1b1febb69f893d Mon Sep 17 00:00:00 2001
From: Peter Stone <thepeterstone@gmail.com>
Date: Wed, 28 Jan 2026 22:19:28 -1000
Subject: Add Agent Context API for external agent integration

Phase 1: Authentication and read-only context
- POST /agent/auth/request - request access with name + agent_id
- GET /agent/auth/poll - poll for approval status
- POST /agent/auth/approve|deny - user approval (browser auth required)
- GET /agent/context - 7-day timeline context (agent session required)

Phase 1.5: Browser-only agent endpoints (HTML pages)
- GET /agent/web/request - request page with token
- GET /agent/web/status - status page with polling
- GET /agent/web/context - context page with timeline data

WebSocket notifications:
- GET /ws/notifications - push agent requests to browsers
- Approval modal with trust indicators and countdown timer

Database:
- agents table for registered agent tracking
- agent_sessions table for pending/active sessions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---
 migrations/010_agent_tables.sql | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 migrations/010_agent_tables.sql

(limited to 'migrations/010_agent_tables.sql')

diff --git a/migrations/010_agent_tables.sql b/migrations/010_agent_tables.sql
new file mode 100644
index 0000000..23e1c2c
--- /dev/null
+++ b/migrations/010_agent_tables.sql
@@ -0,0 +1,30 @@
+-- Agent Context API tables
+-- Migration: 010_agent_tables.sql
+
+-- Registered/approved agents (identity binding)
+CREATE TABLE IF NOT EXISTS agents (
+    id INTEGER PRIMARY KEY AUTOINCREMENT,
+    name TEXT NOT NULL,
+    agent_id TEXT NOT NULL UNIQUE,  -- UUID from agent
+    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+    last_seen DATETIME,
+    trusted BOOLEAN DEFAULT 1       -- can be revoked
+);
+
+-- Pending access requests and active sessions
+CREATE TABLE IF NOT EXISTS agent_sessions (
+    id INTEGER PRIMARY KEY AUTOINCREMENT,
+    request_token TEXT NOT NULL UNIQUE,
+    agent_name TEXT NOT NULL,
+    agent_id TEXT NOT NULL,
+    status TEXT DEFAULT 'pending',  -- pending, approved, denied, expired
+    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+    expires_at DATETIME NOT NULL,   -- request expires after 5 min
+    session_token TEXT,             -- populated on approval
+    session_expires_at DATETIME     -- session TTL (1 hour)
+);
+
+CREATE INDEX IF NOT EXISTS idx_agent_sessions_request ON agent_sessions(request_token);
+CREATE INDEX IF NOT EXISTS idx_agent_sessions_session ON agent_sessions(session_token);
+CREATE INDEX IF NOT EXISTS idx_agent_sessions_status ON agent_sessions(status);
+CREATE INDEX IF NOT EXISTS idx_agents_agent_id ON agents(agent_id);
-- 
cgit v1.2.3

