Executor-Tyrant-Framework Claude Opus 4.6 (1M context) commited on
Commit
e404f67
·
1 Parent(s): 216fbef

Fix gate loop, metadata sanitization, and write confirmation

Browse files

- Kill auto_continue_after_approval loop (caused infinite gate restaging)
- Sanitize message dicts for Anthropic API (strip Gradio metadata field)
- Write confirmation shows full resolved path + file size
- args.get() uses 'or' pattern for null safety

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Files changed (2) hide show
  1. app.py +9 -6
  2. tools/filesystem_tool.py +2 -1
app.py CHANGED
@@ -301,7 +301,10 @@ def _build_api_messages(history: list, system_prompt: str) -> list:
301
  if budget - tokens < 0 and messages:
302
  break
303
  budget -= tokens
304
- messages.append(msg)
 
 
 
305
 
306
  messages.reverse()
307
  return messages
@@ -490,15 +493,15 @@ def execute_approved_proposals(ids, proposals, history):
490
  results.append(f"**{p['tool']}**: {out}")
491
  else:
492
  remaining.append(p)
 
493
  if results:
494
- history.append({"role": "assistant", "content": "**Executed:**\n" + "\n".join(results)})
495
- return "Done.", remaining, _format_gate_choices(remaining), history
496
 
497
 
498
  def auto_continue_after_approval(history, proposals):
499
- last = history[-1].get("content", "") if history else ""
500
- if "**Executed:**" in str(last):
501
- return agent_loop("[System: Tools executed. Continue.]", history, proposals, None)
502
  return (history, "", proposals, _format_gate_choices(proposals),
503
  _stats_label_files(), _stats_label_convos())
504
 
 
301
  if budget - tokens < 0 and messages:
302
  break
303
  budget -= tokens
304
+ # Sanitize — only pass role and content to Anthropic API
305
+ # Gradio adds metadata and other fields that Claude rejects
306
+ clean = {"role": msg["role"], "content": msg["content"]}
307
+ messages.append(clean)
308
 
309
  messages.reverse()
310
  return messages
 
493
  results.append(f"**{p['tool']}**: {out}")
494
  else:
495
  remaining.append(p)
496
+ new_history = list(history) if history else []
497
  if results:
498
+ new_history.append({"role": "assistant", "content": "**Executed:**\n" + "\n".join(results)})
499
+ return "Done.", remaining, _format_gate_choices(remaining), new_history
500
 
501
 
502
  def auto_continue_after_approval(history, proposals):
503
+ # Don't auto-continue it causes infinite gate loops.
504
+ # User sends a new message to continue after approval.
 
505
  return (history, "", proposals, _format_gate_choices(proposals),
506
  _stats_label_files(), _stats_label_convos())
507
 
tools/filesystem_tool.py CHANGED
@@ -85,7 +85,8 @@ class FilesystemTool:
85
  try:
86
  target.parent.mkdir(parents=True, exist_ok=True)
87
  target.write_text(content, encoding='utf-8')
88
- return f"Written to {path}"
 
89
  except PermissionError as e:
90
  return {"status": "error", "tool": "filesystem", "error": str(e), "type": "PermissionError"}
91
  except OSError as e:
 
85
  try:
86
  target.parent.mkdir(parents=True, exist_ok=True)
87
  target.write_text(content, encoding='utf-8')
88
+ size = target.stat().st_size
89
+ return f"Written to {target} ({size:,} bytes)"
90
  except PermissionError as e:
91
  return {"status": "error", "tool": "filesystem", "error": str(e), "type": "PermissionError"}
92
  except OSError as e: