Amr Gharbeia 43dbe3cf2d
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 8s
feat(v0.2.0): Self-Improvement & Structural Integrity
- Fix critical paren balance issues across harness/skills.org, act.org,
  loop.org, memory.org, and skills/self-edit|emacs-edit.org
- Add :reload-skill cognitive tool for hot-reloading without restart
- Add :generate-embeddings tool and self-edit hot-reload infrastructure
- Wire all new skills (self-edit, emacs-edit, lisp-utils) into main ASDF
- Regenerate all .lisp tangled files via emacs --batch org-babel-tangle
- Add :opencortex/tests ASDF system with 14 test suites
- Fix test files to compile cleanly (self-edit-tests symbol vis, etc.)
2026-04-27 07:30:01 -04:00

OpenCortex: The Conductor of your Life Stack

opencortex is a minimalist, extensible AI agent framework designed to manage and continuously organize your personal knowledge base. It transforms a static collection of plaintext notes into a live, programmable Memex—an automated, personalized memory system where humans and AI collaborate in the exact same workspace.

A neurosymbolic AI agent framework for the 100-year Memex

The Problem with Current AI Agents

The current ecosystem of AI agents (typically built in Python or TypeScript) is overwhelmingly built on architectural choices that prioritize rapid prototyping over long-term reliability, security, and self-modification:

1. The Format Trap (Markdown & JSON)

Most agents force a painful translation layer. Humans write in Markdown, which lacks a strict Abstract Syntax Tree (AST)—a rigorous, nested representation of data that machines need to parse context reliably. Machines, in turn, output JSON, which is hostile for human thought and note-taking.

The result is a fractured workspace where the agent's memory and the human's memory are fundamentally incompatible. You cannot see what the agent sees. The agent cannot naturally work with your notes.

2. The Language Trap (Python & TypeScript)

Python and TypeScript are fantastic for gluing together APIs, but they are poorly suited for an agent that needs to safely read, write, and execute its own code at runtime. Their underlying structures are complex and opaque, making autonomous self-editing incredibly brittle and dangerous.

How do you trust an agent to modify its own Python code when Python's AST is so complex that even human programmers need IDEs to navigate it?

3. The Probabilistic Trap

Almost all modern agents rely entirely on probabilistic reasoning. We ask an AI model to guess a shell command or write a Python script, and then blindly pipe that output to a terminal. Without a rigorous, deterministic layer to formally verify the model's proposals before execution, these systems are fundamentally unsafe.

The model might hallucinate a command. It might output valid syntax that still does something dangerous. Without a deterministic gate, there's nothing between the guess and the terminal.

The Vision: A Modern, Homoiconic Memex

openCortex abandons these fragile paradigms by returning to first principles and embracing two historically powerful technologies: Org-mode and Common Lisp.

Org-mode: The Universal Language

Instead of wrestling with Markdown parsers or hiding data in opaque databases, openCortex mandates that Org-mode is the native AST for both humans and machines.

Org-mode is unique because it seamlessly brings together:

  • Human-readable prose
  • Structured metadata (properties and tags)
  • Lifecycle states (TODO/DONE/PLAN)
  • Executable code blocks

…all in a single plain-text file. The code is the data, and the data is the interface. When the agent "remembers" a fact or schedules a task, it writes an Org headline. You read exactly what the agent reads.

This is not a compromise—it's the design principle. The agent's memory and your memory are the same format, the same file, the same text.

Common Lisp: The Engine of Self-Modification

There is a beautiful irony to openCortex: Lisp was invented in 1958 specifically to achieve Artificial Intelligence, and it has been waiting nearly 70 years for this exact moment in computing history.

Lisp possesses a unique property called Homoiconicity: the primary representation of the program is also a data structure (nested lists) within the language itself. Because Lisp code is Lisp data, it is trivially easy for an AI to generate, manipulate, and safely evaluate new tools at runtime.

This makes Lisp the ultimate, un-brittle language for a "self-writing" agent. The agent doesn't need an AST parser—it can simply read and write lists directly. The agent doesn't need a code generator—it can write Lisp that executes Lisp.

The Probabilistic-Deterministic Loop

openCortex does not let AI models touch your system directly. Instead, it splits cognition into two distinct engines:

  1. The Probabilistic Engine (Neural/Dynamic): Provides semantic understanding and dynamic reasoning. It utilizes a Dynamic LLM Cascade (OpenRouter, Ollama, Anthropic) to ensure the agent always has a "brain," falling back to local models if cloud services are unavailable.
  2. The Deterministic Engine (Logic/Safety): Intercepts LLM proposals and formally verifies them against your security rules (the "Bouncer" pattern) before execution.
flowchart LR
    subgraph Probabilistic["Probabilistic Engine (LLM)"]
        LLM[LLM Call]
    end

    subgraph Deterministic["Deterministic Engine (Skills)"]
        Policy[Policy Skill<br/>Constitutional invariants]
        Bouncer[Bouncer Skill<br/>Security vectors]
        Validator[Lisp Validator<br/>Structural verification]
    end

    subgraph Actuation["Actuation"]
        Shell[Shell Actuator]
        TUI[TUI Client]
        Emacs[Emacs Gateway]
    end

    LLM -->|Proposes action| Deterministic
    Policy -->|Checks| Bouncer
    Bouncer -->|Verifies| Validator
    Validator -->|Approves| Actuation
    Actuation -->|Feeds back| LLM

Architecture: Thin Harness, Fat Skills

To guarantee long-term stability, openCortex enforces a strict architectural boundary inspired by the "thin harness, fat skills" philosophy.

The Minimalist Harness

The Lisp microkernel is a thin, unbreakable harness strictly responsible for:

Layer Responsibility Examples
Perceive Normalize sensory input CLI parsing, Emacs events, heartbeats
Reason Bridge neural and deterministic LLM dispatch, response parsing, skill routing
Act Execute approved actions Shell commands, tool calls, UI output
Memory Live object store Org-object graph, snapshots, rollback

What the harness does not contain:

  • Policy rules (those are skills)
  • LLM integrations (those are skills)
  • Domain-specific functionality (those are skills)

Literate, Single-File Skills

In openCortex, a Skill is simply a single .org file containing everything:

  • The documentation (prose explaining the skill's purpose)
  • The AI instructions (how the LLM should use this skill)
  • The deterministic code (Lisp that verifies/proposes actions)

When the system boots, it compiles these skills directly into the live Lisp image. Skills are hot-reloadable without restarting the daemon.

flowchart TD
    subgraph Skill["Skill: policy.org"]
        Docs["Documentation<br/>'This skill enforces...'"]
        AI["AI Instructions<br/>'When the user asks about...'"]
        Code["Deterministic Code<br/>'(defun policy-check-...)'"]
    end

    subgraph Harness["Harness Core"]
        Package["package.lisp"]
        Loop["loop.lisp"]
        Perceive["perceive.lisp"]
        Reason["reason.lisp"]
        Act["act.lisp"]
    end

    Code --> |Compiles into| Harness
    Harness --> |Runs| Pipeline
    Pipeline --> |Feeds| Skill

The Metabolic Pipeline

Every signal in openCortex moves through the same three-stage pipeline:

  1. Perceive: Normalize raw input into a standardized Signal
  2. Reason: Generate a proposal via LLM, verify via skills
  3. Act: Execute the approved action, generate feedback
sequenceDiagram
    participant User
    participant Gateway
    participant Perceive
    participant Reason
    participant Act
    participant User

    User->>Gateway: "Write a note about X"
    Gateway->>Perceive: Raw message
    Perceive->>Perceive: Normalize to Signal
    Perceive->>Reason: Signal
    Reason->>Reason: LLM generates proposal
    Reason->>Reason: Skills verify proposal
    Reason->>Act: Approved action
    Act->>Act: Execute action
    Act->>Reason: Feedback signal
    Reason->>Perceive: New signal
    Perceive->>Gateway: Response
    Gateway->>User: "Done"

The Skill Registry

Skills are discovered, sorted by dependency, and loaded at boot:

flowchart LR
    subgraph Discovery["Skill Discovery"]
        Scan["Scan skills/ directory"]
        Sort["Topological sort by DEPENDS_ON"]
    end

    subgraph Loading["Skill Loading"]
        Validate["Validate syntax"]
        Jail["Jail in package namespace"]
        Register["Register in catalog"]
    end

    Scan --> Sort --> Validate --> Jail --> Register

The Three Data Stores

openCortex maintains three distinct representations of your knowledge:

Store Format Location Purpose
Source of Truth Plaintext .org files `~/memex/` Human-readable, version-controlled
Active Brain RAM (Lisp hash tables) Memory Fast, live, queryable
Snapshots Binary .snap files `~/.opencortex/` Crash recovery, rollback

The Active Brain is built from the Source of Truth on boot and kept in sync via:

  • Buffer updates from Emacs (when you edit)
  • Heartbeat snapshots (periodic persistence)
  • Graceful shutdown saves

The Evolutionary Roadmap

The roadmap is designed working backwards from SOTA parity (V 1.0.0), guiding each version toward a fully autonomous, self-editing agent. Each version builds on the previous, with features designed to be implemented in pure Common Lisp + Org-mode.

Non-Negotiable Identity

  • Pure Common Lisp + Org-mode. No JSON. No YAML. No external databases.
  • Single-address-space memory (Lisp hash tables in RAM — the agent IS the memory).
  • "Thin harness, fat skills" — complexity lives at the edges, not the kernel.
  • One agent composed of many skills. Concurrency via bordeaux-threads (shared memory).
  • Plists everywhere — homoiconic communication between all components.

Version Roadmap

v0.1.0: The Autonomous Foundation — CURRENT RELEASE

The secure, auditable Lisp kernel. All core infrastructure in place.

Component Status Notes
Perceive-Reason-Act pipeline 3-stage metabolic loop
Skills engine with jailed loading defskill, topological sort, hot-reload
Policy skill (6 invariants) Transparency, Autonomy, Bloat, Modularity, Mentorship, Sustainability
Bouncer skill Command whitelist guard functions
Memory (org-object + Merkle) Hash tables, snapshots, rollback
Lisp validator skill Syntax validation before eval
Scribe + Gardener skills Heartbeat-driven distillation + audit
LLM gateway (OpenRouter + Ollama) Provider cascade
Shell actuator Safe command execution
Emacs bridge via Swank Point/buffer updates
FiveAM test suite Memory, boot, pipeline, act, communication
Credentials vault Encrypted storage

v0.2.0: Self-Improvement + Local LLMs — NEXT

Self-editing is the foundation of all future growth. Full org-mode manipulation makes the agent a true Emacs citizen.

Feature Description
org-skill-self-edit Hook into :syntax-error events. Deterministic: auto-balance parens. Probabilistic: LLM surgical fix with memory rollback on failure.
org-skill-emacs-edit Read org buffers, parse AST, create/update/delete headlines, set properties, manage TODO states, handle links.
Local vector search generate-embeddings via Ollama. Add :vector to org-object. Semantic search with cosine similarity.
Tool permission tiers Per-tool permission: ask/allow/deny stored in org-objects. Filter tools before LLM sees them.
Skill hot-reload Swap compiled skill files without breaking active sockets.

v0.3.0: Event Orchestration + Context Awareness

Unified control plane for deep project understanding before complex work.

Feature Description
org-skill-event-orchestrator Unified hooks + cron + routing. Three tiers: :REFLEX (no LLM), :COGNITION (light LLM), :REASONING (full LLM).
org-skill-context-manager Stack-based project scoping. push-context / pop-context. Path resolution relative to context.
Memory scope segmentation :scope property on org-objects: memex/session/project. Scope-aware retrieval.
Model-tier routing Complexity-based model selection: heartbeat → tiny, user → medium, reasoning → large.
Slash commands M-x style command palette in TUI. Commands defined in Org-mode.

v0.4.0: Long-Horizon Planning + Git Workflows

Structured tracking, failure handling, and course correction for multi-step engineering work.

Feature Description
org-skill-long-horizon Decompose tasks into Org-mode headline trees. Terminal states: :done / :blocked / :stuck. Parent summarises children. Branch pruning.
org-skill-git-steward Status, diff, commit, push, branch. Policy enforces commit-before-modify.
TDD runner FiveAM on file save. :test-failure events. Hook into self-fix for auto-repair.
Deep Emacs integration Full org-agenda awareness. Navigate, clock time, refile, archive.

v0.5.0: Creator + Architect + GTD

The agent bootstraps itself: creates skills autonomously, designs projects from PRDs, manages work.

Feature Description
org-skill-creator LLM drafts complete skill org-file from natural language. Mandatory: syntax validation → jail-load → test → register.
org-skill-architect Scan :STATUS: FROZEN PRDs. Generate Phase B PROTOCOL.
org-skill-gtd Full GTD cycle: capture, clarify, organize, reflect, engage. org-gtd v4.0 DAG (:TRIGGER:, :BLOCKER:).
Consensus loop Run multiple providers for critical decisions. Compare results, detect disagreements.
Web research Headless Chromium via Python bridge. Text extraction, screenshots, Gemini Web UI automation.

v1.0.0: SOTA Parity

Feature-complete agent competitive with commercial agents. All features reimplemented in pure Lisp.

Area Status Notes
Self-improvement v0.2.0 Self-edit + lisp-repair
Planning v0.4.0 Task tree DAGs with terminal states
Tool ecosystem 🟡 v0.4.0 10+ cognitive tools
Context window v0.3.0 Semantic search + scope segmentation
Safety v0.1.0 6 Policy invariants + formal verification
Multi-step tasks v0.4.0 Task trees with failure handling
Code editing v0.2.0 Full org-mode file read/write
Memory v0.2.0 Vector recall in org-object
Emacs integration v0.2.0 Full org-mode control
Autonomy v0.1.0 100% local capable (Ollama)

v2.0.0: Lisp Machine Emergence

From Lisp-using agent to true Lisp machine. Agent IS the Emacs process.

Feature Description
Lish: Lisp editor Org-mode as IDE. Org-babel for interactive evaluation. Full REPL in TUI. No bridge needed.
Lish: Shell replacement Lisp-based shell that speaks plists. Org-mode buffers as file system.

v3.0.0: Neurosymbolic Maturity

Deterministic planner takes the wheel. LLM relegated to semantic translation.

Feature Description
Deterministic planner Pure Lisp task scheduler. No LLM needed for planning.
Self-correcting gates Gates learn from false positives (user override patterns).

v4.0.0: AI Stack Internalized

The agent understands its own weights. No external inference.

Feature Description
Llama.cpp in Lisp FFI binding. No Python subprocess. Pure Common Lisp inference.
Weights as sexps Neural weights as Lisp data structures. Homoiconic model introspection.

v5.0.0: True Agency

World models, temporal reasoning, goal persistence across restarts.

Feature Description
World models Predictive models of user behavior, project dynamics, system state.
Temporal reasoning Scheduling, deadlines, elapsed duration awareness.
Goal persistence Goals survive restarts. Long-term projects in org-objects.

Design Principles

1. Radical Transparency

If you can't explain it, you can't do it. Every action must be auditable. Hidden reasoning is forbidden.

2. Autonomy First

Dependency on proprietary systems is debt. Prefer local, offline-capable solutions.

3. Zero Bloat

Complexity must be earned, not anticipated. The harness must remain minimal.

4. Modularity

The kernel must survive even if all skills fail. Complexity belongs at the edges.

5. Mentorship

Teaching is the highest form of assistance. Every action should increase capability.

6. Sustainability

Build for the 100-year horizon. Design for offline operation, local inference.

Contributing

See CONTRIBUTING.org for the Literate Granularity standard and skill creation guidelines.

License

openCortex is released under the AGPLv3 license.

See CLA.org for the Contributor License Agreement.

Description
No description provided
Readme AGPL-3.0 62 MiB
Languages
Shell 67.5%
Emacs Lisp 19.1%
Common Lisp 9.6%
C 2.2%
Dockerfile 1.6%