crewkit 0.1.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/LICENSE +21 -0
- package/README.md +100 -0
- package/bin/crewkit.js +4 -0
- package/package.json +37 -0
- package/skill/SKILL.md +1050 -0
- package/skill/templates/agents/architect.md +103 -0
- package/skill/templates/agents/coder.md +63 -0
- package/skill/templates/agents/explorer.md +51 -0
- package/skill/templates/agents/reviewer.md +108 -0
- package/skill/templates/agents/tester.md +118 -0
- package/skill/templates/hooks/post-compact-recovery.sh +11 -0
- package/skill/templates/hooks/protect-sensitive-files.sh +23 -0
- package/skill/templates/hooks/session-start.sh +29 -0
- package/skill/templates/hooks/stop-quality-gate.sh +25 -0
- package/skill/templates/skills/explore-and-plan/SKILL.md +119 -0
- package/skill/templates/skills/full-workflow/SKILL.md +212 -0
- package/skill/templates/skills/hotfix/SKILL.md +117 -0
- package/skill/templates/skills/review-pr/SKILL.md +53 -0
- package/src/cli.js +35 -0
- package/src/install.js +40 -0
package/skill/SKILL.md
ADDED
|
@@ -0,0 +1,1050 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: crewkit-setup
|
|
3
|
+
description: "Scan your codebase and generate a complete context engineering setup: agents, skills, hooks, rules, memory, CLAUDE.md, settings.json, .mcp.json. One command, fully calibrated to your project."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Set up context engineering for this project.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# crewkit-setup
|
|
11
|
+
|
|
12
|
+
This skill scans the current project's codebase and generates a complete, calibrated context engineering setup. It produces agents, skills, hooks, rules, memory files, CLAUDE.md, settings.json, napkin.md, QUICKSTART.md, and .mcp.json — all tailored to the actual code, not generic boilerplate.
|
|
13
|
+
|
|
14
|
+
**You are the AI executing this skill.** Follow each phase in order. Do not skip phases. This is a fully autonomous flow — do NOT ask the user questions. Scan, generate, validate, report.
|
|
15
|
+
|
|
16
|
+
### Critical rules (read before starting)
|
|
17
|
+
1. **Language:** All generated files MUST be in **English**. User-facing output (reports during execution) matches the user's language.
|
|
18
|
+
2. **Zero questions:** Do not pause for user input except for re-run detection ([R]/[M]/[C]).
|
|
19
|
+
3. **Validate everything:** After all files are generated, run the completion checklist at the bottom of this document before reporting done.
|
|
20
|
+
4. **Persist to disk:** Write scan results to `.crewkit/` files at each phase. Read them back before generating. This survives context compaction.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Pre-flight
|
|
25
|
+
|
|
26
|
+
### 1. Model check
|
|
27
|
+
- Opus or Sonnet: proceed normally.
|
|
28
|
+
- Haiku or unknown: log a warning in the report ("Shallow scan — Haiku model detected") and proceed. Do not ask.
|
|
29
|
+
|
|
30
|
+
### 2. Re-run detection
|
|
31
|
+
Check if `.crewkit/version` exists.
|
|
32
|
+
|
|
33
|
+
**First run:** proceed to Phase 0 (which handles backup if existing files are found).
|
|
34
|
+
|
|
35
|
+
**Re-run** (file exists) — present to the user:
|
|
36
|
+
> "crewkit setup detected (v[version]). What would you like to do?"
|
|
37
|
+
> - **[R] Regenerate** — backup existing setup to `.crewkit-backup/`, regenerate everything
|
|
38
|
+
> - **[M] Memory only** — re-scan codebase and update `.ai/memory/` + `CLAUDE.md` + agent context headers, preserve agents/hooks/skills
|
|
39
|
+
> - **[C] Cancel**
|
|
40
|
+
|
|
41
|
+
Wait for user choice. On [R] or [M]: existing `lessons-*.md` files with content are **preserved and merged**, not overwritten — these contain accumulated institutional knowledge.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Phase 0 — Preparation
|
|
46
|
+
|
|
47
|
+
### Backup (if existing setup found)
|
|
48
|
+
If `.claude/` or `CLAUDE.md` or `.ai/memory/` exists:
|
|
49
|
+
1. Create `.crewkit-backup/` in project root
|
|
50
|
+
2. Copy existing files there with timestamp suffix
|
|
51
|
+
3. Report: "Existing setup backed up to `.crewkit-backup/`"
|
|
52
|
+
|
|
53
|
+
### Create directory structure
|
|
54
|
+
```
|
|
55
|
+
.claude/
|
|
56
|
+
agents/
|
|
57
|
+
hooks/
|
|
58
|
+
rules/
|
|
59
|
+
skills/
|
|
60
|
+
.ai/
|
|
61
|
+
memory/
|
|
62
|
+
plans/
|
|
63
|
+
.crewkit/
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Version tracking
|
|
67
|
+
Write the crewkit version to `.crewkit/version`:
|
|
68
|
+
```
|
|
69
|
+
0.1.0
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Update .gitignore
|
|
73
|
+
Append to `.gitignore` (create if missing, skip lines that already exist):
|
|
74
|
+
```gitignore
|
|
75
|
+
# crewkit — context engineering
|
|
76
|
+
.claude/settings.local.json
|
|
77
|
+
.crewkit/
|
|
78
|
+
.crewkit-backup/
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Report: "Phase 0 complete. Directory structure created."
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Phase 1 — Reconnaissance (~30s)
|
|
86
|
+
|
|
87
|
+
Detect the project's technology stack and infrastructure. Use glob patterns and file reads — no deep code analysis yet.
|
|
88
|
+
|
|
89
|
+
### Stack detection
|
|
90
|
+
Scan for manifest files to identify stacks:
|
|
91
|
+
|
|
92
|
+
| Manifest | Stack |
|
|
93
|
+
|----------|-------|
|
|
94
|
+
| `*.csproj`, `*.sln`, `*.fsproj` | .NET |
|
|
95
|
+
| `package.json` (with framework deps) | Node.js (+ detect Express, Next.js, Nest, etc.) |
|
|
96
|
+
| `go.mod` | Go |
|
|
97
|
+
| `Cargo.toml` | Rust |
|
|
98
|
+
| `pyproject.toml`, `requirements.txt`, `setup.py` | Python (+ detect Django, FastAPI, Flask, etc.) |
|
|
99
|
+
| `pom.xml`, `build.gradle` | Java/Kotlin |
|
|
100
|
+
| `Gemfile` | Ruby |
|
|
101
|
+
| `mix.exs` | Elixir |
|
|
102
|
+
| `composer.json` | PHP |
|
|
103
|
+
| `pubspec.yaml` | Dart/Flutter |
|
|
104
|
+
|
|
105
|
+
For each detected stack, note the framework and version when available.
|
|
106
|
+
|
|
107
|
+
### Git analysis
|
|
108
|
+
- Recent contributors (last 30 days): `git shortlog -sn --since="30 days ago"`
|
|
109
|
+
- Commit message style: read last 10 commits, detect pattern (conventional commits, ticket refs, freeform)
|
|
110
|
+
- Code language: detect predominant natural language from commit messages and comments (EN, PT-BR, ES, etc.)
|
|
111
|
+
- Hotspot files: `git log --since="30 days ago" --name-only --pretty=format: | sort | uniq -c | sort -rn | head -20`
|
|
112
|
+
|
|
113
|
+
### CI/CD detection
|
|
114
|
+
Glob for:
|
|
115
|
+
- `.github/workflows/*.yml` → GitHub Actions
|
|
116
|
+
- `.gitlab-ci.yml` → GitLab CI
|
|
117
|
+
- `Jenkinsfile` → Jenkins
|
|
118
|
+
- `.circleci/config.yml` → CircleCI
|
|
119
|
+
- `azure-pipelines.yml` → Azure DevOps
|
|
120
|
+
- `bitbucket-pipelines.yml` → Bitbucket
|
|
121
|
+
|
|
122
|
+
### Infrastructure detection
|
|
123
|
+
Scan `docker-compose*.yml`, env files, config files for:
|
|
124
|
+
- **Databases:** PostgreSQL, MySQL, MongoDB, Redis, SQLite, Supabase
|
|
125
|
+
- **Message brokers:** RabbitMQ, Kafka, Azure Service Bus, SQS
|
|
126
|
+
- **Cloud services:** AWS, Azure, GCP (from SDK deps or config)
|
|
127
|
+
- **Monitoring:** Sentry, Grafana, Datadog, New Relic (from deps)
|
|
128
|
+
|
|
129
|
+
### Build & test command detection
|
|
130
|
+
For each stack, detect the build and test commands:
|
|
131
|
+
|
|
132
|
+
| Stack | Build command | Test command |
|
|
133
|
+
|-------|--------------|-------------|
|
|
134
|
+
| .NET | `dotnet build [sln-path]` | `dotnet test [test-project-path]` |
|
|
135
|
+
| Node.js | `npm run build` or `npx tsc` | `npm test` |
|
|
136
|
+
| Go | `go build ./...` | `go test ./...` |
|
|
137
|
+
| Rust | `cargo build` | `cargo test` |
|
|
138
|
+
| Python | N/A or `python -m build` | `pytest` or `python -m pytest` |
|
|
139
|
+
| Java (Maven) | `mvn compile` | `mvn test` |
|
|
140
|
+
| Java (Gradle) | `./gradlew build` | `./gradlew test` |
|
|
141
|
+
| Ruby | `bundle exec rake build` | `bundle exec rspec` |
|
|
142
|
+
|
|
143
|
+
Read `package.json` scripts, CI configs, or Makefiles to find the actual commands used in this project. Prefer project-specific over generic.
|
|
144
|
+
|
|
145
|
+
**Store results as: `ReconProfile`** — write to `.crewkit/scan-phase1-recon.md` for persistence.
|
|
146
|
+
|
|
147
|
+
Report: "Phase 1 complete. Detected: [stacks], [CI], [DBs], [build/test commands]."
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Phase 2 — Documentation scan (~1min)
|
|
152
|
+
|
|
153
|
+
Read existing human-written documentation to understand project context, conventions, and team norms.
|
|
154
|
+
|
|
155
|
+
### Files to scan
|
|
156
|
+
|
|
157
|
+
**Project documentation:**
|
|
158
|
+
- `README.md` (or `README.rst`, `readme.md`)
|
|
159
|
+
- `CONTRIBUTING.md`
|
|
160
|
+
- `docs/` directory (scan filenames, read key files)
|
|
161
|
+
- `ARCHITECTURE.md` or `docs/ARCHITECTURE.md`
|
|
162
|
+
|
|
163
|
+
**Existing AI context (from any IDE — preserve, don't discard):**
|
|
164
|
+
- Existing `CLAUDE.md` (if backed up from a previous setup)
|
|
165
|
+
- Existing `.ai/memory/` files (if backed up)
|
|
166
|
+
- `.cursorrules` or `.cursor/rules/*.md` (Cursor)
|
|
167
|
+
- `.github/copilot-instructions.md` or `.github/instructions/*.md` (GitHub Copilot)
|
|
168
|
+
- `.github/agents/*.agent.md` (Copilot agents)
|
|
169
|
+
- `AGENTS.md` (Cursor agents)
|
|
170
|
+
|
|
171
|
+
If any of these exist, read them and extract rules, conventions, and patterns to incorporate into the generated setup. This preserves context engineering work done in other IDEs.
|
|
172
|
+
|
|
173
|
+
### Extract
|
|
174
|
+
- Project description and purpose
|
|
175
|
+
- **Business domain** (what the product does, core entities, risk profile — e.g., "WhatsApp customer service platform, manages conversations, worst case = message loss or cross-tenant data leak")
|
|
176
|
+
- Setup instructions (how to run locally)
|
|
177
|
+
- Contribution guidelines
|
|
178
|
+
- Architecture overview (if documented)
|
|
179
|
+
- Naming conventions mentioned
|
|
180
|
+
- Any AI-specific instructions already in place (from any IDE)
|
|
181
|
+
- Predominant documentation language (EN, PT-BR, ES, etc.)
|
|
182
|
+
|
|
183
|
+
**Store results as: `DocsProfile`** — append to `.crewkit/scan-phase2-docs.md` for persistence.
|
|
184
|
+
|
|
185
|
+
Report: "Phase 2 complete. Found: [list of docs read]."
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Phase 3 — Structural map (~2min)
|
|
190
|
+
|
|
191
|
+
Map the project structure to understand modules, entry points, and test setup.
|
|
192
|
+
|
|
193
|
+
### Directory tree
|
|
194
|
+
Generate a depth-3 tree of the project, ignoring noise directories:
|
|
195
|
+
- Ignore: `node_modules`, `bin`, `obj`, `.git`, `dist`, `build`, `__pycache__`, `.next`, `target`, `vendor`, `.venv`
|
|
196
|
+
|
|
197
|
+
### Entry points
|
|
198
|
+
For each detected stack, find the main entry point(s):
|
|
199
|
+
- .NET: `Program.cs`, `Startup.cs`, or `*.Api` project
|
|
200
|
+
- Node.js: `package.json` → `main` or `scripts.start`
|
|
201
|
+
- Go: `main.go` or `cmd/` directory
|
|
202
|
+
- Python: `manage.py`, `app.py`, `main.py`, or `__main__.py`
|
|
203
|
+
- Rust: `src/main.rs` or `src/lib.rs`
|
|
204
|
+
- Java: class with `main()` method
|
|
205
|
+
|
|
206
|
+
### Module boundaries
|
|
207
|
+
Identify distinct modules/packages/projects and their relationships:
|
|
208
|
+
- .NET: each `.csproj` is a module; read `ProjectReference` for dependencies
|
|
209
|
+
- Node.js monorepo: `workspaces` in `package.json`, or `packages/` directory
|
|
210
|
+
- Go: module paths in `go.mod`
|
|
211
|
+
- Python: top-level directories with `__init__.py`
|
|
212
|
+
|
|
213
|
+
### Test setup
|
|
214
|
+
- Test framework: detect from deps (xUnit, NUnit, Jest, Vitest, pytest, Go testing, etc.)
|
|
215
|
+
- Test directories: where tests live
|
|
216
|
+
- Test naming convention: from existing test files
|
|
217
|
+
- Test infrastructure: builders, fakes, fixtures, helpers
|
|
218
|
+
|
|
219
|
+
### Migrations
|
|
220
|
+
- EF Core: count files in `Migrations/` directory, note latest
|
|
221
|
+
- Prisma: `prisma/migrations/`
|
|
222
|
+
- Alembic: `alembic/versions/`
|
|
223
|
+
- Rails: `db/migrate/`
|
|
224
|
+
- Other ORMs: detect from file patterns
|
|
225
|
+
|
|
226
|
+
**Store results as: `StructureProfile`** — write to `.crewkit/scan-phase3-structure.md` for persistence.
|
|
227
|
+
|
|
228
|
+
Report: "Phase 3 complete. [N] modules mapped, [M] test files found, [K] entry points identified."
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## Phase 4 — Deep read (~5-15min)
|
|
233
|
+
|
|
234
|
+
This is the most important phase. Read representative source files to understand the project's actual patterns, conventions, and anti-patterns.
|
|
235
|
+
|
|
236
|
+
### File selection strategy
|
|
237
|
+
For each module detected in Phase 3, select up to 5 representative files:
|
|
238
|
+
|
|
239
|
+
1. **Most modified** in last 30 days (from git hotspot data in Phase 1)
|
|
240
|
+
2. **Most imported/depended on** (hub file — has the most reverse dependencies)
|
|
241
|
+
3. **Has corresponding test** (file with a matching test file)
|
|
242
|
+
4. **Entry point** of the module
|
|
243
|
+
5. **Largest file** (if not already covered — often contains the most complex logic)
|
|
244
|
+
|
|
245
|
+
**Limit:** max 25 files total across all modules. For large monorepos, focus on the 5 most active modules.
|
|
246
|
+
|
|
247
|
+
### What to read
|
|
248
|
+
Read each selected file **completely**. For each file, extract:
|
|
249
|
+
|
|
250
|
+
- **Architecture patterns:** DDD, Clean Architecture, MVC, hexagonal, event-driven, CQRS, microservices
|
|
251
|
+
- **Code patterns:** dependency injection, factory methods, builder pattern, repository pattern, middleware chain
|
|
252
|
+
- **Auth patterns:** JWT, session-based, OAuth, API keys, multi-tenant isolation
|
|
253
|
+
- **Error handling:** exceptions, Result types, error codes, try/catch patterns
|
|
254
|
+
- **Data access:** ORM patterns, raw SQL, repository interfaces, unit of work
|
|
255
|
+
- **Real-time:** WebSocket, SignalR, SSE, polling
|
|
256
|
+
- **Background processing:** queues, workers, cron jobs, hosted services
|
|
257
|
+
- **Caching:** Redis, in-memory, CDN
|
|
258
|
+
- **Entity conventions:** public/private constructors, factory methods, immutability
|
|
259
|
+
- **Naming conventions:** PascalCase, camelCase, snake_case, prefix/suffix patterns
|
|
260
|
+
- **Anti-patterns found:** files >500 lines, hardcoded secrets, SQL injection risks, missing input validation, no tests for module, god classes
|
|
261
|
+
|
|
262
|
+
### Targeted extractions (MANDATORY — these close specific quality gaps)
|
|
263
|
+
|
|
264
|
+
These are high-value extractions that generic pattern detection misses. Do ALL that apply:
|
|
265
|
+
|
|
266
|
+
**1. Constructor/DI signatures** — For every handler, service, or controller class that uses dependency injection, extract the constructor parameter list with types. Store as a table in the architecture output:
|
|
267
|
+
```
|
|
268
|
+
| Class | Constructor params |
|
|
269
|
+
|-------|------------------|
|
|
270
|
+
| SendMessageHandler | IConversationRepo, ITenantContext, IGatewayClient, ILogger<> |
|
|
271
|
+
```
|
|
272
|
+
This is critical for writing tests with hand-crafted fakes.
|
|
273
|
+
|
|
274
|
+
**2. Test infrastructure inventory** — Glob test directories for all classes matching `Fake*`, `Stub*`, `Mock*`, `*TestHelper*`, `*Builder*`, `*TestBase*`, `*Fixture*`. List each with its interface/purpose:
|
|
275
|
+
```
|
|
276
|
+
| Fake class | Implements | Location |
|
|
277
|
+
|-----------|-----------|----------|
|
|
278
|
+
| FakeConversationRepo | IConversationRepo | Tests.Unit/Fakes.cs |
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
**3. UI component library / Design system** — If the project has a frontend:
|
|
282
|
+
- Scan CSS files for `@layer components`, custom component classes, design tokens
|
|
283
|
+
- Scan component directories for reusable UI components (buttons, modals, inputs, icons)
|
|
284
|
+
- Extract the component contract (props/parameters, variants, rules)
|
|
285
|
+
- Store in conventions output as "Design System" section
|
|
286
|
+
|
|
287
|
+
**4. State machines** — Look for enums with `Status` or `State` in the name, classes with state transition methods, or files with explicit state machine patterns. Document:
|
|
288
|
+
- States and valid transitions
|
|
289
|
+
- Guard conditions
|
|
290
|
+
- Files involved
|
|
291
|
+
|
|
292
|
+
**5. Large files (>500 lines)** — These deserve extra attention. Read them fully and document:
|
|
293
|
+
- Why they're large (god class? complex domain logic? generated code?)
|
|
294
|
+
- Key internal patterns (closures, event handlers, timers, state management)
|
|
295
|
+
- Risks for modification (tight coupling, side effects, concurrency)
|
|
296
|
+
- For files with `setInterval`/`setTimeout`/timers: document timer lifecycle (create, clear, leak risks)
|
|
297
|
+
|
|
298
|
+
**6. Raw SQL / query patterns** — Find any raw SQL strings (not ORM-generated). Document:
|
|
299
|
+
- Whether they use parameterized queries or string interpolation (flag injection risks)
|
|
300
|
+
- Complex queries that future developers need to understand
|
|
301
|
+
|
|
302
|
+
### Confidence scoring
|
|
303
|
+
For each detected pattern, assign a confidence level:
|
|
304
|
+
|
|
305
|
+
| Confidence | Criteria | Action |
|
|
306
|
+
|------------|----------|--------|
|
|
307
|
+
| **HIGH** | 5+ files follow this pattern consistently | Generate as HARD rule in CLAUDE.md |
|
|
308
|
+
| **MEDIUM** | 2-4 files follow this pattern | Generate as rule with note "detected in N files" |
|
|
309
|
+
| **LOW** | 1 file or ambiguous | Observation only, do not generate rule |
|
|
310
|
+
|
|
311
|
+
### Parallel execution
|
|
312
|
+
If the project has 3+ distinct modules, use **parallel subagents** (explorer agents) to read files from different modules simultaneously. Each subagent reads its assigned files and returns a structured summary. Do NOT have each subagent read the entire codebase.
|
|
313
|
+
|
|
314
|
+
**Store results as: `DeepProfile`** — write to `.crewkit/scan-phase4-deep.md` for persistence.
|
|
315
|
+
|
|
316
|
+
**Context management:** Phase 4 is the most context-heavy phase. After completing it, if your context usage is high, use `/compact` before proceeding. The scan results are persisted in `.crewkit/` files — they survive compaction.
|
|
317
|
+
|
|
318
|
+
Report: "Phase 4 complete. [N] files analyzed across [M] modules. [K] patterns detected."
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
## Phase 5 — Health check (OPTIONAL)
|
|
323
|
+
|
|
324
|
+
**Only run if the user passed `--check-health` as an argument**, or if the user explicitly asked for health checking.
|
|
325
|
+
|
|
326
|
+
If not requested, skip entirely and proceed to Phase 6.
|
|
327
|
+
|
|
328
|
+
### Steps
|
|
329
|
+
1. Run the detected build command(s)
|
|
330
|
+
2. Run the detected test command(s)
|
|
331
|
+
3. Count: tests passed, tests failed, build warnings
|
|
332
|
+
|
|
333
|
+
**Store results as: `HealthProfile`** — write to `.crewkit/scan-phase5-health.md` for persistence.
|
|
334
|
+
|
|
335
|
+
Report: "Phase 5 complete. Build: [pass/fail]. Tests: [X passed, Y failed]."
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## Phase 6 — Project Profile (present to user)
|
|
340
|
+
|
|
341
|
+
Compile all profiles into a single summary and present it to the user.
|
|
342
|
+
|
|
343
|
+
### Profile format
|
|
344
|
+
|
|
345
|
+
```markdown
|
|
346
|
+
# Project Profile — [project name]
|
|
347
|
+
|
|
348
|
+
## Domain
|
|
349
|
+
- **What it does:** [1-2 sentences from README/docs — e.g., "Multi-tenant WhatsApp customer service platform"]
|
|
350
|
+
- **Core entities:** [main business objects — e.g., "Conversations, Messages, Tickets, Operators"]
|
|
351
|
+
- **Risk profile:** [worst-case scenario — e.g., "Cross-tenant data leak, message loss, billing errors"]
|
|
352
|
+
|
|
353
|
+
## Stacks
|
|
354
|
+
- [stack 1] — [framework] [version]
|
|
355
|
+
- [stack 2] — [framework] [version]
|
|
356
|
+
|
|
357
|
+
## Architecture
|
|
358
|
+
- [detected patterns with confidence level]
|
|
359
|
+
- Module count: [N]
|
|
360
|
+
- Key modules: [list with brief descriptions]
|
|
361
|
+
|
|
362
|
+
## Conventions
|
|
363
|
+
- Language: [code language] | Docs: [doc language]
|
|
364
|
+
- Naming: [detected conventions]
|
|
365
|
+
- Entity pattern: [e.g., "private setters, factory methods" or "public constructors"]
|
|
366
|
+
- Test pattern: [framework, naming, structure]
|
|
367
|
+
|
|
368
|
+
## Infrastructure
|
|
369
|
+
- CI: [detected CI]
|
|
370
|
+
- DB: [databases]
|
|
371
|
+
- Monitoring: [tools]
|
|
372
|
+
- MCPs recommended: [list]
|
|
373
|
+
|
|
374
|
+
## Patterns (HIGH confidence — will become rules)
|
|
375
|
+
- [pattern 1]
|
|
376
|
+
- [pattern 2]
|
|
377
|
+
|
|
378
|
+
## Patterns (MEDIUM confidence — will become rules with note)
|
|
379
|
+
- [pattern 1] (seen in N files)
|
|
380
|
+
|
|
381
|
+
## Observations (LOW confidence — noted but no rules generated)
|
|
382
|
+
- [observation 1]
|
|
383
|
+
|
|
384
|
+
## Anti-patterns found
|
|
385
|
+
- [anti-pattern 1]
|
|
386
|
+
- [anti-pattern 2]
|
|
387
|
+
|
|
388
|
+
## Health (if checked)
|
|
389
|
+
- Build: [status]
|
|
390
|
+
- Tests: [X passed, Y failed]
|
|
391
|
+
|
|
392
|
+
## Commands
|
|
393
|
+
- Build: `[command]`
|
|
394
|
+
- Test: `[command]`
|
|
395
|
+
- Dev server: `[command]` (if detected)
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### Save profile
|
|
399
|
+
Write the profile to `.crewkit/last-scan.md` for future reference.
|
|
400
|
+
|
|
401
|
+
### Present and proceed
|
|
402
|
+
Show the profile to the user as an informational report. Do NOT ask for confirmation — proceed directly to Phase 7. The user can adjust the generated files afterwards.
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
## Phase 7 — Generation
|
|
407
|
+
|
|
408
|
+
### MANDATORY: Reload scan data before generating
|
|
409
|
+
|
|
410
|
+
Before generating ANY file, re-read the persisted scan results to ensure they survive context compaction:
|
|
411
|
+
1. Read `.crewkit/last-scan.md` — the consolidated project profile
|
|
412
|
+
2. If `last-scan.md` is missing or incomplete, read the individual phase files:
|
|
413
|
+
- `.crewkit/scan-phase1-recon.md` (stacks, commands, CI, infra)
|
|
414
|
+
- `.crewkit/scan-phase2-docs.md` (documentation, language)
|
|
415
|
+
- `.crewkit/scan-phase3-structure.md` (modules, tests, entry points)
|
|
416
|
+
- `.crewkit/scan-phase4-deep.md` (patterns, confidence, anti-patterns)
|
|
417
|
+
|
|
418
|
+
This step is critical for large projects where context compaction may have evicted scan data.
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
Generate all files in order. This order is designed for **graceful failure** — if the process is interrupted, the user has the most valuable files first.
|
|
423
|
+
|
|
424
|
+
**If the user chose [M] (memory only):** generate steps 1-2 (memory + CLAUDE.md), then update the `<!-- crewkit:context-start -->` headers in existing agents (Step 3, header-only — do not overwrite agent body). Stop after that.
|
|
425
|
+
|
|
426
|
+
### Templates directory
|
|
427
|
+
Templates are located at `~/.claude/skills/crewkit-setup/templates/`. Read them from disk.
|
|
428
|
+
On Windows, `~` expands to `%USERPROFILE%` (typically `C:\Users\<username>`). Use the home directory path.
|
|
429
|
+
|
|
430
|
+
---
|
|
431
|
+
|
|
432
|
+
### Step 1 — `.ai/memory/` (AI-generated from scan)
|
|
433
|
+
|
|
434
|
+
Generate these files from the scan results. These are factual descriptions of the codebase — not opinions, not templates.
|
|
435
|
+
|
|
436
|
+
#### `architecture.md`
|
|
437
|
+
```markdown
|
|
438
|
+
# Architecture
|
|
439
|
+
|
|
440
|
+
## Overview
|
|
441
|
+
[1-2 paragraphs describing the project architecture, derived from Phase 3-4 analysis]
|
|
442
|
+
|
|
443
|
+
## Modules
|
|
444
|
+
| Module | Role | Key files |
|
|
445
|
+
|--------|------|-----------|
|
|
446
|
+
[one row per module detected]
|
|
447
|
+
|
|
448
|
+
## Layer rules
|
|
449
|
+
[dependency rules between modules — what can reference what]
|
|
450
|
+
|
|
451
|
+
## Key patterns
|
|
452
|
+
[patterns detected with HIGH confidence]
|
|
453
|
+
|
|
454
|
+
## Entry points
|
|
455
|
+
[main entry points per stack]
|
|
456
|
+
|
|
457
|
+
## Constructor/DI Signatures
|
|
458
|
+
[from targeted extraction #1 — table of handler/service classes with their constructor params]
|
|
459
|
+
| Class | Constructor params |
|
|
460
|
+
|-------|------------------|
|
|
461
|
+
[one row per DI class found]
|
|
462
|
+
|
|
463
|
+
## State Machines
|
|
464
|
+
[from targeted extraction #4 — states, transitions, guard conditions, files]
|
|
465
|
+
|
|
466
|
+
## High-Risk Files
|
|
467
|
+
[from targeted extraction #5 — files >500 lines with detailed analysis]
|
|
468
|
+
For each large file:
|
|
469
|
+
- File path and line count
|
|
470
|
+
- Why it's large (domain complexity, god class, generated)
|
|
471
|
+
- Internal patterns (closures, event handlers, timers, state management)
|
|
472
|
+
- Modification risks (coupling, side effects, concurrency)
|
|
473
|
+
- Timer lifecycle if applicable (create, clear, leak risks)
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
#### `conventions.md`
|
|
477
|
+
```markdown
|
|
478
|
+
# Conventions
|
|
479
|
+
|
|
480
|
+
## Naming
|
|
481
|
+
[detected naming conventions per stack]
|
|
482
|
+
|
|
483
|
+
## Code style
|
|
484
|
+
[patterns detected: entity construction, error handling, DI, etc.]
|
|
485
|
+
|
|
486
|
+
## Anti-patterns to avoid
|
|
487
|
+
[anti-patterns found during scan + universal ones]
|
|
488
|
+
|
|
489
|
+
## Design System
|
|
490
|
+
[from targeted extraction #3 — if frontend detected: component library, CSS tokens, component contracts]
|
|
491
|
+
[if no frontend: omit this section]
|
|
492
|
+
|
|
493
|
+
## Security checklist
|
|
494
|
+
- [ ] Input validation at system boundaries
|
|
495
|
+
- [ ] No hardcoded secrets
|
|
496
|
+
- [ ] Auth/authz on every endpoint
|
|
497
|
+
- [ ] Multi-tenant isolation (if applicable)
|
|
498
|
+
- [ ] No SQL injection (parameterized queries)
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
#### `commands.md`
|
|
502
|
+
```markdown
|
|
503
|
+
# Commands
|
|
504
|
+
|
|
505
|
+
## Build
|
|
506
|
+
[per-stack build commands]
|
|
507
|
+
|
|
508
|
+
## Test
|
|
509
|
+
[per-stack test commands, including filtered test commands]
|
|
510
|
+
|
|
511
|
+
## Dev
|
|
512
|
+
[dev server commands, if detected]
|
|
513
|
+
|
|
514
|
+
## Deploy
|
|
515
|
+
[deploy commands, if detected from CI]
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
#### `testing.md`
|
|
519
|
+
```markdown
|
|
520
|
+
# Testing
|
|
521
|
+
|
|
522
|
+
## Frameworks
|
|
523
|
+
[detected test frameworks per stack]
|
|
524
|
+
|
|
525
|
+
## Structure
|
|
526
|
+
[test directory layout, naming conventions]
|
|
527
|
+
|
|
528
|
+
## Helpers & infrastructure
|
|
529
|
+
[detected builders, fakes, fixtures]
|
|
530
|
+
|
|
531
|
+
## Test Infrastructure Inventory
|
|
532
|
+
[from targeted extraction #2 — complete table of fakes/stubs/mocks found]
|
|
533
|
+
| Fake/Stub class | Implements | Location |
|
|
534
|
+
|----------------|-----------|----------|
|
|
535
|
+
[one row per test double found]
|
|
536
|
+
|
|
537
|
+
## Run commands
|
|
538
|
+
[how to run tests per stack, including filtered]
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
#### `lessons.md`
|
|
542
|
+
```markdown
|
|
543
|
+
# Lessons Index
|
|
544
|
+
|
|
545
|
+
Domain-specific lessons are stored in separate files to keep context manageable.
|
|
546
|
+
|
|
547
|
+
| File | Domain |
|
|
548
|
+
|------|--------|
|
|
549
|
+
[one row per stack — e.g., lessons-dotnet.md, lessons-node.md, lessons-python.md]
|
|
550
|
+
|
|
551
|
+
## How to add lessons
|
|
552
|
+
After completing a task, if a durable lesson was learned, append it to the appropriate domain file:
|
|
553
|
+
- Format: `### [YYYY-MM-DD] <title>` followed by root cause, fix, and lesson
|
|
554
|
+
- Only add lessons that prevent future mistakes — not every fix is a lesson
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
Create empty `lessons-{stack}.md` files for each detected stack.
|
|
558
|
+
|
|
559
|
+
#### `state.md`
|
|
560
|
+
```markdown
|
|
561
|
+
# Project State
|
|
562
|
+
|
|
563
|
+
## Setup
|
|
564
|
+
- crewkit version: 0.1.0
|
|
565
|
+
- Setup date: [today's date]
|
|
566
|
+
- Stacks: [detected stacks]
|
|
567
|
+
|
|
568
|
+
## Current phase
|
|
569
|
+
[Initial setup — update as project evolves]
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
---
|
|
573
|
+
|
|
574
|
+
### Step 2 — `CLAUDE.md` (AI-generated from scan)
|
|
575
|
+
|
|
576
|
+
Generate the project's root `CLAUDE.md`. This is the most important generated file — it defines the AI's behavior for this project.
|
|
577
|
+
|
|
578
|
+
**Structure:**
|
|
579
|
+
```markdown
|
|
580
|
+
# [PROJECT NAME] — CLAUDE.md
|
|
581
|
+
|
|
582
|
+
Global rules for this repository. Subdirectories with CLAUDE.md define local rules (take precedence when more specific).
|
|
583
|
+
|
|
584
|
+
---
|
|
585
|
+
|
|
586
|
+
## Overview
|
|
587
|
+
[1-2 sentences: what the project is, main stack]
|
|
588
|
+
[Business domain from Phase 2: what it does, core entities, risk profile]
|
|
589
|
+
|
|
590
|
+
**Stack:** [stacks detected]
|
|
591
|
+
**Architecture:** [key patterns — e.g., "DDD + CQRS" or "MVC" or "microservices"]
|
|
592
|
+
|
|
593
|
+
---
|
|
594
|
+
|
|
595
|
+
## Hard rules (apply to ALL agents and ALL tasks)
|
|
596
|
+
|
|
597
|
+
[Only include rules with HIGH confidence from Phase 4. Number them.]
|
|
598
|
+
|
|
599
|
+
1. [Rule 1 — e.g., "Multi-tenant: TenantId always from JWT, never from request body"]
|
|
600
|
+
2. [Rule 2 — e.g., "Entities use private setters and Create() factory methods"]
|
|
601
|
+
3. [Rule 3]
|
|
602
|
+
...
|
|
603
|
+
|
|
604
|
+
Details for each rule -> `.ai/memory/conventions.md`
|
|
605
|
+
|
|
606
|
+
---
|
|
607
|
+
|
|
608
|
+
## Agent Discipline
|
|
609
|
+
|
|
610
|
+
- You are an **orchestrator**, not a worker. Use subagents for work.
|
|
611
|
+
- Never dump large raw logs or code — return structured summaries.
|
|
612
|
+
|
|
613
|
+
| Task | Subagent |
|
|
614
|
+
|------|----------|
|
|
615
|
+
| Find files, map dependencies | explorer |
|
|
616
|
+
| Implement feature or fix | coder |
|
|
617
|
+
| Write or validate tests | tester |
|
|
618
|
+
| Architecture decisions | architect |
|
|
619
|
+
| Code review | reviewer |
|
|
620
|
+
|
|
621
|
+
## Skills (slash commands)
|
|
622
|
+
|
|
623
|
+
`/full-workflow` (implement feature) | `/explore-and-plan` (map + plan) | `/hotfix` (production broken) | `/review-pr` (PR review)
|
|
624
|
+
|
|
625
|
+
## Architect Decision Gate — MANDATORY
|
|
626
|
+
|
|
627
|
+
1. Architect **raises options** with pros/cons — does NOT decide
|
|
628
|
+
2. Orchestrator **presents to user** and awaits explicit approval
|
|
629
|
+
3. With confirmed decisions -> creates the plan
|
|
630
|
+
4. Only then the coder is invoked
|
|
631
|
+
|
|
632
|
+
**Violation = rework.** Always include: recommended option, pros/cons, clear positioning.
|
|
633
|
+
|
|
634
|
+
## Test Safety Loop
|
|
635
|
+
|
|
636
|
+
1. Implement -> 2. Create/update tests -> 3. Run -> 4. Fix if FAIL -> 5. Review -> 6. Report success
|
|
637
|
+
|
|
638
|
+
> **ABSOLUTE BLOCK:** Never report success with failing tests. After 2 correction cycles, STOP and escalate.
|
|
639
|
+
|
|
640
|
+
---
|
|
641
|
+
|
|
642
|
+
## Project Memory (`.ai/memory/`)
|
|
643
|
+
|
|
644
|
+
Versioned context in git. Load **on demand by stack/task**, not everything:
|
|
645
|
+
|
|
646
|
+
| File | When to load |
|
|
647
|
+
|------|-------------|
|
|
648
|
+
| `architecture.md` | ALWAYS |
|
|
649
|
+
| `conventions.md` | ALWAYS |
|
|
650
|
+
| `commands.md` | When running build/test/deploy |
|
|
651
|
+
| `testing.md` | When creating or running tests |
|
|
652
|
+
| `lessons.md` | Index -> points to domain files |
|
|
653
|
+
| `lessons-{domain}.md` | When working on that specific domain |
|
|
654
|
+
| `state.md` | When needing context about phases/backlog |
|
|
655
|
+
|
|
656
|
+
**Memory update rule:** At end of task, if durable lesson -> append to `lessons-{domain}.md`. If state changed -> update `state.md`.
|
|
657
|
+
|
|
658
|
+
---
|
|
659
|
+
|
|
660
|
+
## Output Format
|
|
661
|
+
|
|
662
|
+
Always return:
|
|
663
|
+
- **Summary** — what was done
|
|
664
|
+
- **Files changed** — list with brief description
|
|
665
|
+
- **Tests** — pass/fail count
|
|
666
|
+
- **Risks / Next steps** — if any
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
**Customization from scan:**
|
|
670
|
+
- Hard rules come from HIGH confidence patterns in Phase 4
|
|
671
|
+
- Overview comes from Phase 2 (docs) + Phase 1 (stacks)
|
|
672
|
+
- Commands table uses detected build/test commands
|
|
673
|
+
|
|
674
|
+
---
|
|
675
|
+
|
|
676
|
+
### Step 3 — `.claude/agents/` (templates + context header injection)
|
|
677
|
+
|
|
678
|
+
Read all 5 agent templates from `~/.claude/skills/crewkit-setup/templates/agents/`:
|
|
679
|
+
- `explorer.md`
|
|
680
|
+
- `architect.md`
|
|
681
|
+
- `coder.md`
|
|
682
|
+
- `tester.md`
|
|
683
|
+
- `reviewer.md`
|
|
684
|
+
|
|
685
|
+
For each agent template, **inject a project context header** between the frontmatter and the body. This header ensures critical project facts are always available inline, even if the AI skips reading `.ai/memory/` files.
|
|
686
|
+
|
|
687
|
+
**Context header format:**
|
|
688
|
+
```markdown
|
|
689
|
+
---
|
|
690
|
+
name: [agent name]
|
|
691
|
+
model: [model]
|
|
692
|
+
description: "..."
|
|
693
|
+
---
|
|
694
|
+
|
|
695
|
+
<!-- crewkit:context-start -->
|
|
696
|
+
## Project: [project name]
|
|
697
|
+
- **Stack:** [detected stacks with versions]
|
|
698
|
+
- **Architecture:** [key patterns — e.g., "DDD + CQRS, multi-tenant via TenantId from JWT"]
|
|
699
|
+
- **Modules:** [top 5 modules with 1-word role each]
|
|
700
|
+
- **Build:** `[build command]` | **Test:** `[test command]`
|
|
701
|
+
- **Hard rules:** [3-5 most critical rules from CLAUDE.md, 1 line each]
|
|
702
|
+
- **High-risk areas:** [files >500 lines or flagged as complex in Phase 4]
|
|
703
|
+
- **Anti-patterns found:** [top 3 from scan]
|
|
704
|
+
<!-- crewkit:context-end -->
|
|
705
|
+
|
|
706
|
+
[rest of agent template unchanged]
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
**Rules for the context header:**
|
|
710
|
+
- Keep it under 15 lines — it's a quick-reference summary, not a replacement for `.ai/memory/`
|
|
711
|
+
- Only include facts from the scan with HIGH confidence
|
|
712
|
+
- The `crewkit:context-start/end` markers allow `crewkit update` to replace only this block without touching agent customizations
|
|
713
|
+
- On re-run with [R], regenerate the header. On [M] (memory-only), update headers in existing agents too.
|
|
714
|
+
|
|
715
|
+
Write calibrated agents to `.claude/agents/`.
|
|
716
|
+
|
|
717
|
+
---
|
|
718
|
+
|
|
719
|
+
### Step 4 — `.claude/rules/` (AI-generated per stack)
|
|
720
|
+
|
|
721
|
+
Generate one rule file per detected stack. Rules are enforced when the AI edits files in the relevant directories.
|
|
722
|
+
|
|
723
|
+
Each rule file:
|
|
724
|
+
```markdown
|
|
725
|
+
---
|
|
726
|
+
description: "[Stack] coding rules — applied when editing [glob pattern]"
|
|
727
|
+
globs: "[glob pattern for this stack's files]"
|
|
728
|
+
---
|
|
729
|
+
|
|
730
|
+
# [Stack] Rules
|
|
731
|
+
|
|
732
|
+
[Rules derived from HIGH and MEDIUM confidence patterns detected in Phase 4]
|
|
733
|
+
[Anti-patterns to avoid, detected from the codebase]
|
|
734
|
+
[Stack-specific conventions]
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
**MANDATORY: Convert targeted extractions into rules.** If Phase 4 found any of these, they MUST appear as rules:
|
|
738
|
+
- **Raw SQL with string interpolation** (extraction #6) → CRITICAL reviewer rule: "Flag `$"...'{variable}'..."` patterns — always use parameterized queries"
|
|
739
|
+
- **State machine transitions** (extraction #4) → rule: "State changes must follow documented transitions in `.ai/memory/architecture.md`"
|
|
740
|
+
- **Large files >500 lines** (extraction #5) → rule: "Changes to [file] require extra review — high coupling, document timer/closure lifecycle"
|
|
741
|
+
- **Missing input validation** (from anti-patterns) → rule: "Validate all external input at controller/handler boundary"
|
|
742
|
+
|
|
743
|
+
**Glob examples:**
|
|
744
|
+
- .NET: `src/**/*.cs` or `[ProjectName]/**/*.cs`
|
|
745
|
+
- Node.js: `src/**/*.{js,ts,jsx,tsx}`
|
|
746
|
+
- Python: `**/*.py`
|
|
747
|
+
- Go: `**/*.go`
|
|
748
|
+
|
|
749
|
+
**Generate a rule file for EVERY detected stack, including frontend.** If Blazor, React, Vue, Angular, or Svelte was detected, generate a frontend rule file with Design System enforcement from targeted extraction #3.
|
|
750
|
+
|
|
751
|
+
---
|
|
752
|
+
|
|
753
|
+
### Step 5 — `.claude/settings.json` + `.claude/napkin.md`
|
|
754
|
+
|
|
755
|
+
#### settings.json
|
|
756
|
+
Generate dynamically from scan results. The allow list has 3 layers:
|
|
757
|
+
|
|
758
|
+
**Layer 1 — Universal (always included):**
|
|
759
|
+
```json
|
|
760
|
+
"Read(*)",
|
|
761
|
+
"Edit(*)",
|
|
762
|
+
"Write(.ai/memory/*)",
|
|
763
|
+
"Write(.ai/plans/*)",
|
|
764
|
+
"Write(.claude/napkin.md)",
|
|
765
|
+
"Bash(git *)",
|
|
766
|
+
"Bash(cat *)",
|
|
767
|
+
"Bash(wc *)",
|
|
768
|
+
"Bash(mkdir *)",
|
|
769
|
+
"Bash(bash .claude/hooks/*)"
|
|
770
|
+
```
|
|
771
|
+
|
|
772
|
+
**Layer 2 — Stack-specific runtime (add per detected stack):**
|
|
773
|
+
|
|
774
|
+
| Stack | Permissions to add |
|
|
775
|
+
|-------|-------------------|
|
|
776
|
+
| .NET | `"Bash(dotnet *)"` |
|
|
777
|
+
| Node.js | `"Bash(node *)"`, `"Bash(npx *)"`, `"Bash(npm *)"` |
|
|
778
|
+
| Python | `"Bash(python *)"`, `"Bash(pip *)"`, `"Bash(pytest *)"` |
|
|
779
|
+
| Go | `"Bash(go *)"` |
|
|
780
|
+
| Rust | `"Bash(cargo *)"` |
|
|
781
|
+
| Java (Maven) | `"Bash(mvn *)"` |
|
|
782
|
+
| Java (Gradle) | `"Bash(./gradlew *)"` |
|
|
783
|
+
| Ruby | `"Bash(bundle *)"`, `"Bash(rake *)"` |
|
|
784
|
+
|
|
785
|
+
**Layer 3 — Infrastructure (add if detected):**
|
|
786
|
+
|
|
787
|
+
| Detected | Permission to add |
|
|
788
|
+
|----------|------------------|
|
|
789
|
+
| Docker | `"Bash(docker *)"`, `"Bash(docker compose *)"` |
|
|
790
|
+
| Makefile | `"Bash(make *)"` |
|
|
791
|
+
|
|
792
|
+
**Deny list (always):**
|
|
793
|
+
```json
|
|
794
|
+
"Bash(rm -rf *)",
|
|
795
|
+
"Bash(sudo *)"
|
|
796
|
+
```
|
|
797
|
+
|
|
798
|
+
**Hooks (always):**
|
|
799
|
+
```json
|
|
800
|
+
{
|
|
801
|
+
"hooks": {
|
|
802
|
+
"SessionStart": [
|
|
803
|
+
{ "hooks": [{ "type": "command", "command": "bash .claude/hooks/session-start.sh" }] }
|
|
804
|
+
],
|
|
805
|
+
"PreToolUse": [
|
|
806
|
+
{ "matcher": "Edit|Write", "hooks": [{ "type": "command", "command": "bash .claude/hooks/protect-sensitive-files.sh" }] }
|
|
807
|
+
],
|
|
808
|
+
"PostCompact": [
|
|
809
|
+
{ "hooks": [{ "type": "command", "command": "bash .claude/hooks/post-compact-recovery.sh" }] }
|
|
810
|
+
],
|
|
811
|
+
"Stop": [
|
|
812
|
+
{ "hooks": [{ "type": "command", "command": "bash .claude/hooks/stop-quality-gate.sh" }] }
|
|
813
|
+
]
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
```
|
|
817
|
+
|
|
818
|
+
Combine all three layers into a single `settings.json`. The result should look like a complete, valid JSON file with permissions + hooks.
|
|
819
|
+
|
|
820
|
+
**Note:** After Step 9 generates `.mcp.json`, come back and update `settings.json` with Layer 4 (MCP permissions) — see Step 9.
|
|
821
|
+
|
|
822
|
+
#### napkin.md
|
|
823
|
+
```markdown
|
|
824
|
+
# Napkin
|
|
825
|
+
|
|
826
|
+
## Now
|
|
827
|
+
- [Initial setup complete — start working]
|
|
828
|
+
|
|
829
|
+
## Blockers (production)
|
|
830
|
+
- [none detected — add as needed]
|
|
831
|
+
|
|
832
|
+
## Tech debt
|
|
833
|
+
- [anti-patterns found during scan, if any]
|
|
834
|
+
|
|
835
|
+
## Backlog
|
|
836
|
+
- [empty — add as needed]
|
|
837
|
+
```
|
|
838
|
+
|
|
839
|
+
---
|
|
840
|
+
|
|
841
|
+
### Step 6 — `.claude/hooks/` (templates + variable substitution)
|
|
842
|
+
|
|
843
|
+
Read all 4 hook templates from `~/.claude/skills/crewkit-setup/templates/hooks/`:
|
|
844
|
+
- `session-start.sh`
|
|
845
|
+
- `protect-sensitive-files.sh`
|
|
846
|
+
- `post-compact-recovery.sh`
|
|
847
|
+
- `stop-quality-gate.sh`
|
|
848
|
+
|
|
849
|
+
For each hook template, substitute the placeholders:
|
|
850
|
+
|
|
851
|
+
1. **`{{project_dir}}`** (session-start.sh, stop-quality-gate.sh) — replace with the project's absolute directory path
|
|
852
|
+
2. **`{{hard_rules}}`** (post-compact-recovery.sh) — replace with a numbered list of the hard rules from CLAUDE.md Step 2. These are the 5-15 non-negotiable project rules that MUST survive context compaction. Keep each rule to 1 line. Example:
|
|
853
|
+
```
|
|
854
|
+
1. MULTI-TENANT: TenantId always from JWT, never from body
|
|
855
|
+
2. ENTITIES: private setters, factory methods Create(...)
|
|
856
|
+
3. TESTS: every feature/fix must have tests. Never report success with failing tests
|
|
857
|
+
```
|
|
858
|
+
3. **`{{build_gate}}`** (stop-quality-gate.sh) — replace with a bash block that:
|
|
859
|
+
- Checks `git diff --name-only HEAD` for modified source files matching the detected stack extensions
|
|
860
|
+
- If modified files exist, runs the detected build command
|
|
861
|
+
- On build failure: echoes errors and `exit 1` (this prevents Claude from stopping with broken code)
|
|
862
|
+
- On success or no modified files: falls through to the lessons check
|
|
863
|
+
|
|
864
|
+
Example for a Node.js project:
|
|
865
|
+
```bash
|
|
866
|
+
SRC_CHANGED=$(git diff --name-only HEAD 2>/dev/null | grep -E '\.(js|ts|jsx|tsx)$' | wc -l | tr -d '[:space:]')
|
|
867
|
+
SRC_STAGED=$(git diff --cached --name-only 2>/dev/null | grep -E '\.(js|ts|jsx|tsx)$' | wc -l | tr -d '[:space:]')
|
|
868
|
+
if [ "${SRC_CHANGED:-0}" -gt 0 ] || [ "${SRC_STAGED:-0}" -gt 0 ]; then
|
|
869
|
+
BUILD_OUTPUT=$(npm run build 2>&1)
|
|
870
|
+
if [ $? -ne 0 ]; then
|
|
871
|
+
echo "QUALITY GATE FAILED — build broken:"
|
|
872
|
+
echo "$BUILD_OUTPUT" | tail -20
|
|
873
|
+
echo ""
|
|
874
|
+
echo "Fix build errors before completing the task."
|
|
875
|
+
exit 1
|
|
876
|
+
fi
|
|
877
|
+
fi
|
|
878
|
+
```
|
|
879
|
+
|
|
880
|
+
For multi-stack projects, generate one check block per stack.
|
|
881
|
+
|
|
882
|
+
Write calibrated hooks to `.claude/hooks/`.
|
|
883
|
+
|
|
884
|
+
---
|
|
885
|
+
|
|
886
|
+
### Step 7 — `.claude/skills/` (templates, copied directly)
|
|
887
|
+
|
|
888
|
+
Read all 4 core skill templates from `~/.claude/skills/crewkit-setup/templates/skills/`:
|
|
889
|
+
- `full-workflow/SKILL.md`
|
|
890
|
+
- `hotfix/SKILL.md`
|
|
891
|
+
- `explore-and-plan/SKILL.md`
|
|
892
|
+
- `review-pr/SKILL.md`
|
|
893
|
+
|
|
894
|
+
Copy each skill template to `.claude/skills/[name]/SKILL.md`.
|
|
895
|
+
|
|
896
|
+
These skill templates are **stack-agnostic** by design — they reference `.ai/memory/commands.md` for build/test commands and `.ai/memory/` for project context. No variable substitution needed.
|
|
897
|
+
|
|
898
|
+
---
|
|
899
|
+
|
|
900
|
+
### Step 8 — `.claude/QUICKSTART.md` (onboarding guide)
|
|
901
|
+
|
|
902
|
+
Generate a quick start guide for developers joining the project:
|
|
903
|
+
|
|
904
|
+
```markdown
|
|
905
|
+
# Quick Start — Context Engineering Setup
|
|
906
|
+
|
|
907
|
+
This project uses crewkit for AI-assisted development. Here's how to use it.
|
|
908
|
+
|
|
909
|
+
## Day-to-day workflow
|
|
910
|
+
- `/full-workflow <task>` — complete flow: explore → code → test → review (features and non-trivial fixes)
|
|
911
|
+
- `/hotfix <problem>` — compressed flow for urgent production fixes (max 2 iterations)
|
|
912
|
+
- `/explore-and-plan <feature>` — map a module and plan before coding (recommended for LARGE tasks)
|
|
913
|
+
- `/review-pr [number]` — review a pull request
|
|
914
|
+
|
|
915
|
+
## How agents work together
|
|
916
|
+
The orchestrator routes work to specialized agents:
|
|
917
|
+
- **explorer** (Sonnet) — finds files, maps dependencies — read-only
|
|
918
|
+
- **architect** (Opus) — evaluates design options, recommends — read-only
|
|
919
|
+
- **coder** (Sonnet) — implements the smallest correct diff
|
|
920
|
+
- **tester** (Sonnet) — creates tests, runs full suite
|
|
921
|
+
- **reviewer** (Opus) — finds real bugs, high signal, no noise
|
|
922
|
+
|
|
923
|
+
## Project context lives in `.ai/memory/`
|
|
924
|
+
- `architecture.md` — modules, layers, dependencies
|
|
925
|
+
- `conventions.md` — naming, patterns, anti-patterns
|
|
926
|
+
- `commands.md` — build, test, deploy commands
|
|
927
|
+
- `testing.md` — test frameworks, helpers, fakes
|
|
928
|
+
- `lessons-{domain}.md` — lessons learned from production
|
|
929
|
+
|
|
930
|
+
## Enriching the setup over time
|
|
931
|
+
- After a production bug → add to `lessons-{domain}.md`
|
|
932
|
+
- After a recurring reviewer finding → add to `conventions.md`
|
|
933
|
+
- New operational command → add to `commands.md`
|
|
934
|
+
- Known security issue → add to reviewer agent's context header (`crewkit:context-start` block)
|
|
935
|
+
```
|
|
936
|
+
|
|
937
|
+
---
|
|
938
|
+
|
|
939
|
+
### Step 9 — `.mcp.json` (MCP servers)
|
|
940
|
+
|
|
941
|
+
Generate `.mcp.json` based on detected infrastructure:
|
|
942
|
+
|
|
943
|
+
**Always include:**
|
|
944
|
+
```json
|
|
945
|
+
{
|
|
946
|
+
"mcpServers": {
|
|
947
|
+
"context7": {
|
|
948
|
+
"command": "npx",
|
|
949
|
+
"args": ["-y", "@upstash/context7-mcp"]
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
```
|
|
954
|
+
|
|
955
|
+
**Add based on detection:**
|
|
956
|
+
|
|
957
|
+
| Detected | MCP to add |
|
|
958
|
+
|----------|-----------|
|
|
959
|
+
| PostgreSQL | `@modelcontextprotocol/server-postgres` with `{{connection_string}}` placeholder |
|
|
960
|
+
| MySQL | `@modelcontextprotocol/server-mysql` with `{{connection_string}}` placeholder |
|
|
961
|
+
| MongoDB | `mongodb-mcp-server` with `{{connection_string}}` placeholder |
|
|
962
|
+
| Redis | `redis-mcp-server` with `{{connection_string}}` placeholder |
|
|
963
|
+
| Supabase | `@supabase/mcp-server` with `{{project_ref}}` and `{{access_token}}` placeholders |
|
|
964
|
+
| Sentry | `@sentry/mcp-server` with `{{dsn}}` placeholder |
|
|
965
|
+
| Grafana | `@grafana/mcp-server` with `{{url}}` and `{{token}}` placeholders |
|
|
966
|
+
| Vercel | `@vercel/mcp-server` with `{{token}}` placeholder |
|
|
967
|
+
| Linear | `@linear/mcp-server` with `{{api_key}}` placeholder |
|
|
968
|
+
| Atlassian | `@anthropic/mcp-server-atlassian` with `{{url}}` and `{{token}}` placeholders |
|
|
969
|
+
| Slack | `@anthropic/mcp-server-slack` with `{{bot_token}}` placeholder |
|
|
970
|
+
|
|
971
|
+
For any placeholder tokens, add a comment in the profile or tell the user to fill them in.
|
|
972
|
+
|
|
973
|
+
**After generating .mcp.json, update `settings.json`:**
|
|
974
|
+
1. Add `"enableMcpServerCreation": false` to the top-level settings
|
|
975
|
+
2. Add MCP tool permissions (Layer 4) to the allow list — for each server in `.mcp.json`, add `"mcp__[server-name]__query"`. Example: if `.mcp.json` has `postgres-dev`, add `"mcp__postgres-dev__query"`
|
|
976
|
+
|
|
977
|
+
---
|
|
978
|
+
|
|
979
|
+
## Final Report
|
|
980
|
+
|
|
981
|
+
After all generation steps, run the **Completion Checklist** (at the bottom of this document). Then present the summary:
|
|
982
|
+
|
|
983
|
+
```markdown
|
|
984
|
+
# crewkit setup complete
|
|
985
|
+
|
|
986
|
+
## Generated files
|
|
987
|
+
- `.ai/memory/` — [N] files (architecture, conventions, commands, testing, lessons, state)
|
|
988
|
+
- `CLAUDE.md` — project rules ([N] hard rules)
|
|
989
|
+
- `.claude/agents/` — 5 agents (explorer, architect, coder, tester, reviewer)
|
|
990
|
+
- `.claude/rules/` — [N] rule files ([list stacks])
|
|
991
|
+
- `.claude/settings.json` — permissions + hooks
|
|
992
|
+
- `.claude/hooks/` — 4 hooks (session-start, protect-sensitive, post-compact, stop-quality-gate)
|
|
993
|
+
- `.claude/skills/` — 4 skills (full-workflow, hotfix, explore-and-plan, review-pr)
|
|
994
|
+
- `.claude/napkin.md` — priorities board
|
|
995
|
+
- `.claude/QUICKSTART.md` — onboarding guide
|
|
996
|
+
- `.mcp.json` — [N] MCP servers
|
|
997
|
+
- Validation: [N]/15 checks passed
|
|
998
|
+
|
|
999
|
+
## Commands detected
|
|
1000
|
+
- Build: `[command]`
|
|
1001
|
+
- Test: `[command]`
|
|
1002
|
+
|
|
1003
|
+
## Recommended MCPs to configure
|
|
1004
|
+
[List MCPs with placeholder tokens that need user input]
|
|
1005
|
+
|
|
1006
|
+
## Next steps
|
|
1007
|
+
1. Review `CLAUDE.md` and adjust rules as needed
|
|
1008
|
+
2. Fill in MCP tokens in `.mcp.json` (if applicable)
|
|
1009
|
+
3. Commit the setup: `git add .claude/ .ai/ CLAUDE.md .mcp.json && git commit -m "chore: add crewkit context engineering setup"`
|
|
1010
|
+
4. Run `/full-workflow <your-first-task>` to test the setup
|
|
1011
|
+
```
|
|
1012
|
+
|
|
1013
|
+
---
|
|
1014
|
+
|
|
1015
|
+
## Error handling
|
|
1016
|
+
|
|
1017
|
+
- If a template file is missing from `~/.claude/skills/crewkit-setup/templates/`, warn the user and skip that file. Do not fail the entire setup.
|
|
1018
|
+
- If git is not available, skip git-dependent analysis (Phase 1 hotspots, contributors). Proceed with reduced data.
|
|
1019
|
+
- If the project has no code (empty repo, only docs), generate a minimal setup with TODOs.
|
|
1020
|
+
- If a build/test command cannot be detected, leave it as `echo "TODO: configure build command"` in settings.json and commands.md.
|
|
1021
|
+
- If the project is very large (50+ modules), limit Phase 4 deep read to the 5 most active modules and note the limitation.
|
|
1022
|
+
|
|
1023
|
+
---
|
|
1024
|
+
|
|
1025
|
+
## COMPLETION CHECKLIST (mandatory — verify before reporting done)
|
|
1026
|
+
|
|
1027
|
+
Before presenting the Final Report, go through EVERY item. Fix failures before reporting.
|
|
1028
|
+
|
|
1029
|
+
### Content checks
|
|
1030
|
+
- [ ] `.ai/memory/architecture.md` — has constructor/DI signatures table (if project uses DI)
|
|
1031
|
+
- [ ] `.ai/memory/conventions.md` — has Design System section (if frontend detected)
|
|
1032
|
+
- [ ] `.ai/memory/testing.md` — has Fakes/Stubs inventory table (if test doubles detected)
|
|
1033
|
+
- [ ] `.ai/memory/commands.md` — has build + test + dev commands for ALL detected stacks
|
|
1034
|
+
- [ ] `CLAUDE.md` — hard rules present, all in English
|
|
1035
|
+
- [ ] `.claude/agents/` — all 5 have `crewkit:context-start` header with real project data
|
|
1036
|
+
- [ ] `.claude/QUICKSTART.md` — exists with workflow guide
|
|
1037
|
+
|
|
1038
|
+
### Validation checks (run these, don't just assume)
|
|
1039
|
+
- [ ] `.claude/settings.json` — read back, verify valid JSON, has Write(.ai/memory/*), has stack permissions, has MCP permissions (Layer 4)
|
|
1040
|
+
- [ ] `.mcp.json` — read back, verify valid JSON, has context7
|
|
1041
|
+
- [ ] `.claude/hooks/*.sh` — run `bash -n` on each, all 4 pass syntax check
|
|
1042
|
+
- [ ] `.claude/rules/` — at least 1 per detected stack, glob patterns match real files in project
|
|
1043
|
+
- [ ] `.claude/skills/` — all 4 core skills have SKILL.md
|
|
1044
|
+
|
|
1045
|
+
### Integrity checks
|
|
1046
|
+
- [ ] `.crewkit/last-scan.md` — exists with full profile including Domain section
|
|
1047
|
+
- [ ] `.crewkit/scan-phase*.md` — all 4 phase files exist with content
|
|
1048
|
+
- [ ] No Portuguese in any generated file (only in user-facing output)
|
|
1049
|
+
|
|
1050
|
+
Report checklist results as: "Validation: X/15 checks passed." If any failed, list which ones and why.
|