Policy-controlled Bitcoin treasury for AI agents — a deterministic policy engine (auto-approve / escalate / reject), Gemini for agent missions and in-app help, and Lightning-style settlement using real SHA-256 preimage / payment_hash primitives, plus internal vs competitor transaction views.
flowchart LR
subgraph ui [Next.js]
D[Dashboard]
A[Agents / Approvals]
T[Transactions]
end
subgraph api [Hono API :4000]
PE[Policy engine]
AG[Gemini + fallback]
LN[SHA-256 / HTLC-style]
end
DB[(Supabase Postgres)]
ui --> api
PE --> DB
AG --> PE
LN --> DB
This repo is one Eclipse application: a Next.js UI and a Hono API that share one product surface. They live in two npm packages for clarity and deployment.
| Path | Role |
|---|---|
eclipse-backend/ |
API (port 4000): Supabase (service role), policy engine, settlement (lightning.ts — simulated preimage/hash by default; real Bitcoin testnet when TREASURY_WIF is set and the wallet has UTXOs). Gemini for missions, synthesis, and /api/chat help. Optional DATABASE_URL runs SQL migrations on API boot. |
eclipse-frontend/ |
Web UI (port 3000): calls the API via NEXT_PUBLIC_API_URL (defaults to http://localhost:4000). |
From the repo root, npm run dev starts both; see Run locally below.
Architecture (diagrams + API inventory): ARCHITECTURE.md.
Deploy (Vercel frontend + separate API host): DEPLOY.md.
Configure backend in eclipse-backend/.env (copy from eclipse-backend/.env.example):
- Required:
SUPABASE_SERVICE_ROLE_KEY,NEXT_PUBLIC_SUPABASE_URL - Optional:
NEXT_PUBLIC_SUPABASE_ANON_KEY(server),GEMINI_API_KEY(live missions, synthesis, Eclipse Help chat; fallbacks work without it),GEMINI_MODEL(defaults togemini-2.5-flash-litewith quota fallbacks),DATABASE_URL,TREASURY_INITIAL_SATS,TREASURY_WIF(real testnet spends when funded)
Configure frontend in eclipse-frontend/.env.local (copy from eclipse-frontend/.env.example):
NEXT_PUBLIC_API_URL— optional; defaults tohttp://localhost:4000
Treasury math: TREASURY_INITIAL_SATS (default 1.5M) + sum(treasury_topups) − sum(settled transactions). Header balance follows ledger vs on-chain rules described in the API (/api/treasury/balance).
- Prefer
DATABASE_URLineclipse-backend/.envsonpm run migrate(or API startup) appliessupabase/migrations/*.sqlin order. - If
npm run migratefails withEHOSTUNREACH, use the Session pooler URI from Supabase → Connect → Session pooler, then migrate again. - Alternative: run
eclipse-backend/supabase/FULL_SCHEMA.sqlonce in the Supabase SQL Editor on an empty project.
Without tables, the UI may show missing-table errors until the schema exists.
- Copy
eclipse-backend/.env.example→eclipse-backend/.envandeclipse-frontend/.env.example→eclipse-frontend/.env.local; fill Supabase (and optional Gemini) from your dashboard. - Repo root:
npm install && npm run dev(API + web). Or runnpm run devinsideeclipse-backendandeclipse-frontendin two terminals. - Open http://localhost:3000
- Judge path: Run Demo in the sidebar → http://localhost:3000/demo
GitHub Actions (.github/workflows/ci.yml) on main: backend tsc + tests, frontend lint + tests + production build.
- Backend:
cd eclipse-backend && npm test— policy engine, Lightning settlement helpers, Gemini mission (mocked). - Frontend:
cd eclipse-frontend && npm test— helpers and CSV export. - Root:
npm run ci— full pipeline.
curl http://127.0.0.1:4000/health→{"ok":true}- With schema:
curl http://127.0.0.1:4000/api/dashboard→summary+recent_activity
MIT — see LICENSE.