mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix: clean newline paste thingy
This commit is contained in:
parent
eec1db36f7
commit
0642b6cc53
3 changed files with 33 additions and 7 deletions
|
|
@ -29,6 +29,7 @@ import {
|
|||
isTransientTrailLine,
|
||||
pick,
|
||||
sameToolTrailGroup,
|
||||
stripTrailingPasteNewlines,
|
||||
toolTrailLabel
|
||||
} from './lib/text.js'
|
||||
import { DEFAULT_THEME, fromSkin, type Theme } from './theme.js'
|
||||
|
|
@ -784,14 +785,19 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||
void paste(true)
|
||||
}
|
||||
|
||||
if (!text) {
|
||||
const cleanedText = stripTrailingPasteNewlines(text)
|
||||
|
||||
if (!cleanedText) {
|
||||
return null
|
||||
}
|
||||
|
||||
const lineCount = text.split('\n').length
|
||||
const lineCount = cleanedText.split('\n').length
|
||||
|
||||
if (text.length < LARGE_PASTE.chars && lineCount < LARGE_PASTE.lines) {
|
||||
return { cursor: cursor + text.length, value: value.slice(0, cursor) + text + value.slice(cursor) }
|
||||
if (cleanedText.length < LARGE_PASTE.chars && lineCount < LARGE_PASTE.lines) {
|
||||
return {
|
||||
cursor: cursor + cleanedText.length,
|
||||
value: value.slice(0, cursor) + cleanedText + value.slice(cursor)
|
||||
}
|
||||
}
|
||||
|
||||
pasteCounterRef.current++
|
||||
|
|
@ -806,13 +812,13 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||
[
|
||||
...prev,
|
||||
{
|
||||
charCount: text.length,
|
||||
charCount: cleanedText.length,
|
||||
createdAt: Date.now(),
|
||||
id,
|
||||
kind: classifyPaste(text),
|
||||
kind: classifyPaste(cleanedText),
|
||||
lineCount,
|
||||
mode,
|
||||
text
|
||||
text: cleanedText
|
||||
}
|
||||
].slice(-24)
|
||||
)
|
||||
|
|
|
|||
18
ui-tui/src/lib/text.test.ts
Normal file
18
ui-tui/src/lib/text.test.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { stripTrailingPasteNewlines } from './text.js'
|
||||
|
||||
describe('stripTrailingPasteNewlines', () => {
|
||||
it('removes trailing newline runs from pasted text', () => {
|
||||
expect(stripTrailingPasteNewlines('alpha\n')).toBe('alpha')
|
||||
expect(stripTrailingPasteNewlines('alpha\nbeta\n\n')).toBe('alpha\nbeta')
|
||||
})
|
||||
|
||||
it('preserves interior newlines', () => {
|
||||
expect(stripTrailingPasteNewlines('alpha\nbeta\ngamma')).toBe('alpha\nbeta\ngamma')
|
||||
})
|
||||
|
||||
it('preserves newline-only pastes', () => {
|
||||
expect(stripTrailingPasteNewlines('\n\n')).toBe('\n\n')
|
||||
})
|
||||
})
|
||||
|
|
@ -49,6 +49,8 @@ export const thinkingPreview = (reasoning: string, mode: ThinkingMode, max: numb
|
|||
return !text || mode === 'collapsed' ? '' : mode === 'full' ? text : compactPreview(text, max)
|
||||
}
|
||||
|
||||
export const stripTrailingPasteNewlines = (text: string) => (/[^\n]/.test(text) ? text.replace(/\n+$/, '') : text)
|
||||
|
||||
export const toolTrailLabel = (name: string) =>
|
||||
name
|
||||
.split('_')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue