Home/Docs/Core Services/ContextForge

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πŸ”—

SurfaceEntrypointOwner
Web dashboardpython -m contextunity.forgeapp.py and dashboard/
Operational CLI`contextunity-forge statustraces
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 BrainAdminClient in forge/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 DebugCase views, Context Lineage across BrainCell β†’ 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 NeuroPath digests. A Forge review approval never self-mints a Shield EffectAuthorizationDecision, alters WorkerTestMan metrics, 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 (EncryptedExternalObjectRef records and signed object-protection receipts) will follow the same metadata-only boundary once ADR-0015 external offload is implemented.
Important
  • INV-FORGE-SERVICE-ISOLATION: ContextForge accesses upstream data exclusively through authenticated gRPC/SDK clients (such as BrainAdminClient) and shared contextunity.core contracts (including calculate_model_cost in dashboard/pages/cost.py) without opening peer databases directly or importing peer services (enforced by ARCH-FORGE-ISOLATION in .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"]
SymbolRoleInputs / Outputs
lifespanForge ASGI lifecycle managerStarlette app startup/shutdown -> registers/unregisters Forge HTTP runtime
healthzHTTP liveness probeGET /healthz -> 200 OK JSONResponse
BrainAdminClientAuthenticated Brain admin gRPC clientOperator 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:

  1. Headless Lab read kernel (B-101): default-off CLI/MCP read-only memory kernel indexing allowlisted blueprints into _doc BrainCells (scope_path = system.blueprints.*) and answering source-linked Graph-First queries without proposing patches or mutating state.
  2. Candidate generation with Immune Memory Recall (R-301 RouterArchitect): queries governed durable Procedure BrainEngrams, active UDB DebugCase anti-patterns, and low-Q BrainSynapse paths before emitting immutable ArtifactCandidateRef and TaskDAGPlanCandidate proposals plus NeuroPath Checkpoint 1 (generated) with zero auto-registration or execution.
  3. Deterministic classification (S-202 Shield Constitution): 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 (NeuroPath Checkpoint 2).
  4. Isolated execution & evaluation (W-102 WorkerSandman + W-201/W-202 WorkerTestMan): runs classified candidates in ephemeral sandboxes and produces immutable TestRunRecord / EvaluationSummary bundles (NeuroPath Checkpoint 3).
  5. Supervised review, Q-feedback & Lab Mode (F-201 / F-202): Forge Review Queues record append-only human verdicts (NeuroPath Checkpoint 4) and emit Brain ReportOutcomeObservation Q-feedback; Forge Lab Mode wraps coding-agent adapters inside ContextToken-scoped worktrees and packages high-Q Procedure BrainEngrams + recurring UDB patterns into candidate manifest/template workflow diffs.
  6. Target-owner promotion & HITL activation (B-202 / F-202 / B-501): Brain promotes governed procedure BrainEngrams (auto-recalled on subsequent runs), F-202 syncs human-approved manifest diffs to Shield/Router, and Router/Shield gate seed:* installations only after independently verifying the complete NeuroPath receipt 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 patternBacking ownerPurpose
lab://docs/{package}Brain _docCached external package/framework documentation
lab://blueprints/{id}Brain _doc (system.blueprints.*)Indexed ContextUnity architecture, ADR, and milestone sections
lab://experience/{pattern}Brain BrainSynapseHigh-Q positive experience patterns
lab://negative/{fault_class}Brain UDB / low-Q BrainSynapseRecurring fault cases and negative experience
lab://engram/{engram_id}Brain BrainEngram / Engram ViewCompiled doctrine and procedures
lab://step0/{module_path}ACDD / Forge code-map & _docStructural module ownership and seam summary
lab://review/{review_id}Forge Review QueuesCandidate proposal and evaluation evidence bundle
lab://audit/{finding_id}Brain _audit + Shield signatureSigned derived audit finding

VerificationπŸ”—

Use TESTS.md for the Forge owner suite and process tests. Use operator authentication for dashboard and CLI credentials.