deepthinking-mcp 2.4.1 → 2.5.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 +98 -6
- package/dist/index.js +646 -10
- package/dist/index.js.map +1 -1
- package/package.json +10 -3
package/dist/index.js
CHANGED
|
@@ -395,7 +395,7 @@ var ThinkingToolSchema = z.object({
|
|
|
395
395
|
}))
|
|
396
396
|
})).optional(),
|
|
397
397
|
action: z.enum(["add_thought", "summarize", "export", "switch_mode", "get_session", "recommend_mode"]).default("add_thought"),
|
|
398
|
-
exportFormat: z.enum(["markdown", "latex", "json", "html", "jupyter"]).optional(),
|
|
398
|
+
exportFormat: z.enum(["markdown", "latex", "json", "html", "jupyter", "mermaid", "dot", "ascii"]).optional(),
|
|
399
399
|
newMode: z.enum(["sequential", "shannon", "mathematics", "physics", "hybrid", "abductive", "causal", "bayesian", "counterfactual", "analogical", "temporal", "gametheory", "evidential"]).optional(),
|
|
400
400
|
// Mode recommendation parameters (v2.4)
|
|
401
401
|
problemType: z.string().optional(),
|
|
@@ -436,7 +436,21 @@ Phase 3 Modes (v2.1+):
|
|
|
436
436
|
- gametheory: Nash equilibria, strategic analysis, payoff matrices
|
|
437
437
|
- evidential: Dempster-Shafer theory, belief functions, evidence combination
|
|
438
438
|
|
|
439
|
-
|
|
439
|
+
Actions:
|
|
440
|
+
- add_thought: Add a new thought to the session (default)
|
|
441
|
+
- summarize: Generate a summary of the session
|
|
442
|
+
- export: Export session in various formats (markdown, latex, json, html, jupyter)
|
|
443
|
+
- switch_mode: Change reasoning mode mid-session
|
|
444
|
+
- get_session: Retrieve session information
|
|
445
|
+
- recommend_mode: Get intelligent mode recommendations based on problem characteristics
|
|
446
|
+
|
|
447
|
+
Mode Recommendations (v2.4):
|
|
448
|
+
Use action 'recommend_mode' with either:
|
|
449
|
+
\u2022 problemType: Quick recommendation (e.g., 'debugging', 'proof', 'timeline', 'strategy')
|
|
450
|
+
\u2022 problemCharacteristics: Detailed analysis with 10 dimensions (domain, complexity, uncertainty, etc.)
|
|
451
|
+
\u2022 includeCombinations: Set to true for synergistic mode combination suggestions
|
|
452
|
+
|
|
453
|
+
Choose the mode that best fits your problem type, or use recommend_mode to get intelligent suggestions.`,
|
|
440
454
|
inputSchema: {
|
|
441
455
|
type: "object",
|
|
442
456
|
properties: {
|
|
@@ -699,7 +713,7 @@ Choose the mode that best fits your problem type.`,
|
|
|
699
713
|
},
|
|
700
714
|
exportFormat: {
|
|
701
715
|
type: "string",
|
|
702
|
-
enum: ["markdown", "latex", "json", "html", "jupyter"],
|
|
716
|
+
enum: ["markdown", "latex", "json", "html", "jupyter", "mermaid", "dot", "ascii"],
|
|
703
717
|
description: "Export format"
|
|
704
718
|
},
|
|
705
719
|
newMode: {
|
|
@@ -1218,6 +1232,450 @@ var SessionManager = class {
|
|
|
1218
1232
|
}
|
|
1219
1233
|
};
|
|
1220
1234
|
|
|
1235
|
+
// src/export/visual.ts
|
|
1236
|
+
var VisualExporter = class {
|
|
1237
|
+
/**
|
|
1238
|
+
* Export causal graph to visual format
|
|
1239
|
+
*/
|
|
1240
|
+
exportCausalGraph(thought, options) {
|
|
1241
|
+
const { format, colorScheme = "default", includeLabels = true, includeMetrics = true } = options;
|
|
1242
|
+
switch (format) {
|
|
1243
|
+
case "mermaid":
|
|
1244
|
+
return this.causalGraphToMermaid(thought, colorScheme, includeLabels, includeMetrics);
|
|
1245
|
+
case "dot":
|
|
1246
|
+
return this.causalGraphToDOT(thought, includeLabels, includeMetrics);
|
|
1247
|
+
case "ascii":
|
|
1248
|
+
return this.causalGraphToASCII(thought);
|
|
1249
|
+
default:
|
|
1250
|
+
throw new Error(`Unsupported format: ${format}`);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* Export temporal timeline to visual format
|
|
1255
|
+
*/
|
|
1256
|
+
exportTemporalTimeline(thought, options) {
|
|
1257
|
+
const { format, colorScheme = "default", includeLabels = true } = options;
|
|
1258
|
+
switch (format) {
|
|
1259
|
+
case "mermaid":
|
|
1260
|
+
return this.timelineToMermaidGantt(thought, includeLabels);
|
|
1261
|
+
case "dot":
|
|
1262
|
+
return this.timelineToDOT(thought, includeLabels);
|
|
1263
|
+
case "ascii":
|
|
1264
|
+
return this.timelineToASCII(thought);
|
|
1265
|
+
default:
|
|
1266
|
+
throw new Error(`Unsupported format: ${format}`);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Export game tree to visual format
|
|
1271
|
+
*/
|
|
1272
|
+
exportGameTree(thought, options) {
|
|
1273
|
+
const { format, colorScheme = "default", includeLabels = true, includeMetrics = true } = options;
|
|
1274
|
+
switch (format) {
|
|
1275
|
+
case "mermaid":
|
|
1276
|
+
return this.gameTreeToMermaid(thought, colorScheme, includeLabels, includeMetrics);
|
|
1277
|
+
case "dot":
|
|
1278
|
+
return this.gameTreeToDOT(thought, includeLabels, includeMetrics);
|
|
1279
|
+
case "ascii":
|
|
1280
|
+
return this.gameTreeToASCII(thought);
|
|
1281
|
+
default:
|
|
1282
|
+
throw new Error(`Unsupported format: ${format}`);
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Export Bayesian network to visual format
|
|
1287
|
+
*/
|
|
1288
|
+
exportBayesianNetwork(thought, options) {
|
|
1289
|
+
const { format, colorScheme = "default", includeLabels = true, includeMetrics = true } = options;
|
|
1290
|
+
switch (format) {
|
|
1291
|
+
case "mermaid":
|
|
1292
|
+
return this.bayesianToMermaid(thought, colorScheme, includeLabels, includeMetrics);
|
|
1293
|
+
case "dot":
|
|
1294
|
+
return this.bayesianToDOT(thought, includeLabels, includeMetrics);
|
|
1295
|
+
case "ascii":
|
|
1296
|
+
return this.bayesianToASCII(thought);
|
|
1297
|
+
default:
|
|
1298
|
+
throw new Error(`Unsupported format: ${format}`);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
// ===== Causal Graph Exporters =====
|
|
1302
|
+
causalGraphToMermaid(thought, colorScheme, includeLabels, includeMetrics) {
|
|
1303
|
+
let mermaid = "graph TB\n";
|
|
1304
|
+
for (const node of thought.causalGraph.nodes) {
|
|
1305
|
+
const nodeId = this.sanitizeId(node.id);
|
|
1306
|
+
const label = includeLabels ? node.name : nodeId;
|
|
1307
|
+
let shape;
|
|
1308
|
+
switch (node.type) {
|
|
1309
|
+
case "cause":
|
|
1310
|
+
shape = ["([", "])"];
|
|
1311
|
+
break;
|
|
1312
|
+
case "effect":
|
|
1313
|
+
shape = ["[[", "]]"];
|
|
1314
|
+
break;
|
|
1315
|
+
case "mediator":
|
|
1316
|
+
shape = ["[", "]"];
|
|
1317
|
+
break;
|
|
1318
|
+
case "confounder":
|
|
1319
|
+
shape = ["{", "}"];
|
|
1320
|
+
break;
|
|
1321
|
+
default:
|
|
1322
|
+
shape = ["[", "]"];
|
|
1323
|
+
}
|
|
1324
|
+
mermaid += ` ${nodeId}${shape[0]}${label}${shape[1]}
|
|
1325
|
+
`;
|
|
1326
|
+
}
|
|
1327
|
+
mermaid += "\n";
|
|
1328
|
+
for (const edge of thought.causalGraph.edges) {
|
|
1329
|
+
const fromId = this.sanitizeId(edge.from);
|
|
1330
|
+
const toId = this.sanitizeId(edge.to);
|
|
1331
|
+
if (includeMetrics && edge.strength !== void 0) {
|
|
1332
|
+
mermaid += ` ${fromId} --> |${edge.strength.toFixed(2)}| ${toId}
|
|
1333
|
+
`;
|
|
1334
|
+
} else {
|
|
1335
|
+
mermaid += ` ${fromId} --> ${toId}
|
|
1336
|
+
`;
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
if (colorScheme !== "monochrome") {
|
|
1340
|
+
mermaid += "\n";
|
|
1341
|
+
const causes = thought.causalGraph.nodes.filter((n) => n.type === "cause");
|
|
1342
|
+
const effects = thought.causalGraph.nodes.filter((n) => n.type === "effect");
|
|
1343
|
+
for (const node of causes) {
|
|
1344
|
+
const color = colorScheme === "pastel" ? "#e1f5ff" : "#a8d5ff";
|
|
1345
|
+
mermaid += ` style ${this.sanitizeId(node.id)} fill:${color}
|
|
1346
|
+
`;
|
|
1347
|
+
}
|
|
1348
|
+
for (const node of effects) {
|
|
1349
|
+
const color = colorScheme === "pastel" ? "#fff3e0" : "#ffd699";
|
|
1350
|
+
mermaid += ` style ${this.sanitizeId(node.id)} fill:${color}
|
|
1351
|
+
`;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
return mermaid;
|
|
1355
|
+
}
|
|
1356
|
+
causalGraphToDOT(thought, includeLabels, includeMetrics) {
|
|
1357
|
+
let dot = "digraph CausalGraph {\n";
|
|
1358
|
+
dot += " rankdir=TB;\n";
|
|
1359
|
+
dot += " node [shape=box, style=rounded];\n\n";
|
|
1360
|
+
for (const node of thought.causalGraph.nodes) {
|
|
1361
|
+
const nodeId = this.sanitizeId(node.id);
|
|
1362
|
+
const label = includeLabels ? node.name : nodeId;
|
|
1363
|
+
let shape = "box";
|
|
1364
|
+
switch (node.type) {
|
|
1365
|
+
case "cause":
|
|
1366
|
+
shape = "ellipse";
|
|
1367
|
+
break;
|
|
1368
|
+
case "effect":
|
|
1369
|
+
shape = "doubleoctagon";
|
|
1370
|
+
break;
|
|
1371
|
+
case "mediator":
|
|
1372
|
+
shape = "box";
|
|
1373
|
+
break;
|
|
1374
|
+
case "confounder":
|
|
1375
|
+
shape = "diamond";
|
|
1376
|
+
break;
|
|
1377
|
+
}
|
|
1378
|
+
dot += ` ${nodeId} [label="${label}", shape=${shape}];
|
|
1379
|
+
`;
|
|
1380
|
+
}
|
|
1381
|
+
dot += "\n";
|
|
1382
|
+
for (const edge of thought.causalGraph.edges) {
|
|
1383
|
+
const fromId = this.sanitizeId(edge.from);
|
|
1384
|
+
const toId = this.sanitizeId(edge.to);
|
|
1385
|
+
if (includeMetrics && edge.strength !== void 0) {
|
|
1386
|
+
dot += ` ${fromId} -> ${toId} [label="${edge.strength.toFixed(2)}"];
|
|
1387
|
+
`;
|
|
1388
|
+
} else {
|
|
1389
|
+
dot += ` ${fromId} -> ${toId};
|
|
1390
|
+
`;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
dot += "}\n";
|
|
1394
|
+
return dot;
|
|
1395
|
+
}
|
|
1396
|
+
causalGraphToASCII(thought) {
|
|
1397
|
+
let ascii = "Causal Graph:\n";
|
|
1398
|
+
ascii += "=============\n\n";
|
|
1399
|
+
ascii += "Nodes:\n";
|
|
1400
|
+
for (const node of thought.causalGraph.nodes) {
|
|
1401
|
+
ascii += ` [${node.type.toUpperCase()}] ${node.name}: ${node.description}
|
|
1402
|
+
`;
|
|
1403
|
+
}
|
|
1404
|
+
ascii += "\nEdges:\n";
|
|
1405
|
+
for (const edge of thought.causalGraph.edges) {
|
|
1406
|
+
const fromNode = thought.causalGraph.nodes.find((n) => n.id === edge.from);
|
|
1407
|
+
const toNode = thought.causalGraph.nodes.find((n) => n.id === edge.to);
|
|
1408
|
+
const strength = edge.strength !== void 0 ? ` (strength: ${edge.strength.toFixed(2)})` : "";
|
|
1409
|
+
ascii += ` ${fromNode?.name} --> ${toNode?.name}${strength}
|
|
1410
|
+
`;
|
|
1411
|
+
}
|
|
1412
|
+
return ascii;
|
|
1413
|
+
}
|
|
1414
|
+
// ===== Temporal Timeline Exporters =====
|
|
1415
|
+
timelineToMermaidGantt(thought, includeLabels) {
|
|
1416
|
+
let gantt = "gantt\n";
|
|
1417
|
+
gantt += ` title ${thought.timeline?.name || "Timeline"}
|
|
1418
|
+
`;
|
|
1419
|
+
gantt += " dateFormat X\n";
|
|
1420
|
+
gantt += " axisFormat %s\n\n";
|
|
1421
|
+
if (!thought.events || thought.events.length === 0) {
|
|
1422
|
+
return gantt + " No events\n";
|
|
1423
|
+
}
|
|
1424
|
+
gantt += " section Events\n";
|
|
1425
|
+
for (const event of thought.events) {
|
|
1426
|
+
const label = includeLabels ? event.name : event.id;
|
|
1427
|
+
if (event.type === "instant") {
|
|
1428
|
+
gantt += ` ${label} :milestone, ${event.timestamp}, 0s
|
|
1429
|
+
`;
|
|
1430
|
+
} else if (event.type === "interval" && event.duration) {
|
|
1431
|
+
gantt += ` ${label} :${event.timestamp}, ${event.duration}s
|
|
1432
|
+
`;
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
return gantt;
|
|
1436
|
+
}
|
|
1437
|
+
timelineToDOT(thought, includeLabels) {
|
|
1438
|
+
let dot = "digraph Timeline {\n";
|
|
1439
|
+
dot += " rankdir=LR;\n";
|
|
1440
|
+
dot += " node [shape=box];\n\n";
|
|
1441
|
+
if (!thought.events) {
|
|
1442
|
+
dot += "}\n";
|
|
1443
|
+
return dot;
|
|
1444
|
+
}
|
|
1445
|
+
const sortedEvents = [...thought.events].sort((a, b) => a.timestamp - b.timestamp);
|
|
1446
|
+
for (const event of sortedEvents) {
|
|
1447
|
+
const nodeId = this.sanitizeId(event.id);
|
|
1448
|
+
const label = includeLabels ? `${event.name}\\n(t=${event.timestamp})` : nodeId;
|
|
1449
|
+
const shape = event.type === "instant" ? "ellipse" : "box";
|
|
1450
|
+
dot += ` ${nodeId} [label="${label}", shape=${shape}];
|
|
1451
|
+
`;
|
|
1452
|
+
}
|
|
1453
|
+
dot += "\n";
|
|
1454
|
+
for (let i = 0; i < sortedEvents.length - 1; i++) {
|
|
1455
|
+
const from = this.sanitizeId(sortedEvents[i].id);
|
|
1456
|
+
const to = this.sanitizeId(sortedEvents[i + 1].id);
|
|
1457
|
+
dot += ` ${from} -> ${to};
|
|
1458
|
+
`;
|
|
1459
|
+
}
|
|
1460
|
+
if (thought.relations) {
|
|
1461
|
+
dot += "\n // Causal relations\n";
|
|
1462
|
+
for (const rel of thought.relations) {
|
|
1463
|
+
const from = this.sanitizeId(rel.from);
|
|
1464
|
+
const to = this.sanitizeId(rel.to);
|
|
1465
|
+
dot += ` ${from} -> ${to} [style=dashed, label="${rel.relationType}"];
|
|
1466
|
+
`;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
dot += "}\n";
|
|
1470
|
+
return dot;
|
|
1471
|
+
}
|
|
1472
|
+
timelineToASCII(thought) {
|
|
1473
|
+
let ascii = `Timeline: ${thought.timeline?.name || "Untitled"}
|
|
1474
|
+
`;
|
|
1475
|
+
ascii += "=".repeat(40) + "\n\n";
|
|
1476
|
+
if (!thought.events || thought.events.length === 0) {
|
|
1477
|
+
return ascii + "No events\n";
|
|
1478
|
+
}
|
|
1479
|
+
const sortedEvents = [...thought.events].sort((a, b) => a.timestamp - b.timestamp);
|
|
1480
|
+
for (const event of sortedEvents) {
|
|
1481
|
+
const marker = event.type === "instant" ? "\u29BF" : "\u2501";
|
|
1482
|
+
ascii += `t=${event.timestamp.toString().padStart(4)} ${marker} ${event.name}
|
|
1483
|
+
`;
|
|
1484
|
+
if (event.duration) {
|
|
1485
|
+
ascii += ` ${"\u2514".padStart(5)}\u2192 duration: ${event.duration}
|
|
1486
|
+
`;
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
return ascii;
|
|
1490
|
+
}
|
|
1491
|
+
// ===== Game Theory Exporters =====
|
|
1492
|
+
gameTreeToMermaid(thought, colorScheme, includeLabels, includeMetrics) {
|
|
1493
|
+
let mermaid = "graph TD\n";
|
|
1494
|
+
if (!thought.game) {
|
|
1495
|
+
return mermaid + " root[No game defined]\n";
|
|
1496
|
+
}
|
|
1497
|
+
if (thought.gameTree && thought.gameTree.nodes) {
|
|
1498
|
+
for (const node of thought.gameTree.nodes) {
|
|
1499
|
+
const nodeId = this.sanitizeId(node.id);
|
|
1500
|
+
const label = includeLabels ? node.name : nodeId;
|
|
1501
|
+
const shape = node.isTerminal ? ["[[", "]]"] : ["[", "]"];
|
|
1502
|
+
mermaid += ` ${nodeId}${shape[0]}${label}${shape[1]}
|
|
1503
|
+
`;
|
|
1504
|
+
}
|
|
1505
|
+
mermaid += "\n";
|
|
1506
|
+
for (const node of thought.gameTree.nodes) {
|
|
1507
|
+
if (node.childNodes && node.childNodes.length > 0) {
|
|
1508
|
+
for (const childId of node.childNodes) {
|
|
1509
|
+
const fromId = this.sanitizeId(node.id);
|
|
1510
|
+
const toId = this.sanitizeId(childId);
|
|
1511
|
+
const childNode = thought.gameTree.nodes.find((n) => n.id === childId);
|
|
1512
|
+
if (includeMetrics && childNode?.action) {
|
|
1513
|
+
mermaid += ` ${fromId} --> |${childNode.action}| ${toId}
|
|
1514
|
+
`;
|
|
1515
|
+
} else {
|
|
1516
|
+
mermaid += ` ${fromId} --> ${toId}
|
|
1517
|
+
`;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
} else {
|
|
1523
|
+
mermaid += " root[Game]\n";
|
|
1524
|
+
if (thought.strategies) {
|
|
1525
|
+
for (const strategy of thought.strategies.slice(0, 5)) {
|
|
1526
|
+
const stratId = this.sanitizeId(strategy.id);
|
|
1527
|
+
mermaid += ` root --> ${stratId}[${strategy.name}]
|
|
1528
|
+
`;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
return mermaid;
|
|
1533
|
+
}
|
|
1534
|
+
gameTreeToDOT(thought, includeLabels, includeMetrics) {
|
|
1535
|
+
let dot = "digraph GameTree {\n";
|
|
1536
|
+
dot += " rankdir=TD;\n";
|
|
1537
|
+
dot += " node [shape=circle];\n\n";
|
|
1538
|
+
if (!thought.game) {
|
|
1539
|
+
dot += ' root [label="No game"];\n}\n';
|
|
1540
|
+
return dot;
|
|
1541
|
+
}
|
|
1542
|
+
if (thought.gameTree && thought.gameTree.nodes) {
|
|
1543
|
+
for (const node of thought.gameTree.nodes) {
|
|
1544
|
+
const nodeId = this.sanitizeId(node.id);
|
|
1545
|
+
const label = includeLabels ? node.name : nodeId;
|
|
1546
|
+
const shape = node.isTerminal ? "doublecircle" : "circle";
|
|
1547
|
+
dot += ` ${nodeId} [label="${label}", shape=${shape}];
|
|
1548
|
+
`;
|
|
1549
|
+
}
|
|
1550
|
+
dot += "\n";
|
|
1551
|
+
for (const node of thought.gameTree.nodes) {
|
|
1552
|
+
if (node.childNodes && node.childNodes.length > 0) {
|
|
1553
|
+
for (const childId of node.childNodes) {
|
|
1554
|
+
const fromId = this.sanitizeId(node.id);
|
|
1555
|
+
const toId = this.sanitizeId(childId);
|
|
1556
|
+
const childNode = thought.gameTree.nodes.find((n) => n.id === childId);
|
|
1557
|
+
if (includeMetrics && childNode?.action) {
|
|
1558
|
+
dot += ` ${fromId} -> ${toId} [label="${childNode.action}"];
|
|
1559
|
+
`;
|
|
1560
|
+
} else {
|
|
1561
|
+
dot += ` ${fromId} -> ${toId};
|
|
1562
|
+
`;
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
dot += "}\n";
|
|
1569
|
+
return dot;
|
|
1570
|
+
}
|
|
1571
|
+
gameTreeToASCII(thought) {
|
|
1572
|
+
let ascii = `Game: ${thought.game?.name || "Untitled"}
|
|
1573
|
+
`;
|
|
1574
|
+
ascii += "=".repeat(40) + "\n\n";
|
|
1575
|
+
if (thought.strategies && thought.strategies.length > 0) {
|
|
1576
|
+
ascii += "Strategies:\n";
|
|
1577
|
+
for (const strategy of thought.strategies) {
|
|
1578
|
+
ascii += ` \u2022 ${strategy.name} (${strategy.type})
|
|
1579
|
+
`;
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
if (thought.equilibria && thought.equilibria.length > 0) {
|
|
1583
|
+
ascii += "\nEquilibria:\n";
|
|
1584
|
+
for (const eq of thought.equilibria) {
|
|
1585
|
+
ascii += ` \u2696 ${eq.type}: ${eq.strategyProfile.join(", ")}
|
|
1586
|
+
`;
|
|
1587
|
+
ascii += ` Payoffs: [${eq.payoffs.join(", ")}]
|
|
1588
|
+
`;
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
return ascii;
|
|
1592
|
+
}
|
|
1593
|
+
// ===== Bayesian Network Exporters =====
|
|
1594
|
+
bayesianToMermaid(thought, colorScheme, includeLabels, includeMetrics) {
|
|
1595
|
+
let mermaid = "graph LR\n";
|
|
1596
|
+
mermaid += ` H([Hypothesis])
|
|
1597
|
+
`;
|
|
1598
|
+
mermaid += ` Prior[Prior: ${includeMetrics ? thought.prior.probability.toFixed(3) : "?"}]
|
|
1599
|
+
`;
|
|
1600
|
+
mermaid += ` Evidence[Evidence]
|
|
1601
|
+
`;
|
|
1602
|
+
mermaid += ` Posterior[[Posterior: ${includeMetrics ? thought.posterior.probability.toFixed(3) : "?"}]]
|
|
1603
|
+
`;
|
|
1604
|
+
mermaid += "\n";
|
|
1605
|
+
mermaid += " Prior --> H\n";
|
|
1606
|
+
mermaid += " Evidence --> H\n";
|
|
1607
|
+
mermaid += " H --> Posterior\n";
|
|
1608
|
+
if (colorScheme !== "monochrome") {
|
|
1609
|
+
mermaid += "\n";
|
|
1610
|
+
const priorColor = colorScheme === "pastel" ? "#e1f5ff" : "#a8d5ff";
|
|
1611
|
+
const posteriorColor = colorScheme === "pastel" ? "#c8e6c9" : "#81c784";
|
|
1612
|
+
mermaid += ` style Prior fill:${priorColor}
|
|
1613
|
+
`;
|
|
1614
|
+
mermaid += ` style Posterior fill:${posteriorColor}
|
|
1615
|
+
`;
|
|
1616
|
+
}
|
|
1617
|
+
return mermaid;
|
|
1618
|
+
}
|
|
1619
|
+
bayesianToDOT(thought, includeLabels, includeMetrics) {
|
|
1620
|
+
let dot = "digraph BayesianNetwork {\n";
|
|
1621
|
+
dot += " rankdir=LR;\n";
|
|
1622
|
+
dot += " node [shape=ellipse];\n\n";
|
|
1623
|
+
const priorProb = includeMetrics ? `: ${thought.prior.probability.toFixed(3)}` : "";
|
|
1624
|
+
const posteriorProb = includeMetrics ? `: ${thought.posterior.probability.toFixed(3)}` : "";
|
|
1625
|
+
dot += ` Prior [label="Prior${priorProb}"];
|
|
1626
|
+
`;
|
|
1627
|
+
dot += ` Hypothesis [label="Hypothesis", shape=box];
|
|
1628
|
+
`;
|
|
1629
|
+
dot += ` Evidence [label="Evidence"];
|
|
1630
|
+
`;
|
|
1631
|
+
dot += ` Posterior [label="Posterior${posteriorProb}", shape=doublecircle];
|
|
1632
|
+
`;
|
|
1633
|
+
dot += "\n";
|
|
1634
|
+
dot += " Prior -> Hypothesis;\n";
|
|
1635
|
+
dot += " Evidence -> Hypothesis;\n";
|
|
1636
|
+
dot += " Hypothesis -> Posterior;\n";
|
|
1637
|
+
dot += "}\n";
|
|
1638
|
+
return dot;
|
|
1639
|
+
}
|
|
1640
|
+
bayesianToASCII(thought) {
|
|
1641
|
+
let ascii = "Bayesian Network:\n";
|
|
1642
|
+
ascii += "=================\n\n";
|
|
1643
|
+
ascii += `Hypothesis: ${thought.hypothesis.statement}
|
|
1644
|
+
|
|
1645
|
+
`;
|
|
1646
|
+
ascii += `Prior Probability: ${thought.prior.probability.toFixed(3)}
|
|
1647
|
+
`;
|
|
1648
|
+
ascii += ` Justification: ${thought.prior.justification}
|
|
1649
|
+
|
|
1650
|
+
`;
|
|
1651
|
+
if (thought.evidence && thought.evidence.length > 0) {
|
|
1652
|
+
ascii += "Evidence:\n";
|
|
1653
|
+
for (const ev of thought.evidence) {
|
|
1654
|
+
ascii += ` \u2022 ${ev.observation}
|
|
1655
|
+
`;
|
|
1656
|
+
}
|
|
1657
|
+
ascii += "\n";
|
|
1658
|
+
}
|
|
1659
|
+
ascii += `Posterior Probability: ${thought.posterior.probability.toFixed(3)}
|
|
1660
|
+
`;
|
|
1661
|
+
ascii += ` Justification: ${thought.posterior.justification}
|
|
1662
|
+
`;
|
|
1663
|
+
if (thought.bayesFactor !== void 0) {
|
|
1664
|
+
ascii += `
|
|
1665
|
+
Bayes Factor: ${thought.bayesFactor.toFixed(2)}
|
|
1666
|
+
`;
|
|
1667
|
+
}
|
|
1668
|
+
return ascii;
|
|
1669
|
+
}
|
|
1670
|
+
// ===== Utility Methods =====
|
|
1671
|
+
/**
|
|
1672
|
+
* Sanitize ID for use in diagram formats
|
|
1673
|
+
*/
|
|
1674
|
+
sanitizeId(id) {
|
|
1675
|
+
return id.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
1676
|
+
}
|
|
1677
|
+
};
|
|
1678
|
+
|
|
1221
1679
|
// src/index.ts
|
|
1222
1680
|
var server = new Server(
|
|
1223
1681
|
{
|
|
@@ -1321,6 +1779,50 @@ async function handleExport(input) {
|
|
|
1321
1779
|
if (!session) {
|
|
1322
1780
|
throw new Error(`Session ${input.sessionId} not found`);
|
|
1323
1781
|
}
|
|
1782
|
+
const format = input.exportFormat || "json";
|
|
1783
|
+
if (format === "mermaid" || format === "dot" || format === "ascii") {
|
|
1784
|
+
const visualExporter = new VisualExporter();
|
|
1785
|
+
const lastThought = session.thoughts[session.thoughts.length - 1];
|
|
1786
|
+
if (!lastThought) {
|
|
1787
|
+
throw new Error("No thoughts in session to export");
|
|
1788
|
+
}
|
|
1789
|
+
let exported2;
|
|
1790
|
+
if (lastThought.mode === "causal" && "causalGraph" in lastThought) {
|
|
1791
|
+
exported2 = visualExporter.exportCausalGraph(lastThought, {
|
|
1792
|
+
format,
|
|
1793
|
+
colorScheme: "default",
|
|
1794
|
+
includeLabels: true,
|
|
1795
|
+
includeMetrics: true
|
|
1796
|
+
});
|
|
1797
|
+
} else if (lastThought.mode === "temporal" && "timeline" in lastThought) {
|
|
1798
|
+
exported2 = visualExporter.exportTemporalTimeline(lastThought, {
|
|
1799
|
+
format,
|
|
1800
|
+
includeLabels: true
|
|
1801
|
+
});
|
|
1802
|
+
} else if (lastThought.mode === "gametheory" && "game" in lastThought) {
|
|
1803
|
+
exported2 = visualExporter.exportGameTree(lastThought, {
|
|
1804
|
+
format,
|
|
1805
|
+
colorScheme: "default",
|
|
1806
|
+
includeLabels: true,
|
|
1807
|
+
includeMetrics: true
|
|
1808
|
+
});
|
|
1809
|
+
} else if (lastThought.mode === "bayesian" && "hypothesis" in lastThought) {
|
|
1810
|
+
exported2 = visualExporter.exportBayesianNetwork(lastThought, {
|
|
1811
|
+
format,
|
|
1812
|
+
colorScheme: "default",
|
|
1813
|
+
includeLabels: true,
|
|
1814
|
+
includeMetrics: true
|
|
1815
|
+
});
|
|
1816
|
+
} else {
|
|
1817
|
+
throw new Error(`Visual export not supported for mode: ${lastThought.mode}`);
|
|
1818
|
+
}
|
|
1819
|
+
return {
|
|
1820
|
+
content: [{
|
|
1821
|
+
type: "text",
|
|
1822
|
+
text: exported2
|
|
1823
|
+
}]
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1324
1826
|
const sessionWithCustomMetrics = {
|
|
1325
1827
|
...session,
|
|
1326
1828
|
metrics: {
|
|
@@ -1328,14 +1830,31 @@ async function handleExport(input) {
|
|
|
1328
1830
|
customMetrics: Object.fromEntries(session.metrics.customMetrics)
|
|
1329
1831
|
}
|
|
1330
1832
|
};
|
|
1331
|
-
|
|
1833
|
+
let exported;
|
|
1834
|
+
switch (format) {
|
|
1835
|
+
case "json":
|
|
1836
|
+
exported = JSON.stringify(sessionWithCustomMetrics, null, 2);
|
|
1837
|
+
break;
|
|
1838
|
+
case "markdown":
|
|
1839
|
+
exported = exportToMarkdown(sessionWithCustomMetrics);
|
|
1840
|
+
break;
|
|
1841
|
+
case "latex":
|
|
1842
|
+
exported = exportToLatex(sessionWithCustomMetrics);
|
|
1843
|
+
break;
|
|
1844
|
+
case "html":
|
|
1845
|
+
exported = exportToHTML(sessionWithCustomMetrics);
|
|
1846
|
+
break;
|
|
1847
|
+
case "jupyter":
|
|
1848
|
+
exported = exportToJupyter(sessionWithCustomMetrics);
|
|
1849
|
+
break;
|
|
1850
|
+
default:
|
|
1851
|
+
exported = JSON.stringify(sessionWithCustomMetrics, null, 2);
|
|
1852
|
+
}
|
|
1332
1853
|
return {
|
|
1333
|
-
content: [
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
}
|
|
1338
|
-
]
|
|
1854
|
+
content: [{
|
|
1855
|
+
type: "text",
|
|
1856
|
+
text: exported
|
|
1857
|
+
}]
|
|
1339
1858
|
};
|
|
1340
1859
|
}
|
|
1341
1860
|
async function handleSwitchMode(input) {
|
|
@@ -1634,6 +2153,123 @@ For more detailed recommendations, provide problemCharacteristics.`
|
|
|
1634
2153
|
isError: true
|
|
1635
2154
|
};
|
|
1636
2155
|
}
|
|
2156
|
+
function exportToMarkdown(session) {
|
|
2157
|
+
let md = `# Thinking Session: ${session.id}
|
|
2158
|
+
|
|
2159
|
+
`;
|
|
2160
|
+
md += `**Mode**: ${session.mode}
|
|
2161
|
+
`;
|
|
2162
|
+
md += `**Created**: ${session.createdAt}
|
|
2163
|
+
`;
|
|
2164
|
+
md += `**Status**: ${session.status}
|
|
2165
|
+
|
|
2166
|
+
`;
|
|
2167
|
+
md += `## Thoughts
|
|
2168
|
+
|
|
2169
|
+
`;
|
|
2170
|
+
for (const thought of session.thoughts) {
|
|
2171
|
+
md += `### Thought ${thought.thoughtNumber}/${session.thoughts.length}
|
|
2172
|
+
|
|
2173
|
+
`;
|
|
2174
|
+
md += `${thought.content}
|
|
2175
|
+
|
|
2176
|
+
`;
|
|
2177
|
+
}
|
|
2178
|
+
return md;
|
|
2179
|
+
}
|
|
2180
|
+
function exportToLatex(session) {
|
|
2181
|
+
let latex = `documentclass{article}
|
|
2182
|
+
`;
|
|
2183
|
+
latex += ` itle{Thinking Session: ${session.id}}
|
|
2184
|
+
`;
|
|
2185
|
+
latex += `\begin{document}
|
|
2186
|
+
`;
|
|
2187
|
+
latex += `maketitle
|
|
2188
|
+
|
|
2189
|
+
`;
|
|
2190
|
+
latex += `section{Session Details}
|
|
2191
|
+
`;
|
|
2192
|
+
latex += `Mode: ${session.mode}\\
|
|
2193
|
+
`;
|
|
2194
|
+
latex += `Status: ${session.status}\\
|
|
2195
|
+
|
|
2196
|
+
`;
|
|
2197
|
+
latex += `section{Thoughts}
|
|
2198
|
+
`;
|
|
2199
|
+
for (const thought of session.thoughts) {
|
|
2200
|
+
latex += `subsection{Thought ${thought.thoughtNumber}}
|
|
2201
|
+
`;
|
|
2202
|
+
latex += `${thought.content}
|
|
2203
|
+
|
|
2204
|
+
`;
|
|
2205
|
+
}
|
|
2206
|
+
latex += `end{document}
|
|
2207
|
+
`;
|
|
2208
|
+
return latex;
|
|
2209
|
+
}
|
|
2210
|
+
function exportToHTML(session) {
|
|
2211
|
+
let html = `<!DOCTYPE html>
|
|
2212
|
+
<html>
|
|
2213
|
+
<head>
|
|
2214
|
+
`;
|
|
2215
|
+
html += ` <title>Thinking Session: ${session.id}</title>
|
|
2216
|
+
`;
|
|
2217
|
+
html += ` <style>body { font-family: Arial, sans-serif; max-width: 800px; margin: 50px auto; }</style>
|
|
2218
|
+
`;
|
|
2219
|
+
html += `</head>
|
|
2220
|
+
<body>
|
|
2221
|
+
`;
|
|
2222
|
+
html += ` <h1>Thinking Session: ${session.id}</h1>
|
|
2223
|
+
`;
|
|
2224
|
+
html += ` <p><strong>Mode:</strong> ${session.mode}</p>
|
|
2225
|
+
`;
|
|
2226
|
+
html += ` <p><strong>Status:</strong> ${session.status}</p>
|
|
2227
|
+
`;
|
|
2228
|
+
html += ` <h2>Thoughts</h2>
|
|
2229
|
+
`;
|
|
2230
|
+
for (const thought of session.thoughts) {
|
|
2231
|
+
html += ` <div>
|
|
2232
|
+
`;
|
|
2233
|
+
html += ` <h3>Thought ${thought.thoughtNumber}/${session.thoughts.length}</h3>
|
|
2234
|
+
`;
|
|
2235
|
+
html += ` <p>${thought.content}</p>
|
|
2236
|
+
`;
|
|
2237
|
+
html += ` </div>
|
|
2238
|
+
`;
|
|
2239
|
+
}
|
|
2240
|
+
html += `</body>
|
|
2241
|
+
</html>
|
|
2242
|
+
`;
|
|
2243
|
+
return html;
|
|
2244
|
+
}
|
|
2245
|
+
function exportToJupyter(session) {
|
|
2246
|
+
const notebook = {
|
|
2247
|
+
cells: [],
|
|
2248
|
+
metadata: {},
|
|
2249
|
+
nbformat: 4,
|
|
2250
|
+
nbformat_minor: 2
|
|
2251
|
+
};
|
|
2252
|
+
notebook.cells.push({
|
|
2253
|
+
cell_type: "markdown",
|
|
2254
|
+
metadata: {},
|
|
2255
|
+
source: [`# Thinking Session: ${session.id}
|
|
2256
|
+
`, `
|
|
2257
|
+
`, `**Mode**: ${session.mode}
|
|
2258
|
+
`, `**Status**: ${session.status}
|
|
2259
|
+
`]
|
|
2260
|
+
});
|
|
2261
|
+
for (const thought of session.thoughts) {
|
|
2262
|
+
notebook.cells.push({
|
|
2263
|
+
cell_type: "markdown",
|
|
2264
|
+
metadata: {},
|
|
2265
|
+
source: [`## Thought ${thought.thoughtNumber}/${session.thoughts.length}
|
|
2266
|
+
`, `
|
|
2267
|
+
`, `${thought.content}
|
|
2268
|
+
`]
|
|
2269
|
+
});
|
|
2270
|
+
}
|
|
2271
|
+
return JSON.stringify(notebook, null, 2);
|
|
2272
|
+
}
|
|
1637
2273
|
async function main() {
|
|
1638
2274
|
const transport = new StdioServerTransport();
|
|
1639
2275
|
await server.connect(transport);
|