---
name: mma
description: >
  Archive old build log entries from _meta/log.md into compact summary pages
  in _meta/folds/. Prevents log.md from growing unbounded. Extractive only —
  no invented facts, additive only — never removes source entries until confirmed.
  Use when _meta/log.md exceeds 200 entries or feels unwieldy.
argument-hint: "[--dry-run] [--k <batch-exponent>]"
allowed-tools: "Read Write Edit Glob"
---

## Objective

Fold the oldest 2^k entries from _meta/log.md into a single summary page, reducing log.md size while preserving all information.

This command is operational only. Do not write `/mma`, `/memory-mason:mma`, or their execution chatter back into the vault.

## Auto-Trigger

Routine archival runs automatically when mmc appends a build log entry that brings `_meta/log.md` to 32 or more entries. mmc folds the oldest 16 entries (k=4) into `_meta/folds/` without requiring a manual `/mma` call.

Use `/mma` for:
- Manual runs outside the compile flow
- Custom batch sizes (`--k 5` folds 32 entries at once)
- Dry-run inspection before committing a fold (`--dry-run`)

## Path Resolution

Before any other reasoning, resolve vault config in this priority order:
1. Project `./.env`
2. Project `./memory-mason.json`
3. Global `~/.memory-mason/.env`
4. Global `~/.memory-mason/config.json`

Resolve:
- {vault}: absolute path to the Obsidian vault
- {subfolder}: plugin-managed subfolder inside the vault

Use the source that provides the vault path.

Subfolder rules:
- If the vault path comes from an `.env` file, use `MEMORY_MASON_SUBFOLDER` from that same file when present, otherwise default to `ai-knowledge`.
- If the vault path comes from `memory-mason.json` or `~/.memory-mason/config.json`, use its `subfolder`.

Do not claim config is missing until you have attempted all four locations above. If none provide a vault path, fail fast with an explicit error that names every location checked.

## Parameters

- `--dry-run`: Show what would be folded without writing anything. Default behavior.
- `--k <n>`: Batch exponent. Fold 2^n entries at once. Default: k=4 (16 entries).

Always dry-run first. Only write when user confirms or `--commit` is passed.

## Steps

1. Read {vault}/{subfolder}/_meta/log.md.
   - Count total entries (each starts with `## [`).
   - If under 32 entries, report "Nothing to fold yet (N entries, minimum 32)." and stop.

2. Determine fold range.
   - Take the oldest 2^k entries (default 16).
   - Record the earliest and latest timestamps from those entries.
   - Generate fold ID: `fold-k{k}-from-{EARLIEST-DATE}-to-{LATEST-DATE}-n{COUNT}`
     Example: `fold-k4-from-2026-04-01-to-2026-04-16-n16`

3. Generate fold summary.
   - Extractive: summarize what those entries recorded (compiles run, articles created/updated, queries answered).
   - Include exact wikilinks to articles mentioned.
   - Do NOT invent facts not present in the source entries.

4. Fold page format (_meta/folds/{fold-id}.md):

```markdown
---
title: "Fold: {EARLIEST-DATE} to {LATEST-DATE}"
fold_id: "{fold-id}"
entries_folded: {COUNT}
source: "_meta/log.md"
created: {ISO-date}
---

# Build Log Fold: {EARLIEST-DATE} to {LATEST-DATE}

{COUNT} entries from {EARLIEST-DATE} to {LATEST-DATE}.

## Summary

- Compiles run: {count}
- Articles created: {count} ({list key ones with wikilinks})
- Articles updated: {count}
- Queries answered: {count}

## Source Entries

{verbatim copy of the folded entries}
```

5. Write the fold page to _meta/folds/{fold-id}.md.

6. Remove the folded entries from log.md.
   - Replace the folded section with a single back-reference line:
   `<!-- folded: [[{subfolder}/_meta/folds/{fold-id}]] ({COUNT} entries, {EARLIEST-DATE} to {LATEST-DATE}) -->`

7. Append to log.md:
```
## [{ISO-timestamp}] fold | {fold-id}
- Entries folded: {COUNT} ({EARLIEST-DATE} to {LATEST-DATE})
- Fold page: [[{subfolder}/_meta/folds/{fold-id}]]
```

## Dry-run Output

Report without writing:
```
Fold plan:
- Entries to fold: {COUNT} (oldest 2^{k})
- Date range: {EARLIEST-DATE} to {LATEST-DATE}
- Fold ID: {fold-id}
- Fold page: _meta/folds/{fold-id}.md
- Remaining in log.md: {total - COUNT} entries

Run /mma --commit to execute.
```
