docguard-cli 0.9.11 → 0.11.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/PHILOSOPHY.md +59 -106
- package/README.md +26 -3
- package/cli/commands/diagnose.mjs +171 -58
- package/cli/commands/diff.mjs +110 -137
- package/cli/commands/fix.mjs +152 -4
- package/cli/commands/generate.mjs +148 -27
- package/cli/commands/guard.mjs +45 -24
- package/cli/commands/hooks.mjs +40 -2
- package/cli/commands/score.mjs +22 -0
- package/cli/commands/sync.mjs +123 -0
- package/cli/docguard.mjs +22 -0
- package/cli/scanners/api-doc.mjs +122 -0
- package/cli/scanners/doc-tools.mjs +1 -1
- package/cli/scanners/frontend.mjs +438 -0
- package/cli/scanners/integrations.mjs +116 -0
- package/cli/scanners/memory-plan.mjs +242 -0
- package/cli/scanners/project-type.mjs +310 -0
- package/cli/scanners/routes.mjs +194 -32
- package/cli/scanners/schemas.mjs +174 -1
- package/cli/shared-source.mjs +247 -0
- package/cli/validators/api-surface.mjs +254 -0
- package/cli/validators/architecture.mjs +4 -3
- package/cli/validators/changelog.mjs +45 -4
- package/cli/validators/doc-quality.mjs +3 -2
- package/cli/validators/docs-coverage.mjs +9 -14
- package/cli/validators/docs-diff.mjs +117 -66
- package/cli/validators/docs-sync.mjs +30 -24
- package/cli/validators/drift.mjs +6 -2
- package/cli/validators/environment.mjs +43 -3
- package/cli/validators/freshness.mjs +4 -3
- package/cli/validators/metadata-sync.mjs +17 -7
- package/cli/validators/metrics-consistency.mjs +9 -4
- package/cli/validators/schema-sync.mjs +19 -10
- package/cli/validators/security.mjs +20 -7
- package/cli/validators/structure.mjs +8 -1
- package/cli/validators/test-spec.mjs +26 -17
- package/cli/validators/todo-tracking.mjs +21 -8
- package/cli/validators/traceability.mjs +61 -36
- package/cli/writers/api-reference.mjs +101 -0
- package/cli/writers/mechanical.mjs +116 -0
- package/cli/writers/sections.mjs +148 -0
- package/commands/docguard.fix.md +19 -3
- package/commands/docguard.guard.md +5 -4
- package/docs/doc-sections.md +37 -0
- package/docs/quickstart.md +1 -1
- package/extensions/spec-kit-docguard/README.md +8 -5
- package/extensions/spec-kit-docguard/commands/fix.md +74 -0
- package/extensions/spec-kit-docguard/commands/generate.md +25 -2
- package/extensions/spec-kit-docguard/commands/guard.md +6 -5
- package/extensions/spec-kit-docguard/commands/sync.md +62 -0
- package/extensions/spec-kit-docguard/skills/docguard-fix/SKILL.md +11 -1
- package/extensions/spec-kit-docguard/skills/docguard-guard/SKILL.md +3 -2
- package/extensions/spec-kit-docguard/skills/docguard-sync/SKILL.md +111 -0
- package/package.json +1 -1
- package/templates/commands/docguard.guard.md +3 -3
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Section-addressable docs — the foundation for surgical, non-destructive doc
|
|
3
|
+
* maintenance.
|
|
4
|
+
*
|
|
5
|
+
* Canonical docs mix two kinds of content:
|
|
6
|
+
* - CODE-DERIVED sections (endpoint tables, entity lists, env-var tables) that
|
|
7
|
+
* DocGuard can regenerate from the codebase, and
|
|
8
|
+
* - HUMAN prose (rationale, "why", design intent) that must NEVER be clobbered.
|
|
9
|
+
*
|
|
10
|
+
* We mark the regenerable regions with HTML comments so the doc stays plain,
|
|
11
|
+
* readable markdown:
|
|
12
|
+
*
|
|
13
|
+
* <!-- docguard:section id=api-endpoints source=code -->
|
|
14
|
+
* | `GET` | `/api/x` | … |
|
|
15
|
+
* <!-- /docguard:section -->
|
|
16
|
+
*
|
|
17
|
+
* DocGuard rewrites ONLY the bytes between a section's open/close markers.
|
|
18
|
+
* Everything outside any marker (the human writing) is preserved exactly.
|
|
19
|
+
*
|
|
20
|
+
* Pure string transforms — idempotent, no disk I/O. Zero NPM dependencies.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const OPEN_RE = /^[ \t]*<!--\s*docguard:section\b([^>]*?)-->[ \t]*$/;
|
|
24
|
+
const CLOSE_RE = /^[ \t]*<!--\s*\/docguard:section\s*-->[ \t]*$/;
|
|
25
|
+
|
|
26
|
+
/** Parse `id=foo source=code` style attributes from an open-marker tail. */
|
|
27
|
+
function parseAttrs(attrStr) {
|
|
28
|
+
const attrs = {};
|
|
29
|
+
const re = /(\w[\w-]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"']+))/g;
|
|
30
|
+
let m;
|
|
31
|
+
while ((m = re.exec(attrStr)) !== null) {
|
|
32
|
+
attrs[m[1]] = m[2] ?? m[3] ?? m[4] ?? '';
|
|
33
|
+
}
|
|
34
|
+
return attrs;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Parse all well-formed sections in a document.
|
|
39
|
+
* A section is a line matching the open marker, then content lines, then a
|
|
40
|
+
* close-marker line. An open with no matching close is ignored (not corrupted).
|
|
41
|
+
* @returns {Array<{ id, source, attrs, openLine, closeLine, body }>}
|
|
42
|
+
*/
|
|
43
|
+
export function parseSections(content) {
|
|
44
|
+
const lines = String(content).split('\n');
|
|
45
|
+
const sections = [];
|
|
46
|
+
let open = null;
|
|
47
|
+
|
|
48
|
+
for (let i = 0; i < lines.length; i++) {
|
|
49
|
+
const line = lines[i];
|
|
50
|
+
if (open === null) {
|
|
51
|
+
const om = line.match(OPEN_RE);
|
|
52
|
+
if (om) {
|
|
53
|
+
const attrs = parseAttrs(om[1] || '');
|
|
54
|
+
open = { attrs, openLine: i };
|
|
55
|
+
}
|
|
56
|
+
} else if (CLOSE_RE.test(line)) {
|
|
57
|
+
sections.push({
|
|
58
|
+
id: open.attrs.id || '',
|
|
59
|
+
source: open.attrs.source || 'code',
|
|
60
|
+
attrs: open.attrs,
|
|
61
|
+
openLine: open.openLine,
|
|
62
|
+
closeLine: i,
|
|
63
|
+
body: lines.slice(open.openLine + 1, i).join('\n'),
|
|
64
|
+
});
|
|
65
|
+
open = null;
|
|
66
|
+
}
|
|
67
|
+
// Note: a second open before a close just extends the search for a close;
|
|
68
|
+
// we keep the FIRST open's start, so malformed nesting can't corrupt content.
|
|
69
|
+
}
|
|
70
|
+
return sections;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Get a single section by id, or null. */
|
|
74
|
+
export function getSection(content, id) {
|
|
75
|
+
return parseSections(content).find(s => s.id === id) || null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** List section ids present in a document. */
|
|
79
|
+
export function listSections(content) {
|
|
80
|
+
return parseSections(content).map(s => s.id);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Render a full marked section block (open marker + body + close marker). */
|
|
84
|
+
export function renderSection(id, body, { source = 'code' } = {}) {
|
|
85
|
+
const inner = String(body).replace(/^\n+/, '').replace(/\n+$/, '');
|
|
86
|
+
return `<!-- docguard:section id=${id} source=${source} -->\n${inner}\n<!-- /docguard:section -->`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Replace ONLY the body of an existing section, preserving its markers and all
|
|
91
|
+
* surrounding content. Idempotent: if the new body matches, returns unchanged.
|
|
92
|
+
* @returns {{ content: string, replaced: boolean }}
|
|
93
|
+
*/
|
|
94
|
+
export function replaceSection(content, id, newBody) {
|
|
95
|
+
const lines = String(content).split('\n');
|
|
96
|
+
const sections = parseSections(content);
|
|
97
|
+
const sec = sections.find(s => s.id === id);
|
|
98
|
+
if (!sec) return { content, replaced: false };
|
|
99
|
+
|
|
100
|
+
const inner = String(newBody).replace(/^\n+/, '').replace(/\n+$/, '');
|
|
101
|
+
if (sec.body === inner) return { content, replaced: false }; // idempotent no-op
|
|
102
|
+
|
|
103
|
+
const before = lines.slice(0, sec.openLine + 1);
|
|
104
|
+
const after = lines.slice(sec.closeLine);
|
|
105
|
+
const next = [...before, ...inner.split('\n'), ...after].join('\n');
|
|
106
|
+
return { content: next, replaced: true };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Replace a section's body if it exists; otherwise INSERT a new section.
|
|
111
|
+
* Insert position: `after:<id>` (after another section), 'top' (after the H1 /
|
|
112
|
+
* first heading), or 'end' (default, appended).
|
|
113
|
+
* @returns {{ content: string, action: 'replaced'|'inserted'|'unchanged' }}
|
|
114
|
+
*/
|
|
115
|
+
export function upsertSection(content, id, newBody, { source = 'code', position = 'end' } = {}) {
|
|
116
|
+
if (getSection(content, id)) {
|
|
117
|
+
const r = replaceSection(content, id, newBody);
|
|
118
|
+
return { content: r.content, action: r.replaced ? 'replaced' : 'unchanged' };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const block = renderSection(id, newBody, { source });
|
|
122
|
+
const lines = String(content).split('\n');
|
|
123
|
+
|
|
124
|
+
// Insert after a named section.
|
|
125
|
+
const afterMatch = /^after:(.+)$/.exec(position);
|
|
126
|
+
if (afterMatch) {
|
|
127
|
+
const target = parseSections(content).find(s => s.id === afterMatch[1].trim());
|
|
128
|
+
if (target) {
|
|
129
|
+
const before = lines.slice(0, target.closeLine + 1);
|
|
130
|
+
const after = lines.slice(target.closeLine + 1);
|
|
131
|
+
return { content: [...before, '', block, ...after].join('\n'), action: 'inserted' };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Insert just after the first heading (keeps the doc title on top).
|
|
136
|
+
if (position === 'top') {
|
|
137
|
+
const hIdx = lines.findIndex(l => /^#{1,6}\s/.test(l));
|
|
138
|
+
if (hIdx >= 0) {
|
|
139
|
+
const before = lines.slice(0, hIdx + 1);
|
|
140
|
+
const after = lines.slice(hIdx + 1);
|
|
141
|
+
return { content: [...before, '', block, ...after].join('\n'), action: 'inserted' };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Default: append at end (single trailing newline).
|
|
146
|
+
const base = String(content).replace(/\n+$/, '');
|
|
147
|
+
return { content: `${base}\n\n${block}\n`, action: 'inserted' };
|
|
148
|
+
}
|
package/commands/docguard.fix.md
CHANGED
|
@@ -11,11 +11,27 @@ handoffs:
|
|
|
11
11
|
|
|
12
12
|
# DocGuard Fix — AI-Assisted Documentation Repair
|
|
13
13
|
|
|
14
|
-
Generate or repair canonical documentation
|
|
14
|
+
Generate or repair canonical documentation. DocGuard splits fixes into two kinds:
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
- **Mechanical (deterministic, no AI):** structural edits DocGuard applies itself with
|
|
17
|
+
`docguard fix --write` — e.g. removing an endpoint from `docs-canonical/API-REFERENCE.md`
|
|
18
|
+
that the OpenAPI spec confirms no longer exists (its table row + detail block are deleted).
|
|
19
|
+
- **Agent (needs an AI):** content rewrites that require judgment — e.g. replacing an
|
|
20
|
+
X-Ray prose section with CloudWatch, or writing a new endpoint's request/response block.
|
|
21
|
+
These use the research-prompt workflow below.
|
|
17
22
|
|
|
18
|
-
|
|
23
|
+
## Apply mechanical fixes first (fast, safe)
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx docguard-cli fix --write # removes stale documented endpoints; idempotent
|
|
27
|
+
```
|
|
28
|
+
- Only edits docs marked `<!-- docguard:generated true -->` (use `--force` to override).
|
|
29
|
+
- Prints exactly what it removed. Re-run is a no-op if nothing changed.
|
|
30
|
+
- Run `docguard guard` afterward; whatever remains is agent work (below).
|
|
31
|
+
|
|
32
|
+
## What to do (agent work)
|
|
33
|
+
|
|
34
|
+
1. **Identify what needs fixing** (each issue is tagged `mechanical` or `agent`):
|
|
19
35
|
```bash
|
|
20
36
|
npx docguard-cli diagnose
|
|
21
37
|
```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: Run DocGuard guard validation — check project documentation against CDD standards with
|
|
2
|
+
description: Run DocGuard guard validation — check project documentation against CDD standards with 20 validators
|
|
3
3
|
handoffs:
|
|
4
4
|
- label: Fix All Issues
|
|
5
5
|
agent: docguard.fix
|
|
@@ -23,14 +23,14 @@ Run the DocGuard CLI to validate all documentation against Canonical-Driven Deve
|
|
|
23
23
|
npx docguard-cli guard
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
2. **Parse the output**. Each of the
|
|
26
|
+
2. **Parse the output**. Each of the 20 validators reports ✅ (pass), ⚠️ (warning), ❌ (fail), or ➖ (N/A — nothing to validate). **A ➖ N/A is NOT a pass**: it means the validator found nothing to check (e.g. no API-REFERENCE.md, no DB schema, no layer boundaries declared). Don't read N/A as "healthy" — read it as "not assessed".
|
|
27
27
|
|
|
28
28
|
| Validator | What It Checks |
|
|
29
29
|
|-----------|---------------|
|
|
30
30
|
| Structure | Required CDD files exist |
|
|
31
31
|
| Doc Sections | Canonical docs have required sections |
|
|
32
32
|
| Docs-Sync | External doc references are valid |
|
|
33
|
-
| Drift |
|
|
33
|
+
| Drift-Comments | `// DRIFT:` code comments logged in DRIFT-LOG.md |
|
|
34
34
|
| Changelog | CHANGELOG.md is maintained |
|
|
35
35
|
| Test-Spec | Tests match TEST-SPEC.md rules |
|
|
36
36
|
| Environment | Environment documentation |
|
|
@@ -39,6 +39,7 @@ npx docguard-cli guard
|
|
|
39
39
|
| Freshness | Docs updated within commit window |
|
|
40
40
|
| Traceability | Requirements trace to tests |
|
|
41
41
|
| Docs-Diff | Doc changes match code changes |
|
|
42
|
+
| API-Surface | API-REFERENCE.md endpoints match the real API surface (OpenAPI spec / routes) |
|
|
42
43
|
| Metadata-Sync | Metadata headers are consistent |
|
|
43
44
|
| Docs-Coverage | All config files documented |
|
|
44
45
|
| Doc-Quality | Readability, IEEE 830 compliance |
|
|
@@ -49,7 +50,7 @@ npx docguard-cli guard
|
|
|
49
50
|
|
|
50
51
|
3. **Triage findings by severity**:
|
|
51
52
|
- **CRITICAL**: Structure, Security, Test-Spec failures
|
|
52
|
-
- **HIGH**: Doc Sections, Drift, Changelog, Traceability failures
|
|
53
|
+
- **HIGH**: Doc Sections, Drift-Comments, Changelog, Traceability, API-Surface (documented-but-absent endpoint) failures
|
|
53
54
|
- **MEDIUM**: Freshness, Docs-Coverage, Doc-Quality, Metrics-Consistency warnings
|
|
54
55
|
- **LOW**: TODO-Tracking, Schema-Sync, Spec-Kit, Metadata-Sync warnings
|
|
55
56
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Section-Addressable Docs
|
|
2
|
+
|
|
3
|
+
DocGuard maintains canonical docs *surgically*: it regenerates the parts that are
|
|
4
|
+
derived from code while never touching the prose a human wrote. It does this with
|
|
5
|
+
HTML-comment markers that keep the document plain, readable markdown.
|
|
6
|
+
|
|
7
|
+
## The marker format
|
|
8
|
+
|
|
9
|
+
```markdown
|
|
10
|
+
<!-- docguard:section id=api-endpoints source=code -->
|
|
11
|
+
| `GET` | `/api/users` | … |
|
|
12
|
+
<!-- /docguard:section -->
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
- **`id`** — a stable identifier for the section (e.g. `api-endpoints`, `entities`,
|
|
16
|
+
`env-vars`, `screens`). DocGuard addresses sections by id.
|
|
17
|
+
- **`source`** — `code` means DocGuard owns and may regenerate this block from the
|
|
18
|
+
codebase; `human` means it is author-owned and DocGuard will not rewrite it.
|
|
19
|
+
|
|
20
|
+
Markers must each sit on their own line. An open marker with no matching close is
|
|
21
|
+
ignored (DocGuard never corrupts a malformed doc).
|
|
22
|
+
|
|
23
|
+
## What DocGuard does and does not touch
|
|
24
|
+
|
|
25
|
+
- It rewrites **only** the bytes between a `source=code` section's open and close
|
|
26
|
+
markers when the underlying code changes.
|
|
27
|
+
- **Everything outside any marker — and any `source=human` section — is preserved
|
|
28
|
+
exactly.** Your rationale, "why" notes, and design intent are safe.
|
|
29
|
+
|
|
30
|
+
## Why this matters
|
|
31
|
+
|
|
32
|
+
This is the foundation for two things:
|
|
33
|
+
|
|
34
|
+
1. **Complete generation** — `docguard generate` writes code-derived sections inside
|
|
35
|
+
markers, then an AI agent fills the prose around them.
|
|
36
|
+
2. **Always up to date** — `docguard sync` refreshes just the affected section when
|
|
37
|
+
code changes, instead of regenerating (and clobbering) the whole document.
|
package/docs/quickstart.md
CHANGED
|
@@ -68,7 +68,7 @@ diagnose → AI reads prompts → AI fixes docs → guard verifies
|
|
|
68
68
|
## Verify
|
|
69
69
|
|
|
70
70
|
```bash
|
|
71
|
-
npx docguard-cli guard # Pass/fail check (
|
|
71
|
+
npx docguard-cli guard # Pass/fail check (20 validators)
|
|
72
72
|
npx docguard-cli score # 0-100 maturity score
|
|
73
73
|
```
|
|
74
74
|
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
# DocGuard — CDD Enforcement Extension for Spec Kit
|
|
2
2
|
|
|
3
|
-
Enterprise-grade Canonical-Driven Development (CDD) enforcement for [Spec Kit](https://github.com/github/spec-kit).
|
|
3
|
+
Enterprise-grade Canonical-Driven Development (CDD) enforcement and **AI-readable project memory** for [Spec Kit](https://github.com/github/spec-kit). DocGuard builds a complete, language-aware documentation memory of any codebase (`generate --plan`), keeps it always up to date as code changes (`sync`), and verifies it (`guard`) — with deterministic mechanical fixes (`fix --write`) where it can and grounded agent prompts where prose is needed.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
7
|
+
- **20 Validators** — Structure, Security, Doc Quality, Test-Spec, Drift-Comments, API-Surface, Freshness, and 13 more
|
|
8
|
+
- **Language-agnostic** — JS/TS, Python, Rust, Go, Java/Kotlin, Ruby, PHP, C#. Polyglot/monorepo-aware.
|
|
9
|
+
- **AI-powered Generate** — `generate --plan` builds the code-truth skeleton in `<!-- docguard:section -->` markers and emits a structured agent task manifest; the AI writes the prose.
|
|
10
|
+
- **Always up to date** — `sync` surgically refreshes code-truth doc sections in place, **preserves human prose**, flags prose for agent review.
|
|
11
|
+
- **Mechanical `fix --write`** — deterministic, no-LLM: remove stale documented endpoints, refresh stale "N validators" counts, replace stale version refs, insert missing `## [Unreleased]`.
|
|
12
|
+
- **5 AI Skills** — docguard-fix, docguard-guard, docguard-sync, docguard-review, docguard-score (enterprise-grade behavior protocols, not just step-lists)
|
|
13
|
+
- **Workflow Chaining** — YAML handoffs enable guard → sync → fix → review → score flows
|
|
11
14
|
- **Spec Kit Hooks** — Quality gate integrations at implement, tasks, and review phases
|
|
12
15
|
- **Zero Dependencies** — Pure Node.js built-ins only
|
|
13
16
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Fix documentation drift — mechanical (no AI) or AI-driven research, depending on the issue
|
|
3
|
+
allowed-tools: Bash, Read, Edit
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# DocGuard Fix
|
|
7
|
+
|
|
8
|
+
DocGuard splits drift into two kinds and is explicit about which is which.
|
|
9
|
+
|
|
10
|
+
- **Mechanical** (deterministic, no AI): apply with `docguard fix --write`. Covers
|
|
11
|
+
removing endpoints documented but absent in code, refreshing stale "N validators"
|
|
12
|
+
counts, replacing stale version references, inserting a missing `## [Unreleased]`.
|
|
13
|
+
- **Agent** (needs judgment): content rewrites — e.g. updating an X-Ray section to
|
|
14
|
+
CloudWatch, writing a new endpoint's request/response block.
|
|
15
|
+
|
|
16
|
+
## User Input
|
|
17
|
+
|
|
18
|
+
```text
|
|
19
|
+
$ARGUMENTS
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
You **MUST** consider the user input before proceeding (if not empty).
|
|
23
|
+
|
|
24
|
+
## Execution
|
|
25
|
+
|
|
26
|
+
### Step 1 — Apply mechanical fixes (fast, safe, no AI)
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx --yes docguard-cli@latest fix --write
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Output lists every applied fix. Idempotent: re-running is a no-op if nothing changed.
|
|
33
|
+
Only edits `<!-- docguard:generated true -->` docs unless `--force`.
|
|
34
|
+
|
|
35
|
+
### Step 2 — Identify remaining issues by kind
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx --yes docguard-cli@latest diagnose --format json
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Each issue is tagged `fixKind: mechanical` (mostly handled by step 1) or
|
|
42
|
+
`fixKind: agent`. Focus on the agent ones.
|
|
43
|
+
|
|
44
|
+
### Step 3 — Use the deep doc prompt for content rewrites
|
|
45
|
+
|
|
46
|
+
For each affected canonical doc, get a research-grounded prompt:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx --yes docguard-cli@latest fix --doc architecture
|
|
50
|
+
npx --yes docguard-cli@latest fix --doc data-model
|
|
51
|
+
npx --yes docguard-cli@latest fix --doc api-reference
|
|
52
|
+
npx --yes docguard-cli@latest fix --doc security
|
|
53
|
+
npx --yes docguard-cli@latest fix --doc test-spec
|
|
54
|
+
npx --yes docguard-cli@latest fix --doc environment
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Execute the research steps in each prompt: read actual code files, map modules,
|
|
58
|
+
trace routes, extract real schemas, identify real auth patterns. Then write the
|
|
59
|
+
sections — using real file paths, real module names, real dependencies. No placeholders.
|
|
60
|
+
|
|
61
|
+
### Step 4 — Verify
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npx --yes docguard-cli@latest guard
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Iterate until clean (max 3 rounds; if still failing, report remaining issues).
|
|
68
|
+
|
|
69
|
+
## Flags
|
|
70
|
+
|
|
71
|
+
- `--write` — apply deterministic fixes in place (step 1).
|
|
72
|
+
- `--doc <name>` — emit a research-grounded prompt for one specific document (step 3).
|
|
73
|
+
- `--force` — for `--write`, edit docs that lack the generated marker.
|
|
74
|
+
- `--format json` — machine-readable issue list (with `fixKind`).
|
|
@@ -11,7 +11,12 @@ handoffs:
|
|
|
11
11
|
|
|
12
12
|
# DocGuard Generate
|
|
13
13
|
|
|
14
|
-
Scans your codebase and generates canonical documentation: ARCHITECTURE.md, DATA-MODEL.md, TEST-SPEC.md, SECURITY.md, ENVIRONMENT.md,
|
|
14
|
+
Scans your codebase (JS/TS, Python, Rust, Go, Java/Kotlin, Ruby, PHP, C# — polyglot/monorepo-aware) and generates the canonical documentation memory: ARCHITECTURE.md, DATA-MODEL.md, TEST-SPEC.md, SECURITY.md, ENVIRONMENT.md, API-REFERENCE.md, SCREENS.md.
|
|
15
|
+
|
|
16
|
+
Two modes:
|
|
17
|
+
|
|
18
|
+
- **`--plan`** (AI-powered, recommended) — emits a structured agent task manifest + writes the code-truth skeleton inside `<!-- docguard:section -->` markers. The AI agent then writes the prose grounded in scanned facts. Human prose is preserved.
|
|
19
|
+
- **default** — purely deterministic generation: writes templated docs with TODO placeholders. Use when no AI agent is available.
|
|
15
20
|
|
|
16
21
|
## User Input
|
|
17
22
|
|
|
@@ -19,7 +24,25 @@ $ARGUMENTS
|
|
|
19
24
|
|
|
20
25
|
## Steps
|
|
21
26
|
|
|
22
|
-
1.
|
|
27
|
+
1. **Preview the plan** — what code-truth facts were captured + what the agent will write:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npx --yes docguard-cli@latest generate --plan $ARGUMENTS
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
2. **Scaffold the skeleton docs** (marked sections filled with code-truth, prose sections as agent-task placeholders):
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx --yes docguard-cli@latest generate --plan --write $ARGUMENTS
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
3. **Or get the machine-readable manifest** to drive an agent:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx --yes docguard-cli@latest generate --plan --format json $ARGUMENTS
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
4. **Fallback** (no AI, deterministic generation):
|
|
23
46
|
|
|
24
47
|
```bash
|
|
25
48
|
npx --yes docguard-cli@latest generate $ARGUMENTS
|
|
@@ -14,7 +14,7 @@ handoffs:
|
|
|
14
14
|
|
|
15
15
|
# DocGuard Guard
|
|
16
16
|
|
|
17
|
-
Validate your project against its canonical documentation. Runs 160+ automated checks across
|
|
17
|
+
Validate your project against its canonical documentation. Runs 160+ automated checks across 20 validators.
|
|
18
18
|
|
|
19
19
|
## User Input
|
|
20
20
|
|
|
@@ -31,11 +31,11 @@ You **MUST** consider the user input before proceeding (if not empty).
|
|
|
31
31
|
npx --yes docguard-cli@latest guard $ARGUMENTS
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
2. Parse each validator's result and build a severity-ranked findings table.
|
|
34
|
+
2. Parse each validator's result and build a severity-ranked findings table. Status glyphs: ✅ pass, ⚠️ warning, ❌ fail, ➖ N/A (nothing to validate — NOT a pass; the dimension was not assessed).
|
|
35
35
|
|
|
36
36
|
3. **Triage by severity**:
|
|
37
37
|
- **CRITICAL**: Structure, Security, Test-Spec failures → fix immediately
|
|
38
|
-
- **HIGH**: Doc Sections, Drift, Changelog, Traceability → fix before commit
|
|
38
|
+
- **HIGH**: Doc Sections, Drift-Comments, Changelog, Traceability, API-Surface → fix before commit
|
|
39
39
|
- **MEDIUM**: Freshness, Docs-Coverage, Doc-Quality, Metrics → fix this sprint
|
|
40
40
|
- **LOW**: TODO-Tracking, Schema-Sync, Spec-Kit, Metadata → fix when convenient
|
|
41
41
|
|
|
@@ -43,14 +43,14 @@ npx --yes docguard-cli@latest guard $ARGUMENTS
|
|
|
43
43
|
|
|
44
44
|
5. Re-run guard after fixes. Iterate until all checks pass (max 3 iterations).
|
|
45
45
|
|
|
46
|
-
## Validators (
|
|
46
|
+
## Validators (20 total)
|
|
47
47
|
|
|
48
48
|
| Validator | What It Checks |
|
|
49
49
|
|-----------|---------------|
|
|
50
50
|
| Structure | Required CDD files exist |
|
|
51
51
|
| Doc Sections | Canonical docs have required sections |
|
|
52
52
|
| Docs-Sync | External doc references are valid |
|
|
53
|
-
| Drift | `// DRIFT:` comments have DRIFT-LOG entries |
|
|
53
|
+
| Drift-Comments | `// DRIFT:` comments have DRIFT-LOG entries |
|
|
54
54
|
| Changelog | CHANGELOG.md is maintained |
|
|
55
55
|
| Test-Spec | TEST-SPEC.md matches actual test files |
|
|
56
56
|
| Environment | Environment docs and .env.example exist |
|
|
@@ -59,6 +59,7 @@ npx --yes docguard-cli@latest guard $ARGUMENTS
|
|
|
59
59
|
| Freshness | Docs updated after recent code changes |
|
|
60
60
|
| Traceability | Canonical docs linked to source code |
|
|
61
61
|
| Docs-Diff | Entity/route/field drift between code and docs |
|
|
62
|
+
| API-Surface | API-REFERENCE.md endpoints match the real API surface (OpenAPI spec / routes) |
|
|
62
63
|
| Metadata-Sync | Metadata headers are consistent |
|
|
63
64
|
| Docs-Coverage | All config files documented |
|
|
64
65
|
| Doc-Quality | Readability, IEEE 830 compliance |
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Keep canonical docs always up to date — refresh code-truth sections in place, preserve human prose
|
|
3
|
+
allowed-tools: Bash, Read, Edit
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# DocGuard Sync
|
|
7
|
+
|
|
8
|
+
Keep the documentation memory ALWAYS UP TO DATE. Sync re-derives every code-truth
|
|
9
|
+
section (endpoints, entities, screens, tech stack, env vars) and refreshes the
|
|
10
|
+
matching `source=code` sections of existing canonical docs in place. **Human prose
|
|
11
|
+
is never touched** — it lives outside markers or in `source=human` sections.
|
|
12
|
+
|
|
13
|
+
When a code section changes, the prose sections in that doc are flagged for agent review.
|
|
14
|
+
|
|
15
|
+
## User Input
|
|
16
|
+
|
|
17
|
+
```text
|
|
18
|
+
$ARGUMENTS
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
You **MUST** consider the user input before proceeding (if not empty).
|
|
22
|
+
|
|
23
|
+
## Execution
|
|
24
|
+
|
|
25
|
+
1. Preview what will change (dry run, never writes):
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx --yes docguard-cli@latest sync $ARGUMENTS
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
2. If only `source=code` sections are stale, apply the mechanical refresh:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npx --yes docguard-cli@latest sync --write $ARGUMENTS
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
3. For each "prose to review" line, **read the affected doc and update the
|
|
38
|
+
surrounding human-written section to match the new code reality** (e.g. if the
|
|
39
|
+
endpoints table grew, update the API overview prose). Then re-run guard:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx --yes docguard-cli@latest guard
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Flags
|
|
46
|
+
|
|
47
|
+
- `--since <ref>` — also report which code files changed since this git ref (context for prose updates).
|
|
48
|
+
- `--write` — apply the mechanical refreshes. Default is a dry-run preview.
|
|
49
|
+
- `--force` — sync docs even without the `<!-- docguard:generated true -->` marker.
|
|
50
|
+
- `--format json` — machine-readable output (`updates`, `reviews`, `skipped`).
|
|
51
|
+
|
|
52
|
+
## When to use
|
|
53
|
+
|
|
54
|
+
- **Before opening a PR:** `docguard sync --since main` to refresh any stale sections.
|
|
55
|
+
- **On a pre-commit hook:** auto-keep the memory current.
|
|
56
|
+
- **After a big refactor:** confirm the doc map still matches the territory.
|
|
57
|
+
|
|
58
|
+
## Triage glyphs
|
|
59
|
+
|
|
60
|
+
- `↻` mechanically refreshed (code section updated)
|
|
61
|
+
- `•` stale (will refresh with `--write`)
|
|
62
|
+
- `🤖` prose to review — open the doc, update the relevant human-written section
|
|
@@ -36,9 +36,19 @@ Research the actual codebase to generate or repair canonical documentation that
|
|
|
36
36
|
|
|
37
37
|
## Execution Flow
|
|
38
38
|
|
|
39
|
+
### Step 0: Apply Mechanical Fixes First (no AI needed)
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx docguard-cli fix --write 2>&1
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Removes endpoints documented in `docs-canonical/API-REFERENCE.md` that the OpenAPI
|
|
46
|
+
spec confirms no longer exist (table row + detail block). Only edits
|
|
47
|
+
`docguard:generated` docs, idempotent, prints what changed. Don't hand-edit these.
|
|
48
|
+
|
|
39
49
|
### Step 1: Diagnose Current State
|
|
40
50
|
|
|
41
|
-
Run the diagnostic to identify all issues:
|
|
51
|
+
Run the diagnostic to identify all issues (each tagged `mechanical` or `agent`):
|
|
42
52
|
|
|
43
53
|
```bash
|
|
44
54
|
npx docguard-cli diagnose 2>&1
|
|
@@ -78,7 +78,8 @@ Classify every non-passing check using this priority matrix:
|
|
|
78
78
|
|
|
79
79
|
**HIGH (fix before commit)**:
|
|
80
80
|
- Doc Sections failures (missing required sections)
|
|
81
|
-
- Drift
|
|
81
|
+
- Drift-Comments (a `// DRIFT:` comment without a DRIFT-LOG.md entry)
|
|
82
|
+
- API-Surface (API-REFERENCE.md documents an endpoint that no longer exists in code)
|
|
82
83
|
- Changelog gaps
|
|
83
84
|
- Traceability breaks
|
|
84
85
|
|
|
@@ -138,7 +139,7 @@ For each finding, provide a **specific, actionable fix** — not "fix the issue"
|
|
|
138
139
|
|
|
139
140
|
Based on the triage results:
|
|
140
141
|
|
|
141
|
-
- **If all PASS**: "All
|
|
142
|
+
- **If all PASS**: "All 20 validators passed. Project is CDD-compliant. Ready to commit."
|
|
142
143
|
- **If only MEDIUM/LOW warnings**: "Non-blocking warnings found. Safe to commit, but consider running `/docguard.fix` for automated remediation."
|
|
143
144
|
- **If HIGH or CRITICAL failures**: "Blocking issues found. Fix these before committing. Suggest running `/docguard.fix --doc [most impactful doc]` next."
|
|
144
145
|
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: docguard-sync
|
|
3
|
+
description: Keep canonical documentation ALWAYS UP TO DATE. Refreshes code-truth doc sections in place (mechanical, idempotent, preserves human prose) and flags the prose sections you must review when code changes.
|
|
4
|
+
compatibility: Requires DocGuard CLI installed (npm i -g docguard-cli or npx docguard-cli)
|
|
5
|
+
metadata:
|
|
6
|
+
author: docguard
|
|
7
|
+
version: 0.10.0
|
|
8
|
+
source: extensions/spec-kit-docguard/skills/docguard-sync
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# DocGuard Sync Skill
|
|
12
|
+
|
|
13
|
+
## User Input
|
|
14
|
+
|
|
15
|
+
```text
|
|
16
|
+
$ARGUMENTS
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
You **MUST** consider the user input. If `--since <ref>` is provided, include the
|
|
20
|
+
git diff context in your reasoning when reviewing prose sections.
|
|
21
|
+
|
|
22
|
+
## Goal
|
|
23
|
+
|
|
24
|
+
When code changes, re-derive the code-truth surface (endpoints, entities,
|
|
25
|
+
screens, tech stack, env vars), refresh the matching `<!-- docguard:section
|
|
26
|
+
source=code -->` blocks in canonical docs in place, and **review/refresh the
|
|
27
|
+
human-written prose** in the same docs so it still describes reality.
|
|
28
|
+
|
|
29
|
+
## Operating Constraints
|
|
30
|
+
|
|
31
|
+
- **Mechanical refreshes do not need you.** DocGuard does them itself. Your job
|
|
32
|
+
is the prose sections flagged as "review" — where the human writing may no
|
|
33
|
+
longer match the new code reality.
|
|
34
|
+
- **Never edit anything outside the marked `source=human` sections** in
|
|
35
|
+
generated docs. The markers protect human writing; respect them.
|
|
36
|
+
- **Use the dry run first** to see what will change before applying.
|
|
37
|
+
|
|
38
|
+
## Execution Flow
|
|
39
|
+
|
|
40
|
+
### Step 1 — Preview what's stale
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx --yes docguard-cli@latest sync 2>&1
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Reads:
|
|
47
|
+
- `↻` / `•` lines: code-truth sections that drifted (you don't need to write these).
|
|
48
|
+
- `🤖 Prose to review` lines: human-written sections whose surrounding code changed — **these are yours**.
|
|
49
|
+
|
|
50
|
+
### Step 2 — Apply the mechanical refresh
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npx --yes docguard-cli@latest sync --write 2>&1
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Re-derives every code-truth section from the current code and rewrites only those
|
|
57
|
+
markers. Idempotent — running again is a no-op when up to date.
|
|
58
|
+
|
|
59
|
+
### Step 3 — Review the flagged prose
|
|
60
|
+
|
|
61
|
+
For each `🤖 Prose to review` entry:
|
|
62
|
+
|
|
63
|
+
1. Open the doc (e.g. `docs-canonical/API-REFERENCE.md`).
|
|
64
|
+
2. Locate the `<!-- docguard:section id=<id> source=human -->` block.
|
|
65
|
+
3. **Read the surrounding `source=code` section first** — that's the new truth
|
|
66
|
+
(e.g. the refreshed endpoint list, the refreshed screens table).
|
|
67
|
+
4. Update the human prose so it still accurately describes that truth.
|
|
68
|
+
Examples of what to update:
|
|
69
|
+
- The API overview's endpoint count, or its description of the surface area.
|
|
70
|
+
- The Architecture overview when new components/services appeared.
|
|
71
|
+
- The Screens flows when new screens were added/removed/renamed.
|
|
72
|
+
5. Stay inside the `source=human` markers — don't touch the code sections.
|
|
73
|
+
|
|
74
|
+
### Step 4 — Verify
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npx --yes docguard-cli@latest guard
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Confirm there are no errors. If the API surface drifted (`API-Surface` failures),
|
|
81
|
+
combine with `docguard fix --write` (the mechanical removal of stale endpoints).
|
|
82
|
+
|
|
83
|
+
### Step 5 — Loop
|
|
84
|
+
|
|
85
|
+
The intended flow is `sync → guard → (fix if needed) → guard → commit`. Run sync
|
|
86
|
+
again before opening a PR to make sure the memory is current.
|
|
87
|
+
|
|
88
|
+
## What to do if `--since <ref>` is provided
|
|
89
|
+
|
|
90
|
+
When `--since main` is given, DocGuard also lists the changed code files since
|
|
91
|
+
that ref. Use that diff to:
|
|
92
|
+
|
|
93
|
+
- Prioritize which prose sections to update first (the ones whose related code
|
|
94
|
+
files changed most).
|
|
95
|
+
- Cite concrete change reasons in your prose updates ("Added `/api/orders`
|
|
96
|
+
endpoint in commit X" → update the API overview accordingly).
|
|
97
|
+
|
|
98
|
+
## Common patterns
|
|
99
|
+
|
|
100
|
+
| Symptom | Action |
|
|
101
|
+
|---|---|
|
|
102
|
+
| `↻ docs-canonical/API-REFERENCE.md → endpoints` | Code-truth refreshed by `--write`. No action needed. |
|
|
103
|
+
| `🤖 docs-canonical/API-REFERENCE.md → overview` | Open the doc; update the `overview` prose to reflect the new endpoint set. |
|
|
104
|
+
| `Skipped … not marked docguard:generated` | The doc isn't owned by DocGuard. Either add the marker (and commit ownership) or skip with `--force`. |
|
|
105
|
+
| `Documentation memory is up to date` | Done — no drift. |
|
|
106
|
+
|
|
107
|
+
## Anti-patterns (do NOT do these)
|
|
108
|
+
|
|
109
|
+
- ❌ Editing inside `<!-- docguard:section source=code -->` — DocGuard will rewrite it on the next sync.
|
|
110
|
+
- ❌ Removing the markers to "make the doc look cleaner" — that breaks future sync/regeneration.
|
|
111
|
+
- ❌ Skipping `sync --write` and editing the code section by hand — let DocGuard do it.
|