From 22e9ca220770ee47454cc812842b6667bcd928a6 Mon Sep 17 00:00:00 2001 From: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com> Date: Tue, 8 Sep 2026 13:21:35 -0700 Subject: [PATCH 1/2] fix(anchors): resolve workspace agents from session cwd Ensure the anchors bundle loads the optional workspace AGENTS.md relative to the session cwd, with regression coverage for nested self-references and missing files. Generated with Amplifier Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com> --- bundles/anchors/context/system.md | 2 + .../test_instruction_mentions_lead_context.py | 62 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/bundles/anchors/context/system.md b/bundles/anchors/context/system.md index 79dabce3..ad271562 100644 --- a/bundles/anchors/context/system.md +++ b/bundles/anchors/context/system.md @@ -14,3 +14,5 @@ Generated with Amplifier Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com> ``` + +@AGENTS.md diff --git a/tests/test_instruction_mentions_lead_context.py b/tests/test_instruction_mentions_lead_context.py index 4c9b781f..b63be337 100644 --- a/tests/test_instruction_mentions_lead_context.py +++ b/tests/test_instruction_mentions_lead_context.py @@ -102,6 +102,11 @@ def _write(path: Path, content: str) -> Path: return path +_ANCHORS_SYSTEM = ( + Path(__file__).parent.parent / "bundles" / "anchors" / "context" / "system.md" +) + + @pytest.mark.asyncio async def test_public_factory_uses_prepared_bundle_and_target_session( tmp_path: Path, @@ -299,3 +304,60 @@ async def test_mentions_resolved_payload_semantics_unchanged(tmp_path: Path) -> # The instruction's mention now leads the resolutions list as well. assert payload["resolutions"][0]["mention"] == "@ns:context/system.md" + + +@pytest.mark.asyncio +async def test_anchors_system_loads_session_cwd_agents_not_bundle_or_process_cwd( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + """The actual anchors system mention resolves nested @AGENTS.md in session_cwd.""" + anchors_root = _ANCHORS_SYSTEM.parent.parent + assert _ANCHORS_SYSTEM.read_text(encoding="utf-8").endswith("```\n\n@AGENTS.md\n") + + session_cwd = tmp_path / "session-cwd" + cwd_agents = _write( + session_cwd / "AGENTS.md", + "SESSION CWD AGENTS\n@AGENTS.md", + ) + bundle_root = tmp_path / "bundle-root" + _write(bundle_root / "AGENTS.md", "BUNDLE-LOCAL AGENTS DECOY") + process_cwd = tmp_path / "process-cwd" + _write(process_cwd / "AGENTS.md", "PROCESS CWD AGENTS DECOY") + monkeypatch.chdir(process_cwd) + + bundle = Bundle( + name="host", + base_path=bundle_root, + source_base_paths={"anchors": anchors_root}, + instruction="@anchors:context/system.md", + ) + prompt = await _make_prepared(bundle)._create_system_prompt_factory( + bundle, _make_mock_session(), session_cwd=session_cwd + )() + + assert str(cwd_agents.resolve()) in prompt + assert prompt.count("SESSION CWD AGENTS") == 1 + assert "BUNDLE-LOCAL AGENTS DECOY" not in prompt + assert "PROCESS CWD AGENTS DECOY" not in prompt + + +@pytest.mark.asyncio +async def test_anchors_system_missing_cwd_agents_is_nonfatal(tmp_path: Path) -> None: + """Absent optional cwd AGENTS.md leaves the anchors system prompt usable.""" + bundle_root = tmp_path / "bundle-root" + _write(bundle_root / "AGENTS.md", "BUNDLE-LOCAL AGENTS DECOY") + session_cwd = tmp_path / "session-cwd" + session_cwd.mkdir() + bundle = Bundle( + name="host", + base_path=bundle_root, + source_base_paths={"anchors": _ANCHORS_SYSTEM.parent.parent}, + instruction="@anchors:context/system.md", + ) + + prompt = await _make_prepared(bundle)._create_system_prompt_factory( + bundle, _make_mock_session(), session_cwd=session_cwd + )() + + assert "You are Amplifier" in prompt + assert "BUNDLE-LOCAL AGENTS DECOY" not in prompt From 0a86558f4b95f198cdee83c3a19904a559ff9610 Mon Sep 17 00:00:00 2001 From: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com> Date: Tue, 8 Sep 2026 13:31:46 -0700 Subject: [PATCH 2/2] fix(anchors): account for required cwd rule in lean budget Raise the pinned system prompt budget by 12 characters for the required cwd AGENTS rule and update the census saving from 600 to 588 characters. Generated with Amplifier Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com> --- docs/lanes/zc6t-lean-head-ship/DONE-NOTE.md | 10 ++++++++++ tests/test_lean_head_guardrail.py | 12 +++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/lanes/zc6t-lean-head-ship/DONE-NOTE.md b/docs/lanes/zc6t-lean-head-ship/DONE-NOTE.md index 3bbd27c9..19df8ec0 100644 --- a/docs/lanes/zc6t-lean-head-ship/DONE-NOTE.md +++ b/docs/lanes/zc6t-lean-head-ship/DONE-NOTE.md @@ -291,3 +291,13 @@ pin **per artifact**, never to a whole-head absolute · draft PR, ready on green Two children (`4qg2`, `va53`) additionally require their **no-op** target (`web_search`, `mode`) to be verified and **stated** — an unchanged file in a PR is noise, but a silently skipped one is a gap. + +## Addendum — 2026-09-08 + +The current static census for `bundles/anchors/context/system.md` is 1,154 +chars, +12 over its recorded 1,142-char lean budget. The required `@AGENTS.md` +rule auto-loads session-CWD `AGENTS.md`, so the budget is pinned at 1,154 rather +than compressing unrelated prompt text. The owned-head total is now 3,392 chars +against the unchanged 3,980-char stock: a current saving of 588 chars versus the +original 600. Historical experimental results above are unchanged; no vendor +cache metrics were rerun. diff --git a/tests/test_lean_head_guardrail.py b/tests/test_lean_head_guardrail.py index 49128dfb..45191b36 100644 --- a/tests/test_lean_head_guardrail.py +++ b/tests/test_lean_head_guardrail.py @@ -74,7 +74,8 @@ # above what shipped would let the head regrow up to it silently, which is the # whole failure mode. OWNED_HEAD_BUDGET_CHARS = { - "bundles/anchors/context/system.md": 1142, + # Required cwd-AGENTS auto-loading rule costs +12 chars. + "bundles/anchors/context/system.md": 1154, "bundles/anchors-amp-dev/context/amplifier-ecosystem.md": 1300, "delegate:preamble": 938, } @@ -247,10 +248,11 @@ def test_the_owned_head_is_smaller_than_it_was(self) -> None: lean = sum(OWNED_HEAD_BUDGET_CHARS.values()) stock = sum(OWNED_HEAD_STOCK_CHARS.values()) assert lean < stock, f"lean {lean} is not below stock {stock}" - assert stock - lean == 600, ( - f"The recorded saving moved: {stock - lean} chars, was 600. Update " - "both tables and the DONE-NOTE together, or the published census " - "and this repo disagree." + assert stock - lean == 588, ( + f"The current saving moved: {stock - lean} chars, expected 588 " + "after the original measured 600-char saving absorbed the required " + "cwd-AGENTS rule. Update the budget and DONE-NOTE together, or the " + "current census and this repo disagree." )