mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-29 00:38:33 +00:00
Some checks failed
CI and Release / Docker / Build and test / amd64 (push) Has been cancelled
CI and Release / Docker / Build and test / arm64 (push) Has been cancelled
Security / CodeQL / Analyze python (push) Has been cancelled
CI / Python quality / Pre-commit (push) Has been cancelled
CI / Python tests / Unit Tests - py3.12 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.13 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.14 (push) Has been cancelled
CI / Python packages / Build and verify distributions (push) Has been cancelled
CI / Python quality / GitHub Actions (push) Has been cancelled
CI / Python tests / Hermes embedded - ubuntu-latest (push) Has been cancelled
CI / Python tests / Hermes embedded - windows-latest (push) Has been cancelled
CI / Python tests / Unit Tests - py3.11 (push) Has been cancelled
CI / ReMe Studio / Studio checks (push) Has been cancelled
Deploy / Documentation / Build documentation (push) Has been cancelled
CI / Windows / CLI smoke - py3.11 (push) Has been cancelled
Security / CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI and Release / Docker / Publish multi-platform tags (push) Has been cancelled
Deploy / Documentation / deploy (push) Has been cancelled
* refactor(core): reorganize the ReMe runtime and shared helpers * test(status): import the base component from its canonical module * test: remove redundant unit checks * refactor(core): use canonical runtime imports and shared CLI discovery Restore evolve behavior to the base branch and update its imports. Use Application as the runtime entry point and encode SSE in the HTTP service. * fix(cli): honor caller config when service replay is incomplete Use partial startup overrides for port probes and resolve named configs before requesting the service process working directory.
50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
"""Common helpers for workspace file operations."""
|
|
|
|
from collections.abc import AsyncIterator
|
|
from contextlib import asynccontextmanager
|
|
from pathlib import Path
|
|
|
|
from ._path import check_path_permission, display_path, gate_md, resolve_path
|
|
from ..base_step import BaseStep
|
|
from ...utils.files.path_lock import get_path_lock
|
|
|
|
|
|
@asynccontextmanager
|
|
async def frontmatter_target(
|
|
workspace_path: Path,
|
|
path: str,
|
|
allowed_paths: object,
|
|
) -> AsyncIterator[tuple[Path | None, dict]]:
|
|
"""Yield a locked Markdown target or its path error payload."""
|
|
workspace = Path(workspace_path or ".").resolve()
|
|
target, error = resolve_path(workspace, path)
|
|
payload = {"path": path}
|
|
if error or target is None:
|
|
payload["error"] = error or "invalid path"
|
|
yield None, payload
|
|
return
|
|
|
|
original_target = target
|
|
target, is_md = gate_md(target)
|
|
if not check_path_permission(workspace, target, allowed_paths):
|
|
payload["error"] = "no permission to update this file"
|
|
yield None, payload
|
|
else:
|
|
async with await get_path_lock(target):
|
|
if not target.is_file():
|
|
payload["error"] = f"{display_path(workspace, target)} not found"
|
|
elif not is_md:
|
|
payload["error"] = "not markdown"
|
|
yield None if "error" in payload else target, payload
|
|
if target != original_target:
|
|
payload["resolved_path"] = display_path(workspace, target)
|
|
|
|
|
|
class _FileIOStep(BaseStep):
|
|
"""Preserve the file-operation failure envelope without changing its payload."""
|
|
|
|
def _fail(self, message: str, **meta) -> None:
|
|
assert self.context is not None
|
|
self.context.response.success = False
|
|
self.context.response.answer = f"Error: {message}"
|
|
self.context.response.metadata.update(meta)
|