@gotza02/sequential-thinking 2026.2.7 → 2026.2.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/README.md +33 -23
- package/dist/codestore.js +57 -0
- package/dist/index.js +4 -0
- package/dist/notes.js +14 -4
- package/dist/system_test.js +51 -0
- package/dist/tools/codestore.js +51 -0
- package/dist/tools/notes.js +9 -6
- package/dist/tools/thinking.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
# Sequential Thinking MCP Server (Extended Edition) 🧠✨
|
|
2
2
|
|
|
3
|
-
**MCP Server ที่ยกระดับ AI ให้เป็นวิศวกรซอฟต์แวร์อัจฉริยะ ด้วยระบบ Deepest Thinking
|
|
3
|
+
**MCP Server ที่ยกระดับ AI ให้เป็นวิศวกรซอฟต์แวร์อัจฉริยะ ด้วยระบบ Deepest Thinking, การวิเคราะห์ Codebase เชิงลึก และฐานข้อมูลความรู้ (Code Database)**
|
|
4
4
|
|
|
5
|
-
โปรเจกต์นี้คือส่วนขยายขั้นสูงของ Sequential Thinking ที่รวมเอาความสามารถในการวางแผนที่เป็นระบบ, การหาข้อมูลทั่วโลก (Web Search), การสร้างแผนผังความสัมพันธ์ของโค้ด (Dependency Graph)
|
|
5
|
+
โปรเจกต์นี้คือส่วนขยายขั้นสูงของ Sequential Thinking ที่รวมเอาความสามารถในการวางแผนที่เป็นระบบ, การหาข้อมูลทั่วโลก (Web Search), การสร้างแผนผังความสัมพันธ์ของโค้ด (Dependency Graph), การจัดการหน่วยความจำระยะยาว และ **ฐานข้อมูลความรู้โค้ด (Code Database)** เข้าด้วยกัน เพื่อให้ AI สามารถทำงานที่ซับซ้อนได้อย่างอิสระและแม่นยำ
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## 🌟 จุดเด่นของเวอร์ชัน Extended
|
|
10
10
|
|
|
11
11
|
1. **Deepest Thinking Protocol**: บังคับให้ AI วิเคราะห์ปัญหาแบบเป็นลำดับขั้นตอน (Step-by-step) พร้อมการแตกกิ่งความคิด (Branching) และการทบทวนตัวเอง (Reflexion) เพื่อหาทางเลือกที่ดีที่สุด
|
|
12
|
-
2. **Codebase Intelligence**: ระบบ `ProjectKnowledgeGraph` ที่ใช้ TypeScript Compiler API
|
|
13
|
-
3. **
|
|
14
|
-
4. **
|
|
12
|
+
2. **Codebase Intelligence**: ระบบ `ProjectKnowledgeGraph` ที่ใช้ TypeScript Compiler API และ Regex (สำหรับ Python/Go) ในการสแกนความสัมพันธ์ระหว่างไฟล์และ Exported Symbols
|
|
13
|
+
3. **Code Database (CodeStore)**: ระบบจัดเก็บ Snippets และ Architectural Patterns ลงในไฟล์ JSON ถาวร ช่วยให้ AI "จดจำ" วิธีแก้ปัญหาและนำกลับมาใช้ใหม่ได้
|
|
14
|
+
4. **Deep Coding Workflow**: เครื่องมือใหม่สำหรับการแก้ไขโค้ดที่ต้องผ่านการวิเคราะห์บริบท (Context Document) และการวางแผนที่ผ่านการตรวจสอบเหตุผลแล้วเท่านั้น
|
|
15
|
+
5. **Smart Notes**: ระบบบันทึกที่มี **Priority Level** และ **Expiration Date** ช่วยจัดลำดับความสำคัญของงานได้ดียิ่งขึ้น
|
|
15
16
|
|
|
16
17
|
---
|
|
17
18
|
|
|
@@ -25,7 +26,9 @@
|
|
|
25
26
|
| `GOOGLE_SEARCH_CX` | Google Custom Search Engine ID (CX) | ❌ (Optional) |
|
|
26
27
|
| `THOUGHTS_STORAGE_PATH` | ไฟล์เก็บประวัติความคิดเพื่อใช้ต่อเนื่อง | `thoughts_history.json` |
|
|
27
28
|
| `NOTES_STORAGE_PATH` | ไฟล์เก็บความจำระยะยาว (กฎโปรเจกต์, ความชอบ) | `project_notes.json` |
|
|
29
|
+
| `CODE_DB_PATH` | ไฟล์เก็บฐานข้อมูลความรู้โค้ด (Snippets/Patterns) | `code_database.json` |
|
|
28
30
|
| `THOUGHT_DELAY_MS` | เวลาหน่วงระหว่างคิด (เพื่อความสมจริงและการจัดการ Rate Limit) | `0` |
|
|
31
|
+
| `LOG_LEVEL` | ระดับการแสดงผล Log (debug, info, warn, error) | `info` |
|
|
29
32
|
|
|
30
33
|
---
|
|
31
34
|
|
|
@@ -39,31 +42,24 @@
|
|
|
39
42
|
### 💻 2. Deep Coding & Codebase Context
|
|
40
43
|
* **`deep_code_analyze`**: 🌟 **(ใหม่)** สร้าง Codebase Context Document รวบรวมเนื้อหาไฟล์, Symbols และความสัมพันธ์ (Import/Export) เพื่อให้ AI "เรียนรู้" ก่อนแก้โค้ด
|
|
41
44
|
* **`deep_code_edit`**: 🌟 **(ใหม่)** แก้ไขโค้ดแบบ Surgical Edit โดยต้องระบุ `reasoning` (เหตุผลเชิงลึก) ที่ผ่านการคิดวิเคราะห์มาแล้ว
|
|
42
|
-
* **`build_project_graph`**: สแกนโปรเจกต์เพื่อสร้างแผนผังความสัมพันธ์ทั้งหมด
|
|
45
|
+
* **`build_project_graph`**: สแกนโปรเจกต์เพื่อสร้างแผนผังความสัมพันธ์ทั้งหมด (รองรับ TS, JS, PY, GO)
|
|
43
46
|
* **`get_file_relationships`**: ตรวจสอบว่าไฟล์เป้าหมายกระทบกับส่วนไหนของระบบบ้าง
|
|
44
47
|
* **`search_code`**: ค้นหา Code Pattern ทั้งโปรเจกต์แบบชาญฉลาด
|
|
45
48
|
|
|
46
|
-
###
|
|
49
|
+
### 📚 3. Knowledge & Memory (CodeStore)
|
|
50
|
+
* **`add_code_snippet`**: 🌟 **(ใหม่)** บันทึก Snippet โค้ดที่ใช้งานบ่อยลงฐานข้อมูล
|
|
51
|
+
* **`search_code_db`**: 🌟 **(ใหม่)** ค้นหาความรู้เดิมจากฐานข้อมูล (ช่วยลดเวลาในการเริ่มงานใหม่)
|
|
52
|
+
* **`learn_architecture_pattern`**: 🌟 **(ใหม่)** บันทึกรูปแบบโครงสร้างของระบบ
|
|
53
|
+
* **`manage_notes`**: (ปรับปรุงใหม่!) จัดการบันทึกพร้อมระบุ **Priority** และ **Expiration**
|
|
54
|
+
|
|
55
|
+
### 🌐 4. External Research
|
|
47
56
|
* **`web_search`**: ค้นหาข้อมูลล่าสุดจากโลกภายนอก (Brave/Exa/Google)
|
|
48
57
|
* **`read_webpage`**: อ่านเนื้อหาเว็บแปลงเป็น Markdown ที่สะอาดและเข้าใจง่าย
|
|
49
58
|
* **`fetch`**: ดึงข้อมูล Raw จาก API ต่างๆ
|
|
50
59
|
|
|
51
|
-
### 📁
|
|
60
|
+
### 📁 5. System & Persistence
|
|
52
61
|
* **`read_file` / `write_file` / `edit_file`**: จัดการไฟล์ในระบบ
|
|
53
|
-
* **`shell_execute`**: รันคำสั่ง Terminal (เช่น
|
|
54
|
-
* **`manage_notes`**: จัดการหน่วยความจำระยะยาวข้ามเซสชัน
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
## 🔄 The "Deep Coding" Workflow (ขั้นตอนการทำงานที่แนะนำ)
|
|
59
|
-
|
|
60
|
-
เพื่อให้ AI ทำงานได้อย่างเทพที่สุด แนะนำให้ใช้ลำดับการทำงานดังนี้:
|
|
61
|
-
|
|
62
|
-
1. **Map the Codebase**: รัน `build_project_graph` เพื่อให้ AI เข้าใจโครงสร้างโปรเจกต์ทั้งหมด
|
|
63
|
-
2. **Deep Analysis**: ใช้ `deep_code_analyze` กับไฟล์ที่เกี่ยวข้อง เพื่อสร้างบริบทและความเข้าใจ symbols ที่ใช้งาน
|
|
64
|
-
3. **Strategic Planning**: ใช้ `sequentialthinking` เพื่อวางแผนแบบ Deepest Thinking (แตกกิ่งความคิด, ทดสอบสมมติฐาน)
|
|
65
|
-
4. **Precision Edit**: ลงมือแก้ไขด้วย `deep_code_edit` หรือ `edit_file` พร้อมระบุเหตุผลที่วิเคราะห์มาแล้ว
|
|
66
|
-
5. **Verify**: ใช้ `shell_execute` รันคำสั่ง Test หรือ Lint เพื่อตรวจสอบความถูกต้อง
|
|
62
|
+
* **`shell_execute`**: รันคำสั่ง Terminal (มีระบบป้องกันคำสั่งอันตราย เช่น `rm -rf /`)
|
|
67
63
|
|
|
68
64
|
---
|
|
69
65
|
|
|
@@ -93,7 +89,7 @@ git clone https://github.com/gotza02/sequential-thinking.git && cd sequential-th
|
|
|
93
89
|
```bash
|
|
94
90
|
npm run build
|
|
95
91
|
```
|
|
96
|
-
4. **Configuration**:
|
|
92
|
+
4. **Configuration**: ตั้งค่า AI Client ตามตัวอย่างด้านล่าง
|
|
97
93
|
|
|
98
94
|
---
|
|
99
95
|
|
|
@@ -117,6 +113,7 @@ git clone https://github.com/gotza02/sequential-thinking.git && cd sequential-th
|
|
|
117
113
|
"GOOGLE_SEARCH_CX": "YOUR_GOOGLE_SEARCH_ENGINE_ID",
|
|
118
114
|
"THOUGHTS_STORAGE_PATH": "thoughts_history.json",
|
|
119
115
|
"NOTES_STORAGE_PATH": "project_notes.json",
|
|
116
|
+
"CODE_DB_PATH": "code_database.json",
|
|
120
117
|
"THOUGHT_DELAY_MS": "1000",
|
|
121
118
|
"DISABLE_THOUGHT_LOGGING": "false"
|
|
122
119
|
}
|
|
@@ -139,6 +136,7 @@ git clone https://github.com/gotza02/sequential-thinking.git && cd sequential-th
|
|
|
139
136
|
"EXA_API_KEY": "YOUR_EXA_KEY",
|
|
140
137
|
"GOOGLE_SEARCH_API_KEY": "YOUR_GOOGLE_API_KEY",
|
|
141
138
|
"GOOGLE_SEARCH_CX": "YOUR_GOOGLE_SEARCH_ENGINE_ID",
|
|
139
|
+
"CODE_DB_PATH": "code_database.json",
|
|
142
140
|
"THOUGHT_DELAY_MS": "1000"
|
|
143
141
|
}
|
|
144
142
|
}
|
|
@@ -150,6 +148,16 @@ git clone https://github.com/gotza02/sequential-thinking.git && cd sequential-th
|
|
|
150
148
|
|
|
151
149
|
---
|
|
152
150
|
|
|
151
|
+
## 🛠️ ติดตั้งคำสั่งระบบ (System Instruction Setup)
|
|
152
|
+
|
|
153
|
+
คุณสามารถติดตั้งคำสั่งระบบ **Ultimate Deep Engineer** ให้กับ Gemini และ Claude ได้โดยอัตโนมัติด้วย Script นี้:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
chmod +x install-ultimate-engineer.sh && ./install-ultimate-engineer.sh
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
153
161
|
## 🤖 Recommended System Instruction (The Ultimate Deep Engineer)
|
|
154
162
|
|
|
155
163
|
ให้ Copy ข้อความด้านล่างนี้ไปใส่ใน **System Prompt** ของ AI Agent เพื่อประสิทธิภาพสูงสุด:
|
|
@@ -164,6 +172,7 @@ You are a Senior AI Software Engineer equipped with the Sequential Thinking MCP
|
|
|
164
172
|
- **Atomic Analysis:** Use `thoughtType: 'analysis'` to break every request into atomic requirements and constraints before proposing solutions.
|
|
165
173
|
- **Mandatory Reflexion:** Use `thoughtType: 'reflexion'` frequently to critique your own logic, identify potential edge cases, and challenge your assumptions.
|
|
166
174
|
- **Tree of Thoughts:** For critical architectural decisions, use branching to explore multiple paths (Conservative vs. Aggressive) and evaluate them using `thoughtType: 'evaluation'`.
|
|
175
|
+
- **Loop Breaker:** If a bug persists after 2 attempts or reasoning loops, MUST create a new branch (`branchFromThought`) to change strategy completely.
|
|
167
176
|
- **Verified Completion:** Only set `nextThoughtNeeded: false` when the solution is definitive, verified, and follows project standards.
|
|
168
177
|
|
|
169
178
|
## 🏗 CODEBASE INTELLIGENCE PROTOCOL
|
|
@@ -185,6 +194,7 @@ You are a Senior AI Software Engineer equipped with the Sequential Thinking MCP
|
|
|
185
194
|
|
|
186
195
|
## 📝 PERSISTENT MEMORY
|
|
187
196
|
- **Long-term Knowledge:** Use `manage_notes` to save architectural decisions, user preferences, project conventions, and "lessons learned" that must persist across sessions.
|
|
197
|
+
- **Code Database:** Use `add_code_snippet` to store reusable patterns and `search_code_db` to retrieve them.
|
|
188
198
|
- **Session Continuity:** Your thought history is saved. If you restart, review the history to maintain context.
|
|
189
199
|
```
|
|
190
200
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as fs from 'fs/promises';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
export class CodeDatabase {
|
|
4
|
+
filePath;
|
|
5
|
+
db = { snippets: [], patterns: {} };
|
|
6
|
+
loaded = false;
|
|
7
|
+
constructor(storagePath = 'code_database.json') {
|
|
8
|
+
this.filePath = path.resolve(storagePath);
|
|
9
|
+
}
|
|
10
|
+
async load() {
|
|
11
|
+
if (this.loaded)
|
|
12
|
+
return;
|
|
13
|
+
try {
|
|
14
|
+
const data = await fs.readFile(this.filePath, 'utf-8');
|
|
15
|
+
this.db = JSON.parse(data);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
this.db = { snippets: [], patterns: {} };
|
|
19
|
+
}
|
|
20
|
+
this.loaded = true;
|
|
21
|
+
}
|
|
22
|
+
async save() {
|
|
23
|
+
await fs.writeFile(this.filePath, JSON.stringify(this.db, null, 2), 'utf-8');
|
|
24
|
+
}
|
|
25
|
+
async addSnippet(snippet) {
|
|
26
|
+
await this.load();
|
|
27
|
+
const newSnippet = {
|
|
28
|
+
...snippet,
|
|
29
|
+
id: Math.random().toString(36).substring(2, 9),
|
|
30
|
+
updatedAt: new Date().toISOString()
|
|
31
|
+
};
|
|
32
|
+
this.db.snippets.push(newSnippet);
|
|
33
|
+
await this.save();
|
|
34
|
+
return newSnippet;
|
|
35
|
+
}
|
|
36
|
+
async searchSnippets(query) {
|
|
37
|
+
await this.load();
|
|
38
|
+
const q = query.toLowerCase();
|
|
39
|
+
return this.db.snippets.filter(s => s.title.toLowerCase().includes(q) ||
|
|
40
|
+
s.description.toLowerCase().includes(q) ||
|
|
41
|
+
s.tags.some(t => t.toLowerCase().includes(q)) ||
|
|
42
|
+
s.code.toLowerCase().includes(q));
|
|
43
|
+
}
|
|
44
|
+
async learnPattern(name, description) {
|
|
45
|
+
await this.load();
|
|
46
|
+
this.db.patterns[name] = description;
|
|
47
|
+
await this.save();
|
|
48
|
+
}
|
|
49
|
+
async getPattern(name) {
|
|
50
|
+
await this.load();
|
|
51
|
+
return this.db.patterns[name] || null;
|
|
52
|
+
}
|
|
53
|
+
async listAllPatterns() {
|
|
54
|
+
await this.load();
|
|
55
|
+
return this.db.patterns;
|
|
56
|
+
}
|
|
57
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -4,12 +4,14 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
4
4
|
import { SequentialThinkingServer } from './lib.js';
|
|
5
5
|
import { ProjectKnowledgeGraph } from './graph.js';
|
|
6
6
|
import { NotesManager } from './notes.js';
|
|
7
|
+
import { CodeDatabase } from './codestore.js';
|
|
7
8
|
import { registerThinkingTools } from './tools/thinking.js';
|
|
8
9
|
import { registerWebTools } from './tools/web.js';
|
|
9
10
|
import { registerFileSystemTools } from './tools/filesystem.js';
|
|
10
11
|
import { registerGraphTools } from './tools/graph.js';
|
|
11
12
|
import { registerNoteTools } from './tools/notes.js';
|
|
12
13
|
import { registerCodingTools } from './tools/coding.js';
|
|
14
|
+
import { registerCodeDbTools } from './tools/codestore.js';
|
|
13
15
|
const server = new McpServer({
|
|
14
16
|
name: "sequential-thinking-server",
|
|
15
17
|
version: "2026.2.6",
|
|
@@ -17,6 +19,7 @@ const server = new McpServer({
|
|
|
17
19
|
const thinkingServer = new SequentialThinkingServer(process.env.THOUGHTS_STORAGE_PATH || 'thoughts_history.json', parseInt(process.env.THOUGHT_DELAY_MS || '0', 10));
|
|
18
20
|
const knowledgeGraph = new ProjectKnowledgeGraph();
|
|
19
21
|
const notesManager = new NotesManager(process.env.NOTES_STORAGE_PATH || 'project_notes.json');
|
|
22
|
+
const codeDb = new CodeDatabase(process.env.CODE_DB_PATH || 'code_database.json');
|
|
20
23
|
// Register tools
|
|
21
24
|
registerThinkingTools(server, thinkingServer);
|
|
22
25
|
registerWebTools(server);
|
|
@@ -24,6 +27,7 @@ registerFileSystemTools(server);
|
|
|
24
27
|
registerGraphTools(server, knowledgeGraph);
|
|
25
28
|
registerNoteTools(server, notesManager);
|
|
26
29
|
registerCodingTools(server, knowledgeGraph);
|
|
30
|
+
registerCodeDbTools(server, codeDb);
|
|
27
31
|
async function runServer() {
|
|
28
32
|
const transport = new StdioServerTransport();
|
|
29
33
|
await server.connect(transport);
|
package/dist/notes.js
CHANGED
|
@@ -23,13 +23,15 @@ export class NotesManager {
|
|
|
23
23
|
async save() {
|
|
24
24
|
await fs.writeFile(this.filePath, JSON.stringify(this.notes, null, 2), 'utf-8');
|
|
25
25
|
}
|
|
26
|
-
async addNote(title, content, tags = []) {
|
|
26
|
+
async addNote(title, content, tags = [], priority = 'medium', expiresAt) {
|
|
27
27
|
await this.load();
|
|
28
28
|
const note = {
|
|
29
29
|
id: Date.now().toString(36) + Math.random().toString(36).substring(2, 7),
|
|
30
30
|
title,
|
|
31
31
|
content,
|
|
32
32
|
tags,
|
|
33
|
+
priority,
|
|
34
|
+
expiresAt,
|
|
33
35
|
createdAt: new Date().toISOString(),
|
|
34
36
|
updatedAt: new Date().toISOString()
|
|
35
37
|
};
|
|
@@ -37,12 +39,20 @@ export class NotesManager {
|
|
|
37
39
|
await this.save();
|
|
38
40
|
return note;
|
|
39
41
|
}
|
|
40
|
-
async listNotes(tag) {
|
|
42
|
+
async listNotes(tag, includeExpired = false) {
|
|
41
43
|
await this.load();
|
|
44
|
+
const now = new Date();
|
|
45
|
+
let activeNotes = this.notes;
|
|
46
|
+
if (!includeExpired) {
|
|
47
|
+
activeNotes = this.notes.filter(n => !n.expiresAt || new Date(n.expiresAt) > now);
|
|
48
|
+
}
|
|
42
49
|
if (tag) {
|
|
43
|
-
return
|
|
50
|
+
return activeNotes.filter(n => n.tags.includes(tag));
|
|
44
51
|
}
|
|
45
|
-
return
|
|
52
|
+
return activeNotes.sort((a, b) => {
|
|
53
|
+
const priorityMap = { 'critical': 4, 'high': 3, 'medium': 2, 'low': 1 };
|
|
54
|
+
return (priorityMap[b.priority] || 0) - (priorityMap[a.priority] || 0);
|
|
55
|
+
});
|
|
46
56
|
}
|
|
47
57
|
async searchNotes(query) {
|
|
48
58
|
await this.load();
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { NotesManager } from './notes.js';
|
|
2
|
+
import { CodeDatabase } from './codestore.js';
|
|
3
|
+
import * as fs from 'fs/promises';
|
|
4
|
+
async function testSystem() {
|
|
5
|
+
console.log("🚀 Starting System Logic Test...\n");
|
|
6
|
+
// --- 1. Testing Notes Manager (Priority & Expiration) ---
|
|
7
|
+
console.log("--- Testing Notes Manager ---");
|
|
8
|
+
const notes = new NotesManager('test_notes.json');
|
|
9
|
+
// Clean up previous test
|
|
10
|
+
try {
|
|
11
|
+
await fs.unlink('test_notes.json');
|
|
12
|
+
}
|
|
13
|
+
catch { }
|
|
14
|
+
console.log("1. Adding CRITICAL note (expires tomorrow)...");
|
|
15
|
+
await notes.addNote("Urgent Security Fix", "Fix the login bug", ["bug"], "critical", new Date(Date.now() + 86400000).toISOString());
|
|
16
|
+
console.log("2. Adding LOW priority note...");
|
|
17
|
+
await notes.addNote("Refactor UI", "Make it pretty eventually", ["ui"], "low");
|
|
18
|
+
console.log("3. Listing notes (Expect Critical first)...");
|
|
19
|
+
const list = await notes.listNotes();
|
|
20
|
+
list.forEach(n => console.log(`- [${n.priority.toUpperCase()}] ${n.title}`));
|
|
21
|
+
// --- 2. Testing Code Database ---
|
|
22
|
+
console.log("\n--- Testing Code Database ---");
|
|
23
|
+
const codeDb = new CodeDatabase('test_code_db.json');
|
|
24
|
+
try {
|
|
25
|
+
await fs.unlink('test_code_db.json');
|
|
26
|
+
}
|
|
27
|
+
catch { }
|
|
28
|
+
console.log("1. Adding Code Snippet...");
|
|
29
|
+
await codeDb.addSnippet({
|
|
30
|
+
title: "Deepest Thinking Prompt",
|
|
31
|
+
language: "markdown",
|
|
32
|
+
code: "You must use sequentialthinking...",
|
|
33
|
+
description: "Standard prompt for deep agents",
|
|
34
|
+
tags: ["prompt", "ai"]
|
|
35
|
+
});
|
|
36
|
+
console.log("2. Searching for 'Deepest'...");
|
|
37
|
+
const results = await codeDb.searchSnippets("Deepest");
|
|
38
|
+
console.log(`Found ${results.length} result(s):`);
|
|
39
|
+
results.forEach(r => console.log(`- ${r.title} (${r.language})`));
|
|
40
|
+
console.log("\n✅ Test Complete!");
|
|
41
|
+
// Cleanup
|
|
42
|
+
try {
|
|
43
|
+
await fs.unlink('test_notes.json');
|
|
44
|
+
}
|
|
45
|
+
catch { }
|
|
46
|
+
try {
|
|
47
|
+
await fs.unlink('test_code_db.json');
|
|
48
|
+
}
|
|
49
|
+
catch { }
|
|
50
|
+
}
|
|
51
|
+
testSystem();
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export function registerCodeDbTools(server, db) {
|
|
3
|
+
// 16. add_code_snippet
|
|
4
|
+
server.tool("add_code_snippet", "Add a useful code snippet or implementation pattern to the persistent Code Database.", {
|
|
5
|
+
title: z.string().describe("Title of the snippet"),
|
|
6
|
+
code: z.string().describe("The actual code"),
|
|
7
|
+
language: z.string().describe("Programming language"),
|
|
8
|
+
description: z.string().describe("What this code does and why it is useful"),
|
|
9
|
+
tags: z.array(z.string()).optional().default([]).describe("Tags for categorization")
|
|
10
|
+
}, async (args) => {
|
|
11
|
+
const snippet = await db.addSnippet(args);
|
|
12
|
+
return {
|
|
13
|
+
content: [{ type: "text", text: `Snippet saved with ID: ${snippet.id}` }]
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
// 17. search_code_db
|
|
17
|
+
server.tool("search_code_db", "Search the Code Database for existing snippets, patterns, or architectural knowledge.", {
|
|
18
|
+
query: z.string().describe("Search query")
|
|
19
|
+
}, async ({ query }) => {
|
|
20
|
+
const results = await db.searchSnippets(query);
|
|
21
|
+
const patterns = await db.listAllPatterns();
|
|
22
|
+
let output = `--- CODE DATABASE RESULTS ---\n\n`;
|
|
23
|
+
if (results.length > 0) {
|
|
24
|
+
output += `SNIPPETS FOUND:\n`;
|
|
25
|
+
results.forEach(s => {
|
|
26
|
+
output += `ID: ${s.id} | ${s.title} (${s.language})\nDesc: ${s.description}\nCode:\n\`\`\`\n${s.code}\n\`\`\`\n\n`;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const matchedPatterns = Object.entries(patterns).filter(([k, v]) => k.toLowerCase().includes(query.toLowerCase()) || v.toLowerCase().includes(query.toLowerCase()));
|
|
30
|
+
if (matchedPatterns.length > 0) {
|
|
31
|
+
output += `PATTERNS FOUND:\n`;
|
|
32
|
+
matchedPatterns.forEach(([name, desc]) => {
|
|
33
|
+
output += `- ${name}: ${desc}\n`;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (results.length === 0 && matchedPatterns.length === 0) {
|
|
37
|
+
output += "No results found in the Code Database.";
|
|
38
|
+
}
|
|
39
|
+
return { content: [{ type: "text", text: output }] };
|
|
40
|
+
});
|
|
41
|
+
// 18. learn_architecture_pattern
|
|
42
|
+
server.tool("learn_architecture_pattern", "Store a high-level architectural or logic pattern in the Code DB (e.g., 'auth-flow', 'error-handling-strategy').", {
|
|
43
|
+
name: z.string().describe("Name of the pattern"),
|
|
44
|
+
description: z.string().describe("Detailed description of the pattern and how it applies to this project")
|
|
45
|
+
}, async ({ name, description }) => {
|
|
46
|
+
await db.learnPattern(name, description);
|
|
47
|
+
return {
|
|
48
|
+
content: [{ type: "text", text: `Pattern '${name}' learned and stored.` }]
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
}
|
package/dist/tools/notes.js
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export function registerNoteTools(server, notesManager) {
|
|
3
3
|
// 15. manage_notes
|
|
4
|
-
server.tool("manage_notes", "Manage long-term memory/notes. Use this to save important information, rules, or learnings that should persist across sessions.", {
|
|
4
|
+
server.tool("manage_notes", "Manage long-term memory/notes. Use this to save important information, rules, or learnings that should persist across sessions. Supports priority levels and expiration dates.", {
|
|
5
5
|
action: z.enum(['add', 'list', 'search', 'update', 'delete']).describe("Action to perform"),
|
|
6
6
|
title: z.string().optional().describe("Title of the note (for add/update)"),
|
|
7
7
|
content: z.string().optional().describe("Content of the note (for add/update)"),
|
|
8
8
|
tags: z.array(z.string()).optional().describe("Tags for categorization (for add/update)"),
|
|
9
9
|
searchQuery: z.string().optional().describe("Query to search notes (for search)"),
|
|
10
|
-
noteId: z.string().optional().describe("ID of the note (for update/delete)")
|
|
11
|
-
|
|
10
|
+
noteId: z.string().optional().describe("ID of the note (for update/delete)"),
|
|
11
|
+
priority: z.enum(['low', 'medium', 'high', 'critical']).optional().default('medium').describe("Priority level"),
|
|
12
|
+
expiresAt: z.string().optional().describe("Expiration date in ISO format (e.g., 2026-12-31)"),
|
|
13
|
+
includeExpired: z.boolean().optional().default(false).describe("Whether to include expired notes in list")
|
|
14
|
+
}, async ({ action, title, content, tags, searchQuery, noteId, priority, expiresAt, includeExpired }) => {
|
|
12
15
|
try {
|
|
13
16
|
switch (action) {
|
|
14
17
|
case 'add':
|
|
15
18
|
if (!title || !content) {
|
|
16
19
|
return { content: [{ type: "text", text: "Error: 'title' and 'content' are required for add action." }], isError: true };
|
|
17
20
|
}
|
|
18
|
-
const newNote = await notesManager.addNote(title, content, tags);
|
|
19
|
-
return { content: [{ type: "text", text: `Note added successfully.\nID: ${newNote.id}` }] };
|
|
21
|
+
const newNote = await notesManager.addNote(title, content, tags, priority, expiresAt);
|
|
22
|
+
return { content: [{ type: "text", text: `Note added successfully.\nID: ${newNote.id} (Priority: ${newNote.priority})` }] };
|
|
20
23
|
case 'list':
|
|
21
|
-
const notes = await notesManager.listNotes();
|
|
24
|
+
const notes = await notesManager.listNotes(undefined, includeExpired);
|
|
22
25
|
return { content: [{ type: "text", text: JSON.stringify(notes, null, 2) }] };
|
|
23
26
|
case 'search':
|
|
24
27
|
if (!searchQuery) {
|
package/dist/tools/thinking.js
CHANGED
|
@@ -27,6 +27,13 @@ Key features:
|
|
|
27
27
|
- Hypothesis Testing: Formulate and verify hypotheses based on Chain of Thought.
|
|
28
28
|
- Branch Merging: Combine insights from multiple divergent paths.
|
|
29
29
|
|
|
30
|
+
Troubleshooting & Stuck States:
|
|
31
|
+
- If you realize you are stuck in a loop or a bug persists after 2 attempts:
|
|
32
|
+
1. Do NOT continue linear thoughts.
|
|
33
|
+
2. Create a NEW BRANCH ('branchFromThought') from a point before the error.
|
|
34
|
+
3. Explicitly state "Stuck detected, branching to explore Approach B".
|
|
35
|
+
4. Change your fundamental assumptions or implementation strategy completely.
|
|
36
|
+
|
|
30
37
|
Parameters explained:
|
|
31
38
|
- thought: Your current thinking step (analysis, revision, question, hypothesis).
|
|
32
39
|
- nextThoughtNeeded: True if you need more thinking, even if at what seemed like the end.
|