Skip to content

feat(wren): generate AGENTS.md during wren context init#1526

Merged
douenergy merged 4 commits intoCanner:mainfrom
goldmedal:feat/agents-md-init
Apr 8, 2026
Merged

feat(wren): generate AGENTS.md during wren context init#1526
douenergy merged 4 commits intoCanner:mainfrom
goldmedal:feat/agents-md-init

Conversation

@goldmedal
Copy link
Copy Markdown
Contributor

@goldmedal goldmedal commented Apr 7, 2026

Summary

  • Auto-generate AGENTS.md when scaffolding a new Wren project (wren context init) — gives AI coding agents immediate workflow context for data querying and model modification
  • Works for both empty scaffold and --from-mdl import paths
  • Included in --force overwrite and conflict detection

Test plan

  • wren context init --path /tmp/test → AGENTS.md exists with correct content
  • wren context init --from-mdl input.json --path /tmp/test → AGENTS.md exists
  • Re-init without --force → conflict detected, exits with error
  • Re-init with --force → AGENTS.md overwritten
  • Lint passes (just lint)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Init now creates a generated guide file containing usage templates and includes it in init output.
    • Init detects multiple pre-existing project artifacts and reports all conflicts.
  • Bug Fixes

    • Forcible re-initialization reliably replaces the generated guide file.
    • Non---force generation now aborts if any target file already exists and lists the conflicts.
  • Tests

    • Unit tests updated to expect the new guide file and verify its content.

Give AI coding agents (Claude Code, Cursor, Windsurf, Cline) immediate
workflow context when a Wren project is scaffolded — covers data querying,
model modification, and quick-reference commands.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6771780b-6482-49fd-913a-4f99b4a59b11

📥 Commits

Reviewing files that changed from the base of the PR and between 72f3bcd and 0ae6466.

📒 Files selected for processing (1)
  • wren/src/wren/context.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • wren/src/wren/context.py

📝 Walkthrough

Walkthrough

Adds an AGENTS.md template constant and ensures convert_mdl_to_project() always emits an AGENTS.md ProjectFile; write_project_files() now removes AGENTS.md when --force and blocks init if any generated target (including AGENTS.md) already exists; wren context init writes and reports AGENTS.md.

Changes

Cohort / File(s) Summary
Context module
wren/src/wren/context.py
Adds _AGENTS_MD_TEMPLATE; convert_mdl_to_project() includes a ProjectFile for AGENTS.md; write_project_files() --force cleanup removes AGENTS.md and non---force conflict check now fails if any target file (by files[*].relative_path) exists, with updated error listing conflicts.
CLI scaffolding
wren/src/wren/context_cli.py
init now treats AGENTS.md as a pre-existing artifact to error on unless --force; scaffolding for empty projects writes AGENTS.md using the template and includes it in the success output.
Tests
wren/tests/unit/test_convert_mdl.py
Tests updated to expect AGENTS.md in conversion results and on-disk after write; asserts content equals _AGENTS_MD_TEMPLATE; test_empty_mdl() updated to expect both wren_project.yml and AGENTS.md.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI as "wren context init/convert"
  participant Converter as "convert_mdl_to_project()"
  participant Writer as "write_project_files()"
  participant FS as "Filesystem"

  User->>CLI: run init / convert
  CLI->>Converter: convert MDL -> ProjectFiles (includes AGENTS.md)
  Converter-->>CLI: ProjectFiles list
  CLI->>Writer: write ProjectFiles (check conflicts)
  Writer->>FS: stat existing files (e.g., wren_project.yml, AGENTS.md)
  alt conflicts found and no --force
    FS-->>Writer: conflicting filenames
    Writer-->>CLI: raise error listing conflicts
    CLI-->>User: abort with error
  else --force or no conflicts
    Writer->>FS: delete pre-existing generated files if --force (including AGENTS.md)
    Writer->>FS: create files (wren_project.yml, AGENTS.md, ...)
    FS-->>Writer: success
    Writer-->>CLI: success
    CLI-->>User: "Wren project initialized" (lists AGENTS.md)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

documentation, python

Suggested reviewers

  • wwwy3y3
  • douenergy

Poem

🐰 I hopped through lines to plant a note,
AGENTS.md snug in every new coat.
Templates ready, checks in play,
Files aligned to greet the day—
Hooray for projects on their way! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(wren): generate AGENTS.md during wren context init' directly and precisely describes the main change: auto-generating AGENTS.md file when scaffolding a new Wren project.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@wren/src/wren/context_cli.py`:
- Around line 84-88: The error message incorrectly asserts "already a Wren
project" even when only one file (e.g., AGENTS.md) conflicts; update the message
printed in the branch that checks "if conflicts and not force:" to a neutral
conflict notice using the existing variables (conflicts, names) and the same
output mechanism (typer.echo) — for example "Error: the following files already
exist: {names}" or similar — so it reports conflicting filenames without
classifying the repo as a Wren project.

In `@wren/src/wren/context.py`:
- Around line 236-242: The AGENTS.md is always appended (via the
files.append(ProjectFile(...)) call using _AGENTS_MD_TEMPLATE) which bypasses
the non-force protection currently implemented only for wren_project.yml in
write_project_files(); update the flow so AGENTS.md follows the same force
semantics: either (a) change the append site to only add the ProjectFile when
force=True or when the target file does not already exist on disk, or (b)
enhance write_project_files() to check all pending ProjectFile targets
(including "AGENTS.md") and abort/raise when any target exists and force is
False; reference the files.append(ProjectFile(...)), _AGENTS_MD_TEMPLATE, and
write_project_files() when making the change.
- Around line 236-242: The tests must be updated to account for the new
unconditional AGENTS.md generation: in test_empty_mdl() replace the exact paths
assertion to include "AGENTS.md" (or use a subset/assertion that allows extra
files) so paths == {"wren_project.yml", "AGENTS.md"}; in
test_convert_mdl_to_project() add an assertion that the returned ProjectFile
list (or mapping) contains a ProjectFile with relative_path == "AGENTS.md" and
that its content matches _AGENTS_MD_TEMPLATE (or is non-empty); and in
test_write_project_files() add an assertion after write_project_files() that the
filesystem contains "AGENTS.md" (and optionally verify its contents match
_AGENTS_MD_TEMPLATE) so tests reflect
files.append(ProjectFile(relative_path="AGENTS.md",
content=_AGENTS_MD_TEMPLATE)) being unconditional.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0897b719-f3b0-4263-af31-1d872da0c4c8

📥 Commits

Reviewing files that changed from the base of the PR and between a923489 and 53ffbb1.

📒 Files selected for processing (2)
  • wren/src/wren/context.py
  • wren/src/wren/context_cli.py

goldmedal and others added 2 commits April 7, 2026 23:31
Explains how to install the wren CLI, per-data-source extras, and links
to full installation docs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rage

- Use neutral error message instead of "already a Wren project"
- Check all target files (not just wren_project.yml) in write_project_files()
  so AGENTS.md is also protected from silent overwrite without --force
- Update tests: test_empty_mdl, test_convert_mdl_to_project,
  test_write_project_files now assert AGENTS.md presence and content

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
wren/src/wren/context.py (1)

260-266: ⚠️ Potential issue | 🟠 Major

Non-force conflict detection is still incomplete for generated files.

Line 260 unconditionally adds AGENTS.md, but Line 304 only blocks on wren_project.yml. This can still overwrite an existing AGENTS.md (or other generated file) when --force is false.

Suggested fix
 def write_project_files(
@@
-    if project_file.exists() and not force:
-        raise SystemExit(
-            f"Error: {project_file} already exists. Use --force to overwrite."
-        )
+    if not force:
+        conflicts = [
+            f.relative_path
+            for f in files
+            if (output_dir / f.relative_path).exists()
+        ]
+        if conflicts:
+            names = ", ".join(f"'{Path(p).name}'" for p in conflicts)
+            raise SystemExit(f"Error: {names} already exists. Use --force to overwrite.")

Also applies to: 304-307

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@wren/src/wren/context.py` around lines 260 - 266, The code unconditionally
appends a generated ProjectFile for "AGENTS.md" via
files.append(ProjectFile(...)) which can overwrite an existing file because the
existing guard only checks for "wren_project.yml"; update the generation logic
to check for existing target files before appending when the force
flag/parameter is false: either add an existence check for "AGENTS.md" (and any
other generated filenames created similarly) and skip appending unless force is
true, or consolidate into the same check used for "wren_project.yml" so all
generated files honor the non-force conflict detection.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@wren/src/wren/context.py`:
- Around line 260-266: The code unconditionally appends a generated ProjectFile
for "AGENTS.md" via files.append(ProjectFile(...)) which can overwrite an
existing file because the existing guard only checks for "wren_project.yml";
update the generation logic to check for existing target files before appending
when the force flag/parameter is false: either add an existence check for
"AGENTS.md" (and any other generated filenames created similarly) and skip
appending unless force is true, or consolidate into the same check used for
"wren_project.yml" so all generated files honor the non-force conflict
detection.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4f7a6bd9-d83b-4762-95aa-20cb31f3e918

📥 Commits

Reviewing files that changed from the base of the PR and between 53ffbb1 and 9026f04.

📒 Files selected for processing (1)
  • wren/src/wren/context.py

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@goldmedal goldmedal requested a review from douenergy April 8, 2026 02:37
@douenergy douenergy merged commit 40bf46f into Canner:main Apr 8, 2026
11 checks passed
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