mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-30 00:47:36 +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.
51 lines
2 KiB
Python
51 lines
2 KiB
Python
"""Delete stale workspace outputs before a job rebuilds them.
|
|
|
|
A tiny, generic housekeeping step: given workspace-relative ``paths`` (and/or
|
|
``config_keys`` resolved against the app config, e.g. ``daily_dir``), it removes
|
|
each target — file or directory — so the following steps start from a clean
|
|
slate. Missing targets are ignored, and anything resolving outside the workspace
|
|
is refused, so a misconfigured path can never wipe unrelated files.
|
|
"""
|
|
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
from ..base_step import BaseStep
|
|
from ...core.registry import R
|
|
|
|
|
|
@R.register("clear_paths_step")
|
|
class ClearPathsStep(BaseStep):
|
|
"""Remove configured files/dirs under the workspace before a rebuild."""
|
|
|
|
def _targets(self) -> list[str]:
|
|
"""Collect workspace-relative targets from ``paths`` + ``config_keys``."""
|
|
rels: list[str] = list(self.kwargs.get("paths") or [])
|
|
for key in self.kwargs.get("config_keys") or []:
|
|
value = self.config_value(key)
|
|
if value:
|
|
rels.append(str(value))
|
|
return rels
|
|
|
|
async def execute(self):
|
|
assert self.context is not None
|
|
root = self.workspace_path.resolve()
|
|
removed: list[str] = []
|
|
|
|
for rel in self._targets():
|
|
target = (self.workspace_path / rel).resolve()
|
|
# Refuse anything outside the workspace, or the workspace root itself.
|
|
if target == root or root not in target.parents:
|
|
self.logger.warning(f"[{self.name}] refusing to clear out-of-workspace path: {rel!r}")
|
|
continue
|
|
if target.is_dir() and not target.is_symlink():
|
|
shutil.rmtree(target, ignore_errors=True)
|
|
removed.append(rel)
|
|
elif target.exists() or target.is_symlink():
|
|
Path(target).unlink(missing_ok=True)
|
|
removed.append(rel)
|
|
|
|
self.context.response.metadata["cleared_paths"] = removed
|
|
if removed:
|
|
self.logger.info(f"[{self.name}] cleared {removed}")
|
|
return self.context.response
|