mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 04:11:35 +00:00
* refactor(desktop): split clarify-tool.tsx into a clarify/ folder
Pure moves, no behaviour change. Parsing, the question-card core
(shell, choice rows, question block), the delivery watchdog, and each
pending/settled card get their own file so the core can be reused.
* feat(clarify): one questions[] shape with per-question status and one outcome
The clarify tool now takes only questions=[{question, choices?, multi_select?}].
A wrong shape is a tool error that names the right one, so a model that
sends the old top-level question/choices corrects itself on the next call.
Every result has the same shape on every surface: each response carries
status (answered, skipped, unanswered) with user_response null unless
answered, and the result carries one outcome (submitted, cancelled,
timed_out, undelivered) plus an optional surface-written notice. The
timeout and cancel sentences that used to pose as the user's answer are
gone, and the compressor reads status instead of matching their prefixes.
The callback contract is callback(questions) -> {answers, outcome, notice?}
(None = skipped, missing qid = unanswered). tui_gateway settles a batch the
same way for the last lock, a cancel, an interrupt and the deadline, and
clarify.lock keeps a null answer as a skip. A multi-select answer that is
not a JSON array counts as one typed ("Other") answer. The tool-row preview
reads the first question.
* feat(clarify): every surface asks through the one question card
CLI: the batch panel is the only panel; Enter on an empty field skips a
question, Ctrl+C cancels and keeps the locked answers, the deadline returns
timed_out. -q and -z return undelivered with a no-user notice.
Ink TUI: the single-question prompt is gone; the card supports multi-select
(Space or a digit toggles, Enter locks, typed Other text joins the picks),
an empty submit skips, Esc cancels, and "Batch" names are dropped.
Desktop: the single-question card is deleted and its keyboard handling moved
into the one card (arrows, letters and digits, auto-advance, Enter picks then
confirms). Confirm enables at one answer; blank questions lock null; Skip and
a composer message cancel; the settled card shows No answer for unanswered
questions. The bots room card follows the same contract.
Messaging: one card per question with a "Reply skip to skip" line in every
locale; timeouts and delivery failures map to timed_out and undelivered.
* fix(clarify): cancelled for a released messaging card, labels win over the skip word
A prose reply to a messaging choice card, /new and session end released
the wait with "", which read as timed_out. They now resolve with a
CANCELLED marker and the tool gets outcome cancelled.
A typed reply that matches a choice label ("Skip") now resolves to that
choice; the skip word applies only when no choice matches.
The bots room card sends the picked labels as they are; the tool already
strips the recommendation label. Unused OUTCOMES and a new docstring and
comment are removed.
* fix(tui): re-editing a multi-select answer keeps its picks
The Ink card stored a multi-select answer as display text ("A, B"), so
revisiting the question put the whole string into Other and re-locked it
as one item. The answers map now keeps the raw JSON array, the card
restores the picks on revisit, and only the display lines format it.
Comments that earlier edits reworded are restored to their original
words, minus the phrases the change made wrong. The compute-host clarify
lock accepts None for a skipped question.
* test(clarify): align three checks with the one-answer confirm and the regenerated keys
The desktop Cmd+Enter test now expects a send with one answer (the blank
question locks null), the compressor test expects the single-answer summary
the code gives, and locales/_keys.desktop.json is regenerated for the
removed and added clarify strings.
* test(tui): the one-question card header is singular
166 lines
7 KiB
TypeScript
166 lines
7 KiB
TypeScript
/**
|
|
* C20 core: blocking interactive prompts round-trip through the real chain.
|
|
*
|
|
* Real Electron + real `hermes serve`, approvals in manual mode; only the LLM
|
|
* is faked. For each prompt kind the invariant is end to end, not "a card
|
|
* rendered":
|
|
* - clarify: exactly one card; the choice the user clicks is exactly what
|
|
* the model receives in the tool result on its next request; the turn
|
|
* completes; transcript oracle holds.
|
|
* - approval (run once): exactly one approval card; the gated command has
|
|
* NOT run before the click and HAS run after it (observable side effect);
|
|
* the turn completes; transcript oracle holds.
|
|
* - approval (deny): the command never runs; the turn still completes (no
|
|
* wedged busy state); transcript oracle holds.
|
|
*/
|
|
|
|
import * as fs from 'node:fs'
|
|
import * as path from 'node:path'
|
|
|
|
import { expect, type Page, test } from '@playwright/test'
|
|
|
|
import {
|
|
coreAppEnv,
|
|
createCoreSandbox,
|
|
currentSessionId,
|
|
launchCoreApp,
|
|
recordWebSockets,
|
|
send,
|
|
waitForInteractive,
|
|
writeProviderHome
|
|
} from './harness'
|
|
import { assertTranscriptOracle, installDuplicateSampler, type OracleTarget } from './oracle'
|
|
import { type RecordedCompletion, startScriptedProvider } from './provider'
|
|
|
|
const nonce = Math.random()
|
|
.toString(36)
|
|
.slice(2, 8)
|
|
.replace(/[^a-z0-9]/g, 'x')
|
|
.padEnd(4, 'q')
|
|
|
|
const U = (n: number) => `U${n}-${nonce}`
|
|
const A = (n: number) => `A${n}-${nonce}`
|
|
const AI = (n: number) => `A${n}i-${nonce}`
|
|
|
|
function viewport(page: Page) {
|
|
return page.locator('[data-slot="aui_thread-viewport"]').filter({ visible: true }).first()
|
|
}
|
|
|
|
/** Text of the tool results the model received in `completion`'s request. */
|
|
function toolResults(completion: RecordedCompletion | undefined): string {
|
|
const messages: any[] = completion?.body?.messages ?? []
|
|
|
|
return messages
|
|
.filter(m => m?.role === 'tool')
|
|
.map(m => (typeof m.content === 'string' ? m.content : JSON.stringify(m.content)))
|
|
.join('\n')
|
|
}
|
|
|
|
test('clarify and approval prompts round-trip exactly once', async () => {
|
|
const provider = await startScriptedProvider()
|
|
const sandbox = createCoreSandbox('prompts')
|
|
writeProviderHome(sandbox.hermesHome, provider.url, '', 'manual')
|
|
const { app, page } = await launchCoreApp(coreAppEnv(sandbox))
|
|
const ws = recordWebSockets(page)
|
|
const session: OracleTarget = { sessionId: '', expectUserMarkers: [] }
|
|
|
|
const finished = (marker: string, step = 0) =>
|
|
expect
|
|
.poll(() => provider.completions.some(c => c.marker === marker && c.step === step && c.finished), {
|
|
timeout: 120_000,
|
|
message: `provider finished ${marker} step ${step}`
|
|
})
|
|
.toBe(true)
|
|
|
|
const completion = (marker: string, step: number) =>
|
|
provider.completions.find(c => c.marker === marker && c.step === step)
|
|
|
|
try {
|
|
await waitForInteractive(app, page)
|
|
await installDuplicateSampler(page)
|
|
|
|
await test.step('clarify: the clicked choice is exactly what the model receives', async () => {
|
|
const question = `Q1-${nonce} which drink`
|
|
const pick = `mate-${nonce}`
|
|
const other = `chai-${nonce}`
|
|
provider.script(U(1), [
|
|
{
|
|
text: [`${AI(1)} `, 'asking'],
|
|
toolCalls: [{ name: 'clarify', args: { questions: [{ question, choices: [other, pick] }] } }]
|
|
},
|
|
{ text: [`${A(1)} `, 'noted ', 'your ', 'choice'] }
|
|
])
|
|
await send(page, `${U(1)} ask me`, 'Enter', ws)
|
|
const openForms = page.locator('form[data-clarify-choices], form[data-clarify-batch]').filter({ visible: true })
|
|
await expect(openForms).toHaveCount(1, { timeout: 120_000 })
|
|
await expect(viewport(page).getByText(question)).toHaveCount(1)
|
|
await openForms.getByRole('button', { name: new RegExp(pick) }).click()
|
|
const submit = openForms.locator('button[type="submit"]')
|
|
await expect(submit).toBeEnabled()
|
|
await submit.click()
|
|
await finished(U(1), 1)
|
|
const received = toolResults(completion(U(1), 1))
|
|
expect(received, 'model received the clicked choice').toContain(pick)
|
|
expect(received, 'model did not receive the other choice as the answer').not.toMatch(
|
|
new RegExp(`answer[^\\n]*${other}`, 'i')
|
|
)
|
|
await expect(
|
|
page.locator('form[data-clarify-choices], form[data-clarify-batch]').filter({ visible: true })
|
|
).toHaveCount(0)
|
|
await expect(page.locator('[data-clarify-settled]').filter({ visible: true })).toHaveCount(1)
|
|
await expect.poll(() => currentSessionId(page)).not.toBe('')
|
|
session.sessionId = await currentSessionId(page)
|
|
session.expectUserMarkers.push(U(1))
|
|
await assertTranscriptOracle(page, ws, provider, session, 'clarify round trip')
|
|
await expect(viewport(page).getByText(question)).toHaveCount(1)
|
|
})
|
|
|
|
await test.step('approval (run once): the command runs only after the click', async () => {
|
|
const victim = path.join(sandbox.root, `victim-run-${nonce}`)
|
|
fs.mkdirSync(victim)
|
|
provider.script(U(2), [
|
|
{
|
|
text: [`${AI(2)} `, 'needs ', 'approval'],
|
|
toolCalls: [{ name: 'terminal', args: { command: `rm -rf ${victim}` } }]
|
|
},
|
|
{ text: [`${A(2)} `, 'deleted ', 'it'] }
|
|
])
|
|
await send(page, `${U(2)} delete run dir`, 'Enter', ws)
|
|
const run = page.locator('[data-approval-run]').filter({ visible: true })
|
|
await expect(run).toHaveCount(1, { timeout: 120_000 })
|
|
expect(fs.existsSync(victim), 'gated command must not run before approval').toBe(true)
|
|
await run.click()
|
|
await finished(U(2), 1)
|
|
expect(fs.existsSync(victim), 'approved command ran').toBe(false)
|
|
await expect(page.locator('[data-approval-run]').filter({ visible: true })).toHaveCount(0)
|
|
session.expectUserMarkers.push(U(2))
|
|
await assertTranscriptOracle(page, ws, provider, session, 'approval run once')
|
|
})
|
|
|
|
await test.step('approval (deny): the command never runs, the turn still completes', async () => {
|
|
const victim = path.join(sandbox.root, `victim-deny-${nonce}`)
|
|
fs.mkdirSync(victim)
|
|
provider.script(U(3), [
|
|
{
|
|
text: [`${AI(3)} `, 'needs ', 'approval'],
|
|
toolCalls: [{ name: 'terminal', args: { command: `rm -rf ${victim}` } }]
|
|
},
|
|
{ text: [`${A(3)} `, 'left ', 'it ', 'alone'] }
|
|
])
|
|
await send(page, `${U(3)} delete deny dir`, 'Enter', ws)
|
|
const deny = page.locator('[data-approval-deny]').filter({ visible: true })
|
|
await expect(deny).toHaveCount(1, { timeout: 120_000 })
|
|
await deny.click()
|
|
await finished(U(3), 1)
|
|
expect(fs.existsSync(victim), 'denied command never ran').toBe(true)
|
|
expect(toolResults(completion(U(3), 1)), 'the denial reached the model as the tool result').not.toBe('')
|
|
await expect(page.locator('[data-approval-deny]').filter({ visible: true })).toHaveCount(0)
|
|
session.expectUserMarkers.push(U(3))
|
|
await assertTranscriptOracle(page, ws, provider, session, 'approval deny')
|
|
})
|
|
} finally {
|
|
await app.close().catch(() => undefined)
|
|
await provider.close()
|
|
sandbox.cleanup()
|
|
}
|
|
})
|