Skip to content

feat(tui): add exact code block copying - #71849

Open
B-A-M-N wants to merge 3 commits into
NousResearch:mainfrom
B-A-M-N:copyblox
Open

feat(tui): add exact code block copying#71849
B-A-M-N wants to merge 3 commits into
NousResearch:mainfrom
B-A-M-N:copyblox

Conversation

@B-A-M-N

@B-A-M-N B-A-M-N commented Jul 26, 2026

Copy link
Copy Markdown

"Addition of CopyBlocks

I got tired of manually formatting the code block commands Hermes writes. This feature preserves raw fenced content and gives exact-copy blocks in both TUI and CLI frontends.

What it does

TUI

  • Clickable copy controls on every fenced code block
  • Copies raw content between fences — no box-drawing, no decorations
  • /cc: single block copies immediately, multiple shows numbered list
  • Backward search through conversation history
  • Rejects malformed args like /cc 2abc
  • Excludes unclosed/streaming fences

CLI

  • /copy-code and /cc commands matching TUI behavior
  • Backward search, numbered list preview, whitespace-accurate clipboard

Testing

  • 1421 TUI tests pass, 32 Python tests pass, lint clean, typecheck clean"

Infrastructure acknowledgment

CopyBlox was independently designed and implemented. While completing and validating this contribution, I used model-inference access provided by [FreeInference.org](https://freeinference.org/), following my report of a caching issue affecting one of its Qwen deployments.

For clarity, FreeInference did not commission, direct, review, or pay me for this work. This is not a sponsored contribution or an endorsement by FreeInference, Nous Research, or the Hermes Agent project.

I am acknowledging FreeInference because access to capable inference infrastructure can enable meaningful open-source work by developers and researchers who do not have the hardware or budget to run these models themselves.

Organizations able to provide GPU capacity, hardware, cloud credits, research funding, or other infrastructure support should consider supporting the FreeInference project so that it can continue making these resources available for open-source development, research, and education.

@alt-glitch alt-glitch added type/feature New feature or request comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have labels Jul 26, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the exact-copy focus; current main still only copies whole assistant messages, so the feature is useful.

Problems

  • ui-tui/src/lib/copyText.ts:1 imports setClipboard from @hermes/ink, but the package runtime build entry, ui-tui/packages/hermes-ink/src/entry-exports.ts:1-38, does not export it. The PR changes index.d.ts only, so the type declaration and runtime export surface diverge.
  • ui-tui/src/components/copyblox.tsx:125 calls doCopy() for closed: false; an in-flight/unclosed fence remains copyable, contrary to the stated exclusion.
  • hermes_cli/cli_commands_mixin.py:2920 always uses OSC 52. Current /copy at hermes_cli/cli_commands_mixin.py:566-585 uses native platform clipboard backends locally and reserves OSC 52 for SSH/fallback, including Windows/WSL support in hermes_cli/clipboard.py:101-129.
  • ui-tui/src/components/markdown.tsx:829-834 intentionally removes existing recursive rendering for md/markdown fences (main lines 800-804). Clipboard extraction does not require that display regression.

Suggested changes

  • Export the clipboard API from the runtime entry and add a public-import test.
  • Disable copying until a fence closes, with an interaction test.
  • Reuse the established CLI native/remote clipboard policy.
  • Preserve nested Markdown fence rendering unless separately intended and tested.

Automated hermes-sweeper review.

Comment thread ui-tui/src/lib/copyText.ts
Comment thread ui-tui/src/components/copyblox.tsx Outdated
Comment thread hermes_cli/cli_commands_mixin.py Outdated
Comment thread ui-tui/src/components/markdown.tsx Outdated
@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 30, 2026
@B-A-M-N
B-A-M-N force-pushed the copyblox branch 2 times, most recently from fe119a4 to f3be544 Compare July 30, 2026 14:59
@B-A-M-N

B-A-M-N commented Jul 30, 2026

Copy link
Copy Markdown
Author

Rebased onto current main and addressed all review items in f3be5448a:

  • Exported setClipboard from the Ink runtime entry point, with a non-mocked public-import regression test.
  • Disabled copy interaction for unclosed/streaming fences; the test verifies no click handler is registered and copyText is not called.
  • Updated /copy-code to use the existing native clipboard policy locally, OSC 52 over SSH, and OSC 52 fallback when native copy fails; covered by CLI tests.
  • Restored recursive rendering for md/markdown fences with regression coverage.

Validation passed:

  • 174 focused TUI tests
  • TUI typecheck
  • 23 focused Python tests

@B-A-M-N

B-A-M-N commented Aug 13, 2026

Copy link
Copy Markdown
Author

Modified to co-incide and alleviate friction for PRs #71849 and #75783. CopyBlox stays the single frame, with width-safe labels, narrow fallback, matching virtual-height estimates.

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 sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants