13 lines
620 B
Python
Executable File
13 lines
620 B
Python
Executable File
#!/usr/bin/env python3
|
|
"""Test extension: subscribes to tool_call, blocks `read` of secrets and `bash` curl."""
|
|
import json, sys
|
|
for line in sys.stdin:
|
|
m = json.loads(line)
|
|
if m["method"] == "initialize":
|
|
r = {"subscribe": ["tool_call"], "tools": []}
|
|
else:
|
|
e = m["params"]["event"]
|
|
bad = (e["name"] == "read" and ".ssh" in e["args"]["path"]) or (e["name"] == "bash" and "curl" in e["args"]["command"])
|
|
r = {"action": "block", "reason": "guard: " + e["name"]} if bad else {"action": "continue"}
|
|
print(json.dumps({"jsonrpc": "2.0", "id": m["id"], "result": r}), flush=True)
|