hermes - ✅(Solved) Fix [Bug]: Terminal ASCII tables misalign with mixed Chinese/ASCII content [2 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#17700Fetched 2026-04-30 06:45:58
View on GitHub
Comments
2
Participants
2
Timeline
8
Reactions
0
Author
Participants
Timeline (top)
labeled ×3commented ×2cross-referenced ×2referenced ×1

Root Cause

The code calculating column widths uses len(str) or similar, which counts code points rather than display cells. Python's unicodedata.east_asian_width() correctly identifies W (Wide) and F (Full-width) characters. A proper display width function should be:

import unicodedata

def display_width(s):
    return sum(2 if unicodedata.east_asian_width(c) in ('W', 'F') else 1 for c in str(s))

PR fix notes

PR #17721: fix: use display-aware column width for CJK model names

Description (problem / solution / changelog)

Summary

Terminal ASCII tables misalign when model names contain Chinese, Japanese, or Korean (CJK) characters because len() counts Unicode codepoints rather than terminal display cells. CJK characters occupy 2 cells in most terminal emulators.

Root Cause

hermes_cli/auth.py (_prompt_model_selection) and hermes_cli/hermes_cli/models.py (format_model_pricing_table) both compute the model name column width using len(), which underestimates the width of CJK characters by 50-100%.

Fix

Use unicodedata.east_asian_width() to compute display-aware character widths. Characters with East Asian Width property F (Fullwidth) or W (Wide) count as 2 cells; all others count as 1.

Changes:

  • hermes_cli/auth.py: Replace len(m) with display-width computation in the name_col calculation
  • hermes_cli/models.py: Replace len(r[0]) with the same computation

No new imports required — unicodedata is part of the Python standard library.

Verification

  • python3 -m py_compile hermes_cli/auth.py hermes_cli/models.py passes
  • ruff check hermes_cli/hermes_cli/models.py passes (E731 lambda warning resolved with def)
  • 570 CLI tests pass (tests/cli/)

Closes #17700

Changed files

  • hermes_cli/auth.py (modified, +5/-1)
  • hermes_cli/models.py (modified, +6/-1)

PR #17722: fix: align image picker columns for CJK text

Description (problem / solution / changelog)

Summary

  • add Unicode display-width helpers for terminal column padding
  • use display-cell widths in image generation model picker rows and headers
  • cover CJK/full-width metadata alignment with a regression test

Fixes #17700

Test Plan

  • python -m pytest tests/hermes_cli/test_image_gen_picker.py tests/hermes_cli/test_tools_config.py -q -o 'addopts='

Changed files

  • hermes_cli/text_width.py (added, +32/-0)
  • hermes_cli/tools_config.py (modified, +23/-16)
  • tests/hermes_cli/test_image_gen_picker.py (modified, +23/-0)

Code Example

rows = [
    ["Open-Generative-AI", "12.3k", "MIT", "聚合多模型 API,支持图片/音频生成"],
    ["Vicuna", "8.1k", "CC BY-NC-SA 4.0", "基于 LLaMA 的对话模型"],
]
# Columns visibly misalign due to Chinese chars counted as width=1 instead of 2

---

import unicodedata

def display_width(s):
    return sum(2 if unicodedata.east_asian_width(c) in ('W', 'F') else 1 for c in str(s))
RAW_BUFFERClick to expand / collapse

Bug Description

When rendering ASCII tables with mixed Chinese and ASCII characters, column alignment breaks. Chinese characters render at 2 columns wide in standard terminals (macOS Terminal, iTerm2) but are counted as 1 character width in the output, causing all subsequent columns to shift right.

Steps to Reproduce

  1. Use the execute_code tool (or any tool that renders ASCII tables)
  2. Generate a table containing both Chinese characters and ASCII text
  3. Observe misaligned columns in terminal output

Example Python code that produces misaligned output:

rows = [
    ["Open-Generative-AI", "12.3k", "MIT", "聚合多模型 API,支持图片/音频生成"],
    ["Vicuna", "8.1k", "CC BY-NC-SA 4.0", "基于 LLaMA 的对话模型"],
]
# Columns visibly misalign due to Chinese chars counted as width=1 instead of 2

Expected Behavior

Columns should be visually aligned in any terminal supporting Unicode East Asian Width. Chinese characters should occupy 2 columns in monospace rendering, matching how terminals actually display them.

Actual Behavior

Columns shift right by 1 character for every Chinese character encountered, because the code counts each character as width 1 regardless of its actual display width.

Affected Component

  • Tools (terminal, file ops, web, code execution, etc.)

Debug Report

Report https://paste.rs/E6fHo agent.log https://paste.rs/sZRZp gateway.log https://paste.rs/0sBT8

Operating System

macOS (Hermes Agent v0.11.0)

Hermes Version

v0.11.0

Root Cause Analysis

The code calculating column widths uses len(str) or similar, which counts code points rather than display cells. Python's unicodedata.east_asian_width() correctly identifies W (Wide) and F (Full-width) characters. A proper display width function should be:

import unicodedata

def display_width(s):
    return sum(2 if unicodedata.east_asian_width(c) in ('W', 'F') else 1 for c in str(s))

Proposed Fix

Add a terminal-ascii-table skill or shared utility that uses unicodedata.east_asian_width() to calculate proper display width, and update any table-rendering code to use it instead of len().

extent analysis

TL;DR

Update the column width calculation to account for the display width of Unicode characters, particularly Chinese characters that occupy two columns.

Guidance

  • Use the unicodedata.east_asian_width() function to determine the display width of each character, as shown in the proposed display_width function.
  • Replace len(str) with the display_width function in the table-rendering code to accurately calculate column widths.
  • Consider adding a terminal-ascii-table utility to centralize this functionality and make it reusable across the codebase.
  • Verify the fix by rendering tables with mixed Chinese and ASCII characters and checking that the columns are properly aligned.

Example

import unicodedata

def display_width(s):
    return sum(2 if unicodedata.east_asian_width(c) in ('W', 'F') else 1 for c in str(s))

# Example usage:
rows = [
    ["Open-Generative-AI", "12.3k", "MIT", "聚合多模型 API,支持图片/音频生成"],
    ["Vicuna", "8.1k", "CC BY-NC-SA 4.0", "基于 LLaMA 的对话模型"],
]
for row in rows:
    print(' | '.join(word.ljust(display_width(word)) for word in row))

Notes

This solution assumes that the unicodedata module is available and that the east_asian_width function accurately reports the display width of characters. Additionally, this fix may need to be adapted to accommodate other types of characters that have non-standard display widths.

Recommendation

Apply the proposed fix by updating the table-rendering code to use the display_width function, as this will accurately account for the display width of Unicode characters and fix the column alignment issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING