monomind 1.10.57 → 1.11.1

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 (232) hide show
  1. package/.claude/agents/core/coordinator.md +71 -0
  2. package/.claude/agents/generated/case-analyst.md +50 -0
  3. package/.claude/agents/generated/copy-editor.md +45 -0
  4. package/.claude/agents/generated/court-reporter.md +50 -0
  5. package/.claude/agents/generated/defender.md +51 -0
  6. package/.claude/agents/generated/editor-in-chief.md +45 -0
  7. package/.claude/agents/generated/fact-checker.md +45 -0
  8. package/.claude/agents/generated/judge.md +51 -0
  9. package/.claude/agents/generated/prosecutor.md +51 -0
  10. package/.claude/agents/generated/reporter.md +45 -0
  11. package/.claude/commands/hooks/README.md +1 -1
  12. package/.claude/commands/hooks/overview.md +1 -1
  13. package/.claude/commands/mastermind/_repeat.md +1 -1
  14. package/.claude/commands/mastermind/do.md +3 -1
  15. package/.claude/commands/mastermind/help.md +2 -2
  16. package/.claude/commands/mastermind/master.md +39 -6
  17. package/.claude/commands/mastermind/memory.md +1 -1
  18. package/.claude/commands/memory/memory-search.md +2 -2
  19. package/.claude/commands/monitoring/status.md +1 -1
  20. package/.claude/commands/{browse.md → monobrowse.md} +2 -2
  21. package/.claude/commands/sparc.md +1 -1
  22. package/.claude/helpers/handlers/graph-status-handler.cjs +1 -1
  23. package/.claude/helpers/loop-tracker.cjs +1 -1
  24. package/.claude/scheduled_tasks.lock +1 -1
  25. package/.claude/skills/agent-browser-testing/SKILL.md +1 -1
  26. package/.claude/skills/hooks-automation/SKILL.md +0 -3
  27. package/.claude/skills/mastermind/build.md +1 -1
  28. package/.claude/skills/mastermind/code-quality-reviewer-prompt.md +60 -0
  29. package/.claude/skills/mastermind/content.md +1 -1
  30. package/.claude/skills/mastermind/createorg.md +79 -2
  31. package/.claude/skills/mastermind/design.md +3 -1
  32. package/.claude/skills/mastermind/finance.md +1 -1
  33. package/.claude/skills/mastermind/implementer-prompt.md +109 -0
  34. package/.claude/skills/mastermind/marketing.md +1 -1
  35. package/.claude/skills/mastermind/ops.md +1 -1
  36. package/.claude/skills/mastermind/plan.md +20 -2
  37. package/.claude/skills/mastermind/release.md +1 -1
  38. package/.claude/skills/mastermind/research.md +1 -1
  39. package/.claude/skills/mastermind/review.md +1 -1
  40. package/.claude/skills/mastermind/sales.md +1 -1
  41. package/.claude/skills/mastermind/spec-reviewer-prompt.md +63 -0
  42. package/.claude/skills/sparc-methodology/SKILL.md +3 -3
  43. package/.claude/skills/swarm-advanced/SKILL.md +1 -4
  44. package/.claude-plugin/README.md +1 -2
  45. package/.claude-plugin/docs/PLUGIN_SUMMARY.md +0 -1
  46. package/README.md +18 -32
  47. package/package.json +2 -2
  48. package/packages/@monomind/cli/README.md +18 -32
  49. package/packages/@monomind/cli/dist/src/agents/registry-builder.d.ts +1 -7
  50. package/packages/@monomind/cli/dist/src/agents/registry-builder.js +10 -6
  51. package/packages/@monomind/cli/dist/src/benchmarks/benchmark-runner.d.ts +59 -12
  52. package/packages/@monomind/cli/dist/src/benchmarks/benchmark-runner.js +67 -13
  53. package/packages/@monomind/cli/dist/src/benchmarks/pretrain/index.d.ts +0 -13
  54. package/packages/@monomind/cli/dist/src/commands/agent-wasm.d.ts +2 -2
  55. package/packages/@monomind/cli/dist/src/commands/agent-wasm.js +5 -5
  56. package/packages/@monomind/cli/dist/src/commands/agent.js +1 -6
  57. package/packages/@monomind/cli/dist/src/commands/analyze.d.ts +1 -1
  58. package/packages/@monomind/cli/dist/src/commands/analyze.js +8 -18
  59. package/packages/@monomind/cli/dist/src/commands/doctor.js +53 -3
  60. package/packages/@monomind/cli/dist/src/commands/embeddings.js +9 -33
  61. package/packages/@monomind/cli/dist/src/commands/hooks.js +31 -74
  62. package/packages/@monomind/cli/dist/src/commands/index.d.ts +4 -6
  63. package/packages/@monomind/cli/dist/src/commands/index.js +8 -15
  64. package/packages/@monomind/cli/dist/src/commands/init.js +2 -2
  65. package/packages/@monomind/cli/dist/src/commands/issues.js +16 -11
  66. package/packages/@monomind/cli/dist/src/commands/memory.js +6 -6
  67. package/packages/@monomind/cli/dist/src/commands/migrate.js +1 -2
  68. package/packages/@monomind/cli/dist/src/commands/monograph.js +18 -11
  69. package/packages/@monomind/cli/dist/src/commands/monovector/backup.d.ts +11 -0
  70. package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/backup.js +25 -25
  71. package/packages/@monomind/cli/dist/src/commands/monovector/benchmark.d.ts +11 -0
  72. package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/benchmark.js +14 -14
  73. package/packages/@monomind/cli/dist/src/commands/monovector/import.d.ts +18 -0
  74. package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/import.js +21 -21
  75. package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/index.d.ts +6 -6
  76. package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/index.js +22 -22
  77. package/packages/@monomind/cli/dist/src/commands/monovector/init.d.ts +11 -0
  78. package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/init.js +36 -36
  79. package/packages/@monomind/cli/dist/src/commands/monovector/migrate.d.ts +11 -0
  80. package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/migrate.js +16 -16
  81. package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/optimize.d.ts +2 -2
  82. package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/optimize.js +10 -10
  83. package/packages/@monomind/cli/dist/src/commands/monovector/setup.d.ts +18 -0
  84. package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/setup.js +77 -77
  85. package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/status.d.ts +2 -2
  86. package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/status.js +34 -34
  87. package/packages/@monomind/cli/dist/src/commands/neural.d.ts +1 -1
  88. package/packages/@monomind/cli/dist/src/commands/neural.js +31 -608
  89. package/packages/@monomind/cli/dist/src/commands/performance.js +7 -10
  90. package/packages/@monomind/cli/dist/src/commands/plugins.js +3 -4
  91. package/packages/@monomind/cli/dist/src/commands/process.js +5 -12
  92. package/packages/@monomind/cli/dist/src/commands/progress.js +16 -16
  93. package/packages/@monomind/cli/dist/src/commands/route.d.ts +2 -2
  94. package/packages/@monomind/cli/dist/src/commands/route.js +23 -23
  95. package/packages/@monomind/cli/dist/src/commands/status.js +0 -3
  96. package/packages/@monomind/cli/dist/src/commands/swarm.js +2 -3
  97. package/packages/@monomind/cli/dist/src/config-adapter.js +27 -0
  98. package/packages/@monomind/cli/dist/src/consensus/audit-writer.d.ts +44 -17
  99. package/packages/@monomind/cli/dist/src/dlq/dlq-replayer.d.ts +1 -1
  100. package/packages/@monomind/cli/dist/src/index.js +5 -5
  101. package/packages/@monomind/cli/dist/src/init/claudemd-generator.js +57 -37
  102. package/packages/@monomind/cli/dist/src/init/executor.js +17 -27
  103. package/packages/@monomind/cli/dist/src/init/helpers-generator.js +2 -2
  104. package/packages/@monomind/cli/dist/src/init/types.d.ts +1 -1
  105. package/packages/@monomind/cli/dist/src/mcp-client.js +1 -7
  106. package/packages/@monomind/cli/dist/src/mcp-server.js +9 -1
  107. package/packages/@monomind/cli/dist/src/mcp-tools/agent-tools.js +1 -52
  108. package/packages/@monomind/cli/dist/src/mcp-tools/analyze-tools.js +5 -5
  109. package/packages/@monomind/cli/dist/src/mcp-tools/browser-tools.d.ts +1 -1
  110. package/packages/@monomind/cli/dist/src/mcp-tools/browser-tools.js +6 -5
  111. package/packages/@monomind/cli/dist/src/mcp-tools/coordination-tools.d.ts +1 -1
  112. package/packages/@monomind/cli/dist/src/mcp-tools/coordination-tools.js +51 -54
  113. package/packages/@monomind/cli/dist/src/mcp-tools/daa-tools.d.ts +1 -1
  114. package/packages/@monomind/cli/dist/src/mcp-tools/embeddings-tools.js +10 -10
  115. package/packages/@monomind/cli/dist/src/mcp-tools/guidance-tools.js +0 -24
  116. package/packages/@monomind/cli/dist/src/mcp-tools/hooks-tools.js +189 -480
  117. package/packages/@monomind/cli/dist/src/mcp-tools/index.d.ts +0 -2
  118. package/packages/@monomind/cli/dist/src/mcp-tools/index.js +0 -2
  119. package/packages/@monomind/cli/dist/src/mcp-tools/monograph-compat.d.ts +334 -0
  120. package/packages/@monomind/cli/dist/src/mcp-tools/monograph-compat.js +1126 -0
  121. package/packages/@monomind/cli/dist/src/mcp-tools/monograph-tools.js +76 -34
  122. package/packages/@monomind/cli/dist/src/mcp-tools/neural-tools.d.ts +1 -1
  123. package/packages/@monomind/cli/dist/src/mcp-tools/neural-tools.js +2 -2
  124. package/packages/@monomind/cli/dist/src/mcp-tools/ruvllm-tools.d.ts +2 -2
  125. package/packages/@monomind/cli/dist/src/mcp-tools/ruvllm-tools.js +3 -3
  126. package/packages/@monomind/cli/dist/src/mcp-tools/terminal-tools.d.ts +1 -1
  127. package/packages/@monomind/cli/dist/src/mcp-tools/terminal-tools.js +29 -19
  128. package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.d.ts +1 -1
  129. package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.js +2 -2
  130. package/packages/@monomind/cli/dist/src/memory/intelligence.js +14 -8
  131. package/packages/@monomind/cli/dist/src/memory/memory-bridge.d.ts +17 -2
  132. package/packages/@monomind/cli/dist/src/memory/memory-bridge.js +76 -23
  133. package/packages/@monomind/cli/dist/src/memory/memory-initializer.d.ts +2 -2
  134. package/packages/@monomind/cli/dist/src/memory/memory-initializer.js +37 -39
  135. package/packages/@monomind/cli/dist/src/monovector/capabilities.d.ts +34 -0
  136. package/packages/@monomind/cli/dist/src/monovector/capabilities.js +37 -0
  137. package/packages/@monomind/cli/dist/src/monovector/command-outcomes.d.ts +37 -0
  138. package/packages/@monomind/cli/dist/src/monovector/command-outcomes.js +87 -0
  139. package/packages/@monomind/cli/dist/src/monovector/coverage-router.d.ts +103 -0
  140. package/packages/@monomind/cli/dist/src/monovector/coverage-router.js +337 -0
  141. package/packages/@monomind/cli/dist/src/monovector/coverage-tools.d.ts +14 -0
  142. package/packages/@monomind/cli/dist/src/monovector/coverage-tools.js +112 -0
  143. package/packages/@monomind/cli/dist/src/{ruvector → monovector}/diff-classifier.d.ts +2 -2
  144. package/packages/@monomind/cli/dist/src/monovector/index.d.ts +61 -0
  145. package/packages/@monomind/cli/dist/src/monovector/index.js +67 -0
  146. package/packages/@monomind/cli/dist/src/monovector/init-state.d.ts +35 -0
  147. package/packages/@monomind/cli/dist/src/monovector/init-state.js +36 -0
  148. package/packages/@monomind/cli/dist/src/monovector/route-outcomes.d.ts +55 -0
  149. package/packages/@monomind/cli/dist/src/monovector/route-outcomes.js +137 -0
  150. package/packages/@monomind/cli/dist/src/parser.js +3 -3
  151. package/packages/@monomind/cli/dist/src/plugins/store/discovery.js +0 -31
  152. package/packages/@monomind/cli/dist/src/production/circuit-breaker.d.ts +26 -6
  153. package/packages/@monomind/cli/dist/src/production/error-handler.d.ts +55 -30
  154. package/packages/@monomind/cli/dist/src/production/index.d.ts +3 -20
  155. package/packages/@monomind/cli/dist/src/production/index.js +3 -15
  156. package/packages/@monomind/cli/dist/src/production/monitoring.d.ts +54 -34
  157. package/packages/@monomind/cli/dist/src/production/monitoring.js +12 -14
  158. package/packages/@monomind/cli/dist/src/production/rate-limiter.d.ts +64 -19
  159. package/packages/@monomind/cli/dist/src/production/rate-limiter.js +5 -5
  160. package/packages/@monomind/cli/dist/src/production/retry.js +4 -2
  161. package/packages/@monomind/cli/dist/src/services/claim-service.d.ts +50 -59
  162. package/packages/@monomind/cli/dist/src/services/claim-service.js +83 -50
  163. package/packages/@monomind/cli/dist/src/services/config-file-manager.js +8 -1
  164. package/packages/@monomind/cli/dist/src/services/worker-daemon.js +4 -0
  165. package/packages/@monomind/cli/dist/src/types.d.ts +13 -0
  166. package/packages/@monomind/cli/package.json +14 -14
  167. package/packages/@monomind/guidance/dist/index.d.ts +1 -1
  168. package/packages/@monomind/guidance/dist/index.js +1 -1
  169. package/packages/@monomind/guidance/package.json +1 -2
  170. package/scripts/build-monovector.sh +10 -0
  171. package/scripts/publish-monovector.sh +20 -0
  172. package/.claude/commands/monomind/adr.md +0 -11
  173. package/.claude/commands/monomind/budget.md +0 -7
  174. package/.claude/commands/monomind/createtask.md +0 -277
  175. package/.claude/commands/monomind/do.md +0 -498
  176. package/.claude/commands/monomind/graph-status.md +0 -7
  177. package/.claude/commands/monomind/help.md +0 -118
  178. package/.claude/commands/monomind/idea.md +0 -273
  179. package/.claude/commands/monomind/improve.md +0 -352
  180. package/.claude/commands/monomind/loops.md +0 -7
  181. package/.claude/commands/monomind/memory.md +0 -230
  182. package/.claude/commands/monomind/repeat.md +0 -257
  183. package/.claude/commands/monomind/review.md +0 -317
  184. package/.claude/commands/monomind/specialagents.md +0 -125
  185. package/.claude/commands/monomind/swarm.md +0 -161
  186. package/.claude/commands/monomind/understand.md +0 -139
  187. package/.claude/commands/training/README.md +0 -39
  188. package/.claude/commands/training/neural-patterns.md +0 -73
  189. package/.claude/commands/training/neural-train.md +0 -79
  190. package/packages/@monomind/cli/dist/src/commands/appliance-advanced.d.ts +0 -9
  191. package/packages/@monomind/cli/dist/src/commands/appliance-advanced.js +0 -238
  192. package/packages/@monomind/cli/dist/src/commands/appliance.d.ts +0 -8
  193. package/packages/@monomind/cli/dist/src/commands/appliance.js +0 -406
  194. package/packages/@monomind/cli/dist/src/commands/ruvector/backup.d.ts +0 -11
  195. package/packages/@monomind/cli/dist/src/commands/ruvector/benchmark.d.ts +0 -11
  196. package/packages/@monomind/cli/dist/src/commands/ruvector/import.d.ts +0 -18
  197. package/packages/@monomind/cli/dist/src/commands/ruvector/init.d.ts +0 -11
  198. package/packages/@monomind/cli/dist/src/commands/ruvector/migrate.d.ts +0 -11
  199. package/packages/@monomind/cli/dist/src/commands/ruvector/setup.d.ts +0 -18
  200. package/packages/@monomind/cli/dist/src/ruvector/agent-wasm.d.ts +0 -182
  201. package/packages/@monomind/cli/dist/src/ruvector/agent-wasm.js +0 -316
  202. package/packages/@monomind/cli/dist/src/ruvector/ast-analyzer.d.ts +0 -67
  203. package/packages/@monomind/cli/dist/src/ruvector/ast-analyzer.js +0 -277
  204. package/packages/@monomind/cli/dist/src/ruvector/coverage-router.d.ts +0 -160
  205. package/packages/@monomind/cli/dist/src/ruvector/coverage-router.js +0 -539
  206. package/packages/@monomind/cli/dist/src/ruvector/coverage-tools.d.ts +0 -33
  207. package/packages/@monomind/cli/dist/src/ruvector/coverage-tools.js +0 -157
  208. package/packages/@monomind/cli/dist/src/ruvector/enhanced-model-router.d.ts +0 -146
  209. package/packages/@monomind/cli/dist/src/ruvector/enhanced-model-router.js +0 -551
  210. package/packages/@monomind/cli/dist/src/ruvector/flash-attention.d.ts +0 -195
  211. package/packages/@monomind/cli/dist/src/ruvector/flash-attention.js +0 -643
  212. package/packages/@monomind/cli/dist/src/ruvector/graph-analyzer.d.ts +0 -187
  213. package/packages/@monomind/cli/dist/src/ruvector/graph-analyzer.js +0 -929
  214. package/packages/@monomind/cli/dist/src/ruvector/index.d.ts +0 -67
  215. package/packages/@monomind/cli/dist/src/ruvector/index.js +0 -88
  216. package/packages/@monomind/cli/dist/src/ruvector/lora-adapter.d.ts +0 -218
  217. package/packages/@monomind/cli/dist/src/ruvector/lora-adapter.js +0 -455
  218. package/packages/@monomind/cli/dist/src/ruvector/model-router.d.ts +0 -222
  219. package/packages/@monomind/cli/dist/src/ruvector/model-router.js +0 -512
  220. package/packages/@monomind/cli/dist/src/ruvector/moe-router.d.ts +0 -213
  221. package/packages/@monomind/cli/dist/src/ruvector/moe-router.js +0 -649
  222. package/packages/@monomind/cli/dist/src/ruvector/q-learning-router.d.ts +0 -217
  223. package/packages/@monomind/cli/dist/src/ruvector/q-learning-router.js +0 -712
  224. package/packages/@monomind/cli/dist/src/ruvector/ruvllm-wasm.d.ts +0 -179
  225. package/packages/@monomind/cli/dist/src/ruvector/ruvllm-wasm.js +0 -363
  226. package/packages/@monomind/cli/dist/src/ruvector/semantic-router.d.ts +0 -77
  227. package/packages/@monomind/cli/dist/src/ruvector/semantic-router.js +0 -178
  228. package/packages/@monomind/cli/dist/src/ruvector/vector-db.d.ts +0 -69
  229. package/packages/@monomind/cli/dist/src/ruvector/vector-db.js +0 -243
  230. package/packages/@monomind/cli/dist/src/services/ruvector-training.d.ts +0 -222
  231. package/packages/@monomind/cli/dist/src/services/ruvector-training.js +0 -696
  232. /package/packages/@monomind/cli/dist/src/{ruvector → monovector}/diff-classifier.js +0 -0
@@ -1,551 +0,0 @@
1
- /**
2
- * Enhanced Model Router with Agent Booster AST Integration
3
- *
4
- * Implements ADR-026: 3-tier intelligent model routing:
5
- * - Tier 1: Agent Booster (WASM) - <1ms, $0 for simple transforms
6
- * - Tier 2: Haiku - ~500ms for low complexity
7
- * - Tier 3: Sonnet/Opus - 2-5s for high complexity
8
- *
9
- * @module enhanced-model-router
10
- */
11
- import { existsSync, readFileSync, realpathSync, statSync } from 'fs';
12
- import { extname, resolve, sep } from 'path';
13
- const MAX_ROUTE_FILE_SIZE = 1 * 1024 * 1024; // 1 MB
14
- function isPathSafe(filePath) {
15
- const root = process.cwd();
16
- try {
17
- const real = realpathSync(filePath);
18
- return real === root || real.startsWith(root + sep);
19
- }
20
- catch {
21
- const resolved = resolve(filePath);
22
- return resolved === root || resolved.startsWith(root + sep);
23
- }
24
- }
25
- import { getModelRouter } from './model-router.js';
26
- // ============================================================================
27
- // Intent Detection Patterns
28
- // ============================================================================
29
- /**
30
- * Pattern definitions for Agent Booster intent detection
31
- */
32
- const INTENT_PATTERNS = {
33
- 'var-to-const': {
34
- patterns: [
35
- /convert\s+var\s+to\s+const/i,
36
- /change\s+var\s+to\s+const/i,
37
- /change\s+var\s+declarations?\s+to\s+const/i,
38
- /replace\s+var\s+with\s+const/i,
39
- /var\s*(?:→|->|to)\s*const/i,
40
- /use\s+const\s+instead\s+of\s+var/i,
41
- ],
42
- weight: 1.0,
43
- description: 'Convert var declarations to const/let',
44
- },
45
- 'add-types': {
46
- patterns: [
47
- /add\s+type\s+annotations?/i,
48
- /add\s+typescript\s+types?/i,
49
- /type\s+this\s+function/i,
50
- /add\s+types?\s+to/i,
51
- /annotate\s+with\s+types?/i,
52
- ],
53
- weight: 0.9,
54
- description: 'Add TypeScript type annotations',
55
- },
56
- 'add-error-handling': {
57
- patterns: [
58
- /add\s+error\s+handling/i,
59
- /wrap\s+in\s+try\s*[/-]?\s*catch/i,
60
- /add\s+try\s*[/-]?\s*catch/i,
61
- /handle\s+errors?/i,
62
- /add\s+exception\s+handling/i,
63
- ],
64
- weight: 0.7, // Lower weight - often needs more context
65
- description: 'Wrap code in try/catch blocks',
66
- },
67
- 'async-await': {
68
- patterns: [
69
- /convert\s+to\s+async\s*[/-]?\s*await/i,
70
- /convert\s+\w+\s+to\s+async/i,
71
- /use\s+async\s*[/-]?\s*await/i,
72
- /change\s+promises?\s+to\s+async/i,
73
- /refactor\s+to\s+async/i,
74
- /\.then\s*(?:→|->|to)\s*await/i,
75
- /callback\s+to\s+async/i,
76
- /callbacks?\s+to\s+async/i,
77
- ],
78
- weight: 0.8,
79
- description: 'Convert callbacks/promises to async/await',
80
- },
81
- 'add-logging': {
82
- patterns: [
83
- /add\s+logging/i,
84
- /add\s+console\.log/i,
85
- /add\s+debug\s+logs?/i,
86
- /log\s+this\s+function/i,
87
- /add\s+trace\s+logging/i,
88
- ],
89
- weight: 0.85,
90
- description: 'Add console.log or logging statements',
91
- },
92
- 'remove-console': {
93
- patterns: [
94
- /remove\s+(?:all\s+)?console\.log/i,
95
- /remove\s+(?:all\s+)?console\s+statements?/i,
96
- /delete\s+(?:all\s+)?console\s+statements?/i,
97
- /strip\s+console/i,
98
- /clean\s+up\s+console/i,
99
- /clean\s+up\s+debug\s+logs?/i,
100
- /remove\s+(?:all\s+)?debug\s+logs?/i,
101
- /delete\s+(?:all\s+)?console\.log/i,
102
- ],
103
- weight: 0.95,
104
- description: 'Remove console.* calls',
105
- },
106
- };
107
- /**
108
- * File path extraction patterns
109
- */
110
- const FILE_PATH_PATTERNS = [
111
- /(?:in|from|to|file|path)\s+[`"']?([a-zA-Z0-9_./\\-]+\.[a-zA-Z]+)[`"']?/i,
112
- /[`"']([a-zA-Z0-9_./\\-]+\.[a-zA-Z]+)[`"']/,
113
- /(\S+\.[tj]sx?)\b/i,
114
- /(\S+\.(?:js|ts|jsx|tsx|py|rb|go|rs|java|kt|swift|c|cpp|h))\b/i,
115
- ];
116
- /**
117
- * Language detection by extension
118
- */
119
- /**
120
- * High-complexity keywords that indicate Tier 3 (Opus) routing
121
- * These tasks require deep reasoning and architectural understanding
122
- */
123
- const TIER3_KEYWORDS = [
124
- // Architecture & Design
125
- /\b(microservices?|architecture|system\s+design|distributed)\b/i,
126
- /\b(design|architect|plan)\s+(a|an|the|complex)\b/i,
127
- /\b(design)\s+\w+\s+(schema|system|architecture)\b/i,
128
- // Security
129
- /\b(oauth2?|pkce|jwt|rbac|authentication\s+system|security\s+audit)\b/i,
130
- /\b(refresh\s+token|token\s+rotation|role-based|permission|authorization)\b/i,
131
- /\b(encryption|cryptograph|certificate|ssl|tls)\b/i,
132
- /\b(end-to-end\s+encryption|key\s+rotation|secure\s+channel)\b/i,
133
- // Distributed Systems
134
- /\b(consensus|distributed|byzantine|raft|paxos)\b/i,
135
- /\b(replication|sharding|partitioning|eventual\s+consistency)\b/i,
136
- /\b(load\s+balanc|fault[- ]toleran|high\s+availability)\b/i,
137
- /\b(message\s+queue|event\s+sourc|cqrs|saga)\b/i,
138
- // Complex Algorithms
139
- /\b(algorithm|machine\s+learning|neural|optimization)\b/i,
140
- /\b(graph\s+algorithm|tree\s+traversal|dynamic\s+programming)\b/i,
141
- // Database Design
142
- /\b(schema\s+design|database\s+architect|data\s+model)\b/i,
143
- /\b(database\s+schema|multi[- ]tenant)\b/i,
144
- /\b(normalization|denormalization|index\s+strateg)\b/i,
145
- // Performance Critical
146
- /\b(performance\s+critical|low\s+latency|high\s+throughput)\b/i,
147
- /\b(memory\s+optimi|cache\s+strateg|concurrent)\b/i,
148
- ];
149
- const LANGUAGE_MAP = {
150
- '.js': 'javascript',
151
- '.jsx': 'javascript',
152
- '.ts': 'typescript',
153
- '.tsx': 'typescript',
154
- '.py': 'python',
155
- '.rb': 'ruby',
156
- '.go': 'go',
157
- '.rs': 'rust',
158
- '.java': 'java',
159
- '.kt': 'kotlin',
160
- '.swift': 'swift',
161
- '.c': 'c',
162
- '.cpp': 'cpp',
163
- '.h': 'c',
164
- };
165
- // ============================================================================
166
- // Enhanced Model Router Implementation
167
- // ============================================================================
168
- /**
169
- * Enhanced Model Router with Agent Booster AST integration
170
- *
171
- * Provides intelligent 3-tier routing:
172
- * - Tier 1: Agent Booster for simple code transforms (352x faster, $0)
173
- * - Tier 2: Haiku for low complexity tasks
174
- * - Tier 3: Sonnet/Opus for complex reasoning tasks
175
- */
176
- export class EnhancedModelRouter {
177
- config;
178
- tinyDancerRouter;
179
- constructor(config) {
180
- this.config = {
181
- agentBoosterEnabled: true,
182
- agentBoosterConfidenceThreshold: 0.7,
183
- enabledIntents: [
184
- 'var-to-const',
185
- 'add-types',
186
- 'add-error-handling',
187
- 'async-await',
188
- 'add-logging',
189
- 'remove-console',
190
- ],
191
- complexityThresholds: {
192
- haiku: 0.3,
193
- sonnet: 0.6,
194
- opus: 1.0,
195
- },
196
- preferCost: false,
197
- preferQuality: false,
198
- ...config,
199
- };
200
- this.tinyDancerRouter = getModelRouter();
201
- }
202
- /**
203
- * Detect code editing intent from task description
204
- */
205
- detectIntent(task) {
206
- const taskLower = task.toLowerCase();
207
- let bestIntent = null;
208
- let bestScore = 0;
209
- for (const [intentType, config] of Object.entries(INTENT_PATTERNS)) {
210
- if (!this.config.enabledIntents.includes(intentType)) {
211
- continue;
212
- }
213
- for (const pattern of config.patterns) {
214
- if (pattern.test(taskLower)) {
215
- const score = config.weight;
216
- if (score > bestScore) {
217
- bestScore = score;
218
- bestIntent = {
219
- type: intentType,
220
- confidence: score,
221
- description: config.description,
222
- };
223
- }
224
- }
225
- }
226
- }
227
- // Extract file path if intent found
228
- if (bestIntent) {
229
- const filePath = this.extractFilePath(task);
230
- if (filePath) {
231
- bestIntent.filePath = filePath;
232
- bestIntent.language = this.detectLanguage(filePath);
233
- // Boost confidence if file exists
234
- if (existsSync(filePath)) {
235
- bestIntent.confidence = Math.min(1.0, bestIntent.confidence + 0.1);
236
- }
237
- }
238
- }
239
- return bestIntent;
240
- }
241
- /**
242
- * Extract file path from task description
243
- */
244
- extractFilePath(task) {
245
- for (const pattern of FILE_PATH_PATTERNS) {
246
- const match = task.match(pattern);
247
- if (match && match[1]) {
248
- return match[1];
249
- }
250
- }
251
- return null;
252
- }
253
- /**
254
- * Detect language from file extension
255
- */
256
- detectLanguage(filePath) {
257
- const ext = extname(filePath).toLowerCase();
258
- return LANGUAGE_MAP[ext] || 'javascript';
259
- }
260
- /**
261
- * Check if task contains Tier 3 (Opus) keywords
262
- */
263
- containsTier3Keywords(task) {
264
- let count = 0;
265
- for (const pattern of TIER3_KEYWORDS) {
266
- if (pattern.test(task)) {
267
- count++;
268
- }
269
- }
270
- return { matches: count > 0, count };
271
- }
272
- /**
273
- * Route a task to the optimal tier and handler
274
- */
275
- async route(task, context) {
276
- // Step 1: Try Agent Booster intent detection
277
- if (this.config.agentBoosterEnabled) {
278
- const intent = this.detectIntent(task);
279
- if (intent && intent.confidence >= this.config.agentBoosterConfidenceThreshold) {
280
- return {
281
- tier: 1,
282
- handler: 'agent-booster',
283
- confidence: intent.confidence,
284
- reasoning: `Agent Booster can handle "${intent.type}" with ${(intent.confidence * 100).toFixed(0)}% confidence`,
285
- agentBoosterIntent: intent,
286
- canSkipLLM: true,
287
- estimatedLatencyMs: 1,
288
- estimatedCost: 0,
289
- };
290
- }
291
- }
292
- // Step 2: Check for Tier 3 keywords (architecture, security, distributed)
293
- const tier3Check = this.containsTier3Keywords(task);
294
- if (tier3Check.matches && tier3Check.count >= 2) {
295
- // Strong signal for Opus - multiple complex keywords
296
- return {
297
- tier: 3,
298
- handler: 'opus',
299
- model: 'opus',
300
- confidence: Math.min(0.95, 0.7 + tier3Check.count * 0.1),
301
- complexity: 0.8 + tier3Check.count * 0.05,
302
- reasoning: `High complexity task (${tier3Check.count} architectural keywords) - using opus`,
303
- canSkipLLM: false,
304
- estimatedLatencyMs: 5000,
305
- estimatedCost: 0.015,
306
- };
307
- }
308
- // Step 3: AST complexity analysis (if file path provided)
309
- let astComplexity;
310
- const targetFile = context?.filePath || this.extractFilePath(task);
311
- if (targetFile && existsSync(targetFile)) {
312
- try {
313
- astComplexity = await this.analyzeASTComplexity(targetFile);
314
- }
315
- catch {
316
- // AST analysis not available, continue with text-based routing
317
- }
318
- }
319
- // Step 4: Text-based complexity + tiny-dancer routing
320
- const tinyDancerResult = await this.tinyDancerRouter.route(task);
321
- // Step 5: Combine AST complexity with tiny-dancer result
322
- // Also boost if single tier3 keyword found
323
- let finalComplexity = astComplexity !== undefined
324
- ? (astComplexity + tinyDancerResult.complexity) / 2
325
- : tinyDancerResult.complexity;
326
- // Boost complexity if tier3 keywords found (even just one)
327
- if (tier3Check.matches) {
328
- finalComplexity = Math.min(1.0, finalComplexity + 0.25);
329
- }
330
- // Step 6: Determine tier based on complexity
331
- const { haiku, sonnet } = this.config.complexityThresholds;
332
- if (finalComplexity < haiku) {
333
- return {
334
- tier: 2,
335
- handler: 'haiku',
336
- model: 'haiku',
337
- confidence: tinyDancerResult.confidence,
338
- complexity: finalComplexity,
339
- reasoning: `Low complexity (${(finalComplexity * 100).toFixed(0)}%) - using haiku`,
340
- canSkipLLM: false,
341
- estimatedLatencyMs: 500,
342
- estimatedCost: 0.0002,
343
- };
344
- }
345
- if (finalComplexity < sonnet) {
346
- return {
347
- tier: 2,
348
- handler: 'sonnet',
349
- model: 'sonnet',
350
- confidence: tinyDancerResult.confidence,
351
- complexity: finalComplexity,
352
- reasoning: `Medium complexity (${(finalComplexity * 100).toFixed(0)}%) - using sonnet`,
353
- canSkipLLM: false,
354
- estimatedLatencyMs: 2000,
355
- estimatedCost: 0.003,
356
- };
357
- }
358
- return {
359
- tier: 3,
360
- handler: 'opus',
361
- model: 'opus',
362
- confidence: tinyDancerResult.confidence,
363
- complexity: finalComplexity,
364
- reasoning: `High complexity (${(finalComplexity * 100).toFixed(0)}%) - using opus`,
365
- canSkipLLM: false,
366
- estimatedLatencyMs: 5000,
367
- estimatedCost: 0.015,
368
- };
369
- }
370
- /**
371
- * Analyze AST complexity of a file
372
- * Returns normalized complexity score (0-1)
373
- */
374
- async analyzeASTComplexity(filePath) {
375
- try {
376
- if (!isPathSafe(filePath))
377
- return 0.5;
378
- const st = statSync(filePath, { throwIfNoEntry: false });
379
- if (!st || st.size > MAX_ROUTE_FILE_SIZE)
380
- return 0.5;
381
- const content = readFileSync(filePath, 'utf-8');
382
- const lines = content.split('\n');
383
- // Simple heuristics for complexity
384
- let complexity = 0;
385
- // Line count contribution
386
- complexity += Math.min(0.3, lines.length / 1000);
387
- // Nesting depth estimation (count indentation)
388
- const avgIndent = lines
389
- .filter((l) => l.trim().length > 0)
390
- .map((l) => l.match(/^(\s*)/)?.[1].length || 0)
391
- .reduce((sum, indent) => sum + indent, 0) / Math.max(1, lines.length);
392
- complexity += Math.min(0.2, avgIndent / 20);
393
- // Control flow complexity (count keywords)
394
- const controlFlowCount = (content.match(/\b(if|else|for|while|switch|case|try|catch|async|await)\b/g) || []).length;
395
- complexity += Math.min(0.3, controlFlowCount / 100);
396
- // Function/class count
397
- const functionCount = (content.match(/\b(function|class|=>)\b/g) || []).length;
398
- complexity += Math.min(0.2, functionCount / 50);
399
- return Math.min(1, complexity);
400
- }
401
- catch {
402
- return 0.5; // Default to medium complexity on error
403
- }
404
- }
405
- /**
406
- * Execute task using the appropriate tier
407
- * Returns the result and routing information
408
- */
409
- async execute(task, context) {
410
- const routeResult = await this.route(task, context);
411
- if (routeResult.tier === 1 && routeResult.agentBoosterIntent) {
412
- // Try to execute with Agent Booster
413
- const abResult = await this.tryAgentBooster(routeResult.agentBoosterIntent, context);
414
- if (abResult.success) {
415
- return {
416
- result: { applied: true, confidence: abResult.confidence },
417
- routeResult,
418
- };
419
- }
420
- // Agent Booster failed, fall back to LLM
421
- routeResult.tier = 2;
422
- routeResult.handler = 'sonnet';
423
- routeResult.model = 'sonnet';
424
- routeResult.canSkipLLM = false;
425
- routeResult.reasoning += ' (Agent Booster fallback to LLM)';
426
- }
427
- // Return routing result - caller handles LLM invocation
428
- return { result: routeResult.reasoning, routeResult };
429
- }
430
- /**
431
- * Try to apply edit using Agent Booster
432
- */
433
- async tryAgentBooster(intent, context) {
434
- try {
435
- const filePath = intent.filePath || context?.filePath;
436
- if (!filePath || !existsSync(filePath)) {
437
- return { success: false, confidence: 0 };
438
- }
439
- if (!isPathSafe(filePath))
440
- return { success: false, confidence: 0 };
441
- const fst = statSync(filePath, { throwIfNoEntry: false });
442
- if (!fst || fst.size > MAX_ROUTE_FILE_SIZE)
443
- return { success: false, confidence: 0 };
444
- const originalCode = context?.originalCode || readFileSync(filePath, 'utf-8');
445
- const intentToInstruction = {
446
- 'var-to-const': 'Convert all var declarations to const',
447
- 'add-types': 'Add TypeScript type annotations',
448
- 'add-error-handling': 'Wrap in try/catch blocks',
449
- 'async-await': 'Convert to async/await',
450
- 'add-logging': 'Add console.log statements',
451
- 'remove-console': 'Remove all console.* statements',
452
- };
453
- const instruction = intentToInstruction[intent.type];
454
- const language = intent.language || 'javascript';
455
- // Try local agentic-flow agent-booster (v1 — no npx needed)
456
- // Note: agent-booster export declared but dist missing in alpha.1; use intelligence path as fallback
457
- const boosterModule = await import('agentic-flow/agent-booster')
458
- .catch(() => import(/* @vite-ignore */ 'agentic-flow/intelligence/agent-booster-enhanced'))
459
- .catch(() => null);
460
- if (boosterModule?.enhancedApply) {
461
- const result = await boosterModule.enhancedApply({
462
- code: originalCode,
463
- edit: instruction,
464
- language,
465
- });
466
- if (result && result.confidence >= this.config.agentBoosterConfidenceThreshold) {
467
- return { success: true, confidence: result.confidence, output: result.output };
468
- }
469
- return { success: false, confidence: result?.confidence ?? 0 };
470
- }
471
- // Fallback: shell out to npx agent-booster
472
- // Sanitize language to prevent command injection (whitelist only)
473
- const SAFE_LANGUAGES = ['javascript', 'typescript', 'python', 'rust', 'go', 'java', 'c', 'cpp', 'ruby', 'swift', 'kotlin'];
474
- const safeLang = SAFE_LANGUAGES.includes(language) ? language : 'javascript';
475
- const { execSync } = await import('child_process');
476
- const cmd = `npx --yes agent-booster@0.2.2 apply --language ${safeLang}`;
477
- const result = execSync(cmd, {
478
- encoding: 'utf-8',
479
- input: JSON.stringify({ code: originalCode, edit: instruction }),
480
- maxBuffer: 10 * 1024 * 1024,
481
- timeout: 5000,
482
- stdio: ['pipe', 'pipe', 'pipe'],
483
- });
484
- const parsed = JSON.parse(result);
485
- if (parsed.confidence >= this.config.agentBoosterConfidenceThreshold) {
486
- return { success: true, confidence: parsed.confidence, output: parsed.output };
487
- }
488
- return { success: false, confidence: parsed.confidence ?? 0 };
489
- }
490
- catch {
491
- // Agent Booster not available or failed
492
- return { success: false, confidence: 0 };
493
- }
494
- }
495
- /**
496
- * Get router statistics
497
- */
498
- getStats() {
499
- return {
500
- config: { ...this.config },
501
- tinyDancerStats: this.tinyDancerRouter.getStats(),
502
- };
503
- }
504
- }
505
- // ============================================================================
506
- // Singleton & Factory Functions
507
- // ============================================================================
508
- let enhancedRouterInstance = null;
509
- /**
510
- * Get or create the singleton EnhancedModelRouter instance
511
- */
512
- export function getEnhancedModelRouter(config) {
513
- if (!enhancedRouterInstance) {
514
- enhancedRouterInstance = new EnhancedModelRouter(config);
515
- }
516
- return enhancedRouterInstance;
517
- }
518
- /**
519
- * Reset the singleton instance
520
- */
521
- export function resetEnhancedModelRouter() {
522
- enhancedRouterInstance = null;
523
- }
524
- /**
525
- * Create a new EnhancedModelRouter instance (non-singleton)
526
- */
527
- export function createEnhancedModelRouter(config) {
528
- return new EnhancedModelRouter(config);
529
- }
530
- // ============================================================================
531
- // Convenience Functions
532
- // ============================================================================
533
- /**
534
- * Quick route function with enhanced routing
535
- */
536
- export async function enhancedRouteToModel(task, context) {
537
- const router = getEnhancedModelRouter();
538
- return router.route(task, context);
539
- }
540
- /**
541
- * Detect if a task can be handled by Agent Booster
542
- */
543
- export function canUseAgentBooster(task) {
544
- const router = getEnhancedModelRouter();
545
- const intent = router.detectIntent(task);
546
- if (intent && intent.confidence >= 0.7) {
547
- return { canUse: true, intent };
548
- }
549
- return { canUse: false };
550
- }
551
- //# sourceMappingURL=enhanced-model-router.js.map