deepthinking-mcp 5.0.0 → 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 +537 -30
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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();
|
|
@@ -840,6 +843,57 @@ var init_recommendations = __esm({
|
|
|
840
843
|
*/
|
|
841
844
|
recommendModes(characteristics) {
|
|
842
845
|
const recommendations = [];
|
|
846
|
+
const isPhilosophical = characteristics.domain.toLowerCase().includes("metaphysics") || characteristics.domain.toLowerCase().includes("theology") || characteristics.domain.toLowerCase().includes("philosophy") || characteristics.domain.toLowerCase().includes("epistemology") || characteristics.domain.toLowerCase().includes("ethics");
|
|
847
|
+
if (characteristics.complexity === "high" && (characteristics.requiresExplanation || characteristics.hasAlternatives || isPhilosophical)) {
|
|
848
|
+
recommendations.push({
|
|
849
|
+
mode: "hybrid" /* HYBRID */,
|
|
850
|
+
score: 0.92,
|
|
851
|
+
reasoning: "Complex problem benefits from multi-modal synthesis combining inductive, deductive, and abductive reasoning",
|
|
852
|
+
strengths: ["Comprehensive analysis", "Combines empirical and logical approaches", "Maximum evidential strength", "Convergent validation"],
|
|
853
|
+
limitations: ["Time-intensive", "Requires understanding of multiple reasoning types"],
|
|
854
|
+
examples: ["Philosophical arguments", "Scientific theories", "Complex decision-making", "Metaphysical questions"]
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
if (!characteristics.requiresProof && (characteristics.requiresQuantification || characteristics.hasIncompleteInfo || isPhilosophical)) {
|
|
858
|
+
recommendations.push({
|
|
859
|
+
mode: "inductive" /* INDUCTIVE */,
|
|
860
|
+
score: isPhilosophical ? 0.85 : 0.8,
|
|
861
|
+
reasoning: "Problem requires pattern recognition and generalization from observations",
|
|
862
|
+
strengths: ["Empirical grounding", "Pattern detection", "Probabilistic reasoning", "Scientific discovery"],
|
|
863
|
+
limitations: ["Cannot prove with certainty", "Vulnerable to black swans", "Sample size dependent"],
|
|
864
|
+
examples: ["Scientific hypotheses", "Trend analysis", "Empirical arguments", "Data-driven insights"]
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
if (characteristics.requiresProof || isPhilosophical) {
|
|
868
|
+
recommendations.push({
|
|
869
|
+
mode: "deductive" /* DEDUCTIVE */,
|
|
870
|
+
score: characteristics.requiresProof ? 0.9 : 0.75,
|
|
871
|
+
reasoning: "Problem requires logical derivation from general principles to specific conclusions",
|
|
872
|
+
strengths: ["Logical validity", "Rigorous inference", "Exposes contradictions", "Formal reasoning"],
|
|
873
|
+
limitations: ["Soundness depends on premise truth", "Vulnerable to definitional disputes", "May not handle uncertainty well"],
|
|
874
|
+
examples: ["Logical proofs", "Mathematical theorems", "Philosophical arguments", "Formal verification"]
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
if (characteristics.requiresExplanation || isPhilosophical) {
|
|
878
|
+
recommendations.push({
|
|
879
|
+
mode: "abductive" /* ABDUCTIVE */,
|
|
880
|
+
score: isPhilosophical ? 0.9 : 0.87,
|
|
881
|
+
reasoning: "Problem requires finding best explanations through comparative hypothesis evaluation",
|
|
882
|
+
strengths: ["Hypothesis generation", "Comparative evaluation", "Explanatory power assessment", "Handles competing theories"],
|
|
883
|
+
limitations: ["May miss non-obvious explanations", "Explanatory power is subjective"],
|
|
884
|
+
examples: ["Scientific explanation", "Debugging", "Diagnosis", "Theory selection", "Metaphysical arguments"]
|
|
885
|
+
});
|
|
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
|
+
}
|
|
843
897
|
if (characteristics.timeDependent) {
|
|
844
898
|
recommendations.push({
|
|
845
899
|
mode: "temporal" /* TEMPORAL */,
|
|
@@ -860,26 +914,16 @@ var init_recommendations = __esm({
|
|
|
860
914
|
examples: ["Competitive analysis", "Auction design", "Negotiation"]
|
|
861
915
|
});
|
|
862
916
|
}
|
|
863
|
-
if (characteristics.hasIncompleteInfo && characteristics.uncertainty === "high") {
|
|
917
|
+
if (characteristics.hasIncompleteInfo && characteristics.uncertainty === "high" && !isPhilosophical) {
|
|
864
918
|
recommendations.push({
|
|
865
919
|
mode: "evidential" /* EVIDENTIAL */,
|
|
866
|
-
score: 0.
|
|
867
|
-
reasoning: "Problem has incomplete information and high uncertainty",
|
|
920
|
+
score: 0.82,
|
|
921
|
+
reasoning: "Problem has incomplete information and high uncertainty requiring Dempster-Shafer belief functions",
|
|
868
922
|
strengths: ["Handles ignorance", "Evidence combination", "Uncertainty intervals"],
|
|
869
|
-
limitations: ["Computational complexity", "Requires careful mass assignment"],
|
|
923
|
+
limitations: ["Computational complexity", "Requires careful mass assignment", "Better for sensor fusion than philosophical reasoning"],
|
|
870
924
|
examples: ["Sensor fusion", "Diagnostic reasoning", "Intelligence analysis"]
|
|
871
925
|
});
|
|
872
926
|
}
|
|
873
|
-
if (characteristics.requiresExplanation) {
|
|
874
|
-
recommendations.push({
|
|
875
|
-
mode: "abductive" /* ABDUCTIVE */,
|
|
876
|
-
score: 0.87,
|
|
877
|
-
reasoning: "Problem requires finding best explanations",
|
|
878
|
-
strengths: ["Hypothesis generation", "Root cause analysis", "Explanation quality"],
|
|
879
|
-
limitations: ["May miss non-obvious explanations"],
|
|
880
|
-
examples: ["Debugging", "Diagnosis", "Scientific discovery"]
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
927
|
if (characteristics.timeDependent && characteristics.requiresExplanation) {
|
|
884
928
|
recommendations.push({
|
|
885
929
|
mode: "causal" /* CAUSAL */,
|
|
@@ -967,6 +1011,16 @@ var init_recommendations = __esm({
|
|
|
967
1011
|
*/
|
|
968
1012
|
recommendCombinations(characteristics) {
|
|
969
1013
|
const combinations = [];
|
|
1014
|
+
const isPhilosophical = characteristics.domain.toLowerCase().includes("metaphysics") || characteristics.domain.toLowerCase().includes("theology") || characteristics.domain.toLowerCase().includes("philosophy") || characteristics.domain.toLowerCase().includes("epistemology") || characteristics.domain.toLowerCase().includes("ethics");
|
|
1015
|
+
if (isPhilosophical || characteristics.complexity === "high" && characteristics.requiresExplanation && characteristics.hasAlternatives) {
|
|
1016
|
+
combinations.push({
|
|
1017
|
+
modes: ["inductive" /* INDUCTIVE */, "deductive" /* DEDUCTIVE */, "abductive" /* ABDUCTIVE */],
|
|
1018
|
+
sequence: "hybrid",
|
|
1019
|
+
rationale: "Synthesize empirical patterns, logical derivations, and explanatory hypotheses for maximum evidential strength",
|
|
1020
|
+
benefits: ["Convergent validation from three independent methods", "Empirical grounding + logical rigor + explanatory power", "Highest achievable confidence through multi-modal synthesis", "Exposes both empirical patterns and logical contradictions"],
|
|
1021
|
+
synergies: ["Inductive patterns inform abductive hypotheses", "Deductive logic tests hypothesis validity", "Abductive explanations guide inductive search", "All three methods converge on same conclusion"]
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
970
1024
|
if (characteristics.timeDependent && characteristics.requiresExplanation) {
|
|
971
1025
|
combinations.push({
|
|
972
1026
|
modes: ["temporal" /* TEMPORAL */, "causal" /* CAUSAL */],
|
|
@@ -1012,15 +1066,6 @@ var init_recommendations = __esm({
|
|
|
1012
1066
|
synergies: ["Temporal events as game stages", "Strategies evolve over timeline"]
|
|
1013
1067
|
});
|
|
1014
1068
|
}
|
|
1015
|
-
if (characteristics.requiresExplanation && characteristics.complexity === "high") {
|
|
1016
|
-
combinations.push({
|
|
1017
|
-
modes: ["analogical" /* ANALOGICAL */, "abductive" /* ABDUCTIVE */],
|
|
1018
|
-
sequence: "parallel",
|
|
1019
|
-
rationale: "Use analogies to inspire hypotheses while systematically generating explanations",
|
|
1020
|
-
benefits: ["Creative hypothesis generation", "Cross-domain insights"],
|
|
1021
|
-
synergies: ["Analogies suggest hypotheses", "Hypotheses validated by analogical reasoning"]
|
|
1022
|
-
});
|
|
1023
|
-
}
|
|
1024
1069
|
if (characteristics.requiresProof && characteristics.complexity === "high") {
|
|
1025
1070
|
combinations.push({
|
|
1026
1071
|
modes: ["shannon" /* SHANNON */, "mathematics" /* MATHEMATICS */],
|
|
@@ -1038,8 +1083,28 @@ var init_recommendations = __esm({
|
|
|
1038
1083
|
*/
|
|
1039
1084
|
quickRecommend(problemType) {
|
|
1040
1085
|
const typeMap = {
|
|
1086
|
+
// Core reasoning modes
|
|
1087
|
+
"explanation": "abductive" /* ABDUCTIVE */,
|
|
1088
|
+
"hypothesis": "abductive" /* ABDUCTIVE */,
|
|
1089
|
+
"inference": "abductive" /* ABDUCTIVE */,
|
|
1090
|
+
"pattern": "inductive" /* INDUCTIVE */,
|
|
1091
|
+
"generalization": "inductive" /* INDUCTIVE */,
|
|
1092
|
+
"empirical": "inductive" /* INDUCTIVE */,
|
|
1093
|
+
"logic": "deductive" /* DEDUCTIVE */,
|
|
1094
|
+
"proof": "deductive" /* DEDUCTIVE */,
|
|
1095
|
+
"derivation": "deductive" /* DEDUCTIVE */,
|
|
1096
|
+
"complex": "hybrid" /* HYBRID */,
|
|
1097
|
+
"synthesis": "hybrid" /* HYBRID */,
|
|
1098
|
+
"philosophical": "hybrid" /* HYBRID */,
|
|
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 */,
|
|
1105
|
+
// Specialized modes
|
|
1041
1106
|
"debugging": "abductive" /* ABDUCTIVE */,
|
|
1042
|
-
"
|
|
1107
|
+
"mathematical": "mathematics" /* MATHEMATICS */,
|
|
1043
1108
|
"timeline": "temporal" /* TEMPORAL */,
|
|
1044
1109
|
"strategy": "gametheory" /* GAMETHEORY */,
|
|
1045
1110
|
"uncertainty": "evidential" /* EVIDENTIAL */,
|
|
@@ -1923,6 +1988,218 @@ var init_SessionMetricsCalculator = __esm({
|
|
|
1923
1988
|
};
|
|
1924
1989
|
}
|
|
1925
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
|
+
});
|
|
1926
2203
|
var DEFAULT_CONFIG2, SessionManager;
|
|
1927
2204
|
var init_manager = __esm({
|
|
1928
2205
|
"src/session/manager.ts"() {
|
|
@@ -1932,6 +2209,7 @@ var init_manager = __esm({
|
|
|
1932
2209
|
init_logger();
|
|
1933
2210
|
init_lru();
|
|
1934
2211
|
init_SessionMetricsCalculator();
|
|
2212
|
+
init_MetaMonitor();
|
|
1935
2213
|
DEFAULT_CONFIG2 = {
|
|
1936
2214
|
modeConfig: {
|
|
1937
2215
|
mode: "hybrid" /* HYBRID */,
|
|
@@ -1953,12 +2231,14 @@ var init_manager = __esm({
|
|
|
1953
2231
|
logger;
|
|
1954
2232
|
storage;
|
|
1955
2233
|
metricsCalculator;
|
|
2234
|
+
monitor;
|
|
1956
2235
|
/**
|
|
1957
2236
|
* Creates a new SessionManager instance
|
|
1958
2237
|
*
|
|
1959
2238
|
* @param config - Optional default configuration applied to all new sessions
|
|
1960
2239
|
* @param logger - Optional logger instance or log level (default: INFO level logger)
|
|
1961
2240
|
* @param storage - Optional persistent storage backend for sessions
|
|
2241
|
+
* @param monitor - Optional MetaMonitor instance for dependency injection
|
|
1962
2242
|
*
|
|
1963
2243
|
* @example
|
|
1964
2244
|
* ```typescript
|
|
@@ -1980,7 +2260,7 @@ var init_manager = __esm({
|
|
|
1980
2260
|
* const manager = new SessionManager({}, LogLevel.INFO, storage);
|
|
1981
2261
|
* ```
|
|
1982
2262
|
*/
|
|
1983
|
-
constructor(config, logger2, storage) {
|
|
2263
|
+
constructor(config, logger2, storage, monitor) {
|
|
1984
2264
|
this.activeSessions = new LRUCache({
|
|
1985
2265
|
maxSize: 1e3,
|
|
1986
2266
|
enableStats: true,
|
|
@@ -1993,10 +2273,14 @@ var init_manager = __esm({
|
|
|
1993
2273
|
this.logger.error("Failed to save evicted session", error, { sessionId: key });
|
|
1994
2274
|
}
|
|
1995
2275
|
}
|
|
2276
|
+
if (this.monitor) {
|
|
2277
|
+
this.monitor.clearSession(key);
|
|
2278
|
+
}
|
|
1996
2279
|
}
|
|
1997
2280
|
});
|
|
1998
2281
|
this.config = config || {};
|
|
1999
2282
|
this.storage = storage;
|
|
2283
|
+
this.monitor = monitor || metaMonitor;
|
|
2000
2284
|
if (logger2 && typeof logger2 === "object" && "info" in logger2) {
|
|
2001
2285
|
this.logger = logger2;
|
|
2002
2286
|
} else {
|
|
@@ -2062,6 +2346,7 @@ var init_manager = __esm({
|
|
|
2062
2346
|
this.logger.error("Failed to persist session", error, { sessionId });
|
|
2063
2347
|
}
|
|
2064
2348
|
}
|
|
2349
|
+
this.monitor.startStrategy(sessionId, session.mode);
|
|
2065
2350
|
this.logger.info("Session created", {
|
|
2066
2351
|
sessionId,
|
|
2067
2352
|
title,
|
|
@@ -2145,6 +2430,7 @@ var init_manager = __esm({
|
|
|
2145
2430
|
session.currentThoughtNumber = thought.thoughtNumber;
|
|
2146
2431
|
session.updatedAt = /* @__PURE__ */ new Date();
|
|
2147
2432
|
this.metricsCalculator.updateMetrics(session, thought);
|
|
2433
|
+
this.monitor.recordThought(sessionId, thought);
|
|
2148
2434
|
if (!thought.nextThoughtNeeded) {
|
|
2149
2435
|
session.isComplete = true;
|
|
2150
2436
|
this.logger.info("Session completed", {
|
|
@@ -2640,6 +2926,58 @@ var init_ThoughtFactory = __esm({
|
|
|
2640
2926
|
conclusion: input.conclusion || { statement: "", derivationChain: [], certainty: 0 },
|
|
2641
2927
|
alternativeInterpretations: input.alternativeInterpretations || []
|
|
2642
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
|
+
}
|
|
2643
2981
|
case "hybrid":
|
|
2644
2982
|
default:
|
|
2645
2983
|
return {
|
|
@@ -4935,6 +5273,7 @@ var ExportService;
|
|
|
4935
5273
|
var init_ExportService = __esm({
|
|
4936
5274
|
"src/services/ExportService.ts"() {
|
|
4937
5275
|
init_esm_shims();
|
|
5276
|
+
init_types();
|
|
4938
5277
|
init_visual();
|
|
4939
5278
|
init_sanitization();
|
|
4940
5279
|
init_logger();
|
|
@@ -5115,6 +5454,79 @@ ${thoughts}`;
|
|
|
5115
5454
|
md += `${thought.content}
|
|
5116
5455
|
|
|
5117
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
|
+
}
|
|
5118
5530
|
}
|
|
5119
5531
|
return md;
|
|
5120
5532
|
}
|
|
@@ -5273,27 +5685,31 @@ var init_ModeRouter = __esm({
|
|
|
5273
5685
|
init_esm_shims();
|
|
5274
5686
|
init_types();
|
|
5275
5687
|
init_logger();
|
|
5688
|
+
init_MetaMonitor();
|
|
5276
5689
|
ModeRouter = class {
|
|
5277
5690
|
sessionManager;
|
|
5278
5691
|
recommender;
|
|
5279
5692
|
logger;
|
|
5693
|
+
monitor;
|
|
5280
5694
|
/**
|
|
5281
5695
|
* Create a new ModeRouter
|
|
5282
5696
|
*
|
|
5283
5697
|
* @param sessionManager - Session manager instance for mode switching
|
|
5284
5698
|
* @param logger - Optional logger for dependency injection
|
|
5699
|
+
* @param monitor - Optional MetaMonitor instance for dependency injection
|
|
5285
5700
|
*
|
|
5286
5701
|
* @example
|
|
5287
5702
|
* ```typescript
|
|
5288
5703
|
* const router = new ModeRouter(sessionManager);
|
|
5289
5704
|
* // Or with DI:
|
|
5290
|
-
* const router = new ModeRouter(sessionManager, customLogger);
|
|
5705
|
+
* const router = new ModeRouter(sessionManager, customLogger, customMonitor);
|
|
5291
5706
|
* ```
|
|
5292
5707
|
*/
|
|
5293
|
-
constructor(sessionManager, logger2) {
|
|
5708
|
+
constructor(sessionManager, logger2, monitor) {
|
|
5294
5709
|
this.sessionManager = sessionManager;
|
|
5295
5710
|
this.recommender = new ModeRecommender();
|
|
5296
5711
|
this.logger = logger2 || createLogger({ minLevel: 1 /* INFO */, enableConsole: true });
|
|
5712
|
+
this.monitor = monitor || metaMonitor;
|
|
5297
5713
|
}
|
|
5298
5714
|
/**
|
|
5299
5715
|
* Switch a session to a new thinking mode
|
|
@@ -5454,6 +5870,96 @@ var init_ModeRouter = __esm({
|
|
|
5454
5870
|
|
|
5455
5871
|
For more detailed recommendations, provide problemCharacteristics.`;
|
|
5456
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
|
+
}
|
|
5457
5963
|
};
|
|
5458
5964
|
}
|
|
5459
5965
|
});
|
|
@@ -6172,14 +6678,14 @@ var deepthinking_strategic_schema = {
|
|
|
6172
6678
|
};
|
|
6173
6679
|
var deepthinking_analytical_schema = {
|
|
6174
6680
|
name: "deepthinking_analytical",
|
|
6175
|
-
description: "Analytical: analogical mapping, first principles",
|
|
6681
|
+
description: "Analytical: analogical mapping, first principles, meta-reasoning",
|
|
6176
6682
|
inputSchema: {
|
|
6177
6683
|
type: "object",
|
|
6178
6684
|
properties: {
|
|
6179
6685
|
...baseThoughtProperties,
|
|
6180
6686
|
mode: {
|
|
6181
6687
|
type: "string",
|
|
6182
|
-
enum: ["analogical", "firstprinciples"],
|
|
6688
|
+
enum: ["analogical", "firstprinciples", "metareasoning"],
|
|
6183
6689
|
description: "Analytical reasoning mode"
|
|
6184
6690
|
},
|
|
6185
6691
|
sourceAnalogy: {
|
|
@@ -6711,7 +7217,7 @@ var StrategicSchema = BaseThoughtSchema.extend({
|
|
|
6711
7217
|
// src/tools/schemas/modes/analytical.ts
|
|
6712
7218
|
init_esm_shims();
|
|
6713
7219
|
var AnalyticalSchema = BaseThoughtSchema.extend({
|
|
6714
|
-
mode: z.enum(["analogical", "firstprinciples"])
|
|
7220
|
+
mode: z.enum(["analogical", "firstprinciples", "metareasoning"])
|
|
6715
7221
|
});
|
|
6716
7222
|
|
|
6717
7223
|
// src/tools/schemas/modes/scientific.ts
|
|
@@ -6758,6 +7264,7 @@ var modeToToolMap = {
|
|
|
6758
7264
|
// Analytical modes
|
|
6759
7265
|
analogical: "deepthinking_analytical",
|
|
6760
7266
|
firstprinciples: "deepthinking_analytical",
|
|
7267
|
+
metareasoning: "deepthinking_analytical",
|
|
6761
7268
|
// Scientific modes
|
|
6762
7269
|
scientificmethod: "deepthinking_scientific",
|
|
6763
7270
|
systemsthinking: "deepthinking_scientific",
|