Skip to content

The agent that grows with you

feat: /review briefing embeds the workspace's project context files

Teknium23fb949f2c62
diff --git a/agent/review_engine.py b/agent/review_engine.py
index 6d5e8cd62d6..9a1aa6d574a 100644
--- a/agent/review_engine.py
+++ b/agent/review_engine.py
@@ -144,10 +144,41 @@ def collect_parent_loaded_skills(
return names[:limit]
+def load_workspace_context(parent_agent) -> str:
+ """Project context files (AGENTS.md / CLAUDE.md / .cursorrules ...) from
+ the parent's workspace.
+
+ Reuses the SAME discovery/priority/cap logic the main agent's system
+ prompt uses (``agent.prompt_builder.build_context_files_prompt``), pointed
+ at the parent's resolved workspace directory. Subagents are built with
+ ``skip_context_files=True``, so without this the reviewer would judge repo
+ work without the repo's own conventions unless it thought to go read them.
+
+ SOUL.md is skipped — identity belongs to the parent, not the reviewer.
+ Returns "" when no workspace can be resolved or no context files exist.
+ """
+ try:
+ from tools.delegate_tool import _resolve_workspace_hint
+
+ cwd = _resolve_workspace_hint(parent_agent)
+ except Exception:
+ cwd = None
+ if not cwd:
+ return ""
+ try:
+ from agent.prompt_builder import build_context_files_prompt
+
+ return build_context_files_prompt(cwd=str(cwd), skip_soul=True) or ""
+ except Exception:
+ logger.debug("review: workspace context load failed", exc_info=True)
+ return ""
+
+
def build_review_task(
snapshot: List[Dict[str, str]],
user_prompt: str = "",
loaded_skills: Optional[List[str]] = None,
+ workspace_context: str = "",
) -> tuple:
"""Compose the reviewer subagent's (goal, context) pair."""
goal = (
@@ -187,6 +218,15 @@ def build_review_task(
"and review standards as binding for your assessment — the work "
"was produced under them and must be judged against them."
)
+ if workspace_context.strip():
+ lines.append("")
+ lines.append(
+ "The workspace's project context files are reproduced below. "
+ "They are binding for your review — judge the work against "
+ "these conventions and invariants."
+ )
+ lines.append("")
+ lines.append(workspace_context.strip())
if user_prompt.strip():
lines.append("")
lines.append("Additional review instructions from the user:")
@@ -256,7 +296,10 @@ def start_review(
raise ValueError("Nothing to review yet — the conversation is empty.")
loaded_skills = collect_parent_loaded_skills(parent_agent, messages)
- goal, context = build_review_task(snapshot, user_prompt, loaded_skills)
+ workspace_context = load_workspace_context(parent_agent)
+ goal, context = build_review_task(
+ snapshot, user_prompt, loaded_skills, workspace_context
+ )
credentials_cfg = _load_review_credentials_cfg()
from tools.delegate_tool import delegate_task
diff --git a/tests/agent/test_review_engine.py b/tests/agent/test_review_engine.py
index cfe873072dc..bcee91bc90d 100644
--- a/tests/agent/test_review_engine.py
+++ b/tests/agent/test_review_engine.py
@@ -382,6 +382,88 @@ def test_start_review_threads_loaded_skills_into_context(monkeypatch):
assert "skill_view" in built["context"]
+# ---------------------------------------------------------------------------
+# load_workspace_context — reviewer sees the workspace's AGENTS.md et al.
+# ---------------------------------------------------------------------------
+
+def test_load_workspace_context_reads_agents_md(tmp_path, monkeypatch):
+ """Real file I/O through the same loader the main system prompt uses."""
+ import agent.review_engine as engine
+ import tools.delegate_tool as dt
+
+ workspace = tmp_path / "proj"
+ workspace.mkdir()
+ (workspace / "AGENTS.md").write_text(
+ "# Project Rules\nAll fixes must cover sibling call sites.\n"
+ )
+ monkeypatch.setattr(dt, "_resolve_workspace_hint", lambda parent: str(workspace))
+
+ out = engine.load_workspace_context(MagicMock())
+ assert "sibling call sites" in out
+ assert "Project Context" in out
+
+
+def test_load_workspace_context_empty_without_workspace(monkeypatch):
+ import agent.review_engine as engine
+ import tools.delegate_tool as dt
+
+ monkeypatch.setattr(dt, "_resolve_workspace_hint", lambda parent: None)
+ assert engine.load_workspace_context(MagicMock()) == ""
+
+
+def test_briefing_embeds_workspace_context():
+ snap = [{"role": "user", "text": "review my PR"}]
+ ctx_files = "# Project Context\n\nNo hooks without a concrete consumer."
+ _, context = build_review_task(snap, "", None, ctx_files)
+ assert "No hooks without a concrete consumer." in context
+ assert "binding for your review" in context
+
+
+def test_briefing_omits_workspace_block_when_empty():
+ _, context = build_review_task([{"role": "user", "text": "hi"}], "")
+ assert "project context files are reproduced" not in context
+
+
+def test_start_review_threads_workspace_context(monkeypatch, tmp_path):
+ import tools.delegate_tool as dt
+
+ workspace = tmp_path / "repo"
+ workspace.mkdir()
+ (workspace / "AGENTS.md").write_text("# Rules\nNever break prompt caching.\n")
+ monkeypatch.setattr(dt, "_resolve_workspace_hint", lambda parent: str(workspace))
+
+ fake_child = MagicMock()
+ fake_child._delegate_role = "leaf"
+ creds = {
+ "model": "m", "provider": None, "base_url": None, "api_key": None,
+ "api_mode": None, "command": None, "args": None,
+ }
+ built = {}
+
+ def fake_build(**kw):
+ built.update(kw)
+ return fake_child
+
+ monkeypatch.setattr(dt, "_build_child_agent", fake_build)
+ monkeypatch.setattr(dt, "_resolve_delegation_credentials", lambda *a, **k: creds)
+ monkeypatch.setattr(
+ dt, "_run_single_child",
+ lambda *a, **k: {
+ "task_index": 0, "status": "completed", "summary": "ok",
+ "api_calls": 1, "duration_seconds": 0.1, "model": "m",
+ "exit_reason": "completed",
+ },
+ )
+ monkeypatch.setattr(re_mod, "_load_review_credentials_cfg", lambda: None)
+
+ result = start_review(_fake_parent(), [
+ {"role": "user", "content": "open a PR"},
+ {"role": "assistant", "content": "PR #4 opened"},
+ ], "")
+ assert result["status"] == "dispatched"
+ assert "Never break prompt caching." in built["context"]
+
+
# ---------------------------------------------------------------------------
# Registry sync: `review` must be a first-class slot in every aux-task surface
# ---------------------------------------------------------------------------
diff --git a/website/docs/user-guide/features/delegation.md b/website/docs/user-guide/features/delegation.md
index ed32b0719bc..9b8fb9e5757 100644
--- a/website/docs/user-guide/features/delegation.md
+++ b/website/docs/user-guide/features/delegation.md
@@ -183,7 +183,7 @@ What happens:
1. The last 10 user/assistant messages are snapshotted as the reviewer's starting evidence (tool output and system messages are excluded).
2. A reviewer subagent is dispatched on the same background delegation rail as `delegate_task` — it gets the full normal subagent toolset (terminal, web, files, browser...), so it actually opens the PR, reads the diff, and runs code rather than judging from the excerpt.
-3. The reviewer inherits the primary agent's working context: any skills the primary agent had loaded (launch-preloaded or via `skill_view` during the session) are named in its briefing with an instruction to load them and judge the work against their conventions.
+3. The reviewer inherits the primary agent's working context: any skills the primary agent had loaded (launch-preloaded or via `skill_view` during the session) are named in its briefing with an instruction to load them and judge the work against their conventions, and the workspace's project context files (AGENTS.md / CLAUDE.md / .cursorrules — same discovery as the main agent's system prompt) are embedded in the briefing as binding review standards.
4. When it finishes, its full review re-enters the same session as a normal background-subagent completion — your primary agent sees it and can act on it (fix the findings, push follow-ups, reply to you).
The canonical flow: your main agent opens a PR, you type `/review`, and a second pair of eyes investigates it while you keep working; the review lands back in the chat addressed to the agent that created the PR.
diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/delegation.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/delegation.md
index 4ca96ec30c5..2a7ab9c04cb 100644
--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/delegation.md
+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/delegation.md
@@ -174,7 +174,7 @@ delegation:
1. 最近 10 条用户/助手消息被快照为评审者的起始证据(工具输出和系统消息被排除)。
2. 评审子智能体在与 `delegate_task` 相同的后台委派通道上派发——它拥有完整的常规子智能体工具集(终端、网络、文件、浏览器等),因此会实际打开 PR、阅读 diff、运行代码,而不是仅凭摘录下判断。
-3. 评审者继承主智能体的工作上下文:主智能体已加载的技能(启动预加载或会话中通过 `skill_view` 加载)会列在其简报中,并指示其加载这些技能、以其约定为标准评判工作。
+3. 评审者继承主智能体的工作上下文:主智能体已加载的技能(启动预加载或会话中通过 `skill_view` 加载)会列在其简报中,并指示其加载这些技能、以其约定为标准评判工作;工作区的项目上下文文件(AGENTS.md / CLAUDE.md / .cursorrules——与主智能体系统提示相同的发现逻辑)也会嵌入简报,作为具有约束力的评审标准。
4. 完成后,完整评审作为常规后台子智能体完成事件重新进入同一会话——你的主智能体可以看到并据此行动(修复问题、推送后续提交、回复你)。
典型流程:主智能体开了一个 PR,你输入 `/review`,第二双眼睛在你继续工作的同时对其进行调查;评审结果回到聊天中,交给创建该 PR 的智能体。