mapify-cli 1.0.0__py3-none-any.whl
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.
- mapify_cli/__init__.py +1946 -0
- mapify_cli/playbook_manager.py +517 -0
- mapify_cli/recitation_manager.py +551 -0
- mapify_cli/semantic_search.py +405 -0
- mapify_cli/templates/agents/CHANGELOG.md +108 -0
- mapify_cli/templates/agents/MCP-PATTERNS.md +343 -0
- mapify_cli/templates/agents/README.md +183 -0
- mapify_cli/templates/agents/actor.md +650 -0
- mapify_cli/templates/agents/curator.md +1155 -0
- mapify_cli/templates/agents/documentation-reviewer.md +1282 -0
- mapify_cli/templates/agents/evaluator.md +843 -0
- mapify_cli/templates/agents/monitor.md +977 -0
- mapify_cli/templates/agents/predictor.md +965 -0
- mapify_cli/templates/agents/reflector.md +1048 -0
- mapify_cli/templates/agents/task-decomposer.md +1169 -0
- mapify_cli/templates/agents/test-generator.md +1175 -0
- mapify_cli/templates/commands/map-debug.md +315 -0
- mapify_cli/templates/commands/map-feature.md +454 -0
- mapify_cli/templates/commands/map-refactor.md +317 -0
- mapify_cli/templates/commands/map-review.md +29 -0
- mapify_cli/templates/hooks/README.md +55 -0
- mapify_cli/templates/hooks/validate-agent-templates.sh +94 -0
- mapify_cli/templates/settings.hooks.json +20 -0
- mapify_cli/workflow_logger.py +411 -0
- mapify_cli-1.0.0.dist-info/METADATA +310 -0
- mapify_cli-1.0.0.dist-info/RECORD +28 -0
- mapify_cli-1.0.0.dist-info/WHEEL +4 -0
- mapify_cli-1.0.0.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Refactor code with MAP impact analysis
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# MAP Refactoring Workflow
|
|
6
|
+
|
|
7
|
+
**π¨ ABSOLUTELY FORBIDDEN π¨**
|
|
8
|
+
|
|
9
|
+
You are **STRICTLY PROHIBITED** from:
|
|
10
|
+
|
|
11
|
+
β **"Optimizing" the workflow due to token limits** - Token constraints are NOT a valid reason to skip agents
|
|
12
|
+
β **"Combining steps to save time"** - Each agent MUST be called individually
|
|
13
|
+
β **"Doing Reflector/Curator work manually"** - This breaks cipher integration
|
|
14
|
+
β **"Creating a comprehensive document instead"** - This is NOT the MAP workflow
|
|
15
|
+
β **"Skipping reflection for simple tasks"** - EVERY subtask requires Reflector + Curator
|
|
16
|
+
β **Any variation of "I'll optimize by..."** - NO OPTIMIZATION ALLOWED
|
|
17
|
+
|
|
18
|
+
**IF YOU VIOLATE THESE RULES:**
|
|
19
|
+
- cipher_memory_search won't be called β duplicate knowledge
|
|
20
|
+
- cipher_extract_and_operate_memory won't be called β knowledge won't be shared
|
|
21
|
+
- The ENTIRE PURPOSE of MAP Framework will be defeated
|
|
22
|
+
|
|
23
|
+
**YOU MUST:**
|
|
24
|
+
β
Call EVERY agent in sequence for EVERY subtask
|
|
25
|
+
β
Verify each agent used required MCP tools (check output)
|
|
26
|
+
β
Complete the FULL workflow even if it takes 100K+ tokens
|
|
27
|
+
β
Ask user to continue if you hit token limit, but NEVER skip agents
|
|
28
|
+
|
|
29
|
+
Refactor the following code using the MAP framework with comprehensive impact analysis:
|
|
30
|
+
|
|
31
|
+
**Refactor Request:** $ARGUMENTS
|
|
32
|
+
|
|
33
|
+
## Workflow Overview
|
|
34
|
+
|
|
35
|
+
Refactoring requires careful analysis to ensure no behavioral changes:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
1. PREDICT β predictor (analyze all dependencies FIRST)
|
|
39
|
+
2. DECOMPOSE β task-decomposer (break into refactoring steps)
|
|
40
|
+
3. FOR each refactoring step:
|
|
41
|
+
4. IMPLEMENT β actor (refactor code)
|
|
42
|
+
5. VALIDATE β monitor (ensure no logic changes)
|
|
43
|
+
6. PREDICT β predictor (verify no breaking changes)
|
|
44
|
+
7. EVALUATE β evaluator (check quality improvement)
|
|
45
|
+
8. Apply changes and test
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Step 1: Initial Impact Analysis (Critical!)
|
|
49
|
+
|
|
50
|
+
**ALWAYS run predictor FIRST** before any refactoring:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
Task(
|
|
54
|
+
subagent_type="predictor",
|
|
55
|
+
description="Analyze refactoring scope and dependencies",
|
|
56
|
+
prompt="Analyze the scope and dependencies for this refactoring:
|
|
57
|
+
|
|
58
|
+
**Refactoring Request:** $ARGUMENTS
|
|
59
|
+
|
|
60
|
+
Before making ANY changes, identify:
|
|
61
|
+
- All files that import/use the code to be refactored
|
|
62
|
+
- All tests that depend on this code
|
|
63
|
+
- All public APIs that might be affected
|
|
64
|
+
- All configuration files that reference this code
|
|
65
|
+
- Database schemas, migrations, or data structures involved
|
|
66
|
+
|
|
67
|
+
Output JSON with:
|
|
68
|
+
- affected_files: array of {path, relationship, impact_level}
|
|
69
|
+
- public_apis: array of {name, type, usage_locations}
|
|
70
|
+
- dependencies: array of {type, description, must_update}
|
|
71
|
+
- risk_assessment: {level: 'low'|'medium'|'high', reasoning: string}
|
|
72
|
+
- recommended_approach: string
|
|
73
|
+
- testing_strategy: string"
|
|
74
|
+
)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**If predictor.risk_assessment.level === 'high':**
|
|
78
|
+
- Ask user for confirmation before proceeding
|
|
79
|
+
- Consider breaking into smaller refactoring steps
|
|
80
|
+
|
|
81
|
+
## Step 2: Decompose Refactoring
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
Task(
|
|
85
|
+
subagent_type="task-decomposer",
|
|
86
|
+
description="Decompose refactoring into safe steps",
|
|
87
|
+
prompt="Break down this refactoring into atomic, safe steps:
|
|
88
|
+
|
|
89
|
+
**Refactoring Goal:** $ARGUMENTS
|
|
90
|
+
|
|
91
|
+
**Predictor Analysis:** [paste predictor JSON]
|
|
92
|
+
|
|
93
|
+
Create subtasks that:
|
|
94
|
+
- Minimize risk (each step should be independently testable)
|
|
95
|
+
- Maintain backward compatibility where possible
|
|
96
|
+
- Allow for incremental rollback if issues occur
|
|
97
|
+
|
|
98
|
+
Output JSON with:
|
|
99
|
+
- subtasks: array of {id, description, refactor_type, risk_level, rollback_plan}
|
|
100
|
+
- dependency_order: array of subtask IDs in execution order
|
|
101
|
+
- critical_checkpoints: array of {after_subtask_id, verification_required}
|
|
102
|
+
|
|
103
|
+
Refactor types:
|
|
104
|
+
- rename: changing names only
|
|
105
|
+
- extract: moving code to new location
|
|
106
|
+
- restructure: changing organization
|
|
107
|
+
- simplify: reducing complexity"
|
|
108
|
+
)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Step 3: For Each Refactoring Step
|
|
112
|
+
|
|
113
|
+
### Actor: Implement Refactoring
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
Task(
|
|
117
|
+
subagent_type="actor",
|
|
118
|
+
description="Refactor [component]",
|
|
119
|
+
prompt="Perform this refactoring step:
|
|
120
|
+
|
|
121
|
+
**Step:** [description]
|
|
122
|
+
**Type:** [refactor_type]
|
|
123
|
+
**Affected Files:** [from predictor]
|
|
124
|
+
|
|
125
|
+
Output JSON with:
|
|
126
|
+
- approach: string (refactoring strategy)
|
|
127
|
+
- code_changes: array of {file_path, change_type, content, before_snippet, after_snippet}
|
|
128
|
+
- behavior_unchanged_proof: string (explain why behavior is identical)
|
|
129
|
+
- updated_imports: array of {file, old_import, new_import}
|
|
130
|
+
- updated_tests: array of {file, changes_needed}
|
|
131
|
+
|
|
132
|
+
**CRITICAL:** For refactoring, provide side-by-side comparison showing behavior is unchanged."
|
|
133
|
+
)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Monitor: Validate No Behavior Changes
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
Task(
|
|
140
|
+
subagent_type="monitor",
|
|
141
|
+
description="Validate refactoring preserves behavior",
|
|
142
|
+
prompt="Review this refactoring to ensure NO behavioral changes:
|
|
143
|
+
|
|
144
|
+
**Actor Refactoring:** [paste actor JSON]
|
|
145
|
+
|
|
146
|
+
Check:
|
|
147
|
+
- Is the logic exactly the same? (only structure changed)
|
|
148
|
+
- Are all imports/exports updated correctly?
|
|
149
|
+
- Are tests still valid or properly updated?
|
|
150
|
+
- Are there any subtle behavior changes?
|
|
151
|
+
- Is error handling unchanged?
|
|
152
|
+
- Are edge cases still handled the same way?
|
|
153
|
+
|
|
154
|
+
**CRITICAL:** Reject if ANY behavior changes detected.
|
|
155
|
+
|
|
156
|
+
Output JSON with:
|
|
157
|
+
- behavior_preserved: boolean
|
|
158
|
+
- issues: array of {severity, category, description}
|
|
159
|
+
- test_updates_needed: array of strings
|
|
160
|
+
- verdict: 'approved'|'needs_revision'|'rejected'
|
|
161
|
+
- feedback: string"
|
|
162
|
+
)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Predictor: Verify No Breaking Changes
|
|
166
|
+
|
|
167
|
+
After monitor approval:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
Task(
|
|
171
|
+
subagent_type="predictor",
|
|
172
|
+
description="Verify no breaking changes introduced",
|
|
173
|
+
prompt="Verify this refactoring introduces no breaking changes:
|
|
174
|
+
|
|
175
|
+
**Refactoring:** [paste actor JSON]
|
|
176
|
+
**Monitor Verdict:** approved
|
|
177
|
+
|
|
178
|
+
Check:
|
|
179
|
+
- Are all public APIs unchanged?
|
|
180
|
+
- Are all usages still valid?
|
|
181
|
+
- Are there any import/export breakages?
|
|
182
|
+
- Does this affect any external consumers?
|
|
183
|
+
|
|
184
|
+
Output JSON with:
|
|
185
|
+
- breaking_changes: array (should be empty for pure refactoring!)
|
|
186
|
+
- compatibility_check: {backward_compatible: boolean, forward_compatible: boolean}
|
|
187
|
+
- verification_tests: array of tests that must pass
|
|
188
|
+
- risk_level: 'low' (should always be low for pure refactoring)"
|
|
189
|
+
)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Evaluator: Assess Quality Improvement
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
Task(
|
|
196
|
+
subagent_type="evaluator",
|
|
197
|
+
description="Evaluate refactoring quality improvement",
|
|
198
|
+
prompt="Evaluate the quality improvement from this refactoring:
|
|
199
|
+
|
|
200
|
+
**Before:** [code before refactoring]
|
|
201
|
+
**After:** [paste actor JSON]
|
|
202
|
+
|
|
203
|
+
Score improvement (0-10) in:
|
|
204
|
+
- readability: is code easier to understand?
|
|
205
|
+
- maintainability: is code easier to modify?
|
|
206
|
+
- testability: is code easier to test?
|
|
207
|
+
- modularity: is structure better organized?
|
|
208
|
+
- complexity: is complexity reduced?
|
|
209
|
+
|
|
210
|
+
Output JSON with:
|
|
211
|
+
- improvement_scores: object
|
|
212
|
+
- overall_improvement: number
|
|
213
|
+
- recommendation: 'proceed'|'improve'|'revert'
|
|
214
|
+
- justification: string
|
|
215
|
+
- was_it_worth_it: boolean"
|
|
216
|
+
)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Apply Refactoring
|
|
220
|
+
|
|
221
|
+
If all checks pass:
|
|
222
|
+
- Apply code changes
|
|
223
|
+
- Update all imports/references
|
|
224
|
+
- **Run ALL tests** (critical for refactoring!)
|
|
225
|
+
- Verify behavior unchanged
|
|
226
|
+
|
|
227
|
+
### Reflect on Refactoring
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
Task(
|
|
231
|
+
subagent_type="reflector",
|
|
232
|
+
description="Extract refactoring lessons",
|
|
233
|
+
prompt="Extract lessons from this refactoring:
|
|
234
|
+
|
|
235
|
+
**Refactoring:** [what was changed]
|
|
236
|
+
**Quality Improvement:** [evaluator scores]
|
|
237
|
+
**Issues Encountered:** [if any]
|
|
238
|
+
|
|
239
|
+
Analyze:
|
|
240
|
+
- What refactoring patterns were effective?
|
|
241
|
+
- What should be refactored next?
|
|
242
|
+
- What made this refactoring safe/risky?
|
|
243
|
+
- How could we prevent the need for such refactoring?
|
|
244
|
+
|
|
245
|
+
Output JSON with refactoring insights."
|
|
246
|
+
)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Update Playbook
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
Task(
|
|
253
|
+
subagent_type="curator",
|
|
254
|
+
description="Store refactoring patterns",
|
|
255
|
+
prompt="Store refactoring patterns in playbook:
|
|
256
|
+
|
|
257
|
+
**Reflector Insights:** [paste JSON]
|
|
258
|
+
|
|
259
|
+
Focus on:
|
|
260
|
+
- Safe refactoring techniques
|
|
261
|
+
- Risk mitigation strategies
|
|
262
|
+
- Quality improvement patterns
|
|
263
|
+
|
|
264
|
+
Output curator operations."
|
|
265
|
+
)
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Step 4: Final Verification
|
|
269
|
+
|
|
270
|
+
After all refactoring steps complete:
|
|
271
|
+
|
|
272
|
+
1. **Run complete test suite** (all tests must pass!)
|
|
273
|
+
2. **Compare before/after behavior** (should be identical)
|
|
274
|
+
3. **Check performance** (should not degrade)
|
|
275
|
+
4. **Verify all usages** (nothing should break)
|
|
276
|
+
5. **Create detailed commit** explaining what was refactored and why
|
|
277
|
+
|
|
278
|
+
## Step 5: Store Refactoring Pattern
|
|
279
|
+
|
|
280
|
+
```
|
|
281
|
+
mcp__cipher__cipher_extract_and_operate_memory({
|
|
282
|
+
"interaction": "Refactored [component]. Approach: [summary]. Quality improvement: [scores]. Lessons: [key insights]."
|
|
283
|
+
})
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## MCP Tools for Refactoring
|
|
287
|
+
|
|
288
|
+
- `mcp__cipher__cipher_memory_search` - Find successful refactoring patterns
|
|
289
|
+
- `mcp__sequential-thinking__sequentialthinking` - Plan complex refactorings
|
|
290
|
+
- `mcp__deepwiki__ask_question` - See how others refactored similar code
|
|
291
|
+
|
|
292
|
+
## Critical Constraints for Refactoring
|
|
293
|
+
|
|
294
|
+
- **ALWAYS run predictor FIRST** before any changes
|
|
295
|
+
- **NEVER change behavior** - only structure
|
|
296
|
+
- **ALWAYS run ALL tests** after each step
|
|
297
|
+
- **NEVER skip backward compatibility** checks
|
|
298
|
+
- **ALWAYS have rollback plan** for each step
|
|
299
|
+
- **Use Task tool** to call all subagents
|
|
300
|
+
|
|
301
|
+
## Example
|
|
302
|
+
|
|
303
|
+
User says: `/map-refactor extract authentication logic into separate module`
|
|
304
|
+
|
|
305
|
+
You should:
|
|
306
|
+
1. Task(subagent_type="predictor") β analyze all dependencies FIRST
|
|
307
|
+
2. Task(subagent_type="task-decomposer") β break into safe steps
|
|
308
|
+
3. For each step:
|
|
309
|
+
- actor β refactor code
|
|
310
|
+
- monitor β verify no behavior changes
|
|
311
|
+
- predictor β verify no breaking changes
|
|
312
|
+
- evaluator β assess quality improvement
|
|
313
|
+
- Apply changes and **run tests**
|
|
314
|
+
4. Reflect + curate refactoring patterns
|
|
315
|
+
5. Final verification (all tests pass, behavior unchanged)
|
|
316
|
+
|
|
317
|
+
Begin refactoring now.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Comprehensive MAP review of changes
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
**π¨ ABSOLUTELY FORBIDDEN π¨**
|
|
6
|
+
|
|
7
|
+
You are **STRICTLY PROHIBITED** from:
|
|
8
|
+
|
|
9
|
+
β **"Optimizing" the workflow due to token limits** - Token constraints are NOT a valid reason to skip agents
|
|
10
|
+
β **"Combining steps to save time"** - Each agent MUST be called individually
|
|
11
|
+
β **"Doing Reflector/Curator work manually"** - This breaks cipher integration
|
|
12
|
+
β **"Creating a comprehensive document instead"** - This is NOT the MAP workflow
|
|
13
|
+
β **"Skipping reflection for simple tasks"** - EVERY subtask requires Reflector + Curator
|
|
14
|
+
β **Any variation of "I'll optimize by..."** - NO OPTIMIZATION ALLOWED
|
|
15
|
+
|
|
16
|
+
**IF YOU VIOLATE THESE RULES:**
|
|
17
|
+
- cipher_memory_search won't be called β duplicate knowledge
|
|
18
|
+
- cipher_extract_and_operate_memory won't be called β knowledge won't be shared
|
|
19
|
+
- The ENTIRE PURPOSE of MAP Framework will be defeated
|
|
20
|
+
|
|
21
|
+
**YOU MUST:**
|
|
22
|
+
β
Call EVERY agent in sequence for EVERY subtask
|
|
23
|
+
β
Verify each agent used required MCP tools (check output)
|
|
24
|
+
β
Complete the FULL workflow even if it takes 100K+ tokens
|
|
25
|
+
β
Ask user to continue if you hit token limit, but NEVER skip agents
|
|
26
|
+
|
|
27
|
+
Use monitor, predictor, and evaluator agents to review current changes.
|
|
28
|
+
|
|
29
|
+
Provide detailed analysis of code quality, potential impacts, and quality scores.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# MAP Framework - Claude Code Hooks
|
|
2
|
+
|
|
3
|
+
This directory contains Claude Code hooks for the MAP Framework.
|
|
4
|
+
|
|
5
|
+
## Active Hooks
|
|
6
|
+
|
|
7
|
+
### PreToolUse - Template Variable Validation
|
|
8
|
+
|
|
9
|
+
**Hook**: `validate-agent-templates.sh`
|
|
10
|
+
**Triggers**: Before `Edit` or `Write` operations on `.claude/agents/*.md` files
|
|
11
|
+
**Purpose**: Prevents accidental removal of critical template variables
|
|
12
|
+
|
|
13
|
+
**Template Variables Protected**:
|
|
14
|
+
- `{{language}}` - Programming language context
|
|
15
|
+
- `{{project_name}}` - Project name
|
|
16
|
+
- `{{framework}}` - Framework context
|
|
17
|
+
- `{{#if playbook_bullets}}` - ACE learning system
|
|
18
|
+
- `{{#if feedback}}` - MonitorβActor retry loops
|
|
19
|
+
- `{{subtask_description}}` - Task specification
|
|
20
|
+
|
|
21
|
+
**How It Works**:
|
|
22
|
+
1. Detects when agent files are being modified
|
|
23
|
+
2. Checks staged content for required template variables
|
|
24
|
+
3. Blocks commit if variables are missing
|
|
25
|
+
4. Provides clear error message
|
|
26
|
+
|
|
27
|
+
**Override** (use carefully):
|
|
28
|
+
```bash
|
|
29
|
+
git commit --no-verify
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Removed Hooks
|
|
33
|
+
|
|
34
|
+
The following hooks were removed because **bash hooks cannot call MCP tools**:
|
|
35
|
+
|
|
36
|
+
- β `auto-store-knowledge.sh` (PostToolUse) - Tried to call cipher MCP
|
|
37
|
+
- β `enrich-context.sh` (UserPromptSubmit) - Tried to search cipher MCP
|
|
38
|
+
- β `session-init.sh` (SessionStart) - Tried to load from cipher MCP
|
|
39
|
+
- β `track-metrics.sh` (SubagentStop) - Tried to store metrics in cipher MCP
|
|
40
|
+
|
|
41
|
+
**Why Removed**: Bash hooks execute outside Claude Code's context and cannot invoke MCP tools.
|
|
42
|
+
|
|
43
|
+
**Alternative**: Call MCP tools directly within agent prompts or slash commands.
|
|
44
|
+
|
|
45
|
+
## Best Practices
|
|
46
|
+
|
|
47
|
+
**DO Use Hooks For**:
|
|
48
|
+
- β
File validation (grep, regex)
|
|
49
|
+
- β
Git operations (status, diff)
|
|
50
|
+
- β
Static analysis (linters)
|
|
51
|
+
|
|
52
|
+
**DON'T Use Hooks For**:
|
|
53
|
+
- β MCP tool calls
|
|
54
|
+
- β Interactive prompts
|
|
55
|
+
- β Long operations (>10s timeout)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Claude Code PreToolUse hook: Validate agent template integrity
|
|
3
|
+
# Prevents accidental removal of critical Handlebars template variables
|
|
4
|
+
#
|
|
5
|
+
# Input: JSON via stdin with tool parameters
|
|
6
|
+
# Output: JSON with decision (block/allow) and optional message
|
|
7
|
+
# Exit code: 0 = allow, 1 = block
|
|
8
|
+
|
|
9
|
+
set -euo pipefail
|
|
10
|
+
|
|
11
|
+
# Read JSON input from Claude Code
|
|
12
|
+
INPUT=$(cat)
|
|
13
|
+
|
|
14
|
+
# Extract tool name and file path from JSON
|
|
15
|
+
TOOL=$(echo "$INPUT" | jq -r '.tool // empty')
|
|
16
|
+
FILE_PATH=$(echo "$INPUT" | jq -r '.parameters.file_path // empty')
|
|
17
|
+
|
|
18
|
+
# Only validate agent files
|
|
19
|
+
if [[ ! "$FILE_PATH" =~ \.claude/agents/.*\.md$ ]]; then
|
|
20
|
+
# Not an agent file - allow
|
|
21
|
+
echo '{"decision": "allow"}'
|
|
22
|
+
exit 0
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
# Get the new content that will be written
|
|
26
|
+
NEW_CONTENT=$(echo "$INPUT" | jq -r '.parameters.content // .parameters.new_string // empty')
|
|
27
|
+
|
|
28
|
+
if [ -z "$NEW_CONTENT" ]; then
|
|
29
|
+
# No content to validate - allow (might be a read operation)
|
|
30
|
+
echo '{"decision": "allow"}'
|
|
31
|
+
exit 0
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
# Critical patterns that MUST exist in agent files
|
|
35
|
+
REQUIRED_PATTERNS=(
|
|
36
|
+
"{{language}}"
|
|
37
|
+
"{{project_name}}"
|
|
38
|
+
"{{#if playbook_bullets}}"
|
|
39
|
+
"{{#if feedback}}"
|
|
40
|
+
"{{subtask_description}}"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
MISSING_PATTERNS=()
|
|
44
|
+
|
|
45
|
+
for pattern in "${REQUIRED_PATTERNS[@]}"; do
|
|
46
|
+
if ! echo "$NEW_CONTENT" | grep -qF "$pattern"; then
|
|
47
|
+
MISSING_PATTERNS+=("$pattern")
|
|
48
|
+
fi
|
|
49
|
+
done
|
|
50
|
+
|
|
51
|
+
if [ ${#MISSING_PATTERNS[@]} -gt 0 ]; then
|
|
52
|
+
# Build error message
|
|
53
|
+
MESSAGE="β BLOCKED: Agent file is missing critical template variables!\\n\\n"
|
|
54
|
+
MESSAGE+="File: $FILE_PATH\\n"
|
|
55
|
+
MESSAGE+="Missing templates:\\n"
|
|
56
|
+
for pattern in "${MISSING_PATTERNS[@]}"; do
|
|
57
|
+
MESSAGE+=" - $pattern\\n"
|
|
58
|
+
done
|
|
59
|
+
MESSAGE+="\\nThese template variables are NOT optional - they're used by Orchestrator:\\n"
|
|
60
|
+
MESSAGE+=" β’ {{language}}, {{project_name}} - Context injection\\n"
|
|
61
|
+
MESSAGE+=" β’ {{#if playbook_bullets}} - ACE learning system\\n"
|
|
62
|
+
MESSAGE+=" β’ {{#if feedback}} - MonitorβActor retry loops\\n"
|
|
63
|
+
MESSAGE+=" β’ {{subtask_description}} - Task specification\\n"
|
|
64
|
+
MESSAGE+="\\nSee .claude/agents/README.md for details.\\n"
|
|
65
|
+
MESSAGE+="\\nTo bypass this check (NOT recommended):\\n"
|
|
66
|
+
MESSAGE+=" Disable the PreToolUse hook in .claude/settings.hooks.json"
|
|
67
|
+
|
|
68
|
+
# Return blocking decision with message
|
|
69
|
+
echo "{\"decision\": \"block\", \"message\": \"$MESSAGE\"}"
|
|
70
|
+
exit 1
|
|
71
|
+
fi
|
|
72
|
+
|
|
73
|
+
# Check for massive deletions
|
|
74
|
+
if [ -f "$FILE_PATH" ]; then
|
|
75
|
+
OLD_CONTENT=$(cat "$FILE_PATH")
|
|
76
|
+
OLD_LINES=$(echo "$OLD_CONTENT" | wc -l)
|
|
77
|
+
NEW_LINES=$(echo "$NEW_CONTENT" | wc -l)
|
|
78
|
+
LINES_REMOVED=$((OLD_LINES - NEW_LINES))
|
|
79
|
+
|
|
80
|
+
if [ $LINES_REMOVED -gt 500 ]; then
|
|
81
|
+
# Warn about massive deletions but allow (might be intentional refactoring)
|
|
82
|
+
MESSAGE="β οΈ WARNING: $FILE_PATH has $LINES_REMOVED lines removed (>500)\\n"
|
|
83
|
+
MESSAGE+="\\nAre you sure you want to remove significant content from this agent?\\n"
|
|
84
|
+
MESSAGE+="This might include critical Handlebars templates or instructions.\\n"
|
|
85
|
+
MESSAGE+="\\nIf this is intentional, proceed. Otherwise, review the changes carefully."
|
|
86
|
+
|
|
87
|
+
echo "{\"decision\": \"allow\", \"message\": \"$MESSAGE\"}"
|
|
88
|
+
exit 0
|
|
89
|
+
fi
|
|
90
|
+
fi
|
|
91
|
+
|
|
92
|
+
# All checks passed - allow the operation
|
|
93
|
+
echo '{"decision": "allow"}'
|
|
94
|
+
exit 0
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://cdn.jsdelivr.net/npm/@anthropic-ai/claude-code@latest/schemas/settings.schema.json",
|
|
3
|
+
"description": "Claude Code hooks configuration for MAP Framework - Template validation only",
|
|
4
|
+
"hooks": {
|
|
5
|
+
"PreToolUse": [
|
|
6
|
+
{
|
|
7
|
+
"matcher": "Edit|Write",
|
|
8
|
+
"description": "Validate agent template integrity before modifications",
|
|
9
|
+
"hooks": [
|
|
10
|
+
{
|
|
11
|
+
"type": "command",
|
|
12
|
+
"command": ".claude/hooks/validate-agent-templates.sh",
|
|
13
|
+
"timeout": 5,
|
|
14
|
+
"description": "Prevents accidental removal of {{template}} variables from agents"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
}
|