@itz4blitz/agentful 0.3.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +139 -10
- package/bin/cli.js +1032 -48
- package/bin/hooks/README.md +338 -82
- package/bin/hooks/analyze-trigger.js +69 -0
- package/bin/hooks/block-random-docs.js +77 -0
- package/bin/hooks/health-check.js +153 -0
- package/bin/hooks/post-agent.js +101 -0
- package/bin/hooks/post-feature.js +227 -0
- package/bin/hooks/pre-agent.js +118 -0
- package/bin/hooks/pre-feature.js +138 -0
- package/lib/VALIDATION_README.md +455 -0
- package/lib/atomic.js +350 -0
- package/lib/ci/claude-action-integration.js +641 -0
- package/lib/ci/index.js +10 -0
- package/lib/core/CLAUDE_EXECUTOR.md +371 -0
- package/lib/core/README.md +321 -0
- package/lib/core/analyzer.js +497 -0
- package/lib/core/claude-executor.example.js +210 -0
- package/lib/core/claude-executor.js +1046 -0
- package/lib/core/cli.js +141 -0
- package/lib/core/detectors/conventions.js +342 -0
- package/lib/core/detectors/framework.js +276 -0
- package/lib/core/detectors/index.js +15 -0
- package/lib/core/detectors/language.js +199 -0
- package/lib/core/detectors/patterns.js +356 -0
- package/lib/core/generator.js +626 -0
- package/lib/core/index.js +9 -0
- package/lib/core/output-parser.example.js +250 -0
- package/lib/core/output-parser.js +458 -0
- package/lib/core/storage.js +515 -0
- package/lib/core/templates.js +556 -0
- package/lib/index.js +32 -0
- package/lib/init.js +497 -25
- package/lib/pipeline/cli.js +423 -0
- package/lib/pipeline/engine.js +928 -0
- package/lib/pipeline/executor.js +440 -0
- package/lib/pipeline/index.js +33 -0
- package/lib/pipeline/integrations.js +559 -0
- package/lib/pipeline/schemas.js +288 -0
- package/lib/presets.js +207 -0
- package/lib/remote/client.js +361 -0
- package/lib/server/auth.js +286 -0
- package/lib/server/client-example.js +190 -0
- package/lib/server/executor.js +426 -0
- package/lib/server/index.js +469 -0
- package/lib/update-helpers.js +505 -0
- package/lib/validation.js +460 -0
- package/package.json +19 -2
- package/template/.claude/agents/architect.md +260 -0
- package/template/.claude/agents/backend.md +203 -0
- package/template/.claude/agents/fixer.md +244 -0
- package/template/.claude/agents/frontend.md +232 -0
- package/template/.claude/agents/orchestrator.md +528 -0
- package/template/.claude/agents/product-analyzer.md +1130 -0
- package/template/.claude/agents/reviewer.md +229 -0
- package/template/.claude/agents/tester.md +242 -0
- package/{.claude → template/.claude}/commands/agentful-analyze.md +151 -43
- package/template/.claude/commands/agentful-decide.md +470 -0
- package/{.claude → template/.claude}/commands/agentful-product.md +92 -8
- package/template/.claude/commands/agentful-start.md +432 -0
- package/{.claude → template/.claude}/commands/agentful-status.md +88 -3
- package/template/.claude/commands/agentful-update.md +402 -0
- package/template/.claude/commands/agentful-validate.md +369 -0
- package/{.claude → template/.claude}/commands/agentful.md +111 -195
- package/template/.claude/product/EXAMPLES.md +167 -0
- package/{.claude → template/.claude}/settings.json +9 -13
- package/{.claude → template/.claude}/skills/conversation/SKILL.md +13 -7
- package/template/.claude/skills/deployment/SKILL.md +116 -0
- package/template/.claude/skills/product-planning/SKILL.md +463 -0
- package/{.claude → template/.claude}/skills/product-tracking/SKILL.md +10 -21
- package/template/.claude/skills/testing/SKILL.md +228 -0
- package/template/.claude/skills/validation/SKILL.md +650 -0
- package/template/CLAUDE.md +84 -16
- package/template/bin/hooks/block-random-docs.js +121 -0
- package/version.json +1 -1
- package/.claude/agents/architect.md +0 -524
- package/.claude/agents/backend.md +0 -315
- package/.claude/agents/fixer.md +0 -263
- package/.claude/agents/frontend.md +0 -274
- package/.claude/agents/orchestrator.md +0 -283
- package/.claude/agents/product-analyzer.md +0 -799
- package/.claude/agents/reviewer.md +0 -332
- package/.claude/agents/tester.md +0 -410
- package/.claude/commands/agentful-decide.md +0 -214
- package/.claude/commands/agentful-start.md +0 -182
- package/.claude/commands/agentful-validate.md +0 -127
- package/.claude/product/EXAMPLES.md +0 -610
- package/.claude/product/README.md +0 -344
- package/.claude/skills/validation/SKILL.md +0 -271
- package/bin/hooks/analyze-trigger.sh +0 -57
- package/bin/hooks/health-check.sh +0 -36
- package/template/PRODUCT.md +0 -584
- /package/{.claude → template/.claude}/commands/agentful-generate.md +0 -0
- /package/{.claude → template/.claude}/product/index.md +0 -0
package/bin/hooks/README.md
CHANGED
|
@@ -1,120 +1,376 @@
|
|
|
1
|
-
#
|
|
1
|
+
# agentful Lifecycle Hooks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Comprehensive lifecycle hooks for validation and metrics tracking throughout the development workflow. All hooks are Node.js scripts for cross-platform compatibility (Windows, macOS, Linux).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Why Node.js?
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- ✅ **Cross-platform** - Works on Windows, macOS, Linux without modifications
|
|
8
|
+
- ✅ **No extra dependencies** - Node.js already required for Claude Code (>=22.0.0)
|
|
9
|
+
- ✅ **Zero external packages** - Uses only built-in modules (`fs`, `path`, `child_process`)
|
|
10
|
+
- ✅ **Maintainable** - JavaScript is more familiar to most developers than Bash
|
|
11
|
+
- ✅ **Consistent behavior** - Same execution across all platforms
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
## Available Hooks
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
- `package.json` (root only, excludes node_modules)
|
|
13
|
-
- `architecture.json`
|
|
14
|
-
- `tsconfig.json` / `jsconfig.json`
|
|
15
|
-
- Build configs: `vite.config.*`, `webpack.config.*`, `rollup.config.*`, `next.config.*`
|
|
16
|
-
- Environment templates: `.env.example`, `.env.sample`
|
|
17
|
-
- Docker files: `docker-compose.yml`, `Dockerfile`
|
|
15
|
+
### 1. Pre-Agent Hook (`pre-agent.js`)
|
|
18
16
|
|
|
19
|
-
**
|
|
20
|
-
- Runs on PostToolUse for Write/Edit operations
|
|
21
|
-
- Exits silently for non-matching files
|
|
22
|
-
- Outputs suggestion message for matching files
|
|
23
|
-
- Timeout: 3 seconds
|
|
17
|
+
**Purpose**: Validates agent preconditions before invocation
|
|
24
18
|
|
|
25
|
-
**
|
|
19
|
+
**When to invoke**: Before calling `Task()` to delegate to any agent
|
|
20
|
+
|
|
21
|
+
**Environment Variables**:
|
|
22
|
+
- `AGENTFUL_AGENT` - Name of the agent being invoked (e.g., "backend", "frontend")
|
|
23
|
+
- `AGENTFUL_FEATURE` - Feature being worked on (optional)
|
|
24
|
+
- `AGENTFUL_DOMAIN` - Domain containing the feature (optional)
|
|
25
|
+
|
|
26
|
+
**Checks**:
|
|
27
|
+
- Agent file exists in `.claude/agents/`
|
|
28
|
+
- Required state files exist (state.json, completion.json, decisions.json)
|
|
29
|
+
- State files are valid JSON
|
|
30
|
+
- Feature exists in product specification (if specified)
|
|
31
|
+
- Orchestrator is not blocked on decisions
|
|
32
|
+
|
|
33
|
+
**Return Codes**:
|
|
34
|
+
- `0` - All validations passed, proceed with agent invocation
|
|
35
|
+
- `1` - Validation failed, block agent invocation
|
|
36
|
+
|
|
37
|
+
**Example Usage**:
|
|
38
|
+
```bash
|
|
39
|
+
export AGENTFUL_AGENT="backend"
|
|
40
|
+
export AGENTFUL_FEATURE="user-login"
|
|
41
|
+
export AGENTFUL_DOMAIN="authentication"
|
|
42
|
+
|
|
43
|
+
node bin/hooks/pre-agent.js
|
|
44
|
+
# or make executable
|
|
45
|
+
./bin/hooks/pre-agent.js
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 2. Post-Agent Hook (`post-agent.js`)
|
|
49
|
+
|
|
50
|
+
**Purpose**: Tracks agent execution metrics and invocation history
|
|
51
|
+
|
|
52
|
+
**When to invoke**: After an agent completes its work (success or failure)
|
|
53
|
+
|
|
54
|
+
**Environment Variables**: Same as pre-agent
|
|
55
|
+
|
|
56
|
+
**Actions**:
|
|
57
|
+
- Increments invocation counter for the agent
|
|
58
|
+
- Records last invocation timestamp
|
|
59
|
+
- Updates `.agentful/agent-metrics.json`
|
|
60
|
+
|
|
61
|
+
**Return Codes**:
|
|
62
|
+
- `0` - Always succeeds (non-blocking)
|
|
63
|
+
|
|
64
|
+
**Example Usage**:
|
|
65
|
+
```bash
|
|
66
|
+
export AGENTFUL_AGENT="frontend"
|
|
67
|
+
node bin/hooks/post-agent.js
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 3. Pre-Feature Hook (`pre-feature.js`)
|
|
71
|
+
|
|
72
|
+
**Purpose**: Validates feature readiness before implementation
|
|
73
|
+
|
|
74
|
+
**When to invoke**: Before starting feature implementation
|
|
75
|
+
|
|
76
|
+
**Environment Variables**:
|
|
77
|
+
- `AGENTFUL_FEATURE` - Feature name (required)
|
|
78
|
+
- `AGENTFUL_DOMAIN` - Domain name (optional for hierarchical structure)
|
|
79
|
+
|
|
80
|
+
**Checks**:
|
|
81
|
+
- Feature file exists in product specification
|
|
82
|
+
- Completion tracking exists
|
|
83
|
+
- Feature dependencies are met
|
|
84
|
+
- Domain is not blocked (for hierarchical structure)
|
|
85
|
+
- No blocking decisions exist for this feature
|
|
86
|
+
- Tech stack has been analyzed
|
|
87
|
+
- Required agents exist
|
|
88
|
+
|
|
89
|
+
**Return Codes**:
|
|
90
|
+
- `0` - All validations passed (may have warnings)
|
|
91
|
+
- `1` - Validation failed, block feature implementation
|
|
92
|
+
|
|
93
|
+
**Example Usage**:
|
|
94
|
+
```bash
|
|
95
|
+
export AGENTFUL_FEATURE="checkout-flow"
|
|
96
|
+
export AGENTFUL_DOMAIN="ecommerce"
|
|
97
|
+
node bin/hooks/pre-feature.js
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 4. Post-Feature Hook (`post-feature.js`)
|
|
101
|
+
|
|
102
|
+
**Purpose**: Feature completion validation and automated testing
|
|
103
|
+
|
|
104
|
+
**When to invoke**: After feature implementation is complete
|
|
105
|
+
|
|
106
|
+
**Environment Variables**: Same as pre-feature
|
|
107
|
+
|
|
108
|
+
**Actions**:
|
|
109
|
+
1. Runs test suite (`npm test`)
|
|
110
|
+
2. Runs type checking (`npx tsc --noEmit` if TypeScript exists)
|
|
111
|
+
3. Runs linter (`npm run lint`)
|
|
112
|
+
4. Checks test coverage (if available)
|
|
113
|
+
5. Updates `.agentful/completion.json` with validation results
|
|
114
|
+
6. Creates git commit if all validations pass
|
|
115
|
+
|
|
116
|
+
**Return Codes**:
|
|
117
|
+
- `0` - All validations passed, feature complete
|
|
118
|
+
- `1` - Validation failed, needs fixes
|
|
119
|
+
|
|
120
|
+
**Example Usage**:
|
|
26
121
|
```bash
|
|
27
|
-
|
|
122
|
+
export AGENTFUL_FEATURE="search-api"
|
|
123
|
+
node bin/hooks/post-feature.js
|
|
28
124
|
```
|
|
29
125
|
|
|
30
|
-
### `health-check.
|
|
126
|
+
### 5. Health Check Hook (`health-check.js`)
|
|
127
|
+
|
|
128
|
+
**Purpose**: Comprehensive startup health check for agentful
|
|
31
129
|
|
|
32
|
-
**
|
|
130
|
+
**When to invoke**: On system startup, before any agent invocation
|
|
131
|
+
|
|
132
|
+
**Environment Variables**: None
|
|
33
133
|
|
|
34
134
|
**Checks**:
|
|
35
135
|
- `.agentful/` directory exists
|
|
36
|
-
-
|
|
37
|
-
-
|
|
136
|
+
- Core state files exist and are valid JSON
|
|
137
|
+
- `.claude/` directory structure is complete
|
|
138
|
+
- All core agents exist
|
|
139
|
+
- Product specification exists
|
|
140
|
+
- Settings file is valid
|
|
141
|
+
- Architecture has been analyzed
|
|
142
|
+
- Node.js version meets requirements (>=22.0.0)
|
|
143
|
+
|
|
144
|
+
**Return Codes**:
|
|
145
|
+
- `0` - System ready (may have warnings)
|
|
146
|
+
|
|
147
|
+
**Example Usage**:
|
|
148
|
+
```bash
|
|
149
|
+
node bin/hooks/health-check.js
|
|
150
|
+
```
|
|
38
151
|
|
|
39
|
-
|
|
40
|
-
- Runs on SessionStart
|
|
41
|
-
- Outputs "Agentful ready." if all checks pass
|
|
42
|
-
- Lists warnings for missing components
|
|
43
|
-
- Always exits with code 0 (non-blocking)
|
|
44
|
-
- Timeout: 5 seconds
|
|
152
|
+
### 6. Analyze Trigger Hook (`analyze-trigger.js`)
|
|
45
153
|
|
|
46
|
-
**
|
|
154
|
+
**Purpose**: Suggests running `/agentful-analyze` when critical files change
|
|
155
|
+
|
|
156
|
+
**When to invoke**: After file modifications (via git hooks or file watchers)
|
|
157
|
+
|
|
158
|
+
**Environment Variables**:
|
|
159
|
+
- `FILE` - Path to the changed file
|
|
160
|
+
|
|
161
|
+
**Triggers suggestions for**:
|
|
162
|
+
- `package.json` - Dependency changes
|
|
163
|
+
- `architecture.json` - Architecture updates
|
|
164
|
+
- `tsconfig.json` / `jsconfig.json` - TypeScript/JavaScript config
|
|
165
|
+
- Build configs (vite, webpack, rollup, next)
|
|
166
|
+
- Environment templates (`.env.example`, `.env.sample`)
|
|
167
|
+
- Docker configs (`Dockerfile`, `docker-compose.yml`)
|
|
168
|
+
|
|
169
|
+
**Return Codes**:
|
|
170
|
+
- `0` - Always succeeds (informational only)
|
|
171
|
+
|
|
172
|
+
**Example Usage**:
|
|
47
173
|
```bash
|
|
48
|
-
|
|
174
|
+
export FILE="package.json"
|
|
175
|
+
node bin/hooks/analyze-trigger.js
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Implementation Details
|
|
179
|
+
|
|
180
|
+
### Technical Architecture
|
|
181
|
+
|
|
182
|
+
The Node.js hooks use:
|
|
183
|
+
- **ES Modules** - Leverages `"type": "module"` from package.json
|
|
184
|
+
- **Built-in modules only** - `fs`, `path`, `child_process` (no external dependencies)
|
|
185
|
+
- **Cross-platform paths** - Uses `path` module for proper path handling
|
|
186
|
+
- **Environment variables** - `process.env` for configuration
|
|
187
|
+
- **Exit codes** - `process.exit(0/1)` for proper shell integration
|
|
188
|
+
- **JSON parsing** - Native `JSON.parse()` for validation and querying
|
|
189
|
+
- **Command execution** - `execSync` for running npm scripts and git commands
|
|
190
|
+
|
|
191
|
+
### File Structure
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
bin/hooks/
|
|
195
|
+
├── pre-agent.js # Agent precondition validation
|
|
196
|
+
├── post-agent.js # Agent metrics tracking
|
|
197
|
+
├── pre-feature.js # Feature readiness validation
|
|
198
|
+
├── post-feature.js # Feature completion validation
|
|
199
|
+
├── health-check.js # System health check
|
|
200
|
+
├── analyze-trigger.js # Analysis suggestion trigger
|
|
201
|
+
└── README.md # This file
|
|
49
202
|
```
|
|
50
203
|
|
|
51
|
-
|
|
204
|
+
All hooks are executable (`chmod +x`) and can be invoked directly or via `node`.
|
|
52
205
|
|
|
53
|
-
|
|
206
|
+
## Metrics Structure
|
|
54
207
|
|
|
208
|
+
`.agentful/agent-metrics.json`:
|
|
55
209
|
```json
|
|
56
210
|
{
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
211
|
+
"invocations": {
|
|
212
|
+
"backend": 15,
|
|
213
|
+
"frontend": 12,
|
|
214
|
+
"tester": 8
|
|
215
|
+
},
|
|
216
|
+
"last_invocation": {
|
|
217
|
+
"agent": "backend",
|
|
218
|
+
"timestamp": "2026-01-20T10:30:00Z",
|
|
219
|
+
"feature": "login",
|
|
220
|
+
"domain": "authentication"
|
|
221
|
+
},
|
|
222
|
+
"feature_hooks": [
|
|
223
|
+
{
|
|
224
|
+
"hook": "PreFeature",
|
|
225
|
+
"feature": "login",
|
|
226
|
+
"domain": "auth",
|
|
227
|
+
"timestamp": "2026-01-20T10:25:00Z",
|
|
228
|
+
"result": "passed"
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
"hook": "PostFeature",
|
|
232
|
+
"feature": "login",
|
|
233
|
+
"domain": "auth",
|
|
234
|
+
"timestamp": "2026-01-20T10:35:00Z",
|
|
235
|
+
"result": "passed"
|
|
236
|
+
}
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Integration Examples
|
|
242
|
+
|
|
243
|
+
### From Orchestrator Agent
|
|
244
|
+
|
|
245
|
+
```javascript
|
|
246
|
+
// Before delegating to an agent
|
|
247
|
+
const preAgentCheck = await Bash({
|
|
248
|
+
command: `AGENTFUL_AGENT="${agentName}" AGENTFUL_FEATURE="${featureName}" node bin/hooks/pre-agent.js`,
|
|
249
|
+
description: "Validate agent preconditions"
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
if (preAgentCheck.exit_code !== 0) {
|
|
253
|
+
// Handle validation failure
|
|
254
|
+
return "Pre-agent validation failed. Cannot proceed.";
|
|
82
255
|
}
|
|
256
|
+
|
|
257
|
+
// Delegate to agent
|
|
258
|
+
await Task({
|
|
259
|
+
agent: agentName,
|
|
260
|
+
task: "Implement feature..."
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// After agent completes
|
|
264
|
+
await Bash({
|
|
265
|
+
command: `AGENTFUL_AGENT="${agentName}" AGENTFUL_FEATURE="${featureName}" node bin/hooks/post-agent.js`,
|
|
266
|
+
description: "Track agent metrics"
|
|
267
|
+
});
|
|
83
268
|
```
|
|
84
269
|
|
|
85
|
-
|
|
270
|
+
### From CLI Commands
|
|
86
271
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
272
|
+
```javascript
|
|
273
|
+
// In /agentful-start command
|
|
274
|
+
await Bash({
|
|
275
|
+
command: 'node bin/hooks/health-check.js',
|
|
276
|
+
description: "System health check"
|
|
277
|
+
});
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### From Git Hooks
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
# .git/hooks/post-checkout
|
|
284
|
+
#!/bin/bash
|
|
285
|
+
FILE="package.json"
|
|
286
|
+
if git diff --name-only HEAD@{1} HEAD | grep -q "$FILE"; then
|
|
287
|
+
export FILE="$FILE"
|
|
288
|
+
node bin/hooks/analyze-trigger.js
|
|
289
|
+
fi
|
|
290
|
+
```
|
|
92
291
|
|
|
93
|
-
|
|
292
|
+
### From CI/CD Pipelines
|
|
94
293
|
|
|
95
|
-
|
|
294
|
+
```yaml
|
|
295
|
+
# GitHub Actions example
|
|
296
|
+
steps:
|
|
297
|
+
- name: Pre-feature validation
|
|
298
|
+
run: |
|
|
299
|
+
export AGENTFUL_FEATURE="api-auth"
|
|
300
|
+
export AGENTFUL_DOMAIN="backend"
|
|
301
|
+
node bin/hooks/pre-feature.js
|
|
96
302
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
303
|
+
- name: Run feature implementation
|
|
304
|
+
run: |
|
|
305
|
+
# Your implementation steps
|
|
306
|
+
|
|
307
|
+
- name: Post-feature validation
|
|
308
|
+
run: |
|
|
309
|
+
export AGENTFUL_FEATURE="api-auth"
|
|
310
|
+
export AGENTFUL_DOMAIN="backend"
|
|
311
|
+
node bin/hooks/post-feature.js
|
|
312
|
+
```
|
|
104
313
|
|
|
105
314
|
## Testing
|
|
106
315
|
|
|
107
|
-
|
|
316
|
+
To test a hook manually:
|
|
108
317
|
|
|
109
318
|
```bash
|
|
110
|
-
# Test
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
319
|
+
# Test pre-agent validation
|
|
320
|
+
export AGENTFUL_AGENT="backend"
|
|
321
|
+
export AGENTFUL_FEATURE="test-feature"
|
|
322
|
+
node bin/hooks/pre-agent.js
|
|
323
|
+
echo "Exit code: $?"
|
|
324
|
+
|
|
325
|
+
# Test health check
|
|
326
|
+
node bin/hooks/health-check.js
|
|
327
|
+
|
|
328
|
+
# Test with invalid state (should fail)
|
|
329
|
+
mv .agentful/state.json .agentful/state.json.bak
|
|
330
|
+
export AGENTFUL_AGENT="backend"
|
|
331
|
+
node bin/hooks/pre-agent.js
|
|
332
|
+
echo "Exit code: $?" # Should be 1
|
|
333
|
+
mv .agentful/state.json.bak .agentful/state.json
|
|
334
|
+
|
|
335
|
+
# Test post-agent metrics
|
|
336
|
+
export AGENTFUL_AGENT="tester"
|
|
337
|
+
export AGENTFUL_FEATURE="unit-tests"
|
|
338
|
+
node bin/hooks/post-agent.js
|
|
339
|
+
cat .agentful/agent-metrics.json # Verify metrics updated
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## Troubleshooting
|
|
343
|
+
|
|
344
|
+
### Hook Not Executing
|
|
345
|
+
|
|
346
|
+
If a hook doesn't execute:
|
|
347
|
+
1. Verify Node.js version: `node --version` (must be >=22.0.0)
|
|
348
|
+
2. Check file permissions: `ls -la bin/hooks/` (should be executable)
|
|
349
|
+
3. Make executable: `chmod +x bin/hooks/*.js`
|
|
350
|
+
4. Verify environment variables are set: `echo $AGENTFUL_AGENT`
|
|
351
|
+
|
|
352
|
+
### Exit Code Issues
|
|
114
353
|
|
|
115
|
-
|
|
116
|
-
|
|
354
|
+
Hooks use standard exit codes:
|
|
355
|
+
- `0` = Success (proceed)
|
|
356
|
+
- `1` = Failure (block)
|
|
117
357
|
|
|
118
|
-
|
|
119
|
-
|
|
358
|
+
Check exit code in shell:
|
|
359
|
+
```bash
|
|
360
|
+
node bin/hooks/pre-agent.js
|
|
361
|
+
echo $? # Shows exit code
|
|
120
362
|
```
|
|
363
|
+
|
|
364
|
+
### JSON Parse Errors
|
|
365
|
+
|
|
366
|
+
If you see JSON parse errors:
|
|
367
|
+
1. Validate JSON files: `node -e "JSON.parse(require('fs').readFileSync('.agentful/state.json'))"`
|
|
368
|
+
2. Check file encoding (must be UTF-8)
|
|
369
|
+
3. Look for trailing commas or syntax errors
|
|
370
|
+
|
|
371
|
+
## See Documentation
|
|
372
|
+
|
|
373
|
+
For complete documentation, usage examples, and integration guide, see:
|
|
374
|
+
- Orchestrator integration instructions in `.claude/agents/orchestrator.md`
|
|
375
|
+
- Individual hook script headers for detailed behavior
|
|
376
|
+
- Main documentation at `docs/`
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// analyze-trigger.js
|
|
3
|
+
// Checks if changed files warrant an /agentful-analyze suggestion
|
|
4
|
+
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Check if a file change should trigger an /agentful-analyze suggestion
|
|
9
|
+
* @param {string} filepath - The file path to check
|
|
10
|
+
* @returns {string|null} - Suggestion message or null if no suggestion needed
|
|
11
|
+
*/
|
|
12
|
+
export function checkAnalyzeTrigger(filepath) {
|
|
13
|
+
// Exit silently if no file specified
|
|
14
|
+
if (!filepath) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Normalize the file path to get just the filename
|
|
19
|
+
const filename = path.basename(filepath);
|
|
20
|
+
|
|
21
|
+
// Check for key files that should trigger analysis suggestions
|
|
22
|
+
switch (filename) {
|
|
23
|
+
case 'package.json':
|
|
24
|
+
// Only trigger for root package.json, not node_modules
|
|
25
|
+
if (filepath.includes('node_modules')) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return 'Dependencies changed in package.json. Consider running /agentful-analyze to update architecture understanding.';
|
|
29
|
+
|
|
30
|
+
case 'architecture.json':
|
|
31
|
+
return 'Architecture configuration updated. Run /agentful-analyze to refresh tech stack analysis.';
|
|
32
|
+
|
|
33
|
+
case 'tsconfig.json':
|
|
34
|
+
case 'jsconfig.json':
|
|
35
|
+
return 'TypeScript/JavaScript configuration changed. Consider running /agentful-analyze to update build settings.';
|
|
36
|
+
|
|
37
|
+
case '.env.example':
|
|
38
|
+
case '.env.sample':
|
|
39
|
+
return 'Environment template changed. Consider running /agentful-analyze to update configuration understanding.';
|
|
40
|
+
|
|
41
|
+
case 'docker-compose.yml':
|
|
42
|
+
case 'Dockerfile':
|
|
43
|
+
return 'Docker configuration changed. Consider running /agentful-analyze to update deployment setup.';
|
|
44
|
+
|
|
45
|
+
default:
|
|
46
|
+
// Check for build config files with patterns
|
|
47
|
+
if (filename.startsWith('vite.config.') ||
|
|
48
|
+
filename.startsWith('webpack.config.') ||
|
|
49
|
+
filename.startsWith('rollup.config.') ||
|
|
50
|
+
filename.startsWith('next.config.')) {
|
|
51
|
+
return 'Build configuration changed. Consider running /agentful-analyze to update bundler settings.';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// No suggestion needed for other files
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// CLI entrypoint
|
|
60
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
61
|
+
const FILE = process.env.FILE || '';
|
|
62
|
+
const message = checkAnalyzeTrigger(FILE);
|
|
63
|
+
|
|
64
|
+
if (message) {
|
|
65
|
+
console.log(message);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
process.exit(0);
|
|
69
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Block Random Documentation Hook
|
|
5
|
+
*
|
|
6
|
+
* Prevents creation of random markdown files outside of allowed directories.
|
|
7
|
+
*
|
|
8
|
+
* Allowed markdown locations:
|
|
9
|
+
* - docs/pages/*.mdx (Vocs documentation)
|
|
10
|
+
* - README.md, CONTRIBUTING.md, CHANGELOG.md (root project docs)
|
|
11
|
+
* - .claude/agents/*.md (agent definitions)
|
|
12
|
+
* - .claude/skills/*\/SKILL.md (skill documentation)
|
|
13
|
+
* - .claude/product/**\/*.md (product specifications)
|
|
14
|
+
* - template/**\/*.md (template files)
|
|
15
|
+
* - examples/**\/*.md (example documentation)
|
|
16
|
+
*
|
|
17
|
+
* Blocked:
|
|
18
|
+
* - Random *.md files in project root
|
|
19
|
+
* - Documentation in lib/, src/, test/ directories
|
|
20
|
+
* - Any ad-hoc "summary", "guide", "notes" files
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import path from 'path';
|
|
24
|
+
import fs from 'fs';
|
|
25
|
+
|
|
26
|
+
// Get file path from environment (set by Claude Code hooks)
|
|
27
|
+
const filePath = process.env.FILE || '';
|
|
28
|
+
|
|
29
|
+
// Only check markdown files
|
|
30
|
+
if (!filePath.endsWith('.md') && !filePath.endsWith('.mdx')) {
|
|
31
|
+
process.exit(0);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Normalize path
|
|
35
|
+
const normalizedPath = path.normalize(filePath);
|
|
36
|
+
|
|
37
|
+
// Allowed patterns (regex)
|
|
38
|
+
const ALLOWED_PATTERNS = [
|
|
39
|
+
/^docs\/pages\/.*\.mdx$/, // Vocs docs
|
|
40
|
+
/^(README|CONTRIBUTING|CHANGELOG)\.md$/, // Root project docs
|
|
41
|
+
/^\.claude\/agents\/[^\/]+\.md$/, // Agent definitions
|
|
42
|
+
/^\.claude\/skills\/[^\/]+\/SKILL\.md$/, // Skill docs
|
|
43
|
+
/^\.claude\/product\/.*\.md$/, // Product specs
|
|
44
|
+
/^template\/.*\.md$/, // Template files
|
|
45
|
+
/^examples\/.*\.md$/, // Examples
|
|
46
|
+
/^\.agentful\/.*\.md$/ // Internal agentful state docs (rare)
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
// Check if file matches any allowed pattern
|
|
50
|
+
const isAllowed = ALLOWED_PATTERNS.some(pattern => pattern.test(normalizedPath));
|
|
51
|
+
|
|
52
|
+
if (!isAllowed) {
|
|
53
|
+
console.error(`
|
|
54
|
+
❌ BLOCKED: Random markdown file creation
|
|
55
|
+
|
|
56
|
+
File: ${filePath}
|
|
57
|
+
|
|
58
|
+
Allowed locations:
|
|
59
|
+
- docs/pages/*.mdx (user-facing documentation)
|
|
60
|
+
- README.md, CONTRIBUTING.md, CHANGELOG.md (root project docs)
|
|
61
|
+
- .claude/agents/*.md (agent definitions)
|
|
62
|
+
- .claude/skills/*/SKILL.md (skill documentation)
|
|
63
|
+
- .claude/product/**/*.md (product specifications)
|
|
64
|
+
|
|
65
|
+
Instead of creating random markdown files:
|
|
66
|
+
1. Update CLAUDE.md for instructions
|
|
67
|
+
2. Update skills for implementation patterns
|
|
68
|
+
3. Update docs/pages/*.mdx for user docs
|
|
69
|
+
4. Update agents for role definitions
|
|
70
|
+
|
|
71
|
+
Do NOT litter the codebase with ad-hoc documentation files.
|
|
72
|
+
`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// File is allowed
|
|
77
|
+
process.exit(0);
|