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 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
58/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
cli, security

調査の方向性

Start with skills/bmad-bmb-setup/scripts/cleanup-legacy.py and inspect how it builds targets from --module-code and --also-remove before calling shutil.rmtree; check the related copies in the module-builder template and samples/sample-module-setup/ too. Trace verify_skills_installed() and the references to issues #96 and #139. Done when invalid or out-of-scope paths are refused and _bmad/memory/ is protected.

索引モデルが issue の本文から書いたものです。

説明

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

  • Require --module-code and each --also-remove value to be a single, non-empty, non-dot path segment, e.g. ^[A-Za-z0-9_][A-Za-z0-9_.-]*$ and not . or ...
  • Resolve each target and refuse anything that is not a strict child of the resolved --bmad-dir.
  • Never remove _bmad/memory/, and never remove a directory the script can't prove is a legacy skill payload (see #96 and #139).

Environment

  • Model(s) used: n/a (deterministic script)
  • Agentic IDE used: n/a (scripts run directly)
  • BMad version: bmad-builder main @ d4a921c (v2.2.2 + #118)
  • Project language: Python 3.13, Linux
主要言語
Python
スター
220
フォーク
54
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bmad-code-org/bmad-builder のほかの issue

bmad-code-org/bmad-builder の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。