checkpoint: fix regression when using gemini cli outside of manual slop.
This commit is contained in:
@@ -2,6 +2,7 @@ import subprocess
|
||||
import json
|
||||
import sys
|
||||
import time
|
||||
import os
|
||||
|
||||
class GeminiCliAdapter:
|
||||
def __init__(self, binary_path="gemini"):
|
||||
@@ -24,13 +25,17 @@ class GeminiCliAdapter:
|
||||
|
||||
accumulated_text = ""
|
||||
|
||||
env = os.environ.copy()
|
||||
env["GEMINI_CLI_HOOK_CONTEXT"] = "manual_slop"
|
||||
|
||||
process = subprocess.Popen(
|
||||
command,
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
shell=True
|
||||
shell=True,
|
||||
env=env
|
||||
)
|
||||
|
||||
try:
|
||||
|
||||
@@ -29,7 +29,17 @@ def main():
|
||||
tool_name = hook_input.get('tool_name')
|
||||
tool_args = hook_input.get('tool_input', {})
|
||||
|
||||
# 3. Use 'ApiHookClient' (assuming GUI is on http://127.0.0.1:8999)
|
||||
# 3. Check context — if not running via Manual Slop, we pass through (allow)
|
||||
# This prevents the hook from affecting normal CLI usage.
|
||||
hook_context = os.environ.get("GEMINI_CLI_HOOK_CONTEXT")
|
||||
if hook_context != "manual_slop":
|
||||
print(json.dumps({
|
||||
"decision": "allow",
|
||||
"reason": "Non-programmatic usage (GEMINI_CLI_HOOK_CONTEXT not set)."
|
||||
}))
|
||||
return
|
||||
|
||||
# 4. Use 'ApiHookClient' (assuming GUI is on http://127.0.0.1:8999)
|
||||
client = ApiHookClient(base_url="http://127.0.0.1:8999")
|
||||
|
||||
try:
|
||||
@@ -38,20 +48,22 @@ def main():
|
||||
response = client.request_confirmation(tool_name, tool_args)
|
||||
|
||||
if response and response.get('approved') is True:
|
||||
# 5. Print 'allow' decision
|
||||
# 6. Print 'allow' decision
|
||||
print(json.dumps({"decision": "allow"}))
|
||||
else:
|
||||
# 6. Print 'deny' decision
|
||||
# 7. Print 'deny' decision
|
||||
print(json.dumps({
|
||||
"decision": "deny",
|
||||
"reason": "User rejected tool execution."
|
||||
"reason": "User rejected tool execution in GUI."
|
||||
}))
|
||||
|
||||
except Exception as e:
|
||||
# 7. Handle cases where hook server is not reachable
|
||||
# 8. Handle cases where hook server is not reachable
|
||||
# If we ARE in manual_slop context but can't reach the server, we should DENY
|
||||
# because the user expects to be in control.
|
||||
print(json.dumps({
|
||||
"decision": "deny",
|
||||
"reason": f"Hook server unreachable or error occurred: {str(e)}"
|
||||
"reason": f"Manual Slop hook server unreachable: {str(e)}"
|
||||
}))
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user