ContextForge architectureπ
ContextForge is the human and supervised-agent workspace service unifying observability dashboards, bounded MCP tools, documentation sync (ForgeLibrarian), review queues, and supervised Lab Mode. Source lives under services/forge/src/contextunity/forge/.
Current surfacesπ
| Surface | Entrypoint | Owner |
|---|---|---|
| Web dashboard | python -m contextunity.forge | app.py and dashboard/ |
| Operational CLI | `contextunity-forge status | traces |
| MCP server (planned) | Planned Forge MCP surface (not mounted in app.py today) | mcp/ and data/ |
Core boundary: Workspace and observer, never authorityπ
ContextForge composes typed owner APIs (Brain, Router, Worker, Shield) for human inspection, review workflows, and supervised development without owning domain state or security authority:
- Zero direct SQL: Forge accesses upstream data exclusively through authenticated gRPC/SDK clients (such as
BrainAdminClientinforge/data/brain_admin_client.py) and never opens service SQLite files or PostgreSQL tables directly. - Bounded per-domain views: Observability is split into bounded application queries (Graph Journey, UDB
DebugCaseviews, Context Lineage acrossBrainCellβBrainSynapseβBrainEngram, Worker Operations, TestMan Evaluation Workspace, and metadata-only Security/Tenant evidence) rather than a single platform-wide union or generic event ledger. - Review is evidence, not execution authority: Forge Review Queues record append-only human verdicts bound to exact subject and
NeuroPathdigests. A Forge review approval never self-mints a ShieldEffectAuthorizationDecision, altersWorkerTestManmetrics, or activates runtime artifacts directly; downstream target owners (Shield,Brain,Router) independently verify receipts before acting. - Ciphertext and secret opacity: Today Forge inspects metadata and redacted trace/evidence views returned by Brain/Shield RPCs without holding keys or decrypting payloads. Planned ADR-0015 external-object views (
EncryptedExternalObjectRefrecords and signed object-protection receipts) will follow the same metadata-only boundary once ADR-0015 external offload is implemented.
- INV-FORGE-SERVICE-ISOLATION: ContextForge accesses upstream data exclusively through authenticated gRPC/SDK clients (such as
BrainAdminClient) and sharedcontextunity.corecontracts (includingcalculate_model_costindashboard/pages/cost.py) without opening peer databases directly or importing peer services (enforced byARCH-FORGE-ISOLATIONin.acdd/lint/rules.yaml), and never acts as a token minter, effect-authorization allow source, or autonomous promotion authority.
Key symbols and inputs/outputsπ
flowchart LR
Browser["Operator Browser"] --> ASGI["Starlette Dashboard (lifespan, healthz, routes)"]
Operator["Operator Shell"] --> CLI["contextunity-forge CLI"]
ASGI --> Client["BrainAdminClient + Core SDK Clients"]
CLI --> Client
Client --> Peers["Brain / Router / Worker / Shield gRPC"]| Symbol | Role | Inputs / Outputs |
|---|---|---|
lifespan | Forge ASGI lifecycle manager | Starlette app startup/shutdown -> registers/unregisters Forge HTTP runtime |
healthz | HTTP liveness probe | GET /healthz -> 200 OK JSONResponse |
BrainAdminClient | Authenticated Brain admin gRPC client | Operator bearer + bounded query args -> Brain traces, memory, and UDB views |
ForgeLibrarian and documentation-as-memoryπ
ForgeLibrarian orchestrates continuous documentation synchronization and drift detection (additions, edits, renames, deletions, and source-hash mismatches across docs, ADRs, .proto contracts, and config schemas) exclusively through canonical _doc BrainCell APIs (IngestDocument, DeleteDocument, SearchCells). It introduces no duplicate documentation database or competing MCP search authority.
Self-evolving platform loop and NeuroPathπ
ContextUnity separates read-only architectural assistance, candidate generation, sandbox verification, human review, and target activation across distinct service owners:
- Headless Lab read kernel (
B-101): default-off CLI/MCP read-only memory kernel indexing allowlisted blueprints into_docBrainCells(scope_path = system.blueprints.*) and answering source-linked Graph-First queries without proposing patches or mutating state. - Candidate generation with Immune Memory Recall (
R-301RouterArchitect): queries governed durableProcedure BrainEngrams, activeUDBDebugCaseanti-patterns, and low-QBrainSynapsepaths before emitting immutableArtifactCandidateRefandTaskDAGPlanCandidateproposals plusNeuroPathCheckpoint 1 (generated) with zero auto-registration or execution. - Deterministic classification (
S-202ShieldConstitution): inspects candidate plans, patches, and scripts via deterministic rule/AST checks (allow_sandbox | require_human_review | deny), locking policy- or auth-touching changes to human review (NeuroPathCheckpoint 2). - Isolated execution & evaluation (
W-102WorkerSandman+W-201/W-202WorkerTestMan): runs classified candidates in ephemeral sandboxes and produces immutableTestRunRecord/EvaluationSummarybundles (NeuroPathCheckpoint 3). - Supervised review, Q-feedback & Lab Mode (
F-201/F-202): Forge Review Queues record append-only human verdicts (NeuroPathCheckpoint 4) and emit BrainReportOutcomeObservationQ-feedback; Forge Lab Mode wraps coding-agent adapters insideContextToken-scoped worktrees and packages high-QProcedure BrainEngrams+ recurringUDBpatterns into candidate manifest/template workflow diffs. - Target-owner promotion & HITL activation (
B-202/F-202/B-501):Brainpromotes governed procedureBrainEngrams(auto-recalled on subsequent runs),F-202syncs human-approved manifest diffs toShield/Router, andRouter/Shieldgateseed:*installations only after independently verifying the completeNeuroPathreceipt chain.
Governed lab:// MCP resource schemeπ
Lab tools expose read-only context over canonical owner APIs through closed lab:// URIs (unknown schemes and path escapes fail closed):
| URI pattern | Backing owner | Purpose |
|---|---|---|
lab://docs/{package} | Brain _doc | Cached external package/framework documentation |
lab://blueprints/{id} | Brain _doc (system.blueprints.*) | Indexed ContextUnity architecture, ADR, and milestone sections |
lab://experience/{pattern} | Brain BrainSynapse | High-Q positive experience patterns |
lab://negative/{fault_class} | Brain UDB / low-Q BrainSynapse | Recurring fault cases and negative experience |
lab://engram/{engram_id} | Brain BrainEngram / Engram View | Compiled doctrine and procedures |
lab://step0/{module_path} | ACDD / Forge code-map & _doc | Structural module ownership and seam summary |
lab://review/{review_id} | Forge Review Queues | Candidate proposal and evaluation evidence bundle |
lab://audit/{finding_id} | Brain _audit + Shield signature | Signed derived audit finding |
Verificationπ
Use TESTS.md for the Forge owner suite and process tests. Use operator authentication for dashboard and CLI credentials.