ReMe/reme/schema/notebook.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

89 lines
3.7 KiB
Python

"""Action-specific requests for the Todo and Idea jobs."""
from datetime import date
from typing import Annotated, ClassVar, Literal
from pydantic import AfterValidator, AwareDatetime, BaseModel, ConfigDict, Field, StringConstraints, model_validator
DEFAULT_PROJECT = "随笔"
NotebookProject = Annotated[
str,
StringConstraints(strip_whitespace=True),
AfterValidator(lambda value: value or DEFAULT_PROJECT),
]
class _RecordRequest(BaseModel):
"""Share pagination and reject arguments that an action would ignore."""
model_config = ConfigDict(extra="forbid", str_strip_whitespace=True)
action_fields: ClassVar[dict[str, set[str]]]
action: str
id: str | None = Field(default=None, min_length=1)
project: NotebookProject = DEFAULT_PROJECT
text: str | None = Field(default=None, min_length=1)
scope: Literal["active", "archive", "all"] = "active"
query: str = ""
offset: int = Field(default=0, ge=0)
limit: int = Field(default=20, ge=1, le=100)
@model_validator(mode="after")
def validate_action(self):
"""Validate public arguments before any workspace files are accessed."""
supplied = self.model_fields_set - {"action"}
allowed = self.action_fields[self.action]
if supplied - allowed:
raise ValueError(f"unsupported fields for {self.action}: {', '.join(sorted(supplied - allowed))}")
if self.action in {"get", "update", "archive", "restore"} and not self.id:
raise ValueError("id is required")
if "text" in supplied and self.text is None:
raise ValueError("text cannot be null")
if self.action == "create" and self.text is None and not getattr(self, "source_idea", None):
raise ValueError("text is required unless source_idea supplies it")
if self.action == "update" and not supplied - {"id"}:
raise ValueError("update requires at least one changed field")
return self
class TodoRequest(_RecordRequest):
"""Create, query and patch a task, optionally appending one progress note."""
action_fields = {
"create": {"project", "text", "status", "due_date", "source_idea", "progress_text", "progress_time"},
"list": {"project", "status", "source_idea", "scope", "query", "offset", "limit"},
"list_projects": {"scope"},
"get": {"id"},
"update": {"id", "project", "text", "status", "due_date", "source_idea", "progress_text", "progress_time"},
}
action: Literal["create", "list", "list_projects", "get", "update"]
status: Literal["open", "partial", "done", "cancelled"] = "open"
due_date: date | None = None
source_idea: str | None = Field(default=None, min_length=1)
progress_text: str | None = Field(default=None, min_length=1)
progress_time: AwareDatetime | None = None
@model_validator(mode="after")
def validate_progress(self):
"""A supplied progress timestamp must belong to a nonempty progress note."""
if "progress_text" in self.model_fields_set and self.progress_text is None:
raise ValueError("progress_text cannot be null")
if "progress_time" in self.model_fields_set and not self.progress_text:
raise ValueError("progress_time requires progress_text")
return self
class IdeaRequest(_RecordRequest):
"""Keep idea closure explicit without adding a redundant status field."""
action_fields = {
"create": {"project", "text"},
"list": {"project", "scope", "query", "offset", "limit"},
"get": {"id"},
"update": {"id", "project", "text"},
"archive": {"id"},
"restore": {"id"},
}
action: Literal["create", "list", "get", "update", "archive", "restore"]