mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
cf515142b0cb8024a82314686a34d43f03b1ea4d
27 Commits
-
fix(app-server): set originator header from initialize (re-revert) (#8988)
Reapplies https://github.com/openai/codex/pull/8873 which was reverted due to merge conflicts
Owen Lin ·
2026-01-09 12:09:30 -08:00 -
fix: add tui.alternate_screen config and --no-alt-screen CLI flag for Zellij scrollback (#8555)
Fixes #2558 Codex uses alternate screen mode (CSI 1049) which, per xterm spec, doesn't support scrollback. Zellij follows this strictly, so users can't scroll back through output. **Changes:** - Add `tui.alternate_screen` config: `auto` (default), `always`, `never` - Add `--no-alt-screen` CLI flag - Auto-detect Zellij and skip alt screen (uses existing `ZELLIJ` env var detection) **Usage:** ```bash # CLI flag codex --no-alt-screen # Or in config.toml [tui] alternate_screen = "never" ``` With default `auto` mode, Zellij users get working scrollback without any config changes. --------- Co-authored-by: Josh McKinney <joshka@openai.com>
Helmut Januschka ·
2026-01-09 18:38:26 +00:00 -
jif-oai ·
2026-01-09 17:18:42 +00:00 -
Revert "fix(app-server): set originator header from initialize JSON-RPC request" (#8986)
Reverts openai/codex#8873
jif-oai ·
2026-01-09 17:00:53 +00:00 -
fix(app-server): set originator header from initialize JSON-RPC request (#8873)
**Motivation** The `originator` header is important for codex-backend’s Responses API proxy because it identifies the real end client (codex cli, codex vscode extension, codex exec, future IDEs) and is used to categorize requests by client for our enterprise compliance API. Today the `originator` header is set by either: - the `CODEX_INTERNAL_ORIGINATOR_OVERRIDE` env var (our VSCode extension does this) - calling `set_default_originator()` which sets a global immutable singleton (`codex exec` does this) For `codex app-server`, we want the `initialize` JSON-RPC request to set that header because it is a natural place to do so. Example: ```json { "method": "initialize", "id": 0, "params": { "clientInfo": { "name": "codex_vscode", "title": "Codex VS Code Extension", "version": "0.1.0" } } } ``` and when app-server receives that request, it can call `set_default_originator()`. This is a much more natural interface than asking third party developers to set an env var. One hiccup is that `originator()` reads the global singleton and locks in the value, preventing a later `set_default_originator()` call from setting it. This would be fine but is brittle, since any codepath that calls `originator()` before app-server can process an `initialize` JSON-RPC call would prevent app-server from setting it. This was actually the case with OTEL initialization which runs on boot, but I also saw this behavior in certain tests. Instead, what we now do is: - [unchanged] If `CODEX_INTERNAL_ORIGINATOR_OVERRIDE` env var is set, `originator()` would return that value and `set_default_originator()` with some other value does NOT override it. - [new] If no env var is set, `originator()` would return the default value which is `codex_cli_rs` UNTIL `set_default_originator()` is called once, in which case it is set to the new value and becomes immutable. Later calls to `set_default_originator()` returns `SetOriginatorError::AlreadyInitialized`. **Other notes** - I updated `codex_core::otel_init::build_provider` to accepts a service name override, and app-server sends a hardcoded `codex_app_server` service name to distinguish it from `codex_cli_rs` used by default (e.g. TUI). **Next steps** - Update VSCE to set the proper value for `clientInfo.name` on `initialize` and drop the `CODEX_INTERNAL_ORIGINATOR_OVERRIDE` env var. - Delete support for `CODEX_INTERNAL_ORIGINATOR_OVERRIDE` in codex-rs.Owen Lin ·
2026-01-09 08:17:13 -08:00 -
Immutable CodexAuth (#8857)
Historically we started with a CodexAuth that knew how to refresh it's own tokens and then added AuthManager that did a different kind of refresh (re-reading from disk). I don't think it makes sense for both `CodexAuth` and `AuthManager` to be mutable and contain behaviors. Move all refresh logic into `AuthManager` and keep `CodexAuth` as a data object.
pakrym-oai ·
2026-01-08 11:43:56 -08:00 -
chore: unify conversation with thread name (#8830)
Done and verified by Codex + refactor feature of RustRover
jif-oai ·
2026-01-07 17:04:53 +00:00 -
feat: forced tool tips (#8752)
Force an announcement tooltip in the CLI. This query the gh repo on this [file](https://raw.githubusercontent.com/openai/codex/main/announcement_tip.toml) which contains announcements in TOML looking like this: ``` # Example announcement tips for Codex TUI. # Each [[announcements]] entry is evaluated in order; the last matching one is shown. # Dates are UTC, formatted as YYYY-MM-DD. The from_date is inclusive and the to_date is exclusive. # version_regex matches against the CLI version (env!("CARGO_PKG_VERSION")); omit to apply to all versions. # target_app specify which app should display the announcement (cli, vsce, ...). [[announcements]] content = "Welcome to Codex! Check out the new onboarding flow." from_date = "2024-10-01" to_date = "2024-10-15" version_regex = "^0\\.0\\.0$" target_app = "cli" ``` To make this efficient, the announcement is queried on a best effort basis at the launch of the CLI (no refresh made after this). This is done in an async way and we display the announcement (with 100% probability) iff the announcement is available, the cache is correctly warmed and there is a matching announcement (matching is recomputed for each new session).
jif-oai ·
2026-01-06 18:02:05 +00:00 -
feat(tui2): transcript scrollbar (auto-hide + drag) (#8728)
## Summary - Add a transcript scrollbar in `tui2` using `tui-scrollbar`. - Reserve 2 columns on the right (1 empty gap + 1 scrollbar track) and plumb the reduced width through wrapping/selection/copy so rendering and interactions match. - Auto-hide the scrollbar when the transcript is pinned to the bottom (columns remain reserved). - Add mouse click/drag support for the scrollbar, with pointer-capture so drags don’t fall through into transcript selection. - Skip scrollbar hit-testing when auto-hidden to avoid an invisible interactive region. ## Notes - Styling is theme-aware: in light themes the thumb is darker than the track; in dark themes it reads as an “indented” element without going full-white. - Pre-Ratatui 0.30 (ratatui-core split) requires a small scratch-buffer bridge; this should simplify once we move to Ratatui 0.30. ## Testing - `just fmt` - `just fix -p codex-tui2 --allow-no-vcs` - `cargo test -p codex-tui2`
Josh McKinney ·
2026-01-05 09:05:14 -08:00 -
tui2: copy selection dismisses highlight (#8718)
Clicking the transcript copy pill or pressing the copy shortcut now copies the selected transcript text and clears the highlight. Show transient footer feedback ("Copied"/"Copy failed") after a copy attempt, with logic in transcript_copy_action to keep app.rs smaller and closer to tui for long-term diffs. Update footer snapshots and add tiny unit tests for feedback expiry. https://github.com/user-attachments/assets/c36c8163-11c5-476b-b388-e6fbe0ff6034Josh McKinney ·
2026-01-04 22:05:18 -08:00 -
perf(tui2): cache transcript view rendering (#8693)
The transcript viewport draws every frame. Ratatui's Line::render_ref does grapheme segmentation and span layout, so repeated redraws can burn CPU during streaming even when the visible transcript hasn't changed. Introduce TranscriptViewCache to reduce per-frame work: - WrappedTranscriptCache memoizes flattened+wrapped transcript lines per width, appends incrementally as new cells arrive, and rebuilds on width change, truncation (backtrack), or transcript replacement. - TranscriptRasterCache caches rasterized rows (Vec<Cell>) per line index and user-row styling; redraws copy cells instead of rerendering spans. The caches are width-scoped and store base transcript content only; selection highlighting and copy affordances are applied after drawing. User rows include the row-wide base style in the cached raster. Refactor transcript_render to expose append_wrapped_transcript_cell for incremental building and add a test that incremental append matches the full build. Add docs/tui2/performance-testing.md as a playbook for macOS sample profiles and hotspot greps. Expand transcript_view_cache tests to cover rebuild conditions, raster equivalence vs direct rendering, user-row caching, and eviction. Test: cargo test -p codex-tui2
Josh McKinney ·
2026-01-03 11:44:27 -08:00 -
Attach more tags to feedback submissions (#8688)
Attach more tags to sentry feedback so it's easier to classify and debug without having to scan through logs. Formatting isn't amazing but it's a start. <img width="1234" height="276" alt="image" src="https://github.com/user-attachments/assets/521a349d-f627-4051-b511-9811cd5cd933" />
pakrym-oai ·
2026-01-02 16:51:03 -08:00 -
feat(tui2): add multi-click transcript selection (#8471)
Support multi-click transcript selection using transcript/viewport coordinates (wrapped visual line index + content column), not terminal buffer positions. Gestures: - double click: select word-ish token under cursor - triple click: select entire wrapped line - quad click: select paragraph (contiguous non-empty wrapped lines) - quint+ click: select the entire history cell (all wrapped lines belonging to a single `HistoryCell`, including blank lines inside the cell) Selection expansion rebuilds the wrapped transcript view from `HistoryCell::display_lines(width)` so boundaries match on-screen wrapping during scroll/resize/streaming reflow. Click grouping is resilient to minor drag jitter (some terminals emit tiny Drag events during clicks) and becomes more tolerant as the sequence progresses so quad/quint clicks are practical. Tests cover expansion (word/line/paragraph/cell), sequence resets (timing, motion, line changes, real drags), drag jitter, and behavior on spacer lines between history cells (paragraph/cell selection prefers the cell above).
Josh McKinney ·
2025-12-23 21:05:06 +00:00 -
feat(tui2): add copy selection shortcut + UI affordance (#8462)
- Detect Ctrl+Shift+C vs VS Code Ctrl+Y and surface in footer hints - Render clickable “⧉ copy” pill near transcript selection (hidden while dragging) - Handle copy hotkey + click to copy selection - Document updated copy UX VSCode: <img width="1095" height="413" alt="image" src="https://github.com/user-attachments/assets/84be0c82-4762-4c3e-80a4-c751c078bdaa" /> Ghosty: <img width="505" height="68" alt="image" src="https://github.com/user-attachments/assets/109cc1a1-f029-4f7e-a141-4c6ed2da7338" />
Josh McKinney ·
2025-12-22 18:54:58 -08:00 -
chore(tui): include tracing targets in file logs (#8418)
with_target(true) is the default for tracing-subscriber, but we previously disabled it for file output. Keep it enabled so we can selectively enable specific targets/events at runtime via RUST_LOG=..., and then grep by target/module in the log file during troubleshooting. before and after: <img width="629" height="194" alt="image" src="https://github.com/user-attachments/assets/33f7df3f-0c5d-4d3f-b7b7-80b03d4acd21" />
Josh McKinney ·
2025-12-22 15:59:30 -08:00 -
fix(tui2): copy transcript selection outside viewport (#8449)
Copy now operates on the full logical selection range (anchor..head), not just the visible viewport, so selections that include offscreen lines copy the expected text. Selection extraction is factored into `transcript_selection` to make the logic easier to test and reason about. It reconstructs the wrapped visual transcript, renders each wrapped line into a 1-row offscreen Buffer, and reads the selected cells. This keeps clipboard text aligned with what is rendered (gutter, indentation, wrapping). Additional behavior: - Skip continuation cells for wide glyphs (e.g. CJK) so copied text does not include spurious spaces like "コ X". - Avoid copying right-margin padding spaces. Manual tested performed: - "tell me a story" a few times - scroll up, select text, scroll down, copy text - confirm copied text is what you expect
Josh McKinney ·
2025-12-22 15:24:52 -08:00 -
chore: enusre the logic that creates ConfigLayerStack has access to cwd (#8353)
`load_config_layers_state()` should load config from a `.codex/config.toml` in any folder between the `cwd` for a thread and the project root. Though in order to do that, `load_config_layers_state()` needs to know what the `cwd` is, so this PR does the work to thread the `cwd` through for existing callsites. A notable exception is the `/config` endpoint in app server for which a `cwd` is not guaranteed to be associated with the query, so the `cwd` param is `Option<AbsolutePathBuf>` to account for this case. The logic to make use of the `cwd` will be done in a follow-up PR.
Michael Bolin ·
2025-12-19 20:11:27 -08:00 -
feat: support allowed_sandbox_modes in requirements.toml (#8298)
This adds support for `allowed_sandbox_modes` in `requirements.toml` and provides legacy support for constraining sandbox modes in `managed_config.toml`. This is converted to `Constrained<SandboxPolicy>` in `ConfigRequirements` and applied to `Config` such that constraints are enforced throughout the harness. Note that, because `managed_config.toml` is deprecated, we do not add support for the new `external-sandbox` variant recently introduced in https://github.com/openai/codex/pull/8290. As noted, that variant is not supported in `config.toml` today, but can be configured programmatically via app server.
Michael Bolin ·
2025-12-19 21:09:20 +00:00 -
chore: migrate from Config::load_from_base_config_with_overrides to ConfigBuilder (#8276)
https://github.com/openai/codex/pull/8235 introduced `ConfigBuilder` and this PR updates all call non-test call sites to use it instead of `Config::load_from_base_config_with_overrides()`. This is important because `load_from_base_config_with_overrides()` uses an empty `ConfigRequirements`, which is a reasonable default for testing so the tests are not influenced by the settings on the host. This method is now guarded by `#[cfg(test)]` so it cannot be used by business logic. Because `ConfigBuilder::build()` is `async`, many of the test methods had to be migrated to be `async`, as well. On the bright side, this made it possible to eliminate a bunch of `block_on_future()` stuff.
Michael Bolin ·
2025-12-18 16:12:52 -08:00 -
Terminal Detection Metadata for Per-Terminal Scroll Scaling (#8252)
# Terminal Detection Metadata for Per-Terminal Scroll Scaling ## Summary Expand terminal detection into structured metadata (`TerminalInfo`) with multiplexer awareness, plus a testable environment shim and characterization tests. ## Context / Motivation - TUI2 owns its viewport and scrolling model (see `codex-rs/tui2/docs/tui_viewport_and_history.md`), so scroll behavior must be consistent across terminals and independent of terminal scrollback quirks. - Prior investigations show mouse wheel scroll deltas vary noticeably by terminal. To tune scroll scaling (line increments per wheel tick) we need reliable terminal identification, including when running inside tmux/zellij. - tmux is especially tricky because it can mask the underlying terminal; we now consult `tmux display-message` client termtype/name to attribute sessions to the actual terminal rather than tmux itself. - This remains backwards compatible with the existing OpenTelemetry user-agent token because `user_agent()` is still derived from the same environment signals (now via `TerminalInfo`). ## Changes - Introduce `TerminalInfo`, `TerminalName`, and `Multiplexer` with `TERM_PROGRAM`/`TERM`/multiplexer detection and user-agent formatting in `codex-rs/core/src/terminal.rs`. - Add an injectable `Environment` trait + `FakeEnvironment` for testing, and comprehensive characterization tests covering known terminals, tmux client termtype/name, and zellij. - Document module usage and detection order; update `terminal_info()` to be the primary interface for callers. ## Testing - `cargo test -p codex-core terminal::tests` - manually checked ghostty, iTerm2, Terminal.app, vscode, tmux, zellij, Warp, alacritty, kitty. ``` 2025-12-18T07:07:49.191421Z INFO Detected terminal info terminal=TerminalInfo { name: Iterm2, term_program: Some("iTerm.app"), version: Some("3.6.6"), term: None, multiplexer: None } 2025-12-18T07:07:57.991776Z INFO Detected terminal info terminal=TerminalInfo { name: AppleTerminal, term_program: Some("Apple_Terminal"), version: Some("455.1"), term: None, multiplexer: None } 2025-12-18T07:08:07.732095Z INFO Detected terminal info terminal=TerminalInfo { name: WarpTerminal, term_program: Some("WarpTerminal"), version: Some("v0.2025.12.10.08.12.stable_03"), term: None, multiplexer: None } 2025-12-18T07:08:24.860316Z INFO Detected terminal info terminal=TerminalInfo { name: Kitty, term_program: None, version: None, term: None, multiplexer: None } 2025-12-18T07:08:38.302761Z INFO Detected terminal info terminal=TerminalInfo { name: Alacritty, term_program: None, version: None, term: None, multiplexer: None } 2025-12-18T07:08:50.887748Z INFO Detected terminal info terminal=TerminalInfo { name: VsCode, term_program: Some("vscode"), version: Some("1.107.1"), term: None, multiplexer: None } 2025-12-18T07:10:01.309802Z INFO Detected terminal info terminal=TerminalInfo { name: WezTerm, term_program: Some("WezTerm"), version: Some("20240203-110809-5046fc22"), term: None, multiplexer: None } 2025-12-18T08:05:17.009271Z INFO Detected terminal info terminal=TerminalInfo { name: Ghostty, term_program: Some("ghostty"), version: Some("1.2.3"), term: None, multiplexer: None } 2025-12-18T08:05:23.819973Z INFO Detected terminal info terminal=TerminalInfo { name: Ghostty, term_program: Some("ghostty"), version: Some("1.2.3"), term: Some("xterm-ghostty"), multiplexer: Some(Tmux { version: Some("3.6a") }) } 2025-12-18T08:05:35.572853Z INFO Detected terminal info terminal=TerminalInfo { name: Ghostty, term_program: Some("ghostty"), version: Some("1.2.3"), term: None, multiplexer: Some(Zellij) } ``` ## Notes / Follow-ups - Next step is to wire `TerminalInfo` into TUI2’s scroll scaling configuration and add a per-terminal tuning table. - The log output in TUI2 helps validate real-world detection before applying behavior changes.Josh McKinney ·
2025-12-18 12:50:00 -08:00 -
Make loading malformed skills fail-open (#8243)
Instead of failing to start Codex, clearly call out that N skills did not load and provide warnings so that the user may fix them. <img width="3548" height="874" alt="image" src="https://github.com/user-attachments/assets/6ce041b2-1373-4007-a6dd-0194e58fafe4" />
Gav Verma ·
2025-12-17 23:41:04 -08:00 -
chore: cleanup Config instantiation codepaths (#8226)
This PR does various types of cleanup before I can proceed with more ambitious changes to config loading. First, I noticed duplicated code across these two methods: https://github.com/openai/codex/blob/774bd9e432fa2e0f4e059e97648cf92216912e19/codex-rs/core/src/config/mod.rs#L314-L324 https://github.com/openai/codex/blob/774bd9e432fa2e0f4e059e97648cf92216912e19/codex-rs/core/src/config/mod.rs#L334-L344 This has now been consolidated in `load_config_as_toml_with_cli_overrides()`. Further, I noticed that `Config::load_with_cli_overrides()` took two similar arguments: https://github.com/openai/codex/blob/774bd9e432fa2e0f4e059e97648cf92216912e19/codex-rs/core/src/config/mod.rs#L308-L311 The difference between `cli_overrides` and `overrides` was not immediately obvious to me. At first glance, it appears that one should be able to be expressed in terms of the other, but it turns out that some fields of `ConfigOverrides` (such as `cwd` and `codex_linux_sandbox_exe`) are, by design, not configurable via a `.toml` file or a command-line `--config` flag. That said, I discovered that many callers of `Config::load_with_cli_overrides()` were passing `ConfigOverrides::default()` for `overrides`, so I created two separate methods: - `Config::load_with_cli_overrides(cli_overrides: Vec<(String, TomlValue)>)` - `Config::load_with_cli_overrides_and_harness_overrides(cli_overrides: Vec<(String, TomlValue)>, harness_overrides: ConfigOverrides)` The latter has a long name, as it is _not_ what should be used in the common case, so the extra typing is designed to draw attention to this fact. I tried to update the existing callsites to use the shorter name, where possible. Further, in the cases where `ConfigOverrides` is used, usually only a limited subset of fields are actually set, so I updated the declarations to leverage `..Default::default()` where possible.
Michael Bolin ·
2025-12-17 18:01:17 -08:00 -
WIP: Rework TUI viewport, history printing, and selection/copy (#7601)
> large behavior change to how the TUI owns its viewport, history, and suspend behavior. > Core model is in place; a few items are still being polished before this is ready to merge. We've moved this over to a new tui2 crate from being directly on the tui crate. To enable use --enable tui2 (or the equivalent in your config.toml). See https://developers.openai.com/codex/local-config#feature-flags Note that this serves as a baseline for the changes that we're making to be applied rapidly. Tui2 may not track later changes in the main tui. It's experimental and may not be where we land on things. --- ## Summary This PR moves the Codex TUI off of “cooperating” with the terminal’s scrollback and onto a model where the in‑memory transcript is the single source of truth. The TUI now owns scrolling, selection, copy, and suspend/exit printing based on that transcript, and only writes to terminal scrollback in append‑only fashion on suspend/exit. It also fixes streaming wrapping so streamed responses reflow with the viewport, and introduces configuration to control whether we print history on suspend or only on exit. High‑level goals: - Ensure history is complete, ordered, and never silently dropped. - Print each logical history cell at most once into scrollback, even with resizes and suspends. - Make scrolling, selection, and copy match the visible transcript, not the terminal’s notion of scrollback. - Keep suspend/alt‑screen behavior predictable across terminals. --- ## Core Design Changes ### Transcript & viewport ownership - Treat the transcript as a list of **cells** (user prompts, agent messages, system/info rows, streaming segments). - On each frame: - Compute a **transcript region** as “full terminal frame minus the bottom input area”. - Flatten all cells into visual lines plus metadata (which cell + which line within that cell). - Use scroll state to choose which visual line is at the top of the region. - Clear that region and draw just the visible slice of lines. - The terminal’s scrollback is no longer part of the live layout algorithm; it is only ever written to when we decide to print history. ### User message styling - User prompts now render as clear blocks with: - A blank padding line above and below. - A full‑width background for every line in the block (including the prompt line itself). - The same block styling is used when we print history into scrollback, so the transcript looks consistent whether you are in the TUI or scrolling back after exit/suspend. --- ## Scrolling, Mouse, Selection, and Copy ### Scrolling - Scrolling is defined in terms of the flattened transcript lines: - Mouse wheel scrolls up/down by fixed line increments. - PgUp/PgDn/Home/End operate on the same scroll model. - The footer shows: - Whether you are “following live output” vs “scrolled up”. - Current scroll position (line / total). - When there is no history yet, the bottom pane is **pegged high** and gradually moves down as the transcript fills, matching the existing UX. ### Selection - Click‑and‑drag defines a **linear selection** over transcript line/column coordinates, not raw screen rows. - Selection is **content‑anchored**: - When you scroll, the selection moves with the underlying lines instead of sticking to a fixed Y position. - This holds both when scrolling manually and when new content streams in, as long as you are in “follow” mode. - The selection only covers the “transcript text” area: - Left gutter/prefix (bullets, markers) is intentionally excluded. - This keeps copy/paste cleaner and avoids including structural margin characters. ### Copy (`Ctrl+Y`) - Introduce a small clipboard abstraction (`ClipboardManager`‑style) and use a cross‑platform clipboard crate under the hood. - When `Ctrl+Y` is pressed and a non‑empty selection exists: - Re‑render the transcript region off‑screen using the same wrapping as the visible viewport. - Walk the selected line/column range over that buffer to reconstruct the exact text: - Includes spaces between words. - Preserves empty lines within the selection. - Send the resulting text to the system clipboard. - Show a short status message in the footer indicating success/failure. - Copy is **best‑effort**: - Clipboard failures (headless environment, sandbox, remote sessions) are handled gracefully via status messages; they do not crash the TUI. - Copy does *not* insert a new history entry; it only affects the status bar. --- ## Streaming and Wrapping ### Previous behavior Previously, streamed markdown: - Was wrapped at a fixed width **at commit time** inside the streaming collector. - Those wrapped `Line<'static>` values were then wrapped again at display time. - As a result, streamed paragraphs could not “un‑wrap” when the terminal width increased; they were permanently split according to the width at the start of the stream. ### New behavior This PR implements the first step from `codex-rs/tui/streaming_wrapping_design.md`: - Streaming collector is constructed **without** a fixed width for wrapping. - It still: - Buffers the full markdown source for the current stream. - Commits only at newline boundaries. - Emits logical lines as new content becomes available. - Agent message cells now wrap streamed content only at **display time**, based on the current viewport width, just like non‑streaming messages. - Consequences: - Streamed responses reflow correctly when the terminal is resized. - Animation steps are per logical line instead of per “pre‑wrapped” visual line; this makes some commits slightly larger but keeps the behavior simple and predictable. Streaming responses are still represented as a sequence of logical history entries (first line + continuations) and integrate with the same scrolling, selection, and printing model. --- ## Printing History on Suspend and Exit ### High‑water mark and append‑only scrollback - Introduce a **cell‑based high‑water mark** (`printed_history_cells`) on the transcript: - Represents “how many cells at the front of the transcript have already been printed”. - Completely independent of wrapped line counts or terminal geometry. - Whenever we print history (suspend or exit): - Take the suffix of `transcript_cells` beyond `printed_history_cells`. - Render just that suffix into styled lines at the **current** width. - Write those lines to stdout. - Advance `printed_history_cells` to cover all cells we just printed. - Older cells are never re‑rendered for scrollback. They stay in whatever wrapping they had when printed, which is acceptable as long as the logical content is present once. ### Suspend (`Ctrl+Z`) - On suspend: - Leave alt screen if active and restore normal terminal modes. - Render the not‑yet‑printed suffix of the transcript and append it to normal scrollback. - Advance the high‑water mark. - Suspend the process. - On resume (`fg`): - Re‑enter the TUI mode (alt screen + input modes). - Clear the viewport region and fully redraw from in‑memory transcript and state. This gives predictable behavior across terminals without trying to maintain scrollback live. ### Exit - On exit: - Render any remaining unprinted cells once and write them to stdout. - Add an extra blank line after the final Codex history cell before printing token usage, so the transcript and usage info are visually separated. - If you never suspended, exit prints the entire transcript exactly once. - If you suspended one or more times, exit prints only the cells appended after the last suspend. --- ## Configuration: Suspend Printing This PR also adds configuration to control **when** we print history: - New TUI config option to gate printing on suspend: - At minimum: - `print_on_suspend = true` – current behavior: print new history at each suspend *and* on exit. - `print_on_suspend = false` – only print on exit. - Default is tuned to preserve current behavior, but this can be revisited based on feedback. - The config is respected in the suspend path: - If disabled, suspend only restores terminal modes and stops rendering but does not print new history. - Exit still prints the full not‑yet‑printed suffix once. This keeps the core viewport logic agnostic to preference, while letting users who care about quiet scrollback opt out of suspend printing. --- ## Tradeoffs What we gain: - A single authoritative history model (the in‑memory transcript). - Deterministic viewport rendering independent of terminal quirks. - Suspend/exit flows that: - Print each logical history cell exactly once. - Work across resizes and different terminals. - Interact cleanly with alt screen and raw‑mode toggling. - Consistent, content‑anchored scrolling, selection, and copy. - Streaming messages that reflow correctly with the viewport width. What we accept: - Scrollback may contain older cells wrapped differently than newer ones. - Streaming responses appear in scrollback as a sequence of blocks corresponding to their streaming structure, not as a single retroactively reflowed paragraph. - We do not attempt to rewrite or reflow already‑printed scrollback. For deeper rationale and diagrams, see `docs/tui_viewport_and_history.md` and `codex-rs/tui/streaming_wrapping_design.md`. --- ## Still to Do Before This PR Is Ready These are scoped to this PR (not long‑term future work): - [ ] **Streaming wrapping polish** - Double‑check all streaming paths use display‑time wrapping only. - Ensure tests cover resizing after streaming has started. - [ ] **Suspend printing config** - Finalize config shape and default (keep existing behavior vs opt‑out). - Wire config through TUI startup and document it in the appropriate config docs. - [x] **Bottom pane positioning** - Ensure the bottom pane is pegged high when there’s no history and smoothly moves down as the transcript fills, matching the current behavior across startup and resume. - [x] **Transcript mouse scrolling** - Re‑enable wheel‑based transcript scrolling on top of the new scroll model. - Make sure mouse scroll does not get confused with “alternate scroll” modes from terminals. - [x] **Mouse selection vs streaming** - When selection is active, stop auto‑scrolling on streaming so the selection remains stable on the selected content. - Ensure that when streaming continues after selection is cleared, “follow latest output” mode resumes correctly. - [ ] **Auto‑scroll during drag** - While the user is dragging a selection, auto‑scroll when the cursor is at/near the top or bottom of the transcript viewport to allow selecting beyond the current visible window. - [ ] **Feature flag / rollout** - Investigate gating the new viewport/history behavior behind a feature flag for initial rollout, so we can fall back to the old behavior if needed during early testing. - [ ] **Before/after videos** - Capture short clips showing: - Scrolling (mouse + keys). - Selection and copy. - Streaming behavior under resize. - Suspend/resume and exit printing. - Use these to validate UX and share context in the PR discussion.
Josh McKinney ·
2025-12-15 17:20:53 -08:00 -
Sync tui2 with tui and keep dual-run glue (#7965)
- Copy latest tui sources into tui2 - Restore notifications, tests, and styles - Keep codex-tui interop conversions and snapshots The expected changes that are necessary to make this work are still in place: diff -ru codex-rs/tui codex-rs/tui2 --exclude='*.snap' --exclude='*.snap.new' ```diff diff -ru --ex codex-rs/tui/Cargo.toml codex-rs/tui2/Cargo.toml --- codex-rs/tui/Cargo.toml 2025-12-12 16:39:12 +++ codex-rs/tui2/Cargo.toml 2025-12-12 17:31:01 @@ -1,15 +1,15 @@ [package] -name = "codex-tui" +name = "codex-tui2" version.workspace = true edition.workspace = true license.workspace = true [[bin]] -name = "codex-tui" +name = "codex-tui2" path = "src/main.rs" [lib] -name = "codex_tui" +name = "codex_tui2" path = "src/lib.rs" [features] @@ -42,6 +42,7 @@ codex-login = { workspace = true } codex-protocol = { workspace = true } codex-utils-absolute-path = { workspace = true } +codex-tui = { workspace = true } color-eyre = { workspace = true } crossterm = { workspace = true, features = ["bracketed-paste", "event-stream"] } derive_more = { workspace = true, features = ["is_variant"] } diff -ru --ex codex-rs/tui/src/app.rs codex-rs/tui2/src/app.rs --- codex-rs/tui/src/app.rs 2025-12-12 16:39:05 +++ codex-rs/tui2/src/app.rs 2025-12-12 17:30:36 @@ -69,6 +69,16 @@ pub update_action: Option<UpdateAction>, } +impl From<AppExitInfo> for codex_tui::AppExitInfo { + fn from(info: AppExitInfo) -> Self { + codex_tui::AppExitInfo { + token_usage: info.token_usage, + conversation_id: info.conversation_id, + update_action: info.update_action.map(Into::into), + } + } +} + fn session_summary( token_usage: TokenUsage, conversation_id: Option<ConversationId>, Only in codex-rs/tui/src/bin: md-events.rs Only in codex-rs/tui2/src/bin: md-events2.rs diff -ru --ex codex-rs/tui/src/cli.rs codex-rs/tui2/src/cli.rs --- codex-rs/tui/src/cli.rs 2025-11-19 13:40:42 +++ codex-rs/tui2/src/cli.rs 2025-12-12 17:30:43 @@ -88,3 +88,28 @@ #[clap(skip)] pub config_overrides: CliConfigOverrides, } + +impl From<codex_tui::Cli> for Cli { + fn from(cli: codex_tui::Cli) -> Self { + Self { + prompt: cli.prompt, + images: cli.images, + resume_picker: cli.resume_picker, + resume_last: cli.resume_last, + resume_session_id: cli.resume_session_id, + resume_show_all: cli.resume_show_all, + model: cli.model, + oss: cli.oss, + oss_provider: cli.oss_provider, + config_profile: cli.config_profile, + sandbox_mode: cli.sandbox_mode, + approval_policy: cli.approval_policy, + full_auto: cli.full_auto, + dangerously_bypass_approvals_and_sandbox: cli.dangerously_bypass_approvals_and_sandbox, + cwd: cli.cwd, + web_search: cli.web_search, + add_dir: cli.add_dir, + config_overrides: cli.config_overrides, + } + } +} diff -ru --ex codex-rs/tui/src/main.rs codex-rs/tui2/src/main.rs --- codex-rs/tui/src/main.rs 2025-12-12 16:39:05 +++ codex-rs/tui2/src/main.rs 2025-12-12 16:39:06 @@ -1,8 +1,8 @@ use clap::Parser; use codex_arg0::arg0_dispatch_or_else; use codex_common::CliConfigOverrides; -use codex_tui::Cli; -use codex_tui::run_main; +use codex_tui2::Cli; +use codex_tui2::run_main; #[derive(Parser, Debug)] struct TopCli { diff -ru --ex codex-rs/tui/src/update_action.rs codex-rs/tui2/src/update_action.rs --- codex-rs/tui/src/update_action.rs 2025-11-19 11:11:47 +++ codex-rs/tui2/src/update_action.rs 2025-12-12 17:30:48 @@ -9,6 +9,20 @@ BrewUpgrade, } +impl From<UpdateAction> for codex_tui::update_action::UpdateAction { + fn from(action: UpdateAction) -> Self { + match action { + UpdateAction::NpmGlobalLatest => { + codex_tui::update_action::UpdateAction::NpmGlobalLatest + } + UpdateAction::BunGlobalLatest => { + codex_tui::update_action::UpdateAction::BunGlobalLatest + } + UpdateAction::BrewUpgrade => codex_tui::update_action::UpdateAction::BrewUpgrade, + } + } +} + impl UpdateAction { /// Returns the list of command-line arguments for invoking the update. pub fn command_args(self) -> (&'static str, &'static [&'static str]) { ```Josh McKinney ·
2025-12-12 20:46:18 -08:00 -
Anton Panasenko ·
2025-12-12 17:07:17 -08:00 -
feat(tui2): copy tui crate and normalize snapshots (#7833)
Introduce a full codex-tui source snapshot under the new codex-tui2 crate so viewport work can be replayed in isolation. This change copies the entire codex-rs/tui/src tree into codex-rs/tui2/src in one atomic step, rather than piecemeal, to keep future diffs vs the original viewport bookmark easy to reason about. The goal is for codex-tui2 to render identically to the existing TUI behind the `features.tui2` flag while we gradually port the viewport/history commits from the joshka/viewport bookmark onto this forked tree. While on this baseline change, we also ran the codex-tui2 snapshot test suite and accepted all insta snapshots for the new crate, so the snapshot files now use the codex-tui2 naming scheme and encode the unmodified legacy TUI behavior. This keeps later viewport commits focused on intentional behavior changes (and their snapshots) rather than on mechanical snapshot renames.
Josh McKinney ·
2025-12-10 22:53:46 +00:00 -
feat(tui2): add feature-flagged tui2 frontend (#7793)
Introduce a new codex-tui2 crate that re-exports the existing interactive TUI surface and delegates run_main directly to codex-tui. This keeps behavior identical while giving tui2 its own crate for future viewport work. Wire the codex CLI to select the frontend via the tui2 feature flag. When the merged CLI overrides include features.tui2=true (e.g. via --enable tui2), interactive runs are routed through codex_tui2::run_main; otherwise they continue to use the original codex_tui::run_main. Register Feature::Tui2 in the core feature registry and add the tui2 crate and dependency entries so the new frontend builds alongside the existing TUI. This is a stub that only wires up the feature flag for this. <img width="619" height="364" alt="image" src="https://github.com/user-attachments/assets/4893f030-932f-471e-a443-63fe6b5d8ed9" />
Josh McKinney ·
2025-12-09 16:23:53 -08:00