gitgram/aitimemachine/docs/last/AITM_THREE_LAYER_ARCHITECTURE.md
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

19 KiB
Raw Permalink Blame History

AITimeMachine: Three-Layer Architecture Plan

Vision: macOS Time Machine for AI coding - restore code AND chat to any point in time. Canonical reference: ../../../NORTH_STAR_PRD_ARCHITECTURE_V1.md. Canonical SQL source: ../../../CANONICAL_SQL_SCHEMA_V1.sql.


๐ŸŽฏ The Core Vision

When AI breaks your code:

  1. Open AITimeMachine
  2. Select "before the error"
  3. Both code AND chat context are restored
  4. Continue from the clean state

<EFBFBD>๏ธ Backend-Heavy Architecture (Critical)

The Core Principle

The Backend is the Source of Truth. MCP/API act as thin clients with local cache/offline buffering.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    User's Environment                        โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”‚
โ”‚  โ”‚   VSCode     โ”‚  โ”‚ Claude Code  โ”‚  โ”‚   Cursor     โ”‚      โ”‚
โ”‚  โ”‚  + AITM MCP  โ”‚  โ”‚  + AITM MCP  โ”‚  โ”‚  + AITM MCP  โ”‚      โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚
โ”‚         โ”‚                  โ”‚                  โ”‚              โ”‚
โ”‚         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜              โ”‚
โ”‚                            โ”‚                                 โ”‚
โ”‚                            โ–ผ                                 โ”‚
โ”‚         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚         โ”‚      AITM MCP Server (Thin Client)   โ”‚            โ”‚
โ”‚         โ”‚  โ€ข No canonical database              โ”‚            โ”‚
โ”‚         โ”‚  โ€ข Local cache/offline buffer only    โ”‚            โ”‚
โ”‚         โ”‚  โ€ข Forwards writes/reads to backend   โ”‚            โ”‚
โ”‚         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ”‚                            โ”‚                                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚ HTTPS
                             โ–ผ
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ”‚           AITM Backend API Server                 โ”‚
         โ”‚  โ€ข Authentication                                 โ”‚
         โ”‚  โ€ข Business logic                                 โ”‚
         โ”‚  โ€ข All data processing                            โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ”‚              Neon Database (Postgres)             โ”‚
         โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
         โ”‚  โ”‚ โ€ข All chats (every message)                 โ”‚ โ”‚
         โ”‚  โ”‚ โ€ข All code (every version)                  โ”‚ โ”‚
         โ”‚  โ”‚ โ€ข All files (full content)                  โ”‚ โ”‚
         โ”‚  โ”‚ โ€ข All folders (directory trees)             โ”‚ โ”‚
         โ”‚  โ”‚ โ€ข All changes (diffs)                       โ”‚ โ”‚
         โ”‚  โ”‚ โ€ข All contexts (mental states)              โ”‚ โ”‚
         โ”‚  โ”‚ โ€ข All embeddings (for search)               โ”‚ โ”‚
         โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Why Backend-Heavy?

  1. Reliability: User's machine can crash, backend stays up
  2. Cross-Device: Access from anywhere
  3. No Local DB: MCP doesn't manage databases
  4. Scalability: Backend handles heavy operations
  5. Security: Centralized auth and access control

What Gets Saved (Everything!)

// Every AI action triggers backend save
interface CaptureEvent {
  // Chat
  messages: Message[];           // Every user/AI message
  toolCalls: ToolCall[];         // Every tool invocation
  toolOutputs: ToolOutput[];     // Every result
  
  // Code
  files: FileSnapshot[];         // Full file content
  folders: FolderTree[];         // Directory structure
  diffs: FileDiff[];             // What changed
  
  // Context
  activeFiles: string[];         // What was open
  cursorPosition: Position;      // Where user was
  currentTask: string;           // What AI was doing
  
  // Metadata
  timestamp: Date;
  checkpointId: string;
  sessionId: string;
}

<EFBFBD>๐Ÿ—๏ธ Three-Layer Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    AITimeMachine Layers                      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                              โ”‚
โ”‚  Layer 1: โณ TIME LAYER (Git-Quality Storage)               โ”‚
โ”‚  โ”œโ”€ Checkpoints (every AI action)                           โ”‚
โ”‚  โ”œโ”€ Content-addressable storage (deduplication)             โ”‚
โ”‚  โ”œโ”€ Delta compression (Git packfiles)                       โ”‚
โ”‚  โ””โ”€ Advanced diff algorithms (Myers, Histogram)             โ”‚
โ”‚                                                              โ”‚
โ”‚  Layer 2: ๐Ÿง  CONTEXT LAYER (The Memory)                     โ”‚
โ”‚  โ”œโ”€ Full chat history (every message)                       โ”‚
โ”‚  โ”œโ”€ Tool calls + outputs (what AI did)                      โ”‚
โ”‚  โ”œโ”€ Mental state (active files, cursor, goals)              โ”‚
โ”‚  โ””โ”€ Linked to checkpoints (restore chat with code)          โ”‚
โ”‚                                                              โ”‚
โ”‚  Layer 3: ๐Ÿ”ฎ AUGMENTED LAYER (The Intelligence)             โ”‚
โ”‚  โ”œโ”€ Code search (semantic + regex)                          โ”‚
โ”‚  โ”œโ”€ Oracle agent (ask about history)                        โ”‚
โ”‚  โ”œโ”€ Documentation indexing                                  โ”‚
โ”‚  โ””โ”€ Universal search (code + docs + history)                โ”‚
โ”‚                                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”Œ MCP/API โ†’ Backend Connection

MCP Server (Thin Client)

The MCP server runs locally with cache/offline buffering only; canonical state is in the backend.

// src/mcp-daemon.ts (Simplified)
class MCPDaemon {
  private apiClient: AITMBackendClient;
  
  constructor() {
    // Connect to backend
    this.apiClient = new AITMBackendClient({
      baseUrl: process.env.AITM_BACKEND_URL || 'https://timemachine-api.gitgram.app',
      apiKey: process.env.AITM_API_KEY
    });
  }
  
  async handleToolCall(tool: string, args: any) {
    switch (tool) {
      case 'tm_checkpoint':
        // Forward to backend
        return await this.apiClient.post('/checkpoints', {
          description: args.description,
          files: await this.scanCurrentFiles(),
          context: await this.getCurrentContext()
        });
        
      case 'tm_go_back':
        // Get data from backend
        const checkpoint = await this.apiClient.get(`/checkpoints/${args.id}`);
        // Restore locally
        await this.restoreFiles(checkpoint.files);
        return checkpoint.context;
        
      case 'before_action':
        // Capture state and send to backend
        const state = await this.captureCurrentState();
        return await this.apiClient.post('/actions/before', state);
        
      case 'after_action':
        // Capture changes and send to backend
        const changes = await this.captureChanges();
        return await this.apiClient.post('/actions/after', changes);
    }
  }
}

Backend API Endpoints

// Backend handles ALL data operations

// Checkpoints
POST   /api/checkpoints              // Create checkpoint
GET    /api/checkpoints              // List checkpoints
GET    /api/checkpoints/:id          // Get checkpoint details
POST   /api/checkpoints/:id/restore  // Restore to checkpoint
DELETE /api/checkpoints/:id          // Delete checkpoint

// Files (Full content storage)
POST   /api/files                    // Save file content
GET    /api/files/:hash              // Get file by hash
GET    /api/files/tree/:checkpoint   // Get directory tree
POST   /api/files/diff               // Get diff between versions

// Chats
POST   /api/chats/messages           // Save message
GET    /api/chats/messages           // Get messages
GET    /api/chats/sessions/:id       // Get session history
POST   /api/chats/context            // Save context snapshot

// Actions (Tool calls)
POST   /api/actions/before           // Before AI action
POST   /api/actions/after            // After AI action
GET    /api/actions/history          // Get action history

// Search & Intelligence
POST   /api/search/code              // Search code
POST   /api/search/chats             // Search conversations
POST   /api/oracle/ask               // Ask Oracle
POST   /api/oracle/research          // Start research job

// Time Travel
POST   /api/time/undo                // Undo last action
POST   /api/time/restore             // Restore to point
GET    /api/time/timeline            // Get timeline
GET    /api/time/diff                // Get diff

Data Flow Example: AI Makes a Change

1. User: "Create an API endpoint"
   โ†“
2. MCP captures message
   POST /api/chats/messages
   {
     role: "user",
     content: "Create an API endpoint",
     sessionId: "sess_123"
   }
   โ†“
3. AI decides to use create_file tool
   โ†“
4. MCP: before_action
   POST /api/actions/before
   {
     action: "create_file",
     args: {path: "src/api.ts"},
     currentFiles: [...],  // Full snapshot
     currentContext: {...}
   }
   โ†’ Backend saves checkpoint_before_abc123
   โ†“
5. AI creates file
   โ†“
6. MCP: after_action
   POST /api/actions/after
   {
     action: "create_file",
     result: "success",
     newFiles: [...],      // Full snapshot
     diff: {...}
   }
   โ†’ Backend saves checkpoint_after_abc123
   โ†’ Backend links: message โ†’ before โ†’ after
   โ†“
7. Backend generates diff and saves
   POST /api/files/diff
   โ†’ Stores in diffs table
   โ†“
8. Backend generates embeddings (async)
   โ†’ Stores in embeddings table

Authentication Flow

// User authenticates once
const apiKey = await login(email, password);
// Store in environment
process.env.AITM_API_KEY = apiKey;

// MCP uses API key for all requests
headers: {
  'Authorization': `Bearer ${process.env.AITM_API_KEY}`,
  'Content-Type': 'application/json'
}

Layer 1: โณ Time Layer

Goal

Store every version of every file with Git-quality efficiency.

Components

1.1 Local Storage (.aitimemachine/)

  • Content Store: SHA-256 hashed blobs (deduplicated)
  • Packfiles: Delta-compressed archives
  • Checkpoints: JSON snapshots of project state
  • Index: Fast lookup of what changed when

1.2 Cloud Storage (Neon - Required)

-- Core tables
CREATE TABLE checkpoints (
  id TEXT PRIMARY KEY,
  project_id UUID,
  timestamp TIMESTAMP,
  description TEXT,
  parent_id TEXT,
  tree_hash TEXT  -- Merkle tree root
);

CREATE TABLE blobs (
  hash TEXT PRIMARY KEY,
  content BYTEA,
  size INTEGER,
  compression TEXT
);

CREATE TABLE trees (
  hash TEXT PRIMARY KEY,
  entries JSONB  -- [{name, type, hash, mode}]
);

MCP Tools

  • tm_checkpoint(description) - Create manual checkpoint
  • tm_go_back(time_or_id) - Restore to checkpoint
  • tm_undo_last() - Quick undo
  • tm_diff(from, to) - Show changes
  • tm_restore_file(path, checkpoint) - Selective restore

CLI Commands

aitm checkpoint "Before refactor"
aitm back 5m
aitm undo
aitm diff HEAD~1
aitm restore src/api.ts --from abc123

API Endpoints

POST /api/time/checkpoint
POST /api/time/restore
POST /api/time/undo
GET  /api/time/diff/:from/:to
GET  /api/time/timeline

Layer 2: ๐Ÿง  Context Layer

Goal

Capture and restore the AI's "mental state" - not just code, but the conversation and intent.

Components

2.1 Chat Storage

CREATE TABLE messages (
  id UUID PRIMARY KEY,
  project_id UUID,
  session_id TEXT,
  checkpoint_id TEXT,  -- Link to code state
  timestamp TIMESTAMP,
  role TEXT,  -- 'user' | 'assistant' | 'system'
  content TEXT,
  tool_calls JSONB,
  tool_outputs JSONB
);

CREATE TABLE contexts (
  id UUID PRIMARY KEY,
  checkpoint_id TEXT,
  summary TEXT,
  active_files JSONB,
  cursor_position JSONB,
  current_task TEXT
);

2.2 Auto-Capture

Every AI action triggers:

  1. before_action: Checkpoint BEFORE change
  2. Tool execution: Capture inputs/outputs
  3. after_action: Checkpoint AFTER change
  4. Link: Connect chat message โ†’ checkpoint

MCP Tools

  • tm_save_context(summary) - Save mental state
  • tm_get_context(checkpoint_id) - Retrieve context
  • tm_restore_with_context(checkpoint_id) - Restore code + chat

CLI Commands

aitm context save "API design phase"
aitm context load abc123
aitm back --with-context

API Endpoints

POST /api/context/save
GET  /api/context/:checkpoint_id
POST /api/context/restore
GET  /api/context/search?q=authentication

Layer 3: ๐Ÿ”ฎ Augmented Layer

Goal

Intelligent search, research, and understanding (inspired by Nia but AITM-specific).

Components

3.1 Code Intelligence

CREATE TABLE embeddings (
  id UUID PRIMARY KEY,
  project_id UUID,
  checkpoint_id TEXT,
  file_path TEXT,
  chunk_text TEXT,
  embedding vector(1536),  -- pgvector
  metadata JSONB
);

CREATE INDEX ON embeddings USING ivfflat (embedding vector_cosine_ops);

3.2 Oracle Agent

The "Oracle" knows:

  • Project history: What changed when and why
  • Code context: Where functions are defined
  • Chat history: What you discussed with AI
  • External docs: Indexed documentation

MCP Tools (Nia-Inspired)

  • tm_oracle_ask(question) - Ask about project
  • tm_search_code(query) - Semantic code search
  • tm_index_docs(url) - Index documentation
  • tm_universal_search(query) - Search everything
  • tm_research(topic) - Deep research agent

CLI Commands

aitm ask "Where is the auth logic?"
aitm search "database connection"
aitm index https://docs.example.com
aitm research "best practices for API design"

API Endpoints (Nia-Style)

POST /api/oracle/ask
POST /api/search/code
POST /api/search/universal
POST /api/index/docs
POST /api/research/start
GET  /api/research/:job_id

๐Ÿ”„ Data Flow: The Complete Picture

Capture Flow

AI makes change
    โ†“
1. before_action checkpoint
    โ†“
2. Capture tool call + args
    โ†“
3. Execute change
    โ†“
4. Capture tool output
    โ†“
5. after_action checkpoint
    โ†“
6. Link: message โ†’ checkpoint โ†’ context
    โ†“
7. Sync to Neon (async)
    โ†“
8. Generate embeddings (background)

Restore Flow

User: "Go back to before the error"
    โ†“
1. Search checkpoints (by time/description)
    โ†“
2. Load checkpoint metadata
    โ†“
3. Fetch linked context from Neon
    โ†“
4. Restore files from content store
    โ†“
5. Return chat context to AI
    โ†“
6. AI continues with restored state

๐Ÿ“Š Implementation Priority

Phase 1: Time Layer (Core) โœ…

  • Content-addressable storage
  • Checkpoints
  • Diff engine
  • Packfiles
  • MCP tools (basic)

Phase 2: Context Layer (Critical) ๐Ÿ”„

  • Chat message storage
  • Tool call tracking
  • Context snapshots
  • Checkpoint โ†” Context linking
  • Restore with context

Phase 3: Augmented Layer (Intelligence) ๐Ÿ“‹

  • Code embeddings
  • Oracle agent
  • Documentation indexing
  • Universal search
  • Research agent

๐ŸŽฏ Key Differences from Nia

Feature Nia AITimeMachine
Focus External repos/docs Your project history
Time Travel โŒ No โœ… Full restore
Chat Context Limited โœ… Full history
Undo AI Mistakes โŒ No โœ… Core feature
Local-First โŒ Cloud-only โœ… Hybrid
Git Integration Basic โœ… Deep (packfiles, trees)

๐Ÿš€ Success Criteria

  1. โœ… Instant Undo: aitm undo restores in <1 second
  2. โœ… Chat Restore: Going back includes conversation context
  3. โœ… Smart Search: Find "before the Docker changes"
  4. โœ… Selective Restore: Restore just src/api.ts
  5. โœ… Oracle Intelligence: Ask "What did I change yesterday?"
  6. โœ… Heavy Backend: All data synced to Neon for reliability

๐Ÿ“ File Structure

src/
โ”œโ”€โ”€ core/
โ”‚   โ”œโ”€โ”€ engine.ts              # Main TimeMachine engine
โ”‚   โ”œโ”€โ”€ content-store.ts       # Blob storage
โ”‚   โ”œโ”€โ”€ diff-engine-v2.ts      # Advanced diff
โ”‚   โ””โ”€โ”€ git/
โ”‚       โ”œโ”€โ”€ tree.ts            # Merkle trees
โ”‚       โ””โ”€โ”€ pack/              # Packfile logic
โ”œโ”€โ”€ neon/
โ”‚   โ”œโ”€โ”€ client.ts              # Drizzle + Neon
โ”‚   โ”œโ”€โ”€ schema.ts              # DB schema
โ”‚   โ”œโ”€โ”€ sync.ts                # Sync service
โ”‚   โ””โ”€โ”€ indexer.ts             # Embeddings
โ”œโ”€โ”€ oracle/
โ”‚   โ””โ”€โ”€ agent.ts               # Oracle intelligence
โ”œโ”€โ”€ mcp/
โ”‚   โ”œโ”€โ”€ mcp-daemon.ts          # MCP server
โ”‚   โ””โ”€โ”€ ai-time-concept-tools.ts
โ”œโ”€โ”€ api/
โ”‚   โ””โ”€โ”€ server.ts              # REST API
โ””โ”€โ”€ cli/
    โ””โ”€โ”€ cli-v2.ts              # CLI commands

๐Ÿ” Environment Variables

# Required
DATABASE_URL=postgres://...neon.tech/...
OPENAI_API_KEY=sk-...

# Optional
AITM_AUTO_SYNC=true
AITM_CAPTURE_INTERVAL=300  # 5 minutes

๐Ÿ“š Next Steps

  1. Complete Context Layer:

    • Implement chat storage in Neon
    • Link checkpoints โ†” contexts
    • Update tm_go_back to restore context
  2. Build Oracle:

    • Implement embedding generation
    • Create Oracle agent
    • Add universal search
  3. Polish UX:

    • Add visual timeline (TUI)
    • Improve error messages
    • Add progress indicators
  4. Documentation:

    • User guide
    • API reference
    • Video tutorials