moai-adk 0.4.0__py3-none-any.whl โ 0.4.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.
- moai_adk/__init__.py +1 -8
- moai_adk/cli/commands/init.py +10 -5
- moai_adk/cli/commands/update.py +274 -118
- moai_adk/cli/prompts/init_prompts.py +14 -18
- moai_adk/core/diagnostics/slash_commands.py +1 -1
- moai_adk/core/project/backup_utils.py +1 -0
- moai_adk/core/project/phase_executor.py +3 -1
- moai_adk/core/project/validator.py +3 -2
- moai_adk/core/template/backup.py +11 -3
- moai_adk/core/template/merger.py +16 -3
- moai_adk/core/template/processor.py +22 -3
- moai_adk/templates/.claude/agents/alfred/cc-manager.md +443 -424
- moai_adk/templates/.claude/agents/alfred/debug-helper.md +116 -103
- moai_adk/templates/.claude/agents/alfred/doc-syncer.md +130 -116
- moai_adk/templates/.claude/agents/alfred/git-manager.md +186 -174
- moai_adk/templates/.claude/agents/alfred/implementation-planner.md +227 -213
- moai_adk/templates/.claude/agents/alfred/project-manager.md +205 -125
- moai_adk/templates/.claude/agents/alfred/quality-gate.md +224 -209
- moai_adk/templates/.claude/agents/alfred/spec-builder.md +174 -160
- moai_adk/templates/.claude/agents/alfred/tag-agent.md +151 -139
- moai_adk/templates/.claude/agents/alfred/tdd-implementer.md +209 -196
- moai_adk/templates/.claude/agents/alfred/trust-checker.md +247 -233
- moai_adk/templates/.claude/commands/alfred/0-project.md +673 -640
- moai_adk/templates/.claude/commands/alfred/1-plan.md +342 -333
- moai_adk/templates/.claude/commands/alfred/2-run.md +295 -285
- moai_adk/templates/.claude/commands/alfred/3-sync.md +366 -356
- moai_adk/templates/.claude/hooks/alfred/README.md +52 -52
- moai_adk/templates/.claude/hooks/alfred/alfred_hooks.py +44 -48
- moai_adk/templates/.claude/hooks/alfred/core/__init__.py +17 -17
- moai_adk/templates/.claude/hooks/alfred/core/checkpoint.py +59 -59
- moai_adk/templates/.claude/hooks/alfred/core/context.py +19 -19
- moai_adk/templates/.claude/hooks/alfred/core/project.py +52 -52
- moai_adk/templates/.claude/hooks/alfred/handlers/__init__.py +1 -1
- moai_adk/templates/.claude/hooks/alfred/handlers/notification.py +4 -4
- moai_adk/templates/.claude/hooks/alfred/handlers/session.py +27 -27
- moai_adk/templates/.claude/hooks/alfred/handlers/tool.py +16 -17
- moai_adk/templates/.claude/hooks/alfred/handlers/user.py +11 -11
- moai_adk/templates/.claude/output-styles/alfred/agentic-coding.md +308 -307
- moai_adk/templates/.claude/output-styles/alfred/moai-adk-learning.md +297 -296
- moai_adk/templates/.claude/output-styles/alfred/study-with-alfred.md +191 -190
- moai_adk/templates/.claude/skills/moai-alfred-code-reviewer/SKILL.md +112 -0
- moai_adk/templates/.claude/skills/moai-alfred-debugger-pro/SKILL.md +103 -0
- moai_adk/templates/.claude/skills/moai-alfred-ears-authoring/SKILL.md +103 -0
- moai_adk/templates/.claude/skills/moai-alfred-git-workflow/SKILL.md +95 -0
- moai_adk/templates/.claude/skills/moai-alfred-language-detection/SKILL.md +99 -0
- moai_adk/templates/.claude/skills/moai-alfred-performance-optimizer/SKILL.md +105 -0
- moai_adk/templates/.claude/skills/moai-alfred-refactoring-coach/SKILL.md +97 -0
- moai_adk/templates/.claude/skills/moai-alfred-spec-metadata-validation/SKILL.md +97 -0
- moai_adk/templates/.claude/skills/moai-alfred-tag-scanning/SKILL.md +90 -0
- moai_adk/templates/.claude/skills/moai-alfred-trust-validation/SKILL.md +99 -0
- moai_adk/templates/.claude/skills/moai-alfred-tui-survey/SKILL.md +87 -0
- moai_adk/templates/.claude/skills/moai-alfred-tui-survey/examples.md +62 -0
- moai_adk/templates/.claude/skills/moai-claude-code/SKILL.md +70 -43
- moai_adk/templates/.claude/skills/moai-claude-code/examples.md +141 -141
- moai_adk/templates/.claude/skills/moai-claude-code/reference.md +179 -165
- moai_adk/templates/.claude/skills/moai-claude-code/templates/agent-full.md +78 -78
- moai_adk/templates/.claude/skills/moai-claude-code/templates/command-full.md +90 -90
- moai_adk/templates/.claude/skills/moai-claude-code/templates/plugin-full.json +39 -25
- moai_adk/templates/.claude/skills/moai-claude-code/templates/settings-full.json +117 -74
- moai_adk/templates/.claude/skills/moai-claude-code/templates/skill-full.md +131 -134
- moai_adk/templates/.claude/skills/moai-domain-backend/SKILL.md +43 -12
- moai_adk/templates/.claude/skills/moai-domain-cli-tool/SKILL.md +43 -12
- moai_adk/templates/.claude/skills/moai-domain-data-science/SKILL.md +43 -12
- moai_adk/templates/.claude/skills/moai-domain-database/SKILL.md +43 -12
- moai_adk/templates/.claude/skills/moai-domain-devops/SKILL.md +43 -12
- moai_adk/templates/.claude/skills/moai-domain-frontend/SKILL.md +43 -12
- moai_adk/templates/.claude/skills/moai-domain-ml/SKILL.md +43 -11
- moai_adk/templates/.claude/skills/moai-domain-mobile-app/SKILL.md +43 -12
- moai_adk/templates/.claude/skills/moai-domain-security/SKILL.md +43 -12
- moai_adk/templates/.claude/skills/moai-domain-web-api/SKILL.md +43 -12
- moai_adk/templates/.claude/skills/moai-essentials-debug/SKILL.md +47 -11
- moai_adk/templates/.claude/skills/moai-essentials-perf/SKILL.md +47 -11
- moai_adk/templates/.claude/skills/moai-essentials-refactor/SKILL.md +51 -14
- moai_adk/templates/.claude/skills/moai-essentials-review/SKILL.md +46 -10
- moai_adk/templates/.claude/skills/moai-foundation-ears/SKILL.md +62 -25
- moai_adk/templates/.claude/skills/moai-foundation-git/SKILL.md +44 -17
- moai_adk/templates/.claude/skills/moai-foundation-langs/SKILL.md +44 -14
- moai_adk/templates/.claude/skills/moai-foundation-specs/SKILL.md +45 -13
- moai_adk/templates/.claude/skills/moai-foundation-tags/SKILL.md +46 -14
- moai_adk/templates/.claude/skills/moai-foundation-trust/SKILL.md +48 -8
- moai_adk/templates/.claude/skills/moai-lang-c/SKILL.md +44 -12
- moai_adk/templates/.claude/skills/moai-lang-clojure/SKILL.md +44 -12
- moai_adk/templates/.claude/skills/moai-lang-cpp/SKILL.md +44 -11
- moai_adk/templates/.claude/skills/moai-lang-csharp/SKILL.md +44 -11
- moai_adk/templates/.claude/skills/moai-lang-dart/SKILL.md +44 -12
- moai_adk/templates/.claude/skills/moai-lang-elixir/SKILL.md +44 -11
- moai_adk/templates/.claude/skills/moai-lang-go/SKILL.md +44 -11
- moai_adk/templates/.claude/skills/moai-lang-haskell/SKILL.md +44 -11
- moai_adk/templates/.claude/skills/moai-lang-java/SKILL.md +44 -12
- moai_adk/templates/.claude/skills/moai-lang-javascript/SKILL.md +44 -12
- moai_adk/templates/.claude/skills/moai-lang-julia/SKILL.md +44 -12
- moai_adk/templates/.claude/skills/moai-lang-kotlin/SKILL.md +44 -12
- moai_adk/templates/.claude/skills/moai-lang-lua/SKILL.md +44 -11
- moai_adk/templates/.claude/skills/moai-lang-php/SKILL.md +44 -11
- moai_adk/templates/.claude/skills/moai-lang-python/SKILL.md +44 -12
- moai_adk/templates/.claude/skills/moai-lang-r/SKILL.md +44 -11
- moai_adk/templates/.claude/skills/moai-lang-ruby/SKILL.md +44 -11
- moai_adk/templates/.claude/skills/moai-lang-rust/SKILL.md +44 -12
- moai_adk/templates/.claude/skills/moai-lang-scala/SKILL.md +44 -12
- moai_adk/templates/.claude/skills/moai-lang-shell/SKILL.md +44 -11
- moai_adk/templates/.claude/skills/moai-lang-sql/SKILL.md +44 -12
- moai_adk/templates/.claude/skills/moai-lang-swift/SKILL.md +44 -12
- moai_adk/templates/.claude/skills/moai-lang-typescript/SKILL.md +44 -12
- moai_adk/templates/.github/PULL_REQUEST_TEMPLATE.md +44 -43
- moai_adk/templates/.github/workflows/moai-gitflow.yml +36 -35
- moai_adk/templates/.moai/config.json +9 -6
- moai_adk/templates/.moai/memory/development-guide.md +220 -221
- moai_adk/templates/.moai/memory/gitflow-protection-policy.md +85 -85
- moai_adk/templates/.moai/memory/spec-metadata.md +149 -150
- moai_adk/templates/.moai/project/product.md +90 -90
- moai_adk/templates/.moai/project/structure.md +85 -85
- moai_adk/templates/.moai/project/tech.md +117 -117
- moai_adk/templates/CLAUDE.md +350 -722
- moai_adk-0.4.1.dist-info/METADATA +303 -0
- moai_adk-0.4.1.dist-info/RECORD +152 -0
- moai_adk/templates/.claude/commands/alfred/1-spec.md +0 -31
- moai_adk/templates/.claude/commands/alfred/2-build.md +0 -30
- moai_adk/templates/.claude/skills/scripts/standardize_skills.py +0 -166
- moai_adk/templates/.claude/skills/scripts/verify_standardization.sh +0 -43
- moai_adk/templates/.moai/hooks/pre-push.sample +0 -88
- moai_adk-0.4.0.dist-info/METADATA +0 -1816
- moai_adk-0.4.0.dist-info/RECORD +0 -145
- {moai_adk-0.4.0.dist-info โ moai_adk-0.4.1.dist-info}/WHEEL +0 -0
- {moai_adk-0.4.0.dist-info โ moai_adk-0.4.1.dist-info}/entry_points.txt +0 -0
- {moai_adk-0.4.0.dist-info โ moai_adk-0.4.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**Event-Driven Context Management for MoAI-ADK**
|
|
4
4
|
|
|
5
|
-
Alfred Hooks
|
|
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
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -29,10 +29,10 @@ Alfred Hooks๋ Claude Code์ ์ด๋ฒคํธ ์์คํ
๊ณผ ํตํฉ๋์ด ํ๋ก์ ํธ
|
|
|
29
29
|
|
|
30
30
|
### Design Principles
|
|
31
31
|
|
|
32
|
-
- **Single Responsibility**:
|
|
33
|
-
- **Separation of Concerns**: core (
|
|
34
|
-
- **CODE-FIRST**:
|
|
35
|
-
- **Context Engineering**:
|
|
32
|
+
- **Single Responsibility**: Each module has one clear responsibility
|
|
33
|
+
- **Separation of Concerns**: core (business logic) vs handlers (event processing)
|
|
34
|
+
- **CODE-FIRST**: Scan code directly without intermediate cache (mtime Based invalidation)
|
|
35
|
+
- **Context Engineering**: Minimize initial context burden with JIT Retrieval
|
|
36
36
|
|
|
37
37
|
---
|
|
38
38
|
|
|
@@ -40,7 +40,7 @@ Alfred Hooks๋ Claude Code์ ์ด๋ฒคํธ ์์คํ
๊ณผ ํตํฉ๋์ด ํ๋ก์ ํธ
|
|
|
40
40
|
|
|
41
41
|
### `core/project.py` (284 LOC)
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
**Project metadata and language detection**
|
|
44
44
|
|
|
45
45
|
```python
|
|
46
46
|
# Public API
|
|
@@ -51,14 +51,14 @@ count_specs(cwd: str) -> dict[str, int]
|
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
**Features**:
|
|
54
|
-
-
|
|
55
|
-
- `.moai/config.json`
|
|
56
|
-
- Git
|
|
57
|
-
- SPEC
|
|
54
|
+
- Automatic detection of 20 languages โโ(Python, TypeScript, Java, Go, Rust, etc.)
|
|
55
|
+
- `.moai/config.json` First, fallback to auto-detection
|
|
56
|
+
- Check Git information (branch, commit, changes)
|
|
57
|
+
- SPEC progress calculation (total, completed, percentage)
|
|
58
58
|
|
|
59
59
|
### `core/context.py` (110 LOC)
|
|
60
60
|
|
|
61
|
-
**JIT Context Retrieval
|
|
61
|
+
**JIT Context Retrieval and Workflow Management**
|
|
62
62
|
|
|
63
63
|
```python
|
|
64
64
|
# Public API
|
|
@@ -69,15 +69,15 @@ clear_workflow_context()
|
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
**Features**:
|
|
72
|
-
-
|
|
73
|
-
- `/alfred:1-
|
|
74
|
-
- `/alfred:2-
|
|
75
|
-
-
|
|
76
|
-
- Anthropic Context Engineering
|
|
72
|
+
- Automatically recommend documents based on prompt analysis
|
|
73
|
+
- `/alfred:1-plan` โ `spec-metadata.md`
|
|
74
|
+
- `/alfred:2-run` โ `development-guide.md`
|
|
75
|
+
- Context caching for each workflow step (TTL 10 minutes)
|
|
76
|
+
- Compliance with Anthropic Context Engineering principles
|
|
77
77
|
|
|
78
78
|
### `core/checkpoint.py` (244 LOC)
|
|
79
79
|
|
|
80
|
-
**Event-Driven Checkpoint
|
|
80
|
+
**Event-Driven Checkpoint Automation**
|
|
81
81
|
|
|
82
82
|
```python
|
|
83
83
|
# Public API
|
|
@@ -88,16 +88,16 @@ list_checkpoints(cwd: str, max_count: int = 10) -> list[dict]
|
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
**Features**:
|
|
91
|
-
-
|
|
91
|
+
- Automatic detection of dangerous tasks:
|
|
92
92
|
- Bash: `rm -rf`, `git merge`, `git reset --hard`
|
|
93
93
|
- Edit/Write: `CLAUDE.md`, `config.json`
|
|
94
94
|
- MultiEdit: โฅ10 files
|
|
95
|
-
- Git checkpoint
|
|
96
|
-
-
|
|
95
|
+
- Automatic creation of Git checkpoint: `checkpoint/before-{operation}-{timestamp}`
|
|
96
|
+
- Checkpoint history management and recovery guide
|
|
97
97
|
|
|
98
98
|
### `core/tags.py` (244 LOC)
|
|
99
99
|
|
|
100
|
-
**CODE-FIRST TAG
|
|
100
|
+
**CODE-FIRST TAG SYSTEM**
|
|
101
101
|
|
|
102
102
|
```python
|
|
103
103
|
# Public API
|
|
@@ -110,10 +110,10 @@ set_library_version(library: str, version: str)
|
|
|
110
110
|
```
|
|
111
111
|
|
|
112
112
|
**Features**:
|
|
113
|
-
- ripgrep
|
|
114
|
-
- mtime
|
|
115
|
-
- TAG
|
|
116
|
-
-
|
|
113
|
+
- ripgrep-based TAG search (parsing JSON output)
|
|
114
|
+
- mtime-based cache invalidation (CODE-FIRST guaranteed)
|
|
115
|
+
- TAG chain verification (@SPEC โ @TEST โ @CODE completeness check)
|
|
116
|
+
- Library version caching (TTL 24 hours)
|
|
117
117
|
|
|
118
118
|
---
|
|
119
119
|
|
|
@@ -121,32 +121,32 @@ set_library_version(library: str, version: str)
|
|
|
121
121
|
|
|
122
122
|
### `handlers/session.py`
|
|
123
123
|
|
|
124
|
-
**SessionStart, SessionEnd
|
|
124
|
+
**SessionStart, SessionEnd handlers**
|
|
125
125
|
|
|
126
|
-
- **SessionStart**:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
- **SessionEnd**:
|
|
126
|
+
- **SessionStart**: Display project information
|
|
127
|
+
- Language, Git status, SPEC progress, recent checkpoint
|
|
128
|
+
- Display directly to user with `systemMessage` field
|
|
129
|
+
- **SessionEnd**: Cleanup task (stub)
|
|
130
130
|
|
|
131
131
|
### `handlers/user.py`
|
|
132
132
|
|
|
133
|
-
**UserPromptSubmit
|
|
133
|
+
**UserPromptSubmit Handler**
|
|
134
134
|
|
|
135
|
-
- JIT Context
|
|
136
|
-
-
|
|
135
|
+
- Return list of JIT Context recommended documents
|
|
136
|
+
- Analyze user prompt patterns and load related documents
|
|
137
137
|
|
|
138
138
|
### `handlers/tool.py`
|
|
139
139
|
|
|
140
|
-
**PreToolUse, PostToolUse
|
|
140
|
+
**PreToolUse, PostToolUse handlers**
|
|
141
141
|
|
|
142
|
-
- **PreToolUse**:
|
|
143
|
-
- **PostToolUse**:
|
|
142
|
+
- **PreToolUse**: Automatic checkpoint creation when dangerous operation is detected
|
|
143
|
+
- **PostToolUse**: Post-processing operation (stub)
|
|
144
144
|
|
|
145
145
|
### `handlers/notification.py`
|
|
146
146
|
|
|
147
|
-
**Notification, Stop, SubagentStop
|
|
147
|
+
**Notification, Stop, SubagentStop handlers**
|
|
148
148
|
|
|
149
|
-
-
|
|
149
|
+
- Basic implementation (stub, can be expanded in the future)
|
|
150
150
|
|
|
151
151
|
---
|
|
152
152
|
|
|
@@ -166,9 +166,9 @@ uv run pytest tests/unit/test_alfred_hooks_core_project.py -v
|
|
|
166
166
|
|
|
167
167
|
### Test Coverage (18 tests)
|
|
168
168
|
|
|
169
|
-
- โ
**tags.py**: 7 tests (
|
|
170
|
-
- โ
**context.py**: 5 tests (JIT,
|
|
171
|
-
- โ
**project.py**: 6 tests (
|
|
169
|
+
- โ
**tags.py**: 7 tests (cache, TAG verification, version management)
|
|
170
|
+
- โ
**context.py**: 5 tests (JIT, workflow context)
|
|
171
|
+
- โ
**project.py**: 6 tests (language detection, Git, SPEC count)
|
|
172
172
|
|
|
173
173
|
### Test Structure
|
|
174
174
|
|
|
@@ -192,22 +192,22 @@ def _load_{module}_module(module_name: str):
|
|
|
192
192
|
|
|
193
193
|
- **1 file**: 1233 LOC
|
|
194
194
|
- **Issues**:
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
- All functions concentrated in one file
|
|
196
|
+
- Difficult to test, complex to maintain
|
|
197
|
+
- Unclear separation of responsibilities
|
|
198
198
|
|
|
199
199
|
### After (Modular)
|
|
200
200
|
|
|
201
201
|
- **9 files**: โค284 LOC each
|
|
202
202
|
- **Benefits**:
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
203
|
+
- Clear separation of responsibilities (SRP)
|
|
204
|
+
- Independent module testing possible
|
|
205
|
+
- Easy to expand, easy to maintain
|
|
206
|
+
- Compliance with Context Engineering principles
|
|
207
207
|
|
|
208
208
|
### Breaking Changes
|
|
209
209
|
|
|
210
|
-
|
|
210
|
+
**None** - External APIs remain the same.
|
|
211
211
|
|
|
212
212
|
---
|
|
213
213
|
|
|
@@ -215,9 +215,9 @@ def _load_{module}_module(module_name: str):
|
|
|
215
215
|
|
|
216
216
|
### Internal Documents
|
|
217
217
|
|
|
218
|
-
- **CLAUDE.md**: MoAI-ADK
|
|
219
|
-
- **.moai/memory/development-guide.md**: SPEC-First TDD
|
|
220
|
-
- **.moai/memory/spec-metadata.md**: SPEC
|
|
218
|
+
- **CLAUDE.md**: MoAI-ADK User Guide
|
|
219
|
+
- **.moai/memory/development-guide.md**: SPEC-First TDD Workflow
|
|
220
|
+
- **.moai/memory/spec-metadata.md**: SPEC metadata standard
|
|
221
221
|
|
|
222
222
|
### External Resources
|
|
223
223
|
|
|
@@ -2,22 +2,9 @@
|
|
|
2
2
|
# @CODE:HOOKS-REFACTOR-001 | SPEC: SPEC-HOOKS-REFACTOR-001.md
|
|
3
3
|
"""Alfred Hooks - Main entry point for MoAI-ADK Claude Code Hooks
|
|
4
4
|
|
|
5
|
-
Claude Code
|
|
5
|
+
A main entry point that routes Claude Code events to the appropriate handlers.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
"""
|
|
9
|
-
import sys
|
|
10
|
-
from pathlib import Path
|
|
11
|
-
|
|
12
|
-
# Add the hooks directory to sys.path to enable package imports
|
|
13
|
-
HOOKS_DIR = Path(__file__).parent
|
|
14
|
-
if str(HOOKS_DIR) not in sys.path:
|
|
15
|
-
sys.path.insert(0, str(HOOKS_DIR))
|
|
16
|
-
|
|
17
|
-
# Now we can import from the package
|
|
18
|
-
|
|
19
|
-
"""
|
|
20
|
-
Architecture:
|
|
7
|
+
๐๏ธ Architecture:
|
|
21
8
|
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
22
9
|
โ alfred_hooks.py (Router) โ
|
|
23
10
|
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
|
|
@@ -44,26 +31,30 @@ Architecture:
|
|
|
44
31
|
โ - tags.py: TAG search/verification, library version cache โ
|
|
45
32
|
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
46
33
|
|
|
47
|
-
Usage:
|
|
34
|
+
๐ ๏ธ Usage:
|
|
48
35
|
python alfred_hooks.py <event_name> < payload.json
|
|
49
36
|
|
|
50
|
-
Supported Events:
|
|
51
|
-
- SessionStart:
|
|
52
|
-
- UserPromptSubmit:
|
|
53
|
-
- PreToolUse:
|
|
37
|
+
๐ฃ Supported Events:
|
|
38
|
+
- SessionStart: Start Session (display project status)
|
|
39
|
+
- UserPromptSubmit: Prompt submission (JIT document loading)
|
|
40
|
+
- PreToolUse: Before using the tool (automatically creates checkpoint)
|
|
54
41
|
- SessionEnd, PostToolUse, Notification, Stop, SubagentStop
|
|
55
42
|
|
|
56
|
-
Exit Codes:
|
|
57
|
-
- 0:
|
|
58
|
-
- 1:
|
|
43
|
+
๐ฆ Exit Codes:
|
|
44
|
+
- 0: Success
|
|
45
|
+
- 1: Error (no arguments, JSON parsing failure, exception thrown)
|
|
46
|
+
|
|
47
|
+
๐งช TDD History:
|
|
48
|
+
- RED: Module separation design, event routing test
|
|
49
|
+
- GREEN: 1233 LOC โ 9 items Module separation implementation (SRP compliance)
|
|
50
|
+
- REFACTOR: Import optimization, enhanced error handling
|
|
59
51
|
|
|
60
|
-
|
|
61
|
-
- RED: ๋ชจ๋ ๋ถ๋ฆฌ ์ค๊ณ, ์ด๋ฒคํธ ๋ผ์ฐํ
ํ
์คํธ
|
|
62
|
-
- GREEN: 1233 LOC โ 9๊ฐ ๋ชจ๋ ๋ถ๋ฆฌ ๊ตฌํ (SRP ์ค์)
|
|
63
|
-
- REFACTOR: Import ์ต์ ํ, ์๋ฌ ์ฒ๋ฆฌ ๊ฐํ
|
|
52
|
+
Setup sys.path for package imports
|
|
64
53
|
"""
|
|
65
54
|
|
|
66
55
|
import json
|
|
56
|
+
import sys
|
|
57
|
+
from pathlib import Path
|
|
67
58
|
|
|
68
59
|
from core import HookResult
|
|
69
60
|
from handlers import (
|
|
@@ -77,39 +68,44 @@ from handlers import (
|
|
|
77
68
|
handle_user_prompt_submit,
|
|
78
69
|
)
|
|
79
70
|
|
|
71
|
+
# Add the hooks directory to sys.path to enable package imports
|
|
72
|
+
HOOKS_DIR = Path(__file__).parent
|
|
73
|
+
if str(HOOKS_DIR) not in sys.path:
|
|
74
|
+
sys.path.insert(0, str(HOOKS_DIR))
|
|
75
|
+
|
|
80
76
|
|
|
81
77
|
def main() -> None:
|
|
82
|
-
"""
|
|
78
|
+
"""Main entry point - Claude Code Hook script
|
|
83
79
|
|
|
84
|
-
CLI
|
|
85
|
-
|
|
80
|
+
Receives the event name as a CLI argument and reads the JSON payload through stdin.
|
|
81
|
+
Calls the handler appropriate for the event and outputs the results to stdout as JSON.
|
|
86
82
|
|
|
87
|
-
Usage:
|
|
83
|
+
๐ ๏ธ Usage:
|
|
88
84
|
python alfred_hooks.py <event_name> < payload.json
|
|
89
85
|
|
|
90
|
-
Supported Events:
|
|
91
|
-
- SessionStart:
|
|
92
|
-
- UserPromptSubmit:
|
|
86
|
+
๐ฃ Supported Events:
|
|
87
|
+
- SessionStart: Start Session (display project status)
|
|
88
|
+
- UserPromptSubmit: Prompt submission (JIT document loading)
|
|
93
89
|
- SessionEnd, PreToolUse, PostToolUse, Notification, Stop, SubagentStop
|
|
94
90
|
|
|
95
|
-
Exit Codes:
|
|
96
|
-
- 0:
|
|
97
|
-
- 1:
|
|
91
|
+
๐ฆ Exit Codes:
|
|
92
|
+
- 0: Success
|
|
93
|
+
- 1: Error (no arguments, JSON parsing failure, exception thrown)
|
|
98
94
|
|
|
99
|
-
Examples:
|
|
95
|
+
๐ Examples:
|
|
100
96
|
$ echo '{"cwd": "."}' | python alfred_hooks.py SessionStart
|
|
101
97
|
{"message": "๐ MoAI-ADK Session Started\\n...", ...}
|
|
102
98
|
|
|
103
|
-
Notes:
|
|
104
|
-
- Claude Code
|
|
105
|
-
-
|
|
106
|
-
-
|
|
107
|
-
- UserPromptSubmit
|
|
99
|
+
๐๏ธ Notes:
|
|
100
|
+
- Claude Code is automatically called (no need for direct user execution)
|
|
101
|
+
- JSON I/O processing through stdin/stdout
|
|
102
|
+
- Print error message to stderr
|
|
103
|
+
- UserPromptSubmit uses a special output schema (hookEventName + additionalContext)
|
|
108
104
|
|
|
109
|
-
TDD History:
|
|
110
|
-
- RED:
|
|
111
|
-
- GREEN:
|
|
112
|
-
- REFACTOR:
|
|
105
|
+
๐งช TDD History:
|
|
106
|
+
- RED: Event routing, JSON I/O, error handling testing
|
|
107
|
+
- GREEN: Handler map-based routing implementation
|
|
108
|
+
- REFACTOR: Error message clarification, exit code standardization, UserPromptSubmit schema separation
|
|
113
109
|
"""
|
|
114
110
|
# Check for event argument
|
|
115
111
|
if len(sys.argv) < 2:
|
|
@@ -140,7 +136,7 @@ def main() -> None:
|
|
|
140
136
|
handler = handlers.get(event_name)
|
|
141
137
|
result = handler({"cwd": cwd, **data}) if handler else HookResult()
|
|
142
138
|
|
|
143
|
-
# UserPromptSubmit
|
|
139
|
+
# UserPromptSubmit uses a special output schema
|
|
144
140
|
if event_name == "UserPromptSubmit":
|
|
145
141
|
print(json.dumps(result.to_user_prompt_submit_dict()))
|
|
146
142
|
else:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""Core module for Alfred Hooks
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Common type definitions and utility functions
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
from dataclasses import asdict, dataclass, field
|
|
@@ -9,64 +9,64 @@ from typing import Any, NotRequired, TypedDict
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class HookPayload(TypedDict):
|
|
12
|
-
"""Claude Code Hook
|
|
12
|
+
"""Claude Code Hook event payload type definition
|
|
13
13
|
|
|
14
|
-
Claude Code
|
|
15
|
-
|
|
14
|
+
Data structure that Claude Code passes to the Hook script.
|
|
15
|
+
Use NotRequired because fields may vary depending on the event.
|
|
16
16
|
"""
|
|
17
17
|
|
|
18
18
|
cwd: str
|
|
19
|
-
userPrompt: NotRequired[str]
|
|
20
|
-
tool: NotRequired[str] # PreToolUse/PostToolUse
|
|
19
|
+
userPrompt: NotRequired[str] # Includes only UserPromptSubmit events
|
|
20
|
+
tool: NotRequired[str] # PreToolUse/PostToolUse events
|
|
21
21
|
arguments: NotRequired[dict[str, Any]] # Tool arguments
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
@dataclass
|
|
25
25
|
class HookResult:
|
|
26
|
-
"""Hook
|
|
26
|
+
"""Hook execution result"""
|
|
27
27
|
|
|
28
28
|
message: str | None = None
|
|
29
|
-
systemMessage: str | None = None #
|
|
29
|
+
systemMessage: str | None = None # Message displayed directly to the user # noqa: N815
|
|
30
30
|
blocked: bool = False
|
|
31
|
-
contextFiles: list[str] = field(default_factory=list)
|
|
31
|
+
contextFiles: list[str] = field(default_factory=list) # noqa: N815
|
|
32
32
|
suggestions: list[str] = field(default_factory=list)
|
|
33
|
-
exitCode: int = 0
|
|
33
|
+
exitCode: int = 0 # noqa: N815
|
|
34
34
|
|
|
35
35
|
def to_dict(self) -> dict[str, Any]:
|
|
36
|
-
"""
|
|
36
|
+
"""Dictionary conversion for general Hook"""
|
|
37
37
|
return asdict(self)
|
|
38
38
|
|
|
39
39
|
def to_user_prompt_submit_dict(self) -> dict[str, Any]:
|
|
40
|
-
"""UserPromptSubmit Hook
|
|
40
|
+
"""UserPromptSubmit Hook-specific output format
|
|
41
41
|
|
|
42
|
-
Claude Code
|
|
42
|
+
Claude Code requires a special schema for UserPromptSubmit:
|
|
43
43
|
{
|
|
44
44
|
"hookEventName": "UserPromptSubmit",
|
|
45
45
|
"additionalContext": "string (required)"
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
Returns:
|
|
49
|
-
Claude Code UserPromptSubmit Hook
|
|
49
|
+
Claude Code UserPromptSubmit Hook Dictionary matching schema
|
|
50
50
|
|
|
51
51
|
Examples:
|
|
52
52
|
>>> result = HookResult(contextFiles=["tests/"])
|
|
53
53
|
>>> result.to_user_prompt_submit_dict()
|
|
54
54
|
{'hookEventName': 'UserPromptSubmit', 'additionalContext': '๐ Context: tests/'}
|
|
55
55
|
"""
|
|
56
|
-
# contextFiles
|
|
56
|
+
# Convert contextFiles to additionalContext string
|
|
57
57
|
if self.contextFiles:
|
|
58
58
|
context_str = "\n".join([f"๐ Context: {f}" for f in self.contextFiles])
|
|
59
59
|
else:
|
|
60
60
|
context_str = ""
|
|
61
61
|
|
|
62
|
-
# message
|
|
62
|
+
# Add message if there is one
|
|
63
63
|
if self.message:
|
|
64
64
|
if context_str:
|
|
65
65
|
context_str = f"{self.message}\n\n{context_str}"
|
|
66
66
|
else:
|
|
67
67
|
context_str = self.message
|
|
68
68
|
|
|
69
|
-
#
|
|
69
|
+
# If the string is empty, use default
|
|
70
70
|
if not context_str:
|
|
71
71
|
context_str = ""
|
|
72
72
|
|