about summary refs log tree commit diff
path: root/guix.scm
diff options
context:
space:
mode:
authorPjotr Prins <pjotr.public01@thebird.nl>2026-11-17 10:18:26 +0000
committerPjotr Prins <pjotr.public01@thebird.nl>2026-11-17 10:18:26 +0000
commitb7234d2514b4a693b37cf4968b267a5fafe16678 (patch)
tree0691588a6d1507230f9298ac18b855675c4d2eeb /guix.scm
parentb861693dc26a8f9944c3464a34c101af5a81d33c (diff)
downloadai-memory-master.tar.gz
symbols: scan Python and Ruby declarations, and make why FILEBASE resolve HEAD master
A commit that only adds a file recorded nothing: git has no before-side for
the new file, so its hunks carry no context ("@@ -0,0 +1,207 @@"), and Python
and Ruby had no declaration scanner to fall back on. Adding
bin/geno2mdb.py to gemma-wrapper left one commit row and two reasoning
entries with no symbol at all, so `why` could not reach them while `search`
and `list` could.

Both languages are now scanned line by line, which is the right tool here:
in Python and Ruby a declaration is the first token on its line, so the
keyword decides -- `def foo(bar):` declares, `foo(bar)` calls -- the
distinction no C++ line scanner can make.

  Python   def / async def -> fn, class -> type, and at column 0 only
           NAME = value -> const, NAME: Type -> var (an indented assignment
           is a local inside a def)
  Ruby     def / def self.NAME (with ? ! = suffixes) -> fn, class / module ->
           type, and a column-0 capitalised NAME = value -> const

An added file needs no special case: every one of its lines is a '+' line,
which git_touched already walks, so the same path that records an added line
in an existing file now records a new file's declarations. Names strip .py
and .rb like .odin and .rs (script.helper); the C family keeps its extension
because a header declaration and the source definition are different rows.

The lookup's last resort was `s.name like '%name'` -- a suffix match -- so
`why geno2mdb` could never find a file's own symbols even though SKILL.md
documents a LIKE '%...%' scan. It is a substring match now, so the file base
works, and the doc is true again.

The check phase commits script.py and script.rb into its throwaway
repository and asserts both land as `add` rows and that `why script`
resolves; measured on gemma-wrapper, sync adds 344 touches over 319 commits
and `why read_snps` reaches the reasoning attached to the commit that
introduced it.
Diffstat (limited to 'guix.scm')
-rw-r--r--guix.scm29
1 files changed, 28 insertions, 1 deletions
diff --git a/guix.scm b/guix.scm
index a281fee..0a0885b 100644
--- a/guix.scm
+++ b/guix.scm
@@ -351,7 +351,34 @@ to link the system SQLite3 instead of a bundled copy.")
                   (invoke "sh" "-c"
                           (string-append "./bin/ai-memory -C tmp/cpp --db"
                                          " tmp/cpp/store.sqlite why inc"
-                                         " | grep -q 'fn kern.cpp.inc, context'")))))
+                                         " | grep -q 'fn kern.cpp.inc, context'"))
+                  ;; Python and Ruby are line-scanned, which is also the only
+                  ;; thing that can attribute a file that was just *added*: git
+                  ;; has no before-side for it, so its hunks carry no context.
+                  (call-with-output-file "tmp/cpp/script.py"
+                    (lambda (out)
+                      (display "import os\n\ndef helper(x):\n    return x\n" out)))
+                  (call-with-output-file "tmp/cpp/script.rb"
+                    (lambda (out)
+                      (display "module Util\n  def self.twice(x)\n    x * 2\n  end\nend\n" out)))
+                  (invoke "git" "-C" "tmp/cpp" "add" "script.py" "script.rb")
+                  (invoke "git" "-C" "tmp/cpp" "-c" "user.name=check"
+                          "-c" "user.email=check@example" "commit" "-qm" "add scripts")
+                  (invoke "./bin/ai-memory" "-C" "tmp/cpp" "--db"
+                          "tmp/cpp/store.sqlite" "sync")
+                  (invoke "sh" "-c"
+                          (string-append "./bin/ai-memory -C tmp/cpp --db"
+                                         " tmp/cpp/store.sqlite why helper"
+                                         " | grep -q 'fn script.helper, add'"))
+                  (invoke "sh" "-c"
+                          (string-append "./bin/ai-memory -C tmp/cpp --db"
+                                         " tmp/cpp/store.sqlite why twice"
+                                         " | grep -q 'fn script.twice, add'"))
+                  ;; The substring lookup: `why script' reaches both files.
+                  (invoke "sh" "-c"
+                          (string-append "./bin/ai-memory -C tmp/cpp --db"
+                                         " tmp/cpp/store.sqlite why script"
+                                         " | grep -q 'fn script.helper, add'")))))
             (replace 'install
               (lambda _
                 (install-file "bin/ai-memory"