Memory enhancement

From rjmurillo/ai-agents · View interactive version

Memory enhancement is an AI agent skill from the GitHub repository rjmurillo/ai-agents. Manage memory citations, verify code references, and track confidence scores. Use when adding citations to memories, checking citation health, or verifying code references are still valid. Use when you say "add a citation", "verify this memory's code refs", "check citation health". Do NOT use for se

How to use this skill

Skill file

Memory Enhancement

Manage citations, verify code references, and track confidence scores for Serena memories. Ensures memories stay accurate by linking them to specific code locations and detecting when those locations change.

Triggers

Quick Reference

| Input | Output | Duration |

|-------|--------|----------|

| Memory ID + code reference | Citation added with validation | < 5 seconds |

| Memory directory | Health report with stale memories | < 30 seconds |

| Verification results | Updated confidence scores | < 10 seconds |

Decision Tree

Need memory enhancement?
│
├─ Add citation to memory → edit the memory file (no CLI command)
├─ Verify citations → verify or verify-all command
├─ Check memory health → health command
├─ Traverse memory graph → graph command
└─ Show confidence scores → confidence command

Command Surface

Set --memories-dir to the repository's Markdown corpus when using a

directory other than the default. Verify remotely stored claims against

their original sources.

Global options come before the subcommand. Placing --repo-root or

--memories-dir after the subcommand exits 2.

python -m memory_enhancement [--repo-root PATH] [--memories-dir PATH] <command>

| Command | Options | Exit codes |

|---------|---------|------------|

| verify | --memory-id ID | 1 if any citation is invalid, or the id is unknown |

| verify-all | --json | 1 if any citation is invalid |

| health | --json, --text, --markdown (default) | 1 if any citation is broken or stale, or any memory is stale |

| graph | --start ID (required), --depth N | 1 if the start id is unknown |

| confidence | none | 0 |

| search | QUERY (positional), --top N, --json | 0 |

--memories-dir must resolve inside --repo-root; otherwise the CLI exits 1.

A memory id is its path under the memories directory without the .md

suffix, so .serena/memories/testing/foo.md has the id testing/foo.

Process

Phase 1: Identify Target Memory

Locate the memory file by id:

  1. Derive the id - The id is the path under the memories directory without

the .md suffix (.serena/memories/testing/foo.md has id testing/foo).

  1. Point at a different tree - Pass --memories-dir PATH before the

subcommand. It must resolve inside --repo-root.

  1. Validate existence - verify --memory-id <id> prints

Memory not found: <id> and exits 1 when the id is unknown.

Verification: Memory file exists and is readable

Phase 2: Add/Verify Citations

Add Citation

There is no add-citation command. Citations are markdown, so add one by

editing the memory file and appending a citation line to its body:

[cite:file](src/api.py) - the error handler lives here

Syntax: [cite:<source-type>](<target>) - <context>

The parser skips fenced code blocks and inline code spans. Show the syntax

in code to document it. A citation that must count goes in plain text.

An unrecognized source-type warns on stderr and the citation is dropped, so

the memory can still exit 0 with the citation missing. Verify after editing.

A citations: block in YAML frontmatter is not read by this tool.

Verification: verify --memory-id <id> lists the new citation

Verify Citations
# Single memory
python -m memory_enhancement verify --memory-id <memory-id>

# All memories, human-readable
python -m memory_enhancement verify-all

# All memories, JSON for CI
python -m memory_enhancement verify-all --json

Output Indicators:

Verification: Citations validated against current codebase state

Phase 3: Show Confidence

Recalculate scores from current verification results:

python -m memory_enhancement confidence

Prints <memory-id>: <score> for every memory. The command computes scores on

each run and does not write them back to the memory files, and it has no

single-memory filter.

Confidence Calculation:

A weighted blend of four factors, clamped to 0.0-1.0:

| Factor | Weight | Definition |

|--------|--------|------------|

| Citation validity | 0.50 | valid citations / total citations; 1.0 when there are none |

| Update recency | 0.25 | decays linearly to 0 over 90 days since updated_at |

| Link count | 0.15 | outgoing links / 10, capped at 1.0 |

| Memory freshness | 0.10 | decays linearly to 0 over 365 days since created_at |

A memory with no citations therefore does not score low; it scores high on

validity and is limited only by age and link count. Read a high score as

"nothing is known to be broken", not "this was checked against code".

Interpretation:

| Score Range | Meaning | Action |

|-------------|---------|--------|

| 0.9 - 1.0 | High confidence | Trust memory, use in decisions |

| 0.7 - 0.9 | Medium confidence | Review stale citations |

| 0.5 - 0.7 | Low confidence | Update memory or mark obsolete |

| 0.0 - 0.5 | Very low confidence | Memory likely outdated |

Verification: confidence prints a score for every memory

Phase 4: Report Results

Display summary with actionable recommendations:

List Citations

There is no list-citations command. Verifying a memory prints its citations

alongside their status:

python -m memory_enhancement verify --memory-id <memory-id>

Human-readable output:

testing/demo:
  [PASS] src/api.py - File exists
  [FAIL] src/missing.py - File not found: src/missing.py

For machine-readable output across every memory, use verify-all --json. It

emits a flat array, one object per citation:

[
  {
    "memory_id": "testing/demo",
    "target": "src/api.py",
    "source_type": "file",
    "valid": true,
    "reason": "File exists"
  }
]
Health Report
python -m memory_enhancement health --json

Reports the following, and nothing else:

There is no orphan detection and no staleness ranking.

Verification: Report generated successfully

Script Reference

| Operation | CLI Command | Key Parameters |

|-----------|-------------|----------------|

| Add citation | none; edit the memory body | [cite:<type>](<target>) - <context> |

| Verify memory | python -m memory_enhancement verify | --memory-id |

| Verify all | python -m memory_enhancement verify-all | --json |

| Health report | python -m memory_enhancement health | --json, --text, --markdown |

| Show confidence | python -m memory_enhancement confidence | none |

| List citations | python -m memory_enhancement verify | --memory-id |

| Graph traversal | python -m memory_enhancement graph | --start, --depth |

| Search memories | python -m memory_enhancement search | QUERY, --top, --json |

Prefix any of these with --repo-root PATH or --memories-dir PATH to point

at a different tree. Both are global options and must precede the subcommand.

Anti-Patterns

| Avoid | Why | Instead |

|-------|-----|---------|

| Placing --repo-root after the subcommand | argparse rejects it and exits 2 | Put global options first |

| Adding a citation without checking the target | Nothing validates on write; it is a text edit | Run verify --memory-id <id> right after editing |

| Putting citations in YAML frontmatter | The parser only reads [cite:...] in the body | Add the citation line to the memory body |

| Reading a high confidence score as verified | Memories with no citations score high on validity | Check total_citations before trusting a score |

| Using absolute paths | Breaks on different machines | Use repo-relative paths |

| Forgetting to verify after refactoring | Citations go stale silently | Run verify-all regularly or in CI |

Integration with Existing Skills

Phase 5: Health Reporting

Run batch health checks:

# Full report (human-readable markdown, the default)
python -m memory_enhancement --repo-root . --memories-dir .serena/memories health

# JSON output (for CI parsing)
python -m memory_enhancement health --json

# Markdown output (for PR comments)
python -m memory_enhancement health --markdown

# Plain text output
python -m memory_enhancement health --text

The three format flags are mutually exclusive. There is no exemption

mechanism: exempt: true in frontmatter has no effect, and every memory in

the directory is scanned.

Exit Codes:

CI Integration

Memory Health Workflow

The .github/workflows/memory-health.yml workflow runs health checks on all PRs:

Citation Verification Workflow

The .github/workflows/citation-verify.yml workflow verifies citations:

pull requests that touch neither path

Verification

After using this skill:

References

<!-- vendor-portability: declared. This skill cites .project-toolkit/architecture/ADR-007 and ADR-038 as the memory-first and reflexion-schema ADRs, and names .github/workflows/memory-health.yml and .github/workflows/citation-verify.yml as the CI that runs these commands. All four sit outside the plugin root and are absent from a vendored install. Every one is a documentation citation; the enhancement logic reads none of them, the CLI behaves identically without them, and a vendored install loses only the citations and the description of this repository's CI wiring. -->

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.