(session: Any, event: Any)
| 35 | |
| 36 | |
| 37 | def confirm_from_cli(session: Any, event: Any) -> None: |
| 38 | pending = pending_by_tool_id(session, event.tool_id) |
| 39 | data = event_data(event) |
| 40 | tool_id = (pending or {}).get("tool_id") or event.tool_id |
| 41 | |
| 42 | if not tool_id: |
| 43 | print("[hitl] confirmation_required event has no tool id; skipping", file=sys.stderr) |
| 44 | return |
| 45 | |
| 46 | tool_name = (pending or {}).get("tool_name") or event.tool_name or "unknown" |
| 47 | args = (pending or {}).get("args") or data.get("args") or {} |
| 48 | remaining_ms = (pending or {}).get("remaining_ms") or data.get("timeout_ms") |
| 49 | |
| 50 | print("\n[hitl] Tool requires confirmation") |
| 51 | print(f"tool: {tool_name}") |
| 52 | print(f"tool_id: {tool_id}") |
| 53 | if remaining_ms is not None: |
| 54 | print(f"remaining_ms: {remaining_ms}") |
| 55 | print(json.dumps(args, indent=2, ensure_ascii=False)) |
| 56 | |
| 57 | auto_approve = os.environ.get("A3S_CODE_HITL_AUTO_APPROVE") == "1" |
| 58 | answer = "y" if auto_approve else input("Approve this tool call? [y/N] ") |
| 59 | approved = answer.strip().lower().startswith("y") |
| 60 | completed = session.confirm_tool_use( |
| 61 | tool_id, |
| 62 | approved, |
| 63 | "Approved from Python HITL example" if approved else "Rejected from Python HITL example", |
| 64 | ) |
| 65 | state = "approved" if approved else "rejected" |
| 66 | print(f"[hitl] confirmation {'resolved' if completed else 'not found'} ({state})") |
| 67 | |
| 68 | |
| 69 | def main() -> None: |
no test coverage detected