Skip to content

feat: becwright init#6

Merged
DataDave-Dev merged 1 commit into
mainfrom
feat/init-command
Jun 30, 2026
Merged

feat: becwright init#6
DataDave-Dev merged 1 commit into
mainfrom
feat/init-command

Conversation

@DataDave-Dev

@DataDave-Dev DataDave-Dev commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Adds a becwright init command to remove the 'blank page' friction after install.

  • Detects the repo's languages (Python / JS / TS) and writes a starter .bec/rules.yaml with matching rules (secrets for any language; debug/eval for Python; debugger/console for JS/TS).
  • Installs the pre-commit hook in the same step — one command from install to enforcing.
  • Refuses to overwrite an existing .bec/rules.yaml unless --force.
  • Docs and command tables updated (English and Spanish).

Note: while writing this, becwright's own no-dangerous-eval self-rule flagged the new code, because the scaffolding text contained the literal eval() / exec() — a false positive of a text check on documentation. Reworded so the engine source stays clean. Dogfooding caught it.

Summary by CodeRabbit

  • New Features

    • Added a new init command to set up a project by generating a starter .bec/rules.yaml and installing the pre-commit hook.
    • The generated starter rules now adapt to the repository’s detected language mix.
  • Bug Fixes

    • Prevents accidentally overwriting an existing .bec/rules.yaml unless forced.
    • Improves setup guidance so users can follow the new initialization flow consistently across documentation.

init detects the repo's languages (Python / JS / TS) and writes a starter
.bec/rules.yaml with matching rules, then installs the pre-commit hook — one
command to go from install to enforcing. Refuses to overwrite an existing
rules.yaml unless --force. Docs and command tables updated.
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a new becwright init CLI subcommand to src/becwright/cli.py that detects repo languages, generates a starter .bec/rules.yaml, and installs the pre-commit hook, with a --force flag to overwrite. A new test module covers unit and end-to-end scenarios. Documentation and READMEs are updated in English and Spanish.

Changes

becwright init command

Layer / File(s) Summary
Language detection, rule generation, and init command
src/becwright/cli.py
Adds _detect_languages, _starter_rules, _render_rules_yaml, _cmd_init, and parser wiring for init with --force.
Unit and end-to-end tests
tests/test_init.py
Covers language detection skipping noise dirs, starter rule IDs per language, YAML round-trips via load_rules, and full init/check --all CLI integration.
Documentation and README updates
README.md, README.es.md, documentation/usage.md, documentation/usage.es.md, documentation/architecture.md, documentation/architecture.es.md, CLAUDE.md
Replaces becwright install setup flow with becwright init in usage guides, command tables, architecture docs, and READMEs in both languages.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A hop and a skip, a new command in place,
becwright init sets up your rules with grace.
It sniffs out your Python, your JS, your TS,
Writes a tidy YAML with no extra fuss.
The hook is installed, the docs all updated neat—
This rabbit says: your repo setup is complete! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and directly names the main change: adding becwright init.
Description check ✅ Passed It clearly explains the new command, why it exists, and the main behaviors, though it does not use the template headings or checklist.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/init-command

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

@DataDave-Dev
DataDave-Dev merged commit 7f5bd13 into main Jun 30, 2026
2 of 3 checks passed
@DataDave-Dev
DataDave-Dev deleted the feat/init-command branch June 30, 2026 06:56

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/test_init.py (1)

21-21: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the section banner comments.

The test function names already describe these groups, so these comments don’t add complexity-oriented context. As per coding guidelines, "**/*.{py,yaml,yml,toml}: Reserve comments for complex code only; do not add comments that merely restate obvious behavior."

Also applies to: 36-36, 52-52, 69-69

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_init.py` at line 21, Remove the section banner comments from the
test module; the grouped test function names already make the sections clear.
Delete the banner-style comments in the affected test blocks in
tests/test_init.py and keep the tests as-is otherwise.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/becwright/cli.py`:
- Around line 79-83: The traversal in cli.py still walks into skipped
directories before filtering files, so update the root.rglob("*") logic in the
init path to prune directories like node_modules, .venv, .git, and dist before
descending. Adjust the walking logic around the existing _SKIP_DIRS check so
directory entries are removed from traversal rather than only skipped after path
inspection, using the same root-relative part matching in the CLI init flow.

---

Nitpick comments:
In `@tests/test_init.py`:
- Line 21: Remove the section banner comments from the test module; the grouped
test function names already make the sections clear. Delete the banner-style
comments in the affected test blocks in tests/test_init.py and keep the tests
as-is otherwise.
🪄 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 Plus

Run ID: 2789fe1a-9c94-4a13-b951-3572fcfc6a9a

📥 Commits

Reviewing files that changed from the base of the PR and between 4835ea9 and e1d4065.

📒 Files selected for processing (9)
  • CLAUDE.md
  • README.es.md
  • README.md
  • documentation/architecture.es.md
  • documentation/architecture.md
  • documentation/usage.es.md
  • documentation/usage.md
  • src/becwright/cli.py
  • tests/test_init.py

Comment thread src/becwright/cli.py
Comment on lines +79 to +83
for path in root.rglob("*"):
if not path.is_file():
continue
if any(part in _SKIP_DIRS for part in path.relative_to(root).parts):
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

Prune skipped directories before walking into them.

Line 79 still descends through node_modules, .venv, .git, dist, and similar directories; the Line 82 filter only ignores files after traversal. On large repos, becwright init can become unexpectedly slow.

⚙️ Proposed fix
+import os
+
 _SKIP_DIRS = {".git", "node_modules", ".venv", "venv", "__pycache__", "dist", "build", ".tox"}
 _EXT_LANG = {".py": "python", ".js": "js", ".ts": "ts"}
+_LANG_ORDER = ("python", "js", "ts")
 
 
 def _detect_languages(root: Path) -> list[str]:
     found: set[str] = set()
-    for path in root.rglob("*"):
-        if not path.is_file():
-            continue
-        if any(part in _SKIP_DIRS for part in path.relative_to(root).parts):
-            continue
-        lang = _EXT_LANG.get(path.suffix)
-        if lang:
-            found.add(lang)
-    return [lang for lang in ("python", "js", "ts") if lang in found]
+    for _, dirnames, filenames in os.walk(root):
+        dirnames[:] = [name for name in dirnames if name not in _SKIP_DIRS]
+        for filename in filenames:
+            lang = _EXT_LANG.get(Path(filename).suffix)
+            if lang:
+                found.add(lang)
+        if len(found) == len(_LANG_ORDER):
+            break
+    return [lang for lang in _LANG_ORDER if lang in found]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for path in root.rglob("*"):
if not path.is_file():
continue
if any(part in _SKIP_DIRS for part in path.relative_to(root).parts):
continue
import os
_SKIP_DIRS = {".git", "node_modules", ".venv", "venv", "__pycache__", "dist", "build", ".tox"}
_EXT_LANG = {".py": "python", ".js": "js", ".ts": "ts"}
_LANG_ORDER = ("python", "js", "ts")
def _detect_languages(root: Path) -> list[str]:
found: set[str] = set()
for _, dirnames, filenames in os.walk(root):
dirnames[:] = [name for name in dirnames if name not in _SKIP_DIRS]
for filename in filenames:
lang = _EXT_LANG.get(Path(filename).suffix)
if lang:
found.add(lang)
if len(found) == len(_LANG_ORDER):
break
return [lang for lang in _LANG_ORDER if lang in found]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/becwright/cli.py` around lines 79 - 83, The traversal in cli.py still
walks into skipped directories before filtering files, so update the
root.rglob("*") logic in the init path to prune directories like node_modules,
.venv, .git, and dist before descending. Adjust the walking logic around the
existing _SKIP_DIRS check so directory entries are removed from traversal rather
than only skipped after path inspection, using the same root-relative part
matching in the CLI init flow.

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.

1 participant