Skip to content

Add writebook tui - #14

Merged
monorkin merged 23 commits into
mainfrom
tui
Nov 25, 2026
Merged

monorkin merged 23 commits into
mainfrom
tui

Conversation

@monorkin

Copy link
Copy Markdown
Collaborator

Adds writebook tui, a terminal UI for browsing and editing books.

Screens

  • Instance picker: a rounded window over a starfield, ported from the ONCE installer. Ctrl+I opens it as an overlay from anywhere.
  • Books:
    • A gallery of covers with title, subtitle and author. The selected book gets a rounded border in its theme color, and a book without a cover shows a block in its theme color.
    • v switches to a list.
    • / searches all books, n makes a new book, s opens settings.
  • A book:
    • The cover, title, subtitle and author, then its pages as a gallery of previews with word counts, or as a list.
    • a adds a page, picture or section.
    • d deletes, m moves, p publishes (address, copy, QR code), e edits the book.
    • / searches the book.
  • A page:
    • Pages render their Markdown, including images.
    • Pictures and sections show centered.
    • ←/→ turns pages, and Ctrl+I opens the book's index.
  • Editor: e on a page. You write Markdown, which styles itself as you type, like hey-cli's composer.
    • Lists continue on Enter.
    • Ctrl+U uploads a file into the page.
    • Ctrl+S saves.
  • Book form: for new and edited books, laid out like the web's. It has the cover (picked with a file picker), title, subtitle, author, theme, and who can read and edit.
  • Settings: the invite link (copy, QR code, reset), and people's roles. Nobody can change their own role.
  • Profile: name and email, and your password. Changing the email or password asks for your current one.

Help sits at the bottom of every screen, in hey-cli's style, and ? toggles it. Every confirmation is a Yes/No choice. Ctrl+C asks before quitting, and a second Ctrl+C quits.

How it's built

  • Libraries: ratatui and crossterm draw the screens. ratatui-image draws images over kitty, sixel or iTerm2, with half blocks as the fallback in tmux and other multiplexers. pulldown-cmark renders pages, and qrcode draws the QR codes.
  • Network calls: all of them run on threads, so the screen never waits on the network.
  • Sign-ins: the TUI reuses the CLI's sign-ins and API client. creds::signed_in_token reports why renewing a sign-in failed rather than printing a note. writebook mcp now uses it too, so it no longer says "you're not signed in" when the server is down.

Needs basecamp/writebook#520 for the JSON it reads.

Tests cover the screens' keys and layout, the Markdown rendering and editor styling, the file picker, and search highlighting. writebook tui without a terminal stops with an error.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved defects can crash the TUI on resize, display stale search results or images from another instance, and hide selected entries or clip content.

15 open issues
What changed in this PR

Adds writebook tui, an interactive terminal interface for browsing and editing books that reuses the CLI’s sign-ins and API client.

Changes:

  • Adds book browsing, Markdown reading and editing, file selection, publishing, settings, and profile screens.
  • Adds terminal rendering dependencies, image support, contextual help, and UI tests.
  • Preserves highlighted search snippets and reports sign-in renewal failures to TUI and MCP callers.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
tests/​tui.rs Tests rejection of non-terminal execution.
src/​tui/​views.rs Draws galleries, lists, forms, and confirmation overlays.
src/​tui/​theme.rs Maps book themes to terminal colors.
src/​tui/​starfield.rs Animates the instance picker’s background.
src/​tui/​settings.rs Adds people and invitation management.
src/​tui/​search.rs Adds search input, results, and highlighting.
src/​tui/​reader.rs Displays pages, pictures, sections, and the index.
src/​tui/​profile.rs Adds profile and password editing.
src/​tui/​markdown.rs Renders styled Markdown and image rows.
src/​tui/​images.rs Loads, caches, and renders images.
src/​tui/​help.rs Formats contextual keyboard help.
src/​tui/​files.rs Adds file selection with image previews.
src/​tui/​editor.rs Adds Markdown editing, styling, and list continuation.
src/​tui/​edit.rs Adds book creation and settings forms.
src/​tui/​data.rs Connects TUI operations to existing authentication and APIs.
src/​read.rs Exposes search results and preserves highlighted snippets.
src/​mcp.rs Propagates sign-in renewal errors.
src/​main.rs Registers the tui command.
src/​creds.rs Adds token retrieval with explicit renewal errors.
skills/​writebook/​SKILL.md Documents that the TUI requires human interaction.
README.md Introduces the terminal UI command.
Cargo.toml Adds terminal, image, Markdown, and QR dependencies.
Cargo.lock Locks the added dependencies.

Review effort: Balanced

Comment thread src/tui/data.rs Resolved
Comment thread src/tui/editor.rs Resolved
Comment thread src/tui/editor.rs Resolved
Comment thread src/tui/images.rs Resolved
Comment thread src/tui/markdown.rs Resolved
Comment thread src/tui/search.rs Resolved
Comment thread src/tui/search.rs Resolved
Comment thread src/tui/settings.rs Resolved
Comment thread src/tui/views.rs Resolved
Comment thread src/tui/views.rs Resolved
Each screen and overlay now owns its state, keys, bindings, drawing and the
requests it starts; tui.rs keeps the event loop, message routing and global
keys. Background work goes through one spawn helper, the yes/no questions
are one confirmation overlay, search and the file picker share one large
window, and the "not signed in" error lives in one place.
…hat it does, and encode the clipboard with the base64 crate
…at instead of what's selected when it's answered

Copilot AI left a comment

Copy link
Copy Markdown

…other than what's open, and retry a failed search on enter
…ore ctrl and alt letters in fields, keep tab for the profile's fields, and continue a list only from after its marker
…r a line, keep every bullet of nested list items, and render tables a row to a line
…er a page's Markdown once per width instead of every frame
…ll the people, instances and index to the selected row, and keep the selected person on the list after a reload
… MB and decoded within limits, and fetch images from other sites without the token

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved issues can crash the TUI, apply asynchronous results to unrelated screens or instances, discard unsaved edits, and falsely mark changes as saved.

14 open issues
15 resolved since last review

Review effort: Balanced

Comment thread src/tui/markdown.rs Resolved
Comment thread src/tui/overlays.rs Resolved
Comment thread src/tui/screens.rs Resolved
Comment thread src/tui/screens.rs Resolved
Comment thread src/tui/screens.rs Resolved
Comment thread src/tui/publishing.rs Resolved
Comment thread src/tui/screens.rs Resolved
Comment thread src/tui/screens.rs Resolved
Comment thread src/tui/screens.rs Resolved
Comment thread src/tui/screens.rs Resolved
…nds, so the next paragraph doesn't look for its prefix
…each one gets when it's made

Replies found their target by what was open when they arrived, so a book
save, a deletion, a loaded page or a publishing change could land on another
book's screen, and replies for screens set aside under settings, an editor or
a page, or for an overlay under the quit question, were dropped. Now every
request carries the id of the screen or overlay it's for, and its reply goes
there wherever it is, or nowhere if it's gone.

A page gets a new id for each page turned to, saving waits for uploads into
the page to finish, and only the last invite reset shows its link.
@monorkin

Copy link
Copy Markdown
Collaborator Author

@copilot review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread src/tui/overlays.rs Resolved
Comment thread src/tui/data.rs Resolved
Comment thread src/tui/images.rs Resolved
Comment thread src/tui/markdown.rs Resolved
Comment thread src/tui/reader.rs Resolved
Comment thread src/tui/reader.rs Resolved
Comment thread src/tui/settings.rs Resolved
@monorkin

Copy link
Copy Markdown
Collaborator Author

@copilot review

Copilot AI commented Nov 25, 2026

Copy link
Copy Markdown

@copilot review

Pull request overview

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Findings

  • [P1] Publication changes can be undone: publishing.rs:72 permits closing while a request is pending. Reopening before it finishes uses the old visibility; editing the address can send that stale visibility and republish a book made private. Track or serialize saves across overlay instances.
  • [P1] Instance switching discards drafts: screens.rs:222-226 replaces the current screen without checking for unsaved book or profile edits, even when selecting the current instance. Confirm or preserve the draft.
  • [P1] Book saves overwrite concurrent changes: data.rs:352-360 sends every cached field and access list. If another client updates the book while this form is open, saving an unrelated field silently restores the old values, including permissions. Detect conflicts or avoid sending unchanged fields.
  • [P2] Concurrent invite resets can display an invalid link: settings.rs:67-80 assumes request order is server execution order. If the first request reaches the server last, it invalidates the displayed second link, but its response is discarded. Serialize resets or reload after all complete.
  • [P2] Reorders can be applied out of order: book.rs:160-170 allows another reorder while the first request is pending. A delayed first request can overwrite the later order. Serialize saves.
  • [P2] Uploads cross editing sessions: reader.rs:223-225 associates an upload with the page, not its editor. Discarding and reopening the editor before the upload finishes inserts the old attachment into the new draft. Track the editing session.
  • [P2] Inline images vanish in short viewports: reader.rs:325-330 draws images only when all 14 rows fit, so an image can never be seen in a shorter reading area. Scale or clip to the viewport.
  • [P2] Markdown links lose their destinations: markdown.rs:122 keeps only link styling. Readers cannot open or copy the target, including links generated for uploaded files. Preserve and expose the destination.
  • [P2] Image cache is unbounded: images.rs:97-103 retains every decoded image for the entire session, including all fetched covers. Large libraries can exhaust memory. Bound the cache and prioritize visible images.
  • [P2] Section content is truncated: reader.rs:382-387 allocates height from source lines rather than wrapped lines, and sections do not scroll. A long single-line section is cut off. Measure wrapped height and allow scrolling.

CI for this commit passed on Linux and Windows.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed to evaluate asynchronous state races that can crash the reader or cause revoked invite links to be shared.

No open issues 🎉

7 resolved since last review

Review effort: Balanced

@monorkin
monorkin merged commit e15f982 into main Nov 25, 2026
13 of 14 checks passed
@monorkin
monorkin deleted the tui branch November 25, 2026 19:28
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.

3 participants