diff --git a/docs/subsystems/gateway-sessions.md b/docs/subsystems/gateway-sessions.md index 30b82d2c1..847a7b616 100644 --- a/docs/subsystems/gateway-sessions.md +++ b/docs/subsystems/gateway-sessions.md @@ -203,6 +203,11 @@ capabilities to a gateway row. Verification: `TestDesktopSessionTitles`, `TestDesktopSessionTitleInStats`, `TestDesktopTitlesReadOncePerList`, `TestDesktopSessionTitlesOnPages`. +A ZCode request names its session without the `sess_` prefix ZCode's +database gives it, so `Titles` looks a `zcode:` key up under both and +answers under the id asked for (#5195). Verification: +`TestZCodeTitlesByRequestID`. + Routing's stage names the session an account is serving (connor_yang on Discord): a row answering, or that answered, the request shown adds that request's session title after its status, on one line cut short with the diff --git a/internal/sessions/sessions.go b/internal/sessions/sessions.go index b36297884..3458ba6ec 100644 --- a/internal/sessions/sessions.go +++ b/internal/sessions/sessions.go @@ -2679,15 +2679,25 @@ func findListed(agent, id string) (Session, bool) { // agent's own title, else its first prompt. A key with no files, or a // session with no title, is left out. Desktop's local metadata can name a // session without its CLI transcript. The Routing page uses this too (#1293). +// A ZCode request names its session without the sess_ prefix its database +// gives it, so that id names the session too. func Titles(keys []string) map[string]string { out := map[string]string{} if len(keys) == 0 { return out } 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. + alias := map[string]string{} var desktopIDs, piDesktopIDs []string for _, k := range keys { want[k] = true + if agent, id, ok := strings.Cut(k, ":"); ok && agent == "zcode" && !strings.HasPrefix(id, "sess_") { + full := agent + ":sess_" + id + want[full] = true + alias[full] = k + } if id, ok := strings.CutPrefix(k, "claude-desktop:"); ok { desktopIDs = append(desktopIDs, id) continue @@ -2744,6 +2754,9 @@ func Titles(keys []string) map[string]string { continue } out[k] = s.Title + if asked := alias[k]; asked != "" { + out[asked] = s.Title + } } } return out diff --git a/internal/sessions/zcode_titles_test.go b/internal/sessions/zcode_titles_test.go new file mode 100644 index 000000000..db8002ada --- /dev/null +++ b/internal/sessions/zcode_titles_test.go @@ -0,0 +1,31 @@ +package sessions + +import ( + "database/sql" + "path/filepath" + "testing" +) + +// A ZCode request carries its session's id without the prefix its database +// gives it (sess_…), so the Routing page asks for the title by that id. The +// title is found under the database's key and handed back under the id asked +// for, as it is for the prefixed id. +func TestZCodeTitlesByRequestID(t *testing.T) { + home := setupAgents(t) + const id = "578bd3d1-834b-43fb-b40c-ed9d17ad7731" + const name = "A ZCode session's title" + db, err := sql.Open("sqlite", filepath.Join(home, ".zcode", "cli", "db", "db.sqlite")) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { db.Close() }) + if _, err := db.Exec(`INSERT INTO session (id, project_id, parent_id, slug, directory, title, title_source, version, time_created, time_updated) VALUES (?, 'p', NULL, 's', '/work/zc', ?, 'generated', '0.16.9', 1790496000000, 1790496000000)`, "sess_"+id, name); err != nil { + t.Fatal(err) + } + got := Titles([]string{"zcode:" + id, "zcode:sess_" + id}) + for _, k := range []string{"zcode:" + id, "zcode:sess_" + id} { + if got[k] != name { + t.Fatalf("%s: title %q, want %q (all %v)", k, got[k], name, got) + } + } +}