claude-flow-novice 1.6.3 → 1.6.4

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.
Files changed (27) hide show
  1. package/.claude/settings.json +12 -2
  2. package/.claude/settings.local.json +3 -2
  3. package/.claude-flow-novice/dist/src/coordination/index.js +3 -0
  4. package/.claude-flow-novice/dist/src/coordination/index.js.map +1 -1
  5. package/.claude-flow-novice/dist/src/coordination/v1-transparency/interfaces/v1-transparency-system.js +12 -0
  6. package/.claude-flow-novice/dist/src/coordination/v1-transparency/interfaces/v1-transparency-system.js.map +1 -0
  7. package/.claude-flow-novice/dist/src/coordination/v1-transparency/v1-to-v2-bridge.js +433 -0
  8. package/.claude-flow-novice/dist/src/coordination/v1-transparency/v1-to-v2-bridge.js.map +1 -0
  9. package/.claude-flow-novice/dist/src/coordination/v1-transparency/v1-transparency-adapter.js +1468 -0
  10. package/.claude-flow-novice/dist/src/coordination/v1-transparency/v1-transparency-adapter.js.map +1 -0
  11. package/.claude-flow-novice/dist/src/monitoring/apm/apm-integration.js +5 -0
  12. package/.claude-flow-novice/dist/src/monitoring/apm/apm-integration.js.map +1 -1
  13. package/.claude-flow-novice/dist/src/providers/provider-manager.js +5 -3
  14. package/.claude-flow-novice/dist/src/providers/provider-manager.js.map +1 -1
  15. package/.claude-flow-novice/dist/src/providers/tiered-router.js +9 -17
  16. package/.claude-flow-novice/dist/src/providers/tiered-router.js.map +1 -1
  17. package/.claude-flow-novice/metrics.db +0 -0
  18. package/CLAUDE.md +72 -0
  19. package/config/hooks/post-edit-pipeline.js +68 -118
  20. package/config/hooks/pre-tool-memory-safety.js +209 -0
  21. package/package.json +6 -3
  22. package/scripts/cleanup-idle-sessions.sh +59 -0
  23. package/scripts/test-provider-routing.cjs +7 -9
  24. package/wiki/Provider-Routing.md +57 -69
  25. package/.claude-flow-novice/metrics.db-shm +0 -0
  26. package/.claude-flow-novice/metrics.db-wal +0 -0
  27. package/MEMORY_LEAK_ROOT_CAUSE.md +0 -149
@@ -1,17 +1,17 @@
1
1
  # Provider Routing
2
2
 
3
- Intelligent tiered provider routing system that automatically selects optimal AI providers based on agent profiles, task complexity, and cost optimization goals.
3
+ **UPDATED 2025-10-05:** Simplified 2-tier routing system for clarity and cost optimization.
4
4
 
5
5
  ---
6
6
 
7
7
  ## Overview
8
8
 
9
- Provider routing enables cost-effective LLM usage by automatically routing agent requests to the most appropriate provider:
9
+ Provider routing enables optimal LLM usage by automatically routing requests to the most appropriate provider:
10
10
 
11
- - **Profile-based overrides** - Agent profiles specify preferred providers
12
- - **Tiered fallback** - Automatic failover from free to paid tiers
13
- - **Cost optimization** - Up to 64% reduction in API costs
14
- - **Quality preservation** - Maintains output quality while reducing costs
11
+ - **Main chat quality** - Claude Max subscription for user-facing interactions
12
+ - **Agent cost optimization** - Z.ai for all Task tool agents
13
+ - **Simple configuration** - Only 2 tiers, easy to understand and maintain
14
+ - **Predictable routing** - Clear separation between main chat and agent operations
15
15
 
16
16
  ---
17
17
 
@@ -19,68 +19,57 @@ Provider routing enables cost-effective LLM usage by automatically routing agent
19
19
 
20
20
  ### Routing Priority
21
21
 
22
- Provider selection follows this priority hierarchy:
22
+ Provider selection follows this simplified hierarchy:
23
23
 
24
24
  ```
25
25
  1. Agent Profile Override (highest priority)
26
26
  └─> Profile.provider field (zai, anthropic, custom)
27
27
 
28
28
  2. Tiered Provider Router
29
- ├─> Tier 1: zai (free, rate limited)
30
- ├─> Tier 2: deepseek (budget-friendly)
31
- └─> Tier 3: anthropic (premium, fallback)
29
+ ├─> Tier 0: main-chat Anthropic Claude Max
30
+ └─> Tier 1: ALL Task tool agents → Z.ai
32
31
 
33
32
  3. Default Provider
34
33
  └─> anthropic (if no routing configured)
35
34
  ```
36
35
 
37
- ### Tier Characteristics
36
+ ### Current Tier Configuration
38
37
 
39
- | Tier | Provider | Cost | Rate Limit | Use Cases |
40
- |------|----------|------|------------|-----------|
41
- | **Tier 1** | zai | Free | 60 req/min | Non-critical tasks, research, drafting |
42
- | **Tier 2** | deepseek | Budget | 100 req/min | Standard development, testing |
43
- | **Tier 3** | anthropic | Premium | 1000 req/min | Critical tasks, production code |
38
+ | Tier | Provider | Agent Types | Use Case |
39
+ |------|----------|-------------|----------|
40
+ | **Tier 0** | Anthropic Claude Max | `main-chat` (default) | Main conversational interface |
41
+ | **Tier 1** | Z.ai | ALL other agents | Task tool agent swarms |
44
42
 
45
43
  ---
46
44
 
47
45
  ## Configuration
48
46
 
49
- ### Global Routing Setup
50
-
51
- Enable tiered routing in `.claude-flow/settings.json`:
52
-
53
- ```json
54
- {
55
- "providers": {
56
- "routing": {
57
- "enabled": true,
58
- "strategy": "tiered",
59
- "tiers": [
60
- {
61
- "name": "zai",
62
- "priority": 1,
63
- "rateLimit": 60,
64
- "fallbackOnError": true
65
- },
66
- {
67
- "name": "deepseek",
68
- "priority": 2,
69
- "rateLimit": 100,
70
- "fallbackOnError": true
71
- },
72
- {
73
- "name": "anthropic",
74
- "priority": 3,
75
- "rateLimit": 1000,
76
- "fallbackOnError": false
77
- }
78
- ]
79
- }
80
- }
81
- }
47
+ ### Current Configuration (Simplified 2-Tier System)
48
+
49
+ Tiered routing is configured in `src/providers/tiered-router.ts`:
50
+
51
+ ```typescript
52
+ const TIER_CONFIGS: TierConfig[] = [
53
+ {
54
+ name: "Tier 0: Main Chat (Claude Max)",
55
+ provider: "anthropic",
56
+ agentTypes: ["main-chat"],
57
+ priority: 0,
58
+ },
59
+ {
60
+ name: "Tier 1: Z.ai Agent Orchestration (ALL Task Tool Agents)",
61
+ provider: "zai",
62
+ agentTypes: [], // All agents EXCEPT "main-chat"
63
+ priority: 1,
64
+ },
65
+ ];
82
66
  ```
83
67
 
68
+ **Key Points:**
69
+ - **No configuration file needed** - routing is built into the code
70
+ - **Tier 0**: Only `main-chat` (default when no agentType)
71
+ - **Tier 1**: Everything else (fallback for all Task tool agents)
72
+
84
73
  ### Agent Profile Overrides
85
74
 
86
75
  Override routing for specific agents in `.claude/agents/[agent-name].md`:
@@ -108,22 +97,21 @@ Critical security auditing agent that requires premium provider.
108
97
 
109
98
  ## Usage Examples
110
99
 
111
- ### Example 1: Enable Tiered Routing
100
+ ### Example 1: Test Current Routing
112
101
 
113
102
  ```bash
114
- # Activate custom routing system
115
- /custom-routing-activate
103
+ # Test routing configuration
104
+ node scripts/test-provider-routing.cjs
116
105
 
117
106
  # Expected output:
118
- # ✅ Custom routing activated
119
- # Priority: Profile Tier 1 (zai) Tier 2 (deepseek) → Tier 3 (anthropic)
120
- # Cost savings: ~64% (free tier + budget fallback)
107
+ # ✅ Agents will route through tiered system:
108
+ # Tier 0: Main chatAnthropic Claude Max
109
+ # Tier 1: ALL Task tool agents Z.ai
121
110
  ```
122
111
 
123
112
  **What happens:**
124
- 1. All agents without profile overrides use zai (free) first
125
- 2. If zai fails/rate-limited, fallback to deepseek (budget)
126
- 3. If deepseek fails, fallback to anthropic (premium)
113
+ 1. Main chat (no agentType) defaults to "main-chat" Anthropic Claude Max
114
+ 2. ALL Task tool agents route to Z.ai (coder, tester, reviewer, etc.)
127
115
 
128
116
  ### Example 2: Profile-Based Override
129
117
 
@@ -137,8 +125,8 @@ reasoning: Architecture decisions require highest quality reasoning
137
125
  ```
138
126
 
139
127
  **Routing behavior:**
140
- - `system-architect` ALWAYS uses `anthropic` (ignores tiered routing)
141
- - Other agents use tiered routing (zaideepseekanthropic)
128
+ - `system-architect` ALWAYS uses `anthropic` (profile override)
129
+ - Other agents use tiered routing (main-chatanthropic, all others zai)
142
130
 
143
131
  ### Example 3: Mixed Agent Swarm
144
132
 
@@ -150,26 +138,26 @@ mcp__claude-flow-novice__swarm_init({
150
138
  })
151
139
 
152
140
  // Agent 1: researcher (no profile override)
153
- // → Uses zai (free tier, Tier 1)
141
+ // → Uses Z.ai (Tier 1, default for all agents)
154
142
  Task("Researcher", "Research JWT libraries", "researcher")
155
143
 
156
144
  // Agent 2: system-architect (profile: anthropic)
157
- // → Uses anthropic (premium, profile override)
145
+ // → Uses Anthropic (profile override)
158
146
  Task("Architect", "Design auth system", "system-architect")
159
147
 
160
148
  // Agent 3: coder (no profile override)
161
- // → Uses zai (free tier, Tier 1)
149
+ // → Uses Z.ai (Tier 1, default for all agents)
162
150
  Task("Coder", "Implement endpoints", "coder")
163
151
 
164
- // Agent 4: security-specialist (profile: anthropic)
165
- // → Uses anthropic (premium, profile override)
166
- Task("Security Auditor", "Audit auth", "security-specialist")
152
+ // Agent 4: tester (no profile override)
153
+ // → Uses Z.ai (Tier 1, default for all agents)
154
+ Task("Tester", "Test endpoints", "tester")
167
155
  ```
168
156
 
169
157
  **Cost breakdown:**
170
- - 2 agents on zai (free) = $0
171
- - 2 agents on anthropic (premium) = standard cost
172
- - **Total savings: ~50%** vs all-anthropic approach
158
+ - 3 agents on Z.ai (coder, researcher, tester) = lowest cost
159
+ - 1 agent on Anthropic (system-architect) = standard cost
160
+ - **Total savings: ~75%** vs all-anthropic approach
173
161
 
174
162
  ### Example 4: Disable Custom Routing
175
163
 
Binary file
Binary file
@@ -1,149 +0,0 @@
1
- # Memory Leak Root Cause - CONFIRMED
2
-
3
- ## 🔴 Critical Finding
4
-
5
- **Memory leak caused by `find /mnt/c` commands on WSL Windows paths**
6
-
7
- ## Monitoring Results (10-minute observation)
8
-
9
- ```
10
- Timeline:
11
- [1/20] [19:06:56] MEM: 15.6GB | Find: 0 ← Baseline
12
- [3/20] [19:07:56] MEM: 15.8GB | Find: 2 ← Find commands start 🔴
13
- [8/20] [19:10:26] MEM: 26.1GB | Find: 0 ← +10.5GB spike!
14
- [9/20] [19:10:56] MEM: 28.5GB | Find: 3 ← Peak find activity
15
- [10/20] [19:11:26] MEM: 32.0GB | Find: 3 ← Critical heap pressure
16
- [11-19] MEM: 36.5GB | Find: 0 ← Stabilized (heap fragmentation)
17
- [20/20] [19:16:27] MEM: 14.1GB | Find: 0 ← Swarm complete, dropped 22GB
18
- ```
19
-
20
- ## The Smoking Gun
21
-
22
- **4-minute period (19:07 → 19:11):**
23
- - 2-3 `find /mnt/c` commands running concurrently
24
- - Memory jumped from 15.6GB → 32.0GB (+16.4GB)
25
- - **Memory growth rate: 4GB/minute while finds active**
26
-
27
- ## Why `find /mnt/c` is a Memory Bomb
28
-
29
- 1. **WSL filesystem translation**: Linux syscalls → Windows API = extremely slow
30
- 2. **Output buffering**: Each find buffers 50-200MB of file paths in memory
31
- 3. **Concurrent execution**: 3 agents × 200MB buffered output = 600MB+
32
- 4. **Heap fragmentation**: Node.js heap can't release memory fast enough
33
- 5. **Result**: 20GB+ memory spike in 4 minutes → crash
34
-
35
- ## Performance Comparison
36
-
37
- | Tool | Time | Memory | Command |
38
- |------|------|--------|---------|
39
- | `find /mnt/c/...` | 2-10s | 50-200MB per command | ❌ FORBIDDEN |
40
- | `Glob("**/*")` | <100ms | <1MB | ✅ USE THIS |
41
- | `git ls-files` | <50ms | <1MB | ✅ Alternative |
42
-
43
- ## Fix Applied
44
-
45
- ### 1. Pre-Command Hook (BLOCKS find commands)
46
-
47
- **claude-flow-novice/.claude/settings.json:**
48
- ```json
49
- {
50
- "hooks": {
51
- "PreToolUse": [{
52
- "matcher": "Bash",
53
- "hooks": [{
54
- "type": "command",
55
- "command": "bash -c 'CMD=$(cat | jq -r \".tool_input.command // empty\"); if echo \"$CMD\" | grep -q \"find /mnt/c\"; then echo \"🔴 BLOCKED: find on /mnt/c paths forbidden (causes memory leak - use Glob tool instead)\" >&2; exit 1; fi; ...'"
56
- }]
57
- }]
58
- }
59
- }
60
- ```
61
-
62
- **ourstories-v2/.claude/settings.json:**
63
- ```json
64
- {
65
- "hooks": {
66
- "PreToolUse": [{
67
- "matcher": "Bash",
68
- "hooks": [{
69
- "type": "command",
70
- "command": "bash -c 'CMD=$(cat | jq -r \".tool_input.command // empty\"); if echo \"$CMD\" | grep -q \"find /mnt/c\"; then echo \"🔴 BLOCKED: find on /mnt/c paths forbidden (causes memory leak - use Glob tool instead)\" >&2; exit 1; fi'"
71
- }]
72
- }]
73
- }
74
- }
75
- ```
76
-
77
- ### 2. CLAUDE.md Updated
78
-
79
- Added section: **🚨 CRITICAL: Memory Leak Prevention (WSL/Windows)**
80
-
81
- - Prohibits `find /mnt/c` commands
82
- - Mandates Glob tool instead
83
- - Documents performance comparison
84
-
85
- ### 3. Agent Performance Guidelines
86
-
87
- Created: `AGENT_PERFORMANCE_GUIDELINES.md`
88
-
89
- - Best practices for WSL environments
90
- - Tool alternatives (Glob, fd, git ls-files)
91
- - Memory optimization patterns
92
-
93
- ## Secondary Issue: Orphaned Processes
94
-
95
- **Also discovered:**
96
- - 39 orphaned node processes from previous swarms
97
- - 5-6 zombie processes stuck in <defunct> state
98
- - Total: ~3GB additional memory overhead
99
-
100
- **Cleanup needed:**
101
- ```bash
102
- # Kill zombies
103
- kill -9 <zombie_pids>
104
-
105
- # Kill old processes (>1 hour)
106
- ps -eo pid,etime,cmd | grep node | awk '$2 ~ /-/ {print $1}' | xargs kill -9
107
- ```
108
-
109
- ## Testing Hook Protection
110
-
111
- **After restart, if agent tries:**
112
- ```bash
113
- find /mnt/c/Users/masha/Documents/claude-flow-novice -name "*.test.*"
114
- ```
115
-
116
- **Hook will block with:**
117
- ```
118
- 🔴 BLOCKED: find on /mnt/c paths forbidden (causes memory leak - use Glob tool instead)
119
- ```
120
-
121
- **Agent must use instead:**
122
- ```javascript
123
- Glob("**/*.test.*") // Fast, <100ms, minimal memory
124
- ```
125
-
126
- ## Summary
127
-
128
- ✅ **Root cause identified**: `find /mnt/c` commands on WSL
129
- ✅ **Fix applied**: PreToolUse hook blocks dangerous commands
130
- ✅ **Documentation updated**: CLAUDE.md + guidelines
131
- ✅ **Prevention active**: Both repos protected
132
-
133
- **Expected result:** No more 20GB+ memory spikes from find commands.
134
-
135
- ## Monitoring Script
136
-
137
- Created: `scripts/monitor.py`
138
-
139
- Run anytime to check for memory leaks:
140
- ```bash
141
- python3 scripts/monitor.py
142
- ```
143
-
144
- Monitors for:
145
- - Total memory usage
146
- - Node/Claude process counts
147
- - Zombie processes
148
- - Find commands (memory bombs)
149
- - Hook recursion