Skip to content

feat(opentui): port the legacy TUI to OpenTUI - #2

Merged
CjLogic merged 26 commits into
mainfrom
crewcoder-opentui
Nov 21, 2026
Merged

CjLogic merged 26 commits into
mainfrom
crewcoder-opentui

Conversation

@CjLogic

@CjLogic CjLogic commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Ports the legacy crewcoder-tui feature set to crewcoder-opentui, the OpenTUI + React UI that the crewcoder umbrella launches. Shared runtime code (bridge, reducer, state, themes, tool renderers) moves into crewcoder-tui-core so both UIs use one copy. The legacy UI stays published and keeps working.

The full feature-by-feature record, including owner decisions, is in crewcoder-opentui/docs/PORT_LIST.md.

OpenTUI

  • Full-screen transcript (alternate screen, mouse on). Turns read as reasoning, then an "Agent work" box of live tools, then the reply. Tool output collapses past 12 lines (Ctrl+O). Edits show inline diffs with real line numbers (Ctrl+T hides them). Markdown replies. Status panels for jobs, validation, crews, goals, reviews, /why, and checkpoints.
  • Syntax highlighting with Tree-sitter for fenced code, diffs, and read output. Extra grammars are bundled locally, pinned and hashed, with no runtime downloads.
  • Composer: multi-line, prompt history, @ path suggestions, Ctrl+V clipboard images, image pixels inline (kitty/sixel/half-block).
  • Status line with usage and cost. Right sidebar (Ctrl+B): modified files, live crew agents, crew tasks, <cwd>:<git>.
  • Pickers and slash commands: every legacy slash command exists. Branching from /sessions.
  • Themes: slate (default), dark, light, and custom JSON shared with legacy. /theme previews live.
  • Live crews: /crew and /team stream through the bridge. Approvals are answered from the UI; review-mode crews used to auto-deny every gated tool, in legacy too. A crew can optionally run in tmux.
  • tmux support: a startup note lists missing tmux settings, and a copy never claims "Copied" when tmux dropped it.
  • Transcript search (Ctrl+F, /find). It jumps to the exact wrapped line, expanding collapsed output, and marks it.
  • Welcome logo pulse, reply throughput (tok/s), and the focus gate.
  • Audit ports: CrewCoder-mode plans and clarify questions drawn from their arguments (never collapsed), extension tool renderers, and the bare /goal preflight form.
  • Alerts wrap to their real width instead of cutting at the border.

Agent

  • Per-tool file_diff events from private workspace snapshots.
  • Reply throughput is timed without tool and approval waits (GenerationClock).
  • Crew commands attach the stdin control channel, so live approvals work.
  • New run-controls module.

tui-core

Shared theme loader, crew task reader, git labels, clipboard and image helpers, formatTokensPerSecond, and extension tool renderer matching. The reducer gains crew session ids, worker tagging, and stopCrew.

Behavior changes worth reviewing

  • Extension renderers: a renderer whose match sets no field now matches nothing. Legacy matched every tool, so one extension could redraw (and hide) all tool output. This affects both UIs.
  • Bare /goal opens the preflight form instead of a menu. status, list, and logs still work when typed, and the form points to them.
  • Sending a message clears the saved composer text immediately, so an overlay that opens in the same instant no longer restores the sent text as a draft.

Not in this PR

  • Live UI (contributes.liveUi[]) is skipped by owner decision; legacy keeps it.
  • Token budget handoff is still open: on budget exhaustion OpenTUI shows the error but offers no handoff to a new session.
  • Open question: whether an extension renderer may match tools it doesn't own (e.g. toolName: "bash"). It still can, as in legacy.

Test plan

  • npm run typecheck for crewcoder-opentui, crewcoder-tui, and crewcoder-agent
  • npm test -w @onpoint-dev-tools/crewcoder-opentui: 426 passed
  • npm test -w @onpoint-dev-tools/crewcoder-tui-core: 121 passed
  • npm test -w @onpoint-dev-tools/crewcoder-tui: 387 passed
  • Agent run-controls test passes. The full agent suite was not run in this session.
  • Real terminal checks in tmux with a fake agent (CREWCODER_BIN): logo pulse colors, search jump and marker, plan/clarify/renderer views, /goal form, wrapped tmux alert
  • Full agent test suite in CI
  • Manual run against a real provider: a CrewCoder-mode plan, a live crew with approvals, and a real /goal
  • Attached-client tmux check of focus events and clipboard

🤖 Generated with Claude Code

CjLogic and others added 26 commits November 16, 2026 17:24
Move the legacy TUI's UI-independent code (agent process bridge, event
parser, SSH remote quoting, Live UI protocol types, event reducer, state
modules, and the logo text) into the new @onpoint-dev-tools/crewcoder-tui-core
package. The legacy crewcoder-tui keeps working on top of it and stays
published separately.

Add @onpoint-dev-tools/crewcoder-opentui (React on OpenTUI 0.9.2, Node >=26.4):
- split-footer mode: settled transcript is written once, in order, into the
  terminal's native scrollback; streaming replies commit finished rows live
- centered welcome screen with the big wordmark (composer only on small
  windows), then a chat layout with the composer pinned to the bottom
- Gotham background across the whole window via OSC 11, restored on exit
- footer components vendored from termcn (MIT) with fixes, including removal
  of a global "y" key handler that approved tool calls while typing

Switch the crewcoder umbrella to crewcoder-opentui as an optionalDependency so
headless VPS and sandbox installs succeed without native binaries. A bare
crewcoder now explains how to continue when there is no terminal, the TUI is
not installed, or Node.js is too old.

Update release checks, the publish workflow order, CI (Node 26 job), and docs.
OpenTUI (crewcoder-opentui):
- Slash command palette built on the termcn OpenTUI command palette, with
  grouped fuzzy search, scrolling, current-value markers, and exact footer
  sizing (fixes clipped palette and wrong-item selection with groups).
- Every legacy picker: sessions, rewind, provider/model/effort, modes and
  workers, prompts, tool mode, profile, remove-dir, commands, skills,
  handoff. Picker commands also take a value directly (/effort high).
- Remaining legacy commands: branch, compact (+ preview summary editor and
  auto on/off), export, goal, reload, clear, thinking, identity, full-access,
  checkpoints, memory, remember, set-budget, add-dir, extensions, plugins,
  review-summary, why, task, teams, team, approve, deny, approve-plan,
  follow-up, help. /crew skipped; /sidebar and /file-changes deferred.
- Status, on/off, and text-output results show in a vendored termcn alert
  above the composer until the next key.
- Multi-line composer on <textarea>: Enter sends, Shift+Enter / Ctrl+J add
  a line, grows to 8 lines.
- Slate theme, top-first transcript on wide terminals, bottom-pinned on
  narrow ones, clickable approval buttons, no key-hint row.

Shared core (crewcoder-tui-core):
- Move provider defaults and CLI result parsers into state/provider-defaults
  and state/command-results; the legacy UI re-exports them unchanged.

Agent:
- Automatic checkpoints are opt-in: a missing checkpointsEnabled now means
  off in config normalization, both TUIs, and the docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Answer confirm, select, input, and declarative component requests from
  trusted extensions in a focused footer card; answers go back over the
  ui_response control channel. Esc cancels the question, not the run.
- Question text, option labels, and descriptions wrap; question-model.ts is
  the single source for rows and footer height; no extension/request ids shown.
- Vendor termcn select and confirm without global keyboard handlers; free
  text uses OpenTUI's native input.
- Keep the composer draft when a question or live compaction preview opens.
- Key hints read Enter/Esc/PgUp/PgDn.
- README: rewrite Not yet ported from the legacy audit; /crew, /sidebar,
  /file-changes deferred. Add docs/QUESTIONS.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Reasoning commits to native scrollback as termcn's thinking-block design:
  a bordered panel with a "▼ Reasoning" header and muted text. Ported to core
  renderables because scrollback is not React; always expanded, since
  committed rows cannot toggle and summaries must stay visible.
- Streaming reasoning holds back its last text row and bottom border; the
  footer tail continues the panel's left border and the spinner reads
  "Thinking".
- Block layout moves from ScrollbackWriter into per-kind BlockViews
  (scrollback-blocks.ts) that report their stable rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Assistant replies and reasoning render through OpenTUI's native
  MarkdownRenderable in slate markup.* styles: headings, emphasis, inline
  code, links, lists, quotes, content-width tables, and fenced code behind a
  rail. Chosen over termcn markdown, which is React-only (cannot render into
  scrollback) and lacks fenced code, numbered lists, and tables.
- Streaming commits only final rows: blocks the engine reports committed,
  plus all but the last row of an open paragraph or code block. A test checks
  that a chunk-streamed document commits exactly the rows of a one-shot render.
- Fenced code is plain accent text for now; async tree-sitter highlighting
  would land after rows are committed.
- Docs: SCROLLBACK block views and stable-row rules, TERMCN ported designs,
  README and AGENTS updates for the Reasoning panel and markdown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A turn reads as sections in event order, divided by a blank row:
  reasoning panel, then the agent's work, then the reply. Consecutive tool
  calls stack into one work section without spacer rows.
- Reasoning panel restyled to the owner's reference: amber border, bold
  "💭 Reasoning" header, foreground-colored markdown. The streaming footer
  tail uses the same amber rail.
- Tool calls render as icon + bold title sections: "📖 Read File" with the
  target on the next row, "± Edit File: path" inline, "💻 Run Command" with
  clamped output. Paths under the workspace are shown relative. Read, edit,
  and search output is hidden; failures always show their output.
- tool-presentation.ts maps CrewCoder, Claude Code, Codex, and MCP-prefixed
  tool names to one presentation, shared by scrollback (ToolView) and the
  footer's running tools.
- Docs: README, AGENTS, SCROLLBACK, TERMCN.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Emit a file_diff event before each mutating tool's tool_execution_end,
built from private before/after workspace snapshots, so UIs can show
exact diffs for every provider. Controlled by the fileDiffs config key
(default on).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Parse file_diff events and store the files on the matching running tool
block, and track their paths as changed files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Replace the native-scrollback writer with an alternate-screen
  scrollbox transcript: reasoning panel, dashed Agent work box with
  live tool rows, collapsible output (Ctrl+O).
- Show inline diffs for edit/write tools across CrewCoder, Claude, and
  Codex (file_diff events first, tool arguments as fallback), with real
  line numbers from diff-anchors and Ctrl+T to hide. Shell commands and
  deleted files never show a diff.
- /diff runs the external Hunk viewer on the real terminal.
- Use emoji icons only when the terminal reports Unicode widths and no
  multiplexer; otherwise single-cell icons so they never clip.
  CREWCODER_TUI_ICONS=emoji|text overrides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add readGitRepoName (the main repository's name, also from linked
worktrees and bare repos) and a gitRepo field on the shared TUI state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port more of the legacy UI (tracked in docs/PORT_LIST.md):
- Status line under the composer: access, mode or worker,
  provider/model (effort), the session as <repo> · <first prompt>
  instead of its raw id, and context usage with cost pinned right.
  Widths are measured in terminal cells (string-width, pinned to
  OpenTUI's version).
- Prompt history: Up/Down move between composer lines, then recall
  this session's sent messages and restore the draft.
- /repaint (/redraw): full redraw via a resize away and back, since
  OpenTUI ignores a same-size resize.
- /quit, and /ext.<id>.<command> through `crewcoder command run`
  with arguments after `--`.
- Focus gate: keys and pastes are ignored while the terminal is
  unfocused. CREWCODER_TUI_MOUSE=0 turns mouse reporting off.
- Port list records the owner decision to bundle extra Tree-sitter
  grammars rather than download them at runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Move the clipboard helpers (readClipboardImage, readClipboard,
  writeClipboard) from the legacy UI into tui-core state/clipboard so
  the OpenTUI UI can use them; the legacy module re-exports them.
- Move imagePathsFromText (image paths in typed or dropped text) into
  state/image-attachment.
- Fix re-attaching the same image file: every attach copies into the
  cache under a new random name, so comparing cache paths never
  matched. File attachments now record sourcePath, and both UIs check
  attachedSources() before copying.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tcuts

Port more of the legacy UI (tracked in docs/PORT_LIST.md):
- Tree-sitter highlighting for fenced code, inline diffs with real
  line numbers, and read output. Python, Bash, JSON, Rust, Go, YAML,
  CSS, and HTML grammars are bundled in grammars/ from each grammar's
  own npm package (wasm + its highlights.scm + LICENSE), pinned by
  version and SHA-256, registered from absolute local paths; no
  runtime downloads. scripts/update-grammars.mjs reproduces them.
  Adds 0.48 MB packed / 3.5 MB unpacked. Unknown languages and
  line-numbered read output stay plain (docs/SYNTAX.md).
- @ path suggestions under the composer: workspace walk ported from
  legacy, Up/Down/Enter/Tab/Esc, directories stay open for drill-in,
  off in remote mode. Textarea cursorOffset counts display cells, so
  text-offset.ts converts before slicing (docs/MENTIONS.md).
- Composer shortcuts: Ctrl+V attaches a clipboard image (else pastes
  clipboard text), image paths typed or dropped into a prompt attach
  on send, Ctrl+X clears them, Ctrl+P toggles the palette, Tab/Ctrl+I
  opens the modes picker. Images go to the agent as --image and show
  as IMAGE rows (docs/ATTACHMENTS.md). Ctrl+B waits for the sidebar.
- Mention state moves into mentions.ts to keep SessionController
  under the file size limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Move the crew task store reader out of the legacy TaskWidget into
  tui-core state/crew-tasks so the OpenTUI sidebar can use it:
  readCrewTaskSnapshot (async) and readCrewTaskSnapshotSync, plus
  tasksForSession, sessionDisplayNumbers, prioritizedTasks, taskLabel,
  and taskBlocked. Same store paths and CREWCODER_TASKS_ENABLED
  override as the agent. The legacy TaskWidget now only draws.
- Add readGitLabelAsync so a UI can refresh the branch/dirty label
  after a run without blocking on git status.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port more of the legacy UI (tracked in docs/PORT_LIST.md):
- Right sidebar (Ctrl+B, /sidebar on|off|status): modified files
  (/file-changes on|off|status hides the list, tracking continues),
  live crew agents, this session's crew tasks, and the anchored
  <cwd>:<git> footer. Rows come from the pure sidebar-model.ts, sized
  in terminal cells and wrapped, never truncated. Starts closed, hides
  below 60 columns, and the divider drags to resize (18-60 columns).
  Tasks are polled only while open; the git label refreshes after each
  run. A list that does not fit always keeps its "... N more" row
  (legacy dropped it when items filled the budget). docs/SIDEBAR.md.
- Remote target in state: --remote sets state.remoteTarget and the
  remote cwd, so the welcome screen and sidebar show <target>:<cwd>.
  Tasks and git are never read from the local disk for SSH workspaces.
- Branching from /sessions: Tab forks the highlighted session and
  opens the fork with its history and saved settings, so the screen
  and new messages both belong to the branch (legacy's b only switched
  the id and left the old conversation on screen). /branch <id> does
  the same by id or prefix. Branching, including bare /branch, is
  refused during a run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the legacy theme loader into tui-core (theme/crewcoder-theme) so both
UIs read the same built-in names and JSON files; the legacy theme module
only re-exports it and keeps Gotham as its default.

- Optional `syntax` and `markdown` blocks in theme files; every built-in
  carries full palettes. The legacy UI accepts them but does not use them yet.
- New built-in `slate` (the OpenTUI default) and an `extends` field to pick
  the base theme (default `dark`, so existing files behave as before).
- Named themes are found in $CREWCODER_HOME/themes, then in `extraDirs`.
- listThemeFiles lists theme files with the reason a file is unusable.
- Readable errors that name the file and the problem.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- --theme and CREWCODER_THEME, mapped from the shared theme tokens onto
  termcn tokens plus diff, syntax, and markdown colors (toAppTheme).
  Slate stays the default and keeps its previous colors.
- /theme lists built-ins, your themes, and shipped examples (unusable files
  with the reason); the highlighted theme previews live, Enter applies and
  saves it to $CREWCODER_HOME/opentui.json, Esc keeps the applied one.
  Startup order: --theme > CREWCODER_THEME > saved pick > slate; a saved
  pick that broke falls back to slate with a warning.
- Native syntax styles rebuild when the theme changes, so code, diffs, and
  replies already on screen recolor.
- Theme `markdown` colors style replies and markdown source (.md reads,
  diffs, markdown fences) through one markup map covering every capture
  the grammar emits.
- Read output is no longer concealed: a .md read shows its # and ** markers.
- Shipped example theme: examples/themes/ember.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
message_end.durationMs timed the whole modelClient.complete() call. Claude
Agent SDK and Codex run their own tool loop inside that call, so a turn
that ran `npm test` for a minute reported a few tok/s for a model that
streams at 80.

GenerationClock now times the call minus everything that is not the
provider producing output: provider-native tools (start to end, including
their diff snapshot), CrewCoder tools run through executeTool with their
approvals, requestQuestion waits, follow-up delivery, and usage pricing.
Time to first token and reasoning tokens still count. If a provider tool
never reports its end, durationMs is omitted instead of guessed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the reply throughput formatter from the legacy viewport into tui-core
state/usage so the OpenTUI UI uses the same format (one decimal below 100,
whole numbers above).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Sent and tool-result images draw inline through OpenTUI's native
  <image>: kitty graphics (kitty, Ghostty), sixel where reported, else
  half-block cells (always under tmux). Same size caps as legacy (80
  columns, 35% of the screen between 4 and 18 rows), following resizes.
  Kitty placements are cropped at the transcript edge and sit below text.
  CREWCODER_TUI_IMAGE_PROTOCOL=kitty|sixel|blocks|none|auto overrides;
  remote mode draws no pixels. Sources are file: URLs so a path is never
  fetched; an undecodable file keeps the caption with a note.
- CREW CODER shows the reply's generation speed (muted `42.3 tok/s`) once
  message_end reports it.
- Live UI (contributes.liveUi[]) is skipped by owner decision; legacy
  keeps it. Transcript search moves to the end of the port order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t search

Finishes the legacy -> OpenTUI port list (docs/PORT_LIST.md).

- Live crews: /crew and /team stream through the bridge with worker-labelled
  transcript, AGENTS roster, workers' tasks in the sidebar, and approvals
  answered from the UI (agent crew commands attach the stdin control channel).
  Optional second UI in tmux via an owner-only handoff file.
- tmux: startup note for missing settings, honest copy alerts.
- Status panels for background jobs, validation, crews, goals, review
  summaries, /why, and checkpoints (block-panels.ts).
- User messages draw a filled marker instead of a YOU row.
- Welcome logo pulses like legacy (accent at half brightness to glow,
  frozen after 3 idle minutes, steady under reduced motion).
- Transcript search: Ctrl+F or /find [text]. Jumps to the exact wrapped line
  through public OpenTUI renderables, expands collapsed output, marks the
  line, and shows the match line in the bar. No in-text highlight by owner
  decision.
- Sending a message clears the saved composer text right away, so an overlay
  opening in the same instant no longer restores the sent text as a draft.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wrapped alerts

Audit of legacy crewcoder-tui against OpenTUI found four gaps; three ported:

- CrewCoder-mode plan and clarify view: crewcoder_propose_plan reads as
  Requirements / Investigation / File changes / Plan / Acceptance criteria
  with the /approve-plan hint, never collapsed; crewcoder_clarify lists its
  questions. Transcript search sees the same text.
- Extension tool renderers: loaded with `crewcoder extension renderers --json`
  at startup and on /reload; matching tools draw from their template as
  markdown. Matching and templates moved to tui-core state/tool-renderers,
  shared with legacy. A renderer with an empty match now matches nothing
  (legacy matched every tool).
- Bare /goal opens the preflight form (objective, max turns, check model,
  timeout) prefilled from config.goals, as in legacy.

Token budget handoff stays open on the port list.

Alerts wrap title and body to their real width instead of cutting at the
border, keep indentation and hanging list items, and size the footer from the
wrapped rows; the body cap is 16 wrapped rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CI failed two status-line tests that passed locally: they expected the
provider from the developer's CREWCODER_PROVIDER=claude, while CI gets the
real default (codex-cli). A vitest setup file now gives every test file a
private CREWCODER_HOME and clears CREWCODER_* variables, as the agent's
test-home-setup does, and the two tests expect the real default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
codexCliStartFailure kept only the last three stderr lines. For a Node or
Rust crash those are the stack tail (`requireStack: []`, `}`, `Node.js v22`)
and the line naming the cause was dropped, so CI and users saw no reason.
Keep the first error line as well as the tail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e test)

- sdk-runtime: a caller's own modelClient (or the heuristic client) without
  an explicit provider ran in native tool mode, because providerId fell back
  to the env/config default (codex-cli). Native mode then dropped CrewCoder's
  read/write/edit/bash, so SDK embedders got "Tool not found: read". Such
  sessions now use CrewCoder tools; naming a provider keeps native mode.
  Documented in docs/SDK.md.
- codex-approval-question test: run the fake Codex CLI as an executable, like
  codex-cli-provider.test.ts. main's question flag passes `-c ...` before
  `app-server`, which `node <script>` read as its own --check option.
- opentui: wait on time, not 20 render passes, for the async image decode
  error, which timed out under CI load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CjLogic
CjLogic merged commit 001e7ed into main Nov 21, 2026
4 checks passed
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