nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Feature] Support @path imports inside AGENTS.md

Open akramcodez opened this issue 2 weeks ago • 2 comments

Description

Support @path imports inside AGENTS.md so a short top-level file can pull in other markdown files, for example @docs/testing.md or @.nanocoder/rules/style.md. Today the file is read whole and appended to the system prompt as plain text (appendAgentsMd in source/conversation/prompt-builder.ts), so any @path in it is sent to the model as literal text and nothing is loaded.

Use Case

Instruction files grow. A 600 line AGENTS.md is sent on every request, which is costly on small local models, and it is hard for a team to maintain one file. Splitting it into topic files that the main file imports keeps each piece reviewable and lets teams share one file across repos (for example a common style guide checked in as a submodule). Gemini CLI supports this pattern with @file.md imports in its context file.

Proposed Solution

While building the prompt, expand lines of the form @relative/path.md (and @~/path.md for user files) into the file contents, recursively up to a small depth, with cycle detection and a total size cap. Imports resolve relative to the importing file, must stay inside the project root or the user config dir, and are skipped inside fenced code blocks so documentation that mentions an @path is not rewritten. Report unresolved imports once in the status area instead of failing silently.

Alternatives Considered

  • Put everything in one file. Works, but the file is always fully sent.
  • Rely on the model to read the referenced files on demand with read_file. This depends on the model noticing the reference, which small local models often do not.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] This feature aligns with the project's goals (local-first AI assistance)

Related but different: #1972 (more locations for instruction files).

Implementation Notes (optional)

Reuse the project path validation in source/utils/fs/path-validation.ts for the containment check, and apply the existing truncateToolResult-style cap so one import cannot exhaust the context.

akramcodez avatar Nov 17 '26 08:11 akramcodez

@akramcodez @addyCooks can you assign this issue to me thank you!!

shravanramakunja avatar Nov 19 '26 16:11 shravanramakunja

Sure @shravanramakunja 👍

akramcodez avatar Nov 20 '26 08:11 akramcodez