docguard-cli 0.5.1

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 (57) hide show
  1. package/LICENSE +21 -0
  2. package/PHILOSOPHY.md +150 -0
  3. package/README.md +309 -0
  4. package/STANDARD.md +751 -0
  5. package/cli/commands/agents.mjs +221 -0
  6. package/cli/commands/audit.mjs +92 -0
  7. package/cli/commands/badge.mjs +72 -0
  8. package/cli/commands/ci.mjs +80 -0
  9. package/cli/commands/diagnose.mjs +273 -0
  10. package/cli/commands/diff.mjs +360 -0
  11. package/cli/commands/fix.mjs +610 -0
  12. package/cli/commands/generate.mjs +842 -0
  13. package/cli/commands/guard.mjs +158 -0
  14. package/cli/commands/hooks.mjs +227 -0
  15. package/cli/commands/init.mjs +249 -0
  16. package/cli/commands/score.mjs +396 -0
  17. package/cli/commands/watch.mjs +143 -0
  18. package/cli/docguard.mjs +458 -0
  19. package/cli/validators/architecture.mjs +380 -0
  20. package/cli/validators/changelog.mjs +39 -0
  21. package/cli/validators/docs-sync.mjs +110 -0
  22. package/cli/validators/drift.mjs +101 -0
  23. package/cli/validators/environment.mjs +70 -0
  24. package/cli/validators/freshness.mjs +224 -0
  25. package/cli/validators/security.mjs +101 -0
  26. package/cli/validators/structure.mjs +88 -0
  27. package/cli/validators/test-spec.mjs +115 -0
  28. package/docs/ai-integration.md +179 -0
  29. package/docs/commands.md +239 -0
  30. package/docs/configuration.md +96 -0
  31. package/docs/faq.md +155 -0
  32. package/docs/installation.md +81 -0
  33. package/docs/profiles.md +103 -0
  34. package/docs/quickstart.md +79 -0
  35. package/package.json +57 -0
  36. package/templates/ADR.md.template +64 -0
  37. package/templates/AGENTS.md.template +88 -0
  38. package/templates/ARCHITECTURE.md.template +78 -0
  39. package/templates/CHANGELOG.md.template +16 -0
  40. package/templates/CURRENT-STATE.md.template +64 -0
  41. package/templates/DATA-MODEL.md.template +66 -0
  42. package/templates/DEPLOYMENT.md.template +66 -0
  43. package/templates/DRIFT-LOG.md.template +18 -0
  44. package/templates/ENVIRONMENT.md.template +43 -0
  45. package/templates/KNOWN-GOTCHAS.md.template +69 -0
  46. package/templates/ROADMAP.md.template +82 -0
  47. package/templates/RUNBOOKS.md.template +115 -0
  48. package/templates/SECURITY.md.template +42 -0
  49. package/templates/TEST-SPEC.md.template +55 -0
  50. package/templates/TROUBLESHOOTING.md.template +96 -0
  51. package/templates/VENDOR-BUGS.md.template +74 -0
  52. package/templates/ci/github-actions.yml +39 -0
  53. package/templates/commands/docguard.fix.md +65 -0
  54. package/templates/commands/docguard.guard.md +40 -0
  55. package/templates/commands/docguard.init.md +62 -0
  56. package/templates/commands/docguard.review.md +44 -0
  57. package/templates/commands/docguard.update.md +44 -0
package/STANDARD.md ADDED
@@ -0,0 +1,751 @@
1
+ # DocGuard Standard v0.1
2
+
3
+ > **The open specification for Canonical-Driven Development.**
4
+ > Document first. Any agent understands. Machine-enforceable.
5
+
6
+ ---
7
+
8
+ ## 1. Purpose
9
+
10
+ This standard defines **Canonical-Driven Development (CDD)** — a full-lifecycle methodology for building and maintaining software projects where documentation IS the source of truth, not an afterthought.
11
+
12
+ It provides a **universal, language-agnostic documentation structure** that makes any software project fully understandable by AI coding agents (Claude, Gemini, Copilot, Cursor, Kiro, and future agents) while keeping documentation useful for human developers.
13
+
14
+ **DocGuard** is the CLI tool that enforces this standard — auditing, generating, and guarding project documentation.
15
+
16
+ ---
17
+
18
+ ## 2. Canonical-Driven Development (CDD)
19
+
20
+ ### 2.1 What Is CDD?
21
+
22
+ Canonical-Driven Development is a methodology where **canonical documentation drives every phase of a project** — from initial design through ongoing maintenance. Unlike traditional development where docs are written after code (and quickly rot), CDD treats documentation as the authoritative source that code must conform to.
23
+
24
+ > **Canonical** (adj.): accepted as being accurate and authoritative; the standard form.
25
+
26
+ ### 2.2 CDD vs Other Methodologies
27
+
28
+ | Methodology | Core Idea | Limitation |
29
+ |-------------|-----------|------------|
30
+ | **TDD** (Test-Driven) | Write tests first, then code | Only covers correctness, not architecture or design intent |
31
+ | **BDD** (Behavior-Driven) | Write behaviors first, then code | Only covers user-facing behavior, not system internals |
32
+ | **SDD** (Spec-Driven) | Write specs first, then generate code | Stops after code generation — no ongoing governance |
33
+ | **DDD** (Domain-Driven) | Model the domain first | Focuses on domain modeling, not documentation lifecycle |
34
+ | **CDD** (Canonical-Driven) | **Write canonical docs first, code conforms, drift is tracked forever** | — |
35
+
36
+ ### 2.3 CDD Lifecycle
37
+
38
+ CDD is not a phase — it's the entire lifecycle:
39
+
40
+ ```
41
+ ┌─────────────────────────────────────────────────────────────────┐
42
+ │ Canonical-Driven Development │
43
+ │ │
44
+ │ Phase 1: DEFINE Phase 2: BUILD │
45
+ │ ┌─────────────────┐ ┌─────────────────┐ │
46
+ │ │ Write canonical │ → │ Implement from │ │
47
+ │ │ docs (design │ │ canonical docs │ │
48
+ │ │ intent) │ │ (SDD lives here) │ │
49
+ │ └─────────────────┘ └────────┬────────┘ │
50
+ │ │ │
51
+ │ Phase 3: GUARD Phase 4: EVOLVE │
52
+ │ ┌─────────────────┐ ┌─────────────────┐ │
53
+ │ │ Validate code │ ← │ Update canonical │ │
54
+ │ │ matches docs │ → │ docs, log drift, │ │
55
+ │ │ (DocGuard) │ │ track changes │ │
56
+ │ └─────────────────┘ └─────────────────┘ │
57
+ │ │
58
+ │ ↺ Continuous — Phases 2-4 repeat for every change │
59
+ └─────────────────────────────────────────────────────────────────┘
60
+ ```
61
+
62
+ **SDD (Spec-Driven Development) is Phase 1-2.** CDD adds Phase 3-4 and loops forever.
63
+
64
+ ### 2.4 The Two-Tier Documentation Model
65
+
66
+ | Tier | Location | Purpose | Editing Rules |
67
+ |------|----------|---------|---------------|
68
+ | **Canonical** | `docs-canonical/` | Design intent — the "blueprint" | READ-ONLY during implementation. Only updated through deliberate design changes. |
69
+ | **Implementation** | `docs-implementation/` | Current state — what's actually built | Living documents, updated as code changes. |
70
+
71
+ When code must deviate from canonical docs:
72
+ 1. Add `// DRIFT: reason` inline comment in the code
73
+ 2. Log the deviation in `DRIFT-LOG.md`
74
+ 3. Never silently deviate — all drift is conscious and documented
75
+
76
+ ### 2.5 DocGuard: The CDD Enforcement Tool
77
+
78
+ | Mode | Command | What It Does |
79
+ |------|---------|-------------|
80
+ | **🔍 Audit** | `docguard audit` | Scan a project, report what documentation exists or is missing |
81
+ | **🏗️ Generate** | `docguard generate` | Analyze a codebase, auto-create canonical documentation |
82
+ | **✅ Guard** | `docguard guard` | Validate that code stays aligned with its documentation |
83
+
84
+ ---
85
+
86
+ ## 3. Design Principles
87
+
88
+ 1. **Markdown-native** — All documentation is plain markdown. No proprietary formats. Any tool, any editor, any agent can read it.
89
+
90
+ 2. **Language-agnostic** — Works for JavaScript, Python, Java, Go, Rust, Swift, Kotlin, or any language that uses files. Validation is file-system-based, not syntax-based.
91
+
92
+ 3. **Agent-agnostic** — Not tied to any specific AI agent or IDE. Works with Claude Code, Gemini CLI, GitHub Copilot, Cursor, Windsurf, Kiro, or any future agent.
93
+
94
+ 4. **Progressive adoption** — Projects can adopt one piece at a time. Start with `ARCHITECTURE.md`, add more as needed. No all-or-nothing requirement.
95
+
96
+ 5. **Documentation-first** — Canonical docs should be written BEFORE or ALONGSIDE code, not after. When starting a new project, write the docs first. When adopting CDD on an existing project, generate docs from the codebase.
97
+
98
+ 6. **Drift-aware** — Code will sometimes deviate from specs. Instead of pretending it doesn't, this standard provides a structured way to document and track deviations.
99
+
100
+ 7. **Enterprise-grade** — Designed for real production systems, not toy projects. Supports compliance, audit trails, and architectural governance.
101
+
102
+ ---
103
+
104
+ ## 4. File Structure
105
+
106
+ ### 4.1 Required Files (Core)
107
+
108
+ Every CDD-compliant project MUST have these files:
109
+
110
+ ```
111
+ project-root/
112
+ ├── docs-canonical/ # Design intent (the "blueprint")
113
+ │ ├── ARCHITECTURE.md # System design, components, boundaries
114
+ │ ├── DATA-MODEL.md # Database/storage schemas, entity relationships
115
+ │ ├── SECURITY.md # Auth, permissions, secrets, threat model
116
+ │ ├── TEST-SPEC.md # Required tests, coverage rules, test mapping
117
+ │ └── ENVIRONMENT.md # Environment variables, config, setup requirements
118
+
119
+ ├── AGENTS.md # Agent behavior rules (or CLAUDE.md)
120
+ ├── CHANGELOG.md # Change tracking (Keep-a-Changelog format)
121
+ └── DRIFT-LOG.md # Documented deviations from canonical docs
122
+ ```
123
+
124
+ ### 4.2 Recommended Files (Optional)
125
+
126
+ These files add depth but are not required for compliance. Adopt as needed for your project type.
127
+
128
+ ```
129
+ project-root/
130
+ ├── docs-canonical/ # Extended canonical docs
131
+ │ ├── FEATURES.md # Feature inventory, status, roadmap
132
+ │ ├── MESSAGE-FLOWS.md # API sequences, event flows, integrations
133
+ │ ├── DEPLOYMENT.md # Infrastructure, environments, CI/CD pipelines
134
+ │ ├── ADR.md # Architecture Decision Records (why decisions were made)
135
+ │ ├── ERROR-CODES.md # Error codes reference, categories, handling patterns
136
+ │ └── API-REFERENCE.md # API surface documentation (or link to OpenAPI spec)
137
+
138
+ ├── docs-implementation/ # Current-state docs (living, editable)
139
+ │ ├── CURRENT-STATE.md # What's actually deployed now
140
+ │ ├── TROUBLESHOOTING.md # Known issues, common fixes
141
+ │ ├── RUNBOOKS.md # Operational procedures
142
+ │ └── MIGRATION-GUIDE.md # Breaking change guides between versions
143
+
144
+ ├── AGENT-REFERENCE.md # Lookup tables: "when X changes, update Y"
145
+ ├── CONTRIBUTING.md # How to contribute (human & AI contributors)
146
+ └── README.md # Project overview (universal, not DocGuard-specific)
147
+ ```
148
+
149
+ > [!NOTE]
150
+ > **Project type determines relevance.** A CLI tool may skip `DATA-MODEL.md`. A frontend may have a thin `SECURITY.md`. Use `.docguard.json` to configure which files are required for YOUR project.
151
+
152
+ ### 4.3 Configuration
153
+
154
+ ```
155
+ project-root/
156
+ └── .docguard.json # Project-specific config (overrides defaults)
157
+ ```
158
+
159
+ ---
160
+
161
+ ## 5. File Format Specifications
162
+
163
+ ### 5.1 ARCHITECTURE.md
164
+
165
+ Describes the system's design: components, layers, boundaries, and how they interact.
166
+
167
+ **Required sections:**
168
+
169
+ ```markdown
170
+ # Architecture
171
+
172
+ ## System Overview
173
+ <!-- One-paragraph description of what this system does -->
174
+
175
+ ## Component Map
176
+ <!-- List of major components/modules and their responsibilities -->
177
+ | Component | Responsibility | Location |
178
+ |-----------|---------------|----------|
179
+ | API Server | Handles HTTP requests | src/server/ |
180
+ | Auth Module | Authentication & authorization | src/auth/ |
181
+ | Data Layer | Database access & caching | src/data/ |
182
+
183
+ ## Layer Boundaries
184
+ <!-- Which layers can import from which -->
185
+ | Layer | Can Import From | Cannot Import From |
186
+ |-------|----------------|-------------------|
187
+ | Handlers/Controllers | Services, Middleware | Repositories, Database |
188
+ | Services | Repositories, Utils | Handlers, Controllers |
189
+ | Repositories | Models, Utils | Services, Handlers |
190
+
191
+ ## Tech Stack
192
+ <!-- Languages, frameworks, databases, infrastructure -->
193
+ | Category | Technology | Version |
194
+ |----------|-----------|---------|
195
+ | Runtime | Node.js | 20.x |
196
+ | Framework | Next.js | 16.x |
197
+ | Database | DynamoDB | — |
198
+ | Auth | NextAuth | 5.x |
199
+
200
+ ## Diagrams
201
+ <!-- Architecture diagrams using Mermaid or linked images -->
202
+ ```
203
+
204
+ **Validator checks:**
205
+ - File exists in `docs-canonical/`
206
+ - Contains `## System Overview` section
207
+ - Contains `## Component Map` section
208
+ - Contains `## Tech Stack` section
209
+
210
+ ---
211
+
212
+ ### 5.2 DATA-MODEL.md
213
+
214
+ Describes the data structures: tables, schemas, entities, and their relationships.
215
+
216
+ **Required sections:**
217
+
218
+ ```markdown
219
+ # Data Model
220
+
221
+ ## Entities
222
+ <!-- List all data entities/tables/collections -->
223
+ | Entity | Storage | Primary Key | Description |
224
+ |--------|---------|-------------|-------------|
225
+ | User | users table | userId (UUID) | Registered users |
226
+ | Order | orders table | orderId (ULID) | Purchase orders |
227
+
228
+ ## Schema Definitions
229
+ <!-- For each entity, define fields -->
230
+ ### User
231
+ | Field | Type | Required | Description |
232
+ |-------|------|----------|-------------|
233
+ | userId | UUID | Yes | Unique identifier |
234
+ | email | String | Yes | User email (unique) |
235
+ | role | Enum | Yes | admin, user, viewer |
236
+ | createdAt | ISO DateTime | Yes | Account creation time |
237
+
238
+ ## Relationships
239
+ <!-- How entities relate to each other -->
240
+ | From | To | Type | Description |
241
+ |------|-----|------|-------------|
242
+ | User | Order | 1:many | A user can have many orders |
243
+
244
+ ## Indexes
245
+ <!-- Database indexes for query performance -->
246
+ | Table | Index Name | Fields | Purpose |
247
+ |-------|-----------|--------|---------|
248
+ | users | email-index | email | Lookup by email |
249
+ ```
250
+
251
+ **Validator checks:**
252
+ - File exists in `docs-canonical/`
253
+ - Contains `## Entities` section
254
+ - Contains at least one entity definition
255
+
256
+ ---
257
+
258
+ ### 5.3 SECURITY.md
259
+
260
+ Describes the security model: authentication, authorization, secrets handling, and known threats.
261
+
262
+ **Required sections:**
263
+
264
+ ```markdown
265
+ # Security
266
+
267
+ ## Authentication
268
+ <!-- How users/agents authenticate -->
269
+ | Method | Implementation | Details |
270
+ |--------|---------------|---------|
271
+ | JWT | RS256 tokens | Issued by auth service, 15min expiry |
272
+ | API Key | Header-based | For service-to-service calls |
273
+
274
+ ## Authorization
275
+ <!-- Role-based or permission-based access control -->
276
+ | Role | Permissions | Scope |
277
+ |------|------------|-------|
278
+ | admin | read, write, delete, manage-users | All resources |
279
+ | user | read, write own | Own resources only |
280
+
281
+ ## Secrets Management
282
+ <!-- Where secrets are stored, how they're accessed -->
283
+ | Secret | Storage | Access Pattern |
284
+ |--------|---------|---------------|
285
+ | DB credentials | AWS Secrets Manager | Loaded at startup |
286
+ | JWT signing key | Environment variable | Injected by CI/CD |
287
+
288
+ ## Security Rules
289
+ <!-- Explicit rules for code to follow -->
290
+ - All API routes MUST require authentication except: /health, /public/*
291
+ - Secrets MUST NOT appear in code, logs, or error messages
292
+ - All user input MUST be validated before processing
293
+ - PII (email, phone) MUST be masked in logs
294
+ ```
295
+
296
+ **Validator checks:**
297
+ - File exists in `docs-canonical/`
298
+ - Contains `## Authentication` section
299
+ - Contains `## Secrets Management` section
300
+
301
+ ---
302
+
303
+ ### 5.4 TEST-SPEC.md
304
+
305
+ Declares what tests MUST exist, organized by category. This is the file that no other standard provides.
306
+
307
+ **Required sections:**
308
+
309
+ ```markdown
310
+ # Test Specification
311
+
312
+ ## Test Categories
313
+ <!-- Which test types this project requires -->
314
+ | Category | Required | Applies To | Suggested Tools |
315
+ |----------|----------|-----------|-----------------|
316
+ | Unit | ✅ Yes | Services, utilities, helpers | jest, vitest, pytest, junit |
317
+ | Integration | ✅ Yes | API routes, DB operations | supertest, httpx, testcontainers |
318
+ | E2E | ✅ Yes | Critical user journeys | playwright, cypress, detox |
319
+ | Canary | ✅ Yes | Health checks, smoke tests | custom scripts |
320
+ | Load | ⚠️ Optional | High-traffic endpoints | k6, artillery, locust |
321
+ | Security | ⚠️ Optional | Auth flows, input validation | OWASP ZAP, custom |
322
+ | Contract | ⚠️ Optional | Public-facing APIs | pact, dredd |
323
+
324
+ ## Coverage Rules
325
+ <!-- Glob patterns defining what must have tests -->
326
+ | Source Pattern | Required Test Pattern | Category |
327
+ |---------------|----------------------|----------|
328
+ | src/services/**/*.ts | tests/unit/**/*.test.ts | Unit |
329
+ | src/routes/**/*.ts | tests/integration/**/*.test.ts | Integration |
330
+ | src/app/api/**/*.ts | tests/integration/**/*.test.ts | Integration |
331
+
332
+ ## Service-to-Test Map
333
+ <!-- Specific mapping of source files to test files -->
334
+ | Source File | Unit Test | Integration Test | Status |
335
+ |------------|-----------|-----------------|--------|
336
+ | src/services/authService.ts | auth.test.ts | auth.integration.ts | ✅ |
337
+ | src/services/paymentService.ts | payment.test.ts | — | ⚠️ Missing |
338
+
339
+ ## Critical User Journeys (E2E Required)
340
+ <!-- Each journey MUST have a matching E2E test -->
341
+ | # | Journey Description | Test File | Status |
342
+ |---|-------------------|-----------|--------|
343
+ | 1 | Login → Dashboard → View Data | e2e/login-flow.spec.ts | ✅ |
344
+ | 2 | Signup → Email Verify → First Login | e2e/signup-flow.spec.ts | ❌ Missing |
345
+
346
+ ## Canary Tests (Pre-Deploy Gates)
347
+ <!-- Tests that MUST pass before any deployment -->
348
+ | Canary | What It Checks | File |
349
+ |--------|---------------|------|
350
+ | Health | /health returns 200 | canary/health.test.ts |
351
+ | Auth | Login flow works | canary/auth.test.ts |
352
+ | DB | Primary table is accessible | canary/db.test.ts |
353
+ ```
354
+
355
+ **Validator checks:**
356
+ - File exists in `docs-canonical/`
357
+ - Contains `## Test Categories` section
358
+ - Contains `## Coverage Rules` section
359
+ - For each coverage rule: matching test files exist (glob check)
360
+ - For each critical journey marked required: test file exists
361
+ - For each canary test: test file exists
362
+
363
+ ---
364
+
365
+ ### 5.5 ENVIRONMENT.md
366
+
367
+ Documents all environment variables, configuration files, and setup requirements needed to run the project.
368
+
369
+ **Required sections:**
370
+
371
+ ```markdown
372
+ # Environment & Configuration
373
+
374
+ ## Prerequisites
375
+ <!-- Runtime, tools, and accounts needed -->
376
+ | Requirement | Version | Purpose |
377
+ |------------|---------|----------|
378
+ | Node.js | 20.x+ | Runtime |
379
+ | Docker | 24.x+ | Local database |
380
+ | AWS CLI | 2.x | Cloud deployment |
381
+
382
+ ## Environment Variables
383
+ <!-- All env vars the project needs -->
384
+ | Variable | Required | Default | Description | Where to Get |
385
+ |----------|----------|---------|-------------|-------------|
386
+ | DATABASE_URL | ✅ Yes | — | Database connection string | AWS Console → RDS |
387
+ | JWT_SECRET | ✅ Yes | — | Token signing key | Generate: openssl rand -hex 32 |
388
+ | API_PORT | ❌ No | 3000 | Server port | — |
389
+ | LOG_LEVEL | ❌ No | info | Logging verbosity | — |
390
+
391
+ ## Configuration Files
392
+ <!-- Config files and their purpose -->
393
+ | File | Purpose | Template |
394
+ |------|---------|----------|
395
+ | .env.local | Local development secrets | .env.example |
396
+ | docker-compose.yml | Local infrastructure | Committed |
397
+
398
+ ## Setup Steps
399
+ <!-- How to go from zero to running -->
400
+ 1. Clone the repository
401
+ 2. Copy `.env.example` to `.env.local`
402
+ 3. Fill in required values (see table above)
403
+ 4. Run `docker compose up -d` (starts local DB)
404
+ 5. Run `npm install`
405
+ 6. Run `npm run dev`
406
+ ```
407
+
408
+ **Validator checks:**
409
+ - File exists in `docs-canonical/`
410
+ - Contains `## Environment Variables` section
411
+ - Contains `## Setup Steps` section
412
+ - If `.env.example` is referenced, it must exist
413
+
414
+ ---
415
+
416
+ ### 5.6 AGENTS.md
417
+
418
+ Defines behavior rules for AI coding agents working with this project. Compatible with the [AGENTS.md standard](https://agents.md).
419
+
420
+ **Required sections:**
421
+
422
+ ```markdown
423
+ # Agent Instructions
424
+
425
+ ## Project Overview
426
+ <!-- What this project is, in 2-3 sentences -->
427
+
428
+ ## Build & Dev Commands
429
+ <!-- How to install, build, run, test -->
430
+ | Command | Purpose |
431
+ |---------|---------|
432
+ | npm install | Install dependencies |
433
+ | npm run dev | Start development server |
434
+ | npm test | Run unit tests |
435
+ | npm run test:e2e | Run E2E tests |
436
+
437
+ ## Workflow Rules
438
+ <!-- How agents should approach changes -->
439
+ 1. **Research first** — Check docs-canonical/ before suggesting changes
440
+ 2. **Confirm before implementing** — Show a plan before writing code
441
+ 3. **Match existing patterns** — Search codebase for similar implementations
442
+ 4. **Document drift** — If deviating from canonical docs, add `// DRIFT: reason`
443
+ 5. **Update changelog** — All changes need a CHANGELOG.md entry
444
+
445
+ ## Code Conventions
446
+ <!-- Project-specific style rules -->
447
+ - Use TypeScript strict mode
448
+ - Use named exports (no default exports)
449
+ - Error handling: use Result pattern, no thrown exceptions
450
+ - Logging: use structured logger, never console.log
451
+
452
+ ## File Change Rules
453
+ <!-- What requires approval -->
454
+ - Changes to >3 files require explicit approval
455
+ - Schema changes require ADR entry
456
+ - Dependency additions require justification
457
+ ```
458
+
459
+ **Validator checks:**
460
+ - `AGENTS.md` OR `CLAUDE.md` exists at project root
461
+ - Contains `## Build & Dev Commands` section
462
+ - Contains at least one build/test command
463
+
464
+ ---
465
+
466
+ ### 5.7 CHANGELOG.md
467
+
468
+ Tracks all project changes. Follows [Keep a Changelog](https://keepachangelog.com/) format.
469
+
470
+ **Required format:**
471
+
472
+ ```markdown
473
+ # Changelog
474
+
475
+ All notable changes to this project will be documented in this file.
476
+
477
+ ## [Unreleased]
478
+
479
+ ### Added
480
+ - New feature description
481
+
482
+ ### Changed
483
+ - Modified behavior description
484
+
485
+ ### Fixed
486
+ - Bug fix description
487
+
488
+ ### Removed
489
+ - Removed feature description
490
+
491
+ ## [1.0.0] - 2026-03-01
492
+
493
+ ### Added
494
+ - Initial release
495
+ ```
496
+
497
+ **Validator checks:**
498
+ - File exists at project root
499
+ - Contains `## [Unreleased]` section
500
+ - When git-staged files exist, `CHANGELOG.md` should also be staged (warning)
501
+
502
+ ---
503
+
504
+ ### 5.8 DRIFT-LOG.md
505
+
506
+ Documents conscious deviations from canonical docs. Every `// DRIFT: reason` comment in code MUST have a matching entry here.
507
+
508
+ **Required format:**
509
+
510
+ ```markdown
511
+ # Drift Log
512
+
513
+ Documented deviations from canonical specifications.
514
+
515
+ ## Active Drift
516
+
517
+ | ID | File | Line | Canonical Doc | Deviation | Reason | Date |
518
+ |----|------|------|--------------|-----------|--------|------|
519
+ | D-001 | src/auth/jwt.ts | 42 | SECURITY.md | Using HS256 instead of RS256 | Legacy compatibility, migrating in Q2 | 2026-03-01 |
520
+ | D-002 | src/api/users.ts | 18 | ARCHITECTURE.md | Direct DB call from handler | Performance optimization, approved in ADR-005 | 2026-03-10 |
521
+
522
+ ## Resolved Drift
523
+
524
+ | ID | Resolution | Date |
525
+ |----|-----------|------|
526
+ | D-000 | Migrated to proper service layer | 2026-02-15 |
527
+ ```
528
+
529
+ **Validator checks:**
530
+ - File exists at project root
531
+ - Every `// DRIFT:` comment in source code has a matching entry in this file
532
+ - No orphaned drift log entries (entry exists but inline comment was removed)
533
+
534
+ ---
535
+
536
+ ## 6. Inline Code Markers
537
+
538
+ ### 6.1 Drift Marker
539
+
540
+ When code intentionally deviates from canonical documentation:
541
+
542
+ ```javascript
543
+ // DRIFT: Using in-memory cache instead of Redis (DRIFT-LOG D-003)
544
+ const cache = new Map();
545
+ ```
546
+
547
+ **Rules:**
548
+ - Format: `// DRIFT: <reason> (<drift-log-reference>)`
549
+ - MUST have matching entry in `DRIFT-LOG.md`
550
+ - Language-agnostic: use the comment syntax of your language (`#`, `//`, `/* */`, `--`)
551
+
552
+ ---
553
+
554
+ ## 7. Configuration (.docguard.json)
555
+
556
+ Project-level configuration file that customizes validation for the specific project.
557
+
558
+ ```json
559
+ {
560
+ "$schema": "https://docguard.dev/schema/v0.1.json",
561
+ "projectName": "my-project",
562
+ "version": "0.1",
563
+
564
+ "requiredFiles": {
565
+ "canonical": [
566
+ "docs-canonical/ARCHITECTURE.md",
567
+ "docs-canonical/DATA-MODEL.md",
568
+ "docs-canonical/SECURITY.md",
569
+ "docs-canonical/TEST-SPEC.md"
570
+ ],
571
+ "agentFile": ["AGENTS.md", "CLAUDE.md"],
572
+ "changelog": "CHANGELOG.md",
573
+ "driftLog": "DRIFT-LOG.md"
574
+ },
575
+
576
+ "sourcePatterns": {
577
+ "routes": "src/routes/**/*.ts",
578
+ "services": "src/services/**/*.ts",
579
+ "tests": "tests/**/*.test.ts"
580
+ },
581
+
582
+ "layers": {
583
+ "handlers": {
584
+ "dir": "src/handlers",
585
+ "canImport": ["services", "middleware", "schemas"]
586
+ },
587
+ "services": {
588
+ "dir": "src/services",
589
+ "canImport": ["repositories", "utils", "models"]
590
+ },
591
+ "repositories": {
592
+ "dir": "src/repositories",
593
+ "canImport": ["models", "utils"]
594
+ }
595
+ },
596
+
597
+ "validators": {
598
+ "structure": true,
599
+ "docsSync": true,
600
+ "drift": true,
601
+ "changelog": true,
602
+ "architecture": false,
603
+ "testSpec": true,
604
+ "security": false
605
+ }
606
+ }
607
+ ```
608
+
609
+ ---
610
+
611
+ ## 8. Validator Reference
612
+
613
+ | # | Validator | Checks | Default | Severity |
614
+ |---|-----------|--------|---------|----------|
615
+ | 1 | **structure** | All required files exist | ✅ On | Error |
616
+ | 2 | **docs-sync** | Source files have matching canonical doc entries | ✅ On | Warning |
617
+ | 3 | **drift** | `// DRIFT:` comments have DRIFT-LOG entries | ✅ On | Error |
618
+ | 4 | **changelog** | Staged changes have CHANGELOG entries | ✅ On | Warning |
619
+ | 5 | **architecture** | Imports follow declared layer boundaries | ❌ Off | Error |
620
+ | 6 | **test-spec** | Required tests exist per TEST-SPEC.md | ✅ On | Warning |
621
+ | 7 | **security** | No secrets in code, security patterns followed | ❌ Off | Error |
622
+ | 8 | **environment** | Env vars documented, .env.example exists | ✅ On | Warning |
623
+
624
+ ### Exit Codes
625
+
626
+ | Code | Meaning |
627
+ |------|---------|
628
+ | 0 | All checks pass |
629
+ | 1 | One or more errors (hard failures) |
630
+ | 2 | No errors, but warnings present |
631
+
632
+ ---
633
+
634
+ ## 9. Compatibility
635
+
636
+ ### 9.1 With AGENTS.md Standard
637
+
638
+ DocGuard is fully compatible with the [AGENTS.md standard](https://agents.md). Your `AGENTS.md` file serves dual purpose: both for the AGENTS.md ecosystem and for DocGuard validation.
639
+
640
+ ### 9.2 With GitHub Spec Kit (SDD)
641
+
642
+ Spec-Driven Development (SDD) is the **Build phase** of CDD. DocGuard can import from Spec Kit projects:
643
+
644
+ | Spec Kit File | DocGuard Equivalent |
645
+ |--------------|---------------------|
646
+ | `.specify/memory/constitution.md` | `AGENTS.md` |
647
+ | `specs/<feature>/spec.md` | `docs-canonical/FEATURES.md` |
648
+ | `specs/<feature>/plan.md` | `docs-canonical/ARCHITECTURE.md` |
649
+
650
+ Use `docguard init --from-speckit` to bridge.
651
+
652
+ > [!TIP]
653
+ > **CDD encompasses SDD.** If you're already using Spec Kit, you're doing Phase 1-2 of CDD. Add DocGuard for Phase 3-4 (Guard + Evolve) and adopt the full CDD lifecycle.
654
+
655
+ ### 9.3 With Cursor Rules
656
+
657
+ Cursor rules (`.cursor/rules/`) are IDE-specific. DocGuard's `AGENTS.md` provides the universal equivalent that works across all agents.
658
+
659
+ ### 9.4 With Kiro
660
+
661
+ Kiro's steering files and specs are IDE-native. DocGuard's markdown files are repo-native and portable. Both can coexist.
662
+
663
+ ---
664
+
665
+ ## 10. Three Modes of Operation
666
+
667
+ ### 10.1 Audit Mode
668
+
669
+ Scans a project and reports what DocGuard documentation exists or is missing.
670
+
671
+ ```
672
+ $ docguard audit
673
+
674
+ 📋 DocGuard Audit — my-project
675
+
676
+ docs-canonical/ARCHITECTURE.md ✅ Exists
677
+ docs-canonical/DATA-MODEL.md ✅ Exists
678
+ docs-canonical/SECURITY.md ❌ Missing
679
+ docs-canonical/TEST-SPEC.md ❌ Missing
680
+ docs-canonical/ENVIRONMENT.md ❌ Missing
681
+ AGENTS.md ✅ Exists
682
+ CHANGELOG.md ✅ Exists
683
+ DRIFT-LOG.md ❌ Missing
684
+
685
+ Score: 4/8 required files (50%)
686
+ ```
687
+
688
+ ### 10.2 Generate Mode
689
+
690
+ Analyzes an existing codebase and auto-generates canonical documentation.
691
+
692
+ ```
693
+ $ docguard generate
694
+
695
+ 📋 Analyzing codebase...
696
+
697
+ Detected: TypeScript / Next.js 16 / DynamoDB
698
+ Routes: 14 API routes
699
+ Services: 8 service files
700
+ Tests: 12 unit tests, 0 E2E tests
701
+
702
+ 🏗️ Generating documentation...
703
+ ✅ docs-canonical/ARCHITECTURE.md (architecture mapped)
704
+ ✅ docs-canonical/DATA-MODEL.md (5 schemas extracted)
705
+ ✅ docs-canonical/SECURITY.md (auth patterns detected)
706
+ ✅ docs-canonical/TEST-SPEC.md (test coverage analyzed)
707
+ ✅ DRIFT-LOG.md (initialized)
708
+ ✅ CHANGELOG.md (initialized)
709
+
710
+ 📊 Project Health: 62/100
711
+ ```
712
+
713
+ > **Note**: Generate mode produces high-quality drafts by leveraging AI analysis. Human review is recommended before committing generated docs.
714
+
715
+ ### 10.3 Guard Mode
716
+
717
+ Validates the project against its own canonical documentation. Designed for CI/CD and pre-commit hooks.
718
+
719
+ ```
720
+ $ docguard guard
721
+
722
+ 📋 DocGuard — my-project
723
+
724
+ ✅ Structure 7/7 required files present
725
+ ✅ Docs-Sync 14/14 routes documented
726
+ ❌ Drift 2 unlogged drift comments
727
+ ✅ Changelog CHANGELOG.md updated
728
+ ⚠️ Test-Spec 6/8 services have tests (75%)
729
+
730
+ Result: FAIL (1 error, 1 warning)
731
+ ```
732
+
733
+ ---
734
+
735
+ ## 11. Versioning
736
+
737
+ This standard follows [Semantic Versioning](https://semver.org/):
738
+
739
+ - **MAJOR** — Breaking changes to required file structure or format
740
+ - **MINOR** — New optional files or validator capabilities
741
+ - **PATCH** — Clarifications, typo fixes, examples
742
+
743
+ Current version: **v0.1.0** (Draft)
744
+
745
+ ---
746
+
747
+ ## 12. License
748
+
749
+ This standard is released under the [MIT License](https://opensource.org/licenses/MIT).
750
+
751
+ Projects adopting this standard are free to use, modify, and redistribute it.