sessions: a ZCode session the CLI database lacks is named from the app's task index (Flandern1211 on X)

Titles named a ZCode session only from files in the CLI database
(~/.zcode/cli/db/db.sqlite). A session the app keeps only in its own
tasks-index.sqlite (a request names it without the sess_ prefix) had no file,
so the Context page showed the id's first eight characters. Titles now asks
the task index for each ZCode key still unnamed, by sess_<bare id>, skipping
default titles. b0b995e08 covered only sessions that have a CLI row.

Run (mote): internal/sessions and internal/gui whole packages ok; gofmt clean;
go vet darwin, linux nogui, windows ok.
Broken by hand: the fallback removed -> TestZCodeTitleOfSessionOnlyTheAppKnows
red (empty title).
Not tried: a real ZCode on this machine (its CLI db is absent here; the index
has only two sessions); other agents' desktop indexes were not audited beyond
claude-desktop and PI-Desktop, which Titles already reads. Full suite not run
before the tag.
This commit is contained in:
yetone
2026-11-12 09:50:58 +08:00
parent a7662a416f
commit db0c1b039d
2 changed files with 45 additions and 0 deletions
+14
View File
@@ -3086,6 +3086,20 @@ func Titles(keys []string) map[string]string {
if len(keys) == 0 {
return out
}
// A ZCode session the CLI database has no row for (the app keeps its
// tasks in an index of its own) is still named as the app names it.
defer func() {
for _, k := range keys {
if out[k] != "" {
continue
}
if agent, id, ok := strings.Cut(k, ":"); ok && agent == "zcode" {
if t, ok := zcodeTaskOf("sess_" + zcodeBareID(id)); ok && title(t.title) != "" && !ocDefaultTitle(title(t.title)) {
out[k] = t.title
}
}
}
}()
want := make(map[string]bool, len(keys))
// alias maps the key a file is grouped under back to the key asked for:
// ZCode's request id, without the prefix its database gives it.
+31
View File
@@ -298,3 +298,34 @@ func TestZCodeTitleStampsLeaveKeptListAlone(t *testing.T) {
t.Fatalf("the kept list was stamped in place: size %d, mod %d", f.size, f.mod.UnixMilli())
}
}
// The app's task index names a session the CLI database has no row for, and
// a request names it without the sess_ prefix (Flandern1211 on X: the
// Context page showed the id's first eight characters).
func TestZCodeTitleOfSessionOnlyTheAppKnows(t *testing.T) {
home := setupAgents(t)
if err := os.MkdirAll(filepath.Join(home, ".zcode", "v2"), 0o755); err != nil {
t.Fatal(err)
}
idx, err := sql.Open("sqlite", filepath.Join(home, ".zcode", "v2", "tasks-index.sqlite"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { idx.Close() })
if _, err := idx.Exec(`CREATE TABLE tasks (workspace_key TEXT NOT NULL, task_id TEXT NOT NULL, title TEXT NOT NULL DEFAULT '', updated_at INTEGER NOT NULL, deleted INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (workspace_key, task_id))`); err != nil {
t.Fatal(err)
}
if _, err := idx.Exec(`INSERT INTO tasks (workspace_key, task_id, title, updated_at) VALUES ('w', 'sess_49fd5314-1a7a-44f7-857c-c3266cd78aed', '整理发票', 1)`); err != nil {
t.Fatal(err)
}
keys := []string{"zcode:49fd5314-1a7a-44f7-857c-c3266cd78aed", "zcode:sess_49fd5314-1a7a-44f7-857c-c3266cd78aed", "zcode:deadbeef"}
got := Titles(keys)
for _, k := range keys[:2] {
if got[k] != "整理发票" {
t.Fatalf("%s: %q, want 整理发票 (all %v)", k, got[k], got)
}
}
if got[keys[2]] != "" {
t.Fatalf("unknown session named %q", got[keys[2]])
}
}