docguard-cli 0.9.4 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +281 -203
- package/cli/commands/init.mjs +1 -0
- package/cli/scanners/speckit.mjs +318 -87
- package/cli/validators/metrics-consistency.mjs +2 -1
- package/cli/validators/traceability.mjs +17 -9
- package/commands/docguard.fix.md +65 -0
- package/commands/docguard.guard.md +60 -0
- package/commands/docguard.review.md +53 -0
- package/commands/docguard.score.md +61 -0
- package/docs/installation.md +37 -19
- package/docs/quickstart.md +21 -6
- package/extensions/spec-kit-docguard/LICENSE +21 -0
- package/extensions/spec-kit-docguard/README.md +105 -0
- package/extensions/spec-kit-docguard/commands/diagnose.md +43 -0
- package/extensions/spec-kit-docguard/commands/generate.md +50 -0
- package/extensions/spec-kit-docguard/commands/guard.md +73 -0
- package/extensions/spec-kit-docguard/commands/init.md +38 -0
- package/extensions/spec-kit-docguard/commands/score.md +53 -0
- package/extensions/spec-kit-docguard/commands/trace.md +56 -0
- package/extensions/spec-kit-docguard/extension.yml +109 -0
- package/extensions/spec-kit-docguard/scripts/bash/common.sh +106 -0
- package/extensions/spec-kit-docguard/scripts/bash/docguard-check-docs.sh +153 -0
- package/extensions/spec-kit-docguard/scripts/bash/docguard-init-doc.sh +153 -0
- package/extensions/spec-kit-docguard/scripts/bash/docguard-suggest-fix.sh +107 -0
- package/extensions/spec-kit-docguard/skills/docguard-fix/SKILL.md +218 -0
- package/extensions/spec-kit-docguard/skills/docguard-guard/SKILL.md +167 -0
- package/extensions/spec-kit-docguard/skills/docguard-review/SKILL.md +182 -0
- package/extensions/spec-kit-docguard/skills/docguard-score/SKILL.md +178 -0
- package/extensions/spec-kit-docguard/templates/extensions.yml +39 -0
- package/package.json +5 -2
- package/templates/REQUIREMENTS.md.template +68 -0
- package/templates/commands/docguard.fix.md +35 -39
- package/templates/commands/docguard.guard.md +26 -13
- package/templates/commands/docguard.init.md +35 -28
- package/templates/commands/docguard.review.md +33 -23
- package/templates/commands/docguard.update.md +15 -4
package/cli/scanners/speckit.mjs
CHANGED
|
@@ -1,30 +1,114 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Spec Kit Scanner — Detect and integrate with GitHub Spec Kit
|
|
2
|
+
* Spec Kit Scanner — Detect, validate, and integrate with GitHub Spec Kit
|
|
3
3
|
*
|
|
4
|
-
* Auto-detects
|
|
5
|
-
*
|
|
6
|
-
* with Spec Kit-managed projects.
|
|
4
|
+
* Auto-detects Spec Kit artifacts and validates their quality against
|
|
5
|
+
* spec-kit standards (github.com/github/spec-kit).
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
* .specify/
|
|
10
|
-
* specs/
|
|
11
|
-
* specs/
|
|
12
|
-
* specs/
|
|
13
|
-
* constitution.md
|
|
14
|
-
* memory/ → Learned context (maps to DRIFT-LOG.md)
|
|
7
|
+
* v0.9.5 — Aligned with spec-kit's actual file structure:
|
|
8
|
+
* .specify/ → Project uses Spec Kit
|
|
9
|
+
* .specify/specs/NNN-feature/spec.md → Requirements (FR-IDs, User Scenarios)
|
|
10
|
+
* .specify/specs/NNN-feature/plan.md → Implementation plan (Technical Context)
|
|
11
|
+
* .specify/specs/NNN-feature/tasks.md → Task breakdown (Phased)
|
|
12
|
+
* .specify/memory/constitution.md → Project governing principles
|
|
15
13
|
*
|
|
16
|
-
*
|
|
14
|
+
* Also supports legacy paths (pre-v3 spec-kit):
|
|
15
|
+
* specs/[name]/spec.md → Legacy spec location
|
|
16
|
+
* constitution.md → Legacy constitution at root
|
|
17
|
+
* memory/ → Legacy memory at root
|
|
18
|
+
*
|
|
19
|
+
* Credit: Integration with GitHub's Spec Kit framework
|
|
17
20
|
* (github.com/github/spec-kit)
|
|
18
21
|
*
|
|
19
22
|
* Zero dependencies — pure Node.js built-ins only.
|
|
20
23
|
*/
|
|
21
24
|
|
|
22
|
-
import { existsSync, readFileSync, readdirSync,
|
|
25
|
+
import { existsSync, readFileSync, readdirSync, statSync, copyFileSync, writeFileSync } from 'node:fs';
|
|
23
26
|
import { resolve, join } from 'node:path';
|
|
24
27
|
|
|
28
|
+
// ──── Spec Kit Mandatory Sections ────
|
|
29
|
+
// Based on spec-kit's spec-template.md, plan-template.md, tasks-template.md
|
|
30
|
+
|
|
31
|
+
const SPEC_MANDATORY_SECTIONS = [
|
|
32
|
+
'User Scenarios', // or "User Stories"
|
|
33
|
+
'Requirements', // must have FR-xxx IDs
|
|
34
|
+
'Success Criteria', // must have SC-xxx IDs
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
const PLAN_MANDATORY_SECTIONS = [
|
|
38
|
+
'Summary',
|
|
39
|
+
'Technical Context',
|
|
40
|
+
'Project Structure',
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const TASKS_MANDATORY_PATTERNS = [
|
|
44
|
+
/Phase\s+\d/i, // Must have phased breakdown
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
// ──── Safety Helper ────
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Create a .bak backup before overwriting existing files.
|
|
51
|
+
*/
|
|
52
|
+
function backupFile(filePath) {
|
|
53
|
+
if (existsSync(filePath)) {
|
|
54
|
+
try {
|
|
55
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
56
|
+
if (content.trim().length > 0) {
|
|
57
|
+
copyFileSync(filePath, filePath + '.bak');
|
|
58
|
+
}
|
|
59
|
+
} catch { /* non-fatal */ }
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function safeWrite(filePath, content) {
|
|
64
|
+
backupFile(filePath);
|
|
65
|
+
writeFileSync(filePath, content, 'utf-8');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ──── Detection ────
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Scan a specs directory for feature spec folders.
|
|
72
|
+
* Returns array of { name, hasSpec, hasPlan, hasTasks, specPath, planPath, tasksPath }.
|
|
73
|
+
*/
|
|
74
|
+
function scanSpecsDir(specsDir) {
|
|
75
|
+
const specs = [];
|
|
76
|
+
if (!existsSync(specsDir)) return specs;
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
const features = readdirSync(specsDir);
|
|
80
|
+
for (const feature of features) {
|
|
81
|
+
const featureDir = join(specsDir, feature);
|
|
82
|
+
try {
|
|
83
|
+
if (!statSync(featureDir).isDirectory()) continue;
|
|
84
|
+
} catch { continue; }
|
|
85
|
+
|
|
86
|
+
const specFile = join(featureDir, 'spec.md');
|
|
87
|
+
const planFile = join(featureDir, 'plan.md');
|
|
88
|
+
const tasksFile = join(featureDir, 'tasks.md');
|
|
89
|
+
|
|
90
|
+
if (existsSync(specFile) || existsSync(planFile) || existsSync(tasksFile)) {
|
|
91
|
+
specs.push({
|
|
92
|
+
name: feature,
|
|
93
|
+
hasSpec: existsSync(specFile),
|
|
94
|
+
hasPlan: existsSync(planFile),
|
|
95
|
+
hasTasks: existsSync(tasksFile),
|
|
96
|
+
specPath: existsSync(specFile) ? specFile : null,
|
|
97
|
+
planPath: existsSync(planFile) ? planFile : null,
|
|
98
|
+
tasksPath: existsSync(tasksFile) ? tasksFile : null,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} catch { /* ignore */ }
|
|
103
|
+
|
|
104
|
+
return specs;
|
|
105
|
+
}
|
|
106
|
+
|
|
25
107
|
/**
|
|
26
108
|
* Detect if a project uses Spec Kit.
|
|
27
|
-
*
|
|
109
|
+
* Checks both spec-kit v3+ paths (.specify/) and legacy paths.
|
|
110
|
+
*
|
|
111
|
+
* @returns {{ detected, specifyDir, specs[], constitution, constitutionPath, memory, source }}
|
|
28
112
|
*/
|
|
29
113
|
export function detectSpecKit(projectDir) {
|
|
30
114
|
const result = {
|
|
@@ -32,87 +116,189 @@ export function detectSpecKit(projectDir) {
|
|
|
32
116
|
specifyDir: false,
|
|
33
117
|
specs: [],
|
|
34
118
|
constitution: false,
|
|
119
|
+
constitutionPath: null,
|
|
35
120
|
memory: false,
|
|
121
|
+
source: null, // 'specify' (v3+) or 'legacy'
|
|
36
122
|
};
|
|
37
123
|
|
|
38
|
-
// Check for .specify/ directory
|
|
124
|
+
// ── 1. Check for .specify/ directory (v3+ standard) ──
|
|
39
125
|
const specifyDir = resolve(projectDir, '.specify');
|
|
40
126
|
if (existsSync(specifyDir)) {
|
|
41
127
|
result.detected = true;
|
|
42
128
|
result.specifyDir = true;
|
|
129
|
+
result.source = 'specify';
|
|
130
|
+
|
|
131
|
+
// Specs under .specify/specs/ (v3 standard path)
|
|
132
|
+
const v3Specs = scanSpecsDir(resolve(specifyDir, 'specs'));
|
|
133
|
+
if (v3Specs.length > 0) {
|
|
134
|
+
result.specs.push(...v3Specs);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Constitution at .specify/memory/constitution.md (v3 standard)
|
|
138
|
+
const v3Constitution = resolve(specifyDir, 'memory', 'constitution.md');
|
|
139
|
+
if (existsSync(v3Constitution)) {
|
|
140
|
+
result.constitution = true;
|
|
141
|
+
result.constitutionPath = v3Constitution;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Memory directory at .specify/memory/ (v3 standard)
|
|
145
|
+
const v3Memory = resolve(specifyDir, 'memory');
|
|
146
|
+
if (existsSync(v3Memory)) {
|
|
147
|
+
result.memory = true;
|
|
148
|
+
}
|
|
43
149
|
}
|
|
44
150
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (!fstat.isDirectory()) continue;
|
|
55
|
-
} catch { continue; }
|
|
56
|
-
|
|
57
|
-
const specFile = join(featureDir, 'spec.md');
|
|
58
|
-
const planFile = join(featureDir, 'plan.md');
|
|
59
|
-
const tasksFile = join(featureDir, 'tasks.md');
|
|
60
|
-
|
|
61
|
-
if (existsSync(specFile) || existsSync(planFile) || existsSync(tasksFile)) {
|
|
62
|
-
result.detected = true;
|
|
63
|
-
result.specs.push({
|
|
64
|
-
name: feature,
|
|
65
|
-
hasSpec: existsSync(specFile),
|
|
66
|
-
hasPlan: existsSync(planFile),
|
|
67
|
-
hasTasks: existsSync(tasksFile),
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
} catch { /* ignore */ }
|
|
151
|
+
// ── 2. Legacy paths (fallback for pre-v3 or manual setups) ──
|
|
152
|
+
// Only check legacy if not already detected via .specify/
|
|
153
|
+
if (result.specs.length === 0) {
|
|
154
|
+
const legacySpecs = scanSpecsDir(resolve(projectDir, 'specs'));
|
|
155
|
+
if (legacySpecs.length > 0) {
|
|
156
|
+
result.detected = true;
|
|
157
|
+
result.source = result.source || 'legacy';
|
|
158
|
+
result.specs.push(...legacySpecs);
|
|
159
|
+
}
|
|
72
160
|
}
|
|
73
161
|
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
162
|
+
// Constitution at project root (legacy)
|
|
163
|
+
if (!result.constitution) {
|
|
164
|
+
const rootConstitution = resolve(projectDir, 'constitution.md');
|
|
165
|
+
if (existsSync(rootConstitution)) {
|
|
166
|
+
result.detected = true;
|
|
167
|
+
result.constitution = true;
|
|
168
|
+
result.constitutionPath = rootConstitution;
|
|
169
|
+
result.source = result.source || 'legacy';
|
|
170
|
+
}
|
|
79
171
|
}
|
|
80
172
|
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
173
|
+
// Memory at project root (legacy)
|
|
174
|
+
if (!result.memory) {
|
|
175
|
+
const rootMemory = resolve(projectDir, 'memory');
|
|
176
|
+
if (existsSync(rootMemory)) {
|
|
177
|
+
result.detected = true;
|
|
178
|
+
result.memory = true;
|
|
179
|
+
result.source = result.source || 'legacy';
|
|
180
|
+
}
|
|
86
181
|
}
|
|
87
182
|
|
|
88
183
|
return result;
|
|
89
184
|
}
|
|
90
185
|
|
|
186
|
+
// ──── Quality Validation ────
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Check if a markdown file contains specific section headings.
|
|
190
|
+
*
|
|
191
|
+
* @param {string} content - File content
|
|
192
|
+
* @param {string[]} sections - Required section heading texts
|
|
193
|
+
* @returns {{ found: string[], missing: string[] }}
|
|
194
|
+
*/
|
|
195
|
+
function checkSections(content, sections) {
|
|
196
|
+
const found = [];
|
|
197
|
+
const missing = [];
|
|
198
|
+
|
|
199
|
+
for (const section of sections) {
|
|
200
|
+
// Match both "## Requirements" and "### Functional Requirements"
|
|
201
|
+
const pattern = new RegExp(`^#{1,4}\\s+.*${section.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`, 'im');
|
|
202
|
+
if (pattern.test(content)) {
|
|
203
|
+
found.push(section);
|
|
204
|
+
} else {
|
|
205
|
+
missing.push(section);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return { found, missing };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Validate the quality of a spec.md file against spec-kit standards.
|
|
214
|
+
*
|
|
215
|
+
* Checks:
|
|
216
|
+
* - Has mandatory sections (User Scenarios, Requirements, Success Criteria)
|
|
217
|
+
* - Has FR-xxx requirement IDs
|
|
218
|
+
* - Has acceptance scenarios (Given/When/Then)
|
|
219
|
+
*/
|
|
220
|
+
function validateSpecQuality(specPath) {
|
|
221
|
+
const issues = [];
|
|
222
|
+
const content = readFileSync(specPath, 'utf-8');
|
|
223
|
+
|
|
224
|
+
// Check mandatory sections
|
|
225
|
+
const { missing } = checkSections(content, SPEC_MANDATORY_SECTIONS);
|
|
226
|
+
for (const section of missing) {
|
|
227
|
+
issues.push(`Missing mandatory section: "${section}" (spec-kit spec-template.md)`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Check for FR-xxx or FR-NNN requirement IDs
|
|
231
|
+
const hasFRIds = /\b(FR|REQ|NFR)-\d{2,4}\b/.test(content);
|
|
232
|
+
if (!hasFRIds) {
|
|
233
|
+
issues.push('No requirement IDs found (expected FR-001, REQ-001, etc.)');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Check for SC-xxx success criteria IDs
|
|
237
|
+
const hasSCIds = /\bSC-\d{2,4}\b/.test(content);
|
|
238
|
+
if (!hasSCIds) {
|
|
239
|
+
issues.push('No success criteria IDs found (expected SC-001, SC-002, etc.)');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return issues;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Validate the quality of a plan.md file.
|
|
247
|
+
*/
|
|
248
|
+
function validatePlanQuality(planPath) {
|
|
249
|
+
const issues = [];
|
|
250
|
+
const content = readFileSync(planPath, 'utf-8');
|
|
251
|
+
|
|
252
|
+
const { missing } = checkSections(content, PLAN_MANDATORY_SECTIONS);
|
|
253
|
+
for (const section of missing) {
|
|
254
|
+
issues.push(`Missing mandatory section: "${section}" (spec-kit plan-template.md)`);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return issues;
|
|
258
|
+
}
|
|
259
|
+
|
|
91
260
|
/**
|
|
92
|
-
*
|
|
93
|
-
* Returns the canonical doc name and section.
|
|
261
|
+
* Validate the quality of a tasks.md file.
|
|
94
262
|
*/
|
|
263
|
+
function validateTasksQuality(tasksPath) {
|
|
264
|
+
const issues = [];
|
|
265
|
+
const content = readFileSync(tasksPath, 'utf-8');
|
|
266
|
+
|
|
267
|
+
// Must have phased breakdown
|
|
268
|
+
const hasPhases = TASKS_MANDATORY_PATTERNS.some(p => p.test(content));
|
|
269
|
+
if (!hasPhases) {
|
|
270
|
+
issues.push('No phased task breakdown found (expected "Phase 1:", "Phase 2:", etc.)');
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Must have task IDs
|
|
274
|
+
const hasTaskIds = /\bT\d{3}\b/.test(content);
|
|
275
|
+
if (!hasTaskIds) {
|
|
276
|
+
issues.push('No task IDs found (expected T001, T002, etc.)');
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return issues;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// ──── CDD Mapping ────
|
|
283
|
+
|
|
95
284
|
const SPECKIT_CDD_MAP = {
|
|
96
285
|
'spec.md': { cddDoc: 'REQUIREMENTS.md', section: 'Requirements', type: 'requirement' },
|
|
97
286
|
'plan.md': { cddDoc: 'ARCHITECTURE.md', section: 'Design Decisions', type: 'design' },
|
|
98
287
|
'tasks.md': { cddDoc: 'ROADMAP.md', section: 'Task Backlog', type: 'roadmap' },
|
|
99
288
|
};
|
|
100
289
|
|
|
290
|
+
// ──── Generate from Spec Kit ────
|
|
291
|
+
|
|
101
292
|
/**
|
|
102
293
|
* Generate CDD canonical docs from Spec Kit artifacts.
|
|
103
294
|
* Used by `docguard generate --from-speckit`.
|
|
104
|
-
*
|
|
105
|
-
* @param {string} projectDir - Project root
|
|
106
|
-
* @param {object} config - DocGuard config
|
|
107
|
-
* @param {object} flags - CLI flags
|
|
108
|
-
* @returns {object} - { generated: string[], skipped: string[], errors: string[] }
|
|
109
295
|
*/
|
|
110
296
|
export function generateFromSpecKit(projectDir, config, flags) {
|
|
111
297
|
const results = { generated: [], skipped: [], errors: [] };
|
|
112
298
|
|
|
113
299
|
const speckit = detectSpecKit(projectDir);
|
|
114
300
|
if (!speckit.detected) {
|
|
115
|
-
results.errors.push('No Spec Kit artifacts detected.
|
|
301
|
+
results.errors.push('No Spec Kit artifacts detected. Run `specify init` to initialize, or install via: uv tool install specify-cli --from git+https://github.com/github/spec-kit.git');
|
|
116
302
|
return results;
|
|
117
303
|
}
|
|
118
304
|
|
|
@@ -131,8 +317,7 @@ export function generateFromSpecKit(projectDir, config, flags) {
|
|
|
131
317
|
|
|
132
318
|
for (const spec of speckit.specs) {
|
|
133
319
|
if (!spec.hasSpec) continue;
|
|
134
|
-
const
|
|
135
|
-
const content = readFileSync(specPath, 'utf-8');
|
|
320
|
+
const content = readFileSync(spec.specPath, 'utf-8');
|
|
136
321
|
|
|
137
322
|
lines.push(`## ${spec.name}`);
|
|
138
323
|
lines.push('');
|
|
@@ -144,20 +329,17 @@ export function generateFromSpecKit(projectDir, config, flags) {
|
|
|
144
329
|
|
|
145
330
|
lines.push(`<!-- Generated by DocGuard from Spec Kit artifacts on ${new Date().toISOString().split('T')[0]} -->`);
|
|
146
331
|
|
|
147
|
-
|
|
332
|
+
safeWrite(reqPath, lines.join('\n'));
|
|
148
333
|
results.generated.push('REQUIREMENTS.md');
|
|
149
334
|
}
|
|
150
335
|
}
|
|
151
336
|
|
|
152
337
|
// ── Map constitution.md to AGENTS.md context ──
|
|
153
338
|
if (speckit.constitution) {
|
|
154
|
-
const constitutionPath = resolve(projectDir, 'constitution.md');
|
|
155
339
|
const agentsPath = resolve(projectDir, 'AGENTS.md');
|
|
156
340
|
|
|
157
341
|
if (existsSync(agentsPath)) {
|
|
158
342
|
const agentsContent = readFileSync(agentsPath, 'utf-8');
|
|
159
|
-
|
|
160
|
-
// Check if AGENTS.md already references constitution
|
|
161
343
|
if (!agentsContent.includes('constitution.md') && !agentsContent.includes('Constitution')) {
|
|
162
344
|
results.skipped.push('AGENTS.md exists but does not reference constitution.md — consider adding a reference');
|
|
163
345
|
} else {
|
|
@@ -166,17 +348,27 @@ export function generateFromSpecKit(projectDir, config, flags) {
|
|
|
166
348
|
}
|
|
167
349
|
}
|
|
168
350
|
|
|
169
|
-
// ── Map memory/ to DRIFT-LOG.md
|
|
351
|
+
// ── Map memory/ to DRIFT-LOG.md ──
|
|
170
352
|
if (speckit.memory) {
|
|
171
|
-
results.skipped.push('memory/ directory detected — maps conceptually to DRIFT-LOG.md
|
|
353
|
+
results.skipped.push('memory/ directory detected — maps conceptually to DRIFT-LOG.md');
|
|
172
354
|
}
|
|
173
355
|
|
|
174
356
|
return results;
|
|
175
357
|
}
|
|
176
358
|
|
|
359
|
+
// ──── Guard Validator ────
|
|
360
|
+
|
|
177
361
|
/**
|
|
178
|
-
* Validate Spec Kit
|
|
179
|
-
*
|
|
362
|
+
* Validate Spec Kit integration quality.
|
|
363
|
+
*
|
|
364
|
+
* When spec-kit is NOT detected:
|
|
365
|
+
* - Shows 1 informational warning suggesting spec-kit
|
|
366
|
+
*
|
|
367
|
+
* When spec-kit IS detected:
|
|
368
|
+
* - Validates spec.md quality (mandatory sections, FR-IDs, SC-IDs)
|
|
369
|
+
* - Validates plan.md quality (mandatory sections)
|
|
370
|
+
* - Validates tasks.md quality (phased breakdown, T-IDs)
|
|
371
|
+
* - Checks constitution → AGENTS.md mapping
|
|
180
372
|
*
|
|
181
373
|
* @returns {{ errors: string[], warnings: string[], passed: number, total: number }}
|
|
182
374
|
*/
|
|
@@ -185,41 +377,80 @@ export function validateSpecKitIntegration(projectDir, config) {
|
|
|
185
377
|
|
|
186
378
|
const speckit = detectSpecKit(projectDir);
|
|
187
379
|
|
|
188
|
-
// If no Spec Kit detected,
|
|
380
|
+
// If no Spec Kit detected, suggest it
|
|
189
381
|
if (!speckit.detected) {
|
|
382
|
+
results.total++;
|
|
383
|
+
results.warnings.push(
|
|
384
|
+
'No Spec Kit artifacts detected. Consider `specify init` for spec-driven development (github.com/github/spec-kit)'
|
|
385
|
+
);
|
|
190
386
|
return results;
|
|
191
387
|
}
|
|
192
388
|
|
|
193
|
-
// Check 1: .specify/ directory exists
|
|
389
|
+
// ── Check 1: .specify/ directory exists ──
|
|
194
390
|
results.total++;
|
|
195
391
|
if (speckit.specifyDir) {
|
|
196
392
|
results.passed++;
|
|
197
393
|
} else {
|
|
198
|
-
results.warnings.push(
|
|
394
|
+
results.warnings.push(
|
|
395
|
+
'Spec Kit artifacts found but .specify/ directory missing. Run `specify init` to create standard structure'
|
|
396
|
+
);
|
|
199
397
|
}
|
|
200
398
|
|
|
201
|
-
// Check 2:
|
|
399
|
+
// ── Check 2: Validate each spec's quality ──
|
|
202
400
|
for (const spec of speckit.specs) {
|
|
203
|
-
|
|
401
|
+
// 2a: spec.md quality
|
|
402
|
+
if (spec.hasSpec && spec.specPath) {
|
|
204
403
|
results.total++;
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
404
|
+
try {
|
|
405
|
+
const issues = validateSpecQuality(spec.specPath);
|
|
406
|
+
if (issues.length === 0) {
|
|
407
|
+
results.passed++;
|
|
408
|
+
} else {
|
|
409
|
+
for (const issue of issues) {
|
|
410
|
+
results.warnings.push(`specs/${spec.name}/spec.md: ${issue}`);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
} catch {
|
|
414
|
+
results.warnings.push(`specs/${spec.name}/spec.md: Could not read file`);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
208
417
|
|
|
209
|
-
|
|
210
|
-
|
|
418
|
+
// 2b: plan.md quality
|
|
419
|
+
if (spec.hasPlan && spec.planPath) {
|
|
420
|
+
results.total++;
|
|
421
|
+
try {
|
|
422
|
+
const issues = validatePlanQuality(spec.planPath);
|
|
423
|
+
if (issues.length === 0) {
|
|
424
|
+
results.passed++;
|
|
425
|
+
} else {
|
|
426
|
+
for (const issue of issues) {
|
|
427
|
+
results.warnings.push(`specs/${spec.name}/plan.md: ${issue}`);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
} catch {
|
|
431
|
+
results.warnings.push(`specs/${spec.name}/plan.md: Could not read file`);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
211
434
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
)
|
|
435
|
+
// 2c: tasks.md quality
|
|
436
|
+
if (spec.hasTasks && spec.tasksPath) {
|
|
437
|
+
results.total++;
|
|
438
|
+
try {
|
|
439
|
+
const issues = validateTasksQuality(spec.tasksPath);
|
|
440
|
+
if (issues.length === 0) {
|
|
441
|
+
results.passed++;
|
|
442
|
+
} else {
|
|
443
|
+
for (const issue of issues) {
|
|
444
|
+
results.warnings.push(`specs/${spec.name}/tasks.md: ${issue}`);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
} catch {
|
|
448
|
+
results.warnings.push(`specs/${spec.name}/tasks.md: Could not read file`);
|
|
218
449
|
}
|
|
219
450
|
}
|
|
220
451
|
}
|
|
221
452
|
|
|
222
|
-
// Check 3: Constitution
|
|
453
|
+
// ── Check 3: Constitution → AGENTS.md mapping ──
|
|
223
454
|
if (speckit.constitution) {
|
|
224
455
|
results.total++;
|
|
225
456
|
const agentsPath = resolve(projectDir, 'AGENTS.md');
|
|
@@ -36,7 +36,8 @@ export function validateMetricsConsistency(projectDir, config, guardResults) {
|
|
|
36
36
|
if (r.status === 'skipped') return sum;
|
|
37
37
|
return sum + (r.total || 0);
|
|
38
38
|
}, 0);
|
|
39
|
-
|
|
39
|
+
// +1 because Metrics-Consistency itself hasn't been added to results yet
|
|
40
|
+
const validatorCount = guardResults.filter(r => r.status !== 'skipped').length + 1;
|
|
40
41
|
|
|
41
42
|
actuals.checks = totalChecks;
|
|
42
43
|
actuals.validators = validatorCount;
|
|
@@ -72,6 +72,7 @@ const TRACE_MAP = {
|
|
|
72
72
|
|
|
73
73
|
// ──── Default requirement ID patterns ────
|
|
74
74
|
// Users can override via config.traceability.requirementPattern
|
|
75
|
+
// Includes spec-kit standard IDs: FR-xxx, SC-xxx, T-xxx
|
|
75
76
|
const DEFAULT_REQ_PATTERNS = [
|
|
76
77
|
/\b(REQ)-(\d{2,4})\b/g,
|
|
77
78
|
/\b(FR)-(\d{2,4})\b/g,
|
|
@@ -83,6 +84,8 @@ const DEFAULT_REQ_PATTERNS = [
|
|
|
83
84
|
/\b(SYS)-(\d{2,4})\b/g,
|
|
84
85
|
/\b(ARCH)-(\d{2,4})\b/g,
|
|
85
86
|
/\b(MOD)-(\d{2,4})\b/g,
|
|
87
|
+
/\b(SC)-(\d{2,4})\b/g, // Spec Kit: Success Criteria
|
|
88
|
+
/\b(T)(\d{3,4})\b/g, // Spec Kit: Task IDs (T001, T002)
|
|
86
89
|
];
|
|
87
90
|
|
|
88
91
|
/**
|
|
@@ -305,15 +308,20 @@ function getRequirementDocPaths(projectDir, config) {
|
|
|
305
308
|
if (existsSync(p) && !paths.includes(p)) paths.push(p);
|
|
306
309
|
}
|
|
307
310
|
|
|
308
|
-
// Spec Kit artifacts: specs/*/spec.md
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
311
|
+
// Spec Kit artifacts: .specify/specs/*/spec.md (v3+) and specs/*/spec.md (legacy)
|
|
312
|
+
const specKitDirs = [
|
|
313
|
+
resolve(projectDir, '.specify', 'specs'), // v3+ standard
|
|
314
|
+
resolve(projectDir, 'specs'), // legacy
|
|
315
|
+
];
|
|
316
|
+
for (const specsDir of specKitDirs) {
|
|
317
|
+
if (existsSync(specsDir)) {
|
|
318
|
+
try {
|
|
319
|
+
for (const feature of readdirSync(specsDir)) {
|
|
320
|
+
const specPath = join(specsDir, feature, 'spec.md');
|
|
321
|
+
if (existsSync(specPath) && !paths.includes(specPath)) paths.push(specPath);
|
|
322
|
+
}
|
|
323
|
+
} catch { /* ignore */ }
|
|
324
|
+
}
|
|
317
325
|
}
|
|
318
326
|
|
|
319
327
|
return paths;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: AI-driven documentation repair — research codebase, generate content, validate against CDD standards
|
|
3
|
+
handoffs:
|
|
4
|
+
- label: Verify Fixes
|
|
5
|
+
agent: docguard.guard
|
|
6
|
+
prompt: Run guard to verify all fixes pass
|
|
7
|
+
- label: Check Score Improvement
|
|
8
|
+
agent: docguard.score
|
|
9
|
+
prompt: Show score improvement after fixes
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# DocGuard Fix — AI-Assisted Documentation Repair
|
|
13
|
+
|
|
14
|
+
Generate or repair canonical documentation by researching the actual codebase.
|
|
15
|
+
|
|
16
|
+
## What to do
|
|
17
|
+
|
|
18
|
+
1. **Identify what needs fixing**:
|
|
19
|
+
```bash
|
|
20
|
+
npx docguard-cli diagnose
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
2. **For a specific document**, generate a research-aware fix prompt:
|
|
24
|
+
```bash
|
|
25
|
+
npx docguard-cli fix --doc architecture
|
|
26
|
+
npx docguard-cli fix --doc security
|
|
27
|
+
npx docguard-cli fix --doc test-spec
|
|
28
|
+
npx docguard-cli fix --doc data-model
|
|
29
|
+
npx docguard-cli fix --doc environment
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
3. **Execute the research workflow** from the generated prompt:
|
|
33
|
+
- Read actual code files (not just filenames)
|
|
34
|
+
- Map module structure and dependencies
|
|
35
|
+
- Extract real data structures and schemas
|
|
36
|
+
- Identify actual auth mechanisms and security patterns
|
|
37
|
+
|
|
38
|
+
4. **Write documentation with real content**:
|
|
39
|
+
- Use actual file paths, module names, dependency names
|
|
40
|
+
- Include working command examples
|
|
41
|
+
- Use positive language (IEEE 830: "MUST use" not "MUST NOT avoid")
|
|
42
|
+
- Ensure Flesch-Kincaid grade level 8-10
|
|
43
|
+
|
|
44
|
+
5. **Include metadata header** in every canonical doc:
|
|
45
|
+
```markdown
|
|
46
|
+
<!-- docguard:version X.X.X -->
|
|
47
|
+
<!-- docguard:status active -->
|
|
48
|
+
<!-- docguard:last-reviewed YYYY-MM-DD -->
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
6. **Validate the fix** (iterate up to 3 times):
|
|
52
|
+
```bash
|
|
53
|
+
npx docguard-cli guard
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
7. If the project uses Spec Kit, align with spec-kit templates:
|
|
57
|
+
- `spec.md`: User Scenarios, Requirements (FR-IDs), Success Criteria (SC-IDs)
|
|
58
|
+
- `plan.md`: Summary, Technical Context, Project Structure
|
|
59
|
+
- `tasks.md`: Phased breakdown (Phase 1, 2, 3+), Task IDs (T001+)
|
|
60
|
+
|
|
61
|
+
## Important
|
|
62
|
+
|
|
63
|
+
- Never use placeholder content — every section must reference real code
|
|
64
|
+
- Back up before overwriting — use `.bak` files or `safeWrite()`
|
|
65
|
+
- Log deviations in DRIFT-LOG.md with `// DRIFT: reason`
|