docguard-cli 0.15.3 → 0.16.0
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/cli/commands/diff.mjs +28 -2
- package/cli/commands/explain.mjs +286 -0
- package/cli/commands/hooks.mjs +82 -13
- package/cli/commands/init.mjs +5 -1
- package/cli/commands/score.mjs +9 -2
- package/cli/commands/trace.mjs +72 -25
- package/cli/docguard.mjs +19 -2
- package/cli/validators/environment.mjs +12 -0
- package/cli/validators/structure.mjs +26 -4
- package/extensions/spec-kit-docguard/extension.yml +1 -1
- package/extensions/spec-kit-docguard/skills/docguard-fix/SKILL.md +2 -2
- package/extensions/spec-kit-docguard/skills/docguard-guard/SKILL.md +2 -2
- package/extensions/spec-kit-docguard/skills/docguard-review/SKILL.md +2 -2
- package/extensions/spec-kit-docguard/skills/docguard-score/SKILL.md +2 -2
- package/extensions/spec-kit-docguard/skills/docguard-sync/SKILL.md +1 -1
- package/package.json +1 -1
package/cli/commands/diff.mjs
CHANGED
|
@@ -25,8 +25,12 @@ const CODE_EXTENSIONS = new Set([
|
|
|
25
25
|
]);
|
|
26
26
|
|
|
27
27
|
export function runDiff(projectDir, config, flags) {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
// v0.16-P1: headless mode for JSON output (matches guard/score/trace fix).
|
|
29
|
+
const isJson = flags.format === 'json';
|
|
30
|
+
if (!isJson) {
|
|
31
|
+
console.log(`${c.bold}🔍 DocGuard Diff — ${config.projectName}${c.reset}`);
|
|
32
|
+
console.log(`${c.dim} Directory: ${projectDir}${c.reset}\n`);
|
|
33
|
+
}
|
|
30
34
|
|
|
31
35
|
const results = [];
|
|
32
36
|
|
|
@@ -196,6 +200,25 @@ function diffEntities(dir, config = {}) {
|
|
|
196
200
|
};
|
|
197
201
|
}
|
|
198
202
|
|
|
203
|
+
// v0.16-P4: common system environment variables that get backticked in
|
|
204
|
+
// prose ("the venv `PATH`", "your `HOME` directory") but are NEVER user-set
|
|
205
|
+
// application env vars. Excluding them from the docVars set kills the
|
|
206
|
+
// false-positive class reported by the Python user where `PATH` was flagged
|
|
207
|
+
// as "documented-but-not-implemented".
|
|
208
|
+
//
|
|
209
|
+
// Conservative list — only the names that are unambiguously OS/shell vars.
|
|
210
|
+
// Application names like `DATABASE_URL`, `API_KEY` etc. still count.
|
|
211
|
+
const SYSTEM_ENV_VARS = new Set([
|
|
212
|
+
'PATH', 'HOME', 'USER', 'USERNAME', 'SHELL', 'PWD', 'OLDPWD', 'TMPDIR', 'TEMP', 'TMP',
|
|
213
|
+
'LANG', 'LC_ALL', 'LC_CTYPE', 'LC_MESSAGES', 'TZ',
|
|
214
|
+
'EDITOR', 'VISUAL', 'PAGER', 'TERM', 'COLORTERM',
|
|
215
|
+
'DISPLAY', 'SSH_AUTH_SOCK', 'SSH_CONNECTION', 'SSH_TTY',
|
|
216
|
+
'XDG_CONFIG_HOME', 'XDG_DATA_HOME', 'XDG_CACHE_HOME', 'XDG_RUNTIME_DIR',
|
|
217
|
+
// CI/build platform vars (set by the platform, not by the app)
|
|
218
|
+
'CI', 'GITHUB_TOKEN', 'GITHUB_ACTIONS', 'GITHUB_REF', 'GITHUB_SHA',
|
|
219
|
+
'NODE_ENV', // could be app-set but more often platform-set; conservative skip
|
|
220
|
+
]);
|
|
221
|
+
|
|
199
222
|
function diffEnvVars(dir, config = {}) {
|
|
200
223
|
const envDocPath = resolve(dir, 'docs-canonical/ENVIRONMENT.md');
|
|
201
224
|
if (!existsSync(envDocPath)) return null;
|
|
@@ -208,6 +231,9 @@ function diffEnvVars(dir, config = {}) {
|
|
|
208
231
|
const varRegex = /`([A-Z][A-Z0-9_]*[A-Z0-9])`/g;
|
|
209
232
|
let match;
|
|
210
233
|
while ((match = varRegex.exec(content)) !== null) {
|
|
234
|
+
// v0.16-P4: skip backticked system vars that appear in prose. They're
|
|
235
|
+
// never user-set application env vars; flagging them produces noise.
|
|
236
|
+
if (SYSTEM_ENV_VARS.has(match[1])) continue;
|
|
211
237
|
docVars.add(match[1]);
|
|
212
238
|
}
|
|
213
239
|
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Explain Command — v0.16-P6.
|
|
3
|
+
*
|
|
4
|
+
* Asked for by a user who'd spent 5-10 minutes per warning spelunking
|
|
5
|
+
* through validators/*.mjs source to understand what the validator wanted.
|
|
6
|
+
* `docguard explain "<warning text>"` matches the warning back to its
|
|
7
|
+
* validator and prints:
|
|
8
|
+
* - Which validator emitted it
|
|
9
|
+
* - What pattern triggered it
|
|
10
|
+
* - A passing example
|
|
11
|
+
* - The doc / spec / standard it's checking against
|
|
12
|
+
*
|
|
13
|
+
* Also supports `docguard explain <validator-key>` to show the whole
|
|
14
|
+
* validator's purpose without needing a specific warning.
|
|
15
|
+
*
|
|
16
|
+
* Zero NPM dependencies. Pure lookup table.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { c } from '../shared.mjs';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Validator-key → human-readable explainer. Keyed by the same key DocGuard
|
|
23
|
+
* uses internally for severity overrides + lite-mode selection.
|
|
24
|
+
*
|
|
25
|
+
* Each entry has:
|
|
26
|
+
* - title: one-line summary
|
|
27
|
+
* - what: what the validator checks (declarative)
|
|
28
|
+
* - why: why it matters (motivation)
|
|
29
|
+
* - triggers: array of common warning fragments and what each means
|
|
30
|
+
* - example: a tiny passing snippet
|
|
31
|
+
* - standard: the spec/practice the validator references
|
|
32
|
+
*/
|
|
33
|
+
const EXPLAINERS = {
|
|
34
|
+
structure: {
|
|
35
|
+
title: 'Structure — required CDD files exist',
|
|
36
|
+
what: 'Verifies the canonical files declared in .docguard.json `requiredFiles.canonical` are present, plus AGENTS.md/CLAUDE.md, CHANGELOG.md, DRIFT-LOG.md.',
|
|
37
|
+
why: 'A documentation memory needs known anchor points. Missing files = broken memory.',
|
|
38
|
+
triggers: [
|
|
39
|
+
['Missing required file', 'A canonical doc declared in your config doesn\'t exist on disk. Create it or remove it from `requiredFiles.canonical`.'],
|
|
40
|
+
['Missing agent file', 'No AGENTS.md or CLAUDE.md found. Create one — even a stub establishes the agent contract.'],
|
|
41
|
+
],
|
|
42
|
+
example: 'docs-canonical/ARCHITECTURE.md, AGENTS.md, CHANGELOG.md all present',
|
|
43
|
+
standard: 'CDD STANDARD (this project\'s STANDARD.md)',
|
|
44
|
+
},
|
|
45
|
+
docsSync: {
|
|
46
|
+
title: 'Docs-Sync — code files are referenced in canonical docs',
|
|
47
|
+
what: 'Walks route/service files in your source tree. For each, checks that the file path or basename appears in any canonical doc.',
|
|
48
|
+
why: 'Code that exists but isn\'t mentioned in any doc is invisible to future contributors and AI agents.',
|
|
49
|
+
triggers: [
|
|
50
|
+
['not referenced in any canonical doc', 'A route or service file has no mention anywhere in docs-canonical/. Add a one-line reference (path or filename) to ARCHITECTURE.md or DATA-MODEL.md.'],
|
|
51
|
+
],
|
|
52
|
+
example: '`src/services/auth.ts` mentioned in ARCHITECTURE.md\'s Components table',
|
|
53
|
+
standard: 'arc42 Component Map',
|
|
54
|
+
},
|
|
55
|
+
drift: {
|
|
56
|
+
title: 'Drift-Comments — every `// DRIFT:` has a DRIFT-LOG entry',
|
|
57
|
+
what: 'Scans code for `// DRIFT: reason` comments (also # / /* / -- variants). Each must have a row in DRIFT-LOG.md.',
|
|
58
|
+
why: 'DRIFT comments document conscious deviations from canonical specs. Without log entries, the deviation is invisible.',
|
|
59
|
+
triggers: [
|
|
60
|
+
['DRIFT comment but DRIFT-LOG.md doesn\'t exist', 'Create DRIFT-LOG.md or remove the DRIFT comment.'],
|
|
61
|
+
['no matching DRIFT-LOG.md entry', 'Add a row to DRIFT-LOG.md documenting the deviation, OR remove the // DRIFT: comment if the deviation is no longer current.'],
|
|
62
|
+
],
|
|
63
|
+
example: '// DRIFT: using S3 SDK v2 here for compatibility — DRIFT-LOG.md has a row dated and explaining why',
|
|
64
|
+
standard: 'CDD principle: log every intentional deviation',
|
|
65
|
+
},
|
|
66
|
+
changelog: {
|
|
67
|
+
title: 'Changelog — Keep a Changelog format',
|
|
68
|
+
what: 'CHANGELOG.md must have a top-level `# Changelog` heading and an `## [Unreleased]` section.',
|
|
69
|
+
why: 'Standard format makes changelogs machine-readable. The Unreleased section is where new work accumulates between releases.',
|
|
70
|
+
triggers: [
|
|
71
|
+
['Missing # Changelog heading', 'Start CHANGELOG.md with `# Changelog`.'],
|
|
72
|
+
['Missing ## [Unreleased] section', 'Add `## [Unreleased]` between `# Changelog` and your first dated release.'],
|
|
73
|
+
],
|
|
74
|
+
example: '# Changelog\\n\\n## [Unreleased]\\n\\n## [1.0.0] - 2026-01-01',
|
|
75
|
+
standard: 'Keep a Changelog v1.1.0 (https://keepachangelog.com)',
|
|
76
|
+
},
|
|
77
|
+
testSpec: {
|
|
78
|
+
title: 'Test-Spec — declared tests exist',
|
|
79
|
+
what: 'Reads TEST-SPEC.md\'s test mapping (rows linking sources to test files) and verifies each referenced test file exists.',
|
|
80
|
+
why: 'A spec that claims test coverage for X but the test file is missing is a stale promise.',
|
|
81
|
+
triggers: [
|
|
82
|
+
['no service-to-test mappings', 'TEST-SPEC.md has no recognized mapping table. Add a table with `| Source | Test file | Status |` columns.'],
|
|
83
|
+
['referenced test file does not exist', 'A path in TEST-SPEC.md\'s mapping doesn\'t exist. Update the path or remove the row.'],
|
|
84
|
+
],
|
|
85
|
+
example: '| `src/auth.ts` | `tests/auth.test.ts` | ✅ |',
|
|
86
|
+
standard: 'ISO/IEC/IEEE 29119-3 (test specification)',
|
|
87
|
+
},
|
|
88
|
+
environment: {
|
|
89
|
+
title: 'Environment — env vars used in code are documented',
|
|
90
|
+
what: 'Greps `process.env.X` and `import.meta.env.X` (plus `os.environ` for Python) across source. Each name must appear in ENVIRONMENT.md or .env.example/.env.template.',
|
|
91
|
+
why: 'Undocumented env vars are runtime surprises waiting to happen.',
|
|
92
|
+
triggers: [
|
|
93
|
+
['used but not documented', 'Code reads an env var that ENVIRONMENT.md doesn\'t list. Add it to the table.'],
|
|
94
|
+
['VITE_API_URL or similar prefix', 'Naked prefixes like `VITE_` (no suffix) get filtered out — they\'re convention markers, not real var names.'],
|
|
95
|
+
],
|
|
96
|
+
example: '`DATABASE_URL` listed in ENVIRONMENT.md\'s Environment Variables table AND read via `process.env.DATABASE_URL` in code',
|
|
97
|
+
standard: '12-Factor App III. Config',
|
|
98
|
+
},
|
|
99
|
+
security: {
|
|
100
|
+
title: 'Security — secrets handling + auth presence',
|
|
101
|
+
what: 'Checks SECURITY.md for required sections, and scans code for committed secrets / unsafe patterns.',
|
|
102
|
+
why: 'OWASP ASVS baseline.',
|
|
103
|
+
triggers: [
|
|
104
|
+
['Missing "Authentication" section', 'Add `## Authentication` to SECURITY.md. If the project genuinely has no auth (CLI, library), use the v0.16-P7 N/A marker: `<!-- docguard:section authentication n/a — reason -->`.'],
|
|
105
|
+
['Possible secret', 'A pattern matching common secret formats (API keys, JWT secrets) was found in committed code. Move to env var or .env.example.'],
|
|
106
|
+
],
|
|
107
|
+
example: 'SECURITY.md has `## Authentication` describing JWT flow; no `sk_live_*` strings in code',
|
|
108
|
+
standard: 'OWASP ASVS v4.0',
|
|
109
|
+
},
|
|
110
|
+
freshness: {
|
|
111
|
+
title: 'Freshness — docs updated alongside code',
|
|
112
|
+
what: 'For each canonical doc, counts code commits since the doc\'s last commit. >10 commits = stale.',
|
|
113
|
+
why: 'Docs drift silently. This validator surfaces the drift before it becomes invisible.',
|
|
114
|
+
triggers: [
|
|
115
|
+
['code commits since last doc update', 'Run `docguard sync --write` to refresh code-truth sections, then review the prose for accuracy.'],
|
|
116
|
+
['DRIFT-LOG.md may be stale', 'DRIFT comments in code outpaced log entries. Add the entries.'],
|
|
117
|
+
],
|
|
118
|
+
example: 'ARCHITECTURE.md last committed within 10 code commits',
|
|
119
|
+
standard: 'CDD principle: docs and code commit together',
|
|
120
|
+
},
|
|
121
|
+
traceability: {
|
|
122
|
+
title: 'Traceability — every FR/SC ID has test coverage',
|
|
123
|
+
what: 'Scans specs/ for FR-### and SC-### requirement IDs. Each must appear in a test file as `@req FR-###`.',
|
|
124
|
+
why: 'Untraceable requirements drift from implementation.',
|
|
125
|
+
triggers: [
|
|
126
|
+
['has no test coverage', 'Add `// @req FR-012` (or similar) as a comment in the test that verifies the requirement.'],
|
|
127
|
+
['orphaned test reference', 'A `@req` comment references an ID that doesn\'t exist in any spec. Update the ID or remove the marker.'],
|
|
128
|
+
],
|
|
129
|
+
example: 'spec.md defines `**FR-012**: ...` and test file has `// @req FR-012` near the test that verifies it',
|
|
130
|
+
standard: 'ISO/IEC/IEEE 29148 (requirements traceability)',
|
|
131
|
+
},
|
|
132
|
+
apiSurface: {
|
|
133
|
+
title: 'API-Surface — endpoints in code match API-REFERENCE.md',
|
|
134
|
+
what: 'Compares routes scanned from code (Express, Next, FastAPI, Spring, etc.) against endpoints listed in API-REFERENCE.md and OpenAPI specs.',
|
|
135
|
+
why: 'Documented but missing endpoints are dead links. Endpoints in code that aren\'t documented are invisible.',
|
|
136
|
+
triggers: [
|
|
137
|
+
['documented but absent', 'API-REFERENCE.md lists an endpoint that scanRoutes() can\'t find. Remove or fix the doc; `fix --write` removes when marked.'],
|
|
138
|
+
['present but undocumented', 'A route exists in code but API-REFERENCE.md doesn\'t list it. Add it.'],
|
|
139
|
+
],
|
|
140
|
+
example: 'GET /api/users in src/routes/users.ts AND in API-REFERENCE.md\'s Endpoints table',
|
|
141
|
+
standard: 'OpenAPI 3.1',
|
|
142
|
+
},
|
|
143
|
+
metricsConsistency: {
|
|
144
|
+
title: 'Metrics-Consistency — quoted numbers match reality',
|
|
145
|
+
what: 'Greps canonical + root docs for "N validators" / "N checks" claims and compares against the actual runtime count.',
|
|
146
|
+
why: 'Stale numeric claims ("19 validators" when it\'s now 22) erode credibility.',
|
|
147
|
+
triggers: [
|
|
148
|
+
['says "N validators" but actual count is M', 'Run `docguard fix --write` — this is auto-fixable.'],
|
|
149
|
+
],
|
|
150
|
+
example: 'AGENTS.md says "22 validators" and `docguard guard` shows 22 active validators',
|
|
151
|
+
standard: 'CDD principle: documented metrics match reality',
|
|
152
|
+
},
|
|
153
|
+
crossReference: {
|
|
154
|
+
title: 'Cross-Reference — internal markdown links resolve',
|
|
155
|
+
what: 'Scans canonical docs for `[text](./OTHER.md#anchor)` and `#anchor` links. Verifies the target file exists and the anchor matches a heading.',
|
|
156
|
+
why: 'Broken doc-to-doc links are the most-clicked dead ends in onboarding.',
|
|
157
|
+
triggers: [
|
|
158
|
+
['broken link: target file not found', 'The file path doesn\'t exist. Fix the path or remove the link.'],
|
|
159
|
+
['broken anchor', 'Anchor doesn\'t match any heading. Hint: `(did you mean #X?)` is appended for near-misses; if marked `[auto-fixable]`, run `docguard fix --write`.'],
|
|
160
|
+
],
|
|
161
|
+
example: '`[Setup](#prerequisites)` in ENVIRONMENT.md AND `## Prerequisites` heading present',
|
|
162
|
+
standard: 'GitHub Flavored Markdown anchor rules',
|
|
163
|
+
},
|
|
164
|
+
generatedStaleness: {
|
|
165
|
+
title: 'Generated-Staleness — source=code sections match scanner output',
|
|
166
|
+
what: 'For each `<!-- docguard:section source=code -->` block, re-runs the memory plan scanner and compares against on-disk content. Also flags status: draft docs unmodified for > 14 days.',
|
|
167
|
+
why: 'Code-truth sections must reflect what the code actually says. Forgotten drafts rot.',
|
|
168
|
+
triggers: [
|
|
169
|
+
['is stale', 'A code-truth section drifted. Run `docguard sync --write` (or `docguard fix --write` since v0.14-P3 — the validator now emits a regenerate-section fix).'],
|
|
170
|
+
['status: draft for', 'A doc has been in draft for too long. Promote to `status: current` or remove. Threshold via `config.draftStalenessDays`.'],
|
|
171
|
+
],
|
|
172
|
+
example: 'All source=code sections match what the scanner would produce right now',
|
|
173
|
+
standard: 'CDD principle: code-truth sections are machine-owned',
|
|
174
|
+
},
|
|
175
|
+
todoTracking: {
|
|
176
|
+
title: 'TODO-Tracking — TODOs are tracked + skipped tests explained',
|
|
177
|
+
what: 'Finds TODO/FIXME/HACK comments in source. Each must be referenced in tracking docs (ROADMAP.md, GitHub issues, etc.). Also flags `it.skip()` / `test.skip()` without an adjacent `// REASON:` comment.',
|
|
178
|
+
why: 'TODOs in code that no one tracks are silent debt.',
|
|
179
|
+
triggers: [
|
|
180
|
+
['Skipped test without explanation', 'Add `// REASON: <why>` immediately above the skip.'],
|
|
181
|
+
['Untracked TODO', 'Reference the TODO from ROADMAP.md by file:line, OR add it to a GitHub issue and link the issue ID in the comment.'],
|
|
182
|
+
],
|
|
183
|
+
example: '// REASON: waiting on upstream fix in libfoo v2.5\\ntest.skip("foo", () => {})',
|
|
184
|
+
standard: 'Pragmatic Programmer (debt visibility)',
|
|
185
|
+
},
|
|
186
|
+
specKit: {
|
|
187
|
+
title: 'Spec-Kit — spec.md/plan.md/tasks.md have required sections',
|
|
188
|
+
what: 'For projects using Spec Kit, validates each spec/*.md against the spec-kit-template required sections.',
|
|
189
|
+
why: 'Spec Kit\'s value comes from consistent shape across specs.',
|
|
190
|
+
triggers: [
|
|
191
|
+
['Missing mandatory section', 'Add the section listed in the warning. Reference the template at .specify/templates/'],
|
|
192
|
+
],
|
|
193
|
+
example: 'plan.md has Summary, Technical Context, Constitution Check, Project Structure',
|
|
194
|
+
standard: 'GitHub Spec Kit',
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Match a warning text fragment against the explainer table. Returns the
|
|
200
|
+
* matching entry's key + the trigger entry that best matches, or null when
|
|
201
|
+
* no match is confident enough.
|
|
202
|
+
*/
|
|
203
|
+
function matchWarning(query) {
|
|
204
|
+
const q = query.toLowerCase();
|
|
205
|
+
|
|
206
|
+
// Exact validator-key lookup (e.g. `docguard explain freshness`)
|
|
207
|
+
if (EXPLAINERS[query]) return { key: query, trigger: null };
|
|
208
|
+
// Also try kebab-case (e.g. `cross-reference` → `crossReference`)
|
|
209
|
+
const camelized = query.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
210
|
+
if (EXPLAINERS[camelized]) return { key: camelized, trigger: null };
|
|
211
|
+
|
|
212
|
+
// Search trigger phrases
|
|
213
|
+
let best = null;
|
|
214
|
+
let bestScore = 0;
|
|
215
|
+
for (const [key, e] of Object.entries(EXPLAINERS)) {
|
|
216
|
+
for (const [phrase, _hint] of e.triggers) {
|
|
217
|
+
if (q.includes(phrase.toLowerCase())) {
|
|
218
|
+
const score = phrase.length; // prefer the more-specific phrase
|
|
219
|
+
if (score > bestScore) {
|
|
220
|
+
best = { key, trigger: [phrase, _hint] };
|
|
221
|
+
bestScore = score;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return best;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export function runExplain(projectDir, _config, flags) {
|
|
230
|
+
const query = (flags.args || []).join(' ').trim();
|
|
231
|
+
const isJson = flags.format === 'json';
|
|
232
|
+
|
|
233
|
+
if (!query) {
|
|
234
|
+
if (isJson) {
|
|
235
|
+
console.log(JSON.stringify({ validators: Object.keys(EXPLAINERS) }, null, 2));
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
console.log(`${c.bold}🧭 docguard explain${c.reset} ${c.dim}— usage:${c.reset}`);
|
|
239
|
+
console.log(` ${c.cyan}docguard explain <validator-key>${c.reset} e.g. docguard explain freshness`);
|
|
240
|
+
console.log(` ${c.cyan}docguard explain "<warning text>"${c.reset} e.g. docguard explain "no service-to-test mappings"`);
|
|
241
|
+
console.log(`\n${c.dim}Known validators:${c.reset}`);
|
|
242
|
+
for (const [k, e] of Object.entries(EXPLAINERS)) {
|
|
243
|
+
console.log(` ${c.cyan}${k.padEnd(22)}${c.reset} ${c.dim}${e.title}${c.reset}`);
|
|
244
|
+
}
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const match = matchWarning(query);
|
|
249
|
+
if (!match) {
|
|
250
|
+
if (isJson) {
|
|
251
|
+
console.log(JSON.stringify({ query, match: null }, null, 2));
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
console.log(`${c.yellow}No matching validator or warning found for: "${query}"${c.reset}`);
|
|
255
|
+
console.log(`${c.dim}Try: ${c.cyan}docguard explain${c.dim} (no args) to list all validators.${c.reset}`);
|
|
256
|
+
process.exit(1);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const e = EXPLAINERS[match.key];
|
|
260
|
+
if (isJson) {
|
|
261
|
+
console.log(JSON.stringify({ query, match: { key: match.key, ...e, matchedTrigger: match.trigger } }, null, 2));
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
console.log(`${c.bold}🧭 ${e.title}${c.reset}`);
|
|
266
|
+
console.log(`${c.dim} validator key: ${match.key}${c.reset}\n`);
|
|
267
|
+
|
|
268
|
+
console.log(`${c.bold}What it checks:${c.reset}\n ${e.what}\n`);
|
|
269
|
+
console.log(`${c.bold}Why:${c.reset}\n ${e.why}\n`);
|
|
270
|
+
|
|
271
|
+
if (match.trigger) {
|
|
272
|
+
console.log(`${c.bold}Your warning ("${query}") matches:${c.reset}`);
|
|
273
|
+
console.log(` ${c.yellow}${match.trigger[0]}${c.reset}`);
|
|
274
|
+
console.log(` ${match.trigger[1]}\n`);
|
|
275
|
+
} else {
|
|
276
|
+
console.log(`${c.bold}Common warnings:${c.reset}`);
|
|
277
|
+
for (const [phrase, hint] of e.triggers) {
|
|
278
|
+
console.log(` ${c.yellow}${phrase}${c.reset}`);
|
|
279
|
+
console.log(` ${c.dim}${hint}${c.reset}`);
|
|
280
|
+
}
|
|
281
|
+
console.log('');
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
console.log(`${c.bold}Passing example:${c.reset}\n ${c.dim}${e.example}${c.reset}\n`);
|
|
285
|
+
console.log(`${c.bold}Standard:${c.reset} ${c.dim}${e.standard}${c.reset}`);
|
|
286
|
+
}
|
package/cli/commands/hooks.mjs
CHANGED
|
@@ -4,6 +4,56 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { existsSync, writeFileSync, mkdirSync, chmodSync, readFileSync, unlinkSync } from 'node:fs';
|
|
7
|
+
|
|
8
|
+
// v0.16-P3: managed-block markers. Letting users extend the hook with their
|
|
9
|
+
// own commands (data-file guards, lint checks, etc.) without us clobbering
|
|
10
|
+
// them on re-install. Format:
|
|
11
|
+
//
|
|
12
|
+
// #!/bin/sh
|
|
13
|
+
// # ... user's prelude ...
|
|
14
|
+
//
|
|
15
|
+
// # BEGIN DOCGUARD MANAGED — do not edit between these markers
|
|
16
|
+
// ... DocGuard's content ...
|
|
17
|
+
// # END DOCGUARD MANAGED
|
|
18
|
+
//
|
|
19
|
+
// # ... user's postlude ...
|
|
20
|
+
//
|
|
21
|
+
// On re-install, we splice ONLY the content between the markers, preserving
|
|
22
|
+
// everything else verbatim. Without markers (legacy hooks or third-party
|
|
23
|
+
// pre-existing hooks), behavior falls back to the existing --force flow.
|
|
24
|
+
const BEGIN_MARKER = '# BEGIN DOCGUARD MANAGED — do not edit between these markers';
|
|
25
|
+
const END_MARKER = '# END DOCGUARD MANAGED';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Wrap a hook body in BEGIN/END markers so future re-installs can splice
|
|
29
|
+
* just the managed portion. The shebang stays at the top, outside the block.
|
|
30
|
+
*/
|
|
31
|
+
function wrapManaged(body) {
|
|
32
|
+
// Pull shebang off the front if present so it stays at the top.
|
|
33
|
+
const lines = body.split('\n');
|
|
34
|
+
let shebang = '';
|
|
35
|
+
if (lines[0] && lines[0].startsWith('#!')) {
|
|
36
|
+
shebang = lines.shift() + '\n';
|
|
37
|
+
}
|
|
38
|
+
return `${shebang}${BEGIN_MARKER}\n${lines.join('\n').replace(/\n+$/, '')}\n${END_MARKER}\n`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Splice DocGuard's managed content into an existing hook file that has
|
|
43
|
+
* the BEGIN/END markers. Returns the new file content (string) or null
|
|
44
|
+
* when the markers aren't found (caller falls back to legacy behavior).
|
|
45
|
+
*/
|
|
46
|
+
function spliceManagedBlock(existing, newBody) {
|
|
47
|
+
const startIdx = existing.indexOf(BEGIN_MARKER);
|
|
48
|
+
const endIdx = existing.indexOf(END_MARKER);
|
|
49
|
+
if (startIdx === -1 || endIdx === -1 || endIdx < startIdx) return null;
|
|
50
|
+
const before = existing.slice(0, startIdx);
|
|
51
|
+
const after = existing.slice(endIdx + END_MARKER.length);
|
|
52
|
+
// newBody has its own shebang — strip it since we're splicing into the
|
|
53
|
+
// middle of an existing file (which already has one).
|
|
54
|
+
const bodyNoShebang = newBody.replace(/^#!.*\n/, '');
|
|
55
|
+
return `${before}${BEGIN_MARKER}\n${bodyNoShebang.replace(/\n+$/, '')}\n${END_MARKER}${after}`;
|
|
56
|
+
}
|
|
7
57
|
import { resolve } from 'node:path';
|
|
8
58
|
import { c } from '../shared.mjs';
|
|
9
59
|
|
|
@@ -228,26 +278,45 @@ export function runHooks(projectDir, config, flags) {
|
|
|
228
278
|
|
|
229
279
|
for (const name of hookTypes) {
|
|
230
280
|
const hookPath = resolve(hooksDir, name);
|
|
281
|
+
const useAutofix = name === 'pre-commit' && flags.autoFix;
|
|
282
|
+
const newContent = wrapManaged(useAutofix ? PRE_COMMIT_AUTOFIX : HOOKS[name].content);
|
|
283
|
+
const desc = useAutofix ? 'Apply mechanical fixes (fix --write) then guard' : HOOKS[name].description;
|
|
231
284
|
|
|
232
|
-
if (existsSync(hookPath)
|
|
233
|
-
// Check if it's already a DocGuard hook
|
|
285
|
+
if (existsSync(hookPath)) {
|
|
234
286
|
const existing = readFileSync(hookPath, 'utf-8');
|
|
235
|
-
|
|
236
|
-
|
|
287
|
+
|
|
288
|
+
// v0.16-P3: managed-block path — splice just the DocGuard portion,
|
|
289
|
+
// preserve everything outside it. The user can extend the hook with
|
|
290
|
+
// their own commands above/below the markers without losing them on
|
|
291
|
+
// re-install.
|
|
292
|
+
const spliced = spliceManagedBlock(existing, newContent);
|
|
293
|
+
if (spliced !== null) {
|
|
294
|
+
writeFileSync(hookPath, spliced, 'utf-8');
|
|
295
|
+
chmodSync(hookPath, 0o755);
|
|
296
|
+
console.log(` ${c.green}↻ ${name}${c.reset}: updated DocGuard managed block (preserved user content around it)`);
|
|
297
|
+
installed++;
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// No markers found. Two sub-cases:
|
|
302
|
+
// (a) Legacy DocGuard hook (pre-v0.16, no markers, contains "DocGuard")
|
|
303
|
+
// → upgrade in place when --force is set
|
|
304
|
+
// (b) Third-party hook the user wrote themselves
|
|
305
|
+
// → refuse without --force; warn about clobber risk
|
|
306
|
+
if (!flags.force) {
|
|
307
|
+
if (existing.includes('DocGuard')) {
|
|
308
|
+
console.log(` ${c.yellow}⚠️ ${name}: legacy DocGuard hook (pre-v0.16) without managed markers. Re-run with --force to upgrade it to the managed-block format.${c.reset}`);
|
|
309
|
+
} else {
|
|
310
|
+
console.log(` ${c.yellow}⚠️ ${name}: an existing hook is present and has no DocGuard markers. Re-run with --force to overwrite (your hook will be replaced — back it up first!).${c.reset}`);
|
|
311
|
+
}
|
|
237
312
|
skipped++;
|
|
238
313
|
continue;
|
|
239
314
|
}
|
|
240
|
-
|
|
241
|
-
skipped++;
|
|
242
|
-
continue;
|
|
315
|
+
// --force path: write fresh managed-block version
|
|
243
316
|
}
|
|
244
317
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const content = useAutofix ? PRE_COMMIT_AUTOFIX : HOOKS[name].content;
|
|
248
|
-
writeFileSync(hookPath, content, 'utf-8');
|
|
249
|
-
chmodSync(hookPath, 0o755); // Make executable
|
|
250
|
-
const desc = useAutofix ? 'Apply mechanical fixes (fix --write) then guard' : HOOKS[name].description;
|
|
318
|
+
writeFileSync(hookPath, newContent, 'utf-8');
|
|
319
|
+
chmodSync(hookPath, 0o755);
|
|
251
320
|
console.log(` ${c.green}✅ ${name}${c.reset}: ${desc}`);
|
|
252
321
|
installed++;
|
|
253
322
|
}
|
package/cli/commands/init.mjs
CHANGED
|
@@ -253,10 +253,14 @@ poetry.lock
|
|
|
253
253
|
|
|
254
254
|
// ── Spec-Kit Integration (Extension-First) ────────────────────────────
|
|
255
255
|
// Delegate LLM/IDE detection and spec-kit skill install to `specify init`
|
|
256
|
+
// v0.16-P8: --no-spec-kit lets users skip the .specify/.agent/commands
|
|
257
|
+
// scaffolding (minimalist library projects, CI containers, etc.).
|
|
256
258
|
const specKitAvailable = isSpecKitAvailable();
|
|
257
259
|
const specKitInitialized = isSpecKitInitialized(projectDir);
|
|
258
260
|
|
|
259
|
-
if (
|
|
261
|
+
if (flags.noSpecKit) {
|
|
262
|
+
console.log(`\n ${c.dim}⏭️ Spec Kit init skipped (--no-spec-kit).${c.reset}`);
|
|
263
|
+
} else if (specKitAvailable && !specKitInitialized) {
|
|
260
264
|
console.log(`\n ${c.bold}🌱 Spec Kit Integration${c.reset}`);
|
|
261
265
|
|
|
262
266
|
// Detect which AI agent is in use (matches spec-kit's --ai flag)
|
package/cli/commands/score.mjs
CHANGED
|
@@ -21,8 +21,15 @@ const WEIGHTS = {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export function runScore(projectDir, config, flags) {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
// v0.16-P1: suppress banner in JSON mode so stdout stays parseable.
|
|
25
|
+
// Was already fixed for guard/diagnose in v0.12; score/trace/diff missed
|
|
26
|
+
// the pattern. Reported on a Python project where `score --format json`
|
|
27
|
+
// mixed ANSI escapes with JSON.
|
|
28
|
+
const isJson = flags.format === 'json';
|
|
29
|
+
if (!isJson) {
|
|
30
|
+
console.log(`${c.bold}📊 DocGuard Score — ${config.projectName}${c.reset}`);
|
|
31
|
+
console.log(`${c.dim} Directory: ${projectDir}${c.reset}\n`);
|
|
32
|
+
}
|
|
26
33
|
|
|
27
34
|
const { scores, totalScore, grade, details } = calcAllScores(projectDir, config);
|
|
28
35
|
|
package/cli/commands/trace.mjs
CHANGED
|
@@ -21,65 +21,107 @@ const CODE_EXTENSIONS = new Set([
|
|
|
21
21
|
'.py', '.java', '.go', '.rs', '.rb', '.php', '.cs',
|
|
22
22
|
]);
|
|
23
23
|
|
|
24
|
+
// v0.16-P2: language-aware patterns. The original JS/TS-only sets created
|
|
25
|
+
// false-negative warnings on Python/Rust/Go/Java projects (reported by the
|
|
26
|
+
// quick-recon-tool Python user: TEST-SPEC.md was flagged unlinked even
|
|
27
|
+
// though Python tests existed because `.test.mjs` didn't match `test_*.py`).
|
|
28
|
+
// Each `glob` is now a single regex that ALSO matches the equivalent
|
|
29
|
+
// patterns in other ecosystems we care about.
|
|
24
30
|
const TEST_PATTERNS = [
|
|
25
|
-
|
|
26
|
-
/\.spec\.[jt]sx?$/,
|
|
27
|
-
|
|
31
|
+
// JS/TS
|
|
32
|
+
/\.test\.[jt]sx?$/, /\.spec\.[jt]sx?$/, /\.test\.(mjs|cjs)$/,
|
|
33
|
+
// Python — pytest conventions
|
|
34
|
+
/(^|\/)test_[^/]+\.py$/, /[^/]+_test\.py$/, /(^|\/)tests?\/[^/]+\.py$/,
|
|
35
|
+
// Go
|
|
28
36
|
/_test\.go$/,
|
|
29
|
-
/
|
|
37
|
+
// Java/Kotlin — JUnit/TestNG conventions
|
|
38
|
+
/(?:Test|Tests|Spec|IT)\.(?:java|kt)$/,
|
|
39
|
+
// Rust — tests live in tests/ or as #[cfg(test)] modules; pattern below covers integration tests
|
|
40
|
+
/(^|\/)tests\/[^/]+\.rs$/,
|
|
41
|
+
// Ruby/RSpec
|
|
42
|
+
/_spec\.rb$/, /_test\.rb$/,
|
|
43
|
+
// PHP/PHPUnit
|
|
44
|
+
/Test\.php$/, /(^|\/)tests?\/[^/]+\.php$/,
|
|
30
45
|
];
|
|
31
46
|
|
|
32
47
|
/**
|
|
33
48
|
* Mapping of canonical documents to the code/config artifacts they trace to.
|
|
34
49
|
* Each entry defines what source patterns prove coverage of that canonical doc.
|
|
50
|
+
*
|
|
51
|
+
* v0.16-P2: every glob is now multi-language. JS/TS patterns are preserved
|
|
52
|
+
* (the most common case); Python/Rust/Go/Java/Ruby/PHP equivalents are
|
|
53
|
+
* appended so non-JS projects don't false-negative.
|
|
35
54
|
*/
|
|
36
55
|
const TRACE_MAP = {
|
|
37
56
|
'ARCHITECTURE.md': {
|
|
38
57
|
standard: 'arc42 / C4 Model',
|
|
39
58
|
sourcePatterns: [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
{ label: '
|
|
59
|
+
// Entry points: JS (index/main/app/server.[jt]sx?), Python (__main__.py, main.py, app.py, cli.py),
|
|
60
|
+
// Go (main.go, cmd/), Rust (main.rs, lib.rs), Java (Application.java, Main.java)
|
|
61
|
+
{ label: 'Entry points', glob: /(?:^|\/)(?:index|main|app|server|cli|__main__|Application|Main)\.(?:[jt]sx?|mjs|cjs|py|go|rs|java|kt|rb)$|(?:^|\/)cmd\// },
|
|
62
|
+
// Config files: JS (package.json/tsconfig/next.config/vite.config), Python (pyproject.toml/setup.py/setup.cfg),
|
|
63
|
+
// Rust (Cargo.toml), Go (go.mod), Java/Kotlin (pom.xml/build.gradle), Ruby (Gemfile), PHP (composer.json)
|
|
64
|
+
{ label: 'Config files', glob: /(?:^|\/)(?:package\.json|tsconfig|next\.config|vite\.config|pyproject\.toml|setup\.(?:py|cfg)|Cargo\.toml|go\.mod|pom\.xml|build\.gradle|Gemfile|composer\.json)/ },
|
|
65
|
+
// Route handlers + module dirs
|
|
66
|
+
{ label: 'Route handlers / modules', glob: /(?:^|\/)(?:routes?|api|pages|app|controllers?|handlers?|views?|services?)\// },
|
|
43
67
|
],
|
|
44
68
|
},
|
|
45
69
|
'DATA-MODEL.md': {
|
|
46
70
|
standard: 'C4 Component / ER (Chen)',
|
|
47
71
|
sourcePatterns: [
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
{ label: '
|
|
72
|
+
// Schema/model files: JS (schema/model/entity/migration/prisma), Python (models.py/schema.py/Pydantic/SQLAlchemy),
|
|
73
|
+
// Go (models/), Rust (struct definitions in models/), Java (entities/)
|
|
74
|
+
{ label: 'Schema definitions', glob: /(?:schema|model|entity|migration|prisma)/i },
|
|
75
|
+
// Type definitions: JS types.ts, Python types.py, Rust types.rs
|
|
76
|
+
{ label: 'Type definitions', glob: /(?:^|\/)types?\.(?:[jt]sx?|mjs|py|rs|go|java|kt)$/ },
|
|
77
|
+
// ORM/database libs (any language)
|
|
78
|
+
{ label: 'Database configs', glob: /(?:drizzle|knex|sequelize|typeorm|sqlalchemy|alembic|django|diesel|sqlx|gorm|hibernate|active.?record)/i },
|
|
51
79
|
],
|
|
52
80
|
},
|
|
53
81
|
'TEST-SPEC.md': {
|
|
54
82
|
standard: 'ISO/IEC/IEEE 29119-3',
|
|
55
83
|
sourcePatterns: [
|
|
56
|
-
|
|
57
|
-
{ label: 'Test
|
|
58
|
-
|
|
84
|
+
// Test files in any ecosystem (mirrors TEST_PATTERNS above)
|
|
85
|
+
{ label: 'Test files', glob: /\.(?:test|spec)\.(?:mjs|cjs|[jt]sx?)$|(?:^|\/)test_[^/]+\.py$|[^/]+_test\.py$|_test\.go$|(?:Test|Spec|IT)\.(?:java|kt)$|(?:^|\/)tests?\/[^/]+\.(?:rs|py|rb|php)$|_(?:spec|test)\.rb$|Test\.php$/ },
|
|
86
|
+
// Test runner configs: JS (jest/vitest/playwright/cypress), Python (pytest.ini/tox.ini), Rust (Cargo.toml has [[test]]),
|
|
87
|
+
// Java (pom.xml/build.gradle), Go (no config file typically)
|
|
88
|
+
{ label: 'Test config', glob: /(?:jest|vitest|playwright|cypress|pytest|tox|phpunit)\.config|(?:^|\/)pytest\.ini$|(?:^|\/)tox\.ini$|(?:^|\/)phpunit\.xml$/ },
|
|
89
|
+
{ label: 'E2E / integration tests', glob: /(?:^|\/)(?:e2e|integration|tests?\/integration)\// },
|
|
59
90
|
],
|
|
60
91
|
},
|
|
61
92
|
'SECURITY.md': {
|
|
62
93
|
standard: 'OWASP ASVS v4.0',
|
|
63
94
|
sourcePatterns: [
|
|
64
|
-
|
|
65
|
-
{ label: '
|
|
66
|
-
|
|
95
|
+
// Auth modules — semantic, language-agnostic
|
|
96
|
+
{ label: 'Auth modules', glob: /(?:auth|login|session|jwt|oauth|middleware|guard|csrf|cors|permissions?|policy)/i },
|
|
97
|
+
// Secret configs — .env family + secrets.* / keyring patterns
|
|
98
|
+
{ label: 'Secret configs', glob: /\.env(?:\.|$)|(?:^|\/)secrets?\.(?:py|js|ts|yaml|yml|json)$|keyring/i },
|
|
99
|
+
// Gitignore + ignore files
|
|
100
|
+
{ label: 'Ignore files', glob: /^\.(?:git|docker|npm)ignore$/ },
|
|
67
101
|
],
|
|
68
102
|
},
|
|
69
103
|
'ENVIRONMENT.md': {
|
|
70
104
|
standard: '12-Factor App',
|
|
71
105
|
sourcePatterns: [
|
|
72
|
-
|
|
73
|
-
{ label: '
|
|
74
|
-
|
|
106
|
+
// .env family across all ecosystems
|
|
107
|
+
{ label: 'Env files', glob: /\.env(?:\.|$)|(?:^|\/)\.envrc$/ },
|
|
108
|
+
// Containerization
|
|
109
|
+
{ label: 'Container configs', glob: /(?:^|\/)(?:Dockerfile|docker-compose|\.dockerignore|Containerfile)/ },
|
|
110
|
+
// Python venv / requirements / lock files
|
|
111
|
+
{ label: 'Python env', glob: /(?:^|\/)(?:requirements[^/]*\.txt|Pipfile|poetry\.lock|uv\.lock|pyproject\.toml)$/ },
|
|
112
|
+
// CI/CD configs
|
|
113
|
+
{ label: 'CI/CD configs', glob: /(?:^|\/)\.(?:github|gitlab-ci|circleci|drone|gitea)/ },
|
|
75
114
|
],
|
|
76
115
|
},
|
|
77
116
|
'API-REFERENCE.md': {
|
|
78
117
|
standard: 'OpenAPI 3.1',
|
|
79
118
|
sourcePatterns: [
|
|
80
|
-
|
|
81
|
-
{ label: '
|
|
82
|
-
|
|
119
|
+
// Route handlers + Python views/urls + Java/Spring controllers
|
|
120
|
+
{ label: 'Route handlers', glob: /(?:^|\/)(?:routes?|controllers?|handlers?|views?|urls?\.py)/ },
|
|
121
|
+
// OpenAPI / API specs
|
|
122
|
+
{ label: 'API spec', glob: /(?:openapi|swagger|asyncapi)\.(?:json|ya?ml)/ },
|
|
123
|
+
// Middleware / decorators
|
|
124
|
+
{ label: 'API middleware', glob: /(?:^|\/)middleware\/|decorators?\.py$/ },
|
|
83
125
|
],
|
|
84
126
|
},
|
|
85
127
|
};
|
|
@@ -190,9 +232,14 @@ export function runTrace(projectDir, config, flags) {
|
|
|
190
232
|
return runTraceReverse(projectDir, config, flags);
|
|
191
233
|
}
|
|
192
234
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
235
|
+
// v0.16-P1: same headless-mode pattern as guard/score. Reported by Python
|
|
236
|
+
// user — trace --format json was leaking ANSI escapes before the body.
|
|
237
|
+
const isJson = flags.format === 'json';
|
|
238
|
+
if (!isJson) {
|
|
239
|
+
console.log(`${c.bold}🔗 DocGuard Trace — ${config.projectName}${c.reset}`);
|
|
240
|
+
console.log(`${c.dim} Directory: ${projectDir}${c.reset}`);
|
|
241
|
+
console.log(`${c.dim} Generating requirements traceability matrix...${c.reset}\n`);
|
|
242
|
+
}
|
|
196
243
|
|
|
197
244
|
// ── 1. Build set of required doc basenames from config ──
|
|
198
245
|
const requiredDocs = new Set(
|
package/cli/docguard.mjs
CHANGED
|
@@ -42,6 +42,7 @@ import { runLlms } from './commands/llms.mjs';
|
|
|
42
42
|
import { runSetup } from './commands/setup.mjs';
|
|
43
43
|
import { runUpgrade } from './commands/upgrade.mjs';
|
|
44
44
|
import { runImpact } from './commands/impact.mjs';
|
|
45
|
+
import { runExplain } from './commands/explain.mjs';
|
|
45
46
|
import { ensureSkills } from './ensure-skills.mjs';
|
|
46
47
|
|
|
47
48
|
// ── Shared constants (imported to break circular dependencies) ──────────
|
|
@@ -395,6 +396,16 @@ async function main() {
|
|
|
395
396
|
// avoid collision with `docguard init --profile <name>`. `--show-timings`
|
|
396
397
|
// is the long form for users who prefer explicit verbs.
|
|
397
398
|
flags.timings = true;
|
|
399
|
+
} else if (args[i] === '--quiet' || args[i] === '-q') {
|
|
400
|
+
// v0.16-P5: suppress the banner + ensureSkills decorative line.
|
|
401
|
+
// Useful inside git hooks (every commit prints the banner otherwise)
|
|
402
|
+
// and any CI/script that pipes docguard's output.
|
|
403
|
+
flags.quiet = true;
|
|
404
|
+
} else if (args[i] === '--no-spec-kit') {
|
|
405
|
+
// v0.16-P8: opt-out of automatic Spec Kit init during `docguard init`.
|
|
406
|
+
// Default stays on (discoverability), but lets minimalist library
|
|
407
|
+
// projects skip the .specify/.agent/commands scaffolding.
|
|
408
|
+
flags.noSpecKit = true;
|
|
398
409
|
} else if (!args[i].startsWith('--') && i > 0) {
|
|
399
410
|
// Positional args go into flags.args for commands that take them (e.g.
|
|
400
411
|
// `docguard trace --reverse <path>`). Skip the command itself (i === 0).
|
|
@@ -442,10 +453,12 @@ async function main() {
|
|
|
442
453
|
// ensureSkills' install message would corrupt the output for any
|
|
443
454
|
// programmatic consumer (CI, dashboards, the Score-on-PR Action recipe).
|
|
444
455
|
// Headless flags (`--write`, `--check-only`, `--auto`) also suppress chrome.
|
|
456
|
+
// v0.16-P5: --quiet (-q) joins the headless club for users who want
|
|
457
|
+
// banner-free output without committing to a specific machine format.
|
|
445
458
|
const jsonMode = flags.format === 'json';
|
|
446
|
-
const headless = jsonMode || flags.write || flags.checkOnly || flags.changedOnly;
|
|
459
|
+
const headless = jsonMode || flags.write || flags.checkOnly || flags.changedOnly || flags.quiet;
|
|
447
460
|
|
|
448
|
-
if (!
|
|
461
|
+
if (!headless) printBanner();
|
|
449
462
|
|
|
450
463
|
const config = loadConfig(projectDir);
|
|
451
464
|
|
|
@@ -527,6 +540,10 @@ async function main() {
|
|
|
527
540
|
case 'impact':
|
|
528
541
|
runImpact(projectDir, config, flags);
|
|
529
542
|
break;
|
|
543
|
+
case 'explain':
|
|
544
|
+
case 'help-warning':
|
|
545
|
+
runExplain(projectDir, config, flags);
|
|
546
|
+
break;
|
|
530
547
|
default:
|
|
531
548
|
console.error(`${c.red}Unknown command: ${command}${c.reset}`);
|
|
532
549
|
console.log(`Run ${c.cyan}docguard --help${c.reset} for usage.`);
|
|
@@ -45,9 +45,21 @@ export function validateEnvironment(projectDir, config) {
|
|
|
45
45
|
// tokens like `VITE_` (the convention prefix) from being treated as a real
|
|
46
46
|
// variable name.
|
|
47
47
|
const varRe = /`([A-Z][A-Z0-9_]*[A-Z0-9])`/g;
|
|
48
|
+
// v0.16-P4: skip backticked SYSTEM env vars (PATH, HOME, USER, etc.).
|
|
49
|
+
// They appear in ENVIRONMENT.md prose ("the venv `PATH`") but aren't
|
|
50
|
+
// user-set application vars. Mirrors the same skip in diff.mjs.
|
|
51
|
+
const SYSTEM = new Set([
|
|
52
|
+
'PATH','HOME','USER','USERNAME','SHELL','PWD','OLDPWD','TMPDIR','TEMP','TMP',
|
|
53
|
+
'LANG','LC_ALL','LC_CTYPE','LC_MESSAGES','TZ',
|
|
54
|
+
'EDITOR','VISUAL','PAGER','TERM','COLORTERM',
|
|
55
|
+
'DISPLAY','SSH_AUTH_SOCK','SSH_CONNECTION','SSH_TTY',
|
|
56
|
+
'XDG_CONFIG_HOME','XDG_DATA_HOME','XDG_CACHE_HOME','XDG_RUNTIME_DIR',
|
|
57
|
+
'CI','GITHUB_TOKEN','GITHUB_ACTIONS','GITHUB_REF','GITHUB_SHA','NODE_ENV',
|
|
58
|
+
]);
|
|
48
59
|
let m;
|
|
49
60
|
while ((m = varRe.exec(content)) !== null) {
|
|
50
61
|
if (m[1].length < 3) continue; // 'OK' / 'ID' etc. are too short to be env var refs
|
|
62
|
+
if (SYSTEM.has(m[1])) continue; // v0.16-P4: prose mentions of system vars are not docs
|
|
51
63
|
documented.add(m[1]);
|
|
52
64
|
}
|
|
53
65
|
for (const envFile of ['.env.example', '.env.template']) {
|
|
@@ -89,14 +89,36 @@ export function validateDocSections(projectDir, config) {
|
|
|
89
89
|
// Match an actual heading at line start (any level), not a substring that
|
|
90
90
|
// could appear in a table-of-contents link or a code block.
|
|
91
91
|
const headingText = section.replace(/^#+\s*/, '');
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
const escapedHeading = headingText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
93
|
+
const headingRe = new RegExp('^#{2,6}\\s+' + escapedHeading + '\\b', 'm');
|
|
94
|
+
// v0.16-P7: N/A marker. A project can declare a required section as
|
|
95
|
+
// "not applicable" via an HTML comment instead of writing boilerplate
|
|
96
|
+
// "Absent by design" prose. Format:
|
|
97
|
+
// <!-- docguard:section authentication n/a — JWT not used; we're a CLI -->
|
|
98
|
+
// The section name in the marker is matched case-insensitively against
|
|
99
|
+
// the heading slug (lowercase, hyphenated). Requires a reason after `—`
|
|
100
|
+
// or `--` so it's not a silent opt-out.
|
|
101
|
+
const slug = headingText.toLowerCase()
|
|
102
|
+
.replace(/[^a-z0-9\s-]/g, '')
|
|
103
|
+
.replace(/\s+/g, '-');
|
|
104
|
+
// Reason must start with an actual letter or digit (not `>` from `-->`
|
|
105
|
+
// and not whitespace). This makes sure `<!-- ... n/a -->` (no reason)
|
|
106
|
+
// is rejected, while `<!-- ... n/a — CLI tool -->` is accepted.
|
|
107
|
+
const naRe = new RegExp(
|
|
108
|
+
'<!--\\s*docguard:section\\s+' + slug.replace(/-/g, '[-_]') + '\\s+n/a\\s*[—-]+\\s*[A-Za-z0-9]',
|
|
109
|
+
'i'
|
|
95
110
|
);
|
|
96
111
|
if (headingRe.test(content)) {
|
|
97
112
|
results.passed++;
|
|
113
|
+
} else if (naRe.test(content)) {
|
|
114
|
+
// v0.16-P7: explicit N/A — counts as passed (the project has owned
|
|
115
|
+
// the absence) and doesn't pollute the warnings list.
|
|
116
|
+
results.passed++;
|
|
98
117
|
} else {
|
|
99
|
-
results.warnings.push(
|
|
118
|
+
results.warnings.push(
|
|
119
|
+
`${file}: missing section "${section}". ` +
|
|
120
|
+
`If genuinely not applicable, add: <!-- docguard:section ${slug} n/a — your reason -->`
|
|
121
|
+
);
|
|
100
122
|
}
|
|
101
123
|
}
|
|
102
124
|
}
|
|
@@ -3,7 +3,7 @@ schema_version: "1.0"
|
|
|
3
3
|
extension:
|
|
4
4
|
id: "docguard"
|
|
5
5
|
name: "DocGuard — CDD Enforcement"
|
|
6
|
-
version: "0.
|
|
6
|
+
version: "0.16.0"
|
|
7
7
|
description: "Canonical-Driven Development enforcement as a true spec-kit extension. LLM-first design with 19 automated validators, 4 AI behavior skills, spec-kit skill chaining, and workflow hooks. Zero NPM runtime dependencies."
|
|
8
8
|
author: "Ricardo Accioly"
|
|
9
9
|
repository: "https://github.com/raccioly/docguard"
|
|
@@ -6,10 +6,10 @@ description: AI-driven documentation repair with structured research workflow, t
|
|
|
6
6
|
compatibility: Requires DocGuard CLI installed (npm i -g docguard-cli or npx docguard-cli)
|
|
7
7
|
metadata:
|
|
8
8
|
author: docguard
|
|
9
|
-
version: 0.
|
|
9
|
+
version: 0.16.0
|
|
10
10
|
source: extensions/spec-kit-docguard/skills/docguard-fix
|
|
11
11
|
---
|
|
12
|
-
<!-- docguard:version: 0.
|
|
12
|
+
<!-- docguard:version: 0.16.0 -->
|
|
13
13
|
|
|
14
14
|
# DocGuard Fix Skill
|
|
15
15
|
|
|
@@ -7,10 +7,10 @@ description: Run DocGuard guard validation against Canonical-Driven Development
|
|
|
7
7
|
compatibility: Requires DocGuard CLI installed (npm i -g docguard-cli or npx docguard-cli)
|
|
8
8
|
metadata:
|
|
9
9
|
author: docguard
|
|
10
|
-
version: 0.
|
|
10
|
+
version: 0.16.0
|
|
11
11
|
source: extensions/spec-kit-docguard/skills/docguard-guard
|
|
12
12
|
---
|
|
13
|
-
<!-- docguard:version: 0.
|
|
13
|
+
<!-- docguard:version: 0.16.0 -->
|
|
14
14
|
|
|
15
15
|
# DocGuard Guard Skill
|
|
16
16
|
|
|
@@ -6,10 +6,10 @@ description: Cross-document consistency analysis and quality assessment. Perform
|
|
|
6
6
|
compatibility: Requires DocGuard CLI installed (npm i -g docguard-cli or npx docguard-cli)
|
|
7
7
|
metadata:
|
|
8
8
|
author: docguard
|
|
9
|
-
version: 0.
|
|
9
|
+
version: 0.16.0
|
|
10
10
|
source: extensions/spec-kit-docguard/skills/docguard-review
|
|
11
11
|
---
|
|
12
|
-
<!-- docguard:version: 0.
|
|
12
|
+
<!-- docguard:version: 0.16.0 -->
|
|
13
13
|
|
|
14
14
|
# DocGuard Review Skill
|
|
15
15
|
|
|
@@ -6,10 +6,10 @@ description: CDD maturity assessment with category-aware improvement roadmap. Ru
|
|
|
6
6
|
compatibility: Requires DocGuard CLI installed (npm i -g docguard-cli or npx docguard-cli)
|
|
7
7
|
metadata:
|
|
8
8
|
author: docguard
|
|
9
|
-
version: 0.
|
|
9
|
+
version: 0.16.0
|
|
10
10
|
source: extensions/spec-kit-docguard/skills/docguard-score
|
|
11
11
|
---
|
|
12
|
-
<!-- docguard:version: 0.
|
|
12
|
+
<!-- docguard:version: 0.16.0 -->
|
|
13
13
|
|
|
14
14
|
# DocGuard Score Skill
|
|
15
15
|
|
|
@@ -4,7 +4,7 @@ description: Keep canonical documentation ALWAYS UP TO DATE. Refreshes code-trut
|
|
|
4
4
|
compatibility: Requires DocGuard CLI installed (npm i -g docguard-cli or npx docguard-cli)
|
|
5
5
|
metadata:
|
|
6
6
|
author: docguard
|
|
7
|
-
version: 0.
|
|
7
|
+
version: 0.16.0
|
|
8
8
|
source: extensions/spec-kit-docguard/skills/docguard-sync
|
|
9
9
|
---
|
|
10
10
|
|
package/package.json
CHANGED