test(tui-agent): match scripted triggers across the trailing user run

This branch intentionally appends plugin-sourced context (plan-mode
notices, the skill catalog) after the prompt, so the request's last message
is no longer the user's text. The scripted adapter keyed every scenario off
messages.at(-1) only, missed its triggers, and fell through to the
ask_user_question default — the frozen 'Waiting for the first token' PTY
timeouts. It now scans all text since the last assistant message.
This commit is contained in:
_Kerman
2026-07-26 11:47:52 +08:00
parent 4284530c7e
commit 3df3a0dc00

View File

@@ -51,10 +51,19 @@ class ScriptedTuiAdapter extends LlmAdapter {
throw new Error('the scripted TUI request did not apply the selected model to routing and prompt variables') throw new Error('the scripted TUI request did not apply the selected model to routing and prompt variables')
} }
const lastMessage = options.messages.at(-1) const lastMessage = options.messages.at(-1)
const lastText = (lastMessage?.content ?? []) // The loop appends plugin-sourced context (the plan-mode notice, the
.filter(block => block.type === 'text') // tool-skill catalog) AFTER the admitted prompt, so the scripted trigger
.map(block => block.text) // may sit one or more user messages back: scan the whole trailing run of
.join('\n') // user-role messages since the last assistant message.
const trailingUserTexts: string[] = []
for (let index = options.messages.length - 1; index >= 0; index--) {
const message = options.messages[index]
if (message?.role !== 'user') break
for (const block of message.content) {
if (block.type === 'text') trailingUserTexts.push(block.text)
}
}
const lastText = trailingUserTexts.join('\n')
if (lastText.includes(DEFAULT_MODE_PROBE)) { if (lastText.includes(DEFAULT_MODE_PROBE)) {
if (options.system?.includes('Stay in plan mode for this scripted TUI test.')) { if (options.system?.includes('Stay in plan mode for this scripted TUI test.')) {
throw new Error('the scripted TUI request retained plan guidance after /plan off') throw new Error('the scripted TUI request retained plan guidance after /plan off')