feat(context-files): merged AGENTS.md directory chain from git root to cwd (port of grok-cli) - #80781
Merged
Merged
Conversation
Contributor
૮ >ﻌ< ა ci reviewran on 162778b
|
Contributor
|
This was generated by AI during triage. Summary: Problems:
Solution: Checked against |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sessions launched deep inside a monorepo now see the whole
AGENTS.mdchain — git root down through every intermediate directory to cwd — merged into the system prompt at session build, instead of only the single cwd file. Port of superagent-ai/grok-cli's directory-chain instructions loading (src/utils/instructions.ts,directoryChain+loadAgentsSegments).What changed
agent/prompt_builder.py_agents_md_directory_chain(cwd): computes git root → cwd directory list (root first, cwd last). Without a git root — or when cwd sits outside it — the chain is[cwd]only, so parents are never consulted and a strayAGENTS.mdin/tmp/$HOMEcan't leak in (mirrors the existing_find_hermes_mdsafety rationale)._load_agents_mdnow walks that chain: each directory contributes itsAGENTS.md/agents.md(first name wins per dir) as a provenance-labelled section (## ../../AGENTS.md, …,## AGENTS.md), deeper files last so more specific guidance takes precedence._scan_context_contentsecurity scan and per-file_truncate_contentbudget; a multi-file merge is additionally capped by the same total budget so a deep monorepo can't multiply context-file spend unbounded.website/docs/user-guide/features/context-files.md— documents the chain with a monorepo diagram; existing progressive-subdirectory-hints docs unchanged (that mechanism already dedupes by content digest, so files injected at startup that hints later re-discover are the same bytes and its own digest guard plus install-tree exclusions still apply).tests/agent/test_prompt_builder.py— 5 new tests (chain merge + ordering + provenance headers, gap skipping, dedup, byte-identical single-file output, no-git-root cwd-only isolation).Complementary, not duplicate (dupe sweep done)
@<path>include expansion) — explicit opt-in includes; this is automatic discovery. Complementary..hermes.md+AGENTS.md+CLAUDE.mdat one directory; this mergesAGENTS.mdacross directories. Orthogonal axes; both keep the first-match/type structure intact.AGENTS.override.md) — override variant at cwd; layered cleanly on top of this if both land.agent/subdirectory_hints.py) — covers dirs below cwd discovered mid-session; this covers dirs above cwd at startup. No overlap.Validation
scripts/run_tests.sh tests/agent/test_prompt_builder.pyruff checkon touched filesscripts/audit_pr_attribution.py --fixtest_agents_md_single_file_output_unchanged)test_agents_md_no_git_root_stays_cwd_only)Infographic