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
@@ -1,132 +1,132 @@
1
- # Example: Governed Session Transcript
2
-
3
- This is an annotated example of a code-warden governed session.
4
- It shows how the rules activate in practice during a real feature request.
5
-
6
- ---
7
-
8
- ## Session: Add user authentication middleware
9
-
10
- **User:** Let's add JWT authentication middleware to the API. It should protect all `/api/v1/` routes.
11
-
12
- ---
13
-
14
- **Assistant (Re-injection Check):**
15
- > Before writing anything, per the Re-injection Rule, let me restate the current architecture:
16
- > - `src/server.ts` - Express app entry point, mounts routers
17
- > - `src/routes/api.ts` - All `/api/v1/` route definitions
18
- > - `src/middleware/` - Existing middleware directory, currently only `logger.ts`
19
- > - No architecture doc found -> applying Re-injection Fallback
20
- >
21
- > **Research/Fit check:** User requested JWT middleware inside an existing Express API.
22
- > The project already has an API runtime and route structure, so adding focused
23
- > middleware fits better than introducing a new auth framework or reshaping the
24
- > app into a dashboard.
25
- >
26
- > **Session scope:** Adding JWT auth middleware. Touching: `middleware/`, `routes/api.ts`, possibly `server.ts`.
27
- > That's 3 files, which crosses the >2 file threshold.
28
- >
29
- > **[AWAITING CONFIRMATION]** - Plan before proceeding:
30
- > 1. Create `src/middleware/auth.ts` - JWT verification logic only
31
- > 2. Create `src/types/auth.types.ts` - Token payload type definition
32
- > 3. Patch `src/routes/api.ts` - Apply middleware to `/api/v1/` router
33
- >
34
- > Blast Radius:
35
- > - **What might break:** Any route under `/api/v1/` that lacks a valid JWT will begin returning 401. No other routes affected.
36
- > - **Test strategy:** Add unit test for `auth.ts`; smoke test unauthenticated request to `/api/v1/users`.
37
- > - **Rollback:** `git checkout HEAD -- src/routes/api.ts && rm src/middleware/auth.ts src/types/auth.types.ts`
38
- >
39
- > Confirm to proceed?
40
-
41
- ---
42
-
43
- **User:** Yes, go ahead.
44
-
45
- ---
46
-
47
- **Assistant:**
48
- > **Pre-flight:**
49
- > - **File:** `src/middleware/auth.ts` - **Lines:** ~35 / 400 max
50
- > - **Concern:** JWT token verification and request gating
51
- > - **Secrets:** env-var sourced: `JWT_SECRET`
52
- > - **Files changed this action:** `auth.ts` (new), `auth.types.ts` (new), `api.ts` (patch)
53
-
54
- **`src/middleware/auth.ts`** (new file, ~35 lines)
55
- ```ts
56
- import { Request, Response, NextFunction } from 'express';
57
- import jwt from 'jsonwebtoken';
58
- import { TokenPayload } from '../types/auth.types';
59
-
60
- export function requireAuth(req: Request, res: Response, next: NextFunction): void {
61
- const header = req.headers.authorization;
62
-
63
- if (!header || !header.startsWith('Bearer ')) {
64
- res.status(401).json({ error: 'Missing or malformed Authorization header' });
65
- return;
66
- }
67
-
68
- const token = header.slice(7);
69
- const secret = process.env.JWT_SECRET;
70
-
71
- if (!secret) {
72
- // Zero-Trust: never fall back to a default secret
73
- res.status(500).json({ error: 'Server misconfiguration' });
74
- return;
75
- }
76
-
77
- try {
78
- const payload = jwt.verify(token, secret) as TokenPayload;
79
- (req as any).user = payload;
80
- next();
81
- } catch {
82
- res.status(401).json({ error: 'Invalid or expired token' });
83
- }
84
- }
85
- ```
86
-
87
- **`src/types/auth.types.ts`** (new file, ~10 lines)
88
- ```ts
89
- export interface TokenPayload {
90
- sub: string;
91
- email: string;
92
- iat: number;
93
- exp: number;
94
- }
95
- ```
96
-
97
- **Patch for `src/routes/api.ts`** (diff only):
98
- ```diff
99
- + import { requireAuth } from '../middleware/auth';
100
-
101
- - router.use('/api/v1', apiRouter);
102
- + router.use('/api/v1', requireAuth, apiRouter);
103
- ```
104
-
105
- > TECH DEBT FLAGGED: `src/routes/api.ts:14` Route file mounts all sub-routers inline.
106
- > Consider splitting into domain-specific router files, such as `routes/users.ts`
107
- > or `routes/orders.ts`, as the API grows. Do not fix now; logged for next cleanup pass.
108
- >
109
- > Decision logged to DECISIONS.md because the change affects 3 files and alters request data flow.
110
- >
111
- > Verification run:
112
- > - `npm test -- auth`
113
- > - Result: passing authentication middleware tests and route protection smoke test.
114
-
115
- ---
116
-
117
- ## What this example demonstrates
118
-
119
- | Rule | Where it fired |
120
- |------|----------------|
121
- | Re-injection Rule | Session opened with architecture restatement |
122
- | Re-injection Fallback | No architecture doc found; fell back to last 3 dependencies |
123
- | Research and Fit | Existing Express API shape was honored instead of introducing a default stack or dashboard pattern |
124
- | Think Before Coding | Execution plan written before any code |
125
- | Human Checkpoint | `[AWAITING CONFIRMATION]` issued at >2-file change |
126
- | Blast Radius Check | Defined before touching existing route file |
127
- | Zero-Trust Secrets | `JWT_SECRET` read from `process.env`, hard failure if missing |
128
- | Patch-First Editing | `api.ts` change delivered as a diff, not a full rewrite |
129
- | Tech Debt Flagged | Inline router mounting noted in correct format |
130
- | Decision Log | Multi-file + data flow change triggers DECISIONS.md entry |
131
- | Anchor Check (Pre-Flight) | Verifiable manifest prepended before code output |
132
- | Verification Before Completion | Command and result reported before claiming the work is done |
1
+ # Example: Governed Session Transcript
2
+
3
+ This is an annotated example of a code-warden governed session.
4
+ It shows how the rules activate in practice during a real feature request.
5
+
6
+ ---
7
+
8
+ ## Session: Add user authentication middleware
9
+
10
+ **User:** Let's add JWT authentication middleware to the API. It should protect all `/api/v1/` routes.
11
+
12
+ ---
13
+
14
+ **Assistant (Re-injection Check):**
15
+ > Before writing anything, per the Re-injection Rule, let me restate the current architecture:
16
+ > - `src/server.ts` - Express app entry point, mounts routers
17
+ > - `src/routes/api.ts` - All `/api/v1/` route definitions
18
+ > - `src/middleware/` - Existing middleware directory, currently only `logger.ts`
19
+ > - No architecture doc found -> applying Re-injection Fallback
20
+ >
21
+ > **Research/Fit check:** User requested JWT middleware inside an existing Express API.
22
+ > The project already has an API runtime and route structure, so adding focused
23
+ > middleware fits better than introducing a new auth framework or reshaping the
24
+ > app into a dashboard.
25
+ >
26
+ > **Session scope:** Adding JWT auth middleware. Touching: `middleware/`, `routes/api.ts`, possibly `server.ts`.
27
+ > That's 3 files, which crosses the >2 file threshold.
28
+ >
29
+ > **[AWAITING CONFIRMATION]** - Plan before proceeding:
30
+ > 1. Create `src/middleware/auth.ts` - JWT verification logic only
31
+ > 2. Create `src/types/auth.types.ts` - Token payload type definition
32
+ > 3. Patch `src/routes/api.ts` - Apply middleware to `/api/v1/` router
33
+ >
34
+ > Blast Radius:
35
+ > - **What might break:** Any route under `/api/v1/` that lacks a valid JWT will begin returning 401. No other routes affected.
36
+ > - **Test strategy:** Add unit test for `auth.ts`; smoke test unauthenticated request to `/api/v1/users`.
37
+ > - **Rollback:** `git checkout HEAD -- src/routes/api.ts && rm src/middleware/auth.ts src/types/auth.types.ts`
38
+ >
39
+ > Confirm to proceed?
40
+
41
+ ---
42
+
43
+ **User:** Yes, go ahead.
44
+
45
+ ---
46
+
47
+ **Assistant:**
48
+ > **Pre-flight:**
49
+ > - **File:** `src/middleware/auth.ts` - **Lines:** ~35 / 400 max
50
+ > - **Concern:** JWT token verification and request gating
51
+ > - **Secrets:** env-var sourced: `JWT_SECRET`
52
+ > - **Files changed this action:** `auth.ts` (new), `auth.types.ts` (new), `api.ts` (patch)
53
+
54
+ **`src/middleware/auth.ts`** (new file, ~35 lines)
55
+ ```ts
56
+ import { Request, Response, NextFunction } from 'express';
57
+ import jwt from 'jsonwebtoken';
58
+ import { TokenPayload } from '../types/auth.types';
59
+
60
+ export function requireAuth(req: Request, res: Response, next: NextFunction): void {
61
+ const header = req.headers.authorization;
62
+
63
+ if (!header || !header.startsWith('Bearer ')) {
64
+ res.status(401).json({ error: 'Missing or malformed Authorization header' });
65
+ return;
66
+ }
67
+
68
+ const token = header.slice(7);
69
+ const secret = process.env.JWT_SECRET;
70
+
71
+ if (!secret) {
72
+ // Zero-Trust: never fall back to a default secret
73
+ res.status(500).json({ error: 'Server misconfiguration' });
74
+ return;
75
+ }
76
+
77
+ try {
78
+ const payload = jwt.verify(token, secret) as TokenPayload;
79
+ (req as any).user = payload;
80
+ next();
81
+ } catch {
82
+ res.status(401).json({ error: 'Invalid or expired token' });
83
+ }
84
+ }
85
+ ```
86
+
87
+ **`src/types/auth.types.ts`** (new file, ~10 lines)
88
+ ```ts
89
+ export interface TokenPayload {
90
+ sub: string;
91
+ email: string;
92
+ iat: number;
93
+ exp: number;
94
+ }
95
+ ```
96
+
97
+ **Patch for `src/routes/api.ts`** (diff only):
98
+ ```diff
99
+ + import { requireAuth } from '../middleware/auth';
100
+
101
+ - router.use('/api/v1', apiRouter);
102
+ + router.use('/api/v1', requireAuth, apiRouter);
103
+ ```
104
+
105
+ > TECH DEBT FLAGGED: `src/routes/api.ts:14` Route file mounts all sub-routers inline.
106
+ > Consider splitting into domain-specific router files, such as `routes/users.ts`
107
+ > or `routes/orders.ts`, as the API grows. Do not fix now; logged for next cleanup pass.
108
+ >
109
+ > Decision logged to DECISIONS.md because the change affects 3 files and alters request data flow.
110
+ >
111
+ > Verification run:
112
+ > - `npm test -- auth`
113
+ > - Result: passing authentication middleware tests and route protection smoke test.
114
+
115
+ ---
116
+
117
+ ## What this example demonstrates
118
+
119
+ | Rule | Where it fired |
120
+ |------|----------------|
121
+ | Re-injection Rule | Session opened with architecture restatement |
122
+ | Re-injection Fallback | No architecture doc found; fell back to last 3 dependencies |
123
+ | Research and Fit | Existing Express API shape was honored instead of introducing a default stack or dashboard pattern |
124
+ | Think Before Coding | Execution plan written before any code |
125
+ | Human Checkpoint | `[AWAITING CONFIRMATION]` issued at >2-file change |
126
+ | Blast Radius Check | Defined before touching existing route file |
127
+ | Zero-Trust Secrets | `JWT_SECRET` read from `process.env`, hard failure if missing |
128
+ | Patch-First Editing | `api.ts` change delivered as a diff, not a full rewrite |
129
+ | Tech Debt Flagged | Inline router mounting noted in correct format |
130
+ | Decision Log | Multi-file + data flow change triggers DECISIONS.md entry |
131
+ | Anchor Check (Pre-Flight) | Verifiable manifest prepended before code output |
132
+ | Verification Before Completion | Command and result reported before claiming the work is done |