detached c7b7d25

fix(sessions): count repeated search matches

commit
c7b7d25d484d123bc3c643b275560b2ba3737574
author
brice · · 2026-08-19 09:36 UTC
parent
ae3daad
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
3 files · +43 -15
M README.md +1 -1
@@ -359,7 +359,7 @@ Type `!` followed by a command to run it directly without going through the mode
359359
360360 ### `/sessions`
361361
362-Shows previous sessions for the current working directory, newest first, with timestamp, model, message count, cost, and the session title. Press `Tab` to rotate between **this directory** and **all sessions** in the active normal or Zutfile-agent namespace; other agent namespaces never appear. Press `/` and type at least two characters to search contiguous text in an ephemeral in-memory corpus of persisted user and assistant messages. Tool calls, tool results, images, developer context, and compaction payloads are excluded. The picker displays each matching session's count and a highlighted best excerpt; changing a query reuses the corpus rather than reopening transcripts. Session entries and search corpus load in the background. Once an entry appears, `up`/`down` and `enter` can select it immediately; `esc` clears a search or cancels and closes the picker. Selecting a session from another working directory switches the live workspace to that session's recorded directory before the transcript resumes, so tools, instructions, sandbox state, and file suggestions do not retain the old directory. Sessions remember their stored provider and model: resuming rebuilds the live agent when necessary instead of silently using a different model; if a staged switch fails, the current session is left unchanged. Branches created for tree navigation remain available to `/session tree` but are hidden from this flat picker. `/sessions` is unavailable with `--no-session`. A fresh interactive session asks the active model for a concise title after the first real prompt and restores that title when resumed.
362+Shows previous sessions for the current working directory, newest first, with timestamp, model, message count, cost, and the session title. Press `Tab` to rotate between **this directory** and **all sessions** in the active normal or Zutfile-agent namespace; other agent namespaces never appear. Press `/` and type at least two characters to search contiguous text in an ephemeral in-memory corpus of persisted user and assistant messages. Tool calls, tool results, images, developer context, and compaction payloads are excluded. The picker displays each matching session's count and a highlighted first matching excerpt; changing a query reuses the corpus rather than reopening transcripts. Session entries and search corpus load in the background. Once an entry appears, `up`/`down` and `enter` can select it immediately; `esc` clears a search or cancels and closes the picker. Selecting a session from another working directory switches the live workspace to that session's recorded directory before the transcript resumes, so tools, instructions, sandbox state, and file suggestions do not retain the old directory. Sessions remember their stored provider and model: resuming rebuilds the live agent when necessary instead of silently using a different model; if a staged switch fails, the current session is left unchanged. Branches created for tree navigation remain available to `/session tree` but are hidden from this flat picker. `/sessions` is unavailable with `--no-session`. A fresh interactive session asks the active model for a concise title after the first real prompt and restores that title when resumed.
363363
364364 ### `/session`
365365
@@ -359,7 +359,7 @@ Type `!` followed by a command to run it directly without going through the mode
359 359
360 ### `/sessions`360 ### `/sessions`
361 361
362-Shows previous sessions for the current working directory, newest first, with timestamp, model, message count, cost, and the session title. Press `Tab` to rotate between **this directory** and **all sessions** in the active normal or Zutfile-agent namespace; other agent namespaces never appear. Press `/` and type at least two characters to search contiguous text in an ephemeral in-memory corpus of persisted user and assistant messages. Tool calls, tool results, images, developer context, and compaction payloads are excluded. The picker displays each matching session's count and a highlighted best excerpt; changing a query reuses the corpus rather than reopening transcripts. Session entries and search corpus load in the background. Once an entry appears, `up`/`down` and `enter` can select it immediately; `esc` clears a search or cancels and closes the picker. Selecting a session from another working directory switches the live workspace to that session's recorded directory before the transcript resumes, so tools, instructions, sandbox state, and file suggestions do not retain the old directory. Sessions remember their stored provider and model: resuming rebuilds the live agent when necessary instead of silently using a different model; if a staged switch fails, the current session is left unchanged. Branches created for tree navigation remain available to `/session tree` but are hidden from this flat picker. `/sessions` is unavailable with `--no-session`. A fresh interactive session asks the active model for a concise title after the first real prompt and restores that title when resumed.362+Shows previous sessions for the current working directory, newest first, with timestamp, model, message count, cost, and the session title. Press `Tab` to rotate between **this directory** and **all sessions** in the active normal or Zutfile-agent namespace; other agent namespaces never appear. Press `/` and type at least two characters to search contiguous text in an ephemeral in-memory corpus of persisted user and assistant messages. Tool calls, tool results, images, developer context, and compaction payloads are excluded. The picker displays each matching session's count and a highlighted first matching excerpt; changing a query reuses the corpus rather than reopening transcripts. Session entries and search corpus load in the background. Once an entry appears, `up`/`down` and `enter` can select it immediately; `esc` clears a search or cancels and closes the picker. Selecting a session from another working directory switches the live workspace to that session's recorded directory before the transcript resumes, so tools, instructions, sandbox state, and file suggestions do not retain the old directory. Sessions remember their stored provider and model: resuming rebuilds the live agent when necessary instead of silently using a different model; if a staged switch fails, the current session is left unchanged. Branches created for tree navigation remain available to `/session tree` but are hidden from this flat picker. `/sessions` is unavailable with `--no-session`. A fresh interactive session asks the active model for a concise title after the first real prompt and restores that title when resumed.
363 363
364 ### `/session`364 ### `/session`
365 365
M packages/agent/modes/session_dialog.go +23 -14
@@ -563,12 +563,12 @@ func matchSessionSearchSegments(ctx context.Context, query string, segments []co
563563 if text == "" {
564564 text = core.NormalizeSessionSearchText(segment.Text)
565565 }
566- indexes := sessionSearchSubstringIndexes(text, query)
567- if len(indexes) == 0 {
566+ count, indexes := sessionSearchSubstringMatches(text, query)
567+ if count == 0 {
568568 continue
569569 }
570570 current := matches[segment.Path]
571- current.count++
571+ current.count += count
572572 if current.excerpt == "" {
573573 current.excerpt = text
574574 current.indexes = indexes
@@ -582,18 +582,27 @@ func sessionSearchQuery(query string) bool {
582582 return len([]rune(core.NormalizeSessionSearchText(query))) >= minSessionSearchQueryRunes
583583 }
584584
585-func sessionSearchSubstringIndexes(text, query string) []int {
586- start := strings.Index(text, query)
587- if start < 0 {
588- return nil
589- }
590- indexes := make([]int, 0, utf8.RuneCountInString(query))
591- for index := start; index < start+len(query); {
592- indexes = append(indexes, index)
593- _, size := utf8.DecodeRuneInString(text[index:])
594- index += size
585+func sessionSearchSubstringMatches(text, query string) (int, []int) {
586+ count := 0
587+ var firstIndexes []int
588+ for start := 0; start < len(text); {
589+ offset := strings.Index(text[start:], query)
590+ if offset < 0 {
591+ break
592+ }
593+ index := start + offset
594+ count++
595+ if firstIndexes == nil {
596+ firstIndexes = make([]int, 0, utf8.RuneCountInString(query))
597+ for end := index; end < index+len(query); {
598+ firstIndexes = append(firstIndexes, end)
599+ _, size := utf8.DecodeRuneInString(text[end:])
600+ end += size
601+ }
602+ }
603+ start = index + len(query)
595604 }
596- return indexes
605+ return count, firstIndexes
597606 }
598607
599608 func (d *sessionDialog) applySearchFilter() {
@@ -563,12 +563,12 @@ func matchSessionSearchSegments(ctx context.Context, query string, segments []co
563 if text == "" {563 if text == "" {
564 text = core.NormalizeSessionSearchText(segment.Text)564 text = core.NormalizeSessionSearchText(segment.Text)
565 }565 }
566- indexes := sessionSearchSubstringIndexes(text, query)566+ count, indexes := sessionSearchSubstringMatches(text, query)
567- if len(indexes) == 0 {567+ if count == 0 {
568 continue568 continue
569 }569 }
570 current := matches[segment.Path]570 current := matches[segment.Path]
571- current.count++571+ current.count += count
572 if current.excerpt == "" {572 if current.excerpt == "" {
573 current.excerpt = text573 current.excerpt = text
574 current.indexes = indexes574 current.indexes = indexes
@@ -582,18 +582,27 @@ func sessionSearchQuery(query string) bool {
582 return len([]rune(core.NormalizeSessionSearchText(query))) >= minSessionSearchQueryRunes582 return len([]rune(core.NormalizeSessionSearchText(query))) >= minSessionSearchQueryRunes
583 }583 }
584 584
585-func sessionSearchSubstringIndexes(text, query string) []int {585+func sessionSearchSubstringMatches(text, query string) (int, []int) {
586- start := strings.Index(text, query)586+ count := 0
587- if start < 0 {587+ var firstIndexes []int
588- return nil588+ for start := 0; start < len(text); {
589- }589+ offset := strings.Index(text[start:], query)
590- indexes := make([]int, 0, utf8.RuneCountInString(query))590+ if offset < 0 {
591- for index := start; index < start+len(query); {591+ break
592- indexes = append(indexes, index)592+ }
593- _, size := utf8.DecodeRuneInString(text[index:])593+ index := start + offset
594- index += size594+ count++
595+ if firstIndexes == nil {
596+ firstIndexes = make([]int, 0, utf8.RuneCountInString(query))
597+ for end := index; end < index+len(query); {
598+ firstIndexes = append(firstIndexes, end)
599+ _, size := utf8.DecodeRuneInString(text[end:])
600+ end += size
601+ }
602+ }
603+ start = index + len(query)
595 }604 }
596- return indexes605+ return count, firstIndexes
597 }606 }
598 607
599 func (d *sessionDialog) applySearchFilter() {608 func (d *sessionDialog) applySearchFilter() {
M packages/agent/modes/session_dialog_test.go +19 -0
@@ -444,6 +444,25 @@ func TestSessionSearchUsesContiguousQueryAndRequiresTwoCharacters(t *testing.T)
444444 }
445445 }
446446
447+func TestSessionSearchCountsRepeatedSegmentMatches(t *testing.T) {
448+ matches := matchSessionSearchSegments(context.Background(), "sharm", []core.SessionSearchSegment{
449+ {Path: "repeated", Text: "sharm then sharm"},
450+ })
451+ match, ok := matches["repeated"]
452+ if !ok {
453+ t.Fatalf("matches = %#v, missing repeated session", matches)
454+ }
455+ if match.count != 2 {
456+ t.Fatalf("match count = %d, want 2", match.count)
457+ }
458+ if match.excerpt != "sharm then sharm" {
459+ t.Fatalf("match excerpt = %q", match.excerpt)
460+ }
461+ if want := []int{0, 1, 2, 3, 4}; len(match.indexes) != len(want) || match.indexes[0] != want[0] || match.indexes[1] != want[1] || match.indexes[2] != want[2] || match.indexes[3] != want[3] || match.indexes[4] != want[4] {
462+ t.Fatalf("highlight indexes = %v, want %v", match.indexes, want)
463+ }
464+}
465+
447466 func TestSessionDialogDefersSearchUntilSecondCharacter(t *testing.T) {
448467 d := newSessionDialog()
449468 d.active = true
@@ -444,6 +444,25 @@ func TestSessionSearchUsesContiguousQueryAndRequiresTwoCharacters(t *testing.T)
444 }444 }
445 }445 }
446 446
447+func TestSessionSearchCountsRepeatedSegmentMatches(t *testing.T) {
448+ matches := matchSessionSearchSegments(context.Background(), "sharm", []core.SessionSearchSegment{
449+ {Path: "repeated", Text: "sharm then sharm"},
450+ })
451+ match, ok := matches["repeated"]
452+ if !ok {
453+ t.Fatalf("matches = %#v, missing repeated session", matches)
454+ }
455+ if match.count != 2 {
456+ t.Fatalf("match count = %d, want 2", match.count)
457+ }
458+ if match.excerpt != "sharm then sharm" {
459+ t.Fatalf("match excerpt = %q", match.excerpt)
460+ }
461+ if want := []int{0, 1, 2, 3, 4}; len(match.indexes) != len(want) || match.indexes[0] != want[0] || match.indexes[1] != want[1] || match.indexes[2] != want[2] || match.indexes[3] != want[3] || match.indexes[4] != want[4] {
462+ t.Fatalf("highlight indexes = %v, want %v", match.indexes, want)
463+ }
464+}
465+
447 func TestSessionDialogDefersSearchUntilSecondCharacter(t *testing.T) {466 func TestSessionDialogDefersSearchUntilSecondCharacter(t *testing.T) {
448 d := newSessionDialog()467 d := newSessionDialog()
449 d.active = true468 d.active = true

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close