docguard-cli 0.28.0 → 0.30.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.
Files changed (69) hide show
  1. package/README.es.md +102 -0
  2. package/README.md +80 -32
  3. package/README.pt-BR.md +101 -0
  4. package/STANDARD.md +20 -10
  5. package/cli/commands/agents.mjs +149 -0
  6. package/cli/commands/diff.mjs +6 -15
  7. package/cli/commands/generate.mjs +14 -1001
  8. package/cli/commands/guard.mjs +136 -8
  9. package/cli/commands/llms.mjs +67 -5
  10. package/cli/commands/mcp.mjs +263 -0
  11. package/cli/commands/memory.mjs +115 -0
  12. package/cli/commands/score.mjs +76 -12
  13. package/cli/commands/trace.mjs +364 -1
  14. package/cli/commands/verify.mjs +93 -6
  15. package/cli/docguard.mjs +42 -5
  16. package/cli/findings.mjs +511 -0
  17. package/cli/scanners/agent-readability.mjs +202 -0
  18. package/cli/scanners/instruction-audit.mjs +320 -0
  19. package/cli/scanners/semantic-claims.mjs +7 -1
  20. package/cli/scanners/speckit.mjs +443 -28
  21. package/cli/shared-ignore.mjs +148 -16
  22. package/cli/shared.mjs +45 -1
  23. package/cli/validators/api-surface.mjs +113 -26
  24. package/cli/validators/architecture.mjs +66 -43
  25. package/cli/validators/canonical-sync.mjs +59 -28
  26. package/cli/validators/changelog.mjs +41 -17
  27. package/cli/validators/cross-reference.mjs +28 -11
  28. package/cli/validators/doc-quality.mjs +78 -44
  29. package/cli/validators/docs-coverage.mjs +90 -63
  30. package/cli/validators/docs-diff.mjs +63 -64
  31. package/cli/validators/docs-sync.mjs +48 -33
  32. package/cli/validators/drift.mjs +40 -34
  33. package/cli/validators/environment.mjs +67 -27
  34. package/cli/validators/freshness.mjs +12 -5
  35. package/cli/validators/generated-staleness.mjs +26 -10
  36. package/cli/validators/metadata-sync.mjs +28 -25
  37. package/cli/validators/metrics-consistency.mjs +89 -47
  38. package/cli/validators/schema-sync.mjs +37 -32
  39. package/cli/validators/security.mjs +7 -20
  40. package/cli/validators/spec-kit.mjs +3 -0
  41. package/cli/validators/structure.mjs +58 -23
  42. package/cli/validators/surface-sync.mjs +34 -15
  43. package/cli/validators/test-spec.mjs +87 -29
  44. package/cli/validators/todo-tracking.mjs +83 -74
  45. package/cli/validators/traceability.mjs +67 -39
  46. package/cli/writers/doc-generators.mjs +853 -0
  47. package/cli/writers/generate-io.mjs +142 -0
  48. package/cli/writers/sarif.mjs +129 -0
  49. package/commands/docguard.fix.md +56 -53
  50. package/commands/docguard.guard.md +53 -47
  51. package/commands/docguard.review.md +49 -31
  52. package/docs/ai-integration.md +133 -134
  53. package/docs/commands.md +49 -3
  54. package/docs/configuration.md +38 -0
  55. package/docs/faq.md +15 -0
  56. package/extensions/spec-kit-docguard/extension.yml +1 -1
  57. package/extensions/spec-kit-docguard/skills/docguard-fix/SKILL.md +2 -2
  58. package/extensions/spec-kit-docguard/skills/docguard-guard/SKILL.md +2 -2
  59. package/extensions/spec-kit-docguard/skills/docguard-review/SKILL.md +2 -2
  60. package/extensions/spec-kit-docguard/skills/docguard-score/SKILL.md +2 -2
  61. package/extensions/spec-kit-docguard/skills/docguard-sync/SKILL.md +2 -2
  62. package/package.json +2 -1
  63. package/schemas/docguard-config.schema.json +28 -0
  64. package/templates/ci/gitlab-component.yml +90 -0
  65. package/templates/commands/docguard.fix.md +33 -10
  66. package/templates/commands/docguard.guard.md +40 -26
  67. package/templates/commands/docguard.init.md +23 -11
  68. package/templates/commands/docguard.review.md +25 -8
  69. package/templates/commands/docguard.update.md +14 -4
@@ -0,0 +1,90 @@
1
+ # DocGuard — GitLab CI/CD component (CI/CD Catalog style, spec:inputs syntax).
2
+ # Docs: https://docs.gitlab.com/ci/components/ and https://docs.gitlab.com/ci/inputs/
3
+ #
4
+ # This file STAGES the component. Actual catalog publishing requires a GitLab
5
+ # account and a dedicated component project (see packaging/submissions.md):
6
+ # 1. Create a GitLab project (e.g. gitlab.com/raccioly/docguard-component).
7
+ # 2. Copy this file to `templates/docguard.yml` at that project's root
8
+ # (components must live in a top-level templates/ directory).
9
+ # 3. Set the project as a CI/CD Catalog project (Settings > General > Visibility,
10
+ # "CI/CD Catalog project" toggle) and add a release job that tags a version.
11
+ #
12
+ # Consumers then include it as:
13
+ #
14
+ # include:
15
+ # - component: gitlab.com/raccioly/docguard-component/docguard@0.29.0
16
+ # inputs:
17
+ # command: guard
18
+ # fail_on_warning: true
19
+ #
20
+ # Or, without the catalog, this works today from any repo via a plain include:
21
+ #
22
+ # include:
23
+ # - remote: https://raw.githubusercontent.com/raccioly/docguard/v0.29.0/templates/ci/gitlab-component.yml
24
+
25
+ spec:
26
+ inputs:
27
+ command:
28
+ description: DocGuard command to run.
29
+ type: string
30
+ default: guard
31
+ options: [guard, score, ci]
32
+ threshold:
33
+ description: Minimum CDD score (0-100) to pass. Only enforced by the `ci` command; 0 disables.
34
+ type: number
35
+ default: 0
36
+ fail_on_warning:
37
+ description: Fail the job on warnings, not just errors.
38
+ type: boolean
39
+ default: false
40
+ version:
41
+ description: docguard-cli version to run (npm dist-tag or exact version).
42
+ type: string
43
+ default: '0.29.0'
44
+ node_image:
45
+ description: Node.js image for the job (needs git available, so prefer the non-alpine tags).
46
+ type: string
47
+ default: 'node:20'
48
+ ---
49
+ docguard:
50
+ image: '$[[ inputs.node_image ]]'
51
+ stage: test
52
+ variables:
53
+ # Several validators diff against git history — avoid a shallow clone.
54
+ GIT_DEPTH: '0'
55
+ script:
56
+ - |
57
+ set +e
58
+ CMD="$[[ inputs.command ]]"
59
+ FAIL_ON_WARNING="$[[ inputs.fail_on_warning ]]"
60
+ THRESHOLD="$[[ inputs.threshold ]]"
61
+ FLAGS=""
62
+ if [ "$CMD" = "ci" ] && [ "$THRESHOLD" -gt 0 ]; then
63
+ FLAGS="$FLAGS --threshold $THRESHOLD"
64
+ fi
65
+ if [ "$CMD" = "ci" ] && [ "$FAIL_ON_WARNING" = "true" ]; then
66
+ FLAGS="$FLAGS --fail-on-warning"
67
+ fi
68
+
69
+ npx "docguard-cli@$[[ inputs.version ]]" "$CMD" $FLAGS
70
+ RC=$?
71
+
72
+ # guard exit code 2 = warnings only. Not a failure unless asked for.
73
+ if [ "$CMD" = "guard" ] && [ "$RC" = "2" ]; then
74
+ if [ "$FAIL_ON_WARNING" = "true" ]; then
75
+ echo "DocGuard guard found warnings (fail_on_warning is enabled)."
76
+ RC=1
77
+ else
78
+ echo "DocGuard guard found warnings — passing (set fail_on_warning: true to fail)."
79
+ RC=0
80
+ fi
81
+ fi
82
+
83
+ # SARIF report as a browsable artifact — best-effort, never changes the verdict.
84
+ npx "docguard-cli@$[[ inputs.version ]]" guard --format sarif > docguard.sarif || true
85
+
86
+ exit $RC
87
+ artifacts:
88
+ when: always
89
+ paths:
90
+ - docguard.sarif
@@ -13,29 +13,47 @@ handoffs:
13
13
 
14
14
  You are an AI agent responsible for maintaining documentation quality using DocGuard.
15
15
 
16
- ## Step 1: Assess Current State
16
+ ## Step 1: Mechanical fixes first (no AI judgment needed)
17
17
 
18
18
  ```bash
19
- npx docguard-cli diagnose
19
+ npx docguard-cli fix --write
20
20
  ```
21
21
 
22
- Parse the output to identify all issues categorized as errors or warnings with AI-ready fix prompts.
22
+ This deterministically applies the safe fix class: broken doc anchors, stale
23
+ counts bound to code collections, stale version references. Each fix is
24
+ provenance-checked and fail-closed — it never rewrites content whose source of
25
+ truth it cannot verify. Doing this first shrinks the issue list you research.
23
26
 
24
- If no issues found, report "All CDD documentation is up to date" and stop.
27
+ ## Step 2: Assess what remains
25
28
 
26
- ## Step 2: Fix Each Issue
29
+ ```bash
30
+ npx docguard-cli diagnose
31
+ ```
27
32
 
28
- For each issue, determine the fix type:
33
+ Parse the output issues are categorized with AI-ready fix prompts. Every
34
+ finding carries a stable code; run `npx docguard-cli explain <CODE>` whenever
35
+ the right remediation isn't obvious from the message.
36
+
37
+ If no issues remain, report "All CDD documentation is up to date" and stop.
38
+
39
+ ## Step 3: Fix each issue
29
40
 
30
41
  | Issue Type | Action |
31
42
  |-----------|--------|
32
43
  | `missing-file` | Run `npx docguard-cli fix --doc <name>` to generate |
33
- | `empty-doc` / `partial-doc` | Proceed to Step 3 for codebase research |
44
+ | `empty-doc` / `partial-doc` | Proceed to Step 4 for codebase research |
34
45
  | `missing-config` | Create `.docguard.json` based on project type |
35
46
  | `stale-doc` | Update `docguard:last-reviewed` date and content |
36
47
  | `quality-issue` | Fix negation language, add missing sections |
48
+ | false positive | Suppress at the site: `// docguard:ignore <CODE>` (with a reason comment), and report it: `npx docguard-cli feedback` |
49
+
50
+ **Doc wrong vs code wrong:** a doc/code mismatch does not automatically mean
51
+ the doc is stale. Canonical docs are the spec — if the code drifted from a
52
+ documented decision, flag the code (or record the deviation with a
53
+ `// DRIFT: reason` comment + DRIFT-LOG.md entry) instead of silently rewriting
54
+ the doc to match the regression.
37
55
 
38
- ## Step 3: Write Real Content
56
+ ## Step 4: Write real content
39
57
 
40
58
  For each document that needs content:
41
59
 
@@ -50,12 +68,17 @@ Read the output carefully — it contains:
50
68
  - **WRITE THE DOCUMENT**: Expected structure and content for each section
51
69
 
52
70
  Execute the research steps, then write with REAL project content. No placeholders.
71
+ Never edit inside `<!-- docguard:section ... source=code -->` markers by hand —
72
+ those bodies are regenerated from code by `docguard sync --write`; pin them
73
+ (`pinned="reason"`) if a hand-maintained exception is genuinely needed.
53
74
 
54
- ## Step 4: Verify (Iterate up to 3 times)
75
+ ## Step 5: Verify (iterate up to 3 times)
55
76
 
56
77
  ```bash
57
78
  npx docguard-cli guard
58
79
  npx docguard-cli score
59
80
  ```
60
81
 
61
- All checks should pass. If any fail, read the output and fix remaining issues. Report the final CDD score.
82
+ All checks should pass. If any fail, read the output and fix remaining issues.
83
+ Report the final CDD score, plus anything you suppressed (with reasons) or
84
+ reported as a false positive.
@@ -13,41 +13,55 @@ handoffs:
13
13
 
14
14
  You are an AI agent enforcing Canonical-Driven Development (CDD) compliance using DocGuard.
15
15
 
16
- ## Step 1: Run Guard
16
+ ## Step 1: Run Guard (machine-readable)
17
17
 
18
18
  ```bash
19
- npx docguard-cli guard
19
+ npx docguard-cli guard --format json
20
20
  ```
21
21
 
22
- Read the output. It shows pass (✅), warn (⚠️), or fail (❌) for each of the validators:
22
+ Read the JSON contract do not parse prose:
23
23
 
24
- | Priority | Validators |
25
- |----------|-----------|
26
- | CRITICAL | Structure, Security, Test-Spec |
27
- | HIGH | Doc Sections, Drift-Comments, Changelog, Traceability, API-Surface |
28
- | MEDIUM | Freshness, Docs-Coverage, Doc-Quality, Metrics-Consistency |
29
- | LOW | TODO-Tracking, Schema-Sync, Spec-Kit, Metadata-Sync |
24
+ | Field | Meaning |
25
+ |-------|---------|
26
+ | `status` | `PASS` / `WARN` / `FAIL` (severity-aware; matches the exit code: 0/2/1) |
27
+ | `findings[]` | Structured issues: `{code, severity, confidence, message, location, suggestion}` |
28
+ | `nextStep` | The single suggested follow-up command (`null` on PASS) |
29
+ | `reportable[]` | Low-confidence findings (possible false positives) — verify before acting |
30
+ | `coverage` | Markdown tier map: `canonical / tracked / ignored / unclassified[]` |
31
+ | `semanticClaims.count` | Documented counts/limits/enums NOT yet verified against code |
32
+ | `validators[]` | Per-validator results, including `na` (nothing to validate ≠ pass) |
30
33
 
31
- ## Step 2: Handle Results
34
+ ## Step 2: Understand each finding before fixing
32
35
 
33
- ### If all checks pass:
34
- Report success and the score:
35
- ```bash
36
- npx docguard-cli score
37
- ```
36
+ - Every finding carries a stable code (e.g. `STR001`, `ENV003`, `XRF002`). Run
37
+ `npx docguard-cli explain <CODE>` for its contract, cause, and remediation.
38
+ - `confidence: "low"` means the scanner itself is unsure — verify against the
39
+ code before changing anything, and report real false positives with
40
+ `npx docguard-cli feedback`.
41
+ - A finding's `suggestion` may include a ready-to-run `command` or an inline
42
+ `pragma`. Prefer those over inventing your own fix.
38
43
 
39
- ### If checks fail:
40
- For each failing check, provide an **exact fix** — specific file, section, and content.
41
- Then run the fix workflow:
42
- ```bash
43
- npx docguard-cli fix --doc <name>
44
- ```
44
+ ## Step 3: Fix, suppress, or escalate
45
45
 
46
- Execute the research steps in the output, write real content, then re-run guard to verify.
46
+ 1. **Mechanical issues first**: `npx docguard-cli fix --write` applies safe,
47
+ provenance-checked fixes (broken anchors, stale counts/versions). Never
48
+ hand-edit what the tool can fix deterministically.
49
+ 2. **Prose/content issues**: follow the `/docguard.fix` workflow (research →
50
+ write real content).
51
+ 3. **Genuine false positives**: suppress at the finding site with the code —
52
+ `// docguard:ignore <CODE>` on (or above) the flagged line — or mark a whole
53
+ validator not-applicable in a doc:
54
+ `<!-- docguard:validator <key> n/a — reason -->`. Always include the reason.
55
+ Never suppress to silence a real issue.
56
+ 4. If `semanticClaims.count > 0`, offer to run `npx docguard-cli verify --semantic`
57
+ and check each extracted claim against the code — a green guard asserts
58
+ structure, not the truth of documented numbers.
47
59
 
48
- ## Step 3: Report
60
+ ## Step 4: Report
49
61
 
50
62
  Show the user:
51
- 1. Which checks passed/failed (with severity)
52
- 2. What was fixed
53
- 3. Final CDD score
63
+ 1. `status` and pass/total, plus anything in `coverage.unclassified` (docs no
64
+ validator watches suggest enrolling or ignoring them)
65
+ 2. Each finding fixed (by code), each suppressed (with reason), each reported
66
+ as a false positive
67
+ 3. Final score: `npx docguard-cli score`
@@ -21,21 +21,33 @@ npx docguard-cli init
21
21
 
22
22
  This creates the folder structure and template files. The templates are skeletons — they need real content.
23
23
 
24
- ## Step 2: Detect and Configure Project Type
24
+ ## Step 2: Pick the Right Profile
25
+
26
+ `init` auto-detects the project type, but verify the profile fits — it sets
27
+ which docs are required (a CLI shouldn't be forced to document an HTTP API):
28
+
29
+ | Signal | Profile in `.docguard.json` |
30
+ |--------|------------------------------|
31
+ | Has `bin` field / CLI tool | `"profile": "cli"` |
32
+ | Publishable package | `"profile": "library"` |
33
+ | Side project / prototype | `"profile": "starter"` |
34
+ | Team web app / API | `"profile": "standard"` (default) |
35
+ | Regulated / strict | `"profile": "enterprise"` |
36
+
37
+ Only schema-valid keys belong in `.docguard.json` — check
38
+ `schemas/docguard-config.schema.json` (shipped in the package) before adding
39
+ anything. If the project has domain collections (extractors, plugins, rules…),
40
+ declare them so documented counts are verified against code:
41
+ `"collections": { "extractors": "src/extractors/*.py" }`.
42
+
43
+ For an EXISTING codebase, prefer reverse-engineering over blank skeletons:
25
44
 
26
45
  ```bash
27
- cat package.json
46
+ npx docguard-cli generate --plan --write
28
47
  ```
29
48
 
30
- Create `.docguard.json` based on what you find:
31
-
32
- | Signal | Setting |
33
- |--------|---------|
34
- | Has `bin` field | `projectType: "cli"` |
35
- | Has react/next/vue | `projectType: "webapp"`, `needsE2E: true` |
36
- | Has express/fastify | `projectType: "api"`, `needsEnvVars: true` |
37
- | Has database deps | `needsDatabase: true` |
38
- | Default | `projectType: "library"` |
49
+ This pre-fills code-truth sections (routes, schemas, env vars) and leaves you
50
+ an agent-task list for the prose.
39
51
 
40
52
  ## Step 3: Write Real Documentation
41
53
 
@@ -22,8 +22,21 @@ npx docguard-cli score
22
22
  ```
23
23
 
24
24
  Read all output. Identify where documentation no longer matches the codebase.
25
+ Findings carry stable codes — `npx docguard-cli explain <CODE>` when unclear.
25
26
 
26
- ## Step 2: Semantic Analysis (Beyond CLI)
27
+ ## Step 2: Verify Documented Claims Against Code
28
+
29
+ ```bash
30
+ npx docguard-cli verify --semantic
31
+ ```
32
+
33
+ This extracts every checkable claim in the canonical docs — counts, limits,
34
+ rate numbers, retention windows, status enums — as a task list with the nearest
35
+ cited code path. **You perform each verification**: read the cited code, compare
36
+ the value, and report every mismatch with both values. This is the highest-value
37
+ review step; deterministic validators cannot judge these.
38
+
39
+ ## Step 3: Semantic Analysis (Beyond CLI)
27
40
 
28
41
  For each canonical doc, verify alignment with actual code:
29
42
 
@@ -35,16 +48,20 @@ For each canonical doc, verify alignment with actual code:
35
48
  | Test Coverage | Critical flows in TEST-SPEC.md have actual test files |
36
49
  | Terminology | Same concepts named consistently across all docs |
37
50
 
38
- ## Step 3: Update Stale Docs
51
+ ## Step 4: Update Stale Docs
39
52
 
40
53
  For each stale or drifted document:
41
- 1. Read the relevant source code files
42
- 2. Update the specific section that changed
43
- 3. Update the `docguard:last-reviewed` date to today
44
- 4. If the change is intentional drift, add an entry to DRIFT-LOG.md
45
- 5. Add entry to CHANGELOG.md under [Unreleased]
54
+ 1. **Decide which side is wrong first.** Canonical docs are the spec if the
55
+ code regressed from a documented decision, flag the code (or record a
56
+ `// DRIFT: reason` + DRIFT-LOG.md entry); don't rewrite the doc to match a
57
+ regression.
58
+ 2. Sections inside `<!-- docguard:section ... source=code -->` markers are
59
+ regenerated — run `npx docguard-cli sync --write` instead of editing by hand.
60
+ 3. For hand-maintained sections: read the relevant source, update the specific
61
+ section, refresh `docguard:last-reviewed` to today.
62
+ 4. Add entry to CHANGELOG.md under [Unreleased].
46
63
 
47
- ## Step 4: Verify
64
+ ## Step 5: Verify
48
65
 
49
66
  ```bash
50
67
  npx docguard-cli guard
@@ -16,11 +16,12 @@ You are an AI agent that updates documentation to reflect recent code changes.
16
16
  ## Step 1: Identify What Changed
17
17
 
18
18
  ```bash
19
+ npx docguard-cli diff --since HEAD~5
19
20
  git log --oneline -10
20
- git diff HEAD~5 --stat
21
21
  ```
22
22
 
23
- Read the recent commits. Understand what code changed and why.
23
+ `diff --since` maps the changed files directly to the canonical docs they
24
+ affect — read its output first; the git log supplies the "why".
24
25
 
25
26
  ## Step 2: Check Which Docs Are Affected
26
27
 
@@ -38,10 +39,19 @@ For each changed file, determine which canonical doc it affects:
38
39
 
39
40
  ## Step 3: Update Each Affected Doc
40
41
 
41
- For each affected document:
42
+ Mechanical layers first — they update marked sections and counts without AI
43
+ judgment:
44
+
45
+ ```bash
46
+ npx docguard-cli sync --write
47
+ npx docguard-cli fix --write
48
+ ```
49
+
50
+ Then, for each remaining affected document:
42
51
  1. Read the current document
43
52
  2. Read the relevant source code changes
44
- 3. Update the specific section that changed
53
+ 3. Update the specific section that changed (never hand-edit inside
54
+ `<!-- docguard:section ... source=code -->` markers — sync owns those)
45
55
  4. Update the `docguard:last-reviewed` date to today
46
56
  5. Add entry to CHANGELOG.md under [Unreleased]
47
57