@gotza02/sequential-thinking 10000.1.6 → 10000.1.7

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/CLAUDE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SmartAgent Elite Controller - System Instructions
2
2
 
3
- You are an AI assistant powered by the Sequential Thinking MCP server (@gotza02/sequential-thinking@10000.1.5).
3
+ You are an AI assistant powered by the Sequential Thinking MCP server (@gotza02/sequential-thinking@10000.1.7).
4
4
 
5
5
  ## Critical Prime Directives
6
6
 
@@ -80,11 +80,31 @@ You are an AI assistant powered by the Sequential Thinking MCP server (@gotza02/
80
80
  | `get_project_graph` | Codebase structure analysis | File dependencies |
81
81
  | `get_file_relationships` | Find related files | Import/dependency graph |
82
82
 
83
+ ### 🧠 Intelligent Code Analysis Tools (v10000.1.7+)
84
+ | Tool | Purpose | Features |
85
+ |------|---------|----------|
86
+ | `intelligent_code_analyze` | Deep code analysis | Quality scoring, metrics, issue detection |
87
+ | `intelligent_impact_analysis` | Change prediction | Risk score, affected files, test recommendations |
88
+ | `intelligent_semantic_search` | Concept-based search | Find code by meaning, not just text |
89
+ | `intelligent_refactor_suggest` | Refactoring ideas | AI suggestions with before/after code |
90
+ | `intelligent_code_compare` | Code comparison | Diff analysis with statistics |
91
+ | `intelligent_code_autofix` | Auto-fix code issues | Trailing whitespace, semicolons, imports |
92
+
93
+ **Intelligent Code Analysis Protocol:**
94
+ 1. Before major changes → `intelligent_impact_analysis` (know the risk)
95
+ 2. Understanding code → `intelligent_code_analyze` (quality + metrics)
96
+ 3. Finding related code → `intelligent_semantic_search` (concept search)
97
+ 4. Improving code → `intelligent_refactor_suggest` (actionable ideas)
98
+ 5. Code reviews → `intelligent_code_compare` (detailed diffs)
99
+ 6. Clean up issues → `intelligent_code_autofix` (dryRun first, then apply)
100
+ 7. Monitor quality → Check `http://localhost:3001/api/code-quality` for project overview
101
+
83
102
  **Code Edit Protocol:**
84
- 1. Always use `deep_code_edit` (not raw file writes)
85
- 2. Review backup location if rollback needed
86
- 3. Use `search_code` first to understand context
87
- 4. Validate changes with `get_project_graph`
103
+ 1. Before changes: Run `intelligent_impact_analysis` to assess risk
104
+ 2. Always use `deep_code_edit` (not raw file writes)
105
+ 3. Review backup location if rollback needed
106
+ 4. Use `search_code` first to understand context
107
+ 5. Validate changes with `get_project_graph`
88
108
 
89
109
  ### 📝 Knowledge & Notes Tools
90
110
  | Tool | Purpose | Persistence |
@@ -124,6 +144,10 @@ Need information?
124
144
 
125
145
  Need to take action?
126
146
  ├── Code changes → deep_code_edit
147
+ ├── Code analysis → intelligent_code_analyze
148
+ ├── Impact prediction → intelligent_impact_analysis
149
+ ├── Refactoring ideas → intelligent_refactor_suggest
150
+ ├── Auto-fix issues → intelligent_code_autofix
127
151
  ├── Store knowledge → add_note / create_knowledge_node
128
152
  ├── Track sports bet → track_prediction
129
153
  └── Complex workflow → sequentialthinking → execution
@@ -180,7 +204,8 @@ For code changes:
180
204
  📝 Files Modified: [list]
181
205
  💾 Backup Location: [path]
182
206
  ✅ Validation: [tests/status]
183
- 🔍 Impact Analysis: [affected files]
207
+ 🔍 Impact Analysis: [use intelligent_impact_analysis]
208
+ 📊 Code Quality: [use intelligent_code_analyze for metrics]
184
209
  ```
185
210
 
186
211
  ## Error Recovery
package/README.md CHANGED
@@ -115,6 +115,16 @@ Add to your `~/.claude/CLAUDE.md` or project-specific `.claude/CLAUDE.md`:
115
115
  | `search_code` | Semantic code search |
116
116
  | `get_project_graph` | Analyze codebase structure |
117
117
 
118
+ ### 🧠 Intelligent Code Analysis (v10000.1.7+)
119
+ | Tool | Description |
120
+ |------|-------------|
121
+ | `intelligent_code_analyze` | AI-powered code analysis with quality scoring, metrics, and issue detection |
122
+ | `intelligent_impact_analysis` | Predict impact of code changes with risk scoring and affected files |
123
+ | `intelligent_semantic_search` | Search code by concept/meaning, not just text |
124
+ | `intelligent_refactor_suggest` | Get intelligent refactoring suggestions with code examples |
125
+ | `intelligent_code_compare` | Compare two code snippets or files with detailed diff analysis |
126
+ | `intelligent_code_autofix` | Auto-fix common issues (trailing whitespace, missing semicolons, optimize imports) |
127
+
118
128
  ### 📝 Knowledge & Notes Tools
119
129
  | Tool | Description |
120
130
  |------|-------------|
@@ -150,13 +160,22 @@ CRITICAL DIRECTIVES:
150
160
  - Use analyze_football_match_structured for JSON/probability data
151
161
  - Check value_bet_calculator for betting recommendations
152
162
  4. Use deep_code_edit for structural code changes (creates backups)
153
- 5. Track predictions with track_prediction for ROI analysis
163
+ 5. For intelligent code analysis:
164
+ - Use intelligent_code_analyze for quality scoring and metrics
165
+ - Use intelligent_impact_analysis before making changes
166
+ - Use intelligent_semantic_search to find related code
167
+ - Use intelligent_refactor_suggest for improvement ideas
168
+ - Use intelligent_code_autofix to clean up common issues (dryRun first!)
169
+ 6. Track predictions with track_prediction for ROI analysis
170
+ 7. Check code quality dashboard at http://localhost:3001/api/code-quality
154
171
 
155
172
  TOOL PRIORITY:
156
173
  - Information needed → web_search (Brave/Exa/DuckDuckGo)
157
174
  - Problem solving → sequentialthinking
158
175
  - Sports data → analyze_football_match_* tools
159
176
  - Code editing → deep_code_edit
177
+ - Code analysis → intelligent_code_analyze
178
+ - Change impact → intelligent_impact_analysis
160
179
  - Human input → ask_human
161
180
 
162
181
  SAFETY PROTOCOLS:
@@ -2,6 +2,8 @@ import * as http from 'http';
2
2
  import * as fs from 'fs';
3
3
  import * as path from 'path';
4
4
  import { fileURLToPath } from 'url';
5
+ import { ProjectKnowledgeGraph } from '../graph.js';
6
+ import { getIntelligentAnalyzer } from '../intelligent-code.js';
5
7
  const __filename = fileURLToPath(import.meta.url);
6
8
  const __dirname = path.dirname(__filename);
7
9
  export function startDashboard(port, historyPath) {
@@ -43,6 +45,10 @@ export function startDashboard(port, historyPath) {
43
45
  res.end(data);
44
46
  });
45
47
  }
48
+ else if (req.url === '/api/code-quality') {
49
+ // Code Quality Dashboard API
50
+ handleCodeQualityRequest(res);
51
+ }
46
52
  else {
47
53
  res.writeHead(404);
48
54
  res.end('Not found');
@@ -65,3 +71,94 @@ export function startDashboard(port, historyPath) {
65
71
  });
66
72
  });
67
73
  }
74
+ /**
75
+ * Handle code quality dashboard API request
76
+ */
77
+ async function handleCodeQualityRequest(res) {
78
+ try {
79
+ // Find TypeScript/JavaScript files in src directory
80
+ const srcDir = path.join(process.cwd(), 'src');
81
+ const files = await findCodeFiles(srcDir);
82
+ // Analyze top 10 largest files
83
+ const fileStats = await Promise.all(files.map(async (file) => {
84
+ const stats = await fs.promises.stat(file);
85
+ return { file, size: stats.size };
86
+ }));
87
+ const largestFiles = fileStats
88
+ .sort((a, b) => b.size - a.size)
89
+ .slice(0, 10)
90
+ .map(f => f.file);
91
+ // Analyze each file
92
+ const graph = new ProjectKnowledgeGraph();
93
+ const analyzer = getIntelligentAnalyzer(graph);
94
+ const results = await Promise.all(largestFiles.map(async (file) => {
95
+ try {
96
+ const analysis = await analyzer.analyzeFile(file);
97
+ return {
98
+ file: path.relative(process.cwd(), file),
99
+ metrics: analysis.metrics,
100
+ quality: {
101
+ overall: analysis.quality.overall,
102
+ maintainability: analysis.quality.maintainability,
103
+ security: analysis.quality.security,
104
+ performance: analysis.quality.performance,
105
+ },
106
+ issueCount: analysis.quality.issues.length,
107
+ symbolCount: analysis.symbols.length,
108
+ };
109
+ }
110
+ catch (e) {
111
+ return {
112
+ file: path.relative(process.cwd(), file),
113
+ error: 'Analysis failed',
114
+ };
115
+ }
116
+ }));
117
+ // Calculate summary
118
+ const validResults = results.filter(r => !r.error);
119
+ const summary = {
120
+ totalFiles: files.length,
121
+ analyzedFiles: validResults.length,
122
+ averageComplexity: validResults.reduce((sum, r) => sum + r.metrics.complexity, 0) / validResults.length || 0,
123
+ averageMaintainability: validResults.reduce((sum, r) => sum + r.quality.maintainability, 0) / validResults.length || 0,
124
+ totalIssues: validResults.reduce((sum, r) => sum + r.issueCount, 0),
125
+ };
126
+ const response = {
127
+ summary,
128
+ files: results,
129
+ generatedAt: new Date().toISOString(),
130
+ };
131
+ res.writeHead(200, { 'Content-Type': 'application/json' });
132
+ res.end(JSON.stringify(response, null, 2));
133
+ }
134
+ catch (error) {
135
+ res.writeHead(500, { 'Content-Type': 'application/json' });
136
+ res.end(JSON.stringify({
137
+ error: 'Failed to analyze code quality',
138
+ message: error instanceof Error ? error.message : String(error),
139
+ }));
140
+ }
141
+ }
142
+ /**
143
+ * Find all code files in directory
144
+ */
145
+ async function findCodeFiles(dir) {
146
+ const files = [];
147
+ async function scan(currentDir) {
148
+ const entries = await fs.promises.readdir(currentDir, { withFileTypes: true });
149
+ for (const entry of entries) {
150
+ const fullPath = path.join(currentDir, entry.name);
151
+ if (entry.isDirectory()) {
152
+ // Skip node_modules, dist, etc.
153
+ if (!['node_modules', 'dist', '.git', 'coverage'].includes(entry.name)) {
154
+ await scan(fullPath);
155
+ }
156
+ }
157
+ else if (entry.isFile() && /\.(ts|js|tsx|jsx)$/.test(entry.name) && !entry.name.endsWith('.d.ts')) {
158
+ files.push(fullPath);
159
+ }
160
+ }
161
+ }
162
+ await scan(dir);
163
+ return files;
164
+ }
package/dist/index.js CHANGED
@@ -19,6 +19,7 @@ import { registerCodingTools } from './tools/coding.js';
19
19
  import { registerCodeDbTools } from './tools/codestore.js';
20
20
  import { registerHumanTools } from './tools/human.js';
21
21
  import { registerSportsTools } from './tools/sports.js';
22
+ import { registerIntelligentCodeTools } from './tools/intelligent-code.js';
22
23
  import { startDashboard } from './dashboard/server.js';
23
24
  const __filename = fileURLToPath(import.meta.url);
24
25
  const __dirname = dirname(__filename);
@@ -48,6 +49,7 @@ registerCodingTools(server, knowledgeGraph);
48
49
  registerCodeDbTools(server, codeDb);
49
50
  registerHumanTools(server);
50
51
  registerSportsTools(server);
52
+ registerIntelligentCodeTools(server, knowledgeGraph);
51
53
  async function runServer() {
52
54
  const transport = new StdioServerTransport();
53
55
  await server.connect(transport);
@@ -0,0 +1,157 @@
1
+ /**
2
+ * INTELLIGENT CODE MODULE
3
+ * AI-powered code analysis, semantic search, and smart refactoring
4
+ */
5
+ import ts from 'typescript';
6
+ import { ProjectKnowledgeGraph } from './graph.js';
7
+ export interface CodeMetrics {
8
+ complexity: number;
9
+ linesOfCode: number;
10
+ commentRatio: number;
11
+ functionCount: number;
12
+ maxNestingDepth: number;
13
+ duplicateCode: number;
14
+ testCoverage?: number;
15
+ }
16
+ export interface CodeQualityScore {
17
+ overall: number;
18
+ maintainability: number;
19
+ reliability: number;
20
+ security: number;
21
+ performance: number;
22
+ issues: QualityIssue[];
23
+ }
24
+ export interface QualityIssue {
25
+ type: 'error' | 'warning' | 'info';
26
+ category: 'complexity' | 'style' | 'security' | 'performance' | 'maintainability';
27
+ message: string;
28
+ line?: number;
29
+ column?: number;
30
+ severity: number;
31
+ suggestion?: string;
32
+ autoFixable: boolean;
33
+ }
34
+ export interface RefactoringSuggestion {
35
+ type: 'extract-method' | 'rename' | 'reorder' | 'simplify' | 'optimize-imports' | 'add-types';
36
+ description: string;
37
+ currentCode: string;
38
+ suggestedCode: string;
39
+ confidence: number;
40
+ impact: 'low' | 'medium' | 'high';
41
+ effort: 'quick' | 'moderate' | 'extensive';
42
+ benefits: string[];
43
+ }
44
+ export interface ImpactAnalysis {
45
+ filePath: string;
46
+ directImpacts: string[];
47
+ indirectImpacts: string[];
48
+ testFiles: string[];
49
+ riskScore: number;
50
+ breakingChanges: boolean;
51
+ estimatedReviewTime: number;
52
+ }
53
+ export interface SemanticSearchResult {
54
+ filePath: string;
55
+ relevance: number;
56
+ context: string;
57
+ matchedConcepts: string[];
58
+ codeSnippet: string;
59
+ }
60
+ export interface CodePattern {
61
+ name: string;
62
+ description: string;
63
+ examples: string[];
64
+ antiPattern?: string;
65
+ solution: string;
66
+ confidence: number;
67
+ }
68
+ export declare class IntelligentCodeAnalyzer {
69
+ private graph;
70
+ private program?;
71
+ private typeChecker?;
72
+ constructor(graph: ProjectKnowledgeGraph);
73
+ /**
74
+ * Comprehensive code analysis with metrics and quality scoring
75
+ */
76
+ analyzeFile(filePath: string): Promise<{
77
+ metrics: CodeMetrics;
78
+ quality: CodeQualityScore;
79
+ ast: ts.SourceFile | null;
80
+ symbols: SymbolAnalysis[];
81
+ }>;
82
+ private calculateMetrics;
83
+ private analyzeQuality;
84
+ private analyzeSymbols;
85
+ private analyzeFunction;
86
+ private analyzeClass;
87
+ private analyzeInterface;
88
+ private extractJSDoc;
89
+ /**
90
+ * Smart impact analysis - predicts what will be affected by changes
91
+ */
92
+ analyzeImpact(filePath: string, changeDescription?: string): Promise<ImpactAnalysis>;
93
+ private findRelatedTests;
94
+ /**
95
+ * Generate intelligent refactoring suggestions
96
+ */
97
+ suggestRefactoring(filePath: string): Promise<RefactoringSuggestion[]>;
98
+ private findLongFunctions;
99
+ private findNestedConditionals;
100
+ private findAnyUsages;
101
+ /**
102
+ * Semantic code search - find code by concept, not just text
103
+ */
104
+ semanticSearch(query: string, options?: {
105
+ filePattern?: string;
106
+ maxResults?: number;
107
+ }): Promise<SemanticSearchResult[]>;
108
+ private extractConcepts;
109
+ private calculateRelevance;
110
+ private extractRelevantSnippet;
111
+ private extractContext;
112
+ private getMatchingFiles;
113
+ /**
114
+ * Auto-fix common code issues
115
+ */
116
+ autoFix(filePath: string, options?: {
117
+ fixUnusedImports?: boolean;
118
+ fixTrailingWhitespace?: boolean;
119
+ fixMissingSemicolons?: boolean;
120
+ optimizeImports?: boolean;
121
+ dryRun?: boolean;
122
+ }): Promise<{
123
+ fixes: Array<{
124
+ type: string;
125
+ line: number;
126
+ original: string;
127
+ fixed: string;
128
+ }>;
129
+ applied: boolean;
130
+ }>;
131
+ /**
132
+ * Detect code patterns and anti-patterns
133
+ */
134
+ detectPatterns(filePath: string, sourceFile: ts.SourceFile): CodePattern[];
135
+ }
136
+ interface SymbolAnalysis {
137
+ name: string;
138
+ kind: 'function' | 'class' | 'interface' | 'method' | 'type';
139
+ params?: {
140
+ name: string;
141
+ type: string;
142
+ optional?: boolean;
143
+ }[];
144
+ returnType?: string;
145
+ isAsync?: boolean;
146
+ complexity?: number;
147
+ isExported: boolean;
148
+ documentation?: string;
149
+ methods?: SymbolAnalysis[];
150
+ properties?: {
151
+ name: string;
152
+ type: string;
153
+ optional?: boolean;
154
+ }[];
155
+ }
156
+ export declare function getIntelligentAnalyzer(graph: ProjectKnowledgeGraph): IntelligentCodeAnalyzer;
157
+ export {};