mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-09-29 01:41:38 +00:00
refactor(dream): remove hardcoded DEFAULT_DIGEST_DIR and use app_config
This commit is contained in:
parent
1cbaf5a2cf
commit
3a355a657d
3 changed files with 20 additions and 28 deletions
|
|
@ -20,7 +20,7 @@ from pathlib import Path
|
|||
|
||||
import frontmatter
|
||||
|
||||
from .digest_write import DEFAULT_DIGEST_DIR, _validate_digest_path, bucket_names, normalize_buckets
|
||||
from .digest_write import _validate_digest_path, bucket_names, normalize_buckets
|
||||
from ..file_io._file_io import read_file_safe
|
||||
from ..file_io.edit import EditStep
|
||||
from ...components import R
|
||||
|
|
@ -29,12 +29,15 @@ from ...utils.wikilink_handler import WikilinkHandler
|
|||
|
||||
@R.register("digest_edit_step")
|
||||
class DigestEditStep(EditStep):
|
||||
"""EditStep variant that enforces digest path shape + E-1 edge conservation."""
|
||||
"""EditStep variant that enforces digest path shape + E-1 edge conservation.
|
||||
|
||||
def __init__(self, buckets=None, digest_dir: str | None = None, **kwargs):
|
||||
``digest_dir`` is sourced from ``app_context.app_config.digest_dir`` at
|
||||
execute time — same convention as the ``daily_*`` steps.
|
||||
"""
|
||||
|
||||
def __init__(self, buckets=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.buckets = normalize_buckets(buckets)
|
||||
self.digest_dir = (digest_dir or "").strip() or DEFAULT_DIGEST_DIR
|
||||
|
||||
def _reject(self, message: str, **meta) -> None:
|
||||
assert self.context is not None
|
||||
|
|
@ -48,8 +51,9 @@ class DigestEditStep(EditStep):
|
|||
raw = str(self.context.get("path") or "")
|
||||
old = self.context.get("old")
|
||||
new = self.context.get("new")
|
||||
digest_dir = getattr(self.app_context.app_config, "digest_dir", "")
|
||||
|
||||
err = _validate_digest_path(raw, bucket_names(self.buckets), self.digest_dir)
|
||||
err = _validate_digest_path(raw, bucket_names(self.buckets), digest_dir)
|
||||
if err:
|
||||
self._reject(err)
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -80,17 +80,18 @@ def bucket_names(buckets) -> tuple[str, ...]:
|
|||
return tuple(buckets)
|
||||
|
||||
|
||||
DEFAULT_DIGEST_DIR: str = "digest"
|
||||
|
||||
|
||||
@R.register("digest_write_step")
|
||||
class DigestWriteStep(WriteStep):
|
||||
"""WriteStep variant that enforces the ``<digest_dir>/<bucket>/<slug>.md`` layout."""
|
||||
"""WriteStep variant that enforces the ``<digest_dir>/<bucket>/<slug>.md`` layout.
|
||||
|
||||
def __init__(self, buckets=None, digest_dir: str | None = None, **kwargs):
|
||||
``digest_dir`` is sourced from ``app_context.app_config.digest_dir`` at
|
||||
execute time — same convention as ``daily_create`` / ``daily_list`` /
|
||||
``daily_reindex`` for their ``daily_dir``.
|
||||
"""
|
||||
|
||||
def __init__(self, buckets=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.buckets = normalize_buckets(buckets)
|
||||
self.digest_dir = (digest_dir or "").strip() or DEFAULT_DIGEST_DIR
|
||||
|
||||
def _reject(self, message: str) -> None:
|
||||
assert self.context is not None
|
||||
|
|
@ -100,8 +101,9 @@ class DigestWriteStep(WriteStep):
|
|||
async def execute(self):
|
||||
assert self.context is not None
|
||||
raw = str(self.context.get("path") or "")
|
||||
digest_dir = getattr(self.app_context.app_config, "digest_dir", "")
|
||||
|
||||
err = _validate_digest_path(raw, bucket_names(self.buckets), self.digest_dir)
|
||||
err = _validate_digest_path(raw, bucket_names(self.buckets), digest_dir)
|
||||
if err:
|
||||
self._reject(err)
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -198,14 +198,6 @@ class Dreamer(BaseStep):
|
|||
vr = getattr(self.file_store, "vault_path", None)
|
||||
return Path(vr).resolve() if vr else Path.cwd().resolve()
|
||||
|
||||
def _digest_dir(self) -> str:
|
||||
"""Resolve the configured digest subroot (defaults to ``"digest"``)."""
|
||||
if self.app_context is not None:
|
||||
val = getattr(self.app_context.app_config, "digest_dir", "") or ""
|
||||
if val:
|
||||
return val
|
||||
return "digest"
|
||||
|
||||
def _llm_available(self) -> bool:
|
||||
try:
|
||||
return self.as_llm is not None
|
||||
|
|
@ -275,13 +267,10 @@ class Dreamer(BaseStep):
|
|||
def _make_digest_write_tool(self):
|
||||
"""Tool closure: wraps :class:`DigestWriteStep` and tracks creates."""
|
||||
|
||||
digest_dir = self._digest_dir()
|
||||
|
||||
async def digest_write(path: str, name: str, description: str, content: str) -> ToolResponse:
|
||||
step = DigestWriteStep(
|
||||
file_store=self.file_store,
|
||||
buckets=self.buckets,
|
||||
digest_dir=digest_dir,
|
||||
app_context=self.app_context,
|
||||
)
|
||||
await step(path=path, name=name, description=description, content=content)
|
||||
|
|
@ -297,13 +286,10 @@ class Dreamer(BaseStep):
|
|||
def _make_digest_edit_tool(self):
|
||||
"""Tool closure: wraps :class:`DigestEditStep` and tracks updates / conservation violations."""
|
||||
|
||||
digest_dir = self._digest_dir()
|
||||
|
||||
async def digest_edit(path: str, old: str, new: str) -> ToolResponse:
|
||||
step = DigestEditStep(
|
||||
file_store=self.file_store,
|
||||
buckets=self.buckets,
|
||||
digest_dir=digest_dir,
|
||||
app_context=self.app_context,
|
||||
)
|
||||
await step(path=path, old=old, new=new)
|
||||
|
|
@ -388,7 +374,7 @@ class Dreamer(BaseStep):
|
|||
toolkit = self.toolkit or Toolkit()
|
||||
for job_name in _INTEGRATE_READ_TOOLS:
|
||||
self.add_as_tool(toolkit, job_name)
|
||||
digest_dir = self._digest_dir()
|
||||
digest_dir = getattr(self.app_context.app_config, "digest_dir", "")
|
||||
path_shape = f"'{digest_dir}/<bucket>/<slug>.md'"
|
||||
digest_write_desc = (
|
||||
"Create a NEW digest node — same shape as the canonical `write` job, plus "
|
||||
|
|
@ -507,7 +493,7 @@ class Dreamer(BaseStep):
|
|||
async def _integrate_unit(self, unit: dict, material_blob: str, hint: str, vault_dir: Path) -> str:
|
||||
"""One ReAct invocation per memory sub-unit. Returns LLM summary of writes."""
|
||||
toolkit = self._build_integrate_toolkit()
|
||||
digest_dir = self._digest_dir()
|
||||
digest_dir = getattr(self.app_context.app_config, "digest_dir", "")
|
||||
buckets_block = "\n".join(
|
||||
f" - `{digest_dir}/{b['name']}/`" + (f" — {b['description']}" if b.get("description") else "")
|
||||
for b in self.buckets
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue