mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-26 06:01:49 +00:00
fix(tui): harden terminal dimming and multiplexer copy (#14906)
- disable ANSI dim on VTE terminals by default so dark-background reasoning and accents stay readable - suppress local multiplexer OSC52 echo while preserving remote passthrough and add regression coverage
This commit is contained in:
parent
51f4c9827f
commit
acdcb167fb
4 changed files with 85 additions and 6 deletions
|
|
@ -11,6 +11,8 @@ import { BEL, ESC, ESC_TYPE, SEP } from './ansi.js'
|
|||
import type { Action, Color, TabStatusAction } from './types.js'
|
||||
|
||||
export const OSC_PREFIX = ESC + String.fromCharCode(ESC_TYPE.OSC)
|
||||
const ENV_ON_RE = /^(?:1|true|yes|on)$/i
|
||||
const ENV_OFF_RE = /^(?:0|false|no|off)$/i
|
||||
|
||||
/** String Terminator (ESC \) - alternative to BEL for terminating OSC */
|
||||
export const ST = ESC + '\\'
|
||||
|
|
@ -81,6 +83,20 @@ export function getClipboardPath(): ClipboardPath {
|
|||
return 'osc52'
|
||||
}
|
||||
|
||||
export function shouldEmitClipboardSequence(env: NodeJS.ProcessEnv = process.env): boolean {
|
||||
const override = (env.HERMES_TUI_CLIPBOARD_OSC52 ?? env.HERMES_TUI_COPY_OSC52 ?? '').trim()
|
||||
|
||||
if (ENV_ON_RE.test(override)) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (ENV_OFF_RE.test(override)) {
|
||||
return false
|
||||
}
|
||||
|
||||
return !!env['SSH_CONNECTION'] || (!env['TMUX'] && !env['STY'])
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a payload in tmux's DCS passthrough: ESC P tmux ; <payload> ESC \
|
||||
* tmux forwards the payload to the outer terminal, bypassing its own parser.
|
||||
|
|
@ -152,6 +168,7 @@ export async function tmuxLoadBuffer(text: string): Promise<boolean> {
|
|||
export async function setClipboard(text: string): Promise<string> {
|
||||
const b64 = Buffer.from(text, 'utf8').toString('base64')
|
||||
const raw = osc(OSC.CLIPBOARD, 'c', b64)
|
||||
const emitSequence = shouldEmitClipboardSequence(process.env)
|
||||
|
||||
// Native safety net — fire FIRST, before the tmux await, so a quick
|
||||
// focus-switch after selecting doesn't race pbcopy. Previously this ran
|
||||
|
|
@ -170,10 +187,10 @@ export async function setClipboard(text: string): Promise<string> {
|
|||
// Inner OSC uses BEL directly (not osc()) — ST's ESC would need doubling
|
||||
// too, and BEL works everywhere for OSC 52.
|
||||
if (tmuxBufferLoaded) {
|
||||
return tmuxPassthrough(`${ESC}]52;c;${b64}${BEL}`)
|
||||
return emitSequence ? tmuxPassthrough(`${ESC}]52;c;${b64}${BEL}`) : ''
|
||||
}
|
||||
|
||||
return raw
|
||||
return emitSequence ? raw : ''
|
||||
}
|
||||
|
||||
// Linux clipboard tool: undefined = not yet probed, null = none available.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue