code-warden 3.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 (39) hide show
  1. package/CONFIGURE.md +39 -0
  2. package/DECISIONS.md +107 -0
  3. package/README.md +137 -0
  4. package/SKILL.md +169 -0
  5. package/codewarden.json +14 -0
  6. package/examples/governed-session.md +132 -0
  7. package/install.js +399 -0
  8. package/install.ps1 +32 -0
  9. package/install.sh +33 -0
  10. package/package.json +19 -0
  11. package/references/anti-drift.md +55 -0
  12. package/references/architecture.md +26 -0
  13. package/references/cleanup.md +30 -0
  14. package/references/cognition.md +36 -0
  15. package/references/operations.md +45 -0
  16. package/references/planning-gates.md +83 -0
  17. package/references/research-and-fit.md +51 -0
  18. package/references/safety.md +31 -0
  19. package/templates/ci/github-actions.yml +66 -0
  20. package/tools/auto-detect.js +91 -0
  21. package/tools/auto-targets.js +104 -0
  22. package/tools/auto-windsurf-adapter.js +75 -0
  23. package/tools/get-context.js +50 -0
  24. package/tools/hooks/claude/install-hooks.js +112 -0
  25. package/tools/hooks/claude/uninstall-hooks.js +75 -0
  26. package/tools/hooks/claude/warden-lint-hook.js +106 -0
  27. package/tools/hooks/claude/warden-secrets-hook.js +73 -0
  28. package/tools/hooks/codex/install-hooks.js +100 -0
  29. package/tools/hooks/codex/uninstall-hooks.js +53 -0
  30. package/tools/hooks/codex/warden-apply-patch-hook.js +113 -0
  31. package/tools/hooks/codex/warden-bash-hook.js +51 -0
  32. package/tools/lib/config.js +49 -0
  33. package/tools/lib/file-collection.js +72 -0
  34. package/tools/lib/line-count.js +28 -0
  35. package/tools/lib/secret-patterns.js +57 -0
  36. package/tools/tests/fixtures/clean.js +9 -0
  37. package/tools/tests/run-tests.js +210 -0
  38. package/tools/verify-secrets.js +26 -0
  39. package/tools/warden-lint.js +27 -0
package/CONFIGURE.md ADDED
@@ -0,0 +1,39 @@
1
+ # Configuration Guide
2
+
3
+ CodeWarden now uses a machine-readable configuration file: `codewarden.json`.
4
+ Every threshold is tunable through this file, making it easy to share settings across your team.
5
+
6
+ ---
7
+
8
+ ## The `codewarden.json` File
9
+
10
+ Located at the root of the skill folder. Default configuration:
11
+
12
+ ```json
13
+ {
14
+ "thresholds": {
15
+ "max_file_length": 400,
16
+ "pre_flight_trigger_lines": 150,
17
+ "human_checkpoint_files": 2
18
+ },
19
+ "safety": {
20
+ "exempt_from_blast_radius": ["tests/", "docs/", "scripts/"]
21
+ }
22
+ }
23
+ ```
24
+
25
+ | Setting | Default | Rationale |
26
+ |---------|---------|-----------|
27
+ | `max_file_length` | 400 | Keeps files reviewable in a single pass. The `warden-lint.js` script enforces this. |
28
+ | `pre_flight_trigger_lines` | 150 | Forces a JSON manifest before large outputs. |
29
+ | `human_checkpoint_files` | 2 | Requires human `[AWAITING CONFIRMATION]` before modifying this many files simultaneously. |
30
+ | `exempt_from_blast_radius` | (list) | Skips strict rewriting rollback plans on these file directories. |
31
+
32
+ ---
33
+
34
+ ## How to Customize
35
+
36
+ 1. **Open** `codewarden.json` in your `.claude/skills/code-warden/` directory.
37
+ 2. **Modify** the specific rule or threshold inside the JSON structural fields.
38
+ 3. The executable tools (`tools/warden-lint.js`, etc.) read these limits dynamically so no Markdown files need to be edited to enforce limits.
39
+ 4. **Log the change** in `DECISIONS.md` so your team knows why the default was overridden.
package/DECISIONS.md ADDED
@@ -0,0 +1,107 @@
1
+ # DECISIONS.md
2
+
3
+ Decision log for this project. Maintained per the code-warden cleanup protocol.
4
+
5
+ ## Format
6
+
7
+ Each entry:
8
+ - **Date**: YYYY-MM-DD
9
+ - **Decision**: What was decided
10
+ - **Alternatives**: What else was considered
11
+ - **Reasoning**: Why this choice was made, with links where applicable
12
+ - **Files Affected**: List of files changed
13
+
14
+ ---
15
+
16
+ <!-- Append new decisions below this line -->
17
+
18
+ ---
19
+
20
+ ## 2026-05-15 - Codex partial hook enforcement — apply_patch and Bash (ADR)
21
+
22
+ - **Decision**: Ship Codex hook support as "partial hard enforcement" covering `apply_patch` and `Bash` tool calls. Claude hooks are moved to `tools/hooks/claude/`. Codex hooks live at `tools/hooks/codex/`. Each runtime gets its own installer/uninstaller. `install.js` dispatches dynamically via `require('./tools/hooks/${id}/install-hooks')`.
23
+ - **Alternatives considered**:
24
+ - Full Codex parity with Claude (Write/Edit blocking). Rejected: Codex does not expose Write/Edit as hookable tool calls. `apply_patch` and `Bash` are the only available hook surfaces.
25
+ - Single hooks/ directory without runtime subdirs. Rejected: creates naming collisions and makes the difference in behavior invisible.
26
+ - TOML config for Codex. Rejected: `~/.codex/hooks.json` (JSON) avoids a TOML parser dependency and matches the installer pattern already proven with `settings.json`.
27
+ - **Reasoning**: Codex exposes two tool surfaces at PreToolUse — `apply_patch` (for file writes) and `Bash` (for shell execution). Both are realistic vectors for hardcoded secrets. The `apply_patch` hook also estimates resulting file size where a target path is extractable. This covers the most dangerous Codex operations without claiming full parity with the Claude hook surface.
28
+ - **Consequence**: Codex cannot block oversized line counts for net-new files created via `cat >>` or `tee` in Bash. This gap is documented in the README compatibility matrix. CI enforcement (`npm run lint`) closes it at the pipeline level.
29
+ - **Files affected**: `tools/hooks/claude/` (renamed from `tools/hooks/`), `tools/hooks/codex/warden-apply-patch-hook.js`, `tools/hooks/codex/warden-bash-hook.js`, `tools/hooks/codex/install-hooks.js`, `tools/hooks/codex/uninstall-hooks.js`, `install.js`, `package.json`, `SKILL.md`, `DECISIONS.md`
30
+
31
+ ---
32
+
33
+ ## 2026-05-15 - Claude hooks live inside the installed skill path (ADR)
34
+
35
+ - **Decision**: Code-warden Claude hooks (`warden-lint-hook.js`, `warden-secrets-hook.js`) are installed from and referenced at `~/.claude/skills/code-warden/tools/hooks/`. Hook scripts are not copied to a neutral directory (e.g. `~/.claude/hooks/code-warden/`). The absolute path to the skill directory is written into `~/.claude/settings.json` at hook install time.
36
+ - **Alternatives considered**:
37
+ - Neutral directory (`~/.claude/hooks/code-warden/`). Rejected: requires copying hook scripts to a second location on install, syncing them on update, and maintaining a separate removal path. Creates a split-brain problem with two artifact trees.
38
+ - Relative path via `${CLAUDE_PROJECT_DIR}`. Rejected: hooks are user-level (global), not project-level. No stable relative root exists at user scope.
39
+ - **Reasoning**: Hooks are part of the code-warden skill distribution. They version with the skill and are updated by the same installer (`node install.js --hooks=claude`). One source of truth, one update path, one health-check target.
40
+ - **Consequence**: If the skill directory is deleted manually, `~/.claude/settings.json` may contain dangling hook entries pointing at missing scripts. `--doctor`, `--verify-target=claude`, and `--uninstall-hooks=claude` all detect and repair this condition. The risk is visible and recoverable.
41
+ - **Files affected**: `tools/hooks/warden-lint-hook.js`, `tools/hooks/warden-secrets-hook.js`, `tools/hooks/install-hooks.js`, `tools/hooks/uninstall-hooks.js`, `install.js`, `DECISIONS.md`
42
+
43
+ ---
44
+
45
+ ## 2026-05-14 - Research and fit governance
46
+
47
+ - **Decision**: Added `references/research-and-fit.md` and wired it into the core skill, cognitive routing, drift signals, README files, and governed-session example. The layer forces live research for current/version-specific facts and requires a fit check before defaulting to familiar stacks or product shapes.
48
+ - **Alternatives considered**:
49
+ - Expand only the existing "Don't Guess Syntax" rule. Rejected because syntax accuracy is narrower than the failure mode; the agent can know syntax and still choose the wrong stack or app shape.
50
+ - Put all research rules in `operations.md`. Rejected because operational evidence governs completion and source control, while research/fit governs choice formation before implementation.
51
+ - **Reasoning**: AI coding agents often over-index on familiar defaults like Node, React, SaaS dashboards, CRUD admins, or auth-first scaffolds. The skill now makes project fit and current-source research explicit gates instead of relying on generic uncertainty language.
52
+ - **Files affected**: `SKILL.md`, `references/research-and-fit.md`, `references/cognition.md`, `references/anti-drift.md`, `README.md`, root `README.md`, `examples/governed-session.md`, `package.json`
53
+
54
+ ---
55
+
56
+ ## 2026-05-14 - Operational governance layer
57
+
58
+ - **Decision**: Added `references/operations.md` and wired it into the core skill, drift signals, README files, and governed-session example. The layer covers verification-before-completion, source-control hygiene, dependency and supply-chain control, and evidence standards for technical claims.
59
+ - **Alternatives considered**:
60
+ - Fold these rules into `references/safety.md`. Rejected because safety already covers execution risk, secrets, patch-first editing, and dependency freeze; adding verification, git hygiene, and citations there would blur the file's responsibility.
61
+ - Add separate files for verification, source control, dependencies, and evidence. Rejected for now because each layer is short and operationally coupled; one focused operational reference avoids unnecessary reference sprawl.
62
+ - **Reasoning**: The existing skill prevented many bad coding moves, but it did not make final verification evidence, dirty-worktree ownership, dependency changes, or sourced technical claims explicit stop conditions. These are common failure modes in AI coding sessions and deserve first-class governance.
63
+ - **Files affected**: `SKILL.md`, `references/operations.md`, `references/anti-drift.md`, `README.md`, root `README.md`, `examples/governed-session.md`, `package.json`
64
+
65
+ ---
66
+
67
+ ## 2026-05-14 - Codex setup and shared-agent install path
68
+
69
+ - **Decision**: Treat `~/.agents/skills/code-warden` as the default install target while preserving `codex` and `claude` installer options. Added `AGENTS.md` context discovery, refreshed README setup paths, normalized tool output to ASCII status tags, and bumped package metadata to `2.3.1`.
70
+ - **Alternatives considered**:
71
+ - Keep `~/.claude/skills/code-warden` as the only install path. Rejected because the active local environment loads user skills from `~/.agents/skills`.
72
+ - Add a separate Codex-only fork. Rejected because one portable skill with target-specific installers is easier to maintain and audit.
73
+ - **Reasoning**: The skill should be usable by Codex now without breaking Claude Code users. `AGENTS.md` is the local instruction surface for Codex-style repositories, and ASCII tool output avoids terminal encoding failures in Windows PowerShell.
74
+ - **Files affected**: `AGENTS.md`, `README.md`, `SKILL.md`, `package.json`, `install.ps1`, `install.sh`, `tools/get-context.js`, `tools/warden-lint.js`, `tools/verify-secrets.js`
75
+
76
+ ---
77
+
78
+ ## 2026-03-26 - Polish pass: secret patterns, Windows installer, README, version sync
79
+
80
+ - **Decision**: Strengthened `verify-secrets.js` with 13 named patterns: OpenAI `sk-`, GitHub `ghp_`/`gho_`/`ghs_`/`ghx_`, AWS `AKIA`, Stripe `sk_live_`/`sk_test_`, bearer tokens, and generic key/password assignments. Added `README.md`. Added `install.ps1` for Windows. Bumped metadata `version` to `2.3.0`. Added `CLAUDE.md` and `.claude/CLAUDE.md` to `get-context.js` candidate list.
81
+ - **Alternatives considered**:
82
+ - Build additional enforcement tools such as a pre-flight counter, blast-radius reporter, and human checkpoint enforcer. Rejected after ROI analysis: these rules are enforced more reliably by the existing prompt governance layer; tool output can only shape context if the agent runs the tool and reads the result.
83
+ - Keep `install.sh` only. Rejected because the project owner is on Windows and `install.sh` is not enough for the platform.
84
+ - **Reasoning**: The changes were low-debt and high-value. Secret pattern expansion directly improved the only tool that scans third-party code. The Windows installer removed a real friction point for the author. The README provided an onboarding path that was absent. The version sync eliminated a confusing discrepancy. `CLAUDE.md` support aligned with Claude Code project conventions.
85
+ - **Files affected**: `tools/verify-secrets.js`, `install.ps1`, `README.md`, `SKILL.md`, `tools/get-context.js`
86
+
87
+ ---
88
+
89
+ ## 2026-03-25 - Align Human Checkpoint threshold with Think Before Coding rule
90
+
91
+ - **Decision**: Changed `[AWAITING CONFIRMATION]` trigger from >3 files to >2 files across `cognition.md` and the Drift Signals table in `SKILL.md`.
92
+ - **Alternatives considered**:
93
+ - Raise Think Before Coding to >3 files. Rejected because it was too permissive and allowed unconfirmed 3-file changes.
94
+ - Keep both thresholds as-is and document the gap as intentional. Rejected because the gap created ambiguous behavior: a plan was required at 2 files but no pause was enforced until 3.
95
+ - **Reasoning**: The safer boundary is to require explicit confirmation at the same point planning is required. A user reading both rules would expect them to be consistent. Stricter wins.
96
+ - **Files affected**: `references/cognition.md`, `SKILL.md`
97
+
98
+ ---
99
+
100
+ ## 2026-03-25 - Modular references split introduced in v2.1.0
101
+
102
+ - **Decision**: Separated governance rules into five domain files under `references/` instead of a single monolithic `SKILL.md`.
103
+ - **Alternatives considered**:
104
+ - Single flat `SKILL.md` with all rules inline. Rejected because it is token-heavy and loads irrelevant rules every session.
105
+ - Two files: core rules and extended rules. Rejected because it was not granular enough for targeted loading.
106
+ - **Reasoning**: Lazy-loading reference files keeps session token cost low. The model only reads the files relevant to the current task type. Each file has a single stated domain, which mirrors the one-concern-per-file rule the skill itself enforces.
107
+ - **Files affected**: `references/architecture.md`, `references/safety.md`, `references/cognition.md`, `references/cleanup.md`, `references/anti-drift.md`, `SKILL.md`
package/README.md ADDED
@@ -0,0 +1,137 @@
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 scanner — blocks 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
package/SKILL.md ADDED
@@ -0,0 +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`.
@@ -0,0 +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
+ }
@@ -0,0 +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 |