- NEW: REPL-first workflow requirement - NEW: Must use utils-lisp functions for any .lisp work - NEW: Never use edit tool on .lisp files directly - NEW: Post-task verification: REPL verified + utils-lisp used
7.1 KiB
OpenCortex Agent Mandate
This file defines the operating policies and engineering guidelines that all autonomous agents MUST follow.
Vision
- Pure Lisp + Org-mode: All intelligence implemented in Lisp, all documentation in Org-mode
- No JSON, No YAML: Thin harness, fat skills
- Constraint: No temporary scripts in opencortex repo - use
/home/user/memex/system/instead
Current Goal
- v0.2.0: Self-Improvement + Local LLMs
- org-skill-self-edit (self-modification)
- org-skill-emacs-edit (full org-mode manipulation)
- Local vector search (Ollama embeddings)
- Tool permission tiers (ask/allow/deny)
- Skill hot-reload ✅ DONE
- Engineering Standards skill ✅ DONE
- Literate Programming skill ✅ DONE
Wake-Up Protocol
When this agent starts, it MUST:
- Read this file (
~/.opencode/AGENTS.md) - Query the skill catalog: Before any analysis, check if a skill covers the problem domain
(list-skills)to see all loaded skills(find-skill :keyword)to check for a specific domain- Read the skill's org file if found
- Verify git status: Working tree MUST be clean before modification
- Read
gtd.org: Load current task context from the roadmap - Enter lifecycle: Follow the Engineering Standards lifecycle (Phase 0 → A → B → C → D → E)
Rationale: Raw LLM reasoning is a fallback, not a starting point. The skill layer encodes the system's accumulated wisdom. Ignoring skills creates drift.
Engineering Standards
The Engineering Standards skill (opencortex.skills.org-skill-engineering-standards) defines the full lifecycle. The summaries below are reminders; the skill org file is authoritative.
Phase 0: Before You Think
Skill-First Query Rule: Before analysis, debugging, or implementation, query the skill catalog. If a relevant skill exists, follow its mandates. Do not duplicate logic.
Phase A: Design (Test-First)
- Define success criteria first — Write the test or PROTOCOL that proves the feature works
- Break the design with chaos — Three tiers of adversarial testing:
- Deterministic chaos: Scripted regression tests on every change
- Probabilistic chaos: Randomized fuzzing on every major release
- Stress chaos: Load and resource starvation during hardening sprints
Phase B: Commit (Recovery Point)
- Commit Before Modify — Commit and push (if network available) before any file changes
Phase C: Build (Implementation)
- Literate Programming — All logic in Org files; generated
.lispis derived, not authored - Function-Block Granularity — One function per
#+begin_src lispblock - Tangle Mandate — Edit Org only; never touch generated
.lisp - Configuration Externalization — No hardcoded values; use
.env.example - Org as Thinking Medium — Document investigation before fixing
Phase D: Validate (Proof)
- Test Verification — Run the full suite. A change that breaks tests is damage, not a fix.
Phase E: Document (Audit Trail)
- Decision Audit Trail — Document root cause, options, tradeoffs, and rationale
- Stop-and-Wait — For major changes, propose strategy, state "Waiting for user feedback," yield turn
- GTD Synchronization — Update
gtd.orgwith TODO headlines before marking complete
Literate Programming Rules
The Literate Programming skill (opencortex.skills.org-skill-literate-programming) enforces Org discipline:
- One Function, One Block — No bundling multiple definitions
- Org-Mode Evaluation Gate —
C-c C-cafter every block change - Pre-Tangle Structural Check — Verify paren balance before tangling
- No Direct
.lispEdits — All changes flow through Org - Code and Prose Together — Every block preceded by explanatory text
Violating these rules corrupts the skill loader and causes boot failure (as seen in the 2026-04-25 incident).
Agent Workflow
- Boot Sequence: Read AGENTS.md → query skills → verify git → read gtd.org
- Before Any Modification: Commit first (Commit Before Modify rule)
- Plan Mode: Draft PROTOCOL.md before complex implementations
- Testing: Run FiveAM test suite + chaos tests before marking task complete
- Completion: Update gtd.org, commit, sync with user
Self-Enforcement Checklist
This agent MUST verify these conditions before, during, and after each task. Violation is a bug, not a suggestion.
Before Any Task (Gate)
- Git clean — Working tree must be clean before modification
- Skill query — Check if relevant skill exists in
/home/user/memex/projects/opencortex/skills/ - Skill read — If found, read the skill's org file before proceeding
- GTD read — Check
gtd.orgfor current task context
During Task (Literate Programming)
- REPL-first workflow — Explore in REPL before writing code
- Utils-lisp for structural ops — Use these functions for any .lisp work:
utils-lisp-structural-extract— Extract function definitionsutils-lisp-structural-inject— Inject forms into definitionsutils-lisp-structural-wrap— Wrap code in let/prognutils-lisp-validate— Validate code before commitrepl-eval— Test code in REPLrepl-inspect— Inspect variables/functions
- Never use edit tool on .lisp — Only edit .org files; never touch generated .lisp directly
- One function per block — Each
#+begin_srcblock contains exactly one definition - Prose before code — Every block preceded by explanatory text
- Prose includes: What the function does, arguments, return value, rationale
- Evaluate each block — Verify the block compiles/evaluates correctly
- Paren balance — Check balanced parentheses before tangling
After Task (Validation)
- REPL verified — Code tested in REPL before commit (not just text edit)
- Utils-lisp used — Confirmed structural operations went through utils-lisp
- Tests pass — Run full test suite; 100% pass required
- Chaos tier 1 — Deterministic regression tests pass
- No artifacts — No orphaned
.bak,.log,.tmp, or untracked test files - Commit — Stage and commit changes with descriptive message
- GTD update — Update
gtd.orgwith completed task state
For OpenCortex Work Specifically
Reference authoritative skill files:
- Engineering Standards:
projects/opencortex/skills/org-skill-engineering-standards.org - Literate Programming:
projects/opencortex/skills/org-skill-literate-programming.org - Policy:
projects/opencortex/skills/org-skill-policy.org
The summaries in this file are reminders; the skill org files are authoritative.
References
- opencortex repo:
/home/user/memex/projects/opencortex - Engineering Standards:
/home/user/memex/projects/opencortex/skills/org-skill-engineering-standards.org - Literate Programming:
/home/user/memex/projects/opencortex/skills/org-skill-literate-programming.org - Policy Skill:
/home/user/memex/projects/opencortex/skills/org-skill-policy.org - Roadmap:
/home/user/memex/gtd.org - README:
/home/user/memex/projects/opencortex/README.org