chore: remove vestigial sentinel flip code

- Remove deprecated _trigger_sentinel_async function and all call sites
- Clean up force_sentinel_reload option handling (replaced with Unity's synchronous system)
- Addresses repeated CodeRabbit flagging of unused vestigial code

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
main
David Sarno 2025-09-03 16:58:13 -07:00
parent 9697653b64
commit 290c913a0f
1 changed files with 5 additions and 58 deletions

View File

@ -193,37 +193,6 @@ def _find_best_closing_brace_match(matches, text: str):
return best_match return best_match
def _trigger_sentinel_async() -> None:
"""Fire the Unity menu flip on a short-lived background thread.
This avoids blocking the current request or getting stuck during domain reloads
(socket reconnects) when the Editor recompiles.
"""
try:
import threading, time
def _flip():
try:
import json, glob, os
# Small delay so write flushes; prefer early flip to avoid editor-focus second reload
time.sleep(0.1)
try:
files = sorted(glob.glob(os.path.expanduser("~/.unity-mcp/unity-mcp-status-*.json")), key=os.path.getmtime, reverse=True)
if files:
with open(files[0], "r") as f:
st = json.loads(f.read())
if st.get("reloading"):
return
except Exception:
pass
except Exception:
pass
threading.Thread(target=_flip, daemon=True).start()
except Exception:
pass
def _infer_class_name(script_name: str) -> str: def _infer_class_name(script_name: str) -> str:
# Default to script name as class name (common Unity pattern) # Default to script name as class name (common Unity pattern)
return (script_name or "").strip() return (script_name or "").strip()
@ -578,12 +547,7 @@ def register_manage_script_edits_tools(mcp: FastMCP):
} }
resp_struct = send_command_with_retry("manage_script", params_struct) resp_struct = send_command_with_retry("manage_script", params_struct)
if isinstance(resp_struct, dict) and resp_struct.get("success"): if isinstance(resp_struct, dict) and resp_struct.get("success"):
# Optional: flip sentinel only if explicitly requested pass # Optional sentinel reload removed (deprecated)
if (options or {}).get("force_sentinel_reload"):
try:
_trigger_sentinel_async()
except Exception:
pass
return _with_norm(resp_struct if isinstance(resp_struct, dict) else {"success": False, "message": str(resp_struct)}, normalized_for_echo, routing="structured") return _with_norm(resp_struct if isinstance(resp_struct, dict) else {"success": False, "message": str(resp_struct)}, normalized_for_echo, routing="structured")
# 1) read from Unity # 1) read from Unity
@ -704,12 +668,7 @@ def register_manage_script_edits_tools(mcp: FastMCP):
resp_text = send_command_with_retry("manage_script", params_text) resp_text = send_command_with_retry("manage_script", params_text)
if not (isinstance(resp_text, dict) and resp_text.get("success")): if not (isinstance(resp_text, dict) and resp_text.get("success")):
return _with_norm(resp_text if isinstance(resp_text, dict) else {"success": False, "message": str(resp_text)}, normalized_for_echo, routing="mixed/text-first") return _with_norm(resp_text if isinstance(resp_text, dict) else {"success": False, "message": str(resp_text)}, normalized_for_echo, routing="mixed/text-first")
# Successful text write; flip sentinel only if explicitly requested # Optional sentinel reload removed (deprecated)
if (options or {}).get("force_sentinel_reload"):
try:
_trigger_sentinel_async()
except Exception:
pass
except Exception as e: except Exception as e:
return _with_norm({"success": False, "message": f"Text edit conversion failed: {e}"}, normalized_for_echo, routing="mixed/text-first") return _with_norm({"success": False, "message": f"Text edit conversion failed: {e}"}, normalized_for_echo, routing="mixed/text-first")
@ -728,11 +687,7 @@ def register_manage_script_edits_tools(mcp: FastMCP):
} }
resp_struct = send_command_with_retry("manage_script", params_struct) resp_struct = send_command_with_retry("manage_script", params_struct)
if isinstance(resp_struct, dict) and resp_struct.get("success"): if isinstance(resp_struct, dict) and resp_struct.get("success"):
if (options or {}).get("force_sentinel_reload"): pass # Optional sentinel reload removed (deprecated)
try:
_trigger_sentinel_async()
except Exception:
pass
return _with_norm(resp_struct if isinstance(resp_struct, dict) else {"success": False, "message": str(resp_struct)}, normalized_for_echo, routing="mixed/text-first") return _with_norm(resp_struct if isinstance(resp_struct, dict) else {"success": False, "message": str(resp_struct)}, normalized_for_echo, routing="mixed/text-first")
return _with_norm({"success": True, "message": "Applied text edits (no structured ops)"}, normalized_for_echo, routing="mixed/text-first") return _with_norm({"success": True, "message": "Applied text edits (no structured ops)"}, normalized_for_echo, routing="mixed/text-first")
@ -851,11 +806,7 @@ def register_manage_script_edits_tools(mcp: FastMCP):
} }
resp = send_command_with_retry("manage_script", params) resp = send_command_with_retry("manage_script", params)
if isinstance(resp, dict) and resp.get("success"): if isinstance(resp, dict) and resp.get("success"):
if (options or {}).get("force_sentinel_reload"): pass # Optional sentinel reload removed (deprecated)
try:
_trigger_sentinel_async()
except Exception:
pass
return _with_norm( return _with_norm(
resp if isinstance(resp, dict) else {"success": False, "message": str(resp)}, resp if isinstance(resp, dict) else {"success": False, "message": str(resp)},
normalized_for_echo, normalized_for_echo,
@ -937,11 +888,7 @@ def register_manage_script_edits_tools(mcp: FastMCP):
write_resp = send_command_with_retry("manage_script", params) write_resp = send_command_with_retry("manage_script", params)
if isinstance(write_resp, dict) and write_resp.get("success"): if isinstance(write_resp, dict) and write_resp.get("success"):
if (options or {}).get("force_sentinel_reload"): pass # Optional sentinel reload removed (deprecated)
try:
_trigger_sentinel_async()
except Exception:
pass
return _with_norm( return _with_norm(
write_resp if isinstance(write_resp, dict) write_resp if isinstance(write_resp, dict)
else {"success": False, "message": str(write_resp)}, else {"success": False, "message": str(write_resp)},