Skip to content

feat: add AGENTS.md context injection to agentdiff configure#17

Merged
codeprakhar25 merged 2 commits into
mainfrom
feat/issue-15
May 11, 2026
Merged

feat: add AGENTS.md context injection to agentdiff configure#17
codeprakhar25 merged 2 commits into
mainfrom
feat/issue-15

Conversation

@codeprakhar25
Copy link
Copy Markdown
Owner

Summary

  • agentdiff configure now writes/updates an ## AgentDiff managed block in AGENTS.md at the current directory (repo root), so agents like Codex, Cursor, and Copilot that read AGENTS.md get the same context that Claude Code gets from the SKILL template
  • The block is idempotent: re-running configure updates it in place without duplicating content or touching any surrounding text
  • --no-agents-md flag skips the step entirely

Changes

  • src/configure/agents_md.rs — new module with managed-block write/update logic (same HTML-comment marker pattern as the existing antigravity GEMINI.md writer)
  • src/cli.rs — add --no-agents-md flag to ConfigureArgs
  • src/configure/mod.rs — register module, call step 10, pass repo_root, update test helper struct
  • src/main.rs — pass repo_root to run_configure
  • README.md — document AGENTS.md support and --no-agents-md flag

Test plan

  • cargo test — all 39 unit tests pass, including 4 new agents_md tests:
    • creates AGENTS.md from scratch
    • idempotent when block is unchanged
    • updates existing managed block without duplicating
    • appends to existing AGENTS.md content without a block
  • cargo build — clean compile

Closes #15

🤖 Generated with Claude Code

Extend `agentdiff configure` to write/update an `## AgentDiff` managed
block in `AGENTS.md` at the current directory (repo root). This surfaces
agentdiff context to agents like Codex, Cursor, and Copilot that read
AGENTS.md for repo-level instructions — a gap the Claude-specific SKILL
template couldn't fill.

- New `src/configure/agents_md.rs`: idempotent managed-block writer using
  HTML comment markers, following the same pattern as antigravity GEMINI.md
- `agentdiff configure` calls step_configure_agents_md(repo_root) as step 10
- `--no-agents-md` flag skips the AGENTS.md step
- 4 unit tests: create-from-scratch, idempotency, in-place update, and
  append-to-existing-content
- README updated to document AGENTS.md support and --no-agents-md flag

Closes #15

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 7, 2026

Greptile Summary

This PR adds an idempotent AGENTS.md managed-block writer to agentdiff configure, mirroring the existing GEMINI.md pattern. A --no-agents-md flag is provided to skip the step, and a .git-presence guard prevents the file from being created outside a git repository.

  • src/configure/agents_md.rs — new module with write/update/idempotency logic, malformed-block guard, and six unit tests covering all code paths.
  • src/configure/mod.rs / src/main.rs — wires repo_root through to the new step; src/cli.rs adds the --no-agents-md flag; README documents the new behaviour.

Confidence Score: 5/5

Safe to merge — all code paths are covered by tests, the malformed-block guard prevents file corruption, and the git-repo check prevents stray AGENTS.md files outside project roots.

The change is well-scoped: it adds a new, optional configure step backed by thorough unit tests. The two findings are both cosmetic — a leading blank line in newly-created files and an unused import — neither of which affects correctness or data integrity.

src/configure/agents_md.rs — separator logic for the empty-file case; src/configure/mod.rs — unused PathBuf import

Important Files Changed

Filename Overview
src/configure/agents_md.rs New module that writes/updates a managed AgentDiff block in AGENTS.md; correctly handles idempotency, malformed-block guard, and the git-repo skip; minor separator bug creates a leading blank line when producing a new file from scratch
src/configure/mod.rs Adds no_agents_md flag wiring, step 10 call, and repo_root parameter to run_configure; PathBuf is imported but never referenced by name in the file, generating a compiler warning
src/cli.rs Adds --no-agents-md flag to ConfigureArgs; straightforward and correct
src/main.rs Passes repo_root to run_configure; one-line change, correct
README.md Documents new AGENTS.md behavior and --no-agents-md flag; accurate and concise

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[agentdiff configure] --> B{--no-agents-md?}
    B -- yes --> Z[skip AGENTS.md]
    B -- no --> C{.git exists at repo_root?}
    C -- no --> D[print skip message, return Ok]
    C -- yes --> E[read AGENTS.md or default to empty string]
    E --> F{AGENTS_MD_START found?}
    F -- yes --> G{AGENTS_MD_END found?}
    G -- no --> H[warn: malformed, skip]
    G -- yes --> I{current block == managed_block?}
    I -- yes --> J[print up-to-date, return Ok]
    I -- no --> K[replace block in place, write file]
    F -- no --> L{existing is empty?}
    L -- yes --> M[separator = empty string]
    L -- no --> N{ends with newline?}
    N -- yes --> O[separator = single newline]
    N -- no --> P[separator = double newline]
    M & O & P --> Q[append managed block, write file]
Loading

Reviews (2): Last reviewed commit: "fix: skip AGENTS.md outside git repos; w..." | Re-trigger Greptile

Comment thread src/configure/mod.rs
Comment thread src/configure/agents_md.rs
Comment thread src/configure/mod.rs Outdated
Two bugs flagged in review:

- configure run outside a git repo (machine-global setup) wrote AGENTS.md
  to current_dir() instead of skipping. Now checks for .git before writing.
- File with start sentinel but no end sentinel silently got a second block
  appended. Now warns and skips to avoid corrupting the file.

Also: &PathBuf -> &Path in run_configure signature (idiomatic).

Added two tests: skips_when_not_a_git_repo, warns_and_skips_on_unclosed_sentinel.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codeprakhar25 codeprakhar25 merged commit 92038c5 into main May 11, 2026
3 checks passed
@github-actions
Copy link
Copy Markdown

AgentDiff Report

Summary

Agent Lines %
Prakhar Khatri 272 100%

Review Context

  • Intent: unspecified (272 lines, 5 files)
    • Agent/model: Prakhar Khatri / unknown

Files To Review First

File Lines Dominant Agent Intent Context
src/configure/agents_md.rs 254 Prakhar Khatri unspecified trace 2f7caa2e
src/configure/mod.rs 10 Prakhar Khatri unspecified trace 2f7caa2e
src/cli.rs 4 Prakhar Khatri unspecified trace 2f7caa2e
README.md 3 Prakhar Khatri unspecified trace 2f7caa2e
src/main.rs 1 Prakhar Khatri unspecified trace 2f7caa2e
Trace details
Trace Agent Intent Files Lines
2f7caa2e Prakhar Khatri unspecified README.md, src/cli.rs, src/configure/agents_md.rs, src/configure/mod.rs, src/main.rs 212
70f4fc61 Prakhar Khatri unspecified src/configure/agents_md.rs, src/configure/mod.rs 60

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.

agentdiff configure: add AGENTS.md context injection alongside SKILL template

1 participant