docguard-cli 0.9.5 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +281 -203
  2. package/cli/validators/metrics-consistency.mjs +2 -1
  3. package/commands/docguard.fix.md +37 -17
  4. package/commands/docguard.guard.md +45 -12
  5. package/commands/docguard.review.md +37 -19
  6. package/commands/docguard.score.md +36 -17
  7. package/docs/installation.md +37 -19
  8. package/docs/quickstart.md +21 -6
  9. package/extensions/spec-kit-docguard/LICENSE +21 -0
  10. package/extensions/spec-kit-docguard/README.md +105 -0
  11. package/extensions/spec-kit-docguard/commands/diagnose.md +43 -0
  12. package/extensions/spec-kit-docguard/commands/generate.md +50 -0
  13. package/extensions/spec-kit-docguard/commands/guard.md +73 -0
  14. package/extensions/spec-kit-docguard/commands/init.md +38 -0
  15. package/extensions/spec-kit-docguard/commands/score.md +53 -0
  16. package/extensions/spec-kit-docguard/commands/trace.md +56 -0
  17. package/extensions/spec-kit-docguard/extension.yml +109 -0
  18. package/extensions/spec-kit-docguard/scripts/bash/common.sh +106 -0
  19. package/extensions/spec-kit-docguard/scripts/bash/docguard-check-docs.sh +153 -0
  20. package/extensions/spec-kit-docguard/scripts/bash/docguard-init-doc.sh +153 -0
  21. package/extensions/spec-kit-docguard/scripts/bash/docguard-suggest-fix.sh +107 -0
  22. package/extensions/spec-kit-docguard/skills/docguard-fix/SKILL.md +218 -0
  23. package/extensions/spec-kit-docguard/skills/docguard-guard/SKILL.md +167 -0
  24. package/extensions/spec-kit-docguard/skills/docguard-review/SKILL.md +182 -0
  25. package/extensions/spec-kit-docguard/skills/docguard-score/SKILL.md +178 -0
  26. package/extensions/spec-kit-docguard/templates/extensions.yml +39 -0
  27. package/package.json +2 -1
  28. package/templates/commands/docguard.fix.md +35 -39
  29. package/templates/commands/docguard.guard.md +26 -13
  30. package/templates/commands/docguard.init.md +35 -28
  31. package/templates/commands/docguard.review.md +33 -23
  32. package/templates/commands/docguard.update.md +15 -4
@@ -0,0 +1,50 @@
1
+ ---
2
+ description: "Reverse-engineer canonical documentation from existing codebase"
3
+ handoffs:
4
+ - label: Validate Generated Docs
5
+ agent: docguard.guard
6
+ prompt: Validate generated documentation passes all checks
7
+ - label: Review Quality
8
+ agent: docguard.review
9
+ prompt: Review quality of generated documentation
10
+ ---
11
+
12
+ # DocGuard Generate
13
+
14
+ Scans your codebase and generates canonical documentation: ARCHITECTURE.md, DATA-MODEL.md, TEST-SPEC.md, SECURITY.md, ENVIRONMENT.md, and API-REFERENCE.md.
15
+
16
+ ## User Input
17
+
18
+ $ARGUMENTS
19
+
20
+ ## Steps
21
+
22
+ 1. Run DocGuard generate on the current project:
23
+
24
+ ```bash
25
+ npx --yes docguard-cli@latest generate $ARGUMENTS
26
+ ```
27
+
28
+ 2. Review the generated docs in `docs-canonical/`. Each document includes:
29
+ - Structured sections based on industry standards
30
+ - Data extracted from your actual codebase (routes, schemas, configs)
31
+ - Standards citation footer referencing relevant specifications
32
+ - DocGuard metadata headers for freshness tracking
33
+
34
+ 3. Customize with `--doc <name>` to generate a specific document only.
35
+
36
+ ## Generated Documents
37
+
38
+ | Document | Source | Standard |
39
+ |----------|--------|----------|
40
+ | ARCHITECTURE.md | Routes, configs, dependencies | arc42 / C4 Model |
41
+ | DATA-MODEL.md | Schema files, type definitions | C4 Component / ER |
42
+ | TEST-SPEC.md | Test files, test configs | ISO/IEC/IEEE 29119-3 |
43
+ | SECURITY.md | Auth modules, .gitignore, secrets | OWASP ASVS v4.0 |
44
+ | ENVIRONMENT.md | .env files, Docker, CI/CD configs | 12-Factor App |
45
+ | API-REFERENCE.md | Route handlers, OpenAPI specs | OpenAPI 3.1 |
46
+
47
+ ## Flags
48
+
49
+ - `--doc <name>` — Generate a specific document only
50
+ - `--dir <path>` — Run on a different directory
@@ -0,0 +1,73 @@
1
+ ---
2
+ description: "Run 19-validator quality gate with severity triage and actionable remediation"
3
+ handoffs:
4
+ - label: Fix All Issues
5
+ agent: docguard.fix
6
+ prompt: Fix all documentation issues found by guard
7
+ - label: Deep Review
8
+ agent: docguard.review
9
+ prompt: Perform semantic cross-document consistency analysis
10
+ - label: Check Score
11
+ agent: docguard.score
12
+ prompt: Show CDD maturity score and improvement roadmap
13
+ ---
14
+
15
+ # DocGuard Guard
16
+
17
+ Validate your project against its canonical documentation. Runs 160+ automated checks across 19 validators.
18
+
19
+ ## User Input
20
+
21
+ ```text
22
+ $ARGUMENTS
23
+ ```
24
+
25
+ You **MUST** consider the user input before proceeding (if not empty).
26
+
27
+ ## Execution
28
+
29
+ 1. Run DocGuard guard validation:
30
+ ```bash
31
+ npx --yes docguard-cli@latest guard $ARGUMENTS
32
+ ```
33
+
34
+ 2. Parse each validator's result and build a severity-ranked findings table.
35
+
36
+ 3. **Triage by severity**:
37
+ - **CRITICAL**: Structure, Security, Test-Spec failures → fix immediately
38
+ - **HIGH**: Doc Sections, Drift, Changelog, Traceability → fix before commit
39
+ - **MEDIUM**: Freshness, Docs-Coverage, Doc-Quality, Metrics → fix this sprint
40
+ - **LOW**: TODO-Tracking, Schema-Sync, Spec-Kit, Metadata → fix when convenient
41
+
42
+ 4. For each failing check, provide an **exact fix** — specific file, section, and content.
43
+
44
+ 5. Re-run guard after fixes. Iterate until all checks pass (max 3 iterations).
45
+
46
+ ## Validators (19 total)
47
+
48
+ | Validator | What It Checks |
49
+ |-----------|---------------|
50
+ | Structure | Required CDD files exist |
51
+ | Doc Sections | Canonical docs have required sections |
52
+ | Docs-Sync | External doc references are valid |
53
+ | Drift | `// DRIFT:` comments have DRIFT-LOG entries |
54
+ | Changelog | CHANGELOG.md is maintained |
55
+ | Test-Spec | TEST-SPEC.md matches actual test files |
56
+ | Environment | Environment docs and .env.example exist |
57
+ | Security | No hardcoded secrets, .gitignore configured |
58
+ | Architecture | Layer boundaries and diagrams present |
59
+ | Freshness | Docs updated after recent code changes |
60
+ | Traceability | Canonical docs linked to source code |
61
+ | Docs-Diff | Entity/route/field drift between code and docs |
62
+ | Metadata-Sync | Metadata headers are consistent |
63
+ | Docs-Coverage | All config files documented |
64
+ | Doc-Quality | Readability, IEEE 830 compliance |
65
+ | TODO-Tracking | TODOs are tracked |
66
+ | Schema-Sync | Schema documentation matches code |
67
+ | Spec-Kit | Spec quality (FR-IDs, sections) |
68
+ | Metrics-Consistency | Internal counts are accurate |
69
+
70
+ ## Flags
71
+
72
+ - `--format json` — Output results as JSON
73
+ - `--dir <path>` — Run on a different directory
@@ -0,0 +1,38 @@
1
+ ---
2
+ description: "Initialize Canonical-Driven Development in a project"
3
+ handoffs:
4
+ - label: Generate Docs
5
+ agent: docguard.fix
6
+ prompt: Generate documentation content from codebase
7
+ - label: Check Status
8
+ agent: docguard.guard
9
+ prompt: Run guard to see initial status
10
+ ---
11
+
12
+ # DocGuard Init
13
+
14
+ Initialize CDD in your project. Creates the `docs-canonical/` directory, required files (CHANGELOG.md, DRIFT-LOG.md, AGENTS.md), and optionally sets a compliance profile.
15
+
16
+ ## User Input
17
+
18
+ $ARGUMENTS
19
+
20
+ ## Steps
21
+
22
+ 1. Run DocGuard init on the current project:
23
+
24
+ ```bash
25
+ npx --yes docguard-cli@latest init $ARGUMENTS
26
+ ```
27
+
28
+ 2. Choose a compliance profile:
29
+ - **starter** — Minimal CDD (architecture + changelog only)
30
+ - **standard** — Full CDD (all 5 canonical docs)
31
+ - **enterprise** — Strict CDD (all docs, all validators, freshness enforced)
32
+
33
+ 3. After init, run `speckit.docguard.generate` to populate the canonical docs with real data from your codebase.
34
+
35
+ ## Flags
36
+
37
+ - `--profile <name>` — Set compliance profile (starter, standard, enterprise)
38
+ - `--dir <path>` — Run on a different directory
@@ -0,0 +1,53 @@
1
+ ---
2
+ description: "Calculate CDD maturity score with multi-signal quality breakdown"
3
+ handoffs:
4
+ - label: Improve Score
5
+ agent: docguard.fix
6
+ prompt: Fix highest-ROI documentation issues to improve score
7
+ - label: Deep Review
8
+ agent: docguard.review
9
+ prompt: Perform semantic analysis for accuracy verification
10
+ ---
11
+
12
+ # DocGuard Score
13
+
14
+ Calculate your project's Canonical-Driven Development maturity score (0-100) across 8 weighted categories.
15
+
16
+ ## User Input
17
+
18
+ $ARGUMENTS
19
+
20
+ ## Steps
21
+
22
+ 1. Run DocGuard score on the current project:
23
+
24
+ ```bash
25
+ npx --yes docguard-cli@latest score $ARGUMENTS
26
+ ```
27
+
28
+ 2. Review the breakdown:
29
+ - **Structure** (25%) — required files present
30
+ - **Doc Quality** (20%) — docs have required sections
31
+ - **Testing** (15%) — test spec alignment
32
+ - **Security** (10%) — no hardcoded secrets
33
+ - **Environment** (10%) — env docs configured
34
+ - **Drift** (10%) — drift tracking discipline
35
+ - **Changelog** (5%) — changelog maintenance
36
+ - **Architecture** (5%) — layer boundary compliance
37
+
38
+ 3. For per-signal quality labels, add `--signals`.
39
+
40
+ ## Grading
41
+
42
+ | Score | Grade | Status |
43
+ |-------|-------|--------|
44
+ | 90-100 | A | Strong CDD compliance |
45
+ | 75-89 | B | Good, some gaps |
46
+ | 50-74 | C | Needs work |
47
+ | < 50 | D | Significant gaps |
48
+
49
+ ## Flags
50
+
51
+ - `--signals` — Show multi-signal CJE composite breakdown with quality labels
52
+ - `--tax` — Show estimated maintenance effort
53
+ - `--format json` — Output as JSON
@@ -0,0 +1,56 @@
1
+ ---
2
+ description: "Generate requirements traceability matrix"
3
+ handoffs:
4
+ - label: Fix Coverage Gaps
5
+ agent: docguard.fix
6
+ prompt: Fix traceability gaps found in the matrix
7
+ - label: Run Guard
8
+ agent: docguard.guard
9
+ prompt: Validate traceability checks pass
10
+ ---
11
+
12
+ # DocGuard Trace
13
+
14
+ Generate a requirements traceability matrix mapping canonical docs ↔ source code ↔ tests. Config-aware — respects `.docguard.json` exclusions and detects orphaned files.
15
+
16
+ ## User Input
17
+
18
+ $ARGUMENTS
19
+
20
+ ## Steps
21
+
22
+ 1. Run DocGuard trace on the current project:
23
+
24
+ ```bash
25
+ npx --yes docguard-cli@latest trace $ARGUMENTS
26
+ ```
27
+
28
+ 2. Review the matrix. Each canonical doc gets a coverage signal:
29
+ - **TRACED** — doc + source code + tests all linked
30
+ - **PARTIAL** — doc exists, source found, no test coverage
31
+ - **UNLINKED** — doc exists but no matching source code
32
+ - **MISSING** — doc not found
33
+
34
+ 3. Orphaned files (exist but excluded from config) are flagged with cleanup instructions.
35
+
36
+ ## Standards
37
+
38
+ Maps against industry standards per document type:
39
+
40
+ | Document | Standard |
41
+ |----------|----------|
42
+ | ARCHITECTURE.md | arc42 / C4 Model |
43
+ | DATA-MODEL.md | C4 Component / ER (Chen) |
44
+ | TEST-SPEC.md | ISO/IEC/IEEE 29119-3 |
45
+ | SECURITY.md | OWASP ASVS v4.0 |
46
+ | ENVIRONMENT.md | 12-Factor App |
47
+ | API-REFERENCE.md | OpenAPI 3.1 |
48
+
49
+ ## Flags
50
+
51
+ - `--format json` — Output as JSON
52
+ - `--dir <path>` — Run on a different directory
53
+
54
+ ## Research
55
+
56
+ Inspired by ISO/IEC/IEEE 29119 traceability requirements (Lopez et al., AITPG, IEEE TSE 2026).
@@ -0,0 +1,109 @@
1
+ schema_version: "1.0"
2
+
3
+ extension:
4
+ id: "docguard"
5
+ name: "DocGuard — CDD Enforcement"
6
+ version: "0.9.6"
7
+ description: "Canonical-Driven Development enforcement with enterprise-grade AI skills. 19 automated validators, structured research workflows, quality validation loops, and spec-kit integration hooks. Zero dependencies."
8
+ author: "Ricardo Accioly"
9
+ repository: "https://github.com/raccioly/docguard"
10
+ license: "MIT"
11
+ homepage: "https://www.npmjs.com/package/docguard-cli"
12
+
13
+ requires:
14
+ speckit_version: ">=0.1.0"
15
+ tools:
16
+ - name: "node"
17
+ required: true
18
+ version: ">=18.0.0"
19
+ - name: "npx"
20
+ required: true
21
+
22
+ provides:
23
+ commands:
24
+ - name: "docguard.guard"
25
+ file: "commands/guard.md"
26
+ description: "Run 19-validator quality gate with severity triage and remediation plan"
27
+ aliases: ["speckit.docguard.guard"]
28
+
29
+ - name: "docguard.fix"
30
+ file: "commands/fix.md"
31
+ description: "AI-driven documentation repair with codebase research and validation loops"
32
+ aliases: ["speckit.docguard.fix"]
33
+
34
+ - name: "docguard.review"
35
+ file: "commands/review.md"
36
+ description: "Cross-document semantic consistency analysis (read-only)"
37
+ aliases: ["speckit.docguard.review"]
38
+
39
+ - name: "docguard.score"
40
+ file: "commands/score.md"
41
+ description: "CDD maturity score with ROI-based improvement roadmap"
42
+ aliases: ["speckit.docguard.score"]
43
+
44
+ - name: "speckit.docguard.diagnose"
45
+ file: "commands/review.md"
46
+ description: "Diagnose all issues and generate a complete AI remediation plan"
47
+
48
+ - name: "speckit.docguard.generate"
49
+ file: "commands/fix.md"
50
+ description: "Reverse-engineer canonical docs from existing codebase"
51
+
52
+ skills:
53
+ - name: "docguard-guard"
54
+ path: "skills/docguard-guard/SKILL.md"
55
+ description: "19-validator quality gate with severity triage and structured reporting"
56
+
57
+ - name: "docguard-fix"
58
+ path: "skills/docguard-fix/SKILL.md"
59
+ description: "AI-driven documentation repair with research workflow and validation loops"
60
+
61
+ - name: "docguard-review"
62
+ path: "skills/docguard-review/SKILL.md"
63
+ description: "Cross-document semantic consistency analysis with quality scoring"
64
+
65
+ - name: "docguard-score"
66
+ path: "skills/docguard-score/SKILL.md"
67
+ description: "CDD maturity assessment with ROI-based improvement roadmap"
68
+
69
+ scripts:
70
+ - name: "docguard-check-docs"
71
+ path: "scripts/bash/docguard-check-docs.sh"
72
+ description: "Discover project docs, return JSON inventory with metadata"
73
+
74
+ - name: "docguard-suggest-fix"
75
+ path: "scripts/bash/docguard-suggest-fix.sh"
76
+ description: "Run guard, parse results, output prioritized fix suggestions"
77
+
78
+ - name: "docguard-init-doc"
79
+ path: "scripts/bash/docguard-init-doc.sh"
80
+ description: "Initialize a new canonical document with metadata header"
81
+
82
+ hooks:
83
+ after_implement:
84
+ command: "docguard.guard"
85
+ optional: false
86
+ prompt: "Run DocGuard validation after implementation"
87
+ description: "Mandatory quality gate — ensures docs stay in sync with code"
88
+
89
+ before_tasks:
90
+ command: "docguard.review"
91
+ optional: true
92
+ prompt: "Review documentation consistency before generating tasks?"
93
+
94
+ after_tasks:
95
+ command: "docguard.score"
96
+ optional: true
97
+ prompt: "Show CDD maturity score after task generation?"
98
+
99
+ tags:
100
+ - "documentation"
101
+ - "validation"
102
+ - "quality"
103
+ - "cdd"
104
+ - "spec-driven"
105
+ - "traceability"
106
+ - "ai-agents"
107
+ - "enforcement"
108
+ - "spec-kit"
109
+ - "skills"
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env bash
2
+ # DocGuard — Shared utilities for bash scripts
3
+ # Used by all DocGuard orchestration scripts
4
+
5
+ set -e
6
+
7
+ # ── Project Root Detection ─────────────────────────────────────────────────
8
+
9
+ find_docguard_root() {
10
+ local dir="${1:-$(pwd)}"
11
+ while [ "$dir" != "/" ]; do
12
+ # Check for DocGuard project markers
13
+ if [ -d "$dir/docs-canonical" ] || [ -f "$dir/.docguard.json" ] || [ -f "$dir/CHANGELOG.md" ]; then
14
+ echo "$dir"
15
+ return 0
16
+ fi
17
+ dir="$(dirname "$dir")"
18
+ done
19
+ return 1
20
+ }
21
+
22
+ # ── DocGuard CLI Detection ─────────────────────────────────────────────────
23
+
24
+ find_docguard_cli() {
25
+ local root="${1:-$(pwd)}"
26
+
27
+ # Check for local dev mode first
28
+ if [ -f "$root/cli/docguard.mjs" ]; then
29
+ echo "node $root/cli/docguard.mjs"
30
+ return 0
31
+ fi
32
+
33
+ # Check for global install
34
+ if command -v docguard-cli >/dev/null 2>&1; then
35
+ echo "docguard-cli"
36
+ return 0
37
+ fi
38
+
39
+ # Fall back to npx
40
+ if command -v npx >/dev/null 2>&1; then
41
+ echo "npx docguard-cli"
42
+ return 0
43
+ fi
44
+
45
+ return 1
46
+ }
47
+
48
+ # ── JSON Escape ────────────────────────────────────────────────────────────
49
+
50
+ json_escape() {
51
+ local s="$1"
52
+ s="${s//\\/\\\\}"
53
+ s="${s//\"/\\\"}"
54
+ s="${s//$'\n'/\\n}"
55
+ s="${s//$'\t'/\\t}"
56
+ s="${s//$'\r'/\\r}"
57
+ printf '%s' "$s"
58
+ }
59
+
60
+ # ── JSON Output Helper ────────────────────────────────────────────────────
61
+
62
+ json_output() {
63
+ # Build JSON from key=value pairs
64
+ # Usage: json_output key1 "value1" key2 "value2"
65
+ local result="{"
66
+ local first=true
67
+ while [ $# -ge 2 ]; do
68
+ if [ "$first" = true ]; then
69
+ first=false
70
+ else
71
+ result="$result,"
72
+ fi
73
+ result="$result\"$1\":\"$(json_escape "$2")\""
74
+ shift 2
75
+ done
76
+ result="$result}"
77
+ echo "$result"
78
+ }
79
+
80
+ # ── Date Helpers ───────────────────────────────────────────────────────────
81
+
82
+ today_iso() {
83
+ date +%Y-%m-%d
84
+ }
85
+
86
+ # ── File Helpers ───────────────────────────────────────────────────────────
87
+
88
+ file_exists() {
89
+ [ -f "$1" ]
90
+ }
91
+
92
+ dir_exists() {
93
+ [ -d "$1" ]
94
+ }
95
+
96
+ ensure_dir() {
97
+ mkdir -p "$1"
98
+ }
99
+
100
+ # ── Metadata Helpers ──────────────────────────────────────────────────────
101
+
102
+ extract_metadata() {
103
+ local file="$1"
104
+ local key="$2"
105
+ grep "docguard:${key}" "$file" 2>/dev/null | sed "s/.*docguard:${key} //" | sed 's/ -->//' | tr -d '\r'
106
+ }
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env bash
2
+ # DocGuard — Check project documentation status
3
+ # Returns JSON with document inventory and health status
4
+ #
5
+ # Usage:
6
+ # ./docguard-check-docs.sh [--json] [--verbose]
7
+ #
8
+ # JSON output fields:
9
+ # PROJECT_ROOT — absolute path to project root
10
+ # CLI_CMD — command to run DocGuard CLI
11
+ # DOCS — array of {name, path, exists, version, status, lastReviewed}
12
+ # SCORE — CDD maturity score (if --verbose)
13
+ # GUARD_PASS — number of passing guard checks (if --verbose)
14
+ # GUARD_TOTAL — total guard checks (if --verbose)
15
+
16
+ set -e
17
+
18
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19
+ source "$SCRIPT_DIR/common.sh"
20
+
21
+ JSON_MODE=false
22
+ VERBOSE=false
23
+
24
+ while [ $# -gt 0 ]; do
25
+ case "$1" in
26
+ --json) JSON_MODE=true ;;
27
+ --verbose) VERBOSE=true ;;
28
+ --help|-h)
29
+ echo "Usage: $0 [--json] [--verbose]"
30
+ echo ""
31
+ echo "Options:"
32
+ echo " --json Output in JSON format for AI consumption"
33
+ echo " --verbose Include score and guard results"
34
+ echo " --help Show this help message"
35
+ exit 0
36
+ ;;
37
+ *) echo "Unknown option: $1" >&2; exit 1 ;;
38
+ esac
39
+ shift
40
+ done
41
+
42
+ # Find project root
43
+ PROJECT_ROOT=$(find_docguard_root "$(pwd)") || {
44
+ echo "Error: No DocGuard project found. Run 'docguard init' first." >&2
45
+ exit 1
46
+ }
47
+
48
+ # Find CLI command
49
+ CLI_CMD=$(find_docguard_cli "$PROJECT_ROOT") || {
50
+ echo "Error: DocGuard CLI not found. Install with: npm i -g docguard-cli" >&2
51
+ exit 1
52
+ }
53
+
54
+ cd "$PROJECT_ROOT"
55
+
56
+ # Canonical documents to check
57
+ CANONICAL_DOCS=(
58
+ "docs-canonical/ARCHITECTURE.md"
59
+ "docs-canonical/DATA-MODEL.md"
60
+ "docs-canonical/SECURITY.md"
61
+ "docs-canonical/TEST-SPEC.md"
62
+ "docs-canonical/ENVIRONMENT.md"
63
+ "docs-canonical/REQUIREMENTS.md"
64
+ )
65
+
66
+ # Support documents
67
+ SUPPORT_DOCS=(
68
+ "CHANGELOG.md"
69
+ "DRIFT-LOG.md"
70
+ "AGENTS.md"
71
+ "README.md"
72
+ "ROADMAP.md"
73
+ )
74
+
75
+ if $JSON_MODE; then
76
+ # Build canonical docs JSON array
77
+ DOCS_JSON="["
78
+ first=true
79
+ for doc in "${CANONICAL_DOCS[@]}" "${SUPPORT_DOCS[@]}"; do
80
+ if [ "$first" = true ]; then first=false; else DOCS_JSON="$DOCS_JSON,"; fi
81
+
82
+ doc_name=$(basename "$doc" .md)
83
+ doc_path="$PROJECT_ROOT/$doc"
84
+ doc_exists="false"
85
+ doc_version=""
86
+ doc_status=""
87
+ doc_reviewed=""
88
+
89
+ if [ -f "$doc_path" ]; then
90
+ doc_exists="true"
91
+ doc_version=$(extract_metadata "$doc_path" "version" 2>/dev/null || echo "")
92
+ doc_status=$(extract_metadata "$doc_path" "status" 2>/dev/null || echo "")
93
+ doc_reviewed=$(extract_metadata "$doc_path" "last-reviewed" 2>/dev/null || echo "")
94
+ fi
95
+
96
+ DOCS_JSON="$DOCS_JSON{\"name\":\"$(json_escape "$doc_name")\",\"path\":\"$(json_escape "$doc")\",\"exists\":$doc_exists"
97
+ [ -n "$doc_version" ] && DOCS_JSON="$DOCS_JSON,\"version\":\"$(json_escape "$doc_version")\""
98
+ [ -n "$doc_status" ] && DOCS_JSON="$DOCS_JSON,\"status\":\"$(json_escape "$doc_status")\""
99
+ [ -n "$doc_reviewed" ] && DOCS_JSON="$DOCS_JSON,\"lastReviewed\":\"$(json_escape "$doc_reviewed")\""
100
+ DOCS_JSON="$DOCS_JSON}"
101
+ done
102
+ DOCS_JSON="$DOCS_JSON]"
103
+
104
+ # Optionally include score and guard
105
+ EXTRAS=""
106
+ if $VERBOSE; then
107
+ SCORE_OUTPUT=$(eval $CLI_CMD score --format json 2>/dev/null || echo "")
108
+ GUARD_OUTPUT=$(eval $CLI_CMD guard 2>&1 || true)
109
+
110
+ # Extract score
111
+ SCORE=$(echo "$SCORE_OUTPUT" | grep -o '"total":[0-9]*' | head -1 | sed 's/"total"://' || echo "0")
112
+
113
+ # Extract guard pass/total from output like "156/160 passed"
114
+ GUARD_PASS=$(echo "$GUARD_OUTPUT" | grep -o '[0-9]*/[0-9]* passed' | sed 's|/.*||' || echo "0")
115
+ GUARD_TOTAL=$(echo "$GUARD_OUTPUT" | grep -o '[0-9]*/[0-9]* passed' | sed 's|.*/||; s| .*||' || echo "0")
116
+
117
+ EXTRAS=",\"score\":$SCORE,\"guardPass\":$GUARD_PASS,\"guardTotal\":$GUARD_TOTAL"
118
+ fi
119
+
120
+ # Check for spec-kit
121
+ HAS_SPECKIT="false"
122
+ [ -d "$PROJECT_ROOT/.specify" ] && HAS_SPECKIT="true"
123
+
124
+ echo "{\"projectRoot\":\"$(json_escape "$PROJECT_ROOT")\",\"cliCommand\":\"$(json_escape "$CLI_CMD")\",\"hasSpecKit\":$HAS_SPECKIT,\"docs\":$DOCS_JSON$EXTRAS}"
125
+ else
126
+ echo "DocGuard Project: $PROJECT_ROOT"
127
+ echo "CLI: $CLI_CMD"
128
+ echo ""
129
+ echo "Canonical Documents:"
130
+ for doc in "${CANONICAL_DOCS[@]}"; do
131
+ if [ -f "$PROJECT_ROOT/$doc" ]; then
132
+ version=$(extract_metadata "$PROJECT_ROOT/$doc" "version" 2>/dev/null || echo "?")
133
+ reviewed=$(extract_metadata "$PROJECT_ROOT/$doc" "last-reviewed" 2>/dev/null || echo "?")
134
+ echo " ✅ $doc (v$version, reviewed: $reviewed)"
135
+ else
136
+ echo " ❌ $doc (MISSING)"
137
+ fi
138
+ done
139
+ echo ""
140
+ echo "Support Documents:"
141
+ for doc in "${SUPPORT_DOCS[@]}"; do
142
+ if [ -f "$PROJECT_ROOT/$doc" ]; then
143
+ echo " ✅ $doc"
144
+ else
145
+ echo " ❌ $doc (MISSING)"
146
+ fi
147
+ done
148
+
149
+ if $VERBOSE; then
150
+ echo ""
151
+ eval $CLI_CMD score 2>&1 || true
152
+ fi
153
+ fi