Extract drafting-command boilerplate into three shared helpers#57
Merged
Conversation
Three near-identical patterns lived across new / tech / tasks (and a chunk of one across eight non-init commands):
1. **Scan-context branch in new/tech/tasks.** The same `if (isGreenfield) { readOverview } else { scan + compactScan + describeScanWarnings }` block, three copies, same error strings modulo command name. Now `loadScanContext({ cwd, config, log, scan, readOverview, commandName })` returns `{ scanForPrompt, packageMeta, overview }`. Lives at `src/utils/scan-context.js`.
2. **Overwrite-confirm dance in new/tech/tasks.** Same `if !force && exists { TTY ? confirm-or-cancel : throw }` shape three times, with the same inline `confirm({ default: false })` prompt definition. Now `confirmOverwriteOrCancel({ targetPath, slug, file, force, isInteractive, log, confirmOverwrite })` returns a `proceed` boolean. The default prompt moved into `src/utils/overwrite-guard.js`; commands no longer carry per-file `confirmOverwrite` definitions in their `DEFAULT_PROMPTS` (test injection still works through `deps.prompts`).
3. **`.draftwise/` existence guard, eight callers.** Same three-line block (`const dir = join(cwd, '.draftwise'); if (!await pathExists(dir)) throw 'not found, run init first'`) at the top of `explain`, `list`, `new`, `scaffold`, `scan`, `show`, `tasks`, `tech`. Now `await requireDraftwiseDir(cwd)` returns the resolved path. Lives at `src/utils/draftwise-dir.js`. `init.js` is exempt — it asserts the directory does NOT exist and has its own bespoke error.
Net: command files lose ~130 lines, helpers add ~80, tests gain ~250. Single source of truth for "how Draftwise loads scan data into a prompt," "how Draftwise guards a hand-edited spec from clobbering," and "how Draftwise refuses to run before init."
12 new direct tests across `test/utils/{scan-context,overwrite-guard,draftwise-dir}.test.js`. Full suite at 332 passing (was 320 before this branch). Lint clean. No public CLI behavior change — same flags, same error strings, same prompts.
4 tasks
4nkur
added a commit
that referenced
this pull request
Apr 29, 2026
The polish + cleanup release. Half ergonomic improvements (`draftwise init` auto-detects new project vs existing codebase from the filesystem instead of asking; plain-language UX throughout init — #51), half code-quality work (five small dedup + tidy PRs that shrink the public API surface, fix two user-visible `draft` → `draftwise` typos in error messages, and consolidate drafting-command boilerplate behind shared helpers — #53/#54/#55/#56/#57). One genuinely new surface: `draftwise skills <install|uninstall|help>` drops standalone slash-command skills into Claude Code, Cursor, and Gemini CLI's user-level skill dirs (#52) — same SKILL.md, per-provider frontmatter trim — independent of the Claude Code marketplace plugin. Bumps `package.json` + `package-lock.json` from 0.2.0 → 0.2.1. Patch bump because the additive `skills` verb is non-breaking and the removed prompt aliases (`PLAN_SYSTEM`, `SPEC_SYSTEM`, `tech.SYSTEM`, `tasks.SYSTEM`) were never imported by anyone outside this repo (verified by audit). Rolls all [Unreleased] entries into [0.2.1] — 2026-04-29 — Ankur, with a fresh empty [Unreleased] block above. After merge, ritual: `git tag -a v0.2.1 -m "v0.2.1"`, `git push origin v0.2.1`, `npm publish` (interactive — OTP + login may be needed if the npm session expired).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bundle of three audit items (P2 #10, P2 #11, P3 #12). Three near-identical patterns lived across
new/tech/tasks(and a chunk of one across all eight non-init commands):if (isGreenfield) { readOverview } else { scan + compactScan + describeScanWarnings }block, three copies, same error strings modulo command name. NowloadScanContext({ cwd, config, log, scan, readOverview, commandName })insrc/utils/scan-context.jsreturning{ scanForPrompt, packageMeta, overview }.if !force && exists { TTY ? confirm-or-cancel : throw }three times with the same inlineconfirm({ default: false })prompt. NowconfirmOverwriteOrCancel(...)insrc/utils/overwrite-guard.jsreturning aproceedboolean. Default prompt moved into the helper; commands no longer carry per-fileconfirmOverwritedefinitions in theirDEFAULT_PROMPTS(test injection still works throughdeps.prompts)..draftwise/existence guard, eight callers — same three-line block (if (!await pathExists(dir)) throw '.draftwise/ not found, run init first') at the top ofexplain,list,new,scaffold,scan,show,tasks,tech. Nowawait requireDraftwiseDir(cwd)returning the resolved path. Lives atsrc/utils/draftwise-dir.js.init.jsis exempt — it asserts the directory does NOT exist.Net production code: command files lose ~130 lines; helpers add ~80. Tests gain ~250 lines (12 new direct tests across the three new helper files). Single source of truth for: how Draftwise loads scan data into a prompt, how it guards a hand-edited spec, how it refuses to run pre-init.
Test plan
npm test— 332 passing (was 320 before this branch); 12 new direct tests acrosstest/utils/{scan-context,overwrite-guard,draftwise-dir}.test.jsnpm run lint— cleaninit.jsdeliberately untouched (its.draftwise/-existence check is the inverse invariant).