feat(wren): generate AGENTS.md during wren context init#1526
feat(wren): generate AGENTS.md during wren context init#1526douenergy merged 4 commits intoCanner:mainfrom
wren context init#1526Conversation
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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds an Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
wren/src/wren/context.pywren/src/wren/context_cli.py
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>
There was a problem hiding this comment.
♻️ Duplicate comments (1)
wren/src/wren/context.py (1)
260-266:⚠️ Potential issue | 🟠 MajorNon-force conflict detection is still incomplete for generated files.
Line 260 unconditionally adds
AGENTS.md, but Line 304 only blocks onwren_project.yml. This can still overwrite an existingAGENTS.md(or other generated file) when--forceis 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.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
AGENTS.mdwhen scaffolding a new Wren project (wren context init) — gives AI coding agents immediate workflow context for data querying and model modification--from-mdlimport paths--forceoverwrite and conflict detectionTest plan
wren context init --path /tmp/test→ AGENTS.md exists with correct contentwren context init --from-mdl input.json --path /tmp/test→ AGENTS.md exists--force→ conflict detected, exits with error--force→ AGENTS.md overwrittenjust lint)🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
--forcegeneration now aborts if any target file already exists and lists the conflicts.Tests