fix(cli): require --confirm flag before phases clear deletes directories (#1832)
phases clear now checks for phase dirs before deleting. If any exist and --confirm is absent, the command exits non-zero with a message showing the count and how to proceed. Empty phases dir (nothing to delete) succeeds without --confirm unchanged. Updates new-milestone.md workflow to pass --confirm (intentional programmatic caller). Updates existing new-milestone-clear-phases tests to match new API. Closes #1826 Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -602,7 +602,7 @@ async function runCommand(command, args, cwd, raw) {
|
||||
};
|
||||
phase.cmdPhasesList(cwd, options, raw);
|
||||
} else if (subcommand === 'clear') {
|
||||
milestone.cmdPhasesClear(cwd, raw);
|
||||
milestone.cmdPhasesClear(cwd, raw, args.slice(2));
|
||||
} else {
|
||||
error('Unknown phases subcommand. Available: list, clear');
|
||||
}
|
||||
|
||||
@@ -246,15 +246,24 @@ function cmdMilestoneComplete(cwd, version, options, raw) {
|
||||
output(result, raw);
|
||||
}
|
||||
|
||||
function cmdPhasesClear(cwd, raw) {
|
||||
function cmdPhasesClear(cwd, raw, args) {
|
||||
const phasesDir = planningPaths(cwd).phases;
|
||||
const confirm = Array.isArray(args) && args.includes('--confirm');
|
||||
let cleared = 0;
|
||||
|
||||
if (fs.existsSync(phasesDir)) {
|
||||
const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
|
||||
const dirs = entries.filter(e => e.isDirectory());
|
||||
|
||||
if (dirs.length > 0 && !confirm) {
|
||||
error(
|
||||
`phases clear would delete ${dirs.length} phase director${dirs.length === 1 ? 'y' : 'ies'}. ` +
|
||||
`Pass --confirm to proceed.`
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
if (!entry.isDirectory()) continue;
|
||||
for (const entry of dirs) {
|
||||
fs.rmSync(path.join(phasesDir, entry.name), { recursive: true, force: true });
|
||||
cleared++;
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ Delete MILESTONE-CONTEXT.md if exists (consumed).
|
||||
Clear leftover phase directories from the previous milestone:
|
||||
|
||||
```bash
|
||||
node "$HOME/.claude/get-shit-done/bin/gsd-tools.cjs" phases clear
|
||||
node "$HOME/.claude/get-shit-done/bin/gsd-tools.cjs" phases clear --confirm
|
||||
```
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user