deepthinking-mcp 5.0.1 → 6.1.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/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 {
@@ -4907,90 +5198,1206 @@ var init_formal_logic = __esm({
4907
5198
  }
4908
5199
  });
4909
5200
 
4910
- // src/export/visual/index.ts
4911
- var VisualExporter;
4912
- var init_visual = __esm({
4913
- "src/export/visual/index.ts"() {
4914
- init_esm_shims();
4915
- init_causal();
4916
- init_temporal();
4917
- init_game_theory();
4918
- init_bayesian();
4919
- init_sequential();
4920
- init_shannon();
4921
- init_abductive();
4922
- init_counterfactual();
4923
- init_analogical();
4924
- init_evidential();
4925
- init_first_principles();
4926
- init_systems_thinking();
4927
- init_scientific_method();
4928
- init_optimization();
4929
- init_formal_logic();
4930
- VisualExporter = class {
4931
- exportCausalGraph(thought, options) {
4932
- return exportCausalGraph(thought, options);
4933
- }
4934
- exportTemporalTimeline(thought, options) {
4935
- return exportTemporalTimeline(thought, options);
4936
- }
4937
- exportGameTree(thought, options) {
4938
- return exportGameTree(thought, options);
4939
- }
4940
- exportBayesianNetwork(thought, options) {
4941
- return exportBayesianNetwork(thought, options);
4942
- }
4943
- exportSequentialDependencyGraph(thought, options) {
4944
- return exportSequentialDependencyGraph(thought, options);
4945
- }
4946
- exportShannonStageFlow(thought, options) {
4947
- return exportShannonStageFlow(thought, options);
4948
- }
4949
- exportAbductiveHypotheses(thought, options) {
4950
- return exportAbductiveHypotheses(thought, options);
4951
- }
4952
- exportCounterfactualScenarios(thought, options) {
4953
- return exportCounterfactualScenarios(thought, options);
4954
- }
4955
- exportAnalogicalMapping(thought, options) {
4956
- return exportAnalogicalMapping(thought, options);
4957
- }
4958
- exportEvidentialBeliefs(thought, options) {
4959
- return exportEvidentialBeliefs(thought, options);
4960
- }
4961
- exportFirstPrinciplesDerivation(thought, options) {
4962
- return exportFirstPrinciplesDerivation(thought, options);
4963
- }
4964
- exportSystemsThinkingCausalLoops(thought, options) {
4965
- return exportSystemsThinkingCausalLoops(thought, options);
4966
- }
4967
- exportScientificMethodExperiment(thought, options) {
4968
- return exportScientificMethodExperiment(thought, options);
4969
- }
4970
- exportOptimizationSolution(thought, options) {
4971
- return exportOptimizationSolution(thought, options);
4972
- }
4973
- exportFormalLogicProof(thought, options) {
4974
- return exportFormalLogicProof(thought, options);
5201
+ // src/export/visual/mathematics.ts
5202
+ function exportMathematicsDerivation(thought, options) {
5203
+ const { format, colorScheme = "default", includeLabels = true, includeMetrics = true } = options;
5204
+ switch (format) {
5205
+ case "mermaid":
5206
+ return mathematicsToMermaid(thought, colorScheme, includeLabels, includeMetrics);
5207
+ case "dot":
5208
+ return mathematicsToDOT(thought, includeLabels, includeMetrics);
5209
+ case "ascii":
5210
+ return mathematicsToASCII(thought);
5211
+ default:
5212
+ throw new Error(`Unsupported format: ${format}`);
5213
+ }
5214
+ }
5215
+ function mathematicsToMermaid(thought, colorScheme, includeLabels, includeMetrics) {
5216
+ let mermaid = "graph TB\n";
5217
+ const typeId = sanitizeId(`type_${thought.thoughtType || "proof"}`);
5218
+ const typeLabel = includeLabels ? (thought.thoughtType || "Proof").replace(/_/g, " ") : typeId;
5219
+ mermaid += ` ${typeId}[["${typeLabel}"]]
5220
+ `;
5221
+ if (thought.proofStrategy) {
5222
+ const strategyId = sanitizeId("strategy");
5223
+ const strategyLabel = thought.proofStrategy.type;
5224
+ mermaid += ` ${strategyId}(["${strategyLabel}"])
5225
+ `;
5226
+ mermaid += ` ${typeId} --> ${strategyId}
5227
+ `;
5228
+ let prevStepId = strategyId;
5229
+ thought.proofStrategy.steps.forEach((step, index) => {
5230
+ const stepId = sanitizeId(`step_${index}`);
5231
+ const stepLabel = includeLabels ? step.slice(0, 40) + (step.length > 40 ? "..." : "") : `Step ${index + 1}`;
5232
+ mermaid += ` ${stepId}["${stepLabel}"]
5233
+ `;
5234
+ mermaid += ` ${prevStepId} --> ${stepId}
5235
+ `;
5236
+ prevStepId = stepId;
5237
+ });
5238
+ if (includeMetrics) {
5239
+ const completenessId = sanitizeId("completeness");
5240
+ const completenessLabel = `Completeness: ${(thought.proofStrategy.completeness * 100).toFixed(0)}%`;
5241
+ mermaid += ` ${completenessId}{{${completenessLabel}}}
5242
+ `;
5243
+ mermaid += ` ${prevStepId} --> ${completenessId}
5244
+ `;
5245
+ }
5246
+ }
5247
+ if (thought.mathematicalModel) {
5248
+ const modelId = sanitizeId("model");
5249
+ const modelLabel = thought.mathematicalModel.symbolic || "Mathematical Model";
5250
+ mermaid += ` ${modelId}["${modelLabel}"]
5251
+ `;
5252
+ mermaid += ` ${typeId} --> ${modelId}
5253
+ `;
5254
+ }
5255
+ if (thought.theorems && thought.theorems.length > 0) {
5256
+ thought.theorems.forEach((theorem, index) => {
5257
+ const theoremId = sanitizeId(`theorem_${index}`);
5258
+ const theoremLabel = theorem.name || `Theorem ${index + 1}`;
5259
+ mermaid += ` ${theoremId}[/"${theoremLabel}"/]
5260
+ `;
5261
+ mermaid += ` ${typeId} --> ${theoremId}
5262
+ `;
5263
+ });
5264
+ }
5265
+ if (thought.assumptions && thought.assumptions.length > 0) {
5266
+ const assumptionsId = sanitizeId("assumptions");
5267
+ mermaid += ` ${assumptionsId}>"Assumptions: ${thought.assumptions.length}"]
5268
+ `;
5269
+ }
5270
+ if (colorScheme !== "monochrome") {
5271
+ const colors = colorScheme === "pastel" ? { type: "#e8f4e8", strategy: "#fff3e0"} : { type: "#90EE90", strategy: "#FFD700"};
5272
+ mermaid += `
5273
+ style ${typeId} fill:${colors.type}
5274
+ `;
5275
+ if (thought.proofStrategy) {
5276
+ mermaid += ` style ${sanitizeId("strategy")} fill:${colors.strategy}
5277
+ `;
5278
+ }
5279
+ }
5280
+ return mermaid;
5281
+ }
5282
+ function mathematicsToDOT(thought, includeLabels, includeMetrics) {
5283
+ let dot = "digraph MathematicsDerivation {\n";
5284
+ dot += " rankdir=TB;\n";
5285
+ dot += " node [shape=box, style=rounded];\n\n";
5286
+ const typeId = sanitizeId(`type_${thought.thoughtType || "proof"}`);
5287
+ const typeLabel = includeLabels ? (thought.thoughtType || "Proof").replace(/_/g, " ") : typeId;
5288
+ dot += ` ${typeId} [label="${typeLabel}", shape=doubleoctagon];
5289
+ `;
5290
+ if (thought.proofStrategy) {
5291
+ const strategyId = sanitizeId("strategy");
5292
+ dot += ` ${strategyId} [label="${thought.proofStrategy.type}", shape=ellipse];
5293
+ `;
5294
+ dot += ` ${typeId} -> ${strategyId};
5295
+ `;
5296
+ let prevStepId = strategyId;
5297
+ thought.proofStrategy.steps.forEach((step, index) => {
5298
+ const stepId = sanitizeId(`step_${index}`);
5299
+ const stepLabel = includeLabels ? step.slice(0, 30).replace(/"/g, '\\"') : `Step ${index + 1}`;
5300
+ dot += ` ${stepId} [label="${stepLabel}"];
5301
+ `;
5302
+ dot += ` ${prevStepId} -> ${stepId};
5303
+ `;
5304
+ prevStepId = stepId;
5305
+ });
5306
+ if (includeMetrics) {
5307
+ const completenessId = sanitizeId("completeness");
5308
+ dot += ` ${completenessId} [label="${(thought.proofStrategy.completeness * 100).toFixed(0)}%", shape=diamond];
5309
+ `;
5310
+ dot += ` ${prevStepId} -> ${completenessId};
5311
+ `;
5312
+ }
5313
+ }
5314
+ if (thought.theorems) {
5315
+ thought.theorems.forEach((theorem, index) => {
5316
+ const theoremId = sanitizeId(`theorem_${index}`);
5317
+ dot += ` ${theoremId} [label="${theorem.name || `Theorem ${index + 1}`}", shape=parallelogram];
5318
+ `;
5319
+ dot += ` ${typeId} -> ${theoremId};
5320
+ `;
5321
+ });
5322
+ }
5323
+ dot += "}\n";
5324
+ return dot;
5325
+ }
5326
+ function mathematicsToASCII(thought) {
5327
+ let ascii = "Mathematics Derivation:\n";
5328
+ ascii += "=======================\n\n";
5329
+ ascii += `Type: ${(thought.thoughtType || "proof").replace(/_/g, " ")}
5330
+ `;
5331
+ ascii += `Uncertainty: ${(thought.uncertainty * 100).toFixed(1)}%
5332
+
5333
+ `;
5334
+ if (thought.mathematicalModel) {
5335
+ ascii += "Mathematical Model:\n";
5336
+ ascii += ` LaTeX: ${thought.mathematicalModel.latex}
5337
+ `;
5338
+ ascii += ` Symbolic: ${thought.mathematicalModel.symbolic}
5339
+ `;
5340
+ if (thought.mathematicalModel.ascii) {
5341
+ ascii += ` ASCII: ${thought.mathematicalModel.ascii}
5342
+ `;
5343
+ }
5344
+ ascii += "\n";
5345
+ }
5346
+ if (thought.proofStrategy) {
5347
+ ascii += `Proof Strategy: ${thought.proofStrategy.type}
5348
+ `;
5349
+ ascii += `Completeness: ${(thought.proofStrategy.completeness * 100).toFixed(0)}%
5350
+ `;
5351
+ ascii += "Steps:\n";
5352
+ thought.proofStrategy.steps.forEach((step, index) => {
5353
+ ascii += ` ${index + 1}. ${step}
5354
+ `;
5355
+ });
5356
+ if (thought.proofStrategy.baseCase) {
5357
+ ascii += `Base Case: ${thought.proofStrategy.baseCase}
5358
+ `;
5359
+ }
5360
+ if (thought.proofStrategy.inductiveStep) {
5361
+ ascii += `Inductive Step: ${thought.proofStrategy.inductiveStep}
5362
+ `;
5363
+ }
5364
+ ascii += "\n";
5365
+ }
5366
+ if (thought.theorems && thought.theorems.length > 0) {
5367
+ ascii += "Theorems:\n";
5368
+ thought.theorems.forEach((theorem, index) => {
5369
+ ascii += ` [${index + 1}] ${theorem.name}: ${theorem.statement}
5370
+ `;
5371
+ if (theorem.hypotheses.length > 0) {
5372
+ ascii += ` Hypotheses: ${theorem.hypotheses.join(", ")}
5373
+ `;
4975
5374
  }
4976
- };
5375
+ ascii += ` Conclusion: ${theorem.conclusion}
5376
+ `;
5377
+ });
5378
+ ascii += "\n";
5379
+ }
5380
+ if (thought.assumptions && thought.assumptions.length > 0) {
5381
+ ascii += "Assumptions:\n";
5382
+ thought.assumptions.forEach((assumption, index) => {
5383
+ ascii += ` ${index + 1}. ${assumption}
5384
+ `;
5385
+ });
5386
+ ascii += "\n";
5387
+ }
5388
+ if (thought.dependencies && thought.dependencies.length > 0) {
5389
+ ascii += "Dependencies:\n";
5390
+ thought.dependencies.forEach((dep, index) => {
5391
+ ascii += ` ${index + 1}. ${dep}
5392
+ `;
5393
+ });
5394
+ }
5395
+ return ascii;
5396
+ }
5397
+ var init_mathematics = __esm({
5398
+ "src/export/visual/mathematics.ts"() {
5399
+ init_esm_shims();
5400
+ init_utils();
4977
5401
  }
4978
5402
  });
4979
5403
 
4980
- // src/services/ExportService.ts
4981
- var ExportService;
4982
- var init_ExportService = __esm({
4983
- "src/services/ExportService.ts"() {
4984
- init_esm_shims();
4985
- init_visual();
4986
- init_sanitization();
4987
- init_logger();
4988
- ExportService = class {
4989
- visualExporter;
4990
- logger;
4991
- constructor(logger2) {
4992
- this.visualExporter = new VisualExporter();
4993
- this.logger = logger2 || createLogger({ minLevel: 1 /* INFO */, enableConsole: true });
5404
+ // src/export/visual/physics.ts
5405
+ function exportPhysicsVisualization(thought, options) {
5406
+ const { format, colorScheme = "default", includeLabels = true, includeMetrics = true } = options;
5407
+ switch (format) {
5408
+ case "mermaid":
5409
+ return physicsToMermaid(thought, colorScheme, includeLabels, includeMetrics);
5410
+ case "dot":
5411
+ return physicsToDOT(thought, includeLabels, includeMetrics);
5412
+ case "ascii":
5413
+ return physicsToASCII(thought);
5414
+ default:
5415
+ throw new Error(`Unsupported format: ${format}`);
5416
+ }
5417
+ }
5418
+ function physicsToMermaid(thought, colorScheme, includeLabels, includeMetrics) {
5419
+ let mermaid = "graph TB\n";
5420
+ const typeId = sanitizeId(`type_${thought.thoughtType || "physics"}`);
5421
+ const typeLabel = includeLabels ? (thought.thoughtType || "Physics").replace(/_/g, " ") : typeId;
5422
+ mermaid += ` ${typeId}[["${typeLabel}"]]
5423
+ `;
5424
+ if (thought.tensorProperties) {
5425
+ const tensorId = sanitizeId("tensor");
5426
+ const rankLabel = `Rank (${thought.tensorProperties.rank[0]},${thought.tensorProperties.rank[1]})`;
5427
+ mermaid += ` ${tensorId}(["${rankLabel}"])
5428
+ `;
5429
+ mermaid += ` ${typeId} --> ${tensorId}
5430
+ `;
5431
+ const compId = sanitizeId("components");
5432
+ const compLabel = includeLabels ? thought.tensorProperties.components.slice(0, 30) + (thought.tensorProperties.components.length > 30 ? "..." : "") : "Components";
5433
+ mermaid += ` ${compId}["${compLabel}"]
5434
+ `;
5435
+ mermaid += ` ${tensorId} --> ${compId}
5436
+ `;
5437
+ if (thought.tensorProperties.symmetries.length > 0) {
5438
+ const symId = sanitizeId("symmetries");
5439
+ mermaid += ` ${symId}{{"Symmetries: ${thought.tensorProperties.symmetries.length}"}}
5440
+ `;
5441
+ mermaid += ` ${tensorId} --> ${symId}
5442
+ `;
5443
+ }
5444
+ if (thought.tensorProperties.invariants.length > 0) {
5445
+ const invId = sanitizeId("invariants");
5446
+ mermaid += ` ${invId}{{"Invariants: ${thought.tensorProperties.invariants.length}"}}
5447
+ `;
5448
+ mermaid += ` ${tensorId} --> ${invId}
5449
+ `;
5450
+ }
5451
+ }
5452
+ if (thought.physicalInterpretation) {
5453
+ const interpId = sanitizeId("interpretation");
5454
+ const interpLabel = thought.physicalInterpretation.quantity;
5455
+ mermaid += ` ${interpId}[/"${interpLabel}"/]
5456
+ `;
5457
+ mermaid += ` ${typeId} --> ${interpId}
5458
+ `;
5459
+ const unitsId = sanitizeId("units");
5460
+ mermaid += ` ${unitsId}(["${thought.physicalInterpretation.units}"])
5461
+ `;
5462
+ mermaid += ` ${interpId} --> ${unitsId}
5463
+ `;
5464
+ if (thought.physicalInterpretation.conservationLaws.length > 0) {
5465
+ thought.physicalInterpretation.conservationLaws.forEach((law, index) => {
5466
+ const lawId = sanitizeId(`conservation_${index}`);
5467
+ const lawLabel = includeLabels ? law.slice(0, 25) + (law.length > 25 ? "..." : "") : `Law ${index + 1}`;
5468
+ mermaid += ` ${lawId}>"${lawLabel}"]
5469
+ `;
5470
+ mermaid += ` ${interpId} --> ${lawId}
5471
+ `;
5472
+ });
5473
+ }
5474
+ }
5475
+ if (thought.fieldTheoryContext) {
5476
+ const fieldId = sanitizeId("field_theory");
5477
+ mermaid += ` ${fieldId}[("Field Theory")]
5478
+ `;
5479
+ mermaid += ` ${typeId} --> ${fieldId}
5480
+ `;
5481
+ thought.fieldTheoryContext.fields.forEach((field, index) => {
5482
+ const fId = sanitizeId(`field_${index}`);
5483
+ mermaid += ` ${fId}["${field}"]
5484
+ `;
5485
+ mermaid += ` ${fieldId} --> ${fId}
5486
+ `;
5487
+ });
5488
+ const symGroupId = sanitizeId("symmetry_group");
5489
+ mermaid += ` ${symGroupId}{{"${thought.fieldTheoryContext.symmetryGroup}"}}
5490
+ `;
5491
+ mermaid += ` ${fieldId} --> ${symGroupId}
5492
+ `;
5493
+ }
5494
+ if (includeMetrics) {
5495
+ const uncertId = sanitizeId("uncertainty");
5496
+ const uncertLabel = `Uncertainty: ${(thought.uncertainty * 100).toFixed(1)}%`;
5497
+ mermaid += ` ${uncertId}{{${uncertLabel}}}
5498
+ `;
5499
+ }
5500
+ if (thought.assumptions && thought.assumptions.length > 0) {
5501
+ const assumptionsId = sanitizeId("assumptions");
5502
+ mermaid += ` ${assumptionsId}>"Assumptions: ${thought.assumptions.length}"]
5503
+ `;
5504
+ }
5505
+ if (colorScheme !== "monochrome") {
5506
+ const colors = colorScheme === "pastel" ? { type: "#e3f2fd", tensor: "#fff3e0", interp: "#e8f5e9" } : { type: "#87CEEB", tensor: "#FFD700", interp: "#90EE90" };
5507
+ mermaid += `
5508
+ style ${typeId} fill:${colors.type}
5509
+ `;
5510
+ if (thought.tensorProperties) {
5511
+ mermaid += ` style ${sanitizeId("tensor")} fill:${colors.tensor}
5512
+ `;
5513
+ }
5514
+ if (thought.physicalInterpretation) {
5515
+ mermaid += ` style ${sanitizeId("interpretation")} fill:${colors.interp}
5516
+ `;
5517
+ }
5518
+ }
5519
+ return mermaid;
5520
+ }
5521
+ function physicsToDOT(thought, includeLabels, includeMetrics) {
5522
+ let dot = "digraph PhysicsVisualization {\n";
5523
+ dot += " rankdir=TB;\n";
5524
+ dot += " node [shape=box, style=rounded];\n\n";
5525
+ const typeId = sanitizeId(`type_${thought.thoughtType || "physics"}`);
5526
+ const typeLabel = includeLabels ? (thought.thoughtType || "Physics").replace(/_/g, " ") : typeId;
5527
+ dot += ` ${typeId} [label="${typeLabel}", shape=doubleoctagon];
5528
+ `;
5529
+ if (thought.tensorProperties) {
5530
+ const tensorId = sanitizeId("tensor");
5531
+ const rankLabel = `Rank (${thought.tensorProperties.rank[0]},${thought.tensorProperties.rank[1]})`;
5532
+ dot += ` ${tensorId} [label="${rankLabel}", shape=ellipse];
5533
+ `;
5534
+ dot += ` ${typeId} -> ${tensorId};
5535
+ `;
5536
+ const compId = sanitizeId("components");
5537
+ const compLabel = includeLabels ? thought.tensorProperties.components.slice(0, 25).replace(/"/g, '\\"') : "Components";
5538
+ dot += ` ${compId} [label="${compLabel}"];
5539
+ `;
5540
+ dot += ` ${tensorId} -> ${compId};
5541
+ `;
5542
+ const transId = sanitizeId("transformation");
5543
+ dot += ` ${transId} [label="${thought.tensorProperties.transformation}", shape=diamond];
5544
+ `;
5545
+ dot += ` ${tensorId} -> ${transId};
5546
+ `;
5547
+ }
5548
+ if (thought.physicalInterpretation) {
5549
+ const interpId = sanitizeId("interpretation");
5550
+ dot += ` ${interpId} [label="${thought.physicalInterpretation.quantity}", shape=parallelogram];
5551
+ `;
5552
+ dot += ` ${typeId} -> ${interpId};
5553
+ `;
5554
+ const unitsId = sanitizeId("units");
5555
+ dot += ` ${unitsId} [label="${thought.physicalInterpretation.units}", shape=ellipse];
5556
+ `;
5557
+ dot += ` ${interpId} -> ${unitsId};
5558
+ `;
5559
+ thought.physicalInterpretation.conservationLaws.forEach((law, index) => {
5560
+ const lawId = sanitizeId(`conservation_${index}`);
5561
+ const lawLabel = includeLabels ? law.slice(0, 20).replace(/"/g, '\\"') : `Law ${index + 1}`;
5562
+ dot += ` ${lawId} [label="${lawLabel}", shape=hexagon];
5563
+ `;
5564
+ dot += ` ${interpId} -> ${lawId};
5565
+ `;
5566
+ });
5567
+ }
5568
+ if (thought.fieldTheoryContext) {
5569
+ const fieldId = sanitizeId("field_theory");
5570
+ dot += ` ${fieldId} [label="Field Theory", shape=cylinder];
5571
+ `;
5572
+ dot += ` ${typeId} -> ${fieldId};
5573
+ `;
5574
+ thought.fieldTheoryContext.fields.forEach((field, index) => {
5575
+ const fId = sanitizeId(`field_${index}`);
5576
+ dot += ` ${fId} [label="${field}"];
5577
+ `;
5578
+ dot += ` ${fieldId} -> ${fId};
5579
+ `;
5580
+ });
5581
+ const symGroupId = sanitizeId("symmetry_group");
5582
+ dot += ` ${symGroupId} [label="${thought.fieldTheoryContext.symmetryGroup}", shape=diamond];
5583
+ `;
5584
+ dot += ` ${fieldId} -> ${symGroupId};
5585
+ `;
5586
+ }
5587
+ if (includeMetrics) {
5588
+ const uncertId = sanitizeId("uncertainty");
5589
+ dot += ` ${uncertId} [label="${(thought.uncertainty * 100).toFixed(1)}%", shape=diamond];
5590
+ `;
5591
+ }
5592
+ dot += "}\n";
5593
+ return dot;
5594
+ }
5595
+ function physicsToASCII(thought) {
5596
+ let ascii = "Physics Analysis:\n";
5597
+ ascii += "=================\n\n";
5598
+ ascii += `Type: ${(thought.thoughtType || "physics").replace(/_/g, " ")}
5599
+ `;
5600
+ ascii += `Uncertainty: ${(thought.uncertainty * 100).toFixed(1)}%
5601
+
5602
+ `;
5603
+ if (thought.tensorProperties) {
5604
+ ascii += "Tensor Properties:\n";
5605
+ ascii += ` Rank: (${thought.tensorProperties.rank[0]}, ${thought.tensorProperties.rank[1]})
5606
+ `;
5607
+ ascii += ` Components: ${thought.tensorProperties.components}
5608
+ `;
5609
+ ascii += ` LaTeX: ${thought.tensorProperties.latex}
5610
+ `;
5611
+ ascii += ` Transformation: ${thought.tensorProperties.transformation}
5612
+ `;
5613
+ if (thought.tensorProperties.indexStructure) {
5614
+ ascii += ` Index Structure: ${thought.tensorProperties.indexStructure}
5615
+ `;
5616
+ }
5617
+ if (thought.tensorProperties.coordinateSystem) {
5618
+ ascii += ` Coordinate System: ${thought.tensorProperties.coordinateSystem}
5619
+ `;
5620
+ }
5621
+ if (thought.tensorProperties.symmetries.length > 0) {
5622
+ ascii += " Symmetries:\n";
5623
+ thought.tensorProperties.symmetries.forEach((sym, index) => {
5624
+ ascii += ` ${index + 1}. ${sym}
5625
+ `;
5626
+ });
5627
+ }
5628
+ if (thought.tensorProperties.invariants.length > 0) {
5629
+ ascii += " Invariants:\n";
5630
+ thought.tensorProperties.invariants.forEach((inv, index) => {
5631
+ ascii += ` ${index + 1}. ${inv}
5632
+ `;
5633
+ });
5634
+ }
5635
+ ascii += "\n";
5636
+ }
5637
+ if (thought.physicalInterpretation) {
5638
+ ascii += "Physical Interpretation:\n";
5639
+ ascii += ` Quantity: ${thought.physicalInterpretation.quantity}
5640
+ `;
5641
+ ascii += ` Units: ${thought.physicalInterpretation.units}
5642
+ `;
5643
+ if (thought.physicalInterpretation.conservationLaws.length > 0) {
5644
+ ascii += " Conservation Laws:\n";
5645
+ thought.physicalInterpretation.conservationLaws.forEach((law, index) => {
5646
+ ascii += ` ${index + 1}. ${law}
5647
+ `;
5648
+ });
5649
+ }
5650
+ if (thought.physicalInterpretation.constraints && thought.physicalInterpretation.constraints.length > 0) {
5651
+ ascii += " Constraints:\n";
5652
+ thought.physicalInterpretation.constraints.forEach((constraint, index) => {
5653
+ ascii += ` ${index + 1}. ${constraint}
5654
+ `;
5655
+ });
5656
+ }
5657
+ if (thought.physicalInterpretation.observables && thought.physicalInterpretation.observables.length > 0) {
5658
+ ascii += " Observables:\n";
5659
+ thought.physicalInterpretation.observables.forEach((obs, index) => {
5660
+ ascii += ` ${index + 1}. ${obs}
5661
+ `;
5662
+ });
5663
+ }
5664
+ ascii += "\n";
5665
+ }
5666
+ if (thought.fieldTheoryContext) {
5667
+ ascii += "Field Theory Context:\n";
5668
+ ascii += ` Symmetry Group: ${thought.fieldTheoryContext.symmetryGroup}
5669
+ `;
5670
+ if (thought.fieldTheoryContext.fields.length > 0) {
5671
+ ascii += " Fields:\n";
5672
+ thought.fieldTheoryContext.fields.forEach((field, index) => {
5673
+ ascii += ` ${index + 1}. ${field}
5674
+ `;
5675
+ });
5676
+ }
5677
+ if (thought.fieldTheoryContext.interactions.length > 0) {
5678
+ ascii += " Interactions:\n";
5679
+ thought.fieldTheoryContext.interactions.forEach((interaction, index) => {
5680
+ ascii += ` ${index + 1}. ${interaction}
5681
+ `;
5682
+ });
5683
+ }
5684
+ if (thought.fieldTheoryContext.gaugeSymmetries && thought.fieldTheoryContext.gaugeSymmetries.length > 0) {
5685
+ ascii += " Gauge Symmetries:\n";
5686
+ thought.fieldTheoryContext.gaugeSymmetries.forEach((gauge, index) => {
5687
+ ascii += ` ${index + 1}. ${gauge}
5688
+ `;
5689
+ });
5690
+ }
5691
+ ascii += "\n";
5692
+ }
5693
+ if (thought.assumptions && thought.assumptions.length > 0) {
5694
+ ascii += "Assumptions:\n";
5695
+ thought.assumptions.forEach((assumption, index) => {
5696
+ ascii += ` ${index + 1}. ${assumption}
5697
+ `;
5698
+ });
5699
+ ascii += "\n";
5700
+ }
5701
+ if (thought.dependencies && thought.dependencies.length > 0) {
5702
+ ascii += "Dependencies:\n";
5703
+ thought.dependencies.forEach((dep, index) => {
5704
+ ascii += ` ${index + 1}. ${dep}
5705
+ `;
5706
+ });
5707
+ }
5708
+ return ascii;
5709
+ }
5710
+ var init_physics = __esm({
5711
+ "src/export/visual/physics.ts"() {
5712
+ init_esm_shims();
5713
+ init_utils();
5714
+ }
5715
+ });
5716
+
5717
+ // src/export/visual/hybrid.ts
5718
+ function exportHybridOrchestration(thought, options) {
5719
+ const { format, colorScheme = "default", includeLabels = true, includeMetrics = true } = options;
5720
+ switch (format) {
5721
+ case "mermaid":
5722
+ return hybridToMermaid(thought, colorScheme, includeLabels, includeMetrics);
5723
+ case "dot":
5724
+ return hybridToDOT(thought, includeLabels, includeMetrics);
5725
+ case "ascii":
5726
+ return hybridToASCII(thought);
5727
+ default:
5728
+ throw new Error(`Unsupported format: ${format}`);
5729
+ }
5730
+ }
5731
+ function hybridToMermaid(thought, colorScheme, includeLabels, includeMetrics) {
5732
+ let mermaid = "graph TB\n";
5733
+ const hybridId = sanitizeId("hybrid_mode");
5734
+ mermaid += ` ${hybridId}(("Hybrid Mode"))
5735
+ `;
5736
+ const primaryId = sanitizeId(`primary_${thought.primaryMode}`);
5737
+ const primaryLabel = includeLabels ? thought.primaryMode.charAt(0).toUpperCase() + thought.primaryMode.slice(1) : primaryId;
5738
+ mermaid += ` ${primaryId}[["${primaryLabel}"]]
5739
+ `;
5740
+ mermaid += ` ${hybridId} ==> ${primaryId}
5741
+ `;
5742
+ if (thought.secondaryFeatures && thought.secondaryFeatures.length > 0) {
5743
+ const secondaryId = sanitizeId("secondary_features");
5744
+ mermaid += ` ${secondaryId}(["Secondary Features"])
5745
+ `;
5746
+ mermaid += ` ${hybridId} --> ${secondaryId}
5747
+ `;
5748
+ thought.secondaryFeatures.forEach((feature, index) => {
5749
+ const featureId = sanitizeId(`feature_${index}`);
5750
+ const featureLabel = includeLabels ? feature.slice(0, 30) + (feature.length > 30 ? "..." : "") : `Feature ${index + 1}`;
5751
+ mermaid += ` ${featureId}["${featureLabel}"]
5752
+ `;
5753
+ mermaid += ` ${secondaryId} --> ${featureId}
5754
+ `;
5755
+ });
5756
+ }
5757
+ if (thought.switchReason) {
5758
+ const switchId = sanitizeId("switch_reason");
5759
+ const switchLabel = includeLabels ? thought.switchReason.slice(0, 40) + (thought.switchReason.length > 40 ? "..." : "") : "Switch Reason";
5760
+ mermaid += ` ${switchId}>"${switchLabel}"]
5761
+ `;
5762
+ mermaid += ` ${hybridId} -.-> ${switchId}
5763
+ `;
5764
+ }
5765
+ if (thought.stage) {
5766
+ const stageId = sanitizeId(`stage_${thought.stage}`);
5767
+ const stageLabel = thought.stage.replace(/_/g, " ");
5768
+ mermaid += ` ${stageId}{{"Stage: ${stageLabel}"}}
5769
+ `;
5770
+ mermaid += ` ${primaryId} --> ${stageId}
5771
+ `;
5772
+ }
5773
+ if (thought.mathematicalModel) {
5774
+ const modelId = sanitizeId("math_model");
5775
+ const modelLabel = thought.mathematicalModel.symbolic || "Mathematical Model";
5776
+ mermaid += ` ${modelId}["${modelLabel}"]
5777
+ `;
5778
+ mermaid += ` ${primaryId} --> ${modelId}
5779
+ `;
5780
+ }
5781
+ if (thought.tensorProperties) {
5782
+ const tensorId = sanitizeId("tensor");
5783
+ const tensorLabel = `Tensor (${thought.tensorProperties.rank[0]},${thought.tensorProperties.rank[1]})`;
5784
+ mermaid += ` ${tensorId}[/"${tensorLabel}"/]
5785
+ `;
5786
+ mermaid += ` ${primaryId} --> ${tensorId}
5787
+ `;
5788
+ }
5789
+ if (thought.physicalInterpretation) {
5790
+ const physId = sanitizeId("physical");
5791
+ mermaid += ` ${physId}[/"${thought.physicalInterpretation.quantity}"/]
5792
+ `;
5793
+ mermaid += ` ${primaryId} --> ${physId}
5794
+ `;
5795
+ }
5796
+ if (includeMetrics && thought.uncertainty !== void 0) {
5797
+ const uncertId = sanitizeId("uncertainty");
5798
+ const uncertLabel = `Uncertainty: ${(thought.uncertainty * 100).toFixed(1)}%`;
5799
+ mermaid += ` ${uncertId}{{${uncertLabel}}}
5800
+ `;
5801
+ }
5802
+ if (thought.assumptions && thought.assumptions.length > 0) {
5803
+ const assumptionsId = sanitizeId("assumptions");
5804
+ mermaid += ` ${assumptionsId}>"Assumptions: ${thought.assumptions.length}"]
5805
+ `;
5806
+ }
5807
+ if (thought.dependencies && thought.dependencies.length > 0) {
5808
+ const depsId = sanitizeId("dependencies");
5809
+ mermaid += ` ${depsId}>"Dependencies: ${thought.dependencies.length}"]
5810
+ `;
5811
+ }
5812
+ if (colorScheme !== "monochrome") {
5813
+ const colors = colorScheme === "pastel" ? { hybrid: "#e8f4e8", primary: "#e3f2fd", secondary: "#fff3e0" } : { hybrid: "#90EE90", primary: "#87CEEB", secondary: "#FFD700" };
5814
+ mermaid += `
5815
+ style ${hybridId} fill:${colors.hybrid}
5816
+ `;
5817
+ mermaid += ` style ${primaryId} fill:${colors.primary}
5818
+ `;
5819
+ if (thought.secondaryFeatures && thought.secondaryFeatures.length > 0) {
5820
+ mermaid += ` style ${sanitizeId("secondary_features")} fill:${colors.secondary}
5821
+ `;
5822
+ }
5823
+ }
5824
+ return mermaid;
5825
+ }
5826
+ function hybridToDOT(thought, includeLabels, includeMetrics) {
5827
+ let dot = "digraph HybridOrchestration {\n";
5828
+ dot += " rankdir=TB;\n";
5829
+ dot += " node [shape=box, style=rounded];\n\n";
5830
+ const hybridId = sanitizeId("hybrid_mode");
5831
+ dot += ` ${hybridId} [label="Hybrid Mode", shape=doubleoctagon];
5832
+ `;
5833
+ const primaryId = sanitizeId(`primary_${thought.primaryMode}`);
5834
+ const primaryLabel = thought.primaryMode.charAt(0).toUpperCase() + thought.primaryMode.slice(1);
5835
+ dot += ` ${primaryId} [label="${primaryLabel}", shape=box, style="filled,rounded", fillcolor=lightblue];
5836
+ `;
5837
+ dot += ` ${hybridId} -> ${primaryId} [style=bold, penwidth=2];
5838
+ `;
5839
+ if (thought.secondaryFeatures && thought.secondaryFeatures.length > 0) {
5840
+ const secondaryId = sanitizeId("secondary_features");
5841
+ dot += ` ${secondaryId} [label="Secondary Features", shape=ellipse];
5842
+ `;
5843
+ dot += ` ${hybridId} -> ${secondaryId};
5844
+ `;
5845
+ thought.secondaryFeatures.forEach((feature, index) => {
5846
+ const featureId = sanitizeId(`feature_${index}`);
5847
+ const featureLabel = includeLabels ? feature.slice(0, 25).replace(/"/g, '\\"') : `Feature ${index + 1}`;
5848
+ dot += ` ${featureId} [label="${featureLabel}"];
5849
+ `;
5850
+ dot += ` ${secondaryId} -> ${featureId};
5851
+ `;
5852
+ });
5853
+ }
5854
+ if (thought.switchReason) {
5855
+ const switchId = sanitizeId("switch_reason");
5856
+ const switchLabel = includeLabels ? thought.switchReason.slice(0, 30).replace(/"/g, '\\"') : "Switch Reason";
5857
+ dot += ` ${switchId} [label="${switchLabel}", shape=note];
5858
+ `;
5859
+ dot += ` ${hybridId} -> ${switchId} [style=dashed];
5860
+ `;
5861
+ }
5862
+ if (thought.stage) {
5863
+ const stageId = sanitizeId(`stage_${thought.stage}`);
5864
+ dot += ` ${stageId} [label="${thought.stage.replace(/_/g, " ")}", shape=diamond];
5865
+ `;
5866
+ dot += ` ${primaryId} -> ${stageId};
5867
+ `;
5868
+ }
5869
+ if (thought.mathematicalModel) {
5870
+ const modelId = sanitizeId("math_model");
5871
+ const modelLabel = thought.mathematicalModel.symbolic ? thought.mathematicalModel.symbolic.slice(0, 25).replace(/"/g, '\\"') : "Math Model";
5872
+ dot += ` ${modelId} [label="${modelLabel}", shape=parallelogram];
5873
+ `;
5874
+ dot += ` ${primaryId} -> ${modelId};
5875
+ `;
5876
+ }
5877
+ if (thought.tensorProperties) {
5878
+ const tensorId = sanitizeId("tensor");
5879
+ dot += ` ${tensorId} [label="Tensor (${thought.tensorProperties.rank[0]},${thought.tensorProperties.rank[1]})", shape=parallelogram];
5880
+ `;
5881
+ dot += ` ${primaryId} -> ${tensorId};
5882
+ `;
5883
+ }
5884
+ if (thought.physicalInterpretation) {
5885
+ const physId = sanitizeId("physical");
5886
+ dot += ` ${physId} [label="${thought.physicalInterpretation.quantity}", shape=parallelogram];
5887
+ `;
5888
+ dot += ` ${primaryId} -> ${physId};
5889
+ `;
5890
+ }
5891
+ if (includeMetrics && thought.uncertainty !== void 0) {
5892
+ const uncertId = sanitizeId("uncertainty");
5893
+ dot += ` ${uncertId} [label="${(thought.uncertainty * 100).toFixed(1)}%", shape=diamond];
5894
+ `;
5895
+ }
5896
+ dot += "}\n";
5897
+ return dot;
5898
+ }
5899
+ function hybridToASCII(thought) {
5900
+ let ascii = "Hybrid Mode Orchestration:\n";
5901
+ ascii += "==========================\n\n";
5902
+ ascii += `Primary Mode: ${thought.primaryMode.charAt(0).toUpperCase() + thought.primaryMode.slice(1)}
5903
+ `;
5904
+ if (thought.stage) {
5905
+ ascii += `Current Stage: ${thought.stage.replace(/_/g, " ")}
5906
+ `;
5907
+ }
5908
+ if (thought.uncertainty !== void 0) {
5909
+ ascii += `Uncertainty: ${(thought.uncertainty * 100).toFixed(1)}%
5910
+ `;
5911
+ }
5912
+ ascii += "\n";
5913
+ if (thought.switchReason) {
5914
+ ascii += `Switch Reason: ${thought.switchReason}
5915
+
5916
+ `;
5917
+ }
5918
+ if (thought.secondaryFeatures && thought.secondaryFeatures.length > 0) {
5919
+ ascii += "Secondary Features:\n";
5920
+ thought.secondaryFeatures.forEach((feature, index) => {
5921
+ ascii += ` ${index + 1}. ${feature}
5922
+ `;
5923
+ });
5924
+ ascii += "\n";
5925
+ }
5926
+ if (thought.mathematicalModel) {
5927
+ ascii += "Mathematical Model:\n";
5928
+ ascii += ` LaTeX: ${thought.mathematicalModel.latex}
5929
+ `;
5930
+ ascii += ` Symbolic: ${thought.mathematicalModel.symbolic}
5931
+ `;
5932
+ if (thought.mathematicalModel.ascii) {
5933
+ ascii += ` ASCII: ${thought.mathematicalModel.ascii}
5934
+ `;
5935
+ }
5936
+ ascii += "\n";
5937
+ }
5938
+ if (thought.tensorProperties) {
5939
+ ascii += "Tensor Properties:\n";
5940
+ ascii += ` Rank: (${thought.tensorProperties.rank[0]}, ${thought.tensorProperties.rank[1]})
5941
+ `;
5942
+ ascii += ` Components: ${thought.tensorProperties.components}
5943
+ `;
5944
+ ascii += ` Transformation: ${thought.tensorProperties.transformation}
5945
+ `;
5946
+ if (thought.tensorProperties.symmetries.length > 0) {
5947
+ ascii += " Symmetries:\n";
5948
+ thought.tensorProperties.symmetries.forEach((sym, index) => {
5949
+ ascii += ` ${index + 1}. ${sym}
5950
+ `;
5951
+ });
5952
+ }
5953
+ ascii += "\n";
5954
+ }
5955
+ if (thought.physicalInterpretation) {
5956
+ ascii += "Physical Interpretation:\n";
5957
+ ascii += ` Quantity: ${thought.physicalInterpretation.quantity}
5958
+ `;
5959
+ ascii += ` Units: ${thought.physicalInterpretation.units}
5960
+ `;
5961
+ if (thought.physicalInterpretation.conservationLaws.length > 0) {
5962
+ ascii += " Conservation Laws:\n";
5963
+ thought.physicalInterpretation.conservationLaws.forEach((law, index) => {
5964
+ ascii += ` ${index + 1}. ${law}
5965
+ `;
5966
+ });
5967
+ }
5968
+ ascii += "\n";
5969
+ }
5970
+ if (thought.assumptions && thought.assumptions.length > 0) {
5971
+ ascii += "Assumptions:\n";
5972
+ thought.assumptions.forEach((assumption, index) => {
5973
+ ascii += ` ${index + 1}. ${assumption}
5974
+ `;
5975
+ });
5976
+ ascii += "\n";
5977
+ }
5978
+ if (thought.dependencies && thought.dependencies.length > 0) {
5979
+ ascii += "Dependencies:\n";
5980
+ thought.dependencies.forEach((dep, index) => {
5981
+ ascii += ` ${index + 1}. ${dep}
5982
+ `;
5983
+ });
5984
+ ascii += "\n";
5985
+ }
5986
+ if (thought.revisionReason) {
5987
+ ascii += `Revision Reason: ${thought.revisionReason}
5988
+ `;
5989
+ }
5990
+ return ascii;
5991
+ }
5992
+ var init_hybrid = __esm({
5993
+ "src/export/visual/hybrid.ts"() {
5994
+ init_esm_shims();
5995
+ init_utils();
5996
+ }
5997
+ });
5998
+
5999
+ // src/export/visual/metareasoning.ts
6000
+ function exportMetaReasoningVisualization(thought, options) {
6001
+ const { format, colorScheme = "default", includeLabels = true, includeMetrics = true } = options;
6002
+ switch (format) {
6003
+ case "mermaid":
6004
+ return metaReasoningToMermaid(thought, colorScheme, includeLabels, includeMetrics);
6005
+ case "dot":
6006
+ return metaReasoningToDOT(thought, includeLabels, includeMetrics);
6007
+ case "ascii":
6008
+ return metaReasoningToASCII(thought);
6009
+ default:
6010
+ throw new Error(`Unsupported format: ${format}`);
6011
+ }
6012
+ }
6013
+ function metaReasoningToMermaid(thought, colorScheme, includeLabels, includeMetrics) {
6014
+ let mermaid = "graph TB\n";
6015
+ const metaId = sanitizeId("meta_reasoning");
6016
+ mermaid += ` ${metaId}(("Meta-Reasoning"))
6017
+ `;
6018
+ const currentId = sanitizeId("current_strategy");
6019
+ const currentLabel = includeLabels ? thought.currentStrategy.approach : "Current Strategy";
6020
+ mermaid += ` ${currentId}[["${currentLabel}"]]
6021
+ `;
6022
+ mermaid += ` ${metaId} ==> ${currentId}
6023
+ `;
6024
+ const modeId = sanitizeId("current_mode");
6025
+ mermaid += ` ${modeId}(["Mode: ${thought.currentStrategy.mode}"])
6026
+ `;
6027
+ mermaid += ` ${currentId} --> ${modeId}
6028
+ `;
6029
+ const evalId = sanitizeId("evaluation");
6030
+ mermaid += ` ${evalId}{{"Effectiveness: ${(thought.strategyEvaluation.effectiveness * 100).toFixed(0)}%"}}
6031
+ `;
6032
+ mermaid += ` ${currentId} --> ${evalId}
6033
+ `;
6034
+ if (thought.strategyEvaluation.issues.length > 0) {
6035
+ const issuesId = sanitizeId("issues");
6036
+ mermaid += ` ${issuesId}>"Issues: ${thought.strategyEvaluation.issues.length}"]
6037
+ `;
6038
+ mermaid += ` ${evalId} --> ${issuesId}
6039
+ `;
6040
+ }
6041
+ if (thought.strategyEvaluation.strengths.length > 0) {
6042
+ const strengthsId = sanitizeId("strengths");
6043
+ mermaid += ` ${strengthsId}>"Strengths: ${thought.strategyEvaluation.strengths.length}"]
6044
+ `;
6045
+ mermaid += ` ${evalId} --> ${strengthsId}
6046
+ `;
6047
+ }
6048
+ if (thought.alternativeStrategies.length > 0) {
6049
+ const altsId = sanitizeId("alternatives");
6050
+ mermaid += ` ${altsId}(["Alternative Strategies"])
6051
+ `;
6052
+ mermaid += ` ${metaId} --> ${altsId}
6053
+ `;
6054
+ thought.alternativeStrategies.forEach((alt, index) => {
6055
+ const altId = sanitizeId(`alt_${index}`);
6056
+ const altLabel = includeLabels ? `${alt.mode}: ${(alt.recommendationScore * 100).toFixed(0)}%` : `Alt ${index + 1}`;
6057
+ mermaid += ` ${altId}["${altLabel}"]
6058
+ `;
6059
+ mermaid += ` ${altsId} --> ${altId}
6060
+ `;
6061
+ });
6062
+ }
6063
+ const recId = sanitizeId("recommendation");
6064
+ const recLabel = `${thought.recommendation.action}${thought.recommendation.targetMode ? ` \u2192 ${thought.recommendation.targetMode}` : ""}`;
6065
+ mermaid += ` ${recId}[/"${recLabel}"/]
6066
+ `;
6067
+ mermaid += ` ${metaId} ==> ${recId}
6068
+ `;
6069
+ if (includeMetrics) {
6070
+ const confId = sanitizeId("rec_confidence");
6071
+ mermaid += ` ${confId}{{"Confidence: ${(thought.recommendation.confidence * 100).toFixed(0)}%"}}
6072
+ `;
6073
+ mermaid += ` ${recId} --> ${confId}
6074
+ `;
6075
+ }
6076
+ if (includeMetrics) {
6077
+ const qualityId = sanitizeId("quality");
6078
+ const qualityLabel = `Quality: ${(thought.qualityMetrics.overallQuality * 100).toFixed(0)}%`;
6079
+ mermaid += ` ${qualityId}{{"${qualityLabel}"}}
6080
+ `;
6081
+ mermaid += ` ${metaId} -.-> ${qualityId}
6082
+ `;
6083
+ }
6084
+ const resourceId = sanitizeId("resources");
6085
+ mermaid += ` ${resourceId}[("Complexity: ${thought.resourceAllocation.complexityLevel}")]
6086
+ `;
6087
+ mermaid += ` ${metaId} -.-> ${resourceId}
6088
+ `;
6089
+ const sessionId = sanitizeId("session");
6090
+ mermaid += ` ${sessionId}>"Thoughts: ${thought.sessionContext.totalThoughts}"]
6091
+ `;
6092
+ mermaid += ` ${metaId} -.-> ${sessionId}
6093
+ `;
6094
+ if (colorScheme !== "monochrome") {
6095
+ const colors = colorScheme === "pastel" ? { meta: "#f3e5f5", current: "#e3f2fd", rec: "#e8f5e9", alt: "#fff3e0" } : { meta: "#DDA0DD", current: "#87CEEB", rec: "#90EE90", alt: "#FFD700" };
6096
+ mermaid += `
6097
+ style ${metaId} fill:${colors.meta}
6098
+ `;
6099
+ mermaid += ` style ${currentId} fill:${colors.current}
6100
+ `;
6101
+ mermaid += ` style ${recId} fill:${colors.rec}
6102
+ `;
6103
+ if (thought.alternativeStrategies.length > 0) {
6104
+ mermaid += ` style ${sanitizeId("alternatives")} fill:${colors.alt}
6105
+ `;
6106
+ }
6107
+ }
6108
+ return mermaid;
6109
+ }
6110
+ function metaReasoningToDOT(thought, includeLabels, includeMetrics) {
6111
+ let dot = "digraph MetaReasoning {\n";
6112
+ dot += " rankdir=TB;\n";
6113
+ dot += " node [shape=box, style=rounded];\n\n";
6114
+ dot += " subgraph cluster_current {\n";
6115
+ dot += ' label="Current Strategy";\n';
6116
+ dot += " style=filled;\n";
6117
+ dot += " fillcolor=lightblue;\n";
6118
+ const currentId = sanitizeId("current_strategy");
6119
+ const currentLabel = includeLabels ? thought.currentStrategy.approach.slice(0, 30).replace(/"/g, '\\"') : "Current Strategy";
6120
+ dot += ` ${currentId} [label="${currentLabel}"];
6121
+ `;
6122
+ const modeId = sanitizeId("current_mode");
6123
+ dot += ` ${modeId} [label="${thought.currentStrategy.mode}", shape=ellipse];
6124
+ `;
6125
+ dot += ` ${currentId} -> ${modeId};
6126
+ `;
6127
+ if (includeMetrics) {
6128
+ const evalId = sanitizeId("evaluation");
6129
+ dot += ` ${evalId} [label="Eff: ${(thought.strategyEvaluation.effectiveness * 100).toFixed(0)}%", shape=diamond];
6130
+ `;
6131
+ dot += ` ${currentId} -> ${evalId};
6132
+ `;
6133
+ }
6134
+ dot += " }\n\n";
6135
+ if (thought.alternativeStrategies.length > 0) {
6136
+ dot += " subgraph cluster_alternatives {\n";
6137
+ dot += ' label="Alternatives";\n';
6138
+ dot += " style=filled;\n";
6139
+ dot += " fillcolor=lightyellow;\n";
6140
+ thought.alternativeStrategies.forEach((alt, index) => {
6141
+ const altId = sanitizeId(`alt_${index}`);
6142
+ const altLabel = `${alt.mode}\\n${(alt.recommendationScore * 100).toFixed(0)}%`;
6143
+ dot += ` ${altId} [label="${altLabel}"];
6144
+ `;
6145
+ });
6146
+ dot += " }\n\n";
6147
+ }
6148
+ const recId = sanitizeId("recommendation");
6149
+ const recLabel = `${thought.recommendation.action}${thought.recommendation.targetMode ? `\\n\u2192 ${thought.recommendation.targetMode}` : ""}`;
6150
+ dot += ` ${recId} [label="${recLabel}", shape=hexagon, style="filled", fillcolor=lightgreen];
6151
+ `;
6152
+ if (includeMetrics) {
6153
+ const qualityId = sanitizeId("quality");
6154
+ const qualityLabel = `Quality: ${(thought.qualityMetrics.overallQuality * 100).toFixed(0)}%`;
6155
+ dot += ` ${qualityId} [label="${qualityLabel}", shape=diamond];
6156
+ `;
6157
+ }
6158
+ dot += ` ${currentId} -> ${recId} [style=bold, penwidth=2];
6159
+ `;
6160
+ thought.alternativeStrategies.forEach((_, index) => {
6161
+ const altId = sanitizeId(`alt_${index}`);
6162
+ dot += ` ${altId} -> ${recId} [style=dashed];
6163
+ `;
6164
+ });
6165
+ dot += "}\n";
6166
+ return dot;
6167
+ }
6168
+ function metaReasoningToASCII(thought) {
6169
+ let ascii = "Meta-Reasoning Analysis:\n";
6170
+ ascii += "========================\n\n";
6171
+ ascii += "CURRENT STRATEGY\n";
6172
+ ascii += "----------------\n";
6173
+ ascii += `Mode: ${thought.currentStrategy.mode}
6174
+ `;
6175
+ ascii += `Approach: ${thought.currentStrategy.approach}
6176
+ `;
6177
+ ascii += `Thoughts Spent: ${thought.currentStrategy.thoughtsSpent}
6178
+ `;
6179
+ if (thought.currentStrategy.progressIndicators.length > 0) {
6180
+ ascii += "Progress Indicators:\n";
6181
+ thought.currentStrategy.progressIndicators.forEach((ind, index) => {
6182
+ ascii += ` ${index + 1}. ${ind}
6183
+ `;
6184
+ });
6185
+ }
6186
+ ascii += "\n";
6187
+ ascii += "STRATEGY EVALUATION\n";
6188
+ ascii += "-------------------\n";
6189
+ ascii += `Effectiveness: ${(thought.strategyEvaluation.effectiveness * 100).toFixed(1)}%
6190
+ `;
6191
+ ascii += `Efficiency: ${(thought.strategyEvaluation.efficiency * 100).toFixed(1)}%
6192
+ `;
6193
+ ascii += `Confidence: ${(thought.strategyEvaluation.confidence * 100).toFixed(1)}%
6194
+ `;
6195
+ ascii += `Progress Rate: ${thought.strategyEvaluation.progressRate.toFixed(2)} insights/thought
6196
+ `;
6197
+ ascii += `Quality Score: ${(thought.strategyEvaluation.qualityScore * 100).toFixed(1)}%
6198
+ `;
6199
+ if (thought.strategyEvaluation.strengths.length > 0) {
6200
+ ascii += "Strengths:\n";
6201
+ thought.strategyEvaluation.strengths.forEach((s, index) => {
6202
+ ascii += ` + ${index + 1}. ${s}
6203
+ `;
6204
+ });
6205
+ }
6206
+ if (thought.strategyEvaluation.issues.length > 0) {
6207
+ ascii += "Issues:\n";
6208
+ thought.strategyEvaluation.issues.forEach((issue, index) => {
6209
+ ascii += ` - ${index + 1}. ${issue}
6210
+ `;
6211
+ });
6212
+ }
6213
+ ascii += "\n";
6214
+ if (thought.alternativeStrategies.length > 0) {
6215
+ ascii += "ALTERNATIVE STRATEGIES\n";
6216
+ ascii += "----------------------\n";
6217
+ thought.alternativeStrategies.forEach((alt, index) => {
6218
+ ascii += `[${index + 1}] ${alt.mode}
6219
+ `;
6220
+ ascii += ` Reasoning: ${alt.reasoning}
6221
+ `;
6222
+ ascii += ` Expected Benefit: ${alt.expectedBenefit}
6223
+ `;
6224
+ ascii += ` Switching Cost: ${(alt.switchingCost * 100).toFixed(0)}%
6225
+ `;
6226
+ ascii += ` Recommendation Score: ${(alt.recommendationScore * 100).toFixed(0)}%
6227
+ `;
6228
+ });
6229
+ ascii += "\n";
6230
+ }
6231
+ ascii += "RECOMMENDATION\n";
6232
+ ascii += "--------------\n";
6233
+ ascii += `Action: ${thought.recommendation.action}
6234
+ `;
6235
+ if (thought.recommendation.targetMode) {
6236
+ ascii += `Target Mode: ${thought.recommendation.targetMode}
6237
+ `;
6238
+ }
6239
+ ascii += `Justification: ${thought.recommendation.justification}
6240
+ `;
6241
+ ascii += `Confidence: ${(thought.recommendation.confidence * 100).toFixed(1)}%
6242
+ `;
6243
+ ascii += `Expected Improvement: ${thought.recommendation.expectedImprovement}
6244
+ `;
6245
+ ascii += "\n";
6246
+ ascii += "RESOURCE ALLOCATION\n";
6247
+ ascii += "-------------------\n";
6248
+ ascii += `Time Spent: ${thought.resourceAllocation.timeSpent}ms
6249
+ `;
6250
+ ascii += `Thoughts Remaining: ${thought.resourceAllocation.thoughtsRemaining}
6251
+ `;
6252
+ ascii += `Complexity: ${thought.resourceAllocation.complexityLevel}
6253
+ `;
6254
+ ascii += `Urgency: ${thought.resourceAllocation.urgency}
6255
+ `;
6256
+ ascii += `Recommendation: ${thought.resourceAllocation.recommendation}
6257
+ `;
6258
+ ascii += "\n";
6259
+ ascii += "QUALITY METRICS\n";
6260
+ ascii += "---------------\n";
6261
+ ascii += `Logical Consistency: ${(thought.qualityMetrics.logicalConsistency * 100).toFixed(1)}%
6262
+ `;
6263
+ ascii += `Evidence Quality: ${(thought.qualityMetrics.evidenceQuality * 100).toFixed(1)}%
6264
+ `;
6265
+ ascii += `Completeness: ${(thought.qualityMetrics.completeness * 100).toFixed(1)}%
6266
+ `;
6267
+ ascii += `Originality: ${(thought.qualityMetrics.originality * 100).toFixed(1)}%
6268
+ `;
6269
+ ascii += `Clarity: ${(thought.qualityMetrics.clarity * 100).toFixed(1)}%
6270
+ `;
6271
+ ascii += `Overall Quality: ${(thought.qualityMetrics.overallQuality * 100).toFixed(1)}%
6272
+ `;
6273
+ ascii += "\n";
6274
+ ascii += "SESSION CONTEXT\n";
6275
+ ascii += "---------------\n";
6276
+ ascii += `Session ID: ${thought.sessionContext.sessionId}
6277
+ `;
6278
+ ascii += `Total Thoughts: ${thought.sessionContext.totalThoughts}
6279
+ `;
6280
+ ascii += `Mode Switches: ${thought.sessionContext.modeSwitches}
6281
+ `;
6282
+ ascii += `Problem Type: ${thought.sessionContext.problemType}
6283
+ `;
6284
+ ascii += `Modes Used: ${thought.sessionContext.modesUsed.join(", ")}
6285
+ `;
6286
+ if (thought.sessionContext.historicalEffectiveness !== void 0) {
6287
+ ascii += `Historical Effectiveness: ${(thought.sessionContext.historicalEffectiveness * 100).toFixed(1)}%
6288
+ `;
6289
+ }
6290
+ return ascii;
6291
+ }
6292
+ var init_metareasoning = __esm({
6293
+ "src/export/visual/metareasoning.ts"() {
6294
+ init_esm_shims();
6295
+ init_utils();
6296
+ }
6297
+ });
6298
+
6299
+ // src/export/visual/index.ts
6300
+ var VisualExporter;
6301
+ var init_visual = __esm({
6302
+ "src/export/visual/index.ts"() {
6303
+ init_esm_shims();
6304
+ init_causal();
6305
+ init_temporal();
6306
+ init_game_theory();
6307
+ init_bayesian();
6308
+ init_sequential();
6309
+ init_shannon();
6310
+ init_abductive();
6311
+ init_counterfactual();
6312
+ init_analogical();
6313
+ init_evidential();
6314
+ init_first_principles();
6315
+ init_systems_thinking();
6316
+ init_scientific_method();
6317
+ init_optimization();
6318
+ init_formal_logic();
6319
+ init_mathematics();
6320
+ init_physics();
6321
+ init_hybrid();
6322
+ init_metareasoning();
6323
+ VisualExporter = class {
6324
+ exportCausalGraph(thought, options) {
6325
+ return exportCausalGraph(thought, options);
6326
+ }
6327
+ exportTemporalTimeline(thought, options) {
6328
+ return exportTemporalTimeline(thought, options);
6329
+ }
6330
+ exportGameTree(thought, options) {
6331
+ return exportGameTree(thought, options);
6332
+ }
6333
+ exportBayesianNetwork(thought, options) {
6334
+ return exportBayesianNetwork(thought, options);
6335
+ }
6336
+ exportSequentialDependencyGraph(thought, options) {
6337
+ return exportSequentialDependencyGraph(thought, options);
6338
+ }
6339
+ exportShannonStageFlow(thought, options) {
6340
+ return exportShannonStageFlow(thought, options);
6341
+ }
6342
+ exportAbductiveHypotheses(thought, options) {
6343
+ return exportAbductiveHypotheses(thought, options);
6344
+ }
6345
+ exportCounterfactualScenarios(thought, options) {
6346
+ return exportCounterfactualScenarios(thought, options);
6347
+ }
6348
+ exportAnalogicalMapping(thought, options) {
6349
+ return exportAnalogicalMapping(thought, options);
6350
+ }
6351
+ exportEvidentialBeliefs(thought, options) {
6352
+ return exportEvidentialBeliefs(thought, options);
6353
+ }
6354
+ exportFirstPrinciplesDerivation(thought, options) {
6355
+ return exportFirstPrinciplesDerivation(thought, options);
6356
+ }
6357
+ exportSystemsThinkingCausalLoops(thought, options) {
6358
+ return exportSystemsThinkingCausalLoops(thought, options);
6359
+ }
6360
+ exportScientificMethodExperiment(thought, options) {
6361
+ return exportScientificMethodExperiment(thought, options);
6362
+ }
6363
+ exportOptimizationSolution(thought, options) {
6364
+ return exportOptimizationSolution(thought, options);
6365
+ }
6366
+ exportFormalLogicProof(thought, options) {
6367
+ return exportFormalLogicProof(thought, options);
6368
+ }
6369
+ // Sprint 2: New visual export wrapper methods
6370
+ exportMathematicsDerivation(thought, options) {
6371
+ return exportMathematicsDerivation(thought, options);
6372
+ }
6373
+ exportPhysicsVisualization(thought, options) {
6374
+ return exportPhysicsVisualization(thought, options);
6375
+ }
6376
+ exportHybridOrchestration(thought, options) {
6377
+ return exportHybridOrchestration(thought, options);
6378
+ }
6379
+ exportMetaReasoningVisualization(thought, options) {
6380
+ return exportMetaReasoningVisualization(thought, options);
6381
+ }
6382
+ };
6383
+ }
6384
+ });
6385
+
6386
+ // src/services/ExportService.ts
6387
+ var ExportService;
6388
+ var init_ExportService = __esm({
6389
+ "src/services/ExportService.ts"() {
6390
+ init_esm_shims();
6391
+ init_types();
6392
+ init_visual();
6393
+ init_sanitization();
6394
+ init_logger();
6395
+ ExportService = class {
6396
+ visualExporter;
6397
+ logger;
6398
+ constructor(logger2) {
6399
+ this.visualExporter = new VisualExporter();
6400
+ this.logger = logger2 || createLogger({ minLevel: 1 /* INFO */, enableConsole: true });
4994
6401
  }
4995
6402
  /**
4996
6403
  * Export a session to the specified format
@@ -5103,6 +6510,118 @@ var init_ExportService = __esm({
5103
6510
  colorScheme: "default"
5104
6511
  });
5105
6512
  }
6513
+ if (lastThought.mode === "sequential" /* SEQUENTIAL */ && "buildUpon" in lastThought) {
6514
+ return this.visualExporter.exportSequentialDependencyGraph(lastThought, {
6515
+ format,
6516
+ colorScheme: "default",
6517
+ includeLabels: true,
6518
+ includeMetrics: true
6519
+ });
6520
+ }
6521
+ if (lastThought.mode === "shannon" /* SHANNON */ && "stage" in lastThought) {
6522
+ return this.visualExporter.exportShannonStageFlow(lastThought, {
6523
+ format,
6524
+ colorScheme: "default",
6525
+ includeLabels: true,
6526
+ includeMetrics: true
6527
+ });
6528
+ }
6529
+ if (lastThought.mode === "abductive" /* ABDUCTIVE */ && "hypotheses" in lastThought) {
6530
+ return this.visualExporter.exportAbductiveHypotheses(lastThought, {
6531
+ format,
6532
+ colorScheme: "default",
6533
+ includeLabels: true,
6534
+ includeMetrics: true
6535
+ });
6536
+ }
6537
+ if (lastThought.mode === "counterfactual" /* COUNTERFACTUAL */ && "scenarios" in lastThought) {
6538
+ return this.visualExporter.exportCounterfactualScenarios(lastThought, {
6539
+ format,
6540
+ colorScheme: "default",
6541
+ includeLabels: true,
6542
+ includeMetrics: true
6543
+ });
6544
+ }
6545
+ if (lastThought.mode === "analogical" /* ANALOGICAL */ && "sourceAnalogy" in lastThought) {
6546
+ return this.visualExporter.exportAnalogicalMapping(lastThought, {
6547
+ format,
6548
+ colorScheme: "default",
6549
+ includeLabels: true,
6550
+ includeMetrics: true
6551
+ });
6552
+ }
6553
+ if (lastThought.mode === "evidential" /* EVIDENTIAL */ && "frameOfDiscernment" in lastThought) {
6554
+ return this.visualExporter.exportEvidentialBeliefs(lastThought, {
6555
+ format,
6556
+ colorScheme: "default",
6557
+ includeLabels: true,
6558
+ includeMetrics: true
6559
+ });
6560
+ }
6561
+ if (lastThought.mode === "systemsthinking" /* SYSTEMSTHINKING */ && "systemComponents" in lastThought) {
6562
+ return this.visualExporter.exportSystemsThinkingCausalLoops(lastThought, {
6563
+ format,
6564
+ colorScheme: "default",
6565
+ includeLabels: true,
6566
+ includeMetrics: true
6567
+ });
6568
+ }
6569
+ if (lastThought.mode === "scientificmethod" /* SCIENTIFICMETHOD */ && "hypothesis" in lastThought) {
6570
+ return this.visualExporter.exportScientificMethodExperiment(lastThought, {
6571
+ format,
6572
+ colorScheme: "default",
6573
+ includeLabels: true,
6574
+ includeMetrics: true
6575
+ });
6576
+ }
6577
+ if (lastThought.mode === "optimization" /* OPTIMIZATION */ && "objectiveFunction" in lastThought) {
6578
+ return this.visualExporter.exportOptimizationSolution(lastThought, {
6579
+ format,
6580
+ colorScheme: "default",
6581
+ includeLabels: true,
6582
+ includeMetrics: true
6583
+ });
6584
+ }
6585
+ if (lastThought.mode === "formallogic" /* FORMALLOGIC */ && "premises" in lastThought) {
6586
+ return this.visualExporter.exportFormalLogicProof(lastThought, {
6587
+ format,
6588
+ colorScheme: "default",
6589
+ includeLabels: true,
6590
+ includeMetrics: true
6591
+ });
6592
+ }
6593
+ if (lastThought.mode === "mathematics" /* MATHEMATICS */ && "proofStrategy" in lastThought) {
6594
+ return this.visualExporter.exportMathematicsDerivation(lastThought, {
6595
+ format,
6596
+ colorScheme: "default",
6597
+ includeLabels: true,
6598
+ includeMetrics: true
6599
+ });
6600
+ }
6601
+ if (lastThought.mode === "physics" /* PHYSICS */ && "tensorProperties" in lastThought) {
6602
+ return this.visualExporter.exportPhysicsVisualization(lastThought, {
6603
+ format,
6604
+ colorScheme: "default",
6605
+ includeLabels: true,
6606
+ includeMetrics: true
6607
+ });
6608
+ }
6609
+ if (lastThought.mode === "hybrid" /* HYBRID */ && "primaryMode" in lastThought) {
6610
+ return this.visualExporter.exportHybridOrchestration(lastThought, {
6611
+ format,
6612
+ colorScheme: "default",
6613
+ includeLabels: true,
6614
+ includeMetrics: true
6615
+ });
6616
+ }
6617
+ if (lastThought.mode === "metareasoning" /* METAREASONING */ && "currentStrategy" in lastThought) {
6618
+ return this.visualExporter.exportMetaReasoningVisualization(lastThought, {
6619
+ format,
6620
+ colorScheme: "default",
6621
+ includeLabels: true,
6622
+ includeMetrics: true
6623
+ });
6624
+ }
5106
6625
  const thoughts = session.thoughts.map(
5107
6626
  (t, i) => `Thought ${i + 1} (${t.mode}):
5108
6627
  ${t.content}
@@ -5162,6 +6681,79 @@ ${thoughts}`;
5162
6681
  md += `${thought.content}
5163
6682
 
5164
6683
  `;
6684
+ if (isMetaReasoningThought(thought)) {
6685
+ md += `#### \u{1F4CA} Meta-Reasoning Analysis
6686
+
6687
+ `;
6688
+ md += `**Current Strategy:**
6689
+ `;
6690
+ md += `- Mode: ${thought.currentStrategy.mode}
6691
+ `;
6692
+ md += `- Approach: ${thought.currentStrategy.approach}
6693
+ `;
6694
+ md += `- Thoughts Spent: ${thought.currentStrategy.thoughtsSpent}
6695
+ `;
6696
+ if (thought.currentStrategy.progressIndicators.length > 0) {
6697
+ md += `- Progress: ${thought.currentStrategy.progressIndicators.join(", ")}
6698
+ `;
6699
+ }
6700
+ md += `
6701
+ `;
6702
+ md += `**Strategy Evaluation:**
6703
+ `;
6704
+ md += `- Effectiveness: ${(thought.strategyEvaluation.effectiveness * 100).toFixed(1)}%
6705
+ `;
6706
+ md += `- Efficiency: ${(thought.strategyEvaluation.efficiency * 100).toFixed(1)}%
6707
+ `;
6708
+ md += `- Confidence: ${(thought.strategyEvaluation.confidence * 100).toFixed(1)}%
6709
+ `;
6710
+ md += `- Quality Score: ${(thought.strategyEvaluation.qualityScore * 100).toFixed(1)}%
6711
+ `;
6712
+ if (thought.strategyEvaluation.issues.length > 0) {
6713
+ md += `- Issues: ${thought.strategyEvaluation.issues.join("; ")}
6714
+ `;
6715
+ }
6716
+ if (thought.strategyEvaluation.strengths.length > 0) {
6717
+ md += `- Strengths: ${thought.strategyEvaluation.strengths.join("; ")}
6718
+ `;
6719
+ }
6720
+ md += `
6721
+ `;
6722
+ md += `**Recommendation:** ${thought.recommendation.action}
6723
+ `;
6724
+ md += `- ${thought.recommendation.justification}
6725
+ `;
6726
+ md += `- Confidence: ${(thought.recommendation.confidence * 100).toFixed(1)}%
6727
+ `;
6728
+ md += `- Expected Improvement: ${thought.recommendation.expectedImprovement}
6729
+ `;
6730
+ if (thought.alternativeStrategies.length > 0) {
6731
+ md += `
6732
+ **Alternative Strategies:**
6733
+ `;
6734
+ for (const alt of thought.alternativeStrategies) {
6735
+ md += `- **${alt.mode}** (score: ${(alt.recommendationScore * 100).toFixed(0)}%): ${alt.reasoning}
6736
+ `;
6737
+ }
6738
+ }
6739
+ md += `
6740
+ **Quality Metrics:**
6741
+ `;
6742
+ md += `- Logical Consistency: ${(thought.qualityMetrics.logicalConsistency * 100).toFixed(1)}%
6743
+ `;
6744
+ md += `- Evidence Quality: ${(thought.qualityMetrics.evidenceQuality * 100).toFixed(1)}%
6745
+ `;
6746
+ md += `- Completeness: ${(thought.qualityMetrics.completeness * 100).toFixed(1)}%
6747
+ `;
6748
+ md += `- Originality: ${(thought.qualityMetrics.originality * 100).toFixed(1)}%
6749
+ `;
6750
+ md += `- Clarity: ${(thought.qualityMetrics.clarity * 100).toFixed(1)}%
6751
+ `;
6752
+ md += `- Overall Quality: ${(thought.qualityMetrics.overallQuality * 100).toFixed(1)}%
6753
+ `;
6754
+ md += `
6755
+ `;
6756
+ }
5165
6757
  }
5166
6758
  return md;
5167
6759
  }
@@ -5320,27 +6912,31 @@ var init_ModeRouter = __esm({
5320
6912
  init_esm_shims();
5321
6913
  init_types();
5322
6914
  init_logger();
6915
+ init_MetaMonitor();
5323
6916
  ModeRouter = class {
5324
6917
  sessionManager;
5325
6918
  recommender;
5326
6919
  logger;
6920
+ monitor;
5327
6921
  /**
5328
6922
  * Create a new ModeRouter
5329
6923
  *
5330
6924
  * @param sessionManager - Session manager instance for mode switching
5331
6925
  * @param logger - Optional logger for dependency injection
6926
+ * @param monitor - Optional MetaMonitor instance for dependency injection
5332
6927
  *
5333
6928
  * @example
5334
6929
  * ```typescript
5335
6930
  * const router = new ModeRouter(sessionManager);
5336
6931
  * // Or with DI:
5337
- * const router = new ModeRouter(sessionManager, customLogger);
6932
+ * const router = new ModeRouter(sessionManager, customLogger, customMonitor);
5338
6933
  * ```
5339
6934
  */
5340
- constructor(sessionManager, logger2) {
6935
+ constructor(sessionManager, logger2, monitor) {
5341
6936
  this.sessionManager = sessionManager;
5342
6937
  this.recommender = new ModeRecommender();
5343
6938
  this.logger = logger2 || createLogger({ minLevel: 1 /* INFO */, enableConsole: true });
6939
+ this.monitor = monitor || metaMonitor;
5344
6940
  }
5345
6941
  /**
5346
6942
  * Switch a session to a new thinking mode
@@ -5501,6 +7097,96 @@ var init_ModeRouter = __esm({
5501
7097
 
5502
7098
  For more detailed recommendations, provide problemCharacteristics.`;
5503
7099
  }
7100
+ /**
7101
+ * Evaluate current session and suggest mode switch if beneficial
7102
+ *
7103
+ * Uses meta-reasoning to evaluate the current strategy effectiveness
7104
+ * and suggest alternative modes if the current approach is suboptimal.
7105
+ *
7106
+ * @param sessionId - Session to evaluate
7107
+ * @param problemType - Optional problem type for context
7108
+ * @returns Evaluation result with switch recommendation
7109
+ *
7110
+ * @example
7111
+ * ```typescript
7112
+ * const evaluation = await router.evaluateAndSuggestSwitch('session-123', 'debugging');
7113
+ * if (evaluation.shouldSwitch) {
7114
+ * await router.switchMode(sessionId, evaluation.suggestedMode!, evaluation.reasoning);
7115
+ * }
7116
+ * ```
7117
+ */
7118
+ async evaluateAndSuggestSwitch(sessionId, problemType = "general") {
7119
+ this.logger.debug("Evaluating session for potential mode switch", { sessionId, problemType });
7120
+ const evaluation = this.monitor.evaluateStrategy(sessionId);
7121
+ const session = await this.sessionManager.getSession(sessionId);
7122
+ const currentMode = session?.mode || "sequential" /* SEQUENTIAL */;
7123
+ const alternatives = this.monitor.suggestAlternatives(sessionId, currentMode);
7124
+ const shouldSwitch = evaluation.effectiveness < 0.4 || evaluation.effectiveness < 0.6 && alternatives.length > 0 && alternatives[0].recommendationScore > 0.75;
7125
+ const suggestedMode = shouldSwitch && alternatives.length > 0 ? alternatives[0].mode : void 0;
7126
+ 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.`;
7127
+ this.logger.debug("Mode switch evaluation completed", {
7128
+ sessionId,
7129
+ shouldSwitch,
7130
+ suggestedMode,
7131
+ currentEffectiveness: evaluation.effectiveness
7132
+ });
7133
+ return {
7134
+ currentEvaluation: evaluation,
7135
+ shouldSwitch,
7136
+ suggestedMode,
7137
+ reasoning,
7138
+ alternatives
7139
+ };
7140
+ }
7141
+ /**
7142
+ * Auto-switch mode if current strategy is failing
7143
+ *
7144
+ * Automatically evaluates and switches modes if the current approach
7145
+ * is demonstrably ineffective (effectiveness < 0.3).
7146
+ *
7147
+ * @param sessionId - Session to evaluate
7148
+ * @param problemType - Optional problem type for context
7149
+ * @returns Switch result with details
7150
+ *
7151
+ * @example
7152
+ * ```typescript
7153
+ * const result = await router.autoSwitchIfNeeded('session-123', 'complex-problem');
7154
+ * console.log(result.switched ? 'Switched to' + result.newMode : 'No switch needed');
7155
+ * ```
7156
+ */
7157
+ async autoSwitchIfNeeded(sessionId, problemType = "general") {
7158
+ this.logger.debug("Auto-switch evaluation", { sessionId, problemType });
7159
+ const evaluation = await this.evaluateAndSuggestSwitch(sessionId, problemType);
7160
+ const autoSwitchThreshold = 0.3;
7161
+ if (evaluation.currentEvaluation.effectiveness < autoSwitchThreshold && evaluation.suggestedMode) {
7162
+ const session = await this.sessionManager.getSession(sessionId);
7163
+ const oldMode = session?.mode || "sequential" /* SEQUENTIAL */;
7164
+ await this.switchMode(sessionId, evaluation.suggestedMode, evaluation.reasoning);
7165
+ this.logger.info("Auto-switched mode due to low effectiveness", {
7166
+ sessionId,
7167
+ oldMode,
7168
+ newMode: evaluation.suggestedMode,
7169
+ effectiveness: evaluation.currentEvaluation.effectiveness
7170
+ });
7171
+ return {
7172
+ switched: true,
7173
+ oldMode,
7174
+ newMode: evaluation.suggestedMode,
7175
+ reasoning: evaluation.reasoning,
7176
+ evaluation: evaluation.currentEvaluation
7177
+ };
7178
+ }
7179
+ this.logger.debug("Auto-switch not needed", {
7180
+ sessionId,
7181
+ effectiveness: evaluation.currentEvaluation.effectiveness,
7182
+ threshold: autoSwitchThreshold
7183
+ });
7184
+ return {
7185
+ switched: false,
7186
+ reasoning: evaluation.reasoning,
7187
+ evaluation: evaluation.currentEvaluation
7188
+ };
7189
+ }
5504
7190
  };
5505
7191
  }
5506
7192
  });
@@ -6219,14 +7905,14 @@ var deepthinking_strategic_schema = {
6219
7905
  };
6220
7906
  var deepthinking_analytical_schema = {
6221
7907
  name: "deepthinking_analytical",
6222
- description: "Analytical: analogical mapping, first principles",
7908
+ description: "Analytical: analogical mapping, first principles, meta-reasoning",
6223
7909
  inputSchema: {
6224
7910
  type: "object",
6225
7911
  properties: {
6226
7912
  ...baseThoughtProperties,
6227
7913
  mode: {
6228
7914
  type: "string",
6229
- enum: ["analogical", "firstprinciples"],
7915
+ enum: ["analogical", "firstprinciples", "metareasoning"],
6230
7916
  description: "Analytical reasoning mode"
6231
7917
  },
6232
7918
  sourceAnalogy: {
@@ -6758,7 +8444,7 @@ var StrategicSchema = BaseThoughtSchema.extend({
6758
8444
  // src/tools/schemas/modes/analytical.ts
6759
8445
  init_esm_shims();
6760
8446
  var AnalyticalSchema = BaseThoughtSchema.extend({
6761
- mode: z.enum(["analogical", "firstprinciples"])
8447
+ mode: z.enum(["analogical", "firstprinciples", "metareasoning"])
6762
8448
  });
6763
8449
 
6764
8450
  // src/tools/schemas/modes/scientific.ts
@@ -6805,6 +8491,7 @@ var modeToToolMap = {
6805
8491
  // Analytical modes
6806
8492
  analogical: "deepthinking_analytical",
6807
8493
  firstprinciples: "deepthinking_analytical",
8494
+ metareasoning: "deepthinking_analytical",
6808
8495
  // Scientific modes
6809
8496
  scientificmethod: "deepthinking_scientific",
6810
8497
  systemsthinking: "deepthinking_scientific",