Skip to content
memory-enhancement logo

Memory Enhancement

memory-enhancement

Manage memory citations, verify code references, and track confidence scores. Use when adding citations to memories, checking memory health, or verifying code references are still valid.

SKILL.md

Full skill instructions

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

  • "add citation to memory" - Link memory to specific code location
  • "verify memory citations" - Check if code references are still valid
  • "check memory health" - Generate staleness report across all memories
  • "update memory confidence" - Recalculate trust score based on verification

Quick Reference

InputOutputDuration
Memory ID + code referenceCitation added with validation< 5 seconds
Memory directoryHealth report with stale memories< 30 seconds
Verification resultsUpdated confidence scores< 10 seconds

Decision Tree

Need memory enhancement?
│
├─ Add citation to memory → add-citation command
├─ Verify citations → verify or verify-all command
├─ Check memory health → health command
├─ Traverse memory graph → graph command
└─ Update confidence → update-confidence command

Process

Phase 1: Identify Target Memory

Locate memory file by ID or path:

  1. Check default directory - Look in .serena/​memories/ for <memory-id>.md
  2. Try direct path - If full path provided, use it directly
  3. Validate existence - Error if memory file not found (exit code 2)

Verification: Memory file exists and is readable

Phase 2: Add/​Verify Citations

Use CLI commands with structured output:

Add Citation
python -m memory_enhancement add-citation <memory-id> --file <path> --line <num> --snippet <text>

Parameters:

  • memory-id - Memory identifier or file path
  • --file - Relative file path from repository root (required)
  • --line - Line number (1-indexed, optional for file-level citations)
  • --snippet - Code snippet for fuzzy matching (optional)
  • --dry-run - Preview changes without writing (optional)

Exit Codes (ADR-035):

  • 0: Success
  • 1: Validation failed (stale citation)
  • 2: Invalid arguments or file not found
  • 3: File I/​O error
Verify Citations
# Single memory
python -m memory_enhancement verify <memory-id> [--json]

# All memories
python -m memory_enhancement verify-all [--dir .serena/​memories] [--json]

Output Indicators:

  • ✅ VALID - All citations point to valid locations
  • ❌ STALE - Some citations are invalid
  • Confidence score (0.0-1.0)
  • Detailed mismatch reasons

Verification: Citations validated against current codebase state

Phase 3: Update Confidence

Recalculate based on verification results:

python -m memory_enhancement update-confidence <memory-id>

Confidence Calculation:

confidence = valid_citations / total_citations

Interpretation:

Score RangeMeaningAction
0.9 - 1.0High confidenceTrust memory, use in decisions
0.7 - 0.9Medium confidenceReview stale citations
0.5 - 0.7Low confidenceUpdate memory or mark obsolete
0.0 - 0.5Very low confidenceMemory likely outdated
No citationsDefault (0.5)Add citations to improve confidence

Verification: Confidence score updated in YAML frontmatter

Phase 4: Report Results

Display summary with actionable recommendations:

List Citations
python -m memory_enhancement list-citations <memory-id> [--json]

Human-readable output:

Citations for memory-001:
Total: 3

✅ src/​api.py:42
   Snippet: handleError

❌ src/​client.ts:100
   Reason: Line 100 exceeds file length (95 lines)

✅ scripts/​test.py

JSON output for programmatic usage:

{
  "citations": [
    {
      "path": "src/​api.py",
      "line": 42,
      "snippet": "handleError",
      "valid": true,
      "mismatch_reason": null,
      "verified": "2026-01-24T14:30:00"
    }
  ]
}
Health Report
python -m memory_enhancement health [--format markdown|json] [--include-graph]

Generates comprehensive report with:

  • Total memories with citations
  • Stale memory count and percentage
  • Memories ranked by staleness (worst first)
  • Optional: Orphaned memories (disconnected from graph)

Verification: Report generated successfully

Script Reference

OperationCLI CommandKey Parameters
Add citationpython -m memory_enhancement add-citation<memory-id>, --file, --line, --snippet
Verify memorypython -m memory_enhancement verify<memory-id>, --json
Verify allpython -m memory_enhancement verify-all--dir, --json
Health reportpython -m memory_enhancement health--format (markdown/​json)
Update confidencepython -m memory_enhancement update-confidence<memory-id>
List citationspython -m memory_enhancement list-citations<memory-id>, --json
Graph traversalpython -m memory_enhancement graph<root-id>, --strategy, --max-depth

Anti-Patterns

AvoidWhyInstead
Adding citations without verifying file existsAdds invalid citations immediatelyLet CLI validate on add
Skipping confidence updates after verificationConfidence becomes staleRun update-confidence after big code changes
Using absolute pathsBreaks on different machinesUse repo-relative paths
Adding duplicate citationsClutters frontmatterCLI automatically updates existing citations
Forgetting to verify after refactoringCitations go stale silentlyRun verify-all regularly or in CI

Integration with Existing Skills

  • reflect - Auto-capture citations from learnings that reference code
  • memory - Verify citations during memory search
  • curating-memories - Update citations when memories change
  • qa - Run verification as part of test strategy

CI Integration (Optional)

Create .github/​workflows/​memory-validation.yml:

name: Memory Citation Validation

on:
  pull_request:
    paths:
      - '.serena/​memories/​**'
      - 'src/​**'
      - 'scripts/​**'

jobs:
  verify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/​checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
      - uses: actions/​setup-python@40c6b50cc6aa807e2d020b243100c016221d604c # v5.3.0
        with:
          python-version: '3.12'
      - run: pip install -e .
      - run: python -m memory_enhancement verify-all --json > results.json
        continue-on-error: true
      - run: cat results.json
      - name: Comment on PR
        if: failure()
        uses: actions/​github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
        with:
          script: |
            const results = require('./​results.json');
            const stale = results.filter(r => !r.valid);
            if (stale.length > 0) {
              await github.rest.issues.createComment({
                issue_number: context.issue.number,
                owner: context.repo.owner,
                repo: context.repo.name,
                body: `⚠️ ${stale.length} stale memory citation(s) detected. Run \`python -m memory_enhancement verify-all\` locally for details.`
              });
            }

Initially set continue-on-error: true (warning only). After adoption, make blocking.

Verification

After using this skill:

  • Citations validated against current codebase
  • Confidence scores updated in memory frontmatter
  • Stale memories identified and reported
  • Health report generated (if requested)
  • Exit codes follow ADR-035 standard

References

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View