Skip to content
chanmathewPublic

About

Circuit is a local-first desktop app for running AI coding agents through structured, reviewable development workflows.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Circuit

Circuit is a local-first control plane / harness for governed coding-agent workflows.

See the project brief for product goals, architecture, and milestones.

Prerequisites

  • Node.js 22.13+
  • Vite+ (vp) — install with curl -fsSL https://vite.plus | bash
  • pnpm 11.8+ (via Corepack: corepack enable)

Getting started

corepack enable
vp install
pnpm dev        # starts the Electron desktop app

Do not use vp dev alone — that starts the Vite+ web dev server, not Electron. Use pnpm dev from the repo root (runs electron-vite dev in apps/desktop).

First install also downloads the Electron binary and compiles native dependencies for Electron. If the app fails to open, see Troubleshooting.

The Electron desktop app opens with placeholder Dashboard and New Task screens.

Toolchain

This repo follows Vite+ monorepo conventions:

  • vp install / vp check / vp run — root toolchain (lint, fmt, typecheck, task cache)
  • vp migrate — applied for Vite+ alignment (staged, run.cache, catalog mode)
  • vp add <pkg> — preferred way to add dependencies (not manual package.json edits)
  • pnpm-workspace.yaml — workspace membership, catalog, and supply-chain policy
  • TypeScript 7 RC (typescript@rc / 7.0.1-rc) via catalog — platform packages are in minimumReleaseAgeExclude until the RC ages out

Electron exception: electron-vite@6 uses stock Vite 8 for bundling, so there is no global vite catalog override. Only apps/desktop pins vite directly.

Monorepo layout

apps/desktop/          Electron + React shell (package name: desktop)
packages/ui/           Shared shadcn-style components
packages/protocol/     Canonical events, blocks, and parsers
packages/workflow/     Workflow types and definitions
packages/shared/       IDs, paths, errors, events (re-exports protocol)
packages/db/           Drizzle schema, migrations, SQLite client
packages/agent-adapters/  Agent adapter interfaces
packages/workspace-manager/
packages/git/
packages/prompts/

Scripts

Command Description
pnpm dev Start desktop app (electron-vite dev)
vp run ready Full quality gate: check + typecheck + build
vp build Build all packages
vp check Lint, format, and typecheck
vp run -r typecheck Typecheck all workspace packages
pnpm --filter @circuit/db db:generate Generate SQL migration from schema changes (drizzle-kit generate)
pnpm --filter @circuit/db db:migrate Apply migrations to optional dev DB (drizzle-kit migrate)
pnpm --filter @circuit/db db:reset Delete dev DB and re-apply all migrations
pnpm --filter @circuit/db db:studio Drizzle Studio (dev DB)

Database migrations

Schema: packages/db/src/schema.ts. Migrations: packages/db/migrations/ (generated by Drizzle Kit only — never hand-write SQL).

Two databases: the Electron app migrates its own DB on every launch via drizzle-orm + the same SQL files under migrations/. CLI commands use a separate dev copy for Drizzle Studio.

Database Location Who uses it How schema updates apply
App ~/Library/Application Support/desktop/circuit.db (macOS) Electron desktop app pnpm dev — createDb() runs pending migrations on launch
CLI dev packages/db/.data/circuit-dev.db db:migrate, db:studio pnpm --filter @circuit/db db:migrate

Workflow

  1. Edit packages/db/src/schema.ts
  2. pnpm --filter @circuit/db db:generate — creates SQL under migrations/
  3. Commit the new migration files
  4. pnpm dev — app DB picks up pending migrations automatically

For a clean dev DB: pnpm --filter @circuit/db db:reset (deletes packages/db/.data/circuit-dev.db and re-applies migrations). To wipe the app DB, quit the app and delete ~/Library/Application Support/desktop/circuit.db (and -wal / -shm if present), then restart — migrations run on launch.

Migrations are squashed for development (0000_reflective_darkhawk.sql, 0001_next_purple_man.sql). When the baseline changes, wipe the app or dev DB and re-run migrations — no in-place upgrade path.

Troubleshooting

App won't start: ERR_DLOPEN_FAILED / NODE_MODULE_VERSION on better_sqlite3

Why this happens: Circuit uses better-sqlite3, a native SQLite driver (C++ compiled to a .node binary). It is not pure JavaScript — the binary must match the exact runtime that loads it. Electron embeds its own Node (different ABI than the Node on your PATH). We compile one copy in node_modules; whichever runtime built it last wins.

  • pnpm dev → needs the Electron build (desktop postinstall runs electron-rebuild)
  • db:migrate / db:reset / db:studio → need the Node build during the command (pnpm rebuild better-sqlite3), then restore Electron automatically (pnpm --filter desktop rebuild:native at the end; for Studio, that runs when you quit Studio)

If something still breaks (e.g. you ran pnpm rebuild better-sqlite3 by hand), restore the build for the runtime you care about:

# App won't open
pnpm --filter desktop rebuild:native
pnpm dev

# db:migrate fails with ERR_DLOPEN_FAILED
pnpm rebuild better-sqlite3
pnpm --filter @circuit/db db:migrate

This is unrelated to creating migrations — db:generate does not load SQLite. Normal schema work (db:generate → commit → pnpm dev) never requires postinstall.

Fresh install: Electron binary missing

node apps/desktop/scripts/ensure-electron.mjs
pnpm dev

Supply-chain policy

This repo uses explicit pnpm 11 protections in pnpm-workspace.yaml:

  • minimumReleaseAge (24h) — newly published versions are not installed immediately
  • minimumReleaseAgeStrict — install fails if only matching versions are too new
  • blockExoticSubdeps — block git/tarball/http transitive dependencies
  • strictDepBuilds + allowBuilds — block unreviewed postinstall scripts; electron and esbuild are pre-approved

trustPolicy: no-downgrade is documented but not enabled yet — many transitive dependencies lack consistent npm provenance and block installs. Re-enable once the dependency tree stabilizes.

When adding dependencies, use vp add <pkg> (or vp add <pkg> --filter desktop). If a build is blocked, add an explicit entry to allowBuilds after review — do not use --ignore-scripts in CI.

For urgent security patches, use minimumReleaseAgeExclude or run vp pm audit --fix.

Scaffold status

Milestone 1 (Local shell) and Milestone 2b (Workflow state) are implemented:

  • SQLite persistence in app.getPath('userData')/circuit.db via @circuit/db
  • Add local git repo from the dashboard
  • Composer-first task creation (createDraftTask + first chat message)
  • Optional structured workflow attached from the Workflow panel (ADR 002)
  • Writes .Circuit/tasks/<slug>/ artifacts in the target repo
  • Phase rows and artifact files created on Start phase, not on Enable

Also done: Circuit protocol (@circuit/protocol) — event schemas, structured block types, parsers.

Also done: Mock agent loop (M3) — mock adapter phase runs, structured activity feed, approve/revise, markdown preview, decision cards with gating, proceed labels.

Also done: Context packs & fresh sessions (M3b) — context pack builder from approved artifacts, fresh session per mock run, sessionId + contextPackHash on phase_runs.

Not yet implemented:

  • Research/structure/plan structured panels (prototype-only modes)
  • Chat-inferred revision prompts (minor vs material)
  • OpenCode integration
  • Git worktrees and diff review

Next milestone: OpenCode integration — real agent runs with the same context pack + session model.

License

MIT — see LICENSE.

About

Circuit is a local-first desktop app for running AI coding agents through structured, reviewable development workflows.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages