Files
orca/src/shared/hermes-startup-query.windows.test.ts
T
dcfa91919f fix(automations): deliver Hermes prompts via native query (#7862)
* fix(automations): deliver prompt to Hermes TUI via process-ready signal

Hermes's prompt_toolkit TUI never emits the DECSET 2004 bracketed-paste
handshake that the default draft-paste readiness waiter gates on, so the
automation prompt was silently dropped and the agent sat idle (terminal
opens, nothing entered). Add a 'process-ready' DraftPasteReadySignal that
arms the quiet-window on first PTY output and pastes once the TUI settles,
and assign it to the hermes agent config.

Adds a Hermes unit test covering the no-handshake path.

Design for the follow-up PR/issue review loop lives in
docs/design/pr-issue-review-loop.md (not committed; gitignored).

* fix(automations): skip broken process-name fallback for process-ready

CodeRabbit: the process-ready fallback consulted waitForAgentReady, which
compares the foreground process basename via isExpectedAgentProcess. Wrapped
interpreter launches surface as 'python3 .../hermes', so the check can never
confirm readiness and only drops the paste. process-ready readiness is the
PTY-quiet window (handled by waitForAgentDraftInputReady); the process-name
fallback is dead for this signal. Skip it and return false on timeout instead.

* test(automations): assert single paste for Hermes quiet-window path

Guard against a duplicate paste in the no-handshake Hermes path by
asserting sendRuntimePtyInputVerified is called exactly once. Addresses
the CodeRabbit nitpick on PR #7862.

* fix(automations): skip broken process-name fallback on pty-bound paste path

pasteDraftToAgentPtyWhenReady (quick-create/work-item route) still ran the
python3-vs-hermes process-name fallback that can never match for
process-ready agents, burning ~1s and dropping the paste. Mirror the
process-ready guard from pasteDraftWhenAgentReady and surface onTimeout.

Adds regression tests for both the quiet-window happy path and the
fallback-skip on the pty-bound path.

Co-authored-by: Orca <help@stably.ai>

* fix(automations): defer submit Enter until the Hermes TUI is interactive

Live-testing against Hermes v0.18.2 showed the fixed 50ms post-paste Enter
is swallowed: the node ui-tui takes 15s+ to boot, the paste fires ~1.5s in
(process-ready quiet window), and the cooked-mode line discipline turns the
early \r into \n, which the editor treats as newline-insert. The prompt
parked in the input box and the automation never executed.

For process-ready agents, defer the Enter until the TUI signals
interactivity (DECSET 2004 enable) or echoes the pasted content marker-free
(legacy prompt_toolkit), with a 120s best-effort cap. PTY input is FIFO, so
the deferred Enter always lands after the buffered paste text. The paste
echo of the content itself (raw or caret-notation markers adjacent) is
rejected so a cooked-mode echo can't release the Enter early.

Verified end-to-end in the dev app: automation prompt pasted, deferred
Enter released on tui-ready, Hermes submitted and ran the turn.

Co-authored-by: Orca <help@stably.ai>

* fix(automations): use Hermes native startup query

Co-authored-by: Orca <help@stably.ai>

* fix(automations): preserve quoted Hermes queries on Windows

* fix(agents): preserve invalid argument error message

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Brandon Bennett <brandonbennett@macbookair.myfiosgateway.com>
Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com>
2026-07-11 02:35:01 -07:00

53 lines
1.9 KiB
TypeScript

import { execFileSync } from 'node:child_process'
import { copyFileSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { expect, it } from 'vitest'
import { planHermesStartupQuery } from './hermes-startup-query'
const windowsIt = process.platform === 'win32' ? it : it.skip
windowsIt('preserves the startup query and spaced custom args in native Windows argv', () => {
const tempDir = mkdtempSync(join(tmpdir(), 'orca-hermes-startup-query-'))
const capturePath = join(tempDir, 'argv.json')
const hermesPath = join(tempDir, 'hermes.exe')
const prompt = [
'Return the marker with quoted="alpha beta" and unicode=雪🚀.',
'Keep %PATH% literal.',
'--version'
].join('\n')
try {
// Why: the Node executable is a real native Windows process, so this catches
// PowerShell argument marshalling bugs that generated-script assertions miss.
copyFileSync(process.execPath, hermesPath)
writeFileSync(
join(tempDir, 'chat'),
`require('node:fs').writeFileSync(${JSON.stringify(capturePath)}, JSON.stringify(process.argv.slice(2)))`
)
const plan = planHermesStartupQuery({
baseCommand: `"${hermesPath}"`,
agentArgs: '--yolo --source "Orca automation validation"',
prompt,
platform: 'win32',
shell: 'powershell'
})
const encodedCommand = plan?.command.match(/-EncodedCommand\s+(\S+)/)?.[1]
expect(encodedCommand).toBeDefined()
execFileSync('powershell.exe', ['-NoProfile', '-EncodedCommand', encodedCommand!], {
cwd: tempDir,
env: { ...process.env, ...plan?.env }
})
expect(JSON.parse(readFileSync(capturePath, 'utf8'))).toEqual([
`--query=${prompt}`,
'--yolo',
'--source',
'Orca automation validation',
'--tui'
])
} finally {
rmSync(tempDir, { recursive: true, force: true })
}
})