Skip to main content
Glama

Cortical

Autonomous Agentic Harness for pi, 4-Tier Deterministic Merkle/Macro-Graph Second Brain MCP, Adaptive Permission Gate & Dual-Path Voice Engine

Author: Carlo Cancellieri (GitHub · ORCID: 0009-0006-4092-4234)
License: Apache License 2.0 (Apache-2.0)
Platforms: macOS (Apple Silicon Metal) & Linux (NVIDIA CUDA / Vulkan / CPU)


System Architecture

+-----------------------------------------------------------------------------------+
|                        USER INTERACTION LAYER (CLI & VOICE)                       |
|  • Dual-Path Voice Engine (`cortical.voice`): Wake-word + Resilient Barge-in      |
|    - System 1 Reflex (<900ms): Fast Q&A, Status Checks, Voice Permission Approval |
|    - System 2 Agentic: Async background delegation to `pi` Orchestrator           |
+-----------------------------------------+-----------------------------------------+
                                          |
                                          v
+-----------------------------------------------------------------------------------+
|                   `pi` AGENTIC HARNESS (`.pi/extensions/cortical-harness.ts`)     |
|  • Orchestrator (`delegate_subagent` / `submit_report` with bounded `maxTurns`)   |
|  • Adaptive Permission Gate (`cortical.permissions`):                             |
|    - Hard Guardrails (blocks `rm -rf /`, credential leaks, focus-stealing UI)     |
|    - Progressive Risk Learning (auto-approves recurring patterns after feedback)  |
+-------------------+-------------------------------------------+-------------------+
                    |                                           |
                    v (JSON-RPC 2.0 MCP)                        v (Deferred Skills & MCP)
+---------------------------------------+   +---------------------------------------+
|  CORTICAL SECOND BRAIN (`wiki.mcp`)   |   |   WEB & CODE AUTOMATION SUITE         |
|  • 4-Tier Deterministic Merkle Tree:  |   |  • `chrome-devtools-mcp` (Deferred)   |
|    1. `light`  (~50 tok index)        |   |  • Skill: `modern-web-guidance`       |
|    2. `medium` (~250 tok digest)      |   |    (3-Strategy SPA/React Resilience,  |
|    3. `high`   (~1000 tok synthesis)  |   |     Strict Zero Focus-Stealing)       |
|    4. `max`    (Full raw file)        |   |  • Skill: `browser-use-playwright`    |
|  • High-Level Episode Macro-Graph     |   |  • Skill: `cortical-second-brain`     |
|  • 2-Stage NLI Citation Fact-Checker  |   +---------------------------------------+
|  • Multi-Tenant Relational RBAC/ACL   |
+---------------------------------------+

Related MCP server: CiteAnything MCP Server

The 5 Second Brain Pillars + Hybrid Tree/Macro-Graph

  1. Parallel Deterministic Indexing (crawler.py): Uses ThreadPoolExecutor and bottom-up sha256 Merkle subtree hashing. Unchanged files and directories are skipped in $O(1)$.

  2. 2-Stage Citation Fact-Checking (fact_check.py): Verifies verbatim span containment against the raw document hash + evaluates semantic entailment (verified / refuted / unverified) via an NLI decision model.

  3. Multi-Tenancy (db.py): Native tenant_id and workspace_id isolation in SQLite WAL (with a schema 1:1 portable to PostgreSQL).

  4. Scalability via Hybrid Merkle Tree + Macro-Graph: Avoids $O(N^2)$ chunk graphs on thousands of documents by keeping documents in a 4-tier Merkle tree (light, medium, high, max) while maintaining a lightweight High-Level Macro-Graph (task_episodes + macro_edges) for cross-task episodic memory.

  5. Relational Permissions (RBAC/ACL): Path-prefix read/write permissions (acl_permissions) enforced directly at SQL query time.


3-Step Quickstart

Step 1 — Run the One-Shot Setup & Hardware Auto-Profiler

bash ./scripts/setup.sh

setup.sh creates .venv, runs cortical doctor to inspect your CPU/RAM/GPU/VRAM and auto-discover any running local inference servers (:8080 llama-server, :11434 Ollama, :8081 whisper-server) so small laptops incur zero extra VRAM overhead, generates .pi/mcp.json, and crawls the workspace into the Second Brain.

Step 2 — Navigate the 4-Tier Second Brain & Verify Citations

# Navigate root at 'light' depth (~50 tokens)
.venv/bin/cortical --db .cortical_data/wiki.db navigate --path / --depth light

# Escalate to 'high' or 'max' on a specific file
.venv/bin/cortical --db .cortical_data/wiki.db navigate --path /README.md --depth high

# Test the Dual-Path Voice router
.venv/bin/cortical voice-eval "Ehi Cortical, orchestra un sottoagente per analizzare il progetto"

Step 3 — Run the Complete Test Suite

.venv/bin/python -m unittest discover -s tests -v

Available Tools

5 tools
wiki_crawl_deltaC

Run the deterministic parallel Merkle-tree crawler on a directory, updating only modified branches.

Inputs: root_dir (required), principal_id.

wiki_navigateC

Navigate the deterministic Merkle-tree Second Brain at a specific synthesis depth: 'light' (~50 tokens), 'medium' (~250 tokens), 'high' (~1000 tokens), or 'max' (full raw content).

Inputs: path, depth, principal_id, include_children.

wiki_record_episodeC

Record a completed agentic task episode and link it in the High-Level Macro-Graph.

Inputs: goal (required), title (required), episode_id (required), outcome_status (required), +3 more.

wiki_verify_citationB

Verify a claim and quoted span against a source path using deterministic span check + NLI decision model.

Inputs: claim_text (required), quoted_span (required), source_path (required), principal_id.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 5 tools

    Disambiguation4/5

    Each tool targets a distinct action: search (FTS retrieval), navigate (depth-projected tree read), crawl_delta (indexing), verify_citation (validation), record_episode (write/append). The only mild overlap is search vs. navigate, since both are retrieval paths, but the descriptions (FTS5 vs. Merkle-tree depth projection) give an agent enough signal to choose correctly.

    Naming Consistency5/5

    All five tools follow a strict wiki_<verb>_<noun> pattern (wiki_search, wiki_navigate, wiki_crawl_delta, wiki_verify_citation, wiki_record_episode). The prefix and snake_case style are consistent, so the set is predictable and easy to scan.

    Tool Count5/5

    Five tools is well within the ideal 3-15 range for a knowledge-base server, and each one maps to a distinct lifecycle stage (retrieve, project, index, verify, record). No obvious filler or redundant tools are present.

    Completeness3/5

    The surface covers read/search, indexing, citation verification, and episode recording, but there is no page-level write path: no create/update/delete of a note or branch, and no listing or backlink operation. An agent that needs to author or correct content would hit a dead end and have to fall back to raw content delivery.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to use a neuro-symbolic memory fabric with bi-temporal knowledge graph and holographic VSA, providing tools for adding, searching, temporal queries, auditing, and proving memories with cryptographic provenance and zero-LLM ingest.
      2
      Apache 2.0
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to create verifiable, replayable citations, search private knowledge bases, and publish Markdown with verified citation markers.
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI agents to retrieve compact, evidence-backed knowledge graph packets, verify claims against sourced provenance, trace cryptographic audit trails, and explore entity relationships while minimizing context token usage.
      12
      13 npm
      1
      MIT