Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,31 @@ const slimclawPlugin = {
let routingResult: { tier: string; confidence: number; model: string; signals: string[] } | null = null;
if (pluginConfig.routing.enabled) {
try {
const messages: Message[] = ((historyMessages as any[]) || []).map((msg: any) => ({
role: msg.role || 'user',
content: typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content || ''),
}));
// Add current prompt as last message
// Only classify the CURRENT request intent, not the full history.
// Full history causes everything to be "reasoning/lengthy-content".
// Include: system prompt (for context) + last 3 messages (conversational flow) + current prompt.
const classificationMessages: Message[] = [];

if (systemPrompt) {
classificationMessages.push({ role: 'system', content: systemPrompt });
}

// Last few messages for conversational context
const history = (historyMessages as any[]) || [];
const recentHistory = history.slice(-3);
for (const msg of recentHistory) {
if (!msg) continue;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Info

The history.slice(-3) operation will always return an array, even if empty. If history is undefined or null, recentHistory will be an empty array, and the loop will not execute. Therefore, the if (!msg) continue; check at src/index.ts:352 is redundant and can be removed.

Fix: Remove the if (!msg) continue; statement as msg will always be defined within the loop if recentHistory contains elements. The recentHistory array will not contain null or undefined elements itself.

🤖 Prompt for AI Agents
In src/index.ts around line 352:

Issue: The `history.slice(-3)` operation will always return an array, even if empty. If `history` is `undefined` or `null`, `recentHistory` will be an empty array, and the loop will not execute. Therefore, the `if (!msg) continue;` check at `src/index.ts:352` is redundant and can be removed.

Remove the `if (!msg) continue;` statement as `msg` will always be defined within the loop if `recentHistory` contains elements. The `recentHistory` array will not contain `null` or `undefined` elements itself.


classificationMessages.push({
role: msg.role || 'user',
content: typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content || ''),
});
}

if (prompt) {
messages.push({ role: 'user', content: prompt });
classificationMessages.push({ role: 'user', content: prompt });
}

const classification = classifyWithRouter(messages, { originalModel: (event as any).model });
const classification = classifyWithRouter(classificationMessages, { originalModel: (event as any).model });
const tierModel = pluginConfig.routing.tiers[classification.tier];
routingResult = {
tier: classification.tier,
Expand Down