Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.
This repository was archived by the owner on Nov 25, 2026. It is now read-only.

cleanup-legacy.py: unchecked --module-code / --also-remove are passed to rmtree — '' or '.' deletes all of _bmad (agent memory included), '..' deletes the whole project #155

Open

Description

@CloneOfAlex

Describe the bug

cleanup-legacy.py joins --module-code and every --also-remove value onto --bmad-dir, then calls shutil.rmtree on the result. The script is shipped in skills/bmad-bmb-setup/scripts/, the module-builder setup-skill template, and samples/sample-module-setup/. Nothing validates these values:

Value Path(bmad_dir) / value What gets deleted
--module-code "" _bmad/ all of _bmad: every module's config, _config/ manifests, and every agent's sanctum under _bmad/memory/
--module-code . _bmad/. same as above
--module-code .. _bmad/.. the whole project directory, source code included
--also-remove ../src _bmad/../src any folder outside _bmad

The --skills-dir safety check doesn't help. verify_skills_installed() skips every directory that contains no SKILL.md, so it reports skills_verified: true and removal continues. This is related to #96 (deleting live config dirs) and #121/#136 (validating module codes), but the impact here is total data loss from a single bad argument. The module code reaches this command through a {module-code} substitution done by the scaffolder or the LLM.

Steps to reproduce

C=<bmb>/skills/bmad-bmb-setup/scripts/cleanup-legacy.py
for code in "" "." ".."; do
  rm -rf /tmp/p && mkdir -p /tmp/p/_bmad/{bmm,core,memory/my-agent} /tmp/p/src && cd /tmp/p
  echo x > _bmad/memory/my-agent/MEMORY.md; echo code > src/app.py
  python3 $C --bmad-dir _bmad --module-code "$code" --skills-dir .claude/skills >/dev/null 2>&1
  echo "code='$code': _bmad=$([ -d _bmad ] && echo kept || echo DELETED) src/app.py=$([ -f src/app.py ] && echo kept || echo DELETED)"
  cd /
done
# code='':   _bmad=DELETED src/app.py=kept
# code='.':  _bmad=DELETED src/app.py=kept
# code='..': _bmad=DELETED src/app.py=DELETED   (whole project removed)

rm -rf /tmp/p && mkdir -p /tmp/p/_bmad/core /tmp/p/src && cd /tmp/p
python3 $C --bmad-dir _bmad --module-code bmb --also-remove ../src   # src/ deleted

Expected behavior

Environment

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions