Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,27 @@ SESSION` is only an inactivity inference, fresh activity anywhere in the group
suppresses a stale sibling's check; definite input and approval are never
suppressed this way.

**Finding a session:** press **F** (or click **FILTER** in Session Totals) and
type part of its name, directory or session ID. Matching is immediate and
case-insensitive, and combines with the selected status category. **Enter/↓**
returns to the matching live rows; **Esc** in the field clears the filter.
Totals and attention pills still cover all live sessions. Selecting a pill
reveals its session even if it was filtered out. On a shared app-server, names
follow Codex rename events and are refreshed on reconnection; ordinary CLI
sessions still use Codex’s local name index.

**Include history** is off by default. With a local, shared Codex **0.170.0+**
app-server signed in to ChatGPT, enable it under the **All** sessions category
to browse this account’s non-archived saved sessions across model providers,
including providers you no longer use. In the terminal use **Tab** to focus
the checkbox, **Space** to toggle it, then **Tab** to the results. Use **↑/↓**
and **Enter** to open a result or load more; **Esc** or **[←]** returns from
the saved detail. The filter searches metadata in the pages loaded so far,
not message text. Each saved result can show up to ten completed turns,
newest first. Browsing never resumes a session, marks it as read, changes
the totals, or enables a write action. There is no new on-disk index; without
a compatible shared server, the live filter still works.

Named sessions show `<short session ID> // <name>` in the left telemetry panel's border
title, with the directory path inside the box beneath model information when
space permits. Names come from the local
Expand Down Expand Up @@ -3299,6 +3320,10 @@ available from the existing reader.

### Browser Sessions command centre

The same **Filter sessions** field, status filter and opt-in **Include history**
are available in the browser, including in read-only mode. Saved results are
separate from live command controls and are not added to Session Totals.

- **SESSION TOTALS** shows observed tokens and the number of currently listed
sessions, plus separate working, awaiting-approval, awaiting-input and inferred
check counts. Parent counters already include linked agents; they are summed
Expand Down
4 changes: 2 additions & 2 deletions assets/screenshots/manifest.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified assets/screenshots/sessions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/slash-command-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ These are adapter/workflow gaps. Where an API exists it is listed.
| --- | --- | --- | --- |
| `/new` | P1 | High | `thread/start` exists; needs creation options and selection/handoff to the new thread. Proposed next increment: build the common thread-creation/handoff foundation, including subscriptions, drafts and selection. |
| `/clear` | P2 | Medium | Native clear starts a new chat and clears its terminal; no combined local clear/`thread/start` workflow. Hiding monitor rows is different. Proposed next increment: a local clear/new-chat action after the /new foundation exists; Medium assumes that dependency is complete. |
| `/resume` | P1 | High | `thread/list`/`thread/resume` exist; no saved-session picker. Monitor selection observes loaded sessions. Proposed next increment: a paginated saved-session picker with verified load/handoff; share the lifecycle foundation with /new and /fork. |
| `/resume` | P1 | High | Sessions can browse paginated saved history read-only; this does not resume a thread. A native resume command still needs verified load/handoff; share the lifecycle foundation with /new and /fork. |
| `/fork` | P1 | High | `thread/fork` exists; needs options, confirmation and handoff while preserving source drafts. Proposed next increment: a reviewed fork and verified new-thread selection, retaining source history/draft and correct telemetry accounting. |
| `/worktree` | P2 | Very high | Needs actual Git worktree creation/ownership/cleanup plus thread creation/fork. No worktree manager; a cwd update is insufficient. Proposed next increment: managed worktree creation and conversation transition after thread handoff and project-context changes are supported. |
| `/archive` | P2 | Medium | `thread/archive` exists; no archive confirmation/handoff. Close/Close All only hide rows. Proposed next increment: confirm the exact session, observe archive completion and select another row without discarding unrelated drafts. |
Expand Down
2 changes: 2 additions & 0 deletions internal/codex/daemon_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type sessionStatusProvider interface {
}

type sessionDaemonSnapshot struct {
Names map[string]string
SavedScope string
AttachedThreads map[string]string
ReadStates map[string]SessionReadState
Goals map[string]*SessionGoal
Expand Down
43 changes: 32 additions & 11 deletions internal/codex/daemon_status_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package codex

import (
"context"
"crypto/rand"
"encoding/json"
"errors"
"fmt"
Expand All @@ -24,6 +25,8 @@ const (
)

type daemonStatusProvider struct {
savedScope string
names map[string]threadTitle
pendingModels map[string]*pendingModelChange
autoReviews map[string]*autoReviewState
permissionSettings map[string]string
Expand Down Expand Up @@ -124,11 +127,12 @@ func (p *daemonStatusProvider) Fetch(ctx context.Context, threadIDs []string) (s
statuses := make(map[string]sessionRuntimeStatus, len(threadIDs))
for _, threadID := range threadIDs {
p.mu.Lock()
connection, readVersion := p.connection, p.readStates[threadID].version
connection, readVersion, titleVersion := p.connection, p.readStates[threadID].version, p.names[threadID].version
p.mu.Unlock()
var result struct {
ReadState *wireReadState `json:"readState"`
Thread struct {
Name json.RawMessage
ID string `json:"id"`
AttachedToThreadID string `json:"attachedToThreadId"`
Status struct {
Expand All @@ -143,6 +147,9 @@ func (p *daemonStatusProvider) Fetch(ctx context.Context, threadIDs []string) (s
continue
}
p.mu.Lock()
if p.connection == connection && result.Thread.ID == threadID {
p.hydrateTitleLocked(threadID, result.Thread.Name, titleVersion)
}
if p.connection == connection && p.readStates[threadID].version == readVersion && result.Thread.ID == threadID {
p.observeReadStateLocked(threadID, result.ReadState.snapshot())
p.threadAttachments[threadID] = result.Thread.AttachedToThreadID
Expand All @@ -156,16 +163,9 @@ func (p *daemonStatusProvider) Fetch(ctx context.Context, threadIDs []string) (s

p.mu.Lock()
wanted := stringStructSet(threadIDs)
for id := range p.threadAttachments {
if _, keep := wanted[id]; !keep {
delete(p.threadAttachments, id)
}
}
for id := range p.readStates {
if _, keep := wanted[id]; !keep {
delete(p.readStates, id)
}
}
retainThreadIDs(p.names, wanted)
retainThreadIDs(p.threadAttachments, wanted)
retainThreadIDs(p.readStates, wanted)
p.usageCoverage = coverage
p.lastStatusAt = time.Now()
p.statusThreads = stringStructSet(threadIDs)
Expand Down Expand Up @@ -196,7 +196,11 @@ func (p *daemonStatusProvider) cachedStatusSnapshot(threadIDs []string, now time

func (p *daemonStatusProvider) statusSnapshotLocked(threadIDs []string) sessionDaemonSnapshot {
attachments := make(map[string]string)
names := make(map[string]string)
for _, id := range threadIDs {
if title, ok := p.names[id]; ok {
names[id] = title.name
}
if parent := p.threadAttachments[id]; parent != "" {
attachments[id] = parent
}
Expand Down Expand Up @@ -256,6 +260,7 @@ func (p *daemonStatusProvider) statusSnapshotLocked(threadIDs []string) sessionD
contexts[id] = c
}
return sessionDaemonSnapshot{
Names: names, SavedScope: p.savedScope,
AttachedThreads: attachments,
ReadStates: readStates,
Goals: goals,
Expand All @@ -269,6 +274,14 @@ func (p *daemonStatusProvider) statusSnapshotLocked(threadIDs []string) sessionD
}
}

func retainThreadIDs[V any](values map[string]V, wanted map[string]struct{}) {
for id := range values {
if _, keep := wanted[id]; !keep {
delete(values, id)
}
}
}

func stringStructSet(values []string) map[string]struct{} {
set := make(map[string]struct{}, len(values))
for _, value := range values {
Expand Down Expand Up @@ -378,6 +391,7 @@ func (p *daemonStatusProvider) ensureConnected(ctx context.Context) error {
p.autoReviews = make(map[string]*autoReviewState)
p.permissionSettings = make(map[string]string)
p.threadDirectories = make(map[string]string)
p.names = make(map[string]threadTitle)
p.threadAttachments = make(map[string]string)
p.settingsVersions = make(map[string]uint64)
p.settingsSignal = make(chan struct{})
Expand All @@ -398,6 +412,11 @@ func (p *daemonStatusProvider) ensureConnected(ctx context.Context) error {
p.disconnect(connection)
return err
}
p.mu.Lock()
if p.connection == connection && supportsSavedScope(initialized.UserAgent) {
p.savedScope = rand.Text()
}
p.mu.Unlock()
return nil
}

Expand Down Expand Up @@ -572,6 +591,7 @@ func (p *daemonStatusProvider) readLoop(connection *websocket.Conn, wires ...*da
p.goalNotificationLocked(envelope.Method, envelope.Params)
p.autoReviewNotificationLocked(envelope.Method, envelope.Params)
p.readStateNotificationLocked(envelope.Method, envelope.Params)
p.finderNotificationLocked(envelope.Method, envelope.Params)
if p.contexts == nil {
p.contexts = map[string]*daemonContextState{}
}
Expand Down Expand Up @@ -738,6 +758,7 @@ func (p *daemonStatusProvider) disconnect(connection *websocket.Conn) {
p.permissionSettings = nil
p.usageCoverage = nil
p.threadDirectories = nil
p.names, p.savedScope = nil, ""
p.threadAttachments = nil
if p.settingsSignal != nil {
close(p.settingsSignal)
Expand Down
8 changes: 8 additions & 0 deletions internal/codex/live_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
// unavailable pricing. AccountingAdjustments counts recognised synthetic context
// fills; those are excluded from observed tokens, activity and response graphs.
type LiveUsageSnapshot struct {
SavedScope string
TotalTokens int64
LastActivity time.Time
SessionCount int
Expand Down Expand Up @@ -436,6 +437,8 @@ func (r *LiveUsageReader) fetchTokenUsage(ctx context.Context, forceFullDiscover

exactStatuses := map[string]sessionRuntimeStatus(nil)
var daemonCoverage map[string]string
var names map[string]string
var savedScope string
r.daemonContexts = nil
r.daemonDirectories = nil
r.daemonAttachments = nil
Expand All @@ -446,6 +449,7 @@ func (r *LiveUsageReader) fetchTokenUsage(ctx context.Context, forceFullDiscover
if r.statusProvider != nil {
if daemonSnapshot, exact := r.statusProvider.Fetch(ctx, r.observedThreadIDs(now)); exact {
appServerUp = true
names, savedScope = daemonSnapshot.Names, daemonSnapshot.SavedScope
exactStatuses = daemonSnapshot.Statuses
r.daemonContexts = daemonSnapshot.Contexts
if len(daemonSnapshot.AnswerGuards) != 0 {
Expand Down Expand Up @@ -531,6 +535,9 @@ func (r *LiveUsageReader) fetchTokenUsage(ctx context.Context, forceFullDiscover
r.refreshSessionNames()
for i := range sessions {
sessions[i].Name = r.sessionNames[sessions[i].ID]
if name, ok := names[sessions[i].ID]; ok {
sessions[i].Name = name
}
}
coverageIssue := r.usageCoverage(ctx, sessions, daemonCoverage)
if firstReadErr != nil {
Expand All @@ -541,6 +548,7 @@ func (r *LiveUsageReader) fetchTokenUsage(ctx context.Context, forceFullDiscover
)
return LiveUsageSnapshot{
TotalTokens: r.totalTokens, LastActivity: r.lastActivity,
SavedScope: savedScope,
SessionCount: activeSessions, Sessions: sessions,
CodexStatusKnown: codexStatusKnown,
CodexUp: codexUp,
Expand Down
112 changes: 112 additions & 0 deletions internal/codex/session_finder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package codex

import (
"context"
"errors"
"slices"
"strings"
)

// Saved sessions are deliberately a separate, display-only type. A thread
// discovered in history must never become a live control or telemetry target.
type SavedSession struct {
ID string `json:"id"`
Name string `json:"name"`
Directory string `json:"directory"`
}

type SavedTurn struct {
Task string `json:"task"`
Reply string `json:"reply"`
Restricted bool `json:"restricted,omitempty"`
}

type SavedPage struct {
Sessions []SavedSession `json:"sessions,omitempty"`
Next string `json:"next,omitempty"`
Turns []SavedTurn `json:"turns,omitempty"`
}

type SavedSessionClient interface {
BrowseSavedSessions(ctx context.Context, scope, cursor, id string) (SavedPage, error)
}

var ErrSavedSessions = errors.New("account-scoped saved sessions unavailable")

type savedSessionProvider interface {
listSaved(ctx context.Context, scope, cursor, sortKey string) (SavedPage, error)
savedAccount(context.Context, string) (string, error)
}

func singleLine(s string) string { return strings.Join(strings.Fields(SanitizeSessionContext(s)), " ") }

func SessionMatches(query, id, name, directory string) bool {
q := strings.ToLower(strings.TrimSpace(query))
return q == "" || strings.Contains(strings.ToLower(name), q) || strings.Contains(strings.ToLower(directory), q) || strings.Contains(strings.ToLower(id), q)
}

func (c Client) BrowseSavedSessions(ctx context.Context, scope, cursor, id string) (SavedPage, error) {
if c.LiveUsage == nil || scope == "" || len(scope) > 128 || len(cursor) > 4096 || len(id) > 512 {
return SavedPage{}, ErrSavedSessions
}
p, ok := c.LiveUsage.statusProvider.(savedSessionProvider)
if !ok {
return SavedPage{}, ErrSavedSessions
}
account, err := p.savedAccount(ctx, scope)
if err != nil || account == "" {
return SavedPage{}, ErrSavedSessions
}
sameAccount := func() bool {
current, err := p.savedAccount(ctx, scope)
return err == nil && current == account
}
page, err := savedPageFor(ctx, p, scope, cursor, id)
if err != nil {
return SavedPage{}, ErrSavedSessions
}
if id != "" {
if !sameAccount() {
return SavedPage{}, ErrSavedSessions
}
turns, err := c.SessionHistory(ctx, id)
if err != nil {
return SavedPage{}, ErrSavedSessions
}
page = SavedPage{}
for _, t := range turns {
t = HistoryExcerpt(t)
page.Turns = append(page.Turns, SavedTurn{Task: t.CurrentTask, Reply: t.Text, Restricted: t.ReplyRestricted})
}
}
if !sameAccount() {
return SavedPage{}, ErrSavedSessions
}
return page, nil
}

// The cursor is a fast path, not an authorization grant: updated_at ordering
// can change between list and click. On a miss or a stale cursor, walk fresh
// account-scoped pages in creation order so activity cannot move our target.
func savedPageFor(ctx context.Context, p savedSessionProvider, scope, cursor, id string) (SavedPage, error) {
page, err := p.listSaved(ctx, scope, cursor, "updated_at")
matches := func(row SavedSession) bool { return row.ID == id }
if id == "" || (err == nil && slices.ContainsFunc(page.Sessions, matches)) || (err != nil && cursor == "") {
return page, err
}
seen := map[string]bool{}
for cursor = ""; ctx.Err() == nil && !seen[cursor]; cursor = page.Next {
seen[cursor] = true
page, err = p.listSaved(ctx, scope, cursor, "created_at")
if err != nil {
break
}
if slices.ContainsFunc(page.Sessions, matches) {
return page, nil
}
if page.Next == "" {
break
}
}
return SavedPage{}, ErrSavedSessions
}
Loading
Loading