Repository navigation
🌱 tokens: cap AGENTS.md injection at section boundaries with a visible warning - #12156
Conversation
…e warning AGENTS.md was the one kick input with no size cap: primeAgentsMd injected the whole file plus a ~1.1 KB precedence paragraph. Follow the skills cap (maxSkillsInjectionBytes, dropped whole) but at the granularity a repo contract needs: - project.agents_md_max_bytes (default 8192, floor 2048) bounds the block. AgentsConfig.Render splits the body at #/## headings (fenced code and deeper headings stay inside their section; each resolved skill is its own unit) and keeps a section only if it fits whole. One that does not fit is dropped whole and later, smaller sections are still considered. If nothing fits, the block is header + precedence + a whole-file warning, never a fragment. - When anything is dropped a one-line '⚠️ AGENTS.md exceeded N bytes; K section(s) omitted (...): "X", "Y" — read AGENTS.md in the repository root ...' warning follows the precedence statement, before the surviving rules, and the scheduler logs the omitted sections and cap at warn. - The precedence paragraph is one sentence (~0.5 KB from ~1.1 KB); every clause the #7159/#7177 tests pin is kept. InjectionText is Render at the default cap. Closes #12129 Refs #12134 Signed-off-by: Andrew Anderson <andy@clubanderson.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
The Settings dialog has no control for the AGENTS.md cap yet (its sibling project.checkouts_dir is allowlisted under #11854); add the new key beside it so the parity guard stays green. Signed-off-by: Andrew Anderson <andy@clubanderson.com>
|
hive/awaiting-ci: the only red check here, 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 |
|
merged by Hive trusted-author auto-merge: author @clubanderson holds role owner and GitHub permission admin on repo; CI green at a5d9907. |
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
Closes #12129
Refs #12134
cc @mrbobbytables
What
primeAgentsMdinjected the whole repoAGENTS.mdplus a ~1.1 KB precedence paragraph with no cap. This follows the skills cap (maxSkillsInjectionBytes, dropped whole) but at the granularity a repo-owned contract needs — whole sections, never a clipped rule, and a warning the agent reads before the rules.Cap —
project.agents_md_max_bytesagentsmd.DefaultMaxInjectionBytes = 8192(same as the skills cap), floor 2048; yaml overrideproject.agents_md_max_bytes.AgentsConfig.Render(requestedSkills, maxBytes) (string, InjectionOmitted). The body is split at#/##headings (text before the first heading is the "(preamble)"; deeper headings and fenced code stay inside their section). Each resolved skill is its own droppable unit. Sections are visited in document order and kept only if they fit whole; one that doesn't is dropped whole and later, smaller sections are still considered, so one long section doesn't take the rest of the file down.InjectionTextis nowRenderat the default cap (same signature).Visible warning + log
> ⚠️ AGENTS.md exceeded 8192 bytes; 2 section(s) omitted (9114 bytes): "Style guide", "skill: release-notes" — read AGENTS.md in the repository root for the full instructions before you start.(names clipped to 40 bytes, at most 8 listed then "and N more", so the line is bounded and the render never exceeds the cap).
agentsmd: AGENTS.md exceeded the injection cap; sections dropped wholewithcap_bytes,omitted_sections,omitted_bytes,whole_file.Precedence paragraph → one sentence
~1.1 KB → ~0.5 KB. Every clause pinned by the existing #7159/#7177 tests (
TestInjectionTextPrecedenceFraming,TestInjectionTextPrecedenceLeadsRepositoryRules) is kept verbatim; they pass unchanged. A new test keeps it under 600 bytes and single-sentence.Tests
pkg/agentsmd/injection_cap_test.go: under cap (no warning,InjectionText == Render), cap hit (bounded, oversized section dropped whole, later sections kept in order, exact warning text, warning before rules, precedence still leads), whole-file drop, skills as units, skills header only when a skill kept, fenced#not a boundary, 8-names-then-count, default/floor, precedence one-sentence.pkg/scheduler/kick_priming_agentsmd_cap_test.go: end-to-end throughprimeAgentsMdwithproject.agents_md_max_bytes— kick text bounded, warning rendered, log line asserted; and the no-warning common case.Docs
docs/agents-md.md(new "Size cap: whole sections, visible warning" section; precedence-statement section updated),docs/operator-reference.md(Notable fields row), changelog fragment.