code-warden 3.3.0 → 3.3.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 (40) hide show
  1. package/CONFIGURE.md +39 -39
  2. package/DECISIONS.md +107 -107
  3. package/README.md +6 -0
  4. package/SKILL.md +169 -169
  5. package/bin/code-warden.js +82 -82
  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 +62 -62
  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/tools/auto-detect.js +91 -91
  21. package/tools/auto-targets.js +104 -104
  22. package/tools/auto-windsurf-adapter.js +75 -75
  23. package/tools/get-context.js +50 -50
  24. package/tools/governance-report.js +302 -302
  25. package/tools/hooks/claude/install-hooks.js +112 -112
  26. package/tools/hooks/claude/uninstall-hooks.js +75 -75
  27. package/tools/hooks/claude/warden-lint-hook.js +106 -106
  28. package/tools/hooks/claude/warden-secrets-hook.js +73 -73
  29. package/tools/hooks/codex/install-hooks.js +100 -100
  30. package/tools/hooks/codex/uninstall-hooks.js +53 -53
  31. package/tools/hooks/codex/warden-apply-patch-hook.js +113 -113
  32. package/tools/hooks/codex/warden-bash-hook.js +51 -51
  33. package/tools/lib/config.js +49 -49
  34. package/tools/lib/file-collection.js +5 -2
  35. package/tools/lib/line-count.js +28 -28
  36. package/tools/lib/secret-patterns.js +57 -57
  37. package/tools/tests/fixtures/clean.js +9 -9
  38. package/tools/tests/run-tests.js +210 -210
  39. package/tools/verify-secrets.js +26 -26
  40. package/tools/warden-lint.js +27 -27
package/SKILL.md CHANGED
@@ -1,169 +1,169 @@
1
- ---
2
- name: code-warden
3
- description: >
4
- AI development governance protocol for Codex, Claude Code, and Cowork.
5
- Enforces modular architecture, adversarial feedback, patch-first editing,
6
- blast radius safety, zero-trust secrets, and context drift prevention. Use at
7
- the start of any coding session, when generating or modifying modules, when
8
- refactoring existing code, when making architectural changes, or when any of
9
- the following are said: "load protocol", "apply dev rules", "check the rules",
10
- "start a new module", "review this before we write", "are we following the
11
- rules", "new session", "begin coding", "load code-warden", "governance check",
12
- or any request to begin writing code.
13
- metadata:
14
- author: Justin Davis
15
- version: 3.1.1
16
- category: development-governance
17
- changelog: |
18
- v3.1.1 (2026-05-15): Stabilization. Behavioral tests (8 scanner/hook pass/fail
19
- cases via node:test). Shared policy modules: lib/line-count.js, lib/secret-patterns.js,
20
- lib/file-collection.js, lib/config.js. Line-count off-by-one fixed (trailing newline).
21
- Secret-pattern drift fixed (GitHub token gh[posx]_ → gh[pousr]_ unified across all consumers).
22
- README wording: zero-trust secrets policy (governance) vs hardcoded credential scanner (impl).
23
- v3.1.0 (2026-05-15): Codex partial hook enforcement. --hooks=codex installs
24
- PreToolUse hooks for apply_patch (secrets + estimated size) and Bash (secrets).
25
- Hooks live in tools/hooks/codex/. Claude hooks moved to tools/hooks/claude/.
26
- Doctor and verify-target validate Codex hook paths via ~/.codex/hooks.json.
27
- v3.0.0 (2026-05-15): Optional Claude Code hooks package. --hooks=claude installs
28
- PreToolUse hooks that block writes violating file-length or zero-trust secrets
29
- policy before they happen. --uninstall-hooks=claude removes them. Doctor and
30
- verify-target validate hook script paths when hooks are registered.
31
- v2.8.0 (2026-05-15): Added --verify-target=<id> strict per-target health check.
32
- Unknown target IDs exit nonzero. Known but not-installed targets exit nonzero.
33
- Added npm scripts: install-list, install-doctor.
34
- v2.7.1 (2026-05-15): Added Scope Gate and Plan Gate pre-implementation declaration
35
- blocks. Both gates must be confirmed before any code is written. Covers goal,
36
- non-goals, files in/out, patch order, blast radius class, and post-patch checks.
37
- v2.7.0 (2026-05-15): Added GitHub Actions CI template and npm run ci script.
38
- Code-Warden now enforces file length and zero-trust secrets outside the chat session.
39
- v2.6.0 (2026-05-15): Added cross-platform auto-installer with app detection,
40
- atomic install, --doctor health checks, and Windsurf flat-file adapter.
41
- v2.5.0 (2026-05-14): Added Research and Fit governance to force live research
42
- for current facts and challenge default stack/product assumptions.
43
- v2.4.0 (2026-05-14): Added operational governance for verification evidence,
44
- source-control hygiene, dependency control, and technical claim sourcing.
45
- v2.3.1 (2026-05-14): Added Codex/shared-agent install support, AGENTS.md context discovery,
46
- ASCII tool output for reliable terminals, and refreshed setup docs.
47
- v2.3.0 (2026-03-26): Added stronger secret scanner, Windows installer, README, version sync,
48
- and broader Claude context discovery.
49
- v2.2.3 (2026-03-25): Replaced soft checklist with mandatory Hard Gate output block.
50
- v2.2.2 (2026-03-25): Added verifiable Pre-Flight manifest, CONFIGURE.md, and examples.
51
- v2.2.1 (2026-03-25): Fixed reference paths, triggers, DECISIONS.md stub, and checkpoint threshold.
52
- v2.2.0: Added anti-drift.md, Anchor Check, and Drift Trigger Response Protocol.
53
- v2.1.0: Added modular references for safety, cognition, cleanup, architecture, and anti-drift.
54
- v2.0.0: Initial production release.
55
- ---
56
-
57
- # code-warden v3.1.1
58
-
59
- Production-grade AI development governance skill.
60
- Load at the start of every session involving code generation, refactoring,
61
- or architectural changes.
62
-
63
- ## Session Start - HARD GATE
64
-
65
- Do not ask implementation questions. Do not gather requirements. Do not proceed
66
- past this block until all outputs are produced and confirmed by the user.
67
-
68
- Mandatory sequence — produce in order, each confirmed before the next:
69
-
70
- 1. **Architecture State** (below)
71
- 2. **Session Scope** (below)
72
- 3. **Reference Files** (below)
73
- 4. **Scope Gate** — see [references/planning-gates.md](references/planning-gates.md)
74
- 5. **Plan Gate** — see [references/planning-gates.md](references/planning-gates.md) (fires after Scope Gate confirmed)
75
-
76
- Before responding, execute `node <installed-skill-dir>/tools/get-context.js` if
77
- you lack architectural context.
78
-
79
- Common install directories:
80
- - Codex shared agents: `~/.agents/skills/code-warden`
81
- - Codex local skills: `~/.codex/skills/code-warden`
82
- - Claude Code: `~/.claude/skills/code-warden`
83
-
84
- Output this block as your first response before anything else:
85
-
86
- ---
87
-
88
- **ARCHITECTURE STATE** (Re-injection Rule)
89
-
90
- [Paste the context found by `get-context.js` or provided by user. If none found, write:]
91
-
92
- > [WARN] No architecture doc found - applying Re-injection Fallback:
93
- > - Last known files: [list any files mentioned in this session]
94
- > - Current data flow: [unknown - user must provide before proceeding]
95
- >
96
- > **REQUEST:** Paste your architecture doc, PRD, or a 3-sentence scope
97
- > summary before we continue.
98
-
99
- **SESSION SCOPE** (Session Scoping Rule)
100
-
101
- > This session is scoped to: [module/feature name]
102
- > Files in scope: [list]
103
- > Files explicitly OUT of scope: [everything else]
104
-
105
- [If scope is unknown, write:]
106
-
107
- > [WARN] Scope undefined - user must confirm before proceeding.
108
-
109
- **REFERENCE FILES LOADED** (Blueprint Rule)
110
-
111
- > For this task, loading: [list relevant references/ files]
112
- > Status: [PASS found | WARN missing from install - rules enforced from prompt]
113
-
114
- ---
115
-
116
- Do not proceed until the user replies "confirmed" or provides the missing
117
- information above.
118
-
119
- ## Quick Rules
120
-
121
- - **Scope Gate**: Required before every session. Declare goal, non-goals, files in/out, verify commands, rollback plan. See `references/planning-gates.md`.
122
- - **Plan Gate**: Required before any multi-file or >30-line change. Declare patch order, blast radius class, post-patch checks. See `references/planning-gates.md`.
123
- - **Max file size**: Enforced by `warden-lint.js` (default 400 lines). Split into modules at the limit.
124
- - **Editing mode**: Patch/diff first. No full rewrites without blast radius check.
125
- - **Feedback mode**: Adversarial. Correctness over comfort; push back on weak logic.
126
- - **Secrets**: Zero-trust. Enforced by `verify-secrets.js`; no hardcoded keys.
127
- - **Uncertainty**: Say so. Never guess niche syntax or stale API behavior.
128
- - **Concerns**: One responsibility per file. Support human auditing.
129
- - **Verification**: Run meaningful checks before claiming completion; report command and result.
130
- - **Source control**: Inspect dirty state where available; never revert user changes without explicit request.
131
- - **Dependencies**: Do not add, remove, upgrade, or replace packages without evidence and explicit reasoning.
132
- - **Evidence**: Ground technical claims in local files, command output, official docs, or clear uncertainty.
133
- - **Research**: Use live research for current, version-specific, or fast-changing facts.
134
- - **Fit over defaults**: Challenge familiar stack and product-shape defaults before choosing Node, React, dashboards, or CRUD patterns.
135
-
136
- ## Reference Files
137
-
138
- Load these when relevant to the current task:
139
-
140
- - Scope Gate, Plan Gate, blast radius class, patch order -> [references/planning-gates.md](references/planning-gates.md)
141
- - Architecture decisions, Blueprint Rule, Re-injection -> [references/architecture.md](references/architecture.md)
142
- - Blast Radius, Patch-First, Zero-Trust, Dependency Freeze -> [references/safety.md](references/safety.md)
143
- - Think Before Coding, Don't Guess Syntax, Human Checkpoint -> [references/cognition.md](references/cognition.md)
144
- - Tech Debt flag format, Test Contract, Decision Log -> [references/cleanup.md](references/cleanup.md)
145
- - Anchor Check, Session Scoping, Drift Trigger -> [references/anti-drift.md](references/anti-drift.md)
146
- - Verification, git hygiene, dependency control, evidence -> [references/operations.md](references/operations.md)
147
- - Live research, anti-default stack choices, product-shape fit -> [references/research-and-fit.md](references/research-and-fit.md)
148
-
149
- ## Drift Signals - Hard Stop
150
-
151
- Stop and re-anchor immediately if any of these appear:
152
-
153
- | Signal | Action |
154
- |--------|--------|
155
- | Began implementing without a confirmed Scope Gate | Stop, produce Scope Gate, await confirmation |
156
- | Began implementing without a confirmed Plan Gate | Stop, produce Plan Gate, await confirmation |
157
- | Touched a file not declared in Scope Gate | Stop, declare scope expansion, await approval |
158
- | Guessed library syntax without searching docs | Search live docs, correct output |
159
- | Used stale training data for current facts | Run live research or mark unverified |
160
- | Chose a default stack/product shape without fit check | Compare alternatives against project constraints |
161
- | Unexplained contiguous block > limit | Run `warden-lint.js`, split if needed |
162
- | Skipped Blast Radius Check before a rewrite | Run check before proceeding |
163
- | Claimed completion without verification evidence | Run relevant checks or state residual risk |
164
- | Changed dependencies without version/source evidence | Stop, inspect package metadata and lockfile |
165
- | Edited in a dirty repo without checking ownership | Inspect status and preserve user changes |
166
- | No `[AWAITING CONFIRMATION]` before >2-file change | Pause and request confirmation |
167
- | Monolithic file output without module split | Refactor into separated concerns |
168
-
169
- All limits and thresholds are defined in `codewarden.json`.
1
+ ---
2
+ name: code-warden
3
+ description: >
4
+ AI development governance protocol for Codex, Claude Code, and Cowork.
5
+ Enforces modular architecture, adversarial feedback, patch-first editing,
6
+ blast radius safety, zero-trust secrets, and context drift prevention. Use at
7
+ the start of any coding session, when generating or modifying modules, when
8
+ refactoring existing code, when making architectural changes, or when any of
9
+ the following are said: "load protocol", "apply dev rules", "check the rules",
10
+ "start a new module", "review this before we write", "are we following the
11
+ rules", "new session", "begin coding", "load code-warden", "governance check",
12
+ or any request to begin writing code.
13
+ metadata:
14
+ author: Justin Davis
15
+ version: 3.1.1
16
+ category: development-governance
17
+ changelog: |
18
+ v3.1.1 (2026-05-15): Stabilization. Behavioral tests (8 scanner/hook pass/fail
19
+ cases via node:test). Shared policy modules: lib/line-count.js, lib/secret-patterns.js,
20
+ lib/file-collection.js, lib/config.js. Line-count off-by-one fixed (trailing newline).
21
+ Secret-pattern drift fixed (GitHub token gh[posx]_ → gh[pousr]_ unified across all consumers).
22
+ README wording: zero-trust secrets policy (governance) vs hardcoded credential scanner (impl).
23
+ v3.1.0 (2026-05-15): Codex partial hook enforcement. --hooks=codex installs
24
+ PreToolUse hooks for apply_patch (secrets + estimated size) and Bash (secrets).
25
+ Hooks live in tools/hooks/codex/. Claude hooks moved to tools/hooks/claude/.
26
+ Doctor and verify-target validate Codex hook paths via ~/.codex/hooks.json.
27
+ v3.0.0 (2026-05-15): Optional Claude Code hooks package. --hooks=claude installs
28
+ PreToolUse hooks that block writes violating file-length or zero-trust secrets
29
+ policy before they happen. --uninstall-hooks=claude removes them. Doctor and
30
+ verify-target validate hook script paths when hooks are registered.
31
+ v2.8.0 (2026-05-15): Added --verify-target=<id> strict per-target health check.
32
+ Unknown target IDs exit nonzero. Known but not-installed targets exit nonzero.
33
+ Added npm scripts: install-list, install-doctor.
34
+ v2.7.1 (2026-05-15): Added Scope Gate and Plan Gate pre-implementation declaration
35
+ blocks. Both gates must be confirmed before any code is written. Covers goal,
36
+ non-goals, files in/out, patch order, blast radius class, and post-patch checks.
37
+ v2.7.0 (2026-05-15): Added GitHub Actions CI template and npm run ci script.
38
+ Code-Warden now enforces file length and zero-trust secrets outside the chat session.
39
+ v2.6.0 (2026-05-15): Added cross-platform auto-installer with app detection,
40
+ atomic install, --doctor health checks, and Windsurf flat-file adapter.
41
+ v2.5.0 (2026-05-14): Added Research and Fit governance to force live research
42
+ for current facts and challenge default stack/product assumptions.
43
+ v2.4.0 (2026-05-14): Added operational governance for verification evidence,
44
+ source-control hygiene, dependency control, and technical claim sourcing.
45
+ v2.3.1 (2026-05-14): Added Codex/shared-agent install support, AGENTS.md context discovery,
46
+ ASCII tool output for reliable terminals, and refreshed setup docs.
47
+ v2.3.0 (2026-03-26): Added stronger secret scanner, Windows installer, README, version sync,
48
+ and broader Claude context discovery.
49
+ v2.2.3 (2026-03-25): Replaced soft checklist with mandatory Hard Gate output block.
50
+ v2.2.2 (2026-03-25): Added verifiable Pre-Flight manifest, CONFIGURE.md, and examples.
51
+ v2.2.1 (2026-03-25): Fixed reference paths, triggers, DECISIONS.md stub, and checkpoint threshold.
52
+ v2.2.0: Added anti-drift.md, Anchor Check, and Drift Trigger Response Protocol.
53
+ v2.1.0: Added modular references for safety, cognition, cleanup, architecture, and anti-drift.
54
+ v2.0.0: Initial production release.
55
+ ---
56
+
57
+ # code-warden v3.1.1
58
+
59
+ Production-grade AI development governance skill.
60
+ Load at the start of every session involving code generation, refactoring,
61
+ or architectural changes.
62
+
63
+ ## Session Start - HARD GATE
64
+
65
+ Do not ask implementation questions. Do not gather requirements. Do not proceed
66
+ past this block until all outputs are produced and confirmed by the user.
67
+
68
+ Mandatory sequence — produce in order, each confirmed before the next:
69
+
70
+ 1. **Architecture State** (below)
71
+ 2. **Session Scope** (below)
72
+ 3. **Reference Files** (below)
73
+ 4. **Scope Gate** — see [references/planning-gates.md](references/planning-gates.md)
74
+ 5. **Plan Gate** — see [references/planning-gates.md](references/planning-gates.md) (fires after Scope Gate confirmed)
75
+
76
+ Before responding, execute `node <installed-skill-dir>/tools/get-context.js` if
77
+ you lack architectural context.
78
+
79
+ Common install directories:
80
+ - Codex shared agents: `~/.agents/skills/code-warden`
81
+ - Codex local skills: `~/.codex/skills/code-warden`
82
+ - Claude Code: `~/.claude/skills/code-warden`
83
+
84
+ Output this block as your first response before anything else:
85
+
86
+ ---
87
+
88
+ **ARCHITECTURE STATE** (Re-injection Rule)
89
+
90
+ [Paste the context found by `get-context.js` or provided by user. If none found, write:]
91
+
92
+ > [WARN] No architecture doc found - applying Re-injection Fallback:
93
+ > - Last known files: [list any files mentioned in this session]
94
+ > - Current data flow: [unknown - user must provide before proceeding]
95
+ >
96
+ > **REQUEST:** Paste your architecture doc, PRD, or a 3-sentence scope
97
+ > summary before we continue.
98
+
99
+ **SESSION SCOPE** (Session Scoping Rule)
100
+
101
+ > This session is scoped to: [module/feature name]
102
+ > Files in scope: [list]
103
+ > Files explicitly OUT of scope: [everything else]
104
+
105
+ [If scope is unknown, write:]
106
+
107
+ > [WARN] Scope undefined - user must confirm before proceeding.
108
+
109
+ **REFERENCE FILES LOADED** (Blueprint Rule)
110
+
111
+ > For this task, loading: [list relevant references/ files]
112
+ > Status: [PASS found | WARN missing from install - rules enforced from prompt]
113
+
114
+ ---
115
+
116
+ Do not proceed until the user replies "confirmed" or provides the missing
117
+ information above.
118
+
119
+ ## Quick Rules
120
+
121
+ - **Scope Gate**: Required before every session. Declare goal, non-goals, files in/out, verify commands, rollback plan. See `references/planning-gates.md`.
122
+ - **Plan Gate**: Required before any multi-file or >30-line change. Declare patch order, blast radius class, post-patch checks. See `references/planning-gates.md`.
123
+ - **Max file size**: Enforced by `warden-lint.js` (default 400 lines). Split into modules at the limit.
124
+ - **Editing mode**: Patch/diff first. No full rewrites without blast radius check.
125
+ - **Feedback mode**: Adversarial. Correctness over comfort; push back on weak logic.
126
+ - **Secrets**: Zero-trust. Enforced by `verify-secrets.js`; no hardcoded keys.
127
+ - **Uncertainty**: Say so. Never guess niche syntax or stale API behavior.
128
+ - **Concerns**: One responsibility per file. Support human auditing.
129
+ - **Verification**: Run meaningful checks before claiming completion; report command and result.
130
+ - **Source control**: Inspect dirty state where available; never revert user changes without explicit request.
131
+ - **Dependencies**: Do not add, remove, upgrade, or replace packages without evidence and explicit reasoning.
132
+ - **Evidence**: Ground technical claims in local files, command output, official docs, or clear uncertainty.
133
+ - **Research**: Use live research for current, version-specific, or fast-changing facts.
134
+ - **Fit over defaults**: Challenge familiar stack and product-shape defaults before choosing Node, React, dashboards, or CRUD patterns.
135
+
136
+ ## Reference Files
137
+
138
+ Load these when relevant to the current task:
139
+
140
+ - Scope Gate, Plan Gate, blast radius class, patch order -> [references/planning-gates.md](references/planning-gates.md)
141
+ - Architecture decisions, Blueprint Rule, Re-injection -> [references/architecture.md](references/architecture.md)
142
+ - Blast Radius, Patch-First, Zero-Trust, Dependency Freeze -> [references/safety.md](references/safety.md)
143
+ - Think Before Coding, Don't Guess Syntax, Human Checkpoint -> [references/cognition.md](references/cognition.md)
144
+ - Tech Debt flag format, Test Contract, Decision Log -> [references/cleanup.md](references/cleanup.md)
145
+ - Anchor Check, Session Scoping, Drift Trigger -> [references/anti-drift.md](references/anti-drift.md)
146
+ - Verification, git hygiene, dependency control, evidence -> [references/operations.md](references/operations.md)
147
+ - Live research, anti-default stack choices, product-shape fit -> [references/research-and-fit.md](references/research-and-fit.md)
148
+
149
+ ## Drift Signals - Hard Stop
150
+
151
+ Stop and re-anchor immediately if any of these appear:
152
+
153
+ | Signal | Action |
154
+ |--------|--------|
155
+ | Began implementing without a confirmed Scope Gate | Stop, produce Scope Gate, await confirmation |
156
+ | Began implementing without a confirmed Plan Gate | Stop, produce Plan Gate, await confirmation |
157
+ | Touched a file not declared in Scope Gate | Stop, declare scope expansion, await approval |
158
+ | Guessed library syntax without searching docs | Search live docs, correct output |
159
+ | Used stale training data for current facts | Run live research or mark unverified |
160
+ | Chose a default stack/product shape without fit check | Compare alternatives against project constraints |
161
+ | Unexplained contiguous block > limit | Run `warden-lint.js`, split if needed |
162
+ | Skipped Blast Radius Check before a rewrite | Run check before proceeding |
163
+ | Claimed completion without verification evidence | Run relevant checks or state residual risk |
164
+ | Changed dependencies without version/source evidence | Stop, inspect package metadata and lockfile |
165
+ | Edited in a dirty repo without checking ownership | Inspect status and preserve user changes |
166
+ | No `[AWAITING CONFIRMATION]` before >2-file change | Pause and request confirmation |
167
+ | Monolithic file output without module split | Refactor into separated concerns |
168
+
169
+ All limits and thresholds are defined in `codewarden.json`.
@@ -1,82 +1,82 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- const { spawnSync } = require('child_process');
5
- const path = require('path');
6
-
7
- const ROOT = path.join(__dirname, '..');
8
-
9
- const COMMANDS = {
10
- init: { desc: 'Install Code-Warden to detected AI runtimes', run: ['install.js', '--all'] },
11
- doctor: { desc: 'Verify source integrity and install health', run: ['install.js', '--doctor'] },
12
- report: { desc: 'Generate governance report (.code-warden-report.json)', run: ['tools/governance-report.js', '.'] },
13
- list: { desc: 'Show detected AI runtimes', run: ['install.js', '--list'] },
14
- };
15
-
16
- const HOOK_TARGETS = ['claude', 'codex'];
17
-
18
- function usage() {
19
- console.log('Usage: code-warden <command> [options]\n');
20
- console.log('Commands:');
21
- for (const [name, { desc }] of Object.entries(COMMANDS)) {
22
- console.log(` ${name.padEnd(22)} ${desc}`);
23
- }
24
- console.log(` ${'hooks <target>'.padEnd(22)} Install PreToolUse hooks (${HOOK_TARGETS.join(', ')})`);
25
- console.log(` ${'uninstall-hooks <target>'.padEnd(22)} Remove PreToolUse hooks`);
26
- console.log(`\nExamples:`);
27
- console.log(` npx code-warden init`);
28
- console.log(` npx code-warden report`);
29
- console.log(` npx code-warden report --format=md`);
30
- console.log(` npx code-warden hooks claude`);
31
- }
32
-
33
- function run(scriptPath, args) {
34
- const result = spawnSync(process.execPath, [path.join(ROOT, scriptPath), ...args], {
35
- stdio: 'inherit',
36
- cwd: process.cwd(),
37
- });
38
- process.exit(result.status ?? 1);
39
- }
40
-
41
- const args = process.argv.slice(2);
42
- const command = args[0];
43
- const rest = args.slice(1);
44
-
45
- if (!command || command === '--help' || command === '-h') {
46
- usage();
47
- process.exit(0);
48
- }
49
-
50
- if (command === '--version' || command === '-v') {
51
- const pkg = require(path.join(ROOT, 'package.json'));
52
- console.log(pkg.version);
53
- process.exit(0);
54
- }
55
-
56
- if (COMMANDS[command]) {
57
- const entry = COMMANDS[command];
58
- const scriptArgs = [...entry.run.slice(1), ...rest];
59
- run(entry.run[0], scriptArgs);
60
- }
61
-
62
- if (command === 'hooks') {
63
- const target = rest[0];
64
- if (!target || !HOOK_TARGETS.includes(target)) {
65
- console.error(`Usage: code-warden hooks <${HOOK_TARGETS.join('|')}>`);
66
- process.exit(1);
67
- }
68
- run('install.js', [`--hooks=${target}`]);
69
- }
70
-
71
- if (command === 'uninstall-hooks') {
72
- const target = rest[0];
73
- if (!target || !HOOK_TARGETS.includes(target)) {
74
- console.error(`Usage: code-warden uninstall-hooks <${HOOK_TARGETS.join('|')}>`);
75
- process.exit(1);
76
- }
77
- run('install.js', [`--uninstall-hooks=${target}`]);
78
- }
79
-
80
- console.error(`Unknown command: ${command}\n`);
81
- usage();
82
- process.exit(1);
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { spawnSync } = require('child_process');
5
+ const path = require('path');
6
+
7
+ const ROOT = path.join(__dirname, '..');
8
+
9
+ const COMMANDS = {
10
+ init: { desc: 'Install Code-Warden to detected AI runtimes', run: ['install.js', '--all'] },
11
+ doctor: { desc: 'Verify source integrity and install health', run: ['install.js', '--doctor'] },
12
+ report: { desc: 'Generate governance report (.code-warden-report.json)', run: ['tools/governance-report.js', '.'] },
13
+ list: { desc: 'Show detected AI runtimes', run: ['install.js', '--list'] },
14
+ };
15
+
16
+ const HOOK_TARGETS = ['claude', 'codex'];
17
+
18
+ function usage() {
19
+ console.log('Usage: code-warden <command> [options]\n');
20
+ console.log('Commands:');
21
+ for (const [name, { desc }] of Object.entries(COMMANDS)) {
22
+ console.log(` ${name.padEnd(22)} ${desc}`);
23
+ }
24
+ console.log(` ${'hooks <target>'.padEnd(22)} Install PreToolUse hooks (${HOOK_TARGETS.join(', ')})`);
25
+ console.log(` ${'uninstall-hooks <target>'.padEnd(22)} Remove PreToolUse hooks`);
26
+ console.log(`\nExamples:`);
27
+ console.log(` npx code-warden init`);
28
+ console.log(` npx code-warden report`);
29
+ console.log(` npx code-warden report --format=md`);
30
+ console.log(` npx code-warden hooks claude`);
31
+ }
32
+
33
+ function run(scriptPath, args) {
34
+ const result = spawnSync(process.execPath, [path.join(ROOT, scriptPath), ...args], {
35
+ stdio: 'inherit',
36
+ cwd: process.cwd(),
37
+ });
38
+ process.exit(result.status ?? 1);
39
+ }
40
+
41
+ const args = process.argv.slice(2);
42
+ const command = args[0];
43
+ const rest = args.slice(1);
44
+
45
+ if (!command || command === '--help' || command === '-h') {
46
+ usage();
47
+ process.exit(0);
48
+ }
49
+
50
+ if (command === '--version' || command === '-v') {
51
+ const pkg = require(path.join(ROOT, 'package.json'));
52
+ console.log(pkg.version);
53
+ process.exit(0);
54
+ }
55
+
56
+ if (COMMANDS[command]) {
57
+ const entry = COMMANDS[command];
58
+ const scriptArgs = [...entry.run.slice(1), ...rest];
59
+ run(entry.run[0], scriptArgs);
60
+ }
61
+
62
+ if (command === 'hooks') {
63
+ const target = rest[0];
64
+ if (!target || !HOOK_TARGETS.includes(target)) {
65
+ console.error(`Usage: code-warden hooks <${HOOK_TARGETS.join('|')}>`);
66
+ process.exit(1);
67
+ }
68
+ run('install.js', [`--hooks=${target}`]);
69
+ }
70
+
71
+ if (command === 'uninstall-hooks') {
72
+ const target = rest[0];
73
+ if (!target || !HOOK_TARGETS.includes(target)) {
74
+ console.error(`Usage: code-warden uninstall-hooks <${HOOK_TARGETS.join('|')}>`);
75
+ process.exit(1);
76
+ }
77
+ run('install.js', [`--uninstall-hooks=${target}`]);
78
+ }
79
+
80
+ console.error(`Unknown command: ${command}\n`);
81
+ usage();
82
+ process.exit(1);
package/codewarden.json CHANGED
@@ -1,14 +1,14 @@
1
- {
2
- "thresholds": {
3
- "max_file_length": 400,
4
- "pre_flight_trigger_lines": 150,
5
- "human_checkpoint_files": 2
6
- },
7
- "safety": {
8
- "exempt_from_blast_radius": [
9
- "tests/",
10
- "docs/",
11
- "scripts/"
12
- ]
13
- }
14
- }
1
+ {
2
+ "thresholds": {
3
+ "max_file_length": 400,
4
+ "pre_flight_trigger_lines": 150,
5
+ "human_checkpoint_files": 2
6
+ },
7
+ "safety": {
8
+ "exempt_from_blast_radius": [
9
+ "tests/",
10
+ "docs/",
11
+ "scripts/"
12
+ ]
13
+ }
14
+ }