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.

feat(tasks): inject scheduled task guidance

cyh2a6e40003a03
diff --git a/core/handlers/session_handler.py b/core/handlers/session_handler.py
index 6041e6e75..19d58bcd2 100644
--- a/core/handlers/session_handler.py
+++ b/core/handlers/session_handler.py
@@ -382,7 +382,10 @@ class SessionHandler(BaseHandler):
platform = context.platform or (context.platform_specific or {}).get("platform") or self.config.platform
- reply_prompt = build_reply_enhancements_prompt(include_quick_replies=platform != "wechat")
+ reply_prompt = build_reply_enhancements_prompt(
+ include_quick_replies=platform != "wechat",
+ context=context,
+ )
if base_prompt:
final_system_prompt = f"{base_prompt}\n\n{reply_prompt}"
diff --git a/core/reply_enhancer.py b/core/reply_enhancer.py
index a5d4d6633..909de848d 100644
--- a/core/reply_enhancer.py
+++ b/core/reply_enhancer.py
@@ -16,9 +16,11 @@ import logging
import os
import re
from dataclasses import dataclass, field
-from typing import List, Tuple
+from typing import List, Optional, Tuple
from urllib.parse import unquote, urlparse
+from modules.im import MessageContext
+
logger = logging.getLogger(__name__)
# ---------------------------------------------------------------------------
@@ -182,13 +184,55 @@ Rules:
- Use at most 2-4 buttons, each no longer than 20 characters
"""
+_SCHEDULED_TASKS_PROMPT = """\
+
+## 3. Scheduled tasks
+You can create scheduled tasks with the `vibe task add` command.
+
+Current conversation targeting:
+- Default session key: `{session_key}`
+- Current thread ID: `{thread_id}`
+
+Rules:
+- The default session key intentionally does not include a thread ID.
+- Only append `::thread::<thread_id>` to `--session-key` when the user explicitly wants the scheduled task to keep replying in the current thread.
+- Use `--cron "<expr>"` for recurring tasks or `--at "<ISO-8601>"` for one-off tasks.
+- Use `--prompt "..."` or `--prompt-file <path>` to provide the task content.
+
+Examples:
+- Default scope: `vibe task add --session-key '{session_key}' --cron '0 * * * *' --prompt 'Send the hourly update.'`
+- Current thread only when needed: `vibe task add --session-key '{session_key_with_thread}' --cron '0 9 * * *' --prompt 'Post the daily summary in this thread.'`
+"""
+
+
+def _build_scheduled_tasks_prompt(context: MessageContext) -> str:
+ from core.scheduled_tasks import build_session_key_for_context
+
+ default_key = build_session_key_for_context(context, include_thread=False).to_key(include_thread=False)
+ thread_id = context.thread_id or "(none)"
+ if context.thread_id:
+ session_key_with_thread = f"{default_key}::thread::{context.thread_id}"
+ else:
+ session_key_with_thread = f"{default_key}::thread::<thread_id>"
+ return _SCHEDULED_TASKS_PROMPT.format(
+ session_key=default_key,
+ thread_id=thread_id,
+ session_key_with_thread=session_key_with_thread,
+ )
+
-def build_reply_enhancements_prompt(*, include_quick_replies: bool = True) -> str:
+def build_reply_enhancements_prompt(
+ *,
+ include_quick_replies: bool = True,
+ context: Optional[MessageContext] = None,
+) -> str:
"""Build the reply-enhancement prompt for the current platform/backend."""
prompt = _FILES_PROMPT
if include_quick_replies:
prompt += _QUICK_REPLIES_PROMPT
+ if context is not None:
+ prompt += _build_scheduled_tasks_prompt(context)
return prompt
diff --git a/core/scheduled_tasks.py b/core/scheduled_tasks.py
index 351f54e90..ee33af5d7 100644
--- a/core/scheduled_tasks.py
+++ b/core/scheduled_tasks.py
@@ -42,9 +42,9 @@ class ParsedSessionKey:
def is_dm(self) -> bool:
return self.scope_type == "user"
- def to_key(self) -> str:
+ def to_key(self, *, include_thread: bool = True) -> str:
base = f"{self.platform}::{self.scope_type}::{self.scope_id}"
- if self.thread_id:
+ if include_thread and self.thread_id:
return f"{base}::thread::{self.thread_id}"
return base
@@ -75,6 +75,20 @@ def parse_session_key(value: str) -> ParsedSessionKey:
)
+def build_session_key_for_context(context: MessageContext, *, include_thread: bool = False) -> ParsedSessionKey:
+ payload = context.platform_specific or {}
+ platform = context.platform or payload.get("platform") or ""
+ is_dm = bool(payload.get("is_dm", False))
+ scope_type = "user" if is_dm else "channel"
+ scope_id = context.user_id if is_dm else context.channel_id
+ return ParsedSessionKey(
+ platform=platform,
+ scope_type=scope_type,
+ scope_id=scope_id,
+ thread_id=context.thread_id if include_thread else None,
+ )
+
+
@dataclass
class ScheduledTask:
id: str
diff --git a/modules/agents/codex/agent.py b/modules/agents/codex/agent.py
index a09df977c..1ac3fdced 100644
--- a/modules/agents/codex/agent.py
+++ b/modules/agents/codex/agent.py
@@ -272,7 +272,8 @@ class CodexAgent(BaseAgent):
from core.reply_enhancer import build_reply_enhancements_prompt
params["developerInstructions"] = build_reply_enhancements_prompt(
- include_quick_replies=platform != "wechat"
+ include_quick_replies=platform != "wechat",
+ context=request.context,
)
resp = await transport.send_request("thread/start", params)
diff --git a/modules/agents/opencode/agent.py b/modules/agents/opencode/agent.py
index f35fe48ed..1e8a5367c 100644
--- a/modules/agents/opencode/agent.py
+++ b/modules/agents/opencode/agent.py
@@ -240,7 +240,10 @@ class OpenCodeAgent(OpenCodeMessageProcessorMixin, BaseAgent):
if getattr(self.controller.config, "reply_enhancements", True):
from core.reply_enhancer import build_reply_enhancements_prompt
- reply_system = build_reply_enhancements_prompt(include_quick_replies=platform != "wechat")
+ reply_system = build_reply_enhancements_prompt(
+ include_quick_replies=platform != "wechat",
+ context=request.context,
+ )
request_tools = {"question": False} if platform == "wechat" else None
diff --git a/tests/test_reply_enhancer_platform.py b/tests/test_reply_enhancer_platform.py
index 6cac79218..351dbd666 100644
--- a/tests/test_reply_enhancer_platform.py
+++ b/tests/test_reply_enhancer_platform.py
@@ -66,6 +66,23 @@ class ReplyEnhancerPlatformTests(unittest.IsolatedAsyncioTestCase):
self.assertIn("## 1. Send files", prompt)
self.assertNotIn("## 2. Quick-reply buttons", prompt)
+ def test_prompt_includes_scheduled_task_usage_with_threadless_default_session_key(self):
+ context = MessageContext(
+ user_id="U1",
+ channel_id="C1",
+ platform="slack",
+ thread_id="171717.123",
+ platform_specific={"is_dm": False},
+ )
+
+ prompt = build_reply_enhancements_prompt(include_quick_replies=True, context=context)
+
+ self.assertIn("## 3. Scheduled tasks", prompt)
+ self.assertIn("`vibe task add`", prompt)
+ self.assertIn("Default session key: `slack::channel::C1`", prompt)
+ self.assertIn("Current thread ID: `171717.123`", prompt)
+ self.assertIn("slack::channel::C1::thread::171717.123", prompt)
+
def test_file_links_with_parentheses_are_preserved(self):
enhanced = process_reply("![video](file:///Users/test/SaveTwitter.Net_GABV3XNWYAARAZz(gif).mp4)")
diff --git a/tests/test_scheduled_tasks.py b/tests/test_scheduled_tasks.py
index d24c13a97..487a81b83 100644
--- a/tests/test_scheduled_tasks.py
+++ b/tests/test_scheduled_tasks.py
@@ -8,7 +8,13 @@ from types import SimpleNamespace
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
-from core.scheduled_tasks import ScheduledTaskService, ScheduledTaskStore, parse_session_key
+from core.scheduled_tasks import (
+ ScheduledTaskService,
+ ScheduledTaskStore,
+ build_session_key_for_context,
+ parse_session_key,
+)
+from modules.im import MessageContext
class _StubScheduler:
@@ -54,6 +60,21 @@ def test_parse_session_key_rejects_invalid_scope_type() -> None:
raise AssertionError("expected invalid scope type to raise ValueError")
+def test_build_session_key_for_context_defaults_to_threadless_scope() -> None:
+ context = MessageContext(
+ user_id="U123",
+ channel_id="C123",
+ platform="slack",
+ thread_id="171717.123",
+ platform_specific={"is_dm": False},
+ )
+
+ parsed = build_session_key_for_context(context)
+
+ assert parsed.to_key(include_thread=False) == "slack::channel::C123"
+ assert parsed.thread_id is None
+
+
def test_store_round_trip_persists_task(tmp_path: Path) -> None:
store = ScheduledTaskStore(tmp_path / "scheduled_tasks.json")
task = store.add_task(