# memory care

Use this to find stale, duplicate or contradictory memory cards before your agents trust them.

Workspace installs include `.brigade/memory-care.example.json` as a legacy scanner wiring contract, and `brigadestack memory care init` writes the active gitignored `.brigade/memory-care.toml` scanner config.

## Commands

- `brigadestack memory care init` writes the active gitignored `.brigade/memory-care.toml` scanner config.
- `brigadestack memory care scan` scans local memory cards for stale, unconsolidated-evidence, expired, undersourced, contradictory, missing-index-link, orphaned-card, oversized-card, missing-frontmatter, missing-reviewed, missing-freshness, and missing-evidence-ref issues without editing memory.
- `brigadestack memory care plan-fixes` builds a plan for low-risk metadata repairs and, in 0.31.0, does not write card files.
- `brigadestack memory care backfill` bulk-repairs cards that predate the freshness convention by deriving `last_reviewed` from each card's last git commit date and proposing `fresh_until` from the configured stale window. Dry-run by default. `--apply` writes frontmatter without overwriting existing values and records a receipt under `.brigade/memory-care/backfills/`.
- `brigadestack memory care status` reports memory-care scan freshness and open refresh candidates.
- `brigadestack memory care doctor` reports memory-care config and queue health.
- `brigadestack memory care import-issues` routes the latest memory-care refresh queue into the work inbox. The queue resolves from `.brigade/memory-care/decay/refresh-queue.json`, falling back to the legacy `memory/cards/decay/` location.
- `brigadestack memory care closeout` writes closeout metadata marking the current refresh queue reviewed (or deferred with `--defer`) and supports `--reason`.

**0.32.0 beta** adds four more subcommands and an `--apply` flag on `plan-fixes`:

- `brigadestack memory care tend [--stage <stage>] [--dry-run]` runs the tending stages: `hub`, `fixes`, `retire`, `inbox` and `instructions`. It applies low-risk metadata fixes, drains the review inbox and reports instruction-file budgets. `--json` prints the result as data.
- `brigadestack memory care undo <decision-id>` restores a card to the bytes it had before an automatic change, if the card has not changed since.
- `brigadestack memory care archive --from-file decisions.jsonl [--limit N]` moves the listed cards to `memory/archive/cards/`, with undo.
- `brigadestack memory care recover <decision-id>` finishes a change that was interrupted.
- `brigadestack memory care plan-fixes --apply` applies the same low-risk fixes that `tend` applies.

```bash
brigadestack memory care init
brigadestack memory care scan
brigadestack memory care plan-fixes
brigadestack memory care backfill
brigadestack memory care backfill --apply
brigadestack memory care status
brigadestack memory care doctor
brigadestack memory care import-issues
brigadestack memory care closeout
```

Related work-inbox converters:

```bash
brigadestack work import memory-care
brigadestack work import memory-refresh
```

- `brigadestack work import memory-care` converts the refresh queue into imports. It defaults to `memory/cards/decay/refresh-queue.json` under the target, overridable with `--queue`.
- `brigadestack work import memory-refresh` converts memory-refresh candidates into task imports with card identity, reason, evidence summary, and acceptance criteria.

## Read-only paths

Set `read_only_paths` in `.brigade/memory-care.toml` to a list of globs for policy cards that memory care skips. It is empty by default.

```toml
read_only_paths = ["memory/cards/policy-*.md"]
```

`scan`, `plan-fixes`, and `backfill` skip matching cards. `brigadestack memory proposal create` and `apply` refuse them with an error that names the matching pattern. `memory care status` and `doctor` list the active patterns.

## How memory care fits doctor

`brigadestack doctor` checks installed bootstrap files against hard byte budgets so overgrown files fail before agents load truncated context. It also checks:

- `memory/cards/*.md` budgets
- `MEMORY.md` card links under `memory/cards/`
- memory-care config, scan freshness, open refresh candidates, and queue validity
- corrupt scan or refresh-queue JSON once the loop is wired

Missing memory-care state is advisory for fresh installs. Bootstrap truncation is a hard failure.

## What memory care changes

`memory care` itself uses no model. In 0.31.0, `scan`, `plan-fixes`, `status` and `doctor` never write card files. The one write path is `backfill --apply`, which fills missing frontmatter dates and never overwrites a value. **0.32.0 beta:** `scan`, `status` and `doctor` still never write cards, but `plan-fixes --apply`, `tend`, `undo`, `archive` and `recover` do, and every change they make is journaled so `undo` can reverse it. A `contradictory` result from `scan` means two cards claim the same id or alias. It is a string match, not a judgment about whether two facts disagree.

## Reflection and model-backed verification

Two related jobs work on a memory scope on the backend. Both need configuration, and both open proposals. Canonical memory changes when a proposal is applied.

- `brigadestack memory reflect run` finds exact and near-duplicate cards and related links, and proposes merges. It is deterministic and calls no model.
- `brigadestack memory verify run` calls models. Two agents from your `roster.toml`, set by `propose_seat` and `confirm_seat`, check selected cards against the evidence they cite and open a correction proposal when a card no longer holds. It refuses to run until `[verify] enabled = true` is set in that folder's `.brigade/memory-care.toml`. `run --dry-run --no-model` previews which cards it would pick without calling a model.

`brigadestack care install` can schedule both through systemd, launchd or Task Scheduler. `memory-reflect` runs at 10:00 and `memory-verify` at 11:00 by default, each from its own folder.