cerber-core 1.0.4 → 1.1.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 (37) hide show
  1. package/CHANGELOG.md +158 -68
  2. package/README.md +75 -0
  3. package/USAGE_GUIDE.md +254 -0
  4. package/bin/cerber +121 -105
  5. package/dev/templates/cerber-guardian.mjs.tpl +44 -0
  6. package/dev/templates/cerber.yml.tpl +53 -0
  7. package/dev/templates/health-checks.ts.tpl +11 -0
  8. package/dev/templates/health-route.ts.tpl +50 -0
  9. package/dev/templates/pre-commit.tpl +4 -0
  10. package/dist/cli/contract-parser.d.ts +13 -0
  11. package/dist/cli/contract-parser.d.ts.map +1 -0
  12. package/dist/cli/contract-parser.js +241 -0
  13. package/dist/cli/contract-parser.js.map +1 -0
  14. package/dist/cli/init.d.ts +11 -0
  15. package/dist/cli/init.d.ts.map +1 -0
  16. package/dist/cli/init.js +241 -0
  17. package/dist/cli/init.js.map +1 -0
  18. package/dist/cli/template-generator.d.ts +28 -0
  19. package/dist/cli/template-generator.d.ts.map +1 -0
  20. package/dist/cli/template-generator.js +227 -0
  21. package/dist/cli/template-generator.js.map +1 -0
  22. package/dist/cli/types.d.ts +70 -0
  23. package/dist/cli/types.d.ts.map +1 -0
  24. package/dist/cli/types.js +8 -0
  25. package/dist/cli/types.js.map +1 -0
  26. package/package.json +106 -104
  27. package/solo/templates/cerber-guardian.mjs.tpl +44 -0
  28. package/solo/templates/cerber.yml.tpl +53 -0
  29. package/solo/templates/health-checks.ts.tpl +29 -0
  30. package/solo/templates/health-route.ts.tpl +50 -0
  31. package/solo/templates/pre-commit.tpl +4 -0
  32. package/team/templates/CODEOWNERS.tpl +6 -0
  33. package/team/templates/cerber-guardian.mjs.tpl +44 -0
  34. package/team/templates/cerber.yml.tpl +53 -0
  35. package/team/templates/health-checks.ts.tpl +10 -0
  36. package/team/templates/health-route.ts.tpl +50 -0
  37. 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
@@ -140,6 +140,81 @@ export const BACKEND_SCHEMA = {
140
140
 
141
141
  ## 🚀 Quick Start
142
142
 
143
+ ### 30-Second Setup ⚡ (New in v1.1.0!)
144
+
145
+ ```bash
146
+ npm install cerber-core --save-dev
147
+ npx cerber init
148
+ ```
149
+
150
+ **How it works:**
151
+
152
+ **If CERBER.md is missing** → Cerber creates a template and exits.
153
+
154
+ 1. Fill the contract (`CERBER_CONTRACT`) with your project settings
155
+ 2. Choose mode: `solo` | `dev` | `team`
156
+ 3. Enable features: `guardian`, `health`, `ci`
157
+
158
+ **Run `npx cerber init` again** to generate:
159
+
160
+ - ✅ **Guardian hook + runner** - Pre-commit validation
161
+ - ✅ **Health templates** - Production monitoring endpoints
162
+ - ✅ **GitHub Actions workflow** - CI/CD with stable check names
163
+ - ✅ **Team mode: CODEOWNERS** - Schema ownership enforcement
164
+
165
+ **Example CERBER.md:**
166
+
167
+ ```yaml
168
+ ## CERBER_CONTRACT
169
+ \`\`\`yaml
170
+ version: 1
171
+ mode: dev # solo | dev | team
172
+
173
+ guardian:
174
+ enabled: true
175
+ schemaFile: BACKEND_SCHEMA.ts
176
+
177
+ health:
178
+ enabled: true
179
+ endpoint: /api/health
180
+
181
+ ci:
182
+ provider: github
183
+ branches: [main]
184
+ requiredOnPR: true
185
+ \`\`\`
186
+ ```
187
+
188
+ **Error handling:**
189
+
190
+ If CERBER.md exists but is invalid → you'll get a **clear error message** with:
191
+ - Exact problem location
192
+ - Expected format
193
+ - Suggestion: `npx cerber init --print-template` to see valid example
194
+
195
+ **Useful flags:**
196
+
197
+ ```bash
198
+ npx cerber init --dry-run # Preview without creating files
199
+ npx cerber init --force # Overwrite existing files
200
+ npx cerber init --print-template # Print template to stdout
201
+ ```
202
+
203
+ **What happens:**
204
+ - ✅ Creates `CERBER.md` with your architecture contract
205
+ - ✅ Generates Guardian pre-commit hooks
206
+ - ✅ Sets up health check templates
207
+ - ✅ Configures GitHub Actions workflow
208
+ - ✅ Adapts to your mode: solo/dev/team
209
+
210
+ **Next step:** Just commit! Guardian now protects your architecture.
211
+
212
+ ---
213
+
214
+ ### Manual Setup (Alternative)
215
+
216
+ If you prefer manual configuration, follow the guides below.
217
+
143
218
  ### Installation
144
219
 
145
220
  ```bash
package/USAGE_GUIDE.md ADDED
@@ -0,0 +1,254 @@
1
+ # How to Use Cerber in Your Project
2
+
3
+ ## Quick Start (Recommended)
4
+
5
+ 1. **Install Cerber Core**
6
+ ```bash
7
+ npm install cerber-core --save-dev
8
+ ```
9
+
10
+ 2. **Run init command**
11
+ ```bash
12
+ npx cerber init
13
+ ```
14
+
15
+ 3. **Follow the prompts**
16
+ - If no `CERBER.md` exists, one will be created for you
17
+ - Customize the contract (mode, endpoints, branches)
18
+ - Run `npx cerber init` again to generate files
19
+
20
+ 4. **Review generated files**
21
+ - `CERBER.md` - Your architecture contract
22
+ - `scripts/cerber-guardian.mjs` - Pre-commit validator
23
+ - `.husky/pre-commit` - Git hook
24
+ - `src/cerber/health-checks.ts` - Health check templates
25
+ - `.github/workflows/cerber.yml` - CI/CD workflow
26
+
27
+ 5. **Customize for your project**
28
+ - Create `BACKEND_SCHEMA.ts` with your architecture rules
29
+ - Edit `src/cerber/health-checks.ts` to add your checks
30
+ - Update `.github/CODEOWNERS` if in team mode
31
+
32
+ 6. **Commit and push**
33
+ ```bash
34
+ git add .
35
+ git commit -m "feat: add Cerber protection"
36
+ git push
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Configuration Modes
42
+
43
+ ### Solo Mode
44
+ **Best for:** Individual developers, prototypes, small projects
45
+
46
+ **Features:**
47
+ - Guardian pre-commit validation
48
+ - Basic health checks (optional)
49
+ - Simple CI workflow
50
+
51
+ **Setup:**
52
+ ```yaml
53
+ # In CERBER.md CERBER_CONTRACT
54
+ mode: solo
55
+ ```
56
+
57
+ ### Dev Mode (Default)
58
+ **Best for:** Small teams (2-5 developers), standard projects
59
+
60
+ **Features:**
61
+ - Guardian with required imports
62
+ - Health check endpoints
63
+ - GitHub Actions CI/CD
64
+ - Optional post-deploy health gates
65
+
66
+ **Setup:**
67
+ ```yaml
68
+ # In CERBER.md CERBER_CONTRACT
69
+ mode: dev
70
+ ```
71
+
72
+ ### Team Mode
73
+ **Best for:** Larger teams, strict architecture enforcement
74
+
75
+ **Features:**
76
+ - Everything from Dev mode
77
+ - CODEOWNERS protection
78
+ - Required PR reviews for architecture files
79
+ - Post-deploy health validation (enabled by default)
80
+
81
+ **Setup:**
82
+ ```yaml
83
+ # In CERBER.md CERBER_CONTRACT
84
+ mode: team
85
+ ```
86
+
87
+ ---
88
+
89
+ ## CERBER_CONTRACT Reference
90
+
91
+ ```yaml
92
+ version: 1
93
+ mode: dev # solo | dev | team
94
+
95
+ guardian:
96
+ enabled: true # Enable pre-commit validation
97
+ schemaFile: BACKEND_SCHEMA.ts # Path to your schema
98
+ hook: husky # husky | manual
99
+ approvalsTag: ARCHITECT_APPROVED # Tag for exceptions
100
+
101
+ health:
102
+ enabled: true # Generate health check templates
103
+ endpoint: /api/health # Your health endpoint path
104
+ failOn:
105
+ critical: true # Block deploy on critical issues
106
+ error: true # Block deploy on errors
107
+ warning: false # Allow warnings
108
+
109
+ ci:
110
+ provider: github # github | gitlab | manual
111
+ branches: [main] # Protected branches
112
+ requiredOnPR: true # Run Guardian on PRs
113
+ postDeploy:
114
+ enabled: false # Post-deploy health gate
115
+ waitSeconds: 90 # Wait time before check
116
+ healthUrlVar: CERBER_HEALTH_URL # GitHub Variable name
117
+ authHeaderSecret: CERBER_HEALTH_AUTH_HEADER # GitHub Secret name (optional)
118
+ ```
119
+
120
+ ---
121
+
122
+ ## CLI Flags
123
+
124
+ ### Basic Usage
125
+ ```bash
126
+ npx cerber init # Interactive setup
127
+ npx cerber init --mode dev # Override mode
128
+ npx cerber init --dry-run # Preview without creating files
129
+ npx cerber init --force # Overwrite existing files
130
+ ```
131
+
132
+ ### Advanced Flags
133
+ ```bash
134
+ --mode <mode> # Override contract mode (solo|dev|team)
135
+ --force # Overwrite existing files
136
+ --dry-run # Show what would be generated
137
+ --no-husky # Skip Husky hook generation
138
+ --no-workflow # Skip GitHub Actions workflow
139
+ --no-health # Skip health check templates
140
+ --write-contract # Update CERBER.md with CLI options
141
+ ```
142
+
143
+ ### Examples
144
+ ```bash
145
+ # Preview dev mode setup
146
+ npx cerber init --mode dev --dry-run
147
+
148
+ # Generate only Guardian files (no health checks)
149
+ npx cerber init --no-health --no-workflow
150
+
151
+ # Force regenerate all files in team mode
152
+ npx cerber init --mode team --force
153
+ ```
154
+
155
+ ---
156
+
157
+ ## GitHub Actions Setup
158
+
159
+ ### Required Variables
160
+
161
+ If you enable post-deploy health checks, set up GitHub Variables:
162
+
163
+ 1. Go to: **Settings** > **Secrets and variables** > **Actions** > **Variables**
164
+ 2. Add new repository variable:
165
+ - **Name:** `CERBER_HEALTH_URL`
166
+ - **Value:** `https://your-api.com/api/health`
167
+
168
+ ### Optional Secrets
169
+
170
+ For authenticated health endpoints:
171
+
172
+ 1. Go to: **Settings** > **Secrets and variables** > **Actions** > **Secrets**
173
+ 2. Add new repository secret:
174
+ - **Name:** `CERBER_HEALTH_AUTH_HEADER`
175
+ - **Value:** `Bearer your-token-here`
176
+
177
+ ---
178
+
179
+ ## Team Mode Setup
180
+
181
+ ### CODEOWNERS Configuration
182
+
183
+ 1. Edit `.github/CODEOWNERS`:
184
+ ```
185
+ /CERBER.md @your-username
186
+ /BACKEND_SCHEMA.ts @your-username
187
+ /.github/workflows/cerber.yml @your-username
188
+ ```
189
+
190
+ 2. Replace `@your-username` with:
191
+ - Your GitHub username (individual)
192
+ - Team name like `@org/architects` (organization)
193
+
194
+ ### Branch Protection
195
+
196
+ 1. Go to: **Settings** > **Branches** > **Branch protection rules**
197
+ 2. Add rule for `main`:
198
+ - ✅ Require pull request reviews before merging
199
+ - ✅ Require review from Code Owners
200
+ - ✅ Require status checks to pass
201
+ - Add: `cerber-guardian`
202
+ - Add: `post-deploy-health` (if enabled)
203
+
204
+ ---
205
+
206
+ ## Troubleshooting
207
+
208
+ ### "CERBER.md not found"
209
+ Run `npx cerber init` - it will create a template for you.
210
+
211
+ ### "Schema file not found"
212
+ Create `BACKEND_SCHEMA.ts` at your project root with Guardian rules. See [Guardian Configuration](https://github.com/Agaslez/cerber-core#guardian-configuration).
213
+
214
+ ### Guardian hook not running
215
+ ```bash
216
+ npx husky install
217
+ chmod +x .husky/pre-commit
218
+ ```
219
+
220
+ ### Post-deploy health check fails
221
+ - Verify `CERBER_HEALTH_URL` is set in GitHub Variables
222
+ - Check health endpoint returns proper JSON format
223
+ - Review `failOn` settings in `CERBER_CONTRACT`
224
+
225
+ ### Files already exist error
226
+ Use `--force` flag to overwrite:
227
+ ```bash
228
+ npx cerber init --force
229
+ ```
230
+
231
+ ---
232
+
233
+ ## Migration from Manual Setup
234
+
235
+ If you have existing Guardian/Cerber setup:
236
+
237
+ 1. Create `CERBER.md` with contract matching your current config
238
+ 2. Run `npx cerber init --dry-run` to preview changes
239
+ 3. Backup existing files
240
+ 4. Run `npx cerber init --force` to migrate
241
+ 5. Review and test generated files
242
+
243
+ ---
244
+
245
+ ## Next Steps
246
+
247
+ - 📖 Read [Guardian Configuration Guide](https://github.com/Agaslez/cerber-core#guardian-configuration)
248
+ - 🔍 Explore [Cerber Health Examples](https://github.com/Agaslez/cerber-core#cerber-examples)
249
+ - 💬 Ask questions in [GitHub Discussions](https://github.com/Agaslez/cerber-core/discussions)
250
+ - ⭐ Star the repo if Cerber saved you time!
251
+
252
+ ---
253
+
254
+ **Need help?** Open an issue or discussion: https://github.com/Agaslez/cerber-core