@gotza02/sequential-thinking 2026.3.10 → 2026.3.11

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.
@@ -0,0 +1,9 @@
1
+ import { ThoughtData } from '../lib.js';
2
+ export declare class ContextManager {
3
+ private summaryCache;
4
+ constructor();
5
+ getOptimizedContext(history: ThoughtData[], currentBlockId: string | null): Promise<string>;
6
+ private compressOldBlocks;
7
+ private groupByBlock;
8
+ private generateSummary;
9
+ }
@@ -0,0 +1,62 @@
1
+ export class ContextManager {
2
+ summaryCache = new Map();
3
+ constructor() { }
4
+ async getOptimizedContext(history, currentBlockId) {
5
+ // If no current block, treat everything as old or just show all?
6
+ // If null, we might be in setup mode. Let's assume empty current block.
7
+ const safeCurrentBlockId = currentBlockId || '';
8
+ const oldBlocks = history.filter(t => t.blockId !== safeCurrentBlockId);
9
+ const activeBlock = history.filter(t => t.blockId === safeCurrentBlockId);
10
+ const summaries = await this.compressOldBlocks(oldBlocks);
11
+ // Format active block detailed
12
+ const activeContext = activeBlock.map(t => `[${t.thoughtType?.toUpperCase() || 'INFO'}] #${t.thoughtNumber}: ${t.thought}`).join('\n');
13
+ return `
14
+ === PROJECT HISTORY (SUMMARIZED) ===
15
+ ${summaries}
16
+
17
+ === CURRENT FOCUS (DETAILED: ${safeCurrentBlockId || 'GLOBAL'}) ===
18
+ ${activeContext}
19
+ `;
20
+ }
21
+ async compressOldBlocks(logs) {
22
+ const groups = this.groupByBlock(logs);
23
+ let result = '';
24
+ for (const [blockId, thoughts] of groups) {
25
+ // Skip blocks with undefined or empty blockId if they sneak in
26
+ if (!blockId)
27
+ continue;
28
+ const cached = this.summaryCache.get(blockId);
29
+ if (cached && cached.count === thoughts.length) {
30
+ result += `[Block: ${blockId}] Summary: ${cached.summary}\n`;
31
+ }
32
+ else {
33
+ if (thoughts.length > 2) {
34
+ const summary = await this.generateSummary(thoughts);
35
+ this.summaryCache.set(blockId, { summary, count: thoughts.length });
36
+ result += `[Block: ${blockId}] Summary: ${summary}\n`;
37
+ }
38
+ else {
39
+ result += `[Block: ${blockId}] ${thoughts.map(t => t.thought).join(' -> ')}\n`;
40
+ }
41
+ }
42
+ }
43
+ return result;
44
+ }
45
+ groupByBlock(logs) {
46
+ const map = new Map();
47
+ logs.forEach(log => {
48
+ const bid = log.blockId || 'default';
49
+ const items = map.get(bid) || [];
50
+ items.push(log);
51
+ map.set(bid, items);
52
+ });
53
+ return map;
54
+ }
55
+ async generateSummary(thoughts) {
56
+ // Mock implementation
57
+ const decisions = thoughts.filter(t => t.thoughtType === 'planning' || t.thoughtType === 'selection').length;
58
+ const executions = thoughts.filter(t => t.thoughtType === 'execution').length;
59
+ const topic = thoughts[0]?.thought.substring(0, 30) || 'Unknown';
60
+ return `Topic: "${topic}...". Processed ${thoughts.length} steps (${decisions} plans, ${executions} actions). Outcome: Handed off or completed.`;
61
+ }
62
+ }
package/dist/lib.d.ts CHANGED
@@ -38,6 +38,7 @@ export declare class SequentialThinkingServer {
38
38
  private saveMutex;
39
39
  private consecutiveStallCount;
40
40
  private confidenceScore;
41
+ private contextManager;
41
42
  constructor(storagePath?: string, delayMs?: number);
42
43
  private loadHistory;
43
44
  private attemptRecovery;
package/dist/lib.js CHANGED
@@ -3,6 +3,7 @@ import * as fs from 'fs/promises';
3
3
  import { existsSync, readFileSync } from 'fs';
4
4
  import * as path from 'path';
5
5
  import { AsyncMutex } from './utils.js';
6
+ import { ContextManager } from './core/ContextManager.js';
6
7
  export class SequentialThinkingServer {
7
8
  thoughtHistory = [];
8
9
  blocks = [];
@@ -15,6 +16,7 @@ export class SequentialThinkingServer {
15
16
  saveMutex = new AsyncMutex();
16
17
  consecutiveStallCount = 0; // Track consecutive stalls/loops
17
18
  confidenceScore = 100; // Meta-Cognition Score (0-100)
19
+ contextManager = new ContextManager();
18
20
  constructor(storagePath = 'thoughts_history.json', delayMs = 0) {
19
21
  this.disableThoughtLogging = (process.env.DISABLE_THOUGHT_LOGGING || "").toLowerCase() === "true";
20
22
  this.storagePath = path.resolve(storagePath);
@@ -439,9 +441,9 @@ ${typeof wrappedThought === 'string' && wrappedThought.startsWith('│') ? wrapp
439
441
  let feedbackExtension = "";
440
442
  // --- šŸ”„ FEATURE 0: Smart Branching Reward (Reset Confidence on Pivot) ---
441
443
  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.`;
444
+ if (this.confidenceScore < 75) {
445
+ this.confidenceScore = 75;
446
+ feedbackExtension += `\n🌿 BRANCH DETECTED: Confidence restored to 75. Good decision to pivot.`;
445
447
  }
446
448
  }
447
449
  // --- 🧠 FEATURE 1: Semantic Thought Recall ---
@@ -681,6 +683,7 @@ ${typeof wrappedThought === 'string' && wrappedThought.startsWith('│') ? wrapp
681
683
  // D. Generate Contextual Output
682
684
  const currentBlock = this.blocks.find(b => b.id === input.blockId);
683
685
  const mermaid = this.generateMermaid();
686
+ const optimizedContext = await this.contextManager.getOptimizedContext(this.thoughtHistory, input.blockId || null);
684
687
  if (feedbackExtension)
685
688
  warnings.push(feedbackExtension);
686
689
  return {
@@ -694,6 +697,7 @@ ${typeof wrappedThought === 'string' && wrappedThought.startsWith('│') ? wrapp
694
697
  blockContext: currentBlock
695
698
  ? `Block '${currentBlock.topic.substring(0, 30)}' has ${currentBlock.thoughts.length} thoughts.`
696
699
  : 'No active block',
700
+ optimizedContext,
697
701
  branches: Object.keys(this.branches),
698
702
  thoughtHistoryLength: this.thoughtHistory.length,
699
703
  feedback: warnings.length > 0 ? warnings : "Flow Healthy āœ…",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gotza02/sequential-thinking",
3
- "version": "2026.3.10",
3
+ "version": "2026.3.11",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },