@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
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Strategy factory — maps a {@link FeatureFlags.reasoningStrategy} value to
3
+ * a concrete {@link IReasoningStrategy} instance.
4
+ *
5
+ * Today {@link SequentialStrategy} and {@link TreeOfThoughtStrategy} are
6
+ * implemented and are the only valid strategy values.
7
+ *
8
+ * @module core/reasoning/strategies/StrategyFactory
9
+ */
10
+ import type { IReasoningStrategy } from '../../../contracts/strategy.js';
11
+ import type { FeatureFlags } from '../../../contracts/features.js';
12
+ /**
13
+ * Build a reasoning strategy by name.
14
+ *
15
+ * @param name - Strategy identifier from {@link FeatureFlags.reasoningStrategy}.
16
+ * @returns A concrete {@link IReasoningStrategy} instance.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const strategy = createReasoningStrategy(config.features.reasoningStrategy);
21
+ * const decision = strategy.decide(ctx);
22
+ * ```
23
+ */
24
+ export declare function createReasoningStrategy(name: FeatureFlags['reasoningStrategy']): IReasoningStrategy;
25
+ //# sourceMappingURL=StrategyFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StrategyFactory.d.ts","sourceRoot":"","sources":["../../../../src/core/reasoning/strategies/StrategyFactory.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAKnE;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,YAAY,CAAC,mBAAmB,CAAC,GACrC,kBAAkB,CASpB"}
@@ -0,0 +1,16 @@
1
+ import { SequentialStrategy } from "./SequentialStrategy.js";
2
+ import { TreeOfThoughtStrategy } from "./TreeOfThoughtStrategy.js";
3
+ import { assertNever } from "../../../utils.js";
4
+ function createReasoningStrategy(name) {
5
+ switch(name){
6
+ case 'sequential':
7
+ return new SequentialStrategy();
8
+ case 'tot':
9
+ return new TreeOfThoughtStrategy();
10
+ default:
11
+ return assertNever(name);
12
+ }
13
+ }
14
+ export { createReasoningStrategy };
15
+
16
+ //# sourceMappingURL=StrategyFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core/reasoning/strategies/StrategyFactory.js","sources":["../../../../src/core/reasoning/strategies/StrategyFactory.ts"],"sourcesContent":["/**\n * Strategy factory — maps a {@link FeatureFlags.reasoningStrategy} value to\n * a concrete {@link IReasoningStrategy} instance.\n *\n * Today {@link SequentialStrategy} and {@link TreeOfThoughtStrategy} are\n * implemented and are the only valid strategy values.\n *\n * @module core/reasoning/strategies/StrategyFactory\n */\n\nimport type { IReasoningStrategy } from '../../../contracts/strategy.js';\nimport type { FeatureFlags } from '../../../contracts/features.js';\nimport { SequentialStrategy } from './SequentialStrategy.js';\nimport { TreeOfThoughtStrategy } from './TreeOfThoughtStrategy.js';\nimport { assertNever } from '../../../utils.js';\n\n/**\n * Build a reasoning strategy by name.\n *\n * @param name - Strategy identifier from {@link FeatureFlags.reasoningStrategy}.\n * @returns A concrete {@link IReasoningStrategy} instance.\n *\n * @example\n * ```ts\n * const strategy = createReasoningStrategy(config.features.reasoningStrategy);\n * const decision = strategy.decide(ctx);\n * ```\n */\nexport function createReasoningStrategy(\n\tname: FeatureFlags['reasoningStrategy'],\n): IReasoningStrategy {\n\tswitch (name) {\n\t\tcase 'sequential':\n\t\t\treturn new SequentialStrategy();\n\t\tcase 'tot':\n\t\t\treturn new TreeOfThoughtStrategy();\n\t\tdefault:\n\t\t\treturn assertNever(name);\n\t}\n}\n"],"names":["createReasoningStrategy","name","SequentialStrategy","TreeOfThoughtStrategy","assertNever"],"mappings":";;;AA4BO,SAASA,wBACfC,IAAuC;IAEvC,OAAQA;QACP,KAAK;YACJ,OAAO,IAAIC;QACZ,KAAK;YACJ,OAAO,IAAIC;QACZ;YACC,OAAOC,YAAYH;IACrB;AACD"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Tree-of-Thought reasoning strategy — beam search over the thought DAG.
3
+ *
4
+ * Observes the frontier (graph leaves), scores each leaf via
5
+ * {@link scoreThought}, and decides whether to continue, branch (when the
6
+ * current thought falls outside the beam), or terminate (on confidence
7
+ * threshold or score plateau).
8
+ *
9
+ * Pure policy: configuration lives in a module-level {@link WeakMap}, not
10
+ * on the instance, so `Object.getOwnPropertyNames(strategy)` only ever
11
+ * surfaces the readonly `name` discriminator. All other state is derived
12
+ * from the {@link StrategyContext} on every call.
13
+ *
14
+ * @module core/reasoning/strategies/TreeOfThoughtStrategy
15
+ */
16
+ import type { IReasoningStrategy, StrategyContext, StrategyDecision } from '../../../contracts/strategy.js';
17
+ /**
18
+ * Configuration knobs for {@link TreeOfThoughtStrategy}. All fields are
19
+ * optional; defaults are applied in the constructor.
20
+ */
21
+ export interface TotConfig {
22
+ /** Top-K candidates kept on the frontier (default `3`). */
23
+ readonly beamWidth?: number;
24
+ /** Maximum exploration depth before forcing termination (default `8`). */
25
+ readonly depthCap?: number;
26
+ /** Score at/above which the chain terminates (default `0.85`). */
27
+ readonly terminationConfidence?: number;
28
+ /** Window size for plateau detection (default `3`). */
29
+ readonly plateauWindow?: number;
30
+ /** Minimum meaningful score change for plateau detection (default `0.02`). */
31
+ readonly plateauEpsilon?: number;
32
+ }
33
+ /**
34
+ * Tree-of-Thought strategy: beam search over the thought DAG. Pure policy.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const strategy = new TreeOfThoughtStrategy({ beamWidth: 4 });
39
+ * const decision = strategy.decide(ctx);
40
+ * ```
41
+ */
42
+ export declare class TreeOfThoughtStrategy implements IReasoningStrategy {
43
+ readonly name: "tot";
44
+ /** @param config - See {@link TotConfig}. */
45
+ constructor(config?: TotConfig);
46
+ /**
47
+ * Compute the next action for the chain.
48
+ *
49
+ * Order of checks: termination by confidence → termination by plateau →
50
+ * branch when the current thought is outside the beam → continue.
51
+ */
52
+ decide(ctx: StrategyContext): StrategyDecision;
53
+ /** True when the frontier is wider than the beam (diverse exploration). */
54
+ shouldBranch(ctx: StrategyContext): boolean;
55
+ /** True when the best frontier score crosses the threshold OR scores plateau. */
56
+ shouldTerminate(ctx: StrategyContext): boolean;
57
+ }
58
+ //# sourceMappingURL=TreeOfThoughtStrategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TreeOfThoughtStrategy.d.ts","sourceRoot":"","sources":["../../../../src/core/reasoning/strategies/TreeOfThoughtStrategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACX,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,MAAM,gCAAgC,CAAC;AAKxC;;;GAGG;AACH,MAAM,WAAW,SAAS;IACzB,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,kEAAkE;IAClE,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IACxC,uDAAuD;IACvD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,8EAA8E;IAC9E,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CACjC;AAgED;;;;;;;;GAQG;AACH,qBAAa,qBAAsB,YAAW,kBAAkB;IAC/D,QAAQ,CAAC,IAAI,EAAG,KAAK,CAAU;IAE/B,6CAA6C;gBACjC,MAAM,CAAC,EAAE,SAAS;IAI9B;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,eAAe,GAAG,gBAAgB;IAiC9C,2EAA2E;IAC3E,YAAY,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO;IAO3C,iFAAiF;IACjF,eAAe,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO;CAY9C"}
@@ -0,0 +1,103 @@
1
+ import { scoreThought, selectBeam } from "./totScoring.js";
2
+ import { detectPlateau } from "./plateau.js";
3
+ const DEFAULTS = {
4
+ beamWidth: 3,
5
+ depthCap: 8,
6
+ terminationConfidence: 0.85,
7
+ plateauWindow: 3,
8
+ plateauEpsilon: 0.02
9
+ };
10
+ const CONFIGS = new WeakMap();
11
+ function configOf(s) {
12
+ return CONFIGS.get(s) ?? DEFAULTS;
13
+ }
14
+ function thoughtKey(t) {
15
+ return t.id ?? String(t.thought_number);
16
+ }
17
+ function indexHistory(history) {
18
+ const out = new Map();
19
+ for (const t of history)out.set(thoughtKey(t), t);
20
+ return out;
21
+ }
22
+ function scoreFrontier(frontier, byKey) {
23
+ const out = [];
24
+ for (const id of frontier){
25
+ const t = byKey.get(id);
26
+ if (void 0 !== t) out.push({
27
+ id,
28
+ score: scoreThought(t)
29
+ });
30
+ }
31
+ return out;
32
+ }
33
+ function bestScore(scored) {
34
+ let best = -1 / 0;
35
+ for (const c of scored)if (c.score > best) best = c.score;
36
+ return best;
37
+ }
38
+ function recentScores(history, window) {
39
+ const start = history.length > window ? history.length - window : 0;
40
+ const out = [];
41
+ for(let i = start; i < history.length; i++)out.push(scoreThought(history[i]));
42
+ return out;
43
+ }
44
+ class TreeOfThoughtStrategy {
45
+ name = 'tot';
46
+ constructor(config){
47
+ CONFIGS.set(this, {
48
+ ...DEFAULTS,
49
+ ...config ?? {}
50
+ });
51
+ }
52
+ decide(ctx) {
53
+ const cfg = configOf(this);
54
+ if (!ctx.graph) return {
55
+ action: 'continue'
56
+ };
57
+ const frontier = ctx.graph.leaves(ctx.sessionId);
58
+ const byKey = indexHistory(ctx.history);
59
+ const scored = scoreFrontier(frontier, byKey);
60
+ if (scored.length > 0 && bestScore(scored) >= cfg.terminationConfidence) return {
61
+ action: 'terminate',
62
+ reason: 'confidence threshold'
63
+ };
64
+ const recent = recentScores(ctx.history, cfg.plateauWindow);
65
+ if (detectPlateau(recent, cfg.plateauWindow, cfg.plateauEpsilon)) return {
66
+ action: 'terminate',
67
+ reason: 'plateau'
68
+ };
69
+ if (scored.length > cfg.beamWidth) {
70
+ const beam = selectBeam(scored, cfg.beamWidth);
71
+ const currentKey = thoughtKey(ctx.currentThought);
72
+ if (!beam.includes(currentKey)) return {
73
+ action: 'branch',
74
+ branchId: `tot-${ctx.currentThought.thought_number}`,
75
+ fromThought: ctx.currentThought.thought_number,
76
+ reason: 'outside beam'
77
+ };
78
+ }
79
+ return {
80
+ action: 'continue',
81
+ nextHint: 'explore frontier'
82
+ };
83
+ }
84
+ shouldBranch(ctx) {
85
+ const cfg = configOf(this);
86
+ if (!ctx.graph) return false;
87
+ const frontier = ctx.graph.leaves(ctx.sessionId);
88
+ return frontier.length > cfg.beamWidth;
89
+ }
90
+ shouldTerminate(ctx) {
91
+ const cfg = configOf(this);
92
+ if (!ctx.graph) return false;
93
+ const frontier = ctx.graph.leaves(ctx.sessionId);
94
+ const byKey = indexHistory(ctx.history);
95
+ const scored = scoreFrontier(frontier, byKey);
96
+ if (scored.length > 0 && bestScore(scored) >= cfg.terminationConfidence) return true;
97
+ const recent = recentScores(ctx.history, cfg.plateauWindow);
98
+ return detectPlateau(recent, cfg.plateauWindow, cfg.plateauEpsilon);
99
+ }
100
+ }
101
+ export { TreeOfThoughtStrategy };
102
+
103
+ //# sourceMappingURL=TreeOfThoughtStrategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core/reasoning/strategies/TreeOfThoughtStrategy.js","sources":["../../../../src/core/reasoning/strategies/TreeOfThoughtStrategy.ts"],"sourcesContent":["/**\n * Tree-of-Thought reasoning strategy — beam search over the thought DAG.\n *\n * Observes the frontier (graph leaves), scores each leaf via\n * {@link scoreThought}, and decides whether to continue, branch (when the\n * current thought falls outside the beam), or terminate (on confidence\n * threshold or score plateau).\n *\n * Pure policy: configuration lives in a module-level {@link WeakMap}, not\n * on the instance, so `Object.getOwnPropertyNames(strategy)` only ever\n * surfaces the readonly `name` discriminator. All other state is derived\n * from the {@link StrategyContext} on every call.\n *\n * @module core/reasoning/strategies/TreeOfThoughtStrategy\n */\n\nimport type {\n\tIReasoningStrategy,\n\tStrategyContext,\n\tStrategyDecision,\n} from '../../../contracts/strategy.js';\nimport type { ThoughtData } from '../../thought.js';\nimport { scoreThought, selectBeam, type ScoredCandidate } from './totScoring.js';\nimport { detectPlateau } from './plateau.js';\n\n/**\n * Configuration knobs for {@link TreeOfThoughtStrategy}. All fields are\n * optional; defaults are applied in the constructor.\n */\nexport interface TotConfig {\n\t/** Top-K candidates kept on the frontier (default `3`). */\n\treadonly beamWidth?: number;\n\t/** Maximum exploration depth before forcing termination (default `8`). */\n\treadonly depthCap?: number;\n\t/** Score at/above which the chain terminates (default `0.85`). */\n\treadonly terminationConfidence?: number;\n\t/** Window size for plateau detection (default `3`). */\n\treadonly plateauWindow?: number;\n\t/** Minimum meaningful score change for plateau detection (default `0.02`). */\n\treadonly plateauEpsilon?: number;\n}\n\n/** Defaults applied when a {@link TotConfig} field is omitted. */\nconst DEFAULTS: Required<TotConfig> = {\n\tbeamWidth: 3,\n\tdepthCap: 8,\n\tterminationConfidence: 0.85,\n\tplateauWindow: 3,\n\tplateauEpsilon: 0.02,\n};\n\n/**\n * Module-private config storage. Keyed by strategy instance so that no\n * own-properties leak onto `this` (preserving the purity contract).\n */\nconst CONFIGS: WeakMap<TreeOfThoughtStrategy, Required<TotConfig>> = new WeakMap();\n\n/** Resolve the per-instance config (constructor always populates the map). */\nfunction configOf(s: TreeOfThoughtStrategy): Required<TotConfig> {\n\treturn CONFIGS.get(s) ?? DEFAULTS;\n}\n\n/** Stable identifier for a thought: `id` if present, else its sequence number. */\nfunction thoughtKey(t: ThoughtData): string {\n\treturn t.id ?? String(t.thought_number);\n}\n\n/** Index history by stable key for O(1) leaf-id → ThoughtData lookup. */\nfunction indexHistory(history: readonly ThoughtData[]): Map<string, ThoughtData> {\n\tconst out = new Map<string, ThoughtData>();\n\tfor (const t of history) out.set(thoughtKey(t), t);\n\treturn out;\n}\n\n/** Score the frontier (graph leaves), skipping ids absent from history. */\nfunction scoreFrontier(\n\tfrontier: readonly string[],\n\tbyKey: Map<string, ThoughtData>\n): ScoredCandidate[] {\n\tconst out: ScoredCandidate[] = [];\n\tfor (const id of frontier) {\n\t\tconst t = byKey.get(id);\n\t\tif (t !== undefined) out.push({ id, score: scoreThought(t) });\n\t}\n\treturn out;\n}\n\n/** Highest score in a candidate set, or `-Infinity` when empty. */\nfunction bestScore(scored: readonly ScoredCandidate[]): number {\n\tlet best = Number.NEGATIVE_INFINITY;\n\tfor (const c of scored) {\n\t\tif (c.score > best) best = c.score;\n\t}\n\treturn best;\n}\n\n/** Recent per-thought scores, used for plateau detection. */\nfunction recentScores(history: readonly ThoughtData[], window: number): number[] {\n\tconst start = history.length > window ? history.length - window : 0;\n\tconst out: number[] = [];\n\tfor (let i = start; i < history.length; i++) out.push(scoreThought(history[i]!));\n\treturn out;\n}\n\n/**\n * Tree-of-Thought strategy: beam search over the thought DAG. Pure policy.\n *\n * @example\n * ```typescript\n * const strategy = new TreeOfThoughtStrategy({ beamWidth: 4 });\n * const decision = strategy.decide(ctx);\n * ```\n */\nexport class TreeOfThoughtStrategy implements IReasoningStrategy {\n\treadonly name = 'tot' as const;\n\n\t/** @param config - See {@link TotConfig}. */\n\tconstructor(config?: TotConfig) {\n\t\tCONFIGS.set(this, { ...DEFAULTS, ...(config ?? {}) });\n\t}\n\n\t/**\n\t * Compute the next action for the chain.\n\t *\n\t * Order of checks: termination by confidence → termination by plateau →\n\t * branch when the current thought is outside the beam → continue.\n\t */\n\tdecide(ctx: StrategyContext): StrategyDecision {\n\t\tconst cfg = configOf(this);\n\t\tif (!ctx.graph) {\n\t\t\treturn { action: 'continue' };\n\t\t}\n\t\tconst frontier = ctx.graph.leaves(ctx.sessionId);\n\t\tconst byKey = indexHistory(ctx.history);\n\t\tconst scored = scoreFrontier(frontier, byKey);\n\t\tif (scored.length > 0 && bestScore(scored) >= cfg.terminationConfidence) {\n\t\t\treturn { action: 'terminate', reason: 'confidence threshold' };\n\t\t}\n\n\t\tconst recent = recentScores(ctx.history, cfg.plateauWindow);\n\t\tif (detectPlateau(recent, cfg.plateauWindow, cfg.plateauEpsilon)) {\n\t\t\treturn { action: 'terminate', reason: 'plateau' };\n\t\t}\n\n\t\tif (scored.length > cfg.beamWidth) {\n\t\t\tconst beam = selectBeam(scored, cfg.beamWidth);\n\t\t\tconst currentKey = thoughtKey(ctx.currentThought);\n\t\t\tif (!beam.includes(currentKey)) {\n\t\t\t\treturn {\n\t\t\t\t\taction: 'branch',\n\t\t\t\t\tbranchId: `tot-${ctx.currentThought.thought_number}`,\n\t\t\t\t\tfromThought: ctx.currentThought.thought_number,\n\t\t\t\t\treason: 'outside beam',\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn { action: 'continue', nextHint: 'explore frontier' };\n\t}\n\n\t/** True when the frontier is wider than the beam (diverse exploration). */\n\tshouldBranch(ctx: StrategyContext): boolean {\n\t\tconst cfg = configOf(this);\n\t\tif (!ctx.graph) return false;\n\t\tconst frontier = ctx.graph.leaves(ctx.sessionId);\n\t\treturn frontier.length > cfg.beamWidth;\n\t}\n\n\t/** True when the best frontier score crosses the threshold OR scores plateau. */\n\tshouldTerminate(ctx: StrategyContext): boolean {\n\t\tconst cfg = configOf(this);\n\t\tif (!ctx.graph) return false;\n\t\tconst frontier = ctx.graph.leaves(ctx.sessionId);\n\t\tconst byKey = indexHistory(ctx.history);\n\t\tconst scored = scoreFrontier(frontier, byKey);\n\t\tif (scored.length > 0 && bestScore(scored) >= cfg.terminationConfidence) {\n\t\t\treturn true;\n\t\t}\n\t\tconst recent = recentScores(ctx.history, cfg.plateauWindow);\n\t\treturn detectPlateau(recent, cfg.plateauWindow, cfg.plateauEpsilon);\n\t}\n}\n"],"names":["DEFAULTS","CONFIGS","WeakMap","configOf","s","thoughtKey","t","String","indexHistory","history","out","Map","scoreFrontier","frontier","byKey","id","undefined","scoreThought","bestScore","scored","best","Number","c","recentScores","window","start","i","TreeOfThoughtStrategy","config","ctx","cfg","recent","detectPlateau","beam","selectBeam","currentKey"],"mappings":";;AA2CA,MAAMA,WAAgC;IACrC,WAAW;IACX,UAAU;IACV,uBAAuB;IACvB,eAAe;IACf,gBAAgB;AACjB;AAMA,MAAMC,UAA+D,IAAIC;AAGzE,SAASC,SAASC,CAAwB;IACzC,OAAOH,QAAQ,GAAG,CAACG,MAAMJ;AAC1B;AAGA,SAASK,WAAWC,CAAc;IACjC,OAAOA,EAAE,EAAE,IAAIC,OAAOD,EAAE,cAAc;AACvC;AAGA,SAASE,aAAaC,OAA+B;IACpD,MAAMC,MAAM,IAAIC;IAChB,KAAK,MAAML,KAAKG,QAASC,IAAI,GAAG,CAACL,WAAWC,IAAIA;IAChD,OAAOI;AACR;AAGA,SAASE,cACRC,QAA2B,EAC3BC,KAA+B;IAE/B,MAAMJ,MAAyB,EAAE;IACjC,KAAK,MAAMK,MAAMF,SAAU;QAC1B,MAAMP,IAAIQ,MAAM,GAAG,CAACC;QACpB,IAAIT,AAAMU,WAANV,GAAiBI,IAAI,IAAI,CAAC;YAAEK;YAAI,OAAOE,aAAaX;QAAG;IAC5D;IACA,OAAOI;AACR;AAGA,SAASQ,UAAUC,MAAkC;IACpD,IAAIC,OAAOC,MAAwB;IACnC,KAAK,MAAMC,KAAKH,OACf,IAAIG,EAAE,KAAK,GAAGF,MAAMA,OAAOE,EAAE,KAAK;IAEnC,OAAOF;AACR;AAGA,SAASG,aAAad,OAA+B,EAAEe,MAAc;IACpE,MAAMC,QAAQhB,QAAQ,MAAM,GAAGe,SAASf,QAAQ,MAAM,GAAGe,SAAS;IAClE,MAAMd,MAAgB,EAAE;IACxB,IAAK,IAAIgB,IAAID,OAAOC,IAAIjB,QAAQ,MAAM,EAAEiB,IAAKhB,IAAI,IAAI,CAACO,aAAaR,OAAO,CAACiB,EAAE;IAC7E,OAAOhB;AACR;AAWO,MAAMiB;IACH,OAAO,MAAe;IAG/B,YAAYC,MAAkB,CAAE;QAC/B3B,QAAQ,GAAG,CAAC,IAAI,EAAE;YAAE,GAAGD,QAAQ;YAAE,GAAI4B,UAAU,CAAC,CAAC;QAAE;IACpD;IAQA,OAAOC,GAAoB,EAAoB;QAC9C,MAAMC,MAAM3B,SAAS,IAAI;QACzB,IAAI,CAAC0B,IAAI,KAAK,EACb,OAAO;YAAE,QAAQ;QAAW;QAE7B,MAAMhB,WAAWgB,IAAI,KAAK,CAAC,MAAM,CAACA,IAAI,SAAS;QAC/C,MAAMf,QAAQN,aAAaqB,IAAI,OAAO;QACtC,MAAMV,SAASP,cAAcC,UAAUC;QACvC,IAAIK,OAAO,MAAM,GAAG,KAAKD,UAAUC,WAAWW,IAAI,qBAAqB,EACtE,OAAO;YAAE,QAAQ;YAAa,QAAQ;QAAuB;QAG9D,MAAMC,SAASR,aAAaM,IAAI,OAAO,EAAEC,IAAI,aAAa;QAC1D,IAAIE,cAAcD,QAAQD,IAAI,aAAa,EAAEA,IAAI,cAAc,GAC9D,OAAO;YAAE,QAAQ;YAAa,QAAQ;QAAU;QAGjD,IAAIX,OAAO,MAAM,GAAGW,IAAI,SAAS,EAAE;YAClC,MAAMG,OAAOC,WAAWf,QAAQW,IAAI,SAAS;YAC7C,MAAMK,aAAa9B,WAAWwB,IAAI,cAAc;YAChD,IAAI,CAACI,KAAK,QAAQ,CAACE,aAClB,OAAO;gBACN,QAAQ;gBACR,UAAU,CAAC,IAAI,EAAEN,IAAI,cAAc,CAAC,cAAc,EAAE;gBACpD,aAAaA,IAAI,cAAc,CAAC,cAAc;gBAC9C,QAAQ;YACT;QAEF;QAEA,OAAO;YAAE,QAAQ;YAAY,UAAU;QAAmB;IAC3D;IAGA,aAAaA,GAAoB,EAAW;QAC3C,MAAMC,MAAM3B,SAAS,IAAI;QACzB,IAAI,CAAC0B,IAAI,KAAK,EAAE,OAAO;QACvB,MAAMhB,WAAWgB,IAAI,KAAK,CAAC,MAAM,CAACA,IAAI,SAAS;QAC/C,OAAOhB,SAAS,MAAM,GAAGiB,IAAI,SAAS;IACvC;IAGA,gBAAgBD,GAAoB,EAAW;QAC9C,MAAMC,MAAM3B,SAAS,IAAI;QACzB,IAAI,CAAC0B,IAAI,KAAK,EAAE,OAAO;QACvB,MAAMhB,WAAWgB,IAAI,KAAK,CAAC,MAAM,CAACA,IAAI,SAAS;QAC/C,MAAMf,QAAQN,aAAaqB,IAAI,OAAO;QACtC,MAAMV,SAASP,cAAcC,UAAUC;QACvC,IAAIK,OAAO,MAAM,GAAG,KAAKD,UAAUC,WAAWW,IAAI,qBAAqB,EACtE,OAAO;QAER,MAAMC,SAASR,aAAaM,IAAI,OAAO,EAAEC,IAAI,aAAa;QAC1D,OAAOE,cAAcD,QAAQD,IAAI,aAAa,EAAEA,IAAI,cAAc;IACnE;AACD"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Detect if scores have plateaued (no meaningful improvement).
3
+ *
4
+ * A plateau is detected when the recent `window` scores show:
5
+ * 1. Low variance (range < epsilon)
6
+ * 2. No upward trend (last - first <= epsilon)
7
+ *
8
+ * @param scores - Array of sequential confidence/quality scores
9
+ * @param window - Number of recent scores to examine (default 3)
10
+ * @param epsilon - Minimum meaningful change threshold (default 0.02)
11
+ * @returns true if the last `window` scores show no upward trend
12
+ *
13
+ * @example
14
+ * detectPlateau([0.5, 0.5, 0.5]); // true
15
+ * detectPlateau([0.1, 0.5, 0.9]); // false (upward trend)
16
+ */
17
+ export declare function detectPlateau(scores: readonly number[], window?: number, epsilon?: number): boolean;
18
+ //# sourceMappingURL=plateau.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plateau.d.ts","sourceRoot":"","sources":["../../../../src/core/reasoning/strategies/plateau.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,MAAM,GAAE,MAAU,EAClB,OAAO,GAAE,MAAa,GACpB,OAAO,CAYT"}
@@ -0,0 +1,12 @@
1
+ function detectPlateau(scores, window = 3, epsilon = 0.02) {
2
+ if (scores.length < window) return false;
3
+ const recent = scores.slice(-window);
4
+ const min = Math.min(...recent);
5
+ const max = Math.max(...recent);
6
+ const range = max - min;
7
+ const hasUpwardTrend = recent[recent.length - 1] - recent[0] > epsilon;
8
+ return range < epsilon && !hasUpwardTrend;
9
+ }
10
+ export { detectPlateau };
11
+
12
+ //# sourceMappingURL=plateau.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core/reasoning/strategies/plateau.js","sources":["../../../../src/core/reasoning/strategies/plateau.ts"],"sourcesContent":["/**\n * Detect if scores have plateaued (no meaningful improvement).\n *\n * A plateau is detected when the recent `window` scores show:\n * 1. Low variance (range < epsilon)\n * 2. No upward trend (last - first <= epsilon)\n *\n * @param scores - Array of sequential confidence/quality scores\n * @param window - Number of recent scores to examine (default 3)\n * @param epsilon - Minimum meaningful change threshold (default 0.02)\n * @returns true if the last `window` scores show no upward trend\n *\n * @example\n * detectPlateau([0.5, 0.5, 0.5]); // true\n * detectPlateau([0.1, 0.5, 0.9]); // false (upward trend)\n */\nexport function detectPlateau(\n\tscores: readonly number[],\n\twindow: number = 3,\n\tepsilon: number = 0.02,\n): boolean {\n\tif (scores.length < window) return false;\n\n\tconst recent = scores.slice(-window);\n\n\tconst min = Math.min(...recent);\n\tconst max = Math.max(...recent);\n\tconst range = max - min;\n\n\tconst hasUpwardTrend = recent[recent.length - 1]! - recent[0]! > epsilon;\n\n\treturn range < epsilon && !hasUpwardTrend;\n}\n"],"names":["detectPlateau","scores","window","epsilon","recent","min","Math","max","range","hasUpwardTrend"],"mappings":"AAgBO,SAASA,cACfC,MAAyB,EACzBC,SAAiB,CAAC,EAClBC,UAAkB,IAAI;IAEtB,IAAIF,OAAO,MAAM,GAAGC,QAAQ,OAAO;IAEnC,MAAME,SAASH,OAAO,KAAK,CAAC,CAACC;IAE7B,MAAMG,MAAMC,KAAK,GAAG,IAAIF;IACxB,MAAMG,MAAMD,KAAK,GAAG,IAAIF;IACxB,MAAMI,QAAQD,MAAMF;IAEpB,MAAMI,iBAAiBL,MAAM,CAACA,OAAO,MAAM,GAAG,EAAE,GAAIA,MAAM,CAAC,EAAE,GAAID;IAEjE,OAAOK,QAAQL,WAAW,CAACM;AAC5B"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Tree-of-Thought scoring helpers — pure functions for ranking and frontier
3
+ * exploration over the thought DAG.
4
+ *
5
+ * This module exposes three primitives used by the ToT strategy:
6
+ *
7
+ * - {@link scoreThought}: combine confidence and quality into a [0, 1] score.
8
+ * - {@link selectBeam}: pick the top-K candidates with deterministic tiebreaks.
9
+ * - {@link breadthFirstFrontier}: BFS from roots, returning leaves of the
10
+ * explored subgraph capped by depth.
11
+ *
12
+ * All functions are pure: no I/O, no mutable module state, no DI.
13
+ *
14
+ * @module core/reasoning/strategies/totScoring
15
+ */
16
+ import type { ThoughtData } from '../../thought.js';
17
+ import type { GraphView } from '../../graph/GraphView.js';
18
+ import type { SessionId } from '../../../contracts/ids.js';
19
+ /**
20
+ * A scored candidate suitable for {@link selectBeam}.
21
+ */
22
+ export interface ScoredCandidate {
23
+ readonly id: string;
24
+ readonly score: number;
25
+ }
26
+ /**
27
+ * Score a thought by combining its (calibrated) confidence with its
28
+ * self-assessed quality, then applying a per-type weight.
29
+ *
30
+ * Formula: `(calibrated_confidence ?? confidence ?? 0) * (quality_score ?? 0.5) * typeWeight(thought_type)`
31
+ *
32
+ * The `calibrated_confidence` (when present on `confidence_signals`) is
33
+ * preferred over the raw `confidence` field. The result is clamped to the
34
+ * inclusive range `[0, 1]`.
35
+ *
36
+ * @param t - The thought to score.
37
+ * @returns A score in `[0, 1]`.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const s = scoreThought({ ...base, confidence: 0.8, quality_score: 0.5 });
42
+ * // s === 0.4
43
+ * ```
44
+ */
45
+ export declare function scoreThought(t: ThoughtData): number;
46
+ /**
47
+ * Select the top-`width` candidates by score, descending.
48
+ *
49
+ * Sorting is stable and deterministic: ties on `score` are broken by
50
+ * lexicographic comparison of `id` (ascending). When `width >= candidates.length`
51
+ * all candidates are returned in sorted order. When `width <= 0` the result
52
+ * is empty.
53
+ *
54
+ * @param candidates - Scored candidates (input is not mutated).
55
+ * @param width - Beam width (top-K).
56
+ * @returns Selected ids in descending score order.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const top = selectBeam([{ id: 'a', score: 0.1 }, { id: 'b', score: 0.9 }], 1);
61
+ * // top === ['b']
62
+ * ```
63
+ */
64
+ export declare function selectBeam(candidates: readonly ScoredCandidate[], width: number): readonly string[];
65
+ /**
66
+ * Compute the BFS frontier reachable from `roots` within `depthCap` levels.
67
+ *
68
+ * Traverses outgoing edges via `graph.descendants(sessionId, id, 1)`. The returned
69
+ * set contains the *leaves* of the explored subgraph — nodes that either
70
+ * (a) sit at the depth cap, or (b) have no outgoing edges within the
71
+ * explored region.
72
+ *
73
+ * Special cases:
74
+ * - `depthCap === 0` returns the unique roots in input order.
75
+ * - empty `roots` returns an empty array.
76
+ *
77
+ * Each node is visited at most once, so cycles cannot cause infinite loops.
78
+ *
79
+ * @param graph - Read-only graph view.
80
+ * @param sessionId - Session scoping the traversal.
81
+ * @param roots - Starting thought ids.
82
+ * @param depthCap - Maximum BFS depth (0 = roots only).
83
+ * @returns Frontier (leaf) thought ids of the explored subgraph.
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const frontier = breadthFirstFrontier(view, 's1', ['root'], 2);
88
+ * ```
89
+ */
90
+ export declare function breadthFirstFrontier(graph: GraphView, sessionId: SessionId, roots: readonly string[], depthCap: number): readonly string[];
91
+ //# sourceMappingURL=totScoring.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"totScoring.d.ts","sourceRoot":"","sources":["../../../../src/core/reasoning/strategies/totScoring.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAa,MAAM,2BAA2B,CAAC;AAYtE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAuCD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM,CAQnD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CACzB,UAAU,EAAE,SAAS,eAAe,EAAE,EACtC,KAAK,EAAE,MAAM,GACX,SAAS,MAAM,EAAE,CAcnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,QAAQ,EAAE,MAAM,GACd,SAAS,MAAM,EAAE,CAqDnB"}
@@ -0,0 +1,88 @@
1
+ import { assertNever } from "../../../utils.js";
2
+ function getTypeWeight(type) {
3
+ if (void 0 === type) return 1.0;
4
+ switch(type){
5
+ case 'assumption':
6
+ return 0.5;
7
+ case 'decomposition':
8
+ return 1.2;
9
+ case 'backtrack':
10
+ return 0.8;
11
+ case 'tool_call':
12
+ return 1.0;
13
+ case 'tool_observation':
14
+ return 1.0;
15
+ case 'regular':
16
+ case 'hypothesis':
17
+ case 'verification':
18
+ case 'critique':
19
+ case 'synthesis':
20
+ case 'meta':
21
+ return 1.0;
22
+ default:
23
+ return assertNever(type);
24
+ }
25
+ }
26
+ function scoreThought(t) {
27
+ const calibrated = t.confidence_signals?.calibrated_confidence;
28
+ const confidence = calibrated ?? t.confidence ?? 0;
29
+ const quality = t.quality_score ?? 0.5;
30
+ const raw = confidence * quality * getTypeWeight(t.thought_type);
31
+ if (raw < 0) return 0;
32
+ if (raw > 1) return 1;
33
+ return raw;
34
+ }
35
+ function selectBeam(candidates, width) {
36
+ if (width <= 0 || 0 === candidates.length) return [];
37
+ const sorted = [
38
+ ...candidates
39
+ ].sort((a, b)=>{
40
+ if (b.score !== a.score) return b.score - a.score;
41
+ return a.id < b.id ? -1 : 1;
42
+ });
43
+ const k = width >= sorted.length ? sorted.length : width;
44
+ const result = [];
45
+ for(let i = 0; i < k; i++)result.push(sorted[i].id);
46
+ return result;
47
+ }
48
+ function breadthFirstFrontier(graph, sessionId, roots, depthCap) {
49
+ if (0 === roots.length) return [];
50
+ const uniqueRoots = [];
51
+ const seenRoots = new Set();
52
+ for (const r of roots)if (!seenRoots.has(r)) {
53
+ seenRoots.add(r);
54
+ uniqueRoots.push(r);
55
+ }
56
+ if (depthCap <= 0) return uniqueRoots;
57
+ const visited = new Set(uniqueRoots);
58
+ let frontier = [
59
+ ...uniqueRoots
60
+ ];
61
+ let depth = 0;
62
+ while(frontier.length > 0 && depth < depthCap){
63
+ const next = [];
64
+ for (const node of frontier)for (const child of graph.descendants(sessionId, node, 1))if (!visited.has(child)) {
65
+ visited.add(child);
66
+ next.push(child);
67
+ }
68
+ frontier = next;
69
+ depth++;
70
+ }
71
+ const explored = visited;
72
+ const leaves = [];
73
+ const seenLeaf = new Set();
74
+ const collect = (id)=>{
75
+ seenLeaf.add(id);
76
+ leaves.push(id);
77
+ };
78
+ if (depth >= depthCap && frontier.length > 0) for (const id of frontier)collect(id);
79
+ for (const id of explored){
80
+ if (seenLeaf.has(id)) continue;
81
+ const children = graph.descendants(sessionId, id, 1);
82
+ if (0 === children.length) collect(id);
83
+ }
84
+ return leaves;
85
+ }
86
+ export { breadthFirstFrontier, scoreThought, selectBeam };
87
+
88
+ //# sourceMappingURL=totScoring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core/reasoning/strategies/totScoring.js","sources":["../../../../src/core/reasoning/strategies/totScoring.ts"],"sourcesContent":["/**\n * Tree-of-Thought scoring helpers — pure functions for ranking and frontier\n * exploration over the thought DAG.\n *\n * This module exposes three primitives used by the ToT strategy:\n *\n * - {@link scoreThought}: combine confidence and quality into a [0, 1] score.\n * - {@link selectBeam}: pick the top-K candidates with deterministic tiebreaks.\n * - {@link breadthFirstFrontier}: BFS from roots, returning leaves of the\n * explored subgraph capped by depth.\n *\n * All functions are pure: no I/O, no mutable module state, no DI.\n *\n * @module core/reasoning/strategies/totScoring\n */\n\nimport type { ThoughtData } from '../../thought.js';\nimport type { ConfidenceSignals, ThoughtType } from '../../reasoning.js';\nimport type { GraphView } from '../../graph/GraphView.js';\nimport type { SessionId, ThoughtId } from '../../../contracts/ids.js';\nimport { assertNever } from '../../../utils.js';\n\n/**\n * Optional `confidence_signals` carried alongside a thought. The core\n * `ThoughtData` type does not declare this field, but evaluator output may\n * be attached by callers that want calibrated scoring.\n */\ntype ThoughtWithSignals = ThoughtData & {\n\treadonly confidence_signals?: ConfidenceSignals;\n};\n\n/**\n * A scored candidate suitable for {@link selectBeam}.\n */\nexport interface ScoredCandidate {\n\treadonly id: string;\n\treadonly score: number;\n}\n\n/**\n * Per-type score multiplier applied on top of the base confidence×quality score.\n *\n * Weights bias the ToT frontier towards productive thought kinds:\n * - `assumption` (0.5): low confidence until backed by verification.\n * - `decomposition` (1.2): encouraged for problem-splitting.\n * - `backtrack` (0.8): signals exploration but not preferred.\n * - `tool_call` / `tool_observation` (1.0): neutral exogenous information.\n * - All other types (regular, hypothesis, verification, critique, synthesis, meta): 1.0.\n *\n * Pure function: deterministic, no I/O.\n */\nfunction getTypeWeight(type: ThoughtType | undefined): number {\n\tif (type === undefined) return 1.0;\n\tswitch (type) {\n\t\tcase 'assumption':\n\t\t\treturn 0.5;\n\t\tcase 'decomposition':\n\t\t\treturn 1.2;\n\t\tcase 'backtrack':\n\t\t\treturn 0.8;\n\t\tcase 'tool_call':\n\t\t\treturn 1.0;\n\t\tcase 'tool_observation':\n\t\t\treturn 1.0;\n\t\tcase 'regular':\n\t\tcase 'hypothesis':\n\t\tcase 'verification':\n\t\tcase 'critique':\n\t\tcase 'synthesis':\n\t\tcase 'meta':\n\t\t\treturn 1.0;\n\t\tdefault:\n\t\t\treturn assertNever(type);\n\t}\n}\n\n/**\n * Score a thought by combining its (calibrated) confidence with its\n * self-assessed quality, then applying a per-type weight.\n *\n * Formula: `(calibrated_confidence ?? confidence ?? 0) * (quality_score ?? 0.5) * typeWeight(thought_type)`\n *\n * The `calibrated_confidence` (when present on `confidence_signals`) is\n * preferred over the raw `confidence` field. The result is clamped to the\n * inclusive range `[0, 1]`.\n *\n * @param t - The thought to score.\n * @returns A score in `[0, 1]`.\n *\n * @example\n * ```typescript\n * const s = scoreThought({ ...base, confidence: 0.8, quality_score: 0.5 });\n * // s === 0.4\n * ```\n */\nexport function scoreThought(t: ThoughtData): number {\n\tconst calibrated = (t as ThoughtWithSignals).confidence_signals?.calibrated_confidence;\n\tconst confidence = calibrated ?? t.confidence ?? 0;\n\tconst quality = t.quality_score ?? 0.5;\n\tconst raw = confidence * quality * getTypeWeight(t.thought_type);\n\tif (raw < 0) return 0;\n\tif (raw > 1) return 1;\n\treturn raw;\n}\n\n/**\n * Select the top-`width` candidates by score, descending.\n *\n * Sorting is stable and deterministic: ties on `score` are broken by\n * lexicographic comparison of `id` (ascending). When `width >= candidates.length`\n * all candidates are returned in sorted order. When `width <= 0` the result\n * is empty.\n *\n * @param candidates - Scored candidates (input is not mutated).\n * @param width - Beam width (top-K).\n * @returns Selected ids in descending score order.\n *\n * @example\n * ```typescript\n * const top = selectBeam([{ id: 'a', score: 0.1 }, { id: 'b', score: 0.9 }], 1);\n * // top === ['b']\n * ```\n */\nexport function selectBeam(\n\tcandidates: readonly ScoredCandidate[],\n\twidth: number\n): readonly string[] {\n\tif (width <= 0 || candidates.length === 0) {\n\t\treturn [];\n\t}\n\tconst sorted = [...candidates].sort((a, b) => {\n\t\tif (b.score !== a.score) return b.score - a.score;\n\t\treturn a.id < b.id ? -1 : 1;\n\t});\n\tconst k = width >= sorted.length ? sorted.length : width;\n\tconst result: string[] = [];\n\tfor (let i = 0; i < k; i++) {\n\t\tresult.push(sorted[i]!.id);\n\t}\n\treturn result;\n}\n\n/**\n * Compute the BFS frontier reachable from `roots` within `depthCap` levels.\n *\n * Traverses outgoing edges via `graph.descendants(sessionId, id, 1)`. The returned\n * set contains the *leaves* of the explored subgraph — nodes that either\n * (a) sit at the depth cap, or (b) have no outgoing edges within the\n * explored region.\n *\n * Special cases:\n * - `depthCap === 0` returns the unique roots in input order.\n * - empty `roots` returns an empty array.\n *\n * Each node is visited at most once, so cycles cannot cause infinite loops.\n *\n * @param graph - Read-only graph view.\n * @param sessionId - Session scoping the traversal.\n * @param roots - Starting thought ids.\n * @param depthCap - Maximum BFS depth (0 = roots only).\n * @returns Frontier (leaf) thought ids of the explored subgraph.\n *\n * @example\n * ```typescript\n * const frontier = breadthFirstFrontier(view, 's1', ['root'], 2);\n * ```\n */\nexport function breadthFirstFrontier(\n\tgraph: GraphView,\n\tsessionId: SessionId,\n\troots: readonly string[],\n\tdepthCap: number\n): readonly string[] {\n\tif (roots.length === 0) {\n\t\treturn [];\n\t}\n\tconst uniqueRoots: string[] = [];\n\tconst seenRoots = new Set<string>();\n\tfor (const r of roots) {\n\t\tif (!seenRoots.has(r)) {\n\t\t\tseenRoots.add(r);\n\t\t\tuniqueRoots.push(r);\n\t\t}\n\t}\n\tif (depthCap <= 0) {\n\t\treturn uniqueRoots;\n\t}\n\n\tconst visited = new Set<string>(uniqueRoots);\n\tlet frontier: string[] = [...uniqueRoots];\n\tlet depth = 0;\n\n\twhile (frontier.length > 0 && depth < depthCap) {\n\t\tconst next: string[] = [];\n\t\tfor (const node of frontier) {\n\t\t\tfor (const child of graph.descendants(sessionId, node as ThoughtId, 1)) {\n\t\t\t\tif (visited.has(child)) continue;\n\t\t\t\tvisited.add(child);\n\t\t\t\tnext.push(child);\n\t\t\t}\n\t\t}\n\t\tfrontier = next;\n\t\tdepth++;\n\t}\n\n\tconst explored = visited;\n\tconst leaves: string[] = [];\n\tconst seenLeaf = new Set<string>();\n\tconst collect = (id: string): void => {\n\t\tseenLeaf.add(id);\n\t\tleaves.push(id);\n\t};\n\n\tif (depth >= depthCap && frontier.length > 0) {\n\t\t// Hit the depth cap — current frontier is leaves regardless of children.\n\t\tfor (const id of frontier) collect(id);\n\t}\n\t// Any explored node with no outgoing edges inside the explored set is also\n\t// a leaf (covers nodes shallower than depthCap that terminated naturally).\n\tfor (const id of explored) {\n\t\tif (seenLeaf.has(id)) continue;\n\t\tconst children = graph.descendants(sessionId, id as ThoughtId, 1);\n\t\tif (children.length === 0) collect(id);\n\t}\n\treturn leaves;\n}\n"],"names":["getTypeWeight","type","undefined","assertNever","scoreThought","t","calibrated","confidence","quality","raw","selectBeam","candidates","width","sorted","a","b","k","result","i","breadthFirstFrontier","graph","sessionId","roots","depthCap","uniqueRoots","seenRoots","Set","r","visited","frontier","depth","next","node","child","explored","leaves","seenLeaf","collect","id","children"],"mappings":";AAmDA,SAASA,cAAcC,IAA6B;IACnD,IAAIA,AAASC,WAATD,MAAoB,OAAO;IAC/B,OAAQA;QACP,KAAK;YACJ,OAAO;QACR,KAAK;YACJ,OAAO;QACR,KAAK;YACJ,OAAO;QACR,KAAK;YACJ,OAAO;QACR,KAAK;YACJ,OAAO;QACR,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;YACJ,OAAO;QACR;YACC,OAAOE,YAAYF;IACrB;AACD;AAqBO,SAASG,aAAaC,CAAc;IAC1C,MAAMC,aAAcD,EAAyB,kBAAkB,EAAE;IACjE,MAAME,aAAaD,cAAcD,EAAE,UAAU,IAAI;IACjD,MAAMG,UAAUH,EAAE,aAAa,IAAI;IACnC,MAAMI,MAAMF,aAAaC,UAAUR,cAAcK,EAAE,YAAY;IAC/D,IAAII,MAAM,GAAG,OAAO;IACpB,IAAIA,MAAM,GAAG,OAAO;IACpB,OAAOA;AACR;AAoBO,SAASC,WACfC,UAAsC,EACtCC,KAAa;IAEb,IAAIA,SAAS,KAAKD,AAAsB,MAAtBA,WAAW,MAAM,EAClC,OAAO,EAAE;IAEV,MAAME,SAAS;WAAIF;KAAW,CAAC,IAAI,CAAC,CAACG,GAAGC;QACvC,IAAIA,EAAE,KAAK,KAAKD,EAAE,KAAK,EAAE,OAAOC,EAAE,KAAK,GAAGD,EAAE,KAAK;QACjD,OAAOA,EAAE,EAAE,GAAGC,EAAE,EAAE,GAAG,KAAK;IAC3B;IACA,MAAMC,IAAIJ,SAASC,OAAO,MAAM,GAAGA,OAAO,MAAM,GAAGD;IACnD,MAAMK,SAAmB,EAAE;IAC3B,IAAK,IAAIC,IAAI,GAAGA,IAAIF,GAAGE,IACtBD,OAAO,IAAI,CAACJ,MAAM,CAACK,EAAE,CAAE,EAAE;IAE1B,OAAOD;AACR;AA2BO,SAASE,qBACfC,KAAgB,EAChBC,SAAoB,EACpBC,KAAwB,EACxBC,QAAgB;IAEhB,IAAID,AAAiB,MAAjBA,MAAM,MAAM,EACf,OAAO,EAAE;IAEV,MAAME,cAAwB,EAAE;IAChC,MAAMC,YAAY,IAAIC;IACtB,KAAK,MAAMC,KAAKL,MACf,IAAI,CAACG,UAAU,GAAG,CAACE,IAAI;QACtBF,UAAU,GAAG,CAACE;QACdH,YAAY,IAAI,CAACG;IAClB;IAED,IAAIJ,YAAY,GACf,OAAOC;IAGR,MAAMI,UAAU,IAAIF,IAAYF;IAChC,IAAIK,WAAqB;WAAIL;KAAY;IACzC,IAAIM,QAAQ;IAEZ,MAAOD,SAAS,MAAM,GAAG,KAAKC,QAAQP,SAAU;QAC/C,MAAMQ,OAAiB,EAAE;QACzB,KAAK,MAAMC,QAAQH,SAClB,KAAK,MAAMI,SAASb,MAAM,WAAW,CAACC,WAAWW,MAAmB,GACnE,KAAIJ,QAAQ,GAAG,CAACK;YAChBL,QAAQ,GAAG,CAACK;YACZF,KAAK,IAAI,CAACE;;QAGZJ,WAAWE;QACXD;IACD;IAEA,MAAMI,WAAWN;IACjB,MAAMO,SAAmB,EAAE;IAC3B,MAAMC,WAAW,IAAIV;IACrB,MAAMW,UAAU,CAACC;QAChBF,SAAS,GAAG,CAACE;QACbH,OAAO,IAAI,CAACG;IACb;IAEA,IAAIR,SAASP,YAAYM,SAAS,MAAM,GAAG,GAE1C,KAAK,MAAMS,MAAMT,SAAUQ,QAAQC;IAIpC,KAAK,MAAMA,MAAMJ,SAAU;QAC1B,IAAIE,SAAS,GAAG,CAACE,KAAK;QACtB,MAAMC,WAAWnB,MAAM,WAAW,CAACC,WAAWiB,IAAiB;QAC/D,IAAIC,AAAoB,MAApBA,SAAS,MAAM,EAAQF,QAAQC;IACpC;IACA,OAAOH;AACR"}