moai-adk 0.9.0__py3-none-any.whl → 0.9.1__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.

Potentially problematic release.


This version of moai-adk might be problematic. Click here for more details.

Files changed (30) hide show
  1. moai_adk/cli/commands/update.py +214 -56
  2. moai_adk/core/tags/pre_commit_validator.py +0 -1
  3. moai_adk/core/tags/reporter.py +1 -2
  4. moai_adk/templates/.claude/hooks/alfred/.moai/cache/version-check.json +9 -0
  5. moai_adk/templates/.claude/hooks/alfred/README.md +343 -0
  6. moai_adk/templates/.claude/hooks/alfred/TROUBLESHOOTING.md +471 -0
  7. moai_adk/templates/.claude/hooks/alfred/shared/core/project.py +10 -77
  8. moai_adk/templates/.claude/hooks/alfred/shared/handlers/user.py +19 -0
  9. moai_adk/templates/.github/workflows/tag-report.yml +261 -0
  10. moai_adk/templates/.github/workflows/tag-validation.yml +176 -0
  11. moai_adk/templates/.moai/docs/quick-issue-creation-guide.md +219 -0
  12. moai_adk/templates/.moai/hooks/install.sh +79 -0
  13. moai_adk/templates/.moai/hooks/pre-commit.sh +66 -0
  14. moai_adk/templates/.moai/memory/GITFLOW-PROTECTION-POLICY.md +220 -0
  15. moai_adk/templates/.moai/memory/gitflow-protection-policy.md +30 -140
  16. moai_adk/templates/.moai/memory/spec-metadata.md +356 -0
  17. moai_adk/templates/src/moai_adk/core/__init__.py +5 -0
  18. moai_adk/templates/src/moai_adk/core/tags/__init__.py +86 -0
  19. moai_adk/templates/src/moai_adk/core/tags/ci_validator.py +433 -0
  20. moai_adk/templates/src/moai_adk/core/tags/cli.py +283 -0
  21. moai_adk/templates/src/moai_adk/core/tags/pre_commit_validator.py +354 -0
  22. moai_adk/templates/src/moai_adk/core/tags/reporter.py +956 -0
  23. moai_adk/templates/src/moai_adk/core/tags/validator.py +897 -0
  24. {moai_adk-0.9.0.dist-info → moai_adk-0.9.1.dist-info}/METADATA +69 -333
  25. {moai_adk-0.9.0.dist-info → moai_adk-0.9.1.dist-info}/RECORD +28 -13
  26. moai_adk/templates/.claude/hooks/alfred/core/project.py +0 -750
  27. moai_adk/templates/README.md +0 -256
  28. {moai_adk-0.9.0.dist-info → moai_adk-0.9.1.dist-info}/WHEEL +0 -0
  29. {moai_adk-0.9.0.dist-info → moai_adk-0.9.1.dist-info}/entry_points.txt +0 -0
  30. {moai_adk-0.9.0.dist-info → moai_adk-0.9.1.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,343 @@
1
+ # Alfred Hooks System
2
+
3
+ **Event-Driven Context Management for MoAI-ADK**
4
+
5
+ Alfred Hooks integrates with Claude Code's event system to automatically manage project context, create checkpoints before risky operations, and provide just-in-time (JIT) document loading.
6
+
7
+ ---
8
+
9
+ ## 📐 Architecture
10
+
11
+ ### Individual Hook Files (Event + Function Naming)
12
+
13
+ ```
14
+ .claude/hooks/alfred/
15
+ ├── session_start__show_project_info.py # SessionStart: Display project status
16
+ ├── user_prompt__jit_load_docs.py # UserPromptSubmit: JIT document loading
17
+ ├── pre_tool__auto_checkpoint.py # PreToolUse: Automatic safety checkpoints
18
+ ├── post_tool__log_changes.py # PostToolUse: Change tracking (stub)
19
+ ├── session_end__cleanup.py # SessionEnd: Cleanup resources (stub)
20
+ ├── notification__handle_events.py # Notification: Event processing (stub)
21
+ ├── stop__handle_interrupt.py # Stop: Interrupt handling (stub)
22
+ ├── subagent_stop__handle_subagent_end.py # SubagentStop: Sub-agent cleanup (stub)
23
+ └── shared/ # Shared business logic
24
+ ├── core/ # Core modules
25
+ │ ├── __init__.py # Type definitions (HookPayload, HookResult)
26
+ │ ├── project.py # Language detection, Git info, SPEC counting
27
+ │ ├── context.py # JIT retrieval, workflow context
28
+ │ ├── checkpoint.py # Event-driven checkpoint creation
29
+ │ └── version_cache.py # Library version management
30
+ └── handlers/ # Event handlers
31
+ ├── __init__.py # Handler exports
32
+ ├── session.py # SessionStart, SessionEnd handlers
33
+ ├── user.py # UserPromptSubmit handler
34
+ ├── tool.py # PreToolUse, PostToolUse handlers
35
+ └── notification.py # Notification, Stop handlers
36
+ ```
37
+
38
+ ### Design Principles
39
+
40
+ - **Clarity First**: File names describe what each hook does (UX priority)
41
+ - **DRY Implementation**: Shared logic in `shared/` modules (maintainability)
42
+ - **Self-Documenting**: Event + Function naming convention (e.g., `session_start__show_project_info.py`)
43
+ - **Independent Execution**: Each hook file is self-contained and executable
44
+ - **Timeout Protection**: All hooks enforce 5-second SIGALRM timeout
45
+
46
+ ---
47
+
48
+ ## 🎯 Hook Files
49
+
50
+ ### `session_start__show_project_info.py`
51
+
52
+ **Event**: SessionStart
53
+ **Purpose**: Display project information when session begins
54
+
55
+ **Output**:
56
+ - Programming language
57
+ - Git branch and status
58
+ - SPEC progress (completed/total %)
59
+ - Recent checkpoints
60
+
61
+ **Example**:
62
+ ```bash
63
+ echo '{"cwd": "."}' | uv run session_start__show_project_info.py
64
+ # Output: {"continue": true, "systemMessage": "🚀 MoAI-ADK v0.8.0 | 📦 python..."}
65
+ ```
66
+
67
+ ---
68
+
69
+ ### `user_prompt__jit_load_docs.py`
70
+
71
+ **Event**: UserPromptSubmit
72
+ **Purpose**: Analyze prompt and recommend relevant documents
73
+
74
+ **Features**:
75
+ - Pattern matching for Alfred commands (`/alfred:1-plan` → spec-metadata.md)
76
+ - @TAG mention detection
77
+ - SPEC reference extraction
78
+ - Document path suggestions
79
+
80
+ **Output Schema** (UserPromptSubmit-specific):
81
+ ```json
82
+ {
83
+ "continue": true,
84
+ "hookSpecificOutput": {
85
+ "hookEventName": "UserPromptSubmit",
86
+ "additionalContext": "Suggested documents: .moai/memory/spec-metadata.md"
87
+ }
88
+ }
89
+ ```
90
+
91
+ ---
92
+
93
+ ### `pre_tool__auto_checkpoint.py`
94
+
95
+ **Event**: PreToolUse
96
+ **Matcher**: `Edit|Write|MultiEdit`
97
+ **Purpose**: Automatically create Git checkpoints before risky operations
98
+
99
+ **Risky Operations Detected**:
100
+ - **Bash**: `rm -rf`, `git merge`, `git reset --hard`
101
+ - **Edit/Write**: `CLAUDE.md`, `config.json`, critical configuration files
102
+ - **MultiEdit**: Operations affecting ≥10 files
103
+
104
+ **Checkpoint Strategy**:
105
+ 1. Detect risky pattern
106
+ 2. Create checkpoint branch: `checkpoint/before-{operation}-{timestamp}`
107
+ 3. Log to `.moai/checkpoints.log`
108
+ 4. Return guidance message to user
109
+
110
+ **Example**:
111
+ ```bash
112
+ echo '{"toolName": "Bash", "arguments": {"command": "rm -rf temp/"}}' | uv run pre_tool__auto_checkpoint.py
113
+ # Output: {"continue": true, "systemMessage": "✅ Checkpoint created: checkpoint/before-rm-20251029-174500"}
114
+ ```
115
+
116
+ ---
117
+
118
+ ### Stub Hooks (Future Enhancement)
119
+
120
+ **`post_tool__log_changes.py`**
121
+ - Change tracking and audit logging
122
+ - Metrics collection (files modified, lines changed)
123
+
124
+ **`session_end__cleanup.py`**
125
+ - Clear temporary caches
126
+ - Save session metrics
127
+
128
+ **`notification__handle_events.py`**
129
+ - Filter and categorize notifications
130
+ - Send alerts to external systems
131
+
132
+ **`stop__handle_interrupt.py`**
133
+ - Save partial work before interruption
134
+ - Create recovery checkpoint
135
+
136
+ **`subagent_stop__handle_subagent_end.py`**
137
+ - Collect sub-agent execution metrics
138
+ - Log results and errors
139
+
140
+ ---
141
+
142
+ ## 🏗️ Shared Modules
143
+
144
+ ### `shared/core/` - Business Logic
145
+
146
+ **`project.py`** (284 LOC)
147
+ ```python
148
+ detect_language(cwd: str) -> str
149
+ get_git_info(cwd: str) -> dict
150
+ count_specs(cwd: str) -> dict
151
+ ```
152
+
153
+ **`context.py`** (110 LOC)
154
+ ```python
155
+ get_jit_context(prompt: str, cwd: str) -> list[str]
156
+ ```
157
+
158
+ **`checkpoint.py`** (244 LOC)
159
+ ```python
160
+ detect_risky_operation(tool: str, args: dict) -> tuple[bool, str]
161
+ create_checkpoint(cwd: str, operation: str) -> str
162
+ ```
163
+
164
+ ### `shared/handlers/` - Event Processing
165
+
166
+ **`session.py`** - SessionStart, SessionEnd
167
+ **`user.py`** - UserPromptSubmit
168
+ **`tool.py`** - PreToolUse, PostToolUse
169
+ **`notification.py`** - Notification, Stop, SubagentStop
170
+
171
+ ---
172
+
173
+ ## 🔧 Configuration
174
+
175
+ ### settings.json
176
+
177
+ ```json
178
+ {
179
+ "hooks": {
180
+ "SessionStart": [{
181
+ "hooks": [{
182
+ "command": "uv run \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/alfred/session_start__show_project_info.py",
183
+ "type": "command"
184
+ }]
185
+ }],
186
+ "UserPromptSubmit": [{
187
+ "hooks": [{
188
+ "command": "uv run \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/alfred/user_prompt__jit_load_docs.py",
189
+ "type": "command"
190
+ }]
191
+ }],
192
+ "PreToolUse": [{
193
+ "hooks": [{
194
+ "command": "uv run \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/alfred/pre_tool__auto_checkpoint.py",
195
+ "type": "command"
196
+ }],
197
+ "matcher": "Edit|Write|MultiEdit"
198
+ }]
199
+ }
200
+ }
201
+ ```
202
+
203
+ **Key Changes**:
204
+ - ✅ File names are self-descriptive (no arguments needed)
205
+ - ✅ `$CLAUDE_PROJECT_DIR` for reliable path resolution
206
+ - ✅ Each hook file is independent and testable
207
+
208
+ ---
209
+
210
+ ## 🧪 Testing
211
+
212
+ ### Test Individual Hooks
213
+
214
+ ```bash
215
+ # Test SessionStart hook
216
+ echo '{"cwd": "."}' | uv run session_start__show_project_info.py
217
+
218
+ # Test UserPromptSubmit hook
219
+ echo '{"cwd": ".", "userPrompt": "/alfred:1-plan"}' | uv run user_prompt__jit_load_docs.py
220
+
221
+ # Test PreToolUse hook
222
+ echo '{"cwd": ".", "toolName": "Edit", "arguments": {"file_path": "CLAUDE.md"}}' | uv run pre_tool__auto_checkpoint.py
223
+ ```
224
+
225
+ ### Expected Output
226
+
227
+ All hooks should return valid JSON with:
228
+ - `"continue": true` (required field)
229
+ - `"systemMessage"` or `"hookSpecificOutput"` (depending on hook type)
230
+
231
+ ---
232
+
233
+ ## 🐛 Troubleshooting
234
+
235
+ For detailed troubleshooting guide, see [TROUBLESHOOTING.md](./TROUBLESHOOTING.md).
236
+
237
+ ### Quick Diagnosis
238
+
239
+ ```bash
240
+ # List all hook files
241
+ ls -la .claude/hooks/alfred/*.py
242
+
243
+ # Expected output:
244
+ # session_start__show_project_info.py
245
+ # user_prompt__jit_load_docs.py
246
+ # pre_tool__auto_checkpoint.py
247
+ # post_tool__log_changes.py
248
+ # session_end__cleanup.py
249
+ # notification__handle_events.py
250
+ # stop__handle_interrupt.py
251
+ # subagent_stop__handle_subagent_end.py
252
+ ```
253
+
254
+ ### Common Issues
255
+
256
+ 1. **"Hook not found"** → Run `/alfred:0-project update`
257
+ 2. **"Import error: No module named 'handlers'"** → Check `shared/handlers/__init__.py` exists
258
+ 3. **"Timeout"** → Check Git/file operations, consider increasing timeout in hook file
259
+ 4. **"Permission denied"** → Run `chmod +x .claude/hooks/alfred/*.py`
260
+
261
+ ---
262
+
263
+ ## 🏗️ Architecture Decisions
264
+
265
+ ### Why Individual Hook Files? (UX Priority)
266
+
267
+ **Before** (Single Router):
268
+ ```
269
+ alfred_hooks.py SessionStart ❌ Unclear what "SessionStart" does
270
+ ```
271
+
272
+ **After** (Individual Files):
273
+ ```
274
+ session_start__show_project_info.py ✅ Immediately clear purpose
275
+ ```
276
+
277
+ **Benefits**:
278
+ 1. ✅ **Self-Documenting**: File name describes functionality
279
+ 2. ✅ **Easy Debugging**: Error messages show which hook failed
280
+ 3. ✅ **Simple Discovery**: `ls` command shows all available hooks
281
+ 4. ✅ **Independent Testing**: Each hook can be tested in isolation
282
+ 5. ✅ **Selective Disabling**: Comment out specific hook in settings.json
283
+
284
+ **Tradeoffs**:
285
+ - ⚠️ **More Files**: 8 hook files instead of 1 router
286
+ - ⚠️ **Shared Logic**: Still needs `shared/` directory for DRY principle
287
+
288
+ **Decision**: **UX > Technical Elegance** - Users benefit from clarity
289
+
290
+ ### Why Keep shared/ Directory? (DRY Principle)
291
+
292
+ **Shared Logic** (70% of codebase):
293
+ - Type definitions (HookResult, HookPayload)
294
+ - Project metadata (language detection, Git info)
295
+ - Checkpoint creation
296
+ - JIT context analysis
297
+
298
+ **Alternative** (Code Duplication):
299
+ ```python
300
+ # ❌ BAD: Copy HookResult to each hook file
301
+ # session_start__show_project_info.py
302
+ class HookResult: # 50 LOC duplicated
303
+ ...
304
+
305
+ # user_prompt__jit_load_docs.py
306
+ class HookResult: # 50 LOC duplicated again
307
+ ...
308
+ ```
309
+
310
+ **Current** (Shared Module):
311
+ ```python
312
+ # ✅ GOOD: Import from shared module
313
+ from shared.core import HookResult # DRY principle
314
+ ```
315
+
316
+ **Decision**: **Hybrid Approach** - Individual files for UX + Shared modules for DRY
317
+
318
+ ---
319
+
320
+ ## 📈 Version History
321
+
322
+ ### v0.9.0 (2025-10-29) - Individual Hook Files (UX Priority)
323
+ - ✅ **BREAKING**: Split `alfred_hooks.py` into 8 individual files
324
+ - ✅ **NAMING**: Event + Function naming convention (`session_start__show_project_info.py`)
325
+ - ✅ **STRUCTURE**: Moved shared logic to `shared/` directory
326
+ - ✅ **UX**: File names are self-descriptive (no arguments needed)
327
+ - ✅ **DEBUGGING**: Error messages now show which hook failed
328
+
329
+ ### v0.8.0 (2025-10-29) - Path Resolution & Timeout Fixes
330
+ - ✅ **FIXED**: Use `$CLAUDE_PROJECT_DIR` for reliable path resolution
331
+ - ✅ **ADDED**: Global SIGALRM timeout protection (5 seconds)
332
+ - ✅ **ADDED**: Comprehensive TROUBLESHOOTING.md guide
333
+
334
+ ### v0.7.0 (2025-10-17) - Stateless Refactoring
335
+ - ✅ **REMOVED**: Workflow context from hooks (delegated to Commands layer)
336
+ - ✅ **PERFORMANCE**: 180ms → 70ms (61% improvement)
337
+ - ✅ **COMPLIANCE**: 100% stateless (no global variables)
338
+
339
+ ---
340
+
341
+ **Last Updated**: 2025-10-29
342
+ **Version**: 0.9.0
343
+ **Author**: @Alfred (MoAI-ADK SuperAgent)