@polymorphism-tech/morph-spec 4.8.12 → 4.8.14
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 +379 -379
- package/bin/{task-manager.cjs → task-manager.js} +47 -158
- package/claude-plugin.json +14 -14
- package/docs/CHEATSHEET.md +203 -203
- package/docs/QUICKSTART.md +1 -1
- package/framework/agents.json +111 -24
- package/framework/hooks/README.md +202 -202
- package/framework/hooks/claude-code/pre-tool-use/enforce-phase-writes.js +6 -0
- package/framework/hooks/claude-code/session-start/inject-morph-context.js +7 -0
- package/framework/hooks/claude-code/statusline.py +6 -0
- package/framework/hooks/claude-code/stop/validate-completion.js +21 -2
- package/framework/hooks/shared/phase-utils.js +3 -0
- package/framework/skills/level-0-meta/tool-usage-guide/SKILL.md +55 -0
- package/framework/skills/level-1-workflows/phase-clarify/SKILL.md +1 -1
- package/framework/skills/level-1-workflows/phase-codebase-analysis/SKILL.md +1 -1
- package/framework/skills/level-1-workflows/phase-design/SKILL.md +57 -1
- package/framework/skills/level-1-workflows/phase-implement/SKILL.md +23 -1
- package/framework/skills/level-1-workflows/phase-setup/SKILL.md +1 -1
- package/framework/skills/level-1-workflows/phase-tasks/SKILL.md +25 -2
- package/framework/skills/level-1-workflows/phase-uiux/SKILL.md +1 -1
- package/package.json +87 -87
- package/src/commands/state/advance-phase.js +32 -13
- package/src/commands/tasks/task.js +2 -2
- package/src/core/paths/output-schema.js +1 -0
- package/src/lib/detectors/design-system-detector.js +5 -4
- package/src/lib/tasks/task-parser.js +94 -0
- package/src/lib/validators/content/content-validator.js +34 -106
|
@@ -1,202 +1,202 @@
|
|
|
1
|
-
# MORPH-SPEC Hooks Architecture (v2)
|
|
2
|
-
|
|
3
|
-
Comprehensive hooks system for enforcing spec-driven development at the Claude Code level.
|
|
4
|
-
|
|
5
|
-
## Architecture
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
framework/hooks/
|
|
9
|
-
├── claude-code/ # Claude Code native hooks
|
|
10
|
-
│ ├── session-start/
|
|
11
|
-
│ │ └── inject-morph-context.js # Inject state summary on session start
|
|
12
|
-
│ ├── user-prompt/
|
|
13
|
-
│ │ └── enrich-prompt.js # Context-aware prompt enrichment
|
|
14
|
-
│ ├── pre-tool-use/
|
|
15
|
-
│ │ ├── protect-spec-files.js # Block edits to approved spec artifacts
|
|
16
|
-
│ │ └── enforce-phase-writes.js # Enforce writes to correct phase dir
|
|
17
|
-
│ ├── post-tool-use/
|
|
18
|
-
│ │ └── dispatch.js # Dispatch on CLI commands (auto-checkpoint)
|
|
19
|
-
│ ├── stop/
|
|
20
|
-
│ │ └── validate-completion.js # Advisory: warn about incomplete work
|
|
21
|
-
│ ├── pre-compact/
|
|
22
|
-
│ │ └── save-morph-context.js # Snapshot state before compaction
|
|
23
|
-
│ └── notification/
|
|
24
|
-
│ └── approval-reminder.js # Remind about pending approvals
|
|
25
|
-
├── shared/ # Reusable utilities for all hooks
|
|
26
|
-
│ ├── state-reader.js # Read-only state.json accessor
|
|
27
|
-
│ ├── phase-utils.js # Phase constants and path utilities
|
|
28
|
-
│ ├── hook-response.js # JSON response builders
|
|
29
|
-
│ └── stdin-reader.js # Stdin JSON reader
|
|
30
|
-
├── git/ # Git hooks (Bash)
|
|
31
|
-
│ ├── pre-commit/
|
|
32
|
-
│ │ ├── orchestrator.sh # Master hook dispatcher
|
|
33
|
-
│ │ ├── agents.sh # Validates agents.json schema
|
|
34
|
-
│ │ └── specs.sh # Validates spec.md sections
|
|
35
|
-
│ ├── commit-msg/
|
|
36
|
-
│ │ └── conventional-commits.sh # Enforces conventional commits
|
|
37
|
-
│ └── pre-push/
|
|
38
|
-
│ └── run-tests.sh # Runs test suite before push
|
|
39
|
-
└── README.md # This file
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Hook Events
|
|
43
|
-
|
|
44
|
-
| Event | Hook | Type | Purpose |
|
|
45
|
-
|-------|------|------|---------|
|
|
46
|
-
| **SessionStart** | inject-morph-context.js | Inject context | Shows active feature, phase, pending approvals |
|
|
47
|
-
| **UserPromptSubmit** | enrich-prompt.js | Inject context | Warns about wrong-phase work, injects commands |
|
|
48
|
-
| **PreToolUse** (Write\|Edit) | _(native permissions.deny)_ | Block | Blocks edits to state.json and .morph/framework/ |
|
|
49
|
-
| **PreToolUse** (Write\|Edit) | protect-spec-files.js | Block | Blocks edits to spec files after approval |
|
|
50
|
-
| **PreToolUse** (Write\|Edit) | enforce-phase-writes.js | Block | Ensures writes go to current phase directory |
|
|
51
|
-
| **PreToolUse** (Bash) | _(prompt-type inline guard)_ | Block | Blocks `rm -rf .morph/` and direct state edits via Claude's reasoning |
|
|
52
|
-
| **PostToolUse** (Bash) | dispatch.js | Dispatch | Triggers checkpoints on task completion |
|
|
53
|
-
| **PostToolUseFailure** | handle-tool-failure.js | Logging | Appends structured JSON to .morph/logs/tool-failures.log |
|
|
54
|
-
| **Stop** | validate-completion.js | Advisory | Warns about incomplete tasks/missing outputs/pending gates |
|
|
55
|
-
| **PreCompact** | save-morph-context.js | Snapshot | Saves state to .morph/memory/ before compaction |
|
|
56
|
-
| **Notification** | approval-reminder.js | Advisory | Reminds about pending approval gates |
|
|
57
|
-
|
|
58
|
-
## Design Principles
|
|
59
|
-
|
|
60
|
-
1. **Fail-open**: All hooks catch exceptions and `exit 0` — never accidentally block legitimate work
|
|
61
|
-
2. **Non-morph projects**: Every hook checks for `.morph/state.json` first and exits silently if missing
|
|
62
|
-
3. **Performance**: PreToolUse hooks use synchronous state reads for <100ms execution
|
|
63
|
-
4. **Cross-platform**: All hooks use `path.join()`/`path.resolve()`, no hardcoded path separators
|
|
64
|
-
5. **Node.js only**: All hooks use `node` as executor (no PowerShell/bash dependency)
|
|
65
|
-
|
|
66
|
-
## Installation
|
|
67
|
-
|
|
68
|
-
Hooks are automatically installed by `morph-spec init` and updated by `morph-spec update`.
|
|
69
|
-
|
|
70
|
-
During init/update, the entire `framework/hooks/` directory is copied to `.morph/framework/hooks/`.
|
|
71
|
-
Hook commands in `.claude/settings.local.json` reference `$CLAUDE_PROJECT_DIR/.morph/framework/hooks/`
|
|
72
|
-
so they work correctly in any project regardless of how morph-spec was installed.
|
|
73
|
-
|
|
74
|
-
The installer writes to `.claude/settings.local.json`:
|
|
75
|
-
|
|
76
|
-
```json
|
|
77
|
-
{
|
|
78
|
-
"hooks": {
|
|
79
|
-
"SessionStart": [{ "matcher": "startup|resume|compact", "hooks": [...] }],
|
|
80
|
-
"UserPromptSubmit": [{ "hooks": [...] }],
|
|
81
|
-
"PreToolUse": [
|
|
82
|
-
{ "matcher": "Write|Edit", "hooks": [...] },
|
|
83
|
-
{ "matcher": "Bash", "hooks": [...] }
|
|
84
|
-
],
|
|
85
|
-
"PostToolUse": [
|
|
86
|
-
{ "matcher": "Bash", "hooks": [...] }
|
|
87
|
-
],
|
|
88
|
-
"Stop": [{ "hooks": [...] }],
|
|
89
|
-
"PreCompact": [{ "hooks": [...] }],
|
|
90
|
-
"Notification": [{ "matcher": "idle_prompt", "hooks": [...] }]
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Git Hooks
|
|
96
|
-
|
|
97
|
-
```bash
|
|
98
|
-
# In your project root
|
|
99
|
-
cd .git/hooks
|
|
100
|
-
ln -sf ../../framework/hooks/git/pre-commit/orchestrator.sh pre-commit
|
|
101
|
-
ln -sf ../../framework/hooks/git/commit-msg/conventional-commits.sh commit-msg
|
|
102
|
-
ln -sf ../../framework/hooks/git/pre-push/run-tests.sh pre-push
|
|
103
|
-
chmod +x pre-commit commit-msg pre-push
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Shared Utilities
|
|
107
|
-
|
|
108
|
-
All Claude Code hooks import from `framework/hooks/shared/`:
|
|
109
|
-
|
|
110
|
-
| Module | Purpose |
|
|
111
|
-
|--------|---------|
|
|
112
|
-
| `state-reader.js` | `loadState()`, `getActiveFeature()`, `getFeaturePhase()`, `isGateApproved()`, `getPendingGates()`, `getMissingOutputs()` |
|
|
113
|
-
| `phase-utils.js` | Phase constants, path extraction, file classification |
|
|
114
|
-
| `hook-response.js` | `block(reason)`, `approve(context)`, `injectContext(text)`, `pass()` |
|
|
115
|
-
| `stdin-reader.js` | `readStdin()` — Promise-based stdin JSON reader |
|
|
116
|
-
|
|
117
|
-
## How Hooks Work
|
|
118
|
-
|
|
119
|
-
### PreToolUse (Write|Edit) Flow
|
|
120
|
-
|
|
121
|
-
```
|
|
122
|
-
Claude calls Write/Edit tool
|
|
123
|
-
↓
|
|
124
|
-
Claude Code sends JSON to stdin: { tool_input: { file_path: "..." } }
|
|
125
|
-
↓
|
|
126
|
-
[native permissions.deny]
|
|
127
|
-
├── Is .morph/state.json? → BLOCK (use CLI)
|
|
128
|
-
├── Is .morph/framework/**? → BLOCK (read-only)
|
|
129
|
-
└── Other → continue
|
|
130
|
-
↓
|
|
131
|
-
protect-spec-files.js
|
|
132
|
-
├── Is in .morph/features/{feature}/?
|
|
133
|
-
│ ├── Is spec.md and design gate approved? → BLOCK
|
|
134
|
-
│ ├── Is tasks.md and tasks gate approved? → BLOCK
|
|
135
|
-
│ └── Gate not approved → pass
|
|
136
|
-
└── Not a feature file → pass
|
|
137
|
-
↓
|
|
138
|
-
enforce-phase-writes.js
|
|
139
|
-
├── Is in .morph/features/{feature}/?
|
|
140
|
-
│ ├── Phase is implement → pass (unrestricted)
|
|
141
|
-
│ ├── Target dir matches phase dir → pass
|
|
142
|
-
│ └── Target dir doesn't match → BLOCK
|
|
143
|
-
└── Not a feature file → pass
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### SessionStart Flow
|
|
147
|
-
|
|
148
|
-
```
|
|
149
|
-
Session starts/resumes/compacts
|
|
150
|
-
↓
|
|
151
|
-
inject-morph-context.js
|
|
152
|
-
├── No state.json → silent exit
|
|
153
|
-
├── Has active feature → inject summary:
|
|
154
|
-
│ "MORPH-SPEC Status:
|
|
155
|
-
│ - Active feature: my-feature (phase: implement)
|
|
156
|
-
│ - Tasks: 3/10 completed
|
|
157
|
-
│ - Pending approvals: design, tasks"
|
|
158
|
-
└── No active feature → inject feature list
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
## Testing
|
|
162
|
-
|
|
163
|
-
```bash
|
|
164
|
-
# Run hook tests
|
|
165
|
-
npm test -- test/hooks/
|
|
166
|
-
|
|
167
|
-
# Run shared utilities tests
|
|
168
|
-
npm test -- test/hooks/shared-utils.test.js
|
|
169
|
-
|
|
170
|
-
# Run installer tests
|
|
171
|
-
npm test -- test/hooks/hooks-installer.test.js
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
## Troubleshooting
|
|
175
|
-
|
|
176
|
-
### Hooks Not Running
|
|
177
|
-
|
|
178
|
-
```bash
|
|
179
|
-
# Check if hooks are installed
|
|
180
|
-
cat .claude/settings.local.json | jq '.hooks'
|
|
181
|
-
|
|
182
|
-
# Reinstall hooks
|
|
183
|
-
morph-spec update
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
### Hook Blocking Legitimate Work
|
|
187
|
-
|
|
188
|
-
All hooks are fail-open. If a hook is incorrectly blocking:
|
|
189
|
-
|
|
190
|
-
1. The hook catches its own errors and exits 0
|
|
191
|
-
2. If truly stuck, remove the specific hook from `.claude/settings.local.json`
|
|
192
|
-
3. Report the issue so the hook logic can be fixed
|
|
193
|
-
|
|
194
|
-
### Resetting All Morph Hooks
|
|
195
|
-
|
|
196
|
-
```bash
|
|
197
|
-
morph-spec doctor --reset
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
---
|
|
201
|
-
|
|
202
|
-
*MORPH-SPEC by Polymorphism Tech — Hooks Architecture v2.5*
|
|
1
|
+
# MORPH-SPEC Hooks Architecture (v2)
|
|
2
|
+
|
|
3
|
+
Comprehensive hooks system for enforcing spec-driven development at the Claude Code level.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
framework/hooks/
|
|
9
|
+
├── claude-code/ # Claude Code native hooks
|
|
10
|
+
│ ├── session-start/
|
|
11
|
+
│ │ └── inject-morph-context.js # Inject state summary on session start
|
|
12
|
+
│ ├── user-prompt/
|
|
13
|
+
│ │ └── enrich-prompt.js # Context-aware prompt enrichment
|
|
14
|
+
│ ├── pre-tool-use/
|
|
15
|
+
│ │ ├── protect-spec-files.js # Block edits to approved spec artifacts
|
|
16
|
+
│ │ └── enforce-phase-writes.js # Enforce writes to correct phase dir
|
|
17
|
+
│ ├── post-tool-use/
|
|
18
|
+
│ │ └── dispatch.js # Dispatch on CLI commands (auto-checkpoint)
|
|
19
|
+
│ ├── stop/
|
|
20
|
+
│ │ └── validate-completion.js # Advisory: warn about incomplete work
|
|
21
|
+
│ ├── pre-compact/
|
|
22
|
+
│ │ └── save-morph-context.js # Snapshot state before compaction
|
|
23
|
+
│ └── notification/
|
|
24
|
+
│ └── approval-reminder.js # Remind about pending approvals
|
|
25
|
+
├── shared/ # Reusable utilities for all hooks
|
|
26
|
+
│ ├── state-reader.js # Read-only state.json accessor
|
|
27
|
+
│ ├── phase-utils.js # Phase constants and path utilities
|
|
28
|
+
│ ├── hook-response.js # JSON response builders
|
|
29
|
+
│ └── stdin-reader.js # Stdin JSON reader
|
|
30
|
+
├── git/ # Git hooks (Bash)
|
|
31
|
+
│ ├── pre-commit/
|
|
32
|
+
│ │ ├── orchestrator.sh # Master hook dispatcher
|
|
33
|
+
│ │ ├── agents.sh # Validates agents.json schema
|
|
34
|
+
│ │ └── specs.sh # Validates spec.md sections
|
|
35
|
+
│ ├── commit-msg/
|
|
36
|
+
│ │ └── conventional-commits.sh # Enforces conventional commits
|
|
37
|
+
│ └── pre-push/
|
|
38
|
+
│ └── run-tests.sh # Runs test suite before push
|
|
39
|
+
└── README.md # This file
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Hook Events
|
|
43
|
+
|
|
44
|
+
| Event | Hook | Type | Purpose |
|
|
45
|
+
|-------|------|------|---------|
|
|
46
|
+
| **SessionStart** | inject-morph-context.js | Inject context | Shows active feature, phase, pending approvals |
|
|
47
|
+
| **UserPromptSubmit** | enrich-prompt.js | Inject context | Warns about wrong-phase work, injects commands |
|
|
48
|
+
| **PreToolUse** (Write\|Edit) | _(native permissions.deny)_ | Block | Blocks edits to state.json and .morph/framework/ |
|
|
49
|
+
| **PreToolUse** (Write\|Edit) | protect-spec-files.js | Block | Blocks edits to spec files after approval |
|
|
50
|
+
| **PreToolUse** (Write\|Edit) | enforce-phase-writes.js | Block | Ensures writes go to current phase directory |
|
|
51
|
+
| **PreToolUse** (Bash) | _(prompt-type inline guard)_ | Block | Blocks `rm -rf .morph/` and direct state edits via Claude's reasoning |
|
|
52
|
+
| **PostToolUse** (Bash) | dispatch.js | Dispatch | Triggers checkpoints on task completion |
|
|
53
|
+
| **PostToolUseFailure** | handle-tool-failure.js | Logging | Appends structured JSON to .morph/logs/tool-failures.log |
|
|
54
|
+
| **Stop** | validate-completion.js | Advisory | Warns about incomplete tasks/missing outputs/pending gates |
|
|
55
|
+
| **PreCompact** | save-morph-context.js | Snapshot | Saves state to .morph/memory/ before compaction |
|
|
56
|
+
| **Notification** | approval-reminder.js | Advisory | Reminds about pending approval gates |
|
|
57
|
+
|
|
58
|
+
## Design Principles
|
|
59
|
+
|
|
60
|
+
1. **Fail-open**: All hooks catch exceptions and `exit 0` — never accidentally block legitimate work
|
|
61
|
+
2. **Non-morph projects**: Every hook checks for `.morph/state.json` first and exits silently if missing
|
|
62
|
+
3. **Performance**: PreToolUse hooks use synchronous state reads for <100ms execution
|
|
63
|
+
4. **Cross-platform**: All hooks use `path.join()`/`path.resolve()`, no hardcoded path separators
|
|
64
|
+
5. **Node.js only**: All hooks use `node` as executor (no PowerShell/bash dependency)
|
|
65
|
+
|
|
66
|
+
## Installation
|
|
67
|
+
|
|
68
|
+
Hooks are automatically installed by `morph-spec init` and updated by `morph-spec update`.
|
|
69
|
+
|
|
70
|
+
During init/update, the entire `framework/hooks/` directory is copied to `.morph/framework/hooks/`.
|
|
71
|
+
Hook commands in `.claude/settings.local.json` reference `$CLAUDE_PROJECT_DIR/.morph/framework/hooks/`
|
|
72
|
+
so they work correctly in any project regardless of how morph-spec was installed.
|
|
73
|
+
|
|
74
|
+
The installer writes to `.claude/settings.local.json`:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"hooks": {
|
|
79
|
+
"SessionStart": [{ "matcher": "startup|resume|compact", "hooks": [...] }],
|
|
80
|
+
"UserPromptSubmit": [{ "hooks": [...] }],
|
|
81
|
+
"PreToolUse": [
|
|
82
|
+
{ "matcher": "Write|Edit", "hooks": [...] },
|
|
83
|
+
{ "matcher": "Bash", "hooks": [...] }
|
|
84
|
+
],
|
|
85
|
+
"PostToolUse": [
|
|
86
|
+
{ "matcher": "Bash", "hooks": [...] }
|
|
87
|
+
],
|
|
88
|
+
"Stop": [{ "hooks": [...] }],
|
|
89
|
+
"PreCompact": [{ "hooks": [...] }],
|
|
90
|
+
"Notification": [{ "matcher": "idle_prompt", "hooks": [...] }]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Git Hooks
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# In your project root
|
|
99
|
+
cd .git/hooks
|
|
100
|
+
ln -sf ../../framework/hooks/git/pre-commit/orchestrator.sh pre-commit
|
|
101
|
+
ln -sf ../../framework/hooks/git/commit-msg/conventional-commits.sh commit-msg
|
|
102
|
+
ln -sf ../../framework/hooks/git/pre-push/run-tests.sh pre-push
|
|
103
|
+
chmod +x pre-commit commit-msg pre-push
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Shared Utilities
|
|
107
|
+
|
|
108
|
+
All Claude Code hooks import from `framework/hooks/shared/`:
|
|
109
|
+
|
|
110
|
+
| Module | Purpose |
|
|
111
|
+
|--------|---------|
|
|
112
|
+
| `state-reader.js` | `loadState()`, `getActiveFeature()`, `getFeaturePhase()`, `isGateApproved()`, `getPendingGates()`, `getMissingOutputs()` |
|
|
113
|
+
| `phase-utils.js` | Phase constants, path extraction, file classification |
|
|
114
|
+
| `hook-response.js` | `block(reason)`, `approve(context)`, `injectContext(text)`, `pass()` |
|
|
115
|
+
| `stdin-reader.js` | `readStdin()` — Promise-based stdin JSON reader |
|
|
116
|
+
|
|
117
|
+
## How Hooks Work
|
|
118
|
+
|
|
119
|
+
### PreToolUse (Write|Edit) Flow
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
Claude calls Write/Edit tool
|
|
123
|
+
↓
|
|
124
|
+
Claude Code sends JSON to stdin: { tool_input: { file_path: "..." } }
|
|
125
|
+
↓
|
|
126
|
+
[native permissions.deny]
|
|
127
|
+
├── Is .morph/state.json? → BLOCK (use CLI)
|
|
128
|
+
├── Is .morph/framework/**? → BLOCK (read-only)
|
|
129
|
+
└── Other → continue
|
|
130
|
+
↓
|
|
131
|
+
protect-spec-files.js
|
|
132
|
+
├── Is in .morph/features/{feature}/?
|
|
133
|
+
│ ├── Is spec.md and design gate approved? → BLOCK
|
|
134
|
+
│ ├── Is tasks.md and tasks gate approved? → BLOCK
|
|
135
|
+
│ └── Gate not approved → pass
|
|
136
|
+
└── Not a feature file → pass
|
|
137
|
+
↓
|
|
138
|
+
enforce-phase-writes.js
|
|
139
|
+
├── Is in .morph/features/{feature}/?
|
|
140
|
+
│ ├── Phase is implement → pass (unrestricted)
|
|
141
|
+
│ ├── Target dir matches phase dir → pass
|
|
142
|
+
│ └── Target dir doesn't match → BLOCK
|
|
143
|
+
└── Not a feature file → pass
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### SessionStart Flow
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
Session starts/resumes/compacts
|
|
150
|
+
↓
|
|
151
|
+
inject-morph-context.js
|
|
152
|
+
├── No state.json → silent exit
|
|
153
|
+
├── Has active feature → inject summary:
|
|
154
|
+
│ "MORPH-SPEC Status:
|
|
155
|
+
│ - Active feature: my-feature (phase: implement)
|
|
156
|
+
│ - Tasks: 3/10 completed
|
|
157
|
+
│ - Pending approvals: design, tasks"
|
|
158
|
+
└── No active feature → inject feature list
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Testing
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
# Run hook tests
|
|
165
|
+
npm test -- test/hooks/
|
|
166
|
+
|
|
167
|
+
# Run shared utilities tests
|
|
168
|
+
npm test -- test/hooks/shared-utils.test.js
|
|
169
|
+
|
|
170
|
+
# Run installer tests
|
|
171
|
+
npm test -- test/hooks/hooks-installer.test.js
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Troubleshooting
|
|
175
|
+
|
|
176
|
+
### Hooks Not Running
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
# Check if hooks are installed
|
|
180
|
+
cat .claude/settings.local.json | jq '.hooks'
|
|
181
|
+
|
|
182
|
+
# Reinstall hooks
|
|
183
|
+
morph-spec update
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Hook Blocking Legitimate Work
|
|
187
|
+
|
|
188
|
+
All hooks are fail-open. If a hook is incorrectly blocking:
|
|
189
|
+
|
|
190
|
+
1. The hook catches its own errors and exits 0
|
|
191
|
+
2. If truly stuck, remove the specific hook from `.claude/settings.local.json`
|
|
192
|
+
3. Report the issue so the hook logic can be fixed
|
|
193
|
+
|
|
194
|
+
### Resetting All Morph Hooks
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
morph-spec doctor --reset
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
*MORPH-SPEC by Polymorphism Tech — Hooks Architecture v2.5*
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
* Fail-open: exits 0 on any error.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
+
import { existsSync } from 'fs';
|
|
21
|
+
import { resolve } from 'path';
|
|
20
22
|
import { readStdin } from '../../shared/stdin-reader.js';
|
|
21
23
|
import { stateExists, getFeaturePhase } from '../../shared/state-reader.js';
|
|
22
24
|
import {
|
|
@@ -55,6 +57,10 @@ try {
|
|
|
55
57
|
if (!allowedDir) pass(); // Unknown phase — allow
|
|
56
58
|
|
|
57
59
|
if (targetDir !== allowedDir) {
|
|
60
|
+
// Allow editing already-existing files from previous phases
|
|
61
|
+
const absolutePath = resolve(process.cwd(), filePath);
|
|
62
|
+
if (existsSync(absolutePath)) pass(); // editing existing file — allow
|
|
63
|
+
|
|
58
64
|
const phaseLabel = phase.toUpperCase();
|
|
59
65
|
block(
|
|
60
66
|
`MORPH-SPEC: Writing to '${targetDir}/' is not allowed during ${phaseLabel} phase.\n` +
|
|
@@ -71,6 +71,13 @@ try {
|
|
|
71
71
|
lines.push(`- Last checkpoint: #${lastCp.checkpointNum} (${lastCp.passed ? 'passed' : 'failed'})`);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
// Task tracking guidance for work phases
|
|
75
|
+
if (['design', 'tasks', 'implement'].includes(phase)) {
|
|
76
|
+
lines.push('');
|
|
77
|
+
lines.push('💡 TaskCreate/TaskUpdate: Para sessões com 3+ ações planejadas, crie tasks Claude Code');
|
|
78
|
+
lines.push(' para visibilidade do progresso. Ex: TaskCreate("Gerar spec.md"), TaskUpdate(id, "completed")');
|
|
79
|
+
}
|
|
80
|
+
|
|
74
81
|
// Active feature spec (truncated for context budget)
|
|
75
82
|
const specPath = join(process.cwd(), `.morph/features/${name}/1-design/spec.md`);
|
|
76
83
|
if (existsSync(specPath)) {
|
|
@@ -161,6 +161,12 @@ def get_all_active_features(cwd, entries):
|
|
|
161
161
|
|
|
162
162
|
# Filter to features belonging to this session (mentioned in transcript)
|
|
163
163
|
session_names = get_session_feature_names(features, entries)
|
|
164
|
+
|
|
165
|
+
# Auto-detect: if only one feature is in_progress, show it regardless of transcript
|
|
166
|
+
in_progress = [n for n, f in features.items() if f.get('status') == 'in_progress']
|
|
167
|
+
if len(in_progress) == 1:
|
|
168
|
+
session_names.add(in_progress[0])
|
|
169
|
+
|
|
164
170
|
if not session_names:
|
|
165
171
|
return []
|
|
166
172
|
|
|
@@ -120,11 +120,30 @@ try {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
// ── MEMORY.md reminder ────────────────────────────────────────────────────
|
|
124
|
+
const WORK_PHASES = new Set(['design', 'clarify', 'tasks', 'implement']);
|
|
125
|
+
const memoryLines = [];
|
|
126
|
+
if (WORK_PHASES.has(currentPhase)) {
|
|
127
|
+
memoryLines.push('📝 Sessão encerrando. Considere salvar no MEMORY.md:');
|
|
128
|
+
memoryLines.push(' • Padrões de domínio descobertos (regras, invariants, edge cases)');
|
|
129
|
+
memoryLines.push(' • Decisões arquiteturais tomadas nesta sessão (e o motivo)');
|
|
130
|
+
memoryLines.push(' • Erros frequentes desta stack/projeto e como resolvê-los');
|
|
131
|
+
memoryLines.push(' • Nuances do projeto que diferem do padrão (convenções, libs específicas)');
|
|
132
|
+
memoryLines.push(' • Bugs encontrados e a causa raiz');
|
|
133
|
+
memoryLines.push(' Se nada relevante foi descoberto nesta sessão, ignore este lembrete.');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (warnings.length === 0 && memoryLines.length === 0) pass();
|
|
137
|
+
|
|
138
|
+
const allLines = [...warnings];
|
|
139
|
+
if (memoryLines.length > 0) {
|
|
140
|
+
if (allLines.length > 0) allLines.push('');
|
|
141
|
+
allLines.push(...memoryLines);
|
|
142
|
+
}
|
|
124
143
|
|
|
125
144
|
const message = [
|
|
126
145
|
'MORPH-SPEC:',
|
|
127
|
-
...
|
|
146
|
+
...allLines.map(w => ` ${w}`),
|
|
128
147
|
'',
|
|
129
148
|
`Status: morph-spec status ${name}`,
|
|
130
149
|
].join('\n');
|
|
@@ -29,6 +29,7 @@ export const OUTPUT_PHASE_MAP = {
|
|
|
29
29
|
spec: 'design',
|
|
30
30
|
clarifications: 'clarify',
|
|
31
31
|
contracts: 'design',
|
|
32
|
+
contractsVsa: 'design',
|
|
32
33
|
tasks: 'tasks',
|
|
33
34
|
uiDesignSystem: 'uiux',
|
|
34
35
|
uiMockups: 'uiux',
|
|
@@ -45,6 +46,7 @@ export const FILENAME_TO_OUTPUT = {
|
|
|
45
46
|
'spec.md': 'spec',
|
|
46
47
|
'clarifications.md': 'clarifications',
|
|
47
48
|
'contracts.cs': 'contracts',
|
|
49
|
+
'contracts-vsa.cs': 'contractsVsa',
|
|
48
50
|
'tasks.md': 'tasks',
|
|
49
51
|
'design-system.md': 'uiDesignSystem',
|
|
50
52
|
'mockups.md': 'uiMockups',
|
|
@@ -59,6 +61,7 @@ export const PROTECTED_SPEC_FILES = {
|
|
|
59
61
|
'schema-analysis.md': 'design',
|
|
60
62
|
'spec.md': 'design',
|
|
61
63
|
'contracts.cs': 'design',
|
|
64
|
+
'contracts-vsa.cs': 'design',
|
|
62
65
|
'tasks.md': 'tasks',
|
|
63
66
|
'design-system.md': 'uiux',
|
|
64
67
|
'mockups.md': 'uiux',
|
|
@@ -82,6 +82,51 @@ Feature with multiple active agents?
|
|
|
82
82
|
|
|
83
83
|
---
|
|
84
84
|
|
|
85
|
+
## Comunicação com o Usuário
|
|
86
|
+
|
|
87
|
+
### AskUserQuestion vs. Texto Livre
|
|
88
|
+
|
|
89
|
+
| Situação | Ferramenta |
|
|
90
|
+
|---|---|
|
|
91
|
+
| ≥2 opções mutuamente exclusivas | `AskUserQuestion` (options[]) |
|
|
92
|
+
| Escolha binária sim/não | `AskUserQuestion` (2 options) |
|
|
93
|
+
| Aprovação de plano | `ExitPlanMode` |
|
|
94
|
+
| Explicação, progresso, confirmação | Texto direto |
|
|
95
|
+
|
|
96
|
+
**Regra:** NUNCA apresentar opções múltiplas como texto livre. Use `AskUserQuestion` com `options[]` para garantir escolha estruturada sem ambiguidade.
|
|
97
|
+
|
|
98
|
+
### EnterPlanMode
|
|
99
|
+
|
|
100
|
+
Use **ANTES** de iniciar implementação quando:
|
|
101
|
+
- Refactor toca ≥5 arquivos ou muda arquitetura
|
|
102
|
+
- Estimativa de tasks ≥20
|
|
103
|
+
- Escolha entre ≥2 abordagens de design significativamente diferentes
|
|
104
|
+
|
|
105
|
+
NÃO use para:
|
|
106
|
+
- Correção pontual de 1-3 arquivos
|
|
107
|
+
- Usuário já especificou abordagem detalhada
|
|
108
|
+
- Fase implement com tasks.md já aprovado
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
### Regra de Leituras Paralelas (CRÍTICO)
|
|
113
|
+
|
|
114
|
+
Arquivos independentes = uma única mensagem com múltiplas chamadas Read.
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
# ERRADO (sequencial)
|
|
118
|
+
Read: state.json → Read: spec.md → Read: tasks.md # 3 round-trips
|
|
119
|
+
|
|
120
|
+
# CORRETO (paralelo, 1 round-trip)
|
|
121
|
+
Read: state.json + Read: spec.md + Read: tasks.md
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Critério: se a leitura de arquivo B não depende do CONTEÚDO de arquivo A, leia os dois juntos.
|
|
125
|
+
|
|
126
|
+
**Exemplos de independência:** spec.md ↔ decisions.md ↔ contracts.cs ↔ tasks.md (todos lidos juntos na investigação de uma fase).
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
85
130
|
## Tools Per Phase
|
|
86
131
|
|
|
87
132
|
### Phase 0 — Proposal
|
|
@@ -340,6 +385,16 @@ Before choosing a tool, ask:
|
|
|
340
385
|
- Unknown files needing exploration → Glob/Grep, then Read
|
|
341
386
|
- Complex multi-step analysis → Task subagent
|
|
342
387
|
|
|
388
|
+
### Anti-Padrões Globais
|
|
389
|
+
|
|
390
|
+
- ❌ **WebFetch para URLs GitHub** → Use `gh api` ou `gh` CLI
|
|
391
|
+
- Correto: `gh api repos/owner/repo/git/trees/main --field recursive=1`
|
|
392
|
+
- Correto: `gh pr view 123`, `gh issue view 456`
|
|
393
|
+
- WebFetch para GitHub retorna HTML/redirect; `gh` usa a API autenticada
|
|
394
|
+
- ❌ **Perguntas multi-opção como texto livre** → Use `AskUserQuestion` com `options[]`
|
|
395
|
+
- Correto: `AskUserQuestion({ question: "Qual abordagem?", options: [{label: "A"}, {label: "B"}] })`
|
|
396
|
+
- Texto livre cria ambiguidade e requer parse manual da resposta
|
|
397
|
+
|
|
343
398
|
---
|
|
344
399
|
|
|
345
400
|
## MCP Registry
|
|
@@ -4,7 +4,7 @@ description: MORPH-SPEC Phase 3 (Clarify). Reviews spec.md for ambiguities, gene
|
|
|
4
4
|
argument-hint: "[feature-name]"
|
|
5
5
|
user-invocable: false
|
|
6
6
|
allowed-tools: Read, Write, Edit, Bash, Glob, Grep
|
|
7
|
-
cliVersion: "4.8.
|
|
7
|
+
cliVersion: "4.8.14"
|
|
8
8
|
---
|
|
9
9
|
|
|
10
10
|
# MORPH Clarify - FASE 3
|
|
@@ -3,7 +3,7 @@ name: phase-codebase-analysis
|
|
|
3
3
|
description: MORPH-SPEC Design sub-phase that analyzes existing codebase and database schema, producing schema-analysis.md with real column names, types, relationships, and field mismatches. Use at the start of Design phase before generating contracts.cs to prevent incorrect field names or types.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
allowed-tools: Read, Write, Edit, Bash, Glob, Grep
|
|
6
|
-
cliVersion: "4.8.
|
|
6
|
+
cliVersion: "4.8.14"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
# MORPH Codebase Analysis - Sub-fase de DESIGN
|