diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-11 22:05:35 +0000 |
|---|---|---|
| committer | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-11 22:05:35 +0000 |
| commit | aa6fe5369c7733e8bc881623ab6734cfef9cb66c (patch) | |
| tree | 8d6d929282388b5b003f7f932765089e370de78a /doc | |
| download | ai-memory-aa6fe5369c7733e8bc881623ab6734cfef9cb66c.tar.gz | |
initial ai-memory: derive commits and symbols from git, author the why
commits, symbols and touches are derived from `git log`/`git show` by `sync`; only reasoning is authored, and it is append-only. Each entry records a basis (how it was established) and may supersede an earlier entry instead of rewriting it. Symbols come from two signals: declarations added or removed on diff lines (Odin and Rust), and the enclosing item named in git's own hunk headers, which needs no parser and works for any language with a userdiff driver. Links SQLite through the odin-sqlite3 bindings; guix.scm builds both the compiler and the tool. doc/SKILL.md is the operating guide.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/SKILL.md | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/doc/SKILL.md b/doc/SKILL.md new file mode 100644 index 0000000..717b84b --- /dev/null +++ b/doc/SKILL.md @@ -0,0 +1,136 @@ +--- +name: gn-memory +description: Keep a repository's ai-memory SQLite store current — import git history, record reasoning while working, and answer "why does this code look like this?" before changing it. +--- + +# gn-memory + +`ai-memory` is a per-repository store that links **what changed** (derived from +git) to **why it changed** (written by you). Three tables: + +| table | source | contents | +|---|---|---| +| `commits` | derived | hash, author timestamp, subject, body | +| `symbols` + `touches` | derived | every declaration a commit added, modified, removed, or merely *enclosed* (hunk context) | +| `reasoning` | **authored** | append-only thoughts, conclusions and questions; each records its `basis` and may `supersede` an earlier entry | + +Query flow: symbol → commits that touched it → reasoning behind those commits. + +## Getting the binary + +```sh +guix build -f guix.scm # build (odin + sqlite are in guix.scm) +$(guix build -f guix.scm)/bin/ai-memory --help +``` + +Or build locally into `bin/` (gitignored) with the flags listed at the top of +`guix.scm`: + +```sh +guix shell -D -f guix.scm -- odin build . -out:bin/ai-memory -vet -strict-style \ + -collection:sqlite3=$GUIX_ENVIRONMENT/share/odin-sqlite3 \ + -define:SQLITE3_SYSTEM_LIB=true -define:SQLITE3_DYNAMIC_LIB=true \ + "-extra-linker-flags:-L$GUIX_ENVIRONMENT/lib -Wl,-rpath,$GUIX_ENVIRONMENT/lib" +``` + +The store defaults to `<repo>/ai-memory.sqlite`; override with `--db PATH` or +`$AI_MEMORY_DB`. `--repo PATH` / `-C PATH` selects the repository, and may be +given before or after the command. + +## Session protocol + +1. **Once per repo**: `ai-memory -C REPO init` (idempotent, creates/upgrades the schema). +2. **After every commit**: `ai-memory -C REPO sync`. It is cheap and idempotent — + re-running it only refreshes derived rows. Use `import` instead of `sync` + only to pull in a *whole* history the first time (`import` has no limit). +3. **Before changing code**: ask the store, do not guess. + `ai-memory -C REPO why SYMBOL` and `ai-memory -C REPO search TEXT`. +4. **While working**: record as you go, not at the end. `--kind thought` for + what you are weighing, `--kind conclusion` for what you settled on, and + `--kind question` when you need an answer from the user. +5. **Before the commit exists** there is nothing to attach to: use + `--commit none`, then after committing run + `ai-memory -C REPO attach HEAD --session S`. +6. **Correcting yourself is not a normal record.** `--supersedes ID` changes what + `why` and `search` answer from then on, so it needs the user's consent first — + see the Rules below. + +```sh +ai-memory -C REPO record --session fix-parser --step 1 \ + --kind thought --basis "read at git.odin:120-141" \ + --body "Hunk headers name the enclosing fn; a new fn needs the declarative scan." --commit none +ai-memory -C REPO record --session fix-parser --step 2 \ + --kind conclusion --basis "measured on genenetwork4, 281 commits in 2.5 s" \ + --body "Keep both signals; add ctags only if add/remove proves noisy." +ai-memory -C REPO attach HEAD --session fix-parser +``` + +`record` and `attach` import the commit on demand, so they work immediately after +committing even if `sync` has not run yet. + +## Rules + +- **Never write to `commits`, `symbols` or `touches` by hand.** They are derived; + `sync` owns them and hand edits will be silently overwritten or duplicated. +- **`reasoning` is append-only.** Do not edit or delete an entry to change your + mind: record a correction with `--supersedes ID`. The old entry stays visible as + `#12 [superseded by #15]`, `why` and `search` answer with the correction, and + `--all` shows the whole chain. `attach` is the only other update the tool makes + (setting a NULL `commit_hash`). +- **Ask the user before superseding.** `--supersedes` rewrites history as far as + every later reader is concerned: `why` and `search` stop answering with the old + entry, and that entry collapses to a one-line stub. The row survives, but the + record's answer does not. So: say which entry id you propose to replace, what + it claimed, what the replacement says, and on what basis — then wait for a yes. + Do not bundle it into a batch of records, and never supersede an entry written by + someone else without their consent. If the user declines, either record the + correction as a new standing entry without `--supersedes` (both claims stay + visible and the contradiction is on the record) or do not record it at all. +- **Every entry says how it was established** (`--basis`): `read at src/lib.rs:412-470`, + `from commit message`, `measured on the gn4 instance`, or plainly `inferred`. + Inference and observation look identical in prose, and that is exactly what makes + a wrong entry unrecognisable later. +- **One session per task**, monotonically increasing `--step`. `(session_id, step, kind)` + is unique, so re-running a step is a no-op rather than a duplicate. +- **Make bodies self-contained.** Say what you considered, what you chose, what + you rejected and why. A future reader has the diff but not the conversation. +- **Name what you renamed.** Symbols are `<file-base>.<identifier>` (e.g. + `gemma.compute_gemma`); an old name keeps its history, so mention the new name + in the body to keep `search` useful. +- **Never commit the store or the build output.** `/bin/` and `ai-memory.sqlite*` are + in `.gitignore`; commit only source. Importing history is read-only — `-C` + never touches the working tree. + +## Interpretation + +- `[fn gemma.compute_gemma, context]` means a hunk landed *inside* that function, + not that the function was declared. `add`/`remove`/`mod` are declaration changes. +- Only `.odin` and `.rs` are parsed for declarations. Everything else still gets + hunk-context symbols (`[fn name, context]`) thanks to git's userdiff drivers, so + "which function was I in" works for C, Python, Go, … too. +- `why SYMBOL` tries three things in order, all but the last indexed: the + qualified name (`gemma.compute_gemma`), then the bare identifier via + `symbols.basename` (`compute_gemma`), then a `LIKE '%…%'` scan for partial names. +- `log` prints how many reasoning entries each commit carries — commits with `(0)` + are the ones worth annotating later. + +## Troubleshooting + +- `no commits to import` — the repo has no history yet, or `--repo` points elsewhere. +- `why` finds nothing — run `sync` first; or the symbol lives in a file type we do + not parse for declarations. +- `search` finds nothing after manual DB edits — FTS is trigger-maintained; rebuild + with `insert into reasoning_fts(reasoning_fts) values('rebuild')`. +- Direct inspection is fine (read-only): + +```sh +sqlite3 ai-memory.sqlite \ + "select c.hash, c.subject, r.kind, r.body + from symbols s join touches t on t.symbol_id = s.id + join commits c on c.hash = t.commit_hash + left join reasoning r on r.commit_hash = c.hash + where s.name like '%compute_gemma' + order by c.author_ts desc;" +``` + +- `commit`, `symbol` and `touch` are SQL keywords; the tables are plural. |
