cerber-core 1.0.4 → 1.1.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 (42) hide show
  1. package/CHANGELOG.md +158 -68
  2. package/README.md +198 -5
  3. package/USAGE_GUIDE.md +254 -0
  4. package/bin/cerber +120 -104
  5. package/dev/templates/BACKEND_SCHEMA.ts.tpl +48 -0
  6. package/dev/templates/cerber-guardian.mjs.tpl +44 -0
  7. package/dev/templates/cerber.yml.tpl +53 -0
  8. package/dev/templates/health-checks.ts.tpl +11 -0
  9. package/dev/templates/health-route.ts.tpl +50 -0
  10. package/dev/templates/pre-commit.tpl +4 -0
  11. package/dist/cli/contract-parser.d.ts +13 -0
  12. package/dist/cli/contract-parser.d.ts.map +1 -0
  13. package/dist/cli/contract-parser.js +265 -0
  14. package/dist/cli/contract-parser.js.map +1 -0
  15. package/dist/cli/init.d.ts +11 -0
  16. package/dist/cli/init.d.ts.map +1 -0
  17. package/dist/cli/init.js +292 -0
  18. package/dist/cli/init.js.map +1 -0
  19. package/dist/cli/template-generator.d.ts +29 -0
  20. package/dist/cli/template-generator.d.ts.map +1 -0
  21. package/dist/cli/template-generator.js +252 -0
  22. package/dist/cli/template-generator.js.map +1 -0
  23. package/dist/cli/types.d.ts +79 -0
  24. package/dist/cli/types.d.ts.map +1 -0
  25. package/dist/cli/types.js +8 -0
  26. package/dist/cli/types.js.map +1 -0
  27. package/examples/backend-schema.ts +9 -2
  28. package/examples/frontend-schema.ts +9 -2
  29. package/package.json +106 -104
  30. package/solo/templates/BACKEND_SCHEMA.ts.tpl +48 -0
  31. package/solo/templates/cerber-guardian.mjs.tpl +44 -0
  32. package/solo/templates/cerber.yml.tpl +53 -0
  33. package/solo/templates/health-checks.ts.tpl +29 -0
  34. package/solo/templates/health-route.ts.tpl +50 -0
  35. package/solo/templates/pre-commit.tpl +4 -0
  36. package/team/templates/BACKEND_SCHEMA.ts.tpl +48 -0
  37. package/team/templates/CODEOWNERS.tpl +6 -0
  38. package/team/templates/cerber-guardian.mjs.tpl +44 -0
  39. package/team/templates/cerber.yml.tpl +53 -0
  40. package/team/templates/health-checks.ts.tpl +10 -0
  41. package/team/templates/health-route.ts.tpl +50 -0
  42. package/team/templates/pre-commit.tpl +4 -0
package/CHANGELOG.md CHANGED
@@ -1,68 +1,158 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [1.0.0] - 2026-01-03
9
-
10
- ### Added
11
- - **Guardian 1.0**: Pre-commit architecture validator
12
- - Forbidden pattern detection with architect approval system
13
- - Required file validation
14
- - Required import checking
15
- - package.json rules validation
16
- - Recursive directory scanning
17
- - Detailed error/warning reporting
18
- - CLI with `--schema`, `--verbose`, `--fail-on-warning` options
19
-
20
- - **Cerber 2.1**: Runtime health monitoring
21
- - Flexible health check system
22
- - Multiple severity levels (critical, error, warning, info)
23
- - Parallel and sequential check execution
24
- - Detailed diagnostics with fix suggestions
25
- - JSON output for CI/CD integration
26
- - CLI with `--checks`, `--url`, `--parallel` options
27
-
28
- - **Architect Approval System**:
29
- - Comment-based approval format: `// ARCHITECT_APPROVED: reason - YYYY-MM-DD - Name`
30
- - Automatic parsing and tracking
31
- - Integration with Guardian validation
32
-
33
- - **Examples**:
34
- - Frontend schema (React/Vue patterns)
35
- - Backend schema (Node.js/Express patterns)
36
- - Health check templates (DB, disk, memory, env vars)
37
-
38
- - **Documentation**:
39
- - Comprehensive README with real-world metrics
40
- - Contributing guidelines
41
- - API documentation
42
- - MIT License
43
-
44
- - **Production Testing**:
45
- - Extracted from Eliksir project
46
- - Real metrics: 18 commits, 43 issues detected, 4.5 hours saved
47
- - 95% bug detection rate pre-production
48
- - 2 commits blocked by Guardian
49
-
50
- ### Technical Details
51
- - TypeScript with ES2022 target
52
- - ESNext modules for modern bundlers
53
- - Commander.js for CLI
54
- - Chalk for colored output
55
- - Full type definitions included
56
- - Zero runtime dependencies (except CLI deps)
57
-
58
- ## [Unreleased]
59
-
60
- ### Planned
61
- - Web dashboard for health check visualization
62
- - Slack/Discord notifications
63
- - Custom reporter plugins
64
- - VS Code extension
65
- - Git hooks integration (Husky)
66
- - More built-in health checks
67
- - Performance monitoring
68
- - Metrics export (Prometheus, DataDog)
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.1.0] - 2026-01-03
9
+
10
+ ### Added
11
+
12
+ #### 🚀 Instant Setup Command
13
+ - **`npx cerber init`** - One-command project initialization
14
+ - Detects or creates `CERBER.md` with architecture contract
15
+ - Parses machine-readable `CERBER_CONTRACT` (YAML)
16
+ - Generates Guardian hooks, health checks, and CI/CD workflows
17
+ - Supports three modes: `solo`, `dev`, `team`
18
+ - CLI flags: `--mode`, `--force`, `--dry-run`, `--no-husky`, `--no-workflow`, `--no-health`
19
+
20
+ #### 📋 CERBER_CONTRACT Format
21
+ - Machine-readable YAML contract embedded in `CERBER.md`
22
+ - Defines:
23
+ - `mode`: solo | dev | team
24
+ - `guardian`: pre-commit configuration
25
+ - `health`: runtime health check settings
26
+ - `ci`: GitHub Actions and deployment gates
27
+ - Single source of truth for tooling configuration
28
+
29
+ #### 🔧 Generated Files
30
+ - **Guardian**:
31
+ - `scripts/cerber-guardian.mjs` - Pre-commit validator
32
+ - `.husky/pre-commit` - Git hook
33
+ - Updates `package.json` scripts
34
+ - **Health Checks** (optional):
35
+ - `src/cerber/health-checks.ts` - Template checks
36
+ - `src/cerber/health-route.ts` - Express route handler
37
+ - **CI/CD**:
38
+ - `.github/workflows/cerber.yml` - GitHub Actions workflow
39
+ - Reusable `cerber-gatekeeper.yml` workflow for post-deploy health
40
+ - **Team Mode**:
41
+ - `.github/CODEOWNERS` - Protect architecture files
42
+
43
+ #### 🧪 Testing
44
+ - Unit tests for contract parser
45
+ - Manual smoke test script
46
+ - Dry-run mode for safe testing
47
+
48
+ #### 📖 Documentation
49
+ - New `USAGE_GUIDE.md` with complete setup instructions
50
+ - Updated README with 30-second Quick Start
51
+ - CERBER_CONTRACT reference documentation
52
+
53
+ ### Changed
54
+ - **CLI Version** - Bumped to 1.1.0
55
+ - **README.md** - Updated Quick Start section with instant setup
56
+ - Template structure organized into `solo/`, `dev/`, `team/` folders
57
+
58
+ ### Security
59
+ - All generated files include "Generated by Cerber init" comment
60
+ - `--force` flag required to overwrite existing files
61
+ - CODEOWNERS template for protecting critical files
62
+
63
+ ---
64
+
65
+ ## [1.0.4] - 2026-01-02
66
+
67
+ ### Changed
68
+ - Updated package description with business value messaging
69
+ - Enhanced README with "Your Roadmap Becomes Executable Law" section
70
+ - Added ROI calculations and cost savings data
71
+
72
+ ---
73
+
74
+ ## [1.0.3] - 2026-01-02
75
+
76
+ ### Changed
77
+ - Author metadata updates
78
+ - Documentation improvements
79
+
80
+ ---
81
+
82
+ ## [1.0.2] - 2026-01-02
83
+
84
+ ### Fixed
85
+ - CI/CD workflow fixes
86
+ - Branch protection compatibility
87
+
88
+ ---
89
+
90
+ ## [1.0.1] - 2026-01-02
91
+
92
+ ### Changed
93
+ - Initial production release
94
+ - Package metadata refinements
95
+
96
+ ---
97
+
98
+ ## [1.0.0] - 2026-01-03
99
+
100
+ ### Added
101
+ - **Guardian 1.0**: Pre-commit architecture validator
102
+ - Forbidden pattern detection with architect approval system
103
+ - Required file validation
104
+ - Required import checking
105
+ - package.json rules validation
106
+ - Recursive directory scanning
107
+ - Detailed error/warning reporting
108
+ - CLI with `--schema`, `--verbose`, `--fail-on-warning` options
109
+
110
+ - **Cerber 2.1**: Runtime health monitoring
111
+ - Flexible health check system
112
+ - Multiple severity levels (critical, error, warning, info)
113
+ - Parallel and sequential check execution
114
+ - Detailed diagnostics with fix suggestions
115
+ - JSON output for CI/CD integration
116
+ - CLI with `--checks`, `--url`, `--parallel` options
117
+
118
+ - **Architect Approval System**:
119
+ - Comment-based approval format: `// ARCHITECT_APPROVED: reason - YYYY-MM-DD - Name`
120
+ - Automatic parsing and tracking
121
+ - Integration with Guardian validation
122
+
123
+ - **Examples**:
124
+ - Frontend schema (React/Vue patterns)
125
+ - Backend schema (Node.js/Express patterns)
126
+ - Health check templates (DB, disk, memory, env vars)
127
+
128
+ - **Documentation**:
129
+ - Comprehensive README with real-world metrics
130
+ - Contributing guidelines
131
+ - API documentation
132
+ - MIT License
133
+
134
+ - **Production Testing**:
135
+ - Extracted from Eliksir project
136
+ - Real metrics: 18 commits, 43 issues detected, 4.5 hours saved
137
+ - 95% bug detection rate pre-production
138
+ - 2 commits blocked by Guardian
139
+
140
+ ### Technical Details
141
+ - TypeScript with ES2022 target
142
+ - ESNext modules for modern bundlers
143
+ - Commander.js for CLI
144
+ - Chalk for colored output
145
+ - Full type definitions included
146
+ - Zero runtime dependencies (except CLI deps)
147
+
148
+ ## [Unreleased]
149
+
150
+ ### Planned
151
+ - Web dashboard for health check visualization
152
+ - Slack/Discord notifications
153
+ - Custom reporter plugins
154
+ - VS Code extension
155
+ - Git hooks integration (Husky)
156
+ - More built-in health checks
157
+ - Performance monitoring
158
+ - Metrics export (Prometheus, DataDog)
package/README.md CHANGED
@@ -71,7 +71,14 @@ Ongoing savings: $6,000/month per developer
71
71
 
72
72
  ## 🎯 What is Cerber Core?
73
73
 
74
- Cerber Core is a comprehensive toolkit for maintaining code quality and architecture in growing Node.js projects.
74
+ **Cerber Core is a control system for Node.js architecture.**
75
+
76
+ **Critical distinction:** Cerber does NOT design your system. Cerber EXECUTES your design.
77
+
78
+ ```
79
+ You decide → CERBER.md (roadmap)
80
+ Cerber guards → enforces your decisions
81
+ ```
75
82
 
76
83
  ### 💎 The Core Value: Your Roadmap Becomes Executable Law
77
84
 
@@ -138,8 +145,165 @@ export const BACKEND_SCHEMA = {
138
145
 
139
146
  ---
140
147
 
148
+ ## 🎯 ONE SOURCE OF TRUTH
149
+
150
+ **Critical principle:** Cerber does NOT design your system. Cerber enforces YOUR design.
151
+
152
+ ### The Rule
153
+
154
+ ```
155
+ 📜 CERBER.md = Your roadmap (single source of truth)
156
+ 🛡️ Guardian = Enforces CERBER.md rules
157
+ 📋 Schema files = Optional mirrors of CERBER.md (NOT source of truth)
158
+ ```
159
+
160
+ **What this means:**
161
+
162
+ ✅ **CERBER.md defines everything** - architecture, rules, team mode
163
+ ✅ **Cerber executes CERBER.md** - no assumptions, no magic
164
+ ✅ **Schema files are user-owned** - Cerber helps, never decides
165
+ ✅ **You design. Cerber guards.** - separation of concerns
166
+
167
+ ❌ **Cerber does NOT guess your architecture**
168
+ ❌ **Cerber does NOT infer folder structures**
169
+ ❌ **Cerber does NOT auto-design systems**
170
+
171
+ ### Schema Mode: Strict vs Template_Only
172
+
173
+ In `CERBER.md` contract, you control schema generation:
174
+
175
+ ```yaml
176
+ schema:
177
+ enabled: true
178
+ file: BACKEND_SCHEMA.ts
179
+ mode: strict # or template_only
180
+ ```
181
+
182
+ **For mature teams → `mode: strict`**
183
+ - ✅ Cerber NEVER creates schema file
184
+ - ✅ You create schema based on YOUR architecture
185
+ - ✅ Full control, no helpers, no assumptions
186
+ - ✅ `npx cerber init` shows: "You must create BACKEND_SCHEMA.ts"
187
+
188
+ **For beginners → `mode: template_only`**
189
+ - ✅ Cerber creates minimal template if file missing
190
+ - ⚠️ Template says: "NOT SOURCE OF TRUTH - Edit to match CERBER.md"
191
+ - ✅ Empty structures, commented examples only
192
+ - ✅ Helper scaffold, NOT design decision
193
+
194
+ **Default:** `template_only` (backward compatible)
195
+
196
+ **Philosophy:**
197
+
198
+ ```
199
+ Traditional tools:
200
+ → Auto-generate everything
201
+ → Assume folder structures
202
+ → "Helpful" magic that creates chaos
203
+
204
+ Cerber Core:
205
+ → Execute CERBER.md contract
206
+ → Never assume architecture
207
+ → One decision point (CERBER.md)
208
+ → Works WITH AI agents, not against them
209
+ ```
210
+
211
+ **Why this matters:**
212
+
213
+ When your team (or AI agents) follow ONE source of truth:
214
+ - ✅ No conflicts between "docs" and "reality"
215
+ - ✅ No drift between "schema" and "roadmap"
216
+ - ✅ Clear authority: CERBER.md decides, Cerber enforces
217
+ - ✅ Architecture stays intact as team/AI scales
218
+
219
+ **This is not "another tool". This is a control system.**
220
+
221
+ ---
222
+
141
223
  ## 🚀 Quick Start
142
224
 
225
+ ### 30-Second Setup ⚡ (New in v1.1.0!)
226
+
227
+ ```bash
228
+ npm install cerber-core --save-dev
229
+ npx cerber init
230
+ ```
231
+
232
+ **How it works:**
233
+
234
+ **If CERBER.md is missing** → Cerber creates a template and exits.
235
+
236
+ 1. Fill the contract (`CERBER_CONTRACT`) with your project settings
237
+ 2. Choose mode: `solo` | `dev` | `team`
238
+ 3. Enable features: `guardian`, `health`, `ci`
239
+
240
+ **Run `npx cerber init` again** to generate:
241
+
242
+ - ✅ **Guardian hook + runner** - Pre-commit validation
243
+ - ✅ **Health templates** - Production monitoring endpoints
244
+ - ✅ **GitHub Actions workflow** - CI/CD with stable check names
245
+ - ✅ **Team mode: CODEOWNERS** - Schema ownership enforcement
246
+
247
+ **Example CERBER.md:**
248
+
249
+ ```yaml
250
+ ## CERBER_CONTRACT
251
+ \`\`\`yaml
252
+ version: 1
253
+ mode: dev # solo | dev | team
254
+
255
+ guardian:
256
+ enabled: true
257
+ schemaFile: BACKEND_SCHEMA.ts
258
+
259
+ schema:
260
+ enabled: true
261
+ file: BACKEND_SCHEMA.ts
262
+ mode: template_only # strict (mature teams) | template_only (beginners)
263
+ # strict = You create schema, Cerber never generates
264
+ # template_only = Cerber creates minimal helper if missing
265
+
266
+ health:
267
+ enabled: true
268
+ endpoint: /api/health
269
+
270
+ ci:
271
+ provider: github
272
+ branches: [main]
273
+ requiredOnPR: true
274
+ \`\`\`
275
+ ```
276
+
277
+ **Error handling:**
278
+
279
+ If CERBER.md exists but is invalid → you'll get a **clear error message** with:
280
+ - Exact problem location
281
+ - Expected format
282
+ - Suggestion: `npx cerber init --print-template` to see valid example
283
+
284
+ **Useful flags:**
285
+
286
+ ```bash
287
+ npx cerber init --dry-run # Preview without creating files
288
+ npx cerber init --force # Overwrite existing files
289
+ npx cerber init --print-template # Print template to stdout
290
+ ```
291
+
292
+ **What happens:**
293
+ - ✅ Creates `CERBER.md` with your architecture contract
294
+ - ✅ Generates Guardian pre-commit hooks
295
+ - ✅ Sets up health check templates
296
+ - ✅ Configures GitHub Actions workflow
297
+ - ✅ Adapts to your mode: solo/dev/team
298
+
299
+ **Next step:** Just commit! Guardian now protects your architecture.
300
+
301
+ ---
302
+
303
+ ### Manual Setup (Alternative)
304
+
305
+ If you prefer manual configuration, follow the guides below.
306
+
143
307
  ### Installation
144
308
 
145
309
  ```bash
@@ -148,10 +312,12 @@ npm install cerber-core --save-dev
148
312
 
149
313
  ### Choose Your Path
150
314
 
315
+ > ⚠️ **Note:** Examples below show common patterns. Copy and **customize to YOUR architecture**. Schema files are templates, not decisions.
316
+
151
317
  #### 🎨 **Frontend Developer (React/Vue/Angular)**
152
318
 
153
319
  ```bash
154
- # 1. Copy frontend schema example
320
+ # 1. Copy frontend schema example (then customize!)
155
321
  cp node_modules/cerber-core/examples/frontend-schema.ts ./FRONTEND_SCHEMA.ts
156
322
 
157
323
  # 2. Copy validation script
@@ -173,10 +339,12 @@ git commit -m "test"
173
339
  - ✅ Required imports (`react`, `react-dom`)
174
340
  - ✅ Required files (`tsconfig.json`, `vite.config.ts`)
175
341
 
342
+ **Then customize:** Edit FRONTEND_SCHEMA.ts to match YOUR folder structure, YOUR rules, YOUR tech stack.
343
+
176
344
  #### ⚙️ **Backend Developer (Node.js/Express/NestJS)**
177
345
 
178
346
  ```bash
179
- # 1. Copy backend schema example
347
+ # 1. Copy backend schema example (then customize!)
180
348
  cp node_modules/cerber-core/examples/backend-schema.ts ./BACKEND_SCHEMA.ts
181
349
 
182
350
  # 2. Copy validation script
@@ -190,6 +358,8 @@ npx husky add .husky/pre-commit "node scripts/validate-schema.mjs"
190
358
  # 4. Add health endpoint
191
359
  ```
192
360
 
361
+ **Then customize:** Edit BACKEND_SCHEMA.ts to match YOUR routes, YOUR layers, YOUR security rules.
362
+
193
363
  ```javascript
194
364
  // server.js (ESM)
195
365
  import express from 'express';
@@ -300,6 +470,27 @@ cerber-repair
300
470
  cerber-focus
301
471
  ```
302
472
 
473
+ ---
474
+
475
+ ## ⚠️ Important: Schema Files Are NOT Source of Truth
476
+
477
+ Before diving into examples below, understand this:
478
+
479
+ **📋 Schema files (BACKEND_SCHEMA.ts, FRONTEND_SCHEMA.ts):**
480
+ - Are **examples** and **optional templates**
481
+ - Mirror YOUR architecture decisions from CERBER.md
482
+ - Are user-owned and user-created (in strict mode)
483
+ - Should be customized to YOUR project structure
484
+
485
+ **📜 CERBER.md:**
486
+ - Is the ONLY source of truth
487
+ - Defines your roadmap, rules, team mode
488
+ - Controls if/how Cerber helps with schema generation
489
+
490
+ **Cerber does NOT design your system. The examples below show patterns - YOU decide which patterns fit YOUR architecture.**
491
+
492
+ ---
493
+
303
494
  ### Guardian Setup (3 minutes)
304
495
 
305
496
  **1. Create architecture schema:**
@@ -1141,10 +1332,12 @@ Break-even: Day 1 ✅
1141
1332
 
1142
1333
  ## 💡 Examples
1143
1334
 
1335
+ > ⚠️ **Remember:** Examples show patterns, NOT decisions. Copy and customize to YOUR architecture defined in CERBER.md.
1336
+
1144
1337
  ### Complete Examples in `/examples`
1145
1338
 
1146
- - [**Frontend (React + Guardian)**](examples/frontend-schema.ts) - React/Vue architecture rules
1147
- - [**Backend (Express + Cerber)**](examples/backend-schema.ts) - Node.js/Express patterns
1339
+ - [**Frontend (React + Guardian)**](examples/frontend-schema.ts) - React/Vue patterns (customize to your structure)
1340
+ - [**Backend (Express + Cerber)**](examples/backend-schema.ts) - Node.js/Express patterns (customize to your layers)
1148
1341
  - [**Health Checks**](examples/health-checks.ts) - 6 production-ready checks
1149
1342
  - [**SOLO Integration**](examples/solo-integration/) - Automation setup
1150
1343
  - [**TEAM Integration**](examples/team-integration/) - Module system setup