lattice
For Engineers

SQL on one side. Markdown on the other.

Lattice is a bidirectional sync engine between a database (SQLite or Postgres) and the rendered context files your agents actually read. Your schema, your render logic, your file format.

Read the docs →

Install

The library, the CLI, or a self-updating one-liner. Node 18+. Just want the app? Get the desktop install →

Library

bash
npm install latticesql

CLI + local GUI

bash
npm install -g latticesql
lattice gui   # opens the GUI at http://localhost:4317

One-liner (macOS / Linux) — brings its own Node if you need it

bash
curl -fsSL https://latticedesktop.com/install.sh | sh

Quick Start

Define a table. Render a context file. Watch it stay in sync.

typescript
import { Lattice } from 'latticesql';
const db = new Lattice('./state.db');

db.define('projects', {
  columns: {
    id: 'TEXT PRIMARY KEY',
    name: 'TEXT NOT NULL',
    status: 'TEXT',
    owner: 'TEXT',
  },
  render: 'default-table',
  outputFile: 'PROJECTS.md',
});

await db.init();
await db.render('./context');
// → context/PROJECTS.md, ready for any agent to read

Primitives

define()

Declare tables with typed columns. Lattice manages schema migrations.

render specs

Built-in (table/list/detail/json) or your own function. Token-budgeted, cache-friendly.

defineWriteback()

Watch a file, parse agent output back into rows. Bidirectional sync, your parser, your validation.

entity contexts

One directory per row with custom templates. Per-entity scope, no monolithic context dumps.

reward tracking

Score rows on use; auto-prune below thresholds. Agents converge on what works.

adapters

SQLite via better-sqlite3 (sync, local) or Postgres via pg (async, shared). Same API.

Writeback — Agents as Data Producers

Render specs go SQL → markdown. Writeback pipelines go markdown → SQL. Agent output lands as rows you can query.

typescript
db.defineWriteback('agent-notes', {
  watchFile: 'context/NOTES.md',
  parse(content) {
    // Your parser. Returns rows to upsert.
    return parseMarkdownNotes(content);
  },
  persist(rows) {
    return db.upsert('notes', rows);
  },
});

await db.watch('./context');
// → Agent writes to NOTES.md. Lattice parses + persists to SQL.

SQLite Adapter

Synchronous. Local. Fast.

Backed by better-sqlite3. Sub-ms lookups. WAL mode. Ideal for per-developer or per-agent state.

Postgres Adapter

Async. Shared. Production-ready.

Backed by pg. Same Lattice API. Auto-detected from a postgres:// connection string. Use for team-shared state.

Read the Full API.

Schemas, render specs, writeback, entity contexts, reward tracking, adapters — everything in one reference.