feat(skills): 自我进化后端 — curator 配置可编辑 + 运行日志可读
后端骨架: - curator.py / usage.py / skill_tools.py:基于使用计数的生命周期管理 + LLM 合并/归档建议(同事已有原型,集中提交) - skill_evolution_config.py:CuratorConfig 嵌套模型 - app.py:启动时按间隔触发 curator 后台线程 - tools.py:开启自我进化时一并注册 skill_list / skill_view 工具 - skill_manage_tool.py:agent 创建技能时标记 source=agent 本次新增: - skill_evolution_runtime.py:skill_evolution.json 读写,原子写入 - app_config.py:把 overrides 深合并到 AppConfig.skill_evolution, 并把 overrides 的 mtime 纳入缓存失效条件,前端 PUT 后热生效 - curator_log.py:进程内 ring buffer (maxlen=200),所有 record/get 操作内部兜异常,保证 logging 永远不会让 curator 跑挂 - curator.py 关键节点插桩:run_started / 自动转换计数 / 候选数 / LLM agent invoke / 解析结果 / archive 动作 / run complete - routers/skills.py:GET/PUT /api/curator/config(写到 skill_evolution.json + reset_app_config)+ GET /api/curator/logs 测试: - tests/test_skill_evolution_runtime.py:overrides 往返、损坏 JSON 容错、AppConfig 合并、ring buffer 线程安全、record 异常吞咽 杂项: - .gitignore:忽略 .deer-flow/* 与 skills/* 等运行时目录 - uv.lock:跟随依赖锁更新 - 清理已废弃的 agent runtime 数据 SOUL.md Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
230eec1baf
commit
9b6b94d919
14 files changed
+3981
-2698
No files matched your search
@@ -0,0 +1,82 @@
|
||||
"""In-memory ring buffer holding the most recent curator run's execution log.
|
||||
|
||||
The buffer is intentionally process-local and non-persistent — restarting the
|
||||
server clears it. The Gateway exposes the buffer over ``GET /api/curator/logs``
|
||||
so the frontend can show what the latest curator pass actually did.
|
||||
|
||||
All public functions swallow internal exceptions so a logging failure can never
|
||||
break the curator run itself.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import threading
|
||||
from collections import deque
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_MAX_RECORDS = 200
|
||||
|
||||
_lock = threading.Lock()
|
||||
_buffer: deque[dict[str, Any]] = deque(maxlen=_MAX_RECORDS)
|
||||
|
||||
|
||||
def _now_iso() -> str:
|
||||
return datetime.now(UTC).isoformat()
|
||||
|
||||
|
||||
def start_new_run() -> None:
|
||||
"""Clear the buffer and emit a ``run_started`` record.
|
||||
|
||||
Called once at the top of each curator run so the frontend sees a fresh
|
||||
log stream rather than the previous run's tail.
|
||||
"""
|
||||
try:
|
||||
with _lock:
|
||||
_buffer.clear()
|
||||
_buffer.append({"ts": _now_iso(), "level": "info", "message": "run_started"})
|
||||
except Exception:
|
||||
logger.debug("curator_log.start_new_run failed", exc_info=True)
|
||||
|
||||
|
||||
def record(level: str, message: str, **fields: Any) -> None:
|
||||
"""Append a single log record. Never raises.
|
||||
|
||||
``level`` is one of ``info``/``warning``/``error``; unknown values are
|
||||
accepted and rendered verbatim by the frontend. Extra keyword arguments
|
||||
are merged into the record so callers can attach structured context.
|
||||
"""
|
||||
try:
|
||||
entry: dict[str, Any] = {
|
||||
"ts": _now_iso(),
|
||||
"level": str(level or "info"),
|
||||
"message": str(message),
|
||||
}
|
||||
if fields:
|
||||
entry.update({k: v for k, v in fields.items() if k not in entry})
|
||||
with _lock:
|
||||
_buffer.append(entry)
|
||||
except Exception:
|
||||
logger.debug("curator_log.record failed", exc_info=True)
|
||||
|
||||
|
||||
def get_recent() -> list[dict[str, Any]]:
|
||||
"""Return a snapshot copy of the buffer contents. Never raises."""
|
||||
try:
|
||||
with _lock:
|
||||
return list(_buffer)
|
||||
except Exception:
|
||||
logger.debug("curator_log.get_recent failed", exc_info=True)
|
||||
return []
|
||||
|
||||
|
||||
def clear() -> None:
|
||||
"""Drop all buffered records. Used by tests."""
|
||||
try:
|
||||
with _lock:
|
||||
_buffer.clear()
|
||||
except Exception:
|
||||
logger.debug("curator_log.clear failed", exc_info=True)
|
||||
Reference in new issue
Block a user