tracelattice 1.3.2 → 1.3.4

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.
Files changed (185) hide show
  1. package/README.md +25 -25
  2. package/dist/ServerConfig.d.ts +16 -23
  3. package/dist/ServerConfig.d.ts.map +1 -1
  4. package/dist/ServerConfig.js +12 -1
  5. package/dist/ServerConfig.js.map +1 -1
  6. package/dist/__tests__/core/HistoryManager.ownership.test.d.ts +2 -0
  7. package/dist/__tests__/core/HistoryManager.ownership.test.d.ts.map +1 -0
  8. package/dist/__tests__/core/SessionLock.test.d.ts +6 -0
  9. package/dist/__tests__/core/SessionLock.test.d.ts.map +1 -0
  10. package/dist/__tests__/core/SessionManager.test.d.ts +8 -0
  11. package/dist/__tests__/core/SessionManager.test.d.ts.map +1 -0
  12. package/dist/__tests__/core/ThoughtProcessor.toolAllowlist.test.d.ts +2 -0
  13. package/dist/__tests__/core/ThoughtProcessor.toolAllowlist.test.d.ts.map +1 -0
  14. package/dist/__tests__/eval/fixtures/scenarios.d.ts.map +1 -1
  15. package/dist/__tests__/helpers/factories.d.ts +20 -1
  16. package/dist/__tests__/helpers/factories.d.ts.map +1 -1
  17. package/dist/__tests__/sanitize.enforceJsonShape.test.d.ts +2 -0
  18. package/dist/__tests__/sanitize.enforceJsonShape.test.d.ts.map +1 -0
  19. package/dist/__tests__/transport-owner-context.test.d.ts +8 -0
  20. package/dist/__tests__/transport-owner-context.test.d.ts.map +1 -0
  21. package/dist/cache/DiscoveryCache.d.ts +1 -1
  22. package/dist/cache/DiscoveryCache.d.ts.map +1 -1
  23. package/dist/cache/DiscoveryCache.js.map +1 -1
  24. package/dist/cli.js +3602 -8
  25. package/dist/config/ConfigLoader.d.ts +9 -2
  26. package/dist/config/ConfigLoader.d.ts.map +1 -1
  27. package/dist/config/ConfigLoader.js +12 -5
  28. package/dist/config/ConfigLoader.js.map +1 -1
  29. package/dist/context/RequestContext.d.ts +26 -0
  30. package/dist/context/RequestContext.d.ts.map +1 -1
  31. package/dist/context/RequestContext.js +7 -1
  32. package/dist/context/RequestContext.js.map +1 -1
  33. package/dist/contracts/PersistenceBackend.d.ts.map +1 -0
  34. package/dist/contracts/features.d.ts +39 -0
  35. package/dist/contracts/features.d.ts.map +1 -0
  36. package/dist/contracts/features.js +15 -0
  37. package/dist/contracts/features.js.map +1 -0
  38. package/dist/contracts/ids.d.ts +58 -0
  39. package/dist/contracts/ids.d.ts.map +1 -0
  40. package/dist/contracts/ids.js +31 -0
  41. package/dist/contracts/ids.js.map +1 -0
  42. package/dist/contracts/interfaces.d.ts +48 -3
  43. package/dist/contracts/interfaces.d.ts.map +1 -1
  44. package/dist/contracts/strategy.d.ts +2 -2
  45. package/dist/contracts/strategy.d.ts.map +1 -1
  46. package/dist/contracts/suspension.d.ts +3 -2
  47. package/dist/contracts/suspension.d.ts.map +1 -1
  48. package/dist/contracts/transport.d.ts +25 -0
  49. package/dist/contracts/transport.d.ts.map +1 -0
  50. package/dist/core/HistoryManager.d.ts +15 -4
  51. package/dist/core/HistoryManager.d.ts.map +1 -1
  52. package/dist/core/HistoryManager.js +25 -14
  53. package/dist/core/HistoryManager.js.map +1 -1
  54. package/dist/core/IHistoryManager.d.ts +10 -0
  55. package/dist/core/IHistoryManager.d.ts.map +1 -1
  56. package/dist/core/IThoughtFormatter.d.ts +51 -0
  57. package/dist/core/IThoughtFormatter.d.ts.map +1 -0
  58. package/dist/core/IThoughtFormatter.js +1 -0
  59. package/dist/core/InputNormalizer.d.ts.map +1 -1
  60. package/dist/core/InputNormalizer.js +9 -5
  61. package/dist/core/InputNormalizer.js.map +1 -1
  62. package/dist/core/PersistenceBuffer.d.ts +1 -1
  63. package/dist/core/PersistenceBuffer.d.ts.map +1 -1
  64. package/dist/core/PersistenceBuffer.js.map +1 -1
  65. package/dist/core/SessionLock.d.ts +56 -0
  66. package/dist/core/SessionLock.d.ts.map +1 -0
  67. package/dist/core/SessionLock.js +43 -0
  68. package/dist/core/SessionLock.js.map +1 -0
  69. package/dist/core/SessionManager.d.ts +18 -3
  70. package/dist/core/SessionManager.d.ts.map +1 -1
  71. package/dist/core/SessionManager.js +34 -1
  72. package/dist/core/SessionManager.js.map +1 -1
  73. package/dist/core/ThoughtFormatter.d.ts +2 -1
  74. package/dist/core/ThoughtFormatter.d.ts.map +1 -1
  75. package/dist/core/ThoughtFormatter.js +3 -0
  76. package/dist/core/ThoughtFormatter.js.map +1 -1
  77. package/dist/core/ThoughtProcessor.d.ts +22 -3
  78. package/dist/core/ThoughtProcessor.d.ts.map +1 -1
  79. package/dist/core/ThoughtProcessor.js +41 -16
  80. package/dist/core/ThoughtProcessor.js.map +1 -1
  81. package/dist/core/compression/CompressionService.js +3 -3
  82. package/dist/core/compression/CompressionService.js.map +1 -1
  83. package/dist/core/compression/Summary.d.ts +4 -3
  84. package/dist/core/compression/Summary.d.ts.map +1 -1
  85. package/dist/core/graph/Edge.d.ts +11 -4
  86. package/dist/core/graph/Edge.d.ts.map +1 -1
  87. package/dist/core/graph/EdgeEmitter.js +5 -5
  88. package/dist/core/graph/EdgeEmitter.js.map +1 -1
  89. package/dist/core/reasoning/strategies/StrategyFactory.d.ts +1 -1
  90. package/dist/core/reasoning/strategies/StrategyFactory.d.ts.map +1 -1
  91. package/dist/core/reasoning/strategies/StrategyFactory.js.map +1 -1
  92. package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.d.ts.map +1 -1
  93. package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.js +5 -0
  94. package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.js.map +1 -1
  95. package/dist/core/reasoning.d.ts +8 -1
  96. package/dist/core/reasoning.d.ts.map +1 -1
  97. package/dist/core/step.d.ts +5 -0
  98. package/dist/core/step.d.ts.map +1 -1
  99. package/dist/core/thought.d.ts +4 -3
  100. package/dist/core/thought.d.ts.map +1 -1
  101. package/dist/core/tools/InMemorySuspensionStore.d.ts +3 -1
  102. package/dist/core/tools/InMemorySuspensionStore.d.ts.map +1 -1
  103. package/dist/core/tools/InMemorySuspensionStore.js +2 -2
  104. package/dist/core/tools/InMemorySuspensionStore.js.map +1 -1
  105. package/dist/di/Container.d.ts +6 -3
  106. package/dist/di/Container.d.ts.map +1 -1
  107. package/dist/di/Container.js.map +1 -1
  108. package/dist/di/ServiceRegistry.d.ts +6 -6
  109. package/dist/di/ServiceRegistry.d.ts.map +1 -1
  110. package/dist/errors.d.ts +84 -2
  111. package/dist/errors.d.ts.map +1 -1
  112. package/dist/errors.js +85 -22
  113. package/dist/errors.js.map +1 -1
  114. package/dist/health/HealthChecker.d.ts +1 -1
  115. package/dist/health/HealthChecker.d.ts.map +1 -1
  116. package/dist/health/HealthChecker.js.map +1 -1
  117. package/dist/lib.d.ts +60 -2
  118. package/dist/lib.d.ts.map +1 -1
  119. package/dist/lib.js +9 -3
  120. package/dist/lib.js.map +1 -1
  121. package/dist/persistence/FilePersistence.d.ts +2 -2
  122. package/dist/persistence/FilePersistence.d.ts.map +1 -1
  123. package/dist/persistence/FilePersistence.js.map +1 -1
  124. package/dist/persistence/MemoryPersistence.d.ts +1 -1
  125. package/dist/persistence/MemoryPersistence.d.ts.map +1 -1
  126. package/dist/persistence/MemoryPersistence.js.map +1 -1
  127. package/dist/persistence/PersistenceFactory.d.ts +1 -1
  128. package/dist/persistence/PersistenceFactory.d.ts.map +1 -1
  129. package/dist/persistence/PersistenceFactory.js.map +1 -1
  130. package/dist/persistence/SqlitePersistence.d.ts +1 -1
  131. package/dist/persistence/SqlitePersistence.d.ts.map +1 -1
  132. package/dist/persistence/SqlitePersistence.js.map +1 -1
  133. package/dist/pool/ConnectionPool.d.ts +11 -13
  134. package/dist/pool/ConnectionPool.d.ts.map +1 -1
  135. package/dist/pool/ConnectionPool.js.map +1 -1
  136. package/dist/pool/IConnectionPool.d.ts +100 -0
  137. package/dist/pool/IConnectionPool.d.ts.map +1 -0
  138. package/dist/pool/IConnectionPool.js +1 -0
  139. package/dist/registry/BaseRegistry.d.ts +1 -1
  140. package/dist/registry/BaseRegistry.d.ts.map +1 -1
  141. package/dist/registry/BaseRegistry.js.map +1 -1
  142. package/dist/registry/ToolRegistry.d.ts +1 -0
  143. package/dist/registry/ToolRegistry.d.ts.map +1 -1
  144. package/dist/registry/ToolRegistry.js +3 -0
  145. package/dist/registry/ToolRegistry.js.map +1 -1
  146. package/dist/sanitize.d.ts +70 -0
  147. package/dist/sanitize.d.ts.map +1 -1
  148. package/dist/sanitize.js +77 -1
  149. package/dist/sanitize.js.map +1 -1
  150. package/dist/schema.d.ts +35 -35
  151. package/dist/schema.d.ts.map +1 -1
  152. package/dist/schema.js +15 -5
  153. package/dist/schema.js.map +1 -1
  154. package/dist/transport/BaseTransport.d.ts +3 -2
  155. package/dist/transport/BaseTransport.d.ts.map +1 -1
  156. package/dist/transport/BaseTransport.js +1 -1
  157. package/dist/transport/BaseTransport.js.map +1 -1
  158. package/dist/transport/HttpTransport.d.ts +4 -2
  159. package/dist/transport/HttpTransport.d.ts.map +1 -1
  160. package/dist/transport/HttpTransport.js +13 -4
  161. package/dist/transport/HttpTransport.js.map +1 -1
  162. package/dist/transport/SseTransport.d.ts +4 -2
  163. package/dist/transport/SseTransport.d.ts.map +1 -1
  164. package/dist/transport/SseTransport.js +13 -3
  165. package/dist/transport/SseTransport.js.map +1 -1
  166. package/dist/transport/StreamableHttpTransport.d.ts +4 -2
  167. package/dist/transport/StreamableHttpTransport.d.ts.map +1 -1
  168. package/dist/transport/StreamableHttpTransport.js +12 -4
  169. package/dist/transport/StreamableHttpTransport.js.map +1 -1
  170. package/dist/types/skill.d.ts +5 -0
  171. package/dist/types/skill.d.ts.map +1 -1
  172. package/dist/types/tool.d.ts +6 -1
  173. package/dist/types/tool.d.ts.map +1 -1
  174. package/package.json +12 -11
  175. package/dist/__tests__/helpers/index.d.ts +0 -3
  176. package/dist/__tests__/helpers/index.d.ts.map +0 -1
  177. package/dist/contracts/index.d.ts +0 -14
  178. package/dist/contracts/index.d.ts.map +0 -1
  179. package/dist/index.d.ts +0 -2
  180. package/dist/index.d.ts.map +0 -1
  181. package/dist/index.js +0 -1
  182. package/dist/persistence/PersistenceBackend.d.ts.map +0 -1
  183. /package/dist/{persistence → contracts}/PersistenceBackend.d.ts +0 -0
  184. /package/dist/{persistence → contracts}/PersistenceBackend.js +0 -0
  185. /package/dist/contracts/{index.js → transport.js} +0 -0
package/dist/errors.js CHANGED
@@ -1,3 +1,33 @@
1
+ const ERROR_CODES = {
2
+ CONFIGURATION_ERROR: 'CONFIGURATION_ERROR',
3
+ TOOL_NOT_FOUND: 'TOOL_NOT_FOUND',
4
+ SKILL_NOT_FOUND: 'SKILL_NOT_FOUND',
5
+ INVALID_THOUGHT: 'INVALID_THOUGHT',
6
+ SKILL_DISCOVERY_FAILED: 'SKILL_DISCOVERY_FAILED',
7
+ HISTORY_LIMIT_EXCEEDED: 'HISTORY_LIMIT_EXCEEDED',
8
+ DUPLICATE_SKILL: 'DUPLICATE_SKILL',
9
+ INVALID_SKILL: 'INVALID_SKILL',
10
+ DUPLICATE_TOOL: 'DUPLICATE_TOOL',
11
+ INVALID_TOOL: 'INVALID_TOOL',
12
+ SESSION_NOT_ACTIVE: 'SESSION_NOT_ACTIVE',
13
+ SESSION_NOT_FOUND: 'SESSION_NOT_FOUND',
14
+ MAX_SESSIONS_REACHED: 'MAX_SESSIONS_REACHED',
15
+ POOL_TERMINATED: 'POOL_TERMINATED',
16
+ VALIDATION_ERROR: 'VALIDATION_ERROR',
17
+ INVALID_EDGE: 'INVALID_EDGE',
18
+ CYCLE_DETECTED: 'CYCLE_DETECTED',
19
+ SUSPENSION_NOT_FOUND: 'SUSPENSION_NOT_FOUND',
20
+ SUSPENSION_EXPIRED: 'SUSPENSION_EXPIRED',
21
+ INVALID_TOOL_CALL: 'INVALID_TOOL_CALL',
22
+ INVALID_BACKTRACK: 'INVALID_BACKTRACK',
23
+ DUPLICATE_SUMMARY: 'DUPLICATE_SUMMARY',
24
+ UNKNOWN_TOOL: 'UNKNOWN_TOOL',
25
+ LOCK_TIMEOUT: 'LOCK_TIMEOUT',
26
+ SESSION_ACCESS_DENIED: 'SESSION_ACCESS_DENIED'
27
+ };
28
+ const WARNING_CODES = {
29
+ TOTAL_THOUGHTS_ADJUSTED: 'TOTAL_THOUGHTS_ADJUSTED'
30
+ };
1
31
  class SequentialThinkingError extends Error {
2
32
  code;
3
33
  constructor(message, code){
@@ -9,139 +39,172 @@ class SequentialThinkingError extends Error {
9
39
  }
10
40
  class ConfigurationError extends SequentialThinkingError {
11
41
  constructor(message){
12
- super(message, 'CONFIGURATION_ERROR');
42
+ super(message, ERROR_CODES.CONFIGURATION_ERROR);
13
43
  this.name = 'ConfigurationError';
14
44
  }
15
45
  }
16
46
  class ToolNotFoundError extends SequentialThinkingError {
17
47
  constructor(toolName, action){
18
48
  const message = action ? `Tool '${toolName}' not found, cannot ${action}` : `Tool '${toolName}' not found`;
19
- super(message, 'TOOL_NOT_FOUND');
49
+ super(message, ERROR_CODES.TOOL_NOT_FOUND);
20
50
  this.name = 'ToolNotFoundError';
21
51
  }
22
52
  }
23
53
  class SkillNotFoundError extends SequentialThinkingError {
24
54
  constructor(skillName, action){
25
55
  const message = action ? `Skill '${skillName}' not found, cannot ${action}` : `Skill '${skillName}' not found`;
26
- super(message, 'SKILL_NOT_FOUND');
56
+ super(message, ERROR_CODES.SKILL_NOT_FOUND);
27
57
  this.name = 'SkillNotFoundError';
28
58
  }
29
59
  }
30
60
  class InvalidThoughtError extends SequentialThinkingError {
31
61
  constructor(thoughtNumber, reason){
32
- super(`Invalid thought ${thoughtNumber}: ${reason}`, 'INVALID_THOUGHT');
62
+ super(`Invalid thought ${thoughtNumber}: ${reason}`, ERROR_CODES.INVALID_THOUGHT);
33
63
  this.name = 'InvalidThoughtError';
34
64
  }
35
65
  }
36
66
  class SkillDiscoveryError extends SequentialThinkingError {
37
67
  cause;
38
68
  constructor(directory, cause){
39
- super(`Failed to discover skills in ${directory}: ${cause.message}`, 'SKILL_DISCOVERY_FAILED');
69
+ super(`Failed to discover skills in ${directory}: ${cause.message}`, ERROR_CODES.SKILL_DISCOVERY_FAILED);
40
70
  this.name = 'SkillDiscoveryError';
41
71
  this.cause = cause;
42
72
  }
43
73
  }
44
74
  class HistoryLimitExceededError extends SequentialThinkingError {
45
75
  constructor(currentSize, maxSize){
46
- super(`History size ${currentSize} exceeds limit ${maxSize}`, 'HISTORY_LIMIT_EXCEEDED');
76
+ super(`History size ${currentSize} exceeds limit ${maxSize}`, ERROR_CODES.HISTORY_LIMIT_EXCEEDED);
47
77
  this.name = 'HistoryLimitExceededError';
48
78
  }
49
79
  }
50
80
  class DuplicateSkillError extends SequentialThinkingError {
51
81
  constructor(skillName){
52
- super(`skill '${skillName}' already exists`, 'DUPLICATE_SKILL');
82
+ super(`skill '${skillName}' already exists`, ERROR_CODES.DUPLICATE_SKILL);
53
83
  this.name = 'DuplicateSkillError';
54
84
  }
55
85
  }
56
86
  class InvalidSkillError extends SequentialThinkingError {
57
87
  constructor(reason){
58
- super(`Invalid skill: ${reason}`, 'INVALID_SKILL');
88
+ super(`Invalid skill: ${reason}`, ERROR_CODES.INVALID_SKILL);
59
89
  this.name = 'InvalidSkillError';
60
90
  }
61
91
  }
62
92
  class DuplicateToolError extends SequentialThinkingError {
63
93
  constructor(toolName){
64
- super(`tool '${toolName}' already exists`, 'DUPLICATE_TOOL');
94
+ super(`tool '${toolName}' already exists`, ERROR_CODES.DUPLICATE_TOOL);
65
95
  this.name = 'DuplicateToolError';
66
96
  }
67
97
  }
68
98
  class InvalidToolError extends SequentialThinkingError {
69
99
  constructor(reason){
70
- super(`Invalid tool: ${reason}`, 'INVALID_TOOL');
100
+ super(`Invalid tool: ${reason}`, ERROR_CODES.INVALID_TOOL);
71
101
  this.name = 'InvalidToolError';
72
102
  }
73
103
  }
74
104
  class SessionNotActiveError extends SequentialThinkingError {
75
105
  constructor(sessionId){
76
- super(`Session '${sessionId}' is not active`, 'SESSION_NOT_ACTIVE');
106
+ super(`Session '${sessionId}' is not active`, ERROR_CODES.SESSION_NOT_ACTIVE);
77
107
  this.name = 'SessionNotActiveError';
78
108
  }
79
109
  }
80
110
  class SessionNotFoundError extends SequentialThinkingError {
81
111
  constructor(sessionId){
82
- super(`Session not found: ${sessionId}`, 'SESSION_NOT_FOUND');
112
+ super(`Session not found: ${sessionId}`, ERROR_CODES.SESSION_NOT_FOUND);
83
113
  this.name = 'SessionNotFoundError';
84
114
  }
85
115
  }
86
116
  class MaxSessionsReachedError extends SequentialThinkingError {
87
117
  constructor(maxSessions){
88
- super(`Max sessions (${maxSessions}) reached. Wait for a session to close or increase maxSessions.`, 'MAX_SESSIONS_REACHED');
118
+ super(`Max sessions (${maxSessions}) reached. Wait for a session to close or increase maxSessions.`, ERROR_CODES.MAX_SESSIONS_REACHED);
89
119
  this.name = 'MaxSessionsReachedError';
90
120
  }
91
121
  }
92
122
  class PoolTerminatedError extends SequentialThinkingError {
93
123
  constructor(){
94
- super('ConnectionPool has been terminated', 'POOL_TERMINATED');
124
+ super('ConnectionPool has been terminated', ERROR_CODES.POOL_TERMINATED);
95
125
  this.name = 'PoolTerminatedError';
96
126
  }
97
127
  }
98
128
  class ValidationError extends SequentialThinkingError {
99
129
  field;
100
130
  constructor(field, reason){
101
- super(`Validation failed for '${field}': ${reason}`, 'VALIDATION_ERROR');
131
+ super(`Validation failed for '${field}': ${reason}`, ERROR_CODES.VALIDATION_ERROR);
102
132
  this.name = 'ValidationError';
103
133
  this.field = field;
104
134
  }
105
135
  }
106
136
  class InvalidEdgeError extends SequentialThinkingError {
107
137
  constructor(message){
108
- super(message, 'INVALID_EDGE');
138
+ super(message, ERROR_CODES.INVALID_EDGE);
109
139
  this.name = 'InvalidEdgeError';
110
140
  }
111
141
  }
112
142
  class CycleDetectedError extends SequentialThinkingError {
113
143
  constructor(message){
114
- super(message, 'CYCLE_DETECTED');
144
+ super(message, ERROR_CODES.CYCLE_DETECTED);
115
145
  this.name = 'CycleDetectedError';
116
146
  }
117
147
  }
118
148
  class SuspensionNotFoundError extends SequentialThinkingError {
119
149
  constructor(message){
120
- super(message, 'SUSPENSION_NOT_FOUND');
150
+ super(message, ERROR_CODES.SUSPENSION_NOT_FOUND);
121
151
  this.name = 'SuspensionNotFoundError';
122
152
  }
123
153
  }
124
154
  class SuspensionExpiredError extends SequentialThinkingError {
125
155
  constructor(message){
126
- super(message, 'SUSPENSION_EXPIRED');
156
+ super(message, ERROR_CODES.SUSPENSION_EXPIRED);
127
157
  this.name = 'SuspensionExpiredError';
128
158
  }
129
159
  }
130
160
  class InvalidToolCallError extends SequentialThinkingError {
131
161
  constructor(message){
132
- super(message, 'INVALID_TOOL_CALL');
162
+ super(message, ERROR_CODES.INVALID_TOOL_CALL);
133
163
  this.name = 'InvalidToolCallError';
134
164
  }
135
165
  }
136
166
  class InvalidBacktrackError extends SequentialThinkingError {
137
167
  constructor(message){
138
- super(message, 'INVALID_BACKTRACK');
168
+ super(message, ERROR_CODES.INVALID_BACKTRACK);
139
169
  this.name = 'InvalidBacktrackError';
140
170
  }
141
171
  }
172
+ class UnknownToolError extends SequentialThinkingError {
173
+ toolName;
174
+ constructor(toolName, message){
175
+ super(message ?? `Unknown tool '${toolName}': not registered with the server`, ERROR_CODES.UNKNOWN_TOOL);
176
+ this.name = 'UnknownToolError';
177
+ this.toolName = toolName;
178
+ }
179
+ }
180
+ class LockTimeoutError extends SequentialThinkingError {
181
+ sessionId;
182
+ timeoutMs;
183
+ constructor(sessionId, timeoutMs){
184
+ super(`Lock timeout for session '${sessionId}' after ${timeoutMs}ms`, ERROR_CODES.LOCK_TIMEOUT);
185
+ this.name = 'LockTimeoutError';
186
+ this.sessionId = sessionId;
187
+ this.timeoutMs = timeoutMs;
188
+ }
189
+ }
190
+ class SessionAccessDeniedError extends SequentialThinkingError {
191
+ sessionId;
192
+ expectedOwner;
193
+ actualOwner;
194
+ constructor(sessionId, expectedOwner, actualOwner){
195
+ super(`Access denied to session '${sessionId}': owned by '${expectedOwner}', accessed by '${actualOwner ?? 'anonymous'}'`, ERROR_CODES.SESSION_ACCESS_DENIED);
196
+ this.name = 'SessionAccessDeniedError';
197
+ this.sessionId = sessionId;
198
+ this.expectedOwner = expectedOwner;
199
+ this.actualOwner = actualOwner;
200
+ }
201
+ }
202
+ function isErrorCode(err, code) {
203
+ return err instanceof SequentialThinkingError && err.code === code;
204
+ }
142
205
  function getErrorMessage(error) {
143
206
  return error instanceof Error ? error.message : String(error);
144
207
  }
145
- export { ConfigurationError, CycleDetectedError, DuplicateSkillError, DuplicateToolError, HistoryLimitExceededError, InvalidBacktrackError, InvalidEdgeError, InvalidSkillError, InvalidThoughtError, InvalidToolCallError, InvalidToolError, MaxSessionsReachedError, PoolTerminatedError, SequentialThinkingError, SessionNotActiveError, SessionNotFoundError, SkillDiscoveryError, SkillNotFoundError, SuspensionExpiredError, SuspensionNotFoundError, ToolNotFoundError, ValidationError, getErrorMessage };
208
+ export { ConfigurationError, CycleDetectedError, DuplicateSkillError, DuplicateToolError, ERROR_CODES, HistoryLimitExceededError, InvalidBacktrackError, InvalidEdgeError, InvalidSkillError, InvalidThoughtError, InvalidToolCallError, InvalidToolError, LockTimeoutError, MaxSessionsReachedError, PoolTerminatedError, SequentialThinkingError, SessionAccessDeniedError, SessionNotActiveError, SessionNotFoundError, SkillDiscoveryError, SkillNotFoundError, SuspensionExpiredError, SuspensionNotFoundError, ToolNotFoundError, UnknownToolError, ValidationError, WARNING_CODES, getErrorMessage, isErrorCode };
146
209
 
147
210
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sources":["../src/errors.ts"],"sourcesContent":["/**\n * Custom error types for the TraceLattice server.\n *\n * This module defines a hierarchy of error classes for handling various\n * error conditions that can occur in the sequential thinking server.\n * All errors extend the base `SequentialThinkingError` class with\n * specific error codes for programmatic handling.\n *\n * @example\n * ```typescript\n * import { ToolNotFoundError, SkillDiscoveryError } from './errors.js';\n *\n * // Throw a tool not found error\n * throw new ToolNotFoundError('my-tool');\n *\n * // Catch and handle specific errors\n * try {\n * await discoverSkills(dir);\n * } catch (error) {\n * if (error instanceof SkillDiscoveryError) {\n * console.error(`Failed to discover skills: ${error.message}`);\n * console.error(`Error code: ${error.code}`);\n * }\n * }\n * ```\n * @module errors\n */\n\n/**\n * Base error class for all Sequential Thinking server errors.\n *\n * This error extends the native `Error` class and adds a `code` property\n * for programmatic error identification and handling. All specific error\n * types in the system extend this base class.\n *\n * @remarks\n * **Error Codes:**\n * - `TOOL_NOT_FOUND` - A requested tool was not found\n * - `SKILL_NOT_FOUND` - A requested skill was not found\n * - `INVALID_THOUGHT` - Thought validation failed\n * - `SKILL_DISCOVERY_FAILED` - Skill discovery operation failed\n * - `HISTORY_LIMIT_EXCEEDED` - History size limit was exceeded\n * - `INVALID_EDGE` - An invalid edge operation was attempted\n *\n * @example\n * ```typescript\n * // Throw a custom sequential thinking error\n * throw new SequentialThinkingError('Custom error message', 'CUSTOM_CODE');\n *\n * // Check if an error is a SequentialThinkingError\n * if (error instanceof SequentialThinkingError) {\n * console.error(`Error [${error.code}]: ${error.message}`);\n * }\n * ```\n */\nexport class SequentialThinkingError extends Error {\n\t/** The error code for programmatic identification. */\n\tpublic readonly code: string;\n\n\t/**\n\t * Creates a new SequentialThinkingError.\n\t *\n\t * @param message - Human-readable error message\n\t * @param code - Error code for programmatic handling\n\t *\n\t * @example\n\t * ```typescript\n\t * const error = new SequentialThinkingError(\n\t * 'Something went wrong',\n\t * 'CUSTOM_ERROR'\n\t * );\n\t * console.log(error.code); // 'CUSTOM_ERROR'\n\t * ```\n\t */\n\tconstructor(message: string, code: string) {\n\t\tsuper(message);\n\t\tthis.code = code;\n\t\tthis.name = 'SequentialThinkingError';\n\t\tError.captureStackTrace(this, this.constructor);\n\t}\n}\n\nexport class ConfigurationError extends SequentialThinkingError {\n\tconstructor(message: string) {\n\t\tsuper(message, 'CONFIGURATION_ERROR');\n\t\tthis.name = 'ConfigurationError';\n\t}\n}\n\n/**\n * Error thrown when a requested tool is not found in the registry.\n *\n * This error is thrown when attempting to retrieve, update, or delete\n * a tool that doesn't exist in the tool registry.\n *\n * @example\n * ```typescript\n * const tool = registry.getTool('non-existent-tool');\n * if (!tool) {\n * throw new ToolNotFoundError('non-existent-tool');\n * }\n * ```\n */\nexport class ToolNotFoundError extends SequentialThinkingError {\n\t/**\n\t * Creates a new ToolNotFoundError.\n\t *\n\t * @param toolName - The name of the tool that was not found\n\t * @param action - Optional action being performed (e.g., 'remove', 'update')\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new ToolNotFoundError('my-custom-tool');\n\t * // Error: tool 'my-custom-tool' not found\n\t *\n\t * throw new ToolNotFoundError('my-custom-tool', 'remove');\n\t * // Error: tool 'my-custom-tool' not found, cannot remove\n\t * // Code: TOOL_NOT_FOUND\n\t * ```\n\t */\n\tconstructor(toolName: string, action?: string) {\n\t\tconst message = action\n\t\t\t? `Tool '${toolName}' not found, cannot ${action}`\n\t\t\t: `Tool '${toolName}' not found`;\n\t\tsuper(message, 'TOOL_NOT_FOUND');\n\t\tthis.name = 'ToolNotFoundError';\n\t}\n}\n\n/**\n * Error thrown when a requested skill is not found in the registry.\n *\n * This error is thrown when attempting to retrieve, update, or delete\n * a skill that doesn't exist in the skill registry.\n *\n * @example\n * ```typescript\n * const skill = registry.getSkill('non-existent-skill');\n * if (!skill) {\n * throw new SkillNotFoundError('non-existent-skill');\n * }\n * ```\n */\nexport class SkillNotFoundError extends SequentialThinkingError {\n\t/**\n\t * Creates a new SkillNotFoundError.\n\t *\n\t * @param skillName - The name of the skill that was not found\n\t * @param action - Optional action being performed (e.g., 'remove', 'update')\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new SkillNotFoundError('my-custom-skill');\n\t * // Error: skill 'my-custom-skill' not found\n\t *\n\t * throw new SkillNotFoundError('my-custom-skill', 'remove');\n\t * // Error: skill 'my-custom-skill' not found, cannot remove\n\t * // Code: SKILL_NOT_FOUND\n\t * ```\n\t */\n\tconstructor(skillName: string, action?: string) {\n\t\tconst message = action\n\t\t\t? `Skill '${skillName}' not found, cannot ${action}`\n\t\t\t: `Skill '${skillName}' not found`;\n\t\tsuper(message, 'SKILL_NOT_FOUND');\n\t\tthis.name = 'SkillNotFoundError';\n\t}\n}\n\n/**\n * Error thrown when thought validation fails.\n *\n * This error is thrown when a thought fails validation, typically due to\n * invalid values, missing required fields, or constraint violations.\n *\n * @example\n * ```typescript\n * // Validate thought number\n * if (thought.thought_number < 1) {\n * throw new InvalidThoughtError(thought.thought_number, 'thought_number must be >= 1');\n * }\n * ```\n */\nexport class InvalidThoughtError extends SequentialThinkingError {\n\t/**\n\t * Creates a new InvalidThoughtError.\n\t *\n\t * @param thoughtNumber - The thought number that failed validation\n\t * @param reason - Human-readable explanation of why validation failed\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new InvalidThoughtError(5, 'thought_number exceeds total_thoughts');\n\t * // Error: Invalid thought 5: thought_number exceeds total_thoughts\n\t * // Code: INVALID_THOUGHT\n\t * ```\n\t */\n\tconstructor(thoughtNumber: number, reason: string) {\n\t\tsuper(`Invalid thought ${thoughtNumber}: ${reason}`, 'INVALID_THOUGHT');\n\t\tthis.name = 'InvalidThoughtError';\n\t}\n}\n\n/**\n * Error thrown when skill discovery fails.\n *\n * This error is thrown when the skill discovery process encounters an issue,\n * such as filesystem errors, invalid skill files, or parsing failures.\n *\n * @remarks\n * The original error that caused the discovery failure is preserved in the\n * `cause` property for debugging purposes.\n *\n * @example\n * ```typescript\n * try {\n * await discoverSkills('./skills');\n * } catch (error) {\n * throw new SkillDiscoveryError('./skills', error as Error);\n * }\n * ```\n */\nexport class SkillDiscoveryError extends SequentialThinkingError {\n\t/** The underlying error that caused the discovery failure. */\n\tpublic override readonly cause: Error;\n\n\t/**\n\t * Creates a new SkillDiscoveryError.\n\t *\n\t * @param directory - The directory where discovery failed\n\t * @param cause - The underlying error that caused the failure\n\t *\n\t * @example\n\t * ```typescript\n\t * try {\n\t * const skills = await loadSkills('./invalid-directory');\n\t * } catch (error) {\n\t * throw new SkillDiscoveryError('./invalid-directory', error as Error);\n\t * }\n\t * ```\n\t */\n\tconstructor(directory: string, cause: Error) {\n\t\tsuper(`Failed to discover skills in ${directory}: ${cause.message}`, 'SKILL_DISCOVERY_FAILED');\n\t\tthis.name = 'SkillDiscoveryError';\n\t\tthis.cause = cause;\n\t}\n}\n\n/**\n * Error thrown when history size exceeds the configured limit.\n *\n * This error is thrown when an operation would cause the history size\n * to exceed the maximum configured size limit.\n *\n * @example\n * ```typescript\n * if (history.length >= maxSize) {\n * throw new HistoryLimitExceededError(history.length, maxSize);\n * }\n * ```\n */\nexport class HistoryLimitExceededError extends SequentialThinkingError {\n\t/**\n\t * Creates a new HistoryLimitExceededError.\n\t *\n\t * @param currentSize - The current history size\n\t * @param maxSize - The maximum allowed size\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new HistoryLimitExceededError(1500, 1000);\n\t * // Error: History size 1500 exceeds limit 1000\n\t * // Code: HISTORY_LIMIT_EXCEEDED\n\t * ```\n\t */\n\tconstructor(currentSize: number, maxSize: number) {\n\t\tsuper(`History size ${currentSize} exceeds limit ${maxSize}`, 'HISTORY_LIMIT_EXCEEDED');\n\t\tthis.name = 'HistoryLimitExceededError';\n\t}\n}\n\n/**\n * Error thrown when attempting to add a skill that already exists.\n *\n * This error is thrown when trying to register a skill with a name that\n * is already present in the skill registry.\n *\n * @example\n * ```typescript\n * if (registry.hasSkill(skill.name)) {\n * throw new DuplicateSkillError(skill.name);\n * }\n * ```\n */\nexport class DuplicateSkillError extends SequentialThinkingError {\n\t/**\n\t * Creates a new DuplicateSkillError.\n\t *\n\t * @param skillName - The name of the duplicate skill\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new DuplicateSkillError('my-skill');\n\t * // Error: skill 'my-skill' already exists\n\t * // Code: DUPLICATE_SKILL\n\t * ```\n\t */\n\tconstructor(skillName: string) {\n\t\tsuper(`skill '${skillName}' already exists`, 'DUPLICATE_SKILL');\n\t\tthis.name = 'DuplicateSkillError';\n\t}\n}\n\n/**\n * Error thrown when a skill has invalid data.\n *\n * This error is thrown when a skill fails validation, typically due to\n * missing required fields or invalid values.\n *\n * @example\n * ```typescript\n * if (!skill.name) {\n * throw new InvalidSkillError('Skill must have a valid name');\n * }\n * ```\n */\nexport class InvalidSkillError extends SequentialThinkingError {\n\t/**\n\t * Creates a new InvalidSkillError.\n\t *\n\t * @param reason - The reason for the validation failure\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new InvalidSkillError('Skill must have a valid name');\n\t * // Error: Invalid skill: Skill must have a valid name\n\t * // Code: INVALID_SKILL\n\t * ```\n\t */\n\tconstructor(reason: string) {\n\t\tsuper(`Invalid skill: ${reason}`, 'INVALID_SKILL');\n\t\tthis.name = 'InvalidSkillError';\n\t}\n}\n\n/**\n * Error thrown when attempting to add a tool that already exists.\n *\n * This error is thrown when trying to register a tool with a name that\n * is already present in the tool registry.\n *\n * @example\n * ```typescript\n * if (registry.hasTool(tool.name)) {\n * throw new DuplicateToolError(tool.name);\n * }\n * ```\n */\nexport class DuplicateToolError extends SequentialThinkingError {\n\t/**\n\t * Creates a new DuplicateToolError.\n\t *\n\t * @param toolName - The name of the duplicate tool\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new DuplicateToolError('my-tool');\n\t * // Error: tool 'my-tool' already exists\n\t * // Code: DUPLICATE_TOOL\n\t * ```\n\t */\n\tconstructor(toolName: string) {\n\t\tsuper(`tool '${toolName}' already exists`, 'DUPLICATE_TOOL');\n\t\tthis.name = 'DuplicateToolError';\n\t}\n}\n\n/**\n * Error thrown when a tool has invalid data.\n *\n * This error is thrown when a tool fails validation, typically due to\n * missing required fields or invalid values.\n *\n * @example\n * ```typescript\n * if (!tool.name) {\n * throw new InvalidToolError('Tool must have a valid name');\n * }\n * ```\n */\nexport class InvalidToolError extends SequentialThinkingError {\n\t/**\n\t * Creates a new InvalidToolError.\n\t *\n\t * @param reason - The reason for the validation failure\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new InvalidToolError('Tool must have a valid name');\n\t * // Error: Invalid tool: Tool must have a valid name\n\t * // Code: INVALID_TOOL\n\t * ```\n\t */\n\tconstructor(reason: string) {\n\t\tsuper(`Invalid tool: ${reason}`, 'INVALID_TOOL');\n\t\tthis.name = 'InvalidToolError';\n\t}\n}\n\n/**\n * Error thrown when attempting to process a session that is not active.\n *\n * This error is thrown when trying to use a session that has been closed\n * or deactivated.\n *\n * @example\n * ```typescript\n * if (!session.isActive) {\n * throw new SessionNotActiveError(sessionId);\n * }\n * ```\n */\nexport class SessionNotActiveError extends SequentialThinkingError {\n\t/**\n\t * Creates a new SessionNotActiveError.\n\t *\n\t * @param sessionId - The ID of the inactive session\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new SessionNotActiveError('session-123');\n\t * // Error: Session 'session-123' is not active\n\t * // Code: SESSION_NOT_ACTIVE\n\t * ```\n\t */\n\tconstructor(sessionId: string) {\n\t\tsuper(`Session '${sessionId}' is not active`, 'SESSION_NOT_ACTIVE');\n\t\tthis.name = 'SessionNotActiveError';\n\t}\n}\n\n/**\n * Error thrown when a requested session is not found in the pool.\n *\n * This error is thrown when attempting to retrieve, process, or close\n * a session that doesn't exist in the session pool.\n *\n * @example\n * ```typescript\n * const session = pool.getSession('non-existent-session');\n * if (!session) {\n * throw new SessionNotFoundError('non-existent-session');\n * }\n * ```\n */\nexport class SessionNotFoundError extends SequentialThinkingError {\n\t/**\n\t * Creates a new SessionNotFoundError.\n\t *\n\t * @param sessionId - The ID of the session that was not found\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new SessionNotFoundError('session-123');\n\t * // Error: Session not found: session-123\n\t * // Code: SESSION_NOT_FOUND\n\t * ```\n\t */\n\tconstructor(sessionId: string) {\n\t\tsuper(`Session not found: ${sessionId}`, 'SESSION_NOT_FOUND');\n\t\tthis.name = 'SessionNotFoundError';\n\t}\n}\n\n/**\n * Error thrown when the maximum number of sessions has been reached.\n *\n * This error is thrown when trying to create a new session when the\n * pool has reached its configured maximum session limit.\n *\n * @example\n * ```typescript\n * if (pool.sessionCount >= pool.maxSessions) {\n * throw new MaxSessionsReachedError(pool.maxSessions);\n * }\n * ```\n */\nexport class MaxSessionsReachedError extends SequentialThinkingError {\n\t/**\n\t * Creates a new MaxSessionsReachedError.\n\t *\n\t * @param maxSessions - The maximum number of sessions allowed\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new MaxSessionsReachedError(100);\n\t * // Error: Max sessions (100) reached. Wait for a session to close or increase maxSessions.\n\t * // Code: MAX_SESSIONS_REACHED\n\t * ```\n\t */\n\tconstructor(maxSessions: number) {\n\t\tsuper(\n\t\t\t`Max sessions (${maxSessions}) reached. Wait for a session to close or increase maxSessions.`,\n\t\t\t'MAX_SESSIONS_REACHED'\n\t\t);\n\t\tthis.name = 'MaxSessionsReachedError';\n\t}\n}\n\n/**\n * Error thrown when attempting to use a terminated connection pool.\n *\n * This error is thrown when trying to create sessions or process requests\n * after the connection pool has been terminated.\n *\n * @example\n * ```typescript\n * if (pool.isTerminated) {\n * throw new PoolTerminatedError();\n * }\n * ```\n */\nexport class PoolTerminatedError extends SequentialThinkingError {\n\t/**\n\t * Creates a new PoolTerminatedError.\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new PoolTerminatedError();\n\t * // Error: ConnectionPool has been terminated\n\t * // Code: POOL_TERMINATED\n\t * ```\n\t */\n\tconstructor() {\n\t\tsuper('ConnectionPool has been terminated', 'POOL_TERMINATED');\n\t\tthis.name = 'PoolTerminatedError';\n\t}\n}\n\n/**\n * Error thrown when input validation fails due to invalid or malicious data.\n *\n * This error is thrown when user input fails security or format validation,\n * such as path traversal attempts or invalid identifier formats.\n *\n * @example\n * ```typescript\n * if (!BRANCH_ID_PATTERN.test(branchId)) {\n * throw new ValidationError('branchId', 'Invalid format');\n * }\n * ```\n */\nexport class ValidationError extends SequentialThinkingError {\n\t/** The field that failed validation. */\n\tpublic readonly field: string;\n\n\tconstructor(field: string, reason: string) {\n\t\tsuper(`Validation failed for '${field}': ${reason}`, 'VALIDATION_ERROR');\n\t\tthis.name = 'ValidationError';\n\t\tthis.field = field;\n\t}\n}\n\n/**\n * Error thrown when an invalid edge operation is attempted.\n *\n * This error is thrown when attempting to add an edge that violates\n * structural invariants of the thought DAG, such as a self-edge\n * (where `from` and `to` reference the same thought).\n *\n * @example\n * ```typescript\n * if (edge.from === edge.to) {\n * throw new InvalidEdgeError(\n * `Self-edge not allowed: from and to are the same (${edge.from})`\n * );\n * }\n * ```\n */\nexport class InvalidEdgeError extends SequentialThinkingError {\n\t/**\n\t * Creates a new InvalidEdgeError.\n\t *\n\t * @param message - Human-readable explanation of the invalid edge\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new InvalidEdgeError('Self-edge not allowed: from and to are the same (t1)');\n\t * // Code: INVALID_EDGE\n\t * ```\n\t */\n\tconstructor(message: string) {\n\t\tsuper(message, 'INVALID_EDGE');\n\t\tthis.name = 'InvalidEdgeError';\n\t}\n}\n\n/**\n * Error thrown when a cycle is detected during graph traversal.\n *\n * This error is thrown by graph algorithms (such as topological sort)\n * when the thought DAG contains a cycle, violating the acyclic invariant.\n *\n * @example\n * ```typescript\n * try {\n * const order = graphView.topological(sessionId);\n * } catch (error) {\n * if (error instanceof CycleDetectedError) {\n * console.error('Cycle in thought graph:', error.message);\n * }\n * }\n * ```\n */\nexport class CycleDetectedError extends SequentialThinkingError {\n\t/**\n\t * Creates a new CycleDetectedError.\n\t *\n\t * @param message - Human-readable explanation of the cycle\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new CycleDetectedError('Cycle detected in session s1');\n\t * // Code: CYCLE_DETECTED\n\t * ```\n\t */\n\tconstructor(message: string) {\n\t\tsuper(message, 'CYCLE_DETECTED');\n\t\tthis.name = 'CycleDetectedError';\n\t}\n}\n\n/**\n * Error thrown when a suspension record is not found.\n *\n * This error is thrown when attempting to resume a tool interleave\n * suspension that does not exist in the suspension store.\n */\nexport class SuspensionNotFoundError extends SequentialThinkingError {\n\tconstructor(message: string) {\n\t\tsuper(message, 'SUSPENSION_NOT_FOUND');\n\t\tthis.name = 'SuspensionNotFoundError';\n\t}\n}\n\n/**\n * Error thrown when a suspension record has expired.\n *\n * This error is thrown when attempting to resume a tool interleave\n * suspension whose TTL has elapsed.\n */\nexport class SuspensionExpiredError extends SequentialThinkingError {\n\tconstructor(message: string) {\n\t\tsuper(message, 'SUSPENSION_EXPIRED');\n\t\tthis.name = 'SuspensionExpiredError';\n\t}\n}\n\n/**\n * Error thrown when a tool call payload is invalid.\n *\n * This error is thrown when a tool interleave invocation has malformed\n * arguments, missing identifiers, or otherwise fails validation.\n */\nexport class InvalidToolCallError extends SequentialThinkingError {\n\tconstructor(message: string) {\n\t\tsuper(message, 'INVALID_TOOL_CALL');\n\t\tthis.name = 'InvalidToolCallError';\n\t}\n}\n\n/**\n * Error thrown when a backtrack operation is invalid.\n *\n * This error is thrown when an attempt to backtrack the reasoning\n * chain references an unreachable thought or violates DAG invariants.\n */\nexport class InvalidBacktrackError extends SequentialThinkingError {\n\tconstructor(message: string) {\n\t\tsuper(message, 'INVALID_BACKTRACK');\n\t\tthis.name = 'InvalidBacktrackError';\n\t}\n}\n\n/**\n * Extract a human-readable message from an unknown error value.\n *\n * Standardizes the common `error instanceof Error ? error.message : String(error)`\n * pattern used in catch blocks across the codebase.\n *\n * @param error - The unknown error value to extract a message from\n * @returns The error message string\n *\n * @example\n * ```typescript\n * try {\n * await doSomething();\n * } catch (error) {\n * logger.error('Failed', { error: getErrorMessage(error) });\n * }\n * ```\n */\nexport function getErrorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n"],"names":["SequentialThinkingError","Error","message","code","ConfigurationError","ToolNotFoundError","toolName","action","SkillNotFoundError","skillName","InvalidThoughtError","thoughtNumber","reason","SkillDiscoveryError","directory","cause","HistoryLimitExceededError","currentSize","maxSize","DuplicateSkillError","InvalidSkillError","DuplicateToolError","InvalidToolError","SessionNotActiveError","sessionId","SessionNotFoundError","MaxSessionsReachedError","maxSessions","PoolTerminatedError","ValidationError","field","InvalidEdgeError","CycleDetectedError","SuspensionNotFoundError","SuspensionExpiredError","InvalidToolCallError","InvalidBacktrackError","getErrorMessage","error","String"],"mappings":"AAuDO,MAAMA,gCAAgCC;IAE5B,KAAa;IAiB7B,YAAYC,OAAe,EAAEC,IAAY,CAAE;QAC1C,KAAK,CAACD;QACN,IAAI,CAAC,IAAI,GAAGC;QACZ,IAAI,CAAC,IAAI,GAAG;QACZF,MAAM,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW;IAC/C;AACD;AAEO,MAAMG,2BAA2BJ;IACvC,YAAYE,OAAe,CAAE;QAC5B,KAAK,CAACA,SAAS;QACf,IAAI,CAAC,IAAI,GAAG;IACb;AACD;AAgBO,MAAMG,0BAA0BL;IAiBtC,YAAYM,QAAgB,EAAEC,MAAe,CAAE;QAC9C,MAAML,UAAUK,SACb,CAAC,MAAM,EAAED,SAAS,oBAAoB,EAAEC,QAAQ,GAChD,CAAC,MAAM,EAAED,SAAS,WAAW,CAAC;QACjC,KAAK,CAACJ,SAAS;QACf,IAAI,CAAC,IAAI,GAAG;IACb;AACD;AAgBO,MAAMM,2BAA2BR;IAiBvC,YAAYS,SAAiB,EAAEF,MAAe,CAAE;QAC/C,MAAML,UAAUK,SACb,CAAC,OAAO,EAAEE,UAAU,oBAAoB,EAAEF,QAAQ,GAClD,CAAC,OAAO,EAAEE,UAAU,WAAW,CAAC;QACnC,KAAK,CAACP,SAAS;QACf,IAAI,CAAC,IAAI,GAAG;IACb;AACD;AAgBO,MAAMQ,4BAA4BV;IAcxC,YAAYW,aAAqB,EAAEC,MAAc,CAAE;QAClD,KAAK,CAAC,CAAC,gBAAgB,EAAED,cAAc,EAAE,EAAEC,QAAQ,EAAE;QACrD,IAAI,CAAC,IAAI,GAAG;IACb;AACD;AAqBO,MAAMC,4BAA4Bb;IAEf,MAAa;IAiBtC,YAAYc,SAAiB,EAAEC,KAAY,CAAE;QAC5C,KAAK,CAAC,CAAC,6BAA6B,EAAED,UA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 {"version":3,"file":"errors.js","sources":["../src/errors.ts"],"sourcesContent":["/**\n * Custom error types for the TraceLattice server.\n *\n * This module defines a hierarchy of error classes for handling various\n * error conditions that can occur in the sequential thinking server.\n * All errors extend the base `SequentialThinkingError` class with\n * specific error codes for programmatic handling.\n *\n * @example\n * ```typescript\n * import { ToolNotFoundError, SkillDiscoveryError } from './errors.js';\n *\n * // Throw a tool not found error\n * throw new ToolNotFoundError('my-tool');\n *\n * // Catch and handle specific errors\n * try {\n * await discoverSkills(dir);\n * } catch (error) {\n * if (error instanceof SkillDiscoveryError) {\n * console.error(`Failed to discover skills: ${error.message}`);\n * console.error(`Error code: ${error.code}`);\n * }\n * }\n * ```\n * @module errors\n */\n\n/**\n * All known error codes as a const object for exhaustive switching.\n */\nexport const ERROR_CODES = {\n\tCONFIGURATION_ERROR: 'CONFIGURATION_ERROR',\n\tTOOL_NOT_FOUND: 'TOOL_NOT_FOUND',\n\tSKILL_NOT_FOUND: 'SKILL_NOT_FOUND',\n\tINVALID_THOUGHT: 'INVALID_THOUGHT',\n\tSKILL_DISCOVERY_FAILED: 'SKILL_DISCOVERY_FAILED',\n\tHISTORY_LIMIT_EXCEEDED: 'HISTORY_LIMIT_EXCEEDED',\n\tDUPLICATE_SKILL: 'DUPLICATE_SKILL',\n\tINVALID_SKILL: 'INVALID_SKILL',\n\tDUPLICATE_TOOL: 'DUPLICATE_TOOL',\n\tINVALID_TOOL: 'INVALID_TOOL',\n\tSESSION_NOT_ACTIVE: 'SESSION_NOT_ACTIVE',\n\tSESSION_NOT_FOUND: 'SESSION_NOT_FOUND',\n\tMAX_SESSIONS_REACHED: 'MAX_SESSIONS_REACHED',\n\tPOOL_TERMINATED: 'POOL_TERMINATED',\n\tVALIDATION_ERROR: 'VALIDATION_ERROR',\n\tINVALID_EDGE: 'INVALID_EDGE',\n\tCYCLE_DETECTED: 'CYCLE_DETECTED',\n\tSUSPENSION_NOT_FOUND: 'SUSPENSION_NOT_FOUND',\n\tSUSPENSION_EXPIRED: 'SUSPENSION_EXPIRED',\n\tINVALID_TOOL_CALL: 'INVALID_TOOL_CALL',\n\tINVALID_BACKTRACK: 'INVALID_BACKTRACK',\n\tDUPLICATE_SUMMARY: 'DUPLICATE_SUMMARY',\n\tUNKNOWN_TOOL: 'UNKNOWN_TOOL',\n\tLOCK_TIMEOUT: 'LOCK_TIMEOUT',\n\tSESSION_ACCESS_DENIED: 'SESSION_ACCESS_DENIED',\n} as const;\n\nexport type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];\n\n/**\n * All known warning codes as a const object.\n * Warnings are non-fatal advisory signals returned alongside successful results.\n */\nexport const WARNING_CODES = {\n\tTOTAL_THOUGHTS_ADJUSTED: 'TOTAL_THOUGHTS_ADJUSTED',\n} as const;\n\nexport type WarningCode = (typeof WARNING_CODES)[keyof typeof WARNING_CODES];\n\n/**\n * Base error class for all Sequential Thinking server errors.\n *\n * This error extends the native `Error` class and adds a `code` property\n * for programmatic error identification and handling. All specific error\n * types in the system extend this base class.\n *\n * @remarks\n * **Error Codes:**\n * - `TOOL_NOT_FOUND` - A requested tool was not found\n * - `SKILL_NOT_FOUND` - A requested skill was not found\n * - `INVALID_THOUGHT` - Thought validation failed\n * - `SKILL_DISCOVERY_FAILED` - Skill discovery operation failed\n * - `HISTORY_LIMIT_EXCEEDED` - History size limit was exceeded\n * - `INVALID_EDGE` - An invalid edge operation was attempted\n *\n * @example\n * ```typescript\n * // Throw a custom sequential thinking error\n * throw new SequentialThinkingError('Custom error message', 'CUSTOM_CODE');\n *\n * // Check if an error is a SequentialThinkingError\n * if (error instanceof SequentialThinkingError) {\n * console.error(`Error [${error.code}]: ${error.message}`);\n * }\n * ```\n */\nexport class SequentialThinkingError extends Error {\n\t/** The error code for programmatic identification. */\n\tpublic readonly code: ErrorCode;\n\n\t/**\n\t * Creates a new SequentialThinkingError.\n\t *\n\t * @param message - Human-readable error message\n\t * @param code - Error code for programmatic handling\n\t *\n\t * @example\n\t * ```typescript\n\t * const error = new SequentialThinkingError(\n\t * 'Something went wrong',\n\t * 'CUSTOM_ERROR'\n\t * );\n\t * console.log(error.code); // 'CUSTOM_ERROR'\n\t * ```\n\t */\n\tconstructor(message: string, code: ErrorCode) {\n\t\tsuper(message);\n\t\tthis.code = code;\n\t\tthis.name = 'SequentialThinkingError';\n\t\tError.captureStackTrace(this, this.constructor);\n\t}\n}\n\nexport class ConfigurationError extends SequentialThinkingError {\n\tconstructor(message: string) {\n\t\tsuper(message, ERROR_CODES.CONFIGURATION_ERROR);\n\t\tthis.name = 'ConfigurationError';\n\t}\n}\n\n/**\n * Error thrown when a requested tool is not found in the registry.\n *\n * This error is thrown when attempting to retrieve, update, or delete\n * a tool that doesn't exist in the tool registry.\n *\n * @example\n * ```typescript\n * const tool = registry.getTool('non-existent-tool');\n * if (!tool) {\n * throw new ToolNotFoundError('non-existent-tool');\n * }\n * ```\n */\nexport class ToolNotFoundError extends SequentialThinkingError {\n\t/**\n\t * Creates a new ToolNotFoundError.\n\t *\n\t * @param toolName - The name of the tool that was not found\n\t * @param action - Optional action being performed (e.g., 'remove', 'update')\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new ToolNotFoundError('my-custom-tool');\n\t * // Error: tool 'my-custom-tool' not found\n\t *\n\t * throw new ToolNotFoundError('my-custom-tool', 'remove');\n\t * // Error: tool 'my-custom-tool' not found, cannot remove\n\t * // Code: TOOL_NOT_FOUND\n\t * ```\n\t */\n\tconstructor(toolName: string, action?: string) {\n\t\tconst message = action\n\t\t\t? `Tool '${toolName}' not found, cannot ${action}`\n\t\t\t: `Tool '${toolName}' not found`;\n\t\tsuper(message, ERROR_CODES.TOOL_NOT_FOUND);\n\t\tthis.name = 'ToolNotFoundError';\n\t}\n}\n\n/**\n * Error thrown when a requested skill is not found in the registry.\n *\n * This error is thrown when attempting to retrieve, update, or delete\n * a skill that doesn't exist in the skill registry.\n *\n * @example\n * ```typescript\n * const skill = registry.getSkill('non-existent-skill');\n * if (!skill) {\n * throw new SkillNotFoundError('non-existent-skill');\n * }\n * ```\n */\nexport class SkillNotFoundError extends SequentialThinkingError {\n\t/**\n\t * Creates a new SkillNotFoundError.\n\t *\n\t * @param skillName - The name of the skill that was not found\n\t * @param action - Optional action being performed (e.g., 'remove', 'update')\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new SkillNotFoundError('my-custom-skill');\n\t * // Error: skill 'my-custom-skill' not found\n\t *\n\t * throw new SkillNotFoundError('my-custom-skill', 'remove');\n\t * // Error: skill 'my-custom-skill' not found, cannot remove\n\t * // Code: SKILL_NOT_FOUND\n\t * ```\n\t */\n\tconstructor(skillName: string, action?: string) {\n\t\tconst message = action\n\t\t\t? `Skill '${skillName}' not found, cannot ${action}`\n\t\t\t: `Skill '${skillName}' not found`;\n\t\tsuper(message, ERROR_CODES.SKILL_NOT_FOUND);\n\t\tthis.name = 'SkillNotFoundError';\n\t}\n}\n\n/**\n * Error thrown when thought validation fails.\n *\n * This error is thrown when a thought fails validation, typically due to\n * invalid values, missing required fields, or constraint violations.\n *\n * @example\n * ```typescript\n * // Validate thought number\n * if (thought.thought_number < 1) {\n * throw new InvalidThoughtError(thought.thought_number, 'thought_number must be >= 1');\n * }\n * ```\n */\nexport class InvalidThoughtError extends SequentialThinkingError {\n\t/**\n\t * Creates a new InvalidThoughtError.\n\t *\n\t * @param thoughtNumber - The thought number that failed validation\n\t * @param reason - Human-readable explanation of why validation failed\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new InvalidThoughtError(5, 'thought_number exceeds total_thoughts');\n\t * // Error: Invalid thought 5: thought_number exceeds total_thoughts\n\t * // Code: INVALID_THOUGHT\n\t * ```\n\t */\n\tconstructor(thoughtNumber: number, reason: string) {\n\t\tsuper(`Invalid thought ${thoughtNumber}: ${reason}`, ERROR_CODES.INVALID_THOUGHT);\n\t\tthis.name = 'InvalidThoughtError';\n\t}\n}\n\n/**\n * Error thrown when skill discovery fails.\n *\n * This error is thrown when the skill discovery process encounters an issue,\n * such as filesystem errors, invalid skill files, or parsing failures.\n *\n * @remarks\n * The original error that caused the discovery failure is preserved in the\n * `cause` property for debugging purposes.\n *\n * @example\n * ```typescript\n * try {\n * await discoverSkills('./skills');\n * } catch (error) {\n * throw new SkillDiscoveryError('./skills', error as Error);\n * }\n * ```\n */\nexport class SkillDiscoveryError extends SequentialThinkingError {\n\t/** The underlying error that caused the discovery failure. */\n\tpublic override readonly cause: Error;\n\n\t/**\n\t * Creates a new SkillDiscoveryError.\n\t *\n\t * @param directory - The directory where discovery failed\n\t * @param cause - The underlying error that caused the failure\n\t *\n\t * @example\n\t * ```typescript\n\t * try {\n\t * const skills = await loadSkills('./invalid-directory');\n\t * } catch (error) {\n\t * throw new SkillDiscoveryError('./invalid-directory', error as Error);\n\t * }\n\t * ```\n\t */\n\tconstructor(directory: string, cause: Error) {\n\t\tsuper(\n\t\t\t`Failed to discover skills in ${directory}: ${cause.message}`,\n\t\t\tERROR_CODES.SKILL_DISCOVERY_FAILED,\n\t\t);\n\t\tthis.name = 'SkillDiscoveryError';\n\t\tthis.cause = cause;\n\t}\n}\n\n/**\n * Error thrown when history size exceeds the configured limit.\n *\n * This error is thrown when an operation would cause the history size\n * to exceed the maximum configured size limit.\n *\n * @example\n * ```typescript\n * if (history.length >= maxSize) {\n * throw new HistoryLimitExceededError(history.length, maxSize);\n * }\n * ```\n */\nexport class HistoryLimitExceededError extends SequentialThinkingError {\n\t/**\n\t * Creates a new HistoryLimitExceededError.\n\t *\n\t * @param currentSize - The current history size\n\t * @param maxSize - The maximum allowed size\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new HistoryLimitExceededError(1500, 1000);\n\t * // Error: History size 1500 exceeds limit 1000\n\t * // Code: HISTORY_LIMIT_EXCEEDED\n\t * ```\n\t */\n\tconstructor(currentSize: number, maxSize: number) {\n\t\tsuper(`History size ${currentSize} exceeds limit ${maxSize}`, ERROR_CODES.HISTORY_LIMIT_EXCEEDED);\n\t\tthis.name = 'HistoryLimitExceededError';\n\t}\n}\n\n/**\n * Error thrown when attempting to add a skill that already exists.\n *\n * This error is thrown when trying to register a skill with a name that\n * is already present in the skill registry.\n *\n * @example\n * ```typescript\n * if (registry.hasSkill(skill.name)) {\n * throw new DuplicateSkillError(skill.name);\n * }\n * ```\n */\nexport class DuplicateSkillError extends SequentialThinkingError {\n\t/**\n\t * Creates a new DuplicateSkillError.\n\t *\n\t * @param skillName - The name of the duplicate skill\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new DuplicateSkillError('my-skill');\n\t * // Error: skill 'my-skill' already exists\n\t * // Code: DUPLICATE_SKILL\n\t * ```\n\t */\n\tconstructor(skillName: string) {\n\t\tsuper(`skill '${skillName}' already exists`, ERROR_CODES.DUPLICATE_SKILL);\n\t\tthis.name = 'DuplicateSkillError';\n\t}\n}\n\n/**\n * Error thrown when a skill has invalid data.\n *\n * This error is thrown when a skill fails validation, typically due to\n * missing required fields or invalid values.\n *\n * @example\n * ```typescript\n * if (!skill.name) {\n * throw new InvalidSkillError('Skill must have a valid name');\n * }\n * ```\n */\nexport class InvalidSkillError extends SequentialThinkingError {\n\t/**\n\t * Creates a new InvalidSkillError.\n\t *\n\t * @param reason - The reason for the validation failure\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new InvalidSkillError('Skill must have a valid name');\n\t * // Error: Invalid skill: Skill must have a valid name\n\t * // Code: INVALID_SKILL\n\t * ```\n\t */\n\tconstructor(reason: string) {\n\t\tsuper(`Invalid skill: ${reason}`, ERROR_CODES.INVALID_SKILL);\n\t\tthis.name = 'InvalidSkillError';\n\t}\n}\n\n/**\n * Error thrown when attempting to add a tool that already exists.\n *\n * This error is thrown when trying to register a tool with a name that\n * is already present in the tool registry.\n *\n * @example\n * ```typescript\n * if (registry.hasTool(tool.name)) {\n * throw new DuplicateToolError(tool.name);\n * }\n * ```\n */\nexport class DuplicateToolError extends SequentialThinkingError {\n\t/**\n\t * Creates a new DuplicateToolError.\n\t *\n\t * @param toolName - The name of the duplicate tool\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new DuplicateToolError('my-tool');\n\t * // Error: tool 'my-tool' already exists\n\t * // Code: DUPLICATE_TOOL\n\t * ```\n\t */\n\tconstructor(toolName: string) {\n\t\tsuper(`tool '${toolName}' already exists`, ERROR_CODES.DUPLICATE_TOOL);\n\t\tthis.name = 'DuplicateToolError';\n\t}\n}\n\n/**\n * Error thrown when a tool has invalid data.\n *\n * This error is thrown when a tool fails validation, typically due to\n * missing required fields or invalid values.\n *\n * @example\n * ```typescript\n * if (!tool.name) {\n * throw new InvalidToolError('Tool must have a valid name');\n * }\n * ```\n */\nexport class InvalidToolError extends SequentialThinkingError {\n\t/**\n\t * Creates a new InvalidToolError.\n\t *\n\t * @param reason - The reason for the validation failure\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new InvalidToolError('Tool must have a valid name');\n\t * // Error: Invalid tool: Tool must have a valid name\n\t * // Code: INVALID_TOOL\n\t * ```\n\t */\n\tconstructor(reason: string) {\n\t\tsuper(`Invalid tool: ${reason}`, ERROR_CODES.INVALID_TOOL);\n\t\tthis.name = 'InvalidToolError';\n\t}\n}\n\n/**\n * Error thrown when attempting to process a session that is not active.\n *\n * This error is thrown when trying to use a session that has been closed\n * or deactivated.\n *\n * @example\n * ```typescript\n * if (!session.isActive) {\n * throw new SessionNotActiveError(sessionId);\n * }\n * ```\n */\nexport class SessionNotActiveError extends SequentialThinkingError {\n\t/**\n\t * Creates a new SessionNotActiveError.\n\t *\n\t * @param sessionId - The ID of the inactive session\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new SessionNotActiveError('session-123');\n\t * // Error: Session 'session-123' is not active\n\t * // Code: SESSION_NOT_ACTIVE\n\t * ```\n\t */\n\tconstructor(sessionId: string) {\n\t\tsuper(`Session '${sessionId}' is not active`, ERROR_CODES.SESSION_NOT_ACTIVE);\n\t\tthis.name = 'SessionNotActiveError';\n\t}\n}\n\n/**\n * Error thrown when a requested session is not found in the pool.\n *\n * This error is thrown when attempting to retrieve, process, or close\n * a session that doesn't exist in the session pool.\n *\n * @example\n * ```typescript\n * const session = pool.getSession('non-existent-session');\n * if (!session) {\n * throw new SessionNotFoundError('non-existent-session');\n * }\n * ```\n */\nexport class SessionNotFoundError extends SequentialThinkingError {\n\t/**\n\t * Creates a new SessionNotFoundError.\n\t *\n\t * @param sessionId - The ID of the session that was not found\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new SessionNotFoundError('session-123');\n\t * // Error: Session not found: session-123\n\t * // Code: SESSION_NOT_FOUND\n\t * ```\n\t */\n\tconstructor(sessionId: string) {\n\t\tsuper(`Session not found: ${sessionId}`, ERROR_CODES.SESSION_NOT_FOUND);\n\t\tthis.name = 'SessionNotFoundError';\n\t}\n}\n\n/**\n * Error thrown when the maximum number of sessions has been reached.\n *\n * This error is thrown when trying to create a new session when the\n * pool has reached its configured maximum session limit.\n *\n * @example\n * ```typescript\n * if (pool.sessionCount >= pool.maxSessions) {\n * throw new MaxSessionsReachedError(pool.maxSessions);\n * }\n * ```\n */\nexport class MaxSessionsReachedError extends SequentialThinkingError {\n\t/**\n\t * Creates a new MaxSessionsReachedError.\n\t *\n\t * @param maxSessions - The maximum number of sessions allowed\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new MaxSessionsReachedError(100);\n\t * // Error: Max sessions (100) reached. Wait for a session to close or increase maxSessions.\n\t * // Code: MAX_SESSIONS_REACHED\n\t * ```\n\t */\n\tconstructor(maxSessions: number) {\n\t\tsuper(\n\t\t\t`Max sessions (${maxSessions}) reached. Wait for a session to close or increase maxSessions.`,\n\t\t\tERROR_CODES.MAX_SESSIONS_REACHED,\n\t\t);\n\t\tthis.name = 'MaxSessionsReachedError';\n\t}\n}\n\n/**\n * Error thrown when attempting to use a terminated connection pool.\n *\n * This error is thrown when trying to create sessions or process requests\n * after the connection pool has been terminated.\n *\n * @example\n * ```typescript\n * if (pool.isTerminated) {\n * throw new PoolTerminatedError();\n * }\n * ```\n */\nexport class PoolTerminatedError extends SequentialThinkingError {\n\t/**\n\t * Creates a new PoolTerminatedError.\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new PoolTerminatedError();\n\t * // Error: ConnectionPool has been terminated\n\t * // Code: POOL_TERMINATED\n\t * ```\n\t */\n\tconstructor() {\n\t\tsuper('ConnectionPool has been terminated', ERROR_CODES.POOL_TERMINATED);\n\t\tthis.name = 'PoolTerminatedError';\n\t}\n}\n\n/**\n * Error thrown when input validation fails due to invalid or malicious data.\n *\n * This error is thrown when user input fails security or format validation,\n * such as path traversal attempts or invalid identifier formats.\n *\n * @example\n * ```typescript\n * if (!BRANCH_ID_PATTERN.test(branchId)) {\n * throw new ValidationError('branchId', 'Invalid format');\n * }\n * ```\n */\nexport class ValidationError extends SequentialThinkingError {\n\t/** The field that failed validation. */\n\tpublic readonly field: string;\n\n\tconstructor(field: string, reason: string) {\n\t\tsuper(`Validation failed for '${field}': ${reason}`, ERROR_CODES.VALIDATION_ERROR);\n\t\tthis.name = 'ValidationError';\n\t\tthis.field = field;\n\t}\n}\n\n/**\n * Error thrown when an invalid edge operation is attempted.\n *\n * This error is thrown when attempting to add an edge that violates\n * structural invariants of the thought DAG, such as a self-edge\n * (where `from` and `to` reference the same thought).\n *\n * @example\n * ```typescript\n * if (edge.from === edge.to) {\n * throw new InvalidEdgeError(\n * `Self-edge not allowed: from and to are the same (${edge.from})`\n * );\n * }\n * ```\n */\nexport class InvalidEdgeError extends SequentialThinkingError {\n\t/**\n\t * Creates a new InvalidEdgeError.\n\t *\n\t * @param message - Human-readable explanation of the invalid edge\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new InvalidEdgeError('Self-edge not allowed: from and to are the same (t1)');\n\t * // Code: INVALID_EDGE\n\t * ```\n\t */\n\tconstructor(message: string) {\n\t\tsuper(message, ERROR_CODES.INVALID_EDGE);\n\t\tthis.name = 'InvalidEdgeError';\n\t}\n}\n\n/**\n * Error thrown when a cycle is detected during graph traversal.\n *\n * This error is thrown by graph algorithms (such as topological sort)\n * when the thought DAG contains a cycle, violating the acyclic invariant.\n *\n * @example\n * ```typescript\n * try {\n * const order = graphView.topological(sessionId);\n * } catch (error) {\n * if (error instanceof CycleDetectedError) {\n * console.error('Cycle in thought graph:', error.message);\n * }\n * }\n * ```\n */\nexport class CycleDetectedError extends SequentialThinkingError {\n\t/**\n\t * Creates a new CycleDetectedError.\n\t *\n\t * @param message - Human-readable explanation of the cycle\n\t *\n\t * @example\n\t * ```typescript\n\t * throw new CycleDetectedError('Cycle detected in session s1');\n\t * // Code: CYCLE_DETECTED\n\t * ```\n\t */\n\tconstructor(message: string) {\n\t\tsuper(message, ERROR_CODES.CYCLE_DETECTED);\n\t\tthis.name = 'CycleDetectedError';\n\t}\n}\n\n/**\n * Error thrown when a suspension record is not found.\n *\n * This error is thrown when attempting to resume a tool interleave\n * suspension that does not exist in the suspension store.\n */\nexport class SuspensionNotFoundError extends SequentialThinkingError {\n\tconstructor(message: string) {\n\t\tsuper(message, ERROR_CODES.SUSPENSION_NOT_FOUND);\n\t\tthis.name = 'SuspensionNotFoundError';\n\t}\n}\n\n/**\n * Error thrown when a suspension record has expired.\n *\n * This error is thrown when attempting to resume a tool interleave\n * suspension whose TTL has elapsed.\n */\nexport class SuspensionExpiredError extends SequentialThinkingError {\n\tconstructor(message: string) {\n\t\tsuper(message, ERROR_CODES.SUSPENSION_EXPIRED);\n\t\tthis.name = 'SuspensionExpiredError';\n\t}\n}\n\n/**\n * Error thrown when a tool call payload is invalid.\n *\n * This error is thrown when a tool interleave invocation has malformed\n * arguments, missing identifiers, or otherwise fails validation.\n */\nexport class InvalidToolCallError extends SequentialThinkingError {\n\tconstructor(message: string) {\n\t\tsuper(message, ERROR_CODES.INVALID_TOOL_CALL);\n\t\tthis.name = 'InvalidToolCallError';\n\t}\n}\n\n/**\n * Error thrown when a backtrack operation is invalid.\n *\n * This error is thrown when an attempt to backtrack the reasoning\n * chain references an unreachable thought or violates DAG invariants.\n */\nexport class InvalidBacktrackError extends SequentialThinkingError {\n\tconstructor(message: string) {\n\t\tsuper(message, ERROR_CODES.INVALID_BACKTRACK);\n\t\tthis.name = 'InvalidBacktrackError';\n\t}\n}\n\n/**\n * Error thrown when a tool_call references a tool not registered with the server.\n *\n * Acts as an allowlist gate: only tools registered in the ToolRegistry may be\n * invoked through tool interleave. Prevents arbitrary tool name injection.\n */\nexport class UnknownToolError extends SequentialThinkingError {\n\tpublic readonly toolName: string;\n\n\tconstructor(toolName: string, message?: string) {\n\t\tsuper(\n\t\t\tmessage ?? `Unknown tool '${toolName}': not registered with the server`,\n\t\t\tERROR_CODES.UNKNOWN_TOOL\n\t\t);\n\t\tthis.name = 'UnknownToolError';\n\t\tthis.toolName = toolName;\n\t}\n}\n\n/**\n * Error thrown when a per-session async lock cannot be acquired in time.\n *\n * Indicates that a critical section held the lock for longer than the\n * configured timeout, suggesting a stuck handler or deadlock.\n */\nexport class LockTimeoutError extends SequentialThinkingError {\n\tpublic readonly sessionId: string;\n\tpublic readonly timeoutMs: number;\n\n\tconstructor(sessionId: string, timeoutMs: number) {\n\t\tsuper(\n\t\t\t`Lock timeout for session '${sessionId}' after ${timeoutMs}ms`,\n\t\t\tERROR_CODES.LOCK_TIMEOUT,\n\t\t);\n\t\tthis.name = 'LockTimeoutError';\n\t\tthis.sessionId = sessionId;\n\t\tthis.timeoutMs = timeoutMs;\n\t}\n}\n\n/**\n * Error thrown when a session is accessed by a non-owner.\n *\n * Sessions are bound to an owner identifier on first creation when accessed\n * via a multi-user transport (SSE/HTTP). Subsequent access attempts using a\n * different owner are rejected to prevent IDOR (Insecure Direct Object\n * Reference) vulnerabilities.\n *\n * The stdio transport does not set an owner, so its sessions are unaffected.\n */\nexport class SessionAccessDeniedError extends SequentialThinkingError {\n\tpublic readonly sessionId: string;\n\tpublic readonly expectedOwner: string;\n\tpublic readonly actualOwner: string | undefined;\n\n\tconstructor(sessionId: string, expectedOwner: string, actualOwner?: string) {\n\t\tsuper(\n\t\t\t`Access denied to session '${sessionId}': owned by '${expectedOwner}', accessed by '${actualOwner ?? 'anonymous'}'`,\n\t\t\tERROR_CODES.SESSION_ACCESS_DENIED,\n\t\t);\n\t\tthis.name = 'SessionAccessDeniedError';\n\t\tthis.sessionId = sessionId;\n\t\tthis.expectedOwner = expectedOwner;\n\t\tthis.actualOwner = actualOwner;\n\t}\n}\n\n\n/**\n * Type guard to check if an error has a specific error code.\n */\nexport function isErrorCode<C extends ErrorCode>(\n\terr: unknown,\n\tcode: C,\n): err is SequentialThinkingError & { readonly code: C } {\n\treturn err instanceof SequentialThinkingError && err.code === code;\n}\n\n/**\n * Extract a human-readable message from an unknown error value.\n *\n * Standardizes the common `error instanceof Error ? error.message : String(error)`\n * pattern used in catch blocks across the codebase.\n *\n * @param error - The unknown error value to extract a message from\n * @returns The error message string\n *\n * @example\n * ```typescript\n * try {\n * await doSomething();\n * } catch (error) {\n * logger.error('Failed', { error: getErrorMessage(error) });\n * }\n * ```\n */\nexport function getErrorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n"],"names":["ERROR_CODES","WARNING_CODES","SequentialThinkingError","Error","message","code","ConfigurationError","ToolNotFoundError","toolName","action","SkillNotFoundError","skillName","InvalidThoughtError","thoughtNumber","reason","SkillDiscoveryError","directory","cause","HistoryLimitExceededError","currentSize","maxSize","DuplicateSkillError","InvalidSkillError","DuplicateToolError","InvalidToolError","SessionNotActiveError","sessionId","SessionNotFoundError","MaxSessionsReachedError","maxSessions","PoolTerminatedError","ValidationError","field","InvalidEdgeError","CycleDetectedError","SuspensionNotFoundError","SuspensionExpiredError","InvalidToolCallError","InvalidBacktrackError","UnknownToolError","LockTimeoutError","timeoutMs","SessionAccessDeniedError","expectedOwner","actualOwner","isErrorCode","err","getErrorMessage","error","String"],"mappings":"AA+BO,MAAMA,cAAc;IAC1B,qBAAqB;IACrB,gBAAgB;IAChB,iBAAiB;IACjB,iBAAiB;IACjB,wBAAwB;IACxB,wBAAwB;IACxB,iBAAiB;IACjB,eAAe;IACf,gBAAgB;IAChB,cAAc;IACd,oBAAoB;IACpB,mBAAmB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AC,aAAa,GAAGiB;QACrB,IAAI,CAAC,WAAW,GAAGC;IACpB;AACD;AAMO,SAASC,YACfC,GAAY,EACZzC,IAAO;IAEP,OAAOyC,eAAe5C,2BAA2B4C,IAAI,IAAI,KAAKzC;AAC/D;AAoBO,SAAS0C,gBAAgBC,KAAc;IAC7C,OAAOA,iBAAiB7C,QAAQ6C,MAAM,OAAO,GAAGC,OAAOD;AACxD"}
@@ -7,7 +7,7 @@
7
7
  * @module health
8
8
  */
9
9
  import type { Logger } from '../logger/StructuredLogger.js';
10
- import type { PersistenceBackend } from '../persistence/PersistenceBackend.js';
10
+ import type { PersistenceBackend } from '../contracts/PersistenceBackend.js';
11
11
  /**
12
12
  * Health status of an individual component.
13
13
  */
@@ -1 +1 @@
1
- {"version":3,"file":"HealthChecker.d.ts","sourceRoot":"","sources":["../../src/health/HealthChecker.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAG/E;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC,MAAM,EAAE,IAAI,GAAG,UAAU,GAAG,WAAW,CAAC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,WAAW,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAYD;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAa;IACzB,OAA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
1
- {"version":3,"file":"health/HealthChecker.js","sources":["../../src/health/HealthChecker.ts"],"sourcesContent":["/**\n * Aggregate health checking system.\n *\n * Provides liveness and readiness checks by aggregating the health\n * status of registered backend components (persistence, pool, etc.).\n *\n * @module health\n */\n\nimport type { Logger } from '../logger/StructuredLogger.js';\nimport type { PersistenceBackend } from '../persistence/PersistenceBackend.js';\nimport { getErrorMessage } from '../errors.js';\n\n/**\n * Health status of an individual component.\n */\nexport interface HealthComponent {\n\tname: string;\n\thealthy: boolean;\n\tdetails?: string;\n\tlatencyMs?: number;\n}\n\n/**\n * Aggregate health check result.\n */\nexport interface HealthCheckResult {\n\tstatus: 'ok' | 'degraded' | 'unhealthy';\n\ttimestamp: string;\n\tcomponents: Record<string, HealthComponent>;\n}\n\n/**\n * Options for constructing a HealthChecker.\n */\nexport interface HealthCheckerOptions {\n\tpersistence?: PersistenceBackend | null;\n\tlogger?: Logger;\n}\n\n/**\n * No-op logger used when none is provided.\n */\nclass NoopLogger implements Pick<Logger, 'info' | 'warn' | 'error' | 'debug'> {\n\tinfo(): void {}\n\twarn(): void {}\n\terror(): void {}\n\tdebug(): void {}\n}\n\n/**\n * Aggregates component health into liveness and readiness checks.\n *\n * - `checkLiveness()` always returns 'ok' if the process is running.\n * - `checkReadiness()` checks all registered backends and returns an aggregate status.\n *\n * @example\n * ```typescript\n * const checker = new HealthChecker({ persistence: myBackend });\n * const readiness = await checker.checkReadiness();\n * // { status: 'ok', timestamp: '...', components: { persistence: { ... } } }\n * ```\n */\nexport class HealthChecker {\n\tprivate _persistence: PersistenceBackend | null;\n\tprivate _logger: Pick<Logger, 'info' | 'warn' | 'error' | 'debug'>;\n\n\tconstructor(options: HealthCheckerOptions = {}) {\n\t\tthis._persistence = options.persistence ?? null;\n\t\tthis._logger = options.logger ?? new NoopLogger();\n\t}\n\n\t/**\n\t * Liveness check — returns 'ok' if the process is alive.\n\t *\n\t * This is a synchronous check that always succeeds; if this code\n\t * can execute, the process is alive.\n\t */\n\tcheckLiveness(): HealthCheckResult {\n\t\treturn {\n\t\t\tstatus: 'ok',\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tcomponents: {},\n\t\t};\n\t}\n\n\t/**\n\t * Readiness check — aggregates health of all registered backends.\n\t *\n\t * Checks each component and returns:\n\t * - 'ok' if all components are healthy (or no components registered)\n\t * - 'degraded' if some components are unhealthy\n\t * - 'unhealthy' if all components are unhealthy\n\t */\n\tasync checkReadiness(): Promise<HealthCheckResult> {\n\t\tconst components: Record<string, HealthComponent> = {};\n\t\tlet healthyCount = 0;\n\t\tlet totalCount = 0;\n\n\t\t// Check persistence backend\n\t\tif (this._persistence) {\n\t\t\ttotalCount++;\n\t\t\tconst component = await this._checkPersistence();\n\t\t\tcomponents['persistence'] = component;\n\t\t\tif (component.healthy) {\n\t\t\t\thealthyCount++;\n\t\t\t}\n\t\t}\n\n\t\t// Determine aggregate status\n\t\tlet status: 'ok' | 'degraded' | 'unhealthy';\n\t\tif (totalCount === 0 || healthyCount === totalCount) {\n\t\t\tstatus = 'ok';\n\t\t} else if (healthyCount === 0) {\n\t\t\tstatus = 'unhealthy';\n\t\t} else {\n\t\t\tstatus = 'degraded';\n\t\t}\n\n\t\tconst result: HealthCheckResult = {\n\t\t\tstatus,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tcomponents,\n\t\t};\n\n\t\tif (status !== 'ok') {\n\t\t\tthis._logger.warn('Readiness check returned non-ok status', {\n\t\t\t\tstatus,\n\t\t\t\tcomponents,\n\t\t\t});\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Check persistence backend health with latency measurement.\n\t */\n\tprivate async _checkPersistence(): Promise<HealthComponent> {\n\t\tconst start = Date.now();\n\t\ttry {\n\t\t\tconst healthy = await this._persistence!.healthy();\n\t\t\treturn {\n\t\t\t\tname: 'persistence',\n\t\t\t\thealthy,\n\t\t\t\tlatencyMs: Date.now() - start,\n\t\t\t\tdetails: healthy ? 'Backend is responsive' : 'Backend reported unhealthy',\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthis._logger.error('Persistence health check failed', {\n\t\t\t\terror: getErrorMessage(error),\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tname: 'persistence',\n\t\t\t\thealthy: false,\n\t\t\t\tlatencyMs: Date.now() - start,\n\t\t\t\tdetails: `Health check error: ${getErrorMessage(error)}`,\n\t\t\t};\n\t\t}\n\t}\n}\n"],"names":["NoopLogger","HealthChecker","options","Date","components","healthyCount","totalCount","component","status","result","start","healthy","error","getErrorMessage"],"mappings":";AA2CA,MAAMA;IACL,OAAa,CAAC;IACd,OAAa,CAAC;IACd,QAAc,CAAC;IACf,QAAc,CAAC;AAChB;AAeO,MAAMC;IACJ,aAAwC;IACxC,QAA2D;IAEnE,YAAYC,UAAgC,CAAC,CAAC,CAAE;QAC/C,IAAI,CAAC,YAAY,GAAGA,QAAQ,WAAW,IAAI;QAC3C,IAAI,CAAC,OAAO,GAAGA,QAAQ,MAAM,IAAI,IAAIF;IACtC;IAQA,gBAAmC;QAClC,OAAO;YACN,QAAQ;YACR,WAAW,IAAIG,OAAO,WAAW;YACjC,YAAY,CAAC;QACd;IACD;IAUA,MAAM,iBAA6C;QAClD,MAAMC,aAA8C,CAAC;QACrD,IAAIC,eAAe;QACnB,IAAIC,aAAa;QAGjB,IAAI,IAAI,CAAC,YAAY,EAAE;YACtBA;YACA,MAAMC,YAAY,MAAM,IAAI,CAAC,iBAAiB;YAC9CH,UAAU,CAAC,cAAc,GAAGG;YAC5B,IAAIA,UAAU,OAAO,EACpBF;QAEF;QAGA,IAAIG;QAEHA,SADGF,AAAe,MAAfA,cAAoBD,iBAAiBC,aAC/B,OACCD,AAAiB,MAAjBA,eACD,cAEA;QAGV,MAAMI,SAA4B;YACjCD;YACA,WAAW,IAAIL,OAAO,WAAW;YACjCC;QACD;QAEA,IAAII,AAAW,SAAXA,QACH,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,0CAA0C;YAC3DA;YACAJ;QACD;QAGD,OAAOK;IACR;IAKA,MAAc,oBAA8C;QAC3D,MAAMC,QAAQP,KAAK,GAAG;QACtB,IAAI;YACH,MAAMQ,UAAU,MAAM,IAAI,CAAC,YAAY,CAAE,OAAO;YAChD,OAAO;gBACN,MAAM;gBACNA;gBACA,WAAWR,KAAK,GAAG,KAAKO;gBACxB,SAASC,UAAU,0BAA0B;YAC9C;QACD,EAAE,OAAOC,OAAO;YACf,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,mCAAmC;gBACrD,OAAOC,gBAAgBD;YACxB;YACA,OAAO;gBACN,MAAM;gBACN,SAAS;gBACT,WAAWT,KAAK,GAAG,KAAKO;gBACxB,SAAS,CAAC,oBAAoB,EAAEG,gBAAgBD,QAAQ;YACzD;QACD;IACD;AACD"}
1
+ {"version":3,"file":"health/HealthChecker.js","sources":["../../src/health/HealthChecker.ts"],"sourcesContent":["/**\n * Aggregate health checking system.\n *\n * Provides liveness and readiness checks by aggregating the health\n * status of registered backend components (persistence, pool, etc.).\n *\n * @module health\n */\n\nimport type { Logger } from '../logger/StructuredLogger.js';\nimport type { PersistenceBackend } from '../contracts/PersistenceBackend.js';\nimport { getErrorMessage } from '../errors.js';\n\n/**\n * Health status of an individual component.\n */\nexport interface HealthComponent {\n\tname: string;\n\thealthy: boolean;\n\tdetails?: string;\n\tlatencyMs?: number;\n}\n\n/**\n * Aggregate health check result.\n */\nexport interface HealthCheckResult {\n\tstatus: 'ok' | 'degraded' | 'unhealthy';\n\ttimestamp: string;\n\tcomponents: Record<string, HealthComponent>;\n}\n\n/**\n * Options for constructing a HealthChecker.\n */\nexport interface HealthCheckerOptions {\n\tpersistence?: PersistenceBackend | null;\n\tlogger?: Logger;\n}\n\n/**\n * No-op logger used when none is provided.\n */\nclass NoopLogger implements Pick<Logger, 'info' | 'warn' | 'error' | 'debug'> {\n\tinfo(): void {}\n\twarn(): void {}\n\terror(): void {}\n\tdebug(): void {}\n}\n\n/**\n * Aggregates component health into liveness and readiness checks.\n *\n * - `checkLiveness()` always returns 'ok' if the process is running.\n * - `checkReadiness()` checks all registered backends and returns an aggregate status.\n *\n * @example\n * ```typescript\n * const checker = new HealthChecker({ persistence: myBackend });\n * const readiness = await checker.checkReadiness();\n * // { status: 'ok', timestamp: '...', components: { persistence: { ... } } }\n * ```\n */\nexport class HealthChecker {\n\tprivate _persistence: PersistenceBackend | null;\n\tprivate _logger: Pick<Logger, 'info' | 'warn' | 'error' | 'debug'>;\n\n\tconstructor(options: HealthCheckerOptions = {}) {\n\t\tthis._persistence = options.persistence ?? null;\n\t\tthis._logger = options.logger ?? new NoopLogger();\n\t}\n\n\t/**\n\t * Liveness check — returns 'ok' if the process is alive.\n\t *\n\t * This is a synchronous check that always succeeds; if this code\n\t * can execute, the process is alive.\n\t */\n\tcheckLiveness(): HealthCheckResult {\n\t\treturn {\n\t\t\tstatus: 'ok',\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tcomponents: {},\n\t\t};\n\t}\n\n\t/**\n\t * Readiness check — aggregates health of all registered backends.\n\t *\n\t * Checks each component and returns:\n\t * - 'ok' if all components are healthy (or no components registered)\n\t * - 'degraded' if some components are unhealthy\n\t * - 'unhealthy' if all components are unhealthy\n\t */\n\tasync checkReadiness(): Promise<HealthCheckResult> {\n\t\tconst components: Record<string, HealthComponent> = {};\n\t\tlet healthyCount = 0;\n\t\tlet totalCount = 0;\n\n\t\t// Check persistence backend\n\t\tif (this._persistence) {\n\t\t\ttotalCount++;\n\t\t\tconst component = await this._checkPersistence();\n\t\t\tcomponents['persistence'] = component;\n\t\t\tif (component.healthy) {\n\t\t\t\thealthyCount++;\n\t\t\t}\n\t\t}\n\n\t\t// Determine aggregate status\n\t\tlet status: 'ok' | 'degraded' | 'unhealthy';\n\t\tif (totalCount === 0 || healthyCount === totalCount) {\n\t\t\tstatus = 'ok';\n\t\t} else if (healthyCount === 0) {\n\t\t\tstatus = 'unhealthy';\n\t\t} else {\n\t\t\tstatus = 'degraded';\n\t\t}\n\n\t\tconst result: HealthCheckResult = {\n\t\t\tstatus,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tcomponents,\n\t\t};\n\n\t\tif (status !== 'ok') {\n\t\t\tthis._logger.warn('Readiness check returned non-ok status', {\n\t\t\t\tstatus,\n\t\t\t\tcomponents,\n\t\t\t});\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Check persistence backend health with latency measurement.\n\t */\n\tprivate async _checkPersistence(): Promise<HealthComponent> {\n\t\tconst start = Date.now();\n\t\ttry {\n\t\t\tconst healthy = await this._persistence!.healthy();\n\t\t\treturn {\n\t\t\t\tname: 'persistence',\n\t\t\t\thealthy,\n\t\t\t\tlatencyMs: Date.now() - start,\n\t\t\t\tdetails: healthy ? 'Backend is responsive' : 'Backend reported unhealthy',\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthis._logger.error('Persistence health check failed', {\n\t\t\t\terror: getErrorMessage(error),\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tname: 'persistence',\n\t\t\t\thealthy: false,\n\t\t\t\tlatencyMs: Date.now() - start,\n\t\t\t\tdetails: `Health check error: ${getErrorMessage(error)}`,\n\t\t\t};\n\t\t}\n\t}\n}\n"],"names":["NoopLogger","HealthChecker","options","Date","components","healthyCount","totalCount","component","status","result","start","healthy","error","getErrorMessage"],"mappings":";AA2CA,MAAMA;IACL,OAAa,CAAC;IACd,OAAa,CAAC;IACd,QAAc,CAAC;IACf,QAAc,CAAC;AAChB;AAeO,MAAMC;IACJ,aAAwC;IACxC,QAA2D;IAEnE,YAAYC,UAAgC,CAAC,CAAC,CAAE;QAC/C,IAAI,CAAC,YAAY,GAAGA,QAAQ,WAAW,IAAI;QAC3C,IAAI,CAAC,OAAO,GAAGA,QAAQ,MAAM,IAAI,IAAIF;IACtC;IAQA,gBAAmC;QAClC,OAAO;YACN,QAAQ;YACR,WAAW,IAAIG,OAAO,WAAW;YACjC,YAAY,CAAC;QACd;IACD;IAUA,MAAM,iBAA6C;QAClD,MAAMC,aAA8C,CAAC;QACrD,IAAIC,eAAe;QACnB,IAAIC,aAAa;QAGjB,IAAI,IAAI,CAAC,YAAY,EAAE;YACtBA;YACA,MAAMC,YAAY,MAAM,IAAI,CAAC,iBAAiB;YAC9CH,UAAU,CAAC,cAAc,GAAGG;YAC5B,IAAIA,UAAU,OAAO,EACpBF;QAEF;QAGA,IAAIG;QAEHA,SADGF,AAAe,MAAfA,cAAoBD,iBAAiBC,aAC/B,OACCD,AAAiB,MAAjBA,eACD,cAEA;QAGV,MAAMI,SAA4B;YACjCD;YACA,WAAW,IAAIL,OAAO,WAAW;YACjCC;QACD;QAEA,IAAII,AAAW,SAAXA,QACH,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,0CAA0C;YAC3DA;YACAJ;QACD;QAGD,OAAOK;IACR;IAKA,MAAc,oBAA8C;QAC3D,MAAMC,QAAQP,KAAK,GAAG;QACtB,IAAI;YACH,MAAMQ,UAAU,MAAM,IAAI,CAAC,YAAY,CAAE,OAAO;YAChD,OAAO;gBACN,MAAM;gBACNA;gBACA,WAAWR,KAAK,GAAG,KAAKO;gBACxB,SAASC,UAAU,0BAA0B;YAC9C;QACD,EAAE,OAAOC,OAAO;YACf,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,mCAAmC;gBACrD,OAAOC,gBAAgBD;YACxB;YACA,OAAO;gBACN,MAAM;gBACN,SAAS;gBACT,WAAWT,KAAK,GAAG,KAAKO;gBACxB,SAAS,CAAC,oBAAoB,EAAEG,gBAAgBD,QAAQ;YACzD;QACD;IACD;AACD"}
package/dist/lib.d.ts CHANGED
@@ -5,6 +5,7 @@ import { SequentialThinkingSchema } from './schema.js';
5
5
  import { IDisposable } from './types/disposable.js';
6
6
  import type { ConfigFileOptions } from './config/ConfigLoader.js';
7
7
  import { HistoryManager } from './core/HistoryManager.js';
8
+ import { type CallToolResult } from './core/ThoughtProcessor.js';
8
9
  import { Container } from './di/Container.js';
9
10
  import { StructuredLogger } from './logger/StructuredLogger.js';
10
11
  import { SkillRegistry } from './registry/SkillRegistry.js';
@@ -66,7 +67,64 @@ interface ServerEvents {
66
67
  duration: number;
67
68
  };
68
69
  }
69
- export declare class ToolAwareSequentialThinkingServer extends EventEmitter implements IDisposable {
70
+ /**
71
+ * Public API contract for the tool-aware sequential thinking server.
72
+ *
73
+ * Extends {@link IDisposable} for resource cleanup. Concrete implementations
74
+ * are expected to also extend Node's `EventEmitter` to support the typed
75
+ * `emit`/`on` overloads.
76
+ */
77
+ export interface IToolAwareSequentialThinkingServer extends IDisposable {
78
+ /** Direct access to the history manager. */
79
+ readonly history: HistoryManager;
80
+ /** Direct access to the tool registry. */
81
+ readonly tools: ToolRegistry;
82
+ /** Direct access to the skill registry. */
83
+ readonly skills: SkillRegistry;
84
+ /** Server configuration. */
85
+ readonly config: ServerConfig;
86
+ /**
87
+ * Discover skills asynchronously without blocking server startup.
88
+ *
89
+ * @returns The number of skills discovered
90
+ */
91
+ discoverSkillsAsync(): Promise<number>;
92
+ /**
93
+ * Get all branches from the history manager.
94
+ *
95
+ * @returns Map of branch IDs to thought arrays
96
+ */
97
+ getBranches(): Record<string, ThoughtData[]>;
98
+ /**
99
+ * Process a thought through the configured pipeline.
100
+ *
101
+ * @param input - Validated thought input matching the schema
102
+ * @returns The processing result
103
+ */
104
+ processThought(input: v.InferInput<typeof SequentialThinkingSchema>): Promise<CallToolResult>;
105
+ /**
106
+ * Export the current Prometheus metrics snapshot.
107
+ */
108
+ getMetricsSnapshot(): string;
109
+ /**
110
+ * Get the DI container used by this server.
111
+ * Useful for testing and advanced customizations.
112
+ */
113
+ getContainer(): Container;
114
+ /**
115
+ * Stop the server and clean up watchers, suspension stores, and persistence.
116
+ */
117
+ stop(): Promise<void>;
118
+ /**
119
+ * Clear all server state (history, tools, skills).
120
+ */
121
+ clear(): void;
122
+ /**
123
+ * Dispose of the server and all container services.
124
+ */
125
+ dispose(): Promise<void>;
126
+ }
127
+ export declare class ToolAwareSequentialThinkingServer extends EventEmitter implements IToolAwareSequentialThinkingServer {
70
128
  /**
71
129
  * Factory method to create a new server instance with async initialization.
72
130
  * This is the recommended way to create server instances.
@@ -147,7 +205,7 @@ export declare class ToolAwareSequentialThinkingServer extends EventEmitter impl
147
205
  * @returns Record<string, ThoughtData[]> - Map of branch IDs to thought arrays
148
206
  */
149
207
  getBranches(): Record<string, ThoughtData[]>;
150
- processThought(input: v.InferInput<typeof SequentialThinkingSchema>): Promise<import("./core/ThoughtProcessor.js").CallToolResult>;
208
+ processThought(input: v.InferInput<typeof SequentialThinkingSchema>): Promise<CallToolResult>;
151
209
  getMetricsSnapshot(): string;
152
210
  /**
153
211
  * Stop the server and clean up watchers.
package/dist/lib.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAA4B,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAKpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAa1D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAIhE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAKvE,MAAM,WAAW,aAAa;IAC7B,cAAc,CAAC,EAAE,MA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MAAM,CAAC,oBAAoB;IAgLnC;;;OAGG;mBACkB,2BAA2B;IAYhD;;;OAGG;IACI,YAAY,IAAI,SAAS;IAIhC;;;;OAIG;IACU,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAKnD;;;OAGG;IACI,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC;IAKtC,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC,UAAU,CAAC,OAAO,wBAAwB,CAAC;IAuBzE,kBAAkB,IAAI,MAAM;IAInC;;;OAGG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAyClC;;;OAGG;IACI,KAAK,IAAI,IAAI;IAKpB;;;;OAIG;IACU,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAKrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,YAAY,CACjC,OAAO,GAAE,aAAkB,GACzB,OAAO,CAAC,iCAAiC,CAAC,CAE5C;AAGD,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,iCAAiC,CAAC,CAmBnF"}
package/dist/lib.js CHANGED
@@ -14,6 +14,7 @@ import { OutcomeRecorder } from "./core/reasoning/OutcomeRecorder.js";
14
14
  import { createReasoningStrategy } from "./core/reasoning/strategies/StrategyFactory.js";
15
15
  import { ThoughtFormatter } from "./core/ThoughtFormatter.js";
16
16
  import { ThoughtProcessor } from "./core/ThoughtProcessor.js";
17
+ import { SessionLock } from "./core/SessionLock.js";
17
18
  import { Container } from "./di/Container.js";
18
19
  import { StructuredLogger } from "./logger/StructuredLogger.js";
19
20
  import { Metrics } from "./metrics/metrics.impl.js";
@@ -83,7 +84,8 @@ class ToolAwareSequentialThinkingServer extends EventEmitter {
83
84
  maxBranchSize: options.maxBranchSize ?? fileConfig?.maxBranchSize,
84
85
  skillDirs: fileConfig?.skillDirs,
85
86
  discoveryCache: fileConfig?.discoveryCache,
86
- persistence: fileConfig?.persistence
87
+ persistence: fileConfig?.persistence,
88
+ maxSessionsPerOwner: fileConfig?.maxSessionsPerOwner
87
89
  });
88
90
  const logger = options.logger ?? new StructuredLogger({
89
91
  level: fileConfig?.logLevel ?? 'info',
@@ -135,6 +137,7 @@ class ToolAwareSequentialThinkingServer extends EventEmitter {
135
137
  });
136
138
  });
137
139
  container.register('reasoningStrategy', ()=>createReasoningStrategy(config.features.reasoningStrategy));
140
+ container.register('sessionLock', ()=>new SessionLock());
138
141
  container.register('HistoryManager', ()=>{
139
142
  const cfg = container.resolve('Config');
140
143
  const log = container.resolve('Logger');
@@ -151,7 +154,8 @@ class ToolAwareSequentialThinkingServer extends EventEmitter {
151
154
  persistenceBufferSize: cfg.persistenceBufferSize,
152
155
  persistenceFlushInterval: cfg.persistenceFlushInterval,
153
156
  persistenceMaxRetries: cfg.persistenceMaxRetries,
154
- edgeStore
157
+ edgeStore,
158
+ maxSessionsPerOwner: cfg.maxSessionsPerOwner
155
159
  });
156
160
  });
157
161
  container.registerFactory('ThoughtFormatter', ()=>new ThoughtFormatter());
@@ -168,7 +172,9 @@ class ToolAwareSequentialThinkingServer extends EventEmitter {
168
172
  const strategy = container.resolve('reasoningStrategy');
169
173
  const compressionService = config.features.compression ? container.resolve('compressionService') : void 0;
170
174
  const suspensionStore = config.features.toolInterleave ? container.resolve('suspensionStore') : void 0;
171
- return new ThoughtProcessor(history, formatter, evaluator, log, strategy, compressionService, suspensionStore, config.features);
175
+ const toolRegistry = container.resolve('ToolRegistry');
176
+ const sessionLock = container.resolve('sessionLock');
177
+ return new ThoughtProcessor(history, formatter, evaluator, log, strategy, compressionService, suspensionStore, toolRegistry, config.features, sessionLock);
172
178
  });
173
179
  return container;
174
180
  }