Skip to content

refactor: extract the ox-tui crate - #454

Merged
hakula139 merged 4 commits into
mainfrom
refactor/ox-tui-crate
Oct 20, 2026
Merged

hakula139 merged 4 commits into
mainfrom
refactor/ox-tui-crate

Conversation

@hakula139

@hakula139 hakula139 commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Summary

After #451, the terminal UI and slash commands still lived in the ox binary crate. As a result, ox depended on ratatui, crossterm, and the other TUI crates, and the ACP frontend planned in #150 would share a crate with the TUI internals. This PR moves tui, slash, the themes, and the TUI driver into the ox-tui library crate, leaving ox with main.rs, the CLI, and the REPL and headless drivers. The binary, its CLI and output, the release asset names, the Homebrew formula, and nix build .#oxide-code remain unchanged.

  • Crates: crates/ox-tui (crate ox_tui) holds tui's modules flattened into the crate root, so tui::app becomes ox_tui::app, along with slash, the five built-in themes in crates/ox-tui/themes, and the TUI driver, whose run and Startup now sit in lib.rs beside the module declarations from tui.rs. ox keeps main.rs, the CLI and live tests, and the driver module with the REPL and headless drivers and the exit status and shutdown signals that the TUI shares. ox-tui depends on ox-core, and ox depends on both.
  • Surface: ox uses run, Startup, slash::ResumePicker::at_startup, theme::{resolve_theme, ResolvedTheme, Theme}, the stdio drivers' glyphs::{task_marker, INTERRUPTED_MARKER}, and terminal::stdout_width. Only glyphs, slash, terminal, and theme are pub modules, and every other item stays crate-private. run keeps the signature from refactor(oxide-code): narrow the frontends' reach into core internals #438, with the theme as its own parameter. Moving the theme into Startup would keep Theme crate-private, but it would rewrite the setup at the start of run, which needs a real terminal and runs in no test. The version on the welcome screen and in /status now comes from ox-tui's CARGO_PKG_VERSION, which matches ox's because every crate inherits the workspace version.
  • Visibility: In a direct child of the crate root, super already names the crate root, so the flattened modules spell crate-wide items pub(crate) and import their siblings through crate::, as ox-core's top-level modules do, while nested modules keep super. rust.md now states the visibility rule. for_each_slot and SLOT_NAMES, which only theme's child loader uses, became private, and six helpers that only modules under slash or modal call became pub(super). NOTICE_DURATION and now are private in lib.rs, since only the crate's own modules use them. ox imports ox_tui:: items beside ox_core:: in the workspace crates group.
  • Dependencies: ox-tui takes ratatui, ratatui-textarea, crossterm, arboard, syntect, pulldown-cmark, open, base64, unicode-segmentation, unicode-width, and futures from ox. ox keeps indoc only for its tests and drops uuid and tokio's test-util feature, which only the TUI tests used. Because the --list width probe moved from ox's detect_terminal_width to ox_tui::terminal::stdout_width, ox no longer depends on crossterm. ox-tui needs no testing feature because no other crate uses its fixtures, so they stay in #[cfg(test)] modules.
  • Snapshots: The 58 TUI and slash baselines are renamed from the ox__tui__ and ox__slash__ prefixes to ox_tui__, and their source: headers point to the new paths, while the four headless driver baselines keep their names.
  • Tooling: CI, the release workflow, the Nix package, Codecov, cargo-about, cargo-deny, and cargo-mutants need no changes, as their commands are workspace-wide, package.nix already takes all of crates, the release workflow still generates the notices from crates/ox/Cargo.toml, and .cargo/mutants.toml already excludes every testing module.
  • Logs: TUI and slash events now use ox_tui::... targets in place of ox::tui::..., ox::slash::..., and ox::driver::tui. EnvFilter matches targets by prefix, so RUST_LOG=ox=debug still selects all three crates and ox_tui=debug selects only the TUI, while a module directive such as ox::tui::app=debug becomes ox_tui::app=debug. The log format is outside the stability surface.
  • Docs: The module map lists the 16 non-test ox-tui modules and lib.rs and states how the three crates depend on each other, the AGENTS.md layout adds crates/ox-tui, rust.md adds ox_tui:: to the workspace import group, testing.md follows the new crate and paths, and 109 source paths in the design docs and the theming guide point to crates/ox-tui, with their Sources lists re-sorted. The glyphs and terminal module docs now match their map rows.

Part of #149

Test plan

  • cargo fmt --all --check, cargo build (no warnings), cargo clippy --all-targets -- -D warnings, cargo clippy -- -D warnings, and cargo doc --no-deps passed.
  • cargo llvm-cov passed 3,123 unit tests (1,670 in ox-core, 1,396 in ox-tui, and 57 in ox), matching main's count, and 8 CLI tests, with 99.29% line coverage, equal to main. Per file, the uncovered lines match main's, except that main.rs has 4 fewer now that detect_terminal_width is gone and terminal.rs has 1 more in stdout_width's terminal branch. The cache hit in InputArea::visual_line_count is covered in some runs and not others.
  • cargo test -p ox-tui and cargo test -p ox on their own passed all 1,396 and 57 + 8 tests, so neither relies on features that another crate's dev-dependencies turn on.
  • cargo insta test --workspace --unreferenced=reject found no unreferenced snapshots and left no .snap.new files.
  • cargo check with -W unused-crate-dependencies found no unused dependency in -p ox-tui --lib or -p ox --bin ox.
  • cargo tree -p ox -e normal --depth 1 lists only anyhow, clap, ox-core, ox-tui, serde, serde_json, time, tokio, toml, and tracing.
  • cargo deny check licenses advisories sources bans passed. The lockfile diff only adds the ox-tui entry and moves dependencies from ox to it.
  • nix build .#oxide-code built bin/ox, ran the test suite, and passed its version check. The stripped release binary is 17,875,368 bytes, compared with 17,784,312 for main's build (+0.5%), and ox --help is byte-identical.
  • cargo-about 0.9.0 with the release workflow's command produces notices byte-identical to main's.
  • cargo install --git from this branch with --locked installed ox.
  • cargo mutants --workspace --list lists 6,175 mutants, compared with main's 6,176. The only difference is that the 4 mutants of detect_terminal_width became the 3 of stdout_width. A full mutation pass was not run.
  • In a scratch tmux server with isolated config and a mock Messages API, the debug and Nix-built binaries rendered the welcome screen in the configured latte theme, showed the notice for an unknown theme override, listed a session from a headless run in /resume, listed the commands in /help, and exited 0 on Ctrl+D. ox --list printed the same output as main's binary in a terminal and through a pipe.
  • pnpm format, pnpm lint, and pnpm spellcheck passed, and the pre-commit hooks ran on each commit.
  • The Release workflow's dry run on this PR built the archives on all three targets and passed the license file comparison and ox --version checks.

@hakula139 hakula139 added this to the v0.1.0 milestone Oct 20, 2026
@hakula139 hakula139 added refactor Behavior-preserving restructuring area: tui Touches terminal UI rendering, input, or theming area: slash Touches slash commands or their pickers area: engine Touches the engine, its protocol, or the drivers that run it labels Oct 20, 2026
@hakula139 hakula139 self-assigned this Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.38462% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/ox-tui/src/lib.rs 85.71% 1 Missing ⚠️
crates/ox-tui/src/terminal.rs 80.00% 1 Missing ⚠️
crates/ox/src/main.rs 66.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@hakula139
hakula139 force-pushed the refactor/ox-tui-crate branch from 0d8722d to bcc16b2 Compare October 20, 2026 11:55
The terminal UI and the slash commands lived in the `ox` binary crate, so
the binary linked ratatui, crossterm, and the other TUI-only crates, and
an ACP frontend in `ox` would share a crate with the TUI internals.

Move `tui` into the `ox-tui` library crate, flattened so `tui::app`
becomes `ox_tui::app`, together with `slash`, the themes, and the TUI
driver, which becomes `ox_tui::run` and `ox_tui::Startup`. `ox` keeps
`main.rs` and the REPL and headless drivers, and reaches the TUI only
through `run`, `Startup`, `slash::ResumePicker`, the theme resolver,
the two stdio glyphs, and `terminal::stdout_width`, which replaces the
`--list` width probe so `ox` no longer depends on crossterm.

The 58 TUI and slash snapshot baselines take the `ox_tui__` prefix, and
the design docs, the module map, and the conventions follow the new
paths.
Flattening `tui` into the crate root turned `pub(super)` in its direct
children from "within `tui`" into "within the crate", so those files
mixed two spellings of the same visibility. Spell it `pub(crate)` there,
as `ox-core`'s top-level modules do, keep `pub(super)` for items in
nested modules, where it is still narrower, and state the rule in
`rust.md`.
Flattening `tui` also made `super::` in its direct children name the
crate root, so six of them imported siblings through `super::` while
the rest of the crate, and every top-level module in `ox-core`, uses
`crate::`. Spell those imports and the one doc link `crate::`, as their
own test modules already do.
Only `theme`'s child `loader` uses `for_each_slot` and `SLOT_NAMES`, so
both become private. The `slash::testing` fixtures `stamped_id` and
`with_isolated_xdg`, the test-only `SlashOutcome::into_*` accessors, and
`LineEditor::with_placeholder` serve only modules under their parent, so
they become `pub(super)`.
@hakula139
hakula139 force-pushed the refactor/ox-tui-crate branch from bcc16b2 to e1d9198 Compare October 20, 2026 12:16
@hakula139
hakula139 merged commit d598164 into main Oct 20, 2026
18 checks passed
@hakula139
hakula139 deleted the refactor/ox-tui-crate branch October 20, 2026 12:24
hakula139 added a commit that referenced this pull request Oct 22, 2026
…rced ones

The bans that #451 and #454 dropped enforced "Only ox-tui depends on terminal UI
crates", so the sentence that explains their absence names that rule beside the
crate direction.
hakula139 added a commit that referenced this pull request Oct 22, 2026
#565)

## Summary

The architecture doc stated the crate dependency rules but not how they
are enforced, so the `cargo deny` wrapper bans that #451 removed came
back in #454 as an optional guard before they were dropped again. Both
versions banned terminal UI crates outside the frontend crate.

- **Dependency Direction:** `docs/design/architecture.md` now says the
crate manifests encode the crate direction and the terminal UI rule,
review of manifest changes enforces both, and `deny.toml` holds no
crate-layering bans.

## Test plan

- [x] `pnpm format`, `pnpm lint`, and `pnpm spellcheck` pass, and the
pre-commit hooks pass on the commit.
- [x] `deny.toml` on `main` has no `[[bans.deny]]` entries.
- [x] `cargo tree -p ox-core -e normal -i ratatui` and `-i crossterm`
match no package, and `ox` reaches both only through `ox-tui`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: engine Touches the engine, its protocol, or the drivers that run it area: slash Touches slash commands or their pickers area: tui Touches terminal UI rendering, input, or theming refactor Behavior-preserving restructuring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant