code-warden 3.1.1 → 3.3.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 (41) hide show
  1. package/CONFIGURE.md +39 -39
  2. package/DECISIONS.md +107 -107
  3. package/README.md +199 -137
  4. package/SKILL.md +169 -169
  5. package/bin/code-warden.js +82 -0
  6. package/codewarden.json +14 -14
  7. package/examples/governed-session.md +132 -132
  8. package/install.js +399 -399
  9. package/install.ps1 +32 -32
  10. package/install.sh +33 -33
  11. package/package.json +45 -2
  12. package/references/anti-drift.md +55 -55
  13. package/references/architecture.md +26 -26
  14. package/references/cleanup.md +30 -30
  15. package/references/cognition.md +36 -36
  16. package/references/operations.md +45 -45
  17. package/references/planning-gates.md +83 -83
  18. package/references/research-and-fit.md +51 -51
  19. package/references/safety.md +31 -31
  20. package/templates/ci/github-actions.yml +83 -66
  21. package/tools/auto-detect.js +91 -91
  22. package/tools/auto-targets.js +104 -104
  23. package/tools/auto-windsurf-adapter.js +75 -75
  24. package/tools/get-context.js +50 -50
  25. package/tools/governance-report.js +302 -0
  26. package/tools/hooks/claude/install-hooks.js +112 -112
  27. package/tools/hooks/claude/uninstall-hooks.js +75 -75
  28. package/tools/hooks/claude/warden-lint-hook.js +106 -106
  29. package/tools/hooks/claude/warden-secrets-hook.js +73 -73
  30. package/tools/hooks/codex/install-hooks.js +100 -100
  31. package/tools/hooks/codex/uninstall-hooks.js +53 -53
  32. package/tools/hooks/codex/warden-apply-patch-hook.js +113 -113
  33. package/tools/hooks/codex/warden-bash-hook.js +51 -51
  34. package/tools/lib/config.js +49 -49
  35. package/tools/lib/file-collection.js +72 -72
  36. package/tools/lib/line-count.js +28 -28
  37. package/tools/lib/secret-patterns.js +57 -57
  38. package/tools/tests/fixtures/clean.js +9 -9
  39. package/tools/tests/run-tests.js +210 -210
  40. package/tools/verify-secrets.js +26 -26
  41. package/tools/warden-lint.js +27 -27
package/README.md CHANGED
@@ -1,137 +1,199 @@
1
- # code-warden
2
-
3
- > Portable AI Coding Governance Layer
4
-
5
- Code-Warden is a portable governance layer for AI coding agents. It enforces scoped planning, patch discipline, file-size limits, the zero-trust secrets policy, verification evidence, install health, and optional Claude Code pre-tool-use blocking.
6
-
7
- ## Four Layers
8
-
9
- <p align="center">
10
- <img src="../logo/layers-diagram.png" alt="Code-Warden Four Layers" width="100%" />
11
- </p>
12
-
13
- | Layer | What it does |
14
- |-------|-------------|
15
- | **Skill governance** | Scope Gate, Plan Gate, blast-radius checks, patch-first editing, research gates, drift signals, verification evidence |
16
- | **Local verification** | `warden-lint`, `verify-secrets`, `get-context` — directory-aware, no external deps |
17
- | **Installer and health** | Cross-app auto-installer, manifest-backed installs, `--doctor`, `--verify-target`, Windsurf adapter |
18
- | **Hard enforcement** | Claude Code `PreToolUse` hooks block oversized writes and hardcoded secrets before the file system is touched |
19
-
20
- ## Install
21
-
22
- ```bash
23
- git clone https://github.com/Kodaxadev/Code-Warden.git
24
- cd Code-Warden/code-warden
25
- node install.js
26
- ```
27
-
28
- ### Installer commands
29
-
30
- | Command | Purpose |
31
- |---------|---------|
32
- | `node install.js` | Scan, prompt, install to detected apps |
33
- | `node install.js --all` | Install without prompt |
34
- | `node install.js --dry-run` | Preview installs, write nothing |
35
- | `node install.js --list` | Show detected apps and detection method |
36
- | `node install.js --doctor` | Verify source integrity + per-target install health |
37
- | `node install.js --target=claude,cursor` | Force specific targets (warns if not detected) |
38
- | `node install.js --verify-target=claude` | Strict health check — exits nonzero if not installed |
39
- | `node install.js --hooks=claude` | Install PreToolUse hooks into `~/.claude/settings.json` |
40
- | `node install.js --uninstall-hooks=claude` | Remove code-warden hook entries from settings |
41
-
42
- Supported targets: **Claude Code**, **Cursor**, **Warp**, **OpenAI Codex**, **Windsurf**, **Generic Agents**.
43
-
44
- Each install writes a `.code-warden-install.json` manifest (version, target, format, timestamp).
45
-
46
- ### npm scripts
47
-
48
- ```bash
49
- npm run lint # warden-lint on full project tree
50
- npm run check-secrets # verify-secrets on full project tree
51
- npm run install-auto # node install.js
52
- npm run install-dry-run # node install.js --dry-run
53
- npm run install-list # node install.js --list
54
- npm run install-doctor # node install.js --doctor
55
- npm run test # behavioral tests (8 scanner/hook pass/fail cases)
56
- npm run ci # lint + secrets + test + doctor
57
- ```
58
-
59
- ## Usage
60
-
61
- Load at the start of any coding session. Trigger phrases:
62
-
63
- - `"load code-warden"` / `"load protocol"`
64
- - `"begin coding"` / `"new session"` / `"governance check"`
65
- - `"start a new module"` / `"review this before we write"`
66
-
67
- The session sequence is enforced before any implementation:
68
-
69
- <p align="center">
70
- <img src="../logo/session-flow.png" alt="Code-Warden Session Start Sequence" width="100%" />
71
- </p>
72
-
73
- 1. Architecture State (Re-injection Rule)
74
- 2. Session Scope (Session Scoping Rule)
75
- 3. Reference Files (Blueprint Rule)
76
- 4. **Scope Gate** — goal, non-goals, files in/out, verify commands, rollback
77
- 5. **Plan Gate** patch order, blast radius class, post-patch checks
78
-
79
- See [`examples/governed-session.md`](examples/governed-session.md) for an annotated example.
80
-
81
- ## Optional Claude Code Hooks
82
-
83
- <p align="center">
84
- <img src="../logo/hook-flow.png" alt="Code-Warden Hook Enforcement Flow" width="100%" />
85
- </p>
86
-
87
- Install hard enforcement that runs at the `PreToolUse` level — before writes happen:
88
-
89
- ```bash
90
- # Requires Claude Code target to be installed first
91
- node install.js --hooks=claude
92
- ```
93
-
94
- | Hook | Trigger | Policy |
95
- |------|---------|--------|
96
- | `warden-lint-hook.js` | `Write` or `Edit` | Blocks if resulting file exceeds line limit |
97
- | `warden-secrets-hook.js` | `Write` or `Edit` | Hardcoded credential scannerblocks if content matches any secret pattern |
98
-
99
- Both hooks use exec form (`node /path/to/hook.js`) no shell differences across platforms.
100
-
101
- Thresholds are read from `codewarden.json` in the installed skill directory.
102
-
103
- ```bash
104
- node install.js --uninstall-hooks=claude # remove hook entries from settings.json
105
- ```
106
-
107
- Doctor and `--verify-target=claude` validate hook script paths when hooks are registered.
108
-
109
- ## Configuration
110
-
111
- All thresholds in [`codewarden.json`](codewarden.json):
112
-
113
- | Setting | Default | What it controls |
114
- |---------|---------|-----------------|
115
- | `thresholds.max_file_length` | 400 | Lines before `warden-lint.js` flags a file |
116
- | `thresholds.pre_flight_trigger_lines` | 150 | Lines before a pre-flight manifest is required |
117
- | `thresholds.human_checkpoint_files` | 2 | Files touched before `[AWAITING CONFIRMATION]` is required |
118
- | `safety.exempt_from_blast_radius` | `tests/`, `docs/`, `scripts/` | Paths excluded from rollback-plan rule |
119
-
120
- See [`CONFIGURE.md`](CONFIGURE.md) for team-size profiles and tuning rationale.
121
-
122
- ## Reference Files
123
-
124
- | File | Domain |
125
- |------|--------|
126
- | `references/planning-gates.md` | Scope Gate and Plan Gate contracts |
127
- | `references/architecture.md` | Blueprint Rule, Re-injection, State Update |
128
- | `references/safety.md` | Blast Radius, Patch-First, Zero-Trust, Dependency Freeze |
129
- | `references/cognition.md` | Think Before Coding, Don't Guess Syntax, Human Checkpoint |
130
- | `references/cleanup.md` | Tech Debt format, Test Contract, Decision Log |
131
- | `references/anti-drift.md` | Anchor Check, Session Scoping, Drift Trigger Protocol |
132
- | `references/operations.md` | Verification, source-control hygiene, dependency control |
133
- | `references/research-and-fit.md` | Live research gate, stack fit, product-shape guardrails |
134
-
135
- ## Author
136
-
137
- Justin Davis MIT License
1
+ # code-warden
2
+
3
+ > Portable AI Coding Governance Layer
4
+
5
+ Code-Warden provides verifiable governance for AI-assisted development.
6
+ It does not just ask agents to follow rules — it adds Scope Gates, Plan Gates,
7
+ local checks, CI enforcement, runtime hooks where supported, and governance
8
+ artifacts that show what was checked before code was accepted.
9
+
10
+ ## Four Layers
11
+
12
+ <p align="center">
13
+ <img src="../logo/layers-diagram.png" alt="Code-Warden Four Layers" width="100%" />
14
+ </p>
15
+
16
+ | Layer | What it does |
17
+ |-------|-------------|
18
+ | **Skill governance** | Scope Gate, Plan Gate, blast-radius checks, patch-first editing, research gates, drift signals, verification evidence |
19
+ | **Local verification** | `warden-lint`, `verify-secrets`, `get-context` — directory-aware, no external deps |
20
+ | **Installer and health** | Cross-app auto-installer, manifest-backed installs, `--doctor`, `--verify-target`, Windsurf adapter |
21
+ | **Hard enforcement** | Claude Code `PreToolUse` hooks — block oversized writes and hardcoded secrets before the file system is touched |
22
+
23
+ ## Governance Evidence
24
+
25
+ Generate a machine-readable governance report that can be stored in CI, attached to PRs, or used as audit evidence:
26
+
27
+ ```bash
28
+ node tools/governance-report.js . # write .code-warden-report.json + summary
29
+ node tools/governance-report.js . --format=json # JSON to stdout
30
+ node tools/governance-report.js . --format=md # Markdown to stdout
31
+ ```
32
+
33
+ The report runs all checks in a single pass (file length, secrets, behavioral tests, source integrity) and produces a structured artifact:
34
+
35
+ ```json
36
+ {
37
+ "tool": "code-warden",
38
+ "version": "3.2.0",
39
+ "checks": {
40
+ "fileLength": { "status": "pass", "filesScanned": 34, "violations": 0 },
41
+ "secrets": { "status": "pass", "filesScanned": 34, "violations": 0 },
42
+ "behavioralTests": { "status": "pass", "tests": 8, "failures": 0 },
43
+ "installHealth": { "status": "pass" }
44
+ },
45
+ "result": "pass"
46
+ }
47
+ ```
48
+
49
+ In CI, the Markdown format pipes directly into `$GITHUB_STEP_SUMMARY` for PR-visible evidence:
50
+
51
+ | Check | Result | Details |
52
+ |-------|--------|---------|
53
+ | File length | PASS | 34 files scanned, 0 violations |
54
+ | Hardcoded credentials | PASS | 34 files scanned, 0 violations |
55
+ | Behavioral tests | PASS | 8 tests, 0 failures |
56
+ | Install health | PASS | All source files present |
57
+
58
+ See [`templates/ci/github-actions.yml`](templates/ci/github-actions.yml) for the full CI template with artifact upload.
59
+
60
+ ## Install
61
+
62
+ ```bash
63
+ npx code-warden init
64
+ ```
65
+
66
+ Or install globally:
67
+
68
+ ```bash
69
+ npm install -g code-warden
70
+ code-warden init
71
+ ```
72
+
73
+ ### CLI commands
74
+
75
+ | Command | Purpose |
76
+ |---------|---------|
77
+ | `code-warden init` | Install to all detected AI runtimes |
78
+ | `code-warden report` | Generate governance report |
79
+ | `code-warden report --format=md` | Markdown output for PR summaries |
80
+ | `code-warden doctor` | Verify source integrity + install health |
81
+ | `code-warden list` | Show detected runtimes |
82
+ | `code-warden hooks claude` | Install Claude Code PreToolUse hooks |
83
+ | `code-warden hooks codex` | Install Codex PreToolUse hooks (partial) |
84
+ | `code-warden uninstall-hooks claude` | Remove Claude Code hooks |
85
+ | `code-warden uninstall-hooks codex` | Remove Codex hooks |
86
+
87
+ ### Direct installer commands
88
+
89
+ | Command | Purpose |
90
+ |---------|---------|
91
+ | `node install.js` | Scan, prompt, install to detected apps |
92
+ | `node install.js --all` | Install without prompt |
93
+ | `node install.js --dry-run` | Preview installs, write nothing |
94
+ | `node install.js --list` | Show detected apps and detection method |
95
+ | `node install.js --doctor` | Verify source integrity + per-target install health |
96
+ | `node install.js --target=claude,cursor` | Force specific targets (warns if not detected) |
97
+ | `node install.js --verify-target=claude` | Strict health checkexits nonzero if not installed |
98
+ | `node install.js --hooks=claude` | Install PreToolUse hooks into `~/.claude/settings.json` |
99
+ | `node install.js --uninstall-hooks=claude` | Remove code-warden hook entries from settings |
100
+
101
+ Supported targets: **Claude Code**, **Cursor**, **Warp**, **OpenAI Codex**, **Windsurf**, **Generic Agents**.
102
+
103
+ Each install writes a `.code-warden-install.json` manifest (version, target, format, timestamp).
104
+
105
+ ### npm scripts
106
+
107
+ ```bash
108
+ npm run lint # warden-lint on full project tree
109
+ npm run check-secrets # verify-secrets on full project tree
110
+ npm run report # governance report, writes .code-warden-report.json
111
+ npm run report:json # governance report as JSON to stdout
112
+ npm run report:md # governance report as Markdown to stdout
113
+ npm run install-auto # node install.js
114
+ npm run install-dry-run # node install.js --dry-run
115
+ npm run install-list # node install.js --list
116
+ npm run install-doctor # node install.js --doctor
117
+ npm run test # behavioral tests (8 scanner/hook pass/fail cases)
118
+ npm run ci # lint + secrets + test + doctor
119
+ ```
120
+
121
+ ## Usage
122
+
123
+ Load at the start of any coding session. Trigger phrases:
124
+
125
+ - `"load code-warden"` / `"load protocol"`
126
+ - `"begin coding"` / `"new session"` / `"governance check"`
127
+ - `"start a new module"` / `"review this before we write"`
128
+
129
+ The session sequence is enforced before any implementation:
130
+
131
+ <p align="center">
132
+ <img src="../logo/session-flow.png" alt="Code-Warden Session Start Sequence" width="100%" />
133
+ </p>
134
+
135
+ 1. Architecture State (Re-injection Rule)
136
+ 2. Session Scope (Session Scoping Rule)
137
+ 3. Reference Files (Blueprint Rule)
138
+ 4. **Scope Gate** — goal, non-goals, files in/out, verify commands, rollback
139
+ 5. **Plan Gate** — patch order, blast radius class, post-patch checks
140
+
141
+ See [`examples/governed-session.md`](examples/governed-session.md) for an annotated example.
142
+
143
+ ## Optional Claude Code Hooks
144
+
145
+ <p align="center">
146
+ <img src="../logo/hook-flow.png" alt="Code-Warden Hook Enforcement Flow" width="100%" />
147
+ </p>
148
+
149
+ Install hard enforcement that runs at the `PreToolUse` level — before writes happen:
150
+
151
+ ```bash
152
+ # Requires Claude Code target to be installed first
153
+ node install.js --hooks=claude
154
+ ```
155
+
156
+ | Hook | Trigger | Policy |
157
+ |------|---------|--------|
158
+ | `warden-lint-hook.js` | `Write` or `Edit` | Blocks if resulting file exceeds line limit |
159
+ | `warden-secrets-hook.js` | `Write` or `Edit` | Hardcoded credential scanner — blocks if content matches any secret pattern |
160
+
161
+ Both hooks use exec form (`node /path/to/hook.js`) — no shell differences across platforms.
162
+
163
+ Thresholds are read from `codewarden.json` in the installed skill directory.
164
+
165
+ ```bash
166
+ node install.js --uninstall-hooks=claude # remove hook entries from settings.json
167
+ ```
168
+
169
+ Doctor and `--verify-target=claude` validate hook script paths when hooks are registered.
170
+
171
+ ## Configuration
172
+
173
+ All thresholds in [`codewarden.json`](codewarden.json):
174
+
175
+ | Setting | Default | What it controls |
176
+ |---------|---------|-----------------|
177
+ | `thresholds.max_file_length` | 400 | Lines before `warden-lint.js` flags a file |
178
+ | `thresholds.pre_flight_trigger_lines` | 150 | Lines before a pre-flight manifest is required |
179
+ | `thresholds.human_checkpoint_files` | 2 | Files touched before `[AWAITING CONFIRMATION]` is required |
180
+ | `safety.exempt_from_blast_radius` | `tests/`, `docs/`, `scripts/` | Paths excluded from rollback-plan rule |
181
+
182
+ See [`CONFIGURE.md`](CONFIGURE.md) for team-size profiles and tuning rationale.
183
+
184
+ ## Reference Files
185
+
186
+ | File | Domain |
187
+ |------|--------|
188
+ | `references/planning-gates.md` | Scope Gate and Plan Gate contracts |
189
+ | `references/architecture.md` | Blueprint Rule, Re-injection, State Update |
190
+ | `references/safety.md` | Blast Radius, Patch-First, Zero-Trust, Dependency Freeze |
191
+ | `references/cognition.md` | Think Before Coding, Don't Guess Syntax, Human Checkpoint |
192
+ | `references/cleanup.md` | Tech Debt format, Test Contract, Decision Log |
193
+ | `references/anti-drift.md` | Anchor Check, Session Scoping, Drift Trigger Protocol |
194
+ | `references/operations.md` | Verification, source-control hygiene, dependency control |
195
+ | `references/research-and-fit.md` | Live research gate, stack fit, product-shape guardrails |
196
+
197
+ ## Author
198
+
199
+ Justin Davis — MIT License