From 3df3a0dc00a67d79f8a5cbbf6548d075576df4ff Mon Sep 17 00:00:00 2001 From: _Kerman Date: Sun, 26 Jul 2026 11:47:52 +0800 Subject: [PATCH] test(tui-agent): match scripted triggers across the trailing user run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../tests/fixtures/tui-scripted-llm.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/tui-agent/tests/fixtures/tui-scripted-llm.ts b/examples/tui-agent/tests/fixtures/tui-scripted-llm.ts index c3bdbfd1b1..dead5c0b78 100644 --- a/examples/tui-agent/tests/fixtures/tui-scripted-llm.ts +++ b/examples/tui-agent/tests/fixtures/tui-scripted-llm.ts @@ -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') } const lastMessage = options.messages.at(-1) - const lastText = (lastMessage?.content ?? []) - .filter(block => block.type === 'text') - .map(block => block.text) - .join('\n') + // The loop appends plugin-sourced context (the plan-mode notice, the + // tool-skill catalog) AFTER the admitted prompt, so the scripted trigger + // may sit one or more user messages back: scan the whole trailing run of + // 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 (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')