mirror of
https://github.com/andrewyng/openworker.git
synced 2026-09-13 07:40:18 +00:00
OpenWorker: initial import
Imported from andrewyng/aisuite@1b4bbf303e (contents of its platform/ directory, hoisted to the repo root). Development history prior to this commit lives in that repository. Co-authored-by: Devika <devikaverma11@gmail.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""Project context — AGENTS.md ingestion (root + global) into the system prompt."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from .secrets import state_dir
|
||||
|
||||
|
||||
def default_global_agents_path() -> Path:
|
||||
return state_dir() / "AGENTS.md"
|
||||
|
||||
|
||||
def load_agents_md(
|
||||
workspace: str | Path, *, global_path: Optional[str | Path] = None
|
||||
) -> str:
|
||||
"""Return a system-prompt block from the global and project AGENTS.md files.
|
||||
|
||||
v1 loads global (`<state-dir>/AGENTS.md`) + project-root `AGENTS.md` only;
|
||||
nested discovery is a fast-follow.
|
||||
"""
|
||||
parts: list[tuple[str, str]] = []
|
||||
|
||||
g = Path(global_path) if global_path is not None else default_global_agents_path()
|
||||
if g.is_file():
|
||||
parts.append(("global", g.read_text(encoding="utf-8")))
|
||||
|
||||
root = Path(workspace).expanduser().resolve() / "AGENTS.md"
|
||||
if root.is_file():
|
||||
parts.append(("project", root.read_text(encoding="utf-8")))
|
||||
|
||||
if not parts:
|
||||
return ""
|
||||
|
||||
blocks = [
|
||||
f"<{label} AGENTS.md>\n{text.strip()}\n</{label} AGENTS.md>"
|
||||
for label, text in parts
|
||||
]
|
||||
return "Project conventions:\n" + "\n\n".join(blocks)
|
||||
Reference in New Issue
Block a user