deepthinking-mcp 2.5.6 → 2.6.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
@@ -1495,23 +1495,33 @@ var SessionManager = class {
1495
1495
  activeSessions;
1496
1496
  config;
1497
1497
  logger;
1498
+ storage;
1498
1499
  /**
1499
1500
  * Creates a new SessionManager instance
1500
1501
  *
1501
1502
  * @param config - Optional default configuration applied to all new sessions
1502
1503
  * @param logLevel - Optional minimum log level (default: INFO)
1504
+ * @param storage - Optional persistent storage backend for sessions
1503
1505
  *
1504
1506
  * @example
1505
1507
  * ```typescript
1508
+ * // Memory-only mode (default)
1506
1509
  * const manager = new SessionManager({
1507
1510
  * enableAutoSave: true,
1508
1511
  * maxThoughtsInMemory: 500
1509
1512
  * }, LogLevel.DEBUG);
1513
+ *
1514
+ * // With file-based persistence
1515
+ * import { FileSessionStore } from './storage/file-store.js';
1516
+ * const storage = new FileSessionStore('./sessions');
1517
+ * await storage.initialize();
1518
+ * const manager = new SessionManager({}, LogLevel.INFO, storage);
1510
1519
  * ```
1511
1520
  */
1512
- constructor(config, logLevel) {
1521
+ constructor(config, logLevel, storage) {
1513
1522
  this.activeSessions = /* @__PURE__ */ new Map();
1514
1523
  this.config = config || {};
1524
+ this.storage = storage;
1515
1525
  this.logger = createLogger({
1516
1526
  minLevel: logLevel || 1 /* INFO */,
1517
1527
  enableConsole: true
@@ -1564,6 +1574,14 @@ var SessionManager = class {
1564
1574
  collaborators: author ? [author] : []
1565
1575
  };
1566
1576
  this.activeSessions.set(sessionId, session);
1577
+ if (this.storage && session.config.enableAutoSave) {
1578
+ try {
1579
+ await this.storage.saveSession(session);
1580
+ this.logger.debug("Session persisted to storage", { sessionId });
1581
+ } catch (error) {
1582
+ this.logger.error("Failed to persist session", error, { sessionId });
1583
+ }
1584
+ }
1567
1585
  this.logger.info("Session created", {
1568
1586
  sessionId,
1569
1587
  title,
@@ -1576,7 +1594,8 @@ var SessionManager = class {
1576
1594
  /**
1577
1595
  * Get a session by ID
1578
1596
  *
1579
- * Retrieves an active session by its unique identifier.
1597
+ * Retrieves a session by its unique identifier. If the session is not in memory
1598
+ * but storage is available, it will attempt to load from storage.
1580
1599
  *
1581
1600
  * @param sessionId - Unique UUID v4 identifier of the session
1582
1601
  * @returns Promise resolving to the session, or null if not found
@@ -1591,7 +1610,19 @@ var SessionManager = class {
1591
1610
  * ```
1592
1611
  */
1593
1612
  async getSession(sessionId) {
1594
- return this.activeSessions.get(sessionId) || null;
1613
+ let session = this.activeSessions.get(sessionId);
1614
+ if (!session && this.storage) {
1615
+ try {
1616
+ session = await this.storage.loadSession(sessionId);
1617
+ if (session) {
1618
+ this.activeSessions.set(sessionId, session);
1619
+ this.logger.debug("Session loaded from storage", { sessionId });
1620
+ }
1621
+ } catch (error) {
1622
+ this.logger.error("Failed to load session from storage", error, { sessionId });
1623
+ }
1624
+ }
1625
+ return session || null;
1595
1626
  }
1596
1627
  /**
1597
1628
  * Add a thought to a session
@@ -1642,6 +1673,14 @@ var SessionManager = class {
1642
1673
  totalThoughts: session.thoughts.length
1643
1674
  });
1644
1675
  }
1676
+ if (this.storage && session.config.enableAutoSave) {
1677
+ try {
1678
+ await this.storage.saveSession(session);
1679
+ this.logger.debug("Session persisted after thought added", { sessionId });
1680
+ } catch (error) {
1681
+ this.logger.error("Failed to persist session", error, { sessionId });
1682
+ }
1683
+ }
1645
1684
  this.logger.debug("Thought added", {
1646
1685
  sessionId,
1647
1686
  thoughtNumber: thought.thoughtNumber,
@@ -1681,6 +1720,14 @@ var SessionManager = class {
1681
1720
  session.mode = newMode;
1682
1721
  session.config.modeConfig.mode = newMode;
1683
1722
  session.updatedAt = /* @__PURE__ */ new Date();
1723
+ if (this.storage && session.config.enableAutoSave) {
1724
+ try {
1725
+ await this.storage.saveSession(session);
1726
+ this.logger.debug("Session persisted after mode switch", { sessionId });
1727
+ } catch (error) {
1728
+ this.logger.error("Failed to persist session", error, { sessionId });
1729
+ }
1730
+ }
1684
1731
  this.logger.info("Session mode switched", {
1685
1732
  sessionId,
1686
1733
  oldMode,
@@ -1692,9 +1739,10 @@ var SessionManager = class {
1692
1739
  /**
1693
1740
  * List all active sessions with metadata
1694
1741
  *
1695
- * Returns summary information for all sessions currently managed
1696
- * by this SessionManager instance.
1742
+ * Returns summary information for all sessions. If storage is available,
1743
+ * includes both in-memory sessions and persisted sessions.
1697
1744
  *
1745
+ * @param includeStoredSessions - Whether to include sessions from storage (default: true)
1698
1746
  * @returns Promise resolving to array of session metadata
1699
1747
  *
1700
1748
  * @example
@@ -1705,8 +1753,8 @@ var SessionManager = class {
1705
1753
  * });
1706
1754
  * ```
1707
1755
  */
1708
- async listSessions() {
1709
- return Array.from(this.activeSessions.values()).map((session) => ({
1756
+ async listSessions(includeStoredSessions = true) {
1757
+ const memoryMetadata = Array.from(this.activeSessions.values()).map((session) => ({
1710
1758
  id: session.id,
1711
1759
  title: session.title,
1712
1760
  createdAt: session.createdAt,
@@ -1715,11 +1763,27 @@ var SessionManager = class {
1715
1763
  mode: session.mode,
1716
1764
  isComplete: session.isComplete
1717
1765
  }));
1766
+ if (!this.storage || !includeStoredSessions) {
1767
+ return memoryMetadata;
1768
+ }
1769
+ try {
1770
+ const storedMetadata = await this.storage.listSessions();
1771
+ const memoryIds = new Set(memoryMetadata.map((s) => s.id));
1772
+ const combined = [
1773
+ ...memoryMetadata,
1774
+ ...storedMetadata.filter((s) => !memoryIds.has(s.id))
1775
+ ];
1776
+ return combined;
1777
+ } catch (error) {
1778
+ this.logger.error("Failed to list stored sessions", error);
1779
+ return memoryMetadata;
1780
+ }
1718
1781
  }
1719
1782
  /**
1720
1783
  * Delete a session
1721
1784
  *
1722
- * Removes a session from memory. This operation cannot be undone.
1785
+ * Removes a session from memory and storage (if available).
1786
+ * This operation cannot be undone.
1723
1787
  *
1724
1788
  * @param sessionId - ID of the session to delete
1725
1789
  * @returns Promise that resolves when deletion is complete
@@ -1731,15 +1795,23 @@ var SessionManager = class {
1731
1795
  */
1732
1796
  async deleteSession(sessionId) {
1733
1797
  const session = this.activeSessions.get(sessionId);
1734
- const deleted = this.activeSessions.delete(sessionId);
1735
- if (deleted && session) {
1798
+ const deletedFromMemory = this.activeSessions.delete(sessionId);
1799
+ if (this.storage) {
1800
+ try {
1801
+ await this.storage.deleteSession(sessionId);
1802
+ this.logger.debug("Session deleted from storage", { sessionId });
1803
+ } catch (error) {
1804
+ this.logger.error("Failed to delete session from storage", error, { sessionId });
1805
+ }
1806
+ }
1807
+ if (deletedFromMemory && session) {
1736
1808
  this.logger.info("Session deleted", {
1737
1809
  sessionId,
1738
1810
  title: session.title,
1739
1811
  thoughtCount: session.thoughts.length
1740
1812
  });
1741
1813
  } else {
1742
- this.logger.warn("Attempted to delete non-existent session", { sessionId });
1814
+ this.logger.warn("Attempted to delete non-existent session from memory", { sessionId });
1743
1815
  }
1744
1816
  }
1745
1817
  /**