Skip to content

Add draftwise refine [<feature>] [--type=product|tech|tasks] — re-ground a spec while preserving PM hand-edits#66

Merged
4nkur merged 1 commit intomainfrom
feat/refine
Apr 30, 2026
Merged

Add draftwise refine [<feature>] [--type=product|tech|tasks] — re-ground a spec while preserving PM hand-edits#66
4nkur merged 1 commit intomainfrom
feat/refine

Conversation

@4nkur
Copy link
Copy Markdown
Owner

@4nkur 4nkur commented Apr 30, 2026

Summary

Resolves the long-standing "AI-assisted spec merge mode" open question (CLAUDE.md #4 historically). Re-running new / tech / tasks against an existing spec would overwrite PM edits — both `--force` (overwrite) and cancel are blunt. `refine` is the alternative.

Different shape from `clarify`:

  • `clarify` finds gaps in a spec and walks the PM through them; the PM provides answers and the agent rewrites.
  • `refine` takes the existing spec as ground truth for what the PM wants and re-grounds the parts that need it. No questions asked.

What it does

`draftwise refine [] [--type=product|tech|tasks]` reads the chosen file plus its source-of-truth and prints a three-phase agent instruction:

  1. Audit — walk the spec section by section, decide strong (specific, grounded, well-worded → leave alone) or weak (vague, generic, ungrounded, contradictory → rewrite).
  2. Re-ground — for each weak section, re-ground against the source-of-truth (scanner output for product/tech brownfield, overview.md for greenfield, plus the upstream spec for tech/tasks). Mark (unverified) or remove any code reference the scanner doesn't surface.
  3. Write back — save to the same path. Preserve strong sections character-for-character and any YAML frontmatter at the top of `product-spec.md`.

Hard rules in the prompt:

  • No fabricated code references.
  • No scope creep — refine ≠ adding new features / edge cases. Genuine gaps go under "Open questions."
  • Don't rewrite a section just because you'd word it differently. Bar is "actively misleads or under-specifies," not "could be tighter."
  • Don't touch sections you'd classify as strong; if the whole spec is already strong, exit without writing.

Type-aware behavior

--type Filters by Source-of-truth printed Errors if upstream missing
product (default) product-spec.md exists scanner output (brownfield) or overview.md (greenfield) n/a
tech technical-spec.md exists product-spec.md + scanner / overview yes — product-spec missing
tasks tasks.md exists technical-spec.md (no scanner) yes — technical-spec missing

Same auto-pick / multi-spec / unknown-slug ergonomics as `tech`.

What changed

  • New prompt `src/ai/prompts/refine.js` — `buildAgentInstruction(slug, type, projectState)` with a per-type metadata table at the top (file name, source-of-truth labels, section-preservation rule).
  • New command `src/commands/refine.js` — parses `--type`, branches on it for filter / upstream / scanner-vs-overview / heading labels.
  • Routed via `COMMANDS` in `src/index.js`; help block lists `refine []`.
  • 16 new tests in `test/commands/refine.test.js` covering: missing `.draftwise/`, no specs, unknown `--type`, parseArgs strict, auto-pick / slug / multi-spec / unknown-slug for product, `--type=tech` upstream + scanner, `--type=tasks` upstream + no-scanner, greenfield product, missing-upstream errors for tech and tasks, no-disk-write, three-phase + no-fabrication + no-scope-creep instruction text.
  • CHANGELOG `[Unreleased] ### Added` entry; CLAUDE.md (commands list, v1 status Implement draftwise tech [<feature>] #7, new "Refine, don't clobber" design principle); README commands table.

Test plan

  • `npm test` — 257 passing
  • `npm run lint` — clean
  • Smoke: in a repo with one product spec, `draftwise refine` auto-picks; `draftwise refine alpha --type=tech` errors when product-spec missing; `--type=summary` errors with the expected list.

…round a spec while preserving PM hand-edits

Resolves the long-standing "AI-assisted spec merge mode" open question. Re-running `new` / `tech` / `tasks` would clobber PM edits — `refine` is the alternative. Reads the chosen file, treats it as ground truth for what the PM wants, prints it plus its source-of-truth (scanner / overview, plus the upstream spec for tech/tasks), then prints a three-phase agent instruction: audit each section as strong/weak, re-ground only the weak ones, write the file back preserving strong sections character-for-character and any YAML frontmatter at the top of `product-spec.md`. Different shape from `clarify`: clarify finds gaps and walks the PM through them; refine takes the existing spec as ground truth and re-grounds the parts that need it.

Hard rules in the prompt: no fabricated code references (mark `(unverified)` or remove if the source-of-truth doesn't surface it), no scope creep (refine ≠ add new features / edge cases — gaps go under Open questions), and don't touch sections that are already strong. Bar for "weak" is "actively misleads or under-specifies," not "could be tighter," so the agent doesn't churn good prose.

Same auto-pick / multi-spec / unknown-slug ergonomics as `tech`. Filters specs by which file the requested type requires; `tech`/`tasks` additionally validate that the upstream spec exists. Per-type metadata table (file name, source-of-truth label, section-preservation rule) lives at the top of `src/ai/prompts/refine.js`.

Adds 16 tests in `test/commands/refine.test.js`. Updates CHANGELOG `[Unreleased] ### Added`, CLAUDE.md (commands list, v1 status #7, new "Refine, don't clobber" design principle), README commands table.
@4nkur 4nkur merged commit 5d25efd into main Apr 30, 2026
2 checks passed
@4nkur 4nkur deleted the feat/refine branch April 30, 2026 04:35
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