Files
persona/hooks/subagent_stop.py
T
2026-07-29 14:37:20 +00:00

38 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""SubagentStopguest sub agent 結束時解除它的 pin(下次啟動要重新 first-touch)。"""
from __future__ import annotations
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts"))
import persona_lib as pl # noqa: E402
def main() -> int:
try:
event = json.load(sys.stdin)
except json.JSONDecodeError:
return 0
session_id = event.get("session_id") or "unknown"
agent_id = event.get("agent_id")
agent_type = str(event.get("agent_type") or "")
if not agent_id or "persona-guest" not in agent_type:
return 0
data = pl.load_session(session_id)
pins = data.get("pins") or {}
slug = pins.pop(agent_id, None)
if slug is not None:
pl.save_session(session_id, data)
info = (data.get("guests") or {}).get(slug) or {}
if info.get("room"):
pl.add_guest_lease(slug, session_id, info["room"], data.get("host") or "")
print(json.dumps({"suppressOutput": True}, ensure_ascii=False))
return 0
if __name__ == "__main__":
raise SystemExit(main())