[Concept,03/29] u_boot_pylib: Add a way to inspect agent output

Message ID 20260501110040.1874719-4-sjg@u-boot.org
State New
Headers
Series patman: Review-flow improvements and shared helpers |

Commit Message

Simon Glass May 1, 2026, 10:59 a.m. UTC
  From: Simon Glass <sjg@chromium.org>

When the Claude Agent SDK interrupts mid-run (e.g. due to a blocked tool
or an internal limit), only the text blocks are printed and any
surrounding message metadata is lost. This makes it hard to see why the
interruption happened.

Add an env-var hook: setting PATMAN_DEBUG_AGENT=1 dumps every message
and block received from the SDK to stderr. This is verbose so it is off
by default, but invaluable when diagnosing a stuck apply or review run.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/u_boot_pylib/claude.py | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Patch

diff --git a/tools/u_boot_pylib/claude.py b/tools/u_boot_pylib/claude.py
index 6ba980b6b2e..82fd29ea8d7 100644
--- a/tools/u_boot_pylib/claude.py
+++ b/tools/u_boot_pylib/claude.py
@@ -50,11 +50,19 @@  async def run_agent_collect(prompt, options):
         tuple: (success, conversation_log) where success is bool and
             conversation_log is the agent's output text
     """
+    import os
+    debug = os.environ.get('PATMAN_DEBUG_AGENT')
     conversation_log = []
     try:
         async for message in query(prompt=prompt, options=options):
+            if debug:
+                tout.error(f'AGENT MSG: {type(message).__name__}: '
+                           f'{message!r}')
             if hasattr(message, 'content'):
                 for block in message.content:
+                    if debug:
+                        tout.error(f'  BLOCK: {type(block).__name__}: '
+                                   f'{block!r}')
                     if hasattr(block, 'text'):
                         print(block.text)
                         conversation_log.append(block.text)