Skip to content

fix(scaffold): adopt existing repos safely - #12

Merged
R0SEWT merged 1 commit into
mainfrom
fix/scaffold-existing-repos
Oct 5, 2026
Merged

R0SEWT merged 1 commit into
mainfrom
fix/scaffold-existing-repos

Conversation

@R0SEWT

@R0SEWT R0SEWT commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Lecciones al aplicar el scaffold a un repo existente de cliente (Wachi). Cierra project-kit-5ni.

Cambios

  • Preflight agents.md: aborta si hay un agents.md en minúsculas (bd init crearía AGENTS.md al lado).
  • Repo existente (pyproject.toml presente): no crea src/<pkg>; no crea test_smoke.py si ya hay tests reales.
  • Hooks: bd init reescribe .claude/settings.json y deja solo SessionStart → se re-añaden los bd prime faltantes (PreCompact) después de bd init. Afecta también a proyectos nuevos.
  • Prefijo beads: --prefix en minúsculas con guiones.
  • Avisos: si bd init va a commitear en main, y a qué origin sincronizará beads su DB (en Wachi apuntaba al repo del cliente).
  • SKILL.md: checklist brownfield; verificar CI desde un clon limpio.

Verificación (local)

  • bash -n ok; dry-run de CI ok
  • Fixture con agents.md → exit 1 antes de escribir nada
  • Fixture brownfield (pyproject, tests, settings con plugin, origin de cliente) → sin src/<pkg> ni smoke test, hooks [PreCompact, SessionStart], plugin conservado, aviso de origin
  • Greenfield real → hooks [PreCompact, SessionStart], prefijo green-demo

shellcheck no está instalado localmente; lo corre la CI.

Summary by Sourcery

Make scaffolding safe for existing repositories while preserving their structure, maintaining required hooks, and highlighting potentially unsafe beads configuration.

Bug Fixes:

  • Safely adopt existing repositories by avoiding conflicting files, preserving established Python layouts and real tests, and preventing duplicate instruction files.
  • Restore missing beads prime hooks after initialization and surface warnings about commits on shared branches and issue-database synchronization remotes.

Enhancements:

  • Use normalized lowercase, hyphenated beads prefixes and improve scaffold guidance for brownfield repositories and clean-clone CI verification.

Documentation:

  • Document brownfield adoption checks, beads remote safety, existing-project preservation, lint considerations, and clean-clone verification.

@sourcery-ai

sourcery-ai Bot commented Oct 5, 2026

Copy link
Copy Markdown

Sorry @R0SEWT, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 3 days and 4 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

The scaffold now adopts existing repositories conservatively: it detects filename and layout conflicts, avoids duplicate tests, normalizes beads prefixes, restores hooks after bd init, and warns about branch and remote side effects. Brownfield usage and clean-clone validation are documented, while the setup catalog adds research-backed future directions for agent workflows and guardrails.

Sequence diagram for beads initialization and hook restoration

sequenceDiagram
    participant Scaffold
    participant Repo
    participant BD as bd
    participant Settings as settings.json

    Scaffold->>Repo: inspect origin and current branch
    Scaffold->>BD: bd init --prefix BD_PREFIX
    BD->>Repo: commit initialization on current branch
    BD->>Settings: rewrite hooks, retaining SessionStart
    Scaffold->>Settings: restore missing bd prime hooks from template
    Scaffold-->>Repo: warn about main/master and origin sync target
Loading

Flow diagram for safe brownfield scaffold adoption

flowchart TD
    A["Start scaffold"] --> B{"Lowercase agents.md exists?"}
    B -- Yes --> X["Abort before writing files"]
    B -- No --> C{"pyproject.toml exists?"}
    C -- Yes --> D["Keep existing package layout"]
    C -- No --> E["Create src/<pkg>"]
    D --> F["Initialize beads with lowercase hyphenated prefix"]
    E --> F
    F --> G["Restore missing bd prime hooks"]
    G --> H{"Real tests already exist?"}
    H -- Yes --> I["Skip test_smoke.py"]
    H -- No --> J["Create test_smoke.py"]
    I --> K["Warn about branch and beads remote"]
    J --> K
Loading

File-Level Changes

Change Details Files
Make scaffolding safe for brownfield repositories by detecting conflicts and preserving existing project structure.
  • Abort before writing when a lowercase agents.md would conflict with generated AGENTS.md.
  • Skip generating src/<pkg> when pyproject.toml already exists.
  • Avoid adding the smoke test when real tests/test_*.py files are present.
scripts/scaffold.sh
skills/scaffold/SKILL.md
Preserve and restore beads-related Claude Code hooks after initialization.
  • Run bd init with a normalized lowercase, hyphenated prefix.
  • Merge missing bd prime hook events from the template after bd init rewrites settings.
  • Document the brownfield hook behavior and fallback when Python is unavailable.
scripts/scaffold.sh
skills/scaffold/SKILL.md
Add operational warnings and brownfield guidance around beads initialization and validation.
  • Warn before committing bd init on main or master.
  • Report the origin that beads will use for issue DB synchronization and provide repointing commands.
  • Add instructions to verify the generated project from a clean clone.
scripts/scaffold.sh
skills/scaffold/SKILL.md
Expand the setup-options catalog with practitioner research and proposed scaffold capabilities.
  • Record findings and recommendations across git flow, parallel agents, guardrails, and context/memory.
  • Identify adopt, trial, hold, and reject candidates for future beads and scaffold work.
catalog/setup-options.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

- preflight: abort if a lowercase agents.md exists (bd init would add AGENTS.md beside it)
- existing pyproject: don't create src/<pkg>; skip test_smoke.py when real tests exist
- re-add missing bd prime hooks AFTER bd init (it drops PreCompact, also on greenfield)
- bd init --prefix: lowercase, hyphenated project name
- warn when bd init commits on main and which origin beads will sync its DB to
- SKILL.md: brownfield checklist; next steps: verify CI from a clean clone
@R0SEWT
R0SEWT force-pushed the fix/scaffold-existing-repos branch from 24c9931 to 2d7d5e0 Compare October 5, 2026 22:06
@R0SEWT
R0SEWT merged commit 7105bf4 into main Oct 5, 2026
3 checks passed
@R0SEWT
R0SEWT deleted the fix/scaffold-existing-repos branch October 5, 2026 22:12
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