mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-25 14:43:05 +09:00
Checkpoint: File edits
Automatic checkpoint created by Claude Code - Branch: v3 - Timestamp: 2026-01-14T18:49:59Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
49ea4d7b33
commit
85c9b391dc
1 file changed
+135
@@ -2591,6 +2591,141 @@ export const hooksWorkerDetect: MCPTool = {
|
||||
},
|
||||
};
|
||||
|
||||
// Model router - lazy loaded
|
||||
let modelRouterInstance: Awaited<ReturnType<typeof import('../ruvector/model-router.js').getModelRouter>> | null = null;
|
||||
async function getModelRouterInstance() {
|
||||
if (!modelRouterInstance) {
|
||||
try {
|
||||
const { getModelRouter } = await import('../ruvector/model-router.js');
|
||||
modelRouterInstance = getModelRouter();
|
||||
} catch {
|
||||
modelRouterInstance = null;
|
||||
}
|
||||
}
|
||||
return modelRouterInstance;
|
||||
}
|
||||
|
||||
// Model route tool - intelligent model selection
|
||||
export const hooksModelRoute: MCPTool = {
|
||||
name: 'hooks/model-route',
|
||||
description: 'Route task to optimal Claude model (haiku/sonnet/opus) based on complexity',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
task: { type: 'string', description: 'Task description to analyze' },
|
||||
preferSpeed: { type: 'boolean', description: 'Prefer faster models when possible' },
|
||||
preferCost: { type: 'boolean', description: 'Prefer cheaper models when possible' },
|
||||
},
|
||||
required: ['task'],
|
||||
},
|
||||
handler: async (params: Record<string, unknown>) => {
|
||||
const task = params.task as string;
|
||||
const router = await getModelRouterInstance();
|
||||
|
||||
if (!router) {
|
||||
// Fallback to simple heuristic
|
||||
const complexity = analyzeComplexityFallback(task);
|
||||
return {
|
||||
model: complexity > 0.7 ? 'opus' : complexity > 0.4 ? 'sonnet' : 'haiku',
|
||||
confidence: 0.7,
|
||||
complexity,
|
||||
reasoning: 'Fallback heuristic (model router not available)',
|
||||
implementation: 'fallback',
|
||||
};
|
||||
}
|
||||
|
||||
const result = await router.route(task);
|
||||
return {
|
||||
model: result.model,
|
||||
confidence: result.confidence,
|
||||
uncertainty: result.uncertainty,
|
||||
complexity: result.complexity,
|
||||
reasoning: result.reasoning,
|
||||
alternatives: result.alternatives,
|
||||
inferenceTimeUs: result.inferenceTimeUs,
|
||||
costMultiplier: result.costMultiplier,
|
||||
implementation: 'tiny-dancer-neural',
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
// Model route outcome - record outcome for learning
|
||||
export const hooksModelOutcome: MCPTool = {
|
||||
name: 'hooks/model-outcome',
|
||||
description: 'Record model routing outcome for learning',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
task: { type: 'string', description: 'Original task' },
|
||||
model: { type: 'string', enum: ['haiku', 'sonnet', 'opus'], description: 'Model used' },
|
||||
outcome: { type: 'string', enum: ['success', 'failure', 'escalated'], description: 'Task outcome' },
|
||||
},
|
||||
required: ['task', 'model', 'outcome'],
|
||||
},
|
||||
handler: async (params: Record<string, unknown>) => {
|
||||
const task = params.task as string;
|
||||
const model = params.model as 'haiku' | 'sonnet' | 'opus';
|
||||
const outcome = params.outcome as 'success' | 'failure' | 'escalated';
|
||||
|
||||
const router = await getModelRouterInstance();
|
||||
if (router) {
|
||||
router.recordOutcome(task, model, outcome);
|
||||
}
|
||||
|
||||
return {
|
||||
recorded: true,
|
||||
task: task.slice(0, 50),
|
||||
model,
|
||||
outcome,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
// Model router stats
|
||||
export const hooksModelStats: MCPTool = {
|
||||
name: 'hooks/model-stats',
|
||||
description: 'Get model routing statistics',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {},
|
||||
},
|
||||
handler: async () => {
|
||||
const router = await getModelRouterInstance();
|
||||
if (!router) {
|
||||
return {
|
||||
available: false,
|
||||
message: 'Model router not initialized',
|
||||
};
|
||||
}
|
||||
|
||||
const stats = router.getStats();
|
||||
return {
|
||||
available: true,
|
||||
...stats,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
// Simple fallback complexity analyzer
|
||||
function analyzeComplexityFallback(task: string): number {
|
||||
const taskLower = task.toLowerCase();
|
||||
|
||||
// High complexity indicators
|
||||
const highIndicators = ['architect', 'design', 'refactor', 'security', 'audit', 'complex', 'analyze'];
|
||||
const highCount = highIndicators.filter(ind => taskLower.includes(ind)).length;
|
||||
|
||||
// Low complexity indicators
|
||||
const lowIndicators = ['simple', 'typo', 'format', 'rename', 'comment'];
|
||||
const lowCount = lowIndicators.filter(ind => taskLower.includes(ind)).length;
|
||||
|
||||
// Base on length
|
||||
const lengthScore = Math.min(1, task.length / 200);
|
||||
|
||||
return Math.min(1, Math.max(0, 0.3 + highCount * 0.2 - lowCount * 0.15 + lengthScore * 0.2));
|
||||
}
|
||||
|
||||
// Worker cancel tool
|
||||
export const hooksWorkerCancel: MCPTool = {
|
||||
name: 'hooks/worker-cancel',
|
||||
|
||||
Reference in new issue
Block a user