Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/aeondave_pi-claude.json
T

1 line
2.5 KiB
JSON

{"repo": "aeondave/pi-claude", "files": {"scripts/mitmproxy_dump.py": {"9e21dcba6d1e18d87597479723efad4c0aa58461": {"t": 1785674430.038567, "n": 2273, "h": "9502e0bca78d518d", "c": "\"\"\"\nmitmproxy addon: dump every Anthropic /v1/messages request to a JSON file.\n\nCaptures the EXACT wire request (method, URL, headers, parsed JSON body) so a\ngenuine Claude Code request can be diffed against a Pi request made through this\nplugin. The OAuth bearer token is redacted before writing.\n\nUsage (cross-platform — mitmproxy installs via `pip install mitmproxy`):\n\n # terminal 1 — start the proxy with this addon\n mitmdump -s scripts/mitmproxy_dump.py\n\n # terminal 2 — route a client through the proxy, trusting mitmproxy's CA.\n # Node CLIs (claude, pi) honor NODE_EXTRA_CA_CERTS, so no system trust needed.\n # PowerShell:\n # $env:HTTPS_PROXY=\"http://127.0.0.1:8080\"\n # $env:HTTP_PROXY=\"http://127.0.0.1:8080\"\n # $env:NODE_EXTRA_CA_CERTS=\"$HOME/.mitmproxy/mitmproxy-ca-cert.pem\"\n # $env:PI_CAPTURE_LABEL=\"claude\"; claude -p \"say hello\"\n # $env:PI_CAPTURE_LABEL=\"pi\"; pi -p \"say hello\"\n\nOutput: captures/req-<label>-<n>.json (label from PI_CAPTURE_LABEL, default \"capture\")\n\"\"\"\n\nimport json\nimport os\n\nOUT_DIR = os.environ.get(\"PI_CAPTURE_DIR\", \"captures\")\nLABEL = os.environ.get(\"PI_CAPTURE_LABEL\", \"capture\")\n_count = 0\n\n\ndef _redact(headers: dict) -> dict:\n out = {}\n for key, value in headers.items():\n lower = key.lower()\n if lower == \"authorization\":\n out[lower] = \"Bearer sk-ant-REDACTED\"\n elif lower in (\"x-api-key\", \"cookie\"):\n out[lower] = \"REDACTED\"\n else:\n out[lower] = value\n return out\n\n\ndef request(flow) -> None:\n global _count\n if \"/v1/messages\" not in flow.request.path:\n return\n\n _count += 1\n os.makedirs(OUT_DIR, exist_ok=True)\n\n try:\n body = json.loads(flow.request.get_text())\n except Exception:\n body = None\n\n record = {\n \"label\": LABEL,\n \"method\": flow.request.method,\n \"url\": flow.request.pretty_url,\n \"headers\": _redact(dict(flow.request.headers)),\n \"body\": body,\n }\n\n path = os.path.join(OUT_DIR, f\"req-{LABEL}-{_count}.json\")\n with open(path, \"w\", encoding=\"utf-8\") as handle:\n json.dump(record, handle, indent=2, ensure_ascii=False)\n\n size = len(flow.request.content or b\"\")\n print(f\"[capture] wrote {path} ({size} body bytes)\")\n"}}}}