Skip to content

Plan / Interface: admitted AGENTS.md hierarchy - #2092

Merged
JAORMX merged 8 commits into
mainfrom
plan/agents-instruction-hierarchy
Oct 6, 2026
Merged

JAORMX merged 8 commits into
mainfrom
plan/agents-instruction-hierarchy

Conversation

@JAORMX

@JAORMX JAORMX commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Plan / interface

Relates to #2090.

Documentation-only plan; hierarchy support is not implemented or claimed shipped. Existing public and architecture guides remain unchanged until implementation.

Agreed MVP behavior

  • Load the selected admitted source's root-to-starting-folder chain initially, then discover applicable nested guidance through covered structured file tools. Never scan the whole repository, unrelated modules, or siblings. No Shell inference.
  • A default source rooted at a starting subfolder excludes parent/repository-root guidance. Only an explicitly selected admitted broader source can contribute its ancestors. Traversal never admits another source or expands instruction authority.
  • Deliver newly discovered guidance on the next model request. Keep already-loaded scopes and text across follow-up messages, approval continuations, and compaction in the same live session. No automatic live refresh. Reopening after process/server restart may rediscover current guidance lazily; automatic bodies are not persisted in conversation, events, or snapshots.
  • Fresh-context subagents load current guidance from inherited admitted sources; conversation forks inherit the parent's loaded snapshot. Children have independent subsequent discovery/budgets. Ordinary worktree forks support nested discovery through existing trusted mapping, not child-checkout source authority.
  • Resolve AGENTS.md first in each applicable directory, falling back to CLAUDE.md only for missing/blank AGENTS.md, never for a read error.
  • Use a configurable 64 KiB combined project-instruction content default, with safe truncation/omission labels and actual client-visible warnings. Bounds stop automatic loading, not authorized tools.
  • Extend existing assembler/discovery/manifest and composition contracts in place; no parallel replacement/deprecated interface path. Preserve source selection, whole-source combine/replace, permissions, effective-argument authorization, ReadLedger/CAS, and create-only writes.
  • Reuse existing read/envelope paths. No new bounded-read transport operation or external MicroVM release gate.

Remaining draft contracts

Concrete proposals and review remain for exact exported signatures/manifest fields and caller migration, config name/type/validation/threading, live-session retention ownership/cleanup, and a measured new-scope discovery-work ceiling. The prototype's 128 probes and 64 directories are not approved defaults.

The product decisions above do not constitute approval of an implementation-ready plan. ADR 0376 and the plan remain draft and unmerged.

Publication baseline

Current plan head: 4168ab3b298ff384ec6c5cd4f0fc01db696a3ee7.

This records the operator's MVP decisions on top of 9250ec196dd6c7f6bb6e90c7532e8a28092a6879, without incorporating arbitrary newer main changes. The separate NONSHIPPING prototype in #2110 has not been updated to implement these amendments and remains based on the earlier plan commit.

Verification

For the amended documents:

  • Acceptance-plan checker passed (14 acceptance criteria across 5 scenarios).
  • Acceptance-checker regression fixtures passed.
  • task docs passed.
  • git diff --check passed.
  • Advisory design review of the amended contract found no correctness or stated-requirement gaps; exact unchecked interfaces remain open.

No runtime implementation tests or aggregate code gates are claimed for this documentation-only update.

JAORMX and others added 2 commits October 5, 2026 09:58
Relates to #2090. Define the draft acceptance and interface contract for human review; no implementation.

Co-authored-by: Mecatl <[email protected]>
Reuse operand extraction and bounded workspace reads, keep a single assembly path, and extend RootAssembler and discovery without legacy variants.

Co-authored-by: Mecatl <[email protected]>

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: request changes. The plan gets the agents.md rules right: root-to-leaf loading, the nearest file wins on conflicts, sibling folders stay separate, and the user's explicit prompt beats repo guidance. The problem is how it delivers those rules. It is much heavier than what Codex, Claude Code, Gemini CLI, Cursor or OpenCode do, and in a few places it is less forgiving. The agents.md spec only says "nearest file wins". Everything past that is Mecatl's own choice, so the extra machinery should justify itself.

Main issues

1. Blocking a whole batch before it runs is unusual and mostly unnecessary.

  • No major harness makes the model decide again before a tool call. Claude Code loads a nested CLAUDE.md when a tool reads a file in that subtree, and attaches it to the context. Codex loads the root-to-cwd chain once at session start.
  • Mecatl already requires a Read before an Edit or an overwrite (engine/adapter/fstools/write.go:91). So if guidance arrives with the Read result, Edit is already covered.
  • That leaves only new-file Write, Copy, Move and Remove. Those are the only places that need a "guidance not seen yet, try again" stop.
  • That cuts most of the deferral and re-check logic from the plan. That logic covers whole-batch deferral, re-checking unexecuted calls after the first one runs, effective-argument re-checks, and fingerprinting cached reviews per run.

2. Dropping old folder guidance on every batch will cause thrashing.

  • Each batch's target set replaces the active folders instead of adding to them.
  • Example: edit website/a, then services/b, then website/c. That costs three extra model decisions, and the model keeps losing guidance it already saw.
  • Claude Code keeps nested files loaded once they're seen, for the rest of the session.
  • Recommendation: accumulate active folders within a run, with a size cap and least-recently-used eviction.

3. Starting in a subfolder hides the root AGENTS.md by default.

  • Codex, Claude Code, Gemini and OpenCode all walk up from where the session starts to the project root (the git root, in Codex's case), so repo/AGENTS.md applies to a session started in repo/website.
  • This plan finds ancestors only if the broader root was explicitly admitted, and it says it never walks up the host filesystem or infers a git repo.
  • That is the most common monorepo setup. "Can't see the root rules" will be the first bug report.
  • Trust can still gate this: if the git root is already trusted, admit its chain.

4. An oversized file stops the whole run.

  • Limits are 64 KiB per file and 256 KiB total, and going over is a "visible failure", not truncation.
  • Codex defaults to 32 KiB total and truncates. Claude Code warns.
  • Stopping a run because someone's AGENTS.md is 65 KiB is hostile.
  • Recommendation: skip or truncate that file and log a diagnostic. Also, 256 KiB (about 64k tokens) is too high a total; something nearer Codex's 32 KiB is the norm.

5. The new bounded-read transport is scope creep, and it makes completion depend on an external release.

  • The plan adds a new FILE_OPERATION_READ_BOUNDED (bounded-read) protobuf operation and a matching MicroVM operation, and blocks completion on an external MicroVM runtime release (AC7.3).
  • The plan itself says existing transport frame limits already cap the reply envelope. Applying the 64 KiB rule on the client after a frame-limited read is enough for small instruction files.
  • Recommendation: move bounded reads to a follow-up, so hierarchy can ship without waiting on another team.

6. Nested CLAUDE.md is ignored, but root CLAUDE.md is a fallback.

  • If CLAUDE.md is supported for compatibility, apply the same rule in every folder: AGENTS.md first, CLAUDE.md if it's missing.
  • Codex lets operators configure fallback filenames, and many repos (this one included) use CLAUDE.md symlinks.
  • Today a repo with nested CLAUDE.md files gets root guidance only, which is confusing.

What's fine as is

  • Not parsing Shell commands for paths. Claude Code has the same gap.
  • Leaving AGENTS.override.md out of scope, since only Codex supports it.
  • Never saving instruction bodies to the transcript.
  • The breaking signature change to the assembler with no compatibility shim.
  • Keeping the existing trust model unchanged.

Summary

Ship the industry-standard version first:

  1. At session start, load the chain from the root to the session's starting folder.
  2. When a tool first touches a new folder, attach that folder's guidance to the Read result.
  3. Keep loaded folders for the rest of the run.
  4. Stop and retry only for new-file Write, Copy, Move and Remove.
  5. Truncate oversized files with a warning instead of stopping.

That covers what #2090 asks for at a fraction of the 9 open human decisions and 22 acceptance criteria. Batch reconsideration and the bounded transport can come back as separate proposals if they turn out to be needed.

🤖 Generated with Claude Code

JAORMX and others added 2 commits October 5, 2026 14:58
Avoid the ADR 0374 collision with the persisted mecatui server CA decision on main. Update only the proposed decision and its spec references.

Co-authored-by: Mecatl <[email protected]>

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: much better. Five of my six points are fixed, but one compliance gap is still open. The plan went from 490 lines to 140 and now looks like what other harnesses do.

How each point was handled

# Earlier feedback Status
1 Batch blocking and reconsideration Fixed, and went further. All instruction-based blocking is gone, including for new-file Write, Copy, Move and Remove. Guidance now arrives on the next model request. This matches Claude Code, which also doesn't load nested guidance before a first write. Fine.
2 Active folders replaced each batch Fixed. Folders the run has already seen are kept, and moving to a sibling folder no longer drops them.
3 Root AGENTS.md hidden when starting in a subfolder Not fixed. See below.
4 Oversized file stops the run Fixed. 32 KiB total by default (Codex's number), cut at a safe text boundary, with a warning. It never blocks tools.
5 Bounded-read transport and external MicroVM release Fixed. Both removed. It uses existing reads and documents that limit.
6 Nested CLAUDE.md Fixed. AGENTS.md first, CLAUDE.md if it's missing or blank, in every folder.

Remaining issues

1. In the default setup, the root AGENTS.md still isn't loaded when starting in a subfolder (blocker).

  • The plan now says "root-to-starting-folder chain" but still rules out walking up the host filesystem or finding the git root. It only sees ancestors if a broader source was explicitly admitted.
  • The default local source is the starting folder. The plan's "root" and the starting folder are the same in the default setup:
    • internal/app/harness_context_compatibility.go:33 builds the assembler on the configured workspace (RootAssembler{Source: local.Workspace}).
    • cmd/mecatui/config.go:885 sets that workspace to the current directory when none is given.
  • So cd repo/website && mecatui loads website/AGENTS.md and never repo/AGENTS.md. Codex, Claude Code, Gemini CLI and OpenCode all load the repo root here.
  • Fix: the default local source should use the trusted project root (the git root or the existing trust anchor) as its root, with the session's starting folder as the subfolder. The plan already supports that subfolder mapping. Trust still controls it, and nothing is read above the trusted root.

2. Keeping scopes in first-seen order is the wrong priority (recommendation for open decision 2).

  • When the 32 KiB budget is full, new folders are "omitted" and loading stops.
  • Late in a long run, the folder the model is working on now gets no guidance, while folders it touched an hour ago keep their space.
  • Recommendation: always keep the starting chain, and evict the least recently used folder scopes when space runs out.
  • The retention policy is still an open decision, so this is the moment to settle it.

3. Whole-source replace can drop guidance mid-run (minor). Because scopes are now kept, touching website/ once can suppress source B's guidance for services/ for the rest of the run. That only matters when several sources use replace, which no other harness has. Disclosing it is acceptable. Just make sure the diagnostic fires when it happens, not only in the docs.

What's fine as is

  • Not parsing Shell commands for paths, and telling the model about that gap.
  • Leaving AGENTS.override.md out of scope.
  • Keeping the trust model unchanged.
  • Keeping one Deps.Instructions composition path.
  • Leaving the discovery limit open until it's measured.

Summary

Approve once issue 1 is fixed. Issue 2 belongs in the open retention decision. Issue 3 is fine with a diagnostic.

🤖 Generated with Claude Code

JAORMX and others added 3 commits October 5, 2026 15:57
Record the confirmed subfolder-root boundary and source-selection positive control in the hierarchy plan and ADR.

Co-authored-by: Mecatl <[email protected]>
Record session-stable lazy guidance, inherited child behavior, trusted source boundaries, and a configurable 64 KiB default.

Co-authored-by: Mecatl <[email protected]>
@JAORMX
JAORMX merged commit c0b1070 into main Oct 6, 2026
29 checks passed
@JAORMX
JAORMX deleted the plan/agents-instruction-hierarchy branch October 6, 2026 07:38
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 7, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants