Keak-Code Telemetry DB

website·Indexed 30 days ago

https://keak-docs-production.up.railway.app/

Documentation for the Keak-Code Telemetry DB system architecture, covering the Variant Lifecycle State Machine, session database schema, code rendering, tracking implementation, and the end-to-end user journey from element interaction to experiment launch.

Tokens
75.2K
Snippets
278
Records
404
Agent score
0%

What's inside Keak

  1. Overview of Keak Code IDE features

    The Keak Code IDE provides developer-centric A/B testing integrated directly into the codebase. Features include:

    • IDE Setup: Installation, account authentication, and project configuration.
    • Codebase Testing: Ability to create and manage A/B tests directly from source code.
    • Customization: Extension settings and keyboard shortcuts to optimize workflow.
  2. Overview of Keak Chrome Extension features

    The Keak Chrome Extension allows for no-code A/B testing. Key capabilities include:

    • Page Context Extraction: AI-powered semantic analysis and element detection to understand page structure.
    • Variant Generation: AI-generated alternative versions with a visual editor for manual adjustments.
    • Element Selection: Point-and-click targeting with automatic CSS selector and XPath generation.
    • Test Launching: One-click deployment with configuration for traffic allocation, goals, and variant distribution.
  3. Overview of the KeaFab CRO Generation Pipeline

    KeaFab uses a three-phase AI pipeline to transform a selected UI component into a CRO-optimized variant. Unlike generic LLMs, it routes requests to specialized agents trained on conversion psychology and component-specific strategies (e.g., Hero sections vs. Pricing tables).

    The Pipeline Phases:

    1. Router (GPT-4.1-nano): Classifies the component type (e.g., hero, nav, pricing, social_proof, form, feature_section).
    2. Optimizer (Gemini-3-flash): Generates a CRO-optimized variant using vision analysis of the screenshot and the provided code.
    3. Validator (Claude-Haiku-4.5): Ensures the output adheres to technical constraints and fixes JSX violations.
  4. Understand Keak Dashboard API Proxy Architecture

    The Keak dashboard acts as a proxy between the browser extension and the AI engine (KeaChrome). All extension calls are sent to ${BACKEND_URL}/... (which resolves to https://platform.keak.com/api in production). The dashboard validates authentication and billing before proxying requests to KeaChrome's internal adapters.

    Key endpoints include:

    • Generate/Refine (Default): POST /api/v2/page-agent/generate and POST /api/v2/page-agent/refine. These proxy to PageAgentAdapter, where the server drives a Playwright page for screenshots, allowing the extension tab to be closed.
    • Generate/Refine (Legacy): POST /api/v2/variants/generate and POST /api/v2/variants/refine. Used when isBetaModeEnabled() is false; these proxy to ClientInputAdapter and require the tab to remain open for screenshot uploads.
    • Launch Test: POST /api/tests (single) or /api/tests/group (batch) to persist test variations.
  5. Keak-Code IDE State Management Architecture

    Keak-Code uses a 3-tier state architecture to ensure data durability and prevent state loss during app restarts:

    1. Zustand Store: Manages global UI state; partially persisted to localStorage.
    2. ChatPersistence: Stores project-specific history in .keak/history/history.json.
    3. React Component State: Handles transient state for active sessions.

    Key Features:

    • Snapshots: Used to prevent the 'variant-as-control' bug upon restarting the application.
    • Auto-save: Conversation history is written to disk using a 500ms debounce.
  6. Understand the KeakId system for element tracking

    A KeakId is a stable, human-readable identifier injected into source code as a data-keak-id attribute. It ensures tracking survives refactors, provides a key for chat history per element, and allows for file-based persistence via grep. If a keakId is accidentally removed, the system automatically re-injects it upon the next element selection.
  7. Understand Keak Chrome Extension architecture

    The Keak Chrome Extension serves as the authoring surface for A/B tests. It does not call KeaChrome directly; instead, it proxies all requests through the Dashboard API for authentication, billing, and persistence. The extension manages element targeting (injecting data-keak-id), variant authoring (Generate vs Refine), and in-place DOM previews using local Zustand and localStorage stores.
  8. Keak MCP System Architecture

    The Keak MCP server is designed as a thin client where every tool maps to a dashboard endpoint. It uses a layered architecture to ensure extensibility:

    • Entrypoint (index.ts): Handles stdio transport.
    • Assembly (server.ts): Builds the McpServer, injects context, and registers tools.
    • Client (keak-client): The sole location for fetch calls; handles typed API methods and unwraps { data } envelopes.
    • Session Store (context/): Manages per-session in-memory state (e.g., recommended goals, client_session_id, and CRO reports) to avoid passing large payloads back and forth to the LLM.
    • Library (lib/): Contains tool definitions, presentation formatting, and an async-job poller.

    Async Job Handling: Because CRO reports can take minutes and MCP clients have a ~60s timeout, create_cro_report starts a job and polls for ~45s. The model must then use get_cro_report to advance and check the job status.

  9. Manage Control and Variant versions via Just-in-Time Swap

    Keak-Code uses a 'Two versions, one disk slot' approach to handle Control (original) and Variant (generated) code. The system always reads from the disk first before swapping versions to ensure any edits made in external editors (like VS Code) are captured in the snapshot before the file is overwritten by the other version.
    // Example: Transitioning from Control to Variant Preview
    // 1. Read disk (captures control edits!)
    const currentCode = readDisk(); 
    
    // 2. Capture to control snapshot
    snapshot.originalCode = currentCode;
    
    // 3. Write variant to disk
    writeDisk(variantCode);
    
    // 4. Update flag
    snapshot.activePreview = true;
  10. Generate CRO variants with KeaFab API

    KeaFab is an AI service for Conversion Rate Optimization (CRO). It analyzes UI components using vision models, routes them to specialized optimizers (e.g., for hero sections, pricing tables), and generates optimized variants with improved copy, layout, and style while validating code quality.
  11. Understand Keak-Code Telemetry Architecture

    The telemetry system tracks the entire variant generation workflow (Session Start → Chat Start → Generation Start → Generation Complete → Variant Preview → Variant Accept), including feedback and edits.

    Data Flow:

    1. IDE (Electron App): Hooks like use-cro-telemetry and useKeafabGenerator send data to telemetryService.ts.
    2. Transport: Data is sent via HTTP POST with an auth token to the Dashboard (Next.js) API endpoints (/app/api/telemetry/*).
    3. Storage: The Dashboard uses a Supabase Client to write to a dedicated Telemetry Database (configured via TELEMETRY_SUPABASE_URL), which is isolated from the main Dashboard database for performance and scalability.