CortexBuild β System Architecture (v0.1)¶
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CortexBuild CONTROL PLANE β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Web UI (Next.js 15 + Tailwind + shadcn/ui) β β
β β β’ Project list β β
β β β’ Task board (Linear-style; PM-persona language) β β
β β β’ Agent timeline (real-time; tech-lead-persona detail) β β
β β β’ Approval queue (PR merge, deploy, spend, secrets) β β
β β β’ Settings: provider keys, autonomy matrix, rule packs β β
β β β’ Audit log viewer (filterable, exportable) β β
β β β’ Cost dashboard ($ per task, per agent, per provider) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β WebSocket (progress, approvals)
β REST (commands, queries)
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ORCHESTRATOR SERVICE (Python 3.12 + FastAPI) β
β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββββββ β
β β Phase Sequencer β β Rule SSoT β β Recurrence Ledger β β
β β (wave model) β β Engine β β Persister β β
β β β β β β β β
β β PlanβCriticβ β β Renders rules β β Post-mortem capture β β
β β Buildβ[Tβ₯Sβ₯O] β β to all enabled β β β ledger entry β β
β β βPR Reviewer β β provider tools β β β new rule draft β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββββββ β
β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββββββ β
β β Provider Router β β Approval Gate β β Audit Log Writer β β
β β β β State Machine β β β β
β β Claude/Copilot/ β β Auto/Notify/ β β Every shell op, β β
β β Codex/Bedrock/ β β Approve per β β file edit, API call β β
β β Vertex/Ollama β β action class β β β Postgres + S3 β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β Multi-tenant data layer (Postgres + Redis) ββ
β β β’ projects, users, sessions, approvals, tasks, agents, runs ββ
β β β’ audit_log, recurrence_ledger, rule_packs, llm_provider_keys ββ
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β spawns workspace β invokes LLM
βΌ βΌ
ββββββββββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββ
β EXECUTION RUNTIME β β LLM PROVIDER APIs β
β (Daytona devcontainer) β β β
β β β β’ Anthropic (Claude) β
β Per-project sandbox VM: β β β’ OpenAI (GPT/Codex) β
β β’ Repo clone (read-write) β β β’ GitHub Copilot CLI β
β β’ Toolchain auto-install β β β’ Bedrock β
β (node, python, go, rust, java) β β β’ Vertex β
β β’ Provider CLIs β β β’ Ollama (local) β
β (gh, claude, codex, etc.) β β β
β β’ Network egress firewall β β Keys: BYO, encrypted β
β β’ Resource limits (cgroups) β β at rest (KMS), never β
β β’ Audit-logged shell β β leave control plane β
ββββββββββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER'S GIT PROVIDER (external) β
β β
β GitHub / GitLab / Bitbucket / Azure DevOps β
β Branches, PRs, issues, comments β CortexBuild writes here β
β User reviews in their normal git UI; CortexBuild never blocks merge β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Diagram legend (adjacent qualifiers). In the boxes above: Bedrock / Vertex are reachable via an OpenAI-compatible gateway only β no native adapter (roadmap); native providers = Claude, Gemini, OpenAI-compatible. The Execution Runtime (Daytona devcontainer) box is Phase 1 β planned π, not yet shipped.
Status β roadmap vs shipped. This diagram shows the full target architecture. Shipped today (P0): rule SSoT + 4-surface
render, the recurrenceledger, brownfield analysis, and offline conformance/eval. Planned (not yet shipped): the Execution Runtime (Daytona devcontainer / per-project sandbox) is Phase 1 β planned π; the fully autonomous orchestrator control loop and the 20-action-class approval matrix are later phases. Provider note: native providers today are Anthropic (Claude), Gemini, and any OpenAI-compatible endpoint β Bedrock / Vertex / Azure OpenAI are reachable only via an OpenAI-compatible gateway (no native adapter).
Component responsibilities¶
Web UI (Next.js)¶
- Authenticated dashboard
- Real-time updates via WebSocket
- Approval dialogs (blocking when needed)
- Persona toggle (PM β tech-lead)
- BYO key management (write-only forms)
Orchestrator Service (FastAPI)¶
- Stateless API + stateful workers
- Multi-tenant: project = tenant boundary
- Long-running task supervision
- Provider adapter abstraction
- Rule rendering (port of
render-agents.ps1) - Recurrence ledger CRUD
- Audit log emission
Execution Runtime (Daytona) β Phase 1, planned π¶
- One devcontainer per project, persistent
- Toolchain installers triggered by detected stack
- Provider CLIs preinstalled (or installed on-demand)
- Shell wrapped to log every command
- Network egress firewall (allow git provider + LLM APIs only by default)
- Filesystem snapshots before risky operations
LLM Provider APIs¶
- Calls happen from the orchestrator (not the VM) for cost tracking + key isolation
- VM only ever talks to its repo + the orchestrator
- Orchestrator caches plan outputs
Boundaries (what runs where)¶
| Concern | Control Plane | VM | Git Provider | LLM API |
|---|---|---|---|---|
| Repo clone | β | β | (source) | β |
| Code edit | β | β | β | β |
| LLM call | β (router) | β | β | (target) |
| Rule rendering | β | β | β | β |
| PR open | (orchestrates) | β
(gh pr create) |
(target) | β |
| Approval dialog | β | β | β | β |
| Audit log write | β | (emits events) | β | β |
| Recurrence ledger | β | β | β | β |
| Secrets storage | β (KMS) | (env vars at runtime) | β | β |
Data model (top-level tables)¶
-- Tenancy
projects (id, slug, owner_user_id, repo_url, git_provider, status, created_at)
users (id, email, oauth_provider, oauth_id, persona_default, created_at)
project_members (project_id, user_id, role) -- owner | admin | member | viewer
-- Configuration
provider_keys (id, project_id, provider, key_ciphertext, kms_key_id, created_at)
autonomy_matrix (project_id, action_class, level, updated_by, updated_at)
rule_packs_enabled (project_id, pack_name, pack_version, enabled_at)
-- Work
tasks (id, project_id, source, source_id, title, body, complexity, confidence, status, ...)
runs (id, task_id, branch_name, status, started_at, ended_at, cost_usd, ...)
agent_invocations (id, run_id, agent_id, provider, model, prompt_tokens, completion_tokens, latency_ms, ...)
-- Approvals
approvals (id, project_id, run_id, action_class, payload_json, requested_at, decided_at, decision, decided_by)
-- Governance
audit_log (id, project_id, run_id, actor_type, actor_id, action, target, payload_json, ts)
recurrence_ledger (id, project_id, class, severity, agent, symptom, root_cause, fix, guard_id, status, automation_target, ts)
-- Rule SSoT
rule_packs (id, slug, version, source_url, signed_by, content_hash)
rendered_targets (project_id, target_tool, target_path, content_hash, rendered_at)
Provider Adapter interface¶
class ProviderAdapter(Protocol):
name: str # "claude_code" | "copilot_cli" | "codex" | "bedrock" | ... (bedrock/vertex = gateway-only, no native adapter)
async def invoke(
self,
prompt: str,
*,
system: str | None = None,
tools: list[ToolDef] | None = None,
model_hint: ModelTier, # "reasoning_heavy" | "balanced" | "fast_cheap"
max_tokens: int = 4096,
timeout_seconds: int = 300,
) -> InvocationResult: ...
async def stream(self, ...) -> AsyncIterator[StreamChunk]: ...
def estimate_cost(self, prompt: str, model_hint: ModelTier) -> Decimal: ...
def capabilities(self) -> set[Capability]:
# {CODE_EXECUTION, WEB_BROWSE, FILE_IO, VISION, LONG_CONTEXT}
...
async def rate_limit_status(self) -> RateLimitStatus: ...
async def health_check(self) -> HealthStatus:
# Daily smoke test from CI hits this
...
Phase Sequencer (wave model)¶
Ported from CortexVigil rule-phase-sequence:
Wave 1a: Planner (sequential)
Wave 1b: Critic (conditional β skip for trivial low-risk plans)
Wave 2: Builder (sequential β only writer)
Wave 3: Tester β₯ Security β₯ Optimizer (parallel β all read-only)
Wave 4: PR Reviewer (sequential)
State machine guarantees: agents never run out of order; waves block on previous wave's completion; wave 3 parallelism is opt-in per runtime capability.
Approval Gate State Machine¶
Action requested by agent
β
βΌ
ββββββββββββββββββββ
β Lookup autonomy β
β level for class β
ββββββββββββββββββββ
β
βΌ
βββββββββ AUTO ββββββββββββββββ
β Level ββββββββββββΊβ Execute now ββββΊ Audit log
βββββ¬ββββ ββββββββββββββββ
β NOTIFY ββββββββββββββββ ββββββββββββββββ
ββββββββββββββββΊβ Execute now βββΊβ Notify UI ββββΊ 5-min rollback window
β ββββββββββββββββ ββββββββββββββββ
β
β APPROVE ββββββββββββββββ ββββββββββββββββ βββββββββββββββ
ββββββββββββββββΊβ Pause agent βββΊβ UI prompts βββΊβ User decidesβ
ββββββββββββββββ ββββββββββββββββ ββββββββ¬βββββββ
β
Yes ββββββββ΄βββββββ No
βΌ βΌ
ββββββββββββββ ββββββββββββββ
β Execute β β Abort task β
β + audit β β + audit β
ββββββββββββββ ββββββββββββββ
Sequence: Onboarding a brownfield repo¶
User UI Orchestrator VM (Daytona) LLM Provider
β β β β β
β Connect repo URL β β β β
ββββββββββββββββββββββΊβ β β β
β β POST /projects β β β
β βββββββββββββββββββββΊβ β β
β β β Create workspaceβ β
β β βββββββββββββββββββΊβ β
β β β β Clone repo β
β β β β Detect toolchain β
β β β β Install tools β
β β β β Run graphify β
β β ββββββββββββββββββββ Structural report β
β β β β β
β β β Invoke Analyser β β
β β βββββββββββββββββββββββββββββββββββββββΊβ
β β ββββββββββββββββββββββββββββββββββββββββ Inferred rules
β β β β β + heatmap
β β Show heatmap + Q1 β β β
β ββββββββββββββββββββββ β β
β Answer Q1..Qn β β β β
βββββββββββββββββββββββ β β β
β β POST answers β β β
β βββββββββββββββββββββΊβ β β
β β β Render rule packβ β
β β β β .CortexBuild/ β β
β β β Push to repo β β
β β βββββββββββββββββββΊβ β
β β β β git push origin β
β β β β "CortexBuild init" β
β β β β β
β β Show first roadmapβ β β
β ββββββββββββββββββββββ β β
β Approve roadmap β β β β
ββββββββββββββββββββββΊβ β β β
β β POST /run/start β β β
β βββββββββββββββββββββΊβ β β
β β β β β
β β β¦work beginsβ¦ β β β
Note: the VM (Daytona) lane above is the Phase 1 β planned π execution runtime, not yet shipped.
Failure modes + handling¶
| Failure | Detection | Response |
|---|---|---|
| LLM provider timeout | Adapter timeout (300s) | Retry once with smaller model; surface to user if both fail |
| Provider rate limit | HTTP 429 | Queue; backoff; route to alternate provider if user enabled |
| VM crash | Daytona health check | Restart workspace; resume from last checkpoint (planned runtime β Phase 1 π) |
| Git push rejected | Exit code from git push |
Open issue on repo; pause project; notify user |
| Approval timeout | No user response in 24h | Auto-decline; surface in dashboard |
| Budget exceeded | Cost meter | Pause project; notify user; require explicit unblock |
| Recurring same-class failure | Ledger query | Auto-promote to enforced rule; stop attempting that class |
| Provider key revoked | Adapter auth error | Mark project paused; notify user via email + UI |
| Worker process OOM | Container metrics | Auto-restart; failed task flagged for manual review |