The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(hermes-ink): reuse one hasMultipleCodepoints and drop the pre-clear SGR reset
kshitijk4poorc502cd026d29
diff --git a/ui-tui/packages/hermes-ink/src/ink/log-update.test.ts b/ui-tui/packages/hermes-ink/src/ink/log-update.test.tsindex bb94df6000f..5aefad5979d 100644--- a/ui-tui/packages/hermes-ink/src/ink/log-update.test.ts+++ b/ui-tui/packages/hermes-ink/src/ink/log-update.test.ts@@ -90,6 +90,16 @@ describe('LogUpdate.render diff contract', () => {expect(stdoutOnly(diff)).toBe('b')expect(diff.some(part => part.type === 'cursorTo')).toBe(false)expect(diff.some(part => part.type === 'stdout' && part.content === ' ')).toBe(false)++ // A fresh multi-codepoint grapheme over an empty cell has nothing to clear.+ const fresh = mkScreen(4, 1)+ setCellAt(fresh, 0, 0, { char: 'ก\u0E31', styleId: stylePool.none, width: CellWidth.Narrow, hyperlink: undefined })+ fresh.damage = { x: 0, y: 0, width: 1, height: 1 }+ expect(+ log+ .render(mkFrame(mkScreen(4, 1), 4, 1), mkFrame(fresh, 4, 1), true, false)+ .filter(part => part.type === 'stdout' || part.type === 'cursorTo')+ ).toEqual([{ type: 'stdout', content: 'ก\u0E31' }])})it('emits only changed cells when most rows match', () => {diff --git a/ui-tui/packages/hermes-ink/src/ink/log-update.ts b/ui-tui/packages/hermes-ink/src/ink/log-update.tsindex 21996fc42a9..e4789da676d 100644--- a/ui-tui/packages/hermes-ink/src/ink/log-update.ts+++ b/ui-tui/packages/hermes-ink/src/ink/log-update.ts@@ -26,6 +26,7 @@ import {setScrollRegion} from './termio/csi.js'import { LINK_END, link as oscLink } from './termio/osc.js'+import { hasMultipleCodepoints } from './termio/parser.js'type State = {previousOutput: string@@ -363,14 +364,15 @@ export class LogUpdate {// unchanged.if (removed &&- !isEmptyCellAt(prev.screen, x, y) &&- removed.char !== added.char &&removed.width === CellWidth.Narrow &&added.width === CellWidth.Narrow &&- (hasMultipleCodePoints(removed.char) || hasMultipleCodePoints(added.char))+ removed.char !== added.char &&+ (hasMultipleCodepoints(removed.char) || hasMultipleCodepoints(added.char)) &&+ // An unwritten prev cell arrives as removed={' ', Narrow}; nothing to clear.+ !isEmptyCellAt(prev.screen, x, y)) {- currentStyleId = transitionStyle(screen.diff, stylePool, currentStyleId, stylePool.none)- currentHyperlink = transitionHyperlink(screen.diff, currentHyperlink, undefined)+ // No style/hyperlink reset: the glyph overwrites this space at once,+ // so resetting would only break SGR/OSC8 coalescing across the run.screen.diff.push({ type: 'stdout', content: ' ' })screen.diff.push({ type: 'cursorTo', col: screen.cursor.x + 1 })}@@ -746,17 +748,6 @@ function needsWidthCompensation(char: string): boolean {return false}-/** Whether a grapheme contains more than one Unicode code point. */-function hasMultipleCodePoints(char: string): boolean {- const first = char.codePointAt(0)-- if (first === undefined) {- return false- }-- return char.length > (first > 0xffff ? 2 : 1)-}-class VirtualScreen {// Public for direct mutation by writeCellWithStyleStr (avoids txn overhead).// File-private class — not exposed outside log-update.ts.diff --git a/ui-tui/packages/hermes-ink/src/ink/termio/parser.ts b/ui-tui/packages/hermes-ink/src/ink/termio/parser.tsindex 0f58d6f203c..5787d28e0b8 100644--- a/ui-tui/packages/hermes-ink/src/ink/termio/parser.ts+++ b/ui-tui/packages/hermes-ink/src/ink/termio/parser.ts@@ -52,18 +52,15 @@ function isEastAsianWide(codePoint: number): boolean {)}-function hasMultipleCodepoints(str: string): boolean {- let count = 0+/** Whether a string holds more than one Unicode code point (surrogate-aware, O(1)). */+export function hasMultipleCodepoints(str: string): boolean {+ const first = str.codePointAt(0)- for (const _ of str) {- count++-- if (count > 1) {- return true- }+ if (first === undefined) {+ return false}- return false+ return str.length > (first > 0xffff ? 2 : 1)}function graphemeWidth(grapheme: string): 1 | 2 {