Live OKF Context Sync
Sync a Google Open Knowledge Format (OKF) context folder across every client and agent a user runs — laptop, browser, local agent, and cloud agent — without building a custom realtime backend.
This example is intentionally minimal: write kalam/schema.sql, run kalam dev, edit OKF Markdown on disk, and watch metadata updates flow live to the UI and demo agent.
Source: examples/live-okf-context-sync/
Showcase only. KalamDB does not ship folder sync as a core feature. This app demonstrates how to layer OKF context sync on top of SQL metadata, file upload/download, and live subscriptions.
What is Google Open Knowledge Format (OKF)?
Google Open Knowledge Format (OKF) is a folder of Markdown files agents and tools can read as structured context: profiles, project notes, runbooks, policies, and preferences. OKF files often include YAML frontmatter (title, type, tags) so agents know what each document is for.
Teams adopting OKF usually need the same folder available everywhere the user works:
- A local agent on the laptop
- A cloud agent in the browser or on a server
- A web UI for preview and status
- Multiple devices editing the same OKF paths
This example shows how KalamDB coordinates that shared state.
What it does
- Watches a local Google Open Knowledge Format (OKF) folder (
context/alice/,context/bob/) - Uploads Markdown file bytes through KalamDB file upload
- Stores metadata only in a user-scoped SQL table (
path,sha256, frontmatter, conflict flags) - Pushes live metadata updates to subscribers — no page refresh
- Lets a demo agent download canonical OKF files from KalamDB instead of reading disk
- Keeps per-user isolation (Alice cannot see or download Bob’s context)
Why KalamDB for OKF context?
| Need | How this example solves it |
|---|---|
| Same OKF folder on multiple clients | Each client runs a sync worker; metadata rows are the shared source of truth |
| Local agent + cloud agent both need context | Both subscribe to SQL metadata and download files by file_ref when needed |
| Realtime UI without websockets code | live() on a metadata SELECT |
| Per-user privacy | USER TABLE scopes rows and file downloads per user |
| Minimal setup | schema.sql + kalam dev — no ORM, no generated schema |
Prerequisites
- Node.js 18+
- Kalam CLI with
kalam devsupport (kalam self-updateor build from source)
Quick start
Then:
- Open
http://127.0.0.1:5177 - Sign in as alice (default)
- Edit
context/alice/profile.md— an OKF profile Markdown file - Watch the file list update live
- Ask the demo agent:
npm run dev:agent -- "Who is Alice?"
kalam dev starts KalamDB Server, applies kalam/schema.sql, and runs three processes:
Default credentials:
| Role | User | Password |
|---|---|---|
| Server admin (kalam dev) | root | kalamdb123 |
| Demo user Alice | alice | alice123 |
| Demo user Bob | bob | bob123 |
Multi-client OKF sync flow
When an OKF Markdown file changes on disk:
- The sync worker computes
sha256 - Parses YAML frontmatter from the Markdown file
- Uploads file bytes first (never writes metadata before upload completes)
- Compares
base_sha256with the server hash for conflict detection - Updates the canonical row or creates a dated conflict copy
- Live subscribers (web UI, agents) receive the metadata change immediately
Conflict policy: the faster writer keeps the canonical path (for example profile.md). A stale writer from another client creates profile.conflict-{timestamp}.md so nothing is silently lost.
Schema source of truth
The database schema lives only in:
Not schema.ts, Drizzle, or generated TypeScript types. kalam.toml sets generate_types = false.
File content is not stored in SQL columns. OKF bytes use KalamDB upload/download; SQL stores paths, hashes, frontmatter, and sync state.
What to try
Scenario 1: First sync
With context/alice/index.md and context/alice/profile.md present, run kalam dev. Files upload and metadata rows appear in the UI.
Scenario 2: Live edit across clients
- Keep the web UI open as Alice
- Edit
context/alice/profile.mdin your editor - The table updates without refresh — the same live row a cloud agent would see
Scenario 3: Local agent and cloud agent share context
- Run
npm run dev:agent -- "What projects is Alice working on?" - Edit
context/alice/projects/kalamdb.md - Run the agent again — it reads the updated OKF file from KalamDB, not from disk
Scenario 4: Per-user isolation
Switch the UI to bob. Bob only sees his own context_files rows and cannot download Alice’s files.
To sync Bob’s OKF folder, run: KALAM_SYNC_USER=bob npm run dev:sync
Files worth reading
| File | Purpose |
|---|---|
kalam/schema.sql | Single user-scoped metadata table — the only schema source |
kalam.toml | kalam dev wiring with generate_types = false |
src/sync-worker.ts | Watches OKF folder, uploads bytes, writes metadata |
src/web.tsx | Live metadata table with preview/download |
src/agent.ts | Downloads canonical OKF files for demo answers |
src/conflicts.ts | Simple last-writer-wins conflict copies |
Verify it works
With kalam dev running:
Integration tests against a live server:
Next steps
- File datatype — how OKF bytes are stored and downloaded
- Subscriptions — live metadata queries behind the UI
- kalam dev — one-command local workflow
- React AI Chat — fuller chat UI with attachments and approvals