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.
60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
"""Load a complete text file for an interactive editor."""
|
|
|
|
from datetime import datetime
|
|
|
|
from ._base import _FileIOStep
|
|
from ._file_io import read_file_safe
|
|
from ._path import check_path_permission, resolve_path
|
|
from ...core.registry import R
|
|
|
|
DEFAULT_EDITOR_MAX_BYTES = 5 * 1024 * 1024
|
|
|
|
|
|
@R.register("load_step")
|
|
class LoadStep(_FileIOStep):
|
|
"""Return complete text without the truncation used by agent-facing reads."""
|
|
|
|
async def execute(self):
|
|
assert self.context is not None
|
|
raw_path = str(self.context.get("path") or "")
|
|
max_bytes = int(self.context.get("max_bytes") or self.kwargs.get("max_bytes") or DEFAULT_EDITOR_MAX_BYTES)
|
|
target, error = resolve_path(self.workspace_path, raw_path)
|
|
if error or target is None:
|
|
self._fail(error or "invalid path", path=raw_path)
|
|
return self.context.response
|
|
if not check_path_permission(self.workspace_path, target, self.context.get("_allowed_paths")):
|
|
self._fail("no permission to read this file", path=raw_path)
|
|
return self.context.response
|
|
if not target.is_file():
|
|
self._fail("file does not exist", path=raw_path)
|
|
return self.context.response
|
|
|
|
stat = target.stat()
|
|
if stat.st_size > max_bytes:
|
|
self._fail(
|
|
f"file is too large for the editor ({stat.st_size} bytes; limit {max_bytes})",
|
|
code="file_too_large",
|
|
path=raw_path,
|
|
size=stat.st_size,
|
|
max_bytes=max_bytes,
|
|
)
|
|
return self.context.response
|
|
try:
|
|
content, encoding = await read_file_safe(target, max_bytes=max_bytes)
|
|
except Exception as exc: # pylint: disable=broad-except
|
|
self._fail(f"load failed: {exc}", path=raw_path)
|
|
return self.context.response
|
|
|
|
self.context.response.success = True
|
|
self.context.response.answer = content
|
|
self.context.response.metadata.update(
|
|
{
|
|
"path": raw_path,
|
|
"exists": True,
|
|
"type": "file",
|
|
"size": stat.st_size,
|
|
"mtime": datetime.fromtimestamp(stat.st_mtime).isoformat(),
|
|
"encoding": encoding,
|
|
},
|
|
)
|
|
return self.context.response
|