Skip to content

cli: Package terminal apps with nsh package --target tui - #4186

Merged
huacnlee merged 3 commits into
mainfrom
agent/T-12879-package-tui
Dec 3, 2026
Merged

huacnlee merged 3 commits into
mainfrom
agent/T-12879-package-tui

Conversation

@huacnlee

@huacnlee huacnlee commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Closes #4175.

nsh run --target tui runs an app with its Rust crates (such as Yoke's yoke/native module), but nsh package had no terminal target, so apps built and shipped the executable themselves. This adds nsh package --target tui.

What it makes

.nsh/out/<Name>/ for this machine's OS and processor, and the same as <Name>.tar.gz:

Counter/
  counter            # the terminal host, lower case as commands are typed (counter.exe on Windows)
  nsh/
    bundle.nshc      # the app's bytecode
    app.json         # id, name, version, dataDir/logDir, tui.pointsPerCell
    capabilities.json, assets/   # when the app has them
  • Host: an app with Rust crates (nsh.json "rust" or "root") gets its own terminal host, built optimized with its crates, the same host nsh run --target tui builds; a TSX app gets the prebuilt one from the tui component. A Rust app ("root") has no bundle and the host mounts its root.
  • nsh-tui-host: main_with_options checks for nsh/app.json next to the canonical executable, so a symlink in ~/.local/bin still works. When it finds one, it runs that package: it reads the bytecode as the app's own resource, as the Linux runner does, applies dataDir and tui.pointsPerCell, and passes the command line to the app instead of parsing host flags. Development hosts never have that directory beside them, so nsh run/nsh test behave as before. As with --bundle, an app error ends a packaged run.
  • --run runs the package in the current terminal. --sign is refused. No updater: the terminal host does not update itself.

Public API

nsh CLI:

  • nsh package --target tui: packages a terminal app (above). This is the only public addition: no new flag and no new nsh.json key. tui.pointsPerCell and dataDir are existing keys. Why it is needed: today a terminal app can only be shipped with a hand-made build of the host. nsh run --target tui already builds this host, and the other desktop targets already have packages. It follows the precedent of cargo-dist and of Ratatui/Bubbletea apps, which ship one executable plus resources per platform as a .tar.gz.

nsh-tui-host (Rust): no signature changes. Args gains a private, #[arg(skip)] field (Args is already #[non_exhaustive]).

Tests

  • cargo test -p nsh-tui-host --lib package: reads app.json (dataDir, pointsPerCell) and reports a package with neither a bundle nor a root.
  • package::tests::tui_packages_for_this_machine (nsh-cli): parses the target and checks its asset target and app.json.
  • On macOS arm64: nsh package examples/counter --target tui made Counter/counter and Counter.tar.gz. Running counter with no arguments in a pty (100×30) rendered nsh counter Current value 0 −1 +1, and it exited 0 on SIGTERM.
  • nsh package examples/rust-exports --target tui. This is a TSX app with a Rust crate, like Yoke. It built the app's terminal host in release mode, then made Rust Exports/rustexports (66 MB, unstripped) plus nsh/bundle.nshc and nsh/app.json. Running it in a pty rendered the Rust module's values (Ledger · a module Formatted at once: $1,234.50, Account · a class Savings: $120.00, Meter · a native component 25% of the budget spent), and it exited 0 on SIGTERM.

Not tested: Linux and Windows terminals. The code path is the same, and on Windows the executable gets .exe.

🤖 Noop (lead) · Opus 5.5 acting for @huacnlee

huacnlee and others added 2 commits December 3, 2026 15:27
The terminal host runs the bundle in an nsh directory next to its
executable, so the package is the host (the app's own, with its Rust
crates, or the prebuilt one) with the bundle beside it, as on Linux.

Closes #4175

Agent: lead
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@huacnlee

huacnlee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

✅ LGTM (direction approved by the owner): --target tui builds for the host OS, skips icons/signing, writes nsh/{bundle.nshc,app.json,capabilities.json,assets} plus a tarball (crates/nsh-cli/src/package.rs:2355-2455), and nsh-tui-host runs a sibling nsh/app.json package resolving symlinks (crates/nsh-tui-host/src/lib.rs:115-135). Docs updated in en and zh-CN. No new Rust public API; CI still pending.

Reviewed head: b399d63

🤖 Noop (reviewer) · AI agent acting for @huacnlee

@huacnlee

huacnlee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

✅ LGTM: implementation fits the approved --target tui direction.

package::next_to_executable (crates/nsh-tui-host/src/package.rs:371) follows symlinks, so a link in ~/.local/bin still finds nsh/app.json. args() reads only dataDir and tui.pointsPerCell and leaves the app's own command line alone. app() falls back to the Rust root and errors clearly when neither exists. is_dev excludes packaged runs (crates/nsh-tui-host/src/lib.rs:311); assets resolve from the package directory.
Nit: a malformed app.json is silently ignored (read_info returns None); a warning would help diagnose broken packages.

Diff-only review at 3654095.

🤖 Noop (reviewer) · AI agent acting for @huacnlee

@huacnlee
huacnlee merged commit 2dda2b7 into main Dec 3, 2026
11 of 29 checks passed
@huacnlee
huacnlee deleted the agent/T-12879-package-tui branch December 3, 2026 12:25
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.

Support standalone TUI executables with nsh package --target tui

1 participant