stravinsky 0.4.18__py3-none-any.whl → 0.4.66__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 stravinsky might be problematic. Click here for more details.
- mcp_bridge/__init__.py +1 -1
- mcp_bridge/auth/__init__.py +16 -6
- mcp_bridge/auth/cli.py +202 -11
- mcp_bridge/auth/oauth.py +1 -2
- mcp_bridge/auth/openai_oauth.py +4 -7
- mcp_bridge/auth/token_store.py +0 -1
- mcp_bridge/cli/__init__.py +1 -1
- mcp_bridge/cli/install_hooks.py +503 -107
- mcp_bridge/cli/session_report.py +0 -3
- mcp_bridge/config/__init__.py +2 -2
- mcp_bridge/config/hook_config.py +3 -5
- mcp_bridge/config/rate_limits.py +108 -13
- mcp_bridge/hooks/HOOKS_SETTINGS.json +17 -4
- mcp_bridge/hooks/__init__.py +14 -4
- mcp_bridge/hooks/agent_reminder.py +4 -4
- mcp_bridge/hooks/auto_slash_command.py +5 -5
- mcp_bridge/hooks/budget_optimizer.py +2 -2
- mcp_bridge/hooks/claude_limits_hook.py +114 -0
- mcp_bridge/hooks/comment_checker.py +3 -4
- mcp_bridge/hooks/compaction.py +2 -2
- mcp_bridge/hooks/context.py +2 -1
- mcp_bridge/hooks/context_monitor.py +2 -2
- mcp_bridge/hooks/delegation_policy.py +85 -0
- mcp_bridge/hooks/directory_context.py +3 -3
- mcp_bridge/hooks/edit_recovery.py +3 -2
- mcp_bridge/hooks/edit_recovery_policy.py +49 -0
- mcp_bridge/hooks/empty_message_sanitizer.py +2 -2
- mcp_bridge/hooks/events.py +160 -0
- mcp_bridge/hooks/git_noninteractive.py +4 -4
- mcp_bridge/hooks/keyword_detector.py +8 -10
- mcp_bridge/hooks/manager.py +35 -22
- mcp_bridge/hooks/notification_hook.py +13 -6
- mcp_bridge/hooks/parallel_enforcement_policy.py +67 -0
- mcp_bridge/hooks/parallel_enforcer.py +5 -5
- mcp_bridge/hooks/parallel_execution.py +22 -10
- mcp_bridge/hooks/post_tool/parallel_validation.py +103 -0
- mcp_bridge/hooks/pre_compact.py +8 -9
- mcp_bridge/hooks/pre_tool/agent_spawn_validator.py +115 -0
- mcp_bridge/hooks/preemptive_compaction.py +2 -3
- mcp_bridge/hooks/routing_notifications.py +80 -0
- mcp_bridge/hooks/rules_injector.py +11 -19
- mcp_bridge/hooks/session_idle.py +4 -4
- mcp_bridge/hooks/session_notifier.py +4 -4
- mcp_bridge/hooks/session_recovery.py +4 -5
- mcp_bridge/hooks/stravinsky_mode.py +1 -1
- mcp_bridge/hooks/subagent_stop.py +1 -3
- mcp_bridge/hooks/task_validator.py +2 -2
- mcp_bridge/hooks/tmux_manager.py +7 -8
- mcp_bridge/hooks/todo_delegation.py +4 -1
- mcp_bridge/hooks/todo_enforcer.py +180 -10
- mcp_bridge/hooks/truncation_policy.py +37 -0
- mcp_bridge/hooks/truncator.py +1 -2
- mcp_bridge/metrics/cost_tracker.py +115 -0
- mcp_bridge/native_search.py +93 -0
- mcp_bridge/native_watcher.py +118 -0
- mcp_bridge/notifications.py +3 -4
- mcp_bridge/orchestrator/enums.py +11 -0
- mcp_bridge/orchestrator/router.py +165 -0
- mcp_bridge/orchestrator/state.py +32 -0
- mcp_bridge/orchestrator/visualization.py +14 -0
- mcp_bridge/orchestrator/wisdom.py +34 -0
- mcp_bridge/prompts/__init__.py +1 -8
- mcp_bridge/prompts/dewey.py +1 -1
- mcp_bridge/prompts/planner.py +2 -4
- mcp_bridge/prompts/stravinsky.py +53 -31
- mcp_bridge/proxy/__init__.py +0 -0
- mcp_bridge/proxy/client.py +70 -0
- mcp_bridge/proxy/model_server.py +157 -0
- mcp_bridge/routing/__init__.py +43 -0
- mcp_bridge/routing/config.py +250 -0
- mcp_bridge/routing/model_tiers.py +135 -0
- mcp_bridge/routing/provider_state.py +261 -0
- mcp_bridge/routing/task_classifier.py +190 -0
- mcp_bridge/server.py +363 -34
- mcp_bridge/server_tools.py +298 -6
- mcp_bridge/tools/__init__.py +19 -8
- mcp_bridge/tools/agent_manager.py +549 -799
- mcp_bridge/tools/background_tasks.py +13 -17
- mcp_bridge/tools/code_search.py +54 -51
- mcp_bridge/tools/continuous_loop.py +0 -1
- mcp_bridge/tools/dashboard.py +19 -0
- mcp_bridge/tools/find_code.py +296 -0
- mcp_bridge/tools/init.py +1 -0
- mcp_bridge/tools/list_directory.py +42 -0
- mcp_bridge/tools/lsp/__init__.py +8 -8
- mcp_bridge/tools/lsp/manager.py +51 -28
- mcp_bridge/tools/lsp/tools.py +98 -65
- mcp_bridge/tools/model_invoke.py +1047 -152
- mcp_bridge/tools/mux_client.py +75 -0
- mcp_bridge/tools/project_context.py +1 -2
- mcp_bridge/tools/query_classifier.py +132 -49
- mcp_bridge/tools/read_file.py +84 -0
- mcp_bridge/tools/replace.py +45 -0
- mcp_bridge/tools/run_shell_command.py +38 -0
- mcp_bridge/tools/search_enhancements.py +347 -0
- mcp_bridge/tools/semantic_search.py +677 -92
- mcp_bridge/tools/session_manager.py +0 -2
- mcp_bridge/tools/skill_loader.py +0 -1
- mcp_bridge/tools/task_runner.py +5 -7
- mcp_bridge/tools/templates.py +3 -3
- mcp_bridge/tools/tool_search.py +331 -0
- mcp_bridge/tools/write_file.py +29 -0
- mcp_bridge/update_manager.py +33 -37
- mcp_bridge/update_manager_pypi.py +6 -8
- mcp_bridge/utils/cache.py +82 -0
- mcp_bridge/utils/process.py +71 -0
- mcp_bridge/utils/session_state.py +51 -0
- mcp_bridge/utils/truncation.py +76 -0
- {stravinsky-0.4.18.dist-info → stravinsky-0.4.66.dist-info}/METADATA +84 -35
- stravinsky-0.4.66.dist-info/RECORD +198 -0
- {stravinsky-0.4.18.dist-info → stravinsky-0.4.66.dist-info}/entry_points.txt +1 -0
- stravinsky_claude_assets/HOOKS_INTEGRATION.md +316 -0
- stravinsky_claude_assets/agents/HOOKS.md +437 -0
- stravinsky_claude_assets/agents/code-reviewer.md +210 -0
- stravinsky_claude_assets/agents/comment_checker.md +580 -0
- stravinsky_claude_assets/agents/debugger.md +254 -0
- stravinsky_claude_assets/agents/delphi.md +495 -0
- stravinsky_claude_assets/agents/dewey.md +248 -0
- stravinsky_claude_assets/agents/explore.md +1198 -0
- stravinsky_claude_assets/agents/frontend.md +472 -0
- stravinsky_claude_assets/agents/implementation-lead.md +164 -0
- stravinsky_claude_assets/agents/momus.md +464 -0
- stravinsky_claude_assets/agents/research-lead.md +141 -0
- stravinsky_claude_assets/agents/stravinsky.md +730 -0
- stravinsky_claude_assets/commands/delphi.md +9 -0
- stravinsky_claude_assets/commands/dewey.md +54 -0
- stravinsky_claude_assets/commands/git-master.md +112 -0
- stravinsky_claude_assets/commands/index.md +49 -0
- stravinsky_claude_assets/commands/publish.md +86 -0
- stravinsky_claude_assets/commands/review.md +73 -0
- stravinsky_claude_assets/commands/str/agent_cancel.md +70 -0
- stravinsky_claude_assets/commands/str/agent_list.md +56 -0
- stravinsky_claude_assets/commands/str/agent_output.md +92 -0
- stravinsky_claude_assets/commands/str/agent_progress.md +74 -0
- stravinsky_claude_assets/commands/str/agent_retry.md +94 -0
- stravinsky_claude_assets/commands/str/cancel.md +51 -0
- stravinsky_claude_assets/commands/str/clean.md +97 -0
- stravinsky_claude_assets/commands/str/continue.md +38 -0
- stravinsky_claude_assets/commands/str/index.md +199 -0
- stravinsky_claude_assets/commands/str/list_watchers.md +96 -0
- stravinsky_claude_assets/commands/str/search.md +205 -0
- stravinsky_claude_assets/commands/str/start_filewatch.md +136 -0
- stravinsky_claude_assets/commands/str/stats.md +71 -0
- stravinsky_claude_assets/commands/str/stop_filewatch.md +89 -0
- stravinsky_claude_assets/commands/str/unwatch.md +42 -0
- stravinsky_claude_assets/commands/str/watch.md +45 -0
- stravinsky_claude_assets/commands/strav.md +53 -0
- stravinsky_claude_assets/commands/stravinsky.md +292 -0
- stravinsky_claude_assets/commands/verify.md +60 -0
- stravinsky_claude_assets/commands/version.md +5 -0
- stravinsky_claude_assets/hooks/README.md +248 -0
- stravinsky_claude_assets/hooks/comment_checker.py +193 -0
- stravinsky_claude_assets/hooks/context.py +38 -0
- stravinsky_claude_assets/hooks/context_monitor.py +153 -0
- stravinsky_claude_assets/hooks/dependency_tracker.py +73 -0
- stravinsky_claude_assets/hooks/edit_recovery.py +46 -0
- stravinsky_claude_assets/hooks/execution_state_tracker.py +68 -0
- stravinsky_claude_assets/hooks/notification_hook.py +103 -0
- stravinsky_claude_assets/hooks/notification_hook_v2.py +96 -0
- stravinsky_claude_assets/hooks/parallel_execution.py +241 -0
- stravinsky_claude_assets/hooks/parallel_reinforcement.py +106 -0
- stravinsky_claude_assets/hooks/parallel_reinforcement_v2.py +112 -0
- stravinsky_claude_assets/hooks/pre_compact.py +123 -0
- stravinsky_claude_assets/hooks/ralph_loop.py +173 -0
- stravinsky_claude_assets/hooks/session_recovery.py +263 -0
- stravinsky_claude_assets/hooks/stop_hook.py +89 -0
- stravinsky_claude_assets/hooks/stravinsky_metrics.py +164 -0
- stravinsky_claude_assets/hooks/stravinsky_mode.py +146 -0
- stravinsky_claude_assets/hooks/subagent_stop.py +98 -0
- stravinsky_claude_assets/hooks/todo_continuation.py +111 -0
- stravinsky_claude_assets/hooks/todo_delegation.py +96 -0
- stravinsky_claude_assets/hooks/tool_messaging.py +281 -0
- stravinsky_claude_assets/hooks/truncator.py +23 -0
- stravinsky_claude_assets/rules/deployment_safety.md +51 -0
- stravinsky_claude_assets/rules/integration_wiring.md +89 -0
- stravinsky_claude_assets/rules/pypi_deployment.md +220 -0
- stravinsky_claude_assets/rules/stravinsky_orchestrator.md +32 -0
- stravinsky_claude_assets/settings.json +152 -0
- stravinsky_claude_assets/skills/chrome-devtools/SKILL.md +81 -0
- stravinsky_claude_assets/skills/sqlite/SKILL.md +77 -0
- stravinsky_claude_assets/skills/supabase/SKILL.md +74 -0
- stravinsky_claude_assets/task_dependencies.json +34 -0
- stravinsky-0.4.18.dist-info/RECORD +0 -88
- {stravinsky-0.4.18.dist-info → stravinsky-0.4.66.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
# Native Hooks in Stravinsky Orchestrator
|
|
2
|
+
|
|
3
|
+
The Stravinsky orchestrator native subagent uses **native Claude Code hooks** to control delegation behavior.
|
|
4
|
+
|
|
5
|
+
## Hook Architecture
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
User Request
|
|
9
|
+
↓
|
|
10
|
+
Claude Code (main)
|
|
11
|
+
↓
|
|
12
|
+
Auto-delegates to stravinsky native subagent
|
|
13
|
+
↓
|
|
14
|
+
PreToolUse Hook (in orchestrator)
|
|
15
|
+
├→ Intercepts: Read, Grep, Bash, Glob
|
|
16
|
+
├→ Blocks: Return exit code 2 or {"decision": "block"}
|
|
17
|
+
└→ Delegates: Task tool → specialist native subagents
|
|
18
|
+
├→ explore.md (code search)
|
|
19
|
+
├→ dewey.md (documentation)
|
|
20
|
+
├→ code-reviewer.md (quality analysis)
|
|
21
|
+
├→ debugger.md (root cause)
|
|
22
|
+
└→ frontend.md (UI implementation)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Hook Types Available
|
|
26
|
+
|
|
27
|
+
| Hook | When It Fires | Can Block? | Use In Orchestrator |
|
|
28
|
+
|------|---------------|------------|---------------------|
|
|
29
|
+
| **PreToolUse** | Before any tool executes | ✅ Yes | Control delegation (block direct tools, use Task instead) |
|
|
30
|
+
| **PostToolUse** | After tool completes | ❌ No | Result aggregation, metrics |
|
|
31
|
+
| **UserPromptSubmit** | Before prompt sent to LLM | ✅ Yes | Context injection, preprocessing |
|
|
32
|
+
| **PreCompact** | Before context compression | ❌ No | Save state before compaction |
|
|
33
|
+
| **SessionEnd** | When session terminates | ❌ No | Cleanup, final reporting |
|
|
34
|
+
|
|
35
|
+
## PreToolUse Hook for Delegation
|
|
36
|
+
|
|
37
|
+
The orchestrator uses `PreToolUse` to intercept direct tool calls and delegate to specialists instead.
|
|
38
|
+
|
|
39
|
+
### Example: Delegating Read/Grep to Explore Agent
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
#!/usr/bin/env bash
|
|
43
|
+
# .claude/agents/hooks/pre_tool_use.sh
|
|
44
|
+
|
|
45
|
+
# Read stdin JSON
|
|
46
|
+
input=$(cat)
|
|
47
|
+
|
|
48
|
+
# Parse tool name and args
|
|
49
|
+
tool=$(echo "$input" | jq -r '.tool')
|
|
50
|
+
args=$(echo "$input" | jq -r '.args')
|
|
51
|
+
|
|
52
|
+
# Delegation logic
|
|
53
|
+
case "$tool" in
|
|
54
|
+
"Read"|"Grep"|"Glob")
|
|
55
|
+
# Complex search → Delegate to explore agent
|
|
56
|
+
if should_delegate_search "$args"; then
|
|
57
|
+
# Block the native tool
|
|
58
|
+
echo '{"decision": "block", "reason": "Delegating to explore specialist"}' | jq -c
|
|
59
|
+
|
|
60
|
+
# Trigger Task tool delegation
|
|
61
|
+
# (This would be handled by the orchestrator's system prompt)
|
|
62
|
+
exit 2 # Block native tool execution
|
|
63
|
+
fi
|
|
64
|
+
;;
|
|
65
|
+
|
|
66
|
+
"Edit"|"Write")
|
|
67
|
+
# Let these through - orchestrator can edit directly
|
|
68
|
+
echo '{"decision": "allow"}' | jq -c
|
|
69
|
+
exit 0
|
|
70
|
+
;;
|
|
71
|
+
|
|
72
|
+
"Bash")
|
|
73
|
+
# Only allow safe commands
|
|
74
|
+
command=$(echo "$args" | jq -r '.command')
|
|
75
|
+
if is_safe_command "$command"; then
|
|
76
|
+
echo '{"decision": "allow"}' | jq -c
|
|
77
|
+
exit 0
|
|
78
|
+
else
|
|
79
|
+
echo '{"decision": "block", "reason": "Unsafe command - requires review"}' | jq -c
|
|
80
|
+
exit 2
|
|
81
|
+
fi
|
|
82
|
+
;;
|
|
83
|
+
|
|
84
|
+
*)
|
|
85
|
+
# Allow all other tools
|
|
86
|
+
echo '{"decision": "allow"}' | jq -c
|
|
87
|
+
exit 0
|
|
88
|
+
;;
|
|
89
|
+
esac
|
|
90
|
+
|
|
91
|
+
# Helper functions
|
|
92
|
+
should_delegate_search() {
|
|
93
|
+
local args="$1"
|
|
94
|
+
|
|
95
|
+
# Delegate if:
|
|
96
|
+
# - Complex pattern matching (AST search)
|
|
97
|
+
# - Multi-file search (grep across codebase)
|
|
98
|
+
# - Structural analysis
|
|
99
|
+
|
|
100
|
+
# Simple heuristic: delegate if searching more than 3 files
|
|
101
|
+
file_count=$(echo "$args" | jq -r '.pattern' | wc -w)
|
|
102
|
+
[[ $file_count -gt 3 ]]
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
is_safe_command() {
|
|
106
|
+
local cmd="$1"
|
|
107
|
+
|
|
108
|
+
# Allow: git, ls, pwd, echo
|
|
109
|
+
# Block: rm, dd, mkfs, sudo
|
|
110
|
+
|
|
111
|
+
if echo "$cmd" | grep -qE "^(git|ls|pwd|echo|cat|head|tail)"; then
|
|
112
|
+
return 0 # Safe
|
|
113
|
+
else
|
|
114
|
+
return 1 # Unsafe
|
|
115
|
+
fi
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## PostToolUse Hook for Result Aggregation
|
|
120
|
+
|
|
121
|
+
After Task tool completes, aggregate results from specialist agents.
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
#!/usr/bin/env bash
|
|
125
|
+
# .claude/agents/hooks/post_tool_use.sh
|
|
126
|
+
|
|
127
|
+
input=$(cat)
|
|
128
|
+
tool=$(echo "$input" | jq -r '.tool')
|
|
129
|
+
result=$(echo "$input" | jq -r '.result')
|
|
130
|
+
|
|
131
|
+
case "$tool" in
|
|
132
|
+
"Task")
|
|
133
|
+
# Specialist agent completed
|
|
134
|
+
agent_type=$(echo "$input" | jq -r '.args.subagent_type')
|
|
135
|
+
|
|
136
|
+
# Log completion
|
|
137
|
+
log_agent_completion "$agent_type" "$result"
|
|
138
|
+
|
|
139
|
+
# Update orchestrator state
|
|
140
|
+
update_task_graph "$agent_type" "completed"
|
|
141
|
+
|
|
142
|
+
# Check if all parallel tasks complete
|
|
143
|
+
if all_tasks_complete; then
|
|
144
|
+
trigger_synthesis_phase
|
|
145
|
+
fi
|
|
146
|
+
;;
|
|
147
|
+
esac
|
|
148
|
+
|
|
149
|
+
# Pass through result unmodified
|
|
150
|
+
echo "$result"
|
|
151
|
+
exit 0
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Hook Configuration
|
|
155
|
+
|
|
156
|
+
Hooks are configured in the orchestrator's `.claude/settings.json`:
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"hooks": {
|
|
161
|
+
"PreToolUse": [
|
|
162
|
+
{
|
|
163
|
+
"command": "/absolute/path/to/.claude/agents/hooks/pre_tool_use.sh",
|
|
164
|
+
"description": "Delegation control for orchestrator"
|
|
165
|
+
}
|
|
166
|
+
],
|
|
167
|
+
"PostToolUse": [
|
|
168
|
+
{
|
|
169
|
+
"command": "/absolute/path/to/.claude/agents/hooks/post_tool_use.sh",
|
|
170
|
+
"description": "Result aggregation for orchestrator"
|
|
171
|
+
}
|
|
172
|
+
],
|
|
173
|
+
"UserPromptSubmit": [
|
|
174
|
+
{
|
|
175
|
+
"command": "/absolute/path/to/.claude/agents/hooks/user_prompt_submit.sh",
|
|
176
|
+
"description": "Context injection for orchestrator"
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Delegation Patterns
|
|
184
|
+
|
|
185
|
+
### Pattern 1: Automatic Delegation on Tool Use
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
User: "Find all authentication implementations"
|
|
189
|
+
↓
|
|
190
|
+
Stravinsky orchestrator (native subagent)
|
|
191
|
+
↓
|
|
192
|
+
PreToolUse hook detects complex search
|
|
193
|
+
├→ Blocks: Read/Grep tools
|
|
194
|
+
└→ Orchestrator prompt triggers: Task(subagent_type="explore", ...)
|
|
195
|
+
↓
|
|
196
|
+
Explore specialist executes search
|
|
197
|
+
↓
|
|
198
|
+
PostToolUse hook aggregates results
|
|
199
|
+
↓
|
|
200
|
+
Orchestrator synthesizes and responds
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Pattern 2: Conditional Delegation
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
User: "Review this code for security issues"
|
|
207
|
+
↓
|
|
208
|
+
Stravinsky orchestrator
|
|
209
|
+
↓
|
|
210
|
+
System prompt recognizes: "review" + "security" → delegate to code-reviewer
|
|
211
|
+
↓
|
|
212
|
+
Task(subagent_type="code-reviewer", prompt="Review for security...")
|
|
213
|
+
↓
|
|
214
|
+
Code-reviewer specialist analyzes code
|
|
215
|
+
↓
|
|
216
|
+
Returns structured review
|
|
217
|
+
↓
|
|
218
|
+
Orchestrator presents to user
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Pattern 3: Multi-Agent Parallel Execution
|
|
222
|
+
|
|
223
|
+
```
|
|
224
|
+
User: "Implement JWT authentication"
|
|
225
|
+
↓
|
|
226
|
+
Stravinsky orchestrator
|
|
227
|
+
↓
|
|
228
|
+
TodoWrite: [Research JWT, Find examples, Implement, Review, Test]
|
|
229
|
+
↓
|
|
230
|
+
SAME RESPONSE: Multiple Task() calls
|
|
231
|
+
├→ Task(subagent_type="dewey", prompt="Research JWT best practices")
|
|
232
|
+
├→ Task(subagent_type="explore", prompt="Find existing auth patterns")
|
|
233
|
+
└→ Task(subagent_type="code-reviewer", prompt="Review security")
|
|
234
|
+
↓
|
|
235
|
+
All specialists execute in parallel
|
|
236
|
+
↓
|
|
237
|
+
PostToolUse hooks aggregate results
|
|
238
|
+
↓
|
|
239
|
+
Orchestrator synthesizes and implements
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Hook Execution Flow
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
┌─────────────────────────────────────────┐
|
|
246
|
+
│ User submits prompt │
|
|
247
|
+
└───────────────┬─────────────────────────┘
|
|
248
|
+
↓
|
|
249
|
+
┌─────────────────────────────────────────┐
|
|
250
|
+
│ UserPromptSubmit Hook │
|
|
251
|
+
│ - Inject context (CLAUDE.md, README) │
|
|
252
|
+
│ - Preprocess prompt │
|
|
253
|
+
└───────────────┬─────────────────────────┘
|
|
254
|
+
↓
|
|
255
|
+
┌─────────────────────────────────────────┐
|
|
256
|
+
│ Claude Code auto-delegates to stravinsky │
|
|
257
|
+
│ (based on description matching) │
|
|
258
|
+
└───────────────┬─────────────────────────┘
|
|
259
|
+
↓
|
|
260
|
+
┌─────────────────────────────────────────┐
|
|
261
|
+
│ Stravinsky orchestrator processes │
|
|
262
|
+
│ - TodoWrite (plan tasks) │
|
|
263
|
+
│ - Decides on delegation strategy │
|
|
264
|
+
└───────────────┬─────────────────────────┘
|
|
265
|
+
↓
|
|
266
|
+
┌─────────────────────────────────────────┐
|
|
267
|
+
│ PreToolUse Hook fires │
|
|
268
|
+
│ - Intercepts: Read, Grep, Glob, Bash │
|
|
269
|
+
│ - Decision: Allow or Block │
|
|
270
|
+
└───────────────┬─────────────────────────┘
|
|
271
|
+
↓
|
|
272
|
+
┌───────┴───────┐
|
|
273
|
+
↓ ↓
|
|
274
|
+
┌──────────────┐ ┌──────────────────────┐
|
|
275
|
+
│ ALLOW │ │ BLOCK │
|
|
276
|
+
│ Native tool │ │ Delegate via Task │
|
|
277
|
+
│ executes │ │ to specialist agent │
|
|
278
|
+
└──────┬───────┘ └──────┬───────────────┘
|
|
279
|
+
│ │
|
|
280
|
+
└────────┬───────┘
|
|
281
|
+
↓
|
|
282
|
+
┌─────────────────────────────────────────┐
|
|
283
|
+
│ PostToolUse Hook fires │
|
|
284
|
+
│ - Log completion │
|
|
285
|
+
│ - Aggregate results │
|
|
286
|
+
│ - Update task graph │
|
|
287
|
+
└───────────────┬─────────────────────────┘
|
|
288
|
+
↓
|
|
289
|
+
┌─────────────────────────────────────────┐
|
|
290
|
+
│ Orchestrator synthesizes results │
|
|
291
|
+
│ - Combines specialist outputs │
|
|
292
|
+
│ - Updates todos │
|
|
293
|
+
│ - Responds to user │
|
|
294
|
+
└─────────────────────────────────────────┘
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Benefits of This Architecture
|
|
298
|
+
|
|
299
|
+
1. **Automatic Delegation**: Hooks detect when to delegate automatically
|
|
300
|
+
2. **Hard Boundaries**: PreToolUse can block unsafe operations
|
|
301
|
+
3. **Context Isolation**: Specialists run as separate subagents
|
|
302
|
+
4. **Parallel Execution**: Multiple Task() calls execute concurrently
|
|
303
|
+
5. **Result Aggregation**: PostToolUse hooks combine outputs
|
|
304
|
+
6. **Multi-Model Routing**: Specialists can use invoke_gemini/openai MCP tools
|
|
305
|
+
7. **Security**: Orchestrator controls what tools specialists can access
|
|
306
|
+
|
|
307
|
+
## Implementation Status
|
|
308
|
+
|
|
309
|
+
- [x] Stravinsky orchestrator native subagent (.claude/agents/stravinsky.md)
|
|
310
|
+
- [x] Specialist subagent configs (explore, dewey, code-reviewer, debugger, frontend)
|
|
311
|
+
- [ ] PreToolUse hook implementation (.claude/agents/hooks/pre_tool_use.sh)
|
|
312
|
+
- [ ] PostToolUse hook implementation (.claude/agents/hooks/post_tool_use.sh)
|
|
313
|
+
- [ ] Hook registration in .claude/settings.json
|
|
314
|
+
- [ ] Testing and validation
|
|
315
|
+
|
|
316
|
+
## Next Steps
|
|
317
|
+
|
|
318
|
+
1. Implement PreToolUse hook script
|
|
319
|
+
2. Implement PostToolUse hook script
|
|
320
|
+
3. Register hooks in .claude/settings.json
|
|
321
|
+
4. Test delegation patterns
|
|
322
|
+
5. Measure: delegation accuracy, context isolation, performance
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
## Agent Cost Classification & Thinking Budget
|
|
327
|
+
|
|
328
|
+
### Cost-Based Routing (oh-my-opencode Pattern)
|
|
329
|
+
|
|
330
|
+
Each agent has cost/execution metadata in YAML frontmatter:
|
|
331
|
+
|
|
332
|
+
```yaml
|
|
333
|
+
---
|
|
334
|
+
name: agent-name
|
|
335
|
+
model: sonnet
|
|
336
|
+
cost: free | cheap | medium | expensive # Cost tier
|
|
337
|
+
execution: async | blocking | primary # Execution pattern
|
|
338
|
+
temperature: 0.1 # Model temperature (0.0-2.0)
|
|
339
|
+
thinking_budget: 32000 # Extended thinking budget (optional, for Opus/GPT)
|
|
340
|
+
---
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### Agent Classification
|
|
344
|
+
|
|
345
|
+
| Agent | Cost | Execution | When to Delegate |
|
|
346
|
+
|-------|------|-----------|------------------|
|
|
347
|
+
| **explore** | Free | Async | Always (code search is free) |
|
|
348
|
+
| **dewey** | Cheap | Async | Always (docs research is cheap) |
|
|
349
|
+
| **code-reviewer** | Cheap | Async | Always (quality checks are cheap) |
|
|
350
|
+
| **debugger** | Medium | Blocking | After 2+ failed fix attempts |
|
|
351
|
+
| **frontend** | Medium | Blocking | ALL visual changes (no exceptions) |
|
|
352
|
+
| **delphi** | Expensive | Blocking | After 3+ failures, architecture decisions |
|
|
353
|
+
| **stravinsky** | Moderate | Primary | Auto-delegated orchestrator |
|
|
354
|
+
|
|
355
|
+
### Execution Patterns
|
|
356
|
+
|
|
357
|
+
**Async (Non-Blocking)**:
|
|
358
|
+
- Agent runs in parallel via Task tool
|
|
359
|
+
- Orchestrator continues immediately
|
|
360
|
+
- Results collected when needed
|
|
361
|
+
- Use for: free/cheap agents (explore, dewey, code-reviewer)
|
|
362
|
+
|
|
363
|
+
**Blocking (Synchronous)**:
|
|
364
|
+
- Orchestrator waits for result
|
|
365
|
+
- Used when decision depends on output
|
|
366
|
+
- Use for: expensive agents (delphi), visual work (frontend), debugging (debugger)
|
|
367
|
+
|
|
368
|
+
**Primary**:
|
|
369
|
+
- The orchestrator itself (stravinsky)
|
|
370
|
+
- Manages all delegation
|
|
371
|
+
- Never blocks (delegates instead)
|
|
372
|
+
|
|
373
|
+
### Extended Thinking Budget
|
|
374
|
+
|
|
375
|
+
**What It Is**:
|
|
376
|
+
- Extended reasoning capability for complex tasks
|
|
377
|
+
- Claude Opus 4.5 and GPT-5.2 support thinking blocks
|
|
378
|
+
- Allows model to "think out loud" before responding
|
|
379
|
+
- Improves accuracy for complex analysis
|
|
380
|
+
|
|
381
|
+
**Configuration**:
|
|
382
|
+
|
|
383
|
+
```yaml
|
|
384
|
+
# In agent YAML frontmatter:
|
|
385
|
+
thinking_budget: 32000 # 32k tokens for thinking (oh-my-opencode Sisyphus pattern)
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
**Which Agents Use It**:
|
|
389
|
+
- **stravinsky** (orchestrator): 32k thinking for complex task planning
|
|
390
|
+
- **delphi** (strategic advisor): 32k thinking for architectural decisions
|
|
391
|
+
- **Others**: No extended thinking (focus on execution)
|
|
392
|
+
|
|
393
|
+
**How It Works**:
|
|
394
|
+
|
|
395
|
+
For Claude models with extended thinking:
|
|
396
|
+
```xml
|
|
397
|
+
<thinking>
|
|
398
|
+
[Model's internal reasoning - up to 32k tokens]
|
|
399
|
+
- Analyzing the problem
|
|
400
|
+
- Considering multiple approaches
|
|
401
|
+
- Evaluating trade-offs
|
|
402
|
+
- Planning implementation strategy
|
|
403
|
+
</thinking>
|
|
404
|
+
|
|
405
|
+
[Final response based on extended reasoning]
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
For GPT models (via invoke_openai):
|
|
409
|
+
```python
|
|
410
|
+
invoke_openai(
|
|
411
|
+
prompt="...",
|
|
412
|
+
model="gpt-5.2-medium",
|
|
413
|
+
reasoning_effort="medium", # Equivalent to thinking budget
|
|
414
|
+
text_verbosity="high" # Get detailed reasoning
|
|
415
|
+
)
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### Cost Optimization Rules
|
|
419
|
+
|
|
420
|
+
**Always Delegate Async** (oh-my-opencode rule):
|
|
421
|
+
- explore: Free, always background
|
|
422
|
+
- dewey: Cheap, always background
|
|
423
|
+
- code-reviewer: Cheap, always background
|
|
424
|
+
|
|
425
|
+
**Use Blocking Sparingly**:
|
|
426
|
+
- debugger: Only after 2+ failed attempts
|
|
427
|
+
- frontend: Only for visual changes (but ALWAYS for visual)
|
|
428
|
+
- delphi: Only after 3+ failures OR complex architecture
|
|
429
|
+
|
|
430
|
+
**Never Work Alone** (delegation discipline):
|
|
431
|
+
- Orchestrator blocks Read/Grep/Bash via PreToolUse hooks
|
|
432
|
+
- Forces delegation to specialists
|
|
433
|
+
- Prevents expensive orchestrator from doing cheap work
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
**Key Insight**: Native hooks in the orchestrator subagent enable **automatic delegation** to specialist agents while maintaining **hard security boundaries** and **context isolation**. This is the CORRECT architecture the user has been advocating for.
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code-reviewer
|
|
3
|
+
description: |
|
|
4
|
+
Code review and quality analysis specialist. Use for:
|
|
5
|
+
- Reviewing code changes for bugs and security issues
|
|
6
|
+
- Analyzing code quality and best practices
|
|
7
|
+
- Detecting anti-patterns and vulnerabilities
|
|
8
|
+
- Providing improvement recommendations
|
|
9
|
+
tools: Read, Grep, Glob, Bash, mcp__stravinsky__lsp_diagnostics, mcp__stravinsky__lsp_hover, mcp__stravinsky__lsp_find_references, mcp__stravinsky__ast_grep_search, mcp__stravinsky__grep_search
|
|
10
|
+
model: gemini-3-flash
|
|
11
|
+
cost_tier: cheap # Haiku wrapper ($0.25/1M) + Gemini Flash (free/cheap)
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
You are the **Code Reviewer** specialist - focused on code quality, security, and best practices.
|
|
15
|
+
|
|
16
|
+
## Core Capabilities
|
|
17
|
+
|
|
18
|
+
- **Static Analysis**: lsp_diagnostics for errors and warnings
|
|
19
|
+
- **File Reading**: Read tool for analyzing implementation
|
|
20
|
+
- **Code Search**: grep_search, ast_grep_search for pattern detection
|
|
21
|
+
- **LSP Integration**: lsp_find_references, lsp_document_symbols
|
|
22
|
+
- **Claude Sonnet**: Native model for reasoning about code quality
|
|
23
|
+
|
|
24
|
+
## When You're Called
|
|
25
|
+
|
|
26
|
+
You are delegated by the Stravinsky orchestrator for:
|
|
27
|
+
- Code review (pull requests, changes)
|
|
28
|
+
- Security vulnerability detection
|
|
29
|
+
- Code quality analysis
|
|
30
|
+
- Best practice compliance
|
|
31
|
+
- Bug detection and prevention
|
|
32
|
+
|
|
33
|
+
## Review Process
|
|
34
|
+
|
|
35
|
+
### Step 1: Understand Scope
|
|
36
|
+
|
|
37
|
+
Parse the review request:
|
|
38
|
+
- What files changed?
|
|
39
|
+
- What is the purpose of the changes?
|
|
40
|
+
- What are the acceptance criteria?
|
|
41
|
+
|
|
42
|
+
### Step 2: Static Analysis
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
1. lsp_diagnostics on all changed files
|
|
46
|
+
2. Check for errors, warnings, type issues
|
|
47
|
+
3. Verify build would pass
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Step 3: Security Analysis
|
|
51
|
+
|
|
52
|
+
Look for OWASP Top 10 vulnerabilities:
|
|
53
|
+
- SQL Injection (raw queries, string concatenation)
|
|
54
|
+
- XSS (unescaped user input in HTML)
|
|
55
|
+
- Command Injection (shell execution with user input)
|
|
56
|
+
- Path Traversal (file operations with user-controlled paths)
|
|
57
|
+
- Insecure Deserialization
|
|
58
|
+
- Authentication/Authorization flaws
|
|
59
|
+
- Exposed secrets (API keys, passwords in code)
|
|
60
|
+
|
|
61
|
+
### Step 4: Code Quality
|
|
62
|
+
|
|
63
|
+
Analyze for:
|
|
64
|
+
- **Complexity**: Overly complex functions (>50 lines)
|
|
65
|
+
- **Duplication**: Repeated code that should be abstracted
|
|
66
|
+
- **Naming**: Clear, descriptive variable/function names
|
|
67
|
+
- **Comments**: Code is self-documenting vs needs comments
|
|
68
|
+
- **Error Handling**: Proper try/catch, validation
|
|
69
|
+
- **Testing**: Test coverage for new code
|
|
70
|
+
|
|
71
|
+
### Step 5: Best Practices
|
|
72
|
+
|
|
73
|
+
Check for:
|
|
74
|
+
- **Language idioms**: Pythonic code, proper TypeScript patterns
|
|
75
|
+
- **Framework conventions**: Following project patterns
|
|
76
|
+
- **Performance**: Obvious inefficiencies (N+1 queries, nested loops)
|
|
77
|
+
- **Maintainability**: Clear separation of concerns
|
|
78
|
+
|
|
79
|
+
## Output Format
|
|
80
|
+
|
|
81
|
+
Always return structured review:
|
|
82
|
+
|
|
83
|
+
```markdown
|
|
84
|
+
## Code Review Summary
|
|
85
|
+
|
|
86
|
+
**Overall**: [APPROVE / REQUEST CHANGES / COMMENT]
|
|
87
|
+
|
|
88
|
+
**Critical Issues**: [Number] (blocking)
|
|
89
|
+
**Warnings**: [Number] (non-blocking)
|
|
90
|
+
**Suggestions**: [Number] (optional improvements)
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Critical Issues (Must Fix)
|
|
95
|
+
|
|
96
|
+
### 1. SQL Injection Vulnerability
|
|
97
|
+
**File**: `src/api/users.py:45`
|
|
98
|
+
**Issue**: Raw SQL with string formatting
|
|
99
|
+
```python
|
|
100
|
+
# INSECURE
|
|
101
|
+
query = f"SELECT * FROM users WHERE id = {user_id}"
|
|
102
|
+
```
|
|
103
|
+
**Fix**:
|
|
104
|
+
```python
|
|
105
|
+
# SECURE
|
|
106
|
+
query = "SELECT * FROM users WHERE id = ?"
|
|
107
|
+
cursor.execute(query, (user_id,))
|
|
108
|
+
```
|
|
109
|
+
**Severity**: CRITICAL (CWE-89)
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Warnings (Should Fix)
|
|
114
|
+
|
|
115
|
+
### 1. Missing Error Handling
|
|
116
|
+
**File**: `src/api/auth.py:67`
|
|
117
|
+
**Issue**: API call without try/catch
|
|
118
|
+
```python
|
|
119
|
+
# Current
|
|
120
|
+
response = requests.get(api_url)
|
|
121
|
+
```
|
|
122
|
+
**Suggestion**:
|
|
123
|
+
```python
|
|
124
|
+
# Better
|
|
125
|
+
try:
|
|
126
|
+
response = requests.get(api_url, timeout=5)
|
|
127
|
+
response.raise_for_status()
|
|
128
|
+
except requests.RequestException as e:
|
|
129
|
+
logger.error(f"API call failed: {e}")
|
|
130
|
+
return None
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Suggestions (Nice to Have)
|
|
136
|
+
|
|
137
|
+
### 1. Extract Repeated Logic
|
|
138
|
+
**Files**: `utils.py:23`, `helpers.py:45`
|
|
139
|
+
**Observation**: Same validation logic duplicated
|
|
140
|
+
**Suggestion**: Extract to shared validator function
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Test Coverage
|
|
145
|
+
|
|
146
|
+
**New Code**: 15 lines
|
|
147
|
+
**Covered by Tests**: 0 lines (0%)
|
|
148
|
+
**Recommendation**: Add unit tests for new authentication logic
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Compliance Checklist
|
|
153
|
+
|
|
154
|
+
- [x] No type errors (lsp_diagnostics clean)
|
|
155
|
+
- [x] Follows existing code style
|
|
156
|
+
- [ ] Security vulnerabilities addressed
|
|
157
|
+
- [ ] Error handling added
|
|
158
|
+
- [ ] Tests included
|
|
159
|
+
- [x] Documentation updated
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Recommendation
|
|
164
|
+
|
|
165
|
+
**REQUEST CHANGES**: Fix SQL injection vulnerability before merge. Add error handling and tests.
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Review Severity Levels
|
|
169
|
+
|
|
170
|
+
| Level | When to Use | Examples |
|
|
171
|
+
|-------|-------------|----------|
|
|
172
|
+
| **CRITICAL** | Security vulnerabilities, data loss risk | SQL injection, XSS, exposed secrets |
|
|
173
|
+
| **HIGH** | Bugs that will cause failures | Null pointer, logic errors, race conditions |
|
|
174
|
+
| **MEDIUM** | Code quality issues | Missing error handling, poor naming, duplication |
|
|
175
|
+
| **LOW** | Style and suggestions | Formatting, comments, micro-optimizations |
|
|
176
|
+
|
|
177
|
+
## Security Checklist
|
|
178
|
+
|
|
179
|
+
Always check for:
|
|
180
|
+
- [ ] SQL queries use parameterization (not string concat)
|
|
181
|
+
- [ ] User input is validated and sanitized
|
|
182
|
+
- [ ] Secrets are in environment variables (not hardcoded)
|
|
183
|
+
- [ ] Authentication is required for sensitive endpoints
|
|
184
|
+
- [ ] Authorization checks user permissions
|
|
185
|
+
- [ ] File paths are validated (no path traversal)
|
|
186
|
+
- [ ] Cryptography uses secure algorithms (bcrypt, AES-256)
|
|
187
|
+
- [ ] Dependencies have no known vulnerabilities
|
|
188
|
+
|
|
189
|
+
## Code Quality Checklist
|
|
190
|
+
|
|
191
|
+
Always check for:
|
|
192
|
+
- [ ] Functions are <50 lines (single responsibility)
|
|
193
|
+
- [ ] No deeply nested conditionals (>3 levels)
|
|
194
|
+
- [ ] Error cases are handled explicitly
|
|
195
|
+
- [ ] Variable names are descriptive
|
|
196
|
+
- [ ] No magic numbers (use named constants)
|
|
197
|
+
- [ ] No commented-out code (use git history)
|
|
198
|
+
- [ ] Tests exist for new functionality
|
|
199
|
+
|
|
200
|
+
## Constraints
|
|
201
|
+
|
|
202
|
+
- **Constructive feedback**: Focus on "why" not just "what"
|
|
203
|
+
- **Actionable recommendations**: Provide fix examples, not just criticism
|
|
204
|
+
- **Prioritize**: Critical issues first, then warnings, then suggestions
|
|
205
|
+
- **Respect context**: Consider existing codebase patterns
|
|
206
|
+
- **Fast review**: Aim for <5 minutes per file
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
**Remember**: You are a code reviewer. Find issues, explain impact, provide actionable fixes, and return structured recommendations to the orchestrator.
|