Skip to content

perf(termux): speed up tui cold start#29404

Closed
adybag14-cyber wants to merge 1 commit into
NousResearch:mainfrom
adybag14-cyber:perf/termux-cold-start
Closed

perf(termux): speed up tui cold start#29404
adybag14-cyber wants to merge 1 commit into
NousResearch:mainfrom
adybag14-cyber:perf/termux-cold-start

Conversation

@adybag14-cyber

@adybag14-cyber adybag14-cyber commented May 20, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Optimizes Hermes CLI/TUI cold start on Termux/Android without changing the default desktop startup path.

The main hot path is hermes --tui on low-power mobile CPUs. Before this change, the Python launcher always built the full CLI subparser tree, eagerly loaded the model catalog on Termux, and rebuilt the Ink TUI bundle on every launch. This PR gates the faster behavior to Termux:

  • obvious TUI launches use the lightweight top-level/chat parser before the full command tree is built
  • model catalog imports are deferred on Termux until model-selection handlers actually need them
  • fresh TUI bundles skip npm run build on Termux using source/config mtime freshness checks
  • desktop/CI launches retain the historical always-build behavior

Local Termux timing with this branch loaded through the installed Hermes venv:

  • python -m hermes_cli.main --version: about 0.28s after, about 0.96s before
  • _make_tui_argv(...) with a fresh installed TUI bundle: about 0.024s after, about 0.875s before

Related Issue

N/A

Type of Change

  • ðŸ�› Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • ðŸ“� Documentation update
  • ✅ Tests (adding or improving test coverage)
  • â™»ï¸� Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • hermes_cli/main.py
    • Adds an import-safe Termux startup detector shared by cold-start-sensitive paths.
    • Adds a Termux-only fast TUI launch path for unambiguous hermes --tui / hermes chat --tui invocations.
    • Defers model catalog imports on Termux while keeping eager import behavior on desktop/CI.
    • Adds TUI build input freshness checks and only skips rebuilds on Termux when dist/entry.js is fresh.
    • Adds migrate to _BUILTIN_SUBCOMMANDS to keep built-in command gating in sync with parser registration.
  • tests/hermes_cli/test_tui_npm_install.py
    • Covers TUI rebuild freshness and verifies build skipping is Termux-only.
  • tests/hermes_cli/test_tui_resume_flow.py
    • Covers the Termux-only fast TUI parser path and help/non-Termux fallbacks.

How to Test

  1. Syntax check:
    /data/data/com.termux/files/home/.hermes/hermes-agent/.venv/bin/python -m py_compile hermes_cli/main.py
  2. Focused TUI/startup tests:
    /data/data/com.termux/files/home/.hermes/hermes-agent/.venv/bin/python -m pytest -o addopts='' tests/hermes_cli/test_tui_npm_install.py tests/hermes_cli/test_tui_resume_flow.py::test_termux_fast_tui_launch_uses_light_parser tests/hermes_cli/test_tui_resume_flow.py::test_termux_fast_tui_launch_skips_help tests/hermes_cli/test_tui_resume_flow.py::test_fast_tui_launch_is_termux_only tests/hermes_cli/test_tui_resume_flow.py::test_main_top_level_tui_accepts_toolsets -q
  3. Startup gating regression tests:
    /data/data/com.termux/files/home/.hermes/hermes-agent/.venv/bin/python -m pytest -o addopts='' tests/hermes_cli/test_startup_plugin_gating.py -q
  4. Diff hygiene:
    git diff --check

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Termux on Android, Python 3.11.10, Node 24.15.0

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

N/A

Screenshots / Logs

Focused test output:

19 passed in 0.87s
37 passed in 1.10s

Timing output:

import hermes_cli.main: 0.152s
hermes_cli.main --version: 0.28s wall time
_make_tui_argv fresh TUI bundle: 0.024s

@alt-glitch alt-glitch added type/perf Performance improvement or optimization comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have labels May 20, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Merged via #29419 (rebase-merge → c29b4f5) with your authorship preserved in git log. Thanks for the Termux cold-start work — the model catalog deferral helps bare hermes startup too, and the TUI build-skip + fast-launch path cut visible esbuild overhead on --tui.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants