@gotza02/sequential-thinking 2026.3.8 → 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.
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)
@@ -87,21 +87,8 @@ If you have tried to fix the same problem 3 times and failed:
87
87
  blockId: z.string().optional().describe("ID for the current topic block (e.g., 'auth-debug', 'api-research'). Keep same ID to stay in context."),
88
88
  relatedToolCall: z.string().optional().describe("If type='execution', specify the tool name here (e.g., 'read_file', 'edit_file')"),
89
89
  toolResult: z.string().optional().describe("If type='observation', summarize the key findings from the tool output here"),
90
- complexity: z.preprocess((val) => {
91
- if (typeof val !== 'string')
92
- return val;
93
- const v = val.toLowerCase();
94
- if (['simple', 'easy', 'basic'].includes(v))
95
- return 'low';
96
- if (['standard', 'normal', 'regular'].includes(v))
97
- return 'medium';
98
- if (['critical', 'expert', 'very high'].includes(v))
99
- return 'high';
100
- // If it's a string but not one of the enum values, default to medium
101
- if (!['low', 'medium', 'high'].includes(v))
102
- return 'medium';
103
- return v;
104
- }, z.enum(['low', 'medium', 'high']).optional()).describe("Task complexity level. 'low': simple tasks, less strict. 'medium': standard. 'high': critical, requires critique & double verification."),
90
+ complexity: z.string().optional()
91
+ .describe("Task complexity level. 'low': simple tasks, less strict. 'medium': standard. 'high': critical, requires critique & double verification."),
105
92
  // Legacy Fields (backwards compatible)
106
93
  isRevision: z.boolean().optional().describe("Whether this revises previous thinking"),
107
94
  revisesThought: z.number().int().min(1).optional().describe("Which thought number is being reconsidered"),
@@ -114,14 +101,30 @@ If you have tried to fix the same problem 3 times and failed:
114
101
  }, async (args) => {
115
102
  try {
116
103
  const thoughtNumber = args.thoughtNumber ?? (thinkingServer.getHistoryLength() + 1);
104
+ // Normalize complexity manually since we removed z.preprocess to avoid schema validation errors
105
+ let complexity = 'medium';
106
+ if (args.complexity) {
107
+ const v = args.complexity.toLowerCase();
108
+ if (['low', 'simple', 'easy', 'basic'].includes(v))
109
+ complexity = 'low';
110
+ else if (['high', 'critical', 'expert', 'very high'].includes(v))
111
+ complexity = 'high';
112
+ else
113
+ complexity = 'medium';
114
+ }
117
115
  // Smart defaults for totalThoughts based on complexity
118
116
  let defaultAdd = 5;
119
- if (args.complexity === 'low')
117
+ if (complexity === 'low')
120
118
  defaultAdd = 3;
121
- else if (args.complexity === 'high')
119
+ else if (complexity === 'high')
122
120
  defaultAdd = 8;
123
121
  const totalThoughts = args.totalThoughts ?? (thoughtNumber + defaultAdd);
124
- const input = { ...args, thoughtNumber, totalThoughts };
122
+ const input = {
123
+ ...args,
124
+ thoughtNumber,
125
+ totalThoughts,
126
+ complexity: complexity
127
+ };
125
128
  const result = await thinkingServer.processThought(input);
126
129
  return {
127
130
  content: result.content,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gotza02/sequential-thinking",
3
- "version": "2026.3.8",
3
+ "version": "2026.3.10",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },