mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-14 09:40:51 +08:00
初始化:独立 oclaw 仓库首提交
- 在 oclaw/ 下重新初始化 Git 仓库 - 补齐子仓库 .gitignore,避免提交本地运行态数据(_local、node_modules、logs 等) - 提交当前工程代码与配置 Made-with: Cursor
This commit is contained in:
commit
ba3836f00f
579 changed files with 83112 additions and 0 deletions
6
infrastructure/agent_context/__init__.py
Normal file
6
infrastructure/agent_context/__init__.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
"""Agent-context loaders from `oclaw/agent/*`."""
|
||||
|
||||
from .loader import build_role_system_context
|
||||
|
||||
__all__ = ["build_role_system_context"]
|
||||
|
||||
51
infrastructure/agent_context/loader.py
Normal file
51
infrastructure/agent_context/loader.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from oclaw.platform.config.paths import PROJECT_ROOT
|
||||
from oclaw.prompts.loader import render_openclaw_prompt
|
||||
|
||||
|
||||
def _read_text(path: Path) -> str:
|
||||
try:
|
||||
if path.exists() and path.is_file():
|
||||
return path.read_text(encoding="utf-8", errors="ignore").strip()
|
||||
except Exception:
|
||||
return ""
|
||||
return ""
|
||||
|
||||
|
||||
def _workspace_for_role(role: str) -> str:
|
||||
r = str(role or "").strip().lower()
|
||||
if r in {"ops", "coding"}:
|
||||
return "workspace-coding"
|
||||
if r in {"social"}:
|
||||
return "workspace-social"
|
||||
return "workspace-main"
|
||||
|
||||
|
||||
def build_role_system_context(role: str) -> str:
|
||||
"""Build role context from @agent files with prompt fallback."""
|
||||
workspace = _workspace_for_role(role)
|
||||
agent_root = (PROJECT_ROOT / "oclaw" / "agent" / workspace).resolve()
|
||||
parts: list[str] = []
|
||||
for name in ("AGENTS.md", "IDENTITY.md", "SOUL.md", "USER.md"):
|
||||
t = _read_text(agent_root / name)
|
||||
if t:
|
||||
parts.append(f"# {name}\n{t}")
|
||||
# Keep concise fallback for missing local role files.
|
||||
role_id = str(role or "").strip().lower()
|
||||
if role_id == "ops":
|
||||
fallback = render_openclaw_prompt("roles/specialists/ops/system.md", strict=True)
|
||||
elif role_id == "image":
|
||||
fallback = render_openclaw_prompt("roles/specialists/image/system.md", strict=True)
|
||||
elif role_id == "memory_curator":
|
||||
fallback = render_openclaw_prompt("roles/specialists/memory_curator/system.md", strict=True)
|
||||
else:
|
||||
fallback = render_openclaw_prompt("roles/specialists/generalist/system.md", strict=True)
|
||||
parts.append(f"# FALLBACK_ROLE_SYSTEM\n{fallback}")
|
||||
return "\n\n".join([p for p in parts if p.strip()]).strip()
|
||||
|
||||
|
||||
__all__ = ["build_role_system_context"]
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue