create-merlin-brain 2.3.3 → 2.4.0

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.
@@ -0,0 +1,603 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Merlin Loop - Agent Profiles & Routing
4
+ # Task → Agent mapping based on keywords
5
+ #
6
+
7
+ # ═══════════════════════════════════════════════════════════════════════════════
8
+ # Agent Definitions
9
+ # Each agent has: triggers, display_name, required_skills, context_injection
10
+ # ═══════════════════════════════════════════════════════════════════════════════
11
+
12
+ # Agent: hardening-guard (Security Specialist)
13
+ AGENT_hardening_guard_TRIGGERS="auth login password token security 2fa oauth jwt session encrypt decrypt hash"
14
+ AGENT_hardening_guard_DISPLAY="Security Specialist (hardening-guard)"
15
+ AGENT_hardening_guard_SKILLS="security-patterns"
16
+ AGENT_hardening_guard_CONTEXT="Security Guidelines:
17
+ - Always sanitize user input
18
+ - Use parameterized queries for database operations
19
+ - Implement rate limiting on auth endpoints
20
+ - Never store passwords in plain text (use bcrypt/argon2)
21
+ - Validate JWT tokens on every request
22
+ - Use HTTPS everywhere
23
+ - Implement CSRF protection for forms
24
+ - Check OWASP Top 10 considerations"
25
+
26
+ # Agent: merlin-frontend (Frontend Specialist)
27
+ AGENT_merlin_frontend_TRIGGERS="ui component design css layout responsive frontend react vue angular svelte tailwind"
28
+ AGENT_merlin_frontend_DISPLAY="Frontend Specialist (merlin-frontend)"
29
+ AGENT_merlin_frontend_SKILLS="canvas-design accessibility-patterns"
30
+ AGENT_merlin_frontend_CONTEXT="Frontend Guidelines:
31
+ - Follow component composition patterns
32
+ - Ensure keyboard navigation works
33
+ - Make components screen reader compatible
34
+ - Design mobile-first, then scale up
35
+ - Use semantic HTML elements
36
+ - Keep components under 200 lines
37
+ - Extract reusable hooks and utilities"
38
+
39
+ # Agent: merlin-api-designer (API Specialist)
40
+ AGENT_merlin_api_designer_TRIGGERS="api endpoint route rest graphql webhook handler controller"
41
+ AGENT_merlin_api_designer_DISPLAY="API Designer (merlin-api-designer)"
42
+ AGENT_merlin_api_designer_SKILLS="api-patterns"
43
+ AGENT_merlin_api_designer_CONTEXT="API Design Guidelines:
44
+ - Use RESTful conventions (GET/POST/PUT/DELETE)
45
+ - Return consistent response formats
46
+ - Include proper HTTP status codes
47
+ - Add request validation middleware
48
+ - Document endpoints with OpenAPI/Swagger
49
+ - Implement pagination for list endpoints
50
+ - Use versioning (/api/v1/) for stability"
51
+
52
+ # Agent: system-architect (Architecture Specialist)
53
+ AGENT_system_architect_TRIGGERS="database schema model migration architecture structure service microservice"
54
+ AGENT_system_architect_DISPLAY="System Architect"
55
+ AGENT_system_architect_SKILLS=""
56
+ AGENT_system_architect_CONTEXT="Architecture Guidelines:
57
+ - Prefer fewer services over many microservices
58
+ - Keep data models normalized but practical
59
+ - Use foreign keys for referential integrity
60
+ - Add indexes on frequently queried columns
61
+ - Consider future scalability but don't over-engineer
62
+ - Document architectural decisions"
63
+
64
+ # Agent: tests-qa (Testing Specialist)
65
+ AGENT_tests_qa_TRIGGERS="test spec coverage unit integration e2e jest mocha pytest"
66
+ AGENT_tests_qa_DISPLAY="Testing Specialist (tests-qa)"
67
+ AGENT_tests_qa_SKILLS="testing-patterns"
68
+ AGENT_tests_qa_CONTEXT="Testing Guidelines:
69
+ - Write tests for happy path first
70
+ - Add edge case tests for critical paths
71
+ - Mock external services
72
+ - Keep tests isolated and repeatable
73
+ - Use descriptive test names
74
+ - Aim for meaningful coverage, not 100%
75
+ - Test behavior, not implementation"
76
+
77
+ # Agent: dry-refactor (Refactoring Specialist)
78
+ AGENT_dry_refactor_TRIGGERS="refactor cleanup dry organize structure split extract"
79
+ AGENT_dry_refactor_DISPLAY="Refactoring Specialist (dry-refactor)"
80
+ AGENT_dry_refactor_SKILLS="code-organization"
81
+ AGENT_dry_refactor_CONTEXT="Refactoring Guidelines:
82
+ - Keep files under 400 lines
83
+ - Extract shared logic into utilities
84
+ - Use consistent naming conventions
85
+ - Group related functions together
86
+ - Remove dead code
87
+ - Prefer composition over inheritance
88
+ - Make small, atomic changes"
89
+
90
+ # Agent: ops-railway (DevOps Specialist)
91
+ AGENT_ops_railway_TRIGGERS="deploy infra railway docker env ci cd pipeline build"
92
+ AGENT_ops_railway_DISPLAY="DevOps Specialist (ops-railway)"
93
+ AGENT_ops_railway_SKILLS=""
94
+ AGENT_ops_railway_CONTEXT="DevOps Guidelines:
95
+ - Never commit secrets to git
96
+ - Use environment variables for config
97
+ - Keep Dockerfiles minimal and secure
98
+ - Add health check endpoints
99
+ - Log errors with context
100
+ - Set up proper monitoring
101
+ - Document deployment steps"
102
+
103
+ # Agent: docs-keeper (Documentation Specialist)
104
+ AGENT_docs_keeper_TRIGGERS="docs readme documentation comment jsdoc typedoc markdown"
105
+ AGENT_docs_keeper_DISPLAY="Documentation Specialist (docs-keeper)"
106
+ AGENT_docs_keeper_SKILLS=""
107
+ AGENT_docs_keeper_CONTEXT="Documentation Guidelines:
108
+ - Keep docs close to code
109
+ - Document the 'why', not just 'what'
110
+ - Include examples for complex APIs
111
+ - Update docs when code changes
112
+ - Use markdown for readability
113
+ - Add inline comments for tricky logic"
114
+
115
+ # Agent: merlin-debugger (Debugging Specialist)
116
+ AGENT_merlin_debugger_TRIGGERS="debug fix error bug issue crash trace log"
117
+ AGENT_merlin_debugger_DISPLAY="Debugging Specialist (merlin-debugger)"
118
+ AGENT_merlin_debugger_SKILLS=""
119
+ AGENT_merlin_debugger_CONTEXT="Debugging Guidelines:
120
+ - Reproduce the issue first
121
+ - Check logs and error messages
122
+ - Use binary search to isolate the problem
123
+ - Add debug logging if needed
124
+ - Verify the fix doesn't break other tests
125
+ - Document the root cause"
126
+
127
+ # Agent: apple-swift-expert (Apple Platform Specialist)
128
+ AGENT_apple_swift_expert_TRIGGERS="swift swiftui appkit ios macos iphone ipad xcode cocoa uikit swift6 swiftdata coredata"
129
+ AGENT_apple_swift_expert_DISPLAY="Apple Swift Expert (apple-swift-expert)"
130
+ AGENT_apple_swift_expert_SKILLS=""
131
+ AGENT_apple_swift_expert_CONTEXT="Apple Development Guidelines:
132
+ - Use Swift 6 with async/await and actors
133
+ - Default to SwiftUI over UIKit/AppKit
134
+ - Use @Observable not ObservableObject
135
+ - Follow Apple Human Interface Guidelines
136
+ - Use SF Symbols for icons
137
+ - Target newest platform APIs available"
138
+
139
+ # Agent: android-expert (Android Specialist)
140
+ AGENT_android_expert_TRIGGERS="android kotlin compose jetpack material gradle room hilt viewmodel coroutine play-store apk aab"
141
+ AGENT_android_expert_DISPLAY="Android Expert (android-expert)"
142
+ AGENT_android_expert_SKILLS=""
143
+ AGENT_android_expert_CONTEXT="Android Development Guidelines:
144
+ - Use Kotlin with coroutines, never Java for new code
145
+ - Use Jetpack Compose for UI, not XML layouts
146
+ - Follow MVVM + Clean Architecture
147
+ - Use Hilt for dependency injection
148
+ - Use Material Design 3 with dynamic color
149
+ - Test with LeakCanary and Compose testing"
150
+
151
+ # Agent: ui-designer (UI/UX Design Specialist)
152
+ AGENT_ui_designer_TRIGGERS="design-system accessibility wcag color-palette typography spacing visual-hierarchy wireframe mockup ux hig"
153
+ AGENT_ui_designer_DISPLAY="UI Designer (ui-designer)"
154
+ AGENT_ui_designer_SKILLS=""
155
+ AGENT_ui_designer_CONTEXT="UI Design Guidelines:
156
+ - Design with accessibility first (WCAG 2.1 AA)
157
+ - Use semantic color tokens, not raw values
158
+ - 4.5:1 contrast ratio for text minimum
159
+ - Touch targets minimum 44x44px
160
+ - Document all component states
161
+ - Design for dark mode simultaneously"
162
+
163
+ # Agent: ui-builder (UI Component Builder)
164
+ AGENT_ui_builder_TRIGGERS="shadcn radix component-library tailwind form table card modal dialog sheet"
165
+ AGENT_ui_builder_DISPLAY="UI Builder (ui-builder)"
166
+ AGENT_ui_builder_SKILLS=""
167
+ AGENT_ui_builder_CONTEXT="UI Building Guidelines:
168
+ - Use existing design system components first
169
+ - Tailwind CSS with consistent ordering
170
+ - All components must handle loading/empty/error states
171
+ - Mobile-first responsive design
172
+ - Accessible by default (keyboard nav, aria labels)
173
+ - Copy-paste ready production code"
174
+
175
+ # Agent: animation-expert (Animation Specialist)
176
+ AGENT_animation_expert_TRIGGERS="animation motion framer gsap transition scroll-animation parallax spring keyframe animate"
177
+ AGENT_animation_expert_DISPLAY="Animation Expert (animation-expert)"
178
+ AGENT_animation_expert_SKILLS=""
179
+ AGENT_animation_expert_CONTEXT="Animation Guidelines:
180
+ - Import from motion/react not framer-motion
181
+ - Only animate transform and opacity (GPU accelerated)
182
+ - Never animate width, height, top, left
183
+ - Always respect prefers-reduced-motion
184
+ - Use spring physics for natural feel
185
+ - Clean up GSAP contexts on unmount
186
+ - Keep animations purposeful, not decorative"
187
+
188
+ # Agent: marketing-automation (Marketing Automation Specialist)
189
+ AGENT_marketing_automation_TRIGGERS="email campaign drip newsletter marketing automation funnel conversion ab-test analytics tracking utm landing-page growth"
190
+ AGENT_marketing_automation_DISPLAY="Marketing Automation (marketing-automation)"
191
+ AGENT_marketing_automation_SKILLS=""
192
+ AGENT_marketing_automation_CONTEXT="Marketing Automation Guidelines:
193
+ - Always include unsubscribe in marketing emails
194
+ - Use type-safe event tracking
195
+ - Include UTM parameters on all marketing links
196
+ - A/B test subject lines and CTAs
197
+ - GDPR/CAN-SPAM compliant
198
+ - Track opens, clicks, conversions
199
+ - Design drip sequences with conditions"
200
+
201
+ # Agent: desktop-app-expert (Desktop App Specialist)
202
+ AGENT_desktop_app_expert_TRIGGERS="electron tauri desktop native window tray ipc preload menu dmg nsis appimage code-sign notarize"
203
+ AGENT_desktop_app_expert_DISPLAY="Desktop App Expert (desktop-app-expert)"
204
+ AGENT_desktop_app_expert_SKILLS=""
205
+ AGENT_desktop_app_expert_CONTEXT="Desktop App Guidelines:
206
+ - Always use contextIsolation: true and sandbox: true
207
+ - Never enable nodeIntegration in renderer
208
+ - Expose only necessary APIs via contextBridge
209
+ - Validate all IPC inputs in main process
210
+ - Prevent directory traversal in file operations
211
+ - Use electron-updater or tauri-updater for auto-updates
212
+ - Code sign for macOS and Windows distribution
213
+ - Test on all target platforms"
214
+
215
+ # Agent: implementation-dev (General Implementation)
216
+ AGENT_implementation_dev_TRIGGERS=""
217
+ AGENT_implementation_dev_DISPLAY="Implementation Agent (implementation-dev)"
218
+ AGENT_implementation_dev_SKILLS=""
219
+ AGENT_implementation_dev_CONTEXT="Implementation Guidelines:
220
+ - Follow existing patterns in the codebase
221
+ - Keep changes minimal and focused
222
+ - Test your changes before committing
223
+ - Ask for clarification if requirements are unclear"
224
+
225
+ # ═══════════════════════════════════════════════════════════════════════════════
226
+ # Agent Selection (Composable Routing)
227
+ #
228
+ # ARCHITECTURE: Domain specialists are "full-lifecycle" agents that handle
229
+ # implementation, refactoring, architecture, testing, and hardening within
230
+ # their domain. When a domain is detected, the specialist ALWAYS wins over
231
+ # a generic workflow agent.
232
+ #
233
+ # Example: "refactor the Swift networking layer"
234
+ # → Routes to apple_swift_expert (NOT dry_refactor)
235
+ # → The specialist activates its "Refactoring Mode" internally
236
+ #
237
+ # Fallback: When no domain is detected, generic workflow agents handle it.
238
+ # "refactor the payment service" → dry_refactor (no domain detected)
239
+ # ═══════════════════════════════════════════════════════════════════════════════
240
+
241
+ AGENT_LIST="hardening_guard merlin_frontend merlin_api_designer system_architect tests_qa dry_refactor ops_railway docs_keeper merlin_debugger desktop_app_expert apple_swift_expert android_expert ui_designer ui_builder animation_expert marketing_automation implementation_dev"
242
+
243
+ # Domain specialists: full-lifecycle agents with workflow_modes built in.
244
+ # When these score ANY points, they get a +5 domain boost to beat generic agents.
245
+ DOMAIN_SPECIALISTS="apple_swift_expert android_expert desktop_app_expert ui_designer ui_builder animation_expert marketing_automation"
246
+
247
+ # Primary triggers score 3 points, secondary triggers score 1 point
248
+ # Domain specialists also get +5 boost when scoring > 0
249
+
250
+ AGENT_hardening_guard_PRIMARY="security auth login password encrypt 2fa oauth"
251
+ AGENT_hardening_guard_SECONDARY="token jwt session hash rate-limit validate sanitize"
252
+
253
+ AGENT_merlin_frontend_PRIMARY="ui component frontend react vue svelte"
254
+ AGENT_merlin_frontend_SECONDARY="css layout responsive angular tailwind design"
255
+
256
+ AGENT_merlin_api_designer_PRIMARY="api endpoint route rest graphql"
257
+ AGENT_merlin_api_designer_SECONDARY="webhook handler controller middleware"
258
+
259
+ AGENT_system_architect_PRIMARY="database schema model migration architecture"
260
+ AGENT_system_architect_SECONDARY="structure service microservice"
261
+
262
+ AGENT_tests_qa_PRIMARY="test spec coverage unit integration"
263
+ AGENT_tests_qa_SECONDARY="e2e jest mocha pytest"
264
+
265
+ AGENT_dry_refactor_PRIMARY="refactor cleanup dry organize"
266
+ AGENT_dry_refactor_SECONDARY="structure split extract consolidate"
267
+
268
+ AGENT_ops_railway_PRIMARY="deploy infra railway docker"
269
+ AGENT_ops_railway_SECONDARY="env ci cd pipeline build"
270
+
271
+ AGENT_docs_keeper_PRIMARY="docs readme documentation"
272
+ AGENT_docs_keeper_SECONDARY="comment jsdoc typedoc markdown"
273
+
274
+ AGENT_merlin_debugger_PRIMARY="debug fix error bug"
275
+ AGENT_merlin_debugger_SECONDARY="issue crash trace log"
276
+
277
+ AGENT_desktop_app_expert_PRIMARY="electron tauri desktop native ipc"
278
+ AGENT_desktop_app_expert_SECONDARY="window tray preload menu dmg nsis appimage code-sign notarize"
279
+
280
+ AGENT_apple_swift_expert_PRIMARY="swift swiftui appkit ios macos iphone"
281
+ AGENT_apple_swift_expert_SECONDARY="ipad xcode cocoa uikit swiftdata coredata swift6"
282
+
283
+ AGENT_android_expert_PRIMARY="android kotlin compose jetpack"
284
+ AGENT_android_expert_SECONDARY="material gradle room hilt viewmodel coroutine play-store aab apk"
285
+
286
+ AGENT_ui_designer_PRIMARY="design-system accessibility wcag visual-hierarchy ux"
287
+ AGENT_ui_designer_SECONDARY="color-palette typography spacing wireframe mockup hig"
288
+
289
+ AGENT_ui_builder_PRIMARY="shadcn radix component-library form table"
290
+ AGENT_ui_builder_SECONDARY="card modal dialog sheet dropdown popover cva"
291
+
292
+ AGENT_animation_expert_PRIMARY="animation motion framer gsap transition"
293
+ AGENT_animation_expert_SECONDARY="scroll-animation parallax spring keyframe animate lottie"
294
+
295
+ AGENT_marketing_automation_PRIMARY="email campaign drip marketing funnel"
296
+ AGENT_marketing_automation_SECONDARY="newsletter automation conversion ab-test analytics tracking utm landing-page growth"
297
+
298
+ AGENT_implementation_dev_PRIMARY=""
299
+ AGENT_implementation_dev_SECONDARY=""
300
+
301
+ # ═══════════════════════════════════════════════════════════════════════════════
302
+ # Task Type Detection
303
+ # Detects the workflow mode so domain specialists activate the right mode.
304
+ # ═══════════════════════════════════════════════════════════════════════════════
305
+
306
+ detect_task_type() {
307
+ local task_lower="$1"
308
+
309
+ # Check refactoring first (most specific action word)
310
+ for word in refactor cleanup dry reorganize split extract consolidate rename simplify; do
311
+ if echo "$task_lower" | grep -qw "$word"; then echo "REFACTORING"; return; fi
312
+ done
313
+
314
+ # Architecture / design
315
+ for word in architect design plan model schema structure service boundary module; do
316
+ if echo "$task_lower" | grep -qw "$word"; then echo "ARCHITECTURE"; return; fi
317
+ done
318
+
319
+ # Testing
320
+ for word in test spec coverage unit integration e2e qa verify assert; do
321
+ if echo "$task_lower" | grep -qw "$word"; then echo "TESTING"; return; fi
322
+ done
323
+
324
+ # Hardening / security
325
+ for word in harden secure security audit validate review sanitize vulnerability; do
326
+ if echo "$task_lower" | grep -qw "$word"; then echo "HARDENING"; return; fi
327
+ done
328
+
329
+ # Debugging
330
+ for word in debug fix error bug crash trace troubleshoot; do
331
+ if echo "$task_lower" | grep -qw "$word"; then echo "DEBUGGING"; return; fi
332
+ done
333
+
334
+ echo "IMPLEMENTATION" # Default mode
335
+ }
336
+
337
+ # ═══════════════════════════════════════════════════════════════════════════════
338
+ # Agent Scoring
339
+ # ═══════════════════════════════════════════════════════════════════════════════
340
+
341
+ score_agent() {
342
+ local agent="$1"
343
+ local task_lower="$2"
344
+
345
+ local primary_var="AGENT_${agent}_PRIMARY"
346
+ local secondary_var="AGENT_${agent}_SECONDARY"
347
+ local triggers_var="AGENT_${agent}_TRIGGERS"
348
+ local primary="${!primary_var}"
349
+ local secondary="${!secondary_var}"
350
+ local triggers="${!triggers_var}"
351
+
352
+ local score=0
353
+
354
+ # Primary keywords: 3 points each (strong signal)
355
+ if [ -n "$primary" ]; then
356
+ for trigger in $primary; do
357
+ if echo "$task_lower" | grep -qw "$trigger"; then
358
+ score=$((score + 3))
359
+ fi
360
+ done
361
+ fi
362
+
363
+ # Secondary keywords: 1 point each (supporting signal)
364
+ if [ -n "$secondary" ]; then
365
+ for trigger in $secondary; do
366
+ if echo "$task_lower" | grep -qw "$trigger"; then
367
+ score=$((score + 1))
368
+ fi
369
+ done
370
+ fi
371
+
372
+ # Fallback: legacy triggers (1 point each, for backward compat)
373
+ if [ $score -eq 0 ] && [ -n "$triggers" ]; then
374
+ for trigger in $triggers; do
375
+ if echo "$task_lower" | grep -qw "$trigger"; then
376
+ score=$((score + 1))
377
+ fi
378
+ done
379
+ fi
380
+
381
+ echo $score
382
+ }
383
+
384
+ # Check if an agent is a domain specialist
385
+ is_domain_specialist() {
386
+ local agent="$1"
387
+ for specialist in $DOMAIN_SPECIALISTS; do
388
+ if [ "$agent" = "$specialist" ]; then return 0; fi
389
+ done
390
+ return 1
391
+ }
392
+
393
+ # ═══════════════════════════════════════════════════════════════════════════════
394
+ # Main Routing: select_agent_for_task
395
+ #
396
+ # Two-pass routing:
397
+ # 1. Score all agents with keyword matching
398
+ # 2. Domain specialists get +5 boost when they score > 0
399
+ # This ensures "refactor swift code" → apple_swift_expert (not dry_refactor)
400
+ # But "refactor the code" → dry_refactor (no domain detected)
401
+ # ═══════════════════════════════════════════════════════════════════════════════
402
+
403
+ DOMAIN_BOOST=5
404
+
405
+ select_agent_for_task() {
406
+ local task_description="$1"
407
+ local task_lower
408
+ task_lower=$(echo "$task_description" | tr '[:upper:]' '[:lower:]')
409
+
410
+ local best_agent="implementation_dev"
411
+ local best_score=0
412
+
413
+ for agent in $AGENT_LIST; do
414
+ # Skip the default agent (it's the fallback)
415
+ if [ "$agent" = "implementation_dev" ]; then continue; fi
416
+
417
+ local score
418
+ score=$(score_agent "$agent" "$task_lower")
419
+
420
+ # Domain boost: specialists get +5 when they score any points
421
+ # This ensures domain experts beat generic workflow agents
422
+ if [ $score -gt 0 ] && is_domain_specialist "$agent"; then
423
+ score=$((score + DOMAIN_BOOST))
424
+ fi
425
+
426
+ if [ $score -gt $best_score ]; then
427
+ best_score=$score
428
+ best_agent="$agent"
429
+ fi
430
+ done
431
+
432
+ echo "$best_agent"
433
+ }
434
+
435
+ get_agent_display_name() {
436
+ local agent="$1"
437
+ local display_var="AGENT_${agent}_DISPLAY"
438
+ echo "${!display_var:-$agent}"
439
+ }
440
+
441
+ # Map internal agent ID to Claude Code --agent flag name
442
+ # Internal IDs use underscores, Claude agent files use hyphens
443
+ get_agent_cli_name() {
444
+ local agent="$1"
445
+
446
+ # Map internal agent ID → .claude/agents/ filename (without .md)
447
+ case "$agent" in
448
+ hardening_guard) echo "hardening-guard" ;;
449
+ merlin_frontend) echo "merlin-frontend" ;;
450
+ merlin_api_designer) echo "merlin-api-designer" ;;
451
+ system_architect) echo "system-architect" ;;
452
+ tests_qa) echo "tests-qa" ;;
453
+ dry_refactor) echo "dry-refactor" ;;
454
+ ops_railway) echo "ops-railway" ;;
455
+ docs_keeper) echo "docs-keeper" ;;
456
+ merlin_debugger) echo "merlin-debugger" ;;
457
+ desktop_app_expert) echo "desktop-app-expert" ;;
458
+ apple_swift_expert) echo "apple-swift-expert" ;;
459
+ android_expert) echo "android-expert" ;;
460
+ ui_designer) echo "ui-designer" ;;
461
+ ui_builder) echo "ui-builder" ;;
462
+ animation_expert) echo "animation-expert" ;;
463
+ marketing_automation) echo "marketing-automation" ;;
464
+ implementation_dev) echo "implementation-dev" ;;
465
+ *) echo "merlin" ;; # fallback to generalist
466
+ esac
467
+ }
468
+
469
+ get_agent_required_skills() {
470
+ local agent="$1"
471
+ local skills_var="AGENT_${agent}_SKILLS"
472
+ echo "${!skills_var}"
473
+ }
474
+
475
+ # ═══════════════════════════════════════════════════════════════════════════════
476
+ # Full-Merge Composition
477
+ #
478
+ # When a domain specialist handles a workflow task (refactor, test, etc.),
479
+ # we inject the ENTIRE workflow agent's system prompt as additional context.
480
+ # This gives the specialist BOTH deep domain knowledge AND deep methodology.
481
+ #
482
+ # Example: "refactor Swift networking"
483
+ # → Agent: apple-swift-expert.md (loaded via --agent flag = full Swift expertise)
484
+ # → Context: dry-refactor.md (injected here = full refactoring methodology)
485
+ # → Claude gets 488 + 258 = 746 lines of combined expertise
486
+ # ═══════════════════════════════════════════════════════════════════════════════
487
+
488
+ # Map task type → workflow agent file path
489
+ get_workflow_agent_file() {
490
+ local task_type="$1"
491
+ local agents_dir="$HOME/.claude/agents"
492
+
493
+ case "$task_type" in
494
+ IMPLEMENTATION) echo "$agents_dir/implementation-dev.md" ;;
495
+ REFACTORING) echo "$agents_dir/dry-refactor.md" ;;
496
+ ARCHITECTURE) echo "$agents_dir/system-architect.md" ;;
497
+ TESTING) echo "$agents_dir/tests-qa.md" ;;
498
+ HARDENING) echo "$agents_dir/hardening-guard.md" ;;
499
+ DEBUGGING) echo "$agents_dir/merlin-debugger.md" ;;
500
+ *) echo "" ;;
501
+ esac
502
+ }
503
+
504
+ get_agent_context_injection() {
505
+ local agent="$1"
506
+ local task_description="${2:-}"
507
+ local context_var="AGENT_${agent}_CONTEXT"
508
+ local context="${!context_var}"
509
+
510
+ # Full-merge: for domain specialists, inject the ENTIRE workflow agent
511
+ if [ -n "$task_description" ] && is_domain_specialist "$agent"; then
512
+ local task_lower
513
+ task_lower=$(echo "$task_description" | tr '[:upper:]' '[:lower:]')
514
+ local task_type
515
+ task_type=$(detect_task_type "$task_lower")
516
+ local workflow_file
517
+ workflow_file=$(get_workflow_agent_file "$task_type")
518
+
519
+ if [ -n "$workflow_file" ] && [ -f "$workflow_file" ]; then
520
+ local workflow_content
521
+ workflow_content=$(cat "$workflow_file")
522
+
523
+ context="${context}
524
+
525
+ # ═══════════════════════════════════════════════════════════════════════════
526
+ # MERGED WORKFLOW AGENT: ${task_type} MODE
527
+ #
528
+ # You are a domain specialist handling a ${task_type,,} task.
529
+ # The full methodology agent has been merged into your context below.
530
+ # Apply these patterns and principles using YOUR domain expertise.
531
+ # Your domain knowledge takes precedence for technology-specific decisions.
532
+ # The workflow methodology guides HOW you work, not WHAT technology you use.
533
+ # ═══════════════════════════════════════════════════════════════════════════
534
+
535
+ ${workflow_content}"
536
+ fi
537
+ fi
538
+
539
+ echo "$context"
540
+ }
541
+
542
+ # ═══════════════════════════════════════════════════════════════════════════════
543
+ # Skill Detection
544
+ # ═══════════════════════════════════════════════════════════════════════════════
545
+
546
+ detect_skills_from_task() {
547
+ local task_description="$1"
548
+ local task_lower
549
+ task_lower=$(echo "$task_description" | tr '[:upper:]' '[:lower:]')
550
+ local detected=""
551
+
552
+ # Skill mappings
553
+ if echo "$task_lower" | grep -qE "image|avatar|upload|crop|canvas"; then
554
+ detected="${detected}canvas-design
555
+ "
556
+ fi
557
+
558
+ if echo "$task_lower" | grep -qE "payment|stripe|billing|checkout"; then
559
+ detected="${detected}payment-patterns
560
+ "
561
+ fi
562
+
563
+ if echo "$task_lower" | grep -qE "websocket|realtime|socket|notification"; then
564
+ detected="${detected}websocket-patterns
565
+ "
566
+ fi
567
+
568
+ if echo "$task_lower" | grep -qE "chart|graph|visualization|dashboard|analytics"; then
569
+ detected="${detected}data-visualization
570
+ "
571
+ fi
572
+
573
+ if echo "$task_lower" | grep -qE "email|smtp|sendgrid|mailgun"; then
574
+ detected="${detected}email-patterns
575
+ "
576
+ fi
577
+
578
+ echo "$detected"
579
+ }
580
+
581
+ # ═══════════════════════════════════════════════════════════════════════════════
582
+ # Skill Management
583
+ # ═══════════════════════════════════════════════════════════════════════════════
584
+
585
+ get_installed_skills() {
586
+ # Check ~/.claude/skills/ for installed skills
587
+ local skills_dir="$HOME/.claude/skills"
588
+ if [ -d "$skills_dir" ]; then
589
+ ls "$skills_dir" 2>/dev/null | sed 's/\.md$//'
590
+ fi
591
+ }
592
+
593
+ install_skill() {
594
+ local skill="$1"
595
+
596
+ # Try to install via npx claude-code-templates
597
+ if command -v npx &> /dev/null; then
598
+ npx claude-code-templates@latest --skill "$skill" 2>/dev/null
599
+ return $?
600
+ fi
601
+
602
+ return 1
603
+ }