about summary refs log tree commit diff
path: root/doc
diff options
context:
space:
mode:
authorPjotr Prins <pjotr.public01@thebird.nl>2026-11-16 16:35:24 +0000
committerPjotr Prins <pjotr.public01@thebird.nl>2026-11-16 16:35:24 +0000
commitd5e90011f764ba27251936d4fa628e1100145773 (patch)
tree0f671a2b19bb24af91201776746b8e6d511eb95b /doc
parentdc4c16203674191c4821b2f7b53e01febb7a11a6 (diff)
downloadai-memory-d5e90011f764ba27251936d4fa628e1100145773.tar.gz
symbols: C and C++ declarations from ctags, diffed between blobs
C and C++ were the one language family where the store could only say "a hunk
landed inside this function". A diff line cannot be read for declarations
there: inside a body `foo(bar);` calls something, inside a class body the same
bytes declare a constructor, and pangemma indents both the same way (of 248538
changed lines in its history, 14991 are indented `name(` lines, and the most
frequent are calls). So the file is handed to universal-ctags and the tags of a
commit's blob are diffed against its parent's: present only in the new blob is
an add, only in the old one is a remove, and a name whose tag survives both is
left to hunk context, which is the honest answer for "the change was inside
this".

The cost is bounded by a cache keyed by git object id (new table `blobs`): a
blob's tags can never change, so each file version is parsed once per store.
On the pangemma history (688 commits, 1163 distinct C/C++ blobs) the first full
pass takes 26 s and touches go from 1404 context-only rows to 6888 add, 5125
remove, 1505 context; the second pass takes 11 s and runs no ctags at all.

ctags is optional at run time. Without it the store behaves exactly as before
and `sync` says so once. The Guix package bakes its absolute path into
$AI_MEMORY_CTAGS through wrap-program, and the check phase now builds a
two-commit git repository with one C++ file to prove it end to end: the
function added in the second commit is `add`, the one whose body changed is
`context`.

Details found by running it on a real history, all in this commit:

- lambdas are tagged by default under names ctags derives from a hash of the
  file (`__anon426fc91f0102`), so every touched file reported seven functions
  added and seven removed per commit; `--extras=-{anonymous}` turns them off.
- `--kinds-C++=+p` is needed or prototypes are invisible and a declaration in a
  header would never be seen.
- include guards (`#define CALC_H`, `#define __CALC_H__`) are filtered: they are
  bookkeeping, while other macros are kept as `const`.
- merge_decl keyed a commit's declarations by bare identifier, so two files
  declaring the same name in one commit collided and one lost its attribution.
  It is keyed by (file, name) now -- a bug that applied to Odin and Rust too.
Diffstat (limited to 'doc')
-rw-r--r--doc/SKILL.md35
1 files changed, 29 insertions, 6 deletions
diff --git a/doc/SKILL.md b/doc/SKILL.md
index 41b0af9..0450e08 100644
--- a/doc/SKILL.md
+++ b/doc/SKILL.md
@@ -11,7 +11,7 @@ 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) |
+| `symbols` + `touches` | derived | every declaration a commit added, 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.
@@ -42,8 +42,14 @@ guix shell -D -f guix.scm -- odin build . -out:bin/ai-memory -vet -strict-style
 ```
 
 `guix build -f guix.scm` also runs the package's check phase, which builds a
-throwaway store, records an entry, indexes it and queries it -- that is what
-proves the Guile side is wired up.
+throwaway store, records an entry, indexes it, queries it, and then makes a
+two-commit git repository holding one C++ file to prove the ctags half (an added
+function is `add`, a changed body is `context`).
+
+`universal-ctags` is what turns C and C++ files into symbols; the Guix package
+bakes its absolute path into `$AI_MEMORY_CTAGS`, so nothing depends on PATH.  If
+the binary is missing the store still works -- C and C++ simply keep hunk
+context and get no `add`/`remove` -- and `sync` says so once on stderr.
 
 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
@@ -248,9 +254,26 @@ nothing.  Amending *before* recording is cheaper than repairing afterwards.
 
 - `[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.
+- Declarations come from three places: a line scanner for `.odin` and `.rs`, and
+  for C and C++ (`.c .h .cc .cpp .cxx .hpp .hh .hxx .ipp .tpp .inl`)
+  `universal-ctags` over the file itself, diffed between the commit's blob and
+  its parent's -- which is why a C++ `add` means the declaration is new, not that
+  a line mentioning it moved.  Everything else still gets hunk-context symbols
+  (`[fn name, context]`) thanks to git's userdiff drivers, so "which function was
+  I in" works for Python, Go, … too.
+- The ctags pass is cached per git blob (table `blobs`), keyed by object id: a
+  file version is parsed once per store, and re-syncing an imported history runs
+  no ctags at all.  Dropping the table only costs time.
+- C and C++ keep their extension in the symbol name
+  (`lmm.cpp.mdb_analyze`), so a declaration in a header and the definition in the
+  source are two symbols that `why compute_maf` shows side by side.  Directories
+  are still stripped, so a file that moved between directories reads as the same
+  symbol (that collision predates ctags and applies to every language).
+- Kinds are the same five as everywhere else: `fn` for functions, prototypes and
+  methods; `type` for class, struct, union, enum, typedef; `const` for macros
+  except include guards; `var` for file-scope variables.  Class members,
+  enumerators, lambdas and namespaces are deliberately not tags here -- they churn
+  without changing what a hunk was about.
 - `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.