@gotza02/sequential-thinking 2026.3.9 → 2026.3.10

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 (2) hide show
  1. package/dist/lib.js +47 -3
  2. package/package.json +1 -1
package/dist/lib.js CHANGED
@@ -437,6 +437,13 @@ ${typeof wrappedThought === 'string' && wrappedThought.startsWith('│') ? wrapp
437
437
  const complexity = input.complexity || 'medium';
438
438
  const warnings = [];
439
439
  let feedbackExtension = "";
440
+ // --- šŸ”„ FEATURE 0: Smart Branching Reward (Reset Confidence on Pivot) ---
441
+ if (input.branchFromThought) {
442
+ if (this.confidenceScore < 90) {
443
+ this.confidenceScore = 90;
444
+ feedbackExtension += `\n🌿 BRANCH DETECTED: Confidence restored to 90. Good decision to pivot.`;
445
+ }
446
+ }
440
447
  // --- 🧠 FEATURE 1: Semantic Thought Recall ---
441
448
  if (input.thoughtType === 'analysis') {
442
449
  const previousSolution = await this.findSolution(input.thought);
@@ -444,14 +451,50 @@ ${typeof wrappedThought === 'string' && wrappedThought.startsWith('│') ? wrapp
444
451
  feedbackExtension += `\nšŸ’” RECALL: I found a similar past solution for '${previousSolution.topic}'.\nTry these steps: ${previousSolution.solution.substring(0, 100)}...`;
445
452
  }
446
453
  }
447
- // --- šŸ“Š FEATURE 4: Meta-Cognition Score Check ---
454
+ // --- ā›” FEATURE 1.5: Anti-Insanity (Prevent Repeating Failed Executions) ---
455
+ const historyForCheck = this.thoughtHistory.filter(t => t.blockId === input.blockId || (input.blockId === this.currentBlockId && t.blockId === this.currentBlockId));
456
+ if (input.thoughtType === 'execution') {
457
+ const failedExecutions = historyForCheck.filter((t, index) => {
458
+ if (t.thoughtType !== 'execution')
459
+ return false;
460
+ // Find the observation immediately following this execution
461
+ // Note: This relies on thoughtNumber order
462
+ const nextThought = this.thoughtHistory.find(h => h.thoughtNumber === t.thoughtNumber + 1);
463
+ if (nextThought && nextThought.thoughtType === 'observation') {
464
+ const result = nextThought.toolResult?.toLowerCase() || "";
465
+ // Check for failure signals
466
+ return result.includes("error") || result.includes("fail") || result.includes("exception") || result.includes("enoent");
467
+ }
468
+ return false;
469
+ });
470
+ const isRepeatedFailure = failedExecutions.some(t => t.thought.trim() === input.thought.trim());
471
+ if (isRepeatedFailure) {
472
+ const failedItem = failedExecutions.find(t => t.thought.trim() === input.thought.trim());
473
+ warnings.push(`ā›” INSANITY CHECK: You are trying to run a command that ALREADY FAILED in thought #${failedItem?.thoughtNumber}. STOP. Do not repeat mistakes. Try a different parameter or tool.`);
474
+ this.confidenceScore -= 15;
475
+ }
476
+ }
477
+ // --- šŸ“Š FEATURE 4: Meta-Cognition Score Check (Reflexion Mandate & Smart Branching) ---
448
478
  if (this.confidenceScore < 50 && input.thoughtType !== 'reflexion' && input.thoughtType !== 'analysis') {
479
+ // Smart Branching: Find the last valid planning point
480
+ const lastGoodPlan = historyForCheck
481
+ .slice()
482
+ .reverse()
483
+ .find(t => t.thoughtType === 'planning' || t.thoughtType === 'hypothesis');
484
+ const recoveryAdvice = lastGoodPlan
485
+ ? `RECOMMENDATION: Branch from thought #${lastGoodPlan.thoughtNumber} to try a new approach.`
486
+ : `RECOMMENDATION: Use 'reflexion' to analyze why current attempts are failing.`;
449
487
  return {
450
488
  content: [{
451
489
  type: "text",
452
490
  text: JSON.stringify({
453
491
  status: "CRITICAL_STOP",
454
- feedback: ["🚨 CONFIDENCE TOO LOW (<50). Execution blocked. Please use 'reflexion' or 'analysis' to self-correct, or request human intervention."],
492
+ feedback: [
493
+ "🚨 CONFIDENCE CRITICAL (<50). Execution blocked to prevent further damage.",
494
+ "šŸ›‘ STOP: You are likely in a loop or making repeated errors.",
495
+ "šŸ‘‰ REQUIRED ACTION: You must switch thoughtType to 'reflexion' to critique your errors.",
496
+ recoveryAdvice
497
+ ],
455
498
  confidenceScore: this.confidenceScore
456
499
  }, null, 2)
457
500
  }],
@@ -523,7 +566,8 @@ ${typeof wrappedThought === 'string' && wrappedThought.startsWith('│') ? wrapp
523
566
  // Rule 3: Missing Observation
524
567
  if (lastThought &&
525
568
  lastThought.thoughtType === 'execution' &&
526
- input.thoughtType !== 'observation') {
569
+ input.thoughtType !== 'observation' &&
570
+ !input.branchFromThought) {
527
571
  warnings.push(`šŸ’” INTERLEAVED HINT: Your last step was 'execution'. The next step SHOULD be 'observation' to record and analyze the tool result before continuing.`);
528
572
  }
529
573
  // Rule 4: Skipping Planning (Adaptive)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gotza02/sequential-thinking",
3
- "version": "2026.3.9",
3
+ "version": "2026.3.10",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },