sapper-iq 1.1.7 → 1.1.9
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.
- package/package.json +1 -1
- package/sapper.mjs +60 -2
package/package.json
CHANGED
package/sapper.mjs
CHANGED
|
@@ -61,6 +61,7 @@ const spinner = ora();
|
|
|
61
61
|
const CONTEXT_FILE = '.sapper_context.json';
|
|
62
62
|
|
|
63
63
|
let stepMode = false;
|
|
64
|
+
let debugMode = false; // Toggle with /debug command
|
|
64
65
|
let rl = readline.createInterface({
|
|
65
66
|
input: process.stdin,
|
|
66
67
|
output: process.stdout,
|
|
@@ -353,10 +354,23 @@ IMPORTANT RULES:
|
|
|
353
354
|
// 3. Rebuild the messages array starting with the ORIGINAL prompt
|
|
354
355
|
messages = [originalSystemPrompt, ...recentMessages];
|
|
355
356
|
|
|
356
|
-
// 4.
|
|
357
|
+
// 4. Add reminder to stay in Agent Mode (not chatbot mode)
|
|
358
|
+
messages.push({
|
|
359
|
+
role: 'system',
|
|
360
|
+
content: `CONTEXT PRUNED. REMINDER: You are an AGENT, not a chatbot. You MUST use tools to take action:
|
|
361
|
+
- [TOOL:LIST]path[/TOOL] - List directory
|
|
362
|
+
- [TOOL:READ]path[/TOOL] - Read file
|
|
363
|
+
- [TOOL:SEARCH]pattern[/TOOL] - Search codebase
|
|
364
|
+
- [TOOL:WRITE]path]content[/TOOL] - Create/overwrite file
|
|
365
|
+
- [TOOL:PATCH]path]old|||new[/TOOL] - Edit file
|
|
366
|
+
- [TOOL:SHELL]command[/TOOL] - Run terminal command
|
|
367
|
+
Do NOT just display content. Actually WRITE files using the tool.`
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
// 5. Save to context file so it persists
|
|
357
371
|
fs.writeFileSync(CONTEXT_FILE, JSON.stringify(messages));
|
|
358
372
|
|
|
359
|
-
console.log(chalk.green(`✅ Pruned context.
|
|
373
|
+
console.log(chalk.green(`✅ Pruned context. Sapper reminded to stay in Agent Mode.`));
|
|
360
374
|
console.log(chalk.gray(`Context size: ${messages.length} messages\n`));
|
|
361
375
|
continue;
|
|
362
376
|
}
|
|
@@ -367,6 +381,7 @@ IMPORTANT RULES:
|
|
|
367
381
|
console.log(chalk.white(' /reset, /clear') + chalk.gray(' - Clear all context and start fresh'));
|
|
368
382
|
console.log(chalk.white(' /prune') + chalk.gray(' - Remove old messages, keep last 4'));
|
|
369
383
|
console.log(chalk.white(' /context') + chalk.gray(' - Show current context size'));
|
|
384
|
+
console.log(chalk.white(' /debug') + chalk.gray(' - Toggle debug mode (shows regex analysis)'));
|
|
370
385
|
console.log(chalk.white(' /help') + chalk.gray(' - Show this help message'));
|
|
371
386
|
console.log(chalk.white(' exit') + chalk.gray(' - Exit Sapper\n'));
|
|
372
387
|
continue;
|
|
@@ -382,6 +397,16 @@ IMPORTANT RULES:
|
|
|
382
397
|
continue;
|
|
383
398
|
}
|
|
384
399
|
|
|
400
|
+
// Handle debug mode toggle
|
|
401
|
+
if (input.toLowerCase() === '/debug') {
|
|
402
|
+
debugMode = !debugMode;
|
|
403
|
+
console.log(chalk.magenta(`🔧 Debug mode: ${debugMode ? 'ON' : 'OFF'}`));
|
|
404
|
+
if (debugMode) {
|
|
405
|
+
console.log(chalk.gray(' Will show regex matching details after each AI response.'));
|
|
406
|
+
}
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
|
|
385
410
|
messages.push({ role: 'user', content: input });
|
|
386
411
|
|
|
387
412
|
let toolRounds = 0; // Prevent infinite loops
|
|
@@ -423,6 +448,39 @@ IMPORTANT RULES:
|
|
|
423
448
|
// Fixed regex: .+? (non-greedy) stops correctly before [/TOOL]
|
|
424
449
|
const toolMatches = [...msg.matchAll(/\[TOOL:(\w+)\](.+?)(?:\]([\s\S]*?))?\[\/TOOL\]/g)];
|
|
425
450
|
|
|
451
|
+
// Debug mode: show what regex sees
|
|
452
|
+
if (debugMode) {
|
|
453
|
+
console.log(chalk.magenta('\n═══ DEBUG: REGEX ANALYSIS ═══'));
|
|
454
|
+
console.log(chalk.gray(`Response length: ${msg.length} chars`));
|
|
455
|
+
|
|
456
|
+
// Check for tool-like patterns
|
|
457
|
+
const hasToolStart = msg.includes('[TOOL:');
|
|
458
|
+
const hasToolEnd = msg.includes('[/TOOL]');
|
|
459
|
+
const hasBrokenEnd = msg.includes('[/]') || msg.includes('[/WRITE]') || msg.includes('[/READ]');
|
|
460
|
+
|
|
461
|
+
console.log(chalk.gray(`Contains [TOOL:: ${hasToolStart ? chalk.green('YES') : chalk.red('NO')}`));
|
|
462
|
+
console.log(chalk.gray(`Contains [/TOOL]: ${hasToolEnd ? chalk.green('YES') : chalk.red('NO')}`));
|
|
463
|
+
if (hasBrokenEnd) {
|
|
464
|
+
console.log(chalk.red(`⚠️ Found broken closing tag: [/] or [/WRITE] etc.`));
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
console.log(chalk.gray(`Matches found: ${toolMatches.length}`));
|
|
468
|
+
|
|
469
|
+
if (toolMatches.length > 0) {
|
|
470
|
+
toolMatches.forEach((m, i) => {
|
|
471
|
+
console.log(chalk.cyan(` Match ${i+1}: type=${m[1]}, path=${m[2]?.substring(0,50)}...`));
|
|
472
|
+
});
|
|
473
|
+
} else if (hasToolStart) {
|
|
474
|
+
// Show the raw tool attempt for debugging
|
|
475
|
+
const toolAttempt = msg.match(/\[TOOL:[^\]]*\][^\[]{0,100}/s);
|
|
476
|
+
if (toolAttempt) {
|
|
477
|
+
console.log(chalk.yellow(` Raw tool attempt (first 150 chars):`);
|
|
478
|
+
console.log(chalk.gray(` "${toolAttempt[0].substring(0, 150)}..."`));
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
console.log(chalk.magenta('═══════════════════════════════\n'));
|
|
482
|
+
}
|
|
483
|
+
|
|
426
484
|
if (toolMatches.length > 0) {
|
|
427
485
|
toolRounds++;
|
|
428
486
|
|