Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(tasks): attach claude session id before prompt

cyh512fa61c58dd
diff --git a/core/handlers/session_handler.py b/core/handlers/session_handler.py
index 5ddae7e98..b46348f1d 100644
--- a/core/handlers/session_handler.py
+++ b/core/handlers/session_handler.py
@@ -525,6 +525,12 @@ class SessionHandler(BaseHandler):
from core.system_prompt_injection import build_system_prompt_injection
platform = context.platform or (context.platform_specific or {}).get("platform") or self.config.platform
+ self.attach_agent_session_id(
+ context,
+ session_key=session_key,
+ agent_name="claude",
+ session_anchor=base_session_id,
+ )
system_prompt_injection = build_system_prompt_injection(
include_quick_replies=quick_replies_on and platform != "wechat",
diff --git a/tests/test_claude_cli_path.py b/tests/test_claude_cli_path.py
index ee745724a..0ae73733a 100644
--- a/tests/test_claude_cli_path.py
+++ b/tests/test_claude_cli_path.py
@@ -188,6 +188,44 @@ def test_session_handler_disallows_remote_unsafe_claude_tools(monkeypatch, tmp_p
assert captured["options"].disallowed_tools == ["AskUserQuestion", "EnterPlanMode", "ExitPlanMode"]
+def test_session_handler_attaches_persisted_agent_session_id_before_prompt(
+ monkeypatch, tmp_path: Path
+) -> None:
+ captured: dict[str, Any] = {}
+
+ class _PromptSessions(_Sessions):
+ @staticmethod
+ def get_agent_session_row_id(settings_key, base_session_id, agent_name):
+ assert settings_key == "test::C123"
+ assert base_session_id == "slack_C123"
+ assert agent_name == "claude"
+ return "sesk8m4q2p7x"
+
+ class _StubClaudeSDKClient:
+ def __init__(self, options):
+ captured["options"] = options
+
+ async def connect(self) -> None:
+ captured["connected"] = True
+
+ monkeypatch.setattr(session_handler_module, "ClaudeAgentOptions", _StubClaudeAgentOptions)
+ monkeypatch.setattr(session_handler_module, "ClaudeSDKClient", _StubClaudeSDKClient)
+
+ controller = _Controller(tmp_path)
+ controller.settings_manager.sessions = _PromptSessions()
+ handler = SessionHandler(controller)
+ context = MessageContext(user_id="U123", channel_id="C123")
+
+ _run_session(handler, context)
+
+ prompt_value = captured["options"].system_prompt
+ prompt = prompt_value["append"] if isinstance(prompt_value, dict) else prompt_value
+ assert captured["connected"] is True
+ assert "Current session id: `sesk8m4q2p7x`" in prompt
+ assert "--session-id sesk8m4q2p7x" in prompt
+ assert "--session-key" not in prompt
+
+
def test_session_handler_forces_bypass_mode_and_auto_approves_claude_tool_permissions(
monkeypatch, tmp_path: Path
) -> None: