mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-27 23:58:47 +00:00
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
* 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.
91 lines
3.2 KiB
Python
91 lines
3.2 KiB
Python
"""Daily record paths, Markdown parsing, and version tracking for proactive tasks."""
|
|
|
|
from datetime import date
|
|
from pathlib import Path
|
|
import re
|
|
from stat import S_ISREG
|
|
|
|
import yaml
|
|
|
|
from .async_utils import complete_in_thread
|
|
from .files.path_lock import get_path_lock
|
|
from .files.workspace_files import WorkspaceFiles
|
|
|
|
_ROUND_SUFFIX = re.compile(r"[0-9]{6}(?:_[0-9]+)?\.md")
|
|
_FRONTMATTER = re.compile(r"\A(?:[ \t]*\r?\n)*---[ \t]*\r?\n(.*?)^---[ \t]*(?=\r?$)", re.MULTILINE | re.DOTALL)
|
|
|
|
|
|
def is_round_record(path, agent_name):
|
|
"""Check whether the filename matches this agent's round record format."""
|
|
prefix = f"{agent_name}_"
|
|
name = path.name
|
|
return name.startswith(prefix) and _ROUND_SUFFIX.fullmatch(name[len(prefix) :]) is not None
|
|
|
|
|
|
def is_date_directory(path):
|
|
"""Recognize the application's ISO date folder names."""
|
|
try:
|
|
return date.fromisoformat(path.name).isoformat() == path.name
|
|
except ValueError:
|
|
return False
|
|
|
|
|
|
def _split_frontmatter(text):
|
|
text = text.removeprefix("\ufeff")
|
|
if match := _FRONTMATTER.match(text):
|
|
return match[1], text[match.end() :]
|
|
return None, text
|
|
|
|
|
|
def split_record(text):
|
|
"""Read YAML metadata while keeping the exact Markdown suffix for state updates."""
|
|
header, body = _split_frontmatter(text)
|
|
if header is not None:
|
|
metadata = yaml.safe_load(header)
|
|
if isinstance(metadata, dict):
|
|
return metadata, body
|
|
return {}, text.removeprefix("\ufeff")
|
|
|
|
|
|
class RoundRecord:
|
|
"""Track the record's version until the input receipt is durable."""
|
|
|
|
def __init__(self, files: WorkspaceFiles):
|
|
self.files = files
|
|
self.path: Path | None = None
|
|
self.written = None
|
|
|
|
def _version(self, path):
|
|
try:
|
|
stat = self.files.checked(path).stat(follow_symlinks=False)
|
|
except FileNotFoundError:
|
|
return None
|
|
if not S_ISREG(stat.st_mode):
|
|
raise ValueError(f"Round record must be a regular file: {path}")
|
|
return stat.st_ino, stat.st_mtime_ns, stat.st_size
|
|
|
|
async def prepare(self, path: Path):
|
|
"""Ensure the model starts with an unused record path."""
|
|
async with await get_path_lock(path):
|
|
if await complete_in_thread(self._version, path) is not None:
|
|
raise FileExistsError(path)
|
|
self.path = path
|
|
|
|
def capture(self):
|
|
"""Capture the version visible after the model turn for validation."""
|
|
try:
|
|
self.written = self._version(self.path)
|
|
except (OSError, ValueError):
|
|
# Validation reports invalid or unreadable destinations.
|
|
self.written = None
|
|
|
|
def check_version(self, path: Path):
|
|
"""Reject edits made before commit, including a file created after a skip."""
|
|
if path != self.path or self._version(path) != self.written:
|
|
raise RuntimeError(f"Agent output changed outside this round: {path}")
|
|
|
|
def read_body_for_repair(self) -> str | None:
|
|
"""Keep a copy of the body when the original frontmatter is delimited."""
|
|
self.check_version(self.path)
|
|
header, body = _split_frontmatter(self.files.read(self.path))
|
|
return body if header is not None else None
|