@iworkforces/tracelattice 2.0.3

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 (422) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +260 -0
  3. package/dist/CliLifecycle.d.ts +31 -0
  4. package/dist/CliLifecycle.d.ts.map +1 -0
  5. package/dist/CliLifecycle.js +90 -0
  6. package/dist/CliLifecycle.js.map +1 -0
  7. package/dist/ServerConfig.d.ts +290 -0
  8. package/dist/ServerConfig.d.ts.map +1 -0
  9. package/dist/ServerConfig.js +175 -0
  10. package/dist/ServerConfig.js.map +1 -0
  11. package/dist/cache/DiscoveryCache.d.ts +269 -0
  12. package/dist/cache/DiscoveryCache.d.ts.map +1 -0
  13. package/dist/cache/DiscoveryCache.js +104 -0
  14. package/dist/cache/DiscoveryCache.js.map +1 -0
  15. package/dist/cli.d.ts +3 -0
  16. package/dist/cli.d.ts.map +1 -0
  17. package/dist/cli.js +5177 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/config/ConfigLoader.d.ts +270 -0
  20. package/dist/config/ConfigLoader.d.ts.map +1 -0
  21. package/dist/config/ConfigLoader.js +186 -0
  22. package/dist/config/ConfigLoader.js.map +1 -0
  23. package/dist/context/RequestContext.d.ts +43 -0
  24. package/dist/context/RequestContext.d.ts.map +1 -0
  25. package/dist/context/RequestContext.js +14 -0
  26. package/dist/context/RequestContext.js.map +1 -0
  27. package/dist/contracts/PersistenceBackend.d.ts +134 -0
  28. package/dist/contracts/PersistenceBackend.d.ts.map +1 -0
  29. package/dist/contracts/PersistenceBackend.js +6 -0
  30. package/dist/contracts/PersistenceBackend.js.map +1 -0
  31. package/dist/contracts/calibrator.d.ts +97 -0
  32. package/dist/contracts/calibrator.d.ts.map +1 -0
  33. package/dist/contracts/calibrator.js +1 -0
  34. package/dist/contracts/features.d.ts +35 -0
  35. package/dist/contracts/features.d.ts.map +1 -0
  36. package/dist/contracts/features.js +12 -0
  37. package/dist/contracts/features.js.map +1 -0
  38. package/dist/contracts/ids.d.ts +68 -0
  39. package/dist/contracts/ids.d.ts.map +1 -0
  40. package/dist/contracts/ids.js +40 -0
  41. package/dist/contracts/ids.js.map +1 -0
  42. package/dist/contracts/interfaces.d.ts +254 -0
  43. package/dist/contracts/interfaces.d.ts.map +1 -0
  44. package/dist/contracts/interfaces.js +1 -0
  45. package/dist/contracts/persistence-work.d.ts +96 -0
  46. package/dist/contracts/persistence-work.d.ts.map +1 -0
  47. package/dist/contracts/persistence-work.js +1 -0
  48. package/dist/contracts/reasoning-types.d.ts +21 -0
  49. package/dist/contracts/reasoning-types.d.ts.map +1 -0
  50. package/dist/contracts/reasoning-types.js +1 -0
  51. package/dist/contracts/strategy.d.ts +107 -0
  52. package/dist/contracts/strategy.d.ts.map +1 -0
  53. package/dist/contracts/strategy.js +1 -0
  54. package/dist/contracts/summary.d.ts +110 -0
  55. package/dist/contracts/summary.d.ts.map +1 -0
  56. package/dist/contracts/summary.js +1 -0
  57. package/dist/contracts/suspension.d.ts +215 -0
  58. package/dist/contracts/suspension.d.ts.map +1 -0
  59. package/dist/contracts/suspension.js +1 -0
  60. package/dist/contracts/transport.d.ts +26 -0
  61. package/dist/contracts/transport.d.ts.map +1 -0
  62. package/dist/contracts/transport.js +1 -0
  63. package/dist/core/CrossReferenceValidator.d.ts +18 -0
  64. package/dist/core/CrossReferenceValidator.d.ts.map +1 -0
  65. package/dist/core/CrossReferenceValidator.js +125 -0
  66. package/dist/core/CrossReferenceValidator.js.map +1 -0
  67. package/dist/core/HistoryManager.d.ts +215 -0
  68. package/dist/core/HistoryManager.d.ts.map +1 -0
  69. package/dist/core/HistoryManager.js +594 -0
  70. package/dist/core/HistoryManager.js.map +1 -0
  71. package/dist/core/IHistoryManager.d.ts +163 -0
  72. package/dist/core/IHistoryManager.d.ts.map +1 -0
  73. package/dist/core/IHistoryManager.js +1 -0
  74. package/dist/core/IThoughtFormatter.d.ts +51 -0
  75. package/dist/core/IThoughtFormatter.d.ts.map +1 -0
  76. package/dist/core/IThoughtFormatter.js +1 -0
  77. package/dist/core/InputNormalizer.d.ts +140 -0
  78. package/dist/core/InputNormalizer.d.ts.map +1 -0
  79. package/dist/core/InputNormalizer.js +95 -0
  80. package/dist/core/InputNormalizer.js.map +1 -0
  81. package/dist/core/PersistenceBuffer.d.ts +204 -0
  82. package/dist/core/PersistenceBuffer.d.ts.map +1 -0
  83. package/dist/core/PersistenceBuffer.js +382 -0
  84. package/dist/core/PersistenceBuffer.js.map +1 -0
  85. package/dist/core/PersistenceBufferErrors.d.ts +22 -0
  86. package/dist/core/PersistenceBufferErrors.d.ts.map +1 -0
  87. package/dist/core/PersistenceBufferErrors.js +30 -0
  88. package/dist/core/PersistenceBufferErrors.js.map +1 -0
  89. package/dist/core/PersistenceRestore.d.ts +21 -0
  90. package/dist/core/PersistenceRestore.d.ts.map +1 -0
  91. package/dist/core/PersistenceRestore.js +87 -0
  92. package/dist/core/PersistenceRestore.js.map +1 -0
  93. package/dist/core/PersistenceWorkQueue.d.ts +155 -0
  94. package/dist/core/PersistenceWorkQueue.d.ts.map +1 -0
  95. package/dist/core/PersistenceWorkQueue.js +298 -0
  96. package/dist/core/PersistenceWorkQueue.js.map +1 -0
  97. package/dist/core/PersistenceWriter.d.ts +55 -0
  98. package/dist/core/PersistenceWriter.d.ts.map +1 -0
  99. package/dist/core/PersistenceWriter.js +112 -0
  100. package/dist/core/PersistenceWriter.js.map +1 -0
  101. package/dist/core/SessionErrors.d.ts +37 -0
  102. package/dist/core/SessionErrors.d.ts.map +1 -0
  103. package/dist/core/SessionErrors.js +50 -0
  104. package/dist/core/SessionErrors.js.map +1 -0
  105. package/dist/core/SessionLifecycleCoordinator.d.ts +74 -0
  106. package/dist/core/SessionLifecycleCoordinator.d.ts.map +1 -0
  107. package/dist/core/SessionLifecycleCoordinator.js +222 -0
  108. package/dist/core/SessionLifecycleCoordinator.js.map +1 -0
  109. package/dist/core/SessionLock.d.ts +59 -0
  110. package/dist/core/SessionLock.d.ts.map +1 -0
  111. package/dist/core/SessionLock.js +39 -0
  112. package/dist/core/SessionLock.js.map +1 -0
  113. package/dist/core/SessionManager.d.ts +62 -0
  114. package/dist/core/SessionManager.d.ts.map +1 -0
  115. package/dist/core/SessionManager.js +75 -0
  116. package/dist/core/SessionManager.js.map +1 -0
  117. package/dist/core/SessionResetCoordinator.d.ts +37 -0
  118. package/dist/core/SessionResetCoordinator.d.ts.map +1 -0
  119. package/dist/core/SessionResetCoordinator.js +80 -0
  120. package/dist/core/SessionResetCoordinator.js.map +1 -0
  121. package/dist/core/ThoughtEvaluator.d.ts +48 -0
  122. package/dist/core/ThoughtEvaluator.d.ts.map +1 -0
  123. package/dist/core/ThoughtEvaluator.js +85 -0
  124. package/dist/core/ThoughtEvaluator.js.map +1 -0
  125. package/dist/core/ThoughtFormatter.d.ts +134 -0
  126. package/dist/core/ThoughtFormatter.d.ts.map +1 -0
  127. package/dist/core/ThoughtFormatter.js +118 -0
  128. package/dist/core/ThoughtFormatter.js.map +1 -0
  129. package/dist/core/ThoughtProcessor.d.ts +259 -0
  130. package/dist/core/ThoughtProcessor.d.ts.map +1 -0
  131. package/dist/core/ThoughtProcessor.js +451 -0
  132. package/dist/core/ThoughtProcessor.js.map +1 -0
  133. package/dist/core/ThoughtReferenceIndex.d.ts +23 -0
  134. package/dist/core/ThoughtReferenceIndex.d.ts.map +1 -0
  135. package/dist/core/ThoughtReferenceIndex.js +66 -0
  136. package/dist/core/ThoughtReferenceIndex.js.map +1 -0
  137. package/dist/core/VerificationOutcomeAdmission.d.ts +15 -0
  138. package/dist/core/VerificationOutcomeAdmission.d.ts.map +1 -0
  139. package/dist/core/VerificationOutcomeAdmission.js +28 -0
  140. package/dist/core/VerificationOutcomeAdmission.js.map +1 -0
  141. package/dist/core/compression/CompressionService.d.ts +76 -0
  142. package/dist/core/compression/CompressionService.d.ts.map +1 -0
  143. package/dist/core/compression/CompressionService.js +160 -0
  144. package/dist/core/compression/CompressionService.js.map +1 -0
  145. package/dist/core/compression/DehydrationPolicy.d.ts +75 -0
  146. package/dist/core/compression/DehydrationPolicy.d.ts.map +1 -0
  147. package/dist/core/compression/DehydrationPolicy.js +45 -0
  148. package/dist/core/compression/DehydrationPolicy.js.map +1 -0
  149. package/dist/core/compression/InMemorySummaryStore.d.ts +132 -0
  150. package/dist/core/compression/InMemorySummaryStore.d.ts.map +1 -0
  151. package/dist/core/compression/InMemorySummaryStore.js +69 -0
  152. package/dist/core/compression/InMemorySummaryStore.js.map +1 -0
  153. package/dist/core/compression/Summary.d.ts +74 -0
  154. package/dist/core/compression/Summary.d.ts.map +1 -0
  155. package/dist/core/compression/Summary.js +16 -0
  156. package/dist/core/compression/Summary.js.map +1 -0
  157. package/dist/core/evaluator/Aggregator.d.ts +40 -0
  158. package/dist/core/evaluator/Aggregator.d.ts.map +1 -0
  159. package/dist/core/evaluator/Aggregator.js +36 -0
  160. package/dist/core/evaluator/Aggregator.js.map +1 -0
  161. package/dist/core/evaluator/Calibrator.d.ts +52 -0
  162. package/dist/core/evaluator/Calibrator.d.ts.map +1 -0
  163. package/dist/core/evaluator/Calibrator.js +135 -0
  164. package/dist/core/evaluator/Calibrator.js.map +1 -0
  165. package/dist/core/evaluator/PatternDetector.d.ts +69 -0
  166. package/dist/core/evaluator/PatternDetector.d.ts.map +1 -0
  167. package/dist/core/evaluator/PatternDetector.js +192 -0
  168. package/dist/core/evaluator/PatternDetector.js.map +1 -0
  169. package/dist/core/evaluator/SignalComputer.d.ts +116 -0
  170. package/dist/core/evaluator/SignalComputer.d.ts.map +1 -0
  171. package/dist/core/evaluator/SignalComputer.js +110 -0
  172. package/dist/core/evaluator/SignalComputer.js.map +1 -0
  173. package/dist/core/evaluator/calibration-math.d.ts +39 -0
  174. package/dist/core/evaluator/calibration-math.d.ts.map +1 -0
  175. package/dist/core/evaluator/calibration-math.js +42 -0
  176. package/dist/core/evaluator/calibration-math.js.map +1 -0
  177. package/dist/core/evaluator/internals.d.ts +36 -0
  178. package/dist/core/evaluator/internals.d.ts.map +1 -0
  179. package/dist/core/evaluator/internals.js +43 -0
  180. package/dist/core/evaluator/internals.js.map +1 -0
  181. package/dist/core/graph/Edge.d.ts +58 -0
  182. package/dist/core/graph/Edge.d.ts.map +1 -0
  183. package/dist/core/graph/Edge.js +1 -0
  184. package/dist/core/graph/EdgeEmitter.d.ts +68 -0
  185. package/dist/core/graph/EdgeEmitter.d.ts.map +1 -0
  186. package/dist/core/graph/EdgeEmitter.js +118 -0
  187. package/dist/core/graph/EdgeEmitter.js.map +1 -0
  188. package/dist/core/graph/EdgeStore.d.ts +116 -0
  189. package/dist/core/graph/EdgeStore.d.ts.map +1 -0
  190. package/dist/core/graph/EdgeStore.js +107 -0
  191. package/dist/core/graph/EdgeStore.js.map +1 -0
  192. package/dist/core/graph/GraphView.d.ts +157 -0
  193. package/dist/core/graph/GraphView.d.ts.map +1 -0
  194. package/dist/core/graph/GraphView.js +149 -0
  195. package/dist/core/graph/GraphView.js.map +1 -0
  196. package/dist/core/ids.d.ts +33 -0
  197. package/dist/core/ids.d.ts.map +1 -0
  198. package/dist/core/ids.js +11 -0
  199. package/dist/core/ids.js.map +1 -0
  200. package/dist/core/reasoning/OutcomeRecorder.d.ts +88 -0
  201. package/dist/core/reasoning/OutcomeRecorder.d.ts.map +1 -0
  202. package/dist/core/reasoning/OutcomeRecorder.js +51 -0
  203. package/dist/core/reasoning/OutcomeRecorder.js.map +1 -0
  204. package/dist/core/reasoning/strategies/SequentialStrategy.d.ts +54 -0
  205. package/dist/core/reasoning/strategies/SequentialStrategy.d.ts.map +1 -0
  206. package/dist/core/reasoning/strategies/SequentialStrategy.js +22 -0
  207. package/dist/core/reasoning/strategies/SequentialStrategy.js.map +1 -0
  208. package/dist/core/reasoning/strategies/StrategyFactory.d.ts +25 -0
  209. package/dist/core/reasoning/strategies/StrategyFactory.d.ts.map +1 -0
  210. package/dist/core/reasoning/strategies/StrategyFactory.js +16 -0
  211. package/dist/core/reasoning/strategies/StrategyFactory.js.map +1 -0
  212. package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.d.ts +58 -0
  213. package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.d.ts.map +1 -0
  214. package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.js +103 -0
  215. package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.js.map +1 -0
  216. package/dist/core/reasoning/strategies/plateau.d.ts +18 -0
  217. package/dist/core/reasoning/strategies/plateau.d.ts.map +1 -0
  218. package/dist/core/reasoning/strategies/plateau.js +12 -0
  219. package/dist/core/reasoning/strategies/plateau.js.map +1 -0
  220. package/dist/core/reasoning/strategies/totScoring.d.ts +91 -0
  221. package/dist/core/reasoning/strategies/totScoring.d.ts.map +1 -0
  222. package/dist/core/reasoning/strategies/totScoring.js +88 -0
  223. package/dist/core/reasoning/strategies/totScoring.js.map +1 -0
  224. package/dist/core/reasoning.d.ts +179 -0
  225. package/dist/core/reasoning.d.ts.map +1 -0
  226. package/dist/core/reasoning.js +1 -0
  227. package/dist/core/step.d.ts +50 -0
  228. package/dist/core/step.d.ts.map +1 -0
  229. package/dist/core/step.js +1 -0
  230. package/dist/core/thought.d.ts +113 -0
  231. package/dist/core/thought.d.ts.map +1 -0
  232. package/dist/core/thought.js +1 -0
  233. package/dist/core/tools/InMemorySuspensionStore.d.ts +66 -0
  234. package/dist/core/tools/InMemorySuspensionStore.d.ts.map +1 -0
  235. package/dist/core/tools/InMemorySuspensionStore.js +121 -0
  236. package/dist/core/tools/InMemorySuspensionStore.js.map +1 -0
  237. package/dist/di/Container.d.ts +253 -0
  238. package/dist/di/Container.d.ts.map +1 -0
  239. package/dist/di/Container.js +111 -0
  240. package/dist/di/Container.js.map +1 -0
  241. package/dist/di/ServiceRegistry.d.ts +50 -0
  242. package/dist/di/ServiceRegistry.d.ts.map +1 -0
  243. package/dist/di/ServiceRegistry.js +1 -0
  244. package/dist/errors.d.ts +663 -0
  245. package/dist/errors.d.ts.map +1 -0
  246. package/dist/errors.js +282 -0
  247. package/dist/errors.js.map +1 -0
  248. package/dist/health/HealthChecker.d.ts +73 -0
  249. package/dist/health/HealthChecker.d.ts.map +1 -0
  250. package/dist/health/HealthChecker.js +70 -0
  251. package/dist/health/HealthChecker.js.map +1 -0
  252. package/dist/lib.d.ts +273 -0
  253. package/dist/lib.d.ts.map +1 -0
  254. package/dist/lib.js +409 -0
  255. package/dist/lib.js.map +1 -0
  256. package/dist/logger/NullLogger.d.ts +154 -0
  257. package/dist/logger/NullLogger.d.ts.map +1 -0
  258. package/dist/logger/NullLogger.js +24 -0
  259. package/dist/logger/NullLogger.js.map +1 -0
  260. package/dist/logger/StructuredLogger.d.ts +327 -0
  261. package/dist/logger/StructuredLogger.d.ts.map +1 -0
  262. package/dist/logger/StructuredLogger.js +72 -0
  263. package/dist/logger/StructuredLogger.js.map +1 -0
  264. package/dist/metrics/metrics.impl.d.ts +252 -0
  265. package/dist/metrics/metrics.impl.d.ts.map +1 -0
  266. package/dist/metrics/metrics.impl.js +197 -0
  267. package/dist/metrics/metrics.impl.js.map +1 -0
  268. package/dist/persistence/FileLegacyImport.d.ts +2 -0
  269. package/dist/persistence/FileLegacyImport.d.ts.map +1 -0
  270. package/dist/persistence/FileLegacyImport.js +183 -0
  271. package/dist/persistence/FileLegacyImport.js.map +1 -0
  272. package/dist/persistence/FilePersistence.d.ts +53 -0
  273. package/dist/persistence/FilePersistence.d.ts.map +1 -0
  274. package/dist/persistence/FilePersistence.js +312 -0
  275. package/dist/persistence/FilePersistence.js.map +1 -0
  276. package/dist/persistence/FileSnapshotTypes.d.ts +29 -0
  277. package/dist/persistence/FileSnapshotTypes.d.ts.map +1 -0
  278. package/dist/persistence/FileSnapshotTypes.js +1 -0
  279. package/dist/persistence/FileSnapshotV2.d.ts +377 -0
  280. package/dist/persistence/FileSnapshotV2.d.ts.map +1 -0
  281. package/dist/persistence/FileSnapshotV2.js +124 -0
  282. package/dist/persistence/FileSnapshotV2.js.map +1 -0
  283. package/dist/persistence/FileSnapshotValidation.d.ts +15 -0
  284. package/dist/persistence/FileSnapshotValidation.d.ts.map +1 -0
  285. package/dist/persistence/FileSnapshotValidation.js +64 -0
  286. package/dist/persistence/FileSnapshotValidation.js.map +1 -0
  287. package/dist/persistence/FileWriter.d.ts +30 -0
  288. package/dist/persistence/FileWriter.d.ts.map +1 -0
  289. package/dist/persistence/FileWriter.js +155 -0
  290. package/dist/persistence/FileWriter.js.map +1 -0
  291. package/dist/persistence/MemoryPersistence.d.ts +45 -0
  292. package/dist/persistence/MemoryPersistence.d.ts.map +1 -0
  293. package/dist/persistence/MemoryPersistence.js +180 -0
  294. package/dist/persistence/MemoryPersistence.js.map +1 -0
  295. package/dist/persistence/PersistenceCodec.d.ts +7 -0
  296. package/dist/persistence/PersistenceCodec.d.ts.map +1 -0
  297. package/dist/persistence/PersistenceCodec.js +97 -0
  298. package/dist/persistence/PersistenceCodec.js.map +1 -0
  299. package/dist/persistence/PersistenceErrors.d.ts +23 -0
  300. package/dist/persistence/PersistenceErrors.d.ts.map +1 -0
  301. package/dist/persistence/PersistenceErrors.js +26 -0
  302. package/dist/persistence/PersistenceErrors.js.map +1 -0
  303. package/dist/persistence/PersistenceFactory.d.ts +21 -0
  304. package/dist/persistence/PersistenceFactory.d.ts.map +1 -0
  305. package/dist/persistence/PersistenceFactory.js +28 -0
  306. package/dist/persistence/PersistenceFactory.js.map +1 -0
  307. package/dist/persistence/PersistenceScope.d.ts +42 -0
  308. package/dist/persistence/PersistenceScope.d.ts.map +1 -0
  309. package/dist/persistence/PersistenceScope.js +93 -0
  310. package/dist/persistence/PersistenceScope.js.map +1 -0
  311. package/dist/persistence/SessionScopedPersistence.d.ts +4 -0
  312. package/dist/persistence/SessionScopedPersistence.d.ts.map +1 -0
  313. package/dist/persistence/SessionScopedPersistence.js +9 -0
  314. package/dist/persistence/SessionScopedPersistence.js.map +1 -0
  315. package/dist/persistence/SqliteDriver.d.ts +22 -0
  316. package/dist/persistence/SqliteDriver.d.ts.map +1 -0
  317. package/dist/persistence/SqliteDriver.js +29 -0
  318. package/dist/persistence/SqliteDriver.js.map +1 -0
  319. package/dist/persistence/SqliteLegacyImport.d.ts +14 -0
  320. package/dist/persistence/SqliteLegacyImport.d.ts.map +1 -0
  321. package/dist/persistence/SqliteLegacyImport.js +136 -0
  322. package/dist/persistence/SqliteLegacyImport.js.map +1 -0
  323. package/dist/persistence/SqliteLegacySchema.d.ts +15 -0
  324. package/dist/persistence/SqliteLegacySchema.d.ts.map +1 -0
  325. package/dist/persistence/SqliteLegacySchema.js +72 -0
  326. package/dist/persistence/SqliteLegacySchema.js.map +1 -0
  327. package/dist/persistence/SqlitePayload.d.ts +11 -0
  328. package/dist/persistence/SqlitePayload.d.ts.map +1 -0
  329. package/dist/persistence/SqlitePayload.js +86 -0
  330. package/dist/persistence/SqlitePayload.js.map +1 -0
  331. package/dist/persistence/SqlitePersistence.d.ts +49 -0
  332. package/dist/persistence/SqlitePersistence.d.ts.map +1 -0
  333. package/dist/persistence/SqlitePersistence.js +248 -0
  334. package/dist/persistence/SqlitePersistence.js.map +1 -0
  335. package/dist/persistence/SqliteSchemaV2.d.ts +14 -0
  336. package/dist/persistence/SqliteSchemaV2.d.ts.map +1 -0
  337. package/dist/persistence/SqliteSchemaV2.js +129 -0
  338. package/dist/persistence/SqliteSchemaV2.js.map +1 -0
  339. package/dist/persistence/SqliteSnapshotWriter.d.ts +17 -0
  340. package/dist/persistence/SqliteSnapshotWriter.d.ts.map +1 -0
  341. package/dist/persistence/SqliteSnapshotWriter.js +30 -0
  342. package/dist/persistence/SqliteSnapshotWriter.js.map +1 -0
  343. package/dist/pool/ConnectionPool.d.ts +203 -0
  344. package/dist/pool/ConnectionPool.d.ts.map +1 -0
  345. package/dist/pool/ConnectionPool.js +303 -0
  346. package/dist/pool/ConnectionPool.js.map +1 -0
  347. package/dist/pool/IConnectionPool.d.ts +143 -0
  348. package/dist/pool/IConnectionPool.d.ts.map +1 -0
  349. package/dist/pool/IConnectionPool.js +1 -0
  350. package/dist/pool/PoolErrors.d.ts +11 -0
  351. package/dist/pool/PoolErrors.d.ts.map +1 -0
  352. package/dist/pool/PoolErrors.js +16 -0
  353. package/dist/pool/PoolErrors.js.map +1 -0
  354. package/dist/registry/BaseRegistry.d.ts +219 -0
  355. package/dist/registry/BaseRegistry.d.ts.map +1 -0
  356. package/dist/registry/BaseRegistry.js +215 -0
  357. package/dist/registry/BaseRegistry.js.map +1 -0
  358. package/dist/registry/SkillRegistry.d.ts +67 -0
  359. package/dist/registry/SkillRegistry.d.ts.map +1 -0
  360. package/dist/registry/SkillRegistry.js +87 -0
  361. package/dist/registry/SkillRegistry.js.map +1 -0
  362. package/dist/registry/ToolRegistry.d.ts +70 -0
  363. package/dist/registry/ToolRegistry.d.ts.map +1 -0
  364. package/dist/registry/ToolRegistry.js +96 -0
  365. package/dist/registry/ToolRegistry.js.map +1 -0
  366. package/dist/sanitize.d.ts +164 -0
  367. package/dist/sanitize.d.ts.map +1 -0
  368. package/dist/sanitize.js +100 -0
  369. package/dist/sanitize.js.map +1 -0
  370. package/dist/schema.d.ts +562 -0
  371. package/dist/schema.d.ts.map +1 -0
  372. package/dist/schema.js +251 -0
  373. package/dist/schema.js.map +1 -0
  374. package/dist/transport/BaseTransport.d.ts +166 -0
  375. package/dist/transport/BaseTransport.d.ts.map +1 -0
  376. package/dist/transport/BaseTransport.js +199 -0
  377. package/dist/transport/BaseTransport.js.map +1 -0
  378. package/dist/transport/HttpHelpers.d.ts +53 -0
  379. package/dist/transport/HttpHelpers.d.ts.map +1 -0
  380. package/dist/transport/HttpHelpers.js +44 -0
  381. package/dist/transport/HttpHelpers.js.map +1 -0
  382. package/dist/transport/HttpRequestLifecycle.d.ts +37 -0
  383. package/dist/transport/HttpRequestLifecycle.d.ts.map +1 -0
  384. package/dist/transport/HttpRequestLifecycle.js +87 -0
  385. package/dist/transport/HttpRequestLifecycle.js.map +1 -0
  386. package/dist/transport/HttpTransport.d.ts +140 -0
  387. package/dist/transport/HttpTransport.d.ts.map +1 -0
  388. package/dist/transport/HttpTransport.js +245 -0
  389. package/dist/transport/HttpTransport.js.map +1 -0
  390. package/dist/transport/SseTransport.d.ts +149 -0
  391. package/dist/transport/SseTransport.d.ts.map +1 -0
  392. package/dist/transport/SseTransport.js +470 -0
  393. package/dist/transport/SseTransport.js.map +1 -0
  394. package/dist/transport/StreamableHttpTransport.d.ts +225 -0
  395. package/dist/transport/StreamableHttpTransport.d.ts.map +1 -0
  396. package/dist/transport/StreamableHttpTransport.js +449 -0
  397. package/dist/transport/StreamableHttpTransport.js.map +1 -0
  398. package/dist/types/disposable.d.ts +22 -0
  399. package/dist/types/disposable.d.ts.map +1 -0
  400. package/dist/types/disposable.js +1 -0
  401. package/dist/types/server-config.d.ts +32 -0
  402. package/dist/types/server-config.d.ts.map +1 -0
  403. package/dist/types/server-config.js +1 -0
  404. package/dist/types/skill.d.ts +74 -0
  405. package/dist/types/skill.d.ts.map +1 -0
  406. package/dist/types/skill.js +1 -0
  407. package/dist/types/tool.d.ts +78 -0
  408. package/dist/types/tool.d.ts.map +1 -0
  409. package/dist/types/tool.js +1 -0
  410. package/dist/utils.d.ts +27 -0
  411. package/dist/utils.d.ts.map +1 -0
  412. package/dist/utils.js +6 -0
  413. package/dist/utils.js.map +1 -0
  414. package/dist/watchers/SkillWatcher.d.ts +25 -0
  415. package/dist/watchers/SkillWatcher.d.ts.map +1 -0
  416. package/dist/watchers/SkillWatcher.js +96 -0
  417. package/dist/watchers/SkillWatcher.js.map +1 -0
  418. package/dist/watchers/ToolWatcher.d.ts +24 -0
  419. package/dist/watchers/ToolWatcher.d.ts.map +1 -0
  420. package/dist/watchers/ToolWatcher.js +92 -0
  421. package/dist/watchers/ToolWatcher.js.map +1 -0
  422. package/package.json +106 -0
package/dist/errors.js ADDED
@@ -0,0 +1,282 @@
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
+ CLI_SHUTDOWN_TIMEOUT: 'CLI_SHUTDOWN_TIMEOUT',
27
+ SESSION_ACCESS_DENIED: 'SESSION_ACCESS_DENIED',
28
+ SESSION_LIFECYCLE_CLOSED: 'SESSION_LIFECYCLE_CLOSED',
29
+ PERSISTENCE_OWNERSHIP: 'PERSISTENCE_OWNERSHIP',
30
+ PERSISTENCE_CORRUPTION: 'PERSISTENCE_CORRUPTION',
31
+ PERSISTENCE_PUBLICATION: 'PERSISTENCE_PUBLICATION',
32
+ PERSISTENCE_CLOSED: 'PERSISTENCE_CLOSED',
33
+ PERSISTENCE_DRAIN: 'PERSISTENCE_DRAIN',
34
+ PERSISTENCE_SESSION_ADMISSION_CLOSED: 'PERSISTENCE_SESSION_ADMISSION_CLOSED',
35
+ PERSISTENCE_SESSION_BARRIER_REENTRANCY: 'PERSISTENCE_SESSION_BARRIER_REENTRANCY',
36
+ ASYNC_RESET_REQUIRED: 'ASYNC_RESET_REQUIRED',
37
+ PERSISTENCE_CAPABILITY_UNSUPPORTED: 'PERSISTENCE_CAPABILITY_UNSUPPORTED',
38
+ PERSISTENCE_SCOPE_MISMATCH: 'PERSISTENCE_SCOPE_MISMATCH',
39
+ PERSISTENCE_UNAVAILABLE: 'PERSISTENCE_UNAVAILABLE',
40
+ PERSISTENCE_COMPATIBILITY: 'PERSISTENCE_COMPATIBILITY',
41
+ PERSISTENCE_IMPORT_REQUIRED: 'PERSISTENCE_IMPORT_REQUIRED',
42
+ PERSISTENCE_LEGACY_AMBIGUITY: 'PERSISTENCE_LEGACY_AMBIGUITY'
43
+ };
44
+ const WARNING_CODES = {
45
+ TOTAL_THOUGHTS_ADJUSTED: 'TOTAL_THOUGHTS_ADJUSTED'
46
+ };
47
+ class SequentialThinkingError extends Error {
48
+ code;
49
+ constructor(message, code){
50
+ super(message);
51
+ this.code = code;
52
+ this.name = 'SequentialThinkingError';
53
+ Error.captureStackTrace(this, this.constructor);
54
+ }
55
+ }
56
+ class ConfigurationError extends SequentialThinkingError {
57
+ constructor(message){
58
+ super(message, ERROR_CODES.CONFIGURATION_ERROR);
59
+ this.name = 'ConfigurationError';
60
+ }
61
+ }
62
+ class ToolNotFoundError extends SequentialThinkingError {
63
+ constructor(toolName, action){
64
+ const message = action ? `Tool '${toolName}' not found, cannot ${action}` : `Tool '${toolName}' not found`;
65
+ super(message, ERROR_CODES.TOOL_NOT_FOUND);
66
+ this.name = 'ToolNotFoundError';
67
+ }
68
+ }
69
+ class SkillNotFoundError extends SequentialThinkingError {
70
+ constructor(skillName, action){
71
+ const message = action ? `Skill '${skillName}' not found, cannot ${action}` : `Skill '${skillName}' not found`;
72
+ super(message, ERROR_CODES.SKILL_NOT_FOUND);
73
+ this.name = 'SkillNotFoundError';
74
+ }
75
+ }
76
+ class InvalidThoughtError extends SequentialThinkingError {
77
+ constructor(thoughtNumber, reason){
78
+ super(`Invalid thought ${thoughtNumber}: ${reason}`, ERROR_CODES.INVALID_THOUGHT);
79
+ this.name = 'InvalidThoughtError';
80
+ }
81
+ }
82
+ class SkillDiscoveryError extends SequentialThinkingError {
83
+ cause;
84
+ constructor(directory, cause){
85
+ super(`Failed to discover skills in ${directory}: ${cause.message}`, ERROR_CODES.SKILL_DISCOVERY_FAILED);
86
+ this.name = 'SkillDiscoveryError';
87
+ this.cause = cause;
88
+ }
89
+ }
90
+ class HistoryLimitExceededError extends SequentialThinkingError {
91
+ constructor(currentSize, maxSize){
92
+ super(`History size ${currentSize} exceeds limit ${maxSize}`, ERROR_CODES.HISTORY_LIMIT_EXCEEDED);
93
+ this.name = 'HistoryLimitExceededError';
94
+ }
95
+ }
96
+ class DuplicateSkillError extends SequentialThinkingError {
97
+ constructor(skillName){
98
+ super(`skill '${skillName}' already exists`, ERROR_CODES.DUPLICATE_SKILL);
99
+ this.name = 'DuplicateSkillError';
100
+ }
101
+ }
102
+ class InvalidSkillError extends SequentialThinkingError {
103
+ constructor(reason){
104
+ super(`Invalid skill: ${reason}`, ERROR_CODES.INVALID_SKILL);
105
+ this.name = 'InvalidSkillError';
106
+ }
107
+ }
108
+ class DuplicateToolError extends SequentialThinkingError {
109
+ constructor(toolName){
110
+ super(`tool '${toolName}' already exists`, ERROR_CODES.DUPLICATE_TOOL);
111
+ this.name = 'DuplicateToolError';
112
+ }
113
+ }
114
+ class InvalidToolError extends SequentialThinkingError {
115
+ constructor(reason){
116
+ super(`Invalid tool: ${reason}`, ERROR_CODES.INVALID_TOOL);
117
+ this.name = 'InvalidToolError';
118
+ }
119
+ }
120
+ class MaxSessionsReachedError extends SequentialThinkingError {
121
+ constructor(maxSessions){
122
+ super(`Max sessions (${maxSessions}) reached. Wait for a session to close or increase maxSessions.`, ERROR_CODES.MAX_SESSIONS_REACHED);
123
+ this.name = 'MaxSessionsReachedError';
124
+ }
125
+ }
126
+ class PoolTerminatedError extends SequentialThinkingError {
127
+ constructor(){
128
+ super('ConnectionPool has been terminated', ERROR_CODES.POOL_TERMINATED);
129
+ this.name = 'PoolTerminatedError';
130
+ }
131
+ }
132
+ class ValidationError extends SequentialThinkingError {
133
+ field;
134
+ constructor(field, reason){
135
+ super(`Validation failed for '${field}': ${reason}`, ERROR_CODES.VALIDATION_ERROR);
136
+ this.name = 'ValidationError';
137
+ this.field = field;
138
+ }
139
+ }
140
+ class InvalidEdgeError extends SequentialThinkingError {
141
+ constructor(message){
142
+ super(message, ERROR_CODES.INVALID_EDGE);
143
+ this.name = 'InvalidEdgeError';
144
+ }
145
+ }
146
+ class CycleDetectedError extends SequentialThinkingError {
147
+ constructor(message){
148
+ super(message, ERROR_CODES.CYCLE_DETECTED);
149
+ this.name = 'CycleDetectedError';
150
+ }
151
+ }
152
+ class SuspensionNotFoundError extends SequentialThinkingError {
153
+ constructor(message){
154
+ super(message, ERROR_CODES.SUSPENSION_NOT_FOUND);
155
+ this.name = 'SuspensionNotFoundError';
156
+ }
157
+ }
158
+ class SuspensionExpiredError extends SequentialThinkingError {
159
+ constructor(message){
160
+ super(message, ERROR_CODES.SUSPENSION_EXPIRED);
161
+ this.name = 'SuspensionExpiredError';
162
+ }
163
+ }
164
+ class InvalidToolCallError extends SequentialThinkingError {
165
+ constructor(message){
166
+ super(message, ERROR_CODES.INVALID_TOOL_CALL);
167
+ this.name = 'InvalidToolCallError';
168
+ }
169
+ }
170
+ class InvalidBacktrackError extends SequentialThinkingError {
171
+ constructor(message){
172
+ super(message, ERROR_CODES.INVALID_BACKTRACK);
173
+ this.name = 'InvalidBacktrackError';
174
+ }
175
+ }
176
+ class UnknownToolError extends SequentialThinkingError {
177
+ toolName;
178
+ constructor(toolName, message){
179
+ super(message ?? `Unknown tool '${toolName}': not registered with the server`, ERROR_CODES.UNKNOWN_TOOL);
180
+ this.name = 'UnknownToolError';
181
+ this.toolName = toolName;
182
+ }
183
+ }
184
+ class CliShutdownTimeoutError extends SequentialThinkingError {
185
+ timeoutMs;
186
+ constructor(timeoutMs){
187
+ super(`CLI shutdown timed out after ${timeoutMs}ms`, ERROR_CODES.CLI_SHUTDOWN_TIMEOUT);
188
+ this.name = 'CliShutdownTimeoutError';
189
+ this.timeoutMs = timeoutMs;
190
+ }
191
+ }
192
+ class PersistenceOwnershipError extends SequentialThinkingError {
193
+ canonicalDataDir;
194
+ lockPath;
195
+ cause;
196
+ constructor(canonicalDataDir, lockPath, cause){
197
+ super(`Persistence directory '${canonicalDataDir}' already has an active writer`, ERROR_CODES.PERSISTENCE_OWNERSHIP);
198
+ this.name = 'PersistenceOwnershipError';
199
+ this.canonicalDataDir = canonicalDataDir;
200
+ this.lockPath = lockPath;
201
+ this.cause = cause;
202
+ }
203
+ }
204
+ class PersistenceCorruptionError extends SequentialThinkingError {
205
+ path;
206
+ cause;
207
+ constructor(path, cause){
208
+ super(`Persisted data at '${path}' is corrupt or incompatible`, ERROR_CODES.PERSISTENCE_CORRUPTION);
209
+ this.name = 'PersistenceCorruptionError';
210
+ this.path = path;
211
+ this.cause = cause;
212
+ }
213
+ }
214
+ class PersistenceUnavailableError extends SequentialThinkingError {
215
+ constructor(){
216
+ super('Persistence backend is unavailable during startup restore', ERROR_CODES.PERSISTENCE_UNAVAILABLE);
217
+ this.name = 'PersistenceUnavailableError';
218
+ }
219
+ }
220
+ class PersistencePublicationError extends SequentialThinkingError {
221
+ path;
222
+ stage;
223
+ cause;
224
+ constructor(path, stage, cause){
225
+ super(`Failed persistence publication for '${path}' during ${stage}`, ERROR_CODES.PERSISTENCE_PUBLICATION);
226
+ this.name = 'PersistencePublicationError';
227
+ this.path = path;
228
+ this.stage = stage;
229
+ this.cause = cause;
230
+ }
231
+ }
232
+ class PersistenceClosedError extends SequentialThinkingError {
233
+ dataDir;
234
+ constructor(dataDir){
235
+ super(`Persistence writer for '${dataDir}' is closed`, ERROR_CODES.PERSISTENCE_CLOSED);
236
+ this.name = 'PersistenceClosedError';
237
+ this.dataDir = dataDir;
238
+ }
239
+ }
240
+ class PersistenceCompatibilityError extends SequentialThinkingError {
241
+ sourcePath;
242
+ detail;
243
+ cause;
244
+ constructor(sourcePath, detail, cause){
245
+ super(`Persisted data at '${sourcePath}' is incompatible: ${detail}`, ERROR_CODES.PERSISTENCE_COMPATIBILITY);
246
+ this.name = 'PersistenceCompatibilityError';
247
+ this.sourcePath = sourcePath;
248
+ this.detail = detail;
249
+ this.cause = cause;
250
+ }
251
+ }
252
+ class PersistenceImportRequiredError extends SequentialThinkingError {
253
+ sourcePath;
254
+ legacyArtifacts;
255
+ constructor(sourcePath, legacyArtifacts){
256
+ super(`Legacy persistence at '${sourcePath}' requires explicit import`, ERROR_CODES.PERSISTENCE_IMPORT_REQUIRED);
257
+ this.name = 'PersistenceImportRequiredError';
258
+ this.sourcePath = sourcePath;
259
+ this.legacyArtifacts = [
260
+ ...legacyArtifacts
261
+ ];
262
+ }
263
+ }
264
+ class PersistenceLegacyAmbiguityError extends SequentialThinkingError {
265
+ sourcePath;
266
+ detail;
267
+ constructor(sourcePath, detail){
268
+ super(`Legacy persistence at '${sourcePath}' is ambiguous: ${detail}`, ERROR_CODES.PERSISTENCE_LEGACY_AMBIGUITY);
269
+ this.name = 'PersistenceLegacyAmbiguityError';
270
+ this.sourcePath = sourcePath;
271
+ this.detail = detail;
272
+ }
273
+ }
274
+ function isErrorCode(err, code) {
275
+ return err instanceof SequentialThinkingError && err.code === code;
276
+ }
277
+ function getErrorMessage(error) {
278
+ return error instanceof Error ? error.message : String(error);
279
+ }
280
+ export { CliShutdownTimeoutError, ConfigurationError, CycleDetectedError, DuplicateSkillError, DuplicateToolError, ERROR_CODES, HistoryLimitExceededError, InvalidBacktrackError, InvalidEdgeError, InvalidSkillError, InvalidThoughtError, InvalidToolCallError, InvalidToolError, MaxSessionsReachedError, PersistenceClosedError, PersistenceCompatibilityError, PersistenceCorruptionError, PersistenceImportRequiredError, PersistenceLegacyAmbiguityError, PersistenceOwnershipError, PersistencePublicationError, PersistenceUnavailableError, PoolTerminatedError, SequentialThinkingError, SkillDiscoveryError, SkillNotFoundError, SuspensionExpiredError, SuspensionNotFoundError, ToolNotFoundError, UnknownToolError, ValidationError, WARNING_CODES, getErrorMessage, isErrorCode };
281
+
282
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +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 * 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\tCLI_SHUTDOWN_TIMEOUT: 'CLI_SHUTDOWN_TIMEOUT',\n\tSESSION_ACCESS_DENIED: 'SESSION_ACCESS_DENIED',\n\tSESSION_LIFECYCLE_CLOSED: 'SESSION_LIFECYCLE_CLOSED',\n\tPERSISTENCE_OWNERSHIP: 'PERSISTENCE_OWNERSHIP',\n\tPERSISTENCE_CORRUPTION: 'PERSISTENCE_CORRUPTION',\n\tPERSISTENCE_PUBLICATION: 'PERSISTENCE_PUBLICATION',\n\tPERSISTENCE_CLOSED: 'PERSISTENCE_CLOSED',\n\tPERSISTENCE_DRAIN: 'PERSISTENCE_DRAIN',\n\tPERSISTENCE_SESSION_ADMISSION_CLOSED: 'PERSISTENCE_SESSION_ADMISSION_CLOSED',\n\tPERSISTENCE_SESSION_BARRIER_REENTRANCY: 'PERSISTENCE_SESSION_BARRIER_REENTRANCY',\n\tASYNC_RESET_REQUIRED: 'ASYNC_RESET_REQUIRED',\n\tPERSISTENCE_CAPABILITY_UNSUPPORTED: 'PERSISTENCE_CAPABILITY_UNSUPPORTED',\n\tPERSISTENCE_SCOPE_MISMATCH: 'PERSISTENCE_SCOPE_MISMATCH',\n\tPERSISTENCE_UNAVAILABLE: 'PERSISTENCE_UNAVAILABLE',\n\tPERSISTENCE_COMPATIBILITY: 'PERSISTENCE_COMPATIBILITY',\n\tPERSISTENCE_IMPORT_REQUIRED: 'PERSISTENCE_IMPORT_REQUIRED',\n\tPERSISTENCE_LEGACY_AMBIGUITY: 'PERSISTENCE_LEGACY_AMBIGUITY',\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(\n\t\t\t`History size ${currentSize} exceeds limit ${maxSize}`,\n\t\t\tERROR_CODES.HISTORY_LIMIT_EXCEEDED\n\t\t);\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 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/** Error thrown when the CLI's complete shutdown exceeds its outer deadline. */\nexport class CliShutdownTimeoutError extends SequentialThinkingError {\n\tpublic readonly timeoutMs: number;\n\n\tconstructor(timeoutMs: number) {\n\t\tsuper(`CLI shutdown timed out after ${timeoutMs}ms`, ERROR_CODES.CLI_SHUTDOWN_TIMEOUT);\n\t\tthis.name = 'CliShutdownTimeoutError';\n\t\tthis.timeoutMs = timeoutMs;\n\t}\n}\n\nexport class PersistenceOwnershipError extends SequentialThinkingError {\n\tpublic readonly canonicalDataDir: string;\n\tpublic readonly lockPath: string;\n\tpublic override readonly cause: unknown;\n\n\tconstructor(canonicalDataDir: string, lockPath: string, cause: unknown) {\n\t\tsuper(\n\t\t\t`Persistence directory '${canonicalDataDir}' already has an active writer`,\n\t\t\tERROR_CODES.PERSISTENCE_OWNERSHIP\n\t\t);\n\t\tthis.name = 'PersistenceOwnershipError';\n\t\tthis.canonicalDataDir = canonicalDataDir;\n\t\tthis.lockPath = lockPath;\n\t\tthis.cause = cause;\n\t}\n}\n\nexport class PersistenceCorruptionError extends SequentialThinkingError {\n\tpublic readonly path: string;\n\tpublic override readonly cause: unknown;\n\n\tconstructor(path: string, cause: unknown) {\n\t\tsuper(\n\t\t\t`Persisted data at '${path}' is corrupt or incompatible`,\n\t\t\tERROR_CODES.PERSISTENCE_CORRUPTION\n\t\t);\n\t\tthis.name = 'PersistenceCorruptionError';\n\t\tthis.path = path;\n\t\tthis.cause = cause;\n\t}\n}\n\n/** Error raised when startup cannot read from an unhealthy persistence backend. */\nexport class PersistenceUnavailableError extends SequentialThinkingError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'Persistence backend is unavailable during startup restore',\n\t\t\tERROR_CODES.PERSISTENCE_UNAVAILABLE\n\t\t);\n\t\tthis.name = 'PersistenceUnavailableError';\n\t}\n}\n\nexport type PersistencePublicationStage = 'temporary-write' | 'atomic-replacement' | 'cleanup';\n\nexport class PersistencePublicationError extends SequentialThinkingError {\n\tpublic readonly path: string;\n\tpublic readonly stage: PersistencePublicationStage;\n\tpublic override readonly cause: unknown;\n\n\tconstructor(path: string, stage: PersistencePublicationStage, cause: unknown) {\n\t\tsuper(\n\t\t\t`Failed persistence publication for '${path}' during ${stage}`,\n\t\t\tERROR_CODES.PERSISTENCE_PUBLICATION\n\t\t);\n\t\tthis.name = 'PersistencePublicationError';\n\t\tthis.path = path;\n\t\tthis.stage = stage;\n\t\tthis.cause = cause;\n\t}\n}\n\nexport class PersistenceClosedError extends SequentialThinkingError {\n\tpublic readonly dataDir: string;\n\n\tconstructor(dataDir: string) {\n\t\tsuper(`Persistence writer for '${dataDir}' is closed`, ERROR_CODES.PERSISTENCE_CLOSED);\n\t\tthis.name = 'PersistenceClosedError';\n\t\tthis.dataDir = dataDir;\n\t}\n}\n\n/** Error raised for well-formed but unsupported or drifted persisted data. */\nexport class PersistenceCompatibilityError extends SequentialThinkingError {\n\tpublic readonly sourcePath: string;\n\tpublic readonly detail: string;\n\tpublic override readonly cause: unknown;\n\n\tconstructor(sourcePath: string, detail: string, cause?: unknown) {\n\t\tsuper(\n\t\t\t`Persisted data at '${sourcePath}' is incompatible: ${detail}`,\n\t\t\tERROR_CODES.PERSISTENCE_COMPATIBILITY\n\t\t);\n\t\tthis.name = 'PersistenceCompatibilityError';\n\t\tthis.sourcePath = sourcePath;\n\t\tthis.detail = detail;\n\t\tthis.cause = cause;\n\t}\n}\n\n/** Error raised when legacy files require an explicit one-way import. */\nexport class PersistenceImportRequiredError extends SequentialThinkingError {\n\tpublic readonly sourcePath: string;\n\tpublic readonly legacyArtifacts: readonly string[];\n\n\tconstructor(sourcePath: string, legacyArtifacts: readonly string[]) {\n\t\tsuper(\n\t\t\t`Legacy persistence at '${sourcePath}' requires explicit import`,\n\t\t\tERROR_CODES.PERSISTENCE_IMPORT_REQUIRED\n\t\t);\n\t\tthis.name = 'PersistenceImportRequiredError';\n\t\tthis.sourcePath = sourcePath;\n\t\tthis.legacyArtifacts = [...legacyArtifacts];\n\t}\n}\n\n/** Error raised when legacy bytes do not identify one durable namespace. */\nexport class PersistenceLegacyAmbiguityError extends SequentialThinkingError {\n\tpublic readonly sourcePath: string;\n\tpublic readonly detail: string;\n\n\tconstructor(sourcePath: string, detail: string) {\n\t\tsuper(\n\t\t\t`Legacy persistence at '${sourcePath}' is ambiguous: ${detail}`,\n\t\t\tERROR_CODES.PERSISTENCE_LEGACY_AMBIGUITY\n\t\t);\n\t\tthis.name = 'PersistenceLegacyAmbiguityError';\n\t\tthis.sourcePath = sourcePath;\n\t\tthis.detail = detail;\n\t}\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","MaxSessionsReachedError","maxSessions","PoolTerminatedError","ValidationError","field","InvalidEdgeError","CycleDetectedError","SuspensionNotFoundError","SuspensionExpiredError","InvalidToolCallError","InvalidBacktrackError","UnknownToolError","CliShutdownTimeoutError","timeoutMs","PersistenceOwnershipError","canonicalDataDir","lockPath","PersistenceCorruptionError","path","PersistenceUnavailableError","PersistencePublicationError","stage","PersistenceClosedError","dataDir","PersistenceCompatibilityError","sourcePath","detail","PersistenceImportRequiredError","legacyArtifacts","PersistenceLegacyAmbiguityError","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;IACnB,sBAAsB;IACtB,iBAAiB;IACjB,kBAAkB;IAClB,cAAc;IACd,gBAAgB;IAChB,sBAAsB;IACtB,oBAAoB;IACpB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,cAAc;IACd,cAAc;IACd,sBAAsB;IACtB,uBAAuB;IACvB,0BAA0B;IAC1B,uBAAuB;IACvB,wBAAwB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D;IACpC,WAAmB;IACnB,OAAe;IAE/B,YAAYgD,UAAkB,EAAEC,MAAc,CAAE;QAC/C,KAAK,CACJ,CAAC,uBAAuB,EAAED,WAAW,gBAAgB,EAAEC,QAAQ,EAC/DnD,YAAY,4BAA4B;QAEzC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,UAAU,GAAGkD;QAClB,IAAI,CAAC,MAAM,GAAGC;IACf;AACD;AAKO,SAASI,YACfC,GAAY,EACZnD,IAAO;IAEP,OAAOmD,eAAetD,2BAA2BsD,IAAI,IAAI,KAAKnD;AAC/D;AAoBO,SAASoD,gBAAgBC,KAAc;IAC7C,OAAOA,iBAAiBvD,QAAQuD,MAAM,OAAO,GAAGC,OAAOD;AACxD"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Aggregate health checking system.
3
+ *
4
+ * Provides liveness and readiness checks by aggregating the health
5
+ * status of registered backend components (persistence, pool, etc.).
6
+ *
7
+ * @module health
8
+ */
9
+ import type { Logger } from '../logger/StructuredLogger.js';
10
+ import type { PersistenceBackend } from '../contracts/PersistenceBackend.js';
11
+ /**
12
+ * Health status of an individual component.
13
+ */
14
+ export interface HealthComponent {
15
+ name: string;
16
+ healthy: boolean;
17
+ details?: string;
18
+ latencyMs?: number;
19
+ }
20
+ /**
21
+ * Aggregate health check result.
22
+ */
23
+ export interface HealthCheckResult {
24
+ status: 'ok' | 'degraded' | 'unhealthy';
25
+ timestamp: string;
26
+ components: Record<string, HealthComponent>;
27
+ }
28
+ /**
29
+ * Options for constructing a HealthChecker.
30
+ */
31
+ export interface HealthCheckerOptions {
32
+ persistence?: PersistenceBackend | null;
33
+ logger?: Logger;
34
+ }
35
+ /**
36
+ * Aggregates component health into liveness and readiness checks.
37
+ *
38
+ * - `checkLiveness()` always returns 'ok' if the process is running.
39
+ * - `checkReadiness()` checks all registered backends and returns an aggregate status.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const checker = new HealthChecker({ persistence: myBackend });
44
+ * const readiness = await checker.checkReadiness();
45
+ * // { status: 'ok', timestamp: '...', components: { persistence: { ... } } }
46
+ * ```
47
+ */
48
+ export declare class HealthChecker {
49
+ private _persistence;
50
+ private _logger;
51
+ constructor(options?: HealthCheckerOptions);
52
+ /**
53
+ * Liveness check — returns 'ok' if the process is alive.
54
+ *
55
+ * This is a synchronous check that always succeeds; if this code
56
+ * can execute, the process is alive.
57
+ */
58
+ checkLiveness(): HealthCheckResult;
59
+ /**
60
+ * Readiness check — aggregates health of all registered backends.
61
+ *
62
+ * Checks each component and returns:
63
+ * - 'ok' if all components are healthy (or no components registered)
64
+ * - 'degraded' if some components are unhealthy
65
+ * - 'unhealthy' if all components are unhealthy
66
+ */
67
+ checkReadiness(): Promise<HealthCheckResult>;
68
+ /**
69
+ * Check persistence backend health with latency measurement.
70
+ */
71
+ private _checkPersistence;
72
+ }
73
+ //# sourceMappingURL=HealthChecker.d.ts.map
@@ -0,0 +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,oCAAoC,CAAC;AAG7E;;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,OAAO,CAAC,YAAY,CAA4B;IAChD,OAAO,CAAC,OAAO,CAAoD;gBAEvD,OAAO,GAAE,oBAAyB;IAK9C;;;;;OAKG;IACH,aAAa,IAAI,iBAAiB;IAQlC;;;;;;;OAOG;IACG,cAAc,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAyClD;;OAEG;YACW,iBAAiB;CAsB/B"}
@@ -0,0 +1,70 @@
1
+ import { getErrorMessage } from "../errors.js";
2
+ class NoopLogger {
3
+ info() {}
4
+ warn() {}
5
+ error() {}
6
+ debug() {}
7
+ }
8
+ class HealthChecker {
9
+ _persistence;
10
+ _logger;
11
+ constructor(options = {}){
12
+ this._persistence = options.persistence ?? null;
13
+ this._logger = options.logger ?? new NoopLogger();
14
+ }
15
+ checkLiveness() {
16
+ return {
17
+ status: 'ok',
18
+ timestamp: new Date().toISOString(),
19
+ components: {}
20
+ };
21
+ }
22
+ async checkReadiness() {
23
+ const components = {};
24
+ let healthyCount = 0;
25
+ let totalCount = 0;
26
+ if (this._persistence) {
27
+ totalCount++;
28
+ const component = await this._checkPersistence();
29
+ components['persistence'] = component;
30
+ if (component.healthy) healthyCount++;
31
+ }
32
+ let status;
33
+ status = 0 === totalCount || healthyCount === totalCount ? 'ok' : 0 === healthyCount ? 'unhealthy' : 'degraded';
34
+ const result = {
35
+ status,
36
+ timestamp: new Date().toISOString(),
37
+ components
38
+ };
39
+ if ('ok' !== status) this._logger.warn('Readiness check returned non-ok status', {
40
+ status,
41
+ components
42
+ });
43
+ return result;
44
+ }
45
+ async _checkPersistence() {
46
+ const start = Date.now();
47
+ try {
48
+ const healthy = await this._persistence.healthy();
49
+ return {
50
+ name: 'persistence',
51
+ healthy,
52
+ latencyMs: Date.now() - start,
53
+ details: healthy ? 'Backend is responsive' : 'Backend reported unhealthy'
54
+ };
55
+ } catch (error) {
56
+ this._logger.error('Persistence health check failed', {
57
+ error: getErrorMessage(error)
58
+ });
59
+ return {
60
+ name: 'persistence',
61
+ healthy: false,
62
+ latencyMs: Date.now() - start,
63
+ details: `Health check error: ${getErrorMessage(error)}`
64
+ };
65
+ }
66
+ }
67
+ }
68
+ export { HealthChecker };
69
+
70
+ //# sourceMappingURL=HealthChecker.js.map
@@ -0,0 +1 @@
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;QA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