mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-05-06 16:26:16 +08:00
Fix unhandled OSError in subprocess and unsafe dict access in subagent (#159)
- agents/s01_agent_loop.py: Add FileNotFoundError/OSError handling in run_bash() - agents/s04_subagent.py: Same fix + use .get() for block.input['prompt'] (consistent with .get() already used for 'description' on line 157) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -73,6 +73,8 @@ def run_bash(command: str) -> str:
|
||||
return out[:50000] if out else "(no output)"
|
||||
except subprocess.TimeoutExpired:
|
||||
return "Error: Timeout (120s)"
|
||||
except (FileNotFoundError, OSError) as e:
|
||||
return f"Error: {e}"
|
||||
|
||||
|
||||
# -- The core pattern: a while loop that calls tools until the model stops --
|
||||
|
||||
@@ -61,6 +61,8 @@ def run_bash(command: str) -> str:
|
||||
return out[:50000] if out else "(no output)"
|
||||
except subprocess.TimeoutExpired:
|
||||
return "Error: Timeout (120s)"
|
||||
except (FileNotFoundError, OSError) as e:
|
||||
return f"Error: {e}"
|
||||
|
||||
def run_read(path: str, limit: int = None) -> str:
|
||||
try:
|
||||
@@ -155,8 +157,9 @@ def agent_loop(messages: list):
|
||||
if block.type == "tool_use":
|
||||
if block.name == "task":
|
||||
desc = block.input.get("description", "subtask")
|
||||
print(f"> task ({desc}): {block.input['prompt'][:80]}")
|
||||
output = run_subagent(block.input["prompt"])
|
||||
prompt = block.input.get("prompt", "")
|
||||
print(f"> task ({desc}): {prompt[:80]}")
|
||||
output = run_subagent(prompt)
|
||||
else:
|
||||
handler = TOOL_HANDLERS.get(block.name)
|
||||
output = handler(**block.input) if handler else f"Unknown tool: {block.name}"
|
||||
|
||||
Reference in New Issue
Block a user