mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-08 03:01:47 +00:00
refactor(tui): tighten editor handoff helpers
- editor.ts: collapse two private helpers into one flatMap-driven lookup, keep `isExecutable` as the only named primitive, document the fallback chain with prompt_toolkit parity - editor.test.ts: hoist the `exe` helper out of `describe`, drop the empty afterEach + dead mkdir branch, materialize expected paths before the resolveEditor call so argument evaluation order doesn't bite - useComposerState.openEditor: rmSync the mkdtemp dir (was leaking), early-return on bad exit / empty buffer, run cleanup in finally - useInputHandlers: cheap `ch.toLowerCase() === 'g'` guard before the modifier check - hermes-ink/screen.ts: pick up `npm run fix` import-sort cleanup so lint passes
This commit is contained in:
parent
7fd8dc0bfb
commit
83129e72de
5 changed files with 74 additions and 91 deletions
|
|
@ -255,27 +255,34 @@ export function useComposerState({
|
|||
)
|
||||
|
||||
const openEditor = useCallback(async () => {
|
||||
const editor = resolveEditor()
|
||||
const file = join(mkdtempSync(join(tmpdir(), 'hermes-')), 'prompt.md')
|
||||
let code: null | number = null
|
||||
const dir = mkdtempSync(join(tmpdir(), 'hermes-'))
|
||||
const file = join(dir, 'prompt.md')
|
||||
|
||||
writeFileSync(file, [...inputBuf, input].join('\n'))
|
||||
|
||||
let exitCode: null | number = null
|
||||
|
||||
await withInkSuspended(async () => {
|
||||
code = spawnSync(editor, [file], { stdio: 'inherit' }).status
|
||||
exitCode = spawnSync(resolveEditor(), [file], { stdio: 'inherit' }).status
|
||||
})
|
||||
|
||||
if (code === 0) {
|
||||
try {
|
||||
if (exitCode !== 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const text = readFileSync(file, 'utf8').trimEnd()
|
||||
|
||||
if (text) {
|
||||
setInput('')
|
||||
setInputBuf([])
|
||||
submitRef.current(text)
|
||||
if (!text) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
rmSync(file, { force: true })
|
||||
setInput('')
|
||||
setInputBuf([])
|
||||
submitRef.current(text)
|
||||
} finally {
|
||||
rmSync(dir, { force: true, recursive: true })
|
||||
}
|
||||
}, [input, inputBuf, submitRef])
|
||||
|
||||
const actions = useMemo(
|
||||
|
|
|
|||
|
|
@ -366,10 +366,9 @@ export function useInputHandlers(ctx: InputHandlerContext): InputHandlerResult {
|
|||
return voiceRecordToggle()
|
||||
}
|
||||
|
||||
// Alt+G is the escape hatch for terminals that swallow Ctrl+G — VSCode and
|
||||
// Cursor bind it to "Find Next" by default, so the keystroke never reaches
|
||||
// the embedded TUI. Alt+G arrives as `\x1bg` → meta+g across platforms.
|
||||
if (isAction(key, ch, 'g') || (key.meta && ch.toLowerCase() === 'g')) {
|
||||
// Ctrl+G, plus Alt+G fallback for VSCode/Cursor (they bind Ctrl+G to
|
||||
// "Find Next" before the TUI sees it; Alt+G arrives as meta+g).
|
||||
if (ch.toLowerCase() === 'g' && (isAction(key, ch, 'g') || key.meta)) {
|
||||
return cActions.openEditor()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue