feat(plan-phase): add ADR ingest express path for approved enhancement #3209 (#3421)

* feat(plan-phase): add ADR ingest express path for approved enhancement #3209

* fix(review): address coderabbit doc note and brittle section-number assertion
This commit is contained in:
Tom Boucher
2026-05-11 23:01:34 -04:00
committed by GitHub
parent 39e0113bcb
commit 8cd874969c
10 changed files with 619 additions and 8 deletions

View File

@@ -0,0 +1,394 @@
'use strict';
const fs = require('fs');
const path = require('path');
const { requireSafePath } = require('./security.cjs');
const STATUS_REJECT_SET = new Set(['superseded', 'rejected', 'deprecated']);
const CANONICAL_HEADERS = {
status: ['status', 'state', 'lifecycle', 'stage'],
goal: [
'context',
'background',
'problem statement',
'problem',
'situation',
'forces',
'motivation',
'issue',
'drivers',
'pain points',
'story',
'setting',
'premise',
'status quo',
'context and problem statement',
],
decisions: [
'decision',
'decisions',
'resolution',
'conclusion',
'choice',
'we decided',
'direction',
'approach',
'solution',
'outcome',
'selected option',
'recommendation',
'strategy',
'decision outcome',
],
considered_options: [
'considered options',
'alternatives',
'options',
'choices',
'candidates',
'approaches considered',
'variants',
'trade-offs',
'pros and cons of the options',
'discussion',
],
risks: [
'risks',
'trade-offs',
'drawbacks',
'cost',
'tensions',
'liabilities',
'negative consequences',
'side effects',
],
success_criteria: [
'success criteria',
'acceptance criteria',
'validation',
"how we'll know",
'metrics',
'kpis',
'verification',
'test strategy',
'compliance',
'definition of done',
'exit criteria',
'positive consequences',
],
plan_sequence: [
'implementation plan',
'implementation notes',
'steps',
'tasks',
'roadmap',
'sequence',
'migration plan',
'plan',
'action items',
'work breakdown',
'phases',
'milestones',
'stages',
],
key_files: [
'affected files',
'files touched',
'surface area',
'modules affected',
'code locations',
'file changes',
'diff summary',
'touched code',
],
out_of_scope: [
'out of scope',
'non-goals',
'excluded',
'not in this adr',
'out of bounds',
"won't do",
"won't have",
'beyond scope',
'anti-goals',
],
deferred: [
'future work',
'deferred',
'future',
'later',
'follow-up',
'next steps',
],
dependencies: [
'dependencies',
'depends on',
'prerequisites',
'sequencing',
'order',
'blocked by',
'cross-cuts',
'related adrs',
'links',
'references',
'see also',
'upstream',
'inbound',
],
update: [
'update',
'revision',
'amendment',
'locked design',
'final decision',
'post-grilling',
'addendum',
],
consequences: [
'consequences',
'implications',
'impact',
'what this means',
'result',
],
};
const CONSEQUENCE_NEGATIVE_HINTS = [
'negative',
'drawback',
'risk',
'cost',
'liability',
'trade-off',
'tension',
'side effect',
];
const CONSEQUENCE_POSITIVE_HINTS = [
'positive',
'success',
'metric',
'kpi',
'verification',
'acceptance',
'benefit',
];
function normalizeAdrHeader(raw) {
return String(raw || '')
.trim()
.toLowerCase()
.replace(/[\s:._-]+/g, ' ')
.replace(/[^\w\s]/g, '')
.trim();
}
function classifyHeader(normalizedHeader) {
for (const [canonical, synonyms] of Object.entries(CANONICAL_HEADERS)) {
for (const synonym of synonyms) {
if (normalizedHeader === synonym) return canonical;
if (normalizedHeader.startsWith(`${synonym} `)) return canonical;
}
}
return null;
}
function splitEntries(blockText) {
return String(blockText || '')
.split(/\r?\n/)
.map((line) => line.trim())
.filter(Boolean)
.map((line) => line.replace(/^[-*+]\s+/, '').trim())
.filter(Boolean);
}
function parseSections(markdown) {
const lines = String(markdown || '').split(/\r?\n/);
const sections = [];
let current = { heading: null, body: [] };
for (const line of lines) {
const m = line.match(/^#{1,6}\s+(.*)$/);
if (m) {
if (current.heading || current.body.length) sections.push(current);
current = { heading: m[1].trim(), body: [] };
} else {
current.body.push(line);
}
}
if (current.heading || current.body.length) sections.push(current);
return sections;
}
function parseStatusFromSections(sections) {
for (const section of sections) {
const canonical = classifyHeader(normalizeAdrHeader(section.heading));
if (canonical !== 'status') continue;
const line = splitEntries(section.body.join('\n'))[0] || '';
const norm = normalizeAdrHeader(line);
if (!norm) return '';
if (norm.includes('accepted')) return 'accepted';
if (norm.includes('proposed')) return 'proposed';
if (norm.includes('superseded')) return 'superseded';
if (norm.includes('rejected')) return 'rejected';
if (norm.includes('deprecated')) return 'deprecated';
return norm;
}
return '';
}
function pushUnique(target, values) {
const seen = new Set(target);
for (const value of values) {
if (!seen.has(value)) {
target.push(value);
seen.add(value);
}
}
}
function parseConsequences(lines, out) {
for (const entry of lines) {
const lower = entry.toLowerCase();
if (CONSEQUENCE_NEGATIVE_HINTS.some((hint) => lower.includes(hint))) {
out.consequences_negative.push(entry);
continue;
}
if (CONSEQUENCE_POSITIVE_HINTS.some((hint) => lower.includes(hint))) {
out.consequences_positive.push(entry);
continue;
}
out.consequences_positive.push(entry);
}
}
function parseAdrMarkdown(markdown, { sourcePath = '', format = 'auto' } = {}) {
const sections = parseSections(markdown);
const titleLine = String(markdown || '').split(/\r?\n/).find((line) => /^#\s+/.test(line)) || '';
const title = titleLine.replace(/^#\s+/, '').trim();
const out = {
title,
status: parseStatusFromSections(sections) || 'accepted',
context: '',
decisions: [],
options_considered: [],
consequences_positive: [],
consequences_negative: [],
out_of_scope: [],
deferred: [],
dependencies: [],
updates: [],
source_path: sourcePath,
key_files: [],
plan_sequence: [],
format,
unmapped_headers: [],
};
for (const section of sections) {
const heading = section.heading || '';
if (!heading) continue;
const canonical = classifyHeader(normalizeAdrHeader(heading));
const entries = splitEntries(section.body.join('\n'));
const prose = section.body.join('\n').trim();
if (!canonical) {
out.unmapped_headers.push(heading);
continue;
}
switch (canonical) {
case 'goal':
if (!out.context && prose) out.context = prose;
break;
case 'decisions':
pushUnique(out.decisions, entries);
break;
case 'considered_options':
pushUnique(out.options_considered, entries);
break;
case 'risks':
pushUnique(out.consequences_negative, entries);
break;
case 'success_criteria':
pushUnique(out.consequences_positive, entries);
break;
case 'plan_sequence':
pushUnique(out.plan_sequence, entries);
break;
case 'key_files':
pushUnique(out.key_files, entries);
break;
case 'out_of_scope':
pushUnique(out.out_of_scope, entries);
break;
case 'deferred':
pushUnique(out.deferred, entries);
break;
case 'dependencies':
pushUnique(out.dependencies, entries);
break;
case 'update':
out.updates.push({ heading, entries });
break;
case 'consequences':
parseConsequences(entries, out);
break;
default:
break;
}
}
return out;
}
function shouldRejectAdrStatus(status) {
return STATUS_REJECT_SET.has(normalizeAdrHeader(status));
}
function parseCliArgs(argv) {
const opts = { input: null, format: 'auto', projectDir: process.cwd() };
for (let i = 0; i < argv.length; i++) {
const arg = argv[i];
if (arg === '--input') {
opts.input = argv[++i] || null;
} else if (arg === '--format') {
opts.format = argv[++i] || 'auto';
} else if (arg === '--project-dir') {
opts.projectDir = argv[++i] || process.cwd();
} else {
throw new Error(`Unknown argument: ${arg}`);
}
}
if (!opts.input) {
throw new Error('Missing required --input <path>');
}
return opts;
}
function main(argv) {
const opts = parseCliArgs(argv);
const safePath = requireSafePath(opts.input, path.resolve(opts.projectDir), 'ADR input path', { allowAbsolute: true });
const content = fs.readFileSync(safePath, 'utf8');
const parsed = parseAdrMarkdown(content, { sourcePath: opts.input, format: opts.format });
process.stdout.write(JSON.stringify(parsed, null, 2));
}
if (require.main === module) {
try {
main(process.argv.slice(2));
} catch (error) {
process.stderr.write(`Error: ${error.message}\n`);
process.exit(1);
}
}
module.exports = {
CANONICAL_HEADERS,
normalizeAdrHeader,
parseAdrMarkdown,
shouldRejectAdrStatus,
};

View File

@@ -92,7 +92,7 @@ Plan a phase as a vertical MVP slice — three structured user-story prompts (`A
Usage: `/gsd-mvp-phase 1`
Usage: `/gsd-mvp-phase 2 --force`
**`/gsd-plan-phase <number> [--research] [--skip-research] [--research-phase <N>] [--view] [--gaps] [--skip-verify] [--tdd] [--mvp]`**
**`/gsd-plan-phase <number> [--research] [--skip-research] [--research-phase <N>] [--view] [--gaps] [--skip-verify] [--prd <file>] [--ingest <path-or-glob>] [--ingest-format <auto|nygard|madr|narrative>] [--tdd] [--mvp]`**
Create detailed execution plan for a specific phase.
- `--skip-research` — bypass the research subagent
@@ -100,6 +100,9 @@ Create detailed execution plan for a specific phase.
- Modifiers: `--research` forces refresh (re-spawn researcher, no prompt). `--view` prints existing `RESEARCH.md` to stdout without spawning. With neither, prompts `update / view / skip` if `RESEARCH.md` already exists.
- `--gaps` — focus only on closing gaps from a prior plan-check
- `--skip-verify` — skip the post-plan verifier loop
- `--prd <file>` — use a PRD file as planning context and skip discuss-phase (mutually exclusive with `--ingest`)
- `--ingest <path-or-glob>` — use ADR file(s) as planning context and skip discuss-phase (mutually exclusive with `--prd`)
- `--ingest-format <auto|nygard|madr|narrative>` — optional ADR parser format override
- `--tdd` — plan in test-driven order (tests before code)
- `--mvp` — vertical-slice MVP planning mode
@@ -114,7 +117,9 @@ Usage: `/gsd-plan-phase --research-phase 2 --view` — print existing `RESEARCH.
Usage: `/gsd-plan-phase --research-phase 2 --research` — force-refresh, no prompt
Result: Creates `.planning/phases/01-foundation/01-01-PLAN.md`
**PRD Express Path:** Pass `--prd path/to/requirements.md` to skip discuss-phase entirely. Your PRD becomes locked decisions in CONTEXT.md. Useful when you already have clear acceptance criteria.
**PRD Express Path:** Pass `--prd path/to/requirements.md` to skip discuss-phase entirely. Your PRD becomes locked decisions in CONTEXT.md. Useful when you already have clear acceptance criteria. Cannot be combined with `--ingest`.
**ADR Ingest Express Path:** Pass `--ingest path/to/adr.md` (or a glob) to skip discuss-phase and synthesize CONTEXT.md from approved ADR decisions and scope fences. Cannot be combined with `--prd`.
### Execution

View File

@@ -55,7 +55,7 @@ Parse JSON for: `researcher_model`, `planner_model`, `checker_model`, `research_
## 2. Parse and Normalize Arguments
Extract from $ARGUMENTS: phase number (integer or decimal like `2.1`), flags (`--research`, `--skip-research`, `--research-phase <N>`, `--gaps`, `--skip-verify`, `--skip-ui`, `--prd <filepath>`, `--reviews`, `--text`, `--bounce`, `--skip-bounce`, `--chunked`, `--mvp`).
Extract from $ARGUMENTS: phase number (integer or decimal like `2.1`), flags (`--research`, `--skip-research`, `--research-phase <N>`, `--gaps`, `--skip-verify`, `--skip-ui`, `--prd <filepath>`, `--ingest <path-or-glob>`, `--ingest-format <auto|nygard|madr|narrative>`, `--reviews`, `--text`, `--bounce`, `--skip-bounce`, `--chunked`, `--mvp`).
**`--research-phase <N>` — research-only mode (#3042 + #3044).** When this flag is present, parse `<N>` as the phase number (overrides any positional phase argument), set `RESEARCH_ONLY=true`, and treat the rest of this workflow as a research-dispatch only — the planner spawn (step 8), plan-checker, verification, gaps, bounce, and post-planning-gaps blocks all skip on `RESEARCH_ONLY`. Use this for cross-phase research, doc review before committing to a planning approach, and correction-without-replanning loops. Replaces the deleted `/gsd-research-phase` command.
@@ -104,7 +104,10 @@ When `WALKING_SKELETON=true`:
**Interaction with `--prd <filepath>`.** `--mvp` and `--prd` compose. The PRD express path (Step 3.5) creates `CONTEXT.md` from the PRD file and continues to research; the Walking Skeleton gate fires independently from the conditions above. When both are active on Phase 1 of a new project, the planner receives `WALKING_SKELETON=true` and PRD-derived context simultaneously — the PRD informs *what the skeleton should prove*. No precedence is needed; the two signals are orthogonal. See [`references/mvp-concepts.md`](../references/mvp-concepts.md) for the broader interaction map.
Extract `--prd <filepath>` from $ARGUMENTS. If present, set PRD_FILE to the filepath.
Extract express-path args from $ARGUMENTS: `PRD_FILE` (`--prd <filepath>`), `INGEST_PATH` (`--ingest <path-or-glob>`), and optional `INGEST_FORMAT` (`--ingest-format <auto|nygard|madr|narrative>`, default `auto`).
`--prd` and `--ingest` are mutually exclusive. If both are present, error and exit:
`Invalid arguments: cannot combine \`--prd\` with \`--ingest\`.`
**If no phase number:** Detect next unplanned phase from roadmap.
@@ -261,9 +264,24 @@ gsd-sdk query commit "docs(${padded_phase}): generate context from PRD" --files
**Effect:** This completely bypasses step 4 (Load CONTEXT.md) since we just created it. The rest of the workflow (research, planning, verification) proceeds normally with the PRD-derived context.
## 3.6. Handle ADR Ingest Express Path
**Skip if:** No `--ingest` flag in arguments.
**If `--ingest <path-or-glob>` provided:**
1. Display banner: `GSD ► ADR Ingest Express Path` with `{INGEST_PATH}` and `{INGEST_FORMAT}`.
2. Parse each resolved ADR through `get-shit-done/bin/lib/adr-parser.cjs` (`--input`, `--format`) and collect normalized records.
3. Status gate: reject `superseded`/`rejected`/`deprecated`; warn on `proposed`; missing status defaults to `accepted`.
4. Empty-decisions fallback: if all parsed ADRs have zero `decisions[]`, emit `ADR ingest produced no locked decisions; fall back to discuss-phase for this phase.` and exit with `/gsd-discuss-phase {N}` guidance.
5. Generate CONTEXT.md using `<domain>`, `<decisions>`, `<canonical_refs>`, `<specifics>`, `<deferred>`, `<scope_fence>`, map `consequences_positive[]` to Success Criteria and `consequences_negative[]` to Risk Summary, and include `**Source:** ADR Ingest Express Path ({INGEST_PATH})`.
6. Commit with `gsd-sdk query commit "docs(${padded_phase}): generate context from ADR ingest" --files "${phase_dir}/${padded_phase}-CONTEXT.md"` and set `context_content`; continue to step 5.
**Effect:** This bypasses step 4 (Load CONTEXT.md) since CONTEXT.md was synthesized from ADR input.
## 4. Load CONTEXT.md
**Skip if:** PRD express path was used (CONTEXT.md already created in step 3.5).
**Skip if:** PRD express path or ADR ingest express path was used (CONTEXT.md already created in step 3.5/3.6).
Check `context_path` from init JSON.