The interactive TUI should use Ink for terminal layout, borders, clipping, and input rendering instead of hand assembling fixed-width strings. The immediate user-visible fix is that the prompt box remains a stable box when the user types CJK text, emoji, or styled content.
@zcode/tui with an Ink component
tree.runTui() as the public CLI entrypoint.ZCODE_ environment variables.The renderer owns presentation only. Its input is a TuiScreen projection and a
small controller interface for user actions. It must not call model providers,
read session storage, or perform filesystem/network/subprocess I/O.
The transcript starts empty. Runtime readiness or startup sentinel messages are
diagnostics, not user-visible system messages; leaking them into the transcript
causes confusing rows such as System: OpenTUI Node runtime loaded. before the
user has done anything.
Sidebar API request rows preserve raw request data in session events, but their
visible labels should compact opaque UUID-like provider/request identifiers to
first8...last4 so long model request IDs do not dominate the URL and status.
Ink Box components own terminal borders and sizing. The prompt surface uses a
bounded multiline input area:
Box.Enter submits the prompt; Shift+Enter inserts an explicit newline.The renderer may rely on Ink's internal string-width, slice-ansi, Yoga
layout, and ink-text-input behavior for display-cell measurement. Any local
string truncation helper used outside Ink must operate on terminal display width,
not JavaScript code unit length.
Streaming model output can append many small text deltas. The TUI must avoid turning every delta into a full transcript reflow:
Text nodes during steady-state
streaming renders.These rules keep the renderer presentation-only while making long-running sessions viable when the transcript becomes large.
runTui() creates a mutable TuiScreen projection for the current interactive
session. Controller functions are the only code allowed to mutate it. After each
mutation, the controller asks the renderer to commit a new Ink render.
The controller interface exposes user intents rather than raw rendering details:
setInput(value)submitInput(value)handleKey(input, key)requestPermission(request, options)(挂载时经 registerPermissionRequester 登记一次,不随提交传递)stop(code)Permission and clarification prompts stay promise-based at the runtime boundary,
but their visible state is stored in the same TuiScreen.approvalQueue
projection. Closing the TUI rejects unresolved prompts.
The renderer must not depend on POSIX shell behavior or platform-specific path formats. Terminal differences are handled through Ink and Node stream capability checks:
Press Ctrl-C again to exit., and
the confirmed second press aborts active work before closing the UI.If a turn fails, the controller formats the error chain into an agent message and lets the renderer display it. The renderer should not catch or swallow application errors because it does not own recovery.
If Ink rendering throws during startup, runTui() must restore raw mode and
leave the alternate screen before returning or rethrowing at the CLI boundary.
The TUI test suite should cover:
runTui() API.