ReMe/reme/components/proactive_manager/_internal/reminder_files.py
jinliyl ae55e2e570
Some checks are pending
CI / Python packages / Build and verify distributions (push) Waiting to run
CI / Python quality / GitHub Actions (push) Waiting to run
CI / Python quality / Pre-commit (push) Waiting to run
CI / Python tests / Hermes embedded - ubuntu-latest (push) Waiting to run
CI / Python tests / Hermes embedded - windows-latest (push) Waiting to run
CI / Python tests / Unit Tests - py3.11 (push) Waiting to run
CI / Python tests / Unit Tests - py3.12 (push) Waiting to run
CI / Python tests / Unit Tests - py3.13 (push) Waiting to run
CI / Python tests / Unit Tests - py3.14 (push) Waiting to run
CI / ReMe Studio / Studio checks (push) Waiting to run
CI / Windows / CLI smoke - py3.11 (push) Waiting to run
Deploy / Documentation / Build documentation (push) Waiting to run
Deploy / Documentation / deploy (push) Blocked by required conditions
Security / CodeQL / Analyze javascript-typescript (push) Waiting to run
Security / CodeQL / Analyze python (push) Waiting to run
feat!: split proactive runtimes and add Studio backend management (#776)
* refactor(proactive)!: separate runtime ownership and unify delivery

* refactor(proactive): finish runtime and Studio migration

* test(proactive): make scheduled skip coverage deterministic

* refactor(studio): unify navigation and notebook resource loading

* feat(studio): edit workspace documents and update proactive task names

* refactor(studio): simplify task settings and navigation

* feat(studio): secure and supervise backend settings

* feat(studio): unify workbench timelines and refine desktop updates

Use shared timeline panes for notebook, memory, and resources. Add Todo creation ordering, persist companion visibility, and align desktop update handling and release artifacts.

Recheck editor file versions at read and publication boundaries. Retry reminder detail requests from the resource view.

* fix(studio): support unsigned GitHub preview releases

* fix: verify container state and isolate proactive view errors

Mount private supervisor state in Docker smoke tests and verify token and settings persistence. Exercise Studio startup with a loopback-only model fixture, and exclude packaged desktop output from Docker contexts.

Keep Remy subscriptions and healthy tasks available when an individual task has an invalid workspace path or session history.

* fix(home): align candidate Docker context exclusions

* chore(deps): update openai-codex dependency to v0.172.0

- Bump openai-codex from version 0.169.0 to 0.172.0 in pyproject.toml
- Keep other dependencies unchanged
- Ensure compatibility with latest openai-codex features and fixes

* fix(daemon): discover parent dotenv and isolate listeners

Restore parent-directory environment discovery in workers while retaining system precedence. Partition the default supervisor profile and lock by the configured bind address and port.
2026-11-25 21:33:16 +08:00

77 lines
3.2 KiB
Python

"""Read reminder content from daily records and state from the task outbox."""
from pathlib import Path
from pydantic import AwareDatetime, BaseModel, ConfigDict, Field
from ....schema.proactive_agent import ProactiveRecordDecision
from ....schema.proactive_runtime import ChatMessageId
from ....utils.proactive_record import is_date_directory, is_round_record, split_record
class ReminderState(BaseModel):
"""The delivery and processing state owned by ReMe."""
model_config = ConfigDict(extra="forbid")
delivered_at: AwareDatetime
read_at: AwareDatetime | None = None
chat_message_ids: list[ChatMessageId] = Field(default_factory=list)
class ReminderFiles:
"""Use one outbox state file for each registered daily record."""
def __init__(self, files, daily_dir, agent_dir):
self.files = files
self.daily_dir = files.path(daily_dir)
self.relative_dir = self.daily_dir.relative_to(files.workspace)
self.agent_dir = agent_dir
def _outbox(self, agent_name):
return self.files.checked(self.agent_dir / agent_name / "outbox" / self.relative_dir)
def state_path(self, agent_name, path):
"""Locate the registration and Chat state for one source file."""
return self.files.checked(self._outbox(agent_name) / path.parent.name / path.with_suffix(".json").name)
def paths(self, agent_name):
"""Discover sources from the task's persisted registrations."""
for state in self._outbox(agent_name).glob("????-??-??/*.json"):
path = self.daily_dir / state.parent.name / state.with_suffix(".md").name
if self.owns(path.relative_to(self.files.workspace).as_posix(), agent_name):
yield path, state
def owns(self, ref, agent_name):
"""Recognize a canonical reference even if its record is temporarily unavailable."""
if not isinstance(ref, str):
return False
path = Path(ref)
return (
path.parent.parent == self.relative_dir
and path.as_posix() == ref
and is_date_directory(path.parent)
and is_round_record(path, agent_name)
)
def decision(self, path):
"""Read the model's reminder decision from the original Markdown."""
metadata, _ = split_record(self.files.read(path))
return ProactiveRecordDecision.parse(metadata)
def read(self, agent_name, path):
"""Join framework-owned state with the current reminder text."""
try:
state = ReminderState.model_validate_json(self.files.read(self.state_path(agent_name, path)))
except FileNotFoundError:
return None
ref = path.relative_to(self.files.workspace).as_posix()
item = self.decision(path).reminder(ref)
if item is None:
raise ValueError(f"Registered record no longer requests a reminder: {path}")
return item.model_copy(update=state.model_dump())
def write(self, agent_name, path, item):
"""Persist delivery state without rewriting the original Markdown."""
state = item.model_dump(mode="json", include=set(ReminderState.model_fields), exclude_defaults=True)
self.files.write_json(self.state_path(agent_name, path), state)