# Spec Delta ## Purpose The memory store holds the agent's curated lessons for a repository as validated Markdown entries, with a small generated index that is always loaded. ## ADDED Requirements ### Requirement: Entry format Each memory entry SHALL be a Markdown file named `.md` whose frontmatter has `name`, `description`, `type`, `scope`, `status`, `sources`, `occurrences`, `last_verified`, `provenance`, and `links`, followed by a non-empty body. #### Scenario: Valid entry passes the check - **GIVEN** an entry whose fields match the schema and whose name equals its file name - **WHEN** `flywheel.py check` runs - **THEN** it reports no error for that entry #### Scenario: Occurrences must match distinct sources - **GIVEN** an entry with `sources: [add-a, add-a]` and `occurrences: 2` - **WHEN** `flywheel.py check` runs - **THEN** it reports an error that occurrences does not match the 1 distinct source ### Requirement: Lifecycle in fields The store SHALL record lifecycle state only in the `status` field (active, promoted, superseded, stale); a superseded entry MUST name `superseded_by` (an existing entry other than itself) and a promoted entry MUST name `promoted_to`. When `set-status` moves an entry to another status, it SHALL remove a `superseded_by` or `promoted_to` field that no longer applies. #### Scenario: Superseded entry without a successor - **GIVEN** an entry with `status: superseded` and no `superseded_by` - **WHEN** `flywheel.py check` runs - **THEN** it reports an error #### Scenario: Entry superseded by itself - **GIVEN** an active entry `lesson-one` - **WHEN** `flywheel.py set-status lesson-one superseded --superseded-by lesson-one` runs - **THEN** the command fails and the entry is unchanged #### Scenario: Back to active - **GIVEN** an entry superseded by `lesson-two` - **WHEN** `flywheel.py set-status active` runs - **THEN** the entry has `status: active` and no `superseded_by` field, and `flywheel.py check` passes ### Requirement: Generated index The index `MEMORY.md` SHALL be generated from the entries, list one line per active entry grouped by type, and stay within the configured line and byte budget. #### Scenario: Index out of date - **GIVEN** a new entry file that is not in `MEMORY.md` - **WHEN** `flywheel.py check` runs - **THEN** it reports that the index is out of date #### Scenario: Index over budget - **GIVEN** an index budget of 5 lines and 10 active entries - **WHEN** `flywheel.py check` runs - **THEN** it reports that the index is over budget ### Requirement: Deterministic writes The commands `new`, `add-source`, and `set-status` SHALL write entries in a canonical field order and regenerate the index, so the same input always produces the same files. #### Scenario: Add a source - **GIVEN** an entry with one source `add-a` - **WHEN** `flywheel.py add-source add-b` runs - **THEN** the entry has sources `[add-a, add-b]` and `occurrences: 2` ### Requirement: Writes stop on a malformed entry The commands `new`, `add-source`, `set-status`, and `verify --apply` SHALL read every entry before they write anything; when any entry cannot be parsed they MUST fail with an error that names the file and MUST NOT write an entry or the index. #### Scenario: Broken entry in the store - **GIVEN** a store with one valid entry and one entry whose frontmatter cannot be parsed - **WHEN** `flywheel.py new ...` or `flywheel.py add-source ` runs - **THEN** the command fails, no entry file is created or changed, and `MEMORY.md` is unchanged ### Requirement: Values round-trip through the frontmatter When the CLI writes a frontmatter value, it SHALL quote values that would otherwise be read differently (for example a value that starts with `#`, or contains `: `, a comma, or a quote) and SHALL escape double quotes and backslashes, so reading the entry back gives the exact value written. #### Scenario: Description with a hash, quotes, and a backslash - **GIVEN** the description `#1 cause: the "retry" flag, path C:\tmp` - **WHEN** `flywheel.py new --type user --description ` runs - **THEN** the entry's parsed description equals that text and the index line contains it ### Requirement: Unfinished entries are flagged `flywheel.py check` SHALL warn about an entry whose body still contains the TODO placeholders that `new` writes, so a skeleton is not mistaken for a recorded lesson. #### Scenario: Skeleton left unfilled - **GIVEN** an entry created with `flywheel.py new` and not edited - **WHEN** `flywheel.py check` runs - **THEN** it reports a warning about the TODO placeholders