@gotza02/seq-thinking 1.1.0

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 (106) hide show
  1. package/README.md +149 -0
  2. package/SYSTEM_INSTRUCTIONS.md +50 -0
  3. package/agents_test.log +15 -0
  4. package/dist/__tests__/agents.test.d.ts +2 -0
  5. package/dist/__tests__/agents.test.d.ts.map +1 -0
  6. package/dist/__tests__/agents.test.js +673 -0
  7. package/dist/__tests__/agents.test.js.map +1 -0
  8. package/dist/__tests__/mcp-server.test.d.ts +2 -0
  9. package/dist/__tests__/mcp-server.test.d.ts.map +1 -0
  10. package/dist/__tests__/mcp-server.test.js +315 -0
  11. package/dist/__tests__/mcp-server.test.js.map +1 -0
  12. package/dist/__tests__/sequential-thinking.test.d.ts +2 -0
  13. package/dist/__tests__/sequential-thinking.test.d.ts.map +1 -0
  14. package/dist/__tests__/sequential-thinking.test.js +545 -0
  15. package/dist/__tests__/sequential-thinking.test.js.map +1 -0
  16. package/dist/__tests__/swarm-coordinator.test.d.ts +2 -0
  17. package/dist/__tests__/swarm-coordinator.test.d.ts.map +1 -0
  18. package/dist/__tests__/swarm-coordinator.test.js +606 -0
  19. package/dist/__tests__/swarm-coordinator.test.js.map +1 -0
  20. package/dist/__tests__/types.test.d.ts +2 -0
  21. package/dist/__tests__/types.test.d.ts.map +1 -0
  22. package/dist/__tests__/types.test.js +741 -0
  23. package/dist/__tests__/types.test.js.map +1 -0
  24. package/dist/__tests__/utils.test.d.ts +2 -0
  25. package/dist/__tests__/utils.test.d.ts.map +1 -0
  26. package/dist/__tests__/utils.test.js +264 -0
  27. package/dist/__tests__/utils.test.js.map +1 -0
  28. package/dist/agents/base-agent.d.ts +126 -0
  29. package/dist/agents/base-agent.d.ts.map +1 -0
  30. package/dist/agents/base-agent.js +214 -0
  31. package/dist/agents/base-agent.js.map +1 -0
  32. package/dist/agents/critic-agent.d.ts +134 -0
  33. package/dist/agents/critic-agent.d.ts.map +1 -0
  34. package/dist/agents/critic-agent.js +484 -0
  35. package/dist/agents/critic-agent.js.map +1 -0
  36. package/dist/agents/index.d.ts +11 -0
  37. package/dist/agents/index.d.ts.map +1 -0
  38. package/dist/agents/index.js +11 -0
  39. package/dist/agents/index.js.map +1 -0
  40. package/dist/agents/meta-reasoning-agent.d.ts +143 -0
  41. package/dist/agents/meta-reasoning-agent.d.ts.map +1 -0
  42. package/dist/agents/meta-reasoning-agent.js +532 -0
  43. package/dist/agents/meta-reasoning-agent.js.map +1 -0
  44. package/dist/agents/reasoner-agent.d.ts +75 -0
  45. package/dist/agents/reasoner-agent.d.ts.map +1 -0
  46. package/dist/agents/reasoner-agent.js +226 -0
  47. package/dist/agents/reasoner-agent.js.map +1 -0
  48. package/dist/agents/synthesizer-agent.d.ts +174 -0
  49. package/dist/agents/synthesizer-agent.d.ts.map +1 -0
  50. package/dist/agents/synthesizer-agent.js +583 -0
  51. package/dist/agents/synthesizer-agent.js.map +1 -0
  52. package/dist/index.d.ts +21 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +27 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/mcp-server.d.ts +823 -0
  57. package/dist/mcp-server.d.ts.map +1 -0
  58. package/dist/mcp-server.js +377 -0
  59. package/dist/mcp-server.js.map +1 -0
  60. package/dist/sequential-thinking.d.ts +91 -0
  61. package/dist/sequential-thinking.d.ts.map +1 -0
  62. package/dist/sequential-thinking.js +540 -0
  63. package/dist/sequential-thinking.js.map +1 -0
  64. package/dist/swarm-coordinator.d.ts +188 -0
  65. package/dist/swarm-coordinator.d.ts.map +1 -0
  66. package/dist/swarm-coordinator.js +627 -0
  67. package/dist/swarm-coordinator.js.map +1 -0
  68. package/dist/types/index.d.ts +806 -0
  69. package/dist/types/index.d.ts.map +1 -0
  70. package/dist/types/index.js +279 -0
  71. package/dist/types/index.js.map +1 -0
  72. package/dist/utils/index.d.ts +421 -0
  73. package/dist/utils/index.d.ts.map +1 -0
  74. package/dist/utils/index.js +864 -0
  75. package/dist/utils/index.js.map +1 -0
  76. package/dist/utils/llm-adapter.d.ts +23 -0
  77. package/dist/utils/llm-adapter.d.ts.map +1 -0
  78. package/dist/utils/llm-adapter.js +68 -0
  79. package/dist/utils/llm-adapter.js.map +1 -0
  80. package/dist/utils/persistence.d.ts +33 -0
  81. package/dist/utils/persistence.d.ts.map +1 -0
  82. package/dist/utils/persistence.js +108 -0
  83. package/dist/utils/persistence.js.map +1 -0
  84. package/package.json +41 -0
  85. package/src/__tests__/agents.test.ts +858 -0
  86. package/src/__tests__/mcp-server.test.ts +380 -0
  87. package/src/__tests__/sequential-thinking.test.ts +687 -0
  88. package/src/__tests__/swarm-coordinator.test.ts +903 -0
  89. package/src/__tests__/types.test.ts +839 -0
  90. package/src/__tests__/utils.test.ts +322 -0
  91. package/src/agents/base-agent.ts +285 -0
  92. package/src/agents/critic-agent.ts +582 -0
  93. package/src/agents/index.ts +11 -0
  94. package/src/agents/meta-reasoning-agent.ts +672 -0
  95. package/src/agents/reasoner-agent.ts +312 -0
  96. package/src/agents/synthesizer-agent.ts +758 -0
  97. package/src/index.ts +118 -0
  98. package/src/mcp-server.ts +387 -0
  99. package/src/sequential-thinking.ts +560 -0
  100. package/src/swarm-coordinator.ts +744 -0
  101. package/src/types/index.ts +915 -0
  102. package/src/utils/index.ts +1004 -0
  103. package/src/utils/llm-adapter.ts +76 -0
  104. package/src/utils/persistence.ts +108 -0
  105. package/test_output.log +0 -0
  106. package/tsconfig.json +21 -0
package/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # MCP Sequential Thinking with Swarm Coordination
2
+
3
+ [![Version](https://img.shields.io/badge/version-1.1.0-blue.svg)](https://github.com/yourusername/mcp-sequential-thinking)
4
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
5
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen.svg)](https://nodejs.org/)
6
+
7
+ Advanced Sequential Thinking MCP Tool with Swarm Agent Coordination - A superior alternative to Claude's sequential thinking capabilities, integrated with real LLM power via your favorite CLI tools.
8
+
9
+ ## Overview
10
+
11
+ This system provides advanced sequential thinking capabilities with:
12
+
13
+ - **Real LLM Integration**: Connects directly to Gemini, Claude (Claude Code), Kimi, and OpenCode via CLI.
14
+ - **Self-Correction Loops**: Automatically detect and fix reasoning errors.
15
+ - **Parallel Hypothesis Generation**: Explore multiple reasoning paths simultaneously.
16
+ - **Meta-Reasoning**: Reflect on and improve the thinking process.
17
+ - **Adaptive Granularity**: Adjust detail level based on problem complexity.
18
+ - **Persistence Layer**: All thinking sessions and agent states are saved to disk.
19
+ - **Swarm Agent Coordination**: Multiple specialized agents working together with retry logic.
20
+
21
+ ## AI System Instructions
22
+
23
+ This project includes a [SYSTEM_INSTRUCTIONS.md](./SYSTEM_INSTRUCTIONS.md) file specifically designed to guide AI models on how to use these tools effectively. It covers initialization, branching, and swarm delegation strategies.
24
+
25
+ ## Architecture
26
+
27
+ ```
28
+ ┌─────────────────────────────────────────────────────────────────┐
29
+ │ MCP TOOL INTERFACE │
30
+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
31
+ │ │ Sequential │ │ Swarm │ │ Tool Registry │ │
32
+ │ │ Thinking │ │ Coordination│ │ │ │
33
+ │ └──────┬──────┘ └──────┬──────┘ └─────────────────────────┘ │
34
+ └─────────┼────────────────┼──────────────────────────────────────┘
35
+ │ │
36
+ ┌─────────┼────────────────┼──────────────────────────────────────┐
37
+ │ │ ORCHESTRATION ENGINE │
38
+ │ ┌──────┴──────┐ ┌──────────────┐ ┌──────────────────────┐ │
39
+ │ │State Manager│ │ Flow Control │ │ Scheduler │ │
40
+ │ │(Persistence)│ │ (Retry Logic)│ │ │ │
41
+ │ └──────┴──────┘ └──────────────┘ └──────────────────────┘ │
42
+ └─────────┬───────────────────────────────────────────────────────┘
43
+
44
+ ┌─────────┴──────────────────────────────────────────────────────┐
45
+ │ │ SWARM AGENT COORDINATOR │
46
+ │ ┌──────┴──────┐ ┌─────────────┐ ┌──────────────────────┐ │
47
+ │ │ Reasoner │ │ Critic │ │ Synthesizer │ │
48
+ │ │ Agents │ │ Agents │ │ Agents │ │
49
+ │ └──────┬──────┘ └──────┬──────┘ └───────────┬──────────┘ │
50
+ └─────────┼────────────────┼─────────────────────┼────────────────┘
51
+ │ │ │
52
+ ┌─────────┴────────────────┴─────────────────────┴────────────────┐
53
+ │ LLM ADAPTER (CLI BRIDGE) │
54
+ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
55
+ │ │ Gemini │ │ Claude │ │ Kimi │ │ OpenCode │ │
56
+ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
57
+ └─────────────────────────────────────────────────────────────────┘
58
+ ```
59
+
60
+ ## LLM Providers (CLI Integration)
61
+
62
+ The system is designed to use LLMs that you have already logged into via your command line. This simplifies authentication and leverages your existing CLI tools.
63
+
64
+ Supported Providers:
65
+ - **gemini**: Uses `gemini ask "..."`
66
+ - **claude**: Uses `claude "..." --non-interactive` (Compatible with Claude Code)
67
+ - **kimi**: Uses `kimi chat "..."`
68
+ - **opencode**: Uses `opencode ask "..."`
69
+
70
+ ## Installation
71
+
72
+ ```bash
73
+ # Clone the repository
74
+ git clone https://github.com/yourusername/mcp-sequential-thinking.git
75
+ cd mcp-sequential-thinking
76
+
77
+ # Install dependencies
78
+ npm install
79
+
80
+ # Build the project
81
+ npm run build
82
+ ```
83
+
84
+ ## Configuration (MCP JSON)
85
+
86
+ Add this to your MCP settings file (e.g., `claude_desktop_config.json`, `gemini-cli.json`, or Kimi's `mcp.json`):
87
+
88
+ ```json
89
+ {
90
+ "mcpServers": {
91
+ "advanced-thinking": {
92
+ "command": "node",
93
+ "args": ["/absolute/path/to/dist/mcp-server.js"],
94
+ "env": {
95
+ "provider": "gemini",
96
+ "MOCK_LLM": "false"
97
+ }
98
+ }
99
+ }
100
+ }
101
+ ```
102
+
103
+ ### Environment Variables
104
+
105
+ | Variable | Description | Default |
106
+ |----------|-------------|---------|
107
+ | `provider` | The LLM provider to use (`gemini`, `claude`, `kimi`, `opencode`) | `gemini` |
108
+ | `MOCK_LLM` | If `true`, returns mock data instead of calling the CLI (useful for testing) | `false` |
109
+
110
+ ## Persistence
111
+
112
+ Thinking sessions are automatically persisted to the `./data` directory.
113
+ - **Sessions**: Stored in `./data/sessions/`
114
+ - **Agents**: Stored in `./data/agents/`
115
+
116
+ This ensures that your reasoning state is preserved even if the MCP server restarts.
117
+
118
+ ## Enhanced Swarm Logic
119
+
120
+ - **Automated Retries**: Tasks assigned to agents will automatically retry up to 3 times with exponential backoff on failure.
121
+ - **Intelligent Context**: When reaching consensus, agents receive current swarm statistics and history of previous votes to make more informed decisions.
122
+ - **Async Workflow**: All operations are non-blocking, ensuring the MCP server remains responsive during long reasoning tasks.
123
+
124
+ ## API Documentation
125
+
126
+ *(Standard Sequential Thinking and Swarm Coordination operations are supported as documented in the internal tool definitions)*
127
+
128
+ ## Testing
129
+
130
+ ```bash
131
+ # Run tests with mock LLM responses
132
+ export MOCK_LLM=true
133
+ npm test
134
+ ```
135
+
136
+ ## License
137
+
138
+ MIT License - see [LICENSE](LICENSE) file for details.
139
+
140
+ ## Changelog
141
+
142
+ ### v1.1.0 (2026-02-03)
143
+ - Added CLI-based LLM Adapters (Gemini, Claude, Kimi, OpenCode).
144
+ - Implemented Disk Persistence for sessions and agents.
145
+ - Added Task Retry logic in Swarm Coordinator.
146
+ - Updated all tests to support asynchronous operations.
147
+
148
+ ### v1.0.0 (2025-02-03)
149
+ - Initial release with core swarm and sequential thinking logic.
@@ -0,0 +1,50 @@
1
+ # AI System Instructions for MCP Sequential Thinking
2
+
3
+ This document provides instructions for AI models (like Gemini or Claude) on how to effectively utilize this MCP server to solve complex problems.
4
+
5
+ ## 1. When to Use These Tools
6
+
7
+ You should invoke the `advanced_sequential_thinking` tool when:
8
+ - The user's request is complex, ambiguous, or requires multi-step planning.
9
+ - You need to explore multiple hypotheses or alternative solutions.
10
+ - You need to perform self-correction or verify your own reasoning.
11
+ - The task requires a "System 2" thinking approach (deliberative and analytical).
12
+
13
+ ## 2. Decision Logic for Tools
14
+
15
+ | tool | Use Case |
16
+ |------|----------|
17
+ | `advanced_sequential_thinking` | Core reasoning, branching, and meta-reflection. |
18
+ | `swarm_agent_coordination` | Delegating specific sub-tasks to specialized agents (e.g., Fact-checking, Code Critique). |
19
+
20
+ ## 3. Recommended Workflow
21
+
22
+ ### Phase A: Initialization
23
+ 1. **Initialize**: Create a session with a clear `topic`.
24
+ 2. **Adjust Granularity**: Check if the topic is complex enough to require high detail.
25
+
26
+ ### Phase B: Iterative Reasoning
27
+ 1. **Add Thoughts**: Progress step-by-step. Use `thoughtType` (analysis, hypothesis, etc.) correctly.
28
+ 2. **Branching**: If you reach a decision point with multiple viable paths, use `branch_thought` to explore them in parallel.
29
+ 3. **Self-Correction**: Periodically call `self_correct` or `add_meta_thought` to reflect on your progress.
30
+
31
+ ### Phase C: Swarm Delegation (Optional)
32
+ 1. **Register Agents**: If you need specialized help, register a `critic` or `reasoner`.
33
+ 2. **Delegate**: Use `delegate_to_swarm` to let another "brain" analyze a specific thought.
34
+ 3. **Consensus**: Use `reach_consensus` if multiple agents have different outputs.
35
+
36
+ ### Phase D: Conclusion
37
+ 1. **Merge**: Combine successful branches using `merge_branches`.
38
+ 2. **Complete**: Finalize the session and present the consolidated result to the user.
39
+
40
+ ## 4. Best Practices for the AI
41
+
42
+ - **Maintain Context**: Keep track of the `sessionId`. Use it for all related thoughts.
43
+ - **Calibrate Confidence**: Be honest about confidence levels. If confidence drops below 0.5, explicitly use a `self_correction` thought.
44
+ - **Label Everything**: Use `tags` and `thoughtType` diligently. This helps the system (and the user) understand your mental map.
45
+ - **Meta-Reflection**: Don't just think; think about *how* you are thinking. If you get stuck, use `add_meta_thought` to analyze the pattern.
46
+
47
+ ## 5. System Prompt Template
48
+
49
+ When using this MCP server, you may internalize this instruction:
50
+ > "I will use the Sequential Thinking MCP to map out my reasoning process. I will treat complex problems as a graph of thoughts, allowing myself to branch, backtrack, and consult specialized swarm agents when needed to ensure the highest quality output."
@@ -0,0 +1,15 @@
1
+ ✖ dist/__tests__/agents.test.js (9856.244616ms)
2
+ ℹ tests 1
3
+ ℹ suites 0
4
+ ℹ pass 0
5
+ ℹ fail 0
6
+ ℹ cancelled 1
7
+ ℹ skipped 0
8
+ ℹ todo 0
9
+ ℹ duration_ms 9872.053462
10
+
11
+ ✖ failing tests:
12
+
13
+ test at dist/__tests__/agents.test.js:1:1
14
+ ✖ dist/__tests__/agents.test.js (9856.244616ms)
15
+ 'Promise resolution is still pending but the event loop has already resolved'
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=agents.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agents.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/agents.test.ts"],"names":[],"mappings":""}