#3003 (acsfreerun) asked for a Delete on Grok Build's sessions; #4595 kept
them listed with no Delete, because a session is a folder but Grok Build
copies each session's text into $GROK_HOME/sessions/session_search.sqlite,
which a folder delete would leave behind: its search would go on finding a
session Grok Build no longer lists.
Deletable("grok") now says yes, and sessionPaths' "grok" branch moves the
whole folder (updates.jsonl, summary.json, the locks, prompt_context.json,
terminal/, everything else it kept) and its subagents' folders, which
grokFiles folds into the session it ran in. What the cwd's folder holds for
every session there (prompt_history.jsonl), another session's folder and the
index stay. The trash, Restore, Purge, the recent-write ErrActive guard and
WSL handling are the ones Delete already has.
grokSearchRowsDrop (grok_search.go) deletes the deleted session's row in
session_docs, and its subagents', inside one BEGIN IMMEDIATE with a 5 s busy
timeout, so it waits for Grok Build's own write instead of failing; the
session_docs_ad trigger takes the row out of session_docs_fts. It runs before
the first file is moved: a row that can't be taken out (a database that isn't
one, a lock held past the timeout) stops the delete and the session stays
whole, rather than a folder gone from the list and still found by search. No
index file, or one without those tables, deletes as before. Restore brings
the folder back; the index row is not put back, so Grok Build's search finds
a restored session only if Grok Build indexes the folder again.
Tests, in-repo and on fixtures, never on a real ~/.grok: the sessions
package's fixture tree gained a lock file per session, a subagents/ entry, a
terminal/ file and the cwd's prompt_history.jsonl, and a small
session_search.sqlite is built in-test from the real file's schema (v4,
session_docs over FTS5 session_docs_fts with the three triggers).
TestGrokDeleteRestore (delete, folder and row and FTS entry gone, another
session's row kept, ErrActive, Restore, Purge),
TestGrokDeleteLeavesTheSessionWhenItsIndexRowCantGo and
TestGrokSearchRowsDrop; TestGrokSessionDeleteOnThePage drives the page's own
handlers (GET /api/sessions/manage?agent=grok says deletable, POST
/api/sessions/delete moves it, the trash lists it, POST /api/sessions/restore
puts it back).
docs/subsystems/gateway-sessions.md: the delete paragraph, and Grok Build out
of the "sessions magpie cannot delete" list.
Run (mote, this tree, on origin/main 289184a40): gofmt -l clean; go vet -tags
nogui ./... ok (one pre-existing cgo deprecation warning in internal/proc);
go test -count=1 ./internal/sessions/... ok (55.9 s); go test -count=1
./internal/gui -run 'Session|Manage|Forget|Trash|Delete' ok, 63 tests, the
new one among them; go test -tags nogui -count=1 on the same two selections
ok. go test -count=1 ./internal/gui (whole package, 216 s) fails
TestDockReopenKeepsTheWindowsSpace and TestCoveredWindowStaysUp with "timed
out waiting until the window is minimised"; both are red the same way in a
worktree at 289184a40 without this change, so they are this Mac's window
server, not this commit.
Broken by hand: without `"grok"` in Deletable, TestGrokDeleteRestore is red on
"Grok Build's sessions are not deletable"; green with it.
Not tried: a real Grok Build binary deleting one of its own sessions, so
whether it re-indexes a restored folder is unverified (said in the doc).
Isolation: the test binaries put HOME, USERPROFILE, XDG_* and every agent's
own variable (GROK_HOME included) in a temp folder (testenv.Isolate), and the
new tests name GROK_HOME and XDG_CONFIG_HOME themselves. A copy of this
machine's real ~/.grok/sessions (a 14.9 MB session_search.sqlite with 54
rows, one session of 76 files, one parent session of 477 files with two real
subagent folders) was exercised in the scratch folder only: delete, index row
and FTS entry gone, restore to the same file counts, purge; the developer's
own ~/.grok/sessions was snapshotted (every path, size and mtime; the index's
sha256; its session ids) before and after the runs and differs only where the
running Grok Build windows write themselves.