feat: add runtime discovery and execution traces

This commit is contained in:
chungyeong
2026-03-13 21:52:13 +09:00
parent 941304398d
commit 28dd794f54
35 changed files with 376 additions and 88 deletions

View File

@@ -218,6 +218,7 @@ def invoke_agent(
else:
input_data = prompt
cmd_preview = " ".join(cmd[:6])
logger.debug("Invoking agent '%s': %s", agent.name, " ".join(cmd[:5]) + " ...")
spinner: Optional[_Spinner] = None
@@ -259,7 +260,6 @@ def invoke_agent(
err_detail = result.stderr.strip() or result.stdout.strip()
if err_detail and len(err_detail) > 500:
err_detail = err_detail[:500] + "..."
cmd_preview = " ".join(cmd[:6])
failure_type, suggested_action = _classify_agent_failure(err_detail or "")
raise AgentInvocationError(
agent_name=agent.name,
@@ -298,12 +298,20 @@ def invoke_agent(
agent.name, step_name,
)
transcript = _build_transcript(
command_preview=cmd_preview,
stdout=result.stdout,
stderr=result.stderr,
)
return AgentResult(
output=output,
exit_code=result.returncode,
agent_name=agent.name,
step_name=step_name,
duration_seconds=round(duration, 1),
transcript=transcript,
command_preview=cmd_preview,
)
@@ -360,6 +368,7 @@ def invoke_agent_agentic(
f"Work in the current directory."
)
cmd_preview = " ".join(cmd[:6])
logger.debug(
"Invoking agent '%s' (agentic) in worktree: %s",
agent.name, worktree_path,
@@ -401,7 +410,6 @@ def invoke_agent_agentic(
err_detail = result.stderr.strip() or result.stdout.strip()
if err_detail and len(err_detail) > 500:
err_detail = err_detail[:500] + "..."
cmd_preview = " ".join(cmd[:6])
failure_type, suggested_action = _classify_agent_failure(err_detail or "")
raise AgentInvocationError(
agent_name=agent.name,
@@ -426,10 +434,47 @@ def invoke_agent_agentic(
if spinner:
spinner.stop(f"[{step_name}] done — {chars} chars (agentic)")
transcript = _build_transcript(
command_preview=cmd_preview,
stdout=result.stdout,
stderr=result.stderr,
)
return AgentResult(
output=diff_output,
exit_code=result.returncode,
agent_name=agent.name,
step_name=step_name,
duration_seconds=round(duration, 1),
transcript=transcript,
command_preview=cmd_preview,
)
def _build_transcript(
*,
command_preview: str,
stdout: str,
stderr: str,
) -> str:
"""Build a compact execution transcript for debugging/audit output."""
sections = [
"# Agent Execution Transcript",
"",
"## Command",
"```",
command_preview or "(unknown command)",
"```",
"",
"## Stdout",
"```",
(stdout or "(empty)").strip(),
"```",
"",
"## Stderr",
"```",
(stderr or "(empty)").strip(),
"```",
"",
]
return "\n".join(sections)