hermes-agent/ui-tui/src/__tests__
Siddharth Balyan 7ba5df0d52
feat(billing): /credits command — balance + portal top-up handoff (#44776)
* feat(billing): /usage → portal top-up browser handoff

Add the terminal side of the billing slice (phase 2a): start a top-up by
throwing the user to the portal billing page with the top-up modal open. The
terminal does not confirm, poll, or track payment — checkout completes in the
browser and the next /usage shows the new balance.

- nous_account.py: parse organisation.slug/name from /api/oauth/account into
  NousPortalAccountInfo; add nous_portal_topup_url() building the org-pinned
  {base}/orgs/{slug}/billing?topup=open with a null-slug fallback to the legacy
  {base}/billing?topup=open (never /orgs/None/...).
- portal_cli.py: 'hermes portal topup' — fresh account fetch, identity line
  (Topping up as <email> / org <name>), browser open with printed-URL fallback,
  no-wait closing copy. No polling/confirmation (deferred to 2b).
- account_usage.py: the shared /usage credits block now links the org-pinned
  top-up URL (auto-opens the modal) + points to the command.

Depends on NAS #409 (organisation.slug/name + ?topup=open). Do not merge until
that is live on the target env; until then /api/oauth/account returns
organisation: { id } only and the URL falls back to legacy.

* feat(billing): /credits command for balance + top-up handoff

Replace the standalone `hermes portal topup` subcommand with an in-session
/credits slash command — a focused money surface (balance in, top-up out) that
works in the CLI, TUI, and every messaging platform from one registry entry.

- commands.py: register /credits (Info category). Slack is at its 50-slash cap,
  so /credits is routed via /hermes credits on Slack only (new
  _SLACK_VIA_HERMES_ONLY set) to avoid clamping a canonical command off the
  native list and breaking Telegram parity; native everywhere else.
- account_usage.py: build_credits_view() — one portal fetch → balance lines +
  identity line + org-pinned top-up URL + depleted flag, consumed by all
  surfaces. Reuses the same snapshot/URL builder as /usage so numbers match.
- cli.py: _show_credits() — balance block + identity line + 3-button panel
  (Open top-up / Copy link / Cancel) via the existing prompt_toolkit modal.
  ASK, never auto-launch; headless falls back to printing the URL.
- gateway/slash_commands.py: _handle_credits_command() — renders the block +
  tappable top-up URL + no-wait copy; works on button and plain-text platforms.
- /usage credits line now points to /credits.
- Retire `hermes portal topup` (portal_cli.py back to baseline); the engine
  (slug/name parse + nous_portal_topup_url) stays as the shared core.

No polling, no payment confirmation (billing phase 2a). Depends on NAS #409.

* fix(credits): /credits works in the TUI slash-worker (non-interactive)

In the TUI, /credits runs in the slash-worker subprocess where there is no
live prompt_toolkit app and stdin is the JSON-RPC pipe. _show_credits called
the 3-button modal unconditionally, which fell back to reading stdin →
exception → slash.exec rejected → the command produced no output (only the
pre-existing 'Credit access paused' banner showed).

- _show_credits: when self._app is None (TUI worker / piped / non-interactive),
  render the text variant — balance block + tappable top-up URL + no-wait line,
  same affordance as the messaging surfaces — and skip the modal entirely. The
  3-button panel still renders in the interactive CLI.
- Depleted banner copy: 'run /usage for balance' → 'run /credits to top up'
  now that /credits is the dedicated money surface (+ tests).
- Regression tests: _show_credits with self._app=None renders text and never
  invokes the modal; logged-out path.

* feat(tui): credits.view RPC for the /credits tappable top-up button

Add a credits.view JSON-RPC method returning the structured CreditsView
(logged_in, balance_lines, identity_line, topup_url, depleted) so the TUI can
render a clickable <Link> top-up button instead of plain text. Account-
independent (portal fetch gated on a logged-in Nous account), fail-open to
{logged_in: false} on any hiccup. Mirrors session.usage's credits-block pattern.

Frontend (TUI-local /credits command + Ink component) lands separately.

* feat(tui): /credits command with keyboard-driven top-up confirm

TUI-local /credits: fetches the structured balance via the credits.view RPC,
prints the balance + identity + top-up URL, then arms the EXISTING confirm
overlay (Enter = open top-up in browser via openExternalUrl, Esc = cancel).
Reuses ConfirmReq — no new overlay component/state/input handler. Headless
(openExternalUrl returns false) falls back to printing the URL.

- gatewayTypes.ts: CreditsViewResponse.
- commands/credits.ts: the command (mirrors /status's rpc+guarded pattern).
- registry.ts: register creditsCommands.
- test: balance+overlay armed, headless fallback, no-url, logged-out (4 cases).

Matches the CLI /credits 'Enter to open' affordance. Phase 2a: no polling.
2026-06-12 08:51:10 +00:00
..
activeSessionSwitcher.test.ts feat(tui): single /model command + unified Sessions overlay (#37112) 2026-06-01 22:28:36 -04:00
appChromeStatusRule.test.tsx feat(cli,tui): show time since last final agent response on the status bar (#44265) 2026-06-11 06:06:19 -07:00
appChromeStatusRuleDevCredits.test.tsx feat(credits): usage-aware credits — in-session notices, /usage view, dev readout (#40011) 2026-06-06 13:18:18 +05:30
approvalAction.test.ts fix(approval): carry allow_permanent to TUI + desktop approval prompts 2026-06-11 18:23:59 -05:00
asCommandDispatch.test.ts feat(tui): wire /rewind through command.dispatch + prefill payload (#21910) 2026-06-01 01:22:38 -07:00
blockLayout.test.ts fix(tui): clear selection on right-click copy + group transcript blocks 2026-06-02 22:03:38 -05:00
clipboard.test.ts fix(tui): use base64 encoding for PowerShell clipboard writes to preserve UTF-8 2026-05-30 01:40:44 -07:00
constants.test.ts test(tui): tighten redraw hotkey review follow-ups 2026-04-27 12:30:40 -05:00
createGatewayEventHandler.test.ts Merge pull request #44534 from NousResearch/bb/approval-allow-permanent 2026-06-11 18:49:58 -05:00
createSlashHandler.test.ts fix(model): require confirmation for expensive model selections 2026-06-10 00:24:06 -07:00
creditsCommand.test.ts feat(billing): /credits command — balance + portal top-up handoff (#44776) 2026-06-12 08:51:10 +00:00
cursorDriftRegression.test.ts review(tui): route cursorLayout through @hermes/ink wrapAnsi shim (Bun runtime parity) 2026-05-17 11:52:21 -05:00
details.test.ts fix(tui): apply details mode live 2026-04-26 13:34:33 -05:00
emoji.test.ts fix(tui): inject VS16 so text-default emoji render as color glyphs 2026-04-21 15:52:39 -05:00
externalLink.test.ts fix(tui): keep x status citation fallbacks link-like 2026-05-18 20:01:58 -07:00
forceTruecolor.test.ts fix(tui): harden Terminal.app render behavior 2026-05-16 22:51:51 -05:00
gatewayClient.test.ts fix(ui-tui): stabilize embedded dashboard chat gateway (#44528) 2026-06-11 19:47:53 -04:00
gatewayRecovery.test.ts fix(tui): auto-recover session on unexpected gateway death (+ persist lifecycle breadcrumbs) (#35893) 2026-05-31 10:36:57 -05:00
markdown.test.ts fix(tui): preserve dunder identifiers in markdown 2026-05-19 00:06:08 -07:00
mathUnicode.test.ts fix: account for latex 2026-04-28 21:20:43 -04:00
memoryMonitor.test.ts fix(tui): type execFileNoThrow stdio/ChildProcess and make memoryMonitor critical test heap-independent (#40612) 2026-06-07 18:23:42 -07:00
messageLine.test.ts fix(tui): delineate assistant responses from details (#31087) 2026-05-25 10:23:03 -05:00
messages.test.ts fix(tui): preserve prompt separator width (#19340) 2026-05-04 09:58:40 -07:00
orchestratorPromptSession.test.ts feat: add TUI session orchestrator 2026-05-26 20:51:59 -07:00
osc52.test.ts fix(tui): raise picker selection contrast with inverse + bold 2026-04-21 14:31:21 -05:00
parentLog.test.ts fix(tui): auto-recover session on unexpected gateway death (+ persist lifecycle breadcrumbs) (#35893) 2026-05-31 10:36:57 -05:00
paths.test.ts feat(tui): include session name in the terminal titlebar (#43188) 2026-06-10 11:24:01 +10:00
platform.test.ts fix(tui): respect voice.record_key config (supersedes #19028, #19339) (#19835) 2026-05-04 15:49:28 -07:00
precisionWheel.test.ts fix(tui): steady transcript scrollbar (#20917) 2026-05-06 14:50:31 -07:00
prompt.test.ts fix(tui): termux-gate composer rendering tweaks for Ink TUI 2026-05-21 19:08:38 -07:00
providers.test.ts chore(tui): /clean pass — inline one-off locals, tighten ConfirmPrompt 2026-04-19 07:55:38 -05:00
reasoning.test.ts fix(tui): anchor splitReasoning unclosed-tag regex to start of input (#29426) 2026-05-20 14:09:38 -05:00
rpc.test.ts fix(ui-tui): surface RPC errors and guard invalid gateway responses 2026-04-13 14:17:52 -05:00
scroll.test.ts fix(tui): refresh scroll height at cached bottom 2026-05-07 05:48:19 -07:00
slashParity.test.ts test(tui): regression test for /q alias resolving to queue (#31983) 2026-05-25 12:48:46 +00:00
spawnHistoryStore.test.ts fix(tui): handle timeout/error subagent statuses in /agents (#26687) 2026-05-15 20:19:02 -05:00
stateIsolation.test.ts fix(tui): isolate turn state from app render 2026-04-26 15:40:38 -05:00
statusBarTicker.test.ts feat(tui): segment turns with rule above non-first user msgs; trim ticker dead space (#21846) 2026-05-08 05:12:09 -07:00
statusRule.test.ts fix(tui): make busy status-bar reservation /indicator-style aware 2026-06-01 20:28:43 -05:00
streamingMarkdown.test.ts Merge remote-tracking branch 'origin/main' into fix/markdown 2026-04-28 22:01:02 -04:00
subagentTree.test.ts style(debug): add missing blank line between LogSnapshot and helpers 2026-04-22 16:34:05 -05:00
syntax.test.ts fix(tui): restore macOS copy behavior and theme polish (#17131) 2026-04-28 18:47:14 -05:00
terminalModes.test.ts fix(tui): install the process.on('exit') terminal-mode backstop (#42165) 2026-06-08 08:21:19 -07:00
terminalParity.test.ts fix(tui): restore macOS copy behavior and theme polish (#17131) 2026-04-28 18:47:14 -05:00
terminalSetup.test.ts style(tui): apply npm run fix 2026-04-28 22:18:26 -05:00
termux.test.ts fix(tui): termux-gate scrollback preservation, touch-friendly defaults 2026-05-19 12:49:23 -07:00
termuxComposerLayout.test.ts fix(tui): termux-gate composer rendering tweaks for Ink TUI 2026-05-21 19:08:38 -07:00
text.test.ts fix(tui): stop persisting full tool output in trail lines (silent OOM death) 2026-06-03 06:00:22 -07:00
textInputBurstInput.test.ts fix(tui): commit composer input bursts immediately (#31053) 2026-05-23 13:27:16 -05:00
textInputCursorSourceOfTruth.test.ts fix(tui): keep Ink displayCursor in sync with fast-echo writes so cursor stops drifting (#26717) 2026-05-16 00:28:12 -05:00
textInputFastEcho.test.ts fix(tui): termux-gate composer rendering tweaks for Ink TUI 2026-05-21 19:08:38 -07:00
textInputLineNav.test.ts fix(tui): up-arrow inside a multi-line buffer moves cursor, not history 2026-04-21 18:31:35 -05:00
textInputPassThrough.test.ts fix: preserve Ctrl+J newlines in Ghostty 2026-05-28 23:30:39 -07:00
textInputRightClick.test.ts fix(tui): right-click copies selection, only pastes when no selection 2026-05-10 16:06:33 -07:00
textInputWrap.test.ts review(tui): route cursorLayout through @hermes/ink wrapAnsi shim (Bun runtime parity) 2026-05-17 11:52:21 -05:00
theme.test.ts fix(tui): honor skin highlight colors (#20895) 2026-05-06 14:01:56 -07:00
turnControllerNotice.test.ts feat(billing): /credits command — balance + portal top-up handoff (#44776) 2026-06-12 08:51:10 +00:00
turnStore.test.ts chore(tui): remove dead branch cleanup code 2026-04-26 21:54:24 -05:00
useCompletion.test.ts fix(tui): complete absolute paths as paths 2026-05-04 16:14:40 -07:00
useComposerState.test.ts fix(tui): raise picker selection contrast with inverse + bold 2026-04-21 14:31:21 -05:00
useConfigSync.test.ts feat(tui): mouse_tracking DEC mode presets (salvage of #26681) (#30084) 2026-05-21 20:25:52 -05:00
useInputHandlers.test.ts fix(tui): allow transcript scroll + Esc during approval/clarify/confirm prompts (#26414) 2026-05-15 21:59:28 -05:00
useQueue.test.ts fix(tui): copilot review on #16707 — naming, label consistency, esc priority 2026-04-27 15:37:54 -05:00
useSessionLifecycle.test.ts feat: add TUI session orchestrator 2026-05-26 20:51:59 -07:00
useVirtualHistoryHeights.test.ts perf(tui): lazily seed virtual history heights (#16523) 2026-04-27 07:55:45 -07:00
viewport.test.ts fix(tui): stabilize sticky prompt tracking 2026-04-28 22:10:40 -05:00
viewportStore.test.ts fix(tui): steady transcript scrollbar (#20917) 2026-05-06 14:50:31 -07:00
virtualHeights.test.ts fix(tui): clear selection on right-click copy + group transcript blocks 2026-06-02 22:03:38 -05:00
virtualHistoryClamp.test.ts fix(tui): stabilize live progress rendering 2026-04-26 15:23:43 -05:00
virtualHistoryOffsetCache.test.ts fix(tui): preserve transcript tail across resizes 2026-05-23 17:37:42 -05:00
wheelAccel.test.ts chore(tui): /clean recent perf work — KISS/DRY pass 2026-04-26 20:38:47 -05:00