From dc4c16203674191c4821b2f7b53e01febb7a11a6 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Mon, 16 Nov 2026 16:20:48 +0000 Subject: index: title a reasoning doc with its gist, and make --rebuild stand alone A reasoning document was titled with the subject of the commit it is attached to (COALESCE(c.subject,'') through a LEFT JOIN), which is wrong twice over: an entry recorded with --commit none -- every entry before its commit exists -- was indexed with an empty title, and its gist, the assessed one-line claim that `list` and `why` show, was not indexed as text at all; an attached entry merely repeated the title its commit document already carries. The title is now the entry's own gist, from reasoning.gist, and the join is gone. `update-index --rebuild` also died with "mkdir failed (No such file or directory)" whenever the index directory was absent -- the state of every store that has never been indexed, and the state README.md tells a reader to produce by deleting the index. Only the non-rebuild path created the directory; `mkdir -p` now runs before the database handle either way. The check phase records a gist deliberately different from the body and asserts both that it answers a search and that it is the document's title, so a regression fails the build rather than the reader. .gitignore covers *.sqlite.d/, the default index directory, which neither *.sqlite nor *.sqlite-* matched -- the README already claimed the index was ignored. doc/SKILL.md says what `title` means in a search reply: the gist for a reasoning entry, the subject for a commit. --- scripts/index.scm | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'scripts') diff --git a/scripts/index.scm b/scripts/index.scm index 87e32f8..e812f94 100644 --- a/scripts/index.scm +++ b/scripts/index.scm @@ -123,10 +123,13 @@ ;;; Database handles (define (open-writable index rebuild) - (unless rebuild - ;; Xapian creates its files inside DIR, but not DIR. - (unless (zero? (system* "mkdir" "-p" index)) - (die "could not create ~a" index))) + ;; Xapian creates its files inside DIR, but not DIR -- and only the plain + ;; `update' path used to create it, so `update --rebuild' on a store whose + ;; index directory was deleted (the documented way to recover, and the state + ;; of every store that has never been indexed) died in new-WritableDatabase + ;; with "mkdir failed". `mkdir -p' is a no-op when the directory is there. + (unless (zero? (system* "mkdir" "-p" index)) + (die "could not create ~a" index)) (new-WritableDatabase index (if rebuild (DB-CREATE-OR-OVERWRITE) (DB-CREATE-OR-OPEN)))) @@ -197,12 +200,18 @@ (let ((entry (assq key record))) (and entry (second entry)))) +;;; The title is the entry's own gist -- the assessed one-line claim, which is +;;; what `list' and `why' show. It is deliberately NOT the subject of the +;;; commit the entry is attached to: that subject is already the title of the +;;; commit document, and an entry recorded with `--commit none' has no commit +;;; to borrow from, which left it indexed with an empty title and its gist +;;; unsearchable. (define (reasoning-record repo row) (match row - ((id session step kind body commit_hash created_at subject) + ((id session step kind body commit_hash created_at gist) (let* ((key (format #f "reasoning:~a" id)) (date (yyyymmdd created_at)) - (title (if (string? subject) (string-trim-both subject) "")) + (title (if (string? gist) (string-trim-both gist) "")) (topics (if (non-empty-string? session) (map (lambda (word) (term "O" word)) (string-split session #\-)) @@ -334,9 +343,8 @@ (let ((db (sqlite-open store SQLITE_OPEN_READONLY))) (let ((reasoning (query db "SELECT r.id, r.session_id, r.step, r.kind, r.body, COALESCE(r.commit_hash, ''), r.created_at, - COALESCE(c.subject, '') + COALESCE(r.gist, '') FROM reasoning r - LEFT JOIN commits c ON c.hash = r.commit_hash ORDER BY r.id")) (commits (query db "SELECT hash, subject, COALESCE(body, ''), author_ts FROM commits ORDER BY author_ts")) -- cgit 1.4.1