feat(tier4): Add patch modal GUI integration and API hooks
This commit is contained in:
@@ -171,3 +171,22 @@ class ApiHookClient:
|
||||
def reset_session(self) -> None:
|
||||
"""Resets the current session via button click."""
|
||||
self.click("btn_reset")
|
||||
|
||||
def trigger_patch(self, patch_text: str, file_paths: list[str]) -> dict[str, Any]:
|
||||
"""Triggers the patch modal to show in the GUI."""
|
||||
return self._make_request('POST', '/api/patch/trigger', data={
|
||||
"patch_text": patch_text,
|
||||
"file_paths": file_paths
|
||||
}) or {}
|
||||
|
||||
def apply_patch(self) -> dict[str, Any]:
|
||||
"""Applies the pending patch."""
|
||||
return self._make_request('POST', '/api/patch/apply') or {}
|
||||
|
||||
def reject_patch(self) -> dict[str, Any]:
|
||||
"""Rejects the pending patch."""
|
||||
return self._make_request('POST', '/api/patch/reject') or {}
|
||||
|
||||
def get_patch_status(self) -> dict[str, Any]:
|
||||
"""Gets the current patch modal status."""
|
||||
return self._make_request('GET', '/api/patch/status') or {}
|
||||
|
||||
@@ -288,6 +288,97 @@ class HookHandler(BaseHTTPRequestHandler):
|
||||
else:
|
||||
self.send_response(504)
|
||||
self.end_headers()
|
||||
elif self.path == "/api/patch/trigger":
|
||||
patch_text = data.get("patch_text", "")
|
||||
file_paths = data.get("file_paths", [])
|
||||
event = threading.Event()
|
||||
result = {"status": "queued"}
|
||||
def trigger_patch():
|
||||
try:
|
||||
app._pending_patch_text = patch_text
|
||||
app._pending_patch_files = file_paths
|
||||
app._show_patch_modal = True
|
||||
result["status"] = "ok"
|
||||
except Exception as e:
|
||||
result["status"] = "error"
|
||||
result["error"] = str(e)
|
||||
finally:
|
||||
event.set()
|
||||
lock = _get_app_attr(app, "_pending_gui_tasks_lock")
|
||||
tasks = _get_app_attr(app, "_pending_gui_tasks")
|
||||
if lock and tasks is not None:
|
||||
with lock: tasks.append({"action": "custom_callback", "callback": trigger_patch})
|
||||
if event.wait(timeout=10):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps(result).encode("utf-8"))
|
||||
else:
|
||||
self.send_response(504)
|
||||
self.end_headers()
|
||||
elif self.path == "/api/patch/apply":
|
||||
event = threading.Event()
|
||||
result = {"status": "done"}
|
||||
def apply_patch():
|
||||
try:
|
||||
if hasattr(app, "_apply_pending_patch"):
|
||||
app._apply_pending_patch()
|
||||
else:
|
||||
result["status"] = "no_method"
|
||||
except Exception as e:
|
||||
result["status"] = "error"
|
||||
result["error"] = str(e)
|
||||
finally:
|
||||
event.set()
|
||||
lock = _get_app_attr(app, "_pending_gui_tasks_lock")
|
||||
tasks = _get_app_attr(app, "_pending_gui_tasks")
|
||||
if lock and tasks is not None:
|
||||
with lock: tasks.append({"action": "custom_callback", "callback": apply_patch})
|
||||
if event.wait(timeout=10):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps(result).encode("utf-8"))
|
||||
else:
|
||||
self.send_response(504)
|
||||
self.end_headers()
|
||||
elif self.path == "/api/patch/reject":
|
||||
event = threading.Event()
|
||||
result = {"status": "done"}
|
||||
def reject_patch():
|
||||
try:
|
||||
app._show_patch_modal = False
|
||||
app._pending_patch_text = None
|
||||
app._pending_patch_files = []
|
||||
except Exception as e:
|
||||
result["status"] = "error"
|
||||
result["error"] = str(e)
|
||||
finally:
|
||||
event.set()
|
||||
lock = _get_app_attr(app, "_pending_gui_tasks_lock")
|
||||
tasks = _get_app_attr(app, "_pending_gui_tasks")
|
||||
if lock and tasks is not None:
|
||||
with lock: tasks.append({"action": "custom_callback", "callback": reject_patch})
|
||||
if event.wait(timeout=10):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps(result).encode("utf-8"))
|
||||
else:
|
||||
self.send_response(504)
|
||||
self.end_headers()
|
||||
elif self.path == "/api/patch/status":
|
||||
show_modal = _get_app_attr(app, "_show_patch_modal", False)
|
||||
patch_text = _get_app_attr(app, "_pending_patch_text", None)
|
||||
patch_files = _get_app_attr(app, "_pending_patch_files", [])
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({
|
||||
"show_modal": show_modal,
|
||||
"patch_text": patch_text,
|
||||
"file_paths": patch_files
|
||||
}).encode("utf-8"))
|
||||
elif self.path == "/api/ask":
|
||||
request_id = str(uuid.uuid4())
|
||||
event = threading.Event()
|
||||
|
||||
Reference in New Issue
Block a user