Lix for AI Agents
Give each agent task a branch for review before merging into main. Agents can edit normal files or SQL rows, locally or through a hosted server.
The pattern
- Create and switch to a task branch.
- Run the agent.
- Return to main and preview the merge.
- Merge, iterate, or discard.
const main = await lix.activeBranchId();
const task = await lix.createBranch({ name: "Agent task 123" });
await lix.switchBranch({ branchId: task.id });
// Run the agent. Its file and SQL writes are isolated to `task`.
// For example, the agent marks a task as done:
await lix.execute("UPDATE acme_task SET status = $1 WHERE id = $2", [
"done",
"T-1",
]);
await lix.switchBranch({ branchId: main });
const preview = await lix.mergeBranchPreview({ sourceBranchId: task.id });
// preview.changeStats is the one-line review summary:
// { total, added, modified, removed }
await lix.mergeBranch({ sourceBranchId: task.id });
Local file repository
Use FilesystemStorage for files on disk.
Hosted repository
For SDK-only access, query the server directly. For files in a sandbox or mounted volume, sync a filesystem replica. A browser can share the repository through an OPFS replica.
Why branches matter
- Run agents in parallel, isolated from main.
- Compare results and review diffs.
- Discard failed attempts.
Inspect the work
Review current rows in a session on the task branch:
const reviewLix = await lix.openAnotherSession({ branchId: task.id });
const rows = await reviewLix.execute(
"SELECT id, title, status FROM acme_task ORDER BY id",
);
await reviewLix.close();
Use lix_history('<schema>') for commit-anchored history, not current rows; use lix_diff('acme_task', from_commit_id, to_commit_id) for changes between commits.
lix_registered_schema lists schemas. lix_change shows repository-wide activity across branches.
Automatic merging
Lix combines different-column edits and resolves competing same-column edits using last-writer-wins by default. In a branch merge, the source is incoming; plugins can provide column mergers. Review the changes before merging. See Branching for the merge rules.
Next
- Getting Started: the basic setup.
- Branching: previews, automatic merging, and side-by-side reads.
- History: SQL for review and undo.