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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,11 @@ the word starts with C; otherwise they retain a separate `(C)` before the label.
Copy exports the complete sanitized text available in the bounded session preview,
not an unlimited transcript: it cannot recover text omitted by observation limits.
Clipboard contents then follow your terminal and operating system's retention behaviour.
When Codex marks an answer as hidden, blocked, or requiring a native display
that Codexometer cannot provide, Sessions shows **View this reply in Codex.**
The terminal, history, Copy, and read-only web view use that notice in the
configured language instead of the original text. This applies once Codex supplies the decision; it cannot
recall text already shown or copied while an answer was streaming.

`Left` / `Right` move along **graph ↔ split ↔ expanded ↔ full detail** without
wrapping. Each row retains its own presentation; adjusting one does not resize
Expand Down Expand Up @@ -4034,11 +4039,11 @@ go test -race -cover -timeout 10m -run '^TestLocalisedScreens$' ./internal/ui
```

An optional Unix integration check verifies the installed Codex against the
0.164.0 baseline, 0.166.0, 0.167.0, 0.167.1, 0.167.2, 0.168.0 or 0.169.0, including negotiated
0.164.0 baseline, 0.166.0, 0.167.0, 0.167.1, 0.167.2, 0.168.0, 0.169.0 or 0.170.0, including negotiated
compressed WebSocket RPC:

```sh
CODEXOMETER_TEST_CODEX_VERSION=0.169.0 go test ./internal/codex -run '^TestNativeCodexCompression$' -count=1
CODEXOMETER_TEST_CODEX_VERSION=0.170.0 go test ./internal/codex -run '^TestNativeCodexCompression$' -count=1
```

Use `0.164.0` when that version is on `PATH`; the existing
Expand Down
2 changes: 1 addition & 1 deletion docs/slash-command-support.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Slash-command support audit

Codexometer behaviour updated for [v0.31.0](https://github.com/merefield/codexometer/releases/tag/v0.31.0) on **2026-11-18**. The upstream inventory remains pinned to **Codex CLI 0.169.0** (`rust-v0.169.0`): [command registry](https://github.com/openai/codex/blob/rust-v0.169.0/codex-rs/tui/src/slash_command.rs), [native command dispatch](https://github.com/openai/codex/blob/rust-v0.169.0/codex-rs/tui/src/chatwidget/slash_dispatch.rs), [app-server method registry](https://github.com/openai/codex/blob/rust-v0.169.0/codex-rs/app-server-protocol/src/protocol/common.rs), [thread settings types](https://github.com/openai/codex/blob/rust-v0.169.0/codex-rs/app-server-protocol/src/protocol/v2/thread.rs), and [native directory-change workflow](https://github.com/openai/codex/blob/rust-v0.169.0/codex-rs/tui/src/app/working_directory.rs). This is not a claim of compatibility with every newer Codex release.
Upstream inventory checked against **Codex CLI 0.170.0** on **2026-11-19**: [command registry](https://github.com/openai/codex/blob/rust-v0.170.0/codex-rs/tui/src/slash_command.rs), [native command dispatch](https://github.com/openai/codex/blob/rust-v0.170.0/codex-rs/tui/src/chatwidget/slash_dispatch.rs), [app-server method registry](https://github.com/openai/codex/blob/rust-v0.170.0/codex-rs/app-server-protocol/src/protocol/common.rs), [thread settings types](https://github.com/openai/codex/blob/rust-v0.170.0/codex-rs/app-server-protocol/src/protocol/v2/thread.rs), and [native directory-change workflow](https://github.com/openai/codex/blob/rust-v0.170.0/codex-rs/tui/src/app/working_directory.rs). This is not a claim of compatibility with every newer Codex release.

The tables cover all **65 registered command variants** and the three additional accepted aliases `/cwd`, `/pet` and `/clean`: **68 upstream command names** in total. `/presets` and `/config` were absent from the earlier inventory and are now included as gaps, not newly implemented features. Codexometer’s local `/help` and terminal `/commands` entries, and model-advertised speed aliases, are outside that count. Platform, feature and debug-build filters affect actual visibility. The [published reference](https://learn.chatgpt.com/docs/developer-commands#built-in-slash-commands) is supplementary; the pinned registry determines this inventory. Codexometer has explicit adapters/local UI implementations; it does not send slash commands as model prompts. There is no generic server endpoint to discover or execute the CLI's slash commands.

Expand Down
117 changes: 117 additions & 0 deletions internal/codex/answer_display.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package codex

import (
"encoding/json"
"slices"
)

type answerItem struct {
ID, Type, Text, Phase string
Moderation json.RawMessage
}

// The companion cannot implement native replacements, annotations or trusted
// contact checks. Only an explicit plain show (or no restriction) is renderable.
func restrictedAnswer(raw json.RawMessage) bool {
if len(raw) == 0 || string(raw) == "null" {
return false
}
var m struct {
Moderated *bool
Display *struct {
Version int
Mode string
TrustedContacts string
Annotation json.RawMessage
}
}
if json.Unmarshal(raw, &m) != nil || m.Moderated == nil {
return true
}
d := m.Display
if d == nil {
return *m.Moderated
}
return d.Version != 1 || d.Mode != "show" || d.TrustedContacts != "skip" ||
(len(d.Annotation) != 0 && string(d.Annotation) != "null")
}

// Scoped to one thread. Keep identities, never message contents. Copy on
// append so a daemon snapshot can be read after releasing the provider lock.
type answerID struct{ turn, item string }
type answerGuards []answerID

func (g *answerGuards) note(turn, item string) {
key := answerID{turn, item}
if slices.Contains(*g, key) {
return
}
const limit = 4 * SessionHistoryLimit
start := max(0, len(*g)-limit+1)
*g = append(slices.Clone((*g)[start:]), key)
}

func (g answerGuards) covers(turn, item string) bool {
for _, k := range g {
// Completion mirrors omit item IDs. Only use that fallback within
// the same turn; a positive item identity also works without a turn.
if k.turn == turn && (item == "" || k.item == "" || k.item == item) ||
k.item != "" && k.item == item && (k.turn == "" || turn == "") {
return true
}
}
return false
}

func (g answerGuards) protect(c *SessionContext) {
if c.Kind == SessionContextReply && g.covers(c.TurnID, c.ItemID) {
c.withholdAnswer()
}
}

func (c *rolloutCursor) inheritAnswerGuards(guards answerGuards) {
for _, k := range guards {
c.answers.note(k.turn, k.item)
}
c.answers.protect(&c.preview)
}

// SameHistoryTurn compares observations, not their displayed text. Legacy
// mirrors can lack a turn ID: use a shared item ID, or as a last resort
// the same nonzero observation time. Never match conflicting known IDs.
func (a SessionContext) SameHistoryTurn(b SessionContext) bool {
if a.ThreadID != b.ThreadID {
return false
}
if a.TurnID != "" && b.TurnID != "" {
return a.TurnID == b.TurnID
}
if a.ItemID != "" && b.ItemID != "" {
return a.ItemID == b.ItemID
}
return !a.At.IsZero() && a.At.Equal(b.At)
}

// ProtectReply updates an already-delivered excerpt when a matching decision
// arrives via another source. It never matches another thread or a command.
func (decision SessionContext) ProtectReply(c *SessionContext) {
if decision.ReplyRestricted && c.Kind == SessionContextReply && decision.SameHistoryTurn(*c) &&
(decision.ItemID == "" || c.ItemID == "" || decision.ItemID == c.ItemID) {
c.withholdAnswer()
if c.TurnID == "" {
c.TurnID = decision.TurnID
}
if c.ItemID == "" {
c.ItemID = decision.ItemID
}
}
}

func (c *SessionContext) withholdAnswer() {
c.Text, c.ReplyRestricted, c.Streaming = "", true, false
c.Activity = SessionActivity{}
}

// HasDisplayText includes restricted answers: observers carry only the flag;
// presenters supply the localised notice instead of assistant-authored text.
func (c SessionContext) HasDisplayText() bool { return c.ReplyRestricted || c.Text != "" }
134 changes: 134 additions & 0 deletions internal/codex/answer_display_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package codex

import (
"context"
"encoding/json"
"path/filepath"
"strings"
"testing"
"time"
)

func TestAnswerDisplayContract(t *testing.T) {
for _, tc := range []struct {
raw string
restrict bool
}{
{"", false}, {"null", false}, {`{"moderated":false}`, false},
{`{"moderated":true,"display":{"version":1,"mode":"show","trustedContacts":"skip","extra":42}}`, false},
{`{"moderated":true,"display":null}`, true},
{`{"moderated":false,"display":{"version":1,"mode":"hide","replacement":{"kind":"wellbeingPromptHelpline"}}}`, true},
{`{"moderated":true,"display":{"version":1,"mode":"block","reason":{"kind":"protection","protectionType":"fixture"}}}`, true},
{`{"moderated":true,"display":{"version":1,"mode":"show","trustedContacts":"check"}}`, true},
{`{"moderated":true,"display":{"version":1,"mode":"show","trustedContacts":"skip","annotation":{"kind":"wellbeingHelpline","subject":"answer"}}}`, true},
{`{"moderated":false,"display":{"version":2,"mode":"show","trustedContacts":"skip"}}`, true},
{`{"moderated":false,"display":{"action":"legacy"}}`, true},
{`{"moderated":true,"display":{"version":1,"mode":"show"}}`, true},
{`{"display":null}`, true}, {`"malformed"`, true},
} {
if got := restrictedAnswer(json.RawMessage(tc.raw)); got != tc.restrict {
t.Errorf("%s: restricted = %t, want %t", tc.raw, got, tc.restrict)
}
}
}

func TestRestrictedLiveAnswerStopsStreamingAndCannotReplay(t *testing.T) {
states := map[string]*daemonContextState{}
emit := func(method, raw string) {
daemonContextEvent(states, method, nil, json.RawMessage(raw), time.Now())
}
emit("turn/started", `{"threadId":"s","turn":{"id":"t"}}`)
item := `{"threadId":"s","turnId":"t","item":{"id":"a","type":"agentMessage","phase":"final_answer","text":"fixture plaintext"%s}}`
plain := strings.Replace(item, "%s", "", 1)
blocked := strings.Replace(item, "%s", `,"moderation":{"moderated":true}`, 1)
delta := `{"threadId":"s","turnId":"t","itemId":"a","delta":"partial"}`
emit("item/started", plain)
emit("item/agentMessage/delta", delta)
if !states["s"].latest.Streaming {
t.Fatal("ordinary stream was buffered")
}
for _, e := range [][2]string{{"item/completed", blocked}, {"item/started", blocked}, {"item/agentMessage/delta", delta}, {"item/completed", plain}} {
emit(e[0], e[1])
got := states["s"].latest
if !got.ReplyRestricted || got.Text != "" || got.Streaming || states["s"].streamText != "" {
t.Fatalf("%s retained restricted text: %+v", e[0], got)
}
}
emit("item/completed", strings.Replace(plain, `"id":"a"`, `"id":"b"`, 1))
if got := states["s"].latest; got.ReplyRestricted || got.Text != "fixture plaintext" {
t.Fatal("restriction was applied to an unrelated item", got)
}
}

func TestRestrictedRolloutMirrorsAndRestart(t *testing.T) {
for _, decision := range []string{
`{"type":"agent_message","phase":"final_answer","message":"fixture plaintext","moderation":{"item_id":"a","moderated":true}}`,
`{"type":"item_completed","turn_id":"t","item":{"type":"AgentMessage","id":"a","content":[{"type":"Text","text":"fixture plaintext"}],"moderation":{"moderated":true}}}`,
} {
now, home := time.Now(), t.TempDir()
path := testRolloutPath(t, home, now, "s")
event := func(p string) string { return `{"type":"event_msg","payload":` + p + "}\n" }
writeRollout(t, path, sessionMetaLine("s", `"cli"`, "/example", nil)+"\n"+event(`{"type":"task_started","turn_id":"t"}`)+event(decision)+
`{"type":"response_item","payload":{"type":"message","role":"assistant","phase":"final_answer","content":[{"type":"output_text","text":"fixture plaintext"}]}}`+"\n"+
event(`{"type":"task_complete","turn_id":"t","last_agent_message":"fixture plaintext"}`))
for _, compressed := range []bool{false, true} {
if compressed {
compressTestRollout(t, path, true)
}
r, err := NewLiveUsageReader(home)
if err != nil {
t.Fatal(err)
}
r.statusProvider = nil
u, err := r.FetchTokenUsage(context.Background())
if err != nil || len(u.Sessions) != 1 {
t.Fatal(u, err)
}
c := u.Sessions[0].Context
if c.Text != "" || !c.ReplyRestricted || c.TurnID != "t" {
t.Fatal("restart exposed mirrored text", c)
}
for _, cursor := range r.files {
cursor.currentTurnID = "next"
c, ok := rolloutContextRecord([]byte(event(`{"type":"task_complete","turn_id":"next","last_agent_message":"safe"}`)), cursor)
if !ok || c.Text != "safe" || c.ReplyRestricted {
t.Fatal("unrelated turn hidden", c)
}
}
}
}
}

func TestTurnSummaryRestrictsAlreadyStreamedAnswer(t *testing.T) {
states := map[string]*daemonContextState{}
for _, e := range [][2]string{
{"item/started", `{"threadId":"s","turnId":"t","item":{"type":"agentMessage","phase":"final_answer","id":"a"}}`},
{"item/agentMessage/delta", `{"threadId":"s","turnId":"t","itemId":"a","delta":"fixture plaintext"}`},
{"turn/completed", `{"threadId":"s","turn":{"id":"t","status":"completed","items":[{"type":"agentMessage","id":"a","text":"fixture plaintext","moderation":{"moderated":true}}]}}`},
} {
daemonContextEvent(states, e[0], nil, json.RawMessage(e[1]), time.Now())
}
c := daemonContextSnapshot(states, []string{"s"}, nil)["s"]
if !c.ReplyRestricted || c.Text != "" || c.Streaming || states["s"].streamText != "" {
t.Fatal(c)
}
}

func TestTruncatedTailDoesNotPublishOrphanedAnswerMirror(t *testing.T) {
path := filepath.Join(t.TempDir(), "rollout.jsonl")
final := `{"type":"event_msg","payload":{"type":"task_complete","turn_id":"t","last_agent_message":"unverified mirror"}}` + "\n"
writeRollout(t, path, strings.Repeat("x", 256*1024)+"\n"+final)
cursor := &rolloutCursor{threadID: "s", currentTurnID: "t"}
if c := latestSessionContext(path, cursor); c.Text != "" {
t.Fatal(c)
}
c, ok := rolloutContextRecord([]byte(final), cursor)
if !ok || c.Text != "" {
t.Fatal("subsequent mirror exposed truncated history", c)
}
rolloutContextRecord([]byte(`{"type":"event_msg","payload":{"type":"task_started","turn_id":"next"}}`), cursor)
cursor.currentTurnID = "next"
if c, ok := rolloutContextRecord([]byte(strings.ReplaceAll(final, `"t"`, `"next"`)), cursor); !ok || c.Text != "unverified mirror" {
t.Fatal("new turn lost ordinary reply", c)
}
}
4 changes: 2 additions & 2 deletions internal/codex/daemon_native_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestNativeCodexCompression(t *testing.T) {
if expected == "" && os.Getenv("CODEXOMETER_TEST_CODEX_164") == "1" {
expected = "0.164.0" // Retain the existing baseline test invocation.
}
versions := []string{"0.164.0", "0.166.0", "0.167.0", "0.167.1", "0.167.2", "0.168.0", "0.169.0"}
versions := []string{"0.164.0", "0.166.0", "0.167.0", "0.167.1", "0.167.2", "0.168.0", "0.169.0", "0.170.0"}
if expected == "" {
t.Skip("set CODEXOMETER_TEST_CODEX_VERSION to one of " + strings.Join(versions, ", ") + " with that Codex installed")
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestNativeCodexCompression(t *testing.T) {
if err != nil || len(loaded) != 0 {
t.Fatal("isolated server unexpectedly has loaded threads", loaded, err)
}
if expected == "0.169.0" {
if slices.Index(versions, expected) >= slices.Index(versions, "0.169.0") {
// 0.169 adds explicit provider selection. An unknown provider must
// fail rather than silently returning the default catalogue.
if _, err := p.commandModels(context.Background(), "codexometer-unknown-provider"); err == nil {
Expand Down
1 change: 1 addition & 0 deletions internal/codex/daemon_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type sessionDaemonSnapshot struct {
Goals map[string]*SessionGoal
UsageCoverage map[string]string
Contexts map[string]SessionContext
AnswerGuards map[string]answerGuards
WorkingDirectories map[string]string
Statuses map[string]sessionRuntimeStatus
ModelObservations []resolvedModelObservation
Expand Down
8 changes: 8 additions & 0 deletions internal/codex/daemon_status_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,15 @@ func (p *daemonStatusProvider) statusSnapshotLocked(threadIDs []string) sessionD
if contexts == nil {
contexts = map[string]SessionContext{}
}
var guards map[string]answerGuards
for _, id := range threadIDs {
c := contexts[id]
if s := p.contexts[id]; s != nil && len(s.answers) != 0 {
if guards == nil {
guards = make(map[string]answerGuards)
}
guards[id] = s.answers
}
if pending := p.pendingModels[id]; pending != nil {
c.PendingModel = pending.display
}
Expand All @@ -254,6 +261,7 @@ func (p *daemonStatusProvider) statusSnapshotLocked(threadIDs []string) sessionD
Goals: goals,
UsageCoverage: coverage,
Contexts: contexts,
AnswerGuards: guards,
WorkingDirectories: directories,
Statuses: statuses,
ModelObservations: append([]resolvedModelObservation(nil), p.observations...),
Expand Down
9 changes: 9 additions & 0 deletions internal/codex/live_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ type LiveUsageReader struct {
}

type rolloutCursor struct {
answers answerGuards
partialAnswerHistory bool
activity sessionActivityState
preview SessionContext
offset int64
Expand Down Expand Up @@ -446,6 +448,11 @@ func (r *LiveUsageReader) fetchTokenUsage(ctx context.Context, forceFullDiscover
appServerUp = true
exactStatuses = daemonSnapshot.Statuses
r.daemonContexts = daemonSnapshot.Contexts
if len(daemonSnapshot.AnswerGuards) != 0 {
for _, cursor := range r.files {
cursor.inheritAnswerGuards(daemonSnapshot.AnswerGuards[cursor.threadID])
}
}
daemonCoverage = daemonSnapshot.UsageCoverage
r.daemonDirectories = daemonSnapshot.WorkingDirectories
r.daemonAttachments = daemonSnapshot.AttachedThreads
Expand Down Expand Up @@ -725,6 +732,7 @@ func (r *LiveUsageReader) addFile(ctx context.Context, path string, info os.File
// Replacing this path changes the historical baseline, not the activity
// already observed by this process. Keep it only for the same thread.
if previous := r.files[path]; previous != nil && cursor.threadID != "" && previous.threadID == cursor.threadID {
cursor.inheritAnswerGuards(previous.answers)
cursor.observedTokens, cursor.modelCalls, cursor.turnTimings = previous.observedTokens, previous.modelCalls, previous.turnTimings
cursor.lastGrowthAt = previous.lastGrowthAt
}
Expand Down Expand Up @@ -1575,6 +1583,7 @@ func (r *LiveUsageReader) sessionSnapshots(now time.Time, liveWriters map[string
preview.CompletedSteerIDs, preview.TurnID = live.CompletedSteerIDs, live.TurnID
}
}
cursor.answers.protect(&preview)
if cursor.guardianReviewer && !preview.pending() {
// A private reviewer's reply (streaming or final) is not the
// conversation. Its tokens above still belong to this group; the
Expand Down
6 changes: 6 additions & 0 deletions internal/codex/live_usage_compressed.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (r *LiveUsageReader) addCompressedFile(ctx context.Context, path string, in
return fmt.Errorf("read compressed rollout: %w", err)
}
if old != nil && old.threadID == cursor.threadID {
cursor.inheritAnswerGuards(old.answers)
cursor.observedTokens, cursor.modelCalls, cursor.turnTimings = old.observedTokens, old.modelCalls, old.turnTimings
cursor.lastGrowthAt = old.lastGrowthAt
if old.offset != cursor.offset {
Expand Down Expand Up @@ -104,6 +105,11 @@ func compressedRolloutBaseline(ctx context.Context, path string, info os.FileInf
cursor.compressedTail = append(cursor.compressedTail[:0], tail...)
if !oversized {
baselineRolloutRecord(cursor, line)
} else {
cursor.partialAnswerHistory = true
if cursor.preview.Kind == SessionContextReply {
cursor.preview = SessionContext{}
}
}
line = line[:0]
oversized = false
Expand Down
Loading
Loading