@whitehatd/crag 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +864 -15
- package/bin/crag.js +7 -0
- package/package.json +18 -4
- package/src/cli.js +102 -0
- package/src/commands/analyze.js +513 -0
- package/src/commands/check.js +55 -0
- package/src/commands/compile.js +104 -0
- package/src/commands/diff.js +289 -0
- package/src/commands/init.js +112 -0
- package/src/commands/upgrade.js +64 -0
- package/src/commands/workspace.js +94 -0
- package/src/compile/agents-md.js +58 -0
- package/src/compile/atomic-write.js +32 -0
- package/src/compile/cline.js +83 -0
- package/src/compile/cody.js +82 -0
- package/src/compile/continue.js +78 -0
- package/src/compile/copilot.js +70 -0
- package/src/compile/cursor-rules.js +66 -0
- package/src/compile/gemini-md.js +58 -0
- package/src/compile/github-actions.js +165 -0
- package/src/compile/husky.js +66 -0
- package/src/compile/pre-commit.js +50 -0
- package/src/compile/windsurf.js +76 -0
- package/src/compile/zed.js +86 -0
- package/src/crag-agent.md +254 -0
- package/src/governance/gate-to-shell.js +28 -0
- package/src/governance/parse.js +182 -0
- package/src/skills/post-start-validation.md +297 -0
- package/src/skills/pre-start-context.md +506 -0
- package/src/update/integrity.js +131 -0
- package/src/update/skill-sync.js +116 -0
- package/src/update/version-check.js +156 -0
- package/src/workspace/detect.js +190 -0
- package/src/workspace/enumerate.js +270 -0
- package/src/workspace/governance.js +119 -0
- package/cli.js +0 -15
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: post-start-validation
|
|
3
|
+
version: 0.2.1
|
|
4
|
+
source_hash: 5a64dfe68b13577dff818fa63ddb6185be360c80b100f205bc586aac39e19e80
|
|
5
|
+
description: Universal validation and knowledge capture. Detects what changed, runs governance gates, captures knowledge, verifies deployment. Works for any project.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# /post-start-validation
|
|
9
|
+
|
|
10
|
+
Run **after completing any task**. Discovers what changed, applies governance gates, captures knowledge, commits and verifies.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 0. Shell Rule
|
|
15
|
+
|
|
16
|
+
Detect OS. Use Git Bash syntax on Windows (forward slashes, /dev/null).
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 1. Determine Scope
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
git diff --name-only HEAD 2>/dev/null || git status --short
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Classify changes by detecting file patterns:
|
|
27
|
+
- **Frontend?** — `.ts`, `.tsx`, `.js`, `.jsx`, `.css`, `.vue`, `.svelte` files
|
|
28
|
+
- **Backend?** — `.java`, `.kt`, `.py`, `.go`, `.rs`, `.rb` files
|
|
29
|
+
- **Infrastructure?** — `Dockerfile`, `docker-compose*`, `k8s/`, `.github/workflows/`, `*.tf`
|
|
30
|
+
- **Docs-only?** — `.md` files only outside source directories
|
|
31
|
+
|
|
32
|
+
> **Skip rules:** Docs-only → skip code checks. Infra-only → skip local checks.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 2. Read Governance Gates
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
Read .claude/governance.md
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
> The governance file defines which gates to run and in what order. If it specifies "biome → tsc → build" — run exactly that. If it specifies "pytest" — run that. The gates are project-specific; this skill is not.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 3. Run Gates
|
|
47
|
+
|
|
48
|
+
### 3.0. Workspace-aware gate execution
|
|
49
|
+
|
|
50
|
+
If the discovery cache indicates a workspace:
|
|
51
|
+
1. Read root governance gates (from workspace root `.claude/governance.md`)
|
|
52
|
+
2. Identify which members have changes: check `git diff --name-only HEAD` paths
|
|
53
|
+
3. For changed members with their own governance: read member governance, merge with root gates
|
|
54
|
+
4. Execute merged gates in order: root cross-stack gates first, then member-specific gates
|
|
55
|
+
|
|
56
|
+
### Gate annotations (v2 format)
|
|
57
|
+
|
|
58
|
+
**Path-scoped sections:** `### Frontend (path: frontend/)`
|
|
59
|
+
Before running any command in this section, `cd` into the specified directory. After the section completes, `cd` back to the project root. Example:
|
|
60
|
+
```bash
|
|
61
|
+
(cd frontend/ && npx biome check .) || exit 1
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Conditional sections:** `### TypeScript (if: tsconfig.json)`
|
|
65
|
+
Skip the ENTIRE section if the referenced file does not exist at project root. Check before running any gate in the section:
|
|
66
|
+
```bash
|
|
67
|
+
[ -e tsconfig.json ] || echo "Skipping TypeScript gates (no tsconfig.json)"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Gate classifications** (suffix on individual gate lines):
|
|
71
|
+
- `# [MANDATORY]` (default) — stop execution on failure
|
|
72
|
+
- `# [OPTIONAL]` — log failure, print warning, continue to next gate
|
|
73
|
+
- `# [ADVISORY]` — always run, log result, never stop
|
|
74
|
+
|
|
75
|
+
When an OPTIONAL gate fails:
|
|
76
|
+
1. Print: `⚠ [OPTIONAL] <gate command> failed — continuing`
|
|
77
|
+
2. Record in gate_results.failed but do NOT exit
|
|
78
|
+
3. Proceed to the next gate in order
|
|
79
|
+
|
|
80
|
+
When an ADVISORY gate fails:
|
|
81
|
+
1. Print: `ℹ [ADVISORY] <gate command> failed (informational)`
|
|
82
|
+
2. Record in gate_results.failed for session state
|
|
83
|
+
3. Always proceed
|
|
84
|
+
|
|
85
|
+
**Inheritance marker:** `## Gates (inherit: root)`
|
|
86
|
+
When found in a member's governance.md, merge root gates first (prepend), then member gates (append). Execute in order.
|
|
87
|
+
|
|
88
|
+
### Standard execution (no annotations)
|
|
89
|
+
|
|
90
|
+
Execute the gates defined in governance.md, in order. Stop at first MANDATORY failure.
|
|
91
|
+
|
|
92
|
+
**Common patterns** (the governance file will specify which apply):
|
|
93
|
+
|
|
94
|
+
Frontend gates:
|
|
95
|
+
```
|
|
96
|
+
# Lint (biome, eslint, etc.)
|
|
97
|
+
# Type check (tsc --noEmit, mypy, etc.)
|
|
98
|
+
# Build (npm run build, etc.)
|
|
99
|
+
# Test (vitest, jest, pytest, etc.)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Backend gates:
|
|
103
|
+
```
|
|
104
|
+
# Compile (gradlew compileJava, cargo build, go build, etc.)
|
|
105
|
+
# Test (gradlew test, pytest, cargo test, go test, etc.)
|
|
106
|
+
# Check (gradlew check, clippy, etc.)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
> Use `rtk` prefix on all commands for token compression.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 3.5. Gate Auto-Fix (Bounded Retry)
|
|
114
|
+
|
|
115
|
+
If a gate command fails, attempt an automatic fix before escalating to the user.
|
|
116
|
+
|
|
117
|
+
**Step 1 — Classify the failure:**
|
|
118
|
+
|
|
119
|
+
| Error pattern | Classification | Action |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| Lint errors with auto-fix flag | **Auto-fixable** | Run linter with `--fix` / `--write` |
|
|
122
|
+
| Format errors (prettier, rustfmt, ruff, biome) | **Auto-fixable** | Run the formatter on affected files |
|
|
123
|
+
| Unused imports / variables | **Auto-fixable** | Remove them |
|
|
124
|
+
| Missing semicolons, trailing commas | **Auto-fixable** | Fix inline |
|
|
125
|
+
| Type errors in files you changed this session | **Maybe fixable** | Attempt one fix, re-run |
|
|
126
|
+
| Failing tests | **NOT auto-fixable** | Escalate — tests may be validating the change |
|
|
127
|
+
| Build errors from missing dependencies | **NOT auto-fixable** | Escalate |
|
|
128
|
+
| Errors in files you did NOT change | **NOT auto-fixable** | Escalate — pre-existing issue |
|
|
129
|
+
|
|
130
|
+
**Step 2 — If auto-fixable, apply the fix:**
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# Lint auto-fix (use whichever the project has)
|
|
134
|
+
npx eslint --fix <files> # or: npx biome check --write <files>
|
|
135
|
+
npx prettier --write <files> # format
|
|
136
|
+
cargo clippy --fix --allow-dirty # Rust
|
|
137
|
+
ruff check --fix <files> # Python
|
|
138
|
+
ruff format <files> # Python format
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
For other mechanical errors (unused imports, missing semicolons): edit the files directly.
|
|
142
|
+
|
|
143
|
+
**Auto-fix boundaries:**
|
|
144
|
+
- ONLY edit files within this repository
|
|
145
|
+
- NEVER install new global packages as a fix
|
|
146
|
+
- NEVER modify files outside the repo or system config
|
|
147
|
+
- NEVER delete files that weren't created this session
|
|
148
|
+
- If a fix requires out-of-bounds changes → escalate to user
|
|
149
|
+
|
|
150
|
+
**Step 3 — Re-run ONLY the failed gate.** Do not re-run gates that already passed.
|
|
151
|
+
|
|
152
|
+
**Step 4 — Bounded retry:**
|
|
153
|
+
- Maximum **2 auto-fix attempts** per gate
|
|
154
|
+
- If the same gate fails after 2 attempts → **stop and escalate to the user**
|
|
155
|
+
- Never retry the exact same fix that didn't work
|
|
156
|
+
- The circuit breaker hook (`PostToolUseFailure`) provides an additional safety net
|
|
157
|
+
|
|
158
|
+
**Step 5 — After ALL gates pass, write the sentinel:**
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
touch .claude/.gates-passed
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
This sentinel is:
|
|
165
|
+
- **Checked** by the auto-post-start hook before commits
|
|
166
|
+
- **Cleared** by pre-start-context at the beginning of each session
|
|
167
|
+
- Ensures gates are verified at least once per session before any commit
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 4. Cross-Stack Consistency
|
|
172
|
+
|
|
173
|
+
If both frontend and backend changed, verify alignment:
|
|
174
|
+
- API contracts match (routes, types, schemas)
|
|
175
|
+
- New environment variables added to `.env.example`
|
|
176
|
+
- Docker/K8s configs updated if services changed
|
|
177
|
+
- Migration files don't conflict
|
|
178
|
+
|
|
179
|
+
> Read governance.md for project-specific alignment points.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## 5. Security Review
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
Grep -rn "sk_live\|sk_test\|AKIA\|password.*=.*['\"]" . --type ts --type java --type py 2>/dev/null | grep -v node_modules | grep -v test | grep -v example | head -20
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
For every new endpoint/route added:
|
|
190
|
+
- Authentication required (unless explicitly public)?
|
|
191
|
+
- Input validation present?
|
|
192
|
+
- No mass-assignment (explicit DTOs, not raw entity binding)?
|
|
193
|
+
|
|
194
|
+
> Read governance.md for project-specific security requirements (rate limiting, file upload rules, auth patterns).
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## 6. Documentation
|
|
199
|
+
|
|
200
|
+
If changes introduced new endpoints, services, env vars, or architecture changes — update README.
|
|
201
|
+
|
|
202
|
+
If changes are bug fixes, refactors, tests, CSS — skip.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## 7. Knowledge Capture
|
|
207
|
+
|
|
208
|
+
If MemStack rules exist (`.claude/rules/diary.md`), follow them — add-insight, add-session, set-context.
|
|
209
|
+
|
|
210
|
+
If not, at minimum report:
|
|
211
|
+
- What was done
|
|
212
|
+
- Key decisions made and why
|
|
213
|
+
- Any gotchas discovered
|
|
214
|
+
- What to do next session
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## 8. Self-Update
|
|
219
|
+
|
|
220
|
+
Check: did any governance rule get violated during this session? Did any discovery instruction find something unexpected?
|
|
221
|
+
|
|
222
|
+
**If governance was violated:** Flag it to the user. Do NOT change governance.md.
|
|
223
|
+
|
|
224
|
+
**If the pre-start or post-start skill itself had a gap** (missing a check, wrong assumption): Update the skill file. Log the change.
|
|
225
|
+
|
|
226
|
+
> Discovery instructions rarely need updating — they read the filesystem. Governance rules only change when the user decides.
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## 9. Commit & Deploy
|
|
231
|
+
|
|
232
|
+
Read governance.md for:
|
|
233
|
+
- Branch strategy (feature branches or trunk-based?)
|
|
234
|
+
- Commit convention (conventional commits or free-form?)
|
|
235
|
+
- Autonomy level (auto-commit after gates or ask first?)
|
|
236
|
+
|
|
237
|
+
Execute accordingly:
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
git add <files>
|
|
241
|
+
git commit -m "<type>: <description>
|
|
242
|
+
|
|
243
|
+
Co-Authored-By: Claude <noreply@anthropic.com>"
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Then:
|
|
247
|
+
- Push to remote
|
|
248
|
+
- Monitor CI (if configured): `gh run list --limit 3`
|
|
249
|
+
- Verify deployment (if governance specifies how)
|
|
250
|
+
|
|
251
|
+
### Branch cleanup (if feature branch workflow)
|
|
252
|
+
|
|
253
|
+
After merge:
|
|
254
|
+
```
|
|
255
|
+
git branch -d <branch-name>
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Skip Rules
|
|
261
|
+
|
|
262
|
+
| Change type | Skip |
|
|
263
|
+
|---|---|
|
|
264
|
+
| Docs-only | S3-S5 |
|
|
265
|
+
| Infra-only | S3 (local gates), S6 |
|
|
266
|
+
| Backend-only (no API change) | Frontend gates |
|
|
267
|
+
| Frontend-only (no API change) | Backend gates |
|
|
268
|
+
| CSS/styling only | Backend gates, S4, S5 |
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## 10. Write Session State
|
|
273
|
+
|
|
274
|
+
Write `.claude/.session-state.json` for warm starts next session:
|
|
275
|
+
|
|
276
|
+
```json
|
|
277
|
+
{
|
|
278
|
+
"version": 1,
|
|
279
|
+
"timestamp": "<ISO 8601 — use: date -u +%Y-%m-%dT%H:%M:%SZ>",
|
|
280
|
+
"branch": "<current branch>",
|
|
281
|
+
"commit": "<HEAD short hash>",
|
|
282
|
+
"task_summary": "<one-line summary of what was accomplished>",
|
|
283
|
+
"gate_results": {
|
|
284
|
+
"passed": ["<gate commands that passed>"],
|
|
285
|
+
"failed": ["<gate commands that failed — empty if all passed>"],
|
|
286
|
+
"auto_fixed": ["<gates that needed auto-fix before passing>"]
|
|
287
|
+
},
|
|
288
|
+
"files_changed": ["<files modified this session>"],
|
|
289
|
+
"open_questions": ["<unresolved decisions or ambiguities>"],
|
|
290
|
+
"next_steps": ["<suggested actions for next session>"]
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
This file is consumed by pre-start Section 0.1 for warm starts. It enables the next session to:
|
|
295
|
+
- Skip re-explaining context if the user is continuing the same work
|
|
296
|
+
- Surface open questions and next steps immediately
|
|
297
|
+
- Combined with the discovery cache, achieve near-zero-latency startup
|