ReMe/reme/steps/proactive/agent/chat_reminders.py
jinliyl 524b1b6908
feat(studio): unify the workbench and proactive runtime (#764)
* fix(proactive): simplify round files and restore failed summaries

* fix(proactive): validate document-relative Markdown links

* feat(proactive_agent): implement v2 daily record workflow with single-file decision

- Add ProactiveAgentStepV2 class to support single daily note decision and reminder
- Introduce RoundOutputs for v2 round file tracking, and keep RoundArtifacts for v1 summary backup
- Refactor AgentOutbox to support both v1 standalone reminder files and v2 daily reminder records
- Add proactive_record utilities to parse and validate v2 daily record frontmatter and metadata
- Enhance proactive_agent to prepare, read, and manage artifacts for both v1 and v2 flows
- Add configuration profile proactive_v2 to enable new workflow with backward compatibility
- Update proactive.yaml and reactive proactive_agent_step configuration comment for easy switching
- Provide extensive schema validation for v2 reminders ensuring priority and message consistency
- Document v2 workflow and usage in English and Chinese runtime docs
- Add unit tests for v2 step verifying single file output and proper decision handling

* refactor(agent/runtime): replace ReminderRef with string keys and simplify reminder handling

- Remove ReminderRef model and switch to using workspace-relative string keys for reminders
- Simplify AgentOutbox to read, write, and manage reminders keyed by strings
- Change file locking and version checking to protect concurrent edits on daily record files
- Replace legacy and v2 reminder file handling with unified ReminderFiles storage
- Adjust ChatNotifications to operate with the new key scheme and update pending/read sets
- Refactor RoundOutputs to RoundRecord for safer round record tracking and rollback
- Remove unused ProactiveRunResult and related references from imports and exports
- Update InboxWakeRequest, AgentReminder, and related models for consistent ID and path validation
- Adjust proactive agent runtime and local runtime to check reminder versions before commit
- Correct language and docs to describe reminders as daily records instead of separate files
- Clean up roles of inbox and outbox for reminder ownership, delivery, and acknowledgments

* fix(proactive): serialize round commits and align desktop reminders

* refactor(proactive): unify task triggers in Proactive Runtime

* fix(proactive): bound reminder payloads and simplify receipts

* refactor(studio): share workbench and simplify proactive delivery

* fix(studio): update and centralize build dependencies

* fix(proactive): guard draft repair and verify Studio deployments

* chore(docs): update source-map-js

* feat(release): support publishing selected artifacts from a tag

* chore(studio): remove the public playground

* refactor: simplify reminders and release workflows

* fix: preserve proactive records and align release provenance

* test(proactive): remove brittle prompt and preset assertions

* fix(proactive): register reminders after input acknowledgement

* feat(notebook): list projects across todos and ideas

* feat(studio): connect mobile apps to configurable ReMe services

* fix(proactive): reserve registered reminder paths

* fix(studio): request Android local network access

* fix(proactive): reserve reminder paths referenced by receipts
2026-11-23 17:19:21 +08:00

76 lines
4 KiB
Python

"""Evaluate reminders in a disposable fork of the current Chat conversation."""
import asyncio
from contextlib import nullcontext
import math
from ....constants import CHAT_AGENT_NAME
from .chat import BaseChatAgentStep
from ....core.registry import R
from ....schema.proactive_runtime import ProcessChatRemindersRequest
@R.register("process_chat_reminders_step")
class ProcessChatRemindersStep(BaseChatAgentStep):
"""Keep automatic inference and tool traces outside the foreground session."""
def __init__(self, timeout_seconds=120, **kwargs):
super().__init__(**kwargs)
if type(timeout_seconds) not in (int, float) or not math.isfinite(timeout_seconds) or timeout_seconds <= 0:
raise ValueError("timeout_seconds must be a finite positive number")
self.timeout_seconds = timeout_seconds
async def execute(self):
request = ProcessChatRemindersRequest.model_validate(self.parameters())
self.require_paths(self.workspace_path)
async with asyncio.timeout(self.timeout_seconds):
return await self._execute(request)
async def _execute(self, request: ProcessChatRemindersRequest):
runtime = self.proactive_runtime
if not any(identifier in runtime.notifications.pending for identifier in request.msg_ids):
self.context.response.answer = {"skipped": "already_read"}
return self.context.response
active_fork = request.priority == "P0"
if not active_fork and runtime.chat_lock.locked():
self.context.response.answer = {"skipped": "busy"}
return self.context.response
async with nullcontext() if active_fork else runtime.chat_lock:
if runtime.closed:
raise RuntimeError("Agent runtime is closed")
idle = max(0, (runtime.now() - runtime.notifications.last_activity_at).total_seconds())
if request.priority != "P0" and idle < getattr(
runtime.notifications.config,
f"{request.priority.lower()}_idle_seconds",
):
self.context.response.answer = {"skipped": "not_idle"}
return self.context.response
options = self.session_options()
current = await runtime.sessions.current(CHAT_AGENT_NAME) if active_fork else None
session_id = current.session_id if current else await self.ensure_session(options)
status = await runtime.agent_wrapper.get_session_status(session_id)
if status.status not in ({"idle", "not_loaded", "active"} if active_fork else {"idle", "not_loaded"}):
self.context.response.answer = {"skipped": "busy"}
return self.context.response
if active_fork and (
len(runtime.chat_tasks) > 1 or (runtime.chat_lock.locked() and status.status != "active")
):
# Queued user input is not necessarily part of the native snapshot yet.
self.context.response.answer = {"skipped": "busy"}
return self.context.response
async with runtime.notifications.turn(session_id, request.priority, request.msg_ids) as turn:
if not turn.done and (inbox_items := await runtime.notifications.read_turn(turn)):
reply = await runtime.agent_wrapper.reply(
self.prompt_format("hint", inbox_items=inbox_items),
system_prompt=options["system_prompt"],
job_tools=["submit_chat_reminder"],
resume=session_id,
fork_session=True,
ephemeral=True,
sandbox="read-only",
injected_job_kwargs={"_agent_name": CHAT_AGENT_NAME, "_inbox_turn": turn.id},
)
if not turn.done:
raise RuntimeError(reply.get("error") or "Inbox fork ended without submitting a reminder decision")
self.context.response.answer = {"sent": bool(turn.content)}
return self.context.response