deepthinking-mcp 5.0.1 → 6.0.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.
- package/README.md +19 -5
- package/dist/index.js +466 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
[](https://modelcontextprotocol.io)
|
|
6
6
|
|
|
7
|
-
A comprehensive Model Context Protocol (MCP) server featuring **
|
|
7
|
+
A comprehensive Model Context Protocol (MCP) server featuring **21 advanced reasoning modes** including meta-reasoning for strategic oversight, with intelligent mode recommendation, taxonomy-based classification, enterprise security, and production-ready features for complex problem-solving, analysis, and decision-making.
|
|
8
8
|
|
|
9
|
-
> 📋 **Latest Release**:
|
|
9
|
+
> 📋 **Latest Release**: v6.0.0 - See [CHANGELOG](CHANGELOG.md) for updates and improvements.
|
|
10
10
|
>
|
|
11
|
-
> 🎉 **New in
|
|
11
|
+
> 🎉 **New in v6.0.0**: Meta-Reasoning mode for strategic oversight! Monitor reasoning effectiveness, get adaptive mode-switching recommendations, and assess quality metrics across 6 dimensions.
|
|
12
12
|
|
|
13
13
|
## Table of Contents
|
|
14
14
|
|
|
@@ -24,10 +24,12 @@ A comprehensive Model Context Protocol (MCP) server featuring **18 advanced reas
|
|
|
24
24
|
|
|
25
25
|
## Features
|
|
26
26
|
|
|
27
|
-
- **
|
|
27
|
+
- **21 Specialized Reasoning Modes** - From sequential thinking to game theory, formal logic, and meta-reasoning
|
|
28
|
+
- **Meta-Reasoning (NEW!)** - Strategic oversight that monitors effectiveness, recommends mode switches, and assesses quality
|
|
29
|
+
- **Adaptive Mode Switching** - Automatic evaluation-based mode switching when effectiveness drops below thresholds
|
|
28
30
|
- **Intelligent Mode Recommendation** - Automatic mode selection based on problem characteristics
|
|
29
31
|
- **Taxonomy Classifier** - 110+ reasoning types across 12 categories for intelligent task classification
|
|
30
|
-
- **Visual Exports** - Generate Mermaid diagrams, DOT graphs, ASCII art, and LaTeX documents
|
|
32
|
+
- **Visual Exports** - Generate Mermaid diagrams, DOT graphs, ASCII art, and LaTeX documents with meta-insights
|
|
31
33
|
- **Production-Ready** - Search engine, templates, batch processing, caching, backup/restore
|
|
32
34
|
- **Enterprise Security** - Input validation (Zod), rate limiting, path sanitization, PII redaction
|
|
33
35
|
- **High Performance** - LRU caching with auto-eviction, async I/O, 4-5x validation speedups
|
|
@@ -225,6 +227,18 @@ mode: 'first-principles'
|
|
|
225
227
|
// Use for: Fundamental analysis, conceptual understanding, basic truths
|
|
226
228
|
```
|
|
227
229
|
|
|
230
|
+
#### Meta-Reasoning ⭐ NEW
|
|
231
|
+
Strategic oversight of reasoning process - monitors effectiveness, recommends mode switches, assesses quality.
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
mode: 'metareasoning'
|
|
235
|
+
// Use for: Strategy evaluation, adaptive mode switching, quality assessment
|
|
236
|
+
// Metrics: Effectiveness, Efficiency, Confidence, Quality (6 dimensions)
|
|
237
|
+
// Auto-switches at effectiveness < 0.3
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
See [full documentation](docs/modes/METAREASONING.md) for detailed usage.
|
|
241
|
+
|
|
228
242
|
#### Systems Thinking
|
|
229
243
|
Holistic analysis of complex systems, feedback loops, and emergence.
|
|
230
244
|
|
package/dist/index.js
CHANGED
|
@@ -815,6 +815,9 @@ function isGameTheoryThought(thought) {
|
|
|
815
815
|
function isEvidentialThought(thought) {
|
|
816
816
|
return thought.mode === "evidential" /* EVIDENTIAL */;
|
|
817
817
|
}
|
|
818
|
+
function isMetaReasoningThought(thought) {
|
|
819
|
+
return thought.mode === "metareasoning" /* METAREASONING */;
|
|
820
|
+
}
|
|
818
821
|
var init_core = __esm({
|
|
819
822
|
"src/types/core.ts"() {
|
|
820
823
|
init_esm_shims();
|
|
@@ -881,6 +884,16 @@ var init_recommendations = __esm({
|
|
|
881
884
|
examples: ["Scientific explanation", "Debugging", "Diagnosis", "Theory selection", "Metaphysical arguments"]
|
|
882
885
|
});
|
|
883
886
|
}
|
|
887
|
+
if (characteristics.complexity === "high" || characteristics.hasAlternatives && characteristics.uncertainty === "high") {
|
|
888
|
+
recommendations.push({
|
|
889
|
+
mode: "metareasoning" /* METAREASONING */,
|
|
890
|
+
score: characteristics.complexity === "high" ? 0.88 : 0.82,
|
|
891
|
+
reasoning: "Complex or uncertain problems benefit from strategic monitoring and adaptive reasoning",
|
|
892
|
+
strengths: ["Strategy evaluation", "Mode switching recommendations", "Quality monitoring", "Resource allocation", "Self-reflection"],
|
|
893
|
+
limitations: ["Meta-level overhead", "Requires understanding of other modes", "May not directly solve the problem"],
|
|
894
|
+
examples: ["Strategy selection", "Debugging stuck reasoning", "Quality assessment", "Adaptive problem-solving"]
|
|
895
|
+
});
|
|
896
|
+
}
|
|
884
897
|
if (characteristics.timeDependent) {
|
|
885
898
|
recommendations.push({
|
|
886
899
|
mode: "temporal" /* TEMPORAL */,
|
|
@@ -1084,6 +1097,11 @@ var init_recommendations = __esm({
|
|
|
1084
1097
|
"synthesis": "hybrid" /* HYBRID */,
|
|
1085
1098
|
"philosophical": "hybrid" /* HYBRID */,
|
|
1086
1099
|
"metaphysical": "hybrid" /* HYBRID */,
|
|
1100
|
+
// Meta-reasoning
|
|
1101
|
+
"meta": "metareasoning" /* METAREASONING */,
|
|
1102
|
+
"strategy-selection": "metareasoning" /* METAREASONING */,
|
|
1103
|
+
"quality-assessment": "metareasoning" /* METAREASONING */,
|
|
1104
|
+
"reflection": "metareasoning" /* METAREASONING */,
|
|
1087
1105
|
// Specialized modes
|
|
1088
1106
|
"debugging": "abductive" /* ABDUCTIVE */,
|
|
1089
1107
|
"mathematical": "mathematics" /* MATHEMATICS */,
|
|
@@ -1970,6 +1988,218 @@ var init_SessionMetricsCalculator = __esm({
|
|
|
1970
1988
|
};
|
|
1971
1989
|
}
|
|
1972
1990
|
});
|
|
1991
|
+
|
|
1992
|
+
// src/services/MetaMonitor.ts
|
|
1993
|
+
var MetaMonitor, metaMonitor;
|
|
1994
|
+
var init_MetaMonitor = __esm({
|
|
1995
|
+
"src/services/MetaMonitor.ts"() {
|
|
1996
|
+
init_esm_shims();
|
|
1997
|
+
MetaMonitor = class {
|
|
1998
|
+
sessionHistory = /* @__PURE__ */ new Map();
|
|
1999
|
+
currentStrategies = /* @__PURE__ */ new Map();
|
|
2000
|
+
modeTransitions = /* @__PURE__ */ new Map();
|
|
2001
|
+
/**
|
|
2002
|
+
* Record a thought in session history
|
|
2003
|
+
*/
|
|
2004
|
+
recordThought(sessionId, thought) {
|
|
2005
|
+
if (!this.sessionHistory.has(sessionId)) {
|
|
2006
|
+
this.sessionHistory.set(sessionId, []);
|
|
2007
|
+
}
|
|
2008
|
+
const history = this.sessionHistory.get(sessionId);
|
|
2009
|
+
history.push({
|
|
2010
|
+
thoughtId: thought.id,
|
|
2011
|
+
mode: thought.mode,
|
|
2012
|
+
timestamp: thought.timestamp,
|
|
2013
|
+
content: thought.content,
|
|
2014
|
+
uncertainty: "uncertainty" in thought ? thought.uncertainty : void 0
|
|
2015
|
+
});
|
|
2016
|
+
if (!this.modeTransitions.has(sessionId)) {
|
|
2017
|
+
this.modeTransitions.set(sessionId, []);
|
|
2018
|
+
}
|
|
2019
|
+
const transitions = this.modeTransitions.get(sessionId);
|
|
2020
|
+
if (transitions.length === 0 || transitions[transitions.length - 1] !== thought.mode) {
|
|
2021
|
+
transitions.push(thought.mode);
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
/**
|
|
2025
|
+
* Start tracking a new strategy
|
|
2026
|
+
*/
|
|
2027
|
+
startStrategy(sessionId, mode) {
|
|
2028
|
+
this.currentStrategies.set(sessionId, {
|
|
2029
|
+
mode,
|
|
2030
|
+
thoughtsSpent: 0,
|
|
2031
|
+
startTime: /* @__PURE__ */ new Date(),
|
|
2032
|
+
progressIndicators: [],
|
|
2033
|
+
issuesEncountered: []
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
/**
|
|
2037
|
+
* Update current strategy progress
|
|
2038
|
+
*/
|
|
2039
|
+
updateStrategyProgress(sessionId, indicator) {
|
|
2040
|
+
const strategy = this.currentStrategies.get(sessionId);
|
|
2041
|
+
if (strategy) {
|
|
2042
|
+
strategy.progressIndicators.push(indicator);
|
|
2043
|
+
strategy.thoughtsSpent++;
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
/**
|
|
2047
|
+
* Record an issue with current strategy
|
|
2048
|
+
*/
|
|
2049
|
+
recordStrategyIssue(sessionId, issue) {
|
|
2050
|
+
const strategy = this.currentStrategies.get(sessionId);
|
|
2051
|
+
if (strategy) {
|
|
2052
|
+
strategy.issuesEncountered.push(issue);
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
/**
|
|
2056
|
+
* Evaluate current strategy effectiveness
|
|
2057
|
+
*/
|
|
2058
|
+
evaluateStrategy(sessionId) {
|
|
2059
|
+
const strategy = this.currentStrategies.get(sessionId);
|
|
2060
|
+
if (!strategy) {
|
|
2061
|
+
return {
|
|
2062
|
+
effectiveness: 0.5,
|
|
2063
|
+
efficiency: 0.5,
|
|
2064
|
+
confidence: 0.5,
|
|
2065
|
+
progressRate: 0,
|
|
2066
|
+
qualityScore: 0.5,
|
|
2067
|
+
issues: ["No active strategy being tracked"],
|
|
2068
|
+
strengths: []
|
|
2069
|
+
};
|
|
2070
|
+
}
|
|
2071
|
+
const thoughtsSpent = strategy.thoughtsSpent;
|
|
2072
|
+
const progressMade = strategy.progressIndicators.length;
|
|
2073
|
+
const issuesCount = strategy.issuesEncountered.length;
|
|
2074
|
+
const timeElapsed = (/* @__PURE__ */ new Date()).getTime() - strategy.startTime.getTime();
|
|
2075
|
+
const effectiveness = Math.min(1, progressMade / Math.max(1, thoughtsSpent));
|
|
2076
|
+
const efficiency = timeElapsed > 0 ? Math.min(1, progressMade / (timeElapsed / 6e4)) : 0.5;
|
|
2077
|
+
const confidence = Math.max(0.1, 1 - issuesCount * 0.15);
|
|
2078
|
+
const progressRate = thoughtsSpent > 0 ? progressMade / thoughtsSpent : 0;
|
|
2079
|
+
const qualityScore = effectiveness * 0.4 + efficiency * 0.2 + confidence * 0.4;
|
|
2080
|
+
return {
|
|
2081
|
+
effectiveness,
|
|
2082
|
+
efficiency,
|
|
2083
|
+
confidence,
|
|
2084
|
+
progressRate,
|
|
2085
|
+
qualityScore,
|
|
2086
|
+
issues: [...strategy.issuesEncountered],
|
|
2087
|
+
strengths: strategy.progressIndicators.slice(-3)
|
|
2088
|
+
// Recent progress
|
|
2089
|
+
};
|
|
2090
|
+
}
|
|
2091
|
+
/**
|
|
2092
|
+
* Suggest alternative strategies based on current performance
|
|
2093
|
+
*/
|
|
2094
|
+
suggestAlternatives(sessionId, currentMode) {
|
|
2095
|
+
const evaluation = this.evaluateStrategy(sessionId);
|
|
2096
|
+
const alternatives = [];
|
|
2097
|
+
if (evaluation.effectiveness < 0.4) {
|
|
2098
|
+
if (currentMode !== "hybrid" /* HYBRID */) {
|
|
2099
|
+
alternatives.push({
|
|
2100
|
+
mode: "hybrid" /* HYBRID */,
|
|
2101
|
+
reasoning: "Low effectiveness detected - hybrid multi-modal approach may provide better results",
|
|
2102
|
+
expectedBenefit: "Combines multiple reasoning types for comprehensive analysis",
|
|
2103
|
+
switchingCost: 0.3,
|
|
2104
|
+
recommendationScore: 0.85
|
|
2105
|
+
});
|
|
2106
|
+
}
|
|
2107
|
+
if (currentMode !== "inductive" /* INDUCTIVE */) {
|
|
2108
|
+
alternatives.push({
|
|
2109
|
+
mode: "inductive" /* INDUCTIVE */,
|
|
2110
|
+
reasoning: "Consider gathering more empirical observations",
|
|
2111
|
+
expectedBenefit: "Build stronger generalizations from specific cases",
|
|
2112
|
+
switchingCost: 0.2,
|
|
2113
|
+
recommendationScore: 0.7
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
if (evaluation.effectiveness >= 0.4 && evaluation.efficiency < 0.5) {
|
|
2118
|
+
alternatives.push({
|
|
2119
|
+
mode: currentMode,
|
|
2120
|
+
// Same mode, but recommend refinement
|
|
2121
|
+
reasoning: "Progress detected but efficiency is low - consider refining current approach",
|
|
2122
|
+
expectedBenefit: "Improved efficiency while maintaining progress",
|
|
2123
|
+
switchingCost: 0.1,
|
|
2124
|
+
recommendationScore: 0.65
|
|
2125
|
+
});
|
|
2126
|
+
}
|
|
2127
|
+
return alternatives;
|
|
2128
|
+
}
|
|
2129
|
+
/**
|
|
2130
|
+
* Calculate quality metrics for current session
|
|
2131
|
+
*/
|
|
2132
|
+
calculateQualityMetrics(sessionId) {
|
|
2133
|
+
const history = this.sessionHistory.get(sessionId) || [];
|
|
2134
|
+
const strategy = this.currentStrategies.get(sessionId);
|
|
2135
|
+
if (history.length === 0) {
|
|
2136
|
+
return {
|
|
2137
|
+
logicalConsistency: 0.5,
|
|
2138
|
+
evidenceQuality: 0.5,
|
|
2139
|
+
completeness: 0.5,
|
|
2140
|
+
originality: 0.5,
|
|
2141
|
+
clarity: 0.5,
|
|
2142
|
+
overallQuality: 0.5
|
|
2143
|
+
};
|
|
2144
|
+
}
|
|
2145
|
+
const issuesCount = strategy?.issuesEncountered.length || 0;
|
|
2146
|
+
const logicalConsistency = Math.max(0.1, 1 - issuesCount * 0.1);
|
|
2147
|
+
const avgUncertainty = history.reduce((sum, entry) => sum + (entry.uncertainty || 0.5), 0) / history.length;
|
|
2148
|
+
const evidenceQuality = 1 - avgUncertainty;
|
|
2149
|
+
const completeness = Math.min(1, history.length / 5);
|
|
2150
|
+
const uniqueModes = new Set(history.map((h) => h.mode)).size;
|
|
2151
|
+
const originality = Math.min(1, uniqueModes / 3);
|
|
2152
|
+
const progressCount = strategy?.progressIndicators.length || 0;
|
|
2153
|
+
const clarity = Math.min(1, progressCount / Math.max(1, history.length));
|
|
2154
|
+
const overallQuality = logicalConsistency * 0.25 + evidenceQuality * 0.2 + completeness * 0.15 + originality * 0.15 + clarity * 0.25;
|
|
2155
|
+
return {
|
|
2156
|
+
logicalConsistency,
|
|
2157
|
+
evidenceQuality,
|
|
2158
|
+
completeness,
|
|
2159
|
+
originality,
|
|
2160
|
+
clarity,
|
|
2161
|
+
overallQuality
|
|
2162
|
+
};
|
|
2163
|
+
}
|
|
2164
|
+
/**
|
|
2165
|
+
* Get session context for meta-reasoning
|
|
2166
|
+
*/
|
|
2167
|
+
getSessionContext(sessionId, problemType) {
|
|
2168
|
+
const history = this.sessionHistory.get(sessionId) || [];
|
|
2169
|
+
const transitions = this.modeTransitions.get(sessionId) || [];
|
|
2170
|
+
return {
|
|
2171
|
+
sessionId,
|
|
2172
|
+
totalThoughts: history.length,
|
|
2173
|
+
modesUsed: transitions,
|
|
2174
|
+
modeSwitches: Math.max(0, transitions.length - 1),
|
|
2175
|
+
problemType,
|
|
2176
|
+
historicalEffectiveness: this.getHistoricalEffectiveness(problemType)
|
|
2177
|
+
};
|
|
2178
|
+
}
|
|
2179
|
+
/**
|
|
2180
|
+
* Get historical effectiveness for similar problems (simplified)
|
|
2181
|
+
*/
|
|
2182
|
+
getHistoricalEffectiveness(_problemType) {
|
|
2183
|
+
return void 0;
|
|
2184
|
+
}
|
|
2185
|
+
/**
|
|
2186
|
+
* Clear session data (for cleanup)
|
|
2187
|
+
*/
|
|
2188
|
+
clearSession(sessionId) {
|
|
2189
|
+
this.sessionHistory.delete(sessionId);
|
|
2190
|
+
this.currentStrategies.delete(sessionId);
|
|
2191
|
+
this.modeTransitions.delete(sessionId);
|
|
2192
|
+
}
|
|
2193
|
+
/**
|
|
2194
|
+
* Get all tracked sessions
|
|
2195
|
+
*/
|
|
2196
|
+
getActiveSessions() {
|
|
2197
|
+
return Array.from(this.sessionHistory.keys());
|
|
2198
|
+
}
|
|
2199
|
+
};
|
|
2200
|
+
metaMonitor = new MetaMonitor();
|
|
2201
|
+
}
|
|
2202
|
+
});
|
|
1973
2203
|
var DEFAULT_CONFIG2, SessionManager;
|
|
1974
2204
|
var init_manager = __esm({
|
|
1975
2205
|
"src/session/manager.ts"() {
|
|
@@ -1979,6 +2209,7 @@ var init_manager = __esm({
|
|
|
1979
2209
|
init_logger();
|
|
1980
2210
|
init_lru();
|
|
1981
2211
|
init_SessionMetricsCalculator();
|
|
2212
|
+
init_MetaMonitor();
|
|
1982
2213
|
DEFAULT_CONFIG2 = {
|
|
1983
2214
|
modeConfig: {
|
|
1984
2215
|
mode: "hybrid" /* HYBRID */,
|
|
@@ -2000,12 +2231,14 @@ var init_manager = __esm({
|
|
|
2000
2231
|
logger;
|
|
2001
2232
|
storage;
|
|
2002
2233
|
metricsCalculator;
|
|
2234
|
+
monitor;
|
|
2003
2235
|
/**
|
|
2004
2236
|
* Creates a new SessionManager instance
|
|
2005
2237
|
*
|
|
2006
2238
|
* @param config - Optional default configuration applied to all new sessions
|
|
2007
2239
|
* @param logger - Optional logger instance or log level (default: INFO level logger)
|
|
2008
2240
|
* @param storage - Optional persistent storage backend for sessions
|
|
2241
|
+
* @param monitor - Optional MetaMonitor instance for dependency injection
|
|
2009
2242
|
*
|
|
2010
2243
|
* @example
|
|
2011
2244
|
* ```typescript
|
|
@@ -2027,7 +2260,7 @@ var init_manager = __esm({
|
|
|
2027
2260
|
* const manager = new SessionManager({}, LogLevel.INFO, storage);
|
|
2028
2261
|
* ```
|
|
2029
2262
|
*/
|
|
2030
|
-
constructor(config, logger2, storage) {
|
|
2263
|
+
constructor(config, logger2, storage, monitor) {
|
|
2031
2264
|
this.activeSessions = new LRUCache({
|
|
2032
2265
|
maxSize: 1e3,
|
|
2033
2266
|
enableStats: true,
|
|
@@ -2040,10 +2273,14 @@ var init_manager = __esm({
|
|
|
2040
2273
|
this.logger.error("Failed to save evicted session", error, { sessionId: key });
|
|
2041
2274
|
}
|
|
2042
2275
|
}
|
|
2276
|
+
if (this.monitor) {
|
|
2277
|
+
this.monitor.clearSession(key);
|
|
2278
|
+
}
|
|
2043
2279
|
}
|
|
2044
2280
|
});
|
|
2045
2281
|
this.config = config || {};
|
|
2046
2282
|
this.storage = storage;
|
|
2283
|
+
this.monitor = monitor || metaMonitor;
|
|
2047
2284
|
if (logger2 && typeof logger2 === "object" && "info" in logger2) {
|
|
2048
2285
|
this.logger = logger2;
|
|
2049
2286
|
} else {
|
|
@@ -2109,6 +2346,7 @@ var init_manager = __esm({
|
|
|
2109
2346
|
this.logger.error("Failed to persist session", error, { sessionId });
|
|
2110
2347
|
}
|
|
2111
2348
|
}
|
|
2349
|
+
this.monitor.startStrategy(sessionId, session.mode);
|
|
2112
2350
|
this.logger.info("Session created", {
|
|
2113
2351
|
sessionId,
|
|
2114
2352
|
title,
|
|
@@ -2192,6 +2430,7 @@ var init_manager = __esm({
|
|
|
2192
2430
|
session.currentThoughtNumber = thought.thoughtNumber;
|
|
2193
2431
|
session.updatedAt = /* @__PURE__ */ new Date();
|
|
2194
2432
|
this.metricsCalculator.updateMetrics(session, thought);
|
|
2433
|
+
this.monitor.recordThought(sessionId, thought);
|
|
2195
2434
|
if (!thought.nextThoughtNeeded) {
|
|
2196
2435
|
session.isComplete = true;
|
|
2197
2436
|
this.logger.info("Session completed", {
|
|
@@ -2687,6 +2926,58 @@ var init_ThoughtFactory = __esm({
|
|
|
2687
2926
|
conclusion: input.conclusion || { statement: "", derivationChain: [], certainty: 0 },
|
|
2688
2927
|
alternativeInterpretations: input.alternativeInterpretations || []
|
|
2689
2928
|
};
|
|
2929
|
+
case "metareasoning": {
|
|
2930
|
+
const metaInput = input;
|
|
2931
|
+
return {
|
|
2932
|
+
...baseThought,
|
|
2933
|
+
mode: "metareasoning" /* METAREASONING */,
|
|
2934
|
+
currentStrategy: metaInput.currentStrategy || {
|
|
2935
|
+
mode: "sequential" /* SEQUENTIAL */,
|
|
2936
|
+
approach: "Default sequential approach",
|
|
2937
|
+
startedAt: /* @__PURE__ */ new Date(),
|
|
2938
|
+
thoughtsSpent: 0,
|
|
2939
|
+
progressIndicators: []
|
|
2940
|
+
},
|
|
2941
|
+
strategyEvaluation: metaInput.strategyEvaluation || {
|
|
2942
|
+
effectiveness: 0.5,
|
|
2943
|
+
efficiency: 0.5,
|
|
2944
|
+
confidence: 0.5,
|
|
2945
|
+
progressRate: 0,
|
|
2946
|
+
qualityScore: 0.5,
|
|
2947
|
+
issues: [],
|
|
2948
|
+
strengths: []
|
|
2949
|
+
},
|
|
2950
|
+
alternativeStrategies: metaInput.alternativeStrategies || [],
|
|
2951
|
+
recommendation: metaInput.recommendation || {
|
|
2952
|
+
action: "CONTINUE",
|
|
2953
|
+
justification: "No specific recommendation yet",
|
|
2954
|
+
confidence: 0.5,
|
|
2955
|
+
expectedImprovement: "Monitor progress"
|
|
2956
|
+
},
|
|
2957
|
+
resourceAllocation: metaInput.resourceAllocation || {
|
|
2958
|
+
timeSpent: 0,
|
|
2959
|
+
thoughtsRemaining: input.totalThoughts - input.thoughtNumber,
|
|
2960
|
+
complexityLevel: "medium",
|
|
2961
|
+
urgency: "medium",
|
|
2962
|
+
recommendation: "Continue with current approach"
|
|
2963
|
+
},
|
|
2964
|
+
qualityMetrics: metaInput.qualityMetrics || {
|
|
2965
|
+
logicalConsistency: 0.5,
|
|
2966
|
+
evidenceQuality: 0.5,
|
|
2967
|
+
completeness: 0.5,
|
|
2968
|
+
originality: 0.5,
|
|
2969
|
+
clarity: 0.5,
|
|
2970
|
+
overallQuality: 0.5
|
|
2971
|
+
},
|
|
2972
|
+
sessionContext: metaInput.sessionContext || {
|
|
2973
|
+
sessionId,
|
|
2974
|
+
totalThoughts: input.thoughtNumber,
|
|
2975
|
+
modesUsed: [input.mode],
|
|
2976
|
+
modeSwitches: 0,
|
|
2977
|
+
problemType: "general"
|
|
2978
|
+
}
|
|
2979
|
+
};
|
|
2980
|
+
}
|
|
2690
2981
|
case "hybrid":
|
|
2691
2982
|
default:
|
|
2692
2983
|
return {
|
|
@@ -4982,6 +5273,7 @@ var ExportService;
|
|
|
4982
5273
|
var init_ExportService = __esm({
|
|
4983
5274
|
"src/services/ExportService.ts"() {
|
|
4984
5275
|
init_esm_shims();
|
|
5276
|
+
init_types();
|
|
4985
5277
|
init_visual();
|
|
4986
5278
|
init_sanitization();
|
|
4987
5279
|
init_logger();
|
|
@@ -5162,6 +5454,79 @@ ${thoughts}`;
|
|
|
5162
5454
|
md += `${thought.content}
|
|
5163
5455
|
|
|
5164
5456
|
`;
|
|
5457
|
+
if (isMetaReasoningThought(thought)) {
|
|
5458
|
+
md += `#### \u{1F4CA} Meta-Reasoning Analysis
|
|
5459
|
+
|
|
5460
|
+
`;
|
|
5461
|
+
md += `**Current Strategy:**
|
|
5462
|
+
`;
|
|
5463
|
+
md += `- Mode: ${thought.currentStrategy.mode}
|
|
5464
|
+
`;
|
|
5465
|
+
md += `- Approach: ${thought.currentStrategy.approach}
|
|
5466
|
+
`;
|
|
5467
|
+
md += `- Thoughts Spent: ${thought.currentStrategy.thoughtsSpent}
|
|
5468
|
+
`;
|
|
5469
|
+
if (thought.currentStrategy.progressIndicators.length > 0) {
|
|
5470
|
+
md += `- Progress: ${thought.currentStrategy.progressIndicators.join(", ")}
|
|
5471
|
+
`;
|
|
5472
|
+
}
|
|
5473
|
+
md += `
|
|
5474
|
+
`;
|
|
5475
|
+
md += `**Strategy Evaluation:**
|
|
5476
|
+
`;
|
|
5477
|
+
md += `- Effectiveness: ${(thought.strategyEvaluation.effectiveness * 100).toFixed(1)}%
|
|
5478
|
+
`;
|
|
5479
|
+
md += `- Efficiency: ${(thought.strategyEvaluation.efficiency * 100).toFixed(1)}%
|
|
5480
|
+
`;
|
|
5481
|
+
md += `- Confidence: ${(thought.strategyEvaluation.confidence * 100).toFixed(1)}%
|
|
5482
|
+
`;
|
|
5483
|
+
md += `- Quality Score: ${(thought.strategyEvaluation.qualityScore * 100).toFixed(1)}%
|
|
5484
|
+
`;
|
|
5485
|
+
if (thought.strategyEvaluation.issues.length > 0) {
|
|
5486
|
+
md += `- Issues: ${thought.strategyEvaluation.issues.join("; ")}
|
|
5487
|
+
`;
|
|
5488
|
+
}
|
|
5489
|
+
if (thought.strategyEvaluation.strengths.length > 0) {
|
|
5490
|
+
md += `- Strengths: ${thought.strategyEvaluation.strengths.join("; ")}
|
|
5491
|
+
`;
|
|
5492
|
+
}
|
|
5493
|
+
md += `
|
|
5494
|
+
`;
|
|
5495
|
+
md += `**Recommendation:** ${thought.recommendation.action}
|
|
5496
|
+
`;
|
|
5497
|
+
md += `- ${thought.recommendation.justification}
|
|
5498
|
+
`;
|
|
5499
|
+
md += `- Confidence: ${(thought.recommendation.confidence * 100).toFixed(1)}%
|
|
5500
|
+
`;
|
|
5501
|
+
md += `- Expected Improvement: ${thought.recommendation.expectedImprovement}
|
|
5502
|
+
`;
|
|
5503
|
+
if (thought.alternativeStrategies.length > 0) {
|
|
5504
|
+
md += `
|
|
5505
|
+
**Alternative Strategies:**
|
|
5506
|
+
`;
|
|
5507
|
+
for (const alt of thought.alternativeStrategies) {
|
|
5508
|
+
md += `- **${alt.mode}** (score: ${(alt.recommendationScore * 100).toFixed(0)}%): ${alt.reasoning}
|
|
5509
|
+
`;
|
|
5510
|
+
}
|
|
5511
|
+
}
|
|
5512
|
+
md += `
|
|
5513
|
+
**Quality Metrics:**
|
|
5514
|
+
`;
|
|
5515
|
+
md += `- Logical Consistency: ${(thought.qualityMetrics.logicalConsistency * 100).toFixed(1)}%
|
|
5516
|
+
`;
|
|
5517
|
+
md += `- Evidence Quality: ${(thought.qualityMetrics.evidenceQuality * 100).toFixed(1)}%
|
|
5518
|
+
`;
|
|
5519
|
+
md += `- Completeness: ${(thought.qualityMetrics.completeness * 100).toFixed(1)}%
|
|
5520
|
+
`;
|
|
5521
|
+
md += `- Originality: ${(thought.qualityMetrics.originality * 100).toFixed(1)}%
|
|
5522
|
+
`;
|
|
5523
|
+
md += `- Clarity: ${(thought.qualityMetrics.clarity * 100).toFixed(1)}%
|
|
5524
|
+
`;
|
|
5525
|
+
md += `- Overall Quality: ${(thought.qualityMetrics.overallQuality * 100).toFixed(1)}%
|
|
5526
|
+
`;
|
|
5527
|
+
md += `
|
|
5528
|
+
`;
|
|
5529
|
+
}
|
|
5165
5530
|
}
|
|
5166
5531
|
return md;
|
|
5167
5532
|
}
|
|
@@ -5320,27 +5685,31 @@ var init_ModeRouter = __esm({
|
|
|
5320
5685
|
init_esm_shims();
|
|
5321
5686
|
init_types();
|
|
5322
5687
|
init_logger();
|
|
5688
|
+
init_MetaMonitor();
|
|
5323
5689
|
ModeRouter = class {
|
|
5324
5690
|
sessionManager;
|
|
5325
5691
|
recommender;
|
|
5326
5692
|
logger;
|
|
5693
|
+
monitor;
|
|
5327
5694
|
/**
|
|
5328
5695
|
* Create a new ModeRouter
|
|
5329
5696
|
*
|
|
5330
5697
|
* @param sessionManager - Session manager instance for mode switching
|
|
5331
5698
|
* @param logger - Optional logger for dependency injection
|
|
5699
|
+
* @param monitor - Optional MetaMonitor instance for dependency injection
|
|
5332
5700
|
*
|
|
5333
5701
|
* @example
|
|
5334
5702
|
* ```typescript
|
|
5335
5703
|
* const router = new ModeRouter(sessionManager);
|
|
5336
5704
|
* // Or with DI:
|
|
5337
|
-
* const router = new ModeRouter(sessionManager, customLogger);
|
|
5705
|
+
* const router = new ModeRouter(sessionManager, customLogger, customMonitor);
|
|
5338
5706
|
* ```
|
|
5339
5707
|
*/
|
|
5340
|
-
constructor(sessionManager, logger2) {
|
|
5708
|
+
constructor(sessionManager, logger2, monitor) {
|
|
5341
5709
|
this.sessionManager = sessionManager;
|
|
5342
5710
|
this.recommender = new ModeRecommender();
|
|
5343
5711
|
this.logger = logger2 || createLogger({ minLevel: 1 /* INFO */, enableConsole: true });
|
|
5712
|
+
this.monitor = monitor || metaMonitor;
|
|
5344
5713
|
}
|
|
5345
5714
|
/**
|
|
5346
5715
|
* Switch a session to a new thinking mode
|
|
@@ -5501,6 +5870,96 @@ var init_ModeRouter = __esm({
|
|
|
5501
5870
|
|
|
5502
5871
|
For more detailed recommendations, provide problemCharacteristics.`;
|
|
5503
5872
|
}
|
|
5873
|
+
/**
|
|
5874
|
+
* Evaluate current session and suggest mode switch if beneficial
|
|
5875
|
+
*
|
|
5876
|
+
* Uses meta-reasoning to evaluate the current strategy effectiveness
|
|
5877
|
+
* and suggest alternative modes if the current approach is suboptimal.
|
|
5878
|
+
*
|
|
5879
|
+
* @param sessionId - Session to evaluate
|
|
5880
|
+
* @param problemType - Optional problem type for context
|
|
5881
|
+
* @returns Evaluation result with switch recommendation
|
|
5882
|
+
*
|
|
5883
|
+
* @example
|
|
5884
|
+
* ```typescript
|
|
5885
|
+
* const evaluation = await router.evaluateAndSuggestSwitch('session-123', 'debugging');
|
|
5886
|
+
* if (evaluation.shouldSwitch) {
|
|
5887
|
+
* await router.switchMode(sessionId, evaluation.suggestedMode!, evaluation.reasoning);
|
|
5888
|
+
* }
|
|
5889
|
+
* ```
|
|
5890
|
+
*/
|
|
5891
|
+
async evaluateAndSuggestSwitch(sessionId, problemType = "general") {
|
|
5892
|
+
this.logger.debug("Evaluating session for potential mode switch", { sessionId, problemType });
|
|
5893
|
+
const evaluation = this.monitor.evaluateStrategy(sessionId);
|
|
5894
|
+
const session = await this.sessionManager.getSession(sessionId);
|
|
5895
|
+
const currentMode = session?.mode || "sequential" /* SEQUENTIAL */;
|
|
5896
|
+
const alternatives = this.monitor.suggestAlternatives(sessionId, currentMode);
|
|
5897
|
+
const shouldSwitch = evaluation.effectiveness < 0.4 || evaluation.effectiveness < 0.6 && alternatives.length > 0 && alternatives[0].recommendationScore > 0.75;
|
|
5898
|
+
const suggestedMode = shouldSwitch && alternatives.length > 0 ? alternatives[0].mode : void 0;
|
|
5899
|
+
const reasoning = shouldSwitch ? `Current strategy effectiveness: ${(evaluation.effectiveness * 100).toFixed(1)}%. ${alternatives[0]?.reasoning || "Consider switching modes."}` : `Current strategy performing adequately (effectiveness: ${(evaluation.effectiveness * 100).toFixed(1)}%). Continue with current mode.`;
|
|
5900
|
+
this.logger.debug("Mode switch evaluation completed", {
|
|
5901
|
+
sessionId,
|
|
5902
|
+
shouldSwitch,
|
|
5903
|
+
suggestedMode,
|
|
5904
|
+
currentEffectiveness: evaluation.effectiveness
|
|
5905
|
+
});
|
|
5906
|
+
return {
|
|
5907
|
+
currentEvaluation: evaluation,
|
|
5908
|
+
shouldSwitch,
|
|
5909
|
+
suggestedMode,
|
|
5910
|
+
reasoning,
|
|
5911
|
+
alternatives
|
|
5912
|
+
};
|
|
5913
|
+
}
|
|
5914
|
+
/**
|
|
5915
|
+
* Auto-switch mode if current strategy is failing
|
|
5916
|
+
*
|
|
5917
|
+
* Automatically evaluates and switches modes if the current approach
|
|
5918
|
+
* is demonstrably ineffective (effectiveness < 0.3).
|
|
5919
|
+
*
|
|
5920
|
+
* @param sessionId - Session to evaluate
|
|
5921
|
+
* @param problemType - Optional problem type for context
|
|
5922
|
+
* @returns Switch result with details
|
|
5923
|
+
*
|
|
5924
|
+
* @example
|
|
5925
|
+
* ```typescript
|
|
5926
|
+
* const result = await router.autoSwitchIfNeeded('session-123', 'complex-problem');
|
|
5927
|
+
* console.log(result.switched ? 'Switched to' + result.newMode : 'No switch needed');
|
|
5928
|
+
* ```
|
|
5929
|
+
*/
|
|
5930
|
+
async autoSwitchIfNeeded(sessionId, problemType = "general") {
|
|
5931
|
+
this.logger.debug("Auto-switch evaluation", { sessionId, problemType });
|
|
5932
|
+
const evaluation = await this.evaluateAndSuggestSwitch(sessionId, problemType);
|
|
5933
|
+
const autoSwitchThreshold = 0.3;
|
|
5934
|
+
if (evaluation.currentEvaluation.effectiveness < autoSwitchThreshold && evaluation.suggestedMode) {
|
|
5935
|
+
const session = await this.sessionManager.getSession(sessionId);
|
|
5936
|
+
const oldMode = session?.mode || "sequential" /* SEQUENTIAL */;
|
|
5937
|
+
await this.switchMode(sessionId, evaluation.suggestedMode, evaluation.reasoning);
|
|
5938
|
+
this.logger.info("Auto-switched mode due to low effectiveness", {
|
|
5939
|
+
sessionId,
|
|
5940
|
+
oldMode,
|
|
5941
|
+
newMode: evaluation.suggestedMode,
|
|
5942
|
+
effectiveness: evaluation.currentEvaluation.effectiveness
|
|
5943
|
+
});
|
|
5944
|
+
return {
|
|
5945
|
+
switched: true,
|
|
5946
|
+
oldMode,
|
|
5947
|
+
newMode: evaluation.suggestedMode,
|
|
5948
|
+
reasoning: evaluation.reasoning,
|
|
5949
|
+
evaluation: evaluation.currentEvaluation
|
|
5950
|
+
};
|
|
5951
|
+
}
|
|
5952
|
+
this.logger.debug("Auto-switch not needed", {
|
|
5953
|
+
sessionId,
|
|
5954
|
+
effectiveness: evaluation.currentEvaluation.effectiveness,
|
|
5955
|
+
threshold: autoSwitchThreshold
|
|
5956
|
+
});
|
|
5957
|
+
return {
|
|
5958
|
+
switched: false,
|
|
5959
|
+
reasoning: evaluation.reasoning,
|
|
5960
|
+
evaluation: evaluation.currentEvaluation
|
|
5961
|
+
};
|
|
5962
|
+
}
|
|
5504
5963
|
};
|
|
5505
5964
|
}
|
|
5506
5965
|
});
|
|
@@ -6219,14 +6678,14 @@ var deepthinking_strategic_schema = {
|
|
|
6219
6678
|
};
|
|
6220
6679
|
var deepthinking_analytical_schema = {
|
|
6221
6680
|
name: "deepthinking_analytical",
|
|
6222
|
-
description: "Analytical: analogical mapping, first principles",
|
|
6681
|
+
description: "Analytical: analogical mapping, first principles, meta-reasoning",
|
|
6223
6682
|
inputSchema: {
|
|
6224
6683
|
type: "object",
|
|
6225
6684
|
properties: {
|
|
6226
6685
|
...baseThoughtProperties,
|
|
6227
6686
|
mode: {
|
|
6228
6687
|
type: "string",
|
|
6229
|
-
enum: ["analogical", "firstprinciples"],
|
|
6688
|
+
enum: ["analogical", "firstprinciples", "metareasoning"],
|
|
6230
6689
|
description: "Analytical reasoning mode"
|
|
6231
6690
|
},
|
|
6232
6691
|
sourceAnalogy: {
|
|
@@ -6758,7 +7217,7 @@ var StrategicSchema = BaseThoughtSchema.extend({
|
|
|
6758
7217
|
// src/tools/schemas/modes/analytical.ts
|
|
6759
7218
|
init_esm_shims();
|
|
6760
7219
|
var AnalyticalSchema = BaseThoughtSchema.extend({
|
|
6761
|
-
mode: z.enum(["analogical", "firstprinciples"])
|
|
7220
|
+
mode: z.enum(["analogical", "firstprinciples", "metareasoning"])
|
|
6762
7221
|
});
|
|
6763
7222
|
|
|
6764
7223
|
// src/tools/schemas/modes/scientific.ts
|
|
@@ -6805,6 +7264,7 @@ var modeToToolMap = {
|
|
|
6805
7264
|
// Analytical modes
|
|
6806
7265
|
analogical: "deepthinking_analytical",
|
|
6807
7266
|
firstprinciples: "deepthinking_analytical",
|
|
7267
|
+
metareasoning: "deepthinking_analytical",
|
|
6808
7268
|
// Scientific modes
|
|
6809
7269
|
scientificmethod: "deepthinking_scientific",
|
|
6810
7270
|
systemsthinking: "deepthinking_scientific",
|