Prechádzať zdrojové kódy

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.
_Kerman 2 mesiacov pred
rodič
commit
3df3a0dc00

+ 13 - 4
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')