Skip to content

Commit c9719dc

Browse files
Flisselclaude
andcommitted
fix: Fungus MCP connection, task consolidation (465→~60), and EventBus-SoM bridge expansion
Three critical pipeline issues resolved: 1. Fungus MCP: Rewrote server from raw JSON-RPC to official MCP Python SDK, fixed config path (was writing to ~/.kilocode/ instead of .kilo/mcp.json), now shows "fungus: connected" in kilo mcp list. 2. Task Splitting: Added feature-consolidated frontend tasks (1 per component instead of 5) and test tasks (max 3 per epic instead of 1 per Gherkin scenario). Reduces ~465 tasks to ~50-60 in feature consolidation mode. 3. EventBus-SoM Bridge: Added 6 new MCP Event Bridge mappings (EPIC_TASK_COMPLETED/FAILED, API_ROUTES_GENERATED, AUTH_SETUP_COMPLETE, TYPE_ERROR) and 12 new SoM Bridge prefix mappings for feature-consolidated task types (verify_all, api_controller, fe_page, test_e2e_*, env_, etc). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a14bd30 commit c9719dc

46 files changed

Lines changed: 17107 additions & 2385 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/launch.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "0.0.1",
3+
"configurations": [
4+
{
5+
"name": "web-app-frontend",
6+
"runtimeExecutable": "node",
7+
"runtimeArgs": ["node_modules/vite/bin/vite.js", "dev", "--host", "--port", "8081"],
8+
"port": 8081,
9+
"cwd": "web-app/front"
10+
}
11+
]
12+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
name: ce-code-quality
3+
description: Review quality of generated code. Checks for empty files, broken imports, missing modules, duplicate code, TypeScript errors, and rates overall quality. Identifies files that need regeneration.
4+
trigger: When user asks to "review code quality", "check generated code", "is the code real", "any empty files", "code review the output"
5+
---
6+
7+
# ce-code-quality — Generated Code Quality Audit
8+
9+
## Step 1: File Inventory
10+
11+
```bash
12+
docker exec coding-engine-api bash -c "
13+
cd /app/output/*/
14+
echo '=== FILE COUNTS ==='
15+
echo 'Controllers:' && find src/modules -name '*.controller.ts' 2>/dev/null | wc -l
16+
echo 'Services:' && find src/modules -name '*.service.ts' 2>/dev/null | wc -l
17+
echo 'DTOs:' && find src -name '*.dto.ts' 2>/dev/null | wc -l
18+
echo 'Guards:' && find src -name '*.guard.ts' 2>/dev/null | wc -l
19+
echo 'Validators:' && find src -name '*.validator.ts' 2>/dev/null | wc -l
20+
echo 'Frontend Pages:' && find frontend/src -name '*.tsx' 2>/dev/null | grep -v node_modules | wc -l
21+
echo 'Hooks:' && find src/hooks -name '*.ts' 2>/dev/null | wc -l
22+
"
23+
```
24+
25+
## Step 2: Empty File Detection
26+
27+
```bash
28+
docker exec coding-engine-api bash -c "
29+
cd /app/output/*/
30+
echo '=== EMPTY OR TINY FILES (< 50 bytes) ==='
31+
find src -type f -name '*.ts' -o -name '*.tsx' 2>/dev/null | grep -v node_modules | while read f; do
32+
size=\$(wc -c < \"\$f\")
33+
if [ \$size -lt 50 ]; then echo \"EMPTY: \$f (\${size}b)\"; fi
34+
done
35+
echo '=== PLACEHOLDER FILES (contain only imports/exports) ==='
36+
find src -type f -name '*.ts' 2>/dev/null | grep -v node_modules | while read f; do
37+
lines=\$(wc -l < \"\$f\")
38+
if [ \$lines -lt 5 ]; then echo \"STUB: \$f (\${lines} lines)\"; fi
39+
done | head -20
40+
"
41+
```
42+
43+
## Step 3: Import Health Check
44+
45+
```bash
46+
docker exec coding-engine-api bash -c "
47+
cd /app/output/*/
48+
echo '=== BROKEN IMPORTS ==='
49+
grep -rn 'from.*react-native' src/modules/ src/api/ 2>/dev/null | head -5 && echo '^^^ react-native in backend = BUG'
50+
grep -rn 'from.*generated/prisma' src/modules/ 2>/dev/null | head -3 && echo '^^^ prisma import (check if client exists)'
51+
echo '=== MISSING MODULE IMPORTS ==='
52+
grep -rn \"Cannot find module\" /app/output/*/generation.log 2>/dev/null | tail -5
53+
"
54+
```
55+
56+
## Step 4: Code Substance Check (sample 5 files)
57+
58+
For each: read first 20 lines, check if it has real logic (not just boilerplate)
59+
60+
```bash
61+
docker exec coding-engine-api bash -c "
62+
cd /app/output/*/
63+
echo '=== SAMPLE: auth.controller.ts ==='
64+
head -25 src/modules/auth/auth.controller.ts 2>/dev/null || echo 'NOT FOUND'
65+
echo '=== SAMPLE: messages service ==='
66+
head -25 src/modules/messages/messages.service.ts 2>/dev/null || echo 'NOT FOUND'
67+
echo '=== SAMPLE: contacts controller ==='
68+
head -25 src/modules/contacts/contacts.controller.ts 2>/dev/null || echo 'NOT FOUND'
69+
echo '=== SAMPLE: chats service ==='
70+
head -25 src/modules/chats/chats.service.ts 2>/dev/null || echo 'NOT FOUND'
71+
echo '=== SAMPLE: users controller ==='
72+
head -25 src/modules/users/users.controller.ts 2>/dev/null || echo 'NOT FOUND'
73+
"
74+
```
75+
76+
## Step 5: Build Test
77+
78+
```bash
79+
docker exec coding-engine-api bash -c "
80+
cd /app/output/*/
81+
npx tsc --noEmit 2>&1 | tail -20
82+
echo '---EXIT CODE: '\$?
83+
"
84+
```
85+
86+
## Step 6: Rate and Report
87+
88+
Present findings as:
89+
90+
```
91+
# 🔍 Code Quality Audit
92+
93+
## File Inventory
94+
| Type | Count | With Real Logic | Empty/Stub |
95+
96+
## Quality Rating: X/10
97+
- Real controllers with routes: X
98+
- Services with business logic: X
99+
- Empty/placeholder files: X
100+
- Broken imports: X
101+
- Build errors: X
102+
103+
## Issues Found
104+
1. [CRITICAL] ...
105+
2. [WARNING] ...
106+
107+
## Files That Need Regeneration
108+
- path/to/file.ts — reason
109+
```
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
name: ce-health-check
3+
description: Quick health check of all Coding Engine infrastructure. Checks containers, DB connectivity, API endpoints, Discord bot, sandbox preview, LLM API keys, and generation process. Takes 15 seconds.
4+
trigger: When user asks "is everything running", "health check", "check infrastructure", "what's broken", "container status"
5+
---
6+
7+
# ce-health-check — Infrastructure Health Check
8+
9+
Run ALL checks in parallel for speed (target: 15 seconds).
10+
11+
## Checks
12+
13+
### 1. Containers
14+
```bash
15+
docker ps --format "{{.Names}} {{.Status}}" | grep coding-engine | sort
16+
```
17+
Expected: api (healthy), postgres (healthy), redis (healthy), sandbox (healthy), automation-ui (healthy), openclaw (healthy)
18+
19+
### 2. API Health
20+
```bash
21+
curl -s --max-time 3 http://localhost:8000/health
22+
```
23+
Expected: `{"status":"healthy"}`
24+
25+
### 3. DB Connectivity
26+
```bash
27+
docker exec coding-engine-postgres psql -U postgres -d coding_engine -c "SELECT COUNT(*) FROM tasks;" 2>&1
28+
```
29+
30+
### 4. Redis
31+
```bash
32+
docker exec coding-engine-redis redis-cli ping
33+
```
34+
35+
### 5. Sandbox Preview
36+
```bash
37+
curl -s --max-time 3 http://localhost:3100 2>/dev/null | head -1
38+
curl -s --max-time 3 http://localhost:6090 2>/dev/null | head -1
39+
```
40+
41+
### 6. Discord Bot
42+
```bash
43+
docker logs coding-engine-automation-ui --tail 3 2>&1
44+
```
45+
46+
### 7. LLM API Keys
47+
```bash
48+
docker exec coding-engine-api bash -c "
49+
echo 'OPENAI_API_KEY:' && [ -n \"\$OPENAI_API_KEY\" ] && echo 'SET' || echo 'MISSING'
50+
echo 'OPENROUTER_API_KEY:' && [ -n \"\$OPENROUTER_API_KEY\" ] && echo 'SET' || echo 'MISSING'
51+
echo 'ANTHROPIC_API_KEY:' && [ -n \"\$ANTHROPIC_API_KEY\" ] && echo 'SET' || echo 'MISSING'
52+
echo 'LLM_BACKEND:' \$LLM_BACKEND
53+
echo 'GITHUB_TOKEN:' && [ -n \"\$GITHUB_TOKEN\" ] && echo 'SET' || echo 'MISSING'
54+
echo 'DISCORD_BOT_TOKEN:' && [ -n \"\$DISCORD_BOT_TOKEN\" ] && echo 'SET' || echo 'MISSING'
55+
"
56+
```
57+
58+
### 8. Generation Process
59+
```bash
60+
docker top coding-engine-api 2>/dev/null | grep run_generation | head -1 || echo "NO GENERATION RUNNING"
61+
```
62+
63+
### 9. Disk Space
64+
```bash
65+
docker exec coding-engine-api bash -c "df -h /app/output | tail -1"
66+
```
67+
68+
### 10. OpenRouter Credits (if used)
69+
```bash
70+
curl -s https://openrouter.ai/api/v1/auth/key \
71+
-H "Authorization: Bearer $(docker exec coding-engine-api bash -c 'echo $OPENROUTER_API_KEY')" 2>/dev/null | \
72+
python3 -c "import sys,json; d=json.load(sys.stdin).get('data',{}); print('Usage: \$%.2f' % d.get('usage',0))" 2>/dev/null || echo "Cannot check"
73+
```
74+
75+
## Report Format
76+
77+
```
78+
# 🏥 Health Check
79+
80+
| Service | Status | Details |
81+
|---------|--------|---------|
82+
| API | ✅/❌ | |
83+
| Postgres | ✅/❌ | X tasks in DB |
84+
| Redis | ✅/❌ | |
85+
| Sandbox | ✅/❌ | Preview on :3100 |
86+
| VNC | ✅/❌ | Emulator on :6090 |
87+
| Discord Bot | ✅/❌ | |
88+
| Generation | 🔄/⏹️ | Round X/10 |
89+
| OpenAI Key | ✅/❌ | |
90+
| OpenRouter | ✅/❌ | $X used |
91+
| Disk | ✅/⚠️ | X% used |
92+
93+
Issues: X found
94+
```
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
---
2+
name: ce-pipeline-doctor
3+
description: Diagnoses pipeline problems and outputs actionable fix commands. Combines insights from status-report, code-quality, task-audit, and health-check into concrete recommendations with copy-paste-ready commands. Answers "what should I do next?" and "why is generation stuck?"
4+
trigger: When user asks "what's wrong", "fix the pipeline", "what should I do next", "why is it stuck", "diagnose", "doctor", "help me fix this"
5+
---
6+
7+
# ce-pipeline-doctor — Pipeline Diagnosis & Action Plan
8+
9+
Run a full diagnosis, then output a prioritized action plan with ready-to-execute commands.
10+
11+
## Phase 1: Quick Triage (10 seconds)
12+
13+
Run these checks to classify the problem:
14+
15+
```bash
16+
# ONE-SHOT TRIAGE
17+
echo "=== CONTAINERS ===" && docker ps -a --format "{{.Names}} {{.Status}}" | grep coding-engine | sort
18+
echo "=== API HEALTH ===" && curl -s --max-time 3 http://localhost:8000/health 2>&1 || echo "API DOWN"
19+
echo "=== GENERATION ===" && docker top coding-engine-api 2>/dev/null | grep run_generation | head -1 || echo "NOT RUNNING"
20+
echo "=== DB TASKS ===" && docker exec coding-engine-postgres psql -U postgres -d coding_engine -t -c "SELECT status, COUNT(*) FROM tasks WHERE job_id=(SELECT MAX(id) FROM jobs) GROUP BY status ORDER BY status;" 2>&1
21+
echo "=== LAST ERROR ===" && docker exec coding-engine-api bash -c "grep 'ERROR\|OOM\|Kill\|Exit\|FAILED' /app/output/*/generation.log 2>/dev/null | grep -v 'subscriber\|entity_req\|_initialized\|enrichment' | tail -3" 2>&1
22+
echo "=== STALE RUNNING ===" && docker exec coding-engine-postgres psql -U postgres -d coding_engine -t -c "SELECT COUNT(*) FROM tasks WHERE job_id=(SELECT MAX(id) FROM jobs) AND status='RUNNING';" 2>&1
23+
echo "=== MEMORY ===" && docker stats coding-engine-api --no-stream --format "{{.MemUsage}}" 2>/dev/null || echo "Container not running"
24+
```
25+
26+
## Phase 2: Classify Problem
27+
28+
Based on triage results, classify into one of these categories:
29+
30+
### Category A: Container Down
31+
- Symptom: API/Bot/Sandbox container Exited
32+
- Check exit code: 137=OOM, 139=SIGSEGV, 255=restart-failure
33+
34+
### Category B: Generation Stuck/Dead
35+
- Symptom: `run_generation.py` not in process list but RUNNING tasks in DB
36+
- Stale RUNNING tasks = generation crashed mid-execution
37+
38+
### Category C: Cascade Failure
39+
- Symptom: Many CANCELLED/SKIPPED tasks, few FAILED
40+
- Root cause: One upstream task failed → all dependents cancelled
41+
42+
### Category D: LLM Issues
43+
- Symptom: 402 Payment Required, 429 Rate Limit, timeouts
44+
- Check which LLM backend and if credits are available
45+
46+
### Category E: Task Explosion
47+
- Symptom: 2000+ PENDING tasks, generation runs but completes quickly with few results
48+
- Root cause: Tasks too granular, LLM calls wasted on tiny files
49+
50+
### Category F: Code Quality Issues
51+
- Symptom: Build fails, wrong imports, empty generated files
52+
- Check: react-native in backend, missing prisma client, etc.
53+
54+
## Phase 3: Generate Action Plan
55+
56+
For each problem found, output a **numbered action** with the **exact command** to fix it.
57+
58+
### Template Actions:
59+
60+
#### Fix A: Container Down (OOM)
61+
```
62+
ACTION 1: Restart container with memory limit
63+
docker compose up -d api
64+
65+
ACTION 2: Set memory limit in docker-compose.yml
66+
deploy:
67+
resources:
68+
limits:
69+
memory: 4G
70+
71+
ACTION 3: Reduce parallelism to lower memory usage
72+
# In engine_settings.yml: generation.parallelism: 2 (was 3)
73+
```
74+
75+
#### Fix B: Generation Stuck
76+
```
77+
ACTION 1: Reset stale RUNNING tasks
78+
docker exec coding-engine-postgres psql -U postgres -d coding_engine -c "UPDATE tasks SET status='PENDING' WHERE job_id=(SELECT MAX(id) FROM jobs) AND status='RUNNING';"
79+
80+
ACTION 2: Remove stale lock file
81+
docker exec coding-engine-api bash -c "rm -f /app/output/*/.generation_running"
82+
83+
ACTION 3: Restart generation
84+
docker exec -d coding-engine-api bash -c "cd /app && python run_generation.py --project-path /app/Data/all_services/whatsapp-messaging-service_20260211_025459 --output-dir /app/output/whatsapp-messaging-service_20260211_025459 --project-id whatsapp-messaging-service --db-schema whatsapp_app --parallelism 2 --max-rounds 10 >> /app/output/whatsapp-messaging-service_20260211_025459/generation.log 2>&1"
85+
```
86+
87+
#### Fix C: Cascade Failure
88+
```
89+
ACTION 1: Find cascade roots
90+
docker exec coding-engine-postgres psql -U postgres -d coding_engine -c "SELECT task_id, status, status_message FROM tasks WHERE job_id=(SELECT MAX(id) FROM jobs) AND status='FAILED' LIMIT 10;"
91+
92+
ACTION 2: Fix root failures (usually schema/migration)
93+
# If migrations: mark as COMPLETED (schema already synced)
94+
docker exec coding-engine-postgres psql -U postgres -d coding_engine -c "UPDATE tasks SET status='COMPLETED', status_message='Schema already synced' WHERE job_id=(SELECT MAX(id) FROM jobs) AND task_id LIKE '%migration%' AND status='FAILED';"
95+
96+
ACTION 3: Reset cancelled tasks and regenerate
97+
docker exec coding-engine-postgres psql -U postgres -d coding_engine -c "UPDATE tasks SET status='PENDING' WHERE job_id=(SELECT MAX(id) FROM jobs) AND status IN ('CANCELLED','SKIPPED');"
98+
```
99+
100+
#### Fix D: LLM Issues
101+
```
102+
ACTION 1: Check API key balance
103+
curl -s https://openrouter.ai/api/v1/auth/key -H "Authorization: Bearer $OPENROUTER_API_KEY" | python3 -c "import sys,json; print(json.load(sys.stdin)['data']['usage'])"
104+
105+
ACTION 2: Switch to OpenAI if OpenRouter empty
106+
# In docker-compose.yml: LLM_BACKEND=openai
107+
docker compose up -d api
108+
109+
ACTION 3: Use free models as fallback
110+
# In engine_settings.yml: models.fixing.model: qwen/qwen3-coder:free
111+
```
112+
113+
#### Fix E: Task Explosion
114+
```
115+
ACTION 1: Count the damage
116+
docker exec coding-engine-postgres psql -U postgres -d coding_engine -t -c "SELECT 'API tasks: ' || COUNT(*) FROM tasks WHERE job_id=(SELECT MAX(id) FROM jobs) AND task_id LIKE '%API%';"
117+
118+
ACTION 2: Mark redundant sub-tasks as COMPLETED
119+
# Keep only -controller tasks, mark -guard, -validation as done
120+
docker exec coding-engine-postgres psql -U postgres -d coding_engine -c "UPDATE tasks SET status='COMPLETED', status_message='Consolidated: generated with controller' WHERE job_id=(SELECT MAX(id) FROM jobs) AND (task_id LIKE '%-guard' OR task_id LIKE '%-validation') AND status='PENDING';"
121+
122+
ACTION 3: For future projects: modify epic_task_generator.py
123+
# Change _generate_api_tasks() to create 1 task per endpoint group instead of 5
124+
```
125+
126+
#### Fix F: Code Quality
127+
```
128+
ACTION 1: Remove react-native imports from backend
129+
docker exec coding-engine-api bash -c "cd /app/output/*/ && rm -f src/api/loginpageAPI.ts src/api/registerpageAPI.ts src/api/twofactorauthAPI.ts"
130+
131+
ACTION 2: Generate prisma client
132+
docker exec coding-engine-api bash -c "cd /app/output/*/ && DATABASE_URL='postgresql://postgres:postgres@postgres:5432/whatsapp_app?schema=public' npx prisma generate"
133+
134+
ACTION 3: Run build check
135+
docker exec coding-engine-api bash -c "cd /app/output/*/ && npx tsc --noEmit 2>&1 | head -20"
136+
```
137+
138+
## Phase 4: Priority Matrix
139+
140+
After generating actions, present them in priority order:
141+
142+
```
143+
# 🏥 Pipeline Doctor — Diagnosis
144+
145+
## Problem: [Category Name]
146+
[One sentence description]
147+
148+
## Action Plan (in order):
149+
150+
| # | Action | Impact | Command Ready? |
151+
|---|--------|--------|----------------|
152+
| 1 | [Most urgent] | HIGH | ✅ |
153+
| 2 | [Next] | HIGH | ✅ |
154+
| 3 | [Nice to have] | MEDIUM | ✅ |
155+
156+
## Commands to Execute:
157+
[Copy-paste ready block of all commands in sequence]
158+
159+
## Expected Outcome:
160+
- After Action 1: [what changes]
161+
- After Action 2: [what changes]
162+
- After all actions: [final state]
163+
```
164+
165+
## Phase 5: Verify
166+
167+
After actions are executed, re-run Phase 1 triage to confirm fixes worked.

0 commit comments

Comments
 (0)