Skip to content

LeoYeAI/agent-master-skills / skills/agent-memory-system-guide

Agent Memory System Guide

Verified

An agent memory workflow guide for OpenClaw and Codex with MEMORY.md, daily notes, SESSION-STATE, working-buffer, Obsidian archiving, and optional OpenViking support.

FileKindSize
INSTALL.mdmarkdown1.1 KB
README.mdmarkdown12.4 KB
README_CN.mdmarkdown11.6 KB
README_EN.mdmarkdown12.3 KB
SKILL.mdskill md18.8 KB
_meta.jsonconfig833 B
docs/superpowers/plans/2026-03-21-agent-memory-system-guide-obsidian-native.mdmarkdown5.3 KB
docs/superpowers/plans/2026-03-25-memory-backup-import-export.mdmarkdown3.9 KB
docs/superpowers/plans/2026-03-25-memory-examples-maintenance.mdmarkdown3.2 KB
docs/superpowers/plans/2026-03-25-report-warning-example.mdmarkdown1.9 KB
docs/superpowers/plans/2026-03-26-import-clean-mode.mdmarkdown8.6 KB
docs/superpowers/plans/2026-03-26-metadata-bootstrap-safety.mdmarkdown5.4 KB
docs/superpowers/plans/2026-03-27-memory-positioning.mdmarkdown2.6 KB
docs/superpowers/plans/2026-03-27-report-json.mdmarkdown5.5 KB
docs/superpowers/specs/2026-03-21-agent-memory-system-guide-obsidian-design.mdmarkdown5.1 KB
docs/superpowers/specs/2026-03-25-memory-backup-import-export-design.mdmarkdown3.1 KB
docs/superpowers/specs/2026-03-25-memory-examples-maintenance-design.mdmarkdown2.8 KB
docs/superpowers/specs/2026-03-26-import-clean-mode-design.mdmarkdown5.6 KB
docs/superpowers/specs/2026-03-26-metadata-bootstrap-safety-design.mdmarkdown5.0 KB
docs/superpowers/specs/2026-03-27-memory-positioning-design.mdmarkdown4.4 KB
docs/superpowers/specs/2026-03-27-report-json-design.mdmarkdown4.0 KB
manifest.tomlconfig944 B
scripts/memory_capture.pyscript17.3 KB
templates/OBSIDIAN-NOTE.mdmarkdown530 B
templates/SESSION-STATE.mdmarkdown137 B
templates/memory-capture.mdmarkdown385 B
templates/working-buffer.mdmarkdown105 B
tests/test_gitignore_publish_artifacts.pyscript514 B
tests/test_install_contract.pyscript384 B
tests/test_memory_capture_contract.pyscript6.9 KB
tests/test_memory_capture_script.pyscript16.8 KB
tests/test_memory_recovery_contract.pyscript1.5 KB
tests/test_obsidian_contract.pyscript503 B
tests/test_obsidian_template_contract.pyscript183 B
tests/test_openclaw_memory_search_contract.pyscript366 B
tests/test_openviking_optional_contract.pyscript371 B
tests/test_readme_openviking_optional.pyscript383 B
tests/test_release_manifest_contract.pyscript1.3 KB
tests/test_skill_positioning_contract.pyscript849 B

docs/superpowers/plans/2026-03-26-import-clean-mode.md

View on GitHub
# Import Clean Mode Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Add an explicit `import --clean` mode that performs a deterministic clean restore of the supported memory surface while preserving the current default import behavior.

**Architecture:** Keep the current import path as the default overwrite-style restore. Extend the import CLI with `--clean`, back it with a helper that removes only supported files and directories after backup creation, and update docs to distinguish conservative import from clean restore.

**Tech Stack:** Python 3, argparse, pathlib, zipfile, pytest, Markdown docs

---

### Task 1: Lock the two import semantics with failing tests

**Files:**
- Modify: `tests/test_memory_capture_script.py`
- Test: `tests/test_memory_capture_script.py`

- [ ] **Step 1: Write the failing tests**

```python
def test_import_preserves_extra_supported_files_by_default(tmp_path: Path):
    source_workspace = tmp_path / 'source'
    source_memory_dir = source_workspace / 'memory'
    source_memory_dir.mkdir(parents=True)
    (source_workspace / 'MEMORY.md').write_text('# MEMORY\n\nrestored\n', encoding='utf-8')
    (source_memory_dir / '2026-03-25.md').write_text('# daily restored\n', encoding='utf-8')
    archive_path = tmp_path / 'memory-backup.zip'

    export_result = run_command(
        'export',
        '--workspace',
        str(source_workspace),
        '--output',
        str(archive_path),
        '--generated-at',
        '2026-03-26T10:00:00+08:00',
    )
    assert export_result.returncode == 0

    target_workspace = tmp_path / 'target'
    target_memory_dir = target_workspace / 'memory'
    target_memory_dir.mkdir(parents=True)
    (target_workspace / 'MEMORY.md').write_text('# MEMORY\n\nexisting\n', encoding='utf-8')
    extra_note = target_memory_dir / '2026-03-20.md'
    extra_note.write_text('# extra daily note\n', encoding='utf-8')

    result = run_command(
        'import',
        '--workspace',
        str(target_workspace),
        '--input',
        str(archive_path),
        '--generated-at',
        '2026-03-26T10:05:00+08:00',
    )

    assert result.returncode == 0
    assert extra_note.exists()
    assert 'Import mode: conservative' in result.stdout


def test_import_clean_removes_extra_supported_files_before_restore(tmp_path: Path):
    source_workspace = tmp_path / 'source'
    source_memory_dir = source_workspace / 'memory'
    source_memory_dir.mkdir(parents=True)
    (source_workspace / 'MEMORY.md').write_text('# MEMORY\n\nrestored\n', encoding='utf-8')
    (source_memory_dir / '2026-03-25.md').write_text('# daily restored\n', encoding='utf-8')
    archive_path = tmp_path / 'memory-backup.zip'

    export_result = run_command(
        'export',
        '--workspace',
        str(source_workspace),
        '--output',
        str(archive_path),
        '--generated-at',
        '2026-03-26T10:10:00+08:00',
    )
    assert export_result.returncode == 0

    target_workspace = tmp_path / 'target'
    target_memory_dir = target_workspace / 'memory'
    attachments_dir = target_workspace / 'attachments'
    target_memory_dir.mkdir(parents=True)
    attachments_dir.mkdir()
    (target_workspace / 'MEMORY.md').write_text('# MEMORY\n\nexisting\n', encoding='utf-8')
    extra_note = target_memory_dir / '2026-03-20.md'
    extra_note.write_text('# extra daily note\n', encoding='utf-8')
    extra_attachment = attachments_dir / 'old.txt'
    extra_attachment.write_text('old\n', encoding='utf-8')

    result = run_command(
        'import',
        '--workspace',
        str(target_workspace),
        '--input',
        str(archive_path),
        '--generated-at',
        '2026-03-26T10:15:00+08:00',
        '--clean',
    )

    assert result.returncode == 0
    assert not extra_note.exists()
    assert not extra_attachment.exists()
    assert (target_workspace / 'memory' / '2026-03-25.md').exists()
    assert 'Import mode: clean' in result.stdout

    backups = sorted(target_workspace.glob('memory-import-backup-*.zip'))
    assert backups
    with zipfile.ZipFile(backups[0]) as archive:
        assert archive.read('memory/2026-03-20.md').decode('utf-8') == '# extra daily note\n'
        assert archive.read('attachments/old.txt').decode('utf-8') == 'old\n'
```

- [ ] **Step 2: Run tests to verify they fail**

Run: `pytest tests/test_memory_capture_script.py -k "preserves_extra_supported_files_by_default or clean_removes_extra_supported_files_before_restore" -q`
Expected: FAIL because the CLI does not accept `--clean`, does not emit mode lines, and current behavior does not explicitly guarantee the new semantics.

- [ ] **Step 3: Write minimal implementation**

Add the `--clean` flag and deletion helper in `scripts/memory_capture.py`:

```python
import shutil
```

```python
import_parser.add_argument(
    "--clean",
    action="store_true",
    help="Remove supported memory files and directories before restoring the archive.",
)
```

```python
def clear_supported_workspace_state(workspace: Path) -> None:
    for name in SUPPORTED_FILES:
        candidate = workspace / name
        if candidate.exists():
            candidate.unlink()
    for directory_name in SUPPORTED_DIRECTORIES:
        directory = workspace / directory_name
        if directory.exists():
            shutil.rmtree(directory)
```

```python
with zipfile.ZipFile(archive_path) as archive:
    members = safe_members_from_manifest(archive)
    backup_path = backup_existing_workspace_state(workspace, generated_at)
    if args.clean:
        clear_supported_workspace_state(workspace)
    restore_archive(archive, workspace, members)

print(f"Import mode: {'clean' if args.clean else 'conservative'}")
```

Keep equivalent final code if helper names differ, but preserve the same behavior and scope.

- [ ] **Step 4: Run tests to verify they pass**

Run: `pytest tests/test_memory_capture_script.py -k "preserves_extra_supported_files_by_default or clean_removes_extra_supported_files_before_restore" -q`
Expected: PASS

- [ ] **Step 5: Commit**

```bash
git add tests/test_memory_capture_script.py scripts/memory_capture.py
git commit -m "feat: add clean import mode"
```

### Task 2: Update user-facing import semantics in docs

**Files:**
- Modify: `README.md`
- Modify: `README_CN.md`
- Modify: `README_EN.md`
- Modify: `SKILL.md`

- [ ] **Step 1: Write the failing contract test**

Add assertions to an existing contract test in `tests/test_memory_capture_contract.py`:

```python
assert '--clean' in readme_text
assert 'conservative' in readme_en_text
assert 'overwrite-style restore' in readme_en_text
assert '保守' in readme_cn_text
assert '--clean' in skill_text
assert 'clean restore' in skill_text
```

- [ ] **Step 2: Run test to verify it fails**

Run: `pytest tests/test_memory_capture_contract.py -q`
Expected: FAIL because the docs do not yet mention `--clean` or the distinction between conservative import and clean restore.

- [ ] **Step 3: Write minimal documentation updates**

Update the import sections in:

- `README.md`
- `README_CN.md`
- `README_EN.md`
- `SKILL.md`

Required wording to introduce:

- Default import is conservative and overwrite-style.
- `--clean` removes supported memory files/directories before restore.
- Pre-import backup still runs in both modes.

- [ ] **Step 4: Run test to verify it passes**

Run: `pytest tests/test_memory_capture_contract.py -q`
Expected: PASS

- [ ] **Step 5: Commit**

```bash
git add README.md README_CN.md README_EN.md SKILL.md tests/test_memory_capture_contract.py
git commit -m "docs: clarify import restore modes"
```

### Task 3: Run regression verification

**Files:**
- Modify: none
- Test: `tests/test_memory_capture_script.py`
- Test: `tests/test_memory_capture_contract.py`
- Test: full `tests/`

- [ ] **Step 1: Run focused regression tests**

Run: `pytest tests/test_memory_capture_script.py tests/test_memory_capture_contract.py -q`
Expected: PASS

- [ ] **Step 2: Run full test suite**

Run: `pytest -q`
Expected: PASS with all repository contract tests green.

- [ ] **Step 3: Inspect scoped diff**

Run: `git diff -- scripts/memory_capture.py tests/test_memory_capture_script.py tests/test_memory_capture_contract.py README.md README_CN.md README_EN.md SKILL.md`
Expected: Only import-clean implementation, tests, and doc wording changes appear.

- [ ] **Step 4: Commit**

```bash
git add scripts/memory_capture.py tests/test_memory_capture_script.py tests/test_memory_capture_contract.py README.md README_CN.md README_EN.md SKILL.md
git commit -m "feat: document deterministic clean restore"
```
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall