@whitehatd/crag 0.2.3 → 0.2.5

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.
package/README.md CHANGED
@@ -2,447 +2,201 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/%40whitehatd%2Fcrag?color=%23e8bb3a&label=npm&logo=npm)](https://www.npmjs.com/package/@whitehatd/crag)
4
4
  [![Test](https://github.com/WhitehatD/crag/actions/workflows/test.yml/badge.svg)](https://github.com/WhitehatD/crag/actions/workflows/test.yml)
5
+ [![Release](https://github.com/WhitehatD/crag/actions/workflows/release.yml/badge.svg)](https://github.com/WhitehatD/crag/actions/workflows/release.yml)
5
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
6
7
  [![Node](https://img.shields.io/node/v/%40whitehatd%2Fcrag)](https://nodejs.org)
7
8
  [![Zero dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)](./package.json)
8
- [![159 tests](https://img.shields.io/badge/tests-159%20passing-brightgreen)](./test)
9
+ [![323 tests](https://img.shields.io/badge/tests-323%20passing-brightgreen)](./test)
9
10
 
10
- **The bedrock layer for AI coding agents. One `governance.md`. Any project. Never stale.**
11
-
12
- Write your AI agent rules once. Enforce them in **Claude Code, Cursor, Copilot, Codex, Gemini, Aider, Cline, Continue, Windsurf, Zed, and Sourcegraph Cody** — plus your CI pipeline and git hooks. From a single 20-line file.
11
+ > **One `governance.md`. Any project. Generated in 250 ms.**
12
+ >
13
+ > Point crag at an existing codebase. It reads the filesystem, detects your
14
+ > stack, parses your CI, and writes a 30-line governance file that compiles
15
+ > to GitHub Actions, git hooks, and config for nine AI coding agents.
13
16
 
14
17
  ```bash
15
- npx @whitehatd/crag init # Interview generate governance
16
- npx @whitehatd/crag analyze # Or skip the interview: infer from existing project
17
- npx @whitehatd/crag compile --target all # Output for 12 downstream tools
18
+ npx @whitehatd/crag analyze # Generate governance.md from an existing project
19
+ npx @whitehatd/crag compile --target all # Turn it into CI + 12 downstream configs
18
20
  ```
19
21
 
20
- > **The one-sentence pitch:** Every other AI coding tool ships static config files that hardcode your project's current shape. They rot. crag ships a runtime discovery engine plus a single governance file — the engine reads the filesystem every session so it never goes stale, and the governance is your rules, not your paths.
22
+ Zero dependencies. Node 18+. Validated across [20 OSS projects](#validation-on-real-repos).
21
23
 
22
24
  ---
23
25
 
24
- ## The 12-target pitch, visually
25
-
26
- ```
27
- ┌──────────────────┐
28
- │ governance.md │ ← you maintain this (20-30 lines)
29
- │ one file │
30
- └────────┬─────────┘
31
-
32
- crag compile
33
-
34
- ┌─────────────────────┼─────────────────────┐
35
- │ │ │
36
- ┌─────┴──────┐ ┌─────┴──────┐ ┌─────┴──────┐
37
- │ CI / hooks │ │ AI native │ │ AI extras │
38
- ├────────────┤ ├────────────┤ ├────────────┤
39
- │ GitHub CI │ │ AGENTS.md │ │ Copilot │
40
- │ husky │ │ Cursor │ │ Cline │
41
- │ pre-commit │ │ Gemini │ │ Continue │
42
- └────────────┘ └────────────┘ │ Windsurf │
43
- │ Zed │
44
- │ Cody │
45
- └────────────┘
46
- ```
47
-
48
- Change one line in `governance.md`, re-run `crag compile --target all`, and 12 downstream configs regenerate. Your rules, your CI, your git hooks, and 9 different AI coding agents all stay in lock-step from a single source.
26
+ ## What it does
49
27
 
50
- ---
28
+ crag turns project-specific configuration work into a single file.
51
29
 
52
- ## Why "crag"?
30
+ - **You write**: a 20–30 line `governance.md` describing your quality gates, branch strategy, and security rules.
31
+ - **crag generates**: GitHub Actions workflow, husky hooks, pre-commit config, and configuration for **AGENTS.md** (Codex/Aider/Factory), **Cursor**, **Gemini**, **Copilot**, **Cline**, **Continue**, **Windsurf**, **Zed**, and **Sourcegraph Cody** — from that one file.
32
+ - **crag discovers**: runtimes, frameworks, linters, test runners, CI systems, and monorepo layouts — at session time, from the filesystem. Nothing to hardcode.
53
33
 
54
- A crag is a rocky outcrop an unmoving landmark that stands while seasons, paths, and generations change around it. That's exactly what this tool is. Your skills discover. Your gates run. Your CI regenerates. But `governance.md` the crag — doesn't move until you say so. Your AI agents anchor to it.
34
+ The result is a single source of truth for your rules that stays in lock-step with your CI pipeline, your pre-commit hooks, and every AI tool your team uses.
55
35
 
56
36
  ---
57
37
 
58
- ## Proven in Production
38
+ ## Validation on real repos
59
39
 
60
- Not on demos. On real systems, in production, shipping to real infrastructure.
40
+ Unlike most tools in this space, crag ships with a reproducible cross-repo benchmark. `crag analyze --dry-run` was run against 20 diverse open-source projects:
61
41
 
62
- | Project | Stack | Services | Deployment | Result |
63
- |---|---|---|---|---|
64
- | **Leyoda** | Spring Boot + Next.js 16 + Python | Monolith + signal engine | Docker blue-green, NGINX | Discovered entire stack, 215-line governance, zero skill modification |
65
- | **MetricHost** | Spring Boot + Next.js 16 | 11 microservices | Kubernetes (k3s), Kafka, Redis | 3-level governance hierarchy (root + backend + frontend), dual-repo |
66
- | **StructuAI** | Node + Rust + Python + Java + React | 9 Docker Compose services | Docker Compose | 5 languages detected, all gates generated from interview |
67
- | **crag** | Node.js CLI | Single module | npm | Scaffolds itself — full dogfooding, 159 tests, zero deps |
42
+ | Grade | Count | Meaning |
43
+ |---|---:|---|
44
+ | **A** ship-ready governance | **17 / 20 (85%)** | Stack + test + lint + build gates captured. Minimal noise. Ready to commit with light review. |
45
+ | **B** usable after cleanup | 3 / 20 (15%) | Stack correct, some gates need pruning or adding. Still faster than writing from scratch. |
46
+ | **C** rework needed | **0 / 20 (0%)** | |
68
47
 
69
- The same universal skills written once, never modified per project discovered a full-stack monolith with OAuth and blue-green deploys, an 11-microservice K8s platform with Stripe billing and Kafka event buses, a 5-language polyglot with Rust decoders and Puppeteer rendering, and a Node.js CLI. Zero project-specific instructions in the skills. They discovered everything.
48
+ Repos tested: `expressjs/express`, `chalk/chalk`, `fastify/fastify`, `axios/axios`, `prettier/prettier`, `vitejs/vite`, `psf/requests`, `pallets/flask`, `pallets/click`, `tiangolo/fastapi`, `BurntSushi/ripgrep`, `clap-rs/clap`, `rust-lang/mdBook`, `tokio-rs/axum`, `spf13/cobra`, `gin-gonic/gin`, `charmbracelet/bubbletea`, `spring-projects/spring-petclinic`, `sinatra/sinatra` (Ruby), `slimphp/Slim` (PHP).
70
49
 
71
- ---
72
-
73
- ## The Architecture
74
-
75
- ```
76
- ┌──────────────────────────────────────────────────────────────┐
77
- │ Ships with crag (universal — same for every project) │
78
- │ │
79
- │ ┌──────────────────────┐ ┌──────────────────────┐ │
80
- │ │ pre-start skill │ │ post-start skill │ │
81
- │ │ discovers ANY │ │ validates using │ │
82
- │ │ project │ │ YOUR gates │ │
83
- │ └──────────┬───────────┘ └──────────┬───────────┘ │
84
- └─────────────┼───────────────────────────────┼───────────────┘
85
- │ │
86
- │ reads at runtime │ reads at runtime
87
- ▼ ▼
88
- ┌──────────────────────────────────────────────────────────────┐
89
- │ Generated from interview or analyze (project-specific) │
90
- │ │
91
- │ ┌────────────────────────────────────────────┐ │
92
- │ │ governance.md — 20-30 lines of YOUR rules │ │
93
- │ └────────────────────────────────────────────┘ │
94
- │ │
95
- │ Also generated: hooks/ agents/ settings │
96
- └──────────────────────────────────────────────────────────────┘
97
- ```
50
+ | Metric | Value |
51
+ |---|---|
52
+ | Mean `crag analyze` time | **238 ms** per repo |
53
+ | Success rate | **20 / 20 exit 0** |
54
+ | Language families covered | Node, Python, Rust, Go, Java, Ruby, PHP |
55
+ | Zero-gate failures | **0** |
98
56
 
99
- The skills ship once and work forever. They don't know your stack — they discover it. They don't know your gates — they read them from governance.md. Add a service, change your CI, switch frameworks — the skills adapt. Nothing to update.
100
-
101
- ### The Core Insight: Discovery vs Governance
102
-
103
- Every other tool in this space mixes "how to find things" with "what to enforce." crag separates them cleanly:
104
-
105
- - **Discovery** (universal skills) — reads the filesystem, detects runtimes, maps architecture, finds configs. Works on any project without modification.
106
- - **Governance** (your `governance.md`) — defines YOUR rules: quality gates, security requirements, branch strategy, deployment pipeline. Changes only when YOU change it.
107
-
108
- The skills handle discovery. `governance.md` handles governance. The skills never go stale because they re-discover every session. The governance never goes stale because it's your standards, not your file paths.
57
+ Full methodology, grading rubric, per-repo results, and raw outputs: [`benchmarks/results.md`](./benchmarks/results.md).
109
58
 
110
59
  ---
111
60
 
112
- ## Quick Start
113
-
114
- ```bash
115
- # Install once globally (the package is scoped; the binary name is `crag`)
116
- npm install -g @whitehatd/crag
61
+ ## Quick start
117
62
 
118
- # Or use via npx (no install)
119
- npx @whitehatd/crag init
120
-
121
- # After install, all commands use the plain `crag` binary
122
- crag init # Interview → generate governance + hooks + agents
123
- crag analyze # Zero-interview: infer governance from existing project
124
- crag check # Verify infrastructure
125
- crag diff # Compare governance against codebase reality
126
- crag upgrade # Update universal skills (with hash-based conflict detection)
127
- crag workspace # Inspect detected workspace
128
- crag compile --target all # Compile governance → CI, hooks, and 9 AI agent configs
129
- crag install # Install interview agent globally for /crag-project
130
- ```
131
-
132
- After setup, in any Claude Code session:
133
63
  ```bash
134
- /pre-start-context # Discovers project, loads governance, ready to work
135
- # ... do your task ...
136
- /post-start-validation # Validates, captures knowledge, commits, deploys
137
- ```
64
+ # Use via npx (no install)
65
+ npx @whitehatd/crag analyze
66
+ npx @whitehatd/crag compile --target all
138
67
 
139
- ---
140
-
141
- ## User Guide
142
-
143
- ### Installation
144
-
145
- crag is a zero-dependency Node.js CLI. You don't need to install it — run it via `npx`:
146
-
147
- ```bash
148
- npx crag <command>
149
- ```
150
-
151
- Or install globally:
152
- ```bash
68
+ # Or install globally
153
69
  npm install -g @whitehatd/crag
154
- crag <command>
155
- ```
156
-
157
- The package is published under a scope (`@whitehatd/crag`) but the binary name remains `crag`, so after installation all commands work as `crag init`, `crag analyze`, etc.
158
-
159
- **Requirements:**
160
- - Node.js 18+ (uses built-in `https`, `crypto`, `fs`, `child_process`)
161
- - Git (for branch strategy inference and discovery cache)
162
- - Claude Code CLI (`claude --version`) — only needed for `crag init`
163
-
164
- ### Choosing Your Entry Point
165
-
166
- crag has two ways to generate governance for a project:
167
-
168
- | Situation | Command | What happens |
169
- |-----------|---------|--------------|
170
- | New project, unsure of standards | `crag init` | Interactive interview — agent asks about your stack, quality bar, security, deployment |
171
- | Existing project with CI/linters already configured | `crag analyze` | Zero-interview mode — reads your CI workflows, package.json scripts, linter configs, git history |
172
- | Want to see what would be generated | `crag analyze --dry-run` | Prints inferred governance without writing |
173
- | Already have governance, want to add inferred gates | `crag analyze --merge` | Preserves existing governance, appends inferred additions |
174
- | Monorepo with sub-projects | `crag analyze --workspace` | Analyzes root + every workspace member |
175
-
176
- ### Command Reference
177
-
178
- #### `crag init` — Interactive Setup
179
-
180
- Runs an interview agent that asks about your project, then generates all infrastructure:
181
-
182
- ```bash
183
- cd your-project
184
- npx crag init
70
+ crag analyze
71
+ crag compile --target all
185
72
  ```
186
73
 
187
- **What gets generated:**
188
- - `.claude/skills/pre-start-context/SKILL.md` — universal discovery skill
189
- - `.claude/skills/post-start-validation/SKILL.md` — universal validation skill
190
- - `.claude/governance.md` — your rules (from interview answers)
191
- - `.claude/hooks/` — sandbox-guard, drift-detector, circuit-breaker, auto-post-start
192
- - `.claude/agents/` — test-runner, security-reviewer, skill-auditor
193
- - `.claude/settings.local.json` — permissions + hook wiring
194
- - `.claude/ci-playbook.md` — empty template for known CI failures
74
+ **Requirements:** Node.js 18+. Git. (Claude Code CLI is only needed for the interactive `crag init` flow.)
195
75
 
196
- After init, the skills are ready to use in any Claude Code session via `/pre-start-context`.
197
-
198
- #### `crag analyze` — Zero-Interview Governance
199
-
200
- Generates `governance.md` from your existing project without asking questions:
201
-
202
- ```bash
203
- crag analyze # Generate .claude/governance.md
204
- crag analyze --dry-run # Preview without writing
205
- crag analyze --workspace # Analyze all workspace members
206
- crag analyze --merge # Merge with existing governance
207
- ```
208
-
209
- **What it detects:**
210
- - **Stack:** Node, Rust, Python, Java, Go, Docker (from manifests)
211
- - **Gates from CI:** parses `.github/workflows/*.yml` (recursively) for `run:` steps including multiline `run: |` blocks
212
- - **Gates from scripts:** `package.json` `test`, `lint`, `build`, `format`, `typecheck`
213
- - **Linters:** ESLint, Biome, Prettier, Ruff, Clippy, Rustfmt, Mypy, TypeScript
214
- - **Branch strategy:** feature branches vs trunk-based (from git history)
215
- - **Commit convention:** conventional vs free-form (from git log)
216
- - **Deployment:** Docker, Kubernetes, Vercel, Fly.io, Netlify, Render, Terraform
217
-
218
- Output sections marked `# Inferred` should be reviewed.
76
+ ---
219
77
 
220
- #### `crag check` — Verify Infrastructure
78
+ ## How it works
221
79
 
222
- Lists all core and optional files, shows which are present:
80
+ crag separates two things that every other tool in this space conflates:
223
81
 
224
- ```bash
225
- crag check
226
82
  ```
227
-
228
- Run this after `crag init` to verify everything was generated, or any time you're unsure if the setup is complete.
229
-
230
- #### `crag compile` Export Governance (12 targets)
231
-
232
- Compiles your `governance.md` to multiple formats:
233
-
234
- ```bash
235
- # CI / git hooks
236
- crag compile --target github # .github/workflows/gates.yml
237
- crag compile --target husky # .husky/pre-commit
238
- crag compile --target pre-commit # .pre-commit-config.yaml
239
-
240
- # AI coding agents — native formats
241
- crag compile --target agents-md # AGENTS.md (Codex, Aider, Factory)
242
- crag compile --target cursor # .cursor/rules/governance.mdc
243
- crag compile --target gemini # GEMINI.md
244
-
245
- # AI coding agents — additional formats
246
- crag compile --target copilot # .github/copilot-instructions.md
247
- crag compile --target cline # .clinerules
248
- crag compile --target continue # .continuerules
249
- crag compile --target windsurf # .windsurfrules
250
- crag compile --target zed # .zed/rules.md
251
- crag compile --target cody # .sourcegraph/cody-instructions.md
252
-
253
- crag compile --target all # All 12 targets at once
254
- crag compile # List available targets
83
+ ┌────────────────────────────────────────────────────────────────┐
84
+ │ DISCOVERY (ships with crag universal, same for any repo) │
85
+ │ │
86
+ │ Reads the filesystem at runtime. Detects languages, frame- │
87
+ │ works, CI systems, workspace layout, linters, test runners. │
88
+ │ │
89
+ │ Never hardcoded. Never goes stale. Add a service, switch │
90
+ │ frameworks, change CI — discovery adapts automatically. │
91
+ └───────────────────────────┬────────────────────────────────────┘
92
+
93
+
94
+ ┌────────────────────────────────────────────────────────────────┐
95
+ │ GOVERNANCE (your governance.md — project-specific) │
96
+ │ │
97
+ │ 20-30 lines of YOUR rules: quality gates, branch strategy,
98
+ │ security requirements, deployment policy.
99
+ │ │
100
+ │ Human-controlled. Version-pinned. Changes only when you do. │
101
+ └───────────────────────────┬────────────────────────────────────┘
102
+
103
+
104
+ ┌────────────────────────────────────────────────────────────────┐
105
+ │ COMPILE (crag compile --target all) │
106
+ │ │
107
+ │ One governance.md 12 outputs │
108
+ │ │
109
+ │ CI / hooks: GitHub Actions · husky · pre-commit │
110
+ │ AI (native): AGENTS.md · Cursor · Gemini │
111
+ │ AI (extras): Copilot · Cline · Continue · Windsurf · │
112
+ │ Zed · Sourcegraph Cody │
113
+ └────────────────────────────────────────────────────────────────┘
255
114
  ```
256
115
 
257
- **Why this matters:** one `governance.md` becomes your CI workflow, your git hooks, and configuration for **9 different AI coding agents**. Change a gate once, recompile, and every downstream tool sees the update. The generator detects Node/Python/Java/Go versions from your project files (`package.json engines.node`, `pyproject.toml requires-python`, `build.gradle.kts` toolchain, `go.mod` directive) instead of hardcoding defaults.
258
-
259
- Gate classifications control behavior per target:
260
- - `# [MANDATORY]` (default) — stop on failure
261
- - `# [OPTIONAL]` — warn via `continue-on-error: true` (GitHub) or wrapper (husky/pre-commit)
262
- - `# [ADVISORY]` — log result, never block
263
-
264
- #### `crag diff` — Governance Drift Detection
116
+ Change one line in `governance.md`, re-run `crag compile --target all`, and 12 downstream configs regenerate. Every AI tool on your team plus your CI pipeline and pre-commit hooks stays in sync from a single source.
265
117
 
266
- Compares `governance.md` against codebase reality:
267
-
268
- ```bash
269
- crag diff
270
- ```
271
-
272
- ```
273
- MATCH node --check bin/crag.js
274
- DRIFT ESLint referenced but biome.json found
275
- MISSING CI gate: cargo test (in governance, not in CI)
276
- EXTRA docker build (in CI, not in governance)
118
+ ---
277
119
 
278
- 3 match, 1 drift, 1 missing, 1 extra
279
- ```
120
+ ## What crag detects
280
121
 
281
- Command alias normalization means `npm test` and `npm run test` are treated as equivalent, as are `./gradlew` and `gradlew`.
122
+ ### Languages and runtimes
282
123
 
283
- #### `crag upgrade` Update Skills
124
+ | Family | Detected | Gates emitted |
125
+ |---|---|---|
126
+ | **Node / Deno / Bun** | `package.json`, `deno.json`, `bun.lockb`, `bunfig.toml` | `npm run test/lint/build`, `tsc --noEmit`, `eslint`, `biome check`, `xo`, `deno test/lint/fmt`, `bun test` |
127
+ | **Python** | `pyproject.toml`, `setup.py`, `requirements.txt` | `uv run pytest`, `poetry run pytest`, `pdm run pytest`, `hatch run pytest`, `tox run`, `nox`, `ruff check/format`, `mypy`, `black` — detected per runner |
128
+ | **Rust** | `Cargo.toml`, `Cargo.toml [workspace]` | `cargo test`, `cargo clippy -- -D warnings`, `cargo fmt --check` |
129
+ | **Go** | `go.mod`, `.golangci.yml` | `go test ./...`, `go vet ./...`, `golangci-lint run` |
130
+ | **Java / Kotlin** | `pom.xml`, `build.gradle(.kts)`, Kotlin plugin detection | `./mvnw test verify`, `./gradlew test build`, `checkstyle`, `detekt` |
131
+ | **Ruby** | `Gemfile`, `*.gemspec`, `Rakefile` | `bundle exec rspec`, `bundle exec rake test`, `rubocop`, `standardrb`, `brakeman`, `bundle-audit` |
132
+ | **PHP** | `composer.json`, `phpunit.xml(.dist)` | `composer test`, `vendor/bin/phpunit`, `vendor/bin/pest`, `vendor/bin/phpstan analyse`, `vendor/bin/psalm`, `vendor/bin/phpcs`, `composer validate --strict` |
133
+ | **.NET** | `*.csproj`, `*.fsproj`, `*.sln` | `dotnet test`, `dotnet build`, `dotnet format --verify-no-changes` |
134
+ | **Swift** | `Package.swift` | `swift test`, `swift build`, `swiftlint` |
135
+ | **Elixir** | `mix.exs` | `mix test`, `mix format --check-formatted`, `mix credo --strict`, `mix dialyzer` |
136
+ | **Infrastructure** | `*.tf`, `Chart.yaml`, `Dockerfile`, `openapi.yaml`, `*.proto` | `terraform fmt/validate/plan`, `tflint`, `helm lint`, `hadolint`, `spectral lint`, `buf lint` |
284
137
 
285
- Updates universal skills in the current project to the latest version:
138
+ ### CI systems
286
139
 
287
- ```bash
288
- crag upgrade # Update skills in current project
289
- crag upgrade --check # Dry run — show what would change
290
- crag upgrade --workspace # Update all workspace members
291
- crag upgrade --force # Overwrite locally modified skills (creates backup)
292
- ```
140
+ `crag analyze` parses `run:` / `script:` / `command:` steps from nine CI systems and feeds them through a normalizer that dedupes matrix expansions, filters background processes, and strips shell plumbing:
293
141
 
294
- **How it works:**
295
- - Skills track their version in YAML frontmatter (`version: 0.2.1`)
296
- - A `source_hash` (SHA-256, CRLF-normalized) detects local modifications
297
- - If you modified a skill locally, upgrade won't overwrite it without `--force`
298
- - When force-overwriting, a timestamped backup is created (`SKILL.md.bak.1712252400`)
299
- - Global 24-hour cache at `~/.claude/crag/update-check.json`
300
- - Opt-out: `CRAG_NO_UPDATE_CHECK=1`
142
+ GitHub Actions · GitLab CI · CircleCI · Travis CI · Azure Pipelines · Buildkite · Drone · Woodpecker · Bitbucket Pipelines
301
143
 
302
- #### `crag workspace` — Inspect Workspace
144
+ ### Task runners
303
145
 
304
- Shows the detected workspace, all members, their tech stacks, and governance hierarchy:
146
+ Real target mining not placeholders. Canonical test/lint/build targets extracted from:
305
147
 
306
- ```bash
307
- crag workspace # Human-readable
308
- crag workspace --json # Machine-readable JSON (for CI/scripting)
309
- ```
148
+ - **Makefile** (`.PHONY` directives + column-0 targets)
149
+ - **Taskfile.yml** (`tasks:` sub-keys)
150
+ - **justfile** (recipe names)
310
151
 
311
- Example output:
312
- ```
313
- Workspace: npm
314
- Root: /path/to/monorepo
315
- Config: package.json
316
- Members: 3
317
- Root governance: 2 gate section(s), runtimes: node
318
-
319
- Members:
320
- ✓ backend [node]
321
- packages/backend
322
- ✓ frontend [node] (inherits)
323
- packages/frontend
324
- ○ shared [node]
325
- packages/shared
326
- ```
152
+ ### Workspaces
327
153
 
328
- Use this to debug workspace detection or understand governance inheritance in monorepos.
154
+ Eleven workspace types, enumerated at discovery time:
329
155
 
330
- #### `crag install` Install Global Agent
156
+ pnpm · npm/yarn · Cargo · Go · Gradle · Maven · Nx · Turborepo · Bazel · git submodules · independent nested repos
331
157
 
332
- Installs the `crag-project` interview agent to `~/.claude/agents/` so you can invoke it with `/crag-project` from any Claude Code session:
158
+ ### Frameworks
333
159
 
334
- ```bash
335
- crag install
336
- ```
160
+ Detected from manifest dependencies (runtime deps only — no false positives from dev fixtures):
337
161
 
338
- #### `crag version` / `crag help`
162
+ **Web:** Next.js · React · Vue · Svelte · SvelteKit · Nuxt · Astro · Solid · Qwik · Remix · Express · Fastify · Koa · Hono · NestJS · Phoenix
163
+ **Backend:** Rails · Sinatra · Hanami · Laravel · Symfony · Slim · Yii · CakePHP
339
164
 
340
- ```bash
341
- crag version # Print version
342
- crag help # Print usage
343
- ```
165
+ ### Documentation mining
344
166
 
345
- ### The Session Loop
167
+ `CONTRIBUTING.md` and `.github/PULL_REQUEST_TEMPLATE.md` are scanned for gate candidates in code fences and inline backticks — advisory-only, capped at 5, gated by canonical-verb filter.
346
168
 
347
- Once crag is set up, your workflow in any Claude Code session becomes:
169
+ ---
348
170
 
349
- ```
350
- 1. /pre-start-context → Discovers project, loads governance, checks skill currency
351
- 2. ... your task ... → Write code, fix bugs, add features
352
- 3. /post-start-validation → Runs gates, security review, captures knowledge, commits
353
- ```
171
+ ## Commands
354
172
 
355
- **Pre-start does:**
356
- - Detects workspace type (pnpm, Cargo, Go, Gradle, Maven, Nx, Turbo, Bazel, submodules, nested repos)
357
- - Enumerates members and checks for multi-level governance
358
- - Detects runtime versions (Node, Java, Python, Go, Rust, Docker)
359
- - Reads `governance.md` and applies rules for the session
360
- - Loads cross-session memory (if MemStack enabled)
361
- - Checks skill currency — notifies if `crag upgrade` available
362
-
363
- **Post-start does:**
364
- - Runs governance gates in order (stops on MANDATORY failure; logs OPTIONAL/ADVISORY)
365
- - Auto-fixes mechanical errors (lint, format) with bounded retry
366
- - Runs security review (grep for secrets, check new endpoints)
367
- - Captures knowledge (insights, sessions) if MemStack enabled
368
- - Commits with conventional commit format
369
- - Writes `.session-state.json` for next session's warm start
370
-
371
- ### Common Workflows
372
-
373
- **Workflow 1: Add crag to an existing project**
374
173
  ```bash
375
- cd my-existing-project
376
- npx crag analyze --dry-run # Preview what it would generate
377
- npx crag analyze # Write .claude/governance.md
378
- # Review the generated file, adjust as needed
379
- npx crag check # Verify infrastructure
380
- # Use /pre-start-context in Claude Code
381
- ```
174
+ crag analyze # Generate .claude/governance.md from filesystem
175
+ crag analyze --dry-run # Print what would be generated, don't write
176
+ crag analyze --workspace # Analyze root + every workspace member
177
+ crag analyze --merge # Preserve existing governance, append inferred sections
382
178
 
383
- **Workflow 2: Start a brand new project**
384
- ```bash
385
- mkdir my-new-project && cd my-new-project
386
- git init
387
- npx crag init # Interactive interview
388
- # Follow the prompts — agent asks ~20 questions
389
- # Skills + hooks + agents are all generated
390
- npx crag check
391
- ```
179
+ crag init # Interactive interview (needs Claude Code CLI)
392
180
 
393
- **Workflow 3: Monorepo with per-service governance**
394
- ```bash
395
- cd my-monorepo
396
- npx crag workspace # See detected type + members
397
- npx crag init # Root-level governance
398
- cd packages/backend
399
- npx crag analyze --merge # Add backend-specific gates
400
- cd ../../packages/frontend
401
- npx crag analyze --merge # Add frontend-specific gates
402
- # Now each package has its own governance.md, and root has cross-cutting rules
403
- ```
181
+ crag compile --target <name> # Compile governance to a single target
182
+ crag compile --target all # Compile to all 12 targets at once
183
+ crag compile # List available targets
404
184
 
405
- **Workflow 4: Keep everything current**
406
- ```bash
407
- npx crag upgrade --check # See what would update
408
- npx crag upgrade # Apply updates (preserves local changes)
409
- npx crag diff # Check governance hasn't drifted
410
- npx crag compile --target all # Regenerate CI workflows, hooks, cross-agent files
411
- ```
185
+ crag diff # Compare governance against codebase reality
186
+ crag upgrade # Update universal skills to latest version
187
+ crag upgrade --check # Dry-run: show what would change
188
+ crag check # Verify Claude Code infrastructure is in place
189
+ crag workspace # Inspect detected workspace
190
+ crag workspace --json # Machine-readable workspace report
412
191
 
413
- **Workflow 5: Switch AI tools (Claude → Cursor → Gemini)**
414
- ```bash
415
- npx crag compile --target agents-md # Generate AGENTS.md
416
- npx crag compile --target cursor # Generate .cursor/rules/
417
- npx crag compile --target gemini # Generate GEMINI.md
418
- # Same governance rules now work in Codex, Cursor, Gemini CLI, Aider, Factory
192
+ crag version / crag help
419
193
  ```
420
194
 
421
- ### Troubleshooting
422
-
423
- **Q: `crag init` says "Claude Code CLI not found"**
424
- A: Install Claude Code from https://claude.com/claude-code. Only `init` needs it; other commands don't.
425
-
426
- **Q: `crag upgrade` shows "locally modified" and won't update**
427
- A: You edited a skill file. Either (1) accept that your edits are preserved and stay on the old version, or (2) run `crag upgrade --force` to overwrite (backup is created).
428
-
429
- **Q: `crag analyze` generates nothing useful**
430
- A: It needs signals — CI configs, `package.json` scripts, linter configs. For greenfield projects, use `crag init` for the interview flow instead.
431
-
432
- **Q: `crag diff` reports drift but my CI is working**
433
- A: Drift means `governance.md` says one thing and the codebase uses another. Either update `governance.md` to match reality, or update the codebase to match governance. Both are valid.
434
-
435
- **Q: Skills don't auto-update when I run `/pre-start-context`**
436
- A: Auto-update runs via the CLI commands, not the skill itself. Run `crag upgrade` from your terminal. The skill reports skill version on pre-start so you know when to run upgrade.
437
-
438
- **Q: Multi-level governance not merging correctly**
439
- A: Check that member governance files use `## Gates (inherit: root)` to opt in to inheritance. Without this marker, member governance replaces root.
440
-
441
195
  ---
442
196
 
443
- ## governance.md
197
+ ## The governance file
444
198
 
445
- The only file you maintain. 20-30 lines. Everything else is universal.
199
+ The only file you maintain. 2030 lines. Everything else is universal or generated.
446
200
 
447
201
  ```markdown
448
202
  # Governance — StructuAI
@@ -452,12 +206,12 @@ The only file you maintain. 20-30 lines. Everything else is universal.
452
206
  - Description: AI-powered Minecraft schematic describer
453
207
 
454
208
  ## Gates (run in order, stop on failure)
455
- ### Frontend
209
+ ### Frontend (path: frontend/)
456
210
  - npx eslint frontend/ --max-warnings 0
457
211
  - cd frontend && npx vite build
458
212
 
459
213
  ### Backend
460
- - node --check scripts/api-server.js scripts/worker.js scripts/queue.js
214
+ - node --check scripts/api-server.js
461
215
  - cargo clippy --manifest-path source/decode/Cargo.toml
462
216
  - cargo test --manifest-path source/decode/Cargo.toml
463
217
 
@@ -466,390 +220,156 @@ The only file you maintain. 20-30 lines. Everything else is universal.
466
220
 
467
221
  ## Branch Strategy
468
222
  - Trunk-based, conventional commits
469
- - Auto-commit after all gates pass
223
+ - Auto-commit after gates pass
470
224
 
471
225
  ## Security
472
- - Schematic file uploads only (validate file type server-side)
473
- - No hardcoded secrets or API keys in source
474
- ```
475
-
476
- Change a gate → takes effect next session. Add a security rule → enforced immediately. The skills read this file every time — they never cache stale instructions.
477
-
478
- ### Governance v2 annotations (optional)
479
-
480
- Gate sections support optional annotations for workspace-aware execution:
481
-
482
- ```markdown
483
- ## Gates (run in order, stop on failure)
484
- ### Frontend (path: frontend/) # cd to frontend/ before running
485
- - npx biome check . # [MANDATORY] (default)
486
- - npx tsc --noEmit # [OPTIONAL] — warn but don't fail
487
-
488
- ### TypeScript (if: tsconfig.json) # skip section if file doesn't exist
489
- - npx tsc --noEmit
490
-
491
- ### Audit
492
- - npm audit # [ADVISORY] — informational only
493
-
494
- ## Gates (inherit: root) # merge with root governance
226
+ - Schematic file uploads only (validate server-side)
227
+ - No hardcoded secrets or API keys
495
228
  ```
496
229
 
497
- All annotations are optional. Existing governance files work unchanged. Classifications are honored by all compile targets (GitHub Actions `continue-on-error`, husky/pre-commit wrapper scripts).
498
-
499
- ### Multi-level governance (monorepos)
500
-
501
- For projects with multiple sub-repos or services, governance can be hierarchical:
502
-
503
- ```
504
- project-root/
505
- ├── .claude/governance.md # Cross-stack: branch strategy, deployment, security
506
- ├── backend/.claude/governance.md # Backend-specific: Gradle gates, service tests
507
- └── frontend/.claude/governance.md # Frontend-specific: Biome, Vitest, responsive audit
508
- ```
230
+ **Annotations** (all optional):
509
231
 
510
- Each level gets the same universal skills. Each reads its own `governance.md`. Open Claude Code at the root get the cross-stack view. Open it in `backend/` — get backend-specific gates. The skills adapt to wherever you are.
232
+ - `### Section (path: subdir/)` — run this section's gates from `subdir/`
233
+ - `### Section (if: config.json)` — skip if file doesn't exist
234
+ - `- command # [OPTIONAL]` — warn but don't fail
235
+ - `- command # [ADVISORY]` — log only, never block
236
+ - `## Gates (inherit: root)` — merge with root governance (monorepo)
511
237
 
512
238
  ---
513
239
 
514
- ## Workspace Detection
515
-
516
- crag auto-detects 11+ workspace types:
517
-
518
- | Marker | Workspace Type |
519
- |--------|----------------|
520
- | `pnpm-workspace.yaml` | pnpm |
521
- | `package.json` with `"workspaces"` | npm/yarn |
522
- | `Cargo.toml` with `[workspace]` | Cargo |
523
- | `go.work` | Go |
524
- | `settings.gradle.kts` with `include(` | Gradle |
525
- | `pom.xml` with `<modules>` | Maven |
526
- | `nx.json` | Nx |
527
- | `turbo.json` | Turborepo |
528
- | `WORKSPACE` / `MODULE.bazel` | Bazel |
529
- | `.gitmodules` | Git submodules |
530
- | Multiple child `.git` dirs | Independent repos |
240
+ ## Compile targets (12 outputs)
531
241
 
532
- Workspace members are enumerated, checked for their own `.claude/governance.md`, and their tech stacks detected. Multi-level governance merges root gates (mandatory) with member gates (additive).
242
+ | Target | Output | Consumer |
243
+ |---|---|---|
244
+ | `github` | `.github/workflows/gates.yml` | GitHub Actions |
245
+ | `husky` | `.husky/pre-commit` | husky framework |
246
+ | `pre-commit` | `.pre-commit-config.yaml` | pre-commit.com |
247
+ | `agents-md` | `AGENTS.md` | Codex, Aider, Factory, Crush |
248
+ | `cursor` | `.cursor/rules/governance.mdc` | Cursor |
249
+ | `gemini` | `GEMINI.md` | Gemini CLI |
250
+ | `copilot` | `.github/copilot-instructions.md` | GitHub Copilot |
251
+ | `cline` | `.clinerules` | Cline (VS Code) |
252
+ | `continue` | `.continuerules` | Continue.dev |
253
+ | `windsurf` | `.windsurfrules` | Windsurf IDE |
254
+ | `zed` | `.zed/rules.md` | Zed Editor |
255
+ | `cody` | `.sourcegraph/cody-instructions.md` | Sourcegraph Cody |
256
+
257
+ The compiler detects runtime versions from your project (`package.json engines.node`, `pyproject.toml requires-python`, `go.mod` directive, Gradle toolchain). All writes are atomic — partial failures leave the old state intact.
533
258
 
534
259
  ---
535
260
 
536
- ## Governance Compiler — 12 Targets
537
-
538
- `governance.md` is agent-readable. But the gates in it are just shell commands — they can also drive your CI pipeline, git hooks, and configuration for **9 different AI coding agents**. One source of truth, twelve outputs:
539
-
540
- ### Full target list
541
-
542
- | Group | Target | Output path | Consumed by |
543
- |---|---|---|---|
544
- | **CI** | `github` | `.github/workflows/gates.yml` | GitHub Actions |
545
- | **CI** | `husky` | `.husky/pre-commit` | husky pre-commit framework |
546
- | **CI** | `pre-commit` | `.pre-commit-config.yaml` | pre-commit.com framework |
547
- | **AI native** | `agents-md` | `AGENTS.md` | Codex, Aider, Factory, and any tool reading `AGENTS.md` |
548
- | **AI native** | `cursor` | `.cursor/rules/governance.mdc` | Cursor |
549
- | **AI native** | `gemini` | `GEMINI.md` | Google Gemini CLI |
550
- | **AI extras** | `copilot` | `.github/copilot-instructions.md` | GitHub Copilot (VS Code, JetBrains, Visual Studio, Copilot Workspace) |
551
- | **AI extras** | `cline` | `.clinerules` | Cline (VS Code extension) |
552
- | **AI extras** | `continue` | `.continuerules` | Continue.dev |
553
- | **AI extras** | `windsurf` | `.windsurfrules` | Windsurf IDE (Codeium) |
554
- | **AI extras** | `zed` | `.zed/rules.md` | Zed Editor AI assistant |
555
- | **AI extras** | `cody` | `.sourcegraph/cody-instructions.md` | Sourcegraph Cody |
261
+ ## Workspaces
556
262
 
557
263
  ```bash
558
- crag compile --target all # Generate all 12 at once
559
- crag compile --target github # Or pick one
560
- crag compile # Or list targets interactively
561
- ```
562
-
563
- The compiler parses your gates, auto-detects runtimes from the commands (Node, Rust, Python, Java, Go, Docker), and generates the right setup steps with proper version inference from your project files (not hardcoded defaults). Human-readable `Verify X contains Y` gates are compiled to `grep` commands automatically (with shell-injection-safe escaping). All 12 targets write atomically (temp file + rename) so partial failures leave the old state intact.
264
+ crag workspace # Human-readable
265
+ crag workspace --json # Machine-readable
564
266
 
267
+ crag analyze --workspace # Analyze every member and emit per-member gates
565
268
  ```
566
- ┌────────────────────┐
567
- │ governance.md │
568
- │ (one file) │
569
- └──────────┬─────────┘
570
-
571
- crag compile --target all
572
-
573
- ┌─────────────────────────┼─────────────────────────┐
574
- │ │ │
575
- ▼ ▼ ▼
576
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
577
- │ CI / hooks │ │ AI native │ │ AI extras │
578
- ├─────────────┤ ├─────────────┤ ├─────────────┤
579
- │ gates.yml │ │ AGENTS.md │ │ Copilot │
580
- │ husky │ │ Cursor MDC │ │ Cline │
581
- │ pre-commit │ │ GEMINI.md │ │ Continue │
582
- └─────────────┘ └─────────────┘ │ Windsurf │
583
- │ Zed │
584
- │ Cody │
585
- └─────────────┘
586
-
587
- + read at runtime by
588
- universal skills
589
- (pre-start / post-start)
590
- ```
591
-
592
- Governance-as-config that compiles to agent behavior, CI/CD pipelines, and **9 different AI coding tool configs** from a single 20-line file.
593
-
594
- ---
595
-
596
- ## Zero-Interview Mode
597
269
 
598
- Don't want an interview? `crag analyze` generates governance from your existing project:
270
+ Detected types: `pnpm` · `npm/yarn` · `cargo` · `go` · `gradle` · `maven` · `nx` · `turbo` · `bazel` · `git-submodules` · `independent-repos`.
599
271
 
600
- ```bash
601
- crag analyze # Infer governance from codebase + CI
602
- crag analyze --dry-run # Preview without writing
603
- crag analyze --workspace # Analyze all workspace members
604
- crag analyze --merge # Merge with existing governance
605
- ```
272
+ Test-fixture directories (`playground/`, `fixtures/`, `examples/`, `demos/`, `__fixtures__/`) are excluded from per-member enumeration so monorepos like Vite don't generate 79 sections for their playground directories.
606
273
 
607
- It reads your CI workflows (recursively, handling `run: |` multiline blocks), `package.json` scripts, linter configs, git history, and deployment configs. Outputs `governance.md` with `# Inferred` markers so you know what to verify.
274
+ Multi-level governance is supported: root governance sets cross-cutting rules (branch strategy, security), member governance adds stack-specific gates via `## Gates (inherit: root)`.
608
275
 
609
276
  ---
610
277
 
611
- ## Governance Drift Detection
278
+ ## The session loop (Claude Code)
612
279
 
613
- `crag diff` compares your `governance.md` against codebase reality:
280
+ Once crag is set up in a Claude Code project, each session is:
614
281
 
615
- ```bash
616
- crag diff
617
282
  ```
618
-
283
+ /pre-start-context → Discovers project, loads governance, caches runtimes
284
+
285
+ your task
286
+
287
+ /post-start-validation → Runs gates, auto-fixes lint/format, commits
619
288
  ```
620
- MATCH node --check bin/crag.js (tool exists)
621
- DRIFT ESLint referenced but biome.json found
622
- MISSING CI gate: cargo test (in governance, not in CI)
623
- EXTRA CI step: docker build (in CI, not in governance)
624
289
 
625
- 3 match, 1 drift, 1 missing, 1 extra
626
- ```
290
+ `/pre-start-context` classifies task intent, uses a content-hashed discovery cache to skip ~80% of redundant scans on unchanged code, and reads `governance.md` fresh every session so the rules are always current.
627
291
 
628
- ---
292
+ `/post-start-validation` runs gates in the order declared in `governance.md`, stops on `[MANDATORY]` failure, retries mechanical errors (lint, format) up to twice with auto-fix, runs a security review, and creates a conventional-commit commit when everything passes.
629
293
 
630
- ## Auto-Update
294
+ ---
631
295
 
632
- Skills track their version in YAML frontmatter. When you run any crag command, it checks for updates:
296
+ ## Installation and requirements
633
297
 
634
298
  ```bash
635
- crag upgrade # Update skills in current project
636
- crag upgrade --workspace # Update all workspace members
637
- crag upgrade --check # Dry run — show what would change
638
- crag upgrade --force # Overwrite locally modified skills (with backup)
299
+ npm install -g @whitehatd/crag
300
+ # or
301
+ npx @whitehatd/crag <command>
639
302
  ```
640
303
 
641
- The update checker queries the npm registry (cached for 24 hours, 3s timeout, graceful failure offline). Skills are only overwritten if the user hasn't modified them local modifications are detected via SHA-256 content hash (CRLF-normalized for cross-platform consistency) and preserved unless `--force` is used.
642
-
643
- ---
304
+ - **Node.js 18+**uses built-in `https`, `crypto`, `fs`, `child_process`. No runtime dependencies.
305
+ - **Git** — for branch strategy inference and the discovery cache.
306
+ - **Claude Code CLI** — only needed for the interactive `crag init` flow. `analyze`, `compile`, `diff`, `upgrade`, `workspace`, `check` all run standalone.
644
307
 
645
- ## What Ships vs What's Generated
646
-
647
- | Component | Source | Maintains itself? |
648
- |-----------|--------|-------------------|
649
- | Pre-start skill | **Ships universal** | Yes — discovers at runtime, caches results, auto-updates |
650
- | Post-start skill | **Ships universal** | Yes — reads governance for gates, auto-fixes, auto-updates |
651
- | `governance.md` | **Generated from interview or analyze** | No — you maintain it (20-30 lines) |
652
- | Hooks | **Generated for your tools** | Yes — sandbox guard + drift detector + gate enforcement |
653
- | Agents | **Generated for your stack** | Yes — read governance for commands |
654
- | Settings | **Generated** | Yes — RTK wildcards cover new tools |
655
- | CI playbook | **Generated template** | You add entries as failures are found |
656
- | Compile targets | **Generated on demand** | `crag compile` regenerates from governance (12 targets) |
657
- | Workspace detection | **Ships universal** | Yes — detects 11+ workspace types at runtime |
658
- | Governance diff | **Ships universal** | Yes — compares governance vs codebase reality |
308
+ The package is published under `@whitehatd/crag` but the binary name is plain `crag` after install.
659
309
 
660
310
  ---
661
311
 
662
- ## Why Everything Else Is Static
312
+ ## Release pipeline
663
313
 
664
- | Current ecosystem | Why it rots | crag's approach |
665
- |-------------------------------------------|--------------------------------------|------------------------------------------------|
666
- | **CLAUDE.md / AGENTS.md** static files | Hardcode project facts; manual edits | **Universal skills** read filesystem every session — always current |
667
- | **Skill collections** (1,234+ skills) | Pick-per-project; stack mismatch | **One engine** that works for any stack |
668
- | **Per-framework templates** | One stack per template; rot on change | **`governance.md`** — 20–30 lines of YOUR rules only, human-controlled |
314
+ Every push to `master` runs the full CI matrix (Ubuntu / macOS / Windows × Node 18 / 20 / 22) and, if tests pass, auto-bumps the patch version and publishes to npm with SLSA provenance attestation. Tags are created automatically. GitHub releases are generated from `CHANGELOG.md`.
669
315
 
670
- **The difference:** everything else tries to pack facts INTO config files. crag reads facts FROM the filesystem at runtime. The skills don't know your stack — they discover it. The governance doesn't know your paths — it holds your rules.
316
+ To skip a release on a specific push, put `crag:skip-release` on its own line in the commit body.
671
317
 
672
318
  ---
673
319
 
674
- ## The Session Loop
320
+ ## Design principles
675
321
 
676
- ```
677
- ┌────────────────────────────────────────────────────────────────┐
678
- │ PRE-START (universal skill — runs before every task) │
679
- │ │
680
- │ Warm start? Intent? Cache valid? │
681
- │ .session-state.json → classify → .discovery-cache.json │
682
- │ │ │ │ │
683
- │ │ │ ┌───────┴───────┐ │
684
- │ │ │ ▼ ▼ │
685
- │ │ │ Fast path Full discovery │
686
- │ │ │ (skip 80%) (detect stack, │
687
- │ │ │ │ load memory) │
688
- │ └────────────────┴──────────┴───────────────┘ │
689
- │ │ │
690
- │ ▼ │
691
- │ Read governance.md │
692
- └───────────────────────────────┬────────────────────────────────┘
693
-
694
-
695
- ┌──────────────────┐
696
- │ YOUR TASK │
697
- │ (code changes) │
698
- └────────┬─────────┘
699
-
700
-
701
- ┌────────────────────────────────────────────────────────────────┐
702
- │ POST-START (universal skill — runs after every task) │
703
- │ │
704
- │ Detect changes → Run gates → (fail?) → Auto-fix → retry │
705
- │ │ │
706
- │ pass │
707
- │ ▼ │
708
- │ Security review → Capture knowledge │
709
- │ │ │
710
- │ ▼ │
711
- │ Write session state · Commit │
712
- └────────────────────────────────┬───────────────────────────────┘
713
-
714
- │ cache + state + knowledge
715
- └─────► feeds next session
716
- ```
717
-
718
- ### What makes this loop tight
322
+ 1. **Discover, don't hardcode.** Every fact about the codebase is read at runtime. Skills never say "22 controllers" — they say "read the controller directory." They never go stale because there is nothing to go stale.
719
323
 
720
- | Feature | What it does | Savings |
721
- |---|---|---|
722
- | **Discovery cache** | Hashes build files, skips unchanged domains | ~80% of pre-start tool calls on unchanged projects |
723
- | **Intent-scoped discovery** | Classifies task, skips irrelevant domains | Skip frontend discovery for backend bugs, and vice versa |
724
- | **Session continuity** | Reads `.session-state.json` for warm starts | Near-zero-latency startup when continuing work |
725
- | **Gate auto-fix** | Fixes lint/format errors, retries gate (max 2x) | Eliminates human round-trip for mechanical failures |
726
- | **Auto-post-start** | Hook warns before commit if gates haven't run | Removes "forgot to validate" failure mode |
727
- | **Sandbox guard** | Hard-blocks destructive commands at hook level | Security at system level, not instruction level |
728
- | **Workspace detection** | Detects 11+ workspace types, enumerates members | Automatic monorepo/polyrepo awareness |
729
- | **Auto-update** | Version-tracked skills with hash-based conflict detection | Skills stay current across all projects |
730
- | **Governance diff** | Compares `governance.md` against actual codebase | Catches drift before it causes failures |
731
-
732
- No agent framework does all of these. Most re-discover cold every session, require manual validation, and trust instructions for safety.
733
-
734
- ---
324
+ 2. **Govern, don't hope.** Your quality bar lives in `governance.md`. Skills enforce it but never modify it. It changes only when you change it.
735
325
 
736
- ## Generated Infrastructure
326
+ 3. **Ship the engine, generate the config.** Universal skills ship once and work for every project. `governance.md` is generated per project. The engine works forever. The config is 20 lines.
737
327
 
738
- ```
739
- .claude/
740
- ├── governance.md # YOUR rules (only custom file)
741
- ├── skills/
742
- │ ├── pre-start-context/SKILL.md # Universal discoverer
743
- │ └── post-start-validation/SKILL.md # Universal validator
744
- ├── hooks/
745
- │ ├── sandbox-guard.sh # Hard-blocks destructive commands
746
- │ ├── auto-post-start.sh # Gate enforcement before commits
747
- │ ├── drift-detector.sh # Checks key files exist
748
- │ ├── circuit-breaker.sh # Failure loop detection
749
- │ ├── pre-compact-snapshot.sh # Memory before compaction
750
- │ └── post-compact-recovery.sh # Memory after compaction
751
- ├── agents/
752
- │ ├── test-runner.md # Parallel tests (Sonnet)
753
- │ ├── security-reviewer.md # Security audit (Opus)
754
- │ ├── dependency-scanner.md # Vulnerability scan
755
- │ └── skill-auditor.md # Infrastructure audit
756
- ├── rules/ # Cross-session memory
757
- ├── ci-playbook.md # Known CI failures
758
- ├── .session-name # Notification routing
759
- ├── .discovery-cache.json # Cached discovery (auto-generated)
760
- ├── .session-state.json # Session continuity (auto-generated)
761
- ├── .gates-passed # Gate sentinel (auto-generated)
762
- └── settings.local.json # Hooks + permissions
763
- ```
328
+ 4. **Enforce, don't instruct.** Hooks are 100% reliable at zero token cost. Prose rules in context files are ~80% compliant. Critical behavior (destructive-command blocks, gate enforcement) goes in hooks.
764
329
 
765
330
  ---
766
331
 
767
- ## Principles
768
-
769
- 1. **Discover, don't hardcode.** Every fact about the codebase is read at runtime. The skills never say "22 controllers" — they say "read the controller directory."
332
+ ## Honest status
770
333
 
771
- 2. **Govern, don't hope.** Your quality bar lives in `governance.md`. The skills enforce it but never modify it. It changes only when you change it.
334
+ - **Published:** 2026-04-04 as `@whitehatd/crag` on npm. Scoped public package.
335
+ - **Tests:** 323 unit tests, passing on Ubuntu/macOS/Windows × Node 18/20/22.
336
+ - **Benchmark:** 17/20 grade A, 0/20 grade C across the 20 reference repos. Reproducible via `benchmarks/results.md`.
337
+ - **Languages fully supported:** Node, Deno, Bun, Python, Rust, Go, Java, Kotlin, Ruby, PHP, .NET, Swift, Elixir (+ Terraform/Helm/K8s infra gates).
338
+ - **CI systems parsed:** 9 (GitHub Actions, GitLab CI, CircleCI, Travis, Azure Pipelines, Buildkite, Drone, Woodpecker, Bitbucket).
339
+ - **Compile targets:** 12 (GitHub Actions, husky, pre-commit, AGENTS.md, Cursor, Gemini, Copilot, Cline, Continue, Windsurf, Zed, Cody).
772
340
 
773
- 3. **Ship the engine, generate the config.** Universal skills ship once. `governance.md` is generated per-project. The engine works forever. The config is 20 lines.
341
+ ### Known limitations
774
342
 
775
- 4. **Enforce, don't instruct.** Hooks are 100% reliable at zero token cost. CLAUDE.md rules are ~80% compliance. Critical behavior goes in hooks.
343
+ - **FastAPI and similar repos** where CI runs via `uv run ./scripts/*.py` data-pipeline scripts: crag captures the script invocations as gates. A user reviewing the output should prune the ones that aren't quality checks.
344
+ - **Complex CI matrix template expansions** (clap's `make test-${{matrix.features}}` pattern): line-based extraction captures one variant per template; multi-line YAML join is not implemented yet.
345
+ - **Jenkinsfile** (Groovy): CI system is detected but step extraction is not attempted.
346
+ - **No telemetry, no network calls** beyond the optional `crag upgrade --check` npm registry ping (24h cached, 3s timeout, graceful offline).
776
347
 
777
- 5. **Compound, don't restart.** Cross-session memory means each session knows what the last one learned. Knowledge self-verifies against source files.
348
+ ### What crag does not do
778
349
 
779
- 6. **Guard, don't trust.** Security hooks hard-block destructive commands at the system level `rm -rf /`, `DROP TABLE`, `curl|bash`, force-push to main. Even if instructions are misread, the sandbox catches it. Defense in depth: hooks enforce what skills instruct.
780
-
781
- 7. **Cache, don't re-discover.** Every discovery result is cached with content hashes. If nothing changed, the next session starts in seconds, not minutes. The cache is advisory — if it's wrong, full discovery runs as normal.
350
+ - It does not write or modify code in your repo.
351
+ - It does not call any LLM. Discovery, analysis, and compilation are pure filesystem operations.
352
+ - It does not replace your CI provider, your linters, or your test runners. It generates config for them.
353
+ - It does not gate-keep. You can add, remove, or edit any gate in `governance.md` at any time.
782
354
 
783
355
  ---
784
356
 
785
- ## Prior Art
786
-
787
- An independent review assessed every major AI coding tool, open-source project, academic paper, and patent filing as of April 2026. The closest candidates and why they differ:
357
+ ## Why "crag"
788
358
 
789
- | Candidate | What it does | Why it's not this |
790
- |---|---|---|
791
- | **AGENTS.md** (60K+ repos) | Static config file AI agents read | Human-maintained, multiple files by scope, no runtime discovery |
792
- | **Claude Code** `/init` + CLAUDE.md | Scans repo, generates static instructions | Generates static output that rots. Multiple files. No governance separation |
793
- | **Cursor** `.cursor/rules/` | Per-directory rule files | Static context, multiple artifacts, no universal engine |
794
- | **Gemini CLI** GEMINI.md hierarchy | JIT instruction file scanning | Discovers *instruction files*, not the project itself |
795
- | **Kiro** steering docs | Generates product/tech/structure docs | Multiple steering files, not single governance, not universal |
796
- | **Codex** AGENTS.md + hooks + skills | Layered static instructions + extensibility | Instruction chain by directory. Could host this engine but doesn't ship one |
797
- | **claude-code-kit** | Framework detection + generated .claude/ | Kit/framework-specific (Next.js, React, Express). Not universal polyglot |
798
- | **OpenDev** (arxiv paper) | CLI agent with lazy tool discovery | Research prototype. No governance file. Not productized |
799
- | **Repo2Run** (arxiv paper) | Repo → runnable Dockerfile synthesis | Build/CI domain only. No agent governance architecture |
800
-
801
- **Adjacent patents identified:**
802
- - **US20250291583A1** (Microsoft) — YAML-configured agent rules/actions. Covers "config file drives AI agents" broadly but not universal repo discovery.
803
- - **US9898393B2** (Solano Labs) — Repo pattern analysis → inferred CI config. Strong historic prior art for build-system discovery, but not AI agent governance.
804
-
805
- Neither patent blocks this architecture. Both are adjacent, not overlapping.
806
-
807
- **Three novelty hypotheses validated by the review:**
808
- 1. **Compositional:** Many systems have pieces (hooks, skills, context files). None compose them into universal discovery engine + single governance file + continuously regenerated artifacts.
809
- 2. **Scope:** Closest implementations (claude-code-kit) are framework-specific, not polyglot-universal.
810
- 3. **Governance-as-contract:** Existing tools treat instruction files as context (often non-enforced). This treats governance as an executable contract that deterministically shapes gates and commit behavior.
359
+ A crag is a rocky outcrop — an unmoving landmark that stands while seasons, paths, and generations change around it. Your skills discover, your gates run, your CI regenerates — but `governance.md`, the crag, doesn't move until you say so. Your AI agents anchor to it.
811
360
 
812
361
  ---
813
362
 
814
- ## Roadmap
815
-
816
- - [x] Universal pre-start and post-start skills
817
- - [x] Interview-driven governance generation
818
- - [x] CLI (`crag init`, `crag check`, `crag install`)
819
- - [x] Proven on 5-language multi-service project (StructuAI)
820
- - [x] Proven on full-stack monolith with blue-green deploys (Leyoda)
821
- - [x] Proven on 11-microservice K8s platform with dual-repo governance (MetricHost)
822
- - [x] Multi-level governance hierarchy (root + backend + frontend)
823
- - [x] `crag compile` — governance.md → GitHub Actions, husky, pre-commit, AGENTS.md, Cursor, Gemini
824
- - [x] Incremental discovery cache — content-addressed, skips 80% of pre-start on unchanged projects
825
- - [x] Intent-scoped discovery — classifies task, skips irrelevant domains
826
- - [x] Session continuity — warm starts via `.session-state.json`
827
- - [x] Gate auto-fix loop — fixes lint/format errors automatically, bounded retry (max 2x)
828
- - [x] Auto-post-start hook — gate enforcement before commits
829
- - [x] Sandbox guard — hard-blocks destructive commands (rm -rf /, DROP TABLE, curl|bash, force-push main)
830
- - [x] `crag analyze` — generate governance from existing project without interview
831
- - [x] `crag diff` — compare governance against codebase reality
832
- - [x] `crag upgrade` — update universal skills when new version ships
833
- - [x] `crag workspace` — inspect detected workspace type and members
834
- - [x] Workspace detection — 11+ types (pnpm, npm, Cargo, Go, Gradle, Maven, Nx, Turbo, Bazel, submodules, nested repos)
835
- - [x] Governance v2 format — path-scoped gates, conditional sections, mandatory/optional/advisory classification
836
- - [x] Auto-update — version tracking, npm registry check, content-hash conflict detection
837
- - [x] Cross-agent compilation — **12 targets** (GitHub Actions, husky, pre-commit, AGENTS.md, Cursor, Gemini, Copilot, Cline, Continue, Windsurf, Zed, Sourcegraph Cody)
838
- - [x] Modular architecture — 24 modules across 6 directories (zero dependencies)
839
- - [x] Test suite — 159 tests covering parse, integrity, detect, enumerate, merge, compile, version, shell, CLI, 6 new compile targets, analyze internals, diff internals
840
- - [x] Published on npm as `@whitehatd/crag`
841
- - [x] GitHub Actions CI/CD — multi-OS (Ubuntu/macOS/Windows) × multi-Node (18/20/22) test matrix, automated npm publish with SLSA provenance, stale issue cleanup
842
- - [ ] Cross-repo benchmark — 20-30 repos, measure coverage %, false positives, failure modes
843
- - [ ] Drift resilience test — add services, change linters, rename directories. Does the engine re-discover?
844
- - [ ] Baseline comparison — same governance in AGENTS.md, CLAUDE.md, .cursor/rules, GEMINI.md
845
- - [ ] crag Cloud (paid tier) — hosted governance registry, cross-repo dashboard, team library, compliance templates, drift alerts
363
+ ## Contributing
364
+
365
+ Issues and PRs welcome at [github.com/WhitehatD/crag](https://github.com/WhitehatD/crag). See [CONTRIBUTING.md](./CONTRIBUTING.md) for the workflow.
366
+
367
+ If you run crag on a repo and it misses something — a language, a CI system, a gate pattern — that's the bug report I want most. Include the URL of the repo and a paste of `crag analyze --dry-run` output.
846
368
 
847
369
  ---
848
370
 
849
371
  ## License
850
372
 
851
- MIT
852
-
853
- ---
373
+ MIT — see [LICENSE](./LICENSE).
854
374
 
855
- *Built by [Alexandru Cioc (WhitehatD)](https://github.com/WhitehatD)*
375
+ Built by [Alexandru Cioc (WhitehatD)](https://github.com/WhitehatD).