From 141fe199a7e31c6be7ebc95a2141d33effd7d576 Mon Sep 17 00:00:00 2001 From: k-QRedHacker Date: Fri, 10 Jul 2026 11:24:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20session=20handoff=20=E2=80=94=20auto-lo?= =?UTF-8?q?ad=20continuity=20files=20between=20sessions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reads all *.md files from ~/.hermes/session_handoff/ at session build time and injects them into the system prompt volatile_parts tier. Use case: place handoff notes before starting a new session (/new). The agent automatically reads and incorporates them, providing continuity without explicit user action. Cache safety: read once at build_system_prompt_parts() time, byte-stable for the session lifetime. Same tier as memory and user profile — volatile at session boundary, stable within. Co-Authored-By: Claw F (量子红客组织) --- agent/system_prompt.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/agent/system_prompt.py b/agent/system_prompt.py index ea33df54a0d0..b75adb8d0132 100644 --- a/agent/system_prompt.py +++ b/agent/system_prompt.py @@ -468,6 +468,32 @@ def build_system_prompt_parts(agent: Any, system_message: Optional[str] = None) if user_block: volatile_parts.append(user_block) + # ── Session Handoff: auto-load continuity files ── + # Reads all *.md files from ~/.hermes/session_handoff/ at session build + # time. Allows continuity between sessions without the user needing to + # explicitly reference files or paste context into chat. + # Cache-safe: read once at build_system_prompt_parts() time, byte-stable + # for the session lifetime (same tier as memory and user profile). + try: + from pathlib import Path as _SHPath + from hermes_constants import get_hermes_home as _SHget_hh + _sh_dir = _SHPath(_SHget_hh()) / "session_handoff" + if _sh_dir.is_dir(): + _sh_parts = [] + for _sh_f in sorted(_sh_dir.glob("*.md")): + if _sh_f.is_file(): + _sh_content = _sh_f.read_text(encoding="utf-8", errors="replace") + if _sh_content.strip(): + _sh_parts.append( + f"--- Handoff: {_sh_f.name} ---\n{_sh_content.strip()}" + ) + if _sh_parts: + volatile_parts.append( + "# Session Handoff\n" + "\n\n".join(_sh_parts) + ) + except Exception: + pass + # External memory provider system prompt block (additive to built-in) if agent._memory_manager: try: