@gotza02/sequential-thinking 2026.1.23 → 2026.1.25
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 +88 -36
- package/dist/graph.js +12 -8
- package/dist/graph_repro.test.js +63 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,70 +24,117 @@ When connected to this server, you should follow these guidelines to maximize pr
|
|
|
24
24
|
4. **Local Execution**: Use `shell_execute` to run tests, linters, or build commands to verify your changes. Always read files using `read_file` before attempting to write or modify them.
|
|
25
25
|
5. **Persistence**: The thinking process is saved automatically. You can resume previous sessions by reviewing the `thoughts_history.json` file if needed.
|
|
26
26
|
|
|
27
|
-
## Tool
|
|
27
|
+
## Detailed Tool Guide
|
|
28
28
|
|
|
29
|
-
###
|
|
29
|
+
### 🧠 Cognitive Tools
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
#### `sequentialthinking`
|
|
32
|
+
The core engine for structured problem-solving. It forces a step-by-step analysis before arriving at a conclusion.
|
|
32
33
|
|
|
33
|
-
**
|
|
34
|
+
**Inputs:**
|
|
35
|
+
- `thought` (string, required): The content of the current thinking step.
|
|
36
|
+
- `thoughtNumber` (integer, required): Current step number (starts at 1).
|
|
37
|
+
- `totalThoughts` (integer, required): Estimated total steps needed (can be adjusted dynamically).
|
|
38
|
+
- `nextThoughtNeeded` (boolean, required): `true` if you need to think more, `false` only when the final answer is ready.
|
|
39
|
+
- `thoughtType` (enum): The nature of the thought:
|
|
40
|
+
- `analysis`: Breaking down the problem.
|
|
41
|
+
- `generation`: Brainstorming solutions.
|
|
42
|
+
- `evaluation`: Weighing options (use with `score`).
|
|
43
|
+
- `reflexion`: Reviewing previous thoughts (use with `isRevision`).
|
|
44
|
+
- `selection`: Choosing a path.
|
|
45
|
+
- `isRevision` (boolean): Set to `true` if you are correcting a previous mistake.
|
|
46
|
+
- `revisesThought` (integer): The thought number you are fixing.
|
|
47
|
+
- `branchFromThought` (integer): The parent thought number if creating a new reasoning branch.
|
|
48
|
+
- `branchId` (string): A name for the new branch.
|
|
49
|
+
|
|
50
|
+
**Best Practice:** Use this for ANY non-trivial task. Don't just answer; think first.
|
|
51
|
+
|
|
52
|
+
### 🌐 External Knowledge
|
|
53
|
+
|
|
54
|
+
#### `web_search`
|
|
55
|
+
Retrieves real-time information from the internet.
|
|
34
56
|
|
|
35
|
-
|
|
57
|
+
**Inputs:**
|
|
58
|
+
- `query` (string, required): What you want to find.
|
|
59
|
+
- `provider` (enum, optional):
|
|
60
|
+
- `brave`: General web search (Requires `BRAVE_API_KEY`).
|
|
61
|
+
- `exa`: AI-optimized search for deep content (Requires `EXA_API_KEY`).
|
|
62
|
+
- `google`: Google Custom Search (Requires `GOOGLE_SEARCH_API_KEY` & `GOOGLE_SEARCH_CX`).
|
|
36
63
|
|
|
37
|
-
|
|
64
|
+
#### `fetch`
|
|
65
|
+
Performs a direct HTTP request to a URL. Useful for getting raw HTML, JSON, or text from a specific source found via search.
|
|
38
66
|
|
|
39
67
|
**Inputs:**
|
|
40
|
-
- `
|
|
41
|
-
- `
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
Requires one of the following environment variable sets:
|
|
45
|
-
- `BRAVE_API_KEY` (for Brave Search)
|
|
46
|
-
- `EXA_API_KEY` (for Exa Search)
|
|
47
|
-
- `GOOGLE_SEARCH_API_KEY` and `GOOGLE_SEARCH_CX` (for Google Custom Search)
|
|
68
|
+
- `url` (string, required): The target URL.
|
|
69
|
+
- `method`: `GET` (default), `POST`, `PUT`, `DELETE`.
|
|
70
|
+
- `headers`: JSON object for headers (e.g., `{"Authorization": "Bearer..."}`).
|
|
71
|
+
- `body`: Request body for POST/PUT.
|
|
48
72
|
|
|
49
|
-
###
|
|
73
|
+
### 🏗 Codebase Intelligence
|
|
50
74
|
|
|
51
|
-
|
|
75
|
+
#### `build_project_graph`
|
|
76
|
+
**RUN THIS FIRST** when entering a new project. It scans the directory and builds a map of file dependencies using TypeScript AST analysis.
|
|
52
77
|
|
|
53
78
|
**Inputs:**
|
|
54
|
-
- `
|
|
55
|
-
- `method` (string, optional): HTTP method (GET, POST, etc.).
|
|
56
|
-
- `headers` (object, optional): Request headers.
|
|
57
|
-
- `body` (string, optional): Request body.
|
|
79
|
+
- `path` (string, optional): Root directory (defaults to `.`).
|
|
58
80
|
|
|
59
|
-
|
|
81
|
+
#### `get_project_graph_summary`
|
|
82
|
+
Returns high-level stats: total files and the top 5 most-referenced files. Use this to identify the "core" modules of the application.
|
|
60
83
|
|
|
61
|
-
|
|
84
|
+
#### `get_file_relationships`
|
|
85
|
+
Zoom in on a specific file to see its context.
|
|
62
86
|
|
|
63
87
|
**Inputs:**
|
|
64
|
-
- `
|
|
88
|
+
- `filePath` (string, required): Path to the file (e.g., `src/index.ts`).
|
|
89
|
+
**Returns:**
|
|
90
|
+
- `imports`: What this file needs.
|
|
91
|
+
- `importedBy`: Who relies on this file.
|
|
65
92
|
|
|
66
|
-
###
|
|
93
|
+
### 🛠 System Operations
|
|
67
94
|
|
|
68
|
-
|
|
95
|
+
#### `read_file`
|
|
96
|
+
Reads the content of a file. Always read a file before editing it to ensure you have the latest context.
|
|
69
97
|
|
|
70
98
|
**Inputs:**
|
|
71
|
-
- `path` (string): File path.
|
|
72
|
-
- `content` (string, for write_file): Content to write.
|
|
99
|
+
- `path` (string, required): File path.
|
|
73
100
|
|
|
74
|
-
|
|
101
|
+
#### `write_file`
|
|
102
|
+
Creates or overwrites a file.
|
|
75
103
|
|
|
76
|
-
|
|
104
|
+
**Inputs:**
|
|
105
|
+
- `path` (string, required): File path.
|
|
106
|
+
- `content` (string, required): The full content to write.
|
|
107
|
+
|
|
108
|
+
#### `shell_execute`
|
|
109
|
+
Executes a shell command. Use for running tests (`npm test`), building (`npm run build`), or file operations (`ls`, `mkdir`).
|
|
77
110
|
|
|
78
111
|
**Inputs:**
|
|
79
|
-
- `
|
|
112
|
+
- `command` (string, required): The command line string.
|
|
113
|
+
**Warning:** Use with caution. Avoid commands that might delete data or expose secrets.
|
|
80
114
|
|
|
81
|
-
|
|
115
|
+
## Recommended System Instruction
|
|
82
116
|
|
|
83
|
-
|
|
117
|
+
To optimize your AI agent's performance with these tools, we recommend adding the following instructions to its system prompt:
|
|
84
118
|
|
|
85
|
-
|
|
86
|
-
|
|
119
|
+
```text
|
|
120
|
+
# Tools & Workflow
|
|
87
121
|
|
|
88
|
-
|
|
122
|
+
1. **Core Reasoning (`sequentialthinking`)**
|
|
123
|
+
* **Mandatory Step:** For any complex query, bug fix, or feature request, you MUST start by using the `sequentialthinking` tool.
|
|
124
|
+
* **Methodology:** Break the problem down. If your first hypothesis fails, use the tool again to revise your plan (`isRevision: true`).
|
|
125
|
+
* **Goal:** Do not output code or final answers until you have a clear, verified plan.
|
|
89
126
|
|
|
90
|
-
|
|
127
|
+
2. **Codebase Navigation**
|
|
128
|
+
* **Initial Scan:** On start, run `build_project_graph`.
|
|
129
|
+
* **Context:** Before reading a file, check its context with `get_file_relationships`. This prevents "hallucinating" imports or breaking existing dependencies.
|
|
130
|
+
|
|
131
|
+
3. **External Verification**
|
|
132
|
+
* **Docs & Facts:** If you need to use a library you aren't 100% sure about, use `web_search` to check the documentation.
|
|
133
|
+
|
|
134
|
+
4. **Safety & Persistence**
|
|
135
|
+
* **Files:** Always `read_file` before `write_file`.
|
|
136
|
+
* **History:** Your thoughts are saved. If you get stuck, review your previous thoughts.
|
|
137
|
+
```
|
|
91
138
|
|
|
92
139
|
## Usage
|
|
93
140
|
|
|
@@ -146,6 +193,11 @@ npm run build
|
|
|
146
193
|
npm test
|
|
147
194
|
```
|
|
148
195
|
|
|
196
|
+
## Recent Updates (v2026.1.24)
|
|
197
|
+
|
|
198
|
+
- **Bug Fixes**:
|
|
199
|
+
- Fixed `get_file_relationships` to correctly resolve absolute imports and imports from project root (e.g., `src/utils`), ensuring the dependency graph is complete for projects using path aliases or absolute paths.
|
|
200
|
+
|
|
149
201
|
## Recent Updates (v2026.1.22)
|
|
150
202
|
|
|
151
203
|
- **Environment Variables**:
|
package/dist/graph.js
CHANGED
|
@@ -79,15 +79,19 @@ export class ProjectKnowledgeGraph {
|
|
|
79
79
|
if (!currentNode)
|
|
80
80
|
return;
|
|
81
81
|
for (const importPath of imports) {
|
|
82
|
+
let resolvedPath = null;
|
|
82
83
|
if (importPath.startsWith('.')) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
resolvedPath = await this.resolvePath(path.dirname(filePath), importPath);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
resolvedPath = await this.resolvePath(this.rootDir, importPath);
|
|
88
|
+
}
|
|
89
|
+
if (resolvedPath && this.nodes.has(resolvedPath)) {
|
|
90
|
+
if (!currentNode.imports.includes(resolvedPath)) {
|
|
91
|
+
currentNode.imports.push(resolvedPath);
|
|
92
|
+
}
|
|
93
|
+
if (!this.nodes.get(resolvedPath)?.importedBy.includes(filePath)) {
|
|
94
|
+
this.nodes.get(resolvedPath)?.importedBy.push(filePath);
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
+
import { ProjectKnowledgeGraph } from './graph.js';
|
|
3
|
+
import * as fs from 'fs/promises';
|
|
4
|
+
vi.mock('fs/promises');
|
|
5
|
+
describe('ProjectKnowledgeGraph Reproduction', () => {
|
|
6
|
+
let graph;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
graph = new ProjectKnowledgeGraph();
|
|
9
|
+
vi.resetAllMocks();
|
|
10
|
+
});
|
|
11
|
+
it('should resolve absolute imports from project root', async () => {
|
|
12
|
+
// Scenario: /app/src/feature/a.ts imports 'src/shared/b.ts'
|
|
13
|
+
const mockContentA = `import { b } from 'src/shared/b';`;
|
|
14
|
+
fs.readdir.mockResolvedValue([
|
|
15
|
+
{ name: 'src', isDirectory: () => true },
|
|
16
|
+
{ name: 'feature', isDirectory: () => true },
|
|
17
|
+
{ name: 'shared', isDirectory: () => true },
|
|
18
|
+
{ name: 'a.ts', isDirectory: () => false },
|
|
19
|
+
{ name: 'b.ts', isDirectory: () => false }
|
|
20
|
+
]);
|
|
21
|
+
// Mock getAllFiles behavior by manually setting up the file system structure conceptually
|
|
22
|
+
// Since getAllFiles is recursive and hard to mock perfectly with just readdir,
|
|
23
|
+
// we'll focus on the result of getAllFiles which populates the graph.
|
|
24
|
+
// Wait, the test uses the REAL getAllFiles, so we must mock readdir correctly.
|
|
25
|
+
// Let's simplify: Flat structure for test.
|
|
26
|
+
// Root: /app
|
|
27
|
+
// Files: /app/a.ts, /app/b.ts
|
|
28
|
+
// a.ts content: "import ... from 'b'" (no dot)
|
|
29
|
+
// OR
|
|
30
|
+
// a.ts content: "import ... from 'app/b'" (if root is /)
|
|
31
|
+
// Let's try the 'src/...' pattern which is common.
|
|
32
|
+
// Root: /root
|
|
33
|
+
// File: /root/src/index.ts -> imports 'src/utils'
|
|
34
|
+
// File: /root/src/utils.ts
|
|
35
|
+
const rootDir = '/root';
|
|
36
|
+
const indexFile = '/root/src/index.ts';
|
|
37
|
+
const utilsFile = '/root/src/utils.ts';
|
|
38
|
+
// Mock readdir to simulate:
|
|
39
|
+
// /root -> [src]
|
|
40
|
+
// /root/src -> [index.ts, utils.ts]
|
|
41
|
+
fs.readdir.mockImplementation(async (dir) => {
|
|
42
|
+
if (dir === '/root')
|
|
43
|
+
return [{ name: 'src', isDirectory: () => true }];
|
|
44
|
+
if (dir === '/root/src')
|
|
45
|
+
return [
|
|
46
|
+
{ name: 'index.ts', isDirectory: () => false },
|
|
47
|
+
{ name: 'utils.ts', isDirectory: () => false }
|
|
48
|
+
];
|
|
49
|
+
return [];
|
|
50
|
+
});
|
|
51
|
+
fs.readFile.mockImplementation(async (filePath) => {
|
|
52
|
+
if (filePath === indexFile)
|
|
53
|
+
return `import { u } from 'src/utils';`;
|
|
54
|
+
return '';
|
|
55
|
+
});
|
|
56
|
+
await graph.build(rootDir);
|
|
57
|
+
const relationships = graph.getRelationships(indexFile);
|
|
58
|
+
// We expect 'src/utils.ts' to be in imports.
|
|
59
|
+
// Note: graph.getRelationships returns relative paths.
|
|
60
|
+
// relative('/root', '/root/src/utils.ts') -> 'src/utils.ts'
|
|
61
|
+
expect(relationships?.imports).toContain('src/utils.ts');
|
|
62
|
+
});
|
|
63
|
+
});
|