Preserve macOS app permissions via dynamic launcher, .env workspace path, and session/audio tools
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python3
|
||||
"""CLI helper to inspect and reset Hermes voice agent sessions."""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add VoiceAgent1 project root to sys.path
|
||||
project_root = Path(__file__).resolve().parent.parent
|
||||
if str(project_root) not in sys.path:
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
SESSION_FILE_NAME = ".hermes-voice-session.json"
|
||||
|
||||
|
||||
def get_session_file(app_dir: Path | None = None) -> Path:
|
||||
base_dir = app_dir or project_root
|
||||
return base_dir / SESSION_FILE_NAME
|
||||
|
||||
|
||||
def get_active_session_id(app_dir: Path | None = None) -> str | None:
|
||||
session_file = get_session_file(app_dir)
|
||||
if session_file.exists():
|
||||
try:
|
||||
data = json.loads(session_file.read_text())
|
||||
sid = data.get("session_id")
|
||||
if sid and isinstance(sid, str):
|
||||
return sid.strip()
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
def reset_session(app_dir: Path | None = None) -> tuple[bool, str]:
|
||||
session_file = get_session_file(app_dir)
|
||||
deleted = False
|
||||
if session_file.exists():
|
||||
try:
|
||||
session_file.unlink()
|
||||
deleted = True
|
||||
except Exception as e:
|
||||
return False, f"Could not remove session file: {e}"
|
||||
|
||||
msg = "Session reset successfully. A fresh Hermes session will start on the next turn."
|
||||
if not deleted:
|
||||
msg = "No active session file found. Next turn will start with a fresh session."
|
||||
|
||||
try:
|
||||
import web_server
|
||||
web_server.broadcast_event("session_reset", {"message": msg})
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return True, msg
|
||||
|
||||
|
||||
def main():
|
||||
app_dir = project_root
|
||||
|
||||
if len(sys.argv) < 2 or sys.argv[1] in ("get", "info", "current", "show"):
|
||||
sid = get_active_session_id(app_dir)
|
||||
if sid:
|
||||
print(f"Active Session ID: {sid}")
|
||||
else:
|
||||
print("No active Hermes session (a new session will start on the next turn).")
|
||||
return
|
||||
|
||||
action = sys.argv[1].lower()
|
||||
if action in ("reset", "new", "clear"):
|
||||
ok, msg = reset_session(app_dir)
|
||||
print(msg)
|
||||
else:
|
||||
print(f"Unknown action: {sys.argv[1]}. Usage: python bin/session_tool.py [get|reset]")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user