checkpoint: fix regression when using gemini cli outside of manual slop.

This commit is contained in:
2026-02-25 19:01:42 -05:00
parent fcb83e620c
commit f728274764
2 changed files with 24 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ import subprocess
import json import json
import sys import sys
import time import time
import os
class GeminiCliAdapter: class GeminiCliAdapter:
def __init__(self, binary_path="gemini"): def __init__(self, binary_path="gemini"):
@@ -24,13 +25,17 @@ class GeminiCliAdapter:
accumulated_text = "" accumulated_text = ""
env = os.environ.copy()
env["GEMINI_CLI_HOOK_CONTEXT"] = "manual_slop"
process = subprocess.Popen( process = subprocess.Popen(
command, command,
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
text=True, text=True,
shell=True shell=True,
env=env
) )
try: try:

View File

@@ -29,7 +29,17 @@ def main():
tool_name = hook_input.get('tool_name') tool_name = hook_input.get('tool_name')
tool_args = hook_input.get('tool_input', {}) 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") client = ApiHookClient(base_url="http://127.0.0.1:8999")
try: try:
@@ -38,20 +48,22 @@ def main():
response = client.request_confirmation(tool_name, tool_args) response = client.request_confirmation(tool_name, tool_args)
if response and response.get('approved') is True: if response and response.get('approved') is True:
# 5. Print 'allow' decision # 6. Print 'allow' decision
print(json.dumps({"decision": "allow"})) print(json.dumps({"decision": "allow"}))
else: else:
# 6. Print 'deny' decision # 7. Print 'deny' decision
print(json.dumps({ print(json.dumps({
"decision": "deny", "decision": "deny",
"reason": "User rejected tool execution." "reason": "User rejected tool execution in GUI."
})) }))
except Exception as e: 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({ print(json.dumps({
"decision": "deny", "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: except Exception as e: