Read this FIRST before making any changes.
Multiple AI agents work on this repo in parallel.
- Default mode: lane-based coordination. Each agent is assigned to a set of packages it owns.
- Optimize Earth mode: task-based coordination. If the human says
optimize earth, the task database becomes the source of truth and the leased task becomes the ownership boundary.
| Lane | Packages | Focus |
|---|---|---|
| Core Math | optimizer, wishocracy |
Algorithm correctness, paper compliance, test coverage |
| Policy & Budget | opg, obg, data |
Data pipelines, policy scoring, budget optimization |
| Web & API | web |
UI, API routes, task system, treaty pages |
| Treasury & Contracts | treasury-prize, treasury-iab, treasury-wish, treasury-shared |
Smart contracts, agent funding mechanism |
| Agent & Infra | agent, hypercerts, storage |
Autonomous analysis, publishing, agent orchestration |
- In default mode, one package per agent at a time. Do not edit files in packages outside your lane.
- Types are the contract.
@optimitron/dbexports are shared by everyone. Changes to the Prisma schema or exported types require explicit human approval. - Branch per agent. Use git worktrees. One branch per lane. Never push to main directly.
- Interface changes require coordination. If you need to change a public export signature that other packages depend on, document the change and stop — let the human merge and coordinate.
- Read the package AGENTS.md. Each package has its own
AGENTS.mdwith scope, exports, rules, and off-limits.
When the human says optimize earth, switch from lane ownership to task ownership.
Use this protocol exactly:
- Check the current branch/PR for broken GitHub Actions if that information is available.
- If GitHub Actions are broken because of repo code, treat fixing them as the immediate system-blocker task before trusting the queue.
- Audit whether the current queue is sane enough to trust.
- If the queue is obviously narrow, arbitrarily capped, missing quantified impact, or missing system/growth tasks, run
pnpm --filter @optimitron/web run bootstrap:optimize-earthif available, then propose system-improvement tasks first. - Call
getQueueAudit, then callgetNextActionwith your capabilities. - If an action returns a task, call
acquireLease. - Work only on the leased task and only touch files required for that task.
- If the task runs longer than the lease window, call
heartbeatLease. - If no executable task exists, call
proposeTaskBundlefor high-value missing tasks or unblockers. - Never create
ACTIVEtasks directly. Agent-created tasks must start asDRAFT. - Never promote tasks unless review passes and the promotion path explicitly allows it.
- Before any outreach action, respect
checkContactCooldown/recordContactAction. - Call
logAgentRunfor planned or skipped work, then release the lease when done.
Additional rules in Optimize Earth mode:
- One active lease per agent. Do not hold multiple tasks at once.
- Task lease supersedes lane boundaries. A leased task may require edits across packages, but only the files needed for that task may be changed.
- No repo-wide refactors from a vague prompt. If the task does not require it, do not do it.
- No freestyle canonical planning. New tasks enter the system through
proposeTaskBundle, review, and promotion. - If the task DB/MCP is unavailable, stop and report blocked. Do not invent an alternate source of truth.
- Run
pnpm check(typecheck + lint + test) before considering work done - Never import Prisma client in library packages (optimizer, wishocracy, opg, obg, data, agent, hypercerts, storage)
- Use
import typefor cross-package type imports - Follow existing patterns — read surrounding code before writing new code
- In
optimize earthmode, followdocs/OPTIMIZE_EARTH_PROTOCOL.md
Detailed docs live in docs/. Read the relevant ones before working:
docs/TYPE_SYSTEM.md— How types flow from Prisma → all packages
The Prisma schema (packages/db/prisma/schema.prisma) is the canonical source for all data models.
How types flow:
schema.prisma → @optimitron/db exports:
├── Prisma client (for web/API layer ONLY)
├── Pure TS interfaces (for ALL packages)
└── Zod schemas (for runtime validation)
DO:
- Import PLAIN TypeScript interfaces from
@optimitron/db(type-only imports) - Use
import type { Measurement, GlobalVariable } from '@optimitron/db' - Keep Prisma schema as the single source of truth
DO NOT:
- Import
@prisma/clientin library packages (optimizer, wishocracy, opg, obg, data) - Define duplicate interfaces in library packages that mirror DB models
- Create separate "db-types" packages — the types live in
@optimitron/db
They MAY import type-only exports from @optimitron/db.
They MUST NOT import Prisma client, database connections, or any runtime DB code.
They MUST work in the browser (for PGlite/local-first).
@optimitron/optimizer is completely domain-agnostic. NEVER reference:
- "drugs", "supplements", "treatments", "patients"
- "policies", "budgets", "politicians", "government"
- Use: "predictor", "outcome", "variable", "measurement", "effect size"
Domain-specific naming belongs in opg/obg/wishocracy/data/web.
| Convention | Example |
|---|---|
| FK field names match target model | globalVariableId not variableId |
| Predictor/outcome terminology | predictorGlobalVariableId not causeVariableId |
| Outcome not effect in properties | outcomeBaselineAverage (but effectSize stays — Cohen's d) |
| Enums over magic strings | Prisma enforces valid values |
| deletedAt on all models | Soft deletes for cr-sqlite sync |
optimizer ← (nothing, foundation)
wishocracy ← (nothing, standalone pure math)
opg ← optimizer, data
obg ← optimizer, opg
data ← optimizer
agent ← data, obg, opg, optimizer, storage, hypercerts, wishocracy
web ← everything
No circular deps. If you need something from both directions, it belongs in optimizer.
Before implementing any algorithm, read the relevant paper:
- Optimizer → dFDA Spec
- Wishocracy → Wishocracy
- OPG → Optimal Policy Generator
- OBG → Optimal Budget Generator
- IAB → Incentive Alignment Bonds