Fix Codex context preview formatting#2733
Conversation
Greptile SummaryThis PR fixes Codex context preview formatting by flattening multiline titles/requests into single lines so the Codex TUI's line-oriented hook output display stays readable, and adds a compact one-line stats summary as the Codex
Confidence Score: 5/5Safe to merge — all changes are formatting and display improvements with no data-path mutations, and the new Codex branch is fully isolated behind a platform check. The formatter changes are purely cosmetic (prefix characters, whitespace collapsing, indentation) and are well covered by the updated test suite. The Codex branch in context.ts adds an isolated display path that cannot affect the additionalContext payload delivered to the model. The 30 locale bundle regenerations are mechanical outputs of the source change. No files require special attention; the most logic-heavy changes are in src/cli/handlers/context.ts and src/services/context/formatters/AgentFormatter.ts, both of which are straightforward and tested. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[SessionStart hook fires] --> B[Fetch additionalContext via worker]
B --> C{isWorkerFallback?}
C -- yes --> D[Return emptyResult]
C -- no --> E[Trim & check staleMarker]
E --> F{showTerminalOutput?}
F -- no --> G[Return additionalContext only]
F -- yes --> H{platform === 'codex'?}
H -- yes --> I{additionalContext truthy?}
I -- no --> G
I -- yes --> J[Regex extract Stats line]
J --> K[Build compact one-liner systemMessage]
K --> G2[Return additionalContext + compact systemMessage]
H -- no --> L[Fetch coloured timeline]
L --> M{coloredTimeline available?}
M -- yes --> N[displayContent = coloredTimeline]
M -- no --> O{gemini platform?}
O -- yes --> P[displayContent = additionalContext]
O -- no --> Q[displayContent = empty]
N --> R[systemMessage = displayContent + portal URL]
P --> R
Q --> S[systemMessage = undefined]
R --> G3[Return additionalContext + full systemMessage]
S --> G3
Reviews (2): Last reviewed commit: "fix(codex): de-duplicate session-start c..." | Re-trigger Greptile |
| function compactLine(value: string | null | undefined, fallback = ''): string { | ||
| return (value || fallback).replace(/\s+/g, ' ').trim(); | ||
| } |
There was a problem hiding this comment.
Whitespace-only title bypasses the fallback
(value || fallback) evaluates value before trimming, so a title that is purely whitespace (e.g., ' ') is truthy and is selected over the fallback. After .replace(/\s+/g, ' ').trim() it collapses to '', rendering a row as - 42 10:00a I with a silently empty title instead of falling back to 'Untitled'.
| function compactLine(value: string | null | undefined, fallback = ''): string { | |
| return (value || fallback).replace(/\s+/g, ' ').trim(); | |
| } | |
| function compactLine(value: string | null | undefined, fallback = ''): string { | |
| return value?.replace(/\s+/g, ' ').trim() || fallback; | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/services/context/formatters/AgentFormatter.ts
Line: 92-94
Comment:
**Whitespace-only title bypasses the fallback**
`(value || fallback)` evaluates `value` before trimming, so a title that is purely whitespace (e.g., `' '`) is truthy and is selected over the fallback. After `.replace(/\s+/g, ' ').trim()` it collapses to `''`, rendering a row as `- 42 10:00a I ` with a silently empty title instead of falling back to `'Untitled'`.
```suggestion
function compactLine(value: string | null | undefined, fallback = ''): string {
return value?.replace(/\s+/g, ' ').trim() || fallback;
}
```
How can I resolve this? If you propose a fix, please make it concise.…ummary Codex's TUI flattens newlines when it surfaces SessionStart hook output and already echoes additionalContext back as its own "hook context" block. Emitting the full timeline again through systemMessage (shown as a "warning:" block) duplicated the wall of text into an unreadable single line. For the Codex platform, replace the full-timeline systemMessage with a compact one-line summary (obs/work/savings + live URL) that stays legible after Codex flattens it. The model still receives the full, properly formatted additionalContext, and the claude-code/gemini colored multi-line paths are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Validation