@codihaus/claude-skills 1.6.5 → 1.6.7

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.
@@ -0,0 +1,146 @@
1
+ # UC Spec Template
2
+
3
+ ## Principle
4
+
5
+ **Include:** Requirements (testable), technical constraints, acceptance criteria, file checklist
6
+ **Exclude:** Pseudocode, detailed HOW, code examples (reference patterns instead)
7
+ **Length:** ~150 lines max per UC
8
+
9
+ ---
10
+
11
+ ## Structure
12
+
13
+ ```markdown
14
+ # UC-{GROUP}-{NNN}: {Title}
15
+
16
+ > **Feature**: [[feature-{feature}]]
17
+ > **BRD**: [[uc-{group}-{nnn}]]
18
+ > **Status**: Draft
19
+ > **Spec Type**: Lean (Requirements-focused)
20
+
21
+ ## Context
22
+
23
+ {2-3 sentences on what this UC implements and why}
24
+
25
+ **Links:**
26
+ - Use Case: [UC-{GROUP}-{NNN}](../../brd/use-cases/{feature}/UC-{GROUP}-{NNN}-{slug}.md)
27
+ - Codebase Context: [codebase-context.md](../codebase-context.md)
28
+
29
+ ## Requirements
30
+
31
+ **Must Have:**
32
+ - [ ] {testable requirement}
33
+ - [ ] {testable requirement}
34
+
35
+ **Should Have:**
36
+ - [ ] {nice-to-have}
37
+
38
+ **Must Not:**
39
+ - [ ] {what should NOT happen}
40
+
41
+ ## Technical Constraints
42
+
43
+ **Stack & Patterns** (from tech-context.md):
44
+ - API Layer: {use X pattern}
45
+ - Data Access: {use Y method}
46
+ - Client Pattern: {use Z}
47
+ - Validation: {where schemas go}
48
+ - Forms: {which library}
49
+
50
+ **Code Location:**
51
+ - Primary location: `{path}`
52
+ - Related files: `{paths}`
53
+ - Follow pattern: `{reference file}`
54
+
55
+ **External Dependencies:**
56
+ {if applicable}
57
+
58
+ **Constraints:**
59
+ {performance/security/business rules}
60
+
61
+ ## Acceptance Criteria
62
+
63
+ **Happy Path:**
64
+ - [ ] Given {condition}, When {action}, Then {outcome}
65
+
66
+ **Error Cases:**
67
+ - [ ] Given {invalid}, When {action}, Then {error shown}
68
+
69
+ **Edge Cases:**
70
+ - [ ] Given {edge}, When {action}, Then {behavior}
71
+
72
+ ## Files to Modify
73
+
74
+ **New Files:**
75
+ - [ ] `{path}` - {purpose}
76
+
77
+ **Modified Files:**
78
+ - [ ] `{path}` - {what changes}
79
+
80
+ **Reference Pattern:**
81
+ - See `{existing file}` for similar implementation
82
+
83
+ ## API Contract (if applicable)
84
+
85
+ **Endpoint:** `{METHOD} {path}`
86
+
87
+ **Request:**
88
+ ```json
89
+ {
90
+ "field": "type"
91
+ }
92
+ ```
93
+
94
+ **Response (Success):**
95
+ ```json
96
+ {
97
+ "field": "type"
98
+ }
99
+ ```
100
+
101
+ **Response (Error):**
102
+ | Status | Reason | Body |
103
+ |--------|--------|------|
104
+ | 400 | | |
105
+ | 401 | | |
106
+
107
+ ## Test Checklist
108
+
109
+ **Unit Tests:**
110
+ - [ ] {what to test} in `{file}.test.ts`
111
+
112
+ **Integration Tests:**
113
+ - [ ] {scenario} - {expected outcome}
114
+
115
+ **E2E Tests** (if applicable):
116
+ - [ ] {user flow} - {expected result}
117
+
118
+ ## Dependencies
119
+
120
+ **Must Exist Before Implementation:**
121
+ - [ ] {dependency}
122
+
123
+ **Blocks:**
124
+ - [ ] [[uc-{group}-{nnn}]] - {why}
125
+
126
+ ## Implementation Notes
127
+
128
+ **DO:**
129
+ - {guidance}
130
+
131
+ **DON'T:**
132
+ - {anti-pattern}
133
+
134
+ **Watch Out For:**
135
+ - {gotcha}
136
+ ```
137
+
138
+ ---
139
+
140
+ ## Key Rules
141
+
142
+ 1. **No pseudocode** - requirements and constraints only
143
+ 2. **Reference patterns** - don't rewrite them
144
+ 3. **Testable criteria** - every requirement maps to a test
145
+ 4. **Stack-aware** - uses tech-context.md for correct approach
146
+ 5. **Scannable** - read in 2-3 minutes
@@ -49,7 +49,7 @@ const DEFAULT_SETTINGS = {
49
49
  hooks: [
50
50
  {
51
51
  type: "command",
52
- command: "jq -r '.tool_input.file_path // empty' | { read file_path; if [ -n \"$file_path\" ] && echo \"$file_path\" | grep -q 'plans/.*\\.md$'; then bash .claude/scripts/safe-graph-update.sh \"$file_path\" 2>/dev/null || true; fi; }"
52
+ command: "jq -r '.tool_input.file_path // empty' | { read file_path; if [ -n \"$file_path\" ] && echo \"$file_path\" | grep -q 'plans/.*\\.md$'; then python3 .claude/scripts/graph.py --check-path \"$file_path\" 2>/dev/null || true; fi; }"
53
53
  }
54
54
  ]
55
55
  }
@@ -57,13 +57,14 @@ const DEFAULT_SETTINGS = {
57
57
  }
58
58
  };
59
59
 
60
- // Hooks are now configured in settings.json (see DEFAULT_SETTINGS)
60
+ // Hooks are configured in BOTH settings.json AND settings.local.json
61
+ // settings.json = team-shared (checked in), settings.local.json = personal (gitignored)
62
+ // Claude Code merges them, with settings.local.json taking precedence
61
63
 
62
64
  /**
63
65
  * Set up Claude Code settings
64
- * Creates TWO files:
65
- * - settings.json (with hooks, checked into git)
66
- * - settings.local.json (with permissions, gitignored)
66
+ * Creates BOTH settings.json (with hooks for team) AND settings.local.json (with hooks+permissions)
67
+ * This ensures hooks work regardless of which file Claude Code prioritizes
67
68
  */
68
69
  export async function setupSettings(projectPath, options = {}) {
69
70
  const claudePath = path.join(projectPath, '.claude');
@@ -72,23 +73,20 @@ export async function setupSettings(projectPath, options = {}) {
72
73
 
73
74
  await fs.ensureDir(claudePath);
74
75
 
75
- // Create settings.json with hooks (for team, checked in)
76
- const settingsJsonContent = {
76
+ // Create settings.json with hooks (for team, checked into git)
77
+ const settingsJson = {
77
78
  hooks: DEFAULT_SETTINGS.hooks
78
79
  };
80
+ await fs.writeJson(settingsPath, settingsJson, { spaces: 2 });
79
81
 
80
- await fs.writeJson(settingsPath, settingsJsonContent, { spaces: 2 });
81
-
82
- // Create/update settings.local.json with permissions (personal, gitignored)
83
- let localSettings = {
84
- permissions: DEFAULT_SETTINGS.permissions
85
- };
82
+ // Create/merge settings.local.json with hooks + permissions (personal, gitignored)
83
+ let settingsLocal = DEFAULT_SETTINGS;
86
84
 
87
85
  // Merge with existing if present
88
86
  if (await fs.pathExists(settingsLocalPath)) {
89
87
  try {
90
88
  const existing = await fs.readJson(settingsLocalPath);
91
- localSettings = {
89
+ settingsLocal = {
92
90
  permissions: {
93
91
  allow: [...new Set([
94
92
  ...(existing.permissions?.allow || []),
@@ -98,24 +96,25 @@ export async function setupSettings(projectPath, options = {}) {
98
96
  ...(existing.permissions?.deny || []),
99
97
  ...(DEFAULT_SETTINGS.permissions?.deny || [])
100
98
  ])]
101
- }
99
+ },
100
+ hooks: DEFAULT_SETTINGS.hooks
102
101
  };
103
102
  } catch (e) {
104
103
  // Invalid JSON, use defaults
105
104
  }
106
105
  }
107
106
 
108
- await fs.writeJson(settingsLocalPath, localSettings, { spaces: 2 });
107
+ await fs.writeJson(settingsLocalPath, settingsLocal, { spaces: 2 });
109
108
 
110
109
  return {
111
110
  settingsPath,
112
111
  settingsLocalPath,
113
- settings: { ...settingsJsonContent, ...localSettings }
112
+ settings: settingsLocal
114
113
  };
115
114
  }
116
115
 
117
116
  /**
118
- * Set up hook scripts (hooks config is in settings.json)
117
+ * Set up hook scripts (hooks config is in both settings.json and settings.local.json)
119
118
  */
120
119
  export async function setupHooks(projectPath, options = {}) {
121
120
  if (options.noHooks) return null;
@@ -124,11 +124,11 @@ After running `npx @codihaus/claude-skills init`, verify:
124
124
 
125
125
  ```bash
126
126
  # Check hook configuration
127
- cat .claude/hooks.json | jq '.postToolUse[0].matcher.path'
128
- # Should output: "plans/**/*.md"
127
+ cat .claude/settings.json | jq '.hooks.PostToolUse[0].matcher'
128
+ # Should output: "Write|Edit"
129
129
 
130
- cat .claude/hooks.json | jq '.postToolUse[0].command'
131
- # Should output: "bash .claude/scripts/safe-graph-update.sh $PATH"
130
+ cat .claude/settings.json | jq '.hooks.PostToolUse[0].hooks[0].command'
131
+ # Should contain: "bash .claude/scripts/safe-graph-update.sh"
132
132
 
133
133
  # Test the safe wrapper script
134
134
  bash .claude/scripts/safe-graph-update.sh plans/brd/README.md
@@ -17,34 +17,34 @@ Hooks allow you to run commands automatically in response to Claude Code events.
17
17
 
18
18
  ## Best Practices
19
19
 
20
- ### 1. Always Add Retry Limits
20
+ ### 1. Correct Hook Structure
21
+
22
+ Hooks go in `.claude/settings.json`:
21
23
 
22
24
  ```json
23
25
  {
24
- "postToolUse": [{
25
- "matcher": {
26
- "toolName": "Write|Edit",
27
- "path": "plans/**/*.md"
28
- },
29
- "command": "bash .claude/scripts/safe-graph-update.sh $PATH",
30
- "retries": {
31
- "maxAttempts": 3,
32
- "backoff": "exponential",
33
- "failureAction": "warn"
34
- },
35
- "timeout": 5000
36
- }]
26
+ "hooks": {
27
+ "PostToolUse": [
28
+ {
29
+ "matcher": "Write|Edit",
30
+ "hooks": [
31
+ {
32
+ "type": "command",
33
+ "command": "jq -r '.tool_input.file_path // empty' | { read file_path; if [ -n \"$file_path\" ] && echo \"$file_path\" | grep -q 'plans/.*\\.md$'; then bash .claude/scripts/safe-graph-update.sh \"$file_path\" 2>/dev/null || true; fi; }"
34
+ }
35
+ ]
36
+ }
37
+ ]
38
+ }
37
39
  }
38
40
  ```
39
41
 
40
- **Key Fields:**
41
- - `maxAttempts`: Stop after N failures (recommended: 2-3)
42
- - `backoff`: Wait strategy ("none", "linear", "exponential")
43
- - `failureAction`: What to do after max attempts
44
- - `"warn"` - Show warning, continue (recommended)
45
- - `"error"` - Stop and ask user for help
46
- - `"ignore"` - Silent failure (not recommended)
47
- - `timeout`: Kill hook after N milliseconds (recommended: 5000-10000)
42
+ **Key Points:**
43
+ - Hooks are in `settings.json` (checked into git for team)
44
+ - Command uses bash subshell with `read` to capture file path
45
+ - Includes `|| true` for graceful failure (non-blocking)
46
+ - Filters to only run on `plans/**/*.md` files
47
+ - Redirects stderr with `2>/dev/null` to avoid noise
48
48
 
49
49
  ### 2. Make Commands Fail Gracefully
50
50
 
@@ -161,7 +161,7 @@ fi
161
161
  timeout 10s python3 .claude/scripts/graph.py --check-path "$1" || true
162
162
  ```
163
163
 
164
- Then in hooks.json:
164
+ Then in settings.json:
165
165
  ```json
166
166
  {
167
167
  "command": "bash .claude/scripts/safe-graph-update.sh $PATH"
@@ -251,7 +251,7 @@ To temporarily disable a problematic hook:
251
251
  }
252
252
  ```
253
253
 
254
- Or delete `.claude/hooks.json` entirely (hooks are optional).
254
+ Or delete `.claude/settings.json` entirely (hooks are optional).
255
255
 
256
256
  ## Example: Robust Hook Configuration
257
257
 
@@ -13,7 +13,9 @@ set -e
13
13
 
14
14
  # Configuration
15
15
  TIMEOUT_SECONDS=10
16
- GRAPH_SCRIPT=".claude/scripts/graph.py"
16
+ # Get the directory where this script is located
17
+ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
18
+ GRAPH_SCRIPT="$SCRIPT_DIR/graph.py"
17
19
  MAX_RETRIES=0 # Let Claude Code handle retries
18
20
 
19
21
  # Colors for output (optional)
@@ -1,240 +0,0 @@
1
- ---
2
- name: dev-coding-backend
3
- description: Backend implementation patterns and workflows
4
- version: 2.1.0
5
- ---
6
-
7
- # /dev-coding-backend - Backend Implementation
8
-
9
- > **Loaded by**: `/dev-coding` when API/schema work needed
10
- > **After**: Frontend uses API contract documented here
11
-
12
- Backend-specific workflow for API, schema, and data layer implementation.
13
-
14
- ## Fundamentals (MUST READ FIRST)
15
-
16
- **Before implementing, understand the principles:**
17
-
18
- → Read `references/fundamentals.md`
19
-
20
- This covers:
21
- - **Core Mindset**: "Guardian of truth, trust nothing, enforce rules"
22
- - **7 Principles**: Separation of Concerns, Single Source of Truth, Don't Repeat Work, Don't Make Users Wait, Don't Trust Anyone, Plan for Failure, Stateless Design
23
- - **Pattern Recognition**: When to use Service Layer, Repository, Queue, Cache, Circuit Breaker, etc.
24
- - **Architecture Layers**: Route → Service → Domain → Repository → Infrastructure
25
-
26
- **Key Decision**: For each piece of code, ask "which principle applies?" Then choose the pattern that principle suggests.
27
-
28
- ## Knowledge Loading (CRITICAL)
29
-
30
- Before implementing, load relevant knowledge:
31
-
32
- ```
33
- 1. Read stack.md → plans/scout/stack.md
34
- → Identify: API layer, SDK, data access method
35
-
36
- 2. Load stack knowledge based on detected tech:
37
- | If using... | Read... | Section |
38
- |--------------|-----------------------------------|-------------------|
39
- | Directus | knowledge/stacks/directus/_index.md | "For /dev-coding" |
40
- | Nuxt server | knowledge/stacks/nuxt/_index.md | "Server Routes" |
41
- | Next.js API | knowledge/stacks/nextjs/_index.md | "API Routes" |
42
-
43
- 3. Load domain knowledge (if applicable):
44
- | If domain... | Read... | Section |
45
- |--------------|-----------------------------------|-------------------|
46
- | SaaS | knowledge/domains/saas/_index.md | Billing, Multi-tenant |
47
- | E-commerce | knowledge/domains/ecommerce/_index.md | Orders, Payments |
48
-
49
- 4. Use loaded knowledge for:
50
- → Correct SDK usage (not raw fetch)
51
- → Domain-specific validation rules
52
- → Stack-specific error handling
53
- ```
54
-
55
- ## Workflow
56
-
57
- ### Step 1: Extract Backend Requirements
58
-
59
- From UC spec, identify:
60
-
61
- ```
62
- [ ] Schema changes?
63
- → New collections/tables
64
- → New fields
65
- → Relations
66
-
67
- [ ] API endpoints?
68
- → Method + Path
69
- → Request/Response shape
70
- → Auth required?
71
-
72
- [ ] Business logic?
73
- → Validation rules
74
- → Side effects (emails, webhooks)
75
-
76
- [ ] External integrations?
77
- → Third-party APIs
78
- → File storage
79
- ```
80
-
81
- ### Step 2: Schema First
82
-
83
- **Order:** Schema → API → Logic
84
-
85
- ```
86
- 1. Design schema based on spec
87
- 2. Create/modify collections or tables
88
- 3. Set up relations
89
- 4. Configure permissions
90
- 5. Verify schema works
91
- ```
92
-
93
- ### Step 3: API Implementation
94
-
95
- For each endpoint:
96
-
97
- ```
98
- 1. Create route/handler
99
- 2. Parse request
100
- 3. Validate input
101
- 4. Implement logic
102
- 5. Handle errors
103
- 6. Return response
104
- ```
105
-
106
- **Follow project patterns** from scout (file locations, naming, error format).
107
-
108
- ### Step 4: Essential Patterns
109
-
110
- #### Request Validation (always do this)
111
-
112
- ```typescript
113
- const schema = z.object({
114
- email: z.string().email(),
115
- password: z.string().min(8),
116
- });
117
-
118
- const result = schema.safeParse(req.body);
119
- if (!result.success) {
120
- return res.status(400).json({
121
- error: 'Validation failed',
122
- details: result.error.issues
123
- });
124
- }
125
- ```
126
-
127
- #### Error Response Format
128
-
129
- ```typescript
130
- // Consistent format
131
- { "error": "Message", "code": "ERROR_CODE" }
132
-
133
- // Status codes
134
- 200 - Success 400 - Bad request
135
- 201 - Created 401 - Unauthorized
136
- 403 - Forbidden
137
- 404 - Not found
138
- 500 - Server error
139
- ```
140
-
141
- #### Auth Check
142
-
143
- ```typescript
144
- if (!req.user) {
145
- return res.status(401).json({ error: 'Unauthorized' });
146
- }
147
- if (!hasPermission(req.user, 'create:posts')) {
148
- return res.status(403).json({ error: 'Forbidden' });
149
- }
150
- ```
151
-
152
- ### Step 5: Verify
153
-
154
- ```bash
155
- # Test endpoint
156
- curl -X POST http://localhost:3000/api/auth/login \
157
- -H "Content-Type: application/json" \
158
- -d '{"email":"test@test.com","password":"password123"}'
159
- ```
160
-
161
- Checklist:
162
- ```
163
- [ ] Endpoint responds
164
- [ ] Correct status codes
165
- [ ] Validation rejects bad input
166
- [ ] Auth works correctly
167
- [ ] Response matches spec
168
- ```
169
-
170
- ### Step 6: Document for Frontend
171
-
172
- ```markdown
173
- ## API Ready
174
-
175
- ### POST /api/auth/login
176
- - **Auth**: None
177
- - **Request**: `{ email, password }`
178
- - **Success (200)**: `{ token, user }`
179
- - **Errors**: 400 (invalid), 401 (wrong creds)
180
- ```
181
-
182
- ## Security Checklist
183
-
184
- ```
185
- [ ] Input validated (Zod/Yup)
186
- [ ] Parameterized queries (no SQL injection)
187
- [ ] Auth on protected routes
188
- [ ] Permissions verified
189
- [ ] Passwords hashed
190
- [ ] Secrets in env vars
191
- [ ] No sensitive data in logs
192
- ```
193
-
194
- ## Quick Debugging
195
-
196
- ```bash
197
- # Server running?
198
- curl http://localhost:3000/health
199
-
200
- # Database connected?
201
- npx prisma db pull # or check logs
202
-
203
- # Token valid?
204
- curl http://localhost:3000/api/me -H "Authorization: Bearer $TOKEN"
205
- ```
206
-
207
- ## Stack-Specific Patterns
208
-
209
- **Do not implement generic patterns. Load from stacks/:**
210
-
211
- | Stack | What to load | Key patterns |
212
- |-------|--------------|--------------|
213
- | Directus | `stacks/directus/` | SDK queries, permissions, hooks |
214
- | Prisma | `stacks/prisma/` (future) | ORM patterns, migrations |
215
- | Supabase | `stacks/supabase/` (future) | RLS, auth, realtime |
216
-
217
- **Example - if using Directus:**
218
- ```
219
- 1. Read knowledge/stacks/directus/_index.md
220
- 2. Use ItemsService (not raw SQL)
221
- 3. Follow permission patterns
222
- 4. Use SDK for queries
223
- ```
224
-
225
- ## Domain-Specific Logic
226
-
227
- **Load from domains/ when applicable:**
228
-
229
- | Domain | What to load | Key patterns |
230
- |--------|--------------|--------------|
231
- | SaaS | `domains/saas/_index.md` | Subscription states, billing |
232
- | E-commerce | `domains/ecommerce/_index.md` | Order lifecycle, inventory |
233
-
234
- **Example - SaaS billing endpoint:**
235
- ```
236
- 1. Read knowledge/domains/saas/_index.md
237
- 2. Follow subscription state machine
238
- 3. Handle trial → paid → cancelled states
239
- 4. Validate against billing rules
240
- ```