Skip to content

Fix Codex context preview formatting#2733

Open
Glucksberg wants to merge 2 commits into
thedotmack:mainfrom
Glucksberg:fix/codex-context-formatting
Open

Fix Codex context preview formatting#2733
Glucksberg wants to merge 2 commits into
thedotmack:mainfrom
Glucksberg:fix/codex-context-formatting

Conversation

@Glucksberg

Copy link
Copy Markdown
Contributor

Summary

  • Flatten multiline recent-context titles so Codex session-start hook output stays line-oriented instead of merging entries together.
  • Update mode prompts to use agent-neutral wording instead of referring to another Claude Code session.
  • Regenerate plugin bundles for the formatter/prompt changes.

Validation

  • bun test tests/context/formatters/agent-formatter.test.ts
  • parsed all plugin/modes/*.json with Node
  • npm run build

@greptile-apps

greptile-apps Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This 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 systemMessage instead of the full coloured timeline. It also standardises all context list rows with a - prefix, pads day headers with blank lines, indents detail blocks, and updates mode prompt wording from "Claude Code session" to agent-neutral "primary agent session" across 30 locale bundles.

  • AgentFormatter.ts: Adds compactLine (collapses \\s+ to a single space) and indentBlock helpers; applies them to table rows, full-observation blocks, and summary items; all list entries now carry a leading -.
  • context.ts: Introduces a Codex-specific branch that emits a compact one-liner as systemMessage and skips the coloured-timeline fetch, leaving the non-Codex path unchanged.
  • Mode JSON + bundles: Agent-neutral wording replaces "Claude Code session" across all 30 locale variants and the law-study mode.

Confidence Score: 5/5

Safe 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

Filename Overview
src/services/context/formatters/AgentFormatter.ts Core formatting logic updated: adds compactLine/indentBlock helpers, prefixes all list rows with -, pads day headers, and flattens multiline titles.
src/cli/handlers/context.ts Adds Codex-specific system message path: skips the coloured timeline fetch for Codex and surfaces a compact one-line stats summary instead; non-Codex path is functionally unchanged.
tests/context/formatters/agent-formatter.test.ts Tests updated and extended to cover new - list prefixes, 3-element day headers, multiline title/request flattening, and indented detail blocks.
plugin/modes/code.json Prompt wording changed from 'Claude Code session' to 'primary agent session' — cosmetic, agent-neutral update.
plugin/modes/law-study.json Same 'primary agent session' wording update as code.json; no functional change.
plugin/scripts/context-generator.cjs Regenerated bundle reflecting the AgentFormatter and mode prompt changes.

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
Loading

Reviews (2): Last reviewed commit: "fix(codex): de-duplicate session-start c..." | Re-trigger Greptile

Comment on lines +92 to +94
function compactLine(value: string | null | undefined, fallback = ''): string {
return (value || fallback).replace(/\s+/g, ' ').trim();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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'.

Suggested change
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant