Commit Graph

7 Commits

  • tui: queue follow-ups during manual /compact (#15259)
    ## Summary
    - queue input after the user submits `/compact` until that manual
    compact turn ends
    - mirror the same behavior in the app-server TUI
    - add regressions for input queued before compact starts and while it is
    running
    
    Co-authored-by: Codex <noreply@openai.com>
  • Add thread/shellCommand to app server API surface (#14988)
    This PR adds a new `thread/shellCommand` app server API so clients can
    implement `!` shell commands. These commands are executed within the
    sandbox, and the command text and output are visible to the model.
    
    The internal implementation mirrors the current TUI `!` behavior.
    - persist shell command execution as `CommandExecution` thread items,
    including source and formatted output metadata
    - bridge live and replayed app-server command execution events back into
    the existing `tui_app_server` exec rendering path
    
    This PR also wires `tui_app_server` to submit `!` commands through the
    new API.
  • feat(tui): restore composer history in app-server tui (#14945)
    ## Problem
    
    The app-server TUI (`tui_app_server`) lacked composer history support.
    Pressing Up/Down to recall previous prompts hit a stub that logged a
    warning and displayed "Not available in app-server TUI yet." New
    submissions were silently dropped from the shared history file, so
    nothing persisted for future sessions.
    
    ## Mental model
    
    Codex maintains a single, append-only history file
    (`$CODEX_HOME/history.jsonl`) shared across all TUI processes on the
    same machine. The legacy (in-process) TUI already reads/writes this file
    through `codex_core::message_history`. The app-server TUI delegates most
    operations to a separate process over RPC, but history is intentionally
    *not* an RPC concern — it's a client-local file.
    
    This PR makes the app-server TUI access the same history file directly,
    bypassing the app-server process entirely. The composer's Up/Down
    navigation and submit-time persistence now follow the same code paths as
    the legacy TUI, with the only difference being *where* the call is
    dispatched (locally in `App`, rather than inside `CodexThread`).
    
    The branch is rebuilt directly on top of `upstream/main`, so it keeps
    the
    existing app-server restore architecture intact.
    `AppServerStartedThread`
    still restores transcript history from the server `Thread` snapshot via
    `thread_snapshot_events`; this PR only adds composer-history support.
    
    ## Non-goals
    
    - Adding history support to the app-server protocol. History remains
    client-local.
    - Changing the on-disk format or location of `history.jsonl`.
    - Surfacing history I/O errors to the user (failures are logged and
    silently swallowed, matching the legacy TUI).
    
    ## Tradeoffs
    
    | Decision | Why | Risk |
    |----------|-----|------|
    | Widen `message_history` from `pub(crate)` to `pub` | Avoids
    duplicating file I/O logic; the module already has a clean, minimal API
    surface. | Other workspace crates can now call these functions — the
    contract is no longer crate-private. However, this is consistent with
    recent precedent: `590cfa617` exposed `mention_syntax` for TUI
    consumption, `752402c4f` exposed plugin APIs (`PluginsManager`), and
    `14fcb6645`/`edacbf7b6` widened internal core APIs for other crates.
    These were all narrow, intentional exposures of specific APIs — not
    broad "make internals public" moves. `1af2a37ad` even went the other
    direction, reducing broad re-exports to tighten boundaries. This change
    follows the same pattern: a small, deliberate API surface (3 functions)
    rather than a wholesale visibility change. |
    | Intercept `AddToHistory` / `GetHistoryEntryRequest` in `App` before
    RPC fallback | Keeps history ops out of the "unsupported op" error path
    without changing app-server protocol. | This now routes through a single
    `submit_thread_op` entry point, which is safer than the original
    duplicated dispatch. The remaining risk is organizational: future
    thread-op submission paths need to keep using that shared entry point. |
    | `session_configured_from_thread_response` is now `async` | Needs
    `await` on `history_metadata()` to populate real `history_log_id` /
    `history_entry_count`. | Adds an async file-stat + full-file newline
    scan to the session bootstrap path. The scan is bounded by
    `history.max_bytes` and matches the legacy TUI's cost profile, but
    startup latency still scales with file size. |
    
    ## Architecture
    
    ```
    User presses Up                     User submits a prompt
           │                                    │
           ▼                                    ▼
    ChatComposerHistory                 ChatWidget::do_submit_turn
      navigate_up()                       encode_history_mentions()
           │                                    │
           ▼                                    ▼
      AppEvent::CodexOp                  Op::AddToHistory { text }
      (GetHistoryEntryRequest)                  │
           │                                    ▼
           ▼                            App::try_handle_local_history_op
      App::try_handle_local_history_op    message_history::append_entry()
        spawn_blocking {                        │
          message_history::lookup()             ▼
        }                                $CODEX_HOME/history.jsonl
           │
           ▼
      AppEvent::ThreadEvent
      (GetHistoryEntryResponse)
           │
           ▼
      ChatComposerHistory::on_entry_response()
    ```
    
    ## Observability
    
    - `tracing::warn` on `append_entry` failure (includes thread ID).
    - `tracing::warn` on `spawn_blocking` lookup join error.
    - `tracing::warn` from `message_history` internals on file-open, lock,
    or parse failures.
    
    ## Tests
    
    - `chat_composer_history::tests::navigation_with_async_fetch` — verifies
    that Up emits `Op::GetHistoryEntryRequest` (was: checked for stub error
    cell).
    - `app::tests::history_lookup_response_is_routed_to_requesting_thread` —
    verifies multi-thread composer recall routes the lookup result back to
    the originating thread.
    -
    `app_server_session::tests::resume_response_relies_on_snapshot_replay_not_initial_messages`
    — verifies app-server session restore still uses the upstream
    thread-snapshot path.
    -
    `app_server_session::tests::session_configured_populates_history_metadata`
    — verifies bootstrap sets nonzero `history_log_id` /
    `history_entry_count` from the shared local history file.
  • fix(tui): restore remote resume and fork history (#14930)
    ## Problem
    
    When the TUI connects to a **remote** app-server (via WebSocket), resume
    and fork operations lost all conversation history.
    `AppServerStartedThread` carried only the `SessionConfigured` event, not
    the full `Thread` snapshot. After resume or fork, the chat transcript
    was empty — prior turns were silently discarded.
    
    A secondary issue: `primary_session_configured` was not cleared on
    reset, causing stale session state after reconnection.
    
    ## Approach: TUI-side only, zero app-server changes
    
    The app-server **already returns** the full `Thread` object (with
    populated `turns: Vec<Turn>`) in its `ThreadStartResponse`,
    `ThreadResumeResponse`, and `ThreadForkResponse`. The data was always
    there — the TUI was simply throwing it away. The old
    `AppServerStartedThread` struct only kept the `SessionConfiguredEvent`,
    discarding the rich turn history that the server had already provided.
    
    This PR fixes the problem entirely within `tui_app_server` (3 files
    changed, 0 changes to `app-server`, `app-server-protocol`, or any other
    crate). Rather than modifying the server to send history in a different
    format or adding a new endpoint, the fix preserves the existing `Thread`
    snapshot and replays it through the TUI's standard event pipeline —
    making restored sessions indistinguishable from live ones.
    
    ## Solution
    
    Add a **thread snapshot replay** path. When the server hands back a
    `Thread` object (on start, resume, or fork),
    `restore_started_app_server_thread` converts its historical turns into
    the same core `Event` sequence the TUI already processes for live
    interactions, then replays them into the event store so the chat widget
    renders them.
    
    Key changes:
    - **`AppServerStartedThread` now carries the full `Thread`** —
    `started_thread_from_{start,resume,fork}_response` clone the thread into
    the struct alongside the existing `SessionConfiguredEvent`.
    - **`thread_snapshot_events()`** walks the thread's turns and items,
    producing `TurnStarted` → `ItemCompleted`* →
    `TurnComplete`/`TurnAborted` event sequences that the TUI already knows
    how to render.
    - **`restore_started_app_server_thread()`** pushes the session event +
    history events into the thread channel's store, activates the channel,
    and replays the snapshot — used for initial startup, resume, and fork.
    - **`primary_session_configured` cleared on reset** to prevent stale
    session state after reconnection.
    
    ## Tradeoffs
    
    - **`Thread` is cloned into `AppServerStartedThread`**: The full thread
    snapshot (including all historical turns) is cloned at startup. For
    long-lived threads this could be large, but it's a one-time cost and
    avoids lifetime gymnastics with the response.
    
    ## Tests
    
    - `restore_started_app_server_thread_replays_remote_history` —
    end-to-end: constructs a `Thread` with one completed turn, restores it,
    and asserts user/agent messages appear in the transcript.
    - `bridges_thread_snapshot_turns_for_resume_restore` — unit: verifies
    `thread_snapshot_events` produces the correct event sequence for
    completed and interrupted turns.
    
    ## Test plan
    
    - [ ] Verify `cargo check -p codex-tui-app-server` passes
    - [ ] Verify `cargo test -p codex-tui-app-server` passes
    - [ ] Manual: connect to a remote app-server, resume an existing thread,
    confirm history renders in the chat widget
    - [ ] Manual: fork a thread via remote, confirm prior turns appear
  • Move TUI on top of app server (parallel code) (#14717)
    This PR replicates the `tui` code directory and creates a temporary
    parallel `tui_app_server` directory. It also implements a new feature
    flag `tui_app_server` to select between the two tui implementations.
    
    Once the new app-server-based TUI is stabilized, we'll delete the old
    `tui` directory and feature flag.