This commit is contained in:
2026-07-29 14:37:20 +00:00
parent 9c0973ead4
commit 4426ede979
33 changed files with 5128 additions and 216 deletions
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""SessionEnd:釋放人格鎖與所有 guest 租約,人格才能被下一個程序載入。"""
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"
data = pl.load_session(session_id)
host = data.get("host")
if host and pl.persona_exists(host):
state = pl.decay_emotion(pl.load_emotion(host))
pl.write_json(pl.emotion_path(host), state)
pl.append_jsonl(pl.journal_path(host), {
"ts": pl.iso(), "kind": "session-end", "session": session_id[:8],
"mood": pl.mood(state),
})
released = pl.unbind_session(session_id)
pl.gc_runtime()
out: dict = {"suppressOutput": True}
if released["host"]:
out["systemMessage"] = (
f"[jsc-persona] 已釋放 `{released['host']}` 的載入鎖"
+ (f"guest{released['guests']}" if released["guests"] else "")
)
print(json.dumps(out, ensure_ascii=False))
return 0
if __name__ == "__main__":
raise SystemExit(main())