mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-25 05:52:34 +00:00
fix(review): address Copilot follow-up on sanitizer and file decode errors
Consume multi-byte non-CSI ESC sequences during ANSI sanitization and handle UnicodeDecodeError for `hermes send --file` so review findings are resolved without regressions.
This commit is contained in:
parent
7e1788db5d
commit
a65f723e68
4 changed files with 24 additions and 1 deletions
|
|
@ -15,6 +15,7 @@ const ANSI_CSI_WITH_CMD_RE = new RegExp(`${ESC}\\[[0-?]*[ -/]*([@-~])`, 'g')
|
|||
const ANSI_INCOMPLETE_CSI_RE = new RegExp(`${ESC}\\[[0-?]*[ -/]*(?=${ESC}|\\n|$)`, 'g')
|
||||
const ANSI_OSC_RE = new RegExp(`${ESC}\\][\\s\\S]*?(?:${BEL}|${ESC}\\\\)`, 'g')
|
||||
const ANSI_STRING_RE = new RegExp(`${ESC}[PX^_][\\s\\S]*?(?:${BEL}|${ESC}\\\\)`, 'g')
|
||||
const ANSI_NON_CSI_ESC_SEQ_RE = new RegExp(`${ESC}(?!\\[|\\]|P|X|\\^|_)[ -/]*[0-~]`, 'g')
|
||||
const ANSI_STRAY_ESC_RE = new RegExp(`${ESC}(?!\\[)[\\s\\S]?`, 'g')
|
||||
const CONTROL_RE = /[\x00-\x08\x0B\x0C\x0D\x0E-\x1A\x1C-\x1F\x7F]/g
|
||||
const WS_RE = /\s+/g
|
||||
|
|
@ -26,6 +27,7 @@ export const stripAnsi = (s: string) =>
|
|||
.replace(ANSI_INCOMPLETE_CSI_RE, '')
|
||||
.replace(ANSI_CSI_RE, '')
|
||||
.replace(ANSI_INCOMPLETE_CSI_RE, '')
|
||||
.replace(ANSI_NON_CSI_ESC_SEQ_RE, '')
|
||||
.replace(ANSI_STRAY_ESC_RE, '')
|
||||
.replace(CONTROL_RE, '')
|
||||
|
||||
|
|
@ -36,6 +38,7 @@ export const sanitizeAnsiForRender = (s: string) =>
|
|||
.replace(ANSI_INCOMPLETE_CSI_RE, '')
|
||||
.replace(ANSI_CSI_WITH_CMD_RE, (seq, cmd: string) => (cmd === 'm' ? seq : ''))
|
||||
.replace(ANSI_INCOMPLETE_CSI_RE, '')
|
||||
.replace(ANSI_NON_CSI_ESC_SEQ_RE, '')
|
||||
.replace(ANSI_STRAY_ESC_RE, '')
|
||||
.replace(CONTROL_RE, '')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue